akhauriyash/Code-Regression huggingface dataset:
def calc_cost(a, i):
    cost = 0
    for num in a:
        cost += (num - i) ** 2
    return cost


if __name__ == '__main__':
    N = int(input())
    a = [int(x) for x in input().split()]
    max_num = max(a)
    min_cost = calc_cost(a, a[0])
    for i in range(-100, 101):
        cost = calc_cost(a, i)
        if cost < min_cost:
            min_cost = cost
    print(min_cost)


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

using namespace std;

/*helpfull*/
using vl  = vector<long long>;
using vpl = vector<pair<long long, long long>>;
using vs = vector<string>;
using pl  = pair<long long, long long>;
using ll  = long long int;
using vb  = vector<bool>;


struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1> {}(p.first);
        auto hash2 = hash<T2> {}(p.second);
        return hash1 ^ hash2;
    }
};
// #ifndef ONLINE_JUDGE
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);
// #endif

// shortcut macros
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp              make_pair
#define fi              first
#define se              second
// #define mt              make_tuple
#define pb              push_back
#define all(x)          (x).begin(), (x).end()
#define ini(a, v)       memset(a, v, sizeof(a))
#define rep(i, a, n)    for(ll i=a ; i<n ; ++i)
#define For(i, n)       rep(i, 0, n)
#define sz(x)           (int((x).size()))
#define ump(x,y)        unordered_map<x,y>
#define umpr(x,y,z)     unordered_map<x,y,z>
void printcase(ll &x) {
    cout << "Case #" << x << ": ";
}
void read(vector<ll>&v, ll &n) {
    For(i, n)
    cin >> v[i];
}
void read(ll &x) {
    cin >> x;
}
void read(string &s) {
    cin >> s;
}
void read(int &x) {
    cin >> x;
}
void read(ll a[], ll &n) {
    For(i, n)
    cin >> a[i];
}
void print() {
    cout << endl;
}
void write(vector<ll>&v, ll &n) {
    For(i, n)
    cout << v[i] << " ";
    cout << endl;
}
void write(vector<ll>&v) {
    ll n = v.size();
    For(i, n)
    cout << v[i] << " ";
    cout << endl;
}
void write(ll x) {
    cout << x << endl;
}
void write(string &s) {
    cout << s << endl;
}
void write(int &x) {
    cout << x << endl;
}
void write(ll a[], ll &n) {
    For(i, n)
    cout << a[i] << " ";
    cout << endl;
}


ll frogA(int i, vl &h, vl &dp, ll &n) {
    if (i == n - 1)
        return 0;
    if (dp[i] != -1) return dp[i];

    ll j2;
    ll j1 = abs(h[i] - h[i + 1]) + frogA(i + 1, h, dp, n);

    if (i + 2 <= n - 1)
        j2 = abs(h[i] - h[i + 2]) + frogA(i + 2, h, dp, n);
    else {
        dp[i] = j1;
        return dp[i];
    }


    dp[i] = min(j1, j2);
    return dp[i];
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    ll n;
    cin >> n;
    vl h(n), dp(n, -1);
    For(i, n)
    cin >> h[i];
    cout << frogA(0, h, dp, n) << endl;
    return 0;
}




