akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <stack>
using namespace std;
#define ll int64_t
const long mod = 1e9 + 7;


const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


//最大公約数
int gcd( int m, int n ) {
  // 引数に０がある場合は０を返す
  if ( ( 0 == m ) || ( 0 == n ) )
    return 0;
  // ユークリッドの方法
  while ( m != n ) {
    if ( m > n ) m = m - n;
    else         n = n - m;
  }
  return m;
}//gcd


//最小公倍数
int lcm( int m, int n ) { // 引数に０がある場合は０を返す
  if ( ( 0 == m ) || ( 0 == n ) )
    return 0;
  return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm




int main() {
  string s;
  cin >> s;

  long ans = 0;



  stack<char> bole;
  for (int i = 0; i < s.size(); ++i) {
    if (bole.size() >0){
      if (bole.top() ==s[i] ){
        bole.push(s[i]);
      }else{
        ans+=2;
        bole.pop();
      }
    }else{
      bole.push(s[i]);
    }
  }


  cout <<ans;
  // cout << ((ans)?  "TBD" : "Heisei" );



}




















Measured memory_bytes: 512
/* 
 * Author: pawanmsr
 */

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

// Macro //
#define X first
#define Y second
#define pii pair<int,int>
#define pll pair<ll,ll>

// Global //
int n, m, a[101];

// Functions //
bool compare(pii a, pii b) {
    if (a.X!=b.X) return a.X > b.X;
    else return a.Y >= b.Y;
}

// Main //
int main(int argc, char const *argv[])
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    
    /* code */
    cin >> n >> m;
    int tot = 0;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        tot+=a[i];
    }
    
    pii baseline = pii(tot/(4*m), tot%(4*m));
    int selected = 0;
    
    for (int i=0; i<n; i++) {
        if (compare(pii(a[i], 0), baseline))
            selected++;
    }

    if (selected >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <bitset>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dcm(a) setprecision(a)<<fixed
#define MOD 1000000007
#define clr(memo, a) memset(memo,a,sizeof(memo))
#define PI acos(-1)
int const N=2e5+5;
ll a[N];
ll b[N];
void solve()
{
int n,m;
cin>>n>>m;
ll k;
cin>>k;
for(int i=0;i<n;i++)
    cin>>a[i];
for(int i=0;i<m;i++)
    cin>>b[i];
for(int i=1;i<n;i++)
    a[i]+=a[i-1];
for(int i=1;i<m;i++)
    b[i]+=b[i-1];
int ans=0;
for(int i=0;i<n;i++){
    ll temp=k-a[i];
    if(temp>=0){
        int z=upper_bound(b,b+m,temp)-b;
        int y=z+i+1;
        ans=max(ans,y);
    }
}
int z=upper_bound(b,b+m,k)-b;
ans=max(ans,z);
cout<<ans<<endl;
}


int main()
{
    fast;

    solve();

    }


Measured memory_bytes: 6768
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, L = mapint()
apples = [L+i for i in range(N)]
pos_apples = [abs(a) for a in apples]
apples.pop(pos_apples.index(min(pos_apples)))
print(sum(apples))

Measured memory_bytes: 61392
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define popb(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  ll n,a[50001]={},ans=1e9;
  while(1){
    cin>>n;
    if(n==0)return 0;
    rep(i,0,n)cin>>a[i];
    sort(a,a+n);
    rep(i,1,n){
      ans=min(ans,a[i]-a[i-1]);
    }
    cout<<ans<<endl;
    ans=1e9;
  }
}

Measured memory_bytes: 3516
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

int main() {
	int H, N;
	int A[100000];

	cin >> H >> N;

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

	for (int i = 0; i < N; i++) {
		H -= A[i];
	}

	if (H <= 0) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-5;
const ll MOD=1e9+7;
int main(){
    int x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;
    cout<<x2+(y1-y2)<<" "<<y2-(x1-x2)<<" "<<x1+(y1-y2)<<" "<<y1-(x1-x2)<<endl;
}   


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

using namespace std;

#define ll long long
#define PI 3.14159265358979323846264338327950L

int a[200004];
int n,aa;

void solve(){

    cin >> n;

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

    for (int i = 1; i < n; i++)
    {
        cin >> aa;
        aa--;
        a[aa]++;
    }
    
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << endl;
    }
    
}





int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}

Measured memory_bytes: 4380
#include<string>
#include<iostream>

using namespace std;

