akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e5+10;
const ll inf=1e15;
int n,Begin[maxn],Next[maxn<<1],to[maxn<<1],w[maxn<<1][2],e;
bool vis[maxn];
ll dis[maxn][2],Ans[maxn];
void add_edge(int x,int y,int u,int v){
	to[++e]=y;
	Next[e]=Begin[x];
	Begin[x]=e;
	w[e][0]=u;
	w[e][1]=v;
}
void spfa(int S,int flag){
	queue<int> q;
	q.push(S);
	REP(i,1,n) dis[i][flag]=inf,vis[i]=0;
	dis[S][flag]=0;
	while(!q.empty()){
		int x=q.front();q.pop();
		for(int i=Begin[x];i;i=Next[i])
			if(chkmin(dis[to[i]][flag],dis[x][flag]+w[i][flag]))
				if(!vis[to[i]]){
					q.push(to[i]);
					vis[to[i]]=1;
				}
		vis[x]=0;
	}
}
int main(){
	ll ans=inf;
	n=read();
	int m=read(),S=read(),T=read();
	REP(i,1,m){
		int x=read(),y=read(),u=read(),v=read();
		add_edge(x,y,u,v),add_edge(y,x,u,v);
	}
	spfa(S,0),spfa(T,1);
	DREP(i,n,1){
		chkmin(ans,dis[i][0]+dis[i][1]);
		Ans[i]=ans;
	}
	REP(i,1,n) printf("%lld\n",-Ans[i]+inf);
	return 0;
}


Measured memory_bytes: 7808
import java.util.*;
public class Main {
  /*
  private static void roop(int a, int b){
    for(int i = 0; i < a; i++){
      System.out.print(b);
    }
    System.out.println();
  }
  */
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    //char[] a = sc.nextLine().toCharArray();
    for(int i = 0; i < s.length(); i++){
      System.out.print("x");
    }
    System.out.println();
  }
}

Measured memory_bytes: 21588
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std ;

long long a, b, Gcd;

void gcd(int a, int b) {
	if (a < b) swap(a,b);
	while (a % b != 0) {
		a %= b;
		swap(a, b);
	}
	Gcd = b;
}

long long lcm(long long a , long long b) {
	return a * b / Gcd;
}

int main() {
	while (cin >> a >> b) {
		gcd(a, b);
		cout << Gcd << " " << lcm(a, b) << endl ;
	}
	return 0 ;
}


Measured memory_bytes: 3048
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())
S = input()

cnt = 0
for i in range(N - 1):
    cnt += 1 if S[i] != S[i + 1] else 0

print(cnt + 1)

Measured memory_bytes: 3956
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int n,k;
  cin>>n>>k;
  
  if(n%k==0) cout<<0<<endl;
  else cout<<1<<endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int n;
ll a, b;
vector< ll> v;

bool possible(ll t) {
    ll x = t * b;
    ll cnt = 0;
    for (ll e : v) {
        if(e <= x) continue;
        e = e - x;
        cnt += (e + a - 1) / a;
    }
    if(cnt <= t) return true;
    return false;
}

int main() {
    cin >> n >> a >> b;
    a = a - b;
    v.resize(n);

    for (auto &e : v) cin >> e;

    ll res = 0;
    for (ll t = 1e9; t >= 1; t /= 2) {
        while (!possible(res + t)) res += t;
    }

    cout << res + 1 << endl;
}

Measured memory_bytes: 1024
n = int(input())
b = []
for i in range(n):
	x, l = map(int, input().split())
	b.append([x+l,x-l])
b.sort()

r = -10**10
ans = 0
for i in b:
	if i[1] >= r:
		ans += 1
		r = i[0]
	else:
		continue
print (ans)

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

struct list{
  int key;
  struct list* prev;
  struct list* next;
};

void insert(int);
void delete(int);
void deleteFirst();
void deleteLast();

struct list nil={NULL,&nil,&nil};

int main(){
  int i,n,num;
  char order[12];
  struct list* x;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",order);

    if(strcmp(order,"insert")==0){
      scanf("%d",&num);
      insert(num);
    }

    else if(strcmp(order,"delete")==0){
      scanf("%d",&num);
      delete(num);
    }

    else if(strcmp(order,"deleteFirst")==0) deleteFirst();
    else deleteLast();
  }

  x=nil.next;
  while(x->next!=&nil){
    printf("%d ",x->key);
    x=x->next;
  }
  printf("%d\n",x->key);

  return 0;
}

void insert(int k){
  struct list* x=(struct list*)malloc(sizeof(struct list));
  x->key=k;

  x->next=nil.next;
  nil.next->prev=x;
  nil.next=x;
  x->prev=&nil;
}

void delete(int k){
  struct list* x=nil.next;

  while(x!=&nil&&x->key!=k) x=x->next;

  if(x->key==k){
    x->prev->next=x->next;
    x->next->prev=x->prev;
  }
}

void deleteFirst(){
  struct list* x=nil.next;
  
  x->prev->next=x->next;
  x->next->prev=x->prev;
}

