akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template<typename T> T lcm( T m, T n ) { if ( ( 0 == m ) || ( 0 == n ) ) return 0; return ((m / __gcd(m, n)) * n);}
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
ll solve() {
	var(ll, n, m);
	var(string, s, t);
	ll l = lcm(n, m);
	map<ll, char> c;
	rep(i, 0, n) {
		c[i * l / n] = s[i];
	}
	rep(i, 0, m) {
		if (c.find(i * l / m) != c.end() && c[i * l / m] != t[i]) {
			return -1;
		}
	}
	return l;
}
int main() {
	print(solve());
	return 0;
}


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

#define dump(a) (cerr << #a << " = " << (a) << endl)

#define REP(i,a,b) for(int i=(a);i < (int)(b); i++)
#define rep(i,n) REP(i,0,n)
#define ALL(v) begin(v), end(v)

int main(){
  for(int m, c, n; cin >> m >> c >> n && m;) {
    vector<unordered_map<int, int>> desks(m);

    queue<int> que;
    vector<int> index(n, 0);
    vector<vector<int>> books(n);

    for(int i = 0; i < n; ++i) {
      que.push(i);

      int k;
      cin >> k;

      for(int j = 0; j < k; ++j) {
	int b;
	cin >> b;
	books[i].emplace_back(b);
      }
    }

    int ans = 0;
    for(int t = 0; !que.empty(); ++t) {
      const int student = que.front();
      que.pop();

      const int id = books[student][index[student]];
      if(++index[student] < books[student].size()) {
	que.push(student);
      }

      int pos = m;
      for(int i = 0; i < m; ++i) {
	if(desks[i].count(id)) {
	  desks[i].erase(id);
	  pos = i;
	  break;
	}
      }

      ans += pos + 1;

      int tmp = m;
      for(int i = 0; i < m; ++i) {
	if(desks[i].size() < c) {
	  desks[i].insert({id, t});
	  tmp = i;
	  break;
	}
      }

      ans += tmp + 1;

      if(tmp != 0) {
	int r_id = -1;
	int r_time = INT_MAX;

	for(const auto &e : desks[0]) {
	  if(r_time > e.second) {
	    r_id = e.first;
	    r_time = e.second;
	  }
	}

	ans += 1;
	desks[0].erase(r_id);

	int to = m;
	for(int i = 1; i < m; ++i) {
	  if(desks[i].size() < c) {
	    desks[i].insert({r_id, r_time});
	    to = i;
	    break;
	  }
	}

	ans += to + 1;

	if(tmp < m) desks[tmp].erase(id);
	ans += tmp + 1;

	desks[0].insert({id, t});
	ans += 1;
      }
    }


    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1264
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	s = readline() |> chomp
	n = length(s)
	dp = Array{Int}(n)
	dp[1] = 1
	dp[2] = s[1]==s[2]?1:2
	if s[1]==s[2]==s[3]
		dp[3]=2
	elseif s[2]==s[3]
		dp[3]=2
	else
		dp[3] = dp[2]+1
	end
	for i in 4:n
		if s[i]==s[i-1]
			dp[i] = dp[i-3]+2
		else
			dp[i] = dp[i-1]+1
		end
	end
	println(dp[n])
end

main()

Measured memory_bytes: 192216
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <cmath>
using namespace std;

#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647

int main() {
	map<int, int> mp;
	mp[1] = 1;
	for (int i = 2; i < 10; ++i) {
		mp[i] = mp[i - 1] * i;
	}

	int N;
	cin >> N;

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

	int p = 0;
	int q = 0;
	for (int i = N; 0 < i; --i) {
		int count = 0;
		for (size_t t = (N - i) + 1; t < P.size(); ++t) {
			if (P[t] < P[N - i])++count;
		}

		p += mp[i - 1] * count;

		count = 0;
		for (size_t t = (N - i) + 1; t < Q.size(); ++t) {
			if (Q[t] < Q[N - i])++count;
		}

		q += mp[i - 1] * count;
	}

	cout << abs(p - q) << endl;
	return 0;
}

Measured memory_bytes: 3568
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
typedef long long ll;
using namespace std;
typedef pair<int, int> P;
const int INF = 1000000007;
int N,M;
vector<int> A[100002];
priority_queue<int>  que;

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

  cin >> N >> M;
  int a, b;
  rep(i, N){
    cin >> a >> b;
    if (a > M) continue;
    A[a].push_back(b); //期日の後ろから考えていることに注意
  }
  int ans = 0;
  for (int i=1; i<= M; i++){
    rep(j, A[i].size()){
      que.push(A[i][j]);
    }
    if (!que.empty()){
      ans+= que.top();
      que.pop();
    }
  }

  cout << ans << endl;

  return 0;
}

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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define for1(i, a, b) for (int i = (int)a; i < (int)(b); ++i)
#define rfor1(i, a, b) for (int i=(int)b-1;i>=(int)a;i--)
#define for2(i, a, b) for (int i = (int)a; i <= (int)(b); ++i)
#define for3(i, a, b) for (int i = (int)a; i < (int)(b); i=i+2)
#define for4(i, a, b) for (int i = (int)a; i <= (int)(b); i=i+2)
#define tc(t) int t; cin>>t; while(t--)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
   // ios::sync_with_stdio(false);
   // cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b <= a + c && a + b <= b + c) {
        cout << a + b << endl;
    } else if (a + b >= a + c && c + b >= a + c) {
        cout << a + c << endl;
    } else {
        cout << b + c << endl;
    }
}









Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

