akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define floot10 cout<<fixed<<setprecision(10);
#define int long long

struct UnionFind{
  int n;
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
	return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
	return find(x)==find(y);
  }
  void unite(int x,int y){
	x=find(x);y=find(y);
	if(x==y) return;
	if(r[x]<r[y]) swap(x,y);
	r[x]+=r[y];
	p[y]=x;
  }
};


signed main(){
	int n,m;
	cin>>n>>m;
	UnionFind hoge(n);
	lp(i,m){
		int a,b;
		cin>>a>>b;
		hoge.unite(a,b);
	}
	int q;
	cin>>q;
	lp(i,q){
		int a,b;
		cin>>a>>b;
		if(hoge.same(a,b)==true) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}


Measured memory_bytes: 4348
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;


int main(){
    string s,t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    bool flag;
    set<string> se;
    for(int i = n-m;i>=0;i--){
        flag = true;
        rep(j,m){
            if(s[i+j]==t[j] || s[j+i] == '?') continue;
            else {
                flag = false;
                break;
            }
        }
        if(flag) {
            string temp="";
            rep(j,i){
                if(s[j]=='?') temp.push_back('a');
                else temp.push_back(s[j]);
            }
            temp += t;
            for(int j = i+m;j<n;j++){
                if(s[j]=='?') temp.push_back('a');
                else temp.push_back(s[j]);
            }
            se.insert(temp);
        }
    }

    if(se.size()){
        cout << *se.begin() << endl;
    }else cout << "UNRESTORABLE" <<endl;
    
}

Measured memory_bytes: 3612
/*
    Reference :-
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
#define all(vec) vec.begin(),vec.end()
ll mod=1e9+7;
ll fac[100001];
ll power(ll n,ll k){
    ll ans=1;
    while(k){
        if(k&1)ans=(ans*n)%mod;
        k/=2;
        n=(n*n)%mod;
    }
    //ans=(ans-1+mod)%mod;
    return ans;
}
bool comp(PI a,PI b){
    return b.F<a.F;
}

int main(){
    //std::ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    vector<PI> ar;
    forn(i,n){
        int a,b;
        cin>>a>>b;
        ar.pb({a,b});
    }
    sort(all(ar));
    ll co=1,prev=ar[0].first+ar[0].second,nxt=ar[0].first+ar[0].second;
    forn1(i,n){
        ll dif=ar[i].first-ar[i].second;
        if(dif>=prev){
            prev=ar[i].first+ar[i].second;
            co++;
        }
        else{
            dif=ar[i].first+ar[i].second;
            if(prev>=dif)prev=ar[i].first+ar[i].second;
        }
    }
    sort(all(ar),comp);
    //cout<<ar[0].first<<endl;
    ll co1=1;prev=ar[0].first-ar[0].second;
    forn1(i,n){
        ll dif=ar[i].first+ar[i].second;
        if(dif<=prev){
            prev=ar[i].first-ar[i].second;
            co1++;
        }
        else{
            dif=ar[i].first-ar[i].second;
            if(prev<=dif)prev=ar[i].first-ar[i].second;
        }
    }
    cout<<max(co,co1);

	return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

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

    bool good = true;
    rep(i, s.size()-1) {
        if (s[i] == s[i+1]) {
            good = false;
        }
    }

    cout << (good ? "Good" : "Bad") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
using namespace std;

int main(){
    int W,a,b;
    cin >> W >> a >> b;
    if(a+W<b){
        cout << b-a-W << endl;
    }
    else if(b+W<a){
        cout << a-b-W << endl;
    }
    else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0,d=0,e=0, ans = 0, x = 0, y = 0, z = 0, n = 0, m = 0, maxy = 0, mini = 9999, counter = 0, endp = 0, checker = 0;

std::vector <long long int> vec{}, vecsec{}, vecth{};
long long int iremono[100001], koware[100001];
long long int iremono2[100001], check[100001],xpo[10000001],ypo[10000001],hei[1000001];
std::vector<std::string>kinds{}, kaku{};
char maze[1000][1000];
int sx, sy;
int gx, gy;
pair<long long int, long long int>pairs[101],pointkaku[10000000];
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
std::string output, output2, input, input2;
char re;
int starta, startb, enda, endb,ab;


unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

int H, W;//はんい
bool qw = false, er = false, ty = false,ui=false;
int main() {
	cin >> a>>b;
	if (b == 1) {
		cout << 0 << endl;
	}
	else {
		cout << a - b << endl;
	}

}


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

using namespace std;

#define node first
#define state second

const int N = 1e5 + 5;
vector<int> adj[N];
bool vis[N][3];

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

    int n , m;
    cin >> n >> m;

    while (m--) {
        int u , v;
        cin >> u >> v;
        adj[u].push_back(v);
    }

    int s , e;
    cin >> s >> e;

    queue<pair<int , int> > q;
    q.push({s , 0});
    vis[s][0] = 1;

    int dep = 0;
    while (q.size()) {
        int sz = q.size();
        while (sz--) {
            auto &cur = q.front();
            q.pop();

            if (cur.node == e && !cur.state) {
                cout << dep / 3;
                return 0;
            }

            for (int child : adj[cur.node]) {
                if (!vis[child][(cur.state + 1) % 3]) {
                    q.push({child , (cur.state + 1) % 3});
                    vis[child][(cur.state + 1) % 3] = 1;
                }
            }
        }
        dep++;
    }

    cout << -1;
}


Measured memory_bytes: 9352
#include <iostream>
#include <string>
#define MOD 1000000007

using namespace std;

long long ans;
int cnt[30], n;
string s;

void dfs(int here, long long ansHere)
{
	if(here == 'z' - 'a' + 1)
	{
		ans = (ans + ansHere) % MOD;
		return;
	}

	dfs(here + 1, ansHere);
	if(cnt[here] > 0)
		dfs(here + 1, (ansHere * cnt[here]) % MOD);

}

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

	cin >> n >> s;
	for(int i = 0; i < n; i++)
		cnt[s[i] - 'a']++;

	dfs(0, 1);

	cout << ans - 1 << '\n';
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cmath>
#include<math.h>
//#include<array>
#include<algorithm>
#include<queue>
#include<deque>
#include<vector>
//#include<utility>
//#include<set>
#include<map>
//#include<list>
//#include<bitset>
//#include<iomanip>

using namespace std;
using LLI = long long int;
LLI N;

//配列,座標
/*array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
array<int, 4>dir_x2 = { 0,0,1,-1 };
array<int, 4>dir_y2 = { 1,-1,0,0 };
char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };*/

//Union Find
/*class UnionFind {
public:
	vector<int>data;
	UnionFind(int size) :data(size, -1) {};
	bool unionset(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x]) {
				swap(x, y);
			}
			data[x] += data[y];
			data[y] = x;
		}
		return x != y;
	}
	bool findset(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};*/

//最大公約数,最小公倍数
/*LLI gcd(LLI x, LLI y) {
	LLI  r;
	if (x < y) {
		swap(x, y);
	}
	r = x % y;
	while (r != 0) {
		x = y;
		y = r;
		r = x % y;
	}
	return y;
}
LLI lcm(LLI x, LLI y) {
	return x / gcd(x, y) * y;
}*/

//組み合わせ
/*long nCr(int n, int r) {
	long ans = 1;
	for (int i = n; i > n - r; i--) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; i++) {
		ans = ans / i;
	}
	return ans;
}
long nHr(int n, int r) {
	n = n + r - 1;
	return nCr(n, r);
}*/

//素数判定
/*bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}*/

//桁数
/*LLI GetDigit(LLI num) {
	LLI digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}*/

//サンプル
/*const int n_max = 8;
array<array<bool, n_max>, n_max>graph;
int dfs(int v,int N,array<bool,n_max>visited) {
	int ret = 0;
	bool all_visited = true;
	for (int i = 0; i < N;i++) {
		if (visited[i] == false) {
			all_visited = false;
		}
	}
	if (all_visited) {
		return 1;
	}
	for (int i = 0; i < N;i++) {
		if (graph[v][i] == false) {
			continue;
		}
		if (visited[i] == true) {
			continue;
		}
		visited[i] = true;
		ret += dfs(i,N,visited);
		visited[i] = false;
	}
	return ret;
}*/

//サンプル
/*vector<vector<int>>sub;
int dfs(int id) {
	if (sub[id].size() == 0) {
		return 1;
	}
	int minP = (int)1e9;
	int maxP = 0;
	for (int i : sub[id]) {
		int P = dfs(i);
		minP = min(minP, P);
		maxP = max(maxP, P);
	}
	return minP + maxP + 1;
}*/

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl

int main(void) {
	LLI K, X;
	cin >> K >> X;
	if (500 * K >= X)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

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

int main()
{
    string S, T;

    cin >> S >> T ;

    if( S == T.substr(0, T.length()-1) )
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3608
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut a: Vec<u64> = sc.vec(n);
    a.sort();

    let mut suffix_sum = vec![0; n + 1];
    for i in 0..n {
        suffix_sum[i + 1] = suffix_sum[i] + a[n - 1 - i];
    }

    let mut ng = 1e15 as u64;
    let mut ok = 0;
    while ng - ok > 1 {
        let x = (ok + ng) >> 1;
        let (count, _) = calc(x, &a, &suffix_sum);

        if count >= m {
            ok = x;
        } else {
            ng = x;
        }
    }

    let (count1, sum1) = calc(ok, &a, &suffix_sum);
    if count1 == m {
        println!("{}", sum1);
        return;
    }

    let (count2, sum2) = calc(ok + 1, &a, &suffix_sum);
    assert!(count2 < m);
    let remain = m - count2;
    let ans = sum2 + ok * remain as u64;

    println!("{}", ans);
}

fn calc(x: u64, a: &Vec<u64>, suffix_sum: &Vec<u64>) -> (usize, u64) {
    let n = a.len();
    let mut sum = 0;
    let mut cur_row = n;
    let mut cur_col = 0;
    let mut count = 0;
    while cur_col < n {
        if cur_row > 0 && a[cur_col] + a[cur_row - 1] >= x {
            cur_row -= 1;
        } else {
            let c = n - cur_row;
            sum += suffix_sum[c] + a[cur_col] * c as u64;
            count += c;
            cur_col += 1;
        }
    }
    (count, sum)
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 6524
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
#include <fstream>
#include <queue>
#include <cstdio>
#include <deque>
#define fol(i,n) for(int i=0;i<n;i++)
#define db(a) cout << a<< endl;
using namespace std;

int main(){
    long long a,b,c,d;
    cin >> a>>b>>c;
    if ((a%2)*(b%2)*(c%2)==0) cout << 0 <<endl;
    else {
        d = min({a*b,b*c,c*a});
        printf("%lld",d);
    }
    return 0;
}


Measured memory_bytes: 256
import sys
 
read = sys.stdin.read
readline = sys.stdin.readline

R,C,K = map(int,readline().split())
board = [[0]*C for _ in range(R)]
for _ in range(K):
  r,c,v = map(int,readline().split())
  board[r-1][c-1] = v

dp0 = [[0]*C for _ in range(R)]
dp1 = [[0]*C for _ in range(R)]
dp2 = [[0]*C for _ in range(R)]
dp3 = [[0]*C for _ in range(R)]

for i in range(R):
  for j in range(C):
    if dp1[i][j] < dp0[i][j]+board[i][j]:
      dp1[i][j] = dp0[i][j]+board[i][j]
    if j>0:
      if dp0[i][j] < dp0[i][j-1]:
        dp0[i][j] = dp0[i][j-1]
      if dp1[i][j] < dp1[i][j-1]:
        dp1[i][j] = dp1[i][j-1]
      if dp2[i][j] < dp2[i][j-1]:
        dp2[i][j] = dp2[i][j-1]
      if dp3[i][j] < dp3[i][j-1]:
        dp3[i][j] = dp3[i][j-1]
      if dp1[i][j] < dp0[i][j-1]+board[i][j]:
        dp1[i][j] = dp0[i][j-1]+board[i][j]
      if dp2[i][j] < dp1[i][j-1]+board[i][j]:
        dp2[i][j] = dp1[i][j-1]+board[i][j]
      if dp3[i][j] < dp2[i][j-1]+board[i][j]:
        dp3[i][j] = dp2[i][j-1]+board[i][j]
    if i>0:
      if dp0[i][j] < dp0[i-1][j]:
        dp0[i][j] = dp0[i-1][j]
      if dp0[i][j] < dp1[i-1][j]:
        dp0[i][j] = dp1[i-1][j]
      if dp0[i][j] < dp2[i-1][j]:
        dp0[i][j] = dp2[i-1][j]
      if dp0[i][j] < dp3[i-1][j]:
        dp0[i][j] = dp3[i-1][j]
      if dp1[i][j] < dp0[i-1][j]+board[i][j]:
        dp1[i][j] = dp0[i-1][j]+board[i][j]
      if dp1[i][j] < dp1[i-1][j]+board[i][j]:
        dp1[i][j] = dp1[i-1][j]+board[i][j]
      if dp1[i][j] < dp2[i-1][j]+board[i][j]:
        dp1[i][j] = dp2[i-1][j]+board[i][j]
      if dp1[i][j] < dp3[i-1][j]+board[i][j]:
        dp1[i][j] = dp3[i-1][j]+board[i][j]
print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))

Measured memory_bytes: 435512
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define  rep(i,a,b) for(i=a;i<b;i++)
#define endl "\n"
#define ll long long int
#define ld long double
using namespace std;
int main()
{
IOS;
string s;char c;
ll l,i,k=0;
cin>>s;
l=s.length();
rep(i,0,l)
{
    c=s[i];
    if(i%2==0)
    {
        if(c=='L')
            k++;
    }
    else
        if(c=='R')
            k++;
}
if(k!=0)
    cout<<"No";
else
    cout<<"Yes";
return 0;
}



Measured memory_bytes: 256
from fractions import gcd
A, B = map(int, input().split())
g = gcd(A, B)
def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table
print(len(set(prime_decomposition(g)))+1)


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

#define dump(a) (cerr << #a << " = " << (a) << endl)

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

	int n, k;
	cin >> n >> k;

	const int half = (n + 1) / 2;

	for(int i = 0; i < k; ++i) {
		int x, y;
		cin >> x >> y;

		if(x > half)
			x = n - x + 1;

		if(y > half)
			y = n - y + 1;

		if(y >= x)
			cout << (x - 1) % 3 + 1 << endl;
		else
			cout << (y - 1) % 3 + 1 << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1200
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD (ll)1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define MAX_N (1 << 17)

int
main(int argc, char *argv[])
{
  int m, d;
  scanf("%d %d", &m, &d);

  int ans = 0;
  for (int i = 1; i <= d; i++) {
    int x = i / 10;
    int y = i % 10;
    int s = x * y;
    for (int j = 1; j <= m; j++) if (x >= 2 && y >= 2 && s == j) ans++;
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,mod,ans;
	cin>>n;
	mod=n%11;
	if(mod==0) ans=(n/11)*2;
	else if(mod<7) ans=((n/11)*2)+1;
	else ans=((n/11)*2)+2;
	cout<<ans<<endl;
}

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

int main() {
  int a=0;
  int s1=0;
  int s2=0;
  int s3=0;
  int sum=0;
  cin >> a;
  s1 = a/100;
  s2 = a%100/10;
  s3 = a%100%10;
  sum = s1 + s2 + s3;
  cout << sum << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        sc.nextLine();
        String s = sc.nextLine();
        if (a>=3200){
            System.out.println(s);
        }else {
            System.out.println("red");
        }
    }
}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
#include<vector>
using namespace std;
#define MAX 200005
#define MOD 1000000007
#define INF 4000000000000000000
#define EPS 0.0000000000001
int A[MAX];
vector<int> differences[MAX];
int bin_search(int diff,int key)
{
    if(differences[diff].size()==0) return 0;
    int first=0,last=differences[diff].size()-1;
    int middle=(first+last)/2;
    while(first<last)
    {
        if(last-first==1&&differences[diff][first]<key) first=last;
        else if(last-first==1) last=first;
        else if(differences[diff][middle]<key) first=middle;
        else last=middle;
        middle=(first+last)/2;
    }
    if(differences[diff][middle]<key) middle++;
    return differences[diff].size()-middle;
}
int main()
{
    int N,i,j;
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d",&A[i]);
        if(A[i]<=i)
        {
            differences[i-A[i]].push_back(i);
        }
    }
    long long ans=0;
    for(i=0;i<N;i++)
    {
        if(A[i]+i>=MAX)
        {
            continue;
        }
        ans=ans+bin_search(i+A[i],i+A[i]);
    }
    printf("%lld",ans);
    return 0;
}



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

using namespace std;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int n,x;cin>>n>>x;
  //1 $B2sL\$O:BI8(BD1=0
  //i $B2sL\$O:BI8(BDi= Di$B!](B1+ Li$B!](B1$B$GD7$M$^$9!#(B
  //X $B0J2<$NNN0h$G%\!<%k$,D7$M$k2s?t$O2?2s(B
  int cnt=0,l,d=0;
  if(d<=x)cnt++;
  //cout<<"d:"<<d<<" x:"<<x<<endl;
  rep(i,n){
    cin>>l;
    d+=l;
    //cout<<"d:"<<d<<" x:"<<x<<endl;
    if(d<=x)cnt++;
  }
  cout<<cnt<<endl;
}


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

