akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
using int64 = long long;
 
int main() {
  int H, W, D, A[300][300];
  int X[1000000], Y[1000000];
  cin >> H >> W >> D;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> A[i][j];
      X[A[i][j]] = j;
      Y[A[i][j]] = i;
    }
  }
 
  vector< int > add[1000000];
  for(int i = 1; i <= H * W; i++) {
    add[i % D].emplace_back(i);
  }
  vector< int64 > sum[1000000];
  for(int i = 0; i < D; i++) {
    sum[i].resize(add[i].size());
    for(int j = 1; j < add[i].size(); j++) {
      sum[i][j] += sum[i][j - 1];
      sum[i][j] += abs(X[add[i][j - 1]] - X[add[i][j]]);
      sum[i][j] += abs(Y[add[i][j - 1]] - Y[add[i][j]]);
    }
  }
 
 
  int Q;
  cin >> Q;
  while(Q--) {
    int L, R;
    cin >> L >> R;
    int p = L % D;
    int latte = lower_bound(begin(add[p]), end(add[p]), L) - begin(add[p]);
    int malta = lower_bound(begin(add[p]), end(add[p]), R) - begin(add[p]);
    cout << sum[p][malta] - sum[p][latte] << endl;
  }
}

Measured memory_bytes: 59008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll R, G;
    cin >> R >> G;
    cout << R + (G-R)*2 << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)     cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
const int mx = 1e3+7;
int a[mx][mx];
ll dp[mx][mx];
const ll MOD = 1000000007;
int main(){
	fast_io;
	int h,w;
	cin>>h>>w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			char c;
			cin>>c;
			if(c=='#')a[i][j] = -1;
		}
	}
	for(int i=0;i<w;i++){
		if(a[0][i]==-1)break;
		dp[0][i] = 1;
	}
	for(int i=0;i<h;i++){
		if(a[i][0]==-1)break;
		dp[i][0] = 1;
	}
	for(int i=1;i<h;i++){
		for(int j=1;j<w;j++){
			if(a[i][j]==-1){
				continue;
			}
			dp[i][j] = (dp[i-1][j] + dp[i][j-1] + MOD)%MOD; 
		}
	}
	cout<<dp[h-1][w-1];
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 12160
sx,sy,tx,ty = map(int,input().split())
ans = ''
if tx - sx > 0:
  if ty - sy > 0:
    x = ['R','L','U','D']
  else:
    x = ['R','L','D','U']
else:
  if ty - sy > 0:
    x = ['L','R','U','D']
  else:
    x = ['L','R','D','U']
ans += x[0]*abs(tx-sx)
ans += x[2]*abs(sy-ty)
ans += x[1]*abs(tx-sx)
ans += x[3]*abs(ty-sy)
ans += x[3] + x[0]*(abs(tx-sx)+1)
ans += x[2]*(abs(ty-sy)+1) + x[1]
ans += x[2] + x[1]*(abs(tx-sx)+1)
ans += x[3]*(abs(ty-sy)+1) + x[0]
print(ans)

Measured memory_bytes: 9192
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define M 1000000007LL
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) ((ll)v.size())
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll> 
#define mod 1000000007LL
#define MAXN 300002
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
ll pre[300002];
ll a[300002],b[300002];
int main() {
ll n,a,b,c,d;
cin>>n>>a>>b>>c>>d;
string s;
cin>>s;
a--,b--,c--,d--;
if(c>d)
{
    swap(a,b);
    swap(c,d);
}
for(ll i=a;i<=c-1;i++) if(s[i]=='#' and s[i+1]=='#')
{cout<<"No";return 0;}
for(ll i=b;i<=d-1;i++) if(s[i]=='#' and s[i+1]=='#')
{cout<<"No";return 0;}
if(a<b)
{
    cout<<"Yes";
    return 0;
}
for(ll i=a;i<=c;i++)
{
    if(s[i]=='.' and s[i+1]=='.' and s[i-1]=='.')
        {cout<<"Yes";return 0;}
}
cout<<"No";
}

Measured memory_bytes: 640
#include <iostream>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
ll N,A[100000],ans;
ll cnt[3];

int main(void){
    cin >>N;
    rep(i,N)cin>>A[i];
    ans = 1;
    rep(i,N){
        ans = (ans * ((cnt[0]==A[i]) + (cnt[1]==A[i]) +(cnt[2]==A[i])))%MOD;
        rep(j,3)if(cnt[j]==A[i]){cnt[j]++;break;}
    }
    
    ll num = (cnt[0]>0)+(cnt[1]>0)+(cnt[2]>0);

    ans %=MOD;
    cout << ans<<endl;
}


