akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        char[]s=sc.next().toCharArray();
        int n=s.length;
        int c[]=new int[n];
        char a='R';
        ArrayList<Integer>aaa=new ArrayList<Integer>();
        aaa.add(0);
        int ind=0;
        for(int i=0;i<n;i++){
            if(a==s[i]){
                ind++;
            }
            else{
                a=(a=='R')?'L':'R';
                aaa.add(ind);
                ind++;
            }
        }
        if(aaa.size()%2==0)aaa.add(ind);
        for(int i=0;i<aaa.size()/2;i++){
            int x2=aaa.get(2*i+1);
            int y=aaa.get(2*i+2)-x2;
            int x=x2-aaa.get(2*i);
            if(x%2==0){
                if(y%2==0){
                    c[x2-1]=(x+y)/2;
                    c[x2]=(x+y)/2;
                }else{
                    c[x2-1]=(x+y)/2;
                    c[x2]=(x+y)/2+1;
                }
            }
            else{
                if(y%2==0){
                    
                    c[x2-1]=(x+y)/2+1;
                    c[x2]=(x+y)/2;
                }else{
                    c[x2-1]=(x+y)/2;
                    c[x2]=(x+y)/2;
                }
            }
        }
        for(int i=0;i<n;i++)
        System.out.print(c[i]+" ");
    }
}

Measured memory_bytes: 43604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;



int main(){
    int H, W; cin >> H >> W;
    ll SUM = 0;
    vector<vector<int>> A(H, vector<int>(W)); 
    for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) {cin >> A[i][j]; SUM += A[i][j];}
    int grid[H+1][W+1];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(A[i][j] % 2 == 1) grid[i][j] = 1;
            else grid[i][j] = 0;
        }
    }
    vector<int> B, C, D, E;
    ll cnt=0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(A[i][j] >= 0){
            if(grid[i][j] == 1){
                if(j != W-1) {
                    A[i][j]--;
                    A[i][j+1]++;
                    grid[i][j+1] = A[i][j+1] % 2;
                    cnt++;
                    B.push_back(i+1);
                    C.push_back(j+1);
                    D.push_back(i+1);
                    E.push_back(j+2);
                    //cout << i+1 << " " << j+1 << " " << i+1 << " " << j+2 << endl;  
                }
                if(j == W-1 && i != H-1){
                    A[i][j]--;
                    A[i+1][j]++;
                    grid[i+1][j] = A[i+1][j] % 2;
                    cnt++;
                    B.push_back(i+1);
                    C.push_back(j+1);
                    D.push_back(i+2);
                    E.push_back(j+1);
                    //cout << i+1 << " " << j+1 << " " << i+2 << " " << j+1 << endl;  
                }
            }
            }
        }
    }
    cout << cnt << endl;
    for(int i = 0; i < cnt; i++) cout << B[i] << " " << C[i] << " " << D[i] << " " << E[i] << endl; 

}



Measured memory_bytes: 6120
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main() {
  int n = in();
  vector<int> a(n);
  cin >> a;
  int q = in();
  while (q--) cout << lower_bound(all(a), in()) - a.begin() << endl;
}



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

int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}

int main(void){
    int sx,sy,tx,ty;

    scanf("%d %d %d %d%*c",&sx,&sy,&tx,&ty);

    for(int i=sx;i<tx;i++)
        putchar('R');
    for(int i=sy;i<ty;i++)
        putchar('U');
    
    for(int i=sx;i<tx;i++)
        putchar('L');
    for(int i=sy;i<ty;i++)
        putchar('D');
    
    putchar('D');
    for(int i=sx;i<tx+1;i++)
        putchar('R');
    for(int i=sy;i<ty+1;i++)
        putchar('U');
    putchar('L');

    putchar('U');
    for(int i=sx;i<tx+1;i++)
        putchar('L');
    for(int i=sy;i<ty+1;i++)
        putchar('D');
    putchar('R');
    putchar('\n');

    return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int AB,BC,CA;
  cin>>AB>>BC>>CA;
  cout<<AB*BC/2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
typedef long long ll;
using namespace std;
int n,x[100005],y[100005],d[100005];
char ch[]="RLUD";
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
const unsigned int mo=1e9+7;
double ans=9e99;
bool tra(long double t,int md){
	double max=x[0]+t*dx[d[0]],mix=max,may=y[0]+t*dy[d[0]],miy=may;
	ll nmax=0,nmix=0,nmay=0,nmiy=0;
	for(int i=1;i<n;++i){
		long double X=x[i]+t*dx[d[i]],Y=y[i]+t*dy[d[i]];
		if(X>max)nmax=i,max=X;
		if(X<mix)nmix=i,mix=X;
		if(Y>may)nmay=i,may=Y;
		if(Y<miy)nmiy=i,miy=Y;
	}
	//cout<<max<<may<<mix<<miy<<endl;
	ans=min(ans,(max-mix)*(may-miy));
	int p;
	if(md&4) md-=4,p=dx[d[nmax]]-dx[d[nmix]];
	else p=dy[d[nmay]]-dy[d[nmiy]];
	return p<md-1;
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;++i){
		char tp;
		scanf("%d%d %c",x+i,y+i,&tp);
		for(int j=0;j<4;++j){
			if(ch[j]==tp){
				//cout<<j<<endl;
				d[i]=j;break;
			}
		}
	}
	for(int mode=0;mode<8;++mode){
		long double l=0,r=2e8;
		for(int i=0;i<130;++i){
			double mid=(l+r)/2;
			//printf("%.39lf\n",mid);
			if(tra(mid,mode))l=mid;
			else r=mid;
			//printf("%.39lf\n",(double)ans);
		}
	}
	printf("%.17lf\n",ans);
	return 0;
} 
/*
3
-1000 0 U
1000 0 L
-1900 0 R
*/

