akhauriyash/Code-Regression huggingface dataset:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(N, K, inputs):
    rods = string_to_int(inputs[0])
    rods.sort()
    length = 0
    for i in range(K):
        length += rods.pop()
    return length


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    [N, K] = string_to_int(input())
    ret = solve(N, K, inputs(1))
    print(ret)


Measured memory_bytes: 38256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    long N = 1_000_000_007L;
    Scanner scanner = new Scanner(System.in);
    String str = scanner.next();

    long[][] d = new long[str.length() + 1][4];
    d[0][0] = 1;
    for (int i = 1; i <= str.length(); i++) {
      char ch = str.charAt(i - 1);

      int m = ch == '?' ? 3 : 1;
      d[i][0] = d[i - 1][0] * m % N;
      d[i][1] = d[i - 1][1] * m % N;
      d[i][2] = d[i - 1][2] * m % N;
      d[i][3] = d[i - 1][3] * m % N;
      switch (ch) {
        case 'A':
          d[i][1] += d[i - 1][0];
          break;
        case 'B':
          d[i][2] += d[i - 1][1];
          break;
        case 'C':
          d[i][3] += d[i - 1][2];
          break;
        case '?':
          d[i][1] += d[i - 1][0];
          d[i][2] += d[i - 1][1];
          d[i][3] += d[i - 1][2];
          break;
        default:
          throw new IllegalArgumentException();
      }

      for (int j = 0; j < 4; j++) {
        d[i][j] %= N;
      }
    }

    System.out.println(d[str.length()][3]);
  }
}


Measured memory_bytes: 32136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace AGC23_B_
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            char[][] m = new char[n][];
            for (int i = 0; i < n; i++)
            {
                m[i] = ReadLine().ToCharArray();
            }

            var ai = new List<int>();
            int flag1 = 0;
            int count = 0;
            for (int i = 0; i < n; i++)
            {
                flag1 = 0;
                for (int j = 0; j < n; j++)
                {
                    for (int k = 0; k < n; k++)
                    {
                        if (m[(j + i) % n][k] == m[(k + i) % n][j])
                        {
                            flag1++;
                        }
                    }
                }
                if (flag1 == n * n)
                {
                    count++;
                }
            }
            
            WriteLine(count * n);
        }
    }
}


Measured memory_bytes: 13268
#0-indexed
n = int(input())
L = [[]*n for i in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x,y = map(int,input().split())
        x-=1
        L[i].append((x,y))
#print(L)
ans = 0
for i in range(1<<n):
    bit = [(i>>j)&1 for j in range(n)]
    #print(bit)
    flag = True
    for j in range(n):
        if bit[j]:
            for x,y in L[j]:
                if bit[x] != y:
                    flag = False
                    break
            if not flag:
                break
    if flag:
        ans = max(ans,sum(bit))
print(ans)


Measured memory_bytes: 69060
import bisect
n=int(input())
l=list(map(int,input().split()))
l=sorted(l)
a=0
for i in range(n-2):
  for j in range(i+1,n-1):
    a=a+bisect.bisect_left(l,l[i]+l[j])-j-1
print(a)

Measured memory_bytes: 3188
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
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 (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll a, b; cin >> a >> b;

    cout << (a <= 5 ? 0 : (a >= 13 ? b : b/2)) << endl;
    
}


Measured memory_bytes: 256
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = list(map(int, input().split()))
    #a = [list(input().split()) for i in range(n)]
    #a = [int(input()) for i in range(n)]
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    l=int(input())
    print((l/3)**3)


if __name__ == '__main__':
    main()



Measured memory_bytes: 38256
main = do
  getLine 
  a <- map read . words <$> getLine 
  if elem 0 a 
    then print 0
    else print $ get $ solve a 1


mul :: Integer -> Integer -> Maybe Integer
mul n m
  | n*m <= 1000000000000000000 = Just (n*m)
  | otherwise = Nothing 

get :: Maybe Integer -> Integer
get (Just n) = n
get Nothing  = -1      

solve :: [Integer] -> Integer -> Maybe Integer
solve [] cur = Just cur
solve (fa:sa) cur = do
  p <- mul cur fa
  solve sa p

      
      


Measured memory_bytes: 64232
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)  //  rep
#define repr(i,a,n) for(int i=a;i>n;i--)  //  repリバース
#define leng(n) (int)(log10(n)+1)  //  桁数leng
#define INF 9000000000000000000 //  巨大数INF
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int r;
  cin >> r;
  if(r<1200) cout << "ABC" << endl;
  else if (r<2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
}

Measured memory_bytes: 256
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    lw = ""
    d = collections.defaultdict(list)
    for i in range(n):
        w = str(input().rstrip('\n'))
        if lw != "":
            if w[0] != lw or w in d:
                print("No")
                exit()
        lw = w[-1]
        d[w]
    print("Yes")


if __name__ == '__main__':
    slove()


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


int main(){
    int n;
    scanf("%d",&n);
    int a[n],cp[n];
    for(int i = 0; i < n; i++) scanf("%d",&a[i]);
    memcpy(cp, a, sizeof(int)*n);
    sort(cp, cp+n);
    int max1 = cp[n-1];
    int max2 = cp[n-2];
    for(int i = 0; i < n; i++){    
        if(a[i] < max1)printf("%d\n",max1);
        else printf("%d\n",max2); 
    }
}


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

