akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

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

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

void init(){
    fac[0] = finv[0] = fac[1] = finv[1] = inv[1] = 1;
    for(int i = 2; i <= N_MAX; i++){
        fac[i] = (fac[i-1]*i)%P;
        inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
        finv[i] = (finv[i-1]*inv[i])%P;
    }
}
ll pp(ll a, ll b){
  return (a * b)%P;
}
//-------------------------------------------------------------------
int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  vll a(n);
  init();
  re(i, n) std::cin >> a[i];
  vvl dp = vv(n+1, 300*300+1, 0, ll), p = vv(n+1, 300*300+1, 0, ll);
  dp[0][0] = p[0][0] = 1;
  ll s = 0, k=0;
  re(i, n) s += a[i];
  for(int i=1;i<=n;i++){
    for(int j=0;j<=300*300;j++){
      dp[i][j] = (dp[i-1][j]*2)%P;
      p[i][j] = p[i-1][j];
      if(j-a[i-1]<0) continue;
      dp[i][j] = (dp[i][j] + dp[i-1][j-a[i-1]])%P;
      p[i][j] = (p[i][j] + p[i-1][j-a[i-1]])%P;
    }
  }
  for(int i=s/2+s%2;i<=300*300;i++) k = (k+dp[n][i])%P;
  if(s%2==0) k = (k - p[n][s/2] + P)%P;
  k = (k*3)%P;
  vll t(500, 1);rep(i, 1, 500) t[i] = (t[i-1]*3)%P;
  std::cout << (t[n]-k+P)%P << '\n';
  return 0;
}


Measured memory_bytes: 471360
#include<iostream>  
    #include<cstdio>  
    #include<cstring>  
    #include<algorithm>  
    using namespace std;  
    typedef long long ll;  
    ll a[100005],dis[100005];  
    int main(){  
        ll n,i;  
        scanf("%lld",&n);  
        ll sum=0;  
        for(i=1;i<=n;i++)scanf("%lld",&a[i]),sum+=a[i];  
        if(sum%(n*(n+1)/2)){  
            printf("NO\n");  
            return 0;  
        }  
        sum/=(n*(n+1))/2;  
        dis[1]=a[1]-a[n];  
        for(i=2;i<=n;i++)dis[i]=a[i]-a[i-1];  
        ll cnt=0;  
        for(i=1;i<=n;i++){  
            if((sum-dis[i]<0)||(sum-dis[i])%n){  
                printf("NO\n");   
                return 0;  
            }  
            else cnt+=(sum-dis[i])/n;  
        }  
        if(cnt!=sum)printf("NO\n");  
        else printf("YES\n");  
        return 0;  
    }  

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

struct BIT {
    vector<int> dat;
    int n;
    
    BIT(int n, int init) :n(n) { dat.assign(n + 1, init); }
    void init(int n, int init) { n = n; dat.assign(n + 1, init); }
    
    //[1, i]
    int max(int i) {
        int m = -1;
        while (i > 0) {
            chmax(m, dat[i]);
            i -= i & -i;
        }
        return m;
    }
    
    void change(int i, int x) {
        while (i <= n) {
            chmax(dat[i], x);
            i += i & -i;
        }
    }
};
int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    cin >> a;
    
    vector<vector<ll>> l(2, vector<ll>(n + 1));
    BIT bit(n, -1);
    rep(c, 2) {
        rep(i, n) {
            l[c][a[i]] = bit.max(a[i]);
            bit.change(a[i], i);
        }
        reverse(a.begin(), a.end());
        bit.init(n, -1);
    }
    
    ll sum = 0;
    rep(i, n) {
        sum += a[i] * ll(i - l[0][a[i]]) * ll((n - i - 1) - l[1][a[i]]);
    }
    cout << sum << endl;
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

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

    rep(i,3){
        cout<<s[i];
    }
    cout<<endl;
    return 0;

}
/*


*/


Measured memory_bytes: 3624
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n, m;
	while (cin>>n>>m,n) {
		vi taro(n);
		vi hanako(m);
		int ts = 0;
		int hs = 0;
		REP(i, n) {
			cin >> taro[i];
			ts += taro[i];
		}
		REP(i, m) {
			cin >> hanako[i];
			hs += hanako[i];
		}
		SORT(taro);
		SORT(hanako);
		bool clear = false;
		int idx1=999999;
		int idx2=999999;
		REP(i,n) {
			REP(j,m) {
				if ((taro[i] - hanako[j]) * 2 == ts - hs) {
					if (idx1 + idx2 > taro[i] + hanako[j]) {
						idx1 = taro[i];
						idx2 = hanako[j];
						clear = true;
					}
				}
			}
		}
		if (!clear)
			cout << -1 << endl;
		else
			cout << idx1 << " " << idx2 << endl;
	}
}

Measured memory_bytes: 2996
import           Control.Monad

main :: IO ()
main = do
    [n, m] <- fmap (map read . words) getLine :: IO [Int]
    ass    <- replicateM n $ fmap (map read . words) getLine :: IO [[Int]]
    print $ solve n m $ map tail ass    -- あらかじめ各行の先頭は取り除いておく

