akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

using namespace std;
typedef long long ll;

const int MAXN = 3003;
const int MAXM = 3003;
const int MOD = 1e9+7;

int n,m;
int dp[MAXN][MAXM][2];

int ADD(ll a, ll b){
    return (a+b)%MOD;
}

int solve(int red, int m, bool z){
    int& r = dp[red][m][z];
    if(r == -1){
        if(m == 0){
            r = z;
        }else{
            r = 0;
            if(red){
                //RR
                if(red == 1) r = ADD(r, solve(red-1, m-1, true));
                else r = ADD(r, solve(red-1, m-1, z));
                //RB
                if(red == 1) r = ADD(r, solve(red, m-1, true));
                else r = ADD(r, solve(red, m-1, z));
            }
            if(n-red){ 
                //BR
                r = ADD(r, solve(red, m-1, z));
                //BB
                r = ADD(r, solve(red+1, m-1, z));
            }
        }
    }
    return r;
}

int main(){
    for(int i=0;i<MAXN;++i) for(int j=0;j<MAXM;++j) dp[i][j][0]=dp[i][j][1]=-1;
    scanf("%d%d", &n, &m);
    int sol = solve(0, m, true);
    for(int i=1;i<=n;++i){
        sol = ADD(sol, solve(i, m, false));
    }
    printf("%d\n", sol);
}


Measured memory_bytes: 70912
// Problem : C - Lamps
// Contest : AtCoder - Tokio Marine & Nichido Fire Insurance Programming Contest
// 2020 URL :
// https://atcoder.jp/contests/tokiomarine2020/tasks/tokiomarine2020_c Memory
// Limit : 1024 MB Time Limit : 2000 ms Powered by CP Editor
// (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define mk make_pair
#define fast                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define rep(i, a, b) for (ll i = a; i < b; i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x) (int)x.size()
#define mem(a, val) memset(a, val, sizeof(a))
#define deci(x) cout << fixed << setprecision(x);
#define bitcount(x) __builtin_popcountll(x)

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

const long long int mod = 1e9 + 7;
const long double EPS = 1e-12;
const int N = 2e5 + 20;

ll A[N], B[N];

void solve() {
  ll n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> A[i];
  while (k--) {
    for (int i = 1; i <= n; i++) {
      B[max(1ll, i - A[i])] += 1;
      B[min(n + 1, i + A[i] + 1)] -= 1;
    }
    bool flag = true;
    for (int i = 1; i <= n; i++) {
      B[i] += B[i - 1];
      A[i] = B[i];
      if (A[i] != n) flag = false;
    }
    for (int i = 0; i <= n + 1; i++) B[i] = 0;
    if (flag) break;
  }
  for (int i = 1; i <= n; i++) cout << A[i] << " ";
}
int main() {
  fast;
  ll t;
  t = 1;

  // cin>>t;

  while (t--) {
    solve();
  }

  return 0;
}


Measured memory_bytes: 6740
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = int_fast64_t;
using P = pair<i64,i64>;