void deleteLast(){
  struct list* x=nil.prev;

  x->prev->next=x->next;
  x->next->prev=x->prev;
}

Measured memory_bytes: 34972
#include <stdio.h>
#include <string.h>
#define MAX 100

int main(){
    int n;
    int t_point=0, h_point=0;
    char tarou[MAX], hanako[MAX];

    scanf("%d", &n);
    for(;n>0;n--){
        scanf(" %s %s", tarou, hanako);
        if(strcmp(tarou, hanako)>0){
            t_point+=3;
        }else if(strcmp(tarou, hanako)==0){
            t_point+=1;
            h_point+=1;
        }else if(strcmp(tarou, hanako)<0){
            h_point+=3;
        }
    }
    printf("%d %d\n", t_point, h_point);

    return 0;
}

Measured memory_bytes: 2672
import sys
readline = sys.stdin.readline
write = sys.stdout.write

N, Q = map(int, input().split())
INF = 2**31-1

LV = (N-1).bit_length()
N0 = 2**LV
data = [0]*(2*N0)
lazy = [None]*(2*N0)

def gindex(l, r):
    L = (l + N0) >> 1; R = (r + N0) >> 1
    lc = 0 if l & 1 else (L & -L).bit_length()
    rc = 0 if r & 1 else (R & -R).bit_length()
    v = 2
    for i in range(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1; R >>= 1; v <<= 1

def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if v is None:
            continue
        lazy[2*i-1] = lazy[2*i] = data[2*i-1] = data[2*i] = v >> 1
        lazy[i-1] = None

def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)

    L = N0 + l; R = N0 + r
    v = x
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] = data[R-1] = v
        if L & 1:
            lazy[L-1] = data[L-1] = v
            L += 1
        L >>= 1; R >>= 1; v <<= 1
    for i in ids:
        data[i-1] = data[2*i-1] + data[2*i]

def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r

    s = 0
    while L < R:
        if R & 1:
            R -= 1
            s += data[R-1]
        if L & 1:
            s += data[L-1]
            L += 1
        L >>= 1; R >>= 1
    return s


ans = []
for q in range(Q):
    t, *cmd = map(int, readline().split())
    if t:
        s, t = cmd
        ans.append(str(query(s, t+1)))
    else:
        s, t, x = cmd
        update(s, t+1, x)

write("\n".join(ans))
write("\n")



Measured memory_bytes: 18932
#include<bits/stdc++.h>
using namespace std;
const int maxn=199999,maxlg=30;
struct QQ{
	char mo;
	int i,j,k;
	QQ(){}
	QQ(char _m,int _i,int _j,int _k):mo(_m),i(_i),j(_j),k(_k){}
};
vector<QQ> q;
vector<int> PW2,v;
int cnt;
int pw2eq(int p,int k){
	for(int i=1;i<=k;i++)q.emplace_back('+',p,p,p);
	return p;
}
int Less(int p1,int p2){
	q.emplace_back('<',p1,p2,++cnt);
	return cnt;
}
int Plus(int p1,int p2){
	q.emplace_back('+',p1,p2,++cnt);
	return cnt;
}
int Minus(int p1,int p2){
	p1=Plus(p1,PW2[0]);
	int ret=maxn;
	for(int i=maxlg-1;i>=0;i--){
		int b=Less(Plus(p2,PW2[i]),p1),c=pw2eq(b,i);
		p2=Plus(p2,c);
		ret=Plus(ret,c);
	}
	return ret;
}
int ifelse(int b,int p){ //b?p:0 => p-(b<<30)
	return Minus(p,pw2eq(Less(b,PW2[0]),30));
}
void solve(int x,vector<int> &v){
	x=Plus(x,PW2[0]);
	for(int i=maxlg-1;i>=0;i--){
		int b=Less(PW2[i],x),c=ifelse(b,PW2[i]);
		x=Minus(x,c);
		v.push_back(b);
	}
	reverse(v.begin(),v.end());
}
int mul(){
	int ret=maxn;
	for(int i=0;i<maxlg;i++){
		ret=Plus(ret,pw2eq(ifelse(v[i],0),i));
	}
	return ret;
}
int main(){
	cnt=1;
	PW2.push_back(Less(maxn,Plus(0,1)));
	for(int i=1;i<maxlg;i++){
		PW2.push_back(Plus(i+2,i+2));
	}
	solve(1,v);
	q.emplace_back('+',mul(),maxn,2);
	cout<<q.size()<<endl;
	for(int i=0;i<q.size();i++)cout<<q[i].mo<<' '<<q[i].i<<' '<<q[i].j<<' '<<q[i].k<<endl;
	return 0;
}

Measured memory_bytes: 4084
/************************Code by Hardik Aggarwal!!!!***********************************/


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
/*#define endl '\n'*/
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100005;

