akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;
    Vec a(n);
    cin>>a;
    bool ok = true;
    rep(i,n){
        if(a[i]%2==0){
            if(a[i]%3!=0 && a[i]%5!=0){
                ok = false;
            }
        }
    }
    cout<<(ok?"APPROVED":"DENIED")<<endl;
    return  0;
}


Measured memory_bytes: 256
a,b = map(int,input().split())
S = input()
tmp = S[0]
cnt = 0
L = []
for x in S:
    if tmp == x:
        cnt += 1
    else:
        L.append(cnt)
        cnt = 1
        tmp = x
L.append(cnt)
tmp = 0
for _ in range(b):
    for _ in range(2):
        try:
            tmp += L.pop(0)
        except:
            print(a- 1)
            quit()
try:
    tmp += L.pop(0)
except:
    print(a-1)
    quit()
L = [tmp] + L
print(sum(L) - len(L))


Measured memory_bytes: 4724
#include <iostream>
#include <algorithm>
#include <set>
#define int long long
using namespace std;

int dp[100010];

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n,w,a,b,i;
	cin>>n>>w;
	while(n--)
	{
		cin>>a>>b;
		for(i=w;i>=a;i--)
		{
			dp[i]=max(dp[i], dp[i-a]+b);
		}
	}
	cout<<dp[w]<<'\n';
	
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll a, b, n, c;
  scanf("%lld%lld%lld", &n, &a, &b);
  printf("%lld", (c = (n - 2) * b - (n - 2) * a + 1) > 0 && (n > 1 || a == b) ? c : 0);
  return 0;
}

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

int main() 
{
    int n, k;
    cin >> n >> k;
    vector<ll> v(n);
    for(int i=0; i<n; i++)
        cin >> v[i];
    if (k>=n)
        return cout << 0, 0;
    sort(v.begin(), v.end());
    ll sum = 0;
    for (int i=0; i<n-k; i++)
        sum += v[i];
    cout << sum;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll t,i,j,c=1,z=7,k;
	bool flag=false;
	cin>>k;
	map<int,int> mp;
	
	while(1)
	{
		z=z%k;
		if(mp.find(z)!=mp.end())
		break;
		mp[z]++;
		if(z==0)
		{
			flag=true;
			break;
		}
		c++;
		z=z*10+7;
	}
	if(z==0)
	{
		cout<<c;
	}
	else
	{
		cout<<"-1";
	}
}


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

