akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

	static List<Integer> adj[];
	public static void addEdge(int u,int v)
	{
		adj[u].add(v);
		adj[v].add(u);
	}
	static class pair
	{
		int i,j;
		public pair(int i,int j)
		{
			this.i=i;
			this.j=j;
		}
	}
	public static String VertexColoring(int N)
	{
		Queue<pair> q=new LinkedList<>();
		q.offer(new pair(0, 0));
		q.offer(new pair(N-1, 1));
		
		int color[]=new int[N];
		Arrays.fill(color, -1);
		
		while(!q.isEmpty())
		{
			pair p=q.poll();
			
			if(color[p.i]==-1)
			{
				color[p.i]=p.j;
				
				Iterator<Integer> itr=adj[p.i].iterator();
				while(itr.hasNext())
				{
					q.offer(new pair(itr.next(), p.j));
				}
			}
			
		}
		
		int s[]=new int[2];
		for (int i = 0; i < N; i++) {
			s[color[i]]++;
		}
		return s[0]>s[1]?"Fennec":"Snuke";
		
	}
	public static void main(String[] args) {
		
		Scanner sc=new Scanner(System.in);
		int V=sc.nextInt();
		adj=new LinkedList[V];
		for (int i = 0; i < V; i++) {
			adj[i]=new LinkedList<>();
		}
		for (int i = 0; i < V-1; i++) {
			int u=sc.nextInt();
			int v=sc.nextInt();
			u--;
			v--;
			addEdge(u, v);
		}
		
		System.out.println(VertexColoring(V));
	}

}

Measured memory_bytes: 104988
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, A;
    cin >> N >> A;
    N %= 500;
    if (N <= A) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;
using static System.Math;

class Program{
    static void Main(){
        int n = int.Parse(Console.ReadLine());
        int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();
        
        int[] ans = new int[n];
        for (int i = n - 1;i >= 0;i--){
            int c = i + 1;
            for (int j = n - 1;j >= 0;j--){
                if (b[j] == -1) continue;
                if (b[j] == c){
                    b[j] = -1;
                    ans[i] = c;
                    break;
                }
                c--;
            }
            if (ans[i] == 0){
                Console.WriteLine(-1);
                return;
            }
        }
        foreach (var i in ans) Console.WriteLine(i);
    }
}

Measured memory_bytes: 13396
import java.util.*;
public class Main {
	public static void main(String[] args){
 
      Scanner sc = null;
      sc = new Scanner(System.in);
      String S = sc.nextLine();
      if(Character.isUpperCase(S.charAt(0))){
        System.out.println( "A" );
      }
      else {
        System.out.println( "a" );
      }
    }
}

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

using namespace std;

#define MAX 1010

int p[MAX][MAX][3];
int t[MAX][MAX][3];

int solve(int m,int a,int b,int c,int d){
  return t[c][d][m]-t[a-1][d][m]-t[c][b-1][m]+t[a-1][b-1][m];
}

int main(){
  int N,M,Q;
  cin >> N >> M >> Q;
  for(int i = 1 ; i <= N ; i++){
    for(int j = 1 ; j <= M ; j++){
      char ch; cin >> ch;
      int m = (ch == 'J' ? 0 :
               ch == 'O' ? 1 : 2);
      p[i][j][m]++; t[i][j][m]++;
      for(int k = 0 ; k < 3 ; k++){
        p[i][j][k] += p[i][j-1][k];
      }
      for(int k = 0 ; k < 3 ; k++){
        t[i][j][k] += p[i-1][j][k];
        t[i][j][k] += p[i][j-1][k];
      }
    }
    for(int j = 1 ; j <= M ; j++){
      for(int k = 0 ; k < 3 ; k++){
        p[i][j][k] = t[i][j][k];
      }
    }
  }
  int a,b,c,d;
  while(Q--){
    cin >> a >> b >> c >> d;
    cout << solve(0,a,b,c,d) << " "
         << solve(1,a,b,c,d) << " "
         << solve(2,a,b,c,d) << endl;
  }
  return 0;
}

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

int main(){
    while (1){
        int H,W,i,j;
        cin>>H>>W;
        if (H==0 and W==0){
            break;
        }else{
            for ( i=0; i< H;i++ ){
                for (j=0; j<W;j++ ){
                    if ((i==0) or (i==H-1) or (j==0) or (j==W-1)){ 
                     cout<<"#" ; 
                    }else{
                        cout<<".";
                    }
                }
                cout<<endl;
            }
            cout<<endl;
        }
    }
}