-- 料理1..mで、誰もが好きなものをフィルタしてカウント
solve :: Int -> Int -> [[Int]] -> Int
solve n m ass = length $ filter (judge n ass) [1 .. m]

-- 全ての行がkを含む、すなわちkを含む行がn個あるか判定
judge :: Int -> [[Int]] -> Int -> Bool
judge n ass k = n == length (filter (elem k) ass)


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define pq          priority_queue
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define vll         vector<pll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323
// hitman code

const int N=1e5+5;
ll n,wt,w[101],v[101],dp[101][N];

void solve()
{
    cin>>n>>wt;
    rep(i,1,n+1) cin>>w[i]>>v[i];
    rep(i,1,N) dp[0][i]=inf;
    rep(i,1,n+1){
        rep(j,0,N){
            dp[i][j]=dp[i-1][j]; // not taking this item and having as much value
            if(j>=v[i]) dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
        }
    }
    ll ans=0;
    rep(j,0,N) if(dp[n][j]<=wt) ans=j;
    cout<<ans;
}

int main()
{
    speed_up
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


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

using namespace std;

#define ff(i, a, b) for(int i = (a); (i <= (b)); ++i)
#define FF(i, a, b) for(int i = (a); (i >= (b)); --i)
#define ll long long

const int M = 1000000000 + 7;

struct re {
    int x, y;
//    const bool operator < (const re &a) const {
//        if (x != a.x) return x < a.x;
//        return y < a.y;
//    }
};

int f[1111][1111];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("", "r" , stdin);
    //freopen("", "w", stdout);
    int h, w, a, b;
    cin >> h >> w >> a >> b;

//    if (h * a != w * b) {
//        cout << -1;
//        return 0;
//    }

    ff(i, 1, b)
    ff(j, 1, a) f[i][j] = 1;

    ff(i, b + 1, h)
    ff(j, a + 1, w) f[i][j] = 1;


    ff(i, 1, h) {
        ff(j, 1, w) cout << f[i][j];
        if (i != h) cout << endl;
    }
}
//This code belongs to s34vv1nd


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

int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max({a*c,a*d,b*c,b*d})<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<queue>	
#include<functional>

using namespace std;

namespace MyLib {
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long
}

using namespace MyLib;



int main() {
	int n;
	while (cin >> n, n) {
		int a, b, c, x,f;
		cin >> a >> b >> c >> x;
		vector<int> y(100);
		REP(i, n) cin >> y[i];
		f = 0;
		REP(i, n) {
			for (;;f++) {
				if (x == y[i])
					break;
				if (f > 10000)
					break;
				x = (a*x + b) % c;
			}
			if (i < n - 1) {
				f++;
				x = (a*x + b) % c;
			}
			if (f > 10000) {
				f = -1;
				break;
			}
		}
		cout << f << endl;

	}

	
}

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

using namespace std;

#define vit vector<int>::iterator
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fr first
#define sc second
#define skip continue
#define PI 3.14159265

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;

const int INF = 1e9 + 5;
const int MAXN = 3e6 + 123;

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool cmp(const string& a, const string& b) {
	return (a + b) < (b + a);
}

vector<int> Reversed(const vector<int>& s){
   vector<int> d = s;
   reverse(all(d));
   return d;
}

void solve(){
    int n,k;
    cin >> n >> k;
    ull ans = pow(k-1,n-1);
    ull cnt = ans * k;
    cout << cnt;
}
int main(){
    //freopen("lepus.in","r",stdin);
   // freopen("lepus.out","w",stdout);
    //faster();
    int n=1;
    //cin>>n;
    while(n--){
        solve();
        //cout << endl;
    }
    //fclose(stdout);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int i = in.nextInt();
		for (int num = 0; num < i;num++) 
		{
			int total = 0;			
			String string1 = in.next();
			String string2 = in.next();
			int array[][] = new int[string1.length()+1][string2.length()+1];
			
			
			for(int h = 1;h <= string1.length();h++)
				for(int j = 1; j <= string2.length();j++) 
				{   
					char char1 = string1.charAt(h-1);
					char char2 = string2.charAt(j-1);
					if(char1 == char2) 
						{
						array[h][j] = array[h-1][j-1]+1;
						total  = array[h][j];
						}else {
						array[h][j] = Math.max(array[h][j-1], array[h-1][j]);
						total =	array[h][j];
							  }
				}
		System.out.println(total);
		}
		in.close();

	}

}



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

int main() {
    int v, n, k;
    cin >> n >> k;

    vector<int> a(n + 1);
    for (int i = 0; i < n ; i++) {
        cin >> v;
        a.at(v)++;
    }

    sort(a.begin(), a.end());

    int total = 0;
    for (int i = a.size() - 1 - k; i >= 0; i--) {
        total += a.at(i);
    }

    cout << total << endl;
    return 0;
}

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

