akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;

const ll INF = 5e15;
const ll MOD = 1e9 + 7;

ll N, M;
vector<vector<ll>> edges(1e5 + 10);
vector<ll> dp(1e5 * 2 + 10);
map<P, ll> ID;

ll dfs1(ll now, ll pre){
    ll ret = 1;
    for(ll nxt : edges[now]){
        if(nxt == pre) continue;
        ret *= (dfs1(nxt, now) + 1);
        ret %= M;
    }
    return dp[ID[P(pre, now)]] = ret;
}

void dfs2(ll now, ll pre){
    ll ret = 1;
    vector<ll> multi(edges[now].size() + 1, 1);
    vector<ll> multir(edges[now].size() + 1, 1);
    for(ll i = 0; i < edges[now].size(); i++){
        ll nxt = edges[now][i];
        ll id = ID[P(now, nxt)];
        multi[i + 1] = multi[i] * (dp[id] + 1) % M;
    }
    for(ll i = edges[now].size(); i > 0; i--){
        ll nxt = edges[now][i - 1];
        ll id = ID[P(now, nxt)];
        multir[i - 1] = multir[i] * (dp[id] + 1) % M;
    }
    for(ll i = 0; i < edges[now].size(); i++){
        ll nxt = edges[now][i];
        if(nxt == pre) continue;
        ll id = ID[P(nxt, now)];
        dp[id] = multi[i] * multir[i + 1] % M;
    }
    for(ll nxt : edges[now]) if(nxt != pre) dfs2(nxt, now);
}

void dfs(){
    for(ll nxt : edges[0]) dfs1(nxt, 0);
    dfs2(0, -1);
}

int main(){
    cin >> N >> M;
    for(ll i = 0; i < N - 1; i++){
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        edges[x].push_back(y);
        edges[y].push_back(x);
        ID[P(x, y)] = 2 * i;
        ID[P(y, x)] = 2 * i + 1;
    }
    dfs();
    for(ll i = 0; i < N; i++){
        ll ans = 1;
        for(ll nxt : edges[i]) (ans *= dp[ID[P(i, nxt)]] + 1) %= M;
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 37888
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	
	public static void Main(string[] args)
	{
		var s = Console.ReadLine();
		var res = new int[s.Length+1];

		
		int begin = 0;
		for(;begin <s.Length;)
		{
			int i = begin;
			for(; i < s.Length-1; i++)
			{
				if(s[i] != s[i+1])
				{
					break;
				}
			}
			//Console.WriteLine("{0}-{1}", begin, i);
			int cnt = i - begin + 1;
			if(s[begin] == '<')
			{
				int o = 1;
				for(int k = begin+1; k <= i+1; k++)
				{
					res[k] = Math.Max(o, res[k]);
					o++;
				}
			}
			else
			{
				int o = 1;
				for(int k = i; k >= begin && k >= 0; k--)
				{
					res[k] = Math.Max(o, res[k]);
					o++;
				}
			}
			begin = i+1;
		}
		long wa = 0;
		
		foreach(var t in res)
		{
			//Console.Write("{0} ", t);
			wa+=t;
		}
		/*
		Console.WriteLine();
		
		foreach(var t in s)
		{
			Console.Write(" {0}", t);
		}
		Console.WriteLine();
		*/
		Console.WriteLine(wa);
	}
	

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}



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

int main(){
  char grid[3][3];
  while(cin >> grid[0][0]){
    if(grid[0][0] == '0')break;
    for(int i = 0 ; i < 3 ; i++ ){
      for(int j = 0 ; j < 3 ; j++ ){
	if(i == 0 && j == 0)continue;
	cin >> grid[j][i];
      }
    }
    char c[2] = {'b','w'},ans = 'S';
    for(int k = 0 ; k < 2 ; k++ ){

      for(int i = 0 ; i < 3 ; i++ ){
	if(grid[i][0] == c[k] &&
	   grid[i][1] == c[k] &&
	   grid[i][2] == c[k] )ans = c[k]; 

	if(grid[0][i] == c[k] &&
	   grid[1][i] == c[k] &&
	   grid[2][i] == c[k] )ans = c[k]; 
      }
      if(ans != 'S')break;
      if(grid[0][0] == c[k] && 
	 grid[1][1] == c[k] && 
	 grid[2][2] == c[k]  )ans = c[k];

      if(grid[0][2] == c[k] && 
	 grid[1][1] == c[k] && 
	 grid[2][0] == c[k]  )ans = c[k];
      if(ans != 'S')break;
    }
    if(ans == 'S')cout << "NA" << endl;
    else cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1132
#include <iostream>
using namespace std;
int ball[10];

bool dfs(int,int,int);

int main(){
	int n;
	cin>>n;
	for (int i = 0; i < n; i++) {
		for (int& j : ball) cin>>j;
		if(dfs(0,0,0))puts("YES");
		else puts("NO");
	}
	return 0;
}

bool dfs(int b,int c,int m){
	if(m == 9)return (b<ball[m] || c<ball[m]) ? true : false;
	bool res = false;
	if(b<ball[m])res = max(res,dfs(ball[m],c,m+1));
	if(c<ball[m])res = max(res,dfs(b,ball[m],m+1));
	return res;
}

Measured memory_bytes: 1112
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n >> m;
	int a[60], b[60], c[60], d[60];
	rep(i, n) cin >> a[i] >> b[i];
	rep(i, m) cin >> c[i] >> d[i];

	int ch[60];

	rep(i, n){
		int ans = 1e9;
		rep(j, m){
			if(ans > abs(a[i] - c[j]) + abs(b[i] - d[j])){
				ans = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				ch[i] = j+1;
			}	
		}
	}

	rep(i, n){
		cout << ch[i] << endl;
	}
}

Measured memory_bytes: 256
n, m, q = map(int, input().split())
a, b, c, d = [], [], [], []
for i in range(q):
    ai, bi, ci, di = map(int, input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)
    d.append(di)

def dfs(A):
    if len(A) == n:  # 数列が完成している場合
        score = 0
        for i in range(q):
            if A[b[i]-1] - A[a[i]-1] == c[i]:
                score += d[i]
        return score

    ans = 0
    for i in range(A[-1], m+1):
        A.append(i)
        ans = max(ans, dfs(A))
        A.pop()
    return ans

print(dfs([1]))


Measured memory_bytes: 9152
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
	 String a = sc.nextLine();
     int count = 0;
      
		// スペース区切りの整数の入力
		for(int i = 0; i < 4; i++){
            String tmp = a.substring(i,i+1);
            if(tmp.equals("+")){
                count++;
            }else{
                count--;
            }
        }
		System.out.println(count);
    }
}

