akhauriyash/Code-Regression huggingface dataset:
# def C(n, r ,mod=10**9+7):
#     if n-r<r: r=n-r
#     if r == 0: return 1
#     if r == 1: return n
# 
#     numerator = [n - r + k + 1 for k in range(r)]
#     denominator = [k + 1 for k in range(r)]
# 
#     for p in range(2,r+1):
#         pivot = denominator[p - 1]
#         if pivot > 1:
#             offset = (n - r) % p
#             for k in range(p-1,r,p):
#                 numerator[k - offset] /= pivot
#                 denominator[k] /= pivot
# 
#     result = 1
#     for k in range(r):
#         if numerator[k] > 1:
#             result *= int(numerator[k]) %mod
# 
#     return result % mod

A=list(input())
n=len(A)
mod=10**9+7
ans=0
numa= A[0]=="A" 
numa_= A[0]=="?"
numc=A[2:].count("C")
numc_= A[2:].count("?")

for i in range(1,n-1):
    #print(numa,numa_,numc,numc_)
    apro=cpro=0
    if A[i]=="B" or A[i]=="?":
        # for k in range(numa_+1):
        #     apro+= (((C(numa_,k)*pow(2,numa_-k,mod))%mod)*(numa+k))%mod
        # for k in range(numc_+1):
        #     cpro+= (((C(numc_,k)*pow(2,numc_-k,mod))%mod)*(numc+k))%mod
        #print(apro,cpro)
        apro= ((3*numa+numa_)*pow(3,(numa_-1),mod))%mod
        cpro= ((3*numc+numc_)*pow(3,(numc_-1),mod))%mod
        ans+= (apro*cpro)%mod
        ans%=mod
    if A[i] == "A":
        numa+=1
    if A[i]=="?":
        numa_+=1
    if A[i+1] =="C":
        numc-=1
    if A[i+1]=="?":
        numc_-=1
print(ans)


Measured memory_bytes: 10360
S = list(input())
N = len(S)

# Rについて、左から右に順に数えていく
r_counter = [0]*N
start = 0
even, odd = 0, 0
for i, s in enumerate(S):
    if s == 'R':
        if (i-start) % 2 == 0:
            even += 1
        else:
            odd += 1
    else:
        if even > 0 or odd > 0:
            if (i-start) % 2 == 0:
                r_counter[i] += even
                r_counter[i-1] += odd
            else:
                r_counter[i] += odd
                r_counter[i-1] += even
            even, odd = 0, 0
        start = i

# Lについて、右から左に順に数えていく
l_counter = [0]*N
start = 0
even, odd = 0, 0
for i, s in enumerate(S[::-1]):
    if s == 'L':
        if (i-start) % 2 == 0:
            even += 1
        else:
            odd += 1
    else:
        if even > 0 or odd > 0:
            if (i-start) % 2 == 0:
                l_counter[i] += even
                l_counter[i-1] += odd
            else:
                l_counter[i] += odd
                l_counter[i-1] += even
            even, odd = 0, 0
        start = i

for i, j in zip(r_counter, l_counter[::-1]):
    print(i+j, end=' ')

Measured memory_bytes: 7196
#include<iostream>
#include<vector>

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n+1),b(n+1); 
  for(int i = 1; i <= n; i++){
    cin >> a[i];
    b[i] = 0;
  }

  int m = 0;
  for(int i = n; i > 0; i--){
    int c = 0;
    for(int j = i*2;j <= n; j += i)
      c = (c + b[j] ) % 2;
    if(a[i] != c){
      b[i] = 1;
      m++;
    }
  }

  cout << m << endl;
  for(int i = 1; i <= n; i++){
    if( b[i] == 1)
      cout << i << ' ';
  }
  cout << endl;
  
}


Measured memory_bytes: 2432
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        int H,W;
    	//?¨??????\??????????????????????????§????????????
		Scanner scanner = new Scanner(System.in);
		
		while(true){
			H = scanner.nextInt();
			W = scanner.nextInt();
			
			if(H == 0 && W == 0){
				break;
			}
			
			for(int i = 0; i < H;i++){
				for(int j = 0; j < W; j++){
					if((i+j)%2 == 0){
						System.out.print("#");	
					}
					else{
						System.out.print(".");
					}
									
				}
				System.out.println();
			}
			System.out.println();
		}
    	scanner.close();
    }
}

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

using namespace std;

typedef long long ll;

const ll INF = 1e13;

template <typename T>
struct SegmentTree {
    int n;
    vector<T> data;

    //使うときは、この3つを適宜変更する
    static T INITIAL_VALUE;
    static T merge(T x, T y); 
    void updateNode(int k, T x);

    SegmentTree(int size) {
        n = 1;
        while (n < size) n *= 2;
        data.resize(2 * n - 1, INITIAL_VALUE);
    }

    T getLeaf(int k) {
        return data[k + n - 1];
    }
    
    void update(int k, T x) {
        k += n - 1; //葉の節点
        updateNode(k, x);
        while (k > 0) {
            k = (k - 1) / 2;
            data[k] = merge(data[k * 2 + 1], data[k * 2 + 2]);
        }
    }
    