int main() {
    int A;
    cin >> A;
    char op;
    cin >> op;
    int B;
    cin >> B;

    if (op == '+') {
        cout << A + B << endl;
    }
    else if (op == '-') {
        cout << A - B << endl;
    }
    else {
    }

    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define Set(a,b) memset(a,b,sizeof(a))
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;
template <typename T> inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}
typedef long long ll;
typedef unsigned long long ull;
typedef __uint128_t uLL;
typedef double db;
typedef long double ldb;
template <typename T>inline void Inc(T&x,int y){x+=y;if(x>=mod) x-=mod;return;}
template <typename T>inline void Dec(T&x,int y){x-=y;if(x <  0) x+=mod;return;}
template <typename T>inline int fpow(int x,T k){int ret=1;for(;k;k>>=1,x=(ll)x*x%mod) if(k&1) ret=(ll)ret*x%mod;return ret;}
int n,k;
int a[3],b[3],du[5];
int main()
{
	for(int i=0;i<3;++i) init(a[i]),init(b[i]),++du[a[i]],++du[b[i]];
	int cnt=0;
	for(int i=1;i<=4;++i) if(du[i]&1) ++cnt;
	if(cnt==2) puts("YES");
	else puts("NO");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 3010
#define P 998244353
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,m,C[N<<1][N<<1],ans;
void inc(int &x,int y){x+=y;if (x>=P) x-=P;}
signed main()
{
	n=read(),m=read();
	C[0][0]=1;
	for (int i=1;i<=max(n,m);i++)
	{
		C[i][0]=1;
		for (int j=1;j<=i;j++)
		C[i][j]=(C[i-1][j-1]+C[i-1][j])%P;
	}
	for (int i=0;i<=n;i++)
	{
		int s=0;
		for (int j=0;j<=m-1-i;j++) inc(s,C[i][j]);
		for (int j=1;j<=i;j++) //j是第一个前缀和>m的位置 j~i均为2 1~i-j+1均为2 
		if (j*2>m&&(i-j+1<j?(i-j+1)*2+(j-(i-j+1)+1):j*2)<=m+1)
			if (i-j+1<j) inc(s,C[j-(i-j+1)-1][m+1-((i-j+1)*2+(j-(i-j+1)+1))]);
			else if (j*2==m+1) inc(s,1);
		inc(ans,1ll*s*C[n][n-i]%P);
	}
	cout<<ans;
	return 0;
	//NOTICE LONG LONG!!!!!
}
//先把0去掉 则要考虑求长度为0~n的满足条件的序列数量
//找到第一个前缀和>x的位置 然后若当前不是后缀 下一位必须是2 首位也必须是2 
//即第一个前缀和>x的位置及之后全都是2 

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

int main(int argc, char const *argv[])
{
    int D;
    cin >> D;
    int dif = 25-D;
    string ret("Christmas") ;
    for(int i=0;i<dif;++i)ret+=" Eve";
    cout <<ret<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin >> n >> k;
	int a[n],dp[n];
	for(int i = 0 ; i < n ; i++ ){
		cin >> a[i];
		dp[i]=INT_MAX;
	}
	dp[0]=0;
	for(int i = 1 ; i < n ; i++ ){
		for(int j=1 ; j<=k ; j++ ){
			if(i-j>=0)
			dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
			else{
				break;
			}
		}
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef double db; //
typedef string str; //
//
typedef pair<int,int> pi;
typedef pair<ll,ll> pl; //
typedef pair<db,db> pd; //
//
typedef vector<int> vi; 
typedef vector<ll> vl; //
typedef vector<db> vd; //
typedef vector<str> vs; //
typedef vector<pi> vpi;
typedef vector<pl> vpl; //
typedef vector<pd> vpd; //
 
typedef tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() //
#define rsz resize
#define ins insert //
#define ft front() //
#define bk back()
#define pf push_front //
#define pb push_back
#define eb emplace_back //
#define lb lower_bound //
#define ub upper_bound //
 
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
 
const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5; //
const ll INF = 1e18; //
const ld PI = acos((ld)-1);
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1}; //
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); //
//
template<class T> bool ckmin(T& a, const T& b) { 
	return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { //
	return a < b ? a = b, 1 : 0; } //
constexpr int pct(int x) { return __builtin_popcount(x); } //
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x)) //
constexpr int cdiv(int a, int b) { return a/b+!(a<0||a%b == 0); } // division of a by b rounded up, assumes b > 0 //
// IGNORE
int fstTrue(function<bool(int)> f, int lo, int hi) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true 
		int mid = (lo+hi)/2; 
		f(mid) ? hi = mid : lo = mid+1; 
	} 
	return lo;
}
template<class T> void remDup(vector<T>& v) { 
	sort(all(v)); v.erase(unique(all(v)),end(v)); }
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// IGNORE
//
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n, d;
	cin >> n >> d;
	int cnt = 0;
	F0R(a, n){
		ll x, y;
		cin >> x >> y;
		if(d * d >= x * x + y * y)
			cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3664
n,x,y=map(int,input().split())
ans=[0]*n
for i in range(1,n+1):
    for j in range(i+1,n+1):
        dist=min(abs(i-j),abs(i-x)+1+abs(y-j))
        ans[dist]+=1
for i in range(1,n):
    print(ans[i])


Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

using vi=vector<int>;
using pii=pair<int, int>;
using ll=long long;
using ull=unsigned long long;

int main()
{
    int n, m; cin >> n >> m;
    vi a(n);
    vector<pii> ops(m);

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


    for (int i = 0; i < m; i++)
	cin >> ops[i].ss >>  ops[i].ff;

    sort(a.begin(), a.end());
    sort(ops.rbegin(), ops.rend());

    int last_pos = 0;

    for (auto op : ops)
    {
	int nops = op.ss, x = op.ff;

	int pos = lower_bound(a.begin() + last_pos, a.end(), x) - a.begin();

    
	while (nops-- and last_pos < pos)
	    a[last_pos++] = x;
    }

    ll ans = accumulate(a.begin(), a.end(), 0LL);

    cout << ans << "\n";

}


Measured memory_bytes: 1408
n = int(input())
dat = list(map(int, input().split()))
total = 3 ** n
countzero = 0
countodd = []

for i in range(n):
    if dat[i] % 2 == 0:
        countodd.append(2)
    else:
        countodd.append(1)
xxx = 1
for i in range(n):
    xxx *= countodd[i]

total -= xxx
print(total)

Measured memory_bytes: 3060
#include<iostream>

using namespace std;
int main(){
        int W,H,r,x,y;
        cin>>W>>H>>x>>y>>r;
        if(0<=(x-r)&&(x+r)<=W&&0<=(y-r)&&(y+r)<=H){
                cout<<"Yes"<<endl;
        }else{
                cout<<"No"<<endl;
        }
}

Measured memory_bytes: 1156
# coding: utf-8

# AtCoder Grand Contest 017
# A - Biscuits

import sys, re

def solve(N, P, A):
  m = len([a for a in A if a % 2 != 0])  # the num of odd numbers in A
  if m > 0:
    return 2 ** (N-1)
  else:
    return 2 ** N if P == 0 else 0

def splitIntoNums(line):
  words = re.split(r'\s+', line.strip())
  return [int(w) for w in words]  # convert to int

while True:
  l1 = sys.stdin.readline()
  l2 = sys.stdin.readline()
  if not l1: break
  N, P = splitIntoNums(l1)
  A    = splitIntoNums(l2)
  if len(A) != N: raise
  print(solve(N, P, A))


# 以降, コメント:
#
# 奇数枚のビスケットが入っている袋数を m とする
# (偶数枚のビスケットが入っている袋数は N-m).
#
# 補題:
# m > 0 とする. m個の物のうち偶数個を選ぶ選び方は 2 ** (m-1) 通り,
# 奇数個を選ぶ選び方も 2 ** (m-1) 通りである.
# (mに関する数学的帰納法で示せる.)
#
# m > 0 の場合:
#   P == 0 のとき:
#     奇数枚のビスケットが入っている袋を偶数個選ぶ必要がある.
#     偶数枚のビスケットが入っている袋は何個選んでもよい.
#     m個の袋から偶数個選ぶ選び方は 2 ** (m-1) 通り.
#     N-m個の袋から任意の個数選ぶ選び方は 2 ** (N-m) 通り.
#     従って, 選び方は全部で 2 ** (N-1) 通り.
#   P == 1 のときも同様に, 選び方は全部で 2 ** (N-1) 通り.
# m == 0 の場合:
#   どのように選んでもビスケットは偶数枚になる. 従って,
#    P == 0 ならば 2 ** N 通り, P == 1 ならば 0 通り.


Measured memory_bytes: 2568
n, k = map(int, input().split())

ans = 0
# サイコロの目は1,2,...,N（等確立）
for i in range(1, n + 1):

    cnt = 0
    temp = i
    # cnt = 何回2倍したらk超えるか
    while temp < k:
        temp *= 2
        cnt += 1
    # サイコロでその目が出る確率は1/n
    # そこから表を出し続けてk越える確率は(1/2)**cnt
    ans += (1 / n) * ((1 / 2)**cnt)
print(ans)


Measured memory_bytes: 65636
#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 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
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
  
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 =5*100001;
ll power(ll x, ll n) {
  ll res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
  }
  return res;
}

