akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var n = sc.nextInt();
		var s = sc.next();
		sc.close();

		var chars = s.toCharArray();
		var rcount = IntStream.range(0, chars.length).filter(i -> chars[i] == 'R').count();
		var gcount = IntStream.range(0, chars.length).filter(i -> chars[i] == 'G').count();
		var bcount = IntStream.range(0, chars.length).filter(i -> chars[i] == 'B').count();
		var sum = rcount * gcount * bcount;
		for (var i = 0; i < n - 2; i++) {
			var char1 = chars[i];
			for (var j = i + 1; j < n - 1; j++) {
				var char2 = chars[j];
				if (char1 != char2) {
					var k = j + (j - i);
					if (k < n) {
						var char3 = chars[k];
						if (char1 != char3 && char2 != char3) {
							sum--;
						}
					}
				}
			}
		}

		System.out.println(sum);
	}
}

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

int main(){
  int A, B;
  cin >> A >> B;
  int count=0;
  for (int i=A; i<=B; i++){
    string a=to_string(i);
    if (a.at(0)==a.at(4) && a.at(1)==a.at(3)){
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int c=0,mx=0;
    for(int i=0; i<s.size(); i++)
    {

        if(s[i]=='R')
        {
            c++;

        }
        else
        {
            c=0;
        }
        mx=max(c,mx);



    }
    cout<<mx<<endl;

}


Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
  int H, N, A, D = 0;
  cin >> H >> N;
  for(int i = 0; i < N; i++){
    cin >> A;
    D += A;
  }
  if(D >= H) cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 256
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

A, B, K =  map(int, sys.stdin.readline().split())

for i in range(A, min(B + 1, A + K)):
    print(i)
for i in range(max(B - K + 1, A + K), B + 1):
    print(i)

"""
X = [x for x in range(A, min(A + K, B + 1))] + [x for x in range(max(B - K + 1, A), B + 1)]
for x in sorted(list(set(X))):
    print(x)
"""

Measured memory_bytes: 63980
// A.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <string>
#include <vector>

using namespace std;
int main()
{
	unsigned long long N;
	cin >> N;

	vector<unsigned long long> mods;
	unsigned long long tempN = N;
	long length = 0u;
	while (tempN > 0)
	{
		unsigned long long mod = tempN % 26;
		if (mod == 0)
		{
			mods.emplace_back(26);
		}
		else
		{
			mods.emplace_back(mod);
		}
		length++;
		tempN /= 26;
		if (mod == 0)
		{
			tempN -= 1;
		}
	}

	vector<char> vresult;
	for (auto i = 0u; i < length; ++i)
	{
		vresult.emplace_back('a' + (mods[i] - 1));
	}

	for (auto i = length - 1; i >= 0; --i)
	{
		cout << vresult[i];
	}
	cout << endl;
}

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

void solve(){
	int a;
	cin>>a;
	vector<int64_t>v(a);
    for(int i=0;i<a;i++)
		cin>>v[i];
	sort(v.begin(),v.end());
	if(v[0]==0){
		printf("0");
	}
	else{
		long double res=1;
		for(int i=0;i<a;i++){
			res*=v[i];
			if(res>1e18){
				printf("-1");
			    return ;
			}
		}
		cout<<(long long )(res);
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}


Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {

fast();

{
  int n;
  cin>>n;
  int d=n%10;
  n/=10;
  int c=n%10;
  n/=10;
  int b=n%10;
  n/=10;
  int a=n%10;
  //cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
  if((a==b&&b==c)||(b==c&&c==d))
  {
    Yes
  }
  else
  {
    No
  }


}
return 0;
}


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

int main() {
    int h[10] = {};
    for(int i=0; i<10; ++i) {
        cin >> h[i];
    }
    sort(rbegin(h), rend(h));
    for(int i=0; i<3; ++i) {
        cout << h[i] << endl;
    }
}


Measured memory_bytes: 3080
re = /(?<p>\(\g<p>*\))/

ll = r = l = rr = 0
r_min = []
l_min = []
gets.to_i.times{|n|
	s = gets.chomp.gsub(re,'')
	next if s.empty?

	if s[0] == ?(
		ll += s.size
	elsif s[-1] == ?)
		rr += s.size
	else
		i = s.index(?()
		r += i
		l += s.size-i
		r_min = r_min.push([i,n]).sort_by{|_,|_}.take(2)
		l_min = l_min.push([s.size-i,n]).sort_by{|_,|_}.take(2)
	end
}

if ll+l == rr+r and r_min.empty? || r_min.product(l_min).any?{|(r,ri),(l,li)| ri!=li && ll>=r && l<=rr }
	puts'Yes'
else
	puts'No'
end


Measured memory_bytes: 16076
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstdlib>
using namespace std;
struct Node{int key; Node *p,*l,*r;};
Node *null,*root;


void insert(int k){
Node *x,*y,*z;
	y=null;
	x=root;
	z=(Node*)malloc(sizeof(Node));
	z->key=k;
	z->l=null;
	z->r=null;
	while(x!=null){
	    y=x;
		if(z->key<x->key)
		x=x->l;
		else 
		x=x->r;
	}
	z->p=y;
	if(y==null)
	root=z;
	else if(z->key>y->key)
	y->r=z;
	else
	y->l=z;
}
void in_p(Node *u){
	if(u==null)
	return;
	in_p(u->l);
	printf(" %d",u->key);
	in_p(u->r);
}
void pre_p(Node *u){
	if(u==null)
	return ;
	printf(" %d",u->key);
	pre_p(u->l);
	pre_p(u->r);
}
void print(){
	in_p(root);
	printf("\n");
	pre_p(root);
	printf("\n");
}
bool find(Node *a,int k){
	if(a==null)
	return false;
	    else if(a->key==k)
		return true;
		else if(a->key>k)
	     find(a->l,k);
	    else 
	    find(a->r,k);
	}
	Node* getmin(Node *x){
	while(x->l!=null)
	x=x->l;
	return x;
}
Node* getS(Node *x){
	if(x->r!=null)
	return getmin(x->r);
	Node *y;
	y=x->p;
	while(y!=null&&x==y->r){
	x=y;
		y=y->p;
	}
	return y;
}

void Delete(int k){
Node *y,*z,*x;
	x=null;
	z=root;
	while(z->key!=k&&z!=null){
		if(k>z->key)
		z=z->r;
		else
		z=z->l;
	}
	if(z->l==null || z->r==null)
	y=z;
else 
	y=getS(z);
	if(y->l!=null)
	x=y->l;
	else
	x=y->r;
	if(x!=null)
	x->p=y->p;
	if(y->p==null)
	root=x;
	else if(y==y->p->l)
	y->p->l=x;
	else
	y->p->r=x;
	if(y!=z)
	z->key=y->key;
	free(y);
}

main(){
	int i,n,key;
	string com;
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		cin>>com;
		if(com=="insert"){
			scanf("%d",&key);
			insert(key);
		}
		else if(com=="find"){
			scanf("%d",&key);
			if(find(root,key))
			printf("yes\n");
			else
			printf("no\n");
		}
		else if(com=="delete"){
			scanf("%d",&key);
			Delete(key);
		}
		else 
		print();
	}
	
	return 0;
}



Measured memory_bytes: 22080
#include <iostream>
#include <functional>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n

#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define FOR(i,m,n) for(int (i)=(m);(i)<(n); i++)
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define WREP(i,in,j,jn) REP(i,in)REP(j,jn)
using namespace std;
//-------------------------------------------

int main(void){
  ll N,R;
  cin>>N>>R;
  cout<<(N<10?R+100*(10-N):R);
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    int sum = 0;
    int a = N;
    for(int i = 0;;){
        sum += a % 10;
        a /= 10;
        if(a==0)break;
    }
    if(N%sum==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s,t;
    cin>>s>>t;
    int i,ans=0;
    for(i=0;i<s.size();i++){
        if(s[i]!=t[i]) ans++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3800
#include<iostream>

using namespace std;


int main() {
	char Num[1000];
	int Output;

	while (true) {
		Output = 0;

		cin >> Num;

		if (Num[0] == '0'&&Num[1] == '\0')break;

		for (int i = 0; Num[i] != '\0'; i++)Output += Num[i] - '0';
		
		cout << Output << endl;
	}

	return 0;
}

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

int main() {
  long long N,M;
  cin >> N;
  cin >> M;
  long long a[N],b[N];
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    cin >> b[i];
  }

  vector<pair<long long,long long>> AB(N);
  for(int i = 0; i < N; ++i){
    AB[i] = make_pair(a[i],b[i]);
  }
  sort(AB.begin(),AB.end());

  long long count = 0;
  int i = 0;

  while(M>0){
    if(AB[i].second<M){
      M -= AB[i].second;
      count += AB[i].first*AB[i].second;
    }
    else{
      count += AB[i].first*M;
      break;
    }
    ++i;
  }

  cout << count << endl;

}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <queue>
using namespace std;

using VI = vector <int>;
using VVI = vector <VI>;

struct Que {
    Que(int pr, int pc, int pd) : r(pr), c(pc), d(pd) {
    }
    int r;
    int c;
    int d;

    bool operator<(const Que& q) const {
        return d > q.d; // min queue
    }
};

int main() {
    int H;
    int W;
    cin >> H >> W;

    vector <int> C(2);
    vector <int> D(2);
    vector <string> S(H);

    cin >> C[0] >> C[1];
    cin >> D[0] >> D[1];

    --C[0];
    --C[1];
    --D[0];
    --D[1];

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

    VVI best(H, VI(W, -1));
    const char OBSTACLE = '#';

    priority_queue <Que> que;

    if (S[C[0]][C[1]] != OBSTACLE) {
        best[C[0]][C[1]] = 0;
        que.push(Que(C[0], C[1], 0));
    }

    while (!que.empty()) {
        Que q = que.top();
        que.pop();

        // normal
        const int dr[] = {1, -1, 0, 0};
        const int dc[] = {0, 0, 1, -1};

        for (int dir = 0; dir < 4; ++dir) {
            int newr = dr[dir] + q.r;
            int newc = dc[dir] + q.c;

            int newcost = best[q.r][q.c];

            if (newr < H && newr >= 0
            && newc < W && newc >= 0
            && S[newr][newc] != OBSTACLE
            && (best[newr][newc] == -1 || newcost < best[newr][newc])) {
                best[newr][newc] = newcost;
                que.push(Que(newr, newc, newcost));
            }
        }

        // magic
        for (int mdr = -2; mdr <= 2; ++mdr) {
            for (int mdc = -2; mdc <= 2; ++mdc) {
                int newr = mdr + q.r;
                int newc = mdc + q.c;

                int newcost = best[q.r][q.c] + 1;

                if (newr < H && newr >= 0
                && newc < W && newc >= 0
                && S[newr][newc] != OBSTACLE
                && (best[newr][newc] == -1 || newcost < best[newr][newc])) {
                    best[newr][newc] = newcost;
                    que.push(Que(newr, newc, newcost));
                }
            }
        }
    }

    cout << best[D[0]][D[1]] << endl;

    return 0;
}

Measured memory_bytes: 9536
#include <stdio.h>
#define N 105
#define BLACK -2
#define WHITE 1
#define INF 100009
#define NIL -5

typedef struct {
  int color, d, pi;  
}Record;


void dijkstra(int);



int adj[N][N];
int n;
Record data[N];



int main () {
  int m, i, j, p, k, sum =0;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++) {
    scanf("%d %d",&p, &k);

    for(j = 0 ; j < k ; j++) {
      scanf("%d",&m);
      scanf("%d",&adj[p][m]);
      
    }
    
      //Insert(m, i);
  }
  

  dijkstra(0);

  for(i = 0 ; i < n ; i++) {
    printf("%d %d\n",i,data[i].d);
  }

  return 0;
}



void dijkstra(int r) {
  int i, u, mincost = 0;

  for(i = 0 ; i < n ; i++) {
    data[i].color = WHITE;
    data[i].d = INF;
    data[i].pi = NIL;

  }

  data[r].d = 0;
  

  while(1) {
    mincost = INF;

    for(i = 0 ; i < n ; i++) {
      if(data[i].color != BLACK) {
	if(data[i].d < mincost) {
	  mincost = data[i].d;
	  u = i;
	}
      }
    }

    if(mincost == INF) break;

    data[u].color = BLACK;

    for(i = 0 ; i < n ; i++) {
      if(data[i].color != BLACK && (adj[u][i] + data[u].d) < data[i].d && adj[u][i] > 0) {
	data[i].pi = u;
	data[i].d = adj[u][i] + data[u].d;
	//printf("from %d to %d connected (cost %d)\n", u, i, data[i].d);
      }
    }
  }
}



Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
    using namespace std;
    int N;
    cin >> N;
    int ts[N];
    for (int i = 0; i < N; i++) {
        cin >> ts[i];
    }
    int ma = 0;
    for (int i = 0; i < N; i++) {
        ma += ts[i];
    }
    ma = ma / 3 + 50;
    static int s[51][900][900];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < ma; j++) {
            for (int k = j; k < ma; k++) {
                vector<int> p;
                p.push_back(s[i][j][k] + ts[i]);
                if (j >= ts[i]) {
                    p.push_back(s[i][j - ts[i]][k]);
                }
                if (k >= ts[i]) {
                    p.push_back(s[i][j][k - ts[i]]);
                }
                s[i + 1][j][k] = s[i + 1][k][j] = *min_element(p.begin(), p.end());
            }
        }
    }
    int i = ma - 50;
    while (true) {
        if (s[N][i][i] <= i)
            break;
        i += 1;
    }
    cout << i << endl;
}

Measured memory_bytes: 148800
#include<iostream>


//関数の宣言
void func(int cards[4][13], char symbol, int figure);
void output(int cards[4][13]);

int main(){

	int n;
	int figure;
	char symbol;
	const int mark = 4;
	const int num = 13;
	int cards[mark][num];

	for (int i = 0; i < 4; ++i)
		for (int j = 0; j < 13; ++j){
			cards[i][j] = 1;
		}

	std::cin >> n;


	for (int m = 0; m < n; ++m){
		std::cin >> symbol >> figure;
		func(cards, symbol, figure);
	}
	output(cards);
}

//関数の定義
void func(int cards[4][13], char symbol, int figure){
	if (symbol == 's' || symbol == 'S'){
		cards[0][figure-1] = 0;
	}
	else if (symbol == 'h' || symbol == 'H'){
		cards[1][figure-1] = 0;
	}
	else if (symbol == 'c' || symbol == 'C'){
		cards[2][figure-1] = 0;
	}
	else if (symbol == 'd' || symbol == 'D'){
		cards[3][figure-1] = 0;
	}
}

void output(int cards[4][13]){
	for (int k = 0; k < 4; ++k){
		for (int l = 0; l < 13; ++l){
			if (cards[k][l] == 1){
				if (k == 0){
					std::cout << 'S' << ' ' << l + 1 << '\n';
				}
				else if (k == 1){
					std::cout << 'H' << ' ' << l + 1 << '\n';
				}
				else if (k == 2){
					std::cout << 'C' << ' ' << l + 1 << '\n';
				}
				else if (k == 3){
					std::cout << 'D' << ' ' << l + 1 << '\n';
				}
			}
		}
	}
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 220000
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld",&s);
#define sout(s) printf("%lld\n",s);
#define in(s) cin>>s
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl '\n'
#define sp ' '
#define gear_change ios_base::sync_with_stdio(false),cin.tie(0)
#define nfl(i,n) for(i=0;i<n;i++)
#define sfl(i,s,e) for(i=s;i<e;i++)
#define ufl(i,n) for(i=n-1;i>=0;i--)
ll power(ll x,ll y){
    ll ret=1;
    while(y>0){
        if(y&1)
            ret=(ret*x);
        y/=2;
        x=(x*x);
    }
    return ret;
}
vector<ll> divs(ll n){
	vector<ll>ret;
	for(int i=1;i*i<=n;i++){
		if(n%i==0){
			if(i*i==n){
				ret.push_back(i);
			}
			else{
				ret.push_back(i);
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}
vector<ll>vec(100);
ll get(ll i,ll n){
	if(i==0){
		if(vec[i]<vec[i+1]){
			return 0;
		}
	}
	if(i==n-1){
		return -1;
	}
	ll j;
	for(j=i;j<n;j++){
		if(vec[j]<=vec[j+1] && vec[j]<=vec[j-1]){
			return j;
		}
	}
	return -1;
}
ll get2(ll i,ll n){
	if(i==n-1){
		if(vec[i]>vec[i-1]){
			return n-1;
		}
	}
	if(i==0){
		return -1;
	}
	ll j;
	for(j=i;j<n;j++){
		if(vec[j]>=vec[j+1] && vec[j]>=vec[j-1]){
			return j;
		}
	}
	return -1;
}
void solve(){
	ll n,i,j,k;
	// in(n);
	ll s,d,t;
	in3(d,t,s);
	auto ans=(s*t>=d)?"Yes":"No";
	cout<<ans<<endl;
}	
int main(){
	gear_change;
	ll test=1;
	// in(test);
	while(test--){
		solve();
	}
}	


Measured memory_bytes: 3580
N = int(input())

CSFs = [list(map(int, input().split(' '))) for i in range(N - 1)]

for i in range(0, N - 1):
    initial_move_time = CSFs[i][0] + CSFs[i][1]
    for j in range(i + 1, N - 1):
        if initial_move_time <= CSFs[j][1]:
            initial_move_time = CSFs[j][1]
        elif initial_move_time % CSFs[j][2] == 0:
            initial_move_time = initial_move_time
        else:
            initial_move_time = initial_move_time + CSFs[j][2] - initial_move_time % CSFs[j][2]
        initial_move_time += CSFs[j][0]
    print(initial_move_time)
print(0)

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    mp[A[i]]++;
  }

  long long sum = 0;
  for (auto a : mp) {
    sum += ((long long)a.second * ((long long)a.second - 1)) / 2;
  }

  for (int i = 0; i < N; i++) {
    long long res = sum;
    res -= (long long)mp[A[i]] * ((long long)mp[A[i]] - 1) / 2;
    res += ((long long)mp[A[i]] - 1) * ((long long)mp[A[i]] - 2) / 2;
    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 8320
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int check(int x,int y,int z,int w){

}

int main(){
	int n;
	while(cin >> n){
		int ans=0;
		int a,b,c,d;
		for(a=0;a<=9;a++){
			for(b=0;b<=9;b++){
				for(c=0;c<=9;c++){
					for(d=0;d<=9;d++){
						if( a+b+c+d == n ){
							ans++;
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
}

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

#define FOR(i,a,n) for(int i = (a); i < (n); ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

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

int h, w;
int c[10][10];
int main() {
  cin >> h >> w;
  REP(i,10) REP(j,10) cin >> c[i][j];
  REP(i,10) REP(j,10) REP(k,10) {
    chmin(c[j][k], c[j][i]+c[i][k]);
  }
  int a, ans = 0;
  REP(i,h) REP(j,w) {
    cin >> a;
    if (a >= 0) ans += c[a][1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    # https://atcoder.jp/contests/abc070/tasks/abc070_d
    # https://atcoder.jp/contests/abc070/submissions/11681543
    from heapq import heapify, heappop, heappush
    
    inf = 10 ** 17
    
    
    def dijkstra_heap(start, edge):
        # 始点から各頂点への最短距離(頂点番号:0~N-1)
        d = [inf] * N
        used = [False] * N
        d[start] = 0
        used[start] = True
        edgelist = []
        # a:重み(//), b:次の頂点(%)
        for a, b in edge[start]:
            heappush(edgelist, a * (10 ** 6) + b)
    
        while len(edgelist):
            # まだ最短距離が決まっていない頂点の中から最小の距離のものを探す
            minedge = heappop(edgelist)
            if used[minedge % (10 ** 6)]:
                continue
            node = minedge % (10 ** 6)
            d[node] = minedge // (10 ** 6)
            used[node] = True
    
            for e in edge[node]:
                if not used[e[1]]:
                    heappush(edgelist, (e[0] + d[node]) * (10 ** 6) + e[1])
        return d
    
    
    # N:頂点数 W:辺数
    N = int(input())
    W = N-1
    
    edge = [[] for i in range(N)]
    # edge[i] : iから出る道の[重み,行先]の配列
    for _ in range(W):
        x, y, z = map(int, input().split())
        edge[x - 1].append((z, y - 1))
        edge[y - 1].append((z, x - 1))
    
    d = dijkstra_heap(0, edge)
    for i in d:
        print(i%2)
    
    
    
resolve()

Measured memory_bytes: 77360
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
#include <algorithm>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
#define nl (next_num<lint>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?(c=getchar()):0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
const int N=100010,O=1000000007;
inline int add(const int &a,const int &b){return (a+b)%O;}
inline int sub(const int &a,const int &b){return add(a,O-b);}
const lint LINF=0x7f7f7f7f7f7f7f7f;
lint a[N];
int f[N],g[N],_f[N],_g[N];
int main(){
	int n=ni;
	lint da=nl,db=nl;
	for(int i=1;i<=n;i++){
		a[i]=nl;
	}
	a[0]=-LINF,a[n+1]=LINF;
	sort(a+1,a+n+1);
	f[0]=g[0]=_f[0]=_g[0]=1;
	int al=1,bl=1,ar=0,br=0;
	for(int i=1;i<=n;i++){
		if(a[i-1]+da>a[i]){
			al=i;
		}
		if(a[i-1]+db>a[i]){
			bl=i;
		}
		for(;ar<i&&a[ar]+db<=a[i+1];ar++);
		for(;br<i&&a[br]+da<=a[i+1];br++);
		f[i]=al<=ar?sub(_g[ar-1],al>=2?_g[al-2]:0):0;
		g[i]=bl<=br?sub(_f[br-1],bl>=2?_f[bl-2]:0):0;
		_f[i]=(_f[i-1]+f[i])%O;
		_g[i]=(_g[i-1]+g[i])%O;
	}
	printf("%d\n",(f[n]+g[n])%O);
	return 0;
}

Measured memory_bytes: 2560
#include <stdlib.h> 
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>

using namespace std; 

int main()
{
	int n,m,tdays = 0;
	
	cin>>n>>m;
	
	int days[m];
	
	for(int i = 0; i < m ; i++)
		cin>>days[i];
		
	for(int i = 0; i < m; i++)
		tdays = tdays + days[i];
	
	if(tdays > n) cout<<"-1";
	if(tdays == n) cout<<"0";
	if(tdays < n) cout<< n - tdays;
	
	return 0;
}


Measured memory_bytes: 3628
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==================================================================
    public void solve() {
    	int A = Integer.parseInt(sc.next());
    	int B = Integer.parseInt(sc.next());
    	int C = Integer.parseInt(sc.next());
    	out.println(A + B + C >= 22 ? "bust" : "win" );
    }
    // ==================================================================
}


Measured memory_bytes: 21204
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
//typedef pair<ll,ll> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

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

    while(true){
        int N;
        cin>>N;
        if(N==0) return 0;
        int count=0;
        for(int i=1;i<=1000;i++){
            int x=i;
            int t=i+1;
            while(x<N){
                x+=t;
                t++;
            }
            if(x==N) count++;
        }
        cout<<count-1<<endl;
    }
}



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

#define FOR(i,N) for(int i=0;i<N;i++)
#define ROF(i,N) for(int i=N-1;i>=0;i--)
#define ROF1(i,a,b) for(int i=(b);i>=(a);i--)
#define FOR1(i,a,b) for(int i=(a);i<=(b);i++)
#define FORi(i,a,b,c) for(int i=(a);i<=(b);i+=(c))

#define read freopen("IN.txt","r",stdin)
#define write freopen("OT.txt","w",stdout)
#define fastread {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mem(a,b)          memset(a,b,sizeof(a))
#define EPS 1e-9
#define PI              acos(-1.0)
#define INF             2e16

#define ll              long long
#define ull             unsigned long long
#define ft              first
#define sd              second
#define bn              begin
#define en              end
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>
#define all(x) x.begin(), x.end()


#define dbg(args...) {cerr<<"-->";debugger::call(#args,args);cerr<<"\n";}
struct debugger {
    static void call(const char* it) {}
    template<typename T, typename ... aT>
    static void call(const char* it, T a, aT... rest) {
        string b;
        for (; *it&&*it != ','; ++it) if (*it != ' ')b += *it;
        cerr << b << "=" << a << " ";
        call(++it, rest...);
    }
};

int main()
{
#ifdef SunWalker
    //read;
   //write;
#endif

int a,b,c;
cin>>a>>b>>c;
if(c-(a-b)<0)cout<<"0\n";
else
cout<<c-(a-b)<<"\n";


return 0;
}



Measured memory_bytes: 256
<?php

fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%s", $t);

$ss = str_split($s);
$tt = str_split($t);
$ans = 0;
foreach($ss as $i => $sv){
    if($sv == $tt[$i]){
        $ans++;
    }
}
echo $ans;

Measured memory_bytes: 4728
N, X = map(int, input().split())

def a(L):
    if L == 0:
        return 1
    return 2 * a(L-1) + 3

def p(L):
    if L == 0:
        return 1
    return 2 * p(L-1) + 1

def solve(L, X):
    if L == 0:
        return 0 if X == 0 else 1
    if X == 1:
        return 0
    if 1 < X <= 1 + a(L-1):
        return solve(L-1, X-1)
    if X == 2 + a(L-1):
        return p(L-1) + 1
    if 2 + a(L-1) < X <= 2 + 2 * a(L-1):
        return p(L-1) + 1 + solve(L-1, X-a(L-1)-2)
    if X == 3 + 2 * a(L-1):
        return 2 * p(L-1) + 1

print(solve(N, X))

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException{
        int n;
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            n = Integer.parseInt(br.readLine());
        }
        String s = IntStream.rangeClosed(1, n)
                .filter(Main::checkAho)
                .mapToObj(String::valueOf)
                .collect(Collectors.joining(" "));
        System.out.printf(" %s%n", s);
    }

    public static Boolean checkAho(int n) {
        return checkAho(n , true);
    }

    public static Boolean checkAho(int n, Boolean isFirst) {
        if(isFirst && n % 3 == 0) {
            return true;
        }else if(n % 10 == 3) {
            return true;
        }else if(n >= 10) {
            return checkAho(n / 10, false);
        }else {
            return false;
        }
    }
}


Measured memory_bytes: 31680
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>

template <typename T>
constexpr T abs(const T& x)
{
    return x > 0 ? x : -x;
}

template <typename T>
constexpr T max(const T& x, const T& y)
{
    return x > y ? x : y;
}

template <typename T>
constexpr T min(const T& x, const T& y)
{
    return x < y ? x : y;
}



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

    int n = 0;
    std::string s = "";

    std::cin >> n >> s;

    if (n >= 3200)
        std::cout << s << std::endl;
    else
        std::cout << "red" << std::endl;

    return 0;
}

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

using namespace std;

#define MOD 1000000007
typedef long long int ll;

long double dp[3001][3001]={0};
long double p[3001]={0};

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cout<<setprecision(20)<<fixed;

	int n;
	cin>>n;

	for(int i=1;i<=n;i++){
		cin>>p[i];
	}

	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		dp[i][0]=dp[i-1][0]*((long double)1-p[i]);
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			dp[i][j]=dp[i-1][j]*((long double)1-p[i])+dp[i-1][j-1]*p[i];
		}
	}
	long double ans=0;
	for(int i=n/2+1;i<=n;i++){
		ans+=dp[n][i];
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 140928
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int N, M;
    bool G[8][8];
    int ans = 0;
    cin >> N >> M;
    vector<int> v;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            G[i][j] = false;
        }
    }
    for(int i = 1; i < N; i++){
        v.push_back(i);
    }
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        G[a-1][b-1] = true;
        G[b-1][a-1] = true;
    }
    if(N != 2){   
        do {
            if(G[0][v[0]]){
                for(int i = 0; i < N-2;i ++){
                    if(!G[v[i]][v[i+1]]) break;
                    if(i == N-3) ans++;
                }
            }
        } while (next_permutation(v.begin(), v.end()));
    }else{
        if(G[0][1])ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N =sc.nextInt();
        int T =sc.nextInt();
        int tc=0;
        int time[] =new int[N];
        int x=1;
        for(int i=0;i<N;i++){
            time[i] =sc.nextInt();
        }
        
        
        
        int count=T;
        
        for(int i=1;i<N;i++){
           if((time[i]-time[i-1])<T){
               count +=(time[i]-time[i-1]);
           }else{
               count+=T;
           }
                
        }
        
        System.out.println(count);
        
    }       
    
        
}


Measured memory_bytes: 60008
from collections import deque

n, qt = map(int, input().split())

queue = deque()

for i in range(n):
    name, time = input().split()
    queue.append([name, int(time)])

total_time = 0

while queue:
    q_t = queue.popleft()
    if q_t[1] <= qt:
        total_time += q_t[1]
        print(q_t[0], total_time)
    else:
        total_time += qt
        q_t[1] -= qt
        queue.append(q_t)

Measured memory_bytes: 16116
import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int n, m;
int[][] adj;
bool ok(int now, int depth)
{
  if (depth == 2) {
    return now == n;
  }
  bool flag = false;
  foreach (next; adj[now]) {
    flag |= ok(next, depth + 1);
  }
  return flag;
}

void main()
{
  auto nm = readln.chomp.split.map!(to!int);
  n = nm.front;
  m = nm.back;
  adj = new int[][](n + 1);
  foreach (i; 0..m) {
    auto ab = readln.chomp.split.map!(to!int);
    int a = ab.front;
    int b = ab.back;
    adj[a] ~= b;
    adj[b] ~= a;
  }
  writeln =  ok(1, 0) ? "POSSIBLE" : "IMPOSSIBLE";
}


Measured memory_bytes: 22524
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<lli, ii> iii;
typedef pair<double, double> dd;

const int N = (int)(3e2 + 5);
const int LOG = (int)(20);
const lli inf = (lli)(1e15);

lli n, sp[N][N], ind, ar[N][N], ans;
iii p[N * N];

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	cin >> n;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++) {
			cin >> sp[i][j];
			if(i < j) {
				p[++ind].se = {i, j};
				p[ind].fi = sp[i][j];
			}
		}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			for(int k = 1; k <= n; k++) {
				if(sp[i][k] + sp[k][j] < sp[i][j]) {
					cout << -1;
					return 0;
				}
			}
		}
	}

	sort(p + 1, p + ind + 1);
	for(int i = 1; i < N; i++) {
		for(int j = 1; j < N; j++) {
			ar[i][j] = inf;
		}
		ar[i][i] = 0;
	}


	for(int i = 1; i <= ind; i++) {
		int a = p[i].se.fi, b = p[i].se.se, c = p[i].fi;
		if(ar[a][b] == sp[a][b])
			continue;
		ar[a][b] = c;
		ar[b][a] = c;
		ans += c;
		for(int j = 1; j <= n; j++) {
			for(int k = 1; k <= n; k++) {
				if(ar[j][a] + ar[b][k] + ar[a][b] < ar[j][k]) {
					ar[j][k] = ar[j][a] + ar[b][k] + ar[a][b];
					ar[k][j] = ar[j][a] + ar[b][k] + ar[a][b];
				}
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 2432
package main
 
import (
  "fmt"
)
 
func main() {
 
  var a,b,c int
  fmt.Scan(&a,&b,&c) 
  
  if b + c <= a {
    c = 0
  } else {
    c = c - (a - b)
  }
  
  fmt.Println(c)
}

Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>
using namespace std;
int main(){
    multiset<int>m;
    int n,mem[20005],x;
    cin>>n;
                         for(int i=1;i<n;i++){
                             cin>>x;
                             m.insert(x);
                             
                         }
    for(int y=1;y<=n;y++){
        cout<<m.count(y)<<"\n";
    }
                         
    
    
    
    
    
    
    
    
}


Measured memory_bytes: 12976
#include<stdio.h>

int main(void){
    int n,d;
    scanf("%d %d",&n,&d);
    if(n%(2*d+1)==0){
        printf("%d",n/(2*d+1));
    }else{
        printf("%d",n/(2*d+1)+1);
    }
    return 0;
}



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

#define ft first
#define sd second
#define sz(x) ((int)x.size())

using namespace std;

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










int main() {
	string s;
	cin >> s;
	cout << ((sz(s) - (count(s.begin(), s.end(), 'p') << 1)) >> 1);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
using namespace std;
 
int main(){
    int k; cin >> k;
    ll ans=0;
    rep(i,k)rep(j,k)rep(p,k) ans+=gcd(gcd(i+1,j+1),p+1);
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int tab[300000];

int main()
{



long long n;
cin>>n;

long long x = 2;
long long z = 1;
long long a = 0;

for(int i = 0; i < n; i++)
{

    a = x + z;
    x = z;
    z = a;

}
cout<<x<<endl;



    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, count = 0;
	cin>>n;
	while(n > 0){
		if(n%10 == 7){
			count = 1;
			break;	
		}
		n = n/10;
	}
	if(count == 1)cout<<"Yes";
	else cout<<"No";	
}


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

int main()
{
  int A,B;
  cin >> A >> B;
  int count = 0;
  int n=B-A+1;
  for(int i=0;i<n;i++){
    string s;
    s = to_string(A);
    if ((s[0]==s[4])&&(s[1]==s[3])){
      count++;
    }
    A++;
  }
    cout << count << endl;
}



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

int main() {
    int adj_matrix[101][101] = {0};
    int n, u, v, k;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            adj_matrix[u - 1][v - 1] = 1;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << adj_matrix[i][j] << (j != n - 1 ? " " : "\n");
        }
    }

    return 0;
}


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

int main(void){
  int n;
  float sum = 0;
  cin >> n;
  vector<float> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    sum += 1/a[i];
  }
  cout << 1/sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#define rep(i,l,r) for(int i=l;i<r;i++)

typedef long long ll;

ll max(ll x, ll y) { return (x > y) ? x : y; }

int dsc(const void* a, const void* b) { return -*(int*)a + *(int*)b; }

int main() {
    ll n, a[100000],b[100000];
    scanf("%lld", &n);
    ll sum = 0;
    rep(i, 0, n) {
        scanf("%lld", &a[i]);
        if (i % 2 == 0) sum += a[i];
        else sum -= a[i];
    }
    b[0] = sum;
    rep(i, 1, n) {
        b[i] = 2*a[i - 1] - b[i - 1];
    }

    rep(i,0,n) printf("%lld ",b[i]);

    return 0;
}


Measured memory_bytes: 3680
#include <iostream>
#include <string>

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	string s;
	while(cin >> s)
	{
		rep(i,s.size())
		{
			if(s[i] == '@')
			{
				int count = s[i+1] - '0';
				rep(j,count)
				{
					cout << s[i+2];
				}
				i += 2;
			}
			else
			{
				cout << s[i];
			}
		}
		cout << endl;
	}
	return 0;
}

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

int N;
bool ada = false;

int main (){
    cin >> N;
    for(int i=1; i<=9; i++) {
        for(int j=1; j<=9; j++) {
            if(i*j ==N) {
                ada = true;
            }
        }
    }
    if(ada) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
//jwb

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String X =scan.next();

		char s;
		int cnt=0;
		int max=0;

		for(int i=0;i<X.length();i++){
			s=X.charAt(i);
			if(s=='S'){cnt--;}
			else{cnt++;}
			if(cnt>max){
				max = cnt;
			}
		}

		System.out.println(max*2);

	}

}


//文字列の左から順に特定の文字列を探す

Measured memory_bytes: 26704
#include<bits/stdc++.h>
#define DIST(x1,x2, y1, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
#define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
#define CLR(a) a.clear()
#define VCLR(a, n) for(int i=0; i<=n+3; i++) a[i].clear()
#define SIZE(a) a.size()
#define ERASE(a, b) memset(a, b, sizeof a)
#define PB(a, b) a.push_back(b)
#define PB2(a,i,b) a[i].push_back(b)
#define LL long long
#define ULL unsigned long long
#define DBG cout<<"I Am Here"<<endl
#define DBGA(a) cout<<a<<endl
#define DBGI(b,a) cout<<b<<' '<<a<<endl
#define DBGL(i,s,e,b) or(int i=s; i<=e; i++) cout<<b<<endl
#define INF 1e9
#define INV 1e-6
#define sll(a) scanf("%I64d", &a)
#define pll(a) printf("%I64d\n", a)
#define si(a) scanf("%d", &a)
#define pii pair<LL,LL>
#define MAX 100006
#define CASE(i) printf("Case %d: ", i);
#define CSH(i) printf("Case #%d: ", i);
#define PI acos(-1)
#define piis pair<int, string>
#define fast1 ios_base::sync_with_stdio(false);
#define fast2 cin.tie(0)
#define CHECK_BIT(var,pos) ((var & (1 << pos)) == (1 << pos))


LL MOD = 1000000007;

using namespace std;

LL bigmod(LL b, LL p, LL m)
{
    if(p==0)  return 1;
    if(p%2==0)
    {
        LL x = bigmod(b,p/2,m);
        return (x%m * x%m)%m;
    }
    else return ((b%m)*bigmod(b,p-1,m)%m)%m;
}


LL MODINVERSE(LL a)
{
    return bigmod(a, MOD-2, MOD);
}

LL arr[104];

int main()
{
    int n;
    scanf("%d", &n);
    int cnt = 0;
    for(int i=1; i<=n; i++){
        scanf("%lld", &arr[i]);
        if(i>1){
            if(arr[i]!=arr[i-1]) cnt++;
        }
    }
    if(cnt==0){
        printf("0");
        return 0;
    }

    LL cost = 1<<30;

    for(int i=-150; i<=150; i++)
    {
        LL sum = 0;
        for(int j=1; j<=n; j++)
        {
            sum = sum + ((arr[j] - i) * (arr[j] - i));
        }
        cost = min(cost, sum);
    }

    printf("%lld", cost);
}


Measured memory_bytes: 256
def main():
    S = input()
    n = len(S) - 1
    ans = 0

    for i in range(2 ** n):
        c = S[0]
        for j in range(n):
            if (i >> j) & 1 == 1:
                c += "+"
            c += S[j + 1]
        t = list(map(int, c.split("+")))
        ans += sum(t)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 8924
n, m = map(int, input().split())
a = [0 for i in range(m)]
for i in range(n):
    tmp = list(map(int, input().split()))
    for j in range(tmp[0]):
        a[tmp[j+1]-1] += 1
count = 0
for i in range(m):
    if a[i] == n:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n, q;
    cin >> n >> q;
    vector<int> res(n, 0), tmp;
    vector<bool> check(n, true);
    vector<vector<int>> bra(n, tmp);
    rep(i, n-1){
        int a, b;
        cin >> a >> b;
        bra[a-1].push_back(b-1);
        bra[b-1].push_back(a-1);
    }
    rep(i, q){
        int p, x;
        cin >> p >> x;
        res[p-1] += x;
    }
    queue<int> que;
    que.push(0);
    while(!que.empty()){
        int now = que.front();
        check[now] = false;
        que.pop();
        int len = bra[now].size();
        rep(i, len){
            if(check[bra[now][i]]){
                res[bra[now][i]] += res[now];
                que.push(bra[now][i]);
            }
        }
    }

    rep(i, n){
        cout << res[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 16472
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)

int main(){
  ll N;
  cin >> N;
  ll H[100005];
  rep(i,N) cin >> H[i];
  
  ll ans=0;
  ll ren=0;
  rep(i,N-1){
    if(H[i]>=H[i+1]) ren++;
    else{
      ans = max(ans,ren);
      ren=0;
    }
  }
  ans = max(ans,ren);
  
  cout << ans << endl;

}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
  int P, Q, R;
  cin >> P >> Q >> R;
  
  int sum = 0;
  int larger;
  
  if (P > Q) {
    larger = P;
    sum = Q;
  } else {
    larger = Q;
    sum = P;
  }
  if (R > larger) {
    sum += larger;
  } else {
    sum += R;
  }
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
    char str[2005];
    scanf("%s",str);
    int sign=0,sign2=0,cnt1=0,cnt2=0;
    for(int i=0;i<strlen(str);i++)
    {
        if((i+1)%2)
        {
            cnt1++;
            if(str[i]=='R'||str[i]=='U'||str[i]=='D')
            {
                sign++;
            }
        }
        else
        {
            cnt2++;
            if(str[i]=='L'||str[i]=='U'||str[i]=='D')
            {
                sign2++;
            }
        }
    }
    if(sign==cnt1&&sign2==cnt2)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
	int n;
	while(1){
		cin >> n;
		if(n==0)break;
		cout << (1000-n)/500+(1000-n)%500/100+(1000-n)%500%100/50+(1000-n)%500%100%50/10+(1000-n)%500%100%50%10/5+(1000-n)%500%100%50%10%5 <<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#define endl "\n"
#define whats(x) cout<<#x<<" is: "<<x<<endl;
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int happy[n][3];
    for(int i=0; i<n; ++i)
        cin>>happy[i][0]>>happy[i][1]>>happy[i][2];
    int arr[n][3];
    arr[0][0]=happy[0][0];
    arr[0][1]=happy[0][1];
    arr[0][2]=happy[0][2];
    for(int i=1; i<n; ++i){
        arr[i][0]=happy[i][0]+max(arr[i-1][1], arr[i-1][2]);
        arr[i][1]=happy[i][1]+max(arr[i-1][0], arr[i-1][2]);
        arr[i][2]=happy[i][2]+max(arr[i-1][0], arr[i-1][1]);
    }
    cout<<max(max(arr[n-1][0], arr[n-1][1]), arr[n-1][2])<<endl;
    return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long ans = 0;

    for(int i=1;i<=b;i++) {
    	if((a*i)%b==0) {
    		ans=a*i;
    		break;
    	}
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23380
#include<cstdio>
using namespace std;

const int N = 400;
const int M = 1e5;
bool f[N+2][N+2];
int a[M+2],b[M+2];
int n,m;

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1; i<=m; i++) scanf("%d%d",&a[i],&b[i]);
    for(int i=1; i<=n; i++)
    {
        f[i][i] = true;
        for(int j=m; j>=1; j--)
        {
            bool x = f[i][a[j]],y = f[i][b[j]];
            if(x && y) {f[i][0] = true; break;}
            if((!x) && y) {f[i][a[j]] = true;}
            else if(x && (!y)) {f[i][b[j]] = true;}
        }
    }
    int ans = 0;
    for(int i=1; i<=n; i++)
    {
        for(int j=i+1; j<=n; j++)
        {
            if(f[i][0] || f[j][0]) continue;
            bool ok = true;
            for(int k=1; k<=n; k++)
            {
				if(f[i][k] && f[j][k]) ok = false;
			}
			ans += (ok);
		}
	}
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1152
L,R=gets.chomp.split(' ').map{|n| n.to_i}
a = (L/2019+1)*2019
a1 = (L/2019+1)*2019+1
a2 = (L/2019+1)*2019+2
min = 2019
if(L%2019==0 || L<=a && a<=R)
	puts 0
	exit(0)
else
	# enough small
	for i in L..(R)
		for j in (i+1)..(R)
			min = [min,(i*j)%2019].min
		end
	end
end
puts min


Measured memory_bytes: 1788