Measured memory_bytes: 3084
#include<bits/stdc++.h> 
using namespace std;
string s[200005];
int main(){
	int n,m=0;
	cin>>n;
	map<string,int>t;
	for(int i=0;i<n;i++){
		cin>>s[i];
		t[s[i]]++;
		if(m<t[s[i]]) m=t[s[i]];
	}
//	sort(s,s+n);//
	set<string>ww;
	for(int i=0;i<n;i++){
		if(t[s[i]]==m) {
			ww.insert(s[i]);
		//	cout<<s[i]<<endl;
			t[s[i]]=0;
		}
	}
	set<string>::iterator it=ww.begin();
	for(;it!=ww.end();it++){
		cout<<*it<<endl;
	}
	return 0;
}



Measured memory_bytes: 36096
#include <iostream>
#include <vector>
#include <string>

short int dx[4] = {1, 0, -1, 0};
short int dy[4] = {0, 1, 0, -1};
// using pint = std::pair<int, int>;

short int H, W;
std::vector<std::string> fi;

long long numb = 0, numw = 0;
bool seen[410][410];

void dfs(short int x, short int y)
{
    seen[x][y] = true;
    if (fi[x][y] == '#')
        ++numb;
    else
        ++numw;
    for (short int dir = 0; dir < 4; ++dir)
    {
        short int nx = x + dx[dir];
        short int ny = y + dy[dir];
        if (nx < 0 || nx >= H || ny < 0 || ny >= W)
            continue;
        if (fi[x][y] == fi[nx][ny])
            continue;
        if (seen[nx][ny])
            continue;
        dfs(nx, ny);
    }
}

int main()
{
    std::cin >> H >> W;
    fi.resize(H);
    for (short int i = 0; i < H; i++)
        std::cin >> fi[i];

    long long answer = 0;
    for (short int x = 0; x < H; ++x)
    {
        for (short int y = 0; y < W; ++y)
        {
            if (fi[x][y] == '.')
                continue;
            if (seen[x][y])
                continue;
            numb = numw = 0;
            dfs(x, y);
            answer += numb * numw;
        }
    }
    std::cout << answer << std::endl;
}

Measured memory_bytes: 15616
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#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 <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int main(){
    string S;
    cin >> S;
    int N;
    cin >> N;
    int count=0;
    for(int i=0;i<N;++i){
        int T=0;
        cin >> T;
        if(T==1) count++;
        if(T==2){
            int F;string C; cin >> F >> C;
            if(count%2==0){
            if(F==1){
                S.insert(0,C);
                }

            else S+=C;
        }
        else{
         if(T==2){
            if(F==2){
                S.insert(0,C);
                }

            else S+=C;
                    }   
                }
        }
    }
    if(count%2!=0)
    {for(int i=S.length()-1;i>=0;--i) cout << S[i];}
    else cout << S;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> h(n+2);
    rep(i,n) cin >> h[i+2];
    vector<int> dp(n+2);
    dp[0] = 0; dp[1]= 0;
    h[0] = h[2]; h[1] = h[2];
    for(int i = 2; i< n+2; i++){
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[n+1] << endl;
    return 0;
}

Measured memory_bytes: 1024
use proconio::{ input, fastout };

#[fastout]
fn main() {
    input! {
        s: String,
    };
    let d = if &s == "RRR" {
        3
    } else if &s == "RRS" || &s == "SRR" {
        2
    } else if &s == "SSS" {
        0
    } else {
        1
    };
    println!("{}", d );
}


Measured memory_bytes: 2152
N, M, P = map(int, input().split())

E = [[0, 0, 0] for m in range(M)]
for m in range(M):
    A, B, C = map(int, input().split())
    E[m][0] = A - 1
    E[m][1] = B - 1
    E[m][2] = P - C


def BellmanFord(edges, num_v, source, end):
    inf = 10 ** 12
    dist = [inf for i in range(num_v)]
    dist[source] = 0
    parent = [-1 for i in range(num_v)]

    for i in range(num_v):
        for edge in edges:
            if dist[edge[1]] > dist[edge[0]] + edge[2]:
                dist[edge[1]] = dist[edge[0]] + edge[2]
                parent[edge[1]] = edge[0]

    end1 = dist[end]
    trace1 = []
    r = end
    for n in range(num_v):
        trace1.append(r)
        r = parent[r]
        if r == -1:
            break

    for i in range(num_v):
        for edge in edges:
            if dist[edge[1]] > dist[edge[0]] + edge[2]:
                dist[edge[1]] = dist[edge[0]] + edge[2]
                parent[edge[1]] = edge[0]

    end2 = dist[end]
    trace2 = []
    r = end
    for n in range(num_v + 10):
        trace2.append(r)
        r = parent[r]
        if r == -1:
            break

    if trace2[-1] != source:
        return -1

    return max(0, -end1) if end1 == end2 else -1


