akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main()
{
  int i,j;
  int c[3][3];
  for(i=0;i<3;i++)
    for(j=0;j<3;j++)
      cin >> c[i][j];
  if(c[0][0]-c[0][1]!=c[1][0]-c[1][1]
     ||c[0][0]-c[0][1]!=c[2][0]-c[2][1]
     ||c[0][0]-c[0][2]!=c[1][0]-c[1][2]
     ||c[0][0]-c[0][2]!=c[2][0]-c[2][2]
     ||c[0][0]-c[1][0]!=c[0][1]-c[1][1]
     ||c[0][0]-c[1][0]!=c[0][2]-c[1][2]
     ||c[0][0]-c[2][0]!=c[0][1]-c[2][1]
     ||c[0][0]-c[2][0]!=c[0][2]-c[2][2])
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}

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

int main(){
  int w,h,x,y,r;
  cin>>w>>h>>x>>y>>r;
  if(0 <= x-r && x+r <= w && 0 <= y-r && y+r <=h)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}



Measured memory_bytes: 3116
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main()
{
   int N;
   cin >> N;
   ll ans = 0;
   for (int i = 1; i < N; i++)
   {
      ans += (N - 1) / i;
   }
   cout << ans << endl;
   return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 51
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

vector<string> m;
int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

int main() {
    int h, w;
    cin >> h >> w;

    string s;
    for(int i=0; i<h; ++i){
        cin >> s;
        m.push_back(s);
    }

    for(int i=0; i<h; ++i) {
        for(int j=0; j<w; ++j) {
            if(m[i][j] == '.') {
                int cnt = 0;
                for(int k=0; k<8; ++k) {
                    if ( i+dy[k] >= 0 and i+dy[k] < h and j+dx[k] >= 0 and j+dx[k] < w) {
                        if(m[i+dy[k]][j+dx[k]] == '#') ++cnt;
                    }
                }
                m[i][j] = '0'+cnt;
            }
        }
    }

    for(int i=0; i<h; ++i) {
        cout << m[i] << endl;
    }
}



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.HashMap;

public class Main
{
    String s;
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();

	String ans = "";
	for(int i = 0; i < s.length(); i++) {
	    String c = String.valueOf(s.charAt(i));
	    if(!c.equals("B")) {
		ans += c;
	    } else {
		if(ans.length() > 0)
		    ans = ans.substring(0, ans.length() - 1);
	    }
	}
	
	out(ans);
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	s = sc.next();
    }

    void out()
    {
	
    }
    
    void out(int n)
    {
	System.out.println(n);
    }

    void out(double n)
    {
	System.out.println(n);
    }

    void out(long n)
    {
	System.out.println(n);
    }
    
    void out(char c)
    {
	System.out.print(c);
    }
    
    void out(String s)
    {
	System.out.println(s);
    }
}


Measured memory_bytes: 22868
#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    char a[20];
    int max1=0;
    scanf("%s",a);
    for(int i=0;i<strlen(a);i++)
    {
        int sum=0,j=i;
        while(a[j]=='A'||a[j]=='C'||a[j]=='G'||a[j]=='T')
        {
            sum++;
            j++;
        }
        max1=max(max1,sum);
    }
    printf("%d",max1);
    return 0;
}


Measured memory_bytes: 128
n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    #divisors.sort()
    return divisors

d1 = make_divisors(n)
d2 = make_divisors(n-1)

ans = 0
for k in d1:
    if k == 1:
        continue
    temp = n
    while temp%k == 0:
        temp //= k
    if temp%k == 1:
        ans += 1
ans += len(d2)-1
print(ans)


Measured memory_bytes: 3316
using System;
using System.Linq;
class c
{
    static void Main()
    {
        long n = long.Parse(Console.ReadLine());
        var k = new long[11];
        k[0] = 26;
        for (int i = 1; i < 11; i++)
        {
            k[i] = k[i - 1] + (long)Math.Pow(26, i + 1);
        }
        int L = 0;
        for (int i = 0; i < 11; i++)
        {
            if (k[i] < n) L = i + 1;
        }
        if (L >= 1) n = n - k[L - 1];
        n--;
        var ans = "";
        var num = new int[L + 1];
        for (int i = L; i >= 1; i--)
        {
            while (n - (long)Math.Pow(26, i) >= 0 && num[i] <= 25)
            {
                n -= (long)Math.Pow(26, i);
                num[i]++;
            }
        }
        num[0] = (char)(n );
        for (int i = 0; i <= L; i++)
        {
            ans += (char)(num[i] + 'a');
        }
        Console.WriteLine(string.Join("", ans.Reverse()));
    }
}