typedef unsigned long long ull;

int main(){
    ull A, B;
    int K;
    cin >> A >> B >> K;

    for(ull i=A;i<=B;i++){
        if(i<A+K || i>B-K){
            cout << i << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))
MOD = 10**9+7
dp = [[0 for i in range(2010)] for i in range(2010)]
for i in range(2010):
  dp[i][0] = 1
  dp[0][i] = 1
s = list(map(int, input().split()))
t = list(map(int, input().split()))
for i in range(1, n+1):
  for j in range(1, m+1):
    dp[i][j] = (dp[i][j]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%MOD
    if s[i-1]==t[j-1]:
      dp[i][j] = (dp[i][j]+dp[i-1][j-1])%MOD
print(dp[n][m])

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  bool ans = false;
  
  vector<int> haiku;
  haiku ={A, B, C};
  sort(haiku.begin(),haiku.end());
  reverse(haiku.begin(),haiku.end());
  
  if(haiku[0]==7){
    if(haiku[1]==5 && haiku[2]==5){
      ans= true;
    }
  }
  if(ans==true) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3520
#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<int,int>;

int main(){
   int n;
   cin >> n;
   vector<int> a(n);
   rep(i,n) cin >> a[i];
  set<int> s;
  rep(i,n){
  	s.insert(a[i]);
  }
     if(s.size() == n){
     	cout << "YES" << endl;
     }else{
     	cout << "NO" << endl;
     }
   }

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

#define ED return 0;
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) int(pow(x,y))
#define FI first
#define SE second
const long mod = 1000000007;

int change(int n,int before,int after){
    if(before < 2 || after < 2 || before > 10 || after > 10){
        return 0;
    }
    int ten = 0;
    for(int i = 0;n != 0;i++){
        ten += n % 10 * pow(before,i);
        n /= 10;
    }
    int end = 0;
    for(int i = 1;ten > 0;i++){
        end += ten % after * pow(10,i-1);
        ten -= ten % after;
        ten /= after;
    }
    return end;
}

int main(){
    int N;
    cin >> N;
    vector<int> vec (N);
    int g = 0;
    int k = 0;
    for(int i = 0;i < N;i++){
        int test;
        cin >> test;
        if(test % 2 == 1){
            k++;
        }
        else{
            g++;
        }
    }
    cout << ipow(3,N) - ipow(2,g) << endl;
}


Measured memory_bytes: 384
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
e = [a[k] for k in range(0,n,2)]
o = [a[k] for k in range(1,n,2)]
C = Counter(e).most_common()
D = Counter(o).most_common()
if C[0][0] != D[0][0]:
    print(n-C[0][1]-D[0][1])
else:
    if len(C) == len(D) == 1:
        print(n//2)
    elif len(C) == 1 and len(D) > 1:
        print(n-C[0][1]-D[1][1])
    elif len(D) == 1 and len(C) > 1:
        print(n-D[0][1]-C[1][1])
    else:
        print(n-max(D[0][1]+C[1][1],C[0][1]+D[1][1]))


Measured memory_bytes: 21084
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);

void solve(long long int t){
	if(t){
		solve((t - 1) / 26);
		int ans = t % 26;
		if(ans == 0){
			ans = 26;
		}
		cout << (char)(ans + 'a' - 1);
	}
}

int main(){
	long long int n;
	cin >> n;
	solve(n);
} 

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <utility>
#include <vector>


int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); 
    std::cout << std::fixed << std::setprecision(16);
    
    int n, L, T; std::cin >> n >> L >> T;
    std::vector<int> X(n); std::vector<bool> Dir(n);
    std::vector<int> destination(n);
    for(int i = 0; i < n; ++i){
        char c; std::cin >> X[i] >> c;
        if(c == '1'){
            Dir[i] = true;
            destination[i] = (X[i] + T) % L;
        }
        else{
            Dir[i] = false;
            destination[i] = (X[i] - T) % L;
            if(destination[i] < 0) destination[i] = L + destination[i];
        }
    }
    long long int pos = 0;
    if(Dir[0]){
        for(int i = 1; i < n; ++i) if(not Dir[i]){
            long long int dist = X[i] - X[0]; if(dist <= 0) dist += L;
            // (dist + Lk) ≤ 2Tなる最大の k : k = (2T - dist) / L
            const long long int d = 2 * T - dist;
            if(d >= 0) pos += (d / L) + 1;
        }
        pos %= n;
    }
    else{
        for(int i = 1; i < n; ++i) if(Dir[i]){
            long long int dist = X[0] - X[i]; if(dist <= 0) dist += L;
            const long long int d = 2 * T - dist;
            if(d >= 0) pos -= (d / L) + 1;
        }
        pos %= n; if(pos < 0) pos += n;
    }

    const int zero_pos = destination[0];
    std::sort(destination.begin(), destination.end());
    int idx1 = std::lower_bound(destination.cbegin(), destination.cend(), zero_pos) - destination.cbegin();
    if(Dir[0] and idx1 + 1 < n and destination[idx1] == destination[idx1 + 1]) ++idx1;
    
    const int delta = (pos <= idx1) ? idx1 - pos : n + (idx1 - pos);
    for(int i = 0, j = delta; i < n; ++i){
        if(j == n) j = 0;
        std::cout << destination[j++] << '\n';
    }
    
    return 0;
}

Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
	long long n,i,j,k,l,f;
	f=0;
	j=0;
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>arr[i];
	}
	k=1;
	l=0;
	for (i=1;i<=n;i++)
	{
		if (arr[i]==k)
		{
			f=1;
			k++;
			j=j+i-l-1;
			l=i;
		}
	}
	j=j+i-l-1;
	if (f==0)
	{
		cout<<-1<<endl;
		return 0;
	}
	cout<<j<<endl;
}

