akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N,M;
  cin >>N>>M;
  vector<vector<int>> s(N,vector<int>(2));
  for(int i=0;i<N;i++){
    for(int j=0;j<2; j++){
      cin>>s[i][j];
    }
  }
      
  //0が日数、1が報酬
  //短い日数で、最大報酬の仕事から順にこなす。
  
  sort(s.begin(),s.end());
  priority_queue<int> p;
  int answer=0;
  int t=0;
  for(int i=0;i<M;i++){
    
    for(int j=t;j<N;j++){
      if(s[j][0] <= i+1){
        p.push(s[j][1]);
        t++;
      }
      else{
        t=j;
        p.push(0);
        break;
      }
    }
    answer+=p.top();
    p.pop();
    }
  cout <<answer;
      
}

Measured memory_bytes: 6396
#include <stdio.h>

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2],R[MAX/2+2];
int cnt;

void merge(int A[] , int n , int left , int mid , int right)
{
	int n1 = mid - left;
	int n2 = right -mid;
	for( int i = 0; i < n1; i++) L[i] = A[left+i];
	for( int i = 0; i < n2; i++) R[i] = A[mid+i];
	L[n1] = R[n2] = SENTINEL;
	int i = 0 , j = 0;
	for( int k = left; k < right; k++)
	{
		cnt++;
		if(L[i] <= R[j])
		{
			A[k] = L[i++];
		}
		else{
			A[k] = R[j++];
		}
	}
}

void mergeSort(int A[] , int n , int left , int right)
{
	if(left + 1 < right)
	{
		int mid = (left+right)/2;
		mergeSort(A,n,left,mid);
		mergeSort(A,n,mid,right);
		merge(A,n,left,mid,right);
	}
}

