akhauriyash/Code-Regression huggingface dataset:
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=3e5+10,oo=0x3f3f3f3f,MOD=998244353;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int res=0;
    loop(n,i,0){
        int freq[30]={},cnt=0;
        loop(i+1,j,0)
            freq[s[j]-'a']=1;
        loop(n,j,i+1)
            cnt+=(freq[s[j]-'a']==1),freq[s[j]-'a']=2;
        max_self(res,cnt);
    }
    cout<<res<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


Measured memory_bytes: 3608
N, K = list(map(int, input().split()))

d = [0] * K
A = []
cnt = [0] * N
ans = 0


for i in range(K):
    d[i] = int(input())
    array = list(map(int, input().split()))
    A.append(array)

for i in range(K):
    for j in range(len(A[i])):
        cnt[A[i][j]-1] += 1

for i in range(N):
    if cnt[i] == 0:
        ans += 1
print(ans)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const ll INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

int cost(pii a,pii b) {
    return abs(a.first-b.first)+abs(a.second-b.second);
}
signed main() {
    int H,W,D;
    cin>>H>>W>>D;
    vector<vector<int>> A(H,vector<int>(W));
    cin>>A;
    vector<pii> pos(H*W);
    REP(i,H) {
        REP(j,W) {
            pos[A[i][j]-1]={i,j};
        }
    }
    vector<int> sum(H*W,0);
    REP(i,H*W) {
        if(i-D>=0) {
            sum[i]=cost(pos[i-D],pos[i]);
        }
    }
    REP(i,H*W) {
        if(i-D>=0) sum[i]+=sum[i-D];
    }

    int Q;
    cin>>Q;
    while(Q--) {
        int L,R;
        cin>>L>>R;
        R--,L--;
        cout<<sum[R]-sum[L]<<endl;
    }
    return 0;
}



Measured memory_bytes: 3968
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        int n; cin >> n;
        vi a(n);
        map<int, int>mp;
        for(int i = 0; i<n; i++){
            cin >> a[i];
            mp[a[i]] = i+1;
        }
        for(int i = 1; i<=n; i++){
            cout<<mp[i]<<' ';
        }
        cout<<endl;


return 0;
}



Measured memory_bytes: 5888
//written by libra9z
#include <set>
using namespace std;
set <int> st;
int main()
{
	int n;
	__builtin_scanf("%d",&n);
	while (n--)
	{
		int x;
		__builtin_scanf("%d",&x);
		if (!st.count(x))
		{
			st.insert(x);
		}
		else
		{
			st.erase(x);
		}
	}
	__builtin_printf("%d\n",(int)st.size());
	return 0;
}


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

int main() {

int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(max(a,c)-min(a,c)<=d){cout<<"Yes"<<endl;}
  else if(max(a,b)-min(a,b)<=d&&max(a,c)-min(a,c)<=d){cout<<"Yes"<<endl;}
    else if(max(b,c)-min(b,c)<=d&&max(a,c)-min(a,c)<=d){cout<<"Yes"<<endl;}
    else if(max(a,b)-min(a,b)<=d&&max(b,c)-min(b,c)<=d){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}

}



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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init));

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-6 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

