akhauriyash/Code-Regression huggingface dataset:
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

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

ll Prime_factorize(ll n) {
    ll cnt=0;
    for (ll i=2; i*i<=n; i++) {
        ll th = 1;
        ll now = 0;
        while (n%i == 0) {
            now++;
            if (th == now) {
                cnt++;
                now = 0;
                th++;
            }
            n /= i;
        }
        if (i != 2) i++;
    }
    if(n != 1) cnt++;
    return cnt;
}

int main() {
    ll n;
    cin >> n;

    ll cnt = Prime_factorize(n);

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3612
min = 10
min_time = 0
sum=0
for cnt in 1..5 do
  line = gets
  line.chomp!
  tar = line.to_i
  if (tar % 10 == 0)
    sum += tar
  elsif (tar % 10 < min)
    if (min_time>0)
      sum += (min_time / 10 +1) *10
    end
    min_time = tar
    min = tar % 10
  else
    sum += (tar / 10 +1) *10
  end
end

if (min < 10)
  sum += min_time
end

puts sum


Measured memory_bytes: 1788
N = int(input())
A = [int(x) for x in input().split()]

sa = sorted(A)
from bisect import *
hv = sa[-1] / 2
ri = bisect_right(sa, hv)

if ri == 0:
    print(sa[-1], sa[ri])
elif len(sa) == 2:
    print(sa[1], sa[0])
else:
    print(sa[-1], sa[ri - 1] if abs(sa[ri - 1] - hv) < abs(sa[ri] - hv) else sa[ri])

Measured memory_bytes: 14052
// Grid Repainting 2

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int h, w;
vector< vector<char> > s;

bool check_adj(int i, int j) {
    if (i >= 1) {
        if (s[i-1][j] == '#') {
            return true;
        }
    }
    if (i < h-1) {
        if (s[i+1][j] == '#') {
            return true;
        }
    }
    if (j >= 1) {
        if (s[i][j-1] == '#') {
            return true;
        }
    }
    if (j < w-1) {
        if (s[i][j+1] == '#') {
            return true;
        }
    }

    return false;
}

int main() {

    cin >> h >> w;
    s = vector< vector<char> >(h, vector<char>(w, 0));

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> s[i][j];
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') {
                if(!check_adj(i, j)) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
Imports System.Console
Module Module1
    Dim w As Int64
    Dim ii, iii As Int64
    Dim ans As Int64
    Dim md As Int64 = (10 ^ 9) + 7
    Dim max, min As Int64
    Dim n, k, x, t, d, m As Int64
    Sub Add(ByRef arr() As Integer, ByVal num As Integer)
        If arr Is Nothing Then
            ReDim arr(0)
            arr(0) = num
        Else
            ReDim Preserve arr(arr.Length)
            arr(arr.Length - 1) = num
        End If
    End Sub
    Sub Main()
        Dim s As String = ReadLine()
        If s.Last = "s" Then
            s = s & "es"
        Else
            s = s & "s"
        End If
        WriteLine(s)
        ReadLine()
    End Sub
End Module


Measured memory_bytes: 27080
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;


int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int mx = max(max(a,b),c);
    int now = 3*mx-a-b-c;
    int ans = 0;
    if(now%2){
        ans = now/2+2;
    }
    else{
        ans = now/2;
    }
    cout << ans << endl;
    return 0;
}

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

using ll = long long;
using vl = vector<ll>;
using vi = vector<int>;

#define rng(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(n) for(int _ = 0, __ = (int)n; _ < __; _++)
#define FOR(x, cont) for (auto &x: cont)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define SZ(x) (int)(x).size()
#define pq(T,COMP) priority_queue<T, vector<T>, COMP>
auto bet = [](const ll x, const ll y, const ll i) {
    return x <= i && i <= y;
};
using pii = pair<int,int>;
using vb = vector<bool>;

vi get_prime(int n) {
    vi minp(n+1);
    vi p;
    for (int i = 2; i <= n; i++) {
        if (!minp[i]) {
            minp[i] = i;
            p.pb(i);
        }
        FOR(x, p) {
            if (x <= minp[i] && x * i <= n)
                minp[x * i] = x;
        }
    }
    return p;
}

const int mod = 1e9 + 7;

void add_mod(ll &x, const ll &y) {
    x += y;
    if (x >= mod) x -= mod;
}
void sub_mod(ll &x, const ll &y) {
    x -= y;
    if (x < 0) x += mod;
}


// AGC028 D Chords
ll dp[605][605];
pii c[605][605];

int main() {
#ifdef LOCAL
    freopen("main.in", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    vl g(2 * n + 1);
    g[0] = 1;
    for (int i = 2; i <= 2 * n; i += 2) {
        g[i] = g[i - 2] * (i - 1) % mod;
    }
    vector<pair<int, int>> a;
    rep(k) {
        int x, y;
        cin >> x  >> y;
        a.eb(x, y);
    }
    auto check = [&a](int x, int y) {
        int c1 = 0, c2 = 0;
        FOR(i, a) {
            if (bet(x, y, i.first) && bet(x, y, i.second)) c1 += 2;
            else if (!bet(x, y, i.first) && !bet(x, y, i.second)) c2 += 2;
            else return make_pair(-1, -1);
        }
        return make_pair(c1, c2);
    };



    rng (i, 1, 2 * n) rng (j, i + 1, 2 * n + 1) {
            c[i][j] = check(i, j);
            auto &x = c[i][j];
            if (x.first != -1) {
                int l1 = j - i + 1, l2 = 2 * n - l1;
//                cout << i << ' ' << j << ' ' << x.first << ' ' << x.second << endl;
                assert(l1 - x.first >= 0);
                assert(l2 - x.second >= 0);

                dp[i][j] = g[l1 - x.first];
//                if (i == 1 && j == 4) cout << "DEBUG: " << dp[i][j] << endl;
                rng (k, i + 1, j) {
                    if (dp[i][k]) {
//                        if (i==1 && j == 4) {
//                            cout << "DEBUG: " << i << ' ' << k << ' ' << dp[i][k] << endl;
//                        }
                        auto y = check(k + 1, j);
                        assert(y.first != -1);
                        sub_mod(dp[i][j], dp[i][k] * g[j - k - y.first] % mod);
                    }
                }
            }
        }

    ll ans = 0;
//    rng (i, 1, 2 * n) rng (j, i + 1, 2 * n + 1) {
//        if (dp[i][j]) cout << i << ' ' << j << ' ' << dp[i][j] << endl;
//    }
    rng (i, 1, 2 * n) rng (j, i + 1, 2 * n + 1) {
        if (dp[i][j]) add_mod(ans, dp[i][j] * g[2 * n - (j - i + 1) - c[i][j].second] % mod);
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);


int main(){
  string s;
  cin >> s;
  string t="";
  rep(i,s.size()){
    if(s[i]=='0'){
      t+='0';
    }
    if(s[i]=='1'){
      t+='1';
    }
    if(s[i]=='B'){
      t=t.substr(0,t.size()-1);
    }
  }
  cout <<t <<endl;
    
}


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

int main() {
	int n, x = 0, max = 0;
	char s[101];
	cin >> n;
	cin >> s;
	for(int i = 0; i< n; i++){
		if(s[i] == 'I'){
			x += 1;
		}else{
			x -= 1;
		}
		if(max < x){
			max = x;
		}
	}
	
	cout <<  max << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if i % 2 == 1 and j % 2 == 1:
                print("#", end = "")
            elif i % 2 == 1 and j % 2 == 0:
                print(".", end = "")
            elif i % 2 == 0 and j % 2 == 1:
                print(".", end = "")
            else:
                print("#", end = "")
        print("")
    print()


Measured memory_bytes: 7012
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 200010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN];
int E[MAXN][3];
int sum[MAXN];
bool mark[MAXN];
vector<pii> G[MAXN];

void dfs(int node){
	mark[node]=1;
	for (pii p:G[node]) if (!mark[p.first]){
		sum[p.first]=sum[node]+p.second;
		dfs(p.first);
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m;
	for (int i=1; i<=m; i++){
		cin>>E[i][0]>>E[i][1]>>E[i][2];
		G[E[i][0]].pb({E[i][1], E[i][2]});
		G[E[i][1]].pb({E[i][0], -E[i][2]});
	}
	for (int i=1; i<=n; i++) if (!mark[i]) dfs(i);
	for (int i=1; i<=m; i++){
		if (sum[E[i][1]]-sum[E[i][0]]!=E[i][2]) kill("No")
	}
	kill("Yes")
	
	return 0;
}


Measured memory_bytes: 17408
(defun solve (s)
  (let ((n (length s)))
    (loop for i from 0 below (ceiling n 2)
          for j = (- n i 1)
          count (char/= (aref s i)
                        (aref s j)))))

#-swank
(let* ((s (read-line)))
  (format t "~A~%" (solve s)))


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

int main()
{
    int n;
    cin >> n;
    int p[200005];
    for(int i = 0; i < n; i++) cin >> p[i];
    int l = 10000000;
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(p[i] < l){
            ans++;
            l = p[i];
        }
    }
    cout << ans << endl;
}

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

#define ll long long int
#define M 998244353

int main()
{
    int t=0;
    string s,str;
    cin>>s>>str;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=str[i])
            t++;
    }
    cout<<t<<endl;
    return 0;
}



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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

vii v;
void dfs(vi &x, int n, int m, int idx) {
    if (idx == n) {
        v.push_back(x);
        return;
    }

    int mx = x.back();

    repeat(j, mx, m + 1) {
        vi z = x;
        z.push_back(j);
        dfs(z, n, m, idx + 1);
    }
}

struct p {
    int a;
    int b;
    int c;
    int d;
};

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<p> query(q);
    rep(i, q) cin >> query[i].a >> query[i].b >> query[i].c >> query[i].d;

    rep(i, m) {
        vi x = {i + 1};
        dfs(x, n, m, 1);
    }

    ll ans = 0;
    foreach (e, v) {
        ll cnt = 0;
        rep(i, q) {
            auto pic = query[i];
            if (e[pic.b - 1] - e[pic.a - 1] == pic.c) cnt += pic.d;
        }
        chmax(ans, cnt);
    }

    out(ans);

    return 0;
}


