akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;cin>>k;
	cout<<arr[k-1]<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int n, x, i, j, k, s;
	while (1) {
		scanf("%d %d", &n, &x);
		s = 0;
		if (n == 0 && x == 0) {
			break;
		}
		for (i = 1; i <= n; i++) {
			for (j = 1; j <= n; j++) {
				for (k = 1; k <= n; k++) {
					if (i == j || i == k || j == k ) {

					}
					else {
						if (i + j + k == x) {
							s += 1;
						}
					}
				}
			}
		}
		printf("%d\n",s/6);
	}

	return 0;
}


Measured memory_bytes: 2148
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TemplateAlgorithm
{
    class Program
    {
        public const long Inf = (long)1e18;
        public const double eps = 1e-6;
        public const string alfa = "abcdefghijklmnopqrstuvwxyz";
        public const string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        public const int MOD = 1000000007;


        static void Main(string[] args)
        {
            int n = IO.ReadInt();
            var a  = IO.ReadIntArr();

            int count = 0;
            for (var i = 1; i < n-1; i++)
            {
                if (a[i - 1] < a[i] && a[i] < a[i + 1]) count++;
                else if (a[i - 1] > a[i] && a[i] > a[i + 1]) count++;
            }
            WriteLine(count);
        }

        static int ToInt(char c) => c - '0';

        #region MIN,MAX

        /// <summary>
        /// 最大値を返す
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="vals"></param>
        /// <returns></returns>
        public static T MaxValue<T>(params T[] vals) => vals.Max();

        /// <summary>
        /// 最小値を返す
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="vals"></param>
        /// <returns></returns>
        public static T MinValue<T>(params T[] vals) => vals.Min();
        #endregion
    }

    #region IO

    /// <summary>
    /// IO
    /// </summary>
    public class IO
    {
        public static string ReadStr(bool isTrim = false) => (isTrim) ? ReadLine().Trim() : ReadLine();
        public static int ReadInt() => int.Parse(ReadStr());

        public static long ReadLong() => long.Parse(ReadStr());

        public static decimal ReadDecimal() => decimal.Parse(ReadStr());
        public static double ReadDouble() => double.Parse(ReadStr());
        public static string[] ReadStrArr(char separator = ' ') => ReadLine().Split(separator);
        public static int[] ReadIntArr() => Array.ConvertAll(ReadStrArr(), int.Parse);
        public static long[] ReadLongArr() => Array.ConvertAll(ReadStrArr(), long.Parse);

        public static decimal[] ReadDecimalArr() => Array.ConvertAll(ReadStrArr(), decimal.Parse);
        public static double[] ReadDoubleArr() => Array.ConvertAll(ReadStrArr(), double.Parse);

        public static void Cout<T>(T value) => WriteLine(value);
        public static void CoutJoin<T>(T[] values, string separator = " ") => Cout(string.Join(separator, values));
    }

    #endregion    
}


Measured memory_bytes: 11092
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define MOD 998244353
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

int main(){
  int a,b,c,d; cin >>a >>b >>c >>d;
  c-=a; d-=b;
  vector<vector<li>> dp(c+1,vector<li>(d+1,1));
  rep(i,c){
    dp[i+1][0]=dp[i][0]*b%MOD;
  }
  rep(j,d){
    dp[0][j+1]=dp[0][j]*a%MOD;
  }
  if(df) rep(i,c+1) print(dp[i]);
  rep(i,c) rep(j,d){
    li ret=dp[i][j+1]*(b+j+1)%MOD+dp[i+1][j]*(a+i+1)%MOD-dp[i][j]*(a+i)*(b+j)%MOD;
    ((ret%=MOD)+=MOD)%=MOD;
    dp[i+1][j+1]=ret;
  }
  print(dp[c][d]);
}


