akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N;
  string S1, S2;
  cin >> N >> S1 >> S2;

  vector<string> pattern = {
    "aa", "ab", "ac",
    "ba", "bb", "bc",
    "ca", "cb", "cc",
  };

  unordered_map<string, long> state;
  for (auto p: pattern) {
    if (S1[0] == S2[0] and p[0] == p[1]) state[p] = 1;
    if (S1[0] != S2[0] and p[0] != p[1]) state[p] = 1;
  }

  for (long i = 1; i < N; i++) {
    if (S1[i-1] == S1[i]) continue;
    unordered_map<string, long> next_state;
    for (auto p: pattern) for (auto next_p: pattern) {
      if ((S1[i-1] == S2[i-1]) != (p[0] == p[1])) continue;
      if ((S1[i] == S2[i]) != (next_p[0] == next_p[1])) continue;
      if (p[0] == next_p[0]) continue;
      if (p[1] == next_p[1]) continue;
      next_state[next_p] += state[p];
    }
    for (auto it: next_state) next_state[it.first] %= MOD;
    state = next_state;
  }
  
  long ans = 0;
  for (auto it: state) ans += it.second;
  ans %= MOD;
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

using namespace std;

/* * * *   * * *   	* * * */
typedef long long ll;
const int oo = 1e9;
const ll mod = 100000000;
typedef complex<ll> P;
#define X real()
#define Y imag()
/* * * *   * * *   	* * * */

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int a, b; cin>>a>>b;
	if (b%a == 0) cout<<a+b;
	else cout<<b-a;
	return 0;
}


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

int cnt, W, N, w[1000], v[1000], dp[1001][1001];

void solve(){
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= W; j++){
            dp[i+1][j] = 0;
        }
    }
    for(int i = 0; i < N; i++){
        dp[i+1][w[i]] = v[i];
        for(int j = 0; j <= W; j++){
            if( j < w[i] ) dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
        }
    }
    int c,v = 0;
    for(int i = 0; i <= W; i++){
        if( dp[N][i] > v ){
            v = dp[N][i];
            c = i;
        }
    }
    printf("Case %d:\n%d\n%d\n", cnt, v, c);
}

int main(){
    cnt = 0;
    while( true ){
        cnt++;
        scanf("%d", &W);
        if( !W ) break;
        scanf("%d", &N);
        for(int i = 0; i < N; i++){
            scanf("%d,%d", v+i, w+i);
        }
        solve();
    }
    return 0;
}

Measured memory_bytes: 4948
n = int(input())
k, *l = [int(x) for x in input().split()]

m = 0
for i in l:
    m |= 1<<i

for i in range( 2**n ):
    if i & m != m:
        continue

    if i == 0:
        print("{}:".format(i))
        continue
    else:
        print("{}: ".format(i), end="")
    l = []
    for j in range(n):
        if i & (1<<j) != 0:
            l.append(j)
    print(*l)



Measured memory_bytes: 6180
use std::cmp;
fn main() {
    let mut sc = Scanner::new();
    let (a, b, c): (i64, i64, i64) = (sc.read(), sc.read(), sc.read());
    let (x, y): (i64, i64) = (sc.read(), sc.read());

    let mut min = std::i64::MAX;
    for z in 0..1000000 {
        let x_cost = a * cmp::max(x - z / 2, 0);
        let y_cost = b * cmp::max(y - z / 2, 0);
        let z_cost = z * c;
        min = cmp::min(min, x_cost + y_cost + z_cost);
    }
    println!("{}", min);
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>

int main(void) {

  int d;
  scanf("%d", &d);
  long c[26];
  for (int i = 0; i < 26; i++) {
    scanf("%ld", &c[i]);
  }
  long s[d][26];
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      scanf("%ld", &s[i][j]);
    }
  }
  int t[d][200];
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 200; j++) {
      t[i][j] = rand()%26+1;
    }
  }
  int max_p;
  long score,max;
  int last[26];
  for (int p = 0; p < 200; p++) {
    for (int i = 0; i < 26; i++) {
      last[i] = -1;
    }
    score = 0;
    for (int i = 0; i < d; i++) {
      score += s[i][t[i][p]-1];
      last[t[i][p]-1] = i;
      for (int j = 0; j < 26; j++) {
        if (j == t[i][p]-1) {
          continue;
        }
        score -= c[j]*(i-last[j]);
      }
    }
    if (p == 0 || score > max) {
      max = score;
      max_p = p;
    }
  }
  for (int i = 0; i < d; i++) {
    printf("%d\n", t[i][max_p]);
  }

  return 0;
}

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

