akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

const ll N=2e3+10;
mat b(N,vec(N,0));
ll n,k,kk;

ll area(ll x,ll y) {
  ll tmp=0;
  if(x+k-1<=kk) {
    if(y+k-1<=kk) {
      tmp+=b[x+k-1][y+k-1];
      tmp+=b[x-1][y-1];
      tmp-=b[x-1][y+k-1];
      tmp-=b[x+k-1][y-1];
    }
    else {
      tmp+=b[x+k-1][kk];
      tmp-=b[x+k-1][y-1];
      tmp-=b[x-1][kk];
      tmp+=b[x-1][y-1];
      tmp+=b[x+k-1][y+k-1-kk];
      tmp-=b[x-1][y+k-1-kk];
    }
  }
  else {
    if(y+k-1<=kk) {
      tmp+=b[kk][y+k-1];
      tmp-=b[x-1][y+k-1];
      tmp-=b[kk][y-1];
      tmp+=b[x-1][y-1];
      tmp+=b[x+k-1-kk][y+k-1];
      tmp-=b[x+k-1-kk][y-1];
    }
    else {
      tmp+=b[kk][kk];
      tmp-=b[x-1][kk];
      tmp-=b[kk][y-1];
      tmp+=b[x-1][y-1];
      tmp+=b[x+k-1-kk][kk];
      tmp-=b[x+k-1-kk][y-1];
      tmp+=b[kk][y+k-1-kk];
      tmp-=b[x-1][y+k-1-kk];
      tmp+=b[x+k-1-kk][y+k-1-kk];
    }
  }
  return tmp;
}

