akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> answer;
  while(1){
    int m,n_min,n_max,gap_max = 0,ans;
    cin >> m >> n_min >> n_max;
    if(!m)break;
    vector<int> point(m);
    for(int i = 0;i < m;i++)cin >> point[i];
    sort(point.begin(),point.end());
    for(int i = m-n_max;i <= m-n_min;i++){
      if(point[i] - point[i-1] > gap_max){
        ans = m-i;
        gap_max = point[i] - point[i-1];
      }
    }
    answer.push_back(ans);
  }
  for(int i = 0;i < answer.size();i++)cout << answer[i] << endl;
}



Measured memory_bytes: 3120
import java.util.*;
class Main{
	public static void main(String[] args)
    {
      Scanner sc = new Scanner(System.in);
      String S = sc.next();
      String T = sc.next();
      StringBuilder sb  = new StringBuilder();
      sb.append(T);
      sb.append(S);
      System.out.println(sb.toString());
    }
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7

template<typename T>
string printVector(const vector <T> &data) {
    stringstream ss;
    ostream_iterator <T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

#define MAX_V 200005

struct edge {
    int to;
    int cost;
};

// <最短距離, 頂点の番号>
using P = pair<ll, int>;

int V;
vector <edge> graph[MAX_V];
ll d[MAX_V];

void dijkstra(int s) {
    priority_queue <P, vector<P>, greater<P>> que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (int i = 0; i < graph[v].size(); ++i) {
            edge e = graph[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    priority_queue<int> a;
    for (int i = 0; i < n; ++i) {
        int t;
        cin >> t;
        a.push(t);
    }

    for (int i = 0; i < m; ++i) {
        int tmp = a.top();
        a.pop();
        a.push(tmp / 2);
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += a.top();
        a.pop();
    }
    cout << ans << endl;

}


Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define int long long int
#define double long double
#define inf (int)(1e15)
#define all(x) (x).begin(), (x).end()
#define pair pair<int, int>
typedef vector<int> vi;   // Vector of long long
typedef vector<vi> vvi;   // Vector of vi
typedef vector<pair> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of Vector of pairs
typedef vector<bool> vb;  // Vector of bool
#define pq priority_queue // Max heap (To convert to min heap, use negative sign before every value)
#define ff first          // For pairs
#define ss second
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}, dy8[] = {1, -1, 1, 0, -1, 1, -0, -1};
#define testcases(t) \
    int(t);          \
    cin >> (t);      \
    while ((t)--)
signed main()
{
    int n, x, y, ans;
    cin >> n >> x >> y;
    vi dist(n + 1, 0);
    for (int i = 1; i < n; i++)
    {
        for (int j = i + 1; j <= n; j++)
        {
            if ((i < x && j <= x) || (i >= y && j > y))
                ans = j - i;
            else if (i < x && j > y)
                ans = x - i + j - y + 1;
            else if (i >= x && j <= y)
                ans = min(j - i, i - x + y - j + 1);
            else if (i < x && j > x && j <= y)
                ans = x - i + min(j - x, y - j + 1);
            else if (i >= x && i < y && j > y)
                ans = j - y + min(y - i, i - x + 1);
            dist[ans]++;
        }
    }
    for (int i = 1; i < n; i++)
    {
        cout << dist[i] << endl;
    }
    return 0;
}

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

int main() {
    int A,B;
    cin >> A >> B;
    if(A>B) cout << A+A-1;
    if(B>A) cout << B+B-1;
    if(A==B) cout << A+B;
    return 0;
}

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

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

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

bool IsPrime[100005];
int S[100005];

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

    int q;
    cin >> q;
    for(int i = 2; i <= 100000; ++i)    IsPrime[i] = true;
    for(int i = 2; i <= 100000; ++i){
        if(!IsPrime[i]) continue;
        for(int j = i + i; j <= 100000; j += i){
            IsPrime[j] = false;
        }
    }
    for(int i = 3; i <= 100000; ++i){
        if(!IsPrime[i]) continue;
        if(IsPrime[(i + 1) / 2])    ++S[i];
    }
    for(int i = 3; i <= 100000; ++i)    S[i + 1] += S[i];
    for(int i = 0; i < q; ++i){
        int l, r;
        cin >> l >> r;
        cout << S[r + 1] - S[l - 1] << '\n';
    }
}

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

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

Measured memory_bytes: 2988
#include<stdio.h>

int main(){
int a;
long int L[90];
scanf("%d", &a);
L[0] = 2;
L[1] = 1;
for(int i = 0; i <= a; i++) L[i + 2] = L[i + 1] + L[i];

printf("%ld\n", L[a]);
}


Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}";
  return o;
}