int main()
{
	
/*	ll t;
	cin>>t;
	while(t--)
	{	
		string s1,s2;
		cin>>s1>>s2;

		ll pos,ans;
		reverse(s1.begin(),s1.end());
		reverse(s2.begin(),s2.end());
		
			for(ll i=0;i<s2.size();i++)
			{
				if(s2[i]=='1')
				{
					pos=i;
					break;
				}
			}

			for(ll i=pos;i<s1.size();i++)
			{
				if(s1[i]=='1')
					{ans=i-pos;break;}
				
			}
		


		cout<<ans<<endl;

	}

*/


	ll n,k;
	cin>>n>>k;
	ll a[n];
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}


	sort(a,a+n);
	ll ans=mod;
	for(ll i=0;i<n;i++)
	{
		if(i+k-1<n)
		{
			ans=min(ans,a[i+k-1]-a[i]);
		}
	}


	cout<<ans<<endl;






}
	

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

int main(){
    int H,W;
    while(1){
        cin>>H>>W;
        if(H==0&&W==0){
            break;
        }
        //int count=0;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(i%2==0){
                    if(j%2==0){
                        cout<<"#";
                    }else{
                        cout<<".";
                    }
                }else{
                    if(j%2==0){
                        cout<<".";
                    }else{
                        cout<<"#";
                    }
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
#define int long long
int l;
char ans;
bool f;
int dfs(string s,int x){
  //if(x%10000==1) cout<<s<<" "<<x<<endl;
  int res=0;
  for(int i=0;i<(int)s.size();i++){
    if(isalpha(s[i])){
      if(res==x){
	f=1;
	ans=s[i];
	return 0;
      }
      res++;
      continue;
    }
    //cout<<s[i]<<endl;
    int k=0,op=0;
    for(;isdigit(s[i]);i++) k=k*10+s[i]-'0';
    //cout<<k<<endl;
    string t;
    if(s[i]=='('){
      for(i++;!(op==0&&s[i]==')');i++){
	t+=s[i];
	if(s[i]=='(') op++;
	if(s[i]==')') op--;
      }
    }else t=s[i];
    //cout<<k<<endl;
    for(int j=0;j<k;j++){
      int tmp=dfs(t,x-res);
      if(f) return 0;
      res+=tmp;
    }
    if(f) return 0;
  }
  return res;
}
signed main(){
  string s;
  int x;
  while(cin>>s>>x,!(s=="0"&&x==0)){
    f=0;
    ans='-';
    l=dfs(s,x);
    if(f) cout<<ans<<endl;
    else  cout<<0<<endl;
  }
  return 0;
}

Measured memory_bytes: 3008
#include <stdio.h>
#include <ctype.h>

void input();
void change();

char aaa;
int c;


int main(void)
{
	input();
	printf("\n");
	return 0;
}

void input()
{
	for (;;)
	{
		scanf("%c", &aaa);

		c=aaa;

		if (islower(c)!=0)//?°????????????´???
		{
			printf("%c", c-32);
		}
		else if (isupper(c)!=0)//??§???????????´???
		{
			printf("%c", c+32);
		}
		else if (c == '\n')
		{
			break;
		}
		else
			printf("%c", c);
	}
	return;
}

Measured memory_bytes: 524
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)
#define MP make_pair
typedef long long LL;


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(6);

  int INF = 1000000;

  int n;
  while(cin>>n){
    int res=0;
    bool notPrime[n+1];
    memset(notPrime,0,sizeof(notPrime));
    
    notPrime[0] = notPrime[1] = true;

    for(int i=2; i<=n; i++){
      if(!notPrime[i]){
	res++;
	for(int j=2*i; j<=n; j+=i){
	  notPrime[j] = true;
	}
      }
    }
    cout << res << endl;
  }


  return 0;
}

Measured memory_bytes: 2140
N, X = map(int, input().split())

L = [int(i) for i in input().split()]

L.append(0)

s = [0]
for i in range(1, N+1):
    s.append(s[i-1]+L[i-1])

ans = 0
for i in s:
    if i<=X:ans+=1

print(ans)


Measured memory_bytes: 3060
//============================================================================
// Name        : Hello5.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;




int main() {
	int n;
	string s,t;
	string ans;
	cin>>n;
	cin>>s>>t;
	rep(i,n)
	{
	ans+=s[i];
	ans+=t[i];
	}
	cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
l = []
for i in range(n):
    a, b = map(int, input().split())
    l.append([a, b])
l.sort()
ans = 0
k = 0
while m > 0:
    x = min(m, l[k][1])
    ans += l[k][0] * x
    m -= x
    k += 1
print(ans)

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

namespace ABC129
{
    class A
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split(' ').Select(o => int.Parse(o)).ToArray();
            int max = a.Max();
            int sum = a.Sum();
            int r = sum - max;
            Console.WriteLine(r);
        }
    }
}


Measured memory_bytes: 13396
import itertools

n= int(input())

p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]


a= [i for i in range(1,n+1)]
index =0
b=0
c=0
for i in itertools.permutations(a):
    index += 1    
    if list(i)==p:
       b= index
    if list(i)==q:
        c =index
print(abs(b-c))

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

using namespace std;

const int INF = 1e9 + 5;