Measured memory_bytes: 10940
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
using namespace std;

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

    int len = s.length();
    int i;

    int count = 0;
    for(i = 0; i < len / 2; i ++)
    {
    	if(s[i] != s[len - i - 1])
    		count ++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int n, m;
vector< vector<int> > edg;
vector< int > deg, day;
int d2i(int x, int y){
    if(x > y) return d2i(y, x);
    return x + (y-1)*y/2;
}
int main(void){
    cin >> n;
    m = n*(n-1)/2;
    edg.assign(m, vector<int>());
    deg.assign(m, 0);
    day.assign(m, 0);
    for(int i=0;i<n;i++){
        int b;
        cin >> b;
        b = d2i(i, --b);
        for(int j=1;j<n-1;j++){
            int a;
            cin >> a;
            a = d2i(i, --a);
            edg[b].push_back(a);
            deg[a]++;
            b = a;
        }
    }
    int ans = 0, cnt = 0;
    queue<int> q;
    for(int i=0;i<m;i++){
        if(deg[i] == 0){
            q.push(i);
            day[i] = 1;
        }
    }
    while(!q.empty()){
        int v = q.front();
        q.pop();
        if(ans < day[v]) ans = day[v];
        cnt++;
        for(int x : edg[v]){
            if(--deg[x] == 0){
                q.push(x);
                day[x] = day[v] + 1;
            }
        }
    }
    if(cnt < m) ans = -1;
    cout << ans << endl;
}


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

signed main(void)
{
	int n, m;
	bool ok;
	cin >> n >> m;
	string a[n], b[m];
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i];
	rep(k, n - m + 1) rep(l, n - m + 1)
	{
		ok =true;
		rep(i, m) 
		{
			rep(j, m)
			{
				if (a[i + k][j + l] != b[i][j])
					ok = false;
			}
		}
		if (ok)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin >> s;
	int x = 0, maxi = 0;
	for(int i = 0; i < (int)s.size(); i++){
		if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')
			x ++;
		else
			x = 0;
		maxi = max(maxi, x);
	}
	cout << maxi;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}

inline void solve(void){
  string s;
  in(s);
  for(int i=0,j=7;i<8&&j>=0;i++,j--){
    if(s.substr(0,i)+s.substr(s.size()-j,j)=="keyence"){
      out("YES");
      return;
    }
  }
  out("NO");
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
S = str(input())
Reverse_S = S[::-1]
N = len(S)
R = S[:(N-1)//2]
Reverse_R = R[::-1]
L = S[N+3//2:]
Reverse_L = L[::-1]

if S==Reverse_S and R==Reverse_R and L==Reverse_L:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
import itertools
import bisect

def main():
    N,M,K  = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    AS = list(itertools.accumulate(A))
    BS = list(itertools.accumulate(B))
    Amaxin = bisect.bisect_right(AS, K)
    Bmaxin = bisect.bisect_right(BS, K)
    ans = max(Amaxin-1,Bmaxin-1)
    index = 0
    for i in reversed(range(0,Amaxin)):
        while index<M and AS[i] + BS[index] <=K:
            index+=1
        ans = max(i+index+1,ans)
    index = 0
    for i in reversed(range(0,Bmaxin)):
        while index<N and BS[i] + AS[index] <=K:
            index+=1
        ans = max(i+index+1,ans)

    print(max(ans,0))

if __name__ == '__main__':
    main()


Measured memory_bytes: 131152
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String str = in.next();
            int ans = 0;
            for (char c : str.toCharArray()) {
                if (c == '1') {
                    ans++;
                }
            }
            out.print(ans);
        }

    }
}



Measured memory_bytes: 21844
a = [0 for i in range(3)]
b = [0 for i in range(3)]
c = []
c.append(list(map(int,input().split())))
c.append(list(map(int,input().split())))
c.append(list(map(int,input().split())))
ans = 'Yes'
b[0] = c[0][0]
b[1] = c[0][1]
b[2] = c[0][2]
a[1] = c[1][0] - b[0]
a[2] = c[2][0] - b[0]
for i in range(3):
    for j in range(3):
        if a[i] + b[j] != c[i][j]:
            ans = 'No'
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
	int a[1000][3],n=0,k,i,j,m,p;
	scanf("%d",&k);
	for(i=0;i<k;i++){
		scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
		for(j=0;j<3;j++){
			for(m=j;m<3;m++){
				if(a[i][j]<a[i][m]){
					p=a[i][j];
					a[i][j]=a[i][m];
					a[i][m]=p;
				}
			}
		}
	}
	p=1001;
	for(i=0;i<k;i++){
		for(j=0;j<k;j++){
			if(i==j)continue;
			else if(a[i][0]==a[j][0] && a[i][1]==a[j][1] && a[i][2]==a[j][2]){
				++n;
				a[j][0]=p;
				a[j][1]=p+1;
				a[j][2]=p+2;
				p+=3;
			}
		}
	}
	printf("%d\n",n);
	return 0;
}


Measured memory_bytes: 2120
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> vec(200);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }

    std::map<int, int> mp;
    std::sort(vec.begin(),vec.end(),std::greater<int>());
    int count = 0;
    for (int i = 0; i < N; i ++) {
	    int val = vec[i];
	    if (mp[val] == 0) {
		    count += 1;
		    mp[val] = 1;
	    }
    }

    cout << count << endl;


    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

struct engine{
	long double x,y;
	bool operator<(const engine &rhs){
		return (atan2(x,y)<atan2(rhs.x,rhs.y));
	}
	bool operator<=(const engine &rhs){
		return (atan2(x,y)<atan2(rhs.x,rhs.y));
	}
};

vector<engine> v;

