akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
 
public class Main{
  public static void main(String[]args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(System.out);
    String[] S = br.readLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int M = Integer.parseInt(S[1]);
    
    int[][] val = new int[M][3];
    for(int i = 0; i < M; i++){
      String[] T = br.readLine().split(" ");
      val[i][0] = Integer.parseInt(T[0]);
      val[i][1] = Integer.parseInt(T[1]);
      val[i][2] = i;
    }
    Arrays.sort(val, (a, b) -> Integer.compare(a[1], b[1]));
    
    String[] ans = new String[M];
    int[] count = new int[N+1];
    String[] zero = {"00000", "0000","000","00","0"};
    for(int i = 0; i < M; i++){
      StringBuilder sb = new StringBuilder();
      int a = val[i][0];
      count[a]++;
      
      if(a < 10){
        sb.append(zero[0]);
        sb.append(a);
      }else if(a < 100){
        sb.append(zero[1]);
        sb.append(a);
      }else if(a < 1000){
        sb.append(zero[2]);
        sb.append(a);
      }else if(a < 10000){
        sb.append(zero[3]);
        sb.append(a);
      }else if(a < 100000){
        sb.append(zero[4]);
        sb.append(a);
      }else{
        sb.append(a);
      }
      
      int b = count[a];
      if(b < 10){
        sb.append(zero[0]);
        sb.append(b);
      }else if(b < 100){
        sb.append(zero[1]);
        sb.append(b);
      }else if(b < 1000){
        sb.append(zero[2]);
        sb.append(b);
      }else if(b < 10000){
        sb.append(zero[3]);
        sb.append(b);
      }else if(b < 100000){
        sb.append(zero[4]);
        sb.append(b);
      }else{
        sb.append(b);
      }
      
      ans[val[i][2]] = (sb.toString());
    }
    
    for(String s : ans){
     out.println(s); 
    }
    out.flush();
  }
}


Measured memory_bytes: 58836
#include <iostream>
#include <string>
using namespace std;
string s;
string ans;
bool ok = false;
void DFS(int nw,int c){
  if(nw == 4 && c == 7){
    if(!ok)cout << ans << "=7" << endl;
    ok = true;
    return;
  }else if(nw == 4){
    return;
  }
  ans.push_back('+');
  ans.push_back(s[nw]);
  DFS(nw+1,c+s[nw]-'0');
  ans.pop_back();
  ans.pop_back();
  ans.push_back('-');
  ans.push_back(s[nw]);
  DFS(nw+1,c-(s[nw]-'0'));
  ans.pop_back();
  ans.pop_back();
}
int main(){
  cin>>s;
  ans.push_back(s[0]);
  DFS(1,s[0]-'0');
}
  
  


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

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

    int cnt = 0;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            int z = s - x - y;
            if (z >= 0 && z <= k) {
                cnt++;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
using System;

class C
{
	static void Main()
	{
		var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		Console.WriteLine(Lcm(h[0], h[1]));
	}

	static long Gcd(long x, long y) { for (long r; (r = x % y) > 0; x = y, y = r) ; return y; }
	static long Lcm(long x, long y) => x / Gcd(x, y) * y;
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  const int MAX = 1e6;
  int gcd = 0;
  vi cnt(MAX+1);
  rep(i,n){
    int a; cin >> a;
    gcd = __gcd(gcd,a);
    cnt[a]++;
  }
  if(gcd != 1){
    cout << "not coprime";
    return 0;
  }
  bool ok = true;
  for(int i = 2; i <= MAX; i++){
    int res = 0;
    for(int j = i; j <= MAX; j += i) res += cnt[j];
    if(1 < res) ok = false;
  }
  if(ok){
    cout << "pairwise coprime";
  }else{
    cout << "setwise coprime";
  }
  cout << "\n";
  return 0;
}


Measured memory_bytes: 7148
MOD=1000000000+7
def run():
    H,W,K=map(int,input().split())
    K=K-1
    dp=[0]*1000 #dp[i]=i個縦棒がある時その中から何通り選ぶ方法があるか
    dp[0]=1
    dp[1]=1
    dp[2]=2
    for i in range(3,1000):
        dp[i]=(dp[i-1]+dp[i-2])%MOD
    dp2=[[0 for j in range(W)] for i in range(H+1)]
    dp2[0][0]=1
    for i in range(H):
        for j in range(W):
            dp2[i+1][j]=(dp2[i+1][j]+dp2[i][j]*dp[j]%MOD*dp[W-j-1]%MOD)%MOD
            if(j-1>=0):
                dp2[i+1][j-1]=(dp2[i+1][j-1]+dp2[i][j]*dp[j-1]%MOD*dp[W-j-1]%MOD)%MOD
            if(j+1<W):
                dp2[i+1][j+1]=(dp2[i+1][j+1]+dp2[i][j]*dp[j]%MOD*dp[W-j-2]%MOD)%MOD
    print(dp2[H][K])
run()



Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define rep(a,b,c) for (int a=b;a<=c;a++)
#define per(a,b,c) for (int a=b;a>=c;a--)
#define go(u) for (int o=ft[u],v;v=E[o].t;o=E[o].n)
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long LL;
typedef pair<int,int> par;
const int N=200010;
int n,a[N],x,y;
struct nod{
	par l,r;
	int s;
}tr[N<<2];
#define ___ int t=1,int l=1,int r=n
#define mid ((l+r)>>1)
#define ls t<<1,l,mid
#define rs t<<1|1,mid+1,r
nod operator + (nod x,nod y){
	if (x.s) swap(y.l,y.r);
	x.l=min(x.l,y.l);
	x.r=min(x.r,y.r);
	x.s^=y.s;
	return x;
}
void bui(___){
	if (l==r){
		tr[t]=(nod){(par){a[l],l},(par){n+233,0},1};
		return;
	}
	bui(ls),bui(rs),tr[t]=tr[t<<1]+tr[t<<1|1];
}
nod ask(___){
	if (x<=l&&y>=r) return tr[t];
	if (y<=mid) return ask(ls);
	if (x>mid) return ask(rs);
	return ask(ls)+ask(rs);
}
struct dat{
	int k,l,r;
};
bool operator < (dat x,dat y){return x.k>y.k;}
priority_queue <dat> q;
void __(int l,int r){
	nod tmp;
	x=l,y=r,tmp=ask();
	q.push((dat){tmp.l.fi,l,r});
}
void push(int l,int r){
	nod tmp;
	x=l,y=r,tmp=ask();
	int xi=tmp.l.se;
	x=xi+1,tmp=ask();
	int yi=tmp.l.se;
	printf("%d %d ",a[xi],a[yi]);
	if (l<xi-1) __(l,xi-1);
	if (xi+1<yi-1) __(xi+1,yi-1);
	if (yi+1<r) __(yi+1,r);
}
int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",a+i);
	bui();
	push(1,n);
	while (!q.empty()){
		dat t=q.top();
		q.pop();
		push(t.l,t.r);
	}
	return 0;
}


