akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

#define ANSS 200*333+195*666+1
int main(){
	int n;
	cin >> n;
	REP(i,n){
		int y,m,d;
		ll int ans = 0;
		cin >> y >> m >> d;
		y--;
		int t = y/3;
		ans += 200*t;
		ans += 195*(y-t);
		y++;
		if(y%3==0){
			m--;
			ans+= (m*20);
			ans+= d;
		}else{
			m--;
			ans+= ((m/2)*19+(m-m/2)*20);
			ans += d;
		}
		//cout << ANSS << endl;
		//cout << ans << endl;
		cout << ANSS - ans << endl;
	}
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define loop(i,a,n) for (int i = (a); (i) < (n); ++ (i))
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF (int)1e9
#define MOD 0
//#define int ll
using namespace std;
typedef vector<int> vi;

signed main(){
    int count[4] = {0,0,0,0},a;
    cin.tie(0);
    ios::sync_with_stdio(false);
    rep(i,6) {
        cin >> a;
        count[a-1]++;
    }
    rep(i,4) {
        if(count[i] == 3) {
            a = -1;
            break;
        }
    }
    if(a != -1) puts("YES");
    else puts("NO");
    return 0;
}

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

using namespace std;

int main() {
  int n,j,conta=0,contb=0;
  bool empate;
  string a,b;
  cin >> n;
  for(int i =0; i < n; i++){
    cin >> a >> b;
    j = 0;
    empate = false;
    while(a.length()>j && b.length()>j){
      if(int(a[j])<int(b[j])){
        contb+=3;
        empate = false;
        break;
      }
      else if(int(a[j])>int(b[j])){
        conta+=3;
        empate = false;
        break;
      }
      else{
        empate = true;
      }
      j++;
    }
    if(empate){
      if(a.length() == b.length()){
          conta++;
          contb++;
      }
      else if(a.length() > b.length()){
        conta+=3;
      }
      else{
        contb+=3;
      }
    }
  }
  cout << conta << " " << contb << endl;
}


Measured memory_bytes: 3160
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF 1e18//1234567890987654321
#define INF 1234567890
#define pb push_back
#define ins insert
#define f first
#define s second
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN 200006
#define MAXK 26
#define MAXX 15000006
#define ll long long int
#define ld long double
#define rep0(kk, l1, l2)for(ll kk = l1; kk < l2; kk++)
#define rep1(kk, l1, l2)for(ll kk = l1; kk <= l2; kk++)
#define forit(it, A) for(set<ll>::iterator it = A.begin(); it != A.end(); it++)
#define cr(x) cerr << #x << " = " << x << "\n";
#define crA(x, A) cerr << #x << " = " << A[x] << "\n";
#define spacing cout << " ";
#define mmst(x, v) memset((x), v, sizeof ((x)));
#define bg(ms) (*ms.begin())
#define ed(ms) (*prev(ms.end(), 1))
#define addedge(a, b, c, v) v[(a)].pb(pi((b), (c))); v[(b)].pb(pi((a), (c)))
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
string lts(ll x) { stringstream s; s << x; return s.str(); }
ll n, m;
vector <ll> v[MAXN];
pi c[MAXN];
int main()
{
	cin >> n >> m;
	for(ll i = 0; i < m; i++)
	{
		cin >> c[i].f >> c[i].s;
		v[c[i].f].pb(c[i].s);
	}
	for(ll i = 0; i <= n; i++)
	{
		sort(all(v[i]));
	}
	for(ll i = 0; i < m; i++)
	{
		deque <char> ans;
		string ss = lts(c[i].f);
		for(auto j : ss)ans.pb(j);
		while(ans.size() < 6)
		{
			ans.push_front((char)0+48);
		}
		for(auto j : ans)cout << j;
		ans.clear();
		ss = lts((lbd(v[c[i].f], c[i].s) - v[c[i].f].begin())+1);
		for(auto j : ss)ans.pb(j);
		while(ans.size() < 6)
		{	
			ans.push_front((char)0+48);
		}
		for(auto j : ans)cout << j;
		cout << "\n";
	}
}


Measured memory_bytes: 12928
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	 	int p,r,a;
	  	int n = sc.nextInt();
	  	for(int i=0; i<n; i++){
			a=0;r=0;p=0;
			while(a<3){
				String t = sc.next();
				if(t.equals("HIT")){
					r++;
					if(r>3) {r--;p++;}
				} else if(t.equals("OUT")){
					a++;
				} else {
					p+=r+1;
					r=0;
				}
			}
			System.out.println(p);
	  	}
	}
}

Measured memory_bytes: 15360
// 20160313 5:34-6:33
#include <stdio.h>
int main(void)
{
  int n,x;

  int i,j,k,count;

  while(1)
    {
      count = 0;
      scanf("%d %d",&n,&x);
      if(n==0 && x==0)break;
      for(i = 1; i <=n; i++)
        {
          for(j=i+1;j<=n;j++)
            {
              for(k=j+1;k<=n;k++)
                /*= wo irenakattanode saigo no suuji wo
                kazoete inakute error to natteita.*/
                {
                  if(x == i+j+k)count++;
                }
            }
        }
      printf("%d\n",count);
    }
return 0;
}

