akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define ll long long
#define ld long double
#define pb push_back
#define FR first
#define SC second
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000000
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector< vl >
#define vb vector<bool>
#define vbb vector< vb >
#define vpl vector<pll>
#define vpll vector< vpl >

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

bool safe(ll i, ll j, ll n, ll m)
{
    if(i >= 0 && i < n &&  j >= 0 && j < m)
        return true;
    return false;
}
void solve()
{
	ll n, m, sx, sy, fx, fy;
	cin>>n>>m;
	vector<string> mz(n);
	cin>>sx>>sy>>fx>>fy;
	sx--;sy--;
	fx--;fy--;
	for(ll i = 0; i < n; i++) cin>>mz[i];
	//vbb vis(n, vb(m, false));
	vll dist(n, vl(m, LLMX));
	
	deque<pll> q;
	if(mz[sx][sy] == '.')
    {
        q.push_front({sx, sy});
    	dist[sx][sy] = 0;
    }
	while(q.size())
	{
	    pll u = q.front();
	    q.pop_front();
	    //cout<<u.FR<<" "<<u.SC<<"\n";
	    if(u.FR == fx && u.SC == fy)
	        break;
	    for(ll k = 0; k < 4; k++)
	    {
	        ll x = u.FR + dx[k];
	        ll y = u.SC + dy[k];
	        if(safe(x, y, n, m) && mz[x][y] == '.' && dist[u.FR][u.SC] < dist[x][y])
	        {
	            q.push_front({x, y});
	            dist[x][y] = dist[u.FR][u.SC];
	        }
	    }
	    ll ix = u.FR - 2;
	    ll iy = u.SC - 2;
	    for(ll i = 0; i < 5; i++)
        {
            for(ll j = 0; j < 5; j++)
            {
                ll x = ix + i;
                ll y = iy + j;
                if(safe(x, y, n, m) && mz[x][y] == '.' && dist[u.FR][u.SC] + 1 < dist[x][y])
                {
                    q.push_back({x, y});
	                dist[x][y] = 1 + dist[u.FR][u.SC];
                }
            }
        }
	}
	
	if(dist[fx][fy] == LLMX)
	    cout<<-1;
	else
	    cout<<dist[fx][fy];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t = 1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 12624
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <functional>
#include <cmath>
#include <array>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI;
typedef pair<int,int> pii;
const int mod = (int)1e9+7;



int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll a,b,c;
	cin >>a >>b >>c;
	
	if(a%2==0 || b%2==0 || c%2==0){puts("0"); return 0;}
	if(a>b) swap(a,b);
	if(b>c) swap(b,c);
	
	cout << a*b <<"\n";
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  int mile=0;

  for(int i=0;i<999;i++){
    for(int k=0;k<10;k++){
      if(k%2==0||i%3==2) mile += 20;
      else mile += 19;
    } 
  }
  mile += 1;
  //cout << "mile " << mile << endl;
  for(int i=0;i<n;i++){
    int y,m,d;
    cin >> y >> m >> d;
    int count=0;
    // year
    for(int j=0;j<y;j++){
      if(j+1!=y){
        for(int k=0;k<10;k++){
          if(j%3==2||k%2==0){
            count += 20;
          }else{
            count += 19;
          }
        }
      }
      else{
        for(int k=0;k<m;k++){
          if(k==m-1){
            count += d;
          }else if(j%3==2||k%2==0){
            count += 20;
          }else{
            count += 19;
          }
        }
      }
    }
    cout << mile - count << endl;
  }

return 0;
}

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

// 最大公約数
int gcd(int a, int b) {
  return b? gcd(b, a % b): a;
}
int gcd(int a, int b, int c) {
  return gcd(gcd(a, b), c);
}

int main() {
  int n, m;
  cin >> n; // 2 or 3
  if (n == 2) {
    int a, b;
    cin >> a >> b;
    m = gcd(a, b);
  } else {
    int a, b, c;
    cin >> a >> b >> c;
    m = gcd(a, b, c);
  }
  // mの約数を調べる
  vector<int> divisors1; // 前半（昇順）
  vector<int> divisors2; // 後半（降順）
  for (int i=1; i*i<=m; i++) {
    if (m % i == 0) {
      int j = m / i; // ペアの約数
      divisors1.push_back(i);
      if (i != j) divisors2.push_back(j);
    }
  }
  // 出力
  int s1 = divisors1.size(), s2 = divisors2.size();
  for (int i=0; i<s1; i++) cout << divisors1[i] << endl;
  for (int i=s2-1; i>=0; i--) cout << divisors2[i] << endl;
  return 0;
}


Measured memory_bytes: 3144
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
	ans += b[a[i]-1]
	if ((i > 0) and (a[i] == a[i-1]+1)):
		ans += c[a[i-1]-1]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int ans[110000];

