akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define PB push_back
#define MP make_pair

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    int n, q; cin >> n >> q;
    int psum[n];
    psum[0] = 0;
    string s; cin >> s;
    vector<pair<int, int>> Q;
    for (int i = 0; i < q; ++i) {
        int l, r; cin >> l >> r;
        l--, r--;
        Q.PB(MP(l, r));
    }
    char prev = s[0];
    for (int i = 1; i < n; ++i) {
        if (prev == 'A' && s[i] == 'C') psum[i] = psum[i - 1] + 1;
        else psum[i] = psum[i - 1];
        prev = s[i];
    }
    for (auto i : Q) {
        cout << psum[i.second] - psum[i.first] << "\n";
    }
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* print new lines
*/

Measured memory_bytes: 2244
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main(){
    int n;cin >> n;
    char in[120];
    pair<pair<string,int>,int> p[100];
    for(int i=0;i<n;i++){
        int t;cin >> in >> t;
        string tmp = in;
        p[i] = make_pair(make_pair(in, -t),i);
    }
    sort(p,p+n);
    for(int i=0;i<n;i++){
        cout << p[i].second+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
a = [int(i) for i in input().split()]
if a[0] > a[1]:
  pass
else:
  b = a[0]
  c = a[1]
  a[0] = c
  a[1] = b

b = a[0]
c = a[1]

import fractions

g = fractions.gcd(b,c)

print(int((b * c) / g))

Measured memory_bytes: 5044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#pragma GCC optimize("O2")
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define leastsigbit(x)     __builtin_ffs(x)
#define mod             1000000007
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<ll,ll>
#define vpii vector<pii>
#define tt ll tt;cin >> tt;while(tt--)
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n";}
const double PI = acos(-1);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm( ll x, ll y) { return (x*y)/gcd(x,y);}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
bool isPowerOfTwo(int x)
{
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));
}
const int MAXN = 2e5+ 10;
const ll inf = 1e18;

int intlog(double base, double x) {
    return (int)(log(x) / log(base));
}
string s,t;
int change(int i) {
    int cnt = sz(t);
    if(i+sz(t)-1 < sz(s)) {
        for (int j = 0;j <  sz(t); ++j) {
            if(s[j+i] == t[j])cnt--;

        }
    }

    return cnt;
}
int32_t main() {
    fio
    cin >> s >> t;
    int ans = sz(t);
    for (int i = 0; i < sz(s); ++i) {
            ans = min(ans,change(i));
    }
    cout << ans << endl;

    cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}




Measured memory_bytes: 3888
#include<string>
#include<vector>
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

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


