akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int main(void)
{
	char day[7][4] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	char s[4];

	scanf("%s", s);

	if (strcmp(s, day[0]) == 0)
	{
		printf("7\n");
	}
	else if (strcmp(s, day[1]) == 0)
	{
		printf("6\n");
	}
	else if (strcmp(s, day[2]) == 0)
	{
		printf("5\n");
	}
	else if (strcmp(s, day[3]) == 0)
	{
		printf("4\n");
	}
	else if (strcmp(s, day[4]) == 0)
	{
		printf("3\n");
	}
	else if (strcmp(s, day[5]) == 0)
	{
		printf("2\n");
	}
	else if (strcmp(s, day[6]) == 0)
	{
		printf("1\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	if(s.find('7') != string::npos) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b, c, x, d = 0;
    cin >> a >> b >> c >> x;
    x /= 50;
    for (int i = 0; i <= min(a, x / 10); i++)
        for (int j = 0; j <= min(b, (x - i * 10) / 2); j++)
            if (x - 10 * i - j * 2 <= c) d++;
    cout << d;
}

Measured memory_bytes: 3620
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,m,n,s,a[200040];
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout<<fixed<<setprecision(12);
	cin>>n;
	for(;i++<n;)
	{
		cin>>k;
		m=max(m,k);
		s+=m-k;
	}
	cout<<s;
}

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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vp vector<pair<int, int>>
#define vll vector<long long>
#define inf 1000000100
#define infll 1LL << 50

int main()
{
    int sum = 0;
    for(int i = 0; i < 5; ++i)
    {
        int x;
        cin >> x;
        sum += x;
    }
    cout << 15 - sum << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;

int n, m, point1[1001], sum, ans;
vector<int> point2;

int solve(int start, int end, int border){
    int mid;
    while(1){
        if((end + start) % 2){
            mid = (end + start) / 2 + 1;
        } else{
            mid = (end + start) / 2;
        }

        if(point2[mid] > border){
            end = mid;
        } else{
            start = mid;
        }

        if(end - start == 1){
            if(point2[end] < border){
                return point2[end];
            } else{
                return point2[start];
            }
        }
    }
}

int main(){
    while(cin >> n >> m && n && m){
        for(int i = 0; i < n; i++){
            cin >> point1[i];
        }
        for(int i = 0; i < n + 1; i++){
            for(int j = 0; j < n + 1; j++){
                point2.push_back(point1[i] + point1[j]);
            }
        }

        sort(point1, point1 + n + 1);
        sort(point2.begin(), point2.end());

        for(int i = 0; i < n + 1; i++){
            for(int j = 0; j < n + 1; j++){
                sum = point1[i] + point1[j];
                if(sum > m){
                    continue;
                }
                ans = max(ans, sum + solve(0, point2.size() - 1, m - sum));
            }
        }

        cout << ans << endl;

        memset(point1, 0, sizeof(point1));
        point2.clear();
        ans = 0;
    }

    return 0;
}

Measured memory_bytes: 5996
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int A, B, H, M;
    cin >> A >> B >> H >> M;

    const double PI = acos(-1);
    double x = (H + M / 60.0) / 12.0 * 2 * PI;
    double y = M / 60.0 * 2 * PI;
    double s = A * cos(x), t = A * sin(x);
    double u = B * cos(y), v = B * sin(y);
    write(hypot(s - u, t - v));
}

Measured memory_bytes: 4116
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h>  /*文字操作*/

#define rep(i, n) for(int  i = 0; i < (n); i++)
#define max(a,b) ((a>b)?a:b)
#define ABS(a) (((a)>(0))?a:-(a))

#define N 10000
void swap(int *a, int *b)
{
  int temp;
  temp = *a;*a = *b;*b = temp;
}

int main(void)
{
  int n;
  int p;
  int o=0;
  char buf;
  char s[N]={};
  scanf("%d", &n);
  scanf(" %s",&s );
  while (1) {
    if (s[o]=='\0') {
      break;
    }
    o++;
  }
  p = n;
  for (size_t i = 0; i < o; i++) {
     s[i]+=n;
     if (s[i]<'A' || s[i]>'Z') {
       p=n;
       s[i]-=n;
       p-=('Z'-s[i]);
       s[i]='A'+(p-1);
     }
  }

  printf("%s\n",s );
  return 0;
}


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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;

const int MOD = 1000000007, MX = 1e5 + 5;
int N, K, factKm1, factKm1inv;
ll fact[MX], factInv[MX];

ll inv(ll a, ll b) {
	return 1 < a ? b - inv(b % a, a) * b / a : 1;
}

ll xCkm1(int x) {
	ll ret = fact[x];
	ret = (ret * factInv[x - (K - 1)]) % MOD;
	ret = (ret * factInv[K - 1]) % MOD;
	return ret;
}

int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	cin >> N >> K;

	fact[0] = 1;
	factInv[0] = inv(1, MOD);

	for (int i = 1; i < MX; ++i) {
		fact[i] = (fact[i - 1] * i) % MOD;
		factInv[i] = inv(fact[i], MOD);
	}

	vi A(N + 1);

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

	sort(A.begin() + 1, A.end());

	ll ans = 0;

	for (int i = 1; i <= N; ++i) {
		if (i >= K) {
			ans = (ans + ((A[i] * xCkm1(i - 1)) % MOD)) % MOD;
		}
		if (i <= N - K + 1) {
			ans = (ans - ((A[i] * xCkm1(N - i)) % MOD) + MOD) % MOD;
		}
	}

	cout << ans << '\n';



	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


Measured memory_bytes: 2176
def gcd(a, b) :
    if a % b == 0 :
        return b
    else :
        return gcd(b, a % b)

while True :
    try :
        a, b = map(int, input().split())
    except EOFError :
        break
    
    a, b = max(a, b), min(a, b)
    x = gcd(a, b)
    print(x, a * b // x)


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
const int MAXN = 1e5 + 50;
vector<pi> edgeList;
int num, p[MAXN], grpsize[MAXN];
int par(int x) { return (p[x]==x)? x:p[x]=par(p[x]); }
bool isSameGroup(int a, int b) { return par(a) == par(b); }
void merge(int a, int b) {
    if (isSameGroup(a, b)) return;
    num -= grpsize[par(a)]*grpsize[par(b)];
    grpsize[par(b)] += grpsize[par(a)];
    grpsize[par(a)] = 0;
    p[par(a)] = par(b); //b as parent of par(a)
}
/* Initialize */


main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N, M; cin >> N >> M;
    for (int i = 0; i < MAXN; ++i) {
        p[i] = i;
        grpsize[i] = 1;
    }
    num = N*(N-1)/2;
    vector<int> ans;
    for (int i=0; i<M; i++){
        int a, b; cin >> a >> b;
        edgeList.emplace_back(a,b);
    }
    reverse(edgeList.begin(), edgeList.end());
    for (auto i:edgeList){
        ans.push_back(num);
        merge(i.first, i.second);
    }
    reverse(ans.begin(), ans.end());
    for (auto i:ans) cout << i << "\n";
}


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

using namespace std;
int main(){
    string s,T,u;
    cin>>s>>T;
    int x,y;
    cin>>x>>y;
    cin>>u;
    if (u==s){
        x--;
    } else if (u==T){
        y--;
    }
    cout<<x<<" "<<y;

    return 0;
}

Measured memory_bytes: 256
n,l = map(int,input().split())
d = list(range(n))
for i in range(n):
    d[i] = d[i] + l
if d[0] >= 0:
    print(sum(d[1:]))
elif d[n-1] <= 0:
    print(sum(d[:n-1]))
else:
    for i in range(n):
        if d[i] == 0:
            print(sum(d[:i]) + sum(d[(i+1):]))
            exit()

Measured memory_bytes: 3064
n = int(input())
a_inputs = list(map(int,input().split()))
len_bar = sum(a_inputs)

cum_bar = [0]*n
cum_bar[0]=a_inputs[0]
for i in range(1,n):
    cum_bar[i]=cum_bar[i-1]+a_inputs[i]

gap = float('inf')
for i in range(n-1):
    g = abs(len_bar-2*cum_bar[i])
    if g<gap:
        gap=g
print(gap)


Measured memory_bytes: 26024
require("fs").readFileSync("/dev/stdin","utf8").trim().split('\n').map(function(i){f=function(a,b){return b-a};a=[],c=i.split(",").sort(f);c.map(function(j){a[j]?a[j]++:a[j]=1});a.sort(f);l=a[0],n=a[1];console.log(l==4?"four card":l==3?(n==2?"full house":"three card"):l==2?(n==2?"two pair":"one pair"):4==c[0]-c[4]||(c[0]-c[3]==3&&+c[4]==1)?"straight":"null")})

Measured memory_bytes: 7908
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll x;
    cin >> x;
    int ans = 0;
    ans = (x / 500) * 1000;
    x = x % 500;
    ans = ans + (x / 5) * 5;
    cout << ans << endl;
    return 0;
}

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

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = k; i < n; i++){
        if(a[i-k] < a[i]) cout << "Yes" << endl;
        else{
            cout << "No" << endl;
        }
    }
}

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