int main(void){

    int N;
    cin >> N;
    vector<long> H(N);

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

    long max=0;
    for (int i = 0; i < N; ++i) {
        if(H[i] < max) {
            H[i]++;
            if(H[i] < max){
                cout<<"No"<<endl;
                return 0;
            }
        }
        max = H[i];


    }
    cout<<"Yes"<<endl;

    return 0;
}

Measured memory_bytes: 1024
import numpy as np

a,b,x = list(map(int,input().split()))
if x/(a**2) > b/2:
    print(np.arctan((b - x/(a**2)) / (a/2))*(180 /np.pi))
else:
    y = 2*x/(b*a)
    print(np.arctan(b / y)*(180 /np.pi))

Measured memory_bytes: 21408
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int K, S;
    cin >> K >> S;
    int ans = 0;
    for(int i = 0; i <= K; i++){
        for(int j = 0; j <= K; j++){
            if(i + j <= S && i + j >= S - K){
                ans += 1;
            }
        }
    }
    cout << ans;
}

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

int main() {
  int n;
  while(cin >> n) {
    int m = 100000;
    while(n--) {
      m = (int)(ceil(m*1.05/1000.0)*1000);
    }
    cout << m << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
def mainFunc():
    M, D = list(map(int, input().split(" ")))
    months = []
    for i in range(10, D + 1):
        s = str(i).zfill(2)
        divD = list(map(int, list(s)))
        ml = divD[0] * divD[1]
        if 1 <= ml <= M and divD[0] > 1 and divD[1] > 1:
            months.append(ml)
    
    print(len(months))

mainFunc()

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

const int N = 10;

char s[N];

int main(){
	scanf("%s", s);
	int x = s[0] == 'H';
	scanf("%s", s);
	int y = s[0] == 'H';
	return printf(x ^ y ? "D\n" : "H\n"), 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int a,b;cin>>a>>b;
    cout<<max({2*a-1,2*b-1,a+b})<<endl;
}

Measured memory_bytes: 3640
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X;
    cin >> X;
    ll v = X / 500;
    ll ans = v * 1000 + (X - v * 500) / 5 * 5;
    print(ans);

}

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

int main(){
	string S,T;
	cin >> S >> T;
	for(int i=0;i<S.length();i++){
		if(S.compare(T)==0) {
			cout << "Yes" << endl;
			return 0;
		}
		S = S.back() + S.substr(0,S.size()-1);
	}
	cout << "No" << endl;
	return 0;

}


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

using namespace std;
#define rep(i,n) for(int i=1;i<n+1;i++)
#define ll long long int

int main(){
  int N;
  cin>>N;
  ll count=0;
  rep(i,N){
    if(i%3==0||i%5==0){}
      
    else
      count+=i;

  }
  cout<<count;
  return 0;
}


Measured memory_bytes: 3632
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
    struct newdata
    {
        int label,cnt;
    };
    int n,m;
    int a[301][301];
    newdata rank[301];
    bool used[301];
bool cmp(newdata i,newdata j)
{
    return (i.cnt>j.cnt);
}
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
        {
            scanf("%d",&a[i][j]);
            if (j==1) rank[a[i][j]].cnt++;
        }
    int now=0;
    for (int i=1;i<=m;i++)
        rank[i].label=i;
    int ans=2147483647;
    while (now<m)
    {
        sort(rank+1,rank+m+1,cmp);
        ans=min(ans,rank[1].cnt);
        used[rank[1].label]=true;
        memset(rank,0,sizeof(rank));
        for (int i=1;i<=m;i++)
            rank[i].label=i;
        for (int i=1;i<=n;i++)
            for (int j=1;j<=m;j++)
            	if (!used[a[i][j]])
            	{
					rank[a[i][j]].cnt++;
					break;
				}
        now++;
    }
    printf("%d",ans);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define print(a) cout<<(a)<<endl;
#define to_ll(b) stoll(b)
#define MOD 1000000007

int main(){
	string s,ans;
	cin>>s;
	rep(i,0,s.size()){
		char a=s.at(i);
		if(a=='1' || a=='0'){
			ans.push_back(a);
		}
		else{
			if(ans==""){
				continue;
			}
			else ans.pop_back();
		}
	}
	print(ans)
	
}

Measured memory_bytes: 256
#include <string>
#include <assert.h>
#include <cmath>
#include <algorithm>
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    
    int count = 0;
    int isOdd = false;
    while(true) {
        for (int i = 0; i < n; i++) {
            if (a[i] % 2 == 0) a[i] >>= 1;
            else isOdd = true;
        }
        if (isOdd) break;
        count ++;
    }
    cout  << count << endl;
    return 0;
}


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

using namespace std;
#define int long long