int main(){

	int a,b;
	while(true){

	cin >> a >> b;
	if(a==0 && b==0) break;

	vector<int>v;

	v.push_back(0);
	v.push_back(31);
	v.push_back(29);
	v.push_back(31);
	v.push_back(30);
	v.push_back(31);
	v.push_back(30);
	v.push_back(31);
	v.push_back(31);
	v.push_back(30);
	v.push_back(31);
	v.push_back(30);
	v.push_back(31);

	int d=b;
	rep(i,a) d+=v[i];

	if(d%7==0) cout << "Wednesday" << endl;
	if(d%7==1) cout << "Thursday" << endl;
	if(d%7==2) cout << "Friday" << endl;
	if(d%7==3) cout << "Saturday" << endl;
	if(d%7==4) cout << "Sunday" << endl;
	if(d%7==5) cout << "Monday" << endl;
	if(d%7==6) cout << "Tuesday" << endl;

	}

	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
bool prime[200000];

int main(){

  for(int i=2;i*i<200000;i++)
    for(int j=2;j<200000/i&&!prime[i];j++) prime[i*j]=1;

  vector <int> n;
  for(int i=2;i<200000;i++)if(!prime[i])n.push_back(i);
					      
  int p,q;
  cin>>p>>q;
  int a=__gcd(p,q);
  p/=a,q/=a;
  
  int ans=1;
  for(int i=0;i<n.size();i++)
    if(q%n[i]==0){
      ans*=n[i];
      while(q%n[i]==0)q/=n[i];
    }
  ans*=q;

  cout << ans<<endl;

  return 0;

}

Measured memory_bytes: 1544
N, M = map(int, input().split(' '))

On = [True for i in range(N)]
K = [0 for j in range(M)]
S = []

for j in range(M):
  inp = list(map(int, input().split(' ')))
  K[j] = inp[0]
  S.append(inp[1:])
  
P = list(map(int, input().split(' ')))


def check_condition(On, K, S, P):
  for j in range(len(K)):
    on_sum = 0
    for k in range(K[j]):
      if On[S[j][k]-1]: on_sum += 1
    if on_sum%2 != P[j]:
      return False
  return True

def enum_patterns(On, index, K, S, P):
  off = On.copy()
  off[index] = False
  if index == len(On)-1:
    count = check_condition(On, K, S, P) + check_condition(off, K, S, P)
  else:
    count = enum_patterns(On, index+1, K, S, P) + enum_patterns(off, index+1, K, S, P)
  return count


print(enum_patterns(On, 0, K, S, P))

Measured memory_bytes: 9120
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#define N 2010
#define M 2000001
#define ls i << 1
#define rs i << 1 | 1
#define inf 0x3f3f3f3f
#define inc(i) (++ (i))
#define dec(i) (-- (i))
// #define mid ((l + r) >> 1)
#define int long long
#define XRZ 998244353
#define debug() puts("XRZ TXDY");
#define n_ ((n >> 1) + 1)
#define mem(i, x) memset(i, x, sizeof(i));
#define Next(i, u) for(register int i = head[u]; i ; i = e[i].nxt)
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout);
#define Rep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i <= i##Limit ; inc(i))
#define Dep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i >= i##Limit ; dec(i))
// const int dx[10] = {1, -1, 0, 0};
// const int dy[10] = {0, 0, 1, -1};
using namespace std;
inline int read() {
    register int x = 0, f = 1; register char c = getchar();
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
void work() {}
signed main(){
	int H, W;
	H = read(), W = read();
	int ans = H * W / 2;
	if(H * W % 2) ++ ans;
	if(H == 1 || W == 1){ printf("1"); return 0;}
	printf("%lld",ans);
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	map<int,int> m;
	for(int i=0;i<n;i++){
		cin >> a[i];
		m[a[i]]++;
	}
	long long sum=0;
	for(auto itr=m.begin();itr!=m.end();itr=next(itr,1)){
		long long t=itr->second;
		sum+=t*(t-1)/2;
	}
	
	for(int i=0;i<n;i++){
		long long t=m[a[i]]-1;
		cout << sum-t << endl;

	}
	return 0;
}


Measured memory_bytes: 9088
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll inf = 1 << 30;
const ll mod = 1000000000 + 7;

int main()
{
	int a, b, k;
	cin >> a >> b >> k;

	for (int i = b; i >= 1; i--)
	{
		if (a % i == 0 && b % i == 0)
		{
			k--;
			if (k == 0)
			{
				cout << i << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
n,k=map(int,input().split())
h,f,ans=0,k,0
o=[]
e=[]
if k%2==0:
  h=k//2
  for i in range(n//h):
    if i%2==0:
      o.append((i+1)*h)
l=len(o)
if l>2:
  ans+=l*(l-1)*(l-2)
if l>1:
  ans+=l*(l-1)*3
ans+=l
for i in range(1,n//f+1):
  e.append(i*f)
l=len(e)
if l>2:
  ans+=l*(l-1)*(l-2)
if l>1:
  ans+=l*(l-1)*3
ans+=l
print(ans)

Measured memory_bytes: 11032
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>

using namespace std;
typedef long long ll;

int main()
{
	int R;
	cin >> R;
	
	cout << R * 3.14159265 * 2 << endl;
	
	return 0;
}


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

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, k;
    string s;

    cin >> n >> k >> s;
    s[k - 1] += 32;

    cout << s << endl;
}

/**
*/


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()

    return (n+1) // 2


print(main())





Measured memory_bytes: 6212
a,b = gets.chomp.split().map(&:to_i)

def g(n,w); w==1 ? ((n+1)/2)%2 : [(n+1)%2**w - 2**(w-1), 0].max % 2; end

ans = ''
(1..40).each do |i|
  ans += (g(b,i) ^ (g(a-1,i))).to_s
end

puts ans.reverse.to_i(2)

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

int main(){
  while(1){
    int n,m;
    cin >> n >> m;

    if(n==0 && m==0)
      break;

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

    int max=-1;

    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        int p=a[i]+a[j];

        if(max<p && p<=m)
          max=p;
      }
    }

    if(max==-1){
      cout << "NONE" << endl;
    }else {
      cout << max << endl;
    }
  }

  return 0;
}



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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N, A, B;
    cin >> N >> A >> B;
    
    if(A % 2 == B % 2){
        cout << (B - A) / 2 << endl;
    }else{
        cout << min(A - 1, N - B) + 1 + (B - A - 1) / 2 << endl;
    }

}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn=200010,INF=0x3f3f3f3f;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    if(f) x=-x;
}
struct Edge{
	int u,v;ll w;
	Edge(const int _u=0,const int _v=0,const ll _w=0ll){u=_u;v=_v;w=_w;}
	bool operator < (const Edge &b)const{return w<b.w;}
};
struct data{int v,w,nxt;}edge[maxn<<1];
int n,p,sn,rt,top,a[maxn],head[maxn],sz[maxn],mx[maxn],vis[maxn],stk[maxn];
ll ans,sum[maxn];
vector<Edge> G;
vector<Edge>::iterator itr;
struct Dsu{
	int f[maxn];
	void init(int n){for(int i=1;i<=n;i++) f[i]=i;}
	int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
	int merge(int x,int y)
	{
		int fx=find(x),fy=find(y);
		if(fx==fy) return 0;
		return f[fy]=fx;
	}
}dsu;
void insert(int u,int v,int w)
{
	edge[++p]=(data){v,w,head[u]};head[u]=p;
	edge[++p]=(data){u,w,head[v]};head[v]=p;
}
void getrt(int x,int pre)
{
	sz[x]=1;mx[x]=0;
	for(int i=head[x];i;i=edge[i].nxt)
	  if(!vis[edge[i].v]&&edge[i].v^pre)
	  {
	  	getrt(edge[i].v,x);
	  	sz[x]+=sz[edge[i].v];
	  	getmax(mx[x],sz[edge[i].v]);
	  }
	getmax(mx[x],sn-sz[x]);
	if(mx[x]<mx[rt]) rt=x;
}
void input()
{
	int u,v,w;
	read(n);
	for(int i=1;i<=n;i++) read(a[i]);
	for(int i=1;i<n;i++){read(u);read(v);read(w);insert(u,v,w);}
	dsu.init(n);
	sn=n;mx[rt=0]=INF;getrt(1,1);
}
void getdis(int x,int pre)
{
	stk[++top]=x;sz[x]=1;
	for(int i=head[x];i;i=edge[i].nxt)
	  if(!vis[edge[i].v]&&edge[i].v^pre)
	  {
	  	sum[edge[i].v]=sum[x]+edge[i].w;
	  	getdis(edge[i].v,x);
	  	sz[x]+=sz[edge[i].v];
	  }
}
void dfs(int x)
{
	int id;ll mn=1e18;
	vis[x]=1;top=0;sum[x]=0ll;
	getdis(x,x);
	for(int i=1;i<=top;i++)
	  if(getmin(mn,a[stk[i]]+sum[stk[i]]))
	    id=stk[i];
	for(int i=1;i<=top;i++)
	  G.push_back(Edge(id,stk[i],a[stk[i]]+sum[stk[i]]+a[id]+sum[id]));
	for(int i=head[x];i;i=edge[i].nxt)
	  if(!vis[edge[i].v])
	  {
	  	sn=sz[edge[i].v];rt=0;
	  	getrt(edge[i].v,x);
	  	dfs(rt);
	  }
}
int main()
{
	input();
	dfs(rt);
	sort(G.begin(),G.end());
	for(itr=G.begin();itr!=G.end();++itr)
	  if(dsu.merge(itr->u,itr->v))
	    ans+=itr->w;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 88928
#include <bits/stdc++.h>
using namespace std;
#pragma optimize("-O3")
#define int long long int
#define f first
#define s second
#define pb push_back
#define endl '\n'
const int N=1e9;
main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	vector<int>x={-1, 0, 1};
	vector<int>y={-1, 0, 1};
	vector<int>xx={-2, -1, 0, 1, 2};
	vector<int>yy={-2, -1, 0, 1, 2};
	
	int h, w;
	cin>>h>>w;
	int x1, y1, x2, y2;
	cin>>x1>>y1>>x2>>y2;
	x1--;
	y1--;
	x2--;
	y2--;
	char arr[h][w];
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cin>>arr[i][j];
		}
	}
	int dis[h][w];
	bool pro[h][w];
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			dis[i][j]=N;
			pro[i][j]=0;
		}
	}
	set<pair<int, pair<int, int>>>se;
	se.insert({0, {x1, y1}});
	dis[x1][y1]=0;
	while(!se.empty()){
		auto it=se.begin();
		int nx=(*it).s.f;
		int ny=(*it).s.s;
		se.erase(it);
		if(pro[nx][ny]){
			continue;
		}
		pro[nx][ny]=1;
		for(auto ux:x){
			for(auto uy:y){
				if(ux*uy!=0){
					continue;
				}
				if(ux==0 && uy==0){
					continue;
				}
				if(nx+ux>=h || nx+ux<0 || ny+uy<0 || ny+uy>=w){
					continue;
				}
				if(arr[nx+ux][ny+uy]=='#'){
					continue;
				}
				if(dis[nx][ny]<dis[nx+ux][ny+uy]){
					dis[nx+ux][ny+uy]=dis[nx][ny];
					se.insert({dis[nx][ny], {nx+ux, ny+uy}});
				}
			}
		}
		for(auto ux:xx){
			for(auto uy:yy){
				if(ux==0 && uy==0){
					continue;
				}
				if(nx+ux>=h || nx+ux<0 || ny+uy<0 || ny+uy>=w){
					continue;
				}
				if(arr[nx+ux][ny+uy]=='#'){
					continue;
				}
				if(dis[nx][ny]+1<dis[nx+ux][ny+uy]){
					dis[nx+ux][ny+uy]=dis[nx][ny]+1;
					se.insert({dis[nx+ux][ny+uy], {nx+ux, ny+uy}});
				}
			}
		}
	}
	if(dis[x2][y2]==N){
		cout<<-1;
	}
	else{
		cout<<dis[x2][y2];
	}
	return 0;
}

