akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <iostream>
#include <limits>
#include <vector>

template <class Monoid>
struct SegmentTree {
  using T = typename Monoid::type;
  int N_, N;
  std::vector<T> dat;

  SegmentTree(const int N_) : N_(N_) {
    assert(N_ > 0);
    N = 1;
    while (N < N_) {
      N <<= 1;
    }
    dat.assign(2 * N - 1, Monoid::identity());
  }

  SegmentTree(const std::vector<T> &dat_) : N_(dat_.size()) {
    assert(N_ > 0);
    N = 1;
    while (N < N_) {
      N <<= 1;
    }
    dat.assign(2 * N - 1, Monoid::identity());
    std::copy(dat_.begin(), dat_.end(), dat.begin() + N - 1);
    for (int i = N - 2; i >= 0; i--) {
      dat[i] = Monoid::merge(dat[2 * i + 1], dat[2 * i + 2]);
    }
  }

  int size() { return N_; }

  void update(int key, T val) {
    assert(0 <= key && key < N_);

    key += N - 1;
    dat[key] = val;

    while (key > 0) {
      key = (key - 1) / 2;
      dat[key] =
          Monoid::merge(dat[2 * key + 1], dat[2 * key + 2]);  // rewrite here
    }
  }

  inline const T &operator[](const int k) const { return dat.at(N - 1 + k); }
  inline T &operator[](const int k) { return dat.at(N - 1 + k); }

  T query(int low, int high) {
    low += N, high += N;
    T ret = Monoid::identity();
    while (low < high) {
      if (low & 1) {
        ret = Monoid::merge(ret, dat[low - 1]);
        low++;
      }
      if (high & 1) {
        high--;
        ret = Monoid::merge(ret, dat[high - 1]);
      }
      low >>= 1, high >>= 1;
    }
    return ret;
  }
};

template <typename T>
struct RangeSumQuery {
  using type = T;
  static type identity() { return T(0); }
  static type merge(const type &l, const type &r) { return l + r; }
};

template <typename T>
struct RangeMinQuery {
  using type = T;
  static type identity() { return std::numeric_limits<T>::max(); }
  static type merge(const type &l, const type &r) { return std::min(l, r); }
};

template <typename T>
struct RangeMaxQuery {
  using type = T;
  static type identity() { return T(0); }
  static type merge(const type &l, const type &r) { return std::max(l, r); }
};

void aoj_min() {
  // https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_A
  int N, Q;
  std::cin >> N >> Q;
  SegmentTree<RangeMinQuery<int>> rmq(N);
  for (int i = 0; i < Q; i++) {
    int t, x, y;
    std::cin >> t >> x >> y;
    if (t == 0) {
      rmq.update(x, y);
    } else {
      std::cout << rmq.query(x, y + 1) << '\n';
    }
  }
}

void aoj_sum() {
  int N, Q;
  std::cin >> N >> Q;
  SegmentTree<RangeSumQuery<int>> rsq(N);
  for (int i = 0; i < Q; i++) {
    int t, x, y;
    std::cin >> t >> x >> y;
    x--;
    if (t == 0) {
      rsq.update(x, rsq[x] + y);
    } else {
      std::cout << rsq.query(x, y) << '\n';
    }
  }
}

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // aoj_min();
  aoj_sum();
  return 0;
}


Measured memory_bytes: 3812
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
int a[100002];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    a[0]=0;
    for(int i=1;i<=n;i++) cin>>a[i];
    a[n+1]=0;
    ll lall=0;
    for(int i=0;i<=n;i++){
        lall+=abs(a[i+1]-a[i]);
    }
    int skipa[n+1];
    for(int i=1;i<=n;i++){
        skipa[i]=abs(a[i+1]-a[i-1]);
    }
    ll ans[n+1];
    for(int i=1;i<=n;i++){
        ans[i]=lall-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+ skipa[i];
        cout <<ans[i]<< "\n";
    }
}

Measured memory_bytes: 2816
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

template<typename T>inline void upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline void upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