const ll MAX = 100000; 

int main()
{
    
  IOS
  ll n;
  cin>>n;
  string s;
  cin>>s;
  ll ans=0;
  for(ll i=1;i<n;i++)
  {
    if(s[i]!=s[i-1])
    ans++;
  }
  cout<<ans+1;
}
    
  

  
  
	




Measured memory_bytes: 512
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();

		HashSet<String> set = new HashSet<>();

		for(int i=0; i<N; i++) {
			set.add(sc.next());
		}

		System.out.println(set.size());
		sc.close();
	}
}


Measured memory_bytes: 66252
D=int(input())
c=list(map(int,(input().split())))
s=[]
t=[]
last=[0]*26
sat=0

for i in range(D):
  s.append(list(map(int,(input().split()))))
  for day in range(26):
    if(last[day]!=0):
      last[day]+=1

  for j in range(26):
    for k in range(26):
      s[i][j]-=c[k]*(1+last[k])
    s[i][j]+=c[j]*(1+last[j])

  sat+=max(s[i])
  last[s[i].index(max(s[i]))]=1
  ans=s[i].index(max(s[i]))+1
  print(ans)

Measured memory_bytes: 9188
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n,t;
        int nowt=0;
        ArrayList<P> list = new ArrayList<P>();
        n = sc.nextInt();
        t = sc.nextInt();
        sc.nextLine();
        for(int i=0;i<n;i++){
            String str[] = sc.nextLine().split(" ");
            list.add(new P(str[0],Integer.parseInt(str[1])));
        }
        while(list.size()!=0){
            P p = list.get(0);
            list.remove(0);
            if(p.t<=t){
                nowt+=p.t;
                System.out.println(p.name+" "+nowt);
            }else{
                p.t-=t;
                nowt+=t;
                list.add(p);
            }
        }
    }
}

class P{
    String name;
    int t;
    public P(String s,int tt){
        name = s;
        t = tt;
    }
}


Measured memory_bytes: 104548
import java.util.Scanner;
import java.util.Arrays;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int A = scan.nextInt();
    int B = scan.nextInt();
    int C = scan.nextInt();
    if (A == B && A != C) {
      System.out.println("Yes");
    }
    else if (A == C && A != B) {
      System.out.println("Yes");
    }
    else if (B == C && B != A) {
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 22996
x=input().split()

a=int(x[0])
b=int(x[1])
c=int(x[2])
d=int(x[3])

if abs(c-a)<=d:
    print("Yes")
elif (abs(b-a)<=d)and(abs(c-b)<=d):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC opatimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }

int const maxn = 100005;
vector<int> gr[maxn];
int dist1[maxn];
int dist2[maxn];

void dfs1(int* dist, int v, int p = 0) {
    dist[v] = dist[p] + 1;
    for (int ne : gr[v])
        if (ne != p)
            dfs1(dist, ne, v);
}

int ans = 0;

void dfs2(int v, int p = 0) {
    ans = max(ans, dist2[v]);
    for (int ne : gr[v])
        if (ne != p && dist1[ne] < dist2[ne])
            dfs2(ne, v);
}