int main(void){
  long int S,number,digit;
  scanf("%ld",&S);
  number = S;
  while(number!=0){
   number = number/10;
   ++digit;
  }
  int s[digit];
  for(int i = 0;i < digit;i++){
    s[i] = S/((int)pow(10, digit-i-1));
    S = S%((int)pow(10, digit-i-1));
  }
  int min = 753,X = 0;
  for(int i = 0;i < digit - 2; i++){
    X = s[i]*100 + s[i+1]*10 + s[i+2];
    if(min > abs(753 - X)){
      min = abs(753 - X);
    }
  }
  printf("%d\n",min);
  return 0;
}


Measured memory_bytes: 128
N, K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))

A_sort = sorted(A)
F_sort = sorted(F,reverse=True)

l = -1
r = 0
for i in range(N):
    r = max(r,A_sort[i]*F_sort[i])

def judge(c):
    s = 0
    for i in range(N):
        s += max(A_sort[i]-c//F_sort[i],0)
    return s <= K

while r-l > 1:
    c = (l+r)//2
    if judge(c):
        r = c
    else:
        l = c
print(r)

Measured memory_bytes: 121036
#include <stdio.h>

int main(void) 
{
	int n;
	int t, x, y;
	int i;
	int flag = 1;
	int* pflag = &flag;

	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%d %d %d", &t, &x, &y);
		if ( (t % 2) != ((x + y) % 2) || x + y > t) *pflag = 0;
	}

	if (flag) printf("Yes");
	else printf("No");

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin>>n;
    ll ans = 0;
    for(ll i = 1; i <= n; i++)
    {
        for(ll j = 1; j <= n; j++)
        {
            for(ll k = 1; k <= n; k++)
            {
                ans += gcd(i,gcd(j,k));
            }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 3652
import java.util.*;

class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                while(sc.hasNext()){
                        double[][] x = new double[4][2];
                        String[] s = sc.nextLine().split(",");
                        for(int i = 0; i < 4; i++){
                                for(int j = 0; j < 2; j++){
                                        x[i][j] = Double.parseDouble(s[i*2+j]);
                                }   
                        }   
                        System.out.println(judge(x) ? "YES": "NO");
                }   
                sc.close();
        }   
        static boolean vp(double[][] x){
                return (x[2][0]-x[1][0])*(x[3][1]-x[2][1])-(x[2][1]-x[1][1])*(x[3][0]-x[2][0]) > 0;
        }   
        static boolean judge(double[][] x){
                boolean flag = vp(x);
                for(int i = 0; i < 3; i++){
                        shift(x);
                        if(flag != vp(x)){
                                return false;
                        }   
                }   
                return true;
        }   
        static void shift(double[][] x){
                double[] _x = {x[3][0], x[3][1]};
                for(int i = 3; i > 0; i--){
                        x[i][0] = x[i-1][0];
                        x[i][1] = x[i-1][1];
                }   
                x[0][0] = _x[0];
                x[0][1] = _x[1];
        }   
}

Measured memory_bytes: 11000
def pow_mod(n, k, m):
    r = 1
    while k:
        if k & 1:
            r = (r * n) % m
        n = (n * n) % m
        k >>= 1
    return r

def comb(n, r):
    numerator, denominator = 1, 1
    for i in range(n - (r - 1), n + 1):
        numerator = (numerator * i) % (10**9 + 7)
    for i in range(1, r + 1):
        denominator = (denominator * i) % (10**9 + 7)
    inv = pow(denominator, 10**9 + 7 - 2, 10**9 + 7)
    return (numerator * inv) % (10**9 + 7)

def mod_minus(a, b, m):
    if a < b:
        return a + m - b
    else:
        return a - b

n, a, b = map(int, input().split())
count = pow_mod(2, n, 10**9 + 7) - 1
count = mod_minus(count, comb(n, a), 10**9 + 7)
count = mod_minus(count, comb(n, b), 10**9 + 7)
print(count)

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

int main(void){
   int x,y;
   while(true) {
       cin >> x;
       cin >> y;
       if(x == 0 && y == 0) {
           break;
       }
       if(x < y) {
           cout << x << " " << y << endl;
       }
       else {
           cout << y << " " << x << endl;
       }
   }
}


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


int main()
{
	int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin >> k;
	cout << a[k-1] << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<cctype>
#include<map>
#include<set>
#include<deque>
#include<iomanip>
typedef long long LL;
using namespace std;
int a[102][102];
int dp[102][102];
int main()
{
	int n;
	cin>>n;
    for(int i = 1;i<=2;i++)
    {
    	for(int j = 1;j<=n;j++)
    	{
    		cin>>a[i][j];
		}
	}
	dp[1][1] = a[1][1];
	for(int i = 1;i<=2;i++)
	{
		for(int j = 1;j<=n;j++)
		{
			if(i==1)dp[i][j]=dp[i][j-1]+a[i][j];
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1])+a[i][j];
		}
	}
	cout<<dp[2][n]<<endl;
	return 0;
}

Measured memory_bytes: 256
Sa = input().strip()
Sb = input().strip()
Sc = input().strip()

sa = list(Sa[::-1])
sb = list(Sb[::-1])
sc = list(Sc[::-1])

turn = 'a'
while True:
  if turn=='a' and len(sa)==0:
    print('A')
    break
  elif turn=='b' and len(sb)==0:
    print('B')
    break
  elif turn=='c' and len(sc)==0:
    print('C')
    break

  if turn=='a':
    turn = sa.pop()
  elif turn=='b':
    turn = sb.pop()
  elif turn=='c':
    turn = sc.pop()

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

int Partition(vector<int> &A, int p, int r)
{
	int x = A[r];
	int i = p-1;
	for(int j = p; j < r; j++){
		if(A[j] <= x){
			i++;
			swap(A[i], A[j]);
		}
	}
	swap(A[i+1], A[r]);
	return i+1;
}