int n , c[100100] , x ;

int main(){

cin>>n;
for(int i=0;i<n;i++){
    cin>>x;
    c[x]++;
}
int l =1 , r = 100000;

while( l < r ){

    if( c[l] <=1 ){
            l++;
    continue;
    }
    if( c[r] <=1 ){
            r--;
    continue;
    }
    c[l]--;
    c[r]--;
}

for(int i=1;i<=100000;i++)while( c[i] >= 2 )c[i]-=2;

int ans =0 ;
for(int i=1;i<=100000;i++)ans+=c[i];
cout<<ans<<endl;
return 0;
}


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

int main(){
    long long int N;
    cin >> N;
    string ans = "";
    
    while(N > 0){
        N -= 1;
        ans += (N%26) + 'a';
        N = N/26;
    }

    reverse(ans.begin(), ans.end());

    cout << ans << endl;
}

Measured memory_bytes: 3556
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
      int count = 0;
      int max = 0;
		int[] a = new int[n];
		for(int i=0; i<a.length; ++i){
			a[i] = scn.nextInt();
		}
      for(int i=0; i<a.length-1; ++i){
        if(a[i]>=a[i+1]){
          count = count+1;
          if(max<count){
            max = count;
          }
        }else{
          if(max<count){
            max = count;
          }
          count = 0;         
        }
      }
      System.out.println(max);
	}
}