res = BellmanFord(E, N, 0, N - 1)
print(res)


Measured memory_bytes: 49132
# 解説AC
# 解説放送と
# https://twitter.com/kyopro_friends/status/1274710268262547456?s=20
# で理解
MOD = 10**9 + 7


def main():
    K = int(input())
    S = input()
    N = len(S)
    m = N+K + 5
    fac = [0] * m
    finv = [0] * m
    inv = [0] * m

    def COMBinitialize(m):
        fac[0] = 1
        finv[0] = 1
        if m > 1:
            fac[1] = 1
            finv[1] = 1
            inv[1] = 1
            for i in range(2, m):
                fac[i] = fac[i-1] * i % MOD
                inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
                finv[i] = finv[i - 1] * inv[i] % MOD

    def COMB(n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

    COMBinitialize(m)
    ans = 0
    for i in range(K+1):
        v = COMB(N-1+K-i, N-1)
        v %= MOD
        v *= pow(25, (K-i), MOD)
        v %= MOD
        v *= pow(26, i, MOD)
        v %= MOD
        ans += v
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 119868
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define mp make_pair
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define BLACK 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
class Edge {
public:
    ll t;
    ll w;
    Edge() {}
    Edge(ll t, ll w): t(t), w(w) {}
};


int main(void) {
    ll N;
    cin >> N;
    ll a, b;
    
    if(N==1) {
        cout << "Hello World" << endl;
        return 0;
    }
    
    if(N==2) {
        cin >> a >> b;
        prin(a+b);
        return 0;
    }
    
    
}

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

const int N = 1e5 + 100;
int a[N], b[N];
map<int, int> mp;

int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++) {
		scanf("%d", &a[i]);
		mp[a[i]] ++;
	}
	sort(a + 1, a + n + 1, greater<int>());
	int m = unique(a + 1, a + n + 1) - (a + 1);
	long long x = 0, y = 0;
	for(int i = 1; i <= m; i ++) {
		int t = mp[a[i]];
		if( t == 2 || t == 3) {
			if( x == 0)  x = a[i];
			else y = a[i];
		}
		else if( t >= 4) {
			if( x == 0)	x = y = a[i];
			else y = a[i];
		}
		if( x && y)  break;
	}
	printf("%lld\n", (long long) x * y);
}

