akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>

using namespace std;
using ll = long long;

int f_dir[2][4] = {{-1, 0, 0, 1}, {0, -1, 1, 0}};
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  string s; cin >> s;
  if(s == "AAA" || s == "BBB") cout << "No" << endl;
  else cout << "Yes" << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;
ll dp[110][1100100];
vector<ll> w(1,0);
vector<ll> v(1,0);

ll knapsack(ll i,ll W){
    if(dp[i][W] != -1){
        return dp[i][W];
    }
    if(W-w[i] < 0){
        dp[i][W] = knapsack(i-1,W);
    }else{
        dp[i][W] = max(knapsack(i-1,W),knapsack(i-1,W-w[i])+v[i]);
    }
    return dp[i][W];
}

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

    ll n,weight;
    cin >> n >> weight;
    for(ll i = 1; i < n+1;i++) {
        int tw,tv;
        cin >> tw >> tv;
        w.push_back(tw);
        v.push_back(tv);
    }

    for(ll i = 0; i < n+1;i++){
        for(ll l = 0; l < weight+1;l++){
            dp[i][l] = -1;
        }
    }
    for(ll i = 0; i < weight+1;i++){
        dp[0][i] = 0;
    }


    for(ll i = 1; i < n+1;i++){
        for(ll l = 1; l < weight+1;l++){
            knapsack(i,l);
        }
    }
    cout << dp[n][weight] << endl;

    return 0;
}

Measured memory_bytes: 283648
require 'set'
require 'bigdecimal'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

A, B = gets.split.map { |x| BigDecimal(x) }

puts (A*B).to_i


Measured memory_bytes: 14504
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    print(len(set([input() for _ in range(N)])))

if __name__ == '__main__':
    main()


Measured memory_bytes: 37052
import math
n , d = map(int,input().split())
p = []
ans = 0
for i in range (n):
    z = list(map(int,input().split()))
    p.append(z)
for j in range(n):
    for k in range (j+1,n):
        dis2 = 0
        for l in range (d) :
            dis2 += (p[j][l] - p[k][l]) ** 2
        dis = math.sqrt(dis2)
        if int(dis)== dis :
            ans += 1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
 
int n,mini;
int A[36],B[36];
char a[36],b[36];
 
string check(){
  for(int i=0;i<n;i++){
    if(a[i]==b[i]&&A[i]==B[i])continue;
    return "Not stable";
  }
  return "Stable";
}
 
int main(){
  cin>>n;
 
  for(int i=0;i<n;i++){
    cin>>a[i]>>A[i];
    b[i]=a[i];
    B[i]=A[i];
  }
 
  for(int i=0;i<n-1;i++){
    for(int j=n-1;j>i;j--){
      if(A[j]<A[j-1]){
    swap(a[j],a[j-1]);
    swap(A[j],A[j-1]);
      }
    }
  }
 
  for(int i=0;i<n-1;i++){
    mini=i;
    for(int j=i+1;j<n;j++){
      if(B[j]<B[mini])mini=j;
    }
    swap(b[i],b[mini]);   
    swap(B[i],B[mini]);
  }
 
  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<a[i]<<A[i];
  }
  cout<<endl<<"Stable"<<endl;
  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<b[i]<<B[i];
  }
  cout<<endl<<check()<<endl;
  return 0;
}



Measured memory_bytes: 3228
bingo=[]
for i in range(3):
    a_1,a_2,a_3=map(int,input().split())
    bingo.append(a_1)
    bingo.append(a_2)
    bingo.append(a_3)
n=int(input())
for j in range(n):
    b=int(input())
    for k in range(9):
        if(bingo[k]==b):
            bingo[k]=0
a_1=[]
a_1.append(bingo[0])
a_1.append(bingo[1])
a_1.append(bingo[2])
a_2=[]
a_2.append(bingo[3])
a_2.append(bingo[4])
a_2.append(bingo[5])
a_3=[]
a_3.append(bingo[6])
a_3.append(bingo[7])
a_3.append(bingo[8])
a_4=[]
a_4.append(bingo[0])
a_4.append(bingo[3])
a_4.append(bingo[6])
a_5=[]
a_5.append(bingo[1])
a_5.append(bingo[4])
a_5.append(bingo[7])
a_6=[]
a_6.append(bingo[2])
a_6.append(bingo[5])
a_6.append(bingo[8])
a_7=[]
a_7.append(bingo[0])
a_7.append(bingo[4])
a_7.append(bingo[8])
a_8=[]
a_8.append(bingo[2])
a_8.append(bingo[4])
a_8.append(bingo[6])
if(a_1==[0,0,0]):
    print("Yes")
elif(a_2==[0,0,0]):
    print("Yes")
elif(a_3==[0,0,0]):
    print("Yes")
elif(a_4==[0,0,0]):
    print("Yes")
elif(a_5==[0,0,0]):
    print("Yes")
elif(a_6==[0,0,0]):
    print("Yes")
elif(a_7==[0,0,0]):
    print("Yes")