Measured memory_bytes: 58712
#include <bits/stdc++.h>
#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() {
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i,N) cin >> h.at(i);
    int ans = INFINITY;
    sort(h.begin(), h.end());
    rep(i,N-K+1) ans = min(ans, h.at(i+K-1) - h.at(i));
    cout << ans << endl;
}


Measured memory_bytes: 3784
import math
def calc_10000_5000_comb(n2,y2):
    max_10000 = min(math.floor(y2 / 10000), n2)
    for n_10000 in range(max_10000 + 1)[::-1]:
        y5000 = y2 - 10000 * n_10000
        n_5000 = math.floor(y5000 / 5000)
        if n_5000 + n_10000 == n2:
            return [n_10000, n_5000]
        if n2 < n_5000 + n_10000:
            break
    return []
ny = input()
n, y = [int(x) for x in ny.split(" ")]
min_y_1000 = y % 5000
min_n_1000 = math.floor(min_y_1000 / 1000)
max_n_1000 = n
match = [-1,-1,-1]
if y % 1000 == 0:
    for n_1000 in range(min_n_1000,max_n_1000 + 1, 5):
        y_2 = y - 1000 * n_1000
        n_2 = n - n_1000
        n_10000_n_5000_comb = calc_10000_5000_comb(n_2,y_2)
        if n_10000_n_5000_comb:
            match = n_10000_n_5000_comb + [n_1000]
            break
print(" ".join(map(str,match)))

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

using namespace std;

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

int main() {
  const int INF = 1e9;
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (auto &s : S) {
    cin >> s;
  }
  vector<vector<int>> D(H, vector<int>(W, INF));
  if (S[0][0] == '#') {
    D[0][0] = 1;
  } else {
    D[0][0] = 0;
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int d;
      if (i > 0) {
        if (S[i][j] == '#' and S[i - 1][j] == '.') {
          d = 1;
        } else {
          d = 0;
        }
        chmin(D[i][j], D[i - 1][j] + d);
      }
      if (j > 0) {
        if (S[i][j] == '#' and S[i][j - 1] == '.') {
          d = 1;
        } else {
          d = 0;
        }
        chmin(D[i][j], D[i][j - 1] + d);
      }
    }
  }
  cout << D[H - 1][W - 1] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
 
using namespace std;
 
class Node{
public:
  string s;
  int p;
  vector<int> c;
  set<string> f;
  Node(){ c.clear(); f.clear(); }
  Node(string s, int p): s(s), p(p){ c.clear(); f.clear(); }
};
 
vector<Node> nodes;
int n, m;
 
void push(int s, int pos, vector<string>& vec){
  if(s + 1 == (int)vec.size()){
    if(nodes[pos].f.find(vec[s]) == nodes[pos].f.end()) nodes[pos].f.insert(vec[s]);
    return;
  }
  if(vec[s] == "." && s + 1 < (int)vec.size()) push(s + 1, pos, vec);
  if(vec[s] == "..") push(s + 1, nodes[pos].p, vec);
  bool f = false;
  for(int i=0;i<(int)nodes[pos].c.size();i++){
    int id = nodes[pos].c[i];
    if(nodes[id].s == vec[s]){
      f = true;
      push(s + 1, id, vec);
    }
  }
  if(!f){
    nodes.push_back(Node(vec[s], pos));
    nodes[pos].c.push_back((int)nodes.size()-1);
    push(s + 1, (int)nodes.size()-1, vec);
  }
}
 
int find(int s, int pos, vector<string>& vec){
  if(s + 1 == (int)vec.size()){
    if(nodes[pos].f.find(vec[s]) == nodes[pos].f.end()) return -1;
    else return pos;
  }
  if(vec[s] == "."){
    return find(s + 1, pos, vec);
  }
  if(vec[s] == ".."){
    if(pos == 0) return -1;
    else{
      return find(s + 1, nodes[pos].p, vec);
    }
  }
  for(int i=0;i<(int)nodes[pos].c.size();i++){
    int id = nodes[pos].c[i];
    if(nodes[id].s == vec[s]){
      return find(s + 1, id, vec);
    }
  }
  return -1;
}
 
