akhauriyash/Code-Regression huggingface dataset:
#! /usr/bin/env python3

# from fractions import gcd
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)

N, X = [int(_) for _ in input().split()]
x = [int(_) for _ in input().split()]

if N != 1:
    ret = []
    x.append(X)
    now = x[0]

    for i in x[1:]:
        ret += [i - now]
        now = i

    ret = sorted(ret)

    print(gcd_list(ret))

else:
    print(abs(x[0] - X))

Measured memory_bytes: 20680
object Main {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val n, k = sc.nextInt
    val ls = List.fill(n)(sc.nextInt)

    val snake = ls.sorted.splitAt(ls.length - k)

    println(snake._2.sum)
  }
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    string str[n]; bool isFalse = false;
    for (int i = 0; i < n; i++)
        cin >> str[i];
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (str[i] == str[j])
                isFalse = true;
            if (isFalse == true)
                    break;
        }
        if (isFalse == true)
        {
            cout << "No" << endl;
            return 0;
        }
    }

    for (int i = 0, j = 1; j < n; i++, j++)
    {
        if (str[i].at(str[i].size() - 1) != str[j].at(0))
            isFalse = true;
        if (isFalse == true)
                break;
    }
    if (isFalse == true)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 1000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define eps 0.000001
//#define endl '\n'

using namespace std ;

#define MAXN 100010
/*lli spf[MAXN];  
void sieve();
set<lli> factors(lli x);
lli power(lli x,lli y,lli p);
*/
//void getZarr(string str, lli Z[]);
//vll prefix_function(vll s); 

typedef tree<lli,null_type,less<lli>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

int main()
{

    lli n,m;
    cin>>n;
    lli a[n];

    loopl(i,0,n) cin>>a[i];

    lli g=a[0];

    loopl(i,1,n) g = __gcd(g,a[i]);

    cout<<g<<endl;

}


/*vll prefix_function(vll s) 
{
    lli n = (lli)s.size();
    vll pi(n);
    
    for (lli i = 1; i < n; i++)
    {
        lli j = pi[i-1];
        
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        
        if (s[i] == s[j])
            j++;
        
        pi[i] = j;
    }
    return pi;
}
*/
/*void sieve() 
{ 
    spf[1] = 1; 
    loopl(i,2,MAXN) 
        spf[i] = i; 
    for (lli i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (lli i=3; i*i<MAXN; i++) { 
        if (spf[i] == i) { 
            for (lli j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    }

} 

multiset<lli> factors(lli x) 
{ 
    multiset<lli> pr; 
    while (x != 1) 
    { 
        pr.insert(spf[x]); 
        x = x / spf[x]; 
    } 
    return pr; 
}

*/

/*
void dfs(lli q,lli root) 
{
    vis[q]=1;
    
    ans[q]=1;

    for(auto x: v[q])
    {
        if(!vis[x])
        {
            if(a[x]==a[root] && x<root) continue;
            if(a[x]<a[root] || a[x]>a[root]+d) continue;
            dfs(x,root);
            ans[q]=(ans[q]*((ans[x]+1)%mod))%mod ;
        }
    }
        
}
*/



/*void getZarr(string str, lli Z[])
{
    lli n = str.length();
    lli L, R, k;
    L = R = 0;
    for (lli i = 1; i < n; ++i){
        if (i > R){
            L = R = i;
            while (R<n && str[R-L] == str[R])
                R++;
            Z[i] = R-L;
            R--;
        } else {
            k = i-L;
            if (Z[k] < R-i+1)
                Z[i] = Z[k];
            else {
                L = i;
                while (R<n && str[R-L] == str[R])
                    R++;
                Z[i] = R-L;
                R--;
            }
        }
    }
}


*/
/*
lli power(lli x, lli y, lli p) 
{ 
    lli res = 1;   
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
  
        y = y>>1;  
        x = (x*x) % p;   
    } 
    return res; 
} 
*/

Measured memory_bytes: 1024
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;