elif(a_8==[0,0,0]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3192
#include<iostream>
#include<map>
#include<cmath>

using namespace std;

int main(){
  int a,b;
  multimap<int, int, greater<int>> m;
  for(int i=0; i<5; i++){
    cin >> a;
    b = a % 10;
    if (b!=0){
	    m.emplace(b,a);
    }else{
    	m.emplace(9,a);
    }
  }
  int count=0;
  float dum;
  multimap<int, int>::iterator ite;
  for (ite =m.begin(); ite!=m.end();++ite){
    if (ite!=--m.end()){
    	dum = (1.0*ite->second)/10;
	    count += 10*ceil(dum);
    }else{
	    count += ite->second;
    }
  }
  cout <<count<<endl;
}

Measured memory_bytes: 256
x, y = map(int, input().split())

ans = 2* (10 **9)

if y - (-x) >= 0:  # 最初だけBを押す
    ans = y + x + 1

if -y -x >= 0:  # 最後だけBを押す
    ans = min(ans, -y -x + 1)

if -y - (-x) >= 0:  # 最初と最後にBを押す
    ans = min(ans, -y +x +2)

if y - x >= 0:  # Bは押さない
    ans = min(ans, y-x)

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;
typedef pair<ll,int> pli;

int a[4000];
ll sum[4001];
short dp[4001][4001];
short prev[4001][4001];
ll v[4001][4001];
pli tv[4001];

int main() {
  int n;
  cin >> n;
  REP(i,n) cin >> a[i];
  sum[0] = 0;
  REP(i,n) sum[i+1] = sum[i] + a[i];
  REP(i,n)REP(j,n)dp[i][j]=-10000,prev[i][j]=-1;
  REP(i,n) {
    REP(j,i+1) {
      tv[j] = pli(sum[i+1]-sum[j], j);
    }
    sort(tv,tv+i+1);
    REP(j,i+1) {
      v[i][j] = tv[j].first;
    }
    REP(j,i+1) {
      ll a = tv[j].first;
      int b = tv[j].second;
      if (b==0) {
        dp[i][j] = 1;
      } else {
        if (v[b-1][0] < a) {
          int k = lower_bound(v[b-1], v[b-1]+b, a)-v[b-1]-1;
          //cout << i <<" " << j << " " << v[i][j].first << "," << b-1 << " " << k << endl;
          if (k>=0) {
            if (dp[i][j] < dp[b-1][k] + 1) {
              dp[i][j] = dp[b-1][k] + 1;
              prev[i][j] = b-1;
            }
          }
        }
      }
      if (j) {
        if (dp[i][j] < dp[i][j-1]) {
          dp[i][j] = dp[i][j-1];
          prev[i][j] = prev[i][j-1];
        }
      }
    }
  }

  // REP(i,n) {
  //   REP(j,i+1) cout << dp[i][j] << " ";
  //   cout << endl;
  // }
  
  // REP(i,n) {
  //   REP(j,i+1) cout << v[i][j].first << " ";
  //   cout << endl;
  // }
  pii now = pii(n-1,n-1);
  vector<int> ans;
  while(now.first!=-1) {
    if (now.first != n-1) 
      ans.push_back(now.first);
    int p = prev[now.first][now.second];
    REP(i,n) {
      if (dp[p][i] == dp[now.first][now.second]-1) {
        now = pii(p,i);
        break;
      }
    }
  }
  reverse(ALL(ans));
  cout << dp[n-1][n-1] << endl;
  REP(i,ans.size()) {
    if (i) cout << " ";
    cout << ans[i]+1;
  }
  cout << endl;
}

Measured memory_bytes: 187212
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

signed main(){
    int n;
    cin >> n;
    while(1){
        int a,b,c;
        a = n/100;
        b = (n/10)%10;
        c = (n)%10;
        if(a == b && a == c){
            cout << n << endl;
            return 0;
        }
        n++;
    }
    
    
    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://agc030.contest.atcoder.jp/tasks/agc030_a
// rm -r -f test;oj dl http://abc111.contest.atcoder.jp/tasks/abc111_b

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

struct edge{int to,cost;
edge(int to,int cost):to(to),cost(cost){}};

int S,R;
vector<edge> g1[100010],g2[100010];
vi g3[100010];
vector<pi> G;
int a,b,nq;
int dist[100010],used[100010];
pi distv[100010];
ll mask[100010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>S>>R;
	rep(i,R){
		int u,v,w;
		cin>>u>>v>>w;
		u--,v--;
		g1[u].pb(edge(v,w));
		g1[v].pb(edge(u,w));
	}
	cin>>a>>b>>nq;
	a--;b--;
	
	fill(dist,dist+S,INF);
	priority_queue<pi,vector<pi>,greater<pi> > Q;
	dist[a]=0;
	Q.push(mp(0,a));
	
	while(sz(Q)){
		pi p=Q.top();Q.pop();
		int v=p.sec;
		if(p.fir > dist[v])continue;
		rep(i,sz(g1[v])){
			int w=g1[v][i].to;
			int nd=p.fir+g1[v][i].cost;
			if(nd < dist[w]){
				dist[w]=nd;
				Q.push(mp(nd,w));
			}
		}
	}
	
	rep(i,S)rep(j,sz(g1[i])){
		if(dist[i]+g1[i][j].cost == dist[g1[i][j].to]){
			g2[g1[i][j].to].pb(edge(i,g1[i][j].cost));
		}
	}
	
	stack<int> T;
	T.push(b);
	
	while(sz(T)){
		int v=T.top();T.pop();
		if(used[v])continue;
		used[v]=1;
		rep(i,sz(g2[v])){
			int w=g2[v][i].to;
			if(dist[v] == dist[w]+g2[v][i].cost){
				g3[w].pb(v);
				T.push(w);
			}
		}
	}
	
	rep(i,S)distv[i]=mp(dist[i],i);
	sort(distv,distv+S);
	
	rep(i,S){
		int v=distv[i].sec;
		rep(j,sz(g3[v])){
			G.pb(mp(v,g3[v][j]));
		}
	}
	
	int c,d;
	vector<pi> q;
	rep(i,nq){
		cin>>c>>d;
		q.pb(mp(c-1,d-1));
		if(sz(q)==64 || i==nq-1){
			fill(mask,mask+S,0);
			rep(j,sz(q)){
				mask[q[j].fir] |= 1LL<<j;
			}
			rep(j,sz(G)){
				mask[G[j].sec] |= mask[G[j].fir];
			}
			rep(j,sz(q)){
				cout<<(mask[q[j].sec] & 1LL<<j ? "Yes":"No")<<endl;
			}
			q.clear();
		}
	}
}

Measured memory_bytes: 25140
#include <iostream>

using namespace std;

int main () {

   int n, m, l;
   cin >> n >> m >> l;

   long A[100][100] = {}, B[100][100] = {}, C[100][100] = {};
   for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
         cin >> A[i][j];
      }
   }
   for (int i = 0; i < m; i++) {
      for (int j = 0; j < l; j++) {
         cin >> B[i][j];
      }
   }

   for (int i = 0; i < n; i++) {
      for (int j = 0; j < l; j++) {
         for (int k = 0; k < m; k++) {
            C[i][j] += A[i][k] * B[k][j];
         }
      }
   }

   for (int i = 0; i < n; i++) {
      cout << C[i][0];
      for (int j = 1; j < l; j++) {
         cout << " " << C[i][j];
      }
      cout << endl;
   }

   return 0;

}