Measured memory_bytes: 18552
import java.io.PrintWriter
import java.util.*
import kotlin.math.max

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (N, K) = nextIntList()
    val S = next()
    val list = ArrayList<P>()
    var i = 0
    while (i < N) {
        var j = i + 1
        while (j < N && S[i] == S[j]) j++
        list.add(P(S[i], j - i))
        i = j
    }
    var r = 0
    var k = 0
    var ans = 0
    var sum = 0
    for (l in list.indices) {
        while (r < list.size) {
            if (list[r].c == '0') {
                if (k == K) break
                k++
            }
            sum += list[r].l
            r++
        }
        ans = max(ans, sum)
        if (l == r) r++
        sum -= list[l].l
        if (list[l].c == '0') k--
    }
    println(ans)
}

data class P(val c: Char, val l: Int)

Measured memory_bytes: 42580
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    N = int(input())
    A_list = [int(input()) for i in range(N)]
    ans = 0
    pre_rest = 0
    for a in A_list:
        if pre_rest and a > 0:
            ans += 1
            a -= 1
        ans += a // 2
        pre_rest = a % 2

    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> num(100000);//1-index
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    num.at(A.at(i))++;
  }
  int max_ans=0;
  for(int i=0;i<100000;i++){
    int ans;
    if(i==0){
      ans=num.at(0)+num.at(1);
    }
    else if(i==99999){
      ans=num.at(99998)+num.at(99999);
    }
    else{
      ans=num.at(i-1)+num.at(i)+num.at(i+1);
    }
    max_ans=max(max_ans,ans);
  }
  cout << max_ans << endl;
}

Measured memory_bytes: 1024
/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-5-12 21:08:34
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

const int UFSIZE = 100010;
int union_find[UFSIZE];

void init()
{
  for (auto i = 0; i < UFSIZE; i++)
  {
    union_find[i] = i;
  }
}

int root(int a)
{
  if (a == union_find[a])
    return a;
  return (union_find[a] = root(union_find[a]));
}

bool issame(int a, int b)
{
  return root(a) == root(b);
}

void unite(int a, int b)
{
  union_find[root(a)] = root(b);
}

bool isroot(int a)
{
  return root(a) == a;
}

int N, M;
int p[100010];
int x[100010];
int y[100010];

int main()
{
  init();
  cin >> N >> M;
  for (auto i = 0; i < N; i++)
  {
    cin >> p[i];
    p[i]--;
  }
  for (auto i = 0; i < M; i++)
  {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }
  for (auto i = 0; i < M; i++)
  {
    unite(p[x[i]], p[y[i]]);
  }
  int ans = 0;
  for (auto i = 0; i < N; i++)
  {
    if (issame(i, p[i]))
    {
      ++ans;
    }
  }
  cout << ans << endl;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    
    int a, b;
    string s;
    stack<int> st;
    while(cin >> s) {
        if(s[0] == '+') {
            a = st.top(); st.pop();
            b = st.top(); st.pop();
            st.push(a + b);
        }
        else if(s[0] == '-') {
            a = st.top(); st.pop();
            b = st.top(); st.pop();
            st.push(b - a);
        }
        else if(s[0] == '*') {
            a = st.top(); st.pop();
            b = st.top(); st.pop();
            st.push(a * b);
        } else {
            st.push(atoi(s.c_str()));
        }
    }
    cout << st.top() << endl;

    return 0;
}


