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

public class Main {

	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception addd) {
					addd.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception addd) {
				addd.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	
	public static FastReader sc = new FastReader();
 
	static int mod = (int) (1e9+7),MAX=(int) (2e5+100);
    static List<Integer>[] edges;
    static long[][] dp = new long[3010][3010];
    static int n,d;
    static char[] s;
    /*
     * dp(i,remain,small,greater)-> dp(i,g)-> remain = N-i+1, remain = small + greater
     * for "<" dp(i,g) => for(j 1..g) sum of dp(i+1,g-j)
     * for ">" dp(i,g) => for(j 0..s-1) sum of dp(i+1,g+j) 
     * Time is O(n^3)
     * 
     * for O(n^2)
     * expand dp(i,g+1) then we can see relation 
     * for "<" dp(i,g+1) => dp(i,g) + dp(i+1,g)
     * for ">" dp(i,g+1) => dp(i,g) - dp(i+1,g)
     */
	public static void main(String[] args) {
	
		int n=sc.nextInt();
		char s[]=("#"+sc.next()).toCharArray();
		
		// for last pos -> if we have 0 greater than only 1 smaller is left
		// or for 1 greater 0 smaller is left
		
		dp[n][0] = (s[n-1]=='>')?1:0;
		dp[n][1] = (s[n-1]=='<')?1:0;
		
		
		for(int i=n-1;i>=2;i--){
			int tot=n-i+1;
			for(int g=0;g<=tot;g++){
				if(g == 0){
					dp[i][g]=0;
					if(s[i-1] == '<')	continue;
					for(int j=1;j<=tot;j++) dp[i][g] = (dp[i][g] + dp[i+1][tot-j])%mod;
					
				}else{
					
					if(s[i-1] == '<') dp[i][g] = (dp[i][g-1] + dp[i+1][g-1])%mod;
					else dp[i][g] = (dp[i][g-1] - dp[i+1][g-1] + mod)%mod;	
				}
			}
			
		}
		long ans=0;
		for(int i=1;i<=n;i++)
			ans=(ans+dp[2][n-i])%mod;
		
	    out.println(ans);
		out.close();
   }
	
}



Measured memory_bytes: 130380
n,x,y=map(int,input().split())
from collections import Counter
c=Counter()
for i in range(1,n):
  for j in range(i+1,n+1):
    d=min(abs(j-i),abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(j-x))
    c[d]+=1

for k in range(1,n):
  print(c[k])




