akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=1e5+10;
const int N=1e3+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int n,m,k,t,p[maxn],a[maxn];
bool ok(int x)
{
    int i,j;
    memset(p,0,sizeof(p));
    p[0]=1;
    rep(i,1,n)
    {
        if(i==x)continue;
        for(j=k;j>=a[i];j--)
        {
            p[j]|=p[j-a[i]];
        }
    }
    rep(i,0,k-1)if(p[i]&&i+a[x]>=k)return false;
    return true;
}
int main()
{
    int i,j;
    p[0]=1;
    scanf("%d%d",&n,&k);
    rep(i,1,n)scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    int l=1,r=n,ret=0;
    while(l<=r)
    {
        int mid=l+r>>1;
        if(ok(mid))ret=mid,l=mid+1;
        else r=mid-1;
    }
    printf("%d\n",ret);
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

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

  int len=s.size();
  int kikuro=0,gukuro=0;
  for(int i=1;i<=len;i++)
  {
    if(i%2==0)
    {
      if(s.at(i-1)=='0') gukuro++;
    }
    else
    {
      if(s.at(i-1)=='0') kikuro++;
    }
  }
  int gusu=len/2,kisu=len-gusu;

  int ans=min(gusu-gukuro+kikuro,kisu-kikuro+gukuro);
  cout<<ans<<endl;

}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
using namespace std;
long long mod = 924844033,f[2010],dp[6010][2010][2] = {};
vector<int> v;
int par[4010],sz[4010];
void init(int n){
	for(int i=0;i<n;i++){
		par[i] = i; sz[i] = 1;
	}
}

int find(int x){
	if(par[x]==x) return x;
	return par[x] = find(par[x]);
}

void unite(int x, int y){
	x = find(x); y = find(y);
	if(x==y) return;
	if(sz[x]<sz[y]) swap(x,y);
	par[y] = x; sz[x] += sz[y];
}

int main(){
	int i,n,k,j,l;
	cin >> n >> k;
	f[0] = 1;
	for(i=1;i<=n;i++){
		f[i] = f[i-1]*i%mod;
	}
	init(2*n);
	for(i=0;i<n;i++){
		if(i + k<n) unite(i,i + n + k);
		if(i>=k) unite(i,i + n - k);
	}
	for(i=0;i<2*n;i++){
		if(par[i]==i) v.push_back(sz[i]);
	}
	dp[0][0][0] = 1;
	int cnt = 0;
	for(i=0;i<v.size();i++){
		for(j=0;j<v[i] - 1;j++){
			cnt++;
			for(l=0;l<=n;l++){
				(dp[cnt][l + 1][1] += dp[cnt - 1][l][0]) %= mod;
				(dp[cnt][l][0] += (dp[cnt - 1][l][0] + dp[cnt - 1][l][1])%mod) %= mod;
			}
		}
		cnt++;
		for(j=0;j<=n;j++){
			dp[cnt][j][0] = (dp[cnt - 1][j][0] + dp[cnt - 1][j][1])%mod;
		}
	}
	long long ans = f[n],sig = -1;
	for(i=1;i<=n;i++){
		(ans += sig*dp[cnt][i][0]%mod*f[n - i]%mod + mod) %= mod;
		sig *= -1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 127232
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int i, j, x, y, z, temp = 0, a[3] = { 0 }, b, c;
	cin >> a[0] >> a[1] >> a[2];
	for (i = 0; i < 3; i++) {
		for (j = i; j < 3; j++) {
			if (a[i] > a[j]) {
				temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
	}
	printf("%d %d %d\n", a[0], a[1], a[2]);
}

Measured memory_bytes: 3112
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int a,b,c;
cin>>a>>b>>c;

ol(c-min(c,a-b));

return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
         
        int r = stdIn.nextInt();
        int c = stdIn.nextInt();
         
        int[][] h = new int[r+1][c+1];
         
        for(int i = 0; i < r; i++) {
            int rsum = 0;
            for(int j = 0; j < c; j++) {
                int tmp = stdIn.nextInt();
                rsum += tmp;
                h[i][j] = tmp;
            }
            h[i][c] = rsum;
        }
         
        for(int i = 0; i < c+1; i++) {
            int rsum = 0;
            for(int j = 0; j < r; j++) {
                rsum += h[j][i];
            }
            h[r][i] = rsum;
        }
         
        for(int i = 0; i < r+1; i++) {
            for(int j = 0; j < c; j++) {
                System.out.print(h[i][j] + " ");
            }
            System.out.println(h[i][c]);
        }
    }
}


Measured memory_bytes: 42060
using System;

namespace abc071A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            int C = int.Parse(str[2]);
            if (Math.Abs(A - B) > Math.Abs(A - C))
                Console.WriteLine("B");
            else
                Console.WriteLine("A");
        }
    }
}


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