int main() {
//    freopen("in.txt","r", stdin);
//    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n,v,u;
    cin >> n >> v >> u;

    for (int i = 1; i < n; ++i) {
        int x,y;
        cin >> x >> y;
        gr[x].push_back(y);
        gr[y].push_back(x);
    }

    dfs1(dist1, v);
    dfs1(dist2, u);

    dfs2(v);

    cout << ans - 2 << endl;
}


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int N=read();
	int a[N];
	int sum=0;
	REP(i,N){
		a[i]=read();
		sum+=a[i];
	}
	int sum2=0;
	int ans=100000000000;
	REP(i,N-1){
		sum2+=a[i];
		int dif=abs((sum-sum2)-sum2);
		if(dif<ans){
			ans=dif;
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 1920
#include <stdio.h>
#include <string.h>
#define M 999999/* your task*/
#define L 14
#define true 1
#define false -1
#define exist 1
    // Your code here!




char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M/* your task */; }
int h2(int key){ return 1+key%(M-1)/* your task */; }

int find(char str[]){

    /* your task */
 long long key;
 int i=0, hash;
  key = getKey(str);
  
  while(1){
    hash=(h1(key) + i*h2(key)) % M;
    i++;
    
    if(strcmp(H[hash],str) == 0){
      return true;
    }
    else if( strlen(H[hash]) == 0){
      return false;
    }
  }
  

}

int insert(char str[]){

    /* your task */
 long long key;
 int i=0 ,hash;
  key = getKey(str);
  while(1){
    hash = (h1(key) + i*h2(key)) % M;
    i++;
    if(strcmp(H[hash],str)==0) {
      return exist;
    }
    else if(strlen(H[hash])==0) {
      strcpy(H[hash],str);
      return 0;
    }
  }
  
}


int main(){
    int i, n;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	}
	else {
	    if (find(str)==true){
		printf("yes\n");
	    } 
	    
	    else {
		printf("no\n");
	    }
	}
    }

    return 0;

}


Measured memory_bytes: 15404
#include <stdio.h>
int main(void)
{
	int n, p[51], a, b = 0;
	
	scanf("%d", &n);
	for(a = 1; a <= n; a++){
		scanf("%d", &p[a]);
	}
	
	for(a = 1; a <= n; a++){
		if(p[a] != a){
			b++;
		}
	}
	
	if(b == 0 || b == 2){
		printf("YES");
	}else{
		printf("NO");
	}
	
	return 0;
}

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

bool comp(string x,string y){
    if(x.size() > y.size()) return true;
    else if (x.size() < y.size()) return false;
    else return x > y;
}

string dp[10010];
signed main(){
    int n,m;
    cin >> n >> m;
    int a[9];
    int b[10]={0,2,5,5,4,5,6,3,7,6};
    REP(i,m) {
       cin>>a[i];
       a[i];
    }
    //sort(a.begin(),a.end());
    for (int i = 0; i <= n; i++)
    {
        dp[i]="0";
    }
    dp[0]="";
    
  
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if(i-b[a[j]] < 0) continue;
            if(dp[i - b[a[j]]]!="0"){
                if (comp(dp[i-b[a[j]]]+to_string(a[j]),dp[i])) {
                    dp[i]=dp[i-b[a[j]]]+to_string(a[j]);
                }
            }
           
        }
    }
    cout<<dp[n]<<endl;
    


    return 0;
}

Measured memory_bytes: 31872
/*************************************************************************
    > File Name: B.cpp
    > Author: Roundgod
    > Mail: wcysai@foxmail.com 
    > Created Time: 2018-05-23 14:29:52
 ************************************************************************/

#include<bits/stdc++.h>
#define MAXN 200005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,k,a[MAXN],x;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        a[x]=i;
    }
    int ans=0,cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(i==1||a[i]>=a[i-1]) cnt++;
        else
        {
            ans=max(ans,cnt);
            cnt=1;
        }
    }
    ans=max(ans,cnt);
    printf("%d\n",n-ans);
    return 0;
}

Measured memory_bytes: 1024
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;