Measured memory_bytes: 28580
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
 string s,t;
 cin >> s >> t;
 if(t.length()==s.length()+1 && t.substr(0,s.length())==s)
 cout << "Yes";
 else
 cout << "No";
 return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){

    int x;
    cin >> x;
    x++;
    cout << x%2 << endl;
    
    return 0;
}

Measured memory_bytes: 3632
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

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

class SCC{
    public:
        int n, indexed;
        vector<bool> used;
        vector<int> cmp;
        vector<vector<int>> edge;
        vector<vector<int>> rev;
        vector<int> vs;

        SCC(int _n, int indexed)
            : n(_n + indexed), indexed(indexed), used(n), cmp(n),
            edge(n, vector<int>()), rev(n, vector<int>()) {}

        void add_edge(int u, int v){
            edge[u].push_back(v);
            rev[v].push_back(u);
        }

        void dfs(int v){
            if(used[v]){
                return;
            }
            used[v] = true;

            rep(i, (int)edge[v].size()){
                dfs(edge[v][i]);
            }
            vs.push_back(v);
        }

        void rdfs(int v, int k){
            if(used[v]){
                return;
            }
            used[v] = true;
            cmp[v] = k;

            rep(i, (int)rev[v].size()){
                rdfs(rev[v][i], k);
            }
        }

        int scc(){
            for(int v = indexed; v < n; v++){
                if(used[v]){
                    continue;
                }
                dfs(v);
            }

            used.assign(n, false);
            int k = 0;
            for(int i = vs.size()-1; i >= 0; i--){
                if(used[vs[i]]){
                    continue;
                }
                rdfs(vs[i], k++);
            }
            return k;
        }

        bool is_same(int u, int v){
            return cmp[u] == cmp[v];
        }
};

signed main(){
    int v, e;
    cin >> v >> e;

    SCC scc(v, 0);
    rep(i, e){
        int s, t;
        cin >> s >> t;
        scc.add_edge(s, t);
    }
    scc.scc();

    int q;
    cin >> q;
    rep(i, q){
        int u, v;
        cin >> u >> v;
        cout << (scc.is_same(u, v) ? 1 : 0) << endl;
    }

    return 0;
}



Measured memory_bytes: 4456
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

vector<ll> A;
vector<vector<int>> G;

ll countPairs(const vector<ll> &g) {
  ll sum = accumulate(g.begin(), g.end(), 0ll);
  ll mx = *max_element(g.begin(), g.end());
  return min(sum - mx, sum / 2);
}

ll dfs(int v, int p) {
  ll a = A[v];
  vector<ll> children;
  for (int u : G[v]) {
    if (u != p) {
      ll c = dfs(u, v);
      if (c < 0) {
        return -1;
      }
      children.push_back(c);
    }
  }
  if (children.empty()) {
    return a;
  }
  ll sum = accumulate(children.begin(), children.end(), 0ll);
  ll y = sum - a;
  ll x = a - y;
  if (x < 0 || y < 0 || countPairs(children) < y) {
    return -1;
  }
  return x;
}

int main() {
  int N;
  cin >> N;
  A.resize(N);
  G.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  ll v = dfs(0, -1);
  bool res = (G[0].size() > 1 ? v == 0 : v >= 0);
  cout << (res ? "YES" : "NO") << endl;
  return 0;
}


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

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define int long long
bool solve() {
    int N;
    cin >> N;
    if (N == 0) return false;
    vector<int> A(N);
    int sum = 0;
    REP(i, N) {
        cin >> A[i];
        sum += A[i];
    }
    int ans = 0;
    REP(i, N) {
        if (A[i] * N <= sum) ans++;
    }
    cout << ans << endl;
    return true;
}
signed main() {
    while (solve())
        ;
}


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

const int N = 2e5 + 7;

int n, q;
char c[N];
char a[N], b[N];
int dl, dr;

int die(int x) {
	for (int i = 1; i <= q; i++) {
		if (a[i] != c[x])
			continue;
		if (b[i] == 'R')
			x++;
		else
			x--;
		if (x == 0)
			return -1;
		if (x == n + 1)
			return 1;
	}
	return 0;
}

int main() {
	cin >> n >> q;
	for (int i = 1; i <= n; i++)
		cin >> c[i];
	for (int i = 1; i <= q; i++)
		cin >> a[i] >> b[i];
	int l = 0, r = n + 1, md;
	while (r - l > 1) {
		md = (r + l) / 2;
		if (die(md) == -1)
			l = md;
		else
			r = md;
	}
	dl = l;
	l = 0, r = n + 1, md;
	while (r - l > 1) {
		md = (r + l) / 2;
		if (die(md) == 1)
			r = md;
		else
			l = md;
	}	
	dr = r;
	if (dr <= dl)
		dr = dl + 1;
	cout << n - dl - (n - (dr) + 1);
	return 0;
}





























