akhauriyash/Code-Regression huggingface dataset:
use std::io::Read;
use std::io::Write;

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let mut g = vec![vec![]; n];
    for i in 0..(n - 1) {
        let a = it.next().unwrap().parse::<usize>().unwrap() - 1;
        let b = it.next().unwrap().parse::<usize>().unwrap() - 1;
        g[a].push((b, i));
        g[b].push((a, i));
    }
    let color = g.iter().map(|g| g.len()).max().unwrap();
    let mut ans = vec![0; n - 1];
    let mut stack = vec![(0, 0)];
    while let Some((v, p)) = stack.pop() {
        let mut err = 0;
        for i in 0..g[v].len() {
            if g[v][i].0 == p {
                err = ans[g[v][i].1];
                g[v].remove(i);
                break;
            }
        }
        let mut c = 1;
        for &(u, k) in g[v].iter() {
            if c == err {
                c += 1;
            }
            ans[k] = c;
            c += 1;
            stack.push((u, v));
        }
    }
    writeln!(out, "{}", color).ok();
    for a in ans {
        writeln!(out, "{}", a).ok();
    }
}

fn main() {
    run();
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)

#define INF 987654321
#define IINF 2987654321987654321
#define MOD 998244353

inline ll labs(ll n) { return (n > 0) ? n : -n; }

const int LOGX = 32;
ll p2[LOGX];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
char dir[4] = {'L', 'D', 'R', 'U'};

void solve(ll x, ll y) {
	for(int t = LOGX-1; t >= 0; t--) {
		for(int k = 0; k < 4; k++) {
			if(labs(x - dx[k]*p2[t]) + labs(y - dy[k]*p2[t]) <= (p2[t]-1)) {
				printf("%c", dir[k]);
				x -= dx[k]*p2[t];
				y -= dy[k]*p2[t];
				break;
			}
		}
	}
	printf("\n");
}

int main() {
	for(int i = 0; i < LOGX; i++)
		p2[i] = (1LL<<i);

	int n; scanf("%d", &n);
	vector<pii> v(n);
	for(int i = 0; i < n; i++)
		scanf("%d%d", &v[i].first, &v[i].second);

	bool flag = (v[0].first + v[0].second) & 1;
	for(int i = 0; i < n; i++) {
		if(flag ^ ((v[i].first + v[i].second) & 1)) {
			printf("-1\n");
			exit(0);
		}
	}

	if(!flag)
		for(int i = 0; i < n; i++)
			v[i].first--;

	printf("%d\n", flag ? LOGX : LOGX+1);
	if(!flag) printf("1 ");
	for(int i = LOGX-1; i >= 0; i--)
		printf("%lld ", p2[i]);
	printf("\n");

	for(int i = 0; i < n; i++) {
		if(!flag) printf("R");
		solve(v[i].first, v[i].second);
	}
}

Measured memory_bytes: 256
#include<set>
#include<iostream>
#include<ctime>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<random>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<functional>
#include<string.h>
#include<limits.h>
using namespace std;

signed main() {
	int a, b; cin >> a >> b;
	cout << (a + b) / 2 << endl;
}