Measured memory_bytes: 1792
X = int(input())
ans = []

for i in range(34):
  for j in range(2,11):
    if pow(i,j) <= X: 
      ans.append(pow(i,j))
    else:
      break

ans.sort(reverse= True)

for i in ans:
  if i <= X:
    print(i)
    break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    string ans = "";
    if(n==0)
        ans.push_back('0');
    for (int i = 0;; i++)
    {
        if (n == 0)
            break;
        ans += abs(n % 2) + '0';
        if (abs(n % 2))
        {
            if (i % 2 == 0)
                n--;
            else
                n++;
        }
        n /= 2;
    }
    reverse(all(ans));
    cout << ans << endl;
}

Measured memory_bytes: 256
<?php
    fscanf(STDIN, "%d", $n);
    $array = str_split($n);
    for($i = 0; $i < 3; $i++){
        if($array[$i] == 9){
            $array[$i] = 1;
        }elseif($array[$i] == 1){
            $array[$i] = 9;
        }
    }
    $answer = (int)implode($array);
    echo $answer;
?>

Measured memory_bytes: 4728
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    V = list(map(int, readline().split()))
    C = list(map(int, readline().split()))

    ans = 0

    for x, y in zip(V, C):
        if x - y >= 0:
            ans += x - y

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61364
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main(){
    string s;
    cin >> s;
    int i = 0;
    bool t = true;
    while(t){
        if(s[i] == 'A'){
            t = false;
        }
        if(t == true){
        i++;
        }
    }
    int j = s.length() - 1;
    bool p = true;
    while(p){
        if(s[j] == 'Z'){
            p = false;
        }
        if(p == true){
        j--;
        }
    }
    cout << j - i + 1 << endl;
}