int main(){
  int ans=0, n, q, a;
  set<int> arr;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> a;
    arr.insert(a);
  }
  cin >> q;
  for(int i=0; i<q; i++){
    cin >> a;
    if(arr.find(a)!=arr.end())
      ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;

vector<ll> nums;


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

int main() {
    int N;
    cin >> N;
    
    rep(i,N){
        ll t;
        cin >> t;
        nums.push_back(t);
    }
    
    unsigned long a = nums[0];
    rep1(i,N-1){
        a = nums[i]/gcd(a,nums[i])*a;
    }
    cout<<a<<endl;
}

Measured memory_bytes: 384
import math
n,d=map(int,input().split())
x=[]
ans=0
for i in range(n):
    x.append(list(map(int,input().split())))
for i in range(n):
    for j in range(i):
        sum = 0
        for k in range(d):
            sum += (x[i][k]-x[j][k])*(x[i][k]-x[j][k])
        if math.sqrt(sum).is_integer():
            ans+=1
print("{}".format(ans))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(){
  string str;
  cin >> str;
  char now;
  now = str[0];
  int count = 0;
  count = 1;
  for(int i = 1;i <= str.size() - 1;i++){
    if(str[i] != now){
      now = str[i];
      count++;
    }
  }
  cout << count - 1 << endl;
  return 0;
}

Measured memory_bytes: 512
h, w = gets.split.map(&:to_i)

coins = []

h.times do
  coins << gets.split.map(&:to_i)
end

row = Array.new(w, 0)
actions = []

(h-1).times do |y|
  w.times do |x|
    if (coins[y][x] + row[x]).odd?
      row[x] = 1
      actions << [y, x, y + 1, x]
    else
      row[x] = 0
    end
  end
end

# last row
y = h - 1
(w-1).times do |x|
#  p row
  if (coins[y][x] + row[x]).odd?
    row[x + 1] = 1 - row[x + 1]
    actions << [y, x, y, x + 1]
  end
end

p actions.size

#coins.each {|cs| p cs }
actions.each do |y0, x0, y1, x1|
  puts [y0 + 1, x0 + 1, y1 + 1, x1 + 1].join(' ')
end


Measured memory_bytes: 26876
#include <bits/stdc++.h>
#define int long long
using namespace std;
int read() {
	register int x=0,f=0;
	register char ch=getchar();
	while(!isdigit(ch)) {
		f|=(ch=='-');
		ch=getchar();
	}
	while(isdigit(ch)) {
		x=x*10+ch-'0';
		ch=getchar();	
	}
	return f?-x:x;
}
void write(int x) {
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x>=10) write(x/10);
	putchar(x%10+'0');
}
int a,b,c;
signed main() {
	cin>>a>>b>>c;
	cout<<min(a*b,c);
	return 0;
}

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

using namespace std;

int main()
{
	int n;
	while(cin >> n && n)
	{
		string list;
		int number[1000]={};
		int win[1000]={};
		int lose[1000]={};
		int a;

		for(int i=0;i<n;i++)
		{
			cin >> list[i];
			number[i]=i;

			for(int j=0;j<n-1;j++)
			{
				cin >> a;
				if(!a)win[i]++;
				else if(a==1)lose[i]++;
			}
		}

		for(int i=0;i<n;i++)
		{
			for(int j=i;j<n;j++)
			{
				if(win[i]<win[j])
				{
					swap(win[i],win[j]);
					swap(lose[i],lose[j]);
					swap(list[i],list[j]);
					swap(number[i],number[j]);
				}
				else if(win[i]==win[j] && lose[i]>lose[j])
				{
					swap(win[i],win[j]);
					swap(lose[i],lose[j]);
					swap(list[i],list[j]);
					swap(number[i],number[j]);					
				}
				else if(win[i]==win[j] && lose[i]==lose[j] && number[i]>number[j])
				{
					swap(win[i],win[j]);
					swap(lose[i],lose[j]);
					swap(list[i],list[j]);
					swap(number[i],number[j]);	
				}
			}
		}
		for(int i=0;i<n;i++)cout << list[i] << endl;
	}

    return 0;
}

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


int main()
{   
    int h,w;
    cin >> h >> w ;
    string s[h];
    for (int i=0;i<h;i++)
        cin >> s[i] ;
    
    long long ans[h][w] ;
    for (int i=0;i<h;i++)
        for (int j=0;j<w;j++)
            ans[i][j]=(long long) 0 ;
        
    for (int i=0;i<w;i++){
        if (s[0][i]=='#')
            break ;
        ans[0][i]=(long long) 1 ;
    }
    
    for (int i=0;i<h;i++){
        if (s[i][0]=='#')
            break ;
        ans[i][0]=(long long) 1 ;
    }
    
    for (int i=1;i<h;i++)
        for (int j=1;j<w;j++)
            if (s[i][j]=='#')
                ans[i][j]=0 ;
            else 
                ans[i][j]=(ans[i][j-1]+ans[i-1][j])%(((long long)1000000000)+7) ;
    
    cout << ans[h-1][w-1] ;
    return 0 ;
}



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

int main(){
	string At,s,Co,a;
	char b,c;
	cin>>At>>s>>Co;
	a=At.at(0);
	b=s.at(0);
	c=Co.at(0);
	cout<< a+b+c<<endl;
}

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

using namespace std;