Measured memory_bytes: 9780
def gcd(x, y):
  while(y > 0):
    x, y = y, x % y
  return x
n, x = map(int, input().split())
city = list(map(int, input().split()))
dist = []
for i in range(n):
  dist.append(abs(city[i] - x))
g = dist[0]
for i in range(1, n):
  g = gcd(g, dist[i])
print(g)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef pair<string,string> P;
int bnf();
set<P> used;
map<char,int> M;
string S;
int idx,valid;
char ch[8]={'0','1','+','-','*','(',')','='};
int ord[8];

bool check(string a){//?????????????????°??¨??????????????????????¢????
  int par=0;
  for(char s:a){
    par += (s == '(') - (s == ')');
    if(s == '=') return 0;
    if(par < 0) return 0;
  }
  return par==0;
}

int getNum(){ //??????????????°????????????
  int res = 0;
  if(S[idx] == '0' && isdigit(S[idx+1])) valid  = 0;
  while(isdigit(S[idx]))res = res*2 + S[idx++]-'0';
  return res;
}

int cal(){
  char ch = S[idx];
  int res = 0,sign = 1;
  if(ch=='+'||ch=='*'||ch==')'){ valid = 0;return 0;}

  while(S[idx] == '-') idx++, sign *= -1;
  ch = S[idx];

  if(isdigit(ch)){
    res = sign*getNum();
    if(S[idx] == '*'){idx++; return res * cal();}
    return res;
  }
  else if(ch == '(') {
    idx++;res = sign*bnf();idx++;
    return res;
  }

  valid = 0;
  return 0;
}