int main(void){
	int n,i,j;
	long double x,y,ans=0.0;
	engine e;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> x >> y;
		e.x = x; e.y = y;
		if(!(x==0.0 && y==0.0)){
			v.push_back(e);
		}
	}
	sort(v.begin(),v.end());
	n = v.l_ength();
	for(i=0; i<n; ++i){
		x = 0.0; y = 0.0;
		for(j=0; j<n; ++j){
			e = v[(i+j)%n];
			x += e.x;
			y += e.y;
			ans = max(ans,sqrt(x*x+y*y));
		}
	}
	cout << fixed << setprecision(50) << ans << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ATCode_Five_Antennas
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());
            int d = int.Parse(Console.ReadLine());
            int e = int.Parse(Console.ReadLine());
            int k = int.Parse(Console.ReadLine());

            if (e - a <= k)
            {
                Console.WriteLine("Yay!");
            }
            else
            {
                Console.WriteLine(":(");
            }
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int main() {
  int N;
  cin >> N;
  LL ksum = 0, sum = 0;
  REP(i, N) {
    LL D, C;
    cin >> D >> C;
    ksum += C;
    sum += C * D;
  }
  LL ret = ksum - 1 + (sum - 1) / 9;
  cout << ret << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;


int a[100010];
int seg[100010];
int main(void){
	int n, t; cin >> n >> t;
	int dai = 0;
	rep(i, n){
		cin >> a[i];
	}

	int ma = 0;
	for (int i = n - 1; i >= 0 ; --i){
		if(a[i] > ma){
			seg[i] = a[i];
			ma = a[i];
		}else{
			seg[i] = ma;
		}
	}


	multiset<int> mult;
	int ans = 0;
	rep(i, n - 1){
		int now = a[i];
		// printf("%d %d\n", seg[i + 1], now);
		mult.insert(seg[i + 1] - now);
		chmax(ans, seg[i + 1] - now);
	}
	// printf("%d\n", ans);
	printf("%d\n", mult.count(ans));
	return 0;
}

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

const int N = 1e5 + 5;

map <int, int> Map;
map <int, vector <int> > pos;

int n, m, x, y, A[N], B[N], C[N];

#define Exit exit(0 * puts("-1"))

map <int, int> fa;

int getf(int x) {
  if(fa[x] == x) return x;
  return fa[x] = getf(fa[x]);
}

int main() {
  scanf("%d", &n);
  int cur = 0;
  for(int i = 1; i <= n; ++ i)
    scanf("%d", &A[i]), ++ Map[A[i]], cur ^= A[i];
  A[n + 1] = cur;
  int now = 0;
  ++ Map[cur];
  for(int i = 1; i <= n; ++ i) {
    scanf("%d", &B[i]);
    now ^= B[i];
    -- Map[B[i]];
    if(Map[B[i]] < 0) {
      //assert(0);
      Exit;
    }
  }
  //throw;
  B[++ n] = now;
  for(int i = 1; i <= n; ++ i) if(A[i] != B[i] || i == n){
      fa[A[i]] = A[i];
      fa[B[i]] = B[i];
  }
  int tot = 0;
  for(int i = 1; i < n; ++ i) tot += (A[i] != B[i]);
  if(!tot) {
    puts("0");
    return 0;
  }
  for(int i = 1; i <= n; ++ i) {
    if(A[i] != B[i] || i == n) {
      fa[getf(A[i])] = getf(B[i]);
    }
  }
  //cerr << "HERE" << endl;
  set <int> S;
  for(int i = 1; i <= n; ++ i) {
    if(fa.count(A[i])) S.insert(getf(A[i]));
    if(fa.count(B[i])) S.insert(getf(B[i]));
  }
  tot += S.size();
  -- tot;
  cout << tot << endl;
}


Measured memory_bytes: 19840
import numpy

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(numpy.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

x = int(input())

while(1):
    if is_prime(x) == 1:
        break
    else:
        x = x + 1

print(x)

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

using ll=long long;

main(){
    int n,we;
    cin >> n >> we;
    int w[n],v[n];
    for (int i=0;i<n;i++) cin >> w[i] >> v[i];
    ll dp[n+1][we+1] = {};
    for (int i=1;i<n+1;i++){
        for (int i2=1;i2<we+1;i2++){
            if (i2<w[i-1]){
                dp[i][i2]=dp[i-1][i2];
            }
            else{
                dp[i][i2]=max(dp[i-1][i2],dp[i-1][i2-w[i-1]]+v[i-1]);
            }
        }
    }
    cout << dp[n][we] << endl;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
     
#define int long long
#define ll long long
#define f(i,l,n) for(int i=l;i<n;i++)
#define E "\n"
#define Outerloop int q;cin>>q;while(q--)
#define Mod 1000000007
#define N 1e5
string ans,s,t;
int dp[3005][3005];

void solve(int i,int j)
{
	if(i==0 || j==0) return ;
	if(dp[i][j]==1+dp[i-1][j-1] && t[j-1]==s[i-1])
	{
		ans=s[i-1]+ans;
		solve(i-1,j-1);
	}
	else
	{
		if(dp[i][j-1]>dp[i-1][j])
		{
			solve(i,j-1);
		}
		else solve(i-1,j);
	}
}
    int32_t main()
    {
    	
    	cin >> s >> t;
    	int n=s.size(),m=t.size();
    	
    	
    	f(i,1,n+1)
    	{
    		f(j,1,m+1)
    		{
    			if(s[i-1]==t[j-1])
    			{
    				dp[i][j]=1+dp[i-1][j-1];
    			}
    			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    		}
    	}
    	solve(n,m);
    	cout<<ans;
    return 0;
    }

Measured memory_bytes: 70912
import java.util.*;
import java.util.stream.Collectors;


public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        final String s=scanner.next();
        final int K=scanner.nextInt();
        final String alphabet="abcdefghijklmnopqrstuvwxyz";
        Set<String> sets=new HashSet<>();
        for(int i=0;i<s.length();i++){
            for(int j=i+1;j<=Math.min(s.length(),i+6);j++){
                sets.add(s.substring(i,j));
            }
        }
        System.out.println(sets.stream().sorted().collect(Collectors.toList()).get(K-1));


    }

}


Measured memory_bytes: 31480
a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

ans=min(a)+min(b)

for i in range(m):
    p,q,r=map(int,input().split())
    ans=min(a[p-1]+b[q-1]-r,ans)
print(ans)


Measured memory_bytes: 18648
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;
typedef pair<int, int> P; 

int main() {
  int n,m,ans = 0;
  cin >> n >> m;
  vector<int> x(m);
  vector<int> a(m-1);
  
  REP(i,m){
    cin >> x[i];
  }
  sort(x.begin(),x.end(),greater<int>());
  REP(i,m-1){
    a[i] = x[i] - x[i+1];
  }
  sort(a.begin(),a.end());  
  
  if(m > n){
    REP(i,m-n){
      ans += a[i];
    }
    cout << ans << endl;
  }
  else{
    cout << 0 << endl;
  }
  
}


Measured memory_bytes: 4124
s = input()
k = int(input())

cand = set()
for i in range(len(s)):
  for j in range(i+1, i+k+1):
    if j >len(s):
      continue
    cand.add(s[i:j])
listcand = list(cand)
listcand.sort()
print(listcand[k-1])


Measured memory_bytes: 68852
#include<iostream>
#include<vector>
using namespace std;
const int mod = 1e9 + 7;
vector<vector<int>> dp, vis;
int path(vector<vector<int>>& arr, int row, int col, int i, int j) {
	if (i >= row || j >= col) {
		return 0;
	}
	if (arr[i][j] == 1) {
		return 0;
	}
	if (i == row - 1 && j == col - 1) {
		return 1;
	}
	int& ans = dp[i][j];
	if (vis[i][j] == 1) {
		return ans;;
	}
	vis[i][j] = 1;
	int rightMove = path(arr, row, col, i, j + 1)%mod;
	int downMove = path(arr, row, col, i + 1, j)%mod;
	ans = (rightMove + downMove)%mod;
	return ans;
}

int main() {
	int row, col;
	cin >> row >> col;
	vector<vector<int>> arr(row, vector<int>(col, 0));
	for (int i = 0; i < row; i++) {
		for (int j = 0; j < col; j++) {
			char ch; 
			cin >> ch;
			if (ch == '.') {
				arr[i][j] = 0;
			}
			else {
				arr[i][j] = 1;
			}
		}
	}
	if (arr[row - 1][col - 1] == 1) {
		cout << "0" << endl;
		return 0;
	}
	dp.resize(row, vector<int>(col, 0));
	vis.resize(row, vector<int>(col, 0));
	cout << path(arr, row, col, 0, 0);
	return 0;
}

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

#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(x) (x).begin(),x.end()
#define watch(x) cout<<#x<<" = "<<x<<endl;
#define V(x) vector<x>
#define P(x,y) pair<x,y>
#define UMP(x,y) unordered_map<x,y>
#define MP(x,y) map<x,y>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef double db;
const ll mod = 1000000007;

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	//int t;
	//cin>>t;
	//rep(l,0,t){
		int n;
		cin>>n;
		ld sum=0;
		rep(i,1,n+1){
			if(i%3 !=0 && i%5!=0)
				sum+=i;
		}
		printf("%.0Lf",sum);
	//}

	
	return 0;
}



Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


