akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <bitset>
#include <cmath>
#include <queue>

#define ll long long
#define repp(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define repm(i,a,b) for(int i=(int)(a);i>(int)(b);--i)

using namespace std;


int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> jobs(100100);
    repp(i,0,N) {
        int a, b; cin >> a >> b;
        jobs[a].push_back(b);
    }
    priority_queue<int> q;
    ll ans = 0;
    repp(i,1,M+1) {
        for(auto x: jobs[i]) q.push(x);
        if(!q.empty()) ans += q.top(), q.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

typedef long long ll;

const int MAX_N=1e5;

int N,A[MAX_N];

int main(){
	cin>>N;
	bool flg=true;
	REP(i,N){
		cin>>A[i];
		if (A[i]%2==1){
			flg=!flg;
		}
	}
	if (flg){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


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

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

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,a,b;
	cin >> n >>a >>b;
	vector<bool> ck(n);
	ck[a-1] = ck[b-1] =1;
	if((a == 1 && b==2) || (a==n && b==n-1)) puts("Borys");
	else if((b-a)%2) puts("Borys");
	else puts("Alice");
	return 0;
}

Measured memory_bytes: 256
H,W = map(int, input().split())
row = []
erase = []
for i in range(H):
    r = list(input())
    count = 0
    for j in range(W):
        if r[j] == '.':
            count += 1
    if count != W:
        row.append(r)        

for k in range(W): 
    count2 = 0
    for l in range(len(row)): 
        if row[l][k] == '.':
            count2 += 1
    if count2 == len(row):
        erase.append(k)

answer = []
if len(erase) > 0:
    for m in range(len(row)):
        ans = ''
        for n in range(len(row[m])):
            if n not in erase:
                ans += row[m][n]
        answer.append(ans)
    
else:
    for p in range(len(row)):
        ans = ''
        for q in range(len(row[p])):
            ans += row[p][q]
        answer.append(ans)
    

for o in answer:
    print(o)


Measured memory_bytes: 3188
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

string s;
string tt;
int ans;
int ff,fff;

int main(){
  cin >> s;
  while(s!="."){
    ans=0;
    ff=0;
    fff=0;
    int i=0;
    int j=0;
    cin >> tt;
    for(;i<int(s.size())&&j<int(tt.size());){
      if(s[i]==tt[j]&&s[i]!=0x22&&tt[j]!=0x22){
        ++i;
        ++j;
      }
      else{
        if(s[i]!=tt[j]){
          ans=1;
          break;
        }
        if(s[i]==0x22&&tt[j]==0x22){
          ++i;
          ++j;
          for(;s[i]!=0x22&&tt[j]!=0x22;){
            if(s[i]!=tt[j]){
              ++ff;
              fff=1;
              break;
            }
            ++i;
            ++j;
          }
          if(fff==0&&s[i]!=tt[j]){
            ++ff;
          }
          fff=0;
          while(s[i]!=0x22){
            ++i;
          }
          while(tt[j]!=0x22){
            ++j;
          }
          ++i;
          ++j;
        }
      if(ans==1)break;
      }
    }
    if(i==int(s.size())&&j==int(tt.size())){}
    else{
      ans=1;
    }
    if(ans==1||ff>=2){
      printf("DIFFERENT\n");
    }
    else if(ff==0){
      printf("IDENTICAL\n");
    }
    else{
      printf("CLOSE\n");
    }
    cin >> s;
  }
}



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

int main(){
  long n,sum;
  cin >> n;
  vector<long> a(n);
  for(int i=0;i<n;i++)cin >> a[i];
  
  for(int i=0;i<n;i++){
  	for(int j=i+1;j<n;j++){
      sum+=a[i]*a[j];
    }
  }
  cout << sum;
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N=int(input())

A=list(map(int,input().split()))

two=[2**i for i in range(61)]
two=two[::-1]
log=[0]*61

for i in range(len(A)):
    for j in range(len(two)):
        if A[i]-two[j]>=0:
            A[i]-=two[j]
            log[j]+=1

ans=0
for i in range(len(two)):
    ans+=(N-log[i])*log[i]*two[i]

print(ans%(10**9+7))


Measured memory_bytes: 122808
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <map>
#include <stack>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
const int MaxN = 1e5 + 4;
typedef long long LL;
typedef pair<int,int> PLL;
string s;
int vis[MaxN];
int main(){
	int k;
	cin>>s;
	cin>>k;
	int l = s.size();
	for(int i = 0; i < l; i++){
		vis[i] = 'z'-s[i]+1;
	}
	for(int i = 0; i < l; i++){
		if(k == 0) break;
		if(s[i] == 'a') continue;
		if(k-vis[i]>=0){ 
			k -= vis[i];
			s[i] = 'a';
		}
	}
	if(s[l-1]+k > 'z')	s[l-1] = 'a'+(k-('z'-s[l-1]+1))%26;
	else s[l-1] = s[l-1] + k;
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


int main() {
  int  a;
  cin >> a;
  
  cout << a/3 << endl;

  
}



Measured memory_bytes: 256
using System;

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

            int Taro = 0;
            int Hanako = 0;

            for(int i = 0; i < n; i++)
            {
                string[] card = Console.ReadLine().Split(' ');
                if(card[0] == card[1])
                {
                    Taro += 1;
                    Hanako += 1;
                }
                else
                {
                    if (Game(card[0], card[1]) == 1)
                        Taro += 3;
                    else
                        Hanako += 3;
                }
            }
            Console.WriteLine("{0} {1}", Taro, Hanako);
        }

        static int Game(string T_Card, string H_Card)
        {
            if (T_Card == H_Card)
                return 0;
            else
            {
                for(int i = 0; i < Min(T_Card.Length,H_Card.Length); ++i)
                {
                    if ((T_Card[i] - H_Card[i]) > 0)
                        return 1;
                    else if ((T_Card[i] - H_Card[i]) < 0)
                        return -1;
                }
                if (T_Card.Length > H_Card.Length)
                    return 1;
                else
                    return -1;
            }
        }

        static int Min(int a, int b)
        {
            if (a < b)
                return a;
            else
                return b;
        }
    }
}

Measured memory_bytes: 5700
/*    ####################  */
/*   # I_LOVE_THUY_LINH #  */
/*  ####################  */
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define ii pair<int,int>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<ii>
#define matrix vector<vector<ll>>
#define fir first
#define sec second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define sz(a) int((a).size())
#define ms(s,val) memset(s,val,sizeof(s))
#define bitcount(n) __builtin_popcountll(n)
#define getbit(s,k) ((s >> k)&1)
#define turnbit(s,k) (s | (1<<k))
#define offbit(s,k) (s & ~(1<<k))
#define flipbit(s,k) (s ^ (1<<k))
#define prec(n) fixed<<setprecision(n)
#define sqr(x) (ll)(x)*(ll)(x)
#define lcm(a,b) ((ll)a/__gcd((ll)a,(ll)b)*(ll)(b))
#define gcd(a,b) __gcd(a,b)
using namespace std;
const int INF = int(1e9);
int A, B;


int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> A >> B;
    int maxB = 100*B;
    int ans = -1;
    for (int i = 1; i <= maxB; i++)
        if ((i*8)/100 == A && (i*10)/100 == B){
            ans = i;
            break;

    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

class Program
{

	static void Main(string[] args)
	{
		int a = int.Parse(Console.ReadLine());

		if(a >= 1800)
        {
			Console.WriteLine("1");
		}
		else if(a >= 1600)
        {
			Console.WriteLine("2");
		}
		else if(a >= 1400)
        {
			Console.WriteLine("3");
		}
		else if(a >= 1200)
        {
			Console.WriteLine("4");
		}
		else if(a >= 1000)
        {
			Console.WriteLine("5");
		}
		else if(a >= 800)
        {
			Console.WriteLine("6");
		}
		else if(a >= 600)
        {
			Console.WriteLine("7");
		}
		else if(a >= 400)
        {
			Console.WriteLine("8");
		}
		
	}
}

Measured memory_bytes: 27508
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        int x;
        int y;
        int tmp;
        Scanner sc = new Scanner(System.in);
        for(int i = 0;i < 3000;i++){
            x = sc.nextInt();
            y = sc.nextInt();
            if(x >= 0 && x <= 10000 && y >= 0 && y <= 10000){
                if(x == 0 && y == 0){
                   break;
                }else if(x > y){
                    tmp = x;
                    x = y;
                    y = tmp;
                }
                System.out.println(x + " " + y);
            }else{
                System.out.println("入力された数値が正しくありません。");
                continue;
            }
        }
    }
}