int main(){
    fastio
    int n ; 
    cin >> n ; 
    vector<int> v(n) ; 
    for(int i=0;i<n;i++){
    	cin >> v[i] ; 
    }
    int ans = 0 ; 
    for(int i=1;i<n-1;i++){
    	vector<int> t ; 
    	t.push_back(v[i-1]) ; 
    	t.push_back(v[i]) ; 
    	t.push_back(v[i+1]) ; 
    	sort(t.begin(),t.end()) ; 
    	if ( v[i] == t[1] ) ans++ ; 
    }
    cout << ans << endl;
    return 0 ;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
x = list(map(int,input().split()))

x.sort()
dis = [0] * (m - 1)

for i in range(m - 1):
  dis[i] = x[i + 1] - x[i]

dis.sort()

#入力が、コマ数＞地点の場合がありうるため、合計算出にmaxを使用する
ans = sum(dis[:max(m-n, 0)])
print(ans)

Measured memory_bytes: 13960
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef vector<ll> vll;

int main() {
	ll n,ans=0;cin >> n;
	vll v(2*n);
	rep(i, 2*n)cin >> v[i];
	sort(all(v));
	rep(i,2*n){
        ans += v[i];
		i++;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
use proconio::input;

const M: u64 = 1000_000_007;

fn calc(n: usize, k: usize, a: &Vec<usize>) -> u64 {
    let mut dp = vec![vec![0; k + 1]; n];
    for j in 0..=a[0] {
        dp[0][j] = 1;
    }
    for j in (a[0] + 1)..=k {
        dp[0][j] = 0;
    }
    for i in 1..n {
        let mut cum = vec![0; k + 2];
        for j in 1..=(k + 1) {
            cum[j] = (cum[j - 1] + dp[i - 1][j - 1]) % M;
        }
        for j in 0..=k {
            dp[i][j] = (cum[j + 1] + M - cum[if a[i] > j { 0 } else {j - a[i]}]) % M;
        }
    }
    dp[n - 1][k]
}

fn main() {
    input! {
        n: usize,
        k: usize,
        a: [usize; n],
    }

    println!("{}", calc(n, k, &a));
}


Measured memory_bytes: 80980
a, b = map(int,input().split())
s = str(input())

def solve(a,b,s):
    # print(s[a])
    if s[a] != '-':
        return 'No'

    cstring = s[:a] + s[a+1:a+b+1]
    # print(cstring)
    for p in range(len(cstring)):
        if cstring[p].isdigit() != True:
            return 'No'
    return 'Yes'

print(solve(a,b,s))

Measured memory_bytes: 3060
#include<stdio.h>

int main(){

  int H,W,t,y;
  while(1){
    scanf("%d%d",&H,&W);
    if(H==0 && W==0)break;
    for(t=0;t<H;t++){
      for(y=0;y<W;y++){
	if((t+y)%2==1){
	  printf(".");
        } else {
       printf("#");
	}
      }
	printf("\n");
      }
    printf("\n");
  }
    return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 998244353
// #define int long long
#define ll long long
#define EPS 0.00000000000001
#define ld long double
#define inf 1e9
#define N 500001
#define K 20



int small_func(int n)
{
    int cnt = 0;
    while(n > 0)
    {
        int x = __builtin_popcount(n);
        n = n % x;
        cnt++;
    }
    return cnt;
}


int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int n;
    cin >> n;
    vector<int> v(n);
    int cnt = 0;
    for(int i = 0;i < n;i++)
    {
        char c;
        cin >> c; 
        v[i] = (c == '1');
        cnt += v[i];
    }
    if(cnt == 0)
    {
        for(int i = 0;i < n;i++)
            cout << 1 << endl;
        exit(0);
    }
    vector<vector<int>> g(3,vector<int>(n,0));
    vector<vector<int>> pw(3,vector<int>(n,1));
    for(int j = 0;j < 3;j++)
    {
        int y = cnt + (j - 1);
        for(int i = n - 2;i >= 0;i--)
        {
            
            if(y)
                pw[j][i] = (pw[j][i + 1] * 2)%y;
            // cerr << i << " " << y << "  " << pw[j][i] << endl;
        }
    }
    
    // reverse(v.begin(),v.end());
    vector<int> r(3,0);
    for(int j = 0;j < 3;j++)
    {
        int y = cnt + (j - 1);
        
        for(int i = 0;i < n;i++)
        {
            if(y)
            {
                g[j][i] = (v[i] * pw[j][i]) % y;
                r[j] = (r[j] + g[j][i]) % y;
                // cerr << j << " " << r[j] << endl;
            }
        }
    }
    for(int i = 0;i < n;i++)
    {
        int ans;
        // cerr << i << endl;
        if(v[i] == 1)
        {
            int y = cnt - 1;
            if(y == 0)
            {
                ans = 0;
                
            }
            else
            {
                int rem = ((r[0] - g[0][i]) % y + y) % y;
                ans = 1 + small_func(rem);
            }
            
        }
        else
        {
            int y = cnt + 1;
            // cerr << y << endl;
            if(y == 1)
            {
                ans = 1;
            }
            else
            {
                int rem = (r[2] + pw[2][i])%y;
                // cerr << rem << " " << y << endl;
                ans = 1 + small_func(rem);
            }
        }
        cout << ans << endl;
    }
    
    
    

    return 0;  
}
      



Measured memory_bytes: 9360
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    H, W, K = MI()
    G = [[0] * W for _ in range(H)]
    for i in range(H):
        line = LS()
        for j, l in enumerate(line):
            if l == '#':
                G[i][j] += 1
    # print(G)
    G = np.array(G)

    ans = 0
    for i in product([0, 1], repeat=W):
        R = G * i
        for j in product([0, 1], repeat=H):
            A = R.T * j
            # print(A, A.sum())
            if A.sum() == K:
                ans += 1
    print(ans)



if __name__ == '__main__':
    solve()


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

int n, ans;
string s, t;
queue <int> Qu;
int main()
{
	scanf("%d", &n);
	cin >> s >> t;
	if (s == t)
	{
		puts("0");
		return 0;
	}
	int head = n - 1, tail = n - 1;
	while (tail >= 0)
	{
		while (tail && t[tail] == t[tail - 1]) tail--;
		while (head >= 0 && (head > tail || s[head] != t[tail])) head--;
		if (head < 0)
		{
			puts("-1");
			return 0;
		}
		while (!Qu.empty() && Qu.front() - Qu.size() >= tail) Qu.pop();
		if (head != tail) Qu.push(head);
		ans = max(ans, (int)Qu.size() + 1);
		tail--;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 6280
#include<iostream>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;

const int INF = 1e9;

int main() {
    int N, K;
    cin >> N >> K;
    int h[100010];
    for (int i = 0; i < N; i++) cin >> h[i];
    int dp[110000];
    for (int i = 0; i < N; i++) dp[i] = INF;
    dp[0] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
        }
    }
    cout << dp[N-1] << endl;
}


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

int main() {
  string S,T;
  cin >> S >> T;
  bool flag = true;
  for(int i = 0; i < S.size(); i++){
    if(S.at(i) != T.at(i)) flag = false;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl; 
}


Measured memory_bytes: 3572
N,M,C = map(int, input().split(" "))
b_list = input().split(" ")
B=[int(b_list[i]) for i in range(M)]
output=0
for i in range(N):
    a_list = input().split(" ")
    A=[int(a_list[ii]) for ii in range(M)]
    total=0
    for iii in range(M):
        tmp = A[iii]*B[iii]
        total+=tmp
    if (total+C)>0:
        output+=1
print(output)


Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int f[200005],n,s;

int main () {
	
	scanf ("%d",&n);
	for (int i=1;i<=n;i++) {
		scanf ("%d",&f[i]);
		s^=f[i];
	}
	for (int i=1;i<n;i++) {
		printf ("%d ",f[i]^s);
	}
	printf ("%d\n",f[n]^s);

	return 0;
}



Measured memory_bytes: 3212
IDENTIFICATION DIVISION.
PROGRAM-ID. 146B.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 INP   PIC X(10000).
*>
WORKING-STORAGE SECTION.
01 S       PIC X(10000).
01 S-LEN   PIC 9(5).
01 N       PIC 9(5).
01 A-TBL.
   03 F1   PIC X(26) VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
   03 F2   PIC X(26) VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
01 A-TBL-R REDEFINES A-TBL.
   03 A-CH PIC X(1) OCCURS 52.
01 C-TBL.
   03 C-CD PIC S9(4) COMP OCCURS 256.
01 C-WK.
   03 C1   PIC X(1) VALUE LOW-VALUE.
   03 C2   PIC X(1).
01 C-WK-R  REDEFINES C-Wk.
   03 ACD  PIC S9(4) COMP. 
01 I     PIC 9(5).
01 OUT   PIC ZZZZ9.
*>
PROCEDURE DIVISION.
  ACCEPT N.
  OPEN INPUT STDIO.
  READ STDIO.
  CLOSE STDIO.
  UNSTRING INP DELIMITED BY ' '
     INTO S COUNT S-LEN.
*>
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > 26
    MOVE A-CH(I) TO C2
    MOVE I     TO C-CD(ACD)  
  END-PERFORM.
*>
  IF (N > 0)
    PERFORM VARYING I FROM 1 BY 1 UNTIL I > S-LEN
      MOVE S(I:1)              TO C2    
      MOVE A-CH(C-CD(ACD) + N) TO S(I:1) 
    END-PERFORM
  END-IF.
*>
  DISPLAY S(1:S-LEN).
  STOP RUN.


Measured memory_bytes: 384
#include<string>
#include<string.h>
#include<iostream>
using namespace std;
int main(void) {
   string a, b, c;
   int n, m;
   cin >> a >> b >> n >> m>> c;
   if(strcmp(a.c_str(), c.c_str())==0) n--;
   else m--;
   cout << n << ' ' << m << endl;
}

Measured memory_bytes: 256
#include<cstdio>
int p[10][10];
void drop(int x,int y){
    if(0<=x && x<10 && 0<=y && y<10) p[x][y]++;
}
int main(){
    int x,y,s;
    int a=0,b=0;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            p[i][j]=0;
        }
    }
    while(~scanf("%d,%d,%d",&x,&y,&s)){
        if(s==1){
            drop(x,y);
            drop(x+1,y);
            drop(x-1,y);
            drop(x,y+1);
            drop(x,y-1);
        }else if(s==2){
            drop(x,y);
            drop(x+1,y);
            drop(x-1,y);
            drop(x,y+1);
            drop(x,y-1);
            drop(x+1,y+1);
            drop(x+1,y-1);
            drop(x-1,y+1);
            drop(x-1,y-1);
        }else if(s==3){
            drop(x,y);
            drop(x+1,y);
            drop(x-1,y);
            drop(x,y+1);
            drop(x,y-1);
            drop(x+1,y+1);
            drop(x+1,y-1);
            drop(x-1,y+1);
            drop(x-1,y-1);
            drop(x+2,y);
            drop(x-2,y);
            drop(x,y+2);
            drop(x,y-2);
        }
    }
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            if(p[i][j]==0) a++;
            else if(b<p[i][j]) b=p[i][j];
        }
    }
    printf("%d\n%d\n",a,b);
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int a, b, c;
    cin >> a >> b >> c;
    cout << ((a + b + c >= 22) ? "bust" : "win");
    
    return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  // cout << n << " " << m;
  vector<vector<int>> ln(n, vector<int>(0));
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    ln.at(a).push_back(b);
    ln.at(b).push_back(a);
  }
  rep(i, n) {
    sort(ln.at(i).begin(), ln.at(i).end());
    // cout << "[" << i << "]";
    // rep(j, ln.at(i).size()) cout << " " << ln.at(i).at(j);
    // cout << endl;
  }
  vector<int> g(n, -1);
  int ans = -1;
  rep(i, n) {
    if (g.at(i) != -1) continue;
    ans++;
    g.at(i) = ans;
    vector<int> q(0);
    rep(j, ln.at(i).size()) q.push_back(ln.at(i).at(j));
    while (q.size() > 0) {
      int x = q.at(q.size()-1);
      q.pop_back();
      if (g.at(x) != -1) continue;
      g.at(x) = ans;
      rep(j, ln.at(x).size()) q.push_back(ln.at(x).at(j));
    }
  }
  cout << ans << endl;
}


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