Measured memory_bytes: 14028
r, g, b, n = map(int, input().split())
cnt = 0
for red in range(n // r + 1):
    for green in range((n - r * red) // g + 1):
        blue = n - red * r - green * g
        if blue >= 0 and blue % b == 0:
            cnt += 1
print(cnt)

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

int main(){
  int c[3][3];
  for (int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j++){
      cin >> c[i][j];
    }
  }
  
  int a[3], b[3];
  for (int i = 0; i <= c[0][0]; i++){
    a[0] = i;
    b[0] = c[0][0] - i;
    for (int j = 1; j < 3; j++){
      a[j] = c[j][0] - b[0];
    }
    for (int j = 1; j < 3; j++){
      b[j] = c[0][j] - a[0];
    }
    
    bool flag = true;
    for (int j = 1; j < 3; j++){
      for (int k = 1; k < 3; k++){
        if (c[j][k] != a[j] + b[k]) flag = false;
      }
    }
    if (flag){
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  puts("No");
}

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

using namespace std;
long long a[100005],b[100005];
long long x[100005],y[100005],m[100005];
int main(){
	int A,B,M;
	cin>>A>>B>>M;
	for(int i=0;i<A;i++){
		cin>>a[i];
	}
	for(int i=0;i<B;i++){
		cin>>b[i];
	} 
	for(int i=0;i<M;i++){
		cin>>x[i]>>y[i]>>m[i];
        x[i]--,y[i]--;
	}
	long long ans=1e12;
	for(int i=0;i<M;i++){
		ans=min(ans,a[x[i]]+b[y[i]]-m[i]);
	}
	long long k1=1e12,k2=1e12;
	for(int i=0;i<A;i++)k1=min(k1,a[i]);
	for(int i=0;i<B;i++)k2=min(k2,b[i]);
	ans=min(ans,k1+k2);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4096
//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
#define INF 9999999999
#define N 300003
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
string s , T , chk[5] = { "dream" , "dreamer" , "erase" , "eraser" } , take;
bool flag = 0;
int last;
int main(){
fcin;
	cin>>s;
	while(last<s.length()){
		take = s.substr(last,7);
		//cout<<take<<endl;
		if(take!="dreamer"){
			
			take = s.substr(last,6);
			
			if(take!="eraser"){
			
			take = s.substr(last,5);
			
			if(take!="dream" && take!="erase") { 
			
			flag = 1; break;
			
				}
			
			else last += 5;
			
			}
			else{

				last += 6;
			
			}
		}
		else {
			if(take=="dreamer"){
				if(s[last+7]=='a') last += 5;
				else last += 7; 
			}
			else last += 7;
		}

	}
	if(!flag) cout<<"YES\n";
	else cout<<"NO\n";


}

Measured memory_bytes: 512
move_num = int(input())
input_char_str = input()

char_list  = [chr(i) for i in range(65, 65+26)]

ans_char = ""
move_number = move_num
for input_char in input_char_str:
    if (char_list.index(input_char)+move_number) < len(char_list):
        ans_char += char_list[char_list.index(input_char)+move_number]
    else:
        char_index = (char_list.index(input_char)+move_number) - len(char_list)
        ans_char += char_list[char_index]
        
print(ans_char)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
#include<iomanip>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<long double> vdouble;
typedef vector<vector<long double>> vvdouble;
typedef vector<vector<vector<long double>>> vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007


//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// int binary_search(int key){
//  //isOKを満たす要素のうち最小のインデックスを返す。（要ソート）
//   int left = -1;
//   int right = N;
//
//   while(right - left > 1){
//     int mid = left + (right - left)/2;
//
//     if(isOK(mid, key)) right=mid;
//     else left=mid;
//   }
//
//   return right;
// }

// ll gcd(ll m, ll n){
//   if(m<n) swap(m,n);
//   if(n==0) return m;
//   return gcd(n, m%n);
// }

// ll get_pow(ll x, ll y){
//   ll ret=0;
//   ll temp = y;
//   while(true){
//     if(x<=temp) break;
//     ret++;
//     temp *= 2;
//   }
//   return ret;
// }






int main() {
  cout<<fixed<<setprecision(10);

  ll N;cin>>N;
  vint a(N-1),b(N-1);
  rep(i,N-1){
    cin>>a[i]>>b[i];
    a[i]--;
    b[i]--;
  }
  vint c(N);
  rep(i,N)cin>>c[i];
  vsortgr(c);

  vvint edge(N);
  rep(i,N-1){
    edge[a[i]].pb(b[i]);
    edge[b[i]].pb(a[i]);
  }

  vint reached(N,0);
  queue<ll> q;
  q.push(0);
  reached[0] = 1;
  vint cnew(N,0);
  cnew[0] = c[0];

  ll cnt = 1;
  ll ans = 0;

  while(!q.empty()){
    ll temp = q.front();
    q.pop();

    for(ll e : edge[temp]){
      if(reached[e]>0) continue;
      cnew[e] = c[cnt];
      ans += c[cnt];
      cnt++;
      reached[e] = 1;
      q.push(e);
    }
  }

  cout << ans << endl;
  rep(i,N) cout << cnew[i] << " ";
  cout << endl;

}

















//


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>

using namespace std;

int main(){

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

	sort(a,a+n);
	double ans=a[0];

	for(int i=1;i<n;i++){
	
		ans+=a[i];
		ans/=2;
	}

	cout<<ans<<'\n';
}


Measured memory_bytes: 3744
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_152b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');

            Array.Sort(input);

            Console.WriteLine(new string(Convert.ToChar(input[0]) , int.Parse(input[1])));

            Console.Read();
        }
    }
}


Measured memory_bytes: 11360
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin>>a>>b;
    a*=b;
    if(a%2==0) cout<<"Even\n";
    else cout<<"Odd\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

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

    int n;
    cin >> n;
    int x[n], y[n];
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }

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

    double tot = 0;
    do {
        for (int i = 1; i < n; i++) {
            tot += sqrt(pow(x[p[i]] - x[p[i-1]], 2) + pow(y[p[i]] - y[p[i-1]], 2));
        }
    } while (next_permutation(p, p+n));

    for (int i = 1; i <= n; i++) {
        tot /= i;
    }

    cout << fixed << setprecision(10) << tot << endl;

    return 0;
}