Measured memory_bytes: 73744
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {

ll cnt(ll n,ll x) {
  ll res=0;
  rep(i,0,n) {
    res+=i*(-max(x-i,(ll)0));
    res+=(n-i)*(max(x-i,(ll)0));
  }
  res+=x;
  return res;
}

int main(void) {
  ll MOD=pow(10,9)+7;
  int n,k;cin>>n>>k;
  pr((cnt(n,n+1)-cnt(n,k-1))%MOD);
  return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<cmath>
#define pi 3.141592654
int main()
{
    int a,b,x;
    double ans;
    scanf("%d%d%d",&a,&b,&x);
    if (2*x<=a*a*b)
        ans=atan(1.0*a*b*b/2/x)/pi*180;
    else
        ans=atan((2.0*a*a*b-2*x)/a/a/a)/pi*180;
    printf("%lf",ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int N;
	string S;
	cin >> N >> S;

	vector<int> w(N, 0);
	
	if (S[0] == '.') {
		w[0] = 1;
	}
	for (int i = 1; i < N; ++i) {
		w[i] = w[i - 1];
		if (S[i] == '.') {
			w[i] += 1;
		}
	}

	auto numW = [&](int l, int r) {
		if (r < l) {
			return 0;
		}
		int n = w[r];
		if (l > 0) {
			n -= w[l - 1];
		}
		return n;
	};

	auto numB = [&](int l, int r) {
		if (r < l) {
			return 0;
		}
		return (r - l + 1) - numW(l, r);
	};

	int ans = N;
	for (int x = 0; x <= N; ++x) {
		int tmp = numB(0, x - 1) + numW(x, N - 1);
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1412
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;

int gcd(int a, int b) {
    int c=a%b;
    while(c) {
        a=b;
        b=c;
        c=a%b;
    }
    return b;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    while(cin>>a>>b) {
        int g=gcd(a, b);
        int l=a/g*b;
        cout<<g<<' '<<l<<'\n';
    }
    return 0;
}



Measured memory_bytes: 3120
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007LL
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define N			100006
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
	ll n,i,j,x,y;
	cin>>n;
	vector<pii>v;
	for(i=0;i<n;i++){
		cin>>x>>y;
		v.pb(mp(y,x));
	}
	sort(all(v));
	ll sum=0;
	for(i=0;i<n;i++){
		if(v[i].S+sum>v[i].F){
			cout<<"No";return 0;
		}
		sum+=v[i].S;
	}
	cout<<"Yes";
}

Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste

// #include "UnionFind.hpp"
// #include "power.hpp"

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    vector<int> cumulative = {0};
    int now = 1;
    int count = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == (char) ('0' + now)) ++count;
        else {
            cumulative.push_back(count);
            now = (now != 1);
            count = 1;
        }
    }
    if (count != 0) cumulative.push_back(count);
    if (cumulative.size() % 2 == 1) cumulative.push_back(0);
    for (int i = 1; i < cumulative.size(); i++) {
        cumulative[i] = cumulative[i] + cumulative[i - 1];
    }
    int ans = 0;
    for (int i = 0; i < cumulative.size(); i+= 2) {
        ans = max(ans, cumulative[min(i + (2 * K) + 1, (int) cumulative.size() - 1)] - cumulative[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1528
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m,i,j,k,x[100005],y[100005],ans;
bool tag[405];
int main()
{
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;++i)
		scanf("%d%d",x+i,y+i);
	for(i=1;i<n;++i)
		for(j=i+1;j<=n;++j)
		{
			for(k=1;k<=n;++k)
				tag[k]=false;
			tag[i]=tag[j]=true;
			for(k=m;k>=1;--k)
			{
				if(tag[x[k]]&&tag[y[k]])
					break;
				if(tag[x[k]]||tag[y[k]])
					tag[x[k]]=tag[y[k]]=true;
			}
			if(k<1)
				++ans;
		}
	printf("%d",ans);
	return 0;
}


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

ll MOD = 1e9 + 7;
ll powMod[100010];
void calc() {
  powMod[0] = 1;
  rep1(i, 100005) {
    powMod[i] = powMod[i - 1] * 3 % MOD;
  }
}

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

  S = "_" + S;
  int N = S.size();
  calc();

  vector<ll> A(N, 0), C(N, 0), Q(N, 0);
  rep(i, 1, N) {
    A[i] = A[i - 1];
    C[i] = C[i - 1];
    Q[i] = Q[i - 1];
    if (S[i] == 'A') A[i]++;
    if (S[i] == 'C') C[i]++;
    if (S[i] == '?') Q[i]++;
  }

  ll ans = 0;
  rep0(i, N - 1) {
    ll temp = 0, ac = 0;
    if (S[i] == 'B' || S[i] == '?') {
      ll la = A[i - 1];
      ll lq = Q[i - 1];
      ll rc = C[N - 1] - C[i];
      ll rq = Q[N - 1] - Q[i];

      ac = la * rc % MOD;
      if (ac != 0) temp = (temp + ac * powMod[lq + rq]) % MOD;

      ac = lq * rc % MOD;
      if (ac != 0) temp = (temp + ac * powMod[lq - 1 + rq]) % MOD;

      ac = la * rq % MOD;
      if (ac != 0) temp = (temp + ac * powMod[lq + rq - 1]) % MOD;

      ac = lq * rq % MOD;
      if (ac != 0) temp = (temp + ac * powMod[lq - 1 + rq - 1]) % MOD;
    }
    ans = (ans + temp) % MOD;
  }

  cout << ans << BR;
  return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define rep(i,l,r)  for(int i=l;i<=r;i++)
#define pre(i,r,l)  for(int i=r;i>=l;i--)
#define pii pair<int,int>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const int maxn = 1000005;
inline int read(){
    int x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=x*10+c-'0';
    return x*f;
}


int main(){
   int a = read(), b = read();
   if(a <= b) puts("unsafe");
   else  puts("safe");
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define inf 1<<30
#define mp make_pair
using namespace std;

class State{
public:
  int x,y,t,cost;
  State(int x,int y,int t,int cost):x(x),y(y),t(t),cost(cost){};
  bool operator<(State s)const{
    return s.cost<cost;
  }
};

int X[6]={0,1,1,0,-1,-1};
int Y1[6]={1,0,-1,-1,-1,0};
int Y2[6]={1,1,0,-1,0,1};
int sx,sy,gx,gy,n,x,y,lx,ly;

bool in(int x,int y){
  if(x<-lx || y<-ly || lx<x || ly<y)return false;
  return true;
}

int main()
{
  set<pair<int,int> > s;
  cin>>sx>>sy>>gx>>gy;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x>>y;
    s.insert(mp(x,y));
  }
  cin>>lx>>ly;

  priority_queue<State> pq;
  pq.push(State(sx,sy,0,0));
  //            x   y    t    cost
  map<pair<pair<int,int>,int>,int> M;
  M[mp(mp(sx,sy),0)]=0;
  int ans=-1;

  while(!pq.empty()){
    State u=pq.top();
    pq.pop();
    int ind=abs(u.x*u.y*u.t)%6;
    //cout<<u.x<<" "<<u.y<<" "<<u.t<<" "<<u.cost<<endl;
    if(u.x==gx && u.y==gy){
      ans=u.cost;
      break;
    }

    if(M[mp(mp(u.x,u.y),u.t)]<u.cost)continue;

    for(int i=0;i<6;i++){
      int nx=u.x+X[i],ny=u.y,nt=(u.t+1)%6,ncost=u.cost;
      if(u.x%2==0)ny+=Y1[i];
      else ny+=Y2[i];
      if(i!=ind)ncost++;
      if(!in(nx,ny))continue;
      if(s.find(mp(nx,ny))!=s.end())continue;
      pair<pair<int,int>,int> ppp=mp(mp(nx,ny),nt);
      if(M.find(ppp)==M.end()){
	M[ppp]=ncost;
	pq.push(State(nx,ny,nt,ncost));
      }
      else if(ncost<M[ppp]){
	M[ppp]=ncost;
	pq.push(State(nx,ny,nt,ncost));
      }
    }
    pair<pair<int,int>,int> ppp=mp(mp(u.x,u.y),(u.t+1)%6);    
    if(M.find(ppp)==M.end()){
      M[ppp]=u.cost+1;
      pq.push(State(u.x,u.y,(u.t+1)%6,u.cost+1));
    }
    else if(u.cost+1<M[ppp]){
      M[ppp]=u.cost+1;
      pq.push(State(u.x,u.y,(u.t+1)%6,u.cost+1));
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 16052
#include <iostream>

using namespace std;
int main() {
    int N, L;
    cin >> N >> L;
    int orig = 0;
    int minV, minI = -1;
    for (int i=0; i<N; i++) {
        int v = L + (i+1) - 1;
        orig += v;
        int absV = (v < 0) ? (-v) : v;
        if (minI == -1 || minV > absV) {minV = absV; minI = i;}
    }
    orig -= L + (minI+1) - 1;
    cout << orig << endl;
    return 0;
}



Measured memory_bytes: 256
s = int(input())
apple = []
count = 0

def func_1(a):
    a = int(a)
    if a % 2 == 0:
        return int(a / 2)
    else:
        return int(3 * a + 1)

while s not in apple:
    apple.append(s)
    s = func_1(s)
    count += 1
else:
    print(count + 1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, sum = 0;
  cin >> N;
  for(int i = 0; i < N; i++)
  {
    int start, end;
    cin >> start >> end;
    sum += end - start + 1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new ABC127().SolveA(new ConsoleInput(Console.In, ' '));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
  class ABC127
    {
    	public void SolveA(ConsoleInput cin)
        {
            var a = cin.ReadInt;
            var b = cin.ReadInt;
            if (a <= 5) WriteLine(0);
            else if (a <= 12) WriteLine(b / 2);
            else WriteLine(b);
            ReadLine();
        }
    }
}


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

int main() {

  string S, T;
  cin >> S >> T;

  map<int, int> countS;
  for (int i = 0; i < S.size(); i++) {
    countS[S[i] - 'a']++;
  }

  vector<int> countS_;
  for (auto item: countS) {
    countS_.push_back(item.second);
  }

  map<int, int> countT;
  for (int i = 0; i < T.size(); i++) {
    countT[T[i] - 'a']++;
  }

  vector<int> countT_;
  for (auto item: countT) {
    countT_.push_back(item.second);
  }

  sort(countS_.begin(), countS_.end());
  sort(countT_.begin(), countT_.end());

  if (countS_ == countT_) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;

}

Measured memory_bytes: 776
def max(a,b,c):
    if a >= b and a >= c:
        return a
    if b >= a and b >= c:
        return b
    else:
        return c

def min(a,b,c):
    if a <= b and a <= c:
        return a
    if b <= a and b <= c:
        return b
    else:
        return c

def mid(a,b,c):
    if (b-a)*(c-a) <= 0:
        return a
    if (a - b) * (c - b) <= 0:
        return b
    else:
        return c


s = input()
s = s.split()
n = []

for i in s:
    n.append(int(i))

a = n[0]
b = n[1]
c = n[2]

print(min(a,b,c),mid(a,b,c),max(a,b,c))


Measured memory_bytes: 5600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int people = sc.nextInt();
		long anser = 0;
		long max =  1000000000000000000l;
		int[] hp = new int[people];
		for(int num = 0 ; num <people; num++) {
			hp[num] = sc.nextInt();
		}
		//座標場所で一番最小のところ。
			for(int num = 0; num < 100; num++) {
				//最小を探すために毎回初期化
				anser = 0;
				for(int i = 0 ; i < people; i++) {
					//(x-p)2乗　公式
					//住人の座標-開催場所の座標
					anser +=(hp[i]-num) * (hp[i]-num);
				}
				if(max > anser) {
					max = anser;
				}
			}
		System.out.println(max);

	}
}


Measured memory_bytes: 21844
#include <stdio.h>

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

    int i, j;

    int a[100][100];
    int b[100];
    int c[100] = { 0 };
    
   
    for (i = 0; i < n; i++) 
    {
        for (int j = 0; j < m; j++) 
        {
            scanf("%d", &a[i][j]);
        }
    }

    for (i = 0; i < m; i++) 
    {
        scanf("%d", &b[i]);
    }

    for (i = 0; i < n; i++) 
    {
        for (j = 0; j < m; j++) 
        {
            c[i] = c[i] + (a[i][j] * b[j]);
        }
    }
    

    for (i = 0; i < n; i++) 
    {
        printf("%d\n", c[i]);
    }
    
    return 0;
}


Measured memory_bytes: 2124
object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  sc.useDelimiter("\n")
  val N = sc.nextInt()
  val L = sc.next().split(' ').map(_.toInt).toList
  var ans = 0
  // パターンを列挙
  for {i <- 0 until N - 2
       j <- i + 1 until N - 1
       k <- j + 1 until N} {
    val max = L(i).max(L(j)).max(L(k))
    // 条件に合うか
    if (L(i) != L(j) && L(i) != L(k) && L(j) != L(k) && max < L(i) + L(j) + L(k) - max) {
      ans += 1
    }      
  }
  println(ans)
}

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

int main() {
  int N;
  cin >> N;
  long long power10 = 1;
  for (int i = 0; i < N; i++){
    power10 *= 10;
    power10 %= 1000000007;
  }
  long long power9 = 1;
  for (int i = 0; i < N; i++){
    power9 *= 9;
    power9 %= 1000000007;
  }
  long long power8 = 1;
  for (int i = 0; i < N; i++){
    power8 *= 8;
    power8 %= 1000000007;
  }
  
  long long ans = 1000000007 + power10 - power9;
  ans %= 1000000007;
  ans = ans - power9 + 1000000007;
  ans %= 1000000007;
  ans += power8;
  ans %= 1000000007;
  cout << ans << endl;
}



Measured memory_bytes: 3624
#include<iostream>
#include<queue>

using namespace std;

int main(){
  int a,b;
  
  cin >> a >> b;
  int m, n;
  priority_queue<int> q;
  for (int i =0;i<a;i++){
    cin >> m;    
	for (int j =0;j<m;j++){
      cin >> n;
      q.push(n);
    }
  }
  int s = 100000;
  int count = 1;
  int result =0;
  while(!q.empty()){
    if(s == q.top()){
      count++;
    }else{
      if (count == a){
        result++;
      }
      count =1;
    }
    s = q.top();
    q.pop();
  }
  if (count == a){
    result++;
  }
  if (a == 1){
    result--;
  }
  cout <<result<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
long long int x[10000],n,sum;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x[i];
		sum=sum+x[i];
	}
	sort(x,x+n);
	cout<<x[0]<<" "<<x[n-1]<<" "<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1256
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

import java.util.*;
import java.io.*;
import static java.lang.System.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		if(sc.nextInt() < sc.nextInt()){
			out.println("0");
		}
		else{
			out.println("10");
		}
	}
}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class E
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		int M = GetInt();
		var ans = new List<string>();
		if(N % 2 == 1)
		{
			for(int l = 1, r = N - 1; l < r; l++, r--)
				ans.Add($"{l} {r}");
		}
		else
		{
			bool flag = false;
			for(int l = 1, r = N - 1; l < r; l++, r--)
			{
				if(!flag && (r - l <= N / 2))
				{
					r--;
					flag = true;
				}
				ans.Add($"{l} {r}");
			}
		}
		WriteLine(string.Join("\n", ans.Take(M)));
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

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


int main() {

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    if (s[k-1] == 'A') s[k-1] = 'a';
    else if (s[k-1] == 'B') s[k-1] = 'b';
    else s[k-1] = 'c';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
import math
N, K = map(int, input().split())
chance = 0
for i in range(1,N+1):
    temp = i
    counter = 0
    if(i<K):
        while(True):
            temp *= 2
            counter += 1
            if(temp >= K):
                break
    chance += ((1/N)*math.pow(1/2,counter))
print(chance)

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

using namespace std;

int main() {
    int x=10;
    int y=25;
    int z=x+y;
    cin>>x>>y;
    vector<int> v(y);
    z=0;
    for(int i=0;i<y;i++)
   { cin>>v[i];
    z+=(v[i]);
   }
    if(z>=x)
    cout<< "Yes";
    else
    cout<<"No";
}

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

int n, q;
int main() {
  cin >> n;
  
  long sum = 0;
  map<long, long> mp;
  for (int i = 0; i < n; ++i) {
    long a;
    cin >> a;
    ++mp[a];
    sum += a;
  }
  
  cin >> q;
  for (int k = 0; k < q; ++k) {
    long a, b;
    cin >> a >> b;
    long p = mp[a];
    mp[a] = 0;
    mp[b] += p;
    sum += p * (b - a);
    cout << sum << endl;
  }
}

Measured memory_bytes: 9288
#include <utility>
#include <vector>
#include <iostream>
#include <cstdlib>
#include<bits/stdc++.h>
#include <limits>
#include <set>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef long long ll;
using namespace std;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int a[N];
    int numFree = 0;
    set<int> ranks;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        if(a[i] < 3200){
            ranks.insert(a[i]/400);
        }else{
            numFree++;
        }
    }
    int min = ranks.size();
    if(min == 0){
        min =1;
    }
    int max = ranks.size() + numFree;
    cout << min << " " << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 200000
int main(){

  int i,j,n;
  int data[N];
  int res,max_i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&data[i]);
  }

  max_i=1;
  for(i=2;i<n;i++){
    if(data[max_i]<data[i]){
      max_i=i;
    }
  }
  res=data[1]-data[0];
  for(i=0;i<n-1;i++){
    if(max_i==i){
      max_i++;
      for(j=i+1;j<n;j++){
	if(data[max_i]<data[j]){
	  max_i=j;
	}
      }
      if(res<data[max_i]-data[i]){
	res=data[max_i]-data[i];
      }
    }
    else{ 
      if(res<data[max_i]-data[i]){
	res=data[max_i]-data[i];
      }
    }
  }
  printf("%d\n",res);
  return 0;
}
  