string path(int p){
  string res;
  if(p == 0) res = "";
  else res += nodes[p].s;
  return res;
}
 
vector<string> parse(string str){
  vector<string> res;
  int pre = 1;
  for(int i=1;i<(int)str.size();i++){
    if(str[i] == '/'){
      res.push_back(str.substr(pre, i - pre));
      pre = i + 1;
    }
  }
  res.push_back(str.substr(pre));
  return res;
}
 
int main(){
  while(cin >> n >> m && (n|m)){
    nodes.clear();
    nodes.push_back(Node("root", -1));
    for(int i=0;i<n;i++){
      string in;
      cin >> in;
      vector<string> vec = parse(in);
      push(0, 0, vec);
    }
    for(int i=0;i<m;i++){
      string a[2], b[2];
      cin >> a[0] >> b[0];
      if(a[0][(int)a[0].size()-1] == '/'){
        a[0] += "index.html";
        a[1] = a[0];
      }else{
        a[1] = a[0] + "/index.html";
      }
      if(b[0][(int)b[0].size()-1] == '/'){
        b[0] += "index.html";
        b[1] = b[0];
      }else{
        b[1] = b[0] + "/index.html";
      }
      int ans = 0;
      for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
          vector<string> v1 = parse(a[i]);
          vector<string> v2 = parse(b[j]);
          int p1 = find(0, 0, v1);
          int p2 = find(0, 0, v2);    
          if(p1 != -1 && p2 != -1){
            if(path(p1) + "/" + v1[(int)v1.size()-1] == path(p2) + "/" + v2[(int)v2.size()-1]) ans = 2;
            else ans = max(ans, 1);
          }
        }
      }
      if(ans == 0) cout << "not found" << endl;
      else if(ans == 1) cout << "no" << endl;
      else cout << "yes" << endl;
    }
  }
  return 0;
}

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

using namespace std;

#define MAX 999

int main()
{
	int N;
	cin >> N;

	for (int i = N; i <= MAX; i++) {
		if (i % 111 == 0) {
			cout << i << endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n;
	cin>>n;
	int alphabet[26]={0};
	for(int i=0; i<n; i++){
		int curr[26]={0};
		string s;
		cin>>s;
		for(int j=0; s[j]; j++) curr[s[j]-'a']++;
		if(!i){
			for(int j=0; j<26; j++) alphabet[j] = curr[j];
		}
		else{
			for(int j=0; j<26; j++) alphabet[j] = min(alphabet[j],curr[j]);
		}
	}
	for(int i=0; i<26; i++){
		if(alphabet[i]){
			for(int j=0; j<alphabet[i]; j++) cout<<(char)('a'+i);
		}
	}
}

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());


signed main()
{
    gearup;
    ll s; cin >> s;
    ll num = 1000000000;
    // num * div - mod = s;
    ll div,mod;
    div = (s + num -1)/num; //切り上げ
    mod = num * div - s;
    if(div == 1000000001)div = 0;
    cout << "0 0 1000000000 1 " << mod << " " << div << endl;
}

Measured memory_bytes: 3652
#include <iostream>

int main()
{
    int a, b, c;
    std::cin >> a >> b >> c;
    int n_dividors = 0;
    for (int i = a; i <= b; i++) {
        if (c % i == 0) {
            n_dividors++;
        }
    }
    std::cout << n_dividors << std::endl;
    return 0;
}

Measured memory_bytes: 3100
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, l := nextInt(), nextInt()
	a := nextInts(n)

	last := -1
	for i := 0; i < n-1; i++ {
		if a[i]+a[i+1] >= l {
			last = i
		}
	}
	if last < 0 {
		puts("Impossible")
		return
	}

	puts("Possible")
	for i := 0; i < last; i++ {
		puts(i + 1)
	}
	for i := n - 2; i > last; i-- {
		puts(i + 1)
	}
	puts(last + 1)
}


Measured memory_bytes: 5180
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n = 3;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  sort(ALL(a));
  int ans = INF;
  do {
    ans = min(ans,abs(a.at(0)-a.at(1))+abs(a.at(1)-a.at(2)));
  } while(next_permutation(ALL(a)));
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter pw = new PrintWriter(System.out);

    int N = Integer.parseInt(br.readLine());
    int[][] E0 = new int[N - 1][2];
    ArrayList<ArrayList<Integer>> E = new ArrayList<>(N);
    for (int u = 0; u < N; ++u) E.add(new ArrayList<>());
    for (int i = 0; i < N - 1; i++) {
      StringTokenizer st = new StringTokenizer(br.readLine());
      int u = Integer.parseInt(st.nextToken()) - 1, v = Integer.parseInt(st.nextToken()) - 1;
      E0[i][0] = u;
      E0[i][1] = v;
      E.get(u).add(2*i);
      E.get(v).add(2*i + 1);
    }

    int[] col = new int[N - 1];
    Arrays.fill(col, -1);

    go(0, -1, -1, E, E0, col);

    int K = 0;
    for (int c : col) K = Math.max(K, c + 1);
    pw.println(K);
    for (int i = 0; i < N - 1; i++) {
      pw.println(col[i] + 1);
    }
    pw.flush();
  }

  static void go(int u, int p, int pcol, ArrayList<ArrayList<Integer>> E, int[][] E0, int[] col) {
    int cur = 0;
    for (int i : E.get(u)) {
      int v = E0[i / 2][1 ^ (i % 2)];
      if (v == p) continue;
      if (cur == pcol) ++cur;
      col[i / 2] = cur;
      go(v, u, cur, E, E0, col);
      ++cur;
    }
  }
}


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

