akhauriyash/Code-Regression huggingface dataset:
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0,d=0,e=0, ans = 0, x = 0, y = 0, z = 0, n = 0, m = 0, maxy = 0, mini = 9999, counter = 0, endp = 0, checker = 0;

std::vector <long long int> vec{}, vecsec{}, vecth{};
long long int iremono[100001], sec[100001];
long long int iremono2[100001], check[100001],xpo[10000001],ypo[10000001],hei[1000001];
std::vector<std::string>kinds{}, kaku{};
char maze[1000][1000];
int sx, sy;
int gx, gy;
vector<pair<long long int, long long int>>pairs;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
std::string output, output2, input, input2;
char re;
int starta, startb, enda, endb,ab;


unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

int H, W;//はんい
bool first=false;
int main() {
	cin >> a>>b;
	cin >> input;
	input[b - 1] = input[b - 1] + 32;
	cout << input << endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let a: Vec<u64> = (0..n).map(|_| read()).collect();

    let mut mul2 = Vec::new();
    let mut mul4 = Vec::new();
    let mut other = Vec::new();

    for i in a.iter(){
        if i % 4 == 0 {
            mul4.push(i);
        }else if i % 2 == 0{
            mul2.push(i);
        }else{
            other.push(i);
        }
    }

    if mul2.len() == 0 && mul4.len()+1 >= other.len() {
        println!("Yes");
    }else if mul2.len() != 0 && mul4.len() >= other.len() {
        println!("Yes");
    }else{       
        println!("No");
    }
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<pair<int,ll>>>;
using pp=pair<ll,pair<ll,ll>>;
#define MAX 1000000
#define MOD 1000000007
#define INF 1000000000000000000

void dfs(vector<vector<int>> &G,int v,vector<bool> &reach){
  reach[v]=true;
  for(auto nv:G[v]){
    if(reach[nv]==false){
      dfs(G,nv,reach);
    }
  }
}

int main(){
  int N,M;
  ll P;
  cin>>N>>M>>P;
  Graph G(N);
  vector<vector<int>> Gr(N);
  for(int i=0;i<M;i++){
    int A,B;
    ll C;
    cin>>A>>B>>C;
    A--;B--;
    C-=P;
    G[A].push_back(make_pair(B,C));
    Gr[B].push_back(A);
  }

  vector<ll> coin(N,-INF);
  coin[0]=0;
  vector<bool> visit(N);
  queue<int> q;
  q.push(0);
  for(int i=0;i<N;i++){
    for(int i=0;i<N;i++){
      visit[i]=false;
    }
    while(!q.empty()){
      int v=q.front();
      q.pop();
      for(auto e:G[v]){
        int nv=e.first;
        ll c=e.second;
        if(coin[nv]<coin[v]+c){
          coin[nv]=coin[v]+c;
          visit[nv]=true;
        }
      }
    }
    for(int i=0;i<N;i++){
      if(visit[i]==true){
        q.push(i);
      }
    }
  }

  if(!q.empty()){
    vector<bool> can_reach(N,false);
    dfs(Gr,N-1,can_reach);
    bool flag=true;
    while(!q.empty()){
      int v=q.front();
      q.pop();
      if(can_reach[v]){
        flag=false;
      }
    }

    if(flag){
      cout<<max<ll>(0,coin[N-1])<<endl;
    }else{
      cout<<-1<<endl;
    }
  }else{
    cout<<max<ll>(0,coin[N-1])<<endl;
  }
}


Measured memory_bytes: 4016
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

int main(){
	string S;
	cin >> S;
	bool Cf = false;
	for(int i = 0; i < S.size(); i++){
		if(S[i] == 'C'){
			Cf = true;
		}

		if(Cf == true && S[i] == 'F'){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;

  if(min(B,D) - max(A ,C) >= 0)cout << min(B,D) - max(A ,C) << endl;
  else cout << 0 << endl;
  return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> as(100001, 0);

  long long int sum = 0;

  for (int i = 0 ; i < n; ++i) {
    int a;
    cin >> a;
    ++as[a];
    
    sum += a;    
  }

  int q;
  cin >> q;

  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    
    int bc = as[b];
    as[b] = 0;

    as[c] += bc;

    sum += (c-b)*bc;
    cout << sum << endl;
  }

  return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

int main () {
  string s;
  cin >> s;
  rep (i, 3) {
    if (s[i] == s[i + 1]) {
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
}


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

const int maxn = 200005;

int a[maxn], sz[maxn], par[maxn];

int get(int x){
  if(par[x] == x)return x;
  else {
    return par[x] = get(par[x]);
  }
}

void unite(int x, int y){
  x = get(x);
  y = get(y);
  if(x == y)return;
  if(sz[x] < sz[y])swap(x, y);
  par[y] = x;
  sz[x] += sz[y];
}

int main(int argc, char const *argv[])
{
  int n, m;
  scanf("%d %d", &n, &m);
  for(int i = 1; i <= n; ++i){
    par[i] = i;
    sz[i] = 1;
  }
  for(int i = 0; i < m; ++i){
    int x, y;
    scanf("%d %d", &x, &y);
    unite(x, y);
  }
  int ans = 0;
  for(int i = 1; i <= n; ++i){
    if(get(i) == i){
      ans = max(ans, sz[get(i)]);
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5244
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    std::string s;
    std::cin >> s;
    int n = s.size(), b = 0;
    std::vector<int> memo(1 << 26, n);
    memo[0] = 0;
    for (int i = 0; i < n; i++) {
        int index = s[i] - 'a';
        b ^= 1 << index;
        int c = memo[b] + 1;
        for (int j = 0; j < 26; j++) {
            c = std::min(c, memo[b ^ (1 << j)] + 1);
        }
        memo[b] = std::min(memo[b], c);
    }

    int ret = memo[b] + 1;
    for (int i = 0; i < 26; i++) {
        ret = std::min(ret, memo[b ^ (1 << i)] + 1);
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 262660
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll A, B, C, D; cin >> A >> B >> C >> D;
    while(A>0){
        C -= B;
        A -= D;
    }
    if(C>0){
        cout << "No";
    }else{
        cout << "Yes";
    }
}

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

int main() {
  int n, i, v, alice = 0, bob = 0;
  vector<int> a;

  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> v;
    a.push_back(v);
  }

  sort(a.begin(), a.end(), greater<int>());

  for (i = 0; i < n; i++) {
    alice += a.at(i++);

    if (i >= n) {
      break;
    }

    bob += a.at(i);
  }

  cout << alice - bob << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif 
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) {
        // cout << "Case #" << tt - t << ": "; 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
const int N = 1e5 + 5;
vector<int> adj[N]; // adj[0], adj[1], ..., adj[N - 1]
int dp[N];
int longest_path(int v) {
    if (dp[v] != -1) {
        return dp[v];
    }
    int ans = 0;
    for (auto i : adj[v]) {
        ans = max(ans, longest_path(i) + 1);
    }   
    return dp[v] = ans;
}

void solve() {  
    int n, m;
    cin >> n >> m;
    fill(dp, dp + N, -1);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
    }   
    int mx = 0; 
    for (int i = 1; i <= n; ++i) {
        mx = max(mx, longest_path(i));
    }
    cout << mx;
}

Measured memory_bytes: 11888
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
if A1 < B1:
    A1, A2, B1, B2 = B1, B2, A1, A2

if A1*T1+A2*T2 == B1*T1+B2*T2:
    print('infinity')
    exit()

if (A1-B1)*T1 > (B2-A2)*T2:
    print(0)
    exit()

d = abs(A1*T1+A2*T2 - B1*T1-B2*T2)  # T1,T2が終わった後に開く距離
L = abs(A1-B1)*T1  # T1の間に開く距離
# print(d, L)

if L % d == 0:
    print(L//d*2)
else:
    ans = L//d*2+1
    print(ans)
    # if d*L//d <= L:
    #     ans += 1


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

class Prog
{
    public Prog() { }
    public static int Main()
    {
        new Prog().calc();
        return 0;
    }

    Scanner cin;

    public void calc()
    {
        cin = new Scanner();
        var x = cin.nextInt();
        if (x < 1200) Console.WriteLine("ABC");
        else Console.WriteLine("ARC");
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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(a>b){a=b;return 1;}return 0;}
void dump(){cout<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cout<<h<<", ";dump(forward<Ts>(t)...);}
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

void solve1();void solve2();
int main(){
  solve1();
  return 0;
}

void solve1(){

  ll n;
  cin>>n;
  vector<ll> a(n);
  cin>>a;

  vector<ll> sum(n+1);
  rep(i,n)sum[i+1]=sum[i]+a[i];

  ll ans =INF;
  for(int i=1;i<n;++i){
    ll left = sum[i];
    ll right = sum[n]-sum[i];
    chmin(ans,abs(left-right));
  }
  cout<<(ans)<<endl;

}

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

ll X;

ll pow_5(ll i){
    return i * i * i * i * i;
}

int main(){
    cin >> X ;

    for(int i = - 119; i < 200; i++){
        for(int j = - 119; j < 200; j++){
            if(pow_5(i) - pow_5(j) == X){
                cout << i <<" "<< j << endl;
                return 0; 
            }
        }
    }

}


Measured memory_bytes: 3636
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String[] input = br.readLine().split(" ");
        int N = Integer.parseInt(input[0]);
        int M = Integer.parseInt(input[1]);
        int[] A = new int[N+1];
        int[] votes = new int[N+1];

        for(int i = 1; i <= N; i++){
            A[i] = Integer.parseInt(br.readLine());
        }

        for(int i = 0; i < M; i++){
            int B = Integer.parseInt(br.readLine());
            for(int j = 1; j <= N; j++){
                if(A[j] <= B){
                    votes[j]++;
                    break;
                }
            }
        }

        int maxIndex = -1;
        int maxVotes = Integer.MIN_VALUE;
        for(int i = 1; i <= N; i++){
            if(maxVotes < votes[i]){
                maxVotes = votes[i];
                maxIndex = i;
            }
        }
        System.out.println(maxIndex);
    }
}


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

using lint = long long;

int main() {
    int N; lint K;
    cin >> N >> K;
    vector<lint> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

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

    int ans = 0;
    int lb = 0, ub = N;
    while (ub - lb > 0) {
        int mid = (lb + ub)/2;

        lint Kp_min = max(lint(0), K - a[mid]);
        lint Kp_max = K;

        vector<lint> ap = a;
        ap.erase(ap.begin() + mid);

        vector<vector<bool>> can(N, vector<bool>(K + 1, false));
        can[0][0] = true;
        for (int j = 1; j <= N - 1; j++) {
            for (int k = 0; k <= K; k++) {
                if (can[j - 1][k] == true) {
                    can[j][k] = true;
                }
                if (k - ap[j - 1] >= 0 and can[j - 1][k - ap[j - 1]] == true) {
                    can[j][k] = true;
                }
            }
        }

        bool need = false;
        for (int j = Kp_min; j < Kp_max; j++) {
            if (can[N - 1][j] == true) {
                need = true;
                break;
            }
        }
        
        if (need == true) {
            ub = mid;
        } else {
            lb = mid + 1;
        }
    }

    cout << lb << endl;
    return 0;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
#define GO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
const ll N = 2e5 + 2;
const ll Mod = 2520;

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

int main()
{
	GO;
	int n, m, k;
	cin >> n >> m >> k;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	vector<vec> a(n, vec(m, -1));
	auto dis = a;
	for(int i=0;i<n;i++)
		for (int j = 0; j < m; j++)
		{
			char c; cin >> c;
			a[i][j] = (c != '.');
		}
	queue<pair<int, int>> q;
	x1--; y1--;
	x2--; y2--;
	q.push({ x1,y1 });
	dis[x1][y1] = 0;
	while (!q.empty())
	{
		auto [i, j] = q.front();
		q.pop();
		for (int d = 0; d < 4; d++)
			for (int t = 1; t <= k; t++)
			{
				int ii = i + t * dx[d], jj = j + t * dy[d];
				if (ii == n || jj == m || ii < 0 || jj < 0 || a[ii][jj] || (dis[ii][jj] != -1 && dis[ii][jj] <= dis[i][j]))
					break;
				if(dis[ii][jj] == -1)
					dis[ii][jj] = dis[i][j] + 1, q.push({ ii,jj });
			}
	}
	cout << dis[x2][y2] << endl;
	return 0;
}

Measured memory_bytes: 20048
n = gets.to_i
n.times do
  prob = 0
  a = gets.split.map(&:to_i)
  gets.split.map(&:to_i).permutation(9).each do |b|
    score = [0, 0]
    (0..8).each do |i|
      score[a[i] > b[i] ? 0 : 1] += a[i] + b[i]
    end
    prob += 1.0 if score[0] > score[1]
  end
  prob /= (1..9).to_a.inject(:*)
  printf("%07f %07f\n", prob, 1 - prob)
end


Measured memory_bytes: 7352
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1]; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1]; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define pb(x) push_back(x)
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if ((a + b) % 2) cout << "IMPOSSIBLE";
	else cout << (a+b)/2;
}

Measured memory_bytes: 256
dx = (1, 0, -1, 0)
dy = (0, 1, 0, -1)

h,w = map(int, input().split())
board = []
for _ in range(h):
    s = input()
    board.append(list(s))
ans = 'Yes'
for i in range(h):
    for j in range(w):
        if board[i][j] == '.': continue
        adj = 0
        for k in range(4):
            yy = i+dy[k]
            xx = j+dx[k]
            if yy < 0 or yy > h-1: continue
            if xx < 0 or xx > w-1: continue
            if board[yy][xx] == '#': adj = 1
        if adj == 0: ans = 'No'
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-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(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    vector<ll>a(n),sums(n+1);
    map<ll,ll>mods;
    ll sum = 0;
    rep(i,n){
        cin >> a[i];
        sum += a[i];
        sum %= k;
        sums[i+1] = (sum-i-1)%k;
        sums[i+1] += k;
        sums[i+1] %= k;
    }
    ll ans = 0;
    for(int i = 1;i <= n;++i){
        ll top = i-1;
        ll bottom = max((ll)0,i-k+1);
        if(mods.count(sums[top]) == 1){
            mods[sums[top]]++;
        }else{
            mods[sums[top]] = 1;
        }
        if(bottom != 0){
            mods[sums[bottom-1]]--;
        }
        if(mods.count(sums[i]) == 1){
            ans += mods[sums[i]];
        }
    }
    cerr << "from here" << endl;
    rep(i,n){
        cerr << sums[i] << endl;
    }
    cerr << "to here" << endl;

    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 18728
n = int(input())
vvv = list(map(int, input().split()))

d = [{}, {}]
for i in range(n):
    if vvv[i] not in d[i%2].keys():
        d[i%2][vvv[i]]=1
    else:
        d[i%2][vvv[i]]+=1

li1 = [(v,k) for (k,v) in d[0].items()]
li2 = [(v,k) for (k,v) in d[1].items()]

if max(li1)[1] != max(li2)[1]:
    print(n - (max(d[0].values()) + max(d[1].values())))
else:
    v0 = d[0].pop(max(li1)[1])
    v1 = d[1].pop(max(li2)[1])
    
    if len(d[0])==0:
        dtmp0 = 0
    else:
        dtmp0 = max(d[0].values())
        
    if len(d[1])==0:
        dtmp1 = 0
    else:
        dtmp1 = max(d[1].values())
    print(n - max(v0 +dtmp1, dtmp0+v1))

Measured memory_bytes: 20520
// oh yea mr krabs
// REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
#include<bits/stdc++.h>
using namespace std;

const long long pi = (long long)104348/33215 ;
const long long maxn = 2e5+10 ;
const long long mod = 1e9+7 ;

long long a[maxn*10] ;
long long a2[maxn] ;
long long b[maxn] ;
long long n, k ;
long long ans ;

bool possible(long long e){

    long long cnt = 0 ;
    for(long long i = 0; i < n; i++){

        cnt += max(a[i]-e/b[i], 0ll) ;

    }
    if(cnt <= k)
        return 1 ;
    return 0 ;

}

long long bs(long long l, long long r){

    if(r-l<2)
        return l ;
    long long mid = (l+r)/2 ;
    if(possible(mid))
        return bs(l, mid) ;
    return bs(mid, r) ;

}

int main(){

    ios::sync_with_stdio(false) ;
    cin.tie(0) ;

    cin >> n >> k ;

    for(long long i = 0; i < n; i++){
        cin >> a[i] ;
    }
    for(long long i = 0; i < n; i++){
        cin >> b[i] ;
    }

    sort(a, a+n) ;
    sort(b, b+n, greater<long long>()) ;

    long long boi = bs(0, 1e12+1) ;

    if(!possible(boi))
        boi++ ;
    cout << boi ;

}


Measured memory_bytes: 5888
a, b, c = map(int, input().split())
k = int(input())
while k:
    if a >= b:
        b *= 2
    else:
        break
    k -= 1
while k:
    if b >= c:
        c *= 2
    else:
        break
    k -= 1
if a < b and b < c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    string a, b;
    cin >> a >> b;
    string c = a + b;
    int C = stoi(c);
    bool heihou = false;
    int count = 1;
    while (count <= sqrt(C)) {
        if (C == int(pow(count, 2.0))) {
            heihou = true;
            break;
        }

        count += 1;
    }

    if (heihou) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int num1, num2, num3;
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		
		if (a < b) {
			num1 = a;
			num2 = b;
		} else {
			num1 = b;
			num2 = a;
		}
		
		int c = in.nextInt();
		if (c < num1) {
			num3 = num2;
			num2 = num1;
			num1 = c;
		} else if (c > num2) {
			num3 = c;
		} else {
			num3 = num2;
			num2 = c;
		}

		System.out.println(num1 + " " + num2 + " " + num3);
	}
}

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

typedef long long ll;
typedef long double ld;
// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// use merge(all(vec1), all(vec2), vec3.begin()) to merge 2 vectors, use vec3.resize(vec1.size() + vec2.size()) first
// ll pos = partition_point(all(vec), pred) - vec.begin(); bool pred(ll a){return a<3};
// print number in binary -> cout << bitset<20>(n);

int main(){
	cin.tie(0);cin.sync_with_stdio(0);
	int l,r,d;cin>>l>>r>>d;
	int first=l/d+!!(l%d);
	int last=r/d;
	cout<<max(0,last-first+1)<<endl;
}


Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n, m, q;
    cin>>n>>m>>q;
    
    vector<vector<int>> v(600, vector<int>());
    rep(i,m){
        int l,r;
        cin>>l>>r;
        v[l].pb(r);
    }
    
    rep(i,600)sort(all(v[i]));
    
    rep(i,q){
        int ans = 0;
        int l,r;
        cin>>l>>r;
        for(int j=l;j<=r;j++){
            ans += upper_bound(all(v[j]), r) - v[j].begin();
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////

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

	vector<ll> A(M);
	rep(i, M) cin >> A[i];

	if (M == 1) {
		if (A[0] == 1) {
			cout << 1 << endl;
			cout << 1 << endl;
			cout << 1 << endl;
			return 0;
		}

		cout << A[0] << endl;
		cout << 2 << endl;
		cout << 1 << " " << A[0] - 1 << endl;
		return 0;
	}

	vector<ll> od;
	rep(i, M) { if (A[i] % 2 == 1) { od.push_back(i); } }

	if (od.size() > 2) { cout << "Impossible" << endl; return 0; }

	vector<ll> a;
	if (od.size() > 0) { a.push_back(A[od[0]]); }
	rep(i, M) {
		if (A[i] % 2 == 0) { a.push_back(A[i]); }
	}
	if (od.size() > 1) { a.push_back(A[od[1]]); }

	rep(i, M) { cout << a[i] << " "; }
	cout << endl;

	if (a[0] == 1) {
		cout << M - 1 << endl;
		for (ll i = 1; i < M-1; i++) { cout << a[i] << " "; }
		cout << a[M - 1] + 1 << endl;
		return 0;
	}

	cout << M << endl;
	cout << a[0] - 1 << endl;
	for (ll i = 1; i < M - 1; i++) { cout << a[i] << " "; }
	cout << a[M - 1] + 1 << endl;

	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define MAX 1000000007
#define MAXN 100005
bool sortby1column(vector<ll> &v1,vector<ll> &v2){
 return v1[0]<v2[0];
}


int main(){
	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  	int t=1;
	//cin>>t;
	while(t--){
        int x;
        cin>>x;
        int ans = (x/500)*1000;
        ans+=((x%500)/5)*5;
        cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
#!/usr/local/bin/python3
# https://atcoder.jp/contests/abc157/tasks/abc157_b
import numpy as np

def check(A, b):
    A = np.where(A == b, -1, A)
    return A

def bingo(A):
    for a in A:
        if a[0] == a[1] == a[2] == -1:
            return True
    for a in A.T:
        if a[0] == a[1] == a[2] == -1:
            return True
    if A[0][0] == A[1][1] == A[2][2] == -1:
        return True
    if A[0][2] == A[1][1] == A[2][0] == -1:
        return True
    return False



A = []
for _ in range(3):
    A.append(list(map(int, input().split())))
A = np.array(A)
N = int(input())
for _ in range(N):
    b = int(input())
    A = check(A, b)

# for i in range(3):
#     for j in range(3):
#         print(f"{A[i][j]} ", end="")
#     print("")

if bingo(A):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 27160
def main():
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    
    N,K=MI()
    a=LI()#下位の連続するn枚が不要なはず
    a.sort()
    for i in range(N):#K以上ならば必要
        if a[i]>=K:
            a=a[:i]
            break
    N=len(a)
                    
                    
    #x番目の数が必要かどうかの判定 
    #必要なものだけで構成された集合をもとに考えれば良いわけではない，不必要な分も考えなければならない             
    def ch(x):
        
        #使い回す，i番目まででjが作れるか
        dp=[0]*K
        dp[0]=1
        for i in range(N):
            if i==x:
                continue
            else:
                for j in range(K-1,a[i]-1,-1):
                    dp[j]|=dp[j-a[i]]
                
                        
        #K未満K-a[x]以上が作れれば良い    
        for j in range(K-a[x],K):
            if  dp[j]:
                return True
        return False
            
    
                        
    ng=-1
    ok=N
    while abs(ok-ng)>1:
        med=(ok+ng)//2
        
        if ch(med):
            ok=med
        else:
            ng=med
            
    print(ng+1)
    
    
 
    

main()


Measured memory_bytes: 39536
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/10/ALDS1_10_B
# 普通に難しい
# アイデアは写真の解説を参照

# データの入力
N = int(input())

for i in range(N):
    if i == 0:
        P = list(map(int, input().split()))
        continue
    P.append(int(input().split()[1]))

# dpテーブルの用意 minを取るときはinf埋めしておくと処理が楽になるしバグが見つかりやすい
INF = 2**32-1
dp = [[INF]*N for _ in range(N)]

# dpテーブルの初期化
# 対角成分0
for ij in range(N):
    dp[ij][ij] = 0

# dpの更新 どう更新しているのか、なんでこう更新するのかは写真を参照
for l in range(1, N):  # lは対角成分からいくつ離れているか (なん個行列をかけるかという解釈も可)
    for i in range(N):
        j = i+l
        if j >= N:
            continue
        for k in range(i, j):
            dp[i][j] = min(dp[i][k] + dp[k+1][j] + P[i]
                           * P[j+1]*P[k+1], dp[i][j])
# from pprint import pprint
# pprint(dp)
print(dp[0][-1])



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

int main() {
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	string ans = "";
	ans.push_back(s1[0] - 'a' + 'A');
	ans.push_back(s2[0] - 'a' + 'A');
	ans.push_back(s3[0] - 'a' + 'A');
	cout << ans << endl;
}

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

int main() {
	int r, D, x_2000;
	cin >> r >> D >> x_2000;

	int x_next;
	int x_now = x_2000;

	for (int i = 1;i < 10 + 1;++i) {
		x_next = r * x_now - D;
		cout << x_next << endl;
		x_now = x_next;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int a[8]={1,2,4,8,16,32,64,101};
  for(int i=0;i<7;i++){
    if(N>=a[i]&&N<a[i+1]){
      cout<<a[i]<<endl;
      break;
    }
  }
}


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

int main(void){
    rep(i,5){
        int x;
        cin >> x;
        if (x == 0) {
            cout << i + 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(ll i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll n;
  cin >> n;
  ll ans = 0;
  vector<int> vec(n+1, 0);
  reps(i, 1, n+1) {
    for(ll j = i; j <= n; j += i) {
      vec.at(j)++;
    }
  }
  reps(i, 1, n+1) {
    ans += i * vec.at(i);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 42220
#include <iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    int n; cin >> n; int r[200000];
    for (int i = 0; i < n; i++) {
        cin >> r[i];
    }
    int mx = -9999999999; int mn = r[0];
    for (int i = 1; i < n; i++) {
        mx = max(mx,(r[i] - mn));
        mn = min(mn, r[i]);
    }
    cout << mx << endl;
}


Measured memory_bytes: 3876
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a>=0&&b>=0){
		if(b==0) cout<<a+1<<endl;
		else if(a>b) cout<<a-b+2<<endl;
		else cout<<b-a<<endl;
	}
	else if(a>=0&&b<0){
		cout<<abs(abs(a)-abs(b))+1<<endl;
	}
	else if(a<0&&b>=0){
		if(b==0) cout<<abs(abs(a)-abs(b))<<endl;
		else cout<<abs(abs(a)-abs(b))+1<<endl;
	}
	else{
		if(a<b) cout<<b-a<<endl;
		else cout<<a-b+2<<endl;
	}
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000) 

def checkloop(pdict,product,inroute,made):
    inroute.append(product)
    if pdict[product][1] in made:
        return (False,product)
    elif pdict[product][1]==product:
        return (False,product)
    elif pdict[product][1] in inroute:
        return (True,pdict[product][1])
    else:
        return checkloop(pdict,pdict[product][1],inroute,made)

def daysopen(pdict,product,made,notsearched):
    if pdict[product][1] in made:
        made.append(product)
        notsearched.remove(product)
        return pdict[product][2]
    if pdict[product][1]==product:
        made.append(product)
        notsearched.remove(product)
        return pdict[product][0]
    else:
        made.append(product)
        notsearched.remove(product)
        return daysopen(pdict,pdict[product][1],made,notsearched)+pdict[product][2]
    
def daysloop(pdict,product,made,notsearched,inloop):
    inloop.append(product)
    if pdict[product][1] in inloop:
       # print inloop
        smallestdifference=100000
        smallestdifferenceitem=""
        for item in inloop:
            if smallestdifference>pdict[item][0]-pdict[item][2]:
                smallestdifference=pdict[item][0]-pdict[item][2]
                smallestdifferenceitem=item
        #gotsmallestitem
        days=pdict[smallestdifferenceitem][0]
        made.append(smallestdifferenceitem)
        notsearched.remove(smallestdifferenceitem)
        inloop.remove(smallestdifferenceitem)
        for item in inloop:
            made.append(item)
            notsearched.remove(item)
            days=days+pdict[item][2]
        return days
    else:
        return daysloop(pdict,pdict[product][1],made,notsearched,inloop)
    
while(1):
    N=int(raw_input())
    if N==0:
        break
    else:
        pdict={}
        notsearched=[]
        notcomplete=1
        made=[]
        days=0
        for i in range(N):
            indat=raw_input().split()
            pdict[indat[0]]=(int(indat[1]),indat[2],int(indat[3])) #name=(d1,sup,d2)
            notsearched.append(indat[0])
        while len(notsearched)!=0:
            #check if loop
            inroute=[]
            product=notsearched[0]
            #check if sup made
            if pdict[product][1] in made:
                days=days+pdict[product][2]
                made.append(product)
                notsearched.remove(product)
            else:
                [loopbool,loopstartpoint]=checkloop(pdict,product,inroute,made)
                if loopbool:
                    inloop=[]
                    days=days+daysloop(pdict,loopstartpoint,made,notsearched,inloop)
                else:
                    days=days+daysopen(pdict,product,made,notsearched)
        print days

Measured memory_bytes: 5168
import sys,heapq,math,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(RLIMIT_STACK)
  # setrlimit works on ubuntu (and atcoder), but not on WSL
  #resource.setrlimit(RLIMIT_STACK, (128*1024*1024,hard))

n = inn()
a = inl()
h = {} # defaultdict(int)
ddprint(n)
ddprint(a)
for x in a:
    h[x] = (1 if x not in h else h[x]+1)
b = list(h.keys())
x = a[0] if a[0]!=0 else a[1]
if len(h.keys()) == 3 and h[b[0]] == h[b[1]] and h[b[2]] == h[b[1]] and (b[0]^b[1])==b[2]:
    print('Yes')
elif len(h.keys()) == 2 and (b[0]==0 or b[1]==0) and h[0]*2 == h[x]:
    print('Yes')
elif len(h.keys()) == 1 and b[0]==0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 14612
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int to_int(string s) {
  int n=s.size();
  int ret=0;
  int b=1;
  revrep(i,n) {
    ret+=b*static_cast<int>(s[i]-'0');
    b*=10;
  }
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  string s;
  cin>>s;
  //cout << s.substr(5,2) << endl;
  int m=to_int(s.substr(5,2));
  int y=to_int(s.substr(0,4));
  //cout << "m="<<m<<",y="<<y<<endl;
  if(y==2019) {
    if(m<=4) {
      cout << "Heisei" << endl;
    } else {
      cout << "TBD" << endl;
    }
  } else if(y>2019){
    cout << "TBD" << endl;
  } else {
    cout << "Heisei" << endl;
  }
  return 0;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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; }

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

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

using pii = pair<int, int>;

int N;
const int maxV = 222222;
vector<pii> G[maxV]; // 頂点情報のみのグラフ

// treeDFS(親, 現在地, 根から現在地までの距離, 根からの最大の距離, 根から最大の距離となる頂点
void treeDFS(int from, int current, int dist, int &maxDist, int &maxVertex) {
    // 距離と終点を更新
    if (dist > maxDist) {
        maxDist = dist;
        maxVertex = current;
    }

    for (auto p : G[current]) {
			int to = p.first;
			int cost = p.second;
        // 逆流を防ぐ
        if (to == from) continue;
        treeDFS(current, to, dist + cost, maxDist, maxVertex);
    }
}

int getTreeDiameter() {
    int start = 0, end = 0, maxDist = 0;
    treeDFS(-1, start, 0, maxDist, end);
    start = end, end = 0, maxDist = 0;
    treeDFS(-1, start, 0, maxDist, end);
		return maxDist;
}

signed main() {
	cin >> N;
	rep (i, N-1) {
		int a, b, c;
		cin >> a >> b >> c;
		// a--, b--;
		G[a].push_back({b, c});
		G[b].push_back({a, c});
	}

	int dia = getTreeDiameter();
	cout << dia << endl;
	// int dia;
	// cin >> dia;
	
	// dbg(dia)
	// dia++;
	// puts(dia % 3 == 2 ? "Second" : "First");


	return 0;
}


Measured memory_bytes: 20784
n, k = map(int, input().split())
a = [int(input()) for _ in range(n)]
"""
b := ruisekiwa
b[r]-b[l] >= (r-l)k
b[r]-rk >= b[l]-lk (1-indexed)
c := b[i]-ik
"""
b = [0 for _ in range(n)]
b[0] = a[0]
for i in range(1, n):
	b[i] = b[i-1]+a[i]

c = [b[i]-(i+1)*k for i in range(n)]

"""
cr >= cl なる ペア(l, r)の個数を求めたい.
for i in range(n), find (i,j)
"""


class BIT:
	"""
	<Attention> 0-indexed.
	query ... return the sum [0 to m]
	sum ... return the sum [a to b]
	sumall ... return the sum [all]
	add ... 'add' number to element (be careful that it doesn't set a value.)
	search ... the sum version of bisect.right
	output ... return the n-th element
	listout ... return the BIT list
	"""
	
	def query(self, m):
		res = 0
		while m > 0:
			res += self.bit[m]
			m -= m&(-m)
		return res
	
	def sum(self, a, b):
		return self.query(b)-self.query(a)
	
	def sumall(self):
		bitlen = self.bitlen-1
		return self.query(bitlen)
	
	def add(self, m, x):
		m += 1
		bitlen = len(self.bit)
		while m <= bitlen-1:
			self.bit[m] += x
			m += m&(-m)
		return
	
	def search(self, a):
		tmpsum = 0
		i = 0
		k = (self.bitlen-1).bit_length()
		while k >= 0:
			tmpk = 2**k
			if i+tmpk <= self.bitlen-1:
				if tmpsum+self.bit[i+tmpk] < a:
					tmpsum += self.bit[i+tmpk]
					i += tmpk
			k = k-1
		return i+1
	
	def output(self, a):
		return self.query(a+1)-self.query(a)
	
	def listout(self):
		return self.bit
	
	def __init__(self, a):
		self.bitlen = len(a)+1
		self.bit = [0]*(len(a)+1)
		for i, j in enumerate(a):
			self.add(i, j)


def compress(arr):
	*XS, = set(arr)
	XS.sort()
	target = {e:i for i, e in enumerate(XS)}
	rtl = []
	for i in range(n):
		rtl.append(target[arr[i]])
	return rtl


d = compress(c)

bit = BIT([0 for _ in range(n)])
ans = 0
for i in range(n):
	bit.add(d[i], 1)
	ans += bit.query(d[i]+1)
	if c[i] < 0:
		ans -= 1
print(ans)


Measured memory_bytes: 109316
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        T = I()
        if T == 0:
            break
        t = LI()
        n = I()
        a = sorted([LI() for _ in range(n)])
        ad = collections.defaultdict(lambda: inf)
        for d,m in a:
            if ad[d] > m:
                ad[d] = m
        c = collections.defaultdict(lambda: inf)
        c[-1] = 0
        cd = 0
        for d in range(1,max(ad.keys()) + 1):
            m = ad[d]
            nt = 1
            nd = collections.defaultdict(lambda: inf)
            for k,v in c.items():
                if t[(k+nt) % T] <= m:
                    if nd[(k+nt) % T] > v:
                        nd[(k+nt) % T] = v
                if nd[0] > v+1:
                    nd[0] = v+1
            c = nd
            cd = d
        rr.append(min(c.values()))


    return '\n'.join(map(str,rr))


print(main())




Measured memory_bytes: 9064
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    int cnt = 0;
    i64 ss = 0;
    std::cin >> n;
    std::vector<i64> a(n), b(n), d(n);
    i64 sa = 0, sb = 0;
    for (int i = 0; i < n; i++) std::cin >> a[i];
    for (int i = 0; i < n; i++) std::cin >> b[i];
    for (int i = 0; i < n; i++) {
        sa += a[i];
        sb += b[i];
        d[i] = a[i] - b[i];
        if (a[i] < b[i]) {
            cnt++;
            ss += b[i] - a[i];
        }
    }

    if (sa < sb) {
        std::cout << -1 << std::endl;
        return 0;
    }

    std::sort(d.begin(), d.end(), std::greater<>());
    i64 sum = 0;
    int i = 0;
    while (sum < ss) {
        sum += d[i];
        i++;
        cnt++;
    }

    std::cout << cnt << std::endl;

    return 0;
}

Measured memory_bytes: 2560