akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {

    public static void main(String[] args) throws IOException {
        ReaderC.init(System.in);
        int n = ReaderC.nextInt();
        long m = 0, a = 0, r = 0, c = 0, h = 0;
        for (int i = 0; i < n; i++) {
            String name = ReaderC.next();
            if (name.charAt(0) == 'M') m++;
            else if (name.charAt(0) == 'A') a++;
            else if (name.charAt(0) == 'R') r++;
            else if (name.charAt(0) == 'C') c++;
            else if (name.charAt(0) == 'H') h++;
        }

        long ans = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h;
        System.out.println(ans);
    }
}

/**
 * Reader class based on the article at "https://www.cpe.ku.ac.th/~jim/java-io.html"
 */
class ReaderC {
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    static void init(InputStream inputStream) {
        reader = new BufferedReader(new InputStreamReader(inputStream));
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    //    Get a whole line.
    static String line() throws IOException {
        return reader.readLine();
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
}



Measured memory_bytes: 34936
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
using namespace std;
int aa[10];
int a,b,c,d;
signed main()
{
	rep(i,4){
		cin>>aa[i];
		if(aa[i]==1){
			a++;
		}elif(aa[i]==4){
			b++;
		}elif(aa[i]==7){
			c++;
		}elif(aa[i]==9){
			d++;
		}
	}
	if(a==1&&b==1&&c==1&&d==1){
		cout<<"YES";
	}else{
		cout<<"NO";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

/*
    vector<long long> a(n) を座圧する場合 :
    auto v = compress(a);
    auto m = dict(v);
    i番目の要素の取り出し方 :
    m[a[i]]
*/
template <typename T>
vector<T> compress(vector<T> vec) {
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

template <typename T>
map<T, int> dict(vector<T>& vec) {
    map<T, int> res;
    for (int i = 0; i < (int)vec.size(); i++) {
        res[vec[i]] = i;
    }
    return res;
}

/*
    1-indexed であることに注意 !!
*/
template <typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n) : n(n), dat(n + 1, 0) {}

    T sum(int a) {
        T res = 0;
        for (int i = a; i > 0; i -= (i & (-i))) res += dat[i];
        return res;
    }

    T sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }

    void add(int k, T x) {
        if (k == 0) return;
        for (int i = k; i <= n; i += (i & (-i))) dat[i] += x;
    }

    /*
        a[0] + a[1] + ... + a[res] >= x
    */
    int lower_bound(T x) {
        if (x <= 0) return T(0);
        int res = 0, k = 1;
        while (k < n) k <<= 1;
        for (; k > 0; k >>= 1) {
            if (res + k <= n && dat[res + k] < x) {
                x -= dat[res + k];
                res += k;
            }
        }
        return res + 1;
    }
};

signed main() {
    int n;
    ll k;
    cin >> n >> k;
    ll a[n];
    rep(i, n) {
        cin >> a[i];
        a[i] -= k;
    }
    rep(i, n - 1) {
        a[i + 1] += a[i];
    }
    vector<ll> v;
    v.emplace_back(0);
    rep(i, n) {
        v.emplace_back(a[i]);
    }
    auto c = compress(v);
    auto m = dict(c);
    ll ans = 0;
    BIT<int> bit(m.size() + 1);
    bit.add(m[0] + 1, 1);
    rep(i, n) {
        ans += bit.sum(0, m[a[i]] + 1 + 1);
        bit.add(m[a[i]] + 1, 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 18160
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    ll x,y,z,k;cin>>x>>y>>z>>k;
    vll a(x),b(y),c(z);
    rep(i,x)cin>>a[i];
    rep(i,y)cin>>b[i];
    rep(i,z)cin>>c[i];
    sort(all(a));reverse(all(a));
    sort(all(b));reverse(all(b));
    sort(all(c));reverse(all(c));
    ll L=0;ll R=3e10+1;ll M,l,r,m,tmp,sum;
    while(R-L>1){
        M=(L+R)/2;
        sum=0;
        rep(i,x)rep(j,y){
            l=-1;r=z;
            tmp=a[i]+b[j];
            while(r-l>1){
                m=(l+r)/2;
                if(tmp+c[m]<M)r=m;
                else l=m;
            }
            sum+=l+1;//M以上になるcの個数
        }
        if(sum<k)R=M;
        else L=M;
    }
    priority_queue<ll> pq;
    rep(i,x)rep(j,y){
        l=-1;r=z;
        tmp=a[i]+b[j];
        while(r-l>1){
            m=(r+l)/2;
            if(tmp+c[m]<L)r=m;
            else l=m;
        }
        rep(h,l+1)pq.push(tmp+c[h]);
    }
    rep(i,k){
        cout<<pq.top()<<endl;
        pq.pop();
    }
}

Measured memory_bytes: 133088
import Control.Monad
import Data.Char
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as UV

solve1 [h,w] = loop h
  where
    loop h = do
      if h == 0
        then putStrLn ""
        else do
        putStrLn $ concat $ replicate w "#"
        loop (h-1)

input1 :: IO [[Int]]
input1 = loop []
  where
    loop list = do
      temp <- getLine
      let [h,w] = map read . words $ temp :: [Int]
      if h == 0 && w == 0
        then return list
        else do
        loop (list ++ [[h,w]])

main = do
  hws <- input1
  mapM_ solve1 hws



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

int main(){
        long long x, k, d;
        scanf("%lld%lld%lld", &x, &k, &d);
        x=llabs(x);
        long long y=x/d;
        if(y>=k){
                x-=k*d;
                printf("%lld", x);
        }else{
                x-=y*d;
                long long rem=k-y;
                if(rem%2==0){
                        printf("%lld", llabs(x));
                }else{
                        x-=d;
                        printf("%lld", llabs(x));
                }
        }
        return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int N; cin >> N;
  int A[2][N];
  for(int i = 0; i < 2; ++i) {
    for(int j = 0; j < N; ++j) {
      cin >> A[i][j];
    }
  }
  int canN = 0;
  for(int i = 0; i < N; ++i) {
    int tmp = 0;
    for(int j = 0; j < N; ++j) {
      if(j < i) tmp += A[0][j];
      else if(j == i) tmp += A[0][j] + A[1][j];
      else tmp += A[1][j];
    }
    canN = max(canN, tmp);
  }
  cout << canN << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,sum=0;cin>>N;
  int l=log10(N);
  if(pow(10,l)==N)cout<<10<<endl;
  else{
    int k;
    for(int i=0;i<l+1;i++){
      k=N%10;
      N/=10;
      sum+=k;
    }
    sum+=N;
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 512
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
   
    int arr[]=new int[x];
     int tot=sc.nextInt();
    arr[0]=tot;
    for(int i=1;i<x;i++)
    {
      arr[i]=sc.nextInt();
      tot=tot^arr[i];
    }
    for(int i=0;i<x;i++)
    {
       System.out.print((arr[i]^tot)+" ");
    }
  }
}

Measured memory_bytes: 63240
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S,T="AKIHABARA";cin>>S;
  int i,j=0;
  for(i=0;i<9;i++){
    if(j<S.size()&&S.at(j)==T.at(i))j++;
    else if(T.at(i)!='A')break;
  }
  if(i==9&&S.size()<10)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const ll MOD = 1e9 +7;

int main(){
    int N,M,A[10];
    cin >>N>>M;
    int c[10] ={0,2,5,5,4,5,6,3,7,6};
    rep(i,M) cin >>A[i];
    sort(A,A+M,greater<int>());
    vector<int> dp(N+1,-10000);
    dp[0] =0;
    for(int i=1;i<=N;i++){
        rep(j,M){
            if(i-c[A[j]]>=0){
                dp[i] = max(dp[i],dp[i-c[A[j]]]+1);
            }
        }
    }
    while(N){
        rep(j,M){
            if(N-c[A[j]]>=0 && dp[N] == dp[N-c[A[j]]]+1){
                cout<<A[j];
                N-=c[A[j]];
                break;
            }
        }

    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,b,c,tmp;
  
  scanf("%d %d %d",&a,&b,&c);
  tmp = a;
  a = b;
  b = tmp;
  
  tmp = a;
  a = c;
  c = tmp;
  
  printf("%d %d %d\n",a,b,c);
  return 0;
}
  
  

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int a, b;
	cin >>a >>b;
	if (100==b)
		b +=a*1000;
	else if (b>=10)
		b +=a*100;
	else
		b +=a*10;
	int i=0;
	while(b>=i*i) {
		if (b==i*i) {
			cout <<"Yes" <<endl;
			return 0;
		}
		i++;
	}
	cout <<"No" <<endl;
	return 0;
}



Measured memory_bytes: 256
//Atcoder
import java.io.*;
import java.util.*;

public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

	public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt(), m = sc.nextInt();
        String str = sc.nextLine();
        int[] cnt = new int[n];

        for(int i=1;i<n;i++) {
            cnt[i] = cnt[i-1];
            if(str.charAt(i) == 'C' && str.charAt(i-1) == 'A') {
                cnt[i]++;
            }
        }

        //pw.println(Arrays.toString(cnt));

        for(int i=0;i<m;i++) {
            int l = sc.nextInt() - 1, r = sc.nextInt() - 1;
            pw.println(cnt[r] - cnt[l]);
        }

        pw.close();
    }
}


Measured memory_bytes: 40836
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int H, W;
    while(true){
        cin >> H >> W;
        if(H==0 && W == 0)
            break;
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++)
                cout << '#';
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3020
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>
#define ul unsigned long long int
#define ll long long int
#define MAX 1000000+1
using namespace std;
#define F first
#define S second
#define pi 2*acos(0.0)
#define PB push_back
#define CL clear()

ll st(ll& n)
{
    ll a = 9, b= 6;
    while( a <= n) a*= 9;
    a/=9;

    while(b <= n) b*=6;
    b/=6;
    return max(a,b);
}

int main()
{

  string a, b;
  cin >> a >> b;
  int arr[200], brr[200];
  for(int i = 0; i < 200; i++) arr[i] = brr[i] = 0;
  for(int i = 0; i < a.length(); i++)
  {
      arr[a[i]]++;
      brr[b[i]]++;
  }
   for(int i = 0; i < a.length(); i++)
  {
     if(arr[a[i]] != brr[b[i]])
     {
         cout <<"No"; return 0;
     }
  }
  cout << "Yes"; return 0;

}



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

int main()
{
  int n , m , x ;
  long int answer ;
  priority_queue<int> A ;
  cin >> n >> m ;
  for(int i=0; i<n; i++)
  {
    cin >> x ;
    A.push(x) ;
  }
  for(int i=0; i<m; i++)
  {
    x = A.top() ;
    A.pop() ;
    A.push(x/2) ;
  }
  for(int i=0; i<n; i++)
  {
    answer += A.top() ;
    A.pop() ;
  }
  cout << answer << endl ;
}

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

int main()
{
  string a;
  cin>>a;
  int i;
  if((a[0]==a[1]&&a[1]==a[2]) || (a[3]==a[1]&&a[1]==a[2]) )
    puts("Yes");
  else puts("No");

//  main();


}





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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    long long n, x;;
    cin >> n >> x;

    vector <vector <long long>> mn(n, vector <long long> (n, 0));
    vector <long long> a(n);

    for (auto &elem : a) cin >> elem;

    for (int i = 0; i < n; i++) mn[0][i] = a[i];

    for (int j = 1; j < n; j++) {
        for (int i = 0; i < n; i++) {
            mn[j][i] = min(mn[j - 1][i], a[(i - j + n) % n]);
        }
    }

    long long res = 1e18;

    for (int i = 0; i < n; i++) {
        long long new_res = x * i;
        for (auto elem : mn[i]) {
            new_res += elem;
        }
        res = min(new_res, res);
    }

    cout << res;
    
    return 0;
}


Measured memory_bytes: 31616
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main(){
    ll n;
    int k;
    cin >> n >> k;
    int ans = 0;
    while (pow(k, ans) <= n) ans++;
    cout << ans;
    return 0;
}



Measured memory_bytes: 384
import java.util.Scanner;

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