int main() {
	int temp;
	vector<int> num;

	for(int i= 0;i<3 ;i++){
		cin >> temp;
		num.push_back(temp);
	}

	sort(num.begin(), num.end());

	cout << num[2]*10+num[0]+num[1];


}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<long long int>v(N);
	for (auto &i : v)cin >> i;
	while (N < 5) {
		N++;
		v.push_back(0);
	}
	long long int ans = accumulate(v.begin(), v.end(), 0LL);
	vector<vector<vector<int>>>num(5);
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			num[0].push_back({ i, j });
		}
	}
	num[1].push_back({ 0, 1, 2 });
	for (int i = 0; i < 3; i++) {
		for (int j = 3; j < N; j++) {
			num[1].push_back({ i, j });
		}
	}
	num[1].push_back({ 3, 4 });
	num[2].push_back({ 0, 1, 2, 3 });
	for (int i = 0; i < 4; i++)num[2].push_back({ i, 4 });
	num[3].push_back({ 0, 1, 2, 3, 4 });
	num[4].push_back({ 0,1,2 });
	num[4].push_back({ 2,3,4 });
	num[4].push_back({ 0,3 });
	num[4].push_back({ 0,4 });
	num[4].push_back({ 1,3 });
	num[4].push_back({ 1,4 });
	sort(v.begin(), v.end());
	int minus = 0;
	bool flag =false;
	do {
		for (auto i : num) {
			if (i.size() == 10 && flag)continue;
		//	cout << i.size() << endl;
			flag = true;
			vector<int>p(i.size());
			for (int j = 0; j < i.size(); j++)p[j] = j;
			do {
				int box = 0;
				auto w = v;
				for (auto j : p) {
					bool ok = true;
					for (auto k : i[j]) {
						ok &= !!w[k];
					}
					if (ok) {
						box += i[j].size() - 1;
						for (auto k : i[j])w[k]--;
					}
				}
				minus = max(minus, box);
			} while (next_permutation(p.begin(), p.end()));
		}
	} while (next_permutation(v.begin(), v.end()));
	cout << ans - minus << endl;
}


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

int n;
const int M = 1000000007;
const int MAX_N = 100001;
int dp[MAX_N][2];
vector<int> v[MAX_N];

int dfs(int x, int c, int par)
{
    if (dp[x][c])
        return dp[x][c];
    long long int ans = 1;
    for (int i = 0; i < v[x].size(); i++)
    {
        if (v[x][i] == par)
        {
            continue;
        }
        if (c == 1)
        {
            ans *= (dfs(v[x][i], 1, x) + dfs(v[x][i], 0, x));
            ans %= M;
        }
        else
        {
            ans *= dfs(v[x][i], 1, x);
            ans %= M;
        }
    }
    dp[x][c] = ans;
    return ans;
}

int main()
{
    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int ans = dfs(1, 0, 0) + dfs(1, 1, 0);
    ans %= M;
    cout << ans << endl;
    return 0;
}

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

#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define f first
#define s second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;


signed main(){

	int n, x, flag = 0;
	cin >> n;

	int a[n];

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

	for (int i = 1; i < n; ++i)
	{
		if (a[i] == a[i-1]){
			flag = 1;
			break;
		}
	}
	if (flag == 1){
		cout << "NO" << endl;
	}
	else{
		cout << "YES" << endl;
	}
	return 0;
}