Measured memory_bytes: 768
import kotlin.math.pow
import kotlin.math.sqrt

fun main (args:Array<String>){
    val (point, standard) = readLine()!!.split(" ").map(String::toInt)
    var anscount = 0
    for(i in 1..point){
        val (pointX, pointY) = readLine()!!.split(" ").map(String::toDouble)
        val distanceFromOrigin = sqrt(pointX.pow(2) + pointY.pow(2))
        if(distanceFromOrigin <= standard){
            anscount++
        }
    }
    print(anscount)
}

Measured memory_bytes: 60336
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <iomanip>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }
template<typename V> void printVec(V v) {ll i=0;for(auto x : v){std::cout << " [" << i++ << "] " << x;} print();}

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

  std::string S;
  std::cin >> S;

  ll N = S.size();
  ll cntb0 = 0;
  ll cntb1 = 0;
  ll cntw0 = 0;
  ll cntw1 = 0;
  for (ll i = 0; i < N; i++){
    if (i % 2 == 0 && S[i] == '0') cntb0++;
    if (i % 2 == 1 && S[i] == '0') cntb1++;
    if (i % 2 == 0 && S[i] == '1') cntw0++;
    if (i % 2 == 1 && S[i] == '1') cntw1++;
  }

  ll ans = INF;
  ans = std::min(ans, cntb0 + cntw1);
  ans = std::min(ans, cntb1 + cntw0);

  print(ans);
  return 0;
}


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