Measured memory_bytes: 3228
#include<iostream>
#include<vector>
using namespace std;
int q;
main()
{
	cin>>q;
	vector<int>a;
	for(int i=0;i<q;i++)
	{
		int c;cin>>c;
		if(c==0)
		{
			int x;cin>>x;
			a.push_back(x);
		}
		else if(c==1)
		{
			int p;cin>>p;
			cout<<a[p]<<endl;
		}
		else
		{
			a.pop_back();
		}
	}
}


Measured memory_bytes: 3912
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

template<typename CostType>
/// \brief 辺の情報
struct Edge{
  int      to;
  CostType cost;

  Edge(int t, CostType c): to(t), cost(c){
  }
};

template<typename CostType>
class Graph{

private:

  /// \brief adjacent_list_[n]=ノードnの隣接リストを表すvector<Edge>
  std::vector<std::vector<Edge<CostType>>> adjacent_list_;

public:

  /// \brief 頂点数
  const int NODE_SIZE_;

  /// \brief コンストラクタ
  /// \param node_size 頂点数
  explicit Graph(const int node_size): NODE_SIZE_(node_size),
                                       adjacent_list_(node_size){
  }

  /// \brief 有向グラフの辺を生やす
  /// \param from 辺の根本の頂点の番号
  /// \param to 辺の先の頂点の番号
  /// \param cost 辺のコスト
  void SetDirectedEdge(const int from, const int to, const CostType cost){
    adjacent_list_[from].push_back(Edge<CostType>(to, cost));
  }

  /// \brief 無向グラフの辺を生やす
  /// \param node_a 一方の頂点の番号
  /// \param node_b もう一方の頂点の番号
  /// \param cost 辺のコスト
  void
  SetUndirectedEdge(const int node_a, const int node_b, const CostType cost){
    SetDirectedEdge(node_a, node_b, cost);
    SetDirectedEdge(node_b, node_a, cost);
  }

  /// \brief ある頂点の隣接リストを取得
  /// \param node_num 頂点の番号
  /// \return 隣接リスト
  std::vector<Edge<CostType>> GetAdjacentList(int node_num) const{
    return adjacent_list_[node_num];
  }
};

void search(Graph<int>& graph, int curr, int prev, lint& result, int n){
  if(prev!=-1){
    lint a=prev;
    lint b=curr;
    if(a>b){
      swap(a,b);
    }

    lint tmp=a*(n-b+1);
    result-=tmp;
  }
  for(auto e:graph.GetAdjacentList(curr)){
    if(e.to==prev) continue;


    search(graph, e.to, curr, result, n);
  }
}


int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  lint n;
  cin>>n;
  Graph<int> graph(n+1);
  for(int i=0;i<n-1;i++){
    int u,v;
    cin>>u>>v;
    graph.SetUndirectedEdge(u,v,1);
  }

  lint result=0;
  for(lint l=1;l<=n;l++){
    result+=(n-l+1)*(n-l+2)/2;
  }

  search(graph, 1, -1, result, n);


  cout<<result<<endl;


}




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

int W, H, w, h;
vector<vector<int>> a, b, c;

template<typename F>
int reduce2D(int res, F func, int _w, int _h) {
	for (int i = 0; i < _h; ++i) for (int j = 0; j < _w; j++) res = func(i, j, res);
	return res;
}
template<typename F>
int reducePtn(int res, F func) {return reduce2D(res, func, w, h);}
template<typename F>
int reduceField(int res, F func) {return reduce2D(res, func, W - w + 1, H - h + 1);}

int main() {
	while (cin >> H >> W) {
		a = vector<vector<int>>(H, std::vector<int>(W));
		b = vector<vector<int>>(H, std::vector<int>(W));
		for (auto& v : a) for (auto& x : v) cin >> x;
		for (auto& v : b) for (auto& x : v) cin >> x;
		cin >> h >> w;
		c = vector<vector<int>>(h, std::vector<int>(w));
		for (auto& v : c) for (auto& x : v) cin >> x;

		bool flg = false;
		int res = reduceField(-1000000, [&flg](int i, int j, int u){
			if (reducePtn(1, [i, j](int y, int x, int u){return (b[i + y][j + x] == c[y][x]) && u;})) {
				u = max(u, reducePtn(0, [i, j](int y, int x, int u){return a[i + y][j + x] + u;}));
				flg = true;
			}
			return u;
		});
		if (flg) cout << res << endl;
		else cout << "NA" << endl;
	}
	return 0;
}


Measured memory_bytes: 1240
import java.util.*;
 class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		boolean[][] crd = new boolean[4][13];

		for(int i=0; i<n; i++){	
			String s = sc.next();
			int a = sc.nextInt() - 1;
			if (s.equals("S")) {
				crd[0][a] = true;
			}
			else if (s.equals("H")) {
				crd[1][a] = true;
			}
			else if (s.equals("C")) {
				crd[2][a] = true;
			}
			else if (s.equals("D")) {
				crd[3][a] = true;
			}
		}

		for(int w=0;w<4;w++){
			for(int j=0; j<13;j++){
				if(crd[w][j] == false){
					if(w==0){
						System.out.println("S" + " " + (j+1));
					} else if(w==1){
						System.out.println("H" + " " + (j+1));
					} else if(w==2){
						System.out.println("C" + " " + (j+1));
					} else {
						System.out.println("D" + " " + (j+1));
					}
				}
			}
		}

	}
}


Measured memory_bytes: 26216
#include<iostream>
using namespace std;
typedef long long ll;