int main(){
    long long x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    priority_queue<long long> red;
    priority_queue<long long> green;
    
    for(int i=0;i<a;i++){
        int hoge;
        cin>>hoge;
        red.push(hoge);
    }
    
    for(int i=0;i<b;i++){
        int hoge;
        cin>>hoge;
        green.push(hoge);
    }
    
    priority_queue<long long> ans;
    
    for(int i=0;i<x;i++){
        ans.push(red.top());
        red.pop();
    }
    
    for(int i=0;i<y;i++){
        ans.push(green.top());
        green.pop();
    }
    
    for(int i=0;i<c;i++){
        int hoge;
        cin>>hoge;
        ans.push(hoge);
    }
    
    long long sum=0;
    
    for(int i=0;i<x+y;i++){
        sum+=ans.top();
        ans.pop();
    }
    
    cout<<sum<<endl;
    
    return 0;
}

Measured memory_bytes: 8048
# -*- coding:utf-8 -*-

def solve():
    n = int(input())
    V = [None]
    V.extend(list(map(int, input().split(" "))))
    
    # 1種類の数字で構成されているか？
    tmp = V[1]
    flag = True
    for i in range(2, n+1):
        if tmp == V[i]:
            continue
        flag = False
        break
    if flag:
        print(int(n/2))
        return

    # 奇数番目のもので、最も多い数字は？
    odd_dict = {}
    for i in range(1, n+1, 2):
        # 奇数番目のもので、最も多い数字を調べる
        if V[i] in odd_dict.keys():
            odd_dict[V[i]] += 1
            continue
        odd_dict[V[i]] = 1

    # 偶数番目のもので、最も多い数字は？
    even_dict = {}
    for i in range(2, n+1, 2):
        # 偶数番目のもので、最も多い数字を調べる
        if V[i] in even_dict.keys():
            even_dict[V[i]] += 1
            continue
        even_dict[V[i]] = 1

    sorted_odds = sorted(odd_dict.items(), key=lambda x: x[1], reverse=True)
    sorted_evens = sorted(even_dict.items(), key=lambda x: x[1], reverse=True)

    # 変換後、1種類の数字にならないように気を付ける
    if sorted_evens[0][0] == sorted_odds[0][0]:
        if len(sorted_odds) == 1:
            ans = n - sorted_odds[0][1] - sorted_evens[1][1]
        elif len(sorted_evens) == 1:
            ans = n - sorted_odds[1][1] - sorted_evens[0][1]
        else:
            ans1 = n - sorted_odds[0][1] - sorted_evens[1][1]
            ans2 = n - sorted_odds[1][1] - sorted_evens[0][1]
            ans = min(ans1, ans2)
    else:
        ans = n - sorted_evens[0][1] - sorted_odds[0][1]

    print(ans)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 22736
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "begin", long, "end");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto s = sread();
    bool flag = true;
    foreach(i, e; s)
    {
        if(i % 2)
            flag &= (e == 'i');
        else
            flag &= (e == 'h');
    }
    if(!(s.length % 2) && flag)
        writeln("Yes");
    else
        writeln("No");
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

#define int long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define all(c) (c).begin(),(c).end()
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
const ld PI = acos(-1.0);
const int N = 1e5 + 5;
int id[N];
int sz[N];

void pre(){
	
	for(int i= 0 ; i<N ; i++) id[i] = i , sz[i] = 1;
}

int root(int i){
	
	while(i != id[i])	id[i] = id[id[i]] , i = id[i];
	return i;
}

void uni(int a, int b){
	int ra = root(a);
	int rb = root(b);
	if(ra == rb)	return;
	if(sz[ra] < sz[rb]) swap(ra,rb);
	id[rb] = ra , sz[ra] += sz[rb];
}
int32_t main(){
	fast;
    pre();
    
    int n,m;
    cin >> n >> m;
    
    int a[n+1];
    f(i,1,n+1)  cin >> a[i];
    f(i,0,m)
    {
        int x,y;
        cin >> x >> y;
        uni(x,y);
    }
    

    map<int , set<int>> v , v1;
    for(int i=1 ; i<=n ; i++)
    {
        v[root(i)].insert(i);
        v1[root(i)].insert(a[i]);
    }
    
    int ans = 0;
    for(int i=1 ; i<=n ; i++)
    {
        for(auto x : v[i]) v1[i].insert(x);
        ans += (2*v[i].size() - v1[i].size());
    }
    cout<<ans;
}

Measured memory_bytes: 35456
#include <stdio.h>
#include <stdlib.h>
#define MAX 100000

typedef struct{
  char name[20];
  int time;
} data;

void enque(void);
void deque(void);

int head = 1, tail, total = 0;
data list[MAX];

int main(){
  int n, q, i;
	
  scanf("%d%d", &n, &q);
  tail = n+1;
  for(i=1; i<=n; i++) scanf("%s%d", list[i].name, &list[i].time);

  while(1){
    if(head == tail) break;
    if(list[head].time > q){
      total += q;
      list[head].time -= q;
      enque();
      deque();
    }
    else{
      total += list[head].time;
      printf("%s %d\n", list[head].name, total);
      deque();
    }
  }
	
  return 0;
}