int main(){
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]){
        cout<<"Yes"<<endl;
        return 0;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

int main() {
    ll N, M; cin >> N >> M;
    ll sum = 0;
    map<ll, ll> m;
    m[sum]++;
    for(int i=1; i<N+1; i++){
        int a; cin >> a;
        sum += a;
        m[sum%M]++;
    }
    ll ans = 0;
    for(auto i:m){
        ans += (i.second*(i.second-1)/2);
    }
    cout << ans << endl;
    return 0;
}





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

int main()
{
    int h,w;
    std::cin >> h >> w;
    std::vector<std::vector<bool>> map(h+1,std::vector<bool>(w+1));
    std::vector<std::vector<bool>> map2(w+1,std::vector<bool>(h+1));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char tmp;
            std::cin >> tmp;
            map[i][j] = tmp == '.';
        }
    }
    for(int i=0;i<w;i++){
        for(int j=0;j<h;j++){
            map2[i][h-1-j] = map[j][i];
        }
    }
    std::vector<std::vector<int>> sum(h,std::vector<int>(w));
    //横について見ていく
    for(int i=0;i<=h;i++){
        int cnt = 0;
        auto itr = sum[i].begin();
        for(int j=0;j<=w;j++){
            if(!map[i][j]){
                std::fill(itr,sum[i].begin() + j,cnt);
                itr = sum[i].begin() + j+1;
                cnt = 0; 
            }else{
                cnt++;
            }
        }
    }
    //縦について見ていく
    std::vector<std::vector<int>> sum2(w,std::vector<int>(h));
    for(int i=0;i<=w;i++){
        int cnt = 0;
        auto itr = sum2[i].begin();
        for(int j=0;j<=h;j++){
            if(!map2[i][j]){
                std::fill(itr,sum2[i].begin() + j,cnt);
                itr = sum2[i].begin() + j + 1;
                cnt = 0;
            }else{
                cnt++;
            }
        }
    }
    for(int i=0;i<w;i++){
        for(int j=0;j<h;j++){
            sum[j][i] += sum2[i][h-1-j];
        }
    }
    int max = 0;
    for(int i=0;i<h;i++){
        max = std::max(max,*std::max_element(sum[i].begin(),sum[i].end()));
    }
    std::cout << max - 1 << std::endl;
}

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

int main(void)
{
  int x,y,W,H,r;
  cin >> W >> H >> x >> y >> r ;
  
  if( x-r >= 0 && x+r <= W && y-r >= 0 && y+r <= H)
    cout << "Yes" << endl;
  else 
    cout << "No" << endl;
 
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll m, n, x, y, z;
ll ans = 10000000000000000;
ll ara[300000], csum[300000];

int main()
{
    cin >> n;

    for(ll i = 1; i <= n; i++) scanf("%lld", &ara[i]), csum[i] = csum[i - 1] + ara[i];

    for(ll i = 1; i < n; i++){
        ll tmp1 = csum[i];
        ll tmp2 = csum[n] - csum[i];
        ll tmp = abs(tmp1 - tmp2);
        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    if(a < b) cout << "a < b" << endl;
    if(a == b) cout <<"a == b" << endl;
    if(a > b) cout << "a > b" << endl;
}



Measured memory_bytes: 3084
using System;

class ABC_135_A
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);

        if ((A+B) % 2 != 0)
        {
            Console.WriteLine("IMPOSSIBLE");
        }
        else
        {
            Console.WriteLine((A+B)/2);
        }
    }
}

Measured memory_bytes: 11092
//File Name: C.cpp
  //Author: long
  //Mail: 736726758@qq.com
  //Created Time: 2016年11月13日 星期日 23时59分46秒
                                   
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10;
char s[MAXN];
int solve(){
	int n = strlen(s);
	int res = 1;
	char pre = s[0];
	for(int i=1;i<n;i++){
		if(s[i] != pre){
			res++;
			pre = s[i];
		}
	}
	return res - 1;
}
int main(){
	scanf("%s",s);
	printf("%d\n",solve());
	return 0;
}

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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
template <class T>
T GCD(T a, T b)
{
    T r;
    while (a)
        r = b, b = a, a = r % a;
    return b;
}
template <class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<ll> vl;
#define ERASE(x) x.erase(unique(ALL(x)), x.end()); // erase same elements
#define VEC(type, c, n)     \
    std::vector<type> c(n); \
    for (auto &i : c)       \
        std::cin >> i;

// input
#define INIT                          \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define VAR(type, ...) \
    type __VA_ARGS__;  \
    MACRO_VAR_Scan(__VA_ARGS__);

// output
template <typename T>
void MACRO_OUT(const T t) { std::cout << t; }

#define OUT(...) MACRO_OUT(__VA_ARGS__);
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define ENDL std::cout << std::endl;

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
    cout << a;
    ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
    cout << a << ' ';
}