Measured memory_bytes: 640
A = [[int(_) for _ in input().split()] for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

for a in A:
    for b in B:
        if b in a:
            a[a.index(b)] = 0

ans = "No"
if [A[i][i] for i in range(3)] == [0, 0, 0]:
    ans = "Yes"
if [A[i][2-i] for i in range(3)] == [0, 0, 0]:
    ans = "Yes"
for i in range(3):
    if A[i] == [0, 0, 0]:
        ans = "Yes"
    if [A[j][i] for j in range(3)] == [0, 0, 0]:
        ans = "Yes"
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

constexpr ll MOD = 1000000007;

ll inv(ll a,ll p){
  return ( a == 1 ? 1 : (1 - p*inv(p%a,a)) / a + p );
}

ll fact[2000001];
ll ifact[2000001];

ll comb(ll n, ll k) {
  return fact[n] * ifact[k] % MOD * ifact[n-k] % MOD;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  fact[0] = 1;
  REP(i,2000000) {
    fact[i+1] = fact[i] * (i+1) % MOD;
  }
  ifact[2000000] = inv(fact[2000000], MOD);
  REP(ri,2000000) {
    int i = 2000000 - ri;
    ifact[i-1] = ifact[i] * i % MOD;
  }
  ll k;
  cin>>k;
  string s;
  cin>>s;
  ll m = size(s);
  ll p26 = 1;
  REP(i,k) {
    p26 *= 26;
    p26 %= MOD;
  }
  ll p25 = 1;
  ll i26 = inv(26, MOD);
  ll ans = 0;
  REP(i,k+1) {
    ll tmp = comb(m+i-1, m-1) * p25 % MOD * p26 % MOD;
    ans += tmp;
    ans %= MOD;
    p25 *= 25;
    p25 %= MOD;
    p26 *= i26;
    p26 %= MOD;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 35508
#include <bits/stdc++.h>
 
using namespace std;
 
#define ld long double
#define ll long long

int main(){
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        //freopen("test.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    #endif*/
    //freopen("input.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
 
    int a,b;cin>>a>>b;
    cout<<max({a+b,a-b,a*b});

    /*#ifndef ONLINE_JUDGE
        cout << "\nTime Elapsed : " << 1.0 * clock() << " ms\n";
    #endif*/
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
using namespace std;

int main()
{
    int N, X;
    cin >> N >> X;
    vector<int> L(1, 0);
    for (int i = 1; i < N + 1; i++)
    {
        int l;
        cin >> l;
        L.push_back(L[i - 1] + l);
    }
    int ans = 0;
    for (int i : L)
    {
        if (i <= X)
        {
            ans++;
        }
        else
        {
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define ss second
#define ff first
#define ll long long int
#define tcase ll t;cin>>t;while(t--)
#define sz(a) int((a).size())
#define pb push_back
#define present(c,x) (©.find(x) != ©.end())
#define cpresent(c,x) (find(all©,x) != ©.end())
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define Yes cout<<"Yes\n";
#define No cout<<"No\n";
#define f(i,a) for(int i=0;i<a;i++)
#define MAX 500
using namespace std;


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


        int n;
        cin>>n;
         string s;
         cin>>s;
         int l=s.length();
         if(l<=n)
            cout<<s;
         else
         {
             s.erase(n);
             string t="...";
             s+=t;
             cout<<s;
         }

	return 0;
}


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

namespace ABC_Training
{
    public class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            Console.WriteLine(s[2] == s[3] && s[4] == s[5]?"Yes":"No");
        }
    }
}


Measured memory_bytes: 11092
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


n = I()
a = LI()

mx = max(a)
table = [0] * (mx + 1) # num of factors
for x in a:
  table[x] += 1
g = 0
# check 
for x in a:
  g = gcd(g, x)
for i in range(2, mx + 1):
  c = 0
#　因数iの倍数がaにいくつ含まれるか(c)
  for j in range(i, mx + 1, i):
    c += table[j]
# cが2以上=iの倍数となるaが複数存在する
  if c > 1:
    if g == 1:
      print("setwise coprime")
    else:
      print("not coprime")
    exit(0)
print("pairwise coprime")


Measured memory_bytes: 210244
import java.util.ArrayList;
        import java.util.List;
        import java.util.Scanner;
        import java.util.stream.IntStream;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        int Y = sc.nextInt();
        int U = sc.nextInt();
//        int[] a = new int[T];
//        for (int i = 0; i < T; i++) {
//            a[i] = sc.nextInt();
//        }
        //System.out.println(IntStream.of(a).reduce(0,(right,left) -> right + left -1));
        //System.out.println(IntStream.rangeClosed(1,100).filter(c -> c % 2 == 0).sum());

        System.out.println((Y-U)%2==0 ? "Alice" :"Borys");

    }
}


Measured memory_bytes: 23124
import bisect
N, K = map(int, input().split())
a = list(map(int, input().split()))
MOD = 10**9 + 7
ans = 0
a.reverse()
lst2 = sorted(a)
memo = {}
for i in range(N):
    if not a[i] in memo:
        memo[a[i]] = bisect.bisect_left(lst2, a[i])
    ans += K * (K - 1) // 2 *memo[a[i]]

for i in range(1, N):
    lst = sorted(a[0:i])
    k1 = bisect.bisect_left(lst, a[i])
    ans += k1 * K
    ans %= MOD

print(ans)

Measured memory_bytes: 3316
import java.util.*;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		String[] s = sc.nextLine().split(" ");
		int in[] = new int[s.length];
		for(int i=0;i<s.length;i++){
			in[i] = Integer.parseInt(s[i]);
		}
		System.out.println(in[0]/in[1]+" "+in[0]%in[1]+" "+String.format("%.5f",(double)in[0]/in[1]));
	}
}