int main(void)
{
	int A[MAX] , n , i;
	cnt = 0;
	
	scanf("%d",&n);
	
	for( i = 0; i < n; i++)
	{
		scanf("%d",&A[i]);
	}
	mergeSort(A,n,0,n);
	for( i = 0; i < n; i++)
	{
		if(i)printf(" ");
			printf("%d",A[i]);
	}
	printf("\n");
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 5740
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

from collections import Counter
N = ri()
A = ri_()
S = sum(A)
C = Counter(A)
Q = ri()
for _ in range(Q):
    b, c = ri_()
    d = C[b] * c - C[b] * b 
    C[c] += C[b]
    C[b] = 0
    S += d
    print(S)


Measured memory_bytes: 23996
#include <bits/stdc++.h>
using namespace std;
typedef __int128 ll;
#define x first
#define y second
#define pii pair<int , int>
#define mp make_pair
#define pb push_back
#define sz(a) (int)(a.size())
const int INF = 1000 * 1000 * 1000 + 7;
const ll LINF = INF * (ll)INF;
const int mod = 998244353;
const int MAX = 2000005;
vector<string> ans;
int n;
void go(string s , int mx)
{
	if(sz(s) == n)
	{
		cout << s << endl;
		return;
	}
	for(char i = 'a'; i <= 'a' + mx; i++)
	{
		go(s + i , mx + (i == ('a' + mx)));
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin >> n;
	go("a" , 1);
		
}


Measured memory_bytes: 1536
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdint>
#include <vector>
#include <utility>
using namespace std;
using i64 = int64_t;
using pii = pair<i64, int>;
using vpii = vector<pii>;

vpii PF(i64 n){
    vpii pf;
    for(i64 i=2; i*i<=n; i++){
        if(n%i != 0) continue;
        int ex = 0;
        while(n%i == 0){n /= i; ex++;}
        pf.push_back(pii(i, ex));
    }
    if(n != 1) pf.push_back(pii(n, 1));
    return pf;
}

int main(void){
    i64 n;
    cin >> n;
    vpii pf = PF(n);
    int cnt = 0;
    for(const pii &x : pf){
        int ex = x.second; 
        for(int i=1; ex>=i; i++){
            ex -= i;
            cnt++;
        }
    }
    cout << cnt << '\n';
    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const ll MOD = (ll)(1e9 + 7);

ll dp[10000 + 10][105][2];

int main2() {
  string K; cin >> K;
  int D; cin >> D;
  int N = K.size();
  CLR(dp, 0);
  dp[0][0][0] = 1;
  for (int i = 0; i < N; i++) {
    for (int d = 0; d < D; d++) {
      for (int x = 0; x < 10; x++) {
        (dp[i+1][(d+x) % D][1] += dp[i][d][1]) %= MOD;
        if (K[i]-'0' > x) {
          (dp[i+1][(d+x) % D][1] += dp[i][d][0]) %= MOD;
        } else if(K[i]-'0' == x) {
          (dp[i+1][(d+x) % D][0] += dp[i][d][0]) %= MOD;
        }
      }
    }
  }
  ll ans = (dp[N][0][0] + dp[N][0][1]) % MOD;
  ans = (ans - 1 + MOD) % MOD;
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 16768
import scala.io.StdIn.readLine

object Main {
  def getNum(c:Char) = c match {
    case 'I' => 1
    case 'V' => 5
    case 'X' => 10
    case 'L' => 50
    case 'C' => 100
    case 'D' => 500
    case 'M' => 1000
    case _ => 0
  }

  def main(args:Array[String]) = {
    Iterator.continually(readLine).takeWhile(_!=null).foreach { s =>
      var prev = getNum(s(0))
      var sum = prev
      for(j<-1 until s.length) {
        val n = getNum(s(j))
        if(n>prev) sum += n -(2*prev) else sum += n
        prev = n
      }
      println(sum)
    }
  }
}

Measured memory_bytes: 43444
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int n, c, k;
  cin >> n >> c >> k;
  vector<int> t(n);
  REP(i, n)
  {
    cin >> t[i];
  }
  sort(t.begin(), t.end());

  int i = 0;
  int ans = 0;
  while (i < n)
  {
    int s = t[i];
    int j = i;
    while (t[j] <= s + k && (j - i) < c)
    {
      j++;
    }
    ans++;
    i = j;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,d,x,y;
	scanf("%d%d%d",&n,&d,&x);
	int ans=0;
	for(int i=0;i<n;i++){
		scanf("%d",&y);
		ans+=(d-1)/y+1;
	}
	printf("%d",ans+x);
	return 0;
}

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

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

    if(a!=1 && b!=1) cout<<1<<endl;
    else if(a!=2 && b!=2) cout<<2<<endl;
    else cout<<3<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int num,a[100],i,k,l,j;

  cin>>num;
  for(i=0;i<num;i++){
    cin>>a[i];
  }


 for(k=0; k<num; k++){
   
   if(k<num-1){
   cout << a[k]<<" ";
   }else{
     cout <<a[k];
   }
 }
      cout <<endl;
    
  
  for(i=1;i<num;i++){
    for(j=i-1;j>=0;j--){
      if(a[j]>a[j+1]) swap(a[j],a[j+1]);
	     
	else
	  break;

	
    }
 for(k=0; k<num; k++){

   if(k<num-1){
     cout << a[k]<<" ";

   }else
   cout << a[k];


 }

 // if(i!=num-1){
 cout << endl;
 // }
 // cout <<A<<endl;
 
  }
  






      return 0;
}

	
  

Measured memory_bytes: 3076
S=input()
l=len(S)-1
ans=0
for i in range(1<<l):
    s=S
    n=[]
    k=0
    for j in range(l):
        k+=1
        if i&(1<<j):
            n.append(int(s[:k]))
            s = s[k:]
            k=0
    else:
        n.append(int(s))
    ans+=sum(n)
print(ans)

Measured memory_bytes: 3064
n = int(input())
alist = list(map(int, input().split()))
suma = sum(alist)

if suma % (n * (n+1) // 2) != 0:
  print('NO')
else:
  k = suma // (n * (n+1) // 2)
  da = []
  for preva, a in zip(alist, alist[1:]):
    da.append(a - preva - k)
  da.append(alist[0] - alist[-1] - k)
  nk = 0
  is_a = True
  for _da in da:
    if abs(_da) % n != 0:
      is_a = False
      break
    nk += abs(_da) // n
  if not is_a:
    print('NO')
  else:
    if nk != k:
      print('NO')
    else:
      print('YES')


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

int main(){
    double maxn = 0, tmp = 0;
    int n, k; cin >> n >> k;
    vector<int> p(n);
    vector<double> e(n);
    rep(i,n) cin >> p[i];

    for(int i = 0; i < n; i++){
        e[i] = (p[i] * (p[i] + 1) * 0.5) / p[i];
    }

    //maxn = accumulate(e.begin(),e.begin() + k - 1, 0.0);
    for(int i = 0; i < k; i++) tmp += e[i];
    maxn = tmp;
    for(int i = k; i < n; i++){
        tmp = tmp + e[i] - e[i-k];
        maxn = max(maxn, tmp);
    }

    put(maxn);
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define endl         "\n" 

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2) 

#define fo(i,a,b)     for(int i = (int)(a); i <= (int)(b); i++)
#define rf(i,a,b)    for(int i = (int)(a); i >= (int)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***



    int ac,tle,wa,re;   

void solve()
{
    int n;rd(n);
    fo(i,1,n){
        string s;rd(s);
        if(s=="AC")ac++;
        else if(s=="WA")wa++;
        else if(s=="TLE")tle++;
        else if(s=="RE")re++;
    }
    pp("AC","x",ac);
    pp("WA","x",wa);
    pp("TLE","x",tle);
    pp("RE","x",re);
}


void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    // cin >> t;
    while(t--)
        solve();

    cout<<"\n";
    return 0;
}

Measured memory_bytes: 3660
from itertools import combinations_with_replacement
n, m, q = map(int, input().split())
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

pmax = 0
A = [i for i in range(1, m + 1)]
for L in combinations_with_replacement(A, n):
    l = sorted(list(L))
    p = 0
    for i in range(q):
        if l[b[i] - 1] - l[a[i] - 1] == c[i]:
            p += d[i]
    pmax = max(pmax, p)
print(pmax)


Measured memory_bytes: 9212
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
typedef long long int64;
static const int MAXN = 418;
static const int MAXC = 1002;

int n;
struct tile {
    int val[4];
    int64 _hash;

    inline void normalize() {
        static int nw[4];
        static int64 h[4];
        for (int i = 0; i < 4; ++i)
            h[i] = (((int64)val[i] * MAXC + val[(i + 1) % 4]) * MAXC + val[(i + 2) % 4]) * MAXC + val[(i + 3) % 4];
        int x = std::min_element(h, h + 4) - &h[0];
        for (int i = 0; i < 4; ++i) nw[i] = val[(i + x) % 4];
        for (int i = 0; i < 4; ++i) val[i] = nw[i];
    }
    inline void shift() {
        int x = val[0]; val[0] = val[1]; val[1] = val[2]; val[2] = val[3]; val[3] = x;
    }
    inline int64 hash() {
        if (_hash != -1) return _hash;
        static int nw[4];
        for (int i = 0; i < 4; ++i) nw[i] = val[i];
        this->normalize();
        int64 ans = (((int64)val[0] * MAXC + val[1]) * MAXC + val[2]) * MAXC + val[3];
        for (int i = 0; i < 4; ++i) val[i] = nw[i];
        return (_hash = ans);
    }
    inline int rotations() {
        if (val[0] == val[2] && val[1] == val[3]) {
            if (val[0] == val[1]) return 4; else return 2;
        } else return 1;
    }

    tile() : _hash(-1) { }
    tile(int a, int b, int c, int d) : _hash(-1) { val[0] = a, val[1] = b, val[2] = c, val[3] = d; this->hash(); }
} c[MAXN];

inline bool operator < (const tile &lhs, const tile &rhs) { return lhs._hash < rhs._hash; }

std::map< int64, std::vector<int> > counter;

inline int count(int64 hash, int lower)
{
    std::map< int64, std::vector<int> >::iterator p = counter.find(hash);
    if (p == counter.end()) return 0;
    return std::distance(std::lower_bound(p->second.begin(), p->second.end(), lower), p->second.end());
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d%d%d", &c[i].val[0], &c[i].val[1], &c[i].val[2], &c[i].val[3]);
        c[i].normalize();
        counter[c[i].hash()].push_back(i);
    }

    int64 ans = 0;
    tile t[4];
    for (int i = 0; i < n - 1; ++i)
        for (int j = i + 1; j < n; ++j)
            for (int k = 0; k < 4; ++k) {
                t[0] = tile(c[i].val[1], c[i].val[0], c[j].val[1], c[j].val[0]);
                t[1] = tile(c[i].val[2], c[i].val[1], c[j].val[0], c[j].val[3]);
                t[2] = tile(c[i].val[3], c[i].val[2], c[j].val[3], c[j].val[2]);
                t[3] = tile(c[i].val[0], c[i].val[3], c[j].val[2], c[j].val[1]);
                std::sort(t, t + 4);

                int64 cur = 1;
                for (int p = 0, q; p < 4; p = q) {
                    for (q = p + 1; q < 4 && t[p].hash() == t[q].hash(); ++q) ;
                    int ct = count(t[p].hash(), i + 1), sel = q - p;
                    if (t[p].hash() == c[j].hash()) --ct;
                    for (int k = 1; k <= sel; ++k) cur = cur * (ct - k + 1) * t[p].rotations();
                }
                ans += cur;

                c[j].shift();
            }

    printf("%lld\n", ans);
    return 0;
}

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

int l[9];
int n, a, b, c;
int idx;
int min_diff = INT_MAX;
int size_sum;
bool visited[9];

void solution(int sum[], int to_pick[]) {
    if (idx == 3) {  // finished 출력후 종료
        int tmp[3] = {a, b, c};
        
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (i == j) continue;
                for (int k = 0; k < 3; k++) {
                    if (j == k) continue;
                    int diff = abs(tmp[0] - sum[i]) + abs(tmp[1] - sum[j]) + abs(tmp[2] - sum[k]);
                    diff += (size_sum - 3) * 10;
                    if (diff < min_diff) {
                        min_diff = diff;
                        // cout << diff << ' ' << sum[0] << ' ' << sum[1] << ' ' << sum[2] << '\n';
                    }
                }
            }
        }
        
        return;
    }
    
    if (to_pick[idx] == 0) {  // idx 증가 후 next
        idx++;
        solution(sum, to_pick);
        idx--;
        return;
    }
    
    for (int i = 0; i < n; i++) {
        if (!visited[i]) {
            sum[idx] += l[i];
            visited[i] = true;
            to_pick[idx]--;
            solution(sum, to_pick);
            sum[idx] -= l[i];
            visited[i] = false;
            to_pick[idx]++;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    
    cin >> n >> a >> b >> c;
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }
    
    for (int i = 1; i <= n; i++) {  // pick 개수
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                if (i + j + k > n) continue;
                idx = 0;
                int sum[3] = {0, 0, 0};
                int to_pick[3] = {i, j, k};
                size_sum = i + j + k;
                solution(sum, to_pick);
            }
        }
    }
    
    cout << min_diff << '\n';
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#define INF 1000000000