Measured memory_bytes: 2576
#include <bits/stdc++.h>
#define N 125
using namespace std;

const int mod = 1000000007;

int n, G;
int a[N];
int f[2][N][N], (*cur)[N] = *f, (*nxt)[N] = f[1];

inline void add(int &x, const int y) {x = (x + y >= mod ? x + y - mod : x + y);}
	
int main() {
	int i, j, k, v, le, re, c, ans = 0;
	scanf("%d", &n); G = (n << 1) - 1;
	for (i = 1; i <= G; ++i) scanf("%d", a + i);
	sort(a + 1, a + (G + 1));
	nxt[0][0] = 1;
	for (i = n; i > 1; --i) {
		swap(cur, nxt); memset(nxt, 0, sizeof *f);
		le = (a[i] != a[i - 1]); re = (a[G - i + 1] != a[G - i + 2]);
		for (j = 0; j <= n - i << 1; ++j)
			for (k = 0; k <= n - i << 1; ++k)
				if (c = cur[j][k]) {
					add(nxt[j + le][k + re], c); // forward
					for (v = 0; v < j + le; ++v) add(nxt[v][k + 1 + re], c); // right
					for (v = 0; v < k + re; ++v) add(nxt[j + 1 + le][v], c); // left
				}
	}
	for (i = 0; i <= G; ++i)
		for (j = 0; j <= G; ++j)
			add(ans, nxt[i][j]);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
#define vcin(a)                          \
    for (int i = 0; i < (a).size(); i++) \
        cin >> (a)[i];

int main()
{
    int N;
    cin >> N;
    vint A(N), B(N), C(N);
    rep(i, N)
    {
        cin >> A[i];
    }
    sort(all(A));
    int idx1 = 1, idx2 = N - 1;
    rep(i, N)
    {
        if (i == 0)
        {
            B[N / 2] = A[0];
        }
        else if (i % 4 == 1 or i % 4 == 2)
        {
            if (i % 2 == 1)
            {
                B[N / 2 - (i / 2 + 1)] = A[idx2--];
            }
            else
            {
                B[N / 2 + (i / 2)] = A[idx2--];
            }
        }
        else
        {
            if (i % 2 == 1)
            {
                B[N / 2 - (i / 2 + 1)] = A[idx1++];
            }
            else
            {
                B[N / 2 + (i / 2)] = A[idx1++];
            }
        }
    }
    idx1 = 0;
    idx2 = N - 2;
    rep(i, N)
    {
        if (i == 0)
        {
            C[N / 2] = A[N - 1];
        }
        else if (i % 4 == 1 or i % 4 == 2)
        {
            if (i % 2 == 1)
            {
                C[N / 2 - (i / 2 + 1)] = A[idx1++];
            }
            else
            {
                C[N / 2 + (i / 2)] = A[idx1++];
            }
        }
        else
        {
            if (i % 2 == 1)
            {
                C[N / 2 - (i / 2 + 1)] = A[idx2--];
            }
            else
            {
                C[N / 2 + (i / 2)] = A[idx2--];
            }
        }
    }
    ll sum1 = 0, sum2 = 0;
    rep(i, N - 1)
    {
        sum1 += abs(B[i + 1] - B[i]);
        sum2 += abs(C[i + 1] - C[i]);
    }
    cout << max(sum1, sum2);
    return 0;
}

Measured memory_bytes: 1408
from sys import stdin
import math

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

ave = math.ceil(sum(li)/n)
ave2 = sum(li)//n

point = 0
point2 = 0

for i in li:
    point += (ave-i)**2
    point2 += (ave2-i)**2

print(min(point,point2))

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10 ** 5 + 10)
mod = 10 ** 9 + 7

