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

int main(){
  int h,w,n,s_h,s_w ;
  cin >> h >> w >> n >> s_h >> s_w ;
  string s,t ;
  cin >> s >> t ;
  bool up,down,right,left ;
  up = down = right = left = false ;
  int place_u,place_d,place_r,place_l ;
  place_u = place_d = s_h ;
  place_r = place_l = s_w ;
  for(int i=0;i<n;i++){
    if(s.at(i)=='U'){
      place_u-- ;
      if(place_u==0){
        cout << "NO" << endl ;
        return 0 ;
      }
    }
    if(s.at(i)=='D'){
      place_d++ ;
      if(place_d==h+1){
        cout << "NO" << endl ;
        return 0 ;
      }
    }
    if(s.at(i)=='R'){
      place_r++ ;
      if(place_r==w+1){
        cout << "NO" << endl ;
        return 0 ;
      }
    }
    if(s.at(i)=='L'){
      place_l-- ;
      if(place_l==0){
        cout << "NO" << endl ;
        return 0 ;
      }
    }
    if(t.at(i)=='U'){
      place_d-- ;
      if(place_d==0)
        place_d++ ;
    }
    if(t.at(i)=='D'){
      place_u++ ;
      if(place_u==h+1)
        place_u-- ;
    }
    if(t.at(i)=='R'){
      place_l++ ;
      if(place_l==w+1)
        place_l-- ;
    }
    if(t.at(i)=='L'){
      place_r-- ;
      if(place_r==0)
        place_r++ ;
    }
  }
  cout << "YES" << endl ;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define ll long long
const int MOD = 1e9 + 7;
using namespace std;
ll func(int bit,ll a)
{
  return ((a >> bit) & 1);
}
ll d(ll num) {
    ll count = 0;
    while(num) {
        num /= 10;
        count++;
    }
    return count;
}
bool pos(ll num, ll a , ll b, ll x) {

    ll tot = a * num + b * d(num);
    // cout << num << " " << tot << "\n";
    if(tot <= x)
        return true;
    return false;
}
int main() {
    int N;
    string s;
    cin >> N >> s;
    for (int i = 0; i < s.size(); ++i)
    {
        char c = ((s[i]-'A') + N)%26 + 'A';
        printf("%c",c);
    }
    cout << endl;
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (x).size()

ll mod = 1000000007;

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

ll inv(ll x){
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while(k){
    if(k&1)res = (res*y)%mod;
    y = (y*y) % mod;
    k /= 2;
  }
  return res;
}


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

  int n,k;
  cin >> n >> k;
  vi a(n);
  rep(i,n) cin >> a[i];

  for(int i = k; i < n;i++){
    if(a[i] > a[i-k]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    double x[100],y[100];
    int n;
    cin >> n;
    for(int i=0;i<n;i++) cin >> x[i];
    for(int i=0;i<n;i++) cin >> y[i];
    
    for(int p=1;p<=3;p++){
        double d=0.0;
        for(int i=0;i<n;i++) d+=pow(abs(x[i]-y[i]),(double)p);
        printf("%.12lf\n",pow(d,1.0/(double)p));
    }
    double d=0;
    for(int i=0;i<n;i++) d=max(d,abs(x[i]-y[i]));
    printf("%.12lf\n",d);
    
    return 0;
}


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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N; cin >> N;

    cout << N*N*N << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(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 = n - 1; i >= 0; --i)
#define INF 100000000
#define pb push_back
#define all(x) (x).begin(),(x).end()

typedef long long ll;

int main() {
	int A, B, C; cin >> A >> B >> C;
	if (( A > C) && ( B < C)) cout << "Yes";
	else if (( A < C) && ( B > C)) cout << "Yes";
	else cout << "No";
	


	return 0;
}

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(10);
    /*start*/
    string s, t;
    cin >> s >> t;
    sort(All(s));
    sort(All(t), greater<>());
    if (s < t)
    {
        c("Yes");
    }
    else
    {
        c("No");
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll         long long int
#define vi           vector<ll>
#define pii          pair<ll,ll>
#define vpp          vector<pii>
#define mii          map<ll,ll>
#define pb           push_back
#define endl        '\n'
#define rep(i,a,bb)  for(ll i=a;i<bb;i++)
#define ff           first
#define ss           second
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test         ll T;cin>>T;while(T--)
#define __sort(v)    sort(v.begin(),v.end())
#define __rsort(v)   sort(v.rbegin(),v.rend())
#define setbits(x)   __builtin_popcount(x)
#define zrobits(x)   __builtin_ctzll(x)
const ll inf = 5 * (1e+18);
const ll mod = 7 + 1e+9;




int32_t main()
{
  fast;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif


  ll k;
  ll a, b;
  cin >> k >> a >> b;

  ll r = ceil(a * 1.0 / k) * k;
  if (r >= a && r <= b)  cout << "OK";
  else cout << "NG";





  return 0;
}





Measured memory_bytes: 3608
#include<stdio.h>
int main()
{
    long long n,sum=0,T,max,min;
    scanf("%lld",&T);
    for(int i=1; i<=T; i++)
    {
        scanf("%lld ",&n);
        if(i==1)
            max=min=n;
        if(max<n)
            max=n;
        else if(min>n)
            min=n;
        sum=sum+n;
    }
    printf("%d %d %lld\n",min,max,sum);
    return 0;
}



Measured memory_bytes: 2108
import java.util.Scanner;
public class Main{
public static void main(String[] args){
  Scanner scan = new Scanner(System.in);
  int n = scan.nextInt();
  int k = scan.nextInt();
  int x = 0;
  
  while( n >= Math.pow(k,x)){
    x ++;
  }
  
  System.out.println(x);
}
}


Measured memory_bytes: 21844
#include<cstdio>
const int inf=1<<30;
int H,W,V[110][110][2],tot=2;
char a[110][110];
struct edge{int to,cap;edge*rev,*next;}E[110000],*ne=E,*fir[22000],*cur[22000];
void link(int a,int b,int c){
	*ne=(edge){b,c,ne+1,fir[a]};fir[a]=ne++;
	*ne=(edge){a,0,ne-1,fir[b]};fir[b]=ne++;
}
int Q[22000],D[22000];
int dfs(int i,int c){
	if(i==1||!c)return c;
	int fl=0,f;
	for(edge*&e=cur[i];e&&c;e=e->next)
		if(e->cap&&D[e->to]==D[i]-1&&(f=dfs(e->to,c<e->cap?c:e->cap)))
			fl+=f,e->cap-=f,e->rev->cap+=f,c-=f;
	return fl;
}
int mf(){
	for(int f=0;;f+=dfs(0,1<<30)){
		for(int i=0;i<tot;i++)D[i]=0,cur[i]=fir[i];
		for(int*h=Q,*t=Q+(D[*Q=1]=1);h<t;h++)
			for(edge*e=fir[*h];e;e=e->next)
				if(e->rev->cap&&!D[e->to])D[*t++=e->to]=D[*h]+1;
		if(!*D)return f;
	}
}
int main(){
	scanf("%d%d",&H,&W);
	for(int i=0;i<H;i++){
		scanf("%s",a[i]);
		int o=tot++;
		for(int j=0;j<W;j++)if(a[i][j]!='.'){
			V[i][j][0]=tot++;
			V[i][j][1]=tot++;
			link(V[i][j][0],V[i][j][1],1);
			link(V[i][j][1],o,inf);
			link(o,V[i][j][0],inf);
			if(a[i][j]=='S')link(0,V[i][j][1],inf);
			if(a[i][j]=='T')link(V[i][j][0],1,inf);
		}
	}
	for(int j=0;j<W;j++){
		int o=tot++;
		for(int i=0;i<H;i++)if(a[i][j]!='.'){
			link(V[i][j][1],o,inf);
			link(o,V[i][j][0],inf);
		}
	}
	int ans=mf();
	printf("%d\n",ans>=inf?-1:ans);
}

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

using namespace std;

typedef long long ll;

const int Mod = 1e9 + 7;

void add_self(int& x, int y)
{
    if((x += y) >= Mod) x -= Mod;
}

void sub_self(int& x, int y)
{
    if((x -= y) < 0)    x += Mod;
}

int mul(int x, int y)
{
    return (ll) x * y % Mod;
}

int fp(int x, int y)
{
    int Res = 1;

    for( ; y > 0; y >>= 1, x = mul(x, x))
        if(y & 1)
            Res = mul(Res, x);

    return Res;
}

int Inv(int x)
{
    return fp(x, Mod - 2);
}

int C(int n, int r)
{
    if(n < 0 || r < 0 || n < r) return 0;

    r = min(r, n - r);

    int Num = 1;
    int Den = 1;

    for(int i = 0; i < r; i++)
    {
        Num = mul(Num, n - i);
        Den = mul(Den, i + 1);
    }

    return mul(Num, Inv(Den));
}

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

    int Ans = fp(2, n);

    sub_self(Ans, 1);
    sub_self(Ans, C(n, a));
    sub_self(Ans, C(n, b));

    cout << Ans << endl;
}


Measured memory_bytes: 256
N = int(input())

A = list(map(int, input().split()))

print(" ".join(map(str, A)))

for i in range(1,N):
  v = A[i]
  for j in range(i):
    if  A[i-j-1]>v:
      A[i-j] = A[i-j-1]
      A[i-j-1] = v
    else:
      break
  print(" ".join(map(str, A)))


Measured memory_bytes: 5596
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n, m;
    cin >> n >> m;
    vector<bool> flg(n, false);
    vector<int> cnt(n, 0);
    rep(i, m) {
        int p;
        string s;
        cin >> p >> s;
        --p;
        if (s == "AC") {
            flg[p] = true;
        }
        else if (!flg[p] && s == "WA") {
            ++cnt[p];
        }
    }
    int ac_ans = 0;
    int wa_ans = 0;
    rep(i, n) {
        if (flg[i]) {
            ++ac_ans;
            wa_ans += cnt[i];
        }
    }
    cout << ac_ans << " " << wa_ans << endl;
    return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i< (int)(n); i++)
#define rep2(i,x,n) for(int i = (int)x; i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define repitr(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i, n) cin >> p.at(i);
	int ans = 0;
	rep(i, n){
		if(p.at(i) == i+1){
			if(i != n-1){
				swap(p.at(i), p.at(i+1));
			}
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
  int n, k, x, y;
  int r = 0;
  cin >> n >> k >> x >> y;
  if (n>k) {
    r = k*x + (n-k)*y;
  } else {
    r = n*x;
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    
    double r;
    double a;
    double b;
    
    cin>>r;
    
    a=r*r*3.141592653589;
    b=2*r*3.141592653589;
    
    printf("%f %f\n",a,b);
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000007 //1000000000000000003
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  int N;
  cin>>N;

  set<int> se;

  int ored=0;

  rep(i,N){
    int a;
    cin>>a;

    if(a<400) se.insert(1);
    else if(a<800) se.insert(2);
    else if(a<1200) se.insert(3);
    else if(a<1600) se.insert(4);
    else if(a<2000) se.insert(5);
    else if(a<2400) se.insert(6);
    else if(a<2800) se.insert(7);
    else if(a<3200) se.insert(8);
    else ++ored;
  }

  cout<< max(1,(int)se.size())<<" "<< (int)se.size()+ored <<"\n";
}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
int main(void){
    using namespace std;
    static const int AbnormalValueMin = 1;
    static const int AbnormalValueMax = 100;
    int length =0;
    int breadth =0;
    cin >> length;
    cin >> breadth;
    /* Calculation  Area, perimeter */
    assert(AbnormalValueMin <= length && breadth <= AbnormalValueMax);
    cout << length*breadth << " " << (length+breadth)*2 << endl;
	
    return 0;
}

Measured memory_bytes: 3092
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>

using namespace std;

int main(){

	int n,a=1;
	cin >> n;
	for(int i = 6; 0 <= i; i--){
		for(int j = i; 0 < j; j--){
			a = a*2;
		}
		if( a <= n ){
			cout << a << endl;
			return 0;
		}
		a = 1;
	}

	return 0;
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self,size):
        self.parent=range(size)
        self.rank=[0]*size

    def findset(self,x):
        if self.parent[x]==x:
            return x
        else:
            self.parent[x]=self.findset(self.parent[x])
            return self.parent[x]

    def unite(self,x,y):
        x=self.findset(x)
        y=self.findset(y)
        if x==y:
            return
        if self.rank[x]<self.rank[y]:
            self.parent[x]=y
        else:
            self.parent[y]=x
            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def same(self,x,y):
        if self.findset(x)==self.findset(y):
            return True
        else:
            return False

def kruskal(v,e,edges):
    edges.sort()
    node=UnionFind(v)
    ret=0
    for i in xrange(e):
        cost,a,b=edges[i][0],edges[i][1],edges[i][2]
        if not node.same(a,b):
            ret+=cost
            node.unite(a,b)
    return ret

v,e=map(int,raw_input().split())
edges=[]
for i in xrange(e):
    s,t,w=map(int,raw_input().split())
    edges.append([w,s,t])
print(kruskal(v,e,edges))

Measured memory_bytes: 24720
H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
flag = 1
dx = [1,-1,0,0]
dy = [0,0,1,-1]
for i in range(H):
  for j in range(W):
    if A[i][j] =="#":
        flag2 = 0
        for k in range(4):
            if 0<= i+dx[k] <= H-1 and 0<= j+dy[k] <= W-1:
                if A[i+dx[k]][j+dy[k]] == "#":
                    flag2 = 1
        if not flag2:
            flag = 0
print("Yes" if flag else "No")


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

using namespace std;

int n, m, c;
int main()
{
  int res = 0;
  cin >> n >> m >> c;
  vector<int> b(m);
  for(auto &x: b){
    cin >> x;
  }
  for(int i = 1; i <= n; i ++){
   int sum = c;
   for(int j = 1; j <= m; j ++){
   		int x;
    	cin >> x;
     	sum += b[j - 1] * x;
   }
    res += (sum > 0);
  }
  cout << res << "\n";
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int S, W;
    cin >> S >> W;
    if (S > W) cout << "safe" << endl;
    else cout << "unsafe" << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>

int getGCD(int a,int b){
	int i,temp,r;
	
	if(a < b){
		temp = a;
		a = b;
		b = temp;
	}
	 r = a % b; 	
	while(r!=0){
    	a = b;
    	b = r;
    	r = a % b;
	}
	
	return b;
}

long getLCM(int a,int b){
	
	long lcm;
	int gcd = getGCD(a, b);
	lcm = ((long)a * b) / gcd;
		
	return lcm;
}

int main(void){
    int a,b;
	
	while(scanf("%d %d", &a, &b) != EOF){	
        printf("%d %lu\n", getGCD(a, b), getLCM(a, b));
    }
	
	return 0;
}

Measured memory_bytes: 600
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
const ll inf = 1e18;
const ll mod = 1e9 + 7;

ll pow (ll x, ll n){
    ll ans = 1;
    while(n>0){
        if(n & 1 == 1){
            ans *= x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

int c[3][3];
int main(){
    rep(i,3)    rep(j,3)    cin >> c[i][j];
    if(c[0][0]-c[1][0] == c[0][1]-c[1][1] && c[0][2]-c[1][2] == c[0][1]-c[1][1] && c[1][0]-c[2][0] == c[1][1]-c[2][1] && c[1][1]-c[2][1] == c[1][2]-c[2][2] ){
        cout << "Yes" << endl;

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


Measured memory_bytes: 256
import heapq

Q = int(input())
m = L = R = 0
l, r = [], []
n = 0
b = 0

for i in range(Q):
  query = list(map(int, input().split()))
  if len(query) == 3: # 更新クエリ
    b += query[2]
    new = query[1]
    if  n == 0:
      m = new
    elif n == 1:
      if new <= m:
        heapq.heappush(l, -new)
        heapq.heappush(r, m)
        L, R = new, m
        m = new
      else:
        heapq.heappush(l, -m)
        heapq.heappush(r, new)
        L, R = m, new
    elif n == 2:
      if new < m:
        m = -heapq.heappop(l)
        heapq.heappush(l, -new)
        L = new
      else:
        _r = heapq.heappop(r)
        if new < _r:
          m = new
          heapq.heappush(r, _r)
        else:
          m = _r
          heapq.heappush(r, new)
          R = new
    else:
      _l = - heapq.heappop(l)
      _r = heapq.heappop(r)
      if n%2:
        if new <= _l:
          heapq.heappush(l, -new)
          heapq.heappush(r, _r)
          heapq.heappush(r, m)
          m, L, R = _l, L+new, R+m
        elif new <= m:
          heapq.heappush(l, -_l)
          heapq.heappush(r, _r)
          heapq.heappush(r, m)
          m, L, R = new, L+new, R+m
        else:
          heapq.heappush(l, -_l)
          heapq.heappush(r, _r)
          heapq.heappush(r, new)
          L, R = L+m, R+new
      else:
        if new <= m:
          heapq.heappush(l, -_l)
          heapq.heappush(l, -new)
          heapq.heappush(r, _r)
          L += new - m
        elif new <= _r:
          heapq.heappush(l, -_l)
          heapq.heappush(l, -m)
          heapq.heappush(r, _r)
          m = new
        else:
          heapq.heappush(l, -_l)
          heapq.heappush(l, -m)
          heapq.heappush(r, new)
          m, R = _r, R+new-_r
    n += 1
  else: # 求値クエリ
    print(m, R-L+b)

Measured memory_bytes: 11332
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <functional>

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)

using namespace std;
using ll = long long;

int main() {
	string N;
	cin >> N;
	if ((N[0] == N[1]) && (N[1] == N[2])) {
		cout << "Yes" << endl;
		return 0;
	}
	if ((N[1] == N[2]) && (N[2] == N[3])) {
		cout << "Yes" << endl;
		return 0;	
	}
	cout << "No" << endl;
	return 0;
}

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

bool cmp(pair<int, int> p1, pair<int, int> p2)
{
  return p1.first > p2.first;
}

int main()
{
  int x, y, aa, bb, cc;
  cin >> x >> y >> aa >> bb >> cc;
  vector<pair<int, int>> v;
  int a[aa], b[bb], c[cc];
  for(int i = 0; i < aa; i++)
  {
    cin >> a[i];
    v.push_back({a[i], 1});
  }
  for(int i = 0; i < bb; i++)
  {
    cin >> b[i];
    v.push_back({b[i], 2});
  }
  for(int i = 0; i < cc; i++)
  {
    cin >> c[i];
    v.push_back({c[i], 3});
  }
  sort(v.begin(), v.end(), cmp);
  sort(a, a + aa, greater<int>());
  sort(b, b + bb, greater<int>());
  sort(c, c + cc, greater<int>());
  int x1 = 0, y1 = 0, z1 = 0;
  for(int i = 0; i < (aa + bb + cc); i++)
  {
    if(v[i].second == 1)
    {
      if(x1 < x)
        x1++;
    }
    else if(v[i].second == 2)
    {
      if(y1 < y)
        y1++;
    }
    else z1++;
    if(x1 + y1 + z1 == x + y)
    break;
  }
  //  cout << x1 << " " << y1 << " " << z1 << " ";
  long long sol = 0;
  for(int i = 0; i < x1; i++)
	sol += a[i];
  for(int i = 0; i < y1; i++)
    sol += b[i];
  for(int i = 0; i < z1; i++)
    sol += c[i];
  cout << sol;
  
   
    
  
  return 0;
}


Measured memory_bytes: 7408
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<double, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

void mul_mod(ll &a, ll b){
	a *= b;
	a %= MOD;
}

int main(void){
	ll n,m,d;
	cin >> n >> m >> d;
	printf("%.10lf\n",((m-1)*(n-d)*((d)?2.0:1.0)/(n*n)));
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,v,w,t,i;
	cin>>a>>v;
	cin>>b>>w;
	cin>>t;
	if(a<b)
	{
		if((a+v*t)>=(b+w*t))
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;
	}
	else
	{
		if((b-w*t)>=(a-v*t))
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		while (true) {
			String steps = sc.next();
			if (steps.equals("#")) break;
			int N = steps.length();
			int[][][] dp = new int[2][2][9];
			int t = 0;
			Arrays.fill(dp[t][0], 1 << 30);
			Arrays.fill(dp[t][1], 1 << 30);
			int start = steps.charAt(0) - '1';
			int sc = start % 3;
			for (int i = 0; i < 9; ++i) {
				if (i == 4) continue;
				int cc = i % 3;
				if (sc <= cc) {
					dp[t][0][i] = 0;
				}
				if (cc <= sc) {
					dp[t][1][i] = 0;
				}
			}
			for (int i = 1; i < N; ++i) {
				Arrays.fill(dp[1 - t][0], 1 << 30);
				Arrays.fill(dp[1 - t][1], 1 << 30);
				int prev = steps.charAt(i - 1) - '1';
				int next = steps.charAt(i) - '1';
				int nc = next % 3;

				// left-left
				for (int j = 0; j < 9; ++j) {
					if (j == 4) continue;
					int cc = j % 3;
					if (nc > cc) continue;
					dp[1 - t][0][j] = Math.min(dp[1 - t][0][j], dp[t][0][j] + 1);
				}
				// left-right
				for (int j = 0; j < 9; ++j) {
					if (j == 4) continue;
					int cc = prev % 3;
					if (nc > cc) continue;
					dp[1 - t][0][prev] = Math.min(dp[1 - t][0][prev], dp[t][1][j]);
				}
				// right-right
				for (int j = 0; j < 9; ++j) {
					if (j == 4) continue;
					int cc = j % 3;
					if (nc < cc) continue;
					dp[1 - t][1][j] = Math.min(dp[1 - t][1][j], dp[t][1][j] + 1);
				}
				// right-left
				for (int j = 0; j < 9; ++j) {
					if (j == 4) continue;
					int cc = prev % 3;
					if (nc < cc) continue;
					dp[1 - t][1][prev] = Math.min(dp[1 - t][1][prev], dp[t][0][j]);
				}
				t = 1 - t;
			}
			int ans = 1 << 30;
			for (int i = 0; i < 9; ++i) {
				if (i == 4) continue;
				ans = Math.min(ans, dp[t][0][i]);
				ans = Math.min(ans, dp[t][1][i]);
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 28372
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int limit, n, m, x;
        cin >> limit >> n >> m >> x;
        if(limit == 0)
            return 0;

        vector<vector<int> > dp(limit+1, vector<int>(x+1, -1));
        vector<int> a(n), b(n);
        for(int i=0; i<n; ++i){
            string s;
            cin >> s >> a[i] >> b[i];
            if(a[i] <= limit)
                dp[a[i]][0] = max(dp[a[i]][0], b[i]);

            for(int j=0; j<i; ++j){
                if(a[i] + a[j] <= limit)
                    dp[a[i]+a[j]][0] = max(dp[a[i]+a[j]][0], b[i]+b[j]);
            }
        }

        for(int i=0; i<m; ++i){
            string s;
            int c, d;
            cin >> s >> c >> d;
            for(int j=limit-c; j>=0; --j){
                for(int k=0; k<=x; ++k){
                    if(dp[j][k] == -1)
                        continue;
                    dp[j+c][min(k+1,x)] = max(dp[j+c][min(k+1,x)], dp[j][k]+d);
                }
            }
        }

        int ret = 0;
        for(int i=0; i<=limit; ++i)
            ret = max(ret, dp[i][x]);
        cout << ret << endl;
    }
}

Measured memory_bytes: 1336
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[10],b[10],ans=0; 
void fun(int a[10],int b[10]){
	do{
		int flag=1;
		for(int i=0;i<n;i++){
			if(a[i]!=b[i]){
				flag=0;
				ans++;
				break;
			}
		}
		if(flag) break;
	}while(next_permutation(a,a+n));
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	for(int i=0;i<n;i++){
		if(a[i]<b[i]){
			fun(a,b);
			break;
		}
		else if(a[i]>b[i]){
			fun(b,a);
			break;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
        using namespace std;
        typedef long long int ll;
        int main(){
            ll n; cin>>n; ll k; cin>>k;
            ll dp[n+1];
            ll h[n+1]; for(ll i=1;i<=n;i++) { cin>>h[i]; dp[i]=INT_MAX; }
            dp[1]=0; dp[2]=abs(h[2]-h[1]);
            for(ll i=3;i<=n;i++) {
                for(ll j=1;j<=k;j++)
                if(i-j>=1) dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]),dp[i]);
            }
            cout<<dp[n];
        }

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
int main(){
    long long int a,b,c,x,result;
    scanf("%lld %lld %lld",&a,&b,&x);
    if (a%x==0){
        c=a/x-1;
    }
    else{
        c=a/x;
    }
    result=b/x-c;
    printf("%lld",result);
    return 0;
}


Measured memory_bytes: 128
a = []
m = []
h = []
i = 0
j = 0
n = 0
count = 0

while True:
    a.append(input())
    if a[i] == "-":
        break

    inp = input().split()

    # if len(m) == 0:
    #     m.append(inp)
    # else:
    m.extend(inp)

    for j in range(int(m[i])):
        if j == 0:
            h.append(input().split())
        else:
            h[i].extend(input().split())
    
    i += 1

j = 0
for n in range(len(a) - 1):
    s = a[n]
    for j in range(int(m[n])):
        s = s[int(h[n][j]):] + s[:int(h[n][j])]

    print(s)



Measured memory_bytes: 5604
S = input()

for i, s in enumerate(S):

    if i % 2 == 0 and s not in ['R', 'U', 'D']:
        print('No')
        break
    elif i % 2 != 0 and s not in ['L', 'U', 'D']:
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
string s;
int ind;
bool flag;
map<string,int> at;
int num(void)
{
  string n="";
  while(ind<s.size() && '0'<=s[ind] && s[ind]<='9') n.push_back(s[ind++]);
  if(n=="") return 1;
  else return stoi(n);
}
int atom(void)
{
  string a="";
  a.push_back(s[ind++]);
  if(ind<s.size() && 'a'<=s[ind] && s[ind]<='z') a.push_back(s[ind++]);
  if(!at.count(a)){
    flag=false;
    return 0;
  }
  return at[a];
}
int mol(void)
{
  if(ind==s.size()) return 0;
  if('A'<=s[ind] && s[ind]<='Z'){
    int tmp=atom();
    int co=num();
    return tmp*co+mol();
  }else if(s[ind]=='('){
    ++ind;
    int tmp=mol();
    ++ind;
    int co=num();
    return tmp*co+mol();
  }
  return 0;
}
int main(void)
{
  for(;;){
    string na;
    cin >> na;
    if(na=="END_OF_FIRST_PART") break;
    int w;
    cin >> w;
    at[na]=w;
  }
  for(;;){
    cin >> s;
    if(s=="0") return 0;
    ind=0;
    flag=true;
    int answer=mol();
    if(flag) cout << answer << endl;
    else cout << "UNKNOWN" << endl;
  }
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
#define intl long long int 

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	intl a;
	cin>>a;
	cout<<a+a*a+(a*a*a)<<"\n";
}


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


int main(){
    
    std::cout << std::setprecision(14);
    
    int N, K;
    int count, score;
    double sum = 0;

    cin >> N >> K;
    
    for(int i = 1; i <= N; i++){
        score = i;
        count = 1;
        while(score < K){
            score *= 2;
            count *= 2;
    }
        sum += 1/((double)N) * 1/((double)count);
}
    cout << sum << endl;

     return 0;
  
}


Measured memory_bytes: 256
/*
 * ID: ITP1_8_A
 * Problem: Toggling the case of strings
 */

#include <stdio.h>

int main(void)
{
    char s[1200];

    fgets(s, sizeof(s) - 1, stdin);

    int i;
    for (i = 0; i < 1200 && s[i] != '\0'; i++)
        if (islower(s[i]))
            printf("%c", toupper(s[i]));
        else if (isupper(s[i]))
            printf("%c", tolower(s[i]));
        else
            printf("%c", s[i]);

    return 0;
}




Measured memory_bytes: 2048
import Data.List

sameAll :: String -> Bool
sameAll [x1, x2] = x1 == x2
sameAll (x1:remains@(x2:xs))
  | x1 /= x2  = False
  | otherwise = sameAll remains

main :: IO ()
main = do
  number <- readLn
  putStrLn $ head $ filter sameAll $ map show ([number..] :: [Int])

Measured memory_bytes: 508
N, K = map(int, input().split())
#ANSlist = [1]*(N)
ANSlist = []
ANS = 0

for i in range(K):
    I = input() #
    S = input().split()
    #print(ANSlist)
    for j in range(len(S)):
        if S[j] != " ":
            #ANSlist[int(S[j])-1] = 0
            if not S[j] in ANSlist:
                ANSlist.append(S[j])
                
            


'''for i in range(len(ANSlist)):
    if ANSlist[i] != 0:
        ANS += 1'''
ANS = N - len(ANSlist)
print(ANS)

Measured memory_bytes: 9060
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = (1ll << 31) - 1;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
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; }
struct SegmentTree {
	int n;
	vector<int>d;
	SegmentTree(int m) {
		for (n = 1; n < m; n <<= 1);
		d.assign(2 * n, INF);
	}
	void update(int a, int b, int x = -1, int k = 1, int l = 0, int r = -1) {
		if (r == -1)r = n;
		if (r <= a || b <= l)return;
		else if (a <= l&&r <= b) {
			if (x >= 0)d[k] = x;
		}
		else {
			if (d[k] != INF)d[2 * k] = d[2 * k + 1] = d[k], d[k] = INF;
			update(a, b, x, 2 * k, l, (l + r) / 2);
			update(a, b, x, 2 * k + 1, (l + r) / 2, r);
		}
	}
	int find(int i) {
		update(i, i + 1);
		return d[n + i];
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	SegmentTree seg(n);
	rep(i, 0, q) {
		int com; cin >> com;
		if (com) {
			int x; cin >> x;
			cout << seg.find(x) << endl;
		}
		else {
			int s, t, x; cin >> s >> t >> x;
			seg.update(s, t + 1, x);
		}
	}
	return 0;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<iostream>
#define pb push_back
#define fi first
#define se second
#define sz(x)  x.size()
#define cl(x)  x.clear()
#define all(x)  x.begin() , x.end()
#define r(x)  scanf("%d", &x)
#define rr(x , y)  scanf("%d%d" , &x , &y)
#define rd(x)  scanf("%lf" , &x)
#define rrd(x , y)  scanf("%lf%lf" , &x , &y)
#define rst(s)  scanf("%s" , s)
#define rl(x)  scanf("%lld" , &x)
#define rrl(x , y)  scanf("%lld%lld" , &x , &y)
#define w(x)  printf("%d" , x)
#define ww(x , y)  printf("%d %d" , x , y)
#define wl(x)  printf("%lld" , x)
#define wwl(x , y)  printf("%lld %lld" , x , y)
#define sp()  printf(" ")
#define en()  puts("")
#define rep(i , x , n)  for(int i = x ; i <= n ; i ++)
#define per(i , n , x)  for(int i = n ; i >= x ; i --)
#define mem0(x)  memset(x , 0 , sizeof(x))
#define mem_1(x)  memset(x , -1 , sizeof(x))
#define mem_inf(x)  memset(x , inf , sizeof(x))
#define mem__inf(x)  memset(x , -inf , sizeof(x))
#define p_queue priority_queue
#define debug(x)  cout << '*' << x << '\n'
#define ddebug(x , y)  cout << '*' << x << ' ' << y << '\n'
#define ios std::ios::sync_with_stdio(false) , cin.tie(0)
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std ;
using namespace __gnu_pbds ;
//mt19937  rnd(chrono::high_resolution_clock::now().time_since_epoch().count()) ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef long double ld ;
typedef pair<int , int> pii ;
typedef pair<ll , ll> pll ;
typedef pair<int , ll> pil ;
typedef pair<ll , int> pli ;
typedef pair<double , double> pdd ;
typedef pair<int , double> pid ;
const int inf = 0x3f3f3f3f ;
const ll linf = 0x3f3f3f3f3f3f3f3f ;
const int mod = 998244353 ;
const int maxn = 1e6 + 5 ;
const int maxm = 30 ;
const double eps = 1e-6 ;
const double pi = acos(-1.0) ;
ll s , a , b , c , d ;
map<ll , ll> mp ; 
ll cal(ll x)
{
	ll up = 1e18 ;
	if(x > up / d)  return 1e18 ;
	else  return x * d ;
}
ll dfs(ll n)
{
	if(n >= 5ll * s)  return 1e18 ;
	if(n == 0)  return 0 ;
	if(n == 1)  return d ;
	if(mp.count(n))  return mp[n] ;	
	ll ans = 1e18 ;
	ll l2 = (n / 2) * 2 ;
	ll r2 = ((n + 1) / 2) * 2 ;
	ll l3 = (n / 3) * 3 ;
	ll r3 = ((n + 2) / 3) * 3 ;
	ll l5 = (n / 5) * 5 ;
	ll r5 = ((n + 4) / 5) * 5 ;
	ans = min(ans , abs(n - l2) * d + min(a , cal(l2 / 2)) + dfs(l2 / 2)) ;
	ans = min(ans , abs(n - r2) * d + min(a , cal(r2 / 2)) + dfs(r2 / 2)) ;
	ans = min(ans , abs(n - l3) * d + min(b , cal(l3 / 3 * 2)) + dfs(l3 / 3)) ;
	ans = min(ans , abs(n - r3) * d + min(b , cal(r3 / 3 * 2)) + dfs(r3 / 3)) ;
	ans = min(ans , abs(n - l5) * d + min(c , cal(l5 / 5 * 4)) + dfs(l5 / 5)) ;
	ans = min(ans , abs(n - r5) * d + min(c , cal(r5 / 5 * 4)) + dfs(r5 / 5)) ;
	mp[n] = ans ;
	return ans ;
}
int main()
{
	int t ;
	r(t) ;
	while(t --)
	{
		rrl(s , a) , rrl(b , c) , rl(d) ;
		mp.clear() ;
		wl(dfs(s)) , en() ;
	}
	return 0 ;
} 

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl


const int inf = 1e9;
template<typename T> struct segtree {
    
    T merge(T x, T y) {
	return min(x,y);
    }
    int n;
    vector<int> t;
    void init(int n) {
	n += 10;
	this->n = n;
	t.resize(n*4);
    }
 
    void build(int v, int tl, int tr) {
	if (tl==tr) {
	    t[v] = inf;
	} else {
	    int tm = (tl+tr)/2;
	    build(2*v,tl,tm);
	    build(2*v+1,tm+1,tr);
	    t[v] = merge(t[2*v], t[2*v+1]);
	}
    }
 
    void upd(int v, int tl, int tr, int i, T dx) {
	if (tl == tr) {
	    t[v] = merge(t[v], dx);
	} else {
	    int tm = (tl+tr)/2;
	    if (i<=tm) {
		upd(2*v,tl,tm,i,dx);
	    } else {
		upd(2*v+1,tm+1,tr,i,dx);
	    }
	    t[v] = merge(t[2*v], t[2*v+1]);
	}
    }
 
    T qry(int v, int tl, int tr, int l, int r) {
	if (l>tr || r<tl) {
	    return inf;
	}
	if (l <= tl && tr <= r) {
	    return t[v];
	}
	int tm = (tl+tr)/2;
	return merge(qry(2*v,tl,tm,l,r), qry(2*v+1,tm+1,tr,l,r));
    }
};



const int maxn = 1e6 + 5;


int n;
int b[maxn];
vector<int> iv[maxn];

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

    cin>>n;
    int b0=0;
    
    for (int i=0; i<n; i++) {
	cin>>b[i];
	if (b[i]==0) {
	    b0++;
	    b[i]=-1;
	}
    }

    segtree<int> t;
    t.init(n+10);
    t.build(1,1,n+1);


    int q; cin>>q;
    while (q--) {
	int l,r;
	cin>>l>>r;
	--l;
	// [l,r)
	iv[l].push_back(r);
    }


    // Penalty: count of a[i]!=b[i] = count of (0,1) and (1,0)
    
    // = (0,1) + ((_,0) - (0,0))
    // (_, 0) is constant, and we store it as b0.

    // So actually, our goal is to minimize (0,1) - (0,0)
    // We set b[i]=1 to +1, and b[i]=0 to -1 to reflect this.

    // With no intervals, dp[i]=dp[i-1]+b[i-1].

    
    // When using an interval, [l,r), dp[r] = min(dp[l],dp[l+1]....dp[r-1]).
    // [l,r) will create 2 cases (1,1) and (1,0). Obviously we're ok with (1,1), but (1,0) increases the hamming distance,
    // and we have already accounted for those with b0.
    // We can freely take any dp[l],dp[l+1]...dp[r-1] because we only would have updated those with another interval,
    // which just means we're continuing the interval to r. In the case of dp[l], [l,r) is disjoint with it, so it's still fine.





    // dp[i]: min penalty considering first i terms of b.
    auto qry = [&](int l, int r) {
	return t.qry(1,1,n+1,l+1,r+1);
    };


    auto upd = [&](int i, int val) {
	t.upd(1,1,n+1,i+1,val);
    };


    
    for (int i=0; i<=n; i++) {
	if (i>0) {
	    upd(i, qry(i-1,i-1) + b[i-1]);
	} else {
	    upd(i, 0);
	}
	for (int r: iv[i]) {
	    upd(r, qry(i,r-1));
	}
    }

    int res = b0+qry(n,n);
    cout<<res<<endl;
    
    
    return 0;
}


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

main(){
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    ll wakemin = h1*60 + m1;
    ll bedmin = h2*60 + m2;
    ll ans = ((bedmin - wakemin)- k);
    if(ans<0) cout<<"0";
    else cout<<ans;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(){
  int n,i,j,max,d[1500];
  for(i=0;i<1200;i++)d[i]=i*i*i;
  while(scanf("%d",&n),n){
    for(i=max=1;i<n;i++){
      for(j=1;d[i]+d[j]<d[n];j++){
	if(max<d[i]+d[j])max=d[i]+d[j];
      }
    }
    printf("%d\n",d[n]-max);
  }
  return 0;
}

Measured memory_bytes: 604
n,m,q = gets.chomp.split(" ").map(&:to_i)
a = Array.new(n+1).map{Array.new(n+1,0)}
m.times do
  l,r = gets.chomp.split(" ").map{|i|i.to_i-1}
  a[l+1][r] += 1
end
for i in 0..n
  (n-1).downto(0) do |j|
    a[i][j] += a[i][j+1]
  end
end
for j in 0..n
  for i in 1..n
    a[i][j] += a[i-1][j]
  end
end
q.times do
  l,r = gets.chomp.split(" ").map{|i|i.to_i-1}
  puts a[n][0]+a[l][r+1]-a[n][r+1]-a[l][0]
end

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

namespace ConsoleApp2
{
    class Program
    {
        static public long aaa = 1000000007;

        static void Main(string[] args)
        {
            String S = Console.ReadLine();

            int ans;
            if (S == "SUN") {
                ans = 7;
            } else if(S == "MON"){
                ans = 6;
            } else if (S == "TUE") {
                ans = 5;
            } else if (S == "WED") {
                ans = 4;
            } else if (S == "THU") {
                ans = 3;
            } else if (S == "FRI") {
                ans = 2;
            } else if (S == "SAT") {
                ans = 1;
            } else {
                ans = 0;
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int W = sc.nextInt();
    int H = sc.nextInt();
    int N = sc.nextInt();
    
    int l = 0;
    int r = W;
    int b = 0;
    int t = H;
    
    for (int i = 0; i < N; i++) {
      int x = sc.nextInt();
      int y = sc.nextInt();
      int a = sc.nextInt();
      if (a == 1) {
        l = Math.max(l, x);
      } else if (a == 2) {
        r = Math.min(r, x);
      } else if (a == 3) {
        b = Math.max(b, y);
      } else { // a == 4
        t = Math.min(t, y);
      }
    }
    int w = Math.max(r-l, 0);
    int h = Math.max(t-b, 0);
    
    System.out.println(w*h);
  }
}

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

long long gcd(long long a, long long b)  
{  
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
}  
  
long long lcm(long long a, long long b)  
{  
    return (a * b) / gcd(a, b);  
}

int main()
{
	long long a, b, c, d;
	cin >> a >> b >> c >> d;

	long long x = b / c - a / c + ((a % c)? 0 : 1);
	long long y = b / d - a / d + ((a % d)? 0 : 1);

	long long kpk = lcm(c, d);
	long long z = b / kpk - a / kpk + ((a % kpk)? 0 : 1);

	cout << b - a + 1 - x - y + z << endl;

	return 0;
}
 
/* g++ wtf.cpp -o wtf -std=c++11 */

Measured memory_bytes: 256
N = int(input())
h = list(map(int,input().split()))
dp = [0 for _ in range(N)]
dp[0] = 0
dp[1] = abs(h[1]-h[0])
cost = h
for i in range(1,N-1):
	dp[i+1] = min(dp[i]+abs(cost[i+1]-cost[i]),\
	dp[i-1]+abs(cost[i+1]-cost[i-1]))
print(dp[-1])

Measured memory_bytes: 13928
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

const mod = 1000000007

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	getInt()
	s := getString()
	a := make(map[byte]int)
	for _, v := range s {
		a[byte(v)]++
	}

	ans := 1
	for _, v := range a {
		t := v + 1
		ans = (ans * t) % mod
	}
	out(ans - 1)
}


Measured memory_bytes: 1024
import itertools
while True:
    n ,x = map(int, input().split())
    if n == 0 and x == 0:
        break
    L = [i+1 for i in range(n)]
    cnt = 0
    for i in itertools.combinations(L, 3):
        if sum(i) == x:
            cnt += 1
    print(cnt)


Measured memory_bytes: 5644
#include <bits/stdc++.h>
#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()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	if (a.front() > 0) {
		printf("%d\n", -1);
		return 0;
	}
	int prev = a[n - 1];
	ll ans = 0;
	for (int i = n - 1; i >= 0; --i) {
		if (a[i] + 1 < prev) {
			printf("%d\n", -1);
			return 0;
		}
		if (a[i] + 1 != prev) ans += a[i];
		prev = a[i];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
#include<math.h>


void KochCurve( double n, double px, double py, double px2, double py2 )
{
	double side, side2, h;
	double sx,sy,ux,uy,tx,ty;
	
	sx=sy=ux=uy=tx=ty=0.0;
	if( py == py2 ) {
		if( px < px2 ) {
			side=px2-px;
			side/=3;
			side2=side/2;
			h=sqrt( side*side-side2*side2 );	
			
			sx=px+side;
			ux=sx+side2;
			tx=sx+side;
			
			sy=py;
			uy=py+h;
			ty=py2;
		} else {
			side=px-px2;
			side/=3;
			side2=side/2;
			h=sqrt( side*side-side2*side2 );	
			
			sx=px-side;
			ux=sx-side2;
			tx=sx-side;
			
			sy=py;
			uy=py-h;
			ty=py2;		
		}
	} else if( px < px2 ) {
		if( py < py2 ){
			side=px2-px;
			side/=3;
			h=(py2-py)/3;	
				
			sx=px+side;
			ux=px;
			tx=sx+side;
	
			sy=py+h;
			ty=uy=sy+h;
		} else {
			side=px2-px;	
			side/=3;
			h=(py-py2)/3;	
				
			sx=px+side;
			ux=px2;
			tx=sx+side;
	
			sy=uy=py-h;	
			ty=uy-h;
		}
	} else if( px2 < px ) {
		if( py < py2 ) {
			side=px-px2;	
			side/=3;
			h=(py2-py)/3;	
				
			sx=px-side;
			ux=px2;
			tx=sx-side;
	
			uy=sy=py+h;
			ty=py+h*2;
		} else {
			side=px-px2;	
			side/=3;
			h=(py-py2)/3;	
				
			sx=px-side;
			ux=px;
			tx=sx-side;
	
			sy=py2+2*h;
			ty=uy=py2+h;		
		}
	}

	if( 1 < n ) {
		KochCurve( n-1, px, py, sx, sy );
	}
	printf( "%.8f %.8f\n", sx, sy );
	if( 1 < n ) {
		KochCurve( n-1, sx, sy, ux, uy );
	}
	printf( "%.8f %.8f\n", ux, uy );
	if( 1 < n ) {
		KochCurve( n-1, ux, uy, tx, ty );
	}
	printf( "%.8f %.8f\n", tx, ty );
	if( 1 < n ) {
		KochCurve( n-1, tx, ty, px2, py2 );
	}

	if( 0 == n ) { 
		return;
	} 
}


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

 	printf( "%.8f %.8f\n", 0.0, 0.0 );
 	if( 0 < n ) {
    	KochCurve( n, 0.0, 0.0, 100.0, 0.0 );
    }
	printf( "%.8f %.8f\n", 100.0, 0.0 );
	   
    return 0;
}

Measured memory_bytes: 644
#include<stdio.h>

typedef struct{
  int num, id;
  char cccc;
} card;

void swap(card *a,card* b){
    card t=*a;
    *a=*b;
    *b=t;
}

int partition(card *A,int p,int r){
    int x=A[r].num;
    int i=p-1;
    int j;
    for(j=p;j<r;j++){
        if(A[j].num<=x){
            i=i+1;
            swap(&A[i],&A[j]);
        }
    }
    swap(&A[i+1],&A[r]);
    return i+1;
}

void quickSort(card *A,int p,int r){
    if(p<r){
        int q=partition(A,p,r);
        quickSort(A,p,q-1);
        quickSort(A,q+1,r);
    }
}

int isStable(card *a,int n){
    int i;
    for(i=0;i<n-1;i++){
        if(a[i].num==a[i+1].num && a[i].id>a[i+1].id)   return 0;
    }
    return 1;
}

int main(void){
    int n,i;
    card A[100001];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf(" %c %d",&A[i].cccc,&A[i].num);
        A[i].id=i;
    }

    quickSort(A,0,n-1);

    if(isStable(A, n))
        printf("%s\n","Stable");
    else  printf("%s\n","Not stable");

    for(i=0;i<n;i++)
        printf("%c %d\n",A[i].cccc,A[i].num);

    return 0;
}



Measured memory_bytes: 2912
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;

/*
ll mod(ll n, ll m) {
	n -= (n / m)*m;
	return n;
}
ll loop(ll n, ll m, ll k) {
	if (k == 1) {
		return n % m;
	}
	else if (k % 2 == 0) {
		ll t = loop(n, m, k / 2);
		return t * t%m;
	}
	else {
		return loop(n, m, k - 1)*n%m;
	}
}
*/
int main() {
	int A, B, C, K;
	//int A[100];
	cin >> A >> B >> C >> K;
	ll res;
	//long long int res = pow(2,3);
	/*
	N^P ≡res (mod M)
	10^14 <= 2^(14*log10)<=2^43
	15 = 8 + 4 + 2 + 1
	6  = 4 + 2
	7  = 4 + 2 + 1
	*/
	res = max({ A, B, C })*(pow(2, K) - 1) + A + B + C;
	//cout << mod(134,10) << endl;
	cout << res << endl;
	return 0;

}


Measured memory_bytes: 256
#include <stdio.h>

int n;

int main(){
  int i, r;
  scanf("%d", &n);
  r = 0;
  for(i=0;i<n;i++){
    int x;
    scanf("%d", &x);
    r += __builtin_ctz(x);
  }
  printf("%d\n", r);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main()
{
   char S[4];

   scanf("%s",S);

   if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2])
      printf("Yes\n");
   else if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1])
      printf("Yes\n");
   else if  (S[0] == S[3] && S[1] == S[2] && S[0] != S[1])
      printf("Yes\n");
   else
      printf("No\n");

   return 0;
}


Measured memory_bytes: 128