using namespace std;

int merge(int *A, int left, int mid, int right){
	int cnt = 0;
	int n1 = mid-left;
	int n2 = right-mid;
	int *L = (int *)malloc(sizeof(int)*(n1+1));
	int *R = (int *)malloc(sizeof(int)*(n2+1));
	for(int i = 0; i < n1; i++) { L[i] = A[left+i]; }
	for(int i = 0; i < n2; i++) { R[i] = A[mid+i]; }
	L[n1] = INF;
	R[n2] = INF;
	int i = 0, j = 0;
	for( int k = left; k < right; k++ ){
		cnt++;
		if( L[i] <= R[j] ){
			A[k] = L[i];
			i++;
		} else {
			A[k] = R[j];
			j++;
		}
	}
	return cnt;
}

int mergeSort(int *A, int left, int right){
	int cnt = 0;
	if( left+1 < right ){
		int mid = (left+right)/2;
		cnt += mergeSort(A, left, mid);
		cnt += mergeSort(A, mid, right);
		cnt += merge(A, left, mid, right);
	}
	return cnt;
}

int main(){
	int *A, n, cnt = 0;
	
	cin >> n;
	A = (int *)malloc(sizeof(int)*n);
	for(int i = 0; i < n; i++){
		cin >> A[i];
	}
	cnt = mergeSort(A, 0, n);
	
	for(int i = 0; i < n; i++) { 
		cout << A[i];
		if( i != n-1 ) cout << " ";
	}
	cout << endl;
	cout << cnt << endl;
	
	return 0;
}