Measured memory_bytes: 256
#coding:utf-8
#1_11_A 2015.4.17
class Dice:
    def __init__(self,ary):
        self.top = ary[0]
        self.south = ary[1]
        self.east = ary[2]
        self.west = ary[3]
        self.north = ary[4]
        self.bottom = ary[5]

    def get_top(self):
        return self.top

    def roll_n(self):
        self.top , self.south , self.bottom , self.north = self.south , self.bottom , self.north , self.top

    def roll_s(self):
        self.top , self.north , self.bottom , self.south = self.north , self.bottom , self.south , self.top

    def roll_e(self):
        self.top , self.west , self.bottom , self.east = self.west , self.bottom , self.east , self.top

    def roll_w(self):
        self.top , self.east , self.bottom , self.west = self.east , self.bottom , self.west , self.top

dice = Dice(input().split())
cmds = input()
for cmd in cmds:
    if cmd == 'N':
        dice.roll_n()
    elif cmd == 'S':
        dice.roll_s()
    elif cmd == 'E':
        dice.roll_e()
    elif cmd == 'W':
        dice.roll_w()

print(dice.get_top())

Measured memory_bytes: 6744
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <deque>
#include <bitset>
#define ll              long long
#define PII             pair<int, int>
#define rep(i,a,b)      for(int  i=a;i<=b;i++)
#define dec(i,a,b)      for(int  i=a;i>=b;i--)
#define pb              push_back
#define mk              make_pair
using namespace std;
int dir[4][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } };
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979323846;
const int mod = 998244353;
const int N = 50 + 5;
//if(x<0 || x>=r || y<0 || y>=c)

