akhauriyash/Code-Regression huggingface dataset:
//Addition and Multiplication
//AdditionandMultiplication

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) int n;cin>>n;vector<int>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    int n,k;cin>>n>>k;
    int t = 1;
    rep(i,0,n){
        t=min(t*2,t+k);
    }
    cout<<t<<nnn;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <limits>
#include <algorithm>
#include <memory>
#include <climits>

constexpr long long MOD = 1000000007;

int main()
{
  int N;
  std::cin >> N;
  std::vector<int> v(N);
  std::vector<int> c(N);
  for (auto& val: v)
    std::cin >> val;
  for (auto& val: c)
    std::cin >> val;
  int ans = 0;
  for (int i = 0; i < N; ++i)
  {
    if (c[i] < v[i])
      ans += v[i] - c[i];
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    string S; cin >> S;
    for (int i = 0; i < 3; i++) {
        if (S[i] == S[i+1]) {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}

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

struct vec
{
    long double x,y;
    bool operator ==(const vec &a) const{
        return x==a.x&&y==a.y;
    }
    bool operator <(const vec &a) const{
        if(a.x!=x) return x<a.x;
        return y<a.y;
    }
    vec operator +(const vec &a) const{
        return {x+a.x,y+a.y};
    }
    vec operator *(const long double &a) const{
        return {x*a,y*a};
    }
    vec operator -(const vec &a) const{
        return {x-a.x,y-a.y};
    }
    vec operator /(const long double &a) const{
        return {x/a,y/a};
    }
    long double len() const{
        return (x*x+y*y);
    }
    long double dot(const vec &a) const{
        return x*a.x+y*a.y;
    }
    long double crs(const vec &a) const{
        return x*a.y-y*a.x;
    }
    vec proj(const vec &a) const{
        return (a/a.len())*(*this).dot(a)/a.len();
    }
};


struct P
{
    int x,y;
    bool operator <(const P &a) const{
        //if(x!=a.x)
         return y>a.y;

    }
};


long long x,y,z,mod=1000000007;
//vector<long long> v,v1;
vector<int> v;
//vector<long long> v1;
int i,n,m,k,a,d,b,c,h,dx[10]={1,0,-1,0},dy[10]={0,1,0,-1};
int e;
int l[211111];

int o[221111];

int j[222221];
stack<int> s;
//set<int> s;
queue<int> q;
P u[1],u1[1];
//char r[1],r1[3];
string r,r1;
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
map<int,int> p;

//v.resize(unique(v.begin(),v.end())-v.begin());

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng();

bool as(P a,P b)
{
    return a.y<b.y;
}


int main()
{
    scanf("%d",&a);
    for(int t=1;t<=a;t++)
        scanf("%d",&o[t]);
    for(int t=1;t<=a;t++)
        scanf("%d",&l[t]);
    for(int i=1,t=0;t<=28;t++,i*=2)
    {
        for(int t=1;t<=a;t++)
            j[t-1]=o[t]%(i*2);
        sort(j,j+a);
        x=0;
        for(int t=1;t<=a;t++)
        {
            n=l[t]%(i*2);
            x+=(upper_bound(j,j+a,i*2-1-n)-lower_bound(j,j+a,i-n))+(upper_bound(j,j+a,i*4-1-n)-lower_bound(j,j+a,i*3-n));
        }
        if(x%2) k+=i;
    }
    printf("%d",k);
}



Measured memory_bytes: 2560
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


int main() {
	int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;

	int cnt = 0;

	while (X > 0 && Y > 0) {
		X--;
		Y--;
		cnt += min(A + B, 2 * C);
	}
	
	while (X > 0) {
		X--;
		cnt += min(A, 2 * C);
	}
	while (Y > 0) {
		Y--;
		cnt += min(B, 2 * C);
	}
	print(cnt);




	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T x=0,f=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	const int N=1e6+9;
	int n,sum[N],g[N],ans=N;char s[N],t[N];
	inline void solve(int Z){
		for(int i=1;i<=n;i++) t[i]=s[i];
		for(int i=n;i>=1;i--) g[i]=(Z-sum[i])/2;
		for(int i=n-1;i>=1;i--) g[i]=min(g[i],g[i+1]);

	//	for(int i=1;i<=n;i++) cout<<g[i]<<" ";cout<<endl;
		int now=0;
		for(int i=1;i<=n;i++)
			if(t[i]=='?'){
				if(now<g[i]) t[i]='1',now++;
				else t[i]='0';
			}

		int tmp=0,mn=0,mx=0;
		for(int i=1;i<=n;i++){
			tmp+=(t[i]=='1')*2-1;
			mn=min(tmp,mn),mx=max(tmp,mx);
		}
	//	for(int i=1;i<=n;i++) cout<<t[i]<<" ";cout<<endl;
	//	cout<<mn<<" "<<mx<<endl;
		ans=min(ans,mx-mn);
	}
	int main(){
		scanf("%s",s+1),n=strlen(s+1);

		int Z=0;
		for(int i=1;i<=n;i++) sum[i]=sum[i-1]+((s[i]=='1')*2-1),Z=max(Z,sum[i]);
	//	cout<<Z<<endl;
		solve(Z),solve(Z+1);
		printf("%d\n",ans);
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

Measured memory_bytes: 13564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int a[maxn];

map<int,int> mp;

int main()
{
	//IOS;
    int n;
    cin>>n;
    REP(i,n) cin>>a[i];

    if(a[0]!=0){
        cout<<"-1";
        return 0;
    }    
    REP(i,n-1) if(a[i+1]>a[i]+1){
        cout<<"-1";
        return 0;
    }
    ll ans=0;
    REP(i,n){
        int tmp=a[i]-i;
        mp[tmp]=a[i];
    }
    for(auto i:mp){
        ans+=i.S;
    }
    
    cout<<ans;    
	return 0;
}


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


int main(){
  string A, B;
  cin >> A >> B;
  if(A==B){
    cout << "EQUAL" << endl;
  }else if(A.size() > B.size()){
    cout << "GREATER" << endl;
  }else if(A.size() < B.size()){
    cout << "LESS" << endl;
  }else{
    int len = A.size();
    for(int ii=0; ii<len; ii++){
      if(A[ii] == B[ii]) continue;
      cout << (A[ii] > B[ii] ? "GREATER" : "LESS") << endl;
      break;
    }
  }
  return 0;
}

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

int main() {
  string S;
  cin >> S;
  if(S.size()%2==1){
    cout << "No"; return 0;
  }
  for(int i=0;i<S.size();i+=2){
    if(S[i] !='h' || S[i+1] !='i'){
      cout << "No"; return 0;
    }
  }
cout << "Yes";
return 0;
}

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

#define FOR(i,a,b) for(long long i = (a); i < (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define REP(i,a) for(int i = 0; i < (a); i++)
#define REPD(i,a) for(int i = (a)-1; i >= 0; i--)
#define sz(a) (int)a.size()
#define ALL(a) a.begin(),a.end()

#define ii pair<int,int>
#define fi first
#define se second
#define ll long long
#define N 1e5

using namespace std;

int main()
{
    int n;
    string s;

    cin>>n;
    cin>>s;
    if(n&1)
    {
        cout<<"No";
        return 0;
    }
    FOR(i,0,n/2)
    {
        if(s[i]!=s[i+n/2])
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
c=[list(map(int,input().split())) for i in range(3)]
flag='Yes'
for i in range(2):
  if c[0][i+1]-c[0][i] == c[1][i+1]-c[1][i] == c[2][i+1]-c[2][i]:
    pass
  else:
    flag='No'

for j in range(2):
  if c[j+1][0]-c[j][0] == c[j+1][1]-c[j][1] == c[j+1][2]-c[j][2]:
    pass
  else:
    flag='No'
print(flag)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
 
int main(){
	ll A,B,C,D;
    cin>>A>>B>>C>>D;
    cout<<max(A*B,C*D)<<endl;
	return 0;
}

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n, s = 0;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		s += a[i];
	}
	ll poz = s / n;
	ll poz1 = s / n + 1;
	ll st = 0;
	ll st1 = 0;
	for (auto x : a)
	{
		st += ((x - poz) * (x - poz));
		st1 += ((x - poz1) * (x - poz1));
	}
	cout << min(st, st1);
	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll N,K;
    cin >> N >> K;
    vector<pll> dt(N);
    REP(i, N){
        cin >> dt[i].se >> dt[i].fi;
    }

    auto calc = [](ll t, ll x){return t+x*x;};

    RSORT(dt);
    priority_queue<ll,vector<ll>, greater<ll>> q;
    map<int,ll> num;
    ll total = 0;

    REP(i, K){
        total += dt[i].fi; //上からK個取ったときの最大値
        if(num[dt[i].se] == 0)
            num[dt[i].se]++;
        else
            q.push(dt[i].fi); //同じ種類が二個目以上のときキューに入れる  

    }
    ll ans = calc(total, num.size());

    //残りのN-K個をチェック
    if(!q.empty())
    for (int i = K; i < N; i++) {
        if(num[dt[i].se]!=0)continue;
        ll f = q.top();q.pop();
        total -= f;
        total += dt[i].fi;
        num[dt[i].se]++;
        chmax(ans, calc(total, num.size()));
    }   
    pr(ans);
}

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

int main() {
    int x;
    int happy_500;
    int happy_5;
    cin >> x;

    happy_500 = x / 500;
    happy_5 = (x % 500) / 5;

    cout << (happy_500 * 1000) + (happy_5 * 5) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp14
{
    class Class18
    {
        static void Main()
        {
            int MOD = 1000000007;
            var NM = Console.ReadLine().Split();
            int N = int.Parse(NM[0]);
            int M = int.Parse(NM[1]);
            long[] DP = new long[N + 3];
            DP[0] = 1;
            for (int i = 1; i < N + 3; i++) DP[i] = 0;

            for(int i = 0; i < M; i++)
            {
                int a = int.Parse(Console.ReadLine());
                DP[a] = int.MaxValue;
            }

            for(int i = 0; i < N; i++)
            {
                if (DP[i] < int.MaxValue)
                {
                    DP[i + 1] += DP[i]%MOD;
                    DP[i + 2] += DP[i]%MOD;
                }
            }

            Console.WriteLine(DP[N] % MOD);
        }
    }
}


Measured memory_bytes: 13664
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++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(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    REP(i,n)cin >> a[i];
    ll answer = 0;
    ll count =1;
    bool flag = false;
    REP(i,n){
        if(a[i]==count){
            count++;
            flag= true;
        }
        else{
            answer++;
        }
    }
    if(!flag){
        cout << -1 << endl;
        return 0;
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

	static Main main = new Main();
	static HashMap<String, Item> itemTable = new HashMap<String, Item>();

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (!(line = br.readLine()).equals("0")) {
			int m = 0, n = 0;
			String target;

			n = Integer.parseInt(line);
			for (int i = 0; i < n; i++) {
				Item item = getItemInstance(br.readLine());
				itemTable.put(item.name, item);
			}

			m = Integer.parseInt(br.readLine());
			for (int i = 0; i < m; i++) {
				setRecipe(br.readLine());
			}

			target = br.readLine();
			System.out.println(itemTable.get(target).getPriceMin());
		}
	}

	class Item {
		String name;
		int price;
		int recipeCount = 0;
		ArrayList<Item> recipe;

		Item(String name, int price) {
			this.name = name;
			this.price = price;
			recipeCount = 0;
		}

		int getPriceMin() {
			int min = 0;
			if (recipeCount == 0) {
				min = price;
			} else {
				for (Item i : recipe) {
					if (i != null)
						min += i.getPriceMin();
				}
			}
			return min < price ? min : price;
		}
	}

	static Item getItemInstance(String info) {
		int n = info.indexOf(' ');
		String name = info.substring(0, n);
		int price = Integer.parseInt(info.substring(n + 1));
		return main.new Item(name, price);
	}

	static void setRecipe(String info) {
		StringTokenizer st = new StringTokenizer(info);
		Item item = itemTable.get(st.nextToken());
		item.recipeCount = Integer.parseInt(st.nextToken());
		item.recipe = new ArrayList<Item>();
		while (st.countTokens() > 0) {
			item.recipe.add(itemTable.get(st.nextToken()));
		}
	}
}

Measured memory_bytes: 21532
#include	<bits/stdc++.h>
using	namespace	std;
#define	FOR(i,n)	for(int	i=0;i<n;i++)
#define	why(n,x)	int	n;while(cin	>>n,n!=x)
#define	iFOR(i,x,n)for(int	i=x;i<n;i++)
#define	unless(flg)	if	(	!(flg)	)
#define	read	cin<<
#define	echo	cout<<
#define	fin	<<'\n'
#define	__	<<"	"<<
#define	bash	push_back
#define	alles(x)	x.begin(),x.end()
#define	SWAP(a,b)	((a	!=	b)	&&	(a	+=	b,b	=	a	-	b,a	-=	b))
int	dx[]={1,0,-1,0,1,1,-1,-1};
int	dy[]={0,-1,0,1,-1,1,-1,1};
const	int	INF	=	0x3f3f3f3f;
const	long	long	LINF	=	0x3f3f3f3f3f3f3f3fLL;

bool	inside(int	x,int	y,int	w,int	h){
return	(x>=0	&&	y>=0	&&	x<w	&&	y<h);}
typedef	long	long	ll;
typedef	pair	<	int	,	int	>	pii;
typedef	vector	<	int	>	vit;
typedef	map	<	string	,	int	>	mstit;
typedef	vector	<	pii	>	vpi	;
typedef	greater	<	pii	>	gpi;
typedef	priority_queue	<	pii	,	vpi	,	gpi	>	dijk	;




int	main(){
cin.tie(0),	ios::sync_with_stdio(false);
int	a,	b	,	c;
cin	>>	a	>>	b	>>	c;
if(a+b>=c-1)	cout	<<	b+c	fin;
else	cout	<<	a+b+b+1	fin;


return	0;
}

Measured memory_bytes: 256
import collections

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

ans = 0
sums = collections.Counter([0, x[0]])

for i in x[1:]:
    temp = collections.Counter()
    for s, c in sums.items():
        temp[s + i] += c
    sums += temp
    #print(sums)

print(sums[0] - 1)


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

using namespace std;
using ll = long long;

#define MOD 1000000007
template<int mod>
struct ModInt{
   int x;
   ModInt():x(0){}
   ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
   ModInt &operator+=(const ModInt &p){
       if((x+=p.x)>=mod)x-=mod;
       return *this;
   }
   ModInt &operator-=(const ModInt &p){
       if((x+=mod-p.x)>=mod)x-=mod;
       return *this;
   }
   ModInt &operator*=(const ModInt &p){
       x=(int)(1LL*x*p.x%mod);
       return *this;
   }
   ModInt &operator/=(const ModInt &p){
       *this*=p.inverse();
       return *this;
   }
   ModInt &operator^=(long long p){
       ModInt res = 1;
       for (; p; p >>= 1) {
           if (p & 1) res *= *this;
           *this *= *this;
       }
       return *this = res;
   }
   ModInt operator-()const{return ModInt(-x);}
   ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
   ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
   ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
   ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
   ModInt operator^(long long p)const{return ModInt(*this)^=p;}
   bool operator==(const ModInt &p)const{return x==p.x;}
   bool operator!=(const ModInt &p)const{return x!=p.x;}
   explicit operator int() const { return x; }
   ModInt operator=(const int p) {x = p; return ModInt(*this);}
   ModInt inverse()const{
       int a=x,b=mod,u=1,v=0,t;
       while(b>0){
           t=a/b;
           a-=t*b;
           std::swap(a,b);
           u-=t*v;
           std::swap(u,v);
       }
       return ModInt(u);
   }
   friend std::ostream &operator<<(std::ostream &os,const ModInt<mod> &p){
       return os<<p.x;
   }
   friend std::istream &operator>>(std::istream &is,ModInt<mod> &a){
       long long x;
       is>>x;
       a=ModInt<mod>(x);
       return (is);
   }
};
typedef ModInt<MOD> mint;

/*********************************/
template<class T> inline ostream& operator<<(ostream& os,vector<T> arr) {os << "["; for(int i = 0; i < (int)arr.size(); i++)os << arr[i] << (i == (int)arr.size() - 1 ? "]" : ",");os << endl;return os;}
template<typename A, typename B> ostream& operator<<(ostream& os, const pair<A,B>& p){os << "{" << p.first << "," << p.second << "}";return os; }
#define prvec(v) cerr<<#v<<": [";for(int __i = 0;__i < (int)(v).size(); __i++)cerr<<((v)[__i])<<(__i+1==(int)(v).size()?"]\n":",");
#define print(x) cerr<<#x<<": "<<(x)<<endl
/*********************************/

int main()
{
    int n;
    string s, t;
    cin >> n >> s >> t;
    for(auto &i: s) i -= 'a';
    for(auto &i: t) i -= 'a';
    
    vector<mint> dp(n); //dp[i] := 星iにたどり着く場合の数
    vector<mint> path(26);
    dp[0] = 1;

    for(int i = 0; i < n; i++) {
        dp[i] += path[t[i]];
        path[s[i]] += dp[i];
    }
    cout << dp[n - 1] << endl;

}


Measured memory_bytes: 3676
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define KOZYUN(a) sort(all(a),greater<int>())
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
/*
ACplease
　　 ●
　　/⌒ヽ
　 ｜ 　|/⌒ヽ(ヽ
　 (｀　∥ー⌒) |
　|￣||￣￣￣￣￣|
　|―||―――――|
　|　Ｕ　　　　　|
　|￣￣￣￣￣￣￣|
　|＿＿＿＿＿＿＿|
　　|―――――|
　　|―――――|
ｗｗＷｗｗＷｗＷＷｗ
*/

//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n; cin >> n;
    VI x(n); VIin(x);
    int ans = INF;
    repe(i,100){
        int res = 0;
        rep(j,n) res += pow(x[j] - i,2);
        ans = min(ans,res);
    }
    ANS;

    return 0;
}

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

int main(){
  long long N, K; cin >> N >> K;
  K *= 2;
  vector<long long> A, B;
  rep(i, N) {
    int x; cin >> x;
    if (x >= 0) A.push_back(x);
    else B.push_back(-x);
  }
  const long long INF = 1e18 + 10;
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());

  if ((long long)A.size() * (long long)B.size() * 2 < K) {
    K -= (long long)A.size() * B.size() * 2;

    long long ok = 0;
    long long ng = INF;

    while (abs(ok - ng) > 1) {
      long long mid = (ok + ng) / 2;

      long long cnt = 0;
      int now = A.size() - 1;
      rep(i, A.size()) {
        while (now >= 0 && A[i] * A[now] >= mid) now--;
        cnt += now + 1;
        if (A[i] * A[i] < mid) cnt--;
      }

      now = B.size() - 1;
      rep(i, B.size()) {
        while (now >= 0 && B[i] * B[now] >= mid) now--;
        cnt += now + 1;
        if (B[i] * B[i] < mid) cnt--;
      }

      if (cnt < K)
        ok = mid;
      else
        ng = mid;
    }
    cout << ok << endl;

  } else {
    K /= 2;
    sort(A.rbegin(), A.rend());
    sort(B.rbegin(), B.rend());

    long long ok = INF;
    long long ng = -1;

    while (abs(ok - ng) > 1) {
      long long mid = (ok + ng) / 2;

      long long cnt = 0;
      int now = B.size() - 1;
      rep(i, A.size()) {
        while (now >= 0 && A[i] * B[now] <= mid) now--;
        cnt += now + 1;
      }

      if (cnt < K)
        ok = mid;
      else
        ng = mid;
    }
    cout << -ok << endl;
  }
  

}


Measured memory_bytes: 2548
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

s = [_ for _ in input()]
ans = [0]*len(s)

last = 'R'


for ri in range(2):
  cnt=0
  for i in range(len(s)):
    if s[i]=='R':
      cnt+=1
    else:
      ans[i]+=cnt//2
      ans[i-1]+=(cnt+1)//2
      cnt=0

  ans=ans[::-1]
  s=s[::-1]
  for i in range(len(s)):
    if s[i]=='L':
      s[i]='R'
    else:
      s[i]='L'


print(' '.join([str(_) for _ in ans]))


Measured memory_bytes: 56756
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
int main(){
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    db ny=m*6.0;
    db nx=h*30.0+(30.0/360.0)*ny;
    db x=fabs(nx-ny);
    if(x==0){
        cout<<abs(a-b)<<endl;
        return 0;
    }
    else{
        db p=(db)(a*a)+(db)(b*b)-2.0*(db)(a*b)*cos((db)x/180.0*3.1415926535897932);
        printf("%.15f\n",sqrt(p));
    }
}

Measured memory_bytes: 4160
N, M = map(int, input().split())
AB = [0]*N
for n in range(N):
    AB[n] = list(map(int, input().split()))
    
AB.sort(key = lambda x:x[0])

bottle = 0
cost = 0

for n in range(N):
    if AB[n][1] + bottle < M:
        bottle += AB[n][1]
        cost += AB[n][0] * AB[n][1]
    else:
        cost += AB[n][0] * (M-bottle)
        break

print(cost)

Measured memory_bytes: 29028
"繰り返す10真数"


def new_a(n, L):
    numbers = [int(x) for x in list(str(n))]
    if len(numbers) != L:
        numbers.extend([0]*(L-len(numbers)))

    numbers.sort(reverse=True)
    max_n = 0
    for i, n in enumerate(numbers):
        max_n += n
        if i != (len(numbers)-1):
            max_n *= 10

    numbers.sort()
    min_n = 0
    for i, n in enumerate(numbers):
        min_n += n
        if i != (len(numbers)-1):
            min_n *= 10
    return max_n-min_n


while True:
    a, L = map(int, input().split())
    if a == 0 and L == 0:
        break
    A = [a]
    flag = True
    while True:
        hoge = new_a(A[-1], L)
        if hoge in A:
            for j in range(len(A)):
                if A[j] == hoge:
                    print(j, hoge, (len(A)-j))
                    flag = False
                    break
        else:
            A.append(hoge)
        if not flag:
            break



Measured memory_bytes: 5616
import std.stdio;

void main(){
	auto cin = new Cin();
	
	auto S = cin.line!string()[0];
	
	bool succeed = false;
	
	
	foreach( i ; 0..S.length-1 ){
		if( S[i]==S[i+1] ){
			writeln( i+1," ",i+2 );
			return;
		}
	}
	foreach( i ; 0..S.length-2 ){
		if( S[i]==S[i+2] ){
			writeln( i+1," ",i+3 );
			return;
		}
	}
	writeln( "-1 -1" );
	return;
}
auto solve(){
}
unittest{
	
}


import std.stdio,std.conv,std.string;
import std.algorithm,std.array,std.math;

class Cin
{
	T[] line( T = size_t , string token = " " )( size_t m = 1 ){
		T[] arr = [];
		foreach( i ; 0..m ){
			arr ~= this.read!T();
		}
		return arr;
	}
	T[][] rect( T = size_t , string token = " " )( size_t m = 1 ){
		T[][] arr = new T[][](m);
		foreach( i ; 0..m ){
			arr[i] = this.read!T(token);
		}
		return arr;
	}
	private T[] read( T = size_t )( string token = " " ){
		T[] arr;
		foreach( elm ; readln().chomp().split(token) ){
			arr ~= elm.to!T();
		}
		return arr;
	}
}

pure T[] span(T)( in T begein , in T end , in T step = 1 ){
	assert( begin < end );
	assert( 0 < step );
	T[] arr;
	for( T i = begein ; i < end ; i += step ){
		arr ~= i;
	}
	return arr;
}

pure T[] map(T)( ref T[] args , T delegate(T)  dlg ){
	foreach( ref arg ; args ){
		arg.dlg();
	}
	return args;
}
pure T sum(T)( in T[] args ){
	T result = 0;
	foreach( arg ; args ){
		result += arg;
	}
	debug writeln( args , "\n" , arg );
	return result;
}
pure T ave(T)( in T[] args ){
	return args.sum()/args.length;
}


Measured memory_bytes: 508
n = int(input())
h = list(map(int, input().split()))

# if max(h) - h[n - 1] > 1:
#     print('No')
#     exit(0)
# if n == 1:
#     print('Yes')
#     exit(0)
# else:
#     cap = max(h[0:n-1])
#     for i in range(n - 1, 0, -1):
#         if max(h[i - 1] - 1, 1) > h[i]:
#             print('No')
#             exit(0)
#         else:
#             if cap > h[i]:
#                 pass
#             else:
#                 h[i - 1] = max(h[i - 1] - 1, 1)

for i in range(n - 1, 0, -1):
    if h[i - 1] - h[i] > 1:
        print('No')
        exit(0)
    elif h[i - 1] - h[i] == 1:
        h[i - 1] = max(h[i - 1] - 1, 1)
    else:
        pass


print('Yes')

Measured memory_bytes: 63856
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k,x;
	scanf("%d%d",&k,&x);
	if(k==1)
	    printf("%d\n",x);
	else{
	    for(int i=x-k+1;i<x+k-1;i++){
	    	printf("%d ",i);
	    }
	    printf("%d\n",x+k-1);
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#define ll long long 
#define fr(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define inf (1<<31)
#define xx first
#define yy second

using namespace std;

queue<char> A,B,C;
char s;
int main() {
	ios::sync_with_stdio(0);
	string a,b,c;
	cin>>a>>b>>c;
	fr(i,a.length()){
	    A.push(a[i]);
	}
	fr(i,b.length()){
	    B.push(b[i]);
	}
	fr(i,c.size()){
	    C.push(c[i]);
	}
	s=A.front(); A.pop();
	while(1){
	    switch(s){
	        case 'a':if(A.empty()) goto label; else{s=A.front(); A.pop(); break;} 
	        case 'b':if(B.empty()) goto label; else{s=B.front(); B.pop(); break;} 
	        case 'c':if(C.empty()) goto label; else{s=C.front(); C.pop(); break;} 
	    }
	}
	label:
	if(A.empty() && s=='a')
	    cout<<'A';
	else if(C.empty() && s=='c')
	    cout<<'C';
	else if(B.empty() && s=='b')
	    cout<<"B";
	
	return 0;
}

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

int main(void){
  int N;
  cin>>N;
  int cnt=0;
  int max=0;
  int A;
  for(int i=0;i<N;i++){
    cin>>A;
    if(A==1){
      cnt+=1;
    }
    else{
      if(cnt>max){
        max=cnt;
      }
      cnt=0;
    }
  }
  if(cnt>max){
    max=cnt;
  }
  cout<<max+1<<endl;
  return 0;
}



Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

int RSPtoPnt(char jan, int r, int s, int p){
	if(jan == 'r'){
		return p;
	}
	if(jan == 's'){
		return r;
	}
	if(jan == 'p'){
		return s;
	}
}
char win(char jan){
	if(jan == 'r') return 'p';
	if(jan == 's') return 'r';
	if(jan == 'p') return 's';
}
int main(void) {
	int n,k; cin >> n >> k;
	int r,s,p; cin >> r >> s >> p;
	string t; cin >> t;
	vector<string> subs(k);
	rep(i,n) subs[i%k] += t[i];
	int ans = 0;
	bool flg;//前回の手で負けてたらtrue
	rep(i,k){
		flg=false;
		rep(j,subs[i].size()){
			if(j==0) ans+=RSPtoPnt(subs[i][j],r,s,p);
			else if(flg){
				ans+=RSPtoPnt(subs[i][j],r,s,p);
				flg=false;
			}else if(subs[i][j]==subs[i][j-1]){
				flg=true;
			}else{
				ans+=RSPtoPnt(subs[i][j],r,s,p);
			}
		}
	}
	out(ans);


}




Measured memory_bytes: 5120
import heapq

H, W = map(int, input().split())
C = []
for _ in range(10):
    c = list(map(int, input().split()))
    C.append(c)

A = []
for _ in range(H):
    a = list(map(int, input().split()))
    A.append(a)


def dijkstra(start, goal, n, edge):
    d = [float("inf")] * n
    d[start] = 0
    q = [(0, start)]
    heapq.heapify(q)

    while q:
        ci, i = heapq.heappop(q)
        if d[i] < ci:
            continue

        for j in range(n):
            if j != start and j != i:
                if d[j] > d[i] + C[i][j]:
                    d[j] = d[i] + C[i][j]
                    heapq.heappush(q, (d[j], j))

    return d[goal]


cost = [0] * 10
for i in range(10):
    c = dijkstra(i, 1, 10, C)
    cost[i] = c

ans = 0
for h in range(H):
    for w in range(W):
        if A[h][w] == -1:
            continue
        ans += cost[A[h][w]]
print(ans)


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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define all(e) (e).begin(), (e).end()


template <typename T>
void printV(vector<T> A) {
    if (A.empty()) cerr << "EMTPY\n";
    else { 
        cerr << "[";
        for (int i = 0; i < A.size() -1 ; ++i) {
            cerr << A[i] << ", ";
        }
        if (A.size()) cerr << A.back() << "]\n";
    }
}


template <typename T>
void printVV(vector<vector<T>> A) {
    cerr << "[";
    for (auto v : A) {
        printV<T>(v);
    }
    cerr << "]";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

ll mod = 2019;


ll exp(ll val, ll p) {
    ll ret = 1;
    while (p > 0) {
        if (p&1) ret = ret * val;
        p >>= 1;
        val = val * val;
        val %= mod;
        ret %= mod;
    }
    return ret % mod;
}

int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin >> s;
    int n = s.size();

    ll cur = 0;
    vll counts(2019, 0);
    counts[0] = 1;
    for (int i = 0; i < n; ++i) {
        ll d = (s[i] - '0');
        cur = cur * 10 + d; cur %= mod;
        ll val = cur * exp(10, n-i-1);
        val %= mod;
        counts[val]++;
    }

    ll ans = 0;
    for (int i = 0; i < 2019; ++i) {
        ans += counts[i] * (counts[i]-1) / 2;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[] = "ABC";
    char s1[10];
    scanf("%s",s1);
    if(strcmp(s1,s) == 0)
    {
        printf("ARC\n");

    }
    else
    printf("ABC\n");

return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
 using namespace std;
 
 int main() {
 int n;
 cin >> n;
 vector<int> d(n);
 for(int i = 0; i < n; i++) cin >> d[i];
 int ans = 0;
 for(int i = 0; i < n; i++) {
 for(int j = i + 1; j < n; j++) {
 ans += d[i] * d[j];
 }
 }
 cout << ans << endl;
 return 0;
 }

Measured memory_bytes: 256
#include <stdio.h>
int n,s,a,x,i;
int main () {
  scanf ("%d%d",&n,&a);
  while (a--) {
    scanf ("%d",&x);
    s+=x;
  }
  if (s>=n) 
    puts ("Yes");
  else 
    puts ("No");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
using namespace std;


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

	string str = "Christmas";
	if (D <= 24)
	{
		str += " Eve";
	}
	if (D <= 23)
	{
		str += " Eve";
	}
	if (D == 22)
	{
		str += " Eve";
	}

	cout << str << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner sc;
    public static void main(String[] args) {
        sc=new Scanner(System.in);
        //A();
        //B();
        C();
        //D();
    }
    public static void A(){
        int n=sc.nextInt();
        int m=sc.nextInt();
        System.out.println((n-2*m>0)?n-2*m:0);
    }
    public static void B(){
        int n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)a[i]=sc.nextInt();
        int sum=0;
        for(int i=0;i<n-1;i++)
            for(int j=i+1;j<n;j++)
                sum+=a[i]*a[j];
        System.out.println(sum);
    }
    public static void C(){
        int n=sc.nextInt();
        char []po=sc.next().toCharArray();
        char c=po[0];
        int ans=1;
        for(int i=1;i<n;i++)
            if(c!=(c=po[i]))
                ans++;
        System.out.println(ans);
    }
    public static void D(){
        int n=sc.nextInt();
        int []a=new int[n];
        for(int i=0;i<n;i++)
            a[i]=sc.nextInt();
        Arrays.sort(a);
        long ans=0;
        for(int i=0;i<n-2;i++){
            int kk=i+1;
            for(int j=i+1;j<n-1;j++){
                for(int k=(Math.max(kk,j));k<n;k++)
                    if(!(a[i]+a[j]>a[k]))
                        break;
                    else kk=k;
                ans+=kk-j;
            }
        }
        System.out.println(ans);
    }
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> p;


int main()
{
  string s;
  cin >> s;
  int res = 700;
  for (int i = 0; i < 3; i++){
    if (s[i] == 'o') {
      res += 100;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 768
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()

ans=0
for i in range(n):
    mid=b[i]
    ue=bisect.bisect_right(a,mid-1)
    sita=bisect.bisect_left(c,mid+1)
    ans+=ue*(n-sita)
print(ans)

Measured memory_bytes: 23360
N, A, B, C = map(int, input().split())
As = [A, B, C]
l = [int(input()) for _ in range(N)]

bit = [0, 0, 0]
ans = 100000000
for bit[0] in range(1, 1<<N):
  for bit[1] in range(1, 1<<N):
    if bit[1] & bit[0]: continue
    for bit[2] in range(1, 1<<N):
      if bit[2] & bit[0]: continue
      if bit[2] & bit[1]: continue

      sums = [0, 0, 0]
      nums = [0, 0, 0]
      for i in range(N):
        for j in range(3):
          if bit[j] & (1<<i):
            sums[j] += l[i]
            nums[j] += 1

      score = 0
      for i in range(3):
        score += abs(sums[i] - As[i])
        score += (nums[i] - 1) * 10

      ans = min(ans, score)

print(ans)


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

int main() {
    int x1, y1, x2, y2, x3, y3, x4, y4;
    cin >> x1 >> y1 >> x2 >> y2;
    
    int dx = x2-x1;
    int dy = y2-y1;
    
    x3 = x2 - dy;
    y3 = y2 + dx;
    x4 = x1 + x3 - x2;
    y4 = y1 + y3 - y2;
    
    printf("%d %d %d %d\n", x3, y3, x4, y4);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while( x != NIL ){
    y = x;
    if ( z->key < x->key ){
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;
  if ( y == NIL ){
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
       }
  }
}

void inorder(Node u){
  if (u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
  
}
void preorder(Node u){
  if (u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
      if ( com[0] == 'i' ){
	scanf("%d", &x);
	insert(x);
      } else if ( com[0] == 'p' ){
	inorder(root);
	printf("\n");
	preorder(root);
	printf("\n");
      }
  }

  return 0;
}


Measured memory_bytes: 25172
import sys


def input():
    return sys.stdin.readline().strip()


MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)
INF = float("inf")


def main():
    N = int(input())
    A = list(map(int, input().split()))
    # 初期値
    right, ans, tmp = 0, 0, 0

    # leftは0〜Nまで
    for left in range(N):
        while right < N and tmp ^ A[right] == tmp + A[right]:
            tmp += A[right]
            ans += right - left + 1
            right += 1

        # リストの長さが0になったら、どちらも一つ進める
        if left == right:
            right += 1
        # それ以外の場合はleftを一つ進める(合計値から一番左の値を引いておく)
        else:
            tmp -= A[left]
    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

const int MX = 100 * 1000 + 7;

int a[MX];

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        a[u] ^= 1;
        a[v] ^= 1;
    }
    for (int i = 1; i <= n; i++) {
        if (a[i]) {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}


Measured memory_bytes: 640
bmi :: Float -> Float -> Float
bmi w h = w / (h ^ 2)

isFat :: Float -> Bool
isFat = (>=25.0)

solve :: [(Int, Float, Float)] -> [(Int, Float, Float)]
solve = filter f
  where f (_, w, h) = isFat $ bmi w h

main :: IO ()
main = getContents >>= mapM_ printResult . solve . input
  where input = map (tup . words) . lines . map c2s
        printResult (i, _, _) = print i
        tup (i:w:h:_) = (read i, read w, read h)
        c2s ',' = ' '
        c2s c   = c

Measured memory_bytes: 4008
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<62;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[8]={0,1,0,-1,1,1,-1,-1},dy[8]={1,0,-1,0,1,-1,1,-1};

int n,K;
vl x,y;

int main(){
	cin>>n>>K;
	x=y=vl(n);
	for(int i=0;i<n;i++) cin>>x[i]>>y[i];
	ll res=INF;
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) for(int I=0;I<n;I++) for(int J=0;J<n;J++) if(x[i]<x[j]&&y[I]<y[J]){
		int cnt=0;
		for(int k=0;k<n;k++) if(x[i]<=x[k]&&x[k]<=x[j]&&y[I]<=y[k]&&y[k]<=y[J]) cnt++; 
		if(cnt>=K) res=min(res,(x[j]-x[i])*(y[J]-y[I]));
	}
	cout<<res<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <utility>
#include <iomanip>
#include <queue>
#include <set>
#include <numeric>
#include <unordered_set>

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

using namespace std;


int main(){
    int N;
    cin>>N;
    
    
    ll L[N];
    for(int i=0;i!=N;++i){
        cin>>L[i];
    }
    if(N==1){
        cout<<0<<endl;
        
    }else{
        
        ll count=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((L[i]!=L[j])&&(L[j]!=L[k])&&(L[k]!=L[i])){
                        if((L[i]+L[j]>L[k])&&(L[j]+L[k]>L[i])&&(L[k]+L[i]>L[j])){
                            ++count;
                        }
                    }
                }
            }
        }
        cout<<count<<endl;
    }
}



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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

vec_p memo;

struct UnionFind
{
    vector<long long> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    long long root(long long x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(long long x, long long y)
    {                           // xとyの木を併合
        long long rx = root(x); //xの根をrx
        long long ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(long long x, long long y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        long long rx = root(x);
        long long ry = root(y);
        return rx == ry;
    }
};

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

    ll N,M;
    string S;
    cin >> N>>M;

    UnionFind tree(N + 1);

    REP(i, M)
    {
        ll a, b;
        cin >> a >> b;
        tree.unite(a, b);
    }

    vector<ll> count(N+1);
    REP(i,N+1){
        count.at(i) = 0;
    }

    REPS(i,N){
        ll tmp = tree.root(i);

        count.at(tmp)++;
    }

    sort(count.begin(), count.end());
    reverse(count.begin(), count.end());

    cout << count.at(0) << endl;
}


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

#define INF 1e9
vector<int> memo;

int fib(int n){
  if(memo[n] == -INF){ memo[n] = fib(n - 1) + fib(n - 2); }
  return memo[n];
}

int main(void){
  int n;
  cin >> n;
  
  memo = vector<int>(n + 1, -INF);
  memo[0] = memo[1] = 1; 
  
  cout << fib(n) << endl;
  return 0;
}

Measured memory_bytes: 3152
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}

/********************************************************/
//	d.erase(unique(all(d)), d.end());




int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		// reverse(a.begin(),a.end());
		cin>>n>>m;
		// n=s.length();
		// ll a[n];
		if((n-1)/2019!=m/2019)
		{
			cout<<"0";
			return 0;
		}
		n=n%2019;
		m=m%2019;
		c=LLONG_MAX;
		repe(i,n,m+1)
		{
			repe(j,i+1,m+1)
			{
				c=min(c,(i*j)%2019);
				// debug3(i,j,c);
			}
		}
		
		
		cout<<c;
		
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256