akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) {
        FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        Task solver = new Task();
        int t = 1;
        while (t --> 0) solver.solve(1, scan, out);
        out.close();
    }

    static class Task {

        public void solve(int testNumber, FastReader scan, PrintWriter out) {
            int n = scan.nextInt();
            for(char c : scan.next().toCharArray()) {
                int next = (c-'A'+n)%26;
                out.print((char) (next+'A'));
            }
        }
    }

    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static void shuffle(long[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            long temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(new File(s)));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 21460
C = [[int(i) for i in input().split()] for j in range(3)]
a = [sum(C[i]) - sum(C[i-1]) for i in range(3)]
b = [sum([C[j][i] for j in range(3)]) - sum([C[j][i-1] for j in range(3)]) for i in range(3)]
for i in range(3):
    if not (a[i]/3).is_integer() or not (b[i]/3).is_integer():
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 9212
#include <iostream>

using namespace std;

int main(){
  string n;
  std::cin >> n;
  if(n[0] == '7' || n[1] == '7' || n[2] == '7'){
    std::cout << "Yes" << '\n';
  }else{
    std::cout << "No" << '\n';
  }
  return 0;
}


Measured memory_bytes: 3040
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	long pow(long a,long n) {
		long r=1;
		for(;n>0;n>>=1,a=a*a%MOD)if(n%2==1)r=r*a%MOD;
		return r;
	}
	
	final long MOD=(long)1e9+7;
	
	int N=(int)1e6;
	long[] fac=new long[N];
	long[] inv=new long[N];
	long[] ifac=new long[N];
	{
		fac[0]=fac[1]=inv[0]=inv[1]=ifac[0]=ifac[1]=1;
		for(int i=2;i<fac.length;++i) {
			fac[i]=i*fac[i-1]%MOD;
			inv[i]=MOD-inv[(int)(MOD%i)]*(MOD/i)%MOD;
			ifac[i]=inv[i]*ifac[i-1]%MOD;
		}
	}
	
	long comb(int n,int k) {
//		long ret=1;
//		for(long i=n;i>=n-k+1;--i)ret=ret*i%MOD;
//		for(int i=1;i<=k;++i)ret=ret*inv[i]%MOD;
//		return ret;
		return fac[n]*ifac[k]%MOD*ifac[n-k]%MOD;
	}
	
	//最終的な分布がa_iになったとする。
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long k=sc.nextLong();
		long ans=0;
		for(int zero=0;zero<=Math.min(k, n-1);++zero) {
			int a=n-zero;
			int b=zero;
			ans+=comb(n,zero)*comb(a+b-1,b)%MOD;
			ans%=MOD;
		}
		System.out.println(ans);
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}


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

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

    for(int i=0;i<3;i++){
      if(s[i]==s[i+1]){
        cout << "Bad" << endl;
        return 0;
      }
    }

    cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
def gcd(a, b):
    while b != 0:
        a, b = b, a%b
    return a


def main():
    N, X = map(int, input().split())
    x = [abs(int(i) - X) for i in input().split()] 

    y = x[0]
    for i in range(N):
        if x[i]%y == 0:
            continue
        y = gcd(y, x[i])
    print(y)


if __name__ == '__main__':
    main()

Measured memory_bytes: 14248
import sys
import collections


def solve():
    sys.setrecursionlimit(2000)
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(list)
    for i in range(m):
        a, b = list(map(int, input().rstrip('\n').split()))
        if a == 1:
            d[b] += [1]
        if b == 1:
            d[a] += [1]
        if a == n:
            d[b] += [n]
        if b == n:
            d[a] += [n]
    for k, v in d.items():
        if len(v) == 2:
            print("POSSIBLE")
            exit()
    print("IMPOSSIBLE")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 80604
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.D_Challenge
{
    class ABC_099
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nc = ReadInts();
            int n = nc[0];
            int c = nc[1];
            var ds = new int[c, c];
            for (int i = 0; i < c; i++)
            {
                int[] input = ReadInts();
                for(int j = 0; j < c; j++)
                {
                    ds[i, j] = input[j];
                }
            }

            var cs = new int[n, n];
            for (int i = 0; i < n; i++)
            {
                int[] input = ReadInts();
                for (int j = 0; j < n; j++)
                {
                    cs[i, j] = input[j];
                }
            }

            var colors = new int[3,c];//余りと色の個数
            for(int i = 0; i < n; i++)
            {
                for(int j = 0; j < n; j++)
                {
                    colors[(i + j) % 3, cs[i, j] - 1]++;
                }
            }

            var errors = new int[3, c];
            for(int i = 0; i < 3; i++)
            {
                for(int j = 0; j < c; j++)
                {
                    errors[i,j] = 0;
                    for(int k = 0; k < c; k++)
                    {//色kからjに変える
                        errors[i, j] += colors[i, k] * ds[k, j];
                    }
                }
            }

            int minError = int.MaxValue;
            for(int i = 0; i < c; i++)
            {
                for(int j = 0; j < c; j++)
                {
                    if (i == j) continue;

                    for(int k = 0; k < c; k++)
                    {
                        if (i == k || j == k) continue;

                        int errorSum 
                            = errors[0, i] + errors[1, j] + errors[2, k];
                        minError = Math.Min(minError, errorSum);
                    }
                }
            }

            Console.WriteLine(minError);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 17888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X;
    cin >> X;
    int ans = 1;
    for(int i=1;i<=1000;i++){
        for(int k=2;k<=10;k++){
            int now = 1;
            for(int j=1;j<=k;j++){
                now *= i;
                if(now>X) break;
            }
            if(now<=X) ans = max(ans,now);
        }
    }
    cout << ans << "\n";
}

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