int main() {
  int H,W,N,x,y;
  cin >> H >> W >> N >> y >> x;

  string S,T;
  cin >> S >> T;

  vector<int> cnt(4,0);//L,R,U,D
  char s,t;
  rep(i,N){
    if (i>0) {
      t = T[i-1];
      if (t=='L'&&x+cnt[1]-1>0) cnt[1]--;
      else if (t=='R'&&W>x-cnt[0]+1) cnt[0]--;
      else if (t=='U'&&y+cnt[3]-1>0) cnt[3]--;
      else if (t=='D'&&H>y-cnt[2]+1) cnt[2]--;
    }

    s = S[i];
    if (s=='L') cnt[0]++;
    else if (s=='R') cnt[1]++;
    else if (s=='U') cnt[2]++;
    else cnt[3]++;
    
    // cout << cnt << endl;
    if (x<=cnt[0]||W-x<cnt[1]||y<=cnt[2]||H-y<cnt[3]) {
      cout << "NO\n"; return 0;
    }
  }
  cout << "YES\n";
}

Measured memory_bytes: 776
#include <iostream>
#include <algorithm>
using namespace std;
int maxtime(int x) {
	// Maximum consuming time for x-minute order
	return (x + 9) / 10 * 10;
}
int remtime(int x) {
	// Remained time for x-minute order
	return maxtime(x) - x;
}
int main() {
	int A, B, C, D, E;
	cin >> A >> B >> C >> D >> E;
	int sum = maxtime(A) + maxtime(B) + maxtime(C) + maxtime(D) + maxtime(E);
	sum -= max({ remtime(A), remtime(B), remtime(C), remtime(D), remtime(E) });
	cout << sum << endl;
	return 0;
}

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

int digit_sum(int x) {
  int s = 0;
  while (0 < x) {
    s += x % 10;
    x /= 10;
  }
  return s;
}

