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

using namespace std;

#define forn(i,n) for ( int i=0 ; i < n ; i++ )
#define all(a) (a).begin(), (a).end()
#define lb lower_bound
#define ub upper_bound
#define vi vector<int >
#define pii pair<int, int>
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SQ(a) (a)*(a)
#define ll long long
#define lli long long int
#define ull unsigned long long
#define endl '\n'
#define Pi(a) printf("%d\n",a);
#define debug2(a,b) printf("%d\t%d\n",a,b);
#define debug1(a) printf("%d\n",a);
#define Si(a) scanf("%d",&a);
#define mod 1000000007
#define w(n) while(n--)



int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//code
	string s,t;
	cin >> s >> t;
	int n=s.length();
	bool ans=false;
	forn(i,n){
		int k=i;
		bool local=true;
		forn(j,n){
			if(s[k%n]!=t[j]) local=false;
			k++;
		}
		if(local) ans=true;
	}
	if(ans) cout << "Yes";
	else cout << "No";
	return 0;

}

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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;using vb=vector<bool>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template <typename T> T read() {T t; cin >> t; return t;}

void Main() {
  int h = read<int>();
  int w = read<int>();
  rep(y, h) rep(x, w) {
    string s = read<string>();
    if (s == "snuke") {
      string ans = "";
      _p("%c%d\n", 'A' + x, y + 1);
    }
  }
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<Edge>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,K,ans=0;
  cin>>N>>K;
  ll A[N],S[N+1],T[N+1];
  S[0]=0;
  T[0]=0;
  REP(i,N){
    cin>>A[i];
    S[i+1]=S[i]+A[i];
    T[i+1]=(S[i+1]-i-1)%K;
    if(T[i+1]<0) T[i+1]+=K;
  }
  
  vector<pair<ll,ll>> L;
  REP(i,N+1) L.PB(MP(T[i],i));
  SORT(L);
  
  ll cnt=0,NT[N+1];
  NT[0]=0;
  RREP(i,N){
    if(L[i].first>L[i-1].first) cnt++;
    NT[L[i].second]=cnt;
  }
  
  ll COUNT[N+1];
  REP(i,N+1) COUNT[i]=0;
  COUNT[0]=1;
  
  if(N<K){
    for(ll i=1; i<=N; ++i){
      ans+=COUNT[NT[i]];
      COUNT[NT[i]]++;
    }
  }
  else{
    for(ll i=1; i<=K-1; ++i){
      ans+=COUNT[NT[i]];
      COUNT[NT[i]]++;
    }
    for(ll i=K; i<=N; ++i){
      COUNT[NT[i-K]]--;
      ans+=COUNT[NT[i]];
      COUNT[NT[i]]++;
    }
  }
  
  co(ans);
  return 0;
}

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

typedef pair<int,int> pii;

int n,ma=0,kq[100001],den[100001];
vector<pii> a[100001];
set<int> col[100001];

void nhap()
{
    scanf("%d",&n);
    for (int i=1;i<n;++i)
    {
        int u,v;
        scanf("%d %d",&u,&v);
        a[u].push_back({v,i});
        a[v].push_back({u,i});
        den[u]++;
        den[v]++;
    }
}

void bfs()
{
    queue<int> q;
    q.push(1);
    while (!q.empty())
    {
        int u=q.front();
        q.pop();
        for (auto v:a[u])
        {
            if (den[v.first])
            {
                int cl=(*col[u].begin());
                col[u].erase(col[u].begin());
                auto j=col[v.first].lower_bound(cl);
                if (j!=col[v.first].end())
                    col[v.first].erase(j);
                kq[v.second]=cl;
                q.push(v.first);
                den[u]--;
                den[v.first]--;
            }
        }
    }
}

void process()
{
    for (int i=1;i<=n;++i)
    {
        int vs=a[i].size();
        ma=max(ma,vs);
        for (int j=1;j<=vs;++j)
            col[i].insert(j);
    }
    bfs();
    cout<<ma<<"\n";
    for (int i=1;i<n;++i)
        cout<<kq[i]<<"\n";
}

int main()
{
    nhap();
    process();
    return 0;
}


Measured memory_bytes: 21376
N = int(input())
X = list(map(int, input().split()))
p_list = [0]
for P in range(1,101):
    power = 0
    for i in range(N):
        power += (X[i] - P)**2
    p_list.append(power)
sp_list = sorted(p_list)
print(sp_list[1])

Measured memory_bytes: 3060
from queue import Queue

