akhauriyash/Code-Regression huggingface dataset:
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 1000005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); //cout.tie(0);
#define pi 3.1415926535897L
#define db long double  /* print with %Lf */
#define EPS 1e-9
#define flu fflush(stdout)
#define imp {cout<<"No\n"; return 0;}
#define yup {cout<<"Yes\n"; return 0;}
#define debug_vec(vec,n) {rep(idxi,n) cout<<vec[idxi]<<" "; cout<<"\n";}
#define debug_pvec(vec,n) {rep(idxi,n) cout<<vec[idxi].fi<<"-"<<vec[idxi].se<<"  "; cout<<"\n";}
#define debug_set(seta) {cout<<seta.size()<<"\n"; for(auto idxi:seta) cout<<idxi<<" "; cout<<"\n";}
#define debug_map(mappa) {cout<<mappa.size()<<"\n";for(auto idxi:mappa) cout<<idxi.fi<<"-"<<idxi.se<<"  "; cout<<"\n";}
#define debug_vecvec(vec,n) {rep(idxi,n) {for(auto idxi2:vec[idxi]) cout<<idxi2<<" "; cout<<"\n";}}
 
// LOOK AT THESE BEFORE SUBMISSION
// LOOK AT THESE BEFORE SUBMISSION
// ============================================================
// Nmax value and is index access offset taking it beyond Nmax.
// Precision error in case of real numbers.
// N vs N2 chosen correctly.
// Modulo applied everywhere.
// Flush in case of interactive.
// Don't erase value in multiset.
// Check for array indices out of bound (in pre or suff sums).
// Correct return value for functions.
// Confirm the letter case of yes and no.
// Dont paste code two times in the text file.
// ============================================================

int main() {

    get(n);
    ll maxi = 0;

    map<string, ll> ma;
    rep(i,n) {
        gets(s);
        ma[s]++;
        maxi = max(maxi, ma[s]);
    }

    for(auto i:ma) {
        if(i.se==maxi)
            printf("%s\n", i.fi.c_str());
    }
    

    return 0;  
}   


Measured memory_bytes: 25216
#include <iostream>
#include <vector>
#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    vector<int> value(4);
    string abcd;
    string tmp_pm="+++";
    string pm="+++";
    cin >> abcd;
    for(int i=0; i<4; i++){
        int tmp=abcd[i]-'0';
        value[i]=tmp;
    }

    for(int i=0; i<2; i++){
        int tmp=value[0];
        if(i%2==0){
            tmp_pm[0]='+';
            tmp+=value[1];
        }else{
            tmp_pm[0]='-';
            tmp-=value[1];            
        }
        for(int j=0; j<2; j++){
            int tmp1=tmp;
            if(j%2==0){
                tmp_pm[1]='+';
                tmp1+=value[2];
            }else{
                tmp_pm[1]='-';
                tmp1-=value[2];            
            }
            for(int k=0; k<2; k++){
                int tmp2=tmp1;
                if(k%2==0){
                    tmp_pm[2]='+';
                    tmp2+=value[3];
                }else{
                    tmp_pm[2]='-';
                    tmp2-=value[3];            
                }
                //cout << tmp2 << endl;
                if(tmp2==7){
                    pm=tmp_pm;
                }
            }
        }
    }
    cout << value[0] << pm[0] << value[1] << pm[1] << value[2] << pm[2] << value[3] << "=7" << endl;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        WriteLine(N % 2 == 0 ? N / 2 - 1 : N / 2);
    }
}

Measured memory_bytes: 11092
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
//#include<unordered_map>//イテレータあるけど順序保持しないmap
//#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;
#define input(N) cin >> N ;

signed main() {
int A,B,C,cou5=0,cou7=0;
string ans = "NO";
cin >> A >> B >> C;
if(A==5)cou5++;
if(A==7)cou7++;
if(B==5)cou5++;
if(B==7)cou7++;
if(C==5)cou5++;
if(C==7)cou7++;

if(cou5==2&&cou7==1){
    ans ="YES";
}

answer(ans);

}


Measured memory_bytes: 256
//People only find me interesting because they can't tell whether I'm serious or not