int digitSum(ll x){
    int ret = 0;
    while(x > 0){
        ret += x%10;
        x /= 10;
    }
    return ret;
}

int main(){
    int a, n, m;
    cin >> a >> n >> m;

    int ans = 0;
    for(int i = 1;;i++){
        ll tmp = 1;
        for(int j = 0; j < n; j++){
            tmp *= (i+a);
        }
        if(tmp > m) break;
        if(digitSum(tmp) == i)  ans++;
    }

    cout << ans << endl;

    return 0;
}






Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n, k, q;
    cin >> n >> k >> q;

    vector<int64_t> s(n + 1, 0);
    for (auto _ : irange(0L, q)) {
        int64_t a;
        cin >> a;

        ++s[a];
    }

    for (auto i : irange(1L, n + 1)) {
        auto score = k - q + s[i];
        if (score <= 0) {
            cout << "No\n";
        } else {
            cout << "Yes\n";
        }
    }
}

Measured memory_bytes: 1408
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxs=1<<15|1;
int n,m,f[maxs][16],p[maxs],d[16][16],v[maxs],ans;
int U;
int main(){
	scanf("%d%d",&n,&m);U=(1<<n)-1;
	for(int i=1,x,y,z;i<=m;i++)scanf("%d%d%d",&x,&y,&z),d[x][y]=d[y][x]=z;
	for(int i=1;i<=n;i++)v[1<<i-1]=i;
	for(int s=1;s<=U;s++){
		int t=v[s&-s];
		p[s]=p[s-(1<<t-1)];
		for(int i=t+1;i<=n;i++)
			if(s&(1<<i-1))p[s]+=d[t][i];
	}
	ans=-0x3f3f3f3f;for(int s=0;s<=U;s++)for(int i=0;i<=n;i++)f[s][i]=ans;f[1][1]=0;
	for(int s=1;s<=U;s++){
		for(int i=1;i<=n;i++){
			for(int s0=s;s0;s0=(s0-1)&s)
				if(s0&(1<<i-1))f[s][i]=max(f[s][i],f[(s-s0)|(1<<i-1)][i]+p[s0]);
			for(int j=1;j<=n;j++)
				if(!(s&(1<<j-1))&&d[i][j])
					f[s|(1<<j-1)][j]=max(f[s|(1<<j-1)][j],f[s][i]+d[i][j]);
		}
		if(s&(1<<n-1))ans=max(ans,f[s][n]);
	}
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)ans-=d[i][j];
	printf("%d\n",-ans);
    return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        if(i%3==0 || i%5==0)
        {
            continue;
        }
        else
        {
            sum+=i;
        }
    }
    cout<<sum;
    return 0;
}



Measured memory_bytes: 3648
def partition(a,p,r)->int:
    x = a[r][1]
    i = p-1
    for j in range(p,r):
        if a[j][1]<=x:
            i+=1
            a[i],a[j] = a[j],a[i]
    a[i+1],a[r] = a[r],a[i+1]
    return i+1

def quick_sort(a,l,r):
    if l<r:
        q = partition(a,l,r)
        quick_sort(a,l,q-1)
        quick_sort(a,q+1,r)

def check(a):
    for i in range(len(a)):
        j = i+1
        while j<len(a) and a[i][1]==a[j][1]:
            if a[j][2]<a[i][2]:return 'Not stable'
            j+=1
    return 'Stable'

def main():
    n = int(input())
    a = []
    for i in range(n):
        b,c = input().split()
        a.append([b,int(c),i])
    quick_sort(a,0,n-1)
    print (check(a))
    for b,c,_ in a:print (b,c)

if __name__ == '__main__':
    main()




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

int main(){
  ll N,ans=0;
  cin>>N;
  map<ll,ll> m;
  for(ll i=0;i<N;i++){
    ll a;
    cin>>a;
    m[a]++;
  }
  for(auto a:m){
    if(a.first>a.second) ans+=a.second;
    else ans+=a.second-a.first;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6272
#include<stdio.h>
int main(){
	int a,b,c,d,result;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a<=b){
		if(c<=d){
            result=a+c;
    	}
    	else result=a+d;
    }
    else if(c<=d){
        result=b+c;
    }else result=b+d;
    printf("%d",result);
    return 0;
}


Measured memory_bytes: 128
//  RAKSHIT KADAM

 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 3
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
#warning check the size of arrays!!!
// NUMERIC DEFINITIONS :
    #define INF 1000000000000000005
    #define inf 1000000004
    #define MOD  1000000007
    #define mod 998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
#define ld long double
 #define ll long long
 #define int long long
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll ter; cin>> ter; while(ter--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>
 
 #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
 #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
 
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}

int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m;}
ll modInverse(int a, int m){{ return power(a, m-2, m);}}
const int maxn = 500003;
//ll fact[1000005];
//ll modIN[1000005];
//void facto()
//{
//    ll lim =1000005;fact[0]=1;
//    for(ll i=1;i<lim;i++)
//    {
//        fact[i]=(fact[i-1]*i)%MOD;
//    }
//    modIN[n]=modInverse(fact[n],MOD);
//    for(ll i=n-1;i>=1;i--)
//    {
//        modIN[i] = (modIN[i+1]*(i+1))%MOD;
//    }
//}
//ll ncr(ll a,ll b)
//{
//    ll ret = 0;
//    ret = fact[a]*(modIN[b]);
//    ret%=MOD;
//    ret*=modIN[a-b];
//    ret%=MOD;
//    return ret;
//}