Measured memory_bytes: 3080
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AFiftyFifty solver = new AFiftyFifty();
        solver.solve(1, in, out);
        out.close();
    }

    static class AFiftyFifty {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String x = in.next();
            if (x.charAt(0) == x.charAt(1) && x.charAt(1) == x.charAt(2) && x.charAt(2) == x.charAt(3))
                out.println("No");
            else if (x.charAt(0) == x.charAt(1) && x.charAt(2) == x.charAt(3)) {
                out.println("Yes");
            } else if (x.charAt(0) == x.charAt(2) && x.charAt(1) == x.charAt(3)) {
                out.println("Yes");
            } else if (x.charAt(0) == x.charAt(3) && x.charAt(2) == x.charAt(1)) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 21332
def c_tax_increase():
    A, B = [int(i) for i in input().split()]
    for k in range(1, 10**6):
        t1 = 8 * k // 100
        t2 = k // 10
        if t1 > 0 and t2 > 0 and t1 == A and t2 == B:
            return k
    return -1

print(c_tax_increase())

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> c(n);

    for (int i=0; i<n; i++) cin >> v[i];
    for (int i=0; i<n; i++) cin >> c[i];

    int ans = 0;
    for (int i=0; i<n; i++) {
        int t = v[i] - c[i];
        if (t > 0) ans += t;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
map<int, int> mp;
int main()
{
	ll n, m, k;
	cin >> n >> m >> k;
	vector<ll> a(n), b(m);
	vector<ll> suma(n + 1, 0), sumb(m + 1, 0);
	suma[0] = sumb[0] = 0;
	rep(i, n) {
		cin >> a[i];
		suma[i + 1] = suma[i];
		suma[i + 1] += a[i];
	}
	rep(i, m) {
		cin >> b[i];
		sumb[i + 1] = sumb[i];
		sumb[i + 1] += b[i];
	}	
	ll ans = 0, tmpans = 0, tmpk;
	rep(i, n + 1) {
		tmpk = k;
		tmpans = i;
		tmpk -= suma[i];
		if (tmpk < 0)	break;
		int lower, upper, current;
		lower = 0; upper = m;
		if (0 <= tmpk - sumb[upper]) tmpans += upper;
		else {
			current = (upper + lower) / 2;
			while (1 < upper - lower) {
				if (tmpk - sumb[current] < 0)	upper = current;
				else if (0 <= tmpk - sumb[current])	lower = current;
				current = (upper + lower) / 2;
			}
			tmpans += lower;
		}
		if (ans < tmpans)	ans = tmpans;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9584
#include<bits/stdc++.h>
#define P 1000000007
#define ll long long
using namespace std;
int n,m,K,S;ll f[4005][2005],g[4005][2005],Ans;
int main()
{
	scanf("%d%d%d",&n,&m,&K);
	f[0][0]=1;
	for (int i=0;i<=n;i++)
		g[0][i]=1;
	S=(n+m-1)/(K-1);
	for (int i=1;i<=S;i++)
	{
		for (int j=0;j<=n;j++)
		{
			/*
			for (int t=0;t<=j&&t<K;t++)
				f[i][j]=f[i][j]+f[i-1][j-t];*/
			if (j>=K) f[i][j]=(g[i-1][j]-g[i-1][j-K])%P;
			else f[i][j]=g[i-1][j];
			if (j) g[i][j]=(g[i][j-1]+f[i][j])%P;
			else g[i][j]=f[i][j];
			int tmp=i*(K-1)-j;
			if (j%(K-1)==n%(K-1)&&tmp<=m-1&&tmp%(K-1)==(m-1)%(K-1))
			{
				Ans=(Ans+f[i][j]-f[i-1][j])%P;
			}
		}
	}
	printf("%lld\n",(Ans+P)%P);
}

Measured memory_bytes: 125696
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int>a(N);
  vector<int>b(N);
  vector<int>c(N);
  for(int i=0;i<N;i++){
  int A,B,C;
    cin>>A>>B>>C;
    a.at(i)=A;
    b.at(i)=B;
    c.at(i)=C;
  }vector<vector<int>>dp(N+1,vector<int>(3,0));
  for(int i=1;i<=N;i++){
  dp[i][0]=a.at(i-1)+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=b.at(i-1)+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=c.at(i-1)+max(dp[i-1][0],dp[i-1][1]);
  }int ans=max(dp[N][0],max(dp[N][1],dp[N][2]));
  cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 6912
#include <stdio.h>
int main()
{
  int i, j ;
  int n, m ;
  scanf("%d %d",&n,&m) ;

  int mat[100][100], vec[100], ans[100] ;

  /*行列の各要素を代入する*/
  for( i=0 ; i<n ; i++ ){
    for( j=0 ; j<m ; j++){
      scanf("%d",&mat[i][j]) ;
    }
  }

  /*ベクトルの成分をスキャン、代入*/
  for( j=0 ; j<m ; j++ ){
    scanf("%d",&vec[j]) ;
  }

  for( i=0 ; i<n ; i++ ){
    for( j=0 ; j<m ; j++ ){
      ans[i] += mat[i][j] * vec[j] ;
    }
    printf("%d\n", ans[i]) ;
  }

  return 0 ;
}


Measured memory_bytes: 2092
#include <stdio.h>

int main(void) {
	int N, M;
	int i;
	int hayamisaori = 1;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 1; i * i <= M; i++) {
		if (M % i == 0) {
			if (i >= N) {
				if (M / i > hayamisaori) hayamisaori = M / i;
			}
			if (M / i >= N) {
				if (i > hayamisaori) hayamisaori = i;
			}
		}
	}
	printf("%d\n", hayamisaori);
	return 0;
}

/*

xb_1 + xb_2 + ... + xb_N = M

xk = M (k >= N)

*/


Measured memory_bytes: 128
#include <bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ll long long int
using namespace std;
ll ans = 0, sum = 0, n, k, counter = 0, w, h;
string s;
vector<ll> v;
vector<pair<ll, ll>> vp;
vector<vector<ll>> vv(50, vector<ll>(50, INF));

ll parent(ll num) {
  if (v[num] == num) return num;
  else {
    ll res = parent(v[num]);
    v[num] = res;
    return res;
  }
}

int main() {
  cin >> n >> k;
  v.resize(n);
  REP(i, n) {
    v[i] = i;
  }
  REP(i, k) {
    ll a, b, c;
    cin >> a >> b >> c;
    if (a) {
      if (parent(b) == parent(c)) cout << "1" << endl;
      else cout << "0" << endl;
    }
    else {
      v[parent(c)] = parent(b);
    }
  }
}

Measured memory_bytes: 3288
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long sum = 1;

		for(int i=1; i<=n;i++) {
			sum *=i;
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 26064
N, M, C = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

ans = 0

N.times do
  a = gets.split.map(&:to_i)  
  ans += 1 if [a, b].transpose.map{|x| x.inject(:*)}.inject(:+) + C > 0
end

puts ans

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

void Main()
{
    int n;
    cin >> n;
    vector<long> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    long money = 1000;
    long stock = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i+1] <= a[i]) {
            money += stock * a[i];
            stock = 0;
        } else {
            stock += money / a[i];
            money = money % a[i];
        }
    }
    money += stock * a[n-1];
    cout << money << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 3628
N, M, C = map(int, input().split())
B = list(map(int,input().split()))
ans = 0
for i in range(N):
    A = list(map(int,input().split()))
    tmp = C
    for j in range(M):
        tmp += A[j] * B[j]
    if tmp > 0:
        ans += 1
print(ans)




Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
using namespace std;
 
int main(){
    int n; cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int tmp=0;
    int ans=0;
    rep(i,n-1){
        if(h[i]>=h[i+1]) tmp++;
        else{
            ans=max(ans,tmp);
            tmp=0;
        }
    }
    cout << max(ans,tmp) << endl;
return 0;
}

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

using namespace std;
const int MAXN = 1e5 + 5;

int main(int argc, char* argv) {
    int n;
    cin >> n;
    while (n > 1000)
        n -= 1000;
    cout << 1000 - n << endl;
    return 0;
}


Measured memory_bytes: 3584
/*
ID: alec3
LANG: C++14
PROG:
*/


#include <bits/stdc++.h>

#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ss second
#define ff first
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ld long double
#define all(c) (c).begin(), (c).end()
#define FOR(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int main()
{
    io;
    int n, l;
    cin >> n >> l;
    l --;

    // in inverse p each index is actually the value and the value
    // held at that that index is actually an index
    vector<int> p(n), inv_p(n);
    for (int i = 0; i < n; i++){
        cin >> p[i];
        p[i] --;
        inv_p[p[i]] = i;
    }

    vector<ll> c(n);
    for (int i = 0; i < n; i++)
        cin >> c[i];

    // minimum possible
    ll ret = -(1LL << 62);

    // loop though starting positions
    for (int i = 0; i < n; i++){
        ll s = 0;
        // prefix sum vector
        vector<ll> a;
        a.pb(s);

        // loop through the cycle
        for (int j = i; ; j = p[j]){
            // update the sum
            s += c[j];
            a.pb(s);
            // if the value is the same as starting point
            // we've completed a cylce so break out
            if (p[j] == i)
                break;
        }

        // save the length of a and copy a into b
        int m = a.size() -1;
        vector<ll> b = a;

        // find the maximum value at each point in the cycle
        for (int j = 1; j <= m; j++)
            b[j] = max(b[j], b[j-1]);

        // loop though these possible conditions
        for (int d : {0, 1, 2, l / m, l / m - 1, l / m - 2}){
            // we won't have a valid index
            if (d < 0 || d * m > l)
                continue;
            // update the result if the following is greater
            // c[the value i] (gives index) + sum * element in list + b (holds max values at each index)
            // at the min of m (the size of a) and l - d * m where l is length of the subcycle
            ret = max(ret, c[inv_p[i]] + s * d + b[min(m, l - d * m)]);
        }
    }
    cout << ret << endl;

    return 0;

}


Measured memory_bytes: 3816
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, L = map(int, readline().split())
a = []
tmp = 0
min_tmp = 100000

for i in range(n):
    a.append(i+L)

for i in range(n):
    tmp = abs(a[i])
    if tmp < min_tmp:
        min_tmp = tmp
        min_i = i

print(sum(a) - a[min_i])


Measured memory_bytes: 3060
import sys, collections
input = sys.stdin.readline

n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
nums = [0 for i in range(n)]
day = 0
match = 0
flag = True
queue = collections.deque([])
temp = set()
for i in range(1, n + 1):
    i2 = a[i - 1][0]
    if a[i2 - 1][0] == i:
        if i not in temp:
            queue.append([i, i2])
            temp.add(i)
            temp.add(i2)
if not queue:
    flag = False
while queue:
    temp = []
    while queue:
        test = queue.popleft()
        match += 1
        num1, num2 = test[0], test[1]
        nums[num1 - 1] += 1
        nums[num2 - 1] += 1
        temp.append(num1)
        temp.append(num2)
    flag2 = False
    temp2 = set()
    for i in temp:
        if nums[i - 1] <= n - 2:
            new_num = a[i - 1][nums[i - 1]]
            if nums[new_num - 1] <= n - 2 and a[new_num - 1][nums[new_num - 1]] == i:
                if i not in temp2:
                    queue.append([i, new_num])
                    flag2 = True
                    temp2.add(i)
                    temp2.add(new_num)
    if flag2 == False and match < n * (n - 1) // 2:
        flag = False
        break
    day += 1

if flag == True:
    print(day)
else:
    print(-1)

Measured memory_bytes: 41544
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int a, b;
	cin >> a >> b;
	if (a <= b)cout << a << endl;
	else
		cout << a - 1 << endl;

	return 0;
}



Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
from itertools import combinations_with_replacement

def main():
    N, M, Q = map(int, readline().rstrip().split())
    P = [tuple(map(int, readline().rstrip().split())) for _ in range(Q)]
    ans = 0    
    for pair in combinations_with_replacement([i for i in range(1, M+1)], N):
        score = 0
        for a, b, c, d in P:
            if pair[b-1] - pair[a-1] == c:
                score += d
        ans = max(ans, score)
    
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9212
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
#define N 2507
#define M 5007
#define int long long
using namespace std;
inline int read() {
	int x=0,f=1; char ch=getchar();
	while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
	return x * f;
}
const int INF = 1e18;	//longlongµÄINF²»ÊÇ0x3f3f3f 
int n,m,p;
int f[N];
struct Edge {
	int u,v,d;
}E[M];
signed main()
{
	n = read() ,m = read() ,p = read();
	for(int i=1,u,v,d;i<=m;++i) {
		u = read() ,v = read() ,d = read();
		E[i] = (Edge){u,v,d-p};
	}
	for(int i=1;i<=n;++i) f[i] = -INF;
	f[1] = 0;
	for(int i=1;i<=n*2;++i) {
		for(int j=1;j<=m;++j) {
			int u = E[j].u ,v = E[j].v ,d = E[j].d;
			if(f[u]==-INF) continue;
			if(f[u]+d > f[v]) {
				f[v] = i<=n ? f[u]+d : INF;
			}
		}
	}
	if(f[n]==INF) puts("-1");
	else if(f[n]<0) puts("0");
	else printf("%lld\n",f[n]);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

#define NIL -1

using namespace std;

struct node{
    int id, depth, height, parent; //depth?????????????????????????????§?????????????????? height?????????????????????????????§?????????????????§???
    int sibling; //??????
    int left, right; // ???(???)
};

struct node tree[30];

void setDepth(int start){
    int answer = 0;
    int currentNode = start;
    while(1){
        if(tree[currentNode].parent == NIL) break;
        answer++;
        currentNode = tree[currentNode].parent; 
    }
    tree[start].depth = answer;
}

int setHeight(int start){
    int heightRight = 0, heightLeft = 0;
    if(tree[start].right != NIL){
        heightRight =  setHeight(tree[start].right) + 1;
    }
    if(tree[start].left != NIL){
        heightLeft =  setHeight(tree[start].left) + 1;
    }
    if(heightLeft > heightRight) return heightLeft;
    
    else return heightRight;
}


int main(){
    int n;
    int tempId; // ??\?????¨
    cin >> n;

    for(int i = 0; i < n; i++) tree[i].parent = tree[i].depth = tree[i].height = tree[i].sibling = tree[i].left = tree[i].right = NIL;

    for(int i = 0; i < n; i++){
        cin >> tempId;
        cin >> tree[tempId].left >> tree[tempId].right;
        if(tree[tempId].left != NIL) tree[tree[tempId].left].parent = tempId;
        if(tree[tempId].right != NIL) tree[tree[tempId].right].parent = tempId;
    }

    for(int i = 0; i < n; i++){
        setDepth(i); 
        tree[i].height = setHeight(i);
    }

    for(int i = 0; i < n; i++){
        cout << "node " << i << ": parent = " << tree[i].parent << ", sibling = ";
        if(tree[i].parent == NIL) cout << -1;
        else if(tree[tree[i].parent].left == i) cout << tree[tree[i].parent].right;
        else cout << tree[tree[i].parent].left;
        cout << ", degree = ";
        if(tree[i].left == NIL && tree[i].right == NIL) cout << 0;
        else if(tree[i].left != NIL && tree[i].right != NIL) cout << 2;
        else cout << 1;
        cout << ", depth = " << tree[i].depth << ", height = " << tree[i].height << ", ";
        if(tree[i].parent == NIL) cout << "root";
        else if(tree[i].left == NIL && tree[i].right == NIL) cout << "leaf";
        else cout << "internal node";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}
const int dx[]={-1,0,1,0};
const int dy[]={0,1,0,-1};
const int MAX_N=55;
char s[MAX_N][MAX_N];
int H,W;
int main()
{
	cin>>H>>W;
	For(i,1,H)
	{
		scanf("%s",s[i]+1);
	}
	For(i,1,H)
	{
		For(j,1,W)
		{
			if(s[i][j]=='.')continue;
			bool ok=false;
			rep(d,0,4)
			{
				ok|=(s[i+dx[d]][j+dy[d]]=='#');
			}
			if(!ok)
			{
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	return 0;
}



Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =1e5+7;
const int mod = 1e14 ;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
typedef long long ll;
char s[4][5]={"AC","WA","TLE","RE"};
int ans[4];
int main()
{
	int n;
	scanf("%d",&n);
	while(n--)
	{
		char a[5];
		scanf("%s",a);
		for(int i=0;i<4;i++)
		{
			if(strcmp(a,s[i])==0)
			{
				ans[i]++;
				break;
			}
		}
	}
	for(int i=0;i<4;i++)
	{
		printf("%s x %d\n",s[i],ans[i]);
	}
	return 0;
 } 

Measured memory_bytes: 3712
import numpy as np

def solve(posi):
    INF = 100000000000
    d = np.zeros((H, W))
    for i in range(H):
        for j in range(W):
            d[i][j] = INF
    que = [posi]
    d[posi[0],posi[1]] = 0

    move = np.array([[1,0], [-1,0], [0,1], [0,-1]])
    while len(que):
        p = que.pop(0)
        if np.allclose(posi, np.array([H-1,W-1])):
            break

        for dir in move:
            new_p = p + dir
            if 0 <= new_p[0] and new_p[0] < H and 0 <= new_p[1] and new_p[1] < W:
                if d[new_p[0],new_p[1]] == INF and maze[new_p[0]][new_p[1]] != '#':
                    que.append(new_p)
                    d[new_p[0],new_p[1]] = d[p[0], p[1]] + 1

    if d[H-1][W-1] == INF:
        return -1
    return d[H-1][W-1]

if __name__=='__main__':
    H, W  = map(int, input().split(' '))
    maze = []
    for i in range(H):
        maze.append(list(input()))
    counter = 0
    for i in range(H):
        for j in range(W):
            if maze[i][j] == '.':
                counter += 1

    posi = np.array([0,0])
    if solve(posi) != -1:
        print(int(counter - solve(posi) - 1))
    else:
        print(-1)
    

Measured memory_bytes: 21244
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		long[][] c = new long[51][51];
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= i; j++) {
				if (j == 0 || j == i) c[i][j] = 1;
				else c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
			}
		}

		Long[] v = new Long[n];
		for (int i = 0; i < n; i++) {
			v[i] = sc.nextLong();
		}

		Arrays.sort(v, Comparator.reverseOrder());

		double ave = 0.0;

		for (int i = 0; i < a; i++) {
			ave += v[i];
		}

		ave /= a;
		System.out.println(ave);

		int t = 0;
		int u = 0;
		for (int i = 0; i < n; i++) {
			if (v[i].equals(v[a - 1])) {
				u++;
				if (i < a) t++;
			}
		}

		if (u == 1) {
			System.out.println(1);
			return;
		}

		long count = 0L;
		if (a == t) {
			for (int j = t; j <= b; j++) {
				count += c[u][j];
			}
		} else {
			count += c[u][t];
		}

		System.out.println(count);
	}
}


Measured memory_bytes: 24020
#include <stdio.h>
using namespace std;

int main(){
    int a, b;
    char op;
    
    while(1){
	scanf("%d %c %d", &a, &op, &b);
        if(op == '+'){
            printf("%d\n", a+b);
        }else if(op == '-'){
            printf("%d\n", a-b);
        }else if(op == '*'){
            printf("%d\n", a*b);
        }else if(op == '/'){
            printf("%d\n", a/b);
        }else{
            break;
        }
    }
}



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

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

const long long MOD = 1000000007;

int main(){
  int x,y,a,b,c,d;
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a),q(b),r(c);
  rep(i,a) cin >> p.at(i);
  rep(i,b) cin >> q.at(i);
  rep(i,c) cin >> r.at(i);
  sort(p.begin(),p.end());
  sort(q.begin(),q.end());
  sort(r.begin(),r.end());
  int t=0,ta=0,tb=0;
  while(t<c){
    if(ta<x && tb<y){
      if(p.at(a-x+ta)<=q.at(b-y+tb)) d=0;
      else d=1;
      
      if(d && r.at(c-1-t)>q.at(b-y+tb)){
        q.at(b-y+tb) = r.at(c-1-t);
        t++;
        tb++;
      }
      else if(r.at(c-1-t)>p.at(a-x+ta)){
        p.at(a-x+ta) = r.at(c-1-t);
        t++;
        ta++;
      }
      else break;
    }
    else if(ta<x){
      if(r.at(c-1-t)>p.at(a-x+ta)){
        p.at(a-x+ta) = r.at(c-1-t);
        t++;
        ta++;
      }
      else break;
    }
    else if(tb<y){
      if(r.at(c-1-t)>q.at(b-y+tb)){
        q.at(b-y+tb) = r.at(c-1-t);
        t++;
        tb++;
      }
      else break;
    }
    else break;
  }
  ll ans=0;
  rep(i,x) ans+=p.at(a-1-i);
  rep(i,y) ans+=q.at(b-1-i);
  cout << ans << endl;
}


Measured memory_bytes: 1408
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

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

int main()
{
    int n;
    cin>>n;
    int arr[n][3];
    int dp[n][3];
    for(int i = 0; i < n; i++) {
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
        dp[i][0] = INT_MIN;
        dp[i][1] = INT_MIN;
        dp[i][2] = INT_MIN;
    }
    dp[0][0] = arr[0][0];
    dp[0][1] = arr[0][1];
    dp[0][2] = arr[0][2];
    for(int i = 1; i < n; i ++) {
        for(int j = 0; j < 3; j++) {
            for(int z = 0; z < 3; z++) {
                if(j != z) {
                    dp[i][j] = max(dp[i][j], dp[i - 1][z] + arr[i][j]);
                }
            }
        }
    }
    cout<<max(dp[n - 1][0], max(dp[n-1][1], dp[n-1][2]))<<"\n";

    return 0;
}


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

int main() {
  ll n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<ll> ans(1e5);
  ll count=0;
  reverse(s.begin(),s.end());
  s=s+'0';
  ll temp=0;
  while(temp<n) {
    ll go=k;
    bool flag=false;
    while(1) {
      if(temp+go<=n&&s[temp+go]=='0') {
        temp+=go;
        ans[count]=go;
        count++;
        break;
      }
      else {
        go--;
      }
      if(go<1) {
        flag=true;
        break;
      } 
    }
    if(flag) {
      break;
    }
  }
  if(temp!=n) {
    cout << -1 << endl;
  }
  else {
    for(ll i=count-1;i>-1;i--) {
      if(i!=count-1) {
        cout << " ";
      }
      cout << ans[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 1436
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string[] s1 = Console.ReadLine().Split(' ');
        int q = int.Parse(Console.ReadLine());
        string[] s2 = Console.ReadLine().Split(' ');

        int[] a = new int[N];
        int[] b = new int[q];
        int cnt = 0;

        for (int i = 0; i < N; i++)
        {
            a[i] = int.Parse(s1[i]);
        }

		for (int i = 0; i < q; i++)
		{
			b[i] = int.Parse(s2[i]);
		}

        Array.Sort(a);

        for (int i = 0; i < q;i++)
        {
            if (Array.BinarySearch(a, b[i])>=0) cnt++;
        }


        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 10280
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ps push
#define pf push_front
#define mp make_pair
#define And &&
#define Or ||
#define inf INT_MAX
#define sz(name) name.size()
#define len(name) name.length()
#define ig cin.ignore()
#define sc(name) scanf("%d",&name)
#define ssc(name1,name2) scanf("%d%d",&name1,&name2)
#define sssc(name1,name2,name3) scanf("%d%d%d",&name1,&name2,&name3)
#define scl(name) scanf("%lld",&name)
#define sscl(name1,name2) scanf("%lld%lld",&name1,&name2)
#define ssscl(name1,name2,name3) scanf("%lld%lld%lld",&name1,&name2,&name3)
#define Sort(name) sort(name.begin(),name.end())
#define For(name,start,finish) for(int name=start;name<finish;name++)
#define Forr(name,start,finish) for(int name=start;name>=finish;name--)
#define fast_in_out ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


//int row[]={-1,0,1,0};
//int col[]={0,1,0,-1};

const ll N=1e3+10;
const ll M=1e9+7;

ll logx(ll a,ll b){return log(a)/log(b);}
ll Max(ll a,ll b){if(a>b)return a;return b;}
ll Min(ll a,ll b){if(a>b)return b;return a;}
ll big_mul(ll a,ll b,ll m){ll x=0,y=a%m;while(b>0){if(b&1)x=(x+y)%m;y=(2*y)%m;b>>=1;}return x%m;}
ll big_mod(ll a,ll b,ll m){ll x=1,y=a%m;while(b>0){if(b&1)x=(x*y)%m;y=(y*y)%m;b>>=1;}return x%m;}
ll Big_mod(ll a,ll b,ll m){ll x=1,y=a%m;while(b>0){if(b&1)x=big_mul(x,y,m);y=big_mul(y,y,m);b>>=1;}return x%m;}
ll mod_inverse(ll a,ll m){return big_mod(a,m-2,m);}  //a^-1 mod m = a^(m-2) mod m


int main()
{

    string str;
    cin>>str;


    bool flag=true;

    For(i,0,sz(str))
    {
        if((i+1)%2==1 And str[i]=='L')
        {
            flag=false;
            break;
        }

        if((i+1)%2==0 And str[i]=='R')
        {
            flag=false;
            break;
        }

    }

    if(flag==false)
        cout<<"No"<<endl;

    else
        cout<<"Yes"<<endl;

    return 0;
}


//cf 439 C
//cf 489 C
//cf 465 div 2 E
// cc sep17 fill the array

/*

1
3 1000000000
1231 1200
1000 800
1 100
*/


Measured memory_bytes: 256
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}
// import java.util.ArrayDeque

object Main extends App {
  val n = in.readInt

  case class edge(v:Int, d:Int)
  val tree = Array.fill(n)(mu.ListBuffer.empty[edge])

  Iterator.continually(in.readLine)
    .take(n-1)
    .map(_.split(" ").map(_.toInt))
    .foreach { case Array(v, u, d) =>
      new edge(u-1, d) +=: tree(v-1)
      new edge(v-1, d) +=: tree(u-1)
    }

  val colors = Array.ofDim[Int](n)
  val visit = Array.ofDim[Boolean](n)

  def dfs(v:Int, d:Int):Unit = {
    val stk = mu.Stack.empty[edge]
    // val stk = new ArrayDeque[edge]
    stk.push(new edge(v, d))

    while(!stk.isEmpty) {
      val v = stk.pop
      if(!visit(v.v)) {
        visit(v.v) = true
        colors(v.v) = v.d
        for(nv <- tree(v.v) if !visit(nv.v)){
          val d = (v.d + nv.d) % 2
          stk.push(new edge(nv.v, d))
        }
      }
    }
  }

  dfs(0,0)
  println(colors.mkString("\n"))
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

//メモ化再帰
int f[50];
int fib(int i)
{
    if (i == 0 || i == 1)
        return 1;

    if (f[i] != -1)
        return f[i];

    return f[i] = fib(i - 1) + fib(i - 2);
}

int main()
{
    rep(i, 50) f[i] = -1;
    int n;
    cin >> n;
    OP(fib(n));
}


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

int main(void){
    int a, b, ans;
    cin >> a >> b;

    if(a <= 5){
        ans = 0;
    }else if(a <= 12){
        ans = b / 2;
    }else{
        ans = b;
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
	int N;
	cin >> N;
	int A[N+5];
	rep(i,N) cin >> A[i];
	sort(A, A+N, greater<int>());

	int now = A[0];
	int i = 1;
	int j = 0;
	int b[2] = {0,0};
	while (i < N) {
		if (now == A[i]) {
			b[j] = now;
			j++;
			if (j == 2) break;

			now = A[i+1];
			i += 2;
		}
		else {
			now = A[i];
			i++;
		}
	}
	cout << (ll)b[0]*b[1] << endl;

return 0;
}


Measured memory_bytes: 3948
import collections

n = int(input())
p = [input() for i in range(n)]

c = collections.Counter(p)
m = c.most_common()
most = m[0][1]

answer = []

answer.append(m[0][0])

for i in range(len(m)-1):
    if m[i+1][1] == most:
        answer.append(m[i+1][0])
    else:
        break

for output in sorted(answer):
    print(output)

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

using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll LNF = __LONG_LONG_MAX__;

int main(){
    int D,T,S; cin >> D >> T >> S;
    cerr << D/S << "\t" << T << endl;
    if(1.0*D/S<=1.0*T) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main() {
  string S;
	int K,M;
  cin >>K;
  	cin >> S;
  std::string str =S;
  size_t size = str.length();
  
  if (size<=K){
    cout <<S<<endl;
  }
  else{
    std::string substr = S.substr(0, K);
    cout << substr <<std::flush;
    cout << "..." << endl;
  }
}

Measured memory_bytes: 3588
import sys
readline = sys.stdin.readline

def main():
    n = int(readline())
    w1 = readline().rstrip()
    l = w1[-1]
    words = set()
    words.add(w1)
    for _ in range(n-1):
        w = readline().rstrip()
        if w[0] == l and w not in words:
            l = w[-1]
            words.add(w)
        else:
            print('No')
            return
    
    print('Yes')


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    string S; cin >> S;
    bool okay = true;
    if (S.size() % 2 == 1) okay = false;
    for (int i = 0; i < S.size(); i += 2) {
        if (S[i] != 'h' || S[i + 1] != 'i') {
            okay = false;
        }
    }
    cout << (okay ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
MOD = 10**9 + 7

def restor_accumulation_max(accumulation_max: list, include_0: bool) -> list:
    '''累積Maxを復元する
    Maxには逆元が存在しないので、一意に復元することはできない
    復元値の候補を[begin, end)として定義される
 
    例: accumulation_max = [3, 4, 4, 8, 8]
        include_0 = Trueのとき
        -> [(3, 4), (4, 5), (0, 5), (8, 9), (0, 9)]
        include_0 = Falseのとき
        -> [(3, 4), (4, 5), (0, 5), (8, 9), (1, 9)]
    '''
    n = len(accumulation_max)
    res = []
    init = 0 if include_0 else 1
    max_ = init
    
    for i in range(n):
        if accumulation_max[i] > max_:
            res.append((accumulation_max[i], accumulation_max[i] + 1))
            max_ = accumulation_max[i]
        else:
            res.append((init, max_ + 1))
    
    return res

li_t = restor_accumulation_max(t, False)
li_a = restor_accumulation_max(a[::-1], False)[::-1]

ans = 1
for i in range(n):
    tmp = min(li_t[i][1], li_a[i][1]) - max(li_t[i][0], li_a[i][0])
    if tmp <= 0:
        ans *= 0
    ans *= tmp
    ans %= MOD
print(ans)

Measured memory_bytes: 98916
import java.util.*;

public class Main {

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        while (true)
        {
            int n = sc.nextInt();
            int s = sc.nextInt();
            if(n==0&&s==0)break;
            System.out.println(answer(n,s,-1));
        }
    }
    static int answer(int n,int s,int p)
    {
        if (n==0)return (s==0)?1:0;
        int ans =0;
        for(p++;p<=Math.min(s,9);p++)
        {
            ans +=answer(n-1,s-p,p);
        }
        return ans;
    }
}

Measured memory_bytes: 26032
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<vector>
#include<stdio.h>
typedef int long long ll;
using namespace std;

int main(){
    ll n,k;
    cin>>n>>k;
    
    vector<ll> h(n);
    for(ll i=0;i<n;i++){
        ll x;cin>>x;
        h[i]=x;
    }
    vector<ll> a(n);
    a[0]=0;
    for(ll i=1;i<n;i++){
        ll mi=(1ll<<32);
        for(ll j=i-1;j>=0&&j>=i-k;j--){
            mi=min((abs(h[i]-h[j])+a[j]),mi);
        }
        a[i]=mi;
    }
    
    cout<<a[n-1]<<endl;
    
    
    
   /* a[1]=abs(h[1]-h[0]);
    if(n==2){cout<<a[1];return 0;}
    for(int i=2;i<n;i++){
        a[i]=min((abs(h[i]-h[i-1])+a[i-1]),abs(h[i]-h[i-2])+a[i-2]);
    }
    cout<<a[n-1]<<endl;*/
    
    return 0;
}


Measured memory_bytes: 1792
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = sorted(inpl())
b = sorted(inpl())
c = sorted(inpl())
x = [0] * n
for i in range(n):
    x[i] = bisect.bisect_left(a,b[i])
xx = [0] * (n+1)
xx[0] = 0
xx[1] = x[0]
for i in range(1,n):
    xx[i+1] = xx[i] + x[i] 
# print(x,xx)
res = 0
for i in range(n):
    tmp = bisect.bisect_left(b,c[i])
    res += xx[tmp]
print(res)

Measured memory_bytes: 120416
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int m, f, b;
    cin >> m >> f >> b;

    if (b <= m) {
        cout << 0 << endl;
    } else if (m < b && b <= (m + f))  {
        cout << (b - m) << endl;
    } else {
        cout << "NA" << endl;
    }
}



Measured memory_bytes: 3200
import java.util.Scanner;
public class Main{
    public static boolean equal(Data d1[], Data d2[]){
    	for(int i = 0 ; i < d1.length ; i++){
    		if(!(d1[i].data.equals(d2[i].data)))
			return false;
	}
	return true;
    }
    public static void Merge(Data d[], int left, int mid, int right){
        int n1 = mid- left;
        int n2 = right - mid;
        Data L1[] = new Data[n1 + 1];
        Data L2[] = new Data[n2 + 1];
        for(int i = 0 ; i < n1 ; i++)
            L1[i] = new Data(d[left + i].data,d[left + i].num);
        for(int i = 0 ; i < n2 ; i++)
            L2[i] = new Data(d[mid + i].data,d[mid + i].num);
        L1[n1] = L2[n2] = new Data("",1000000001) ;
        int i = 0;
        int j = 0;
        for(int k = left ; k < right ; k++){
            if(L1[i].num <= L2[j].num){
                d[k].num = L1[i].num;
		d[k].data = L1[i].data;
                i++;
            }
            else{
                d[k].num = L2[j].num;
                d[k].data = L2[j].data;
		j++;
            }
        }
    }
    public static void MergeSort(Data d[], int left, int right){
        if(left+1 < right){
            int mid = (left + right)/2;
            MergeSort(d,left,mid);
            MergeSort(d,mid,right);
            Merge(d,left,mid,right);
        }
    }
    public static int partition(Data d[], int start, int end){
        long x = d[end].num;
        int i = start-1;
        for(int j = start ; j < end ; j++){
            if(d[j].num <= x){
                i++;
                Data tmp = new Data(d[j].data,d[j].num);
		d[j].data = d[i].data;
		d[j].num = d[i].num;
		d[i].data = tmp.data;
		d[i].num = tmp.num;
            }
        }
        Data tmp2 = new Data(d[end].data,d[end].num);
	d[end].data = d[i+1].data;
	d[end].num = d[i+1].num;
	d[i+1].data = tmp2.data;
	d[i+1].num = tmp2.num;
        return i+1;
    }
    public static void quicksort(Data d[], int start, int end){
        if(start < end){
            int q = partition(d,start,end);
            quicksort(d,start,q-1);
            quicksort(d,q+1,end);
        }
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	Data d1[] = new Data[n];
	Data d2[] = new Data[n];
	for(int i = 0 ; i < n ; i++){
		String data = sc.next();
		long num = sc.nextLong();
		d1[i] = new Data(data,num);
		d2[i] = new Data(data,num);
	}
	MergeSort(d1,0,n);
	quicksort(d2,0,n-1);
	if(equal(d1,d2))
		System.out.println("Stable");
	else
		System.out.println("Not stable");
	for(int i = 0 ; i < n ; i++)
		System.out.println(d2[i].data + " " + d2[i].num);
    }
}
class Data{
	String data;
	long num;
	Data(String data, long num){
		this.data = data;
		this.num = num;
	}
}


Measured memory_bytes: 123400
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[][] s = new String[h][w];
		String[] alf = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
		for(int i = 0 ; i < h ; i++) {
			for(int j = 0 ; j < w ; j++) {
				s[i][j] = sc.next();
			}
		}
		for(int i = 0 ; i < h ; i++) {
			for(int j = 0 ; j < w ; j++) {
				if(s[i][j].equals("snuke")) {
					System.out.println(alf[j] + (i + 1));
				}
			}
		}
	}
}

Measured memory_bytes: 21844
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);
  char s[n][51];
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
  }
  int alp_count[n][26];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      alp_count[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 51; j++) {
      if (s[i][j] < 'a' || s[i][j] > 'z') {
        break;
      }
      alp_count[i][s[i][j]-'a']++;
    }
  }
  int min;
  for (int i = 0; i < 26; i++) {
    min = 50;
    for (int j = 0; j < n; j++) {
      if (alp_count[j][i] < min) {
        min = alp_count[j][i];
      }
    }
    for (int j = 0; j < min; j++) {
      printf("%c", 'a'+i);
    }
  }
  printf("\n");

  return 0;
}

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


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

    vector<int> number(4);

    rep(i,4){//各桁の数を格納
        number[3-i] = abcd%10;
        abcd/=10;
    }

    int sum = 0;
    vector<string> opp(3);

    for(int i=0;i < (1 << 3); i++){
        sum = number[0];
        for(int j = 0;j < 3;j++){
            if((i >> j) & 1){
                sum += number[j+1];
                opp[j] = '+';
            }
            else{
                sum -= number[j+1];
                opp[j] = '-';
            }
        }

        if(sum==7){
            rep(i,3){
                cout << number[i] << opp[i];
            }
            cout << number[3] << "=7" <<endl;
            break;
        }
    }
    
}

