akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pci pair<char, int>
#define pic pair<int, char>
#define plvl pair<long long, vector<long long> >
#define pcvc pair<char, vector<char> >
#define mod 1e9 + 7
#define newl "\n"

using namespace std;

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

template <typename T>
void show1(vector<T> dp) {
	for(auto d : dp) {
		cout << d << " ";
	}
	cout << "\n";
}

template <typename T>
void show2(vector<vector<T> > dp) {
	for(auto d : dp) {
		for(auto dd : d) {
			cout << dd << " ";
		}
		cout << "\n";
	}
}

bool isPal(string s) {
	for(ll i = 0 ; i < s.length() ; i++) {
		if(s[i] != s[s.length() - 1 - i]) {
			return false;
		}
	}
	return true;
}

void executeCode() {
	string str;
	cin >> str;
	ll n = str.length();
	if(n & 1 == 0) {
		cout << "No" << newl;
		return;
	}
	if(n == 1) {
		cout << "Yes" << newl;
		return;
	}
	string resl = str.substr(0, (n - 1) / 2);
	string resr = str.substr((n + 1) / 2, (n - 1) / 2);
	if(isPal(str) && isPal(resl) && isPal(resr)) {
		cout << "Yes" << newl;
	}else {
		cout << "No" << newl;
	}
	return;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int tt = 1;
	// cin >> tt;
	for(ll i = 1; i <= tt ; i++) {
	//	cout << "Case #" << i << ": ";
		executeCode();	
	}
	return 0;
}

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

int main() {
  int A,B,K;
  cin >> K >> A >> B;
  bool judge=false;
  
  for(int i=A; i<=B; i++){
    if(i%K==0){
      judge=true;
      break;
    }
  }
  if(judge){
    cout << "OK" << endl;
  }
  else{
    cout << "NG" << endl;
  }
    
}


Measured memory_bytes: 3636
n = int(raw_input())


w = map(int, raw_input().split(" "))

s1 = 0
for i in range(0, len(w)):
    s1 += w[i]

s2 = 0
ans = abs(s1 - s2)

for i in range(0, len(w)):
    s1 -= w[i]
    s2 += w[i]
    ans = min(ans, abs(s1 - s2))

print(ans)


Measured memory_bytes: 2568
open Batteries

let read_two () = Scanf.sscanf (read_line ()) "%d %d" (fun a b -> (a, b))

let read_three () =
  Scanf.sscanf (read_line ()) "%d %d %d" (fun a b c -> (a, b, c))

let read_four () =
  Scanf.sscanf (read_line ()) "%d %d %d" (fun a b c d -> (a, b, c, d))

let read_list () =
  read_line () |> String.split_on_char ' '
  |> List.map (fun s -> int_of_string s)

(* a**x *)
let pow a x =
  let rec aux acc = function 0 -> acc | n -> aux (acc * a) (n - 1) in
  aux 1 x

let rec pow2 n = if n mod 2 = 0 then 1 + pow2 (n / 2) else 0

let rec f (l, r) x = function
  | [] -> (l, r)
  | a :: rest -> if a < x then f (l + 1, r) x rest else f (l, r + 1) x rest

