akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, Q;
	int64_t S[100010], Sdiv[100010], ans[100010];
	int A[100010], X[100010];
	cin >> N >> Q;

	eFOR(i,1, N) {
		cin >> A[i];
		S[i] = S[i - 1] + A[i];
		Sdiv[i] = A[i];
		if (i - 2 > 0) {
			Sdiv[i] += Sdiv[i - 2];
		}
	}
	REP(i, Q) {
		cin >> X[i];
	}

	REP(q, Q) {
		int ng = 0;
		int ok = N;
		while (ok - ng > 1) {
			int mid = (ng + ok) / 2;
			if (A[mid] < X[q]) {
				ng = mid;
			}else {
				int upper = N - mid + 1;
				int lower = mid - (lower_bound(A, A + N + 1, max(1LL, 2 * X[q] - A[mid])) - A) + 1;
				(upper > lower ? ng : ok) = mid;
			}
		}

		int64_t res = S[N] - S[ok - 1];
		int tf = N - (N - ok + 1) * 2;
		if (tf > 0)res += Sdiv[tf];
		ans[q] = res;

	}



	REP(i, Q) {
		cout << ans[i] << endl;
	}


	return 0;
}



Measured memory_bytes: 5632
#include<stdio.h>
#include<math.h>
struct Point{double x,y;};
void koch(int n,Point a,Point b){
 if(n==0)return;
 Point s,t,u;
 double th=M_PI*60.0/180.0;
 s.x=(2.0*a.x+1.0*b.x)/3.0;
 s.y=(2.0*a.y+1.0*b.y)/3.0;
 t.x=(1.0*a.x+2.0*b.x)/3.0;
 t.y=(1.0*a.y+2.0*b.y)/3.0;
 u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
 u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
 koch(n-1,a,s);
 printf("%.8f %.8f\n",s.x,s.y);
 koch(n-1,s,u);
 printf("%.8f %.8f\n",u.x,u.y);
 koch(n-1,u,t);
 printf("%.8f %.8f\n",t.x,t.y);
 koch(n-1,t,b);
}
int main(){
 Point a,b;
 int n;
 scanf("%d",&n);
 a.x=0;
 a.y=0;
 b.x=100;
 b.y=0;
 printf("%.8f %.8f\n",a.x,a.y);
 koch(n,a,b);
 printf("%.8f %.8f\n",b.x,b.y);
 return 0;
}


Measured memory_bytes: 2664
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  int N, K; cin >> N >> K;
  int R, S, P; cin >> R >> S >> P;
  string T; cin >> T;

  vector<char> memo(K);
  int res{};
  for (int i = 0; i < N; ++i) {
    int j = i % K;
    char t = T[i];
    if (memo[j] == t) {
      memo[j] = 0;
    } else {
      switch (t)
      {
        case 'r':
          res += P;
          break;
        case 's':
          res += R;
          break;
        case 'p':
          res += S;
          break;
        default:
          break;
      }
      memo[j] = t;
    }
  }
  cout << res << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

const ll mod = 1e9 + 7;
const int maxn = 3e3 + 10;
ll DP[maxn][maxn];
ll sum[maxn];
char s[maxn];
int N;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    for(int i = 1; i < N; ++i){
        cin >> s[i];
    }
    DP[1][1] = 1;
    for(int i = 2; i <= N; ++i){
        sum[0] = DP[i - 1][0];
        for(int j = 1; j <= i - 1; ++j){
            sum[j] = (sum[j - 1] + DP[i - 1][j]) % mod;
        }
        for(int j = 1; j <= i; ++j){
            if(s[i - 1] == '<'){
                DP[i][j] = sum[j - 1];
            }
            else{
                DP[i][j] = (sum[i - 1] - sum[j - 1] + mod) % mod; 
            }
        }
    }
    ll ret = 0;
    for(int i = 1; i <= N; ++i){
        ret = (ret + DP[N][i]) % mod;
    }
    cout << ret << endl;
}


Measured memory_bytes: 69248
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using v = vector<ll>;
using p = pair<ll,ll>;

void a(){
    ll h,a;
    cin >> h >> a;
    cout << (h%a==0? h/a:h/a+1);
}

void b(){
    ll h,n;
    cin >> h >> n;
    auto a = v(n,0);
    for(ll i=0;i<n;i++) cin >> a[i];
    ll sum = accumulate(a.begin(),a.end(),0);
    cout << (sum>=h?"Yes":"No");
}

void c(){
    ll n,k;
    cin >> n >> k;
    auto h = v(n,0);
    for(ll i=0;i<n;i++){
        cin >> h[i];
    }
    sort(h.begin(),h.end(),greater<ll>());
    if(n<=k) {
        cout << 0 << endl;
        return;
    }
    auto sum = accumulate(h.begin()+k,h.end(),(ll)0);
    cout <<sum<<endl;

}
int main(){
    c();
    return 0;
}