Measured memory_bytes: 600
import java.util.*;
public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int d = sc.nextInt();
      int n = sc.nextInt();

      int i = 0;

      int j = 1;

      if (n != 100) {

      while ( i < d ) {
         j = j * 100;
         i = i + 1;
      }
      System.out.println(n * j);


      }
      else {
         if (d == 0) {
            System.out.println(101);
         }
         else if (d == 1) {
            System.out.println(10100);
         }
         else {
            System.out.println(1010000);
         }
      }
   }
}

Measured memory_bytes: 21716
<?php

$n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));
$a = (int)$input[0];
$b = (int)$input[1];
$ps = explode(' ', trim(fgets(STDIN)));

$first = 0;
$second = 0;
$third = 0;

foreach ($ps as $p) {
	$tmp = (int)$p;
	if ($tmp <= $a) {
		++$first;
	}elseif ($tmp <= $b) {
		++$second;
	}else{
		++$third;
	}
}
echo min($first, $second, $third);


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

int main() {
    int n,m;
    cin >> n >> m;
 
    dsu d(n);
    for (int i=0; i<m; i++)
    {
        int a,b;
        cin >> a >> b;
        d.merge(a-1,b-1);
    }
    cout << d.groups().size()-1 << endl;


    return 0;
}


Measured memory_bytes: 8972
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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 (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int h, n; cin >> h >> n;
    int sum = 0;
    rep(i,n) {
        int a; cin >> a;
        sum += a;
    }
    if (sum >= h) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

struct T{
  int v,r;
};

struct S{
  int v,c,r;
  bool operator<(S s)const{
    return c>s.c;
  }
};

int N,K;
int C[5001],R[5001];
vector<int> G[5001];

int main(){
  cin>>N>>K;
  for(int i=1;i<=N;i++){
    cin>>C[i]>>R[i];
  }
  while(K--){
    int A,B;
    cin>>A>>B;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  priority_queue<S> que;
  que.push({1,0,0});
  static bool mem[5001][5001];
  for(;;){
    S cs=que.top();
    if(cs.v==N)break;
    que.pop();
    if(mem[cs.v][cs.r]++)continue;
    que.push({cs.v,cs.c+C[cs.v],R[cs.v]});
    if(cs.r){
      for(auto e:G[cs.v]){
	que.push({e,cs.c,cs.r-1});
      }
    }
  }
  cout<<que.top().c<<endl;
}

Measured memory_bytes: 25604
N,a,b,c=map(int,input().split())
L=[int(input()) for i in range(N)]
import itertools 
ans=300000
for i in itertools.product('ABCD',repeat=N):
  cst=0
  A=[]
  B=[]
  C=[]
  for j in range(N):
    if i[j]=='A':
      A.append(L[j])
    elif i[j]=='B':
      B.append(L[j]) 
    elif i[j]=='C':
      C.append(L[j])
  if len(A)>0 and len(B)>0 and len(C)>0:
    if len(A)>1:
      cst+=(len(A)-1)*10
    cst+=abs(sum(A)-a)
    if len(B)>1:
      cst+=(len(B)-1)*10
    cst+=abs(sum(B)-b)
    if len(C)>1:
      cst+=(len(C)-1)*10
    cst+=abs(sum(C)-c)
    ans=min(ans,cst)
 
print(ans)
   

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

int main(void){
    int N;
    cin >> N;
    vector<int> H(N);
    for(int i=0; i<N; ++i){
        cin >> H[i];
    }
    int i=0;
    int max = 0;
    int max_tmp = 0;
    
    while(true){
        max_tmp = 0;
        for(int j=i+1; j<N; ++j){
            if(H[j-1]>=H[j]){
                ++max_tmp;
            }
            else{
                i = j;
                break;
            }
            if(j == N-1){
                i = j;
            }
        }
        if(max_tmp > max){
            max = max_tmp;
        }
        if(i==N-1){
            break;
        }
    }
    cout << max << endl;
}


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

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)
#define SCANFD(x) scanf("%d",&x)

int main(){
    int N,K;
    scanf("%d%d",&N,&K);
    if(K==1)
        printf("0\n");
    else
        printf("%d\n",N-K);

    return 0;
}


Measured memory_bytes: 256
zahyou = list(map(int, input().split()))

if zahyou[0] > zahyou[2] and zahyou[2] > zahyou[1]:
  print('Yes')
  exit()
if zahyou[0] < zahyou[2] and zahyou[2] < zahyou[1]:
  print('Yes')
  exit()

print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int h,w,k;
	cin >> h >> w >> k;
	vector<string> cho(h);
	REP(i,h) cin >> cho[i];

	int ans = 1e9;
	REP(bit, (1<<(h-1))){
		vector<int> ind(h);
		int to = 0;
		REP(i,h){
			ind[i] = to;
			if(i<h-1 && (bit & (1<<i))) to++;
		}
		vector<int> sum(to+1, 0);
		
		int cnt = to;
		REP(j,w){
			vector<int> col(to+1, 0);
			REP(i,h) if(cho[i][j]=='1') col[ind[i]]++;

			bool ov = false;
			REP(p,to+1) if(col[p]>k) ov = true;
			if(ov){ 
				cnt = 1e9; 
				break;
			}
			bool over = false;
			REP(p,to+1) if(sum[p]+col[p]>k) over = true;
			if(over){
				cnt++;
				REP(p,to+1) sum[p] = col[p];
			}else{
				REP(p,to+1) sum[p] += col[p];
			}
		}

		ans = min(ans, cnt);
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, M, ans = 0;
  std::cin >> N >> M;
  std::vector<ll> A(N);
  for(int i=0;i<N;i++) {
    std::cin >> A[i];
    A[i] = ((i==0?0:A[i-1]) + A[i])%M;
    if(A[i]==0) ans++;
      //std::cout << A[i] << " ";
  }
  sort(A.begin(), A.end());
  ll count=0, now = 0;
  for(int i=0;i<N;i++){
    if(i==0) now=A[0], count=1;
    else if(A[i]!=now) {
      ans = ans+(count*((count-1))/2);
      now = A[i];
      count = 1;
    }else {
      count++;
      if(i==N-1){
        ans = ans+(count*((count-1))/2);
      }
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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 (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}



signed main(){
    int k,a,b;
    cin >> k >> a >> b;
    ll ans = 0;

    if(a>=b-1){
        ans += k+1;
    }else{
        ll d = k-(a-1);
        ans = b;
        if(d>0){

            ans += (b-a)*(d/2-1)+d%2;
        }
    }
    cout << ans fin;
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>


#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

const ll M = 998244353;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

const int MOD = 1e9 + 7;
const int INF = 1e9;
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> box(n, 1), flag(n);
    flag[0] = 1;
    rep(i, m){
        int x, y;
        cin >> x >> y;
        x--;y--;
        if(flag[x])flag[y] = 1;
        box[x]--;
        box[y]++;
        if(box[x] == 0)flag[x] = 0;
    }
    int res = 0;
    rep(i, n)if(flag[i])res++;
    cout << res << endl;
}

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

int sum10(int n){
    int sum = 0;
    while(n>0){
        sum += n%10;
        n /=10;
    }
    return sum;
}

int main(){
    int N;
    cin >> N;
    int tempmin = 100;
    for(int i =1; i <=N-1 ; i++){
        int a = sum10(i) + sum10(N-i);
        if(a < tempmin){
            tempmin = a;
        }
    }
    cout << tempmin << endl;
}

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

int main()
{
    int x;
    cin >> x;
    if(x==1){
        cout << 0 << endl;
    }
    else if(x==0){
        cout << 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
    
int main(){
   int a, b, c;
   cin >> a >> b >> c;
   int cnt;
   cnt = (b - (b%a)) / a;
   if(cnt>c) cout << c << endl;
   else cout << cnt << endl;
    return 0;
}

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

//関数宣言
//int func(int x, int y);

int main(void){

  //スカラー入力
  int N,M;

  scanf("%d %d", &N, &M);

  //配列入力
  int k[M], s[M], p[M], tmp, tmp2, tmp3;

  for(int i=0; i<M; i++){
    scanf("%d", &tmp);
    k[i] = tmp;
    s[i] = 0;
    for(int j=0; j<tmp; j++){
      scanf("%d", &tmp2);
      tmp3 = 1 << (tmp2-1);
      s[i] += tmp3;
    }
  }
  for(int i=0; i<M; i++){
    scanf("%d", &p[i]);
  }
  /* for(int i=0; i<M; i++){ */
  /*   printf("%d ", s[i]); */
  /* } */
  /* printf("\n"); */

  int max = 1;
  for(int i=0; i<N; i++){
    max *= 2;
  }

  int ans=0,flag=0;
  for(int k=0; k<max; k++){
    flag=0;
    for(int i=0; i<M; i++){
      tmp = s[i] & k;
      /* printf("%d %d %d %d\n",i,k,tmp,p[i]); */
      tmp2 = 0;
      for(int j=0; j<N; j++){
        tmp2 += tmp & 1;
        tmp = tmp >> 1;
      }
      if((tmp2%2)!=p[i]){
        flag++;
        break;
      }
    }
    if(!flag){
      ans++;
    }
  }

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


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;cin>>s;
    int n = s.size();
    int ans = 0;
    rep(i,n/2){
        if(s[i]!=s[n-1-i])ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    int n;
    int total;
    total=0;
    cin>>n;
    int d[n];
    for(int i=0;i<n;i++){
        cin>>d[i];
    }
    for(int j=0;j<n;j++){
        for(int k=j+1;k<n;k++){
            total = total + d[j]*d[k];
        }
    }
    cout<<total<<endl;
    return 0;
}

    
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
typedef vector<ll> vi;
ll sm = 0,ip,cr=0;
void solve(ll ro,ll col,ll con)
{
 vi b(col);
 for(ll &i:b)
  cin>>i;
 for(ll i = 0;i<ro;i++){
 	for(ll j = 0;j<col;j++){
 		cin>>ip;
 		sm+=(ip*b[j]);
 	}
 	cr+=sm+con>0?1:0;
 	sm = 0;
 }
 cout<<cr<<"\n";
}
int main()
{
  ll n,m,c;
  cin>>n>>m>>c;
  solve(n,m,c);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll inf=1e9+7;
int main()
{
	ll n,val,i,j,k,c,s=0,x,y,a,b;
	string ss;
	cin>>n>>x>>y;
	vector<ll> v;
	for(i=0;i<n-1;i++) v.push_back(0);
//	
	ll dp[n+2][n+2];
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++) dp[i][j]=0;
	}
	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			dp[i][j]=min(abs(j-i),abs(x-i)+1+abs(y-j));
		}
	}
	
	for(i=1;i<=n;i++)
	{
		for(j=i;j<=n;j++)
		{
		//	cout<<dp[i][j]<<"   ";
		//	cout<<endl;
		v[dp[i][j]]++;
		}
	//	cout<<endl;
	}
	for(i=1;i<n;i++)
	{
		cout<<v[i]<<endl;
	}
}

Measured memory_bytes: 31616
let () = Scanf.scanf "%d" @@ fun n ->
  let array = Array.make 110 false in
  for i=1 to 9 do
    for j=1 to 9 do
      array.(i*j) <- true
    done
  done;
  Printf.printf "%s\n" @@
  if array.(n)
  then "Yes"
  else "No"

Measured memory_bytes: 3744
fun main() {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val group = (0 until m)
            .map {
                val (p, y) = readLine()!!.split(' ').map { it.toInt() }
                Triple(it, p, y)
            }
            .groupBy { it.second }

    val ids = Array<String?>(m) { null }
    for (cities in group) {
        var cnt = 0
        for ((i, p, y) in cities.value.sortedBy { it.third }) {
            cnt++
            ids[i] = "$p".padStart(6, '0') + "$cnt".padStart(6, '0')
        }
    }

    println(ids.joinToString("\n"))
}


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

int N;
int d[110];

int main(){
    cin>>N;
    for (int i = 0; i < N; i++)
    {
        cin>>d[i];
    }
    
    sort(d,d+N);

    int ans = 1;
    for (int i = 1; i < N; i++)
    {
        if(d[i-1]<d[i]) ans++;
    }
    

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 300005

// it's swapnil07 ;)
bool is_correct(int n){
    if(n<=12 && n>0){
        return true;
    }
    return false;
}

signed main(){
    fast
    #ifdef SWAPNIL07
        freopen("/home/swapnil/Desktop/c++/input.txt","r",stdin);
        freopen("/home/swapnil/Desktop/c++/output.txt","w",stdout);
    #endif
    string s; cin>>s;
    string s1 = s.substr(0, 2);
    string s2 = s.substr(2, 2);
    int n1 = stoll(s1);
    int n2 = stoll(s2);
    bool f1 = is_correct(n1);
    bool f2 = is_correct(n2);
    if(f1 && f2){
        cout<<"AMBIGUOUS";
    }
    if(!f1 && f2){
        cout<<"YYMM";
    }
    if(f1 && !f2){
        cout<<"MMYY";
    }
    if(!f1 && !f2){
        cout<<"NA";
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int isprime(int n){
  int i;
  for(i = 2; i*i <= n; i++){
    if(n % i == 0) {
      return 0;
    }
  }
  return 1;
}





int main(){
  int n,i;
  while(1){
    scanf("%d", &n);
    for(i = n; i > 1; i--){
      if(isprime(i) == 1 && isprime(i-2) == 1){
        printf("%d %d\n", i-2, i);
        break;
      }
    }
    if(n == 0 || n == 1)break;
  }
  return 0;
}

Measured memory_bytes: 600
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

char A[1005][1005];
int mod = 1e9 + 7;

// mod
void add(int& a, int b) {
    a += b;
    if (a >= mod)
        a -= mod;
}

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

    int H, W;
    cin >> H >> W;
    REP(i, H) {
        REP(j, W) {
            cin >> A[i][j];
        }
    }

    int dp[1005][1005];
    dp[0][0] = 1;
    REP(i, H) {
        REP(j, W) {
            int a = A[i][j];
            if (a == '#') continue;
            if (i + 1 < H && A[i + 1][j] == '.') {
                add(dp[i + 1][j], dp[i][j]);
            }
            if (j + 1 < W && A[i][j + 1] == '.') {
                add(dp[i][j + 1], dp[i][j]);
            }
        }
    }
    cout << dp[H - 1][W - 1] << endl;

    return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    int K;
    cin >> K;
    string S;
    cin >> S;
    if (S.size() <= K) {
        cout << S << endl;
    } else {
        cout << S.substr(0, K) << "..." << endl;
    }
    return 0;
}



Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		String sentence = "";
		String word = in.next();
		int count = 0;

		while(!(sentence.equals("END_OF_TEXT"))){

			sentence = in.next();

			if(word.equalsIgnoreCase(sentence)){

				count ++;

			}
		}

		System.out.println(count);

	}
}

Measured memory_bytes: 26032
#include <stdio.h>
#include <ctype.h>

int main(void){
	char ch[1200];	
	int i=0;

	fgets(ch, 1200, stdin);

	while (ch[i] != '\0'){
		if (islower((unsigned char)ch[i])){
			ch[i] = toupper(ch[i]);
		}
		else if (isupper((unsigned char)ch[i])){
			ch[i] = tolower(ch[i]);
		}
		i++;
	}
	fputs(ch, stdout);
	
	return 0;
}

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

int main(){
    int S,h,m,s;
    cin >> S;
    h = S / 3600;
    S %= 3600;
    m = S /60;
    S %= 60;
    s = S;
    cout << h << ":" << m << ":" << s << endl;
}



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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	string s;
	t = 1;
	while(t--) {
	 cin >> s;
	 if(s[0] == '9' || s[1] == '9')
	  cout << "Yes" << endl;
	 else
	  cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<ll,ll,ll> tll;
const ll MOD = 1000000007;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
/* RMQ：[0,n-1] について、区間ごとの最小値を管理する構造体
    update(i,x): i 番目の要素を x に更新。O(log(n))
    query(a,b): [a,b) での最小の要素を取得。O(log(n))
*/
template <typename T>
struct RMQ {
    int n;         // 葉の数
    vector<T> dat; // 完全二分木の配列
    RMQ(int n_) : n(), dat(n_ * 4, 0) { // 葉の数は 2^x の形
        int x = 1;
        while (n_ > x) {
            x *= 2;
        }
        n = x;
    }
    void update(int i, T x) {
        i += n - 1;
        dat[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;  // parent
            dat[i] = max(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }
    // the minimum element of [a,b)
    T query(int a, int b) { return query_sub(a, b, 0, 0, n); }
    T query_sub(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) {
            return 0;
        } else if (a <= l && r <= b) {
            return dat[k];
        } else {
            T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return max(vl, vr);
        }
    }
};
int main(){
  ll n,k;
  cin>>n>>k;
  vll a(n);
  rep(i,n) cin>>a[i];
  RMQ<ll> s(300001);
  vll dp(n,0);
  rep(i,n){
    ll ma=max(0LL,a[i]-k);
    ll mma=min(300001LL,a[i]+k+1LL);
    if(dp[i]<s.query(ma,mma)+1){
      dp[i]=s.query(ma,mma)+1;
      s.update(a[i],dp[i]);
    }
  }
  ll ans=0;
  rep(i,n){
    chmax(ans,dp[i]);
  }
  COUT(ans);
}

Measured memory_bytes: 17260
#include <cstdio>
#include <utility>
#include <vector>
#include <climits>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <array>
#include <utility>
#include <valarray>

using namespace std;

int main()
{
    int N, M;
    scanf("%d %d\n", &N, &M);
    vector<pair<int, int>> students; students.reserve(N);
    for (int i = 0; i < N; ++i){
        int ai, bi;
        scanf("%d %d\n", &ai, &bi);
        students.emplace_back(ai, bi);
    }
    vector<pair<int, int>> checkpoints; checkpoints.reserve(M);
    for (int i = 0; i < M; ++i){
        int ci, di;
        scanf("%d %d\n", &ci, &di);
        checkpoints.emplace_back(ci, di);
    }
    for (auto& s : students){
        int result = -1;
        int distance = INT_MAX;
        for (int i = 0; i < M; ++i){
            const int d = abs(checkpoints[i].first - s.first) + abs(checkpoints[i].second - s.second);
            if (d < distance){
                result = i;
                distance = d;
            }
        }
        printf("%d\n", result + 1);
    }
}


Measured memory_bytes: 256
/*************************************************************************

       Author:            palayutm
       Created Time :     Mon 10 Oct 2016 12:06:45 PM CST

       File Name:         a.cc
       Description:       new style, new life

 ************************************************************************/
#include <bits/stdc++.h>

using namespace std;

int main(int argc, const char *argv[])
{
  string s = "CODEFESTIVAL2016";
  string t;
  cin >> t;
  int num = 0;
  for (int i = 0; i < 16; i ++) {
    num += (t[i] != s[i]);
  }
  cout << num << endl;
  return 0;
}



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

int T[10000];
struct edge {
	int to, d;
};

vector<edge> G[10000];

int dist[10000][3][210];

struct S {
	int v, hot, rem, d;
	bool operator <(const S& x) const {
		return d > x.d;
	}
};

int rec(S s) {
	return dist[s.v][s.hot][s.rem];
}

void save(S s) {
	dist[s.v][s.hot][s.rem] = s.d;
}

const int COLD = 0;
const int GOOD = 1;
const int HOT = 2;

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

	int N, M, X;
	cin >> N >> M >> X;
	for(int i = 0; i < N; i++) {
		cin >> T[i];
	}
	for(int i = 0; i < M; i++) {
		int a, b, d;
		cin >> a >> b >> d;
		a--, b--;
		G[a].push_back({ b, d });
		G[b].push_back({ a, d });
	}

	const int INF = 1 << 25;
	fill((int*)begin(dist), (int*)end(dist), INF);
	dist[0][COLD][X] = 0;
	priority_queue<S> q;
	q.push({ 0, COLD, X, 0 });
	while(q.size()) {
		S s = q.top();
		q.pop();
		//cerr << "s.v : " << s.v << ", s.hot : " << s.hot << ", s.rem : " << s.rem << endl;
		if(s.v == N - 1) {
			cout << s.d << endl;
			return 0;
		}
		for(auto e : G[s.v]) {
			int nrem = max(s.rem - e.d, 0);
			if(s.hot == HOT && T[e.to] == COLD && nrem > 0) continue;
			if(s.hot == COLD && T[e.to] == HOT && nrem > 0) continue;
			if(T[e.to] != GOOD) nrem = X;
			int nt = T[e.to] == GOOD ? s.hot : T[e.to];
			S ns = { e.to, nt, nrem, s.d + e.d };
			if(rec(ns) > ns.d) {
				//cerr << "\t" << "ns.v : " << ns.v << ", ns.hot : " << ns.hot << ", ns.rem : " << ns.rem << endl;
				save(ns);
				q.push(ns);
			}
		}
	}
}

Measured memory_bytes: 28736
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  int n = S.size();
  int x {1};
  vector<int> dp(n);
  rep(i,n) {
    if (i==0) dp[0] = S[0] - '0';
    else dp[i] = (dp[i-1]+(S[i]-'0')*x) % 2019;
    x = (x*10)%2019;
  }

  int ans {};
  std::unordered_map<int, int> mp;
  mp[0] = 1;
  rep(i,n) {
    ans += mp[dp[i]];
    ++mp[dp[i]];
  }
  cout << ans << '\n';
}


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

#define int long long
typedef long long ll;
const int N = 105, MOD = 1e9 + 7;
int n, m, k, fac[N << 1], ifac[N << 1];

int fpow(int a, int m) {
	int ans = 1;
	for(; m; m >>= 1) {
		if(m & 1) ans = ans * 1ll * a % MOD;
		a = a * 1ll * a % MOD;
	}
	return ans;
}

struct Edge {
	int nxt, v;
}e[N << 1];
int bccno[N], bcc_cnt,siz_e[N], siz_p[N], dfs_clock, low[N], pre[N], head[N], cnt, top;
pair<int, int> stk[N];

void add(int u, int v) {
	e[++cnt] = (Edge){head[u], v}, head[u] = cnt;
	e[++cnt] = (Edge){head[v], u}, head[v] = cnt;
}
void dfs(int u, int fa) {
    low[u] = pre[u] = ++dfs_clock;
    for(int i = head[u]; ~i; i = e[i].nxt) {
    	int v = e[i].v;
    	if(v == fa) continue;
    	if(!pre[v]) {
    		stk[++top] = make_pair(u, v);
    		dfs(v, u);
    		low[u] = min(low[u], low[v]);
    		if(low[v] >= pre[u]) {
    			bcc_cnt++;
    			while(523) {
                    int x = stk[top].first, y = stk[top].second;
    			    top--;
    			    siz_e[bcc_cnt]++;
    			    if(bccno[x] != bcc_cnt) {bccno[x] = bcc_cnt; siz_p[bcc_cnt]++;}
    			    if(bccno[y] != bcc_cnt) {bccno[y] = bcc_cnt; siz_p[bcc_cnt]++;}
    			    if(x == u && y == v) break;
    			}
    		}
    	}
    	else if(pre[v] < pre[u]) {stk[++top] = make_pair(u, v); low[u] = min(low[u], pre[v]);}
    }
}
int C(int n, int m) {
	return fac[n] * 1ll * ifac[m] % MOD * ifac[n - m] % MOD;
}
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

signed main() {
    memset(head, -1, sizeof head);
    scanf("%lld %lld %lld", &n, &m, &k);
    fac[0] = ifac[0] = ifac[1] = 1;
    for (int i = 1; i <= m + k; ++i) fac[i] = fac[i - 1] * 1ll * i % MOD;
    for (int i = 2; i <= m + k; ++i) ifac[i] = (MOD - MOD / i) * 1ll * ifac[MOD % i] % MOD;
    for (int i = 2; i <= m + k; ++i) ifac[i] = ifac[i - 1] * 1ll * ifac[i] % MOD;
    for(int i = 1; i <= m; i++) {
    	int u, v;
    	scanf("%lld %lld", &u, &v);
    	add(u, v);
    }
    for(int i = 1; i <= n; i++) {
    	if(!pre[i]) dfs(i, 0);
    }
    int ans1 = 1, ans2 = 1, ans3 = 1;
    for(int i = 1; i <= bcc_cnt; i++) {
    	if(siz_e[i] == 1) ans1 = ans1 * 1ll * k % MOD;
    	else if(siz_e[i] == siz_p[i]) {
            int sum = 0;
            for(int j = 1; j <= siz_e[i]; j++) {
                sum += fpow(k, gcd(siz_p[i], j));
                if(sum >= MOD) sum -= MOD;
            }
            ans2 = ans2 * 1ll * sum % MOD * fpow(siz_e[i], MOD - 2) % MOD; 
    	} else ans3 = ans3 * 1ll * C(siz_e[i] + k - 1, k - 1) % MOD;
    }
    printf("%lld\n", ans1 * 1ll * ans2 % MOD * ans3 % MOD);
    return 0;
}

Measured memory_bytes: 3828
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> H(N);
    rep(i, N) cin >> H[i];
    vector<ll> dp(N + 1, INF);
    // dp[i]:=[0,i)までで最小コスト
    dp[0] = dp[1] = 0;
    for(int i = 1; i < N; i++) {
        for(int k = 1; k <= K; k++) {
            if(i + k <= N)
                dp[i + k] =
                    min(dp[i + k], dp[i] + abs(H[i + k - 1] - H[i - 1]));
        }
    }
    cout << dp[N] << endl;
    return 0;
}

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

string s,t;
ll q;
ll a,b,c,d;
ll a_b_count[2][100010]; //a-bの値%3

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


int main() {
    std::cin >> s>>t;
    std::cin >> q;
    Fill(a_b_count,0);
    ll s_length = s.length();
    ll t_length = t.length();
    
    for (int i = 0; i < s_length; i++) {
        if(s[i]=='A'){
            a_b_count[0][i+1]= a_b_count[0][i] + 1;
        }else{
            a_b_count[0][i+1]= a_b_count[0][i] + 2;
        }
    }
    for (int i = 0; i < t_length; i++) {
        if(t[i]=='A'){
            a_b_count[1][i+1]= a_b_count[1][i] + 1;
        }else{
            a_b_count[1][i+1]= a_b_count[1][i] + 2;
        }
    }
    
    for (int i = 0; i < q; i++) {
        std::cin >> a>>b>>c>>d;
        if((a_b_count[0][b] - a_b_count[0][a-1]) %3 == (a_b_count[1][d] - a_b_count[1][c-1]) %3){
            std::cout << "YES" << std::endl;
        }else{
            std::cout << "NO" << std::endl;
        }
    }
}


Measured memory_bytes: 2432
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include<bitset>

using namespace std;
#define modd 1000000007
#define moda 1000003


typedef pair<long long, long long> pl;



#define ll long long




/*
class UnionFind {
public:
	vector <ll> par; 
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		for (ll i = 0; i < sz_; ++i) par[i] = i; 
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, K, a, b, c, d,e, H, W, X;
long long A[200005] = {};
long long B[200005] = {};
long long C[200005] = {};
bool f, ff,fff;
string S;
set <long long>sll;
pl bufpl;
vector <long long>vl[100005];
vector <pl>vpl[2];
vector <string> vs;
set<ll> llset;

struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



vector <ST> vst;
ST st[200005];
ST bufst;

bitset<5000> bits;

int main() {

	cin >> S;

	a = 0;
	b = 0;
	for (int i = 0; i < S.size(); i++) {

		if (S[i] == 'S') {
			a++;
		}

		if (S[i] == 'T') {
			if (a > 0) {
				a--;
				b++;
			}
			else {
				a = 0;
			}

		}

	}
	
	

	cout << S.size()-2*b << endl;

	return 0;

}


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

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

    int tot = 0;
    for (int i = 1; i <= N; i++)
    {
        int count = 0;
        if (i % 2 == 0)
            continue;
        for (int j = 1; j <= i; j++)
        {
            if (i % j == 0)
                count++;
        }
        if (count == 8)
            tot++;
    }

    cout << tot << endl;
    return 0;
}

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

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int N;
	cin >> N;
	vector<int> h(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> h[i];
	}
	h.push_back(0);
	int ans = 0;
	bool update = true;
	while (update)
	{
		update = false;
		int minV = 1e9;
		int index = 0;
		for (int i = 0; i < N + 1; ++i)
		{
			if (h[i] == 0)
			{
				if (index == i)
				{
					++index;
					continue;
				}
				for (int j = index; j < i; ++j)
				{
					if (j == N)
					{
						continue;
					}
					h[j] -= minV;
					update = true;
				}
				ans += minV;
				index = i + 1;
				minV = 1e9;
			}
			minV = min(minV, h[i]);
		}
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 256
use std::io::Read;
use std::collections::HashSet;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let s: Vec<_> = (0..n).map(|_| iter.next().unwrap()).collect();
    let d: HashSet<_> = s.iter().collect();

    let mut ok = d.len() == s.len();

    for i in 0..n-1 {
        if s[i].chars().last().unwrap() != s[i+1].chars().next().unwrap() {
            ok = false;
            break;
        }
    }
    println!("{}", if ok { "Yes" } else { "No" });
}



Measured memory_bytes: 4352
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
#define rep(i,n) for(int i=0;i<(n);++i)
#define ll long long
using namespace std;
int main(){
    int n,a,b;
    cin>>n>>a>>b;
    vector<int>p(n);
    rep(i,n)cin>>p[i];
    int x=0,y=0,z=0;
    rep(i,n){
        if(p[i]<=a)x++;
        else if(p[i]>=a+1&&p[i]<=b)y++;
        if(p[i]>=b+1) z++;
    }
cout<<min(min(x,y),z);
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")




int main() {


    ll sx,sy,tx,ty; cin >> sx >> sy >> tx >> ty;
    ll dx = tx-sx,dy = ty-sy;
    string ans;

    //loop1
    rep(i,dy) ans += 'U';
    rep(i,dx) ans += 'R';
    rep(i,dy) ans += 'D';
    rep(i,dx) ans += 'L';

    //loop2
    ans += 'L';
    rep(i,dy+1) ans += 'U';
    rep(i,dx+1) ans += 'R';
    ans += 'D';
    ans += 'R';
    rep(i,dy+1) ans += 'D';
    rep(i,dx+1) ans += 'L';
    ans += 'U';

    cout << ans;


    return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;
class Main
{
    public static void main(String args[])
	{
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();

        if(a>2*b){
            System.out.println(a-(2*b));
        }
        else{
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

const int mod=1000000007;
int a[22][22];
ll dp[1<<22];
int main(){
    int n;
    cin>>n;
    rep(i,n)rep(j,n) cin>>a[i][j];
    dp[0]=1;
    rep(i,1<<n)rep(j,n){
        int m=__builtin_popcount(i);
        if((i>>j&1)==0&&a[m][j]==1){
            dp[i|(1<<j)]+=dp[i];
            dp[i|(1<<j)]%=mod;
        }
    }
    cout<<dp[(1<<n)-1]<<endl;
    return 0;
}


Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll x;
    cin >> x;
    if (x)
        cout << 0 << "\n";
    else
        cout << 1 << "\n";

    return 0;
}

Measured memory_bytes: 3616
from collections import defaultdict
import itertools
N = int(input())
dic = defaultdict(int)
for i in range(2, N+1):
    for j in range(2, i + 1):
        while i % j == 0:
            i /= j
            dic[j] += 1
lst_2 = [k for k, v in dic.items() if v >= 2]
lst_4 = [k for k, v in dic.items() if v >= 4]
lst_14 = [k for k, v in dic.items() if v >= 14]
lst_24 = [k for k, v in dic.items() if v >= 24]
lst_74 = [k for k, v in dic.items() if v >= 74]
z = list(itertools.combinations(lst_4, 2))
p_2_q_4_r_4 = len([x for x in list(itertools.product(lst_2, z)) if x[0] != x[1][0] and x[0] != x[1][1]])
p_14_q_2 = len(lst_14) * len(lst_4) - len([x for x in lst_14 if x in lst_4])
p_2_q_24 = len(lst_2) * len(lst_24) - len([x for x in lst_2 if x in lst_24])
p_74 = len([k for k, v in dic.items() if v >= 74])
print(p_2_q_4_r_4 + p_14_q_2 + p_2_q_24 + p_74)

Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  int ans = 1000;
  for(int i=0;i<s.size()-2;i++){
    char a,b,c;
    a = s[i] - '0';
    b = s[i+1] - '0';
    c = s[i+2] - '0';

    int d = (int)a*100+(int)b*10+(int)c;

    ans = min(ans,abs(d-753));
  }
  cout << ans << endl;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<pair<int, int>> ans;
  for(int i = 1; i < n; i++){
    for(int j = i + 1; j <= n; j++){
      if(i + j != n + !(n % 2)) ans.push_back(make_pair(i, j));
    }
  }
  
  cout << ans.size() << '\n';
  for(int i = 0; i < ans.size(); i++) cout << ans.at(i).first << " " << ans.at(i).second << '\n';
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//#define _debug
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc(x) scanf("%d",&x)
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORd(i,a,b) for(int i=a;i>b;i--)
#define ff first
#define ss second
#define sz(x) x.size()
#define pb push_back
//#define _online_judge

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, //data type
        null_type, //
        less<int>, //
        rb_tree_tag, //red-black tree
        tree_order_statistics_node_update> new_data_set;

typedef pair<int,int> pii;
typedef vector<pii> vii;
const int con = static_cast<const int>(1e5 + 2);
const int MOD = 1000000007;

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

}


int main (){
	FASTIO
#ifdef _online_judge
	freopen("input.txt" , "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif

    int n;cin >> n;
    string s;cin >> s;
    int k;cin >> k;
    for(int i=0;i<n;i++){

        if(s[i] != s[k-1]) s[i] = '*';
    }
    cout << s;
    return 0;
}


Measured memory_bytes: 256