Measured memory_bytes: 8296
void main() {
    string a = readln.chomp;
    string b = readln.chomp;
    if (a.length > b.length) {
        "GREATER".writeln;
    } else if (a.length < b.length) {
        "LESS".writeln;
    } else {
        if (a > b) {
            "GREATER".writeln;
        } else if (a < b) {
            "LESS".writeln;
        } else {
            "EQUAL".writeln;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<array>
#include<string>
#include<map>
#include<utility>

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    int min, max;
    min = a <= b ? a : b; 
    max = a >= b ? a : b;
    
    for(int i=0;i<max;++i){
        cout << min;
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

#define SQ(X) ((X)*(X))
#define CB(X) ((X)*(X)*(X))
#define ABS(X) ((X)>0?(X):(-(X)))
#define MAX(X,Y) ((X)>(Y)?(X):(Y))

using namespace std;

int main(void){
  int n;
  int x[100], y[100];
  double d;
  
  cin >> n;
  cout << setprecision(10);
  for (int i=0; i<n; i++) cin >> x[i];
  for (int i=0; i<n; i++) cin >> y[i];
  // p=1
  d=0;
  for (int i=0; i<n; i++){
    d += ABS(x[i]-y[i]);
  }
  cout << d << endl;
  // p=2
  d=0;
  for (int i=0; i<n; i++){
    d += SQ(ABS(x[i]-y[i]));
  }
  cout << sqrt(d) << endl;
  // p=3
  d=0;
  for (int i=0; i<n; i++){
    d += CB(ABS(x[i]-y[i]));
  }
  cout << cbrt(d) << endl;
  // p=INF
  d=ABS(x[0]-y[0]);
  for (int i=1; i<n; i++){
    d = MAX(d, ABS(x[i]-y[i]));
  }
  cout << d << endl;
  
  return 0;
}



Measured memory_bytes: 3492
from math import gcd
n,m=map(int,input().split())
s=input()
t=input()
res=n*m//gcd(n,m)
a=m//gcd(n,m)
b=n//gcd(n,m)
if n>=m:
  for i in range(m):
    if (i*b)%a==0:
      if s[(i*b)//a]!=t[i]:
        print(-1)
        exit()
else:
  for i in range(n):
    if (i*a)%b==0:
      if s[i]!=t[(i*a)//b]:
        print(-1)
        exit()
print(res)

Measured memory_bytes: 9340
#include <stdio.h>

int main()
{
    int n,i,max = 50000;
    scanf("%d",&n);

    for (i = 1; i <= max; i++)
    {
        if(i * 108 / 100 == n)break;
    }
    if(i == max + 1)printf(":(");
    else printf("%d",i);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
char s[107];
int main(){
    scanf("%s",s+1);
    if(s[1]>='3')
        printf("TBD");
    else if(s[1]=='2'&&s[2]>'0')
        printf("TBD");
    else if(s[1]=='2'&&s[2]=='0'&&s[3]>'1')
        printf("TBD");
    else if(s[1]=='2'&&s[2]=='0'&&s[3]=='1'&&s[4]<'9')
        printf("Heisei");
    else if(s[1]=='2'&&s[2]=='0'&&s[3]=='1'&&s[4]=='9'){
        if(s[6]=='1')
            printf("TBD");
        else if(s[6]=='0'&&s[7]>'4')
            printf("TBD");
        else if(s[6]=='0'&&s[7]<='4')
            printf("Heisei");
    }
    return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
x = gets.chomp.split(" ").map(&:to_i)

a = []
n.times do |i|
  a << [x[i], i]
end

a.sort_by!{|e| e[0]}

y = Array.new(n)

a.each_with_index do |e, i|
  if i + 1 <= n / 2
    y[e[1]] = a[n / 2][0]
  else
    y[e[1]] = a[n / 2 - 1][0]
  end
end
puts y

Measured memory_bytes: 36888
from collections import deque

N, M = map(int, input().split())
AB = [map(int, input().split()) for _ in range(M)]

links = [[] for _ in range(N + 1)]
for a, b in AB:
    links[a].append(b)
    links[b].append(a)

result = [-1] * (N + 1)
q = deque([1])
while q:
    i = q.popleft()
    for j in links[i]:
        if result[j] == -1:
            result[j] = i
            q.append(j)
print('Yes')
print('\n'.join(str(i) for i in result[2:]))

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

int main(void){
    int N; cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    sort(A.begin(), A.end(), greater<int>());
    int Alice=0, Bob=0;
    for(int i=0; i<N; i++){
        if(i%2==0) Alice+=A[i];
        else Bob+=A[i];
    }

    cout << Alice-Bob << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

int main(){
    //freopen("in.txt", "r", stdin);
    int n, h;
    cin>>n;

    int cnt = 0;
    int prev = 1;
    while (n--){
        cin>>h;
        if (h>=prev) cnt++;
        prev = max(prev, h);
    }
    cout<<cnt<<endl;

    return 0;
}

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

using namespace std;

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

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

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

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

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

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

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> v(n, 0);
    v[0] = s[0] == 'W' ? 1 : 0;
    rep(i, n) {
        if (i == 0) continue;
        v[i] = v[i - 1];
        if (s[i] == 'W') v[i]++;
    }
    ll ans = 0;
    rep(i, n) {
        if (s[i] == 'B') continue;
        int k = v[i];

        int now = i - k + 1;
        ans += now;
    }
    cout << ans << endl;

    cout << endl;
}


Measured memory_bytes: 1412
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
dic = {}
for a in A:
    dic[a] = dic.get(a,0)+1
ans = 0

for a in A:
    small = (1<<(len(format(a,"b")))) - a
    if small == a:
        if dic[a] >= 2:
            dic[a] -= 2
            ans += 1
        continue
    if dic.get(a,0)>0 and dic.get(small,0)>0:
        dic[a] -= 1
        dic[small] -= 1
        ans += 1
print(ans)


Measured memory_bytes: 33860
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    let (n, m): (usize, usize) = (io.read(), io.read());

    match n % 2 {
        0 => {
            let mut l = 1;
            let mut r = n - 1;
            let mut flg = false;

            while l <= m {
                if !flg && (r - l) <= n / 2 {
                    r -= 1;
                    flg = true;
                }
                println!("{} {}", l, r);
                io.debug2(l, r);
                r -= 1;
                l += 1;
            }
        }
        _ => {
            for i in 1..m + 1 {
                let j = n - i;
                // 1,3,5,...
                println!("{} {}", i, j);
            }
        }
    }
}

static MOD: i64 = 1000000007;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 2828
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	ll N, A, B;
	cin >> N >> A >> B;

	ll ans = (N/(A+B)) * A + min(N%(A+B), A);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
ABCD=input()
def Op_change(a):
  if a==1:
    return "+"
  elif a==-1:
    return "-"
  else:
    return ""
A=int(ABCD[0])
B=int(ABCD[1])
C=int(ABCD[2])
D=int(ABCD[3])
Op=[1,-1]
Op_List=[]
Flag=0
for i in Op:
  for j in Op:
    for k in Op:
      if A+i*B+j*C+k*D==7:
        Flag=1        
        Op_List.append(Op_change(i))
        Op_List.append(Op_change(j))
        Op_List.append(Op_change(k))
        break
    if Flag==1:
      break
  if Flag==1:
      break
print(str(A)+Op_List[0]+str(B)+Op_List[1]+str(C)+Op_List[2]+str(D)+"=7")

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

using ll = long long;
const ll mod = 100000000+7;
const ll MAX_N = 1000;

ll a,b,c,d;
int main(){
  cin>>a>>b>>c>>d;

  cout<<max(a*b,c*d)<<endl;

}


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

#define ll long long int
#define ld long double
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define show(x) cerr<<#x<<" : "<<x<<'\n';
#define yogeshk972() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();

using namespace std;
const int N= 1e3+10, mod= 1e9+7;

int main() {
  ios_base::sync_with_stdio(false);cin.tie(NULL);
/*
  #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin);
  freopen("out.txt","w",stdout);
  #endif
  */
  int n;
  cin>>n;
  vector<int> v1(n),v2(n);
  
  for(auto &x:v1)cin>>x;
  for(auto &x:v2)cin>>x;
  
  int a,b,ct=0;
  vector<int> v;
  for(int i=1;i<=n;i++)v.pb(i);

  do{
    if(v==v1)a=ct;
    if(v==v2) b=ct;
    ct++;
  }while(next_permutation(v.begin(),v.end()) );
  


  cout<<abs(a-b);

  return 0;
}


Measured memory_bytes: 256
// Love and Freedom.
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<bitset>
#define maxn 500
using namespace std;

int a[110000],b[110000];
bool dead[maxn];
bitset<maxn> g[maxn];

int main()
{
	int n,i,m,j,k,x,y,ans=0;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++)	scanf("%d%d",&a[i],&b[i]);
	for(i=1;i<=n;i++)
	{
		g[i][i]=1;
		for(j=m;j;j--)
		{
			x=g[i][a[j]];y=g[i][b[j]];
			if(x&&y)
			{
				dead[i]=1;
				break;
			}
			else
			{
				if(x)	g[i][b[j]]=1;
				if(y)	g[i][a[j]]=1;
			}
		}
	}
	for(i=1;i<n;i++)
	{
		if(dead[i])	continue;
		for(j=i+1;j<=n;j++)
		{
			if(dead[j])	continue;
			int cur=1;
			for(k=1;k<=n;k++)
				if(g[i][k]&&g[j][k])
				{
					cur=0;
					break;
				}
			ans+=cur;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
  char s[100001] = {};
  scanf("%s", s);
  
  int i = strlen(s);
  if(s[0] == s[i-1]){
    if(i%2 == 1){
      printf("%s", "Second");
    }else{
      printf("%s", "First");
    }
  }else{
    if(i%2 == 1){
      printf("%s", "First");
    }else{
      printf("%s", "Second");
    }
  }
  
  return 0;
}

Measured memory_bytes: 1824
schedule = gets.strip
w = (schedule =~ /w/i)
e = (schedule =~ /e/i)
n = (schedule =~ /n/i)
s = (schedule =~ /s/i)

if w && e && n && s
	puts "Yes"
elsif n && s && (!e) && (!w)
	puts "Yes"
elsif e && w && (!n) && (!s)
	puts "Yes"
else
	puts "No"
end



Measured memory_bytes: 1788
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type dictionary struct {
	arr [1000][]int64
}

func toNum(c string) int64 {
	bytes := []byte(c)
	var res int64 = 0
	for _, v := range bytes {
		switch v {
		case 'A':
			res = res*4 + 1
		case 'C':
			res = res*4 + 2
		case 'G':
			res = res*4 + 3
		case 'T':
			res = res*4 + 4
		default:
			panic(fmt.Sprint("illegal string: %s\n", c))
		}
	}
	return res
}

func (dict *dictionary) insert(c string) {
	if !dict.find(c) {
		num := toNum(c)
		h := num % 1000
		dict.arr[h] = append(dict.arr[h], num)
	}
}

func (dict *dictionary) find(c string) bool {
	num := toNum(c)
	h := num % 1000
	for _, v := range dict.arr[h] {
		if num == v {
			return true
		}
	}
	return false
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	dict := &dictionary{}
	for i := 0; i < n; i++ {
		inst := nextText(sc)
		letters := nextText(sc)
		if inst == "insert" {
			dict.insert(letters)
		} else if inst == "find" {
			if dict.find(letters) {
				fmt.Println("yes")
			} else {
				fmt.Println("no")
			}
		} else {
			panic(fmt.Sprintf("unknown instruction: %s\n", inst))
		}
	}
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}



Measured memory_bytes: 8672
import java.util.*

object Mod {
    var num: Long = 1000000007
    val inverse: HashMap<Long, Long> = hashMapOf()
    val factorial: HashMap<Long, Long> = hashMapOf()
}

infix fun Long.plM(other: Long): Long {
    return (this + other) % Mod.num
}

infix fun Long.mnM(other: Long): Long {
    return (this - other) % Mod.num
}

infix fun Long.tiM(other: Long): Long {
    return ((this % Mod.num) * (other % Mod.num)) % Mod.num
}

infix fun Long.diM(other: Long): Long {
    return ((this % Mod.num) * other.inverse()) % Mod.num
}

fun Long.power(num: Long): Long {
    var res: Long = 1
    var a = this
    var n = num
    while (n > 0) {
        if (n and 1L == 1L) {
            res = res tiM a
        }
        a = a tiM a
        n = n shr 1
    }
    return res
}

fun Long.inverse(): Long {
    val ans = Mod.inverse[this]
    return if (ans != null) {
        ans
    } else {
        val ans2 = this.power(Mod.num - 2)
        Mod.inverse[this] = ans2
        ans2
    }
}

fun Long.factorial(): Long {
    if (this == 1.toLong()) return 1
    val ans = Mod.factorial[this]
    return if (ans != null) {
        ans
    } else {
        val ans2 = (this - 1).factorial() tiM this
        Mod.factorial[this] = ans2
        ans2
    }
}

fun Long.combi(other: Long): Long {
    if (this < other) return 0
    if (other == this || other == 0.toLong()) return 1
    return this.factorial() tiM
            other.factorial().inverse() tiM
            (this - other).factorial().inverse()
}

fun main(args: Array<String>) {
    val p = readLine()!!.toInt()
    Mod.num = p.toLong()
    val array = readLine()!!.split(' ').map(String::toInt)
//    val start = System.currentTimeMillis()
//    Cache
    p.toLong().factorial()
    val p_1C = hashMapOf<Int, Long>()
    for (k in 0..(p - 1)) {
        p_1C[k] = (p - 1).toLong().combi(k.toLong())
    }

//    1 - (x-j)^(p-1)
    val ans = LongArray(p)
    for (i in 0 until p) {
        if (array[i] == 0) continue
        ans[0]++
        val j = i.toLong()
        var jTimes = 1L
        for (k in p-1 downTo 0) {
            ans[k] = ans[k] mnM (p_1C[k]!! tiM jTimes)
            jTimes = jTimes tiM -j
        }
    }
//    val stop = System.currentTimeMillis()
//    println("Total: ${stop - start} ms")

    for (res in ans) {
        print("${if (res >= 0) res else res + Mod.num} ")
    }
}


Measured memory_bytes: 71972
#include<stdio.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)

int main(){
	int h,w;
	char c[102][102];
	scanf("%d %d",&h,&w);
	FOR(i,0,h) scanf("%s",c[i]);
	FOR(i,0,h) FOR(j,0,2) printf("%s\n",c[i]);
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
	int a, b;
	for(int i=0; ; i++){
		scanf("%d %d", &a, &b);
		if(a==0 && b==0) break;
		if(a>b) printf("%d %d\n", b, a);
		else printf("%d %d\n", a, b); 
	}
}


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

int main() {
  
  int A, B;
  
  cin >> A >> B;
  if (A == 1 && B == 2) cout << 3 << endl;
  else if (A == 1 && B == 3) cout << 2 << endl;
  else if (A == 2 && B == 1) cout << 3 << endl;
  else if (A == 2 && B == 3) cout << 1 << endl;
  else if (A == 3 && B == 1) cout << 2 << endl;
  else if (A == 3 && B == 2) cout << 1 << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    
    int n;
    cin >> n;
    ll a[n];
    inrep(n,a);

    ll dp[n] = {};
    rep(i,0,n)dp[i]= linf;
    dp[0] = 0;
    dp[1] = abs(a[0] - a[1]);
    rep(i,2,n){
	dp[i] = min(dp[i-2] + abs(a[i-2] - a[i]),dp[i-1] + abs(a[i-1] - a[i])); 
    }
    P(dp[n-1]);
    return  0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll         long long int 
#define pb         push_back
#define umap       unordered_map
#define mod        1000000007
#define all(x)     (x).begin(), (x).end()
#define rall(x)    (x).rbegin(), (x).rend()
#define MN(a,b,c)  min(a,min(b,c))
#define MX(a,b,c)  max(a,max(b,c))
#define pr1         pair<ll,ll>
#define F          first
#define S          second
#define mP         make_pair
#define f(i,n)     for(int i=0;i<n;i++)
#define f1(i,x,y)  for(int i=x;i<=y;i++)
#define f2(i,x,y)  for(int i=x;i>=y;i--)
#define yes        cout<<"YES"<<"\n"
#define no         cout<<"NO"<<"\n"
//__builtin_popcount(x)
//__builtin_parity(x)   =(number of set bits)%2
//__builtin_clz(x)      to count the number of leading  zeroes 
//__builtin_ctz(x)      to count the number of trailing zeroes 
//__gcd(a,b)
using namespace std;
int main()
{
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 ll n;cin>>n;
 vector <ll> h(n);
 f(i,n){cin>>h[i];}
 vector <ll> dp(n,0);
 dp[0]=0,dp[1]=abs(h[1]-h[0]);
 if(n>=3){dp[2]=abs(h[2]-h[0]);}
 ll v1,v2;
 for(int i=3;i<n;i++)
 {
   dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
 }
 cout<<dp[n-1];
}
   

Measured memory_bytes: 4792
import sys
s = input()
n = int(input())
cnt = 0
if n == 1:
	print(s[0])
	sys.exit()
for i in s:
	if i == '1':
		cnt += 1
	else:
		break
if n <= cnt:
	print(1)
	sys.exit()
	
for i in s:
	if i != '1':
		print(i)
		sys.exit()
print(1)

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define MOD 1000000007
#define int long long
#define vi vector<long long int>
#define pb push_back
#define rep(i,a,n) for (int i=(a);i<(n);++i)
using namespace __gnu_pbds;
using namespace std;
// its godfather
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int>vec;
long long power(long long a, long long b, long long m)
{
   long long res = 1;
   while (b > 0)
   {
      if (b & 1)
         res = res * a % m;
      a = a * a % m;
      b >>= 1;
   }
   return res;
}
signed main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(0);

#ifndef ONLINE_JUDGE
   if (fopen("INPUT.txt", "r"))
   {
      freopen("INPUT.txt", "r", stdin);
      freopen("OUTPUT.txt", "w", stdout);
   }
#endif
   int t;
   // cin>>t;
   t=1;
   while(t-->0){
      int n;
      cin>>n;
      vector<int>arr;
      for(int i=0;i<n;i++){
         int g;
         cin>>g;
         arr.pb(g);
      }
      sort(arr.begin(), arr.end());
      int z=arr[n-1];
      vector<bool> visited(z+1, false);
      int ans=0;
      for(int i=0;i<n;i++){
         if(!visited[arr[i]]){
            if(i==n-1 || arr[i]!=arr[i+1])
               ans++;
            for(int j=1;j*arr[i]<=z;j++){
               visited[j*arr[i]]=true;
            }
         }
      }
      cout<<ans<<endl;
   }
}

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

using namespace std;

int main() {
    int n ; cin >> n;
    bool ok = false;
    vector<int>v(n) , mark(n + 1);
    for(int& i : v){
        cin >> i;
        if(i % 2 == n % 2)ok = true;
        mark[i]++;
        if(mark[i] > 2){
            ok = true;
        }
    }
    int z = count(v.begin() , v.end() , 0);
    if(z && n % 2 == 0){
        cout << 0 << endl;
        return 0;
    }
    if(z > 1 || ok){
        cout << 0 << endl;
        return 0;
    }
    int half = n / 2 ;
    long long ans = 1;
    const int M = 1e9 + 7;
    for(int i = 1 ; i <= half; ++i){
        ans = (ans * 2) % M;
    }
    cout << ans << endl;

    
}

Measured memory_bytes: 3972
#include <stdio.h>
/*ここから上は消さないで*/

int main(){
	int a;
	int b;
	int c;
	double S;
	scanf("%d %d", &a, &b);
	c = a * b;
	S = c / 3.305785;
	printf("%f\n", S);
	return 0;	//ここの行、重要
}

Measured memory_bytes: 632
using System;

namespace _066_TicTacToe
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;

			while ((inputStr = Console.ReadLine ()) != null)
			{
				char result = IsLine (inputStr);
				Console.WriteLine (result);
			}
		}

		static char IsLine ( string result )
		{
			//?¨?
			if (result[0] != 's' && result[0] == result[1] && result[1] == result[2])
			{
				return result[0];
			}
			else if (result[3] != 's' && result[3] == result[4] && result[4] == result[5])
			{
				return result[3];
			}
			else if (result[6] != 's' && result[6] == result[7] && result[7] == result[8])
			{
				return result[6];
			}

			//???
			else if (result[0] != 's' && result[0] == result[3] && result[3] == result[6])
			{
				return result[0];
			}
			else if (result[1] != 's' && result[1] == result[4] && result[4] == result[7])
			{
				return result[1];
			}
			else if (result[2] != 's' && result[2] == result[5] && result[5] == result[8])
			{
				return result[2];
			}

			//??????
			else if (result[0] != 's' && result[0] == result[4] && result[4] == result[8])
			{
				return result[0];
			}
			else if (result[2] != 's' && result[2] == result[4] && result[4] == result[6])
			{
				return result[2];
			}

			return 'd';
		}
	}
}

Measured memory_bytes: 8708
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[5]={-1,0,1,0,0};
int dy[5]={0,-1,0,1,0};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    string s;cin>>s;
    ll now=0;
    ll ans=0;
    ll n=s.length();
    ll ss=0,cnt=0;
    for(ll i=0;i<n;i++){
        if(s[i]=='S')ss++;
        else{
            if(ss){
                ss--;
                cnt+=2;
            }
        }
    }
    cout<<n-cnt<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





































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

int main(){
    int N, d[100010];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> d[i];
    }
    sort(d, d + N, greater<int>());
    int n = N/2;
    cout << d[n-1] - d[n] << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
#define MSG(a) cout << #a << " " << a << "\n";

int main(){
    int n;cin >> n;
    vint p(n); REP(i,n) cin >> p.at(i);
    
    int x1,x2,x3,ans = 0;
    FOR(i,1,n-1){
        x1 = p.at(i-1);
        x2 = p.at(i);
        x3 = p.at(i+1);
        if( (x1 < x2 & x2 < x3) | (x1 > x2 & x2 > x3) ) ans++;
    }
    cout << ans <<endl;

}

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


using namespace std;


const int MAXN = 200 * 1000 + 123;






long long n, a[MAXN], b[MAXN];
set<long long> s;
long long ans;

int main() {
	cin >> n;
	s.insert(n + 1);
	s.insert(0);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		b[a[i]] = i;
	}
	for (int i = 1; i <= n; i++) {
		auto x = s.upper_bound(b[i]);
		ans += (*x - b[i]) * (b[i] - *(--x)) * i;
		s.insert(b[i]);
	}
	cout << ans;
	return 0;
}	

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int cnt[100005];
int main(){
    /// input
    int n,x;
    cin>>x>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    /// process
    for(int i=0;i<n;i++){
        cnt[a[i]] = 1;
    }
    int dis = 1e9;
    int ans = 1000;
    for(int i=0;i<=100001;i++){
        int found = cnt[i];
        if(found==1)continue;
        int tmp = abs(x-i);
        if(tmp<dis){
            dis = tmp;
            ans = i;
        }
    }
    /// output
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define tcase int _; cin >> _; while(_--)
const int MAX = 1e6;

int n, k, c;
string s;
int l[MAX], r[MAX];

void solve() {
	cin >> n >> k >> c >> s;
	memset(l, 0, sizeof l);
	// memset(r, 0, sizeof r);
	fill(r, r+MAX, k+1);
	for(int i=1; i<=n; i++) {
		if(s[i-1] == 'o') {
			if(i <= c) l[i]++;
			else l[i] = l[i-c-1]+1;
		} else {
			l[i] = l[i-1];
		}
	}
	for(int i=n; i; i--) {
		if(s[i-1] == 'o') {
			if(i+c >= n) r[i]--;
			else r[i] = r[i+c+1]-1;
		} else {
			r[i] = r[i+1];
		}
	}
	int day = 1;
	int last = 0;
	int cnt = 0;
	for(int i=1; i<=n; i++) {
		if(s[i-1] == 'o' && l[i] == r[i]) {	
			if(l[i] == day) {
				cnt++;
				last = i;
			} else {
				if(cnt == 1) cout << last << "\n";
				day = l[i];
				last = i;
				cnt = 1;
			}
		}
	}
	if(cnt == 1) cout << n << "\n";
}

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

 	solve();

  	return 0;
}



Measured memory_bytes: 11564
k = sorted(map(int, input().split()))
a = k[0]
b = k[1]
c = k[2]

cnt = 0
if a%2 != b%2:
    c += 1
    a += 1
    cnt += 1

while True:
    if a == c or b == c:
        break
    a += 1
    b += 1
    cnt += 1
if a == c:
    print(cnt)
else:
    print(cnt+(c-a)//2)

Measured memory_bytes: 9016