akhauriyash/Code-Regression huggingface dataset:
n = int(input())
path = []

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n
    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)
    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n)

for i in range(n):
    x,y = map(int,input().split())
    path.append((x,y,i))

x_li = sorted(path)
y_li = sorted(path,key=lambda x:(x[1]))

edge = []

for i in range(1,n):
    edge.append((x_li[i][2],x_li[i-1][2],x_li[i][0]-x_li[i-1][0]))
    edge.append((y_li[i][2],y_li[i-1][2],y_li[i][1]-y_li[i-1][1]))

edge.sort(key=lambda x:(x[2]))

uf = UnionFind(n)
cost = 0

for i,j,k in edge:
    if not uf.same(i,j):
        uf.union(i,j)
        cost += k

print(cost)

Measured memory_bytes: 133084
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    string s;
    cin>>s;
    ll res=0;
    rep(i,s.size()){
        res+=s[i]-'0';
    }
    if(res%9==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3736
#include<stdio.h>
 int main(void)
 {
     int A,B,C;

     scanf("%d%d%d",&A,&B,&C);

     if((A>B)&&(A>C)) printf("%d\n",A*10+B+C);
     else if((B>A)&&(B>C)) printf("%d\n",B*10+A+C);
     else if((C>A)&&(C>B)) printf("%d\n",C*10+A+B);
     else if((A==B)&&(B>C)) printf("%d\n",A*10+B+C);
     else if((A==B)&&(B<C)) printf("%d\n",C*10+A+B);
     else if((A==C)&&(A>B)) printf("%d\n",A*10+B+C);
     else if((A==C)&&(A<B)) printf("%d\n",B*10+A+C);
     else if((B==C)&&(B>A)) printf("%d\n",B*10+A+C);
     else if((B==C)&&(B<A)) printf("%d\n",A*10+B+C);
     else printf("%d\n",A*10+B+C);

     return 0;
 }


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

using namespace std;
using ll = long long;

int main() {
    string S;
    cin >> S;
    for(int i = 0; i <= 7; i++) {
        if("keyence" == S.substr(0,i) + S.substr(S.size() - 7 + i, 7 - i)) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 3628
import java.io.InputStreamReader;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.*;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStream;
import static java.lang.Math.*;

public class Main {

    public static void main(String[] args) {
        final String[] tasks = new String[]{"D","C","B","A"};
        for(final String task:tasks) {
            try {
                Class ca = Main.class.getClassLoader().loadClass(task);
                if (ca.getField("on").getInt(null) == 1) {
                    Object aTask = ca.newInstance();
                    Method m = ca.getMethod("S", null);
                    m.invoke(aTask, null);
                }
            } catch (Exception ex) { }
        }
    }

}

class A {
    public static int on = 1;

    public void run(){
        int[][] a = new int[3][3];
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                a[i][j] = ni();
            }
        }

        for(int i=1;i<3;i++){
            int r = -100000;
            for(int j=0;j<3;j++){
                if(r==-100000) {
                    r = a[i][j] - a[i - 1][j];
                }else if(r!=(a[i][j] - a[i - 1][j])){
                    pl("No");
                    return;
                }
            }
        }


        for(int j=1;j<3;j++){
            int r = -100000;
            for(int i=0;i<3;i++){
                if(r==-100000) {
                    r = a[i][j] - a[i][j-1];
                }else if(r!=(a[i][j] - a[i][j-1])){
                    pl("No");
                    return;
                }
            }
        }
        pl("Yes");






    }
    private InputReader in =  new InputReader(System.in);
    private PrintWriter out = new PrintWriter(System.out);
    public void S(){run();out.close(); }
    public int ni(){return Integer.parseInt(in.ns());}
    public long nl(){return Long.parseLong(in.ns());}
    public String ns(){return in.ns();}
    public void p(Object obj){out.print(obj);}
    public void ps(Object obj){p(obj);p(" ");}
    public void pl(Object obj){out.println(obj);}
    public int gcd(int a,int b){ while( b != 0 ) { int t = a % b;a = b;b = t; } return a; }
}

class B {
    public static int on = 0;

    public void run(){

    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String ns() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

}





Measured memory_bytes: 22612
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b, c;
	cin >> a >> b >> c;
	cout << b + min(c, a + b + 1) << endl;
	return 0;
}

/* --------------------------------------- */


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,k;cin >> n >> k;
  vector<int> c(45);
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    ll b=a[i];
    int cnt=0;
    while(b){
      if(b&1){
        c[cnt]++;
      }
      cnt++;
      b>>=1;
    }
  }
  ll ans=0;
  for(int i=0;i<45;i++){
    ll t=1,x=0;
    if((k+1)>>i&0){
      continue;
    }
    for(int j=0;j<45;j++){
      if(j<=i-1){
        if(c[j]*2<n){
          x+=t;
        }
      }
      else if(j==i){
      }
      else{
        if((k+1)>>j&1){
          x+=t;
        }
      }
      t*=2;
    }
    if(x>k){
      continue;
    }
    ll res=0;
    for(int j=0;j<n;j++){
      res+=x^a[j];
    }
    ans=max(ans,res);
  }
  cout << ans << endl;
}

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

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