/*

*/

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (A != B && B != C&&A!=C){
		cout << "No";
		return 0;
	}
	else if (A == B && B == C&&A==C)
	{
		cout << "No";
		return 0;
	}
	else if (A == B && B != C)
	{
		cout << "Yes";
		return 0;
	}
	else if (A == C && B != C)
	{
		cout << "Yes";
		return 0;
	}
	else if (B == C && A != C) {
		cout << "Yes";
		return 0;
	}
	else
	{

	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll inf = (1LL << 60LL);
const int maxn = 50005;
int n;
vector<int> a;
int dp[maxn * 2][3];
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin >> n;
    for(int i = 0; i < n; i ++){
        int num;
        cin >> num;
        a.push_back(num);
    }
    sort(a.begin(), a.end());
    int l=a[(int)a.size() - 1]; 
    int r=l;             
    int i=0, j = (int)a.size() - 2;
    long long int sum=0;
    while(i < j){
        int li = abs(l - a[i]), ri = abs(r - a[i]);
        int lj = abs(l-a[j]),rj = abs(r - a[j]);
        if(li>ri || lj>rj){ 
            if(li > lj){
                sum += li;
                l = a[i ++];
            }
            else{
                sum += lj;
                l = a[j --];
            }
        }
        else{
            if(ri > rj){
                sum += ri;
                r = a[i ++];
            }
            else{
                sum += rj;
                r = a[j --];
            }
        }
    }
    sum += max(abs(l - a[i]),abs(r - a[i]));
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 892
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int main()
{
    int n;
    while(cin>>n)
    {
        cout<<(n+1)/2<<endl;
    }
    return 0;
}


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

int main() {
  int a;
  string b;
  int c = 0;
  cin >> a >> b;
  for (int i = 0; i < a; i++) {
    if (b.substr(i, 3) == "ABC") {
      c++;
    }
    
  }
  cout << c;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
#define int long long int

using P = pair<int, int>;

int W, H, D;

int memo[300 * 300];
P pos[300 * 300 + 1];

void solve() {
  for (int i = D + 1; i < 300 * 300 + 1; i++) {
    P from = pos[i - D];
    P to = pos[i];
    memo[i] =
        memo[i - D] + abs(from.first - to.first) + abs(from.second - to.second);
  }
}

signed main() {
  cin >> W >> H >> D;

  for (int w = 0; w < W; w++) {
    for (int h = 0; h < H; h++) {
      int a;
      cin >> a;
      pos[a] = make_pair(w, h);
    }
  }

  solve();

  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << memo[r] - memo[l] << endl;
  }
}


Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <algorithm>
#define pb push_back
#define mp make_pair
using namespace std;

const long long mod = 1e9 + 7;

void solve() {
	int n; cin >> n;
	vector<vector<int> > a(n, vector<int>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	vector<long long> dp(1 << n);
	dp[0] = 1;
	for (int mask = 0; mask < (1 << n) - 1; mask++) {
		int m = __builtin_popcount(mask);
		for (int w = 0; w < n; w++) {
			if (a[m][w] and !(mask & (1 << w))) {
				dp[mask ^ (1 << w)] += dp[mask];
				dp[mask ^ (1 << w)] %= mod;
			}
		}
	}
	cout << dp[(1 << n) - 1] << endl;
}

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

Measured memory_bytes: 16768
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1e9;
#define MOD 1e9+7;
#define INF64 1e18;

#define F first
#define S second


using namespace std;

SINT32 MASU[3][3];

int main() {

	
	rep(i,0,3) {
		rep(j,0,3) {
			cin >> MASU[i][j];
		}
	}

	rep(c1,0,101) {
		rep(c2,0,101) {
			rep(c3,0,101) {
				if (((MASU[0][0]+c1 == MASU[0][1]+c2) && (MASU[0][0]+c1== MASU[0][2]+c3))
				&& ((MASU[1][0]+c1 == MASU[1][1]+c2) && (MASU[1][0]+c1== MASU[1][2]+c3))
				&& ((MASU[2][0]+c1 == MASU[2][1]+c2) && (MASU[2][0]+c1== MASU[2][2]+c3))) {
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}



	cout << "No" << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));　//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();	//key以上を探す
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/

/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 0) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N, X;
  std::cin >> N >> X;
  std::vector< ll > vm(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> vm[i];
  }

  ll sum = std::accumulate(vm.begin(), vm.end(), 0);
  ll mval = *std::min_element(vm.begin(), vm.end());

  ll ans = (X - sum) / mval + N;
  print(ans);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> prl;
typedef vector<ll> vcl;
typedef map<ll,ll> mapl;
typedef unordered_map<ll,ll> umap;
#define pb push_back
#define all(v) v.begin(), v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repi(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;

int main() {
    // your code goes here
    ll n,k,p[5005],c[5005],ans=-1e18;
    bool used[5005]={0};
    cin >> n >> k;
    rep(i,0,n-1){
    	cin >> p[i];
    	p[i]--;
    }
    rep(i,0,n-1){
    	cin >> c[i];
    }
    rep(i,0,n-1){
    	if(!used[i]){
    		ll pv=i,np,cyc,mx=-1e18;
    		vcl gm;
    		while(!used[pv]){
    			//cout << pv << endl;
    			used[pv]=true;
    			gm.pb(pv);
    			pv=p[pv];
    		}
    		np=gm.size();
    		ll dp[np+5][np+5]={0};
    		//cout << np << endl;
    		rep(x,0,np-1){
    			rep(y,1,np){
    				dp[x][y]=dp[x][y-1]+c[gm[(x+y)%np]];
    			}
    		}
    		cyc=dp[0][np];
    		//cout << cyc << endl;
    		if(k>np&&cyc<0){
    			rep(x,0,np-1){
    				rep(y,1,min(np,k)){
    					chmax(mx,dp[x][y]);
    				}
    			}
    			chmax(ans,mx);
    		} else {
    			ll km=k;
    			ll s=max(((k-1)/np)-1,0ll);
    			ll ss=s*cyc;
    			km-=s*np;
    			rep(x,0,np-1){
    				rep(y,1,km){
    					if(y<=np) chmax(mx,dp[x][y]);
    					else chmax(mx,dp[x][y-np]+cyc);
    				}
    			}
    			ss+=mx;
    			chmax(ans,ss);
    		}
    	}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 199484
let f()=List.map int_of_string(Str.split(Str.regexp_string" ")(read_line()))open Array;;match f()with[n;m]->let a,b=make(n*m)0,make m 0in for i=0to n-1do List.iteri(fun j e->a.(m*i+j)<-e)(f())done;for i=0to m-1do b.(i)<-read_int()done;for i=0to n-1do let c=ref 0in for j=0to m-1do c:=!c+a.(m*i+j)*b.(j)done;Printf.printf"%d
"!c done|_->()

Measured memory_bytes: 4052
using System;

public class ABC0137_A1v1 {
    private static void Main(string[] args) {
        var input = Console.ReadLine().Trim();
        Prepare(input);
    }

    private static void Prepare(string input) {
        var numStrs = input.Split();
        Compute(int.Parse(numStrs[0]), int.Parse(numStrs[1]));
    }

    private static void Compute(int numA, int numB) {
        var answer = Math.Max(numA + Math.Abs(numB), numA * numB);
        OutputAnswer(answer.ToString());
    }

    private static void OutputAnswer(string text) => Console.WriteLine(text);
}

Measured memory_bytes: 11220
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int fqm[4][4] = {{1, 2, 3, 4}, {2, -1, 4, -3}, {3, -4, -1, 2}, {4, 3, -2, -1}};
int judge(int a, int b){
	return fqm[a][b];
}

int main(void){
	int n;
	while(cin >> n, n){
		rep(t, n){
			int cA[4], cB[4], cal = 0;
			int xx = 0, yy = 0,zz = 0, ww = 0;
			rep(d, 4){
				cin >> cA[d];
			}
			rep(d, 4){
				cin >> cB[d];
			}
			for(int j = 0; j < 4; j++){
				for(int k = 0; k < 4; k++){
					int calc = cA[j] * cB[k];
					int ff = judge(j, k);
					int fl = abs(ff);
					if(fl == 1){
						xx += (calc*ff);
					}else if(fl == 2){
						yy += (calc*ff)/2;
					}else if(fl == 3){
						zz += (calc*ff)/3;
					}else if(fl == 4){
						ww += (calc*ff)/4;
					}
				}
			}
			cout << xx << " " << yy << " " << zz << " " << ww << endl;
		}
	}

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 1168
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
//#include "C:\code\all.h"
#define rep(i,n) for(i = 0; i < n; i++)
using namespace std;

int main(){
  int n;
  int i;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  int count2n1 = 0;
  rep(i,n) if(a[i] % 2 == 1) count2n1++;
  if(count2n1 % 2 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int ans = 0;
    for (int i = 0; i < k; i++) {
        ans += a[i];
    }
    cout << ans << endl;
}



Measured memory_bytes: 3652
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int to[200000];
vector<int>frm[200000];
bool flag[220000];
bool iscirc[200000];
typedef pair<int, int>pii;
pii dfs(int node)
{
	vector<int>v;
	for (int i = 0; i < frm[node].size(); i++)
	{
		if (!iscirc[frm[node][i]])
		{
			v.push_back(dfs(frm[node][i]).first);
		}
	}
	for (int i = 0; i < v.size(); i++)flag[v[i]] = true;
	pii z;
	int c = 0;
	for (int i = 0;; i++)
	{
		if (!flag[i] && c == 0)c++, z.first = i;
		else if (!flag[i] && c == 1)
		{
			z.second = i;
			break;
		}
	}
	for (int i = 0; i < v.size(); i++)flag[v[i]] = false;
	return z;
}
void yes()
{
	printf("POSSIBLE\n");
	exit(0);
}
void no()
{
	printf("IMPOSSIBLE\n");
	exit(0);
}
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)
	{
		scanf("%d", &to[i]);
		to[i]--;
		frm[to[i]].push_back(i);
	}
	int now = 0;
	vector<int>circ;
	for (;;)
	{
		if (flag[now])
		{
			int z = now;
			for (;;)
			{
				circ.push_back(z);
				//printf("%d\n", z + 1);
				iscirc[z] = true;
				z = to[z];
				if (z == now)break;
			}
			break;
		}
		flag[now] = true;
		now = to[now];
	}
	fill(flag, flag + num, false);
	vector<pii>v;
	for (int i = 0; i < circ.size(); i++)v.push_back(dfs(circ[i]));
	int t = v[v.size() - 1].first;
	for (int i = 0; i < v.size(); i++)
	{
		//printf("%d %d\n", v[i].first, v[i].second);
		if (v[i].first == t)t = v[i].second;
		else t = v[i].first;
	}
	if (t == v[v.size() - 1].first)yes();
	t = v[v.size() - 1].second;
	for (int i = 0; i < v.size(); i++)
	{
		if (v[i].first == t)t = v[i].second;
		else t = v[i].first;
	}
	if (t == v[v.size() - 1].second)yes();
	no();
}

Measured memory_bytes: 14196
S = input()
ans = ""
for b in range(2**(3)):
    ans = ""
    for i,s in enumerate(S):
        ans += s
        if b & 1 << i:
            ans += "+"
        else:
            ans += "-"
    ans = ans[:-1]
    if eval(ans)==7:
        print("{}=7".format(ans))
        break

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

int fib(int n){
    int A[45]={};
    A[0]=1; A[1]=1;
    
    if(n==0 || n==1) return 1;
    else{
        for(int i=2; i<=n; i++) A[i]=A[i-1]+A[i-2];
        return A[n];
    }
}


int main(){
    int n;
    cin>>n;
    cout<<fib(n)<<endl;
    return 0;
}



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

#define int long long
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);

int32_t main(){
	fast;
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	if(a[0] + a[1] == a[2]) cout << "Yes\n";
	else    cout << "No\n";
}







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

int main(){
    int N, K;
    string S;
    cin >> N >> S >> K;

    for (int i = 0; i < N; i++){
        if(S[i] == S[K - 1])
            cout << S[i];
        else
            cout << "*";    
    }
    cout << endl;

    return 0;
}

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

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> B(N - 1);
	for (auto &x : B) {
		cin >> x;
	}

	int ans = B[0] + B[N - 2];
	for (int i = 0; i + 1 < N - 1; ++i) {
		ans += min(B[i], B[i + 1]);
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define eb pb
#define rep(X,Y) for(int X=0;X<(Y);++X)
#define reps(X,O,Y) for(int X=O;X<(Y);++X)
#define all(X) (X).begin(),(X).end()

using namespace std;
using ll=long long;

const int N=11234567;
int prime[N];

int main(){
	fill(prime,prime+N,1);
	prime[0]=prime[1]=0;
	rep(i,N)if(prime[i])for(int j=i+i;j<N;j+=i) prime[j]=0;
	// rep(i,10) cout<<prime[i];cout<<endl;
	int n;
	cin>>n;
	if(n<=2){ cout<<0<<endl; return 0;}
	int re=0;
	reps(i,3,n+1)if(prime[i] && prime[i+2]) ++re;
	cout<<re*2<<endl;
}



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

vector<int>PF(int n)
{
	vector<int>v;
	for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			while(n%i==0)
			{
				n/=i;
				v.push_back(i);
			}
		}
	}
	if(n!=1)v.push_back(n);
	return v;
}

int main()
{	
	int n;
	cin>>n;
	vector<int>v=PF(n);
	cout<<n<<":";
	for(int i=0;i<v.size();i++)cout<<" "<<v[i];
	cout<<endl;
	return 0;	
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int L = A + B;
  int R = C + D;
 
  if (L > R) {
    cout << "Left" << endl;
  }
  else if (L == R){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <sstream> //string stream its useful!
#include<string>
#include<iostream>
#include<utility> //pair
#include <vector> // vector
#include <algorithm>    // swap,sort,binary_search
#include <functional>   // std::greater
#include <map> //map
#include<set> //set
#include<queue> //queue
#include<list> //list
#include<cmath>
#include<numeric>
#include<cassert>
#include <iomanip> //cout<<setprecision
#include <regex>



typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
ll W = 1000000007;


using namespace std;
void omajinai() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(15);
    //freopen("txt.csv","r",stdin);
}


class Main{
public:
    Main(){
        
    }
    
    
    void run(){
        int a,b,c; cin>>a>>b>>c;
        cout<<((a<=c && c<=b)?"Yes": "No")<<endl;
    }
};

int main(){
    omajinai();
    Main().run();
}

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

using namespace std;

int t1, t2;
long long a1, a2, b1, b2;

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    if (a1 > b1) swap(a1, b1), swap(a2, b2);
    long long d1 = a1*t1+a2*t2, d2 = b1*t1+b2*t2;
    long long aa1 = a1*t1, aa2 = a2*t2, bb1 = b1*t1, bb2 = b2*t2;
    if (d1 < d2) {
        cout << 0 << endl;
        return 0;
    }
    if (d1 == d2) {
        cout << "infinity" << endl;
        return 0;
    }
    // aa1 < bb1, aa2 > bb2, dd1+dd2 > 0
    long long dd1 = aa1-bb1, dd2 = aa2-bb2;
#ifdef DEBUG
    cout << dd1 << " " << dd2  << " " << dd1+dd2 << endl;
#endif
    cout << (-dd1)/(dd1+dd2)*2+((-dd1)%(dd1+dd2) != 0) << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#include<stdlib.h>

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cstdlib>

#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=1e6+6;
const int mod=1e9+7;
ll a[maxn]={1,0,0,1,1};
bool cmp(ll a,ll b){
    return a>b;
}
int main()
{
    cin.tie(0);std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    if(n>4){
        for(int i=5;i<=n;i++)
            a[i]=(a[i-1]+a[i-3])%mod;
    }
    cout<<a[n]<<endl;
	system("pause");
    return 0;
}

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

int	max(int a, int b)
{
	return ((a > b) ? a : b);
}

int	main(void)
{
	int	N, i, j, m = 0, sum = 0;
	int	*L;

	scanf("%d", &N);
	L = malloc(sizeof(int) * N);
	for (i = 0; i < N; i++)
	{
		scanf("%d", &L[i]);
		if (m < L[i])
		{
			m = L[i];
			j = i;
		}
	}
	for (i = 0; i < N; i++)
		if (i != j)
			sum += L[i];
	if (m < sum)
		printf("Yes\n");
	else
		printf("No\n");
	return (0);
}

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

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  vector<ll> v(n);
  for (int i = 0; i < n; i++) { cin >> v[i]; }

  ll ans = 0;
  for (int i = 0; i < n - 1; i++)
    ans += min((v[i + 1] - v[i]) * a, b);

  cout << ans << endl;
}


Measured memory_bytes: 1024
val MOD = 1000000007L

fun main(args : Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toLong() }

    var max = (n downTo (n-k)+1).sum()
    var min = (0..k-1).sum()

    var ans = 0L

    for (i in k..n+1) {
        ans += max - min + 1
        ans %= MOD

        min += i
        max += n-i
    }

    println(ans)
}

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

void chmax(double& a, double b){
    a = max(a, b);
}
void chmin(double& a, double b){
    a = min(a, b);
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> edges[600];
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        edges[a-1].push_back(b-1);
    }
    double ans = 1e18;
    for(int s=0; s<N; s++){
        vector<double> dp(N);
        for(int i=N-2; i>=0; i--){
            double sum = 0, mx = 0;
        for(int j : edges[i]){
            sum += dp[j];
            chmax(mx, dp[j]);
            }
            int sz = edges[i].size();
            if(i == s && sz > 1){
                dp[i] = 1 + (sum-mx)/(sz-1);
            }else{
                dp[i] = 1 + sum/sz;
            }
        }
        chmin(ans, dp[0]);
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0226
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] a = Console.ReadLine().Split();
                if (a[0] == a[1] && a[1] == "0") { break; }
                int hit = 0,blow=0;
                for (int i = 0; i < 4; i++)
                {
                    for (int k = 0; k < 4; k++)
                    {
                        if (a[0][i] == a[1][k])
                        {
                            if (i == k) { hit++; }
                            else { blow++; }
                        }
                    }
                }
                Console.WriteLine(hit+" "+blow );
            }
        }
    }
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}
// }}}
/* vim:set foldmethod=marker: */