Measured memory_bytes: 26412
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

bool query(int &l,int &r,char &lch){
    int mid = (l+r)/2;
    if(r-l==2) cout << l+1 << "\n" << flush;
    else cout << mid << "\n" << flush;
    string s; cin >> s;
    if(s[0] == 'V') return true;
    else if(s[0]==lch){
        if((mid-l)%2==0) l = mid;
        else r = mid;
    }else{
        if((mid-l)%2==1) {
            l = mid;
            lch = s[0];
        }else r = mid;
    }
    return false;
}

int main(){
    int n;cin >> n;
    bool flag = false;
    cout << 0 << "\n" << flush;
    string s;cin >> s;
    if(s[0]=='V') return 0;
    int l = 0;
    int r = n;
    while(!flag){
        flag = query(l,r,s[0]);
    }
    return 0;
    
}

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

int main()
{
    int s, c = 1;
    cin >> s;
    while (s != 1 && s != 2 && s != 4)
    {
        if (s & 1) s = 3 * s + 1;
        else s = s >> 1;
        c++;
    }
    cout << c + 3 << '\n';
    return(0);
}

Measured memory_bytes: 256
nums = list(map(int, input().split()))
N, M = nums[0], nums[1]
A = list(map(int, input().split()))

nums = [2,5,5,4,5,6,3,7,6];