# フィボナッチ数列
fib_memo = {}
def fib(N):
    if N < 2: return 1
    if N not in fib_memo:
        fib_memo[N] = fib(N-1) + fib(N-2)
    return fib_memo[N]

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

tmp_list = [0] * (M+1)
now_kaidan = 0
for i in range(M):
    tmp_list[i] = (A[i] - 1) - now_kaidan
    now_kaidan = A[i] + 1
tmp_list[-1] = N-now_kaidan
ans = 1

for v in tmp_list:
    if v == -1:     # 壊れた階段が連続している時は0移動方法がない
        print(0)
        exit()
    ans *= fib(v)
    ans %= mod

print(ans%mod)

Measured memory_bytes: 544360
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()


a, b = LI()
guchi = 1
ans = 0
while guchi < b:
    guchi += a - 1
    ans += 1
print(ans)


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.length()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>())
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////
	int a,b,c;
	cin >> a >> b >> c;
	cout << min({a+b,b+c,a+c}) <<endl;

	
//////////////////////////////////////////////
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
bool judge(int x)
{
	int count=0;
	for(int i=1;i*i<=x;i++)
	{
		if(x%i==0)
		{
			count+=2;
		}
	}
	if(count==8)
	{
		return 1;
	}
	else return 0;
}
int main() 
{
	int N,count;
	while(cin>>N)
	{
		count=0;
		for(int i=1;i<=N;i+=2)
		{
			if(judge(i)==1)
			{
				count++;
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

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

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

int main(){

    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    for (int i=0; i<h; i++) cin >> a[i];

    // 多点スタート
    // スタートから0距離で到達できる場合には距離配列に0を格納
    vector<vector<int>> dist(h, vector<int>(w, -1));
    queue<pair<int, int>> que;
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (a[i][j] == '#') {
                dist[i][j] = 0;
                que.push(pair<int, int>(i,j));
            }
        }
    }

    while(!que.empty()) {
        auto cur = que.front();
        que.pop();
        for (int i=0; i<4; i++) {
            int nx = cur.first + dx[i];
            int ny = cur.second + dy[i];
            if (nx<0 || nx>=h || ny<0 || ny>=w) continue;
            if (dist[nx][ny]==-1) {
                que.push(pair<int, int>(nx, ny));
                dist[nx][ny] = dist[cur.first][cur.second] + 1;
            }
        }
    }

    int res = 0;
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            res = max(res, dist[i][j]);
        }
    }
    
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 17032
#include<stdio.h>

int selectionSort(int A[], int N) {
int i, j, t, sw=0, minj;
for ( i = 0; i < N - 1; i++ ) {
minj = i;
for ( j = i; j < N; j++ ) {
if ( A[j] < A[minj] ) minj = j;
}
t = A[i]; A[i] = A[minj]; A[minj] = t;
if ( i != minj ) sw++;
}
return sw;
}

int main() {
int A[100], N, i, sw;

scanf("%d", &N);
for ( i = 0; i < N; i++ )
scanf ("%d", &A[i]);
sw = selectionSort(A, N);
 for ( i = 0; i < N; i++ ) {
if ( i > 0 )  printf(" ");
printf("%d", A[i]);

}
printf("\n");
printf("%d\n", sw);

return 0;
}


Measured memory_bytes: 2056
n=int(input())
a = [int(i) for i in input().split() if i!="1"]

if 0 in a:
    print(0)
else:
    ans=1
    for aa in a:
        ans=ans*aa
        if ans>10**18:
            print(-1)
            break
    else:
        print(ans)

Measured memory_bytes: 88148
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var nh=arr.shift();
   if(nh=="0 0")break;
   nh=nh.split(" ").map(Number);
   var n=nh[0];
   var h=nh[1];
   var obj={};
   for(var i=0;i<h;i++){
      var ary=arr.shift().split(" ");
      var x=ary[0];
      var a=ary[1]-0;
      var b=ary[2]-0;
      if(x=="xy"){for(var j=1;j<=n;j++)obj[a+","+b+","+j]=true;}
      else if(x=="xz"){for(var j=1;j<=n;j++)obj[a+","+j+","+b]=true;}
      else if(x=="yz"){for(var j=1;j<=n;j++)obj[j+","+a+","+b]=true;}
   }
   console.log(n*n*n-Object.keys(obj).length);
}

