akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define LL long long
#define int LL
const LL inf=0x3f3f3f3f;
using namespace std;
template<typename tp> inline void read(tp &x)
{
	x=0; char c=getchar(); bool f=0;
	for(;c<'0'||c>'9';f|=(c=='-'),c = getchar());
	for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0',c = getchar());
	if(f) x=-x;
}
int n,m,q;
vector<int> x[510];
signed main()
{
	read(n),read(m),read(q);
	for(int i=1,l,r;i<=m;i++)
	{
		read(l),read(r);
		x[l].push_back(r);
	}
	for(int i=1;i<=n;i++)
		sort(x[i].begin(),x[i].end());
	for(int i=1,l,r;i<=q;i++)
	{
		read(l),read(r);
		int ret=0;
		for(int j=l;j<=r;j++)
			ret+=upper_bound(x[j].begin(),x[j].end(),r)-x[j].begin();
		printf("%lld\n",ret);
	}
	return 0;
}

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

int main(){
  int n; cin>>n;
  int a[n];
  rep(i,n){
    cin>>a[i];
    a[i]--;
  }
  int count=0;
  rep(i,n){
    if(i==a[a[i]]) count++;
  }
  cout<<count/2<<endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
    int w, n, a, b, ans[50];
    for(int i=0 ; i < 50 ; i++ ){
        ans[i] = i;
    }
    scanf("%d %d", &w, &n);
    for(int i=0 ; i < n ; i++ ){
        scanf("%d,%d", &a, &b );
        swap( ans[a] , ans[b] );
    }
    for(int i=1 ; i <= w ; i++ ){
        printf("%d\n", ans[i] );
    }
}

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

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


int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n)cin >> p[i];
  int ans = 0;
  int x = 1e9;
  rep(i,n){
    x = min(x,p[i]);
    if(x==p[i])ans++;
  }
  cout << ans << endl;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> B(N-1);
  for(int i=0; i<N-1; i++) cin >> B.at(i);
  int ans=B.at(0);
  for(int i=0; i<N-2; i++){
    ans+=min(B.at(i),B.at(i+1));
  }
  ans+=B.at(N-2);
  cout << ans << endl;
}

Measured memory_bytes: 256
def examA():
    N, L = LI()
    V, D = LI()
    X = [LI()for _ in range(N)]

    ans = 0
    print(ans)
    return

def examB():
    N, K = LI()
    H = 11; W = 7
    S = [[0]*(W+1) for _ in range(H+3)]
    for h in range(H+2):
        for w in range(W):
            S[h+1][w+1] = (S[h][w+1] + S[h+1][w] - S[h][w] + (7*h+w+1))
    #print(S)
    base = 0
    for h in range(H):
        for w in range(W-2):
            cur = S[h+3][w+3] - S[h+3][w] - S[h][w+3] + S[h][w]
            if cur%11==K:
                base += 1
                #print(h,w)
    ans = base * ((N-2)//11)
    #print(ans)
    rest = (N-2)%11
    for h in range(rest):
        for w in range(W-2):
            cur = S[h+3][w+3] - S[h+3][w] - S[h][w+3] + S[h][w]
            if cur%11==K:
                ans += 1
                #print(h,w)
    print(ans)
    return

def examC():
    N, K = LI()
    A = LI()
    loop = 2**N
    ans = inf
    for i in range(loop):
        cnt = 0
        need = 0
        highest = 0
        for j in range(N):
            if i&(1<<j)==0:
                if highest<A[j]:
                    need = inf
                    break
                continue
            cnt += 1
            if highest>=A[j]:
                need += (highest+1-A[j])
                highest = highest + 1
            else:
                highest = A[j]
        if cnt>=K and need<ans:
            ans = need
        #print(need)
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examC()

"""

"""

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    set<int> s;

    int n; cin >> n;
    for(int i = 0;i < n; ++i){
        int d; cin >> d;
        s.insert(d);
    }
    
    int ans = s.size();
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int N;
    cin>>N;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin>>A.at(i);
    }
    ll mn=LONG_MAX,mncount=0,sum=0;
    for(int i=0;i<N;i++){
        sum+=abs(A.at(i));
        chmin(mn,abs(A.at(i)));
        if(A.at(i)<0)mncount++;
    }
    if(mncount%2==0){
        cout<<sum<<endl;
    }
    else {
        cout<<sum-mn*2<<endl;
    }
}

Measured memory_bytes: 1024
def prov(maskHor, maskVert):
    kol = 0
    for i in range(h):
        for j in range(v):
            if m[i][j] == '#':
                b = 0
                for hor in maskHor:
                    if hor == i:
                        b = 1
                for vert in maskVert:
                    if vert == j:
                        b = 1
                if b == 0:
                    kol += 1
    #tmh = maskHor
    #for i in range(len(tmh)):
    #    tmh[i] = str(tmh[i])
    #tmv = maskVert
    #for i in range(len(tmv)):
    #    tmv[i] = str(tmv[i])
    #print('!', ' '.join(tmh), '!', ' '.join(tmv), '!', kol)
    if kol == k:
        global ans
        ans += 1