Measured memory_bytes: 1792
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0
for a500 in range(A + 1):
    if a500 * 500 > X:
        break
    for b100 in range(B+1):
        if a500 * 500 + b100 * 100 > X:
            break
        for c50 in range(C+1):
            if a500 * 500 + b100 * 100 + c50 * 50 == X:
                cnt += 1
            else:
                if a500 * 500 + b100 * 100 + c50 * 50 > X:
                    break
print(cnt)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,o,b[200009],t=0,c[200009],sum[200009],sum1[200009],e[200009],ans[200009],t1=0,maxi1[200009],maxi2[200009];
char a[200009];
int query(int x)
{
    if(x<0)
        return 0;
    int res=0;
    while(x)
    {
        res=max(res,c[x]);
        x-=x&-x;
    }
    return res;
}
void add(int x,int d)
{
    while(x<=b[t-1])
    {
        c[x]=max(c[x],d);
        x+=x&-x;
    }
}
int main()
{
    memset(c,0,sizeof(c));
    memset(maxi1,0,sizeof(maxi1));
    memset(maxi2,0,sizeof(maxi2));
    scanf("%d%d%d%s",&n,&m,&o,a+1);
    for(int i=1; a[i]!='\0'; i++)
        if(a[i]=='o')
            b[t++]=i;
    for(int i=0; i<t; i++)
    {
        sum[i]=query(b[i])+1;
        add(b[i]+o+1,sum[i]);
    }
    memset(c,0,sizeof(c));
    e[t-1]=1;
    for(int i=t-2;i>=0;i--)
        e[i]=e[i+1]+b[i+1]-b[i];
    for(int i=t-1;i>=0;i--)
    {
        sum1[i]=query(e[i])+1;
        add(e[i]+o+1,sum1[i]);
    }
    maxi1[0]=sum[0];
    for(int i=1;i<t;i++)
        maxi1[i]=max(maxi1[i-1],sum[i]);
    maxi2[t-1]=sum1[t-1];
    for(int i=t-2;i>=0;i--)
        maxi2[i]=max(maxi2[i+1],sum1[i]);
    for(int i=0;i<t;i++)
    {
        if(i==0&&maxi2[i+1]<m)
            ans[t1++]=b[i];
        else if(i&&maxi1[i-1]+maxi2[i+1]<m)
        ans[t1++]=b[i];
    }
    for(int i=0;i<t1;i++)
        printf("%d\n",ans[i]);
    return 0;
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, A, B, answer = 0;
  cin >> N >> A;
  int x[N];
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }
  for (int i = 1; i <= N; i++) {
    B = i*A;
    long long dp[i+1][N+1][B+1];
    for (int j = 0; j <= i; j++) {
      for (int k = 0; k <= N; k++) {
        for (int l = 0; l <= B; l++) {
          dp[j][k][l] = 0;
        }
      }
    }
    for (int j = 0; j <= N; j++) {
      dp[0][j][0] = 1;
    }
    for (int j = 1; j <= i; j++) {
      for (int k = j; k <= N; k++) {
        for (int l = 1; l <= B; l++) {
          dp[j][k][l] = dp[j][k-1][l];
          if (l >= x[k-1]) {
            dp[j][k][l] += dp[j-1][k-1][l-x[k-1]];
          }
        }
      }
    }
    answer += dp[i][N][B];
  }
  cout << answer;
}

Measured memory_bytes: 51072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=100010;
const int inf=0x3f3f3f3f;
typedef pair<int,int> pr;
inline ll read()
{
	ll x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}
template<typename T>inline void Min(T &x,ll y){if(x>y)x=y;}
struct edge{
	int from,to;
	ll w;
	bool operator < (const edge &rhs) const {
		return w>rhs.w;
	}
}e[maxn<<1];
int n,fa[maxn];
ll tag[maxn],ans[maxn];
vector<int> g[maxn];
inline int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
inline void merge(int x,int y,ll w)
{
	int fx=find(x),fy=find(y);
	if(g[fx].size()<g[fy].size()) swap(fx,fy);
	for(int i=0;i<g[fy].size();i++) ans[g[fy][i]]+=1LL*tag[fy]-tag[fx]+(g[fx].size()-g[fy].size())*w;
	tag[fx]+=1LL*(ll)g[fy].size()*w;for(int i=0;i<g[fy].size();i++) g[fx].push_back(g[fy][i]);
	fa[fy]=fx;find(x),find(y);
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++) g[i].push_back(i),fa[i]=i;
	for(int i=1;i<n;i++) e[i].from=read(),e[i].to=read(),e[i].w=read();
	sort(e+1,e+n);
	for(int i=1;i<n;i++) merge(e[i].from,e[i].to,e[i].w);
	for(int i=1;i<=n;i++) printf("%lld\n",ans[i]+tag[find(i)]);
	return 0;
}

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