int main(){
    int H,W;
    cin >> H >> W;
    vector<vector<char>> grid(H,vector<char>(W));
    int ans = 0;
    rep(h,H)rep(w,W){
        cin >> grid[h][w];
        if(grid[h][w] == '.') ans++;
    }

    vector<vector<bool>> visited(H,vector<bool>(W,false));
    vector<vector<P>> from(H,vector<P>(W));
    queue<P> que;
    que.push({0,0});
    visited[0][0] = true;

    const int d[4] = {1, -1, 0, 0};
    while(!que.empty()){
        P p = que.front();
        que.pop();

        int h = p.first;
        int w = p.second;

        for(int i = 0; i < 4; i ++){
            int nh = h + d[i];
            int nw = w + d[i^2];

            if(nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if(grid[nh][nw] == '#' || visited[nh][nw]) continue;

            visited[nh][nw] = true;
            from[nh][nw] = {h, w};
            que.push({nh, nw});
        }
    }

    if(visited[H-1][W-1] == false){
        cout << -1 << endl;
        return 0;
    }

    int h = H-1, w = W - 1;
    while(h != 0 || w != 0){
        ans--;
        P p = from[h][w];
        grid[h][w] = '$';
        h = p.first;
        w = p.second;
    } 
    ans--;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF=1<<30;
using vec = vector<vector<vector<vector<int>>>>;


int main(){
int h,w,n;
  cin>>h>>w>>n;
  int x,y;

  if(n%h==0) x = n/h;
  else x=n/h+1;
  if(n%w==0) y = n/w;
  else y=n/w+1;
  cout<<min(x,y)<<endl;
}

Measured memory_bytes: 256
n = int(input())
li = list(map(int,input().split()))
ans = 0

for i in range(n):
        li[i] -= i+1
li.sort()

if n%2 == 1:
        for i in range((n-1)//2):
                ans -= li[i]
        for i in range((n+1)//2, n):
                ans += li[i]
elif n%2 == 0:
        for i in range(n//2):
                ans -= li[i]
        for i in range(n//2,n):
                ans += li[i]

print(ans)


Measured memory_bytes: 26180
#include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++) 
using namespace std;
int dp[101][10001];
int main(){
    int n,w;
    cin>>n>>w;
    int v[n+1],a[n+1];
    r(i,1,n+1)cin>>v[i]>>a[i];
    r(i,1,n+1)r(j,1,w+1){
    	if(j<a[i])dp[i][j]=dp[i-1][j];
    	else dp[i][j]=max(dp[i-1][j],max(dp[i-1][j-a[i]]+v[i],dp[i][j-a[i]]+v[i]));
    }
    cout<<dp[n][w]<<endl;
}

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

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	set<int>ss;
	for (int i = 0; i < n; i++)cin >> a.at(i);
	sort(a.begin(), a.end());
	for (int i = 0; i < n - 1; i++) {
		if (a.at(i) == a.at(i + 1))ss.insert(a.at(i));
	}
	vector<bool>elt(1000010,true);
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		if (elt.at(a.at(i)) == true) {
			if(!ss.count(a.at(i)))ans++;
			for (int j = 1; j <= 1000009/a.at(i); j++) {
				elt.at(j*a.at(i)) = false;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5056
#include "bits/stdc++.h"

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
//int dx[] = { 1, 0 };
//int dy[] = { 0, 1 };
#define mod7 1e9+7;
#define mod9 1e9+9;

//int nextInt(){
//	int a;	cin >> a;return a;
//}
//string next(){
//	string s;cin >> s;return s;
//}
//char nextChar(){
//	char c;cin >> c;return c;
//}

unsigned long long strtoint(std::string str) {
	unsigned long long ret;
	std::stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

void solve(){
	int n;
	cin >> n;
	map<int,int> m;
	vector<int> v;
	rep(i,n){
		int a;
		cin >> a;
		if(m.find(a) == m.end()){
			m[a]++;
			v.pb(a);
		}
	}
	ssort(v);
	rev(v);
	P(v.size());
}

int main() {
	solve();
	return 0;
}


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

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
	ll r=1;
	a=a%m;
	while(b>0)
	{
		if(b&1)
		    r=(r*a)%m;
		b>>1;
		a=(a*a)%m;
	}
	return r%m;
}

int main(){
    ll h,w,n; cin>>h>>w>>n;
    if(w>h)swap(h,w);
    ll sum = 0,ans = 0;
    rep(i,0,w)
    {
        sum+=h;
        ans++;
        if(sum>=n)break;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))



def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

N=int(input())
if N==1:
    print(0)
    exit()
l=make_divisors(N)
ans=0
for i in range(1,len(l)):
    a,b=divmod(N,l[i]-1)
    if a==b:
        ans+=l[i]-1
print(ans)

Measured memory_bytes: 5336
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			final int N = scn.nextInt();
			//final int[] v = IntStream.generate(scn::nextInt).limit(N).toArray();

			System.out.println(
					IntStream.generate(scn::nextInt).limit(N)
							.sorted()
							.asDoubleStream()
							.reduce((a, b) -> (a + b) / 2)
							.getAsDouble());
		}
	}
}


Measured memory_bytes: 28628
import copy
from math import ceil
n, k = map(int, input().split())
A = list(map(int, input().split()))

ok = 100000000000
ng = 0


def cal(n):
    s = 0
    for a in A:
        s += ceil(a/n)-1
    return s


while ok-ng > 1:
    mid = (ok+ng)//2
    s = cal(mid)
    if s <= k:
        ok = mid
    else:
        ng = mid
print(ok)


Measured memory_bytes: 31820
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    vector<ll>mo;
    mo.pb(1);
    ll now6=1;
    while(1){
        now6*=6;
        if(now6>N){
            break;
        }
        mo.pb(now6);

    }

    ll now9=1;
    while(1){
        now9*=9;
        if(now9>N){
            break;
        }
        mo.pb(now9);

    }
    ll M=mo.size();
    vector<vector<ll>>dp(M+1,vector<ll>(N+1,INF));
    dp[0][0]=0;
    rep(i,M){
        dp[i+1][0]=0;
    }
    rep(i,M){
        rep(j,N+1){
            if(j-mo[i]>=0){
                dp[i+1][j] = min({dp[i][j],dp[i][j-mo[i]]+1,dp[i+1][j-mo[i]]+1});
            }else{
                dp[i+1][j]=dp[i][j];
            }
            
        }
    }

    /*rep(i,M+1){
        rep(j,N+1){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    cout << dp[M][N] << endl;


    return 0;
    

}

Measured memory_bytes: 14088
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        x: isize,
        n: isize,
        mut p: [isize; n],
    }
    p.sort();

    let mut ans = 0;
    let mut diff = 1000;
    for i in 0..=101 {
        if p.contains(&i) {
            continue;
        }
        if (x - i).abs() < diff {
            ans = i;
            diff = x - i;
        }
    }
    println!("{}", ans);
}


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

typedef long long ll;
const int N = 2000006;
const ll MOD = 1e9+7;

int n;
vector<int> adj[N];

int sz[N],par[N];

void dfs(int x,int p){
	par[x] = p;
	sz[x]++;
	for(int y:adj[x]){
		if(y!=p){
			dfs(y,x);
			sz[x]+=sz[y];
		}
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin>>n;
	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	dfs(1,1);
	vector<int> v;
	int t = n;
	ll cnt = 0;
	ll y = 0;
	while(t != par[t]){
		v.push_back(sz[t]-cnt);
		y += sz[t] - cnt;
		cnt = sz[t];
		t = par[t];
	}
	v.push_back(sz[t]-cnt);
	y += sz[t] - cnt;
	//cout<<v.size()<<endl;
	//for(int x:v){
	//	cout<<x<<" ";
	//}cout<<endl;
	
	ll x = 0;
	for(int i=0;i<(int)v.size()/2;i++){
		x += v[i];
	}
	
	if(x >= y-x){
		cout<<"Snuke"<<endl;
	}else{
		cout<<"Fennec"<<endl;
	}
	return 0;
}


Measured memory_bytes: 62456
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>

using namespace std;

#define P(a) (a) * (a)

typedef unsigned uint;
typedef long long Int;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }

int c[20], x[20500];
int dp[20500][256];
// dp[x][y]

int main()
{
	int n, m;
	while (cin >> n >> m, n && m){
		for (int i = 0; i < m; i++){
			cin >> c[i];
		}
		for (int i = 0; i < n; i++){
			cin >> x[i];
		}
		memset(dp, INF, sizeof(dp));

		dp[0][128] = 0;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < 256; j++){
				if (dp[i][j] == INF) continue;
				for (int k = 0; k < m; k++){
					int next = j + c[k];
					next = min(next, 255);
					next = max(next, 0);
					dp[i + 1][next] = min(dp[i + 1][next], dp[i][j] + P(x[i] - next));
					// cout << dp[i+1][next] << " ";
				}
				// puts("");
			}
		}

		int ret = INF;
		for (int j = 0; j < 256; j++){
			ret = min(ret, dp[n][j]);
		}
		cout << ret << endl;
	}

    return 0;
}

Measured memory_bytes: 21748
import java.util.*;

public class Main {
    public static void main(String[] args)
    {
        Scanner scan1 = new Scanner(System.in);
        int num = scan1.nextInt();
        String res = "No";

        for (int i = 0; i < 3; i++)
        {
            if ((num/(int)Math.pow(10, i)) % 10 == 7) {
               res = "Yes";
                break;
            }
        }
        System.out.println(res);

    }
}


Measured memory_bytes: 35624
def main():
    N = int(input())
    S = input()
    r = [0]
    g = [0]
    b = [0]
    for i in S:
        if i == 'R':
            r.append(r[-1]+1)
            g.append(g[-1])
            b.append(b[-1])
        if i == 'G':
            r.append(r[-1])
            g.append(g[-1]+1)
            b.append(b[-1])
        if i == 'B':
            r.append(r[-1])
            g.append(g[-1])
            b.append(b[-1]+1)
    rr = r[-1]
    gg = g[-1]
    bb = b[-1]
    ans = 0
    for i, v in enumerate(S[:-2], start=1):
        if v == 'R':
            for j, w in enumerate(S[i:-1], start=i+1):
                if w == 'G':
                    ans += bb - b[j]
                    if 2*j - i-1 < N and S[2*j - i-1] == 'B':
                        ans -= 1
                if w == 'B':
                    ans += gg - g[j]
                    if 2*j - i-1 < N and S[2*j - i-1] == 'G':
                        ans -= 1
        if v == 'G':
            for j, w in enumerate(S[i:-1], start=i+1):
                if w == 'R':
                    ans += bb - b[j]
                    if 2*j - i-1 < N and S[2*j - i-1] == 'B':
                        ans -= 1
                if w == 'B':
                    ans += rr - r[j]
                    if 2*j - i-1 < N and S[2*j - i-1] == 'R':
                        ans -= 1
        if v == 'B':
            for j, w in enumerate(S[i:-1], start=i+1):
                if w == 'R':
                    ans += gg - g[j]
                    if 2*j - i-1 < N and S[2*j - i-1] == 'G':
                        ans -= 1
                if w == 'G':
                    ans += rr - r[j]
                    if 2*j - i-1 < N and S[2*j - i-1] == 'R':
                        ans -= 1
    return ans
print(main())


Measured memory_bytes: 69456
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <random>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

    mt19937 engine(0);

    for (int i = 0; i < 365; i++) {
        uint32_t res = engine();

        cout << (res % 26) + 1 << endl;
    }

    return 0;
}

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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    ll r = n % (a + b);
    ll k = n / (a + b);
    if(r <= a){
        cout << k * a + r << endl;
    }else {
        cout << (k + 1) * a << endl;
    }
}


Measured memory_bytes: 256
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret

def solve():
    a, b = getList()
    if (b % a) == 0:
        print(a + b)
    else:
        print(b - a)

def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 65672
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

vector<int> G[100010];
int dpn[200010], dpc[200010];
 
signed main() {
    int V, E; cin >> V >> E;

    vector<int> visited(V, -1);
    for(int i=0; i<E; i++) {
        int u, v; cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    bool bipartite = true;
    int cnt0 = 0, cnt1 = 0, sum = 0, add = 0;
    function<void(int)> check = [&](int cur) {
        int c = visited[cur];
        for(auto to : G[cur]) {
            if(visited[to] >= 0) {
                bipartite &= (visited[to] == 1 - c);
            }
            else {
                visited[to] = 1 - c;
                (1 - c == 0 ? cnt0 : cnt1)++;
                check(to);
            }
        }
    };

    map<int, int> rec;
    for(int i=0; i<V; i++) {
        cnt0 = 0, cnt1 = 0;
        if(visited[i] >= 0) continue;
        visited[i] = 0; cnt0++;
        
        check(i);
        int val = abs(cnt0 - cnt1);
        sum += val * 2;
        add += min(cnt0, cnt1);
        rec[val]++;
    }

    if(!bipartite) {
        cout << -1 << endl;
        return 0;
    }

    fill(dpc, dpc + sum + 1, -1);
    fill(dpn, dpn + sum + 1, -1);
    dpc[0] = 0;
    for(auto e : rec) {
        int val, cnt; tie(val, cnt) = e;
        for(int i=0; i<=sum; i++) {
            if(dpc[i] >= 0) chmax(dpn[i], cnt);
            if(i + 2*val <= sum) chmax(dpn[i + 2*val], dpn[i] - 1);
            dpc[i] = -1;
        }
        swap(dpn, dpc);
    }

    int ans = 0;
    for(int i=0; i<=sum; i++) {
        if(dpc[i] < 0) continue;
        int A = i / 2 + add, B = V - A;
        chmax(ans, A * B - E);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 13336
#include <stdio.h>
#include <string.h>

int main() {
	char n[4];
	char* adr1;
	scanf("%s", n);
	// 7が含まれているかどうか
	adr1 = strchr(n, '7');
	if (adr1 == NULL) printf("No");
	else printf("Yes");
	return 0;
}

Measured memory_bytes: 1700
#include<bits/stdc++.h>
using namespace std;
#define F(i,L,R) for(int i=L;i<R;i++)
#define FE(i,L,R) for(int i=L;i<=R;i++)
#define RF(i,l,r) for(int i=r;i>l;i--)
#define RFE(i,l,r) for(int i=r;i>=l;i--)
#define getI(i) scanf("%d",&i)
#define getII(i,j) scanf("%d%d",&i,&j)
#define getIII(i,j,k) scanf("%d%d%d",&i,&j,&k)
#define VgetI(i) int (i);scanf("%d",&(i));
#define VgetII(i,j) int (i),(j);scanf("%d%d",&(i),&(j));
#define VgetIII(i,j,k) int (i),(j),(k);scanf("%d",&(i),&(j),&(k));
#define EoF(n) int(n);while(~getI(n))
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define abs(n) (n>0?n:(-n))
#define INF 2147483647
#define nINF -2147483648
int main(){
	char in[15];
	while(~scanf("%s",in)){
		printf("2018/");
		int l=strlen(in);
		F(i,5,l) printf("%c",in[i]);
		puts("");
	}
}


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

int main(){
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;

  printf("%c%c%c\n", toupper(s1[0]), toupper(s2[0]), toupper(s3[0]));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
using ll = long long;
int main() {
    int n;
    scanf("%d", &n);
    vector<int> l(n);
    rep(i, n) scanf("%d", &l[i]);
    if (n >= 3) {
        int count = 0;
        rep(i, n - 2) {
            for (int j = i + 1; j < n - 1; j++) {
                for (int k = j + 1; k < n; k++) {
                    ll a = l[i];
                    ll b = l[j];
                    ll c = l[k];
                    if (a != b && b != c && a != c) {
                        if (a + b > c && b + c > a && c + a > b) count++;
                    }
                }
            }
        }
        printf("%d\n", count);
    } else
        printf("%d\n", 0);
    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;
       
typedef long long lo;

template <class T> inline void read(T &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = getchar());
    if (f) x = -x;
}  
typedef unsigned long long ul;
const int N = 1e5 + 233;
int n, K;
struct perm_t {
    int a[N];
    perm_t() {
	fill(a, a + n + 1, 0);
    }
    int& operator [] (int x) {return a[x];}
    friend perm_t operator * (perm_t x, perm_t y) {
	perm_t ans;
	rep (i, n) ans[i] = x[y[i]];
	return ans;
    }
    perm_t inv() {
	perm_t p = *this, ans;
	rep (i, n) ans[p[i]] = i;
	return ans;
    }
    inline void read() {
	rep (i, n) cin >> a[i];
    }
    inline void write() {
	rep (i, n) cout << a[i] << " \n"[i == n];
    }
};
perm_t p, q, t, a[7];

perm_t power(perm_t a, int k) {
    perm_t ans;
    rep (i, n) ans[i] = i;
    for (; k; k >>= 1, a = a * a)
	if (k & 1) ans = ans * a;
    return ans;
}

int main(void) {
    read(n); read(K);
    p.read(); q.read(); t = q * p.inv() * q.inv() * p;
    t = power(t, (K - 1) / 6);
    a[1] = t * p * t.inv(); a[2] = t * q * t.inv();
    for (int i = 3; i <= 6; i++)
	a[i] = a[i - 1] * a[i - 2].inv();
    int ret = K - ((K - 1) / 6) * 6;
    a[ret].write();
}


Measured memory_bytes: 19200
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int dp[4010][4010];

int main(){
	string s, t;
	while(cin>>s>>t){
		rep(i, 4010) rep(j, 4010) dp[i][j] = 0;
		rep(i, s.size()){
			rep(j, t.size()){
				if(s[i]==t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
				else dp[i + 1][j + 1] = 0;
			}
		}
		int ans = 0;
		rep(i, s.size()+1) rep(j, t.size()+1) ans = max(ans, dp[i][j]);
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 64016
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i+=2){
		int c=0;
		for(int j=1;j<=i;j+=2){
			if(i%j==0)c++;
		}
		if(c==8)ans++;
	}
	cout<<ans<<endl;
		
	return 0;
}


Measured memory_bytes: 256
from sys import stdin
from sys import setrecursionlimit
import math
setrecursionlimit(10 ** 7)

n,m = map(int,stdin.readline().rstrip().split())
point = 0

for i in range(n):
    a,b = map(int,stdin.readline().rstrip().split())
    l = math.sqrt(a**2+b**2)
    if l <= m:
        point += 1

print(point)

Measured memory_bytes: 9192
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>





using namespace std;
int main() {
	
	int n, k;
	cin >> n >> k;
	int t = 0;

	for (int i = 0; i < n; i++) {
		t += i + k;
	}
	int ans = t;
	int r = 99999999;
	for (int i = 0; i < n; i++) {
		if (abs(t-(t - (i + k)))<abs(t-r)) {
			ans = t - (i + k);
			r = abs(t - (i + k));
			//cout << r << endl;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
R = []
B = []
for _ in range(N):
    R.append(list(map(int,input().split())))
for _ in range(N):
    B.append(list(map(int,input().split())))

count = 0
B = sorted(B)
for b in B:
    y_max = -1
    for i,r in enumerate(R):
        if r[0]<b[0] and r[1]<b[1] and y_max < r[1]:
            y_max = r[1]
            r_num = i
    if y_max != -1:
        R.pop(r_num)
        count += 1
print(count)

Measured memory_bytes: 3064
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Wed Feb  6 11:16:01 2019
//
package main

import "fmt"

func main() {
	var N, Y int
	fmt.Scan(&N, &Y)

	for i := 0; i <= N; i++ {
		for j := 0; i+j <= N; j++ {
			k := N - (i + j)
			if 10000*i+5000*j+1000*k == Y {
				fmt.Println(i, j, k)
				return
			}
		}
	}
	fmt.Println(-1, -1, -1)
}


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

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

int main(){
  int X, Y;
  cin >> X >> Y;
  
  for(int i = 0; i < X; i++){
    cin >> board[i];
  }
  
  for(int i = 0; i < X; i++){
	for(int j = 0; j < Y; j++){
	  if(board[i][j] == '.'){
	    int cnt = 0;
        for(int k = 0; k < 8; k++){
		  int x = i + dx[k];
          int y = j + dy[k];
          if(0 <= x && x < X && 0 <= y <= Y && board[x][y] == '#'){
            cnt++;
          }
        }
        board[i][j] = '0' + cnt;
      }
    }
  }
  
  for(int i = 0; i < X; i++){
	cout << board[i] << endl;
  }  
}


Measured memory_bytes: 256
n = int(input())
internal_AB = 0
B_A = 0
B_ = 0
_A = 0
for i in range(n):
    s = input()
    for j in range(len(s)-1):
        if s[j] == 'A' and s[j+1] == 'B':
            internal_AB += 1
    if s[0] == 'B' and s[-1] == 'A':
        B_A += 1
    elif s[0] == 'B':
        B_ += 1
    elif s[-1] == 'A':
        _A += 1
if _A == 0 and B_ == 0:
    ans = max(0,B_A - 1)
elif _A == 0 or B_ == 0:
    ans = B_A
else:
    if B_A > 0:
        ans = B_A +1 + min(_A-1,B_-1)
    else:
        ans = min(B_,_A)
print(ans + internal_AB)





Measured memory_bytes: 92612
import java.util.*
import kotlin.math.min

data class Edge(val to: Int, val fee: Int, val time: Int)
fun main() {
    val (n, m, s) = readLine()!!.trim().split(' ').map(String::toInt)
    val stations = List(n){mutableListOf<Edge>()}
    repeat(m){
        val (u, v, a, b) = readLine()!!.trim().split(' ').map(String::toInt)
        stations[u - 1].add(Edge(v - 1, a, b))
        stations[v - 1].add(Edge(u - 1, a, b))
    }
    val exchanger = List(n){
        val (c, d) = readLine()!!.trim().split(' ').map(String::toInt)
        c to d
    }
    val maxCost = stations.sumBy{ it.sumBy(Edge::fee) } / 2
    val minCost = Array(n){LongArray(maxCost + 1){Long.MAX_VALUE} }.also{it[0][min(s, maxCost)] = 0}
    val queue = PriorityQueue<Pair<Pair<Int, Int>, Long>>(compareBy(Pair<*, Long>::second)).also{it.add(Pair(0 to min(s, maxCost), 0))}
    while (queue.isNotEmpty()) {
        val (pair, time) = queue.poll()
        val (current, silver) = pair
        if (minCost[current][silver] != time) continue
        for ((next, fee, duration) in stations[current]) if (fee <= silver) {
            if (minCost[next][silver - fee] > time + duration) {
                minCost[next][silver - fee] = time + duration
                queue.add(Pair(next to silver - fee, time + duration))
            }
        }
        val (silverDiff, duration) = exchanger[current]
        if (minCost[current][min(silver + silverDiff, maxCost)] > time + duration) {
            minCost[current][min(silver + silverDiff, maxCost)] = time + duration
            queue.add(Pair(current to min(silver + silverDiff, maxCost), time + duration))
        }
    }
    println(
        minCost.drop(1).joinToString("\n"){it.min()!!.toString()}
    )
}


Measured memory_bytes: 69232
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;


signed main(){
    string t; cin >> t;
    rep(i,t.size()){
        if(t[i]=='?'){
            t[i]='D';
        }
    }
    cout << t << endl;
}


Measured memory_bytes: 3756
#include<bits/stdc++.h>
#define ll     long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll ll,ll ll>
#define all(v) (v).begin(), (v).end()
using namespace std;

void solve()
{
    ll n,x,t;
    cin>>n>>x>>t;
    cout<<(n+x-1)/x*t;

}
int main()
{



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

    ll TESTS = 1;
    // cin >> TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int x;
  x = 0;
  
  for (int i = 0; i < N; i++) {
    int D1i, D2i;
    cin >> D1i >> D2i;
    
    if (D1i == D2i) {
      x = x + 1;
    }
    else {
      x = 0;
    }
    
    if (x == 3) {
      cout << "Yes" << endl;
      break;
    }
    
    if (i == N-1 && x != 3) {
      cout << "No" << endl; 
    }
          
  }
}

Measured memory_bytes: 3624
def main():
    N, M = map(int, input().split())
    A_list = [A for A in input().split()]
    A_list = list(map(int, A_list))
    A_list.sort(reverse = True)

    value_sum = float(sum(A_list))
    fourM = float(4 * M)
    i_cycle = 0
    for Ai in A_list :
        i_cycle = i_cycle + 1
        #print(1 / fourM)
        if Ai / value_sum >= (1 / fourM) and i_cycle <= M :
            if i_cycle == M :
                print("Yes")
                break
        #elif Ai / value_sum < (1 / fourM) and i_cycle <= M :
        #    print("No")
        #    break
        else :
            print("No")
            break

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define F first
#define S second
//cout<<fixed<<setprecision(11);
const string nl="\n";
const ll MOD=1e9+7;
const ll ARR_MAX = 1e5+1;
const ll VAL_MAX = 1e5+1;
const ll INF=1e14;

void solve(){
    int n;cin>>n;
    string s,t;
    cin>>s>>t;
    for(int i=0;i<n;i++){
    	cout<<s[i]<<t[i];
    }
    cout<<nl;
}

int main(){
    fastio();
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	a, b := readInt(), readInt()
	ans := 0
	for i := a; i < b+1; i++ {
		if i%10 == 0 {
			continue
		}
		b := []byte(strconv.Itoa(i))
		rb := make([]byte, len(b))
		for j := range b {
			rb[j] = b[len(b)-j-1]
		}
		if string(b) == string(rb) {
			ans++
		}
	}
	fmt.Println(ans)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 1536
from itertools import accumulate, combinations

def main():
    N, *L = map(int, open(0).read().split())

    A = [0] * (2 * 10 ** 3 + 7)
    for l in L:
        A[l] += 1

    S = list(accumulate(A))

    ans = 0
    for b, c in combinations(L, 2):
        l, r = c - b if c > b else b - c, b + c
        ans += S[r - 1] - S[l] - (l < b < r) - (l < c < r)

    print(ans // 3)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
S = input()
N = len(S)
ans = N*[1]

for n in range(N):
  if S[n]=="R" and S[n+1]=="R":
    ans[n+2]+=ans[n]
    ans[n]=0
  m = N-n-1
  if S[m]=="L" and S[m-1]=="L":
    ans[m-2]+=ans[m]
    ans[m]=0

print(*ans)

Measured memory_bytes: 10732
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,X,Y,p,q,i,x[500],y[500];
    cin>>n>>m>>X>>Y;
    for(i=0;i<n;i++)
    {
        cin>>x[i];
    }
    sort(x,x+n);
    for(i=0;i<m;i++)
    {
        cin>>y[i];
    }
    sort(y,y+m);
    int fl=-1;
    int res;
    for(i=X+1;i<=Y;i++)
    {
        if(i>x[n-1] && i<=y[0]){fl=0;res=i;}
    }
    if(fl==0)
    {
        cout<<"No War"<<'\n';
    }
    else cout<<"War"<<'\n';
    return 0;
}


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

int main() {
    long long N;
    cin >> N;
    long long list[5];
    for (long long i = 0; i < 5; i++) list[i] = 0;
    for (long long i = 0; i < N; i++) {
        char name[11];
        scanf("%s", name);
        switch (name[0]) {
        case 'M':
            list[0]++;
            break;
        case 'A':
            list[1]++;
            break;
        case 'R':
            list[2]++;
            break;
        case 'C':
            list[3]++;
            break;
        case 'H':
            list[4]++;
            break;
        default:
            break;
        }
    }
    long long num = 0;
    for (long long i =0; i <= 2; i++) {
        for (long long j = i+1; j <=3; j++) {
            for (long long k = j+1; k <=4; k++) {
                num += list[i] * list[j] * list[k];
            }
        }
    }
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;

double A, B, C, D, E, F, res1, res2;
double MAX = -0xe869120;

int main() {
	cin >> A >> B >> C >> D >> E >> F;
	for (int i = 0; i*A * 100 <= F; ++i) {
		for (int j = 0; i*A * 100 + j * B * 100 <= F; ++j) {
			if (i == 0 && j == 0)continue;
			for (int k = 0; i*A * 100 + j * B * 100 + k * C <= F && k*C <= E * (i*A + j * B); ++k) {
				for (int l = 0; i*A * 100 + j * B * 100 + k * C + l * D <= F && k*C + l * D <= E * (i*A + j * B); ++l) {
					if (MAX < (k*C + l * D) / (i*A + j * B)) {
						MAX = (k*C + l * D) / (i*A + j * B);
						res1 = i * A * 100 + j * B * 100 + k * C + l * D;
						res2 = k * C + l * D;
					}
				}
			}
		}
	}
	cout << res1 << sp << res2 << endl;
	return 0;
}

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

int main() {
  int64_t N, D;
  cin >> N >> D;
  int count = 0;
  for(int64_t i = 0; i < N; i++) {
    int64_t x, y;
    cin >> x >> y;
    if(x * x + y * y <= D * D) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;

struct Edge
{
    int t, w;
    //Edge(){}
    Edge(int t=-1, int w=-1): t(t), w(w){}
};
const int MAX = 100005;
const int INF = (1<<29);
int color[MAX], d[MAX];//d存的是距离
vector<Edge> G[MAX];
int n;
//color -1未遍历  0已遍历
void bfs(int u)
{
    memset(color, -1, sizeof(color));
    memset(d, -1, sizeof(d));
    queue<int> Q;
    int v;
    Q.push(u);//第一个节点
    d[u] = 0;
    color[u] = 0;
    while(!Q.empty())
    {
        u = Q.front(); Q.pop();
        for(int i=0; i<G[u].size(); i++)
        {
            int v = G[u][i].t;
            if(color[v]==-1)//找到未遍历的邻接点
            {
                color[v] = 0;
                Q.push(v);
                d[v] = d[u]+G[u][i].w;
            }
        }
    }
}

void solve()
{
    bfs(0);
    int Max = -1;
    int x, y;
    for(int i=0; i<n; i++)
    {
        if(d[i]>=0 && Max<d[i])
        {
            Max = d[i];
            x = i;
        }
    }
    bfs(x);
    Max = -1;
    for(int i=0; i<n; i++)
    {
        if(d[i]>=0 && Max<d[i])
        {
            Max = d[i];
            y = i;
        }
    }
    cout << d[y] << endl;
}
int main()
{
    int u, k, v;
    cin >> n;
    if(n==1)
    {
        cout << 0 << endl;
        return 0;
    }
    for(int i=0; i<n-1; i++)
    {
        cin >> u >> k >> v;
        G[u].push_back(Edge(k, v));
        G[k].push_back(Edge(u, v));
    }
    solve();

    return 0;
}



Measured memory_bytes: 10212
#include<iostream>
#include<vector>
#include<utility>
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main(){
  ll n;
  string s[2];
  bool num[2][53];
  long long ans;
  bool type;
  ll i;
  cin >> n;
  cin >>s[0] >> s[1];
  if(s[0][0]==s[1][0]){
    ans=3;
    i=1;
    type=true;
  }else{
    ans=6;
    i=2;
    type=false;
  }
  while(i<n){
    if(type==true){
      ans*=2;
      if(s[0][i]==s[1][i]){
        type=true;
        i++;
      }else{
        type=false;
        i+=2;
      }
    }else{
      if(s[0][i]==s[1][i]){
        type=true;
        i++;
      }else{
        ans*=3;
        type=false;
        i+=2;
      }
    }
    ans%=MOD;
  }
  cout << ans <<endl;
}


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

// for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

// abbreviati
#define PB(v) push_back(v)
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

// constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000000+7;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

// adjacency list
vector<int> to[100005];

// Graph
using Graph = vector<vector<int>>;

// Grid
int H,W;
vector<vector<int>> field;

// 4方向への移動ベクトル
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<ll> A(n);
    vector<ll> sum(n);
    ll sums=0;
    //vector<ll> modn(MOD);
    rep(i,0,n){
        ll a=0;
        cin >> a;
        if(a>=MOD){
            A[i]=a%MOD;
        }else A[i]=a;
        //modn[A[i]]++;
        sums+=A[i];
    }
    rep(i,0,n){
        if(i==0)sum[i]=sums-A[i];
        else sum[i]=sum[i-1]-A[i];
    }

    // rep(i,0,n){
    //     cout << "sum: " << sum[i] ENDL;
    // }
    ll ans=0;
    rep(i,0,n){
        ans+=A[i]*(sum[i]%MOD);
        if(ans>=MOD) ans%=MOD;
    }
    // rep(i,0,n-1){
    //     rep(j,i+1,n){
    //         ans+=A[i] * A[j];
    //         if(ans>MOD) ans%=MOD;
    //         //cout << ans ENDL;
    //     }
        
    //     //cout << ans ENDL;
    // }
    // rep(i,0,n){
    //     rep(j,0,MOD){
            
    //         modn[A[i]]--;
    //         ans+=A.at(i)*A.at(j)*modn.at(A.at(j));
    //         if(ans>=MOD) ans%=MOD;
    //     }
    // }
    
    cout << ans ENDL;
    return 0;
}

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

using namespace std;
#define chmax(x, y) x = max(x,y);
ll MOD=1000000007;
ll MAX=1000000001;

#include <iostream>
using namespace std;

//N^P(modM)

ll modpow(ll a, ll n, ll p) {
		ll result = 1;
		while (n > 0) {
			if (n & 1) result = result * a % p;
			a = a * a % p;
			n >>= 1;
		}
		return result;
	};



ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    ll ans=N * RepeatSquaring(N, P-1, M);
    return ans%M;
}

// n!/(n-a)!を計算
ll modn(ll a, ll n, ll mod) {
    ll res = 1;
    ll n1=n;
    for (ll i=0; i<a; i++){
      res*=n1;
      res=res%mod;
      n1-=1;

    }
    return res;
}



int main(){

ll n,a,b;
cin>>n>>a>>b;

ll ans=modpow(2,n,MOD);
ans-=1;
if (ans<0)ans+=MOD;



ll coma, comb, a1, b1;
//coma=modn(a,n,MOD);
//comb=modn(b,n,MOD);
a1=modn(a,a,MOD);
b1=modn(b,b,MOD);
//a1=modpow(2,4,MOD);
coma=modpow(a1,(MOD-2),MOD)*modn(a,n,MOD);
coma=coma%MOD;

comb=modpow(b1,(MOD-2),MOD)*modn(b,n,MOD);
comb=comb%MOD;

ans-=coma;
if (ans<0)ans+=MOD;

ans=ans%MOD;
ans-=comb;
if (ans<0)ans+=MOD;
ans=ans%MOD;


cout<<ans;
}


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

int main() {
	int N, S = 0;

	cin >> N;

	for (int i = 0; i < N; i++){
		int a;
		cin >> a;
		while(a%2 == 0){
			S++;
			a /= 2;
		}
	}

	cout << S;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#define ROP(i,n) for(int i=0;i<n;i++)
#define ROOP(i,n) for(int i=1;i<=n;i++)
using namespace std;
int main(){
  long long N;
  long long L[90];
  L[0]=2;L[1]=1;
  scanf("%lld",&N);
  for(long long i=2;i<=N;i++){
    L[i]=L[i-2]+L[i-1];
  }
  printf("%lld\n",L[N]);
  return 0;
}


Measured memory_bytes: 256