int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	vector <int> h(n);
	for (int &x : h)
	{
		scanf("%d", &x);
	}
	vector <int> dp(n, INF);
	dp[0] = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j <= i + k; j++) {
			if (j < n) {
				dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
			}
		}
	}
	printf("%d\n", dp[n - 1]);
	cin.get();
	return 0;
}

Measured memory_bytes: 3948
//int he name of GOD//
#include <bits/stdc++.h>

using namespace std;

int n, g, cnt;

int main()
{
	cin >> n;
	g = sqrt(n);
	for(int i = 1; i<=n; i++)
	{
		for(int j = 1; j<=n; j++)
		{
			if(i*j < n)
			{
//				cout << i<< ' '<< j<< ' '<< (n-(i*j))<< endl;
				cnt++;
			}
			else
			{
				break;
			}
		}
	}
	
	cout << cnt;
	return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
int main(){
	int k, a, b;
	cin >> k >> a >> b;
	for(int i = a; i <= b; i++){
		if(i % k == 0){
			cout << "OK";
			return 0;
		}
	}
	cout << "NG";
}

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

#define pb push_back
#define lli long long int

set <lli> s ;
int main ()
{
    lli n , aux ;
    cin >> n ;

    for (lli i = 0 ; i < n ; i++)
    {
        cin >> aux ;
        s.insert(aux) ;
    }

    if (s.size() == n)
    {
        cout << "YES\n";
    }
    else
    {
        cout << "NO\n" ;
    }
    
    return 0 ;
}



Measured memory_bytes: 9600
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define fi first
#define se second

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum[ohara],pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>m;
    rep(i,m)cin>>a[i];
    sort(a,a+m);
    rep(i,m-1){
        sum[i]=abs(a[i]-a[i+1]);
    }
    sort(sum,sum+m-1);
    reverse(sum,sum+m-1);
    rrep(i,n-1,m-1)ans+=sum[i];
    Cout(ans);
    return 0;
}




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

int main(){

  int n, y;

  cin>>n>>y;

  for(int i=0;i<=y;i+=10000){
    for(int j=0;i+j<=y;j+=5000){
      int z=(y-(i+j))/1000;
      if(z+i/10000+j/5000==n){
        cout<<i/10000<<" "<<j/5000<<" "<<z<<endl;
        return 0;
      }
    }
  }

  cout<<"-1 -1 -1"<<endl;

  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> vp(n);
    for(int i = 0; i < n; i++){
        cin >> vp[i].second >> vp[i].first;
    }
    sort(vp.begin(), vp.end());
    const int INF = 1<<29;
    int dp[n+1][n+1];
    for(int i = 0; i < n+1; i++){
        for(int j = 0; j < n+1; j++){
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= i; j++){
            int ctim = dp[i][j];
            int ntim = ctim+vp[i].second;
            if(ntim <= vp[i].first) dp[i+1][j+1] = min(dp[i+1][j+1], ntim);
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
        }
    }
    for(int i = n; i >= 0; i--){
        if(dp[n][i] == INF) continue;
        cout << i << endl;
        return 0;
    }
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()

using namespace std;

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

  int ans = 0;
  for (auto e : str) {
    if (e == '+')
      ans++;
    else if (e == '-')
      ans--;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back
#define pp pair<int,int>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define int long long
 main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt.txt","r",stdin);
	// freopen("output.txt.txt","w",stdout);
	// #endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	vi w(n),v(n);
	int W;
	cin>>W;
	rep(i,0,n) cin>>w[i]>>v[i];
	int dp[n][W+1];
	rep(i,0,n)
	{
		rep(j,0,W+1)
		{
			if(i==0)
			{
				dp[i][j] = (w[i]<=j)*v[i]; continue;
			}
			dp[i][j] = dp[i-1][j];
			if(j>=w[i])
				dp[i][j] = max(dp[i][j],dp[i-1][j-w[i]]+v[i]);

		}
	}
	cout<<dp[n-1][W]<<endl;




}

Measured memory_bytes: 78336
#include <iostream>

using namespace std;
int cnt = 0;

void insertion_sort(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;
    }
}

void shell_sort(int* a, int n){
    int h = 0;
    int m = 0;
    while (h <= n / 9){
        h = h * 3 + 1;
        m++;
    }
    int g[m];
    g[m - 1] = 1;
    for (int i = 1; i < m; i++){
        g[m - i - 1] = 3 * g[m - i] + 1;
    }

    for (int i = 0; i < m; i++){
        insertion_sort(a, n, g[i]);
    }

    cout << m << endl;
    for (int i = 0; i < m; i++){
        if (i != 0) cout << " ";
        cout << g[i];
    }
    cout << endl << cnt << endl;

    int tmp;
    cin >> tmp;
}

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

    shell_sort(a, n);

    for (int i = 0; i < n; i++){
        cout << a[i] << endl;
    }

    return 0;
}


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