Measured memory_bytes: 65796
#include <stdio.h>

int main(void){
    long int A, B;
    int K;
    long int a[100]={0};
    long int b[100]={0};
    scanf("%ld %ld %d", &A, &B, &K);
    if (K > ((B-A+1)/2 + (B-A+1)%2)) K=(B-A+1)/2 + (B-A+1)%2;
    for (int i=0; i<K ; i++) {
        a[i]= A+i;
        b[i]= B-i;
        
    }
    for (int j= 0; j<K; j++) {
        if (a[j] != b[j]) printf("%ld\n", a[j]);
    }
    for (int l= 0; l<K; l++) {
        printf("%ld\n", b[K-1-l]);
    }
    return(0);
}

Measured memory_bytes: 128
// May this submission get accepted
#pragma GCC optimize ("O3")
#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 STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

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

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    string s = inp1;
    string t(s.size(), 'x');
    cout << t << endl;
    
}

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

#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) <<"#" <<endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 998244353;
const ll MAX = 3e3+23;
const ll inf = 1e18+7;


int main(){
  fastio;
  string s;
  cin>>s;
  ll cont =0;
  f(i,0,sz(s)){
    if(s[i]=='A') cont++;
  }
  if(cont==2 || cont==1) cout<<"Yes\n";
  else cout<<"No\n";
  return 0; 
}

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

int main() {
	ios_base::sync_with_stdio(0);
	
	string s;
	cin >> s;
	
	int wins = 0;
	int loses = 0;
	for(auto c : s) (c == 'o' ? wins : loses) += 1;
	
	if(loses < 8) cout << "YES\n";
	else cout << "NO\n";
	
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	rep(i,ty-sy) cout << "U";
	rep(j,tx-sx) cout << "R";
	rep(i,ty-sy) cout << "D";
	rep(j,tx-sx) cout << "L";
	cout << "L";
	rep(i,ty-sy+1) cout << "U";
	rep(j,tx-sx+1) cout << "R";
	cout << "DR";
	rep(i,ty-sy+1) cout << "D";
	rep(j,tx-sx+1) cout << "L";
	cout << "U" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
int i,j,k;
int n,m,l;
double a[100][100],b[100][100];
double c[100][100]={0};

scanf(" %d %d %d",&n,&m,&l);
for(i = 0;i < n;i++){
for(j = 0;j < m;j++){
scanf("%lf",&a[i][j]);
}
}
for(i = 0;i < m;i++){
for(j = 0;j < l;j++){
scanf("%lf",&b[i][j]);
}
}

for(i = 0;i < n;i++){
for(j = 0;j < l;j++){
for(k = 0;k < m;k++){
c[i][j]+=a[i][k]*b[k][j];
}
}
}
for(i = 0;i < n;i++){
for(j = 0;j < l;j++){
printf("%.0f",c[i][j]);
if(j != l-1) printf(" ");
else printf("\n");
}
}
return 0;
}



Measured memory_bytes: 2056
import java.math.*