void OutputWithSpace(int C){
	cout << C << ' ';
}
void OutputWithEndl(int C){
	cout << C << endl;
}
void OutputWithSpaceAndBracket(int C){
	cout << '[' << C << "] ";
}
void OutputWithSpaceAndEndl(int C){
	cout << '[' << C << ']' << endl;
}

int main()
{
	int n;
	cin >> n;
	vector<int> A(n);
	for(int i = 0; i < n; i++){
		cin >> A[i];
	}
	int q = Partition(A, 0, n-1);
	for(int i = 0; i < n; i++){
		if(i != q && i != n-1){
			OutputWithSpace(A[i]);
		}else if(i == q && i != n-1){
			OutputWithSpaceAndBracket(A[i]);
		}else if(i != q && i == n-1){
			OutputWithEndl(A[i]);
		}else{
			OutputWithSpaceAndEndl(A[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 3084
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

const int N = 2e5 + 5;

int n;
int arr[N];

ll memo[N][3];
ll dp(int now, int skip){
    if(now > n){
        if(skip <= 1)return 0;
        else return -INF;
    }

    ll& ret = memo[now][skip];
    if(ret != -1)return ret;

    ret = dp(now+2, skip) + arr[now];
    if(skip > 0){
        ret = max(ret, dp(now+1, skip-1));
    }

    return ret;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);

    cin>>n;
    REP(i,1,n)cin>>arr[i];

    memset(memo, -1, sizeof memo);
    cout << dp(1, (n&1) ? 2 : 1) << endl;

    return 0;
}


Measured memory_bytes: 13764
r, g, b, n = gets.chomp.split(' ').map(&:to_i)
min, mid, max = [r, g, b].sort

max_max_count = n / max
mid_max_count = n / mid

count = 0
max_count = max_max_count
while max_count >= 0 do
  mid_count = 0
  while mid_count <= mid_max_count do
    rest = n - max * max_count - mid * mid_count
    break if rest < 0
    count += 1 if rest % min == 0
    mid_count += 1
  end
  max_count -= 1
end

puts count


Measured memory_bytes: 1788
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
using namespace std;
int main()
{
  int w,h;
  for(;cin>>w>>h,w;)
    {
      char maps[h][w];
      vector<pair<int,int> > dast;
      int sx,sy;
      for(int i=0;i<h;i++)
	for(int j=0;j<w;j++)
	  {
	    cin>>maps[i][j];
	    if(maps[i][j]=='*')
	      {
		dast.push_back(make_pair(i,j));
	      }
	    else if(maps[i][j]=='o')
	      {
		sx=i;
		sy=j;
	      }
	  }
      //now,bit;
      map<pair<pair<int,int>,int>,bool >hash;
      //now, bit,cnt;
      queue<pair< pair<int,int>,pair<int,int> > >qu;
      qu.push(make_pair(make_pair(sx,sy),make_pair(0,0)));
      int ans=-1;
      int size=dast.size();
      int dx[]={1,-1,0,0};
      int dy[]={0,0,1,-1};
      //cout<<"lastbit:"<<((1<<(size))-1)<<endl;
      //      qu.pop();
      while(!qu.empty())
	{
	  pair<int,int> now=qu.front().first;
	  int x=now.first;
	  int y=now.second;
	  int bit=qu.front().second.first;
	  int cnt=qu.front().second.second;
	  qu.pop();
	  //	  cout<<"now: "<<x<<" "<<y<<" "<<bit<<" "<<cnt<<endl;
	  if(maps[x][y]=='*')
	    {
	      for(int i=0;i<size;i++)
		{
		  if(x==dast[i].first &&y==dast[i].second )
		    bit=bit|(1<<i);
		}
	    }
	  if(bit==(1<<size)-1)
	    {
	      ans=cnt;
	      break;
	    }
	  if(hash.count(make_pair(now,bit))!=0)
	    continue;
	  hash[make_pair(now,bit)]=true;
	  for(int i=0;i<4;i++)
	    {
	      if(x+dx[i]>=0 &&x+dx[i]<h &&
		 y+dy[i]>=0 &&y+dy[i]<w &&
		 maps[x+dx[i]][y+dy[i]]!='x' &&
		 hash.count(make_pair(make_pair(x+dx[i],y+dy[i]),bit))==0
		 )
		qu.push(make_pair(make_pair(x+dx[i],y+dy[i]),make_pair(bit,cnt+1)));

	    }
	}
      cout<<ans<<endl;
    }
}

Measured memory_bytes: 6636
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n = gets.to_i

print "#{a[n-1]}\n"

Measured memory_bytes: 1788
n = int(input())
a = list(map(int, input().split()))
from collections import defaultdict
d = defaultdict(int)

ans=1
for num in a:
    if num==0:
        last_cnt=3
    else:
        last_cnt=d[num-1]

    tmp = last_cnt - d[num]
    if tmp < 0:
        tmp=1
    ans*=tmp
    ans%=1000000007
    d[num]+=1

print(ans)

Measured memory_bytes: 62252
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

char S[101010];

int L;
bool vis[26];

bool solve()
{
	// first wins?
	bool flg = false;
	for (int i = 1; i < L - 1; ++i) {
		if (S[i - 1] != S[i + 1]) flg = true;
	}
	if (!flg) return false;

	for (int i = 0; i < L; ++i) vis[S[i] - 'a'] = true;
	int ki = 0;
	for (int i = 0; i < 26; ++i) if (vis[i]) ++ki;

	int eff = L - (S[0] == S[L - 1] ? 1 : 0);
	return eff % 2 == 1;
}

int main()
{
	scanf("%s", S);
	L = strlen(S);
	puts(solve() ? "First" : "Second");
	return 0;
}


Measured memory_bytes: 384
var s,s1:ansistring;
var n,i,j,k,l:longint;
begin
  s1:='';
  readln(s);
  for i:=1 to 2 do
    for j:=1 to 2 do
      for k:=1 to 2 do
        for l:=1 to 2 do
        begin
          s1:='';
          if i=1 then s1:=s1+'A';s1:=s1+'KIH';
          if j=1 then s1:=s1+'A';s1:=s1+'B';
          if k=1 then s1:=s1+'A';s1:=s1+'R';
          if l=1 then s1:=s1+'A';
          if s1=s then begin writeln('YES');exit;end;
        end;
  writeln('NO');
end.

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

#define HEAP_SIZE 2000000
long int heap[HEAP_SIZE+1];
int heap_size;

void maxHeapify(long int heap[], int i)
{
	int l = i * 2;
	int r = i * 2 + 1;
	int largest;
	long int w;

	if((l <= heap_size) && (heap[l] > heap[i])){
		largest = l;
	}else{
		largest = i;
	}
	if((r <= heap_size) && (heap[r] > heap[largest])){
		largest = r;
	}
	if(largest != i){
		w = heap[i];
		heap[i] = heap[largest];
		heap[largest] = w;
		maxHeapify(heap, largest);
	}

	return;
}

void heapIncreaseKey(long int heap[], int i, long int key)
{
	int w;
	if(key < heap[i]){
		return;
	}
	heap[i] = key;
	while(i > 1 && heap[i / 2] < heap[i]){
		w = heap[i / 2];
		heap[i / 2] = heap[i];
		heap[i] = w;
		i = i / 2;
	}
	return;
}

void maxHeapInsert(long int heap[], long int key)
{
	heap_size = heap_size + 1;
	heap[heap_size] = -1;
	heapIncreaseKey(heap, heap_size, key);
	return;
}

long int heapExtractMax(long int heap[])
{
	long int max;
	if(heap_size < 1){
		return(-1);
	}
	max = heap[1];
	heap[1] = heap[heap_size];
	heap_size = heap_size - 1;
	maxHeapify(heap, 1);
	return(max);
}

int main()
{
	char cmd[30];
	long int key;

	do{
		scanf("%s", cmd);
		if(strcmp("insert", cmd) == 0){
			scanf("%ld", &key);
			maxHeapInsert(heap, key);
		}else if(strcmp("extract", cmd) == 0){
			printf("%ld\n", heapExtractMax(heap));
		}
	}while(strcmp("end", cmd) != 0);

	return(0);
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

struct Point {
    double x, y;

    Point(double x = 0.0, double y = 0.0) : x(x), y(y) {}
    Point(const Point& p) : x(p.x), y(p.y) {}

    static double dist(const Point& p1, const Point& p2) {
        return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
    }
};

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

    int n;
    cin >> n;

    vector<Point> p(n);
    rep(i, 0, n) { cin >> p[i].x >> p[i].y; }

    double ans = 0.0;
    rep(i, 0, n - 1) {
        rep(j, i + 1, n) { ans += Point::dist(p[i], p[j]); }
    }
    ans *= 2 / double(n);
    printf("%.10f\n", ans);

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vint;
typedef vector<ll> vll;

int n;
vint a(100010,0);

int main(){
    cin>>n;
    int tmp;
    for(int i=0; i<n; i++){
        cin>>tmp; tmp++;
        a[tmp]+=1;
        a[tmp+1]+=1;
        a[tmp-1]+=1;
    }
    sort(a.begin(), a.end(), greater<int>());
    cout<<a[0]<<endl;
    return 0;
}

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

int main(void) {
    int l[50];
    int K, N;
    
    cin >> N >> K;

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

    sort(l, l + N, greater<int>());

    int ans = 0;
    for (int i = 0; i < K; ++i) {
        ans += l[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <cassert>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using ld = long double;

#define st first
#define nd second

const int MAXN = 3e3 + 5, inf = 1e9;
const ll INF = 1e18, mod = 1e9 + 7;
const ld PI = 3.1415926535897932384626433832795;

int cnt[MAXN];
ll dp[MAXN][MAXN];
bool vis[MAXN], used[MAXN], av[MAXN][MAXN];

vector<int> G[MAXN];
vector<ll> V;
set<ll> S;
map<ll, int> M;
stack<ll> St;
queue<ll> Q;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(13) << fixed;

    //////////////////////////////////////////
    //////////////////////////////////////////

    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            char c;
            cin >> c;
            if (c == '.') {
                av[i][j] = 1;
            }
        }
    }

    dp[0][1] = av[0][1] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] = (dp[i - 1][j] * av[i - 1][j] + dp[i][j - 1] * av[i][j - 1])  %mod;
        }
    }

    cout << dp[n][m] << "\n";
}


Measured memory_bytes: 28928
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
using namespace std;
int mincost[10][10];
int main(void){
	int i,j,H,W;
	cin >> H >> W;
	int A[H][W];
	int c[10][10];
	int mincost [10][10];
	for(i=0;i<10;i++){
		for(j=0;j<10;j++){
			cin >> c[i][j];
			mincost[i][j] = c[i][j];
		}
	}
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			cin >> A[i][j];
		}
	}
	for(int k1=0;k1<=9;k1++){//iから1に向かうときのコストをmin求める ワーシャルフロイド法
		for(int k2=0;k2<=9;k2++){
			for(int k3=0;k3<=9;k3++){
				mincost[k2][k3]=min(mincost[k2][k3],mincost[k2][k1]+mincost[k1][k3]);
			}
		}
	}
	int sumcost = 0;
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			if(A[i][j]!=-1){
				sumcost += mincost[A[i][j]][1];
			}
		}
	}
	cout << sumcost;
}

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