vector<int> di = {0,1};
vector<int> dj = {1,0};

int main() {
  int h,w; cin >>h >>w;
  vector<vector<int>> field(h, vector<int>(w));
  rep(i, h) rep(j, w) cin >>field[i][j];
  int n = 0;
  queue<int> que;
  rep(i, h){
    rep(j, w){
      if (field[i][j] % 2 == 0) continue;
      // 奇数なら右か下に1押し付ける
      rep(k, di.size()){
        int ni = i + di[k];
        int nj = j + dj[k];
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        field[ni][nj]++;
        field[i][j]--;
        que.push(i+1); que.push(j+1);
        que.push(ni+1); que.push(nj+1);
        n++;
        break;
      }
    }
  }
  cout <<n <<endl;
  rep(i, n){
    rep(j, 4){
      cout <<que.front();
      if (j == 3) cout <<endl;
      else cout <<" ";
      que.pop();
    }
  }
}


Measured memory_bytes: 5120
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
M = 10**9 + 7

pre = a[0]
for v in a[1:]:
    pre = pre * v // gcd(pre, v)
# print(pre)
# print([pre // v for v in a])
print(sum(pre // v for v in a) % M)


Measured memory_bytes: 6072
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double R;
    cin >> R;

    double ans = 2 * R * 3.1415926535;
    printf("%f\n", ans);
    return 0;
}

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

struct Node {
    int left, right, parent;
};
Node a[25];

int searchRoot(int n, Node a[]) {
    Node tmp;
    int i;
    for (i = 0; i < n; i++) {
        if (a[i].parent == i) break;
        tmp.parent = a[i].parent;
    }
    return i;
}
void Preparse(int u) {
    if (u == -1) return;
    cout << " " << u;
    Preparse(a[u].left);
    Preparse(a[u].right);
}
void Inparse(int u) {
    if (u == -1) return;
    Inparse(a[u].left);
    cout << " " << u;
    Inparse(a[u].right);
}
void Postparse(int u) {
    if (u == -1) return;
    Postparse(a[u].left);
    Postparse(a[u].right);
    cout << " " << u;
}
int main() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        a[i].parent = i;
    }
    int id, left, right;
    for (int i = 0; i < n; i++) {
        cin >> id >> left >> right;
        a[id].left = left;
        a[id].right = right;
        a[left].parent = id;
        a[right].parent = id;
    }
    int tmp = searchRoot(n, a);
    cout << "Preorder" << endl;
    Preparse(tmp);
    cout << endl;
    cout << "Inorder" << endl;
    Inparse(tmp);
    cout << endl;
    cout << "Postorder" << endl;
    Postparse(tmp);
    cout << endl;
    
    return 0;
}