int main(int argc, char const* argv[])
{
    int n,k;
    cin >> n >> k;

    int ans=1;
    for (int i = 0; i < n; i++) {
        ans = min(ans * 2, ans + k);
    }

    cout << ans << endl;
    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, a, b) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << '\n';

template <class T> vector<T> xor_span(vector<T> a) {
  int k = 0;
  for (int i = 8 * int(sizeof(T)) - 1; i >= 0; --i) {
    auto p = find_if(a.begin() + k, a.end(), [i](T x) { return x & T(1) << i; });
    if (p == a.end()) continue;
    swap(a[k], *p);
    for (int j = 0; j < int(a.size()); j++)
      if (j != k && (a[j] & T(1) << i)) a[j] ^= a[k];
    k++;
  }
  return a.resize(k), a;
}

int main() {
  int n;
  cin >> n;
  vector<LL> a(n);
  FI(i,0,n-1) scanf("%lld", &a[i]);
  LL ans = 0;
  for (LL x: a) ans ^= x;
  for (LL &x: a) {
    for (int i = 0; i < 60; ++i) {
      if (ans & 1LL << i) {
        if (x & 1LL << i) x ^= 1LL << i;
      }
    }
  }
  auto v = xor_span(a);
  LL mask = 0;
  for (LL x: v) mask = max(mask, mask ^ x);
  cout << ans + mask * 2 << endl;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN 800010
#define LL long long
#define P 924844033
using namespace std;

LL getPow(LL x,LL y){
	LL res=1;
	while(y){
		if(y&1) res=res*x%P;
		x=x*x%P;
		y>>=1;
	}
	return res;
}

struct edge{
	int to,next;
	edge(int _to=0,int _next=0):to(_to),next(_next){}
}e[MAXN<<1];

int n,sizew;
int g[MAXN],nume;
int size[MAXN];
LL fac[MAXN],invfac[MAXN];
LL c[MAXN],d[MAXN],f[MAXN];

void addEdge(int u,int v){
	e[nume]=edge(v,g[u]);
	g[u]=nume++;
}

void dfs(int x,int p){
	size[x]=1;
	for(int i=g[x];~i;i=e[i].next)
		if(e[i].to^p){
			dfs(e[i].to,x);
			size[x]+=size[e[i].to];
		}
}

void init(){
	fac[0]=1;
	for(int i=1;i<MAXN;i++) fac[i]=fac[i-1]*i%P;
	invfac[MAXN-1]=getPow(fac[MAXN-1],P-2);
	for(int i=MAXN-2;i>=0;i--) invfac[i]=invfac[i+1]*(i+1)%P;
}

LL getC(int x,int y){
	if(x<y) return 0;
	return fac[x]*invfac[y]%P*invfac[x-y]%P;
}

void FFT(LL *a,int len,int flag){
	static int rev[MAXN];
	rev[0]=0;
	for(int i=1;i<len;i++) rev[i]=rev[i>>1]>>1|((i&1)?(len>>1):0);
	for(int i=0;i<len;i++)
		if(i<rev[i]) 
			swap(a[i],a[rev[i]]);
	for(int l=2;l<=len;l<<=1){
		LL w=getPow(5,(P-1)/l);
		int l2=l/2;
		for(int i=0;i<len;i+=l){
			LL temp=1;
			for(int j=0;j<l2;j++){
				LL t1=a[i+j],t2=a[i+j+l2]*temp%P;
				a[i+j]=(t1+t2)%P;
				a[i+j+l2]=(t1-t2)%P;
				temp=temp*w%P;
			}
		}
	}
	if(flag==-1){
		LL invn=getPow(len,P-2);
		for(int i=0;i<len;i++)
			a[i]=a[i]*invn%P;
		for(int i=1;i<len;i++)
			if(i<len-i)
				swap(a[i],a[len-i]);
	}
}

int main(){
#ifdef DEBUG
	freopen("F.in","r",stdin);
#endif
	init();
	memset(g,-1,sizeof g);
	scanf("%d",&n);
	for(sizew=1;sizew<=n;sizew<<=1);
	sizew<<=1;
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		addEdge(u,v);
		addEdge(v,u);
	}
	dfs(1,0);
	for(int i=2;i<=n;i++){
		c[size[i]]++;
		c[n-size[i]]++;
	}
	for(int i=1;i<=n;i++) c[i]=c[i]*fac[i]%P;
	for(int i=0;i<=n;i++) d[i]=invfac[n-i];
	FFT(c,sizew,1); FFT(d,sizew,1);
	for(int i=0;i<sizew;i++) f[i]=c[i]*d[i]%P;
	FFT(f,sizew,-1);
	for(int i=1;i<=n;i++){
		f[i]=f[i+n]*invfac[i]%P;
		f[i]=((getC(n,i)*n-f[i])%P+P)%P;
		printf("%lld\n",f[i]);
	}
	return 0;
}