vector<int> countingSort(const vector<int>& A) 
{
    const int max = *max_element(A.cbegin(), A.cend());
    vector<int> counter(max+1);
    for (auto a : A) {
        ++counter[a];
    }
    int sumCount = 0;
    for (auto& c : counter) {
        c += sumCount;
        sumCount = c;
    }
    vector<int> B(A.size());

    for (const auto& a : A) {
        B[counter[a]-1] = a;
        --counter[a];
    }
    return B;
}

int main() {
    int n;
    cin >> n;
    vector<int> A(n);

    for (auto& a : A) {
        cin >> a;
    }
    vector<int> B = countingSort(A);
    for (int i = 0; i < n-1; ++i) {
        cout << B[i] << " ";
    }
    cout << B[n-1] << endl;
}


Measured memory_bytes: 18296
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    vector<int> A(4);
    for (int i = 0; i < 6; i++){
        int a;
        cin >> a;
        A.at(a - 1)++;
    }
    sort(ALL(A));
    if (A.at(0) == 1 && A.at(1) == 1 && A.at(2) == 2 && A.at(3) == 2){
        cout << "YES" << endl;
    } 
    else {
        cout << "NO" << endl;
    }
}



Measured memory_bytes: 256
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;

const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 1e5+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
    ll n;
    cin >> n;
    vector<ll> v(n), vv, ff;
    for(int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    vv.push_back(300);
    for(int i = 0; i < n; i++)
    {
        if(vv.back() != v[i])
            vv.push_back(v[i]);
    }
    vv.push_back(0);
    ll nn = vv.size()-2;
    for(int i = 1; i <= nn; i++)
    {
        if(vv[i-1] < vv[i] && vv[i] > vv[i+1])
            ff.push_back(vv[i]);
        else if(vv[i-1] > vv[i] && vv[i] < vv[i+1])
            ff.push_back(vv[i]);

    }
    // for(auto u : ff)
    //     cout << u << ' ';
    ll curr = 1000;
    for(int i = 0; i + 1 < ff.size(); i+= 2)
    {
        ll x = ff[i];
        ll y = ff[i+1];
        // cout << x << ' ' << y << '\n';
        ll z = curr / x;
        curr -= z * x;
        curr += z * y;
    }
    cout << curr << '\n';

}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

