akhauriyash/Code-Regression huggingface dataset:
n = int(input())
nmx = 200000
sml = 2*nmx
big = 4*nmx
pp = [[[] for _ in range(big+1)] for _ in range(8)]
mm = [[[] for _ in range(nmx+1)] for _ in range(4)]
for _ in range(n):
  x,y,d = input().split()
  x = int(x)
  y = int(y)
  if d == 'R':
    pp[0][+x+y].append(+y)
    pp[2][+x-y].append(-y)
    mm[0][y].append(x)
  if d == 'L':
    pp[4][-x+y].append(+y)
    pp[6][-x-y].append(-y)
    mm[1][y].append(x)
  if d == 'U':
    pp[1][+x+y].append(+x)
    pp[5][-x+y].append(-x)
    mm[2][x].append(y)
  if d == 'D':
    pp[3][+x-y].append(+x)
    pp[7][-x-y].append(-x)
    mm[3][x].append(y)
import bisect
inf = 10**10
ans = inf
def ser(lx,ly,su):
  global ans
  lly = len(ly)
  for xx in lx:
    b = bisect.bisect_left(ly,su-xx)
    if b != lly:
      ans = min(ans,(xx+ly[b]-su)*10)
    else:
      pass
for d in range(4):
  xd = 2*d
  yd = 2*d+1
  for sun in range(-sml,sml+1):
    if pp[xd][sun] and pp[yd][sun]:
      pp[xd][sun].sort()
      pp[yd][sun].sort()
      #print(pp[xd][sun],pp[yd][sun],sun,xd,yd)
      ser(pp[xd][sun],pp[yd][sun],sun)
for sun in range(0,nmx+1):
  if mm[0][sun] and mm[1][sun]:
    llm = len(mm[1][sun])
    mm[0][sun].sort()
    mm[1][sun].sort()
    for xx in mm[0][sun]:
      b = bisect.bisect_left(mm[1][sun],xx)
      if b != llm:
        ans = min(ans,(mm[1][sun][b]-xx)*5)
      else:
        pass
for sun in range(0,nmx+1):
  if mm[2][sun] and mm[3][sun]:
    llm = len(mm[3][sun])
    mm[2][sun].sort()
    mm[3][sun].sort()
    for yy in mm[2][sun]:
      b = bisect.bisect_left(mm[3][sun],yy)
      if b != llm:
        ans = min(ans,(mm[3][sun][b]-yy)*5)
      else:
        pass
#print(ans)
if ans == inf:
  print('SAFE')
else:
  print(ans)

Measured memory_bytes: 381124
#include <stdio.h>
#include <math.h>
#define N 10000

int main(){
  int count=0,a,i,j;
  int array[N];

  scanf("%d",&a);

  for(i=0; i<a; i++) scanf("%d",&array[i]);

  for(i=0; i<a; i++){
    for(j=2; j<=sqrt((double) array[i]); j++){
      if(array[i]%j == 0){
	count ++;
	break;
      }
    }
  }

  printf("%d\n",a-count);
  return 0;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
using namespace std;
string A,B;
int n,Ab,Bb;

int Bit(int bit ,int i,int x){
  while((bit>>i&1)!=x)bit ^= 1<<i;
  return bit;
}

int mem[16][1<<16],used[16][1<<16];
int dep = 0;
int dfs(short pos,int bit){
  cout<<  dep++ <<endl;
  if(bit ==Bb) return 0;
  if(used[pos][bit]++) return mem[pos][bit];
  
  int &res = mem[pos][bit] = 1e9;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++){
      int nbit = bit;
      nbit = Bit(nbit,i,bit>>j&1);
      nbit = Bit(nbit,j,bit>>i&1);
      res = min(res,abs(pos-i)+abs(i-j)+dfs(j,nbit));
    }
  cout<<dep<<endl;
  return mem[pos][bit];
}


typedef pair<int,int> P;
typedef pair<int,P> PP;
int bfs(){
  for(int j=0;j<16;j++) 
    for(int i=0;i<(1<<16);i++)mem[j][i] = 1e9;
  
  priority_queue<PP,vector<PP>,greater<PP> > Q;
  for(int i=0;i<n;i++) Q.push(PP(0,P(i,Ab))),mem[i][Ab] = 0;
  while(!Q.empty()){
    PP t = Q.top();Q.pop();
    int cost = t.first;
    int pos = t.second.first;
    int bit = t.second.second;
    if(bit == Bb) return cost;
    if(mem[pos][bit]<cost)continue;
    
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++){
	int nbit = bit;
	nbit = Bit(nbit,i,bit>>j&1);
	nbit = Bit(nbit,j,bit>>i&1);
	int ncost = cost+abs(pos-i)+abs(i-j);
	if(ncost >= mem[j][nbit])continue;
	Q.push(PP(ncost,P(j,nbit)));
	mem[j][nbit] = ncost;
      }
  }
  assert(0);  
}


int main(){
 
  while(cin>>n,n){
    cin>>A>>B;
    
    Ab = Bb = 0;
    for(int i=0;i<n;i++)Ab|=(A[i]=='W')<<i, Bb|=(B[i]=='W')<<i;
    
    memset(used,0,sizeof(used));
    int ans = 1e9;
    //for(int i=0;i<n;i++) ans=min(ans,dfs(i,Ab));
    //cout<<ans<<endl;
    cout<<bfs()<<endl;
  }
  return 0;
}

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