Measured memory_bytes: 1400
X, N = map(int,input().split())
P = list(map(int,input().split()))
ans = 0
def f(X,N,P):
  if(N==0):
    ans = X
    return ans
  else:
    for i in range(N+1):
      if(not (X-i in P)):
        ans = X-i
        return ans
      elif(not (X+i in P)):
        ans = X+i
        return ans
print(f(X,N,P))

Measured memory_bytes: 9080
#include <cstdio>

using namespace std;
#define MAX_N 25
#define NIL -1

struct Node {
	int parent;
	int left;
	int right;
	int depth;
	int height;
	int degree;
	Node():parent(NIL),left(NIL),right(NIL),
		depth(NIL),height(NIL),degree(NIL) {}
	~Node(){}
};

Node tree[MAX_N];

// (tree index, set depth)
void setDepth(int index, int setval) {
	if (index == NIL) {
		return;
	}
	tree[index].depth = setval;
	setDepth(tree[index].left, setval + 1);
	setDepth(tree[index].right, setval + 1);
	return;
}

int setHeight(int index) {
	int h1 = 0, h2 = 0;
	if (tree[index].left != NIL) {
		h1 = setHeight(tree[index].left) + 1;
	}
	if (tree[index].right != NIL) {
		h2 = setHeight(tree[index].right)+1;
	}
	return tree[index].height = (h1 > h2 ? h1 : h2);
}

int getSebling(int id) {
	if (tree[id].parent == NIL) return NIL;
	// ?????????????????????????????????
	if (tree[tree[id].parent].left != id
		&& tree[tree[id].parent].right != NIL) {
		return tree[tree[id].parent].left;
	}
	// ?????????????????????
	if (tree[tree[id].parent].right != id
		&& tree[tree[id].parent].left != NIL) {
		return tree[tree[id].parent].right;
	}
	return NIL;
}

void print(int id) {
	printf("node %d: ", id);
	printf("parent = %d, ", tree[id].parent);
	printf("sibling = %d, ", getSebling(id));
	int deg = 0;
	if (tree[id].left != NIL) deg++;
	if (tree[id].right != NIL) deg++;
	printf("degree = %d, ", deg);
	printf("depth = %d, ", tree[id].depth);
	printf("height = %d, ", tree[id].height);

	if (tree[id].parent == NIL) {
		printf("root\n");
	}
	else if (tree[id].left == NIL && tree[id].right == NIL) {
		printf("leaf\n");
	}
	else {
		printf("internal node\n");
	}
	return;
}

int main() {
	int n = 0;
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		int id, l, r;
		scanf("%d%d%d", &id, &l, &r);
		tree[id].left = l;
		tree[id].right = r;
		if (l != NIL) {
			tree[l].parent = id;
		}
		if (r != NIL) {
			tree[r].parent = id;
		}
	}

	// ?????????????????????????±???????
	int root = 0;
	for (int i = 0; i < n; i++) {
		if (tree[i].parent == NIL) {
			root = i;
			break;
		}
	}
	// ?????°????????±???,??????????????????
	setDepth(root,0);
	setHeight(root);

	for (int i = 0; i < n; i++) print(i);
	return 0;
}

Measured memory_bytes: 2744
fun main(args: Array<String>) {
    val q = readLine()!!.toInt()
    val queries = (1..q).map { readLine()!!.split(" ").map { it.toInt() } }

    val n = 10e5.toInt()
    val s = Array(n) {0}
    for (i in 1 until n) {
        val flg = if ((i and 1 == 1) && isPrime(i) && isPrime((i + 1) / 2)) 1 else 0
        s[i] = s[i - 1] + flg
    }

    for ((l, r) in queries) {
        println(s[r] - s[l - 1])
    }
}