void solve()
{
    ll n;cin>>n;
    ll dp[n+1];
    memset(dp,0,sizeof dp);
    dp[0]=1;

    for(ll i=3;i<=n;i++)
    {
        for(ll j=i-3;j>=0;j--)
        {
            dp[i]+=dp[j];
            dp[i]%=MOD;
        }
    }
    cout<<dp[n]<<endl;
}
signed main(){
   Need_for_speed(activated);
//
//    satisfy
//    {
// solve();
//    }
    
  
    solve();

    
    
    return 0;
}


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

int main() {
    int n, m; cin >> n >> m;    // n:SW、m:電球
    vector<vector<int>> s(m, vector<int>(n));
    rep(i, m) {
        int k; cin >> k;
        s[i].resize(k);
        rep(j, k) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    vector<int> p(m);
    rep(i, m) {
        cin >> p[i];
    }

    int ans = 0;
    for (int tmp = 0; tmp < (1 << n); tmp++) { // スイッチをbit全探索
        bitset<10> b(tmp);
        vector<int> m_sum(m);
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < s[i].size(); j++) {
                if (b.test(s[i][j]) == 1) {
                    m_sum[i]++;
                }
            }
        }
        bool is_all_on = true; 
        for (int i = 0; i < m; i++) {
            //printf("m_sum[%d]==%d\n", i, m_sum[i]);
            if ((m_sum[i] % 2) != p[i]) {
                is_all_on = false;
            }
        }
        if (is_all_on) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(int& a){printf("%d",a);}
//void print(long long& a){printf("%lld",a);}
void print(double& a){printf("%.15lf",a);}
template<class T> void print(T& a){cout<<a;}
template<class T> void print(vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(Head& head, Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(T& a){cerr<<a;}
template<class T> void dprint(vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(Head& head, Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int n;
    in(n);
    ll ans=100000;
    rep(i,n){
        ans=ans*1.05;
        if(ans%1000!=0)ans+=1000-ans%1000;
    }
    out(ans);
}


Measured memory_bytes: 3196
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;

public class Hello
{

    public static void Main()
    {
        int[] n = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        int count = 0;
        int z = 0;
        for (int x = 0; x <= n[0]; x++) {
            for (int y = 0; y <= n[0]; y++) {
                z = n[1] - x - y;
                if (0 <= z && z <= n[0]) {
                    count++;
                }
            }
        }
        Console.WriteLine(count);
    }

}



public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int Cin()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }

}


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

int main()
{
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
    }

    vector<int> arrived(n, -1);
    int next;
    int roop_start, roop_end;

    if (k > n) {
        rep(i,n) {
            if (i==0) {
                // 町1にいる
                arrived[0] = 0;
                next = a[0];
            } else {
                if (arrived[next-1] == -1) {
                    // 町a[next]にいる
                    arrived[next-1] = i;
                    next = a[next-1];
                    //cout << "im not arrived" << endl;
                } else {
                    roop_end = i;
                    //cout << "im arrived" << endl;
                    break;
                }
            }
        }
        roop_start = arrived[next-1];
        //cout << "start" << roop_start << endl;
        //cout << "end" << roop_end << endl;
        int roop_size = roop_end - roop_start;
        //cout << "size" << roop_size << endl;
        int des;
        if ((k+1-roop_start)%roop_size != 0) {
            des = roop_start + (k+1-roop_start)%roop_size - 1;
        } else {
            des = roop_start + (k+1-roop_start)%roop_size + roop_size - 1;
        }
        //cout << "des" << des << endl;
        rep(i,n) {
            if (arrived[i] == des) {
                cout << i+1 << endl;
                break;
            }
        }
    } else {
        rep(i,k) {
            if (i==0) {
                next = a[0];
            } else {
                next = a[next-1];
            }
        }
        cout << next << endl;
    } 

    return 0;
}

Measured memory_bytes: 4828
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

vvll edges;
V<bool> used;
vll d;

ll dfs(ll i) {
    if (used[i]) return d[i];
    else {
        used[i] = true;
        ll ret = 0;
        for (auto v: edges[i]) chmax(ret, dfs(v)+1);
        return d[i] = ret;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    edges.resize(1001000);
    used.resize(1001000);
    d.resize(1001000, 1);
    vll h(1001000, 0);
    REP(i, n) {
        ll pa; cin >> pa; pa--;
        REP(j, n-2) {
            ll tmpa; cin >> tmpa; tmpa--;
            ll pas = tmpa;
            ll tmpi=i, pi=i;
            if (tmpa > tmpi) swap(tmpa, tmpi);
            if (pa > pi) swap(pa, pi);
            edges[1000*pi+pa].push_back(1000*tmpi+tmpa);
            h[1000*tmpi+tmpa]++;
            pa = pas;
        }
    }

    stack<ll> st;
    REP(i, 1001000) if (edges[i].size() > 0 && h[i] == 0) st.push(i);
    ll ans = 0;
    while (st.size()) {
        ll u = st.top(); st.pop();
        for (ll v: edges[u]) {
            h[v]--;
            if (h[v] == 0) st.push(v);
        }
        ans++;
    }

    if (ans != n*(n-1)/2) cout << -1 << '\n';
    else {
        ll ret=0;
        REP(i, 1001000) chmax(ret, dfs(i));
        cout << ret+1 << '\n';
    }
    return 0;
}


Measured memory_bytes: 55168
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		prepareFact();
		int num = sc.nextInt();
		int color = sc.nextInt();
		ArrayList<ArrayList<Integer>> connect = new ArrayList<>();
		for(int i = 0; i < num; i ++) {
			connect.add(new ArrayList<Integer>());
		}
		for(int i = 0; i < num - 1; i ++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			connect.get(a).add(b);
			connect.get(b).add(a);
		}
		if(num == 1) {
			System.out.println(color);
			return;
		}
		if(num == 2) {
			System.out.println(mod(color * (color - 1)));
			return;
		}
		if(color == 1) {
			System.out.println(0);
			return;
		}
		if(color == 2) {
			System.out.println(0);
			return;
		}

		long ans = color;
		boolean visited[] = new boolean[num];
		visited[0] = true;
		Deque<Integer> stack = new ArrayDeque<Integer>();
		for(int i = 0; i < connect.get(0).size(); i ++) {
			int crt = connect.get(0).get(i);
			stack.addLast(crt);
			visited[crt] = true;
		}
		ans = mod(ans * permuMod(color - 1, connect.get(0).size()));
		while(!stack.isEmpty()) {
			int root = stack.removeFirst();
			int count = 0;
			for(int i = 0; i < connect.get(root).size(); i ++) {
				int crt = connect.get(root).get(i);
				if(visited[crt]) { continue; }
				stack.addLast(crt);
				visited[crt] = true;
				count ++;
			}
			ans = mod(ans * permuMod(color - 2, count));
		}

		System.out.println(mod(ans));
	}

	static long MOD = (long)Math.pow(10, 9) + 7;
	public static long mod(long i) {
		return i % MOD + ((i % MOD) < 0 ? MOD : 0);
	}
	
	static long powerMod(long x, long y) {
		if (y == 0) {
			return 1;
		} else if (y == 1) {
			return x;
		} else if (y % 2 == 0) {
			long tmp = powerMod(x, y / 2);
			return mod(tmp * tmp);
		} else {
			long tmp = powerMod(x, y / 2);
			return mod(mod(tmp * tmp) * x);
		}
	}
	
	static long invMod(long x) {
		return powerMod(x, MOD - 2);
	}
	
	static int MAX_FACT = 200_100;
	static long factMod[] = new long[MAX_FACT];
	static void prepareFact() {
		factMod[0] = 1;
		for(int i = 1; i < MAX_FACT; i ++) {
			factMod[i] = mod(factMod[i - 1] * i);
		}
	}
	
	static long combiMod(int n, int r) {
		if(n < 0 || n < r) { return 0; }
		if(r == 0 || r == n) { return 1; }
		return mod(mod(factMod[n] * invMod(factMod[r])) * invMod(factMod[n - r]));
	}

	static long permuMod(int n, int r) {
		if(n < 0 || n < r) { return 0; }
		if(r == 0) { return 1; }
		return mod(factMod[n] * invMod(factMod[n - r]));
	}
}

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

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


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