inline ll read()
{
	ll x = 0; bool f = true; char c = getchar();
	while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
	while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
	return f ? x : -x;
}

ll gcd(ll m, ll n)
{
	return n == 0 ? m : gcd(n, m % n);
}
ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}
ll m, n, q;
ll a[N], b[N], c[N], d[N];
vector<bool> vis(11, false);
ll ans = 0;
void dfs(vector<int> &v)
{
	if (v.size()-1 == n)
	{
		ll res = 0;
		rep(i, 1, q)
		{
			if (v[b[i]] - v[a[i]] == c[i])
				res += d[i];
		}
		ans = max(ans,res);
		return;
	}
	for (int i = 1; i <= m; i++)
	{
		if (v.back()<=i)
		{
			v.push_back(i);
			dfs(v);
			v.pop_back();
		}
	}
}
int main()
{
	cin >> n >> m >> q;
	rep(i, 1, q)
	{
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	vector<int> v(1,0);
	dfs(v);
	cout << ans << endl;
	return 0;
}



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

int main() {
  string a,b;
  cin >> a >> b;
  if(a.size() == b.size()){
    if(a < b){
      cout << "LESS" << endl;
    }else if(a > b){
      cout << "GREATER" << endl;
    }else if(a == b){
      cout << "EQUAL" << endl;
    }
  }else if(a.size() <= b.size()){
    cout << "LESS" << endl;
  }else{
    cout << "GREATER" << endl;
  }
}


Measured memory_bytes: 256
N, Y = map(int, input().split())

resx, resy, resz = (-1, -1, -1)
for x in range(Y//10000+1):
    for y in range(N+1-x):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z

        if total == Y:
            resx, resy, resz = (x, y, z)
            break
        else:
            if total > Y:
                break
            else:
                continue

print(resx, resy, resz)

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7
bit_one_count = [0 for i in range(60)]
bit_zero_count = [0 for i in range(60)]
for i in range(n):
    bits = '{0:060b}'.format(a[i])
    for j in range(60):
        if bits[-1 -j] == '1':
            bit_one_count[j] += 1
        else:
            bit_zero_count[j] += 1

ans = 0
for j in range(60):
    ans += bit_one_count[j] * bit_zero_count[j] * 2 ** j
    ans %= MOD

print(ans)


Measured memory_bytes: 125624
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define INF 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int> >;
vector<ll> memo(1e5+1,-1);
vector<ll>h;
ll rec(int n){
    if(n<0) return INF;
    if(n==0) return 0;
    if(memo[n]!=-1)return memo[n];
    ll res1=rec(n-1)+abs(h[n]-h[n-1]);
    ll res2=rec(n-2)+abs(h[n]-h[n-2]);
    return memo[n]=min(res1,res2);
}

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
h.resize(n);
rep(i,n)cin>>h[i];
cout<<rec(n-1)<<endl;
//system("pause");
return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> vec(n), cop(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
    cop[i] = vec[i];
  }
  sort(cop.begin(), cop.end());
  int k = 0;
  for (int i = 0; i < n; i++) {
    k += (vec[i] != cop[i]);
  }
  cout << (k == 2 || k == 0 ? "YES" : "NO") << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, k, n) for (int i = k; i < n; ++i)
#define sz(s) (int)s.size()
#define F first
#define S second


vector<pair<char, int>> run(string &s) {
    vector<pair<char, int>> res;
    for (char c: s) {
        if (res.empty() || res.back().first != c) res.emplace_back(c, 1);
        else res.back().second++;
    }
    return res;
}


int main() {
    int l; string s;
    while (cin >> l >> s) {
        int maxcnt = 0;
        rep(i, sz(s)) {
            if (s[i] == '.') {
                string t = s;
                t[i] = 'W';
                auto v = run(t);
                int tmp = 0;
                rep(j, sz(v) - 2) {
                    if (v[j].F == 'B' && v[j + 1].F == 'W' && v[j + 2].F == 'B') {
                        tmp = 0;
                        break;
                    }
                    if (v[j].F == 'W' && v[j + 1].F == 'B' && v[j + 2].F == 'W') {
                        tmp = max(tmp, v[j + 1].S);
                    }
                }
                maxcnt = max(maxcnt, tmp);
            }
        }
        cout << maxcnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3204
from subprocess import*
with open('e.cpp','w')as f:f.write(r"""
#include <bits/stdc++.h>
using namespace std;

const int maxs = 4096;
int dp[maxs];

int main() {
	memset(dp, 0x3f, 16384);
	dp[0] = 0;
	int n, m;
	cin >> n >> m;
	while (m--) {
		int a, b, s = 0;
		cin >> a >> b;
		while (b--) {
			int c;
			cin >> c;
			s ^= 1 << c - 1;
		}
		dp[s] = min(dp[s], a);
	}
	for (int i = 0; i != n; ++i) for (int all = (1 << n) - 1 ^ 1 << i, sub = all; sub; sub = sub - 1 & all)
		dp[sub] = min(dp[sub], dp[sub ^ 1 << i]);
	for (int s = 0; s != (1 << n); ++s) if (s != (s & -s))
		for (int t = s - 1 & s; t != s; t = t - 1 & s)
			dp[s] = min(dp[s], dp[t] + dp[s ^ t]);
	int mask = (1 << n) - 1;
	if (dp[mask] == 0x3f3f3f3f) dp[mask] = -1;
	cout << dp[mask] << endl;
}""")
call(('g++','e.cpp'))
call('./a.out')


Measured memory_bytes: 73572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)
#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl


int main(){
    int a,b;
    cin>>a>>b;
    Yes(a%2&&b%2);
    return 0;
}

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

int main() {
    vector <int> a(1000000);
    cin >> a.at(0);
    int i=1;
    int tmp=0;
    while (true) {
        if (a.at(i-1)%2==0) tmp=a.at(i-1)/2;
        else tmp=3*a.at(i-1)+1;
        if (find(a.begin(), a.end(), tmp)!=a.end()) {
            cout << i+1;
            return 0;
        }
        a.at(i)=tmp;
        i++;
    }
}

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

int main(int argc, char *argv[]){
    std::string S;
    std::cin >> S;
    int N = S.size();
    std::string isEasy("Yes");
    for(int i=0; i<N; ++i){
        if((i&1)==0){
            if(S[i] == 'L'){
                isEasy = "No";
                break;
            }
        }else if((i&1)==1){
            if(S[i] == 'R'){
                isEasy = "No";
                break;
            }
        }
    }
    std::cout << isEasy << std::endl;
    return 0;
}


Measured memory_bytes: 256
//xenowitz -- Jai Shree Ram
#include<bits/stdc++.h>
using namespace std;

#define fori(i,a,b) for (long int i = a; i <= b ; ++i)
#define ford(i,a,b) for(long int i = a;i >= b ; --i)
#define mk make_pair
#define mod 1000000007
#define pb push_back
#define eb emplace_back
#define vec vector<long long int>
#define ll long long
#define rnd mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count())
#define pi pair<long long int,long long int>
#define sc second
#define fs first
#define stf shrink_to_fit

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

  int n;
  cin >> n;

  vector<pair<int,int> > v;
  int a, b;
  fori(i,1,n) {
      cin >> a >> b;
      v.pb(mk(a, b));
  }

  for(int i = 0; i+2 < n; i += 1) {
      if (v[i].fs == v[i].sc &&
        v[i+1].fs == v[i+1].sc &&
    v[i+2].fs == v[i+2].sc) {
        cout << "Yes" << endl;
        return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3624
#ifdef DEBUG
#include "../utils.cpp"
#endif
#include <bits/stdc++.h>
/*
Problem


Category
DP
 
URL:


考察:



Date: 2020/06/01
*/
 

using namespace std;
using ll = int64_t;
#define int int64_t
#define INF 10e9

 
/* ==== declarations ====== */
// functions
void solve();
void getInput();
 
// global variables
int N;
vector<int> L, R;
vector<vector<int>> dp;

/* ======================== */


void getInput() {
    cin>>N;
    L = vector<int>(N, 0);
    R = vector<int>(N, 0);
    dp = vector<vector<int>>(N, vector<int>(N, 1e9));
    
    for(int i=0; i<N; ++i) {
        cin>>L[i]>>R[i];
    }
}
 

void solve() {
    
    for(int i=0; i<N; ++i) {
        dp[i][i] = 0;
    }
    for(int i=0; i+1<N; ++i) {
        dp[i][i+1] = L[i]*R[i]*R[i+1];
    }

    for(int i=2; i<N; ++i) {
        for(int j=0; i+j < N; ++j) {
            for(int k = 0; k<i; ++k) {
                int p = L[j];
                int q = R[j+k];
                int r = R[j+i];
                dp[j][j+i] = min(dp[j][j+i], p*q*r + dp[j][j+k] + dp[j+k+1][j+i]);

            }
        }
    }
    cout<<dp[0][N-1]<<endl;
}
 
 
signed main(){
    
    getInput();
    solve();
    
    return 0;
}




Measured memory_bytes: 3228
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    int l[n],r[n];
    l[0]=a[0];
    for(int i=1;i<n;i++)
    {
        l[i]=__gcd(a[i],l[i-1]);
    }
    r[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--)
    {
        r[i]=__gcd(a[i],r[i+1]);
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(i==0) ans=max(ans,__gcd(0,r[i+1]));
        else if(i==n-1) ans=max(ans,__gcd(l[i-1],0));
        else ans=max(ans,__gcd(l[i-1],r[i+1]));
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4816
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<stack>
#include<string>

using namespace std;
 
int main(void){
 
    stack<double> data;
	double num1,num2;
    string inp;


	while(cin>>inp){
		if(inp=="*"||inp=="+"||inp=="-"||inp=="/"){
			num2=data.top(),data.pop();
			num1=data.top(),data.pop();
			switch(inp[0]){
				case'*':
					data.push(num1*num2);
					break;
				case'/':
					data.push(num1/num2);
					break;
				case'+':
					data.push(num1+num2);
					break;
				case'-':
					data.push(num1-num2);
					break;
				default:
					return 1;
			}
		}
		else{
			data.push(atoi(inp.c_str()));
		}
	}
	cout<<data.top()<<endl;
    return 0;
}

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

#define p pair<int,int>
#define f first
#define s second
#define ll long long
#define db double

const int maxn=1e6+10;
const int inf=1e9;

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    int n,m;
    cin>>n>>m;
    cout<<(n-1)*(m-1);
    return 0;
}

Measured memory_bytes: 892
from itertools import combinations
import math

counter = 0
n, d = map(int, input().split())

li_n = list()

for i in range(n):
    li_n.append(list(map(int, input().split())))

for con in combinations(li_n, 2):
    result = math.sqrt(sum([(abs(x - y)) ** 2 for x, y in zip(con[0], con[1])]))
    if result.is_integer():
        counter += 1

print(counter)





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

using namespace std;

int dist[100][100][2];
char board[100][100];
int h,w;

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

	cin >> h >> w;

	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin >> board[i][j];
		}
	}

	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			dist[i][j][0] = 1e9;
			dist[i][j][1] = 1e9;
		}
	}

	priority_queue <pair<int,pair<pair<int,int>,int>>,vector<pair<int,pair<pair<int,int>,int>>>,greater<pair<int,pair<pair<int,int>,int>>>> pque;

	if(board[0][0]=='#')
	{
		dist[0][0][1] = 1;
		pque.push(make_pair(dist[0][0][1],make_pair(make_pair(0,0),1)));
	}
	else
	{
		dist[0][0][0] = 0;
		pque.push(make_pair(dist[0][0][0],make_pair(make_pair(0,0),0)));
	}

	while(!pque.empty())
	{
		int y = pque.top().second.first.first;
		int x = pque.top().second.first.second;
		int t = pque.top().second.second;
		pque.pop();

		if(t==0)
		{
			if(y+1<h)
			{
				if(board[y+1][x]=='#')
				{
					if(dist[y+1][x][1-t] > dist[y][x][t] + 1)
					{
						dist[y+1][x][1-t] = dist[y][x][t] + 1;
						pque.push(make_pair(dist[y+1][x][1-t],make_pair(make_pair(y+1,x),1-t)));
					}
				}
				else
				{
					if(dist[y+1][x][t] > dist[y][x][t])
					{
						dist[y+1][x][t] = dist[y][x][t];
						pque.push(make_pair(dist[y+1][x][t],make_pair(make_pair(y+1,x),t)));
					}
				}
			}
			if(x+1<w)
			{
				if(board[y][x+1]=='#')
				{
					if(dist[y][x+1][1-t] > dist[y][x][t] + 1)
					{
						dist[y][x+1][1-t] = dist[y][x][t] + 1;
						pque.push(make_pair(dist[y][x+1][1-t],make_pair(make_pair(y,x+1),1-t)));
					}
				}
				else
				{
					if(dist[y][x+1][t] > dist[y][x][t])
					{
						dist[y][x+1][t] = dist[y][x][t];
						pque.push(make_pair(dist[y][x+1][t],make_pair(make_pair(y,x+1),t)));
					}
				}				
			}
		}
		else
		{
			if(y+1<h)
			{
				if(board[y+1][x]=='#')
				{
					if(dist[y+1][x][t] > dist[y][x][t])
					{
						dist[y+1][x][t] = dist[y][x][t];
						pque.push(make_pair(dist[y+1][x][t],make_pair(make_pair(y+1,x),t)));
					}
				}
				else
				{
					if(dist[y+1][x][1-t] > dist[y][x][t])
					{
						dist[y+1][x][1-t] = dist[y][x][t];
						pque.push(make_pair(dist[y+1][x][1-t],make_pair(make_pair(y+1,x),1-t)));
					}
				}
			}
			if(x+1<w)
			{
				if(board[y][x+1]=='#')
				{
					if(dist[y][x+1][t] > dist[y][x][t])
					{
						dist[y][x+1][t] = dist[y][x][t];
						pque.push(make_pair(dist[y][x+1][t],make_pair(make_pair(y,x+1),t)));
					}
				}
				else
				{
					if(dist[y][x+1][1-t] > dist[y][x][t])
					{
						dist[y][x+1][1-t] = dist[y][x][t];
						pque.push(make_pair(dist[y][x+1][1-t],make_pair(make_pair(y,x+1),1-t)));
					}
				}				
			}
		}
	}

	cout << min(dist[h-1][w-1][0],dist[h-1][w-1][1]) << '\n';

	return 0;
}