int number(string &s, int &i) {
    return s[i++] - '0';
}

int term(string &s, int &i) {
    int res = number(s, i);
    while (true) {
        if (s[i] == '*') {
            i++;
            res *= number(s, i);
        } else {
            break;
        }
    }
    return res;
}

int expr(string &s, int &i) {
    int res = term(s, i);
    while (true) {
        if (s[i] == '+') {
            i++;
            res += term(s, i);
        } else {
            break;
        }
    }
    return res;
}

int main() {
    string s; cin >> s;
    int n = s.length();
    int ans; cin >> ans;
    int ans_LtoR = s[0] - '0';
    for (int i = 1; i < n; i += 2) {
        if (s[i] == '+') ans_LtoR += s[i + 1] - '0';
        if (s[i] == '*') ans_LtoR *= s[i + 1] - '0';
    }
    int i = 0;
    int ans_Mult = expr(s, i);
    bool is_LtoR = ans == ans_LtoR;
    bool is_Mult = ans == ans_Mult;
    if (is_LtoR && is_Mult) {
        cout << "U" << endl;
    } else if (is_LtoR) {
        cout << "L" << endl;
    } else if (is_Mult) {
        cout << "M" << endl;
    } else {
        cout << "I" << endl;
    }
    return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long total = 0;
    string a,b;
    cin >> a >> b;
    multimap<char,int> mp;
    map<char,vector<int>> mp2;
    size_t szA = a.size(), szB = b.size();
    int checkLetters = 0;
    for (int i = 0; i < szB; i++)
    {
        if (mp.find(b[i]) == mp.end())
            checkLetters++;
        mp.insert({b[i], i + 1});
    }
    for (int i = 0; i < szA; i++)
    {
        if (mp.find(a[i]) != mp.end())
        {
            mp2[a[i]].push_back(i + 1);
        }
    }
    if (mp2.size() < checkLetters)
        cout << -1 << endl;
    else
    {
        int prev = -1;
        for (int i = 0; i < szB; i++)
        {
            // asdaosfgdsada
            // so
            int curNum;
            vector<int>::iterator a;
            if (prev != -1)
                a = upper_bound(mp2[b[i]].begin(), mp2[b[i]].end(), prev);
            else
                a = mp2[b[i]].begin();
            if (a == mp2[b[i]].end())
            {
                curNum = mp2[b[i]][0];
            }
            else
            {
                curNum = *a;
            }
            if (prev != -1)
            {
                if (curNum == prev)
                {
                    total += (long long) szA;
                }
                else if (curNum > prev)
                {
                    total += (long long) curNum - (long long) prev;
                }
                else
                {
                    total += (long long) curNum + (long long) szA - (long long) prev;
                }
            }
            else
                total += (long long) curNum;
            prev = curNum;
        }
        cout << total << endl;
    }
    return 0;

}


Measured memory_bytes: 5760
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]

b = sorted(a, key = lambda x: x[1])

work = 0
flag = 0
for i in range(n):
    work += b[i][0]
    if work > b[i][1]:
        flag = 1
        print("No")
        break

if flag == 0:
    print("Yes")

Measured memory_bytes: 55264
#include <stdio.h>
#include <stdlib.h>

#define MAX 100007

struct pair {
        long a;
        int b;
};

int compare(const void *x, const void *y) {
        long x_a = ((struct pair *) x)->a;
        long y_a = ((struct pair *) y)->a;
        return x_a - y_a;
}