int A[100010];

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  
  int A2 = 0, A4 = 0;
  for (int i = 0; i < N; i++) {
    int ai = A[i];
    if (ai % 4 == 0) A4++;
    else if (ai % 2 == 0) A2++;
  }
  
  if (A4 >= 1) {
    N -= A4 * 2 + 1;
    if (A2 >= 2) {
      N ++;
      N -= A2;
    }
  }
  else if (A2 >= 2)
    N -= A2;
  
  if (N <= 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007


signed main(){
    fast;
    // #ifndef ONLINE_JUDGE
    //     freopen("/home/swapnil/Desktop/c++/input.txt","r",stdin);
    //     freopen("/home/swapnil/Desktop/c++/output.txt","w",stdout);
    // #endif
    int n;
    cin>>n;
    int a,b;cin>>a>>b;int gval=__gcd(a, b);
    For(i, 2, n){
        cin>>a;
        gval = __gcd(gval, a);
    }
    cout<<gval;
    return 0;
}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a = 0,b = 0,c = 0;
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i){
		int x;
		cin >> x;
		if(x & 1) a++;
		else if(x & 3) b = 1;
		else c++;
	}
	if(c + 1 >= (a + b)) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static int solve(int n, int m, char[][] arr) {
      int[][] memo = new int[n][m];
      for(int i = 0; i < n; i++) {
        Arrays.fill(memo[i],-1);
      }
      
      return dfs(arr, n, m, 0, 0, 0,memo);
      //return 0;
    }

    private static int dfs(char[][] arr, int n, int m, int x, int y, int currentPath, int[][] memo) {
      if(x>= n || y >= m || arr[x][y] == '#')
        return 0;
      
      if(memo[x][y] != -1){
        return memo[x][y];
      }
      
      if(x == n - 1 && y == m - 1) {
        return 1;
      }
      
      int result = 0;
      arr[x][y] = '#';
      result += dfs(arr, n, m, x + 1, y, currentPath,memo) % 1000000007;
      result += dfs(arr, n, m, x, y + 1, currentPath, memo) % 1000000007;
      arr[x][y] = '.';
      memo[x][y] = result % 1000000007;
      return result % 1000000007;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        char[][] arr = new char[n][m];

        for (int i = 0; i < n; i++) {
          char[] s = scanner.next().toCharArray();
          for(int j = 0; j < m; j++) {
            arr[i][j] = s[j];
          }
        }

      	int result = solve(n,m,arr);
        System.out.println(result);
    }
}

Measured memory_bytes: 37596
#include <bits/stdc++.h>
using namespace std;
#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()
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);