void Correct(complex<double> &a){
  double real = a.real();
  double imag = a.imag();
  if(abs(real) == 0) real = 0;
  if(abs(imag) == 0) imag = 0;
  a = complex<double>(real,imag);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  while(cin >> n && n){
    ll m;
    vector<vector<complex<double>>> v(8);
    vector<vector<complex<double>>> v2(n+1);
    double a,b;
    cin >> m;
    v[0].resize(m);
    v[4].resize(m);
    rep(i,m){
      cin >> a >> b;
      v[0][i] = complex<double>(a,b);
    }
    auto tmp = v[0];
    reverse(all(tmp));
    v[4] = tmp;
    REP(i,1,m){
      v[0][i] -= v[0][0];
      v[4][i] -= v[4][0];
    }
    v[0][0] -= v[0][0];
    v[4][0] -= v[4][0];
    REP(j,1,4){
      v[j].resize(m);
      v[j+4].resize(m);
      REP(i,0,m){
        v[j][i] = v[j-1][i] * complex<double> (0,1);
        v[j+4][i] = v[j+3][i] * complex<double> (0,1);
        Correct(v[j][i]);
        Correct(v[j+4][i]);
      }
    }
    rep(i,n){
      cin >> m;
      v2[i].resize(m);
      rep(j,m){
        cin >> a >> b;
        v2[i][j] =complex<double>(a,b);
      }
      REP(j,1,m){
        v2[i][j] -= v2[i][0];
      }
      v2[i][0] -= v2[i][0];
    }
    rep(i,n){
      rep(j,8){
        if(v[j] == v2[i]){
          cout << i + 1 << endl;
          break;
        }
      }
    }
    cout << "+++++"<<endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
const int MAX = 100005;
const int MOD = 1000000007;
#define F first

#define S second

void solve()
{
	ll n;
	cin>>n;
	vector<ll> arr(n);
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	sort(arr.begin(),arr.end());
	ll ans=arr[n/2]-arr[n/2-1];
	cout<<ans<<endl;
	return;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x, ll y, ll p)  
{  
    ll res = 1;x = x % p;if (x == 0)return 0;while (y > 0)  
    {if (y & 1) res = (res*x) % p;  y = y>>1; x = (x*x) % p;  }  return res;  
}
bool sortinrev(const pair<vector<int>,int>&a,const pair<vector<int>,int>&b){if(a.fi==b.fi)return b.se>a.se;return a.fi>b.fi;}
void run(vector<int>v){for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;}
void solve()
{
    int n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    ll dp[n];
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
        if(i>=2)
            dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
        else
            dp[i] = dp[i-1]+abs(a[i]-a[i-1]);
    }
    cout<<dp[n-1]<<endl;
    
    

}
int main() 
{ 
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    
        solve();
    
        
    
    
    return 0; 
} 

Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
	int A,B,C,D;
	int i,n;
	scanf("%d%d%d%d",&A,&B,&C,&D);
	n=0;
	for(i=A;i<B;i++)
	{
		if(i>=C&&i<D)
		{
			n++;
		}
	}
	printf("%d\n",n);
	return 0;
}

Measured memory_bytes: 128
#include<map>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
map<char,int> a;
map<pair<char,int>,int> b;
int fn(string s){
  if(s[0]>='0'&&s[0]<='9'){
    return atoi(s.c_str());
  }else{
    if(a.count(s[0])){
      int p=fn(s.substr(2,s.length()-3).c_str());
      if(p>=0&&p<a[s[0]]){
	if(b.count(make_pair(s[0],p)))
	  return b[make_pair(s[0],p)];
      }
    }
  }
  return -1;
}
int main(){
  int h,i;
  string s;
  cin>>s;
  while(s[0]!='.'){
    a.clear();
    b.clear();
    h=0;
    for(i=1;s[0]!='.';i++){
      if(s.find('=')==string::npos){
	a[s[0]]=atoi(s.substr(2,s.length()-3).c_str());
      }else{
	if(a.count(s[0])){
	  int p=fn(s.substr(2,s.find('=')-3));
	  if(p>=0&&p<a[s[0]]){
	    int q=fn(s.substr(s.find('=')+1,s.length()-s.find('=')-1));
	    if(q>=0){
	      b[make_pair(s[0],p)]=q;   
	    }else{
	      if(h==0)
		h=i;
	    }
	  }else{
	    if(h==0)
	      h=i;
	  }
	}else{
	  if(h==0)
	    h=i;
	}
      }
      cin>>s;
    }
    cout<<h<<endl;
    cin>>s;
  }
  return 0;
}

Measured memory_bytes: 0
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n, m, q := ri(), ri(), ri()
	ar := make([][]int, n+1)
	for i := range ar {
		ar[i] = make([]int, n+1)
	}
	for i := 0; i < m; i++ {
		l, r := ri(), ri()
		for j := 0; j <= l; j++ {
			ar[j][r]++
		}
	}
	for i := 0; i < q; i++ {
		l, r := ri(), ri()
		sum := 0
		for j := l; j <= r; j++ {
			sum += ar[l][j]
		}
		fmt.Println(sum)
	}
}

var sc = bufio.NewScanner(os.Stdin)

func ri() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}


Measured memory_bytes: 6016
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())

def solve():
    n = INT()
    Q = [tuple(MAP1()) for _ in range(n-1)]

    deg = [0]*n
    adj = [[] for _ in range(n)]
    color = dict()

    for a, b in Q:
        deg[a] += 1
        deg[b] += 1
        adj[a].append(b)
        adj[b].append(a)

    def dfs(s, p):
        nouse = -1
        if p > -1:
            nouse = color[(min(s,p),max(s,p))]
        c = 1
        for t in adj[s]:
            if t == p:
                continue
            if c == nouse:
                c += 1
            color[(min(s,t),max(s,t))] = c
            dfs(t,s)
            c += 1
    
    dfs(1,-1)
    
    print(max(deg))
    for a, b in Q:
        print(color[(a, b)])

if __name__ == '__main__':
    solve()

Measured memory_bytes: 101332
N = int(input())
S = input()