int main() {
        int N, M;
        scanf("%d %d", &N, &M);

        struct pair AB[MAX];
        for (int i = 0; i < N; i++)
                scanf("%ld %d", &AB[i].a, &AB[i].b);
        qsort(AB, N, sizeof(struct pair), compare);

        struct pair ab = {0, 0};
        for (int i = 0; i < N; i++) {
                if (ab.b + AB[i].b <= M) {
                        ab.a += AB[i].a * AB[i].b;
                        ab.b += AB[i].b;
                } else {
                        ab.a += AB[i].a * (M - ab.b);
                        break;
                }
        }
        printf("%ld\n", ab.a);

        return 0;
}


Measured memory_bytes: 3324
s = input()
my, ym = 0<int(s[:2])<13, 0<int(s[2:])<13
if my and ym:
    o = "AMBIGUOUS"
elif my:
    o = "MMYY"
elif ym:
    o = "YYMM"
else:
    o = "NA"
print(o)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(ll i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<< endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N);
  VEC(int, v, N);
  map<int, int> even;
  map<int, int> odd;
  for (int i = 0; i < N; i += 2) {
    even[v[i]]++;
  }
  for (int i = 1; i < N; i += 2) {
    odd[v[i]]++;
  }
  vector<pii> ve;
  vector<pii> vo;
  each(x, even) {
    ve.push_back(pii(x.second, x.first));
  }
  each(x, odd) {
    vo.push_back(pii(x.second, x.first));
  }
  sort(all(ve), greater<>());
  sort(all(vo), greater<>());
  int ans = N;
  if (ve[0].second == vo[0].second) {
    if (N == 2) {
      ans = 1;
    } else {
      ans -= max(ve[0].first + vo[1].first, ve[1].first + vo[0].first);
    }
  } else {
    ans -= ve[0].first + vo[0].first;
  }
  print(ans);
}


Measured memory_bytes: 6524
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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;}

int main(){
	int n;
	cin >> n;
	vector<int> a(n+1); // 1-based
	REP(i,n) cin >> a[i+1];
	
	int count=0;
	vector<int> ans(n+1,0);
	for(int i=n; i>=1; i--){
		int sum=0;
		for(int j=2; i*j<=n; j++){
			sum = (sum+ans[i*j])%2;
		}
		
		if(sum!=a[i]){
			ans[i]=1;
			count++;
		}
	}
	
	cout << count << endl;
	REP(i,n){
		if(ans[i+1]==1){
			cout << i+1 << " ";
		}
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 4732
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
using lint=long long;
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  lint x,y;cin>>x>>y;
	if(abs(x-y)<=1){
        cout<<"Brown"<<endl;
    }
    else{
        cout<<"Alice"<<endl;
    }
  return 0;
}


Measured memory_bytes: 3636
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
product = 1
max = 10**18
if a.include?(0)
    puts "0"
    exit
end
for i in 0..(a.length - 1) do
    product = product *  a[i]
    if product >  max
        puts "-1"
        exit
    end
end
puts product


Measured memory_bytes: 23408
#include<iostream>

int n;
int a=0, b;
int c = 0;

int main() {
	std::cin >> n;
	for (int i = 0; i < n; i++)
	{
		std::cin >> b;
		if (a <= b) {
			a = b;
			c++;
		}
	}
	std::cout << c;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cctype>
using namespace std;
int main(){
    char a;
    while(1){
        scanf("%c",&a);
        if(isalpha(a)){
            if(islower(a))cout<<(char)toupper(a);
            else if(isupper(a))cout<<(char)tolower(a);
        }
        else {cout<<a;}
        if(a=='\n')break;
    }
return 0;
}

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

double EPS = 1e-9;
typedef complex<double> P,point;

struct C {P p; double r;C(const P &p, double r) : p(p), r(r) { } C(){} };

vector<P> C_cp(C a,C b){
	vector<P> ret;
	double L = abs(a.p-b.p);
 
	/* anma dekitenai */
	if(	L-a.r-b.r > EPS || (abs(a.p-b.p)<EPS && fabs(a.r-b.r)<EPS) || 
		abs(a.p-b.p) < abs(a.r-b.r)
	)return ret;
 
	double theta = atan2(b.p.imag()-a.p.imag(),b.p.real()-a.p.real());
	double c = (L*L+a.r*a.r-b.r*b.r)/(2*L*a.r);
	ret.push_back(
		P(a.p.real()+a.r*cos(theta+acos(c)),
		  a.p.imag()+a.r*sin(theta+acos(c)))
	);
	if(fabs(L-a.r-b.r) > EPS)
		ret.push_back(
			P(a.p.real()+a.r*cos(theta-acos(c)),
			  a.p.imag()+a.r*sin(theta-acos(c)))
		);
	return ret;
}
 
 
bool f(vector<C> b,double h){
	vector<P> cP;
	for(int i = 0 ; i < b.size() ; i++){
		cP.push_back(b[i].p);
	}
	for(int i = 0 ; i < b.size() ; i++){
		b[i].r = sqrt(b[i].r*b[i].r-h*h);
	}
	for(int i = 0 ; i < b.size() ; i++){
		for(int j = i+1 ; j < b.size() ; j++){
			auto tmp = C_cp(b[i],b[j]);
			cP.insert(cP.end(),tmp.begin(),tmp.end());
		}
	}
	for(int i = 0 ; i < cP.size() ; i++){
		bool intersectAll = true;
		for(int j = 0 ; j < b.size() ; j++){
			if( abs(b[j].p-cP[i]) > b[j].r + EPS){
				intersectAll = false;
			}
		}
		if(intersectAll) return true;
	}
	return false;
}
int main(){
	int n;
	while(cin >> n && n){
		vector<C> b(n);
		double l = 0, r = 1e9;
		for(int i = 0 ; i < n ; i++){
			double x,y,len;
			cin >> x >> y >> len;
			b[i].p = P(x,y);
			b[i].r = len;
			r = min(r,len);
		}
		
		for(int i = 0 ; i < 128 ; i++){
			double m = (l+r) / 2;
			if( f(b,m) ) l = m;
			else r = m;
		}
		printf("%.10lf\n",l);
	}
}

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

#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
const int N = 1005;

pair<int, int> loc[N][N];
int mu[N][N], day[N][N];
int n, played;
bool done[N][N];

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> n;
	
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n - 1; ++j) {
			int a; cin >> a;
			--a;
			mu[i][j] = a;
			loc[i][a] = {i, j};
		}
	}
	
	list<pair<int, int>> q;
	for (int i = 0; i < n; ++i) {
		day[i][0] = 1;
		q.push_back({i, 0});
	}
	
	int ans = 0;
	bool changed;
	do {
		changed = false;
		for (auto it = q.begin(); it != q.end();) {
			auto nxt = next(it, 1);
			pair<int, int> v = *it;
			int r = v.first, c = v.second;
			if (done[r][c]) {
				it = q.erase(it);
				continue;
			}
			int match = mu[r][c];
			pair<int, int> muloc = loc[match][r];
			if (day[muloc.first][muloc.second]) {
				changed = true;
				// cout << r << ' '  << c << '\n';
				done[r][c] = true;
				done[muloc.first][muloc.second] = true;
				++played;
				
				int md = max(day[muloc.first][muloc.second], day[r][c]);
				day[muloc.first][muloc.second] = day[r][c] = md;
				
				ans = max(ans, md);
				day[r][c + 1] = md + 1;
				day[muloc.first][muloc.second + 1] = md + 1;
				if (c + 1 < n - 1) q.push_back({r, c + 1});
				if (muloc.second + 1 < n - 1) q.push_back({muloc.first, muloc.second + 1});
				
				q.erase(it);
			}
			it = nxt;
		}
	} while (changed);
	
	if (played == n * (n - 1) / 2) cout << ans;
	else cout << -1;
}