    // 標準入力から値を取得
    // *N：宿泊数, K：X円/日で泊まれる日数, X：K泊目以内の日毎宿泊費, Y：K+1泊目以降の日毎宿泊費
    int n = scanner.nextInt();
    int k = scanner.nextInt();
    int x = scanner.nextInt();
    int y = scanner.nextInt();

    // NがK以下の場合、宿泊数 * Xを出力
    if(n <= k) {
      System.out.println(n * x);

    // NがKより大きい場合、K * X + (N - K) * Y を出力
    } else {
	  // *K + 1日目からN日目までの日数
      int z = n - k;
      System.out.println(k * x + z * y);
    }
  }
}

Measured memory_bytes: 35728
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

struct DisjointSet {
	vector<int> par;

	DisjointSet(int N) : par(N, -1) {}

	bool isSame(int a, int b) {
		return root(a) == root(b);
	}

	int root(int a) {
		if (par[a] < 0) return a;
		par[a] = root(par[a]);
		return par[a];
	}

	int size(int a) {
		return -par[root(a)];
	}

	void unite(int a, int b) {
		if (!isSame(a, b)) {
			a = root(a);
			b = root(b);
			if (size(a) < size(b)) swap(a, b);
			par[a] += par[b];
			par[b] = a;
		}
	}
};