long long N;

int main() {
    cin >> N;
    vector<long long> A(N);
    long long first = 0, second = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] > first) {
            second = first;
            first = A[i];
        } else if (A[i] > second) {
            second = A[i];
        }
    }
    for (int i = 0; i < N; i++) {
        cout << (A[i] == first? second: first) << endl;
    }
}


Measured memory_bytes: 3200
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <ctime>
using namespace std;

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

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int inf=1<<29;

string S;


ll num[26];
ll fact[25];

void init(){
	fact[0]=fact[1]=1;
	for(int i=2;i<25;i++) fact[i]=fact[i-1]*i;
	return ;
}

int main(void){
	
	cin >> S;
	rep(i,S.size()) num[S[i]-'a']++;
	
	int n=S.size();

	bool odd=false;

	rep(i,26){
		if(num[i]&1){
			if(odd){
				cout << 0 << endl;
				return 0;
			}else
				odd=true;
		}
	}

	init();
	ll ans=fact[n/2];
	rep(i,26) ans/=fact[num[i]/2];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1184
#include<iostream>
#include<cmath>
using namespace std;
int64_t a[17];
int main() {

	int64_t N, digit, i, sum = 0, j = 0;
	cin >> N;
	digit = int64_t(log10(N)) + 1;

	if (digit == 1) {
		cout << N << endl;
		return 0;
	}

	for (i = 0; i < digit; ++i) {
		a[i] = N / int64_t(pow(10, digit-1-i));
		N = N % int64_t(pow(10, digit-1-i));
	}

	for (i = digit - 1; i >= 0; --i) {
		if (i == 0 && j != 0) --a[i];
		if (a[i] != 9&&i!=0) a[i] = 9, ++j;
		else continue;
	}

	for (i = 0; i < digit; ++i) {
		sum += a[i];
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d/%d/%d",&a,&b,&c);
    if(c<=30&&b<=04&&a<=2019)
    {
        printf("Heisei\n");
    }
    else
    {
        printf("TBD\n");
    }
    return 0;

}

Measured memory_bytes: 128
s = input()

len_s = len(s)

cnt01_0 = 0
cnt01_1 = 0
cnt10_0 = 0
cnt10_1 = 0

for i in range(len_s):
    if (i%2 == 0)and(s[i]=='0'):
        cnt01_0 += 1
    elif(i%2 == 1)and(s[i]=='1'):
        cnt01_1 += 1

for i in range(len_s):
    if (i%2 == 0)and(s[i]=='1'):
        cnt10_0 += 1
    elif(i%2 == 1)and(s[i]=='0'):
        cnt10_1 += 1

out01 = len_s - cnt01_0 - cnt01_1
out10 = len_s - cnt10_0 - cnt10_1


print(min(out01,out10))

Measured memory_bytes: 3188
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 3005;
const ll mm = 1e+18;
int dp[N][N][3];
int a[N][N];
int f(int x,int y,int z){
    if(dp[x][y][z]!=-1) return dp[x][y][z];
    if(x<1||y<1) return 0;
    int mx=a[x][y]+f(x-1,y,0);
    if(a[x][y]){
        if(z<2){
            mx=max(mx,a[x][y]+f(x,y-1,z+1));
        }
    }
    mx=max(mx,f(x,y-1,z));
    dp[x][y][z]=mx;
    return mx;
}
void solve()
{
    int n,m,k;
    cin>>n>>m>>k;
    rep0(i,k){
        int x,y,c;
        cin>>x>>y>>c;
        a[x][y]=c;
    }
    memset(dp,-1,sizeof(dp));
    cout<<f(n,m,0);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}

Measured memory_bytes: 286072
#include <iostream>
#include <string>
#include <stack>
#include <map>
#include <cstdlib>
#include <cctype>
#include <cstdio>
#include <cstring>

using namespace std;

// 1+(4-25)*3= => ["1", "+", "(", "4", "-", "25", ")", "*", "3", "="]
void str2arr(string s, string A[]) {
    int n = 0;
    string tmp = "";

    for (int i = 0; s[i] != '=' ; i++) {
        if ('0' <= s[i] && s[i] <= '9') {
            tmp += s[i];
        }
        else {
            if (tmp != "") { 
                A[n++] = tmp;
                tmp = "";
            }
            A[n++] = s[i];
        }
    }
    if (tmp != "") { A[n++] = tmp; }
    A[n++] = "=";
}

// generate Reverse Polish Notation

void Generate_RPN(string A[], string B[]) {
    map<string, int> table;
    stack<string> St;
    table["*"] = 1;
    table["/"] = 1;
    table["+"] = 0;
    table["-"] = 0;
    table["("] = -1;
    table[")"] = -1;

    int i, j = 0;
    for (i = 0; A[i] != "="; i++) {
        if ('0' <= A[i][0] && A[i][0] <= '9') {
            B[j++] = A[i];
        }

        else if (A[i] == "(") {
            St.push(A[i]);
        }
        else if (A[i] == ")") {
            while (St.top() != "(") {
                B[j++] = St.top(); St.pop();
            }
            St.pop();
        }
        else {
            while ((!St.empty()) && (table[St.top()] >= table[A[i]])) {
                B[j++] = St.top(); St.pop();
            }
            St.push(A[i]);
        }
    }
    while (!St.empty()) {
        B[j++] = St.top(); St.pop();
    }
    B[j] = "=";
}

int Calculate_RPN(string s[]) {
    stack<double> St;
    double a, b;

    for (int i = 0; s[i] != "="; i++) {
        if (s[i] == "+") {
            b = int(St.top()); St.pop();
            a = int(St.top()); St.pop();
            St.push(a+b);
        }
        else if (s[i] == "-") {
            b = int(St.top()); St.pop();
            a = int(St.top()); St.pop();
            St.push(a-b);
        }
        else if (s[i] == "*") {
            b = int(St.top()); St.pop();
            a = int(St.top()); St.pop();
            St.push(a*b);
        }
        else if (s[i] == "/") {
            b = int(St.top()); St.pop();
            a = St.top(); St.pop();
            St.push(a/b);
        }
        else {
            St.push(atoi(s[i].c_str()));
        }
    }
    return int(St.top());
}

int main() {
    int n;
    string A[100], B[100];
    string in;

    cin >> n;

    while (n--) {
        cin >> in;
        str2arr(in, A);
        Generate_RPN(A, B);
        cout << Calculate_RPN(B) << endl;
    }

    return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll A[MAX_N], B[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	rep(i, 0, N) cin >> B[i];
	vl vec;
	ll sum = 0;
	int res = 0;
	rep(i, 0, N) {
		if(A[i] - B[i] > 0) vec.pb(A[i] - B[i]);
		else if(A[i] - B[i] < 0) {
			sum += B[i] - A[i];
			res++;
		}
	}
	if(sum == 0) cout << 0 << "\n";
	else {
		sort(all(vec));
		reverse(all(vec));
		rep(i, 0, sz(vec)) {
			sum -= vec[i];
			if(sum <= 0) {
				cout << res + i + 1 << "\n";
				return;
			}
		}
		cout << -1 << "\n";
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 3708
#include <stdio.h>
int main ( )
{
int S,h,m,s;
    scanf("%d", &S);
if (S>=0 && S<=86400)
    {
    h= S/3600;
    m= S%3600/60;
    s= S%60;

    printf("%d:%d:%d\n",h,m,s);
    }

return 0;
}








Measured memory_bytes: 2748
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		//変数//
		int a;		//パックAの個数
		int b;		//パックBの個数
		int c;		//パックCの個数
		boolean ans = false;	//分けれるかどうか
		
		Scanner scan = new Scanner(System.in);
		
		//入力//
		a = scan.nextInt();
		b = scan.nextInt();
		c = scan.nextInt();
		
		scan.close();
		
		//処理//
		if( a == b + c ){
			ans = true;
		}else if( b == a + c ){
			ans = true;
		}else if( c == a + b ){
			ans = true;
		}
		
		//結果//
		if(ans){
			System.out.println( "Yes" );
		}else{
			System.out.println( "No" );
		}

	}

}


Measured memory_bytes: 10192
#include <iostream>

using namespace std;

int main(){
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  c+=a+b;
  b+=a;
  if(k<=a){
    cout << k;
  }else if(a<k&&k<=b){
    cout << a;
  }else if(k>b){
    cout << a-k+b;
  }
}

Measured memory_bytes: 3644
#include <stdio.h>
 
int main(void) {
	int N, A[100], i, j, k, v;

	scanf("%d", &N);

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

	for (i = 0;i < N;i++) {
		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		for (k = 0;k < N;k++) {
			if (k != 0) printf(" ");
			printf("%d", A[k]);
		}

		printf("\n");

	}

	return 0;
}

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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1)); }

