akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n; cin >> n;
    vector<int>v(n); erep(e,v) cin >> e;
    map<int,int>g,k,rg,rk;
    rep(i,v.size()){
        if(i%2)k[v[i]]++;
        else   g[v[i]]++;
    }
    vector<pii>gv,kv;
    for(auto itr : g) gv.push_back(pii(itr.second,itr.first));
    for(auto itr : k) kv.push_back(pii(itr.second,itr.first));
    gv.push_back(pii(0,0));
    kv.push_back(pii(0,0));
    sort(all(gv),greater<pii>());
    sort(all(kv),greater<pii>());
    if(gv[0].first > kv[0].first or( gv[0].first == kv[0].first and gv.size() > kv.size())){
        int key = gv[0].second;
        rep(i,kv.size()){
            if(kv[i].second != key){
                cout << n - gv[0].first - kv[i].first << endl;
                return 0;
            }
        }
    } else{
        int key = kv[0].second;
        rep(i,gv.size()){
            if(gv[i].second != key){
                cout << n - kv[0].first - gv[i].first << endl;
                return 0;
            }
        }
    }
}





Measured memory_bytes: 9592
import fractions
import traceback
n,x=map(int,input().split())
citys=list(map(int, input().split()))
mod_citys=citys
for i in range(len(mod_citys)):
    mod_citys[i]-=x
    if(mod_citys[i]<0):
        mod_citys[i] *= -1
if(len(mod_citys)==1):
    print(mod_citys[0])
elif(len(mod_citys)==2):
    print(fractions.gcd(mod_citys[0],mod_citys[1]))
else:
    mod_citys = sorted(mod_citys, reverse=False)
    spmin = 9999999999999
    pod = 0
    for i in range(len(mod_citys)):
        try:
            pod=fractions.gcd(mod_citys[i],mod_citys[i+1])
            if(pod<spmin):
                spmin=pod
        except:
            pass
    print(spmin)

Measured memory_bytes: 16408
#!/usr/bin/env -S JULIA_VERSION=0.5.0 julia
# contest: abc155, problem: abc155_a, alphabet: A
const YES = "Yes"
macro Y() :( println(YES); return ) end
const NO = "No"
macro N() :( println(NO); return ) end

function solve(A::Int, B::Int, C::Int)
  length(unique([A, B, C]))==2 && @Y
  @N
end

function main()
  tokens = Channel{String}(32)
  Task() do
    for line in eachline(@static VERSION < v"0.6" ? STDIN : stdin)
      startswith(line, '\0') && break
      for token in split(chomp(line))
        put!(tokens, token)
      end
    end
    close(tokens)
  end |> schedule
  A = parse(Int, take!(tokens))
  B = parse(Int, take!(tokens))
  C = parse(Int, take!(tokens))
  solve(A, B, C)
end

if isempty(get(ENV, "ATCODER_LOCAL", ""))
  isempty(ARGS) && main()
else
  @eval begin
    const samples = [("5 7 5", "Yes"), ("4 4 4", "No"), ("4 9 6", "No"), ("3 3 4", "Yes")]
    function test(sampleids...)
      isempty(sampleids) && return test(collect(1:length(samples))...)
      ostdin, ostdout = @static VERSION < v"0.6" ? (STDIN, STDOUT) : (stdin, stdout)
      rd, wr = first(redirect_stdout()), last(redirect_stdin())
      try
        map(sampleids) do sampleid
          input, output = samples[sampleid]
          print(ostdout, "Testing sample #$(sampleid)..."); flush(ostdout)
          println(wr, input)
          println(wr, "\0")
          t = @elapsed main()
          println()
          result = strip(String(readavailable(rd)))
          if result == output
            println(ostdout, "OK ($t sec).")
            true
          else
            println(ostdout, "ERROR ($t sec)")
            println(ostdout, "== expected ==\n$output")
            println(ostdout, "== actual ==\n$result\n")
            false
          end
        end |> all
      finally
        redirect_stdin(ostdin)
        redirect_stdout(ostdout)
      end
    end
    submit() = test() && (prog = @__FILE__; run(`atcoder-submit $prog`))
    !isinteractive() && submit()
  end
end


Measured memory_bytes: 171548
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 05/03/20 20:34:41
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  ll a[3]; cin>>a[0]>>a[1]>>a[2];
  map<char,int> id;
  id['A']=0;
  id['B']=1;
  id['C']=2;
  vector<string> qs(n);
  for (auto& s:qs) cin>>s;
  string ans;
  auto solve = [&]() {
    ll sum = a[0]+a[1]+a[2];
    int cz = (a[0]==0)+(a[1]==0)+(a[2]==0);
    if (cz == 3) {
      return;
    }
    if (sum >= 3) {
      for (auto& q:qs) {
        if (a[id[q[0]]]==0 and a[id[q[1]]]==0){
          ans.clear();
          return;
        }
        if (a[id[q[0]]] >= a[id[q[1]]]) {
          ans.push_back(q[1]);
          a[id[q[0]]]--;
          a[id[q[1]]]++;
        } else {
          ans.push_back(q[0]);
          a[id[q[0]]]++;
          a[id[q[1]]]--;
        }
      }
    } else {
      vector<bitset<31>> dp(n+1);
      auto key = [](int a,int b,int c) {
        return a*9+b*3+c;
      };
      dp[0][key(a[0],a[1],a[2])] = true;
      int i = 1;
      for (auto& q:qs) {
        for (int m=0; m<=30; m++) {
          if (!dp[i-1][m]) continue;
          int x[3];
          x[0] = m/9, x[1]=(m/3)%3, x[2]=m%3;
          x[id[q[0]]]++;
          x[id[q[1]]]--;
          if (x[id[q[1]]]>=0)
            dp[i][key(x[0],x[1],x[2])] = true;
          x[id[q[0]]]-=2;
          x[id[q[1]]]+=2;
          if (x[id[q[0]]]>=0)
            dp[i][key(x[0],x[1],x[2])] = true;
        }
        ++i;
      }
      int s = -1;
      for (int m = 0; m <= 30; m++) {
        if (dp[n][m]) {
          s = m;
          break;
        }
      }
      if (s == -1)
        return;
      for (int i = n; i > 0; i--) {
        int x[3];
        x[0] = s/9, x[1]=(s/3)%3, x[2]=s%3;
        x[id[qs[i-1][0]]]++;
        x[id[qs[i-1][1]]]--;
        if (x[id[qs[i-1][1]]]>=0 and dp[i-1][key(x[0],x[1],x[2])]) {
          s = key(x[0],x[1],x[2]);
          ans.push_back(qs[i-1][1]);
          continue;
        }
        x[id[qs[i-1][0]]]-=2;
        x[id[qs[i-1][1]]]+=2;
        if (x[id[qs[i-1][0]]]>=0 and dp[i-1][key(x[0],x[1],x[2])]) {
          s = key(x[0],x[1],x[2]);
          ans.push_back(qs[i-1][0]);
          continue;
        }
      }
      reverse(ans.begin(), ans.end());
    }
  };
  solve();
  if (ans.empty()) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for (auto a:ans)
      cout << a << endl;
  }

  return 0;
}