int main() {
	int n, q;
	cin >> n >> q;
	DisjointSet S(n);
	for (int i = 0; i < q; ++i) {
		int com;
		cin >> com;
		if (com == 0) {
			int x, y;
			cin >> x >> y;
			S.unite(x, y);
		}
		else {
			int x, y;
			cin >> x >> y;
			cout << S.isSame(x, y) << endl;
		}
	}
}


Measured memory_bytes: 3152
def binary_search(x,li):
    low = 0
    high = len(li)-1
    mid = (low + high)//2
    while low <= high:
        if li[mid] == x:
            return True
        elif x < li[mid]:
            low = mid + 1
        else:
            high = mid - 1
        mid = (low + high)//2
    return False

n,l = map(int,input().split())
taste = [0 for i in range(n)]
check = len(taste)
for i in range(n):
    taste[i] = l + i
taste = sorted(taste)
state = 0
for i in range(n):
    if taste[i] == 0:
        state = 1
        break
    else:
        state = 0
if state == 1:
    ans = 0
    for i in range(n):
        ans+=taste[i]
    print(ans)
else:
    if taste[0]>0:
        ans = 0
        for i in range(1,len(taste)):
            ans+=taste[i]
        print(ans)
    elif taste[0]<0:
        ans = 0
        for i in range(n):
            if taste[i] > 0:
                check = i
                break
        for i in range(n):
            if i != check-1:
                ans+=taste[i]
        print(ans)