def genMaskVert(pos, mask, maskHor):
    if (pos == v):
        prov(maskHor, mask)
        #if not len(mask) == 0:
        #    mask.pop()
        return
    else:
        genMaskVert(pos + 1, mask, maskHor)
        temp = mask
        temp.append(pos)
        genMaskVert(pos + 1, temp, maskHor)
        if not len(mask) == 0:
            mask.pop()
        return


def genMaskHor(pos, mask):
    if (pos == h):
        genMaskVert(0, [], mask)
        #if not len(mask) == 0:
        #    mask.pop()
        return
    else:
        genMaskHor(pos + 1, mask)
        mask.append(pos)
        genMaskHor(pos + 1, mask)
        if not len(mask) == 0:
            mask.pop()
        return


h, v, k = input().split()
h = int(h)
v = int(v)
k = int(k)
ans = 0
m = []
for i in range(h):
    m.append(input())
genMaskHor(0, [])
print(ans)


Measured memory_bytes: 74980
n=int(input())
a=list(map(int,input().split()))
d={}
for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
q=int(input())
s=sum(a)
for i in range(q):
    b,c=map(int,input().split())
    if c in d and b in d:
        d[c]+=d[b]
    elif b in d:
        d[c]=d[b]
    if b in d:
        s=s+(c-b)*d[b]
        d.pop(b)
    print(s)


Measured memory_bytes: 84296
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
	int n;
	cin >> n;
	string s;
	set<string> st;
	rep(i, n) cin >> s, st.insert(s);
	cout << st.size();
	return 0;
}


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