// ========================================================================= //

const int N = 55;

int pw(int a, int b) {
    int r = 1;
    for (; b; b >>= 1) {
        if (b & 1)
            r = 1LL * r * a % MOD;
        a = 1LL * a * a % MOD;
    }
    return r;
}
ll fact[N], ofact[N];

ll cnk(int n, int k) {
    if (n < k || k < 0)
        return 0;
    return fact[n] * ofact[k] % MOD * ofact[n-k] % MOD;
}

static ll d[N][N][N];
ll solve(int n, int x, int y) {
    ll &cd = d[n][x][y];
    if (cd != -1)
        return cd;
    if (n == 0)
        return cd = 1;
    if (x + y == 0)
        return cd = 0;
    cd = 0;
    for (int sx = 0; sx + x + y <= n; ++sx)
        for (int sy = 0; sx + sy + x + y <= n; ++sy) {
            int c1 = x - sx + sy, c2 = y - sy + sx;
            if (c1 < 0 || c2 < 0)
                continue;
            ll nd = solve(n - x - y, sx, sy);
            nd = nd * cnk(n, c1) % MOD;
            nd = nd * cnk(n-c1, c2) % MOD;
            cd = (cd + nd) % MOD;
        }
    return cd;
}
int main() {
    fact[0] = 1;
    for (int i = 1; i < N; ++i)
        fact[i] = fact[i - 1] * i % MOD;
    for (int i = 0; i < N; ++i)
        ofact[i] = pw(fact[i], MOD - 2);


    memset(d, -1, sizeof(d));
    int n;
    cin >> n;
    cout << solve(n, 1, 0) << "\n";


    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(),x.end()
ll power(ll x, ll y, ll p) { 
    ll res = 1;    x = x % p;  
    while(y > 0) {
        if(y & 1) res = (res*x) % p; 
        y = y>>1;    x = (x*x) % p; 
    } return res; 
}

int main()
{
    Imposter
    
    int t=1;
    //cin>>t;
    while(t--)
    {
       ll n,k,sum=0;
       cin>>n>>k;
       ll a[n];
       input(a,n);
       sort(a,a+n);
       f(k)sum+=a[i];
       cout<<sum<<endl;
        
    }
    return 0;
}

Measured memory_bytes: 3664
/*Code by Codercjh*/
#include<bits/stdc++.h>
#define fr(i,a,b) for(int i=(a);i<=(b);++i)
#define rf(i,a,b) for(int i=(a);i>=(b);--i)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std;
typedef long long ll;
template<typename T>
inline void read(T &x){
	char c=getchar();T fh=0;bool f=false;
	while(!isdigit(c))f|=(c=='-'),c=getchar();
	while(isdigit(c))fh=(fh<<1)+(fh<<3)+(c^48),c=getchar();
	x=f?-fh:fh;
	return;
}
int n,a[1000005];
ll ans;
int main(){
	read(n);
	fr(i,1,n)a[i]=i;
    fr(i,1,n/3)a[3*i]=0;
    fr(i,1,n/5)a[5*i]=0;
    fr(i,1,n)ans+=a[i];
    cout<<ans;
	return 0;
}


Measured memory_bytes: 7460
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
long long H[100010];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	int count = 0;
	int m = 0;
	for (int i = N - 2; i >= 0; i--) {
		if (H[i] >= H[i + 1]) {
			count++;
		}
		else {
			if (count > m) {
				m = count;
			}
			count = 0;
		}
	}
	cout << max(m, count);
}

Measured memory_bytes: 1024
using System;
class Program
{
  static void Main(string[] args)
  {
    long x,ans;
    x = long.Parse(Console.ReadLine());
    ans=x%11;
    if(ans==0) ans=0;
    else if(ans<7) ans=1;
    else ans=2;
    ans+=(x/11)*2;
    Console.WriteLine("{0}", ans);
  }
}

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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n), c(m), d(m);

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

    for (int i = 0; i < m; ++i) {
        cin >> c[i] >> d[i];
    }

    int p = 1;
    for (int i = 0; i < n; ++i) {
        int tempMin = abs(a[i] - c[0]) + abs(b[i] - d[0]);
        for (int j = 0; j < m; ++j) {
            int ans = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (tempMin > ans) {
                p = j + 1;
                tempMin = ans;
            }
        }
        cout << p << endl;
        p = 1;
    }


}