int main(){
    int N;
    int d[110];

    cin >> N;
    for(int i=0;i<N;i++) cin >> d[i];
    int num[110] ={0};
    for(int i=0;i<N;i++){
        num[d[i]]++;
    }
    
    int res =0;
    for(int i=1;i<=100;i++){
        if(num[i])  res++;
    }

    cout << res <<endl;

}


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

int main() {
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    rep(i, a+1){
      rep(j,b+1){
        rep(k,c+1){
          if (x==500*i+100*j+50*k)ans++;
        }
      }
    }
    cout << ans << endl;
}


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

int main()

{
  int a,b;

  cin >> a >> b;

  if ( a < b )cout << "a < b" << '\n';
  else if ( a > b )cout << "a > b" << '\n';
  else if( a == b )cout << "a == b" << '\n';


  return 0;
}

Measured memory_bytes: 1124
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    string a;
    set<string> data;
    for (int i = 0; i < n; i++){
        cin >> a;
        data.insert(a);
    }
    cout << data.size() << endl;
}

Measured memory_bytes: 19216
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#include <complex>
#define ll long long
#define INF 1000000000000000001
#define MOD 998244353
using namespace std;


int main(){
    /* E
    int N;
    ll K;
    cin >> N >> K;
    ll A[200000];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
     */
    
    int N,M;
    cin >> N >> M;
    string S;
    cin >> S;
    
    int temp=N;
    
    stack<int> ans;
    
    int tempans=0;
    
    while(1){
        if(temp==0){
            ans.push(tempans);
            break;
        }
        

        if(tempans==M){
            ans.push(tempans);
            tempans=0;
        }
        
        if(S[temp-1]=='0'){
            tempans++;
            temp--;
        }else{
            
            int cnt = 0;
            for(int i=1; S[temp-i]=='1'; i++){
                cnt++;
            }
            if(tempans+cnt+1 <= M){
                tempans = tempans+cnt+1;
                temp = temp - cnt-1;
            }else{
                if(tempans==0){
                    cout<<-1<<endl;
                    return 0;
                }else{
                    ans.push(tempans);
                    tempans=0;
                }
            }
        }
        
        
    }
    
    
    while(!ans.empty()){
        cout<<ans.top()<<" ";
        ans.pop();
    }
    cout<<endl;
    return 0;
    
}


Measured memory_bytes: 868
import math 


n = int(input())

cnt = 0
l = []
for i in range(n):
    a = int(input())
    l.append(a)

for i in range(n):
    idx = 1

    for j in range(2, int(math.sqrt(l[i])) + 1):
        if l[i] % j == 0:
            idx = 0
            break

    if idx == 1:
        cnt += 1

print(cnt)



Measured memory_bytes: 6008
#include<stdio.h>

int n;
int a;

int main(void)
{
	int i;
	int mltn2, mlt4;
	
	scanf( "%d", &n );
	
	mltn2 = mlt4 = 0;
	for( i=0; i<n; i++ ) {
		scanf( "%d", &a );
		if ( a % 4 == 0 ) mlt4++;
		else if ( a % 2 != 0 ) mltn2++;
	}
	
	if ( mlt4 >= mltn2 || ( mlt4 + mltn2 == n && mlt4 >= mltn2-1 ) ) printf( "Yes\n" );
	else printf( "No\n" );
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <set>
#include <utility>
#include <map>
#include <stdio.h>
using namespace std;

int main() {
    //freopen("in.txt", "r", stdin);

    long long H, W, N;
    set<pair<int, int> > blacks;

    cin >> H >> W >> N;
    for (int i = 0; i < N; ++ i) {
        int r, c;
        cin >> r >> c;
        pair<int, int> p(r, c);
        blacks.insert(p);
    }

    map<int, int> _hash;
    for (int i = 1; i <= 9; ++ i) _hash[i] = 0;
    set<pair<int, int> > visited;
    for(set<pair<int, int> >::iterator iter = blacks.begin(); iter != blacks.end(); ++ iter) {
        for (int i = 0; i > -3; -- i) {
            for (int j = 0; j > -3; -- j) {
                int r0 = iter->first + i;
                int c0 = iter->second + j;
                if (r0 < 1 || r0 > H || c0 < 1 || c0 > W)
                    continue;
                if (r0+2 > H || c0+2 > W)
                    continue;
                pair<int, int> root(r0, c0);
                if (visited.find(root) != visited.end())
                    continue;
                visited.insert(root);
                //cout << r0 << ", " << c0 << ": ";
                int n_black = 0;
                for (int ii = 0; ii < 3; ++ ii) {
                    for (int jj = 0; jj < 3; ++ jj) {
                        int cur_r = r0 + ii;
                        int cur_c = c0 + jj;
                        if (cur_r < 1 || cur_r > H || cur_c < 1 || cur_c > W)
                            continue;
                        pair<int, int> cell(cur_r, cur_c);
                        if (blacks.find(cell) != blacks.end())
                            ++ n_black;
                    }
                }
                //cout << n_black << endl;
                ++ _hash[n_black];
            }
        }
    }

    long long sum = 0;
    for (map<int, int>::iterator iter = _hash.begin(); iter != _hash.end(); ++ iter)
        sum += iter->second;
    long long n_zero = (W-3+1) * (H-3+1) - sum;

    cout << n_zero << endl;
    for (map<int, int>::iterator iter = _hash.begin(); iter != _hash.end(); ++ iter)
        cout << iter->second << endl;

    return 0;
}


Measured memory_bytes: 47104
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new java.util.Scanner(System.in);

        int H = sc.nextInt();
        int A = sc.nextInt();
        int ans = (int)Math.ceil(H / (double)A);

        System.out.println(ans);
    }

}