Measured memory_bytes: 3524
#include <stdio.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define getInt(n) scanf("%d", &n)
#define showAns(ans) printf("%d\n", ans)

int main(void){
    int L, R, d;
    getInt(L);
    getInt(R);
    getInt(d);

    int ans = 0;

    rep(i,R-L+1) if((L+i)%d==0) ans++;

    showAns(ans);

    return 0;
}

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

const int mod=1000000007;
int p[610],f[2][310][310],a[610],n,x,y,jc[310],cnt;

void add(int &x,int y) {x=(x+y>=mod?x+y-mod:x+y);}

int main()
{
	scanf("%d",&n),jc[0]=1;
	for (int i=1; i<=n; i++) jc[i]=1ll*jc[i-1]*i%mod;
	for (int i=1; i<=2*n; i++)
	{
		scanf("%d",&a[i]);
		if (a[i]>0) p[a[i]]=i; 
		if (!(i&1)&&a[i]==-1&&a[i-1]==-1) cnt++;
	}
	x=1,y=0,f[0][0][0]=1;
	for (int i=2*n; i; i--)
	{
		if (p[i]&&a[(p[i]&1)?(p[i]+1):(p[i]-1)]!=-1) continue;
		x^=1,y^=1,memset(f[y],0,sizeof(f[y]));
		if (p[i])
		{
			for (int j=0; j<=n; j++)
				for (int k=0; k<=n; k++)
				{
					add(f[y][j+1][k],f[x][j][k]);
					if (k) add(f[y][j][k-1],f[x][j][k]);
				}
		} else
		{
			for (int j=0; j<=n; j++)
				for (int k=0; k<=n; k++)
				{
					add(f[y][j][k+1],f[x][j][k]);
					if (j) f[y][j-1][k]=(f[y][j-1][k]+1ll*j*f[x][j][k])%mod;
					if (k) add(f[y][j][k-1],f[x][j][k]);
				}
		}
	}
	return printf("%d\n",1ll*jc[cnt]*f[y][0][0]%mod),0;
}

Measured memory_bytes: 1024
// inputに入力データ全体が入る
function Main(input) {
	input = input.split("\n");
  　input.shift();
    P = input
    var max = 0;
    var x;
    var sum = 0;
    for(i of P){
      if(max < i){
        x = Number(i) / 2
        max = Number(i);
      }
      sum += Number(i)
    }
    sum -= x   
    console.log(sum)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>
#include <stack>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;
using Graph = Vvec<int>;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    string T;
    cin >> T;
    for(auto& x: T){
        if(x == '?') x = 'D';
    }

    cout << T << endl;
}

Measured memory_bytes: 3756
A, B = gets.split.map &:to_i
H = 21
W = 100
def f(fore, back, n)
  cnt = 0
  H.times.map{|i|
    W.times.map{|j|
      if i.even?
        back
      elsif j.odd?
        cnt += 1
        cnt < n ? fore : back
      else
        back
      end
    }
  }
end