fun main(args: Array<String>) {
    val (A, B, C, D) = readInputLine().split(" ").map { it.toInt() }
    
    println(Math.max(0, Math.min(B, D) - Math.max(A, C)))
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37872
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0

for i in range(a+1):
    for j in range(b+1):
        for l in range(c+1):
            if 500*i + 100*j + 50*l ==x:
                ans += 1
print(ans)


Measured memory_bytes: 3060
if __name__ == '__main__':

    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    root = [] # 訪れた頂点をメモ
    already = [-1] * (n+1) # rootのindexのメモ　と　すでに訪れたか

    c = 1# 周期
    l = 0# 例外部分のながさ

    v = 1#頂点は1 ここから遷移
    while(already[v] == -1): # すでに書いてあれば訪れている。かつ周期の起点となる場所
        already[v] = len(root) #訪れたら何回目かを記述
        root.append(v)
        v = a[v-1]

    c = len(root) - already[v]
    l = already[v]

    if k < l:#例外部分のながさ
        ans = root[k]
    else:# 周期にいるなら
        k -= l
        ans = root[k%c+l]

    print(ans)


Measured memory_bytes: 32216
def main():
    num_list = list(map(int, input().split()))  # n個の数字がリストに格納される

    result = 0

    for i in range(len(num_list)):
        result += num_list[i]


    if result >= 22:
        print('bust')
    else:
        print('win')

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
use std::io::*;
use std::str::FromStr;

fn main() {
    let a: u64 = read();
    let b: u64 = read();
    let c: u64 = read();

    if a == b && a == c {
        return println!("No");
    }

    if a == b && a != c {
        return println!("Yes");
    }

    if a == c && a != b {
        return println!("Yes");
    }

    if b == c && b != a {
        return println!("Yes");
    }

    println!("No");
}

/// Example
/// ```
///
///  let n: i32 = read();
///
///  let mut xs = Vec::new();
///  for _ in 0..n {
///      xs.push(read::<i32>() + 1000);
///  }
/// ```
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
const int MOD=1000*1000*1000+7;
int main()
{
	long long l, r;
	cin>>l>>r;
	long long mini=LLONG_MAX, b;
	for(long long i=l; i<l+2040; i++)
	{
		if(i>r)break;
		for(long long j=i+1; j<l+2040; j++)
		{
			if(j>r)break;
			b=((i)*(j))%2019;
			mini=min(mini,b); 
		}
	}
	cout<<mini<<endl;
}


Measured memory_bytes: 256
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = int(input())

if N >= 1000:
    print('ABD')
else:
    print('ABC')


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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (size_t i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static int MOD = 1000000000 + 7;
const static llong INF = 1LL << 60;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

struct UF {
    vector<int> par, sz;

    UF(int n) {
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find_root(int x) {
        return par[x] == x ? x : par[x] = find_root(par[x]);
    }

    bool same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y) {
        x = find_root(x);
        y = find_root(y);
        if (x == y) return;

        if (sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        par[y] = x;
    }   
};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k, l;
    cin >> n >> k >> l;
    UF road(n), rail(n);
    rep(i, k) {
        int p, q;
        cin >> p >> q;
        road.unite(p - 1, q - 1);
    }
    rep(i ,l) {
        int r, s;
        cin >> r >> s;
        rail.unite(r - 1, s - 1);
    }

    vector<pair<int, int> > V(n);
    map<pair<int, int>, int> M;
    rep(i, n) {
        V[i].first = road.find_root(i);
        V[i].second = rail.find_root(i);
        ++M[V[i]];
    }

    rep(i, n) {
        if (i) cout << " ";
        cout << M[V[i]];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 16640
N = int(input())
p = []
for i in range(N):
    a = int(input())
    p.append(a)

ma =max(p)
ans = 0
cnt = 0
for i in p:
    if i == ma and cnt ==0:
        ans += i/2
        cnt = 1
    else:
        ans += i
print(int(ans))


Measured memory_bytes: 3060
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,popcnt")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 1<<17, mod = 1e9 + 7, i2 = (mod+1)/2;
int x[maxn], y[maxn], w[maxn], z[maxn];
int main() {
	cin.tie(0)->sync_with_stdio(0);
	string s, t;
	cin >> s >> t;
	int n = s.size(), m = t.size();
	for(int i = 0; i < n; i++) x[i+1] = x[i] + (s[i]=='A') + 1;
	for(int i = 0; i < m; i++) y[i+1] = y[i] + (t[i]=='A') + 1;
	int q;
	cin >> q;
	int a, b, c, d;
	while(q--) {
		cin >> a >> b >> c >> d;
		--a, --c;
		cout << ((x[b]-x[a])%3 == (y[d]-y[c])%3 ? "YES\n" : "NO\n");
	}
	return 0;
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

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

    int N, M;
    string s;
    cin >> N >> M >> s;

    vvi g(N);
    vi ad(N), bd(N);
    for (int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].push_back(v);
        g[v].push_back(u);
        if (s[u] == 'A')
            ad[v]++;
        else
            bd[v]++;
        if (s[v] == 'A')
            ad[u]++;
        else
            bd[u]++;
    }

    queue<int> del;
    vector<bool> alive(N, true);
    for (int i = 0; i < N; i++) {
        if (!ad[i] || !bd[i]) {
            del.push(i);
            alive[i] = false;
        }
    }

    while (!del.empty()) {
        int nxt = del.front();
        del.pop();
        for (int nbr : g[nxt]) {
            if (s[nxt] == 'A')
                --ad[nbr];
            else
                --bd[nbr];
            if (alive[nbr] && (!ad[nbr] || !bd[nbr])) {
                del.push(nbr);
                alive[nbr] = false;
            }
        }
    }

    for (bool v : alive) {
        if (v) {
            cout << "Yes\n";
            return 0;
        }
    }

    cout << "No\n";
    return 0;
}


Measured memory_bytes: 12240
#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 a,b;
	cin >> a >> b;
	if(a * b == 2) cout << 3 << endl;
	else if(a * b == 3) cout << 2 << endl;
	else cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 256
// ABC081-B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int num[210];
	int min=10000,now = 0;
	for (int i=0; i < n; i++)
	{
		cin >> num[i];
		//cout << num[i];
		while(num[i]%2 == 0)
		{
			num[i] = num[i] / 2;
			now++;
			//cout << "new num[i]=" << num[i];
			//cout << "now=" << now;
		}
		if (min > now)
		{
			min = now;
		}
		now = 0;
	}
	cout << min;

}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    size_t N;
    scanf("%zu", &N);

    vector<int> A(N);
    for (size_t i=0; i<N; ++i)
        scanf("%d", &A[i]);

    for (size_t i=1; i<=N; ++i) {
        sort(A.begin(), A.begin()+i);

        for (size_t i=0; i<N; ++i)
            printf("%d%c", A[i], i<N-1? ' ':'\n');
    }

    return 0;
}

Measured memory_bytes: 2784
from fractions import gcd
inpl = lambda: list(map(int,input().split()))
def lcm(a,b): return a*b//gcd(a,b)
A, B, C, D = inpl()
CD = lcm(C,D)
XB = B//C + B//D - B//CD
XA = (A-1)//C + (A-1)//D - (A-1)//CD
X = XB - XA
Z = (B - A + 1) - X
print(Z)

Measured memory_bytes: 5076
#include <iostream>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()
typedef complex<double> P;
typedef vector<P> VP;

int main(){
    while(1){
        int n,m;
        cin >> n >> m;
        if(n == 0) break;

        VP dog(n);
        vector<double> v(n);
        for(int i=0; i<n; i++){
            double x,y;
            cin >> x >> y >> v[i];
            dog[i] = P(x, y);
        }

        VP fp(m), dir(m);
        for(int i=0; i<m; i++){
            double xp,yp,xd,yd;
            cin >> xp >> yp >> xd >> yd;
            fp[i] = P(xp, yp);
            dir[i] = P(xd, yd);
        }

        vector<int> ans(n, 0);
        for(int i=0; i<m; i++){
            //座標変換(フリスビー位置を原点、投げる方向をx軸方向に)
            P bpos = fp[i];
            P bdir = dir[i]/abs(dir[i]);
            for(int j=0; j<n; j++){
                dog[j] -= bpos;
                dog[j] /= bdir;
            }
            for(int j=0; j<m; j++){
                fp[j] -= bpos;
                fp[j] /= bdir;
                dir[j] /= bdir;
            }

            vector<bool> run(n, false);
            VP rdir(n);
            double tmin = INF;
            int minidx = -1;
            //2次方程式を解く
            for(int j=0; j<n; j++){
                double a,b,c;
                a = 1 -(v[j]*v[j] /norm(dir[i]));
                b = -2 *dog[j].X;
                c = norm(dog[j]);
                double sol = INF;
                if(abs(a) < EPS){
                    if(abs(b) > EPS && -c/b > 0){
                        sol = -c/b;
                    }
                }else{
                    double d = b*b -4*a*c;
                    if(abs(d) < EPS) d = 0;
                    if(d >= 0){
                        double tmp[2] = {(-b+sqrt(d))/(2*a), (-b-sqrt(d))/(2*a)};
                        if(tmp[0] > 0) sol = min(sol, tmp[0]);
                        if(tmp[1] > 0) sol = min(sol, tmp[1]);
                    }
                }

                if(sol == INF) continue;
                run[j] = true;
                rdir[j] = P(sol, 0) -dog[j];
                rdir[j] *= v[j] /abs(rdir[j]);
                double time = sol/dir[i].X;
                if(time < tmin){
                    tmin = time;
                    minidx = j;
                }
            }
            for(int j=0; j<n; j++){
                if(run[j]){
                    dog[j] += tmin *rdir[j];
                }
            }
            if(minidx != -1){
                ans[minidx]++;
            }
        }

        for(int i=0; i<n-1; i++){
            cout << ans[i] << " ";
        }
        cout << ans[n-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(void){

  ll n;
  cin>>n;
  vector<ll> num_people(5);

  rep(i,5){
    cin>>num_people[i];
  }

  ll tmp=0;

  rep(i,5){
    if(n%num_people[i]==0) tmp=max( tmp,n/num_people[i] );
    else tmp=max( tmp,n/num_people[i] + 1 );
  }

  cout << tmp+4 << endl;

  return 0;

}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
mod = 10**9+7

ans = 0
for i in range(K, N+2):
    ans += (N+(N-i+1))*i//2-(i*(i-1)//2)+1
    ans %= mod
print(ans)

Measured memory_bytes: 63508
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
    int n;
    cin >> n;
    int n3 = n / 3;
    int mul3 = (n3*(3 + 3 + (n3-1) * 3) ) / 2;
    int n5 = n / 5;
    int mul5 = (n5 * (5 + 5 + (n5 - 1) * 5)) / 2;
    int n15 = n / 15;
    int mul15 = (n15 * (15 + 15 + (n15 - 1) * 15)) / 2;

    int sum  = (n * (n + 1)) / 2;
    sum = sum - mul3 - mul5 + mul15;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <map>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
    char game[101];
    int len;
    while(scanf("%s", game) && game[0] != '0') {
        len = int(strlen(game));
        map<char, int> m; m.insert({'A', 0}); m.insert({'B', 0});
        for (int i = 1; i < len; i++) {
            m[game[i]]++;
        }
        if (m['A'] > m['B']) m['A']++;
        else m['B']++;
        printf("%d %d\n", m['A'], m['B']);
    }
    return 0;
}



Measured memory_bytes: 2824
#include<iostream>
#include<cmath>

using namespace std;
int main()
{
	long long int c,cc;
	long long int a;
	cin>>a;
	c=1E13;
	for(int i=2;i<=sqrt((long double)a) + 1;i++)
	{
		if(a%i==0)
			c=i+a/i-2;
		cc=min(c,a-1);
	}
	cout<<cc;
	
	

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <functional>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> arr(3 * n), mxsum(3 * n), mnsum(3 * n);
	int i;
	for(i = 0; i < 3 * n; i++) {
		cin >> arr[i];
	}
	mxsum[0] = arr[0];
	//ll curmin = arr[0];
	multiset<int> ms;
	ms.insert(arr[0]);
	mnsum[3 * n - 1] = arr[3 * n - 1];
	//ll curmax = arr[3 * n - 1];
	for(i = 1; i < n; i++) {
		ms.insert(arr[i]);
		mxsum[i] = mxsum[i - 1] + arr[i];
	}
	for(i = n; i < 3 * n; i++) {
		auto it = ms.begin();
		if(*it < arr[i]) {
			mxsum[i] = mxsum[i - 1] - *it + arr[i];
			ms.erase(it);
			ms.insert(arr[i]);
		}
		else {
			mxsum[i] = mxsum[i - 1];
		}
	}
	ms.clear();
	ms.insert(arr[3 * n - 1]);
	for(i = 3 * n - 2; i >= 2 * n; i--) {
		ms.insert(arr[i]);
		mnsum[i] = mnsum[i + 1] + arr[i];
	}
	for(i = 2 * n - 1; i >= 0; i--) {
		auto it = ms.end();
		it--;
		if(*it > arr[i]) {
			mnsum[i] = mnsum[i + 1] - *it + arr[i];
			ms.erase(it);
			ms.insert(arr[i]);
		}
		else {
			mnsum[i] = mnsum[i + 1];
		}
	}
	ll ans = -1e18;
	for(i = n - 1; i < 2 * n; i++) {
		ans = max(ans, mxsum[i] - mnsum[i + 1]);
	}
	cout << ans;
			
	
    return 0;
}



Measured memory_bytes: 12032
#include <stdio.h>

int main(void)
{
    int n;
    int student;

    while (scanf("%d", &n) == 1){
        student = 1;
        while (n > 1){
            n--;
            student++;
            if (student == 40){
                student = 1;
            }
        }
        printf("3C");
        if (student < 10){
            printf("0");
        }
        printf("%d\n", student);
    }

    return (0);
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }

int main(){
  ll inf = pow(10,12);
  ll A,B,Q; cin>>A>>B>>Q;
  ll s[A+2];
  s[0] = -inf;
  for(int i=1;i<=A;++i){ cin>>s[i]; }
  s[A+1] = inf;
  ll t[B+2];
  t[0] = -inf; 
  for(int i=1;i<=B;++i){ cin>>t[i];}
  t[B+1] = inf;
  
  REP(count,Q){
    ll x; cin>>x;
    ll* iters = lower_bound(s,s+A+2,x);
    ll* itert = lower_bound(t,t+B+2,x);
    ll hs = *(iters-1);
    ll ms = *iters;
    ll ht = *(itert-1);
    ll mt = *itert;
    
    ll c1 = min( abs(x-hs) + abs(hs-ht), abs(x-ht)+abs(ht-hs) );
	ll c2 = min( abs(x-hs) + abs(hs-mt), abs(x-mt)+abs(mt-hs) );
    ll c3 = min( abs(x-ms) + abs(ms-ht), abs(x-ht)+abs(ht-ms) );
    ll c4 = min( abs(x-ms) + abs(ms-mt), abs(x-mt)+abs(mt-ms) );
   
    ll ans = min({c1,c2,c3,c4});
    cout << ans <<"\n";
  }
  
}

Measured memory_bytes: 2816
X=gets.chomp
s_num = 0
t_num = 0
(0..(X.length-1)).each do |i|
    if X[i] == "T"
        if s_num > 0
            s_num-=1
        else
            t_num+=1
        end
    else
        s_num+=1
    end
end
puts s_num*2


Measured memory_bytes: 2300
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#include <numeric>
#define lint long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++)
#define DUMP(ar) for(auto itd=begin(ar); itd != end(ar); itd++) cout << "["s << itd - begin(ar) << "]:"s << *itd << endl
#define DUMPL(ar) for(auto itd=begin(ar); itd != end(ar); itd++) { cout << *itd; if(end(ar)-itd > 1) cout << ' '; } cout << endl
#define COUT(x) cout << (x) << endl
#define VCIN(ar) for(auto &vcin: (ar)) cin >> vcin
#define ALL(ar) ar.begin(), ar.end()
#define LOOPD(i) cout << "ループ["s << i << "]回目---------------"s << endl
using namespace std;
// lint:64ビット 10^19
using P = pair<lint, bool>;
vector<int> a;
vector<vector<P>> mm(3001, vector<P>(3001, make_pair(0, false)));

lint rec(int left, int right, bool turn=true){ // turn=true...x+  false...y+
    if(left == right){
        if(turn == true) return a[right];
        else return -a[right];
    }

    if(mm[left][right].second) return mm[left][right].first;
    lint ans = 0;
    lint tmp1 = rec(left+1, right, !turn) + (turn ? a[left] : -a[left]);
    lint tmp2 = rec(left, right-1, !turn) + (turn ? a[right] : -a[right]);
    if(turn){
        // tmp1 += a[left];
        // tmp2 += a[right];
        ans = max(tmp1, tmp2);
    }else{
        // tmp1 -= a[left];
        // tmp2 -= a[right];
        ans = min(tmp1, tmp2);
    }

    mm[left][right].first = ans;
    mm[left][right].second = true;

    return ans;
}

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

    int n;
    cin >> n;
    a.resize(n);
    VCIN(a);

    lint ans = rec(0, a.size()-1);
    cout << ans << endl;

    // cout << "縦:left, 横:right" << endl;
    // cout << "  ";
    // for(int i=0; i<4; i++){
    //     cout << setw(4) << i << ' ';
    // }
    // cout << endl;
    // for(int i=0; i<4; i++){
    //     cout << i << ' ';
    //     for(int j=0; j<4; j++){
    //         cout << setw(4) << mm[i][j].first << ' ';
    //     }
    //     cout << endl;
    // }

    return 0;
}

Measured memory_bytes: 141312
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const long long MAXN=100005;
long long n,m;
vector<int>w[MAXN];
bool vis[MAXN];
long long cl[MAXN];
bool dfs(long long u)
{
	vis[u]=1;
	long long re=1;
	for(long long i=0;i<int(w[u].size());i++)
	{
		long long v=w[u][i];
		if(vis[v])
			re&=(cl[u]!=cl[v]);
		else
		{
			cl[v]=cl[u]^1;
			re&=dfs(v);
		}
	}
	return re;
}
int main()
{
	//freopen("squared.in","r",stdin);
	//freopen("squared.out","w",stdout);
	scanf("%lld %lld",&n,&m);
	for(long long i=1;i<=m;i++)
	{
		long long u,v;
		scanf("%lld %lld",&u,&v);
		w[u].push_back(v);
		w[v].push_back(u);
	}
	long long I=0,O=0,J=0;
	for(long long i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			if(int(w[i].size())==0)
				I++;
			else if(dfs(i))
				O++;
			else
				J++;
		}
	}
	printf("%lld\n",I*I+I*(n-I)*2+O*O*2+J*J+O*J*2);
	fclose(stdin);
	fclose(stdout);
}

Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=100010;
int main()
{
    ll n , m;
    while (~scanf("%lld%lld", &n,&m)){
        double sum = 0.0;
        ll temp = m*1900 + (n-m)*100;
        ll t = 1;
        for (int i=0; i<m; i++)  t *= 2;

        printf("%lld\n", t * temp);
    }
    return 0;
}


Measured memory_bytes: 256
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      k: usize,
      a: [usize; n]
   }
   let mut l: usize = 0;
   let mut r: usize = 0;
   for i in 0..n {
      if a[i] == 1 {
         l = i;
         r = n - i - 1;
         break;
      }
   }
   let mut ans = n;
   for dl in 0..k {
      let dr = k - 1 - dl;
      if dl > l || dr > r {
         continue;
      }
      ans = std::cmp::min(
         ans,
         1 + if l - dl != 0 {
            (l - dl - 1) / (k - 1) + 1
         } else {
            0
         } + if r - dr != 0 {
            (r - dr - 1) / (k - 1) + 1
         } else {
            0
         },
      );
   }
   println!("{}", ans);
}


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

using namespace std;
const int MN = 1e5+7;

int dp[MN][3], n;

int main()
{
    cin >> n;
    int a, b, c;
    cin >> a >> b >> c;
    dp[0][0] = max(b, c);
    dp[0][1] = max(a, c);
    dp[0][2] = max(a, b);
    for(int i = 1; i < n; i++){
        cin >> a >> b >> c;
        dp[i][0] = max(dp[i-1][1] + b, dp[i-1][2] + c);
        dp[i][1] = max(dp[i-1][0] + a, dp[i-1][2] + c);
        dp[i][2] = max(dp[i-1][0] + a, dp[i-1][1] + b);
    }
    cout << max(dp[n-1][0], dp[n-1][1]);
}


Measured memory_bytes: 1408