akhauriyash/Code-Regression huggingface dataset:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, k = LI()
a = LI()
base = 1
for i in range(k, n):
    rate = a[i] / a[i-k]
    if rate > 1:
        ans = 'Yes'
    else:
        ans = 'No'
    print(ans)


Measured memory_bytes: 94184
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

vector<int> a[1000];
signed main(){
  int n, k = -1, cnt = 1;cin >> n;
  rrep(i,2*n)if(i*(i-1) == 2*n)k = i;
  if(k == -1){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  rep(i,k)repi(j,i+1,k){
    a[i].pb(cnt);
    a[j].pb(cnt);
    cnt++;
  }
  cout << k << endl;
  rep(i,k)cout << k-1 << " " << a[i] << endl;
  return 0;
}





Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k,x;
	cin>>k>>x;
	for(int i=x-k+1;i<=x;i++)
	cout<<i<<" ";
	for(int i=x+1;i<=x+k-1;i++)
	cout<<i<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
  int a,b,d;
 string c[10];
      
  cin >> a>>b;
   for(int i=0;i<a;i++){
    cin >>c[i];
   }
  
   for(int i=0;i<a;i++){
     
     for(int j=0;j<b;j++){
       
      
      if(c[i][j] == '#'){
         d ++;
      }
     }
   }
  if(d>a+b-1){
  cout << "Impossible" << endl;
}
  else{
    cout <<"Possible" << endl;
  }
}
         
       


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ll k,q;
  cin >> k >> q;
  vector<ll> vec(k);
  vector<ll> mov(k+1);
  vector<ll> sum_vec(k+1);
  rep(i,k){
    cin >> vec[i];
  }
  ll n,x,m;
  ll ans;
  rep(i,q){
    cin >> n >> x >> m;
    x %= m;
    ans = n-1;
    ll sum = 0;
    mov[0] = 0;
    sum_vec[0] = 0;
    REP(i,1,k+1){
      mov[i] = (mov[i-1] + vec[i-1] % m);
      if(vec[i-1] % m == 0){
        sum++;
      }
      if(mov[i] >= m){
        sum++;
        mov[i] %= m;
      }
      sum_vec[i] = sum;
    }
    n--;
    ans -= sum * (n / k);
    //cout << ans << endl;
    ans -= sum_vec[n%k];
    t1 = (n / k) * mov[k] + mov[n % k] + x;
    ans -= (t1 / m);
    cout << ans << endl;
  }
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
#include <stdio.h>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;

#define rep(i,N) for(int (i)=0; (i)<(N); (i)++)
#define revrep(i,N) for(int (i)=(N)-1; (i)>=0; (i)--)
#define dump(vec) for(int i = 0; i < (vec).size(); i++){cout << vec.at(i) << ",";}cout << endl

typedef long long ll;

int main(void)
{
    int N;

    cin >> N;
    vector<vector<pair<int,bool>>> A(N);
    rep(i,N){
        int a;
        cin >> a;
        rep(j,a){
            int x;
            bool y;
            cin >> x >> y;
            x--;
            A.at(i).push_back(make_pair(x,y));
        }
    }

    //rep(i,N){
    //    rep(j,A.at(i).size()){
    //        cout << "(" << A.at(i).at(j).first << "," << A.at(i).at(j).second << ")";
    //    }
    //    cout << endl;
    //}

    int ret = 0;
    for(ll u = 0; u < pow(2,N); u++){
        bool isMujun = false;
        vector<bool> S(N);
        rep(i,N){
            if(((u >> i) & 0x01) == 1) {
                S.at(i) = true;
            } else {
                S.at(i) = false;
            }
        }

        //rep(i,N){
        //    cout << S.at(i);
        //} cout << endl;

        rep(i,N){
            if (S.at(i) == false) continue;

            for(auto elem : A.at(i)){
                if (S.at(elem.first) == elem.second) {

                } else {
                    isMujun = true;
                    break;
                }
            }
        }

        if (!isMujun) {
            int ret_temp = 0;
            rep(i,N){
                if(S.at(i)) ret_temp++;
            }
            ret = max(ret, ret_temp);
        }
    }

    cout << ret << endl;

    return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	string s;
	int32 w;
	cin >> s >> w;
	REP(i, s.size()){
		if(i % w == 0){
			cout << s[i];
		}
	}
	cout << endl;
}

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