dot = f(?., ?#, A)
sharp = f(?#, ?., B)
puts "#{H*2} #{W}"
(dot+sharp).each{|l|
  puts l*""
}


Measured memory_bytes: 3836
n, k = map(int, input().split())
d = [0] * k
a = [0 for i in range(k)]
ac = [0] * n

for i in range(k):
    d[i] = int(input())
    a[i] = list(map(int, input().split()))

for i in range(k):
    for j in range(d[i]):
        if ac[a[i][j]-1] == 0:
           ac[a[i][j]-1] = 1

total = sum(ac)
ans = n - total

print(ans)

Measured memory_bytes: 9216
#include<stdio.h>

int main(void){

    int K,S,i,j,k,result=0;

    scanf("%d %d",&K,&S);

    for(i = 0;i <= K;i++){
        for(j = 0;j <= K;j++){
            k = S - i - j;
            if(k >= 0 && k <= K){
                //printf("%d %d %d\n",i,j,k);
                result++;
            }
        }
    }

    printf("%d",result);
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace contest20191025
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) 
            {
                Console.WriteLine("Bad");
            }
            else
            {
                Console.WriteLine("Good");
            }

        }
    }
}


Measured memory_bytes: 13140
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))
B = list(map(int, sys.stdin.readline().rsplit()))

res = 0
for i, b in enumerate(B):
    a = A[i]
    a1 = A[i + 1]
    if a >= b:
        res += b
    else:
        res += a
        if a1 >= b - a:
            A[i + 1] = a1 - (b - a)
            res += b - a
        else:
            A[i + 1] = 0
            res += a1

print(res)

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

int main(){
  int64_t N, A, B;
  cin >> N >> A >> B;
  vector<int64_t> X(N);
  for(int64_t i=0; i<N; i++){
    cin >> X.at(i);
  }
  int64_t Ans=0;
  for(int64_t i=0; i<N-1; i++){
    if((X.at(i+1)-X.at(i))*A<B){
      Ans+=(X.at(i+1)-X.at(i))*A;
    }
    else{
      Ans+=B;
    }
  }
  cout << Ans << endl;
}

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

typedef long long ll;