from copy import deepcopy as copy
dp = [[0 for _ in range(10)] for _ in range(N+1)]

def compare_dp(a1, a2):
    for i in range(10):
        if a1[i] > a2[i]:
            return True
        elif a1[i] < a2[i]:
            return False

    return True

def allzero(a):
    flag = True
    for e in a:
        flag = flag and (e==0)
    return flag

for i in range(N+1):
    for j in range(M):
        if i >= nums[A[j]-1]:
            if (not allzero(dp[i-nums[A[j]-1]])) or i-nums[A[j]-1]==0:
                val = copy(dp[i-nums[A[j]-1]])
                val[0] += 1
                val[10-A[j]] += 1
                if compare_dp(val, dp[i]):
                    dp[i] = copy(val)

for i in range(9):
    for j in range(dp[N][i+1]):
        print(9-i, end="")
print("\n", end="")


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

int main()
{
    int x;
    cin >> x;
    int t = x;
    int k = 1;
    while( t % 360 != 0 )
    {
        k++;
        t += x;
    }

    cout << k;
}

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

int main(){
  long long N, A, B;
  cin >> N >> A >> B;

  long long sum_max = (N - 1) * B + A, sum_min = B + (N - 1) * A;
  long long ans = max(0LL, sum_max - sum_min + 1);

  cout << ans << endl;
}


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