Measured memory_bytes: 3444
/*
RAone00
Rohit sharma
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef vector < vector < ll > > matrix;
typedef vector < ll > vll;

#define pb push_back
#define debug(x) cout << (#x) << " is " << (x) << endl
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll mod = 1e9 + 7;
const ll inf = LLONG_MAX;
const ll N = 1e5 + 10;

int main() {
    fast_io();
    int a, s;
    cin >> a >> s;
    int n1 = (a + s);
    int n2 = (a - s);
    int n3 = (a * s);
    //     if(n1 >= n2 && n1 >= n3)
    // {
    //     cout << n1 << "\n";
    // }
    // if(n2 >= n1 && n2 >= n3)
    // {
    //     cout << n2 << "\n";
    // }
    // if(n3 >= n1 && n3 >= n2) {
    //     cout << n3 << "\n";
    // }
    cout << max({n1, n2, n3});
    return 0;
}


Measured memory_bytes: 256
N = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

res = 0
for i in range(N):
    b = b_list[i]
    if b >= a_list[i]:
        b -= a_list[i]
        res += a_list[i]
        a_list[i] = 0
    else:
        res += b
        a_list[i] -= b
        b = 0

    if b >= a_list[i+1]:
        b -= a_list[i+1]
        res += a_list[i+1]
        a_list[i+1] = 0
    else:
        res += b
        a_list[i+1] -= b
        b = 0
print(res)


Measured memory_bytes: 18476
use std::io::stdin;

fn main() {
    let mut is = String::new();
    stdin().read_line(&mut is).ok();
    is.clear();
    stdin().read_line(&mut is).ok();
    let mut itr = is.split_whitespace().map(|e| e.parse::<i128>().unwrap());
    let mut ans = 1;
    let flg = itr.clone().any(|e| e == 0);
    if !flg {
        for e in itr {
            ans *= e;
            if ans > 1000000000000000000 {
                ans = -1;
                break;
            }
        }
    }

    println!("{}", if flg { 0 } else { ans });
}


Measured memory_bytes: 4020
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
	ll s;
	cin >> s;
	ll ans = 1;
	set<ll> st{s};
	while (true){
		s = s%2==0 ? s/2: 3*s + 1;
		ans += 1;
		if (st.count(s)==1){cout << ans << endl; break;}
		st.insert(s);
	}
}

Measured memory_bytes: 256
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
    #include<numeric>
    #include<array>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define Vl vector<ll>
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<ll>>;
    using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;
const ll ZER = 0;

int main(){
    int n, k;
    cin >> n >> k;
    if((n + 1) / 2 >= k){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}


Measured memory_bytes: 3632
#include<stdio.h>

int main(){
  int n, i, j;
  scanf("%d", &n);
  
  for(i=1; i < 10; i++){
    for(j=1; j < 10; j++){
      if(n == i * j){
      	printf("Yes");
        return(0);
      }
    }   
  }
  printf("No");
  return(0);
}


Measured memory_bytes: 1704
#include<iostream>
#include<cstdio>
#include<bitset>
#include<cstring>
using namespace std;
int n,a[2010],sum;
bitset<4000010> f[2];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	f[0][0]=1;
	for(int i=1,v=1;i<=n;i++,v^=1)
		f[v]=f[v^1]|(f[v^1]<<a[i]);
	for(int i=(sum+1)/2;i<=sum;i++)
		if(f[n&1][i]) {printf("%d",i);return 0;}	
	return 0;
}

Measured memory_bytes: 2688
"use strict";
main(
  require("fs")
    .readFileSync("/dev/stdin", "UTF-8")
    .trim()
    .split("\n")
);

/**
 * 長さ奇数の文字列Sがあり、以下の条件の時、Sは強い回文
 *
 * 1. 回文 ... 始めから読んでも、後ろから読んでも同じ
 * 2. N...Sの長さとした時、S1~S(N-1)/2からなる文字列は回文
 * 3. N...Sの長さとした時、S(N+3)/2~SNからなる文字列は回文
 */