Measured memory_bytes: 20376
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define m_p			make_pair
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define sz(x)       (int)x.size()
#define f			first
#define debug		cout<<"##########3"<<endl
#define mod			1000000007
#define ll			long long int
#define lMax		LLONG_MAXs
// queue<int> , prefix_sum(a,a+n) , reverse(a,a+n) , priority_queue <int> max heap , priority_queue <int, vector<int>, greater<int> > min heap;
// == precedence gretaer then &
ll n,m;
string s,s1;
priority_queue <long long int> pq;
ll mp[200005];
vector<ll> vec[300005];
vector<pair<int,int> > q;
int par[200005];
int vis[100005];
ll ans[200005];
ll arr[200005];

vector<pair<ll,pair<ll,ll>>> edges;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
	
    ll i,j,k,c=0,an=0,t,z=0,x=1,y,w=1;
    cin>>n;
    
    rep(i,0,n){
    	cin>>arr[i];
    	ans[n-i-1] = arr[i];
	}
  
  	vector<int> res;
  	res.pb(ans[0]);
  	for(i=1;i<n;i++)
  	{
  		auto it = upper_bound(res.begin(), res.end(), ans[i]);
		if(it==res.end()){
			res.pb(ans[i]);	
		}	
		else
		{
			*it = ans[i];//ok?
		}
	}
  	cout<<res.size();//len of long decrasing was
  
 	return 0;
}

Measured memory_bytes: 12412
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
const int MOD = 1000000007;