fun isPrime(x: Int): Boolean {
    if (x <= 1) {
        return false
    }

    for (i in 2..Math.sqrt(x.toDouble()).toInt()) {
        if (x % i == 0) {
            return false
        }
    }

    return true
}

Measured memory_bytes: 108764
import java.util.*;
public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n =Integer.parseInt(scan.next());
		HashSet<String> set = new HashSet<>();
		for (int i = 0 ;i < n; ++i){
			set.add(scan.next());
		}

		System.out.print(set.size());

	}
}
//end


Measured memory_bytes: 76648
def divisors(n: int) -> list:
    d = []
    for i in range(1, n + 1):
        q, r = divmod(n, i)
        if r == 0:
            d.append(i)
    return d


N = int(input())

ans = 0
for i in range(1, N + 1, 2):
    if len(divisors(i)) == 8:
        ans += 1

print(ans)


Measured memory_bytes: 3316
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll howMany(ll value, ll unit){
    ll sum = 0;
    FOR(i, 0, 7){
        ll num = (int)floor(value / pow(unit, i)) % unit;
        sum += num;
    }
    return sum;
}

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

    // input
    int N;
    cin >> N;

    ll answer = 100000;
    
    // 6でどれだけ払うか (6^0含む)
    FOR(i, 0, N+1){
        // i : 6で払う分
        ll num6 = howMany(i, 6);

        // rest : 9で払う分
        ll rest = N - i;
        ll num9 = howMany(rest, 9);
        
        answer = min(answer, num6+num9);
    }

    p(answer);

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

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


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

using namespace std;
typedef pair<int, int> ii;


const int N = 1e3;
vector<ii> e;
int adj[N][N];
int g[N][N];

int32_t main(){
  int n, m;
  cin >> n >> m;

  memset(g, 0x3f, sizeof g);
  for(int i = 0; i < n; i++) g[i][i] = 0;

  for(int i = 1; i <= m; i++){
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    adj[a][b] = g[a][b] = adj[b][a] = g[b][a] = c;
    e.push_back(ii(a, b));
  }

  for(int k = 0; k < n; k++){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }

  int ans = 0;
  for(ii p : e){
    int u, v;
    tie(u, v) = p;

    bool good = true;
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if(g[i][u] + adj[u][v] + g[v][j] == g[i][j])
          good = false;
      }
    }

    ans += good;
  }

  cout << ans << endl;
}


Measured memory_bytes: 8576
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <cstring>
#include <list>  
#include <cassert>
#include <climits>
#include <bitset>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;  
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

ll n, a, b;

ll solve() {
	if (a > b) swap(a, b);
	ll diff = abs(b - a);
	if (diff % 2 == 0) return diff / 2;
	ll ret = LLONG_MAX;
	REP(rep, 2) {
		ll aa = a, bb = b;
		ll x = aa - 1; aa -= x, bb -= x;
		ll y = 1; --bb;
		ll ddiff = abs(bb - aa);
		assert(ddiff % 2 == 0);
		ll z = ddiff / 2;
		ll cur = x + y + z;
		ret = min(ret, x + y + z);
		a = n - a + 1, b = n - b + 1; swap(a, b);
	}
	return ret;
}

void run() {
	scanf("%lld%lld%lld", &n, &a, &b);
	printf("%lld\n", solve());
}

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


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

using namespace std;
typedef long long ll;
const int MAXN = 1e5+10;

int n;

struct edge {
  int to;
  ll cost;
};

vector<edge> g[MAXN];
bool visited[MAXN];
bool color[MAXN];
int dist[MAXN];

void dfs(int x) {
  visited[x] = true;
  for (int i=0;i<g[x].size();i++) {
    int next = g[x][i].to;
    if (!visited[next]) {
      dist[next] = (dist[x] + g[x][i].cost) & 1;
      color[next] = !(dist[next] & 1);
      dfs(next);
    }
  }
}

void solve() {
  color[0] = true; // black
  dfs(0);
  for (int i=0;i<n;i++) {
    cout << (color[i] ? '0' : '1') << endl;
  }
}

int main() {
  cin >> n;
  for (int i=0;i<n-1;i++) {
    int u, v, w;
    cin >> u >> v >> w;
    g[--u].push_back((edge){--v, w});
    g[v].push_back((edge){u, w});
  }
  solve();
}