ll ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b, c, d, n;
int x, y;
int sum;
char ch;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// cout << (conditon ? (result:  == 1 ): (==0)) << endl; <- output result of if
// long long 型が表せる値の上限はおよそ 9 × 10＾18 です．
int main()
{
    INIT;

    cin >> a >> b;
    string q;
    rep(i, b + 2) q += '#';
    pr(q);
    rep(i, a)
    {
        cin >> s;
        cout << "#" << s << "#" << endl;
    }

    pr(q);
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>
using namespace std;
#define all(x) (x).begin(), (x).end()

const int N = 100001;
int n, q;
string s[N];

int go[26][4 * N];
int wh[4 * N];
int cnt = 1;
int a[26][26][N];
int p[4 * N];
int fl[4 * N];
int fl2[N];
int sz[4 * N];
int into[4 * N];

vector<vector<int> > b;

void dfs(int v)
{
    fl[v] = fl[v] + fl[p[v]];
    if (wh[v] != -1)
    {
        fl2[wh[v]] = fl[v];
        for (int x = 0; x < 26; x++)
            for (int y = 0; y < 26; y++)
                a[x][y][wh[v]] = b[x][y];
    }
    for (int x = 0; x < 26; x++)
    {
        if (go[x][v] != 0)
        {
            for (int y = 0; y < 26; y++)
            {
                b[y][x] += go[y][v] ? sz[go[y][v]] : 0;
            }
            dfs(go[x][v]);
            for (int y = 0; y < 26; y++)
            {
                b[y][x] -= go[y][v] ? sz[go[y][v]] : 0;
            }
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    wh[0] = -1;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
        int pnt = 0;
        for (int j = 0; j < s[i].size(); j++)
        {
            sz[pnt]++;
            if (go[s[i][j] - 'a'][pnt] == 0)
            {
                p[cnt] = pnt;
                into[cnt] = s[i][j] - 'a';
                wh[cnt] = -1;
                go[s[i][j] - 'a'][pnt] = cnt++;
            }
            pnt = go[s[i][j] - 'a'][pnt];
        }
        sz[pnt]++;
        wh[pnt] = i;
        fl[pnt] = 1;
    }
    b.resize(26, vector<int>(26));
    dfs(0);
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int k;
        string alpha;
        cin >> k >> alpha, k--;
        vector<int> pos(26);
        int ans = 0;
        for (int j = 0; j < alpha.size(); j++) pos[alpha[j] - 'a'] = j;
        for (int x = 0; x < 26; x++)
            for (int y = 0; y < 26; y++)
                if (pos[x] < pos[y])
                    ans += a[x][y][k];
        cout << ans + fl2[k] << "\n";
    }
}


Measured memory_bytes: 327196
#include<stdio.h>
#include<queue>
#include<assert.h>
#include<tuple>
#include<string>
#include<algorithm>
#include<iostream>
#include<map>
#include<string.h>
#include<vector>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<ctype.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 200005;
const int MM = 1000000007;

char buf[MX];
int N, K, flip;
queue<int> Q;

void push(int x){
	Q.push(flip^x);
}

int pop(){
	int v = Q.front()^flip; Q.pop();
	return v;
}

int main()
{
	scanf("%d%d%s", &N, &K, buf+1);
	for(int i = 1; i <= N; i++) Q.push(buf[i] == 'A');
	for(int i = 1; i <= K && i <= 2*N; i++){
		if( Q.front()^flip ) Q.front() ^= 1;
		else{
			Q.pop();
			flip ^= 1;
			push(1);
		}
	}
	if( K > 2*N && N%2 == 1 && (K-2*N)%2 == 1) Q.front() ^= 1;
	while(Q.size()){
		printf("%c", Q.front()^flip? 'A' : 'B');
		Q.pop();
	}
	printf("\n");
}


Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] ans = new int[N];
    for (int id = 1; id <= N; id++) {
      int num = sc.nextInt();
      ans[num - 1] = id;
    }
    System.out.print(ans[0]);
    for (int i = 1; i < N; i++) {
      System.out.print(" " + ans[i]);
    }
  }
}


Measured memory_bytes: 65500
class Node:
  def __init__(self,key):
    self.key = key
    self.next = None

class List:
  def __init__(self):
    self.head = Node(0)
    self.tail = self.head

  def insert(self,key):
    self.tail.next = Node(key)
    self.tail = self.tail.next

  def dump(self):
    p = self.head.next
    while p != None:
      print(p.key, end='')
      if p.next != None:
        print(' ',end='')
      p = p.next
    print()

  def splice(self,other):
    other.tail.next = self.head.next
    other.tail = self.tail
    self.head.next = None
    self.tail = self.head

''' main function '''
n,q = map(int,input().split())

SList = [List() for i in range(n)]

for i in range(q):
  com,index,*n = map(int,input().split())
  if com == 0:
    SList[index].insert(n[0])
  elif com == 1:
    SList[index].dump()
  elif com == 2:
    SList[index].splice(SList[n[0]])



Measured memory_bytes: 105476
#include<iostream>
#include<cmath>
#include<algorithm>
#define MAX 100000000
using namespace std;

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

  int v, cnt = 0;
  for ( int i = 0; i < n; i++){
    cin >> v;
    bool prime = true;
    for ( int j = 2; j <= sqrt(v); j++ ){
      if ( v % j == 0){
        prime = false;
        break;
      }
    }
    if ( prime ) cnt++;
  }

  cout <<  cnt << endl;

  return 0;
}


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

