akhauriyash/Code-Regression huggingface dataset:
class ans:
  def __init__(self):
    self.N, self.A, self.B, self.C = map(int,input().split())
    self.L = [int(input()) for _ in range(self.N)]
    print(self.dfs(0, 0, 0, 0))
    exit()

  def dfs(self, x, a, b, c):
    if(x == self.N):
      if(min(a, b, c) > 0):
        return abs(a-self.A)+abs(b-self.B)+abs(c-self.C) - 30
      else:
        return 1e9+7
    ret0 = self.dfs(x+1, a, b, c)
    ret1 = self.dfs(x+1, a+self.L[x], b, c) + 10
    ret2 = self.dfs(x+1, a, b+self.L[x], c) + 10
    ret3 = self.dfs(x+1, a, b, c+self.L[x]) + 10
    return min(ret0, ret1, ret2, ret3)

ans()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int n;
    cin >> n;
    vector<int> v;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        mp[a]++;
        v.push_back(a);
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    int even = 0;
    for (int i = 0; i < v.size(); i++) {
        if (mp[v[i]] % 2 == 0) {
            even++;
        }
    }

    if (even % 2 == 0) {
        cout << v.size() << endl;
    } else {
        cout << (v.size() - 1) << endl;
    }


    return 0;
}


Measured memory_bytes: 5368
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

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

  vector< vector<char> > s(H, vector<char>(W));
  vector< vector<int> > a(H, vector<int>(W));

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

  int index = 0;
  for (int i = 0; i < H; i++) {
    int j = 0;
    int prev_j = 0;
    for (; j < W; j++) {
      if (s[i][j] == '#') {
        index++;
        for (int k = prev_j; k <= j; k++) {
          a[i][k] = index;
        }
        prev_j = j + 1;
      }
    }
    if (prev_j != 0) {
      for (int k = prev_j; k < W; k++) {
        a[i][k] = index;
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (a[i][j] == 0) {
        if (i != 0 && a[i-1][j] != 0) {
          a[i][j] = a[i-1][j];
        }
      }
    }
  }
  for (int i = H - 1; i >= 0; i--) {
    for (int j = 0; j < W; j++) {
      if (a[i][j] == 0) {
        if (i != H - 1 && a[i+1][j] != 0) {
          a[i][j] = a[i+1][j];
        }
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N, K;
  cin >> N >> K;
  vector<int> a(N+1);
  a.at(0)=1;
  for (int i=0; i<N; i++){
  	a.at(i+1)=min(a.at(i)*2,a.at(i)+K);
  }
  cout << a.at(N);
}

Measured memory_bytes: 256
import copy
N=input()
s=int(input())
b=N[0]
c=0
x=[]
for a in N:
	if a != b:
		x.append([int(b),c])
		b=a
		c=0
	c+=1
x.append([int(b),c])
y=[]
while x != y:
	y=copy.deepcopy(x)
	p=0
	for i in range(len(x)):
		p += x[i][1]
		if p > s:
			break
		x[i][1]=x[i][1]*x[i][0]
w=0
for xx in x:
	w += xx[1]
	if w >= s:
		print(xx[0])
		break

Measured memory_bytes: 3572
array = []
array2 = []
import sys
for i in sys.stdin.readlines():
    n = i.rstrip()
    if n == "0":
        array2.append(array[-1])
        array.pop(-1)
    else:
        array.append(n)
for i in range(len(array2)):
    print(array2[i])

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

int main() {
  int N;
  cin >> N;
  
  switch(N) {
    case 400 ... 599:
      cout << '8' << endl;
      break;
    case 600 ... 799:
      cout << '7' << endl;
      break;
    case 800 ... 999:
      cout << '6' << endl;
      break;
    case 1000 ... 1199:
      cout << '5' << endl;
      break;
    case 1200 ... 1399:
      cout << '4' << endl;
      break;
    case 1400 ... 1599:
      cout << '3' << endl;
      break;
    case 1600 ... 1799:
      cout << '2' << endl;
      break;
    case 1800 ...1999:
      cout << '1' << endl;
      break;
    default:
      cout << "error" << endl;
      break;
  }
}

Measured memory_bytes: 3624
#include<stdio.h>

void swap(int *a,int *b){
	int t;
	t=*b;
	*b=*a;
	*a=t;
}

int main(){
	int n, i, j, A[100], count = 0,mini;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &A[i]);

	for (i = 0; i < n - 1; i++){
		mini = i;
		for (j = i; j <= n - 1; j++){
			if (A[j] < A[mini]){
				mini = j;
			}
		}
		if (A[i] != A[mini]){
			swap(&A[i], &A[mini]);
			count++;
		}
	}

	for (i = 0; i < n; i++){
		printf("%d", A[i]);
		if (i < n - 1){ printf(" "); }
	}
	printf("\n%d\n",count);

	return 0;
}

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

using namespace std;

const int mod = 1e9 + 7;

int vis[53];
string m[2];

int main(){
	memset(vis, 0, sizeof(vis));
	int n; cin >> n;
	cin >> m[0] >> m[1];
	int ans = 1;
	for(int i = 0; i < n; ++i){
		if(vis[i]) continue;
		if(m[0][i] == m[1][i]){
			vis[i] = 1;
			if(!i) ans = 3ll * ans % mod;
			else if(vis[i-1] == 1) ans = 2ll * ans % mod;
		}
		else{
			vis[i] = vis[i + 1] = 2;
			if(!i) ans = 6ll * ans % mod;
			else if(vis[i-1] == 1) ans = 2ll * ans % mod;
			else ans = 3ll * ans % mod;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
if(n>=400 && n<=599)
{
    cout<<"8";
}
if(n>=600 && n<=799)
{
    cout<<"7";
}
if(n>=800 && n<=999)
{
    cout<<"6";
}
if(n>=1000 && n<=1199)
{
    cout<<"5";
}
if(n>=1200 && n<=1399)
{
    cout<<"4";
}
if(n>=1400 && n<=1599)
{
    cout<<"3";
}
if(n>=1600 && n<=1799)
{
    cout<<"2";
}
if(n>=1800 && n<=1999)
{
    cout<<"1";
}
}

Measured memory_bytes: 3624
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

int main() {
	ll ans = 0;
	ll tmp;
	int h, w, m; cin >> h >> w >>  m;
	int x, y;
	vector<pair<int, int>> ta(h+1), yo(w+1), ex;
	REP1(i, h){
		ta[i].second = i;
		ta[i].first = 0;
	}
	REP1(i, w){
		yo[i].second = i;
		yo[i].first = 0;
	}
	REP(i, m){
		cin >> x >> y;
		ex.push_back(make_pair(x, y));
		ta[x].first++;
		yo[y].first++;
	}
	sort(ta.rbegin(), ta.rend());
	sort(yo.rbegin(), yo.rend());
	int tam = ta[0].first, yom = yo[0].first;
	set<int> tad, yod;
	REP(i, ta.size()){
		if(ta[i].first == tam) tad.insert(ta[i].second);
	}
	REP(i, yo.size()){
		if(yo[i].first == yom) yod.insert(yo[i].second);
	}
	int cross = 0;
	REP(i, m){
		if(tad.find(ex[i].first) != tad.end() && yod.find(ex[i].second) != yod.end()) cross++;
	}
	if(tad.size()*yod.size() == cross) cout << tam + yom - 1 << endl;
	else cout << tam + yom  << endl;
}

Measured memory_bytes: 38452
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

typedef long long ll;

const int maxn = 200010;
const int Alphabet = 26;

vector<int> loc[Alphabet];
vector<pair<int,int>> p;
char str[maxn];
int dest[maxn];
int len;
int bit[maxn * 2];

bool cmp(pair<int,int> a, pair<int,int> b)
{
	return a.first < b.first;
}

void add(int k, int x)
{
	k++;
	while (k <= len + 10)
	{
		bit[k] += x;
		k += k & -k;
	}
}

int getsum(int k)
{
	k++;
	int ret = 0;
	while (k)
	{
		ret += bit[k];
		k -= k & -k;
	}
	return ret;
}

int main()
{
	//freopen("E.in","r",stdin);
	scanf("%s",str);
	len = strlen(str);

	for (int i=0;i<len;i++) loc[str[i]-'a'].push_back(i);

	int oddNum = 0, odd;
	for (int i=0;i<Alphabet;i++)
	{
		if (loc[i].size() % 2 == 1) oddNum++, odd = i;
	}
	if ((len % 2 == 0 && oddNum != 0)||(len % 2 == 1 && oddNum != 1)) { puts("-1"); return 0; }

	for (int i=0;i<Alphabet;i++)
	{
		for (int j=0;j<loc[i].size()/2;j++) p.push_back(make_pair(loc[i][j],loc[i][loc[i].size()-1-j]));
	}
	sort(p.begin(), p.end(), cmp);
	for (int i=0;i<p.size();i++)
	{
		dest[p[i].first] = i;
		dest[p[i].second] = len-1-i;
	}
	if (oddNum == 1) dest[loc[odd][(loc[odd].size()-1)/2]] = len/2;

	ll ans = 0;
	for (int i=0;i<len;i++)
	{
		ans += (ll)getsum(len) - (ll)getsum(dest[i]);
		//cout<<len<<" "<<dest[i]<<" "<<getsum(len)<<" "<<getsum(dest[i])<<endl;
		add(dest[i],1);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4596
import java.util.*;

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

	int x = sc.nextInt();
	int y= sc.nextInt();

	int a = x*y;
	int b = 2*x+2*y;

	System.out.println(a+" "+b);
  }
}

Measured memory_bytes: 25992
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

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

    int n,m; cin >> n >> m;
    vp a(m);
    rep(i,m) cin >> a[i].S  >> a[i].F;
    sort(all(a));
    int res=0,edge=-1*INF;
    rep(i,m){
        if(a[i].S>=edge){
            edge=a[i].F;
            res++;
        }
    }
    COUT(res);


}

Measured memory_bytes: 4784
import sys
sys.setrecursionlimit(2147483647)
INF=10**9
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

class D(object):
    def __init__(self):
        self.L=[INF]*3
        self.R=[-INF]*3

    def add(self,x,v):
        v+=1
        self.L[v]=min(self.L[v],x)
        self.R[v]=max(self.R[v],x)

    def get(self,t):
        l=INF; r=-INF
        L=self.L; R=self.R
        for i in range(3):
            l=min(L[i]+i*t,l)
            r=max(R[i]+i*t,r)
        return r-l

    def event(self):
        L=self.L; R=self.R
        res=[]
        for i in range(3):
            for j in range(i): # 0<=j<i<=2
                t=(L[j]-L[i])/(i-j)
                if(t>0): res.append(t)
        for i in range(3):
            for j in range(i): # 0<=j<i<=2
                t=(R[j]-R[i])/(i-j)
                if(t>0): res.append(t)
        return res

def resolve():
    n=int(input())
    xd=D()
    yd=D()
    for i in range(n):
        x,y,d=input().split()
        x=int(x); y=int(y)
        if(d=='R'):
            xd.add(x,1)
            yd.add(y,0)
        elif(d=='L'):
            xd.add(x,-1)
            yd.add(y,0)
        elif(d=='U'):
            xd.add(x,0)
            yd.add(y,1)
        elif(d=='D'):
            xd.add(x,0)
            yd.add(y,-1)
    T=[0]+xd.event()+yd.event()
    ans=float("inf")
    for t in T:
        ans=min(ans,xd.get(t)*yd.get(t))
    print(ans)
resolve()

Measured memory_bytes: 45544
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
ans = 0
for i in range(N):
  tmp = 0
  A = list(map(int,input().split()))
  for k in range(M):
    tmp = tmp + (A[k] * B[k])
  tmp = tmp + C
  if(tmp > 0):
    ans += 1
print(str(ans))

Measured memory_bytes: 3064
n,m=map(int,input().split())

s=[]
l= 0
r = n
for i in range(m):
    ln,rn=map(int,input().split())
    if ln>l:
        l=ln
    if rn<r:
        r=rn
if r-l+1>0:
    print(r-l+1)
else:
    print(0)


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int mod=998244353;
const int N=2e5+10;
ll a[N],b[N];
ll sum;
ll n,k;
bool check(ll x,ll k)
{
    for(int i = 1 , j = n ; i <= n ; i++ , j--)
    {
        ll temp=a[i]*b[j];
        if(temp>x)
        {
            k -= (temp - x) / b[j];
            if((temp - x) % b[j] != 0)
                k--;
        }
        if(k<0)
        {
            break;
        }
    }
    if(k >= 0)
        return true;
    else
        return false;
}
int main()
{
    cin>>n>>k;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    for(int i=1; i<=n; i++)
    {
        cin>>b[i];
    }
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    if(sum-k<=0)
    {
        cout<<0<<endl;
        return 0;
    }
    ll l=0,r=a[n]*b[n],ans=0;
    while(l<=r)
    {
        ll mid= (l + r + 1LL)>>1;
        if(check(mid,k))
        {
            r=mid-1;
            ans=mid;
        }
        else
        {
            l=mid+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6632
#include <iostream>
#include <cmath>
#include <limits>
using namespace std;
int main(){
  int N;
  cin >> N;
  long power = 1;
  long div = pow(10,9)+7;
  for(int i = 1; i <= N; i++){
    power = power * i;
    if(power >= div) {
      power %= div; 
    }
  }
  
  cout << power << endl;
}

Measured memory_bytes: 256
// Score: /100

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	cout << max({
		A * 10 + B + C,
		A * 10 + C + B,
		B * 10 + A + C,
		B * 10 + C + A,
		C * 10 + A + B,
		C * 10 + B + A,
		A + B * 10 + C,
		A + C * 10 + B,
		B + A * 10 + C,
		B + C * 10 + A,
		C + A * 10 + B,
		C + B * 10 + A,
	});
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll n; cin >> n;
  vector<ll> p(n), q(n+1);
  REP(i, n){
    cin >> p[i];
    q[p[i]] = i+1;
  }
  ll maxi = 1;
  ll l = 1;
  FOR(i, 1, n){
    if(q[i] < q[i+1]){
      l++;
      if(i == n-1) maxi = max(maxi, l);
    }else{
      maxi = max(maxi, l);
      l = 1;
    }
  }
  
  cout << n -  maxi << endl;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int n;
vector<P> g[100005];
vector<int> ans(100005);

void dfs(int v, int now = 1, int p = -1) {
	ans[v] = now;
	for (auto& c : g[v]) {
		if (c.first == p) continue;
		if (c.second % 2 == 1) dfs(c.first, now ^ 1, v);
		else dfs(c.first, now, v);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	rep(i, n - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].push_back(P(b, c));
		g[b].push_back(P(a, c));
	}
	dfs(0);
	rep(i, n) printf("%d\n", ans[i]);
	return 0;
}


Measured memory_bytes: 9216
//i hate _____
#include<bits/stdc++.h>

#define ll long long int 
#define ld long double 
#define pb push_back
#define mk make_pair
#define ii pair<int , int>

using namespace std;
double pi = 2 * acos(0.0) ;

template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << " " << x;
        return os << '}'; 
}

void solve(){
    
}

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

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    int n; cin>>n;
    ll ans = 0;
    int a,b,c;
    for (int i=1;i<=n;i++){
        b = n/i;
        if (n%i==0)b--;
        ans+=b;
    }
    cout << ans << endl;
    return 0;
}
/*
    problems are the sign of life
*/


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main()
{
	ll i,j,k,n,s=0;
	cin>>n;
	string ss;
	cin>>ss;
	ll dp[n+3][4];
	memset(dp,0,sizeof(dp));
	if(ss[0]=='R') dp[0][0]=1;
	if(ss[0]=='G') dp[0][1]=1;
	if(ss[0]=='B') dp[0][2]=1;
	for(i=1;i<ss.size();i++)
	{
		if(ss[i]=='R')
		{
			dp[i][0]=dp[i-1][0]+1;
			dp[i][1]=dp[i-1][1];
			dp[i][2]=dp[i-1][2];
			
		}
		if(ss[i]=='G')
		{
			dp[i][0]=dp[i-1][0];
			dp[i][1]=dp[i-1][1]+1;
			dp[i][2]=dp[i-1][2];
			
		}
		if(ss[i]=='B')
		{
			dp[i][0]=dp[i-1][0];
			dp[i][1]=dp[i-1][1];
			dp[i][2]=dp[i-1][2]+1;
			
		}
	}
	vector<pair<ll,pair<ll,ll > > > v;
	for(i=0;i<n-2;i++)
	{
		for(j=i+1;j<n-1;j++)
		{
			if(ss[i]!=ss[j])
			{
				ll xx;
				if(ss[i]=='R'&& ss[j]=='G') xx=2;
				else if(ss[i]=='G'&& ss[j]=='R') xx=2;
				else if(ss[i]=='R'&& ss[j]=='B') xx=1;
				else if(ss[i]=='B'&& ss[j]=='R') xx=1;
				else if(ss[i]=='B'&& ss[j]=='G') xx=0;
				else if(ss[i]=='G'&& ss[j]=='B') xx=0;
				v.push_back(make_pair(xx,make_pair(i,j)));
			}
		}
	}
	ll z=0;
	for(i=0;i<v.size();i++)
	{
		s=s+(dp[n-1][v[i].first]-dp[v[i].second.second][v[i].first]);
		ll kk,po;
		ll rr;
		rr=v[i].second.second-v[i].second.first;
		kk=v[i].second.second+rr;
		if(kk>n-1) po=0;
		else
		{
			if(ss[kk]=='G' && v[i].first==1) po=1;
			else if(ss[kk]=='R' && v[i].first==0) po=1;
			else if(ss[kk]=='B' && v[i].first==2) po=1;
			else po=0;			
		}
		s=s-po;
		
	}
	
	cout<<s;
    
}

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

int main() {
  string s;
  cin >> s;
  int lengthS = 0;
  int lengthT = 0;
  bool T = true;
  if(s[0] == 'S') {
    lengthS++;
    T = false;
  }
  if(s[0] == 'T') lengthT++;
  int ans = 0;
  for(int i=1;i<s.size();i++) {
    if(!T && s[i] == 'S') lengthS++;
    else if(T && s[i] == 'S') {
      if(lengthS > lengthT) {
        lengthS -= lengthT;
      }
      else {
        ans += lengthT - lengthS;
        lengthS = 0;
      }
      
      lengthS++;
      lengthT = 0;
      T = false;
    } else if(s[i] == 'T') {
      if(!T) T = true;
      lengthT++;
    }
  }

  ans += abs(lengthS - lengthT);

  cout << ans << endl;
}

Measured memory_bytes: 640
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    readint;
    auto a = readints;

    auto d = new int[8];
    int redOver = 0; // (>= 3200)
    foreach (x; a) {
        if (x < 3200) d[x / 400]++;
        else redOver++;
    }

    int x = cast(int) d.count!(e => e > 0);
    int minAns = x;
    if (minAns == 0 && redOver > 0) minAns++;
    int maxAns = x + redOver;
    writeln(minAns, " ", maxAns);
}


Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#define frr(i, r, l) for(int i = r; i >= l; --i)
#define fr(i, l, r) for(int i = l; i < r; ++i)
#define forit(it, type, var) for(type::iterator it = var.begin(); it != var.end(); it++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define MEMS(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define ll long long
#define ld long double
typedef pair<ll, ll> iPair; 
priority_queue< ll, vector <ll> , greater<ll>>pq1,pq2;
#define maxN 1000000000000000000
ll power(ll a,ll b){ll res=1;while(b>0){res*=a;b--;}return res;}
int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,sum=0,pref[200005],ar[200005],mod=1000000007;
    cin>>n;
    pref[0]=0;
    fr(i,0,n)
    {
        cin>>ar[i];
        sum+=ar[i];
        pref[i]=sum;
    }
    ll ans=0;
    frr(i,n-1,1)
    {
        ll st=pref[i-1]%mod;
        ll st1=(ar[i]*st)%mod;

        ans=(ans+st1)%mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6732
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,W;
    cin>>n>>W;
    int w[n];
    int val[n];
    //cout<<"\n";
    for(int i=0;i<n;i++){
        cin>>w[i]>>val[i];
 
    }
   long long int dp[n+1][W+1];
    for(int i=0;i<n+1;i++){
        for(int j=0;j<W+1;j++){
            if(i==0 || j==0)
                dp[i][j]=0;
            
            else if(w[i-1] <= j){
                    dp[i][j]=max(val[i-1] + dp[i-1][j-w[i-1]],dp[i-1][j]);//check 2nd term
            }
            else{
                    dp[i][j]=dp[i-1][j];
            }
            
        }
    }
    cout<<dp[n][W]<<" \n";
    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

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

struct UnionFind {
    vector<int> d; // 根なら (-サイズ), そうでないなら親の番号
    UnionFind(int N) : d(N, -1){} // 全て根として初期化

    int root(int x) { // データ x が属する木の根を再帰で得る
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }

    bool unite(int x, int y) { // x と y の木を併合. 併合した場合 true
        x = root(x); y = root(y); // x <- x の根, y <- y の根
        if (x == y) return false; 
        // merge technique（データ構造をマージするテク. 小を大にくっつける）
        if (d[x] > d[y]) swap(x, y);    // x の木のサイズ > y の木のサイズにする. d[x], d[y] < 0 に注意.
        d[x] += d[y];   // x の木のサイズ += y の木のサイズ
        d[y] = x;   // y の親は x
        return true;
    }

    bool same(int x, int y) { // 2つのデータ x, y が属する木が同じなら true
        return root(x) == root(y);
    }
    
    int size(int x) { // 素集合のサイズ
        return -d[root(x)]; // d[root(x)] < 0 に注意.
    }
};

void Main(){
    // Union Find Tree - ABC126 - E - 1 or 2 //
	int n, m; cin >> n >> m;
	
	UnionFind tree(n);
	rep(i, m) {
	    int a, b, z; cin >> a >> b >> z;
	    a--; b--;	   
	    tree.unite(a,b);
	}
    
    map<int, int> mp;

	rep(i, n){
	    int r = tree.root(i);
	    mp[r]++;
	}
	cout << mp.size() << endl;
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

void Main()
{
	int A, B; cin >> A >> B;
	cout << (A <= 8 && B <= 8 ? "Yay!" : ":(") << endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
package main

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

var (
	n int
)

func dfs(s string, mx rune, io *Io) {
	if len(s) == n {
		io.println(s)
		return
	}
	for c := 'a'; c <= mx+1; c++ {
		tmp := s
		tmp += string(c)
		dfs(tmp, rune(max(int(mx), int(c))), io)
	}
}

func main() {
	io := NewIo()
	defer io.Flush()

	n = io.readInt()
	dfs("", 'a'-1, io)
}

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) readStringLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) readString() string {
	for io.nextToken >= len(io.tokens) {
		line := io.readStringLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) readInt() int {
	i, err := strconv.Atoi(io.readString())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) printStringSlice(a []string) {
	var b []interface{}
	for _, v := range a {
		b = append(b, v)
	}
	io.println(b...)
}

func (io *Io) printIntSlice(a []int) {
	var b []interface{}
	for _, v := range a {
		b = append(b, v)
	}
	io.println(b...)
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}


Measured memory_bytes: 6032
var s:string;
tot:qword;
k,i,j,l:longint;
begin 
	tot:=0;
	readln(s);
	readln(k);
	l:=length(s);
	i:=1;
	while i<=l do 
	begin 
		j:=i;
		while (s[j]=s[i]) and (j<=l) do inc(j);
		dec(j);
		tot:=tot+(j-i+1) div 2;
		i:=j+1;
	end;
	tot:=tot*k;
	i:=2;
	while s[i]=s[1] do inc(i);
	dec(i);
	j:=l;
	while s[j]=s[1] do dec(j);
	inc(j);
	if j<=l then 
	begin 
		if i<j then tot:=tot+(k-1)*((i+l-j+1)div 2-i div 2-(l-j+1) div 2)
			else tot:=(l*k) div 2;
	end;
	writeln(tot);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  
  char c1,c2,c3,c4;
  c1 = S[2];
  c2 = S[3];
  c3 = S[4];
  c4 = S[5];
    
  if (c1 == c2 & c3 == c4) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    li m, k;
    cin >> m >> k;
    if (m == 1) {
        cout << (k == 0 ? "0 0 1 1" : "-1") << endl;
        return 0;
    }

    if ( k >= bit(m)) {
        puts("-1");
        return 0;
    }

    cout << k << " ";
    rep(i, bit(m)) {
        if (i != k)
            cout << i << " ";
    }
    cout << k << " ";
    rep(i, bit(m)) {
        if (bit(m) - 1 - i != k)
            cout << bit(m) - 1 - i << " ";
    }



    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repi(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
int main() {
  const int MAX_N=2e5+1;
  int n,a1e,a1v,a2v=0;
  cin>>n;
  int a[MAX_N];
  rep(i,n) cin>>a[i];
  a1e=max_element(a,a+n)-a;
  rep(i,n){
    if(i!=a1e) a2v=max(a2v,a[i]);
  }
  a1v=a[a1e];
  rep(i,n){
    if(i==a1e) cout<<a2v<<endl;
    else cout<<a1v<<endl;
  }
  return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include<vector>

using namespace std;
int main() {
    int n,m,i,j,temp,ans=0;
    cin>>n>>m;
    vector<int> k(n);
    vector<bool> flg(m,true);

    vector<vector<int>> a(n);
    for(i=0;i<n;i++){
        cin>>k[i];
        for(j=0;j<k[i];j++){
            cin>>temp;
            a[i].push_back(temp);
        }

    }
    for(i=0;i<n;i++){
        vector<bool> flg2(m,false);
        for(j=0;j<k[i];j++){
            flg2[a[i][j]-1]=true;
        }
        for(j=0;j<m;j++){
            if(flg2[j]==false)flg[j]=false;
        }


    }

    for(j=0;j<m;j++){
    if(flg[j]){
        ans++;
    }
        }




    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    string T,TD,TP;
    cin >> T;
    rep(i,T.size()){
        if(T[i]=='?'){
            TD.PB('D');
            TP.PB('P');
        }
        else{
            TD.PB(T[i]);
            TP.PB(T[i]);
        }
    }
    rep(i,T.size()){
        if(T[i]=='?'){
            T[i]='D';
        }
    }
    rep(i,T.size()){
        cout << T[i];
    }
    cout << endl;
}

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


int main(){
  string s;
  cin >> s;
  string str = "CODEFESTIVAL2016";
  int count = 0;
  for(int i = 0; i < s.length(); i++){
    if(s[i] != str[i])count++;
  }
  cout << count << endl;
  return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i < int(n); ++i)

int n;
string s;

void turn(vector<char>& a, int i) {
	if (a[i - 1] == 'S')
		a[i + 1] = 'W';
	else
		a[i + 1] = 'S';
}

bool sim(vector<char>& a) {
	for1(i, n - 1) {
		if (a[i] == 'S') {
			if (s[i] == 'o')
				a[i + 1] = a[i - 1];
			else
				turn(a, i);
		}
		else {
			if (s[i] == 'x')
				a[i + 1] = a[i - 1];
			else
				turn(a, i);
		}
	}

	if (a[0] == 'S')
		if (s[0] == 'o' && a.back() != a[1] || s[0] == 'x' && a.back() == a[1])
			return false;

	if (a[0] == 'W')
		if (s[0] == 'x' && a.back() != a[1] || s[0] == 'o' && a.back() == a[1])
			return false;

	if (a.back() == 'S')
		if (s.back() == 'o' && a[0] != a[n - 2] || s.back() == 'x' && a[0] == a[n - 2])
			return false;

	if (a.back() == 'W')
		if (s.back() == 'x' && a[0] != a[n - 2] || s.back() == 'o' && a[0] == a[n - 2])
			return false;

	return true;
}

void print(vector<char>& a) {
	forn(i, n)
		cout << a[i];
	cout << endl;
}

int main() {
	cin >> n;

	cin >> s;

	vector<char> a(n);
	vector<char> b(n);
	vector<char> c(n);
	vector<char> d(n);
	a[0] = 'S', a[1] = 'S';
	b[0] = 'W', b[1] = 'W';
	c[0] = 'S', c[1] = 'W';
	d[0] = 'W', d[1] = 'S';

	if (sim(a)) {
		print(a);
		return 0;
	}

	if (sim(b)) {
		print(b);
		return 0;
	}

	if (sim(c)) {
		print(c);
		return 0;
	}

	if (sim(d)) {
		print(d);
		return 0;
	}

	cout << -1 << endl;
}

Measured memory_bytes: 896
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int dp[SIZE];
void update(int &x,int v){
    if(x==-1)x=v;
    else x=min(x,v);
}
int main(){
    MS1(dp);
    int h,n;
    R(h,n);
    dp[0]=0;
    REP(i,n){
        int x,y;
        R(x,y);
        for(int j=0;j<h;j++){
            if(dp[j]!=-1)update(dp[min(j+x,h)],dp[j]+y);
        }
    }
    W(dp[h]);
    return 0;
}


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

int main(){
	int s = 0, m = 0, h = 0;
	cin >> s;
	while(true){
		if(s >= 60){
			s -= 60;
			++m;
		}
		else
			break;
	}
	while(true){
		if(m >= 60){
			m -= 60;
			++h;
		}
		else
			break;
	}
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  vector<int> x(n), y(n);
  for (int i = 0; i < n; i++){
    cin >> x[i] >> y[i];
  }
  vector<int> xpos;
  for (int i = 0; i < n; i++){
    xpos.push_back(x[i]);
  }
  sort(xpos.begin(), xpos.end());
  xpos.erase(unique(xpos.begin(), xpos.end()), xpos.end());
  int xcnt = xpos.size();
  map<int, int> mpx;
  for (int i = 0; i < xcnt; i++){
    mpx[xpos[i]] = i;
  }
  for (int i = 0; i < n; i++){
    x[i] = mpx[x[i]];
  }
  vector<int> ypos;
  for (int i = 0; i < n; i++){
    ypos.push_back(y[i]);
  }
  sort(ypos.begin(), ypos.end());
  ypos.erase(unique(ypos.begin(), ypos.end()), ypos.end());
  int ycnt = ypos.size();
  map<int, int> mpy;
  for (int i = 0; i < ycnt; i++){
    mpy[ypos[i]] = i;
  }
  for (int i = 0; i < n; i++){
    y[i] = mpy[y[i]];
  }
  vector<vector<int>> S(ycnt + 1, vector<int>(xcnt + 1, 0));
  for (int i = 0; i < n; i++){
    S[y[i] + 1][x[i] + 1]++;
  }
  for (int i = 1; i <= ycnt; i++){
    for (int j = 1; j <= xcnt; j++){
      S[i][j] += S[i][j - 1];
    }
  }
  for (int j = 1; j <= xcnt; j++){
    for (int i = 1; i <= ycnt; i++){
      S[i][j] += S[i - 1][j];
    }
  }
  for (int i = 0; i < m; i++){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1 = lower_bound(xpos.begin(), xpos.end(), x1) - xpos.begin();
    y1 = lower_bound(ypos.begin(), ypos.end(), y1) - ypos.begin();
    x2 = upper_bound(xpos.begin(), xpos.end(), x2) - xpos.begin();
    y2 = upper_bound(ypos.begin(), ypos.end(), y2) - ypos.begin();
    cout << S[y2][x2] - S[y2][x1] - S[y1][x2] + S[y1][x1] << endl;
  }
}


Measured memory_bytes: 101376
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector <int>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)

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

    int n; cin >> n;
    int pos[n][2];
    REP(i, n) {
        cin >> pos[i][0] >> pos[i][1];
    }
    double sum = 0;
    REP(i, n-1) {
        FOR(j, i+1, n) {
            sum += sqrt((pos[i][0]-pos[j][0])*(pos[i][0]-pos[j][0]) + (pos[i][1]-pos[j][1])*(pos[i][1]-pos[j][1]));
        }
    }
    cout << fixed << setprecision(10) << 2*sum/n << "\n";
}


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

int main ()
{
    int a,b,cnt=0;
    char s[20];

    cin>>a>>b;

    for(int i=0; i<(a+b+1); i++)
    {
        cin>>s[i];
        if(s[i] == '-') cnt++;
    }

    if(s[a] !='-' || cnt>1 )
    {
        cout<<"No"<<endl;
    }
    else cout<<"Yes"<<endl;




return 0;
}


Measured memory_bytes: 256
def dif(h):
  return (abs(A - (T-l[0]*0.006)))
  

N=int(input())
T,A=map(int,input().split())
l=[int(i) for i in input().split()]
d=[]
for i in l:
  d.append((abs(A - (T-i*0.006))))
print(d.index(min(d))+1)


Measured memory_bytes: 3060
# ABC 134 C
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
B = sorted(A)

if B[-1] != B[-2]:
    t = A.index(B[-1])
    for i in range(N):
        if i == t:
            print(B[-2])
        else:
            print(B[-1])
else:
    for i in range(N):
        print(B[-1])

Measured memory_bytes: 19108
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int n; char s[SZ];
int rp[SZ];
int main()
{
	cin>>n>>s;
	for(int i=0;i<=1;i++)
	{
		for(int j=0;j<=1;j++)
		{
			rp[0]=i; rp[1]=j;
			for(int k=1;k+1<n;k++)
			{
				int r=(s[k]=='x')^rp[k];
				rp[k+1]=rp[k-1]^r;
			}
			bool good=1;
			for(int k=0;k<n;k++)
			{
				int r=(s[k]=='x')^rp[k];
				if(rp[(k+1)%n]!=(rp[(k+n-1)%n]^r))
					good=0;
			}
			if(good)
			{
			for(int k=0;k<n;k++)
			{
				if(rp[k]) putchar('W');
				else putchar('S');
			}
			exit(0);
			}
		}
	}
	puts("-1");
}


Measured memory_bytes: 768
import std.stdio, std.range, std.conv, std.string, std.array, std.functional, std.math;
import std.algorithm.comparison, std.algorithm.iteration, std.algorithm.mutation, std.algorithm.searching, std.algorithm.setops, std.algorithm.sorting;
import std.container.binaryheap;
import std.typecons; 

void main()
{
    const input = readln().strip.to!(long);

    writeln(input/2 * (input/2 + input%2));
}

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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
#define F first
#define S second
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 60;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  int k; cin >> k;
  rep(i, k)cout << "ACL";
  cout << endl;
  return 0;
}


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

using namespace std;




int main(){
  vector<int> primes;
  primes.push_back(2);
  for(int i=3;i<200000; i++){
    bool flag = true;
    for(auto x: primes) if((i % x) == 0){flag=false; break;}
    if(flag) primes.push_back(i);
  }
  int n; cin >> n;
  for(int i=0;i<200000;i++){
  	if(n <= primes[i]){
      cout << primes[i] << endl;
      return 0;
    }
  }
  return 0;
}


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

using namespace std;
using ll = long long;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount

int H, W;
int dx[] = {1, 0}, dy[] = {0, 1};
char grid[10][10];

void dfs(int x, int y){
    bool flg = true;
    grid[y][x] = '.';
    for (int i = 0; i < 2; i++) {
        int nx = x + dx[i], ny = y + dy[i];
        if(nx>=W||nx<0||ny>=H||ny<0)
            continue;
        if(grid[ny][nx]=='#'){
            flg = false;
            dfs(nx, ny);
            grid[ny][nx] = '#';
        }
    }

    if(flg){
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if(grid[i][j]=='#')
                    return;
                if(i==H-1&&j==W-1){
                    puts("Possible");
                    exit(0);
                }
            }
        }
    }

    return;
}

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> grid[i][j];
        }
    }

    dfs(0, 0);

    puts("Impossible");

    return 0;
}

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

int main()
{
  string str;
  bool a, b;
  a = b = false;

  cin >> str;
  int m = str.size();
  for (int i = 0; i < m; i++){
    if (str[i] == 'C')  a = true;
    if (a && str[i] == 'F') b = true;
  }

  if (b)  cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256