function isPalindrome(text) {
  let result = true;
  for (let i = 0; i < Math.ceil(text.length / 2); i++) {
    if (text[i] !== text[text.length - i - 1]) {
      result = false;
      break;
    }
  }
  return result;
}

function main(input) {
  input = input[0];
  const N = input.length;

  const case1 = isPalindrome(input);
  const case2 = isPalindrome(input.slice(0, (N - 1) / 2));
  const case3 = isPalindrome(input.slice((N + 3) / 2 - 1, N));

  console.log(case1 && case2 && case3 ? "Yes" : "No");
}


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

main() {
    string S; cin >> S;
    int a,z;
    rep(i,S.size()){
        if(S[i]=='A'){a=i; break;}
    }
    for(int i=S.size()-1;i>=0;i--){
        if(S[i]=='Z'){z=i; break;}
    }
    cout << z-a+1 << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
bool small(char c){
	if(c >= 'a' and c <= 'z')return true;
	else return false;
}
int main(void){
	string s;cin >> s;
	bool ans = true;
	if(s[0] != 'A'){
		ans = false;
	}
	int count = 0,num = 0;
	for(int i = 2;i <= s.size() - 2;i++){
		if(s[i] == 'C'){count++;num = i;}
	}
	if(count != 1){
		ans = false;
		goto B;
	}
	for(int i = 1;i < s.size();i++){
		if(i != num){
			if(!small((char)s[i])){
				ans = false;
				goto B;
			}
		}
	}
	
B:;
	(ans) ? cout << "AC" << endl : cout << "WA" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int n;
const int MAX_N = 100;
int z[MAX_N];

void print_array(const int a[]){
  for(int i = 0; i < n; i++){
    printf("%d",a[i]);
    if(i != n - 1) printf(" ");
  }
  printf("\n");
}

int bubblesort(int a[], int n){
  int sw = 0;
  bool flag = true;
  for(int i = 0; flag; i++){
    flag = false;
    for(int j = n - 1; j >= i + 1; j--){
      if(a[j] < a[j-1]){
        swap(a[j-1],a[j]);
        flag = true;
        sw++;
      }
    }
  }
  return sw;
}

int main(){
  cin >> n;
  for(int i = 0; i < n; i++) cin >> z[i];
  int ans = bubblesort(z, n);
  print_array(z);
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
 
int main(void) {
  int k;cin>>k;
  string s;cin>>s;
  if(s.size()<=k) cout << s << endl;
  else cout << s.substr(0, k) << "..." << endl;


  return 0;
}

Measured memory_bytes: 3572
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=list(S())
  ln=len(s)

  ans=0
  i=0
  __s=''
  _s=''
  while True:
    if i>=ln:
      return ans
    _s+=s[i]
    if _s!=__s:
      ans+=1
      __s=_s
      _s=''
    i+=1

# main()
print(main())


Measured memory_bytes: 10020
fn main() {
    let (a,b,c)
        = {let v: Vec<i32> = read_vec(); (v[0],v[1],v[2])};
    println!("{}",std::cmp::max(0,c-(a-b)));
}

fn get_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().to_owned()
}

fn read<T: std::str::FromStr>() -> T{
    get_line().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T>{
    get_line().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

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

int main(){
    int64_t x;
    cin >> x;
    int64_t y = (x / 11) * 2;
    int64_t z = x % 11;
    if (z >= 7) y += 2;
    else if (z != 0) y += 1;
    cout << y << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)

int main()
{
    fast();

    using P = pair<ll, ll>;

    // d[0] : ひだり, d[1] : うえ, d[2] : みぎ, d[3] : した
    int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
    ll H, W, K;
    cin >> H >> W >> K;
    vector<string> grid(H);
    vector<vector<vector<P>>> d(H);

    int sx, sy, gx, gy;

    cin >> sx >> sy >> gx >> gy;
    sx--, sy--, gx--, gy--;

    for (int i = 0; i < H; i++)
    {
        cin >> grid[i];
    }

    for (int i = 0; i < H; i++) // init
    {
        d[i] = vector<vector<P>>(W, vector<P>(4, P(infll, infll)));
    }

    // (最短距離, その方向に進んだ回数), (x, y), dir
    priority_queue<pair<P, pair<P, ll>>, vector<pair<P, pair<P, ll>>>, greater<pair<P, pair<P, ll>>>> pq;

    for (int i = 0; i < 4; i++)
    {
        d[sx][sy][i] = P(1, 0);
        pq.push({d[sx][sy][i], {{sx, sy}, i}});
    }

    while (!pq.empty())
    {
        auto v = pq.top();
        pq.pop();
        ll vx = v.second.first.first, vy = v.second.first.second, dir = v.second.second;

        for (int i = 0; i < 4; i++) // 向きを変える
        {
            P ncost = make_pair(d[vx][vy][dir].first + 1, 0);
            if (d[vx][vy][i] <= ncost)
                continue;
            d[vx][vy][i] = ncost;
            pq.push({ncost, {{vx, vy}, i}});
        }

        // 直進する
        int nx = vx + dx[dir], ny = vy + dy[dir];
        if (nx < 0 || nx >= H || ny < 0 || ny >= W) // grid の外
            continue;
        if (grid[nx][ny] == '@') // 行き止まり
            continue;
        ll df = d[vx][vy][dir].first, ds = d[vx][vy][dir].second;
        P ncost = make_pair(df + (ds + 1) / (K + 1), ds % K + 1);
        if (d[nx][ny][dir] <= ncost)
            continue;
        d[nx][ny][dir] = ncost;
        pq.push({ncost, {{nx, ny}, dir}});
    }

    ll min_cost = (*min_element(d[gx][gy].begin(), d[gx][gy].end())).first;

    cout << (min_cost == infll ? -1 : min_cost) << "\n";
}


Measured memory_bytes: 126796
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n,w,k;
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>k;
	while(n){
		w++;
		n/=k;
	}
	cout<<w;
	re 0;
}


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

using namespace std;

const int N = 105;

int a[3][N], dp[3][N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= n; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= n; j++) {
      dp[i][j] = max(dp[i][j], dp[i][j-1] + a[i][j]);
      dp[i][j] = max(dp[i][j], dp[i-1][j] + a[i][j]);
      //printf("%d ", dp[i][j]);
    }
    //printf("\n");
  }
  cout << dp[2][n] << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll mod = 1000000007;
const int limit = 100005;
int n, k;
ll cnt[limit];

void dfs(int v, int p, int kind, vector<vector<int>> &G){
	cnt[v] = max(kind,0);
	int c = 1;
	if(p != -1) c++;
	for(auto nv : G[v]){
		if(nv == p) continue;
		dfs(nv, v, k - c, G);
		c++;
	}
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
	vector<vector<int>> G(n);
    for(int i = 0; i < n-1; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
	memset(cnt, 0, sizeof(cnt));
    dfs(0, -1, k, G);
	ll ans = 1;
	rep(i,n){
		ans = (ans * cnt[i]) % mod;
	}
	cout << ans << endl;
    return 0;
}


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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1LL<<62)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int Cost;
struct Edge {
  int src, dst; Cost cost;
  Edge(int s, int d, Cost c) : src(s), dst(d), cost(c) {}
};

typedef vector<Edge>  Edges;
typedef vector<Edges> Graph;
typedef vector<Cost>  Array;
typedef vector<Array> Matrix;

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

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A * B > C * D) cout << A * B << endl;
  else cout << C * D << endl;
  return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;constexpr ll INF=1LL<<60,MOD=1e9+7;//998244353;
void solve();int main(){cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();return 0;}
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d>0?i<n:i>n;i+=d)
#define endl "\n"
#ifdef __LOCAL
#include "ostreams.h"
#endif
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> vector<T> make_vector(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_vector(size_t a,Ts... ts){return vector<decltype(make_vector(ts...))>(a,make_vector(ts...));}
void print(){cerr<<endl;} template<class T,class... Ts> void print(const T& a,const Ts&... ts){cerr<<a<<' ';print(ts...);}

void solve(){
    string S; cin >> S;
    ll n = S.size();
    ll res = INF;

    for(char c = 'a'; c <= 'z'; ++c){
        string now = S;
        while(1){
            bool flag = true;
            for(auto x : now){
                flag &= x == c;
            }
            if(flag){
                chmin(res, n - (ll)now.size());
                break;
            }
            string next;
            rep(i, (ll)now.size() - 1){
                if(now[i] == c or now[i + 1] == c){
                    next.push_back(c);
                } else {
                    next.push_back(now[i]);
                }
            }
            swap(now, next);
        }
    }


    cout << res << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> a(m);
    rep(i, m) cin >> a[i];
    int left = 0;
    repk(i, 1, x) {
        if (binary_search(a.begin(), a.end(), i))
            left++;
    }
    int right = 0;
    repk(i, x + 1, n + 1) {
        if (binary_search(a.begin(), a.end(), i))
            right++;
    }
	cout<<min(left,right)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
 
vector<pi> gph[200005];
int n, m, k;
 
bool vis[200005];
lint val[200005];
 
lint l, r;
 
void dfs(int x, lint v){
	if(vis[x]){
		if(val[x] != v){
			puts("No");
			exit(0);
		}
		return;
	}
	vis[x] = 1;
	val[x] = v;
	if(x <= n) l = max(l, v);
	else r = min(r, v);
	for(auto &i : gph[x]){
		dfs(i.first, v + i.second);
	}
}
 
 
int main(){
	cin >> n >> m >> k;
	for(int i=0; i<k; i++){
		int x, y, v;
		scanf("%d %d %d",&x,&y,&v);
		gph[x].push_back(pi(y+n, v));
		gph[y+n].push_back(pi(x, -v));
	}
	for(int i=1; i<=n+m; i++){
		if(!vis[i]){
			l = -1e18, r = 1e18;
			dfs(i, 0);
			if(l > r) return !puts("No");
		}
	}
	puts("Yes");
}

Measured memory_bytes: 12928
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
    #define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
    #define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
LL solve(LL k, LL a, LL b) {
    if (a+2 >= b) return k+1;
    LL cur = 1, tmp;
    if (cur < a) {
        tmp = min(k, a - cur);
        cur += tmp;
        k -= tmp;
    }
    tmp = k/2;
    cur += tmp * (b-a);
    k -= tmp*2;
    assert(k == 0 || k == 1);
    if (k == 1) cur++;
    return cur;


}





int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.precision(10); cout << fixed;
#ifdef LOCAL
    freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
    int k, a, b;
    cin >> k >> a >> b;
    cout << solve(k, a, b) << endl;






/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
    return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int n, m;
  int wa[MAX] = {0};
  int ac[MAX] = {0};
  scanf("%d %d", &n, &m);
  rep(i, 0, m) {
    char s[3];
    int p;
    scanf("%d %s", &p, s);
    if (strcmp(s, "AC") == 0) {
      ac[p]++;
    } else if (ac[p] == 0) {
      wa[p]++;
    }
  }

  int sa = 0, sw = 0;
  rep(i, 1, n + 1) {
    if (ac[i] > 0) {
      sa++;
      sw += wa[i];
    }
  }
  printf("%d %d\n", sa, sw);
  return 0;
}


Measured memory_bytes: 896
n = input()
S = list(map(int,input().split()))
n = input()
T = list(map(int,input().split()))
count =  0

def binarySearch(a,b):
    left = 0
    right = len(b)
    while left < right:
        mid = int((left + right)/2)
        if b[mid] == a:
            return 1
        elif b[mid] < a:
            left = mid+1
        elif b[mid] > a:
            right = mid
    return 0

count = 0
for i in T:
    count += binarySearch(i, S)
    
print(count)

Measured memory_bytes: 18648
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

x, n = inm()
a = inl()
count = 1
if x not in a:
    print(x)
else:
    while True:
        if x - count not in a:
            print(x - count)
            break
        if x + count not in a:
            print(x + count)
            break
        count += 1

Measured memory_bytes: 9204
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ii>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100009;
ll a,b,c,n,g,i,j,k,ans;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>a>>b>>c>>n;
    rep(i,0,a + 1) rep(j,0,b + 1) rep(k,0,c + 1){
        g = i*500 + j*100 + k*50;
        ans += g == n;
    }
    cout<<ans;
    return 0;
}

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