Measured memory_bytes: 23764
#include<stdio.h>
int main(void){

  int A=0,B=0,C=0;
  scanf("%d",&A);
  scanf("%d",&B);
  scanf("%d",&C);  
  
   if(A==B){
     if(B==C){
       puts("No");
     }
     else{
       puts("Yes");
     }
   }
   else{
     if(B==C){
       puts("Yes");
     }
     else if(A==C){
       puts("Yes");
     }
     else{
       puts("No");
     }
   }
  
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

typedef struct UnionFind {
    std::vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) std::swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
}NODE;

int main() {
    int people, languages;
    
    std::cin >> people >> languages;
    std::vector<std::vector<int> > ability(languages);
    NODE a(people);
    //for (int i = 0; i < people; i++) {
    //    a.data[i] = i;
    //}
    a.data[0] = 1;

    for (int i = 0; i < people; i++) {
        int k;
        std::cin >> k;
        for (int j = 0; j < k; j++) {
            int lang;
            std::cin >> lang;
            ability[lang - 1].push_back(i);
        }
    }

    for (int i = 0; i < languages; i++) {
        for (int j = 1; j < ability[i].size(); j++) {
            a.unionSet(ability[i][j], ability[i][0]);
        }
    }

    bool ans = true;
    int r = a.root(0);

    for (int i = 0; i < people; i++) {
        if (a.root(i) != r) {
            ans = false;
        }
    }

    std::cout << (ans ? "YES" : "NO") << std::endl;

    return 0;
}