Measured memory_bytes: 1024
#include "cstdio"
int main(){
    long long n,a,b;scanf("%lld%lld%lld",&n,&a,&b);
    if (n>1&&b>=a||n==1&&a==b)
        printf("%lld",(n-2)*(b-a)+1);
    else printf ("0"); 
    return 0;
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int m=1e9+7;
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    fastio
    int n,k;
    cin>>n>>k;
    int cnt=0;
    while(n--){
        int a;
        cin>>a;
        if(a>=k) ++cnt;
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 3644
# include <iostream>
# include <vector>
# include <map>


using namespace std;


template<typename T>
vector<int> argsort(vector<T> input) {
    size_t seq_len = input.size();

    vector<pair<int, T>> seq(seq_len);
    for (int i=0; i<seq_len; i++) {
        seq[i] = make_pair(input[i], i);
    }
    sort(seq.begin(), seq.end());

    vector<int> result(seq_len);
    for (int i=0; i<seq_len; i++) result[seq[i].second] = i;
    return result;
};


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

    vector<int> p(m), y(m);
    for (int i=0; i<m; i++) cin >> p[i] >> y[i];

    map<int, vector<int>> r;
    for (int i=0; i<m; i++) {
        if (r.find(p[i]) == r.end()) r[p[i]] = {y[i]};
        else r[p[i]].push_back(y[i]);
    }

    map<pair<int, int>, int> ans;
    for (auto r_p: r) {
        vector<int> ra_p = argsort(r_p.second);

        for (int i=0; i<r_p.second.size(); i++) {
            ans[make_pair(r_p.first, r_p.second[i])] = ra_p[i]+1;
        }
    }

    for (int i=0; i<m; i++) {
        printf("%06d%06d\n", p[i], ans[make_pair(p[i], y[i])]);
    }
    return 0;
}



Measured memory_bytes: 17920
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;

long pre[200005];

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    vector<long> c(n);
    long i;
    for(i=0; i<n; i++) {
        scanf("%ld", &c[i]);
    }

    for(i=0; i<200005; i++) {
        pre[i]=INF;
    }

    vector<ll> dp(n);
    for(i=0; i<n; i++) {
        dp[i] = (i>0? dp[i-1]: 1);
        if(pre[c[i]]<i-1) {
            dp[i] = (dp[i] + dp[pre[c[i]]])%MOD;
        }
        pre[c[i]] = i;
    }

    printf("%lld\n", dp[n-1]);

    return 0;
}


Measured memory_bytes: 4864
N = int(input())
A = list(map(int,input().split()))

cnt = 0
flag = False
while True:
    for n in range(N):
        if A[n] % 2 == 1:
            flag = True
            break
        A[n] //= 2
    if flag:
        break
    cnt += 1

print(cnt)

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

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

using namespace std;

int main() {

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

    int N;
    cin >> N;

    vector<char> w(N);

    function<void(int, int)> dfs = [&](int n, int m) {
        if (n == N) {
            REP(i, N) cout << w[i];
            cout << '\n';
            return;
        }
        REP(i, m) {
            w[n] = 'a' + i;
            dfs(n + 1, m);
        }
        w[n] = 'a' + m;
        dfs(n + 1, m + 1);
    };

    dfs(0, 0);
    cout << flush;

    return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 1005
typedef long long ll;



int main(){
    string s;
    int i,l;
    cin>>s;
    l=s.length();
    for(i=0;i<l;i++){
        if(s[i]=='?')
            s[i]='D';
    }
    cout<<s;
    
    
    return 0;
}


Measured memory_bytes: 3752
#include<iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
         if (i) cout << " ";
         cout << a[i];
    }
    cout << endl;
    for (int i = 1; i < n; ++i) {
        for (int j = i - 1; j >= 0; --j) {
            if (a[j + 1] < a[j]) {
                swap(a[j + 1], a[j]);
            }
        }
        for (int i = 0; i < n; ++i) {
            if (i) cout << " ";
            cout << a[i];
        }
        cout << endl;
    }
    return 0;
}



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

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0) 

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static const int MOD = 1000000007;
static const int INF = ((1<<30)-1);
static const s64 LINF = ((1LL << 62)-1);

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }
    
    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