signed main(){
    int X,Y;
    cin >> X >> Y;
    
    int ans = 0;
    if(X<=3) ans += (4-X)*100000;
    if(Y<=3) ans += (4-Y)*100000;
    if(X == 1 && Y == 1) ans += 400000;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int popcount32(unsigned int x) {
	x = x - ((x >> 1) & 0x55555555);
	x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
	x = (x + (x >> 4)) & 0x0F0F0F0F;
	x = x + (x >> 8);
	x = x + (x >> 16);
	return x & 0x0000003F;
}

int dp[1 << 18][18];


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

	int n;
	int ab[2][18];

	cin >> n;
	rep(i, n)cin >> ab[0][i];
	rep(i, n)cin >> ab[1][i];

	rep(i, 1 << n)rep(j, n)dp[i][j] = INF;
	rep(i,n) {
		dp[1 << i][i] = i;
	}

	rep(i, 1 << n)rep(j, n)if (dp[i][j] != INF) {
		int p = popcount32(i);
		int prev = ab[abs((p - 1) - j) % 2][j];

		rep(k, n) if ((i >> k & 1) == 0) {
			int dif = abs(p - k) % 2;
			if (prev > ab[dif][k])continue;

			dp[i | 1 << k][k] = min(dp[i | 1 << k][k]
				, dp[i][j] + k - popcount32(i & ((1 << k) - 1)));
		}
	}

	int ans = INF;
	rep(i, n)ans = min(ans, dp[(1 << n) - 1][i]);
	if (ans == INF) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}



	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<tuple<string, int, int>> v(n);
  for (int i = 0; i < n; i++) {
    cin >> get<0>(v[i]) >> get<1>(v[i]);
    get<2>(v[i]) = i + 1;
  }

  sort(v.begin(), v.end(), [](auto a, auto b) {
    if (get<0>(a) == get<0>(b))
      return get<1>(a) > get<1>(b);
    else
      return get<0>(a) < get<0>(b);
  });

  for (int i = 0; i < n; i++) cout << get<2>(v[i]) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cassert>

using namespace std;    
static const int MAX_NUM = 100;

int bubbleSort(int array[], int num);

int main()
{
    int num;
    int array[MAX_NUM];

    cin >> num;
    for(int i = 0; i < num; ++i) cin >> array[i];

    int swap_cnt = bubbleSort(array, num);

    for(int i = 0; i < num; ++i)
    {
        if(i != 0) cout << " ";
        cout << array[i];
    }

    cout << endl;
    cout << swap_cnt << endl;

    return 0;
}

int bubbleSort(int array[], int num)
{
    assert(num > 0);

    int swap_cnt = 0;    
    bool flag = true;
    while(flag)
    {
        // ソート済み要素のカウント
        // バブルソートは一巡する度に先頭から「ソート済み」になって位置が確定する
        int sorted_cnt = 0;

        // もう一巡させるかどうかのフラグ
        // 一旦クリアしておく
        flag = false;

        for(int j = num - 1; j > sorted_cnt; --j)
        {
            if(array[j] < array[j-1])
            {
                std::swap(array[j], array[j-1]);
                flag = true;
                ++swap_cnt;
            }
        }
        ++sorted_cnt;
    }

    return swap_cnt;
}



Measured memory_bytes: 3100
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
    int n;
    string s;
    cin >> n >> s;
    int tmp,ans;
    tmp=0;
    ans=0;
    
    //処理
    REP(i,0,n){
        if(s[i]=='I') tmp++;
        if(s[i]=='D') tmp--;
        chmax(ans,tmp);
    }
    
    //出力
    cout << ans << ENT;
    return 0;
}

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


Measured memory_bytes: 256
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh
#define hash asdgasdgasdgdfrywewery

#define eps 1e-12
#define M_PI 3.141592653589793
#define bsize 300

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 200031;

long long n,p;

long long pw(long long a,long long b){
	if (b==0)
		return 1;
	return a*pw(a,b-1);
}

vector<pair<long long, long long> > factorize(long long x){
	vector<pair<long long, long long> > V;
	for (long long i=2;i*i<=x;i++){
		if (x%i)
			continue;
		int cnt=0;
		while (x%i==0){
			x/=i;
			cnt++;
		}
		V.push_back(make_pair(i,cnt));
	}
	if (x>1){
		V.push_back(make_pair(x,1));
	}
	return V;
}

int main(){
//    freopen("apache.in","r",stdin);
//    freopen("apache.out","w",stdout);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    //cin.tie(0);

    cin>>n>>p;

    vector<pair<long long, long long> > V=factorize(p);

    long long ans=1;
    for (int i=0;i<V.size();i++){
    	int here=V[i].second/n;
    	ans=ans*pw(V[i].first,here);
    }
    cout<<ans<<endl;

//    cin.get(); cin.get();
    return 0;
}


Measured memory_bytes: 256
s={}
for i in range(int(input())):
  ss=input()
  if ss in s:
    s[ss]+=1
  else:
    s[ss]=1
t={}
for i in range(int(input())):
  tt=input()
  if tt in t:
    t[tt]+=1
  else:
    t[tt]=1
for k,v in s.items():
  if k in t:
    s[k]-=t[k]
ans=sorted(s.items(),key=lambda x:x[1])
if ans[-1][1]>=0:
  print(ans[-1][1])
else:
  print(0)
  