int main() {
  cin >> n >> k;
  kk=2*k;
  for(ll i=0;i<n;i++) {
    ll x,y;
    char c;
    cin >> x >> y >> c;
    if(c=='B') b[x%kk+1][y%kk+1]++;
    else b[(x+k)%kk+1][y%kk+1]++;
  }
  for(ll i=0;i<kk;i++) {
    for(ll j=0;j<=kk;j++) {
      b[i+1][j]+=b[i][j];
    }
  }
  for(ll i=0;i<=kk;i++) {
    for(ll j=0;j<kk;j++) {
      b[i][j+1]+=b[i][j];
    }
  }
  ll ans=0;
  for(ll i=1;i<=kk;i++) {
    for(ll j=1;j<=kk;j++) {
      ll tmp=0;
      tmp+=area(i,j);
      tmp+=area((i+k-1)%kk+1,(j+k-1)%kk+1);
      ans=max(ans,tmp);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 31872
n,m=map(int,input().split())
a = [int(x)//2 for x in input().split()]
import fractions
lmc=a[0]
for i in range(1,n):
    lmc=lmc*a[i]//fractions.gcd(lmc,a[i])
    if lmc>m:
        print("0")
        exit()
for i in range(n):
   if (lmc//a[i])%2==0:
      print("0")
      exit()
if (m//lmc)%2==0:
    print((m//lmc)//2)
else:
    print(((m//lmc)+1)//2)

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

#define fast ios_base::sync_with_stdio; cin.tie(0); cout.tie(0)
#define ll          long long
#define ull         unsigned long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
//#define endl        '\n'
#define mod        1000000007
//#define mod        998244353
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define INF         numeric_limits<ll>::max();
#define NINF        numeric_limits<ll>::min();
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))
const long double pi=3.14159265359;

int n,m,q;
vector<vector<int>> v;
ll ans=0;

void fun(vi a,int num){
    if(num==n){
        v.pb(a);
        return;
    }
    rep(i,a[a.size()-1],m+1){
        a.pb(i);
        fun(a,num+1);
        a.pop_back();
    }
}

int main()
{fast;
 #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
 #endif
 int t=1;
 //cin>>t;
 while(t--)
 {cin>>n>>m>>q;
  vi v1(q),v2(q),v3(q),v4(q);
  rep(i,0,q){
    cin>>v1[i]>>v2[i]>>v3[i]>>v4[i];
  }
  vi a;
  a.pb(1);
  fun(a,1);
  rep(i,0,v.size()){
    vi b=v[i];
    ll sum=0;
    rep(j,0,q){
        if(b[v2[j]-1]-b[v1[j]-1]==v3[j]){
            sum+=v4[j];
        }
    }
    ans=max(ans,sum);
  }
  cout<<ans;
 }
 return 0;
}


Measured memory_bytes: 6688
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int int64_t
#define ALL(a) (a).begin(),(a).end()
signed main(){
  int N,sumX=0;
  cin>>N;
  vector<int> W(N);
  rep(i,0,N){
    cin>>W[i];
    sumX+=W[i];
    }
  int sum=0,ans;
  rep(i,0,N){
    sum+=W[i];
    if(sum>sumX/2){
      ans=min(sum*2-sumX,sumX-2*(sum-W[i]));
      break;
    }
    }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pi = pair<int,int>;
using mp = map<int,int>;
using ump = unordered_map<int,int>;
#define MOD 1000000007

#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

#define dbg(args...) do {cerr<<#args<<" : "; faltu(args); } while(0)
void faltu ()  {        cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr<<arg<< ' ';faltu(rest...);}

#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main(){
    fastio;
    ///freopen("input.txt","r",stdin);
    ///freopen("output.txt","w",stdout);

    ll N, tmp; cin>>N;
    tmp=N%10;
    if(tmp==3)
        cout<<"bon"<<endl;
    else if(tmp==0||tmp==1||tmp==6||tmp==8)
        cout<<"pon"<<endl;
    else cout<<"hon"<<endl;
return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	ll n,d; cin>>n>>d;
	ll ans=0;
	rep(i,1,n+1){
		for(ll j=2;j*j<=i;j++){
			if(j/10==0 && (i/j)/10==0){
				if(i%j==0 && i/j>1){
					ll k=i/j;
					ll a=k*10+j;
					ll b=j*10+k;
					if(a<=d && a!=b)ans++;
					if(b<=d && a!=b)ans++;
					if(a<=d && a==b)ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 3636
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var nq = Console.ReadLine().Split().Select(int.Parse).ToArray();

        List<int>[] graph = Enumerable.Repeat(0, nq[0]).Select(_ => new List<int>()).ToArray();
        for (int i = 0; i < nq[0] - 1; i++)
        {
            var st = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
            graph[st[0]].Add(st[1]);
            graph[st[1]].Add(st[0]);
        }

        var node = new long[nq[0]];
        for (int i = 0; i < nq[1]; i++)
        {
            var px = Console.ReadLine().Split().Select(int.Parse).ToArray();
            node[px[0] - 1] += px[1];
        }

        bool[] arrived = new bool[nq[0]];

        Stack<int> stack = new Stack<int>();
        stack.Push(0);
        while (stack.Count > 0)
        {
            var elem = stack.Pop();
            arrived[elem] = true;
            foreach (var item in graph[elem])
            {
                if (arrived[item]) continue;
                node[item] += node[elem];
                stack.Push(item);
            }
        }

        Console.WriteLine(string.Join(" ", node));
    }
}


Measured memory_bytes: 52676
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}
int main()
{
    string S,T;
    cin>>S>>T;
    ll L=S.size();
    ll M=T.size();
    ll ans=10000;
    rep(i,L-M+1){
        ll count=0;
        rep(j,M){
            if(S.at(i+j)!=T.at(j))count++;
        }
        ans=min(ans,count);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<vector>
#include<deque>
#include<list>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll n;
	cin>>n;
	ll ans=2;
	while(ans*2<=n){
		ans*=2;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3120
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8)
	{
		cout << "Yay!" << endl;
	}
	else
	{
		cout << ":(" << endl;
	}
}

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    s = input()
    t = input()
    ans = 1001
    for i in range(len(s) - len(t) + 1):
        short_s = s[i:i + len(t)]
        icchi = 0
        for j in range(len(t)):
            if short_s[j] != t[j]:
                icchi += 1
        if icchi < ans:
            ans = icchi
    print(ans)


   

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 9068
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long int
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int32_t main()
    {
        ll i,j,k,l,n,m,q,t,max1,min1,flag=0,flag2=0;
        cin>>n;
        for(i=1;i<=sqrt(n);i++)
        {
            if(n%i==0&&(n/i)<10&&i<10)
            {
                flag=1;
                break;
            }
        }
        if(flag)
        {
            cout<<"Yes";
        }
        else{
            cout<<"No";
        }
       return 0;
    }







Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> x(N), y(N), h(N);
    for(int i = 0; i < N; ++i){
        cin >> x[i] >> y[i] >> h[i];
    }
    int Cx, Cy, H, Hmin, h_calc;
    Hmin = *max_element(h.begin(), h.end());

    bool isOK;

    for(Cx = 0; Cx <= 100; ++Cx){
        for(Cy = 0; Cy <= 100; ++Cy){
            for(H = Hmin; H <= Hmin + 100; ++H){
                isOK = true;
                for(int i = 0; i < N; ++i){
                    h_calc = max(H - abs(x[i] - Cx) - abs(y[i] - Cy), 0);
                    if(h_calc != h[i]){
                        isOK = false;
                        break;
                    }
                }
                if(isOK){
                    cout << Cx << " " << Cy << " " << H << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}

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

def resolve():
    n,k = map(int, input().split())

    ds = []
    aks = []
    for i in range(k):
        ds.append(int(input()))
        aks.append(list(map(int, input().split())))

    dict = {}
    for i in aks:
        for j in i:
            dict[j] = 0

    print(n - len(dict.items()))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3 2
2
1 3
1
3"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3 3
1
3
1
3
1
3"""
        output = """2"""
        self.assertIO(input, output)

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

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

int main() {
  string n;
  cin >> n;
  vector<vector<vector<vector<ll>>>> dp0(n.size()+1,vector<vector<vector<ll>>>(11,vector<vector<ll>>(11,vector<ll>(11))));
  vector<vector<vector<vector<ll>>>> dp1(n.size()+1,vector<vector<vector<ll>>>(11,vector<vector<ll>>(11,vector<ll>(11))));
  dp1[0][0][0][0]=1;
  for(ll i=0;i<n.size();i++) {
    for(ll j=0;j<10;j++) {
      for(ll k=0;k<10;k++) {
        for(ll l=0;l<10;l++) {
          if(j==0&&k==0&&l==0) {
            dp0[i+1][j][k][l]+=dp0[i][j][k][l];
            dp0[i+1][j][k][l]+=dp1[i][j][k][l];
          }
          dp0[i+1][j+1][k][l]+=dp0[i][j][k][l];
          dp0[i+1][j][k+1][l]+=dp0[i][j][k][l];
          dp0[i+1][j][k][l+1]+=dp0[i][j][k][l];
          if(int(n[i]-'0')>7) {
            dp0[i+1][j+1][k][l]+=dp1[i][j][k][l];
            dp0[i+1][j][k+1][l]+=dp1[i][j][k][l];
            dp0[i+1][j][k][l+1]+=dp1[i][j][k][l];
          }
          else if(int(n[i]-'0')==7) {
            dp1[i+1][j+1][k][l]+=dp1[i][j][k][l];
            dp0[i+1][j][k+1][l]+=dp1[i][j][k][l];
            dp0[i+1][j][k][l+1]+=dp1[i][j][k][l];
          }
          else if(int(n[i]-'0')>5) {
            dp0[i+1][j][k+1][l]+=dp1[i][j][k][l];
            dp0[i+1][j][k][l+1]+=dp1[i][j][k][l];
          }
          else if(int(n[i]-'0')==5) {
            dp1[i+1][j][k+1][l]+=dp1[i][j][k][l];
            dp0[i+1][j][k][l+1]+=dp1[i][j][k][l];
          }
          else if(int(n[i]-'0')>3) {
            dp0[i+1][j][k][l+1]+=dp1[i][j][k][l];
          }
          else if(int(n[i]-'0')==3) {
            dp1[i+1][j][k][l+1]+=dp1[i][j][k][l];
          }
        }
      }
    }
  }
  ll ans=0;
  for(ll i=1;i<=10;i++) {
    for(ll j=1;j<=10;j++) {
      for(ll k=1;k<=10;k++) {
        ans+=dp1[n.size()][i][j][k]+dp0[n.size()][i][j][k];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static long sa = 0;
    public static long sb = 0;
    public static long su = 0;
    public static long sv = 0;


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();
        long Y = sc.nextLong();
        long n = (2 * Y - X) / 3;
        long m = (2 * X - Y) / 3;
        long MN = 1;
        long MM = 1;
        if((2 * Y - X) < 0 || (2 * X - Y) < 0){
            System.out.println(0);
            return;
        }

        if((2 * Y - X) % 3 != 0 || (2 * X - Y) % 3 != 0){
            System.out.println(0);
            return;
        }

        long c = 1000000007L;
        long a = 12345678900000L;
        long b = 100000L;
        a %= c;
//        System.out.println(a * modInv(b,c) % c);
        for (long i = n + 1; i < n + m + 1; i++) {
//            System.out.println(MN);
            MN *= i;
            MN %= c;
        }
        for (long i = 1; i < m + 1; i++) {
//            System.out.println(MM);
            MM *= i;
            MM %= c;
        }
        System.out.println(MN * modInv(MM,c) % c);
    }

    private static long modInv(long a, long m) {
        long b = m;
        long u = 1;
        long v = 0;
        while (b > 0) {
            long t = a / b;
            a -= t * b;
            u -= t * v;
            sa = a;
            sb = b;
            a = sb;
            b = sa;
            su = u;
            sv = v;
            u = sv;
            v = su;
        }
        u %= m;
        if(u < 0) u+=m;
        return u;
    }
}


Measured memory_bytes: 22740
#include<stdio.h>
#include<stdlib.h>
int binarySearch(int,int*,int);
int main(){
  int n1,n2,*N1,*N2,i,count=0;
  scanf("%d",&n1);
  N1 = (int *)malloc(n1 * sizeof(int));
  for(i=0;i<n1;i++){
    scanf("%d",&N1[i]);
  }
  scanf("%d",&n2);
  N2 = (int *)malloc(n2 * sizeof(int));
  for(i=0;i<n2;i++){
    scanf("%d",&N2[i]);
  }
  for(i=0;i<n2;i++){
    if(binarySearch(N2[i],N1,n1) == 1) count++;
  }
  printf("%d\n",count);
  return 0;
}
int binarySearch(int key,int *A,int n){
  int left=0,right=n,mid;
  while(left < right){
    mid = (left + right)/2;
    if(A[mid] == key) return 1;
    else if(key < A[mid]) right = mid;
    else left = mid + 1;
  }
  return 0;
}



Measured memory_bytes: 2320
//
//  main.cpp
//  Exercise
//
//

#include <algorithm>
#include <iostream>
#include <limits>
#include <math.h>
#include <tuple>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "string.h"
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <set>

using namespace std;

using int_t = long long;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2015

int main() {
    struct DataSet {
        vector<int> Ns;
        vector<int> Ms;
        DataSet(vector<int>&& aNs, vector<int>&& aMs) {
            Ns = aNs;
            Ms = aMs;
        };
    };
    vector<DataSet> probs;
    while (true) {
        int N, M;
        scanf("%d %d", &N, &M);
        if (N == 0 && M == 0) {
            break;
        }
        vector<int> Ns;
        Ns.reserve(N);
        vector<int> Ms;
        Ms.reserve(M);
        for (int i = 0; i < N; i++) {
            int Ni;
            scanf("%d", &Ni);
            Ns.push_back(Ni);
        }
        for (int i = 0; i < M; i++) {
            int Mi;
            scanf("%d", &Mi);
            Ms.push_back(Mi);
        }
        probs.emplace_back(move(Ms), move(Ns));
    }
    for (auto it = probs.begin(); it != probs.end(); ++it) {
        vector<int> Ms = move((*it).Ms);
        vector<int> Ns = move((*it).Ns);
        auto makeSubSums = [](const vector<int>& seq) {
            vector<int> subsums;
            subsums.reserve((seq.size() * (seq.size() + 1)) / 2);
            for (int i = 0; i < seq.size(); i++) {
                int sum = 0;
                for (int j = i; j < seq.size(); j++) {
                    sum += seq[j];
                    subsums.push_back(sum);
                }
            }
            sort(subsums.begin(), subsums.end());
            return subsums;
        };
        vector<int> MSums = makeSubSums(Ms);
        vector<int> NSums = makeSubSums(Ns);
        int count = 0;
        auto mit = MSums.begin();
        auto nit = NSums.begin();
        while (true) {
            if (mit == MSums.end() || nit == NSums.end()) {
                break;
            }
            if (*mit < *nit) {
                ++mit;
                continue;
            } else if (*mit > *nit) {
                ++nit;
                continue;
            }
            int commonVal = *mit;
            int cntM = 0;
            while (*mit == commonVal && mit != MSums.end()) {
                cntM++;
                ++mit;
            }
            int cntN = 0;
            while (*nit == commonVal && nit != NSums.end()) {
                cntN++;
                ++nit;
            }
            count += cntM * cntN;
        }
        printf("%d\n", count);
    }
    return 0;
}



Measured memory_bytes: 12104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    string ans = "";
    S[K - 1] = tolower(S[K - 1]);
    cout << S << endl;
}


Measured memory_bytes: 256
from collections import deque
import bisect

S = list(input())
T = list(input())

pos_S = {}
for i, s in enumerate(S):
  if s in pos_S:
    pos_S[s].append(i)
  else:
    pos_S[s] = deque([i])
x = 0
start = 0
for t in T:
  if t in pos_S:
    poss = pos_S[t]
    pos = bisect.bisect_left(poss, start)
    if pos >= len(poss):
      x += 1
      start = poss[0]+1
    else:
      start = poss[pos]+1
  else:
    x = -1
    break
if x == -1:
  print(-1)
else:
  print(x*len(S)+start)



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

using namespace std;
using namespace std::chrono;

#define rep(i,a,b) for(int i = a;i<(b);++i)
#define trav(a,v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

const ll big = 1000000007ll;
const ll big2 = 1000000009ll;
ll n,m,k,q,w,h,T;

vector<vector<ll> > C(100001, vector<ll>());

ll mark[100001] = {0};
ll P[2] = {0};
bool fail = 0;

void dfs(ll i,ll col){
    mark[i] = col;
    P[col-1]++;

    for(ll c1 = 0; c1 <sz(C[i]); c1++){
        ll a = C[i][c1];
        if(mark[a] != 0 && mark[a] == col){
            fail = 1;
            return;
        }
        if(mark[a] == 0){
            dfs(a,col%2+1);
        }
    }

}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d;

    cin >> n >> m;
    for(ll c1 =0 ; c1 < m; c1++){
        cin >> a >> b;a--;b--;
        C[a].push_back(b);
        C[b].push_back(a);
    }

    dfs(0,1);
    if(fail){
        cout << (n*(n-1))/2-m << "\n";
    }
    else{
        cout << (n*(n-1))/2-m-(P[0]*(P[0]-1))/2-(P[1]*(P[1]-1))/2 << "\n";
    }

    return 0;
}


Measured memory_bytes: 7808
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int M1 = sc.nextInt();
		int D1 = sc.nextInt();
		int M2 = sc.nextInt();
		int D2 = sc.nextInt();
		
		if(M1<M2){
			System.out.println("1");
		}else{
			System.out.println("0");
		}
    }
}


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

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)


// #define printf(a,...) if(0){}
using ll = int64_t;
constexpr ll mod = ll(1e9 + 7);

int main () {
  ios::sync_with_stdio(0); cin.tie(0);
  int TT = 1;
  // cin >> TT;
  while (TT--) {
    ll n;
    cin >> n;
    vector<int> A(n);
    for (auto& xx : A) cin >> xx;
    sort(A.begin(), A.end());
    if (A[0] == 1) {
      if (n > 1 && A[1] == 1) {
        cout << 0 << endl;
      } else {
        cout << 1 << endl;
      }
      continue;
    }
    bool has_2 = A[0] == 2;
    vector<int> old = A;
    vector<bool> seen(1e6+1);
    for (int i = 1; i < n; ++i) {
      if (old[i] == old[i-1]) {
        seen[A[i]] = true;
        A[i] = A[i-1] = -1;
      }
    }

    int ans = 0;

    for (int i = 0; i < n; ++i) {
      if (A[i] == -1) continue;
      seen[A[i]] = true;
      if (A[i] % 2 == 0 && has_2) {
        if (A[i] == 2) ++ans;
        continue;
      }
      bool good = true;
      ll x = A[i];
      int64_t l = 2, r = x / 2 + 1;
      while (l < r) {
        if (l*r < x) {
          ++l;
        } else if (l*r > x) {
          r = min(r-1, x/l);
        } else {
          if (seen[l] || seen[r]) {
            good = false;
            break;
          }
          ++l;
          --r;
        }
      }
      if (l*l == x) { // check sqrt(x)
        if (seen[l]) good = false;
      }
      if (good) {
//        cout << "good:" << x << endl;
      }
      ans += good;
    }
    cout << ans << endl;
  }
}

/*
7 2
*/


Measured memory_bytes: 5048
package main

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

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)
	writer := bufio.NewWriter(os.Stdout)

	var n, q int

	m := make(map[int]int, 0)
	fmt.Sscan(getNextLine(scanner), &n)
	ss := getIntList(scanner)
	fmt.Sscan(getNextLine(scanner), &q)
	tt := getIntList(scanner)
	for i := 0; i < q; i++ {
		m[tt[i]] = 1
	}
	ans := 0
	for i := 0; i < n; i++ {
		_, ok := m[ss[i]]
		if ok && m[ss[i]] > 0 {
			m[ss[i]]--
			ans++
		}
	}
	fmt.Fprintln(writer, ans)

	writer.Flush()
}



Measured memory_bytes: 1700
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int h, w;
char c[200];
char a[200][200];

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen(fname".in", "r", stdin);
	// freopen(fname".out", "w", stdout);
	scanf("%d%d", &h, &w);
	for(int i = 0; i < h; ++i){
		scanf("%s\n", c);
		string s = c;
		for(int j = 0; j < w; ++j)
			a[i][j] = s[j];
	}
	for(int i = 0; i < h + 2; ++i){
		for(int j = 0; j < w + 2; ++j){
			if(i == 0 || j == 0 || i == h + 1 || j == w + 1)
				printf("#");
			else
				printf("%c", a[i - 1][j - 1]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

template<class T>
void outvo(vector<T> v) {
  if (v.size() == 0) return;
  cout << v[0];
  for (int i = 1; i < v.size(); i++)
    cout << " " << v[i];
  cout << endl;
}

void solve() {
  int n; cin >> n;
  vector<ll> a(n+1), b(n+1);
  rep(i, n) cin >> a[i+1];

  for (int i = n; i >= 1; i--) {
    int sum = 0;
    for (int j = i; j <= n; j += i)
      sum ^= b[j];
    b[i] = sum^a[i];
  }

  vector<ll> ans;
  for (int i = 1; i <= n; i++)
    if (b[i]) ans.push_back(i);
  outl(ans.size());
  outvo(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  ll a,b,c,d; cin >> a >> b >> c >> d;
  ll ans = 0;
  if(0 <= a && 0 <= c){
    ans = b*d;
  }else if(b <= 0 && d <= 0){
    ans = a*c;
  }else{
    ans = max({a*d,b*c,a*c,b*d});
  }
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3656
def solve(n, score):
    score = sorted(score)
    return sum(score[1:-1])//len(score[1:-1])

def main():
    ans = []
    while True:
        n = int(input())
        if (n == 0):
            break
        score = [int(input()) for i in range(n)]
        ans.append(solve(n, score))
    
    for i in ans:
        print(i)

main()


Measured memory_bytes: 5600
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll N;
vector<ll> D;
vector<ll> check;

int main() {
	cin >> N;
	D.resize(N);
	for (ll n = 0; n < N; n++) {
		cin >> D[n];
	}
	check.resize(1e5 + 1,0);
	for (ll n = 0; n < N; n++) {
		check[D[n]]++;
	}
	ll ans = 1;
	for (ll n = 1; n < N; n++) {
		if (D[n] == 0)ans *= 0;
		ans *= check[D[n]-1];
		ans %= 998244353;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

template<class Monoid>
class SegmentTree {

public:
    /**
     * @param N size
     * @param e identity element
     * @param operation operation to merge `data`
     * @param updater operation to update `data`
     */
    SegmentTree(size_t N, Monoid e, function<Monoid(Monoid, Monoid)> operation,
                function<Monoid(Monoid, Monoid)> updater)
            : e(e), operation(operation), updater(move(updater)) {
        n = 1;
        while (n < N) {
            n *= 2;
        }
        data = vector<Monoid>(2 * n - 1, e);
        for (int i = n - 2; i >= 0; i--) {
            data[i] = operation(data[2 * i + 1], data[2 * i + 2]);
        }
    }

    /**
     * iの値をxに更新 ( 0-indexed )
     */
    void update(int i, Monoid x) {
        i += n - 1;
        data[i] = updater(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    /**
     * [a, b)の区間でクエリを実行
     */
    Monoid query(int a, int b) {
        return query(a, b, 0, 0, n);
    }

    /**
     * 添字でアクセス( 0-indexed )
     */
    Monoid operator[](int i) {
        return data[i + n - 1];
    }

private:
    int n;
    vector<Monoid> data;
    Monoid e;
    function<Monoid(Monoid, Monoid)> operation;
    function<Monoid(Monoid, Monoid)> updater;

    Monoid query(int a, int b, int k, int l, int r) {
        // 交差しない
        if (r <= a || b <= l) return e;
        // 区間 [a, b) に l, r が含まれる
        if (a <= l && r <= b) return data[k];
        // 左の子
        Monoid c1 = query(a, b, 2 * k + 1, l, (l + r) / 2);
        // 右の子
        Monoid c2 = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return operation(c1, c2);
    }
};


void solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    SegmentTree<ll> segmentTree(1e5 + 10, 0, [](ll a, ll b) { return a + b; }, [](ll a, ll b) { return b; });

    rep(i, N) {
        ll a = A[i];
        ll cnt = segmentTree.query(a, a + 1);
        segmentTree.update(A[i], a * (cnt/a + 1));
    }
    ll Q;
    cin >> Q;
    rep(i, Q) {
        ll b, c;
        cin >> b >> c;
        ll x = segmentTree.query(b, b + 1);
        segmentTree.update(b, 0);
        ll y = segmentTree.query(c, c + 1);
        segmentTree.update(c, (x/b + y/c) * c);
        ll ans = segmentTree.query(0, 1e5 + 5);
        cout << ans << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 6116
inpl = lambda: list(map(int,input().split()))
N = int(input())
S = input()
NE = S.count('E')
ans = cur = NE
for s in S:
    if s == 'E':
        cur -= 1
        if cur < ans:
            ans = cur
    else:
        cur += 1
print(ans)

Measured memory_bytes: 41560
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rep1n(i, n) for(int i=1;i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
int main() {

	int n, m;
	cin >> n >> m;
	vector<string>a(n), b(m);
	rep(i, n)cin >> a[i];
	rep(i, m)cin >> b[i];
	rep(i, n)rep(j, n) {
		if (a[i][j] == b[0][0]) {
			bool all = true;
			rep(k, m)rep(l, m) {
				if (i + k >= n || j + l >= n || a[i + k][j + l] != b[k][l]) {
					all = false;
					break;
				}
			}
			if (all) {
				Yes(all);
				return 0;
			}
		}
	}
	cout << "No";

	return 0;
}





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

int main(){
	int n; cin>>n;
	string s[n]; rep(i,n) cin>>s[i];
	int m; cin>>m;
	int cnt=0;
	rep(i,m){
		string t; cin>>t;
		bool flg=0;
		rep(j,n){
			if(t==s[j]) flg=1;
		}
		if(flg){
			cnt++;
			if(cnt%2==1) cout<<"Opened by "<<t<<endl;
			else cout<<"Closed by "<<t<<endl;
		}else{
			cout<<"Unknown "<<t<<endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3228
class Facts:

  def __init__(self, mod=10**9+7, n_max=1):
    self.mod     = mod
    self.n_max   = n_max
    self.fact    = [1, 1]
    self.inv     = [0, 1]
    self.factinv = [1, 1]
    if 1 < n_max:
      self.setup_table(n_max)

  def cmb(self, n, r):
    if r < 0 or n < r:
      return 0
    if self.n_max < n:
      self.setup_table(n)
    return self.fact[n] * (self.factinv[r] * self.factinv[n-r] % self.mod) % self.mod

  def factorial(self, n):
    if self.n_max < n:
      self.setup_table(n)
    return self.fact[n]
    
  def hom(self, n, k):
    return self.cmb(n+k-1, k)

  def prm(self, n, k):
    if self.n_max < n:
      self.setup_table(n)
    return self.fact[n] * self.factinv[n-k] % self.mod

  def setup_table(self, t):
    for i in range(self.n_max+1,t+1):
      self.fact.append( self.fact[-1] * i % self.mod )
      self.inv.append( -self.inv[mod % i] * (self.mod // i) % self.mod )
      self.factinv.append( self.factinv[-1] * self.inv[-1] % self.mod )
    self.n_max = t

# ABC156 Roaming
mod = 10 ** 9 + 7

n, k = map(int, input().split())

ans = 0
f = Facts(mod)

for i in range(0, min(n-1, k)+1):
  ans += f.cmb(n,i) * f.hom(n-i,i) % mod
  if ans >= mod:
    ans -= mod 

print(ans)

# ABC167 E 2020/5/11
# mod = 998244353

# n, m, k = map(int, input().split())

# ans = 0
# f = Facts(mod)
# t = m * pow(m-1, n-1-k, mod)

# for i in range(k,-1,-1):
#   ans += f.cmb(n-1,i) * t % mod
#   t = t * (m-1) % mod

# print(ans % mod)


Measured memory_bytes: 81136
import java.util.Scanner;

class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        for (int i = n - 1; i >= 0; i--) {
            System.out.print(a[i] + ((i == 0) ? "" : " "));
        }
        
        System.out.println("");
    }

}


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


int main() {
    int n;

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

}
sort(a.begin(), a.end() );
int ans=0;

for (int i = 0; i < n-2; i++)
{
    for(int j=i+1;j<n-1;j++)
    {
        for (int k=j+1 ; k < n; k++)
        {
           if (a[i]!=a[j]&&a[i]!=a[k]&&a[j]!=a[k])
           {
              if (a[i]+a[j]>a[k])
              {
                  ans++;
              }
              
           }
           
        }
        
    }
}
cout<<ans<<endl;
}

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

using namespace std;

#define fo(i,n) for(int i=0; i<n; i++)
#define Fo(i,k,n) for(int i=k; i<n; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it=a.begin(); it!=a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

int N;
vvi edges;

const int mod = 1e9+7;

ll mul(int a, int b){
    return (ll)a*b%mod;
}

ll add(ll a, ll b){
    return (a+b)%mod;
}

pii dfs(int node, int parent){
    ll blk = 1;
    ll wht = 1;
    // cout<<node<<endl;
    for(auto child:edges[node]){
        if(child!=parent){
            auto curr = dfs(child, node);
            ll wb = mul(wht, curr.second);
            ll ww = mul(wht, curr.first);
            ll bw = mul(blk, curr.first);
            blk = bw;
            wht = add(wb, ww);
            // cout<<blk<<" "<<wht<<" "<<wb<<" "<<ww<<" "<<bw<<endl;
        }
    }
    // cout<<blk<<" "<<wht<<endl;
    return make_pair(wht, blk);
}

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

    cin>>N;
    edges.resize(N+1);
    Fo(i,1,N){
        int x,y;
        cin>>x>>y;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }
    pii ans = dfs(1, -1);
    cout<<add(ans.first, ans.second)<<endl;
    
    return 0;
}

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

using namespace std;
const long ma = 1000010;
bool hams[ma];
void ham(long);

void gen(){
    for(int i=0;i<ma;i++){
        hams[i] = false;
    }
    ham(1);
}

void ham(long n){
    if(n > ma) return;
    if(hams[n]) return;
    hams[n] = true;
    ham(2*n);
    ham(3*n);
    ham(5*n);
}

int count(int m,int n){
    int c;
    for(int i=m;i<n+1;i++){
        if(hams[i]) c++;
    }
    return c;
}

int main(){
    gen();
    int m,n;
    while(true){
        cin >> m;
        if(m==0)break;
        cin >> n;
        cout << count(m,n) << endl;
    }
}

Measured memory_bytes: 0
import java.util.*;
import java.lang.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int length = scan.nextInt();
        int k = scan.nextInt();
        int[] numbers = new int[length];
        for (int i = 0; i < length; i++){
            numbers[i] = scan.nextInt();
        }
        int[] result = new int[length];
        for (int i = 0; i < length; i++){
            result[i] = 999999999;
        }
        result[0] = 0;
        for (int i = 0; i < length; i++){
            for (int j = 1; j <= k; j++){
                if (i + j < length) result[i + j] = Math.min(result[i + j],result[i] + (int)Math.abs(numbers[i] - numbers[i+j]));
            }
        }
        System.out.println(result[length -1]);
        
        scan.close();
    }
}

Measured memory_bytes: 50912
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

ans=b[a[0]-1]
for i in range(1,n):
    ans+=b[a[i]-1]
    if a[i]==a[i-1]+1:
        ans+=c[a[i-1]-1]
print(ans)


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

constexpr int MOD = 1000000007;

class mint {
  int n;
public:
  mint(int n_ = 0) : n(n_) {}
  explicit operator int() { return n; }
  friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
  friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
  friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
  friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
  friend mint &operator+=(mint &a, mint b) { return a = a + b; }
  friend mint &operator-=(mint &a, mint b) { return a = a - b; }
  friend mint &operator*=(mint &a, mint b) { return a = a * b; }
  friend bool operator==(mint a, mint b) { return a.n == b.n; }
  friend bool operator!=(mint a, mint b) { return a.n != b.n; }
  friend istream &operator>>(istream &i, mint &a) { return i >> a.n; }
  friend ostream &operator<<(ostream &o, mint a) { return o << a.n; }
};

mint dp[100010][13];

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  string s;
  cin >> s;
  dp[0][0] = 1;
  rep(i, s.size()) {
    rep(j, 13) {
      if (s[i] == '?') {
        rep(k, 10) {
          dp[i + 1][(j * 10 + k) % 13] += dp[i][j];
        }
      } else {
        dp[i + 1][(j * 10 + s[i] - '0') % 13] += dp[i][j];
      }
    }
  } 
  cout << dp[s.size()][5] << endl;
}

Measured memory_bytes: 5632
#include <stdio.h>
#include <stdlib.h>
#define rep(i,n) for(int i = 0;i < (n);++i)

int pcnt(int n){
    int B;
    int sum = 0;
    while(n != 0){
        B = n%2;
        n = (n-B)/2;
        if(B == 1)sum++;
    }
    return sum;
}

int f(int x){
    if(x == 0) return 0;
    return f(x%pcnt(x)) + 1;
}

int main(){
    int N,pc = 0;
    scanf("%d",&N);
    char ch[N];
    scanf("%s",ch);
    for(int i = 0;i < N;i++){
        if(ch[i] == '0')ch[i] = 0;
        else {
            ch[i] = 1;
            pc++;
        }
    }

    int ans[N];
    rep(i,N) ans[i]=0;
    rep(b,2){
        int npc = pc;
        if(b == 0) npc++;else npc--;
        if(npc <= 0) continue;
        int r0 = 0;
        rep(i,N){
            r0 = (r0*2)%npc;
            r0 += ch[i];
        }
        int k = 1;
        for(int i = N - 1;i >= 0;--i){
            if(ch[i] == b){
                int r = r0;
                if(b == 0) r = (r+k)%npc;
                else r = (r-k+npc)%npc;
                ans[i] = f(r) + 1;
            }
            k = (k*2)%npc;
        }
    }
    rep(i,N) printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 2704
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
const ll INF = 1010101010;
ll dp[110][101010]; //N*Wの配列

int max_3(int x, int y, int z){
  if(x>=y&&x>=z) return x;
  else if(y>=z&&y>=x) return y;
  else return z;
}

int main(){
  int n, W;
  cin >> n >> W;
  vector<int> w(n), v(n);
  rep(i,n) cin >> w[i] >> v[i];

  rep(i,n){
    int w_i = w[i];
    int v_i = v[i];
    rep(j,W+1){
      if(j-w_i>=0) dp[i+1][j] = max(dp[i][j],dp[i][j-w_i]+v[i]);
      else dp[i+1][j] = dp[i][j];
    }
  }
  /*rep(i,n+1){
    rep(j,W+1){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }*/
  cout << dp[n][W] << endl;
}

Measured memory_bytes: 79360
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    string s; cin >> s;
    int N; N = s.size();
    long long res = 0;
    repp(bit,0,1<<(N-1)) {
        long long t = 0;
        repp(i,0,N) {
            t = 10 * t + s[i] - '0';
            if (bit & (1 << i)) {
                res += t;
                t = 0;
            }
        }
        res += t;
    }
    cout << res << endl;
}



Measured memory_bytes: 256