using namespace std;

#define SZ(a) int((a).size())
#define mp make_pair
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lrt rt<<1
#define rrt rt<<1|1
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;
const LL mod=1e9+7;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double EPS=1e-6;
inline void read(LL& x){int f=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(f=-1,x=0):(x=c-'0');while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=f;}
inline void read(int& x){LL t;read(t);x=t;}


char s[6];
int num[6];
int ans[5];

void dfs(int i,int p){
    if(i==3&&p==7){
        for(int j=0;j<3;j++){
            printf("%d%c",num[j],ans[j]==1?'+':'-');
        }printf("%d=7\n",num[3]);
        exit(0);
    }else if(i==3) return;
    ans[i]=1;
    dfs(i+1,p+num[i+1]);
    ans[i]=2;
    dfs(i+1,p-num[i+1]);
}

int main(){//ios_base::sync_with_stdio(0);cin.tie(0);
    scanf("%s",s);
    for(int i=0;i<4;i++) num[i]=s[i]-'0';
    dfs(0,num[0]);
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


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

	int a, b, d, r;
	double f;
	scanf("%d %d", &a, &b);

	d = a / b;
	r = a % b;
	f = (double)a / (double)b;

	printf("%d %d %lf\n", d, r, f);

	return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,T,A;
  cin >> N >> T >> A;
  int v[N];
  for (int i=0;i<N;i++){
    cin >> v[i];
  }
  double pos=(T-A)/0.006;
  double minimum=100010,ans;
  for (int i=0;i<N;i++){
    if (abs(v[i]-pos)<minimum){
      ans=i+1;
      minimum=abs(v[i]-pos);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
$as=explode(' ',trim(fgets(STDIN)));
$nums = [];
$ress = [];
foreach ($as as $a) {
  if (!isset($nums[$a])) $nums[$a]=0;
  $nums[$a]++;
}
$sum = 0;
foreach ($nums as $a => $num) {
  if (!isset($ress[$num])) $ress[$num] = $num * ($num - 1) / 2;
  $sum += $ress[$num];
}
foreach ($as as $a) {
  $num = $nums[$a] - 1;
  if (!isset($ress[$num])) $ress[$num] = $num * ($num - 1) / 2;
  echo $sum - $ress[$nums[$a]] + $ress[$num] . "\n";
}

Measured memory_bytes: 25328
n,m=map(int,input().split())
l=[0]*(n+1)
miss=[0]*(n+1)
for _ in range(m):
    p,s=input().split()
    p=int(p)
    if l[p]==0:
        if s=='AC':
            l[p]+=1
        else:
            miss[p]+=1
for i in range(1,n+1):
    if l[i]==0 and miss[i]!=0:
        miss[i]=0
a=l.count(1)
b=sum(miss)
print(a,b)

Measured memory_bytes: 10324
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int N;
  cin >> N;
  if (N % 2) {
    cout << 0 << endl;
  } else {
    int ans = 0;
    int p = 1;
    rep(k, 0, 30) {
      p *= 5;
      ans += (N / 2) / p;
      if ((N / 2) / p == 0) break;
    }
    cout << ans << endl;
  }
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 256
N, C = map(int, input().split())
stcs = []
for i in range(N):
  s, t, c = map(int, input().split())
  stcs.append((s, t, c))
stcs.sort()
rs = []
for s, t, c in stcs:
  ok = False
  for l in rs:
    s0, t0, c0 = l[-1]
    if t0 < s or (t0 == s and c0 == c):
      l.append((s, t, c))
      ok = True
      break
  if not(ok):
    l = [(s, t, c)]
    rs.append(l)
#print(rs)
r = len(rs)
print(r)


Measured memory_bytes: 25732