main()
{
    string s,t; cin>>s>>t;
    int a,b;
    string u;
    cin>>a>>b>>u;
    if(s==u) --a;
    else --b;
    cout << a << " " << b << "\n";

    // int k,n; cin>>n>>k;
    // vector<int> acc(n+1);
    // int ans{};
    // for(int i=1; i<=n; ++i)
    // {
    //     int p; cin>>p;
    //     acc[i]=acc[i-1]+p;
    //     if(i<k) continue;
    //     int tmp=acc[i]-acc[i-k];
    //     if(tmp>ans) ans=tmp;
    // }
    // cout << double(ans+k)/2 << "\n";
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  private static void solve(int L, int R, int d) {
    int res = 0;
    for (int i = L; i <= R; i++) {
      if (i % d == 0) {
        res++;
      }
    }
    System.out.println(res);
  }

  public static void main(String[] args) {
    int L = scanner.nextInt();
    int R = scanner.nextInt();
    int d = scanner.nextInt();
    solve(L, R, d);
  }

  private static final Scanner scanner = new Scanner(System.in);
}


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

int main(void){
    ll X,D,K;
    cin >> X >> K >> D;

    X = abs(X);
    ll MOD,WARI,ans = 0;
    WARI = X / D;
    MOD = X % D;
    if(WARI > K) ans = X - K*D;
    else{

        if((K-WARI) % 2 == 0 ){
            ans = MOD;
        }else ans = abs(MOD - D);
    }
    cout << abs(ans) << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};

const int mod = 1000000007;

signed main(){
    int h,w;
    cin>>h>>w;
    string s[55];
    for(int i=0;i<h;i++)cin>>s[i];
    int d[55][55];
    for(int i=0;i<55;i++){
        for(int j=0;j<55;j++){
            d[i][j]=mod;
        }
    }
    int cnt=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#')cnt++;
        }
    }
    queue<pair<pair<int,int>,int>> Q;
    Q.push(make_pair(make_pair(0,0),1));
    s[0][0]='#';
    while(!Q.empty()){
        auto p=Q.front();Q.pop();
        int y=p.first.first;
        int x=p.first.second;
        int di=p.second;
        d[y][x]=di;
        if(y==h-1&&x==w-1)break;
        for(int i=0;i<4;i++){
            int ny=y+dy[i];
            int nx=x+dx[i];
            if(ny<0||ny>=h||nx<0||nx>=w)continue;
            if(s[ny][nx]=='.'){
                s[ny][nx]='#';
                Q.push(make_pair(make_pair(ny,nx),di+1));
            }
        }
    }    
    cout<<max(h*w-cnt-d[h-1][w-1],-1LL)<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(){
    int i,j,l,dl,f=1,t;
    char s[131072];
    char d[4][8]={"remaerd","maerd","esare","resare"};
    scanf("%s\n",s);
    l = strlen(s);
    while(f){
        f = 0;
        for(i = 0;i < 4;i++){
            dl = strlen(d[i]);
            for(j = l-1;j > l-1-dl;j--){
                t = l-1-j;
                if(j < 0){break;}
                if(d[i][t] != s[j]){break;}
                if(j == l-dl){f=1;break;}
            }
            if(f){
                if(i == 0){l-=7;}
                if(i == 1){l-=5;}
                if(i == 2){l-=5;}
                if(i == 3){l-=6;}
                break;
            }
        }
        if(l == 0){printf("YES\n");return 0;}
    }
    printf("NO\n");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define endl "\n"
#define pi 3.14159265358979323846264338327950288
#define MOD 1000000007
#define INF -100000000000000
#define ordered_set tree<pair< ll int ,ll  int>, null_type,less<pair<ll int, ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define lld long double
using namespace __gnu_pbds;
int main()
{
    fast;
    ll int n;
    cin>>n;
    ll int a[n];ll int i;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        

    }ll int j,k,cnt=0;
    if(n<3)
    {
        cout<<0<<endl;
        exit(0);
    }
    sort(a,a+n);
    for(i=0;i<n-2;i++)
    {
        for(j=i+1;j<n-1;j++)
        {
            for(k=j+1;k<n;k++)
            {
                if(a[i]+a[j]>a[k] && a[i]!=a[j] && a[j]!=a[k])
                    cnt++;
            }
        }
        //cout<<i<<" "<<cnt<<endl;
    }
    cout<<cnt<<endl;
}


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

using namespace std;

#define endl '\n'


int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  vector <long long> vet(n);
  for(int i=0;i<n;i++)
    cin >> vet[i];

  sort(vet.begin(),vet.end());
  reverse(vet.begin(),vet.end());

  long long ans = 0;

  int i = 0;
  int players = 1;

  if(players < n){
    ans = vet[i++];
    players++;
    while(true){
      if(players >= n)
        break;
      ans+=vet[i];
      players++;
      if(players >= n)
        break;
      ans+=vet[i];
      players++;
      i++;
    }
  }


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