inline int read(int x) {
	cout<<x<<endl;
	string s;
	cin>>s;
	if (s[0]=='V') return 0;
	if (s[0]=='M') return 1;
	return 2;
}
int main()
{
	int n=gi(),p=0;
	int k=read(0);
	read(n-1);
	for (int t=1<<20;t;t>>=1)
		if (p+t<n&&(read(p+t)==k)==(t%2==0))
			p+=t;
	read(p+1);
	return 0;
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int a[100010];
ll tot = 0;

int main(){
    int n;
    cin >> n;
    rep(i, n) cin >> a[i+1];
    rep(i, n+1){
        tot += abs(a[i+1] - a[i]);
    }

    for(int i = 1; i <= n; i++){
        ll d = abs(a[i+1] - a[i-1]) - (abs(a[i+1] - a[i]) + abs(a[i] - a[i-1]));
        cout << tot + d << endl;
    }

    return 0;
}


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

int main() {
  int N, x, k, j ;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x;
    for (j= 0; x % 2 == 0; j++) {
      x /= 2;
    }
    if (i == 0 || k > j) {
      k = j;
    }
  }
   cout << k << endl; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

ll n;
vector<ll>cnt;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>n;
    cnt.resize(n+1);
    ll ans=0;
    for(int i=1;i<=n;i++)cnt[i]++;
    for(int i=2;i<=n;i++){
        for(int j=i;j<=n;j+=i){
            cnt[j]++;
        }
    }
    for(ll i=1;i<=n;i++){
        ans+=i*cnt[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 81336
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
char s[210][210];
bool graph[210][210];
bool vis[210];
signed main(){
    int n;
    cin>>n;
    vector<vector<int>>v(n,vector<int>());
   for (int i = 0; i < n; i++)
   {
       cin>>s[i];
   }
   for (int i = 0; i < n; i++)
   {
       for (int j = 0; j < n; j++)
       {
           if(s[i][j]=='1') v[i].push_back(j);
       }
   }
   int ans=0;
   //どれを1つの集合にするか
  
   int err=0;
   bool ok=false;
   for (int ver = 0; ver < n; ver++)
   {
       queue<int>q;
       int tmp=0;
       ok=false;
       q.push(ver);
       vector<int>w(n,0);
       //for(auto &u :v[ver]) q.push(u);
       w[ver]=1;
       vis[ver]=true;
        while(!q.empty()){
           int x=q.front();
           q.pop();
           for(auto &u :v[x]){
               if(!vis[u]){
               q.push(u);
               vis[u]=true;
               w[u]=w[x]+1;
               }
               else{
                   if(abs(w[u]-w[x])!=1){
                        cout<<-1<<endl;
                        return 0;
                   }
               }
           }
           if(ok)break;
            }
        for (int i = 0; i < n; i++)
        {
            chmax(tmp,w[i]);
        }
       // cerr<<tmp<<endl;   
       chmax(ans,tmp);
       for (int i = 0; i < n; i++)
       {
           vis[i]=false;
       }
       
   }
 
   cout<<ans<<endl;
   
   
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,m,ans=0;
  cin >> n >> m;
  long long a[m];
  for(int i=0;i<m;i++){
    cin >> a[i];
    ans+=a[i];
  }
  cout << ans/(n+1)+(ans%(n+1)>0) << endl;
  return 0;
}


Measured memory_bytes: 3136
N,M,C=gets.split.map(&:to_i)
bs=gets.split.map(&:to_i)

ret = 0
N.times do
    as=gets.split.map(&:to_i)
    t = C
    as.zip(bs).each do |a,b|
        t+=a*b
    end
    ret += 1 if t > 0
end

puts ret


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

const string YES = "YES";
const string NO = "NO";

bool check5(string s){
    return (s == "dream")|| (s == "erase");
}

bool check7(string s){
    return s == "dreamer";
}

bool check6(string s ){
    return s == "eraser";
}
void solve(std::string S){
    ll n = S.length();
    if(n<5) {
        cout << NO << endl;
        return;
    }
    ll i= n;
    while(i>=5){
        
        if(i-7 >= 0 && check7( S.substr(i-7, 7))){
            
            i-= 7; continue;
        }
        else if(i-6 >=0 && check6(S.substr(i-6, 6))){
            i-= 6; continue;
        }
        else if(i-5 >= 0 && check5(S.substr(i-5, 5))){
            i-= 5; continue;
        }
        else {
            cout << NO << endl;
            return;
        }
    }
    cout << YES << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

int main(int argc, char const *argv[])
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;

    if(x >= r && y >= r && x + r <= w && y + r <= h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl; 
    
    return 0;
}



Measured memory_bytes: 3116
import collections
N = int(input())
A_list = list(map(int, input().split()))

left = [i - a for i, a in enumerate(A_list)]
right = [i + a for i, a in enumerate(A_list)]

left_c = collections.Counter(left)
right_c = collections.Counter(right)

count = 0
for i in left_c:
    if i in right_c:
        count += left_c[i] * right_c[i]

print(count)

Measured memory_bytes: 166672
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <unordered_map>

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

ll N,M,ans;
const ll nmax=8;
const ll mmax=8*(8-1)/2;
ll graph[nmax+1][nmax+1];
bool visited[nmax],allvisited;

ll f(ll a,ll b){
    ll da=0;
    ll db=0;
    for(ll i=0;i<=10;i++){
        if((a/ll(pow(10,i)))>0) da++;
        if((b/ll(pow(10,i)))>0) db++;
    }
    return max(da,db);
}


int main(){
    ll N;
    ll a,b;
    cin>>N;
    for(ll i=floor(sqrt(N));1<=i;i--){
        if(N%i==0){
            a=i;
            b=N/i;
            break;
        }
    }
    cout<<f(a,b)<<endl;
    return 0;
}


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

const ll INF = 1LL << 60;

// i: 何日め
// j: 前日に何を選んだか 0: A, 1: B, 2: C
// dp[i][j] 

ll N;
ll dp[100100][3];
int main() {
    cin >> N;
    vector<ll> a(N), b(N), c(N);
    rep(i, N) cin >> a[i] >> b[i] >> c[i];

    // 初日
    dp[1][0] = a[0];
    dp[1][1] = b[0];
    dp[1][2] = c[0];

    // 2日目
    for (int i = 1; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            // from: j
            if (j == 0) {
                // 1, 2
                dp[i + 1][0] = max(dp[i + 1][0], dp[i][0]);
                dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + b[i]);
                dp[i + 1][2] = max(dp[i + 1][2], dp[i][0] + c[i]);
            } else if (j == 1) {
                // 0, 2
                dp[i + 1][1] = max(dp[i + 1][1], dp[i][1]);
                dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + a[i]);
                dp[i + 1][2] = max(dp[i + 1][2], dp[i][1] + c[i]);
            } else {
                // 0, 1
                dp[i + 1][2] = max(dp[i + 1][2], dp[i][2]);
                dp[i + 1][0] = max(dp[i + 1][0], dp[i][2] + a[i]);
                dp[i + 1][1] = max(dp[i + 1][1], dp[i][2] + b[i]);
            }
        }
    }

    ll ans = 0;
    rep(j, 3) {
        ans = max(ans, dp[N][j]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <functional>
#include <utility>
using namespace std;
typedef long long ll;

int main(){
  int M1,D1,M2,D2;
  cin >> M1 >> D1 >> M2 >> D2;

  if((M1 + 1) % 12 == M2%12)cout << 1 << endl;
  else cout << 0 << endl;

  return 0;
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
       PROGRAM-ID. ATCODER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  indata PIC 9(20).
       01  r PIC 9(20).
       01 disp   PIC Z(10)9.
       PROCEDURE DIVISION.
        ACCEPT indata.
        compute r = indata * indata.
        MOVE FUNCTION TRIM(r) to disp.
        display disp

        

       STOP RUN.


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

#define INT int64_t
#define REP(i,a,b) for(INT i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
int64_t n,m;

cin >> n >> m;
if(n > 2 && m > 2){
	n-=2;
	m-=2;
}else{
	if(n==1 && m==1) n=1;
	else if(n == 1 && m >2) m-=2;
	else if(m == 1 && n >2) n-=2;
	else n=0;
}
//if(n <= 2 && m <= 2){ n=0; m=0;}
cout<<n*m<<endl;

return 0;
}


Measured memory_bytes: 256
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cassert>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll n,x,m;
    cin>>n>>x>>m;
    //idいつ訪れたか
    vll id(m,-1);
    vll a;
    ll len=0;
   
    while(id[x]==-1){
        a.push_back(x);
        id[x]=len;
        len++;
        x=(x*x)%m;
    }

    ll loop_sum=0;
    for(int i=id[x];i<len;i++){
        loop_sum+=a[i];
    }

    ll c=len-id[x];
    ll ans=0;
    if(n<=len){
        rep(i,n)ans+=a[i];       
    }else{
        rep(i,len)ans+=a[i];
        n-=len;
        ans+=loop_sum*(n/c);
        n%=c;
        rep(j,n)ans+=a[id[x]+j];
    }

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

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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define dump(x)  cout << #x << " = " << (x) << endl
#define vuniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mins(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

int main(){
    ll n, ans = 0;
    string s;
    map<string, ll> m;
    cin >> n;
    for (ll i = 0; i < n; i++) {
        cin >> s;
        asort(s);
        m[s]++;
    }

    for (auto e : m) {
        ll cnt = e.second * (e .second - 1) / 2;
        ans += cnt;        
    }

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

Measured memory_bytes: 11372
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    int N,K;
    ArrayList<Integer>[] v;
    private void solve() {
        N = nextInt();
        K = nextInt();

        int uToV = N * (N - 1) / 2 - (N - 1);
        if (uToV < K) {
            out.println(-1);
            return;
        }

        v = new ArrayList[N];
        for(int i = 0;i < N;i++) {
            v[i] = new ArrayList<>();
        }

        for(int i = 1;i < N;i++) {
            v[0].add(i);
        }

        int s = 1;
        int t = 2;
        for(int i = 0;i < uToV - K;i++) {
            if (t == N) {
                s++;
                t = s + 1;
            }
            v[s].add(t);
            t++;
        }

        int M = 0;
        for(int i = 0;i < N;i++) {
            M += v[i].size();
        }
        out.println(M);

        for(int i = 0;i < N;i++) {
            for(int u : v[i]) {
                int a = i + 1;
                int b = u + 1;
                out.println(a + " " + b);
            }
        }
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

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

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


Measured memory_bytes: 22996
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

template<class T = lint>
vector<T> Dijkstra(vector<vector<pair<int, T>>> &edges, int st) {

	int V = edges.size();
	const T INF = numeric_limits<T>::max();
	vector<T> dist(V, INF);
	dist[st] = 0;

	priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> que;
	que.emplace(dist[st], st);

	while (!que.empty()) {
		T cost;
		int idx;
		tie(cost, idx) = que.top();
		que.pop();

		if (dist[idx] < cost) continue;
		for (auto &e : edges[idx]){
			auto tmp_cost = cost + e.second;
			if (dist[e.first] > tmp_cost) {
				dist[e.first] = tmp_cost;
				que.emplace(dist[e.first], e.first);
			}
 		}
	}

	return dist;

}

int main() {

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

	int N;
	cin >> N;

	int u, v, len;
	vector<vector<pair<int, int>>> edges(N);

	for (int i = 0; i < N - 1; i++) {
		cin >> u >> v >> len;
		edges[u - 1].emplace_back(make_pair(v - 1, len % 2));
		edges[v - 1].emplace_back(make_pair(u - 1, len % 2));
	}

	auto ans = Dijkstra<int>(edges, 0);

	for (const auto& i: ans){
		if (i % 2) cout << '1' << "\n";
		else cout << '0' << "\n";
	}

	return 0;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > ve;
int dfs(int start,int *mark,int *length)
{
    mark[start]=1;
    int len=ve[start].size();
    int maximum=0;
    for(int i=0;i<len;i++)
    {
        if(mark[ve[start][i]]==0)
        {
            maximum=max(maximum,dfs(ve[start][i],mark,length));
        }
        else{
            maximum=max(maximum,length[ve[start][i]]+1);
        }
    }
    length[start]=maximum;
    return (maximum+1);
}
int main(void)
{
    int n,m;
    cin>>n>>m;
    //int income[n+1]={0};
    int length[n+1]={0};
    int mark[n+1]={0};
    ve.resize(n+1);
    int start,end;
    for(int i=1;i<=m;i++)
    {
        cin>>start>>end;
        ve[start].push_back(end);
        //income[end]=1;
    }
    //dfs(1,mark,length);
    int fake=0;
    for(int i=1;i<=n;i++)
    {
        if(mark[i]==0)
        {
            fake=dfs(i,mark,length);
            //printf("hello\n");
        }
    }
    int maximum=0;
    for(int i=1;i<=n;i++)
    {
        if(length[i]>=maximum)
        maximum=length[i];
    }
    cout<<maximum<<endl;
}

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

// #define int ll
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define fastio    ios::sync_with_stdio(0); cin.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp        make_pair
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second

int inf(0x3fffffff);
int mod(1000000007);
double pi(acos(-1.0));

int32_t main() {
  fastio;
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif

  int n;
  cin >> n;
  ll cur = 1;
  bool ok = true;
  while (n--) {
    ll x;
    cin >> x;
    if (x == 0) {
      cout << 0;
      return 0;
    }
    else if (x > 1000000000000000000 / cur) ok = false;
    else cur *= x;
  }
  if (ok) cout << cur;
  else cout << -1;

  return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int N,temp;
    int count = 0;
    vector<int> rt;
    cin>>N;
    while(cin>>temp){
        rt.push_back(temp);
    }
    for(int i = 0;i<N;i++){
        for (int j=N-1;j>i;j--){
            if(rt[j]<rt[j-1]){
                count++;
                temp = rt[j];
                rt[j] = rt[j-1];
                rt[j-1] = temp;
            }
        }
        if(i!=N-1)
            cout<<rt[i]<<" ";
        else
            cout<<rt[i]<<endl;
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3132
#include <iostream>
#include <algorithm>
using namespace std;
int n;
long long x = 0;
int main()
{
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  cin >>n;
  for (int i = 1; i <= n; ++i)
  {
    for (int j = 1; j <= n; ++j)
    {
      int g = __gcd(i, j);
      for (int k = 1; k <= n; ++k)
      {
        x += __gcd(g, k);
      }
    }
  }
  cout <<x << '\n';
}


Measured memory_bytes: 3648
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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

//想定解答との絶対誤差または相対誤差が 10−6以下の場合+1以上だしておく。適当に15とかでもおｋ．
//cout << fixed << setprecision(15);

int main() {
    int N, q;
    cin >> N;
    vi a(N);
    rep(i, 0, N) {
        cin >> a[i];
    }
    cin >> q;
    vector<pair<int, bool> > m(q);
    rep(i, 0, q) {
        cin >> m[i].first;
        m[i].second = false;
    }
    ll res = 0;
    //1<<nは2^n
    //2^nは全パターン数と一致
    //<<ビット(2進数)を左へシフトする
    //bit->0-7
    //2進数は先頭に0bをつけて表す
    rep(bit, 0, 1<<N) {
        bool ok = true;
        vector<int> S;
        int sum = 0;
        rep(i, 0, N) {
            if (bit & (1<<i)) {
                S.push_back(i);
                sum += a[i];
            }
        }
        rep(i, 0, m.size()) {
            if (sum == m[i].first) {
                m[i].second = true;
            }
        }
    }
    rep(i, 0, m.size()) {
        cout << (m[i].second ? "yes" :  "no") << endl;
    }
    return 0;
}



Measured memory_bytes: 3160
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false); cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
int main() {
    IO;
  
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if (a[0] == a[1] && a[1] == a[2]) {
        cout << 0;
        return 0;
    }
    int cnt = a[2] - a[1];
    a[0] += a[2] - a[1];
    a[1] = a[2];
    int need = (a[1] - a[0]) / 2;
    a[0] += 2 * need;
    cnt += need;
    if (a[0] < a[1]) cnt += 2;
    cout << cnt; 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int cnt = 0;
  string a,b;cin>>a>>b;
  for(int i=0;i<a.size();i++){
    if(a[i]!=b[i]) cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;

  long long ans = 1;
  for (int i = 0; i < n; i++) {
    if (i == 0) ans *= k;
    else ans *= (k - 1);
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline LL rd() {
	char ch=nc(); LL i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int N=1e5+50;
int n, m, b[N], cir[N], vis[N], tot;
LL k, a[N], c[N];
int main() {
	n=rd();
	for(int i=1;i<=n;i++) a[i]=rd();
	for(int i=0;i<n;i++) a[i]=a[i+1]-a[i];
	m=rd(); k=rd();
	for(int i=1;i<n;i++) b[i]=i;
	for(int i=1;i<=m;i++) {int x=rd(); swap(b[x], b[x-1]);}
	for(int i=1;i<n;i++) {
		if(!vis[i]) {
			cir[tot=1]=i; vis[i]=1;
			for(int p=b[i];!vis[p]; p=b[p]) cir[++tot]=p, vis[p]=1;
			int t=k%tot;
			for(int j=1;j<=tot;j++) {
				int now=cir[j], tar=cir[((j+t)>tot) ? (j+t-tot) : (j+t)];
				c[now]=a[tar];
			}
		}
	}
	for(int i=1;i<=n;i++) a[i]=a[i-1]+c[i-1], printf("%lld.0\n",a[i]);
}

Measured memory_bytes: 4480
def can_fill(image, k, v):
    for y in range(v[1], v[3] + 1):
        for x in range(v[0], v[2] + 1):
            m = image[y][x]
            if m != k and m != '*':
                return False
    return True

def is_safe(image, p):
    keys = list(p.keys())
    i = 0
    while i < len(keys):
        k = keys[i]
        v = p[k]
        if can_fill(image, k, v):
            for y in range(v[1], v[3] + 1):
                for x in range(v[0], v[2] + 1):
                    image[y][x] = '*'
            keys.remove(k)
            i = 0
        else:
            i += 1
    return len(keys) == 0

n = int(input())
for i in range(n):
    h, w = map(int, input().split(' '))
    image = [list(input()) for y in range(h)]
    p = {}
    for y in range(h):
        for x in range(w):
            m = image[y][x]
            if m != '.':
                if m not in p:
                    p[m] = [x, y, x, y]
                else:
                    p[m][0] = min(p[m][0], x)
                    p[m][1] = min(p[m][1], y)
                    p[m][2] = max(p[m][2], x)
                    p[m][3] = max(p[m][3], y)
    print('SAFE' if is_safe(image, p) else 'SUSPICIOUS')

Measured memory_bytes: 5624
N = int(input())
XU = [input().split() for i in range(N)]

ans = 0.0
for i in range(N):
   x = float(XU[i][0])
   u = XU[i][1]
   if u == 'JPY':
       ans += x
   else:
       ans += x * 380000.0

print(ans)

Measured memory_bytes: 3060
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
ans = 0
d = readInts()
for a,b in combinations(d,2):
    ans += a*b
print(ans)


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

using namespace std;

int main()
{

    int k,s,c=0;
    cin>>k>>s;
    for(int i=0; i<=k; i++){
    for(int j=0; j<=k; j++)
    {
        int x;
        if(s-(i+j)>=0)
        x=s-(i+j);

        if(i+j+x==s&&x<=k)
            c++;

    }
    }
   cout<<c<<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;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(3*n);
	rep(i,3*n) scanf("%d",&a[i]);

	sort(a.rbegin(),a.rend());

	lint ans=0;
	deque<int> Q(a.begin(),a.end());
	while(!Q.empty()){
		Q.pop_front();
		ans+=Q.front();
		Q.pop_front();
		Q.pop_back();
	}
	printf("%lld\n",ans);

	return 0;
}


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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

        int N;
        std::cin >> N;

        vector<int> sum_W(N + 1, 0);
        for(int i = 1; i <= N; i++) {
            int w;
            std::cin >> w;
            sum_W[i] = w + sum_W[i - 1];
        }

        auto ans = INF;
        for(int i = 1; i < N; i++) {
            auto diff = abs(sum_W[i] - (sum_W.back() - sum_W[i]));
            ans = min(ans, diff);
        }

        std::cout << ans << std::endl;

        // auto itr = lower_bound(sum_W.begin(), sum_W.end(), sum_W.back() / 2);
        // std::cout << abs(*itr - (sum_W.back() - *itr)) << std::endl;
    }
    catch(const exception& e) {
        std::cout << e.what() << std::endl;
        exit(1);
    }
    return 0;
}


Measured memory_bytes: 256
def gcd(p, q):
    if p < q:
        p, q = q, p
    while q > 0:
        p, q = q, p%q
    return p

n = int(input())
ans = 1
for i in range(n):
  t = int(input())
  ans = ans*t//gcd(ans, t)
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<algorithm>
#include<functional>
using namespace std;
 
int n;
int s=0;
int a[45];

 
int main()
{
	cin>>n;

	if(n==0 || n==1){
		cout<<1<<endl;
		return 0;
	}
	a[0]=1;
	a[1]=1;

	for(int i=1;i<n;i++){
	s=a[i]+a[i-1];
	a[i+1]=s;
	}

	cout<<s<<endl;

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((int)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;


////////////////////////////////////////////////////////


int main() {
    ll n, m; cin >> n >> m;
    Vp p(m);
    rep(i, 0, m){
        ll a, b; cin >> a >> b;
        p[i].first = b; p[i].second = a;
    }
    sort(ALL(p));
    Vl v = {};
    rep(i, 0, m){
        ll a = p[i].second, b = p[i].first;
        bool f = false;
        rep(j, 0, sz(v)){
            if(a < v[j] && v[j] <= b) f = true;
        }
        if(f) continue;
        v.push_back(b);
    }
    ll ans = sz(v);
    co(ans);

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned long long
#define ld long double

#define mod 1000000007
#define EULER 2.7182818284
#define INF 1000000000

#define pb push_back
#define ins insert
#define IT iterator
#define PQ priority_queue
#define    nl           "\n"
#define fi first
#define se second
#define maxe max_element
#define mine min_element
#define er erase
#define lb lower_bound
#define ub upper_bound

#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()

#define mem(v,i) memset(v,i,sizeof(v)) // v is array. To set all elements to 0 or -1 only. mem(arr,0);


#define repab(i,a,b) for(int i=(a);i<=(b);i++)
#define reprab(i,a,b) for(int i=(a);i>=(b);i--)
#define repll(i,a,b) for(ll i=(a);i<=(b);i++)
#define rep(i,n) for(int i=(0);i<(n);i++)
#define repr(i,n) for(int i=(n);i>=0;i--)
#define bs bitset
#define bpc(a) __builtin_popcount(a)
#define tc int t;cin>>t;while(t--)
template<typename T> void TIME(T start, T end)
{
#ifndef ONLINE_JUDGE
    double time_taken =  chrono::duration_cast<chrono::nanoseconds>(end - start).count();
    time_taken *= 1e-9;
    cout << "\nExecuted in: " << fixed
         << time_taken << setprecision(9);
    cout << " sec";
#endif
}

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

ll max(ll a,ll b)
{
    if(a>b)return a;return b;
}
ll min(ll a,ll b)
{
    if(a<b)return a;return b;
}

ll mypow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    return gcd(b,a%b);
}
//..............................!!!!!!Get ready to fight!!!!!!............................


int main()
{   
     auto start = chrono::high_resolution_clock::now();
    fast
    ll a;
    cin>>a;
    ll ans=a+a*a+a*a*a;
    cout<<ans<<nl;
    auto end = chrono::high_resolution_clock::now();
    TIME(start, end);
    return 0;
}

Measured memory_bytes: 3608
N, X, D = gets.split.map(&:to_i)

(puts X == 0 ? 1 : N + 1; exit) if D == 0
x, d = X, D
h = Hash.new{|h, k| h[k] = []}
(0 .. N).each do |i|
  l = x*i + i*(i - 1)/2 * d
  r = x*i + i*(N - i + N - 1)/2 * d
  h[l % d] << [l/d, r/d + 1]
end
ans = 0
h.values.each do |a|
  lst = -10**18
  a.sort.each do |s, e|
    if lst < s
      ans += e - s
      lst = e
    end
    if lst < e
      ans += e - lst
      lst = e
    end
  end
end
puts ans

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

bool check(string s, ll i, ll j)
{
  while(i<j)
  {
    if(s[i]!=s[j])
      return false;
    i++;j--;
  }
  return true;
}
int main()
{
  string s;
  cin>>s;
  ll n=s.size();
  if(check(s,0,n-1) && check(s, 0, n/2-1) && check(s, n/2+1, n-1))
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func isKaisu(a int) bool {
	var digits []int
	for a > 0 {
		digits = append(digits, a%10)
		a /= 10
	}
	for i := 0; i < len(digits)/2; i++ {
		if digits[i] != digits[len(digits)-1-i] {
			return false
		}
	}
	return true
}

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	var sum int
	for i := a; i <= b; i++ {
		if isKaisu(i) {
			sum++
		}
	}
	fmt.Println(sum)
}


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

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

    bool r = 
        (S.find('a') != std::string::npos) &&
        (S.find('b') != std::string::npos) &&
        (S.find('c') != std::string::npos);

    if (r) {
        std::cout << "Yes" << std::endl;
    }   
    else {
        std::cout << "No" << std::endl;
    } 

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
int main()
{
	while(1)
	{
		int n;
		cin >> n;
		if(n == -1) return 0;
		int v = 0;
		if(n <= 10) v = 1150;
		else if(n <= 20) v = 1150+(n-10)*125;
		else if(n <= 30) v = 2400+(n-20)*140;
		else v = 3800+(n-30)*160;
		cout << 4280-v << endl;
	}
}

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

int main(void){
    string str;
    cin >> str;
    int count, i;

    for(i = 0, count = 0; i < 4; i++){
        if(str[i] == '2'){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
MOD = 998244353

n = int(input())
D = list(map(int,input().split()))
if D[0]!=0:
    print(0)
    exit()
M = max(D)
L = [0]*(M+1)
for i in range(n):
    L[D[i]] += 1
if L[0]!=1:
    print(0)
else:
    ans = 1
    for i in range(1,M+1):
        ans *= L[i-1]**L[i]%MOD
    print(ans%MOD)

Measured memory_bytes: 53172
let () =
  let n = Scanf.scanf "%d " (fun x -> x) in
  let s = Array.init n (fun _ -> Scanf.scanf "%c"
                                   (fun x -> x)) in
  let result = ref n in
  let left = Array.make n 0 in
  let right = Array.make n 0 in
  
  for i = 1 to (n-1) do
    if s.(i-1) = 'W' then
      left.(i) <- left.(i-1) + 1
    else
      left.(i) <- left.(i-1)
  done;
  for i = 1 to (n-1) do
    let i = n-1-i in
    if s.(i+1) = 'E' then
      right.(i) <- right.(i+1) + 1
    else
      right.(i) <- right.(i+1)
  done;
  for i = 0 to (n-1) do
    let res = left.(i) + right.(i) in
    if res < !result then
      result := res
  done;
  Printf.printf "%d\n" !result



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

int main() {
  int N; cin >> N;
  int a[N]; rep(i,0,N) cin >> a[i];
  
  for (int i =N-1; i>=0; i-=2) {
    if (i==N-1) cout << a[i];
    else cout <<" " << a[i];
  }
  for (int i = N%2; i<=N-1; i+=2) {
    cout << " " << a[i];
  }
}

Measured memory_bytes: 4320
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct E{int to,co,ti;};
struct P{int tim,idx,res;};
bool operator <(const P &a,const P &b){return a.tim>b.tim;}
int ans[50][5001],cnt,n,m,s;

signed main(){
  memset(ans,-1,sizeof(ans));
  cin>>n>>m>>s;
  vector<E> edge[n];
  vector<int> c(n),d(n),fans(n,-1);
  while(m--){
    int u,v,a,b;cin>>u>>v>>a>>b;u--;v--;
    edge[u].push_back({v,a,b});
    edge[v].push_back({u,a,b});
  }
  for(int i=0;i<n;i++)cin>>c[i]>>d[i];
  priority_queue<P> que;
  que.push({0,0,min(5000LL,s)});
  while(que.size()){
    P p=que.top();que.pop();
    if(~ans[p.idx][p.res])continue;
    ans[p.idx][p.res]=p.tim;
    if(fans[p.idx]<0){
      fans[p.idx]=p.tim;
      if(++cnt==n)break;
    }
    for(auto q:edge[p.idx])
      if(p.res>=q.co&&!~ans[q.to][p.res-q.co])
        que.push({p.tim+q.ti,q.to,p.res-q.co});
    if(p.res+c[p.idx]<=5000)que.push({p.tim+d[p.idx],p.idx,p.res+c[p.idx]});
  }
  for(int i=1;i<n;i++)cout<<fans[i]<<endl;
}


Measured memory_bytes: 17428
#include<iostream>
using namespace std;
 
int main(){
  int H,W,a,i;
  
  cin >> H >> W;
  while(H > 0 && W > 0){
      a = H;
      i = W;
      while(a > 0){
          while(i > 0){
              cout << "#";
              i = i - 1;
          }
          cout << endl;
          i = W;
          a = a - 1;
      }
      cout << endl;
      cin >> H >> W;
  }
  
      
      

  return 0;		 
}
		   


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;

const string YES = "Yes";
const string NO = "No";

void solve()
{
  ll a;
  scanf("%lld",&a);
  ll b;
  scanf("%lld",&b);
  ll c;
  scanf("%lld",&c);
  ll d;
  scanf("%lld",&d);
  if ((abs(a-b)<=d&&abs(b-c)<=d)||abs(a-c)<=d) cout << YES << endl;
  else cout << NO << endl;
}

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


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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << ":" << #x << " = " << (x) << endl;
#else
#define dbg
#endif

#pragma endregion Macros

int main()
{
    int H,W;
    cin >> H >> W;
    vector<string> s(H);
    rep(i, H) cin >> s[i];

    const int INF = 100100100;

    vector<vector<int>> c(H, vector<int>(W, INF));

    queue<tuple<int,int>> q;
    q.push(make_tuple(0,0));
    c[0][0] = 0;

    int dh[] = {0, 1};
    int dw[] = {1, 0};

    while(!q.empty()){
        auto p = q.front();
        q.pop();

        int h = get<0>(p);
        int w = get<1>(p);

        int cost = c[h][w];

        for(int i=0;i<2;i++){
            int nh = h + dh[i];
            int nw = w+dw[i];

            if(nh < H && nw < W) {
                int a = (s[h][w] == s[nh][nw] ? 0 : 1);
                if(chmin(c[nh][nw], c[h][w]+a)){
                    q.push(make_tuple(nh, nw));
                }
            }
        }
    }

    int ans = c[H - 1][W - 1];

    if (s[0][0] == '#' && s[H - 1][W - 1] == '#'){
        ans = ans / 2 + 1;

    } else if(s[0][0] == '.' && s[H - 1][W - 1] == '.'){
        ans = ans / 2;
    }else{
        ans = (ans + 1) / 2;
    }


    cout << ans << endl;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9+7;
const int N = 1e6+10;
int arr[N];
int dp[N];
signed main(){
  int n; int X,Y;
  cin>>n>>X>>Y;
  for(int i=0;i<n;i++){
  	cin>>arr[i];
  }
  if(X>Y) swap(X,Y);
  arr[n]=arr[n-1]+Y;
  dp[0]=1;
  dp[1]=1+(arr[1]-arr[0]>=Y);
  int sum=0,cur=0;
  int fl=1;
  for(int i=2;i<n+1;i++){
    if(arr[i-1]-arr[i-2]<X){
    	fl=0;
    }
    while(cur<i-2&&arr[i]-arr[cur]>=Y&&(cur==0||arr[cur+1]-arr[cur-1]>=X)){ 
    	sum+=dp[cur++];
    }
    if(arr[i-1]-arr[i-2]<X){
     	sum=0,cur=i-2;
 	}
    dp[i]=fl+sum;
    if(arr[i]-arr[i-1]>=Y){ 
    	dp[i]+=dp[i-1];
    }
    if(arr[i]-arr[i-2]>=Y){
      if(i-2==0||arr[i-1]-arr[i-3]>=X){
        dp[i]+=dp[i-2];
   	  }
    }
    dp[i]%=mod;
  }
  cout<<dp[n];
  return 0;
}


Measured memory_bytes: 5120
#include "bits/stdc++.h"

using namespace std;

int main() {
    int A, B;
    cin >> A >> B;
    bool flag = false;
    for(int C = 1; C <= 3; C++){
        if(A * B * C % 2 == 1) flag = true;
    }
    if(flag) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
/*  Bismillahir Rahmanir Rahim  */

#include <bits/stdc++.h>

using namespace std;

typedef pair <int, int> pii;

const int N = 305;
const long long mod = 1e9 + 7;

int dp[N][N][N];
bool vis[N][N][N];
vector <pii> ck[N];
int n, m;

bool ok(int a, int b, int c){
	int at = max({a, b, c});
	for(auto u : ck[at]){
		int cnt = 0;
		cnt += (a >= u.first);
		cnt += (b >= u.first);
		cnt += (c >= u.first);
		if(cnt != u.second) return false;
	}
	return true;
}

int recur(int l1, int l2, int l3){
	if(vis[l1][l2][l3]) return dp[l1][l2][l3];
	vis[l1][l2][l3] = 1;
	int at = max({l1, l2, l3}) + 1;
	long long ret = 0;
	if(!ok(l1, l2, l3)) ret = 0;
	else if(at == n + 1) ret = 1;
	else{
		ret += recur(at, l2, l3);
		ret += recur(l1, at, l3);
		ret += recur(l1, l2, at);
	}
	return dp[l1][l2][l3] = ret % mod;
}

int main(){
	int l, r, x;
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= m; ++i){
		scanf("%d %d %d", &l, &r, &x);
		ck[r].push_back({l, x});
	}
	printf("%d\n", recur(0, 0, 0));
	return 0;
}



Measured memory_bytes: 137600