akhauriyash/Code-Regression huggingface dataset:
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

struct BIT{ //sample add
    vector<int> data;
    int nodes;

    BIT(int N){
        nodes=N;
        data.resize(nodes*2+1);
        for(auto i:data) i=0; //initialize;
    }

    void add(int k,int a){ //add a to element k
        k++;
        int tmp=0;
        while(k<=nodes){
            data[k]+=a;
            k += k & -k;
            //cout<<k<<endl;
            if(tmp>10) break;
        }
    }

    ll sum(int i){ //calc sum of [0,i)
        i++;
        ll ret = 0ll;
        while(i>0){
            ret+=data[i];
            i -= i & -i;
        }
        return ret;
    }
};


void solve(int cn) {
    int N,Q; cin>>N>>Q;
    vector<int> c(N);
    for (int i = 0; i < N; ++i) {
        cin>>c[i];
        c[i]--;
    }
    vector<pair<pair<int,int>,int>> q(Q);
    int l,r;
    for (int i = 0; i < Q; ++i) {
        cin>>l>>r; --l; --r;
        q[i]=make_pair(make_pair(r,l),i);
    }
    sort(q.begin(),q.end());
    vector<int> ans(Q),right(N,-1);
    BIT bit = BIT(N);
    int idx=0;
    for (int i = 0; i < Q; ++i) {
        while(idx<=q[i].first.first){
            int color = c[idx];
            if(right[color]>=0){
                bit.add(right[color],-1);
            }
            right[color]=idx;
            bit.add(right[color],1);
            idx++;
        }
        ans[q[i].second] = bit.sum(q[i].first.first)-bit.sum(q[i].first.second-1);
    }

    for(auto i:ans) cout<<i<<endl;

}


#define SINGLE
int main() {
#ifdef SINGLE
    solve(1);
#else
    int N;
    cin>>N;
    for(int i=0;i<N;++i){
        solve(i);
    }
#endif
    return 0;
}


Measured memory_bytes: 19424
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	string s,t; cin >> s >> t;
	int ans = 0;
	rep(i,s.size()){
		ans += (s[i] != t[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3920
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T>

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

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

vector<int> bfs(vvi L,int S){ //List,Start
  vector<int> v(L.size(),-1);
  v[S]=0;
  queue<int> q;
  q.push(S);
  while(!q.empty()){
    int a=q.front();
    q.pop();
    for(int x:L[a]){
      if (v[x]==-1){
        v[x]=v[a]+1;
        q.push(x);
      }
    }
  }
  return v;
}

void initialize(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << fixed << setprecision(15);
}

/////////////////////////////////////////

int main(){
  initialize();
  int N,D;
  cin >> N >> D;
  int x[N][D];
  rep(i,N)rep(j,D) cin >> x[i][j];
  int ans=0;
  for(int i=0;i<N;i++)for(int j=i+1;j<N;j++){
    int a=0;
    rep(k,D) a+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
    if(a==(int)sqrt(a)*(int)sqrt(a)){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a[4], b[4];
    while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>b[0]>>b[1]>>b[2]>>b[3]){
        int hit=0, blow=0;
        for(int i=0; i<4; i++){
            if(a[i]==b[i]){
                ++hit;
                continue;
            }
            for(int j=0; j<4; j++){
                if(i!=j&&b[i]==a[j]){
                    ++blow;
                    break;
                }

            }
        }
        cout<<hit<<' '<<blow<<'\n';
    }
    return 0;
}

Measured memory_bytes: 3068
#include <iostream>

using namespace std;

#include <vector>
#include <sstream>
#include <algorithm>
#include <numeric>


int main(void) {
    // 自分の得意な言語で
    // Let's チャレンジ！！

    string str;
    int N;
    vector<int> a;
    int count = 0;
    while (getline(cin, str)) {
        stringstream ss;
        ss << str;
        if (count == 0) {
            ss >> N;
        } else {
            for (int i = 0; i < N; ++i) {
                int temp;
                ss >> temp;
                a.push_back(temp);
            }
            break;
        }


        count++;
    }

    int average = (accumulate(a.begin(), a.end(), 0) % N < (double) N / 2) * (accumulate(a.begin(), a.end(), 0) / N) +
            (accumulate(a.begin(), a.end(), 0) % N >= (double) N / 2) * (accumulate(a.begin(), a.end(), 0) / N + 1);

    int sum = 0;

    for (int j = 0; j < N; ++j) {
        sum += (a[j] - average) * (a[j] - average);
    }


    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int n;
	cin >> n;
	
	double v[50];
	rep(i,n) {
		cin >> v[i];
	}
	sort(v, v + n);

	double a = v[0];
	for (int i = 1; i < n;i++) {
		double b = v[i];

		a = (a + b) / 2;
	}

	printf("%.6f\n", a);




	return 0;
}

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

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a*a+b*b==c*c)cout<<a*b/2<<endl;
	else if(b*b+c*c==a*a)cout<<b*c/2<<endl;
	else cout<<c*a/2<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length();
        char[] a = new char[26];
        for(int i = 0 ; i < 26 ;i++) {
            a[i] = (char)('a'+ i);
        }
        int min = Integer.MAX_VALUE;

        for(int i = 0 ; i < 26 ;i++) {
            int temp = 0;
            List <Integer> l = new ArrayList<>();
            for(int j = 0 ; j < n ;j++) {
                if(s.charAt(j) == a[i]) {
                    l.add(j - temp);
                    temp = j+1;
                }
            }
            l.add(n - temp);
            Collections.sort(l);
            min = Math.min(min, l.get(l.size()-1));
        }

        System.out.println(min);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;

const int N = 3e5 + 5;



signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (i % 2 == 1 && x % 2 == 1)
            ans++;
    }
    cout << ans;
    return 0;
}


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

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

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//最大公約数
ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}