Measured memory_bytes: 4784
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	while(1)
	{
		int a,b,count,count2,k;
		cin >> a >> b;
		if(a==0&&b==0)break;
		vector<int> vec;
		for(int i=0;i<a;i++)
		{
			vec.push_back(i);
		}
		count=0;
		count2=0;
		for(int i=0;;i++)
		{
			if(i>=a)i%=a;
			if(vec[i]!=-1)count++;
			if(count==b)
			{
				vec[i]=-1;
				count=0;
				count2++;
			}
			if(count2==a-1)break;
			
		}
		for(int i=0;;i++)
		{
			if(vec[i]!=-1)
			{
				k=i;
				break;
			}
		}
		cout << vec[k]+1 << endl;
	}
	return 0;
}

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

int main()
{
    long long int k, a, b;
    cin >> k >> a >> b;
    long long int max = 1;
    if (b - a > 2)
    {
        while (max < a)
        {
            max++;
            k--;
        }
        max += k / 2 * (b - a) + k % 2;
    }
    else
    {
        max += k;
    }
    cout << max << endl;
}

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

#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
using namespace std;

int main() 
{	
	fast;
	ll x,y; cin>>x>>y;
	if(abs(x-y) <= 1) cout << "Brown" << endl;
	else cout << "Alice" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
int f[N],a[N],l,b[N],tot,ne[N],fi[N],zz[N],in[N],ans[N],n,m;
struct Tree{
	int l,r,num;
}T[N*4];
void up(int x){
	if (x==1)return;
	if (b[f[x]]<b[f[x/2]]){
		swap(f[x],f[x/2]);
		up(x/2);
	}
}
void down(int x){
	int i=x;
	if (x*2<=l&&b[f[x]]>b[f[x*2]])i=x*2;
	if (x*2<l&&b[f[i]]>b[f[x*2+1]])i=x*2+1;
	if (i!=x){
		swap(f[x],f[i]);
		down(i);
	}
}
void build(int x,int l,int r){
	T[x].l=l;T[x].r=r;T[x].num=n+1;
	if (T[x].l==T[x].r)return;
	int mid=(l+r)/2;
	build(x*2,l,mid);
	build(x*2+1,mid+1,r);
}
void insert(int x,int y,int z){
	T[x].num=min(T[x].num,z);
	if (T[x].l==T[x].r)return;
	int mid=(T[x].l+T[x].r)/2;
	if (y<=mid)insert(x*2,y,z);
	else insert(x*2+1,y,z);
}
int find(int x,int l,int r){
	if (T[x].l>r||l>T[x].r)return n+1;
	if (T[x].l>=l&&T[x].r<=r)return T[x].num;
	return min(find(x*2,l,r),find(x*2+1,l,r));
}
void jb(int x,int y){
	ne[++tot]=fi[x];
	fi[x]=tot;
	zz[tot]=y;
	in[y]++;
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)scanf("%d",&a[i]),b[a[i]]=i;
	build(1,1,n);
	for (int i=n;i;i--){
		int k1=find(1,b[i]-m+1,b[i]),k2=find(1,b[i],b[i]+m-1);
		if (k1<=n)jb(i,k1);
		if (k2<=n)jb(i,k2);
		insert(1,b[i],i);
	}
	for (int i=1;i<=n;i++)
		if (!in[i])f[++l]=i,up(l);
	for (int i=1;i<=n;i++){
		int k=f[1];f[1]=f[l--];down(1);
		ans[b[k]]=i;
		for (int j=fi[k];j;j=ne[j]){
			in[zz[j]]--;
			if (!in[zz[j]])f[++l]=zz[j],up(l);
		}
	} 
	for (int i=1;i<=n;i++)printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 48640
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
const int N=200000,inf=1000000000;
vector<vector<int>>pas(N);
vector<int>dp(N,inf);
int lis[N],a[N];
stack<P>update;
void dfs(int x,int before){
    int l=lower_bound(dp.begin(),dp.end(),a[x])-dp.begin();
    update.push({l,dp[l]});
    dp[l]=a[x];
    lis[x]=lower_bound(dp.begin(),dp.end(),inf)-dp.begin();
    for(int i=0;i<pas[x].size();i++)if(pas[x][i]!=before)dfs(pas[x][i],x);
    P reset=update.top();
    update.pop();
    dp[reset.first]=reset.second;
    return;
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    int v[n-1],u[n-1];
    for(int i=0;i<n-1;i++){
        cin>>v[i]>>u[i];
        pas[v[i]-1].push_back(u[i]-1);
        pas[u[i]-1].push_back(v[i]-1);
    }
    dfs(0,-1);
    for(int i=0;i<n;i++)cout<<lis[i]<<endl;
    return 0;
}

Measured memory_bytes: 31132
h, w = map(int, input().split())
board = ['#'*(w+2)]
for i in range(h):
    board.append('#'+input()+'#')
board.append('#'*(w+2))
flag = True
dy = [-1, 0, 0, 1]
dx = [0, -1, 1, 0]
for i in range(1, h):
    for j in range(1, w):
        if board[i][j] == '#':
            ok = False
            for k in range(4):
                if board[i+dy[k]][j+dx[k]] == '#':
                    ok = True
            if ok == False:flag = False
if flag == False:print("No")
else:print("Yes")

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;
ll mypow(ll x, ll n, ll m) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return mypow(x*x%m, n / 2, m);
	}
	else {
		return x * mypow(x, n - 1, m) % m;
	}
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

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