Measured memory_bytes: 1408
import java.util.*;

public class Main{
    Scanner sc = new Scanner(System.in);

    public Main(){
        int j = sc.nextInt();
        int y = sc.nextInt();
        parse(0, 0, j, y, "");
    }

    void parse(int a, int b, int j, int y, String p){
        if ( a == j && b == y ){
            System.out.println(p);
            return;
        }
        if ( a >= 5 && b <= 3 ) return;
        if ( b >= 5 && a <= 3 ) return;
        if ( a+1 <= j && b <= y ) parse(a+1, b, j, y, p+"A");
        if ( a <= j && b+1 <= y ) parse(a, b+1, j, y, p+"B");
    }

    public static void main(String[] a){ new Main(); }
}




Measured memory_bytes: 26508
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
struct edge {
    int to; 
    int weight;
    edge(int t, int w) : to(t),weight(w) {}
};
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int main(){

    int n; cin >> n;
    ll ans = -1;
    int pre = -1;
    bool ok = true;
    rep(i,n){
        int a; cin >> a;
        if(a > pre+1) ok = false;
        else if(a == pre+1) ans++;
        else ans += a;
        pre = a;
    }
    ok? cout << ans << endl : cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main() {
  char c; cin >> c;
  cout << char(c + 1) << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

#define P 998244353
#define N_MAX 10000000
typedef long long int ll;
ll fac[N_MAX+1];
ll inv[N_MAX+1];
ll finv[N_MAX+1];

ll comb(ll n, ll k){
  if(n<0||k<0||n<k) return 0;
  return (((fac[n]*finv[n-k])%P)*finv[k])%P;
}

void init(){
  fac[0] = finv[0] = fac[1] = finv[1] = inv[1] = 1;
  for(int i = 2; i <= N_MAX; i++){
    fac[i] = (fac[i-1]*i)%P;
    inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
    finv[i] = (finv[i-1]*inv[i])%P;
  }
}
ll pp(ll a, ll b){
  return (a * b)%P;
}
ll mpow(ll a, ll b, ll p = -1){
  ll ret = 1, num = a;
  if(p==-1){
    while(b>0){
      if(b%2) ret *= num;
      num = num * num;
      b /= 2;
    }
  }else{
    while(b>0){
      if(b%2) ret = (ret*num)%p;
      num = (num*num)%p;
      b /= 2;
    }
  }
  return ret;
}

int main(int argc, char const *argv[]) {
  ll n, m, k;std::cin >> n >> m >> k;
  init();
  ll ans = 0;
  // m^i *
  for(ll i=n-k;i<=n;i++){
    ll amari = n - i;
    ll tmp = (m * mpow(m-1, i-1, P))%P;
    tmp = pp(tmp, comb(i+amari-1, amari));
    //std::cout << i << " " << tmp << '\n';
    ans = (ans + tmp)%P;
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 237552
import sys
from collections import defaultdict
def main():
    input = sys.stdin.readline
    N = int(input())
    d = defaultdict(int)

    for n in range(1, N+1):
        s = str(n)
        head, tail = int(s[0]), int(s[-1])
        d[(head, tail)] += 1

    ans = 0
    for i in range(1,10):
        for j in range(1,10):
            ans += d[(i,j)] * d[(j,i)]
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 41324
/*
 * Created by Dipta Das on 14-05-2019
 * Title: 
 * Problem Link: 
 * Editorial: 
 * Source Code: 
 * Comments: 
*/

#include <bits/stdc++.h>
#include <stdio.h>
#define fin freopen("input", "r", stdin)
#define whatis(x) cerr << #x << ": " << x << endl;

using namespace std;
using ll = long long;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    int cnt1 = 0, cnt2 = 0;

    string s;
    cin >> s;
    
    int n = s.length();

    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0) {
            if (s[i] == '1') ++cnt1;
            else ++cnt2;
        } else {
            if (s[i] != '1') ++cnt1;
            else ++cnt2;
        }
    }

    cout << min (cnt1 , cnt2) << endl;




    return 0;
}



Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

#include<stdio.h>
#include<stdlib.h>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

	int X, Y;
	cin >> X >> Y;

	for (int i = 0; i <= X; i++) {
		int t = i;
		int k = X - i;

		if (t * 2 + 4 * k == Y) {
			cout << "Yes" << endl;
			goto EndPoint;
		}
	}
	cout << "No" << endl;

EndPoint:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG

	return 0;
}




Measured memory_bytes: 3156
/*  ex6_2
    Graku   */
#include<stdio.h>
#include<string.h>

int main(void) {
    char str[101]; //max is 100

    scanf("%100s", str);

    //begin of "str", length of "str" minus 2, end of "str"
    printf("%c%d%c\n", str[0], strlen(str) - 2, str[strlen(str) - 1]);

    return 0;
}

Measured memory_bytes: 128
import collections
import bisect
N = int(input())
S = input()
ans = 0
table = collections.defaultdict(list)
for i, x in enumerate(S):
    table[x].append(i)