int find(char str[]){
 long long key, i, h;
 key = getKey(str);
 for (i = 0;; i++){
   h = (h1(key) + i * h2(key)) % M;
   if(strcmp(H[h], str) == 0) return 1;
   else if(strlen(H[h]) == 0) return 0;
 }
   return 0;
 }

int insert(char str[]){
   long long key, i, h;
  key = getKey(str);
  for(i = 0;; i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0){
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
	    scanf("%s %s", com, str);

	    if ( com[0] == 'i' ){
	      insert(str);
	    } else {
	      if (find(str)){
		      printf("yes\n");
	      } else {
		      printf("no\n");
	      }
	    }
    }

    return 0;
}



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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;

int dp[201010][2];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S;
	FOR(i,N+1) dp[i][0]=dp[i][1]=201010;
	dp[0][0]=dp[0][1]=0;
	FOR(i,N) {
		// ww
		dp[i+1][0]=min(dp[i+1][0],dp[i][0]+(S[i]=='#'));
		// wb
		dp[i+1][1]=min(dp[i+1][1],dp[i][0]+(S[i]!='#'));
		//bb
		dp[i+1][1]=min(dp[i+1][1],dp[i][1]+(S[i]!='#'));
	}
	
	cout<<min(dp[N][0],dp[N][1])<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 2196
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (!sc.hasNext("0")) {
			HashMap<String,String> h = new HashMap<String,String>();
			int n = sc.nextInt();
			for ( int i = 0; i < n; i++ )
				h.put(sc.next(),sc.next());
			int m = sc.nextInt();
			for ( int i = 0; i < m; i++ ) {
				String p = sc.next();
				if ( h.containsKey(p) ) p = h.get(p);
				System.out.print(p);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <stdlib.h>
int main(){
        int s;
        scanf("%d",&s);
        int c[4];
        c[0]=s/1000;//1234
        c[1]=(s%1000)/100;//234
        c[2]=(s%100)/10;//34
        c[3]=(s%10);//4
        //printf("%d %d %d %d",c[0],c[1],c[2],c[3]);
        if(c[0]==c[1]||c[1]==c[2]||c[2]==c[3]){
                printf("Bad");
        }else{
                printf("Good");
        }
        return 0;
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  string s;
  cin >> s;

  ll scnt = 0;
  ll tcnt = 0;
  ll n = s.size();

  rep(i, n) {
    if (s[i] == 'T') {
      if (scnt == 0)
        tcnt++;
      else
        scnt--;
    } else {
      scnt++;
    }
  }

  ll ans = tcnt + scnt;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 720
#include <iostream>

using namespace std;

int main(void){
	int N=0,n=0,a=0;

	cin >> N;

	n = N;

	while(N > 0){
		a = a + N%10;
		N = N / 10;
	}
	a = a + N;

	if(n%a == 0)
		cout << "Yes" <<endl;
	else
		cout << "No" <<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf 1e18
#define g(x) cout<<x<<" "<<endl;
#define gg(x,y) cout<<x<<" & "<<y<<" "<<endl
#define jam(t) cout<<"Case #"<<t<<": "
#define ggg(x,y,z) cout<<x<<" & "<<y<<" & "<<z<<" "<<endl
#define all(x) x.begin(),x.end()
#define input_from_file  freopen("input.txt", "r", stdin);
#define mod 1000000007ll
#define sz 400005
#define bitcnt(x) __builtin_popcountll(x)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}



void solve(){
    ll n,m;
    cin >> n >> m;
    ll an = (n*(n-1))/2;
    an += (m*(m-1))/2;
    g(an);
}
int main()
{

 
    FASTIO
    cin.tie(NULL);
    fflush(stdout);
    ll t = 1;
    //cin >> t;
    for(ll tcase = 1;tcase <= t;tcase++){
        solve();
        
    }
return 0;
}

Measured memory_bytes: 256
N = int(input())
# print(N)


if N == 0:
    print(0)
elif N > 0:
    co = [0 for i in range(31)]

    a = 2
    i = 1
#    for i in range(29):
    co[0] = N % 2
    while a <= N:
        co[i] = ((N - a) // (2 ** i) + 1) % 2
#        print(i, a, co[i])

        i = i + 1
        if i % 2 == 1:
            if i == 1:
                pass
            else:
                a = a + 2 ** (i - 1)

    ans = 0
    for i in range(31):
        ans = ans + (10 ** i) * co[i]
    print(ans)
else:
    co = [0 for i in range(32)]
    N = - N

    a = 1
    i = 1
    co[0] = N % 2
    while a <= N:
        co[i] = ((N - a) // (2 ** i) + 1) % 2
#        print(i, a, co[i])

        i = i + 1
        if i % 2 == 0:
            a = a + 2 ** (i - 1)

    ans = 0
    for i in range(32):
        ans = ans + (10 ** i) * co[i]
    print(ans)


Measured memory_bytes: 3064
from math import sqrt


def Calc_Divisors(num):
    divisors = []
    for i in range(1, int(sqrt(num)) + 1):
        if num % i == 0:
            divisors.append(i)
            if i != num // i:
                divisors.append(num//i)
    divisors.sort()
    return divisors

if __name__ == "__main__":
    N, P = map(int, input().split())

    A = Calc_Divisors(P)

    ans = 1
    for i in A:
        tmp = P % (pow(i, N))
        if N > 40:
            print(ans)
            exit()
        if pow(i, N) > P:
            print(ans)
            exit()
        if tmp == 0:
            ans = i

    print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int** dp;
int N,M;
int POW[23],base[500],work[500];
char table[500][501];

int makeCode(){

	int ret = 0;

	for(int i = 0; i < M; i++){
		if(work[i] == 1){
			ret += POW[i];
		}
	}
	return ret;
}


void func_N(){

	int limit = POW[N];

	int ans = 0,count;
	bool FLG;

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

		for(int k = 0; k < M; k++)work[k] = 0;

		count = 0;

		for(int loop = 0; loop < N; loop++){
			if(i & (1 << loop)){ //??¬??????loop?????????
				count++;
				for(int k = 0; k < M; k++){
					work[k] += table[loop][k] - '0';
				}
			}
		}

		FLG = true;
		for(int k = 0; k < M; k++){
			if(work[k]%2 == 1){
				FLG = false;
				break;
			}
		}

		if(FLG)ans = max(ans,count);

	}

	printf("%d\n",ans);
}

//??????????¨????????°?????????´???
void func_M(){

	int limit = POW[M];

	for(int i = 0; i < limit; i++){
		dp[0][i] = 0; //??¶???????????????????????£?????¬??????????????§?????°
		dp[1][i] = 0;
	}

	for(int i = 0; i < M; i++){
		work[i] = table[0][i]-'0';
	}
	dp[1][makeCode()] = 1;

	int array[500],tmp;

	for(int i = 1; i < N; i++){  //??¬??????????????????

		for(int state = 0; state < limit; state++){
			dp[0][state] = dp[1][state];
		}

		for(int k = 0; k < M; k++){
			array[k] = table[i][k] - '0'; //????????¬???????????????????????¨???????????????
		}

		for(int state = 0; state < limit; state++){
			if(dp[0][state] == 0)continue;

			//??????????????¶???state??????????????????????????????????????????(0:???????????? 1:????????????)
			for(int loop = 0; loop < M; loop++){
				if(state & (1 << loop)){
					base[loop] = 1;
				}else{
					base[loop] = 0;
				}
			}

			//2????????¶???????¶????
			for(int k = 0; k < M; k++){
				work[k] = base[k]+array[k];
				work[k] %= 2;
			}

			tmp = makeCode();
			dp[1][tmp] = max(dp[1][tmp],dp[0][state]+1);
		}

		for(int k = 0; k < M; k++){
			work[k] = array[k];
		}

		tmp = makeCode();
		dp[1][tmp] = max(dp[1][tmp],1);
	}

	printf("%d\n",dp[1][0]);
}


int main(){

	for(int i = 0; i <= 22; i++){
		POW[i] = pow(2,i);
	}

	dp = new int*[2]; //dp???????¬??????????????????¨???????§?????????¶?????????????????????????????\?????????????§????????????????
	dp[0] = new int[POW[22]];
	dp[1] = new int[POW[22]];


	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		for(int i = 0; i < N; i++){
			scanf("%s",table[i]);
		}

		if(N <= 22)func_N();
		else{
			func_M();
		}
	}

	return 0;
}

Measured memory_bytes: 19996
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main(){

    string s;
    cin >> s;
    string front = s.substr(0, 2);
    string back = s.substr(2, 2);

    int frontNum = stoi(front);
    int backNum = stoi(back);

    bool frontMM = false;
    bool backMM = false;

    if(1 <= backNum && backNum <= 12){
        backMM = true;
    }

    if(1 <= frontNum && frontNum <= 12){
        frontMM = true;
    }

    if(frontMM && backMM){
        cout << "AMBIGUOUS";
    }else if(frontMM){
        cout << "MMYY";
    }else if(backMM){
        cout << "YYMM";
    }else{
        cout << "NA";
    }

    return 0;
}

Measured memory_bytes: 3036
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

  ll a, b, k;
  cin >> a >> b >> k;

  set<ll> ans;
  rep(i, k) {
    ans.emplace(a + i);
    ans.emplace(b - i);
  }

  for (int e : ans) {
    if( e >= a && e <= b ) cout << e << endl;
  }

  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = n/2
b = 0
sum = 0
list = []
(1..a).each do |i|
  b = n-i
  sum = 0
  while i>0 do
    sum+=i%10
    i=i/10
  end
  while b>0 do
    sum+=b%10
    b=b/10
  end
  list << sum
end
puts list.min



Measured memory_bytes: 2300