Measured memory_bytes: 3608
from math import gcd
MOD=10**9+7
n=int(input())
zero=0
cnt={}
for i in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        zero+=1
        continue
    g=gcd(a,b)
    a//=g
    b//=g
    # a/bを作る
    if b<0:
        a*=-1
        b*=-1
    # b == 0 の時 a = 1 する
    if b==0 and a<0:
        a*=-1
    # if a <= 0: cnt[(b, -a)][0]
    # else: [(a, b)][1]
    # a1/b1 == b2/-a2 の時 1と2は仲が悪い
    if a<=0:
        a,b=b,-a
        if (a,b) in cnt:
            cnt[(a,b)][0]+=1
        else:
            cnt[(a,b)]=[1,0]
    else:
        if (a,b) in cnt:
            cnt[(a,b)][1]+=1
        else:
            cnt[(a,b)]=[0,1]
ans=1
for i,v in cnt.items():
    # 空集合 + (b, -a)でできる集合 + (a, b)でできる集合
    ans*= 1 + (pow(2,v[0],MOD) - 1) + (pow(2,v[1],MOD) - 1)
    ans%=MOD
print((zero-1+ans)%MOD)


Measured memory_bytes: 136452
#!/usr/bin/env python3
import sys
 
 
def solve(N: int, K: int):
    count = 0
 
    if K % 2 == 0:
        count += (N//K)**3
        # a,b,c == 0 mod K//2
        count += (N//(K//2) - N//K)**3
    else:
        count += (N//K)**3
    print(count)
    return
 
 
def main():
    N,K= map(int,input().split())
    # N = int(next(tokens))  # type: int
    # K = int(next(tokens))  # type: int
    solve(N, K)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int n,h,w,f=0;
string st[20];
map<P,int> m;
map<int,P> r;
char c[5]="RDLU";
int ai[]={0,1,0,-1};
int aj[]={1,0,-1,0};
bool in(int i,int j){
  return (0<=i&&i<h&&0<=j&&j<w);
}
void dfs(int b,int p,int d,string s){
  //cout<<b<<p<<"/"<<d<<s<<endl;
  if(f) return;
  if(b==(1<<n)-1){
    f=1;
    cout<<s<<endl;
    return;
  }
  for(int k=0;k<4;k++){
    //cout<<k<<endl;
    if((d+2)%4==k) continue;
    int i=r[p].first,j=r[p].second;
    while(1){
      while(in(i,j)&&st[i][j]=='.') i+=ai[k],j+=aj[k];//,cout<<i<<j<<endl;
      if(!in(i,j)) break;
      if((b>>m[P(i,j)])&1){
	i+=ai[k],j+=aj[k];
	continue;
      }
      break;
    }
    if(!in(i,j)) continue;
    if(m.find(P(i,j))==m.end()) continue;
    int x=m[P(i,j)];
    dfs(b+(1<<x),x,k,s+c[k]);
  }
}
signed main(){
  int d;
  cin>>h>>w;
  for(int i=0;i<h;i++) cin>>st[i];
  n=1;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(st[i][j]=='o'){
	m[P(i,j)]=n;
	r[n]=P(i,j);
	n++;
      }
      for(int k=0;k<4;k++){
	if(st[i][j]==c[k]){
	  m[P(i,j)]=0;
	  r[0]=P(i,j);
	  d=k;
	  st[i][j]='.';
	}
      }
    }
  }
  dfs(1,0,d,"");
  return 0;
}

Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,a[N],b[N];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
	long long ans=0;
	for (int i=n;i;i--){
		int res=(a[i]+ans)%b[i];
		if (res) ans+=b[i]-res;
	}
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int, int>;
const ll mod = 1e9+7;

struct Edge {
  int to, id;
  Edge(int to, int id): to(to), id(id) {}
};

vector<vector<Edge>> edges(51);
ll path;
bool dfs(int v, int to, int p=0) {
  // printf("v: %d, to: %d, p: %d\n", v, to, p);
  if(v==to) {
    path = 0ll;
    return true;
  }
  for(auto edge: edges[v]) {
    if(edge.to==p) continue;
    if(dfs(edge.to, to, v)) {
      path |= 1ll<<edge.id;
      return true;
    }
  }
  return false;
}

int main(int argc, char const* argv[])
{
  int n;
  cin>>n;
  REP(i,n-1) {
    int a, b;
    cin>>a>>b;
    edges[a].emplace_back(b, i);
    edges[b].emplace_back(a, i);
  }

  int m;
  cin>>m;
  vector<ll> constraints;
  REP(i,m) {
    int u, v;
    cin>>u>>v;
    dfs(u, v);
    constraints.push_back(path);
  }

  ll ans = 0;
  for (ll i = 0; i < 1ll<<m; i++) {
    ll c = i;
    ll white_edges = 0;
    ll pos = 0;
    while(c) {
      if(c&1ll) white_edges |= constraints[pos];
      c>>=1ll;
      pos++;
    }
    int white = __builtin_popcountll(white_edges);
    ll conb = 1ll<<(n-1-white);
    if(__builtin_popcountll(i)&1ll) ans-=conb;
    else ans+=conb;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const ll INF = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

int n, m;
vector<int> es[100010];
bool use[100010];
int r1[100010];
void rec(int s,int &i) {

	use[s] = true;
	r1[i] = s;
	i++;
	for(auto nex : es[s])
	{
		if (use[nex]) continue;
		use[nex] = true;
		return rec(nex, i);
	}
}
void solv() {

	cin >> n >> m;
	for (size_t i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		es[a].push_back(b);
		es[b].push_back(a);
	}
	use[1] = true;
	int ind = 0;
	rec(1,ind);
	vector<int> ar;
	for (size_t i = 0; i < ind; i++)
	{
		ar.push_back(r1[i]);
	}

	for (size_t i = 1; i <= n; i++)
	{
		use[i] = false;
	}
	for (auto val : ar)
	{
		use[val] = true;

	}
	if (es[1].size() > 0) {
		int ind2 = 0;
		for (size_t i = 1; i < es[1].size(); i++)
		{
			if (use[es[1][i]]) continue;
			rec(es[1][i], ind2);
			break;
		}

		if (ind2 > 0) {
			for (size_t i = 0; i < ind2; i++)
			{
				ar.insert(ar.begin(),r1[i]);
			}
		}
	}
	cout << ar.size() << endl;
	for (size_t i = 0; i < ar.size() ; i++)
	{
		if (i > 0) cout << " ";
		cout << ar[i];
	}
	cout << endl;
}




int main() {
	solv();

	return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int a,b,c,d; cin >> a >> b >> c >> d;
  cout << max(a*b,c*d) << endl;
  return 0;
}





Measured memory_bytes: 256
N = int(input())
nums = [int(e) for e in input().split()]
M = int(input())
P = []
for i in range(0,M):
    P.append([int(t) for t in input().split()])
ans = 0
a = 0
for i in range(0,M):
    a = nums[P[i][0]-1]
    nums[P[i][0]-1] = P[i][1]
    for k in range(0,N):
        ans += nums[k]
    print(ans)
    ans = 0
    nums[P[i][0]-1] = a


Measured memory_bytes: 38512
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())



if b-a > k:
    print(':(')
elif c -b > k:
    print(':(')
elif d -c > k:
    print(':(')
elif e -d > k:
    print(':(')
elif c -a > k:
    print(':(')
elif d -a > k:
    print(':(')
elif d -b > k:
    print(':(')
elif e -a > k:
    print(':(')
elif e -b > k:
    print(':(')
elif e -c > k:
    print(':(')   
else:
    print('Yay!')

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

int main(){
    int sx,sy,tx,ty;
    cin >> sx>>sy>>tx>>ty;
    for(int i=0;i<tx-sx;i++){
        cout << 'R';
    }
    for(int i=0;i<ty-sy;i++){
        cout << 'U';
    }

    for(int i=0;i<tx-sx;i++){
        cout << 'L';
    }
    for(int i=0;i<ty-sy;i++){
        cout << 'D';
    }

    cout << 'D';

    for(int i=0;i<tx-sx+1;i++){
        cout << 'R';
    }
    for(int i=0;i<ty-sy+1;i++){
        cout << 'U';
    }
    cout << 'L';
    cout << 'U'; 

    for(int i=0;i<tx-sx+1;i++){
        cout << 'L';
    }
    for(int i=0;i<ty-sy+1;i++){
        cout << 'D';
    }
    cout << 'R';
    cout << endl;
    return 0;
}


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

int main () {
    string S, T;

    cin >> S;

    if (S == "Sunny") {T = "Cloudy";}
    else if (S == "Cloudy") {T = "Rainy";}
    else if (S == "Rainy") {T = "Sunny";}

    cout << T << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
 
using namespace std;
 
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
 
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }
 
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
 
    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
 
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
 
int main() {
    int N, M;
    cin >> N >> M;
    vector<int> P(N);
    for(int i = 0; i < N; i++){
        cin >> P[i];
    }
 
    UnionFind tree(N);
 
    for(int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        tree.unite(x-1, y-1); // x-1の木とy-1の木を併合する
    }
 
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        if (tree.same(i, P[i]-1)) { //iとP[i]-1が同じ木に属するなら，カウンタに1追加
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;

 
const ll INF = 1e12;
const ll N =(1e5+5); // TODO : change value as per problem
const ll MOD = 1e9+7;
int x[N],y[N];
bool red[N];
int balls[N];
void solve(){
	int n,m;
	cin >> n >> m;
	for(int i = 1;i <= m;i++){
		cin >> x[i] >> y[i];
	}
	red[1] = true;
	for(int i = 1;i<=n;i++){
		balls[i] = 1;
	}
	for(int i =1;i<=m;i++){
		int from = x[i],to  =y[i];
		if(red[from]){
			if(balls[from] == 1) {
				red[from] = false;
				balls[from] = 0;
			}
			else balls[from]--;
			red[to] = true;
			balls[to]++;
		}
		else{
			balls[from]--;
			balls[to]++;
		}
 	}int ans = 0;
 	for(int i = 1;i<=n;i++){
 		if(red[i]){
 			ans++;
 		}
 	}
 	cout << ans << endl;
}
signed main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     // freopen(".in","r",stdin);freopen(".out","w",stdout);
    
     ll tt=1;   
     // cin >> tt;
    while(tt--){    
        solve();
    }    
}

Measured memory_bytes: 6024
/// Bismillahir Rahmanir Rahim
/* Author: Mohammad Morsalin (aka white_space)
    Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define PI acos(-1)
#define IOS ios::sync_with_stdio(false);
using namespace std;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
int main()
{
    IOS
    string s;
    cin>>s;
    if(s=="ABC")cout << "ARC\n";
    else cout << "ABC\n";
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=998244353;

ll power(ll x,ll n){
    if(n==0) return 1;
    ll res=power(x*x%mod,n/2);
    if(n&1) res=res*x%mod;
    return res;
}

int main(){
  int n,m,k;
  cin>>n>>m>>k;
  ll a[n+1];
  a[0]=1;
  rep(i,1,n+1) a[i]=a[i-1]*i%mod;
  ll b[n+1];
  b[0]=1;
  rep(i,1,n+1) b[i]=power(a[i],998244351);
  ll ans=0;
  rep(i,0,k+1){
    ans+=(a[n-1]*b[i]%mod*b[n-1-i]%mod)*m%mod*power(m-1,n-1-i)%mod;
    ans%=mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6724
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ar array<int,2>
#define inf 1000000000000000000 
int mod=1e9+7;
int min(int a,int b){return (a<b)?a:b;}
int max(int a,int b){return (a>b)?a:b;}
int fp(int a,int b){if(b==0) return 1;int x=fp(a,b/2);x=(x*x)%mod;if(b&1) x=(x*a)%mod;return x;}


const int N=2e5+5;



void solve()
{		
	int n,x,y;
	cin>>n;
	vector<int> tmp(1ll<<2,-inf);
	int ans=-inf;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		for(int j=0;j<(1ll<<2);j++)
		{
			if(tmp[j]==-inf)
				break;
			int z=tmp[j];
			if(j&1)
				z-=y;
			else
				z+=y;
			if((j>>1)&1)
				z-=x;
			else
				z+=x;
			ans=max(ans,z);
		}

		for(int j=0;j<(1ll<<2);j++)
		{
			int z=0;
			if(j&1)
				z+=y;
			else
				z-=y;
			if((j>>1)&1)
				z+=x;
			else
				z-=x;
			tmp[j]=max(tmp[j],z);
			//cout<<tmp[j]<<endl;
		}
	}   
	cout<<ans<<endl;
}

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
 srand(time(0));
 int t=1;
 //cin>>t;
 for(int i=1;i<=t;i++)
 {
   solve();
 }


}

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

using namespace std;

#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 each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int n, x;
	cin >> n >> x;

	vector<int> a(n);
	rep(i, n) cin >> a[i];

	ll ans = 0;
	rep(i, n - 1) {
		int sum = a[i] + a[i + 1];
		if (sum > x) {
			if (a[i + 1] >= sum - x) {
				a[i + 1] -= sum - x;
			} else {
				a[i] -= sum - x - a[i + 1]; 
				a[i + 1] = 0;
			}
			ans += sum - x;
		}
	}	
	cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cctype>
using namespace std;
int main()
{
	int n;
	while(scanf("%d", &n) != EOF)
	{
		int k = n / 15;
		printf("%d\n", n * 800 - 200 * k);
	}
	return 0;
}

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

int main(){
	
	int h, w;
	cin >> h >> w;
	vector<string> s(51);
	for(int i = 0; i < h; i++)
	{
		cin >> s[i];

	}

	bool ans = true;
	vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};

	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{
			if(s[i][j] == '#'){
				bool found = false;
				for(int k = 0; k < 4; k++)
				{
					int i2 = i + dx[k];
					int j2 = j + dy[k];
					if(i2 >= 0 && i2 < h && j2 >= 0 && j2 < w && s[i2][j2] == '#') found = true; 
				}
				if(!found) ans = false;
				
			}
				
		}
		
	}
	
	cout << (ans? "Yes": "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll N;
vl x;
vl y;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    x = vl(N-1);
    y = vl(N-1);
    for(int i = 0; i < N-1; ++i){
        cin >> x[i];
        cin >> y[i];
    }
    solve();
}

// 2 <= N <= 100000
// 1 <= x_i, y_i <= N
// 与えられるグラフは木である．

vvl g;
ll f(ll x=0,ll p=-1){
    ll ret=0;
    for(ll to:g[x]){
        if(to==p)continue;
        ret^=f(to,x)+1;
    }
    return ret;
}

// ll N, vl x, vl y
// Alice が勝つなら Alice を，Bob が勝つなら Bob を出力せよ．
void solve(){
    /* (´~`) */
    g.resize(N);
    rep(i,N-1){
        g[x[i]-1].push_back(y[i]-1);
        g[y[i]-1].push_back(x[i]-1);
    }

    cout<<(f()?"Alice":"Bob")<<endl;
}


Measured memory_bytes: 12032
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
#define MOD  1000000007


int main(int argc, char const *argv[]) {
  int n;
  std::cin >> n;
  if(n==25) std::cout << "Christmas" << '\n';
  else if(n==24) std::cout << "Christmas Eve" << '\n';
  else if(n==23)std::cout << "Christmas Eve Eve" << '\n';
  else std::cout << "Christmas Eve Eve Eve" << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#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)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  cout << n*n*n << endl;
}

Measured memory_bytes: 3084
import java.util.Scanner;
public class Main {

    public static void main(String[] args){

    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int D = sc.nextInt();
    	int A = D + 1 + D;
    	int ans = N / A;

    	if (N % A > 0){
    		ans++;
    	}

    	System.out.println(ans);
    }
}

Measured memory_bytes: 22996
module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";var n=r(1);r(2)(n.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,r){"use strict";var n=r(3),i=r(5);t.exports=function(t){var e=new n(t);i(e)}},function(t,e,r){"use strict";var n=r(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new n(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,r){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,r){"use strict";var n=r(6);t.exports=function(t){var e=t.in(),r=n(e),i=e,s=1,o=e;for(var u in r){if(u>r[u])break;i>r[u]-u&&(s=u,o=r[u],i=r[u]-u)}console.log(s-1+o-1)}},function(t,e,r){"use strict";t.exports=function(t){for(var e={},r=Math.ceil(Math.sqrt(t)),n=1;n<r+1;n++)t%n==0&&(e[n]=t/n,e[t/n]=n);return e}}]);

Measured memory_bytes: 21448
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if((c>a&&c<b) || (c<a &&c>b)){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}



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

int n, w;
int dat[100];
int maxi;
int l, r;
double calc() {
  double ans = 0;
  l = 0;
  for(int i = l; i <= r; ++i) {
    ans += ((double)(r-i)/(r-l)) * ((double)dat[i]/maxi);
  }
  return ans + 0.01;
}

main() {
  while((cin >> n >> w) && (n || w)) {
    fill(dat, dat+101, 0);
    for(int i = 0; i < n; ++i) {
      int v;
      cin >> v;
      v /= w;
      ++dat[v];
      l = i == 0 ? v : min(l, v);
      r = i == 0 ? v : max(r, v);
      maxi = i == 0 ? dat[v] : max(maxi, dat[v]);
    }
    cout << calc() << endl;
  }
}

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

using namespace std;
template<typename T> void in(T &x) { x = 0; bool neg = false; register T c = getchar(); if (c == '-')neg = true, c = getchar(); while ((c < 48) || (c > 57))c = getchar(); for (; c < 48 || c > 57; c = getchar()); for (; c > 47 && c < 58; c = getchar())x = (x << 3) + (x << 1) + (c & 15); if (neg) x *= -1; }
template<typename T> void out(T n) { bool neg = 0; if (n < 0)n *= -1, neg = 1; char snum[65]; int i = 0; do { snum[i++] = n % 10 + '0'; n /= 10; } while (n); --i; if (neg)putchar('-'); while (i >= 0)putchar(snum[i--]); }
template<typename T> void outln(T n) { bool neg = 0; if (n < 0)n *= -1, neg = 1; char snum[65]; int i = 0; do { snum[i++] = n % 10 + '0'; n /= 10; } while (n); --i; if (neg)putchar('-'); while (i >= 0)putchar(snum[i--]); putchar('\n'); }
#define len(_x) (sizeof((_x)) / sizeof(_x)[0])
#define fastIO ios_base::sync_with_stdio(false); cin.tie(false);
#define ll long long
#define itr(_c) for(auto i=_c.begin();i!=_c.end();i++)
#define itrr(_c)for(auto i=_c.begin();i!=_c.end();i++)
#define f1(_x)for (int i = 0; i < _x; ++i)
#define fr(_x)for (int i = _x; i >0; i--)
#define f2(_x,_y)for (int i = _x; i < _y; ++i)
#define fileIO 	freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
typedef vector<int> vi; typedef vector<string> vs; typedef vector<bool> vb; vector<long long>vll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;

int main() {fastIO
	string s;
	std::cin >> s;
	int CNT = 0;
	int ss, tt;
	itr(s)
	{
		if (*i == 'S')ss++;
		else if (ss > 0) { CNT++; ss--; }
	}

	std::cout << s.size()-CNT*2;
	
	
}


Measured memory_bytes: 720
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)
//???
class Point{
	public:	
		double x,y;
		Point(double x = 0,double y = 0):x(x),y(y){}
		//?????????
		Point operator + (Point p) { return Point(x + p.x,y + p.y);}
		Point operator - (Point p) { return Point(x - p.x,y - p.y);}
		Point operator * (double a) { return Point(x*a,y*a);}
		Point operator / (double a) { return Point(x/a,y/a);}
		//???????????¨??§??????
		double abs() {return sqrt(norm());}
		double norm() {return x*x+y*y;}

		bool operator < (const Point &p) const{
			return x != p.x ? x < p.x : y < p.y;
		}
		bool operator == (const Point &p) const{
			return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
		}
};
//??????
struct Segment{Point p1,p2;};
//????????????
typedef Point Vector;
//??´???
typedef Segment Line;
//???
class Circle{
	public:
		Point c;
		double r;
		Circle(Point c = Point(),double r = 0.0): c(c),r(r){}
};
//????§???¢
//typedef Vector<Point> Polygon;
//????????¨??????
double dot(Vector a,Vector b){
	return a.x*b.x + a.y*b.y;
}
double cross(Vector a,Vector b){
	return a.x*b.y - a.y*b.x;
}

Point projection(Segment a,Vector hypo,Vector base){
	double r = dot(hypo,base)/base.norm();
	return  a.p1 + base*r;
}

int main(){
	int x0,y0,x1,y1;
	int n;
	int x2,y2;
	cin >> x0 >> y0 >> x1 >> y1;
	cin >> n;
	Point s(x0,y0);
	Point t(x1,y1);
	Segment seg;seg.p1 = s;seg.p2 = t;
	Vector base(t.x-s.x,t.y-s.y);
	for(int i = 0;i < n;i++){
		cin >> x2 >> y2;
		Vector hypo(x2-x0,y2-y0);
		Point p = projection(seg,hypo,base);
		printf("%.10f %.10f",p.x,p.y);
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa=[0]*n
ba=[0]*m
aa[0]=a[0]
ba[0]=b[0]
for i in range(1,n):
  aa[i]=aa[i-1]+a[i]
for i in range(1,m):
  ba[i]=ba[i-1]+b[i]
aa=[0]+aa
ba=[0]+ba
import bisect as bi
ax=bi.bisect_right(aa,k)-1
ans=0
for i in range(ax+1):
  kk=k-aa[ax-i]
  bx=bi.bisect_right(ba,kk)-1
  t=ax+bx-i
  ans=max(ans,t)
print(ans)

Measured memory_bytes: 50288
using System;
class Program
{
  static void Main(string[] args)
  {
    int N = int.Parse(Console.ReadLine());
    int A = int.Parse(Console.ReadLine());

    if (N % 500 <= A)
    {
      Console.WriteLine("Yes");
    }
    else
    {
      Console.WriteLine("No");
    }
  }
}

Measured memory_bytes: 13140
def gcd(a, b):
    while b: a, b = b, a % b
    return abs(a)

K = int(input())
s = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            s += gcd(gcd(i, j), k)
print(s)

Measured memory_bytes: 68912
<?php
$N = int();
$P = ints();
$dp[0][0] = 1;
for($i = 1; $i <= $N; $i++){
    $p = $P[$i-1];
    $q = 1-$p;
    for($j = 0; $j < $i+1; $j++){
        $dp[$i][$j] = (($dp[$i - 1][$j-1]??0) * $q + ($dp[$i-1][$j]??0) * $p); 
    }
}
$sum = 0;
for($i = 0; $i <= intdiv($N-1,2); $i++){
    $sum+=$dp[$N][$i];
}
echo $sum;

function r($n){
  return range(0, $n-1);
}
function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("doubleval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

Measured memory_bytes: 229880
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

int main() {
    int n; cin >> n;
    vector<vector<pair<int, int>>> table(n);
    rep(i, n) {
        int a; cin >> a;
        rep(j, a) {
            int x, y; cin >> x >> y;
            table[i].push_back(make_pair(x-1, y));
        }
    }
    int ans = 0;
    rep(i, (1<<n)) {
        bool fl = true;
        rep(j, n) {
            if(!(i & (1<<j))) continue;
            for(pair<int, int> p : table[j]) {
                if((bool)((1<<p.first) & i) ^ p.second) {
                    fl = false;
                }
            }
        }
        if(fl) chmax(ans, (int)bitset<20>(i).count());
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <cstdio>
#include <complex>
using namespace std;

int dir = 0;
int cur_x;
int cur_y;
int cur_side;

int refd[] = {0, 1, 0, 1};
int refx[] = {0, 0, -1, 0};
int refy[] = {0, 0, 0, -1};

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

char ans[] = "RDLU";

bool WithinRange(int d, int y, int x) {
  if (x < 0) return false;
  if (y < 0) return false;

  if (d == 0) { 
    if (x >= 4) return false;
    if (y >= 5) return false;
  } else {
    if (x >= 5) return false;
    if (y >= 4) return false;
  }
  return true;
}

char walls[2][5][5];

int main() {
  for (int i=0; i<9; i++) {
    int n = i%2 ? 5: 4;
    for (int j=0; j<n; j++) {
      scanf(" %c", &walls[i%2][i/2][j]);
    }
  }

  cur_side = -1;
  while (1) {
    int a, b, c;

    for (int i=0; i<4; i++) {
      int ndir = (dir+3+i)%4;

      a = refd[ndir];
      b = cur_y + refy[ndir];
      c = cur_x + refx[ndir];
      if (WithinRange(a, b, c) && walls[a][b][c] == '1') {
        cur_y += dy[ndir];
        cur_x += dx[ndir];
        printf("%c", ans[ndir]);
        dir = ndir;
        break;
      }
    }

    //printf("(%d, %d)\n", cur_y, cur_x);
    if (cur_y == 0 && cur_x == 0) break;
  }
  puts("");
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i_len=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back
#define mp make_pair

int main()
{
    ll N;
    cin >> N;
    vec x(N), y(N);
    REP(i,0,N) cin >> x[i] >> y[i];

    double d = 0.0;
    ll dx, dy;
    REP(i,0,N-1) {
        REP(j,i+1,N) {
            dx = x[i] - x[j];
            dy = y[i] - y[j];
            d += sqrt(dx * dx + dy * dy);
        }
    }
    cout << setprecision(12) << d * 2.0 / N << endl;

    return 0;
}

/*



*/

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long
 int main() { 
 ll a,b,c,d,i,j=0,k=0; 
    cin>>a;
    for(i=1;i<=a;i++)
    {
     d=i;
   while(d)
  {j++;
        d=d/10;
  }
if(j%2==1)k++;
j=0;
   }
cout<<k<<endl;
  }

Measured memory_bytes: 256
def solve():
    def bfs(maze, start):
        from collections import deque

        directions = ((-1,0), (1,0), (0,-1), (0, 1))
        H = len(maze)
        W = len(maze[0])
        visited = []
        for i in range(H):
            visited.append(maze[i][:])

        nexts = deque()
        nexts.append((start, 0))
        x,y = start
        visited[x][y] = '#'
        longest_distance = 0
        while nexts:
            cur_pos,cur_distance = nexts.popleft()
            longest_distance = max(cur_distance, longest_distance)
            x,y = cur_pos
            for direction in directions:
                dx,dy = direction
                next_x = x + dx
                next_y = y + dy
                next_pos = (next_x, next_y)
                if 0 <= next_x < H and 0 <= next_y < W and next_pos:
                    if visited[next_x][next_y] == '.':
                        visited[next_x][next_y] = '#'
                        nexts.append(((next_x, next_y), cur_distance+1))
        return longest_distance

    H,W = [int(i) for i in input().split()]
    maze = []
    for i in range(H):
        row = [c for c in input()]
        maze.append(row)

    ans = 0
    for i in range(H):
        for j in range(W):
            if maze[i][j] == '.':
                start = (i,j)
                longest_distance = bfs(maze, start)
                ans = max(longest_distance, ans)

    print(ans)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 9428