int main(){
	for(string R,G,res;cin>>R>>G>>res;){
		int pr=0,pg=1,p=0;
		char cen=G[0];
		string ans;
		while(p<res.length()){
			if(cen==res[p]){
				p++;
				cen=R[pr++];
			}
			else{
				ans+=cen;
				cen=G[pg++];
			}
		}
		cout<<ans<<cen<<G.substr(pg)<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<bitset>
#include<stack>
using namespace std;
#define MOD 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

bitset<324> mat[324];
Int cnt,n, m,a;
Int mod_pow(Int x, Int a, Int m = MOD){
  if(a == 0)return 1;
  Int res = mod_pow(x, a / 2, m);
  res = res * res % m;
  if(a % 2)res *= x;
  return res % m;
}

Int inv(Int x, Int m = MOD){
  return mod_pow(x, m-2, m);
}


int main(){
  cin >> n >> m;
  for(int i = 0;i < n;i++){
    for(int j = 0;j < m;j++){
      cin >> a;
      if(a)mat[i].set(j);
    }
  }
  int p = 0;
  for(int i = 0;i < n;i++){
    if(p == m)continue;
    int st = i;
    while(st < n && !mat[st][p])st++;
    if(st == n){
      p++;
      i--;
      continue;
    }
    cnt++;
    if(st != i)swap(mat[st], mat[i]);
    for(int j = i+1;j < n;j++){
      if(mat[j][p])mat[j] ^= mat[i];
    }
  }
  cout << ((mod_pow(2, n+m) - mod_pow(2,n+m-cnt))*inv(2) % MOD+ MOD )% MOD << endl;
  return 0;
}


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

int n,m,a,b;
vector<int> veze[200005];
int bio[200005];
queue<int> Q;
vector<int> sol;
bool check;

int main() {
    cin >> n >> m;
    for (int i=0;i<m;i++) {
        cin >> a >> b;
        veze[a].push_back(b);
        veze[b].push_back(a);
    }
    bio[1]=1;
    Q.push(1);
    while(!Q.empty()) {
        a=Q.front();
        Q.pop();
        for (auto e : veze[a]) {
            if (bio[e]==0) {
                bio[e]=bio[a]+1;
                Q.push(e);
            }
        }
    }

    check=true;
    for (int i=2;i<=n;i++) {
        if (bio[i]==0) {
            check=false;
            break;
        }
        for (auto e : veze[i]) {
            if (bio[e]<bio[i]) {
                sol.push_back(e);
                break;
            }
        }
    }
    if (!check) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
        for (auto e : sol) {
            cout << e << endl;
        }
    }

}


Measured memory_bytes: 13228
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define debug_array(a,n) for (ll bccc=(0); bccc<(n); bccc++) cout<<a[bccc]<<" "
#define debug_vector(a) for(ll bccc=(0); bccc<(a.size());bccc++) cout<<a[bccc]<<" "
#define F           first
#define S           second
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll i;
    for(i=0;i<b;i++)
        c*=a;
    return c;
}
//ll hell=1000000007;
ll hell=998244353 ;
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;
}
// mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());  after namespace std
// srand(chrono::high_resolution_clock::now().time_since_epoch().count()); after ios:base
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b;
    cin>>a>>b;
    ll i;
    for(i=max(-1000000LL,b-a+1);i<=min(1000000LL,b+a-1);i++)
        cout<<i<<" ";
    return 0;
}


Measured memory_bytes: 256
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll  long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define bp __builtin_popcountll
#define MOD 1000000007
const int N = 2e5 + 5;
 
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>



int main() 
{
    FAST;
    ll n,k;
    cin >> n >> k;
    ll a[n];
    ll dp[k+1];
    memset(dp,-1,sizeof(dp));
    for(ll i=0;i<n;i++)  cin >> a[i],dp[a[i]]=1;
    for(ll i=1;i<=k;i++)
    {
        if(dp[i]!=-1)   continue;
        ll chk = 0;
        for(ll j=0;j<n;j++)
        {
            if(i-a[j]>=1 && dp[i-a[j]]==0)
            {
                chk=1;
            }
        }
        if(chk)  dp[i]=1;
        else     dp[i]=0;
    }
    if(dp[k])  cout<<"First";
    else       cout<<"Second";
    
}    

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  

ll MOD = 1000000007;
ll INF = 1145141919;

int main(){
    ll N, M; cin >> N >> M;

    ll ans = 0;
    while(N <= M){
        N *= 2;
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 764
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

int main(void) {
    string S;
    cin >> S;

    int Q;
    cin >> Q;

    string ls = "";
    string rs = S;

    for (int i = 0; i < Q; i++) {
        int q;
        cin >> q;
        if (q == 1) {
            swap(ls, rs);
        } else {
            int f;
            char c;
            cin >> f >> c;

            if (f == 1) {
                ls.push_back(c);
            } else {
                rs.push_back(c);
            }
        }
    }

    reverse(ls.begin(), ls.end());
    cout << ls << rs << endl;

    return 0;
}


Measured memory_bytes: 3936
#include<bits/stdc++.h>
#define ld long double
#define ll long long
#define st first
#define nd second
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
using namespace std;
const int N = 501;
int n, p[N * N], q[N * N], dp[N * N];
int ans;
int vis[N * N], iter;
int getX(int x) {
	return x/n;
}
int getY(int x) {
	return x%n;
}
int dist(int a, int b) {
	return abs(getX(a) - getX(b)) + abs(getY(a) - getY(b));
}
void bfs(int X) { 
	deque<int> Q;
	Q.push_back(X);
	while(Q.size()) {
		int x = Q.front();
		Q.pop_front();
		if(vis[x]==iter) continue;
		vis[x] = iter;
		if(getY(x) < n-1) {
			if(q[x] < iter && dp[x+1] > dp[x]) {
				dp[x+1] = dp[x];
				Q.push_front(x+1);
			}
			else if(dp[x+1] > dp[x]+1){
				dp[x+1] = dp[x]+1;
				Q.push_back(x+1);
			}
		}
		if(getY(x) > 0) {
			if(q[x] < iter && dp[x-1] > dp[x]) {
				dp[x-1] = dp[x];
				Q.push_front(x-1);
			}
			else if(dp[x-1] > dp[x]+1){
				dp[x-1] = dp[x]+1;
				Q.push_back(x-1);
			}
		}
		if(getX(x) < n-1) {
			if(q[x] < iter && dp[x+n] > dp[x]) {
				dp[x+n] = dp[x];
				Q.push_front(x+n);
			}
			else if(dp[x+n] > dp[x]+1){
				dp[x+n] = dp[x]+1;
				Q.push_back(x+n);
			}
		}
		if(getX(x) > 0) {
			if(q[x] < iter && dp[x-n] > dp[x]) {
				dp[x-n] = dp[x];
				Q.push_front(x-n);
			}
			else if(dp[x-n] > dp[x]+1){
				dp[x-n] = dp[x]+1;
				Q.push_back(x-n);
			}
		}
	}
}
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=0; i<n*n; ++i) {
		cin>>p[i];
		p[i]--;		
		q[p[i]] = i;
		dp[p[i]] = min({getX(p[i]), n - getX(p[i]) - 1, getY(p[i]), n - getY(p[i]) - 1});
	}
	for(int i=0; i<n*n; ++i) {
		iter++;
		int cur = p[i];
		ans += dp[cur];
		bfs(cur);
	}
	cout<<ans;
}


