akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//#define MOD 1000000007
#define MOD 998244353
#define INF 100000000000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int H,W;
    const int MAX=1010;
    char A[MAX][MAX];
    int D[MAX][MAX];
    int E[MAX][MAX];
    REP(i,MAX){
        REP(j,MAX){
            D[i][j]=INF;
            E[i][j]=INF;
        }
    }
    cin >> H >> W;
    REP(i,H){
        REP(j,W){
            cin  >> A[i][j];
        }
    }
    int now=-1;
    REP(i,H){
        now=-1;
        REP(j,W){
            if(A[i][j]=='#'){
                now=j;
                D[i][j]=0;
            }else{
                if(now==-1)continue;
                D[i][j]=min(D[i][j],abs(j-now));
            }
        }
    }
    REP(i,H){
        now=-1;
        RREP(j,W){
            if(A[i][j]=='#'){
                now=j;
                D[i][j]=0;
            }else{
                if(now==-1)continue;
                D[i][j]=min(D[i][j],abs(j-now));
            }
        }
    }
  	REP(i,MAX){
        REP(j,MAX){
            E[i][j]=D[i][j];
        }
    }  
  
  
    /*REP(i,H){
        REP(j,W){
            cout << D[i][j] << " ";
        }cout << endl;
    }cout << endl;*/
    
    REP(j,W){
        REP(i,H){
            if(i!=0){
                E[i][j]=min(E[i][j],E[i-1][j]+1);
            }
        }
        RREP(i,H){
            if(i!=H-1){
                E[i][j]=min(E[i][j],E[i+1][j]+1);
            }
        }
    }
    
    int Ans=0;
    REP(i,H){
        REP(j,W){
            Ans=max(Ans,E[i][j]);
        }
    }
    
    /*REP(i,H){
        REP(j,W){
            cout << E[i][j] << " ";
        }cout << endl;
    }*/
    
    cout << Ans << endl;
    
    return 0;
}


Measured memory_bytes: 17152
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define REP(i, n) for (size_t i = 0; i < (n); i++)
#define nvec(T, v, n) vector<T> v(n); REP(i, n) {cin>>(v)[i];}
#define npairs(T1, T2, v, n) vector<pair<T1, T2>> v(n); REP(i, n){cin>>v[i].first>>v[i].second;}
#define ntuples(T1, T2, T3, v, n) vector<tuple<T1, T2, T3>> v(n); REP(i, n){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}
#define vec2d(T, v, m, n) vector<vector<T>> (v)(m, vector<T>(n))
#define nvec2d(T, v, m, n) vec2d(T, v, m, n); REP(j, m){REP(i, n) {cin>>(v[j])[i];}}

#define min_index(v) size_t( min_element(all(v)) - (v).begin() )
#define max_index(v) size_t( max_element(all(v)) - (v).begin() )
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))

#define count_le(v, a) size_t( upper_bound(ALL(v), a) - (v).begin() )
#define count_lt(v, a) size_t( lower_bound(ALL(v), a) - (v).begin() )
#define count_ge(v, a) size_t( (v).end() - lower_bound(ALL(v), a) )
#define count_gt(v, a) size_t( (v).end() - upper_bound(ALL(v), a) )

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))

#define pos position<int>
#define at_(p) at(p.x).at(p.y)

#define GCD(v) gcd(ALL(v), 0l)

template <typename T>
T gcd(T a, T b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b%a, a);
}
template <typename InputItr, typename T>
T gcd(InputItr first, InputItr last, T init) {
    for (; first != last; ++first) init = gcd(init, *first);
    return init;
}

template <typename T>
using vec =vector<T>;

template <typename T>
using vvec =vector<vector<T>>;



int main(){
  int x;
  cin>>x;
  vec<int> v(100);
  for (int i = 0; i <= 120; i++) {
    v[i]=i*i*i*i*i;
  }
  int i,j;
  for (i = 0; i <= 120; i++) {
    for (j = 0; j <= i; j++) {
      if(i*i*i*i*i+j*j*j*j*j==x){
        cout<<i<<" "<<-j;
        return 0;
      }
      if(i*i*i*i*i-j*j*j*j*j==x){
        cout<<i<<" "<<j;
        return 0;
      }
    }
    
  }
}