Measured memory_bytes: 52928
# https://atcoder.jp/contests/arc071/submissions/6325840

from itertools import accumulate

convert = {'A': 1, 'B': 2}
S = tuple(convert[x] for x in input())
T = tuple(convert[x] for x in input())
# 最速:   convert
# 次点:   *A, = map()
# 最下位: A = tuple(map())

acc_s = (0,) + tuple(accumulate(S))
acc_t = (0,) + tuple(accumulate(T))

ans = []
Q = int(input())
for _ in range(Q):
    sl, sr, tl, tr = map(int, input().split())
    # 添え字-1は変数再代入しない方が20ms速い
    ans.append('YES' if (acc_t[tr] - acc_t[tl - 1]) % 3 == (acc_s[sr] - acc_s[sl - 1]) % 3 else 'NO')

print(*ans, sep='\n')
# 逐次printだと1000ms
# 一括だと500ms


Measured memory_bytes: 15772
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double PI = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

int main(){
    string s;
    cin >> s;
    string ans = string();
    bool flag = true;
    for(int i = 0; i <= ('z'-'a'); i++){
        char c = 'a' + i;
        ans = c;
        for(int j = 0; j < s.length(); j++){
            if(s[j] == c){
                flag = false;
                ans = "None";
                break;
            }
        }
        if(flag) break;
        flag = true;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
using namespace std;
typedef struct{
    char value;
    int flag;
}sq;
sq field[102][102];
int dir[]={-1,1};
void tick(int i,int j,int n,int m,char c){
    for(int d=0;d<2;d++){
        if(field[i+dir[d]][j].value==c&&field[i+dir[d]][j].flag==0){
            field[i+dir[d]][j].flag=1;
            tick(i+dir[d],j,n,m,c);
        }
        if(field[i][j+dir[d]].value==c&&field[i][j+dir[d]].flag==0){
            field[i][j+dir[d]].flag=1;
            tick(i,j+dir[d],n,m,c);
        }
    }
}
int main(void){
    int n,m,pond=0;
    cin>>n>>m;
    while(n!=0){
        for(int i=1;i<n+1;i++) for(int j=1;j<m+1;j++){
            cin>>field[i][j].value;
            field[i][j].flag=0;
        }
        for(int i=1;i<n+1;i++) for(int j=1;j<m+1;j++){
            if(field[i][j].flag==0){
                tick(i,j,n,m,field[i][j].value);
                pond++;
            }
        }
        cout<<pond<<endl;
        for(int i=0;i<102;i++) for(int j=0;j<102;j++){
            field[i][j].value='-';
            field[i][j].flag=0;
        }
        pond=0;
        cin>>n>>m;
    }
    return 0;
}


Measured memory_bytes: 3956
//It is made by Awson on 2018.1.28
    #include <set>
    #include <map>
    #include <cmath>
    #include <ctime>
    #include <queue>
    #include <stack>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <complex>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define LL long long
    #define dob complex<double>
    #define Abs(a) ((a) < 0 ? (-(a)) : (a))
    #define Max(a, b) ((a) > (b) ? (a) : (b))
    #define Min(a, b) ((a) < (b) ? (a) : (b))
    #define Swap(a, b) ((a) ^= (b), (b) ^= (a), (a) ^= (b))
    #define writeln(x) (write(x), putchar('\n'))
    #define lowbit(x) ((x)&(-(x)))
    using namespace std;
    const int N = 100;
    void read(int &x) {
        char ch; bool flag = 0;
        for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
        for (x = 0; isdigit(ch); x = (x<<1)+(x<<3)+ch-48, ch = getchar());
        x *= 1-2*flag;
    }
    void write(int x) {
        if (x > 9) write(x/10);
        putchar(x%10+48);
    }
     
    int n, f[N+5][2], a[N+5][2];
     
    void work() {
        read(n);
        for (int i = 0; i <= 1; i++) for (int j = 1; j <= n; j++) read(a[j][i]);
        for (int i = 1; i <= n; i++) f[i][0] = f[i-1][0]+a[i][0];
        for (int i = 1; i <= n; i++) f[i][1] = Max(f[i-1][1], f[i][0])+a[i][1];
        writeln(f[n][1]);
    }
    int main() {
        work(); return 0;
    }

Measured memory_bytes: 256
use std::io;

fn main() {
    let (a, b, c) = input();
    let mut v = [a, b, c];
    v.sort();

    println!("{} {} {}", v[0], v[1], v[2]);
}

fn input() -> (i32, i32, i32) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");

    let mut iter = s.trim().split_whitespace();

    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();
    let c: i32 = iter.next().unwrap().parse().unwrap();

    (a, b, c)
}



Measured memory_bytes: 5028
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);