#define MAX(x,y)	((x)>(y)?(x):(y))
#define MIN(x,y)	((x)<(y)?(x):(y))
#define MAX3(x,y,z)	((x)>(MAX(y,z)) ? (x):(MAX(y,z)))
#define MIN3(x,y,z)	((x)<(MIN(y,z)) ? (x):(MIN(y,z)))
#define ABS(x)		((x)<0 ? -(x):(x))
#define M0(x)       memset(x, 0x00, sizeof(x))

typedef long long ll;

int main(){
    ll n,x,y,cnt=0;
    long double d;
    scanf("%lld%Lf", &n, &d);
    for(int i=0; i<n; i++){
        
        scanf("%lld%lld", &x, &y);
        if( sqrt(pow(x,2)+pow(y,2)) <= d ){
            cnt++;
        }
    }
    printf("%lld\n",cnt);
    return 0;
}

Measured memory_bytes: 2220
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
ll sz=55;  
ll ret=0;
vector<ll>a(sz),b(sz),c(sz),d(sz);
void dfs(ll n,ll m,ll len,vector<ll>&v,ll now,vector<vector<ll>>&g){
  if(len>0){
    for(auto z:g[len-1]){
      if(v[a[z]]+c[z]==v[b[z]])now+=d[z];
    }
  }
  if(len==n)chmax(ret,now);
  else{
    ll st=1;
    if(len>0)st=v[len-1];
    rep(i,st,m+1){
      v.PB(i);
      dfs(n,m,len+1,v,now,g);
      v.pop_back();
    }
  }
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,m,q;cin>>n>>m>>q;
  rep(i,0,q)cin>>a[i]>>b[i]>>c[i]>>d[i];
  vector<vector<ll>>g(n);
  rep(i,0,q){
    a[i]--;b[i]--;
    g[b[i]].PB(i);
  }
  vector<ll>v;
  dfs(n,m,0,v,0,g);
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 3668
#include<cmath>
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
using namespace std;
using ll = long long;

int main() {
    long long int x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    long long int plusmx = x/d;
    long long int y = min(plusmx,k);
    x = x - ( y * d);
    k -= min(plusmx,k);
    k = k % 2;
    if(k)
        cout << abs(d-x);
    else{
        cout << x;
    }
    // if(x >= (k*d)){
    //     cout << x - (k*d);
    // }
    // else if(x == d && d == k && k == x){
    //     cout << x << endl;
    // }
    // else if(abs(x-(k*d)) == k){
    // cout << abs((x-(k*d))) << endl;   
    // }
    // else
    // cout << abs((x-(k*d)) % k)<<endl;
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define int long long
#define puts(x) cout<<x<<endl
#define inf 243000000000000001
#define minf -243000000000000001
#define in(v) (v).begin(),(v).end()


signed main(){
    int n;
    cin>>n;
    int data[n][3];
    for(int i=0; i<n;i++){
        for(int j=0; j<3;j++){
            cin>>data[i][j];
        }
    }



    
    int ans [n][3];
    ans[0][0]=data[0][0];
    ans[0][1]=data[0][1];
    ans[0][2]=data[0][2];
    for(int j=0;j<3;j++){
        
    }
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            if(j==0){
                ans[i][j]=max(ans[i-1][1],ans[i-1][2])+data[i][j];
            }
            else if(j==1){
                ans[i][j]=max(ans[i-1][0],ans[i-1][2])+data[i][j];
            }
            else if(j==2){
                ans[i][j]=max(ans[i-1][1],ans[i-1][0])+data[i][j];
            }
          
        }
        
    }

    
    puts(max(max(ans[n-1][0],ans[n-1][1]),ans[n-1][2]));
}

Measured memory_bytes: 8324
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	int x, y;
	cin >> x >> y;
	for (int i = 2 * x; i <= 4 * x; i += 2) {
		if (i == y) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
}

Measured memory_bytes: 3652
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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



	int a, b;
	cin >> a >> b;
	a--;
	cout << (a + b) / 2 + 1 << endl;
	return 0;
}



Measured memory_bytes: 256
n = input()
m = input()
ln = len(n)
lm = len(m)
dp = [[0] * (lm+1) for _ in range(ln+1)]
for i in range(ln+1):
    dp[i][0] = i
for j in range(lm+1):
    dp[0][j] = j
for i in range(1,ln+1):
    for j in range(1,lm+1):
        if n[i-1] == m[j-1]:
            dp[i][j] = dp[i-1][j-1]
        else:
            dp[i][j] = min(dp[i][j-1]+1, dp[i-1][j]+1, dp[i-1][j-1]+1)
print(dp[-1][-1])


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

const int N=1e5+5;
typedef pair<int,int> pii;
int n,q,t,nt;
long long mn,mx,m;
vector<pii> pt[2];
int p1[N],p2[N],gp[N];

int fp1(int x){
	return (p1[x]==x)?x:(p1[x]=fp1(p1[x]));
}

void lnk1(int x,int y){
	x=fp1(x);y=fp1(y);
	p1[x]=y;
}

int fp2(int x){
	return (p2[x]==x)?x:(p2[x]=fp2(p2[x]));
}