white_count = S.count(".")
black_count = 0
ans = white_count
for s in S:
    if s == "#":
        black_count += 1
    else:
        white_count -= 1
    if ans > black_count + white_count:
        ans = black_count + white_count

print(ans)

Measured memory_bytes: 3500
import sys
N = int(input())
array_a = list(map(int,input().split()))
array_b = list(map(int,input().split()))
array_c = list(map(int,input().split()))

if not ( 2 <= N <= 20 ):sys.exit()
if not ( 1 <= min(array_a) and max(array_a) <= N ): sys.exit()
if not ( 1 <= min(array_b) and max(array_b) <= 50 ): sys.exit()
if not ( 1 <= min(array_c) and max(array_c) <= 50 ): sys.exit()

confortable = 0
before = -1
for I in range(len(array_a)):
    pos = array_a[I]
    confortable += array_b[pos-1]
    if before + 1 == array_a[I]:
        confortable += array_c[before-1]
    before = array_a[I]
print(confortable)

Measured memory_bytes: 9192
from collections import Counter

n = int(input())
L = list(map(int, input().split()))
L1 = L[::2]
L2 = L[1::2]
c1 = Counter(L1).most_common()
c2 = Counter(L2).most_common()
if len(set(L1)) == len(set(L2)) == 1:
    if c1[0] == c2[0]:
        print(len(L1))
    else:
        print(0)
else:
    if c1[0] != c2[0]:
        print(n - c1[0][1] - c2[0][1])
    else:
        print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))


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

#define endl "\n"

typedef long long ll;
typedef pair <ll, ll> pii;
typedef long double ld;

const ll D = 100007;
const ll Inf = 1000000007;
ll n,m,k;
ll a,b,c;
ll v[D];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>a>>b>>c;
    cout<<c/a*b;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
int main(void){
    int N ;
    
    for(;;){
        bool flag = false ;
        map<long int,int> mp ;
        
        cin >> N ;
        if(N == 0) break ;
        for(int i=0;i<N;i++){
            long int t ;
            cin >> t ;
            mp[t]++ ;
            if(mp[t]==N/2+1){
                flag = true ;
                cout << t  ;
            }
        }
        
        if(!flag) cout << "NO" << ' ' << "COLOR" ;
        cout << endl ;
    }
   
    
}

Measured memory_bytes: 5020
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

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

using namespace std;

int main() {
    string S;
    int64_t K;
    cin >> S >> K;
    for(auto& c: S) {
        if(c == 'a') {
            continue;
        }
        auto d = 'z' - c + 1;
        if(d <= K) {
            c = 'a';
            K -= d;
        }
    }
    K %= 26;
    S[S.size()-1] += K;

    cout << S << endl;

    return 0;
}