// ===

const MOD: i64 = 1000000007;

fn main() {
    let s: String = read();
    let s: Vec<u8> = s.into_bytes();
    let n = s.len();

    let mut pow3 = vec![1; n+10];
    for i in 1..pow3.len() {
        pow3[i] = pow3[i-1] * 3 % MOD;
    }

    let abc = [b'A', b'B', b'C', b'?'];

    let mut prev = vec![vec![0; 4]; n+1];
    let mut next = vec![vec![0; 4]; n+1];
    for i in 0..n {
        for j in 0..4 {
            let pa = if s[i] == abc[j] { 1 } else { 0 };
            let pb = if s[n-1-i] == abc[j] { 1 } else { 0 };
            prev[i+1][j] += prev[i][j] + pa;
            next[i+1][j] += next[i][j] + pb;
        }
    }

    let mut sum = 0;
    for i in 1..n-1 {
        let mut sharp = prev[n][3] as usize;
        if s[i] == b'B' {
        } else if s[i] == b'?' {
            sharp -= 1;
        } else {
            continue;
        }
        let aa = prev[i][0];
        let ax = prev[i][3];
        let cc = next[n-1-i][2];
        let cx = next[n-1-i][3];
        let mut add = 0;

        // *_*
        if ax >= 1 && cx >= 1 {
            add += ax * cx % MOD * pow3[sharp-2] % MOD;
        }

        // a_* or *_c
        if ax >= 1 || cx >= 1 {
            add += ((aa * cx) + (ax * cc)) % MOD * pow3[sharp-1] % MOD;
        }

        // a_c
        add += aa * cc % MOD * pow3[sharp] % MOD;

        sum += add;
        sum %= MOD;
    }

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


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll mod = 998244353;
ll N;
ll a[500];
ll sum;

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

    cin >> N;
    for (int i = 0;i < N;i++){
        cin >> a[i];
        sum += a[i];
    }

    ll dp[301][90000]; memset(dp,0LL,sizeof(dp));
    dp[0][0] = 1LL;

    for (int i = 0;i < N;i++){
        for (int j = 0;j <= sum;j++){
            if(dp[i][j] == 0) continue;
            dp[i][j] %= mod;
            dp[i+1][j] += dp[i][j]*2;
            dp[i+1][j+a[i]] += dp[i][j];
        }
    }

    ll ans = 1;
    for (int i = 0;i < N;i++){
        ans *= 3;
        ans %= mod;
    }
    ll cnt = 0;

    for (int i = (sum+1)/2;i <= sum;i++){
        cnt += dp[N][i]%mod;
        cnt %= mod;
    }
    
    cnt = (cnt*3)%mod;
    ans = ans+mod-cnt;
    ans %= mod;
    
    if(sum%2 == 0){
        memset(dp,0LL,sizeof(dp));
        dp[0][0] = 1;
        for (int i = 0;i < N;i++){
            for (int j = 0;j <= sum;j++){
                if(dp[i][j] == 0) continue;
                dp[i][j] %= mod;
                dp[i+1][j] += dp[i][j];
                dp[i+1][j+a[i]] += dp[i][j];
            }
        }
        ans += (dp[N][sum/2]%mod)*3;
        ans %= mod;
    }

    cout << ans << endl;

    return 0;

}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i < S.size(); i++)
  {
    if (i == 0)
      ans += S[i] - '0' - 1;
    else
      ans += 9;
  }
  int res = 0;
  for (int i = 0; i < S.size(); i++)
  {
    res += S[i] - '0';
  }
  cout << max(res, ans) << endl;
  return 0;
}