a=[0]#x^5 list
for i in range(1,201):
    a.append(i**5)

I=0
J=0
b=0
for i in range(0,201):
    for j in range(0,201):
        if a[i]-a[j]==x:
            I=i
            J=j
            b=1
            break
    if b==1:
        break

for i in range(0,201):
    for j in range(0,201):
        if a[i]+a[j]==x:
            I=i
            J=-j
            b=1
            break
    if b==1:
        break
print(I,J)


Measured memory_bytes: 64144
///
// File:  a.go
// Author: ymiyamoto
//
// Created on Tue May 22 22:13:49 2018
//
package main

import (
	"fmt"
)

var A, B, C, K int64

func main() {
	fmt.Scan(&A, &B, &C, &K)
	if K%2 == 0 {
		fmt.Println(A - B)
	} else {
		fmt.Println(B - A)
	}
}


Measured memory_bytes: 512
num = int(input())
happiness = 0
num1 = num // 500
num2 = num % 500 

num3 = num2 // 5 

happiness += num1 * 1000 + num3 * 5

# while num > 500:
#     num = num - 500
#     happiness += 1000 
# while num > 5:
#     num = num - 5 
#     happiness += 5 

print (happiness)

Measured memory_bytes: 2940
#include<stdio.h>
int main(void)
{
	int a,s,d,i;
	while(scanf("%d",&a)!=EOF){
	s=1;
	for(i=1;i<=a;i++){
		s=s+i;
	}
	printf("%d\n",s);
	}
	return 0;
}

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