void enque(void){
  list[tail] = list[head];
  if((tail+1) == MAX) tail = 0;
  else tail++;
}

void deque(void){
  if((head+1) == MAX) head = 0;
  else head++;
}

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


int main(){
    int n, k, q;
    cin >> n >> k >> q;
    int x;
    unordered_map<int, int> mp;
    for (int i = 0; i < q; ++i)
    {
        cin >> x;
        mp[x]++;
    }
    for (int i = 0; i < n; ++i)
    {
        if ((k - q + mp[i+1]) > 0)
            cout << "Yes" << endl;
        else 
            cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 4772
// i_am_arin

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<string> vs;


#define f(i, a, n) for(ll i=a; i<(ll)n; i++)
#define f2(i, a, b) for(ll i=a; i<=(ll)b; i++)
#define PB push_back
#define FF first
#define SS second
const ll MOD = 1e9+7;
const ll INF = LLONG_MAX;

ll h,w;
vector<string> s(1000);
ll dp[1005][1005];

ll go(ll h,ll w){
	if(w==0&&h==0) return 1;
	if(dp[h][w]!=-1) return dp[h][w];
	if(h==0){
		if(s[h][w]=='.') return dp[h][w]=go(h,w-1);
		else return dp[h][w]=0;
	}
	if(w==0){
		if(s[h][w]=='.') return dp[h][w]=go(h-1,w);
		else return dp[h][w]=0;
	}
	if(s[h][w]=='.') return dp[h][w]=(go(h-1,w)+go(h,w-1))%MOD;
	else return dp[h][w]=0;
}

void solve(){

cin>>h>>w;

memset(dp,-1,sizeof(dp));
f(i,0,h) cin>>s[i];
cout<<go(h-1,w-1)<<endl;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std ;
#define async ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long int
#define let auto
#define of :
#define all(y) y.begin(), y.end()
#define present( x, y ) (x.find( y ) != x.end())
#define _matrix(T) vector<vector<T>>
template<class T>
auto matrix( int r, int c, T v ){
	return vector<vector<T>>( r, vector<T>( c, v ) ) ;
}
const int mod = (int)1e9 + 7 ;
const int inf = (int)1e18 ;
void mxz( int &a, int b ){
	a = max( a, b ) ;
}

signed main(){
	double N, D ; cin >> N >> D ;
	int cnt = 0 ;
	double x, y ;
	for( int i = 0 ; i < N ; i++ ){
		cin >> x >> y ;
		if( sqrt( x*x + y*y ) <= (D) ) cnt++ ;
	}
	cout << cnt ;
	return 0 ;
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD =  1000000007;
const int INF = 1e11;
using Graph = vector<vector<int>>;

signed main(){
  int N, K;
  cin >> N >> K;

  if( K > (N-1)*(N-2)/2 ){
    cout << -1 << endl;
    return 0;
  }

  vector<pair<int, int>> ans;
  for( int i = 2; i <= N; i++ ) ans.push_back({1, i});

  int one = 2; int two = 3;
  for( int i = 0; i < (N-1)*(N-2)/2-K; i++ ){
    ans.push_back({one, two});
    two++;
    if( two > N ){
      one++;
      two = one+1;
    }
  }

  cout << ans.size() << endl;
  for( int i = 0; i < (int)ans.size(); i++ ) cout << ans[i].first << " " << ans[i].second << "\n";

}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int n; cin>>n;
  vector<int> t(n, 0);
  rep(i,n) cin>>t[i];
  int m; cin>>m;
  vector<int> p(m, 0);
  vector<int> x(m, 0);
  rep(i,m) cin>>p[i]>>x[i];

  ll sum = 0;
  rep(i,n) sum+=t[i];
  rep(i,m) cout << sum-t[p[i]-1]+x[i] << endl;
}

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


Measured memory_bytes: 256
import sys
a = []
for i in range(3):
    a.append(list(input().split()))    

n = int(input())
b = []
for i in range(n):
    b.append(input())
# if n > 6:
#     print("Yes")
# elif n < 3:
#     print("No")
# else:
ans = [["0","0","0"],["0","0","0"],["0","0","0"]]
for i in range(n):
    for j in range(3):
        if b[i] in a[j]:
            index = a[j].index(b[i])
            ans[j][index]  = "1"
# print(ans)
for i in range(3):
    if "0" in ans[i]:
        pass
    else:
        print("Yes")
        sys.exit()

count = 0
for i in range(3):
    if "0" in ans[i][0]:
        pass
    else:
        count += 1
if count == 3:
    print("Yes")
    sys.exit()
count = 0
for i in range(3):
    if "0" in ans[i][1]:
        pass
    else:
        count += 1
if count == 3:
    print("Yes")
    sys.exit()
count = 0
for i in range(3):
    if "0" in ans[i][2]:
        pass
    else:
        count += 1
if count == 3:
    print("Yes")
    sys.exit()

count = 0
for i in range(3):
    # print(a[i][i])
    if ans[i][i] == "1":
        # print(count)
        count += 1
    if count == 3:
        print("Yes")
        sys.exit()

count = 0
for i in range(3):
    if ans[i][-(i+1)] == "1":
        count += 1
    if count == 3:
        print("Yes")
        sys.exit()
print("No")



# print(ans)

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

void solve(){
    string S, T, ans;
    cin >> S >> T;
    int sn = S.size();
    int tn = T.size();
    int idx = -1;
    for (int i = 0; i < sn; ++i){
        bool flag = true;
        if (S[i] == '?' || S[i] == T[0]){
            int j = 1;
            while (j <= tn){
                if (j == tn && flag){
                    idx = i;
                    break;
                }
                if (S[i+j] == '?'){
                    j++;
                }
                else{
                    if (S[i+j] == T[j]){
                        j++;
                    }else{
                        flag = false;
                        break;
                    }
                }
            }

        }
    }

    if (idx == -1){
        ans = "UNRESTORABLE";
        cout << ans << endl;
        return ;
    }else{
        for (int i = 0; i < tn; ++i){
            S[idx + i] = T[i];
        }
        for (int i = 0; i < sn; ++i){
            if (S[i] == '?') S[i] = 'a';
        }
        ans = S;
        cout << S << endl;
        return ;
    }

}
int main(void){
    //////////////////////////

    solve();

    //////////////////////////
    return 0;
}

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

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

    int arr[n];
    int arr1[n];
    int arr2[n];

    for (int i=0;i<n;i++)
    {
        cin>>arr[i];
        arr1[i] = arr[i];
    }


    sort(arr1, arr1+n);
    int c= 0;
    for (int i =0;i<n;i++)
    {
        if (arr[i]==arr1[i])
            continue;
            else
            {
                c++;
                arr2[c-1] = i;
            }
    }
    if (c>2)
    {
        cout<<"NO"<<endl;
    }
    else if (c==2)
    {
        cout<<"YES"<<endl;
    }
else
{
    cout<<"YES"<<endl;
}






}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define REP(i,N) for(int i=0;i<N;++i)
using namespace std;
using ll = long long;

int main () {
	int N;
	cin >> N;
	vector<ll> A(N);
	// 0-base
	REP(i,N) {
		scanf("%lld", &A[i]);
		A[i] -= (i+1);
	}
	// the median for A is the value for the sum to be lowest.
	// find the median
	sort(A.begin(), A.end());
	// if N is odd, the median can be uniquely identified.
	// If N is even, the median cannot be uniquely idenfied as an integer. so, get the two consecutive integers. 
	ll b1, b2;
	ll sum1, sum2;
	b1 = A[N/2];
	sum1 = 0;
	REP(i,N) sum1 += abs(A[i] - b1);
	bool is_even = false;
	if (N % 2 == 0) {
		is_even = true;
		b2 = A[N/2-1];
		sum2 = 0;
		REP(i,N) sum2 += abs(A[i] - b2);
	}
	cout << (is_even ? sum2 : sum1) << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main() {
  int count, leg;
  scanf("%d%d", &count, &leg);
  int i = 0;
  int sum = 0;
  int flag = 0;
  for (i = 0; i <= count; i++) {
    sum = 2 * i + 4 * (count - i);
    if (sum == leg) {
      flag = 1;
      break;
    }
  }
  if (flag == 1) {
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iomanip>
#include <climits>


using namespace std;

int main()
{
	int A,B,C;
	cin >> A >> B >> C;
	if(C>=A && C<=B){
		cout << "Yes" << endl;
	}else{cout << "No" << endl;}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private static final String[] WEATHERS = new String[] { "Sunny", "Cloudy", "Rainy" };

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			String s = scanner.next();
			System.out.println(WEATHERS[(getIndex(WEATHERS, s) + 1) % WEATHERS.length]);
		}
	}

	/**
	 * @param strings
	 * @param key
	 * @return keyがstringsにおけるindex
	 */
	private static int getIndex(String[] strings, String key) {
		for (int i = 0; i < strings.length; i++) {
			if (key.equals(strings[i])) {
				return i;
			}
		}
		return 0;
	}
}


Measured memory_bytes: 21460
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

signed main(){
	int A,B,C;
	cin>>A>>B>>C;
	cout<<min(B/A,C)<<endl;
	return 0;
}


Measured memory_bytes: 256
r, c = map(int, input().split())
A = []
for i in range(r):
    a = [int(j) for j in input().split()]
    A.append(a)

for i in range(r):
    s = 0
    for k in A[i]:
        s += k
    A[i].append(s)

z = []
for j in range(c+1):
    t = 0
    for i in range(r):
        t += A[i][j]
    z.append(t)
A.append(z)

for i in range(r+1):
    print(" ".join(str(a) for a in A[i]))    
    

Measured memory_bytes: 7724
S=gets.chop
n=S.size
L=[0]*n
l=[n]*26
(n-1).downto(0){|i|L[i]=l.dup;l[S[i].ord-97]=i}
L[-1]=l
q=[-1]
z={-1=>[nil,0]}
(v=q.shift;l=L[v];26.times{|c|!z[l[c]]&&(z[l[c]]=[v,c];q<<l[c])})while q[0]&&q[0]!=n
r=''
(n,c=z[n];r<<(c+97))while n
$><<r.reverse[1..-1]

Measured memory_bytes: 86140
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 1000; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j])%mod;
//       }
//     }
//   }
//   return 0;
// }


// int factorial(int n){
//   if(n == 0) return 1;
//   return n*factorial(n-1);
// }

// int divisor(int a){
//   int cnt = 0;
//   for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
//   return cnt;
// }

// int comb(int n, int k){
//   pascal_triangle();
//   return memo[n][k];
// }

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}