int main() {
    string S, ans = "AC\n";
    cin >> S;
    if (S[0] != 'A') ans = "WA\n";
    if (S[1] < 'a' || S[1] > 'z') ans = "WA\n";
    int C = 0, n = S.size();
    if (S[n - 1] < 'a' || S[n - 1] > 'z') ans = "WA\n";
    for (int i = 2; i < n - 1; i++) {
        if (S[i] == 'C') C++;
        else if (S[i] < 'a' || S[i] > 'z') ans = "WA\n";
    }
    if (C != 1) ans = "WA\n";
    cout << ans;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

N = int(input())

X = []
for i in range(N):
    s, p = input().rstrip().split(' ')
    p = int(p)
    X.append([i+1, s, p])
    
X = sorted(X, key=lambda x: '{}{:03d}'.format(x[1], 100-x[2]))

for i, s, p in X:
    print(i)

Measured memory_bytes: 3060
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    A.sort(reverse=True)
    val=0
    for i in range(n):
        if i%2==0:
            val+=A[i]
        else:
            val-=A[i]

    print(val)



resolve()

Measured memory_bytes: 3060
#include <cstdio> 
#include <cstdlib> 
#include <cmath> 
#include <cstring> 
#include <climits> 
#include <cfloat> 
#include <map> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <numeric>
#include <cassert>

#define FOR(i, min, max) for (int i = (min); i < (max); ++i) 
#define FORE(i, min, max) for (int i = (min); i <= (max); ++i) 
#define REP(i, n) for (int i = 0; i < (n); ++i) 
#define REPV(vec, i) for (int i = 0; i < (int)(vec.size()); ++i) 
#define FOR_EACH(vec, it) for (typeof((vec).begin()) it = (vec).begin(); it != (vec).end(); ++it)

using namespace std; 
static const double EPS = 1e-12; 
typedef long long ll; 

// BIT, 0-index
template<typename T>
class BIT {
    int N;
    vector<T> data_;
    T *data;
  public:
    BIT(int N_) : N(N_), data_(N), data(&data_[0]-1) {}

    void add(int i, const T &val) {
        assert(i < N);
        i++; // for 1-index
        while (i <= N) { data[i]+=val; i+=(i&(-i)); }
    }

    // sum [0, i]
    T sum(int i) const {
        assert(i < N);
        if (i < 0)
            return T();
        i++; // for 1-index
        T s = 0; while (i > 0) { s+=data[i]; i-=(i&(-i)); }
        return s;
    }

    // sum [a, b]
    T sum(int a, int b) {
        if (a > b)
            return T();
        return sum(b) - sum(a-1);
    }
};

vector<int> inN;
vector<int> outN;

void dfs(vector<vector<int> > &E, int n, int &inc, int lastN = -1) {
    assert(inN[n] == -1);
    inN[n] = inc;
    inc++;
    for (auto &m : E[n]) if (m != lastN) { dfs(E, m, inc, n); }
    assert(outN[n] == -1);
    outN[n] = inc-1;
}

int main(void)
{
    int N;
    cin >> N;
    vector<int> C(N);
    REP(i, N) {
        cin >> C[i];
        --C[i];
    }
    vector<vector<int> > E(N);
    REP(i, N-1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        E[a].push_back(b);
        E[b].push_back(a);
    }
    inN.resize(N, -1);
    outN.resize(N, -1);
    int inc = 0;
    dfs(E, 0, inc);
    assert(inc == N);
    
    BIT<ll> bit(N);
    REP(i, N) bit.add(i, 1);

    vector<vector<int> > vs(N);
    REP(i, N) {
        vs[C[i]].push_back(i);
    }

    vector<pair<int, ll> > hist;
    REP(c, N) {
        ll ret = 0;
        sort(vs[c].begin(), vs[c].end(), [&](const int &a, const int &b) { return inN[a] > inN[b]; });
        for (auto n : vs[c]) {
            for (auto m : E[n]) if (inN[n] < inN[m]) {
                int s = bit.sum(inN[m], outN[m]);
                ret += (ll)s*(s+1)/2;
            }
            ll sum = bit.sum(inN[n], outN[n]);
            hist.push_back({inN[n], sum});
            bit.add(inN[n], -sum);
        }
        if (C[0] != c) {
            int s = bit.sum(inN[0], outN[0]);
            ret += (ll)s*(s+1)/2;
        }
        while(!hist.empty()) {
            bit.add(hist.back().first, hist.back().second);
            hist.pop_back();
        }
        cout << (ll)N*(N+1)/2LL - ret << endl;
    }

    return 0;
}


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

bool judge(vector<int> p,vector<int> q){
  int sum=0;
  for(int i=1;i<=11;i++){
    sum+=p[i]*q[i];
    sum%=11;
  }
  if(sum<=1 && p[0]==0){return true;}
  if(sum<=1 && p[0]!=0){return false;}
  sum=11-sum;
  if(p[0]!=sum){return false;}
  return true;
}


int main(){
  vector<int> p,q;
  p.resize(12);
  q.resize(12);
  for(int i=1;i<=6;i++){
    q[i]=i+1;
  }
  for(int i=7;i<=11;i++){
    q[i]=i-5;
  }
  int w;
  for(int i=11;i>=0;i--){
    char c;
    cin>>c;
    if('0'<=c && c<='9'){p[i]=c-'0';}
    else{p[i]=-1; w=i;}
  }
  int count=0;
  int ans=-1;
  for(int i=0;i<=9;i++){
    p[w]=i;
    if(judge(p,q)){count++; ans=i;}
  }
  if(count!=1){cout<<"MULTIPLE"<<endl;}
  else{cout<<ans<<endl;}
  
  return 0;
}



Measured memory_bytes: 3160
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

class BIT {
    // Binary Indexed Tree : 数列要素1つへの加算、数列のある地点までの累積和を高速に計算
    public:
    std::vector<int> data;
    BIT() {}
    BIT(const int size) {
        // 想定されるサイズの2倍の値を入れた方がいいかもしれない。数列は1から数えることを想定している。
        data.resize(size*2, 0);
    }
    int sum(int i) const {
        int s = 0;
        while (i > 0) {
            s += data[i];
            i = i & (i-1); // iの最後のビットを引く。
        }
        return s;
    }

    void add(int i, int x) {
        while (i < data.size()) {
            data[i] += x;
            i += i - (i & (i-1)); // iの最後のビットを加算する。
        }
    }
};

const int MAX_N = 5000;
int N;
int a[MAX_N*2];
char c[MAX_N*2];

int loc_white[MAX_N*2], loc_black[MAX_N*2];

int cost_white[MAX_N][MAX_N], cost_black[MAX_N][MAX_N], dp[MAX_N][MAX_N];

//BIT processed = BIT(MAX_N*2);

int main(int argc, char **argv) {
    std::cin >> N;

    for (int i = 1; i <= N * 2; i++) {
        std::cin >> c[i] >> a[i];
    }
    
    for (int i = 1; i <= N * 2; i++) {
        if (c[i] == 'W') {
            loc_white[a[i]] = i;
        } else {
            loc_black[a[i]] = i;
        }
    }

    BIT processed_white = BIT(MAX_N*2);
    for (int i = 0; i <= N; i++) {
        BIT processed_black = BIT(MAX_N*2);
        for (int j = 0; j <= N; j++) {
            if (i != N) {
                cost_white[i][j] = loc_white[i+1] - 1 - processed_white.sum(loc_white[i+1] - 1) - processed_black.sum(loc_white[i+1] - 1);
            }
            if (j != N) {
                cost_black[i][j] = loc_black[j+1] - 1 - processed_white.sum(loc_black[j+1] - 1) - processed_black.sum(loc_black[j+1] - 1);
            }
            if (j != N) { processed_black.add(loc_black[j+1], 1); }
            //std::cout << i << " " << j << " " << cost_white[i][j] << " " << cost_black[i][j] << std::endl;
        }
        if (i != N) { processed_white.add(loc_white[i+1], 1); }   
    }

    dp[0][0] = 0;
    for (int i = 1 ; i <= N; i++) {
        dp[i][0] = dp[i-1][0] + cost_white[i-1][0];
        dp[0][i] = dp[0][i-1] + cost_black[0][i-1];
    }

    for (int i = 1 ; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            dp[i][j] = std::min(dp[i-1][j] + cost_white[i-1][j], dp[i][j-1] + cost_black[i][j-1]);
        }
    }

    std::cout << dp[N][N] << std::endl;
    
    return 0;
}

Measured memory_bytes: 122496
N,X = map(int,input().split(' '))
num_list = list(map(int,input().split(' ')))
num_list_s = sorted(num_list)
total = 0
index = 0
for i in range(N):
    total += num_list_s[i]
    if total > X:
        break
    else:
        index += 1
if sum(num_list) < X:
    print(index-1)