Measured memory_bytes: 3244
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int dp[3111][3111];
vector<char> s[3111][3111];
int main() {
	string a, b;
	cin >> a >> b;
	a = " " + a;
	b = " " + b;
	for (int i = 1; i < a.size(); i++) {
		for (int j = 1; j < b.size(); j++) {
			if (a[i] == b[j]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}
			else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	string h;
	int i = a.size()-1, j = b.size()-1;
	while (i > 0 && j > 0) {
		if (dp[i][j] == dp[i - 1][j]) {
			i--;
		}
		else {
			if (dp[i][j] == dp[i][j - 1]) {
				j--;
			}
			else {
				if (dp[i][j] == dp[i - 1][j - 1] + 1) {
					h = a[i] + h;
					i--;
					j--;
				}
			}
		}
	}
	cout << h;
	return 0;
}

Measured memory_bytes: 266848
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  if (n%1000 == 0)
  {
    cout << 0 << endl;
  }else
  {
    cout <<  (n/1000+1)*1000-n << endl;
  }
  
  
  
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

//https://arc061.contest.atcoder.jp/tasks/arc061_a 

int main() {
    string S; cin >> S;

    ll ans = 0;
    int len = S.length();
    REP(mask, 1 << (len - 1)) {

        ll num = S[0] - '0';
        REP(i, len - 1) {

            if (mask & 1 << i) {
                ans += num;
                num = 0;
            }

            num = num * 10 + S[i + 1] - '0';
        }

        ans += num;
    }

    cout << ans << "\n";

    return 0;
}


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

string f(string s)
{
 bool f = true;
 for(int i = 0;i < s.length();i++)
 {
  switch(i % 2)
  {
  case 0:
   if(s[i] != 'R' && s[i] != 'U' && s[i] != 'D')
    f = false;
   break;
  case 1:
   if(s[i] != 'L' && s[i] != 'U' && s[i] != 'D')
    f = false;
   break;
  }
 }
 return f ? "Yes" : "No";
}

int main()
{
 string s;
 cin >> s;
 cout << f(s) << endl;
 return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sync ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD  1000000007 
int powm(int base,int exp,int mod=MOD) {int ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
int32_t main()
{
	int n;
	cin>>n;
	int a[n],b[n];
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	int ans = INT_MIN;
	int count  = 0;
	for(int i=0;i<n;i++){
		if(a[i]==b[i])
			count++;
		else{
			ans = max(ans, count);
			count = 0;
		}
	}
	ans = max(ans, count);
	if(ans >= 3)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

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

int main(){
  string str;
  getline(cin,str);
  for(int i=0;i<(int)str.size();i++){
    if('a'<=str[i]&&str[i]<='z'){
      str[i]=str[i]-'a'+'A';
    }else if('A'<=str[i]&&str[i]<='Z'){
      str[i]=str[i]-'A'+'a';
    }
  }
  cout<<str<<endl;
  return 0;
}



Measured memory_bytes: 3152
#abc174_c

k=int(input())

# kの倍数が登場 -> 77...777%k==0となる最小の77の長さは？
if k%2==0:
    print(-1)
    exit()
if k==1:
    print(1)
    exit()
if k==7:
    print(1)
    exit()

rem=7%k
for i in range(2,k+1):
    rem=(rem*10+7)%k
    if rem==0:
        print(i)
        exit()
print(-1)
    

Measured memory_bytes: 9168
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    int a = scanner.nextInt();
		    int b = scanner.nextInt();
		    
		    if( a%2 != 0 && b%2 != 0 ) 
		    {
		    	System.out.println("Yes");
		    }
		    else 
		    {
		    	System.out.println("No");
		    }
		    
		    scanner.close(); }
		  }

Measured memory_bytes: 21460
#include<bits/stdc++.h>
#define INF (1e9)
#define M 200005
using namespace std;

vector<int> S[M];
int n, a[21];
double dp[21][M];

int main(){
  
  for(int i=1;i<=M;i++){
    
    for(int j=1;j*j<=i;j++)
      if(i%j==0){
	S[i].push_back(j);
	if(i!=j) S[i].push_back(i/j);
      }
    
    sort(S[i].begin(),S[i].end());
    
  }
  
  cin>>n;
  
  for(int i=0;i<n;i++) cin>>a[i];
  
  reverse(a,a+n);
  
  for(int i=0;i<=n;i++)
    for(int j=0;j<M;j++) dp[i][j]=INF;

  for(int i=1;i<M;i++) dp[0][i]=0;
  
  for(int i=0;i<n;i++){
    
    for(int j=1;j<M;j++){
      
      if(dp[i][j]==INF) continue;
      
      for(int k=0;k<S[j].size();k++){
	
	int nj = S[j][k];
	double ncost = max(dp[i][j], 1.0 * abs(a[i] - S[j][k]) / a[i]);
	
	dp[i+1][nj] = min(dp[i+1][nj], ncost);
	
      }
      
    }
    
  }
  
  double ans = INF;
  
  for(int i=1;i<M;i++) ans = min(ans, dp[n][i]);

  printf("%.10f\n", ans);
  
  return 0;
}

Measured memory_bytes: 55740
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

#define int long long

signed main(void) {
  int i,j;
  int n;
  cin>>n;
  int a=sqrt(n);
  //  cout<<"a"<<a<<endl;                            
  while(n%a)a--;
  int tmp=n/a;
  //  cout<<a<<" "<<tmp<<endl;                       
  int ans=1;
  while(tmp/10){
    ans++;
    tmp/=10;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
n,*a=gets(p).split.map(&:to_i)
a.sort!
max=a.last
idx=a.bsearch_index{|v|2*v>max}
idx=0 unless idx
r = (max-2*a[idx]).abs<(max-2*a[idx-1]).abs ? a[idx] : a[idx-1]
puts "%d %d"%[max,r]

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

int main(){
    int X, N;
    cin >> X >> N;
    if(N == 0){
        cout << X << endl;
        return 0;
    }
    vector<int> p(N);
    rep(i, N) cin >> p[i];
    int ans1 = 0, ans2 = 0;
    int x = X;
    
    rep(i,N){
        bool t = true;
        rep(j,N){
            if(x == p[j]){
               t = false;
               break;
            }
        }
        if(t){
            ans1 = x;
            break;
        }
        x++;
    }
     x = X;

    rep(i,N){
        bool t = true;
        rep(j,N){
            if(x == p[j]){
               t = false;
            }
        }
        if(t){
            ans2 = x;
            break;
        }
        x--;
    }
    int ans = min(ans1, ans2);
    int an1 = ans1;
    int an2 = ans2;
    an1 = abs(X - ans1);
    an2 = abs(X - ans2);
    if(an1 < an2) cout << ans1 << endl;
    if(an1 > an2) cout << ans2 << endl;
    if(an1 == an2) cout << ans << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int main()
{
int s;
cin>>s;
int a=s%100,b=0;
if (a==s)
{
    b=0;
}
else
{
   b=(s-a)/100;
}


if (a==0&&b==0)
{
    cout<<"NA"<<endl;
}

else if (a<=12&&b<=12&&a!=0&&b!=0)
{
    cout<<"AMBIGUOUS"<<endl;
}
else if (a<=12&&a!=0)
{
    cout<<"YYMM"<<endl;

}
else if (b<=12&&b!=0)
{
    cout<<"MMYY"<<endl;
}
else
{
    cout<<"NA"<<endl;
}

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(n):
    if a[i] > i + 1:
        print(-1)
        exit()
for i in range(n):
    for i in range(n - i)[-1::-1]:
        if a[i] == i + 1:
            ans.append(a[i])
            del a[i]
            break
for i in ans[-1::-1]:
    print(i)

Measured memory_bytes: 9152
n = list(map(int, input().split()))
dec_num, base_num = n[0], n[1]
ans, n = "", 0

while True:
    if dec_num <= 0:
        break
    
    n = dec_num % base_num
    dec_num = int(dec_num / base_num)
    ans += str(n)

if ans[:1:-1] == "0":
    ans += "1"

ans[::-1]
print(len(ans))

Measured memory_bytes: 3064
def main():
    N, T = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    AB.sort()
    A = [a[0] for a in AB]
    B = [b[1] for b in AB]

    ans = 0
    dp1 = [[0]*(T+1) for _ in range(N+1)]
    for i in range(N):
        for j in range(T):
            t = j - A[i]
            if 0 <= t:
                dp1[i+1][j] = max(dp1[i][j], dp1[i][t] + B[i])
            else:
                dp1[i+1][j] = dp1[i][j]
        ans = max(ans, dp1[i][T-1] + B[i])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 145508
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <typeinfo>
//#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>

using namespace std;

long long numburger(int n)
{
  if (n == 0)
  {
    return 1;
  }
  else
  {
    return 2 * numburger(n - 1) + 3;
  }
}

long long numpatty(int n)
{
  if (n == 0)
  {
    return 1;
  }
  else
  {
    return 1 + numpatty(n - 1) * 2;
  }
}

long long answer(int n, long long x)
{
  if (n == 0)
  {
    if (x <= 0)
    {
      return 0;
    }
    else
    {
      return 1;
    }
  }
  if (x == 1)
  {
    return 0;
  }
  long long numB = numburger(n - 1);
  if (1 < x && x <= 1 + numB)
  {
    return answer(n - 1, x - 1);
  }
  else if (x == 2 + numB)
  {
    return numpatty(n - 1) + 1;
  }
  else if (2 + numB < x && x <= 2 + 2 * numB)
  {
    return numpatty(n - 1) + 1 + answer(n - 1, x - 2 - numB);
  }
  else if (x == 3 + 2 * numB)
  {
    return 2 * numpatty(n - 1) + 1;
  }
}

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

  cout << answer(n, x) << endl;

  return 0;
}

Measured memory_bytes: 256
main = mapM_ process . takeWhile (/= "0 0") . lines =<< getContents
  where process line = do
                          putStrLn $ replicate w '#'
                          putStr $ unlines (replicate (h-2) $ "#"++(replicate (w-2) '.')++"#")
                          putStrLn $ replicate w '#'
                          putStrLn ""
                          where [h,w] = map (read::String->Int) $ words line

Measured memory_bytes: 4300
#include <iostream>
#include <string>
using namespace std;
int main() {
  
  string S;
  cin >> S;
  string strMonth = S.substr(5, 2);
  int month = stoi(strMonth);
  if (month <= 4)
    cout << "Heisei" << endl;
  else
    cout << "TBD" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long N = sc.nextLong();

        long ans = 0;
        if(N >= B-1){
            ans = A*(B-1)/B;
        }else{
            ans = A*N/B;
        }

        System.out.println(ans);
    }
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	string s;
	cin>>n>>s;
	vector<int>cnt(26,1);
	for(auto&i:s)++cnt.at(i-'a');
	const int mod=1e9+7;
	int ans=accumulate(cnt.begin(),cnt.end(),1,[&](auto a,auto b){return (int64_t)a*b%mod;});
	cout<<ans-1<<"\n"s;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstring>
#include<cstdlib>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
int n,K;
ll dp[310][310],a[310];
int main()
{
	cin>>n>>K;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    memset(dp,inf,sizeof(dp));
    dp[0][0]=0;
    ll ans=1e15;
    for(int i=1;i<=n;i++)
    for(int j=0;j<i;j++)
    for(int k=i-1;k>=0;k--)
    dp[i][k+1]=min(dp[i][k+1],dp[j][k]+max(0ll,a[i]-a[j]));
    for(int i=0;i<=n;i++)
    for(int j=0;j<=n;j++)
    if(j>=n-K) ans=min(ans,dp[i][j]);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

 
public class Main {
 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n  = sc.nextInt();
		int d  = sc.nextInt();
		int ans = 0;
		
		for(int i = 0; i  < n; i++) {
			double distance = Math.sqrt(Math.pow(sc.nextInt(), 2) + Math.pow(sc.nextInt(), 2));
			if(distance <= d) {
				ans++;
			}
		}

		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 59568
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)

	is_all_even := true
	for i := 0; i < N; i++ {
		var a int
		fmt.Scan(&a)
		if a%2 == 1 {
			is_all_even = false
			break
		}
	}

	if is_all_even {
		fmt.Println("second")
	} else {
		fmt.Println("first")
	}
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

bool ml(string x) {
	for (int i = 0;i <= x.size() / 2;i++) {
		//cout << x[i] << " " << x[x.size() - 1 - i] << endl;
		if (x[i] != x[x.size() - 1 - i]) return false;
	}
	return true;
}

int main(){

	string s;

	cin>> s;

	if (ml(s)) {
		//cout << s.substr(0, (s.size() - 1) / 2) << endl;
		if (ml(s.substr(0, (s.size() - 1) / 2))) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
long long gcd(long long a, long long b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
long long test[223456];
int main() {
	long long n, k, sum = 0, ans = 0; cin >> n >> k;
	int uiop[223456] = { 0 };
	for (int h = 0; h < n; h++) {
		cin >> test[h];
	}
	sort(test, test + n);
	for (int h = 0; h < n; h++) {
		uiop[test[h]]++;
	}
	sort(uiop, uiop + 223456);
	for (int h = 223456; h >= 0; h--) {
		if (uiop[h] > 0) {
			sum++;
		}
	}
	if (sum <= k) {
		cout << 0 << endl;
		cin >> n; return 0;
	}
	for (int h = 223456 - sum; h < 223456 - k; h++) {
		ans += uiop[h];
	}
	cout << ans << endl;
	cin >> n;
}

Measured memory_bytes: 2816
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int digit(int a){
    int res = 0;
    while (a){
        res++;
        a /= 10;
    }
    return res;
}

int main() {
    ll n;
    cin >> n;
    int ans = 1e9;
    FOR(a,1,sqrt(n)){
        if (n % a != 0) continue;
        int b = n/a;
        int x = max(digit(a), digit(b));
        ans = min(ans, x);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define repin(a,n) vector<ll> a(n);rep(i,n){cin>>a[i];}
#define in(a) ll a;cin>>a;
#define out(a) cout<<a<<endl;

int main()
{
    in(n);
    repin(a,n);
    double sum = 0;
    rep(i,n){
        sum += 1.0/a[i];
    }
    printf("%.10f", 1/sum);
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)

def dfs_a(N,v,adjlist,cur):
    global depth_a
    depth_a[v]=cur
    for node in adjlist[v]:
        if depth_a[node]<0:
            dfs_a(N,node,adjlist,cur+1)
def dfs_t(N,v,adjlist,cur):
    global depth_t
    depth_t[v]=cur
    for node in adjlist[v]:
        if depth_t[node]<0:
            dfs_t(N,node,adjlist,cur+1)
    
    
    

from collections import deque

N,u,v=map(int,input().split())
adjlist=[[] for _ in range(N)]
for _ in range(N-1):
    a,b=map(int,input().split())
    adjlist[a-1].append(b-1)
    adjlist[b-1].append(a-1)
depth_a=[-1]*N
depth_t=[-1]*N
dfs_a(N,v-1,adjlist,0)
dfs_t(N,u-1,adjlist,0)
M=0
for i in range(N):
    if depth_a[i]>depth_t[i]:
        curm=depth_a[i]-1
        if curm>M:
            M=curm
print(M)
        

 
        
    

Measured memory_bytes: 98700
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    ll a,b;
    cin>> a>>b;
    cout << a*b << endl;
    return 0;
}


Measured memory_bytes: 3652
import io.StdIn.{readInt, readLine}
object Main extends App {
  val n = readInt
  val Array(a,b) = readLine.split(" ").map(_.toInt)
  val ps = readLine.split(" ").map(_.toInt)

  val problem1 = ps.filter(p => p <= a)
  val problem2 = ps.filter(p => a+1 <= p && p <= b)
  val problem3 = ps.filter(p => b+1 <= p)

  val result = Seq(problem1, problem2, problem3).map(_.length).min
  println(result)
}

Measured memory_bytes: 55052
#include <iostream>
#include <cstdio>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  stack<int> S1;
  stack<pair<int,int> > S2;
  char ch;
  int A=0;
  for (int i=0; cin >> ch; i++) {
    if (ch=='\\') {
      S1.push(i);
    } else if (ch=='/' && S1.size()>0) {
      int j=S1.top();
      S1.pop();
      A+=i-j;
      int a=i-j;
      while (S2.size()>0 && S2.top().first>j) {
	a+=S2.top().second;
	S2.pop();
      }
      S2.push(make_pair(j,a));
    }
  }
  vector<int> L;
  while (S2.size()>0) {
    L.push_back(S2.top().second);
    S2.pop();
  }
  reverse(L.begin(),L.end());
  printf("%d\n",A);
  printf("%d",L.size());
  for (int k=0; k<L.size(); k++) {
    printf(" %d",L[k]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 3276
N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [1000000000 for i in range(N)]
dp[0] = 0
for i in range(1, N):
  for j in range(1, K+1):
    if i >= j:
      dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))
print(dp[N-1])

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

int main()
{
int i,j,k,W,H;
while(1)
 {
cin >> H >> W;
if(H==0||W==0) break;
for(j=0;j<H;j++)
  {
for(k=0;k<W;k++)
   {
cout << "#";
   }
cout << endl;
  }
cout << endl;
 }
return 0;
}

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

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

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

int n;
cin >> n;
ll t;
ld ans = 1;
for (int i = 0; i < n; i++)
{
    cin >> t;
    if (ans != -1)
       ans *= t;
    if (ans > 1000000000000000000 || ans < 0)
       ans = -1;
    if (t == 0)
       ans = 0;
}
cout << (ll)ans;
return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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; }

const long long INF = 1LL << 60;

int main(){
  char x, y;
  cin >> x >> y;

  if(x == y){
    cout << "=" << endl;
    return 0;
  }
  else cout << (x < y ? "<" : ">") << endl;

  return 0;
}


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

#define N 305

int dp[N*N], ep[N*N];
int ans, n, a[N];

const int mod = 998244353;

int expmod(int a, int b, int mod) {
	int res = 1;
	for ( ; b; b >>= 1) {
		if (b&1) res = 1ll * res * a % mod;
		a = 1ll * a * a % mod;
	}
    return res;
}

void add(int &a, int b) {
    a = (a + b) % mod;
	if (a < 0) a += mod;
}

int main() {
    scanf("%d", &n);
    int sum = 0;
	for (int i = 1; i <= n; i ++) scanf("%d", &a[i]), sum += a[i];
    int up = sum / 2;
    dp[0] = 1; ep[0] = 1;
    for (int i = 1; i <= n; i ++) {
        for (int j = up-a[i]; j >= 0; j --) {
            add(dp[j+a[i]], dp[j]);
            add(ep[j+a[i]], ep[j]);
            add(ep[j+a[i]], ep[j]);
        }
    }
    for (int i = 1; i <= up; i ++) {
        ans = (ans + ep[i] - 2ll * dp[i]) % mod;
		if (ans < 0) ans += mod;
    }
    int C = (expmod(3, n, mod) - 1ll * expmod(2, n, mod) * 3 + 3) % mod;
    if (C < 0) C += mod;
    ans = (C - ans * 3ll) % mod;
    if (ans < 0) ans += mod;
    printf("%d\n", ans);
}


Measured memory_bytes: 640
n=int(input())
p=list(map(int,input().split()))

def ju(a,b,c):
    return b==(a+b+c)-min(a,b,c)-max(a,b,c)
    

ans=0
for i in range(1,n-1):
    if ju(p[i-1],p[i],p[i+1]):
        ans+=1
print(ans)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a, b, c, d;
  string s;
  int temp;
  int mbrc = 0;
  int mnrc = 0;

  cin >> n >> a >> b >> c >> d;
  cin >> s;
  
  a --; b --; c --; d --;
  
  temp = 0;
  for(int i = a + 1;i <= d;i++){
    if(s[i] == '#'){
      temp ++;
    }else{
      mbrc = max(mbrc, temp);
      temp = 0;
    }
  }

  if(mbrc >= 2){
    cout << "No" << endl;
    return 0;
  }
  
  if(c < d){
    cout << "Yes" << endl;
    return 0;
  }

  temp = 0;
  for(int i = b - 1;i <= d;i++){
    if(s[i] == '.'){
      temp ++;
    }else{
      mnrc = max(mnrc, temp);
      temp = 0;
    }
  }
  
  if(d + 1 != n && s[d + 1] == '.'){
    temp++;
  }
  mnrc = max(mnrc, temp);

  if(mnrc >= 3){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 592
n = int(input())
n_cnt = 0
for i in range(1,n + 1,2):
  cnt = 0
  for j in range(1,n + 1):
    if i % j == 0:
      cnt += 1
    if j == n and cnt == 8:
      n_cnt += 1
print(n_cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>a(n),sum(n+1);
	rep(i, n) {
		cin >> a[i];
	}
	sum[0] = 0;
	FOR(i, 1, n+1) {
		sum[i] = sum[i - 1] + a[i - 1];
	}
	int ans = INF;
	FOR(i, 1, n) {
		int tmp = sum[n] - sum[i];
		int tmp2 = abs(sum[i] - tmp);
		chmin(ans, tmp2);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
#include <string>
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define FOR(i, start, end) for(ll i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {
    int a, b;
    cin >> a >> b;
    
    int base = min(a, b);
    int time = max(a, b);

    string O;
    REP(i, time) {
        O += to_string(base);
    }

    cout << O << endl;

    return 0;
}

Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

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

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int N = 2e5 + 100;

int n;
vector<int> eds[N];

pair<int, int> dfs1(int v, int p = -1) {
	pair<int, int> ans = {0, v};
	for (int u: eds[v]) {
		if (u == p)
			continue;
		pair<int, int> tmp = dfs1(u, v);
		++tmp.first;
		ans = max(ans, tmp);
	}
	return ans;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		eds[a].push_back(b);
		eds[b].push_back(a);
	}
	int a = dfs1(0).second;
	int d = dfs1(a).first;
	if (d % 3 == 0 || d % 3 == 2)
		cout << "First\n";
	else
		cout << "Second\n";
	return 0;
}




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

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

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int n; std::cin >> n;
  int c = 0;
  bool ans = false;
  rep(i,n) {
    int a,b; std::cin >> a >> b;
    if ( a != b ) c = 0;
    else c++;
    if ( c >= 3 ) ans = true;
  }

  if (ans) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
  return 0;
}



Measured memory_bytes: 3636
import sys

# バリデーション
# ルール１：同じ桁数に複数の値を割り当てることはできない
# ルール２：一桁目に０は入れることができない
def check_sets():
  check_lists = {}
  if [1, 0] in sets and N > 1:
    return True
  for a,b in sets:
    if a not in check_lists:
      check_lists[a] = b
    else:
      if check_lists[a] != b:
        return True
  return False

N, M = list(map(lambda x: int(x), input().split()))
ans_strs = ['0' for _ in range(N)]
ans_strs[0] = '1'

sets = []
for _ in range(M):
  sets.append(list(map(lambda x: int(x), input().split())))

is_bad = check_sets()
if is_bad:
  print(-1)
  sys.exit()

for index,number in sets:
  ans_strs[index - 1] = str(number)

answer = int(''.join(ans_strs))
if answer == 1 and [1,1] not in sets:
  answer = 0
print(answer)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int n, l, r;
int a[55];

int main(void)
{
	while(1){
		cin >> n >> l >> r;
		if(n == 0 && l == 0 && r == 0) break;
		for(int i = 1; i <= n; i++) cin >> a[i];
		
		int ans = 0;
		for(int i = l; i <= r; i++){
			for(int j = 1; j <= n; j++){
				if(i % a[j] == 0){
					if(j % 2) ans++;
					goto end;
				}
			}
			if(n % 2 == 0) ans++;
			end:;
		}
		cout << ans << endl;
	}
	return 0;
}


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

using namespace std;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

pii dfs(int v, int p, vector<vector<int>> &G) {
    int w = v, l = 0;
    for(int i = 0; i < G[v].size(); i++) {
        if (G[v][i] == p) continue;
        pii r = dfs(G[v][i], v, G);
        if (r.first + 1 > l) {
            l = r.first + 1;
            w = r.second;
        }
    }
    return {l, w};
}

void solve() {
    int N;
    cin >> N;
    vector<vector<int>> G(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    pii r1 = dfs(0, -1, G);
    pii r2 = dfs(r1.second, -1, G);

    int L = r2.first;
    if (L % 3 == 1) {
        cout << "Second" << endl;
    } else {
        cout << "First" << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 26880