int main() {
	int n = ri();
	int a = ri();
	int b = ri();
	int m = b-a;
	s64 c = ri();
	s64 d = ri();
	FOR(i,n) {
		s64 minus = n-1-i;
		s64 maxx = i*d-minus*c;
		s64 minn = i*c-minus*d;
		if (m <= maxx && m >= minn) {
			cout << "YES" << endl;
			return 0;
		}
	}
		cout << "NO" << endl;
	
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    int n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    int cnt = 0;
    rep(i, n){
        map<char,int> mp;
        mp[a[i]]++;
        mp[b[i]]++;
        mp[c[i]]++;
        cnt += mp.size() - 1;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iomanip>
#include<iostream>
#include<queue>
#include<string>
#include<unordered_set>
#include<vector>
using namespace std;
typedef long long ll;
const ll INF = 1000000000000000000;
const ll big_prime = 1000000007;

ll N, A[10010], max_ai, ans;
ll factor[1000010], LCM=1;

long long calc_sq(long long x) {
	x = x % big_prime;
	return (x * x) % big_prime;
}

long long calc_pow(long long a, long long b) {
	long long ret;
	if (b == 0)return 1;
	if (b == 1)return a;
	if (b % 2 == 0) {
		ret = calc_sq(calc_pow(a, b / 2)) % big_prime;
		return ret;
	}
	if (b % 2 == 1) {
		ret = (a * calc_sq(calc_pow(a, b / 2))) % big_prime;
		return ret;
	}
}

void solv(ll x){
    ll i = 2;
    while(i*i<=x){
        ll t = 0;
        while(x % i == 0){
            x /= i;
            t++;
        }
        factor[i] = max(factor[i], t);
        i++;
    }
   factor[x] = max(factor[x], (ll)1);
}

int main(){
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> A[i];
        solv(A[i]);
        max_ai = max(max_ai, A[i]);
    }
    for(int i=2; i<=max_ai; i++){
        for(int j=0; j<factor[i]; j++){
            LCM *= i;
            LCM %= big_prime;
        }
    }
    for(int i=0; i<N; i++){
        ans += LCM * calc_pow(A[i], big_prime - 2);
        ans %= big_prime;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6656
#include <stdio.h>
#include <ctype.h>

int main(void) {
	char str[1200];
	int strlen = 0;
	int i;
	
	gets(str);
	
	for (i = 0;i < 1200; i++){
		if (isupper(str[i])) str[i] = tolower(str[i]);
		else if (islower(str[i])) str[i] = toupper(str[i]);
	}
	
	printf("%s\n", str);
	
	return 0;
}

Measured memory_bytes: 524
import java.util.*;
public class Main {
    public static void main(String args[]) {
     Scanner sc = new Scanner(System.in);
     
   long n = sc.nextLong();
   long count =1;
   long sum=0;
 
 while(n>0){
     sum+=count;
     count*=2;
     n/=2;
 }
     
 System.out.println(sum);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	string s;cin >> s;int a = 0, b = 0;
	rep(i, s.size()) {
		if (s[i] == '0') a++;
		else b++;
	}
	cout << min(a, b) * 2 << endl;
}

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

void setIn(string s){freopen(s.c_str(), "r", stdin);}
void setOut(string s){freopen(s.c_str(), "w", stdout);}
void unsyncIO(){cin.tie(0) -> sync_with_stdio(0);}
void setIO(string s = ""){
	unsyncIO();
	if(s.size()){
		setIn(s + ".in");
		setOut(s + ".out");
	}
}


#define ll long long
const ll mod = 998244353;
const int MX = 5005;

int main(){
	setIO();
	int d,t,s;
	cin >> d >> t >> s;
	if(d > t * s) cout << "No\n";
	else cout << "Yes\n";
}

Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <array>
using namespace std;

#define IS_POWER_TWO(x) (!(x & (x-1))) 


int main()
{
	int n;
	vector<int> e;
	scanf("%d", &n);
	int ave = 0;
	for (int i = 0; n > i; i++) {
		int a;
		scanf("%d", &a);
		ave += a;
		e.push_back(a);
	}
	ave /= n;
	int cost = 0, cost2 = 0;
	for (int i = 0; n > i; i++) {
		cost += abs(pow(e[i] - ave,2));
		cost2 += abs(pow(e[i] - ave-1,2));
	}
	printf("%d\n", min(cost2,cost));
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	long a,b,c;
	cin>>a>>b>>c;

	if(a%2&&b%2&&c%2)
		cout<<min(a*b,min(a*c,b*c))<<endl;
	else
		cout<<0<<endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <utility>

using namespace std;


char map[30][30];
pair<int,int> s;
int w,h;
int cnt;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
class Node{
public:
  int x,y;
  int cnt;
  Node(int _x,int _y,int _cnt):x(_x),y(_y),cnt(_cnt){

  }

};
int sx,sy;
void show(){
  for(int i=0;i<h;i++){
    cout<<map[i]<<endl;

  }
}
int bfs(){
  queue<Node> q;
  q.push(Node(sx,sy,0));
  map[sy][sx]='#';
  int ans=0;
  while(!q.empty()){
    Node cur=q.front();q.pop();
    //    show();
    ans=max(ans,cur.cnt);
    for(int i=0;i<4;i++){
      int nx=cur.x+dx[i];
      int ny=cur.y+dy[i];
      if(nx<0||nx>=w||ny<0||ny>=h||map[ny][nx]=='#')continue;
      map[ny][nx]='#';
      cnt++;
      q.push(Node(nx,ny,cur.cnt+1));
    }
  }
  return cnt;
    
}void solve(){
  cnt=0;

  cout<<bfs()+1<<endl;
}
int main(){
  while(cin>>w>>h&&(w||h)){
    //    for(int i=0;i<h;i++)for(int j=0;j<w;j++)map[i][j]='.';
    for(int i=0;i<h;i++){
      cin>>map[i];
      for(int j=0;j<w;j++){
	if(map[i][j]=='@'){
	  sx=j;sy=i;
	}
      }
    }
    solve();
  }
  return 0;
}

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

#define print(x) cerr << #x << " is " << x << endl;
#define int long long int
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpi vector<pair<int, int>>
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pb push_back
#define eb emplace_back
#define PI 3.1415926535897932384626
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define out cout << fixed << setprecision(12) <<

const int N = 2e5 + 10;
const int mod = 1e9 + 7;

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

    int s, w;
    cin >> s >> w;
    if( w >= s){
        cout << "unsafe\n";
    }
    else
        cout << "safe\n";
    return 0;
}

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

const int MAX = 1e5 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;
 
string S;

int main(){
    cin >> S;

    int cnt = 0;
    vector<int> LR, a;
    char now = 'R';
    rep(i, S.size()){
        if(S[i] == now) cnt++;
        else{
            LR.push_back(cnt);
            cnt = 1;
            if(now == 'R'){
                a.push_back(i - 1);
                now = 'L';
            } else {
                now = 'R';
            }
        }
    }
    LR.push_back(cnt);

    rep(i, S.size()){
        if(i != a.front()){
            cout << "0" << " ";
            continue;
        }

        int R = LR[0];
        int L = LR[1];
        if((R + L) % 2){
            if(R % 2) cout << (R + L + 1) / 2 << " " << (R + L) / 2 << " ";
            else      cout << (R + L) / 2 << " " << (R + L + 1) / 2 << " ";
        } else {
            cout << (R + L) / 2 << " " << (R + L) / 2 << " ";
        }
        LR.erase(LR.begin());
        LR.erase(LR.begin());
        a.erase(a.begin());
        i++;
    }
}

Measured memory_bytes: 1400
def main():
    k = int(input())
    aa = list(map(int, input().split()))[::-1] + [1]
    if aa[0] != 2:
        print(-1)
        return
    min_n, max_n = 2, 2
    for i in range(k):
        a = aa[i]
        b = aa[i + 1]
        if min_n % a:
            min_n = (min_n // a + 1) * a
        else:
            min_n = min_n // a * a
        m = max_n + a - 1
        m -= m % b
        if min_n > m:
            print(-1)
            return
        else:
            max_n = m
    print(min_n, max_n)


main()


Measured memory_bytes: 14224
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		char c = scan.next().charAt(0);
		scan.close();
		char x[]= {'a','e','i','o','u'};
		
		int check=0;
		for(int i=0;i<x.length;i++) {
			if(x[i]==c) {
				check=1;
				break;
			}
		}
		if(check==1)System.out.println("vowel");
		else System.out.println("consonant");
	}
}

Measured memory_bytes: 22740
#define _USE_MATH_DEFINES
#include <iostream> 
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std; 
int main(){
	vector<int> v;
	for(int i=1;i<=10;i++){
		int h;
		cin >> h;
		v.push_back(h);
	}
	std::sort(v.begin(), v.end());
	std::reverse(v.begin(), v.end());
	for(int i=0;i<3;i++){
		cout << v[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> istream & operator>>(istream & s, vector<T> & v) { RF(e, v) { s >> e; } return s; }
template<typename T> ostream & operator<<(ostream & s, vector<T> const & v) {
	inc(i, SI(v)) { s << (i == 0 ? "" : " ") << v[i]; }
	return s;
}

auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };

int main() {
	IN(LL, n, k);
	vector<LL> a(n);
	cin >> a;
	
	auto f = [&](LL v) -> bool {
		LL c = 0;
		RF(e, a) { c += ce(e, v) - 1; }
		return (c <= k);
	};
	LL ng = 0, ok = 1e9;
	until(ok - ng <= 1) {
		LL m = (ok + ng) / 2;
		(f(m) ? ok : ng) = m;
	}
	OUT(ok);
}


Measured memory_bytes: 4772
import java.util.*;

public class Main {

    public static void main(String args[]) {


        Scanner scan = new Scanner(System.in);

        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int k = scan.nextInt();

        int d = a + b;

        if (a >= k) {
            System.out.println(String.valueOf(k));
            return;
        }


            if (d >= k) {
                System.out.println(String.valueOf(a));
            } else {
                int e = k - d;
                System.out.println(String.valueOf(a - e));
            }
        }
    

}

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

const int mx = 1234567;
const double exp1 = 1e-6;
const int md = 1e9+7;
typedef long long ll;

int ar[mx],xar[mx],uses[mx];
ll arr[mx],ax[mx];
string st[1000];

int main(){

    int tk=1,n,m=0;
//    freopen("in.txt","r", stdin);
//    freopen("out.txt","w", stdout);

    while(scanf("%d",&n)==1){
        for(int i  = 0; i < n; i++){
            scanf("%lld",arr + i);
            ax[i] = arr[i] - i + 1;
        }
        sort(ax, ax+n);
        int a = n/2;
        ll b = ax[a];
        ll res = 0;
        cerr<<a<<" "<<ax[a]<<endl;
        for(int i  = 0; i < n; i++){
           res += abs(ax[i] - b);
        }
        cout<<res<<endl;

    }
    return 0;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    map<int, int, greater<int>> mp;
    rep(i,n) {
        int a;
        cin >> a;
        mp[a]++;
    }
    ll ans = 1;
    int cnt =  0;
    for(auto x : mp) {
        if(x.second >= 4 && cnt == 0){
            ans*=x.first;
            ans*=x.first;
            cnt = 2;
            break;

        }
        else if(x.second >= 2) {
            cnt++;
            ans*=x.first;
            if(cnt==2) break;
        }
        
    }
    if(cnt!=2) {
        cout << 0 << endl;
    }
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8176
while True:
    input_n = int(input())
    key = 0
    if input_n == 0:
        break
    id_list = [[0 for i in range(2)]for i in range(input_n)]
    for i in range(input_n):
        id_line = input().split()
        for j in id_list:
            if j[0] == int(id_line[0]):
                j[1] += int(id_line[1]) * int(id_line[2])
                uriage = j[1]
                break
        else:
            id_list[i][0] = int(id_line[0])
            id_list[i][1] = int(id_line[1]) * int(id_line[2])
            uriage = id_list[i][1]
        if uriage >= 1000000:
            key = 1
    
    for i in id_list:
        if key == 0:
            print("NA")
            break
        if i[1] >= 1000000:
            print(i[0])


Measured memory_bytes: 5884
#include <bits/stdc++.h>
#define maxn 100010
int a[maxn], b[maxn], c[maxn];
using namespace std;
typedef long long LL;
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
    for (int i = 0; i < n; ++i) scanf("%d", &c[i]);
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);
    LL ans=0;
    for (int i = 0; i < n; ++i) {
        int p1 = lower_bound(a, a+n, b[i]) - a - 1,
            p2 = upper_bound(c, c+n, b[i]) - c;
        ans += 1LL * (p1+1) * (n-p2);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1408
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

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

uintmax_t combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    ll ten = 10;

    if(n % 2 == 1) ans = 0;
    else{
        while(n / ten > 0){
            ll k = n / ten;
            ans+=k;
            ten*=5;
        }
    }

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

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

public class Main {
	public static void main(String[] args) throws IOException {
		//Scanner sc = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine());
		ArrayList<Integer> arr = new ArrayList<>(N);
		ArrayList<Integer> sorted = new ArrayList<>(N);
		for(int i = 0; i<N; i++){
			int x = Integer.parseInt(br.readLine());
			arr.add(x);
			sorted.add(x);
		}
		
		Collections.sort(sorted);
		
		HashMap<Integer, Integer> places = new HashMap<>();
		int ind = 0;
		for(int i : sorted){
			places.put(i, ind);
			ind++;
		}
		
		ind = 0;
		int count = 0;
		for(int i : arr){
			int cplace = places.get(i);
			if(cplace%2 != ind%2) count++;
			ind++;
		}
		System.out.println(count/2);
	}
}

Measured memory_bytes: 29540
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

use input::*;

fn main() {
    let s = str2vec(&input_line_str());

    if s.len() == 1 {
        p(1);
        return;
    }

    let mut prev = &s[0..1];
    let mut ans = 1;

    let mut from = 1;
    let mut to = 2;

    while from <= s.len() {
        if prev != &s[from..to] {
            prev = &s[from..to];
            ans += 1;
            from = to;
            to = from + 1;
        } else {
            to += 1;
        }
        if to > s.len() {
            break;
        }
    }
    p(ans);
}

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

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

    vector<string> ans;
    for(int i=0; i<s.size(); i++){
        for(int j=0; j<=k; j++){
            if(s.substr(i, j) == "") continue;
            ans.push_back(s.substr(i, j));
        }
    }

    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());

    cout << ans[k-1] << endl;
    return 0;
}

Measured memory_bytes: 1660
//AnkitCode99 (DP)....
//every ups and downs matter!

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr)
typedef long long int ll;

using namespace std;

const ll sz=1e5+5;

ll n,totW,wt[105],val[105],cache[105][sz];

ll dp_valid_wt(ll idx,ll profit)
{
	if(profit<0)
		return 1e15;//this wont give the minimum weight satisfying our need

	if(profit==0)
		return 0;

	if(idx==n+1)
		return 1e15;//actually we dont need this value so putting its weight as infinity

	ll &ans=cache[idx][profit];
	if(ans!=-1)
		return ans;

	ans=min(dp_valid_wt(idx+1,profit),wt[idx]+dp_valid_wt(idx+1,profit-val[idx]));
	return ans;
}

int main()//in this variant of Knapsack we find the 
//maximum total weight which is less than the total knapsack 
//capacity and gives maximum profit, so we iterate over all total profit values
//and find the maximum of all valid profits.
{
	fast;
	
	memset(cache,-1,sizeof cache);
	cin>>n>>totW;
	for(ll i=1;i<=n;i++)
	{
		cin>>wt[i]>>val[i];
	}

	ll final_ans=0;
	for(ll i=1;i<=sz;i++)
	{
		ll this_wt=dp_valid_wt(1,i);//i is the profit
		if(this_wt<=totW)
		{
			final_ans=i;
		}
	}

	cout<<final_ans<<endl;

}//Goodbye...

Measured memory_bytes: 82304
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

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

	int LR[N+1][N+1] = {};
	int C[N+1][N+1] = {};
	int p[Q] = {};
	int q[Q] = {};
	int ans[Q] = {};

	int l,r;
	for (int i = 0; i < M; ++i) {
		cin >> l >> r;
		LR[l][r]++;
	}
	for (int i = 1; i < N+1; ++i) {
		for (int j = i; j < N+1; ++j) {
			C[i][j] += LR[i][j];
			C[i][j] += C[i][j-1];
		}
	}

	for (int i = 0; i < Q; ++i) {
		cin >> l >> r;
		for (int j = l; j <= r; ++j) {
			ans[i] += (C[j][r] - C[j][j-1]);
		}
	}

	for (int i = 0; i < Q; ++i) {
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
	int n,ans=0;
	cin>>n;
	int d[1000];
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		d[a]++;
	}
	for(int i=0;i<105;i++){
		if(d[i]>0){
			ans++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

    bool flag = true;

    for (int i = 0; i < S.size() - 1; i++) {
        if (S[i] == S[i + 1]) {
            flag = false;
            break;
        }
    }

    if (flag) {
        cout << "Good" << endl;
    }
    else {
        cout << "Bad" << endl;
    }
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
//typedef long long int;
static const double pi = 3.141592653589793;
const ll M = 1000000007;
double A, B, C, D, G, H, N, L, K, P, Q, R, W, X, Y, Z;
string S, T;

signed main(){
	std::cin >> A>>B>>H>>W;
	double c=cos(2*pi*((60*H+W)/720-W/60));
	//c=cos(pi/6);
	//std::cout << c << std::endl;
	double ans=A*A+B*B-2*A*B*c;
	//std::cout << ans << std::endl;
    cout << fixed << setprecision(15) << sqrt(ans) << endl;
}


Measured memory_bytes: 4252
#include <bits/stdc++.h>
using namespace std;
int m;
vector<int>p;
vector<int>s;
int maxn,minn;
 
 
int main(){
  int i,j,now=0,ni=0;
  while(1){
  cin >> m >> minn >> maxn;
  now = 0;
  if(m==0&&maxn==0&&minn==0)break;
  for(i=0;i<m;i++){
    cin >> j;
    p.push_back(j);
  }
  sort(p.begin(),p.end());
  for(i=0;i<m-1;i++)  s.push_back(p[i+1]-p[i]);
  for(i=m-minn-1;i>=m-maxn-1;i--){
    // cout << " bbb"<<s[i];
    if(s[i]>=now){
      now = s[i];
      ni = i;
      //cout <<"aaa"<< now << " "<< ni << endl;
    }
  }
  //cout <<endl<< ni << endl;
  cout << m-1-ni << endl;
  while(p.size())p.pop_back();
  while(s.size())s.pop_back();
  }
  return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,temp;
cin>> n;
vector<int> a(n);
vector<int> b;
for(int i=0;i<n-1;i++) {cin >>temp; b.push_back(temp);}
for(int i=b.size()-1;i>=0;i--){
  a[b[i]-1]+=1;
}
for(int i=0;i<n;i++) cout << a[i] << endl;

}



Measured memory_bytes: 5104
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char c=getchar();int fh=1;
	while (!isdigit(c)){if (c=='-')fh=-1;c=getchar();}
	while (isdigit(c))x=x*10+c-'0',c=getchar();
	x*=fh;
}
int a,b,c;
int main(){
	cin>>a>>b>>c;
	cout<<b+min(c,a+b+1)<<endl;
	return 0;
}

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

using namespace std;

int f(int k){
    int sum = 0;
    while(k != 0){
        sum += k % 10;
        k /= 10;
    }
    return sum;
}

int main(){
    int mmin = 1e9;
    int n;
    cin >> n;
    for(int i = 1; i < n; i++){
        mmin = min(mmin, f(i) + f(n - i));
    }
    cout << mmin;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,A,B,a[300005];
int main(){
	scanf("%d%d%d",&n,&A,&B);
	if(A+B>n+1) return puts("-1"),0;
	bool g=0;
	if(A<B) swap(A,B),g=1;
	//if(n-A-(B-1)>A) return puts("-1"),0;
	if(B==1&&A!=n) return puts("-1"),0;
	for(int i=1;i<=A;i++) a[i]=n-A+i;
	
	int rst=n-A,S=A,T=n-A;B--;
	while(rst-A>=B){
		for(int i=S+1;i<=S+A;i++) a[i]=T-A+(i-S);
		S+=A;B--;rst-=A;T-=A;
	}
	if(B<=0&&rst) return puts("-1"),0;
	for(int i=1;i<=B;i++) a[S+i]=B-i+1;
	for(int i=B+1;S+i<=n;i++) a[S+i]=i;
	if(g) for(int i=1;i<=n;i++) a[i]=n-a[i]+1;
	for(int i=1;i<=n;i++) printf((i==n)?"%d":"%d ",a[i]);
	return 0;
}

Measured memory_bytes: 3328
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let _n = get!(usize);
    let mut aa = vec![0; 100002];
    for a in get!(String).split_whitespace() {
        if let Ok(n) = a.parse::<usize>() {
            if n > 0 { aa[n-1] += 1; }
            aa[n] += 1;
            aa[n+1] += 1;
        }
    }
    println!("{}", aa.into_iter().fold(0, std::cmp::max));
}

Measured memory_bytes: 3248
#include <stdio.h>

int main(){
  int N;
  char S[5];
  int A[5]={};
  char T[5][5]={"AC","WA","TLE","RE"};
  scanf("%d\n",&N);
  for(int i=1;i<=N;i++){
    scanf("%s\n",S);
    if(S[0]=='A'){
      A[0]++;
    }else if(S[0]=='W'){
      A[1]++;
    }else if(S[0]=='T'){
      A[2]++;
    }else{
      A[3]++;
    }
  }
  for(int i=0;i<=3;i++){
    printf("%s x %d\n",T[i],A[i]);
  }
  return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
 
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
 
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
 
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
 
#define _  %  MOD
#define __ %= MOD
 
#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))
 
#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
#define fbo find_by_order
#define ook order_of_key
 
ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent
ll n,k,r,s,p;
string t;
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
	cin>>n>>k>>r>>s>>p>>t;
	ll ans=0;
	vector<char> v(n);
	rep(i,n)
	{
		if(t[i]=='r')
		{
			if(i-k>=0)
			{
				char ch=v[i-k];
				if(ch=='p')
				{
					if(i+k<n)
					{
						char ch1=t[i+k];
						if(ch1=='r')
						{
							v[i]='s';
						}
						if(ch1=='s')
						{
							v[i]='s';
						}
						if(ch1=='p')
						{
							v[i]=='r';
						}
					}
				}
				else
				{
					ans+=p;
					v[i]='p';
				}
			}
			else
			{
				ans+=p;
				v[i]='p';
			}
		}
		if(t[i]=='s')
		{
			if(i-k>=0)
			{
				char ch=v[i-k];
				if(ch=='r')
				{
					if(i+k<n)
					{
						char ch1=t[i+k];
						if(ch1=='r')
						{
							v[i]='s';
						}
						if(ch1=='s')
						{
							v[i]='s';
						}
						if(ch1=='p')
						{
							v[i]='p';
						}
					}
				}
				else
				{
					ans+=r;
					v[i]='r';
				}
			}
			else
			{
				ans+=r;
				v[i]='r';
			}
		}
		if(t[i]=='p')
		{
			if(i-k>=0)
			{
				char ch=v[i-k];
				if(ch=='s')
				{
					if(i+k<n)
					{
						char ch1=t[i+k];
						if(ch1=='r')
						{
							v[i]='r';
						}
						if(ch1=='s')
						{
							v[i]='p';
						}
						if(ch1=='p')
						{
							v[i]='r';
						}
					}
				}
				else 
				{
					ans+=s;
					v[i]='s';
				}
			}
			else
			{
				ans+=s;
				v[i]='s';
			}
		}
	}
	cout<<ans<<'\n';
	return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!



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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

ll n,s;
vll a;

const ll mod=998244353;

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  cin >> n >> s;
  a.resize(n);
  ll m=0;
  rep(i,0,n) {
    cin >> a[i];
    m=max(m,a[i]);
  }
  
  vector<vvll> dp(n+1,vvll(s+m+1,vll(3,0)));
  
  dp[0][0][0]=1;
  
  rep(i,0,n){
   rep(j,0,s+1){
     (dp[i+1][j][0]+=dp[i][j][0])%=mod;
     (dp[i+1][j+a[i]][1]+=dp[i][j][0]*(i+1))%=mod;
     (dp[i+1][j+a[i]][2]+=dp[i][j][0]*(i+1)*(n-i))%=mod;
  
     
     (dp[i+1][j][1]+=dp[i][j][1])%=mod;
     (dp[i+1][j+a[i]][1]+=dp[i][j][1])%=mod;
     (dp[i+1][j+a[i]][2]+=dp[i][j][1]*(n-i))%=mod;
     
      (dp[i+1][j][2]+=dp[i][j][2])%=mod;
   }
  }
  cout << dp[n][s][2] << endl;
}

Measured memory_bytes: 716544
#include <stdio.h>

static const int MAX = 500;
static const int IN = (1<<21);

int main(){
  int num,i,j,ei,sum;
  int Ma[MAX][MAX];
  int x,y,kI,cI;
  int Minv;
  int D[MAX];
  int P[MAX];
  int Vis[MAX];

  scanf("%d",&num);

  for(i=0;i<num;i++){
    for(j=0;j<num;j++){
      Ma[i][j] = IN;
    }
  }

  for(i=0;i<num;i++){
    scanf("%d %d",&x,&kI);
    for(j=0;j<kI;j++){
      scanf("%d %d",&y,&cI);
      Ma[x][y]=cI;
    }
  }
  for(i=0;i<num;i++){
    D[i]=IN;
    Vis[i]=0;
  }
  
  D[0] = 0;

  while(1){
    Minv = IN;
    x=-1;
    for(i=0;i<num;i++){
      if(Minv > D[i] && !Vis[i]){
	x=i;
	Minv=D[i];
      }
    }
    if(x==-1){
      break;
    }
    Vis[x] = 1;
    for(y=0;y<num;y++){
      if(!Vis[y] && Ma[x][y] != IN){
	if(D[y] > D[x]+Ma[x][y]){
	  D[y] =D[x]+ Ma[x][y];

	}
      }
    }
  }

  for(i=0;i<num;i++){
    printf("%d %d\n",i,(D[i]==IN?-1:D[i]));
    }


  return 0;
}



Measured memory_bytes: 2060
#include <iostream>

using namespace std;

typedef long long ll;

int main(void)
{
    ll R, G, B, N;
    cin >> R >> G >> B >> N;
    ll ans = 0;
    for (ll x = 0; R * x <= N; x++) {
        for (ll y = 0; R * x + G * y <= N; y++) {
            if ((N - R * x - G * y) % B == 0) {
                ans += 1;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import qualified Data.Sequence as SQ

--挿入数ストア、処理すべきシーケンス、最終スコア
solver::Int -> SQ.Seq Char -> (Int,Bool)
solver score sq =  if SQ.length sq <= 1 then (score,True)
                                        else let (left SQ.:< sq') = SQ.viewl sq  in
                                             let (rest SQ.:> right) = SQ.viewr sq' in
                                             case (left=='x',right=='x',left==right) of
                                               (_,_,True)        -> solver score rest
                                               (True,False,False)-> solver (score+1) sq'
                                               (False,True,False)-> solver (score+1) (left SQ.<| rest)
                                               (_,_,False)       -> (score,False)
                                               

main::IO()
main=do
  str<-getLine
  let (sc,b) = solver 0 (SQ.fromList str)
  print (if b then sc else (-1))

Measured memory_bytes: 6908
n,l=map(int,input().split())

aji=[]
for i in range(1,n+1):
    aji.append(l+i-1)
sum=sum(aji)
#print(aji)
#print(sum)
p=1000
for i in range(n):
    if abs(aji[i])<=abs(aji[i-1]):
        p=aji[i]
        #print(aji[i])
print(sum-p)

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

int main() {
	int d, n;
	cin >> d >> n;
	if (d == 0) {
		if (n == 100)
			cout << 101 << endl;
		else
			cout << n << endl;
	}
	else if (d == 1) {
		if (n == 100)
			cout << 10100 << endl;
		else
			cout << 100 * n << endl;
	}
	else {
		if (n == 100)
			cout << 1010000 << endl;
		else
			cout << 10000 * n << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int minTrain, minBus;
    minTrain = A > B ? B : A;
    minBus = C > D ? D : C;

    cout << minTrain + minBus << "\n";

    return 0;
}


Measured memory_bytes: 256
n,x,y=map(int,input().split())
ans=[0]*n #個数を数えるのにバケットを用意する
for i in range(1,n+1): #i<jなるすべての頂点の組について最短距離を求める
    for j in range(i+1,n+1):
        dist1=j-i
        dist2=abs(x-i)+abs(y-j)+1
        d=min(dist1,dist2) #最短距離は上式により求められる
        ans[d]+=1 #最短距離がdとなる組の個数を1増やす
for i in range(1,n):
    print(ans[i])

Measured memory_bytes: 3444
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    X,Y = map(int, input().split())
    ans = 0
    num = X
    while num <= Y:
        num *= 2
        ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3700
import sys
input = sys.stdin.readline
 
MOD = 10**9 + 7
U = 2 ** 20
 
N = int(input())
A = [int(x) for x in input().split()]
 
arr_0 = [1] * U
arr_1 = [0] * U
 
zero_update = [0] * U #0が出てきて更新した回数
zero_cnt = 0
 
c = 0
for a in A:
  c ^= a
  if c == 0:
    zero_cnt += 1
    continue
  n = zero_cnt - zero_update[c]
  zero_update[c] = zero_cnt
  a = arr_0[c]
  b = arr_1[c]
  a,b = a+n*b,b
  a,b = a,a+b
  a %= MOD
  b %= MOD
  arr_0[c] = a
  arr_1[c] = b
 
answer = 0
if c != 0:
  answer = arr_0[c]
else:
  answer = sum(arr_1[1:])
  answer += pow(2,zero_cnt-1,MOD)
  answer %= MOD
print(answer)


Measured memory_bytes: 125524
#include<iostream>
using namespace std;
using ll = long long;
int N;
ll L[87];

int main() {
	cin >> N;
	
	L[0] = 2, L[1] = 1;

	for (int i = 2; i <= N; i++) {
		L[i] = L[i - 2] + L[i - 1];
	}

	cout << L[N] << endl;
}

Measured memory_bytes: 3584