Measured memory_bytes: 35440
n = int(input())

class student:
    def __init__(self, number, name):
        self.number = number
        self.name = name

a = list(map(int, input().split()))
order = []
for i in range(n):
    order.append(student(a[i],i+1))

reorder = sorted(order, key=lambda u: u.number)

for i in range(n):
    if i == n-1:
        print(reorder[i].name)
    else:
        print(reorder[i].name, end=" ")


Measured memory_bytes: 30208
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for(ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for(ll i = (ll)(n - 1); i >= 0; i--)
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; }

const ll MAX = 200005;
const ll MOD = 998244353;

ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return (((fac[n] * finv[k]) % MOD) * finv[n - k]) % MOD;
}

// a^n mod を計算する
ll modpow(long long a, long long n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}

int main()
{
	cout << fixed << setprecision(18);

	ll n, m, k;
	ll ans = 0;

	cin >> n >> m >> k;

	COMinit();
	rep(i, k + 1) {
		ll tmp = (((m * COM(n - 1, i)) % MOD) * modpow(m - 1, n - 1 - i)) % MOD;
		ans += tmp;
		ans %= MOD;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8320
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    double L;
    cin>>L;

    cout<<fixed<<setprecision(10)<<(L*L*L)/27;
    return 0;
}

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

int main()
{
    int n,l;
    cin >> n >> l;
    int sum = n*(n-1)/2 +l*n;
    if(1-l <= 0) sum -= l;
    else if(1-l > n) sum -= l+n-1;
    cout << sum << endl;
    return 0;
}

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

using namespace std;

int main()
{
    long long n,k;
    long long i,j;
    long long ans;
    while (scanf("%lld%lld",&n,&k)!=EOF)
    {
        ans=0;
        for (i=1;i<=n-k;i++)
        {
            j=i+k;
            ans+=(n/j)*i;
            if(n%j-k>=0)
                ans+=n%j-k+1;
        }
        if (k==0)
            ans=n*n;
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<cstdlib> 
#include<string>
#include<math.h>
#include<bitset>
#include<algorithm>
#include<vector>
#include<set>
#include<stack>
#include<queue>
using namespace std;

int main(){

	int N,a[100000],ans=0;

	cin >> N;
	for(int i=0;i<N;i++)cin >> a[i];

	for(int i=0;i<N;i++){
		if(a[a[i]-1]-1==i)ans++;
	}
	ans/=2;
	cout << ans << endl;

	//while(1);

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    ll t1,t2,a1,a2,b1,b2;
    cin >> t1 >> t2;
    cin >> a1 >> a2;
    cin >> b1 >> b2;
    a1 *= t1;
    a2 *= t2;
    b1 *= t1;
    b2 *= t2;
    if(a1 + a2 == b1 + b2){
        cout << "infinity" << endl;
        return 0;
    }
    if(a1 + a2 < b1 + b2){
        swap(a1, b1);
        swap(a2, b2);
    }
    if(a1 > b1){
        cout << 0 << endl;
        return 0;
    }
    ll c = b1 - a1, d = (a1 + a2) - (b1 + b2);
    if(c % d == 0) cout << 2 * ((c + d - 1) / d) << endl;
    else cout << 2 * ((c + d - 1) / d) - 1 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	int n=Integer.parseInt(input.readLine());
	
	String str1=input.readLine();
	int m=Integer.parseInt(input.readLine());
	String str2=input.readLine();
	if(n>m)
	    {
		int tmp=n;
		n=m;
		m=tmp;
		String temp=str1;
		str1=str2;
		str2=temp;
	    }
	int b[]=new int[m];
	int a[]=new int[n];
	
	String str_ary1[]=str1.split(" ");
	for(int i=0;i<n;i++)
	    {
		a[i]=Integer.parseInt(str_ary1[i]);
	    }
	
	
	
	String str_ary2[]=str2.split(" ");
	for(int i=0;i<m;i++)
	    {
		b[i]=Integer.parseInt(str_ary2[i]);
	    }
	int x=0;
	for(int i=0;i<n;i++)
	    {
		for(int j=0;j<m;j++)
		    {
			if(a[i]==b[j])
			    {
				x++;
				break;
			    }
		    }
	    }
	System.out.println(x);
    }
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 h,w;
    cin >> h >> w;
    REP(i,h)REP(j,w){
        string s;
        cin >> s;
        if(s == "snuke"){
            cout << (char)('A' + j) << (i + 1) << endl;
        }
    }
    return 0;
}

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

using namespace std;

int main(void){
	int n;
	while(scanf("%d", &n) && n){
		
		int num[5001]={0};
		int total[5001]={0};
		int ans = -2000000000;
		
		for(int i = 0; i < n; i++){
			scanf("%d", &num[i]);
		}
		
		for(int i = 0; i < n; i++){
			for(int j = i; j < n; j++){
				total[i] += num[j];
				ans = max(ans,total[i]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()ss		
#define debug system("pause")				//デバッグ用

int saiki(string, int, int);

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

	int a,b;
    cin>>a>>b;
    cout<<(a+b+1)/2<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

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

Measured memory_bytes: 596
#include <cstdio>

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

using namespace std;

int main(){
	for(int n;scanf("%d",&n),n;){
		char s[500][11];
		rep(i,n) scanf("%s",s[i]);

		bool ok=true;
		bool adj[26][26]={};
		rep(i,n-1){
			for(int j=0;;j++){
				if(s[i][j]=='\0') break;
				if(s[i+1][j]=='\0'){ ok=false; break; }
				if(s[i][j]!=s[i+1][j]){
					adj[s[i][j]-'a'][s[i+1][j]-'a']=true;
					break;
				}
			}
		}
		rep(k,26) rep(i,26) rep(j,26) adj[i][j]|=adj[i][k]&&adj[k][j];

		rep(i,26) if(adj[i][i]) ok=false;
		puts(ok?"yes":"no");
	}

	return 0;
}

Measured memory_bytes: 1020
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__


void solve(void){
  
  int N, D;
  cin >> N >> D;
  
  int ans=0;
  
  while(N>0){
    ans++;
    N -= 2*D+1;
  }
  
  cout << ans << endl;
  
  return;
   
}

#define TESTCASES 1

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

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

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
a, b = 1, N
S = set()
for _ in range(M):
    print(a, b)
    S.add(b - a)
    S.add(a + N - b)
    a += 1
    b -= 1
    if b - a in S or a + N - b in S or b - a << 1 == N:
        b -= 1

Measured memory_bytes: 90952
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 20

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

uint64_t get_int(void) {
  uint64_t num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%llu", &num);
#else
#error
#endif
  return num;
}

int main(void) {
    uint64_t num = get_int();
    uint64_t cnt = 1;
    uint64_t ans = 0;
    while(num > 1) {
        num /= 2;
#ifdef DEBUG
        printf("cnt: %llu -> %llu\n", cnt, num);
#endif
        ans += cnt;
        cnt = cnt * 2;
    }
    ans += cnt;
    printf("%llu\n", ans);

    return 0;
}

Measured memory_bytes: 128
S=input()
A=[1,0,0,0,0,0,0,0,0,0,0,0,0]
a=10**9+7
for i in range(len(S)):
  B=A[:]
  if S[i]=="?":
    A[0]=(B[0]+B[9]+B[5]+B[1]+B[10]+B[6]+B[2]+B[11]+B[7]+B[3])%a
    A[1]=(B[4]+B[0]+B[9]+B[5]+B[1]+B[10]+B[6]+B[2]+B[11]+B[7])%a
    A[2]=(B[8]+B[4]+B[0]+B[9]+B[5]+B[1]+B[10]+B[6]+B[2]+B[11])%a
    A[3]=(B[12]+B[8]+B[4]+B[0]+B[9]+B[5]+B[1]+B[10]+B[6]+B[2])%a
    A[4]=(B[3]+B[12]+B[8]+B[4]+B[0]+B[9]+B[5]+B[1]+B[10]+B[6])%a
    A[5]=(B[7]+B[3]+B[12]+B[8]+B[4]+B[0]+B[9]+B[5]+B[1]+B[10])%a
    A[6]=(B[11]+B[7]+B[3]+B[12]+B[8]+B[4]+B[0]+B[9]+B[5]+B[1])%a
    A[7]=(B[2]+B[11]+B[7]+B[3]+B[12]+B[8]+B[4]+B[0]+B[9]+B[5])%a
    A[8]=(B[6]+B[2]+B[11]+B[7]+B[3]+B[12]+B[8]+B[4]+B[0]+B[9])%a
    A[9]=(B[10]+B[6]+B[2]+B[11]+B[7]+B[3]+B[12]+B[8]+B[4]+B[0])%a
    A[10]=(B[1]+B[10]+B[6]+B[2]+B[11]+B[7]+B[3]+B[12]+B[8]+B[4])%a
    A[11]=(B[5]+B[1]+B[10]+B[6]+B[2]+B[11]+B[7]+B[3]+B[12]+B[8])%a
    A[12]=(B[9]+B[5]+B[1]+B[10]+B[6]+B[2]+B[11]+B[7]+B[3]+B[12])%a
  else:
    s=int(S[i])
    for i in range(13):
      A[i]=B[(i*4+9*s)%13]
print(A[5])
    
        
   


Measured memory_bytes: 3552
#include <iostream>
#include <algorithm>

int N, M;
long memo[100001];

long step(int position) {
    if (memo[position] >= 0) {
        return memo[position];
    }
    memo[position] = (step(position + 1) + step(position + 2)) % 1000000007;
    return memo[position];
}

int main() {
    std::cin >> N >> M;
    for (int i = 0; i < N; i += 1) {
        memo[i] = -1;
    }
    for (int i = 0; i < M; i += 1) {
        int ai;
        std::cin >> ai;
        memo[ai] = 0;
    }
    memo[N] = 1;
    memo[N + 1] = 0;

    std::cout << step(0) << std::endl;

    return 0;
}


Measured memory_bytes: 4096
object Main extends App {
  var nm = scala.io.StdIn.readLine()
  val nmArray =  nm.split(" ").map(_.toInt)
  val n = nmArray(0)
  val m = nmArray(1)
  var seqKa = Seq.empty[Int]
  for(i<-1 to n) {
    val ka = scala.io.StdIn.readLine()
    val kaArray = ka.split(" ").map(_.toInt)
    if(i == 1){
      seqKa = kaArray.tail
    } else {
      seqKa = seqKa.filter(s => kaArray.tail.find(_ == s).isDefined)
    }
  }
  println(seqKa.length)
}

Measured memory_bytes: 27796
#include<cstdio>
#include<algorithm>
int main(){
	int n;
	scanf("%d",&n);
	long long int a[n]={};
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	std::sort(a,a+n);
	long long int p=0;
	long long int q=0;
	int u=0;
	for(int i=n-2;i>=0;i--){
		if(a[i]==a[i+1]&&u==1){
			q=a[i];
			break;
		}
		if(a[i]==a[i+1]&&u==0){
			p=a[i];
			a[i]=0;
			a[i+1]=0;
			u++;
		}
	}
	printf("%lld\n",p*q);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型
using Real = mp::number<mp::cpp_dec_float<1024>>;
Bint INF = 1000000000000000000;
int main() {
    int N;
    cin >> N;
    vector<Bint>A(N);
    Bint ans = 1;
    for(int i = 0; i < N; i++) {
        cin >> A[i]; 
        if(A[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i = 0; i < N; i++) {
        ans *= A[i];
        if(ans > INF) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6488
def prime? n
  return true if n == 2
  return false if n.even?
  3.step(n**0.5, 2) do |d|
    return false if n % d == 0
  end
  true
end

ans = 0
gets.to_i.times do
  ans += 1 if prime?(gets.to_i)
end
puts ans


Measured memory_bytes: 6940
N, K = map(int,input().split())
numbers = [list(map(int,input().split())) for _ in range(N)]
#print(numbers)
numbers.sort(key = lambda x:x[0])
#print(numbers)
cnt = 0
for idx,num in enumerate(numbers):
    cnt += num[1]
    if cnt >= K:
        print(numbers[idx][0])
        exit()



Measured memory_bytes: 65752
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cstring>
#include<list>
using namespace std;
typedef vector<int>VI;
typedef vector<VI>VVI;
typedef vector<string>VS;
typedef pair<int,int>PII;
typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define PB push_back
#define EACH(i,c) for(typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int N;
vector<int>V[30];

int solve(){
    vector<set<int> >S(N);
    REP(i,N)S[i].insert(i);
    REP(i,30){
        set<int>T;
        REP(j,V[i].size()){
            int p=V[i][j];
            EACH(it,S[p])T.insert(*it);
        }
        REP(j,V[i].size())S[V[i][j]]=T;

        if(T.size()==N)return i+1;
    }
    return -1;
}


int main(){
    while(cin>>N,N){
        REP(i,30)V[i].clear();
        REP(i,N){
            int m;cin>>m;
            REP(j,m){
                int t;cin>>t;
                V[t-1].PB(i);
            }
        }
        if(N==1)cout<<0<<endl;
        else cout<<solve()<<endl;
    }

    return 0;
}

Measured memory_bytes: 1344
# include<bits/stdc++.h>
using namespace std ;
int main () {
    int N , M ; cin >> N >> M ;
    vector <int > cnt (M , 0);
    for ( int i = 0; i < N ; ++ i ) {
        int K; cin >> K ;
        for ( int j = 0; j < K ; ++ j ) {
            int A; cin >> A ; --A ;
            ++ cnt [ A ];
        }
    }
    int ans = 0;
    for ( int i = 0; i < M ; ++ i ) {
        if ( cnt [ i ] == N ) {
            ++ ans ;
        }
    }
    cout << ans << endl ;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

const int N = 520;
const int mod = 100000;
int dp[N][N][2][2];
int dx[]={1,0};
int dy[]={0,1};

int solve(int r,int c){
  rep(i,N)rep(j,N)rep(k,2)rep(l,2)dp[i][j][k][l]=0;
  //dp[0][0][0][0]=1;
  dp[0][1][0][0]=1;
  dp[1][0][1][0]=1;
    

  rep(i,r){
    rep(j,c){
      rep(dir,2){
	rep(isact,2){
	  if (isact == 0){
	    if (dir == 0){
	      dp[i][j+1][0][0]+=dp[i][j][dir][isact];
	      dp[i][j+1][0][0]%=mod;
	      dp[i+1][j][1][1]+=dp[i][j][dir][isact];
	      dp[i+1][j][1][1]%=mod;
	    }else {
	      dp[i][j+1][0][1]+=dp[i][j][dir][isact];
	      dp[i][j+1][0][1]%=mod;
	      dp[i+1][j][1][0]+=dp[i][j][dir][isact];
	      dp[i+1][j][1][0]%=mod;
	    }
	  }else {
	    dp[i+dy[dir]][j+dx[dir]][dir][0]+=dp[i][j][dir][isact];
	    dp[i+dy[dir]][j+dx[dir]][dir][0]%=mod;
	  }
	}
      }
    }
  }
  /*
  rep(k,2){
    rep(l,2){
      cout << k <<" " << l <<" graph" << endl;
      rep(i,r){
	rep(j,c){
	  int sum = dp[i][j][k][l];
	  cout << sum << " ";
	}
	cout << endl;
      }
      cout << endl;
    }
  }
  */
  return (dp[r-1][c-1][0][0]+dp[r-1][c-1][0][1]+dp[r-1][c-1][1][0]+dp[r-1][c-1][1][1])%mod;
}


main(){
  int r,c;
  while(cin>>r>>c &&r){
    cout << solve(r,c)<< endl;
  }
}

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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

signed main() {
	int n, a[114];
	cin >> n;
	int sum = 0;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
		a[i] *= n;
	}
	int mi = 1145141919, ans = 0;
	rep(i, n) {
		if (mi > abs(sum - a[i])) {
			mi = abs(sum - a[i]);
			ans = i;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
#include <math.h>

int main() {
  int a, b, c, dig = 1, d;
  scanf("%d%d", &a, &b);
  c = b;
  while (c != 0) {
    dig *= 10;
    c /= 10;
  }
  a = a*dig + b;
  d = (int)sqrt((double)a);
  if (a == d * d) printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int n,sum=0;
    cin>>n;
   int a[n],b[n],c[n-1];
   for(int i=0;i<n;i++)cin>>a[i];
   for(int i=0;i<n;i++)cin>>b[i];
   for(int i=0;i<n-1;i++)cin>>c[i];
   for(int i=0;i<n;i++){
       sum+=b[a[i]-1];
       if(i>0 && a[i]==a[i-1]+1)sum+=c[a[i-1]-1];
   }
   cout<<sum;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,cost=0,avg=0;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    avg=round(accumulate(arr,arr+n,0)/(float)n);  
    for(int i=0;i<n;i++)
        cost+=pow(arr[i]-avg,2);
    cout<<cost;
}


Measured memory_bytes: 384
n = int(input())
a = [int(x) for x in input().split()]
d_cnt = dict()
d_comb = dict()
for x in a:
    cnt = d_cnt.get(x, -1) + 1
    d_cnt[x] = cnt
    if cnt >= 1:
        d_comb[x] = d_comb.get(x, 0) + cnt
base = sum(d_comb.values())
for x in a:
    print(base - d_cnt.get(x))

Measured memory_bytes: 25768
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 1; i+i < (int)s.size(); ++i)
		if (s.substr(0, i) == s.substr(i, i))
			ans = i+i;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp std::make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
const ll MOD=1e9+7;
//const ll MOD=998244353;
//const ll MOD=100000;
const ll MAX=1e7;
const ll INF=(1ll<<60);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,int a){
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
};
struct Union_Find{
    ll N;
    vi par;
    vi siz;
    ll sum=0;
    Union_Find(int n):N(n){
        par.resize(N);
        siz.resize(N,1);
        rep(i,0,N) par[i]=i;
    }
    ll root(ll X){
        if(par[X]==X) return X;
        return par[X]=root(par[X]);
    }
    bool same(ll X,ll Y){
        return root(X)==root(Y);
    }
    void unite(ll X,ll Y){
        X=root(X);
        Y=root(Y);
        if(X==Y) return;
        sum-=siz[X]*(siz[X]-1)/2;
        sum-=siz[Y]*(siz[Y]-1)/2;
        par[X]=Y;
        siz[Y]+=siz[X];
        siz[X]=0;
        sum+=siz[Y]*(siz[Y]-1)/2;
    }
};
ll modpow(ll X,ll Y){
    ll sum=X,cnt=1;
    vi A;
    while(cnt<=Y){
        A.pb(sum);
        sum*=sum;
        sum%=MOD;
        cnt*=2;
    }
    int M=A.size();
    ll ret=1;
    REP(i,1,M){
        if(Y>=(1ll<<M-i)){
            Y-=(1ll<<M-i);
            ret*=A[M-i];
            ret%=MOD;
        }
    }
    return ret;
}
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n,ll r){
    if(n<r||n<0||r<0) return 0;
    return fac[n]*finv[r]%MOD*finv[n-r]%MOD;
}
signed main(){
    ll N,Q; cin>>N>>Q;
    vi A(Q),B(Q);
    rep(i,0,Q) cin>>A[i]>>B[i];
    reverse(ALL(A));
    reverse(ALL(B));
    vi ans;
    Union_Find tree(N);
    rep(i,0,Q){
        ans.pb(tree.sum);
        tree.unite(A[i]-1,B[i]-1);
    }
    reverse(ALL(ans));
    rep(i,0,Q) cout<<N*(N-1)/2-ans[i]<<endl;
}


Measured memory_bytes: 5364
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================

string S,T;

void input()
{
    cin>>S;
    cin>>T;
}
//=========FUNCTIONS==========

void solve()
{
    int N = S.size();

    
    bool match = false;
    bool matched = false;
    for (int i = 0; i < N; ++i){
        if (matched)break;
        match = true;
        for (int j = 0; j < N; ++j){
            int ind = i+j;
            ind %= N;

            if (S[j] != T[ind]){
                match = false;
                break;
            }
        }
        if (match){
            matched =true;
            break;
        }
    }

    cout<< (matched ? "Yes" : "No") << endl;

}

//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    w,h,x,y = LI()
    t = w * h / 2
    k = 0
    if w / 2 == x and h / 2 == y:
        k = 1

    return "{} {}".format(t,k)


print(main())



Measured memory_bytes: 5708
/******* all required header files *******/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;

/*****All definitions*******/
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define mp make_pair
#define ll long long int
#define pb push_back
#define F first
#define S second
/***************************/

int main()
{
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

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

	ll a, b;
	cin>>a>>b;
	cout<<a*b;
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,m,k,sum=0,a=0,b=0;
  long long mod = 1000000007;
  cin >> k;
  for(long i=1;i<=k;i++){
    for(long j=1;j<=k;j++){
      for(long l=1;l<=k;l++){
        sum += gcd(gcd(i,j),l);
      }
    }
  }
  cout << sum << endl;
}

long gcd (long p ,long q){
  if(p % q == 0) return q;
  return gcd(q, p % q);
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n; cin >> n;
  int cnt = 0, ans = 0;
  REP(i,n) {
    int d1,d2;
    cin >> d1 >> d2;
    if (d1 == d2) cnt++;
    else cnt=0;

    if (cnt == 3) ans = 1;
  }
  Yes(ans);

  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
const int md = 1e9 + 7;
inline int mul(int& a, int b) {
  a = (int)((long long)a * b % md);
}
int main() {
  int n;
  cin >> n;
  vector<char> c(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  vector<int> mlt(26, 0);
  for (int i = 0; i < n; i++) {
    mlt[c[i] - 'a']++;
  }
  int ret = 1;
  for (int i = 0; i < 26; i++) {
    mul(ret, mlt[i] + 1);
  }
  ret--;
  cout << ret << '\n';
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <numeric>
using namespace std;

int main(){
    int k,n;
    cin >> n >> k;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int b=n-1;
    int c=k-1;
    cout << (b+c-1)/c  << endl;
}



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

using namespace std;

int main() {
    string X;
    cin >> X;
    
    
    
    long long count = 0;
    long long res = 0;
    for (long long i = X.size() -1; i > -1; --i) {
        if ( X[i] == 'S') --count;
        else ++count;
        
        if (count == -1) {
            ++res;
            count = 0;
        }
    }
    
    
    cout << 2 * res << endl;
    
}

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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
typedef long long ll;

int main(){
  int N; cin >> N;
  vector<int> I(N);
  rep(i,N) cin >> I[i];
  ll r = 0;
  int max = -1000000;
  int min = 1000000;
  rep(i,N) {
    chmax(max,I[i]);
    chmin(min,I[i]);
    r += I[i];
  }
  cout << min << " " << max << " " << r << endl;
  
}



Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>
#include <assert.h>
#include <unordered_map>

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define bitcount(b) __builtin_popcount(b)
const double EPS = 1e-10;
const double PI = acos(-1.0);
#define MOD 1000000007
#define INF 1000000000000
using namespace std;



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

    int N;
    cin >> N;

    vector<vector<LL>> dp(N, vector<LL>(N, INF));
    vector<vector<LL>> v(N, vector<LL>(N, INF));
    FOR(i, 0, N) {
        FOR(j, 0, N) {
            cin >> dp[i][j];
            v[i][j] = dp[i][j];
        }
    }

    for(int m = 0; m < N; ++m) {
        for(int s = 0; s < N; ++s) {
            for(int e = 0; e < N; ++e) {
                if (s == e || s == m || m == e) { continue; }
                LL d = dp[s][m] + dp[m][e];
                if (d < dp[s][e]) {
                    cout << -1 << endl;
                    return 0;
                }
                if (dp[s][e] == d) {
                    v[s][e] = 0;
                }
            }
        }
    }
    LL ans = 0;
    FOR(i, 0, N) {
        FOR(j, 0, N) {
            ans += v[i][j];
        }
    }

    cout << ans / 2 << endl;

    return 0;
}


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

#累積和を計算
SumA = [0]*(N+1)
n = 1
for i in range(N):
	SumA[i+1] = SumA[i] + A[i]

#A*Aの全パターンを計算
AA = []
for j in range(N):
	AA.append(A[j]*(SumA[N]-SumA[j+1]))

#合計を計算
ans = sum(AA)%1000000007
print(ans)

Measured memory_bytes: 39724
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

void solve() {
  int N; cin >> N;
  vector<string> name(N);
  rep(i,N) cin >> name[i];

  string MARCH = "MARCH";
  vl initial(5, 0);
  rep(i,N) rep(j,5) if (name[i][0] == MARCH[j]) ++initial[j];
  
  ll ans = 0;
  for (int i=0; i<3; ++i) {
    for (int j=i+1; j<4; ++j) {
      for (int k=j+1; k<5; ++k) {
        ans += initial[i] * initial[j] * initial[k];
      }
    }
  }

  cout << ans << endl;
  return;
}

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


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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    string n; cin >> n;
    for (int i = 0; i < n.size(); i++) {
        if (n.at(i) == '1') n.at(i) = '9';
        else n.at(i) = '1';
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
/*input
4 100000
100000 100000 100000 100000
*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
/********************* MODULAR ARITHMETIC *******************************/

ll MOD = 1000000007;

void mod(ll &a){ if(a >= MOD) a %= MOD; }
ll add(ll a, ll b) { a += b; mod(a); return a; }
ll mul(ll a, ll b) { mod(a); mod(b); a *= b; mod(a); return a; }
ll sub(ll a, ll b) { mod(a); mod(b); a -= b; a += MOD; mod(a); return a; }

ll powr(ll a, ll b) {
  ll x = 1LL;
  while(b) {
    if(b & 1) x = mul(x, a);
    a = mul(a, a), b >>= 1;
  }
  return x;
}

ll inv(ll a) { return powr(a, (MOD - 2)); }

/************************************************************************/

ll dp[101][100005];
vector < int > v;

int main()
{
  int n, k;
  cin >> n >> k;
  v.resize(n);
  for(auto &x: v) {
    cin >> x;
  }

  for(int i = 0; i <= n; i ++) {
    dp[i][0] = 1;
  }

  for(int j = 0; j <= k; j ++) {
  	dp[0][j] = 1;
  }


  for(int i = 1; i <= n; i ++) {
    for(int j = 1; j <= k; j ++) {
    	int high = j;
    	int low = max(j - v[i - 1], 0);
    	if(low == 0) {
    		dp[i][j] = dp[i - 1][high];
    	} else {
    		dp[i][j] = sub(dp[i - 1][high], dp[i - 1][low - 1]);
    	}
    }
    if(i < n) {
	    for(int j = 1; j <= k; j ++) {
	    	// cout << dp[i][j] << " ";
	    	dp[i][j] = add(dp[i][j], dp[i][j - 1]);
	    }
	    // cout << "\n";
  	}
  }

  cout << dp[n][k];
  return 0;
}

Measured memory_bytes: 79104
#include<stdio.h>
int main(){
  int A[100],N;
  int i,j,k,flag=1,temp,num=0;

  scanf("%d",&N);

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
      }


  while(flag){
    flag=0;
    for(j=N-1;j>0;--j){
      if(A[j]<A[j-1]){
	temp=A[j];
	A[j]=A[j-1];
	A[j-1]=temp;
	flag=1;
	num++;
      }
    }
  }

  printf("%d",A[0]);
    for(j=1;j<N;j++){
      printf(" %d",A[j]);
    }
    printf("\n");
    printf("%d\n",num);

    return 0;
    
}

Measured memory_bytes: 604
use proconio::input;
use itertools::Itertools;

const INF:i64 = 1e16 as i64;

fn main() {
    input! {
        n:usize,
        m:usize,
        abc:[(i64,i64,i64);n],
        def:[(i64,i64,i64);m],
    };

    let xs:Vec<i64> = {
        let mut vec = Vec::<i64>::new();
        vec.push(0);
        vec.push(INF);
        vec.push(-INF);
        abc.iter().for_each(|&(a,b,_)|{
            vec.push(a);
            vec.push(b);
        });
        def.iter().for_each(|&(d,_,_)|{
            vec.push(d);
        });
        vec.sort();
        vec.into_iter().unique().collect()
    };
    let ys:Vec<i64> = {
        let mut vec = Vec::<i64>::new();
        vec.push(0);
        vec.push(INF);
        vec.push(-INF);
        abc.iter().for_each(|&(_,_,c)|{
            vec.push(c);
        });
        def.iter().for_each(|&(_,e,f)|{
            vec.push(e);
            vec.push(f);
        });
        vec.sort();
        vec.into_iter().unique().collect()
    };
    
    let gridx = {
        let mut gridx = vec![vec![false;ys.len()];xs.len()];
        for &(a,b,c) in &abc {
            let j = ys.iter().position(|&y|y==c).unwrap();
            for i in 0..xs.len() {
                if a<=xs[i] && xs[i]<b {
                    gridx[i][j] = true
                }
            }
        }
        gridx
    };

    let gridy = {
        let mut gridy = vec![vec![false;ys.len()];xs.len()];
        for &(d,e,f) in &def {
            let i = xs.iter().position(|&x|x==d).unwrap();
            for j in 0..ys.len() {
                if e<=ys[j] && ys[j]<f {
                    gridy[i][j] = true
                }
            }
        }
        gridy
    };

    let mut grid = vec![vec![false;ys.len()];xs.len()];
    let mut stack = Vec::<(usize,usize)>::new();
    {
        let (i,j) = {
            (
            xs.iter().position(|&x|x==0).unwrap(),
            ys.iter().position(|&y|y==0).unwrap(),
            )
        };
        grid[i][j] = true;
        stack.push((i,j));
    }

    let di = vec![1,0,-1,0];
    let dj = vec![0,1,0,-1];

    while let Some((i,j)) = stack.pop() {
        if i==0 || j==0 || i==xs.len()-1 || j==ys.len()-1 {
            println!("INF");
            return;
        }
        for k in 0..4 {
            let gi = i+(di[k]+1) as usize/2;
            let gj = j+(dj[k]+1) as usize/2;
            let xwall = dj[k]!=0 && gridx[gi][gj];
            let ywall = di[k]!=0 && gridy[gi][gj];
            let toi = (i as i32 +di[k]) as usize;
            let toj = (j as i32 +dj[k]) as usize;
            if !xwall && !ywall && !grid[toi][toj]{
                grid[toi][toj] = true;
                stack.push((toi,toj));
            }
        }
    }

    let mut ans = 0;
    for i in 0..xs.len()-1 {
        for j in 0..ys.len()-1 {
            if grid[i][j] {
                let xwid = xs[i+1]-xs[i];
                let ywid = ys[j+1]-ys[j];
                ans += xwid*ywid;
            }
        }
    }
    println!("{}",ans);

}


Measured memory_bytes: 82292