akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
	static void Main(string[] args) {
		new Calc().Solve();
	}
	public class Calc {
		public Calc() { }
		public void Solve() {
			string A = Utils.ReadLine<string>();
			string B = Utils.ReadLine<string>();
			if (A.Length > B.Length) {"GREATER".WriteLine();return; }
			if (B.Length > A.Length) { "LESS".WriteLine();return; }
			for (int i = 0; i < A.Length; i++) {
				if(A[i]>B[i]) { "GREATER".WriteLine(); return; }
				if(A[i]<B[i]) { "LESS".WriteLine(); return; }
			}
			"EQUAL".WriteLine();
			return;
		}
	}
    

}
public static class Utils {
	public static T ReadLine<T>() {
		return (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
	}

	public static T[] ReadLine<T>(params char[] separators) {
		return Console.ReadLine()
			.Split(separators)
			.Where(_ => _.Length > 0)
			.Select(_ => (T)Convert.ChangeType(_, typeof(T)))
			.ToArray();
	}

	public static List<T> ReadLines<T>(int readCount) {
		List<T> rt = new List<T>();
		for (int i = 0; i < readCount; i++) {
			rt.Add(ReadLine<T>());
		}
		return rt;
	}

	public static string Docking<T>(this IEnumerable<T> s, int sequenceRange, Func<T, string> filter = null) {
		string str = "";
		int c = 0;
		foreach (var item in s) {
			str += filter == null ? item.ToString() : filter(item);
			c++;
			if (c == sequenceRange) break;
		}
		return str;
	}

	public static string Docking<T>(this IEnumerable<T> s, Func<T, string> filter = null) {
		return s.Docking(s.Count(), filter);
	}

	public static string RangeDocking<T>(this IEnumerable<T> s, int start, int end, Func<T, string> filter = null) {
		string str = "";
		end = end < s.Count() ? end : s.Count();
		var items = s.ToArray();
		for (int i = start; i < end; i++) {
			str += filter == null ? items[i].ToString() : filter(items[i]);
		}
		return str;
	}
	public static int IntParse(this string n) {
		return int.Parse(n);
	}


	public static void WriteLine(this object obj) {
		Console.WriteLine(obj);
	}
	public static void AddTo<T>(this T obj,List<T> list) {
		list.Add(obj);
	}
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){
      lint n,x,t;
      string s;
      cin>>n>>x>>t;
      lint ans;
    if(n%x==0)ans=(n/x)*t;
    else ans=(n/x+1)*t;
      cout<<ans<<endl;
  }
      
    
  

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

int main(){
	int n,p[200+2][3],ans;
	bool a[200+2][3];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			scanf("%d",&p[i][j]);
			a[i][j]=true;
		}
	}
	for(int i=0;i<3;i++){
		for(int j=0;j<n;j++){
			if(a[j][i])for(int k=j+1;k<n;k++){
				if(p[j][i]==p[k][i]){
					a[j][i]=false;
					a[k][i]=false;
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		ans=0;
		for(int j=0;j<3;j++){
			if(a[i][j])ans+=p[i][j];
		}
		printf("%d\n",ans);
	}
}

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

vector<long long> enum_divisors(long long n){
  vector<long long> res;

  for(long long i = 1; i * i <= n; i++){
    if(n % i == 0){
      res.push_back(i);
      if(n/i != i) res.push_back(n/i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}

int main(){
  long long n;
  cin >> n;

  const long long INF = 1e12;
  long long ans = INF;
  long long digit = 0;
  for(long long i = 1; i * i <= n; i++){
    digit = 0;
    if(n % i == 0){
      long long a = i;
      long long b = n / i;
      long long large = max(a,b);
      // cout << a << " " << b << endl;
      while(large != 0){
        large /= 10;
        digit ++;
      }
      ans = min(ans, digit);
    }
    
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
// D - Practical Skill Test
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,n) for(int i=0;i<(n);++i)

int main(){
	int H,W,D; cin>>H>>W>>D;

	int MAX = H * W;
	vi HH(MAX), WW(MAX), DD(MAX);

	rp(h, H) rp(w, W){ int a; cin>>a; HH[a-1] = h; WW[a-1] = w; }

	rp(pre, MAX-1){
		int now = pre + D;
		if(now > MAX-1) break;
		DD[now] = DD[pre] + abs(HH[pre] - HH[now]) + abs(WW[pre] - WW[now]);
	}

	int Q; cin>>Q;
	while(Q--){ int l,r; cin>>l>>r; cout<< DD[r-1] - DD[l-1] <<endl; }
}

Measured memory_bytes: 2176
n, m = map(int, input().split())
graph = list(input())
ans = [0] * n
sans = [0] * n
for i in range(n-1):
    if graph[i] == "A" and graph[i+1] == "C":
        ans[i] += 1
for j in range(n-1):
    sans[j+1] = sans[j] + ans[j]

for _ in range(m):
    j, k = map(int, input().split())
    print(sans[k-1] - sans[j-1])
    

Measured memory_bytes: 9204
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicInteger;

public class Main {
  public static void main(String[] args) throws Exception {
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      int n = Integer.parseInt(br.readLine());
      Map<String, AtomicInteger> map = new TreeMap<>();
      int max = 0;
      for (int i = 0; i < n; i++) {
        String s = br.readLine();
        AtomicInteger c = map.get(s);
        int val = 1;
        if (c == null) {
          map.put(s, new AtomicInteger(1));
        } else {
          val = c.incrementAndGet();
        }
        if (val > max) {
          max = val;
        }
      }
      for (Map.Entry<String, AtomicInteger> e : map.entrySet()) {
        if (e.getValue().get() == max) {
          System.out.println(e.getKey());
        }
      }
      System.out.flush();
    }
  }
}

Measured memory_bytes: 67176
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
inline int read()
{
    int s=0,f=1; char ch=getchar();
    while(!isdigit(ch) && ch!='-')ch=getchar();
    if(ch=='-')ch=getchar(),f=-1;
    while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
    return ~f?s:-s;
}


const int maxn=1e4+20;

inline int Ask(int x,int y)
{
    printf("? %d %d",x,y);
    cout<<endl;
    char ch;
    cin>>ch;
    return ch=='Y';
}

int main()
{
    int A=read(),B=read();
    if(A<=B)puts("Impossible"),cout<<endl;
    else
    {
	static int st[maxn],top;
	REP(i,0,A+B-1)
	{
	    if(!top || Ask(st[top],i))st[++top]=i;
	    else top--;
	}
	static int ans[maxn];
	
	REP(i,0,A+B-1)
	    ans[i]=Ask(st[top],i);
	printf("! ");
	REP(i,0,A+B-1)printf("%d",ans[i]);cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 724
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
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 mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BIncrementDecrement solver = new BIncrementDecrement();
        solver.solve(1, in, out);
        out.close();
    }

    static class BIncrementDecrement {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            in.voids();
            String s = in.string();
            int x = 0;
            int max = 0;
            for (char c : s.toCharArray()) {
                x += c == 'I' ? 1 : -1;
                max = Math.max(max, x);
            }
            out.println(max);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

        public void voids() {
            string();
        }

    }
}



Measured memory_bytes: 21972
import math

Input_list = [int(i) for i in input().split()]
A = Input_list[0]
B = Input_list[1]
H = Input_list[2]
M = Input_list[3]

A_angle = 2 * math.pi * (H + M/60.0) / 12.0
B_angle = 2 * math.pi * M / 60.0

R_A = [A*math.cos(A_angle), A*math.sin(A_angle)]
R_B = [B*math.cos(B_angle), B*math.sin(B_angle)]

L = ((R_A[0] - R_B[0])**2 + (R_A[1] - R_B[1])**2) ** 0.5
print(L)

Measured memory_bytes: 9468
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
int dy[] = { 1,0,-1,0 }, dx[] = { 0,-1,0,1 };
vector<string>v(2);
bool within(int x, int y) {
	return 0 <= x&&x < 2 && 0 <= y&&y < v[0].size();
}
int dfs(int x = 0, int y = 0, int p = -1) {
	dump(x, y, p);
	if (!within(x, y))return 1;
	auto a = v[x][y];
	int z;
	int block;
	rep(i, 0, 4) {
		int X = x + dx[i], Y = y + dy[i];
		if (!within(X, Y))continue;
		dump(a, v[X][Y]);
		if (a == v[X][Y]) {
			z = i;
		}
	}

	dump(z);
	if (x == 0 && y == 0) {
		if (z == 3)return 3 * dfs(x, y + 1, 1) % MOD;
		else if (z == 0)return 6 * dfs(x, y + 2, 2) % MOD;
	}
	else {
		if (z == 3) {// p=1
			if (p == 1)return 2 * dfs(x, y + 1, 1) % MOD;
			else return dfs(x, y + 1, 1) % MOD;
		}
		else if (z == 0) { // p=2,3
			if (p == 1)return 2 * dfs(x, y + 2, 2) % MOD;
			else return 3 * dfs(x, y + 2, 2) % MOD;
		}
	}

}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	rep(i, 0, 2)cin >> v[i];
	cout << dfs() % MOD << endl;
	return 0;
}

Measured memory_bytes: 256
import math
from fractions import gcd
import copy

# 0以上整数x「未満」の素数をリストに格納して返す
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0  # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]


n, p = map(int, input().split())
res = 1
if n == 1:
    print(p)
else:
    divide = math.ceil(pow(p, 1 / n))
    for i in reversed(range(2, divide + 1)):
        tmp = copy.copy(p)
        tmp_cnt = 0
        while tmp % i == 0 and tmp_cnt != n-1:
            tmp /= i
            tmp_cnt += 1
        if tmp_cnt == n-1:
            res = max(res, gcd(i, tmp))
    print(int(res))


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


int main() {
	int n;

	std::cin >> n;

	std::string s;

	std::cin >> s;

	int count = 1;

	for (size_t i = 0; i < s.length() - 1; i++)
	{
		if (s[i] != s[i + 1]) {
			count++;
		}
	}

	if (count == 0) {
		count++;
	}

	std::cout << count << std::endl;

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> anys;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(anys{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N;
	cin >> N;
	vector<ll> A(N), B(N);
	for(int i=0; i<N; i++) cin >> A[i];
	for(int i=0; i<N; i++) cin >> B[i];

	priority_queue<pair<ll, int>> que;
	for(int i=0; i<N; i++) que.push({B[i], i});

	ll ans = 0;
	while(!que.empty()){
		ll x = que.top().first;
		int n = que.top().second;
		que.pop();

		ll y = max(A[n], max(B[(n-1+N)%N], B[(n+1)%N]));
		ll z = B[(n-1+N)%N] + B[(n+1)%N];
		ll k = (x - y + z - 1) / z;
		ans += k;
		B[n] -= k * z;
		debug(n, x, B[n]);

		if(x - k * z < A[n]) {
			cout << -1 << endl;
			return 0;
		}
		if(x - k * z > A[n]) {
			que.push({B[n], n});
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 9456
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INF = 999999999;
const int MOD = (int)1e9 + 7;
const int EPS = 1e-9;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  int ans = 0;
  if (2*c<=(x>y?a:b)){
      ans = 2*c*max(x,y);
  }else if (a+b>2*c){
      int mn = min(x,y);
      x -= mn;
      y -= mn;
      ans = mn*2*c + x*a + y*b;
  }else{
      ans = x*a+y*b;
  }
  cout << ans << endl;



}

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


int main() {
    int a, b;
    cin >> a >> b;
    int maxx;
    maxx = max(a + (a - 1), b + (b - 1));
    maxx = max(maxx, a + b);
    cout << maxx << endl;
}


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

int main(){

  long long a, b, c, d, mx;
  cin>>a>>b>>c>>d;
  
  
  mx=max(a*c, b*d);
  mx=max(a*d, mx);
  mx=max(c*b, mx);
  
  cout<<mx<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  string s,str;
  cin>>s;
  int q;
  cin>>q;
  rep(i,q){
    int t;
    cin>>t;
    if(t==1)
      swap(s,str);
    else{
      int f;char c;
      cin>>f>>c;
      if(f==1)
        str+=c;
      else
        s+=c;
    }
  }
  reverse(all(str));
  str+=s;
  cout<<str<<endl;
}

Measured memory_bytes: 1128
#include <cmath>
#include <cstdio>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    double x1, y1, r1, x2, y2, r2;
    scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &r1, &x2, &y2, &r2);
    double distance = sqrt(pow(x1 - x2, 2.0) + pow(y1 - y2, 2.0));
    if (distance > r1 + r2) {
      puts("0");
    } else if (distance + r2 < r1) {
      puts("2");
    } else if (distance + r1 < r2) {
      puts("-2");
    } else {
      puts("1");
    }
  }

  return 0;
}

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

int main() {
  string s;
  cin >> s;
  string result;
  if (s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi") {
    result = "Yes";
  } else {
    result = "No";
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
while true
    n = gets.to_i
    break if n == 0
    
    list = gets.chomp.split(" ").map &:to_f
    average = list.inject(:+)/n
    
    d = 0.0
    list.each { |point| d += (point-average)**2 }
    
    d /= n
    puts d**0.5
end

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

for i in range(h):
    a[i].insert(0, "#")
    a[i].append("#")

a.insert(0, ["#"*(w+2)])
a.append(["#"*(w+2)])
for i in a:
    print("".join(list(map(str,i))))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 3.1415926536
int n,p;
vector<int> vec;
ll dp[55][5006];
ll solve(int ind ,ll sum)
{
    if (ind==n)
    {
        if (sum%2==p)
            return 1;
        return 0;
    }
    if (dp[ind][sum]!=-1)
        return dp[ind][sum];
    ll c=0;
    c=solve(ind+1,sum+vec[ind]);
    c+=solve(ind+1,sum);
    return dp[ind][sum]=c;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>p;
    memset(dp,-1,sizeof dp);
    vec.resize(n);
    for (int i=0; i<n; i++)cin>>vec[i];
        cout<<solve(0,0);
    return 0;
}



Measured memory_bytes: 2432
N, Y = map(int, input().split())

resx, resy, resz = (-1, -1, -1)
maxn = min(N, Y//10000)
for x in range(maxn+1):
    for y in range(N+1-x):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z

        if total == Y:
            resx, resy, resz = (x, y, z)
            break

print(resx, resy, resz)

Measured memory_bytes: 3060
#include<stdio.h>

int main(void)
{
	long long int n,a,min,i,d=0;
	scanf("%lld%lld",&n,&a);
	min=a;
	for(i=0;i<4;i++){
		scanf("%lld",&a);
		if(a<min)
			min=a;
		}
	if(n%min==0)
		d=-1;
		
	printf("%lld",n/min+5+d);
	return 0;
}

Measured memory_bytes: 128
#最小全域木問題、プリム法
from heapq import *
def solve():
    N = int(input())
    A = [list(map(int, input().split()))+[i] for i in range(N)]
    edge = [[] for _ in range(N)]
    A.sort()
    for i in range(N-1):
        w = min(abs(A[i+1][0]-A[i][0]),abs(A[i+1][1]-A[i][1]))
        edge[A[i][2]].append((w,A[i+1][2]))
        edge[A[i+1][2]].append((w,A[i][2]))
    A.sort(key=lambda x:x[1])
    for i in range(N-1):
        w = min(abs(A[i+1][0]-A[i][0]),abs(A[i+1][1]-A[i][1]))
        edge[A[i][2]].append((w,A[i+1][2]))
        edge[A[i+1][2]].append((w,A[i][2]))
    bridges = []
    heapify(bridges)
    used = [False]*N
    used[0] = True
    ans = 0
    for w,v in edge[0]:
        heappush(bridges,(w,v))
    while len(bridges)>0:
        w,v = heappop(bridges)
        if used[v]==False:
            ans += w
            used[v] = True
            for w,u in edge[v]:
                if used[u]==False:
                    heappush(bridges,(w,u))
    return ans
print(solve())

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

#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
#define mod 1000000007
#define random_jbt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

using namespace std;

string a,b;
int d[3010][3010];
string ans;

int main(){
    ios;
    cin>>a>>b;
    memset(d,0,sizeof(d));
    int n=a.size(),m=b.size();
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            d[i][j]=max(d[i-1][j],d[i][j-1]);
            if (a[i-1]==b[j-1])d[i][j]=d[i-1][j-1]+1;
        }
    }
    while(n>0 and m>0){
        if (a[n-1]==b[m-1]){
            ans.pb(a[n-1]);
            n--,m--;
            continue;
        }
        if (d[n][m-1]==d[n][m])m--;
        else n--;
    }
    reverse(all(ans));
    cout<<ans;
    return 0;
}


Measured memory_bytes: 36224
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 1
max_limit = 10 ** 18
for i in range(N):
  ans *= A[i]
  if ans > max_limit:
    ans = -1
    break

if ans > max_limit:
  print(str(-1))
else:
  print(str(ans))

Measured memory_bytes: 21636
#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;
int main()
{
  
  int n;
  for(;cin>>n,n!=-1;)
    {
      double x=1,y=1;   
      n-=2;
      for(;n--;)
	{
	  double X=-y,Y=x,d=sqrt(x*x+y*y);
	  x+=X/d;
	  y+=Y/d;    
	}
      cout<<fixed<<setprecision(2)<<x<<endl<<y<<endl;
    }
}

Measured memory_bytes: 1236
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define VI vector<int>
#define VL vector<lint>
#define VB vector<bool>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVL vector<VL>
#define rep(i, n) for(int i = 0 ; i < n ; i++)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int n;
    cin >> n;
    VI t(n);
    int sum = 0;
    rep(i, n){
        cin >> t[i];
        sum += t[i];
    }
    int m;
    cin >> m;
    rep(i, m){
        int p, x;
        cin >> p >> x;
        p--;
        cout << sum - (t[p] - x) << endl;
    }
}

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

using namespace std;

string str, str2, d;
int i;

int main(){

	cin >> str;

	for(i=0;i<str.size();i++){
		d=str.substr(i, 1);

		if(d == "D"){d = "A";}
		else if(d == "E"){d = "B";}
		else if(d == "F"){d = "C";}
		else if(d == "G"){d = "D";}
		else if(d == "H"){d = "E";}
		else if(d == "I"){d = "F";}
		else if(d == "J"){d = "G";}
		else if(d == "K"){d = "H";}
		else if(d == "L"){d = "I";}
		else if(d == "M"){d = "J";}
		else if(d == "N"){d = "K";}
		else if(d == "O"){d = "L";}
		else if(d == "P"){d = "M";}
		else if(d == "Q"){d = "N";}
		else if(d == "R"){d = "O";}
		else if(d == "S"){d = "P";}
		else if(d == "T"){d = "Q";}
		else if(d == "U"){d = "R";}
		else if(d == "V"){d = "S";}
		else if(d == "W"){d = "T";}
		else if(d == "X"){d = "U";}
		else if(d == "Y"){d = "V";}
		else if(d == "Z"){d = "W";}
		else if(d == "A"){d = "X";}
		else if(d == "B"){d = "Y";}
		else if(d == "C"){d = "Z";}

		str2 += d;
	}

	cout << str2 << endl;

	return 0;
}

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


int main() {

	int x, y;
	cin >> x >> y;
	int ans = 0;
	if (x == 1) {
		ans += 300000;
	}
	if (x == 2) {
		ans += 200000;
	}
	if (x == 3) {
		ans += 100000;
	}
	if (y == 1) {
		ans += 300000;
	}
	if (y == 2) {
		ans += 200000;
	}
	if (y == 3) {
		ans += 100000;
	}
	if (x == 1 && y == 1) {
		ans += 400000;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 2e9;

ll dist[505][505];

void warchall_floyd(int N){
    rep(k,N)rep(i,N){
        if(dist[i][k] == INF) continue;
        rep(j,N){
            if(dist[k][j] == INF) continue;
	        chmin(dist[i][j], dist[i][k]+dist[k][j]);
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
	cin >> h >> w;
    rep(i,10)rep(j,10) cin >> dist[i][j];
    warchall_floyd(10);
	ll ans = 0;
	rep(i,h)rep(j,w){
		int a;
		cin >> a;
		if(a == -1) continue;
		ans += dist[a][1];
	}
	cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;

ll modexp(ll base, ll exp, ll mod) {
	ll res = 1ll;
	base = base % mod;
	for(ll i=0ll; i<sizeof(ll)*8; i++) {
		if(exp%2ll == 1ll) {
			res = ((res%mod)*(base%mod))%mod;
		}
		base = ((base%mod)*(base%mod))%mod;
		exp = exp>>1ll;
	}
	return res%mod;
}

int main(int argc, char ** argv) {
	ll n, a, b;
	cin >> n >> a >> b;
	if(n == 1) {
		if(a!=b) cout << 0 << endl;
		else cout << 1 << endl;
		return 0;
	}
	if(a<b)
		cout << ((n-1)*b+a)-((n-1)*a+b)+1 << endl;
	else if(a == b)
		cout << 1 << endl;
	else
		cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <algorithm>
#define N 45
typedef long long ll;
template <typename T> inline void read(T &x) {
	x = 0; char c = getchar(); bool flag = false;
	while (!isdigit(c)) { if (c == '-')	flag = true; c = getchar(); }
	while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
	if (flag)	x = -x;
}
using namespace std;
int n, nn;
char A[N][N];
ll f[N][N][N];
ll dfs(int l, int r, int k) {
	if (l == r) {
		return 1;
	}
	if (~f[l][r][k])	return f[l][r][k];
	ll res = 0;
	for (register int x = l; x < k; ++x) {
		for (register int y = r; y > k; --y) if (A[x][y] == '1')	{
			for (register int p = x; p < k; ++p) {
				for (register int q = y; q > k; --q) {
					res += dfs(l, p, x) * dfs(p + 1, q - 1, k) * dfs(q, r, y);
				}
			}
		}
	}
	return f[l][r][k] = res;
}
int main() {
	memset(f, -1, sizeof(f));
	read(n), nn = n << 1;
	for (register int i = 1; i <= nn; ++i )
		scanf("%s", A[i] + 1);
	ll ans = 0;
	for (register int i = 2; i <= nn; ++i) if (A[1][i] == '1') {
		ans += dfs(2, nn, i);
	}
	printf("%lld\n", ans);
	return 0;
}

/*
3
011111
101111
110111
111011
111101
111110
//3

4
01111100
10011111
10011100
11101111
11110111
11111011
01011101
01011110
//6

8
0111101111111111
1011101111111111
1101101111011101
1110111111111111
1111011111110111
0001101111111111
1111110111011111
1111111011111111
1111111101111111
1111111110111111
1101110111011111
1111111111101111
1111011111110111
1111111111111011
1101111111111101
1111111111111110
//4762
*/

Measured memory_bytes: 896
#include <stdio.h>

int main(void)
{
	int h, w;
	int i, j;

	while (1) {
		scanf("%d %d", &h, &w);

		if (h == 0 && w == 0) {
			break;
		}
		for (i = 1; i <= h; i++) {
			for (j = 1; j <= w; j++) {
				if (i == 1 || i == h || j == 1 || j == w) {
					printf("#");
				}
				else {
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}


Measured memory_bytes: 2112
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

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

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

ll find_index(vector<ll> v, ll elm){
	vector<ll>::iterator it = find(v.begin(), v.end(), elm);
	ll index;
	if (it != v.end()){
		index = distance(v.begin(), it);
	}
	else{
		index = -1;
	}
	return index;
}

int main(){
	int N;
	cin >> N;
	string s, t;
	cin >> s >> t;
	int ans = 2 * N;
	for (int i = 0; i < N; i++){
		if (s.substr(i, N - i) == t.substr(0, N - i)){
			ans = N + i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    set<int> se1 = {1, 3, 5, 7, 8, 10, 12};
    set<int> se2 = {4, 6, 9, 11};
    int x, y;
    cin >> x >> y;
    if(se1.count(x) && se1.count(y)) {
        print("Yes");
    } else if(se2.count(x) && se2.count(y)) {
        print("Yes");
    } else if(x == y && x == 2) {
        print("Yes");
    } else {
        print("No");
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int h[n];
    for(int i = 0; i<n; i++)
        cin>>h[i];

    int dp[n];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    // cout<<dp[0]<<" "<<dp[1]<<"\n";
    for(int i = 2; i<n; i++){
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }
    cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 4400
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    int N; cin >> N;
    vector<long long> A(N+1);
    vector<long long> B(N);
    for (int i = 0; i < N+1; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }

    long long ans = 0;
    for (int i = 0; i < N; i++) {
        long long tmp = min(A[i], B[i]);
        ans += tmp;
        B[i] -= tmp;
        tmp = min(A[i+1], B[i]);
        A[i+1] -= tmp;
        B[i] -= tmp;
        ans += tmp;
    }
    cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  rep(i, n) cin >> a[i] >> b[i] >> c[i];

  vector<vector<int>> dp(n+1, vector<int>(3));
  rep(i, n) {
    dp[i+1][0] = max(dp[i][1] + a[i], dp[i][2] + a[i]);
    dp[i+1][1] = max(dp[i][2] + b[i], dp[i][0] + b[i]);
    dp[i+1][2] = max(dp[i][0] + c[i], dp[i][1] + c[i]);
  }
  int ans = max({dp[n][0], dp[n][1], dp[n][2]});
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9868
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToLong();
		
		var o = new List<long>();
		var m = PrimeFact(n);
		var keys = m.Keys.ToArray();
		var arys = m.Values.ToArray();
		//foreach(var key in m.Keys)
		for(int i = 0; i < keys.Length; i++)
		{
			var max = arys[i];
			for(int j = 1; j <= max; j++)
			{
				if(arys[i] < j)
					break;
				o.Add((long)Math.Pow(keys[i], j));
				arys[i] -= j;
			}
			//break;
		}
		o.Sort();
		long wa = 0;
		for(int i = 0; i < o.Count; i++)
		{
			if(n<o[i])
				break;
			if(n%o[i] == 0)
			{
				wa++;
			}
			
		}
		Console.WriteLine(wa);
	}
	
	static SortedDictionary<long, int> PrimeFact(long n) {
		var dic = new SortedDictionary<long, int>();
		
	    for (long i = 2; i*i <= n; i++) {
	        if (n % i == 0) {
	        	int j = 0;
	            while (n % i == 0) {
	                n /= i;
	                j++;
	            }
	            dic.Add(i, j);
	        }
	    }
	    if (n > 1) 
	    {
	    	if(!dic.ContainsKey(n))
	    		dic.Add(n, 1);
	    	else
	    		dic[n]++;
	    }
	    return dic;
	}
	
	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 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, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 28656
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func combination(n int) int {
	return (n * (n - 1)) / 2
}

func main() {
	n := scanInt()
	countTable := make(map[int]int, n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		num := scanInt()
		arr[i] = num
		countTable[num]++
	}
	total := 0
	combinationTable := make(map[int]int, len(countTable))
	for k, v := range countTable {
		combinationTable[k] = combination(v)
		total += combinationTable[k]
	}

	for _, e := range arr {
		ans := total - combinationTable[e] + combination(countTable[e]-1)
		fmt.Println(ans)
	}
}


Measured memory_bytes: 14976
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 10002;
// const int mo = 1e9 + 7;

int n;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	vector<vector<int> > g(n);

	for (int i = 1; i < n; ++i) {
		int u, v;
		cin >> u >> v;
		--u;
		--v;

		g[u].push_back(v);
		g[v].push_back(u);
	}

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

	sort(c.begin(), c.end());

	queue<int> qu;
	for (int i = 0; i < n; ++i) {
		d[i] = g[i].size();
		if (d[i] == 1) {
			d[i] = 0;
			qu.push(i);
		}
	}
	
	int ans = 0, idx = 0;
	vector<int> plan(n);

	while (!qu.empty() && idx < n) {
		int u = qu.front();
		qu.pop();
		
		plan[u] = c[idx];
		++idx;

		for (int i = 0; i < g[u].size(); ++i) {
			int v = g[u][i];
			--d[v];
			if (d[v] == 1) {
				d[v] = 0;
				qu.push(v);
			}
		}
	}

	for (int i = 0; i < n; ++i)
		for (int j = 0; j < g[i].size(); ++j)
			if (i < g[i][j])
				ans += min(plan[i], plan[g[i][j]]);

	cout << ans << endl;
	for (int i = 0; i < n-1; ++i)
		cout << plan[i] << " ";
	cout << plan[n-1] << endl;

	return 0;
}

Measured memory_bytes: 1024
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
C = input()

i = 0
w = deque()
r = deque()
for c in C:
    if c == 'W':
        w.appendleft(i)
    else:
        r.append(i)
    i += 1

ans = 0
while len(w) != 0 and len(r) != 0:
    ww = w.pop()
    rr = r.pop()
    if ww > rr:
        break
    ans += 1

print(ans)

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

using namespace std;

using int64 = long long;

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  // A枚を1円に交換して1円をB円に交換するべき

  if(A + 2 >= B) {
    cout << K + 1 << endl;
    return 0;
  }

  int64 ret = 1;
  for(int i = 1; i <= K; i++) {
    if(ret >= A && i + 1 <= K) {
      ret -= A;
      ret += B;
      ++i;
    } else {
      ++ret;
    }
  }

  cout << ret << endl;
}



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

using ll =  long long;
using pint =  pair<int,int>;

#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i))
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(x,v) for(const auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//lambda: [&](int x, int y){return x<y;}

signed main(void){
    int n;cin>>n;
    priority_queue<int> a;
    rep(i,n){
        int t;cin>>t;
        a.push(t);
    }
    int h=a.top();a.pop();
    while(!a.empty()&&a.top()!=h){
        h=a.top();
        a.pop();
    }

    if(a.empty()){
        cout << 0 << endl;
        return 0;
    }
    a.pop();
    int w=a.top();a.pop();
    while(!a.empty()&&a.top()!=w){
        w=a.top();
        a.pop();
    }
    if(a.empty()){
        cout << 0 << endl;
        return 0;
    }
    a.pop();
    cout << h*w << endl;


}


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

#define int long long
#define INF 1e18

const int N = 100 + 1;
int g[N][N], n, m;

bool FloydWarshall(){
   for(int k = 0; k < n; k++){
	   for(int i = 0; i < n; i++){
		  for(int j = 0; j < n; j++){
			  if (g[i][k] == INF || g[k][j] == INF) continue;
			  g[i][j] = min(g[i][j], g[i][k] + g[k][j]);   
		   }  
		}  
	 } 
   for(int i = 0; i < n; i++){
	    if (g[i][i] < 0 ) return false; 
	  }  // check for negative weight cycle	
   return true;
}

int32_t main(){
   	cin >> n >> m;
   	for(int i = 0; i < n; i++){
	  for(int j = 0; j < n; j++){
		   if (i == j) g[i][j] = 0;
		   else g[i][j] = INF;  
		}	
    }
    for(int i = 0; i < m; i++){
	  int x, y , val;
	  cin >> x >> y >> val;
	  g[x][y] = val;	
	}
   bool ok = FloydWarshall();
   if (ok){
	   for(int i = 0; i < n; i++){
		 for(int j = 0; j < n; j++){
			 if (j) cout << " ";
			 if (g[i][j] == INF) cout << "INF";
			 else cout << g[i][j]; 
		   }
		  cout << endl;  
		 }
	 }
   else cout << "NEGATIVE CYCLE" << endl;
}



Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int a[1000];
int b[8];
int main () {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i =0; i < n; i++) {
    int temp;
    cin >> temp;
    if (temp >= 3200) {
      cnt++;
    } else {
      b[temp / 400]++;
    }
  }
  int ans = 0;
  for (int i = 0; i < 8; i++) {
    if (b[i] != 0) {
      ans++;
    }
  }
  cout << max(1, ans) << " " << ans + cnt << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int sum, i, p,q = 0;

  for (i = 8; i >= 0; i--) {
    int t, j;
    t = 1;
    for (j = 0; j < i; j++) {
      t *= 10;
    }
    if (t > N) {
      continue;
    }
    
    p = (N - q)/t; // 桁の数字 1, 4, 8
    sum += p; //各桁数の合計
    q = (N/t) * t; //前までの数の合計 0, 100, 140となるべき
    //cout << p << endl;
  }

  if (N % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 200010
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const ll mod = 1e18 + 7;


int main (){
    ios_base::sync_with_stdio(false);
    set <int> s;
    int a, b, c;
    cin >> a >> b >> c;
    s.insert(a);
    s.insert(b);
    s.insert(c);

    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define IOS std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
using namespace std;

// DEBUG TEMPLATE
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}

void OFFLINE(){
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
        #define debug(x...) cout << "[" << #x << "] = ["; _print(x)
        #else
            #define debug(x...)
    #endif
}

const int MOD = 1e9 + 7;
const int N = 1e5 + 1;
vector<int> G[N];
vector<bool> vis(N, false);

void dfs(int src) {

    vis[src] = true;
    for(auto child : G[src]) {
        if(!vis[child]){
            dfs(child);
        }
    }
}

int main(){

    IOS;
    OFFLINE();
    //check for corner test cases

    int n, m;
    cin >> n >> m;

    int u, v;
    while(m--) {
        cin >> u >> v;
        G[u - 1].pb(v - 1);
        G[v - 1].pb(u - 1);
    }

    int cc_cnt = 0;
    for(int i = 0; i < n; i++){
        if(!vis[i]){
            cc_cnt++;
            dfs(i);
        }
    }

    cout << cc_cnt - 1 << "\n";

    //check for corner test cases
    return 0;
}

Measured memory_bytes: 9608
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>


using namespace std;


int gcd(int a, int b)
{
	if (a < b)
		return gcd(b, a);
	if (b == 0)
		return a;

	return gcd(b, a%b);
}

int main()
{
	int n;
	scanf("%d ", &n);
	for (int ww = 0; ww < n; ++ww)
	{
		char enc[1<<8+1];
		fgets(enc, sizeof(enc), stdin);
		enc[strlen(enc)-1] = '\0';

		bool isFound = false;
		for (int a = 3; ; ++a)
		{
			if (gcd(a, 26) != 1)
				continue;

			int da[26];
			for (int i = 0; i < 26; ++i)
				da[(a*i)%26] = i;
			for (int b = 0; b < 25; ++b)
			{
				int dt[26];
				for (int i = 0; i < 26; ++i)
					dt[i] = da[(i+b)%26];

				char dec[1<<8+1];
				for (int i = 0; enc[i] != '\0'; ++i)
				{
					char c;
					if (islower(enc[i]))
						c = dt[enc[i]-'a'] + 'a';
					else
						c = enc[i];
					
					dec[i] = c;
				}
				dec[strlen(enc)] = '\0';

				if (strstr(dec, "that") || strstr(dec, "this"))
				{
					puts(dec);
					isFound = true;
					break;
				}
			}
			if (isFound)
				break;
		}
	}

	return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main()
	{
		int N = GetInt();
		var L = new List<int>(2 * N);
		for(int i = 0; i < 2 * N; i++)
			L.Add(GetInt());
		L.Sort();

		int ans = 0;
		for(int i = 0; i < 2 * N; i += 2)
			ans += L[i];

		Console.WriteLine(ans);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 11220
import java.util.Scanner;
//import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int k = scan.nextInt();
		int s = scan.nextInt();
		int count = 0;
		for(int x=0; x<=k; x++){
			for(int y=0; y<=k; y++){
				if(s - x - y <= k && 0 <= s-x-y){
					count++;
				}
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 35632
#include <bits/stdc++.h>
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

typedef long long i64; 

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(void) {
  i64 a, b, k; 
  scanf("%lld %lld %lld", &a, &b, &k);
  i64 val = min(a, k);
  a -= val;
  k -= val;
  val = min(b, k);
  b -= val;
  k -= val;
  printf("%lld %lld\n", a, b);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
 
const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int a[3], b[3];
int c[4][4];
int x[4];

int main() {
    rep(i,3) cin >> a[i] >> b[i];
    rep(i,3) {a[i]--; b[i]--; }
    rep(i,3) {
        c[a[i]][b[i]] = 1;
        c[b[i]][a[i]] = 1;
    }
    rep(i,4) x[i] = i;
    do {
        bool ok = true;
        rep(i,3) {
            if (!c[x[i]][x[i+1]]) ok = false;
        }
        if (ok) {
            puts("YES");
            return 0;
        }
    } while (next_permutation(x, x+4));
    puts("NO");
}



Measured memory_bytes: 256