akhauriyash/Code-Regression huggingface dataset:
import sys
import math
from collections import Counter
import itertools
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

A,B,C,D=MI()

while True:
    if C-B>0:
        C=C-B
    else:
        print("Yes")
        exit()
    if A-D>0:
        A=A-D
    else:
        print("No")
        exit()
        

Measured memory_bytes: 9492
/* ex4_3
   offNaria */
#include <stdio.h>

int numberOfEastMonument(int a, int b);
int heightOfMonument(int a);
int getDepthOfSnow(int a, int b);

int main(void){
  int visibleWestMonument, visibleEastMonument;
  scanf("%d %d", &visibleWestMonument, &visibleEastMonument);
  printf("%d\n", getDepthOfSnow(heightOfMonument(numberOfEastMonument(visibleWestMonument, visibleEastMonument)), visibleEastMonument));
  return 0;
}

int numberOfEastMonument(int visibleWestMonument, int visibleEastMonument){
  return visibleEastMonument - visibleWestMonument;
}

int heightOfMonument(int number){
  return number * (number + 1) / 2;
}

int getDepthOfSnow(int heightOfEastMonument, int visibleEastMonument){
  return heightOfEastMonument - visibleEastMonument;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans, x, N, t;
map<int, int> c;

int main(void) {
    scanf("%d", &N);
    rep(i, 0, N) {
        int a;
        scanf("%d", &a);

        if (c[a] > 0) x++;
        else t++;

        c[a]++;
    }

    ans = t;
    if (x % 2 != 0) ans--;
    printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 4992
import java.io.*;
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String line;
            /* input */
            while(true){
                line = br.readLine();
                int n = Integer.parseInt(line.split(" ")[0]), h = Integer.parseInt(line.split(" ")[1]);
                if(n==0&&h==0) return;
                
                Set<Integer> s = new HashSet<Integer>();
                
                for(int i=0;i<h;i++){
                	line = br.readLine();
                	
                	String[] str = line.split(" ");
                	String p = str[0];
                	int a = Integer.parseInt(str[1])-1, b = Integer.parseInt(str[2])-1;
                	if(p.equals("xy")){
                		for(int j=0;j<n;j++){
                			s.add(1000000*a+1000*b+j);
                		}
                	} else if(p.equals("yz")){
                		for(int j=0;j<n;j++){
                			s.add(1000000*j+1000*a+b);
                		}
                	} else {
                		for(int j=0;j<n;j++){
                			s.add(1000000*a+1000*j+b);
                		}
                	}
                }
                System.out.println(n*n*n-s.size());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 50880
import Control.Monad                                                                                                                                  
                                                                                                                                                      
main :: IO ()                                                                                                                                         
main = do                                                                                                                                             
  [n,_,c] <- map read . words <$> getLine                                                                                                             
  bm <- map read . words <$> getLine                                                                                                                  
  an <- replicateM n $ sum . zipWith (*) bm . map read . words <$> getLine                                                                            
  print . length . filter (\x -> x > (-c)) $ an

Measured memory_bytes: 1020
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
typedef pair<int, int> P;

int main(){
  int H, W, M;
  while(cin>>H>>W>>M){
    vector<string> grid(H);
    REP(i, H) cin>>grid[i];
    int c_mt[50][50];
    int c_on[50][50];
    int c_of[50][50];
    REP(y, H)REP(x, W) cin>>c_mt[y][x];
    REP(y, H)REP(x, W) cin>>c_on[y][x];
    REP(y, H)REP(x, W) cin>>c_of[y][x];
    vector<int> cx, cy;
    REP(i, M){
      int y, x; cin>>y>>x;
      cx.push_back(x); cy.push_back(y);
    }
    vector<int> time[50][50];
    time[cy[0]][cx[0]].push_back(0);
    int now = 0;
    REP(i, M - 1){
      const P null = P(-1, -1);
      P prev[50][50];
      REP(y, H)REP(x, W) prev[y][x] = null;
      queue<int> qx, qy;
      qx.push(cx[i]); qy.push(cy[i]);
      while(!qx.empty()){
        int x = qx.front(); qx.pop();
        int y = qy.front(); qy.pop();
        REP(r, 4){
          int nx = x + dx[r];
          int ny = y + dy[r];
          if(valid(nx, ny, W, H) && prev[ny][nx] == null && grid[ny][nx] != '#'){
            prev[ny][nx] = P(x, y);
            qx.push(nx); qy.push(ny);
          }
        }
      }
      prev[cy[i]][cx[i]] = null;
      vector<P> path;
      P cur = P(cx[i + 1], cy[i + 1]);
      while(cur != null){
        path.push_back(cur);
        cur = prev[cur.second][cur.first];
      }
      reverse(path.begin(), path.end());
      FOR(i, 1, path.size()){
        int x = path[i].first, y = path[i].second;
        int t = now + i;
        time[y][x].push_back(t);
      }
      now += path.size() - 1;
    }
    ll ans = 0;
    REP(y, H)REP(x, W){
      if(time[y][x].empty()) continue;
      int T = time[y][x].size();
      ll dp[1010][2] = {};
      REP(i, T) dp[i][0] = dp[i][1] = (ll)1e16;
      dp[0][0] = c_on[y][x] + c_of[y][x];
      dp[0][1] = c_on[y][x];
      FOR(i, 1, T){
        int cur = min(dp[i - 1][0] + c_on[y][x], dp[i - 1][1] + (ll)c_mt[y][x] * (time[y][x][i] - time[y][x][i - 1]));
        dp[i][0] = cur + c_of[y][x];
        dp[i][1] = cur;
      }
      //printf("x = %d y = %d m = %lld\n", x, y, dp[T-1][0]);
      ans += dp[T - 1][0];
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 6536
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"

int main()
{
	bool ck=1;
	string s;
	cin>>s;
	for0(i,s.size()){
		if(i%2 && s[i]=='R') {ck=0;break;}
		else if(i%2==0 && s[i]=='L') {ck=0;break;}
		}
	pf(ck? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
t, a = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
num = 0
min = 9999999999.0
for i in 0..(n-1)
  d = (a - (t - h[i] * 0.006)).abs
  if min > d
    num = i
    min = d
  end
end
puts num + 1

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N,A;
  cin >> N >> A;
  int cost=N*N-A;
  cout << cost << endl;
  return 0;
}

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

using ll = long long;

const int MAXN = 100010;
int N, M;
vector<int> adj[MAXN];
int col[MAXN];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0);
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	int nIsolated = 0;
	int nBipartite = 0;
	int nOther = 0;
	fill_n(col + 1, N, -1);
	for (int s = 1; s <= N; s++) {
		if (col[s] != -1) continue;
		vector<int> q = {s};
		col[s] = 0;
		bool isBip = true;
		for (size_t i = 0; i < q.size(); i++) {
			int cur = q[i];
			int colNxt = 1 - col[cur];
			for (size_t j = 0; j < adj[cur].size(); j++) {
				int nxt = adj[cur][j];
				if (col[nxt] == -1) {
					col[nxt] = colNxt;
					q.push_back(nxt);
				} else {
					isBip &= (col[nxt] == colNxt);
				}
			}
		}
		if (q.size() == 1) {
			nIsolated++;
		} else if (isBip) {
			nBipartite++;
		} else {
			nOther++;
		}
	}

	ll ans = 0;
	ans += ll(2) * nIsolated * N - ll(nIsolated) * nIsolated;
	ans += ll(2) * nBipartite * nBipartite;
	ans += ll(nOther) * nOther;
	ans += ll(2) * nOther * nBipartite;
	cout << ans << endl;

	return 0;
}


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

int main(){
  int n,k,a[8888],dp[8888];

  scanf("%d%d",&n,&k);
  for(int i=0;i<n;i++)scanf("%d",&a[i]);

  int ans = 0;
  for(int i=0;i<n;i++){
    if(a[i]<i)continue;
    for(int j=0;j<=a[i]-i+1;j++)dp[j] = 1e8;
    for(int j=i;j<a[i];j++){
      if(a[i]<a[j])*lower_bound(dp,dp+a[i]-i+1,a[j]) = a[j];
    }
    ans = max(ans, (int)(lower_bound(dp,dp+a[i]-i+1,1e8) - dp));
    if(ans+1+k>=n/2){ printf("%d\n",n/2); return 0; }
  }
  printf("%d\n",ans+1+k);
}

Measured memory_bytes: 1256
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<P> VP;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

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

#define LFOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RLFOR(i,b,a) for(ll i=(b)-1;i>=(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(int)(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define dump(x) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";
#define dump2(x,y) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x)\
			<< " , " << #y << " = " << (y) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;

int n,m;

ll sigx, sigy, ans;
const int mod = 1e9 + 7;
int x[100000], y[100000];
int main() {
	cin >> n >> m;
	REP(i, n){
		cin >> x[i];
	}
	sort(x, x+n);
	REP(i, n){
		sigx += ll(2 * i - n + 1) * x[i] + (ll)mod * 1e5;
		sigx %= mod;
	}
	REP(j, m){
		cin >> y[j];
	}
	sort(y, y+m);
	REP(j, m){
		sigy += ll(2 * j - m + 1) * y[j] + (ll)mod * 1e5;
		sigy %= mod;
	}

	ans = sigx * sigy;
	ans %= mod;
	cout << ans << endl;
}


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

int main(void){
	int n, m, h[1500], w[1500], sumw[1501], sumh[1501], ans, mapw[1500001];
	int i, j;
	while(1){
		scanf("%d%d",&n,&m);
		if((n | m) == 0){
			break;
		}
		for(i = 0;i < n;i++){
			scanf("%d",&h[i]);
		}
		for(i = 0;i < m;i++){
			scanf("%d",&w[i]);
		}
		ans = 0;
		sumh[0] = 0;
		sumw[0] = 0;
		for(i = 1;i <= n;i++){
			sumh[i] = sumh[i - 1] + h[i - 1];
		}
		for(i = 1;i <= m;i++){
			sumw[i] = sumw[i - 1] + w[i - 1];
		}
		memset(mapw,0,sizeof(mapw));
		for(i = 0;i <= m;i++){
			for(j = i + 1;j <= m;j++){
				mapw[sumw[j] - sumw[i]]++;
			}
		}
		for(i = 0;i <= n;i++){
			for(j = i + 1;j <= n;j++){
				ans += mapw[sumh[j] - sumh[i]];
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

int main() {
    string S; cin >> S;
    long long ans = 0;
    for (long long i = 0; i < S.size(); i++) {
        ans += (S.at(i) - '0');
    }
    if (ans % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3752
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
class lazy_segment_tree{
    private:
        static int calc_size(int n){
            int m = 1;
            while(m < n){
                m *= 2;
            }
            return m;
        }

        void eval(int i, int l, int r){
            if(lazy[i] != 0){
                node[i] += lazy[i];
                if(r - l > 1){
                    lazy[i * 2 + 1] += lazy[i];
                    lazy[i * 2 + 2] += lazy[i];
                }
                lazy[i] = 0;
            }
        }

        void add(int s, int t, int x, int i, int l, int r){
            eval(i, l, r);

            if(t <= l || r <= s){
                return;
            }

            if(s <= l && r <= t){
                lazy[i] += x;
                eval(i, l, r);
                return;
            }

            int m = l + (r - l) / 2;
            add(s, t, x, 2 * i + 1, l, m);
            add(s, t, x, 2 * i + 2, m, r);
            node[i] = f(node[2 * i + 1], node[2 * i + 2]);
        }

        T query(int s, int t, int i, int l, int r){
            eval(i, l, r);

            if(t <= l || r <= s){
                return INF;
            }

            if(s <= l && r <= t){
                return node[i];
            }

            int m = l + (r - l) / 2;
            T vl = query(s, t, i * 2 + 1, l, m);
            T vr = query(s, t, i * 2 + 2, m, r);
            return f(vl, vr);
        }

    public:
        int n;
        vector<T> node, lazy;
        T init;
        function<T(T, T)> f;

        lazy_segment_tree(int n, T init, function<T(T, T)> f)
            : n(calc_size(n)), node(calc_size(n) * 2, init) , lazy(calc_size(n) * 2, 0), init(init), f(f) {}

        void update(int i, const T& x){
            node[i + n] = x;
            for(int j = (i + n) / 2; j > 0; j /= 2){
                node[j] = f(node[j * 2 + 1], node[j * 2 + 2]);
            }
        }

        T query(int s, int t){
            return query(s, t, 0, 0, n);
        }

        void add(int s, int t, int x){
            add(s, t, x, 0, 0, n);
        }
};

signed main(){
    int n, q;
    cin >> n >> q;

    lazy_segment_tree<int> lst(n, 0, [](int a, int b){return min(a, b);});
    rep(i, q){
        int que, s, t;
        cin >> que >> s >> t;

        if(que == 0){
            int x;
            cin >> x;
            lst.add(s, t+1, x);
        }else{
            cout << lst.query(s, t+1) << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 7080
N,X = map(int,input().split())

# B[L] = 1 + B[L-1] + 1 + B[L-1] + 1
# B[0] = 1
def Ber(L):
    if L == 0:
        return 1
    return 2*Ber(L-1) + 3

# P[L] = P[L-1] + 1 + P[L-1]
# P[L] = 1
def Patty(L):
    if L == 0:
        return 1
    return 2*Patty(L-1) + 1

def rec(L=N,bottom=X):
    if L == 0:
        return 1
    if bottom <= 1:
        return 0
    elif bottom <= 1 + Ber(L-1):
        return rec(L-1,bottom-1)
    elif bottom == 1 + Ber(L-1) + 1:
        return Patty(L-1) + 1
    elif bottom <= 1 + Ber(L-1) + 1 + Ber(L-1):
        return Patty(L-1) + 1 + rec(L-1,bottom-(1+Ber(L-1)+1))
    elif bottom <= 1 + Ber(L-1) + 1 + Ber(L-1) + 1:
        return Patty(L-1) + 1 + Patty(L-1)

print(rec())

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;



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

	vector <ll> a(N);
	ll suma = 0;

	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
		suma += a[i];
	}

	vector <ll> ans(N);

	// 0のこし
	ll tmp = suma;

	for (int i=1;i<N;i+=2)
	{
		tmp -= a[i]*2;
	}
	ans[0] = tmp;

	for (int i=1;i<N;i++)
	{
		ans[i] = (a[i - 1] - ans[i - 1] / 2) * 2;

	}



	for (int i = 0; i < N; ++i)
	{
		if (i > 0)
		{
			cout << " ";

		}
		cout << ans[i];
	}
	cout << endl;


	return 0;
}


Measured memory_bytes: 2944
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll dx[]={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};
    ll k;
    cin>>k;
    cout<<dx[k-1]<<endl;
}


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

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

  if (a + b > c + d) {
	cout << "Left" << endl;
   }
  else if ( a + b == c + d) {
	cout << "Balanced" << endl;
  }
  else {
	cout << "Right" << endl;
  }
  
}

Measured memory_bytes: 256
import numpy as np
H, W, N = map(int, input().split())

L = np.ones((W,H))
for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    for i in range(x):
      for j in range(W):
        L[j][i] = 0
  elif a == 2:
    for i in range(x, H):
      for j in range(W):
        L[j][i] = 0
  elif a == 3:
    for i in range(y):
      for j in range(H):
        L[i][j] = 0
  elif a == 4:
    for i in range(y, W):
      for j in range(H):
        L[i][j] = 0

print (int(np.sum(L)))


Measured memory_bytes: 20732
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <deque>
#include <cstring>
#include <set>
#include <bitset>
#include <map>
#include <chrono>
#include <random>
#include <unordered_map>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<int> vi;
typedef std::vector<bool> vb;
typedef std::vector<string> vs;
typedef std::vector<double> vd;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<int> > vvi;
typedef vector<vll> vvll;
typedef std::vector<std::pair<int, int> > vpi;
typedef vector<vpi> vvpi;
typedef std::pair<int, int> pi;
typedef std::pair<ll, ll> pll;
typedef std::vector<pll> vpll;

const long long mod = 1000000007;
const unsigned gen_seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937_64 gen(gen_seed);

#define all(c) (c).begin(),(c).end()
#define forn(i, a, b) for(int i = a; i < b; i++)
#define read(x) scanf("%d", &x)
#define readv(x, n) vll x(n); forn(i,0,n) scanf("%lld", &x[i])

#define pb push_back
#define mp make_pair


int main()
{
    int n;
    scanf("%d", &n);
    readv(a,n);
    readv(b,n);
    ll sa = 0, sb = 0;
    forn(i,0,n) sa+=a[i], sb+=b[i];
    if(sa > sb) {
        cout<<"No";
        return 0;
    }
    ll m = sb - sa;
    ll na = 0;
    forn(i,0,n) {
        if(a[i] < b[i]) {
            na += (b[i]-a[i]+1)/2;
        }
    }
    if(na > m) cout<<"No";
    else cout<<"Yes";
}


Measured memory_bytes: 384
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,a[200111];
int tol[200111],tor[200111];
pair<int,int> st[200111];
int stn;
int main()
{
	geti(n);
	for(int i=1;i<=n;i++)geti(a[i]);
	stn=0;
	for(int i=1;i<=n;i++)
	{
		while(stn>0&&st[stn-1].FF>a[i])
		{
			stn--;
		}
		if(stn==0)tol[i]=1;else tol[i]=st[stn-1].SS+1;
		st[stn++]=MP(a[i],i);
	}
	stn=0;
	for(int i=1;i<=n;i++)
	{
		while(stn>0&&st[stn-1].FF>=a[n-i+1])
		{
			stn--;
		}
		if(stn==0)tor[n-i+1]=n;else tor[n-i+1]=st[stn-1].SS-1;
		st[stn++]=MP(a[n-i+1],n-i+1);
	}
	ll ans=0;
	for(int i=1;i<=n;i++)ans+=1ll*a[i]*(tor[i]-i+1)*(i-tol[i]+1);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void decToBinary(int n, int k) 
{ 
    // array to store binary number 
    int binaryNum[32]; 
  
    // counter for binary array 
    int i = 0; 
    while (n > 0) { 
  
        // storing remainder in binary array 
        binaryNum[i] = n % k; 
        n = n / k; 
        i++; 
    } 
  	
  	cout<<i<<endl;
    // printing binary array in reverse order 
    // for (int j = i - 1; j >= 0; j--)
    //     cout << binaryNum[j]; 
} 
int main()
{
	int n, k;
	cin>>n>>k;
	decToBinary(n,k);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

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

ll gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

	if (r > n / 2) { r = n - r; }

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

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

void PrimeFact(ll x) { // 素因数分解 出力部を適切に書き換え
	int i=2;
	while(x%2&&i*i<=x) {
		cout<<2<<endl;
		x/=2;
	}
	i++;
	while(i*i<=x) {
		if(x%i) {
			i+=2;
			continue;
		}
		cout<<i<<endl;
		x/=i;
	}
}

bool Palind(string s) {
	return s == string(s.rbegin(), s.rend());
}

int main() {
	ll N; cin>>N;
	if(N%2) {
		cout<<0<<endl;
		return 0;
	}
	N/=2;
	ll result=0LL;
	while(N) {
		result+=N/5;
		N/=5;
	}
	cout<<result<<endl;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()

dic = dict([('s',r),('p',s),('r',p)])


ans = 0
for i in range(k):
    A = [t[j] for j in range(i,n,k)]
    flag = A[0]
    ans += dic[flag]
    for j in range(1,len(A)):
        if A[j]==flag:
            if j!=len(A)-1:
                flag = (set(['r','s','p'])-set(A[j+1])).pop()
        else:
            ans += dic[A[j]]
            flag = A[j]
print(ans)


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

typedef long long ll;

#define rep(i,a,b) for(i=a;i<=b;i++)
#define maxn 100000

struct tikus{
	ll x;
	ll y;
	ll z;
};
tikus ar[maxn];
ll dpx[maxn],dpy[maxn];

bool sekom(tikus aw,tikus ak){
	return aw.x-aw.y > ak.x-ak.y;
}

priority_queue<ll,vector<ll>,greater<ll> > pqx,pqy;

int main(){
	int N,N1,N2,N3,i;
	cin>>N1>>N2>>N3;
	N=N1+N2+N3;
	ll has=0;
	rep(i,0,N-1){
		cin>>ar[i].x>>ar[i].y>>ar[i].z;
		has+=ar[i].z;
	}
	sort(ar,ar+N,sekom);
//	cout<<has<<"\n";
//	cout<<"\n";
//	rep(i,0,N-1){
//		printf("%lld %lld %lld\n",ar[i].x,ar[i].y,ar[i].z);
//	}
//	cout<<"\n";
	ll tam=0;
	rep(i,0,N-1){
		tam+=(ar[i].x-ar[i].z);
		pqx.push(ar[i].x-ar[i].z);
		if((int)pqx.size() > N1){
			tam-=pqx.top();
			pqx.pop();
		}
		dpx[i]=tam;
//		cout<<dpx[i]<<"\n";
	}
//	cout<<"\n";
	reverse(ar,ar+N);
	tam=0;
	rep(i,0,N-1){
		tam+=(ar[i].y-ar[i].z);
		pqy.push(ar[i].y-ar[i].z);
		if((int)pqy.size() > N2){
			tam-=pqy.top();
			pqy.pop();
		}
		dpy[i]=tam;
//		cout<<dpy[i]<<"\n";
	}
//	cout<<"\n";
	tam=LLONG_MIN;
	rep(i,N1-1,N-N2-1){
		tam=max(tam,dpx[i]+dpy[N-2-i]);
	}
	has+=tam;
	cout<<has<<"\n";
}


Measured memory_bytes: 5148
package main
import (
  "fmt"
)
func main() {
  var N, B int
  fmt.Scan(&N)
  fmt.Scan(&B)
  res := B
  prev := B
  for i:=1; i<N-1; i++ {
    fmt.Scan(&B)
    if prev <= B {
      res += prev
    } else {
      res += B
    }
    prev = B
  }
  res += prev
  fmt.Println(res)
}


Measured memory_bytes: 512
import java.util.Scanner;
        


/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int k = (n - 1) *(m - 1);
        System.out.println(k);


    }
}


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

int main()
{
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	auto dx = vector<int>(n);
	auto dy = vector<int>(m);
	for(auto& a : dx) cin >> a;
	for(auto& a : dy) cin >> a;
	sort(dx.begin(), dx.end());
	sort(dy.begin(), dy.end());
	cout << (*dx.rbegin() < *dy.begin() && x < *dy.begin() && *dx.rbegin() < y ? "No War" : "War") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll  long long int
#define out  cout<<

using namespace std;



int main(){
    ll n;
    cin>>n;
    ll a[n][n];

    for(ll i=0;i<n;i++){
     for(ll j=0;j<2;j++){
        cin>>a[i][j];

     }

    }
    //for(ll i=0;i<n;i++)
       // cout<<indx[i]<<"\n";
    bool flag =false;
       for(ll k=0;k<n-2;k++){
            if((a[k][0] ==a[k][1])&&(a[k+1][0]  == a[k+1][1])&&(a[k+2][0]  == a[k+2][1])){
                flag =true;
                break;
            }


       }
       if(flag == true)
        cout<<"Yes"<<"\n";
       else
        cout<<"No"<<"\n";

return 0;}


Measured memory_bytes: 3660
#!/bin/bash

read in1
a=(${in1// / })

m=$((${a[0]} / 2019))
n=$((${a[1]} / 2019))
p=$((${a[0]} % 2019))
q=$((${a[1]} % 2019))
if [ $((n - m)) -ge 1 ]; then
  echo 0
else
  x=2018
  for ((i=p; i<q; i++)); do
    for ((k=$((i+1)); k<=q; k++)); do
      if [ $(((i*k)%2019)) -lt $x ]; then
        x=$(((i*k)%2019))
        if [ $x -eq 0 ]; then
          break 2
        fi
      fi
    done
  done
  echo $x
fi


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define MAX_H 50
#define MAX_W 50
char G[MAX_H][MAX_W];
i64 dy[] = {1, -1, 0, 0};
i64 dx[] = {0,  0, 1, -1};

int main() {
    i64 H, W; cin >> H >> W;
    REP(i, H) REP(j, W) cin >> G[i][j];

    auto inside = [&](i64 y, i64 x) {
        return 0 <= y && y < H && 0 <= x && x < W;
    };

    REP(i, H) REP(j, W) {
        if (G[i][j] == '#') {
            bool ok = false;
            REP(k, 4) {
                if (inside(i + dy[k], j + dx[k]) && G[i + dy[k]][j + dx[k]] == '#') ok = true;
            }
            if (!ok) {
                cout << "No" <<  endl;
                return 0;
            }
        }
    }
    cout << "Yes" <<  endl;

    return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  var r = input;
  r = parseInt( r, 10 );

  console.log('%d', 3 * r * r);

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <stdio.h>
#include <string.h>
#define MN 200005
int c[26],n;
long long ans=0;
char str[MN];
int main(){
	scanf("%s",str+1); n=strlen(str+1);
	for(int i=1;i<=n;i++)
		ans+=i-(++c[str[i]-'a']);
	printf("%lld",ans+1);
}

Measured memory_bytes: 384
import numpy as np
n = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()                                                          
    return divisors

a = np.sort(make_divisors(n))
#print(a)                                                                      
if len(a)//2==0:
    x = len(a)//2-1
else:
    x = len(a)//2

xx = a[x]
yy= n//xx

print(xx-1+yy-1)

Measured memory_bytes: 13388
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <algorithm>
using namespace std;
 
typedef long long ll;
ll mod = 1e9+7;


int main()
{
    int n;
    string s;
    cin>>n>>s;
    int l=0;
    for(int i=0;i<s.size();i++)
        if(s[i]=='R')   l++;
    int ans=0;
    for(int i=0;i<l;i++)
        if(s[i]=='W')   ans++;
    cout<<ans<<endl;
     
    int ab;
    cin>>ab;
}

Measured memory_bytes: 3748
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long h = sc.nextInt();
    long w = sc.nextInt();

    if(h==1 || w==1) {
      System.out.println(1);
      System.exit(0);
    }

    long ans;
    if(h*w % 2 == 0) ans = h*w/2;
    else             ans = h*w/2+1;

    System.out.println(ans);
  }
}

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

int main() {
  int l, r;
  cin>>l>>r;
  set<int> s;

  int a = l % 2019;
  int b = r % 2019;
  if (r - l >= 2018) {
    for (int i=0; i<2019; i++) {
      s.insert(i);
    }
  } else if (b > a) {
    for (int i=a; i<=b; i++) {
      s.insert(i);
    }
  } else {
    for (int i=a; i<=2018; i++) {
      s.insert(i);
    }
    for (int i=0; i<=b; i++) {
      s.insert(i);
    }
  }
  vector<int> v(s.begin(), s.end());
  int ans = 2018;
  for (int i=0; i<v.size(); i++) {
    for (int j=i+1; j<v.size(); j++) {
      ans = min(ans, (v[i]*v[j])%2019);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;

// 0はdummy, 1:'A', 2:'C', 3:'G', 4:'T'
ll dp[101][5][5][5] = {}; // dp[i文字目まで][3文字前][2文字前][1文字前]

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

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

    dp[0][0][0][0] = 1;
    // except "AGC", "ACG", "GAC", "A?GC", "AG?C"
    rep(n, N)
    {
        rep(i, 5)
        {
            rep(j, 5)
            {
                rep(k, 5)
                {
                    for (int l = 1; l < 5; l++) {
                        if (i == 1 && j == 3 && l == 2)
                            continue;
                        if (i == 1 && k == 3 && l == 2)
                            continue;
                        if (j == 1 && k == 2 && l == 3)
                            continue;
                        if (j == 1 && k == 3 && l == 2)
                            continue;
                        if (j == 3 && k == 1 && l == 2)
                            continue;
                        add(dp[n + 1][j][k][l], dp[n][i][j][k]);
                    }
                }
            }
        }
    }
    ll res = 0;
    for (int i = 1; i < 5; i++) {
        for (int j = 1; j < 5; j++) {
            for (int k = 1; k < 5; k++) {
                add(res, dp[N][i][j][k]);
            }
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 384
import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

l = range(1, n+1)
count = 0
for elem in itertools.permutations(l, n):
    count += 1
    if elem == p:
        p_count = count
    if elem == q:
        q_count = count

print(abs(p_count-q_count))


Measured memory_bytes: 39024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

char rev(char c) {
  return c == 'S' ? 'W' : 'S';
}

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  string cand[4] = {"SS", "SW", "WS", "WW"};
  for(string s: cand) {
    string ans(N, '-');
    ans[N-1] = s[0], ans[0] = s[1];
    rep(i, N) {
      int pr = i == 0 ? N-1 : i-1;
      int ne = i == N-1 ? 0 : i+1;
      char Sne;
      if(ans[i] == 'S') Sne = S[i] == 'o' ? ans[pr] : rev(ans[pr]);
      else              Sne = S[i] == 'o' ? rev(ans[pr]) : ans[pr];
      if(i == N-2) {
        if(ans[ne] != Sne)
          break;
      } else if(i == N-1) {
        if(ans[ne] == Sne) {
          cout << ans << endl;
          return 0;
        }
      } else {
        ans[ne] = Sne;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}



Measured memory_bytes: 512
from bisect import bisect

N, M = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

a = set(A)
b = set(B)

sA = sorted(A)
sB = sorted(B)

if len(a) != len(A) or len(b) != len(B):
    print(0)
    exit()

m = 10**9 + 7
nm = N * M
ans = 1
for x in range(N*M, 0, -1):

    if x in a and x in b:
        ans *= 1
    elif x in a:
        j = bisect(sB, x)
        ans *= M - j
    elif x in b:
        j = bisect(sA, x)
        ans *= N - j
    else:
        ans *= (N - bisect(sA, x)) *  (M - bisect(sB, x)) - (nm - x)
    ans %= m
    
print(ans%m)

Measured memory_bytes: 3188
#include<cstdio>
#include<cstring>
#include<map>
#include<set>

using namespace std;
typedef long long int lli;
typedef pair<int,int> pp;

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

int res[10];
int h,w,n;
set<pp> black, calced;

void chk(int x, int y) {
    if(calced.find(pp(x,y)) != calced.end()) return;
    calced.insert(pp(x,y));
    for(int i=0; i<9; i++)
        if(!(0<=x+dx[i] && x+dx[i]<w && 0<=y+dy[i] && y+dy[i]<h)) return;
    int cnt=0;
    for(int i=0; i<9; i++)
        if(black.find(pp(x+dx[i],y+dy[i])) != black.end()) cnt++;
    res[cnt]++;
}

int main(void) {
    scanf("%d%d%d",&h,&w,&n);
    for(int i=0; i<n; i++) {
        int x,y;
        scanf("%d%d",&y,&x);
        x--, y--;
        black.insert(pp(x,y));
    }

    for(auto xy : black)
        for(int i=0; i<9; i++)
            chk(xy.first+dx[i], xy.second+dy[i]);

    int sum = 0;
    for(int i=1; i<=9; i++)
        sum += res[i];

    printf("%lld\n",(1LL*w*h)-2*h-2*(w-2) - sum);
    for(int i=1; i<=9; i++)
        printf("%d\n", res[i]);

    return 0;
}

Measured memory_bytes: 47104
import java.util.ArrayList;
import java.util.Scanner;

public class Main { 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] line = sc.nextLine().split(" ");
		int wholeApple = Integer.parseInt(line[0]);
		int frgiApple = Integer.parseInt(line[1]);
		System.out.println((wholeApple*3+frgiApple)/2);

		
		
		
	}
}
	
	

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;



int main(int argc, const char * argv[]) {
    
   
    cin.tie(0);
    ios::sync_with_stdio(false);
   
    string s,t; cin>> s >> t;
    if(s[0]==t[2] && s[1]==t[1] && s[2]==t[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	// your code goes here 
	
	 char inp;
	 
	 scanf("%c",&inp);
	 
	 if(inp=='a'|| inp=='e'|| inp=='i'|| inp=='o'|| inp=='u')
	 {
	     printf("vowel");
	     return 0;
	 }
	 else
	 printf("consonant");
	
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

char s[312][312];
vi v[312];
int ans[312][312] = {};

int main(){
	int h, w, k; scanf("%d%d%d", &h, &w, &k);
	REP(i, h) scanf("%s", s[i]);
	REP(i, h){
		REP(j, w) if(s[i][j] == '#') v[i].EB(j);
	}
	int x = 1; // current
	int a = 0;
	REP(i, h){
		if(v[i].empty()) continue;
		v[i].EB(w);
		v[i][0] = 0;
		REP(j, (int)v[i].size() - 1){
			DEBUG("(%d, %d)\n", i, v[i][j]);
			FOR(k, v[i][j], v[i][j+1]){
				ans[i][k] = x;
			}
			x++;
		}
		FOR(j, a, i){
			REP(k, w){
				ans[j][k] = ans[i][k];
			}
		}
		DEBUG("[%d, %d]\n", a, i);
		a = i+1;
	}
		FOR(j, a, h){
			REP(k, w){
				ans[j][k] = ans[a-1][k];
			}
		}
	assert(x == k+1);
	REP(i, h){
		REP(j, w){
			printf("%d ", ans[i][j]);
		}
		printf("\n");
	}
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	
	Scanner sc = new Scanner(System.in);
	public void run() {
		while(sc.hasNext()){
			int t = sc.nextInt();
			int p = sc.nextInt();
			int r = sc.nextInt();
			if(t == 0 && p == 0 && r == 0) break;
			calc(t, p, r);
		}
	}
	public void calc(int t, int p, int r){
		int[][] gotou = new int[t][p];
		int[] seikai = new int[t];
		int[] penalty = new int[t];
		
		for(int i = 0; i < r; i++){
			int tiD = sc.nextInt();
			int piD = sc.nextInt();
			int time = sc.nextInt();
			String line = sc.nextLine();
			String message = line.split(" ")[1];

			if(gotou[tiD-1][piD-1] != -1){
				if(message.equals("WRONG")){
					gotou[tiD-1][piD-1] = gotou[tiD-1][piD-1] + 1;
				}
				else if(message.equals("CORRECT")){
					seikai[tiD-1] = seikai[tiD -1] + 1;
					penalty[tiD-1] = penalty[tiD-1] + (gotou[tiD-1][piD-1] * 1200 + time);
					gotou[tiD-1][piD-1] = -1;
				}
			}
		}
		
		int[] sortedSeikai = new int[t];
		for(int i = 0; i < t; i++) sortedSeikai[i] = i;
		mergesort(sortedSeikai, seikai, penalty);
		
		for(int i = 0; i < t; i++){
			System.out.println((sortedSeikai[i]+1) + " " + seikai[sortedSeikai[i]] + " " + penalty[sortedSeikai[i]]);
		}
		
	}
	public void merge(int[] list1, int[] list2, int[] list,  int[] seikai, int[] penalty){
		int i = 0;
		int j = 0;
		while(i < list1.length || j < list2.length){
			if(j >= list2.length || (i < list1.length && seikai[list1[i]] > seikai[list2[j]])){
				list[i+j] = list1[i];
				i++;
			}
			else if(i < list1.length && j < list2.length && seikai[list1[i]] == seikai[list2[j]]){
				if(penalty[list1[i]] < penalty[list2[j]]){
					list[i+j] = list1[i];
					i++;
				}
				else if(penalty[list1[i]] == penalty[list2[j]] && list1[i] < list2[j]){
					list[i+j] = list1[i];
					i++;
				}
				else if(penalty[list1[i]] == penalty[list2[j]] && list1[i] > list2[j]){
					list[i+j] = list2[j];
					j++;
				}
				else{
					list[i+j] = list2[j];
					j++;
				}
			}
			else{
				list[i+j] = list2[j];
				j++;
			}
		}
	}
	public void mergesort(int[] list, int[] seikai, int[] penalty){
		if(list.length>1){
			int m = list.length/2;
			int n = list.length-m;
			int[] list1 = new int[m];
			int[] list2 = new int[n];
			for(int i = 0; i < m; i++)list1[i] = list[i];
			for(int i = 0; i < n; i++)list2[i] = list[i+m];
			mergesort(list1, seikai, penalty);
			mergesort(list2, seikai, penalty);
			merge(list1, list2, list, seikai, penalty);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 75940