k = int(input())

q = Queue()

for i in range(9):
  q.put(i + 1)

for _ in range(k):
  x = q.get()
  residue = x % 10
  if residue != 0:
    q.put(10 * x + residue - 1)
  q.put(10 * x + residue)
  if residue != 9:
    q.put(10 * x + residue + 1)

print(x)

Measured memory_bytes: 12480
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,a,b;
    cin >> x >> a >> b;
    print((x - a) % b);
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstring>
using namespace std;
struct wo{
	int x;
	int y;
}a[100005];
int n,m;
int maxx,num;
int ans,ans1;
int cmp(wo b,wo c){
	return b.y>c.y;
}
int main() {
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) {
        scanf("%d%d",&a[i].x,&a[i].y);
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++){
    	if(a[i].x>maxx){
    		num=1;
    		maxx=a[i].x;
		}
	}
	for(int i=1;i<=n;i++){
		if(a[i].y>=maxx){
			ans++;
			m-=a[i].y;
			if(m<=0){
				printf("%d",ans);
				return 0;
			}
		}
	}
	printf("%d",ans+(m+maxx-1)/maxx);
    
    return 0;
}


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

int main(){
  int n, y;
  cin >> n >> y;
  int ans1 = -1, ans2 = -1, ans3 = -1;
  for(int i = 0 ; i <= n ; ++i){
    for(int j = 0 ; j <= n - i ; ++j){
      int k = n - i - j;
      if(i * 10000 + j * 5000 + k * 1000 == y){
        ans1 = i;
        ans2 = j;
        ans3 = k;
      }
    }
  }
  printf("%d %d %d\n", ans1, ans2, ans3);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
static int N = 200;

int main(){
    int G[N][N] = {{0}};
    int n, id, k, adj;
    cin >> n;

    for(int i=1;i<=n;i++){
        cin >> id >> k;
        for(int j=1;j<=k;j++) {
            cin >> adj;
            G[id][adj] = 1;
        }
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++) {
            if(j==1) cout << G[i][j];
            else cout << " " << G[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3276
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();
    int max_ab = Integer.max(a, b);
    int max_bc = Integer.max(b, c);
    int max = Integer.max(max_ab, max_bc);
    int result = max;
    for (int i = 0; i < k; i++) {
      result *= 2;
    }
    result = result + a + b + c - max;
    System.out.println(result);
  }
}

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

int main(){
    long double H,W;
    cin >> H >> W;
    cout << (H == 1 || W == 1 ? 1 : (long long)ceil(H * W / 2)) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,k;
    char a[1000000];
    while(gets(a))
 {
    k=strlen(a);
    if(k==1)
        puts(a);
    else
    for(i=0;i<k;i+=2)
    {
        printf("%c",a[i]);
    }
    printf("\n");
 }
return 0;
}


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

int main() {
   int H , A ;
  cin >> H >> A ; ;//敵の残り体力
  int x = 0 ;//攻撃回数
  while (H > 0 ){
    H -= A ;
    
    x += 1 ;
  }
  cout  << x << endl;
}



Measured memory_bytes: 256
/* -------------------------------- Template -------------------------------- */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

// template<typename T> constexpr T inf;
// template<> constexpr int inf<int> = 1e9;
// template<> constexpr ll inf<ll> = 1e18;
// template<> constexpr ld inf<ld> = 1e30;

struct yes_no : std::numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve();

int main() {
  std::locale loc(std::locale(), new yes_no);
  std::cout << std::boolalpha << std::setprecision(12) << std::fixed;
  std::cout.imbue(loc);
  solve();
  return 0;
}

using namespace std;

/* -------------------------------- Library -------------------------------- */

/* ---------------------------------- Main ---------------------------------- */

ll A[128000];
ll B[128000];

void solve() {
  ll N;
  cin >> N;
  vector<int> idx;
  REP(i,N) {
    if (i > 0) {
      string op;
      cin >> op;
      if (op == "-") idx.push_back(i);
    }
    cin >> A[i];
  }
  REP(i,N) B[i+1] = B[i] + A[i];

  ll sum = accumulate(A, A + N, 0LL);
  if (idx.empty()) {
    cout << sum << endl;
    return;
  }

  ll res = -1e18;
  ll dec = 0;
  REP(i,idx.size()-1) {
    chmax(res, sum - dec * 2 - (B[idx[i+1]] - B[idx[i]]) * 2);
    dec += A[idx[i]];
  }
  chmax(res, sum - dec * 2 - A[idx.back()] * 2);
  cout << res << endl;
}


Measured memory_bytes: 2296
#define inr register int
#define ll long long
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
ll read(){
	char a=getchar();ll c=0,b=1;
	while(a<'0'||a>'9'){if(a=='-')b=-1;a=getchar();}
	while(a>='0'&&a<='9')c=c*10+a-48,a=getchar();
	return c*b;
}
int main(){
	for(inr i=1;i<=3;i++){
		char a;
		cin>>a;
		if(a=='7'){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
const int Maxn = 100010;
const int Mod = 1e9+7;
int X[Maxn], Y[Maxn];
struct lnode {
	int x, y;
}list[Maxn]; int ll;
int b[Maxn], bl, c[Maxn], cl, p1[Maxn], p2[Maxn], f[Maxn];
int n, m;
vector <int> vec[Maxn];
int s[Maxn];
int lowbit(int x) { return x & (-x); }
void add(int x, int k) { while(x <= cl){ s[x] = (s[x]+k)%Mod; x += lowbit(x); } }
int qry(int x) { int ret = 0; while(x > 0){ ret = (ret+s[x])%Mod; x -= lowbit(x); } return ret; }
int main() {
	int i, j, k;
	scanf("%d%d", &n, &m);
	for(i = 1; i <= n; i++) scanf("%d", &X[i]);
	for(i = 1; i <= m; i++) scanf("%d", &Y[i]);
	int p = 0;
	for(i = 1; i <= n; i++){
		while(p+1 <= m && X[i] > Y[p+1]) p++;
		if(p != 0 && p != m){
			ll++;
			list[ll].x = X[i]-Y[p];
			list[ll].y = Y[p+1]-X[i];
			b[++bl] = list[ll].x;
			c[++cl] = list[ll].y;
		}
	}
	sort(b+1, b+bl+1);
	bl = unique(b+1, b+bl+1) - (b+1);
	sort(c+1, c+cl+1);
	cl = unique(c+1, c+cl+1) - (c+1);
	for(i = 1; i <= ll; i++) vec[lower_bound(b+1, b+bl+1, list[i].x) - b].push_back(lower_bound(c+1, c+cl+1, list[i].y) - c);
	int ans = 1;
	for(i = 1; i <= bl; i++){
		for(j = 0; j < vec[i].size(); j++){
			if(p1[vec[i][j]] != i){
				p1[vec[i][j]] = i;
				f[vec[i][j]] = qry(vec[i][j]-1)+1;
				ans = (ans+f[vec[i][j]])%Mod;
			}
		}
		for(j = 0; j < vec[i].size(); j++){
			if(p2[vec[i][j]] != i){
				p2[vec[i][j]] = i;
				add(vec[i][j], f[vec[i][j]]);
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}


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

int main() {
 int A, B = 0;
 int c1, c2 = 0;
  
 cin >> A >> B;

 c1 = (B - 1) / (A - 1);
 c2 = (B - 1) % (A - 1);

 if(c2 != 0) {
	c1++;
  }

 cout << c1 << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
using ll=long long;

int main(){
    ll N;
    cin >> N;
    ll sum = 0;
    ll dig;
    ll tmp = N;
    while(tmp){
        dig = tmp % 10;
        sum += dig;
        tmp /= 10;
    }
    
    if(N % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

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

const int MOD =1000000007;
//

signed main() {
 int a,b;
 cin>>a>>b;
 if(a>b)swap(a,b);
 int a0=a,b0=b;
 while(a!=0){
     b%=a;
     swap(a,b);
 }
 cout<<a0*b0/b;
 return 0;
}


Measured memory_bytes: 256
n=int(input())
s=input()
count=0
for i in range(n-2):
    if s[i]=="A":
        if s[i+1]=="B":
            if s[i+2]=="C":
                count=count+1
                i=i+3
            else:
                i=i+2
        else:
            i=i+1
print(count)

Measured memory_bytes: 3060
#include <cstdio>
#include <cmath>
using namespace std;
int a[100000];
int main(void) {
  int N, K, idx;
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; i++) {
    scanf("%d", a + i);
    if (a[i] == 1)
      idx = i;
  }

  // int a = ceil((idx) / (double)(K - 1));
  // int b;
  // if (idx == 0)
  //   b = ceil((N - 1) / (double)(K - 1));
  // else if (idx < K - 1)
  //   b = ceil((N - K) / (double)(K - 1));
  // else
  //   b = ceil((N - idx - 1) / (double)(K - 1));
  printf("%d\n", (int)ceil((N - 1) / (double)(K - 1)));
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

const bool CanAllEatInX(
    const LLONG x,
    const int N, const LLONG K, 
    const vector<int> &As, const vector<int> &Fs)
{
    LLONG shugyoNum = 0;
    for (int i = 0; i < N; ++i)
    {
        shugyoNum += max(As[i] - x / Fs[i], 0LL);
    }
    return shugyoNum <= K;
}

int main()
{
    int N;
    LLONG K;
    cin >> N >> K;
    vector<int> As(N), Fs(N);
    for (auto &Ai : As) cin >> Ai;
    for (auto &Fi : Fs) cin >> Fi;
    sort(As.begin(), As.end());
    sort(Fs.rbegin(), Fs.rend());
    LLONG min = -1LL, max = static_cast<LLONG>(1e18);
    while (max - min > 1)
    {
        auto x = (min + max) / 2;
        (CanAllEatInX(x, N, K, As, Fs) ? max : min) = x;
    }
    cout << max << endl;
}


Measured memory_bytes: 1920
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kishan Sairam Adapa
 */

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ll long long int
#define MOD ((int)(1e9) + 7)

class BMultiplication2 {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        using namespace std;
        int n;
        cin >> n;
        ll ans = 1;
        bool flag = false;
        while(n--) {
            ll tp;
            cin >> tp;
            if(ans == 0 || tp == 0) {
                ans = 0;
                flag = false;
                continue;
            }
            if(tp > 1000000000000000000 / ans) {
                flag = true;
            }
            if(flag) continue;
            ans *= tp;
        }
        if(flag)
            cout << "-1\n";
        else
            cout << ans << '\n';
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    BMultiplication2 solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3172
package main

import (
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		neg := false
		for ; '0' > b || b > '9'; b = rc() {
			if b == '-' {
				neg = true
			}
		}
		for ; '0' <= b && b <= '9'; b = rc() {
			x = x*10 + int(b&15)
		}
		if neg {
			return -x
		}
		return
	}
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}
	gcd := func(a, b int) int {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}
	const mod int = 1e9 + 7
	pow := func(n int) int {
		res, x := 1, 2
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return res
	}

	type pair struct{ x, y int }
	cntO := 0
	cnt := map[pair]int{}
	cnt2 := map[pair]int{}
	n := r()
	for i := 0; i < n; i++ {
		x, y := r(), r()
		if x == 0 && y == 0 {
			cntO++
			continue
		}
		if y < 0 {
			x = -x
			y = -y
		} else if y == 0 {
			x = abs(x)
		}
		g := gcd(abs(x), y)
		x /= g
		y /= g
		if x > 0 {
			cnt[pair{x, y}]++
		} else {
			cnt2[pair{y, -x}]++
		}
	}

	ans := 1
	for p, c := range cnt {
		ans = ans * (pow(c) + pow(cnt2[p]) - 1) % mod
		delete(cnt2, p)
	}
	for _, c := range cnt2 {
		ans = ans * (pow(c)) % mod
	}
	Fprint(_w, (ans+cntO-1+mod)%mod)
}

func main() { run(os.Stdin, os.Stdout) }


Measured memory_bytes: 16976
/*Program from Luvwgyx*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=4e3+10;
char s[10];int top,sta[maxn],ans[maxn];
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(int x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
void write(int x){print(x);puts("");}
void query(int x,int y){printf("? %d %d\n",x,y);fflush(stdout);scanf("%s",s);}
int main(){
    int a=read(),b=read(),n=a+b;
    if(a<=b){puts("Impossible");return 0;}
    for(int i=0;i<n;i++){
        if(!top)sta[++top]=i;
        else {
            query(sta[top],i);
            if(s[0]=='Y')sta[++top]=i;
            else top--;
        }
    }for(int i=0;i<n;i++){query(sta[top],i);if(s[0]=='Y')ans[i]=1;}
    printf("! ");for(int i=0;i<n;i++)printf("%d",ans[i]);puts("");
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define INF (int)1e8
#define EPS 1e-9

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
  int N;
  cin >> N;
  string res = "No";

  rep(i, 26) rep(j, 15) {
    if (4 * i + 7 * j == N) {
      res = "Yes";
      break;
    }
    if (res == "Yes") break;
  }

  cout << res << endl;
}

Measured memory_bytes: 256
/*input
667763461
*/
 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdint.h>
#include <tgmath.h>
 
using namespace std;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define ar array
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define tests int r; cin >> r; while(r--)
#define MP make_pair
#define PI acos(-1)
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
#define godspeed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
 
#define M(x) ((x)%(1000000007))
#define MAXN   100001  
 

std::vector<int> ans;

void factorize(long long n){
   
   int count = 0;
   while (!(n % 2)) {
      n/= 2;
      count++;
   }
   if (count)
      ans.push_back(count);
   for (long long i = 3; i <= sqrt(n); i += 2) {
      count = 0;
      while (n % i == 0) {
         count++;
         n = n / i;
      }
      if (count)
      	ans.push_back(count);
   }
   if (n > 2)
   	ans.push_back(1);
}






int main() {
 	int64 n;
 	cin>>n;
 	int64 g = floor(pow(n,.2));
 	int a = 0;
 	int b = 0;

 	for(int64 i = -2*g; i<=2*g;i++){
 		int64 p = pow(i,5);
 		int64 q = abs(p-n);


 		if(pow(floor(pow(q,.2)),5)==q){
 			a=i;
 			b = pow(q,.2);
 		}
 	}
 	if(pow(a,5)-pow(b,5)==n){
 		cout<<a<<" "<<b<<endl;
 	}
 	else{
 		b = -1*b;
 		cout<<a<<" "<<b<<endl;
 	}
 	
}



 


Measured memory_bytes: 4064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * 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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Butterfly solver = new Butterfly();
        try {
            int testNumber = 1;
            while (true)
                solver.solve(testNumber++, in, out);
        } catch (UnknownError e) {
            out.close();
        }
    }

    static class Butterfly {
        final int MAX = 1 << 16;
        long[] dp = new long[MAX];

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            if (N == 0) throw new UnknownError();
            Arrays.fill(dp, 0);
            for (int i = 0; i < N; i++) {
                int M = in.nextInt();
                long L = in.nextLong();
                int mask = 0;
                for (int j = 0; j < M; j++) {
                    int s = in.nextInt() - 6;
                    int e = in.nextInt() - 6;
                    for (int bit = s; bit < e; bit++) {
                        mask |= (1 << bit);
                    }
                }
                for (int bit = MAX - 1; bit >= 0; bit--) {
                    if ((bit & mask) == 0) {
                        dp[bit | mask] = Math.max(dp[bit | mask], dp[bit] + L);
                    } else {
                        dp[bit | mask] = Math.max(dp[bit | mask], dp[bit]);
                    }
                }
            }
            long ans = 0;
            for (int i = 0; i < MAX; i++) {
                ans = Math.max(ans, dp[i]);
            }
            out.println(ans);
        }

    }
}

Measured memory_bytes: 60532
#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,x,n) for(int i=x; i<(n); i++)
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main()
{
    int n;
    cin >> n;
    int a[n];
    REP(i,n){
    cin >> a[i];
    }
    int key = 0;
    REP(i, n)
    {
        if(a[i]!=i+1)
            key++;
        if(key>2)
            break;
    }

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

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
ll D;
ll p[10];
ll c[10];
ll G;
ll ans = 100000000;
int main() {
	cin >> D >> G;
	G /= 100;
	rep(i, 0, D) {
		cin >> p[i] >> c[i];
		c[i] /= 100;
	}
	rep(i, 1, 1 << D) {
		bitset<10> bset(i);
		ll num = 0;
		ll score = 0;
		rep(j, 0, D) {
			if (bset[j]) {
				score += (j+1) * p[j] + c[j];
				num += p[j];
			}
		}
		if (G > score) {
			urep(j, D-1, 0) {
				if (!bset[j] && G <= score + (j+1) * p[j]) {
					num += (G - score + (j+1) - 1) / (j+1);
					score += (j + 1) * p[j];
					break;
				}
			}
		}
		if (G <= score)
			ans = min(ans, num);
	}
	if (G <= D * (p[D - 1] - 1)) {
		ans = min(ans, (G + D - 1) / D);
	}
	cout << ans << endl;
	cin >> ans;
	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 2e5+7;
int n,sz[MAXN];
int main(){
    ____();
    cin >> n;
    for(int i = 2; i <= n; i++){
        int f; cin >> f;
        sz[f]++;
    }
    for(int i = 1; i <= n; i++) cout << sz[i] << endl;
    return 0;
}

Measured memory_bytes: 4388
/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
typedef unsigned long long ULL;
using namespace std;

const LL INF = 99999999999999;
const int inf = 999999999, maxn = 100 + 24;
int T;
struct P{
	string s;
	int score;
	bool operator < (const P & r) const {
		return s == r.s ? score > r.score : s < r.s;
	}
};

P h[maxn], u[maxn];

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	while(scanf("%d", &T) == 1) {
		for(int i = 0; i < T; i++) {
			cin >> h[i].s;
			u[i].s = h[i].s;
			scanf("%d", &h[i].score);
			u[i].score = h[i].score;
		}
		sort(h, h + T);
		for(int i = 0; i < T; i++) {
			int x;
			for(int j = 0; j < T; j++) {
				if(u[j].s == h[i].s && u[j].score == h[i].score) { x = j + 1; break;}
			}
			printf("%d\n", x);
		}
	}


	return 0;
}
/*
    input:
    output:
    modeling:
    methods:
    complexity:
    summary:
*/

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int F[45];
	F[0] = 1;
	F[1] = 1;
	int n;
	cin >> n;
	for (int i = 2; i <= n; i++) {
		F[i] = F[i - 1] + F[i - 2];
	}
	cout << F[n] << endl;
	return 0;
}

Measured memory_bytes: 1160
n = gets.chomp.to_i
a_arr = gets.chomp.split(" ").map(&:to_i)
b_arr = gets.chomp.split(" ").map(&:to_i)

sum_a = 0
sum_b = 0
count1 = 0
count2 = 0
(0..n-1).each do |i|
  sum_a += a_arr[i]
  sum_b += b_arr[i]
  if a_arr[i] > b_arr[i]
    count1 += a_arr[i] - b_arr[i]
  else
    count2 += ((b_arr[i] - a_arr[i]) / 2.to_f).ceil
  end
end
if sum_b - sum_a >= [count1, count2].max
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 15468
#include <iostream>
#include <algorithm>
#include <vector>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
	int i;
	ll n, s, d, a, kn, ks;
	vector<ll> v;

	scanf("%lld%lld", &n, &s);

	if (n <= s) {
		if (n == s) {
			printf("%lld\n", n + 1);
		}
		else {
			printf("-1\n");
		}
		return 0;
	}

	d = n - s;

	for (a = 1; a * a <= d; a++) {
		if (d % a == 0) {
			v.push_back(a);
			v.push_back(d / a);
		}
	}
	v.push_back(d);

	sort(v.begin(), v.end());

	for (i = 0; i < v.size(); i++) {
		kn = n;
		ks = 0ll;
		while (kn > 0) {
			ks += kn % (v[i] + 1);
			kn /= (v[i] + 1);
		}
		if (ks == s) {
			printf("%lld\n", v[i] + 1);
			return 0;
		}
	}

	printf("-1\n");

	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++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n;
    cin >> n;
    int x[n+1],y[n+1],t[n+1];
    x[0] = 0;y[0]=0;t[0]=0;
    rep(i,n)cin >> t[i+1] >> x[i+1] >> y[i+1];
    bool ans = true;
    rep(i,n){
        int time = t[i+1]-t[i];
        int x1 = abs(x[i+1]-x[i]);
        int y1 = abs(y[i+1]-y[i]);
        if(x1+y1 > time){
            ans = false;
            //cout << i << "f1" << endl;
        }
        if((x1+y1)%2 != time%2){
            ans = false;
            //cout << i << "f2" << endl;
        }
    }
    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define _abs(x)((x) < 0 ? (x) * -1 : (x))
#define _max(x, y)(max(0, max((x), (y))))
#define _min(x, y)(max(0, min((x), (y))))

static const ll MOD = 1e9 + 7;

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;

    cin >> s;
    
    if (s.size() < 4) cout << "No" << '\n';
    else if (s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') cout << "Yes" << '\n';
    else cout << "No" << '\n';

    return 0;
}


Measured memory_bytes: 256
import java.util.InputMismatchException;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		try {
			Scanner scanner = new Scanner(System.in);

			int a = scanner.nextInt();
			int b = scanner.nextInt();

			if ((a + b) % 2 == 0) {
				int answer = (a + b) / 2;
				System.out.println(answer);
			}else{
				System.out.println("IMPOSSIBLE");
			}
			scanner.close();

		} catch (InputMismatchException e) {
			// TODO: handle exception
			System.out.println("整数を入力してください");
		}
	}

}



Measured memory_bytes: 22740
#![allow(unused)]

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
//入力マクロここまで

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;

fn main() {
    input! {
        n: u64,
        a: u64,
        b: u64,
    }

    if a == 0 {
        println!("0");
        return;
    }

    let mut ans;
    ans = (n / (a + b)) * a;

    let r = n % (a + b);
    if r > a {
        ans += a;
    } else {
        ans += r;
    }

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/agc031_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  string S;
  cin >> S;

  map<char, int> m;
  rep(i, N) { m[S[i]]++; }

  mint ans = 1;
  for (auto kv : m) {
    ans *= (kv.second + 1);
  }

  cout << ans - 1 << endl;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn = 100005;
int a,b,c;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> a >> b >> c;
    if(c >= a && c <= b)
        cout << "Yes";
    else cout << "No";
    return 0;
}



Measured memory_bytes: 256
import itertools


n = int(input())
s = [input() for _ in range(n)]

m = 0
a = 0
r = 0
c = 0
h = 0

for i in range(len(s)):
    if s[i][0] == "M":
        m += 1
    if s[i][0] == "A":
        a += 1
    if s[i][0] == "R":
        r += 1
    if s[i][0] == "C":
        c += 1
    if s[i][0] == "H":
        h += 1

head_l = [m, a, r, c, h]
comb_l = list(itertools.combinations(head_l, 3))
ans = 0
for comb in comb_l:
    pat = comb[0]
    for i in range(1, len(comb)):
        pat *= comb[i]
    ans += pat
        
print(ans)
        

Measured memory_bytes: 9824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j) vector<vector<ll>> name(i,vector<ll>(j))
#define vec2f(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k)))
#define vec3f(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define vec4(name,i,j,k,l) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l))))
#define vec4f(name,i,j,k,l,m) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l,m))))
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    REP(i,n) cin >> a[i];
    ll xo = 0;
    FOR(i,2,n-1) xo=xo^a[i];
    ll s = a[0]+a[1];
    if ((s-xo)%2||s<xo||s-xo>2*a[0]){
        cout << -1 << endl;
        return 0;
    }
    ll ans = (s-xo)/2;
    if (ans&xo){
        cout << -1 << endl;
        return 0;
    }
    FORD(i,50,0) if ((xo>>i)%2&&(1ll<<i)+ans<=a[0]) ans=ans+(1ll<<i);
    if (ans==0) cout << -1 << endl;
    else cout << a[0]-ans << endl;
}

Measured memory_bytes: 3632
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    S = input().rstrip('\n')
    ans = 0
    cnt = 0
    for s in S:
        if s == "B":
            cnt += 1
        else:
            ans += cnt
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40048
from math import gcd
from functools import reduce

N, *A = map(int, open(0).read().split())

def f():
    t = [0] * (10 ** 6 + 1)
    for a in A:
        t[a] += 1

    c = 0
    for j in range(2, 10 ** 6 + 1, 2):
        c += t[j]
    if c > 1:
        return False

    for i in range(3, 10 ** 6 + 1, 2):
        c = 0
        for j in range(i, 10 ** 6 + 1, i):
            c += t[j]
        if c > 1:
            return False

    return True

if f():
    print('pairwise coprime')
elif reduce(gcd, A) == 1:
    print('setwise coprime')
else:
    print('not coprime')


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

typedef long long int llint;

int main()
{
  int ans = 0;
  int a[100001];
  int g[100001] = {};
  int k[100001] = {};
  int n;
  cin>> n;
  
  for(int i = 0; i < n; i++) {
    cin>> a[i];
    if(i % 2 == 0) g[a[i]]++;
    else k[a[i]]++;
  }

  int cntg = 0, mg;
  int cntk = 0, mk;
  
  for(int i = 0; i < n; i++) {
    if(i % 2 == 0) {
      if(cntg < g[a[i]]) {
	cntg = g[a[i]];
	mg = a[i];
      }
    } else {
      if(cntk < k[a[i]]) {
	cntk = k[a[i]];
	mk = a[i];
      }
    }
  }

  if(mg == mk) {
    g[mg] = 0;
    k[mk] = 0;
    int cntgg = 0;
    int cntkk = 0;
    for(int i = 0; i < n; i++) {
      if(i % 2 == 0) cntgg = max(cntgg, g[a[i]]);
      else cntkk = max(cntkk, k[a[i]]);
    }
    ans = n - max(cntg + cntkk, cntk + cntgg);
  } else {
    ans = n - cntg - cntk;
  }

  cout<< ans <<endl;

  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
#define ll long long
using namespace std;

int main(){
    int N;  string S;
    cin >> N >> S;
    vector<int> cntw(N,0), cntb(N,0);
    for(int i=0; i<N; i++){
        if(S[i]=='#') cntb[i]++;
        if(i>0) cntb[i]+=cntb[i-1];
    }
    for(int i=N-1; i>=0; i--){
        if(S[i]=='.') cntw[i]++;
        if(i<N-1) cntw[i]+=cntw[i+1];
    }

    int ans = N;
    for(int i=0; i<N; i++){
        if(S[i]=='#'){
            ans = min(ans, cntb[i]-1 + cntw[i]);
        }else{
            ans = min(ans, cntb[i] + cntw[i]+1);
        }
    }
    ans = min({ans, cntb[N-1], cntw[0]});
    cout << ans << endl;
}


Measured memory_bytes: 2180
#include <bits/stdc++.h>
using namespace std;
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep4(i, a, b, c) for (int i = int(a), i##__b = int(b), i##__c = int(c); i < i##__b; i += i##__c)
#define rep1(n) rep4(i, 0, n, 1)
#define rep2(i, n) rep4(i, 0, n, 1)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define REP(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep3(i, a, b) for (int i = int(b) - 1, i##__a = int(a); i >= i##__a; i--)
#define rrep1(n) rrep3(i, 0, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep4(i, a, b, c) for (int i = int(a + (b - a - 1) / c * c), i##__a = int(a), i##__c = int(c); i >= i##__a; i -= i##__c)
#define RREP(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define FOREACH(i, x) for (auto &i : x)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define print(x) cout << x << endl;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 9;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
template <class T> using vv = vector<vector<T>>;
// clang-format off
template <class T> bool chmax(T &a, const T &b) {if (a < b) {a = b;return 1;}return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b < a) {a = b;return 1;}return 0;}
// clang-format on


int main() {
    ll N;
    cin >> N;
    REP(h, 1, 3501) REP(n, 1, 3501) {
        ll bunbo = N * h * n, bunshi = 4 * h * n - N * (h + n);
        if (bunshi == 0) continue;
        if (bunbo % bunshi == 0) {
            ll w = bunbo / bunshi;
            if (w >= 0) {
                cout << h << " " << n << " " << bunbo / bunshi;
                return 0;
            }
        }
    }
    cerr << "end";
}

Measured memory_bytes: 256
N, A, B = gets.chomp.split.map(&:to_i)
S = gets.chomp

apply = A + B
b_count = 0
total = 0

N.times do |i|
	if S[i] == 'c'
		puts 'No'
	elsif S[i] == 'a' && total < apply
		total += 1
		puts 'Yes'
	elsif S[i] == 'b' && total < apply && b_count < B
		total += 1
		b_count += 1
		puts 'Yes'
	else
		puts 'No'
	end
end

Measured memory_bytes: 2428
#include <iostream>
//#include <map>
//#include <iterator>
//#include <fstream>
//#include <iomanip>
//#include <omp.h>
#include <vector>
//#include <string>
#include <algorithm>
//#include <stdlib.h>
//#include <thread>
//#include <chrono>
#include <cmath>
using namespace std;
typedef long long LL;
 
LL hp[100000];
int N, A, B, diff;
int* monsters;
int* countAttack;
 
bool isAttackCompleted(LL T)
{
	LL center = 0;
	for (LL i = 0; i < N; i++) {
		LL tmp = hp[i] - B*T;
		if (tmp > 0) {
			LL count = (tmp + (diff - 1)) / diff;
			center += count;
		}
	}
	return center <= T;
}
 
int main()
{
	cin >> N >> A >> B;
	diff = A - B;
 
	LL maxHp = 0;
	for (LL i = 0; i < N; i++)
	{
		cin >> hp[i];
		if (hp[i] > maxHp) maxHp = hp[i];
	}
 
	sort(hp, hp + N);
 
	LL left = 0;
	LL right = (maxHp + (B - 1)) / B + 1;
	LL mid;
	//int index;
	//int answer = 0;
	//vector<int> v;
	//chrono::milliseconds mil(1000);
	//std::chrono::system_clock::time_point  start, end;
	//start = std::chrono::system_clock::now();
	while (left + 1 < right)
	{
		mid = (left + right) / 2;
		bool flag = isAttackCompleted(mid);
		if (flag)
			right = mid;
		else
			left = mid;
		//this_thread::sleep_for(mil);
	}
	cout << right << endl;
	//end = std::chrono::system_clock::now();
	//double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
	//cout << "Time : " << elapsed << " [ms]\n";
	return 0;
}

Measured memory_bytes: 1024