Measured memory_bytes: 384
#include <iostream>

int main(){
   int X, A, B;
   std::cin >> X >> A >> B;

   if (A>=B) std::cout << "delicious" << std::endl;
   else if (A+X>=B) std::cout << "safe" << std::endl;
   else std::cout << "dangerous" << std::endl;

   return 0;
}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n; cin>> n;

    long double sum= 0, x;
    string u;

    for(int i=0; i<n; i++)
    {
        cin>> x>> u;

        sum += (u== "JPY" ? x : x* 380000);
    }

    cout << fixed << setprecision (8) << sum;
    nl;

    return 0;
}




Measured memory_bytes: 3696
#include<iostream>
using namespace std ;
 int main(){
int A,B,C;
cin>>A>>B>>C;
if(A==C &&B!=C && B!=A && C==A){
    cout<<B;
}
else if (A==B && B==A && C!=A && C!=B){
    cout<<C;
}
else if (A!=B && A!=C && B==C &&C==B){
    cout<<A;
}
 return 0;
 }


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

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

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

    if(a%b == 0) cout << "0" << endl;
    else cout << "1" << endl;; 

    return 0;
}


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

const int N = 200005;

std::map<int, int> id;

int n, a[N], b[N], c[N], d[N], f[N], ans, tot = 0;
int active(int x) {
	if (id.count(x)) return id[x];
	else return id[x] = ++tot, f[tot] = tot;
}
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
void link(int x, int y) { f[find(x)] = find(y); }

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> a[i], a[0] ^= a[i];
	for (int i = 1; i <= n; ++i) std::cin >> b[i], b[0] ^= b[i];
	for (int i = 0; i <= n; ++i) c[i] = a[i], d[i] = b[i];
	std::sort(c, c + n + 1), std::sort(d, d + n + 1);
	for (int i = 0; i <= n; ++i) if (c[i] != d[i]) return std::cout << "-1\n", 0;
	for (int i = 0; i <= n; ++i) if (a[i] != b[i]) link(active(a[i]), active(b[i])), ++ans;
	for (int i = 1; i <= tot; ++i) ans += i == find(i);
	if (a[0] != b[0]) ans -= 2;
	else
		for (int i = 1; i <= n; ++i)
			if (a[i] != b[i] && a[i] == a[0]) {--ans; break;}
	std::cout << ans << '\n';
	return 0;
}

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