Measured memory_bytes: 3064
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int a,b;

    private void solve() {
        a = nextInt();
        b = nextInt();

        out.println(a * b % 2 == 0 ? "Even" : "Odd");
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 21204
#include<iostream>
#include <cmath>
using namespace std;
typedef long long ll;

ll A, B, N;

int main() {
  cin >> A >> B >> N;
  ll x = min(B-1, N);
   
  int res = floor(A*x/B) - (A * floor(x/B));
  
  cout << res << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007 //(10^9 +7)
using namespace std;
typedef long long  ll;
typedef long double ld;
const ll N=100005;
const ll inf=1e18;
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b&1){
            res=res*a;
        }
        a=a*a;
        b>>=1;
    }
    return res;
}
int main(){
    fastIO;
    ll n;
    cin>>n;
    vector<ll> vect(n,0);
    ll i=0,j=0;
    for(i=0;i<n;i++){
        cin>>vect[i];
    }
    vector<ll> dp(n,0);
    dp[0]=0;
    dp[1]=abs(vect[1]-vect[0]);
    for(i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(vect[i]-vect[i-1]),dp[i-2]+abs(vect[i]-vect[i-2]));
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 1792
n=int(input())
if n%2==0:
    s=n+1
    res=[]
    for i in range(1,n//2+1):
        res.append([i,s-i])
    z=[]
    for i in range(len(res)-1):
        for j in range(i+1,len(res)):
            for x in range(2):
                for y in range(2):
                    z.append([min(res[i][x],res[j][y]),max(res[i][x],res[j][y])])
    print(len(z))
    for t in z:
        print(t[0],t[1])
else:
    s=n
    res=[]
    for i in range(1,n//2+1):
        res.append([i,s-i])
    z=[]
    for i in range(len(res)-1):
        for j in range(i+1,len(res)):
            for x in range(2):
                for y in range(2):
                    z.append([min(res[i][x],res[j][y]),max(res[i][x],res[j][y])])
    for i in range(1,n):
        z.append([i,n])
    print(len(z))
    for t in z:
        print(t[0],t[1])

Measured memory_bytes: 46960
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;
	public static final long HUGE_NUM = 99999999999999999L;
	public static final double EPS = 0.000000001;

	public static int W[];
	public static int num_W;
	public static int num_track;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			String tmp_str[] = br.readLine().split("\\s+");

			num_W = Integer.parseInt(tmp_str[0]);
			num_track = Integer.parseInt(tmp_str[1]);

			W = new int[num_W];
			long sum = 0;

			for(int i = 0; i < num_W; i++){

				W[i] = Integer.parseInt(br.readLine());
				sum += W[i];
			}

			long left = 0,right = sum,mid = (left+right)/2;
			long ans = right;

			while(left <= right){

				if(is_OK(mid)){

					ans = mid;
					right = mid-1;

				}else{

					left = mid+1;
				}
				mid = (left+right)/2;
			}

			System.out.println(ans);

		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}

	public static boolean is_OK(long P){

		int index_W = 0,index_truck = 0;

		long tmp_sum;

		while(index_W < num_W && index_truck < num_track){

			tmp_sum = 0;
			while(index_W < num_W && tmp_sum+W[index_W] <= P){

				tmp_sum += W[index_W];
				index_W++;
			}
			index_truck++;
		}

		return index_W == num_W;
	}
}

class UTIL{

	//文字が半角数字か判定する関数
	public static boolean isNumber(String tmp_str){
		Pattern pattern = Pattern.compile("\\A[0-9]+\\z");
		Matcher matcher = pattern.matcher(tmp_str);
		return matcher.matches();
	}
}


Measured memory_bytes: 35644
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <tuple>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sys/time.h>

using namespace std;

void solve(long long N, long long X, vector<long long> L){
  long long ans = 1;
  long long x = 0;
  for (int i = 0; i < N; i++) {
    x += L[i];
    if (x <= X) {
      ans++;
    }
  }
  std::cout <<  ans << std::endl;
}

int main(){
  long long N;
  long long X;
  scanf("%lld",&N);
  vector<long long> L(N);
  scanf("%lld",&X);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&L[i]);
  }
  solve(N, X, L);
  return 0;
}


Measured memory_bytes: 256
N = int(input())
C = list(input())

left = 0
right = N - 1

ans = 0
while left < right:
    if C[left] == "W":
        if C[right] == "R":
            ans += 1
            left += 1
            right -= 1
        else:
            right -= 1
    else:
        left += 1


print(ans)