/*----------------------------------------------------------------*/
signed main(){
	
	int n;
	string s;
	cin >> n >> s;

	int r = n-1;
	int l = 0;
	int ans = 0;
	while(l<r){
		if(s[l] == 'W' && s[r] == 'R'){
			l++;
			r--;
			ans++;
			continue;
		}
		if(s[l] == 'R')l++;
		if(s[r] == 'W')r--;
	}
	cout << ans << endl;




	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_b
// rm -r -f test;oj dl https://atcoder.jp/contests/abc174/tasks/abc174_b

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

int main() {
  int n, ks;
  std::cin >> n >> ks;

  std::vector<std::pair<int64_t, int64_t>> xy(n);
  std::vector<int64_t> x, y;
  x.reserve(n);
  y.reserve(n);

  for (auto &i : xy) {
    std::cin >> i.first >> i.second;
    x.push_back(i.first);
    y.push_back(i.second);
  }

  std::map<std::pair<int64_t, int64_t>, int> c, c_x, c_y, c_xy;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      const auto x = xy[i].first;
      const auto y = xy[j].second;
      int co = 0, co_x = 0, co_y = 0, co_xy = 0;
      for (int k = 0; k < n; k++) {
        if (xy[k].first <= x && xy[k].second <= y) {
          co++;
        }
        if (xy[k].first < x && xy[k].second <= y) {
          co_x++;
        }
        if (xy[k].first <= x && xy[k].second < y) {
          co_y++;
        }
        if (xy[k].first < x && xy[k].second < y) {
          co_xy++;
        }
      }
      c[{x, y}] = co;
      c_x[{x, y}] = co_x;
      c_y[{x, y}] = co_y;
      c_xy[{x, y}] = co_xy;
    }
  }

  std::sort(x.begin(), x.end());
  std::sort(y.begin(), y.end());
  uint64_t w = static_cast<uint64_t>(x.back() - x.front())
    * static_cast<uint64_t>(y.back() - y.front());

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = i + 1; k < n; k++) {
        for (int l = j + 1; l < n; l++) {
          const auto x_min = x[i], x_max = x[k], y_min = y[j], y_max = y[l];
          const auto count = c[{x_max, y_max}] - c_x[{x_min, y_max}]
            - c_y[{x_max, y_min}] + c_xy[{x_min, y_min}];
          if (ks <= count) {
            const uint64_t x_len = x_max - x_min;
            const uint64_t y_len = y_max - y_min;
            w = std::min(w, x_len * y_len);
          }
        }
      }
    }
  }

  std::cout << w << std::endl;
  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  vll a(5);
  rep(i,5) cin>>a[i];
  rep(i,5){
    if(a[i]==0){
      COUT(i+1);
      return 0;
    }
  }
}


Measured memory_bytes: 3588
a,b,c,d = map(int, input().split())

# print(a,b,c,d)

rectangle_x = a * b
rectangle_y = c * d

if rectangle_x > rectangle_y:
    print(rectangle_x)
elif rectangle_x < rectangle_y:
    print(rectangle_y)
else:
    print(rectangle_x)

Measured memory_bytes: 9064
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int n,q,a[100010],x,ret;
int rui[100010], ev[100010], od[100010];
int aoki_hi;
int aoki_lo;

signed main(){
    I(n); I(q);
    REP(i,n) I(a[i]);
    rui[n-1] = a[n-1];
    REPN(i,n-1) rui[i] = rui[i+1] + a[i];
    ev[0] = a[0];
    ev[1] = a[1];
    for(int i = 2; i < n; i += 1){
        ev[i] = ev[i-2] + a[i];
    }
    REP(_,q){
        I(x);
        if (x <= a[0]){
            printf("%lld\n", rui[n-(n+1)/2]);
            continue;
        }
        int lo = 0;
        int hi = (n+1)/2;
        while(lo+1 < hi){
            int mid = (lo+hi)/2;
            aoki_hi = a[n-1-mid];
            aoki_lo = a[n-mid-mid-1];
            if (aoki_hi - x >= x - aoki_lo){
                lo = mid;
            } else {
                hi = mid;
            }
        }
        aoki_hi = a[n-1-lo];
        aoki_lo = a[n-lo-lo-1];
        cerr << "lo: " << lo << " " << aoki_lo <<" " << aoki_hi << endl;
        if (aoki_hi - x >= x - aoki_lo ){
            ret = rui[n-lo-1];
            if (n-3-lo-lo >= 0){
                ret += ev[n-3-lo-lo];
            }
        } else {
            ret = rui[n-lo] + ev[n-1-lo-lo];
        }
        printf("%lld\n", ret);
    }
}

Measured memory_bytes: 4096
n, k = map(int, input().split())
p = list(map(int, input().split()))
saidai = 0
wa =[None]*n
wa_2 = 0
gokei = 0
for i in range(n):
    gokei += p[i]
    wa[i] = gokei