struct tes {
    int x,y;
};

int main() {
    fastio;
    ll N;
    cin >> N;
    vector<vector<tes>> v(N);
    rep(j,N) {
        int a;
        cin >> a;
        v[j].resize(a);
        rep(i,a) {
            auto& [x,y] = v[j][i];
            cin >> x >> y;
            --x;
        }
    }
    int ans=0;
    rep(pat,1<<N) {
        auto h = [&](int o)->bool { return pat & (1<<o); };
        rep(i,N) {
            if (!h(i))
                continue;
            if (any_of(begin(v[i]), end(v[i]), [&](auto t) { return t.y != h(t.x); }))
                goto next;
        }
        updmax(ans, (int)__builtin_popcount(pat));
    next:;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
int n,k,x,y,ans=0;
int main()
{
    cin>>n>>k>>x>>y;
    for(int i=1;i<n+1;i++)
    {
        if(i<=k)
        {
            ans+=x;
        }
        if(i>k)
        {
            ans+=y;
        }
    }
    cout<<ans<<endl;
}

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

char c[55][55]; int H, W, cnt;

int main() {
	cin >> H >> W;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) cin >> c[i][j];
	}
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (c[i][j] == '#' && c[i][j - 1] != '#' && c[i - 1][j] != '#' && c[i][j + 1] != '#' && c[i + 1][j] != '#') cnt++;
		}
	}
	if (cnt == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

s = int(input())
ed = defaultdict(int)
cnt = 1
ed[s] = 1
while True:
    cnt += 1
    if s%2 == 0:
        s //= 2
    else:
        s = 3*s + 1
    if ed[s]:
        break
    else:
        ed[s] = 1

print(cnt)


Measured memory_bytes: 4212
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int n,x,ans=0;
	cin>>n>>x;
	vector<int>l(n);
	rep(i,n)cin>>l.at(i);
	static int p=0;
	rep(i,n+1){
			if(i!=0)p+=l.at(i-1);
			if(x<p)break;
			ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
D = defaultdict(int)
D[0] = 3

ans = 1
for a in A:
    ans *= D[a]
    ans %= MOD
    D[a] -= 1
    D[a + 1] += 1

print(ans % MOD)


Measured memory_bytes: 20960
n, x = map(int, input().split())

patty = [0]*(n+1)
length = [0]*(n+1)
for L in range(n+1):
    if L==0:
        patty[L] = 1
        length[L] = 1
    else:
        patty[L] = patty[L-1]*2+1
        length[L] = length[L-1]*2+3

def patty_n(L,X): # length[L]>=X>=0
    # print('L,X',L,X)
    if X==0:
        return 0
    elif L==0:
        return 1
    else:
        l = length[L-1]
        if X==1:
            return 0
        elif 1<X<=1+l:
            return patty_n(L-1, X-1)
        else:
            return patty[L-1]+1+patty_n(L-1, X-l-2)

print(patty_n(n,x))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

string ID(int p, int th){
  th++;
  string id = "";
  rep(i,6-(int)to_string(p).size())id += ('0');
  id += to_string(p);
  rep(i,6-(int)to_string(th).size())id += ('0');
  id += to_string(th);
  return id;
}

int main(){
  int N,M; cin >> N >> M;
  vector<pair<pair<int,int>,int>> YPI(M);
  vector<string> YPI_ans(M);

  rep(i,M){
    cin >> YPI[i].first.first >> YPI[i].first.second;
    YPI[i].second = i;
  }
  sort(all(YPI));
  int last = mod;
  int cnt = 0;
  rep(i,M){
    if(last != YPI[i].first.first){
      last = YPI[i].first.first;
      cnt = 0;
    }
    else cnt++;

    YPI_ans[YPI[i].second] = ID(YPI[i].first.first, cnt);
  }
  rep(i,M){
    cout << YPI_ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 9728
S=list(input())
len_S=len(S)
ans=[1]*len(S)
for i in range(len_S):
    if S[i]=='R':
        if S[i+1]=='R':
            ans[i+2]+=ans[i]
            ans[i]=0
for i in range(len_S)[::-1]:
    if S[i]=='L':
        if S[i-1]=='L':
            ans[i-2]+=ans[i]
            ans[i]=0
print(*ans)

Measured memory_bytes: 7088
// AGC 017B
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
int main()
{
	int n,i,j;
	LL a,b,c,d;
	LL x,y,z;
	cin>>n>>a>>b>>c>>d;
	n-=1;
	if(a>b)
		swap(a,b);
	for(i=n%2;i<=n;i=i+2)
	{
		j=(n-i)/2;
		x=(LL)a+c*i+(c-d)*j;
		y=(LL)a+d*i+(d-c)*j;
		if(x<=b&&b<=y){
			//cout<<x<<' '<<y<<endl;
			cout<<"YES\n";
			return 0;
		}
	}
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func main() {
	io := NewIo()
	defer io.Flush()

	N := io.NextInt()
	totalSum := 0
	minusNum := 0
	min := 999999999999999999

	for i := 0; i < N; i++ {
		A := io.NextInt()
		if A < 0 {
			A *= -1
			minusNum++
		}

		if A < min {
			min = A
		}

		totalSum += A

	}

	if minusNum%2 == 1 {
		totalSum -= 2 * min
	}

	io.PrintLn(totalSum)

}


Measured memory_bytes: 6912
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <map>

int main(void) {
	int n;

	std::cin >> n;

	std::priority_queue<int> q;

	for (size_t i = 0; i < n; i++) {
		int p;

		std::cin >> p;

		q.push(p);
	}

	long long ans = q.top() / 2;

	q.pop();

	while (!q.empty()) {
		ans += q.top();
		q.pop();
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scl1(a) scanf("%lld",&a)
#define scl2(a,b) scanf("%lld%lld",&a,&b)
#define scl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define pr1(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d ",a,b)
#define pr3(a,b,c) printf("%d %d %d ",a,b,c)
#define mii map<int,int>
#define vi vector<int>
#define vl vector<long long>
#define vii vector<pair<int,int>>
#define mii map<int,int>
#define ll long long
#define ii pair<int,int>
#define loop(i,a,b) for(int i=(a);i<(b);i++)
#define rloop(i,a,b) for(int i=(a);i>(b);i--)
#define tr(it,c) for(decltype((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define ft first
#define sd second
#define mod 998244353
#define mod2 1000000007
#define mem(a,b) memset(a,b,sizeof(a))
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL)
 
using namespace std;
int gcd(int a,int b)
{
	if(a<b)
	swap(a,b);
	if(b==0)
	return a;
	while((a=a%b)!=0)
	{
		swap(a,b);
	}
	return b;
}
ll modpow(ll x,int y)
{
	ll res=1;
	while(y>0)
	{
		if(y&1)
		res=res*x%mod2;
		y=y>>1;
		x=x*x%mod2;
	}
	return res;
}
ll ncr(int n,int r)
{
	ll f1=1,f2=1;
	loop(i,n-r+1,n+1)
	f1=f1*i%mod;
	loop(i,1,r+1)
	f2=f2*i%mod;
	return f1*modpow(f2,mod-2)%mod;
}
int *sieve(int n)
{
	int *lpf=new int[n+1];
	for(int i=1;i<=n;i++)
	lpf[i]=i;
	int rt=(int)floor(sqrt(n))+1;
	loop(i,2,rt)
	{
		if(lpf[i]!=i)
		continue;
		for(int j=i*i;j<=n;j+=i)
		{
			if(lpf[j]==j)
			lpf[j]=i;
		}
	}
	return lpf;
}









void solve()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int r=0;
	for(char c:s)
	{
		if(c=='R')
		r++;
	}
	int ans=0;
	loop(i,0,r)
	{
		if(s[i]=='W')
		ans++;
	}
	cout<<ans;
}

int main()
{
	SYNC;
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int t=1;
	//cin>>t;
	while(t--)
	{
		//cout<<"Case #"<<z+1<<": ";
		solve();
		cout<<"\n";
	}
}


Measured memory_bytes: 3732
#include <iostream>
#include <algorithm>
#define MAX_R 10000
#define MAX_C 30
#define INF 100000
using namespace std;
typedef pair<int, int> coordinate;
char field[MAX_R][MAX_C + 1];
bool used[MAX_R][MAX_C + 1];
int d[MAX_R][MAX_C + 1];
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int R, C;
coordinate start, goal;

void dijkstra(coordinate s) {
	d[s.second][s.first] = 0;

	while (1) {
		coordinate v(-1, -1);
		for (int i = 0; i < R; ++i) {
			for (int j = 0; j < C; ++j) {
				if (!used[i][j] && (v == coordinate(-1, -1) || d[i][j] < d[v.second][v.first])) {
					v = coordinate(j, i);
				}
			}
		}

		if (v == coordinate(-1, -1)) break;
		used[v.second][v.first] = true;

		for (int i = 0; i <= 4; ++i) {
			int nx = v.first + dx[i]; int ny = v.second + dy[i];
			if (0 <= nx && nx < C && 0 <= ny && ny < R && field[ny][nx] != '#') {
				if (field[ny][nx] == 'o') d[ny][nx] = min(d[ny][nx], d[v.second][v.first] + 1);
				else if (field[ny][nx] == 'x') d[ny][nx] = min(d[ny][nx], d[v.second][v.first] + 3);
				else d[ny][nx] = min(d[ny][nx], d[v.second][v.first] + 2);

				int nnx = nx + dx[i]; int nny = ny + dy[i];
				if (0 <= nnx && nnx < C && 0 <= nny && nny < R && field[nny][nnx] != '#') {
					d[nny][nnx] = min(d[nny][nnx], d[v.second][v.first] + 4);

					int nnnx = nnx + dx[i]; int nnny = nny + dy[i];
					if (0 <= nnnx && nnnx < C && 0 <= nnny && nnny < R && field[nnny][nnnx] != '#') {
						d[nnny][nnnx] = min(d[nnny][nnnx], d[v.second][v.first] + 5);
					}
				}

			}
		}
	}
}


int main() {
	char tmp;
	cin >> R >> C;
	for (int i = 0; i < R; ++i) {
		fill(d[i], d[i] + C, INF);
		fill(used[i], used[i] + C, false);
	}
	for (int i = 0; i < R; ++i) {
		for (int j = 0; j < C; ++j) {
			cin >> tmp;
			if (tmp == 'S') start = coordinate(j, i);
			if (tmp == 'G') goal = coordinate(j, i);
			if (tmp == '#') used[i][j] = true;
			field[i][j] = tmp;
		}
	}
	dijkstra(start);
	cout << d[goal.second][goal.first] << endl;
	return 0;
}

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

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

    vector<int> a(n+1);
    vector<int> b(n);
    for (int i = 0; i < n+1; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];

    long long beaten = 0;
    for (int i = n; i >= 1; i--) {
        int diff1 = min(a[i], b[i-1]);
        int diff2 = min(a[i-1], abs(b[i-1] - diff1));
        beaten += diff1;
        beaten += diff2;
        a[i-1] -= diff2;
    }

    cout << beaten << endl;

    return 0;
}

Measured memory_bytes: 1024
//In The Name Of The God

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define F first
#define S second
#define X first.first
#define Y first .second
#define A second.first
#define B second.second
#define mp make_pair
#define pb push_back
#define pf push_front
#define P push
#define pob pop_back
#define pof pop_front
#define PO pop
#define rep(i,j,k) for(int i = j ; i <= k ; ++ i)
#define rrep(i,j,k) for(int i = j ; i>=k ; --i)
#define FR(i,j,k) for(int i = j ; i < k ; ++ i )
#define rFR(i,j,k) for(int i = j ; i > k ; -- i )
#define lb(x) x&-x
#define p2(x) (1LL<<x)
#define SZ size()
#define LB lower_bound
#define UB upper_bound
#define IT iterator
#define RIT reverse_iterator
#define E end()
#define BE begin()
#define RE rend()
#define RBE rbegin()
#define UN unsigned

typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll ;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
typedef pair<int,pll> pipl;
typedef pair<pll,int> ppli ;
typedef pair<pll,pll> plpl ;
typedef pair<ll,pii> lpip;
typedef pair<pii,ll> lppi;
typedef pair<pii,pii> lppp;
typedef pair<ll,pll> lpipl;
typedef pair<pll,ll> lppli ;
typedef pair<pll,pll> lplpl ;
typedef vector<int> vi ;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef set<int> sti;
typedef set<ll> stl;
typedef set<pii > stpi;
typedef set<pll> stpl;
typedef vi::IT vit;
typedef vl::IT vlt;
typedef vpi::IT vpit;
typedef vpl::IT vplt;
typedef sti::IT stit;
typedef stl::IT stlt;
typedef stpi::IT stpit;
typedef stpl::IT stplt;
typedef vpi::RIT rvpit;
typedef vpl::RIT rvplt;
typedef sti::RIT rstit;
typedef stl::RIT rstlt;
typedef stpi::RIT rstpit;
typedef stpl::RIT rstplt;

const int MAXN = 500000;
const int SUPERN = 5000000;
const int MAXS = 325;
const int SUPERS = 1000;
const int MD = 1e9+7;
//......Structures.......

//......Variables........
int n,m,k;
//......Funcs............
ll sum(ll a,ll b)
{
    return (a+b)%MD;
}
ll mu(ll a,ll b)
{
    return (a*b)%MD;
}
ll mn(ll a,ll b)
{
    return(a-b+MD)%MD;
}
//......Code.............
int main()
{
	cin>>n>>m>>k;
	rep(i,0,n)rep(j,0,m)
	{
		if(i*m+j*n-2*i*j==k)
		{
			cout<<"Yes";return 0;
		}
	}
	cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
        #define ll long long
        #define rep(i,a,b) for(int i=a;i<=b;i++)
        using namespace std;
        const int maxn=400010;
        const double pi=acos(-1.0);
        struct point{
            int x,y;
            double angle;
        };
        bool cmp(point w,point v){ return w.angle<v.angle; }
        point a[maxn]; ll ans,x,y;
        void update(){ ans=max(ans,1LL*x*x+y*y); }
        int main()
        {
            int N,head=0;
            scanf("%d",&N);
            rep(i,1,N){
                scanf("%d%d",&a[i].x,&a[i].y);
                a[i].angle=atan2(a[i].y,a[i].x);
            }
            sort(a+1,a+N+1,cmp);
            rep(i,1,N){
                a[i+N]=a[i];
                a[i+N].angle=a[i].angle+pi*2;
            }
            rep(i,1,N){
                x-=a[i-1].x; y-=a[i-1].y;
                update();
                while(head+1-i+1<=N&&head+1<=N+N&&a[head+1].angle-a[i].angle<=pi){
                    head++; x+=a[head].x; y+=a[head].y;
                    update();
                }
            }
            printf("%.12lf\n",sqrt(ans));
            return 0;
        }

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

using namespace std;

int D[30][30];
int C[510][510];
int cost[3][30];

int main() {
  int N, NC;
  cin >> N >> NC;
  for (int y = 0; y < NC; y++) {
    for (int x = 0; x < NC; x++) {
      cin >> D[y][x];
    }
  }

  for (int y = 0; y < N; y++) {
    for (int x = 0; x < N; x++) {
      cin >> C[y][x];
      C[y][x]--;
    }
  }

  memset(cost, 0, sizeof(cost));
  for (int i = 0; i < 3; i++) {
    for (int dstColor = 0; dstColor < NC; dstColor++) {
      int totalCost = 0;
      for (int y = 0; y < N; y++) {
        for (int x = 0; x < N; x++) {
          if (((y + x) % 3) != i) continue;
          int srcColor = C[y][x];
          totalCost += D[srcColor][dstColor];
        }
      }
      cost[i][dstColor] = totalCost;
    }
  }

  int result = 1e9;
  for (int c0 = 0; c0 < NC; c0++) {
    for (int c1 = 0; c1 < NC; c1++) {
      if (c1 == c0) continue;
      for (int c2 = 0; c2 < NC; c2++) {
        if (c2 == c0 or c2 == c1) continue;
        int totalCost = cost[0][c0] + cost[1][c1] + cost[2][c2];
        result = min(result, totalCost);
      }
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
typedef long long ll;
typedef double db;
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 1e5+20;
#define dep(i,a,b) for(int i=(a);i>=(b);i--)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define mes(p) memset(p,0,sizeof(p))
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
int main()
{
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    if((a+b)&1) cout<<"IMPOSSIBLE";
    else{
    	cout<<(a+b)/2;
	}
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int INF = 1e9;
inline int read(){
	int X = 0,w = 0 ;
	char ch = 0;
	while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
	while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
	return w ? -X : X;
}
map<pair<string,string>,ll> m;
char s[105];
int main()
{
	int n;
	cin>>n;
	cin>>s;
	for(int i=0;i<(1<<n);i++)
	{
		string s1;
		string s2;
		for(int j=0;j<n;j++)
		{
			if(i&(1<<j))
			{
				s1+=s[j];
			}
			else
			{
				s2+=s[j];
			}
		}
		m[make_pair(s1,s2)]++;
	}
	ll sum=0;
	for(int i=0;i<(1<<n);i++)
	{
		string s1;
		string s2;
		for(int j=n-1;j>=0;j--)
		{
			if(i&(1<<j))
			{
				s2+=s[j+n];
			}
			else
			{
				s1+=s[j+n];
			}
		}
		sum+=m[make_pair(s1,s2)];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 91904
#include "bits/stdc++.h"
#define ll long long
#define mk make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
using namespace std;
const int MAXN=1e5+9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	if(n%10==3)
	{
		cout<<"bon"<<endl;
		return 0;
	}
	int p=(n%10);
	if(p==0||p==1||p==6||p==8)
	{
		cout<<"pon"<<endl;
		return 0;
	}
	cout<<"hon"<<endl;
	return 0;
}

Measured memory_bytes: 3652
import time

def main():
    h, n = map(int, input().split())
    INF = 10 ** 9
    magic = []

    for i in range(n):
        a, b = map(int, input().split())
        magic.append((a, b))

    # t = time.time()

    magic.sort(reverse=True, key=lambda x: x[0])

    dp = [INF] * (h + 10 ** 4)
    dp[0] = 0

    for a, b in magic:
        for i in range(h):
            if dp[i] != INF:
                tmp = dp[i] + b
                if tmp < dp[i + a]:
                    dp[i + a] = tmp

    ans = min(dp[h:])

    print(ans)
    # print(time.time() - t)

main()

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

lis=[[0]*10 for i in range(10)]

for i in range(N):
    temp=list(str(i+1))
    temp=list(map(int,temp))
    lis[temp[0]][temp[-1]]+=1

ans=0
for i in range(10):
    for j in range(10):
        ans+=lis[i][j]*lis[j][i]
print(ans)
    

Measured memory_bytes: 3060
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using INT=mp::cpp_int;
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
INT LCM(INT x,INT y){
  INT z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
INT modinv(INT a, INT m) {
    INT b = m, u = 1, v = 0;
    while (b) {
        INT t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main() {
  cout << fixed << setprecision(30);
  string s;
  cin>>s;
  map<char,ll> al;
  loop(i,s.size())al[s[i]]++;
  vec a(3);
  a[0]=al['a'];
  a[1]=al['b'];
  a[2]=al['c'];
  sort(all(a));
  if(a[2]-a[0]<=1)putout("YES");
  else putout("NO");
}

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

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

	sort(value, value + N);

	value[N - 1] /= 2;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		ans += value[i];
	}

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

Measured memory_bytes: 384
import java.io.*;

class Ps {
	String name;
	Integer t;
	
	public Ps( String name, Integer t )
	{
		this.name = name;
		this.t = t;
	}
}
 
class Main {
    public static void main(String[] args) {
        BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
        try {
 
            String[] str = kb.readLine().split( " " );
            int n = Integer.parseInt( str[0] );
            int q = Integer.parseInt( str[1] );
			
			
			final int LEN = 100005;
			Ps[] queue = new Ps[LEN];
			int head = 0, tail = n-1;				
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                queue[i] = new Ps( str[0], Integer.parseInt( str[1] ) );
            }

            StringBuilder output = new	StringBuilder( );
			String name;
            int time, t;
           	time = 0;
            while( 0 != n ) {
	           	name = queue[ head ].name;
            	t = queue[ head ].t;
            	if( t <= q ) {
            		queue[ head ] = null;
            		n--;
            		output.append( name );
            		output.append( " " );
            		output.append(  time + t );
            		output.append( "\n" );
            		time += t;          		
            	} else {
            		tail++;
            		if( LEN == tail ) { tail = 0; }
	           		queue[tail] = new Ps( name, t - q );
	                time += q;        
            	}
          		head++;
          		if( LEN == head ) { head = 0; }
            }
            System.out.print( output );
             
        } catch( IOException e ) {
            System.err.println( e );
        }
    }
}

Measured memory_bytes: 60660
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
 
typedef long long ll;
typedef pair<int,int> P;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
int main(){
    string s;
    std::cin >> s;
    int n;
    std::cin >> n;
    string ans;
    rep(i,s.size()){
        if(i%n==0){
            ans.pb(s[i]);
        }
    }
    std::cout << ans << std::endl;
}

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, ans;  cin >> s;
    rep (i, s.size()) {
      if (s[i] != 'B') {
        ans.push_back(s[i]);
      } else {
        if (s.size() > 0) ans.pop_back();
      }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())

if n%(a+b) == 0:
  print(n//(a+b)*a)
else:
  tmp = n%(a+b)
  if tmp >= a:
    print(n//(a+b)*a + a)
  elif tmp < a:
    print(n//(a+b)*a + tmp)
  else:
    print(n//(a+b)*a)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;
//printf("%.10f\n", n);

ll item[3005][3005], dp[3005][3005][4];
signed main() {
	ll n, m, l; cin >> n >> m >> l;
	rep(i, l) {
		ll a, b, c; cin >> a >> b >> c;
		item[a][b] = c;
	}
	rep2(i, n) {
		rep2(j, m) {
			//取らない
			vector<ll> nget(4);
			rep(k, 4) {
				nget[k] = max(nget[k], dp[i][j - 1][k]);
				nget[0] = max(nget[0], dp[i - 1][j][k]);
			}
			//取る
			vector<ll> get(4);
			if (item[i][j] != 0) {
				rep2(k, 3) {
					get[k] = max(get[k], dp[i][j - 1][k - 1]);
					get[1] = max(get[1], dp[i - 1][j][k]);
				}
				get[1] = max(get[1], dp[i - 1][j][0]);
				rep2(k, 3) {
					get[k] += item[i][j];
				}
			}
			rep(k, 4) {
				dp[i][j][k] = max(nget[k], get[k]);
			}
		}
	}
	ll ans = 0;
	rep(i, 4) { ans = max(ans, dp[n][m][i]); }
	cout << ans << endl;
	cin >> n; return 0;
}

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

int main(){
  double w,h,x,y;
  cin >> w >> h >> x >> y;
  cout << w*h/2 << " ";
  if(x==w/2 && y ==h/2){
    cout << "1" << endl;
  }else{cout << "0" << endl;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=b-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
#define vec vector
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 100005;
ll dp[N][2];
bool val[N][2];

vector<int> t[N];

ll gdp(int x, int c, int par){
	if(!val[x][c]){
		val[x][c] = 1;
		ll &res = dp[x][c];
		if(c == 0){// black
			res = 1;
			for(int a:t[x]){
				if(a != par)res = res * gdp(a, 1, x) % MOD;
			}
		}
		else{
			res = 1;
			for(int a:t[x]){
				if(a != par){
					res = res * (gdp(a, 1, x) + gdp(a, 0, x)) % MOD;
				}
			}
		}
	}
	return dp[x][c];
}

int main(){
	fast_io();
	int n;
	cin >> n;
	cu(i,0,n-1){
		int x,y;
		cin >> x >> y;
		t[x].pb(y);
		t[y].pb(x);
	}
	cout << (gdp(1,0,0) + gdp(1,1,0)) % MOD << '\n';
}


Measured memory_bytes: 14464
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define pb push_back
#define mp make_pair
#define err(x) cout<<#x<<"= "<<x<<endl;
#define rep(i,n) for(int i =0; i< n; i++)
#define ff first
#define ss second
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define SIZE 200010
#define eps 1e-13
#define prev prev1
int prev[25];
int nxt[SIZE];

int main(){
//	#ifdef ONLINE_JUDGE
//	freopen("little.in", "r" , stdin);
//	freopen("little.out", "w", stdout);
// cin.tie(false); cout.tie(false);	
//	#endif
	ios::sync_with_stdio(false);
	rep(i,25) prev[i] = -1;
	int n;
	cin>>n;	
	rep(i,SIZE) nxt[i] = n;

	rep(i,n){
		int a,cur = 0;
		cin>>a;
		while(a){
			if(a&1){
				if(prev[cur] >=0){
					nxt[prev[cur]] = min(nxt[prev[cur]], i);
				}
				prev[cur] = i;
			}
			a>>=1;cur++;
		}
	}
//	rep(i,n)
//		cout<<nxt[i]<<' ';
//	cout<<endl;
	int now = n;
	for(int i = n-1; i>=0; i--){
		nxt[i] = min(now, nxt[i]);
		now = min(now, nxt[i]);
	}
	ll ans =0;
	rep(i,n){
		ans += nxt[i]-i;
	}
	cout<<ans<<endl;
	return 0;
};


Measured memory_bytes: 1024
/* Written By : Anish Ray */
 
#include <bits/stdc++.h>
 
#define ll long long
#define v(k) vector <k>
#define mod 1000000007
#define m(a,b) map <a,b>
#define ull unsigned long long
#define fi first
#define se second
 
using namespace std;
  
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

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

	if(n%k==0)
	{
		cout<<0;
	}
	else
	{
		cout<<1;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "YES":"NO"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,v,b,w,t;
	while(cin>>a>>v>>b>>w>>t) {
		bool ans=abs(a-b)<=t*max(0LL, v-w);
		cout<<YN(ans)<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (upper_bound(ALL(c),x)-lower_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *min_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

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

int extended_gcd(int a, int b, int& x, int& y) {
   // solve ax + by = gcd(a,b)
   if(b == 0) { x = 1; y = 0; return a; }
   int X, Y;
   int g = extended_gcd(b, a % b, X, Y);
   x = Y; y = X - a/b * Y;
   return g;
}


signed main()
{
   int a, b; cin >> a >> b;
   int x, y;
   extended_gcd(a, b, x, y);
   cout << x << " " << y << endl;

   return 0;
}



Measured memory_bytes: 3064