int main() {
	int n;
	cin >> n;
	ll sum = 0;
	for (ll i = 1; i <= n; ++i) {
		if (i % 3 !=0 && i % 5 != 0) {
			sum += i;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3652
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException {
		int hishi = 0;
		int tyou = 0;
		String check;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while((check=br.readLine()) != null) {
			String[] str = new String[3];
			str = check.split(",");
			int[] hen = new int[3];
			hen[0] = Integer.parseInt(str[0]);
			hen[1] = Integer.parseInt(str[1]);
			hen[2] = Integer.parseInt(str[2]);
			if(hen[0]*hen[0] + hen[1]*hen[1] == hen[2]*hen[2]) tyou++;
			if(hen[0] == hen[1] && (hen[0]+hen[1]>hen[2] || Math.abs(hen[0]-hen[1])<hen[2])) hishi++;
		}
		System.out.println(tyou +"\n" + hishi);
	}
}

Measured memory_bytes: 17044
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL a[1000010];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	LL n;
	cin>>n;
	for(LL i=1;i<=n;i++){
		cin>>a[i];
	}
	LL j=1,s=0,ans=0;
	for(LL i=1;i<=n;i++){
		while(j<=n&&s+a[j]==(s^a[j])){
			s+=a[j];
			j++;
			ans++;
		}
		s-=a[i];
		ans+=j-i-1;
	}
	cout<<ans<<endl;
	return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define MAX 1000000


ll  fastpower(ll a, ll n)
{
	ll res = 1;
	while(n > 0)
	{
		if(n % 2 != 0)
		{
			res = (res * a) % MOD;
		}
		n /= 2;
		a=(a * a) % MOD;
	}
	return res;
}

void getprime(vector<bool>&prime)
{
	prime[0] = false;
	prime[1] = false;
	
	for(ll i = 2;i <= MAX; i++)
	{
		if(prime[i])
		{
			for(ll j = i*i; j <= MAX; j += i)
				prime[j] = false;
		}
	}
}

void getfact(vector<ll> &fact, vector<ll> &ifact)
{
	fact[0] = 1;
	ifact[0] = 1;
	
	for(ll i = 1; i <= MAX; i++)
	{
		fact[i] = (fact[i-1] * i)%MOD;
		ifact[i] = (ifact[i-1] * fastpower(i, MOD -2) )%MOD;
	}
}
ll dx[4] = {0, 1, 0, -1};
ll dy[4] = {1, 0, -1, 0};

ll BFS(vector<string>&a, ll n, ll m, ll i, ll j)
{
  vector< vector<bool> >vis(n, vector<bool>(m, false));
  vector< vector<ll> >dis(n, vector<ll>(m, LLMX));
  queue< pair<ll, ll> >q;
  dis[i][j] = 0;
  q.push({i, j});
  vis[i][j] = true;
  ll res = 0;
  while(!q.empty())
  {
    pair<ll, ll>temp = q.front();
    ll x = temp.first;
    ll y = temp.second;
    q.pop();
    for(ll c=0;c<4;c++)
    {
      ll xd = x+dx[c];
      ll yd = y+dy[c];
      
      if(xd >= 0 && xd < n && yd >= 0 && yd < m && a[xd][yd] == '.' && !vis[xd][yd])
      {
        dis[xd][yd] = min(dis[xd][yd], dis[x][y]+1);
        res = max(res, dis[xd][yd]);
        vis[xd][yd] = true;
        q.push({xd, yd});
      }
    }
    
  }
  return res;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll n,m,k;
  string s;
  cin>>n>>m;
  vector<string>a(n);
  for(ll i=0;i<n;i++) cin>>a[i];
  ll res = LLMN;
  for(ll i=0;i<n;i++)
  {
    for(ll j=0;j<m;j++)
    {
      if(a[i][j] == '.')
      {
        res = max(res, BFS(a, n, m, i, j));
      }
    }
  }
  cout<<res;
  return 0;
}

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

void check(int A, int B, int K) {
    int sum = 0;
    // A+B>=K
    if (A + B >= K) {
        // trueならsum=A
        if(A<K) {
            sum = A;
        } else {
            sum = K;
        }
        cout << sum ;
        exit (0);
    } else {
        // falseなら次を実行
        // cからとる枚数を計算してsumに加える
        sum = A + ((( K - (A+B))) * (-1));
        cout << sum;
        exit (0);
    }
}

int main() {
    int A,B,C,K; 
    cin >> A >> B >> C >> K;
    check(A,B,K);
    return 0;
}

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

ld dp[305][305][305];

int main() {
  ll n;
  cin>>n;
  ll a[n],x=0,y=0,z=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]==1) x++;
    else if(a[i]==2) y++;
    else z++;
  }
  for(int k=0;k<=n;k++)
    for(int j=0;j<=n;j++)
      for(int i=0;i<=n;i++)
          dp[i][j][k]=0.0;
  ll i=0,j=0,k=0;
  ld val=0;
 // cout<<x<<" "<<y<<" "<<z<<"\n";
  for( k=0;k<=n;k++){
    for( j=0;j<=n;j++){
      for( i=0;i<=n;i++){
        //cout<<i<<" "<<j<<" "<<k<<"\n";
        if(i+j+k>n) continue;
        if(i+j+k==0) continue;
        else{
          dp[i][j][k]=n/(long double)(i+j+k);
          if(i>0) dp[i][j][k]+=(dp[i-1][j][k]*i)/(long double)(i+j+k);
          if(j>0) dp[i][j][k]+=(dp[i+1][j-1][k]*j)/(long double)(i+j+k);
          if(k>0) dp[i][j][k]+=(dp[i][j+1][k-1]*k)/(long double)(i+j+k);
        }
       // cout<<i<<" "<<j<<" "<<k<<"-->"<<dp[i][j][k]<<"\n";
      }
    }
  }
  cout<<fixed<<setprecision(10);
  cout<<dp[x][y][z]<<"\n";
}

