akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_W = 100;
const int MAX_H = 100;

const int dxs[] = {1, 0, -1, 0};
const int dys[] = {0, 1, 0, -1};

/* typedef */

/* global variables */

int w, h, n;
bool wls[MAX_H][MAX_W][4], vstd[MAX_H][MAX_W][4];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> w >> h >> n;
    if (w == 0) break;
    
    memset(wls, 0, sizeof(wls));
    memset(vstd, 0, sizeof(vstd));

    for (int i = 0; i < n; i++) {
      int x0, y0, x1, y1;
      cin >> x0 >> y0 >> x1 >> y1;

      if (y0 == y1) {
	if (x0 > x1) swap(x0, x1);
	for (int x = x0; x < x1; x++)
	  wls[y0 - 1][x][1] = wls[y0][x][3] = true;
      }
      else {
	if (y0 > y1) swap(y0, y1);
	for (int y = y0; y < y1; y++)
	  wls[y][x0 - 1][0] = wls[y][x0][2] = true;
      }
    }

    for (int x = 0; x < w; x++) wls[0][x][3] = wls[h - 1][x][1] = true;
    for (int y = 0; y < h; y++) wls[y][0][2] = wls[y][w - 1][0] = true;
    
    int x, y, x1, y1, gx, gy, left;
    cin >> x >> y >> x1 >> y1 >> gx >> gy;

    if (y == y1) {
      if (x > x1) swap(x, x1);
      if (y == 0) left = 2;
      else y--, left = 0;
    }
    else {
      if (y > y1) swap(y, y1);
      if (x == 0) left = 1;
      else x--, left = 3;
    }

    int d;
    for (d = 1; x != gx || y != gy; d++) {
      //printf("x=%d, y=%d, left=%d\n", x, y, left);
      
      if (vstd[y][x][left]) { d = 0; break; }
      vstd[y][x][left] = true;
      
      int drc = left;
      for (int di = 0; di < 4; di++, drc = (drc + 3) % 4)
	if (! wls[y][x][drc]) {
	  x += dxs[drc];
	  y += dys[drc];
	  left = (drc + 1) % 4;
	  break;
	}
    }

    if (d <= 0) cout << "Impossible" << endl;
    else cout << d << endl;
  }

  return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;

int N;
long long a[10001], b[10001];
long long aa, bb;

