akhauriyash/Code-Regression huggingface dataset:
n = int(input())
v = list(map(int, input().split()))

va = v[0::2]
vb = v[1::2]

ma, mb = {None: 0}, {None: 0}
for vi in va:
    c = ma[vi] if vi in ma else 0
    ma[vi] = c + 1
for vi in vb:
    c = mb[vi] if vi in mb else 0
    mb[vi] = c + 1

# items() is [(k, m[k]) for k in m.keys()]
pa = list(ma.items())
pb = list(mb.items())
pa.sort(key=lambda x: x[1], reverse=True)
pb.sort(key=lambda x: x[1], reverse=True)

if pa[0][0] == pb[0][0]:
    if pa[0][1] < pb[0][1]:
        ans = n - pa[1][1] - pb[0][1]
    elif pa[0][1] > pb[0][1]:
        ans = n - pa[0][1] - pb[1][1]
    else:
        h = pa[0][1]
        if pa[1][1] < pb[1][1]:
            ans = n - h - pb[1][1]
        else:
            ans = n - h - pa[1][1]
else:
    ans = n - pa[0][1] - pb[0][1]
print(ans)


Measured memory_bytes: 21568
H, W, K=map(int, input().split())
List = [list(input()) for _ in range(H)]

MAP=[[0 for j in range(W)] for i in range(H)]

for i in range(H):
    for j in range(W):
        if List[i][j]=='#':
          MAP[i][j]=1

MAPP=[[0 for j in range(W)] for i in range(H)]
bx=[0]*W
by=[0]*H
c=[0]*2**H*2**W
for i in range(2**H*2**W):
    b=format(i,'b').zfill(H+W)
    for jx in range(W):
      bx[jx]=int(b[-W+jx])
    for jy in range(H):
      by[jy]=int(b[jy])
    for k in range(H):
      for l in range(W):
        MAPP[k][l]=MAP[k][l]*bx[l]*by[k]
    c[i]=sum(map(sum, MAPP))

print(c.count(K))

Measured memory_bytes: 9224
/*  -*- coding: utf-8 -*-
 *
 * a.cc: C: Attention
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 300000;
const int INF = 1 << 30;

/* typedef */

/* global variables */

char s[MAX_N + 4];
int ens[MAX_N + 1];

/* subroutines */

/* main */

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

  ens[0] = 0;
  for (int i = 0; i < n; i++)
    ens[i + 1] = ens[i] + (s[i] == 'E' ? 1 : 0);

  int mind = INF;
  for (int i = 0; i < n; i++) {
    int d = (i - ens[i]) + (ens[n] - ens[i + 1]);
    if (mind > d) mind = d;
  }

  printf("%d\n", mind);
  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