Measured memory_bytes: 436724
N = int(input())

xy = [map(int,input().split()) for _ in range(N)]
x,y = [list(i) for i in zip(*xy)]

ans = 0
flag = False

for i in range(N):
    if x[i] == y[i]:
        ans +=1
    elif ans >= 3:
        flag = True
        ans = 0
    else:
        ans = 0
        
if ans >= 3  or flag ==True:
    print("Yes")
    
else:
    print("No")

Measured memory_bytes: 9200
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <stdlib.h>
#include <vector>
#include <numeric>
#include <unordered_map>

using namespace std;

class Queue {
   public:
   	int *array;
    int front, rear;
    int capacity;

	Queue(int size) {
     array = new int[size];
     front = rear = 0;
     capacity = size;
     int men = sizeof(array)/sizeof(array[0]);
     cout << men << "\n";
	} 
    void enqueue(int data);
    int peek();
    void dequeue();
    bool isEmpty();
    bool isFull();
    void print();
};

void Queue::enqueue(int data) {
	if(isFull()) {
       cout << "Queue is full, you cannot push an element!" << "\n";
	} else {

    array[rear] = data;
    rear++;

}
}

void Queue::dequeue() {

	if(isEmpty()) {
		cout << "there is no element to remove " << "\n";
	}
	else {
	    cout << "removing " << array[front] <<  "\n";
	    front = front + 1;
	}
}

bool Queue::isFull() {
	if(rear == capacity) {
		return true;

	}
	return false;
}
bool Queue::isEmpty() {
   if(front == 0 || front == rear) {
   	 return true;
   }
   return false;
}

void Queue::print()  {
	if(isEmpty()) {
		cout <<  " there is no element in the Queue " << "\n"; 
	} else {
	for(int i = front; i < rear; i++) {
		cout << array[i] << " ";
	}
	cout << "\n"; 
}
}

int main () {
 /*   Queue queue(10);
    queue.enqueue(10);
    queue.enqueue(20);
    queue.enqueue(30);
    queue.enqueue(40);
    queue.enqueue(50);
    queue.enqueue(60);
    queue.enqueue(70);
    queue.enqueue(80);

    queue.print();
    queue.print();
 */   
  /*
     vector<int> nums = {1, 1, 2, 2, 3, 4, 5, 5, 6};

     vector<pair<bool, int>> visited(nums.size());
     for(int i = 0; i < nums.size(); i++){
     	if(visited) {
     		visited = true;	
     	}
     }*/

    int h, w;
     cin >> h >> w;
     vector<vector<string>>  snuke(h, vector<string> (w));

     for(int i = 0; i < h; i++) {
     	for(int j = 0;  j < w; j++) {
     		cin >> snuke[i][j];
     	}
     }
   
   char alphaSet[26] = {'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'};   
     for(int i = 0; i < h; i++) {
     	for(int j = 0;  j < w; j++) {
         if(snuke[i][j] == "snuke") {
         	cout << alphaSet[j]  << i + 1 << "\n";
         	return 0;
         }
     	}
     }


	 return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,max=0,max1=0,q;
	cin>>n;
	int a[n];
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
		if (a[i]>max)
		{
			q=i;
			max=a[i];
			continue;
		}
		else if (a[i]>max1)
		{
			max1=a[i];
		}
	}
	for (int i=1;i<=n;i++)
	{
		if (i!=q)
		{
			cout<<max<<endl;
		}
		else
		{
			cout<<max1<<endl;
		}
	}
	return 0;
} 

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