int bnf(){
  int res = cal();
  while(idx<(int)S.size()){
    if(valid == 0) return -1;
    char ch = S[idx];
    if(ch == '('){valid = 0;}
    else if(ch == '*'){idx++;res *= cal();}
    else if(ch == '+'){idx++;res += cal();}
    else if(ch == '-'){idx++;res -= cal();}
    else if(ch != ')') valid = 0;
    else break;
  }
  if(valid ==0) return -1;
  return res;
}

string mkS(string a){
  string res;
  for(char s:a){
    if(isalpha(s))res += ch[ ord[ M[s] ] ];
    else res += s;
  }
  return res;
}

int calc(string A,string B){
  if(A.size()==0 || B.size()==0) return 0;
  if(used.count(P(A,B)))return 0;
  used.insert(P(A,B));
  valid = check(A) && check(B);
  idx = 0;
  S = A;
  int ra = bnf();
  idx = 0;
  S = B;
  int rb = bnf();
  //if(valid)cout<<A<<"="<<B<<" "<<valid<<" "<<ra<<" "<<rb<<endl;
  return ra == rb && valid;
}

int calc(string s){
  s = mkS(s);
  for(int i=0;i<(int)s.size();i++)
    if(s[i]=='=') return calc(s.substr(0,i),s.substr(i+1,s.size()-i-1));
  return 0;
}

int dfs(int num,string &s){
  if(num == 8) return calc(s);
  
  int res = 0;
  for(int i=0;i<8;i++){
    if(ord[i] != -1)continue;
    ord[i] = num;
    res +=dfs(num+1,s);
    ord[i] = -1;
  }
  return res;
}


int main(){
  string str;
  cin>>str;
  if(str.size()<3)cout<<0<<endl,exit(0);

  map<char,int> cnt;
  for(int i=0;i<(int)str.size();i++)if(isalpha(str[i]))cnt[str[i]]++;
  if(cnt.size()>8)cout<<0<<endl,exit(0);

  int c = 0;
  for(pair<char,int> p:cnt)if(isalpha(p.first)) M[p.first] = c++;
  
  memset(ord,-1,sizeof(ord));  
  cout<<dfs(0,str)<<endl;
  return 0;
}

Measured memory_bytes: 10004
#include<bits/stdc++.h>
    using namespace std;
    int fir,sec;
    bool f,s;
    int main(){
        scanf("%2d%2d",&fir,&sec);
        if(1<=fir&&fir<=12) f=1;
        if(1<=sec&&sec<=12) s=1;
        if(f&&s) printf("AMBIGUOUS");
        else if(f) printf("MMYY");
        else if(s) printf("YYMM");
        else printf("NA");
    }

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int count =0;
    int check =0;
    ArrayList<Integer> t = new ArrayList<Integer>();
    ArrayList<Integer> x = new ArrayList<Integer>();
    ArrayList<Integer> y = new ArrayList<Integer>();
    ArrayList<Integer> z = new ArrayList<Integer>();
    while (sc.hasNext()) {
      count++;
      t.add(sc.nextInt());
      x.add(sc.nextInt());
      y.add(sc.nextInt());
    }
    for (int i =0; i<count; i++) {
      int ttmp = t.get(i);
      int xtmp = x.get(i);
      int ytmp = y.get(i);
      z.add(xtmp + ytmp);
      
      if (xtmp+ytmp > ttmp) break;
      if ((ttmp+xtmp+ytmp) % 2 == 1) break;
      if (i>0) {
        int ztmp = z.get(i-1);
        int interval = Math.abs(xtmp + ytmp - ztmp);
        if (interval > ttmp - t.get(i-1)) break;
      }
      check++;
    } 
      if (check == count ) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
  }
}

Measured memory_bytes: 94584
#include <stdio.h>
#include <stdlib.h>
#define min(a,b) \
({ __typeof__ (a) _a = (a); \
    __typeof__ (b) _b = (b); \
    _a < _b ? _a : _b; })
#define FOR(i,L,R) for (int i = L; i < R; i++)
#define ll long long
#define READ(n) int (n); scanf("%d",&(n))
#define getString(x) scanf("%s", x)
#define getInt(a) scanf("%d", &a)

int main(){
    READ(a); READ(b);
    int x = abs(b - a);
    if (x % 2 == 1){
        printf("IMPOSSIBLE\n");
        return 0;
    }
    printf("%d\n", min(a, b) + x/2);
}

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

