akhauriyash/Code-Regression huggingface dataset:
def main():
    from math import gcd
    from functools import reduce
    n, *a, = map(int, open(0).read().split())
    m = max(a)

    d = [0] * (m + 1)
    d[1] = 1
    for i in range(2, m + 1):
        for j in range(i, m + 1, i):
            if d[j] == 0:
                d[j] = i

    def primes(x):
        ps = set()
        while x != 1:
            p = d[x]
            ps.add(p)
            x = x // d[x]
        return ps

    b = set()
    f = 0
    for i in a:
        ps = primes(i)
        if b & ps:
            f = 1
            break
        b |= ps
    if f > 0 and reduce(gcd, a) != 1:
        f = 2

    ans = ["pairwise coprime", "setwise coprime", "not coprime"][f]
    print(ans)


if __name__ == '__main__':
    main()


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

ll f(int n) {
    if (n < 2) return 0;
    return (ll)n * (ll)(n-1) / 2;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> c(n+1);
    rep(i, n) {
        cin >> a[i];
        c[a[i]]++;
    }
    ll sum = 0;
    rep(i, n+1) {
        sum += f(c[i]);
    }
    rep(i, n) {
        ll ans = sum - (c[a[i]] - 1);
        cout << ans << endl;
    }
}

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

using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)

int main(){
	int n,a;
	cin >> n >> a;
	if(n % (2 * a + 1) != 0)cout << n / (2 * a + 1) + 1 << endl;
	else  cout << n / (2 * a + 1) << endl;
	return 0;
}


Measured memory_bytes: 256
import math
N,D = map(int,input().split())
cood = []
for i in range(N):
    cood.append(list(map(int,input().split())))

count = 0
for i in range(N) :
    for j in range(N) :
        if i == j :
            continue
        dist = 0.0
        for k in range(D):
            dist += (cood[i][k] - cood[j][k]) ** 2
        dist = math.sqrt(dist)
        if dist.is_integer() :
            count += 1
print(int(count / 2))


Measured memory_bytes: 3064
#include "bits/stdc++.h"

#pragma warning(disable : 4996)

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
//#define int long long;