int main() {
	cin.tie(NULL); cout.tie(NULL);
	ios::sync_with_stdio(false);
	
	cin >> N;
	for (int i = 1; i <= N; ++i) {
		cin >> a[i];
	}
	for (int i = 1; i <= N; ++i) {
		cin >> b[i];
	}
	
	for (int i = 1; i <= N; ++i) {
		if (a[i] > b[i]) {//1이 필요한 개수
			bb += (a[i] - b[i]);
		}
		else if (b[i] > a[i]){//2가 필요한 개수
			aa += (b[i] - a[i]) / 2;
		}
	}

	if (bb <= aa) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <vector>
 
int main() {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  std::cin >> n >> m;
  double sum = 0;
  std::vector<int> v(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> v[i];
    sum += v[i];
  }
  double bar = sum / 4 / m;
  int c = 0;
  for (int i = 0; i < n; ++i) {
    if (v[i] >= bar) ++c;
  }
  std::cout << ((c >= m ) ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=2000+10;
int s[maxn][maxn],sum[maxn][maxn],num[maxn][maxn];
int i,j,k,l,t,n,m,q,x,y,u,v,ans;
char get(){
	char ch=getchar();
	while (ch!='1'&&ch!='0') ch=getchar();
	return ch;
}
int main(){
	scanf("%d%d%d",&n,&m,&q);
	fo(i,1,n)
		fo(j,1,m)
			s[i][j]=get()-'0';
	fo(i,1,n)
		fo(j,1,m){
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
			if (j>1) sum[i][j]+=(s[i][j]&&s[i][j-1]);
			num[i][j]=num[i-1][j]+num[i][j-1]-num[i-1][j-1];
			if (i>1) num[i][j]+=(s[i][j]&&s[i-1][j]);
		}
	fo(i,1,n)
		fo(j,1,m)
			s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
	while (q--){
		scanf("%d%d%d%d",&x,&y,&u,&v);
		ans=s[u][v]-s[x-1][v]-s[u][y-1]+s[x-1][y-1];
		y++;
		t=sum[u][v]-sum[x-1][v]-sum[u][y-1]+sum[x-1][y-1];
		ans-=t;
		y--;
		x++;
		t=num[u][v]-num[x-1][v]-num[u][y-1]+num[x-1][y-1];
		ans-=t;
		x--;
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 49024
# -*- coding: utf-8 -*-


def check_numbers(cargo_weight_list, number_of_all_cargo, number_of_tracks, maximum_weight):
    """check the numbers that are loadable in tracks
    
    Args:
        cargo_weight_list: cargo weight list
        number_of_tracks: the number of tracks
        
    Returns:
        the number of cargos that are loadable in tracks
    """
    counter = 0
    number_of_loaded_cargo = 0

    while counter < number_of_tracks:
        current_track_weight = 0

        while current_track_weight + cargo_weight_list[number_of_loaded_cargo] <= maximum_weight:
            current_track_weight += cargo_weight_list[number_of_loaded_cargo]
            number_of_loaded_cargo += 1
            if number_of_loaded_cargo == number_of_all_cargo:
                return number_of_all_cargo

        counter += 1

    return number_of_loaded_cargo


def find_the_minimum_of_maximum_weihgt(cargo_weight_list, number_of_all_cargo, number_of_tracks):
    """find the minimum of maximum weight s.t all of the cargos can be loaded into tracks.
    (binary search is used. the number of loadable cargos monotonicaly increases as the maximum weight increases)


    Args:
        cargo_weight_list: cargo weight list
        numbef of all cargo: the number of all cargos
        number of tracks: the number of tracks

    Returns:
        minumim number of maximum track weight that are needed to load all of the cargos
    """
    left = max(cargo_weight_list)
    right = sum(cargo_weight_list)
    while (right - left) > 0:
        middle = (right + left) / 2
        the_number_of_loadable_cagos = check_numbers(cargo_weight_list, number_of_all_cargo, number_of_tracks, middle)
        if the_number_of_loadable_cagos >= number_of_all_cargo:
            right = middle
        else:
            left = middle + 1

    return right

def main():
    number_of_all_cargo, number_of_tracks = [int(x) for x in raw_input().split(' ')]
    cargo_weight_list = [int(raw_input()) for _ in xrange(number_of_all_cargo)]
    
    print find_the_minimum_of_maximum_weihgt(cargo_weight_list, number_of_all_cargo, number_of_tracks)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9448
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define clr(a) memset(a,0,sizeof(a))
using namespace std;
typedef long long ll;
const int N=1e5+3;
int p[N],dist[N];
vector<int> g[N];

void dfs(int u,int pa,int f)
{
  p[u]=pa;
  for(auto&v:g[u])
    if(v!=pa)
    dist[v]=dist[u]+1,dfs(v,u,f);
  	else if(v!=pa&&v==f)
    {
      dist[v]=dist[u]+1;
      p[v]=u;
      break;
    }
}
int cnt;
void dfs2(int u,int pa)
{
  cnt++;
  for(auto&v:g[u])
    if(v!=pa)
    dfs2(v,u);
}

int main()
{
	int i,n,u,v;
  	cin>>n;
    FOR(i,1,n-1)
    {
      cin>>u>>v;
      g[u].pb(v);
      g[v].pb(u);
    }
  dfs(n,n,1);
  i=1;
  int flag=0;
  vector<int>a;
  while(p[i]!=i)
  {
  	flag=1;
  	a.pb(i);
  	i=p[i];
  }
  if(flag)
  a.pb(i);
  //for(auto&k:a)
  //cout<<k<<" ";cout<<endl;
  int slow,nn=a.size(),prev;
  
  if(a.size()%2==0)
  slow=a[nn/2],prev=((nn/2-1>-1)?a[nn/2-1]:-1);
  else
  slow=a[nn/2+1],prev=a[nn/2];
  
  //cout<<endl<<nn<<":"<<slow<<endl;
  dfs2(slow,prev);
 // cout<<cnt<<" "<<(n-cnt)<<endl;
  if(cnt>=(n-cnt))
    cout<<"Snuke";
  else cout<<"Fennec";
    
}

Measured memory_bytes: 13436
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 入力
		int N = sc.nextInt();
		int A[] = new int[N];
		int x[][] = new int[N][N];
		int y[][] = new int[N][N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			for (int j = 0; j < A[i]; j++) {
				x[i][j] = sc.nextInt();
				y[i][j] = sc.nextInt();
			}
		}
		sc.close();

		// bit全探索
		// 誰が正直者で誰が不親切なのかを完全に決め打ちすると、
		// 全員の証言が整合しているかどうかを簡単に確認できる
		int ans = 0;
		for (int bit = 1; bit < (1 << N); bit++) {
			boolean flg = true;
			for (int i = 0; i < N; i++) {
				// 不親切な人の証言は見ない
				if ((bit & (1 << i)) == 0) {
					continue;
				}
				// 正直な人の証言
				for (int j = 0; j < A[i]; j++) {
					// 値と証言が一致しなかった場合にflgをfalseにする
					if ((((bit >> x[i][j] - 1) & 1) ^ y[i][j]) == 1) {
						flg = false;
					}
				}
			}

			// 全部の証言がOKだった場合
			if (flg) {
				int cnt = 0;
				for (int j = 0; j < N; j++) {
					if ((bit >> j) % 2 == 1) {
						cnt++;
						ans = Math.max(ans, cnt);
					}
				}
			}
		}
		System.out.println(ans);
	}
}


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

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

    ll n, k;
    cin >> n >> k;
    cout << min(n%k, k-n%k);

	return 0;
}


Measured memory_bytes: 256
void main()
{
    long n, t;
    rdVals(n, t);
    long[] a = rdRow;

    long total;
    long time;
    foreach (x; a)
    {
        if (x < time)
        {
            long diff = t - time + x;
            total += diff;
            time += diff;
        }
        else
        {
            total += t;
            time = x + t;
        }
    }

    total.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

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.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 11608
#include "bits/stdc++.h"
using namespace std;

//wierd debugging stuff
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << "\n" ; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//end of weird debugging stuff
using ll= long long;
using ld = long double;
using vi = vector<int> ;
using ii = pair<int,int>;
using vll = vector<ll> ;
using vvi = vector<vi>;
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
 
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define fo(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define foe(i,x) for(auto& i: x)
#define ar array
#define pb push_back
#define vt vector
#define F first
#define S second

template<class T> bool umin(T& a,const T& b){return b<a?a=b,1:0;}
template<class T> bool umax(T& a,const T& b){return b>a?a=b,1:0;}

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {cin>>x;}
void read(double& d) {string t;read(t);	d=stod(t);}
void read(long double& d) {	string t;read(t);d=stold(t);}
template<class H, class... T> void read(H& h, T&... t) {read(h);read(t...);}
template<class A> void read(vt<A>& x) {	foe(a, x)read(a);}
int nxt(){int a;read(a);return a;}   // iota(all(v),0); genrate(all(v),nxt);

// no change 
const ll MOD = 1e9+7;  
const int mx = 1e5;
int n,m;
void Titan(){

	read(n);
	n-=400;

	n/=200;
	cout << 8-n << endl;


}

	

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T = 1;
	//cin >> T;		//cmt if one test case
    fo(T){
		//cout << "Case #" << i+1 << ": " ;
		Titan();
	}
}
/*///////////////////////////////////////////////////////////
Important Notes : 
* check long long 
* check base cases
* do not loose Hope
* if case fails on 2nd test case maybe some cases are missing check them
* do not sit idle
* try to do it using pen/paper.
* in recurance first build a base case then preprocessig(means the the tasks to be perform everyturn the recrursice calls the then post processing which you do after hitting the base case or the last possibble values of recursrion"
*/


Measured memory_bytes: 3624
//
// Created by yamunaku on 2019/12/29.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    ll n;
    cin >> n;
    ll x,t=0;
    rep(i,n){
        cin >> x;
        t+=x;
    }
    cout << t-n*(n+1)/2 << endl;
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int N;
    cin >> N;
    string S, rgb = "RGB";
    cin >> S;
    vector<int> iRGB(3, 0);
    rep(i,N) {
        if (S[i] == 'R') {
            iRGB[0]++;
        }
        else if (S[i] == 'G') {
            iRGB[1]++;
        }
        else if (S[i] == 'B') {
            iRGB[2]++;
        }
    }

    ll cnt = ll(iRGB[0]) * ll(iRGB[1]) * ll(iRGB[2]);
    rep(i, N) repSE(j, i+1, N) {
        if (S[j] != S[i]) {
            int k = 2 * j - i;
            if (k < N && S[k] != S[i] && S[k] != S[j]) cnt--;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

int main() {
  int h, w;
  std::cin >> h >> w;
  std::vector<std::string> s(h);
  for (int i = 0; i < h; i++) {
    std::cin >> s[i];
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        if (i == 0) {
          if (j == 0 && s[i + 1][j] == '.' && s[i][j + 1] == '.') {
            std::cout << "No" << "\n";
            return 0;
          } else if (j == w - 1 && s[i + 1][j] == '.' && s[i][j - 1] == '.') {
            std::cout << "No" << "\n";
            return 0;
          }
        } else if (i == h - 1) {
          if (j == 0 && s[i - 1][j] == '.' && s[i][j + 1] == '.') {
            std::cout << "No" << "\n";
            return 0;
          } else if (j == w - 1 && s[i - 1][j] == '.' && s[i][j - 1] == '.') {
            std::cout << "No" << "\n";
            return 0;
          }
        } else if (j == 0) {
          if (s[i][j + 1] == '.' && s[i - 1][j] == '.' && s[i + 1][j] == '.') {
            std::cout << "No" << "\n";
            return 0;
          }
        } else if (j == w - 1) {
          if (s[i][j - 1] == '.' && s[i - 1][j] == '.' && s[i + 1][j] == '.') {
            std::cout << "No" << "\n";
            return 0;
          }
        } else {
          if (s[i][j + 1] == '.' && s[i][j - 1] == '.' && s[i - 1][j] == '.' && s[i + 1][j] == '.') {
            std::cout << "No" << "\n";
            return 0;
          }
        }
      }
    }
  }
  std::cout << "Yes" << "\n";
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# 標準入力を取得
K = int(input())

# 求解処理
ans = -1
remainder = 7 % K
for i in range(1, 9000000):
    if remainder == 0:
        ans = i
        break
    remainder = (10 * remainder + 7) % K

# 結果出力
print(ans)


Measured memory_bytes: 9156
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    int a,b,k;
    while(~scanf("%d %d %d",&a,&b,&k))
    {
        if(b-a+1<=2*k)
        {
            for(int i=a;i<=b;i++)
                printf("%d\n",i);
        }
        else
        {
            for(int i=a;i<=b;i++)
            {
                if(i-a<k)
                    printf("%d\n",i);
                else if(b-i<k)
                    printf("%d\n",i);
            }
        }
    }
    return 0;
}


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

class Program
{
    static void Main()
    {
        string[] inp = Console.ReadLine().Split();
        long w, h, x, y;
        w = long.Parse(inp[0]);
        h = long.Parse(inp[1]);
        x = long.Parse(inp[2]);
        y = long.Parse(inp[3]);
        var f = x * 2 == w && y * 2 == h;
        Console.WriteLine("{0} {1}",w * h / 2.0,f ? 1 : 0);

    }
}

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

int main() {
	int a, b, ans;
	char op;
	while(1){
	cin >> a >> op >> b;
	switch(op){
		case '+':
			ans = a+b;
			break;
		case '-':
			ans = a - b;
			break;
		case '*':
			ans = a * b;
			break;
		case '/':
			ans = a / b;
			break;
		case '?':
			return 0;
	}
	cout << ans << endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>

int linearsearch(int A[], int n, int key)
{
	int i=0;
	
	A[n] = key;
	
	while(A[i] != key){

			i++;
	}
	
	if(i==n)
	{
		return 0;
	}
	else
	{
		return 1;
	}
	
}

int main(void)
{

int n, q, count;



count = 0;

scanf("%d", &n);

int S[n];

for(int i=0; i<n; i++)
{
	scanf("%d", &S[i]);
}

scanf("%d", &q);

int T[q];
	
for(int i=0; i<q; i++)
{
	scanf("%d", &T[i]);
}

for(int i=0; i<q; i++)
{
	if(linearsearch(S,n,T[i])==1)
	{
		count++;
	}
}
	
	printf("%d\n", count);


return 0;

}


Measured memory_bytes: 2144
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string ss,tt;
  cin >> ss >> tt;
  int n = ss.size();
  auto s = [&](int i){ return ss[i]-'a'; };
  auto t = [&](int i){ return tt[i]-'a'; };

  vector<int> vs[26],vt[26];
  rep(i,n) vs[s(i)].push_back(i);
  rep(i,n) vt[t(i)].push_back(i);

  rep(si,26){
    if(vs[si].empty()) continue;
    int ti = t(vs[si][0]);
    for(int i:vs[si]){
      if(t(i)!=ti){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  rep(ti,26){
    if(vt[ti].empty()) continue;
    int si = s(vt[ti][0]);
    for(int i:vt[ti]){
      if(s(i)!=si){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 2824
#include "bits/stdc++.h"
using namespace std;

int main() {
	int  X, A , B;
	cin >> X >> A >> B;
	if (A>=B) {
		cout << "delicious"<<endl;
	}
	else if((B-A)<=X){
		cout << "safe" << endl;
	}
	else {
		cout << "dangerous" << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
// #include <unordered_map>
// #include <unordered_set>
#include <utility>
#include <vector>

#define pb push_back
#define mp make_pair

#ifdef ONLINE_JUDGE
#define link renamelink
#define next renamenext
#define prev renameprev
#endif

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef long double ld;

inline void EnableFileIO(const string& fileName, bool local = 0) {
  if (fileName.empty()) return;
  if (local) {
    freopen((fileName + ".in").c_str(), "r", stdin);
    freopen((fileName + ".out").c_str(), "w", stdout);
    return;
  }
#ifdef ONLINE_JUDGE
  freopen((fileName + ".in").c_str(), "r", stdin);
  freopen((fileName + ".out").c_str(), "w", stdout);
#endif
}

const int INF = (1 << 30) - 1;
const LL LINF = (1LL << 61) - 1;
const double EPS = 1e-10, PI = acos(-1);
const int N = 500, P = 1000;

typedef vector<LL> tile;

int n;
tile t[N];
LL hsv[N];
map<LL, LL> c, rc;

tile rotate(const tile& t) {
  tile res(4);
  for (int i = 0; i < 4; i++) res[i] = t[(i + 1) & 3];
  return res;
}
LL gethash(const tile& t) {
  return (t[0] * P * P * P + t[1] * P * P + t[2] * P + t[3]);
}
LL calchash(tile t) {
  LL res = gethash(t);
  for (int i = 0; i < 4; i++, t = rotate(t)) res = min(res, gethash(t));
  return res;
}
LL getrot(const tile& t) {
  tile p = t;
  LL res = 0;
  for (int i = 0; i < 4; i++, p = rotate(p)) res += (p == t);
  return res;
}

int main() {
  // srand((int)time(0));
  // printf("Hello, world!\n");
  // EnableFileIO("");

  cin >> n;
  for (int i = 0; i < n; i++) {
    t[i].resize(4);
    for (int j = 0; j < 4; j++) cin >> t[i][j];
    c[hsv[i] = calchash(t[i])]++;
    rc[hsv[i]] = getrot(t[i]);
  }

  LL ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      c[hsv[i]]--, c[hsv[j]]--;
      for (int k = 0; k < 4; k++) {
        map<LL, LL> m;
        m[calchash({t[i][1], t[i][0], t[j][1], t[j][0]})]++;
        m[calchash({t[i][0], t[i][3], t[j][2], t[j][1]})]++;
        m[calchash({t[i][3], t[i][2], t[j][3], t[j][2]})]++;
        m[calchash({t[i][2], t[i][1], t[j][0], t[j][3]})]++;
        LL tmp = 1;
        for (pair<LL, LL> it : m) {
          for (int i = 0; i < it.second; i++)
            tmp *= (c[it.first] - i) * rc[it.first];
        }
        ans += tmp;
        t[j] = rotate(t[j]);
      }
      c[hsv[i]]++, c[hsv[j]]++;
    }
  }
  cout << ans / 3 << endl;
  return 0;
}


Measured memory_bytes: 159872
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int q = sc.nextInt();
        int cnt = 1;
        char k = 0;
        char l = 0;
        int a2 = 0;
        int b2 = 0;
        List<Character> str = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            str.add(s.charAt(i));
        }
        while (cnt <= q) {
            String order = sc.next();
            int a = sc.nextInt();
            int b = sc.nextInt();
            a2 = a;
            b2 = b;
            if (order.equals("print")) {
                for (int i = 0; i <= b - a; i++) {
                    System.out.print(str.get(i + a));
                }
                System.out.println("");
            } else if (order.equals("reverse")) {

                for (int i = 0; i < (b - a) / 2 + ((b - a) % 2); i++) {
                    k = str.get(a2);
                    l = str.get(b2);
                    str.set(a2, l);
                    str.set(b2, k);
                    a2++;
                    b2--;
                }
            } else {
                String p = sc.next();
                for (int i = 0; i <= b - a; i++) {
                    str.set(a2, p.charAt(i));
                    a2++;
                }
            }
            cnt++;
        }
    }
}

Measured memory_bytes: 33724
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//文字列を入力
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		String p=sc.next();

		//文字列をカウント
		int n=s.length();
		String x;
		String y;
		//文字列を加工
		for(int i=0;i<=n-1;i++) {
			if(s.indexOf(p)!=-1) {
				System.out.println("Yes");
				break;
			}
			if(i==n-1) {
				System.out.println("No");
			}
			x=s.substring(0,n-1);
			y=s.substring(n-1,n);
			s=y+x;
		}
	}

}



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

using lint = long long;

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

    int n, a, b;
    while(cin >> n >> a >> b){
        if(a + b - 1 > n || (lint)a * b < (lint)n){
            cout << -1 << '\n';
            continue;
        }

        set<int> st;
        for(int i = 1 ; i <= n ; ++i){
            st.insert(i);
        }

        vector<int> ans;
        for(int i = 0 ; i < a ; ++i){
            ans.emplace_back(n - a + i + 1);
            st.erase(ans.back());
        }

        for(int i = a ; i + b - 1 < n ; i += b - 1){
            for(int j = i ; j < i + b - 1 ; ++j){
                ans.emplace_back((i - a) + (b - 1) - (j - i));
                st.erase(ans.back());
            }
        }

        for(auto it = st.rbegin() ; it != st.rend() ; ++it){
            ans.emplace_back(*it);
        }

        for(int i = 0 ; i < n ; ++i){
            if(i) cout << ' ';
            cout << ans[i];
        }
        cout << '\n';
    }

    cout << flush;

    return 0;
}

Measured memory_bytes: 14464
use std::io::*;
use std::str::FromStr;

fn parse_line<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn parse_pair<T: FromStr, U: FromStr>() -> (T, U) {
    let line = parse_line::<String>();
    let mut iter = line.split_whitespace();
    (
        iter.next().unwrap().parse().ok().unwrap(),
        iter.next().unwrap().parse().ok().unwrap(),
    )
}

fn println<T: ToString>(s: T) {
    println!("{}", s.to_string());
}

// ------------------------------------------------------------------------

fn main() {
    let (n, k) = parse_pair::<usize, usize>();

    if k == 1 {
        println(0);
        return;
    }

    println(n - k);
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

const ll MOD = 1e9 + 7;

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

  ll N;
  cin >> N;
  vector<int> back(1001);

  for(int n = 1; n <= N; n++){

    int tmp = n;
    for(int i = 2; i * i <= n; i++){
      while(tmp % i == 0 && tmp > 0){
        tmp = tmp / i;
        back[i]++;
      }
    }
    if(tmp > 1){
      back[tmp]++;
    }
  }

  ll ans = 1;
  for(int i = 1; i <= 1000; i++){
    if(back[i] >= 1){
      ans = (ans * (back[i] + 1)) % MOD;
    }
  }

  cout << ans << endl;


  return 0;
}


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

int main() {
  int N; cin >> N;
  int A[2][N];
  rep(i, 2) {
    rep(j, N) {
      cin >> A[i][j];
    }
  }
  int ans = 0;
  rep(i, N) {
    int cnt = 0;
    rep(j, i+1) {
      cnt += A[0][j];
    }
    rep2(j, i, N) {
      cnt += A[1][j];
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	N := ReadInt()

	h := make(map[int]bool)
	for i := 0; i < N; i++ {
		A := ReadInt()
		if h[A] {
			delete(h, A)
		} else {
			h[A] = true
		}
	}

	fmt.Println(len(h))
}

var sc = bufio.NewScanner(os.Stdin)

func init()        { sc.Buffer(make([]byte, 256), 1e9); sc.Split(bufio.ScanWords) }
func Read() string { sc.Scan(); return sc.Text() }

func ReadInt() int {
	v, e := strconv.Atoi(Read())
	if e != nil {
		panic(e.Error())
	}
	return v
}


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

int main(){
    int n;
    cin >> n;
    long i[1000000];
    int j;
    long min = 1000000;
    long max = -1000000;
    long sum = 0;
    for(j = 0; j < n; j++){
        cin >> i[j];
        if(min > i[j])
            min = i[j];
        if(max < i[j])
            max = i[j];
        sum += i[j];
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;
}
    

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

int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;
  
  if ( U == S ) {
    A = A-1;
  }
  else {
    B = B-1; 
  }
    
  cout << A << " " << B << endl;
 
   
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

int n,m,t,p;

void solve(){
    int h=m,w=n;
    int g[h][w];
    rep(i,h)rep(j,w) g[i][j]=1;
    rep(_,t){
        int d,c;cin>>d>>c;
        int new_g[h][w]={};
        if(d==1){
            rep(i,h){
                for(int j=0;j<c;j++){
                    new_g[i][j]=g[i][c-1-j]+(c+j<w?g[i][c+j]:0);
                }
                for(int j=c;j<w-c;j++){
                    new_g[i][j]=(j+c<w?g[i][j+c]:0);
                }
            }
        }
        else{
            // c=h-c;
            rep(j,w){
                for(int i=0;i<c;i++){
                    new_g[i][j]=g[c-1-i][j]+(c+i<h?g[c+i][j]:0);
                }
                for(int i=c;i<h-c;i++){
                    new_g[i][j]=(i+c<h?g[i+c][j]:0);
                }
            }
        }
        rep(i,h){
            rep(j,w){
                g[i][j]=new_g[i][j];
            }
        }
    }

    // cout<<"debug=-begin"<<endl;
    // rep(i,h){
    //     rep(j,w){
    //         cout<<g[i][j]<<"  ";
    //     }cout<<endl;
    // }
    // cout<<"debug---end"<<endl;

    // int geta=0;
    // while(g[h-1-geta][0]==0) geta++;
    rep(_,p){
        int x,y;cin>>x>>y;
        cout<<g[y][x]<<endl;
    }
    // cout<<n<<m<<t<<p<<endl;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    while(true){
        cin>>n>>m>>t>>p;
        solve();
        if(n==0 and m==0 and t==0 and p==0) return 0;
    }

    return 0;
}



Measured memory_bytes: 3148
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int getsum(int n){
    int ret=0;
    for(int i =0;n!=0 ;i++){
        ret+= n%10;
        n=n/10;
    }
    return ret;
}
int main(void){
    // Your code here!
    int N;
    int a,b;
    cin>>N >> a >>b;
    int count=0;
    for (int i=1;i<=N;i++){
        
        if(a<= getsum(i) && getsum(i)<=b) count+= i;
    }
    cout<<count;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ld,ld>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    string S; cin>>S;
    string T=S;
    rep(i,N){
        T[i]=S[i];
    }
    rep(i,N){
        T[i+N]=S[N*2-i-1];
    }
    unordered_map<string,P> mp;
    rep(i,1<<N){
        string x,y;
        rep(j,N){
            if(i>>j&1) x+=T[j];
            else y+=T[j];
        }
        x+="#";
        x+=y;
        mp[x].first++;
    }
    rep(i,1<<N){
        string x,y;
        rep(j,N){
            if(i>>j&1) x+=T[j+N];
            else y+=T[j+N];
        }
        x+="#";
        x+=y;
        mp[x].second++;
    }
    ll ans=0;
    for(auto pe: mp){
        ans+=pe.second.first*pe.second.second;
    }
    cout<< ans <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 100084
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

int main(void){
    int A,B,C,D,E,F;
    scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F);

    int ans1=A*100;
    int ans2=0;
    double cmax=0;
    for(int i=0;i<=30;i++){
        for(int j=0;j<=30;j++){
            //水の量
            int W=((A*i)+(B*j))*100;
            //もし水が0gならスキップ、重量オーバーならbreakで次のforループに
            if(W==0) continue;
            if(W>F) break;

            int limit_sugar=MIN((A*i+B*j)*E,F-W);
            for(int k=0;k<=(limit_sugar)/C;k++){
                //砂糖の量
                int S=C*k+D*((limit_sugar-C*k)/D);
                double c=100.0*S/(W+S);
                
                if(c>cmax){
                    cmax=c;
                    ans1=W+S;
                    ans2=S;
                }
            }
        }
    }
    printf("%d %d\n",ans1,ans2);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define sor(a, l, r) sort(a + l, a + r + 1);
#define reve(a, l, r) reverse(a + l, a + r + 1)
using namespace std;
typedef long long LL;
const int N = 205;
const int MAXN = 100005;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

namespace ModCalculator {
	const int MOD = 1e9 + 7;
	inline void Inc(int &x, int y) {
		x += y; if (x >= MOD) x -= MOD;
	}
	inline void Dec(int &x, int y) {
		x -= y; if (x < 0) x += MOD;
	}
	inline int Add(int x, int y) {
		Inc(x, y); return x;
	}
	inline int Sub(int x, int y) {
		Dec(x, y); return x;
	}
	inline int Mul(int x, int y) {
		return 1LL * x * y % MOD;
	}
}
using namespace ModCalculator;

int n, X, a[N];
int dp[2][MAXN];

void init() {
	read(n); read(X);
	for (int i = 1; i <= n; ++i) {
		read(a[i]);
	}
	sor(a, 1, n);
}

void solve() {
	int pre = 0, cur = 1;
	dp[pre][X] = 1;
	int ans = 0;
	for (int i = n; i >= 1; --i) {
		mset(dp[cur], 0);
		for (int j = 0; j <= X; ++j) {
			Inc(dp[cur][j], Mul(dp[pre][j], i - 1));
			Inc(dp[cur][j % a[i]], dp[pre][j]);
		}
		swap(pre, cur);
	}
	for (int i = 1; i <= X; ++i) {
		Inc(ans, Mul(i, dp[pre][i]));
	}
	printf("%d\n", ans);
}

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


Measured memory_bytes: 1532
import java.util.Scanner;
import java.util.Arrays;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        if(Math.abs(a-c)<=d){
            System.out.println("Yes");
        }else{
            if(Math.abs(a-b)<=d&&Math.abs(b-c)<=d){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }
    }

}


Measured memory_bytes: 22484
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long int lli;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	int mx = -1, res = 0;
	for(int i=0; i<n; i++){
		int m;
		cin >> m;
		if(m >= mx){
			res++;
			mx = m;
		}
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 256
/*
   TASK: nocows
   LANG: C++14
 */

#include "bits/stdc++.h"
typedef long long ll;
typedef long double ld;

using namespace std;
#define finish(x) return cout << x, 0;

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

const string USCAO_TAG = "nocows";
void usaco() { setIn(USCAO_TAG + ".in"); setOut(USCAO_TAG + ".out"); }
/*
template<typename... Args>
void print(Args... args) {
	((std::cout << args << " "), ...);
}
*/
ll dp[100001][3];

int a[100001];
int b[100001];
int c[100001];

int main() {
	//usaco();
	#ifndef ONLINE_JUDGE
	//setIn("in.txt");
	#endif

	int n;
	cin >> n;

	for(int i = 0; i < n; i++)
		cin >> a[i] >> b[i] >> c[i];

	dp[n - 1][0] = a[n - 1];
	dp[n - 1][1] = b[n - 1];
	dp[n - 1][2] = c[n - 1];

	for(int i = n - 2; i >= 0; i--){
		dp[i][0] += max(dp[i + 1][1], dp[i + 1][2]) + a[i];
		dp[i][1] += max(dp[i + 1][0], dp[i + 1][2]) + b[i];
		dp[i][2] += max(dp[i + 1][1], dp[i + 1][0]) + c[i];
	}

	cout << max(dp[0][1], max(dp[0][2], dp[0][0]));
}


Measured memory_bytes: 3712
n,k=[int(j) for j in input().split()]
p=[int(j) for j in input().split()]
from itertools import accumulate
l=[0]+list(accumulate(p))
t=0
a,b=0,0
for i in range(n-k+1):
    if t<l[i+k]-l[i]:
        t=l[i+k]-l[i]
        a,b=i+k,i
ans=0
for i in range(b,a):
    j=p[i]
    ans+=j*(j+1)//2/j
    
print(ans)

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

typedef long long ll;
const int maxn=100005;
int num[maxn];

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	int n,k;
	while(cin>>n>>k){
		int pos=-1;
		for(int i=0;i<n;i++){
			cin>>num[i];
			if(num[i]==1) pos=i;
		}
		int ans=0;
		n-=k;
		ans++;
		while(n>0){
			n-=k-1;
			ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main(){
    string s;
    cin >> s;

    int n = s.length();
    int cou = 0;
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(cou == 0){
            if(s[i] == 'S'){
                cou++;
            }
        }else{
            if(s[i] == 'S'){
                cou++;
            }else{
                ans += 2;
                cou--;
            }
        }
    }

    cout << n - ans << endl;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    int n;
    scanf("%d", &n);
    lint a[n];
    int cntz = 0, cntm = 0;
    rep(i, n){
        scanf("%lld", &a[i]);
        if(a[i] == 0) ++cntz;
        else if(a[i] < 0) ++cntm;
    }
    lint ans = 0;
    rep(i, n) ans += abs(a[i]);
    if(cntm % 2 == 1 && cntz == 0){
        lint tmp = mod;
        rep(i, n) chmin(tmp, abs(a[i]));
        ans -= 2 * tmp;
    }
    printf("%lld\n", ans);
}

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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
  return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
  return a / gcd(a, b) * b;
}

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

int main()
{
  string s;
  ci >> s;

  int mn = 10000;
  for(int i = 0; i < s.size() - 2; i++) {

    int n = 0;
    n += (s[i    ] - '0') * 100;
    n += (s[i + 1] - '0') * 10;
    n += (s[i + 2] - '0');

    mn = min(mn, abs(n - 753));
  }

  co << mn << en;
  
  return 0;
}


Measured memory_bytes: 256
import sys

#+++++

def nn(val, count, aal):
	#pa((val,count,aal))
	if aal[val] >= 0:
		return aal[val]
	
	ll=[1]
	i=1
	while 6**i <= val:
		ll.append(6**i)
		i+=1
	
	i=1
	while 9 ** i <= val:
		ll.append(9**i)
		i+=1
	
	ll=ll[::-1]
	min_v = val
	for l in ll:
		temp = nn(val-l, count+1,aal)
		min_v = min(min_v,temp)
	
	aal[val]=min_v+1
	return min_v+1
	
	
		
def main():
	N = int(input())
	al=[-1]*(N+1)
	al[0:6]=[0,1,2,3,4,5]
	#print(al[0:10])
	ans=nn(N,0,al)

	print(ans)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

int main() {
    int a;
    int b;
    while (cin >> a >> b) {
        int digit = 1;
        int sum = a + b;
        while (true) {
            if (sum / 10 != 0) {
                digit += 1;
                sum /= 10;
            }
 
            else if (sum / 10 == 0 ) {
                break;
            }
        }
        cout << digit << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


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


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]


K = int(input())
sum = 0
tmp = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            tmp = math.gcd(i, j)
            sum += math.gcd(tmp, k)
print(sum)


Measured memory_bytes: 75012
#include <bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vp = vector<P>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvb = vector<vb>;
const int INF = 1e9;
const int MOD = 1e9+7;


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll N; cin >> N;
    vl A(N); REP(i, N) cin >> A[i];
    ll countMinus = 0;
    vl nums;
    ll abssum = 0;
    REP(i, N) abssum += abs(A[i]);
    REP(i, N)
    {
        nums.push_back(abs(A[i]));
        if(A[i] < 0) countMinus++;
    }
    if(countMinus % 2 == 0) cout << abssum << endl;
    else
    {
        sort(ALL(nums));
        cout << abssum - 2*nums[0] << endl;
    }
}

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

int main(void)
{
    map<string, bool> mp;
    int n;
    cin >> n;
    string s;
    for (int i = 0; i < n; i++)
    {
      cin >> s;
      mp[s] = true;
    }
    cout << mp.size() << endl;
}

Measured memory_bytes: 19228
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    string s;
    cin >> s;
    int n = s.length();
    for(int i = 0; i + 1 < n; ++i){
        if(s[i] == s[i + 1]){
            cout << i + 1 << ' ' << i + 2 << endl;
            return 0;
        }
    }
    for(int i = 0; i + 2 < n; ++i){
        if(s[i] == s[i + 2]){
            cout << i + 1 << ' ' << i + 3 << endl;
            return 0;
        }
    }
    cout << -1 << ' ' << -1 << endl;
}

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

int main(){
    int h,w,n;
    cin>>h>>w>>n;
    map<pair<int,int>,int> mp;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        --a,--b;
        for(int j=max(0,a-2);j<=min(a,h-3);j++){
            for(int k=max(0,b-2);k<=min(b,w-3);k++){
                mp[{j,k}]++;
            }
        }
    }
    ll cnt[11]={};
    for(auto p:mp){
        cnt[p.second]++;
    }
    cnt[0]=(ll)(h-2)*(w-2)-mp.size();
    for(int i=0;i<=9;i++){
        cout<<cnt[i]<<endl;
    }
}


Measured memory_bytes: 56448