Measured memory_bytes: 21844
// abc165_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int K;
    cin >> K;
    int A, B;
    cin >> A >> B;

    REPN(n, A, B+1){
        if (n % K == 0){
            print("OK");
            return 0;
        }
    }

    print("NG");

    return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 22;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

struct TeamResult {
  int teamnumber;
  int num, time, ptime;
  vi penalty;

  TeamResult() {

  }

  void init(int p, int t) {
    penalty.resize(p, 0);
    teamnumber = t;
    num = 0;
    time = 0;
    ptime = 0;
  }

  void update(int m, int p, int j) {
    if(j == 0) {
      num++;
      time += m + penalty[p] * 20;
    } else {
      penalty[p]++;
    }
  }
};


bool operator>(const TeamResult &t1, const TeamResult &t2) {
  if(t1.num == t2.num) {
    if(t1.time == t2.time) {
      return t1.teamnumber > t2.teamnumber;
    } else {
      return t1.time < t2.time;
    }
  } else {
    return t1.num > t2.num;
  }
}

bool operator==(const TeamResult &t1, const TeamResult &t2) {
  return (t1.num == t2.num && t1.time == t2.time);
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int m, t, p, r; cin >> m >> t >> p >> r;
    if(m == 0 && t == 0 && p == 0 && r == 0) break;
    vector<TeamResult> team(t);
    REP(i, t) {
      team[i].init(p, i);
    }

    REP(i, r) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      team[t-1].update(m, p-1, j);
    }

    sort(ALL(team), greater<TeamResult>());

    cout << team[0].teamnumber + 1;
    FOR(i, 1, t) {
      if(team[i] == team[i-1]) cout << "=";
      else cout << ",";
      cout << team[i].teamnumber + 1;
    }
    cout << endl;
  }
}



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

const int mod = 1e5;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	for (int i = 1; i < n; i++) {
		cin >> a[i]; a[i] += a[i - 1];
	}
	int p = 0, res = 0;
	while (m--) {
		int x;
		cin >> x;
		res = (res + abs(a[p + x] - a[p])) % mod;
		p += x;
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<vector>

int main () {
    int n;
    std::cin >> n;
    std::vector<int> x(n);
    long long sum = 0;
    for (int i = 0; i < n; i++)
    {
        std::cin >> x[i];
        sum += x[i];
    }
    float ave = 1.0*sum / n;
    int mid;
    if (ave >= int(ave) + 0.5)
    {
        mid = (int)ave + 1;
    } else {
        mid = int(ave);
    }

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += (x[i] - mid) * (x[i] - mid);
    }

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

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Applicative((<$>))
import Control.Monad
import qualified Data.Map as M
-- import qualified Data.Char as C
import qualified Data.List as L
-- import qualified Data.IntSet as I
-- import Debug.Trace
--------------------------------------------
readInt    = read :: String -> Int
readFloat  = read :: String -> Float
getInt     = readInt <$> getLine
getIntList = map readInt . words <$> getLine
int2bin 0 =  []
int2bin n =  n `mod` 2 : int2bin (n `div` 2)
----------------------------------------------

main :: IO ()
main = do
  s <- getLine
  let !ans = filter (\c -> not (any (c ==) s)) ['a'..'z']
  putStrLn $ if ans == [] then "None" else [head ans]


Measured memory_bytes: 7164
use proconio::input;

fn main() {
  input! {
    n: usize,
    ais: [isize;n]
  }
  
  let mut sum = 0;
  let mut max = ais[0];
  for v in ais {
    if max > v {
      sum += max - v;
    }
    max = std::cmp::max(max, v);  
  }
  println!("{}", sum);
}

Measured memory_bytes: 5572
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve()
}