R = len(table["R"])
G = len(table["G"])
L = len(table["B"])

s = set(table["B"])

for i in range(R):
    for j in range(G):
        x = table["R"][i]
        y = table["G"][j]
        if x > y:
            x, y = y, x
        ans += L
        if 2*y - x in s:
            ans -= 1
        if 2*x - y in s:
            ans -= 1
        if (x+y) % 2 == 0 and (x+y)//2 in s:
            ans -= 1

print(ans)


Measured memory_bytes: 9668
import math
 
n = input("")
a = input("")
b = input("")
c = input("")
d = input("")
e = input("")
 
list_i = [float(a),float(b),float(c),float(d),float(e)]
 
num = min(list_i)
count = n / num
 
print(int(math.ceil(count+4)))

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

using namespace std;
typedef long long ll;

const int N = 1e5 + 10 , OO = 0x3F3F3F3F;


string w[] = {"Sunny" , "Cloudy" , "Rainy"};


int main()
{

    string s;

    cin >> s;
    for(int i = 0 ; i < 3 ; ++i){
        if(w[i] == s)
            cout << w[(i+1)%3] << "\n";
    }





    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll long long
ll a[100000][20],vs[2000000],d[4000000],ar[20][20],c[20];
vector<ll> v[40];
queue<ll>q;

int main()
{
    IO;
    ll i, j, n, m,mm=1e6, k=1, t, ans=0,l=1, g, p,kk=0;
    cin>>n>>m>>k;
    for(i=1; i<=n; i++) l*=2;
    for(i=1; i<=n; i++){
            cin>>c[i];
        for(j=1; j<=m; j++) cin>>ar[i][j];
    }
    for(i=1; i<=l; i++){
        g=i; j=1;
        while(g!=0){
            a[i][j]=(g%2);
            g/=2; j++;
        }
    }
    for(i=1; i<=l; i++){
        for(j=1; j<=n; j++)
            d[i]+=a[i][j]*c[j];
    }
    ll mn=INT_MAX,sum=0;kk=1;

    for(i=1; i<=l; i++){
        ll kkk = 1;
        for(p=1; p<=m; p++){
           mm=0;
        for(j=1; j<=n; j++)
        {
            mm+=a[i][j]*ar[j][p];
        }
        if(mm<k)   kkk=0;
    }
    if(kkk==1) { mn=min(mn,d[i]); kk=0;}
    }
    if(kk==1) return cout<<-1<<endl,0;
    cout<<mn<<endl;
    return 0;
}


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

int main()
{
	int f,n;
	cin >> n;
	while(n!=0)
	{ 
		if(n>=1  &&  n<=999)
		{
			cout << "ABC" << endl;
			return 0;
		}
		else{
			cout << "ABD" << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
def selection_sort(N, A):
    num = 0
    for i in range(N):
        minimum = A[i]
        flag = False
        for j in range(i+1, N):
            if A[j] < minimum:
                minimum = A[j]
                index = j
                flag = True
        if flag:
            A[i], A[index] = A[index], A[i]
            num += 1
    return [num, *A]

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    ans = selection_sort(N, A)
    print(*ans[1:])
    print(ans[0])


Measured memory_bytes: 5608
#include<iostream>
#include<string>
#include<vector>

using namespace std;

typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)

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

	string s1, s2;
	cin >> s1 >> s2;

	vector<vector<ll > > dp(s1.size()+1, vector<ll >(s2.size()+1));

	rep(i, s1.size()+1)
	{
		dp[i][0] = i;
	}
	rep(i, s2.size()+1)
	{
		dp[0][i] = i;
	}

	for (int i = 1; i <= s1.size(); i++)
	{
		for (int j = 1; j <= s2.size(); j++)
		{
			int c;
			c = !(s1[i-1] == s2[j-1]);
			dp[i][j] = min(dp[i - 1][j] + 1, min(dp[i][j - 1] + 1, dp[i - 1][j - 1] + c));
		}
	}

	cout << dp[s1.size()][s2.size()] << endl;
	return 0;
}


Measured memory_bytes: 10724
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n;
    cout << (1000 - n % 1000) % 1000 << endl;
}


Measured memory_bytes: 3616
N=int(input())
a=list(map(int,input().split()))
b=list(set(a))
b.sort()
if len(b) == 3 and b[0] ^ b[1] == b[2] and a.count(b[0]) == a.count(b[1]) == a.count(b[2]):
    print('Yes')
elif b==[0]:
    print('Yes')
elif len(b)==2 and b[0]==0 and 2*a.count(b[0])==a.count(b[1]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 14116
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();


        if(S.length()==0){
            System.out.println(0);
        }

        int count1=0;
        //010101
        for (int i = 0; i < S.length(); i++) {
            char c = S.charAt(i);
            if(c != '0' && i%2==0){
                count1++;
            }
            if(c != '1' && i%2==1){
                count1++;
            }
        }
        int count2=0;
        //10101
        for (int i = 0; i < S.length(); i++) {
            char c = S.charAt(i);
            if(c != '0' && i%2==1){
                count2++;
            }
            if(c != '1' && i%2==0){
                count2++;
            }
        }


        System.out.println(Math.min(count1,count2));

    }
}


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

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

  for (int i = 0; i < S.size(); i++) {
    if (i % 2 == 0) {
      // iは偶数だが、文字は奇数
      if (S.at(i) != 'R' and S.at(i) != 'U' and S.at(i) != 'D') {
        cout << "No" << endl;
        return 0;
      }
    } else {
      if (S.at(i) != 'L' and S.at(i) != 'U' and S.at(i) != 'D') {
        cout << "No" << endl;
        return 0;
      }
    }
  }

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