else:
    print(index)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
  int D,T,S;
  scanf("%d%d%d",&D, &T, &S);
  
  int a = T*S;
  
  if(a >= D){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int P = 5040;
int dp[2][P]={};

int fact[8];

inline vector<int> decode(int x)
{
    vector<int> ret(7);
    vector<bool> use(7,false);
    rep(i,7)
    {
        int num = x/fact[6-i];
        x -= fact[6-i]*num;

        int y = 0,ct = 0;
        while(y<7)
        {
            if(!use[y]) ++ct;

            if(ct==num+1) break;
            ++y;
        }
        use[y]=true;
        ret[i]=y;
    }
    return ret;
}

inline int encode(const vector<int> &p)
{
    int ret = 0;
    vector<bool> use(7,false);
    rep(i,7)
    {
        int ct = 0;
        for(int j=0; j<p[i]; ++j) ct += !use[j];
        ret += ct*fact[6-i];
        use[p[i]]=true;
    }

    return ret;
}

inline vector<int> normalize(const vector<int> &p)
{
    vector<int> t(p);
    sort(all(t));

    int ct=0;
    int id[10];
    for(const auto &v:t) id[v]=ct++;

    vector<int> ret(7);
    rep(i,7) ret[i]=id[p[i]];

    return ret;
}

int main()
{
    fact[0]=1;
    for(int i=1; i<8; ++i) fact[i] = fact[i-1]*i;

    int n;
    cin >>n;
    vector<int> d(n+7),a(n+7);
    rep(i,n) cin >>d[i+7];
    rep(i,n) cin >>a[i+7];

    auto prev = dp[0], now = dp[1];

    n += 7;
    for(int i=7; i<n; ++i)
    {
        fill(now,now+P,0);
        rep(j,P)
        {
            vector<int> p = decode(j);

            // i??????????????????????£??????????
            rep(k,8)
            {
                vector<int> nx(all(p));
                for(auto &v:nx)if(v>=k) ++v;
                nx.pb(k);

                int NX = nx.size();
                int add = 0;
                for(int l=1; l<NX; ++l)
                {
                    if(nx[NX-1]>nx[NX-1-l])
                    {
                        // i???????????????????£??????????
                        if(d[i-l]>=l) add+=a[i-l];
                    }
                    else
                    {
                        // i???????????????????£??????????
                        if(d[i]>=l && i-l>=7) add+=a[i];
                    }
                }

                nx.erase(nx.begin());
                nx = normalize(nx);
                int idx = encode(nx);
                now[idx] = max(now[idx], prev[j]+add);
            }
        }
        swap(now,prev);
    }

    cout << *max_element(prev,prev+P) << endl;
    return 0;
}

Measured memory_bytes: 3192
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int n;
    lint m;
    cin >> n >> m;
    vector<lint> a(n);
    rep(i, n){
        int x;
        cin >> x;
        a[i] = x % m;
    }
    vector<lint> s(n+1);
    s[0] = 0;
    rep(i, n){
        s[i+1] = (s[i] + a[i]) % m;
    }
    SORT(s);
    lint ans = 0, cnt = 1;
    rep(i, n){
        if(s[i] == s[i+1]){
            cnt++;
        }else{
            ans += ((cnt * (cnt - 1)) / 2);
            cnt = 1;
        }
    }
    ans += ((cnt * (cnt - 1)) / 2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

ll h, w;
vector <vector <bool>> v(50, vector <bool> (50, 0));
vector <vector <ll>> d(50, vector <ll> (50, INF));
vector <ll> nx = {1, -1, 0, 0};
vector <ll> ny = {0, 0, -1, 1};

void dfs(ll x, ll y) {
  rep(i, 4) {
    ll px = x+nx.at(i), py = y+ny.at(i);
    if (0<=px&&px<h && 0<=py&&py<w) {
      if (d.at(x).at(y)+1<d.at(px).at(py) && v.at(px).at(py)) {
        d.at(px).at(py) = d.at(x).at(y) + 1;
        dfs(px, py);
      }
    }
  }
  return;
}

int main() {
  cin >> h >> w;
  ll white = 0;
  rep(i, h) {
    rep(j, w) {
      char c;
      cin >> c;
      if (c == '.') {
        v.at(i).at(j) = 1;
        white++;
      }
    }
  }
  d.at(0).at(0) = 0;
  dfs(0, 0);
  if (d.at(h-1).at(w-1) == INF) cout << -1 << endl;
  else cout << white-d.at(h-1).at(w-1)-1 << endl;
}

Measured memory_bytes: 512
import fractions
import math
from collections import deque

def prime(x):
  px = []
  limit = int(math.sqrt(x))
  for i in range(2, limit+1):
    flag = False
    while x % i == 0:
      flag = True
      x = x // i
    if flag:
      px.append(i)
  if x != 1:
    px.append(x)
  return px

tmp = list(map(int,(input().split())))
a = tmp[0]
b = tmp[1]

pa = prime(a)
pb = prime(b)

cnt = 1
j = 0

for i in range(len(pa)):
  while j < len(pb) and pb[j] < pa[i]:
    j += 1
  if j == len(pb):
    break
  elif pb[j] == pa[i]:
    cnt += 1
  
print (cnt)

Measured memory_bytes: 5052
import math
A, B, H, M =  map(int, input().split())
alpha = (H * 30 + M / 60.0 * 30) 
beta = (360.0 * M / 60) 
theta = abs(alpha - beta)
if theta > 180.0:
    theta = 360.0 - theta
theta = theta * math.pi / 180.0
c = A * A + B * B - 2 * A * B * math.cos(theta)
c = math.sqrt(c)

print(c)

Measured memory_bytes: 9512
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

int a,b;

int main() {

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

    printf("%d",(a+b)%24);

    return 0;
}



Measured memory_bytes: 256