Measured memory_bytes: 10632
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int INF=1e3+125;
const int dfx[]={0,0,1,-1},dfy[]={1,-1,0,0};
const int bfx[]={-2,-2,-2,-2,-2,-1,-1,-1,-1,0,0,1,1,1,1,2,2,2,2,2};
const int bfy[]={-2,-1,0,1,2,-2,-1,1,2,-2,2,-2,-1,1,2,-2,-1,0,1,2};
int h,w,cx,cy,dx,dy,qx[INF*INF*30+25],qy[INF*INF*30+25],l,r,dis_[INF][INF];
bool vis[INF][INF];
char Map[INF][INF];
void DFS(int x,int y) {
        for (int i=0; i<4; i++) {
                int gx=x+dfx[i],gy=y+dfy[i];
                if (gx<1 || gy<1 || gx>h || gy>w|| Map[gx][gy]!='.' || dis_[gx][gy]<=dis_[x][y] || vis[gx][gy]) continue;
                vis[gx][gy]=true;
                dis_[gx][gy]=dis_[x][y];
                qx[++r]=gx;
                qy[r]=gy;
                DFS(gx,gy);
        }
        return;
}
void BFS() {
        memset(dis_,63,sizeof dis_);
        vis[cx][cy]=true;
        dis_[cx][cy]=0;
        DFS(cx,cy);
        bool flag=false;
        while (l<=r) {
                int x=qx[l],y=qy[l]; l++;
                if (vis[dx][dy]) flag=true;
                if (flag) break;
                for (int i=0; i<20; i++) {
                        int gx=x+bfx[i],gy=y+bfy[i];
                        if (gx<1 || gy<1 || gx>h || gy>w|| Map[gx][gy]!='.' || dis_[gx][gy]<dis_[x][y]+1 || vis[gx][gy]) continue;
                        dis_[gx][gy]=dis_[x][y]+1;
                        vis[gx][gy]=true;
                        DFS(gx,gy);
                        if (vis[dx][dy]) flag=true;
                        if (flag) break;
                        qx[++r]=gx;
                        qy[r]=gy;
                }
                if (flag) break;

                // for (int i=1; i<=h; i++) {
                //         for (int j=1; j<=w; j++)
                //                 printf("%10d ",dis_[i][j]);
                //         putchar('\n');
                // }
                // putchar('\n');
        }
        return;
}
signed main()
{
        // freopen("test.out","w",stdout);
        scanf("%d %d",&h,&w); scanf("%d %d %d %d ",&cx,&cy,&dx,&dy);
        for (int i=1; i<=h; i++) {
                for (int j=1; j<=w; j++)
                        cin>>Map[i][j];
        }
        // cout<<"ok\n";
        l=1;
        qx[++r]=cx;
        qy[r]=cy;
        BFS();
        if (vis[dx][dy]) cout<<dis_[dx][dy]<<"\n";
        else cout<<"-1\n";
        return 0;
}


Measured memory_bytes: 14028
#include<iostream>
#include<string>
using namespace std;
int main(){
	int h,w;
	while(cin>>h>>w){
	if(h==0&&w==0)
		break;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++)
			cout<<"#";
		cout<<endl;
	}
	cout<<endl;
	}
	return 0;
}

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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int x,y,ans[13] = {0,1,0,1,2,1,2,1,1,2,1,2,1};