int main(){

    int N;
    cin >> N;
    vector<int> vx;
    int A[N],B[N];
    for(int i = 0; i < N;i++){
        cin >> A[i];
        vx.push_back(A[i]);
    }
    
    sort(A,A+N);
    sort(vx.begin(),vx.end());
    vx.erase(unique(vx.begin(),vx.end()),vx.end());
    if(vx.size()>3){
        cout << "No" << endl;
        return 0;
    }
    
    for(int i = 0; i < vx.size();i++){
        
        for(int j = 0; j < vx.size();j++){
            
            int a = vx[i],b = vx[j];
            B[0]=a,B[1]=b;
            for(int k = 2;k<N;k++)B[k]=B[k-2]^B[k-1];
            bool up = true;
            for(int k = 0; k < N;k++){
                
                int S = B[k];
                int T = B[(k-1+N)%N]^B[(k+1)%N];
                if(S!=T)up=false;
            }

            if(up){
                sort(B,B+N);
                for(int k = 0; k < N;k++)if(B[k]!=A[k])up = false;
                if(up){
                    cout <<"Yes"<<endl;
                    return 0;
                }
            }
        }
    }
    cout <<"No"<<endl;
    return 0;
}

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

// Begin Header {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define all(x) x.begin(), x.end()
#define rep(i, n) for (intmax_t i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

template <class T>
inline istream& operator>>(istream &is, vector<T> &vec) {
    for (auto &e: vec) {
        is >> e;
    }
    return is;
}

inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    output(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

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

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

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// End Header }}}

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

    var(intmax_t, N);

    reps(i, 1, 9) reps(j, 1, 9) {
        if (i * j == N) {
            return output("Yes"), 0;
        }
    }

    output("No");

    return 0;
}


Measured memory_bytes: 256
N = gets()
ary = []
N.to_i.times do |_|
  ary << gets()
end
ret = {}

ary.each do |e|
  _e = e.chars.sort.join
  if ret.has_key? _e
    ret[_e] += 1
  else
    ret[_e] = 1
  end
end

ans = 0
ret.each do |k, v|
  ans += (v * (v-1)) / 2
end
puts ans
                
  


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    double a, b, t,index=1;
    cin >> a >> b >> t;

    while (1) {
        if ((index * a) < (t + 0.5))index++;
        else break;
    }
    cout << --index * b << endl;
    return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

string S;
int ans, cnt;

int main(){
  cin >> S;
  int N = S.length();
  for (int i = N - 1; i >= 0; i--){
    if (S[i] == 'T'){
      cnt++;
    }else{
      if (cnt > 0) cnt--;
      else ans++;
    }
  }
  cout << ans + cnt << endl;


  return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;
 
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll mod(ll a, ll b) { return (a%b+b)%b; }
ll gcd(ll x, ll y) { return __gcd(x, y); }
ll lcm(ll x, ll y) { return x * 1ll * y / gcd(x, y); }
 
 
const ll MAXN = 1e18;
const ll SIZE = 2e5 + 5;
const ll MOD  = 1e9 + 7;

int n;

int main() { speedhack()

	cin >> n;
	n = n % 10;

	if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
		cout << "hon";
	else if (n == 0 || n == 1 || n == 6 || n == 8)
		cout << "pon";
	else
		cout << "bon";

	return 0;
}


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

ll gcd(ll x,ll y){return y ? gcd(y,x%y) : x; }

vector<pair<ll,int>>factorize(ll n){
  vector<pair<ll,int>>res;
  for (ll i=2;i*i<=n;i++){
    if(n%i)continue;
    res.emplace_back(i,0);
    while(n%i==0){
      n/=i;
      res.back().second++;
    }
  }
  if (n!=1) res.emplace_back(n,1);
  return res;
}

int main(){
  ll a,b;
  cin>>a>>b;
  ll g=gcd(a,b);
  auto f=factorize(g);
  ll ans=f.size()+1;
  cout<<ans<<endl;
  return 0;
}

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

int main() {
	int n, k;
	string s;
	cin >> n >> k;
	cin >> s;
	char x = s.at(0);
	int st = 1;
	int en= 0;
	for (int i = 0; i < k; i++) {
		en = s.length();
		for (int j = st-1; j < s.length(); j++) {
			if (s.at(j) == x)continue;
			else {
				st = j;
				for (int k = j; k < s.length(); k++) {
					if (s.at(st) != s.at(k)) {
						en = k;
						break;
					}
				}
				break;
			}
		}
		for (int j = st; j < en; j++)s.at(j) = x;
		st = en - 1;
	}
	ll ans = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s.at(i) == 'L') {
			if (i == 0)continue;
			else {
				if (s.at(i - 1) == 'L')ans++;
			}
		}
		else {
			if (i == s.length() - 1)continue;
			else {
				if (s.at(i + 1) == 'R')ans++;
			}
		}
	}
	//cout << s << endl;
	cout << ans << endl;
}

Measured memory_bytes: 512