vvi g;
vi dp;
ll dfs(int i){
    if(dp[i]!=-1)return dp[i];
    ll res=0;
    for(ll x:g[i])chmax(res,dfs(x)+1);
    return res;
}
int main(){
    ll n,m;cin>>n>>m;
    vvi dp(n,vi(m));
    vvb ok(n,vb(m,false));
    rep(i,n){
        string s;cin>>s;
        rep(j,m){
            if(s[j]=='.')ok[i][j]=true;
        }
    }
    dp[0][0]=1;
    rep(i,n-1)if(ok[i+1][0])dp[i+1][0]+=dp[i][0];
    rep(i,n-1)if(ok[0][i+1])dp[0][i+1]+=dp[0][i];
    rep(i,n-1){
        rep(j,m-1){
            if(ok[i+1][j+1]){
                dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1])%mod;
            }
        }
    }
    out(dp[n-1][m-1]);
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> S(N);
  for(int i=0;i<N;i++){
    cin>>S.at(i);
  }
  sort(S.begin(),S.end());
  int ans=1;
  for(int i=0;i<N-1;i++){
    if(S.at(i)<S.at(i+1)) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
 
int d[10][10];
int c[10][10];
int main(){
  int h,w;
  cin>>h>>w;
  REP(i,10){
    REP(j,10){
      cin>>c[i][j];
      d[i][j]=c[i][j];
    }
  }
  REP(k,10){
    REP(i,10){
      REP(j,10){
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
  int a[h][w];
  long long ans=0;
  REP(i,h){
    REP(j,w){
      cin>>a[i][j];
      if(a[i][j]==-1){
        continue;
      }else{
        ans += d[a[i][j]][1];
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
using namespace std;
  
int main () {
  int n[3];
  cin >> n[0] >> n[1] >> n[2];
  sort (n, n+3);
  cout << n[0] << " " << n[1] << " " << n[2] << endl;
  return 0;
}

Measured memory_bytes: 3132
def min(a,b)
    a < b ? a : b
end

n=gets.to_i
s=n.times.map{gets.chomp.chars}

cnt=0
x,y,z=0,0,0
n.times do |i|
    x += 1 if s[i][-1] == 'A' && s[i][0] != 'B'
    y += 1 if s[i][-1] != 'A' && s[i][0] == 'B'
    z += 1 if s[i][-1] == 'A' && s[i][0] == 'B'
    (s[i].size-1).times do |j|
        cnt += 1 if s[i][j] == 'A' && s[i][j+1] == 'B'
    end
end
m = min(x,y)
t = z
if z == 0
    t = m
else
    if x+y == 0
        t -= 1
    else
        t += m
    end
end

puts t + cnt


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

using ll=long long; 

bool hantei(vector<int> p){
	for(int i=1; i<p.size(); i++){
		if(p[i-1]>p[i]){
			return false;
		}
	}
	return true;
}

void solve(){
	int n;
	cin>>n;
	vector<int>p(n);
	for(int i=0; i<n; i++)cin>>p[i];
	if(hantei(p)){
		cout<<"YES"<<endl;
		return;
	}
	for(int i=0; i<n-1; i++){
		for(int j=i+1; j<n; j++){
			swap(p[i], p[j]);
			if(hantei(p)){
				cout<<"YES"<<endl;
				return;
			}
			swap(p[i], p[j]);
		}
	}
	cout<<"NO"<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
n, a, b, c = map(int, input().split())
l = [int(input()) for i in range(n)]
min_ = 10**18
for i in range(4**n):
  la = []
  lb = []
  lc = []
  for j in range(n):
    i, amari = divmod(i, 4)
    if amari == 1:
      la.append(l[j])
    elif amari == 2:
      lb.append(l[j])
    elif amari == 3:
      lc.append(l[j])
    
    if len(la)>0 and len(lb)>0 and len(lc)>0:
      min_ = min(min_, abs(sum(la)-a)+10*(len(la)-1)+abs(sum(lb)-b)+10*(len(lb)-1)+abs(sum(lc)-c)+10*(len(lc)-1))
      
print(min_)

Measured memory_bytes: 3064
n = int(input())
a = [int(i) for i in input().split()]
m = 1000
s = 0
for i in range(n - 1):
    if a[i] > a[i + 1]:
        m += s * a[i]
        s = 0
    elif a[i] < a[i + 1]:
        b = m // a[i]
        m -= a[i] * b
        s += b
print(m + s * a[-1])


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

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

  int count = 1;
  while(count == 1){
    count = 0;
    if(strlen(s.c_str()) >= 5){
      if((s.substr(strlen(s.c_str())-5,5) == "dream") || (s.substr(strlen(s.c_str())-5,5) == "erase")){
        s.erase(s.end()-5, s.end());
        count = 1;
      }
    }

    if(strlen(s.c_str()) >= 6){
      if(s.substr(strlen(s.c_str())-6,6) == "eraser"){
        s.erase(s.end()-6, s.end());
        count = 1;
      }
    }

    if(strlen(s.c_str()) >= 7){
      if(s.substr(strlen(s.c_str())-7,7) == "dreamer"){
        s.erase(s.end()-7, s.end());
        count = 1;
      }
    }

  }

  if(s == ""){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.*;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author HBonsai
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CEnergyDrinkCollector solver = new CEnergyDrinkCollector();
        solver.solve(1, in, out);
        out.close();
    }

    static class CEnergyDrinkCollector {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            List<Pair> stores = new ArrayList<>();

            for (int i = 0; i < N; i++) {
                stores.add(new Pair(in.nextLong(), in.nextLong()));
            }
            stores.sort(Comparator.comparing(p->p.first));

            long ans = 0;
            long remain = M;
            out:
            for (int i = 0; i < N; i++) {
                Pair store = stores.get(i);
                for (long j = store.second; j > 0; j--) {
                    ans += store.first;
                    remain--;
                    if (remain <= 0) break out;
                }
            }
            out.println(ans);
        }

        class Pair {
            public long first;
            public long second;

            public Pair(long first, long second) {
                this.first = first;
                this.second = second;
            }

        }

    }
}


Measured memory_bytes: 95972
#include <cstdio>
#include <algorithm>
#include <vector>

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

using namespace std;

typedef long long ll;

int n, k;
vector<int> z[3];
vector<int> comp[3];
 
int s[100][100][100];

int main(){
	vector<int>& x = z[0];
	vector<int>& y = z[1];
	vector<int>& d = z[2];

	scanf("%d%d", &n, &k);
	rep(i, 3){
		z[i].resize(2 * n);
	}
	rep(i, n){
		scanf("%d%d%d", &x[i], &y[i], &d[i]);
		scanf("%d%d%d", &x[i + n], &y[i + n], &d[i + n]);
	}

	rep(i, 3){
		comp[i] = z[i];
		sort(comp[i].begin(), comp[i].end());
		comp[i].erase(unique(comp[i].begin(), comp[i].end()), comp[i].end());
		rep(j, 2 * n){
			z[i][j] = lower_bound(comp[i].begin(), comp[i].end(), z[i][j]) - comp[i].begin();
		}
	}

	rep(i, n){
		int sx = x[i];
		int ex = x[i + n];
		int sy = y[i];
		int ey = y[i + n];
		int sd = d[i];
		int ed = d[i + n];
		s[sx][sy][sd] += 1;
		s[ex][sy][sd] -= 1;
		s[sx][ey][sd] -= 1;
		s[sx][sy][ed] -= 1;
		s[sx][ey][ed] += 1;
		s[ex][sy][ed] += 1;
		s[ex][ey][sd] += 1;
		s[ex][ey][ed] -= 1;
	}

	rep(a, 3){
		int dz[3] = {0, 0, 0};
		dz[a] = 1;
		for(int p = dz[0]; p < 2 * n; ++p){
			for(int q = dz[1]; q < 2 * n; ++q){
				for(int r = dz[2]; r < 2 * n; ++r){
					s[p][q][r] += s[p - dz[0]][q - dz[1]][r - dz[2]];
				}
			}
		}
	}

	/*
	rep(r, 2 * n){
		rep(p, 2 * n){
			rep(q, 2 * n){
				printf("%d", s[p][q][r]);
			}
			printf("\n");
		}
		printf("\n");
	}
	*/

	ll ans = 0;
	rep(p, 2 * n){
		rep(q, 2 * n){
			rep(r, 2 * n){
				if(s[p][q][r] >= k){
					ll dx = comp[0][p + 1] - comp[0][p];
					ll dy = comp[1][q + 1] - comp[1][q];
					ll dd = comp[2][r + 1] - comp[2][r];
					ans += (dx * dy * dd);
				}
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 6656
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        var K = int.Parse(ReadLine());
        int v = 7%K;
        
        var used = new bool[(int)K];
        used[v] = true;
        if (used[0])
        {
            WriteLine(1);
            return;
        }

        int num = 2;
        while (true)
        {
            v = (v * 10 + 7) % K;
            
            if (used[(int)v])
            {
                WriteLine(-1);
                return;
            }
            used[(int)v] = true;
            if (used[0])
            {
                WriteLine(num);
                return;
            }
            num+=1;
        }

    }
    public static int ModPow(int x, int n, int mod)
    {
        long res = 1;
        while (n > 0)
        {
            if ((n & 1) > 0) res = res * x % mod;
            x = x * x % mod;
            n >>= 1;
        }
        return (int)res;
    }
}
class Modular
{
    public static int M = 1000000007;
    public int setM { set { M = value; } }
    private long value;
    public Modular(long value) { this.value = value; }
    public static implicit operator Modular(long a)
    {
        var m = a % M;
        return new Modular((m < 0) ? m + M : m);
    }
    public static Modular operator +(Modular a, Modular b)
    {
        return a.value + b.value;
    }
    public static Modular operator -(Modular a, Modular b)
    {
        return a.value - b.value;
    }
    public static Modular operator *(Modular a, Modular b)
    {
        return a.value * b.value;
    }
    public static Modular Pow(Modular a, int n)
    {
        switch (n)
        {
            case 0:
                return 1;
            case 1:
                return a;
            default:
                var p = Pow(a, n / 2);
                return p * p * Pow(a, n % 2);
        }
    }
    public static Modular operator /(Modular a, Modular b)
    {
        return a * Pow(b, M - 2);
    }
    private static readonly List<int> facs = new List<int> { 1 };
    private static Modular Fac(int n)
    {
        for (int i = facs.Count; i <= n; ++i)
        {
            facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
        }
        return facs[n];
    }
    public static Modular Ncr(int n, int r)
    {
        return (n < r) ? 0
             : (n == r) ? 1
                        : Fac(n) / (Fac(r) * Fac(n - r));
    }
    public static explicit operator int(Modular a)
    {
        return (int)a.value;
    }
}


Measured memory_bytes: 28472
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        String winner = "second";
        for(long i = 0; i < n; i++){
            long a = sc.nextLong();
            if(a % 2 == 1){
                winner = "first";
                break;
            }
        }
        System.out.println(winner);
    }
}


Measured memory_bytes: 50112
#include<stdio.h>
#include<math.h>
int main(){
	double a[10][2];
	double ans = 0;
	int N,i,j;
	scanf("%d",&N);
	for(i = 1;i <= N;i++)
		scanf("%lf%lf",&a[i][0],&a[i][1]);
	for(i = 1;i <= N;i++)
		for(j = 1;j <= N;j++){
			ans+=sqrt((a[i][0]-a[j][0])*(a[i][0]-a[j][0])+(a[i][1]-a[j][1])*(a[i][1]-a[j][1]));
		}
		ans = ans/N;
		printf("%.10lf",ans);
	     
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vi a(n); for(auto& e : a) cin >> e;

    set<int> s;
    for(auto& e : a){
        if(s.find(e) == end(s)){
            s.insert(e);
        }
        else {
            s.erase(e);
        }
    }

    cout << s.size() << endl;

    return 0;
}


Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b) {
	if (!b)return a; return gcd(b, a%b);
}
signed main() {
	int w, h, c; cin >> w >> h >> c;
	cout << w*h / gcd(w, h) / gcd(w, h)*c << endl;
}



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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
int main(){
  int n,ma,mb;cin>>n>>ma>>mb;
  int dp[42][410][410]={};
  for(int i=0;i<42;i++)
    for(int j=0;j<410;j++)
      for(int k=0;k<410;k++)
	dp[i][j][k]=INF;
  pair<pair<int,int>,int> yaku[n+10];
  for(int i=0;i<n;i++){
    cin>>yaku[i].F.F>>yaku[i].F.S>>yaku[i].S;
  }
  dp[0][0][0]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<400;j++){
      for(int k=0;k<400;k++){
	if(dp[i][j][k] != INF){
	  dp[i+1][j+yaku[i].F.F][k+yaku[i].F.S]
	    =min(dp[i+1][j+yaku[i].F.F][k+yaku[i].F.S],dp[i][j][k]+yaku[i].S);
	}
	dp[i+1][j][k]=min(dp[i][j][k],dp[i+1][j][k]);
      }
    }
  }
  int a=ma,b=mb;
  int ans=INF;
  while(a<=400&&b<=400){
    ans=min(ans,dp[n][a][b]);
    a+=ma;
    b+=mb;
  }
  if(ans!=INF)
    cout<<ans<<endl;
  else
    cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 27776
from collections import Counter
N = int(input())
S = input()
tmp = Counter(S)
# print(tmp)
r = tmp["R"]
g = tmp["G"]
b = tmp["B"]
ans = 0
# for s in S:
#     if s == "R":
#         r += 1
#     elif s == "G":
#         g += 1
#     else:
#         b += 1

for i in range(len(S) - 2):
    j = 1
    if S[i] == "R":
        ans += g * b
        r -= 1
    elif S[i] == "G":
        ans += r * b
        g -= 1
    else:
        ans += r * g
        b -= 1
    
    while not (i + j + j >= len(S)):
        if S[i] == "R":
            if S[i + j] == "R":
                j += 1
                continue
            if S[i + j] == "G" and S[i + j + j] == "B" or S[i + j] == "B" and S[i + j + j] == "G":
                ans -= 1
        if S[i] == "G":
            if S[i + j] == "G":
                j += 1
                continue
            if S[i + j] == "R" and S[i + j + j] == "B" or S[i + j] == "B" and S[i + j + j] == "R":
                ans -= 1
        if S[i] == "B":
            if S[i + j] == "B":
                j += 1
                continue
            if S[i + j] == "G" and S[i + j + j] == "R" or S[i + j] == "R" and S[i + j + j] == "G":
                ans -= 1
        j += 1
print(ans)


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

int main(){
  vector<bool>a(6,true);
  for(int i=0;i<5;i++){
    int b;
    cin >> b;
    a.at(b) = false;
  }
  for(int i=0;i<6;i++){
    if(a.at(i)) cout << i << endl;
  }
}

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

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf INT_MAX/3
#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define ALL(a) (a).begin(),(a).end()
#define all(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define PII pair<int,int>
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define in scanf
#define out printf
#define LL long long
#define ll long long
#define ULL unsigned long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second

VI X;
int a,b;

int main(){

	cin >> a >> b;
	if(a<=0 && b >= 0 )
		cout << "Zero";
	else if(a>0 && b >0)
		cout << "Positive";
	else {
		if((a%2 == 0 && b%2 == 0 )|| (abs(a%2)  == 1 &&abs(b%2) == 1))
			cout << "Negative";
		else
			cout << "Positive";
	}


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ctype.h>
using namespace std;
 
 
int main(){
  string a,s,c;
  cin>>a>>s>>c;
  char S,A,B;
  A=toupper(a.at(0));
  B=toupper(c.at(0));
  S=toupper(s.at(0));
  cout<<A<<S<<B<<endl;
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll n,x;
    cin>>n>>x;
    ll ct=0;
    VL arr(n);
    fr(i,0,n)
        cin>>arr[i];
    fr(i,1,n)
    {
        if((arr[i]+arr[i-1])>x)
        {
            ll rem=(arr[i]+arr[i-1])-x;
            ll f=min(rem,arr[i]);
            rem-=f;
            arr[i]-=f;
            ct+=f;
            if((arr[i]+arr[i-1])>x)
            {
                ct+=rem;
            }
        }
    }
    cout<<ct<<endl;
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<":\n";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 4000
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define int long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;

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




Measured memory_bytes: 3632
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;
using System.Timers;

static class MainClass
{
    public static void Main(string[] args)
    {
        var n = Console.ReadLine();
        if (n == "1")
            Console.WriteLine("Hello World");
        else
        {
            var a = Console.ReadLine().ToInt32();
            var b = Console.ReadLine().ToInt32();
            Console.WriteLine(a + b);
        }
    }


    #region ライブラリ

    #region 文字列処理

    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();

    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    #endregion
    #region DeepClone
    public static T DeepClone<T>(this T src)
    {
        using (var memoryStream = new MemoryStream())
        {
            var binaryFormatter
              = new BinaryFormatter();
            binaryFormatter.Serialize(memoryStream, src);
            memoryStream.Seek(0, SeekOrigin.Begin);
            return (T)binaryFormatter.Deserialize(memoryStream);
        }
    }
    #endregion

    public static int Gcd(int a, int b)
    {
        if (b == 0)
            return a;
        return Gcd(b, a % b);
    }
    public static BigInteger Gcd(BigInteger a, BigInteger b)
    {
        if (b == 0)
            return a;
        return Gcd(b, a % b);
    }


    public static BigInteger Factorial(int n)
    {
        var dp = new BigInteger[n];
        dp[0] = 1;
        for (int i = 1; i < n; i++)
        {
            dp[i] = dp[i - 1] * (i + 1);
        }
        return dp[n - 1];
    }

    public static List<int> PrimeFactorize(int n)
    {
        var bases = n;
        var num = (int)Math.Pow(n, 0.5);
        var ls = new List<int>();
        for (int i = 2; i <= num; i++)
        {
            if (n % i == 0)
            {
                n = n / i;
                ls.Add(i);
                i--;
                continue;
            }
        }
        var nnn = 1;
        foreach (var item in ls)
        {
            nnn = nnn * item;
        }
        if (nnn != bases)
            ls.Add(n);
        return ls;
    }

    #endregion

}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string s;
    cin >> s;
    int q;
    cin >> q;
    int muki=0;
    deque<char> ans;
    for(char c:s){
      ans.push_back(c);
    }
    for(int i=0;i<q;i++){
        int t;
        cin >> t;
        if(t==1){
            if(muki==0)muki++;
            else muki--;
        }
        else{
            int f;
            cin >> f;
            char c;
            cin >> c;
            if((f==1&&muki==0)||(f==2&&muki==1)){
                ans.push_front(c);
            }
            else{
                ans.push_back(c);
            }
        }
    }
  if(muki==0){
    while(!ans.empty()){
        cout << ans.front();
        ans.pop_front();
    }
    cout << endl;
  }
  else{
    while(!ans.empty()){
        cout << ans.back();
        ans.pop_back();
    }
    cout << endl;
  } 
}


Measured memory_bytes: 3900
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ld long double
const int M = 1e9+7;

vector<int> a;
vector<int> ind;
vector<int> dp;

int32_t main(){
	int n;
	cin>>n;
	a.resize(n);
	for(int i=0;i<n;++i)
		cin>>a[i];
	ind.assign(n+1,-1);
	dp.assign(n+1,1e10);
	int ans = 1e10;
	for(int i=0;i<n;++i){
		if(a[i]==1){
			if(dp[1]<1e8)
				dp[1]=max(dp[1],i);
			else dp[1]=i;
		}
		ind[a[i]]=max(ind[a[i]],i);
		dp[a[i]]=min(dp[a[i]],dp[a[i]-1]+i-ind[a[i]-1]-1);
		ans = min(ans,dp[a[i]]+(n-i-1));

		// cout << a[i] << ' ' << dp[a[i]] << endl;
	}
	if(ans>1e7){
		cout << "-1\n";
	}else{
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 4992
const main = (inputs) => {
  var array = inputs[0].split(" ");
  if (Number(array[0]) > Number(array[1])) {
    console.log('safe');
  } else {
    console.log('unsafe');
  }

}
main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));

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

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

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

    sort(l, l + 2 * n);
    int ans = 0;
    for(int i = 0; i < 2 * n; i += 2){
        ans += l[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
require 'set'

n, k = gets.split.map(&:to_i)
l, r = k.times.map{ gets.split.map(&:to_i) }.transpose

dp = Array.new(n, 0)
sdp = Array.new(n+1, 0)
dp[0] = 1
sdp[1] = 1

(1...n).each do |i|
  k.times do |j|
    right = [0, i - l[j]+1].max
    left = [0, i - r[j]].max

    dp[i] += sdp[right] - sdp[left]
    dp[i] %= 998244353
  end

  sdp[i+1] += sdp[i] + dp[i]
  sdp[i+1] %= 998244353
end

p dp[n-1]


Measured memory_bytes: 17556
#import<bits/stdc++.h>
#define LL long long
using namespace std;
typedef struct{int x;int y;}H;
int a,b,c,i,j,k,m,n,s,t,x,y,z,w[100005];
int pv[300000];
char h,u[105];
H e[200040];
queue<int>B,D;
int A(H a,H b){return a.x<b.x||a.x==b.x&&a.y<b.y;}
void BP(void);
void bfs(int s);
void dfs(int s);
int dgs(int x){int s=0;for(;x;x/=10)s+=x%10;return s;}
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int max2(int x,int y){return x>y?x:y;}
int max3(int x,int y,int z){return x>y?x>z?x:z:y>z?y:z;}
int min2(int x,int y){return x<y?x:y;}
int min3(int x,int y,int z){return x<y?x<z?x:z:y<z?y:z;}
int prime(int x){if(x<2||x%6^1&&x%6^5)return x==2|x==3;for(int i=5;i*i<=x;i+=6)if(x%i<1||x%(i+2)<1)return 0;return 1;}
int vowel(char x){return x%32==1||x%32==5||x%32==9||x%32==15||x%32==21;}
main()
{
	scanf("%d%d%d",&n,&a,&b);
	printf("%d",n*a<b?n*a:b);
}
void BP(void)
{
	for(int i=0;e[++i].x;)
	{
		if(e[i].x>e[i-1].x)
		{
			for(int j=e[i-1].x;j++<e[i].x;)
			{
				pv[j]=i;
			}
		}
	}
}
void bfs(int s)
{
	
}
void dfs(int s)
{
	
}

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

int main(void){
    ll n, m, lx = 0, rn = 1e9;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        ll l, r;
        cin >> l >> r;
        lx = max(lx, l);
        rn = min(rn, r);
    }
    
    cout << max(0ll, rn - lx+ 1) << endl;
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string w;
cin>>w;
map<char,int> cnt;
rep(i,w.size()){
    cnt[w[i]]++;
}
string ans="Yes";
for(auto v:cnt){
    if(v.second%2!=0){
        ans="No";
        break;
    }
}
cout<<ans<<endl;
return 0;
}

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

using namespace std;

int main()
{
	// 入力
	int r;
	cin >> r;
	
	// 正十二角形の面積 = 3 * (半径2乗)
	int area = 3 * pow(r, 2.0f);
	
	cout << area << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int>L(N);
  for (int i = 0; i < N; i++) {
    cin >> L.at(i);
  }
  sort(L.begin(), L.end());
  int sum = 0;
  for (int i = 0; i < N-1; i++) {
    sum += L.at(i);
  }
  if (sum > L.at(N-1)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 3628
#include<iostream>
#include<stdio.h>
using namespace std;
int main() {
	double r,x,y;
	cin>>r;
	x=3.141592653589*r*r;
	y=2*3.141592653589*r;
	printf("%f",x);
	cout<<" ";
	printf("%f",y);
	return 0;
} 



Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int i = 0;
        while (true) {
            if (i % 2 == 0) {
                c -= b;
            } else {
                a -= d;
            }
            if (c <= 0) {
                System.out.println("Yes");
                return;
            }
            if (a <= 0) {
                System.out.println("No");
                return;
            }
            i++;
        }
    }

}


Measured memory_bytes: 35744
import sys
input = sys.stdin.readline

area_data = input()
total_area = 0
temp_area = 0

stack1 = []
stack2 = []

now_position = 0
for c in area_data:
    if c == '\\':
        stack1.append(now_position)
    elif c == '/':
        if len(stack1) > 0:
            last_potision = stack1.pop()
            temp_area = (now_position - last_potision)
            total_area += temp_area  # 前の\からの距離が、そのまま面積になる

            # print("before stack:{}".format(stack2))
            while len(stack2) > 0:
                prev_spot = stack2.pop()
                # print("prev spot:{}".format(prev_spot))
                # print("last_potision:{}".format(last_potision))
                if prev_spot[0] > last_potision:
                    temp_area += prev_spot[1]
                else:
                    stack2.append(prev_spot)
                    break

            stack2.append((last_potision, temp_area))

        # print("stack2:{}".format(stack2))

    now_position += 1

print(total_area)
print(len(stack2), end="")
for s in stack2:
    print(" ", end="")
    print(s[1], end="")
print()



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

int main(){
  int x,S[100],i=0;
  char s[100];

  for(i=0;scanf("%s", s) != EOF; ){

    if ( s[0] == '+' ){
      S[i-2]=S[i-2]+S[i-1];
      i--;
    } else if ( s[0] == '-' ){
      S[i-2]=S[i-2]-S[i-1];
      i--;
    } else if ( s[0] == '*' ){
      S[i-2]=S[i-2]*S[i-1];
      i--;
    } else {
      x = atoi(s);
      S[i]=x;
      i++;
    }
  }
  printf("%d\n",S[i-1]);
  return 0;
}

Measured memory_bytes: 2692
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define INF 0X3F3F3F3F
#define N 100005
#define M 2000005
#define LL long long
#define FF(i, a, b) for(int i = a; i <= b; ++i)
#define RR(i, a, b) for(int i = a; i >= b; --i)
#define FJ(i, a, b) for(int i = a; i < b; ++i)
#define SC(x) scanf("%d", &x)
#define SCC(x, y) scanf("%d%d", &x, &y)
#define SCCC(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define SS(x) scanf("%s", x)
#define PR(x) printf("%d\n", x)
#define CL(a, x) memset(a, x, sizeof(a))
#define _P fd[rt]
#define _L fd[rt << 1]
#define _R fd[rt << 1 | 1]
#define MID int mid = ((l + r) >> 1)
#define lson rt<<1 ,l, mid
#define rson rt<<1 | 1, mi d + 1, r
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define MP make_pair
#define PB push_back
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-8;
inline void II(int &n){char ch = getchar(); n = 0; bool t = 0;
for(; ch < '0'; ch = getchar()) if(ch == '-') t = 1;
for(; ch >= '0'; n = n * 10 + ch - '0', ch = getchar()); if(t) n =- n;}
inline void OO(int a){if(a < 0) {putchar('-'); a = -a;}
if(a >= 10) OO(a / 10); putchar(a % 10 + '0');}
inline int sgn(double x){return (x > EPS) - (x < -EPS);}
int vis[10000005], pri[M], prn;
void init(){
    for(int i = 2; i < 10000000; ++i){
        if(vis[i] == 0) pri[++prn] = i;
        for(int j = 1; j <= prn && i * pri[j] <= 10000000; ++j){
            vis[i * pri[j]] = 1;
            if(i % pri[j] == 0) break;
        }
    }
}
int n, a[300], c[300], cnt, l[300], r[300], ln, rn;
bool mp[300][300];
int vv[300], link[300], ii;
bool dfs(int u){
    FF(v, 1, rn) if(mp[u][v]){
        if(vv[v] != ii){
            vv[v] = ii;
            if(!link[v] || dfs(link[v])){
                link[v] = u;
                return 1;
            }
        }
    }
    return 0;
}
int main(){
//    IN;
    init();
    vis[0] = vis[1] = vis[2] = 1;
    SC(n);
    FF(i, 1, n) SC(a[i]);
    int p = 1;
    while(p <= n){
        c[++cnt] = a[p];
        int pp = p;
        while(pp < n && a[pp + 1] == a[pp] + 1) ++pp;
        c[++cnt] = a[pp] + 1;
        p = pp + 1;
    }
    FF(i, 1, cnt){
        if(c[i] & 1) l[++ln] = c[i];
        else r[++rn] = c[i];
    }
    FF(i, 1, ln)FF(j, 1, rn){
        if(vis[abs(l[i] - r[j])] == 0) mp[i][j] = 1;
    }
    int s = 0;
    for(ii = 1; ii <= ln; ++ii){
        if(dfs(ii)){
            ++s;
        }
    }
    int ans = s;
    ans += ((ln - s) / 2 + (rn - s) / 2) * 2;
    ans += (ln - s) % 2 ? 3 : 0;
    printf("%d\n", ans);
    return 0;
}


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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(long long i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const double EPS = 1e-9;
const ll powll = 1LL<<1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int main(void){
    int h,w; cin >> h >> w;
    string s[h];
    rep(i,0,h){
        cin >> s[i];
    }
    ll dp[h][w];
    rep(i,0,h){
        rep(j,0,w){
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;
    rep(i,0,h){
        rep(j,0,w){
            if(s[i][j] == '.'){
                if(i > 0){
                    dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD;
                }
                if(j > 0){
                    dp[i][j] = (dp[i][j] + dp[i][j-1]) % MOD;
                }
            }
            //cout << dp[i][j] << " ";
        }
        //cout << "\n";
    }
    cout << dp[h-1][w-1] << "\n";
}

Measured memory_bytes: 13308
import java.util.Scanner;

public class Main {

    public String shffl(String inS, int num) {
        String buf1 = inS.substring(0, num);
        String buf2 = inS.substring(num, inS.length());
        inS = buf2.concat(buf1);
        return inS;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Main app = new Main();

        while(true) {
            String pattern = scan.next();
            if (pattern.equals("-")) break;
            int times = Integer.parseInt(scan.next());
            for (int i = 0; i < times; i++) {
                int num = Integer.parseInt(scan.next());
                pattern = app.shffl(pattern, num);
            }
            System.out.println(pattern);
        }
    }
}


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int main() {
	int N, A;
	cin >> N >> A;
	cout << N + 1 - A << endl;
	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const int inf=1<<29;
int dist[201][201];
int r[8];
int main() {
	int N,M,R;
	cin >> N >> M >> R;
	for(int i=0;i<R;i++){
		cin >>  r[i];
	}
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++){
			dist[i][j]=inf;
		}
		dist[i][i]=0;
	}
	for(int i=0;i<M;i++){
		int a,b,c;
		cin >> a>>b>>c;
		dist[a][b]=dist[b][a]=c;
	}
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++){
			for(int k=1;k<=N;k++){
				dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k]);
			}
		}
	}
	sort(r,r+R);
	int ret=inf;
	do{
		int d=0;
		for(int i=1;i<R;i++){
			d+=dist[r[i-1]][r[i]];
		}
		ret=min(ret,d);
	}while(next_permutation(r,r+R));

	cout << ret << endl;

	return 0;
}



Measured memory_bytes: 384
// C - Synthetic Kadomatsu
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

int N;
vi A(4), L(8);
int ans = INT_MAX;

void calc(vi v){
	vi sum(4), count(4);
	for(int i=0; i<N; ++i){
		count[v[i]]++;
		sum[v[i]] += L[i];
	}

	if(min({count[1], count[2], count[3]})!=0){
		int s = 0;
		for(int i=1; i<4; ++i){
			s += abs(A[i] - sum[i]);
			if(count[i]>1) s += (count[i]-1) * 10;
		}
		ans = min(ans, s);
	}
}

int main(){
	cin>>N;
	for(int i=1; i<4; ++i) cin>>A[i];
	for(int i=0; i<N; ++i) cin>>L[i];
	int E = 1<<(N*2);
	for(int i=0; i<E; ++i){
		vi v(N);
		for(int j=0; j<N; ++j) v[j] = (i>>(2*j)) & 3;
		calc(v);
	}
	cout<< ans <<endl;
}

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

using namespace std;

int main(void){
    
    unsigned int N, K;
    string S;
    std::cin >> N >> S >> K;
    
    for(int i=0; i<N; i++){
        if(S[i]!=S[K-1]){
            S[i] = '*';
        }
    }
    
    std::cout << S << std::endl;
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use std::cmp::{max, min};

#[fastout]
fn main() {
    input! {
    s: Chars
    }
    for i in 0..s.len() -1 {
        if s[i] == s[i + 1]{
            println!("Bad");
            return
        }
    }
    println!("Good");
}


Measured memory_bytes: 2156
sure =[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())

print(sure[k-1])

Measured memory_bytes: 3060
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let a: Vec<i64> = read_vec();

    let mut x_1 = 0;
    for i in 0..n {
      if i % 2 == 0 {
        x_1 += a[i];
      } else {
        x_1 -= a[i];
      }
    }
    x_1 /= 2;
    let mut v: Vec<i64> = vec![0; n];
    v[0] = x_1;

    for i in 1..n {
      v[i] = a[i-1] - v[i-1];
    }

    for i in 0..n {
      print!("{} ", v[i] * 2);
    }
    println!("");

}


Measured memory_bytes: 8444
#include<stdio.h>
 int abs2(int A){
     int a;
     if(A>=0){a=A;}else{a=-A;}
     return a;
}
int min(int n,int x[]){
    int y,i=0,j=0;
    y=x[0];
    while(i<n){
        if(x[i]<y){
            y=x[i];
            j=i;
        }
        i++;
    }
    return j+1;
}
 
int main(void){
    int N,T,A,h;
    int d;
    scanf("%d%d%d",&N,&T,&A);
    int H[N],a[N];
    for(int i=0;i<N;i++){
        scanf("%d",&H[i]);
    }
    for(int i=0;i<N;i++){
        d=H[i]*6;
        a[i]=abs2(1000*A-1000*T+d);
    }
int Answer=min(N,a);
    printf("%d\n",Answer);
        return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

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

	int N;
	cin >> N;

	vector<int> side(N);
	for (int i = 0; i < N; i++) cin >> side[i];
	sort(side.begin(), side.end());

	int sum = 0;
	for (int i = 0; i < (int)side.size() - 1; i++) sum += side[i];

	if (sum > side.back()) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int tmpsu=sc.nextInt();
		int[] iki_tra=new int[tmpsu];		// kae_tra,iki_traはトランポリンの飛べる距離
		int[] kae_tra=new int[tmpsu];		//kae_traはiki_traをひっくり返したもの
		int iki_toutatuka=0;
		int kae_toutatuka=0;


		for(int i=0; i<tmpsu; i++) {
			iki_tra[i]=sc.nextInt();
			kae_tra[tmpsu-1-i]=iki_tra[i];
		}

		for(int i=0; i<tmpsu; i++) {
			if(iki_toutatuka<10*i) {
				System.out.println("no");
				System.exit(0);
			}
			int tmp=i*10+iki_tra[i];

			if(tmp>iki_toutatuka) {
				iki_toutatuka=tmp;
			}
		}
		for(int i=0; i<tmpsu; i++) {
			if(kae_toutatuka<10*i) {
				System.out.println("no");
				System.exit(0);
			}
			int tmp=i*10+kae_tra[i];

			if(tmp>kae_toutatuka) {
				kae_toutatuka=tmp;
			}
		}
		System.out.println("yes");
	}
}


Measured memory_bytes: 108876
#include <stdio.h>
#define MAX 100000
#define NIL -1

typedef struct{
  int p,l,r;
}Node;
 
Node T[MAX];
 
int depth(int x){
  if(T[x].p == NIL){
    return 0;
  }
  else{
    return depth(T[x].p) + 1;
  }       
}

void cprint(int y){
  if(y == NIL) return;

  if(T[y].r == NIL){
    printf("%d",y);
  }

  else{printf("%d, ",y);
  }

  if(T[y].r == NIL)return;
 
  cprint(T[y].r);
}
 
void print(int z){
 
  printf("node %d: parent = %d, depth = %d, %s, [",z,T[z].p,depth(z),T[z].p == NIL?"root":(T[z].l == NIL?"leaf":"internal node"));
  cprint(T[z].l);
  printf("]\n");
} 
 
 
int main(){
  int i,j,n,v,s,c,tmp;
   
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    T[i].p = NIL;
    T[i].l = NIL;
    T[i].r = NIL;
  }

  for(i = 0;i < n;i++){
    scanf("%d",&v);
    scanf("%d",&s);
    for(j = 0;j < s;j++){
      scanf("%d",&c);
      T[c].p = v;
      if(j == 0){
	T[v].l = c;
      }else{
	T[tmp].r = c;
      }
      tmp = c;     
    }
  } 
  for(i = 0;i < n;i++){
    print(i);
  }
  return 0;
}

Measured memory_bytes: 1784