//二項係数(mod剰余)----------------------------

// const int MAX = 3000010;
// const int M = 1000000007;

// vector<ll> fac(MAX); //n!(mod M)
// //a,bの範囲的にこれだけ配列を用意していけば十分
// vector<ll> ifac(MAX); //k!^{M-2} (mod M)

// ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
//     ll ans = 1;
//     while(n != 0){
//         if(n&1) ans = ans*x % M;
//         x = x*x % M;
//         n = n >> 1;
//     }
//     return ans;
// }

// ll COMinit(){
//   //大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
//   fac[0] = 1;
//   ifac[0] = 1;
//   for(ll i = 0; i<MAX; i++){
//     fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
//     ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
//   }
//   return 0;
// }

// ll COM(ll a, ll b){ //aCbをmod計算
//   if(a == 0 && b == 0)return 1;
//   if(a < b || a < 0)return 0;
//   ll tmp = ifac[a-b]* ifac[b] % M;
//   return tmp * fac[a] % M;
// }

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



int main(){
  int N,K;
  cin >> N >> K;
  ll H[N];
  rep(i,N){
    cin >> H[i];
  }
  sort(H,H+N,greater<ll>());
  ll ans = 0;
  if(N <= K) cout << 0 << endl;
  else{
    for(int i = K; i < N; i++){
      ans+=H[i];
    }
    cout << ans << endl;
  }
 
  return 0;
}




Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int N=800005;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch&15);ch=getchar();}
	return x*f;
}