#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
typedef double db;
//typedef __int128 s128;
//typedef __uint128_t u128;
//typedef unsigned long long u64;
#define int long long int
#define P 998244353
#define Q 1000000006
#define sz(a) (ll)a.size()
#define lt(a) (ll)a.length()
#define pll pair<ll,ll>
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define bac(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define teevra_gati ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define N 100005
#define PI 3.14159265359
#define inf LLONG_MAX
using namespace __gnu_pbds;
using namespace std;
void solve(){
    string s;
    cin>>s;
    f(i,0,lt(s)){
        if(s[i]=='?') s[i]='D';
    }
    cout<<s;
}
signed main() {
    teevra_gati
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    solve();
    return 0;
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  
  if(a + b + c == 17){
    cout << "YES" << endl; 
  }else{
    cout << "NO" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll mod=INF;


int main() {
    int x,y;
    cin >> x >> y;
    bool t=false;
    rep(i,x+1){
        if (i*2+(x-i)*4==y) t=true;
    }
    if (t) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

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

  if (a + b >= c)
    cout << b + c << endl;
  else
  {
    ll ans = 0;
    ans += b * 2;
    c -= b;
    ans += a;
    ans++;
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A;
  string op;
  cin >> N >> A; // 1<=N円<=10000 0<=A枚<=1000
 
  if (N <= A) {
    cout << "Yes" << endl;
  }
  else if (N%500 <= A) {
	cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
A,B,C,D=map(int,input().split())
def gcd(a,b):
    while a%b>0:
        a,b=b,a%b
    return b
CC=B//C-(A-1)//C
DD=B//D-(A-1)//D
CD=C*D//gcd(C,D)
EE=B//CD-(A-1)//CD
print(B-A+1-CC-DD+EE)

Measured memory_bytes: 3060
;; #!/usr/bin/env sbcl --script

(declaim (optimize (speed 3) (safety 0) (debug 0)))

(deftype uint8 () '(unsigned-byte 8))
(deftype int32 () '(signed-byte 32))

(declaim (type fixnum *ptr* *len*)
         (type (vector uint8 4096) *buf*))

(defvar *buf* (make-array 4096 :element-type 'uint8 :initial-element 0))
(defvar *ptr* (the fixnum 0))
(defvar *len* (the fixnum -1))

(defun refresh-buf ()
  (setf *len* (the fixnum (read-sequence *buf* *standard-input*)))
  (setf *ptr* (the fixnum 0)))

(declaim (ftype (function () uint8) my-read-char))
(defun my-read-char ()
  (when (>= *ptr* *len*) (refresh-buf))
  (if (>= *ptr* *len*)
      0
      (progn (incf *ptr*)
             (aref *buf* (1- *ptr*)))))

(declaim (ftype (function () int32) my-read-int))
(defun my-read-int ()
  (let ((is-negative nil)
        (result 0))
    (declare (type int32 result))
    (loop for cur-char = (my-read-char) then (my-read-char)
       while (and (/= cur-char (char-code #\-))
                  (/= 0)
                  (or (< cur-char 48)
                      (> cur-char 57)))
       finally (if (<= 48 cur-char 57)
                   (setf result (- cur-char 48))
                   (setf is-negative t)))
    (loop for cur-char = (my-read-char) then (my-read-char)
       while (<= 48 cur-char 57)
       do (setf result (+ (* result 10) (- cur-char 48))))
    (when is-negative (setf result (- result)))
    result))

(defun main ()
  (let* ((n (my-read-int))
         (k (my-read-int))
         (a (make-array n :element-type 'int32))
         (dp (make-array n :element-type 'int32 :initial-element (+ (expt 10 9) 100))))
    (dotimes (i n)
      (setf (aref a i) (my-read-int)))
    (setf (aref dp 0) 0)
    (loop for i of-type int32 from 0 below n do
      (loop with from-val of-type int32 = (aref dp i)
         for j of-type int32 from (1+ i) to (+ i k)
         while (< j n)
         for nval of-type int32 = (+ from-val (abs (- (aref a i) (aref a j))))
         if (< nval (aref dp j))
         do
           (setf (aref dp j) nval)))
    (format t "~a~%" (aref dp (- n 1)))))

(main)

;; (defun main2 ()
;;   (let* ((n (the int32 (read)))
;;          (k (the int32 (read)))
;;          (a (make-array n :element-type 'int32))
;;          (dp (make-array n :element-type 'int32 :initial-element (+ (expt 10 9) 100))))
;;     (let ((stream (make-string-input-stream (read-line))))
;;       (loop for i from 0
;;          for j = (read stream nil) until (null j)
;;          do (setf (aref a i) (the int32 j)))
;;     (setf (aref dp 0) 0)
;;     (loop for i of-type int32 from 0 below n do
;;       (loop with from-val of-type int32 = (aref dp i)
;;          for j of-type int32 from (1+ i) to (+ i k)
;;          while (< j n)
;;          do
;;            (let ((nval (the int32 (+ from-val (abs (- (aref a i) (aref a j)))))))
;;              (setf (aref dp j) (min (aref dp j) nval)))
;;     (format t "~a~%" (aref dp (- n 1)))))



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

using namespace std;


#define MAXN 810
typedef pair<int, int> pii;
int h, w, k;
char a[MAXN][MAXN];
int d[MAXN][MAXN];
int dx[4] = {1,  0, -1,  0};
int dy[4] = {0, -1,  0,  1};

int intceil(int a, int b) {
  return a/b + (a%b>0);
}

void bfs(int i, int j) {
  priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>> > pq;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      d[i][j] = 1e9;
    }
  }
  pq.push({0, {i, j}});
  d[i][j] = 0;
  while(!pq.empty()) {
    auto u = pq.top();
    int cost = u.first;
    i = u.second.first;
    j = u.second.second;
    pq.pop();
    for (int di = 0; di < 4; ++di) {
      int ni = i+dy[di];
      int nj = j+dx[di];
      if (ni<0 || ni>h-1 || nj<0 || nj>w-1) continue;
      if (a[ni][nj]=='#') continue;
      int nc = cost + 1;
      if (d[ni][nj] > nc) {
        d[ni][nj] = nc;
        pq.push({nc, {ni, nj}});
      }
    }
  }
}


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int I, J, ans=1e9;
  cin >> h >> w >> k;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> a[i][j];
      if (a[i][j]=='S') {
        I = i;
        J = j;
      }
    }
  }
  bfs(I, J);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      //cout << d[i][j] << " ";
      if (d[i][j]<=k) ans = min(ans, intceil(min(min(i, h-1-i), min(j, w-1-j)), k)+1);
    }
    //cout << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3456
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const int INF = 1e9;

int main() {
  string w;
  cin >> w;
  map<char, int> m;
  for(char x: w) m[x]++;
  for(auto x: m) {
    if (x.second % 2 != 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
import sys
import math

n = int(input())
corrdinate = []
[corrdinate.append(list(map(int,input().split()))) for _ in range(n)]

total = 0
factorial = 1
for i in range(n):
    factorial *= n-i

fa = factorial / ((n))
for i in range(n):
    for j in range(i+1,n):
        xi = corrdinate[i][0]
        xj = corrdinate[j][0]
        yi = corrdinate[i][1]
        yj = corrdinate[j][1]
        total += math.sqrt( (xi - xj)**2 + (yi - yj)**2 ) * 2 * fa

print(total / (factorial ) )







Measured memory_bytes: 3064
#include<iostream>
#include<queue>
#include<utility>
#include<string>


using namespace std;

typedef pair<string ,int> proc;

int main(){
	int n,q,sumTime=0;
	queue< proc > que;
	cin >> n>>q;
	
	
	for(int i=0;i<n;i++){
		proc p;
		cin >> p.first;
		cin >> p.second;
		que.push(p);
	}
	
	
	while(!que.empty()){
		proc p=que.front();
		que.pop();
		if(p.second <= q){
			sumTime += p.second;
			cout << p.first << " " << sumTime << endl;
		}else{
			sumTime += q;
			p.second -= q;
			que.push(p);
		}
	}
	return 0;
	
}

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

int main(){
  vector<int> N(3);
  for(int i=0;i<3;i++) cin>>N[i];
  vector<int> V={5,7,5};
  int check = 0;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++)
      if(N[j]==V[i]){
        check++;
        N[j] = 0;
        break;
      }
  }
  if(check==3)cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

using namespace std;

int main()
{
    int a, b, c, x, y;
    long long int ans = 0;

    cin >> a >> b >> c >> x >> y;

    if (a + b > c * 2) {
        ans += c*2*min(x, y);
        if (x > y) {
            if (a > c*2) {
                ans += (x-y)*c*2;
            }
            else {
                ans += (x-y)*a;
            }
        }
        else if (x < y) {
            if (b > c*2) {
                ans += (y-x)*c*2;
            }
            else {
                ans += (y-x)*b;
            }
        }
    }
    else {
        ans += a * x + b * y;
    }

    cout << ans << endl;
}


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

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
int al[26];

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  string s;
  fill(al, al + 26, inf);
  for(int i = 0; i < n; i++){
    cin >> s;
    vector<int> vec = vector<int>(26, 0);
    for(char c: s){
      vec[c - 'a']++;
    }
    for(int i = 0; i < 26; i++){
      al[i] = min(al[i], vec[i]);
    }
  }
  for(int i = 0; i < 26; i++){
    for(int j = 0; j < al[i]; j++){
      cout << char('a' + i);
    }
  }
  cout << endl;
	return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())

sum = 0
for n in range(1, N+1):
  n = '0000' + str(n)
  a, b, c, d, e = int(n[-5]), int(n[-4]), int(n[-3]), int(n[-2]), int(n[-1])
  if A <= a + b + c + d + e <= B:
    sum += int(n)
print(sum)

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			TreeSet<Integer> S = new TreeSet<Integer>();
			int q = sc.nextInt();
			for(int i = 0; i < q; i++) {
				int cmd = sc.nextInt();
				int x = sc.nextInt();
				if(cmd == 0) {
					S.add(x);
					System.out.println(S.size());
				}
				else if(cmd == 1){
					System.out.println(S.contains(x) ? "1" : "0");
				}
				else if(cmd == 2) {
					S.remove(x);
				}
				else /* cmd == 3 */{
					int r = sc.nextInt();
					S.subSet(x,true, r, true).forEach(xx->System.out.println(xx));
				}
			}
		}
	}
}



Measured memory_bytes: 187336
#include <iostream>

using namespace std;
struct node{
    char type;
    bool value;
    node *left, *right;
    node(){
        type='\0';
        value=false;
        left=right=NULL;
    }
    ~node(){
        if(left!=NULL) delete left;
        if(right!=NULL) delete right;
    }
};

node *root;

int rec(node* p, int i, string str){
    if(i==str.size())return -1;
    if(p->type=='='){
        p->left=new node();
        i=rec(p->left,i,str)+2;
        p->right=new node();
        i=rec(p->right,i,str);
        return -1;
    }
    if(str[i]=='F'||str[i]=='T'){
        p->type='C';
        p->value=str[i]=='T';
        return i;
    }
    if(str[i]=='-'){
        p->type='-';
        p->left=new node();
        return rec(p->left,i+1,str);
    }
    if(str[i]>='a'&&str[i]<='k'){
        p->type=str[i];
        return i;
    }
    if(str[i]=='('){
        p->left=new node();
        i=rec(p->left,i+1,str)+1;
        if(str[i]=='-'){
            p->type=str[++i];
        }else{
            p->type=str[i];            
        }
        p->right=new node();
        i=rec(p->right,i+1,str)+1;
        return i;
    }
    return i;
}
bool b[11];

bool rec2(node*p){
    if(p->type=='=') return rec2(p->left)==rec2(p->right);
    if(p->type=='C') return p->value;
    if(p->type>='a'&&p->type<='k') return b[p->type-'a'];
    if(p->type=='-') return !rec2(p->left);
    if(p->type=='*') return rec2(p->left)&&rec2(p->right);
    if(p->type=='+') return rec2(p->left)||rec2(p->right);
    if(p->type=='>') return !(rec2(p->left)&&!rec2(p->right));
    return false;
}

int main(){
    string str;
    node *p;
    while(cin>>str,str[0]!='#'){
        if(root!=NULL) delete root;
        root=new node();
        root->type='=';
        rec(root,0,str);
        bool ans=true;
        for(int i=0;i<(1<<11);i++){
            for(int j=0;j<11;j++){
                b[j]=(bool)(i&(1<<j));
            }
            if(!rec2(root)){
                ans=false;
                break;
            }
        }
        if(ans){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

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

int main () {
  int K;
  cin >> K;
  
  if (K % 2 == 1) {
    cout << (K-1)*(K+1)/4 << endl;
  }
  else {
    cout << K * K / 4 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n, k;
    cin >> n >> k;
    vector<int> score(3);
    for(int i = 0; i < 3; ++i)  cin >> score[i];
    string t;
    cin >> t;
    vector<int> order(n);
    for(int i = 0; i < n; ++i){
        if(t[i] == 'r') order[i] = 0;
        else if(t[i] == 's')    order[i] = 1;
        else    order[i] = 2;
    }

    // dp[i][j] := (i - k) 番目に、手 j を出したときのスコア
    vector<vector<int>> dp(n + 1, vector<int>(3, 0));
    for(int i = 0; i < n; ++i){
        if(i + k <= n){
            for(int j = 0; j < 3; ++j){
                int preval;
                if(i < k)   preval = 0;
                else{
                    preval = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]);
                }
                if((j + 1) % 3 == order[i]){
                    dp[i + k][j] += preval + score[j];
                }
                else{
                    dp[i + k][j] += preval;
                }
            }
        }
        else{
            int val = 0;
            for(int j = 0; j < 3; ++j){
                int sum = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]);
                if((j + 1) % 3 == order[i]){
                    sum += score[j];
                }
                chmax(val, sum);
            }
            for(int j = 0; j < 3; ++j){
                dp[n][j] += val;
            }
        }
    }
    // for(int j = 0; j < 3; ++j){
    //     for(int i = 0; i <= n; ++i){
    //         cerr << dp[i][j] << ' ';
    //     }
    //     cerr << '\n';
    // }
    int ans = max({dp[n][0], dp[n][1], dp[n][2]});
    cout << ans << endl;
}

Measured memory_bytes: 6224
def gcd(x,y):
    a=max(x,y)
    b=min(x,y)
    r=a%b
    if r==0:
        return b
    else:
        return gcd(b,r)

def extd_gcd(numbers):
    from functools import reduce
    return reduce(gcd,numbers)

if __name__ == '__main__':
    N=int(input())
    Monsters=list(map(int,input().split()))
    print(extd_gcd(Monsters))



Measured memory_bytes: 62832
#include<bits/stdc++.h>
using namespace std;
const int N=100000+5;
int sum[N];
int main(){
	for(int i=1;i<=N;i++)
	   sum[i]=sum[i-1]+i;
	int x;
	cin>>x;
	int pos;
	pos=lower_bound(sum+1,sum+N+1,x)-sum;
	cout<<pos;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF 1000000000
#define EPS      1e-10
#define MOD      1000003
#define HOGE 100000
#define HUGA 100000
using namespace std;
typedef long long ll;
typedef pair<double,double> P;
typedef pair<double,P> PQ;

int n;
int a[1000];

int main(){
    cin >> n;
    rep(i,n) cin >> a[i];
    int ans = -1;
    rep(i,n){
        for(int j = i+1; j < n; j++){
            int num = a[i]*a[j];
            int tmp = num;
            if(num > ans){
                bool ok = true;
                int z = num%10;
                num /= 10;
                while(num > 0){
                    if(num%10 == z-1){
                        z--;
                    } else{
                        ok = false;
                        break;
                    }
                    num /= 10;
                }
                if(ok) ans = tmp;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3052
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n, a;
  	cin >> n >> a;
  	if(n%500 <= a) puts("Yes");
  	else puts("No");
	return;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 600, mod = 1e9 + 7;
int n, cnt, is[maxn + 10];
int a[maxn + 10];
int f[maxn + 10][maxn + 10], g[maxn + 10][maxn + 10];

inline void addto(int &x, int y) {
	x += y; if (x >= mod) x -= mod;
}

void addin(int d) {
	if (d == 2) return;
	memset(g, 0, sizeof g);
	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= n; ++j)
			if (f[i][j]) {
				if (d == 0) {
					addto(g[i][j + 1], f[i][j]);
					if (i) addto(g[i - 1][j], 1ll * f[i][j] * i % mod);
					if (j) addto(g[i][j - 1], f[i][j]);
				} else {
					addto(g[i + 1][j], f[i][j]);
					if (j) addto(g[i][j - 1], f[i][j]);
				}
			}
	memcpy(f, g, sizeof g);
}

int main() {
	scanf("%d", &n);
	n *= 2;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		if (a[i] != -1) is[a[i]] = 1;
		if (i % 2 == 0) {
			if (a[i] != -1 && a[i - 1] != -1)
				is[a[i]] = is[a[i - 1]] = 2;
			if (a[i] == -1 && a[i - 1] == -1)
				++cnt;
		}
	}
	f[0][0] = 1;
	for (int i = n; i >= 1; --i) addin(is[i]);
	int ans = f[0][0];
	for (int i = 1; i <= cnt; ++i)
		ans = 1ll * ans * i % mod;
	printf("%d", ans);
}


Measured memory_bytes: 3200
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define LONG_INF 800000000000000000
vector<int> vertexs[10];
int main() {
	int n, m;
	cin >> n >> m;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		vertexs[a].push_back(b);
		vertexs[b].push_back(a);
	}
	int ans = 0;
	queue<pair<int, int>> wow;
	wow.push(make_pair(1, 1));
	while (wow.empty() == false) {
		pair<int, int> hoge = wow.front();
		wow.pop();
		if (hoge.second == (1 << n) - 1) {
			ans++;
			goto ooo;
		}
		for (int j = 0;j < vertexs[hoge.first].size();++j) {
			if (((1 << (vertexs[hoge.first][j]-1))&hoge.second) == 0) {
				wow.push(make_pair(vertexs[hoge.first][j], (1 << (vertexs[hoge.first][j]-1)) + hoge.second));
			}
		}
	ooo:;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
typedef long long ll;
/*
    problem : http://abc058.contest.atcoder.jp/tasks/arc071_b
*/
int n, m;
const int MOD = 1e9 + 7;
ll calc(int num)
{
	VI A(num);
	REP(i, 0, num) cin >> A[i];

	ll res = 0;
	REP(i, 1, num){
		res += ((ll)(A[i]-A[i-1]) * i) % MOD * (num-i);
		res %= MOD;
	}

	return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n >> m;


	ll sumX = calc(n), sumY = calc(m);
	
	cout << (sumX * sumY) % MOD << endl;

	return 0;
}

Measured memory_bytes: 640
#define I(X,C)\
X##xm=X##ym=9999,X##xM=X##yM=-9999;\
for(scanf("%d",&C),i=0;i<C;i++){\
  scanf("%d%d",X[i],X[i]+1);\
  if(X##xm>X[i][0])X##xm=X[i][0];\
  if(X##ym>X[i][1])X##ym=X[i][1];\
  if(X##xM<X[i][0])X##xM=X[i][0];\
  if(X##yM<X[i][1])X##yM=X[i][1];\
}for(i=0;i<C;i++)X[i][0]-=X##xm,X[i][1]-=X##ym;X##xM-=X##xm,X##yM-=X##ym;

m[10][2],x[10][2],z[10][2],zz[10][2];
rx[4][2]={{1,0},{0,-1},{-1,0},{0,1}};
ry[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
mv[4][2]={{0,0},{0,0},{0,0},{0,0}};

main(N,M,Z,t,i,j,k,mxm,mym,mxM,myM,zxm,zym,zxM,zyM){
  for(;scanf("%d",&N),N;puts("+++++")){
    I(z,Z)
    for(i=0;i<Z;i++)zz[Z-1-i][0]=z[i][0],zz[Z-1-i][1]=z[i][1];
    for(j=0;j<N;j++){
      I(m,M)
      if(M!=Z)continue;
      mv[1][0]=myM,mv[2][0]=mxM,mv[2][1]=myM,mv[3][1]=mxM;
      for(k=0;k<4;k++){
        for(i=0;i<M;i++)x[i][0]=rx[k][0]*m[i][0]+rx[k][1]*m[i][1]+mv[k][0],x[i][1]=ry[k][0]*m[i][0]+ry[k][1]*m[i][1]+mv[k][1];
        if(!memcmp(x,z,4*2*M)||!memcmp(x,zz,4*2*M))printf("%d\n",j+1),k=4;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;

int main() {
	long N, K;
	cin >> N >> K;
	long *a = new long[N];// 入力
	long w = 0, b = 0;
	long sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if (a[i] > 0) {
			sum += a[i];
		}
	}
	for (int i = 0; i < K; i++) {
		if (a[i] > 0) {
			w += a[i];
		}
		else if (a[i] < 0) {
			b -= a[i];
		}
	}
	
	long wmin = w, bmin = b;
	for (int i = K; i < N; i++) {
		if (a[i] > 0) {
			w += a[i];
		}
		else if (a[i] < 0) {
			b -= a[i];
		}
		if (a[i - K] > 0) {
			w -= a[i - K];
		}
		else if (a[i - K] < 0) {
			b += a[i - K];
		}

		wmin = min(wmin, w);
		bmin = min(b, bmin);
	}

	cout << sum - min(wmin, bmin) << endl;

	return 0;
}

Measured memory_bytes: 1024
N=int(input())
def func(n,a):
    cnt=0
    while n!=0:
        r=n%a
        n=(n-r)//a
        cnt+=r
    return cnt

ans=N
for i in range(N+1):
    tmp=func(i,6)+func(N-i,9)
    ans=min(ans,tmp)
print(ans)


Measured memory_bytes: 41068
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cfloat>
#include <cmath>
#include <functional>
#include <forward_list>
#include <list>


#define DEBUG(x) cout << #x << "\t:" << x << endl;
#define EPS (1e-9)
#define INF (INT_MAX/3)
#define MOD 1000000007
#define PI 3.14159265358979
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REPV(it,v) for(auto it = (v).begin(); it != (v).end(); ++it)

#define NUM 5000

#define ll long long
#define ull unsigned long long

using namespace std;

typedef pair<int, int> iiPair;


class Main {
public:
	int compare = 0;

	vector<int> merge(vector<int>& as, vector<int>& bs) {
		vector<int> ret;

		int ia=0;
		int ib=0;
		while (ia < as.size() && ib < bs.size()) {
			if (as[ia] <= bs[ib]) {
				ret.push_back(as[ia]);
				ia++;
				compare++;
			}
			else {
				ret.push_back(bs[ib]);
				ib++;
				compare++;
			}
		}

		while (ia < as.size()) {
			ret.push_back(as[ia]);
			ia++;
			compare++;
		}

		while (ib < bs.size()) {
			ret.push_back(bs[ib]);
			ib++;
			compare++;
		}

		return ret;
	}

	vector<int> mergeSort(vector<int>& as) {
		if (as.size() <= 1) {
			return as;
		}

		int mid = as.size() / 2;
		vector<int> former, latter;
		REP(i, as.size()) {
			if (i < mid) {
				former.push_back(as[i]);
			}
			else {
				latter.push_back(as[i]);
			}
		}

		former = mergeSort(former);
		latter = mergeSort(latter);
		vector<int> ret = merge(former, latter);

		return ret;
	}
};

int main(void) {
	Main main;
	int n;
	vector<int> as;
	cin >> n;
	REP(i, n) {
		int inp;
		cin >> inp;
		as.push_back(inp);
	}

	auto ans = main.mergeSort(as);
	REP(i, n) {
		cout << ans[i];
		if (i <= n - 2) cout << " ";
	}
	cout << endl;
	cout << main.compare << endl;

	return 0;
}

Measured memory_bytes: 11656
#include <stdlib.h>
#include <stdio.h>
int compare(const void *a,const void *b){
    if(*(int *)a>*(int *)b)return 1;
    return -1;
}
int main()
{   int n;
    scanf("%d",&n);
    int a[n+1];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    a[n]=0;
    qsort(a,n,sizeof(int),compare);
    int sub=1,ans=0;
    for(int i=0;i<n;i++){
        if(a[i]==a[i+1]){
            sub++;
        }else{
            ans+=sub%2;
            sub=1;
        }
    }
    printf("%d",ans);

    return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  ll a,b;
  int k;
  cin >> a >> b >> k;
  bool taka=true;
  rep(i,k){
    if(taka){
      if(a%2==1) a--;
      b+=a/2;
      a/=2;
      taka=false;
    }

    else{
      if(b%2==1) b--;
      a+=b/2;
      b/=2;
      taka=true;
    }
  }
  cout << a << ' ' << b << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [ int(i) for i in input().split() ]
if n == 1:
    print(0)
    import sys
    sys.exit()
ans = []
for i in range(1,n):
    if a[i] > a[i-1]:
        ans.append(0)
    else:
        ans.append(1)


dp = [ 0 for i in range(n-1) ]
dp[0] = ans[0]
for i in range(1,n-1):
    if ans[i] == 0:
        dp[i] = 0
    else:
        dp[i] = 1 + dp[i-1]

print(max(dp))


Measured memory_bytes: 14224
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    abc = MII()
    abc.sort()
    c = abc[2]
    a = c-abc[0]
    b = c-abc[1]
    cnt = (-(-(a-b)//2))+b
    if (a-b)%2==1: cnt+=1
    print(cnt)


if __name__ == '__main__':
    main()


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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<(n);i++)
#define rep2(i, m, n) for(int i=m;i<(n);i++)
#define rrep(i, n, m) for(int i=n;i>=(m);i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S;
    cin >> S;
    int first = (S[0] - '0') * 10 + (S[1] - '0');
    int second = (S[2] - '0') * 10 + (S[3] - '0');

    if (1 <= first && first <= 12){
        if (1 <= second && second <= 12){
            cout << "AMBIGUOUS" << endl;
        }else{
            cout << "MMYY" << endl;
        }
    }else{
        if (1 <= second && second <= 12){
            cout << "YYMM" << endl;
        }else{
            cout << "NA" << endl;
        }
    }

}

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


Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    L = I()

    # if L % 3 == 0:
    #     l = L // 3
    #     print(l**3)
    #     return


    l = L / 3
    # print(l)
    print(l**3)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38640
import math

A,B,H,M = map(float, input().split())
p = abs(30*H-5.5*M)
p = min(360-p,p)
p *= (math.pi/180.0)
ans = math.sqrt((A-B*math.cos(p))**2 + (B*math.sin(p))**2)

print(ans)

Measured memory_bytes: 9504
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  if(S=="RRR"){
    cout << 3 << endl;
  }else if(S=="RRS" || S=="SRR" ){
    cout << 2 << endl;
  }else if( S=="RSS" || S=="SRS" || S=="SSR" ||S=="RSR" ){
    cout << 1 << endl;
  }else if(S=="SSS"){
    cout << 0 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3604
// https://beta.atcoder.jp/contests/abc107

#define SUBMIT
#define DEBUG

#include <utility>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <map>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

const int MAX_SIDE = 100;
int H, W;
char field[MAX_SIDE][MAX_SIDE];

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    string program_input_str = R"(7 6
......
....#.
.#....
..#...
..#...
......
.#..#.
)";
    stringstream stream(program_input_str);
#endif
    stream >> H >> W;
    for (int y = 0; y < H; ++y) {
        for (int x = 0; x < W; ++x) {
            stream >> field[y][x];
        }
    }

    vector<int> print_rows;
    for (int y = 0; y < H; ++y) {
        bool contains_black = false;
        for (int x = 0; x < W; ++x) {
            if (field[y][x] == '#') contains_black = true;
        }

        if (contains_black) print_rows.push_back(y);
    }

    vector<int> print_cols;
    for (int x = 0; x < W; ++x) {
        bool contains_black = false;
        for (int y = 0; y < H; ++y) {
            if (field[y][x] == '#') contains_black = true;
        }

        if (contains_black) print_cols.push_back(x);
    }

    for (auto y : print_rows) {
        for (auto x : print_cols) {
            cout << field[y][x];
        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;

#define TT template<typename T>
#define ET(T) typename T::value_type
TT inline T sq(T x){return x*x;}
TT inline T In(){T x;cin>>x;return x;}
TT inline int ubnd(T&v,ET(T) x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT inline int lbnd(T&v,ET(T) x){return lower_bound(begin(v),end(v),x)-begin(v);}
TT inline void sort(T&v){sort(begin(v),end(v));}
TT inline void revs(T&v){reverse(begin(v),end(v));}
TT inline void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT inline void inpt(T&v,int n,function<ET(T)()>f=In<ET(T)>){for(v.reserve(n);n--;v.emplace_back(f()));}
TT inline void show(T&v,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),cout<<x;cout<<e;}
#undef TT
#undef ET

inline void fast_io(){ios::sync_with_stdio(0); cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline string instr(){string x;cin>>x;return x;}
inline ll pow_mod(ll a, ll k, ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a, ll p){return pow_mod(a,p-2,p);}

const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000;

int mcxi_to_int(const string& s)
{
  int table[256] = {};
  table['m'] = 1000;
  table['c'] = 100;
  table['x'] = 10;
  table['i'] = 1;
  int v = 1;
  int r = 0;
  for (const auto& c : s){
    if (isdigit(c)) v = c - '0';
    else {
      r += table[c] * v;
      v = 1;
    }
  }
  return r;
}

string int_to_mcxi(int x)
{
  stringstream ss;
  for (int i = 0; x > 0; i++){
    int v = x % 10;
    if (v){
      ss << "ixcm"[i];
      if (v != 1){
        ss << v;
      }
    }
    x /= 10;
  }
  string s = ss.str();
  revs(s);
  return s;
}

int main()
{
  int n = in();
  for (int i = 0; i < n; i++){
    string a, b;
    cin >> a >> b;
    cout << int_to_mcxi(mcxi_to_int(a) + mcxi_to_int(b)) << endl;
  }

  return (0);
}

// priority_queue queue deque front top push pop map set stringstream max_element min_element insert count find get tie make_tuple

Measured memory_bytes: 1240
#include <stdio.h>
#include <stdint.h>

#define MOD_BY 1000000007

int add(int a, int b) {
	return a + b - (a + b >= MOD_BY ? MOD_BY : 0);
}

int sub(int a, int b) {
	return b == 0 ? a : add(a, MOD_BY - b);
}

int mul(int a, int b) {
	return (int)(((int64_t)a * b) % MOD_BY);
}

int pou(int a, int b) {
	int r = 1;
	while (b > 0) {
		if (b & 1) r = mul(r, a);
		a = mul(a, a);
		b >>= 1;
	}
	return r;
}

int inv(int a) {
	return pou(a, MOD_BY - 2);
}

int dexibu(int a, int b) {
	return mul(a, inv(b));
}

int gcd(int a, int b) {
	while (b > 0) {
		int r = a % b;
		a = b;
		b = r;
	}
	return a;
}

int N, K;

int kazu(int baisu) {
	return pou(K / baisu, N);
}

int asumi[114514];

int main(void) {
	int i, j;
	int kotae = 0;
	if (scanf("%d%d", &N, &K) != 2) return 1;

	for (i = K; i >= 1; i--) {
		asumi[i] = kazu(i);
		for (j = i + i; j <= K; j += i) {
			asumi[i] = sub(asumi[i], asumi[j]);
		}
	}

	for (i = 1; i <= K; i++) {
		kotae = add(kotae, mul(i, asumi[i]));
	}

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

/*

gcdがx → A_1, ... , A_N がxの倍数

公約数にxがある → x以外のxの倍数が公約数にないなら、gcdがx (予想)

ユークリッドの互除法は速いのできっとなんとかなる

*/


Measured memory_bytes: 2096
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <stack>
#include <set>
#include <algorithm>
using namespace std;
#define ll long long int

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if ( a < c && c < b ) {
    cout << "Yes" << endl;  
  } else if ( b < c && c < a) {
    cout << "Yes" << endl;  
  }else {
    cout << "No" << endl;  
  }
  return 0;
}



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

struct gr
{
    string s;
    int i=0,j;
    char ch;
};

void game(gr a,gr b,gr c,int t){
    gr temp;
    if(t==1){ 
        a.j--;
        temp=a;
        a.i++;
    }
    if(t==2){ 
        b.j--;
        temp=b;
        b.i++;
    }
    if(t==3){ 
        c.j--;
        temp=c;    
        c.i++;
    }
    if(temp.j==-1){
       cout << temp.ch;
       return ;
   }
    switch(temp.s.at(temp.i))
   {
       case 'a' :
                    //cout << 1;
                    game(a,b,c,1);
                    break;
       case 'b' :
                    //cout << 2;
                    game(a,b,c,2);
                    break;
       case 'c' :  
                    //cout <<3;
                    game(a,b,c,3);
                    break;
   }
   
   
}


int main()
{
   gr a,b,c;
   cin >> a.s ;
   cin >> b.s ;
   cin >> c.s ;
   a.j=a.s.length();
   b.j=b.s.length();
   c.j=c.s.length();
   //cout << a.j << b.j << c.j ;
   a.ch='A';
   b.ch='B';
   c.ch='C';
   game(a,b,c,1);
   
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  int count;
  cin >> A >> B;
  
  for( int i = A; i <= B; i++) {
    int d1,d2,d3,d4,d5;
    int j ;
    
    d1 = i / 10000;
    d2 = i % 10000 / 1000;
    d3 = i %  1000 /  100;
    d4 = i %   100 /   10;
    d5 = i %    10;
    
    if ( d1 > 0 ) {
      j = d5 * 10000 + d4 * 1000 + d3 * 100 + d2 * 10 + d1;
    } else if ( d2 > 0 ) {
      j = d5 * 1000 + d4 * 100 + d3 * 10 + d2;
    } else if ( d3 > 0 ) {
      j = d5 * 100 + d4 * 10 + d3;
    } else if ( d4 > 0 ) {
      j = d5 * 10 + d4;
    } else if ( d5 > 0 ) {
      j = d5;
    }    
    if ( i == j ) {
      count++;
    }  
  }
  cout << count << endl;
}

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

int main(){
  int N,Q;
  string S;
  cin>>N>>Q>>S;

  vector<int> l(Q),r(Q);
  for(int i=0;i<Q;i++){
    cin>>l[i]>>r[i];
  }
  vector<int> ruiseki(N+1);
  ruiseki[0]=0;
  for(int i=1;i<N;i++){
    if(S[i-1]=='A'&&S[i]=='C') ruiseki[i]=ruiseki[i-1]+1;
    else ruiseki[i]=ruiseki[i-1];
  }
  ruiseki[N]=ruiseki[N-1];
  
  int ans;
  for(int i=0;i<Q;i++){
    ans=ruiseki[r[i]-1]-ruiseki[l[i]-1];
    cout<<ans<<endl;
  }

  return 0;
}


Measured memory_bytes: 2176
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int a = scan.nextInt();
			int b = scan.nextInt();
			if(a == 0 && b == 0){
				break;
			}
			int s = b - a;
			if(s == 0){
				System.out.println("0 0 0");
				continue;
			}
			int x = 0;
			int y = 0;
			int z = 0;
			if(s >= 1000){
				x = s / 1000;
				s %= 1000;
			}
			if(s >= 500){
				y = s / 500;
				s %= 500;
			}
			if(s >= 100){
				z = s / 100;
				s %= 100;
			}
			System.out.println(z + " " + y + " " + x);
		}
	}
}

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

using namespace std;

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s, t, u;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    cin >> u;
    if (s == u) a--;
    else b--;
    cout << a << " " << b << endl;
    return 0;
}


Measured memory_bytes: 256
S = input()

abv_list = []
prev_c = ""

for c in list(S) :
    if len(abv_list) == 0 :
        abv_list.append(c)
        prev_c = c
    else :
        if c != prev_c :
            abv_list.append(c)
        prev_c = c
    
print(0 if len(abv_list) == 1 else abv_list.count('B') + abv_list.count('W') - 1)

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

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> D;
    int tmp;
    for(int i=0;i<K;i++){
        cin >> tmp;
        D.push_back(tmp);
    }
    vector<int> use;
    int flag;
    for(int i=0;i<10;i++){
        flag = 0;
        for(int k=0;k<D.size();k++){
            if(i == D[k]){
                flag++;
                break;
            }
        }
        if(flag == 0) use.push_back(i);
    }
    int keta=1;
    tmp = N;
    while(tmp > 9){
        tmp /= 10;
        keta ++;
    }

    /*
    cout << "use:" ;
    for(int i=0;i<use.size();i++) cout << use[i];
    cout << endl;
    */

    string s = to_string(N);
    string answer = "";
    int f;
    for(int i=0;i<s.size();i++){
        tmp = s[i] - '0';
        f = 0;
        for(int j=0;j<use.size();j++){
            if(tmp == use[j]){
                answer += use[j] + '0';
                f ++;
                break;
            }else if(tmp < use[j]){
                answer += use[j] + '0';
                for(int k=0;k<s.size()-i-1;k++) answer += use[0] + '0';
                //cout << "a" << endl;
                cout << answer << endl;
                return 0;
            }
        }

        if(f == 0){
            if(use[0] == 0){
                cout << use[1];
                for(int j=0;j<keta;j++) cout << use[0];
            }else{
                for(int j=0;j<keta+1;j++)cout << use[0];
            }
            return 0;
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256