/* きょむ〜 */


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int n, l, r;
  cin >> n;
  int ans = 0;
  for(int i = 0; i < n; ++i)
  {
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
/* 大文字を小文字に変換 */
/* 小文字を大文字に変換 */
 
int main() {
	int a,b,c;
  cin >> a >> b >>c;
  if ((b-a) == (c-b)) cout <<"YES" << endl;
  else cout << "NO" << endl;
}



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

int main() {
  int N, A = 0;
  string S;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    cin >> S;
    
    if (S == "Y") {
      A = 1;
    }
  }
  
  if (A == 1) {
    cout << "Four" << endl;
  }
  
  else {
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
def is_prime(x):
    if x < 2:
        return False
    if x == 2:
        return True
    if x % 2 == 0:
        return False
    for i in range(3,int(x**0.5)+1, 2):
        if x%i == 0 :
             return False
    return True

x = int(input())
for i in range(x, 100003):
    if is_prime(i):
        print(i)
        break
else:
    print(100003)

Measured memory_bytes: 3188
a1,b1=map(int,input().split())
a2,b2=map(int,input().split())
a3,b3=map(int,input().split())
a4,b4=map(int,input().split())
a5,b5=map(int,input().split())
a6,b6=map(int,input().split())
a7,b7=map(int,input().split())

c1=a1-b1
c2=a2-b2
c3=a3-b3
c4=a4-b4
c5=a5-b5
c6=a6-b6
c7=a7-b7

print(c1)
print(c2)
print(c3)
print(c4)
print(c5)
print(c6)
print(c7)



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

int main()
{
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;
	bool f = true;

	if (b - a > k)	f = false;
	else if (c - a > k)	f = false;
	else if (d - a > k)	f = false;
	else if (e - a > k)	f = false;

	if (c - b > k)	f = false;
	else if (d - b > k)	f = false;
	else if (e - b > k)	f = false;

	if (d - c > k)	f = false;
	else if (e - c > k)	f = false;

	if (e - d > k)	f = false;

	if (f)	cout << "Yay!" << endl;
	else cout << ":(" << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

h,w = map(int,input().split())
a = [0] * h
for i in range(h):
    a[i] = list(input())

delete = []
for i in range(h):
    if not("#" in a[i]):
        delete.append(i)

diff = 0
for i in range(len(delete)):
    del a[delete[i] - diff]
    diff += 1

bucket = [0] * len(a[0])
for i in range(len(a)):
    for j in range(len(a[0])):
        if a[i][j] == "#":
            bucket[j] += 1

delete = []
for i in range(len(bucket)):
    if bucket[i] == 0:
        delete.append(i)

diff = 0
for i in range(len(delete)):
    for j in range(len(a)):
        del a[j][delete[i] - diff]
    diff += 1

for i in range(len(a)):
    temp = "".join(a[i])
    print(temp)


Measured memory_bytes: 3188
import math
import itertools

N = int(input())
route = [list(map(int, input().split())) for _ in range(N)]

rr = list(itertools.permutations(route, N))

total = 0
for r in rr:
    for i in range(len(r) - 1):
        x = (r[i][0] - r[i+1][0]) ** 2
        y = (r[i][1] - r[i+1][1]) ** 2
        f = math.sqrt(x + y)
        total += f

print(total/len(rr))


Measured memory_bytes: 8052
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

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


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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int A, B;
  cin >> A >> B;
  int ans = ((B-1) + (A-2)) / (A - 1);
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#define f first
#define s second
 
using namespace std;
 
pair <int, pair <int, int> > q[500001];
int n, m, a[500001], ans[500001];
int st[25*100001], used[5000001];
int cmp(pair <int, pair <int, int> > a, pair <int, pair <int, int> > b)
{
    if (a.s.f != b.s.f)
        return a.s.f < b.s.f;
    return a.f < b.f;
}
void update(int v, int l, int r, int x, int d)
{
    if (l == r)
    {
        st[v] = d;
        return;
    }
    int mid = (l + r) / 2;
    if (x <= mid)
        update(v * 2, l, mid, x, d);
    else
        update(v * 2 + 1, mid + 1, r, x, d);
    st[v] = st[v * 2] + st[v * 2 + 1];
}
int Find(int v, int A, int B, int l, int r)
{
    if (l > B || r < A)
        return 0;
    if (A == l && B == r)
        return st[v];
    int mid = (A + B) / 2;
    return Find(v * 2, A, mid, l, min(mid, r)) + Find(v * 2 + 1, mid + 1, B, max(mid + 1, l), r);
}
 
int main()
{
    scanf("%d", &n);
	scanf("%d", &m);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    
    for (int i = 1; i <= m; i++)
        scanf("%d %d", &q[i].f, &q[i].s.f), q[i].s.s = i;
    sort(q + 1, q + m + 1, cmp);
    int j = 1;
    for (int i = 1; i <= m; i++)
    {
        while(j <= q[i].s.f)
        {
            if (!used[a[j]])
            {
                update(1, 1, n, j, 1);
                used[a[j]] = j;
            }
            else
            {
                update(1, 1, n, used[a[j]], 0);
                update(1, 1, n, j, 1);
                used[a[j]] = j;
            }
            j++;
        }
        ans[q[i].s.s] = Find(1, 1, n, q[i].f, q[i].s.f);
    }
    for (int i = 1; i <= m; i++)
        printf("%d\n", ans[i]);
 
    return 0;
}

Measured memory_bytes: 19608
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){return "";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var count = {};
  for(var i = 0; i < N; i++){
    if(count[list[i]] == null){
      count[list[i]] = 1;
    }else{
      count[list[i]]++;
    }
  }
  var keys = Object.keys(count);
  myerr(keys);
  if(keys.length > 3){
    myout("No");
  }else if(keys.length == 3){
    
    if((keys[0] ^ keys[1]) == keys[2] && count[keys[0]] == count[keys[1]] && count[keys[1]] == count[keys[2]]){
      myout("Yes");
    }else{
      myout("No");
    }
  }else if(keys.length == 2){
    if(keys.indexOf("0") != -1){
      
      var zeroCount = count["0"];
      var notZeroCount;
      if(keys[0] != 0){
         notZeroCount = count[keys[0]];
      }else{
         notZeroCount = count[keys[1]];
      }
      myerr(zeroCount);
      myerr(notZeroCount);
      if(notZeroCount / 2 == zeroCount){
        myout("Yes");
      }else{
        myout("No");
      }
    }else{
      myout("No");
    }
  }else{
    if(keys[0] == 0){
      myout("Yes");
    }else{
      myout("No");
    }
  }
}


Measured memory_bytes: 49240
n = int(input())
resl = "Yes"
wrds = set()
for i in range(n):
  sng = input()
  if i==0:
    lst = sng[len(sng)-1]
    wrds.add(sng)
  elif sng[0]==lst and (sng not in wrds):
    lst = sng[len(sng)-1]
    wrds.add(sng)
  else:
    resl = "No"
print(resl)

Measured memory_bytes: 3064
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;
ll mod9 = 1000000009;

signed main(){
    ll n,m;
    cin>>n>>m;
    if(n%2==1){
        rep(i,m){
            cout<<1+i<<" "<<(2*m)-i<<endl;
        }
    }else{
        ll ko;
        ko = min(m,(n/2)/2);
        rep(i,ko){
            cout<<1+i<<" "<<2*ko-i<<endl;
        }
        m = max(m-ko,0LL);
        rep(i,m){
            cout<<2*ko+1+i<<" "<<2*(ko+m)+1-i<<endl;
        }
    }
}


Measured memory_bytes: 3596
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
struct Pos {
  int x, y;
};
double distance(Pos p1, Pos p2) {
  return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}
int main() {
  int N;
  cin >> N;
  vector<Pos> p(N);
  vector<int> v(N);
  iota(v.begin(), v.end(), 0);
  for (int i = 0; i < N; i++) cin >> p[i].x >> p[i].y;
  int cnt = 0;
  double ave = 0.0;
  do {
    for (int i = 1; i < N; i++) ave += distance(p[v[i - 1]], p[v[i]]);
    cnt++;
  } while (next_permutation(v.begin(), v.end()));
  cout << fixed;
  cout.precision(10);
  cout << ave / cnt << endl;
}


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

using namespace std;

long long dp[101][100001];

int main()
{
	int N, W;
	cin >> N >> W;
	vector<int> w(N), v(N);
	for (int i = 0; i < N; i++)
		cin >> w[i] >> v[i];
	for (int i = 0; i < N; i++)
		for (int j = 0; j <= W; j++)
		{
			if (j + w[i] <= W)
				dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
		}
	cout << dp[N][W] << endl;

	return 0;
}


Measured memory_bytes: 78336
n = int(input())

ar = [int(s) for s in input().split()]
q = int(input())

bc = [[] for _ in range(q)]

for i in range(q):
    bc[i] = [int(s) for s in input().split()]

#print(bc)

a_ini = sum(ar)

d = {}
for i in ar:
    d[i] = d.setdefault(i,0) + 1

#print(d)


for i in range(q):
    #print(d)
    b = bc[i][0]
    c = bc[i][1]
    a_ini -= (b-c)*d.setdefault(b,0)
    print(a_ini)
    d[c] = d.setdefault(c,0) + d.setdefault(b,0)
    d[b] = 0


Measured memory_bytes: 105800
n, m = map(int, input().split())
ipy = []

for i in range(m):
    p, y = map(int, input().split())
    ipy.append([i, p, y])
    
city_count = {}
order = {}

for i, p, y in sorted(ipy, key = lambda x: x[2]):
    if not p in city_count:
        city_count[p] = 0
    city_count[p] += 1
    order[i, p] = city_count[p]

for i, p, y in ipy:
    print('{:06}{:06}'.format(p, order[i, p]))

Measured memory_bytes: 44484
public class Hello{
    public static void Main(){

        string[] str = System.Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int A = int.Parse(str[1]);
        int B = int.Parse(str[2]);

        int ans = 0;
        for(int i = 1; i <= N; i++){
            //数字iの各桁の和を算出
            int tmp = i;
            int sum = 0;
            while(tmp > 0){
                sum += tmp % 10;
                tmp /= 10;
            }
          	//数字iの各桁の和がA以上B以下ならば加算
            if(sum >= A && sum <= B) ans += i;
        }
        System.Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
 
int main(void)
{
    int N , n , i , j , h , max , min ;
    int a[101] ;
 
    scanf("%d",&N);
    for(i=0;i<N;i++){
 
        for(j=0;j<101;j++){
            a[j]=0;
        }
        max = 0 ;
        min = 0 ;
 
        scanf("%d",&n);
        for(j=1;j<=n;j++){
            scanf("%d",&h);
            a[j] = h ;
            if((max < (a[j] - a[j-1])) && j != 1){
                max = a[j] - a[j-1] ;
            }
            if(min < (a[j-1] - a[j])){
                min = a[j-1] - a[j] ;
            }
        }
        printf("%d %d\n",max,min);
    }
    return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if ((a - b * 2) <= 0) cout << 0 << endl;
	else cout << a - b * 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    vector<vector<int> > v(n+1);
    std::vector<int> v1(m);
    std::vector<int> v2(m);

    for (int i = 0; i < m; ++i)
    {
    	cin>>v1[i]>>v2[i];
    	v[v1[i]].push_back(v2[i]);
    }
    for (int i = 0; i < n+1; ++i)
    {
    	if(v[i].size() > 0)
    		sort(v[i].begin(), v[i].end());
    }
    for (int i = 0; i < m; ++i)
    {
    	string s1=to_string(v1[i]);
    	if(s1.length()< 6)
    	for (int pp = 0; pp < 6-s1.length(); ++pp)
    	{
    		cout<<"0";
    	}
    	cout<<s1;

    	int index=upper_bound(v[v1[i]].begin(), v[v1[i]].end(), v2[i])-v[v1[i]].begin(); 
    	string s2=to_string(index);
    	if(s2.length()< 6)
    	for (int pp = 0; pp < 6-s2.length(); ++pp)
    	{
    		cout<<"0";
    	}
    	cout<<s2<<endl;
    }


    
	return 0;
}


Measured memory_bytes: 7808
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

bool isvalid(int b, int e, vector<int> &num, string &str){
    if(b==e || (str[num[b]+1]!=')' && str[num[e]-1]!='(')){
        return true;
    }
    return false;
}

int main(){
    string str;
    cin >> str;
    vector<int> num, op;
    for(int i=0; i<(int)str.length(); i++){
        if('0'<=str[i] && str[i]<='9') num.push_back(i);
        if(str[i]=='+' || str[i]=='-') op.push_back(i);
    }
    
    int n = num.size();
    vector<vector<int> > dpmin(n, vector<int>(n, inf)), dpmax(n, vector<int>(n, -inf));;
    for(int i=0; i<n; i++) dpmin[i][i] = dpmax[i][i] = str[num[i]]-'0';
    
    for(int j=1; j<n; j++){
        for(int i=0; i+j<n; i++){
            for(int k=0; k<j; k++){
                if(isvalid(i, i+k, num, str) && isvalid(i+k+1, i+j, num, str)){
                    if(str[op[i+k]] == '+'){
                        dpmax[i][i+j] = max(dpmax[i][i+j], dpmax[i][i+k]+dpmax[i+k+1][i+j]);
                        dpmin[i][i+j] = min(dpmin[i][i+j], dpmin[i][i+k]+dpmin[i+k+1][i+j]);
                    }else{
                        dpmax[i][i+j] = max(dpmax[i][i+j], dpmax[i][i+k]-dpmin[i+k+1][i+j]);
                        dpmin[i][i+j] = min(dpmin[i][i+j], dpmin[i][i+k]-dpmax[i+k+1][i+j]);
                    }
                }
            }
        }
    }
    cout << dpmax[0][n-1] << endl;
    return 0;
}



Measured memory_bytes: 3280
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#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, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	int N, K;

	cin >> N >> K;

	cout << ((N%K==0)?0:1) << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	static final long MOD = 1000000007;

	static int H, W, K;
	static long[][] dp = new long[110][10];
	static int ans = 0;
	static long n = 0;





	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int H = sc.nextInt();
		int W = sc.nextInt();
		int K = sc.nextInt();
		long MOD = 1000000007;

		int[][] dp = new int[H+1][W];				//dp[i][j] = i列目のj行目への経路の総数
		dp[0][0] = 1;		
		for(int h = 1;h <= H;h++){
			for(int w = 0;w < W;w++){
				for(int i = 0;i < (1 << W-1);i++){		//ビット全探索 h行目について横棒を全通り列挙
					int mask = 3;
					boolean flag = true;
					while(true){		//隣同士が繋がっていないか確認
						
						if((mask & i) == mask){
							flag = false;
						}

						if(mask == 3<<W-1){				//端っこまでシフトしたら終了
							break;
						}
						mask =mask << 1;					//右へ1シフト
					}

					if(flag){				//横同士が繋がっていない時

						if(w > 0 && (i & (1 << w-1)) > 0){			//左端でなく、wとw-1列目が繋がっている
							dp[h][w] += dp[h-1][w-1];
						}else if(w < W-1 && (i & (1 << w)) > 0){	//右端でなく、wとw+1列目が繋がっている
							dp[h][w] += dp[h-1][w+1];
						}else{										//真上から降りてくるパターン
							dp[h][w] += dp[h-1][w];

						}
						dp[h][w] %= MOD;


					}

				}
			}
		}
		System.out.println(dp[H][K-1]);

	}
}







class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}



Measured memory_bytes: 25300
def solve(n, s):
    if n % 2 == 1:
        return "No"
    m = n // 2
    for i in range(m):
        if s[i] != s[m + i]:
            return "No"
    return "Yes"


def main():
    n = int(input())
    s = list(input())
    res = solve(n, s)
    print(res)


def test():
    assert solve(6, "abcabc") == "Yes"
    assert solve(6, "abcadc") == "No"
    assert solve(1, "z") == "No"


if __name__ == "__main__":
    test()
    main()


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


int main() {
	int x;
	cin >> x;
	vector<bool>expo(x + 1);
	expo[1] = 1;
	for (int i = 2;i < x;++i) {
		int res = i * i;
		while (res <= x) {
			expo[res] = 1;
			res *= i;
		}
	}
	for (int i = x;i >= 1;i--) {
		if (expo[i]) {
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
// typedef pair<ll,ll> P;

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

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};
int main() {
    ll r,d,x2000,xi; cin >> r >> d >> x2000;

    xi = x2000;
    for(int i=0; i<10; i++){
        xi = r*xi-d;
        cout << xi << endl;
    }


    return 0;
}


Measured memory_bytes: 256
A = 1;B = 0; C= 0
while True:
    try:
        M,N = raw_input().split(',')
    except EOFError:
        break
    if (M,N) == ('A','B'): A,B = B,A
    elif (M,N) == ('A','C'): A,C = C,A
    elif (M,N) == ('B','A'): B,A = A,B
    elif (M,N) == ('B','C'): B,C = C,B
    elif (M,N) == ('C','A'): C,A = A,C
    elif (M,N) == ('C','B'): C,B = B,C
        
if A == 1:print 'A'
elif B == 1: print 'B'
elif C == 1: print 'C'

Measured memory_bytes: 4248
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
int A[301][301];

typedef pair<int,int> P;
template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  int n;
  F f;
  T ti;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(F f,T ti):f(f),ti(ti){}
  void init(int n_){
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }
  void build(const vector<T> &v){
    int n_=v.size();
    init(n_);
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  void set_val(int k,T x){
    dat[k+=n]=x;
    while(k>>=1)
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
  }
  T query(int a,int b){
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }
};

//main
signed main(){
  int N,M;cin>>N>>M;
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      cin>>A[i][j];
      A[i][j]--;
    }
  }
  std::vector<int> kaisai(M,1),player[M],nanban(N,0);
  for(int i=0;i<N;i++)player[A[i][0]].push_back(i);
  auto f=[&](P x,P y){return max(x,y);};
  SegmentTree<P> seg(f,P(-INF,-1));
  vector<P> vp(M);
  for(int i=0;i<M;i++)vp[i]=P(player[i].size(),i);
  seg.build(vp);
  P ans=seg.query(0,M);
  for(int rest=M;N/rest<=ans.first&&rest>1;rest--){
    P now=seg.query(0,M);
    int shokyo=now.second;
    seg.set_val(shokyo,P(0,shokyo));
    kaisai[shokyo]=0;
    set<int> kousin;
    for(int u:player[shokyo]){
      while(kaisai[A[u][nanban[u]]]==0)nanban[u]++;
      player[A[u][nanban[u]]].push_back(u);
      kousin.insert(A[u][nanban[u]]);
    }
    for(int u:kousin)seg.set_val(u,P(player[u].size(),u));
    ans=min(ans,seg.query(0,M));
  }
  cout<<ans.first<<endl;
}


Measured memory_bytes: 2176
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
#define dout(n) cout<<# n<<" = "<<n<<endl;

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> v = divisor(n-1);
    ll ans = v.size()-1;
    v = divisor(n);
    FOR(i,1,v.size()){
        ll x = v[i];
        ll t = n;
        while(t%x==0)t/=x;
        if(t%x==1)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
# 2019-11-16 14:51:41(JST)
import sys
import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 
import heapq

def main():
    # 10**5連勤とか超人すぎる
    n, m = [int(x) for x in sys.stdin.readline().split()]

    job_list = dict((i, list()) for i in range(1, m+1))
    for _ in range(n):
        a, b = [int(x) for x in sys.stdin.readline().split()]
        if a <= m:
            job_list[a].append(b)
    
    schedule = [0 for _ in range(m+1)] # 当日は報酬0
    q = []
    for i in range(1, m+1):
        for reward in job_list[i]: # 期限i日前にできる仕事の報酬一覧をheqp queueに入れる
            heapq.heappush(q, -reward) 
            # あとで最大値を取り出すために-1かける(heappop()で取り出せるのは最小値)

        if q: # その日できる仕事が一つでもあれば
            # 報酬の最小値(マイナスなので元々の最大値)を取り出して-1をかけ、scheduleにいれる
            schedule[i] = -heapq.heappop(q) # 戻り値を返すと同時にq自体も変更している
        else: # できる仕事がなければ
            pass  # その日の報酬は0のまま

    print(sum(schedule))


if __name__ == "__main__":
    main()


Measured memory_bytes: 30176
function main(input) {
  const inputList = input.split(/\n/);
  const oneLineList = inputList[0].split(/\s/).map(inp => formatNum(inp));
  const N = oneLineList[0];
  const D = oneLineList[1];
  const valueList = [];
  for (var i = 1; i <= N; i++) {
    valueList.push(inputList[i].split(/\s/).map(il => formatNum(il)));
  }
  var listA = [];
  var listB = [];
  var count = 0;
  for (var j = 0; j < valueList.length; j++) {
    for (var l = j + 1; l < valueList.length; l++) {
      if (l !== valueList.length) {
        listA = valueList[j];
        listB = valueList[l];
        var calcValue = 0;
        for (var k = 0; k < D; k++) {
          calcValue += (listA[k] - listB[k]) * (listA[k] - listB[k]);
        }
        var sqrtNum = Math.sqrt(calcValue);
        if (Number.isInteger(sqrtNum)) {
          count++
        }
      }
    }
  }
  console.log(count);
};

// 文字列を数値に変換
function formatNum(str) {
  return Number(str);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

N = len(S)
N1 = int((N - 1) / 2)
N2 = int((N + 3) / 2)
S0 = list(reversed(S))
S1 = list(reversed(S[:N1]))
S2 = list(reversed(S[N2-1:]))

if S == S0 and S[:N1] == S1 and S[N2-1:] == S2:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e16;

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


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define poq pop_back
#define tof ios_base :: sync_with_stdio(NULL);cin.tie(0);cout.tie(0)




using namespace std;

char  y[809][809];
bool viz[809][809];
bool vizz[809][809];

int main()
{
    ll h,w,k,X,Y;
    cin>>h>>w>>k;
    for (ll i=0; i<h; i++)
    {
        for (ll j=0; j<w; j++)
        {
            cin>>y[i][j];
            if (y[i][j]=='S')
            {
                X=i;
                Y=j;
            }
        }
    }
    stack<pair<ll,ll> > stk;
    stack<pair<ll,ll>  >sttk;
    stack<pair<ll,ll>  >stttk;
    pair<ll,ll> v;
    stk.push(mp(X,Y));
    stttk.push(mp(X,Y));
    viz[X][Y]=1;


    ll ans=0;
    for (ll i=0; i<k; i++)
    {
        while(!stk.empty())
        {
            v=stk.top();
            if (v.F>0)
            {
                if (y[v.F-1][v.S]!='#')
                {
                    sttk.push(mp(v.F-1,v.S));
                }
            }
            else
            {
                cout<<1;
                return 0;
            }
            if (v.F<h-1)
            {
                if (y[v.F+1][v.S]!='#')
                {
                    sttk.push(mp(v.F+1,v.S));
                }
            }
            else
            {
                cout<<1;
                return 0;
            }
            if (v.S>0)
            {
                if (y[v.F][v.S-1]!='#')
                {
                    sttk.push(mp(v.F,v.S-1));
                }
            }
            else
            {
                cout<<1;
                return 0;
            }
            if (v.S<w-1)
            {
                if (y[v.F][v.S+1]!='#')
                {
                    sttk.push(mp(v.F,v.S+1));
                }
            }
            else
            {
                cout << 1;
                return 0;
            }
            stk.pop();
        }
        while (!sttk.empty())
        {
            v=sttk.top();
            if (v.F==0||v.S==0||v.F==h-1||v.S==w-1)
            {
                cout << 1;
                return 0;
            }
            if (!viz[v.F][v.S])
            {
                stk.push(v);
                stttk.push(v);
                viz[v.F][v.S]=1;
            }
            sttk.pop();
        }
    }
    ans=1e9;
    while (!stttk.empty())
    {
        v=stttk.top();
        ans=min(ans,v.F);
        ans=min(ans,v.S);
        ans=min(ans,w-1-v.S);
        ans=min(ans,h-1-v.F);
        stttk.pop();
    }
    if (ans%k==0)
    {
        cout << ans/k+1;
    }
    else
    {
        cout << ans/k+2;
    }
//egrgergerge
}

Measured memory_bytes: 2048
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;
int n,a[10000];

int main()
{
	for(;;){
	int x=0;
	cin >> n;
	if(n==0)return 0;
	int pro=n;
	for(int i=0;i<n;i++)cin >> a[i];
	for(int i=0;i<n;i++){
		for(int j=1;j<=3;j++){
	     if(a[i]!=j){
	     int u=a[i];
	     a[i]=j;
	     int ans=0;
	     int p=i;
	     int q=i;
	     int s=1;
	     while(p>0||q<n-1){
		     while(p>0&&a[p]==a[p-1])p--,s++;
		     while(q<n-1&&a[q]==a[q+1])q++,s++;
		     if(s>=4){
			     ans+=s;
			     if(a[--p]!=a[++q])break;
			     s=2;
			     continue;
		     }
		         break;
             }
		     
	         pro=min(pro,n-ans);
			 a[i]=u;
			 }
		 }
	}
	printf("%d\n",pro);
	}
    return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

vector<int> dx{1, 0, -1, 0};
vector<int> dy{0, -1, 0, 1};
int main(){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  int count = 0;
  rep(i, h){
    cin >> s[i];
    rep(j, w) if(s[i][j] == '.') count++;
  }
  
  vector<vector<int>> dist(h, vector<int>(w, -1));
  queue<pair<int, int>> que;
  dist[0][0] = 0;
  que.push(make_pair(0, 0));
  int ans = -1;
  bool flag = false;
  while(!que.empty()){
    auto pos = que.front();
    que.pop();
    int ph = pos.first;
    int pw = pos.second;
    rep(i, 4){
      int nh = ph + dx[i];
      int nw = pw + dy[i];
      if (nh < 0 || nw < 0 || nh >= h || nw >= w) continue;
      if (dist[nh][nw] != -1 || s[nh][nw] == '#') continue;
      dist[nh][nw] = dist[ph][pw] + 1;
      que.push(make_pair(nh, nw));
      if (nh == h-1 && nw == w-1){
        ans = count - (dist[nh][nw] + 1);
        flag = true;
        break;
      }
    }
    if(flag) break;
  }
  cout << ans << endl;
  
  return 0;
}

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

int main()
{
  int i=0;
  std::vector<int> list;
  while(1) {
    std::cin >> i;
    if(i == 0) break;
    list.push_back(i);
  }
  for(i=0;i<list.size();i++) std::cout << "Case " << i+1 << ": " << list.at(i) << std::endl;
  return 0;
}



Measured memory_bytes: 3172
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;
struct BIT{
    vector<int> bit;
    int size;
    BIT(int n):size(n), bit(n+1, 0){}
    int sum(int i){
        int s=0;
        while(i>0){
            s+=bit[i];
            i-=(i&(-i));
        }
        return s;
    }
    void add(int i, int x){
        while(i<=size){
            bit[i]+=x;
            i+=(i&(-i));
        }
    }
};
int main()
{
	int n;
	cin>>n;
    ll m=(ll)n*(ll)(n+1)/2;
	int a[100000];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	int x1=0, x2=1e9+1;
	while(x1!=x2){
		int x=(x1+x2+1)/2;
		int s[100001];
        s[0]=0;
		for(int i=0; i<n; i++){
			if(a[i]>=x) s[i+1]=s[i]+1;
            else s[i+1]=s[i]-1;
		}
		BIT bit(2*n+1);
        ll ct=0;
        for(int i=0; i<=n; i++){
            ct+=(ll)bit.sum(n+1+s[i]);
            bit.add(n+1+s[i], 1);
        }
		if(ct>=(m+1)/2) x1=x;
		else x2=x-1;
	}
	cout<<x1<<endl;
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    set<int> s;
    for (int i = 0; i < n; i++)
    {
        int d;
        cin >> d;
        s.insert(d);
    }
    if (s.size() != n)
    {
        cout << "NO" << endl;
    }
    else
    {
        cout << "YES" << endl;
    }
}

Measured memory_bytes: 9600
from re import findall


def main():
    N = int(input())
    num_full = 0
    begin_b = 0
    end_a = 0
    both = 0
    for i in range(N):
        s_i = input()
        num_full += len(findall('AB', s_i))
        if s_i[0] == 'B' and s_i[-1] == 'A':
            both += 1
        if s_i[0] == 'B':
            begin_b += 1
        if s_i[-1] == 'A':
            end_a += 1
    ans = num_full
    if begin_b == end_a:
        if begin_b == both:
            ans += max(begin_b - 1, 0)
        else:
            ans += begin_b
    else:
        ans += min(begin_b, end_a)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        s: chars
    }
    let mut ans = vec![];
    for &c in &s {
        if c == 'B' {
            ans.pop();
        } else {
            ans.push(c);
        }
    }
    println!("{}", ans.iter().cloned().collect::<String>());
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define N 200010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n)	for(int i = n - 1; i >= 0; --i)
#define forr1(i, n)	for(int i = n; i >= 1; --i)
#define form(l, r, i)	for(int i = l; i <= r; ++i)
#define forv(r, l, i)	for(int i = r; i >= l; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
#define elif else if
 
const int inf = 1e9 + 7;
const lld EPS = 0.00000001;
const ll modwdop = 998244353ll;
 
ll pp = 13337ll;
ll modw = 1e9 + 7;
 
using namespace std;

int main()
{
	barnarnar
	lld l;
	cin >> l;
	l /= 3;
	cout << setprecision(10) << fixed << l * l * l;
	r0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}comb(200005);

int main(){
    int s;
    cin >> s;

    mint ans = 0;
    for(int i=1;i<=s/3;i++){
        ans += comb(s-1-2*i, i-1);
    }

    cout << ans << endl;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<long long> X(N);
  vector<long long> sorted(N);
  for (int i = 0; i < N; ++i) {
    cin >> X[i];
    sorted[i] = X[i];
  }
  sort(sorted.begin(), sorted.end());
  long long left = sorted[N / 2 - 1], right = sorted[N / 2];
  for (int i = 0; i < N; ++i) {
    if (X[i] <= left) {
      cout << right << endl;
    }
    else {
      cout << left << endl;
    }
  }
						 
  return 0;
}



Measured memory_bytes: 5376
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    ll a, b;
    cin >> a >> b;
    if (max(a, b) >= min(a, b) + 2)
        cout << "Alice"
             << "\n";
    else
        cout << "Brown"
             << "\n";
    return 0;
}

Measured memory_bytes: 256
while True:
    n = int(input())
    if n==0:
        break
    else:
        a = list(map(int,input().split()))
        m = sum(a) / n #average
        res = 0
        for i in range(n):
            res += (a[i] - m)**2
        print((res/n)**0.5)


Measured memory_bytes: 5664
from itertools import accumulate
from collections import Counter
from scipy.misc import comb

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(accumulate(A))
A = [0] + [a % M for a in A]

ans = 0
C = Counter(A)
for v in C.values():
    ans += comb(v, 2, 1)

print(ans)


Measured memory_bytes: 24352
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 200005;
char s[maxn];

int main() {
	int n = read, k = read;
	scanf("%s", s + 1);

	int p = 1, A = 'A';
	while(k --) {
		if(s[p] == A)
			s[p] = 'A' + 'B' - s[p];
		else {
			A = 'A' + 'B' - A;
			++ p;
			if(p > n) p = 1;
		}
	}

	for(int i = p; i <= n; i ++)
		printf("%c", "BA"[s[i] == A]);
	for(int i = 1; i < p; i ++)
		printf("%c", "BA"[s[i] == A]);
	puts("");
}


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

int main(){
    int N; cin >> N;
    vi d(N);
    for(auto &x : d){
        cin >> x;
    } 
    ll res=0;
    for(int i=0; i<N-1; i++){
        for(int j=i+1; j<N; j++){
            res+=d[i]*d[j];
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int k,s,ans = 0;
    cin >> k >> s;
    if (k + k + k == s) {
        cout << 1 << endl;
        return 0;
    }else if(k + k + k < s){
        cout << 0 << endl;
        return 0;
    }
    rep(x, k + 1){
        rep(y, k + 1){
            if (s - (x + y) <= k && s - (x + y) >= 0) {
                ++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256