Measured memory_bytes: 256
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define jkl int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7

int main(){
    ll n, t, a;
    ll h[1002];
    cin >> n >> t >> a;
    REP(i, n)cin >> h[i];
    double diff = mod;
    ll diff_i = -1;
    double tmp;
    REP(i, n){
        tmp = t - h[i] * 0.006;
        if(abs(a - tmp) < diff){
            diff = abs(a - tmp);
            diff_i = i;
        }
    }
    print(diff_i + 1);
}

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

using namespace std;
const int N = 1e6 + 77 , Mod = 1e9 + 7;
long long x;

int main(){
	cin >> x;
	cout << (int)((sqrt(1 + 8 * x) + 1) / 2 - 1e-9);
	
	return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout <<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;

  VAR(int, n);
  VEC(int, a, n);
  map< int, int > mp;
  REP(i, n) {
    mp[a[i]]++;
  }

  bool ok = true;
  EACH(mi, mp) {
    if (mi.first == 0) ok &= (mi.second == 1);
    else ok &= (mi.second == 2);
  }

  auto pow = [&](int x, int n) {
    int res = 1;
    while (n > 0) {
      if (n & 1) (res *= x) %= MOD;
      (x *= x) %= MOD;
      n >>= 1;
    }
    return res % MOD;
  };
  
  int ans = ok ? pow(2, n / 2) : 0;
  OUT(ans)BR;
  
  return 0;
}