int main() {
  int N, s;
  cin >> N;
  s = digit_sum(N);
  if (N % s == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define eps 1e-6
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, k=0, i, j,l=2e9+7;
  string s, r, y;
  cin>>n;
  if(n) cout<<0;
  else cout<<1;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
  // cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main{
  public static void main(String args[]){
    Scanner scanner = new Scanner(System.in);
    int inputA = scanner.nextInt();
    int inputB = scanner.nextInt();

    if(inputA<inputB){
      System.out.println("a < b");
    }else if(inputA>inputB){
      System.out.println("a > b");
    }else{
      System.out.println("a == b");
    }
  }
}

Measured memory_bytes: 26084
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;
typedef vector<int> VI;
#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )

int main() {
    VI nums;
    
    int a, b;
    while (cin >> a >> b) {
        nums.push_back(a + b);
    }
    
    for (int n : nums) {
        cout << floor(log10(n)) + 1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1312
class SegTree():
    def __init__(self, lists, function, basement):
        self.n = len(lists)
        self.K = (self.n-1).bit_length()
        self.func = function
        self.basement = basement
        self.seg = [basement]*2**(self.K+1)
        self.lazy_seg = [basement]*2**(self.K+1)
        X=2**self.K
        for i,v in enumerate(lists):
            self.seg[i+X-1] = v

        for i in range(2*X-2, 0, -2):
            self.seg[(i-1)>>1] = self.func(self.seg[i], self.seg[i-1])

    def update(self, k, value):
        # 0-indexでa[k]の値をvalueに変更
        X=2**self.K
        k += X-1
        self.seg[k] = value
        while k:
            k = (k-1)>>1
            self.seg[k] = self.func(self.seg[(k<<1)+1], self.seg[(k<<1)+2])

            

    def query(self, p, q):
        # 0-indexで[p,q)の値を取得する
        if q <= p:
            return self.basement
        num = 2**self.K
        p += num-1
        q += num-2
        res = self.basement
        while q-p > 1:
            if p & 1 == 0:
                res = self.func(res, self.seg[p])
            if q & 1 == 1:
                res = self.func(res, self.seg[q])
                q -= 1
            p = p>>1
            q = (q-1)>>1
        if p == q:
            res = self.func(res, self.seg[p])
        else:
            res = self.func(self.func(res, self.seg[p]), self.seg[q])
        return res

import sys
input=sys.stdin.readline
N=int(input())
S=list(input())
Q=int(input())
que=[tuple(input().split()) for i in range(Q)]
alpha="abcdefghijklmnopqrstuvwxyz"
Data={alpha[i]:[0]*N for i in range(26)}
for i in range(N):
    Data[S[i]][i]+=1
SEG={alpha[i]:SegTree(Data[alpha[i]],max,0) for i in range(26)}
for X,u,v in que:
    if X=="1":
        u=int(u)-1
        NOW=S[u]
        S[u]=v
        SEG[NOW].update(u,0)
        SEG[v].update(u,1)
    else:
        u,v=int(u)-1,int(v)-1
        res=0
        for j in range(26):
            res+=SEG[alpha[j]].query(u,v+1)
        print(res)
            
        
    
    


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

int main() {
    int N, a, min = 1001, max = -1;
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> a;
        if(a < min) {
            min = a;
        }
        if(a > max) {
            max = a;
        }
    }
    cout << max - min << endl;
    return 0;
}

Measured memory_bytes: 256
def calcPatt(steps):
    if steps <= 1:
        return 1
    elif steps == 2:
        return 2
    ll = {}
    # ここからは3以上
    for i in range(steps)[::-1]:
        if i + 1 == steps:
           ll[i] = 1
        elif i + 2 ==steps:
            ll[i] = 2
        else:
            ll[i] = ll[i+1] + ll[i+2]
    
    return ll[0]

N, M = map(int,(input().split()))

before = 0
f = True
ll = []
ax = {}
for i in range(M):
    # 上っていい段数を取得
    a = int(input())
    ax[i] = a
    limit = a - 1
    stepRenge = limit  - before
    #print("before:{}/limit:{}/break:{}/step:{}".format(before,limit,a,stepRenge))
    if not f and stepRenge == -1:
        ll.append(0)
        break
    ll.append(calcPatt(stepRenge))
    before = limit + 2
    f = False
    

# 最後の一回分が残ってるのでやる
stepRenge = N  - before
ll.append(calcPatt(stepRenge))

pro = 1
for i in ll:
    pro = (pro * i) % 1000000007
 
print(pro)

Measured memory_bytes: 468516
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <string>
#include <sstream>
#include <cstring>
#include <cmath>

using namespace std;

#ifdef DEBUG
#define LOG(args) cout << args << "\n"
#define debug(x) x
#else
#define LOG(args)
#define debug(x)
#endif

#define vi vector<int>
#define ii pair<int, int>
#define vii vector< ii >
#define vvi vector< vi >
#define mp make_pair
#define pb push_back
#define ms(x, v) memset(x, v, sizeof(x))
#define all(x) x.begin(), x.end()
#define REP(x, n) for(int x = 0; x < n; x++)
#define REPV(x, v, n) for(int x = v; x < n; x++)
#define REVE(x, n) for(int x = n; x >= 0; x--)

typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int M, N, K, ans = 0;
	cin >> M >> N >> K;
	string grid[M];
	REP(i, M)
		cin >> grid[i];
	REP(mi, (1 << M))
	{
		REP(mj, (1 << N))
		{
			int black = 0;
			REP(i, M)
			{
				REP(j, N)
				{
					if((mi & (1 << i)) && (mj & (1 << j)) && grid[i][j] == '#')
						black++;
				}
			}
			ans += black == K;
		}
	}
	cout << ans << "\n";
	return 0;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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 T>
void print1(T begin, T end) {
  while (begin != end) {
    cerr << (*begin) << " ";
    *begin++;
  }
  cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cerr << " " << Array[i][j];
    }
    cerr << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

signed main() {
  int n, k;
  cin >> n >> k;

  if (n >= k) {
    if (n % k == 0) {
      cout << 0 << endl;
    } else {
      cout << 1 << endl;
    }
  } else {
    cout << 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
object Main extends App {
  def count(seq: Seq[StepAction]): Int = {
    val aerobics = new Aerobics(Down)
    seq.foreach(aerobics.action)
    aerobics.count
  }

  def solve(): Unit = {
    while (AerobicsReader.hasNext()) {
      println(count(AerobicsReader.next()))
    }
  }

  solve()
}

class Aerobics(var currentState: AerobicsState) {
  var objectiveState = currentState.nextObject
  var count = 0

  def action(action: StepAction): Unit = {
    currentState = currentState.transition(action)
    if (currentState == objectiveState) {
      count += 1
      objectiveState = currentState.nextObject
    }
  }
}

object AerobicsReader extends StepAction {
  def hasNext(): Boolean = {
    io.StdIn.readLine().toInt > 0
  }

  def next(): Seq[StepAction] = {
    io.StdIn.readLine().split("\\s").map(valueOf).toSeq
  }
}

/*
 ?¶???????????????¨?????????
 */
sealed trait StepAction {

  val valueOf = (code: String) => {
    code match {
      case "lu" => LeftUp
      case "ru" => RightUp
      case "ld" => LeftDown
      case "rd" => RightDown
      case _ => throw new NoSuchElementException(code + ": unexpected token")
    }
  }
}

case object LeftUp extends StepAction

case object RightUp extends StepAction

case object LeftDown extends StepAction

case object RightDown extends StepAction


/*
 ????¶??????¶????????¨?????????
 */
sealed trait AerobicsState {
  val nextObject: AerobicsState = null

  def transition(action: StepAction): AerobicsState
}

case object Down extends AerobicsState {
  override val nextObject = Up

  override def transition(action: StepAction): AerobicsState = {
    action match {
      case LeftUp => UpOnlyLeft
      case RightUp => UpOnlyRight
      case _ => this
    }
  }
}

case object UpOnlyLeft extends AerobicsState {
  override def transition(action: StepAction): AerobicsState = {
    action match {
      case RightUp => Up
      case LeftDown => Down
      case _ => this
    }
  }
}

case object UpOnlyRight extends AerobicsState {
  override def transition(action: StepAction): AerobicsState = {
    action match {
      case LeftUp => Up
      case RightDown => Down
      case _ => this
    }
  }

}

case object Up extends AerobicsState {
  override val nextObject = Down

  override def transition(action: StepAction): AerobicsState = {
    action match {
      case LeftDown => UpOnlyRight
      case RightDown => UpOnlyLeft
      case _ => this
    }
  }
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M,Q;;
int dp[501][501];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>Q;
	FOR(i,M) {
		cin>>x>>y;
		dp[x][y]++;
	}
	for(i=2;i<=N;i++) {
		for(x=1;x+i-1<=N;x++) {
			dp[x][x+i-1]+=dp[x+1][x+i-1]+dp[x][x+i-2]-dp[x+1][x+i-2];
		}
	}
	FOR(i,Q) {
		cin>>x>>y;
		cout<<dp[x][y]<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
using namespace std;
const int maxd=1000000007,N=100000;
const double pi=acos(-1.0);
typedef long long ll;
int n,m;
ll x[100100],dis[100100];

int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

int main()
{
	m=read();n=read();int i;
	for (i=1;i<=n;i++) x[i]=read();
	if (m>=n) {cout << 0 << endl;return 0;}
	sort(x+1,x+1+n);
	for (i=1;i<n;i++) dis[i]=x[i+1]-x[i];
	//for (i=1;i<n;i++) cout << dis[i] << " ";cout << endl;
	sort(dis+1,dis+n);
	ll ans=0;
	for (i=1;i<n;i++) ans+=dis[i];
	for (i=n-1;i>n-m;i--) ans-=dis[i];
	cout << ans;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int M, D;

int main(void) {

	cin >> M >> D;

	int ans = 0;

	int d1, d2;

	for (int i = 1; i <= M; i++) {
		for (int j = 1; j <= D; j++) {
			d1 = j % 10;
			d2 = j / 10;
			if (d1>=2 && d2>=2 && (i == d1*d2)) { 
				//cout << d2 << "  "<<d1<<endl;
				ans++; }
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int num = 0;
		int count = 0;
		boolean prime;

		for (int i = 0; i < n; i++) {
			num = sc.nextInt();
			if (num == 2) {
				count++;
				continue;
			}

			prime = true;
			for (int j = 2; j < num / (j-1); j++) {
				if (num % j == 0) {
					prime = false;
					break;
				}
			}
			if (prime) {
				count++;
			}
		}

		System.out.println(count);
	}

}


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

int main() {
    int n;
    string s, t;
    cin >> n >> s;
    t = "Yes";
    for(int i=0; i<(n+1)/2; i++) {
        if (n%2==1) {
            t = "No";
            break;
        }

        if(s.at(i) != s.at(i+n/2)) {
            t =  "No";
            break;
        }
    }
    cout << t << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPS(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
using ll = long long;
using ld = long double;

int main(void) {
    int N;
    cin >> N;

    bool flg = false;
    REP (i, 3) {
        if (N % 10 == 7) {
            flg = true;
        }
        N /= 10;
    }

    if (flg) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
long long int n,minimum[100010];
vector<long long int>v;
long long int dp(long long index)
{
    long long int temp1,temp2=INT_MAX;
    if(index==n-1)
        return 0;
    if(minimum[index+1]==-1)
    {
        minimum[index+1]=dp(index+1);
    }
    temp1=abs(v[index]-v[index+1])+minimum[index+1];
    if(minimum[index+2]==-1 && index<n-2)
    {
        minimum[index+2]=dp(index+2);
    }
    if(index<n-2)
        temp2=abs(v[index]-v[index+2])+minimum[index+2];
    return min(temp1,temp2);

}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    long long int i,j,k,temp;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>temp;
        v.push_back(temp);
    }
    memset(minimum,-1,sizeof(minimum));
    cout<<dp(0);
}


Measured memory_bytes: 6644
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
int d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];

int dfs(int x,int y){
  if(dp[x][y] != -1)return dp[x][y];
  if(y - x <= 0)return dp[x][y] = 0;
  int res = 0;
  for(int i = x;i < y;i++){
    res = max(res,dfs(x,i) + dfs(i + 1,y));
  }
  if(abs(d[x] - d[y]) <= 1){
    if(dfs(x+1,y-1) == y - x - 1){
      res = max(res,dfs(x+1,y-1)+2);
    }
  }
  return dp[x][y] = res;
}

int main(){
  while(1){
    cin >> n;
    if(n == 0)break;
    clr(dp,-1);
    rep(i,0,n)cin >> d[i];
    print(dfs(0,n-1));
  }
  return 0;
}


Measured memory_bytes: 7164
import math as m

def find_cd(n):
    n_cd = set()
    for i in range(1,round(m.sqrt(n))+1):
        if n%i == 0:
            n_cd.add(i)
            n_cd.add(n//i)
            
    return list(n_cd)


def f(a,b):
    ans_a = 0
    ans_b = 0
    res_a = a
    res_b = b
    while res_a > 0:
        res_a = res_a // 10
        ans_a += 1
        
    while res_b > 0:
        res_b = res_b // 10
        ans_b += 1
        
    return max(ans_a, ans_b)
        
n = int(input())
lst = find_cd(n)

lst.sort()

len_lst = len(lst)

ans_min = 10000

for i in range(len_lst//2):
    ans = f(lst[i],lst[len_lst-i-1])
    ans_min = min(ans_min, ans)
    
if len_lst%2 == 1:
    ans = f(lst[len_lst//2], lst[len_lst//2])
    ans_min = min(ans_min, ans)

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main() {
	string s;
	cin >> s;
	int n = s.size();
	stack<char> stk;
	for(int i = 0; i < n; i++){
        if(!stk.empty() && s[i] == 'T' && stk.top() == 'S'){
            stk.pop();
        }
        else stk.push(s[i]);
	}
	cout << stk.size() << endl;
}


Measured memory_bytes: 644
// #include <bits/stdc++.h>
#include <cstdio>
#include <vector>
#include <functional>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

// using i32 = std::int_fast32_t;
// using i64 = std::int_fast64_t;
using i32 = int;
using i64 = long long;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()

// template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

// struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); } } initCpp;

signed main() {
  i32 x, y, z, k;
  scanf("%d%d%d%d", &x, &y, &z, &k);
//  cin >> x >> y >> z >> k;
  vector<i64> A(x), B(y), C(z);
  REP(i, x) scanf("%lld", &A[i]);
  REP(i, x) scanf("%lld", &B[i]);
  REP(i, x) scanf("%lld", &C[i]);
//  cin >> A >> B >> C;
  sort(ALL(A), greater<i64>());
  sort(ALL(B), greater<i64>());
  sort(ALL(C), greater<i64>());
  using T = tuple<i32, i32, i32>;
  using P = pair<i64, T>;
  priority_queue<P> Q;
  Q.push({A[0] + B[0] + C[0], make_tuple(0, 0, 0)});
  set<T> S;
  S.insert(make_tuple(0, 0, 0));
  REP(_, k) {
    i64 p = Q.top().first;
    i32 u, v, w;
    tie(u, v, w) = Q.top().second;
    Q.pop();
    printf("%lld\n", p);
    // cout << p << endl;
    auto u1 = make_tuple(u + 1, v, w);
    auto v1 = make_tuple(u, v + 1, w);
    auto w1 = make_tuple(u, v, w + 1);
    if (u + 1 < x && !S.count(u1)) { S.insert(u1); Q.push({A[u + 1] + B[v] + C[w], u1}); }
    if (v + 1 < y && !S.count(v1)) { S.insert(v1); Q.push({A[u] + B[v + 1] + C[w], v1}); }
    if (w + 1 < z && !S.count(w1)) { S.insert(w1); Q.push({A[u] + B[v] + C[w + 1], w1}); }
  }
}

Measured memory_bytes: 896
#include <iostream>
#include <math.h>

using namespace std;

int main() {
    int k, s;
    cin >> k >> s;
    int count = 0;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <=min(s-x, k) ; y++) {
            int z = s - x - y;
            if (z >= 0 && z <= k) {
                count++;
            }
        }
    } 
    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<math.h>
using namespace std;

#define LL long long

LL arr[1000000];

int main()
{
        int n;
        while(cin>>n){
                arr[0]=0;
                for(int i=1;i<=n;i++){
                        int k;scanf("%d",&k);
                        arr[i]=arr[i-1]+k;
                }
                map<LL,int> ma;
                map<LL,int> mb;
                LL ans=0;
                for(int i=0;i<=n;i++){
                        ma[arr[i]]++;
                }
                for(int i=0;i<=n;i++){
                        if(mb[arr[i]])continue;
                        mb[arr[i]]=1;
                        ans+=(ma[arr[i]]-1)*(LL)ma[arr[i]]/2;
                }
                cout<<ans<<endl;
        }
        return 0;
}


Measured memory_bytes: 26752
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,c = "No";
  cin >> s;
  for(int i=0;i<s.size()-1;i++){
    if(s[i]=='A'&&s[i+1]=='C') c = "Yes";
  }
  cout << c << endl;
}


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



int main(int argc, char const *argv[]) {
  int a, b, c; cin >> a >> b >> c;
  printf("%d %d %d", c, a, b);
  return 0;
}


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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#ifdef LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll read(){
	ll i;
	scanf("%"  SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}

signed main(){
	int n=read(),m=read();
	string s=readString();
	string t=readString();
	int g=gcd(n,m);
	REP(i,g)
		if(s[i*(n/g)]!=t[i*(m/g)]){
			print(-1);
			return 0;
		}
	print(n*m/g);
}


Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <queue>
#include <set>

using namespace std;

const long long inf = 1e8 + 5;

int main()
{
    long long N;
    cin >> N;
    vector<long long> a(N);

    long long maxa = -inf;
    long long mina = inf;

    map<long long, long long> m;

    for (long long i = 0; i < N;i++)
    {
        cin >> a[i];
        maxa = max(maxa, a[i]);
        mina = min(mina, a[i]);
    }
    for (long long i = 0; i < N;i++)
    {
        if(a[i] == maxa)
        {
            m[maxa]++;
        }
        else
        {
            m[mina]++;
        }
    }
    //cout << "m[maxa] = " << m[maxa] << endl;
    //cout << "m[mina] = " << m[mina] << endl;
    string ans;
    long long val = (long long)(m[maxa] / 2);
    if (maxa - mina >= 2 || m[maxa] == 1)
    {
        ans = "No";
    }
    else if(maxa - mina == 0)
    {
        if(maxa <= val || maxa == N - 1)
        {
            ans = "Yes";
        }
        else
        {
            ans = "No";
        }
    }
    else
    {
        if (mina <= m[mina] - 1 + val && m[mina] <= mina )
        {
            ans = "Yes";
        }
        else
        {
            ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int dp[3001][3001];

int main()
{
	string a, b;
    cin>>a;
    cin>>b;
    memset(dp, 0, sizeof(dp));
    for(int i = 1; i <= a.length(); ++i)
    {
        for(int j = 1; j <= b.length(); ++j)
        {
            if(a[i - 1] == b[j - 1])
                dp[i][j] = 1 + dp[i - 1][j - 1];
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    int len = dp[a.length()][b.length()];
    string s;
    int i = a.length(), j = b.length();
    while(i > 0 and j > 0)
    {
        if(a[i - 1] == b[j - 1])
        {
            s += b[j - 1];
            len--;
            i--;
            j--;
        }
        else if(dp[i][j] == dp[i - 1][j])
            i--;
        else if(dp[i][j] == dp[i][j - 1])
            j--;
    }
    reverse(s.begin(), s.end());
    cout<<s;
    return 0;
}

Measured memory_bytes: 35456
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;

string S;
int Len,Ans,N;
int main()
{
	cin >>S;
	Len=S.length();
	S=" "+S;
	if(S[1]!='A')
	{
		printf("WA");
		return 0;
	}
	if(int(S[2])<97)
	{
		printf("WA");
		return 0;
	}
	if(int(S[Len])<97)
	{
		printf("WA");
		return 0;
	}
	for(int i=3;i<Len;i++)
	{
		if(S[i]=='C') Ans++;
		if(Ans>1)
		{
			printf("WA");	
			return 0;
		}
		if(S[i]!='C'&&S[i]!='A')
		if(int(S[i])<97)
		{
			printf("WA");
			return 0;
		}
	}
	if(!Ans) printf("WA");
	else if(Ans==1) printf("AC");
} 

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=100050;
//int arr[SIZE]={};
//ここまでテンプレ
int main(){
	int H,W;
	cin>>H>>W;
	int alpha[26]={};
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			char c;
			cin>>c;
			alpha[c-'a']++;
		}
	}
	int four=0,even=0,odd=0;
	for(int i=0;i<26;i++){
		if(alpha[i]%4==0)
			four++;
		else if(alpha[i]%2==0)
			even++;
		else
			odd++;
	}
	if(H%2==0 && W%2==0){
		if(even==0 && odd==0)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
	else if(H%2 && W%2){
		int kisuu=(H/2+W/2);
		if(odd==1 && even<=kisuu)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
	else{
		int kisuu=0;
		if(H%2){
			kisuu=W/2;
		}
		else{
			kisuu=H/2;
		}

		if(odd==0 && even<=kisuu)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
def root(v):
    if v == par[v]:
        return v
    par[v] = root(par[v])
    return par[v]

def unite(u, v):
    u = root(u)
    v = root(v)
    if u == v:
        return
    if rank[u] < rank[v]:
        par[u] = v
    else:
        par[v] = u
        if rank[u] == rank[v]:
            rank[u] += 1

def bridge(u, v):
    return root(u) != root(v)

N, M = map(int, input().split())
E = [tuple(map(int, input().split())) for _ in range(M)]
ans = 0
for i in range(M):
    par = list(range(N))
    rank = [0] * N
    tmp_E = E[:i] + E[i+1:]
    for a, b in tmp_E:
        unite(a-1, b-1)
    a, b = E[i]
    ans += bridge(a-1, b-1)
print(ans)

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

using namespace std;

typedef long long ll;

#define MOD (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()

ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

pll norm(ll x,ll y)
{
  ll g=__gcd(abs(x),abs(y));
  x/=g;
  y/=g;
  if(x<0)return mp(-x,-y);
  else return mp(x,y);
}


int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);


string s,t;
cin>>s>>t;
sort(all(s));
sort(t.rbegin(),t.rend());

if(s<t)cout<<"Yes"<<"\n";
else cout<<"No"<<"\n";


return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

int count(string& s){
    int res=0;
    for(int i=0;i<s.length()-1;i++){
        if(s[i]==s[i+1])res++;
    }
    return res;
}

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

    
    int n,k;
    cin>>n>>k;
    string s,t;
    cin>>s;
    t=s;
    //全部左のに揃える
    int kn=k;
    for(int i=1;i<n;i++){
        if(kn>0&&s[i]!=s[0]){
            kn--;
            int j=0;
            while(i+j<n&&s[i+j]!=s[0]){
                s[i+j]=s[0];
                j++;
            }
            i=max(i+j-1,i);
        }
        if(kn==0)break;
    }
    fin(count(s));
    // fin(s);

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int N=2e5+10;
int a[N];
int w[N];

int cmp1(int a,int b)
{
    return b<a;
}
multiset<int> ss;
map<int,int>mp;
int main()
{

    int n;
    cin>>n;
    cout<<n+n*n+n*n*n;
    //for(int i=1;i<=n;i++) cin>>a[i];
}


Measured memory_bytes: 3624
#define SUBMIT

// https://beta.atcoder.jp/contests/abc105

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>

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

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

    for (int i = 0; i <= 25; ++i) {
        for (int j = 0; j <= 15; ++j) {
            auto total = 4 * i + 7 * j;
            if (total > 100) {
                continue;
            }

            if (total == N) {
//                cout << i << " " << j << endl;
                cout << "Yes" << endl;
                exit(0);
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define REPM(i,n,a) for(int i = n - 1; i >= a; --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFD 1.0e+308
typedef long long LL;
typedef unsigned long long ULL;

typedef pair<LL, LL> PP;

int H, W;
string S;
int main() {
	cin >> H >> W;
	REP(i, 0, H) {
		cin >> S;
		cout << S << endl << S << endl;
	}
	return 0;
}

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

#define pb push_back
#define int ll

using ll=long long;
using pii=pair<int,int>;
using vpii=vector<pii>;
using vvpii=vector<vpii>;
using vi=vector<int>;
using vvi=vector<vi>;


void f(int n, int i, bool top, vi& sol) {
  // how can we get to 1?
  // - k doesn't divide n -> will always subtract -> iff k | (n-1)
  //   (also handles all k > sqrt n which don't divide n)
  if ((n-1) % i == 0) {
    sol.pb(i);
    if (top) {
      int d2 = (n-1) / i;
      if (d2 > i)
        sol.pb(d2);
    }
    return;
  }
  // - k divides n -> go to n/k first. recurse. O(nlogn)
  //   (k | n and k > sqrt n  -> stuck after n/k, so never a sol)
  if (n % i == 0) {
    f(n/i, i, false, sol);
  }
}

signed main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vi sol;
  for (int i=2; i*i<=n; ++i)
    f(n, i, true, sol);
  if (n-1 >= 2)
    sol.pb(n-1);  // valid and not a duplicate since n > 2
  sol.pb(n);
  cout << sol.size() << "\n";
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll N;
    cin >> N;
    ll L[N];
    rep(i,N) cin >> L[i];
    sort(L,L+N);
//    rep(i,N) cout << L[i] << " ";
//    cout << endl;
    ll out = 0;
    rep(i,N-2){
        for(ll j=i+1;j<N-1;j++){
            for(ll k=j+1;k<N;k++){
                if(L[k]<L[i]+L[j]){
                    out++;
//                    cout << L[i] << " " << L[j] << " " << L[k] << endl;
                }else break;
            }
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int i, j, h, w;
   
    cin >> h >> w;
    while(h>0 || w>0)
    {
        for(int j=0;j<w;j++) cout << "#";
            cout << endl;
        for(int i=1;i<h-1;i++)
        {
            cout << "#";
        for(int j=1;j<w-1;j++) cout << ".";
            cout << "#" << endl;
        }
    for(int j=0;j<w;j++) cout << "#";
    cout << endl;
    
        cout << endl;
    
        cin >> h >> w;
    }
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;

static const int MAX_SIZE = 1 << 20; 

LL segMax[2 * MAX_SIZE - 1], segAdd[2 * MAX_SIZE - 1];

//区間[a, b)に値xを加算する.
void add(int a, int b, LL x, int k = 0, int l = 0, int r = MAX_SIZE)
{
    if (r <= a || b <= l) return;

    if (a <= l && r <= b){
        segAdd[k] += x;
        return;
    }

    add(a, b, x, k * 2 + 1, l, (l + r) / 2);
    add(a, b, x, k * 2 + 2, (l + r) / 2, r);

    segMax[k] = max(segMax[k * 2 + 1] + segAdd[k * 2 + 1], segMax[k * 2 + 2] + segAdd[k * 2 + 2]);
}

LL getMax(int a, int b, int k = 0, int l = 0, int r = MAX_SIZE)
{
    if (r <= a || b <= l) return 0;

    if (a <= l && r <= b) return (segMax[k] + segAdd[k]);

    LL left = getMax(a, b, k * 2 + 1, l, (l + r) / 2);
    LL right = getMax(a, b, k * 2 + 2, (l + r) / 2, r);

    return (max(left, right) + segAdd[k]);
}

vector<P> v[200001];

int main(){
    int n,m;cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int l,r,a;cin >> l >> r >> a;
        v[r].pb(make_pair(l,a));
    }
    for (int i = 0; i <= n; i++) {
        add(i,i+1,getMax(0,i));
        for (int j = 0; j < v[i].size(); j++) {
            add(v[i][j].fs,i+1,v[i][j].sc);
        }
    }
    cout << getMax(0,n+1) << endl;
    return 0;

}


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

int main() {
int n,d;
cin >> n >> d;
vector<vector<int>> a(n,vector<int>(d));
rep(i,n){
  rep(j,d) cin >> a.at(i).at(j);
}
int ans = 0;
rep(i,n){
  rep(j,i){
    int dis = 0;
    rep(k,d){
      dis += (a.at(i).at(k) - a.at(j).at(k))*(a.at(i).at(k) - a.at(j).at(k));
    }
    int s = sqrt(dis) + 0.5;
    if(s*s == dis) ans++;
  }
}
cout << ans << endl;
}
  


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,t[10000],m,p[100],x[10000],a,sum[100]={0};
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>t[i];
	}
	cin>>m;
	for(int j=0;j<m;j++){
		cin>>p[j]>>x[j];
	}
	for(int k=0;k<m;k++){
		a=p[k]-1;
		for(int l=0;l<n;l++){
			if(l==a){
				sum[k]+=x[k];
			}
			else{
				sum[k]+=t[l];
			}
		}
	}
	for(int z=0;z<m;z++){
		cout<<sum[z];
		if(z<m-1){
			cout<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256