Measured memory_bytes: 256
import math
a, b, c = map(float, input().split())
c = math.radians(c)
L = a + b + (math.sqrt(a*a + b*b - 2*a*b*math.cos(c)))
S = (a * b * math.sin(c)) / 2
H = (2*S)/a

print(f"{S}\n{L}\n{H}")



Measured memory_bytes: 5700
#include<bits/stdc++.h>
using namespace std;
int n;
long long f[87];
int main()
{
    cin>>n;
    f[0]=2;
    f[1]=1;
    for(int i=2;i<=n;i++)
        f[i]=f[i-1]+f[i-2];
    cout<<f[n];
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var t string
	fmt.Scan(&t)

	res := make([]string, 1000000)
	tmp := ""
	for i := len(t)-1; i >= 0 ; i-- {
		tmp = t[i :i+1]

		if tmp == "?" {

			if i == len(t)-1 {
				res[i] = "D"
			}else if i == 0 {
				if res[i+1] == "D" {
					res[i] = "P"
				} else {
					res[i] = "D"
				}
			
			} else {
				if t[i-1:i] == "P" {
					res[i] = "D"
				} else if res[i+1] == "D" {
					res[i] = "P"
				} else if t[i-1:i] == "?"{
					res[i] = "D"
				} else {
					res[i] = "D"
				}
					

				
				
			} 

		} else {
			res[i] = tmp
		}
	}

	

	fmt.Println(strings.Join(res, ""))
}