double dist(double x1, double y1, double x2, double y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
ll idist(ll x1, ll y1, ll x2, ll y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
using namespace std;

signed main() {
  string a, b;
  cin >> a >> b;
  int d = 16777216;
  rep(i,a.length()- b.length()+1) {
    int c = 0;
    rep(j, b.length()) {
      if (a[i + j] != b[j])c++;
    }
    //cout << i << " " << c << endl;
    d = min(c, d);
  }
  cout << d;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF = (1LL<<60)-1;
const int maxN = 1000001;
int32_t main(){
    SPEED;
    int n;
    cin >> n;
    int arr[n];
    read(arr);
    int preSum[n] = {};
    preSum[0] = arr[0];
    for(int i = 1; i < n; ++i){
        preSum[i] = arr[i] + preSum[i - 1];
    }
    int ans = 0;
    for(int i = 1; i < n; ++i){
        ans = ((ans % mod) + ((arr[i] % mod) * (preSum[i - 1] % mod)) % mod) % mod;
    }
    cout << ans << endl;

}


Measured memory_bytes: 6760
from collections import deque
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
CB = deque([])
for i in range(M):
    B, C = map(int, input().split())
    CB.append([C, B])
CB = sorted(CB, reverse=True)
flag = False
c = 0
I = 0
for i in CB:
    I += i[1]
    if flag:
        break
    while c < I:
        if c >= N:
            break
        if A[c] < i[0]:
            A[c] = i[0]
            c += 1
        else:
            c = I
            flag = True
print(sum(A))

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

using namespace std;

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

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<max(0,c - (a-b))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, c, f, i, j, a[200000], vis[1000001], spf[1000001];
int main()
{
    ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  	for (i = 2; i <= 1e6; i += 2)
        spf[i] = 2;
    for (i = 3; i < 1e6; i += 2)
        spf[i] = i;
    for (i = 3; i < 998; i += 2)
        if (spf[i] == i)
            for (j = i * i; j < 1e6; j += i)
                if (spf[j] == j)
                    spf[j] = i;
    cin >> n;
    for (i = 0; i < n; i++)
        cin >> a[i], vis[a[i]]++;
    if (vis[1])
    {
        if (vis[1] == 1)
            cout << 1 << '\n';
        else
            cout << 0 << '\n';
        return 0;
    }
    for (i = 0; i < n; i++)
        if (vis[a[i]] == 1)
        {
            if (a[i] != spf[a[i]])
                for (j = spf[a[i]]; j * j <= a[i]; j++)
                    if (a[i] % j == 0 && (vis[a[i] / j] || vis[j]))
                    {
                        c++;
                        break;
                    }
        }
        else c++;
    cout << n - c << '\n';
}

Measured memory_bytes: 12140
/*
 *  Created on: 3 / 7 / 2020
 *  Author:     Eslam Waheed
 */

#define _CRT_SECURE_NO_WARNINGS
//#define __USE_MINGW_ANSI_STDIO

#include <bits/stdc++.h>
//#include <bits/BIGINT.h>
//#include <bits/Int128.h>
using namespace std;

#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define dd   double
#define ld   long dd
#define ss   string

#define pb      push_back
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n);
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   (ll)(s.size())
#define endl    '\n'

#define loop(i,m,n)  for(ll i=m;i<n;i++)
#define test(t)      while(t--)

//ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

//const ld PI = acos(-1);
//const ll mod = 1e9 + 7;
//const ld EPS = 1e-8;
//__int128
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/

void solve()
{
    ll n; cin >> n;
    n %= 1000;
    cout << (1000 - n) % 1000;
}
int main()
{
    //stp(0)
    Eslam__Waheed
        solve();
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  int n;
  cin >> n;
  vector<int> hoge(n);
  rep_i(i, n){
    cin >> hoge[i];
  }

  int num = 0;
  rep_i(i, n){
    if(num + 1 == hoge[i]){
      num += 1;
    };
  }

  if(num == 0){
    say(-1);
  }else{
    say(n - num);
  }
  // int count = 0;
  // int e = 0;
  // sort_v(hoge);
  // hoge.erase(unique(hoge.begin(), hoge.end()), hoge.end());
  // e = n - hoge.size();
  
  // rep_i(i, hoge.size()){
  //   if((i+1) == hoge[i]){
  //     count += 1;
  //   }else{
  //     break;
  //   }
  // }

  // cout << "e: " << e << endl;
  // cout << "hoge: " <<  hoge.size() << endl;
  // cout << "count: " <<  count << endl;
  // if(count == 0){
  //   say(-1);
  // }else{
  //   say(e + (hoge.size() - count));
  // }
}

Measured memory_bytes: 1024
fn main() {
    let n = read::<usize>();
    let v = read_vec::<usize>();
    let c = read_vec::<usize>();

    let mut ret = 0;
    for i in 0..n {
        if v[i] > c[i] {
            ret += v[i] - c[i];
        }
    }
    println!("{}", ret);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstring>

using namespace std;
int l, dp[100005][2];
char str[100005];

int main() {
    cin >> str;
    l = strlen(str);
    if (str[0] == '0')dp[0][0] = 0, dp[0][1] = 1;
    else dp[0][1] = 0, dp[0][0] = 1;
    for (int i = 1; i < l; i++) {
        if (str[i] == '0')dp[i][0] = dp[i - 1][1], dp[i][1] = dp[i - 1][0] + 1;
        else dp[i][1] = dp[i - 1][0], dp[i][0] = dp[i - 1][1] + 1;
    }
    cout << min(dp[l - 1][0], dp[l - 1][1]);
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define int ll

int n,k;
int a[1000000];

signed main(){
  cin>>n>>k;
  rep(i,n){
    cin>>a[i];
  }
  sort(a,a+n);

  int ans=0;
  rep(i,n){
    if(i==n-1&&a[i]==k||i!=n-1&&a[i]<=k){
      ans++;
      k-=a[i];
    }
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


def solve(A: int, B: int):
    return A * B if A <= 9 and B <= 9 else -1


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    print(f'{solve(A, B)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 74888
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main()
{
	int i,j,k;
	map<char,string>c2s;
	const char transStr1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
	for(i=0; transStr1[i]; ++i)
	{
		string s;
		for(j=0;j<5;++j)
		{
			if(i&(0x10>>j)) s+='1';
			else s+='0';
		}
		c2s[transStr1[i]]=s;
	}
	map<string,char>s2c;
	
	s2c["101"] = ' ';
	s2c["000000"] = '\'';
	s2c["000011"] = ',';
	s2c["10010001"] = '-';
	s2c["010001"] = '.';
	s2c["000001"] = '?';
	s2c["100101"] = 'A';
	s2c["10011010"] = 'B';
	s2c["0101"] = 'C';
	s2c["0001"] = 'D';
	s2c["110"] = 'E';
	s2c["01001"] = 'F';
	s2c["10011011"] = 'G';
	s2c["010000"] = 'H';
	s2c["0111"] = 'I';
	s2c["10011000"] = 'J';
	s2c["0110"] = 'K';
	s2c["00100"] = 'L';
	s2c["10011001"] = 'M';
	s2c["10011110"] = 'N';
	s2c["00101"] = 'O';
	s2c["111"] = 'P';
	s2c["10011111"] = 'Q';
	s2c["1000"] = 'R';
	s2c["00110"] = 'S';
	s2c["00111"] = 'T';
	s2c["10011100"] = 'U';
	s2c["10011101"] = 'V';
	s2c["000010"] = 'W';
	s2c["10010010"] = 'X';
	s2c["10010011"] = 'Y';
	s2c["10010000"] = 'Z';

	string input;
	while(getline(cin,input))
	{
		string codeStr;
		for(i=0; i<input.size(); ++i)
			codeStr += c2s[input[i]];
		for(i=0,j=0; j<codeStr.size(); ++j)
		{
			auto ite = s2c.find(codeStr.substr(i,j-i+1));
			if(ite != s2c.end())
			{
				putchar(ite->second);
				i=j+1;
			}
		}
		puts("");
	}
	return 0;
}

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

int main(){
  string s[3];
  cin >> s[0] >> s[1] >> s[2];
  char turn = 0;
  char tmp;
  while(1){
    if(s[turn]=="") break;
    tmp=turn;
    turn=s[turn][0]-'a';
    s[tmp].erase(s[tmp].begin());
  }
  cout << (char)('A'+turn) << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int n;
	cin >> n;
	if (n < 1000) {
		cout << "ABC";
	}
	else {
		cout << "ABD";
	}
	system("pause");
	return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

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

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi h(n);
    rep(i, n) cin >> h[i];
    int ans = 0, cnt = 0;
    rep(i, n-1) {
        if (h[i]>=h[i+1]) ++cnt;
        else {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    if (cnt > 0) ans = max(ans, cnt);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3788
"use strict";
// inputに入力データ全体が入る
const main = (input) => {
  const [a, b, c] = input.trim().split(" ");
  if (a.slice(-1) === b.slice(0, 1) && b.slice(-1) === c.slice(0, 1)) {
    return "YES";
  } else {
    return "NO";
  }
};

// ※この行以降は編集しない (標準入力から一度に読み込みMainを呼び出します)
console.log(main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 30528
#include <stdio.h>
#include <math.h>

int main(){
    int i,j;
    double s[10001],n,ave,dec;

    while(1){
        scanf("%lf",&n);
        if(n==0) break;
        for(s[0]=0,i=1;i<=n;i++){
            scanf("%lf",&s[i]);
            s[0]+=s[i];
        }
        ave=s[0]/n;
        for(dec=0,i=1;i<=n;i++) dec+=(s[i]-ave)*(s[i]-ave);
        printf("%f\n",sqrt(dec/n));
    }

    return 0;
}

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

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

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

  vector<bool> te(n),ae(n);

  te[0] = true;
  for(int i=1; i<n; i++){
    if(t[i-1]==t[i]){
      te[i]=false;
    }else{
      te[i]=true;
    }
  }

  ae[n-1] = true;
  for(int i=n-2; i>=0; i--){
    if(a[i+1]==a[i]){
      ae[i]=false;
    }else{
      ae[i]=true;
    }
  }

  long long int ans = 1;
  for(int i=0; i<n; i++){
    if(te[i] && ae[i]){
      if(t[i]!=a[i]){
        ans = 0;
        break;
      }
    }else if(te[i]){
      if(t[i]>a[i]){
        ans = 0;
        break;
      }
    }else if(ae[i]){
      if(a[i]>t[i]){
        ans = 0;
        break;
      }
    }else{
      ans = (ans*min(a[i],t[i])) % ((long long int)1e9+7);
    }
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x,i,ans=0;
  cin>>n>>x;
  vector<int> m(n);
  for(i=0;i<n;i++){
    cin>>m.at(i);
    x-=m.at(i);
    ans++;
  }
  sort(m.begin(),m.end());
  ans+=x/m.at(0);
  cout<<ans<<endl;
}

Measured memory_bytes: 3604
n = int(input())
a_list = list(map(int, input().split()))
a_dict = {}
a_sum = sum(a_list)
for a in a_list:
    if a in a_dict:
        a_dict[a] += 1
    else:
        a_dict[a] = 1

q = int(input())

for i in range(q):
    b, c = map(int,input().split())
    diff = 0
    if b in a_dict:
        diff = a_dict[b] * (c - b)
        if c in a_dict:
            a_dict[c] += a_dict[b] 
        else:
            a_dict[c] = a_dict[b]
        a_dict.pop(b)
    a_sum += diff
    print(a_sum)

Measured memory_bytes: 20852
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        int d=sc.nextInt();
        int x=0;
        int k=0;
        while(true) {
            if (x % 2 == 0) {
                if (c > b) {
                    c -= b;
                    x++;
                } else {
                    k = 1;
                    break;
                }
            }
            else {
                if (a > d) {
                    a -= d;
                    x++;
                } else {
                    k = 2;
                    break;
                }
            }
        }
        if(k==1)
            System.out.println("Yes");
        if(k==2)
            System.out.println("No");
    }
}


Measured memory_bytes: 35508
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<long long int>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vb vector<bool>
#define vvl vector<vector<ll> >
#define vvi vector<vector<int> >
#define pl pair<ll,ll>
#define pb push_back
#define PI 3.14159265
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fri(s,n) for(int i=s;i<n;i++)
#define frj(s,n) for(int j=s;j<n;j++)
#define T(i) int i=1;cin>>i;while(i--)
#define vsi vector<set<int> >
#define pii pair<int,int>
#define inf 1e9
#define vpii vector<pair<int,int> >


ll power(ll a,ll b){
    if(b==0)
        return 1;
    if(b&1)
        return a*power(a,b-1);
    ll temp=power(a,b/2);
    return temp*temp;
    }
bool mycompare(ll a,ll b){
    return a>b;
    }
ll dp[100005][2];
vector<vector<int> > graph;
ll solve(vector<vector<int> >& graph,int parent,int node,int col){
  	if(dp[node][col]!=-1)
      	return dp[node][col];
    dp[node][col]=1;
  	for(auto nbr:graph[node]){
      	if(nbr!=parent){
        	if(col)
                dp[node][col]=dp[node][col]*(solve(graph,node,nbr,0)+solve(graph,node,nbr,1)%mod)%mod;
            else
                dp[node][col]=dp[node][col]*solve(graph,node,nbr,1)%mod;
        }
    }
    return dp[node][col];
}

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
  	int n;
  	cin>>n;
  	memset(dp,-1,sizeof dp);
    graph.resize(n+1);
  	for(int i=0;i<n-1;i++){
      	int x,y;
      	cin>>x>>y;
    	graph[x].push_back(y);
      	graph[y].push_back(x);
    }
  	cout<<(solve(graph,0,1,1)%mod+solve(graph,0,1,0)%mod)%mod;

	}



Measured memory_bytes: 21392
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;

int main(){
   lint N,ans=1;
   cin>>N;
   lint A[N];
   rep(i,N){
       cin>>A[i];
   }
   sort(A,A+N);
   if(N%2==0){
       lint y=1;
       rep(i,N-1){
          if(A[i]==y&&A[i+1]==y) {
              y+=2;
              i++;
          }else{cout<<0<<endl;
return 0;
          }
       }
   }
      if(N%2==1){
       lint x=0;
       rep(i,N-1){
        if(i==0&&A[i]==0){
            x+=2;
            continue;
        }else if(i==0&&A[i]!=0) {cout<<0<<endl;
        return 0;
        }
         if(A[i]==x&&A[i+1]==x) {
              x+=2;
              i++;
          }else{ cout<<0<<endl;
            return 0;
          }
       }
   }
    lint S=N;
    S/=2;
    rep(i,S){
            ans*=2;
            ans%=MOD;
    }
    cout<<ans;
}

Measured memory_bytes: 1024
N = int(input())
C = list(input())

i = 0
j = N-1
ans = 0
while True:
    if j <= i:
        break
    c = C[i]
    rc = C[j]
    if c=="W" and rc=="R":
        ans += 1
        i += 1
        j -= 1
    elif c=="W" and rc=="W":
        j -= 1
    elif rc=="R" and rc=="R":
        i += 1
    else:
        i += 1
        j -= 1
print(ans)


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

int main(){
  int X; cin >> X;
  vector<bool> p(1000000, true);
  p[0] = p[1] = false;
  for(int i=2; i<1000; i++){
    if(p[i]==false) continue;
    int now = i;
    while(1){
      now += i;
      if(now>=1000000) break;
      else p[now] = false;
    }
  }
  rep(i,1000000){
    if(i>=X && p[i]){
      cout << i <<endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){return modpow(x,mod-2);}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,k;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>k;
    int ans=0;
    for(int i=k;i<=n+1;i++){
        int ma=(n+n-i+1)*i/2;
        int mi=(i-1)*i/2;
        ans+=ma-mi+1;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;
#define int long long

signed main(){
  int N;cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  sort(v.begin(),v.end());
  int ans=0;
  while(v[N-1]>N-1){
    int k=0;
    for(int i=0;i<N;i++){
      if(v[i]<=N-1)continue;
      int a=(v[i]-(N-1)-1)/N+1;
      k+=a;v[i]-=a*(N+1);
    }
    for(int i=0;i<N;i++)v[i]+=k;
    ans+=k;
    sort(v.begin(),v.end());
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
def main():
    N = int(input())

    if N == 1:
        print(0)
    else:
        def prime_list(n):
            prime = [True for _ in range(n+1)]
            prime[0] = False
            prime[1] = False
            for i in range(2,int(n**0.5)+1):
                if not prime[i]:
                    continue
                for j in range(i*2,n+1,i):
                    prime[j] = False
            return [i for i in range(n+1) if prime[i]]

        prime_list = prime_list(N//2)
        cnt_list = [0 for _ in range(len(prime_list))]
        for i in range(len(prime_list)):
            count = 0
            d = N
            while d >= 1:
                count += d//(prime_list[i])
                d //= prime_list[i]
            cnt_list[i] = count

        def num(X):
            return len(list(filter(lambda x:x>=X-1,cnt_list)))

        print(num(75)+num(15)*(num(5)-1)+num(25)*(num(3)-1)+\
            num(5)*(num(5)-1)*(num(3)-2)//2)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <chrono>
#include <random>

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

const int ms = 200100;

std::vector<int> edges[ms];
int ans[ms];

void dfs(int on, int par) {
	for(auto to : edges[on]) {
		if(to == par) continue;
		ans[to] += ans[on];
		dfs(to, on);
	}
}

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n, q;
	std::cin >> n >> q;
	for(int i = 1; i < n; i++) {
		int u, v;
		std::cin >> u >> v;
		u--;v--;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}
	while(q--) {
		int p, x;
		std::cin >> p >> x;
		p--;
		ans[p] += x;
	}
	dfs(0, 0);
	for(int i = 0; i < n; i++) {
		std::cout << ans[i] << (i + 1 == n ? '\n' : ' ');
	}
}

Measured memory_bytes: 23552
#include<bits/stdc++.h>
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 ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumlate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

main(){
  ll x; cin >> x;
  ll ans = (x / 11) * 2;
  x %= 11;
  //cout << ans << " " << x << endl;
  if(0 < x and x <= 6){
    ans++;
    x -= 6;
  }else if(6 < x){
    ans += 2;
    x -= 11;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

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 RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

LL K;
LL a[55];

int main() {
    cin >> K;
    if (K == 0) {
        cout << 2 << "\n" << "0 0" << endl;
    } else {
        const int n = 50;
        cout << n << endl;
        REP(i, n) a[i] = 49 + K / n;
        REP(i, K  % 50) {
            REP(j, n) {
                if (i == j) a[i] += n;
                else a[j]--;
            }
        }
        REP(i, n) {
            cout << a[i] << (i + 1 == n ? "\n" : " ");
        }
    }
}


Measured memory_bytes: 256
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i
    integer(int64), allocatable:: x(:),y(:),w(:),z(:)


    read*, n
    allocate(x(n), y(n))
    do i=1,n
        read*, x(i),y(i)
    end do
    allocate(w(n),z(n))
    z(:) = x(:)+y(:)
    w(:) = x(:)-y(:)
    print'(i0)', max(maxval(z)-minval(z), maxval(w)-minval(w))
end program main

Measured memory_bytes: 9108
import java.util.*;

public class Main{
    public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    String w = sc.next().toLowerCase();
    

    int cnt=0;

    while(true){
        String T = sc.next();
        if(T.equals("END_OF_TEXT"))    break;
        String t = T.toLowerCase();
        if(t.equals(w))    cnt++;
        
    }

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


Measured memory_bytes: 26420
#include <bits/stdc++.h>
using namespace std;
 
typedef long long               ll;
typedef long double             ld;
 
 
#define racecar          ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time_start		 time_t start, end; time(&start); 
#define time_end		 time(&end);double time_taken=double(end-start);cout <<"\n"<< time_taken*1000<<" ms";
#define si(a)            scanf("%d", &a)
#define si2(a,b)         scanf("%d %d", &a,&b)
#define sll(a)           scanf("%I64d",&a)
#define sll2(a,b)        scanf("%I64d %I64d",&a,&b)
#define pb               push_back
#define pi(a)            printf("%d",int(a))
#define pll(a)           printf("%I64d",ll(a))
#define all(x)           (x).begin(),(x).end()
#define rall(x)          (x).rbegin(),(x).rend()
#define ps               printf(" ")
#define nln              printf("\n")
#define ff               first
#define ss               second
#define vi               vector<int>
#define vll              vector<ll>
#define vstr             vector<string>
#define vc               vector<char>
#define pii              pair<int,int>
#define PLL              pair<ll,ll>
#define PI               acos(-1)
#define sq(x)            x*x
#define forr(i,a,b)      for(ll i=ll(a);i<ll(b);i++)
#define forn(i,a,b)      for(ll i=ll(a);i>ll(b);i--)
#define max3(a,b,c)      max(a,max(b,c))
#define max4(a,b,c,d)    max(max3(a,b,c),d)
#define min3(a,b,c)      min(a,min(b,c))
#define mod              1000000007
#define inf              9223372036854775807

///knight moves:
///int dx[] = {-2, -1, 1, 2, -2, -1, 1, 2}; 
///int dy[] = {-1, -2, -2, -1, 1, 2, 2, 1};

 
ll power(ll b,ll n)
{
    if(n==0) return 1;
    else if(n%2) return b*power(b,n/2)*power(b,n/2);
    else return power(b,n/2)*power(b,n/2);
}
 
ld root(ll n,ll r)
{
    ld dif=0.0001;
    ld guess=n/2.0;
    while(abs(pow(guess,r)-n)>=dif)
    {
        ld temp=pow(guess,r)-n;
        ld tmp=r*pow(guess,r-1);
        guess-=temp/tmp;
    }
    return guess;
}
 
void fileio()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}


int solve()
{
	int a,b;
	si2(a,b);
	
	pi(max3(a+b,a-b,a*b));
			
	return 0;
}
	
 
int main()
{
//	time_start;
//    racecar;
//    cout<<fixed<<setprecision(9);
//    fileio();
    solve();
//    time_end;
}

 
 
///    Before submission=>
///    ***check for integer overflow,array bounds
///    ***check for n


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

k = readint()
flag = 1
if k%2==0 or k%5==0:
    flag = 0

if flag:
    a = 7
    a %= k
    i = 1
    while 1:
        if a%k==0:
            print(i)
            exit()
        else:
            a+=7*pow(10,i,k)
            a%=k
            i+=1
else:
    print(-1)



Measured memory_bytes: 63612
void main()
{
    long n = rdElem;
    long[] a = n.rdCol;

    if (a[0])
    {
        writeln(-1);
        return;
    }

    long[] x = new long[n];
    x[n-1] = a[n-1];
    long cnt = x[n-1];
    foreach_reverse (i; 0 .. n-1)
    {
        if (x[i+1]) x[i] = x[i+1] - 1;
        if (i < x[i] || x[i] > a[i])
        {
            writeln(-1);
            return;
        }
        else if (x[i] < a[i])
        {
            cnt += a[i];
            x[i] = a[i];
        }
    }

    cnt.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

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

Measured memory_bytes: 5372
#include<iostream>
#include<cstring>
#include<cassert>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<time.h>
#include<algorithm>
using namespace std;
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define rep(i,n) REP(i,1,n)
#define rep0(i,n) REP(i,0,n-1)
#define repG(i,x) for(ll i=pos[x];~i;i=e[i].next)
#define ll long long
#define db double
const ll N=107;
const ll M=1007;
const ll INF=1e9+7;
char s[N];
ll k,n;
ll a[N],d[M];
ll calc(ll p){
	rep(i,p)rep(j,n)d[(i-1)*n+j]=a[j];
	ll gg=0;
	REP(i,2,p*n){
		if(d[i]==d[i-1]){
			gg++;
			d[i]=-1;
		}
	}
	return gg;
}
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	scanf("%lld",&k);
	rep(i,n)a[i]=s[i]-'a';
	bool fl=1;
	rep(i,n)if(a[i]!=a[1])fl=0;
	if(fl){
		printf("%lld\n",k*n/2);
		return 0;
	}
	if(k<=10){
		printf("%lld\n",calc(k));
		return 0;
	}
	ll v5=calc(5),v10=calc(10);
	ll o=(v10-v5)/5;
	printf("%lld\n",v10+o*(k-10));
	return 0;
}


Measured memory_bytes: 256
// 入力マクロ
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}



fn main() {
    input! {
        n: usize,
        a: [usize; n]
    }

    let mut count = vec![0; 100_002];
    for i in a {
        count[i] += 1;
        count[i+1] += 1;
        count[i+ 2] += 1;
    }

    let ans = count.iter().max().unwrap();
    println!("{}", ans);
}


Measured memory_bytes: 4352
n,m= map(int, input().split())
if m!=0:
  a = [int(input()) for _ in range(m)]
else:
  a=[0]
dp=[0]*(n+1)
dp[0]=1
j=0

for i in range(1,n+1):
    if i==a[j]:
        if j<m-1:
            j+=1
    else:
        if i==1:
            dp[i]=1
        else:
            dp[i]=dp[i-1]+dp[i-2]

print(dp[n]%(10**9+7))

Measured memory_bytes: 460020
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	var s string
	if sc.Scan() {
		s = sc.Text()
	}
	return s
}

func main() {
	sc.Split(bufio.ScanWords)
	s := nextString()
	var result string
	for range s {
		result += "x"
	}
	fmt.Println(result)
}


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

#define _rep4(i,n,N,k) for(int i=n,_i##_end=(N),_i##_inc=(k);i<_i##_end;i+=_i##_inc)
#define _rep3(i,n,N,_a) for(int i=n,_i##_end=(N);i<_i##_end;++i)
#define _rep2(i,N,_a,_b) _rep3(i,0,N,0)
#define _rep_call(a,b,c,d,name,...) name(a,b,c,d)
#define rep(...) _rep_call(__VA_ARGS__,_rep4,_rep3,_rep2)

int work(std::istream &in) {
  int N;
  in >> N;
  std::string S;
  in >> S;

  int next[10];
  int table[N + 2][10];
  memset(next, -1, sizeof(next));
  memset(table, -1, sizeof(table));

  rep(j, 10) next[j] = table[N][j] = table[N + 1][j] = N + 1;
  for (int i = S.size() - 1; 0 <= i; --i) {
    int d = S[i] - '0';
    rep(j, 10) {
      table[i][j] = next[j];
    }
    next[d] = table[i][d] = i + 1;
  }

  int r = 0;
  rep(i, 10) rep(j, 10) rep(k, 10) {
    r += N + 1 != table[table[table[0][i]][j]][k];
  }
  return r;
}

struct testdata {
  const char *input;
  int expected;
};

int test() {
  int ret = 0;

  struct testdata testset[] = {
    {"4\n0224", 3},
    {"6\n123123", 17},
    {"19\n3141592653589793238", 329},
  };

  const int TESTLEN = sizeof(testset) / sizeof(testset[0]);
  for (int i = 0; i < TESTLEN; ++i) {
    std::istringstream in(testset[i].input);

    int actual = work(in);
    int expected = testset[i].expected;
    if (actual != expected) {
      fprintf(stderr, "ERROR: expected %d, but actual %d\n", expected, actual);
      ret = 1;
    }
  }
  return ret;
}

int main(int argc, char *argv[]) {
  std::cin.tie(nullptr);
  std::cout << std::fixed << std::setprecision(15);

  if (argc == 2 && strcmp("--test", argv[1]) == 0) {
    return test();
  }
  printf("%d\n", work(std::cin));
  return 0;
}

Measured memory_bytes: 1536
def function(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1

s = int(input())
a = [s]
i = 1
while len(set(a)) == len(a):
    a.append(function(a[i-1]))
    i += 1
print(len(a))

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
int n,a[110];
ll ans=0,last=1;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);	
	for(int i=1;i<=n;i++)
	{
		ans=ans*3+last*(1+(a[i]&1));
		if((a[i]&1)==0) {last=last*2;} 
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct bag{
    int w;
    int v;
};
int main(){
    int n,W,i,j;
    cin>>n>>W;
    bag arr[n+1];
    for(i=1; i<=n; i++)
        cin>>arr[i].w>>arr[i].v;
    long long dp[n+1][W+1];
    for(i=0; i<=W; i++)
        dp[0][i]=0;
    for(i=0; i<=n; i++)
        dp[i][0]=0;
    for(i=1; i<=n; i++){
        for(j=1; j<=W; j++){
            if(j>=arr[i].w && (arr[i].v+dp[i-1][j-arr[i].w])>=dp[i-1][j])
                dp[i][j]=arr[i].v+dp[i-1][j-arr[i].w];
            else dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][W];
    return 0;
}

Measured memory_bytes: 79104
from collections import deque

lst = deque()

for l in range(int(input())):
  dat_set = input().split()
  command = dat_set[0]
  try:
    if command == 'insert':
      lst.appendleft(dat_set[-1])
    elif command == 'delete':
      lst.remove(dat_set[-1])
    elif command == 'deleteFirst':
      lst.popleft()
    elif command == 'deleteLast':
      lst.pop()
  except:
    pass

print(*lst)



Measured memory_bytes: 69736
'''     ##     ##  #######  # #  ######
        ##     ##  ##   ##  ###    ##
        ##     ##  ##    #  # #    ##
        #########  #######  # #    ##    '''

import sys
import math
# sys.setrecursionlimit(10**6)

def get_ints(): return map(int, input().strip().split())
def get_list(): return list(input())

def printspx(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")
def printchk(*args): return print(*args, end=" \ ")

MODPRIME = int(1e9+7); BABYMODPR = 998244353;

ONLINE_JUDGE = 1
if not ONLINE_JUDGE:
    sys.stdin  = open("input.txt","r")
    sys.stdout = open("output.txt","w")
    sys.stderr = open("output.txt","w")

# for _testcases_ in range(int(input())):
from collections import deque
a = deque(get_list())
b = deque(get_list())
c = deque(get_list())
li = [a, b, c]
curr = 0
while True:
    if len(li[curr]) == 0:
        print(chr(curr+ord('A')))
        break
    curr = ord(li[curr].popleft())-ord('a')





'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS BY ME @luctivud ( UDIT GUPTA )
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
DO NOT PLAGIARISE.
TESTCASES:
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''

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

int main() {
    int w,h;
    int a[101][101] = {0}; //initialize!
    
    cin >> w >> h;
    for ( int i = 0; i < w; i++ ) {
    	for ( int j = 0; j < h; j++ ) {
    		cin >> a[i][j];
    		a[w][j] += a[i][j];
    		a[i][h] += a[i][j];
    		a[w][h] += a[i][j];
    	}
    }
    for ( int i = 0; i <= w; i++ ) {
    	for ( int j = 0; j <= h; j++ ) {
    		cout << a[i][j];
    		if ( j != h ) cout << " ";
    	}
    	cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3140
#include"bits/stdc++.h"
using namespace std;

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int sum = 0, b = 0;
    string S;
    cin >> S;
    vector<bool> ans(S.size());
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'a') {
            if (sum < A + B) {
                ans[i] = true;
                sum++;
            }
        } else if (S[i] == 'b') {
            if (sum < A + B && b < B) {
                ans[i] = true;
                sum++;
                b++;
            }
        }
    }

    for (auto a : ans) {
        if (a) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

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


int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  for(int i=0;i<n;i++) cin >> x[i] >> y[i];
  vector<int> xpy(n);
  vector<int> xmy(n);
  for(int i=0;i<n;i++) {
    xpy[i] = x[i] + y[i];
    xmy[i] = x[i] - y[i];
  }
  sort(xpy.begin(),xpy.end());
  sort(xmy.begin(),xmy.end());
  cout << max(xpy[n-1]-xpy[0],xmy[n-1]-xmy[0]) << endl;

}

Measured memory_bytes: 6336
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;
using namespace std;



int main(){
	ll N; cin>>N;
	string s; cin>>s;
	vector<ll> r(N+1,0);
	vector<ll> g(N+1,0);
    vector<ll> b(N+1,0);
	for(int i = N-1;i>=0;--i){
        if(s[i] == 'R'){
          r[i] = r[i+1] + 1;
          g[i] = g[i+1];
          b[i] = b[i+1];
        }else if(s[i] == 'G'){
          r[i] = r[i+1];
          g[i] = g[i+1] + 1;
          b[i] = b[i+1];
        }else{
          r[i] = r[i+1];
          g[i] = g[i+1];
          b[i] = b[i+1] + 1;
        }
    }
 	ll ans = 0;
    REP(i,N-2)for(int j = i+1;j<=N-2;j++){
          ll k = 2*j - i;
    	  if(s[i] == 'R' && s[j] == 'G'){
            ans+=b[j+1];
            if(k<N) ans -= (s[k] == 'B');
          }else if(s[i] == 'R' && s[j] == 'B'){
            ans+=g[j+1];
            if(k<N) ans -= (s[k] == 'G');
          }else if(s[i] == 'G' && s[j] == 'R'){
            ans+=b[j+1];
            if(k<N) ans -= (s[k] == 'B');
          }else if(s[i] == 'G' && s[j] == 'B'){
            ans+=r[j+1];
            if(k<N) ans -= (s[k] == 'R');
          }else if(s[i] == 'B' && s[j] == 'R'){
            ans+=g[j+1];
            if(k<N) ans -= (s[k] == 'G');
          }else if(s[i] == 'B' && s[j] == 'G'){
            ans+=r[j+1];
            if(k<N) ans -= (s[k] == 'R');
          }
    }
    cout << ans;
  	return 0;
}



Measured memory_bytes: 3636