const int MAX_N = 212345;

int A[MAX_N];
bool possible(const int K, const int N) {

  if (K == 1) {
    for (int i = 1; i < N; i++) {
      if (A[i-1] >= A[i]) return false;
    }
    return true;
  }

  map<int, int> S;
  for (int i = 1; i < N; i++) {
    const int x = A[i-1];
    const int y = A[i];
    if (x >= y) {

      auto it = S.upper_bound(y);
      S.erase(it, S.end());

      int j = y;
      for (; j >= 1; j--) {
        ++S[j];
        if (S[j] == K) {
          S.erase(j);
        } else {
          break;
        }
      }
      if (j == 0) return false;
    }
  }
  return true;
}

int main2() {
  int N = nextInt();
  REP(i, N) A[i] = nextInt();

  int hi = N;
  int lo = 0;
  while (hi - lo > 1) {
    int K = (hi + lo) / 2;
    if (possible(K, N)) hi = K; else lo = K;
  }
  cout << hi << endl;
  return 0;
}

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

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int tab[101][101];
int w , h;
int x = 1  , y = 1;
void next(){
if( x % 2 == 1){
    if( y == w)
        x++;
    else
        y++;
    }else{
    if(y == 1)
        x++;
    else
        y--;
    }
}
int main() {
cin >> w >> h;
int n;
int a;
cin >> n;
for(int i = 1 ; i <= n ; i++){
    cin >> a;
    for(int j = 1 ; j <= a ; j++){
        tab[x][y] = i;
        next();
    }
}
for(int i = 1 ; i <= w ; i++){
    for(int j = 1; j <= h ; j++){
        cout << tab[j][i] << " ";
    }
    cout << endl;
}
}


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

double eps = 1e-10;

class Point {
public:
	double x, y;
	
	Point(double x = 0, double y = 0) : x(x), y(y) {}
	
	Point operator + (const Point& p) {
		return Point(x + p.x, y + p.y);
	}
	Point operator - (const Point& p) {
		return Point(x - p.x, y - p.y);
	}
	Point operator * (const double& a) {
		return Point(x * a, y * a);
	}
	Point operator / (const double& a) {
		return Point(x / a, y / a);
	}
	