int main() {

  // cin.tie(0);
  // ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  LL T1,T2,A1,A2,B1,B2;
  cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
  LL D1 = A1-B1, D2 = A2-B2;
  if(D1 > 0){
    D1 = -D1;
    D2 = -D2;
  }

  LL X = T1*D1, Y = T2*D2;

  if(D2 < 0){
    cout << 0 << endl;
  }else if(-X == Y){
    cout <<"infinity" << endl;
  }else if(X+Y < 0){
    cout << 0 << endl;
  }else{
    LL res = (-X)/(X+Y)*2 + (((-X)%(X+Y)==0)?0:1);
    cout << res << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optmize ("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define spIO ios::sync_with_stdio(false);cin.tie(0)
typedef long long ll;
typedef long double ld;
int a, b;
inline int f1(ld x)
{
	return int(x * 0.08);
}
inline int f2(ld x)
{
	return int(x * 0.1);
}
inline void solve()
{
	for (int i = 1; i <= 100000; i++)
	{
		ld x = i;
		if (f1(x) == a && f2(x) == b)
		{
			cout << i;
			return;
		}
	}
	cout << -1;
}
int main()
{
	spIO;
	cin >> a >> b;
	solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LiangJiaJun main
#define ll long long
using namespace std;
int n;
int ne,h[100004];
struct edge{
    int to,nt,w;
}e[400004];
ll dis[400004];
void add(int u,int v,int w){
    e[++ne].to=v;e[ne].w=w;
    e[ne].nt=h[u];h[u]=ne;
}
void dfs(int x,int fa){
    for(int i=h[x];i;i=e[i].nt){
        if(e[i].to==fa)continue;
        dis[e[i].to]=dis[x]+e[i].w;
        dfs(e[i].to,x);
    }
}
int LiangJiaJun(){
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        int u,v,w;scanf("%d%d%d",&u,&v,&w);
        add(u,v,w);
        add(v,u,w);
    }
    dfs(1,0);
    for(int i=1;i<=n;i++)printf("%lld\n",dis[i]&1);
    return 0;
}


Measured memory_bytes: 9600
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
ll n, ans = 0;

namespace FenwickTree {
	const int SIZE = 400010;
	int t1[SIZE], t2[SIZE];

	int lowbit(int x) { return x & (-x); }

	void add(int pos, int x, int t[]) { // 单点修改
		for (; pos <= n; pos += lowbit(pos)) {
			t[pos] += x;
		}
	}

	void add(int l, int r, int x, int t1[], int t2[]) { // [l, r] 区间＋x
		add(l, x, t1);
		add(r + 1, -x, t1);
		add(l, l * x, t2);
		add(r + 1, -x * (r + 1), t2);
	}

	int query_presum(int pos, int t[]) { // 单点查询，即对差分数组求前缀和
		int ans = 0;
		for (; pos > 0; pos -= lowbit(pos)) {
			ans += t[pos];
		}
		return ans;
	}

	int query_sum(int l, int r, int t1[], int t2[]) { // 区间修改下的区间查询
		int p1 = l * query_presum(l - 1, t1) - query_presum(l - 1, t2);
		int p2 = (r + 1) * query_presum(r, t1) - query_presum(r, t2);
		return p2 - p1;
	}
}
using namespace FenwickTree;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin >> n;
	vector<int> a(n + 1);
	vector<int> b(n + 1);
	for (int i = 1; i <= n; ++i) {
		cin >> a[i] >> b[i];
		int x = a[i] - a[i - 1];
		add(i, x, t1);
		add(i, i * x, t2);
	}
	for (int i = n; i; --i) {
		int res = (b[i] - query_sum(i, i, t1, t2) % b[i]) % b[i];
		ans += res;
		add(1, i, res, t1, t2);
	}
	cout << ans;
	return 0;
}

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

long long int dp[51][51][3000];
int n,a;
int x[51];

int main() {

    cin >> n >> a;

    for(int i=1; i<=n; i++){
        cin >> x[i];
    }

    dp[0][0][0] = 1;

    for(int i=1; i<=n; i++){
        for(int j=0; j<=i; j++){
            for(int k=0; k<=2500; k++) {
                if(k-x[i] >= 0 && j > 0){
                    dp[i][j][k] += dp[i - 1][j - 1][k - x[i]];
                }
                dp[i][j][k] += dp[i-1][j][k];
            }
        }
    }

    long long int ans = 0;

    for(int i=1; i<=n; i++){
        ans += dp[n][i][a*i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 59136
n=int(input())
l=[0]+list(map(int,input().split()))+[0]
ans=0
for a,s in zip(l,l[1:]):
    ans+=abs(a-s)
for i in range(n):
    a,s=sorted([l[i],l[i+2]])
    if a<=l[i+1]<=s:print(ans)
    else:
        print(ans-abs(a-l[i+1])-abs(l[i+1]-s)+s-a)

Measured memory_bytes: 13920
let k = cin.int
let s = cin.str

if s.count > k {
    print(s.prefix(k) + "...")
} else {
    print(s)
}

// MARK: #### 以下、ライブラリ ####

import Foundation
#if os(Linux)
    import Glibc
#else
    import Darwin.C
#endif

enum cin {
    // 123
    static var int: Int { Int(readLine()!)! }
    // 12 23
    static var pair: (Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!) }
    // 12 23 34
    static var triple: (Int, Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!, Int(line[2])!) }
    // AtCoder
    static var str: String { readLine()! }
    // At Coder
    static var arrayStr: [String] { str.components(separatedBy: " ") }
    // 1 2 3 4
    static var array: [Int] { str.components(separatedBy: " ").map { Int($0)! } }
    // 1
    // 2
    // 3
    static func v_array(count: Int) -> [Int] { (0..<count).map { _ in int } }
}

extension Int {
    // 123 -> [1, 2, 3]
    var digits: [Int] { Array(String(self)).map { Int(String($0))! } }
}

extension Array where Element == Int {
    // [2, 1, 3, 2] -> 8
    var sum: Int { self.reduce(0, +) }
    // [2, 1, 3, 2] -> [1, 2, 2, 3]
    var orderBy: [Int] { sorted() }
    // [2, 1, 3, 2] -> [3, 2, 2, 1]
    var orderByDesc: [Int] { sorted(by: { $0 > $1 }) }
    // [2, 1, 3, 2] -> [2, 1, 3]
    var distinct: [Int] { Array(Set(self)) }
}

precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence }
infix operator ^^ : PowerPrecedence
func ^^ (radix: Int, power: Int) -> Int {
    return Int(pow(Double(radix), Double(power)))
}

extension String {
    // e.g. cin.line.regex(match: "^(dream|dreamer|erase|eraser)*$")
    func regex(match pattern: String) -> Bool {
        let regex = try! NSRegularExpression(pattern: pattern)
        return regex.firstMatch(in: self, range: NSRange(location: 0, length: self.count)) != nil
    }
    // "ABC"[1] -> "B"
    subscript(i: Int) -> Character {
        get {
            self[index(at: i)]
        }
        set(char) {
            var characters = Array(self)
            characters[i] = char
            self = String(characters)
        }
    }
    func index(at offset: Int) -> String.Index { index(startIndex, offsetBy: offset) }
    // "ABC".swapAt(0, 1) -> "BAC"
    mutating func swapAt(_ index1: Int, _ index2: Int) {
        var characters = Array(self)
        characters.swapAt(index1, index2)
        self = String(characters)
    }
}


Measured memory_bytes: 12916
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775802
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, M, P;
	cin >> N >> M >> P;
	
	VI a(M), b(M), c(M), dis(N);
	REP(i, N)
		dis[i] = -LLINF;
	REP(i, M) {
		cin >> a[i] >> b[i] >> c[i];
		c[i] -= P;
	}
	dis[0] = 0;
	int tmp;
	REP(j,2*(N - 1)) {
		REP(i, M) {
			if (dis[a[i] - 1] == -LLINF)continue;
			if (a[i] == b[i] && c[i]>0)c[i]=LLINF;

//			cout << dis[b[i] - 1] << " " << dis[a[i] - 1] + c[i] << endl;

			if (c[i] == LLINF) {
				dis[b[i] - 1] = LLINF;
			}
			else if (dis[a[i] - 1] == LLINF) {
				dis[b[i] - 1] = LLINF;
			}
			else if (dis[b[i] - 1] < dis[a[i] - 1] + c[i]) {
				dis[b[i] - 1] = dis[a[i] - 1] + c[i];
				//cout << i << " " << c[i] << endl;
			}
			
			//cout << dis[0] << " " << dis[1] << " " << dis[2] << endl;
		}
		
		if (j == N - 2) {
			tmp = dis[N - 1];
			//cout << dis[N - 1] << endl;
		}

	}
	//cout << dis[N - 1] << endl;

	
	if(tmp!=dis[N-1] || dis[N-1]==LLINF){
		cout << -1 << endl;
	}
	else cout << max(0LL, dis[N - 1]) << endl;
	


	return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define REP(i,a,b) for(register int i=a;i<=b;++i)
#define DREP(i,a,b) for(register int i=a;i>=b;--i)
using namespace std;
int n,a;
int main(){
	scanf("%d%d",&n,&a);
	if((n%500)<=a)
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
from typing import List


if __name__ == "__main__":
    n, k = map(lambda x: int(x), input().split())

    target: List[int] = []
    v = (1 << k) - 1
    while (v < (1 << n)):
        target.append(v)
        x = v & -v
        y = v + x
        v = ((v & ~y) // x >> 1) | y
    target.sort()

    for d in target:
        print(f"{d}: ", end="")
        print(" ".join(str(j) for j in range(n) if d & (1 << j)))



Measured memory_bytes: 9140
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;


int main(){


    int N;cin>>N;
    LL t,a;cin>>t>>a;
    pair<LL,LL> vote(t,a);

    REP(i,N-1){
        cin>>t>>a;
        LL r1= (vote.first-1)/t +1;
        LL r2= (vote.second-1)/a +1;
        vote.first=max(r1,r2)*t;
        vote.second=max(r1,r2)*a;
    }
    cout<<vote.first+vote.second<<endl;

    return 0;
}

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

int main(){
  ll X,Y,A,B,C;
  cin >> X >> Y >> A >> B >> C;
  vector<ll> p(A),q(B),r(C);
  for(int i=0;i<A;++i) cin >> p[i];
  for(int i=0;i<B;++i) cin >> q[i];
  for(int i=0;i<C;++i) cin >> r[i];
  sort(p.begin(),p.end(),greater<ll>());
  sort(q.begin(),q.end(),greater<ll>());
  priority_queue<ll, vector<ll>, greater<ll>> Q;

  for(ll i=0;i<X;++i) Q.push(p[i]);
  for(ll i=0;i<Y;++i) Q.push(q[i]);

  for(ll i=0;i<C;++i){
    ll q = Q.top();
    if(q <= r[i]){
      Q.pop();
      Q.push(r[i]);
    }
  }
  ll ans=0;
  for(ll i=0;i<X+Y;++i) {
    ans += Q.top();
    Q.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 4724
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<deque>
using namespace std;

using ll = long long;
const int INF = 1001001001;

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

int main()
{
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import java.awt.Point;
import java.util.Arrays;
import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		new Main().mainrun();
	}

	private Scanner scan;
	private int W,H,ans,count;

	private int[][] F;
	private int[][]	vec_a = {{-1,-1},{-1,0},{0,1},{1,0},{1,-1},{0,-1}},	//偶数列
						vec_b = {{-1,0},{-1,1},{0,1},{1,1},{1,0},{0,-1}};	//奇数列

	private int[][] state;

	private HashMap<Integer,Boolean> stateMap;

	private Deque<Point> deque;

	private void mainrun() {

		scan = new Scanner(System.in);

		W = scan.nextInt();
		H = scan.nextInt();
		count = 0;

		deque = new LinkedList<>();

		stateMap = new HashMap<>();
		stateMap.put(0, false);

		F = new int[H + 2][W + 2];
		state = new int[H][W];
		ans = 0;

		Arrays.fill(F[0], 0);
		Arrays.fill(F[H + 1], 0);

		for(int i = 1;i < H + 1 ;i++) {
			F[i][0] = 0;
			F[i][W + 1] = 0;
			for(int j = 1;j < W + 1;j++) {
				F[i][j] = scan.nextInt();

				if(F[i][j] == 1) {
					ans++;
				}
			}
			Arrays.fill(state[i-1], 0);
		}

		for(int i = 1; i < H + 1;i++) {
			for(int j = 1;j < W + 1;j++) {
				if(F[i][j] == 0 && state[i-1][j-1] == 0) {
					count++;
					stateMap.put(count, true);

					state[i-1][j-1] = count;

					deque.add(new Point(j,i));
					Point p;

					while(!deque.isEmpty()) {
						p = deque.remove();
						putState(p.y,p.x);
					}
				}
			}
		}

		for(int i = 1; i < H + 1;i++) {
			for(int j = 1;j < W + 1;j++) {
				if(F[i][j] == 0 && stateMap.get(state[i-1][j-1])) {
					F[i][j] = 1;
					ans++;
				}
			}
		}

		ans *= 6;

		for(int i = 1; i < H + 1 ;i++) {
			for(int j = 1;j < W + 1;j++) {
				if(F[i][j] == 1) {
					ans -= aroundNum(i,j);
				}
			}
		}

		System.out.println(ans);

		scan.close();
	}

	private void putState(int y,int x) {
		int xx,yy;
		int[][] vec;

		if(y % 2 ==0) {
			vec = vec_a;
		}else {
			vec = vec_b;
		}

		for(int i = 0;i < 6;i++) {
			xx = x + vec[i][1];
			yy = y + vec[i][0];

			if(xx == 0 || yy == 0|| xx == W + 1 || yy == H + 1) {//範囲外
				stateMap.put(count, false);
				continue;
			}

			if(F[yy][xx] == 1|| state[yy-1][xx-1] != 0) {
				continue;
			}

			state[yy-1][xx-1] = count;
			deque.add(new Point(xx,yy));
		}
	}

	private int aroundNum(int y,int x) {
		int cnt = 0,xx,yy;
		int[][] vec;
		if(y % 2 == 0) {
			vec = vec_a;
		}else {
			vec = vec_b;
		}
		for(int i = 0;i < 6; i++) {
			xx = x + vec[i][1];
			yy = y + vec[i][0];
			if(F[yy][xx] == 1) {
				cnt++;
			}
		}
		return cnt;
	}
}



Measured memory_bytes: 39972
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Sum of product of pairs
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MOD = 1000000007;

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  int sum = 0, asum = 0;
  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    sum = (sum + (ll)asum * ai % MOD) % MOD;
    asum = (asum + ai) % MOD;
  }

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


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			(3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
template<class T> void chmax(T &a, const T &b){if(a<b)a=b;}
template<class T> void chmin(T &a, const T &b){if(a>b)a=b;}
void YN(bool b){cout<<(b?"YES":"NO")<<endl;}
void Yn(bool b){cout<<(b?"Yes":"No")<<endl;}
void yn(bool b){cout<<(b?"yes":"no")<<endl;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,nsub,s,sub;
	cin>>n>>s;
	ll i;
	for(i=2;i*i<=n;i++){
		nsub=n;
		sub=0;
		while(i<=nsub){
			sub+=(nsub%i);
			nsub/=i;
		}
		sub+=nsub;
		if(sub==s){
			cout<<i<<endl;
			return 0;
		}
	}
	i=n/i;
	for(;i>0;i--){
		if((n-s)>=i&&(n-s)%i==0){
			ll b=(n-s)/i+1;
			if(s-i<b&&s>=i&&s-i==n-i*b){
				cout<<b<<endl;
				return 0;
			}
		}
	}
	if(n==s){
		cout<<n+1<<endl;
		return 0;
	}
	cout<<-1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
long long fac[200030];
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (y == 0 || x == 1) return 1;
  if (x == 0) return 0;
  while (y > 0) {  
    if (y & 1) {
      res = (res*x) % p;  
    }
    y = y>>1;
    x = (x*x) % p;  
  }  
  return res;  
}
long long C(long long n, long long r) {
  if (!r) return 1;
  return (fac[n] * ( power( (fac[r]*fac[n-r]), MOD-2, MOD) ) ) %MOD;
}
int main() {
  int n,m,k;
  scanf("%d%d%d",&n,&m,&k);
  if (n==1) {
    printf("%d\n",m);
    return 0;
  }
  fac[0] = 1;
  for (int i = 1; i < 200010; i++) {
    fac[i] = (fac[i-1]*i)%MOD;
  }
  long long ans = 0;
  for (int i = 0; i <= k; i++) {
    ans = (ans+power(m-1,n-1-i,MOD)*C(n-1,i))%MOD;
  }
  printf("%lld\n",(ans*m)%MOD);
}

Measured memory_bytes: 5388
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

unordered_map<ll, ll> mp;

void solve() {
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = unordered_map<ll, ll>();
#pragma clang diagnostic pop
#endif

        int x = 0, n;
        int ans = 0;
        string s;
        cin >> n >> s;
        rep(i, n) {
            if (s[i] == 'I')x++; else x--;
            ans = max(x, ans);
        }
        cout << ans << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
typedef unsigned long ul;
typedef unsigned int ui;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ul N,i,a,cnt4,cnt2;

inline void solve(){
  IN(N);
  REP(i,N){
    IN(a);
    if(a%4==0)cnt4++;
    else if(a%2==0)cnt2++;
  }
  if(cnt2>=N||cnt4>=N/2||(N-cnt2<=2*cnt4))OUT("Yes");
  else OUT("No");
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.regex.Pattern
import java.util.{ArrayList, Collections, Comparator, List => JList}

import scala.math._
import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val s = input.toSeq.toVector
    val n = s.length - 1
    (0 until 1<<n).foldLeft(0L){(sum, bit) =>
      val newS = s(0) +: (1 to n).foldRight(Vector.empty[String]){(j, list) =>
        if ((1 & bit >> (j-1)) == 1) s";${s(j)}" +: list else s(j).toString +: list
      }.mkString
      sum + newS.split(""";""").map(_.toLong).sum
    }.toString
  }

  def divisors(n: Long): Vector[Long] = {
    val halfList = (1 to sqrt(n).toInt).toVector.filter(_ % n == 0).map(_.toLong)
    val reversedList = if (sqrt(n).floor == sqrt(n)) halfList.reverse.tail.map(n/_) else halfList.reverse.map(n/_)
    halfList ++ reversedList
  }

  def gcd(m: Long, n: Long): Long = n match {
    case 0 => m
    case _ => gcd(n, m % n)
  }
  def lcm(a: Long, b: Long): Long = a * b / gcd(a, b)

  val tests=List(
    """125""".stripMargin -> """176
                               |
                                    |""".stripMargin,
    """9999999999""".stripMargin -> """12656242944
                                     |""".stripMargin
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

Measured memory_bytes: 30840
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n;
  cin>>n;
  cout<<(n/2)*(n-n/2)<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3636
/*
    Author - Param Kothari
    Ah shit, here we go again
*/
 
/* Ordered Set Implementaton:

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;

typedef tree<
    int,
    null_type,
    less<int>,
    rb_tree_tag,
    tree_order_statistics_node_update>
ordered_set;
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair 
 
typedef long long ll;
typedef long double ld;

bool pal(string s){
    string t = s;
    reverse(s.begin(), s.end());
    return t == s;
}

void solve(){
    string s;
    cin >> s;
    int n = (int)s.size();
    if(pal(s) && pal(s.substr(0, n / 2)) && pal(s.substr((n / 2) + 1, n / 2))){
        cout << "Yes\n";
    }
    else cout << "No\n";
    return;
}
 
int main(){
    IOS;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  int c;
  c = N % 10;
  
  if(c == 3){
    cout << "bon" << endl;
  }
  
  else if(c == 0 || c == 1 || c == 6 || c == 8){
    cout << "pon" << endl;
  }
  
  else {
    cout << "hon" << endl;
  }
}
    

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

const int mod = 1e9+7;

int main() {
	int t = 1; 
	//cin>>t;
	while (t--) {
		int n;
		cin>>n;
		vector <ll> a(n);
		ll sum = 0, answer = 0;
		for (int i = 0; i < n; i++) {
			cin>>a[i];
			answer += a[i]*sum;
			answer %= mod;
			sum += a[i];
			sum %= mod;
		}
		cout<<answer;
	}
}
//9.2 x 10^18

Measured memory_bytes: 4828
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN

    double base = 0;
    ll a,b,c,d,e,f; cin>>a>>b>>c>>d>>e>>f;
    ll ans0 = 0;
    ll ans1 = 0;
    ll ans2 = 0;
    FOR(i,0, f/(100*a) + 1){
        FOR(j,0, f / (100*b) + 1){
            FOR(s, 0, f / c + 1){
                FOR(t, 0, f / d + 1){
                    if(i==0 && j==0) continue;
                    if (100*a*i + 100*b*j + c*s + d*t > f) continue;
                    if ((c*s+d*t) > ((a*i+b*j) * e)) continue;
                    if (base <= double(c*s+d*t) / double(a*i+b*j)){
                        base = double(c*s+d*t) / double(a*i+b*j);
                        ans0 = 100*a*i + 100*b*j + c*s + d*t;
                        ans1 = c*s + d*t;
                        ans2 = s + t;
                    }
                }
            }
        }
    }
    cout<<ans0<<' '<<ans1<<endl;
    // cout<<ans2<<endl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int n, m;
vvi adj(200001);
vector<bool> visited(200001);

int dfs(int src)
{
	if (visited[src])
		return 0;
	visited[src] = true;
	int res = 1;
	for (int a : adj[src])
		res += dfs(a);
	return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int maxcomp = 0;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	for (int i = 1; i <= n; i++)
	{
		int res = dfs(i);
		maxcomp = max(maxcomp, res);
	}
	cout << maxcomp << '\n';
}

Measured memory_bytes: 20308
import sys
from collections import deque
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
from itertools import combinations_with_replacement

n,m,x=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
ans=2<<32

for bit in range(2**n):
    now=bin(bit)[2:].zfill(n)[::-1]
    pricesum=0
    unds=[0]*m
    for i in range(n):
        if now[i]!="1":
            continue
        pricesum+=a[i][0]
        for j in range(m):
            unds[j]+=a[i][j+1]
    if min(unds)>=x:
        ans=min(ans,pricesum)

print(-1 if ans==2<<32 else ans)


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

int main() {
  int n, a;
  cin >> n;
  a = 0;
  
  for(int i = 1; i < 10; i++){
    for(int k = 1; k < 10; k++){
      if(i*k == n){
        a = 1;
      }
    }
  }
  
  if(a){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
      
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

ll MOD = 1000000007;

ll spow(ll a,ll p){
  if(p == 0) return 1;
  if(p == 1) return a;
  ll tmp = spow(a,p/2)%MOD;
  if(p%2 == 0) return tmp*tmp%MOD;
  else{
    ll ans = a*tmp%MOD;
    ans = ans*tmp%MOD;
    return ans;
  }
}

int main(){
  ll x,y;
  cin >> x >> y;
  if((x+y)%3 != 0){
    cout << 0 << endl;
    return 0;
  }
  ll a = (2*x-y)/3;
  ll b = (-x+2*y)/3;
  if(a < 0 || b < 0){
    cout << 0 << endl;
    return 0;
  }
  vector<ll> f(a+b+1,1);
  rep1(i,a+b) f[i] = (f[i-1]*i)%MOD;
  vector<ll> g(max(a,b)+1,1);
  rep1(i,max(a,b)) g[i] = spow(f[i],MOD-2);
  ll ans = f[a+b]*g[a]%MOD;
  ans = ans*g[b]%MOD;
  cout << ans << endl;
}

Measured memory_bytes: 8064
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

int main() {
    string S;
    cin >> S;

    int cnt = 0;
    int maxCnt = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
            cnt++;
        } else {
            cnt = 0;
        }
        maxCnt = max(cnt, maxCnt);
    }

    cout << maxCnt << endl;
    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll a,b;cin >> a >> b;
    cout << max(0LL,a-2*b) <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n;
  cin >> n;
  n %= 10;
  if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) cout << "hon" << endl;
  else if (n == 3) cout << "bon" << endl;
  else cout << "pon" << endl;
}


Measured memory_bytes: 3608
n = int(input())
a = [int(input()) for i in range(n)]
ff = [0] * n
fb = [0] * n
ff[0] = a[0]
for i in range(1, n):
    ff[i] = max(a[i], ff[i-1])
fb[n-1] = a[n-1]
for i in range(n-1)[::-1]:
    fb[i] = max(fb[i+1], a[i])
print(fb[1])
for i in range(1, n-1):
    print(max(ff[i-1], fb[i+1]))
print(ff[n-2])


Measured memory_bytes: 72664
import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 6)

def main():
    def dfs(i=0,oi=-1):
        for ki,w in to[i]:
            if ki==oi:continue
            ans[ki]=(ans[i]+w)%2
            dfs(ki,i)

    n=int(input())
    to=defaultdict(list)
    for _ in range(n-1):
        u,v,w=map(int,input().split())
        u,v=u-1,v-1
        to[u].append([v,w])
        to[v].append([u, w])
    ans=[-1]*n
    ans[0]=0
    dfs()
    for x in ans:
        print(x)
main()


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

int main() {
  
  int n, k, R, S, P;
  cin>>n>>k;
  cin>>R>>S>>P;
  string x;
  cin>>x;
  char y,z;
  ll ans = 0;
  
  rep(i, n) {
    y = x.at(i);
    if(i<k){
      if(y=='r') ans+=P;
      else if(y=='s') ans+=R;
      else ans+=S;
    }
    else{
      z = x.at(i-k);
      if(y=='r'){
        if(z=='r') x.at(i)='a';
        else ans+=P;
      }
      else if(y=='p'){
        if(z=='p') x.at(i)='a';
        else ans+=S;
      }
      else{
        if(z=='s') x.at(i)='a';
        else ans+=R;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3764
#include<stdio.h>
int main(){
	int a,b,i;
	i = 0;
	while(i < 3000){
		scanf("%d %d",&a,&b);
		if(a == 0 && b == 0) break;
		if(a > b) printf("%d %d\n",b,a);
		else{
			printf("%d %d\n",a,b);
		}
		i = i + 1;
	}
}



Measured memory_bytes: 2072