main() {
    cin >> x >> y;
    if (ans[x] == ans[y]) ct("Yes")
    else ct("No")
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

int x[22][42];
int r, n;
int dx[] = {0, -1, -1, 0};
int dy[] = {0, 0, -1, -1};

bool check(double t) {
  repl(i, 1, 21)repl(j, 1, 41) {
    if ((i - 1 - t + r) * (i - 1 - t + r) + (j - 21) * (j - 21) < r * r) {
      rep(k, 4) {
        if (x[i + dy[k]][j + dx[k]] == 0) {
          return false;
        }
      }
    }
  }
  return true;
}

int main(){
  cin.sync_with_stdio(false);
  rep(i, 22)rep(j, 42) x[i][j] = 1;

  while(cin >> r >> n, r) {
    repl(i, 1, 21)repl(j, 1, 41) x[i][j] = 0;

    rep(i, n) {
      int l, r, h;
      cin >> l >> r >> h;

      repl(k, 1, h + 1)repl(j, l + 21, r + 21) x[k][j] = 1;
    }

    double ok = 0, ng = 20, md;
    rep(i, 100) {
      md = (ok + ng) / 2;
      if (check(md)) ok = md;
      else ng = md;
    }

    printf("%.10f\n", ok);
  }

  return 0;
}

Measured memory_bytes: 3172
#include<stdio.h>
#include<string.h>
int main(void)
{
	char str[100];
	scanf("%s", str);
	int i;
	int k = 0;
	int len= strlen(str);
	for (i = 0; i < len; i++)
	{
		if (i == 0 && str[i] == 'B') {
			str[i] = '\0';
			continue;
		}
		else if (str[i] == 'B')
		{
			k = i;
			str[i] = '\0';
			while (str[k] == '\0'&&k>=1)
			{
				if (str[k - 1] != '\0')
				{
					str[k - 1] = '\0';
					break;
				}
				k--;
			}
		}
	}
	for (i = 0; i < len; i++)
	{
		while (str[i] == '\0')
		{
			i++;
		}
		if (i >= len) break;
		printf("%c", str[i]);
	}
	printf("\n");
	return 0;
}


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

int main() {
  int n,x=0,tmp;
  cin >> n ;
  tmp=n;
  while(tmp>0){
      x+=tmp%10;
      tmp/=10;
  }
  if (n%x==0){
   cout<<"Yes"<<endl;   
  }
    else
    {
        cout<<"No"<<endl;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define pb push_back
#define ll long long
#define F first
#define S second
#define ld long double
 
using namespace std;
 
void data() {
    #ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
}
 
const int N = 1e6 + 100;
const ll mod = 998244353; //1e9 + 7

int main () 
{
    data();               
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a / b + (a % b ? 1 : 0)) * c;
}


Measured memory_bytes: 3564
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MOD (ll)1000000007

ll power(ll a, ll p)
{
	if (p == 0)
		return 1LL;
	else if (p == 1LL)
		return a;

	ll ret = power(a, p / 2LL);
	ret = (ret * ret) % MOD;
	if (p % 2LL)
		ret = (ret * a) % MOD;
	
	return ret % MOD;
}

int main(void)
{
	ll n;
	scanf("%lld", &n);
	ll ans = power(10LL, n);
	ll mi = power(9LL, n);
	ll eight = power(8LL, n);

	ans = (ans + eight) % MOD;
	ans = (ans - mi * 2LL + MOD * 2LL) % MOD;
	printf("%lld", ans);
	return 0;
}

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

using ll = long long;

ll f(ll X, ll Y)
{
    if (Y > X) return f(Y, X);
    if (X % Y == 0) return 2 * X - Y;
    else return (X / Y) * 2 * Y + f(X % Y, Y);
}

ll solve(ll N, ll X) { return N + f(X, N-X); }

int main()
{
    ll N, X; cin >> N >> X;
    cout << solve(N, X) << endl;
}

Measured memory_bytes: 256
//Alter Altar

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n;string s;cin>>n>>s;
    bool flag = true;
    int W=0,R=0,ans=0;
    rep(i,0,n){
        if(s[i]=='W')W++;
        else R++;
    }
    rep(i,0,R){
        if(s[i]=='W')ans++;
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 3720
<?php
fscanf(STDIN, "%d %d", $X, $Y);
$kame = ($Y/2) - $X;
$turu = $X - $kame;

if($turu >= 0 && $kame >= 0 && $X === $turu + $kame && $Y === 2*$turu + 4*$kame){
    echo "Yes";
}else{
    echo "No";
}
?>

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

int main() {
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  if(e-a>k){
    cout<<":("<<endl;
  }
  else{
    cout<<"Yay!"<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,a[200000];
  cin >> n;
  long long X=0,x=0,ans=1000000000000000;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    X+=a[i];
  }
  for(int i=0; i<n; i++) {
    x+=a[i];
    if(i<n-1) {
      ans=min(ans,abs(X-2*x));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
/*
00:42 - 01:17
 */

#include<iostream>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<algorithm>
#include<climits>
#include<cassert>
#include<cstdio>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 31
using namespace std;

int H,W;
bool used[MAX][MAX];
char G[MAX][MAX];
int sp,mincost;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

inline bool isValid(int x,int y){ return ( 0 <= x && x < W && 0 <= y && y < H); }

void dfs(int cur,int cost,int pdir){

  if(cost >= 10)return;
  if(mincost <= cost)return;
  int x = cur % W, y = cur / W;

  if(G[y][x] == '>'){
    mincost = min(mincost,cost);
    return;
  }

  if(used[y][x])return;

  rep(i,4){
    if(i == pdir)continue;

    int rnx = x + dx[(i+2)%4], rny = y + dy[(i+2)%4];//次に進む方向の逆
    if( G[rny][rnx] == '#' ){

      used[y][x] = true;
      int nx = x + dx[i], ny = y + dy[i];
      while( G[ny][nx] == '_' ){ 
	if( G[ny+dy[i]][nx+dx[i]] == '^' )break;
	if( G[ny+dy[i]][nx+dx[i]] == '_'){
	  G[ny+dy[i]][nx+dx[i]] = '#';
	  dfs(nx+ny*W,cost+1,(i+2)%4);
	  G[ny+dy[i]][nx+dx[i]] = '_';
	}
	  nx += dx[i], ny += dy[i];
      }
      if( G[ny][nx] == '>' )dfs(nx+ny*W,cost,(i+2)%4);
      if( G[ny][nx] == '#'){
	nx -= dx[i], ny -= dy[i];
	dfs(nx+ny*W,cost,(i+2)%4);
      }
      used[y][x] = false;
    } else if( rnx+rny*W != sp && G[rny][rnx] == '_' ) {
      G[rny][rnx] = '#';
      dfs(cur,cost+1,pdir);
      G[rny][rnx] = '_';
    }
  }
}

int main(){
  int T;
  scanf("%d",&T);
  while(T--){
    scanf("%d %d",&H,&W);
    rep(y,H)rep(x,W){
      cin >> G[y][x];
      if(G[y][x] == 'A')sp = x + y * W, G[y][x] = '_';
      used[y][x] = false;
    }
    
    mincost = IINF;
    dfs(sp,0,IINF);
    if(mincost == IINF)puts("10");
    else               printf("%d\n",mincost);

  }
  return 0;
}

Measured memory_bytes: 1228
#include<cstdio>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    ll sum = 0;
    scanf("%lld",&n);
    for(ll i = 1;i<=n;i++){
        if(i%3!=0&&i%5!=0)sum+=i;
    }
    printf("%lld",sum);
}

Measured memory_bytes: 1736
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    s1,s2,s3 = map(str, input().split())
    tmp = s1[0] + s2[0] + s3[0]
    print(tmp.upper())
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 39152
#include<iostream>


int area(int length, int breadth) {
  return length * breadth;
}

int perimeter(int length, int breadth) {
  return length * 2 + breadth * 2;
}

int main() {
  int a, b;

  std::cin >> a >> b;
  std::cout << area(a, b) << " " << perimeter(a, b) << std::endl;

  return 0;
}



Measured memory_bytes: 3004
#include<bits/stdc++.h>
using namespace std;
int64_t mod=1e9+7;
int64_t f(int64_t x){
  int64_t y=1,i;
  for(i=2;i<=x;i++) y=y*i%mod;
  return y;
}
int main(){
  int64_t n,m;
  cin>>n>>m;
  if(abs(n-m)>1) cout<<0<<endl;
  else if(n!=m) cout<<f(n)*f(m)%mod<<endl;
  else if(n==m) cout<<f(n)*f(n)%mod*2%mod<<endl;
}

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

const ll N = 200005, INF = 1e18;
ll n, h[N], a[N];
ll dp[N], t[4 * N];

void modify(ll v, ll vl, ll vr, ll pos, ll val){
    if(vl == vr){
        t[v] = val;
        return;
    }
    ll vm = (vl + vr) >> 1;
    if(pos <= vm){
        modify(v*2+1, vl, vm, pos, val);
    }else{
        modify(v*2+2, vm+1, vr, pos, val);
    }
    t[v] = max(t[v*2+1], t[v*2+2]);
}

ll query(ll v, ll vl, ll vr, ll l, ll r){
    if(l > vr || r < vl){
        return -INF;
    }
    if(l <= vl && vr <= r){
        return t[v];
    }
    ll vm = (vl + vr) >> 1;
    ll q1 = query(v*2+1, vl, vm, l, r);
    ll q2 = query(v*2+2, vm+1, vr, l, r);
    return max(q1, q2);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n; 
    for(ll i = 1; i <= n; i++){cin>>h[i]; modify(0, 1, N-1, h[i], -INF);}
    for(ll i = 1; i <= n; i++){cin>>a[i];}
    modify(0, 1, N-1, h[n+1], 0);
    for(ll i = n; i >= 1; --i){
        dp[i] = max(dp[i], query(0, 1, N-1, h[i]+1, N-1) + a[i]);
        modify(0, 1, N-1, h[i], dp[i]);
    }
    cout<<query(0, 1, N-1, 1, N-1);
    return 0;
}

Measured memory_bytes: 11264
# coding: utf-8
# user: herp_sy

def quicksort(seq):
    if len(seq) < 1:
        return seq
    pivot = seq[0]
    left = []
    right = []
    for x in range(1, len(seq)):
        if seq[x] <= pivot:
            left.append(seq[x])
        else:
            right.append(seq[x])
    left = quicksort(left)
    right = quicksort(right)
    foo = [pivot]
    return (left + foo + right)

# , = map(int, input.split())
#  = int(input())

cnt = 0
cf2016 = "CODEFESTIVAL2016"
s = input()
for i in range(0,len(cf2016)):
    if cf2016[i] != s[i]:
        cnt = cnt + 1
print(cnt)

Measured memory_bytes: 3064
#ifndef _WIN32
#include<iostream>
#endif

#include <complex>
#include <vector>
using namespace std;


#define FOR(i,bg,ed) for(int i = (bg);<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back

#define IL inline
namespace geo{
	typedef double D;
	typedef bool B;
	typedef complex<D> P;
#define X real()
#define Y imag()
	B comp(const P& l, const P& r)
	{
		return (l.X == r.X) ? l.Y < r.Y : l.X < r.X;
	}
	typedef pair<P, P> L;
	typedef pair<P, P> LS;
	typedef pair<P, D> C;
	typedef vector<P> Poly;
	const D EPS = 1e-8;

	//Decomposition Macro
#define DCI(a,b,l) P(a),(b);tie(a,b)=l;
#define DCc(a,b,c) P(a);D(b);tie(a,b)=c;

	//A dot B
	IL D dot(P a, P b)
	{
		return a.X*b.X + a.Y*b.Y;
	}
	IL D cross(P a, P b)
	{
		return a.X*b.Y - a.Y*b.X;
	}
	IL D ccw(P a, P b, P c)
	{
		return cross(b - a, c - a);
	}
}

using namespace geo;


int main()
{
	int n;

	cin >> n;
	while (n--){
		D x1, x2, x3, y1, y2, y3, x4, y4;

		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		P a(x1 - x2, y1 - y2), b(x3 - x4, y3 - y4);

		if (dot(a, b) == 0)
		{
			cout << 1 << endl;
			continue;
		}
		else if (cross(a, b) == 0){
			cout << 2 << endl;
			continue;
		}
		else{
			cout << 0 << endl;
			continue;
		}
	}
	return 0;
}

Measured memory_bytes: 3224