sa = [0] * (n+1)
sb = [0] * (m+1)
r = m
ans = 0

for i in range(n):
    sa[i+1] = sa[i] + a[i]
for i in range(m):
    sb[i+1] = sb[i] + b[i]

for i in range(n+1):
    if sa[i] > k:
        break
    while sa[i] + sb[r] > k:
        r -= 1
    ans = max(ans, i+r)
print(ans)

Measured memory_bytes: 47456
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

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

int main(){

    int k, s, cnt;
    cin >> k >> s;

    for(int n=0; n<k+1; n++){
        for(int m=0; m<k+1; m++){
            int z = s - n - m;
            if(0 <= z && z <= k) cnt++; //0よりもzが大きい(zが制約を満たすところにあるか?)
        }
    }


    cout << cnt << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>

using namespace std;

typedef long long ll;

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

  int j = 0;
  for (int i = 0; i < n; ++i) {
    if (j < i) j = i;
    while (j + 1 < n && a[j + 1] > a[j]) j++;
    if (j - i + 1 >= k) {
      b[i] = 1;
      result |= b[i];
    }
    //cerr << b[i];
  }
  //cerr << endl;

  for (int i = 0; i + k <= n; ++i) {
    if (b[i] != 1) {
      result++;
    }
  }

  set<int> s;
  for (int i = 0; i < k + 1; ++i) {
    s.insert(a[i]);
  }

  for (int i = 0; i + k < n; ++i) {
    int ok = 1;
    if (*s.begin() != a[i]) ok = 0;
    if (*s.rbegin() != a[i + k]) ok = 0;
    //cerr << ok;
    if (ok && !b[i]) result--;
    if (i + k + 1 == n) {
      break;
    }
    s.erase(s.find(a[i]));
    s.insert(a[i + k + 1]);
  }
  //cerr << endl;

  cout << result << endl;

  return 0;
}


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