int main() {
  long long a, b;
  cin >> a >> b;
  if (a > b) {
    long long t = a;
    a = b;
    b = t;
  }

  long long ans = a;
  while (ans % b != 0) {
    ans += a;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc087/tasks/abc087_b
module Main

let a = stdin.ReadLine() |> int
let b = stdin.ReadLine() |> int
let c = stdin.ReadLine() |> int
let x = stdin.ReadLine() |> int

seq {
    for i = 0 to a do
        for j = 0 to b do
            for k = 0 to c do
                yield i * 500 + j * 100 + k * 50
}
|> Seq.sumBy (fun v ->
       if v = x then 1
       else 0)
|> printfn "%d"


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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;


int main() {
    int N; cin >> N;
    vi h(N);
    rep(i,N) cin >> h[i];
    int ans = h[0];
    rep(i,N-1){
        if(h[i+1] > h[i]) ans += h[i+1] - h[i];
    }

    cout << ans << endl;
  
}

Measured memory_bytes: 256
S = list(input())

if S == S[-1::-1]:
    if S[:(len(S) - 1) // 2] == S[(len(S) - 1) // 2 - 1::-1]:
        if S[(len(S) + 3) // 2 - 1:] == S[-1:(len(S) + 3) // 2 - 2:-1]:
            print("Yes")
            exit()

print("No")


Measured memory_bytes: 3060
#include <iostream>
 
using namespace std;
 
int main(){
    int X,Y,a=0;
    cin>>X>>Y;
    for(int i=0;i<=X;i++){
        if((X-i)*2+i*4==Y){
            a=1;
            break;
        }
    }
    if(a==1)printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int n,i,j,c;
    int x[4][14];  //二次元配列
    char m, d;
    
    //配列を初期化
    for(i=0; i<4; i++){
        for(j=0; j<14; j++){
            x[i][j]=0;
        }
    }
    
    scanf("%d",&c);
    for(i=0; i<c; i++){
        scanf("%c",&d);
        scanf("%c %d",&m,&n);
        if(m == 'S'){
            x[0][n] = 1;
        }
        if(m == 'H'){
            x[1][n] = 1;
        }
        if(m == 'C'){
            x[2][n] = 1;
        }
        if(m == 'D'){
            x[3][n] = 1;
        }
    }
    
    for(j=1; j<14; j++){
        if(x[0][j] != 1){
            printf("S %d\n",j);
        }
    }
    for(j=1; j<14; j++){
        if(x[1][j] != 1){
            printf("H %d\n",j);
        }
    }
    for(j=1; j<14; j++){
        if(x[2][j] != 1){
            printf("C %d\n",j);
        }
    }
    for(j=1; j<14; j++){
        if(x[3][j] != 1){
            printf("D %d\n",j);
        }
    }
    
    return 0;
}



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

const int maxn = 110;
int n, a[2][maxn], f[2][maxn];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < 2; i++) {
        for (int j = 1; j <= n; j++) {
            scanf("%d", &a[i][j]);
            f[i][j] = f[i][j - 1] + a[i][j];
            if (i) f[i][j] = max(f[i][j], f[i - 1][j] + a[i][j]);
        }
    }
    printf("%d\n", f[1][n]);
    return 0;
}

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

int main() {
    long long n,i,flag=0;
    cin>>n;
    for(i=1;i<=9;i++)
    {
        if(n%i==0)
        {
            if(n/i<=9&&n/i>=1)
            {
                flag=1;
                
            }
        }
    }
    if(flag==0)
        cout<<"No";
        else
        cout<<"Yes";
    
	return 0;
}

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

using namespace std;

#define mem(a,i) memset(a,i,sizeof(a))
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

int n,k;

int main() {
    while(~scanf("%d%d",&n,&k)) {
        if(2*k-1<=n) puts("YES");
        else puts("NO");
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public long[] A;
        public long MOD = 1000000007;

        public void Run()
        {
            N = Input.ReadInt();
            A = new long[N];
            for (int i = 0; i < N; i++)
            {
                A[i] = Input.ReadLong();
            }

            Array.Sort(A);

            var l1 = new List<long>();
            var l2 = new List<long>();

            var l = 0;
            var r = N - 1;

            for (int t = 0; t < N / 2; t++)
            {
                if (t % 2 == 0)
                {
                    l1.Add(A[l]);
                    l2.Add(A[r]);
                }
                else
                {
                    l1.Add(A[r]);
                    l2.Add(A[l]);
                }
                l++;
                r--;
            }

            long ret = 0;
            ret += Math.Abs(l1[0] - l2[0]);
            for (int i = 1; i < l1.Count; i++)
            {
                ret += Math.Abs(l1[i - 1] - l1[i]);
            }
            for (int i = 1; i < l2.Count; i++)
            {
                ret += Math.Abs(l2[i - 1] - l2[i]);
            }

            if (N % 2 == 1)
            {
                int m = N / 2;
                ret += Math.Max(Math.Abs(l1.Last() - A[m]), Math.Abs(l2.Last() - A[m]));
            }

            Console.WriteLine(ret);
        }
    }

    // libs ----------


    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}


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

int main(void){
    int A,B,C,D;
    cin >> A >> B>>C>>D;
    rep(i,250){
        C -= B;
        if(C<=0){
            printf("Yes");
            return 0;
        }
        A -= D;
        if(A<=0){
            printf("No");
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int h = std.nextInt();
        int w = std.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = std.nextInt();
            b[i] = std.nextInt();
        }

        int count = 0;
        for (int i = 0; i < n; i++) {
            int ai = a[i];
            int bi = b[i];
            if (ai >= h && bi >= w) {
                count++;
            }
        }

        System.out.println(count);
    }
}

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

int main() {
  int n, x; cin >> n >> x;
  vector<int> m(n);
  int sum = 0, minm = 1e+9;
  for (auto& e: m) {
    cin >> e;
    sum += e;
    minm = min(minm, e);
  }
  cout << n + (x - sum) / minm << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using namespace std;

void Main()
{
   int N, Q;
   std::cin >> N >> Q;
   string S;
   std::cin >> S;
   vector<int> AC(N);
   int ac = 0;
   for (int i = 0; i < N; i++)
   {
      if (S[i] == 'C' && S[i - 1] == 'A')
         ac++;
      AC[i] = ac;
   }
   int l, r;
   for (int q = 0; q < Q; q++)
   {
      std::cin >> l >> r;
      std::cout << (AC[r - 1] - AC[l - 1]) << endl;
   }
   return;
}

int main()
{
   std::cin.tie(nullptr);
   std::ios_base::sync_with_stdio(false);
   std::cout << std::fixed << std::setprecision(15);
   Main();
   return 0;
}

Measured memory_bytes: 1488
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
typedef long long ll;
#define INF (1e9+7) 
int main(){
    int n;
    cin >> n;
    vector<double> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());

    int ans1 = a[0];

    double line =(double) ans1 / 2;
    //line殿さが最も小さいのが答え

    for (int i = 1; i < n; i++)
    {   
        a[i] -= line;
    }
    int min_a = INF;
    int min_index = 0;
    for (int i = 1; i < n; i++)
    {
        if(abs(a[i])<min_a){
            min_a = abs(a[i]);
            min_index = i;
        }
    }
    int ans2 = a[min_index] + line;
    cout << ans1 << " " << ans2 << endl;


    return 0;
}

Measured memory_bytes: 1024
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
using namespace std; 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

bool *isprime;

bool isPrime(int n){
	if(n == 1){
		return false;
	}
	if(n == 2){
		return true;
	}
	if(n > 2 && n % 2 == 0){
		return false;

	}
	int i = 3;
	while(i <= (int)sqrt(n)){
		if(n % i == 0){
			return false;
		}
		i += 2;
	}
	return true;	
}

int main(){
	int count = 0;
	int n,num;
	cin >> n;
	rep(i,n){
		cin >> num;
		if(isPrime(num)){
			count++;
		}
	}
	P(count);
	return 0;
}

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

#define MOD (1000000007LL)

using namespace std;

const int denom = 1000;

int cntt[500000 / denom][26];
string S;

bool hoge(int n, int l, int r){
    int L = (l + denom) / denom;
    int R = (r + 1) / denom;
    // cout << L << " " << R << endl;
    for(int I = L; I < R; I++){
        if(cntt[I][n] > 0) return true;
    }
    for(int i = l; i <= min(r, L * denom); i++){
        // cout << "i: " << i << ", S[i]: " << S[i] << endl;
        if(S[i] == n + 'a') return true;
    }
    for(int i = max(l, R * denom); i <= r; i++){
        if(S[i] == n + 'a') return true;
    }
    // cout << "false" << endl;
    return false;
}

int main(void){
    int N;
    int Q;
    cin >> N >> S >> Q;

    for(int i = 0; i < N; i++){
        cntt[i / denom][S[i] - 'a']++;
    }

    for(int q = 0; q < Q; q++){
        int t;
        cin >> t;
        if(t == 1){
            int i;
            char c;
            cin >> i >> c;
            i--;
            cntt[i / denom][S[i] - 'a']--;
            cntt[i / denom][c - 'a']++;
            S[i] = c;
        }
        if(t == 2){
            int ans = 0;
            int l, r;
            cin >> l >> r;
            for(int i = 0; i < 26; i++){
                if(hoge(i, l - 1, r - 1)) ans++;
            }
            cout << ans << endl;
        }
    }
    
    // cout << S << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
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; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

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

vector<ll> sieve(ll n){
  vector<bool> is_prime(n+1,true);
  vector<ll> res;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      res.push_back(i);
      for(int j=2*i;j<=n;j+=i){
        is_prime[j] = false;
      }
    }
  }
  return res;
}

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

umap<int,int> prime_factor(ll n){
  umap<int,int> fac;
  for(int i=2;i*i<=n;i+=2){
    if(n%i == 0){
      int count = 0;
      while(n%i == 0){
        count++;
        n /= i;
      }
      fac[i] = count;
    }
  }
  if(n!=1)fac[n] = 1;
  return fac;
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  string s;
  int k;
  cin >> s;
  cin >> k;
  int n = s.length();
  set<string> group;
  REP(i,n){
    for(int j=1;j<=k;j++){
      if(i+j<=n){
        group.insert(s.substr(i,j));
      }
    }
  }
  auto itr = group.begin();
  REP(i,k-1){
    ++itr;
  }
  cout << *itr << endl;
  return 0;
}


Measured memory_bytes: 4816
#include <stdio.h>

int main(){
  int n,r,i,j,p,c,idx,now[50],next[50];
  while(1){
    scanf("%d%d",&n,&r);
    for(i = 0 ; i < n ; i++){ now[i] = n-i; }
    if(n == 0 && r == 0){ break; }
    for(i = 0 ; i < r ; i++){
      scanf("%d%d",&p,&c);
      idx = 0;
      for(j = p-1 ; j < p-1+c ; j++){
        next[idx] = now[j];
        idx++;
      }
      for(j = 0 ; j < n ; j++){
        if(p-1 > j || j >= p-1+c){
          next[idx] = now[j];
          idx++;
        }
      }
      for(j = 0 ; j < n ; j++){
        now[j] = next[j];
      }
    }
    printf("%d\n",now[0]);
  }
  return 0;
}

Measured memory_bytes: 600
import scala.io.StdIn.{readInt, readLine}
case class Node[T](data: Option[T], var prev: Node[T], var next: Node[T])
case class DoublyLinkedList[T]() {
    val n = new Node[T](None, null, null)
    def isEmpty(): Boolean = if (n.prev == null && n.next == null) true else false
    def insert(e: T): Unit = {
        if (isEmpty) {
            val newNode = new Node(Option(e), n, n)
            n.next = newNode
            n.prev = newNode
        } else {
            val newNode = new Node(Option(e), n, n.next)
            n.next.prev = newNode
            n.next = newNode
        }
    }
    def delete(e: T): Unit = {
        def find(node: Node[T]): Node[T] = node.next match {
            case a if a.data.isEmpty => null
            case a if a.data.get == e => a 
            case a => find(a)
        }
        if (!isEmpty) {
            val target = find(n)
            if (target != null) {
                val targetNext = target.next
                val targetPrev = target.prev
                if (targetNext eq targetPrev) {
                    n.prev = null
                    n.next = null
                } else {
                    targetPrev.next = targetNext
                    targetNext.prev = targetPrev
                }
            }
        }
    }
    def deleteFirst(): Unit = {
        if (!isEmpty) {
            val targetNext = n.next.next
            if (n eq targetNext) {
                n.prev = null
                n.next = null
            } else {
                n.next = targetNext
                targetNext.prev = n
            }
        }
    }
    def deleteLast(): Unit = {
        if (!isEmpty) {
            val targetPrev = n.prev.prev
            if (n eq targetPrev) {
                n.prev = null
                n.next = null
            } else {
                n.prev = targetPrev
                targetPrev.next = n
            }
        }
    }
    def printList(): Unit = {
        if (isEmpty) {
            println()
        } else {
            def go(node: Node[T], list: List[T]): List[T] = node.prev match {
                case a if a.data.isEmpty => list
                case a => go(a, a.data.get :: list)
            }
            println(go(n, Nil).mkString(" "))
            
        }
    }
}
object Main {
    def main(args: Array[String]): Unit = {
        val list = DoublyLinkedList[String]()
        for (i <- (1 to readInt)) {
            val input = readLine.split(" ") 
            if (input(0) == "insert") list.insert(input(1))
            else if (input(0) == "delete") list.delete(input(1))
            else if (input(0) == "deleteFirst") list.deleteFirst()
            else if (input(0) == "deleteLast") list.deleteLast()
        }
        list.printList()
    }
}


Measured memory_bytes: 529892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,m;
	cin>>n>>m;
	if(n==1 && m==1){
		cout<<1;
		return 0;
	}
	if(n==1){
		cout<<m-2;
		return 0;
	}
	if(m==1){
		cout<<n-2;
		return 0;
	}
	cout<<n*m-(2*n+2*m-4);
}


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