using namespace std;

const int MAX_N = 504;

typedef long long ll;

ll MOD;
int N, U[MAX_N], L[MAX_N], ord[MAX_N];

int sq(int x) { return x * x; }

void init() {
    scanf("%d%lld", &N, &MOD);
    for (int i = 0; i < 2 * N; i++) {
        U[i] = 0;
        L[i] = 2 * N - 1;
        for (int j = 0; j < 2 * N; j++) {
            if (sq(i) + sq(j) >= sq(N) && sq(i) + sq(j) <= sq(2 * N)) {
                U[i] = max(U[i], j);
                L[i] = min(L[i], j);
            }
        }
    }
    pair<int, int> _ord[MAX_N];
    for (int i = 0; i < N; i++) {
        _ord[i] = make_pair(L[i] - 1, i);
    }
    for (int i = N; i < 2 * N; i++) {
        _ord[i] = make_pair(U[i], i);
    }
    sort(_ord, _ord + 2 * N, [](pair<int, int> a, pair<int, int> b) {
                                 if (a.first != b.first) return a.first < b.first;
                                 return a.second > b.second;
                             });
    for (int i = 0; i < 2 * N; i++) ord[i] = _ord[i].second;
}

ll F[MAX_N][MAX_N], ans;
void solve() {
    for (int m = 0; m <= N; m++) {
        memset(F, 0, sizeof(F));
        F[0][0] = 1;
        int fixed = 0;
        for (int i = 0; i < 2 * N; i++) {
            int x = ord[i];
            if (x < N) {
                for (int j = 0; j <= m; j++) {
                    (F[i + 1][j + 1] += F[i][j] * max(L[x] - fixed - j, 0)) %= MOD;
                    (F[i + 1][j] += F[i][j] * max(U[x] + 1 - i - (m - j) - (N - fixed), 0)) %= MOD;
                }
            } else {
                for (int j = 0; j <= m; j++) {
                    (F[i + 1][j] += F[i][j] * max(U[x] + 1 - fixed - j, 0)) %= MOD;
                }
                fixed++;
            }
        }
        (ans += (m & 1 ? MOD - 1 : 1) * F[2 * N][m]) %= MOD;
    }
    printf("%lld\n", ans);
}