Measured memory_bytes: 7364
#pragma GCC optimize("Ofast")
#include<iostream>
#include<string>

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

int a[200000],n,b;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    REP(i,n){cin>>a[i];b^=a[i];}
    REP(i,n){cout<<(a[i]^b)<<"\n";}
    return 0;
}

Measured memory_bytes: 4332
h,w = map(int, input().split())

li = [list(input().split()) for _ in range(h)]

alpha = [chr(i) for i in range(65, 65+26)]

for i in range(h):
    for j in range(w):
        if li[i][j] == 'snuke':
            print(alpha[j] + str(i+1))

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
   string s;
   cin>>s;
   int a=s[0]-'0';
   int b=s[1]-'0';
   int c=s[2]-'0';
   int d=s[3]-'0';
   if(a*10+b<=12&&a*10+b>0&&(c*10+d==0||c*10+d>12))
   {
             cout<<"MMYY"<<endl;
   }
   else if((a*10+b>12||a*10+b==0)&&(c*10+d<=12&&c*10+d>0))
   {
    cout<<"YYMM"<<endl;
   }
   else if(a*10+b<=12&&c*10+d<=12&&a*10+b>0&&c*10+d>0)
    cout<<"AMBIGUOUS"<<endl;
   else cout<<"NA"<<endl;

 
   //cout<<a<<endl; 
}
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a[100005];
int main(){
	//freopen("in.txt","r",stdin);
    long long n;
    cin>>n;
    long long sum = 0;
    for(long long i=0;i<n;i++) {
    	long long x;
    	cin>>x;
    	a[x]++;
    	sum+=x;
	}
	long long q;
	cin>>q;
	for(long long i=0;i<q;i++){
		long long t,y;
		cin>>t>>y;
		sum+=((y-t)*a[t]);
		
		cout<<sum<<endl;
		a[y]+=a[t];
		a[t] = 0;
		
	}
    return 0;
}

Measured memory_bytes: 4284
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int m=0;
  int c=0;
  for(int i=0;i<n;i++){
    int h;
    cin>>h;
    if(m<=h){
      c++;
      m=h;
    }
  }
  cout<<c<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <map>
#include <iostream>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <iterator>
#include <array>
typedef long long int ll;
using namespace std;
#define maxN 1000005
#define mod 1000000007

ll all[maxN]= {};
int n;
string s;
void solve() {
	
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	map<string,bool>ss;
	int ans=0;
	for(int i=0;i<n;i++){
		cin>>s;
		if(ss[s]==false){
			ss[s]=true;
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 19180