let () =
  let _, _, x = read_three () in
  let a = read_list () in
  let l, r = f (0, 0) x a in
  let ans = min l r in
  print_int ans;
  print_newline ()


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

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>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
    vector<int> P(A), Q(B), R(C);
    REP(i, 0, A) cin >> P[i];
    REP(i, 0, B) cin >> Q[i];
    REP(i, 0, C) cin >> R[i];

    sort(ALL(P), greater<int>());
    sort(ALL(Q), greater<int>());
    sort(ALL(R), greater<int>());

    ll sumA = 0, sumB = 0;
    priority_queue<int, vector<int>, greater<int>> QA, QB;
    REP(i, 0, X) {
        sumA += P[i];
        QA.push(P[i]);
    }
    REP(i, 0, Y) {
        sumB += Q[i];
        QB.push(Q[i]);
    }

    ll ans = sumA + sumB;
    REP(i, 0, C) {
        if (QA.top() > QB.top()) {
            sumB -= QB.top();
            QB.pop();
            sumB += R[i];
            QB.push(R[i]);
        } else {
            sumA -= QA.top();
            QA.pop();
            sumA += R[i];
            QA.push(R[i]);
        }
        ans = max(ans, sumA + sumB);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int n,x,ans = 1;
  cin >> n >> x;
  vi l(n),d(n+1,0);
  rep(i,n) cin >> l[i];
  for(int i=2; i<=n+1; i++){
    d[i-1] = d[i-2] + l[i-2];
    if(d[i-1] <= x){
      ans++;
    }
    else break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int MOD=1000000007,INF=1001001001;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

#define int ll

int n,m,a,b,cnt=0;
int box[100010];
bool can[100010];

signed main(){
    rep(i,0,100010)box[i]=1;
    can[0]=true;
    cin>>n>>m;
    rep(i,0,m){
        cin>>a>>b;a--,b--;
        if(can[a])can[b]=true;
        
        box[a]--,box[b]++;
        if(box[a]==0)can[a]=false;
    }
    rep(i,0,n){
        if(box[i]>0 && can[i])cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 1152
n, y = map(int,input().split(' '))
y = y/1000

m = 0
g = 0
s = 0

m = int(y/10)
g = int((y-10*m)/5)
s = int(y-10*m-5*g)

tmpn = m+g+s

while(tmpn != n ):
    if g>0 and n-tmpn >=4:
        g= g-1
        s= s+5
        tmpn=m+g+s
    elif m > 0 and n-tmpn >=1:
        m=m-1
        g=g+2
        tmpn=m+g+s
    else:
        m=-1
        g=-1
        s=-1
        break

print(m,g,s)


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

using namespace std;

int main()
{
    string s;
    cin>>s;
    //cout<<"S:"<<s<<endl;
    int res=0,currCount, i=0;
    while(i<3)
    {
        //cout<<"i:"<<i<<endl;
        if(s[i]=='R')
        {
            //cout<<" R"<<endl;
            currCount=1;
            while(i+1<3 && s[i+1]=='R')
            {
                currCount++;
                i++;
            }
            res=max(res,currCount);
        }
        i++;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3568
a, b = map(int, input().split())
kuchi =  1
cnt = 0
if kuchi <= b:
    for i in range(1, 20):
        if kuchi >= b:
                break
        else:
            for j in range(1, a ** i):
                if kuchi >= b:
                    break
                else:
                    if j < a ** i:
                        cnt += 1
                        kuchi = kuchi - 1 + a
                    else:
                        kuchi = kuchi * a
                        cnt += kuchi / a 
print(cnt)


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

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

    int f = 0, t = 0, o = 0;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        if(!(a % 4)) f++;
        else if(!(a % 2)) t++;
        else o++;
    }
    t %= 2;

    bool flag = false;
    if(t){
        f += t / 2;
        o += t % 2;
        if(o <= f + 1){
            flag = true;
        }
    }else{
        if(o <= f + 1){   // o-f-o-f-o
            flag = true;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

using namespace std;

int main(){
	while(true){
		string str;
		cin >> str;
		if(str=="0")break;
		int ans=0;
		for(string::iterator it=str.begin();it!=str.end();++it){
			int t=*it-'0';
			ans+=t;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3200
import java.util.Scanner;
import java.util.ArrayList;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int repeatNum = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<Integer>(repeatNum);
    for(int i= 0;i<repeatNum;i++){
      list.add(sc.nextInt());
    }
    int result = 0;
    int temp=0;
    for(int j= 0;j<repeatNum;j++){
      temp= list.get(j) - sc.nextInt();
      if(temp>0){
        result+=temp;
      }
    }
    System.out.println(result);
  }
}

Measured memory_bytes: 23252
import math
a, b, x = map(int, input().split())

if x / (a * b) * 2 <= a:
    c = x / (a * b) * 2
    print(math.degrees(math.acos(c / math.sqrt(c * c + b * b))))
else:
    c = 2 * x / (a * a) - b
    print(math.degrees(math.acos(a / math.sqrt(a * a + (b -c) * (b - c)))))


Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int max,mid,min;
  max=a;
  mid=a;
  min =a;
  if(b>max){
    max=b;
  }
  else if(b < min){
    min=b;
  }
  if(c>max){
    max=c;
  }else if(c < min){
    min =c;
  }
  mid=a+b+c-max-min;
  if(max==min+mid)
    cout << "Yes";
  else
    cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;
typedef long long ll;


int main(){

 int ans = 0;
 int n;
 cin >> n;
 for (int i=1; i<=n; i++){
   if ((1 <= i) & (i < 10)){
     ans += 1;
   }
  else if ((100 <= i) & (i < 1000)){
     ans += 1;
   }
  else if ((10000 <= i) & (i < 100000)){
     ans += 1;
   }

 }

 cout << ans << endl;

  return 0;
}


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

int N,K; //
vector<int> d;
vector<vector<int>> A;

void input(){
    cin>>N>>K;
    d.resize(K); //i番目のお菓子を持っている人数
    A.resize(K,vector<int>()); //K種類のお菓子とKi番目のお菓子を持っている人数
    for(int i=0;i<K;i++){
        cin>>d[i];
        A[i].resize(d[i]);
        for(int x=0;x<d[i];x++){
            cin>>A.at(i).at(x);
        }
    }
}
void solve(){
    int ans=0;
    for(int i=1; i<=N;i++){
        bool have = false;
        for(auto v : A){
            for(auto p:v){
               if(i==p){
                have = true;
               }
            }
        }
        if(!have){
            ans++;
        }
    }
    cout<<ans<<endl;
}
int main()
{
    input();
    solve();
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
int main() {
	ll n, a; cin >> n;
	vector<ll> v;
	v.push_back(0);
	for (int i = 0; i < n; i++) {
		cin >> a;
		v.push_back(a);
	}
	v.push_back(0);
	ll re = 0;
	for (ll i = 0; i < n + 1; i++)
		re += abs(v[i+1] - v[i]);
	for (int i = 1; i < n+1; i++)
		cout << re + abs(v[i - 1] - v[i + 1]) - (abs(v[i - 1] - v[i]) + abs(v[i] - v[i + 1])) << endl;
	return 0;
}

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

int main(void)
{
	long long int num;
	cin>>num;
	long long int res=0;
	for(int i=1;i<=num;++i){
		if(i%3!=0&&i%5!=0)
			res+=i;
	}
	cout<<res;
	return 0;
}

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

int main() {
    int N, K;
    int sum = 1;

    cin >> N >> K;

    int i;

    for(i = 0; i < N ;i++){
        if(sum * 2 > sum + K){
            sum = sum  + K;
        }
        else{
            sum = 2 * sum;
        }
    }

    cout << sum << endl;

    return 0;
}

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

using namespace std;

string s, need = "keyence";

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> s;
    if (s.size() < need.size() ) return printf("NO"), 0;

    for (int i = 0; i <= 7; ++i) {
        string ret = "";
        for (int j = 0; j < i; ++j) ret += s[j];
        for (int j = (int)s.size() - (7 - i); j < (int)s.size(); ++j) ret += s[j];
        if (ret == need) return printf("YES"), 0;
    }

    printf("NO");

    return 0;
}


Measured memory_bytes: 256
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

n,k = MI()
R,S,P = MI()
T = input()
li = [[] for _ in range(k)]
for i in range(len(T)):
    j = i%k
    li[j].append(T[i])
score = 0
for i in range(k):
    prev = "-1"
    for j in range(len(li[i])):
        if li[i][j] == "r":
            if prev == "p":
                prev = "-1"
            else:
                score += P
                prev = "p"
        if li[i][j] == "s":
            if prev == "r":
                prev = "-1"
            else:
                score += R
                prev = "r"
        if li[i][j] == "p":
            if prev == "s":
                prev = "-1"
            else:
                score += S
                prev = "s"
print(score)

Measured memory_bytes: 18056
N,D = map(int, input().split())
XY_s = [list(map(int,input().split())) for _ in range(N)]
D**=2
answer = 0
for i in range(N):
    if D >= XY_s[i][0]**2 + XY_s[i][1]**2:
        answer+=1
print(answer)

Measured memory_bytes: 125468
import java.util.Scanner;

public class Main {
	static int cnt = 0;
	static int mcnt = 0;
	static int[] h = {1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573, 265720, 797161, 2391484}; 
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(i = 0; i < n; i++) {
        	a[i] = sc.nextInt();
        }
        
        shellSort(a, n);
        System.out.println(mcnt);
        outPut1(h, mcnt);
        System.out.println(cnt);
        outPut2(a, n);
	}
	
	//insertion sort
	public static int[] insertionSort(int[] a, int n, int g) {
		for(int i = g; i < n; i++) {
			int v = a[i];
			int j = i - g;
			while(j >= 0 && a[j] > v) {
				a[j + g] = a[j];
				j = j - g;
				cnt++;
			}
			a[j + g] = v;
		}
		return a;
	}
	
	//shell sort
	public static int[] shellSort(int[] a, int n) {
		for(int i = 0; h[i] <= n; i++) {
			mcnt++;
		}
		for(int i = mcnt; i >= 0; i--) {
			insertionSort(a, n, h[i]);
		}
		return a;
	}
	
	//output array
	public static void outPut1(int[] a, int n) {
		for(int i = n-1; i >= 0; i--) {
			if(i == 0) {
				System.out.println(a[i]);
				break;
			}
			System.out.print(a[i] + " ");
		}
	}
	
	public static void outPut2(int[] a, int n) {
		for(int i = 0; i < n; i++) {
			System.out.println(a[i]);
		}
	}
}


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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;



vector<vi> can(11 , vi());

set<vi> s;

inline vi viadd(vi v , int val){
	v.pb(val);
	return v;
}

void rec(int ev , int p , int n , vi cur){
	if(p == n){
		s.insert(cur);
	}else{
		if(ev == p){
			rep(i , 3){
				if(can[p][i] % 2 == 0){
					rec(ev , p + 1 , n , viadd(cur , can[p][i]));
				}
			}	
		}else{
			rep(i , 3){
				rec(ev , p + 1 , n , viadd(cur , can[p][i]));
			}
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 

	int n;
	cin >> n;
	
	vi v(n);
	rep(i , n){
		cin >> v[i];
	}
	
	rep(i , n){
		can[i].pb(v[i] - 1);
		can[i].pb(v[i] + 1);
		can[i].pb(v[i]);
	}
	
	rep(i , n){
		rec(i , 0 , n , vi());	
	}
	
	cout << sz(s);

	return 0;
}

Measured memory_bytes: 6784
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int mod=1e9+7;
int n,m,K,f[4005][2005][2],sum[4005];
int add(int a,int b){return a+b>=mod?a+b-mod:a+b;}
void upd(int &a,int b){a=(a+b>=mod)?a+b-mod:a+b;}
int main(){
	scanf("%d%d%d",&n,&m,&K);
	int tot=(n+m-1)/(K-1);
	f[0][0][0]=1;
	m--;K--;
	int ans=0;
	for(int i=1;i<=tot;i++){
		for(int p=1;p<=n+1;p++) sum[p]=add(sum[p-1],add(f[i-1][p-1][0],f[i-1][p-1][1]));
		for(int p=0;p<=n;p++){
			f[i][p][0]=add(sum[p+1],mod-sum[p]);
			int k=max(0,p-K);
			f[i][p][1]=add(sum[p],mod-sum[k]);
		}
		for(int p=n%K;p<=n;p+=K){
			if(i*K-p<=m&&(i*K-p)%K==m%K) upd(ans,f[i][p][1]);
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 62848
fun main(args: Array<String>) {
    val (n, x) = readLine()!!.split(" ").map { it.toInt() }
    val l = readLine()!!.split(" ").map { it.toInt() }
    var iti = 0
    var count = 0
    var flag = 0
    for (i in 1 until n+1){
        iti += l[i-1]
        if (iti > x){
            count = i
            flag = 1
            break
        }
    }
    if (flag == 0) count = n + 1
    if (x < l[0]) count = 1
    println(count)
}

Measured memory_bytes: 37936
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
ll n,w;
ll memo[100][100000],p[100000],v[100000];
ll dp(ll i,ll w){
	if(i == n || w == 0) return 0;
	if(memo[i][w] != -1) return memo[i][w];
	ll ret = INT_MIN;
	if(w >= p[i]) ret = max(dp(i+1,w),dp(i+1,w-p[i])+v[i]);
	else ret = dp(i+1,w);
	memo[i][w] = ret;
	return ret;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	memset(memo,-1,sizeof(memo));
	cin>>n>>w;
	for(int i=0;i<n;i++){
		cin>>p[i]>>v[i];
	}
	cout<<dp(0,w)<<"\n";
	return 0;
}

Measured memory_bytes: 78464
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int x;
    cin >> x;
    int s = 100;
    int cnt = 0;
    while (1)
    {
        if(x<=s){
            break;
        }
        s *= 1.01;
        cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3624
using System;
class Program
{
    static void Main(string[] args)
    {
        var correct = 753;
        var S = Console.ReadLine();
        var charList = S.ToCharArray();
        var result = 1000000000;

        var length = S.Length;
        for(int i=0; i+2<length; i++){
            var e = new char[] {charList[i] , charList[i+1] , charList[i+2]};
            var temp = new String(e);
            var intTemp = int.Parse(temp);
            var abs = System.Math.Abs(correct - intTemp);
            if(result > abs){
                result = abs;
            }
        }
        Console.WriteLine(result);
    }
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int a, b;
	while( (cin >> a) && (cin >> b) ) {
		int x = a+b;
		int dg = 1;

		while( (x /= 10) > 0 ) {
			dg += 1;
		}

		cout << dg << endl;
	}
}



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

int main(){
  int n; cin>> n;
  int A[2][n];
  for (int i=0; i<2; i++){
    for (int j=0; j<n; j++){
      cin >> A[i][j];
    }
  }
  int dp[n];
  int i=0;
  dp[0]=A[0][0];
  while(i!=n){
    dp[0] += A[1][i];
    i++;
  }

  for (int i=1; i<n; i++){
    dp[i] = dp[i-1]-A[1][i-1]+A[0][i];
  }

  int m=0;
  for (int i=0; i<n; i++){
    m =max(m, dp[i]);
  }

  cout << m << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt();
        if (a<b&&b<c) System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 26392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

int main(){
  int n,x;
  cin>>n>>x;
  if(x==1||x==(2*n-1)){
    cout<<"No"<<endl;
    return 0;
  }
  int a[2*n];
  bool used[2*n];
  for(int i=0;i<2*n;i++){
    used[i]=0;
    a[i]=-1;
  }
  if(x==2){
    a[n-1]=x+1;
    a[n]=x;
    a[n+1]=x-1;
    a[n+2]=x+2;
    used[x+1]=used[x]=used[x-1]=used[x+2]=1;
  }else{
    a[n-1]=x-1;
    a[n]=x;
    a[n+1]=x+1;
    a[n+2]=x-2;
    used[x-1]=used[x]=used[x+1]=used[x-2]=1;
  }
  int ind=1;
  for(int i=1;i<=2*n-1;i++){
    if(a[i]!=-1) continue;
    else if(used[ind]){
      while(used[ind]) ind++;
      a[i]=ind;
      ind++;
    }else{
      a[i]=ind;
      ind++;
    }
  }
  cout<<"Yes"<<endl;
  for(int i=1;i<2*n;i++) cout<<a[i]<<endl;
  return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int N,M;
    cin >> N >> M;
    string S;
    cin >> S;
    vector<int> vec;
    for(int i = 0;i < N + 1;i++) {
        if(S.at(i) == '0') {
            vec.push_back(N - i);
        }
    }
    reverse(vec.begin(),vec.end());
    int cnt = 0;
    bool ret = true;
    vector<int> ret2;
    for(int i = 0;i < N;i++) {
        auto itr = upper_bound(vec.begin(),vec.end(),cnt + M);
        int A = itr - vec.begin();
        if(vec.at(A - 1) == cnt) {
            ret = false;
            break;
        }
        else {
            ret2.push_back(vec.at(A - 1) - cnt);
            cnt = vec.at(A - 1);
        }
        if(cnt == N) {
            break;
        }
    }
    if(ret == false) {
        cout << -1 << endl;
    }
    else {
        reverse(ret2.begin(),ret2.end());
        for(int i = 0;i < ret2.size();i++) {
            cout << ret2.at(i) << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 1592
N = int(input())
s = input()
t = input()


nomatch = False
place = 0
for i in range(N):
    place = i
    if t[0] == s[i]:      
        match = True
        for j in range(N-i):
            if t[j] != s[i+j]:
                match = False
        if match:
            break
        else:
            continue
    elif i == N-1:
        nomatch = True

if nomatch:
    print(2*N)
else:
    print(N+place)

Measured memory_bytes: 3064
//#pragma warning(disable:4996)
//#include <Windows.h>
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

template<class T>
inline void chmin(T& a, T b) {
	a = min(a, b);
}

template<class T>
inline void chmax(T& a, T b) {
	a = max(a, b);
}

void input();
void solve();

void daminput();

int main() {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	input();
	//daminput();
	solve();
	return 0;
}

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

int A, B;

void input() {
	cin >> A >> B;
}

void daminput() {
}

void solve() {
	int af = (100 * A) / 8;
	int bf = 10*B;
	int as;
	if ((100 * (A + 1)) % 8 == 0) {
		as = 100 * (A + 1) / 8 - 1;
	}
	else {
		as = (100 * (A + 1)) / 8;
	}
	int bs = 10 * B + 9;
	int fl = max(af, bf);
	int se = min(as, bs);
	for (int x = max(1, fl); x <= se; x++) {
		if ((8 * x / 100 == A) && (1 * x / 10 == B)) {
			cout << x << "\n";
			return;
		}
	}
	cout << -1 << "\n";
}

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

int main(){
    int N, K;
    cin >> N >> K;
    int a[50];
    int ans = 0;
    for (int i = 0; i < N; i++) cin >> a[i];
    sort (a, a + N, greater<int>());
    for (int i = 0; i < K; i++) ans += a[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;

namespace AtCoder.Abc
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            int x = int.Parse(Console.ReadLine());

            Console.WriteLine(x==0?"1":"0");

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27456
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    int n;
    int k;
    vector<int> zero_start;
    vector<int> one_start;
    int ans=0;
    string s;
    cin >> n >> k;
    cin >> s;

    if(n==1){
        if(s[0]=='0'){
            zero_start.push_back(0);
        }else{
            one_start.push_back(0);
        }
    }
    for(int i=1; i<n; i++){
        if(s[i-1]=='0' && s[i]=='1'){
            one_start.push_back(i);
        }else if(i==1 && s[i-1]=='1'){
            one_start.push_back(i-1);            
        }
        if(s[i-1]=='1' && s[i]=='0'){
            zero_start.push_back(i);
        }else if(i==1 && s[i-1]=='0'){
            zero_start.push_back(i-1);       
        }
    }

    //cout << zero_start.size() << " " << one_start.size() << endl;
    //cout << zero_start[1] << " " << one_start[1] << endl;
    int tmp;
    if(one_start.size()==0 || zero_start.size()==0){
        ans = n;
    }else{
        if(one_start[0]<zero_start[0]){
            //cout << "test0" << endl;
            if(one_start.size()>k){
                for(int i=0; i<one_start.size()-k; i++){
                    if(zero_start.size()>i+k){
                        tmp=zero_start[i+k]-one_start[i];
                    }else{
                        tmp=n-one_start[i];
                    }
                    //cout << one_start[i] << " " << one_start[i+k] << " " << tmp << endl;
                    if(tmp>ans){
                        ans=tmp;
                    }
                }
                tmp=n-one_start[one_start.size()-k];
                //cout << one_start[one_start.size()-k] << " " << tmp << endl;
                if(tmp>ans){
                    ans=tmp;
                }
            }else{
                ans=n;
            }
        }else{
            //cout << "test" << endl;
            if(zero_start.size()>k){
                ans=zero_start[k]-zero_start[0];
                for(int i=1; i<zero_start.size()-k; i++){
                    tmp=zero_start[i+k]-one_start[i-1];
                    if(tmp>ans){
                        ans=tmp;
                    }
                }
                tmp=n-one_start[zero_start.size()-k-1];
                //cout << tmp << endl;
                if(tmp>ans){
                    ans=tmp;
                }                
            }else{
                ans=n;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

void shift(char x[]){
	int n=strlen(x),i;
	for(i=0;i<n;i++){
		if('a'<=x[i] && x[i]<='y')x[i]++;
		else if(x[i]=='z')x[i]='a';
	}
}

int check(char x[]){
	if(strstr(x,"the")!=NULL)return 1;
	if(strstr(x,"that")!=NULL)return 1;
	if(strstr(x,"this")!=NULL)return 1;
	return 0;
}

int main(void) {
	char text[82];

	while(1){
		if(fgets(text,82,stdin)==NULL)break;

		while(1){
			shift(text);
			if(check(text))break;
		}

		printf("%s",text);
	}

	return 0;
}

Measured memory_bytes: 532
from collections import Counter

N = int(input())
s = []
for i in range(N):
    s.append(input())
M = int(input())
t = []
for i in range(M):
    t.append(input())
N_count = Counter(s)
M_count = Counter(t)
ans = 0
for i in N_count.keys():
    temp = N_count[i] -M_count[i]
    if ans <= temp:
        ans = temp
print(ans)


Measured memory_bytes: 3572
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	long long int T, t, A, a, B, b;
	scanf("%lld %lld %lld %lld %lld %lld", &T, &t, &A, &a, &B, &b);
	if (T * A + t * a == T * B + t * b) printf("infinity");
	else {
		if (A < B) {
			swap(A, B);
			swap(a, b);
		}
		if (T * A + t * a > T * B + t * b) printf("0");
		else {
			long long ans = T * (A - B) / (T * (B - A) + t * (b - a));
			long long rans = ans * 2 + 2;
			if (ans * (T * (B - A) + t * (b - a)) == T * (A - B)) --rans;
			--rans;
			printf("%lld", rans);
		}
	}
	return 0;
}

Measured memory_bytes: 128
MOD = 10**9 + 7

n, k = map(int, input().split())

c = 0

d = [0] * (k + 1)

for i in range(k, 0, -1):

        # temp_c = 0
    if d[i] == 0:

        
        t1 = k // i    
        c1 = pow(t1, n, MOD)

        j = i
        while j + i <= k:
            j += i
            c1 -= d[j]
            if c1 < 0:
                c1 += MOD

        d[i] = c1

        # print (i, d[i])

        c += i * c1
        c %= MOD

print (c)

Measured memory_bytes: 69096
#include<bits/stdc++.h>
using namespace std;
int gcd(int x, int y);

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<int> left(n);
    left[0]=a[0];
    for(int i=1;i<n;i++){
        left[i]=gcd(left[i-1],a[i]);
    }
    vector<int> right(n);
    right[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--){
        right[i]=gcd(right[i+1],a[i]);
    }
    int ans=0;
    for(int i=1;i<n-1;i++){
        ans=max(ans,gcd(left[i-1],right[i+1]));
    }   
    ans=max(ans,left[n-2]);
    ans=max(ans,right[1]);
    cout<<ans<<endl;
}
int gcd(int x,int y){
    if(y==0)return x;
    else return gcd(y,x%y);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  vector<int> a(9);
  rep(i, 9) cin >> a[i];
  int n;
  cin >> n;
  rep(i, n) {
    int b;
    cin >> b;
    rep(j, 9) {
      if (b == a[j])
        a[j] = 0;
    }
  }
  if ((a[0] || a[1] || a[2]) && (a[3] || a[4] || a[5]) &&
      (a[6] || a[7] || a[8]) && (a[0] || a[3] || a[6]) &&
      (a[1] || a[4] || a[7]) && (a[2] || a[5] || a[8]) &&
      (a[0] || a[4] || a[8]) && (a[2] || a[4] || a[6]))
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
X, Y, a, b, c = list(map(int,input().split()))
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
s = sorted(p)[::-1][:X] + sorted(q)[::-1][:Y] + r
s = sorted(s)[::-1]
ans = sum(s[:X + Y])
print(ans)   

Measured memory_bytes: 111232
#include<stdio.h>
#include<string.h>
#define N 1005
char A[N][N];
int f[N*N][3],res=0;
int main() {
    int n,m,i,j,h=0,t=0,ans,x,y;
    int fs[8]={-1,0,0,-1,0,1,1,0}; 
    scanf("%d%d",&n,&m);
    for(i=0; i<n; i++) {
        getchar();
        for(j=0; j<m; j++) {
            scanf("%c", &A[i][j]);
            if(A[i][j]=='#') {
                f[t][0]=i,
                f[t][1]=j,
                f[t][2]=0;
                t++;
            }
            else res++;
        }
    }
    while(h<t) {
        for(i=0; i<8; i+=2) {
            x = fs[i]   + f[h][0],
            y = fs[i+1] + f[h][1];
            if(x>=0 && y>=0 && x<n && y<m && A[x][y]=='.') {
                A[x][y]='#';
                res--;
                f[t][0]=x, f[t][1]=y, f[t][2]=f[h][2]+1;
                t++;
            }
        }
        h++;
        if(!res) break;
    }
    printf("%d\n", f[t-1][2]);
}


Measured memory_bytes: 12928
#include <stdio.h>

int main(void)
{
	char s[11], p[11];
	int i = 0, j = 0;

	scanf("%s", s);

	while (s[i] != '\0')
	{
		if (s[i] == '0')
		{
			p[j] = '0';
			j++;
		}
		if (s[i] == '1')
		{
			p[j] = '1';
			j++;
		}
		if (s[i] == 'B')
		{
			if (j != 0)
				j--;
			else
				;
			p[j] = '\0';
		}

		i++;
	}

	p[j] = '\0';

	printf("%s\n", p);
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
	int A, B;
	string S;
	cin >> A >> B >> S;
  	int leng = A + B + 1;	
	int i;	
  	for( i=0; i<A; i++ ){
    	if( S[i] == '-' ){
        	cout << "No" << endl;
          	return 0;
		}
    }
  	if( S[A] != '-' ){
    	cout << "No" << endl;
        return 0;
    }
  	for( i=A+1; i<A+B+1; i++ ){
    	if( S[i] == '-' ){
        	cout << "No" << endl;
          	return 0;
		}
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){return (int)s.size();}
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    ll n,c,k; cin >> n >> c >> k;
    vc<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    ll cnt = 0, ans = 1, cri=a[0];
    rep(i,n){
        if(a[i]-cri > k || cnt == c){
            cri = a[i];
            ans++;
            cnt = 0;
        }
        cnt++;
    }
    cout << ans << endl;
    return 0;
}


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

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__() for(long blockTime=NULL;(blockTime==NULL?(blockTime=clock())!=NULL:false); debug("Time:%.4fs\n",(double)(clock()-blockTime)/CLOCKS_PER_SEC))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265358979323846264338327
#define INF 2000000000
#define MOD 998244353
#define MAXN 100005
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef unsigned long long ull;

void mins(ll &x,ll v){
	x=min(x,v);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n,W,MAXV=0;	cin>>n>>W;
	ll w[n],v[n]; //min weight with value = j
	forn(i,0,n){
		cin>>w[i]>>v[i];
		MAXV+=v[i];
	}
	
	ll dp[MAXV+1];
	fore(i,0,MAXV)	dp[i]=INF;
	dp[0]=0;
	
	forn(j,0,n){
		for(int i=MAXV;i>=v[j];i--)
		{
			mins(dp[i],dp[i-v[j]]+w[j]);
		}
	}

	for(int i=MAXV;i>=0;i--){
		if(dp[i]<=W){
			cout<<i;
			return 0;
		}
	}
		
	return 0;
}


Measured memory_bytes: 1024
N,K = map(int,input().split())
TD = [tuple(map(int,input().split())) for i in range(N)]
TD.sort(key=lambda x:x[1])

import heapq
hq = []
heapq.heapify(hq)
selected = set()
ans = 0
for _ in range(K):
    t,d = TD.pop()
    if t in selected:
        heapq.heappush(hq, d)
    else:
        selected.add(t)
    ans += d
ans += len(selected)**2

tmp = ans
while TD:
    t,d = TD.pop()
    if t in selected: continue
    selected.add(t)
    if len(hq)==0: break
    tmp -= heapq.heappop(hq)
    tmp += d
    tmp += len(selected)*2 - 1
    ans = max(ans ,tmp)
print(ans)

Measured memory_bytes: 25244
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;
const int MAXN = 1e6+10;
typedef long long LL;
LL cnt[MAXN];
int mu[MAXN],prime[MAXN];
int num[MAXN];
bool vis[MAXN];
int pcnt;

/*求解Mobinus函数*/
void Mobinus()
{
   // cout << 1 << "\n";
    memset(vis,0,sizeof(vis));

    pcnt=0;
    mu[1]=1;
    //printf("1\n");
    for(LL i=2; i<MAXN; i++)
    {
        if(!vis[i])
        {
            prime[pcnt++]=i;
            mu[i]=-1;
        }
       // printf("%lld\n",i);
        for(LL j=0; j<pcnt&&i*prime[j]<MAXN; j++)
        {
            vis[i*prime[j]]=1;
            if(i%prime[j])mu[i*prime[j]]=-mu[i];//i是素数的情况
            else
            {
                mu[i*prime[j]]=0;
                break;
            }
        }
    }
}

int main()
{
  //  cout << 1 << "\n";
    Mobinus();
    LL n;
    scanf("%lld",&n);
    LL Max=-99999999,ans=0;
    LL a[MAXN];
    memset(cnt,0,sizeof(cnt));
    memset(num,0,sizeof(num));
    for(int i=0; i<n; i++)
    {
        scanf("%lld",&a[i]);
        Max=max(a[i],Max);
    }
    for(int i=0; i<n; i++)
    {
        num[a[i]]++;
    }
    for(int i=1; i<=Max; i++)
    {
        for(int j=i; j<=Max; j+=i)
            cnt[i]+=num[j];
    }
    for(int i=1; i<=Max; i++)
    {
        ans+=(mu[i]*cnt[i]*(cnt[i]-1))>>1;
    }
    if(ans==n*(n-1)/2)
    {
        printf("pairwise coprime\n");
    }
    else
    {
        LL d = a[0];
        for(int i = 1;i<n;++i)
        {
            d = __gcd(d,a[i]);
        }
        if(d==1)
        {
            printf("setwise coprime\n");
        }
        else
            printf("not coprime\n");
    }
    return 0;
}


Measured memory_bytes: 28416
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

int main() {
	int n;
	cin >> n;
	
	set<int> ss;
	while (n--) {
		int a;
		scanf("%d", &a);
		
		if (ss.find(a) != ss.end()) ss.erase(a);
		else ss.insert(a);
	}
	cout << ss.size() << endl;
	return 0;
}

Measured memory_bytes: 4864
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define fill(x,y) memset(x,y,sizeof(x))
#define prev PREV
#define next NEXT
                         
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }
template<class T> inline T sqr (T x) { re x * x; }

#define filename ""

int n;
int m;
int k;
vi v[2000];

int go (int x, int p, int len) {
	int cur = 1;
	if (len) {
		for (int i = 0; i < sz (v[x]); i++)
			if (v[x][i] != p)
				cur += go (v[x][i], x, len - 1);
	}
	re cur;
}

int main () {
	scanf ("%d%d", &n, &k);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		scanf ("%d%d", &a, &b); a--; b--;
		v[a].pb (b);
		v[b].pb (a);
	}
	int ans = 0;
	if (k & 1) {
		for (int i = 0; i < n; i++)
			for (int j = 0; j < sz (v[i]); j++)
				ans = max (ans, go (i, v[i][j], k / 2) + go (v[i][j], i, k / 2));
	} else {
		for (int i = 0; i < n; i++) ans = max (ans, go (i, i, k / 2));
	}
	printf ("%d\n", n - ans);
	return 0;
}

Measured memory_bytes: 384
/*
    author: Salam_35
    Created at :

*/

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

/*        speed up       */
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define Max 100005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF    1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() _fastio;int testsalam;cin >> testsalam;while(testsalam--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
#define endl '\n'
//void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}
string inttostr(ll n){std::stringstream ss;ss << n;string out=ss.str();return out;}
ll stringtoint(string s){istringstream iss (s);ll n;iss >> n;return n;}
template <typename T> T gcd(T a,T b){if(a < 0)return gcd(-a,b);if(b < 0)return gcd(a,-b);return (b == 0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a < 0)return lcm(-a,b);if(b < 0)return lcm(a,-b);return a*(b/gcd(a,b));}
typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;

int main()
{
    string s,t;
  cin >> s >> t;
  int c=0;
  for(int i=0;i<int(s.size());i++)
  {
    if(s[i]!=t[i])c++;
  }
  return cout<<c<<endl,0;
}
/*
 		remember:
 		ll vs int
 		array size
 		case for 1 2 3 
*/


Measured memory_bytes: 3924
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
	int N,P,Q;
	scanf("%d%d%d",&N,&P,&Q);
	vector<long long>c(N),a(N+1);
	for(int i=0;i<N;i++){
		scanf("%lld",&c[i]);
		c[i]+=(long long)P*i;
		a[i+1]=(long long)P*(Q+i*2)+a[i];
	}
	sort(c.begin(),c.end());
	long long s=0,ma=a[N];
	for(int i=N-1;i>=0;i--){
		s+=c[i];
		ma=max(ma,s+a[i]);
	}
	printf("%lld\n",ma-(long long)P*N*(N-1)/2);
}

Measured memory_bytes: 8792
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

int n, m;
int s[10], c[10];

int main() { 

  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &s[i], &c[i]);
  }

  for (int i = 0; ; i++) {
    string cur = to_string(i);
    if (sz(cur) > n) {
      break;
    }
    if (sz(cur) < n) {
      continue;
    }
    bool ok = true;
    for (int j = 0; j < m; j++) {
      if (cur[s[j] - 1] - '0' != c[j]) {
        ok = false;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;

  return 0;
}


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

//#define int long long
#define DEBUG 0
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;

signed main() {
	int N, T; cin >> N >> T;
	vector<int> A(N);
	rep(i, 0, N)cin >> A[i];

	vector<int> B(N);
	int M = 0;
	rrep(i, 0, N) {
		M = max(A[i], M);
		B[i] = max(0, M - A[i]);
	}
	sort(all(B));
	reverse(all(B));
	dumpc(B);
	int ans = 1;
	rep(i, 1, N) {
		if (B[i] == B[0])ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
"""
Created on Sat May  5 11:31:13 2018
Napsack problem
@author: maezawa
"""

n, wmax = list(map(int, input().split()))
v = []
w = []
for i in range(n):
    vi, wi = list(map(int, input().split()))
    v.append(vi)
    w.append(wi)

dp = [[0 for _ in range(wmax+1)] for _ in range(n+1)]

for i in range(n):
    for j in range(wmax+1):
        if j-w[i] < 0:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j-w[i]] + v[i], dp[i][j])
            
print(dp[n][wmax])


Measured memory_bytes: 42272