int main() {
    init();
    solve();
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
bool isPrime(
    int n) { /* returns whether n is prime number or not * n should be in range
                [0, lim]. * to see detail, search 'Sieve of Eratosthenes' */
  static int lim = 1e6+1;
  static bool done = false;
  static vector<bool> isp(lim + 1, 1);
  if (!done) {
    isp[0] = isp[1] = false;
    for (int i = 2; i <= lim; i++) {
      if (isp[i]) {
        for (int j = i + i; j <= lim; j += i) {
          isp[j] = false;
        }
      }
    }
    done = true;
  }
  return isp[n];
}
int main() {
  int X;
  cin>>X;
  while(1){
    if(isPrime(X)){
      cout<<X<<endl;
      break;
    }
    X++;
  }

  return 0;
}


Measured memory_bytes: 384
n = int(input())
a = list(map(int,input().split()))
a1=0
m = [0]*n
for i in range(n):
    a1+=(-1)**i*a[i]
m[0]=str(a1)
for i in range(1,n):
    m[i]=str((a[i-1]-int(m[i-1])//2)*2)
print(' '.join(m))


Measured memory_bytes: 17228
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
constexpr int R=5e6+69, INF=2e9+6969;

int qq;

int main()
{
		string S,T;
		int a,b;
		string w;
		cin >> S >> T;
		cin >> a >> b;
		cin >> w;
		if(w==S) --a;
		else --b;
		cout << a<<" "<< b<<"\n";
	return 0;
}


Measured memory_bytes: 3620
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 1000 * 100 + 47;

int n;
int A[MAX];
vector<int> g[MAX];
vector<int> L[MAX];

void no()
{
	cout << "NO" << endl;
	exit(0);
}

LL dfs(int v, int p)
{
	if (SZ(g[v]) == 1 && v != 0) return A[v];
	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		if (to == p) continue;
		L[v].push_back(dfs(to, v));
	}

	LL s = 0;
	int maxx = -INF;
	FOR(i, 0, SZ(L[v]))
	{
		s += L[v][i];
		maxx = max(maxx, L[v][i]);
	}

	if (A[v] > s) no();
	LL all = s;
	if (maxx > s - maxx)
	{
		all = 2 * (s - maxx);
	}

	if (2 * (s - A[v]) > all) no();
	
	LL totop = s - 2 * (s - A[v]);
	if (v == 0)
	{
		if (SZ(g[v]) == 1 && A[v] != totop) no();
		if (SZ(g[v]) != 1 && totop != 0) no();
	}

	return totop;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	FOR(i, 0, n) cin >> A[i];
	FOR(i, 0, n - 1)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	dfs(0, 0);
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 20992
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 200005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int n,m,r;
  scanf("%d%d%d",&n,&m,&r);
  vi a(r);
  cin>>a;
  vvi dist(n,vi(n,INF));
  rep(i,m) {
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    --a; --b;
    mins(dist[a][b], c);
    mins(dist[b][a], c);
  }
  rep(i,n) dist[i][i] = 0;
  rep(k,n)rep(i,n)rep(j,n) mins(dist[i][j], dist[i][k]+dist[k][j]);
  sort(rng(a));
  int ans = INF;
  do {
    int now = 0;
    rep(i,r-1) {
      now += dist[a[i]-1][a[i+1]-1];
    }
    mins(ans,now);
  } while(next_permutation(rng(a)));
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 384
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
ABCABC
---+/
/+---test
C
---+/
/+---test
ABCACCBABCBCAABCB
---+/

void main(string[] args) {
  const S = readln.chomp.replace("BC", "D").splitter!(x => x == 'B' || x == 'C').array;

  long ans;
  foreach (S1; S) {
    long a_cnt;
    foreach (s; S1) {
      if (s == 'A') {
        ++a_cnt;
      } else {
        ans += a_cnt;
      }
    }
  }
  ans.writeln;
}


Measured memory_bytes: 4152
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string S;
    cin >> S;

    int N = S.length();
    int A_min = N;
    int Z_max = 0;

    for (int i = 0; i < N; i++){
        if(S[i] == 'A'){
            A_min = min(A_min, i);
        }
        else if(S[i] == 'Z'){
            Z_max = max(Z_max, i);
        }
    }

    if (Z_max - A_min <= 0){
        cout << 0 << endl;
    }
    else {
        cout << Z_max - A_min + 1<< endl;
    }
}

Measured memory_bytes: 640
from collections import Counter


def solve(V):
    n = len(V)
    ac = Counter(V[::2]).most_common(2)
    bc = Counter(V[1::2]).most_common(2)

    if ac[0][0] != bc[0][0]:
        return n - ac[0][1] - bc[0][1]
    else:
        if len(bc) == 1 or len(ac) == 1:
            return n // 2
        else:
            return n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])


if __name__ == "__main__":
    n = int(input())
    l = input()
    print(solve(l.split(" ")))


Measured memory_bytes: 16808
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

const int MAXN = 1e5;

int n, m;
vector<int> G[MAXN];
bool bio[MAXN];
int mem[MAXN];

int calc(int x) {
  if (bio[x]) return mem[x];
  bio[x] = 1;

  for (int i: G[x]) {
    mem[x] = max(mem[x], calc(i)+1);
  }

  return mem[x];
}

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--; y--;
    G[x].push_back(y);
  }

  int sol = 0;
  for (int i = 0; i < n; ++i) {
    if (bio[i]) continue;
    sol = max(sol, calc(i));
  }

  printf("%d\n", sol);
  return 0;
}



Measured memory_bytes: 7552
#include <stdio.h>