using namespace std;

long long int gcd(long long int a,long long int b)
{
    if(a%b==0)
        return b;
    if(b%a==0)
        return a;
    if(a>b)
        return gcd(b,a%b);
    else
        return gcd(a,b%a);
}

int main()
{
    long long int t,n,x,flag,temp,i,j,sum=0,k,l;
    cin>>k;
    //cout<<"1";
    for(i=1;i<=k;i++)
    {
        for(j=1;j<=k;j++)
        {
            for(l=1;l<=k;l++)
            {
                sum+=gcd(i,gcd(j,l));
            }
            
        }
    }
    cout<<sum;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define pf push_front
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
const int n_max=1e5+5;
vector<int> g[n_max];
bool used[n_max];
deque<int>  deq;

void dfsf(int v){
  for(auto i:g[v]){
    if(used[i]) continue;
    else{
      used[i]=true;
      deq.pf(i);
      dfsf(i);
      break;
    }
  }
}
void dfsb(int v){
  for(auto i:g[v]){
    if(used[i]) continue;
    else{
      used[i]=true;
      deq.pb(i);
      dfsb(i);
      break;
    }
  }
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin >> n >> m;  
  //  vector<int> g[n];
  int a,b;
  rep(i,m){
    cin >> a >> b;
    a--;b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  deq.pf(0);
  deq.pb(g[0][0]);
  //  bool used[n];
  rep(i,n) used[i]=false;
  used[0]=used[g[0][0]]=true;
  dfsf(0);
  dfsb(g[0][0]);
  cout << deq.size() << endl;
  rep(i,deq.size()){
    cout << deq[i]+1 << " ";    
  }
  cout << "" << endl;
  
  
  return 0;
    

}


Measured memory_bytes: 9600
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr, sort)
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Ord
import Data.Coerce

sortDown :: forall a. Ord a => [a] -> [a]
sortDown = coerce (sort :: [Down a] -> [Down a])

exchangeOne :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int
exchangeOne !gA !sA !bA !gB !sB !bB !n =
  let dg = gB - gA
      ds = sB - sA
      db = bB - bA
      l = sortDown $ filter (\(d,x) -> d > 0) [(dg, gA), (ds, sA), (db, bA)]
  in case l of
       [] -> n
       [(!dx,!xA)] ->
         let (qx,rx) = n `quotRem` xA
             -- A で qx * gA 個のどんぐりを売却し、金 qx グラムを得る。
             -- B で金 qx グラムを売却し、 qx * gB 個のどんぐりを得る。
         in n + qx * dx
       [(!dx,!xA),(!dy,!yA)] ->
         n + maximum [ x * dx + y * dy
                     | x <- [0..n `quot` xA]
                     , let y = (n - x * xA) `quot` yA
                     ]
       [(!dx,!xA),(!dy,!yA),(!dz,!zA)] ->
         n + maximum [ x * dx + maximum [ y * dy + z * dz
                                        | y <- [0..n' `quot` yA]
                                        , let z = (n' - y * yA) `quot` zA
                                        ]
                     | x <- [0..n `quot` xA]
                     , let !n' = n - x * xA
                     ]

main = do
  n <- readLn
  [gA,sA,bA] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  [gB,sB,bB] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ exchangeOne gB sB bB gA sA bA $ exchangeOne gA sA bA gB sB bB n


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<pair<int64_t,int64_t>> vec(N);
  for (int i =0; i<N; i++) {
    int64_t O,P;
    cin >> O >> P;
    vec.at(i) = make_pair(O,P);
  }
  sort(vec.begin(), vec.end());
  int64_t total =0;
  int64_t ans =0;
  int i =0;
  bool shokai =false;
  while (true) {
    if (vec.at(i).second >= M) {
      shokai =true;
      break;
    } else {
      total += vec.at(i).second;
      ans += vec.at(i).first * vec.at(i).second;
      if (total + vec.at(i+1).second >= M) {
        break;
      } else {
        i++;
      }
    }
  }
  if (shokai) {
    ans += (M - total) * vec.at(i).first;
  } else {
    ans += (M - total) * vec.at(i+1).first;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4820
//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 1000005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;
ll N, ans, K, suf[MAX];

int main() {
    optimiza_io
    ll T;
    cin >> N >> K;
    for( ll i = N; i >= 0; i -- )
        suf[i] = ( suf[i + 1] + i ) % MOD;
    for( ll i = K; i <= N+1; i ++ ) {
        ll mn = 0, mx = 0;
        mn = ( i * ( i - 1 ) ) / 2;
        mx = suf[N-i+1];
        ll sz = ( mx - mn + 1 ) % MOD;
        sz += MOD;
        sz %= MOD;
        ans += sz;
        ans %= MOD;
    }
    
    cout << ans << "\n";
    return 0;
}

// CHECAR LIMITES 

Measured memory_bytes: 5204
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=200005;
//i_am_noob
int n,a[maxn],b[maxn];

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	rep(n) cin >> a[i];
	rep(n) b[a[i]-1]=i+1;
	rep(n) print0(b[i]);
	cout << '\n';
	return 0;
}

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

int main(){
	int n, m, k; cin>>n>>m>>k;
	int A[n], B[m];
	rep(i, n) cin>>A[i];
	rep(i, m) cin>>B[i];
	int64_t tot = 0; rep(i, m) tot += B[i];
	int ans = 0, j = m;
	rep(i, n+1){
		while(j>0 && tot > k) tot -= B[--j];
		if(tot > k) break;
		if(i < n) tot += A[i];
		ans = max(ans, i+j);
	}
	cout<< ans <<endl;
}


Measured memory_bytes: 5200
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(void){
  float n;
  cin >> n;
  
  float sum = 0;
  
  vector<float>a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum += a[i];
  }
  
  sum /= n;
  float max = 100000000;
  int ans = 0;
  for(int i=0;i<n;i++){
    if(max > abs(sum - a[i])){
      ans = i;
      max = abs(sum - a[i]);
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch SheepAndWolves | diff SheepAndWolves.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address SheepAndWolves.cpp && ./a.out

/*
 
 4/26/2020
 
 5:00-
 
 */

int S,W;

void solve() {
  string r=W>=S?"unsafe":"safe";
  cout<<r<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>S>>W;
  solve();
  
  return 0;
}


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

typedef long long int ll;
typedef vector<int> vi;     typedef vector<ll> vl;
typedef vector<vi> vvi;     typedef vector<vl> vvl;
typedef pair<int, int>  pii;  typedef pair<ll, ll> pll;
typedef vector<pii> vii;    typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
const ll INFL = 1e18;
const int INFI = 1e9;
#ifdef EVIL
	#include "../../trace.h"
#else
	#define trace(args...)
#endif

ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}
ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
// void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

long double eps=1e-10;
ll m=1e18;

void solve(){
	int n;
	cin>>n;
	// vl a(n);
	ll ans=1;
	bool flag=0;
	// cout<<setprecision(30);
	rep(i,0,n-1){
		ll x;
		cin>>x;
		// cout<<log10(1.0L*ans)<<endl;
		// cout<<log10(1.0L*x)<<endl;
		// cout<<log10(1.0L*ans)+log10(1.0L*x)<<endl;
		if(x==0){
			ans=0;
			flag=0;
			break;
		}
		else{
			if(log10(1.0L*ans)+log10(1.0L*x)>18-eps){
				if(m%ans!=0 || m%x!=0){
					flag=1;			
				}
				else{
					ans=ans*x;
				}
			}
			else{
				ans=ans*x;
			}
		}
	}
	if(flag==1){
		cout<<-1;
	}
	else{
		cout<<ans;
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef EVIL
		freopen("inp.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
		freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	// cin>>t;
	rep(q,0,t-1){
		solve();
	}
}


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

int n, m;
set<string> st;
int t;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=0; i<n; ++i){
		string s;
		cin >> s;
		st.insert(s);
	}
	cin >> m;
	for(int j=0; j<m; ++j){
		string s;
		cin >> s;
		auto ite = st.find(s);
		if(ite == st.end()) cout << "Unknown " << s << "\n";
		else{
			if(t == 0) cout << "Opened by " << s << "\n";
			else cout << "Closed by " << s << "\n";
			t = 1 - t;
		}
	}
}


Measured memory_bytes: 3228
using i64 = long long;
#define _overload(_1, _2, _3, _4, name, ...) name
#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)
#define _rep2(Itr, a, b) _rep3(Itr, a, b, 1)
#define _rep3(Itr, a, b, step) for (i64 (Itr) = a; (Itr) < b; (Itr) += step)
#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>

using namespace std;
using llong = long long;

struct Trie {
    using State = string::iterator;
    struct Node {
        Node *ch[26] = {};
        int cnt[26] = {};
        int s = 0;
    };

    Node *root = nullptr;
    Trie () {
        root = new Node();
    };

    void insert(string &s, int cnt[]) {
        root->s++;
        repeat(i, 26) {
            if (cnt[i]) root->cnt[i]++;
        }

        if (root->ch[s[0] - 'a'] == nullptr) root->ch[s[0] - 'a'] = new Node();
        insert(root->ch[s[0] - 'a'], s.begin(), cnt);
    };

    void insert(Node *u, State s, int cnt[]) {
        cnt[*s - 'a']--;
        u->s++;
        repeat(i, 26) {
            if (cnt[i]) u->cnt[i]++;
        }

        s++;
        if (*s == '\0') return;
        if (u->ch[*s - 'a'] == nullptr) u->ch[*s - 'a'] = new Node();
        insert(u->ch[*s - 'a'], s, cnt);
    };

    int find(string &s) {
        if (s.size() == 1) {
            return root->cnt[s[0] - 'a'];
        }
        else {
            return find(root->ch[s[0] - 'a'], s.begin());
        }
    };
    int find(Node *u, State s) {
        if (u == nullptr) return 0;

        ++s;
        if (s[1] == '\0') {
            return u->cnt[*s - 'a'];
        }
        else {
            return find(u->ch[*s - 'a'], s);
        }
    };
};

llong n;
vector<string> s;
Trie tr;

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

    cin >> n;
    s.resize(n);
    for (auto &vs:s) cin >> vs;

    repeat(i, n) {
        int cnt[26] = {};
        reverse(s[i].begin(), s[i].end());
        for (auto ch:s[i]) {
            cnt[ch - 'a']++;
        }
        tr.insert(s[i], cnt);
    }

    llong ans = 0;
    repeat(i, n) {
        ans += tr.find(s[i]) - 1;
    }

    cout << ans << '\n';

    return 0;
};


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

using namespace std;

typedef long long ll;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    if (s == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1;
        return 0;
    }
    int n = s.length();
    if (n < 26) {
        vector<int> p(26);
        for (char c : s) {
            p[c - 'a'] = 1;
        }
        for (int i = 0; i < 26; ++i) {
            if (!p[i]) {
                s += char('a' + i);
                break;
            }
        }
    } else {
        vector<int> p(26);
        string t = s;
        next_permutation(s.begin(), s.end());
        for (int i = 0; i < 26; ++i) {
            if (s[i] != t[i]) {
                s.erase(i + 1);
                break;
            }
        }
    }
    cout << s;
    return 0;
}

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

using namespace std;

int main() {
  int N, K;
  while (cin >> N >> K) {
    int V[55] = {};
    for (int i = 0; i < N; i++) {
      cin >> V[i];
    }
    long long ans = 0;
    for (int i = 0; i <= K; i++) {
      for (int j = 0; i + j <= K; j++) {
        vector<long long> v;
        for (int k = 0; k < i && k < N; k++) {
          v.push_back(V[k]);
        }
        for (int k = 0; k < j && i + k < N; k++) {
          v.push_back(V[N-1-k]);
        }
        sort(v.begin(), v.end());
        long long sum = accumulate(v.begin(), v.end(), 0);
        // cout << i << ' ' << j << ' ' << sum << endl;
        for (int k = 0; k < K - i - j && k < v.size(); k++) {
          if (v[k] < 0) sum -= v[k];
        }
        // cout << sum << endl;
        ans = max(sum, ans);
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
from collections import Counter

def solve(n, A):
    c = Counter(A)
    cands = sorted(filter(lambda kv: kv[1] >= 2, c.items()),  key=lambda kv: -kv[0])
    ret = 0
    if len(cands) >= 1 and cands[0][1] >= 4:
        ret = cands[0][0] * cands[0][0]
    elif len(cands) >= 2:
        ret = cands[0][0] * cands[1][0]
    return ret

_n = int(input())
_A = map(int, input().split())
print(solve(_n, _A))


Measured memory_bytes: 24224
import Control.Applicative

main = do xs <- map (map read . words) . lines <$> getContents
          putStr . unlines . filter (/="") $ map solve xs

solve :: [Int] -> String
solve (m:f:r:_) | m == -1 && f == -1 && r == -1 = ""
                | m== -1 || f== -1 = "F"
                | m+f>=80 = "A"
                | m+f>=65 = "B"
                | m+f>=50 || (m+f>=30 && r>=50) = "C"
                | m+f>=30 = "D"
                | otherwise = "F"

Measured memory_bytes: 3936
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    cout << (e - a <= k ? "Yay!" : ":(") << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
	n = int(input())
	List = list(map(int,input().split()))
	List.sort()

	# print(List)
	# print(len(List))
	# print(len(List)/2)

	c = List[int(len(List)/2)]
	cm = List[int(len(List)/2) -1]
	# print(c,cm,c-cm)

	print(c-cm)

if __name__ == "__main__":
	main()

Measured memory_bytes: 52776
#include <iostream>
#define M 1000

using namespace std;

int min (int *a,int n){
    int i = 0;
    int nMin = a[0];
    for( i = 1; i<n; i++){
        if (nMin > a[i] ){
            nMin = a[i];
        }
    }
    return nMin;
}

int max (int *a,int n){
    int i = 0;
    int nMax = a[0];
    for( i = 1; i<n; i++){
        if (nMax < a[i] ){
            nMax = a[i];
        }
    }
    return nMax;
}

int main (){
    int n;
    int a[M];
    
    cin >> n;
    for (int i = 0; i < n; i++ ){
        cin >> a[i];
    }
    
    cout << max(a,n) - min(a,n) << endl;
    

    return 0;
}


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

	//A
	int n;
	cin >> n;
	char s[100];
	char t[100];

	cin >> s;
	cin >> t;

	int i, j;
	int flag;
	for (i = 0; i < n; i++) {
		flag = 0;
		for (j = 0; j <= n-i-1; j++) {
			if (t[j] == s[j + i]) {

			}
			else {
				flag = 1;
				break;
			}
		}
		if (flag == 0) {
			cout << n + i;
			return 0;
		}
	}
	cout << 2 * n;
	return 0;

	/*int n, x, i;
	
	std::cin >> n;
	std::cin >> x;

	
	if (n == 1) {
		if (x == 1) {
			std::cout << "Yes\n";
			std::cout << 1;
		}
		else {
			std::cout << "No";
		}
	}
	else if (n == 2) {
		if (x == 2) {
			std::cout << "Yes\n";
			std::cout << 1; std::cout << "\n"; std::cout << 2; std::cout << "\n"; std::cout << 3;
		}
		else {
			std::cout << "No";
		}
	}
	else {
		if (x == 1) {
			std::cout << "No";
		}
		else if (x == 2 * n - 1) {
			std::cout << "No";
		}
		else if (x == 2) {
			std::cout << "Yes\n";
			for (i = 1; i <= 2 * n - 1; i++) {
				if (i < n - 1) {
					std::cout << i + 4;
				}
				else if (i < n + 2) {
					std::cout << n + 2 - i;
				}
				else if (i == n + 2) {
					std::cout << 4;
				}
				else {
					std::cout << i;
				}
			}
			std::cout << "\n";
		}
		else {
			std::cout << "Yes\n";
			for (i = 1; i <= 2 * n - 1; i++) {
				if (i == n - 1) {
					std::cout << x - 1;
				}
				else if (i == n) {
					std::cout << x;
				}
				else if (i == n + 1) {
					std::cout << x + 1;
				}
				else if (i == n + 2) {
					std::cout << x - 2;
				}
				//else if (i == x - 1) {
				//	std::cout << n - 1;
				//}
				//else if (i == x) {
				//	std::cout << n;
				//}
				//else if (i == x + 1) {
				//	std::cout << n + 1;
				//}
				//else if (i == x - 2) {
				//	std::cout << n + 2;
				//}
				else {
					std::cout << i;
				}
				std::cout << "\n";
			}
		}
	}
	return 0;
	*/

}

Measured memory_bytes: 3576
fun main(args: Array<String>) = yorukatsu13c()

fun yorukatsu13c() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val aList = readLine()!!.split(' ').map { it.toInt() }

    val answer = Math.ceil((n - 1).toDouble() / (k - 1).toDouble()).toLong()

    println(answer)
}


Measured memory_bytes: 47744
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<ll> h(n);
    rep(i, n)cin >> h[i];
    ll ma = h[0], ans = 1;
    REP(i, n-1){
        if(h[i] >= ma)ans++;
        ma = max(ma, h[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    
    long long int n,i,a,min=1000000,max=-1000000,sum=0;
    scanf("%lld",&n);
    
    for(i=0;i<n;i++){
        scanf("%lld",&a);
        
        if(a<min) min=a;
        if(a>max) max=a;
        sum=sum+a;
    }
    printf("%lld %lld %lld\n",min,max,sum);
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d)cout<<"Left"<<endl;
  else if(a+b==c+d)cout<<"Balanced"<<endl;
  else cout<<"Right"<<endl;
  return 0;
}




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

cnt_R = 0

for i in range(N):
    if C[i] == 'R':
        cnt_R += 1


ans = min(cnt_R, N - cnt_R)

cnt_swap = 0
for i in range(cnt_R):
    if C[i] != 'R':
        cnt_swap += 1


print(min(ans, cnt_swap))

Measured memory_bytes: 67292
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define dbg(n) cout<<#n<<' '<<n<<endl;
vector<int>a[100001];
int len[100001]={0};
int dfs(int n,int vis[]){
	if(!vis[n]){
		vis[n]=1;
		for(int i=0;i<(int)a[n].size();i++){
			len[n]=max(len[n],dfs(a[n][i],vis));	
		}
		len[n]=max(len[n],1);
	}
	return len[n]+1;	
}
int main(){ 
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		a[x].pb(y);
	}
	int vis[100001]={0};
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			dfs(i,vis);
		}
	}
	int mx=0;
	for(int i=1;i<=n;i++)mx=max(mx,len[i]);
	cout<<mx-1<<endl;
}



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

int main(void) {
    int s;
    cin>>s;
    int high = s/100;
    int low = s%100;
    string ans="";
    if(high>0&&high<13){
        if(low>0&&low<13)ans="AMBIGUOUS";
        else ans="MMYY";
    }
    else if(low>0&&low<13)ans="YYMM";
    else ans="NA";
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

n = ni()
ans = set()

for _ in range(n):
    s = ns()
    ans.add(s)

print(len(ans))

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

int main() {
  vector<int> vec(3);
  for(int i=0;i<3;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  cout << vec.at(2)-vec.at(0) <<endl;
}

Measured memory_bytes: 256
/*
  選択ソート（数列Aを読み込み、選択ソートのアルゴリズムで昇順に並び替え
  　　　　　　出力するプログラム）
  2018/04/16
*/

#include<stdio.h>

#define MAX 100//Aの要素数

void swap(int *a,int i,int j)
{
  int temp;
  temp = a[i];
  a[i] = a[j];
  a[j] = temp;
}
//Ｎこの要素を含む０-オリジンの配列
int selectionSort(int *a,int n)
{
  int i,j;
  int minj;
  int count;
  int sum=0;//比較回数の合計

  for(i=0;i<n;i++){
    minj = i;
    count = 0;
    for (j=i;j<n;j++)
      if(a[j] < a[minj]){
	minj = j;
	count = 1;
      }
    swap(a,i,minj);
    sum += count;
  }
  return sum;
}

int main(void)
{
  int a[MAX];
  int n;
  int i;
  int count = 0;

  fscanf(stdin,"%d",&n);
  for(i=0;i<n;i++)
    fscanf(stdin,"%d",&a[i]);

  count = selectionSort(a,n);

  for(i=0;i<n-1;i++)
    fprintf(stdout,"%d ",a[i]);
  fprintf(stdout,"%d\n%d\n",a[i],count);

  return 0;
}


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

using namespace std;

const int MAXN=101;

int n,m,a[MAXN],sum=0,tot=0;

int main() {
	cin>>n>>m;
	for(int i=1; i<=n; ++i) {
		cin>>a[i];
		sum+=a[i];
	}
	for(int i=1; i<=n; ++i) if(a[i]*4*m>=sum) ++tot;
	puts(tot>=m ? "Yes":"No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

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

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
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; }

// debug
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}
#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif


int main() {
  int N; cin >> N;
  // int N, M; cin >> N >> M;
  // int H, W; cin >> H >> W;

  string S[N];
  int T[N];
  rep(i, N) {
    cin >> S[i] >> T[i];
  }
  string X;
  cin >> X;
  int sum = 0;
  rrep(i, N-1) {
    if (S[i] == X) {
      cout << sum << endl;
      return 0;
    }
    sum += T[i];
  }

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(void) {
	string s, t; cin >> s >> t;
	vector<char> cs, ct;
	for(auto u : s) cs.pb(u);
	for(auto u : t) ct.pb(u);
	sort(all(cs)), sort(all(ct));
	reverse(all(ct));
	string ds, dt;
	for(auto u : cs) ds += u;
	for(auto u : ct) dt += u;
	if(ds < dt) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	int N,M,sw = 0;
  cin >> N >> M;
  vector<vector<char>> a(N,vector<char>(M));
  vector<vector<int>> b(N,vector<int>(M,0));
  froop1(0,N){
    for(int j = 0;j < M;j++){
      cin >> a.at(i).at(j);
    }
  }
  
	froop1(0,N){
      for(int j = 0;j < M;j++){
        if(a.at(i).at(j) == '#'){
          sw = 1;
          break;
        }
      }
      if(sw == 0){
      for(int j = 0;j < M;j++){
        b.at(i).at(j) = 1;
      }
      }
      sw = 0;
	}
  	froop1(0,M){
      for(int j = 0;j < N;j++){
        if(a.at(j).at(i) == '#'){
          sw = 1;
          break;
        }
      }
      if(sw != 1){
      for(int j = 0;j < N;j++){
        b.at(j).at(i) = 1;
      }
      }
      sw = 0;
	}
  
  froop1(0,N){
   for(int j = 0;j < M;j++){
    if(b.at(i).at(j) == 0){
      cout << a.at(i).at(j);
      sw = 1;
    }
   }
    if(sw == 1){
    cout << endl;
      sw = 0;
    }
  }
return 0;
}

Measured memory_bytes: 256