	bool operator < (const Point& p) const {
		return x != p.x ? x < p.x : y < p.y;
	}
	bool operator == (const Point& p) const {
		return fabs(x - p.x) < eps && fabs(y - p.y) < eps;
	}
	
	double abs() {
		return sqrt(norm());
	}
	double norm() {
		return x * x + y * y;
	}
	
};

typedef Point Vector;

// ????????????
bool equals(const double& a, const double& b) {
	return fabs(a - b) < eps;
}

// ??????
double dot(const Vector& a, const Vector& b){
	return a.x * b.x + a.y * b.y;	
}

// ??´?????????(????????????)
bool isOrthogonal(Vector a, Vector b){
	return equals(dot(a, b), 0.0);
}

// ??´?????????(???4???)
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2){
	return isOrthogonal(a1 - a2, b1 - b2);
}

int main() {
	double x1, x2, x3, x4, y1, y2, y3, y4;
	while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4){
		Point p1 = Point(x1, y1); Point p2 = Point(x2, y2);
		Point p3 = Point(x1, y2); 
		Point p4 = Point(x3, y3); Point p5 = Point(x4, y4);
		Point p6 = Point(x3, y4);
        if(p6.x <= p2.x &&  p3.x <= p5.x && p6.y >= p1.y && p4.y <= p3.y){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1228
# include<iostream>
using namespace std;
long long A[200000];
int k =0;
long long B[1000];
int N;
int M;
void dfs(int i)
{
	  if(i>=N-1)
	  {
	  	    long long num=0;
	  	    for(int l=0;l<N-1;l++)
	  	    {
	  	    	 num+=B[l];
	  	    	 num*=10;
			  }
	  	
	  	  	for(int j=max((long long)0,B[i-1]-1);j<=min(B[i-1]+1,(long long)9);j++)
	  	   {
	  	   	 
	  	   	   
	  	   	   	k++;
	  	   	  
	  	   	   if(k==M)
	  	   	   {
	  	   	   	   cout<<num+j<<endl;
	  	   	   	   return;
					}
				else if(k>M)
				{
					return;
					}	
				
		   }
		   return ;	 
	  }
	  
	  if(i==0)
	  {
	  	  for(int j=1;j<10;j++)
	  	  {
	  	     B[i] = j;
			 dfs(i+1);	
		  }
	  }
	  else
	  {
	  	   for(int j=max((long long)0,B[i-1]-1);j<=min(B[i-1]+1,(long long)9);j++)
	  	   {
	  	   	   B[i] = j;
	  	   	   dfs(i+1);
		   }
	  }
}

int main ()
{
	cin>>M;
	for(int i=1;i<=9;i++)
	{
		A[i] =i;
	}
	k= 9;
	if(M<=9)
	{
		cout<<A[M]<<endl;
	}
    for(int i=2;i<=11;i++)
    {
    	N= i;
    	dfs(0);
	}

	
}

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

using namespace std;

int main()
{
    string s;
    cin>>s;
    int sum = 0;
    for (char c : s) sum += (int) (c - '0');
    if (sum % 9) cout << "No" << '\n';
    else cout << "Yes" << '\n';
    return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
vector <int> x(10000);
int main() {
    int N , M;
    cin >> N >> M;
    ll ans = 1;
    if(N == M + 1 || N + 1 == M){
        for(int i = N; i >= 1; i--){
            ans*=i;
            if(ans >= 1000000007){
                ans = ans % 1000000007;
            }
        }
        for(int i = M; i >= 1; i--){
            ans*=i;
            if(ans >= 1000000007){
                ans = ans % 1000000007;
            }
        }
        cout << ans << endl;
    }
    else if(N == M){
        for(int i = N; i >= 1; i--){
            ans*=i;
            if(ans >= 1000000007){
                ans = ans % 1000000007;
            }
        }
        for(int i = M; i >= 1; i--){
            ans*=i;
            if(ans >= 1000000007){
                ans = ans % 1000000007;
            }
        }
        cout << ans * 2 % 1000000007 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3640
A,B = map(int,input().split())
S = input()

sliceA = S[0:A]
sliceB = S[A+1:A+B+1]

if sliceA.isdigit() and sliceB.isdigit() and S.find("-") == A and len(sliceA) == A and len(sliceB) == B:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
import sys
read = sys.stdin.buffer.read
s = read().decode("utf-8")
H = s[:(len(s) - 1) // 2]
B = s[(len(s) - 1) // 2 + 1:-1]

if s[:-1] == s[:-1][::-1] and H == H[::-1] and B == B[::-1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9120
class UnionFind():
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n

    def root(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.par[x] = y
            else:
                self.par[y] = x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    def samegrp(self, x, y):
        return self.root(x) == self.root(y)

n, m = [int(x) for x in input().split()]
A = UnionFind(n)
ans = n
for i in range(m):
    x, y, _ = [int(z) - 1 for z in input().split()]
    if not A.samegrp(x, y):
        ans -=1
    A.union(x, y)

print(ans)


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

using namespace std;

using u128 = __uint128_t;

#define int long long
#define mod 1000000007

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    char x;
    cin>>x;
    cout<<((char) (x+1))<<endl;
}

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

#define ALPH 26

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

  string p;
  int SakumonBox[ALPH] = {};
  for(int i = 0; i < n; i++){
    cin >> p;
    SakumonBox[p[0] - 'A']++;
  }

  // 頭文字ごとに、問題数が多い順に詰める
  priority_queue<int> SakumonQueue;
  for(int i = 0; i < ALPH; i++)
    if(SakumonBox[i] > 0)
      SakumonQueue.push(SakumonBox[i]);

  // 永遠にKUPCを開催し続けたい
  for(int cnt = 0; ; ++cnt){
    // k問作れなくなったら出力して終了
    if((int)SakumonQueue.size() < k){
      cout << cnt << endl;
      break;
    }

    // 上からk問取り出して、詰め直す
    vector<int> tmp;
    for(int i = 0; i < k; i++){
      tmp.push_back(SakumonQueue.top());
      SakumonQueue.pop();
    }
    for(int i = 0; i < k; i++)
      if(--tmp[i] > 0)
        SakumonQueue.push(tmp[i]);
  }

  return 0;
}


Measured memory_bytes: 384
#include<cstdio>

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

using namespace std;

void riffle(int n,int c[],int p){
	int a[50],b[50];
	for(int i=0,ia=0,ib=0;i<n;i++){
		if(i<n/2)	b[ib++]=c[i];
		else		a[ia++]=c[i];
	}
	for(int i=0,ia=0,ib=0;i<n;i++){
		if((i/p)%2==0 && ia<(n+1)/2)	c[i]=a[ia++];
		else							c[i]=b[ib++];
	}
}

int main(){
	for(int n,r;~scanf("%d%d",&n,&r);){
		int c[50];
		rep(i,n)	c[i]=i;
		rep(i,r){
			int p;	scanf("%d",&p);
			riffle(n,c,p);
		}
		printf("%d\n",c[n-1]);
	}

	return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
	Scanner sc;
	void run() { 
		sc = new Scanner(System.in);
		int n= sc.nextInt();
		for (int i=0;i<n;i++) {
			String str1 = sc.next();
			String str2 = sc.next();
			int num = str2Num(str1) + str2Num(str2);
			System.out.println(num2Str(num));
		}
	}
	
	int str2Num(String str) {
		int num=0;
		int tmp=1;
		for (int i=0;i<str.length();i++) {
			String a = "" + str.charAt(i);			
			if (a.compareTo("m")==0) {
				num += tmp * 1000;
				tmp = 1;
			}else if (a.compareTo("c")==0) {
				num += tmp * 100;
				tmp = 1;
			}else if (a.compareTo("x")==0) {
				num += tmp * 10;
				tmp = 1;
			}else if (a.compareTo("i")==0){
				num += tmp;
				tmp = 1;
			}else {
				tmp = Integer.parseInt(a);
			}
		}
		return num;
	}
	
	int[] ku = {1000,100,10,1};
	char[] c = {'m','c','x','i'};
	String num2Str(int num) {
		String str = "";
		for (int i=0;i<4;i++) {
			if (num / ku[i] > 0) {
				int tmp = num/ku[i];
				num = num - tmp*ku[i];
				if (tmp != 1) str += tmp;
				str += c[i];
			}
		}
		return str;
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

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

int main() {
    int a = ri();
    int b = ri();
    int res = 0;
    FROMTO(i,a,b) {
        char s[10];
        snprintf(s, 10, "%d", (int)i);
        string ss(s);
        string sss(ss);
        reverse(ss.begin(), ss.end());
        if (ss == sss) res++;
    }
    cout << res << endl;
 return 0;
}


Measured memory_bytes: 256
#include<cstdio>

int n;

int binarysearch(int *A,int key){
  int left=0,right=n,mid;
  while(left<right){
    mid = (right+left)/2;
    
    if(key==A[mid]){
      return 1;
    }else if(key<A[mid]){
      right = mid;
    }else if(key>A[mid]){
      left = mid+1;
    }
  }
  return 0;
}

int main() {
  int A[100000];
  
  scanf("%d",&n);
  
  
  for(int i=0;i<n;i++){
    scanf("%d",A+i);
  }
  
  int q;
  scanf("%d",&q);
  
  int key,sum=0;
  for(int i=0;i<q;i++){
    scanf("%d",&key);
    if(binarysearch(A,key)){
      sum++;
    }
  }
  
  printf("%d\n",sum);
  
  return 0;
}

Measured memory_bytes: 3068
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <queue>
using namespace std;
const int MOD = 1e9+7;
const int N = 1e5+1;
int m[N], n, re, dp[N][13];

inline void add(int &a, int b) {a+=b; a=a>MOD?a-MOD:(a<0?a+MOD:a);}

int solve(){
	dp[0][0] = 1;
	for(int i=1;i<=n;++i){
		for(int j=0;j<13;++j){
			for(int k=0;k<10;++k){
				add(dp[i][(k*m[i-1]+j)%13], dp[i-1][j]);
			}
		}
	}
	return dp[n][re];
}

int main(){
	string s;
	cin >> s;
	int x = 1;
	re = 5;
	for(int i=s.size()-1;i>=0;--i){
		if(s[i]=='?'){
			m[n++] = x;
		}
		else{
			re -= (s[i]-'0') * x % 13;
			if(re<0) re += 13;
		}
		x = x*10 % 13;
	}
	printf("%d\n", solve());
    return 0;
}


Measured memory_bytes: 5888