#define BIG 2000000007

#define MOD 1000000007
typedef unsigned long long ull;
typedef   signed long long sll;

typedef struct {
	ull above;
	ull below;
	int index;
} hw;

#define N_MAX 100000
#define M_MAX 100000

ull n, m, k;
ull h, w;
ull a[N_MAX];
// ull b[N_MAX];
// ull dp[N_MAX][M_MAX + 1];
// char s[N_MAX + 1];

void swap_adj(ull *a, ull *b){
	ull tmp = *b;
	*b = *a;
	*a = tmp;
	return;
}

int comp(const void *a, const void *b){
	if (*(ull*)a > *(ull*)b) {
		return -1;
	} else if (*(ull*)a < *(ull*)b) {
		return +1;
	} else {
		return 0;
	}
}

ull divide(ull a, ull b){
	ull x = MOD - 2;
	ull ans = 1;
	while (x) {
		if (x & 1) ans = (ans * b) % MOD;
		b = (b * b) % MOD;
		x /= 2;
	}
	return (a * ans) % MOD;
}

int digits(ull x){
	int i = 1;
	while (x >= 10) {
		x /= 10;
		i++;
	}
	return i;
}

int min(ull x, ull y){
	return (x < y) ? x : y;
}

ull gcd(ull x, ull y){
	if (x < y) {
		return gcd(y, x);
	} else if (y == 0) {
		return x;
	} else {
		return gcd(y, x % y);
	}
}