Measured memory_bytes: 9984
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (true) {
			int n = Integer.parseInt(in.next());
			int x = Integer.parseInt(in.next());
			if (n == 0 && x == 0) {
				break;
			}
			int count = 0;
			for (int i = 1; i <= n - 2; i++) {
				for (int j = i + 1; j <= n - 1; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
		in.close();
	}
}	


Measured memory_bytes: 26476
#include <bits/stdc++.h>
using namespace std;
int main(){
string x,y,l,n;
cin>>x;
int z=0;
 y=x;
 l=x;
 n=x;
int o,j,a,s;
o=x.size()-1;
j=x.size()-1;
a=(x.size()-1)/2-1;
s=(x.size()+3)/2-1;
for(int i=0;i<j;i++){
    swap(x[j],x[i]);
    j--;
}
if(x==y){
    z++;}

    for(int i=0;i<=a;i++){
            if(a==1){
            break;
    z++;
    }
    swap(l[a],l[i]);
    a--;
}
if(l==y){
    z++;}

for(;s<o;s++){
    swap(n[o],n[s]);
    o--;
}
if(n==y){
    z++;}

if (z==3)
cout<<"Yes";
else
cout<<"No";
return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int qpow(int x,int k)
{
    int r=1;
    while(k)
    {
        if(k&1)r=1ll*r*x%mod;
        k>>=1;x=1ll*x*x%mod;
    }
    return r;
}
int add(int x,int y){return x+y<mod?x+y:x+y-mod;}
int n;
char s[300300];

int X[6]={233,1919,114514,817,1001,9527};
int inv[6];
struct Node {
    int v[6];
    bool operator < (const Node &o)const{
        for(int i=0;i<6;++i)
            if(v[i]!=o.v[i])return v[i]<o.v[i];
        return 0;
    }
    void clear(){memset(v,0,sizeof(v));}
    void f(char c)
    {
        if(c=='+') for(int i=0;i<6;++i)v[i]=add(v[i],1);
        else if(c=='-') for(int i=0;i<6;++i)v[i]=add(v[i],mod-1);
        else if(c=='>') for(int i=0;i<6;++i)v[i]=1ll*v[i]*X[i]%mod;
        else if(c=='<') for(int i=0;i<6;++i)v[i]=1ll*v[i]*inv[i]%mod;
    }
};
map<Node,int>mp;
struct PNN{
    Node k,b;
    void clear() { for(int i=0;i<6;++i)k.v[i]=1,b.v[i]=0; }
    void f(char c)
    {
        if(c=='+')for(int i=0;i<6;++i)b.v[i]=add(b.v[i],mod-k.v[i]);
        else if(c=='-')for(int i=0;i<6;++i)b.v[i]=add(b.v[i],k.v[i]);
        else if(c=='>')for(int i=0;i<6;++i)k.v[i]=1ll*k.v[i]*inv[i]%mod;
        else if(c=='<')for(int i=0;i<6;++i)k.v[i]=1ll*k.v[i]*X[i]%mod;
    }
    Node calc(Node x)
    {
        Node res;
        for(int i=0;i<6;++i)
            res.v[i]=add(1ll*k.v[i]*x.v[i]%mod,b.v[i])%mod;
        return res;
    }
};
int main()
{
    for(int i=0;i<6;++i)inv[i]=qpow(X[i],mod-2);
    scanf("%d",&n);
    scanf("%s",s+1);
    Node C;C.clear();
    for(int i=n;i;--i)C.f(s[i]);
    Node o;o.clear();
    mp[o]++;
    PNN cur;cur.clear();
    long long ans=0;
    for(int i=n;i;--i)
    {
        cur.f(s[i]);
        Node tt=cur.calc(C);
        ans+=mp[cur.calc(C)];
        mp[cur.calc(o)]++;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 39552
# Fast IO (only use in integer input) or take care about string
 
import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
 
N = int(input())
 
ans = 0
for i in range(N):
  ans += (N-i) * (i+1)
for _ in range(N-1):
  a,b = map(int,input().split())
  if a > b:
    c = a
    a = b
    b = c
  ans -= a * (N - b + 1)
print(ans)

Measured memory_bytes: 78268
#include <iostream>

using namespace std;

int main(void){
	for(;;){
		int h, w;

		cin >> h >> w;
		if(h == 0 && w == 0)
			break;

		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++)
				cout << '#';
			cout << endl;
		}
		cout << endl;
	}
}



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


int main(){

    string S,T;
    cin >> S >> T;

    if(S.length()+1==T.length()){
        int judge = 0;
        for(int i=0;i<S.length();i++){
            if(S[i]!=T[i]) judge++;
        }
        if(!judge){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }

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

    return 0;
}


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

int n, m;

bool chk(vector<int> &on, vector<vector<int>> &s, vector<int> &p){
  int c;
  for(int i=0; i<m; ++i){
    c=0;
    for(int j=0; j<10; ++j){
      if(s[i][j]==-1) break;
      if(on[s[i][j]]) c++;
    }
    if(c%2==p[i]){
      continue;
    }
    else{
      return false;
    }
  }
  return true;
}

int main(){
  int k;
  vector<vector<int>> s(11, vector<int>(11, -1)); // どのスイッチに紐付いているか
  vector<int> p(11, -1); // 点灯条件
  
  cin >> n >> m;
  rep(i, m) {
    cin >> k;
    rep(j, k){
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  rep(i, m) cin >> p[i];
  
  int cnt=0;
  vector<int> on(n); // スイッチ状態
  for(int bit=0; bit < (1<<n); ++bit){
    
    for(int i=0; i<n; ++i){
      if(bit & (1<<i))
        on[i]=1;
      else
        on[i]=0;
    }

    if(chk(on, s, p)){
      cnt++;
    }
  }
  
  cout << cnt << endl;  
  return 0;
}


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

int main(){
	int L, mon[12][2], sav, i;
	
	while(1){
		sav = 0;
		cin >> L;
		if(L == 0)
			return 0;
		for(i = 0; i < 12; i++){
			cin >> mon[i][0] >> mon[i][1];
		}
		
		for(i = 0; i < 12; i++){
			sav += mon[i][0]-mon[i][1];
			if(sav >= L){
				cout << i+1 << endl;
				break;
			}
		}
		
		if(sav < L)
			cout << "NA" << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <numeric>

using namespace std;

int main(){
   int n,a,b;
   cin>>n>>a>>b;
   cout<<min(n*a,b)<<endl;
   

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

std::string EvalCommand(std::string commands)
{
    std::string answer = "";
    for(const auto& command : commands)
    {
        if(command == '0')
            answer += "0";
        else if(command == '1')
            answer += "1";
        else
            answer = answer.substr(0,answer.length()-1);
    }
    return answer;
}

int main(int argc, char const *argv[]) {

    std::string s;
    std::cin >> s;
    
    std::cout << EvalCommand(s) << '\n';

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String readStr;

    LinkedList<Integer> queue = new LinkedList<Integer>();
    while ((readStr = reader.readLine()) != null) {
      int readInt = Integer.parseInt(readStr);
      if (readInt == 0)
        System.out.println(queue.removeLast());
      else
        queue.add(readInt);
    }
  }

}

Measured memory_bytes: 16856
#include <bits/stdc++.h>
#define hell 1000000007
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long int
#define pi 3.1415926536
using namespace std;
void solve()
{ll t,n,x,y,z,d=0,p=INT_MAX,q,l=INT_MAX,mini=0,prev;
  cin>>n;
  vector<ll> v(n+1),a(n);
  for(ll i=0;i<n+1;i++)
  cin>>v[i];
  for(ll i=0;i<n;i++)
  cin>>a[i];
  for(ll i=0;i<n;i++)
  {
  	if(a[i]>v[i])
  	{	d+=v[i];
  		a[i]-=v[i];
  		v[i]=0;
  		if(a[i]>v[i+1])
  		{
  			a[i]-=v[i+1];
  			d+=v[i+1];
  			v[i+1]=0;
		  }
		  else
		  {
		  	d+=a[i];
		  	v[i+1]-=a[i];
		  	a[i]=0;
		  }
	}
	else
	{
		v[i]-=a[i];
		d+=a[i];
		a[i]=0;
	}
  }
  cout<<d;
}

int main()
{
  fast
ll t=1;

while(t--)
{solve();
 //cout<<ma<<endl;
}
return 0;}

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

int main(){
  int N;
  cin >> N;
  
  vector<double> vec(N);
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  double sum = 0.0;
  
  for (int i = 0; i < N; i++){
    sum = sum + ( 1.0 / vec.at(i) );
  }
  
  double ans = 1.0 / sum;
  
  cout << fixed << setprecision(10);
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
    ll ans = 1;
    ll mod = 1000000007;

    int n; cin >> n;
    for(int i=1; i<=n; i++) ans = ans * i % mod;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<limits.h>

int main(){
  int i,bc[4],price,coins[4],buf[4],bp,end,form[]={10,50,100,500},j,sp;
  int num,c;
  char flg=0;
  do{
    scanf("%d",&price);
    if(!price) break;
    if(flg) printf("\n");
    scanf("%d %d %d %d",coins,coins+1,coins+2,coins+3);
    for(i=0,end=1;i<4;i++){
      buf[i]=bc[i]=0;
      if(coins[i]) end*=coins[i]+1;
    }
    for(end--,i=0,bp=INT_MAX;i<end;i++){
      for(j=0;j<4;j++)
	if(coins[j]!=0&&buf[j]+1<=coins[j]) break;
	else buf[j]=0;
      buf[j]++;
      for(j=0,sp=0;j<4;j++) sp+=buf[j]*form[j];
      if(sp>=price){
	for(num=sp-price,j=3,c=0;j>-1;j--){
	  if(num>=form[j]){
	    c+=num/form[j];
	    num-=form[j]*(num/form[j]);
	  }
	}
	for(j=0;j<4;j++) c+=coins[j]-buf[j];
	if(c<bp){
	  for(j=0;j<4;j++) bc[j]=buf[j];
	  bp=c;
	}
      }
    }
    for(i=0;i<4;i++)
      if(bc[i]) printf("%d %d\n",form[i],bc[i]);
    flg=1;
  }while(1);
  return 0;
}

Measured memory_bytes: 412
#include<stdio.h>
#include<math.h>
  
int main(){
  int n, x[100], y[100];
  int i, k, max = 0;
  double ans;
  
  scanf("%d", &n);
    
  for(i = 0; i<n; ++i){
    scanf("%d", &x[i]);
  }
  for(i = 0; i<n; ++i){
    scanf("%d", &y[i]);
  }
  
  for(i = 1; i<4; ++i){
    ans = 0;
    for(k = 0; k<n; ++k){
      ans += pow(fabs(x[k] - y[k]), i);
      if(max < fabs(x[k] - y[k])){
    max = fabs(x[k] - y[k]);
      }
    }
    ans = pow(ans, 1.0/i);
  
    printf("%lf\n", ans);
  }
  
  printf("%d\n", max);
    
  return 0;
}


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

ll f(ll n) {
  string s = to_string(n);
  ll len = s.length();
  if (len < 2) return -1;
  reverse(s.begin(), s.end());
  for (int i=0; i<len-1; i++) {
    if (abs(s[i] - s[i+1]) > 1) return i;
  }
  return -1;
}

ll g(ll n) {
  string s = to_string(n);
  ll len = s.length();
  if (len < 2) return n+1;
  ll t = -1;
  for (int i=0; i<len-1; i++) {
    if (s[i+1] - s[i] > 1) {
      t = i;
      break;
    }
  }
  if (t > -1) {
    for (int j=0; j<len; j++) {
      if (j < t) continue;
      if (j == t) s[j]++;
      if (j > t) s[j] = '0' + max(s[j-1]-'0'-1, 0);
    }
    // cout << "s = " << s << endl;
    return stoll(s);
  }
  return n+1;
}

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

  ll cnt = 0;
  ll n = 1;
  while (cnt < k) {
    ll t = f(n);
    if (t < 0) {
      cnt++;
      // printf("n = %lld\n", n);
      n++;
    } else {
      n = g(n);
      // printf("\tn = %lld\n", n);
    }
  }
  cout << n-1 << endl;

  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;

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    for (ll &l:v) cin >> l;

    vector<ll> r = {v[0]};
    ll ans = 0;
    for (int i = 1; i < n; i++) {
        ll next = v[i];
        if (r.back() <= next) {
            r.push_back(next);
            continue;
        }

        assert(next < r.back());
        ll sub = r.back() - next;
        ans += sub;
        r.push_back(r.back());
    }

    cout << ans << endl;

}


Measured memory_bytes: 6928
//  Copyright © 2019 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 300005
using namespace std;
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
typedef long long i64;

int N, ans;
int l[MAX];
int r[MAX];
int a[MAX];

int main()
{
    optimiza_io 
    cin >> N;
    for( int i = 1; i <= N; i ++ )
        cin >> a[i];
    
    for( int i = 1; i <= N; i ++ )  
        l[i] = __gcd( l[i - 1] , a[i] );
        
    for( int i = N; i >= 1; i -- )  
        r[i] = __gcd( r[i + 1] , a[i] );
    
    for( int i = 1; i <= N; i ++ )
        ans = max( ans , __gcd( l[i - 1] , r[i + 1] ) );
        
    cout << ans;
    return 0;
}

Measured memory_bytes: 1408
# import itertools
# import math
# from functools import reduce
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque
import copy

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
X = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

#def make_divisors(n):
#    lower_divisors , upper_divisors = [], []
#    i = 1
#    while i*i <= n:
#        if n % i == 0:
#            lower_divisors.append(i)
#            if i != n // i:
#                upper_divisors.append(n//i)
#        i += 1
#    return lower_divisors + upper_divisors[::-1]

# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)

# if gcd_list(A) > 1:
#     print("not coprime")
#     exit()

# 高速素因数分解準備
#MAXN = 10**6+10
#sieve = [i for i in range(MAXN+1)]
#p = 2
#while p*p <= MAXN:
#    if sieve[p] == p:
#        for q in range(2*p, MAXN+1, p):
#            if sieve[q] == q:
#                sieve[q] = p
#    p += 1

X = [[i, x] for i, x in enumerate(X)]
X = sorted(X, reverse=False, key=lambda x:x[1])
X_ranked = copy.copy(X)
X = [[l[0], i, l[1]] for i, l in enumerate(X)]
X = sorted(X, reverse=False, key=lambda x:x[0])

med = len(X) // 2

for l in X:
    if l[1] < med:
        print(X_ranked[med][1])
    else:
        print(X_ranked[med - 1][1])


Measured memory_bytes: 71924
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <set>

#define LR_L 0
#define LR_R 1
using namespace std;

int main(void) {
    int n,a,b;
    multiset<int> mr,ml;
    cin >> n;
    for(int i = 0;i < n;i++) {
        cin >> a >> b;//L R
        ml.insert(a);
        mr.insert(b);
    }
    ml.insert(0);
    mr.insert(0);
    long long res = 0;
    auto itr_l = ml.rbegin();
    auto itr_r = mr.begin();
    while(*itr_l - *itr_r > 0) {
        res = res + (*itr_l - *itr_r);
        itr_r++;
        itr_l++;
    }
    cout << res * 2 << endl;
    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 5;
const int inf = 0x3f3f3f3f;

int main() {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    printf("%d\n", max(a*b,c*d));
    return 0;
}


Measured memory_bytes: 256
# 入力
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

x = lc()

# Sを開きカッコ(, Tを閉じカッコ)のように考える
s_cnt = 0
ans = 0
for c in x:
    if c == "S":
        s_cnt += 1
    else:
        s_cnt -= 1
        
        if s_cnt < 0:
            ans += 1
            s_cnt = 0

ans += s_cnt

print(ans)

Measured memory_bytes: 4840
import java.util.*;
public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		long ans=0;
		long[] A=new long[N];
		long sum=0;
		int mod=1000000007;
		for(int i=0;i<N;i++){
			A[i]=sc.nextInt();
			sum+=A[i];
          	sum%=mod;
		}
		for(int i=0;i<N;i++){
				sum+=mod;
          		sum-=A[i];
          		sum%=mod;
				ans+=A[i]*sum;
              	ans%=mod;
		}
		System.out.println(ans);
		
		
	}
}



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

int main() 
{
    int n, x;
    cin >> n >> x;
    vector<int> v(n);
    int sum=0;
    for (int i=0; i<n; i++)
    {
        cin >> v[i];
        sum += v[i];
    }
    int min = *min_element(v.begin(), v.end());
    cout << n+(x-sum)/min;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
ll f(ll H) {
    if(H == 1) return 1;
    else return 1 + 2 * f(H / 2);
}
void solve(long long H) {
    cout << f(H) << endl;
}
int main() {
    long long H;
    scanf("%lld",&H);
    solve(H);
    return 0;
}


Measured memory_bytes: 256
from collections import deque
h, w = map(int, input().split())
grid = [list(input()) for _ in range(h)]

gidx = 0
for i in range(h):
    for j in range(w):
        if grid[i][j] == '.':
            grid[i][j] = gidx
            gidx += 1
node_cnt = gidx
g = [[] for _ in range(node_cnt)]
for i in range(h):
    for j in range(w):
        if grid[i][j] != '#':
            gidx = grid[i][j]
            #上下左右
            if i > 0 and grid[i-1][j] != '#':
                g[gidx].append(grid[i-1][j])
            if i < h-1 and grid[i+1][j] != '#':
                g[gidx].append(grid[i+1][j])
            if j > 0 and grid[i][j-1] != '#':
                g[gidx].append(grid[i][j-1])
            if j < w-1 and grid[i][j+1] != '#':
                g[gidx].append(grid[i][j+1])

num_white = sum(s.count('.') for s in g)
d = [-1] * node_cnt
seen = [False] * node_cnt

q = deque()
def bfs():
    q.append(0)
    d[0] = 0
    seen[0] = True
    while len(q) > 0:
        now_v = q.popleft()
        for new_v in g[now_v]:
            if seen[new_v]:
                continue
            seen[new_v] = True
            q.append(new_v)
            d[new_v] = d[now_v] + 1

bfs()
ok = True
if grid[0][0] == '#' or grid[h-1][w-1] == '#' or d[node_cnt - 1] == -1:
    ok = False

print(node_cnt - d[node_cnt - 1] - 1 if ok else -1)

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

vll ans;
vvll to;
priority_queue<ll> c;

void dfs(ll cur, ll pre=-1){
	for(auto&& next:to[cur]){
		if(ans[cur]==0){
			ans[cur]=c.top();
			c.pop();
		}
		if(next!=pre) dfs(next,cur);
	}
}

int main()
{
	ll n;
	cin >> n;
	ans.resize(n);
	to.resize(n);
	rep(i,n-1){
		ll a,b;
		cin >> a >> b;
		a--;
		b--;
		to[a].pb(b);
		to[b].pb(a);
	}
	ll sum=0,tmp=0;
	rep(i,n){
		ll x;
		cin >> x;
		sum+=x;
		chmax(tmp,x);
		c.push(x);
	}
	dfs(0);
	cout << sum-tmp << endl;
	for(auto&& e:ans) cout << e << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 1536
A, B, C, D = map(int, input().split())

A_n = C // B
amari = C % B
if amari > 0:
  A_n += 1

C_n = A // D
amari = A % D
if amari > 0:
  C_n += 1

if A_n <= C_n:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9184
s = input().split()
n = int(s[0])
m = int(s[1])
x = int(s[2])
y = int(s[3])

city_a = []
city_b = []

v = input().split()
w = input().split()

for i in range(n):
    city_a.append(int(v[i]))
for i in range(m):
    city_b.append(int(w[i]))

city_a.sort()
city_b.sort()

p = city_a.pop()
q = city_b[0]

check = False

for i in range(x + 1, y+1):
    if p < i <= q:
        check = True
        break

if check:
    print('No War')
else:
    print('War')


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

using namespace std;

#define int long long
#define forr(i,n) for(int i = 0;i < (int)n; i++)
#define forn(i,n) for(int i = (int)(n-1); ~i ;i--)
#define deb(x) cout<<#x<<" " <<x<<"\n";
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define pb push_back
#define mpa make_pair
#define endl "\n"
#define ar array

const int INF = (int)2e9+10;
const int mxN = (int)2e5+10;
const int MOD = (int)1e9 + 7;


void solve(){
	string s,t;
	cin>>s>>t;
	int ans = 0;
	forr(i,s.length()){
		if(s[i]!=t[i]) ans++;
	}
	cout<<ans;
}


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


Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define sortall(obj) sort(ALL(obj))
#define revall(obj) reverse(ALL(obj))
#define SortRevAll(obj) revall(sortall(obj))
typedef string str;
typedef long long ll;
const int mod=1e9+7;
const int INF=1e9;
const ll LINF=1e18;
#define VI vector<int>
#define P pair
#define M map
#define F first()
#define S second()
#define PB(a) push_back(a)
#define IN(a) insert(a)
#define ins(a) int a;cin >> a
#define lls(a) ll a;cin >> a
#define in(a) cin >> a
#define sts(a) string (a);cin >> a
#define For(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) For(i,0,n)
#define Forr(i,m,n) for(int i=n-1;i>=m;i--)
#define repr(i,n) Forr(i,0,n)
#define print(a) cout << a << endl
#define Endl cout << endl
#define YES(n) cout << ((n)? "YES" : "NO") << endl
#define Yes(n) cout << ((n)? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define br(c,y,n) cout << ((c)? y : n) << endl

int main(){
    ins(a);sts(s);ins(b);
    if(s=="+"){
        print(a+b);
    }else{
        print(a-b);
    }

    return 0;
}


Measured memory_bytes: 256