func resolve() {
	n, k := scanInt(sc), scanInt(sc)
	rate := 0.0
	for i := 1; i <= n; i++ {
		rate += pWin(i, k)
	}
	rate /= float64(n)
	fmt.Printf("%.10f\n", rate)
}

func pWin(n, k int) float64 {
	cur := n
	rate := 1.0
	for cur < k {
		cur <<= 1
		rate /= 2.0
	}
	return rate
}
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1776
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main(){

  int k;
  cin >> k;

  if( (k % 2) == 0){
    cout << (k / 2) * (k / 2) << endl;
  }
  else {
    cout << ((k + 1) / 2) * (((k + 1) / 2) - 1) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
H,W,k = map(int, input().split())
cell = [input() for i in range(H)]

cnt = 0

for h in range(1 << H):
    for w in range(1 << W):
        black = 0

        for i in range(H):
            if (h >> i) % 2 == 1:
                continue
            for j in range(W):
                if (w >> j) % 2 == 1:
                    continue

                black += cell[i][j] == '#'
        
        cnt += black == k

print(cnt)
            

    


Measured memory_bytes: 9084
#include<iostream>
using namespace std;
int main() {
  long long n, a, b, c;
  cin >> n >> a >> b;
  c = a + b;
  if (a == 0) {
    cout << 0;
  } else if (b == 0) {
    cout << n;
  } else {
    cout << n / c * a + min(n % c, a);
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int peri,houses;
    cin>>peri>>houses;
    int a[houses],dist[houses],prev,first,max=0,sum=0;
    for(int i=0;i<houses;i++)
    {
        cin>>a[i];
        if(i==0)
        {
            first=a[i];
        }
        if(i>0)
        {
            dist[i-1]=a[i]-prev;
            //cout<<dist[i-1]<<endl;
        }
        prev=a[i];
        if(i>0 && dist[i-1]>max)
        {
            max=dist[i-1];
        }
        if(i>0)
        {
            sum+=dist[i-1];
        }
    }
    dist[houses-1]=peri+first-prev;
    sum+=dist[houses-1];
    //cout<<dist[houses-1]<<endl;
    if(max<dist[houses-1])
    {
        max=dist[houses-1];
    }
    //cout<<max<<endl;
    cout<<sum-max<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int N;
	cin >> N;
	if (N < 10) {
		cout << N;
	}
	else if(N>=10&&N<=99){
		cout << 9;
	}
	else if (N >= 100 && N <= 999) {
		cout << 9 + (N / 100 - 1) * 100 + N % 100 + 1;
	}
	else if (N >= 1000 && N <= 9999) {
		cout << 909;
	}
	else if (N >= 10000 && N<=99999) {
		cout << 909 + (N / 10000 - 1) * 10000 + N % 10000 + 1;
	}
	else if(N==100000){
		cout << 90909;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define IOS {ios :: sync_with_stdio(false); cin.tie(0);cout.tie(0); }
#define F first
#define S second
#define pb push_back
typedef long double ld;
#define deci(n) cout << fixed << setprecision(n);
typedef long long ll;

#define mem0(x)  memset(x,0,sizeof(x));
#define mem1(x)  memset(x,1,sizeof(x));
#define memm1(x) memset(x,-1,sizeof(x));
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define fori2(n) for(ll i=1;i<=n;i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define forj2(n) for(ll j=1;j<=n;j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define fork2(n) for(ll k=1;k<=n;k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
const ll md = 1e9 + 7;
// const ll N = 100005;
// ll fac[N] = {1};
// #define calfac for(ll i=1  ;i<N;i++) fac[i] = (fac[i-1]*i)%md;
// ll C[N+1][M+1]; 
// void  ncr(){
//     ll n = N,k = M; 
//     for (ll i = 0; i <= n; i++) { 
//         for (ll j = 0; j <= min(i, k); j++) { 
//             if (j == 0 || j == i)  C[i][j] = 1; 
//             else C[i][j] = C[i - 1][j - 1] +  C[i - 1][j]; 
//         } 
//     } 
// } 


#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
ll modInv(ll a)
{
    return pow(a,md-2);
}
 
// ll nCr(ll n,ll r)
// {
//     return (fac[n]*modInv((fac[r]*fac[n-r])%md))%md;
// }

 
ll po(ll x,ll n){
    if(n==0) return 1;
    if(n%2==1) return (x*po(x,n-1));
    else {
        ll k=po(x,n/2);
        return (k*k);
    }
}
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
}
#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))

 
ll dp[(1<<23)];
ll a[23][23],n;

ll sol(ll idx,ll mask){
    if(dp[mask] != -1) return dp[mask];
    if(mask == (1<<n)-1) return 1;
    if(idx==n+1) return 0; 
    ll &t = dp[mask];
    t = 0;
    for(ll i = 0 ; i < n ; i++){
        if(BCHK(mask,i) || a[idx][i+1]==0) continue;  
        t += sol(idx+1,BSET(mask,i));
        t %= md;
    } 
    return t;
}


int32_t main(){
    IOS;
    ll i,j,k,m;
    cin >> n;
    memm1(dp);
    fori2(n){
        forj2(n){
            cin >> a[i][j];
        }
    }
    cout << sol(1,0);

}                                                                                                                                                                   

Measured memory_bytes: 65792
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	ll ans = 0;
	int tmp;
	ll a;
	double b;
	cin >> a >> b;
	b = round(b*100.0); //100倍して小数第1位で四捨五入
	ll c = b; // long long int に格納
	cout << (ll)(c*a/100) << endl; //Aとの積を100で割って出力
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,a,b,sum=0,sum1;
    cin>>n>>a>>b;
    for (i=1;i<=n;i++)
    {
        int x=i;
        while (x>0)
        {
            sum1+=x%10;
            x/=10;
        }
        if (sum1>=a&&sum1<=b) sum+=i;
        sum1=0;
    }
    cout<<sum<<endl;
    return 0;
}

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

inline void ioThings() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#define debug(x) cerr << #x << ": <" << (x) << ">\n"
#else
#define debug(x)
#endif
}

#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp(x, y)  make_pair(x, y);
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second
#define mod       1000000007

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

int main() {
  ioThings();

  int  a, b, c, k;
  cin >> a >> b >> c >> k;

  int res = min(a, k);
  k -= res;
  k = max(0, k - b);

  cout << res - min(c, k);

  return 0;
}


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

int const MAX = 100005;

int sa[MAX], sb[MAX], ta[MAX], tb[MAX];

void count_char(int x[], string s, char c) {
	x[0] = 0;
	for (int i = 1; i <= s.size(); i++) {
		x[i] = x[i - 1] + (s[i - 1] == c);
	}
}

int main() {
	string s, t;
	cin >> s >> t;
	count_char(sa, s, 'A');
	count_char(sb, s, 'B');
	count_char(ta, t, 'A');
	count_char(tb, t, 'B');
	int q;
	cin >> q;
	for (int i = 1; i <= q; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		int aofs, bofs, aoft, boft;
		aofs = sa[b] - sa[a - 1];
		bofs = sb[b] - sb[a - 1];
		aoft = ta[d] - ta[c - 1];
		boft = tb[d] - tb[c - 1];
		if (((aofs - bofs) - (aoft - boft)) % 3 == 0) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}

Measured memory_bytes: 2432
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

char s[210000], t[210000];
int main() {
	scanf("%s", s);
	scanf("%s", t);
	int cnt = 0;
	for (int i = 0; s[i]; i++)
		cnt += s[i] != t[i];
	printf("%d\n", cnt);
}

Measured memory_bytes: 2124
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			
			int[] a = new int[7];
			int m=0;
			for(int i=0;i<n;i++){
				m = sc.nextInt();
				if(m<10){
					a[0]++;
				}else if(m>=10 && m<20){
					a[1]++;
				}else if(m>=20 && m<30){
					a[2]++;
				}else if(m>=30 && m<40){
					a[3]++;
				}else if(m>=40 && m<50){
					a[4]++;
				}else if(m>=50 && m<60){
					a[5]++;
				}else if(m>=60){
					a[6]++;
				}	
			}

			for(int i=0;i<7;i++){
				System.out.println(a[i]);
			}
		}
	}	
}

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

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

template<typename Monoid>
struct SegmentTree{
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;

    const F f;      // モノイドに対して二項演算を行う関数オブジェクト
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1){
        sz = 1;
        while(sz < n)   sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x){
        seg[k + sz] = x;
    }

    void build(){
        for(int k = sz - 1; k > 0; --k){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    void update(int k, const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k >>= 1){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    Monoid query(int a, int b){
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1){
            if(a & 1)   L = f(L, seg[a++]);
            if(b & 1)   R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const{
        return seg[k + sz];
    }
};

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

    int n;
    ll k;
    cin >> n >> k;
    SegmentTree<ll> seg(n, [](ll a, ll b){return a + b;}, 0ll);
    vector<P> input(n);
    for(int i = 0; i < n; ++i)  cin >> input[i].first >> input[i].second;
    sort(input.begin(), input.end());
    for(int i = 0; i < n; ++i)  seg.set(i, input[i].second);
    seg.build();
    int lb = 0, ub = n;
    while(ub - lb > 1){
        int mid = (lb + ub) / 2;
        if(seg.query(0, mid) >= k)  ub = mid;
        else    lb = mid;
    }
    cout << input[lb].first << endl;
}

Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
	double min = 1000;
	int place;
	int N;
	int T, A;
	vector<int> v;
	cin >> N >> T >> A;
	for (int i = 0; i < N; i++) {
		int t;
		cin >> t;
		double m = abs(A - (T - t*0.006));
		if (min > m) {
			min = m;
			place = i+1;
		}
	}
	cout  <<  place << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

typedef long long ll;
typedef map<ll, ll> M;
typedef pair<ll, ll> P;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ((ll)(x).size())

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  vector<ll> tmp(4);
  tmp[0] = a * c;
  tmp[1] = a * d;
  tmp[2] = b * c;
  tmp[3] = b * d;
  sort(ALL(tmp));
  cout << tmp[3] << endl;
  return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>

int main(){
  int a, b, c;
  int i;
  int count = 0;
  
  scanf("%d %d %d", &a, &b, &c);

  for(i = a; i <= b; i++){
    if(c % i == 0) count++;
  }

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


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

int main(){
  int a,b,c,d,e,f;
  cin >>a>>b>>c>>d>>e;
if (a <40) a=40;
if (b<40) b=40;
if (c<40) c=40;
if (d <40) d=40;
if(e<40)e=40;
  f =(a+b+c+d+e)/5;
  cout<<f<<endl;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
const int inf=INT_MAX;
#define mod 1e9+7
#define PI acos(-1)
#define INF 0x3f3f3f
#define ll long long
#define pb push_back
#define C(a) cout<<a<<endl;
#define CY cout<<"YES"<<endl;
#define CN cout<<"NO"<<endl;
#define Cy cout<<"Yes"<<endl;
#define Cn cout<<"No"<<endl;
#define ull unsigned long long
#define ffr(a) for(int i=0;i<a;i++)
#define frr(a) for(int i=1-1;i>=0;i--)
#define me(a) memset(a,0,sizeof(a));
#define my(a,b) memcpy(a,b,sizeof(b));
#define cio ios::sync_with_stdio(false);
ll gcd(ll a,ll b){return (a%b==0) ? b : gcd(b,a%b);}
int main()
{
	ll x;
	long double y; 
	cin>>x>>y;
	ll g=x*y;
	cout<<g<<endl;
    return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include<string>

using namespace std;

int main(void) {
	int N, A, B, C, D;
	
	cin >> N >> A >> B >> C >> D;
	string S;

		cin >> S;

		A -= 1;
		B -= 1;
		C -= 1;
		D -= 1;

		int temp = S.find("##",A);
			if (temp != -1) { //##がある
				if (temp < C || temp < D) {
					cout << "No";
					return 0;
				}
			}

	//追い越すとき
	if (C > D) {
		int temp = S.find("...",B-1);
		if (temp == -1) {
			cout << "No";
			return 0;
		}
			else {
				if(temp>D-1) {
					cout << "No";
					return 0;
				}
			}
		} 


	cout << "Yes";
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

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

    ll sum_=0;
    for(ll i=1; i<=N; i++){
        if(i%3>0 && i%5>0){
            sum_+=i;
        }
    }
    cout << sum_ << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const long double PI = acos(-1);
const long long INF = (1 << 30);
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;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  ll n;
  cin >> n;
  if(n/100 == 7 || n/10%10 == 7 || n%10 == 7) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main() {
  int city_num, road_num;
  cin >> city_num >> road_num;
  
  vector<int> city_road(city_num);

  for (int cnt=0; cnt < road_num; ++cnt) {
    int a,b;
    cin >> a >> b;
    city_road.at(a-1) += 1;
    city_road.at(b-1) += 1;
  }

  for (int cnt=0; cnt < city_num; ++cnt) {
    cout << city_road.at(cnt) << endl;
  }

  return 0;
}

Measured memory_bytes: 3612
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: usize,
        s: [String; n],
    }

    let mut ac = 0;
    let mut wa = 0;
    let mut tle = 0;
    let mut re = 0;
    for i in s {
        match i.as_ref() {
            ("AC") => ac += 1,
            ("WA") => wa += 1,
            ("TLE") => tle += 1,
            ("RE") => re += 1,
            (_) => {},
        }
    }
    println!("AC x {}\nWA x {}\nTLE x {}\nRE x {}", ac, wa, tle, re);
}


Measured memory_bytes: 7812
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

int main() {
  int n,k,r,s,p; string t;
  cin >> n >> k >> r >> s >> p >> t;
  int ans = 0;
  rep(i,n){
    if(i<k){
      if(t[i] == 'r') ans += p;
      else if(t[i] == 's') ans += r;
      else ans += s;
    }else{
      if(t[i] == t[i-k]){
        t[i] = 'z';
      }else{
        if(t[i] == 'r') ans += p;
        else if(t[i] == 's') ans += r;
        else ans += s;    
      }
    }
  }
  
  cout << ans << endl;
  return 0;
  
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	vector<pair<bool, int>> ans(n);
	rep(i, n) ans.at(i) = make_pair(false, 1);
	ans.at(0).first = true;
	rep(i, m){
		int x, y;
		cin >> x >> y;
		x--; y--;
		ans.at(x).second--;
		ans.at(y).second++;
		if(ans.at(x).first == true) ans.at(y).first = true;
		if(ans.at(x).second == 0) ans.at(x).first = false;
	}
	int aa = 0;
	rep(i, n){
		// cerr << ans.at(i).first << " " << ans.at(i).second << endl;
		if(ans.at(i).first == true && ans.at(i).second != 0) aa++;
	}
	cout << aa << endl;
	return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  string s;
  cin >> s;
  cout << (s == "ABC" ? "ARC" : "ABC");
}
#endif


Measured memory_bytes: 3572
"use strict";
main(require("fs").readFileSync("/dev/stdin", "UTF-8"));

function main(input) {
  input = input.trim().split("\n");
  const sAL = parseInt(input.shift()); // 文字列Aの長さ
  let sA = new Array(sAL).fill(0);
  let sB = input[0].split(" ").map(s => parseInt(s));
  sA[0] = sB[0];
  for (let i = 0; i < sB.length; i++) {
    sA[i + 1] = sB[i];
    if (sB[i] < sA[i]) {
      sA[i] = sB[i];
    }
  }
  let sum = 0;
  sA.map(n => (sum += n));
  console.log(sum);
}


Measured memory_bytes: 7372
n = int(input())
A = list(map(lambda x: int(x) - 1, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
prev = -10
for a in A:
    ans += B[a]
    if a == prev + 1:
        ans += C[prev]
    prev = a
print(ans)


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

using namespace std;
typedef long long ll;

int main(){
  ll L,R;
  cin >> L >> R;
  int ans=2019;
  if(R-L>=2019){
    ans = 0;
  }else{
    for(ll i=L;i<R;i++){
      for(ll j=i+1;j<R+1;j++){
	int n = i%2019;
	int m = j%2019;
	ans=min(ans,(n*m)%2019);
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3624
//
//  Competitive Programming
//  Don't Copy Be Original - Ehsaan Rahman
//  Copyright © 2020 Ehsaan Rahman. All rights reserved.
//
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<map>
#include<bitset>
#include<cstring>
#include<stack>
#include<queue>
#include<set>
#include<chrono>
#include<list>
#include<climits>
#include<iomanip>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #define PBDS tree<long long int,null_type,less<long long int>, rb_tree_tag,tree_order_statistics_node_update>
// using namespace __gnu_pbds;
#define arrsize 200001
#define dpsize 1001
#define w(t) while(t--)
#define PP pair<ll,ll>
#define INF 1999999996000000010
#define ll long long int
#define takeINP(arr,n) for(long long int i=0;i<n;i++) cin>>arr[i];
#define f(i,s,e) for(long long int i=s;i<e;i++)
#define cf(i,s,e) for(long long int i=s;i<=e;i++)
#define rf(i,e,s) for(long long int i=e-1;i>=s;i--)
#define mem(arr) memset(arr,0,sizeof(arr));
#define MOD 1000000007
#define pp(a,b) make_pair(a,b)
#define print(arr,s,e) f(i,s,e) cout<<arr[i]<<" "; cout<<endl;
#define PP pair<ll,ll>
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define vll vector<ll>
#define triplet pair<ll,pair<ll,ll> >
#define MITR(a,b) map<a,b>::reverse_iterator 
using namespace std;
using namespace chrono;

///Author - Ehsaan Rahman - Don't Copy Be Original
///---------------Functions---------------------///
ll advceil(ll num,ll den){return (num%den==0?num/den:num/den+1);}
ll lstbt(ll val){ ll msk = val&(val-1); return log2(val^msk);}
///---------x------------x----------x-----------///
map<ll,vector<ll> > edges;
ll color[arrsize]={};
ll dp[arrsize][3]={};
///1 white //2 black
ll dfs(ll src,ll par,ll parcolor){
	if(dp[src][parcolor]!=-1) return dp[src][parcolor];

	ll cnt1 = 1;
	for(auto itr : edges[src]){
		if(itr==par) continue;
		cnt1 = (cnt1%MOD*dfs(itr,src,1)%MOD)%MOD;
	}
	ll cnt2 = 1;
	if(parcolor!=2){
		for(auto itr : edges[src]){
			if(itr==par) continue;
			cnt2 = (cnt2%MOD*dfs(itr,src,2)%MOD)%MOD;
		}
    }
    else cnt2 = 0;

    return dp[src][parcolor] = (cnt1+cnt2)%MOD;
}

void solve(){
	ll n; cin>>n;
	f(i,0,n-1){
		ll x,y; cin>>x>>y;
		edges[x].push_back(y);
		edges[y].push_back(x);
	}
	memset(dp,-1,sizeof(dp));
	cout<<dfs(1,0,-1)<<endl;
}

int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r" ,stdin);
		freopen("output.txt", "w" ,stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    auto start1 = high_resolution_clock::now();
    solve();
    auto stop1 = high_resolution_clock::now();
	auto duration = duration_cast<microseconds>(stop1 - start1);
    #ifndef ONLINE_JUDGE
		cerr << "Time: " << duration.count() / 1000.0 << endl;
	    cout<<duration.count()/1000.0<<endl;
    #endif
}

Measured memory_bytes: 28916
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
typedef long long ll;

int main()
{
	int A, B;
	scanf("%d%d", &A, &B);
	int cnt = 0;
	for (int i = A; i <= B; i++) {
		int j = i % 10;
		int k = i / 10000 % 10;
		int l = i / 10 %10;
		int m = i / 1000 % 10;
		if (j == k && l == m) cnt++;
	}

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

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

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

  int B[N];
  rep(i, N - 1) { cin >> B[i]; }

  ll result = 0;

  rep(i, N - 1) {
    if (i == 0) {
      result += B[0] + min(B[0], B[1]);
    } else if (i == N - 2) {
      result += B[i];
    } else {
      result += min(B[i], B[i + 1]);
    }
  }

  cout << result << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

#define INF 1000000000000009LL
#define MOD 1000000007LL

ll dp[405][405];
ll multi[400][400];

ll dfs(int i, int j) {
  if (i == j) return 0LL;
  
  for (int k = i; k < j; k++) {
    if (dp[i][j] == dp[i][k] + dp[k+1][j]) return dp[i][j] + dfs(i, k) + dfs(k+1, j);
  }
}

int main() {
  int N; cin >> N;
  vector<ll> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  
  for (int i = 0; i < N; i++) {
    for (int j = i; j < N; j++) {
      ll multi_a = 0;
      for (int k = i; k <= j; k++) multi[i][j] += a[k];
    }
  }
  
  for (int i = N - 1; i >= 0; i--) {
    for (int j = i; j < N; j++) {
      if (i == j) dp[i][j] = 0;
      else {
        ll res = INF;
        for (int k = 0; k < j - i; k++) {
          res = min(res, multi[i][j] + dp[i][i+k] + dp[i+k+1][j]);
        }
        dp[i][j] = res;
      }
    }
  }
  
  cout << dp[0][N-1] << endl;
  return 0;
}

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

struct Data{
  int num,id;
  char ch;
};

int Partition(Data A[],int p,int r){
  Data x = A[r];
  int i=p-1;
  for(int j=p;j<r;j++){
    if(A[j].num<=x.num){
      i++;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[r]);
  return i+1;
}

void Quicksort(Data A[],int p,int r){
  if(p<r){
    int q = Partition(A,p,r);
    Quicksort(A,p,q-1);
    Quicksort(A,q+1,r);
  }
}

void check(Data A[],int n){
  for(int i=1;i<n;i++){
    if(A[i-1].num<A[i].num)continue;
    if(A[i-1].id<A[i].id)continue;
    cout<<"Not stable"<<endl;
    return;
  }
  cout<<"Stable"<<endl;
}

int main(){
  int n;
  Data A[100000];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>A[i].ch>>A[i].num;
    A[i].id=i;
  }
  
  Quicksort(A,0,n-1);
  check(A,n); 
  for(int i=0;i<n;i++){
    cout<<A[i].ch<<' '<<A[i].num<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 4260
n,m,q = map(int,input().split())
arr = [list(map(int,input().split())) for x in range(q)]
ans = 0

for i1 in range(1,m+1):
  for i2 in range(i1,m+1):
    for i3 in range(i2,m+1):
      for i4 in range(i3,m+1):
        for i5 in range(i4,m+1):
          for i6 in range(i5,m+1):
            for i7 in range(i6,m+1):
              for i8 in range(i7,m+1):
                for i9 in range(i8,m+1):
                  for i10 in range(i9,m+1):
                    tmp = 0
                    arrs = [0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]
                    for a,b,c,d in arr:
                      if arrs[b] - arrs[a] == c:
                        tmp += d
                    ans = max(ans,tmp)
print(ans)


Measured memory_bytes: 9132
#include<bits/stdc++.h>
#define LL long long
#define clr(x,y) memset(x,y,sizeof(x))
#define FOR(x,l,r) for(int x=l,x##_=r;x<=x##_;x++)
#define FR(x,l,r) for(int x=l,x##_=r;x<x##_;x++)
#define DOR(x,r,l) for(int x=r,x##_=l;x>=x##_;x--)
using namespace std;
int a,b,c;
int main () {
	scanf("%d%d%d",&a,&b,&c);
	printf("%d\n",min(a*b,c));
	return 0;
}


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

int main(){
	int i, j, r, c;
	int array[102][102];

	cin >> r >> c;

	for (i = 1; i <= r + 1; i++){
		for (j = 1; j <= c + 1; j++){
			array[i][j] = 0;
		}
	}

	for (i = 1; i <= r; i++){
		for (j = 1; j <= c; j++){
			cin >> array[i][j];
			array[i][c+1] += array[i][j];
			array[r+1][j] += array[i][j];
			array[r+1][c+1] += array[i][j];
		}
	}

	for (i = 1; i <= r + 1; i++){
		for (j = 1; j <= c + 1; j++){
			if (j != 1) cout << " ";
			cout << array[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1196
use std::io::*;
use std::str::FromStr;
use std::collections::*;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  };
  ($e:expr => $i:expr; $t:ty) => {
    {
      let mut v = Vec::new();
      for _ in 0..$i {
        v.push($e.get::<$t>());
      }
      v
    }
  }
}

struct Scanner<R: Read> {
  reader: R
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader: reader }
  }
  fn safe_get<T: FromStr>(&mut self) -> Option<T> {
    let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
      .skip_while(|c| c.is_whitespace())
      .take_while(|c| !c.is_whitespace())
      .collect::<String>();
    if token.is_empty() { None } else { token.parse().ok() }
  }
  fn get<T: FromStr>(&mut self) -> T {
    if let Some(v) = self.safe_get() { v } else {
      writeln!(stderr(), "Terminated with EOF").unwrap();
      std::process::exit(0);
    }
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  let n = scan!(sc; i32);
  let query = scan!(sc => n * 2; String);
  let mut h = HashSet::new();
  let mut qit = query.iter();
  for _ in 0..n {
    let q = qit.next().unwrap();
    let s = qit.next().unwrap();
    match &q[..] {
      "insert" => { h.insert(s); },
      "find"   => {
        println!("{}", if h.contains(s) { "yes" } else { "no" });
      },
      _ => {}
    }
  }
}



Measured memory_bytes: 86960
N = int(input())
L = list(map(int, input().split()))

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
                continue
            l = [L[i], L[j], L[k]]
            l.sort()
            if l[0] + l[1] > l[2]:
                ans += 1

print(ans)


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


			

int main(){
	
	int N,M;
	cin>>N>>M;
	
	vector<vector<bool>> flag(M,vector<bool>(N,false));
	
	for(int i=0;i<M;i++){
		int k;
		cin>>k;
		for(int j=0;j<k;j++){
			int a;
			cin>>a;
			flag[i][a-1]=true;
		}
	}
	vector<bool> p(M);
	for(int i=0;i<M;i++){
		int a;
		cin>>a;
		if(a)p[i]=true;
		else p[i]=false;
	}
	int ans = 0;
	for(int i=0;i<(1<<N);i++){
		bool f = true;
		for(int j=0;j<M;j++){
			int x = 0;
			for(int k=0;k<N;k++){
				if((i>>k)%2==1&&flag[j][k])x++;
			}
			if(x%2!=p[j]){
				f=false;
				break;
			}
		}
		if(f)ans++;
	}
	
	cout<<ans<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
using namespace std;
struct Node {
	int key;
	Node *prev, *next;
};
Node *nil;

void init(){
 	nil = (Node *)malloc(sizeof(Node));
 	nil -> next = nil;
 	nil -> prev = nil;
}

void insert(int key){
	Node *x = (Node *)malloc(sizeof(Node));
	x -> key = key;
	x -> next = nil -> next;
	nil -> next -> prev = x;
	nil -> next = x;
	x -> prev = nil;
}
Node *listSearch(int key){
	Node *x = nil->next;
	while(x != nil && x -> key != key) x = x -> next;
	return  x;
}
void deleteNode(Node *t){
	if(t == nil) return;
	t -> prev -> next = t -> next;
	t -> next -> prev = t -> prev;
	free(t);
}
void deleteFirst(){
	deleteNode(nil -> next);
}

void deleteLast(){
	deleteNode(nil -> prev);
}

void printList(){
	Node *t = nil -> next;
	while(t != nil){
		printf("%d", t -> key);
		if(t -> next != nil) printf(" ");
		t = t -> next;
	}
	printf("\n");
}

int main(){
	int n, key;
	scanf("%d", &n);
	init();
	while(n--){
		char s[20];
		scanf("%s", s);
		if(s[0] == 'i'){
			scanf("%d", &key);
			insert(key);
		}
		else{
			if(s[6] == 'F') deleteFirst();
			else if(s[6] == 'L') deleteLast();
			else{
				scanf("%d", &key);
				deleteNode(listSearch(key));
			}
		}
		//printList();
	} 
	printList();
	
	return 0;
}


Measured memory_bytes: 33820
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
int main(){
    int n;cin>>n;
    int h;cin>>h;
    int t=0;
    for(int i=0;i<n-1;i++){
        int k;cin>>k;
        if(k<h)t+=(h-k);
        if(t==1&&k>h)t--;
        if(t>=2)break;
        h=k;
    }
    cout<<(t<2?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    long long n,k;
    cin >> n >> k;
    long long res;
    for(int i = k + 1; i <= n; i++){
        long long s,t;
        s = n / i;
        t = n % i;
        res += (i-k)*s;
        if(t>=k && k > 0)res += t-k+1;
        if(k==0)res += t-k;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int p[4][300];
int cost[300];
int dp[301][301];
int n,m;

int solve(int now, int money, int pp){
  if(now == n) return 0;
  if(dp[now][money] != -1) return dp[now][money];
  int ret = 0;
  if(money >= cost[now])
    ret = p[pp][now] + solve(now,money-cost[now],pp);
  ret = max(ret, solve(now+1,money,pp));
  return dp[now][money] = ret;
}

int main(){
  string str;
  while(getline(cin,str)){
    stringstream ss(str);
    ss >> n >> m;

    REP(i,n){
      getline(cin,str);
      getline(cin,str);
      stringstream ss2(str);
      ss2 >> cost[i] >> p[0][i] >> p[1][i] >> p[2][i];
    }

    int ans = 0;
    REP(pp,4){
      memset(dp,-1,sizeof(dp));
      ans = max(ans, solve(0,m,pp));
    }

    print(ans);
  }
  return 0;
}

Measured memory_bytes: 1320
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <random>
#include <sstream>
#include <stack>
#include <deque>

using namespace std;

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

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

string S;

int main() {
  cin >> S;
  int n = S.size();
  int c[3] = {};
  rep(i,n) c[S[i]-'a']++;
  sort(c, c+3);
  if (c[2] - c[0] <= 1) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
       int[] t= {sc.nextInt(),sc.nextInt(),sc.nextInt()};
       Arrays.sort(t);
       System.out.println(t[0]+Math.min(sc.nextInt(), sc.nextInt())-50);
    }
}


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

#define ll long long

int main()
{
    ll a,b,x;
    cin >> a >> b >> x;
    ll ans1 = a / x;
    ll ans2 = b / x;
    ll ans = ans2 - ans1;
    if(a % x == 0)
    {
        ans++;
    }
    cout << ans;
}


Measured memory_bytes: 3636