using namespace std;

template <typename T>
vector<int> kmp_table(int n, const T& s) {
  vector<int> p(n);
  int k = 0;
  for (int i = 1; i < n; ++i) {
    while (k > 0 && s[i] != s[k]) {
      k = p[k - 1];
    }
    if (s[i] == s[k]) {
      ++k;
    }
    p[i] = k;
  }
  return p;
}

template <typename T>
vector<int> kmp_table(const T& s) {
  return kmp_table((int) s.size(), s);
}

template <typename T>
vector<int> kmp_search(int n, const T& s, int m, const T& w, const vector<int>& p) {
  assert(n >= 1 && (int) p.size() == n);
  vector<int> ret;
  int k = 0;
  for (int i = 0; i < m; ++i) {
    while (k > 0 && (k == n || w[i] != s[k])) {
      k = p[k - 1];
    }
    if (w[i] == s[k]) {
      ++k;
    }
    if (k == n) {
      ret.push_back(i - n + 1);
    }
  }
  return ret;
}

template <typename T>
vector<int> kmp_search(const T& s, const T& w, const vector<int>& p) {
  return kmp_search((int) s.size(), s, (int) w.size(), w, p);
}

int main() {
  string s;
  cin >> s;
  int n = (int) s.size();
  vector<bool> f(n), g(n);
  for (int rot = 0; rot < 2; ++rot) {
    auto& v = rot == 0 ? f : g;
    auto p = kmp_table(s);
    for (int i = 0; i < n; ++i) {
      v[i] = (p[i] == 0 || (i + 1) % (i + 1 - p[i]) != 0);
    }
    reverse(s.begin(), s.end());
  }
  if (f[n - 1]) {
    cout << "1\n1\n";
    return 0;
  }
  int split = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (f[i] && g[n - 2 - i]) {
      ++split;
    }
  }
  if (split == 0) {
    cout << n << '\n' << 1 << '\n';
  } else {
    cout << 2 << '\n' << split << '\n';
  }
  return 0;
}