int n,k,tot,tmp,ans=0x7fffffff;
int ver[N],nex[N],head[N];
inline void add(int x,int y)
{ver[++tot]=y;nex[tot]=head[x];head[x]=tot;}

inline void dfs(int x,int fa,int dep)
{
	if(dep>k/2) tmp++;
	for(int i=head[x];i;i=nex[i])
	{
		int y=ver[i];
		if(y==fa) continue;
		dfs(y,x,dep+1);
	}
} 

int main()
{
	n=read(),k=read();
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read();
		add(x,y);add(y,x); 
	} 
	if(k%2)
	{
		for(int x=1;x<=n;x++)
			for(int i=head[x];i;i=nex[i])
			{
				tmp=0;int y=ver[i];
				dfs(x,y,0);dfs(y,x,0);
				ans=min(ans,tmp);
			}
	}
	else
		for(int x=1;x<=n;x++)
			tmp=0,dfs(x,0,0),ans=min(ans,tmp);
	printf("%d\n",ans);
}

Measured memory_bytes: 4352
# DP ver
import sys
input = sys.stdin.readline
def main():
    X = int(input())
    dp = [0] * (X+1)
    dp[0] = 1
    for base in range(100, X+1):
        can_buy = False
        for fraction in range(6):
            pre_cost = base - (100 + fraction)
            if dp[pre_cost] == 1:
                can_buy = True
                break
        if can_buy:dp[base] = 1
    print(dp[-1])
if __name__ == "__main__":
    main()

Measured memory_bytes: 40048
#include<stdio.h>
#include<stdlib.h>

typedef struct DATA{
  int num;
  int p;
  int y;
}data;

int cmpy(const void *a,const void *b){
  return ((data*)a)->y - ((data*)b)->y;
}

int cmpnum(const void *a,const void *b){
  return ((data*)a)->num - ((data*)b)->num;
}

int main(void){
  int n,m,i,j,tmp;
  scanf("%d %d",&n,&m);
  
  data d[m];
  int Th[m];
  int id[n+1];
  for(i=0;i<m;i++) Th[i]=0;
  for(i=0;i<n+1;i++) id[i]=0;
  for(i=0;i<m;i++){
    scanf("%d %d",&d[i].p,&d[i].y);
    d[i].num=i;
  }
  
  qsort(d,m,sizeof(data),cmpy);
  for(i=0;i<m;i++) Th[d[i].num] = ++id[d[i].p];
  
  qsort(d,m,sizeof(data),cmpnum);
  for(i=0;i<m;i++) printf("%06d%06d\n",d[i].p,Th[i]);
  
  return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=0;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli a,b,c;
	cin>>a>>b>>c;

	cout<<a*b/2<<endl;

	return 0;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){ 
  int N;
  string S;
  cin >> N >> S;
  bool ans = true;
  if(N % 2){
    cout << "No" << endl;
    return 0;
  }
  REP(i, N/2){
    if(S[i] != S[i+N/2]){
      ans = false;
    }
  }
  cout << (ans ? "Yes": "No") << endl;
  return 0;
}



Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
B = [True]*(A[-1]+1)
i = 0
for i in range(N):
  if i < N-1 and A[i] == A[i+1]:
    B[A[i]] = False
  if A[-1] < 2*A[i]:
    continue
  M = A[-1]//A[i]+1
  for j in range(2,M):
    B[j*A[i]] = False