ull solve(){
	int i, j;

	qsort(a, n, sizeof(ull), comp);
	ull left = 0, right = 0;

	for (i = 1; i < n; i++) {
		if (a[i - 1] == a[i]) {
			if (left == 0) {
				left = a[i];
				i++;
			} else {
				right = a[i];
				break;
			}
		}
	}

	printf("%llu\n", left * right);

	return 0;
}

int main(void){
	int i, j;

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

	solve();

	return 0;
}


Measured memory_bytes: 1660
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;

#define m(a,b) memset(a,b,sizeof(a));
typedef long long ll;
const int MAXN=1e5+100;

int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if (a+b==c+d) printf("Balanced\n");
	else if (a+b>c+d) printf("Left\n");
	else printf("Right\n");
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.nextLine().toCharArray();
		char[] t = sc.nextLine().toCharArray();
		int[] a = new int[26];
		int[] b = new int[26];
		for (int i = 0; i < s.length; i++) {
			a[s[i] - 'a']++;
		}
		for (int i = 0; i < t.length; i++) {
			b[t[i] - 'a']++;
		}

		Arrays.sort(a);
		Arrays.sort(b);
		for (int i = 0; i < a.length; i++) {
			if (a[i] != b[i]) {
				System.out.println("No");
				return;
			}
		}

		System.out.println("Yes");
	}
}


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

using namespace std;

int a[100010], b[100010], c[100010];

int main ()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i = 0;i < n;i++)
        cin >> a[i];
    for(int i = 0;i < n;i++)
        cin >> b[i];
    for(int i = 0;i < n;i++)
        cin >> c[i];
    sort(a, a+n);
    sort(b, b+n);
    sort(c, c+n);
    long long ans = 0;
    for(int i = 0;i < n;i++)
    {
        int d1, d2;
        d1 = lower_bound(a, a+n, b[i]) - a;
        d2 = upper_bound(c, c+n, b[i]) - c;
        long long num1,num2;
        num1 = d1;
        num2 = n-d2;
        ans += num1*num2;
    }
    printf("%lld\n", ans);
    return 0;
}


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

main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto& a : A) {
    cin >> a;
  }
  sort(begin(A), end(A), greater<>());
  int d = 0;
  int sign = 1;
  for (auto a : A) {
    d += sign * a;
    sign -= 2*sign;
  }
  cout << d << endl;
}

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

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