Measured memory_bytes: 62080
#define MyDebug
#include <bits/stdc++.h>

#define rep(i, first, to) for(int i = first; i < to; ++i)
#define REP(i, first, to) for(int i = first; i <= to; ++i)

#ifdef MyDebug
	#define debug(x) cerr << #x << " : " << x << endl
	#define debugP(x) cerr << x << endl
#else
	#define debug(x)
	#define debugP(x)
#endif

using namespace std;
typedef long long ll;

int n;
void solve() {
	cin >> n;
	int p = 1;
	for (int i = 0; ; ++i) {
		p *= 2;
		if (p > n) {
			break;
		}
	}
	p = p / 2;
	cout << p << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include "Local_Debug.h"
using namespace std;
#define Endl endl
#define debug(x) cout << #x << " = " << (x) << endl
typedef long long ll;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 5;
ll n, k, h;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	while (cin >> n >> k)
	{
		ll ans = 0;
		for (ll i = 1; i <= n&&cin >> h; ++i)
			if (h >= k)
				ans++;
		cout << ans << endl;
	}
}
/*
4 150
150 140 100 200

1 500
499

5 1
100 200 300 400 500
*/

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>
#include <atcoder/all>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 998244353;

int op(int a, int b) {
    return max(a, b);
}

int e() {
    return 0;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, k;
    cin >> n >> k;

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

    atcoder::segtree<int, op, e> seg(300001);
    seg.set(a[0], 1);
    for(int i=1;i<n;++i) {
        int max_prev = seg.prod(max(0, a[i]-k), min(300001, a[i]+k+1));
        seg.set(a[i], max_prev + 1);
    }

    cout << seg.all_prod() << endl;
}