using namespace std;

#define MAX_N 100000

int N;
int d[MAX_N];

void quick_sort(int *v,int left,int right);
void swap(int *v,int i,int j);

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

  quick_sort(d,0,N-1);
  int k=d[N/2]-d[N/2-1];
  if(k<0){
    k*=(-1);
  }
  printf("%d\n",k);
  return 0;
}


void quick_sort(int *v,int left,int right)
{
  int i,last;
  if(left>=right)
    return;
  swap(v,left,(left+right)/2);
  last=left;
  for(i=left+1;i<=right;i++){
    if(v[i]<v[left]){//v[i]<v[left]------------------------------
      swap(v,++last,i);
    }
  }
  swap(v,left,last);
  quick_sort(v,left,last-1);
  quick_sort(v,last+1,right);
}

void swap(int *v,int i,int j)
{
  int temp;
  temp=v[i];
  v[i]=v[j];
  v[j]=temp;
}




Measured memory_bytes: 640
/**
 *    author:  tourist
 *    created: 22.01.2020 00:08:30       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string foo;
  cin >> foo;
  reverse(foo.begin(), foo.end());
  vector<int> a(foo.size());
  int n = (int) foo.size();
  for (int i = 0; i < n; i++) {
    a[i] = (int) (foo[i] - '0');
  }
  int carry = 0;
  for (int i = 0; i < n; i++) {
    a[i] = a[i] * 9 + carry;
    carry = a[i] / 10;
    a[i] %= 10;
  }
  while (carry > 0) {
    a.push_back(carry % 10);
    carry /= 10;
  }
  int sum = accumulate(a.begin(), a.end(), 0);
  int cnt = 0;
  while (cnt < sum) {
    cnt += 1;
    for (int i = 0; i <= (int) a.size(); i++) {
      if (i == (int) a.size()) {
        a.push_back(1);
        sum += 1;
        break;
      }
      if (a[i] == 9) {
        sum -= 9;
        a[i] = 0;
      } else {
        sum += 1;
        a[i] += 1;
        break;
      }
    }
  }
  cout << (cnt + 8) / 9 << '\n';
  return 0;
}


Measured memory_bytes: 6684
#include <iostream>
#include <cstring>
using namespace std;
const int N=5+5;

int main()
{
	char a[N];
	cin>>a;
	int n=strlen(a);
	bool f=false;
	for(int i=0;i<n-1;i++){
		if(a[i]=='A' && a[i+1]=='C'){
			f=true;
			break;
		}
	}
	if(f)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set2d(array, val, m, n) memset(array, val, sizeof(array[0][0]) * m * n);
#include <bits/stdc++.h>
using namespace std;
ll gcd(ll a, ll b)
{
  if (!b)
    return a;
  return gcd(b, a % b);
}
ll power(ll x, ll y, ll p)
{
  ll res = 1;
  x %= p;
  while (y > 0)
  {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
ll po(ll base, ll powerRaised)
{
  if (powerRaised != 0)
    return (base * po(base, powerRaised - 1));
  else
    return 1;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll h;
  cin >> h;
  ll ans = 0, cnt = 0;
  while (h > 1)
  {
    h /= 2;
    cnt++;
  }
  // if (ans < h)
  //   cnt++;
  ll child = po(2, cnt);
  ans += child;
  while (child >= 2)
  {
    ans += child / 2;
    child /= 2;
  }
  cout << ans;

  // cout << cnt;
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}

Measured memory_bytes: 256
// RAM RAM

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ppb pop_back
#define vi vector<int>
#define mp make_pair
#define arrayin(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define N 55

using namespace std;

  
unsigned int onesComplement(unsigned int n) 
{ 
   // Find number of bits in the given integer 
   int number_of_bits = floor(log2(n))+1; 
  
   // XOR the given integer with poe(2,  
   // number_of_bits-1 and print the result  
   return ((1 << number_of_bits) - 1) ^ n; 
} 

string binary(int num){
	string res="";
	while(num){
		if(num%2==0){
			res.pb('0');
		}else{
			res.pb('1');
		}
		num/=2;
	}
	reverse(res.begin(),res.end());
	return res;
}
int bin(string a){
	int res=0;
	int buf=1;
	for(int i=a.length()-1;i>=0;i--){
		int temp=a[i]-'0';
		res=res+ buf*temp;
		buf=buf*2;
	}
	return res;
}
unsigned int l,r;
unordered_set<int> s;
void allpos(string &a,int ind,int n){
	int ho=bin(a);
	if(ho>r){
		return;
	}
	if(ho>=(int)l)
	s.insert(ho);
	if(ind==n){
		return;
	}
	
	if(a[ind]=='0'){
		a[ind]='1';
		allpos(a,ind+1,n);
		a[ind]='0';
		allpos(a,ind+1,n);	
	}else{
		allpos(a,ind+1,n);
	}
	return;
}


int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);

    int a,b,c;cin>>a>>b>>c;
    if(a==(b+c)){
    	cout<<"Yes"<<endl;
    }else if(b==(a+c)){
    	cout<<"Yes"<<endl;
    }else if(c==(a+b)){
    	cout<<"Yes"<<endl;
    }else{
    	cout<<"No"<<endl;
    }
    
	return 0;
}

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

string S,K;
const int INF=1<<28;

void solve(){
	string ans;
	int len=INF, cnt=0;
	int left=INF;
	int idx[K.length()];
//	fill(begin(idx), end(idx), 0);
	for(int i=0; i<K.length(); ++i)idx[i]=-1;

	for(int p=0; p<S.length(); ++p){
		for(int k=0; k<K.length(); ++k){
			if(S[p]==K[k]){
				idx[k]=p;
				left=INF;
				for(int i=0; i<K.length(); ++i)	left=min(left, idx[i]);
				if(left>=0){
//					cout << left << " " << p << endl;
					string cand=S.substr(left, p-left+1);
					if(len>cand.length()){
						cnt=1;
						len=cand.length();
						ans=cand;
					}else if(len==cand.length()){
						++cnt;
					}
				}
			}
		}
	}

	if(len>=INF){
		cout << 0 << endl;
	}else{
		cout << cnt << endl;
		cout << endl;

		for(int i=0; i<ans.size(); ++i){
			if(i>0 && i%72==0)	cout<<endl;
			cout << ans[i];
		}
		cout<<endl;
	}
	cout<<endl;
}

int main(){
	for(int cnt=0;;++cnt){
		string tmp;
		if(getline(cin,tmp).eof())	break;
		if(tmp=="")	break;
		S=tmp;
		while(true){
			getline(cin,tmp);
			if(tmp=="")	break;
			S+=tmp;
		}
		getline(cin,K);
		getline(cin,tmp);
//		cout<<S<<endl;
//		cout<<K<<endl;
//		if(cnt>0)	cout<<endl;
		solve();
	}
	return 0;
}

Measured memory_bytes: 1828
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <queue>
#include <math.h>
#include <string> 
#include <bits/stdc++.h>
using namespace std;

int main(){
    int M,N;
    cin >> N >> M;
    vector<int> array(M);
    int hw;
    hw =0;
    for(int i=0;i<M;i++){
        cin >> array[i];
    }
    for(int i=0;i<M;i++){
        hw = hw + array[i];
    }
    if(N-hw>=0){
        cout << N-hw << endl;
    }else{
        cout << "-1" <<endl;
    }
    return 0;
}

Measured memory_bytes: 3640
n,k=map(int,input().split())
p=list(map(int,input().split()))

x=[]
for i in p:
 x.append((i+1)/2)

b=[0]
for i in range(1,n+1):
 b.append(b[i-1]+x[i-1])

ans=0
for i in range(n-k+1):
 ans=max(ans,b[i+k]-b[i])

print(ans)

Measured memory_bytes: 25060
import std.stdio;
import std.string;
import std.array; // split
import std.conv; // to

void main()
{
   string s1 = chomp(readln());
   string s2 = chomp(readln());
   string s3 = chomp(readln());
   int a = to!int(s1); // 第0要素を整数に変換
   int b = to!int(s2); // 第1要素を整数に変換
   int c = to!int(s3); // 第1要素を整数に変換
   writeln((a+b)*c/2); // 表示
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
const ll mod = 1e9+7;
#define INFL 0x3f3f3f3f3f3f3f3fLL
 
//-------------------------<MATH>-------------------------------------------------------//
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;
ll c = (a * b)%mod;
//cout << a << " " << b << endl;
return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(5e5 + 5)] , inv_fac[(int)(5e5 + 5)];
void precomp_factorial(int M){fac[0] = 1;for(int i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(int i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int lo[(int)(1e3 + 6)];
void sieve(int M){for(int i = 2 ; i < M ; i++){ if(lo[i]) continue; for(int j = i ; j < M ; j += i)lo[j] = i;}}
int max_expo_prime_n_fac(ll N , int prime){int ress = 0;while(N){ress += (N/prime);N /= prime;}return ress;}
//-------------------------</MATH>-------------------------------------------------------//
 
//-------------------------<STRING>-------------------------------------------------------//
string get_prefix(string x , int MAX){return x.substr(0 , min((int)x.size() , MAX));}
string get_suffix(string x,int MAX){int dn=1;for(int i=x.size()-1;i>=0;i--){if(dn==MAX)return x.substr(i);dn++;}return x;}
string convert_to_binary(int x,int len) {string ans=""; while(x){if(x&1){ans='1'+ans;}
    else{ans ='0'+ans;}x/=2;}int k = ans.size();while(k < len){ans = '0' + ans;k++;}return ans;}
//-------------------------</STRING>-------------------------------------------------------//
 
ull llrand() {ull r = 0;for(int i = 0; i < 5; ++i){r = (r << 15)|(rand() & 0x7FFF);}return r & 0xFFFFFFFFFFFFFFFFULL;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
 
 
int main(){
    ll n, k;
    cin >> n >> k;
    vector <ll> p(n+1), c(n+1);
    for(int i = 1; i <= n; i++) cin >> p[i];
    for(int i = 1; i <= n; i++) cin >> c[i];

    ll ans = -1e9;

    for(int i = 1; i <= n; i++){
        vector <ll> vec1;
        vec1.push_back(c[i]);
        int ind = p[i];
        while(ind != i){
              vec1.push_back(c[ind]);
              ind = p[ind];
        }
        for(int j = 1; j < vec1.size(); j++){
           vec1[j] += vec1[j-1];
        }
        int sz = vec1.size();
        //cout << i << " " << sz << endl;
        for(int j = 0; j < sz; j++){
            ll k1 = k - (j+1);
            if(k1 < 0) break;
            k1 /= sz;
            ll ans1 = vec1[j]+max(0LL,k1*vec1[sz-1]);
            //cout << ans1 << "|" << k1 << "|" << vec1[j] << endl;
            ans = max(ans, ans1);
        }
    }
    cout << ans;

}


Measured memory_bytes: 3812
#include<iostream>
using namespace std;
int main()
{
    int l;
    cin >> l;

    string s;
    cin >> s;

    int count=0;
    for(int i=1; i<(l-1) ; i++)
    {
        if(s[i-1] == 'A' && s[i] == 'B' && s[i+1] == 'C')
            count++;
    }
    cout << count << endl;

    return 0;
}

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

int n;
long long d[N],c[N],f[N];

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();c[0]=read();
	for (int i=1;i<=n;i++){
		d[i]=read();
		c[i]=min(c[i-1],abs(c[i-1]-d[i]));
	}
	for (int i=n;i>=1;i--)
		if (d[i]>2*f[i+1]+1) f[i]=f[i+1];
		else f[i]=f[i+1]+d[i];
	for (int q=read();q;q--){
		int x=read();
		printf(c[x-1]>f[x+1]?"YES\n":"NO\n");
	}
	return 0;
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N, T;
  cin >> N >> T;
  vector<P> tc(N); // (time, cost)
  for (int i = 0; i < N; i++) {
    cin >> tc[i].second >> tc[i].first;
  }
  sort(tc.begin(), tc.end());
  int ans = INF;
  for (int i = 0; i < N; i++) {
    if (tc[i].first <= T) {
      ans = min(ans, tc[i].second);
    } else {
      break;
    }
  }
  if (ans == INF) {
    cout << "TLE" << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

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

//nが素数かどうか判定する
bool is_prime(int n){
    if(n < 2){
        return false;
    }
    for(int i = 2; i < (int)sqrt(n) + 1; i++){
        if(n % i == 0){
            return false;
        }
    }
    return true;
}

//n以下の素数を格納した配列を返す
vector<int> make_prime_list(int n){
    vector<int> prime_list;
    if(n < 2){
        return prime_list;
    }
    for(int i = 2; i < n+1; i++){
        if(is_prime(i)){
            prime_list.push_back(i);
        }
    }
    return prime_list;
}

//nを素因数分解
vector<int> prime_factorization(int n){
    vector<int> factorization_list;
    if(n <= 1){
        return factorization_list;
    }
    
    vector<int> prime_list = make_prime_list(n);
    for(int i = 0; i < prime_list.size(); i++){
        int prime = prime_list.at(i);
        if(n % prime == 0 && n > 0){
            while(n % prime == 0 && n > 0){
                n /= prime;
                factorization_list.push_back(prime);
            }
        }
    }
    return factorization_list;
}

//nの約数の個数を返す
int search_divisor_num(int n){
    if(n < 0){
        return 0;
    }
    if(n == 1){
        return 1;
    }

    vector<int> factorization = prime_factorization(n);
    vector<int> backet(n + 1, 0);
    for(int i = 0; i < factorization.size(); i++){
        int prime = factorization.at(i);
        backet.at(prime)++;
    }
    int divisor_num = 1;
    for(int i = 0; i < backet.size(); i++){
        divisor_num *= (backet.at(i) + 1);
    }
    return divisor_num;
}

int main(){
    int N; cin >> N;
    map<int,int> nums;
    for(int i = 1; i <= N; i++){
        vector<int> factorization = prime_factorization(i);
        for(int j = 0; j < factorization.size(); j++){
            nums[factorization[j]]++;
        }
    }
    ll ans = 1;
    for(auto it : nums){
        int num = it.second;
        ans = (ans * (num + 1)) % 1000000007;
    }
    cout << ans << endl;
}


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

#define N 200009

using namespace std;

vector< pair< pair<int,int>,int> > final;

int main(){
	int i,j,t1,t2,t3,t4,n,a1,a2,cur,rem,adder;
	scanf("%d",&n);
	t1=0;
	t2=1;
	while(1){
		t2*=2;
		if(t2<=n){
			t1++;
		}
		else{
			break;
		}
	}
	t2/=2;
	cur=t2-1;
	rem=n-1-cur;
	adder=t2;
	a1=t1+1;
	t2/=2;
	//printf("wow+%d %d %d %d\n",t1,n-1,t2,rem);
	for(i=1;i<a1;i++){
		final.push_back(make_pair(make_pair(i,i+1),0));
		final.push_back(make_pair(make_pair(i,i+1),t2));
		t2/=2;
	}
	while(rem>=2){
		t1=0;
		t2=1;
		while(1){
			t2*=2;
			if(t2<=rem){
				t1++;
			}
			else{
				break;
			}
		}
		t2/=2;
		rem-=t2;
		final.push_back(make_pair(make_pair(1,a1-t1),adder));
		adder+=t2;
	}
	if(rem==1){
		final.push_back(make_pair(make_pair(1,a1),adder));
	}
	a2=(int)final.size();
	printf("%d %d\n",a1,a2);
	for(auto it : final){
		printf("%d %d %d\n",it.first.first,it.first.second,it.second);
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC125A
{
    //
    // Biscuit Generator
    //
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' '); //スペース区切りで数値の入力
            int A = int.Parse(input[0]);//生産の間隔　A秒
            int B = int.Parse(input[1]);//ビスケットの枚数　B枚
            int T = int.Parse(input[2]);//装置を起動してからの時間　T秒

            int ans = 0;//答えを入れる変数

            ans =T / A * B;

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline int read()
{
	int 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;
}

const int mod = 1e9 + 7;
inline int mul(int x, int y) {return (ll)x * y % mod;}
inline int inc(int x, int y) {int t = x + y; return t >= mod ? t - mod : t;}
inline int qpow(int x, int y)
{
	int res = 1;
	for (; y; y >>= 1, x = (ll)x * x % mod)
		if (y & 1) res = (ll)res * x % mod;
	return res;
}

const int maxn = 2e5 + 10;
char s[maxn];
int n, cnt;

int main()
{
	scanf("%s", s);
	n=strlen(s);ll ans = 0;
	for (int i = 0; i < n; i ++)
		if (s[i] == 'B') ++ cnt;
		else ans += cnt;
	printf ("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

char str[2048][2048];
int ver[2048][2048], ori[2048][2048], part[2048][2048];

int main ()
{
    //freopen ("file.in", "r", stdin);

    int n, m, q;
    scanf ("%d %d %d\n", &n, &m, &q);

    for (int i = 1; i <= n; ++i)
    {
        fgets (str[i] + 1, 2048, stdin);

        for (int j = 1; j <= m; ++j)
        {
            ver[i][j] = ver[i - 1][j] + ver[i][j - 1] - ver[i - 1][j - 1] + (str[i][j] == str[i - 1][j] && str[i][j] == '1');
            ori[i][j] = ori[i - 1][j] + ori[i][j - 1] - ori[i - 1][j - 1] + (str[i][j] == str[i][j - 1] && str[i][j] == '1');
            part[i][j] = part[i - 1][j] + part[i][j - 1] - part[i - 1][j - 1] + (str[i][j] == '1');
        }
    }

    for (; q; --q)
    {
        int a, b, x, y;
        scanf ("%d %d %d %d", &a, &b, &x, &y);

        printf ("%d\n", part[x][y] - part[a - 1][y] - part[x][b - 1] + part[a - 1][b - 1] - (ver[x][y] - ver[a][y] - ver[x][b - 1] + ver[a][b - 1]) - (ori[x][y] - ori[a - 1][y] - ori[x][b] + ori[a - 1][b]));
    }

    return 0;
}


Measured memory_bytes: 54912
using System;
using System.Collections.Generic;

    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int n= int.Parse(input);

            string output = "";
            switch (n % 10)
            {
                case 2:
                case 4:
                case 5:
                case 7:
                case 9:
                    output = "hon";
                    break;
                case 0:
                case 1:
                case 6:
                case 8:
                    output = "pon";
                    break;
                case 3:
                    output = "bon";
                    break;
            }

            Console.WriteLine(output);
        }
    }


Measured memory_bytes: 27480
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T, class U> inline void chmax(T &a, const U &b) { if ((a) < (b)) (a) = (b); }
template <class T, class U> inline void chmin(T &a, const U &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// {{{ include acl-library
// #include <atcoder/fenwicktree>
// #include <atcoder/segtree>
// #include <atcoder/lazysegtree>
// #include <atcoder/string>
// #include <atcoder/math>
// #include <atcoder/convolution>
// #include <atcoder/modint>
// #include <atcoder/dsu>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
// #include <atcoder/scc>
// #include <atcoder/twosat>
// using namespace atcoder;
// }}}

int solve() {
    int k;cin>>k;
    string t = "ACL";
    string ans;
    rep(i, k) ans += t;
    cout << ans << endl;
    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
//#define Local
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int N = 250005, P1 = 1e9 + 7, P2 = 1e9 + 9;

ll qpow(ll a, ll b, ll c) {
    ll ans = 1;
    while(b) {
        if(b & 1) ans = ans * a % c;
        a = a * a % c;
        b >>= 1;
    }
    return ans;
}

char s[N];
int n;

struct rolling_hash{
    ll a, b;
    rolling_hash() {
        a = b = 0;
    }
    rolling_hash(ll x) {
        a = x % P1;
        b = x % P2;
    }
    rolling_hash(ll x, ll y) {
        a = x % P1;
        b = y % P2;
    }
    rolling_hash operator + (const rolling_hash& A) const {
        return rolling_hash(a + A.a, b + A.b);
    }
    rolling_hash operator - (const rolling_hash& A) const {
        return rolling_hash(a - A.a + P1, b - A.b + P2);
    }
    rolling_hash operator * (const rolling_hash& A) const {
        return rolling_hash(a * A.a, b * A.b);
    }
    ll get() {
        return a * P2 + b;
    }
}hs[N], pos[N];

rolling_hash X = 1000003;
rolling_hash invX = rolling_hash(qpow(X.a, P1 - 2, P1), qpow(X.b, P2 - 2, P2));

unordered_map <ll, int> mp;

void run() {
    mp.clear();
    cin >> s + 1;
    pos[0] = 1;
    for(int i = 1; i <= n; i++) {
        pos[i] = pos[i- 1];
        if(s[i] == '>') {
            pos[i] = pos[i - 1] * X;
        } else if(s[i] == '<') {
            pos[i] = pos[i - 1] * invX;
        }
    }
    hs[n + 1] = 0;
    for(int i = n; i >= 1; i--) {
        hs[i] = hs[i + 1];
        if(s[i] == '+') {
            hs[i] = hs[i] + pos[i];
        } else if(s[i] == '-') {
            hs[i] = hs[i] - pos[i];
        }
    }
    ll ans = 0;
    ++mp[hs[n + 1].get()];
    for(int i = n; i >= 1; i--) {
        rolling_hash now = hs[i] - hs[1] * pos[i - 1];
        ans += mp[now.get()];
        ++mp[hs[i].get()];
//        cout << ans << '\n';
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
#ifdef Local
    freopen("../input.in", "r", stdin);
    freopen("../output.out", "w", stdout);
#endif
    while(cin >> n) run();
    return 0;
}


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

int main() {
    int coef, diff, weight, w_prime;
    cin >> coef >> diff >> weight ;

    // 10 回ループするfor文
    for (int i = 0; i < 10; i++) {
        w_prime = coef * weight - diff;
        // weight を更新する
        weight = w_prime;
        // 結果を出力 
        cout << w_prime << endl;
    }    

    // おまじない？
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    n: usize,
    k: usize,
    }
    let ans = if n % k != 0 {
        1
    } else {
        0
    };
    println!("{}", ans);
}



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

int main(){
    int n;
    cin >> n;
    int tmp=n;
    int sum=0;
    while(tmp>0){
        sum+=tmp%10;
        tmp/=10;
    }
    if(n%sum==0) cout << "Yes" << endl;
    else cout << "No" <<endl;
    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h1, p1, h2, p2;
  cin >> h1 >> p1 >> h2 >> p2;
  int die1 = (h1 + p2 - 1) / p2;
  int die2 = (h2 + p1 - 1) / p1;
  if (die1 >= die2) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 3608
n=int(input())
A=[int(i) for i in input().split()]
mod=10**9+7
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
lcm=A[0]

chk=True

for i in range(1,n):
  if lcm%A[i]!=0:
    lcm=lcm*A[i]//gcd(lcm,A[i])
  if lcm>10**50000:
    chk=False
    break

if chk:
  ans=0
  for i in range(n):
    ans=(ans+lcm//A[i])%mod
  print(ans)
else:
  ans=0
  mult=1
  for a in A:
    mult=(mult*a)%mod
  for a in A:
    ans=(ans+mult*pow(a,mod-2,mod))%mod
  print(ans)

Measured memory_bytes: 41836
#include<iostream>
#include<cmath>
using namespace std;
int x[10][11]; long long a;
int main() {
	while (cin >> a) {
		for (int i = 9; i >= 0; i--) {
			x[0][i] = (a / (int)pow(10, i)) % 10;
		}
		for (int i = 1; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				x[i][j] = x[i - 1][j] + x[i - 1][j + 1];
			}
		}
		cout << x[9][0] % 10 << endl;
	}
}

Measured memory_bytes: 1204
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		if(a%2==0&&b%2==0%2&&c%2==0) {
			int count = 1;
			for(int i = 0; i < 30; i++) {
				long na = b/2+c/2;
				long nb = a/2+c/2;
				long nc = a/2+b/2;
				a = na;b = nb;c = nc;
				if(a%2==0&&b%2==0&&c%2==0) {
					count++;
				} else {
					System.out.println(count);
					return;
				}
			}
		} else {
			System.out.println(0);
			return;
		}
		System.out.println(-1);
	}
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int a,b,c;cin>>a>>b>>c;
  string ans="NO";
  reps(i,100){
    int now=a*i;
    if(now%b==c)ans="YES";
  }
  cout(ans);
  return 0;
}

Measured memory_bytes: 256
n = int(input())
b = [int(x) for x in input().split()]
a = list()
temp = 0
count1 = 0
count2 = 0

a = b.copy()

if a[0] == 0:
	a[0] = 1
	count1 = 1

sum = a[0]
for i in range(1, n):
	if abs(a[i]) <= abs(sum) or a[i] * sum >= 0:
		if sum > 0:
			temp = -1 * abs(sum) - 1
		else:
			temp = abs(sum) + 1
		count1 += abs(temp - a[i])
		a[i] = temp
	sum += a[i]

a = b.copy()

count2 = abs(a[0]) + 1
if a[0] >= 0:
	a[0] = -1
else:
	a[0] = 1
	
sum = a[0]
for i in range(1, n):
	if abs(a[i]) <= abs(sum) or a[i] * sum >= 0:
		if sum > 0:
			temp = -1 * abs(sum) - 1
		else:
			temp = abs(sum) + 1
		count2 += abs(temp - a[i])
		a[i] = temp
	sum += a[i]

print(min(count1, count2))


Measured memory_bytes: 14332
a, b, c = map(int, input().split())

ans = 0
while (a % 2 == 0) & (b % 2 == 0) & (c % 2 == 0):
    a, b, c = (b + c) // 2, (c + a) // 2, (a + b) // 2
    ans += 1
    if ans>1000000:
        ans = -1
        break
print(ans)


Measured memory_bytes: 62880
<?php

$n = trim(fgets(STDIN));
$x = explode(" ", trim(fgets(STDIN)));
$y = explode(" ", trim(fgets(STDIN)));

$p = array_fill(1, 4, 0);

for ($i = 0; $i < $n; $i++) {
  $a = abs($x[$i] - $y[$i]);
  $p[1] += $a;
  $p[2] += pow($a, 2);
  $p[3] += pow($a, 3);
  if ($p[4] < $a) {
    $p[4] = $a;
  }
}

$p[2] = pow($p[2], 1.0/2.0);
$p[3] = pow($p[3], 1.0/3.0);

for ($i = 1; $i <= 4; $i++) {
  printf("%f" . PHP_EOL, $p[$i]);
}

Measured memory_bytes: 15752