Measured memory_bytes: 50012
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    public static void Main()
    {
        int n = NextInt();
        int m = NextInt();
        int d = NextInt();
        double ans = 2 * (n - d) / (Math.Pow(n, 2) + .0) * (m - 1);
        if (d == 0) { ans = 1 / (n + .0) * (m - 1); }
        Console.WriteLine(ans.ToString("F10"));
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define init(c) memset(c,0,sizeof c)
#define S second
#define F first
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=20000005;
int n,k,x,t,a,m;
string s;
vi v;

void solve(){
	cin >> n >>s;
	vi b(n+10,0),r(n+10,0),g(n+10,0);	
 	for(int i =n-1;i>=0;i--){
 		r[i]=r[i+1];
 		g[i]=g[i+1];
 		b[i]=b[i+1];
 		if(s[i]=='R'){
 			r[i]++;
 		}else if(s[i]=='G'){
 			g[i]++;
 		}else{
 			b[i]++;
 		}
 	}
 	 			set<char>st;

 	ll ans = 0;
 	for(int i =0;i<n;i++){
 		if(s[i] == 'R'){
 			ans= (ans+1ll*g[i]*b[i]);
 		}else if(s[i]=='G'){
			ans= (ans+1ll*r[i]*b[i]);
 		}else{
 			ans= (ans+1ll*g[i]*r[i]);
 		}
 		for(int j=1;j<n;j++){
 			st.clear();

 			for(int e=i;e<n&&e<=i+j*2;e+=j){
 				st.insert(s[e]);
 			}

 			if(st.size()==3){
  				ans--;
 			}
 		}

 	}
 	cout << ans;
}
 
int main(){

	t=1;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3520
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,m=map(int,input().split())
dic={}
w=ac=0
for _ in range(m):
  a,b=input().split()
  if a in dic:
    if dic[a][1]:
      if b == 'WA':
        dic[a][0]+=1
      else:
        ac+=1
        w+=dic[a][0]
        dic[a][1]=False
  else:
    dic[a]=[0,True]
    if b == 'WA':
      dic[a][0]+=1
    else:
      ac+=1
      dic[a]=[0,False]

print(ac,w)


Measured memory_bytes: 25328
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int w,h,p;
  vector< pair<int,int> > v;
  cin>>w>>h;
  for(int i=0;i<w;i++)cin>>p,v.push_back(make_pair(p,1));
  for(int i=0;i<h;i++)cin>>p,v.push_back(make_pair(p,2));
  sort(v.begin(),v.end());
  w++,h++;
  int ans=0;
  for(int i=0;i<v.size();i++){
    if(v[i].second==1){
      ans+=v[i].first*h;
      w--;
    }else{
      ans+=v[i].first*w;
      h--;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 6384
#include<stdio.h>

void orz( float eye ,int LR[] )
{
	if( eye < 0.2 )
		LR[ 3 ]++ ;
	else if( eye < 0.6 )
		LR[ 2 ]++ ;
	else if( eye < 1.1 )
		LR[ 1 ]++ ;
	else
		LR[ 0 ]++ ;
	return ;
}

int main()
{
	float eye_r ,eye_l ;
	int r[ 4 ] = { 0 } ,l[ 4 ] = { 0 } ;

	while( scanf( "%f %f" ,&eye_r ,&eye_l ) != EOF )
	{
		orz( eye_r ,l ) ;
		orz( eye_l ,r ) ;
	}

	for( int i = 0 ; i < 4 ; i++ )
		printf( "%d %d\n" ,l[ i ] ,r[ i ] ) ;

	return 0 ;
}

Measured memory_bytes: 2608
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int a;
  string s;
  cin >> a >> s;
  if(a >= 3200){cout << s << endl;}
  else{cout << "red"<< endl;}
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(){
  char s[4] = "\0";

  scanf("%s", s);

  if(s[0] == 'A' && s[1] == 'A' && s[2] == 'A') printf("No\n");

  else if(s[0] == 'B' && s[1] == 'B' && s[2] == 'B') printf("No\n");

  else printf("Yes\n");

  return 0;
}


Measured memory_bytes: 128
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353


def main():
    N = int(input())
    d = list(map(int, input().split()))

    distance = [0] * (max(d) + 1)

    for _d in d:
        distance[_d] += 1

    if d[0] != 0 or distance[0] != 1:
        print(0)
        return

    ans = 1
    for i in range(1, len(distance)):
        n = distance[i-1]
        r = distance[i]
        ans = ans * n ** r
        ans = ans % MOD
        # print(ans)

    print(ans % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 52720
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	for (int i = 0; i < n; i++){
		cin>>a[i];
		a[i]--;
	}
	int cnt = 0;
	for (int i = 0; i < n; i++){
		if(a[i]!=i)cnt++;
	}
	cout<<((cnt==2 || cnt==0)?"YES":"NO")<<endl;
	return 0;
}

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

typedef long long ll;

int n, m;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> n >> m;
    priority_queue<ll> que;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        que.push(a);
    }
    
    for(int i = 0; i < m; ++i){
        int temp = que.top();
        que.pop();
        temp /= 2;
        que.push(temp);
    }
    
    ll ans = 0;
    while(!que.empty()){
        ans += que.top();
        que.pop();
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v) cerr << #v << ":"; rep(i, v.size()) cerr << " " << v[i]; cerr << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    ll a;
    int b, c;
    scanf("%lld %d.%d", &a, &b, &c);
    cout << a * (b * 100 + c) / 100 << endl;
}

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


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

#define AAA 10



void solve(std::string S, std::string T){
    cout << T << S << endl;

}

int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a;
	int b;
	int c;
	int d;
	cin>>a>>b>>c>>d;
	if((a*b)>(c*d))
	cout<<a*b;
	else if((c*d)>(a*b))
	cout<<c*d;
	else if((c*d)==(a*b))
	cout<<c*d;
	

	
}

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

using ll = long long;

int main(){
    ll W, H, x, y;
    std::cin >> W >> H >> x >> y;
    long double s = W * H * 0.5;
    int offset = 0;
    if(2 * x == W && 2 * y == H){
        offset = 1;
    }
    printf("%.10llf %d\n", s, offset);
    return 0;
}


Measured memory_bytes: 256
D,G = map(int,input().split())
pc = []
for i in range(D):
    p,c = map(int,input().split())
    pc.append((p,c))

l = len(bin(2**D-1)[2:])
ans = 10**10
for i in range(0,2**D):
    li = list(bin(i)[2:].zfill(l))
    s = 0
    num = 0
    rest_max = -1
    for j in range(D):
        if li[j] == '1':
            s += 100*(j+1) * pc[j][0] + pc[j][1]
            num += pc[j][0]
        else:
            rest_max = j
    if s < G:
        s1 = 100 * (rest_max + 1)
        need = (G-s+s1-1) // s1
        if need >= pc[rest_max][0]: continue
        num += need
    ans = min(ans, num)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define ft first
#define sc second
#define ppb pop_back
#define sz size
#define forn(i,a,n) for(i=a;i<n;i++)
#define M 1000000007
#define inf 2e18


int main() {


ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
    
char s;
cin>>s;
s+=1;
cout<<s;


return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int H,W,D;cin >> H >> W >> D;
  vector<vector<int> > squares(H,vector<int>(W));
  vector<PII> v(H*W+1,PII(-1,-1));
  rep(i,H)rep(j,W){
    cin >> squares[i][j];
    v[squares[i][j]] = PII(i,j);
  }
  vector<int> w(H*W+1);
  repp(i,1,D+1){
    int n = i;
    w[n] = 0;
    PII p = v[n];
    while(n+D<=H*W){
      n+=D;
      w[n] = w[n-D] + abs(p.first - v[n].first) + abs(p.second - v[n].second);
      p = v[n];
    }
  }
  int Q;cin >> Q;
  while(Q--){
    int L,R;cin >> L >> R;
    cout << w[R] - w[L] << endl;
  }
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
int n, K, h[100005], f[100005];
void init(){
    n = read(), K = read();
    for (int i = 1; i <= n; ++i)    
        h[i] = read();
}
void solve(){
    f[1] = 0;
    for (int i = 2; i <= n; ++i){
        f[i] = INT_MAX;
        for (int j = 1; j <= K && i - j >= 1; ++j)
            f[i] = min(f[i - j] + abs(h[i] - h[i - j]), f[i]);
    }
    printf("%d\n", f[n]);
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, count = 0;
    string S;
    cin >> N >> S;
    for (int i = 0; i < N-2; i++){
        if(S.at(i) == 'A'){
            if(S.at(i+1) == 'B'){
                if(S.at(i+2) == 'C'){
                    count ++;
                }
            }
        }
    }
    cout << count << endl;
}

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



int main()
{
  int N;
  cin>>N;
  for(int i=1;i<=50000;i++)
  {
    if((int)(i* 1.08)==N)
    {
        cout<<i<<endl;
        return 0;
    }
  }
  cout<<":("<<endl;
} 


Measured memory_bytes: 3604
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int a[5];
    while(cin>>a[0]){
        if(a[0]==0)break;
        for(int i=1;i<5;i++){
            cin>>a[i];
        }
        
        rep(i,5){
            bool win=true;
            bool lose=true;
            rep(j,5){
                if(i!=j){
                    if(a[j]==(a[i]+1)%3+1)win=false;
                    if(a[j]==(a[i])%3+1)lose=false;
                }
            }
            bool ai=true;
            for(int i=1;i<5;i++){
                if(a[i]!=a[i-1])ai=false;
            }
            if( (!win && !lose) || ai){
                cout<<"3"<<endl;
            }
            else if(win)cout<<"1"<<endl;
            else if(lose)cout<<"2"<<endl;

        }
        
    }
}

Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int sx,sy;
int gx,gy;
vvi tmp;
int q;
int dx[]={0,0,1,-1};
int dy[]={-1,1,0,0};
void solve(int x,int y){
	tmp[x][y]=-1;
	rep(i,4){
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(tmp[nx][ny]==q){solve(nx,ny);}
	}
}
int main(){
	int n,m;
	while(cin>>n>>m,n+m){
		vvi in(n+2,vi(m+2));
		cin>>sx>>sy>>gx>>gy;
		cin>>n;
		while(n--){
			int a,b,c,d;
			cin>>a>>b>>c>>d;
			if(!b)rep(i,4)rep(j,2)in[c+i][d+j]=a;
			else rep(i,2)rep(j,4)in[c+i][d+j]=a;
		}
		tmp=in;
		//rep(i,in.size()){rep(j,in[0].size())cout<<in[i][j]<<" ";cout<<endl;}
		if(in[sx][sy]){
			q=in[sx][sy];
			solve(sx,sy);
		}
		//cout<<endl;
		//rep(i,tmp.size()){rep(j,tmp[0].size())cout<<tmp[i][j]<<" ";cout<<endl;}
		cout<<((tmp[gx][gy]==-1)?"OK":"NG")<<endl;
		//rep(i,22){rep(j,22)cout<<tmp[i][j]<<" ";cout<<endl;}
	}
}

Measured memory_bytes: 1304
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n; cin >> n;
	vector<int>p(n);
	for (int i = 0;i < n;i++) {
		cin >> p[i];
	}
	int cnt = 0;
	for (int i = 0;i < n;i++) {
		if (i == 0 || i == n - 1)continue;
		if (p[i-1] < p[i] && p[i] < p[i + 1]) {
			cnt++;
		}
		else if (p[i - 1] > p[i] && p[i] > p[i + 1]) {
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
 
int main() {
    int a,b;
    cin >> a >> b;
    string re = "Even";
    if(a%2 ==1 && b%2 == 1){
        re = "Odd";
    }

    cout << re << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
int main(){
    string s,t;
    cin>>s;
    cin>>t;
    int len=s.length();
    for(int i=0;i<len;i++){
           int  cnt=0,flag=1;
        for(int j=len-i;j<len;j++){
            if(s[j]!=t[cnt++]){
                flag=0;
                break;
            }
        }
        if(flag==1)
        for(int j=0;j<len-i;j++){
             if(s[j]!=t[cnt++]){
                flag=0;
                break;
            }
        }
        if(flag==1) {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    
    vector<ll> vll(s.size());
    vll[s.size() - 1] = 0;
    for (auto i = s.size() - 1; i > 0; --i) {
        vll[i - 1] = vll[i] + (s[i] == 'W' ? 1 : 0);
    }
    ll res = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'B') res += vll[i];
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 2196
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){

	int n;
	cin >> n;
	int k;
	cin >> k;
	for(int i = 0; i < k; i++){
        int x,y;
        cin >> x >> y;
        int ans = min(min(x,n-x+1),min(y,n-y+1));
        printf("%d\n",ans % 3==0?3:ans%3);
	}

	return 0;
}

Measured memory_bytes: 1144
#include<stdio.h>
int main(void)
{
	int a,b,c,flg;
	scanf("%d %d",&a,&b);
	c=a+b;
	flg=0;
	if(c%3==0 || a%3==0 || b%3==0){
		flg=1;
	}
	if(flg==1){
		printf("Possible\n");
	}
	if(flg==0){
		printf("Impossible\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;

const double EPS = 1e-9;

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

void solve(){
	int a, b;
	cin >> a >> b;
	cout << ceil((a+b)/2.0) << endl;
}

int main(){
	solve();
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <vector <int>> vvi;
typedef vector <vector <long long>> vvll;
typedef vector <long long> vll;
typedef pair <int, int> pii;
typedef pair<ll , ll> pll;
typedef vector <pair <int, int>> vpii;

int main()
{
    ll n, weight; cin >> n >> weight;
    vector<ll> w(n + 1), v(n + 1);
    for(int i = 1; i<= n; i++)
    {
        cin >> w[i] >> v[i];
    }

    vvll state(n+1, vll(weight + 1, LONG_LONG_MIN));

    state[0][0] = 0;

    for(ll i = 1; i <= n; i++)
        for(ll j = 0; j <= weight; j++)
        {
            state[i][j] = max(state[i-1][j], ((j >= w[i]) ? (state[i-1][j - w[i]] + v[i]) : LONG_LONG_MIN));
        }
    
    ll ans = LONG_LONG_MIN;
    for(ll j = 0; j <= weight; j++)
        ans = max(ans, state[n][j]);
    cout << ans << endl;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	vector<vector<int>> ch(n + n);
	multiset<ll> S;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	sort(a.begin(), a.end());
	int root = n;
	ch[root] = {n - 1, 0};
	for (int i = 1; i + 1 < n; ++i) {
		if (a[i] <= 0) {
			ch[root + 1] = {root, i};
		} else {
			ch[root + 1] = {i, root};
			swap(ch[root][0], ch[root][1]);
		}
		++root;
	}
	vector<pair<ll, ll>> ans;
	function<ll(int)> solve = [&](int v) {
		if (v < n) return (ll)a[v];
		ll x = solve(ch[v][0]);
		ll y = solve(ch[v][1]);
		ans.emplace_back(x, y);
		return x - y;
	};
	printf("%lld\n", solve(root));
	for (auto& x : ans) printf("%lld %lld\n", x.first, x.second);
}


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

int main() {
  vector<long long> a(3);
  cin>>a[0]>>a[1]>>a[2];
  sort(a.begin(),a.end());
  if(a[0]%2==1&&a[1]%2==1&&a[2]%2==1) cout<<a[0]*a[1]<<endl;
  else cout<<0<<endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;

//集会所
int main() {
    int n;
    cin >> n;
    vector<int> x(n,0);
    rep(i,n)cin >> x[i];
    sort(x.begin(),x.end());
    int res = INF;
    rep(i,x[n-1]+1){
        int time = 0;
        rep(j,n){
            time = max(abs(x[j]-i),time);
        }
        res = min(time,res);
    }
    cout << res << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/


Measured memory_bytes: 3176
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=2e5+5;
int a[maxn],b[maxn];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i];
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    int ans;
    if(n%2)
    {
        int mid_a=a[(n+1)/2],mid_b=b[(n+1)/2];
        ans=mid_b-mid_a+1;
    }
    else
    {
        int mid_a=a[n/2]+a[n/2+1],mid_b=b[n/2]+b[n/2+1];
        ans=mid_b-mid_a+1;
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 5176
import java.util.*;
public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    HashMap<String, String> hashmap = new HashMap<String, String>();

    for (int i = 0; i < n; i++) {
      String s = sc.next();
      hashmap.put(s, s);
    }
    System.out.println(hashmap.size());

    sc.close();

  }
}

Measured memory_bytes: 76948
r, c = gets.split.map(&:to_i)
vec = []
total = 0

r.times do
  row = gets.split.map(&:to_i)
  row_sum = row.inject(:+)
  total += row_sum
  vec << [*row, row_sum]
end

last_row = Array.new(c, 0)

c.times do |j|
  vec.each do |v|
    last_row[j] += v[j]
  end
end

last_row << total

vec.each do |v|
  puts v.join(' ')
end

puts last_row.join(' ')



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

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}

void solve(int h[],int w,int l){
	int i;
	for(i=0;i<5;i++){
		if(h[i]==w){
			puts("1");
		}
		else{
			puts("2");
		}
	}
}

int main(void){
	int n,i,j,p,q,r,c,f,a[1000][4],cal[4]={0,4,9,4},tmp;
	while(1){
		n=in();
		if(!n){
			break;
		}
		f=1;
		for(i=0;i<n;i++){
			for(j=0;j<4;j++){
				a[i][j]=in();
			}
		}
		p=in();
		q=in();
		r=in();
		c=in();
		for(i=0;i<n;i++){
			tmp=0;
			for(j=1;j<4;j++){
				tmp+=a[i][j]*cal[j];
			}
			if(a[i][1]<=p&&a[i][2]<=q&&a[i][3]<=r&&tmp<=c){
				printf("%d\n",a[i][0]);
				f=0;
			}
		}
		if(f){
			puts("NA");
		}
	}
	return 0;
}

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

int main(){
	int n,ans=0;
	cin>>n;
	while(n){
		ans+=n%10;
		n/=10;
	}
	if(ans==1) cout<<10;
	else cout<<ans;
	return 0;
}


Measured memory_bytes: 256
///Astalavista Code........~CodeSlayer007
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (#x) << " is " << (x) << endl;
#define SPD_emergency ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
int IM = 1e17;
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " "; cout << endl;}
void PA(int v[], int n) {for (int i = 0 ; i < n ; i++)cout << v[i] << " " ; cout << endl;}
void IN(int a[], int n) {for (int i = 0; i < n; i++)cin >> a[i];}
inline void PTN(int n = 1, int a = 0, int b = 0, int c = 0) { if (n--)cout << a << " "; if (n--)cout << b << " "; if (n--)cout << c << " "; cout << endl; }
inline void open() {
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}
// <-------------------------------------------------------------------------------------------------------------------------------------------------------------------------> Ignore This-->  tuple first second push_back  continue make_pair break deque stack queue sort reverse accumulate  count lower_bound upper_bound next_permutation copy_n __builtin_popcount make_tuple
// <========================================================================================================================================================================

signed  main() {
   SPD_emergency

   //int t; cin >> t; int tt = 1; while (t--)
   {
      int a, b, n;
      cin >> a >> b >> n;
      int l = (n/b)*b;
      if(n<b)
         l = n;
      int k = a*l;
      int a1 = floor((double)(k)/b) - (a*floor((double)l/b));
      l--;
      k = a*l;
      int a2 =  floor((double)(a*l)/b) - (a*floor((double)l/b));
      cout<<max(a1,a2);


   }
   return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,m,yw,sw,ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=m;++j)
		{
			yw=j%10;
			sw=(j-yw)/10;
			if(yw*sw==i&&sw>=2&&yw>=2)
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import heapq


def prim(G):
    n = len(G)
    is_visited = [False for _ in range(n)]
    que = []
    heapq.heappush(que, (0, 0))

    ret = 0
    while que:
        cost, cur_v = heapq.heappop(que)
        if is_visited[cur_v]:
            continue

        is_visited[cur_v] = True
        ret += cost
        for (adj_dst, adj_cost) in G[cur_v]:
            heapq.heappush(que, (adj_cost, adj_dst))

    return ret


def main():
    n = int(input())
    g = [[] for _ in range(n)]
    a = [[int(x) for x in input().split()] for _ in range(n)]

    for i in range(n):
        for j in range(n):
            if a[i][j] == -1:
                continue
            g[i].append((j, a[i][j]))
            g[j].append((i, a[i][j]))

    print(prim(g))


main()


Measured memory_bytes: 8032
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 100005
#define ll signed long long int
using namespace std;


signed main()
{
    FAST;
    ll n, m;
    cin >> n >> m;
    ll mx = max(m, n);
    ll mn = min(m , n);
    for(ll i = 0; i < mx; i++){
    	cout << mn;
	}
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

bool solve(const string& S) {
  int n = S.length();
  REP(i, n) for(int j = i; j <= n; ++j) {
    string T = S.substr(0, i) + S.substr(j, n - j);
    if(T == "keyence") {
      return true;
    }
  }
  return false;
}

int main(){
  string S;
  cin >> S;
  cout << (solve(S) ? "YES" : "NO") << endl;
  return 0;
}



Measured memory_bytes: 256
#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;
typedef vector<int> vec;
typedef vector<vec> mat;
int main(){
    string s;
    cin>>s;
    ll ans=0;
    int z=0;
    rep(i,s.size()){
        int a=s[i]-'0';
        if(a<=3) ans+=a,z=0;
        else if(a==4){
            if(z==1&&i<s.size()-1&&s[i+1]-'0'>4) ans+=5;
            else ans+=a,z=0;
        }
        else if(a==5){
            if(z==1) ans+=9-a;
            else{
                if(i<s.size()-1&&s[i+1]-'0'>4) ans+=11-a,z=1;
                else ans+=a,z=0;
            }
        }
        else {
            if(z==0) ans+=2;
            ans+=9-a;
            z=1;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 1412
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール

// 処理内容
int main() {
    
    ll n; cin >> n;
    vector<ll> a(n);
    REP(i, n) {
        cin >> a[i];
        a[i] *= -1;
    }

    vector<ll> lis(n, INF);
    REP(i, n) {
        auto itr = upper_bound(ALL_OF(lis), a[i]);
        *itr = a[i];
    }
    DUMPALL(lis);
    ll ans = 0;
    while (ans < n && lis[ans] != INF) ans++;
    cout << ans << endl;

}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using P = pair<int, int>;

int lap(const P &a, const P &b) {
    vector<P> p{a, b};
    sort(p.begin(), p.end());

    if (p[0].first <= p[1].first && p[1].first <= p[0].second) {
        return min(p[0].second - p[1].first, p[1].second - p[1].first);
    }
    return 0;
}

int main() {
    int x1, y1, w1, h1;
    int x2, y2, w2, h2;

    cin >> x1 >> y1 >> w1 >> h1;
    cin >> x2 >> y2 >> w2 >> h2;

    P xx1 = make_pair(x1, x1 + w1);
    P xx2 = make_pair(x2, x2 + w2);
    P yy1 = make_pair(y1, y1 + h1);
    P yy2 = make_pair(y2, y2 + h2);

    cout << w1 * h1 + w2 * h2 - (lap(xx1, xx2) * lap(yy1, yy2)) * 2 << endl;
}


Measured memory_bytes: 3092
#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 getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

int main() {
  int A, B, Q; cin >> A >> B >> Q;
  vector<long long> s(A), t(B);
  for(int i = 0; i < A; ++i) cin >> s[i];
  for(int i = 0; i < B; ++i) cin >> t[i];
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());

  vector<long long> x(Q);
  for(int i = 0; i < Q; ++i) {
    cin >> x[i];
  }
  for(int i = 0; i < Q; ++i) {
    long long ans = 1LL<<60;

    int it = lower_bound(s.begin(), s.end(), x[i]) - s.begin();
    for(int j = max(0, it-2); j < min(A, it+2); ++j) {
      long long y = s[j];
      int it2 = lower_bound(t.begin(), t.end(), y) - t.begin();
      for(int k = max(0, it2-2); k < min(B, it2+2); ++k) {
        chmin(ans, abs(x[i]-y)+abs(y-t[k]));
      }
    }
    it = lower_bound(t.begin(), t.end(), x[i]) - t.begin();
    for(int j = max(0, it-2); j < min(B, it+2); ++j) {
      long long y = t[j];
      int it2 = lower_bound(s.begin(), s.end(), y) - s.begin();
      for(int k = max(0, it2-2); k < min(A, it2+2); ++k) {
        chmin(ans, abs(x[i]-y) + abs(y-s[k]));
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3712
let () = Scanf.scanf "%d\n" @@ fun n ->
  let ss =
    Array.init n @@ fun _ ->
      Scanf.scanf "%s\n" @@ fun s ->
        Array.fold_left (fun (m, c) -> function
          | '(' -> (m, c + 1)
          | ')' -> (min m (c - 1), c - 1)) (0, 0) @@
        Array.init (String.length s) (String.get s) in
  print_endline @@
  if
    ( <> ) 0 @@
    Array.fold_right (fun (_, c) -> ( + ) c) ss 0
  then "No"
  else begin
    Array.sort (fun (m, c) (m', c') ->
      let f m c = if 0 <= c then (1, m) else (0, c - m) in
      compare (f m' c') (f m c)) ss;
    try
      ignore
      (Array.fold_left (fun x (m, c) ->
        if x + m < 0 then raise Not_found; x + c) 0 ss);
      "Yes"
    with Not_found -> "No"
  end



Measured memory_bytes: 38580
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
#define _DEBUG
     
int main() {
  int k;
  string s;
  cin >> k >> s;
  int len = s.size();

  if (len <= k) cout << s << endl;
  else {
    rep (i, k) cout << s[i];
    cout << "..." << endl;
  }
}

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

const int mod = 1000000007;

int main() {
	int N;
	cin >> N;
	vector<ll> A(N);
	rep(i, N) cin >> A[i];

	ll ans = 0;
	rep(i, 60) {
		ll x = 0;
		rep(j, N) {
			if((A[j] >> i) & 1) ++x;
		}
		ll now = x * (N - x) % mod;
		rep(j, i) now = (now * 2) % mod;
		ans += now;
		ans %= mod;
	}

	cout << ans << endl;

	return 0;
}

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

int main()
{
    int h, w;
    cin >> h >> w;
    int count = 0;
    char b[h][w];
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> b[i][j];
            if (b[i][j] == '.')
                count++;
        }
    }
    int dh[4] = {-1, 1, 0, 0};
    int dw[4] = {0, 0, 1, -1};
    queue<pair<int, int>> q;
    q.push(make_pair(0, 0));
    vector<vector<bool>> visited(h, vector<bool>(w, 0));
    int ans[h][w];
    ans[0][0] = 1;
    ans[h - 1][w - 1] = -1;
    while (!q.empty())
    {
        pair<int, int> cr = q.front();
        q.pop();
        if (cr.first == h - 1 && cr.second == w - 1)
            break;
        for (int i = 0; i < 4; i++)
        {
            int nh = cr.first + dh[i];
            int nw = cr.second + dw[i];
            if (nh > h - 1 || nh < 0 || nw > w - 1 || nw < 0 ||
                b[nh][nw] == '#' || visited[nh][nw] == 1)
                continue;
            else
            {
                q.push(make_pair(nh, nw));
                visited[nh][nw] = 1;
                ans[nh][nw] = ans[cr.first][cr.second] + 1;
            }
        }
    }
    if (ans[h - 1][w - 1] == -1)
        cout << -1 << endl;
    else
        cout << count - ans[h - 1][w - 1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using mat = vector<vector<ll>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int N; cin >>N;
  int Ma,Mb; cin >>Ma >>Mb;
  vector<int> a(N),b(N),c(N); rep(i, N) cin >>a[i] >>b[i] >>c[i];
  if (Ma > Mb){
    swap(Ma, Mb); swap(a, b);
    // 問題をMa <= Mb の場合に帰着する
  }
  vector<vector<int>> dp(N+1, vector<int>(8001, inf));
  for (int i=0; i<N; i++) dp[i+1][b[i]*Ma-a[i]*Mb+4000] = c[i];
  // Ma : Mb = A : B <=> Ma*B = A*Mb
  // X = B*Ma - A*Mb とすると
  // Xが取りうる値は
  //   最小値：40 * 1 * 1 - 40*10*10 = 40 * (-99) > -4000
  //   最大値：40 * 10 *10 - 40*1*9   = 40 * 91 < 4000
  // よって Y = X + 4000 とすれば
  // 0 <= Y <= 8000 としてよい
  // dp[i][Y] := i番目までの薬品を使って, 選んだai, bi の合計をA, B としたとき Y = B*Ma - A*Mb + 4000 とする。
  //             このときの予算の最小値
  // 求めたいものはdp[N][4000]
  for (int i=0; i<N; i++){
    for (int Y=0; Y<=8000; Y++){
      if (dp[i][Y] == inf) continue;
      chmin(dp[i+1][Y], dp[i][Y]);
      // dY = (nB*Ma - nA*Mb + 4000) - (B*Ma - A*Mb + 4000)
      //    = (nB-B)*Ma - (nA-A)*Mb
      //    = b[i]*Ma - a[i]*Mb
      chmin(dp[i+1][Y + b[i]*Ma - a[i]*Mb], dp[i][Y] + c[i]);
    }
  }
  int res = dp[N][4000] == inf ? -1 : dp[N][4000];
  cout <<res <<endl;
}


Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    string s;
    cin >> s;
    int len = s.length();
    int left = 0;
    int right = 0;
    vector<int> ans(len);
    for(int i = 0; i < len; i++){
        ans[i] = 0;
    }
    for(int i = 0; i < len-1; i++){
        if(s[i] == 'L' && s[i+1] == 'R'){
            right = i;
            for(int j = left; j <= right; j++){
                int tmp = 0;
                if(s[j] == 'R' && s[j+1] == 'L'){
                    tmp = j;
                    ans[j] ++;
                    ans[j+1] ++;
                    for(int k = left; k <= right; k++){
                        if(k != tmp && k != tmp+1){
                            if(abs(k-tmp)%2 == 0){
                                ans[j] ++;
                            }else if(abs(k-tmp)%2 == 1){
                                ans[j+1] ++;
                            }
                        }
                    }
                }
            }
            left = i+1;
        }
    }
    right = len-1;
    for(int j = left; j <= right; j++){
        if(s[j] == 'R' && s[j+1] == 'L'){
            ans[j] ++;
            ans[j+1] ++;
            for(int k = left; k <= right; k++){
                if(k != j && k != j+1){
                    if(abs(k-j)%2 == 0){
                        ans[j] ++;
                    }else{
                        ans[j+1] ++;
                    }
                }
            }
        }
    }
    for(int i = 0; i < len; i++){
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}


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

#define ll long long
#define f(i,start,end,inc) for(int i = start;i<end;i+=inc)
#define fl(i,start,end,inc) for(ll i = start;i<end;i+=inc)
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define umap unordered_map
#define uset unordered_set
#define vpii vector<pair<int,int> >
#define vpll vector<pair<ll,ll> >
#define vpis vector<pair<int,string> >
#define vpls vector<pair<ll,string> >
#define w(t) int t;cin >> t;while(t--)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pis pair<int,string>
#define pls pair<ll,string>
#define F first
#define S second
#define inp(c) int c;cin >> c
#define inpl(c) ll c;cin >> c



using namespace std;

int dp[3001][3001];

string getLcs(string &s,string &t,int len){
	string l;
	int i = 0,j = 0;
	while(len > 0){
		if(s[i] == t[j]){
			l.pb(s[i]);
			i++;j++;len--;
		}
		else{
			if(dp[i][j+1] > dp[i+1][j]){
				j++;
			}
			else{
				i++;
			}
		}
	}
	return l;
}

int lenLcs(string &s,string &t,int i,int j){
	if(i >= s.length() or j >= t.length()){
		return 0;
	}
	if(dp[i][j]!=-1)
		return dp[i][j];
	if(s[i] == t[j])
		return dp[i][j] = 1 + lenLcs(s,t,i+1,j+1);
	else{
		return dp[i][j] = max(lenLcs(s,t,i+1,j),lenLcs(s,t,i,j+1));
	}
}

string solve(string s,string t){
	memset(dp,-1,sizeof(dp));
	int len = lenLcs(s,t,0,0);
	return getLcs(s,t,len);
}

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

  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // #endif
  
  string s,t;
  cin >> s >> t;
  cout << solve(s,t) << endl;

  return 0;
}


Measured memory_bytes: 35968
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);


int main() {
  int A, B;
  cin >> A >> B;
  if(B%A==0) cout << A+B << endl;
  else cout << B - A << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, char> Q;
const ll mod = 1000000007;
const ll INF = 1000000000000000;

ll H, W, K, type[330][330];
string s[330];
vector<P> vec;

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

void dfs(ll x, ll y, ll f)
{
	type[x][y] = f;

	for (int i = 0; i < 4; i++)
	{
		if (type[x + dx[i]][y + dy[i]] != 0) continue;

		if (i < 2)
		{
			if (i == 0 && y != W - 1)
			{
				dfs(x + dx[i], y + dy[i], f);
			}
			if (i == 1 && x != H - 1)
			{
				dfs(x + dx[i], y + dy[i], f);
			}
		}
		else
		{
			if (i == 2 && y != 0)
			{
				dfs(x + dx[i], y + dy[i], f);
			}
			if (i == 3 && x != 0)
			{
				dfs(x + dx[i], y + dy[i], f);
			}
		}
	}
}

int main(void)
{
	cin >> H >> W >> K;
	ll cnt = 1;
	ll tt = 0;
	for (int i = 0; i < H; i++)
	{
		cin >> s[i];
		vector<ll> str;
		for (int j = 0; j < W; j++)
		{
			if (s[i][j] == '#')
			{
				str.push_back(j);
				if (tt == 0) tt = i;
			}
		}

		if (str.size() == 0) continue;

		for (int j = 0; j < str[0]; j++)
		{
			type[i][j] = cnt;
		}
		
		for (int l = 0; l < str.size() - 1; l++)
		{
			for (int j = str[l]; j < str[l + 1]; j++)
			{
				type[i][j] = cnt;
			}
			cnt++;
		}
		for (int j = str[str.size() - 1]; j < W; j++)
		{
			type[i][j] = cnt;
		}
		cnt++;
	}

	for (int i = 0; i < W; i++)
	{
		for (int j = tt; j >= 0; j--)
		{
			if (type[j][i] == 0)
			{
				type[j][i] = type[j + 1][i];
			}
			
		}
		for (int j = tt; j < H; j++)
		{
			if (type[j][i] == 0)
			{
				type[j][i] = type[j - 1][i];
			}
		}
	}

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			cout << type[i][j];
			if (j == W - 1)
			{
				cout << endl;
			}
			else
			{
				cout << ' ';
			}
		}
	}

	int xxx;
	cin >> xxx;
}



Measured memory_bytes: 1664
#include "bits/stdc++.h"
using namespace std;

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

	int size = s.size();
	string ans = "Yes";
	for (int i = 0; i < size; i++) {
		if (i % 2 == 0) {
			if (s.at(i) == 'R' || s.at(i) == 'U' || s.at(i) == 'D') {
			} else {
				ans = "No";
			}
		}
		if (i % 2 == 1) {
			if (s.at(i) == 'L' || s.at(i) == 'U' || s.at(i) == 'D') {
			} else {
				ans = "No";
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256