akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

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

bool prime(int n) {
  for (int i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0) { return false; }
  }
  return n != 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; }

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  string s;
  cin >> s;

  ll cnt = 0;
  ll ans = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'B' && s[i+1] == 'C') {  // "BC" pair.
      ans += cnt;
      ++i; // We consider this as pair, so skip C.
    } else if (s[i] == 'A') {
      ++cnt;
    } else {  // "B" or "C" alone.
      cnt = 0;  // reset count.
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 764
n = int(input())
sp = []
for i in range(n):
    s,p = input().split()
    sp.append([s,int(p), i+1])
sp.sort()
ans = [sp[0][2]]
b = sp[0][0]
for s,p,i in sp[1:]:
    if b == s:
        ans.append(i)
    else:
        for x in ans[::-1]: print(x)
        b = s
        ans = [i]
if ans:
    for x in ans[::-1]: print(x)

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

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

Measured memory_bytes: 1024
import numpy as np
import math
import collections
import fractions
import itertools

def solve():
    n, m = map(int, input().split())
    cave = [list(map(int, input().split())) for i in range(m)]
    g = [[] for i in range(n)]
    for i in cave:
        g[i[0]-1].append(i[1])
        g[i[1]-1].append(i[0])
    que = collections.deque()
    ans = [-1]*n
    que.append(1)
    ans[0] = 0
    while(len(que)!=0):
        state = que.popleft()
        for i in g[state-1]:
            if ans[i-1] == -1:
                ans[i-1] = state
                que.append(i)
    if -1 in ans:
        print("No")
    else:
        print("Yes")
        for i in range(1,n):
            print(ans[i])
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 75224
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const [k, s] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

const ans = () => {
  let x = (y = z = 0)
  let count = 0
  for (let i = 0; i <= k; i++) {
    x = i
    for (let j = 0; j <= k; j++) {
      y = j
      z = s - (x + y)
      if (0 <= z && z <= k) {
        count++
      }
    }
  }

  return count
}

console.log(ans())


Measured memory_bytes: 7500
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
using namespace std;
using ll = long long;
const int mod = 1000000007;

ll top(ll N){
    while(true){
        if(N/10==0)break;
        N/=10;
    }
    return N;
}
ll bottom(ll N){
    return N%10;
}

int main(){
    ll N;
    cin>>N;
    map<pair<ll,ll>,ll>mp;
    for(ll i=1;i<=N;i++){
        // cout<<"N:"<<i<<", top:"<<top(i)<<endl;
        mp[make_pair(top(i),bottom(i))]++;
    }
    ll res=0;
    for(ll i=1;i<=9;i++){
        for(ll j=1;j<=9;j++){
           res+= mp[make_pair(i,j)]*mp[make_pair(j,i)];
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using lint = long int;
using llint = long long int;
using namespace std;

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

    while (true) {
        int count = 0;
        int n, x;
        cin >> n >> x;
        if (n == 0 && x == 0) {
            break;
        }

        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                for (int k = j + 1; k <= n; k++) {
                    if (i + j + k == x) {
                        count++;
                    }
                }
            }
        }
        cout << count << endl;
    }

    return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;

int N;
const int MN = 100000;
typedef pair<ll,ll> P;
vector<vector<P>> G;
int sz[MN];

int mx[MN];

ll ans;
bool is;

void dfs(int v,int p=-1){
	sz[v] = 1;
	for(P e:G[v]){
		int u = e.fs;
		ll c = e.sc;
		if(u==p) continue;
		dfs(u,v);
		sz[v] += sz[u];
		chmax(mx[v],sz[u]);

		int n = min(sz[u],N-sz[u]);

		ans += 2*n*c;
		if(n*2 == N){
			is = 1;
			ans -= c;
		}
	}
	chmax(mx[v],N-1-sz[v]);
}

int main(){
	cin>>N;
	G.assign(N,vector<P>());
	rep(i,N-1){
		ll a,b,c;
		cin>>a>>b>>c;
		a--,b--;
		G[a].pb(P(b,c));
		G[b].pb(P(a,c));
	}
	dfs(0);
	if(!is){
		int c = 0;
		rep(i,N){
			if(mx[c]>mx[i]) c = i;
		}
		ll mn = 1e18;
		for(P e:G[c]){
			chmin(mn,e.sc);
		}
		ans -= mn;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 15360
#include <bits/stdc++.h>
#define CFS cin.tie(nullptr);ios::sync_with_stdio(false);
#define CST(x) cout<<fixed<<setprecision(x);
using namespace std;
constexpr int IINF = numeric_limits<int>::max();
constexpr long LINF = numeric_limits<long>::max();
constexpr int MOD = (int) 1e9 + 7;
// constexpr int MOD = 998244353;

int main(){
    string s;
    cin >> s;
    if (s == "ABC") cout << "ARC" << "\n";
    else cout << "ABC" << "\n";
}

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

int T[26];

int main()
{
	string str, cur, ans;
	int flag = 0;
	cin >> str;
	for (int i = 0, len = str.length(); i <= len; i++) {
		for (int j = (i == len ? 0 : str[i]-'a'+1); j < 26; j++)
			if (!T[j]) {
				if (!flag) flag = 1, ans = cur+char(j+'a');
				else ans = min(ans, cur+char(j+'a'));
				break;
			}
		if (i == len) 
			break;
	        cur = cur+str[i];
		T[str[i]-'a'] = 1;
	}
	if (flag == 0) puts("-1");
	else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.*
import java.util.*

object FastReader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    private var st: StringTokenizer = StringTokenizer(br.readLine())

    fun next(): String {
        if (!st.hasMoreElements() ) {
            try {
                st = StringTokenizer(br.readLine());
            } catch (e: IOException) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    fun nextInt() = next().toInt()

    fun nextLong() = next().toLong()

    fun nextDouble() = next().toDouble()
}


fun main(args: Array<String>) = Scanner(System.`in`).use {
    FastReader.nextInt()
    val a = FastReader.nextInt()
    val b = FastReader.nextInt()
    val s = FastReader.next()!!

    var c1 = 0
    var c2 = 0
    for (c in s) {
        if ((c == 'a') && (c1 < a+b)) {
            println("Yes")
            c1++
        } else if ((c == 'b') && (c1 < a+b) && (c2 < b)) {
            println("Yes")
            c1++
            c2++
        } else {
            println("No")
        }
    }
}

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

int main(){
  
  int N,M;
  cin >>N>>M;
  priority_queue<int> q;
  rep(i,N){
    int a;
    cin >>a;
    q.push(a);
  }
  rep(i,M){
    int a = q.top(); q.pop();
    q.push(a/2);
  }
  ll ans = 0;
  rep(i,N){
    ans += q.top(); q.pop();
  }
  cout << ans << endl;
}


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

int main(){
  ll n,s,w,q;
  while(cin >> n >> s >> w >> q, n){
    vector<int> a(n);
    ll g = s;
    rep(i,n){
      a[i] = (g/7) % 10;
      g = (g/2) ^ ((g%2)*w);
    }

    ll ans = 0, non_zeros = 0;
    if(q==2 || q==5){
      rep(i,n){
	if(a[i])non_zeros++;
	if(a[i]%q == 0)ans += non_zeros;
      }
    }else{
      reverse(a.begin(),a.end());
      map<ll,ll> memo;
      memo[0] = 1;
      ll rem = 0, k = 1;
      rep(i,n){
	rem = (rem + a[i] * k) % q;
	(k *= 10) %= q;
	if(a[i])ans += memo[rem];
	memo[rem]++;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 7120
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
typedef double db;
const db pi=acos(-1.0);
int n,L,a[3010];db A,B;
int main(){
	scanf("%d%d",&n,&L);
	rep(i,1,n) scanf("%d",a+i);
	sort(a+1,a+n+1);
	rep(i,1,n) rep(j,i+1,n){
		db x=cos(db(a[i]+a[j])/L*pi),y=sin(db(a[i]+a[j])/L*pi);
		int k1=j-i-1,k2=n-2-k1;
		A+=(k2-k1)*x,B+=(k2-k1)*y;
	}
	A=A/n/(n-1)/(n-2)*6;
	B=B/n/(n-1)/(n-2)*6;
	printf("%.15lf %.15lf",A,B);
	return 0;
}

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

long long func(long long *a, int i, long long x){
	long long dif = 0;
	if(i == 0){
		if(a[i] > x){
			dif = a[i]-x;
		}
	}
	else if(a[i-1]+a[i] > x){
		dif = (a[i-1]+a[i])-x;
	}
	a[i] -= dif;
	return dif;
}

int main(void){
	long long N,x,count;
	cin>>N>>x;
	long long a[N];
	for(int i = 0; i<N; i++){
		cin>>a[i];
	}
	count = 0;
	for(int i = 0; i<N; i++){
		count += func(a,i,x);
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
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;
}


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	vector<int> one, to;
	rep(i, m) {
		cin >> a[i] >> b[i];
		if (a[i] == 1) one.push_back(b[i]);
		if (a[i] == n) to.push_back(b[i]);
		if (b[i] == 1) one.push_back(a[i]);
		if (b[i] == n) to.push_back(a[i]);
	}
	sort(one.begin(), one.end());
	sort(to.begin(), to.end());
	bool ans = false;
	rep(i, one.size()) {
		if (upper_bound(to.begin(), to.end(), one[i]) - lower_bound(to.begin(), to.end(), one[i]) > 0) {
			ans = true;
			break;
		}
	}
	cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
	return 0;
}

Measured memory_bytes: 5084
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	int ans = 0;
	rep(i, n){
		while(a[i] % 2 == 0) ans++, a[i] /= 2;
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
// Problem : B - String Palindrome
// Contest : AtCoder Beginner Contest 159
// URL : https://atcoder.jp/contests/abc159/tasks/abc159_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

bool isPal(string s){
	int len = s.size();
	for(int i = 0; i < len / 2; i++)
		if (s[i] != s[len - i - 1]){
			return false;
		}
	return true;
}
int main(){
	string s;
	cin >> s;
	int len = s.size();
	
	if (isPal(s) && isPal(s.substr(0,(len - 1) / 2)) && isPal(s.substr((len + 3)/2-1))){
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}
	
	
	return 0;	
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
r=list(range(1,n+1))
s=0
m=0
if l==r:
  m=1
  print("YES")
else:
  while s<n:
    for i in range(n):
      r=list(range(1,n+1))
      d=r[s]
      r[s]=r[i]
      r[i]=d
      if l==r:
        print("YES")
        s=n
        m=1
        break
    s=s+1
if not m==1:
  print("NO")

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

typedef  long long ll;
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;}

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

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int temp=i*1.08;
        if(temp==n){
            cout<<i<<endl;
            return 0;
        }
    }
cout<<":("<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}

int main(void){
  fast_io
  int n;
  cin>>n;
  vector<Pll> hoge;
  rep(i,n){
    Pll p;
    ll x,l;
    cin>>x>>l;
    hoge.push_back({x,l});
  }
  sort(all(hoge));
  int ans = 0;
  ll r = -LINF;
  rep(i,n){
    ll ml = hoge[i].first - hoge[i].second;
    ll mr = hoge[i].first + hoge[i].second;
    if(r <= ml){
      ans++;
      r = max(r, mr);
    }else{
      r = min(r, mr);
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

int main(){
    char s[20000000],t[200000000];
    scanf("%s", s);
    scanf("%s", t);
    int a = 0;
    int b = 0;
    while(s[a] != '\0'){
        if(t[a] != s[a]){
            b++;
        }
        a++;
    }
    printf("%d\n", b);
    return 0;


}


Measured memory_bytes: 2112
#include <cstdio>
const int MAXN = 105;
char S[MAXN];
int N;

bool solve() {
    if (N & 1) {
        return false;
    }
    int K = N / 2;
    for (int i = 0; i < K; ++i) {
        if (S[i] != S[i+K]) {
            return false;
        }
    }
    return true;
}

int main() {
    scanf(" %d%s", &N, S);
    puts(solve() ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int index = Integer.parseInt(sc.nextLine());
        String[] str = sc.nextLine().split(" ");
 
        for(int loopcnt = str.length; loopcnt > 0; loopcnt--){
            if( loopcnt != 1 ) System.out.print(str[loopcnt-1] + " ");
            else System.out.print(str[loopcnt-1]);
        }
        System.out.println();
    }
}

Measured memory_bytes: 25952
#include "bits/stdc++.h"
#define INF 0x7fffffff
using namespace std;
vector<int> a; 
int main()
{
	int i,n,x,sum=0,count,minn=INF;
	scanf("%d %d",&n,&x);
	a.resize(n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
		if(minn>a[i])
		{
			minn=a[i];
		}
	}
	count=n;
	x-=sum;
	count+=x/minn;
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
int main() {
	ll h,w;
	cin>>h>>w;
	if(h==1 || w==1) cout<<1;
	else 
	cout<<((w+1)/2)*((h+1)/2) + (h/2)*(w/2);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N;
  cin >> N;
  cout << N/3 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){ 

int i,kazu; 

long sum=0,a,min=1000001,max=-1000001; 

scanf("%d",&kazu);  

for(i=0;i<kazu;i++){ 

scanf("%ld",&a); 

if(a<=min){ 

min=a; 

} 

if(a>=max){ 

max=a; 

} 

sum=sum+a; 

} 

printf("%d %d %ld\n",min,max,sum); 

return 0;

}
 

Measured memory_bytes: 600
import java.util.*;
import java.io.*;
 
public class Main{
    static PrintWriter out = new PrintWriter(System.out);
 
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] X = new int[N];
        double average = 0;
        for(int i = 0; i < N; i++){
            X[i] = Integer.parseInt(sc.next());
            average = average + X[i];
        }
        average = Math.round(average/N);
        int sum = 0;
        for(int i = 0; i < N; i++){
            sum = sum + (X[i]-(int)average)*(X[i]-(int)average);
        }

        System.out.println(sum);
       
    }
} 

Measured memory_bytes: 22868
import math
N = int(input())
if N == 1:
    print(0)
    exit()
 
#素数リスト
M = int(math.sqrt(N))+1
sosu = [2]
a = 0
for i in range(3,M,2):
  if sosu[a] <= math.sqrt(i):
    a += 1
  hantei = (i%x for x in sosu[:a+1])
  if 0 not in hantei:
    sosu.append(i)
 
soin = []
for p in sosu:
    for j in range(1,N+1):
        pe = p**j
        if N % pe != 0:
            if pe != p:
                soin.append(j-1)
                N //= p**(j-1)
            break

Ans = 0
if N != 1:
    Ans += 1

for k in soin:
    if k == 1:
        Ans += 1
        continue
    for n in range(1,k+1):
        if (n*(n+1))//2 > k:
            Ans += n-1
            break
print(max(Ans,1))

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

int main() {
  int S,s1,s2,s3;
  cin >> S ;

  s1=S/100;
  s2=(S/10)-s1*10;
  s3=S-s1*100-s2*10;

  cout << s1+s2+s3 <<endl;
}



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

int main(){

    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1;i <= n; i += 2){
        int y = 0;
        for(int j = 1; j <= i; ++j){
            if(i%j == 0)++y;
        }
        if(y == 8)++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mp make_pair
#define pii pair<int,int>
using namespace std;

pii e[2010];
vector<int> g[2010];
int n,k,cnt,ans=0x3f3f3f3f,d[2020][2020];

void dfs(int kd,int now,int fa,int dis)
{
	d[kd][now]=dis;
	if(dis>k/2) cnt++;
	for(int i=0; i<g[now].size(); i++)
	{
		if(g[now][i]==fa) continue;
		dfs(kd,g[now][i],now,dis+1);
	}
}

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1; i<n; i++)
	{
		int from,to;
		scanf("%d%d",&from,&to);
		g[from].push_back(to);
		g[to].push_back(from);
		e[i]=mp(from,to);
	}
	for(int i=1; i<=n; i++)
	{
		cnt=0;
		dfs(i,i,0,0);
		ans=min(ans,cnt);
	}
	if(k&1)
	{
		for(int i=1; i<n; i++)
		{
			cnt=0;
			for(int j=1; j<=n; j++)
			{
				if(min(d[e[i].first][j],d[e[i].second][j])>k/2) cnt++;
			}
			ans=min(ans,cnt);
		}
	}

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


Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


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

    ll div = n / (a + b);
    ll mdiv = n % (a + b);

    ll ans = 0;
    ans += div * a;
    ans += (mdiv >= a) ? a : mdiv;

    cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;

int vx[4] = {0,1,0,-1};
int vy[4] = {1,0,-1,0};
int re[55][55];

void dfs(vector<vector<char>> map){
    queue<int> qx;
    queue<int> qy;
    qx.push(1);
    qy.push(1);

    while(!qx.empty()){
        int x = qx.front();qx.pop();
        int y = qy.front();qy.pop();
        rep(i,4){
            int nx = x + vx[i];
            int ny = y + vy[i];
            if(re[nx][ny] != 0) continue;
            if(map[nx][ny] != '#'){
                re[nx][ny] = re[x][y]+1;
                qx.push(nx);
                qy.push(ny);
            }

        }
    }
    return;

}

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

    int h,w;
    cin >> h >> w;
    vector<vector<char>> map(h+2,vector<char> (w+2));
    int sum = 0;
    rep(i,h+2){
        rep(j,w+2){
            map[i][j] = '#';
        }
    }
    for(int i = 1;i < h+1;++i){
        for(int j = 1;j < w+1;++j){
            char c;
            cin >> c;
            map[i][j] = c;
            if(map[i][j] == '#'){
                sum++;
            }
        }
    }
    dfs(map);
    if(re[h][w] == 0){
        cout << -1 << endl;
        return 0;
    }
    int ans = re[h][w] + 1;
    ans = h*w - ans - sum;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws Exception{
        String str[];
        int a, b;

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        str = br.readLine().split(" ");
        a = Integer.parseInt(str[0]);
        b = Integer.parseInt(str[1]);

        if(a < b){
        	System.out.println("a < b");
        }else if(a > b){
        	System.out.println("a > b");
        }else if(a == b){
        	System.out.println("a == b");
        }
    }
}

Measured memory_bytes: 24188
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N, K = ni()
    val H = na(N)
    val cost = Array.fill[Int](N)(1e9.toInt + 10)
    cost(0) = 0
    REP(N) { i =>
      REP(K, 1) { k =>
        if (i + k < N) cost(i + k) = min(cost(i + k),  cost(i) + abs(H(i) - H(i + k)))
      }
    }
    out.println(cost(N - 1))
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }


  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

Measured memory_bytes: 37844
/**
 * Created by karayuu on 2019/05/23
 */
fun main(args: Array<String>) {
    while (true) {
        var string = readLine()!!
        if (string == "-") {
            return
        }
        val count = readLine()!!.toInt()
        for (i in 1..count) {
            val h = readLine()!!.toInt()
            val lower = string.take(h)
            val upper = string.drop(h)

            string = upper + lower
        }
        println(string)
    }
}



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

a=list(map(int,input().split()))
b=list(map(int,input().split()))

a_min=min(a)
b_min=min(b)

tmp=a_min+b_min

for i in range(c):
  i,j,k=map(int,input().split())
  i-=1
  j-=1
  tmp=min(tmp,a[i]+b[j]-k)
print(tmp)

Measured memory_bytes: 18736
#include <stdio.h>
 #include <stdlib.h>
 #include <wchar.h>
 int main()
{
	int i,j,k,l,n,max,now;
	wchar_t moji[10000];
	scanf("%ls",moji);
	n=wcslen(moji);
	/*printf("%d",n);*/
	int henka [n];
	for(i=0;i<=n-1;i++)
	{
		if(moji[i]=='A'||moji[i]=='T'||moji[i]=='C'||moji[i]=='G')
		henka[i]=1;
		else
		henka[i]=0;
	}
	/*for(i=0;i<=n-1;i++)
	{
	   printf("%d\n",henka[i]);
	}*/
	max=0;
	now=0;
	for(i=0;i<=n-1;i++)
	{ /*  printf("%d%d",now,max);*/
		if(henka[i]==1)
		{
			now=now+1;
			if(max<=now)
			{
				max=now;
			}
			
		}else
		{
			now=0;
		}
	}
	printf("%d",max);
	
}
	

Measured memory_bytes: 128
import sys

l=input().split()
N=int(l[0])
M=int(l[1])
X=int(l[2])

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


migi=0
hidari=0
for item in l:
	if(item>X):
		migi+=1
	else:
		hidari+=1

if(migi>hidari):
	print(hidari)
else:
	print(migi)

Measured memory_bytes: 3064
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include <ctime>
#include <map>
#include <math.h>
#include <cstdio>
#include <set>
#include <deque>
#include <memory.h>
#include <queue>

#pragma comment(linker, "/STACK:64000000")
typedef long long ll;

using namespace std;

const int MAXN = 1 << 18;
const int MOD = 1; // 1000 * 1000 * 1000 + 7;
const int INF = 2e9;

int main() {
#ifdef _MSC_VER
	freopen("input.txt", "r", stdin);
#endif

	int n;
	while (cin >> n) {
		vector<int> a(n);
		for (int i = 0; i < n; i++) cin >> a[i];

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

	return 0;
}

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

#define ll long long int

using namespace std;

int inf=1e9+5;

unordered_map<ll,int> s;
vector<ll> pot;
ll h,w;
void goo(ll x)
{
    ll H,W;
    W=x%inf;
    x-=x%inf;
    H=x/inf;
    for(int i=H-2;i<=H;i++)
    {
        for(int j=W-2;j<=W;j++)
        {
            if(i>=1 && i<=h && j>=1 && j<=w)
            {
                ll res=(ll)i*inf+j;
                pot.push_back(res);
            }
        }
    }
}

int cnt[10];

void doo(ll x)
{
    ll H,W;
    W=x%inf;
    x-=x%inf;
    H=x/inf;
    int res=0;
    if(H>=1 && H+2<=h && W>=1 && W+2<=w)
    {
        for(int i=H;i<=H+2;i++)
        {
            for(int j=W;j<=W+2;j++)
            {
                ll akt=(ll)i*inf+j;
                res+=s[akt];
            }
        }
    }
    else return;
    cnt[res]++;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>h>>w;
    int n; cin>>n;
    vector<ll> a;
    for(int i=0;i<n;i++)
    {
        int x,y; cin>>x>>y;
        a.push_back((ll)x*inf+y);
        s[a[i]]=1;
    }
    for(int i=0;i<n;i++)
    {
        goo(a[i]);
    }
    sort(pot.begin(),pot.end());
    for(int i=0;i<pot.size();i++)
    {
        if(i==0 || pot[i]!=pot[i-1])
        {
            doo(pot[i]);
        }
    }
    ll cnn=0;
    for(int i=1;i<=9;i++)
    {
        cnn+=cnt[i];
    }
    cout<<(ll)(w-2)*(h-2)-cnn<<endl;
    for(int i=1;i<=9;i++) cout<<cnt[i]<<endl;
    return 0;
}


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

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

typedef long long ll;
using namespace std;

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

  int A, B;
  cin >> A >> B;

  if ((1 <= A && A <= 9) && (1 <= B && B <= 9)) {
    cout << A * B << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

//20180508
//05

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

		int length = scanner.nextInt();
		long tmp = 0;
		long max = -1000000;
		long min = 1000000;
		long sum = 0;

		for(int i = 0;i < length;i++) {
			tmp = scanner.nextLong();
			max = Math.max(max, tmp);
			min = Math.min(min, tmp	);
			sum += tmp;
		}

		System.out.println(min + " " + max + " " + sum);

    	scanner.close();
    }
}


Measured memory_bytes: 42544
from collections import Counter, defaultdict


def solve():
    N = int(input())
    
    A = [input() for _ in range(N)]
    count_A = Counter(A)
    
    M = int(input())
    B = [input() for _ in range(M)]
    count_B = Counter(B)
    for k,v in count_B.items():
        if k in count_A:
            count_A[k] -= v
    
    ret = count_A.most_common()[0][1]
    print(max(ret,0))
    
solve()

Measured memory_bytes: 3316
#include<stdio.h>

int main(void){

	int n, i, j, num, cards[4][13] = {};
	char pattern, design[4] = "SHCD";
	enum {S, H, C, D};
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%c", &pattern);
		scanf("%c %d", &pattern, &num);
		switch (pattern) {
			case 'S':
				cards[S][num-1] = 1;
				break;
			case 'H':
				cards[H][num-1] = 1;
				break;
			case 'C':
				cards[C][num-1] = 1;
				break;
			default:
				cards[D][num-1] = 1;
		}
	}
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 13; j++) {
			if (!cards[i][j]) {
				printf("%c %d\n", design[i], j + 1);
			}
		}
	}
    return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

const double EPS = 1e-6;

int main()
{
    ios::sync_with_stdio(false);

    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    double ans = -1;
    int all = 0, sugar = 0;

    for (int aa=0; aa*A*100<=F; aa++) {
        int a = aa * A;
        for (int bb=0; bb*B*100<=F; bb++) {
            int b = bb*B;
            for (int cc=0; cc*C<=(a+b)*E; cc++) {
                for (int dd=0; dd*D<=(a+b)*E; dd++) {
                    int c = cc*C, d = dd*D;
                    if (!a && !b && !c && !d) continue;
                    if (c + d > (a + b) * E) break;
                    if ((a + b) * 100 + (c + d) > F) break;

                    double r = (c + d) * 100.0 / ((a + b) * 100 + c + d);
                    // DUMP(r);
                    if (r > ans + EPS) {
                        ans = r;
                        all = (a + b) * 100 + c + d;
                        sugar = c + d;
                    }
                }
            }
        }
    }

    cout << all << " " << sugar << endl;
    assert(all > 0);
}

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

using namespace std;

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

long int f(string a){
    long int res = 0;
    long int num = 0;
    rep(i, a.size()){
        if (a[i] == '+'){
            res += num;
            num = 0;
        }else{
            num *= 10;
            num += a[i] - '0';
        }
        
    }
    res += num;
    return res;
}


int main(){
    string s;
    cin >> s;
    long int ans = 0;
    for (long int i = 0; i < (1 << (s.size() - 1)); i++){
        string a;
        rep(j, s.size()){
            a += s[j];
            if (((i >> j) & 1) == 1){
                a += '+';
            }
        }
        ans += f(a);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
s = input()

s1 = s.replace('x', '')

# 先に回文にできないケースを除外する
if s1 != s1[::-1]:
    print(-1)
    exit()

l, r = 0, len(s)-1
ans = 0
while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    elif s[l] == 'x':
        l += 1
        ans += 1
    elif s[r] == 'x':
        r -= 1
        ans += 1
    else:
        AssertionError('ここには来ないはず')
        pass

print(ans)

Measured memory_bytes: 9136
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int k = in.nextInt();
        int x =0;
        if(k<=a){
            System.out.println(k);
        }
        else{
            x=a;
            k-=a;
            if(k<=b){
                System.out.println(x);
            }
            else{
                k-=b;
                
                System.out.println(x+(k*-1));
            }
        }
    }
}

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

using namespace std;

typedef long long LL;

int main()
{
    LL n,x,m;
    cin>>n>>x>>m;
    vector<int>pos(m+1,-1);
    vector<LL>rest(m+1);
    int nr=1;
    pos[x]=0;
    rest[0]=x;
    x=(x*x)%m;
    while(pos[x]==-1)
        rest[nr]=x,
        pos[x]=nr,
        ++nr,
        x=(x*x)%m;
    LL serie=0;
    int start=pos[x];
    for (int i=start;i<nr;++i)
        serie+=rest[i];
    LL s=0;
    for (int i=0;i<n && i<start;++i)
        s+=rest[i];
    if (n<=start)
    {
        cout<<s;
        return 0;
    }
    n-=start;
    nr-=start;
    LL nrserii=n/nr;
    LL ramase=n%nr;
    s=s+nrserii*serie;
    for (int i=0;i<ramase;++i)
        s=s+rest[start+i];
    cout<<s;
}



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

int main() {
  int N,L;
	cin >> N >> L;
	int sum = 0;
	int absminv = abs(L);
	int minv = L;
	for(int i = 1;i <= N; i++) {
		int tmp = L + i - 1;
		if(absminv > abs(tmp)){
			absminv = abs(tmp);
			minv = tmp;
		}
		sum += tmp;
	}
	sum -= minv;
	cout << sum << endl;
}

Measured memory_bytes: 256
from collections import deque
n = input()
d = deque()
for i in range(int(n)):
	command = input()
	if command[0] == 'i':
		d.appendleft(command[7:])
	else:
		if command[6] == " ":
			if  command[7:] in d:
				d.remove(command[7:])
		else:
			if command[6] == 'L':
				d.pop()
			else:
				d.popleft()
for _ in range(len(d)-1):
	print(d.popleft(), end=" ")
print(d.pop())

Measured memory_bytes: 71632
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<unordered_map>
using namespace std;

int main()
{   
    long long K;
    string S;

    cin >> K >> S;
    
    if(S.length() <= K){
        cout << S << endl;
    }else{
        cout << S.substr(0, K) << "..." << endl;
    }
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
string s;
int sumt,sums,sum;
int main()
{
    std::ios::sync_with_stdio(false);
    cin>>s;
    int n=s.size();
    for(int i=0;i<n;i++)
    {
        if(s[i]=='S') sums++;//计算S的个数
        else if(sums) sumt++;//如果有S，就计算T的个数（类似于有左括号再算右括号）
        if(sums>=sumt)//如果此时的S数量比T大了或相等(这里写的不大明白
        {
            sum+=min(sums,sumt)*2;//计算需要删去的数量
            sums-=min(sums,sumt);//减去用掉的S数
            sumt=0;//减去用掉的T数
        }
    }
    cout<<n-sum<<endl;
    return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
char s[105][105];
int a[105], b[105];
int main(){
    int h, w;
    scanf("%d%d", &h, &w);
    for (int i = 0; i<h; i++) {
        scanf("%s",s[i]);
    }
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    for(int i = 0; i<h; i++){
        int cnt = 0;
        for (int j = 0; j<w; j++) {
            if (s[i][j]=='.') {
                cnt++;
            }
        }
        if (cnt == w) {
            a[i]=1;
        }
    }
    for(int i = 0; i<w; i++){
        int cnt = 0;
        for (int j = 0; j<h; j++) {
            if (s[j][i]=='.') {
                cnt++;
            }
        }
        if (cnt == h) {
            b[i]=1;
        }
    }
    for (int i = 0; i<h; i++) {
        int cnt = 0;
        for (int j = 0; j<w; j++) {
            if (a[i]==0&&b[j]==0) {
                cnt = 1;
                printf("%c", s[i][j]);
            }
        }
        if (cnt) {
            printf("\n");
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
using ll = long long;

ll n,a[3],ans=100000000000;
vector<ll> l(8);
void calc(vector<int> v){
    ll bamboo[3]={},temp=0;
    for(int i=0;i<n;i++){
        if(v[i]!=3){
            if(bamboo[v[i]]==0) bamboo[v[i]]+=l[i];
            else{
                    bamboo[v[i]]+=l[i];
                    temp+=10;
            }
        }
    }
    for(int i=0;i<3;i++){
        if(bamboo[i]==0)    return;
        temp += abs(bamboo[i]-a[i]);
    }
    ans = min(ans,temp);
    return;
}
void dfs(int depth,vector<int> v){
    if(depth == n){
          calc(v);
          return;
    }
    else{
        for(int i=0;i<4;i++){
            v[depth] = i;
            dfs(depth+1,v);
        }
        return;
    }
}

int main(){
    vector<int> v(8);
    cin >> n >> a[0] >> a[1] >> a[2];
    for(ll i=0;i<n;i++) cin >> l[i];
    dfs(0,v);
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]


    S = input()
    T = input()
    c = 0
    for s,t in zip(S,T):
        if s==t:
            c += 1
    print(c)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38448
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;cin >> S;
  int N = S.size();
  string ans = "No";
  if (N >= 4) {
    if (S.at(0) == 'Y' && S.at(1) == 'A' && S.at(2) == 'K' && S.at(3) == 'I') {
      ans = "Yes";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define REP(i,n) for (lint i = 0; i < (n); i++)
#define REP1(i,n) for (lint i = 1; i < (n); i++)

int main(void){
    lint N;
    cin >> N;
    vector<lint> A(N);
    REP (i, N) cin >> A[i];
    vector<lint> B = A;
    sort(B.begin(), B.end());

    for (int i = 0; i < N; ++i) {
        lint ans = 0;
        if (A[i] != B[N-1]) {
            cout << B[N-1] << endl;
        } else {
            cout << B[N-2] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4736
def comb_list(n, r, mod):
    ret = [1]
    for i in range(1, r+1):
        ret.append(ret[-1] * (n+1-i) * pow(i, mod-2, mod) % mod)
    return ret

n,k = map(int,input().split())
mod = 10**9+7

r = min(k,n-1)
ans = 0
nCl = comb_list(n, r, mod)
n1Cl = comb_list(n-1, r, mod)

for i in range(r+1):
    ans = (ans + nCl[i] * n1Cl[i]) % mod

print(ans)


Measured memory_bytes: 18960
#include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{

	while(true)
	{
		string s;
		getline(cin,s);
		if(s=="."){break;}
		
		//かっこ以外を消去
		int i=0;
		while(i<s.length()){
			if(s[i]!='[' && s[i]!=']' && s[i]!='(' && s[i]!=')')
			{	s.erase(s.begin() + i); i--;}
			i++;}
		
		int x = s.length()/2;
		REP(i,x)
		{
			REP(i,s.length()-1)
			{
				if(	(s[i]=='[' && s[i+1]==']') || (s[i]=='(' && s[i+1]==')')	)
				{s.erase(s.begin()+i);
				s.erase(s.begin()+i);
				break;}
			}
		}
		if(s.length()==0)cout << "yes" <<endl;
		else cout << "no" << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
k = int(input())

lis = []

lis.append(1)
lis.append(2)
lis.append(3)
lis.append(4)
lis.append(5)
lis.append(6)
lis.append(7)
lis.append(8)
lis.append(9)

keta = 1

while len(lis) <= k:
    for j in [i for i in lis if len(str(i)) == keta]:
        if j % 10 == 0:
            lis.append( j * 10 )
            lis.append( j * 10 + 1 )
        elif j % 10 == 9:
            lis.append( j * 10 + 9 )
            lis.append( j * 10 + 8 )
        else:
            last = j % 10
            lis.append( j * 10 + last - 1 )
            lis.append( j * 10 + last )
            lis.append( j * 10 + last + 1 )
    keta += 1

lis.sort()
print(lis[k-1])

Measured memory_bytes: 12072
import java.util.Scanner;
public class Main {
  public static void main (String[]args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int C = sc.nextInt();
    int B[] = new int[M];
    int A[][] = new int[N][M];

    for(int i = 0; i<M; i++){
      B[i] = sc.nextInt();
    }
    for(int i = 0; i<N; i++){
      for(int j = 0; j<M; j++){
        A[i][j] = sc.nextInt();
      }
    }
    int ans=0;
    
    for(int i = 0; i<N; i++){
      int sum=0;
      for(int j = 0; j<M; j++){
        sum += A[i][j]*B[j];
      }
      if(sum + C > 0) {
        ++ans;
      }
    }
    System.out.println(ans);
  }
}

//i...M(よこ)
//j...N(たて)


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

using namespace std;
using namespace std;
typedef long long ll;
typedef long double ld;
#define endl "\n"
#define all(v) v.begin(),v.end()
#define sz(v)  v.size()


void fast() {

    cin.tie(0);
    cin.sync_with_stdio(0);
}


int N = 1.5 * 1e7 + 5;

ll GCD(ll a, ll b) {
    if (!b)return a;
    return GCD(b, a % b);
}

ll fastExpo(ll a, ll b) {
    if (!b)return 1;
    ll half = fastExpo(a, b / 2);
    ll ans = (half * half);
    if (b & 1)return (ans * a);
    return ans;
}

int sumofdigits(int n) {
    int t = 0;
    while (n != 0) {
        t += n % 10;
        n /= 10;
    }
    return t;
}

ll fact(int n) {
    if (n <= 1)return 1;
    return n * fact(n - 1);
}


map<string,int>freq;

bool sorti(string &a,string &b){
    return freq[a]>freq[b];
}

int main() {
    fast();
    int n;cin>>n;
    vector<string>ans;
    int maxi=0;
    while(n--){
        string s;cin>>s;
        if(!freq[s])ans.push_back(s);
        freq[s]++;
        maxi=max(maxi,freq[s]);
    }
    int si=ans.size();
    vector<string>v;
    for (int k = 0; k <si ; ++k) {
        if(freq[ans[k]]==maxi)v.push_back(ans[k]);
    }
    sort(all(v));
    int si2=v.size();
    for (int j = 0; j <si2 ; ++j) {
        cout<<v[j]<<endl;
    }
}


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

int main(void){
    long double a,b,h,m;
    
    cin >> a >> b >> h >> m;
    long double s = (h * 60 + m) / 720 * 2 * acos(-1);
    long double l = m / 60 * 2 * acos(-1);
    long double angle = abs(l - s);
    printf("%20.20Lf\n",sqrt(a * a + b * b - 2 * a * b * cos(angle)));
}


Measured memory_bytes: 4108