int main() {
    int n, x, m, min;
    scanf("%d %d", &n, &x);

    min = x;

    for(int i = 0; i < n; i++) {
        scanf("%d", &m);
        x -= m;
        if (min > m)
            min = m;
    }

    n += x / min;
    printf("%d\n", n);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
  int a , b, c;

  scanf("%d %d %d", &a, &b, &c);

  int n = c - (a - b);
  if (n < 0)
    printf("0\n");
  else
    printf("%d\n", n);

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std ;
int a[1000][1000], yoko[1000], tate[1000];
int main() {

	int r, c, goukei = 0;
	cin >> r >> c;
	for (int x = 0; x < r; x++) {
		for (int y = 0; y < c; y++) {
			tate[y] = 0;
			yoko[x] = 0;
		}
	}
	for (int x = 0; x < r; x++) {
		for (int y = 0; y < c; y++) {
			cin >> a[x][y];
			tate[y] += a[x][y];
			yoko[x] += a[x][y];
		}

	}
	for (int x = 0; x < r; x++) {
		goukei += yoko[x];
	}
	for (int x = 0; x < r; x++) {	
		for (int y = 0; y < c; y++) {
			cout << a[x][y] << ' ';
		}
		cout << yoko[x] << endl;

	}	

	for (int y = 0; y < c; y++) {
		cout << tate[y] << ' ';
	}
	cout << goukei << endl;
	return 0;
}


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

int main(){
 cout<<fixed<<setprecision(6);
 double r;
 cin >>r;

 double PI=acos(-1);//cos(π) = -1 ->acos(-1)=π
 double area=r*r*PI;
 double cir=(r+r)*PI;

 cout<<area<<" "<<cir<<endl;
 

}


Measured memory_bytes: 3224
N = int(input())
xl = [0] * N
for i in range(N):
  x, l = map(int ,input().split())
  a = x - l
  b = x + l
  xl[i] = [a, b]
  
xl = sorted(xl, key = lambda x:x[1])

ans = 0
now = 0
for i in range(N):
  if i == 0:
    ans += 1
    now = xl[0][1]
  else:
    if xl[i][0] >= now:
      ans += 1
      now = xl[i][1]
      
print(ans)
    
    
    

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

using ll = long long;

int main(){
  ll n,output=0;
  cin>>n;
  for(ll i=1;i<=n;i++){
    for(ll j=1;j<=n;j++){
      for(ll k=1;k<=n;k++){
        ll gcd = __gcd(i,__gcd(j,k));
        output+=gcd;
      }
    }
  }
  cout<<output;

}


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

const ll MOD = 1e9 + 7;

long long mod_pow(long long n, long long p, long long m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        long long t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    ans += mod_pow(10, n, MOD);
    ans -= 2 * mod_pow(9, n, MOD);
    ans %= MOD;
    ans += mod_pow(8, n, MOD);
    ans %= MOD;
    if (ans < 0) ans += MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3512
var
  a:array[0..102,0..102] of integer;
  n,m,i,j,t:longint;
  ch:char;
begin
  readln(n,m);
  for i:=1 to n do
   begin
     for j:=1 to m do
      begin
        read(ch);
        if ch='#' then a[i,j]:=1;
      end;
      readln;
   end;
  for i:=1 to n do
   begin
     for j:=1 to m do
      if a[i,j]=1 then write('#')
       else
        begin
          t:=a[i-1,j-1]+a[i-1,j]+a[i-1,j+1]+a[i,j-1]+a[i,j+1]+a[i+1,j-1]+a[i+1,j]+a[i+1,j+1];
          write(t);
        end;
     writeln;
   end;
end.


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = sc.next().split("");


		long r = 0;
		long g = 0;
		long b = 0;

		for (String str : s){
			if ( str.equals("R") ){
				r++;
			} else if ( str.equals("G") ) {
				g++;
			} else {
				b++;
			}

		}

		long total = r * g * b;

		long sum = 0;

		for ( int i = 0; i < n; i++){
			for ( int j = i+1; j < n; j++){

				if ( s[i].equals( s[j] ) ) continue;

				int k = j*2-i;

				if ( k >= n || s[k].equals( s[i] ) || s[k].equals( s[j] ) ) continue;

				sum++;

			}
		}
		System.out.println(total - sum);

	}

}


Measured memory_bytes: 36468
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    a,b,c=MI()
    if c-a-b>0 and 4*a*b<(c-a-b)**2:print("Yes")
    else:print("No")

main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
#define PI  acos(-1)
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  string S;cin>>S;
  int l=0,r=S.size()-1;
  int ans=0;
  while(l<r){
    if(S.at(l)==S.at(r)){
      l++;r--;
    } else {
      if(S.at(l)!='x'&&S.at(r)!='x'){
        // print(l,r);
        print(-1);
        re 0;
      } else{
        if(S.at(l)=='x'){l++;ans++;}
        if(S.at(r)=='x'){r--;ans++;}
      }
    }
  }
  print(ans);

}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	bool maze[2000][2000];
	memset(maze, false, sizeof(maze));

	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	rep(i, 0, tx - sx) cout << 'R';
	rep(i, 0, ty - sy) cout << 'U';
	cout << 'R';
	rep(i, 0, ty - sy + 1) cout << 'D';
	rep(i, 0, tx - sx + 1) cout << 'L';
	cout << 'U';
	cout << 'L';
	rep(i, 0, ty - sy + 1) cout << 'U';
	rep(i, 0, tx - sx + 1) cout << 'R';
	cout << 'D';
	rep(i, 0, tx - sx) cout << 'L';
	rep(i, 0, ty - sy) cout << 'D';
	cout << endl;
}


Measured memory_bytes: 4224