int main() {
  int N,a,b;
  cin >> N;
  a = N;
  for(int i=0;i<8;i++){
    b += a%10;
    a /= 10;
  }
  if(N%b==0){
    cout << "Yes";
  }
  else{
    cout << "No";
  }

}


Measured memory_bytes: 256
#!/usr/bin/env python3

N = int(input())
H = list(map(int, input().split()))
D = [0, abs(H[1] - H[0])]
for i in range(2, N):
    D.append(min(abs(H[i] - H[i - 1]) + D[i - 1], abs(H[i] - H[i - 2]) + D[i - 2]))
print(D[-1])

Measured memory_bytes: 13928
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>
#include<cmath>
#include<assert.h>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<complex>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

const double EPS = 1e-8;

struct Point : public complex<double> {
    int idx;

    Point(double x, double y, int idx) : complex<double>(x, y), idx(idx) {}

    Point(complex<double> xy, int idx = 0) : complex<double>(xy), idx(idx) {}

    Point() {}
};
namespace std {
    bool operator<(const Point &a, const Point &b) {
        if (real(a) != real(b))return real(a) < real(b);
        if (imag(a) != imag(b))return imag(a) < imag(b);
        return a.idx < b.idx;
    }
}

double cross(const Point &a, const Point &b) {
    return imag(conj(a) * b);
}

double dot(const Point &a, const Point &b) {
    return real(conj(a) * b);
}

struct Line : public vector<Point> {
    Line(const Point &a, const Point &b) {
        push_back(a);
        push_back(b);
    }
};

typedef vector<Point> Polygon;

struct Circle {
    Point p;
    double r;

    Circle(const Point &p, double r) : p(p), r(r) {}
};