Measured memory_bytes: 9792
#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int main() 
{
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a+3);
  int ans=0;
  ans += a[2] -a[1];
  ans += (a[1] -a[0])/2 + ((a[1] -a[0])%2)*2;
  cout << ans << endl;
 
}

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

int main (void) {
    int n, sum = 0;
    scanf("%d", &n);

    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }

    sort(vec.begin(), vec.end(), greater<int>());

    for (int i = 0; i < n; i += 2) {
        sum += vec.at(i);
    }

    for (int i = 1; i < n; i += 2) {
        sum -= vec.at(i);
    }

    printf("%d", sum);
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    s[0] = '2';
    s[1] = '0';
    s[2] = '1';
    s[3] = '8';
    cout << s << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pb push_back
#define ii pair<int,int>
#define iii pair<ii,int>
#define ppb pop_back
#define st first
#define nd second
#define ll long long
#define N 500005
#define inf 2000000005
#define MOD 1000000007
#define LOG 14
#define EPS 0.000000001
using namespace std;

int f(int n) {

	int cnt = 0;
	for(int i = 1; i * i <= n; i++) {
		for(int j = 1; j <= i; j++) {
			int r = n - i * i - j * j - i * j;
			if(r < 0)
				break ;
			int s = i + j;
			int delta = s * s + 4 * 1 * r;
			if(delta > 0) {
				int sq = sqrt(delta);
				if(sq * sq == delta) {
					if(!((-s + sq) % 2)) {
						cnt += ((-s + sq) > 0) * (1 + (i != j));
					}
				}
			}
		}
	}
	return cnt;

}