string S;
int main(){

    cin >> S;

    int bc = 0;
    ll ans = 0;
    for(int i = (int)S.size() - 1; i>= 0; i--){
        if(i - 1 >= 0 && S[i] == 'C' && S[i-1] == 'B'){
            bc++;
            i--;
        }
        else if(S[i] == 'A'){
            ans += bc;
        }
        else{
            bc = 0;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;

class UnionFind {
public:
    vector <int> par; // 各元の親を表す配列
    vector <int> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(int sz_): par(sz_), siz(sz_, 1) {
        for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(int sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);
        for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    int root(int x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(int x, int y) { // 連結判定
        return root(x) == root(y);
    }

    int size(int x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int N, M;
    cin >> N >> M;
    int A[N];
    rep(i,N){
      cin >> A[i];
      --A[i];
    }
    UnionFind uf(N);
    rep(i,M){
      int a, b;
      cin >> a >> b;
      --a; --b;
      uf.unite(a, b);
    }
    int ans = 0;
    rep(i,N){
      if(uf.root(i) == uf.root(A[i])) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main (){
        ll rr, cc; cin >> rr >> cc;
        ll r, c; cin >> r >> c;
        ll res = rr*cc - r*cc - c*rr + r*c; cout << res << endl;
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>

using namespace std;

int main(){
	int h,w,n;
	int black = 0;
	int count = 0;
	cin >> h;
	cin >> w;
	cin >> n;
	
	while(black < n){
		if(h < w){
			black += w;
			count++;
			h--;
			if(h == 0){
				break;
			}
		}else{
			black += h;
			count++;
			w--;
			if(w == 0){
				break;
			}
		}
	}
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int R;
    cin >> R;
    if(R<1200)
    {
        cout << "ABC";
    }
    else if(R<2800)
    {
        cout << "ARC";
    }
    else
    {
        cout <<"AGC";
    }
    return 0;
}

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

using namespace std;

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

	int n, m;
	cin >> n >> m;

	vector<long long> cost(m + 1);
	vector<int> v[m+1];
	int b;

	for(int i = 1; i <= m; i++) {
		cin >> cost[i] >> b;
		while(b--) {
			int a;
			cin >> a;
			v[i].push_back(a-1);
		} 
	}



	vector<vector<long long>> dp(m+1, vector<long long>(1 << n, 1e18));

	dp[0][0] = 0;

	for(int i = 1; i <= m; i++) {
		for(int j = 0; j < (1<< n); j++) {
			int x = j;
			for(auto k : v[i]) {
				if(x & (1 << k)) x -= (1<<k);
			}
			dp[i][j] = min(dp[i-1][j], cost[i] + dp[i][x]);
		}
	}

	long long  res = dp[m][(1<<n) - 1];
	if(res == (1e18)) {
		cout << -1;
	}
	else cout << res;

	return 0;
}


Measured memory_bytes: 32512
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 8005;

vector<int> arr;
int dp[MAXN][2*MAXN];

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

	string str;
	cin >> str;
	arr.push_back(0);
	for (int i = 0; i < (int)str.length(); i++) {
		if (str[i] == 'T') arr.push_back(0);
		else arr.back()++;
	}
	int N = arr.size();

	int x, y;
	cin >> x >> y;


	if (arr.size() == 1) {
		if (x == arr[0]) {
			cout << "Yes\n";
		} else {
			cout << "No\n";
		}
		return 0;
	}

	x -= arr[0];
	x += MAXN; y += MAXN;
	dp[0][MAXN] = dp[1][MAXN+arr[1]] = dp[1][MAXN-arr[1]] = 1;
	for (int pos = 2; pos < N; pos++) {
		for (int rem = 0; rem < 2*MAXN; rem++) {
			int &ret = dp[pos][rem];
			ret = 0;
			if (rem + arr[pos] < 2*MAXN) ret |= dp[pos-2][rem+arr[pos]];
			if (rem - arr[pos] >= 0) ret |= dp[pos-2][rem-arr[pos]];
		}
	}
	if (N&1) {
		if (dp[N-1][x] && dp[N-2][y]) {
			cout << "Yes\n";
		} else {
			cout << "No\n";
		}
	} else {
		if (dp[N-1][y] && dp[N-2][x]) {
			cout << "Yes\n";
		} else {
			cout << "No\n";
		}
	}
}

Measured memory_bytes: 497920
#include <bits/stdc++.h>
#define pvar(x) clog << "[" << #x << ":" << x << "]\n"
using namespace std;
using ll = long long int;
// r - 0 w-1
void solve() {
  int n;
  char c;
  cin >> n;
  vector<bool> v(n);
  for (int i = 0; i < n; i++) {
    cin >> c;
    if (c == 'R')
      v[i] = 0;
    else
      v[i] = 1;
  }
  int l = 0, r = n - 1, cnt = 0;
  while (l < r) {
    if (v[l] == 1 && v[r] == 0) {
      ++cnt;
      l++, r--;
    } else if (v[l] == 0)
      ++l;
    else if (v[r] == 1)
      --r;
  }
  cout << cnt;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}


Measured memory_bytes: 3688
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
  int ans = 0;
  int ma = 0;
  int n;cin >> n;
  for(int i = 0;i<n;i++) {
    char c;cin >> c;
    if(c=='I') ans++;
    else ans--;
    ma=max(ma,ans);
  }
  cout << ma << endl;
}

Measured memory_bytes: 3612
@d = gets.to_i
@c = gets.split.map &:to_i
@s = @d.times.map { gets.split.map &:to_i }

def score(schedule, range = 0...@d, last = [0] * 26)
  sat = 0
  range.each do |day|
    type = schedule[day]
    sat += @s[day][type]
    day += 1
    last[type] = day
    sat -= 26.times.sum { |i, day_last| @c[i] * (day - last[i]) }
  end
  sat
end

# greedy part

schedule = [0] * @d
last = [0] * 26
score = nil
@d.times do |day|
  s_max, i_max = -10000000, 0
  26.times do |i|
    schedule[day] = i
    s = score(schedule, day..day, last.dup)
    s_max, i_max = s, i if s > s_max
  end
  schedule[day] = i_max
  score = s_max
  last[i_max] = day + 1
end

# climbing part

10.times do
  day = rand @day
  type = rand 26
  prev = schedule[day]
  schedule[day] = type
  s = score(schedule)
  if s > score
    score = s
  else
    schedule[day] = prev
  end
end

schedule.each do |type|
  p type + 1
end


Measured memory_bytes: 14716
import math
from functools import reduce
# def gcd(*numbers):
#     return reduce(math.gcd, numbers)

k = int(input())
res = 0
for c in range(1,k+1):
    for b in range(1,k+1):
        gcd_cd = math.gcd(c,b)
        for a in range(1,k+1):
            # res += gcd(a,b,c)
            gcd_abc = math.gcd(a,gcd_cd)
            res += gcd_abc
print(res)

Measured memory_bytes: 9548
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const double PI = acos(-1);
const long long INF = (1 << 30);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  double r;
  cin >> r;
  printf("%.16f\n", 2*PI*r);
  return 0;
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
//#include<ext/rope>
//using namespace __gnu_cxx
//#include<ext/pb_ds/priority_queue.hpp>
//using namespace __gnu_pbds;
#define lowbit(x) (x&-x)
#define pb push_back
#define empb emplace_back
#define all(x) (x).begin(),(x).end()
#define clr(a,b) memset(a,b,sizeof(a))
#define caze(T) for(cin>>T;T;T--)
#define inf (1<<29)
#define Endl ('\n')
#define fi first
#define se second
#define db double
#define ldb long double
#define ll long long
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define ull unsigned long long
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
inline char nc() {
	#define SZ 1000000
	static char buf[SZ], *p1, *p2;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,SZ,stdin),p1==p2)?EOF:*p1++;
}
template<typename T>
inline int scan(T &x) {
	char c, sign=1; 
	while(!isdigit(c=nc())&&c!=EOF)if(c=='-')sign*=-1;
	if(c==EOF) return EOF;
	for(x = 0; isdigit(c); c = nc())
		x = (x<<1) + (x<<3) + (c&15);
	return x *= sign, 1;
}
template<typename T, typename...Args>
inline int scan(T &x, Args&...args) {
	return scan(x), scan(args...);
}
const int N=1<<18;
const int zero=1<<17;
int t[N],a[N],n;
void add(int x,int v){for(;x<N;t[x]+=v,x+=lowbit(x));}
int sum(int x){int ret=0;while(x)ret+=t[x],x-=lowbit(x);return ret;}
int sum(int l,int r){return sum(r)-sum(l-1);}
ll calc(int x)
{
	int y=zero;
	ll ret=0;
	clr(t,0);
	add(zero,1);
	for(int i=1;i<=n;++i)
	{
		y+=(a[i]<=x?1:-1);
		ret+=sum(y-1);
		add(y,1);
	}
	return ret;
} 
int main()
{IOS;
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	int L=1,R=1000000000,mid;
	ll ans,tp;
	ll ok=1LL*(n+1)*n/4+1;
	while(R>=L)
	{
		mid=(L+R)>>1;
		if((tp=calc(mid))>=ok)
			ans=mid,R=mid-1;
		else L=mid+1;
	}
	cout<<ans<<Endl;
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;

    if (a % 2 == 0 && b % 2 == 0 || a % 2 != 0 && b % 2 != 0 ){
        cout << "Alice" << endl;
    } else {
        cout << "Borys" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e5 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	//ifstream cin (".in");
	//ofstream cout (".out");
    int n;
    cin >> n;
    bool ans = false;
    for(int i=1; i<10; i++){
    	for(int j=1; j<10; j++){
    		if(i*j == n){
    			ans = true;
    		}
    	}
    }
    if(ans == true){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }
    return 0;

}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdlib>
#include <list>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
 
int main(void)
{
    int64_t A, B, C, K;
    cin >> A >> B >> C >> K;

    if (A>=K)
    {
        cout << K;
    }
    else if (A + B >= K)
    {
        cout << A;
    }
    else {
        cout << (A - (K - (A + B)));
    }

    return 0;
}


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

#define r(i,n) for(int i=0;i<n;i++)
#define fi first
#define se second

using namespace std;
typedef pair<int,int>P;

int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int dx1[]={-1,-1,-1,0,0,1,1,1};
int dy1[]={-1,0,1,-1,1,-1,0,1};
int h,w;
char S,T;

vector<int>v[1000];

int sx,sy,gx,gy;
string s[100];

void INPUT(){

  cin>>h>>w>>S>>T; 

  r(i,h)cin>>s[i];

  r(i,h)r(j,w){
    if(s[i][j]==S)sx=j,sy=i;
    if(s[i][j]==T)gx=j,gy=i;
  }
}

void make_GRAPH(){
  r(i,h)r(j,w)if('A'<=s[i][j]&&s[i][j]<='Z'){
    r(k,4){
      int x=j+dx[k]+dx[k];
      int y=i+dy[k]+dy[k];
      if(x<0||y<0||x>=w||y>=h)continue;
      if(k%2==1&&s[y][x]=='|')continue;
      if(k%2==0&&s[y][x]=='-')continue;

      if(k%2==1&&s[y][x]=='-'){
        while(s[y][x]=='-'){
          y+=dy[k];
          x+=dx[k];
        }
        y+=dy[k];
        x+=dx[k];
        v[s[i][j]-'A'].push_back(s[y][x]-'A');
      }

      else if(k%2==0&&s[y][x]=='|'){
        while(s[y][x]=='|'){
          y+=dy[k];
          x+=dx[k];
        }
        y+=dy[k];
        x+=dx[k];
        v[s[i][j]-'A'].push_back(s[y][x]-'A');
      }

    }
  }
}
bool used[100009];
int d[100005];

void BFS(){

  queue<P>q;

  q.push(P(s[sy][sx]-'A',0));
  used[s[sy][sx]-'A']=1;

  while(!q.empty()){
    P p=q.front();q.pop();
    int x=p.first;
    int cost=p.second;
    d[x]=cost;
    r(i,v[x].size()){
      int next=v[x][i];
      if(!used[next]){
        used[next]=1;
        q.push(P(next,cost+1));
      }
    }
  }
  cout<<d[s[gy][gx]-'A']<<endl;
}

int main(){
  INPUT();
  make_GRAPH();
  BFS();
}


Measured memory_bytes: 3264
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

s = ri()
print(['Christmas Eve Eve Eve', 'Christmas Eve Eve', 'Christmas Eve', 'Christmas'][s-22])














Measured memory_bytes: 27004
#include <stdio.h>
#define MAX_SIZE 3

int main(void)
{
	int a[MAX_SIZE][MAX_SIZE];
	int b, n;
	int i, j, k;

	/* ビンゴカードに数字を書く */
	for (i = 0; i < MAX_SIZE; i++)
	{
		for (j = 0; j < MAX_SIZE; j++)
		{
			scanf("%d", &a[i][j]);
		}
	}

	/* n個の数を選ぶ */
	scanf("%d", &n);

	for (k = 0; k < n; k++)
	{
		scanf("%d", &b);
		/* 選ばれた数に印を付ける */
		for (i = 0; i < MAX_SIZE; i++)
		{
			for (j = 0; j < MAX_SIZE; j++)
			{
				if (b == a[i][j]) {
					a[i][j] = -1;
				}
			}
		}
	}

	/* 横列のビンゴを確認する */
	for (i = 0; i < MAX_SIZE; i++)
	{
		if (a[i][0] == a[i][1] && a[i][1] == a[i][2])
		{
			printf("Yes\n");
			return 0;
		}
	}

	/* 縦列のビンゴを確認する */
	for (i = 0; i < MAX_SIZE; i++)
	{
		if (a[0][i] == a[1][i] && a[1][i] == a[2][i])
		{
			printf("Yes\n");
			return 0;
		}
	}

	/* 斜めのビンゴを2通り確認する */
	if (a[0][0] == a[1][1] && a[1][1] == a[2][2])
	{
		printf("Yes\n");
		return 0;
	}

	if (a[0][2] == a[1][1] && a[1][1] == a[2][0])
	{
		printf("Yes\n");
		return 0;
	}

	printf("No\n");

	return 0;
}

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

int main() {
  char X,Y;
  cin>>X>>Y;
  if(X>Y){
    cout<<">"<<endl;
  }
  else if(X==Y){
    cout<<"="<<endl;
  }
  else if(X<Y){
    cout<<"<"<<endl;
  }
}

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

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

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

  int m;
  cin >> m;
  cout << 24 + (24 - m) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mo 1000000007
#define P 50
#define N 53
using namespace std;
int n;
ll jie[N],nj[N],dp[N][N*2];
ll po(ll x,ll y){ll z=1;while (y){if (y%2)z=x*z%mo;x=x*x%mo;y/=2;}return z;}
void add(ll &x,ll y){x=(x+y)%mo;}
ll C(ll x,ll y){return (jie[x]*nj[y]%mo)*nj[x-y]%mo;}
int main(){
	cin>>n;
	jie[0]=1;for (int i=1;i<=n;i++)jie[i]=jie[i-1]*i%mo;
	nj[n]=po(jie[n],mo-2);for (int i=n-1;i>=0;i--)nj[i]=nj[i+1]*(i+1)%mo;
	dp[1][0]=1;dp[1][1]=1;
	for (int i=1;i<n;i++)
		for (int j=0;j<=i;j++)
			for (int x=1-(j!=0);x*2+j+i<=n;x++)
				for (int y=-x;y<=x+j;y++)add(dp[x*2+i+j][abs(y)],(dp[i][j]*C(i+x+y,x+y)%mo)*C(x+x+i+j,x+j-y));	
	cout<<dp[n][0]<<endl;
	return 0;
}

Measured memory_bytes: 256