int ccw(Point a, Point b, Point c) {
    b -= a;
    c -= a;
    if (cross(b, c) > 0)return 1;//counter clockwise
    if (cross(b, c) < 0)return -1;//clockwise
    if (dot(b, c) < 0)return 2;//c--a--b on line
    if (norm(b) < norm(c))return -2;//a--b--c on line
    return 0;
}

vector<Point> convex_hull(vector<Point> ps) {
    int n = ps.size(), k = 0;
    sort(ps.begin(), ps.end());
    vector<Point> ch(2 * n);
    for (int i = 0; i < n; ch[k++] = ps[i++])//lower-hull
        while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0)--k;
    for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])//upper-hull
        while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0)--k;
    ch.resize(k - 1);
    return ch;
}

int N;
vector<Point> ps;
double Ans[110];

signed main() {
    cin >> N;
    rep(i, N) {
        int x, y;
        cin >> x >> y;
        ps.push_back(Point(x, y, i));
    }
    vector<Point> ch = convex_hull(ps);
    ch.push_back(ch[0]);
    ch.push_back(ch[1]);
    rep(i, ch.size() - 2) {
        Point v = ch[i + 1];
        double arg = 3.14159265 - acos(dot((ch[i + 2] - v) / abs(ch[i + 2] - v), (ch[i] - v) / abs(ch[i] - v)));
        Ans[v.idx] = arg / (2 * 3.14159265);
    }
    rep(i, N) {
        printf("%.16lf\n", Ans[i]);
    }
    return 0;
}


Measured memory_bytes: 256
///who is the king ??? *** << t.mohammad >> *** ///
/*
                  00                                                                                                            00
                 00                               00                                                                           00
            0000000000                           00                                                                           00
           0000000000   000       000           00                        000       000  000       000                       00
              00       0000     0000           00         000000         0000     0000  0000     0000   000000              00
             00       00 00   00 00    000    00        00000000        00 00   00 00  00 00   00 00  00000000       00000000
            00       00  00 00  00   00000   000000    00    000       00  00 00  00  00  00 00  00  00    000     0000000000
           00       00   000   00  00   00  00000000  00    0000      00   000   00  00   000   00  00    0000    00     0000
          00       00         00  00   00  00    00  00    00 00     00         00  00         00  00    00 00   00     00 00
         00  00   00         00   00000   00    00  00000000  00    00         00  00         00  00000000  00  000000000  00
        00  00   00         00    000    00    00   000000    00   00         00  00         00   000000    00  0000000    00
*/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std ;
#define int long long int
typedef long double ld ;
#define ff first
#define ss second
#define setp(t) cout << setprecision(t) << fixed ;
const int N = 1e5 + 100 ;
int dp[110][N] ;
vector <int> w2 , c ;
int32_t main() {
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
	int n , w ;
	cin >> n >> w ;
	for(int i = 0 ; i < n ; i++) {
		int a , b ;
    	cin >> a >> b ;
    	w2.push_back(a) ;
    	c.push_back(b) ;
	}
	for(int i = 0 ;i <= n ; i++) {
		for(int j = 0 ; j <= w ; j++) {
        	if(i == 0 || j == 0)
        		dp[i][j] = 0 ;
        	else if(j >= w2[i - 1])
        		dp[i][j] = max(c[i - 1] + dp[i - 1][j - w2[i - 1]] ,dp[i - 1][j]) ;
        	else
        		dp[i][j] = dp[i - 1][j] ;
    	}
	}
	cout << dp[n][w] ;
}


Measured memory_bytes: 80128
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

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

  if(n <= 2){
    cout << 1 << endl;
    return 0;
  }

  bool all = true;
  for(int i = 0; i + 1 < n; i++){
    if(a[i] != a[i + 1]){
      all = false;
      break;
    }
  }
  if(all){
    cout << 1 << endl;
    return 0;
  }


  int s = 0;
  int count = 0;
  while(s < n){
    int t = s;
    int f = 0;
    while(t + 1 < n){
      if(a[t] == a[t + 1]) ++t;
      else if(a[t] < a[t + 1]){
        if(f == 0 || f == 1){
          f = 1;
          ++t;
        }
        else break;
      }
      else if(a[t] > a[t + 1]){
        if(f == 0 || f == 2){
          f = 2;
          ++t;
        }
        else break;
      }
      else break;
    }
    ++count;
    s = t + 1;
  }

  cout << count << endl;

  return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  int count =0;
  for(int i=0;i<n;i++){
    cin >> p.at(i);
    if(p.at(i)-1 != i){
      count ++;
  }}
  
  if(count==0||count==2){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

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

typedef unsigned long long ull;

#define REP(i, N) for (int i = 0; i < N; i++)
#define ANS(a) cout << a << endl;
#define SORT(V) sort(V.begin(), V.end())
#define RSORT(V) sort(V.rbegin(), V.rend())

#define DBG(V) for (auto v : V) cout << v << " "; cout << endl

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

  if (K == 1) { ANS(0); return 0; }
  ANS(N-K);
  return 0;
}


Measured memory_bytes: 256