akhauriyash/Code-Regression huggingface dataset:
use std::cmp::*;
use std::collections::HashSet;
use std::io::*;
use std::num::*;
use std::str::*;

mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}

fn main() {
    let n = i::u();
    let a = i::uv(n);
    let mut set = HashSet::new();
    for k in &a {
        if set.contains(k) {
            set.remove(k);
        } else {
            set.insert(k);
        }
    }
    println!("{}", set.len());
}


Measured memory_bytes: 8444
while True:
    try:
        r = sorted(list(map(int, input().split())))
        
        
        def euclidfunc(a, b):
            while b != 0:
                a, b = b, a % b
            return a
        
        
        def lcmfunc(a, b):
            return a * b // euclidfunc(a, b)
        
        
        print("{a} {b}".format(a=euclidfunc(r[1], r[0]), b=lcmfunc(r[1], r[0])))
    except EOFError:
        break



Measured memory_bytes: 5596
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
using namespace std;

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x != i + 1) {
      cnt++;
    }
  }

  if (cnt == 0 || cnt == 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
diff = A - B
H = [int(input()) for i in range(N)]

def check(x):
  time = 0
  _H = [h-B*x for h in H]
  for _h in _H:
    if _h > 0:
      time += -(-_h//diff)
  return time <= x

left = 0 # False
right = 10**10 # True
while left + 1 < right:
  mid = (left + right) // 2
  if check(mid):
    right = mid
  else:
    left = mid

print(right)

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

int main() {
  int X;
  cin >> X;
  vector<bool> expo(X+1);

  expo.at(1) = true;

  for (int b=2; b<=X; b++) {
    int v = b*b;
    while(v<=X) {
      expo.at(v) = true;
      v *= b;
    }
  }
  for (int i=X; i>=1; i--) {
    if (expo.at(i)) {
      cout << i << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
  
    int n,a,b;
    cin>>n>>a>>b;
    
    int p1=a*n;
    int p2=b;
    
    if(p1>=p2){
        cout<<p2<<endl;
    }else{
        cout<<p1<<endl;
    }
    
    return 0;
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);
  int x,a,b;
  cin >> x >> a >> b;
  if(abs(a-x) > abs(b-x)) cout << 'B' << endl;
  else cout << 'A' << endl;
  return 0;
}

Measured memory_bytes: 256
import heapq
import sys
input = sys.stdin.buffer.readline


def dijkstra(adj, start):
    # adj: [[to, cost] * vertices], 0th index must be empty
    dist = [float('inf')] * len(adj)
    dist[start] = 0
    q = []
    heapq.heappush(q, (0, start))
    while q:
        min_dist, v_from = heapq.heappop(q)
        # if v_from == 2:
        #    return dist
        if min_dist > dist[v_from]:
            continue
        v_tos = adj[v_from]
        for v_to, cost in v_tos:
            if min_dist + cost < dist[v_to]:
                dist[v_to] = min_dist + cost
                heapq.heappush(q, (dist[v_to], v_to))
    return dist


def main():
    xs, ys, xt, yt = map(int, input().split())
    N = int(input())
    br = [(xs, ys, 0), (xt, yt, 0)]
    for _ in range(N):
        br.append(tuple(map(int, input().split())))

    adj = [[] for _ in range(N+3)]
    for i in range(N+2):
        for j in range(i+1, N+2):
            dij = max(((br[i][0] - br[j][0])**2 + (br[i][1] - br[j][1])**2) ** (1/2) - (br[i][2] + br[j][2]), 0)
            adj[i+1].append([j+1, dij])
            adj[j+1].append([i+1, dij])

    print(dijkstra(adj, 1)[2])


if __name__ == '__main__':
    main()


Measured memory_bytes: 182636
package main

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

func solve() {
	n := getInt()
	vs := getIntSlice(n)

	mOdd := make(map[int]int)
	mEven := make(map[int]int)
	for i, v := range vs {
		switch i % 2 {
		case 1:
			mOdd[v]++
		default:
			mEven[v]++
		}
	}

	calc := func(m map[int]int) (int, int, int) {
		var f, fn, sn int
		for k, v := range m {
			switch {
			case v > fn:
				f = k
				sn = fn
				fn = v
			case v > sn:
				sn = v
			}
		}
		return f, fn, sn
	}
	oFirst, oFirstNum, oSecondNum := calc(mOdd)
	eFirst, eFirstNum, eSecondNum := calc(mEven)

	ans := 0
	if oFirst == eFirst {
		ans = n - max((oFirstNum+eSecondNum), (eFirstNum+oSecondNum))
	} else {
		ans = n - (oFirstNum + eFirstNum)
	}
	fmt.Fprintln(wr, ans)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


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

#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define endl '\n'
#define int long long

typedef pair<int,int> pii;
const int N = 2e3+5;
const int K = 2e3+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n, b;
int C[N][K];
void precalc(){
	for(int i=0; i<N; i++) C[i][0] = 1;
	for(int i=1; i<N; i++){
		for(int j=1; j<K; j++){
			C[i][j] = (C[i-1][j] + C[i-1][j-1]) % MOD;
		}
	}
}
int32_t main()
{
	IOS
	precalc();
	//freopen("input.txt", "r", stdin);
	cin >> n >> b;
	int r = n-b; //red
	for(int i=1; i<=b; i++){
		int ans = C[r+1][i] * C[b-1][i-1] % MOD;
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 31744
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define setbit(s, i) (s|=(1LL<<(i)))
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "D"
int n;
int a[200001];
int b[200001];
int c[200001], d[200001];
int f(int u){
    int l=1, r=n, res=0, m;
    while(l<=r){
        m=(l+r)/2;
        if(d[m]<=u){
            res=m;
            l=m+1;
        }
        else r=m-1;
    }
    return res;
}
int main(){
    #ifdef Kanikou
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Kanikou
    read(n);
    FOR(i, 1, n) read(a[i]);
    FOR(i, 1, n) read(b[i]);
    int ans=0;
    FOR(i, 0, 28){
        FOR(j, 1, n) c[j]=a[j]&(mask(i+1)-1);
        FOR(j, 1, n) d[j]=b[j]&(mask(i+1)-1);
        sort(d+1, d+n+1);

        int x=0;
        FOR(j, 1, n){
            x+=n-f(mask(i+1)+mask(i)-c[j]-1)+f(mask(i+1)-c[j]-1)-f(mask(i)-c[j]-1);
            x%=2;
        }
        x%=2;
        if(x) ans|=mask(i);
    }
    writeln(ans);
}

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

#define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))

int n,m;
int x[55],y[55];
int fa[55];
int du[55];

int find(int x) { return x==fa[x]?x:fa[x]=find(fa[x]); }

void join(int x,int y)
{
    int fx=find(x),fy=find(y);
    if(fx<fy) fa[fx]=fy;
    else fa[fy]=fx;
}

int main()
{
    cin>>n>>m;
    int ans=0;
    F(i,1,m) scanf("%d %d",x+i,y+i);
    F(i,1,m)
    {
        for(int j=0;j<=n;++j) fa[j]=j;
        mem(du,0);
        F(j,1,m)if(i!=j)
        {
            join(x[j],y[j]);
            du[x[j]]++,du[y[j]]++;
        }
        int cnt=0;
        for(int j=1;j<=n;++j)if(fa[j]==j) cnt++;
        if(cnt>1) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int N,C;
	cin >> N >> C;

	vector<T> stc(N);
	for(int i = 0;i < N;i++){
		int s,t,c;
		cin >> s >> t >> c;
		c--;
		stc[i] = T(s,t,c);
	}
	sort(stc.begin(),stc.end());
	vector<vector<P>> st(C);
	for(int i = 0;i < N;i++){
		int s,t,c;
		tie(s,t,c) = stc[i];
		st[c].push_back(P(s,t));
	}
	vector<P> st1;
	for(int i = 0;i < C;i++){
		for(int j = 0;j < st[i].size();j++){
			int k = j;
			int nowt = st[i][j].second;
			int nows = st[i][j].first;
			while(k+1 < st[i].size() && st[i][k+1].first == nowt){
				nowt = st[i][k+1].second;
				k++;
			}
			st1.push_back(P(nows,nowt));
			j = k;
		}
	}
	sort(st1.begin(),st1.end());
	multiset<int> mst;
	mst.insert(st1[0].second);
	for(int i = 1;i < st1.size();i++){
		int nows = st1[i].first;
		int nowt = st1[i].second;
		auto p = mst.lower_bound(nows);

		if(p != mst.begin()){
			p--;
			mst.erase(p);
		}
		mst.insert(nowt);
	}
	cout << mst.size() << endl;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const ll oo = 1e18;
const ll mod = 1e9 + 7,maxn = 100000000;
const double PI = acos(-1);

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if(b < a) swap(a, b);
        for (int i=0; i<b; i++){
            cout << a;
        }
        cout << endl;

    return 0;
}

Measured memory_bytes: 256
# ball and box 6
MOD = pow(10,9)+7
from math import factorial
def P(n,r):
    return factorial(n)//factorial(n-r)
def C(n,r):
    return P(n,r)//factorial(r)
def H(n,r):
    return C(n+r-1,r)
n, k = map(int, input().split())
print(H(k,n-k)%MOD if n >= k else 0)


Measured memory_bytes: 5668
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int q = sc.nextInt();
    int[] points = new int[n];

    for (int i = 0; i < q; i++) {
      int a = sc.nextInt();
      a--;
      points[a] += 1;
    }

    for (int i = 0; i < n; i++) {
      if (k - q + points[i] > 0) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }
  }
}


Measured memory_bytes: 69104
from collections import deque
N,M=map(int,input().split())
G=[[] for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
X=[0 for i in range(N)]
q=deque([])
q.append(0)
q.append(G[0][0])
X[0]=1
X[G[0][0]]=1
while(True):
    r=q[0]
    flag=0
    for p in G[r]:
        if X[p]==0:
            q.appendleft(p)
            X[p]=1
            flag=1
            break
    if flag==1:
        continue
    r=q[-1]
    flag=0
    for p in G[r]:
        if X[p]==0:
            q.append(p)
            X[p]=1
            flag=1
            break
    if flag==0:
        break
L=[str(i+1) for i in q]
print(len(L))
print(" ".join(L))

Measured memory_bytes: 31288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=1e6+5;
vector<ll> V;
ll n,s;
bool check(ll b) {
	return n/b+n%b==s&&n/b<b;
}
int main() {
    cin>>n>>s;
    if(n<s) return 0*puts("-1");
    if(n==s) return cout<<n+1<<endl,0;
    for(ll i=2;i*i<=n;i++) {
    	ll tem=n,sum=0;
    	while(tem) 	
    		sum+=tem%i,tem/=i;
    	if(sum==s) return cout<<i<<endl,0;
    }
    ll tem=n-s,ans=1e18;
    for(ll i=1;i*i<=tem;i++) {
    	if(tem%i==0) {
    		ll x=tem/i,y=i;
    		if(check(x+1)) ans=min(ans,x+1);
    		if(check(y+1)) ans=min(ans,y+1);
    	}
    }
    if(ans!=1e18) cout<<ans<<endl;else cout<<"-1\n";
    return 0;
}

Measured memory_bytes: 3564
N, Y = map(int, input().split())

for x in range(N + 1):
    for y in range(N + 1 - x):
        z = N - x - y
        if 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            exit()

print("-1 -1 -1")


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int answer = min(b,d)-max(a,c);
    cout << max(answer,0) << endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
Pn = []
for i in range(M):
    Pn.append(list(input().split()))

check = [0 for i in range(N + 1)]
pAC = 0
pWA = 0
for p in Pn:
    x = int(p[0])
    if check[x] != -1:
        if p[1] == 'WA':
            check[x] += 1
        elif p[1] == 'AC':
            pWA += check[x]
            pAC += 1
            check[x] = -1

print(pAC, pWA)


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

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> dp(n,0);
  vector<vector<int>> g(n,vector<int>(0)); 
  vector<int> v(n,0);
  
  rep(i,m){
    int x,y;
    cin>>x>>y;
    x--; y--;
    g[x].push_back(y);
    v[y]++;
  }
  
  stack<int> st;
  
  rep(i,n){
    if(!v[i]) st.push(i);
  }
  
  vector<int> ans(0);
  
  while(st.size()){
    int i = st.top(); st.pop();
    ans.push_back(i);
    for(int j : g[i]){
      v[j]--;
      if(!v[j]) st.push(j);
    }
  }
  
  int reans = 0;
  for(int i=n-1; i >= 0; i--){
    for(int j : g[ans[i]]){
      dp[ans[i]] = max(dp[ans[i]],dp[j]+1);
      reans = max(reans,dp[ans[i]]);
    }
  }   

  cout << reans << endl;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b,c;
    cin >> a>>b >> c;
    if(a-b == b - c)    cout << "YES\n";
    else{
        cout << "NO\n";
    }
    

    return 0;
}

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

using ll = long long;
// #define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

char getWin(char c) {
  if(c == 'r') return 'p';
  if(c == 's') return 'r';
  if(c == 'p') return 's';
}

/***** MAIN *****/
signed main() {
  int n, k, r, s, p;
  string str;
  // r ぐー, s ちょき, p パー
  cin >> n >> k;
  cin >> r >> s >> p;
  unordered_map<char, int> um{{'r', r}, {'s', s}, {'p', p}};
  cin >> str;
  ll ans = 0;
  vector<char> v(n);
  REP(i,n) {
    v[i] = getWin(str[i]);
  }
  REP(i,k) {
    ans += um.at(v[i]);
  }

  REPS(i,k,n) {
    if(v[i] != v[i-k]) {
      ans += um.at(v[i]);
      continue;
    }
    v[i] = 'a';
  }
  // REP(i,k) {
  //   ans += um.at(getWin(str[i]));
  // }
  // REPS(i,k,n) {
  //   if(str[i] != str[i-k]) {
  //     ans += um.at(getWin(str[i]));
  //     continue;
  //   }
    
  // }

  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 512
import java.util.Scanner;
class Main{
    double r,x,y;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        r = sc.nextDouble();
        x = r * r * 3.141592653589;
        y = 2 * r * 3.141592653589;
        System.out.printf("%8.6f %8.6f",x,y);
    }
    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 18896
N  = int(input())
rs = [ [ *input().split(), n ] for n in range(N) ]

rs = sorted(
    [ (f'{s}{100 - int(p):03}', i + 1) for s, p, i in rs ],
    key=lambda t: t[0],
)

for r in rs:
    print(r[1])

Measured memory_bytes: 9188
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll n;
  cin >> n;
  vector<ll> a1(n),a2(n);
  vector<ll> sum1(n),sum2(n);

  rep(i,n) cin >> a1[i];
  rep(i,n) cin >> a2[i];
  
  rep(i,n) sum1[i] = (i > 0 ? sum1[i - 1] : 0) + a1[i];
  rep(i,n) sum2[i] = (i > 0 ? sum2[i - 1] : 0) + a2[i];

  ll ans = 0;
  rep(i,n)
  {
    ll buf = sum1[i] + sum2[n-1] - ( i > 0 ? sum2[i - 1] : 0);
    ans = max(ans , buf);
  }

  cout << ans << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
fn main() {
    let (k, _n) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s = s.trim_end().to_owned();

        let mut ws = s.split_whitespace();
        let n: i32 = ws.next().unwrap().parse().unwrap();
        let m: i32 = ws.next().unwrap().parse().unwrap();
        (n, m)
    };

    let a_s = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_end().to_owned()
    };
    let whitespace = a_s.split_whitespace();
    let b: Vec<i32> = whitespace.into_iter().map(|x| x.parse::<i32>().unwrap()).collect();

    let mut max = *b.get(0).unwrap() + (k - *b.get(b.len() - 1).unwrap());
    for i in 0..(b.len() - 1) {
        let a1 = b.get(i).unwrap();
        let a2 = b.get(i + 1).unwrap();
        max = std::cmp::max(max, a2 - a1);
    }

    println!("{}", k - max);
}


Measured memory_bytes: 4816
#include<stdio.h>

int main(void)
{
	int a,b,c;
	int x = 0;
	scanf("%d %d %d",&a, &b, &c);
        for(a;a <= b;a++){
		if(c % a == 0){
			x = x + 1;
		}
	}
	printf("%d\n",x);
	return 0;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

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

void solve() {
  string S, T;
  cin >> S >> T;
  cout << T + S << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
constexpr int MOD = 1e9 + 7;
signed main(){
    int N; cin >> N;
    vector<int>v(N);
    for( auto& e : v) cin >> e;
    vector<int>dp(N,0LL);
    int maxi = *max_element(v.begin(), v.end());
    vector<vector<int>>cnt(maxi+1);
    for(int i = 0; i < v.size(); ++i){
        int num = v[i];
        if(i)dp[i] += dp[i-1];
        if(cnt[num].empty() ){
            
            cnt[num].push_back(i);
            
        } else if(cnt[num].back() + 1 == i){
            cnt[num].back() = i;
        
        } else {
            int lst = cnt[num].back();
            dp[i] += dp[lst] + 1;
            dp[i] %= MOD;
            cnt[num].push_back(i);
        }
    }
    cout << dp.back() + 1 << endl;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 1;
signed main()
{
#ifdef home
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
#else
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    int i, o, t, j, l, s, z;
    cin >> i >> o >> t >> j >> l >> s >> z;
    int ans = o * 2;
    int _1 = j, _2 = l, _3 = i, v = min(j, min(l, i));
    if (_1 && _2 && _3)
    {
        ans += 6;
        _1--, _2--, _3--;
    }
    ans += _1 / 2 * 4 + _2 / 2 * 4 + _3 / 2 * 4;
    ans = max(ans, j / 2 * 4 + i / 2 * 4 + l / 2 * 4 + o * 2);
    cout << ans / 2;
}

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

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    vector<int> ans(n);
    for (int i = 0; i < n - 1; i++) {
        int a;
        cin >> a;
        a--;
        ans[a]++;
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4784
n, m = map(int, input().split())
hs = list(map(int, input().split()))

tembo = [1]*n

ab = []
for i in range(m):
  a, b = map(int, input().split())
  if (hs[b-1] < hs[a-1]):
    tembo[b-1] = 0
  elif (hs[a-1] < hs[b-1]):
    tembo[a-1] = 0
  else:
    tembo[b-1] = 0
    tembo[a-1] = 0
    

print(sum(tembo))

Measured memory_bytes: 85028
#include <bits/stdc++.h>
using namespace std;
long long i,j,w,n,m,p,k,l,Max,ans,t,ans2,B,r,b,d,ind,x,y,dp[201][100001];
pair <long long,long long> a[2000001];
int main () {
    cin>>n>>w;
    for (i=1;i<=n;i++) {
        cin>>a[i].first>>a[i].second;
    }
    for (i=1;i<=n;i++) {
        for (j=1;j<=w;j++) {
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
            if (j-a[i].first>=0)
            {
                dp[i][j]=max(dp[i][j],dp[i-1][j-a[i].first]+a[i].second);
            }
        }
    }
    for (i=1;i<=w;i++) {
        ans=max(dp[n][i],ans);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 80128
#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 int MOD = 1000000007;
const ll INF = 1LL<<60;

int main(){

    ll X; cin >> X;
    ll a, b;

    for (int i = -1000; i < 1001; i++){
        for(int j = -1000; j < 1001; j++){
            if (X == pow(i,5)-pow(j,5)){
                a = i;
                b = j;
                break;
            }
        }
    }

    cout << a << " " << b << endl;
}

Measured memory_bytes: 4100
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846;

signed main() {
	int N;
	cin >> N;
	map<int, int>D, T;
	int input;
	rep(i, N) {
		cin >> input;
		D[input]++;
	}
	int M;
	cin >> M;
	rep(i, M) {
		cin >> input;
		T[input]++;
	}
	for (auto i : T) {
		if (i.second <= D[i.first])continue;
		else {
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
}

Measured memory_bytes: 25216
#include <iostream>
#include <algorithm>
#include <numeric>
#include <utility>
#include <map>
#include <set>
#include <vector>
#include <climits>
#include <cmath>
#include <stdlib.h>

#define max_n 100001

using namespace std;

int dfs(vector<set<int>> &v, int i, vector<bool> &vis)
{
    vis[i] = true;
    int ans = 1; 
    for (auto it : v[i])
    {
        if (!vis[it]) 
            ans += dfs(v, it, vis);
    }
    return ans;
}

int main()
{
    int n, m; cin >> n >> m;
    vector<set<int>> v(n + 1);

    for (int i = 0; i < m; i++)
    {
        int a, b; cin >> a >> b;
        v[a].insert(b);
        v[b].insert(a);
    }
    int ans = 0; 
    vector<bool> vis(v.size(), false);
    for (int i = 1; i <= n; i++)
    {
        if (!vis[i])
        {
            ans = max(ans, dfs(v, i, vis));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 43784
#include<iostream>

int main(){
    int A,B,C,D;
    std::cin>> A >> B;
    for(int i=0;i<3000;i++){
        C=i*8/100;
        D = i*10/100;
        if(C==A && D==B){
            std::cout<<i<<std::endl;
            return 0;
        }
    }
    std::cout<<-1<<std::endl;
}


Measured memory_bytes: 256
n = int(input())
s = input()
ans = 0
r, g, b = [0 for _ in range(n+1)], [0 for _ in range(n+1)], [0 for _ in range(n+1)]
for i in range(n):
	r[i+1], g[i+1], b[i+1] = r[i], g[i], b[i]
	if s[i] == "R":
		r[i+1] += 1
	elif s[i] == "G":
		g[i+1] += 1
	else:
		b[i+1] += 1

ans = 0
for i in range(1, n-1):
	if s[i] == "R":
		ans += g[i] * (b[n] - b[i+1]) + b[i] * (g[n] - g[i+1])
		for j in range(1, min(i, n-i-1)+1):
			if {s[i-j], s[i+j]} == {"G", "B"}:
				ans -= 1
	elif s[i] == "G":
		ans += r[i] * (b[n] - b[i+1]) + b[i] * (r[n] - r[i+1])
		for j in range(1, min(i, n-i-1)+1):
			if {s[i-j], s[i+j]} == {"R", "B"}:
				ans -= 1
	elif s[i] == "B":
		ans += g[i] * (r[n] - r[i+1]) + r[i] * (g[n] - g[i+1])
		for j in range(1, min(i, n-i-1)+1):
			if {s[i-j], s[i+j]} == {"G", "R"}:
				ans -= 1
print(ans)

Measured memory_bytes: 68988
#include<cstdio>
#include<cstring>
const int MAXN=100005;

char s[MAXN];
int n;

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	s[0]='0';
	for(int i=0;i<=n;i++)
		if(s[i]!=s[n-i])
		{
			puts("-1");
			return 0;
		}
	if(s[1]=='0')
	{
		puts("-1");
		return 0;
	}
	int root=2;
	puts("1 2");
	for(int i=2;i<n;i++)
		if(s[i]=='1')
		{
			printf("%d %d\n",root,i+1);
			root=i+1;
		}
		else
			printf("%d %d\n",i+1,root);
	
	return 0;
}


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

using namespace std;
using ll = long long;

int dfs(int n, int m, int q, vector<int> a, vector<int> b, vector<int> c, vector<int> d, vector<int> A) {
    int sum = 0;
    if(A.size() == n) {
        for(int i = 0; i < q; ++i) {
            if(A[b[i] - 1] - A[a[i] - 1] == c[i]) sum += d[i];
        }
        return sum;
    }

    A.emplace_back(A.back());
    while(A.back() <= m) {
        sum = max(sum, dfs(n, m, q, a, b, c, d, A));
        A.back()++;
    }

    return sum;
}

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

    int n, m, q;
    cin >> n >> m >> q;
    vector<int> a(q), b(q), c(q), d(q);
    for(int i = 0; i < q; ++i) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    printf("%d\n", dfs(n, m, q, a, b, c, d, vector<int>(1, 1)));

    return 0;
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;

struct edge{
	int to;
	int cost;
};
vector<vector<edge>>	G(100010);
vint col(100010, 0);
vint used(100010, 0);
void dfs(int v, int d){
	if(d&1)	col[v] = 1;
	else 	col[v] = -1;
	used[v] = 1;
	for(auto e : G[v])	if(!used[e.to])	dfs(e.to, d+e.cost);
}
int main(){
	int N;
	cin >> N;
	for(int i = 0;i < N-1;i++){
		int ui, vi, wi;
		cin >> ui >> vi >> wi;
		edge e = {vi-1, wi};
		G[ui-1].push_back(e);
		e = {ui-1, wi};
		G[vi-1].push_back(e);
	}
	dfs(0, 0);
	for(int i = 0;i < N;i++){
		if(col[i] == 1)	cout << 0 << endl;
		else 	cout << 1 << endl;
	}
}

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

using ld = long double;
const ld eps = 1e-8, pi = acos(-1.0);

bool eq(ld a, ld b) {
	return abs(a - b) < eps;
}

using Point = complex<ld>;
class Line {
public:
	Point a, b;
};
class Circle {
public:
	Point p;
	ld r;
};

ld dot(Point a, Point b) {
	return real(conj(a) * b);
}

ld cross(Point a, Point b) {
	return imag(conj(a) * b);
}

int ccw(Point a, Point b, Point c) {
	b -= a, c -= a;
	if (cross(b, c) > eps) return 1;
	if (cross(b, c) < -eps) return -1;
	if (dot(b, c) < 0) return 2;
	if (norm(b) < norm(c)) return -2;
	return 0;
}

bool isis_ll(Line l, Line m) {
	return abs(cross(l.b - l.a, m.b - m.a)) > eps;
}

bool isis_ls(Line l, Line s) {
	return (cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps);
}

bool isis_lp(Line l, Point p) {
	return abs(cross(l.b - p, l.a - p)) < eps;
}

bool isis_sp(Line s, Point p) {
	return abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps;
}

Point proj(Line l, Point p) {
	ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
	return l.a + t * (l.a - l.b);
}

Point is_ll(Line s, Line t) {
	Point sv = s.b - s.a, tv = t.b - t.a;
	assert(cross(sv, tv) != 0);
	return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}

bool isis_ss(Line s, Line t) {
	if (isis_ll(s, t)) return isis_ls(s, t) && isis_ls(t, s);
	return isis_sp(s, t.a) || isis_sp(s, t.b) || isis_sp(t, s.a);
}

ld dist_lp(Line l, Point p) {
	return abs(p - proj(l, p));
}

ld dist_ll(Line l, Line m) {
	return isis_ll(l, m) ? 0 : dist_lp(l, m.a);
}

ld dist_ls(Line l, Line s) {
	return isis_ls(l, s) ? 0 : min(dist_lp(l, s.a), dist_lp(l, s.b));
}

ld dist_sp(Line s, Point p) {
	Point r = proj(s, p);
	return isis_sp(s, r) ? abs(r - p) : min(abs(s.a - p), abs(s.b - p));
}

ld dist_ss(Line s, Line t) {
	if (isis_ss(s, t)) return 0;
	return min({ dist_sp(s, t.a), dist_sp(s, t.b), dist_sp(t, s.a), dist_sp(t, s.b) });
}

int main()
{
	int q;
	ld x1, x2, x3, x4, y1, y2, y3, y4;
	cout << fixed << setprecision(10);
	cin >> q;
	while (q--) {
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		Line l1 = { (Point) { x1, y1 }, (Point) { x2, y2 } };
		Line l2 = { (Point) { x3, y3 }, (Point) { x4, y4 } };
		cout << dist_ss(l1, l2) << endl;
	}
	return 0;
}

Measured memory_bytes: 3332
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CABSubstrings solver = new CABSubstrings();
        solver.solve(1, in, out);
        out.close();
    }

    static class CABSubstrings {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int N = in.ni();
            int ba = 0, xa = 0, bx = 0;
            int ans = 0;
            for (int i = 0; i < N; i++) {
                String s = in.ns();
                for (int j = 1; j < s.length(); j++) {
                    if (s.charAt(j - 1) == 'A' && s.charAt(j) == 'B')
                        ans++;
                }
                int n = s.length();
                char first = s.charAt(0);
                char last = s.charAt(n - 1);
                if (first == 'B' && last == 'A') {
                    ba++;
                } else if (first == 'B') {
                    bx++;
                } else if (last == 'A') {
                    xa++;
                }
            }

            if (ba > 0) {
                ans += ba - 1;
                ba = 1;
            }
            if (ba > 0 && xa > 0 && bx > 0) {
                ba = 0;
                xa--;
                bx--;
                ans += 2;
            }
            int cnt = Math.min(xa, bx);
            ans += cnt;
            xa -= cnt;
            bx -= cnt;
            if (ba > 0 && (xa > 0 || bx > 0)) {
                ans++;
            }
            out.println(ans);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

    }
}



Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
int main(){
        ios_base::sync_with_stdio(false); cin.tie(0);
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w", stdout);
        int n,xo=0; cin>>n;
        int a[n] ; for(int i=0;i<n;i++) {cin>>a[i]; xo^=a[i]; }
        for(int i=0;i<n;i++) cout<<(xo^a[i])<<" ";
        cout<<endl;
}



Measured memory_bytes: 4376
while True:

    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for k in range(W):
            if (i+k)%2 == 0:
                print("#",end = "")
            else:
                print(".",end = "")
        print()

    print() 


Measured memory_bytes: 7000
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int x[123],y[123];
    for(int i=0;i<n;i++){
      cin>>x[i]>>y[i];
      x[i]+=2000;
      y[i]+=2000;
    }
    x[n]=x[0];
    y[n]=y[0];
    int ans=0;
    for(int i=0;i<=4000;i++){
      bool in[4234]={};
      vector<double> cx[2];
      for(int j=0;j<n;j++){
	if(y[j]!=y[j+1]&&min(y[j],y[j+1])<=i&&i+1<=max(y[j],y[j+1])){
	  double x1=(x[j+1]-x[j])*(i-y[j])*1./(y[j+1]-y[j])+x[j];
	  double x2=(x[j+1]-x[j])*(i+1-y[j])*1./(y[j+1]-y[j])+x[j];
	  cx[0].push_back(x1);
	  cx[1].push_back(x2);
	  if(x1>x2){
	    swap(x1,x2);
	  }
	  for(int k=x1;k<x2;k++){
	    in[k]=true;
	  }
	}
      }
      for(auto e:cx){
	sort(begin(e),end(e));
	for(int i=0;i<e.size();i+=2){
	  for(int j=e[i];j<e[i+1];j++){
	    in[j]=true;
	  }
	}
      }
      ans+=count(begin(in),end(in),true);
    }
    cout<<ans<<endl;
  }
}

	    

Measured memory_bytes: 1224
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var B = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        Array.Sort(B, A);
        var order = Enumerable.Range(0, N).ToArray();
        Array.Sort(A, order);

        for (int i = 0; i < N; i++)
        {
            if (A[i] > B[i])
            {
                Console.WriteLine("No");
                return;
            }
        }

        var count = 0;
        var p = 0;
        do
        {
            p = order[p];
            count++;
        } while (p != 0);
        if (count != N)
        {
            Console.WriteLine("Yes");
            return;
        }

        for (int i = 0; i < N - 1; i++)
        {
            if (A[i + 1] <= B[i])
            {
                Console.WriteLine("Yes");
                return;
            }
        }

        Console.WriteLine("No");
    }
}

Measured memory_bytes: 35804
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod
#define AddMult(x, y, z) x = (x + (y) * (z)) % mod



signed main(){

    int N; cin >> N;
    vec C(N); readv_m1(C);

    int dp[200000] = {};
    int ans = 1;
    REP(i, N){
        if(i != N - 1 && C[i] == C[i + 1]) continue;
        int tmp = ans;
        Add(tmp, dp[C[i]]);
        Add(dp[C[i]], ans);
        ans = tmp;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N, M);
  vl v(N, 1);
  set<int> st;
  st.insert(0);
  rep(i, 0, M) {
    VAR(int, xi, yi);
    xi--; yi--;
    v[xi]--;
    v[yi]++;
    if (st.count(xi)) {
      if (!st.count(yi)) {
        st.insert(yi);
      }
      if (v[xi] == 0) {
        st.erase(xi);
      }
    }
  }
  print(st.size());
}


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

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		double x1, y1, x2, y2, x3, y3, px, py, r;
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		px = ((y1 - y3) * (y1 * y1 - y2 * y2 + x1 * x1 - x2 * x2) - 
			  (y1 - y2) * (y1 * y1 - y3 * y3 + x1 * x1 - x3 * x3)) / 
			 (2 * (y1 - y3) * (x1 - x2) - 2 * (y1 - y2) * (x1 - x3));
		py = ((x1 - x3) * (x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2) -
			(x1 - x2) * (x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3)) /
			(2 * (x1 - x3) * (y1 - y2) - 2 * (x1 - x2) * (y1 - y3));
		r = sqrt((x1 - px) * (x1 - px) + (y1 - py) * (y1 - py));
		printf("%.3lf %.3lf %.3lf\n", px, py, r);
	}
}


Measured memory_bytes: 3068
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    long long n = 0;
    cin >> n;
    string ans = "";
    while (n != 0) {
        int buf = n%2;
        if (buf == 0) {
            ans += '0';
            n /= -2;
        }
        else {
            ans += '1';
            n = (n-1) / -2;
        }
    }
    if (ans == "") ans += '0';
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}


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

int main(void){
    int N;
    cin>>N;
    vector<ll> a(N),b(N);
    rep(i,N){
        cin>>a[i];
    }
    ll sum=0;
    rep(i,N){
        sum += a[i];
        b[i] = sum;
    }

    ll res = INT_MAX;
    rep(i,N-1){
        res = min(res,abs(sum-2*b[i]));
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;
long long n,m,nows=0;
char a[105][105];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(a[i][j]=='#')
			{
				cout<<"#";
				continue;
			}
			nows=0;
			if(a[i-1][j]=='#') nows++;
			if(a[i+1][j]=='#') nows++;
			if(a[i][j+1]=='#') nows++;
			if(a[i][j-1]=='#') nows++;
			if(a[i-1][j-1]=='#') nows++;
			if(a[i-1][j+1]=='#') nows++;
			if(a[i+1][j-1]=='#') nows++;
			if(a[i+1][j+1]=='#') nows++;
			cout<<nows;
		}
		cout<<endl;
	}
	return 0;
}

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

long long divisor(int n) {
    long long ret = 0;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret++;
            if (i * i != n) ret++;
        }
    }
    return ret;
}

int main() {
    int N;
    cin >> N;
    long long ans = 0;

    for (int i = 1; i < N; i++) {
        ans += divisor(i);
    }

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


Measured memory_bytes: 3644
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

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

  ll sum = 0;
  if (N != 2) {
    vector<ll> vec(N - 2);
    iota(begin(vec), end(vec), 1LL);
    sum = accumulate(cbegin(vec), cend(vec), 0LL);
  }
  if (K > sum) {
    cout << -1 << endl;
    return 0;
  }

  stringstream ss;
  ll count = 0;
  for (ll i = 2; i <= N; i++) {
    ss << 1 << " " << i << endl;
    count++;
  }
  ll minus = 0;
  for (ll i = 2; i < N; i++) {
    for (ll j = i + 1; j <= N; j++) {
      if (minus + K == sum) {
        cout << count << endl;
        cout << ss.str();
        return 0;
      }
      ss << i << " " << j << endl;
      count++;
      minus++;
    }
  }

  cout << count << endl;
  cout << ss.str();
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    LL a, b;
    cin >> a >> b;
    int cnt = 0;
    
    for( LL i = a; i <= b; i *= 2 ) {
        ++cnt;

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



Measured memory_bytes: 256
#include <stdio.h>

long pow(long a,int n){
  long answer = 1;
  for(int i = 0; i < n; ++i) answer *= a;
  return answer;
}

long eat(int n,long x){//n層下からxまでのpatty
  if(n == 1){
    if(x == 1) return 0;
    else if(x == 5) return 3;
    else return x - 1;
  }else if(n > 1){
    long p = pow(2,n+1) - 1; //真ん中のpの位置 = nバp数
    long pp = (p - 1) / 2; //n-1Burger
    long a = p - 2;        //n-1バーガーの層数
    long all = 2 * p - 1; //nBurgerの層数
    if(x == 1) return 0;  //bのみ
    else if(x < p) return eat(n-1,x-1); //下のburger
    else if(x == p) return 1 + eat(n-1,x-2);
    else if(x < all) return 1 + pp + eat(n-1,x - p);
    else if(x == all) return 1 + pp + eat(n-1,x - p - 1);
  }
}

int main(){
  int n;
  long x;
  scanf("%d %ld",&n,&x);
  long p = pow(2,n+1) - 1;//真ん中のpの位置
  long a = pow(2,n+1) - 3;//n-1バーガーの層数
  long answer = eat(n,x);
  printf("%ld\n",answer);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,k;
  cin >> n >> k;
  if(n % k == 0)cout << 0 << endl;
  else cout << 1 << endl;
}

Measured memory_bytes: 3636