    //区間[a, b)に対するクエリに答える
    //k:節点番号, [l, r):節点に対応する区間
    T query(int a, int b, int k, int l, int r) {
        //[a, b)と[l, r)が交差しない場合
        if (r <= a || b <= l) return INITIAL_VALUE;
        //[a, b)が[l, r)を含む場合、節点の値
        if (a <= l && r <= b) return data[k];
        else {
            //二つの子をマージ
            T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return merge(vl, vr);
        }
    }
    
    //外から呼ぶ用
    T query(int a, int b) {
        return query(a, b, 0, 0, n);
    }
};

//使うときは以下3つを変更
template <typename T>
T SegmentTree<T>::INITIAL_VALUE = INF;

template <typename T>
T SegmentTree<T>::merge(T x, T y) {
    return min(x, y);
}

template <typename T>
void SegmentTree<T>::updateNode(int k, T x) {
    data[k] = x;
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	ll a;
	cin >> n >> q >> a;
	a--;
	vector<ll> x(q + 1);
	cin >> x[0];
	x[0]--;
	for (int i = 1; i <= q; i++) {
		cin >> x[i];
		x[i]--;
	}

	SegmentTree<ll> st1(n), st2(n);

	st1.update(a, -a);
	st2.update(a, a);

	ll add = 0;
	for (int i = 1; i <= q; i++) {
		ll tmp = INF;
		tmp = min(tmp, st1.query(0, x[i]) + x[i]);
		tmp = min(tmp, st2.query(x[i], n) - x[i]);
		tmp += add;
		add += abs(x[i] - x[i - 1]);
		ll tar = st1.getLeaf(x[i - 1]) + x[i - 1] + add;
		if (tar <= tmp) continue;
		tmp -= add;
		st1.update(x[i - 1], tmp - x[i - 1]);
		st2.update(x[i - 1], tmp + x[i - 1]);
	}

	ll ans = INF;
	for (int i = 0; i < n; i++) {
		ans = min(ans, st1.getLeaf(i) + i);
	}
	ans += add;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9984
import scala.io.StdIn._

object Main extends App {
  val Array(n, x) = readLine().split(' ').map(_.toInt)
  val ms = for {
    _ <- 0 until n
  } yield readInt()

  val s = ms.sum
  val r = x - s
  println(r / ms.min + ms.length)
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N) cin >> A.at(i);
  vector<int> cnt(M);
  for (int x: A) {
    if (cnt.at(x) != 0) {
      cnt.at(x) = 2;
      continue;
    }
    for (int i = x; i < M ; i+=x){
      cnt.at(i)++;
    }
  }
  int ans = 0;
  for (int x: A) {
    if (cnt.at(x) == 1) ans++;
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 8008
#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 repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  int k;
  string s;
  cin >> k >> s;
  if (s.size() <= k)
    cout << s << endl;
  else {
    rep(i, k) {
      cout << s[i];
    }
    cout << "..." << endl;
  }
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int  long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
using namespace std;
/// age ye mosh dp ro baze dashti dp tedad baz shodeye baste nashode yadet nare !!

int32_t main(){
    ll n,a,b;
    cin >> n >> a >> b;
    if (a<b) swap(a,b);
    if ((a-b)%2==0){
        cout << (a-b)/2;
        return 0;
    }
    ll ans=b+(a-b-1)/2;
    ans=min(ans,n-a+1+(a-b-1)/2);
    cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int len, ans, nowmax;
int h[20];
int main(){
	cin >> len;
	for(int i = 0;i < len;++i){
		cin >> h[i];
		if(h[i] >= nowmax){
			++ans;
			nowmax = h[i];
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 256
N = int(input())
c = 0
b = [0]*1000
p = 0
while N % 2 == 0:
  b[p] += 1
  N //= 2
if b[p]!=0:
  p += 1
i = 3
while i * i <= N:
  if N % i == 0:
    b[p] += 1
    N //= i
  else:
    i += 2
    if b[p]!=0:
      p += 1
if N==i:
  b[p] += 1
  N //= i
if N!=1:
  p += 1
  b[p] += 1
for v in b:
  for i in range(1,v+1):
    if i<=v:
      c += 1
      v -= i
    else:
      break
print(c)

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


int main(){
  int x=0;
 char s[4];
  scanf("%s",s);
  for (int i = 0; i < 4; i++) {
    if(s[i]=='+'){
      x++;
    }else{
      x--;
    }
  }
    printf("%d",x);
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <ctype.h>
#include <iostream>
#include <string>

int main(int argc, char const* argv[])
{
	std::string w, t;

	int found = 0;
	int pos = 0;

	std::cin >> w;
	std::transform (w.begin(), w.end(), w.begin(), toupper);
	while (std::cin >> t)
	{
		if(t == "END_OF_TEXT")
			break;
		std::transform (t.begin(), t.end(), t.begin(), toupper);
		if (t.compare(w) == 0)
			found++;
	}

	std::cout << found << std::endl;
	return 0;
}

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

typedef long long LL;

int n, m, x;
LL dp[100][2];

int main(){
    while(~scanf("%d %d", &n, &m)){
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        for(int i=1; i<=n; i++){
            scanf("%d", &x);
            x &= 1;
            if(x == 0){
                dp[i][0] = dp[i-1][0] * 2;
                dp[i][1] = dp[i-1][1] * 2;
            } else {
                dp[i][0] = dp[i][1] = dp[i-1][0] + dp[i-1][1];
            }
        }
        printf("%lld\n", dp[n][m]);
    }
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define per(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define enter cout << endl
#define siz(x) ((int)x.size())
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 100010 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }

int n, m ;
ll f[N], w[N], v[N] ;

signed main(){
	scanf("%d%d", &n, &m) ;
	for (int i = 1; i <= n; i++) scanf("%lld%lld", &w[i], &v[i]) ; // height and value
	memset(f, 0xcf, sizeof(f)) ;
	f[0] = 0 ;
	for (int i = 1; i <= n; i++)
	for (int j = m; j >= w[i]; j--)
	f[j] = max(f[j], f[j - w[i]] + v[i]) ;
	ll ans = 0 ;
	for (int j = 0; j <= m; j++) ans = max(ans, f[j]) ;
	printf("%lld\n", ans) ;
	return 0 ;
}

/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
*/


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


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

    long long currentT=T[0], currentA=A[0];
    for(int i=1; i<N; i++){
        long long nextT=T[i], nextA=A[i];
        /*if(nextT < currentT || nextA < currentA){
            long long scale = max( ceil((double)currentT/nextT) ,
                                   ceil((double)currentA/nextA) );
            nextT *= scale;
            nextA *= scale;
        }*/
        if(nextT < currentT || nextA < currentA){
            long long scale = max(currentT/nextT,currentA/nextA);

            nextT = T[i]*scale;
            nextA = A[i]*scale;
            if(nextT < currentT || nextA < currentA){
                scale++;
                nextT = T[i]*scale;
                nextA = A[i]*scale;
            }
        }


        currentT = nextT;
        currentA = nextA;
    }
    cout << (currentT + currentA) << '\n';

}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

constexpr ll MOD = 1'000'000'007;

ll naive(const vecll& a) {
  ll ans = 1;
  for(auto&&e:a) {
    ans *= e + MOD;
    ans %= MOD;
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,k;
  cin>>n>>k;
  vecll a(n);
  for(auto&&e:a)cin>>e;
  int zcnt = count(ALL(a), 0l);
  if (k == n) {
    cout<<naive(a)<<endl;
    return 0;
  } else if (k > n - zcnt) {
    cout<<0<<endl;
    return 0;
  } else if (k == n - zcnt) {
    ll ncnt = 0;
    for(auto&&e:a) if (e < 0) ++ncnt;
    if (ncnt % 2 == 0) {
      vecll b;
      for(auto&&e:a) if (e != 0) b.push_back(e);
      cout<<naive(b)<<endl;
    } else {
      cout<<0<<endl;
    }
    return 0;
  }
  vecll pos, neg;
  for (auto&&e:a) {
    if (e > 0) pos.push_back(e);
    else if (e < 0) neg.push_back(e);
  }
  sort(ALL(pos),greater<ll>());
  sort(ALL(neg));
  if (pos.empty()) {
    if (k % 2 == 1) {
      if (zcnt) {
        cout<<0<<endl;
      } else {
        reverse(ALL(neg));
        neg.erase(begin(neg) + k, end(neg));
        cout<<naive(neg)<<endl;
      }
    } else {
      neg.erase(begin(neg) + k, end(neg));
      cout<<naive(neg)<<endl;
    }
    return 0;
  }
  int idx = -1;
  REP(i,n) {
    int negsz = 2*i;
    int possz = k - negsz;
    if (negsz > size(neg) || possz > size(pos) || possz < 0) continue;
    if (idx >= 0 && neg[negsz-2] * neg[negsz-1] <= pos[possz] * pos[possz+1]) break;
    idx = i;
  }
  if (idx == -1) {
    throw runtime_error("BAD");
  } else {
    vecll v;
    REP(i,2*idx) v.push_back(neg[i]);
    REP(i,k-2*idx) v.push_back(pos[i]);
    cout<<naive(v)<<endl;
  }
  return 0;
}


Measured memory_bytes: 9420
#include<stdio.h>
#include<string.h>
int main()
{  int i,l;
   char s[200005];
   gets(s);
   l=strlen(s);
   for(i=0;i<l;i++)
   { if(s[i]=='?')
     printf("D");
     else printf("%c",s[i]); 
   }
} 

Measured memory_bytes: 1688
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,count=0,d,i;
  cin>>n>>d;
  pair<int,int> p[n];
  for(i=0;i<n;i++)
  {
    cin>>p[i].first>>p[i].second;
    if(sqrt(pow(p[i].first,2)+pow(p[i].second,2))<=d)
    count++;
  } 
  cout<<count;
  return 0;
}

Measured memory_bytes: 5120
S = input()[::-1]


_MOD = {0: 1}
amari = 0
a = 1
ans = 0

for i in S:
    amari = (amari + int(i) * a) % 2019
    a = (a * 10) % 2019  #表示桁 1あたりの余
    if amari in _MOD:
        _MOD[amari] = _MOD[amari] + 1
    else:
        _MOD[amari] = 1
    
for amari in _MOD:
    m = _MOD[amari]
    ans += (m * (m - 1)) // 2

print(ans)

Measured memory_bytes: 9512
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

class pos{
public:
  int x;
  int y;
};

class data{
public:
  int id;
  double dist;
  vector<bool> v;
  data(int in, int n);
  data(int in, int n, vector<bool> origin);
};

data::data(int in, int n){
  for(int i=0; i<n; i++){
    v.push_back(true);
  }
  v[in] = false;
  id = in;
  dist = 0;
}


data::data(int in, int n, vector<bool> origin){
  for(int i=0; i<n; i++){
   v.push_back(origin[i]); 
  }
  cerr << "here" << endl;
  v[in] = false;
  id = in;
  dist = 0;
}

double calsqrt(pos src, pos dst){
  double ret = sqrt(pow((src.x - dst.x), 2) + pow((src.y - dst.y), 2));
  cerr << ret << endl;
  return ret;
}

int main(){
	
  int n;
  cin >> n;
  
  vector<pos> p(n);
  
  for(int i=0; i<n; i++){
  	cin >> p[i].x >> p[i].y;
  }
  
  
  double sum = 0;
  int cnt = 0;
  
  for(int sp=0; sp<n; sp++){
    int itr = 0;
    data srt(sp, n);
    vector<data> queue = {srt};
    while(itr < queue.size()){
      int nv = 0;
      for(int id=0; id<n; id++){
        if(queue[itr].v[id]){
          cerr << id << endl;
          nv++;
          data tmp(id, n, queue[itr].v);
          tmp.dist = queue[itr].dist + calsqrt(p[queue[itr].id], p[id]);
          queue.push_back(tmp);
        }
      }
      if(nv == 0){
          sum += queue[itr].dist;
          cnt ++;
      }
      itr++;
    } 
  }
  
  double ans = sum / cnt;
  printf("%.10lf\n", ans);
}

Measured memory_bytes: 2120
line = [int(i) for i in input().split()]
v1 = line[0]
v2 = line[1]
v3 = line[2]
v4 = line[3]

s1 = set(range(v1,v2+1))
s2 = set(range(v3,v4+1))

inter = s1.intersection(s2)

res = len(inter)-1
if res == -1 : res = 0
print(res)

Measured memory_bytes: 3064
import java.util.Scanner;
class Line{
    protected int[][] liner;
    protected int[] beq;
    protected int sum;
    public Line(int x,int y){
	liner=new int[x][];
	for(int i=0;i<x;i++) liner[i]=new int[y];
	beq=new int[y];
    }
    public void calc(int x,int y){
	for(int i=0;i<x;i++){
	    sum=0;
	    for(int j=0;j<y;j++){
		sum+=liner[i][j]*beq[j];
	    }
	    System.out.println(sum);
	}
    }
}

class Main{
    public static void main(String[] args){
	final Scanner sc=new Scanner(System.in);
	int x=sc.nextInt();
	int y=sc.nextInt();
	Line line=new Line(x,y);
	for(int i=0;i<x;i++){
	    for(int j=0;j<y;j++){
		line.liner[i][j]=sc.nextInt();
	    }
	}
	for(int i=0;i<y;i++) line.beq[i]=sc.nextInt();
	line.calc(x,y);
    }
}

Measured memory_bytes: 31876
#include <cstdio>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>

using namespace std;

typedef long long LL;

int suki[100005];

int main() {
  memset(suki, 0, sizeof(suki));
  int n;
  scanf("%d\n", &n);
  for (int i = 1; i <= n; i += 1) {
    scanf("%d", &suki[i]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i += 1) {
    if (suki[suki[i]] == i) {
      ans += 1;
    }
  }
  ans /= 2;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 640
using System;

class Atcoder02
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        string a = input[0];
        string b = input[1];
        string c = input[2];

        char aa = a[0];
        char bb = b[0];
        char cc = c[0];

        string aaa = aa.ToString();
        string bbb = bb.ToString();
        string ccc = cc.ToString();

        string aaaa = aaa.ToUpper();
        string bbbb = bbb.ToUpper();
        string cccc = ccc.ToUpper();

        Console.WriteLine(aaaa + bbbb + cccc);
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

template<typename T> vector<pair<T, LL>> cc(vector<T> v) {
	vector<pair<T, LL>> a;
	inc(i, v.size()) {
		if(i == 0 || v[i] != v[i - 1]) { a.EB(v[i], 1); } else { a.back().SE++; }
	}
	return a;
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	inc(i, n) { cin >> a[i]; }
	sort(ALL(a));
	auto v = cc(a);
	
	bool ans = false;
	if(n % 3 != 0) { ans = (SI(v) == 1 && v[0].FI == 0); }
	else {
		if(SI(v) == 3) { ans = (v[0].SE == n / 3 && v[1].SE == n / 3 && (v[0].FI ^ v[1].FI) == v[2].FI); }
		if(SI(v) == 2) { ans = (v[0].SE == n / 3 && v[0].FI == 0); }
		if(SI(v) == 1) { ans = (v[0].SE ==     n && v[0].FI == 0); }
	}
	
	cout << (ans ? "Yes" : "No") << endl;
	
	return 0;
}


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

const int INF = 1 << 30;

int dp1[1010101], dp2[1010101];

void solve(int n) {
    for (int i = 1; i <= n; i++) {
        dp1[i] = INF;
        dp2[i] = INF;
    }
    dp1[0] = dp2[0] = 0;
    for (int i = 1; i < 202; i++) {
        int polloc = i * (i + 1) * (i + 2) / 6;
        if (polloc > n) break;
        for (int j = polloc; j <= n; j++) {
            dp1[j] = min(dp1[j], dp1[j - polloc] + 1);
        }
        if (polloc % 2) {
            for (int j = polloc; j <= n; j++) {
                dp2[j] = min(dp2[j], dp2[j - polloc] + 1);
            }
        }
    }
    cout << dp1[n] << ' ' << dp2[n] << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    while (true) {
        cin >> N;
        if (N == 0) break;
        solve(N);
    }
    return 0;
}


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

int n, ar[200001] = {};

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> ar[i];
	}
	sort(ar, ar + n, greater<int>());
	long long to = ar[0];
	for (int i = 0; i < n - 2; i += 2)
	{
		to += min(2, n - 2 - i) * ar[i / 2 + 1];
	}
	cout << to << "\n";
	return 0;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

void solve(ll N){
  string ans;
  while(N){
    if(N % 26 == 0){
      ans += 'z';
      N/=26;
      N--;
    }
    else{
      ans += (N % 26-1) + 'a';
      N /= 26;
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}

int main(){
  ll N;
  cin >> N;
  solve(N);
  return 0;
}


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;

    s[k - 1] = (char)(s[k - 1] + 32);

    cout << s << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	var sc = bufio.NewScanner(os.Stdin)
	var s string
	if sc.Scan() {
		_ = sc.Text()
	}
	if sc.Scan() {
		s = sc.Text()
	}
	ss := strings.Split(s, " ")
	as := make([]int, 0, len(ss))
	for _, s := range ss {
		i, _ := strconv.Atoi(s)
		as = append(as, i)
	}

	////////////////////////////////////
	var sum int
	for _, num := range as {
		sum+=num
	}
	avg := round(float64(sum) / float64(len(as)))

	var cost int
	for _, num := range as {
		cost+=(num-int(avg))*(num-int(avg))
	}
	fmt.Println(cost)
}

func round(f float64) float64 {
	return math.Floor(f + .5)
}

Measured memory_bytes: 640
n,m = map(int,input().split())

a = []
b = []
for i in range(n):
  a.append(list(map(int,input().split())))

for i in range(m):
  b.append(int(input()))

s = 0
for i in range(n):
  for j in range(m):
    s += a[i][j] * b[j]
  print(s)
  s = 0


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

int main()
{
        set<long long> key;
        map<long long, long long> cnt;
        long long N;
        cin >> N;
        for (int i=0; i < N; ++i) {
                long long x;
                cin >> x;
                key.insert(x);
                cnt[x] += 1;
        }
        long long ans = 0;
        for (auto x: key) {
                if (cnt[x] == x) continue;
                if (x < cnt[x]) {
                        ans += cnt[x]-x;
                }
                else {
                        ans += cnt[x];
                }
        }
        cout << ans << endl;
}


Measured memory_bytes: 10752
import sys
 
input()
minv = int(input())
maxv = -1000000000
 
for r in map(int,sys.stdin.readlines()):
  m = r-minv
  if maxv < m: 
    maxv = m
    if m < 0: minv = r
  elif m < 0: minv = r
 
print(maxv)

Measured memory_bytes: 21832
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

int main(){
    char C[3][3];
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < 3; j++){
            cin >> C[i][j];
        }
    }
    for(int i = 0; i < 3; i++){
        if(C[0][i] != C[1][2-i]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" <<endl;
} 

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n,d;
    cin>>n>>d;
    int ans = (n+d*2)/(1+d*2);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

ll gcd(ll a, ll b) {
    return b != 0 ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

int main()
{	
    ll n, q;
    cin >> n;
    map<ll, ll> mp;
    REP(i, n){
        ll a;
        cin >> a;
        mp[a]++;
    }
    cin >> q;
    ll allsum = 0;
    for(auto p : mp) allsum += p.first * p.second;
    ll sum = allsum;
    
    REP(i, q){
        ll b, c;
        cin >> b >> c;
        sum = sum-mp[b]*b+mp[b]*c;
      	mp[c] += mp[b];
      	mp[b] = 0;
        cout << sum << endl;
    }
}


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

#define MAX 200

int main(void) {
    char First[MAX];
    char Copy[MAX];
    int m, h, length;
    char str;

    while(1) {
      scanf("%s", First);

      if(strcmp(First, "-") == 0) {
        break;
      }

      scanf("%d", &m);

      length = strlen(First);
      for(int i=0; i<m; ++i) {
        scanf("%d", &h);
        strncpy(Copy, First, h);
        int j = h, p = 0;
        while(First[j] != '\0') {
          First[p++] = First[j++];
        }
        j = length - h;
        p = 0;
        while(p < h) {
          First[j++] = Copy[p++];
        }
      }

      printf("%s\n", First);
    }
}



Measured memory_bytes: 2032
X, N = map(int, input().split())
try:
  list_  = list(map(int, input().split()))
except:
  print(X)

else:
    for i in range(0, 101):
        if not (X-i) in list_:
            print(X-i)
            break
        
        elif not(X+i) in list_:
            print(X+i)
            break

Measured memory_bytes: 9180
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = 2e5+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

int ls[30];
string str[M];

typedef struct node{
	node* nxt[26];
	int dp[26];
}node;

node* nnode()
{
	node* tmp = new node;
	for(int i=0;i<26;++i)
	{
		tmp->nxt[i] = NULL;
		tmp->dp[i] = 0;
	}
	return tmp;
}

node* insert(node* root,string ar)
{
	node* cur = root;
	int n = ar.size();

	for(int j=0;j<26;++j)
		ls[j] = -1;

	for(int i=0;i<n;++i)
		ls[ar[i]-'a'] = i;

	for(int i=0;i<n;++i)
	{
		for(int j=0;j<26;++j)
		{
			if(ls[j] >= i)
				cur->dp[j]++;
		}
		if(cur->nxt[ar[i]-'a']==NULL)
		{
			node* tmp=nnode();
			cur->nxt[ar[i]-'a']=tmp;
			cur=cur->nxt[ar[i]-'a'];
		}
		else
			cur=cur->nxt[ar[i]-'a'];
	}
	return root;
}

int search(node* root,string ar)
{
	node* cur=root;
	int n = ar.size();

	for(int i=0;i<n-1;++i)
		cur=cur->nxt[ar[i]-'a'];

	return cur->dp[ar[n-1]-'a']-1;
}	

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

	ll i,n,ans = 0;

	node* root = nnode();

	cin >> n;
	for(i=1;i<=n;++i)
	{
		cin >> str[i];
		reverse(all(str[i]));
		root = insert(root,str[i]);
	}

	for(i=1;i<=n;++i)
		ans += search(root,str[i]);

	cout << ans << "\n";
}


Measured memory_bytes: 322916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n,i;
    ll k,sum=0;
    cin>>n>>k;
    ll ara[n+5];
    for(i=0;i<n;i++)
        cin>>ara[i];
    sort(ara,ara+i,greater<int>());
    int cnt=0;
    for(i=0;i<n;i++)
    {
        if(cnt==k)
            sum+=ara[i];
        if(cnt<k)
            cnt++;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    string s;
    int K;
    cin >> s;
    cin >> K;
    vector<string> vec;
    for (int i = 0; i < s.size(); i++)
    {
        //start
        for (int j = 1; j <= K; j++)
        {
            //length
            string tmp = s.substr(i,j);
            vec.push_back(tmp);
        }
    }
    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(),vec.end()),vec.end());
    //ゴミの手前から最後までを消す
    cout<<vec[K-1]<<endl;
}

Measured memory_bytes: 1660
# Euclidean Algorithm
import math

def euclid(A,B):
    if A < B:
        A , B = B , A
    quotient = math.floor(A / B)
    surplus = A % B
    if surplus == 0:
        Gretest_common_divisor = B
    else:
        Gretest_common_divisor = euclid(A - B * quotient, B)
    return Gretest_common_divisor

IN = input().split(" ")
A = int(IN[0])
B = int(IN[1])
print(int((A / euclid(A,B)) * B))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
typedef long long ll;
typedef long double ld;
using namespace std;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;


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

  int ans = 1;
  int n;
  string s;
  cin >> n >> s;
  for (int i = 1; i < n; i++) {
    ans += s[i] != s[i - 1];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;

int main() {string s;
cin >> s;
long N = s.size();
long ans1 = -1;long ans2 = -1;
if(s.at(0) == s.at(1)){
    ans1 = 1;
    ans2 = 2;
}
else{
    for(long i = 2; i < N; i++){
        if(s.at(i) == s.at(i - 1)){
            ans1 = i;
            ans2 = i + 1;
            break;
        }
        else if(s.at(i) == s.at(i - 2)){
            ans1 = i - 1;
            ans2 = i + 1;
            break;
        }
    }
}



cout << ans1 << ' ' << ans2 << endl;
  return 0;
 
}



Measured memory_bytes: 512
s = input()

dp = [[0 for i in range(13)] for j in range(len(s)+1)]
dp[0][0]=1
keta = 1
di=10**9+7
ii = len(s)
for i in range(len(s)):
    if s[ii-1-i] != "?":
        for j in range(13):
            dp[i+1][(keta*int(s[ii-1-i])+j)%13]=(dp[i+1][(keta*int(s[ii-1-i])+j)%13]+dp[i][j])%di
    else:
        for j in range(13):
            for num in range(10):
                #print(dp[i][j])
                dp[i+1][(keta*num+j)%13]=(dp[i+1][(keta*num+j)%13]+dp[i][j])%di
    keta = (keta*10)%13

#print(*dp,sep="\n")
print(dp[len(s)][5])


Measured memory_bytes: 66396
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
int n,m;
int main()
{
    n=read(),m=read();
    if(n>=10||m>=10){puts("-1");return 0;}
    cout<<n*m<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <numeric>
#include <algorithm>
#include <math.h>
using namespace std;
int main(){
    int a,b,c,d,p,x,y;
    cin>>a>>b>>c>>d>>p;
    x=p*a;
    if(p>=c){
        y=b+(p-c)*d;
    }
    else{
        y=b;
    }
    if(x>y){
        cout<<y<<endl;
    }
    else{
        cout<<x<<endl;
    }
}


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

int main() {
	int n, d;
	cin >> n >> d;
	ll x[200010];
	ll y[200010];
	rep (i, n) {
		cin >> x[i] >> y[i];
		if (x[i] < 0) x[i]*= -1;
		if (y[i] < 0) y[i]*= -1;
	}

	int cnt = 0;
	rep (i, n) {
		ll s = x[i]*x[i] + y[i]*y[i];
		ll t = sqrt(s);
		ll p = t*t;
		if (p < s) t+=1;
		if (t <= d) cnt++;
	}

	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 6704
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int mod = 1e9;
int main(){ 
  int n, k, s;
  cin >> n >> k >> s;
  if (k == 0) {
    for (int i = 0; i < n; i++) cout << (s + 1) % mod << " ";
    cout << endl;
  } else {
    for (int i = 0; i < k; i++) {
      cout << s << " ";
    }
    for (int i = k; i < n; i++) {
      cout << (s + 1) % mod << " ";
    }
    cout << endl;
  }
  return 0;
} 

Measured memory_bytes: 1280
#include<stdio.h>

int main(void)

{

 int i,n;

 int number;

 long long int sum=0;

 int min=0;

 int max=0;

   scanf("%d",&n);

   for(i=0;i<n;i++)

 {

  scanf("%d",&number);

     if(i==0)

  {

   min = number;

   max = number;

  }

  if(number<min)

min = number;

  if(number>max)

max = number;

     sum += number;

 }

   printf("%d %d %lld\n",min,max,sum);

   return 0;

  }

Measured memory_bytes: 2760
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Ord

main :: IO ()
main = getLine >> breads >>= putStrLn . unlines . fmap (unwords . fmap show) . solve

solve :: [Int] -> [[Int]]
solve xs
    | minv >= 0 = [l - 1] : build1 1
    | maxv <= 0 = [l - 1] : build2 l
    | maxv > abs minv = [2 * l - 1] : build3
    | otherwise = [2 * l - 1] : build4
    where
        l = length xs
        (minv, mini) = minimumBy (comparing fst) $ zip xs [1..]
        (maxv, maxi) = maximumBy (comparing fst) $ zip xs [1..]

        build1 y
            | y < l = [y, y + 1] : build1 (y + 1)
            | otherwise = []
        build2 y
            | y > 1 = [y, y - 1] : build2 (y - 1)
            | otherwise = []
        build3 = [[maxi, y] | y <- [1..l]] `mappend` build1 1
        build4 = [[mini, y] | y <- [1..l]] `mappend` build2 l



breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)

Measured memory_bytes: 508
#include<stdio.h>

int main(void)
{
	int a, b, i, j;
	while (1)
	{
		scanf("%d%d", &a, &b);
		if (a == 0 && b == 0){
			break;
		}

		for (i = 1; i <= a; i++)
		{
			for (j = 1; j <= b; j++)
			{
				if (j % 2 == 1)
				{
					if (i % 2 == 1){
						printf("#");
					}
					else {
						printf(".");
					}
				}
				else
				{
					if (i % 2 == 1){
						printf(".");
					}
					else{
						printf("#");
					}
				}
			}
			printf("\n");
		}
		printf("\n");

	}
	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
	int a, b, c, d;
	string s;
	cin >> s;
	a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
	vector<int> num = { a,b,c,d };
	string ans;
	for (int bit = 0; bit < (1 << 3); ++bit) {
		vector<char> operands(3, '-');
		for (int i = 0; i < 3; ++i) {
			if (bit & (1 << i)) {
				operands[i] = '+';
			}
		}
		int sum = num[0];
		for (int i = 1; i < 4; ++i) {
			if (operands[i - 1] == '+') sum += num[i];
			else sum -= num[i];
		}
		if (sum == 7) {
			ans = "";
			ans += s[0];
			ans += operands[0];
			ans += s[1];
			ans += operands[1];
			ans += s[2];
			ans += operands[2];
			ans += s[3];
			ans += '=';
			ans += '7';
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
s=[list(map(int,input().split())) for i in range(3)]
res = [0]*4
for i in range(len(s)):
    res[s[i][0]-1] += 1
    res[s[i][1]-1] += 1

if max(res) > 2:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 38416
# coding: utf-8
H, W = map(int, input().split())

campus = []

for i in range(H):
    campus.append(list(input()))


def search_lonely_sharp(l :list) -> list:
    _lonely_sharps = []
    ls = ['.'] + l + ['.']
    for i in range(1, len(ls)-1):
        if ls[i] == '#' and ls[i] != ls[i-1] and ls[i] != ls[i+1]:
            _lonely_sharps.append(i-1)
    return _lonely_sharps


for i in range(1, H-1):
    before_line = campus[i-1]
    line = campus[i]
    after_line = campus[i+1]
    lonely_sharps = search_lonely_sharp(line)
    for j in lonely_sharps:
        if before_line[j] != '#' and after_line[j] != '#':
            print('No')
            exit()

print('Yes')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
string n;
int a,b;
int main()
{
	cin>>n;
	for (int i=0;i<n.size();i++)
	{
		if(n[i]=='C') a=1;
		if(n[i]=='F'&&a==1)
		{
		    cout<<"Yes";
		    return 0;
    	}
	}
	cout<<"No";
	return 0;
}

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

typedef long long ll;
const int MAX_N = 10;

int main() {
  int N, M, connection[MAX_N] = {}, p = 0;
  std::cin >> N >> M;
  for(int i = 0; i < M; ++i) {
    int k;
    std::cin >> k;
    for(int j = 0; j < k; ++j) {
      int s;
      std::cin >> s;
      --s;
      connection[s] |= 1 << i;
    }
  }
  for(int i = 0; i < M; ++i) {
    int x;
    std::cin >> x;
    p |= x << i;
  }

  int ans = 0;
  for(int b = 0; b < 1 << N; ++b) {
    int state = 0;
    for(int i = 0; i < N; ++i) {
      if((b >> i) & 1) {
        state ^= connection[i];
      }
    }
    if(state == p) ++ans;
  }

  std::cout << ans << std::endl;
}

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

int main(void){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 1;
	char b = s[0];
	for(int i = 1; i < n; ++i){
		if(s[i] != b){
			ans++;
		}
		b = s[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
from bisect import bisect_left
N = int(input())
As = [(x, i) for i, x in enumerate(map(int, input().split()))]

up = sorted(As)
dp = [[0]*(N+1) for _ in range(N+1)]

for i, (u, idx) in enumerate(up[::-1], 1):
    for j in range(i):
        left = j
        right = N-(i-j)
        dp[i][j] = max(dp[i][j], dp[i-1][j]+u*abs(right-idx))
        dp[i][j+1] = max(dp[i][j+1], dp[i-1][j]+u*abs(left-idx))

print(max(dp[-1]))

Measured memory_bytes: 106176
#include <bits/stdc++.h>
#define boost ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define M 1000000007
#define eb emplace_back

using namespace std;
const int N = 1e6;

int32_t main(){
  boost;
  int t = 1; //cin >> t;
  while(t--)
  {
    int n,m;
    cin >> n >> m;
    n==m ? cout << "Yes\n" : cout <<"No\n";
  }
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
using namespace std;
long a[251];
int main(){
	int H; scanf("%d",&H);
	for (int i = 1; i <= H; ++i) scanf("%ld",&a[i]);
	for (int i = 1; i <= H; ++i){
		cout << "node " << i << ": key = " << a[i] << ", ";
		if (i/2 >=1 ) cout << "parent key = " << a[i/2] << ", ";
		if (2*i <= H)	cout << "left key = " << a[2*i] << ", ";
		if (2*i+1 <= H) cout << "right key = " << a[2*i+1] << ", ";
		cout << '\n';
	}
}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> P;
map<pair<int,int>,int>M;
int main(){
    int n,m;
    cin >> n >> m;
    vector<int>k(n+5,0);
    int a,b;
    rep(i,m){
        cin >> a >> b;
        k[a]++;
        k[b]++;
    }
    rep(i,n+5){
        if(k[i]%2==1){
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
    
}

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

#define MAX_SIZE 200010

struct Map {
  int key;
  int value;
  Map() {key = 0; value = 0;}
};

bool comp(const struct Map &a,const struct Map &b) {
  return a.value < b.value;
}

int main() {
  Map A[MAX_SIZE];
  int N, K;
  cin >> N >> K;

  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    A[a].key = a;
    ++A[a].value;
  }

  sort(A+1, A+N+1,comp);

  int size = 0;
  for (int i = 1; i <= N; ++i) {
    if (A[i].value) {
      ++size;
    }
  }

  int index = 1;
  while (!A[index].key) ++index;

  int ans = 0;
  for (int i = index; i < index + size - K; ++i) {
    ans += A[i].value;
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
  int n;
  cin >> n;
  ll c[n];
  rep(i,n) cin >> c[i];
  sort(c,c+n);
  ll t = 1;
  rep(i,2*n-2) (t *= 2) %= mod;
  ll ans = 0;
  rep(i,n) {
    ll p = (n+1-i)*t % mod;
    (ans += p*c[i]) %= mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(std::string S, std::string T){
  cout<<T<<S<<endl;
}

int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val iobuf = readLine.split(" ").map(_.toInt).head
    import scala.math.log
    val x = (log(iobuf) / log(2)).toInt
    import scala.math.pow
    val ans = pow(2, x).toInt
    println(ans)
  }
}


Measured memory_bytes: 27340