void lnk2(int x,int y){
	x=fp2(x);y=fp2(y);
	p2[x]=y;
}

int main(){
	scanf("%d%I64d%d",&n,&m,&q);
	for(int i=1;i<=q;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		a++;b++;
		pt[c].push_back(make_pair(a,b));
	}
	for(int i=1;i<=n;i++) p1[i]=i;
	for(int i=0;i<pt[0].size();i++) lnk1(pt[0][i].first,pt[0][i].second);
	for(int i=1;i<=n;i++) if(fp1(i)==i) t++;
	mn=mx=n-t;
	mx+=1ll*t*(t-1)/2;
	for(int i=1;i<=n;i++) p2[i]=i;
	for(int i=0;i<pt[1].size();i++){
		int x=pt[1][i].first;
		int y=pt[1][i].second;
		if(p1[x]==p1[y]){
			puts("No");
			return 0;
		}
		lnk2(p1[x],p1[y]);
	}
	for(int i=1;i<=n;i++){
		if(fp1(i)==i&&fp2(i)==i) nt++;
		gp[p2[i]]++;
	}
	for(int i=1;i<=n;i++) if(gp[i]>1) mn+=gp[i];
	mn+=nt-1;
//	printf("%lld %lld\n",mn,mx);
	if(mn<=m&&m<=mx) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 5420
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005

ll N;
ll A[NUM],B[NUM],C[NUM];
ll rui_B[NUM];

int main(){

	scanf("%lld",&N);

	for(int i = 0; i < N; i++){

		scanf("%lld",&A[i]);
	}

	for(int i = 0; i < N; i++){

		scanf("%lld",&B[i]);
	}

	for(int i = 0; i < N; i++){

		scanf("%lld",&C[i]);
	}

	sort(A,A+N);
	sort(B,B+N);
	sort(C,C+N);

	for(int i = 0; i <= N; i++){

		rui_B[i] = 0;
	}

	//Bより多いCの数を数える
	int index = N-1;

	for(int loc = N-1; loc >= 0; loc--){

		while(index >= 0 && C[index] > B[loc])index--;

		rui_B[loc] = N-(index+1);
		rui_B[loc] += rui_B[loc+1];
	}

	ll ans = 0;

	index = N-1;

	for(int loc = N-1; loc >= 0; loc--){

		while(index >= 0 && B[index] > A[loc])index--;

		ans += rui_B[index+1];
	}

	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 3456
<?php
$n = trim(fgets(STDIN));
$nyukyo = array_fill(0, 4, array_fill(0, 3, array_fill(0, 10, 0)));

for ($i = 0; $i < $n; $i++) {
  $line = trim(fgets(STDIN));
  $arr = explode(" ", $line);

  $nyukyo[$arr[0]-1][$arr[1]-1][$arr[2]-1] += $arr[3];
}

for ($i = 0; $i < 4; $i++) {
  for ($j = 0; $j < 3; $j++) {
    echo " " . implode(" ", $nyukyo[$i][$j]) . "\n";
  }

  if ($i < 4-1) echo str_repeat("#", 20) . "\n";
}

Measured memory_bytes: 15528
//  Created by liszt on 2019/07/28.
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,i; cin>>n;
    vector<long long> a(n);
    for(i=0;i<n;i++)cin>>a[i];
    
    if(n%2==1){
        for(i=n-1;i>=0;i-=2)cout<<a[i]<<" ";
        for(i=1;i<n-1;i+=2)cout<<a[i]<<" ";
    }else{
        for(i=n-1;i>=1;i-=2)cout<<a[i]<<" ";
        for(i=0;i<n-1;i+=2)cout<<a[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
namespace modular_space {
	long long mod;
	struct umod {
		long long val;
		umod(): val(0ll){}
		umod(long long x){ x %= mod; if(x < 0) x += mod; val = x; }
		umod& operator += (umod oth){ val += oth.val; if(val >= mod) val -= mod; return *this; }
		umod& operator -= (umod oth){ val -= oth.val; if(val < 0) val += mod; return *this; }
		umod& operator *= (umod oth){ val = val * oth.val % mod; return *this; }
		umod& operator /= (umod oth){ return *this *= oth.inverse(); }
		umod& operator ^= (long long oth){ return *this = pwr(*this, oth); }
		umod operator + (umod oth) const { return umod(*this) += oth; }
	       	umod operator - (umod oth) const { return umod(*this) -= oth; }
		umod operator * (umod oth) const { return umod(*this) *= oth; }
		umod operator / (umod oth) const { return umod(*this) /= oth; }
		umod operator ^ (long long oth) const { return umod(*this) ^= oth; }
		bool operator < (umod oth) const { return val < oth.val; }
		bool operator > (umod oth) const { return val > oth.val; }
		bool operator <= (umod oth) const { return val <= oth.val; }
		bool operator >= (umod oth) const { return val >= oth.val; }
		bool operator == (umod oth) const { return val == oth.val; }
		bool operator != (umod oth) const { return val != oth.val; }
		umod pwr(umod a, long long b) const {
			umod r = 1;
			for(; b; a *= a, b >>= 1)
				if(b&1)
					r *= a;
			return r;
		}
		umod inverse() const {
			long long a = val, b = mod, u = 1, v = 0;
			while(b){
				long long t = a/b;
				a -= t * b; swap(a, b);
				u -= t * v; swap(u, v);
			}
			if(u < 0)
				u += mod;
			return u;
		}
		friend istream& operator >> (istream &is, umod &oth);
		friend ostream& operator << (ostream &os, const umod& oth);
	};
	ostream& operator << (ostream &os, const umod &oth){
		os << oth.val;
		return os;
	}
	istream& operator >> (istream &is, umod &oth){
		long long x; is >> x;
		oth = umod(x);
		return is;
	}
	struct binprime_kit {
		int sz;
		vector<umod> fat, ifat;
		void init(int s){
			sz = s;
			fat.resize(sz + 1);
			ifat.resize(sz + 1);
			fat[0] = 1;
			for(int i = 1; i <= sz; i++) fat[i] = fat[i - 1] * i;
			ifat[sz] = fat[sz] ^ (mod - 2);
			for(int i = sz - 1; i >= 0; i--) ifat[i] = ifat[i + 1] * (i + 1);
		}
		umod coef(int n, int r){
			if(n < r) return 0;
			return fat[n] / (ifat[r] * ifat[n - r]);
		}
	};
};
int main(){
	long long p; cin >> p;
	modular_space::mod = p;
	vector<modular_space::umod> ans(p, 0), now(p, 0), pwr(p, 0);
	modular_space::binprime_kit kit;
	kit.init(p - 1);
	for(int i = 0; i < p; i++){
		int x; cin >> x;
		if(x){
			if(i == 0){
				for(int j = 0; j < p; j++) now[j] = 0;
				now[p - 1] -= 1;
				now[0] += 1;
				for(int j = 0; j < p; j++) ans[j] += now[j];
				continue;
			}
			pwr[0] = 1;
			for(int j = 1; j < p; j++)
				pwr[j] = pwr[j - 1] * i;
			for(int j = 0; j < p; j++){
				now[j] = kit.coef(p - 1, j);
				if(j % 2 == 0) now[j] *= -1;
				now[j] *= pwr[p - 1 -j];
			}
			now[0] += 1;
			for(int j = 0; j < p; j++) ans[j] += now[j];
		}
	}
	for(int j = 0; j < p; j++) cout << ans[j] << " "; cout << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <math.h>
#include <string.h>
#include <iostream>
typedef long long ll;
using namespace std;
#define maxn 200005
ll a[20000005],b[5000005];
int main()
{
    ll n,k,mau=0,mad=0,mal=0,mar=0,d=0,l=0,r=0,u=0,m=0,i,j,ans=0,t;
    scanf("%lld %lld",&k,&n);
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
    }
    for(i=2;i<=n;i++)
    {
       b[i]=a[i]-a[i-1];
    }
    b[n+1]=a[1]+k-a[n];
     for(i=2;i<=n+1;i++)
    {
       // printf("*%lld\n",b[i]);
        ans+=b[i];
    }
    sort(b+1,b+n+2);
    ans-=b[n+1];
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3840
// Vivek Rai
// Blazer_007

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

#define fastio    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl      '\n'

typedef long long int ll;
const int hell = 1e9 + 7 ;

signed main() {

    fastio

    int n;
    cin >> n;
    set<string> s;
    while(n--)
    {
    	string str;
    	cin >> str;
    	s.insert(str);
    }
    cout << s.size() << endl;

    return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

#define ll          long long
#define fio         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define vi          vector<ll>
#define pp          push_pop
#define pll         pair<ll,ll>
#define in          insert
#define ini(a,n)    memset(a,n,sizeof(a))
#define ff          first
#define ss          second
#define inf         10000000000000000
#define all(p)      p.begin(), p.end()
#define que_max     priority_queue <int>
#define que_min     priority_queue <int, vi, greater<int>>
#define print(a)    for(auto i:a){cout<<i<<" ";}
#define print1(a)   for(auto i:a){cout<<i.ff<<" "<<i.ss<<endl;}
#define run_time cout << "\nTIME = " << clock() - tt << endl; tt = clock();

typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> Set;
unordered_map<ll,vi> g;
unordered_map<ll,ll> vis;
ll tt;
const ll mod = 1e9+7;

ll power(ll x,ll y,ll p){ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;}
const ll N = 2e5+10;
ll dx[4]={-1, +1, 0, 0};
ll dy[4]={0, 0, +1, -1};
bool imp = false;



void solve() {

    string s,t;cin>>s>>t;
    ll ans = 0;
    for(ll i=0;i<s.size();i++){
        if(s[i] != t[i])
            ans ++;
    }
    cout<<ans<<endl;


}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    fio
    int t=1;
    if(imp) cin>>t;
    tt = clock();
    while(t--)
    {
        // cout<<"Case #"<<tc<<": ";
        g.clear();
        vis.clear();
        solve();
        // tc++;
    }
//    run_time;

}


Measured memory_bytes: 3864
#include<bitset>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;

/* AOJ 1100 */

const int N = 55;

int n, cnt = 0;
double ans;
struct Point {
	int x, y;
	void read(void) {
		scanf("%d%d", &x, &y);
	}
	friend int operator - (Point b, Point a) {
		return a.x*b.y - b.x*a.y;
	}
}P[N];

signed main(void) {

	while (scanf("%d", &n), n) {
		ans = 0;
		for (int i = 0; i < n; i++)
			P[i].read();
		for (int i = 0; i < n; i++)
			ans += (double)(P[i] - P[(i + 1) % n]);
		ans /= 2;
		printf("%d %.1lf\n", ++cnt, ans);
	}

}

Measured memory_bytes: 1220
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 200000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

int a[N];
int bucket[N];
bool cmp(int a,int b){
    return a>b;
}
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        bucket[a[i]]++;
    }

    int cnt=0;
    for(int i=1;i<=n;i++){
        if(bucket[i]!=0){
            a[++cnt]=bucket[i];
        }
    }
    sort(a+1,a+1+cnt,cmp);
    int res=0;
    for(int i=k+1;i<=cnt;i++)
        res+=a[i];
    printf("%d\n",res);

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX_N 100000

int n, m;
vector<int> G[MAX_N];

ll dp[MAX_N];
vector<ll> ans(MAX_N, 1);

ll dfs(int v, int pre) {
    ll res = 1;
    for (auto to : G[v]) {
        if (to == pre) continue;
        res *= dfs(to, v) + 1;
        res %= m;
    }
    return dp[v] = res;
}

void ddfs(int v, int pre) {
    for (auto to : G[v]) {
        ans[v] *= dp[to] + 1;
        ans[v] %= m;
    }
    int k = G[v].size();
    vector<ll> left(k + 2, 1);
    vector<ll> right(k + 2, 1);
    for (int i = 0; i < k; i++) {
        left[i + 1] = left[i] * (dp[G[v][i]] + 1);
        left[i + 1] %= m;
    }
    for (int i = k; i > 0; i--) {
        right[i] = right[i + 1] * (dp[G[v][i - 1]] + 1);
        right[i] %= m;
    }
    for (int i = 0; i < k; i++) {
        int to = G[v][i];
        if (to == pre) continue;
        dp[v] = left[i] * right[i + 2];
        dp[v] %= m;
        ddfs(to, v);
    }
}

signed main() {
    cin >> n >> m;
    int x, y;
    rep(i, n - 1) {
        cin >> x >> y;
        x--;
        y--;
        G[x].emplace_back(y);
        G[y].emplace_back(x);
    }
    dfs(0, -1);
    ddfs(0, -1);
    rep(v, n) {
        cout << ans[v] << endl;
    }
    return 0;
}

Measured memory_bytes: 21760
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
INF = float("inf")

N,M,R = map(int,input().split())
r = list(map(int,input().split()))
adj_cost = defaultdict(set)

for i in range(M):
    a, b, c = map(int, input().split())
    adj_cost[a-1].add((b-1, c))
    adj_cost[b-1].add((a-1, c))

def dijkstra(v):
    d = [INF] * N
    d[v] = 0
    hq =[(0,v)]

    while hq:
        u = heapq.heappop(hq)[1]
        for (v,c) in adj_cost[u]:
            if d[v] > d[u] + c:
                d[v] = d[u] +c
                heapq.heappush(hq,(d[u]+c,v))
    return d

ans = INF
table = {}
for i in r:
    table[i-1] = dijkstra(i-1)

for each in permutations(r):
    dis = 0
    for i in range(R-1):
        dis += table[each[i]-1][each[i+1]-1]

    ans = min(ans,dis)
print(ans)

Measured memory_bytes: 8400
#include <bits/stdc++.h>
using ll = long long;
const ll MOD = 1000000007;
#define rep(i,n) for (ll i=0; i < (n); i++)
using namespace std;
int get_gcd(int a, int b) {
  while(1) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    a %= b;
  }
}
int get_lcm(int a, int b){return a * b / get_gcd(a, b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main () {
  int n;
  scanf("%d", &n);

  struct Job {
    int a;
    int b;
  };
  vector<Job> jobs(n);
  rep(i,n) scanf("%d %d", &jobs[i].a, &jobs[i].b);

  // 締め切りが近い仕事ほど優先すべきなので、その順にソート
  sort(jobs.begin(), jobs.end(), [](const Job& a, const Job& b){return a.b < b.b;});

  // 締め切りが近い順から間に合うかを計算する
  int t = 0;
  rep(i,n) {
    t += jobs[i].a;
    if (t > jobs[i].b) {
      printf("No\n");
      return 0;
    }
  }

  printf("Yes\n");
  return 0;
}


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

template <typename InputIterator>
typename InputIterator::value_type
summation(InputIterator first, InputIterator last) {
  using T = typename InputIterator::value_type;
  T *p = new T();
  const auto sum = std::accumulate(first, last, *p);
  delete p;
  return sum;
}
template <typename T>
std::istream& operator>> (std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream& operator>> (std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream& operator>> (std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream& operator>> (std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  int64_t i = 1;
  for (int64_t j = 1; j <= n; j++) {
    i *= j;
    i %= 1000000007;
  }
  std::cout << i << std::endl;
  return 0;
}

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

int main()
{
  string s;
  cin >> s;
  if (s == "Sunny")
    cout << "Cloudy" << endl;
  else if (s == "Cloudy")
    cout << "Rainy" << endl;
  else
    cout << "Sunny" << endl;
  return 0;
}


Measured memory_bytes: 256
import bisect
a,b,q = map(int,input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]
for i in range(q):
    x = int(input())
    index1 = bisect.bisect(s,x)
    index2 = bisect.bisect(t,x)
    cands = []
    if index1 != 0:
        sl = x-s[index1-1]
    if index1 != a:
        sr = s[index1]-x
    if index2 != 0:
        tl = x-t[index2-1]
    if index2 != b:
        tr = t[index2]-x
    if index1 != 0:
        if index2 != 0:
            cands.append(max(sl,tl))
        if index2 != b:
            cands.append(sl*2+tr)
            cands.append(tr*2+sl)
    if index1 != a:
        if index2 != 0:
            cands.append(sr*2+tl)
            cands.append(sr+tl*2)
        if index2 != b:
            cands.append(max(sr,tr))
    print(min(cands))

Measured memory_bytes: 12088
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin >> s;
	int c = 0;
	if(s[0] == 'R'){
		if(s[1] == 'R' && s[2] == 'R'){
			c = 3;
		}
		else if (s[1] == 'R' && s[2] != 'R'){
			c = 2;
		}
		else{
			c = 1;
		}

	}
	else if(s[1] == 'R'){
		if(s[2] == 'R'){
			c = 2;
		}
		else{
			c = 1;
		}
	}
	else if(s[2] == 'R'){
		c = 1;
	}
	cout << c;
}


Measured memory_bytes: 3536
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, N = MAP()
A = LIST()

print("Yes" if sum(A) >= H else "No")

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

void main_()
{
    string S, T;
    cin >> S >> T;

    auto ans = "No";

    for (size_t i = 0; i < T.size(); i++) {
        if (T == S) {
            ans = "Yes";
            break;
        }
        rotate(begin(S), begin(S) + 1, end(S));
    }

    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  string S;
  cin >> S;
  int ans0 = 0;
  int ans1 = 0;
  REP(i, S.size()) {
    ans0 += (S[i] - '0') ^ (i % 2 == 0);
    ans1 += (S[i] - '0') ^ (i % 2 == 1);
  }
  cout << min(ans0, ans1) << endl;
}



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

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if ((100 * x + a * 10 + b) % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np
from collections import Counter
mo = 1000000007
r = range

n = int(input())
a = np.array(list(map(int, input().split())))

c = Counter(a.tolist())

if n % 2 == 1 and (0 not in c or c[0] != 1): print(0); exit();

for i in r(n//2):
    x = i * 2 + (1 if n % 2 == 0 else 2)
    if x not in c or c[x] != 2: print(0); exit();

print(2 ** (n//2) % mo)


Measured memory_bytes: 23392
using System;
using System.Linq;

public class AtCoder
{
  public static void Main()
  {
    var input = Console.ReadLine().Trim().Split().Select(x => int.Parse(x)).ToArray();
    var a = input[0];
    var b = input[1];
    var c = input[2];
    var d = input[3];

    var s =  a > c ? a : c;
    var e =  b < d ? b : d;
    var diff = (e-s);

    var ans = diff >= 0 ? diff : 0;
    Console.WriteLine(ans);
  }
}

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

#define cnd(c, a, b) (c ? a : b);
#define fl(x,y,z) for(int x=y;x<z;x++)
#define fe(x,y,z) for(int x=y;x<=z;x++)
#define fge(x,y,z) for(int x=y;x>=z;x--)

#define debug(x) std::cerr << #x << " --> " << x << "\n";
#define fastIO std::ios_base::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
#define pb push_back
#define pob pop_back
 
#define ln '\n'
typedef long long int ll;

ll mod=1e9+7;

void decrypt() {
	ll n, a, b;
	ll flag, cnt, tp;
	vector<pair<ll, ll> >  vec;
	cin>>n;
	fl(i,0,n) {
		cin>>a>>b;
		vec.pb(make_pair(a,b));
	}
	tp = 0;
	cnt = 0;
	flag = 0;
	fl(i,0,n) {
		if(tp==1) {
			if(vec[i].first == vec[i].second) {
				cnt++;
				if(cnt==3) {
					flag = 1;
					break;
				}
			} else {
				tp = 0;
				cnt = 0;
			}
		} else {
			if(vec[i].first == vec[i].second) {
				cnt = 1;
				tp = 1;
			}
		}
	}
	if(flag==1) {
		cout<<"Yes"<<ln;
	}
	 else {
	 	cout<<"No"<<ln;
	 }
	 return;
}

int main() {
    fastIO
    int t = 1;
    // cin >> t;
    fl(i,0,t) {
    	// cout << "Case #"<< i+1 <<": ";
    	decrypt();
    }
    return 0;
}

Measured memory_bytes: 3652
<?php
fscanf(STDIN, '%d', $n);
$v = array_map('intval', explode(' ', trim(fgets(STDIN))));
$q = new SplPriorityQueue();
for($i = 0; $i < $n; $i++) {
    $q->insert($v[$i], -$v[$i]);
}
while ($q->count() > 1) {
    $x = $q->extract();
    $y = $q->extract();
    $z = ($x + $y) / 2;
    $q->insert($z, -$z);
}
$ans = $q->extract();
echo $ans . PHP_EOL;

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define sz(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()

ll mygcd (ll x, ll y)
{
    ll ans = 0;
    while (x && y)
    {
        if (x < y)
            swap(x, y);

        ll times = (x / y);

        if (x == y * times)
            ans += (times - 1) * 2 * y + y;
        else
            ans += times * 2 * y;
        x -= y * times;

    }
    return ans;
}

void solve (ll n)
{
    ll x;
    cin >> x;
    ll ans = n + mygcd(x, n - x);
    cout << ans << endl;
}

int main()
{
    #ifndef ONLINE_JUDGE
 //   freopen("input.txt", "rt", stdin);
 //   freopen("output.txt", "w", stdout);
    #endif

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

    ll n;
    while (cin >> n)
        solve(n);
}


Measured memory_bytes: 256
import sys
S = input()
T = "AKIHABARA"
posS = 0
posT = 0
while True:
    if posS == len(S):
        if posT >= len(T)-1:
            print("YES")
        else:
            print("NO")
        sys.exit()
    if posT >= len(T):
        print("NO")
        sys.exit()
    if S[posS] == T[posT]:
        posS += 1
        posT += 1
    elif T[posT] == 'A':
        posT += 1
    else:
        print("NO")
        sys.exit()

Measured memory_bytes: 3188
// C - 次のアルファベット

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	int K;
	cin >> K;

	string t = "";

	for (int i=0; i<s.size(); i++) {
		if (K == 0) {
			t.push_back(s[i]);
		} else if (i == s.size()-1) {
			int c = s[i] - 'a';
			t.push_back((char)(((c + K) % 26) + 'a'));
		} else {
			int c = s[i] - 'a';
			if (c > 0 && c + K >= 26) {
				t.push_back('a');
				K -= 26 - c;
			} else {
				t.push_back(s[i]);
			}
		}
	}

	cout << t << endl;

	return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
using P = pair<ll, ll>;

const long long MOD = 1000000007;

ll dp[110][64] = {};
string S = "ACGT";
void solve(long long N){
    loop (64, i) {
        string s = S.substr((i / 16) % 4, 1) + S.substr((i / 4) % 4, 1) + S.substr(i % 4, 1);
        if (s != "AGC" && s != "GAC" && s != "ACG") {
            dp[3][i] = 1;
        }
    }

    loop (105, i) {
        if (i < 3) continue;
        loop (64, j) {
            int base = (j * 4) % 64;
            string s = S.substr((j / 16) % 4, 1) + S.substr((j / 4) % 4, 1) + S.substr(j % 4, 1);
            string l2 = s.substr(1, 2);
            // +A
            dp[i + 1][base] += dp[i][j];
            dp[i + 1][base] %= MOD;
            // +C
            if (l2 != "AG" && l2 != "GA" && s != "ATG" && s != "AGG" && s != "AGT") {
                dp[i + 1][base + 1] += dp[i][j];
                dp[i + 1][base + 1] %= MOD;
            } 
            // +G
            if (l2 != "AC") {
                dp[i + 1][base + 2] += dp[i][j];
                dp[i + 1][base + 2] %= MOD;
            }
            // +T
            dp[i + 1][base + 3] += dp[i][j];
            dp[i + 1][base + 4] %= MOD;
        }
    }

    ll ans = 0;
    loop (64, i) ans = (ans + dp[N][i]) % MOD;
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while (!"-1".equals((line = br.readLine()))) {
			double q = Double.parseDouble(line);
			double xn = q / 2.0;
			double checkVal = xn * xn * xn - q;
			while (Math.abs(checkVal) >= 0.00001 * q) {
				xn = xn - (checkVal) / (xn * xn * 3.0);
				checkVal = xn * xn * xn - q;
			}
			System.out.printf("%f", xn);
			System.out.println();

		}
	}
}

Measured memory_bytes: 16972
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
using namespace std;
typedef unsigned int ll;
ll n,k;
ll a[200005];
ll suan(ll m)
{
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		ans+=a[i]/m;
		if(a[i]%m==0) ans--;
		if(ans>k) return ans;
	}
	return ans;
}
ll fen(ll l,ll r)
{
	if(l==r) return l;
	ll m=(l+r)/(ll)2;
	ll cal=suan(m);
	if(cal>k)
    {
      return fen(m+1,r);
    }
	else return fen(l,m);
}
int main(void)
{
	scanf("%d%d",&n,&k);
	for(ll i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	printf("%d",fen((ll)1,(ll)1000000000));
}

Measured memory_bytes: 4604
# import functools
N = int(input())

#for i in range(N+1):
# @functools.lru_cache()
# def L(i):
#     if i == 0:
#         return 2
#     if i == 1:
#         return 1
#     else:
#         return L(i-1) + L(i-2)
# print(L(N))


#上はfunctoolを使うもの下がいい

LL = [2,1] # リュカ数保存するリスト

for i in range(2,N+1):
    LL.append(LL[i-1] + LL[i-2])

print(LL[N])




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

int main() {
	int n;
	float x1, y1, x2, y2, x3, y3, x4, y4;
	cin >> n;
	while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4) {
		if (((y2 - y1) / (x2 - x1)) == ((y4 - y3) / (x4 - x3))) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 3152
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        int A = sc.nextInt();
        int B = sc.nextInt();
        String U = sc.next();

        if(U.equals(S)){
            System.out.println((A-1) + " " + B);
        }else if(U.equals(T)){
            System.out.println(A + " " + (B-1));
        }

    }
}


Measured memory_bytes: 21716
from collections import deque

n,m=map(int,input().split())

graph=[[] for i in range(n)]

roomSign=[-1]*n

for i in range(m):
    a,b=map(int,input().split())
    a-=1;b-=1
    graph[a].append(b)
    graph[b].append(a)

D=deque([0])

while D:
    v=D.popleft()
    for i in graph[v]:
        if roomSign[i] == -1:
          roomSign[i]=v
          D.append(i)

print("Yes")

for i in range(1,n):
    print(roomSign[i]+1)

Measured memory_bytes: 34312
#include <stdio.h>
#include <vector>

using namespace std;

long long bit[200002];

long long max(long long x, long long y) {
    return x > y ? x : y;
}

void update(int k, long long v) {
    for (int i = k + 1; i <= 200001; i += i & -i) {
        bit[i] = max(bit[i], v);
    }
}

long long query(int k) {
    long long res = 0;
    for (int i = k; i > 0; i -= i & -i) {
        res = max(res, bit[i]);
    }
    return res;
}

int N;
int H[200000], A[200000];;
long long dp[200001];

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &H[i]);
    }
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    for (int i = 0; i <= 200000; i++) {
        dp[i] = -2e18;
    }
    for (int i = 0; i <= 200001; i++) {
        bit[i] = -2e18;
    }
    dp[0] = 0;
    update(0, 0);
    for (int i = 0; i < N; i++) {
        dp[H[i]] = max(dp[H[i]], query(H[i]) + A[i]);
        update(H[i], dp[H[i]]);
    }
    printf("%lld\n", query(N + 1));
    return 0;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

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

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

    vector<string> T(2);
    int cnt = 0;
    rep(i, q) {
        int t;
        cin >> t;
        if(t == 1) {
            cnt++;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if(f == 1) {
                if(cnt % 2 == 0) {
                    T[0].push_back(c);
                } else {
                    T[1].push_back(c);
                }
            } else {
                if(cnt % 2 == 0) {
                    T[1].push_back(c);
                } else {
                    T[0].push_back(c);
                }
            }
        }
    }

    string ans;
    if(cnt % 2 == 0) {
        reverse(ALL(T[0]));
        ans = T[0] + s + T[1];
    } else {
        reverse(ALL(s));
        reverse(ALL(T[1]));
        ans = T[1] + s + T[0];
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1348
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);

int main() {
    ll A,B; cin >> A >> B;
    int K; cin >> K;
    REP(i,K) {
        if(i%2 == 0) {
            if(A%2 == 0) {
                B += A/2;
                A /= 2;
            } else {
                B += A/2;
                A--;
                A /= 2;
            }
        } else {
            if(B%2 == 0) {
                A += B/2;
                B /= 2;
            } else {
                A += B/2;
                B--;
                B /= 2;
            }
        }
    }
    cout << A << " " << B << endl;
}

Measured memory_bytes: 3588
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;

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

	int a, b;
	cin >> a >> b;

	int ans = 0;
	if ((b - 1) % (a - 1) == 0) {
		ans = (b - 1) / (a - 1);
	}
	else {
		ans = (b - 1) / (a - 1) + 1;
	}

	cout << ans << endl;

	return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int K[15];
int S[15][15];
int P[15];

int main()
{
    int N, M;
    cin >> N >> M;
    REP(i, M)
    {
        cin >> K[i];
        REP(j, K[i])
        {
            cin >> S[i][j];
            S[i][j]--;
        }
    }
    REP(i, M)
    {
        cin >> P[i];
    }

    ll ans = 0;
    REP(i, pow(2, N))
    {
        int m = 0;
        REP(j, M)
        {
            int t = 0;
            REP(k, K[j])
            {
                if (((i >> S[j][k]) & 1) == 1)
                    t++;
            }
            if (t % 2 == P[j])
                m++;
        }

        if (m == M)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#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 = 1000000007; // 10000000000000007ll;

const double eps = 1e-8;

const i64 MAXN = 3'000'000 + 6;

i64 T;
i64 n;
i64 a[MAXN];

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    string s;
    cin >> s;

    bool R = s[2] == s[3] && s[4] == s[5];

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


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int64_t X;
    cin >> X;
    int x;
    x = X / 500;
    X = X - 500 * x;
    int y;
    y = X / 5;
    cout << x * 1000 + y * 5 << endl;
}


Measured memory_bytes: 384
use std::io;

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

    io::stdin().read_line(&mut R).expect("aho");
    let R:i32 = R.trim().parse().unwrap();

    if R>=2800 {
        println!("AGC");
    }else if R>=1200 {
        println!("ARC");
    }else {
        println!("ABC");
    }
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
/*
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<ctime> 
*/
#define ll long long
using namespace std;
const int N=1e5 + 100;
const double eps=1e-10;
const ll M=26;
ll n;
char a[50];
int main(){
	scanf("%lld",&n);
	int op=0;
	while(n>0){
		op++;
		n-=1;
		a[op]=(n%M)+'a';
		n/=M;
	}
	for(int i=op;i>=1;i--) printf("%c",a[i]);
	return 0;
}

Measured memory_bytes: 3680
//https://atcoder.jp/contests/abc151/tasks/abc151_a
//A - Next Alphabet
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
    char C; cin>>C;
    ++C;
    cout<<C<<endl;    
    return 0;
}

Measured memory_bytes: 256