int main() {
    int N, MAX = 1e6 + 1;
    cin >> N;
    vi a(N);
    rep(i, N) { cin >> a[i]; }
    vb dp(MAX, true);
    unordered_set<int> used;
    used.insert(1e7);
    rep(i, N) {
        if (used.find(a[i]) != used.end()) {
            dp[a[i]] = false;
            continue;
        }
        if (dp[a[i]]) {
            rep2(j, 2, MAX / a[i] + 1) { dp[a[i] * j] = false; }
        }
        used.insert(a[i]);
    }
    int ans = 0;
    rep(i, N) {
        if (dp[a[i]]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 12372
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 100000
using namespace std;

int n,m;
int fa[MAXN+5],val[MAXN+5];

int find_fa(int x)
{
    if(fa[x]==x)
        return x;
    int dad=find_fa(fa[x]);
    val[x]+=val[fa[x]];
    fa[x]=dad;
    return dad;
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        fa[i]=i;
    int l,r,va;
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&l,&r,&va);
        int fl=find_fa(l),fr=find_fa(r);
        if(fl==fr)
        {
            int t=val[r]-val[l];
            if(-t!=va)
            {
                printf("No\n");
                return 0;
            }
        }
        else
        {
            fa[fr]=fl;
            val[fr]=-va+val[l]-val[r];
        }
    }
    printf("Yes");
}


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

int main(int argc, char const *argv[]) {
    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int counter = 0;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                int temp = 500 * i + 100 * j + 50 * k;
                if (temp == x) {
                    counter++;
                }
            }
        }
    }

    cout << counter << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct BIT{
    int size;
    vector<int> bit;
    void init(int n){
        size = n;
        bit.assign(size+1, 0);
    }

    // from 1 to x (inclusive)
    int sum(int x){
        int res = 0;
        while(x > 0){
            res += bit[x];
            x -= (x & -x);
        }
        return res;
    }

    void add(int x, int y){
        while(x <= size){
            bit[x] += y;
            x += (x & -x);
        }
    }
};
BIT bit[26];
int main(void){
    int n, q;
    string s;
    cin >> n >> s >> q;
    for(int i=0;i<26;i++) bit[i].init(n);
    for(int i=0;i<n;i++){
        int v = s[i] - 'a';
        bit[v].add(i+1, 1);
    }

    for(;q--;){
        int p;
        cin >> p;
        if(p == 1){
            int i;
            char c;
            cin >> i >> c;
            int v = s[i-1]-'a';
            bit[v].add(i, -1);
            v = c - 'a';
            bit[v].add(i, 1);
            s[i-1] = c;
        }else{
            int l, r, ans = 0;
            cin >> l >> r;
            for(int i=0;i<26;i++){
                if(bit[i].sum(r)-bit[i].sum(l-1) > 0){
                    ans++;
                }
            }
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 51716
#include <iostream>
#include <vector>

typedef long long ll;

using namespace std;

int main(){
    string s,t;cin >> s >> t;
    int n=s.size();
    bool judge=false;
    for(int i=0;i<=n;i++){
        if(s==t){
            judge=true;
        }
        s=s.back()+s.substr(0,s.size()-1);
    }
    if(judge)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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


int main() {
  int n, ans=0;
  cin >> n;
 
  int pre=-10;
  rep(i, n-1){
    int b;
    cin >> b;
    if(i==0){
      ans+= 2*b;
      pre = b;
      continue;
    }
    if(pre > b) ans = ans-pre+(2 * b);
    else ans+= b;
    pre = b;
  }
  
  cout << ans << endl;  
  return 0;
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (a % b == 0) return b;
    return gcd(b, a % b);

}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

class Solve {
public:
    void solve() {
        Int A, B;
        cin >> A >> B;
        Int ans = lcm(A, B);
        cout << ans << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto &__VA_ARGS__:(c))
using namespace std;
using ll = long long;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int N,M;
	cin>>N>>M;
	vector<pair<int,int>> a(N);
	pair<int,int> res;
	rep(i,0,M) {
		int p;
		string s;
		cin>>p>>s;
		p--;
		if (s=="AC") {
			if (a[p].first==0) {
				a[p].first=1;
				res.first++;
				res.second+=a[p].second;
			}
		} else {
			if (a[p].first==0) a[p].second++;
		}
	}

	cout<<res.first<<" "<<res.second<<'\n';
}


Measured memory_bytes: 1024
void main(){
	int a, b;
	readf("%d %d\n", &a, &b);
	if( a%3==0 || b%3==0 || (a+b)%3==0 ){
		writeln("Possible");
	}else{
		writeln("Impossible");
	}
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;      
// 1要素のみの入力
T inelm(T= int)(){
	return to!(T)( readln().chomp() );
}
     
// 1行に同一型の複数入力
T[] inln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
	return ln;
}


Measured memory_bytes: 2720
# -*- coding: utf-8 -*-
import math
import datetime

# 入力
#N = int(input())
#S = str(input())
#H, W = map(int, input().split())
A, B = map(int, input().split())

list = []
list.append(A)
list.append(B)
list.sort()

x = list[1]
list[1] -= 1
list.sort()
x += list[1]

print (x)


Measured memory_bytes: 3312
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	N, ans := scanInt(), 0
	for i := 0; i < N; i++ {
		ans += scanInt() - 1
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
int x[101], y[101], h[101];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> x[i] >> y[i] >> h[i];
     

    for (int cx = 0;  cx <= 100; cx++) {
        for (int cy = 0; cy <= 100; cy++) {
            int H= 0;
            for (int i = 0;  i < N; i++) {
                if (h[i] == 0)
                    continue;
                H = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
            }
            if (H == 0)
                continue;
            
            bool b = true;
            for (int i = 0; i < N; i++) {
                int hh = max(H -abs(x[i]-cx) - abs(y[i]-cy), 0);
                if (hh != h[i]) {
                    b = false;
                    break;
                }
            }
            if (!b)
                continue;
            cout << cx << " " << cy << " " << H << endl;
            return 0;

        }
    }


    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
 
int main(){
    u_int a;	// width
    u_int b;	// height
    while(std::cin >> a >> b){
        if(a == 0 && b == 0){
            break;
        }
		
		// initialization
        std::vector<std::vector<u_int>> path(a+1, std::vector<u_int>(b+1, 1));
        //for(u_int i = 0; i < a+1; ++i){
        //    path[i].resize(b+1, 1);
        //}
        
        // construction
        u_int n;
        std::cin >> n;
        for(u_int i = 0; i < n; ++i){
            u_int x, y;
            std::cin >> x >> y;
            path[x][y] = 0;
        }
        
        // out path
        for(u_int i = 0; i < a+1; ++i) path[i][0] = 0;
        for(u_int i = 0; i < b+1; ++i) path[0][i] = 0;
        
        
        for(u_int x = 1; x <= a; ++x){
            for(u_int y = 1; y <= b; ++y){
                if(path[x][y] != 0 && !(x == 1 && y == 1)){
                    path[x][y] = path[x-1][y] + path[x][y-1];
                }
            }
        }
         
        std::cout << path[a][b] << std::endl;
         
    }
    return 0;
}

Measured memory_bytes: 1208
#!/usr/bin python3
# -*- coding: utf-8 -*-

import bisect

n, t = map(int, input().split())
a = list(map(int, input().split()))
mx = 0
p = [0] * n
for i in range(n-1,-1,-1):
    mx = max(mx, a[i])
    p[i] = mx - a[i]
p.sort()
print(n-bisect.bisect_left(p, p[-1]))


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

int main()
{

    int flag = -1, count=0;
    string S;
    cin >> S;

    for (int i = 0; i < S.size();i++){
        if (i==0 && S.at(0) != 'A')
        {
            flag = 0;
            //cout << flag << endl;
        }

        if(i>=2 && i<S.size()-1){
            if(S.at(i)>='a'&&S.at(i)<='z'){

            }
            else if(S.at(i)=='C'){
                count++;
            }
            else
            {
                flag = 0;
            }
            
        }
            
        if (i==1 || i >=  S.size() - 1)
        {
            if (S.at(i) >= 'a' && S.at(i) <= 'z')
            {
            }
            else
            {
                flag = 0;
            }
        }
        //cout << i << " " << count << " " << flag << endl;
    }


    if(flag==0){
        cout << "WA" << endl;
    }
    else if(count!=1){
        cout << "WA" << endl;
    }

    else{
        cout << "AC" << endl;
    }
}


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

#define ll long long

int main(void){

    int n,m;
    cin>>n>>m;
    int x[m];
    for(int i=0;i<m;i++){
        cin>>x[i];
    }
    sort(x,x+m);

    int d[m-1];
    for(int i=0;i<m-1;i++){
        d[i]=abs(x[i]-x[i+1]);
    }
    sort(d,d+m-1);
    int ans=0;
    for(int i=0;i<m-1-n+1;i++){
        ans+=d[i];
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    a = na()
    b = na()

    a_cnt = 0
    b_cnt = 0

    for ai, bi in zip(a, b):
        tmp = bi - ai
        if tmp < 0:
            b_cnt += abs(tmp)
        elif tmp > 0:
            a_cnt += (tmp + 1) // 2
            b_cnt += tmp % 2
        # print(ai, bi, a_cnt, b_cnt)

    print("Yes" if a_cnt >= b_cnt else "No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 6608
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;


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

Measured memory_bytes: 512
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int calc(int x, int y, int z) {
    int ans = x * x + y * y + z * z + x * y + y * z + z * x;
    return ans;
}

int main() {
    int N;
    cin >> N;
    vi ans(10000, 0);
    for (int i = 1; i < 100; i++) {
        for (int j = 1; j < 100; j++) {
            for (int k = 1; k < 100; k++) {
                int num = calc(i, j, k);
                if (num <= N) {
                    ans.at(num - 1)++;
                }
            }
        }
    }
    for (int i = 0; i < N; i++) {
        cout << ans.at(i) << endl;
    }
}

Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	ll res = 0;
	if (a + b >= c)
	{
		res = c + b;
	}
	else
	{
		res = a + b + b + 1;
	}

	cout << res << endl;
}


Measured memory_bytes: 256
s = input()

for bit in range(1 << 3):
    ans = s[0]
    value = int(s[0])
    for i in range(3):
        if bit & (1 << i):
            ans += "+" + s[i+1]
            value += int(s[i+1])
        else:
            ans += "-" + s[i+1]
            value -= int(s[i+1])
    
    if value == 7:
        print(ans + "=7")
        exit()

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

int main(){
	int a[4];
	int b[4];
	int hit, blow;
	while(cin >> a[0] >> a[1] >> a[2] >> a[3]){
		cin >> b[0] >> b[1] >> b[2] >> b[3]; 
		hit = 0;
		blow = 0;
		for(int i = 0; i < 4; i++){
			if(b[i] == a[i]){
				hit++;
			}else{
				for(int j = 0; j < 4; j++){
					if(b[i] == a[j]){
						blow++;
						break;
					}
				}
			}
		}
		cout << hit << " " << blow << endl;
	}
	return 0;
}

Measured memory_bytes: 0
n = int(input())
A = list(map(int,input().split()))
A.sort()
q = int(input())
m = list(map(int,input().split()))

tar = max(max(m),sum(A))+1
dp = [[0]*tar for i in range(n+1)]
dp[0][0] = 1

for j in range(n):
    for k in range(tar):
        dp[j+1][k] = dp[j+1][k] or dp[j][k]

        if k >= A[j]:
            dp[j+1][k] = dp[j+1][k] or dp[j][k-A[j]]

for i in range(q):
    if dp[n][m[i]]:
        print("yes")
    else:
        print("no")



Measured memory_bytes: 5952
#include<bits/stdc++.h>
typedef long long int   LL;
typedef long double     LD;
#define OR              ||
#define AND             &&
#define nl              '\n'
#define S               string
#define inf             INT_MAX
#define SQR(a)          (a) * (a)
#define GCD(a, b)       __gcd(a, b)
#define pi              2.0*acos(0.0)
#define LCM(a, b)       (a * b) / GCD(a, b)
#define mem(a,b)        memset(a,b,sizeof(a))
#define srtv(v)         sort(v.begin(),v.end())
#define T               int t; cin>>t; while(t--)
#define boost		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inout           freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
using namespace std;

long long powerMod(long long number,long long power,long long mod)
{
    LL ret=0;

    if(power==0) return 1LL%mod;
    if(power==1) return number%mod;
    if(power%2==0)
    {
        ret=powerMod(number,power/2,mod);
        ret=(ret%mod*ret%mod)%mod;
        return ret%mod;
    }
    else
    {
        ret=powerMod(number,power/2,mod);
        ret=(ret%mod*ret%mod*number%mod)%mod;
        return ret%mod;
    }
}


int main()
{
    boost;

    int n;
    cin>>n;

    LL a[n];

    LD sm=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sm+=a[i];
    }

    sm=sm/(LD)n;

    LL ann=sm;
    double diff=sm-ann;

    LL sum=0;

    if(diff>0.5)
        sum=ceil(sm);
    else
        sum=floor(sm);


    LL ans=0;

        for(int i=0;i<n;i++)
        {
            ans=ans+((a[i]-sum)*(a[i]-sum));
        }
    cout<<ans;


    return 0;
}

/*

*/


Measured memory_bytes: 256
#include <vector>
#include <stdio.h>
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <random>
#include <time.h>
#include <cassert>

#define prev askdnsajd
#define rank asasdmdnasd
#define next lsjndajbs
#define hash asmdklansd
#define index asdklnas

using namespace std;

typedef long long ll;
typedef long double dbl;

template<class T>
void print(vector<T> s){
	for (T x : s)
		cout << x + 1 << " ";
	cout << endl;
}

bool check(string s, int a, int b){
	// cout << s << " " << a << " " << b << endl;
	int cnt = 0;
	for (int i = a; i <= b; i++){
		if (s[i] == '.')
			cnt = 0;
		else
			cnt++;
		if (cnt == 2)
			return false;
	}
	return true;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	string s;
	cin >> s;
	a--, b--, c--, d--;
	// cout << check(s, 1, 5) << endl;
	if (!check(s, b, d) || !check(s, a, c)){
		cout << "No\n";
		return 0;
	}
	if (c < d)
		cout << "Yes\n";
	else{
		int cnt = 0;
		for (int i = b - 1; i <= d + 1; i++){
			if (s[i] == '.')
				cnt++;
			else
				cnt = 0;
			if (cnt == 3){
				cout << "Yes\n";
				return 0;
			}
		}
		cout << "No\n";
	}
	return 0;	
}

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

int main(){
	int x;
	cin >> x;
	int maks = 0;
	for(int i=1;i<=31;i++){
		for(int j=2;j<=5;j++){
			//printf("%d %d\n", i ,j);
			if(pow(i,j) <= x){
				int r = pow(i,j);
				maks = max(maks, r);
			}else break;
		}
	}
	printf("%d\n", maks);
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector <pair <int, int> > a(n);
	vector <int> b(n);
	
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].first;
		a[i].second = i;
	}
		
	sort(a.begin(), a.end());
	
	for (int i = 0; i < n/2; i++)
		b[a[i].second] = a[n/2].first;
		
	for (int i = n/2; i < n; i++)
		b[a[i].second] = a[n/2-1].first;
	
	for (int i = 0; i < n; i++)
		cout << b[i] << endl;
		
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
int main()
{
char s[110],b[110];
cin>>s;
int a[27]={0},r=0,x=110,y,z;
int n=strlen(s);
for(int i=0;i<26;i++)
{
      bool d=true;
      for(int j=0;j<n;j++) {b[j]=s[j];if(s[j]==i+'a') d=false;}
      if(d) continue;
      else d=true;
      y=0;
      z=n-1;
      while(d)
      {
            d=false;
            for(int j=0;j<=z;j++) if(b[j]!=i+'a') d=true;
            if(!d) break;
            for(int j=0;j<z;j++)
            {
                  if(b[j+1]==i+'a') b[j]=i+'a';
            }
            y++;z--;
      }
      //cout<<y<<" "<<(char)(i+'a')<<"\n";
      x=min(x,y);
}
cout<<x;
return 0;
}

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

int main(){
    string str;
    int K;
    cin >> str;
    cin >> K;
    int sz = str.size();
    int change = 0;//今操作を加えている文字の位置
    while(K > 0){
        if(str[change] == 'a'){
            if(change+1 != sz){
                change++;
            }else{//今最後の文字を操作している。
                int sss = str[change] - 'a';
                int kok = (sss+K)%26;
                char ss='a';
                ss += kok;
                str[change] = ss;
                K = 0;
            }
        }else{
            int aho = 26 - (str[change]-'a');
            if(aho <= K){
                if(change+1 != sz){
                    str[change] = 'a';
                    K = K - aho;
                    change++;
                }else{//今最後の文字を操作している。
                    int sss = str[change] - 'a';
                    int kok = (sss+K)%26;
                    char ss='a';
                    ss += kok;
                    str[change] = ss;
                    K = 0;
                }
            }else{//残りの操作できる回数が少ない時
                if(change+1 != sz){
                    change++;
                }else{//今最後の文字を操作している。
                    int sss = str[change] - 'a';
                    int kok = (sss+K)%26;
                    char ss = 'a';
                    ss += kok;
                    str[change] = ss;
                    K = 0;
                }
                
            }
        }
    }
    cout << str << endl;
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define int long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define prvp(a) for(auto x : a) cout << "{" << x.ff << ',' << x.ss << "}";cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = 62;

inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(int a, int b){return (int)((long long) a * b % mod);}
inline int modexpo(int a, int b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(int a, int b){ return mul(a, modexpo(b, mod - 2));}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

const int N = 3e5 + 5;
int a[N];
int b[bit64];

void solve(){
  int n, i, j; cin >> n;
  forn(0, n, i){
    cin >> a[i];
    forn(0, bit64, j){
      if((a[i] >> j) & 1){
        b[j]++;
      }
    }
  }

  ll ans = 0;

  forn(0, bit64, i){
    ll p = b[i];
    ll q = n - p;
    q = mul(q, p);
    ll now = modexpo(2, i);
    now = mul(now, q);
    ans = add(ans, now);
  }

  cout << ans << '\n';

}

signed main(){
  fastio

  int t = 1;
  // cin >> t;
  while(t--){
    solve();
  }

  ktj();
}


Measured memory_bytes: 2560
inputs = []
STDIN.gets.chomp.to_i.times.map do
  inputs << STDIN.gets.chomp.split.map(&:to_i).sort.reverse.map{|i| i**2}
end

inputs.each do |i|
  result = i[0] == i[1] + i[2] ? 'YES' : 'NO'
  puts result
end

Measured memory_bytes: 8732
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

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

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; }

int main() {
    int n, w;
    cin >> n >> w;
    int weight[n];
    ll values[n];
    for (int i = 0; i < n; i++) {
        cin >> weight[i] >> values[i];
    }

    ll dp[n + 1][100000] = {};
    for (int i = 0; i < n; i++) {
        for (int sum_w = 0; sum_w <= w; sum_w++)
        {
            if (sum_w - weight[i] >= 0)
            {
                chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + values[i]);
            }
            chmax(dp[i + 1][sum_w], dp[i][sum_w]);
        }
    }

    cout << dp[n][w] << endl;
    return 0;
}

Measured memory_bytes: 82524
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

string upper(string str){
    for(int i = 0;i < str.size();i++){
		if ('a' <= str[i] && str[i] <= 'z')
    	{
    		str[i] = (str[i] - 'a' + 'A');
    	}
    }
    return str;
}

int main(){
	string W = "";
	string S = "";
	string T = "";
	int j = 0;
    int b = 0;
    int i = 0;
	cin >> W;
	getline(cin,T);
	do{
		S += T;
		getline(cin,T);
		T += " ";
	}while(T != "END_OF_TEXT ");
	T = "";
	S = upper(S);
	W = upper(W);
	while(i < S.size()){
			while(S[i] != ' '){
				T += S[i];
				i++;
			}
			if(T == W){
				b++;
			}
			T = "";
			i++;
		}
	cout << b << endl;
	return 0;
}

Measured memory_bytes: 1204
from collections import Counter

INF = 10**9 + 7

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
n, p = map(int, input().split())
li = Counter(prime_factorize(p))
ans = 1
for k, v in li.items():
  ans *= k ** (v // n)
print(ans)


Measured memory_bytes: 3316
#!/usr/bin/env python3
import sys


def solve(S: int, W: int):
    print("unsafe" if S<=W else "safe")
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    solve(S, W)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);


		int N = sc.nextInt();
		
		ArrayList<Integer> a = new ArrayList<Integer>();
		
		for(int i = 0 ; i< N ; i++) {
			
			a.add(sc.nextInt());
			
		}

		ArrayList<Integer> b = new ArrayList<Integer>(a);
		
		
		Collections.sort(b, Collections.reverseOrder());
		
		for(int i = 0; i< N ; i++) {
			
			if(a.get(i) == b.get(0)){
				System.out.println(b.get(1));
			} else {
				System.out.println(b.get(0));
			}
			
			
			
			
		}
		

	}

}

Measured memory_bytes: 94456
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
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;
}
long long dp[100][9];
const int MOD = 1000000007;
long long ruijo(int x, int n) {
    long long res = 1;
    rep(i, 0, n) { res *= x; }
    return res;
}
int main() {
    int H, W, K;
    cin >> H >> W >> K;
    //初期値(H=0)
    if(W == 1) {
        cout << 1 << endl;
        return 0;
    }
    rep(k, 0, W) {
        if(k == 0) {
            dp[0][0] = 1;
        } else {
            dp[0][k] = 0;
        }
    }
    // H=1の全パターン数
    int pat[9];
    pat[0] = 1;
    pat[1] = 1;
    rep(w, 2, 9) { pat[w] = pat[w - 1] + pat[w - 2]; }
    rep(h, 1, H + 1) {
        rep(k, 0, W) {
            if(k == 0) {
                dp[h][k] = (dp[h - 1][k] * pat[W - 1]) +
                           (dp[h - 1][k + 1] * pat[W - 2]);

                dp[h][k] = dp[h][k] % MOD;
            } else if(k == W - 1) {
                dp[h][k] = (dp[h - 1][k] * pat[W - 1]) +
                           (dp[h - 1][k - 1] * pat[W - 2]);

                dp[h][k] = dp[h][k] % MOD;
            } else {
                dp[h][k] = (dp[h - 1][k] * pat[k] * pat[W - k - 1]) +
                           (dp[h - 1][k - 1] * pat[k - 1] * pat[W - k - 1]) +
                           (dp[h - 1][k + 1] * pat[k] * pat[W - k - 2]);
                dp[h][k] = dp[h][k] % MOD;
            }
            // cout << "h:" << h << " k:" << k << " dp:" << dp[h][k] << endl;
        }
    }
    cout << dp[H][K - 1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    int n;
    cin >> n;
    vector<int> T(n);
    int sum = 0;
    rep(i, n)
    {
        cin >> T[i];
        sum += T[i];
    }
    int m;
    cin >> m;
    vector<int> P(m);
    vector<int> X(m);
    rep(i, m)
    {
        cin >> P[i];
        cin >> X[i];
    }
    for (int i = 0; i < m; i++)
    {
        int ans = sum;
        ans += X[i] - T[P[i] - 1];
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
s = input()
ans = 0
l = len(s)
for i in range(2**(l-1)):
  nums = [s]
  idx = 0
  #print(f'i={i}')
  for j in range(l-1):
    if i>>j&1:
      a = s[idx:j+1]
      b = s[j+1:]
      #print(f'j={j}')
      #print(f'idx={idx}, a={a}, b={b}')
      idx = j+1
      nums[-1] = a
      if b != '':
        nums.append(b)
  ans += sum(list(map(int, nums)))
  #print(nums)
  #print('----------------')
print(ans)

Measured memory_bytes: 9112
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  double l ;
  cin >> l ;
  double a = l/3 ;
  cout << SP(10) << a*a*a <<endl ;
  
  
  
  return 0 ;
}




Measured memory_bytes: 256
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        ret = 0
        while i > 0:
            ret += self.tree[i]
            i -= i & -i
        return ret

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

N, K = map(int, input().split())

bit = Bit(2000)

intra, inter = 0, 0
for i, a in enumerate(map(int, input().split())):
    bit.add(a, 1)
    intra += i + 1 - bit.sum(a)
    inter += bit.sum(a - 1)

mod = 10**9 + 7
ans = (intra * K * (K + 1) // 2) % mod
ans += (inter * (K - 1) * K // 2) % mod
print(ans % mod)


Measured memory_bytes: 41196