saidai = wa[k-1]
for j in range(n-k):
    wa_2 = wa[j+k]-wa[j]
    if wa_2 > saidai:
        saidai = wa_2
kitai = (1/2)*(k+saidai)
print(str(kitai))

Measured memory_bytes: 24548
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 998244353;
int a[] = {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};
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	cout << a[n - 1] << endl;
}

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

int main() {
	int n;cin>>n;
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			if(i*j==n){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}


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

int main() {

  long long n, k;
  cin >> n >> k;
  vector<int> h(n);
  long long tmp = 0;
  long long lol = 0;
  long long ans = 0;

  for(int i = 0; i < n; i++) { 
    cin >> h.at(i);
    lol = lol + h.at(i);
  }

  if(k == 0) {
    cout << lol << endl;
    return 0;  
  } else if (k >= n) {
    cout << "0" << endl;
  } else {

    sort(h.begin(), h.end());
    reverse(h.begin(), h.end());
    
    for(int i = 0; i < k; i++) {
      h.at(i) = 0;
    }
    for(int i = 0; i < n; i++) {
      tmp = tmp + h.at(i);
    }
    cout << tmp << endl;
  }
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

string s1, s2, s3;

int n, ans;

int main(){
	cin >> n >> s1 >> s2;
	ans = n + n;
	for(int i=n-1;i>=0;--i){
		s3 = "";
		for(int j=0;j<i;++j){
			s3 += s1[j];
		}
		for(int j=0;j<n;++j){
			s3 += s2[j];
		}
		int cnt = 0;
		for(int j=0;j<n;++j){
			if(s1[j] == s3[j]){
				++cnt;
			}
			if(s3[s3.size()-1-j] == s2[n-1-j]){
				++cnt;
			}
		}
		if(cnt == n + n){
			ans = n + n - (n - i);
		}
	}

	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1000005;
struct Edge{int u,v;int w;
inline bool operator <(const Edge &b)const {return w<b.w;}
}e[N];
ll f[N],sum[N];
int fa[N];
int a[N],b[N];
int find(int x){return fa[x]=(fa[x]==x?x:find(fa[x]));}
int main()
{
	//freopen("input.txt","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m,tmp=0;
	cin >>n>>m;
	for(int i=1;i<=n;i++)cin >>a[i]>>b[i],fa[i]=i,sum[i]=b[i],f[i]=max(a[i],b[i]);
	for(int i=1;i<=m;i++)cin >>e[i].u>>e[i].v,e[i].w=max(max(a[e[i].u]-b[e[i].u],0),max(a[e[i].v]-b[e[i].v],0));
	sort(e+1,e+1+m);
	for(int i=1;i<=m;i++)if((e[i].u=find(e[i].u))!=(e[i].v=find(e[i].v)))
	{
		f[e[i].u]=min(max(f[e[i].u],(ll)e[i].w)+sum[e[i].v],max(f[e[i].v],(ll)e[i].w)+sum[e[i].u]);
		fa[e[i].v]=e[i].u;
		sum[e[i].u]+=sum[e[i].v];
	}
	cout <<f[find(1)]<<endl;
	//cout <<tmp<<n;
	return 0;
}

Measured memory_bytes: 13824
import java.util.Scanner;

public class Main
{

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

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());

		int l = 1;
		int r = n;

		for (int i = 1; i <= m; i++) {
			int tl = Integer.parseInt(sc.next());
			int tr = Integer.parseInt(sc.next());

			if (l < tl) l = tl;
			if (tr < r) r = tr;
		}

		if (r < l) {
			System.out.println(0);
		} else {
			System.out.println(r - l + 1);
		}

		sc.close();
	}
}

Measured memory_bytes: 47444
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N;
    cin >> N;

    vll A(N);
    rep(i, N) cin >> A[i];

    ll money = 1000;
    ll stock = 0;

    rep(i, N)
    {
        money += A[i] * stock;
        stock = 0;

        if (i < N - 1 && A[i] < A[i + 1])
        {
            stock += money / A[i];
            money %= A[i];
        }
    }

    cout << money << endl;

    return 0;
}

Measured memory_bytes: 3652
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int mod=1e9+7;

int power(int x,int y){int ret=1;do{if(y&1)ret=1ll*ret*x%mod;x=1ll*x*x%mod;}while(y>>=1);return ret;}
int n,k,f[4000111],invf[4000111];