int main() {

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

	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
		cout << f(i) << "\n";

}

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

int main() {
  
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  ll k;
  cin >> k;
  ll n = 7, ans = 1;
  
  rep(i,1000000) {
    if (n % k == 0) {
      cout << ans << endl;
      return 0;
    }
    ans++;
    n = (10 * n + 7 ) % k;
  }
  cout << -1 << endl;
}

Measured memory_bytes: 3600
h,w,k=map(int,input().split())
s=[list(input()) for i in range(h)]

ans=[[0]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            x=i
            y=j
            break
    else:
        continue
    break
for i in range(y+1):
    ans[x][i]=1
k=1
for i in range(y+1,w):
    if s[x][i]=="#":
        k+=1
        ans[x][i]=k
    else:
        ans[x][i]=k
for i in range(x-1,-1,-1):
    for j in range(w):
        if s[i][j]=="#":
            a=j
            k+=1
            break
    else:
        ans[i]=ans[i+1]
        continue
    for j in range(a+1):
        ans[i][j]=k
    for j in range(a+1,w):
        if s[i][j]=="#":
            k+=1
            ans[i][j]=k
        else:
            ans[i][j]=k
for i in range(x+1,h):
    for j in range(w):
        if s[i][j]=="#":
            a=j
            k+=1
            break
    else:
        ans[i]=ans[i-1]
        continue
    for j in range(a+1):
        ans[i][j]=k
    for j in range(a+1,w):
        if s[i][j]=="#":
            k+=1
            ans[i][j]=k
        else:
            ans[i][j]=k

for u in ans:
    print(*u)

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

#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int gcd(int a, int b){
    int r, tmp;

      /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

    /* ユークリッドの互除法 */
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main(){
    int K;
    cin>>K;
    ll ans=0;
    for(int i=1;i<=K;i++){
        for(int j=1;j<=K;j++){
            int temp=gcd(i,j);
            for(int k=1;k<=K;k++){
                ans+=gcd(temp,k);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

template<class T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

template<class T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }


int main() {
    int n;
    cin>>n;
    vector<ll> a(3*n);
    rep(i,3*n)cin>>a[i];
    sort(a.begin(),a.end());
    ll ans = 0;

    for(int i=3*n-2;i>n-1;i-=2){
        ans+=a[i];
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 2560
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		// your code goes here
		
		var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
		int n = a[0];
		int d = a[1];
		int hani = 2*d+1;
		int answer = n/hani;
		if(n%hani!=0){answer++;}
		Console.WriteLine(answer);
		
	}
}

Measured memory_bytes: 13268