Measured memory_bytes: 256
h,w=map(int,input().split())
g=[input() for _ in range(h)]
import numpy as np
from collections import *
a=0
for sx in range(h):
  for sy in range(w):
    if g[sx][sy]=='#': continue
    d=[[-1]*w for _ in range(h)]
    d[sx][sy]=0
    q=deque([(sx,sy)])
    while q:
      x,y=q.popleft()
      for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]:
        nx,ny=x+dx,y+dy
        if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]<0:
          d[nx][ny]=d[x][y]+1
          q.append((nx,ny))
    a=max(a,np.max(d))
print(a)

Measured memory_bytes: 27272
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	s = strings.Replace(s, "BC", "D", -1)
	ss := []byte(s)
	l := len(ss)
	cnt := 0
	sq := 0
	for i := 0; i < l; i++ {
		if ss[i] == 'A' {
			sq++
		} else if ss[i] == 'D' {
			cnt += sq
		} else {
			sq = 0
		}
	}
	fmt.Println(cnt)
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pi acos(-1)
#define mod 1000000007
#define all(x) x.begin(), x.end()
using namespace std;

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

    int tc = 1;
    //cin >>  tc;
    while(tc--){
        char ch;
        cin >> ch;
        if(ch >= 'a' && ch <= 'z'){
            cout << 'a';
        }else{
            cout << "A";
        }
    }
}



Measured memory_bytes: 3608
#include<stdio.h>
#include<string.h>
int main()
{
    long long int x,y,ans,i;
    char a[3],a1,a2;
    scanf("%lld",&x);
    scanf("%s",&a);
    scanf("%lld",&y);
    for(i=0;;i++)
    if(a[i]=='+')
    {
        ans=x+y;
        break;
    }
    else if(a[i]=='-')
    {
        ans=x-y;
        break;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
LL ans;
int main()
{
    int n,i,u,v;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
        ans+=(LL)i*(n-i+1);//i表示每次选择点的个数，(n-i+1)表示选择点集的可能数量。若无连线，全是孤立点，对应不同的连通分量。
    //printf("%lld\n",ans);
    for(i=1; i<n; i++)
    {
        scanf("%d%d",&u,&v);
        if(u>v)
            swap(u,v);//无向图，让边的节点，左小右大，方便处理
        ans-=(LL)u*(n-v+1);//乘法原理,等价于(u-1+1)*(n-v+1).u-1+1代表区间[1,u]内的节点个数.(n-v+1)代表区间[v,n]内的节点个数
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1732