//複数個の最大公約数
ll ngcd(vector<ll> a)
{
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size() && res != 1; i++)
  {
    res = gcd(a[i], res);
  }
  return res;
}

//最小公倍数
ll lcm(ll a, ll b)
{
  return a / gcd(a, b) * b;
}

//複数個の最小公倍数
ll nlcm(vector<ll> numbers)
{
  ll res;
  res = numbers[0];
  for (ll i = 1; i < numbers.size(); i++)
  {
    res = lcm(res, numbers[i]);
  }
  return res;
}

//実行部
void Main()
{
  ll n; cin >> n;
  vll p(n); rep(i, n) cin >> p[i];
  fin(nlcm(p));
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/


Measured memory_bytes: 256
X, N = map(int, input().split())
p = list(map(int, input().split()))

if N == 0: print(X)
else:
    p.sort()
    if X in p:
        index = p.index(X)
        c = 1
        while True:
            if index - c >= 0 and p[index - c] != X - c:
                print(X - c)
                break
            elif index - c < 0:
                print(X - c)
                break
            elif index + c >= N:
                print(X + c)
                break
            elif index + c < N and p[index + c] != X + c:
                print(X + c)
                break
            else:
                c += 1

    else: print(X) 

Measured memory_bytes: 9216
import sys
input = sys.stdin.readline
S = list(input())[: -1]
t = []
res = 0
i = 1
while i < len(S):
  if S[i - 1] == "B" and (S[i] == "C"):
    t.append("X")
    i += 1
  else:
    if S[i - 1] == "A": t.append(S[i - 1])
    else: t.append("Y")
  i += 1
tt = "".join(t).split("Y")
for x in tt:
  xs = x.count("X")
  for i in range(len(x)):
    if x[i] == "A":
      res += xs
    else: xs -= 1
print(res)

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

int main() {

  while(1){ 
  int n,a,b,c,x;
  cin >> n >> a >> b >> c >> x;
  if(n == 0 && a == 0 && b==0&&c==0&&x==0) break;

  int y[101]={};
  for(int i=0;i<n;i++) cin >> y[i];

  int ans = 0;
  int ima=0;
  while(1){
    if(x == y[ima]){
      ima++;
      if(ima == n) break;
    }
    x = (a*x+b)%c;
    ans++;
    if(ans > 10000) {
      ans = -1;
      break;
    }
  }  

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

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << x << endl;
#else 
    #define dbg(x)
#endif

#define int long long
#define pb push_back
#define ppb pop_back()
#define mp make_pair
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 200010;
const double EPS = 1e-9;


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


ll add(ll a, ll b) {
    a += b;
    if (a >= MOD) return a - MOD;
    return a;
}

ll sub(ll a, ll b) {
    a -= b;
    if (a < 0) return a + MOD;
    return a;
}

ll mult(ll a, ll b) {
    return a * b % MOD;
}

ll powmod(ll a, ll p) {
    if (p == 0) return 1;
    if (p & 1) return mult(a, powmod(a, p - 1));
    return powmod(mult(a, a), p / 2);
}

ll rev(ll a) {
    return powmod(a, MOD - 2);
}

int f[MX];
int f1[MX];

int C(int n, int k) {
    if (k < 0 || k > n)
        return 0;
    return mult(f[n], mult(f1[k], f1[n - k]));
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    f[0] = 1;
    fi(1, MX)
        f[i] = mult(f[i - 1], i);
    f1[MX - 1] = rev(f[MX - 1]);
    fi1(MX - 1, 0)
        f1[i] = mult(f1[i + 1], i + 1);
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    int ans = C(h - 1 + w - 1, w - 1);
    fi(0, b) {
        int w1 = C(i + h - a - 1, i);
        int w2 = C(w - i - 1 + a - 1, w - i - 1);
        ans = sub(ans, mult(w1, w2));
    }
    cout << ans << '\n';
}

Measured memory_bytes: 6752
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

LL gcd(LL a, LL b){
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return gcd(b, a%b);
}

int main(){
    fastcin();

    LL a, b;
    cin >> a >> b;
    LL g = gcd(a, b);
    LL ans = 0;
    vector<LL> s;
    for(LL i = 1; i*i <= g; i++){
        if(g%i == 0){
            s.push_back(i);
            if(i*i != g) s.push_back(g/i);
        }
    }
    sort(all(s));
    rep(i, s.size()){
        bool f = 1;
        rep1(j, i) if(s[i] != -1 && s[i] % s[j] == 0){
            f = 0;
            break;
        }
        if(f) ans++;
    }
    cout << ans << endl;
}

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

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

  int fr = -1;
  vector<int> r;
  vector<char> c(n);
  for(int i=0;i<n;i++){
    cin >> c[i];
    if(fr<0)fr=i;
    if(c[i]=='R'){
      r.push_back(i);
    }
  }
  int rn = r.size();

  if(fr+1>rn){
    cout << rn << endl;
    return 0;
  }

  r.pop_back();
  // for(int i=0;i<r.size()+1;i++){
  //   cout << r[i];
  // }
  // cout <<  endl;

  int cnt=0;
  for(int i=0;i<n;i++){
    if(i>=r[r.size()]){
      break;
    }
    if(c[i]!='R'){
      cnt++;
      r.pop_back();
    }
  }
  

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 4412
import sys
input = sys.stdin.readline


def main():
    a, b, k = map(int, input().split())
    if a >= k:
        print(a-k, b)
        return
    if a+b >= k:
        k -= a
        print(0, b-k)
        return
    if a+b < k:
        print(0, 0)
        return


if __name__ == "__main__":
    main()


Measured memory_bytes: 9032
class List
  def initialize n
    @first = ListItem.new n
    @last = @first
  end

  def [] index
    current_item = @first

    # ?????????????????????
    index.times {|item|
      if current_item.next.nil?
        raise '?????£' + current_item.n
      end
      current_item = current_item.next
    }

    current_item
  end

  def insert val
    new_item = ListItem.new val

    if @first.nil?
      @first = new_item
      @last = new_item
    else
      new_item.next = @first
      @first.prev = new_item
      @first = new_item
    end
  end

  def search target
    current_item = @first

    loop do
      if  current_item.nil?
        return nil
      end
      if current_item.n == target
        return current_item
      end
      current_item = current_item.next
    end
  end

  def delete target
    target_item = search target
    return false if target_item.nil?

    # ????????????
    prev_item = target_item.prev
    next_item = target_item.next

    prev_item.next = next_item unless prev_item.nil?
    next_item.prev = prev_item unless next_item.nil?

    # ??????????±????????????????
    if prev_item.nil?
      @first = next_item
    end

    # ??????????±????????????????
    if next_item.nil?
      @last = prev_item
    end

    return true
  end

  def delete_first
    if @first.next.nil?
      @first = nil
      @last = nil
    else
      @first = @first.next
      @first.prev = nil
    end
  end

  def delete_last
    if @last.prev.nil?
      @last = nil
      @first = nil
    else
      @last = @last.prev
      @last.next = nil
    end
  end

  def print delimiter = ' '
    print_items = []
    current_item = @first
    until current_item.nil?
      print_items << current_item.n
      current_item = current_item.next
    end
    puts print_items.join delimiter
  end

  class ListItem
    def initialize n
      @n = n
      @next = nil
      @prev = nil
    end
    attr_accessor :next, :prev, :n
  end
end

def main commands
  # ??¨???????????????????????????insert??¨?????????
  list = List.new commands.shift.split(' ')[1]

  commands.each do |raw_command|
    #list.print
    command, arg = raw_command.split ' '
    case command
    when 'insert'
      list.insert arg
    when 'delete'
      list.delete arg
    when 'deleteFirst'
      list.delete_first
    when 'deleteLast'
      list.delete_last
    else
      raise '??????'
    end
  end
  list.print
end


inputs = STDIN.read.split(/\n/)
inputs.shift

main(inputs)

Measured memory_bytes: 301036
import java.io.*;
import java.util.*;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;
	
	List<Integer>[] g;
	int[] b;
	int k;
	
	int dfs(int v, int p) {
		int depth = 0;
		for (int u : g[v]) {
			if (u == p) {
				continue;
			}
			depth = Math.max(depth, dfs(u, v) + 1);
		}
		
		if (depth == k - 1) {
			b[v] = 0;
			return -1;
		}
		return depth;
	}

	void solve() throws IOException {
		int n = nextInt();
		k = nextInt();
		int[] a = new int[n];
		
		for (int i = 0; i < n; i++) {
			a[i] = nextInt() - 1;
		}
		
		b = a.clone();
		b[0] = 0;
		
		g = new List[n];
		for (int i = 0; i < n; i++) {
			g[i] = new ArrayList<>();
		}
		
		for (int i = 1; i < n; i++) {
			g[b[i]].add(i);
		}
		
		dfs(0, -1);
		
		int ret = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != b[i]) {
				ret++;
			}
		}
		
		out.println(ret);
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		
		Thread t = new Thread(null, new Runnable() {

			@Override
			public void run() {
				try {
					solve();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			
		}, "lul", 1 << 26);
		
		t.start();
		try {
			t.join();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 44128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

struct UnionFind{
    vector<ll> par;
    vector<ll> sizes;
    UnionFind(ll n) : par(n), sizes(n, 1) {
        rep(i,n) par[i] = i;
    }
    int find(ll x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    }
    void unite(ll x, ll y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x, y);
        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(ll x, ll y) {
        return find(x) == find(y);
    }

    ll size(ll x) {
        return sizes[find(x)];
    }
};


ll x[100010], y[100010];
ll ans = 0;
ll m = 100010;

int main(){
    ll n;
    cin >> n;
    UnionFind tree(2*m);
    rep(i, n) {
        cin >> x[i] >> y[i];
        tree.unite(x[i], y[i]+m);
    }
    map<ll, ll> mx, my;
    rep(i, m) mx[tree.find(i)]++;
    rep(i, m) my[tree.find(i+m)]++;

    rep(i, 2*m) ans += mx[i] * my[i];

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


Measured memory_bytes: 33064
#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>
#include <functional>

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 EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
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;

int main(void) {
    int N;
    LL K;
    cin >> N >> K;
    VI A(N);
    REP(i, N) {
        cin >> A[i];
        A[i]--;
    }

    VI cnt(N, -1);
    int cur = 0;
    int dist = 0;
    cnt[cur] = dist++;
    while (true) {
        cur = A[cur];
        if (cnt[cur] == -1) {
            cnt[cur] = dist++;
            continue;
        }

        break;
    }

    const int st = cnt[cur];
    const int loop = dist - cnt[cur];

    if (K <= st) {
        REP(i, N) {
            if (cnt[i] == K) {
                cout << i + 1 << endl;
                return 0;
            }
        }
    }

    K -= st;
    K %= loop;
    REP(i, N) {
        if (cnt[i] == st + K) {
            cout << i + 1 << endl;
            return 0;
        }
    }

    assert(false);
}


Measured memory_bytes: 4844
#include<stdio.h>

int main(void)
{
	int a[12], b, c, d, e, f;
	while (1) {
		scanf("%d", &b);
		c = 0;
		if (b == 0) break;
		for (d = 0;d < 12;d++)
		{
			scanf("%d %d", &e, &f);
			c += e - f;
			a[d] = c;
		}
		for (d = 0;d < 12;d++){
			if (a[d] >= b)
			{
				printf("%d\n", d + 1);
				break;
			}
	}
	if (c < b)printf("NA\n");
}
return;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s;
    cin >> n;
    cin >> s;
    int flag = 1;
    if(n%2!=0)
    {
       flag = 0;
    }
    else
    {
        for(int i=0;i<n/2;i++)
        {
            if(s[i]!=s[i+n/2])
            {
                flag=0;
            }
           /// cout << flag << endl;
        }
    }
    if(flag==1)
    {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
typedef pair<int,int> P;
typedef pair<int,P> PP; 
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1e9+7;

signed main(){
  int n;
  cin>>n;
  cout<<n*n*n<<endl;
  return 0;
}


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

int main()
{

  int d;
  cin >> d;

  vector<int> c(26);
  for(int i=0; i<26; ++i)
    cin >> c[i];

  vector<vector<int> > s(d, vector<int>(26));
  for(int i=0; i<d; ++i)
    for(int j=0; j<26; ++j)
      cin >> s[i][j];

  vector<int> t(d);
  for(int i=0; i<d; ++i){
    cin >> t[i];
    --t[i];
  }

  int ans = 0;
  vector<int> last(26,-1);
  for(int i=0; i<d; ++i){
    
    ans += s[i][t[i]];

    last[t[i]] = i;
    for(int j=0; j<26; ++j)
      ans -= c[j]*(i - last[j]);
    
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3600
#include<iostream>
using namespace std;
int main()
{
  int n;
  std::cin>>n;
  
  int i=1,t=0;
  for(;i<=9;i++)
  {
    t=n/i;
    if(t>=1&&t<=9&&(t*i)==n)
    {
      std::cout<<"Yes";
      return 0;
    }
  }
   /* for(;j=9;j++)
    {
      if(i*j==n)
      {
        std::cout<<"Yes";
        return 0;
      }
    }
  }*/
  std::cout<<"No";
  return 0;
}

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

int main(void)
{
    int A,B,C;
    ll X,Y;
    ll ans = 1000000000;
    cin >> A >> B >> C >> X >> Y;

    rep(i, 1000001){
        ll total = max((ll)0,X-i)*A+max((ll)0,Y-i)*B+2*i*C;
        ans = min(total,ans);
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;

using namespace std;

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

int main(){
	int A,B;
	cin >> A >> B;
	int i = 1;
	for(int i=1;i<=2000;i++){
		int temp = i*0.08;
		int temp2 = i*0.1;
		if(temp == A && temp2 == B){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


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

using namespace std;
#define LL long long
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int qq = 2e5 + 10;

int main(){
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	int d = a * 100 + b * 10 + c;
	if(d % 4 == 0){
		puts("YES");
	}else{
		puts("NO");
	}
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

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

	n := x
	for {
		isPrime := true
		for i := 2; i < int(math.Sqrt(float64(n))); i++ {
			if n%i == 0 {
				isPrime = false
				break
			}
		}
		if isPrime {
			fmt.Println(n)
			return
		}
		n++
	}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=998244353;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll a[1100000];
const ll MAX=210000;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

long long modpow(ll a, ll b) {
    ll res=1;
    while (b) {
        if (b&1)res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}

int main(){
    ll m,n,k,ans=0;
    cin>>n>>m>>k;
    COMinit();
    rep(i,0,k+1){
        ll tmp=(m*modpow(m-1,n-i-1))%mod;
        ll tmp2=COM(n-1, i)%mod;
         ans=(ans+(tmp*tmp2)%mod)%mod;
    }
    cout<<(ans+mod)%mod;
}


Measured memory_bytes: 8564
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    a = I()
    s = ST()
    if a >= 3200:
        print(s)
    else:
        print("red")
if __name__ == '__main__':
    main()

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

using ll = long long;

int main() {
    ll h; cin >> h;
    ll cnt = 1, ans = 0;
    while(h) {
        ans += cnt;
        h /= 2;
        cnt <<= 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a,b,ans=0;
  cin >> a;
  for(int i = 0;i<a;i++){
    cin >> b;
    if(b!=(i+1))ans++;
  }
  if(ans<3)cout << "YES";
  else cout << "NO";
}


Measured memory_bytes: 3592
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
struct Point{
    double x,y;
    Point(){}
    Point(double x,double y):x(x),y(y){}
};
typedef Point Vector;
Vector operator + (Vector A,Vector B){
    return Vector(A.x+B.x,A.y+B.y);
}
Vector operator - (Vector A,Vector B){
    return Vector(A.x-B.x,A.y-B.y);
}
Vector operator * (Vector A,double p){
    return Vector(A.x*p,A.y*p);
}
Vector operator / (Vector A,double p){
    return Vector(A.x/p,A.y/p);
}
bool operator < (const Point& a,const Point& b){
    return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
const double eps = 1e-10;
int dcmp(double x){
    if(fabs(x<eps)) return 0; else return (x<0?-1:1);
}
bool operator == (const Point& a,const Point& b){
    return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0;
}
//点积
double Dot(Vector A,Vector B){
    return A.x*B.x+A.y*B.y;
}
double Length(Vector A){
    return sqrt(Dot(A,A));
}
double Angle(Vector A,Vector B){
    return acos(Dot(A,B)/Length(A)/Length(B));
}
 
//叉积
double Cross(Vector A,Vector B){
    return (A.x*B.y-A.y*B.x);
}
//三角形面积的二倍的叉乘公式
double Area2(Point A,Point B,Point C){
    return Cross(B-A,C-A);
}
//向量旋转,rad是弧度
Vector Rotate(Vector A,double rad){
    return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
//计算向量的单位法线,先逆时针旋转90度，然后把长度归一化
Vector Normal(Vector A){
    double Len=Length(A);
    return Vector(-A.y/Len,A.x/Len);
}
//求两直线交点
//调用前请确保P+tv和Q+tw有唯一交点，当且仅当Cross(v,w)非0
Point GetLineIntersection(Point P,Vector v,Point Q,Vector w){
    Vector u=P-Q;
    double t=Cross(w,u)/Cross(v,w);
    return P+v*t;
}
//点到直线的距离
double DistanceToLine(Point P,Point A,Point B){
    Vector v1=B-A,v2=P-A;
    return fabs(Cross(v1,v2))/Length(v1);
}
//点到线段的距离
double DistanceToSegment(Point P,Point A,Point B){
    if(A==B) return Length(P-A);
    Vector v1=B-A,v2=P-A,v3=P-B;
    if(dcmp(Dot(v1,v2))<0) return Length(v2);
    else if(dcmp(Dot(v1,v3))>0) return Length(v3);
    else return fabs(Cross(v1,v2))/Length(v1);
}
//点在直线上的投影
Point GetLineProjection(Point P,Point A,Point B){
    Vector v=B-A;
    return A+v*(Dot(v,P-A)/Dot(v,v));
}
Point GetLineReflection(Point P,Point A,Point B){
    return GetLineProjection(P,A,B)*2-P;
}
int main(){
    Point A,B;
    cin>>A.x>>A.y>>B.x>>B.y;
    int t;
    cin>>t;
    while(t--){
        Point P;
        cin>>P.x>>P.y;
        cout<<fixed<<setprecision(10)<<GetLineReflection(P,A,B).x<<" "<<GetLineReflection(P,A,B).y<<endl;
    }
    return 0;
}


Measured memory_bytes: 3296
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)      //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++) //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)    //repeat from n to 0
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))        //array size
#define SORTD(a) sort(a,a+ASIZE(a),greater<int>()) //sort in descending order for array
#define SORTA(a) sort(a,a+ASIZE(a))                //sort in ascending order for array
#define SORTS(a) sort(a.begin(),a.end())           //sort in ascending order for string type
typedef long long ll;
 
void SCAN(int *a){scanf("%d",a);}                             //scan for type int
void SCAN(int *a,int n){int i;REP(i,n){scanf("%d",&a[i]);}}   //scan for type int array
void SCAN(char *c){scanf(" %c",c);}                           //scan for type char
void SCAN(char *c,int n){int i;REP(i,n){scanf(" %c",&c[i]);}} //scan for type char array
 
const int MOD = 1000000007;
const int INF = 1000000000;
 
int pascalTri(int n,int r){
	int tri[n+1][n+1];
	int i,j;
	REP(i,n+1){REP(j,n+1){tri[i][j]=0;}}
	REP(i,n+1){
		REP(j,n+1){
			if(j>i){break;}
			if(j==0||j==i){tri[i][j]=1;}else{tri[i][j]=(tri[i-1][j-1]%MOD+tri[i-1][j]%MOD)%MOD;}
		}
	}
	return tri[n][r];
}
 
const int DX4[4]= {-1,0,0,1};
const int DY4[4]= {0,-1,1,0};
 
int main(){
	char c[2][3];
	int i,j;
 
	REP(i,2){
		SCAN(c[i],3);
	}
 
	REP(j,3){
		if(c[0][j]!=c[1][2-j]){
			printf("NO\n");
			return 0;
		}
	}
 

	printf("YES\n");
 
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int k,n,i;
  int house[1000000];
  int max = 0;
  
  scanf("%d",&k);
  scanf("%d",&n);
  for(i = 0;i < n;i++)
    scanf("%d",&house[i]);
  
  for(i = 0;i < n;i++){
    if(max < house[i+1]-house[i]){
      max = house[i+1]-house[i];
    }
  }
  
  if(max < k + house[0] - house[n-1])
    max = k + house[0] - house[n-1];
  
  printf("%d\n",k-max);
  
  return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#include<vector>
#include<cmath>
#include<math.h>
#include<cstdlib>
#include<assert.h>
#include<string>
#include<sstream>
#include<algorithm>
#include<ctime>
#include<iostream>
#define ll long long 
#define ld long double
#define pb push_back
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(j,n) for (j=1;j<=n;j++)
#define PI 3.14159265358979323846
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL) 
using namespace std;
void input(vector<ll>& v,ll n)
{
	ll i,io;
	rep(i,n)
	{
		cin>>io;
		v.pb(io);
	}
}
/*bool binary_pred(int a,int b)
{
	return a==b;
}*/
int main()
{
	fastio;
	ll n,i,k,sum=0;
	cin>>n>>k;
	vector<ll> v;
	input(v,n);
	sort(v.begin(),v.end());
	rep(i,k)
		sum+=v.at(i);
	cout<<sum<<endl;
}


Measured memory_bytes: 3652
import math

N, M = list(map(int, input().split()))
cons = (10**9+7)
if N == M:
    s = math.factorial(N)
    print((s**2*2)%cons)

elif abs(N-M) == 1:
    N = min(N, M)
    s = math.factorial(N)
    print((s*(s*(N+1))%cons))
else:
    print(0)


Measured memory_bytes: 5192
#include <bits/stdc++.h>
using namespace std;
int main(){
	char a[10];
	cin>>a;
	int len=strlen(a);
	int sum=0,num=0,k=1;
	for(int i=0;i<len;i++){
		sum=sum+a[i]-48;
		//cout<<"sum:"<<sum<<endl;
	}
	for(int i=len-1;i>=0;i--){
		num=num+(a[i]-48)*k;
		k=k*10;
		//cout<<"num:"<<num<<endl;
	}
	
	
	if(num%sum==0){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	return 0;
} 

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

#define ll long long
#define ld long double
#define ii pair<int ,int >
#define S second
#define F first
#define PI 3.1415926535897932384626
#define SPEED std::ios_base::sync_with_stdio(false);

ll n;
vector<ll>ans;
set<ll>st;
void rec(ll i , int tmp){
    if(st.find(i)==st.end()){
        ans.push_back(i);
        st.insert(i);
    }
    if(tmp==0)return ;
    ll t = i*10*1LL;
    if(i%10 < 9)rec(t+(i%10)+1,tmp-1);
    rec(t+(i%10),tmp-1);
    if(i%10 > 0)rec(t+(i%10)-1,tmp-1);
}

int main(){
    cin>>n;
    for(ll i=1;i<10;i++){
        rec(i,9);
    }
    sort(ans.begin(),ans.end());
    cout<<ans[n-1];
}


Measured memory_bytes: 11120
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n = II()
    a = [0] + [II() for _ in range(n-1)]
    d = collections.defaultdict(list)
    for i in range(1,n):
        d[a[i]].append(i+1)
    m = {}
    def f(i):
        if not d[i]:
            return 0
        t = collections.defaultdict(int)
        for c in d[i]:
            t[f(c)] += 1
        t = list(t.items())
        t.sort()
        r = 0
        for c, tc in t:
            if r < c:
                r = c
            r += tc
        return r
    return f(1)


print(main())


Measured memory_bytes: 162708
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

#a = list(map(int, input().split()))

n,m=list(map(int, input().split()))
print(n*m//fractions.gcd(n,m))

Measured memory_bytes: 63980
#include<stdio.h>
#include<string>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<tuple>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int x,y;
    scanf("%d%d",&x,&y);
    ll m=0;
    if(x==3)m+=100000;
    else if(x==2)m+=200000;
    else if(x==1)m+=300000;
    if(y==3)m+=100000;
    else if(y==2)m+=200000;
    else if(y==1)m+=300000;
    if(x==1&&y==1)m+=400000;
    printf("%lld\n",m);
    return 0;
}

Measured memory_bytes: 256
n = int(input())

B = [int(x) for x in input().split()]

A = [0] * n
A[0] = B[0]
A[n - 1] = B[n - 2]

for i in range(1, len(A) - 1):
    A[i] = min([B[i - 1], B[i]])

print(sum(A))


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

int main(){
	int a, b;
	long ans;
	cin >> a >> b;
	if(abs(a-b)>1){
		ans = 0;
	} else if(a != b) {
		ans = 1;
		for(int i=2; i<=a; i++){
			ans = ans * i % 1000000007;
		}
		for(int i=2; i<=b; i++){
			ans = ans * i % 1000000007;
		}
	} else {
		ans = 2;
		for(int i=2; i<=a; i++){
			ans = ans * i % 1000000007;
		}
		for(int i=2; i<=b; i++){
			ans = ans * i % 1000000007;
		}
	}
	cout << ans;
	return 0;
}



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

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

	int n, m; cin >> n >> m;
	vector<ll> a(n); REP(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	vector<P> bc(m);
	REP(i, m) cin >> bc[i].second >> bc[i].first;
	sort(bc.rbegin(), bc.rend());

	int cnt = 0;
	vector<ll> d;
	while (n > (int)d.size()) {
		REP(i, bc[cnt].second)
			d.push_back(bc[cnt].first);
		cnt++;
		if (cnt == m) break ;
	}
	sort(d.rbegin(), d.rend());

	ll res = 0;
	if (n <= (int)d.size()) {
		REP(i, n) res += max(a[i], d[i]);
	} else {
		REP(i, n - (int)d.size())
			d.push_back(0);
		REP(i, n) res += max(a[i], d[i]);
	}
	cout << res << '\n';
    return 0;
}


Measured memory_bytes: 7560
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String op = sc.next();
    String b = sc.next();
    long a1 = Long.parseLong(a);
    long b1 = Long.parseLong(b);
    long ans = a1 + b1;
    if(op.equals("-")) ans = a1 - b1;
    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

int ans = 100000000;

int main(){
    ll N,M; cin >> N >> M;

    ll ans;
    if (N==2 || M == 2){
        ans = 0;
    }
    else if (N == 1 || M == 1){
        ans = max(1LL, N*M-2);
    }
    else{
        ans = ((N-2)*(M-2));
    }
    cout << ans << endl;
}


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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1;} return 0;}

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    string s;
    cin >> n >> s;
    map<char, int> m;
    rep(i, n) {
        ++m[s[i]];
    }

    llong ans = 1;
    stl_rep(itr, m) {
        ans *= (itr->second + 1);
        ans %= mod;
    }

    cout << (ans - 1 + mod) % mod << endl;
    
    return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,m=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
arr=[[0]*m for i in range(n)]
for i in range(n):
    for j in range(m):
        if S[i] == T[j]:
            arr[i][j] = 1
acum = [[0]*m for i in range(n)]
acum[0][0] = arr[0][0]
for i in range(1,n):
    acum[i][0] = acum[i-1][0] + arr[i][0]
for j in range(1,m):
    acum[0][j] = acum[0][j-1] + arr[0][j]
for i in range(1,n):
    for j in range(1,m):
        arr[i][j] += (acum[i-1][j-1])*(arr[i][j])
        acum[i][j] = acum[i-1][j] + acum[i][j-1] - acum[i-1][j-1] + arr[i][j]
        arr[i][j] %= mod; acum[i][j] %= mod
print(1+sum(map(sum,arr))%mod)
# print(*arr,sep="\n");print()
# print(*acum,sep="\n")




Measured memory_bytes: 106076
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var A = one[0];
  var B = one[1];
  for(var i = 1; i <= 100000; i++){
    var L = Math.floor(i * 1.08);
    var R = Math.floor(i * 1.1);
    if(L - i == A && R - i == B){
      myout(i);
      return;
    }
  }
  myout(-1);
}



Measured memory_bytes: 33416