struct Unionfind {
  vector<int> par;

  Unionfind(int n) : par(n,-1) {}

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

  bool unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if(rx==ry) return false;
    if(par[rx]>par[ry]) swap(rx,ry);
    par[rx] += par[ry];
    par[ry] = rx;
    return true;
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

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

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  Unionfind tree(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    tree.unite(a,b);
    ans[a]--; ans[b]--;
  }
  rep(i,k) {
    int c, d;
    cin >> c >> d;
    c--; d--;
    if(tree.root(c)==tree.root(d)) {
      ans[c]--; ans[d]--;
    }
  }
  rep(i,n) {
    int r = tree.root(i);
    ans[i] += (tree.size(r) - 1);
  }
  rep(i,n) {
    cout << ans[i];
    if(i!=n-1) cout << " ";
    else cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;
template<class T>struct SegTree{
	T *dat;
	int n;
	SegTree(int size = 1000000){
		for(n = 1; n < size; n *= 2);
		dat = new T[2 * n - 1];
		init();
	}
	~SegTree(){ delete [] dat; }
	
	void init(){
		rep(i, 2 * n - 1) dat[i] = inf;
	}
	void update(int k, T a){
		k += n - 1;
		dat[k] = min(dat[k], a);
		
		while(k > 0){
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	T query(int a, int b, int k, int l, int r){
		if(r <= a || b <= l) return inf;
		if(a <= l && r <= b) return dat[k];
		
		T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		
		return min(vl, vr);
	}
	T query(int a, int b){ return query(a, b, 0, 0, n); }
};
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vi b(n); rep(i, n) cin >> b[i];
	int q; cin >> q;
	vector<pi> v;
	rep(i, q){
		int l, r; cin >> l >> r;
		v.emplace_back(l - 1, r);
	}
	sort(all(v));
	
	vi zero(n + 1), one(n + 1);
	rep(i, n) if(b[i]) one[i + 1]++; else zero[i + 1]++;
	rep(i, n){
		zero[i + 1] += zero[i];
		one[i + 1] += one[i];
	}
	
	SegTree<int> dp1(n + 1), dp2(n + 1);
	dp1.update(0, 0); //ans - zero
	dp2.update(0, 0); //ans - one
	
	for(pi p : v){
		int l = p.first, r = p.second;
		int mn = inf;
		mn = min(mn, dp1.query(l, r) + zero[r]);
		mn = min(mn, dp2.query(0, l) + zero[r] - zero[l] + one[l]);
		dp1.update(r, mn - zero[r]);
		dp2.update(r, mn - one[r]);
		
		//dbg(mn, p.first, p.second);
	}
	int ans = inf;
	rep(i, n + 1){
		ans = min(ans, dp1.query(i, i + 1) + zero[i] + one[n] - one[i]);
		ans = min(ans, dp2.query(i, i + 1) + one[n]);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 8304
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) ((ll)v.size())
#define mp make_pair
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll> 
const ll mod = 1000000007;
#define MAXN 2000002
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll arr[200002];
int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   ll i,n,j;
   cin>>n;
   //cout<<typeid(1);
   string s;
   cin>>s;
   ll ans=1,cnt=0;
   for(i=0;i<2*n;i+=2){
      if(s[i]=='B' and s[i+1]=='B'){
       ans=(ans*(cnt+1))%mod;
      }
      else if(s[i]=='W' and s[i+1]=='W'){
       // cout<<"DD";
        if(cnt==0){
          cout<<0;
          return 0;
        }
        ans=(ans*(cnt))%mod;
      }
      else if(s[i]=='W' and s[i+1]=='B'){
        if(cnt==0){
          cout<<0;
          return 0;
        }
        ans=(ans*( (cnt*(cnt-1ll)) % mod ))%mod;
        cnt-=2;
      }
      else if(s[i]=='B' and s[i+1]=='W'){
        cnt+=2;
      }
   }
   if(cnt){
    cout<<0;
    return 0;
   }
   for(i=1;i<=n;i++) ans=(ans*i)%mod;
    cout<<ans;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
const int mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (t == 0) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
istream& operator>>(istream& i, mint& var) {
    ll tmp; i >> tmp;
    var.x = tmp;
    return i;
}
ostream& operator<<(ostream& o, const mint& var) {
    o << var.x;
    return o;
}
using vm  = vector<mint>;
using vvm = vector<vm>;

vl getDivisor(ll x) {
    vl res;
    ll pre = x+1;
    for (ll i = 1; i*i <= x; ++i) {
        ll j = x / i;
        if (x % i == 0) {
            res.push_back(i);
            if (i*i != x) res.push_back(j);
            pre = j;
            continue;
        }
        if (j != pre) {
            res.push_back(i);
            if (j != i) res.push_back(j);
            pre = j;
        }
    }
    res.push_back(0);
    sort(res.begin(), res.end());
    return res;
}

map<int,int> getIndices(vl S) {
    map<int,int> res;
    for (int i = 0; i < S.size(); ++i) {
        res[S[i]] = i;
    }
    return res;
}

int main() {
    ll N, K; cin >> N >> K;
    
    vl divs = getDivisor(N);
    map<int, int> toIdx = getIndices(divs);
    
    vm dp(divs.size(), 0);
    for (int i = 1; i < divs.size(); ++i) {
        dp[i] += mint(divs[i] - divs[i-1]);
        dp[i] += dp[i-1];
    }
    for (int k = 0; k < K-1; ++k) {
        vm ndp(divs.size(), 0);
        for (int i = 1; i < divs.size(); ++i) {
            ll t = N / divs[i], ti = toIdx[t];
            ndp[i] += mint(divs[i] - divs[i-1]) * dp[ti];
            ndp[i] += ndp[i-1];
        }
        dp = ndp;
    }

    mint ans = dp[divs.size()-1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4744
N = int(input())
A = list(map(int, input().split()))

Flag = False
cnt = 0
S = 0
m = 10**9

for i in A:
  if i == 0:
    Flag = True
  elif i > 0:
    S += i
    m = min(m, i)
  else:
    S += -i
    cnt ^= 1
    m = min(m, -i)

if Flag or cnt == 0:
  print(S)
else:
  print(S-2*m)

Measured memory_bytes: 20092
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#include <iostream>
#define ll long long int
#define cases int t; cin >> t; while (t--)
#define pb push_back
using namespace std;

int main()
{
    int n, d; cin >> n >> d;
    int a[n][d], ans = 0;
    float temp, sum;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < d; j++)
        {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < n-1; i++)
    {
        sum = 0;
        for (int j = i+1; j < n; j++)
        {
            sum = 0;
            for (int k = 0; k < d; k++)
            {
                sum += pow(a[i][k] - a[j][k], 2);
            }
            temp = sqrt(sum);
            if (ceil(temp) == floor(temp)) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/* libnum {{{*/
void amax(N, Args...)(ref N x, Args y) {
  x = x.max(y);
}
void amin(N, Args...)(ref N x, Args y) {
  x = x.min(y);
}
auto maxE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amax(y);
  return x;
}
auto minE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amin(y);
  return x;
}
/*}}}*/

/+---test
3 4
4 3
4 1
2 2
---+/
/+---test
5 3
1 2
1 3
1 4
2 1
2 3
---+/
/+---test
1 1
2 1
---+/

void main(string[] args) {
  long N, M;
  readf(" %d %d ", &N, &M);

  long[][] jobs;
  jobs.length = M;

  foreach (i; 0..N) {
    long day, reward;
    readf(" %d %d ", &day, &reward);
    if (M >= day) jobs[day-1] ~= reward;
  }

  auto queue = (new long[N]).heapify(0);

  long reward;
  foreach (job; jobs) {
    job.each!(x => queue.insert(x));
    if (queue.empty) continue;
    reward += queue.removeAny();
  }
  reward.writeln;
}


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

using namespace std;

#define rep(i,m,n) for(long long i=m;i<n;i++)

typedef long long ll;

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  ll k=0;
  rep(i,0,n){
   cin >> a[i];
   k=max(k,a[i]);
  }
  
  vector<ll> cnt(k+1);
  rep(i,0,n) cnt[a[i]]++;

  bool flag=true;
  if((!(k%2==1&&cnt[(k+1)/2]==2))&&(!(k%2==0&&cnt[(k+1)/2]==1))) flag=false;
  rep(i,0,(k+1)/2) if(cnt[i]>0) flag=false;
  rep(i,(k+1)/2+1,k+1) if(cnt[i]<2) flag=false;
  
  if(flag) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

int N, Q;
string S;

int ac[100010];

signed main()
{
	cin >> N >> Q;
	cin >> S;

	for (int i = 1; i < S.length(); i++)
	{
		if (S[i] == 'C' && S[i - 1] == 'A')
		{
			ac[i] = ac[i - 1] + 1;
		}
		else
		{
			ac[i] = ac[i - 1];
		}
	}

	REP(i, Q)
	{
		int l, r;
		cin >> l >> r;
		l--;
		r--;
		cout << (ac[r] - ac[l]) << endl;
	}
}



Measured memory_bytes: 4000
#include <bits/stdc++.h>
#define MAXV 100000
const int INF = INT_MAX;
using namespace std;
typedef pair<int, int> P;
struct edge {int to, cost; };

int V;
vector<edge> G[MAXV];
int d[MAXV];

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill_n(d, V, INF);
  d[s] = 0;
  que.push(P(0, s));

  while(!que.empty()) {
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int E, r;
  cin >> V >> E >> r;
  for(int i = 0; i < E; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    struct edge tmp;
    tmp.to = t; tmp.cost = d;
    G[s].push_back(tmp);
  }
  dijkstra(r);
  for(int i = 0; i < V; i++) {
    if(d[i] == INF){
      cout << "INF" << endl;
      continue;
    }
    cout << d[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 12916
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

A, B, C = map(int, input().split())

s = set()

cnt = 0
while A % 2 == B % 2 == C % 2 == 0:
    if (A, B, C) in s:
        cnt = -1
        break
    s.add((A, B, C))
    A, B, C = B // 2 + C // 2, C // 2 + A // 2, A // 2 + B // 2
    cnt += 1

print(cnt)

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


int main(){
    int N;
    string s;
    cin >> N >> s;
    if(s.size() <= N){
        cout << s << endl;
    } else {
        rep(i, N){
            cout << s[i];
        }
        cout << "...";
        cout << endl;
    }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,ac=0,bc=0,cc=0,ans=0;
    cin>>n;
    string s;
    for(int i=0;i<n;i++){
        cin>>s;
        m=s.size();
        if(s[0]=='B'&&s[m-1]=='A'){cc++;}
        else if(s[0]=='B'){bc++;}
        else if(s[m-1]=='A'){ac++;}
        
        
        for(int j=0;j<m-1;j++){
            if(s[j]=='A'&&s[j+1]=='B'){ans++;}
        }
    }
    if(cc==0){cout<<ans+min(ac,bc);return 0;}
    else if(bc+ac>0){cout<<ans+cc+min(ac,bc);return 0;}
    else{cout<<ans+cc-1;return 0;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

string normalize(string s) {
    string t = "";
    for (char c : s) {
        if (t.empty()) t.push_back(c);
        else if (c == '(') t.push_back(c);
        else if (c == ')' && t.back() == '(') t.pop_back();
        else t.push_back(c);
    }
    return t;
}

int main() {
    int n;
    cin >> n;
    vector<string> ss(n);
    rep(i, n) cin >> ss[i], ss[i] = normalize(ss[i]);

    vector<P> ts(n);
    rep(i, n) ts[i].first = count(ss[i].begin(), ss[i].end(), ')');
    rep(i, n) ts[i].second = count(ss[i].begin(), ss[i].end(), '(');

    vector<P> l, r;

    for (P p : ts) p.first <= p.second ? l.push_back(p) : r.push_back(p);

    sort(l.begin(), l.end(), [](P p1, P p2) {
        return p1.first < p2.first;
    });
    sort(r.rbegin(), r.rend(), [](P p1, P p2) {
        return p1.second < p2.second;
    });

    string s = "";

    for (P p : l) {
        rep(i, p.first) s.push_back(')');
        rep(i, p.second) s.push_back('(');
    }

    for (P p : r) {
        rep(i, p.first) s.push_back(')');
        rep(i, p.second) s.push_back('(');
    }

    string t = normalize(s);
    string ans = t.empty() ? "Yes" : "No";
    cout << ans << endl;
}


Measured memory_bytes: 69572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
const int MAX = 510000;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i=2; i<MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

ll COM(int n, int k){
    if(n<k){
        return 0;
    }
    if(n<0 || k<0){
        return 0;
    }
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(){
    COMinit();
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    ll ans = 0;
    for(int i=0; i<w-b; i++){
        ans = (ans + COM(h-a+b-1+i, b+i) * COM(a+w-b-2-i, a-1)) % MOD;
    }

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

Measured memory_bytes: 12160
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
bool x[SZ],y[SZ];
int a,b,c,d,e,f;
int main()
{
	cin>>a>>b>>c>>d>>e>>f;
	x[0]=y[0]=1;
	for(int i=a;i<=f;++i)
		x[i]|=x[i-a];
	for(int i=b;i<=f;++i)
		x[i]|=x[i-b];
	for(int i=c;i<=f;++i)
		y[i]|=y[i-c];
	for(int i=d;i<=f;++i)
		y[i]|=y[i-d];
	int xx=1,yy=-1;
	for(int i=1;i*100<=f;++i)
	{
		if(!x[i]) continue;
		int j=e*i;
		while(!y[j]||i*100+j>f) --j;
		if(j*(ll)(xx*100+yy)>yy*(ll)(i*100+j))
			xx=i,yy=j;
	}
	printf("%d %d\n",xx*100+yy,yy);
}


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

int main()
{
    int n, d;
    cin >> n >> d;
    int x[12][12];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < d; j++){
            cin >> x[i][j];
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            int dis2 = 0;
            for(int k = 0; k < d; k++){
                dis2 += abs((x[i][k] - x[j][k]) * (x[i][k] - x[j][k]));
            }
            int dis = sqrt(dis2);
            if(dis * dis == dis2) ans++;
        }
    }
    cout << (ans - n) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
typedef long long ll;


ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

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

  vector<ll> h(n);
  rep(i, n) { 
      cin >> h.at(i);
  }
  sort(h.begin(), h.end(), greater<ll>());

  ll ans = 0;
  for (int i = k; i < n; i++) {
      /* code */
      ans += h.at(i);
  }
  cout << ans << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	ll n,t;cin>>n>>t;
	vll a(n);
	rep(i,n){
		cin>>a[i].F;
		a[i].S=a[i].F+t;
	}
	int k=0;
    ll ans=0;
	rep(i,n-1){
		if(a[i].S<a[i+1].F){
			ans+=a[i].S-a[k].F;
			k=i+1;
		}
	}
	ans+=a[n-1].S-a[k].F;
	cout<<ans<<endl;
}

Measured memory_bytes: 3328
import itertools
import math

N = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))

l = list(itertools.permutations(range(1,N+1)))

for i in range(math.factorial(N)):
  if list(l[i]) == p:
    a = i
    break
    
for i in range(math.factorial(N)):
  if list(l[i]) == q:
    b = i
    break

print(abs(a-b))

Measured memory_bytes: 45552
#include <bits/stdc++.h>
#include <queue>
using namespace std;
int main(){
	int N, M; cin >> N >> M; 
	int INF = 114514; 
	int A[2019] = {}; int B[2019] = {}; 
	vector<int> E[1010] = {}; 
	vector<int> F[1010] = {}; 
	for(int i = 0; i < M; i++){
		int a, b; cin >> a >> b; 
		a--; b--; A[i] = a; B[i] = b; 
		E[a].push_back(b);
		F[b].push_back(a);  
	}
	int ans[2019] = {}; 
	queue<int> que; 
	for(int i = 0; i < M; i++){ 
		int D[1010] = {}; 
		fill(D, D+N, INF); 
		D[B[i]] = 0; 
		queue<int> que; 
		que.push(B[i]); 
		while(que.size()){
			int t = que.front(); que.pop();
			for(int j = 0; j < E[t].size(); j++){
				if(D[E[t].at(j)] < INF) continue;
				//if(t == B[i] && E[t].at(j) == A[i]) continue; 
				D[E[t].at(j)] = D[t] + 1; 
				que.push(E[t].at(j)); 
			}
		}
		ans[i] = D[A[i]] + 1; 
	}
	int kotae = INF + 1; int index = -1; 
	for(int i = 0; i < M; i++){
		if(kotae > ans[i]){
			kotae = ans[i]; index = i; 
		}
	}
	if(kotae == INF + 1){
		cout << -1 << endl; return 0;  
	}
	int D[1010] = {}; fill(D, D+N, INF); 
	D[B[index]] = 0; 
	que.push(B[index]); 
	while(que.size()){
		int t = que.front(); que.pop();
		for(int j = 0; j < E[t].size(); j++){
			if(D[E[t].at(j)] < INF) continue; 
			D[E[t].at(j)] = D[t] + 1; 
			que.push(E[t].at(j)); 
		}
	}
	int mx = D[A[index]]; int ind = A[index]; 
	cout << mx + 1 << endl << A[index]+1 << endl; 
	while(mx > 0){
		for(int i = 0; i < F[ind].size(); i++){
			if(D[F[ind].at(i)] == mx - 1){
				cout << F[ind].at(i)+1 << endl; 
				ind = F[ind].at(i); 
				mx --; break;
			}
		}
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define mp make_pair
#define LL long long
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int main(){
	char x;
	int sum=0;
	while(cin>>x)sum+=x-'0';
//	cout<<sum<<endl;
	cout<<(sum%9==0?"Yes":"No")<<endl;
	return 0;
}


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

using namespace std;

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

const int N = 555;

char s[N][N], a[N][N], c[N][N];
int x[N * N], y[N * N];
bool was[N][N];

int main() {
  int h, w;
  scanf("%d %d", &h, &w);
  for (int i = 0; i < h; i++) {
    scanf("%s", s[i]);
    for (int j = 0; j < w; j++) {
      if (i % 2 == 0) {
        a[i][j] = s[i][j];
        c[i][j] = '#';
      } else {
        a[i][j] = '#';
        c[i][j] = s[i][j];
      }
    }
    a[i][0] = '#';
    a[i][w - 1] = '.';
    c[i][0] = '.';
    c[i][w - 1] = '#';
    a[i][w] = c[i][w] = 0;
  }
  for (int i = 0; i < h; i++) {
    puts(a[i]);
  }
  puts("");
  for (int i = 0; i < h; i++) {
    puts(c[i]);
  }
  return 0;
}


Measured memory_bytes: 1536
from collections import Counter

s = input()

d = Counter(s)
ans = 101

if len(d) == 1:
    print(0)
    exit()

for item in d.keys():
    st = item
    tmp = list(s)
    n = len(s)
#    print('----------',item,tmp,'---------------')
    while n>0:
        gen = []
        flag = True
        for i in range(n-1):
            if tmp[i] == st or tmp[i+1] == st:
                gen.append(st)
            else:
                gen.append(tmp[i])
                flag = False
#        print(gen)
        if flag: break
        else: 
            tmp = gen.copy()
            n -= 1
    ans = min(ans,len(s)-len(gen))
print(ans)

Measured memory_bytes: 9220
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	static public void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long[] aArray = new long[n];
		for (int i = 0; i < n; i++) {
			aArray[i] = scan.nextLong();
		}
		scan.close();

		long count = 0L;
		long sum = 0L;
		Map<Long, Integer> sumMap = new HashMap<>();
		sumMap.put(0L, 1);
		for (int i = 0; i < n; i++) {
			sum += aArray[i];
			if (sumMap.containsKey(sum)) {
				count += sumMap.get(sum);
			} else {
				sumMap.put(sum, 0);
			}
			sumMap.put(sum, sumMap.get(sum) + 1);
		}
		System.out.println(count);
	}
}


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


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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

typedef pair<int,int> pii;
typedef long long int ll;

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

string a,b,c;
char ans[3][2];

int main(){
  cin >> a >> b >> c;
  if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <iomanip>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }
template<typename V> void printVec(V v) {ll i=0;for(auto x : v){std::cout << " [" << i++ << "] " << x;} print();}

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

  ll A, B;
  std::cin >> A >> B;
  ll ans = 0LL;
  ans = std::max(ans, A + B);
  ans = std::max(ans, A + A - 1);
  ans = std::max(ans, B + B - 1);

  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){      
      lint m;
      cin>>m;
      lint digit=0;
      lint sum=0;
      rep(i,m){
          lint d,c;
          cin>>d>>c;
          sum+=d*c;
          digit+=c;
      }
      cout<<digit-1+(lint)(sum-1)/9<<endl;
      }
  
     


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, K;
ll H[200100];

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

  std::cin >> N >> K;

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

  std::sort(H, H + N);
  std::reverse(H, H + N);

  ll res = 0;

  if(K < N){
      res = std::accumulate(H + K, H + N, 0ll);
  }

  std::cout << res << std::endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
using namespace std;

static const int INF=100000;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int N;
    cin >> N;
    int p[N];
    int s[N];
    for(int i=0;i<N;i++){
        cin >> p[i];
        s[i]=p[i];
    }
    sort(s,s+N);
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            bool ans=false;
            swap(p[i],p[j]);
            for(int k=0;k<N;k++){
                if(p[k]==s[k]) ans=true;
                else{
                    ans=false;
                    break;
                }
            }
            if(ans){
                cout << "YES" << endl;
                return 0;
            }
            swap(p[i],p[j]);
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
a,b,c = map(int,input().split())
ans = 0
for i in range(10000001):
  if a%2 == 1 or b%2 == 1 or c%2 == 1:
    break
  if i == 1000000:
    print(-1)
    exit()
  m = a
  n = b
  l = c
  a = (b+c)//2 
  b = (c+m)//2 
  c = (m+n)//2
  ans += 1
print(ans)

Measured memory_bytes: 9096
//https://atcoder.jp/contests/agc040/tasks/agc040_a
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = a; i <= b; ++i)
#define ROF(i,a,b) for(int i = a; i >= b; --i)
#define fast_read ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define maxN 2000005
using namespace std;
int a[maxN];
string s;
vector<int> e[maxN];
int f[maxN];
bool used[maxN];
void dfs(int u ){
    used[u] = true;
    //cout<< " u " <<u<<endl;
    if(e[u].size() == 0) {
        f[u] = 0 ;
        return;
    }
    for(int v :e[u]) {
        if(!used[v]) dfs(v);
        f[u] = max(f[u],f[v]+1);
    }
}
int main () {
    fast_read
    cin>>s;
    int n = (int) s.size() + 1;
    FOR(i,1,n - 1) {
        if(s[i -1] == '>') {
            e[i].pb(i+1);
        }
        else {
            e[i+1].pb(i);
        }
    }
    FOR(i,1,n) if(!used[i]) dfs(i);
    ll ans =0 ;
    FOR(i,1,n) {
      //  cout<<f[i]<<' ';
        ans += 1ll*f[i];
    }
    cout<<ans;
}


//#include <bits/stdc++.h>
//#define FOR(i,a,b) for(int i = a; i <= b; ++i)
//#define ROF(i,a,b) for(int i = a; i >= b; --i)
//#define fast_read ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//#define ll long long
//#define fi first
//#define se second
//#define pii pair<int,int>
//#define pb push_back
//#define maxN 2000005
//using namespace std;
//int a[maxN];
//string s;
//vector<int> e[maxN];
//int ra[maxN];
//queue<pair<int,int> > q;
//int main () {
//    fast_read
//    cin>>s;
//    int n = (int) s.size() + 1;
//    FOR(i,1,n - 1) {
//        if(s[i -1] == '>') {
//            e[i+1].pb(i);
//            ra[i]++;
//        }
//        else {
//            e[i].pb(i+1);
//            ra[i+1]++;
//        }
//    }
//    FOR(i,1,n)
//        if(!ra[i]) q.push({i,0});
//    while(!q.empty()) {
//        int u = q.front().fi;
//        int cur = q.front().se;
//        a[u] = cur;
//       // cout<<"u " <<u<<' '<<cur<<endl;
//
//        q.pop();
//        for(int v : e[u]) {
//            ra[v]--;
//            if(ra[v] == 0) {
//                q.push({v,cur+1});
//            }
//        }
//    }
//    ll ans =0 ;
//    FOR(i,1,n) {
//       // cout<<a[i]<<' ';
//        ans += 1ll*a[i];
//    }
//    cout<<ans;
//}


Measured memory_bytes: 91548
#include <bits/stdc++.h>
 
typedef long long ll;

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define AA(i) cout<<i<<endl;
#define AS(i) cout<<i<<" ";
 
const int INF = 1001001001;
 
using namespace std;
 
int main() {

    int n;
    cin >> n;

    int a;
    rep(i, n) {
        cin >> a;

        if (a % 2 == 0) {

            if (a % 3 != 0 && a % 5 != 0 ) {
                AA("DENIED");
                return 0;
            }
        }
    }

    AA("APPROVED");
}



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

struct Edge{
	  int tgt_;
	  Edge(int t){
			tgt_ = t;
	  }
};

typedef vector<vector<Edge> > Adj_list;

vector<int> topological_sort(Adj_list G){

	  const int V = G.size();

	  vector<int> S; // ??\?????????????????????
	  vector<int> inorder(V,0); // ??\?????????????????????
	  
	  for(int i=0; i<V; i++) for(Edge& e : G[i]) inorder[e.tgt_]++;
	  for(int i=0; i<V; i++) if(inorder[i] == 0) S.push_back(i);

	  assert(S.size() > 0);

	  vector<int> topological_order;
	  while(S.size()){
			int v = S[S.size()-1]; S.pop_back();
			topological_order.push_back(v);

			for(int i=G[v].size()-1; i>=0; i--){
				  Edge e = G[v][i];	G[v].pop_back();
				  inorder[ e.tgt_ ]--; 

				  if( inorder[e.tgt_] == 0)
						S.push_back( e.tgt_ );
			}
	  }
	  for(int i=0; i<V; i++) assert(G[i].size()==0);
	  return topological_order;
}


int main(){

	  int V,E; cin >> V >> E;
	  Adj_list G(V);
	  for(int i=0; i<E; i++){
			int s,t; cin >> s >> t;
			G[s].push_back( Edge(t) );
	  }
	  
	  vector<int> ans = topological_sort(G);
	  for(int i=0; i<V; i++)
			cout << ans[i] << endl;

}

Measured memory_bytes: 4016
#include<iostream>
    using namespace std;
     
    int main()
    {
      	int A,B,C;
    	cin>>A>>B>>C;
        //cout << A <<B <<C;
        if (A>B)
          cout<<0;
      	else if(B/A>=C)
          cout << C;
        else if (B/A< C)
          cout << B/A;
    }

Measured memory_bytes: 256
n = int(raw_input().strip())
ais = map(int, raw_input().strip().split())

sp = abs(ais[0]) + abs(ais[-1]) + sum([abs(ais[i + 1] - ais[i]) for i in xrange(n - 1)])

total = [sp for _ in xrange(n)]
for i in xrange(n):
    if i == 0:
        total[i] -= abs(ais[0] - 0)
        total[i] -= abs(ais[1] - ais[0])
    elif i == n - 1:
        total[i] -= abs(0 - ais[n - 1])
        total[i] -= abs(ais[n - 1] - ais[n - 2])
    else:
        total[i] -= abs(ais[i + 1] - ais[i])
        total[i] -= abs(ais[i] - ais[i - 1])

    if i == n - 1:
        total[i] += abs(0 - ais[n - 2])
    elif i == 0:
        total[i] += abs(ais[1] - 0)
    else:
        total[i] += abs(ais[i + 1] - ais[i - 1])

    print total[i]


Measured memory_bytes: 11108
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>
 
using std::cin;
using std::cout;
using std::endl;
 
typedef long long ll;
typedef unsigned long long ull;
 
const int N = 100000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int LOG = 40;
const ull BASE = 19260817;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
// const double PI = acos(-1);
const double PI = 3.14159;

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

namespace Comb{
inline void exgcd(ll a, ll b, ll &g, ll &x, ll &y) {
    if (!b) g = a, x = 1, y = 0;
    else exgcd(b, a % b, g, y, x), y -= x * (a / b);
}
 
inline ll inv(ll a) {
    ll g, res, tmp;
    exgcd(a, MOD, g, res, tmp);
    return ((res % MOD) + MOD) % MOD;
}
 
ll f[N], invFact[N];
 
inline void prepare() {
    f[0] = 1;
    int n = 200000;
    for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i % MOD;
    invFact[n] = inv(f[n]);
    for (int i = n - 1; i >= 1; i--) invFact[i] = invFact[i + 1] * (i + 1) % MOD;
}
 
inline ll C(int n, int m) {
    if (!m) return 1;
    if (n == m) return 1;
    if (m > n) return 0;
    if (m < 0) return 0;
    return f[n] * invFact[m] % MOD * invFact[n - m] % MOD;
}
}

int n, ans;
int bit[N * 2];

inline int lowbit(int x) {
    return x & -x;
}

inline void update(int pos, int val) {
    for (int i = pos; i <= n; i += lowbit(i)) bit[i] += val;
}

inline int query(int pos) {
    int res = 0;
    for (int i = pos; i > 0; i -= lowbit(i)) res += bit[i];
    return res;
}

inline int query(int l, int r) {
    return query(r) - query(l - 1);
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x, tmp;
        scanf("%d", &x);
        tmp = query(x, n);
        // printf("%d %d\n", i, tmp);
        if (tmp == i - 1) ans++;
        update(x, 1);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
main()
{
	int a,b,c;
	scanf("%d %d",&a,&b);
	c = a+b;
	if(c<3) printf("Impossible\n");
	else if(a%3==0 || b%3==0 || c%3 == 0) printf("Possible\n");
	else printf("Impossible\n");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
   int x,y,i;
   for(i=1;i<=3000;i++){
       scanf("%d %d",&x,&y);
      if(0<=x&&x<10000&&0<=y&&y<=10000){
           if(x==0&&y==0)break;
           if(x<y){
               printf("%d %d\n",x,y);
           }
           else{
               printf("%d %d\n",y,x);
           }
       }
       else break;
   }
    return 0;
}


Measured memory_bytes: 2040
import numpy as np

D,G = map(int, input().split())
P = []
C = []

for i in range(D):
    p,c = map(int,input().split())
    P.append(p)
    C.append(c)

cnt = np.zeros(D,dtype=int)
P = np.array(P)
C = np.array(C)

ans = sum(P)
cnt_tar = 0

ind_list = np.arange(D)

for bit_seed in range(2**D):

    s_bit = (format(bit_seed, '#016b'))[::-1]
    bit_list = np.array(list(s_bit[:D]),dtype=int)

    cnt = P*bit_list
    num_base = np.sum(cnt)

    point_base_array = (P * (ind_list+1) * 100 + C) * bit_list
    point_base = np.sum(point_base_array)
#    print(point_base_array)

    if point_base >= G:
        num = num_base
        ans = min(ans,num)
    elif num_base > ans:
        continue
    else:
        for i,bit in enumerate(bit_list):
            if bit == 0:
                tar = i

        point_max = point_base + P[tar]*(tar+1)*100 + C[tar]
        if point_max >= G:

            tar_min = (G-point_base) // ((tar+1)*100)
            point = point_base + P[tar]*(tar+1)*100*tar_min

            if point < G:
                tar_min += 1

            if tar_min < P[tar]:
                num = num_base + tar_min
            else:
                num = num_base + P[tar]
            ans = min(ans,num)

print(ans)


Measured memory_bytes: 12504
#include<stdio.h>
#include<string.h>

int main()
{
    char s[105];
    scanf("%s",s);
    int count=0,i;
    int len=strlen(s);
    for(i=0; i<len; i++)
    {
        if(s[i]!=s[len-1-i])
            count++;
    }
    int x=count/2;
    printf("%d\n",x);
    return 0;
}


Measured memory_bytes: 128