Measured memory_bytes: 8000
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; 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)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  cout << "ABC"
  << setfill('0') << right << setw(3) << N 
  << setfill(' ') << endl;
  return 0;
}

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

int main(){
  ll N; cin >> N;
  ll sum = 0LL;
  vector<ll> a(N);
  bitset<4000001> b(1);
  for(ll i = 0; i < N; i++){
    cin >> a[i];
    sum += a[i];
    b |= (b << a[i]);
  }
  ll hs = sum/2 + sum%2;
  while(1){
    if(b[hs]) {
      cout << hs << endl;
      break;
    }
    hs++;
  }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
void solve(){
    string s,t;
    cin>>s>>t;
    int dp[s.length()+1][t.length()+1];
    for(int i=0;i<=s.length();i++){
        for(int j=0;j<=t.length();j++){
            if(i==0||j==0) dp[i][j]=0;
            else if(s[i-1]==t[j-1])
            dp[i][j]=1+dp[i-1][j-1];
            else
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int len=dp[s.length()][t.length()];
    char ans[len];
    int i=s.length(),j=t.length();
    while(i>0&&j>0){
        if(s[i-1]==t[j-1]){
            ans[len-1]=s[i-1];
            i--;j--;len--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
        i--;
        else
        j--;
    }
    for(auto x:ans) cout<<x;
}
int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 35456
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))[::-1]
l=0
r=n-1
ans=[]
for i in range(n):
    if a[i]==b[i]:
        ans.append(i)

for i in ans:
    if b[i]!=a[l] and b[i]!=b[l]:
        b[l],b[i]=b[i],b[l]
        l+=1
        continue
    if b[i]!=a[r] and b[i]!=b[r]:
        b[r],b[i]=b[i],b[r]
        r-=1
f=0
for i in range(n):
    if a[i]==b[i]:
        f=1
        break
if f:
    print("No")
else:
    print("Yes")
    print(*b)







Measured memory_bytes: 119004
#include <stdio.h>
#include <iostream>
int main(void){
  long long int N,M;
  std::cin >> N >> M;
  long long int ans=0;
  if(M <= N){
    ans += M/2;
    printf("%lld",ans);
    return 0;
  }
  if(M-2*N >= 0){
    ans += N;
    M -= 2*N;
  }else{
    ans += 2*N-M;
    M -= 2*(2*N-M);
  }
  if(M >= 0){
    ans += M/4;
  }
  printf("%lld",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	long long K;
	scanf("%lld", &K);

	int N;
	long long a[50];

	if(K==0){
		printf("2\n");
		printf("1 1\n");
	}else if(K==1){
		printf("2\n");
		printf("2 0\n");
	}else if(2<=K && K<=50){
		printf("%d\n",K);
		for(int i=K;i>0;i--) printf("%d ", i);
		printf("\n");
	}else{
		printf("50\n");
		for(int i=0;i<50;i++){
			a[i] = (50-i) + (K/50) - 1;
		}
		for(int i=0;i<(K%50);i++){
			a[i]++;
		}
		for(int i=0;i<50;i++){
			printf("%lld ",a[i]);
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var H, W int
	fmt.Scan(&H, &W)
	a := make([]string, H)
	for i := 0; i < H; i++ {
		fmt.Scan(&a[i])
	}
	ans := ""
	for i := 0; i < W + 2; i++ {
		ans += "#"
	}
	ans += "\n"
	for i := 0; i < H; i++ {
		ans += "#" + a[i] + "#\n"
	}
	for i := 0; i < W + 2; i++ {
		ans += "#"
	}
	ans += "\n"
	fmt.Println(ans)
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

struct less_key {
    bool operator()(const std::pair<i64,i64> &left, const std::pair<i64,i64> &right) {
        return left.first < right.first;
    }
};

const i64 MAXN = 300005;

i64 n;

i64 a[MAXN];
i64 b[MAXN];

i64 c[MAXN];

i64 an;
i64 bn;

i64 R;

void check(i64* a, i64& an) {
    for (i64 i = 0; i < n; i++) {
        if(a[i] != c[i]) {
            return;
        }
    }

    an = R;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

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

    for(;;) {
        check(a, an);
        check(b, bn);

        if (!next_permutation(c, c + n)) {
            break;
        }
        R += 1;
    }

    cout << abs(an - bn) << endl;

    return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;


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

ll lcm(ll a,ll b){
    ll g =gcd(a,b);
    return a/g*b;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,a[100010],ans;
    cin>>n;
    rep(i,n){
        cin>>a[i];
    }
    ans=a[0];
    rep(i,n){
        ans=lcm(ans,a[i]);
    }
    cout<<ans<<endl;
    return 0;
}


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

vector<vector<int>> g;
vector<int> x;
vector<int> counter;
typedef tuple<int, int, int> T;

// void solve(int current_p, int previous_p, int current_counter)
// {
//     current_counter += x[current_p];
//     counter[current_p] += current_counter;
//     for (size_t i = 0; i < g[current_p].size(); i++) {
//         if (g[current_p][i] == previous_p) continue;
//         solve(g[current_p][i], current_p, current_counter);
//     }
// }

int main(void)
{
    int n, q;
    cin >> n >> q;
    g = vector<vector<int>>(n, vector<int>());
    for (int i = 0; i < n-1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    x = vector<int>(n, 0);
    for (int i = 0; i < q; i++) {
        int p;
        int xp;
        cin >> p >> xp;
        p--;
        x[p] += xp;
    }
    counter = vector<int>(n, 0);

    // solve(0, -1, 0);
    queue<T> que;
    que.push(T(0, -1, 0));
    while (que.size()) {
        T t = que.front(); que.pop();
        int current_p = get<0>(t);
        int previous_p = get<1>(t);
        int current_counter = get<2>(t);
        current_counter += x[current_p];
        counter[current_p] += current_counter;
        for (size_t i = 0; i < g[current_p].size(); i++) {
            if (g[current_p][i] == previous_p) continue;
            que.push(T(g[current_p][i], current_p, current_counter));
        }
    }

    for (int i = 0; i < n; i++) {
        cout << counter[i];
        if (i < n-1) cout << " ";
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 17908
let n = read_int ()
let f m = let cs = Array.make 8 0 in let rec f n =
  if n = 0 then cs.(3) + cs.(5) + cs.(7) = 3 else (cs.(n mod 10) <- 1; f (n / 10)) in m <= n && f m
let rec g m = if m > n then 0 else List.fold_left (fun c k -> c + g (10 * m + k) + if f @@ 10 * m + k then 1 else 0) 0 [3; 5; 7]
let _ = g 0 |> Printf.printf "%d\n"

Measured memory_bytes: 2560
n = int(input())
arr = []
queue = []
from heapq import heappush, heappop
for i in range(n):
    a = int(input())
    heappush(queue, -a)
    arr.append(a)
first = -heappop(queue)
second = -heappop(queue)
for a in arr:
    print(first if a != first else second)

Measured memory_bytes: 82136
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>

using namespace std;

int main(void)
{
	int a[5], k;

	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;

	bool flag = true;
	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			if (a[j] - a[i] > k) {
				flag = false;
			}
		}
	}

	if (flag) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

// constexpr inline ll mod = 1'000'000'007;
// constexpr int max_n = 200'000 + 5;

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    int n,m; cin>>n>>m;
    int sum = 0;
    rep(i,m) {
        int a; cin>>a;
        sum += a;
    }
    cout << max(-1, n - sum) << '\n';

    return 0;
}


Measured memory_bytes: 3624
export class Main {
  static main(input: string): string {
    const tmp = input.split("\n");
    const [a, b] = tmp[0].split(" ").map(Number);
    return `${b + (b % a == 0 ? 1 : -1) * a}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
int main()
{
    long long N;
    string s;
    cin >> N >> s;
    long long r = 0,g = 0,b = 0;
    for(int i = 0;i < N;i++){
        if(s[i] == 'R') r++;
        else if(s[i] == 'G') g++;
        else b++;
    }
    long long all = r*g*b;
    long long mcount = 0;
    for(long long i = 0;i < N;i++){
        for(long long j = i + 1;j < N;j++)
        {
            if(s[i] == s[j]) 
                continue;
            long long k = j + j - i;   
            if(k >= N) 
                continue;
            if(s[j] == s[k] or s[i] == s[k]) 
                continue;
            mcount++;
        }
    }
    cout << all - mcount << '\n';
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int cnt=0,ans=0;
	for(int i=0;i<3;i++)
	{
		if(s[i]=='S')
			cnt=0;
		else
			cnt++;
		ans=max(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3624
N = int(input())
h = list(map(int,input().split()))

dp = [0]*N
dp[1] = abs(h[0]-h[1])
for i in range(2,N):
    dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))
print(dp[-1])

Measured memory_bytes: 13928
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
ll n,b,sum=0,y=0;
cin>>n;
ll a[n];
for(ll i=0;i<n;i++)
    cin>>a[i];
sort(a,a+n);
 for(ll i=0;i<n;i++)
    {
        y+=(a[i]-a[n-1])*(a[i]-a[n-1]);

    }
for(ll j=1;j<a[n-1];j++)
{
    sum=0;
    for(ll i=0;i<n;i++)
    {
        sum+=(a[i]-j)*(a[i]-j);

    }
         y=min(sum,y);

}
cout<<y<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define REP(i,n)    for(int i = 0; i < (int)n; i++)
#define MAX_N   100000
typedef long long ll;

void solve(){
    string s;
    cin >> s;
    bool a = true;
    REP(i, s.length() - 1){
        if(s[i] == s[i + 1]){
            cout << "Bad\n";
            a = false;
            break;
        }
    }
    if(a)
        cout << "Good\n";
}

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

Measured memory_bytes: 256
from collections import deque
q = deque(input())
Q = int(input())
cnt = 0
for i in range(Q):
    query = input().split()
    if query[0] == '1':
        cnt += 1
    else :
        if query[1] == '1':
            if cnt % 2 == 0:
                q.appendleft(query[2])
            else :
                q.append(query[2])
        else :
            if cnt % 2 == 1:
                q.appendleft(query[2])
            else :
                q.append(query[2])
if cnt % 2 == 1: q.reverse()
print(''.join(q))

Measured memory_bytes: 8692
#include<iostream>
#include<queue>

using namespace std;

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFINITY -1

int n,M[N][N];
int color[N], d[N];

void bfs_visit(int u){

  queue<int> Q;
  color[u] = GRAY;
  Q.push(u);

  d[u] = 0;

  int present;
  while( !Q.empty() ){
    present = Q.front();
    Q.pop();
    color[present] = BLACK;

    for(int v=0;v<n;v++){
      if( M[present][v] == 1 && color[v] == WHITE ){
        Q.push(v);
        color[v] = GRAY;
        d[v] = d[present] + 1;
      }
    }  
  }
}

void bfs(int u){

  for(int i=0;i<n;i++){
    color[i] = WHITE;
    d[i] = INFINITY;
  }

  bfs_visit(u);

  for(int i=0;i<n;i++){
    cout << i+1 << " " << d[i] << endl;
  }
}


int main(void){

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

  int u,v,k;
  for(int i=0;i<n;i++){
    cin >> u >> k;
    for(int j=0;j<k;j++){
      cin >> v;
      M[u-1][v-1] = 1;
    }
  }

  bfs(0);

  return 0;
}



Measured memory_bytes: 3128
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;

void main()
{
    auto N = readln.chomp.to!int;
    auto A1 = readln.split.to!(int[]);
    auto A2 = readln.split.to!(int[]);

    A2[0] += A1[0];
    foreach (j; 1..N) {
        A1[j] += A1[j-1];
        A2[j] += A1[j] > A2[j-1] ? A1[j] : A2[j-1];
    }
    writeln(A2[N-1]);
}

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

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

vector<int> p[MAX_N];
int pp[MAX_N];
int par[MAX_N];
char c[MAX_N];
int num[MAX_N];
int a[MAX_N];
int first[MAX_N];

void initial(int n){		//?????????
	for(int i=0;i<n;i++){
		par[i] = i;
	}
}

int find(int x){		//??¨??????????±???????
	if(par[x] == x){
		return x;
	}else{
		return par[x] = find(par[x]);
	}
}

void unite(int x,int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	par[y] = x;
}

bool same(int x,int y){
	return find(x) == find(y);
}

void dfs(int v,int anc)
{
	if(a[v]==1){
		rep(i,p[v].size()){
			dfs(p[v][i],v);
		}
	}else{
		unite(anc,v);
		rep(i,p[v].size()){
			dfs(p[v][i],anc);
		}
	}
}

int main()
{
	while(1){
		int n,q;
		cin >> n >> q;
		if(n==0&&q==0){
			break;
		}
		rep(i,n){
			p[i].clear();
		}
		rep(i,n-1){
			int x;
			scanf("%d",&x);
			p[x-1].push_back(i+1);
			pp[i+1] = x-1;
		}
		initial(n);
		fill(a,a+n,0);
		a[0] = 1;
		rep(i,q){
			scanf("%*c%c%d",&c[i],&num[i]);
			if(c[i]=='M'){
				if(a[num[i]-1] == 0){
					a[num[i]-1] = 1;
					first[num[i]-1] = i;
				}
			}
		}
		dfs(0,0);
		ll ans = 0;
		for(int i=q-1;i>=0;--i){
			if(c[i] == 'M' && i == first[num[i]-1]){
				unite(pp[num[i]-1],num[i]-1);
			}else if(c[i] == 'Q'){
				ans += find(num[i]-1)+1;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

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


using namespace std;

int main(){
    string s;
    cin >> s;
    bool ans = false;
    if(s[2]==s[3]&&s[4]==s[5]) ans = true;
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;    
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <cctype>
#include <cstring>
#include <cassert>

using namespace std;

struct state {
  int x,y,u,t,c;
  state(){}
  state(int x,int y,int u,int t,int c):x(x),y(y),u(u),t(t),c(c){}
};

int cost[20][20][1<<8][100];
char g[20][20];
int n,v[8],d[8],s[8],e[8];
int w,h;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

int main(void)
{
  for(;;) {
    scanf("%d%d",&w,&h); if(w+h == 0)break;
    int x,y; x = y = -1;
    for( int i = 0; i < h; i++ ) {
      for( int j = 0; j < w; j++ ) {
        scanf(" %c",g[i]+j);
        if( g[i][j] == 'P' ) {
          g[i][j] = '.';
          x = j;
          y = i;
        }
      }
    }
    assert(x>=0 && y>=0);
    scanf("%d",&n);
    for( int i = 0; i < n; i++ ) {
      scanf("%d%d%d%d",v+i,d+i,s+i,e+i);
    }
    int res = 0;
    queue<state> q;
    q.push(state(x,y,0,0,0));
    memset(cost,-1,sizeof(cost));
    while( !q.empty() ) {
      state p = q.front(); q.pop();
      //printf("%d %d %02x %d %d\n",p.x,p.y,p.u,p.t,p.c);
      if( p.t >= 100 ) continue;
      if( res < p.c ) res = p.c;
      for( int i = 0; i < 4; i++ ) {
        x = p.x+dx[i];
        y = p.y+dy[i];
        if( x < 0 || x >= w || y < 0 || y >= h ) continue;
        if( isdigit(g[y][x]) ) {
          int k = g[y][x]-'0';
          if( !(p.u>>k&1) ) {
            for( int j = 0; j < n; j++ ) {
              if( s[j] <= p.t && p.t < e[j] && v[j] == k ) {
                if( cost[p.y][p.x][p.u|1<<k][p.t] < p.c+d[j] ) {
                  cost[p.y][p.x][p.u|1<<k][p.t] = p.c+d[j];
                  q.push(state(p.x,p.y,p.u|1<<k,p.t,p.c+d[j]));
                }
              }
            }
          }
        }
        if( g[y][x] == '.' && cost[y][x][p.u][p.t+1] < p.c ) {
          cost[y][x][p.u][p.t+1] = p.c;
          q.push(state(x,y,p.u,p.t+1,p.c));
        }
      }
    }
    printf("%d\n",res);
  }
  return 0;
}

Measured memory_bytes: 41756
loop{
  r, c = readline.split.map(&:to_i)
  break if r == 0 && c == 0

  a = []
  r.times{
    a << readline.split.map(&:to_i)
  }

  # ???????????????????????¨???????????¢?????????
  # ???????????¢??????0-????´???? 1-????´????????°??????????
  max_ura_num = 0
  (2 ** (r-1)).times{|idx|
    b = a.dup

    # idx(2?????°) ??§ 1 ??? bit ??????????????¢
    ("%b" % idx).rjust(r, "0").chars.map(&:to_i).each_with_index{|val, inv_row|
      next if val == 0
      b[inv_row] = a[inv_row].dup.map{|val| 1-val}
    }

    # p b
    # ???????????¢
    b = b.transpose
    ura_num = 0
    b.each{|col|
      # ??¨?????°
      col_ura_num = r - col.inject{|result, item| result + item}
      # p "#{col_ura_num} #{col}"
      if col_ura_num <= r/2
        col_ura_num = r - col_ura_num
      end
      ura_num += col_ura_num
    }
    # p ura_num
    max_ura_num = [ura_num, max_ura_num].max
  }

  puts max_ura_num
}

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

using namespace std;

typedef long long ll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define rep(i,n) for(int i=0;i<(n);i++)
int N;
double Count=0;
vector<int> X(0),Y(0);
bool visit[9]={false};
//vは原点からの移動距離
void DFS(int v,double l,int Co){
    if(Co==N){
        Count+=l;
        return;
    }
    visit[v]=true;


    for(int i=0;i<N;i++){
        if(visit[i])continue;
        int a=X[i]-X[v],b=Y[i]-Y[v];
        double range=sqrt(a*a+b*b);
        DFS(i,range+l,Co+1);
    }
    visit[v]=false;
    return ;
}

int main(){
    cin>>N;
    X.resize(N),Y.resize(N);
    rep(i,N)cin>>X[i]>>Y[i];
    for(int i=0;i<N;i++){
        visit[i]=true;
        DFS(i,0,1);
        visit[i]=false;
    }

    double b=1;
    for(int i=2;i<=N;i++){
        b*=i;
    }

    cout<<setprecision(10)<<Count/b<<endl;

    return 0;
}

//a=97,z=122

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

#define INF 1e9

using namespace std;
typedef long long ll;

int main(void) {
  string s, t, result;
  result = "No";
  
  cin >> s >> t;

  if (s == t) {
  } else if (s == t.replace(t.size() - 1, 1, "")) {
    result = "Yes";
  }
  cout << result << endl;
}

Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
import numpy as np

n, k = map(int, input().split())
d = np.zeros((k))
a = np.zeros(())
list_all = []
set_all = {}
for i in range(k):
    d = input()
    list_all.extend(input().split())
    set_all = set(list_all)

ans = n - len(set_all)

print(ans)


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

using namespace std;
#define BUF (200005)
#define ll long long 

int n;

ll A[BUF];
ll B[BUF];

ll a[BUF];
ll b[BUF];


int main(void){
	cin >> n;
	for(int i=1;i<=n;i++) cin >> A[i];
	for(int i=1;i<=n;i++) cin >> B[i];

	ll ans=0;
	for(int k=0;k<31;k++){
		ll cnt = 0;
		ll T = 1 << k;
		for(int i=0;i<=n;i++) a[i] = A[i]%(2*T);
		for(int i=0;i<=n;i++) b[i] = B[i]%(2*T);
		sort(b+1,b+n+1);

		for(int i=1;i<=n;i++){
			ll *j0 =lower_bound(b+1,b+n+1,1*T-a[i]);
			ll *j1 =lower_bound(b+1,b+n+1,2*T-a[i]);
			ll *j2 =lower_bound(b+1,b+n+1,3*T-a[i]);
			ll *j3 =lower_bound(b+1,b+n+1,4*T-a[i]);
			cnt+= (j1-j0) + (j3-j2) ;
			//out << j0-b << j1-b << j2-b<< j3-b << " ";
			//cout << "  " << cnt << "\n";
		}
		//cout << "\n";
		//cout << T <<  k << cnt << "\n";
		if(cnt%2==1) ans+= T;
		
	}	

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


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

using namespace std;
// const int MOD = 1e9+7;
const int MOD  = 998244353;
const int INF = 0x3f3f3f3f;
const double PI = 4*atan(1);
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
// ll gcd(ll a, ll b) { 
//     if (a == 0) return b; 
//     return gcd(b % a, a); 
// }
// ll mod(ll x) {
// 	x%=MOD;
// 	if(x<0)x+=MOD;
// 	return x;
// }
// ll power(int base, int power) {
// 	ll prod = 1;
// 	ll b = base;
// 	while(power) {
// 		if (power & 1) {
// 			prod = mod(prod*b);
// 		}
// 		b = mod(b*b);
// 		power/=2;
// 	}
// 	return prod;
// }
// struct line {
//     int m, c;
//     ll eval(int x) { return 1LL * m * x + c; }
//     double intersectX(line l) { return (double) (c - l.c) / (l.m - m); }
int k;
string s;
void solve() {
	cin >> k >> s;
	if (s.length()>k) {
		cout << s.substr(0,k) << "...\n";
	} else {
		cout << s << endl;
	}
}
int main() {
	int t=1;
	// cin >> t;
	for (int i = 1; i <= t; i++) { 
		// cout << "Case #" << i << ": ";
		solve();
	}
}

Measured memory_bytes: 3632
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	m := iScan()
	if n*2 >= m {
		fmt.Println(m / 2)
	} else {
		fmt.Println(n + (m-2*n)/4)
	}
}


Measured memory_bytes: 1772
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納　par[x] == x の時そのノードは根
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0)
        self.rank = [0] * (n+1)
        # 各々の集合の要素数（根が代表して値を持っておく）
        self.count = [1] * (n+1)

    # 検索
    def find(self, x):
        # 根ならその番号を返す
        root = x
        queue = [x]
        data = []
        while queue:
            now = queue.pop()
            if self.par[now] == now:
                root = now
            else:
                # 根でないなら親の要素で再検索
                data.append(now)
                queue.append(self.par[now])
        # 検索する過程で親を更新
        for y in data:
            self.par[y] = root
        return root

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return True
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.count[y] += self.count[x]
            self.count[x] = 0
        else:
            self.par[y] = x
            self.count[x] += self.count[y]
            self.count[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
        return False

    # 同じ集合に属しているか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    # 属している集合の要素数
    def size(self, x):
        q = UnionFind.find(self, x)
        return self.count[q]


n, m = map(int, input().split())
data = [tuple(map(lambda z: int(z) - 1, input().split())) for _ in range(m)]
ans = 0
for i in range(m):
    u = UnionFind(n)
    for j in range(m):
        if i == j:
            continue
        u.union(data[j][0], data[j][1])
    ans += 0 if u.same_check(data[i][0], data[i][1]) else 1

print(ans)


Measured memory_bytes: 45016
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    map<int,int> mp;
    set<int> st;
    rep(i, n)
    {
        cin >> a[i];
        mp[a[i]]++;
        st.insert(a[i]);
    }
    ll a1,a2 = 0;
    for(auto e:st){
        if(mp[e]>=2){
            a2 = a1;
            if(mp[e] >= 4)a2 = e;
            a1 = e;
        }
    }
    cout << a1 * a2 << endl;
}

Measured memory_bytes: 9984
#include <stdio.h>
int main(void)
{
    char s[10*10*10*10*10*10];
    int i=0, n, q, l[10*10*10*10*10], r[10*10*10*10*10], j;
    int cnt, c[10*10*10*10*10*10]={0};
    scanf("%d%d", &n, &q);
    scanf("%s", s);
    for(i=0;i<q;i++){
        scanf("%d%d", &l[i], &r[i]);
    }

    i=0;
    while(s[i]!='\0'){
        if(s[i]=='A' && s[i+1]=='C'){
            c[i+1]=c[i]+1;
            }
        else{
            c[i+1]=c[i];
        }
        i++;
    }
   
    for(i=0;i<q;i++){
        printf("%d\n", c[r[i]-1]-c[l[i]-1]);
    }

    return 0;
}


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

#define real() cout<<"\n";

#define debug(arguments...) {string pri=#arguments;replace(pri.begin(),pri.end(),',',' ');stringstream prii(pri);istream_iterator<string> _iterat(prii);error(_iterat,arguments);}
void error(istream_iterator<string> _iterat) {}
template<typename T,typename...args>
void error(istream_iterator<string> _iterat,T a,args...arguments)
{
    cerr<<*_iterat<<"="<<a<<"\n";
    error(++_iterat,arguments...);
}

#define debugmp(z) {string pri=#z;error(pri,z);}
template<typename T,typename V>
void error(string pri,const pair<T,V> &z)
{
    cerr<<pri<<"="<<"{"<<z.first<<","<<z.second<<"}"<<"\n";
}
template<typename T,typename V>
void error(string pri,const map<T,V> &z)
{
    cerr<<pri<<" is={";
    for(auto it=z.begin();it!=z.end();++it)
    {
        cerr<<it->first<<":"<<it->second;
        auto _it=z.end();
        _it--;
        if(it!=_it) cerr<<",";
    }
    cerr<<"}";
    cerr<<"\n";
}

#define debugc(z,st,ed) {string pri=#z;error(pri,z,st,ed);}
template<typename T>
void error(string pri,const vector<T> &z,long long st,long long ed)
{
    cerr<<pri<<" in range["<<st<<","<<ed<<")=[";
    for(long long i=st;i<ed;++i)
    {
        cerr<<z[i];
        if(i!=ed-1) cerr<<" ";
    }
    cerr<<"]";
    cerr<<"\n";
}
template<typename T>
void error(string pri,const set<T> &z,long long st,long long ed)
{
    cerr<<pri<<" in range["<<st<<","<<ed<<")=[";
    long long tempcount=0;
    for(auto it=z.begin();it!=z.end();++it)
    {
        if(tempcount>=st and tempcount<ed)
        {
            cerr<<*it;
            if(tempcount!=ed-1) cerr<<" ";
        }
        tempcount++;
    }
    cerr<<"]";
    cerr<<"\n";
}
template<typename T>
void error(string pri,const T z[],long long st,long long ed)
{
    cerr<<pri<<" in range["<<st<<","<<ed<<")=[";
    for(long long i=st;i<ed;++i)
    {
        cerr<<z[i];
        if(i!=ed-1) cerr<<" ";
    }
    cerr<<"]";
    cerr<<"\n";
}

void logic()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;++i)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    cout<<arr[n-1]-arr[0];
    cout<<"\n";
    //incase of wrong answer...stress test your code...do not stress test yourself
    //overflow,bounds,size,constraints
    //sample tests,corner case/special case(n==0 or n==1 or negative numbers...),some hand written tests
    //read statement carefully
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    long long t;
    //cin>>t;
    //while(t--)
    {
        logic();
    }
}


Measured memory_bytes: 3704
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);


		String [] S = sc.next().split("");

		int i=0;
		int g=0;
		while(i<S.length) {
			if(g==0) {
				if(S[i].equals("L")) {
					g=3;
					break;
				}
			}else {
				if(S[i].equals("R")){
					g=3;
					break;
				}
			}
			i++;

			if(g==0) {
				g++;
			}else {
				g--;
			}
		}

		if(g==3) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}


	}

}


Measured memory_bytes: 21460
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<map>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 110000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

ll dp[110000][4];

int main(){
    string s;
    cin>>s;
    dp[0][0]=1;
    for(int i=0;i<(int)s.size();i++){
        for(int j=0;j<4;j++){
            if(j==3){
                if(s[i]=='?') dp[i+1][j]+=dp[i][j]*3;
                else dp[i+1][j]+=dp[i][j];
                dp[i+1][j]%=MOD;
                continue;
            }
            if(j==0 && s[i]=='A') dp[i+1][1]+=dp[i][j];
            else if(j==1 && s[i]=='B') dp[i+1][2]+=dp[i][j];
            else if(j==2 && s[i]=='C') dp[i+1][3]+=dp[i][j];
            
            if(s[i]=='?'){
                dp[i+1][j+1]+=dp[i][j];
                dp[i+1][j]+=dp[i][j]*3;
            } else{
                dp[i+1][j]+=dp[i][j];
            }
            dp[i+1][j+1]%=MOD;
            dp[i+1][j]%=MOD;
        }
    }
    cout<<dp[(int)s.size()][3]<<endl;
}



Measured memory_bytes: 3712
#include<stdio.h>
#include<stdlib.h>

int asc(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(){
    int N, x, i;
    int a[110];

    scanf("%d %d", &N, &x);
    for(i=0; i<N; i++){
        scanf("%d", &a[i]);
    }

    qsort(a, N, sizeof(int), asc);
    for(i=0; i<N; i++){
        if(x>=a[i]){
            x = x-a[i];
        }else{
            break;
        }
    }
    //printf("%d %d\n", i, x);
    if(i==N){
        if(x>0){
            i=N-1;
        }else{
            i=N;
        }
    }else{
        i=i;
    }

    printf("%d", i);

    return 0;
}

Measured memory_bytes: 128