Measured memory_bytes: 3100
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

#define all(v) 			((v).begin()), ((v).end())
#define sz(v) 			((int)((v).size()))
#define endl			"\n"
#define MOD             1000000007

typedef long long ll;

void File()
{
	//freopen("output.txt", "w", stdout);
	freopen("coffee.in", "r", stdin);
}
void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
}
const double pi = 2 * acos(0.0);
const int nn = 1e5 + 5;
const int oo = 0x3f3f3f3f;

int main()
{
	fast();
	int n;
	cin >> n;
	ll sum = 0;
	int mx = 0;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		sum += x;
		mx = max(mx, x);
	}
	sum -= mx;
	sum += (mx / 2);
	cout << sum << endl;
#if _DEBUG
	system("pause");
#endif
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000 + 10;
const int M = 1000000007;
const double PI = atan(1) * 4;
const int oo = 1000000000;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define pb push_back 
#define all(c) (c).begin(),(c).end()
int n,p,v[51];
ll dp[51][2];
ll calc(int u, int d){
	if(u==n)return d==p;
	if(dp[u][d]!=-1)return dp[u][d];
	return dp[u][d]=calc(u+1,d)+calc(u+1,(d+v[u])%2);
}
int main(){
	cin>>n>>p;
	for(int i=0; i<n; ++i)
		cin>>v[i];
	memset(dp,-1,sizeof(dp));
	cout<<calc(0,0)<<endl;
}




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

int main() {
    double a,b,h,m,pi=3.14159265358979;
    cin>>a>>b>>h>>m;
    double j=h+(m/60);
    double jr=j/6*pi,mr=m/30*pi;
    double ans=sqrt(pow(a*cos(jr)-b*cos(mr),2)+pow(a*sin(jr)-b*sin(mr),2));
    cout<<setprecision(14)<<ans;
	return 0;
}

Measured memory_bytes: 4072
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
	#endif
}

int dpx[8]={1,1,1,-1,-1,-1,0,0};
int dpy[8]={-1,1,0,1,-1,0,-1,1};

int32_t main()
{
	fastIO
	inp_out();
	int l, r, k; 
	cin  >> l >> r >> k; 

	int val  = k, ans = 0; 
	while(k <= r)
	{
		if(k >= l)
			 ++ ans; 
		k  += val; 
	}

	cout << ans; 
	return 0;
}

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

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}

template <typename T> inline bool CheckMax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}

template <typename T> inline bool CheckMin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}

const int N = 1048580;
const int M = 25;

int n, m, len, ans, f[M][N], g[M][N];
char s[N];