int dp[2333][2333];
int c(int x,int y){if(x<y||y<0)return 0;return 1ll*f[x]*invf[y]%mod*invf[x-y]%mod;}
int main()
{
	f[0]=1;for(int i=1;i<4000111;i++)f[i]=1ll*f[i-1]*i%mod;
	invf[4000111-1]=power(f[4000111-1],mod-2);for(int i=4000111-2;i>=0;i--)invf[i]=1ll*invf[i+1]*(i+1)%mod;
	get2(n,k);
	if(k==1){puts("1");return 0;}
	dp[0][0]=f[n];
	for(int i=0;i<=n;i++)for(int j=i;j<=n;j++)//i:color 0 j:others
	{
		if(i)dp[i][j]=dp[i-1][j];
		if(j)dp[i][j]=(dp[i][j]+1ll*dp[i][j-1]*c(i+j*(k-1)-1,k-2))%mod;
	}
	printendl(dp[n][n]);
	return 0;
}

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

using namespace std;

int main()
{
	int N = 0;
	cin >> N;
	string S;
	cin >> S;

	if (N % 2 == 1)
		cout << "No" << endl;
	else
	{
		int lim = N / 2;
		bool flag = true;
		for (int i = 0; i < lim; ++i)
			if (S[i] != S[lim+i])
			{
				flag = false;
				break;
			}
		if (flag)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/ruby

def main(argv)
	n = STDIN.gets.chomp.to_i
	l = STDIN.gets.chomp.split(' ').map(&:to_i).sort
	
	s = 0
	n.times do |i|
		s += [l[2 * i], l[2 * i + 1]].min
	end
	STDOUT.puts s.to_s
end

if self.to_s == 'main' then
	main(ARGV)
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define MOD (long int)10e9 + 7

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i = 0; i < n; ++i){
        cin >> s[i];
    }

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

    vector<int> dp(n);

    dp[0] = 1;

    for(int i = 1; i < n; ++i){
        if(s[i-1] != s[i]){
            dp[i] = ++dp[i - 1];
        }else{
            dp[i] = dp[i - 1];
        }
    }

    cout << dp.back() << endl;

    return 0;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    ll n;
    cin >> n;
    string s;
    cin >> s;

    if (n >= 3200) cout << s << endl;
    else cout << "red" << endl;
}


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

int main()
{
    lld a, b, x, cnt = 0, start, last;
    cin >> a >> b >> x;

    start = a/x;
    last = b/x;

    cnt = last - start;
    if(a % x == 0)cnt++;

    cout << cnt;

    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
using ping = pair<ll, ll>;

int main(){
    ll N, M;
    cin >> N>>M;
    vector<ping> S(N);
    for (int i = 0; i < N; i++) cin >> S[i].first >> S[i].second;
    sort(S.begin(), S.end());

    ll price = 0, num = 0;
    for (int i = 0; i<N; i++){
      for (int j = 1; j <= S[i].second; j++){
        num++;
        if(num==M || j==S[i].second){
          price += S[i].first * j;
          break;
        }
      }
      if (num == M) break;
    }
    cout << price << endl;
    return 0;
}

Measured memory_bytes: 4844
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) {
        res.push_back(n / i);
      }
    }
  }
  return res;
}

ll N;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  vector<ll> ds = divisor(N);

  ll ans = 0;
  for (auto &e : ds) {
    if (e == 1 || e == 2) {
      continue;
    }

    ll d = N / e;
    if ((N - d) % d == 0) {
      ll a = (N - d) / d;
      if ((N / a) == (N % a)) {
        ans += a;
      }
    }
  }

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

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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> A(M+2);
  A.at(0) = -1;
  for(int i=1;i<=M;i++){
    cin >> A.at(i);
  }
  A.at(M+1) = N+1;
  vector<int> D(M+1);
  int dmax=0;
  long q = 1000000007;
  for(int i=0;i<=M;i++){
    D.at(i) = A.at(i+1)-A.at(i);
    //cout << D.at(i) << endl;
    dmax = max(dmax,D.at(i));
  }
  vector<long> F(dmax+1);
  for(int i=0;i<=dmax;i++){
    if(i<=1){
      F.at(i) = i;
    }else{
      F.at(i) = (F.at(i-1) + F.at(i-2))%q;
    }
  }
  long ans = 1;
  for(int i=0;i<=M;i++){
    //cout << ans << endl;
    ans = ans*F.at(D.at(i)-1)%q;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;
vector<ll> v[200005];
bool vi[200005];
ll cn;
void dfs(ll so)
{
	vi[so] = true;
	cn++;
	for(auto u: v[so])
	{
		if(!vi[u]) dfs(u);
	}
}
signed main()
{
    fast;
  
    ll n,m,i,j,ans=0;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
    	ll x,y;
    	cin>>x>>y;
    	v[x].pb(y);
    	v[y].pb(x);
    }
    for(i=1;i<=n;i++)
    {
    	cn=0;
    	if(!vi[i]) 
    	{
    		dfs(i);
    		ans = max(ans,cn);
    	}
    }
    cout<<ans;
    
    	
}