ans = 0
for a in A:
  if B[a]:
    ans += 1
print(ans)

Measured memory_bytes: 32332
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp make_pair
#define F first
#define S second
#define pf pop_front
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
typedef long long ll;
const ll mod=1e9+7;
const ll maxn=100005;
const ll inf=1e9+7;
ll dp[maxn];
ll n,k;
ll a[maxn];
int main()
{
    cin>>n>>k;
    memset(dp,0,sizeof(dp));
    rep(i,n) cin>>a[i];
    for(int i=0;i<=k;i++)
    {
        if(!dp[i])
        rep(j,n)
        {
            if(i+a[j]<=k) dp[i+a[j]]=1;
        }
    }
    if(dp[k]) cout<<"First\n";
    else cout<<"Second\n";

}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

struct Point {
  double x, y;
};

void koch(int n, Point a, Point b) {
  if (n == 0)
    return;

  Point s, t, u;
  double th = M_PI * 60.0 / 180.0;
  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n - 1, a, s);
  printf("%.8f %.8f\n", s.x, s.y);
  koch(n - 1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  koch(n - 1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  koch(n - 1, t, b);
}

int main(void) {
  Point a, b;
  int n;
  cin >> n;
  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;

  printf("%.8f %.8f\n", a.x, a.y);
  koch(n, a, b);
  printf("%.8f %.8f\n", b.x, b.y);
}



Measured memory_bytes: 3212
# abc159_c.py
# https://atcoder.jp/contests/abc159/tasks/abc159_c

# C - Maximum Volume /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# 正の整数 Lが与えられます。 
# 縦、横、高さの長さ (それぞれ、整数でなくてもかまいません) の合計が Lの直方体としてありうる体積の最大値を求めてください。

# 制約
#     1≤L≤1000
#     Lは整数

# 入力
# 入力は以下の形式で標準入力から与えられる。
# L

# 出力
# 縦、横、高さの長さの合計が Lの直方体としてありうる体積の最大値を出力せよ。 
# なお、想定解答との絶対誤差または相対誤差が 10−6以下であれば正解として扱われる。

# 入力例 1
# 3

# 出力例 1
# 1.000000000000

# 例えば 縦 0.8、横 1 、高さ 1.2 の直方体の体積は 0.96です。
# 一方、縦 1、横 1 、高さ 1 とすると直方体の体積は 1で、より体積が大きいです。

# 入力例 2
# 999

# 出力例 2
# 36926037.000000000000


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    L = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = (L/3)**3

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3']
        lines_export = [1.000000000000]
    if pattern == 2:
        lines_input = ['999']
        lines_export = [36926037.000000000000]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9484
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
class edge{
public:
	int t,w;
	edge(){}
	edge(int t,int w):t(t),w(w){}
};
#define MAX 100010
vector<vector<edge> >G(MAX);
int n,d[MAX];
bool vis[MAX];
int cnt;
void bfs(int s){
	rep(i,n)d[i]=inf;
	queue<int>q;
	q.push(s);
	d[s]=0;
	int u;
	while(!q.empty()){
		u=q.front();q.pop();
		rep(i,G[u].size()){
			edge e=G[u][i];
			if(d[e.t]==inf){
				d[e.t]=d[u]+e.w;
				q.push(e.t);
			}
		}
	}
}
void solve(){
	bfs(0);
	int maxv=0;
	int tgt=0;
	rep(i,n){
		if(d[i]==inf)continue;
		if(maxv<d[i]){
			maxv=d[i];
			tgt=i;
		}
	}
	bfs(tgt);
	maxv=0;
	rep(i,n){
		if(d[i]==inf)continue;
		maxv=max(maxv,d[i]);
	}
	cout<<maxv<<endl;
}
int main(){
	int s,t,w;
	cin>>n;
	rep(i,n-1){
		cin>>s>>t>>w;
		G[s].pb(edge(t,w));
		G[t].pb(edge(s,w));
	}
	solve();
}

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

int main(){

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

    int cur = 0;
    for(int i = 0; i < 2 * n; i++){
        if(cur == 1){
            cout << i << endl;
            return 0;
        }
        cur = a[cur];
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;
 
typedef long long i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
  i64 from, to, cost;
  edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
  edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//-----end of template-----//

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int d;
	cin >> d;
	string s = "Christmas";
	for(int i = 0; i < 25 - d; ++i) s += " Eve";
	cout << s << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
typedef long long ll;

vector<int> primes;
bool sieve[40000];

int main() {
  fill(sieve, sieve + 40000, true);
  sieve[0] = sieve[1] = false;
  for (int i = 2; i < 40000; ++i) {
    primes.push_back(i);
    for (int j = i+i; j < 40000; j+=i) 
      sieve[j] = false;
  }
  
  vector<int> a(3), m(3), lens(3);
  while (cin >> a[0] >> m[0], a[0]) {
    rep(i,2) cin >> a[i+1] >> m[i+1];
    rep(i,3) {
      int len = 0, cur = 1;
      do {
        cur = cur * a[i] % m[i];
        ++len;
      } while (cur != 1);
      lens[i] = len;
    }
    vector<vector<int> > prime_count(3, vector<int>(40000, 0));
    for (int i = 0; i < 3; ++i) {
      int value = lens[i];
      // printf("[%d]\n", value);
      for (int j = 0; j < primes.size() && value > 0; ++j) {
        while (value % primes[j] == 0) {
          value /= primes[j];
          ++prime_count[i][ primes[j] ];
          // printf(" %d\n", primes[j]);
        }
      }
    }

    ll ans = 1;
    for (int i = 0; i < primes.size(); ++i) {
      int MaxC = -1;
      rep(j,3) MaxC = max(prime_count[j][ primes[i] ], MaxC);
      rep(j,MaxC) ans *= primes[i];
    }
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 0
function Main(input) {
    input = input.split(" ").map(Number);
    var a = input[0];
    var b = input[1];
    var c = input[2];
    var ans = Math.max(0, c - (a - b));
    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  if (s.length() <= k) {
    cout << s << endl;
  } else {
    cout << s.substr(0, k) << "..." << endl;
  }
}


Measured memory_bytes: 3456
N = int(input())
a = list(map(int, input().split()))
a_avg = sum(a) / len(a)
ai_min = 0  # 最も小さいフレーム番号
d_min = abs(a[0] - a_avg)  # ai_minが持つ平均値との距離
for i in range(1, N):
    d = abs(a[i] - a_avg)
    if d < d_min:
        ai_min = i
        d_min = d
print(ai_min)


Measured memory_bytes: 3060
import math
N, M = map(int,input().split())
st = dict()
cp = dict()
for i in range(N):
    st[i+1] = list(map(int,input().split()))

for j in range(M):
    cp[j+1] = list(map(int,input().split()))

for k in st.keys():
    a, b = st[k]
    ans = dict()
    for l in cp.keys():
        c, d = cp[l]
        pi = abs(a-c) + abs(b-d)
        ans[l] = pi
    st[k] = min(ans,key=ans.get)
        

for m in st.keys():
    print(st[m])



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

struct Card { char suit, value;};

void bubble(struct Card A[], int N){
  for( int i = 0; i < N; i++){
    for(int j = N -1; j >= i; j--){
      if(A[j].value < A[j-1].value){
	Card t = A[j]; A[j] = A[j - 1]; A[j - 1] = t;
      }
    }
  }
}

void selection(struct Card A[], int N){
  for ( int i = 0; i < N; i++){
    int minj = i;
    for( int j = i; j < N; j++){
      if (A[j].value < A[minj].value) minj = j;
    }
  Card t = A[i]; A[i] = A[minj]; A[minj] = t;
  }
}

void print(struct Card A[], int N){
  for(int i = 0; i < N; i++){
    if(i > 0) cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[],struct Card C2[], int N){
  for( int i = 0; i < N; i++ ){
    if ( C1[i].suit != C2[i].suit) return false;
  }
  return true;
}

int main(){
  Card C1[100],C2[100];
  int N;
  char ch;

  cin >> N;
  for ( int i = 0; i < N; i++ ){
    cin >> C1[i].suit >> C1[i].value;
  }

  for(int i = 0; i < N; i++)C2[i] = C1[i];

  bubble(C1,N);
  selection(C2, N);

  print(C1, N);
  cout << "Stable" << endl;
  print(C2, N);
  if (isStable(C1,C2,N)){
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a <= 5) {
			System.out.println(0);
		} else if (a <= 12) {
			System.out.println(b / 2);
		} else {
			System.out.println(b);
		}
	}
}


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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

signed main(){
    string S;
    int Q;
    cin >> S >> Q;
    int t, f;
    char c;
    int rev = 1;
    REP(i, Q){
        cin >> t;
        if(t == 1){
            rev *= -1;
            continue;
        }
        cin >> f >> c;
        f = ((f == 1) ? 1 : -1);
        if(rev * f == 1){
            S.insert(S.begin(), c);
        }else{
            S.push_back(c);
        }
    }
    if(rev == -1) reverse(ALL(S));
    PRINT(S);
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m, k;
	cin >> n >> m >> k;
	REP(i, n + 1) {
		REP(j, m + 1) {
			if (i*m + n*j - 2*i*j == k) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256