int main() {
#ifdef wxh010910
  freopen("d.in", "r", stdin);
#endif
  Read(n), Read(m);
  for (int i = 0; i <= n; ++i) {
    scanf("%s", s);
    for (int j = 0; j < 1 << i; ++j) {
      if (s[j] == '1') {
        f[i][j] = 1;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 1 << i; ++j) {
      int b = j >> (i - 1) & 1, r = 0;
      for (; r < i && (j >> i - r - 1 & 1) == b; ++r);
      g[i][j] = r == i ? -1 : r;
    }
  }
  for (int i = 0; i <= n; ++i) {
    for (int j = 1; i + j <= n; ++j) {
      for (int k = 0; k < 1 << i + j; ++k) {
        f[i][k >> j] += f[i + j][k];
        int t = g[j][k & (1 << j) - 1];
        if (~t) {
          f[i + j - t][(k >> j << j - t) | (k & (1 << j - t) - 1)] += f[i + j][k];
        }
      }
    }
    for (int j = (1 << i) - 1; ~j; --j) {
      if (f[i][j] >= m) {
        len = i, ans = j;
      }
    }
  }
  for (int i = len - 1; ~i; --i) {
    putchar((ans >> i & 1) + '0');
  }
  putchar(10);
#ifdef wxh010910
  Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}


Measured memory_bytes: 101632
class Node:
    def __init__(self, data):
        self.data = data
        self.parent = self

def find_root(node):
    if node.parent == node:
        return node

    else:
        node.parent = find_root(node.parent)
        return node.parent

def unite(x, y):
    x_root = find_root(x)
    y_root = find_root(y)
    if x_root == y_root:
        return
    else:
        y_root.parent = x_root

def same(x, y):
    if find_root(x) == find_root(y):
        print(1)
    else:
        print(0)


if __name__ == '__main__':
    n, q = map(int, input().split())

    nodeset = []
    for i in range(n):
        nodeset.append(Node(i))

    for i in range(q):  
        com, x, y = map(int, input().split())
        x_node = nodeset[x]
        y_node = nodeset[y]
        if com == 0:
            unite(x_node, y_node)
        else:
            same(x_node, y_node)


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

int main(){
  long N;
  string S;
  cin >> N >> S;
  
  long len = S.length(); 
  long cntL = 0;
  string tmpL = "";
  for(int i = 0; i < len; i++){
    if(S[i] == '('){
      cntL += 1;
    }
    if(S[i] == ')'){
      cntL -= 1;
    }
    if(cntL < 0){
      tmpL = '(' + tmpL;
      cntL = 0;
    }
  }
  long cntR = 0;
  string tmpR = "";
  for(int i = len-1; i >= 0; i--){
    if(S[i] == ')'){
      cntR += 1;
    }
    if(S[i] == '('){
      cntR -= 1;
    }
    if(cntR < 0){
      tmpR = tmpR + ')';
      cntR = 0;
    }
  }
  S = tmpL + S + tmpR;
  cout << S;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;


int main() {

    lli N;
    cin >> N;

    vector<lli> A(N);

    for (lli i = 0; i < N; ++i) {
        cin >> A[i];
    }

    vector<lli> ACopy = A;
    sort(ACopy.begin(), ACopy.end());
    lli first = ACopy[N - 1];
    lli second = ACopy[N - 2];


    for (lli i = 0; i < N; ++i) {
        lli num = A[i];
        if (num == first) {
            cout << second << endl;
        } else {
            cout << first << endl;
        }
    }

    return 0;
}

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

int main() {
  int a,b;
  cin >> a>>b;
  if((a+b)%2==0) cout << (a+b)/2 <<endl;
  else cout << "IMPOSSIBLE" <<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

int n, m;
vector<vi> graph;
int ans = 0;

void dfs(int i, set<int> path) {
  if(path.size() == n - 1)
    ans++;
  else {
    path.insert(i);
    for(auto v : graph[i])
      if(!path.count(v)) dfs(v, path);
  }
}

int main() {
  cin >> n >> m;
  graph = vector<vi>(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    graph[a - 1].push_back(b - 1);
    graph[b - 1].push_back(a - 1);
  }
  dfs(0, {});
  cout << ans << endl;
}

Measured memory_bytes: 256
h, w, k = gets.to_s.split.map{|t|t.to_i}
s = Array.new(h){ gets.to_s.chomp }

ans = 0
[0, 1].repeated_permutation(h+w) do |bit|
  m = s.dup
  cnt = 0
  h.times do |i|
    w.times do |j|
      cnt += 1 if m[i][j] == '#' && bit[i] == 0 && bit[h+j] == 0
    end
  end
  ans += 1 if cnt == k
end

puts ans

Measured memory_bytes: 14404
#include <bits/stdc++.h> 
using namespace std; 
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main(void) {
    io;
    string str;
    getline(cin,str);
    bool space = false;
    int len = (int) str.size();
    cout << str[0];
    for (int i = 1; i< len; i++) {
        if ((space == true) && (str[i] != ' ')) {
            cout << str[i];
            space = false;
        }
        if (str[i] == ' ') space = true;
    }
    return 0;
}

Measured memory_bytes: 3584
#include <stdio.h>
int main( )
{
    double area,circumference,pi,r;
    pi=3.14159265358979323846;
    scanf("%lf",&r);

if (r>0 && r<10000)
    {
    area=pi*r*r;
    circumference=2*pi*r;

    printf("%lf %lf\n", area, circumference);
    }

return 0;
}



Measured memory_bytes: 2708
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int A[3];
    cin >> A[0] >> A[1] >> A[2];

    int cnt = 0;
    sort(A,A+3);
    int maxi = A[2];
    A[0] = maxi - A[0];
    A[1] = maxi - A[1];
    cnt += A[0]/2 + A[1]/2;
    A[0] %= 2;A[1] %= 2;
    if(A[0] & A[1]){
        cnt += 1;
    }else if(A[0] ^ A[1]){
        cnt += 2;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

for i,row in enumerate(a):
    for j,x in enumerate(row):
        if x in b:
            a[i][j] = 0
bingo = False
for row in a:
    if row == [0]*3:
        bingo = True
for j in range(3):
    if a[0][j] == 0 and a[1][j] == 0 and a[2][j] == 0:
        bingo = True
if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
    bingo = True
if a[0][2] == 0 and a[1][1] == 0 and a[2][0] == 0:
    bingo = True

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


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
double t[4]={0.2,0.6,1.1,9999999.9};
double a,b;
int ans[4][2];
int main(){
  for(int i=0;i<4;i++)for(int j=0;j<2;j++)ans[i][j]=0;
  while(cin>>a>>b){
    for(int i=0;i<4;i++){
      if(a<t[i]){
	ans[3-i][0]++;
	break;
      }
    }
    for(int i=0;i<4;i++){
      if(b<t[i]){
	ans[3-i][1]++;
	break;
      }
    }
  }
  for(int i=0;i<4;i++){
    cout<<ans[i][0]<<' '<<ans[i][1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#define INF 100000000
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < n; ++i)
#define out(x) cout << x << endl;
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;


// ABC117C - Streamline
// https://atcoder.jp/contests/abc117/tasks/abc117_c
void ABC117C() {
	int N, M;
	cin >> N >> M;

	vector<int> X(M);
	rep(i, M) {
		cin >> X[i];
	}
	sort(all(X)); //昇順


	/*
		各区間の距離を計算し、降順に並び替える
		距離が大きいものをN-1個を除外すると、残りが移動距離
	*/	
	vector<int> dist(M - 1); //区間の数は座標の個数-1なのでM-1
	rep(i, M - 1) {
		dist[i] = X[i + 1] - X[i]; //各区間の距離
		//out(dist[i]);
	}
	sort(all(dist), std::greater<int>()); //降順


	//移動距離の計算
	int ans = 0;
	for (int i = N-1; i < SZ(dist); i++) //距離が大きい区間(N-1個)は除外して距離を計算
	{
		ans += dist[i];
	}

	//出力
	out(ans);
}


int main() {
	ABC117C();

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int T, A;
	cin >> T >> A;
	vector<int> H(N);
	int res = 0;
	double mn = 1e9;
	double t;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
		t = T - 0.006 * H[i];
		if (mn > abs(A - t)) {
			mn = abs(A - t);
			res = i + 1;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <bitset>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int N;
vector<int> A;

int main(){
  cin>>N;
  int sum=0;
  for(int i=0;i<N;i++){
      int x;
      cin>>x;
      A.push_back(x);
      sum+=x;
  }

  bitset<2000*2000+1> dp;
  dp.set(0);
  for(int i=0;i<N;i++){
      bitset<2000*2000+1> tmp=dp;
      dp|=(dp<<A[i]);
  }

  for(int i=(sum+1)/2;i<=2000*2000;i++){
      if(dp[i]){
          cout<<i<<endl;
          return 0;
      }
  }



  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

ll n;
vector<ll> g[101010];

ll dfs(ll v,ll pre){
  ll res=0;
  ll csz=0,sum=0,aru=0;
  for(ll nv : g[v]){
    if(nv==pre)continue;
    ll t=dfs(nv,v);
    sum+=t;
    if(t>0)aru++;
    csz++;
  }
  return max(0LL,csz-1-aru)+sum;
}

int main(){
	cin>>n;
  rep(i,n-1){
    ll a,b;
    cin>>a>>b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ll p=-1;
  rep(i,n){
    if(g[i].size()>=3)p=i;
  }
  if(p==-1){
    cout<<1<<endl;
    return 0;
  }
  cout<<dfs(p,-1)<<endl;
	return 0;
}


Measured memory_bytes: 10368
function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n};

(() => {
    const [ n ] = readMany(1).map(it => parseInt(it))
    let powerMod = 1
    for (let i = 1; i <= n; i += 1) {
        powerMod = powerMod * i % (10 ** 9 + 7)
    }
    console.log(powerMod)
})()


Measured memory_bytes: 7500
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val h = sc.nextInt()
  val w = sc.nextInt()
  val s = (1..h).map { sc.next() }

  val ans = Array(h) { Array(w) { '0' } }

  for (i in 0 until h) {
    val si = s[i]
    for (j in 0 until w) {
      val c = si[j]
      if (c != '#') {
        continue
      }
      // c == '#'
      ans[i][j] = '#'
      if (j != 0) {
        // left mid
        if (ans[i][j-1] != '#') {
          ans[i][j - 1]++
        }
      }
      if (j != w - 1) {
        // right mid
        if (ans[i][j+1] != '#') {
          ans[i][j+1]++
        }
      }
      if (i != 0) {
        // center top
        if (ans[i-1][j] != '#') {
          ans[i-1][j]++
        }
      }
      if (i != h - 1) {
        // center bottom
        if (ans[i+1][j] != '#') {
          ans[i+1][j]++
        }
      }
      if (i != 0 && j != 0) {
        // left top
        if (ans[i-1][j-1] != '#') {
          ans[i-1][j-1]++
        }
      }
      if (i != 0 && j != w-1) {
        // right top
        if (ans[i-1][j+1] != '#') {
          ans[i-1][j+1]++
        }
      }
      if (i != h-1 && j != 0) {
        // left bottom
        if (ans[i+1][j-1] != '#') {
          ans[i+1][j-1]++
        }
      }
      if (i != h-1 && j != w-1) {
        // right bottom
        if (ans[i+1][j+1] != '#') {
          ans[i+1][j+1]++
        }
      }
    }
  }

  val tmp = mutableListOf<String>()
  for (ai in ans) {
    tmp.add(ai.joinToString(""))
  }

  println(tmp.joinToString("\n"))
}


Measured memory_bytes: 42240
#include<iostream> 
#include<vector> 
#include<algorithm> 
#include<iomanip> 
#include<stack> 
#include<unordered_map>
#include<queue> 
#include<deque>
#include<map> 
#include<climits>
#include<set> 
#include<string> 
//#include<time.h>
//#include<bits/stdc++.h> 
using namespace std; 
#define lld long long int 
#define eb emplace_back
//to insert pair use eb
#define mp make_pair
#define fi first
#define se second
#define pb push_back

#define X 1000000007
#define Y 998244353
#define E4 10000
#define E5 100000
#define E6 1000000
#define inf 2001001001001001001
#define pi 3.1415926535

# define rec2(i,a,n) for(lld i=a;i<n;i++) 
#define rec(i,n) for(lld i=0;i<n;i++)
#define rev(i,a,n) for(lld i=n-1;i>=a;i--)
#define all(v) (v).begin(), (v).end()
#define large(v)  *max_element(all(v))
#define small(v)  *min_element(all(v)) 
#define v vector 
#define p(x,y)  pair<x,y> 
const double EPS = 1e-6;

void google(int i)
{  cout<<"Case #"<<i<<": "; }

//prime[i]==1 if it is prime 
lld prime[E6+1]; 
void sieve(lld n) 
{ rec(i,n+1) 
    prime[i]=1; 
   for(lld i=2;i*i<=n;i++) 
     { if(prime[i]!=1) 
          continue; 
         for(lld j=i*i;j<=n;j=j+i) 
          if(prime[j]==1)
           prime[j]=i; 
      }
}

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

//fermat a^(m-2)%mod
lld binarymul(lld a,lld n,lld m)
{  lld res=1; 
 while(n) 
  { if(n%2) 
      { res=(res*a)%m; 
         n--; 
      } 
     a=(a*a)%m; 
     n/=2; 
  }
  return res; 
}
/*
void complexity(time_t end,time_t start)
{ 
  double taken = double(end - start); 
    cout<<"Time : "; 
    cout<<fixed<<taken<<setprecision(8);         cout<<" sec "<<endl;
}
*/ 
void bfs(lld s,v<lld> g[],lld n)
{ 
   bool vis[n]; 
   rec(i,n) 
    vis[i]=false; 
    
   vis[s]=true; 
   deque<lld> q; 
   q.pb(s); 
   
   while(!q.empty()) 
   {  
      s=q.front(); 
     q.pop_front(); 
      
     for(lld i=0;i<g[s].size();i++) 
      {  
        if(!vis[g[s][i]])
         { vis[g[s][i]]=true; 
            q.pb(g[s][i]); 
         }
      }
   }
}

void dfs(lld u,v<lld> g[],bool *vis)
{ 

   vis[u]=true; 
   for(lld i=0;i<g[u].size();i++) 
     if(!vis[g[u][i]])
          dfs(g[u][i],g,vis); 
       
}
void contest(lld t); 
int main()
{   
    /*
    time_t start, end; 
    time(&start); 
    */
   ios_base::sync_with_stdio(false); 
   cin.tie(0);
     #ifdef PUNEET_GOEL
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif
   //sieve(E6); 
    lld T=1; 
  
    rec(t,T) 
    {
      contest(t); 
    }
    /*
     time(&end); 
    complexity(end,start);
    */
	return 0;
}

void contest(lld t)
{ 
  string a; 
  cin>>a; 
  lld n=a.length(); 
  cout<<a; 
      if(a[n-1]=='s') 
       cout<<"es"; 
      else 
      cout<<"s"; 
   
}

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

int main(){
  int num;
  int max = 0;
  int cnt = 0;
  
  cin >> num;
  
  vector<int> vec(num);
  for(int i = 0; i < num; i++) cin >> vec.at(i);
  
  for(int i = 0; i < num; i++){
    if(vec.at(i) >= max){
      max = vec.at(i);
      cnt++;
    }
  }
  
  cout << cnt;
}


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

string str;
int n,a[100];
double ans;
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	ans=(double)a[1];
	for(int i=2;i<=n;i++){
		ans+=a[i];
		ans*=0.5;
	}
	printf("%.8lf",ans);
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;









int main(){
    int n;
    cin >> n;
    string ns = to_string(n);
    rep(i,ns.size()){
        if (ns[i] == '7'){
            cout << "Yes"; rn 0;
        }
    }
    cout <<"No";
    rn 0;
    
}
















Measured memory_bytes: 3696
// Aizu 1188: Hierarchical Democracy
// 2017.9.18 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char buf[10003];

int cmp(int *a, int *b) { return *a - *b; }

char *pair(char *p)
{
	int n = 0;
	while (1) {
		if (*p == '[') n++;
		else if (*p == ']') { n--; if (n < 0) break; }
		p++;
	}
	return p;
}

char *calc(char *p, int *v, int *half)
{
	int n, i, s, h;
	char *pp;
	int *t;

	pp = p, n = 0; while (*p == '[') p++, p = pair(p), p++, n++;
	if (n == 0) {
		s = 0; while (isdigit(*p)) s = s * 10 + *p++ - '0';
		*v = s, *half = 1; return p;
	}
	t = calloc(n, sizeof(int));
	p = pp; for (i = 0; i < n; i++) p++, p = calc(p, &s, &h), p++, t[i] = s;
	qsort(t, n, sizeof(int), cmp);
	for (s = 0, n >>= 1, i = 0; i <= n; i++) if (h) s += 1 + (t[i] >> 1); else s += t[i];
	free(t);
	*v = s, *half = 0;
	return p;
}

int main()
{
	int n, ans, t;
	char *p;

	scanf("%d", &n);
	while (n-- > 0) {
		scanf("%s", p = buf); p++;
		calc(p, &ans, &t);
		printf("%d\n", ans);
	}
	return 0;
}

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

int main(){
    int h,w,i,j;
    while(true){
        cin>>h>>w;
        if(h==0&&w==0)break;
        else{
            for(i=0;i<h;i++){
                for(j=0;j<w;j++){
                    cout<<"#";
                }
                cout<<"\n";
            }
            cout<<"\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3072