Measured memory_bytes: 7384
from collections import deque
n, m= map(int, input().split())
lis = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    lis[a].append(b)
    lis[b].append(a)

seen = [False] * n
ans = 1
for i in range(n):
    if seen[i] == False:
        queue = deque([i])
        seen[i] = True
        tmp =0
        while queue:
            now = queue.pop()
            tmp += 1
            for j in lis[now]:
                if seen[j] == True:
                    continue
                else:
                    seen[j] = True
                    queue.append(j)
        ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 107328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main(){
  string S; cin >> S;
  if (S.at(2) == S.at(3) && S.at(4) == S.at(5)){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define N 301
int num[4], n;
double p[N][N][N];
double P(int x, int y, int z) {
    if (p[x][y][z] >= 0) return p[x][y][z];
    double sum = (double)n / (x + y + z);
    if (x) sum += P(x - 1, y, z) * x / (x + y + z);
    if (y) sum += P(x + 1, y - 1, z) * y / (x + y + z);
    if (z) sum += P(x, y + 1, z - 1) * z / (x + y + z);
    return p[x][y][z] = sum;
}
int main() {
    scanf("%d", &n);
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
            for (int k = 0; k <= n; k++) p[i][j][k] = -1;
    p[0][0][0] = 0;
    for (int i = 1, x; i <= n; i++) {
        scanf("%d", &x);
        num[x]++;
    }
    printf("%.10lf\n", P(num[1], num[2], num[3]));
    return 0;
}

Measured memory_bytes: 213504
t, a, times = [ int(i) for i in input().split(" ")]
 
a_count = times - t
if t == 0 and a == 0:
  print(0, 0)
elif a_count <= 0:
  print(t-times, a)
else:
  if a_count > a:
    print(0, 0)
  else:
    print(0, a-a_count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
const int N=100005;
ll mod = 1e9+7;
vector<ll> v[2*N];
ll vis[2*N]={};
ll c=0;
void bfs(ll x)
{
	queue<ll>q;
    vis[x]=1;
    c++;
    q.push(x);
	while(!q.empty())
    {
		ll x=q.front();q.pop();
		for(int y:v[x])
        if(!vis[y])
        {
            vis[y]=vis[x]+1;
            q.push(y);
            c++;
        }
	}
}
void solve()
{
    ll n,m=0,k=0,i=1,j,p,f,x, y, z;
    ll ans=0,sum=0;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    for(i=1;i<=n;i++)
    {
        c=0;
        if(!vis[i]) bfs(i);
        ans=max(c, ans);
    }
    cout<<ans;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif 
    int t=1;
    //cin>>t;
    while(t--)solve();
    return 0;
}

Measured memory_bytes: 18744
import sys

def jisin(gen,mae,huka):
    hukasa[gen]=huka
    for c in tens[gen]:
        if(c!=mae):
            jisin(c,gen,huka+1)
    return

def kyokudai(gen,mae):
    dai=0
    if(len(tens[gen])==1 and mae!=-1):
        dai=hukasa[gen]
        #print(dai)
    else:
        for c in tens[gen]:
            if(c!=mae):
                dai=max(dai,kyokudai(c,gen))
    saisin[gen]=dai
    #print(gen,dai)
    return dai

def oikake(gen):
    miti.append(gen)
    if(hukasa[gen]==0):
        return
    for c in tens[gen]:
        if(hukasa[c]==hukasa[gen]-1):
            oikake(c)

sys.setrecursionlimit(10**6)
n,u,v=map(int,input().split())
u-=1
v-=1
tens=[[]for i in range(n)]
hukasa=[0]*n
saisin=[0]*n

for i in range(n-1):
    s,t=map(int,input().split())
    tens[s-1].append(t-1)
    tens[t-1].append(s-1)

#print(tens)

jisin(v,-1,0)
#print(hukasa)
kyokudai(v,-1)
#print(saisin)

miti=[]
oikake(u)
l=len(miti)-1
#print(miti)
#print(l)

ans=saisin[miti[l//2]]
print(ans-1)

Measured memory_bytes: 98608
#include <stdio.h>
int main(void)
{
  int N;
  char S[200], T[200];
  scanf("%d", &N);
  scanf("%s %s", &S[0], &T[0]);

  int i;
  for (i = 0; i < N; i++)
  {
    printf("%c%c", S[i], T[i]);
  }
  return 0;
}



Measured memory_bytes: 128
#include <stdio.h>

#define swap(a,b,tmp)  { tmp=a; a=b; b=tmp; }


int main(void)
{
	int a,b,c,d,temp;
	int overlap;

	// input and normalization
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if (c<a)
	{
		swap(a,c,temp);
		swap(b,d,temp);
	}

	overlap=b-c;
	if (overlap>0)
	{
		temp=d-c;
		if (temp<overlap)
		{
			overlap=temp;
		}
	}
	else
	{
		overlap=0;
	}

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



Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var (
		n, k int
		s    string
	)
	fmt.Scan(&n, &s, &k)

	wr := bufio.NewWriter(os.Stdout)
	for _, r := range s {
		if r != rune(s[k-1]) {
			wr.WriteString("*")
		} else {
			wr.WriteString(string(r))
		}
	}
	wr.WriteString("\n")
	wr.Flush()
}


Measured memory_bytes: 1652
def resolve():
    a, b = input().split()
    if (a, b) == ("H", "H") or (a, b) == ("D", "D"):
        print("H")
    elif (a, b) == ("H", "D") or (a, b) == ("D", "H"):
        print("D")


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 2940
from collections import deque
H, W = map(int, input().split())
C_1, C_2 = map(int, input().split())
D_1, D_2 = map(int, input().split())
T = []
for i in range(H):
    A = list(input())
    T.append(A)
used = [[0]*W for _ in range(H)]
P = deque([(C_1 - 1, C_2 - 1, 0)])
while(True):
    if len(P) == 0:
        print(-1)
        break
    a, b, cost = P.popleft()
    if (a, b) == (D_1 - 1, D_2 - 1):
        print(cost)
        break
    if used[a][b] == 0:
        used[a][b] = 1
        for i, j in ((0, 1), (0, -1), (1, 0), (-1, 0)):
            if 0 <= a + i <= H-1:
                if 0 <= b + j <= W-1:
                    if T[a+i][b+j] == ".":
                        P.appendleft((a + i, b + j, cost))
        for i in range(-2, 3):
            for j in range(-2, 3):
                if 0 <= a + i <= H-1:
                    if 0 <= b + j <= W-1:
                        if T[a+i][b+j] == ".":
                            P.append((a + i, b + j, cost + 1))

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

int main(){
  vector<int> v(4,0);
  for(int i = 0; i < 3; i++){
    int a,b; cin >> a >> b;
    v.at(a-1)++;
    v.at(b-1)++;
  }
  if(v.at(0) == 1 and v.at(3) == 1 and v.at(1) == 2 and v.at(2) == 2)
    cout << "YES";
  else
    cout << "NO";
}
  
      

Measured memory_bytes: 3612
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.T = function(T) local t={} for i=1,T do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
----
local function create_ndim_array(n, last_metatbl)
    local metatables = {}
    metatables[1] = last_metatbl
    for i=2,n do
        metatables[i] = {__index = function(parent, k)
            local child = setmetatable({}, metatables[i-1])
            rawset(parent, k, child)
            return child
        end}
    end
    return setmetatable({}, metatables[n])
end
-- E
local S = read.l():totable()
local T = {}
for i=1,#S do
    T[i] = tonumber(S[i])
end
local D = #T
local K = read.n()

local tbl = create_ndim_array(3, {__index = function() return 0 end})
tbl[0][true][0] = 1
for i=0,D-1 do
    for _, m in ipairs {false, true} do
        for k=0,K do
            if tbl[i][m][k] == 0 then
                goto continue_k
            end
            local ni = i+1
            local nd = T[ni]
            for d=0,9 do
                local nk = k
                local nm
                if m == false then
                    nm = false
                else
                    if d > nd then
                        break
                    elseif d == nd then
                        nm = true
                    else
                        nm = false
                    end
                end
                if d ~= 0 then
                    nk = nk + 1
                end
                if nk > K then
                    goto continue_d
                end
                tbl[ni][nm][nk] = tbl[ni][nm][nk] + tbl[i][m][k]
                ::continue_d::
            end
            ::continue_k::
        end
    end
end
local ans = tbl[D][false][K] + tbl[D][true][K]
print(ans)

Measured memory_bytes: 760
let check_trick array size =
  let rec loop i cnt =
    if i >= size
    then cnt
    else
      if array.(i) = false
      then loop (i+1) (cnt+1)
      else loop (i+1) cnt
  in loop 0 0

let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let snuke = Array.make n false in
  let multi_input () = Scanf.scanf "%d\n" @@ fun d ->
    for i=0 to d-1 do
      if i<d-1
      then Scanf.scanf " %d" @@ fun id -> snuke.(id-1) <- true
      else Scanf.scanf " %d\n" @@ fun id -> snuke.(id-1) <- true
    done in
  let solve () =
    for i=1 to k do
      multi_input ()
    done;
    check_trick snuke n
  in Printf.printf "%d\n" @@ solve ()

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

using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int x = 0;

  string s;
  cin >> s;
  for (char c : s) {
    if (c == '+') {
      x++;
    } else {
      x--;
    }
  }

  cout << x << endl;

  return 0;
}

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

int main()
{
    int i=0 ,j=0 ;
    int q=0 ;
    int a=0 ,b=0 ;
    char str[1001] = {0} ;
    char cmd[10] = {0} ;
    char p[1001] = {0} ;
    char mem[1001] = {0} ;
    char mem2[1001] = {0} ;

    scanf("%s" ,str) ;
    scanf("%d" ,&q) ;
    for (i=0 ;i < q ;i++)
    {
        memset(p ,0 ,sizeof p) ;
        memset(mem ,0 ,sizeof mem) ;
        memset(mem2 ,0 ,sizeof mem2) ;

        scanf("%s" ,cmd) ;
        scanf("%d %d" ,&a ,&b) ;

        if (strcmp(cmd ,"print") == 0)
        {
            for (j=a ;j <= b ;j++)
            {
                printf("%c" ,str[j]) ;
            }
            printf("\n") ;
        }
        else if (strcmp(cmd ,"reverse") == 0)
        {
            for (j=a ;j <= b ;j++)
            {
                mem[j-a]=str[j] ;
            }
            for (j=0 ;j <= b-a ;j++)
            {
                mem2[(b-a)-j]=mem[j] ;
            }
            for (j=a ;j <= b ;j++)
            {
                str[j]=mem2[j-a] ;
            }
        }
        else if (strcmp(cmd ,"replace") == 0)
        {
            scanf("%s" ,p) ;
            for (j=a ;j <= b ;j++)
            {
                str[j]=p[j-a] ;
            }
        }

    }

    return 0 ;
}

Measured memory_bytes: 576
import java.util.*;

public class Main {

	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int prev = 0;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if (a < prev) {
				System.out.println("No");
				return;
			} else if (a > prev) {
				prev = a - 1;
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 48220
#include <memory>
#include <utility>

using i64 = long long;

int rand() {
  static unsigned int seed = 91;
  seed *= 91;
  return int(seed);
}

struct treap {
  struct node;
  using pointer = std::unique_ptr<node>;
  struct node {
    int priority;
    i64 key, value;
    pointer left, right;

    node(i64 key) : priority(rand()), key(key), value(0), left(), right() {}
  };

  pointer merge(pointer left, pointer right) {
    if (!left) {
      return std::move(right);
    }
    if (!right) {
      return std::move(left);
    }
    if (left->priority > right->priority) {
      left->right = merge(std::move(left->right), std::move(right));
      return std::move(left);
    } else {
      right->left = merge(std::move(left), std::move(right->left));
      return std::move(right);
    }
  }

  using P = std::pair<pointer, pointer>;

  P split(pointer ptr, i64 key) {
    if (!ptr) {
      return {};
    }
    if (key <= ptr->key) {
      P temp = split(std::move(ptr->left), key);
      ptr->left = std::move(temp.second);
      return {std::move(temp.first), std::move(ptr)};
    } else {
      P temp = split(std::move(ptr->right), key);
      ptr->right = std::move(temp.first);
      return {std::move(ptr), std::move(temp.second)};
    }
  }

  pointer root;

  i64 &access(i64 key) {
    P lt = split(std::move(root), key);
    P rt = split(std::move(lt.second), key + 1);
    if (!rt.first) {
      rt.first = std::make_unique<node>(key);
    }
    i64 &ret = rt.first->value;
    lt.second = merge(std::move(rt.first), std::move(rt.second));
    root = merge(std::move(lt.first), std::move(lt.second));
    return ret;
  }
};

#include <iostream>

int main() {
  int n;
  std::cin >> n;
  treap t;
  i64 acc = 0;
  i64 ans = 0;
  ++t.access(0);

  for (int i = 0; i < n; ++i) {
    i64 a;
    std::cin >> a;
    ans += t.access(acc += a)++;
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<set>

using namespace std;

int main()
{
	int n;
	int i,j,k;
	int num[60000];
	int pri[100000];
	set<int> prime;
	
	pri[0]=2;
	
	for(i=0;i<60000;i++)
		num[i]=1;
	
	num[0]=0;
	num[1]=0;
	for(i=0;pri[i]<50022;)
	{
		for(j=1;pri[i]*j<50100;j++)
		{
			num[pri[i]*j]=0;
//			cout << "*" << pri[i]*j << endl;
		}
		for(k=0;;k++)
		{
			if(num[k]==1)
			{
//				cout << "pri:" << pri[i] << endl;;
				i++;
				pri[i]=k;
//				cout << k <<endl;
				break;
			}
		}
	}
	
	
	for(j=0;j<i;j++)
		prime.insert(pri[j]);
		
	set<int>::iterator it=prime.begin();
	for(;it!=prime.end();)
	{
//		cout << "it: " << *it << endl;
		it++;
	}
	for(;cin >> n;)
	{
	
		it=prime.lower_bound(n);
		if(*it==n)
		{
			cout << *(--it) << " " ;
			++it;
			cout << *(++it) << endl;
		}
		else
		{
			cout << *(--it) << " ";
			++it;
			cout << *(it) << endl;
		}
	}
}

Measured memory_bytes: 1008
#include <iostream>
#include <stdio.h>

int main() {
    
    while (true) {
        int m = 0, f = 0, r = 0;
        const char *ch[512];
        int sum = 0;
        scanf("%d%d%d", &m, &f, &r);
        sum = m + f;
        
        if (m == -1 && f == -1 && r == -1) break;
        
        if (sum >= 80) *ch = "A";
        if (sum >= 65 && sum < 80) *ch = "B";
        if (sum >= 50 && sum < 65) *ch = "C";
        if (sum >= 30 && sum < 50) {
            *ch = "D";
            if (r >= 50) {
                *ch = "C";
            }
        }
        if (sum < 30) *ch = "F";
        if (m == -1 || f == -1) *ch = "F";

        printf("%s\n", *ch);
    }
}

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

#define ll long long

int const V = 1e5 + 1;

int main()
{
    int n, w;
    cin >> n >> w;
    
    ++w;
    
    int arr[n][2];
    for (int i = 0; i < n; ++i)
        cin >> arr[i][0] >> arr[i][1];
        
    ll dp[n][V] = {};
    bool vis[n][V] = {};
    
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < V; ++j)
            dp[i][j] = INT_MAX;
    
    dp[0][0] = 0, vis[0][0] = 1;
    dp[0][arr[0][1]] = arr[0][0], vis[0][arr[0][1]] = 1;
    
    for (int i = 1; i < n; ++i)
    {
        for (int j = 0; j < V; ++j)
        {
            if (vis[i - 1][j])
            {
                dp[i][j] = min(dp[i][j], dp[i - 1][j]);
                vis[i][j] = 1;
                
                dp[i][j + arr[i][1]] = min(dp[i][j + arr[i][1]], dp[i - 1][j] + arr[i][0]);
                vis[i][j + arr[i][1]] = 1;
            }
        }
    }
    
    ll ans = 0;
    
    for (ll i = 0; i < V; ++i)
        if (vis[n - 1][i] && dp[n - 1][i] < w)
            ans = max(ans, i);
    
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 88192
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<complex>

#define INF (long long)1000000000
#define MOD 1000000007
#define EPS 1e-8

#define REP(i, m) for(long long i = 0; i < m; ++i)
#define FOR(i, n, m) for(long long i = n; i < m; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

enum FACE{TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT};
class Dice {
public:
	Dice() {
		id[TOP] = 0; id[BOTTOM] = 1; id[FRONT] = 2;
		id[BACK] = 3; id[LEFT] = 4; id[RIGHT] = 5;
	}
	Dice(int top,int bottom, int front, int back, int left, int right) {
		id[TOP] = top; id[BOTTOM] = bottom; id[FRONT] = front;
		id[BACK] = back; id[LEFT] = left; id[RIGHT] = right;
	}
	int& operator[] (FACE f) { return id[f]; }
	void rotX(int c) {
		for(int i = 0; i < c; ++i) {
			int top = id[BACK], front = id[TOP], bottom = id[FRONT], back = id[BOTTOM];
			id[TOP] = top; id[FRONT] = front;
			id[BOTTOM] = bottom; id[BACK] = back;
		}
	}
	void rotY(int c) {
		for(int i = 0; i < c; ++i) {
			int top = id[LEFT], right = id[TOP], bottom = id[RIGHT], left = id[BOTTOM];
			id[TOP] = top; id[RIGHT] = right;
			id[BOTTOM] = bottom; id[LEFT] = left;
		}
	}
	void rotZ(int c) {
		for(int i = 0; i < c; ++i) {
			int front = id[RIGHT], left = id[FRONT], back = id[LEFT], right = id[BACK];
			id[FRONT] = front; id[LEFT] = left;
			id[BACK] = back; id[RIGHT] = right;
		}
	}
	vector<vector<int> > all() {
		vector<vector<int> > vs;
		for(int i = 0; i < 4; ++i) {
			for(int j = 0; j < 4; ++j) {
				vector<int> v(6);
				v[TOP] = id[TOP]; v[BOTTOM] = id[BOTTOM];
				v[FRONT] = id[FRONT]; v[BACK] = id[BACK];
				v[RIGHT] = id[RIGHT]; v[LEFT] = id[LEFT];
				vs.pb(v);
				rotZ(1);
			}
			rotX(1);
		}
		for(int i = 0; i < 4; ++i) {
			for(int j = 0; j < 4; ++j) {
				vector<int> v(6);
				v[TOP] = id[TOP]; v[BOTTOM] = id[BOTTOM];
				v[FRONT] = id[FRONT]; v[BACK] = id[BACK];
				v[RIGHT] = id[RIGHT]; v[LEFT] = id[LEFT];
				vs.pb(v);
				rotZ(1);
			}
			rotY(1);
		}
		return vs;
	}
private:
	int id[6];
};

int main() {
	Dice d;
	int top,right,front,back,left,bottom;
	cin>>top>>right>>front>>back>>left>>bottom;
	d[TOP]=top;
	d[RIGHT]=right;
	d[FRONT]=front;
	d[BACK]=back;
	d[LEFT]=left;
	d[BOTTOM]=bottom;
	int q;
	cin>>q;
	vector<vector<int> > a = d.all();
	REP(i,q) {
		int t,r;
		cin>>t>>r;
		int f = -1;
		REP(j,a.size()) {
			if(a[j][TOP]==t&&a[j][RIGHT]==r) f = a[j][FRONT];
		}
		cout<<f<<endl;
	}
}

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

int rec(vector<int> &n, int k)
{
    if(n.size() < k) return 0;
    if(n[0] == 0){
        vector<int> m(n.size()-1);
        copy(n.begin()+1, n.end(), m.begin());
        return rec(m, k);
    }else if(n[0] == -1){
        if(n.size()-1 <k) return 0;
        int c1 = 1, c2 = 1;;
        for (int i = 0; i < k; i++)
        {
            c1 *= n.size()-1-i;
            c1 *= 9;
            c2 *= i+1;
        }
        return c1/c2;
    }

    int ans = 0;
    if(k == 1){
        ans = n[0] + (n.size()-1)*9;
    }else{
        vector<int> m(n);
        m[0] = -1;
        ans += rec(m, k);
        ans += (n[0]-1) * rec(m, k-1);
        m[0] = 0;
        ans += rec(m, k-1);
    }

    return ans;
}

void Main()
{
    string s;
    int k;
    cin >> s >> k;
    vector<int> n(s.size());
    for (int i = 0; i < s.size(); i++)
    {
        n[i] = s[i] - '0';
    }
    int ans = rec(n, k);
    
    cout << ans << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1000000001
#define mod 1000000007

ll N,T;
vector<P> ps;
ll dp[200010][31];

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

  cin>>N>>T;
  rep(i,N){
  	ll a,b;
  	cin>>a>>b;
  	ps.push_back(P(a+1,a+b+1));
  }
  sort(all(ps),[](const P& a,const P& b){
  	if(a.fi==1&&b.fi==1) return a.se < b.se;
  	else return b.fi*a.se+b.se < a.fi*b.se+a.se;
  });

  ll M=N;
  rep(i,N){
  	if(ps[i].fi==1){
  		M=i;
  		break;
  	}
  }
  const ll K=30;
  rep(i,M+1)rep(j,K+1)dp[i][j]=INF;
  dp[0][0]=0;
  rep(i,M)rep(j,K+1){
  	if(dp[i][j]==INF)continue;
  	minch(dp[i+1][j],dp[i][j]);
  	if(j+1<=K)minch(dp[i+1][j+1],ps[i].fi*dp[i][j]+ps[i].se);
  }

  ll res=0;
  rep(j,K+1){
  	if(dp[M][j]>T)continue;
  	ll crtt=dp[M][j];
  	ll crtcnt=j;
  	repl(i,M,N){
  		if(crtt+ps[i].se<=T){
  			crtt+=ps[i].se;
  			crtcnt++;
  		}else{
  			break;
  		}
  	}
  	maxch(res,crtcnt);
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 52844
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int N=405;
const int mod=998244353;
int n,a[N],b[N],jc[N],inv[N],sum[N],f[N][N][N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
int kuai(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=res*a%mod;
		a=a*a%mod;
		b=b/2;
	}
	return res;
}
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read(),b[i]=read();
	jc[0]=jc[1]=inv[0]=inv[1]=1;
	for(int i=2;i<=400;i++)jc[i]=jc[i-1]*i%mod;
	inv[400]=kuai(jc[400],mod-2);
	for(int i=400-1;i>1;i--)inv[i]=inv[i+1]*(i+1)%mod;
	int s1=0,s2=0;
	f[0][0][0]=mod-1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=s1;j++)
			for(int k=0;k<=s2;k++)
				f[i][j][k]=f[i-1][j][k];
		sum[0]=1;
		for(int j=1;j<b[i];j++)sum[j]=sum[j-1]*a[i]%mod;
		for(int j=0;j<b[i];j++)sum[j]=sum[j]*inv[j]%mod;
		for(int j=0;j<=s1;j++)
			for(int k=0;k<=s2;k++)
				for(int p=0;p<b[i];p++)
		f[i][j+p][k+a[i]]=(f[i][j+p][k+a[i]]-f[i-1][j][k]*sum[p]%mod+mod)%mod;
		s1+=b[i]-1;s2+=a[i];
	}
	int ans=0;
	for(int i=0;i<=s1;i++)
		for(int j=1;j<=s2;j++)
		{
			int x=f[n][i][j]*jc[i]%mod;
			x=x*kuai(j,mod-i-1)%mod;
			ans=(ans+x*s2%mod*kuai(j,mod-2)%mod)%mod;
		}
	cout<<ans;
}

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

int charToIdx(const char &c)
{
	switch(c)
	{
	case 'S':
		return 0;
	case 'H':
		return 1;
	case 'C':
		return 2;
	case 'D':
		return 3;
	}
}

int main()
{
	const int CARD_NUM = 14;
	int n = 0;
	cin >> n;

	bool check[4][14] = {false};
	char c = 0;
	int num = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> c >> num;
		check[charToIdx(c)][num] = true;
	}
	char str[] = {'S', 'H', 'C', 'D'};
	for(int i = 0; i < 4; i++)
	{
		for(int j = 1; j < 14; j++)
		{
			if(!check[i][j])
			{ 
				cout << str[i] << " " << j << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3036
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define min(a,b) (((a)>(b))?(b):(a))
#define max(a,b) (((a)>(b))?(a):(b))
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int main(){
	int n;
	cin>>n;
	string w[n];
	for(int i=0;i<n;i++){
		cin>>w[i];
		for(int j=0;j<i;j++){
			if(w[i]==w[j]){
				cout<<"No";
				return 0;
			}
		}
		if(i!=0){
			if(w[i-1][w[i-1].length()-1]!=w[i][0]){
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";
	return 0;
	

}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", v)
#define PRIY PRI("Yes")
#define PRIN PRI("No")
#define MINS(a,b) a = min(a,(decltype(a))(b))
#define MAXS(a,b) a = max(a,(decltype(a))(b))


int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans = -1e18;
	MAXS(ans, a * c);
	MAXS(ans, a * d);
	MAXS(ans, b * c);
	MAXS(ans, b * d);
	PRI(ans);
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

bool check(int x) {
  if (x % 2 == 0) {
    return true;
  } else {
    return false;
  }
}

int main() {
  int h, w; cin >> h >> w;
  int v[h][w];

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> v[i][j];
    }
  }

  int rescnt = 0;
  vector<pair<int, int>> vpin(250000);
  vector<pair<int, int>> vpout(250000);

  //縦判定
  for (int i = 0; i < h - 1; ++i) {
    for (int j = 0; j < w; ++j) {
      if (check(v[i][j])) {
        continue;
      } else {
        vpin[rescnt] = make_pair(i + 1, j + 1);
        vpout[rescnt] = make_pair(i + 2, j + 1);
        rescnt++;
        v[i][j]--;
        v[i + 1][j]++;
      }
    }
  }

  //横判定
  for (int j = 0; j < w - 1; ++j) {
    if (check(v[h - 1][j])) {
      continue;
    } else {
      vpin[rescnt] = make_pair(h, j + 1);
      vpout[rescnt] = make_pair(h, j + 2);
      rescnt++;
      v[h - 1][j]--;
      v[h - 1][j + 1]++;
    }
  }
  cout << rescnt << endl;
  for (int i = 0; i < rescnt; ++i) {
    cout << vpin[i].first << " " << vpin[i].second << " " << vpout[i].first << " "
    << vpout[i].second << endl;
  }

}

Measured memory_bytes: 7040
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

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

int main()
{
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> x_pos, y_pos;
    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        x_pos.push_back(tmp);
    }
    for (int i = 0; i < M; i++)
    {
        int tmp;
        cin >> tmp;
        y_pos.push_back(tmp);
    }

    sort(x_pos.begin(), x_pos.end());
    sort(y_pos.begin(), y_pos.end());

    if (x_pos[x_pos.size() - 1] < y_pos[0] && x_pos[x_pos.size() - 1] < Y && X < y_pos[0])
    {
        cout << "No War" << endl;
    }
    else
    {
        cout << "War" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    string s;
    cin>>s;
    ll k;cin>>k;
    ll c=0;
    bool f=(s[0]==s[s.size()-1]);
    rep(i,s.size()-1){
        if(s[i]==s[i+1]){
            if(i==s.size()-2)f=0;
            c++;
            i++;
        }
    }
    bool f2=(s[0]==s[s.size()-1]);
    ll c2=0;
    ll ans=0;
    REP(i,1,s.size()-1){
        if(s[i]==s[i+1]){
            if(i==s.size()-2)f2=0;
            c2++;
            i++;
        }
    }
    ans+=0;
    if(s.size()==1){
        cout<<k/2<<endl;;
    }
    else{
    if(f){
        if(f2){
            ans+=(k-1)*(c2+1)+c;
        }else{
            ans+=k/2*c+k/2*(c2+1)+k%2*c;
        }
    }else{
        ans+=k*c;
    }
    cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,m;
int main(){
  cin >>n>>m;
  ll a[m];
  for(ll i=0;i<m;i++) cin >>a[i];
  ll t=1,n1=1,n2=1,k=0;
  if(a[0]==1){
    k++;
    t=0;
    n2=0;
  }
  for(ll i=1;i<n;i++){
      t=(n1+n2)%1000000007;
      if(k<=m-1&&i==a[k]-1) {
        k++;
        t=0;
      }
      n1=n2%1000000007;
      n2=t%1000000007;
  }
  cout <<t<<endl;
  }


Measured memory_bytes: 1024
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

fn main() {
    const U_INF: usize = 1 << 60;
    const I_INF: isize = 1 << 60;
    const MOD: usize = 1000000007;

    let h: usize = read!();
    let w: usize = read!();
    let mut map = vec![vec![false; w + 10]; h + 10];
    for i in 0..h {
        let str: String = read!();
        for (j, c) in str.chars().enumerate() {
            if c == '#' {
                map[i][j] = true;
            }
        }
    }


    let mut dp = vec![vec![0; w + 10]; h + 10];
    dp[0][0] = 1;
    for i in 0..h {
        for j in 0..w {
            if !map[i][j + 1] {
                dp[i][j + 1] += dp[i][j];
                dp[i][j + 1] %= MOD;
            }
            if !map[i + 1][j] {
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][j] %= MOD;
            }
        }
    }

    println!("{}", dp[h-1][w-1]);
}

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

int main(){
	int n,k;
	cin >> n >> k;
	vector<int> s(n,0);
	rep(i,k){
		int d;
		cin >> d;
		rep(j,d){
			int a;
			cin >> a;
			a--;
			s[a]++;
		}
	}
	int ans = 0;
	rep(i,n){
		if(s[i] == 0) ans++;
	}
	cout << ans << endl;
    return 0;
}



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

using namespace std;

int main() {
  
  vector<int> back[20];
  int front[20] = {};
  int m, n;
  
  cin >> m;
  cin >> n;
    
  for(int i=0; i<n; i++) {
    int x, y;
    cin >> x >> y; x--, y--;
    back[x].push_back(y);
    front[y] ++;
  }
  
  for(int i=0; i<m; i++) {
    for(int j=0; j<m; j++) {
      if(!front[j]) {
	cout << j+1 << endl;
	for(int k=0; k<back[j].size(); k++) {
	  front[back[j][k]] --;
	}
	front[j] = -1;
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 1216
#pragma warning(disable:4996)
//#define _CRT_NONSTDC_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <math.h>
#include <bitset>
#include <fstream>
#include <numeric>
#include <sstream>
#include <algorithm>
#include <string>
#include <cstring>
#include <iomanip>
#include <unordered_map>
#include <ctime>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
 
 
using namespace std;
typedef long long ll;
typedef long double ld;
                        
#define all(x)   (x).begin(), (x).end()           /*sorting STL */
#define fastio	 ios_base::sync_with_stdio(0);  cin.tie(nullptr);  cout.tie(nullptr)
 
#define TRIPmin(a, b, c) 	min(a, min(b, c))
#define TRIPmax(a, b, c)    max(a, max(b, c))
#define fillchar(a,x) 		memset(a, x, sizeof (a))
 
//#define mod		(1000000000+7)
 
/***********************************************************************/
 
const ll maxn = 2*1e6;
int main() {
    ll n, demw = 0, ans = 0;
    char c[maxn];
    cin >> n;
    for(ll i = 1; i <= n; i++) {
        cin >> c[i];
        if(c[i] == 'W') demw++;
    }
    if(demw == n || demw == 0) {
        cout << 0;
        return 0;
    }
    ll j = n;
    for(ll i = 1; i <= n-demw; i++) {
        if(c[i] == 'W') {
            while(j > n-demw) {
                if(c[j] == 'R') {
                    swap(c[i], c[j]);
                    break;
                }
                j--;
            }
            ans++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3796
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long w = Long.parseLong(sc.next());
        long h = Long.parseLong(sc.next());
        long x = Long.parseLong(sc.next());
        long y = Long.parseLong(sc.next());
        int isMulti = ((w / 2.0) == x && (h / 2.0) == y) ? 1 : 0;
        System.out.println((w * h / 2.0) + " " + isMulti);
    }
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

#include <bits/stdc++.h>
using namespace std;

template<typename T>
void cmpmax(T* reference, T value) {
	*reference = max(*reference, value);
}

template<typename T>
void cmpmin(T* reference, T value) {
	*reference = min(*reference, value);
}

const ll mod = 1000000007;

static const ll INF = 1e15;

int main() {
	ll n;
	cin >> n;
	vector<ll> as(n);
	rep(i, n) cin >> as[i];
	ll m = 1;
	const ll up = 1e18;
	rep(i, n) {
		if (as[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	rep(i, n) {
		if (up / m < as[i]) {
			cout << -1 << endl;
			return 0;
		}
		m *= as[i];
	}
	cout << m << endl;
	return 0;
}
	


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

int n;
vector<int> G[202];

int color[202];
bool dfs(int v,int c){
	//cout << v << " " << color[v] << " " << c << endl;
	if(color[v] == c)return true;
	if(color[v] != 0)return false;
	color[v] = c;
	bool ret = true;
	for(int i = 0 ; i < G[v].size() ; i ++){
		ret &= dfs(G[v][i],-c);
		if(!ret)break;
	}
	return ret;
}

int main(){
	scanf("%d",&n);
	for(int i = 0 ; i < n ; i ++){
		scanf("\n");
		for(int j = 0 ; j < n ; j ++){
			char c;
			scanf("%c",&c);
			if(c == '1')G[i].push_back(j);
			//cout << i << " " << j << " " << c << endl;
		}
		//cout << endl;
	}
	
	int dist[202][202] = {};
	for(int i = 0 ; i < 202 ; i ++){
		for(int j = 0 ; j < 202 ; j ++){
			dist[i][j] = 10000;
		}
		dist[i][i] = 0;
	}
	for(int i = 0 ; i < n ; i ++){
		for(int j = 0 ; j < G[i].size() ; j ++){
			dist[i][G[i][j]] = 1;
		}
	}
	
	for(int k = 0 ; k < n ; k ++){
		for(int i = 0 ; i < n ; i ++){
			for(int j = 0 ; j < n ; j ++){
				dist[i][j] = min( dist[i][j] , dist[i][k]+dist[k][j] );
			}
		}
	}
	
	int ret = 0;
	for(int i = 0 ; i < n ; i ++){
		for(int j = 0 ; j < n ; j ++){
			ret = max( ret , dist[i][j] );
		}
	}
	if(dfs(0,1))cout << ret+1 << endl;
	else cout << -1 << endl;
}
	

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){ 
    string s; cin >> s;
    vector<int> a(4);
    rep(i, 4){
        a[i] = s[i] - '0';
        //cout << a[i] << endl;
    }

    for(int bit = 0; bit < (1 << 4); bit++){
        int sum = 0;
        for(int i = 1; i < 4; i++){
            if(bit & 1 << i){
                sum += a[i];
            }else{
                sum -= a[i];
            }
        }
        if(sum + a[0] == 7){
            cout << a[0];
            for(int i = 1; i < 4; i++){
                if(bit & 1 << i){
                    cout << '+';
                }else{
                    cout << '-';
                }
                cout << a[i];
            }
            cout << "=7" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	vector<int> a(3);
	rep(i, 3) cin >> a[i];
	sort(rall(a));
	cout << a[0] * 10 + a[1] + a[2] << endl;
}

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

	solve();
}


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

#define INF 1145141919

int N, M;
int W;
int T[160][1010];
int dp[160][1010][80];

int main() {
  while (cin >> N >> M) {
    if (N == 0 && M == 0) break;
    for (int i=0; i<160; i++) {
      for (int j=0; j<1010; j++) {
        T[i][j] = -1;
      }
    }
    W = 0;
    for (int i=0; i<N; i++) {
      int k;
      cin >> k;
      for (int j=0; j<k; j++) {
        int x, d;
        cin >> x >> d;
        T[i][x-1] = d;
        W = max(W, x);
      }
    }

    for (int i=0; i<160; i++) {
      for (int j=0; j<1010; j++) {
        for (int m=0; m<80; m++) {
          dp[i][j][m] = INF;
        }
      }
    }
    for (int i=0; i<W; i++) {
      if (T[0][i] > 0) dp[0][i][0] = 0;
      if (T[1][i] > 0) dp[1][i][1] = 0;
    }
    for (int i=0; i<N; i++) {
      for (int j=0; j<W; j++) {
        for (int m=0; m<=M; m++) {
          if (dp[i][j][m] == INF) continue;
          for (int nj=0; nj<W; nj++) {
            if (T[i+1][nj] > 0) {
              dp[i+1][nj][m] = min(dp[i+1][nj][m], dp[i][j][m] + abs(j - nj)*(T[i+1][nj] + T[i][j]));
            }
            if (T[i+2][nj] > 0) {
              dp[i+2][nj][m+1] = min(dp[i+2][nj][m+1], dp[i][j][m] + abs(j - nj)*(T[i+2][nj] + T[i][j]));
            }
          }
        }
      }
    }
    int ans = INF;
    for (int i=0; i<W; i++) {
      for (int m=0; m<=M; m++) {
        if (m < M) ans = min(ans, dp[N-2][i][m]);
        ans = min(ans, dp[N-1][i][m]);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}

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

int N,M;

int solve(vector<int> b, vector<int> goal){
    int cnt=0;
    rep(l,N)if(b[l]!=goal[l]){
        int r=l;
        do{
            if(r==N-1)return 1000;
            r++;
        }while(b[l]==b[r]);

        while(l<r){
            swap(b[r],b[r-1]);
            r--;
            cnt++;
        }
    }
    return cnt;
}

int main(void){
    cin>>N>>M;
    vector<int> b(N),goal1(N),goal2(N);
    rep(i,N) cin>>b[i];
    int index=0;
    rep(i,M) {
        int p;
        cin>>p;
        rep(j,p){
            goal1[index] = (i%2==0);
            goal2[index] = (i%2!=0);
            index++;
        }
    }
    cout<<min(solve(b,goal1),solve(b,goal2))<<endl;
    return 0;
}

Measured memory_bytes: 3148