Measured memory_bytes: 4608
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int a,b;
int main() {
	scanf("%d%d",&a,&b);
	int d=abs(a-b);
	if (d&1) puts("IMPOSSIBLE");
	else printf("%d\n",a+b>>1);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

int main(){

  int in;
  while(cin >> in && in){
    long long  sum = 0, now = 0;
    int data[in];
    for(int i = 0; i < in; i++) cin >> data[i];
    sort(data,data+in);
    for(int i = 0; i < in; i++){
      sum += now;
      now += data[i];
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

#define pii pair<int,int>

pii v[200000];

int main(){
  int N,M; cin>>N>>M;
  REP(count,M){
    int a,b; cin>>a>>b;
    v[count] = make_pair(a,b);
  }
  sort(v,v+M);
  
  int ans = 0;
  int ca = -1;
  int cb = -1;
  REP(count,M){
    pii k = v[count];
    int ka = k.first;
    int kb = k.second;
    if(ka>=cb){ ca = ka; cb = kb; ++ans; }
    else{ ca = ka; cb = min(cb,kb);}
  }
  cout << ans << "\n";
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
using namespace std;
int gcd(int x,int y){
	if(y==0){
		return x;
	}
	else{
		return (gcd(y,x%y));
	}
}
int main(){
	int x=0,y=0;
	cin>>x;
	cin>>y;

	cout<<x+y-(gcd(x,y)-1)<<endl;
	return (0);
}


Measured memory_bytes: 3092
//
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>

using namespace std;

#define REP(i,m,n) for(int i=m;i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define ALL(x) (x).begin(),(x).end()


int main(){

	int n,t,a;
	long long  int t_r, a_r;
	cin >> n;
	rep(i,n){
		cin >> t >> a;
		if(i == 0){
			t_r = t;
			a_r = a;
			continue;
		}
		long long int m = std::max(std::ceil((long double)t_r/t), std::ceil((long double)a_r/a));
		t_r = m*t;
		a_r = m*a;
	};
	printf("%lld\n", t_r+a_r);
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>

using namespace std;


int main(){

    long long int ans=1;
    int n;
    long long int a[100000];
    cin >> n ;
    for(int i=0;i<n;i++){
        cin >> a[i];
        //cout << a << endl;
    }
    sort(a,a+n);
    for(int i=0;i<n;i++){
        //cout << ans << endl;
        if(a[i] == 0){
            cout << 0 << endl;
            return 0;
        }
        if(1000000000000000000/ans < a[i]){
            cout << -1 << endl;
            return 0;
        }
        ans = ans*a[i];
    }


    cout << ans << endl;
    
    
    
    return 0;

}

Measured memory_bytes: 4420
n,x = map(int,input().split())
a = list(map(int,input().split()))

a = sorted(a)

count = 0

for i in range(n - 1):
    if a[i] <= x:
        x -= a[i]
        count += 1
    else:
        break

if a[-1] == x:
    count += 1

print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>

using namespace std;

const int INF = 100000000;
int N, M, R;
int ds[200][200],dl[200][200];//ship walk
int list[1000];
int dp[1000][200];

int main() {
	while (cin >> N >> M, N + M) {
		for (int i = 0; i < N; i++)for (int j = 0; j < N; j++)
		{
			if (i == j)dl[i][j] = ds[i][j] = 0;
			else dl[i][j] = ds[i][j] = INF;
		}
		for (int i = 0; i < M; i++) {
			int a, b, cost;
			char c;
			cin >> a >> b >> cost >> c;
			a--, b--;
			if (c == 'L') dl[a][b] = min(cost, dl[a][b]), dl[b][a] = dl[a][b];
			else ds[a][b] = min(cost, ds[a][b]), ds[b][a] = ds[a][b];
		}
		cin >> R;
		for (int i = 0; i < R; i++)cin >> list[i],list[i]--;
		//???????????£??????????????????
		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j]);
					dl[i][j] = min(dl[i][j], dl[i][k] + dl[k][j]);
				}
			}
		}
		for (int i = 0; i < R; i++)for (int j = 0; j < N; j++)dp[i][j] = INF;
		//dp[i][j] := i???????????????????????°??§???j?????????????????¨??????????????¨?????????????????????????????????
		for (int i = 0; i < N; i++) {
			dp[0][i] = ds[list[0]][i] + dl[i][list[0]];
		}
		for (int i = 1; i < R; i++) {
			for (int j = 0; j < N; j++) {
				for (int k = 0; k < N; k++) {
					if (j == k)dp[i][j] = min(dp[i][j], dp[i - 1][k] + dl[list[i]][list[i - 1]]);
					else {
						dp[i][k] = min(dp[i][k], dp[i - 1][j] + dl[list[i - 1]][j] + ds[k][j] + dl[k][list[i]]);
					}
				}
			}
		}
		int ans = INF;
		for (int i = 0; i < N; i++)ans = min(ans, dp[R - 1][i]);
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
  string a,b;
  cin>>a>>b;
  int c=0;
  for(int i=0;i<a.size();i++){
    if(!(a.at(i)==b.at(i)))c++;
  }
  if(c==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3632
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h>
using namespace std;
int main(void){
 int N;
 long int x;
 cin >> N >> x;
 vector<long int> vec(N);
 for(int i = 0; i < N; i++)cin >> vec.at(i);
 sort(vec.begin(),vec.end());
 int count = 0;
 long int wa = 0;
 for(int i = 0; i < N; i++)wa += vec.at(i);
 if(wa == x) {
     count = N;
    }
 else if(wa < x){
     count = N - 1;
     }
 else{
     for(int i = 0; i < N ;i++){
         if(x >= vec.at(i)){
             x = x - vec.at(i);
             count++;
         }
         else{break;}
     }
 }
 cout << count << endl;
}

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

char s[200005];
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>(s+1);
    string now = "",pre = "";
    int ans = 0;
    int n = strlen(s+1);
    for(int i = 1;i<=n;i++) {
        now += s[i];
        if(now!=pre) {
            pre = now; ans++; now = "";
        }
    }
    cout<<ans;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
static const int N = 100;
static const int NONE = 0;
static const int DETECTED = 1;
static const int FINISHED = 2;

int M[N][N];

void dfs(int u, int n, int M[N][N], int status[], int t_detected[], int t_finished[], int &t) {
    status[u] = DETECTED;
    t_detected[u] = ++t;
    for (int v = 0; v < n; v++) {
        if (M[u][v] != 0 && status[v] == NONE) {
            dfs(v, n, M, status, t_detected, t_finished, t);
        }
    }
    status[u] = FINISHED;
    t_finished[u] = ++t;
}

int main() {
    int n, u, k, v;
    cin >> n;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }

    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    int status[n], t_detected[n], t_finished[n];
    for (u = 0; u < n; u++) {
        status[u] = NONE;
        // t_detected[u] = 0;
        // t_finished[u] = 0;
    }
    int t = 0;

    for (u = 0; u < n; u++) {
        if (status[u] == NONE) dfs(u, n, M, status, t_detected, t_finished, t);
    }

    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << t_detected[i] << " " << t_finished[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 3132
#include <iostream>
#include <bits/stdc++.h> //for all of STL
#include <numeric> //for accumulate(v.begin(),v.end(),0)
// #include <algorithm>
// #include <vector>

using namespace std;
int64_t n,t,i,j,k,l,flag,c,s,m;
int main()
{
    //long n;
    // cout<<__builtin_popcount(num)<<endl; //for counting number of set (1) bits in a number
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    // cout.tie(NULL);
    // for faster I/O fr CP
    
    cin>>n>>k;
    if(k>=n){
        cout<<"unsafe\n";
    }
    else{
        cout<<"safe\n";
    }
return 0;
}



Measured memory_bytes: 3652
import Data.Char (chr,ord)
import Data.Maybe (fromJust,isJust)

trans [] _ = []
trans [_] _ = []
trans (x:y:s) c
  | y == c = y:trans (y:s) c
  | otherwise = x:trans (y:s) c

solve :: String -> Int -> Char -> Int
solve s n c =
  if s == replicate (length s) c
    then n
    else
      solve ns (n+1) c
  where ns = trans s c

main = do
  s <- getLine :: IO String
  print $ minimum $ map (solve s 0.chr) [ord 'a'..ord 'z']


Measured memory_bytes: 1020
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  long long n,t,ans=1;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> t;
    ans=ans/__gcd(ans,t)*t;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=2010;
const int inf=2147483647;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
int n,k;
struct Edge{int y,next;}e[Maxn<<1];
int last[Maxn],len=0;
void ins(int x,int y)
{
	int t=++len;
	e[t].y=y;e[t].next=last[x];last[x]=t;
}
int f[Maxn][Maxn],g[Maxn],sz[Maxn],ans=inf;
void dfs(int x,int ff)
{
	sz[x]=1;f[x][k]=n;
	for(int i=last[x];i;i=e[i].next)
	{
		int y=e[i].y;
		if(y==ff)continue;
		dfs(y,x);
		for(int j=1;j<k;j++)
		g[j]=min(f[x][j]+f[y][min(k-j-1,j-1)],f[x][min(k-j,j)]+f[y][j-1]);
		f[x][k]=min(f[x][k]+sz[y],sz[x]-1+f[y][k-1]);
		sz[x]+=sz[y];
		f[x][0]+=f[y][0]+1;
		for(int j=2;j<k;j++)g[j]=min(g[j],g[j-1]);
		for(int j=1;j<k;j++)f[x][j]=g[j];
	}
//	for(int i=0;i<=k;i++)
//	printf("f[%d][%d]=%d\n",x,i,f[x][i]);puts("");
	for(int i=1;i<=k;i++)ans=min(ans,n-sz[x]+f[x][i]);
}
int main()
{
//	freopen("wa.txt","r",stdin);
	memset(f,0,sizeof(f));
	n=read(),k=read();
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read();
		ins(x,y),ins(y,x);
	}
	dfs(1,0);
	printf("%d",ans);
}

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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define all(a) (a.begin(), a.end())

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////
	
void solve() {
	int N,K;
	cin >> N >> K;

	ll cnt1 = 0,cnt2=0;
	for (int i = 1; i <= N; ++i) {
		if (i%K==0) {
			++cnt1;
			//cout << i << '\n';
		}
	}

	if (K%2==0) {
		K /= 2;
	}

	for (int i = 1; i <= N; ++i) {
		if (i%K==0) {
			++cnt2;
		}
	}

	cnt2 -= cnt1;

	ll ans = cnt2*cnt2*cnt2 + cnt1*cnt1*cnt1;
	cout << ans << '\n';
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

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

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//
vector<ll> A(vector<ll>& dp){
    vector<ll> res = dp;
    res[1] = ADD(res[1], dp[0]);
    return res;
}
vector<ll> B(vector<ll>& dp){
    vector<ll> res = dp;
    res[2] = ADD(res[2], dp[1]);
    return res;
}
vector<ll> C(vector<ll>& dp){
    vector<ll> res = dp;
    res[3] = ADD(res[3], dp[2]);
    return res;
}

ll solve(string& s) {
    vector<ll> dp(4, 0);
    dp[0] = 1;
    for (char c : s) {
        switch (c) {
            case 'A':
                dp = A(dp); break;
            case 'B':
                dp = B(dp); break;
            case 'C':
                dp = C(dp); break;
            case '?':
                vector<ll> dpA = A(dp), dpB = B(dp), dpC = C(dp);
                rep(i,4) dp[i] = ADD(dpA[i], ADD(dpB[i], dpC[i]));
                break;
        }
    }
    return dp[3];
}

int main() {
    string s; cin >> s;
    cout << solve(s) << endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
    string n;
    cin>>n;
    for(int i=0;i<n.size();i++)
    {
        if(n[i]=='C')
        {
            for(int j=i+1;j<=n.size();j++)
            {
                if(n[j]=='F')
                {
                    cout<<"Yes"<<'\n';
                    return 0;
                }
            }
        }
    }
    cout<<"No"<<'\n';
    return 0;
}

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	string s, t, st;
	cin >> s >> t >> st;
	cout << (char)toupper(s[0]) << (char)toupper(t[0]) << (char)toupper(st[0]) << endl;
	
	Please AC;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int M=500010;
typedef long long ll;
int a[M];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        sort(a,a+n);
        ll x=0,y=0;
        int k1=n-1,k2=0;
        for(int i=n-2;i>=0;i--)
        {
            if(a[i]==a[i+1])
            {
                k1=i;
                x=a[i];
                break;
            }
        }

        for(int i=k1-2;i>=0;i--)
        {
            if(a[i]==a[i+1])
            {
                k2=i;
                y=a[i];
                break;
            }
        }
        printf("%lld\n",x*y);
    }
    return 0;
}


Measured memory_bytes: 640