Measured memory_bytes: 20956
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

class Edge
{
public:
    int to, dist;
    Edge(int to, int dist){
        this->to = to;
        this->dist = dist;
    }
};

void solve(const vector<vector<Edge> >& edges, int curr, int prev, bool isBlack, vector<bool>& ans)
{
    ans[curr] = isBlack;
    for(const Edge& e : edges[curr]){
        if(e.to == prev)
            continue;
        bool isBlack2 = isBlack ^ (e.dist % 2 != 0);
        solve(edges, e.to, curr, isBlack2, ans);
    }
}

int main()
{
    int n;
    cin >> n;
    vector<vector<Edge> > edges(n);
    for(int i=0; i<n-1; ++i){
        int u, v, w;
        cin >> u >> v >> w;
        -- u;
        -- v;
        edges[u].push_back(Edge(v, w));
        edges[v].push_back(Edge(u, w));
    }

    vector<bool> ans(n);
    solve(edges, 0, -1, true, ans);

    for(int i=0; i<n; ++i)
        cout << (ans[i] ? 0 : 1) << endl;

    return 0;
}


Measured memory_bytes: 9472
#include<iostream>
using namespace std;
int main(){
  unsigned long N, K, Q, P[100000]={};
  cin >> N >> K >> Q;
  for(int i=0; i<Q; i++){
    int a;
    cin >> a;
    P[a-1]++;
  }
  for(int i=0; i<N; i++){
    if(Q-P[i]<K) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
} 

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

int main(){
  string S;
  int cctr=0;
  cin>>S;
  
  if( S.at(0)!='A'){cout<<"WA"<<endl;return 0;}
  if( isupper(S.at(1))){cout<<"WA"<<endl;return 0;}
  
  for(int k=2;k<S.size()-1;k++){
    if(S.at(k)!='C'&&isupper(S.at(k))){cout<<"WA"<<endl; return 0;}
    if(S.at(k)=='C')cctr++;
  	if(cctr>1){cout<<"WA"<<endl; return 0;}
  }

	if(isupper(S.at(S.size()-1))){cout<<"WA"<<endl; return 0;}
    if(cctr!=1){cout<<"WA"<<endl; return 0;}
    cout<<"AC"<<endl;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  bool allEven = true;
  REP(i,n){
    ll a;
    cin >> a;
    if(a%2==1) allEven = false;
  }
  if(allEven) cout << "second" << endl;
  else cout << "first" << endl;
  return 0;
}


Measured memory_bytes: 256
import com.sun.org.apache.xml.internal.utils.res.IntArrayWrapper;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        double[] values = new double[N];
        double[] highValues = new double[A];
        double max = 0;
        double combination = 0;
        HashMap<Double, Integer> map = new HashMap<>();

        for (int i = 0; i < N; i++) {
            values[i] = scanner.nextDouble();
            if (!map.containsKey(values[i])) {
                map.put(values[i], 1);
            } else {
                map.put(values[i], map.get(values[i])+1);
            }
        }

        Arrays.sort(values);
        highValues = Arrays.copyOfRange(values, N-A, N);

        for (int i = 0; i < A; i++ ) {
            max += highValues[i];
        }
        max = max/A;

        List<Double> list = new ArrayList<>();
        for (double i : highValues) list.add(i);
        Set<Double> set = new HashSet<Double>(list);
        Double[] highValuesSet = new Double[set.size()];
        set.toArray(highValuesSet);
        Arrays.sort(highValuesSet);


        if (set.size() == 1) {
            for (int i = A; i <= Math.min(map.get(highValuesSet[0]), B); i++) {
                combination += calcCombination(map.get(highValues[0]), i);
            }
        } else {
            int e = A;
            for (int i = 1; i < highValuesSet.length; i++) {
                e -= map.get(highValuesSet[i]);
            }
            combination = calcCombination(map.get(highValuesSet[0]), e);
        }
        System.out.println(String.format("%.6f", max));
        System.out.println(String.format("%.0f", combination));

    }

    private static double calcCombination( int n, int m ) {
        double c = 1;
        m = ( n - m < m ? n - m : m );
        for( int ns = n - m + 1, ms = 1; ms <= m; ns ++, ms ++ ) {
            c *= ns;
            c /= ms;
        }
        return c;
    }
}


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

int main() {
  int N,num=3;
  cin>>N;
  for(int i=0;i<N;i++){
    string s;
    cin>>s;
    if(s=="Y")
      num++;
	}
  if(num==3)
    cout<<"Three"<<endl;
  else
    cout<<"Four"<<endl;
}


Measured memory_bytes: 256