Measured memory_bytes: 4992
function main(input) {
  const args = input.split('\n');
  const ary1 = args[0].split(' ');
  const N = parseInt(ary1[0], 10);
  const K = parseInt(ary1[1], 10);
  const ary2 = args[1].split(' ').map(n => parseInt(n)).sort((a, b) => {return b - a});
  let ans = 0;
  
  for(let i = 0; i < K; i++) {
    ans += ary2[i];
  }
  
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29580
#include <stdio.h>

int main(void) {
	int i, p, h, w;
	while (h+w) {
		scanf("%d %d", &h, &w);
		if (h+w!=0) {
			for (i=0;i<h;i++) {
				for (p=0;p<w;p++) {
					if (i==0||i==h-1||p==0||p==w-1) printf("#");
					else printf(".");
				}
				printf("\n");
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <vector>

using namespace std;

int cnt = 0;
int m;
std::vector<int> G;

void InsertarionSort(int A[], int n, int g) {
    for(int i = g; i < n; i++) {
        int key = A[i];
        int j = i - g;
        while(j >= 0 && A[j] > key) {
            A[j+g] = A[j];
            j-= g;
            cnt++;
        }
        A[j+g] = key;
    }
}

void ShellSort(int A[], int n) {
    int h = 1;
    while(h <= n) {
        G.insert(G.begin(), h);
        h = 3 * h + 1;
    }
    m = int(G.size());

    for(int i = 0; i < m; i++) InsertarionSort(A, n, G[i]);
}

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

    ShellSort(A, n);

    cout << m << endl;
    for(int i = 0; i < m; i++) {
        if(i != 0) cout << " ";
        cout << G[i];
    }
    cout << endl;
    cout << cnt << endl;
    for(int i = 0; i < n; i++) cout << A[i] << endl;

}


Measured memory_bytes: 7080
N = $stdin.gets.chomp.to_i

MARCH = ['M', 'A', 'R', 'C', 'H']

num = {}
MARCH.each {|c| num[c] = 0}

N.times do |_|
    init = $stdin.gets[0]
    num[init] += 1 if MARCH.include?(init)
end

sum = 0
MARCH.combination(3) do |arr|
    sum += num[arr[0]] * num[arr[1]] * num[arr[2]]
end

print sum

Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;

int k, s;

int main(){
  cin >> k >> s;
  int ans = 0;
  for(int x = 0; x <= k; x++){
    for(int y = 0; y <= k; y++){
      if(x + y > s || x + y + k < s) continue;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 100010
#define inf 1e9

int main()
{

    ll n;
    cin >> n;
    double sum=0;
    vector<double> v;
    for(ll i = 0; i<n;i++)
    {

        double x;
        cin >> x;
        v.pb(x);
    }
    sort(v.begin(), v.end());
    sum = (v[0]+v[1])/2.0;
    for(ll i = 2; i < v.size(); i++)
    {

        sum = (sum+v[i])/2.0;
    }
    printf("%.10lf\n", sum);
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 100005

ll a , b;

int main()
{
    _FastIO;
    cin >> a;
    string s;
    cin >> s;
    b = int(s[0] - 48);
    b *= 10;
    b += int(s[2] - 48);
    b *= 10;
    b += int(s[3] - 48);
    ll ans = (a * b) / 100;
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
using ll = long long;

bool between(ll x, ll y1, ll y2){
    if(y1 > y2) swap(y1, y2);
    y1++; y2--;
    if(!(y1 <= y2)) return false;

    if(x % 3 == 1){
        if(y2 - y1 > 3) return true;
        for(ll y=y1;y<=y2;y++) if(y % 3 == 1) return true;
    }

    return false;
}

ll get_extra(ll x1, ll y1, ll x2, ll y2) {
    ll ans = 0;
    ll three = 1;
    for (int i = 0; i < 35; ++i) {
        if(x1 / three == x2 / three && between(x1 / three, y1 / three, y2 / three)) {
            ll tmp = min(min(x1 % three, x2 % three) + 1, three - max(x1 % three, x2 % three));
            ans = max(ans, tmp);
        }
        three *= 3;
    }

    return ans;
}

ll get_dist(ll x1, ll y1, ll x2, ll y2){
    return abs(x1 - x2) + abs(y1 - y2) + 2 * max(get_extra(x1, y1, x2, y2), get_extra(y1, x1, y2, x2));
}

int main() {
    int Q;
    cin >> Q;

    while (Q--) {
        long long a;
        long long b;
        long long c;
        long long d;

        cin >> a >> b >> c >> d;
        cout << get_dist(a-1, b-1, c-1, d-1) << endl;
    }

    return 0;
}

Measured memory_bytes: 3656
n = gets.chomp.to_i
arr = gets.chomp.split(" ").map(&:to_i)

(0..n-1).each do |i|
  arr[i] -= i + 1
end

arr.sort_by!{|a| a}

half = arr[n / 2]
result = 0
arr.each do |a|
  result += (a - half).abs
end

puts result

Measured memory_bytes: 36096
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
const int INF=int(1e9);
int n,goal;
int con[15][2];
int dp[15][int(2e5)];
int DP(int x,int y)
{
    if(y<=0) return 0;
    if(x<1) return INF;
    if(dp[x][y]!=-1) return dp[x][y];
    dp[x][y]=INF;
    for(int i=0;i<con[x][0];i++)
        dp[x][y]=min(dp[x][y],DP(x-1,y-i*x)+i);
    dp[x][y]=min(dp[x][y],DP(x-1,y-con[x][0]*x-con[x][1])+con[x][0]);
    return dp[x][y];
}
int main()
{
	memset(dp,-1,sizeof dp);
    scanf("%d%d",&n,&goal);
    goal/=100;
    for(int i=1;i<=n;i++)
        scanf("%d%d",&con[i][0],&con[i][1]),con[i][1]/=100;
    printf("%d\n",DP(n,goal));
    return 0;
}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()


int main() {
  i64 N, M;
  cin >> N >> M;
  vector<pair<i64, i64>> vec;
  rep(i,0,N) {
    i64 a, b;
    cin >> a >> b;
    vec.push_back({ a, b });
  }
  vector<i64> A(N), B(N);
  sort(all(vec));
  rep(i,0,N) {
    A[i] = vec[i].first;
    B[i] = vec[i].second;
  }
  vector<i64> L(M), R(M);
  rep(i,0,M) {
    i64 l, r;
    cin >> l >> r;
    L[i] = lower_bound(all(A), l) - begin(A);
    R[i] = upper_bound(all(A), r) - begin(A);
  }
  vector<vector<pair<i64, i64>>> mat(N);
  rep(i,0,M) {
    if(L[i] < R[i]) {
      mat[L[i]].push_back({ R[i], i });
    }
  }
  vector<pair<i64, i64>> P;
  rep(i,0,N) {
    if(mat[i].size() == 0) continue;
    sort(all(mat[i]));
    for(i64 j = mat[i].size(); j --> 1;) {
      int nl = mat[i][j - 1].first;
      int nr = mat[i][j].first;
      if(nl < nr) {
        mat[nl].push_back({ nr, mat[i][j].second });
        P.push_back({ mat[i][j - 1].second, mat[i][j].second });
      }
    }
  }
  reverse(all(P));
  vector<i64> sum(N + 1, 0);
  vector<i64> ans(M);
  rep(i,0,N) {
    if((B[i] + sum[i]) % 2 == 1) {
      if(mat[i].size() == 0) {
        cout << -1 << endl;
        return 0;
      }
      i64 r = mat[i].front().first;
      i64 idx = mat[i].front().second;
      ans[idx] = true;
      sum[i]++;
      sum[r]--;
    }
    sum[i + 1] += sum[i];
  }
  for(auto p: P) {
    ans[p.first] ^= ans[p.second];
  }
  vector<i64> res;
  rep(i,0,M) {
    if(ans[i]) res.push_back(i);
  }
  cout << res.size() << endl;
  rep(i,0,res.size()) {
    cout << res[i] + 1 << " \n"[i + 1 == res.size()];
  }
}


Measured memory_bytes: 73956
n, m = [int(i) for i in input().split()]
a = [-1 * int(i) for i in input().split()]

import heapq

heapq.heapify(a)

for _ in range(m):
    target = heapq.heappop(a)
    target = int(target / 2)
    heapq.heappush(a, target)

print(sum(a) * -1)


Measured memory_bytes: 72216
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

"""
列ベクトルが M 個ある
いくつかを選ぶ（和をとる）→すべての行が0となる選び方：0、その他：2^{N-1}通り
列ベクトル空間の生成する次元：d次元
ans = 2^{N-1} * (2^M - 2^[M-d})
= 2^{N+M-1} * (1-2^{-rank})
"""

import numpy as np
MOD = 998244353
N,M = map(int,input().split())
A = np.array([[int(x) for x in input().split()] for _ in range(N)])

def rank(A):
    # F_2 上の行列のrank
    N,M = A.shape
    if N == 0 or M == 0:
        return 0
    nz = np.nonzero(A[0])[0]
    if len(nz) == 0:
        # first col = zero
        return rank(A[1:])
    i = nz[0]
    # swap
    temp = A[:,i].copy()
    A[:,i] = A[:,0]
    A[:,0] = temp
    # (0,0) 成分が 1 になった。行基本変形。
    A ^= A[0][None,:] * A[:,0][:,None]
    return 1 + rank(A[1:,1:])

d = rank(A)
answer = pow(2,N+M-1,MOD) * (1 - pow(2,(-d)%(MOD-1), MOD)) % MOD
print(answer)

Measured memory_bytes: 14560
import java.util.Scanner;

//Dividing Snacks
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), INF = 1<<29;
		int[] a = new int[n+2];
		for(int i=1;i<n;i++)a[i]=sc.nextInt();
		int[][][] dp = new int[2][2][n/2+1];
		for(int i=0;i<2;i++)for(int j=0;j<2;j++)for(int k=0;k<=n/2;k++)dp[i][j][k]=INF;
		dp[0][0][0] = 0;
		int x = 1;
		for(int i=1;i<=n;i++,x=1-x)for(int j=0;j<2;j++){
			int t = Math.min(i, n>>1);
			for(int k=0;k<=t;k++){
				dp[x][0][k] = Math.min(dp[1-x][0][k], dp[1-x][1][k]);
				if(0<k){
					dp[x][1][k] = dp[1-x][0][k-1]+a[i-1]+a[i];
					if(1<k)dp[x][1][k] = Math.min(dp[x][1][k], dp[1-x][1][k-1]-a[i-1]+a[i]);
				}
			}
		}
		System.out.println(Math.min(dp[1-x][0][n/2], dp[1-x][1][n/2]));
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ll nr;
    cin >> nr;
    ll aux = (sqrt(4*2*nr +1)-1)/2;
    if((2*aux+1)*(2*aux+1)<(4*2*nr+1))
        aux++;
    cout<<aux;
    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long double X[200100];
int N;
long long Count(long double len)
{
  long long Ans=0;
  for(int i=0;i<N;i++)
  {
    Ans+=(long long)(X[i]/len);
    //Ans+= (ceil(X[i])-1/len);
  }
  return Ans;
}
int main()
{
  long long K;
  cin>>N>>K;
  for(int i=0;i<N;i++)
{
	cin>>X[i];
	//X[i]-=0.1;
}
  long double l=1,r=1e9;
  //while(l<r-0.1)//なぜかOK
	//for(int i=0;i<35;i++)//OK log2(10^9)
  //while(((long long)(r)-(long long)(l)) > 1)
  //while(!((ceil(r)-ceil(l)) == 0))//https://atcoder.jp/contests/abc174/submissions/15672399
  while(!((floor(r)-floor(l)) == 0))//https://atcoder.jp/contests/abc174/submissions/15672399
  {
    //long double mid=(l+r+0.1)/2;
    long double mid=(l+r)/2;
  //  cout<<l<<" "<<r<<" "<<mid<<endl;
    if(Count(mid)<=K) r=mid;
    else	l=mid;
    //else	l=mid+0.01;
  }
  cout<<(long long)(l+0.999)<<endl;
  return 0;
}


Measured memory_bytes: 6824
a,b,c,x,y = map(int,input().split())
ab = min(a+b, c*2)
if x>y:
    tmp, tmp2, tmp3 = y, (x-y)*a, (x-y)*ab
else:
    tmp, tmp2, tmp3 = x, (y-x)*b, (y-x)*ab
ans = 0
for i in range(tmp):
    ans += ab
print(ans+min(tmp2, tmp3))


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

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

    ll tmp = N/K;
    
    ll ans = tmp*tmp*tmp;

    if(K%2 == 0 && K/2 <= N){
        ll tmp2 = (N+K/2)/K;
        ans += tmp2*tmp2*tmp2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
n,m,x = map(int, input().split())

c = [0 for _ in range(n)]
a = [[0] for j in range(n)]

for i in range(n):
  c[i],*a[i] = map(int, input().split())

cmin = sum(c) + 1
tassei = False

for i in range(1<<n):
  rikai = [0 for i in range(m)]
  cnow = 0
  for j in range(n):
    if i & (1<<j):
      cnow+=c[j]
      for mnow in range(m):
        rikai[mnow]+=a[j][mnow]
  if min(rikai)>=x:
    tassei = True
    cmin = min(cmin, cnow)

if tassei:
  print(cmin)
else:
  print(-1)

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

int a[100005];
ll diffs[100005];
int invperm[100005];


template<typename T>
ostream& operator<< (ostream& out, const vector<T>& v) {
    out << "[";
    size_t last = v.size() - 1;
    for(size_t i = 0; i < v.size(); ++i) {
        out << v[i];
        if (i != last) 
            out << ", ";
    }
    out << "]";
    return out;
}

vector<int> id;

vector<int> mult(vector<int> a, vector<int> b){
	vector<int> res(a.size());
	for (int i = 0; i < a.size(); i++){
		res[i] = a[b[i]];
	}
	return res;
}

vector<int> expo(vector<int> a, ll N){
	if (N == 0){
		return id;
	}
	vector<int> v = expo(a, N/2LL);
	if (N%2LL == 1){
		return mult(a, mult(v, v));
	}
	else{
		return mult(v, v);
	}
}

int main(){
	int N; cin >> N;
	for (int i = 0; i < N; i++){
		cin >> a[i];
	}
	for (int i = 0; i < N - 1; i++){
		diffs[i] = a[i + 1] - a[i];
	}
	int M; ll K; cin >> M >> K;
	vector<int> perm(N - 1);
	for (int i = 0; i < N - 1; i++){
		perm[i] = i;
	}
	id = perm;
	for (int i = 0; i < M; i++){
		int j; cin >> j;
		swap(perm[j - 2], perm[j - 1]);
	}
	
	//cout << perm << endl;
	vector<int> finperm = expo(perm, K);
	//cout << finperm << endl;
	ll start = a[0];
	cout << start << endl;
	for (int i = 0; i < N - 1; i++){
		start += diffs[finperm[i]];
		cout << start << endl;
	}
}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
    LL n;
    cin>>n;
    LL a[n];
    LL x=0;
    for(LL i=0;i<n;i++)
    {
        cin>>a[i];
        x=x^a[i];
    }
    for(LL i=0;i<n;i++)
    {

        LL y=x^a[i];
        cout<<y<<" ";
    }
}


Measured memory_bytes: 5116
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = (ll)1 << 62;

ll qx[1000001] = {};
ll qy[1000001] = {};
ll st = 0;
ll en = 0;

int main() {
	ll r, c; cin >> r >> c;
	//ll sy, sx; cin >> sy >> sx;
	//ll gy, gx; cin >> gy >> gx;

	ll sy = 1, sx = 1;
	ll gy = r, gx = c;

	char m[51][51];
	rep(i, 0, 51)rep(j, 0, 51) m[i][j] = '#';

	ll d[51][51];
	bool v[51][51] = {};
	ll totalW = 0;
	repe(i, 1, r) repe(j, 1, c) {
		cin >> m[i][j];
		if (m[i][j] == '.') totalW++;
	}

	ll y[4] = { 0,1,-1,0 };
	ll x[4] = { 1,0,0,-1 };

	qy[en] = sy;
	qx[en] = sx;
	d[sy][sx] = 0;
	v[sy][sx] = true;
	en++;

	while (st < en) {
		ll cy = qy[st];
		ll cx = qx[st];
		st++;

		rep(i, 0, 4) {
			ll nx = cx + x[i];
			ll ny = cy + y[i];

			if (ny >= 1 && ny <= r && nx >= 1 && nx <= c && m[ny][nx] != '#' && !v[ny][nx]) {
				v[ny][nx] = true;
				d[ny][nx] = d[cy][cx] + 1;
				qy[en] = ny;
				qx[en] = nx;
				en++;
			}
		}
	}

	if (d[gy][gx] == 0) {
		cout << -1 << endl;
	}
	else {
		cout << (totalW - (d[gy][gx] + 1)) << endl;
	}

	return 0;
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int main(){
    int N;
    cin >> N;

    vector<int> X(N);
    rep(i, N) cin >> X[i];

    vector<ll> fact(N + 1);
    fact[0] = 1;
    for (int i = 1; i <= N; ++i) {
        fact[i] = fact[i - 1] * i % MOD;
    }

    vector<ll> inv(N + 1);
    inv[1] = 1;
    for (int i = 2; i <= N; ++i) {
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    }

    vector<ll> V(N);
    V[0] = 1;
    for (int i = 1; i < N; ++i) {
        V[i] = V[i - 1] + 1.0 * inv[i + 1];
        V[i] %= MOD;
    }

    ll res = 0;
    rep(i, N - 1) {
        res += (X[i + 1] - X[i]) * V[i];
        res %= MOD;
    }

    ll ans = res * fact[N - 1];
    ans %= MOD;
    if (ans < 0) ans += MOD;

    cout << ans << endl;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"

int main(){
    ll a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;
    if(v<=w){
        COUT("NO");
        return 0;
    }
    else{
        if(abs(a-b)<=t*(v-w)){
            COUT("YES");
        }
        else COUT("NO");
    }
    return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 200010
#define ll long long
#define inf 1000000000000000LL
using namespace std;

struct tt{int l, r; ll f, x, mn1, mn2;}t[N*2];
int n, m, A, B, last, x, d, l;
ll mn, ans;

inline void update(int i){
	t[i].mn1=min(t[t[i].l].mn1, t[t[i].r].mn1);
	t[i].mn2=min(t[t[i].l].mn2, t[t[i].r].mn2);
}
inline void maketree(int L, int R){
	t[l].l=t[l].r=t[l].f=0;
	if(L<R){
		int mid=(L+R)>>1, l1=l;
		l++; t[l1].l=l; maketree(L, mid);
		l++; t[l1].r=l; maketree(mid+1, R);
		update(l1);
	}else{t[l].x=inf; t[l].mn1=t[l].x-L; t[l].mn2=t[l].x+L;}
}
inline void updatef(int i, ll x){t[i].f+=x; t[i].x+=x; t[i].mn1+=x; t[i].mn2+=x;}
inline void pushdown(int i){
	if(t[i].f){
		updatef(t[i].l, t[i].f); updatef(t[i].r, t[i].f);
		t[i].f=0;
	}
}
inline void ins(int i, int x, ll y, int L, int R){
	if(L==R){t[i].x=min(t[i].x, y); t[i].mn1=t[i].x-L; t[i].mn2=t[i].x+L; return;}
	pushdown(i);
	int mid=(L+R)>>1;
	if(x<=mid)ins(t[i].l, x, y, L, mid); else ins(t[i].r, x, y, mid+1, R);
	update(i);
}
inline ll cmn1(int i, int a, int b, int L, int R){
	if(a<=L&&R<=b)return t[i].mn1;
	pushdown(i);
	int mid=(L+R)>>1; ll mn=inf;
	if(a<=mid)mn=min(mn, cmn1(t[i].l, a, b, L, mid));
	if(mid<b)mn=min(mn, cmn1(t[i].r, a, b, mid+1, R));
	return mn;
}
inline ll cmn2(int i, int a, int b, int L, int R){
	if(a<=L&&R<=b)return t[i].mn2;
	pushdown(i);
	int mid=(L+R)>>1; ll mn=inf;
	if(a<=mid)mn=min(mn, cmn2(t[i].l, a, b, L, mid));
	if(mid<b)mn=min(mn, cmn2(t[i].r, a, b, mid+1, R));
	return mn;
}
inline void dfs(int i, int L, int R){
	if(L==R){ans=min(ans, t[i].x); return;}
	pushdown(i);
	int mid=(L+R)>>1;
	dfs(t[i].l, L, mid); dfs(t[i].r, mid+1, R);
}

int main(){
	scanf("%d%d%d%d", &n, &m, &A, &B); last=A;
	l=1; maketree(1, n); ins(1, B, 0, 1, n);
	for(int i=1; i<=m; i++){
		scanf("%d", &x); d=max(x-last, last-x);
		mn=min(cmn1(1, 1, x, 1, n)+x, cmn2(1, x, n, 1, n)-x);
		ins(1, last, mn-d, 1, n); updatef(1, d);
		last=x;
	}
	ans=inf; dfs(1, 1, n); printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 15872
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>

using namespace std;

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node * find(Node *u, int k) {
	while(u != NIL && k != u->key) {
		if(k < u->key) u = u->left;
		else u = u->right;
	}
	return u;
}

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key   = k;
	z->left  = NIL;
	z->right = NIL;
	
	while(x != NIL) {
		y = x;
		if(z->key < x->key) {
			x = x->left;
		} else {
			x = x->right;
		}
	}
	
	z->parent = y;
	if(y == NIL) {
		root = z;
	} else {
		if( z->key < y->key) {
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if(u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}
void preorder(Node *u) {
	if(u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}
	
int main(void) {
	int n, i, x;
	string com;
	scanf("%d",&n);
	
	for(i=0;i<n;i++) {
		cin >> com;
		if(com[0] == 'f') {
			scanf("%d",&x);
			Node *t = find(root,x);
			if(t != NIL) printf("yes\n");
			else printf("no\n");
		} else if(com == "insert") {
			scanf("%d",&x);
			insert(x);
		} else if(com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}

	return 0;
}

/*
8
insert 30
insert 88
insert 12
insert 1
insert 20
find 12
insert 17
insert 25
find 16
print
*/


Measured memory_bytes: 22012
#include <stdio.h>

#define COLUMNS 4

int
main(void)
{
	char row1[COLUMNS], row2[COLUMNS];
	scanf("%s %s", row1, row2);

	if (row1[0] == row2[2] && row1[2] == row2[0] && row1[1] == row2[1])
		puts("YES");
	else
		puts("NO");
	return (0);
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    string s; cin >> s;
    cout << s << (s[s.size()-1]=='s'?"es":"s") << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>
/*
recommend usage
initial 
*/

void solve(int a, int b){
    if( a==b ){
        printf("a == b\n");
    }
        else if( a>b )//if( a>b ){
        printf("a > b\n");
    else if( b>a ){ //}else{
        printf("b > a\n");
    }
    
}

int main(void){
    // Your code here!
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    //solve(a,b);
    if( a<b && b<c ) puts("Yes");
    else puts("No");
    
    return 0;
    
    
}



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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (c > (a - b))
    {
        cout << c - (a - b) << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}


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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, x) for (int i = 1, _##i = (x); i <= _##i; i++)
#define repr(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)

#define L(x) ((x)*2)
#define R(x) ((x)*2+1)

#ifndef __SOULTCH
#define endl '\n'
#define debug(x) 
#else
#define debug(x) cout << " [+] " << #x << " = " << x << endl
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
typedef pair<ll, ll> pll;

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << pai.first << ' ' << pai.second;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    rep(i, sz(v)) cout << v[i] << ' ';
    return os;
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> s) {
    for (T p : s) cout << p << ' ';
    return os;
}

template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> s) {
    for (auto p : s) cout << '(' << p << ") ";
    return os;
}

template<typename T, typename V>
istream &operator>>(istream &is, pair<T, V> &pai) {
	is >> pai.first >> pai.second;
	return is;
}

int N;
char str[1001];
int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> N >> str; 
    cout << (count(str, str+N, 'R')*2>N?"Yes":"No") << endl;
}






Measured memory_bytes: 256
n, a, b = map(int, input().split())

ans = 0
for i in range(1, n + 1):
    t = i
    sum = 0
    while(t > 0):
        sum += t % 10
        t = int(t / 10)
    
    if(a <= sum <= b):
        ans += i
    
print(ans)

Measured memory_bytes: 3060