Measured memory_bytes: 2912
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





int main() {
    ll H, W, h, w;
    cin >> H >> W >> h >> w;
    
    if(H % h == 0 && W % w == 0){
        cout << "No" << endl;
        return 0;
    }
    
    vector<vector<ll>> ans(H, vector<ll>(W));
    if(W % w != 0){
        ll minus = -(w * 2 - 1);
        ll sum = 0;
        REP(j, W){
            ans[0][j] = j % w == w - 1? minus : 2;
            sum += ans[0][j];
        }
        while(sum <= 0){
            REP(j, W){
                ll t = j % w == w - 1? -2 * (w - 1) : 2;
                ans[0][j] += t;
                sum += t;
            }
        }
        REP(i, H - 1){
            REP(j, W){
                ans[i + 1][j] = ans[i][j];
            }
        }
    }
    else{
        ll minus = -(h * 2 - 1);
        ll sum = 0;
        REP(i, H){
            ans[i][0] = i % h == h - 1? minus : 2;
            sum += ans[i][0];
        }
        while(sum <= 0){
            REP(i, H){
                ll t = i % h == h - 1? -2 * (h - 1) : 2;
                ans[i][0] += t;
                sum += t;
            }
        }
        REP(i, H){
            REP(j, W - 1){
                ans[i][j + 1] = ans[i][j];
            }
        }
    }
    
    cout << "Yes" << endl;
    REP(i, H){
        REP(j, W){
            cout << ans[i][j] << " \n"[j == W - 1];
        }
    }
}


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

int N, M;
const int N_MAX = 1e5;

int main(){
  cin >> N >> M;
  priority_queue<int> que;
  for(int i = sqrt(M); i >= 1; i--){
    if(M % i == 0) {
      que.push(i); que.push(M / i);
    }
  }
  
  while(!que.empty()){
    int n = que.top(); que.pop();
    if(M / n >= N) {
      cout << n << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,x;
    cin>>k>>x;
    if(k==1)
    cout<<x;
    else
    {
        for(int i=x-k+1;i<k+x;i++)
        {
            cout<<i<<" ";
        }
    }
}

Measured memory_bytes: 3592
n = int(input())
a = list(map(int,input().split()))
x = [3,3]

temp = 3
for i in range(1,30):
    temp *= 2
    x.append(temp)
    
a.sort(reverse = True)
sepa = []
un = []
j,k = 0,0
for i in range(n):
    if j == x[k]:
        sepa.append(un)
        un = []
        un.append(a[i])
        k += 1
        j = 1
        
    else:
        un.append(a[i])
        j += 1
        
sepa.append(un)

if len(sepa) >= 3:
    ans = sepa[0][0] + (sepa[0][1] + sepa[0][2]) * 2
    for i in range(len(sepa)-2):
        for j in range(len(sepa[i+2])):
            ans += sepa[i+1][j//2]
            
else:
    p = [0,1,1,2,2]
    ans = 0
    for i in range(n-1):
        ans += sepa[0][p[i]]
            
print(ans)

Measured memory_bytes: 97480