akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        float possibility = (float)((N / 2) + 1) / N;

        if (N%2 == 1) {
            System.out.println(possibility);
        } else {
            System.out.println(0.5000000000);
        }
    }
}

Measured memory_bytes: 22740
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <climits>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

void solve(void){
    int n, k, t;
    ll sum = 0LL;
    cin >> t;
    rep(t, meaningless) {
        sum = 0LL;
        cin >> n >> k;
        vector <int> difs(n);
        int pre, tmp; cin >> pre;
        rep(n-1, i) {
            cin >> tmp;
            difs.pb(tmp-pre);
            sum += tmp-pre;
            pre = tmp;
        }
        sort(all(difs));
        reverse(all(difs));
        rep(k-1, i) sum -= difs[i];
        cout << max(sum, 0LL) << '\n';
    }
}

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



Measured memory_bytes: 4252
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;

using LL = long long;

int main(void)
{
	cout.precision(15);
	cout << fixed;
	for (;;)
	{
		int n, m, k;
		cin >> n >> m >> k;
		if (!n)break;
		//dp(i,j):=i??????m??¢???????????§j?????????????????°
		//dp[i][j] = dp[i-1][j-k](k=1~m)
		map<pair<int, int>, LL>dp;
		if (n == 1)
		{
			for (int kk = 1; kk <= m; ++kk)
			{
				dp[{1, kk}] = 1;
			}
		}
		else
		{
			dp[{0, 0}] = 1;
			for (int i = 1; i <= n; ++i)
			{
				for (int j = 0; j <= i * m; ++j)
				{
					for (int kk = 1; kk <= m; ++kk)
						dp[{i, j}] += dp[{i - 1, j - kk}];
				}
			}
		}
		LL ans = 0;
		LL div = 0;
		for (int j = 0; j <= n * m; ++j)
		{
			int score = max(1, j - k);
			ans += dp[{n, j}] * score;
			div += dp[{n, j}];
		}
		cout << (double)ans / div << endl;
	}
	return 0;
}

Measured memory_bytes: 3860
#include <bits/stdc++.h>
#define int long long
#define pb       push_back
#define io    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(a)      (a).begin(),(a).end()
#define endl        '\n'
#define F    first
#define S second
#define mod 1000000007 
#define N 200005
#define pii pair<int,int>
using namespace std;
int n;
vector<int> dp(N,INT_MAX);
int ans=0;
vector<int> v(N);
int a;
int fun(int x)
{
    
    if(x<0)
        return INT_MAX;
    if(dp[x] != INT_MAX)
        return dp[x];
        
    if(x-1>=0)
        dp[x]=min(dp[x],fun(x-1)+abs(v[x]-v[x-1]));
    if(x-2>=0)
        dp[x]=min(dp[x],fun(x-2)+abs(v[x]-v[x-2]));
    return dp[x];
}
void solve()
{
    for(int i=0;i<n;i++)dp[i]=INT_MAX;
    cin>>n;
    dp[0]=0;
    
    for(int i=0;i<n;i++)cin>>v[i];
    cout<<fun(n-1);
}

signed main(){
    io;
    int t=1;
    //cin>>t;
    while(t--){
      solve();
    }
    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;



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

   int count=0;
   for(int i=1; i<=n; i++){
       if(i/10 == 0) count ++;
       else if(i/100 == 0) continue;
       else if(i/1000 == 0) count++;
       else if(i/10000 == 0) continue;
       else if(i/100000 == 0)count++;
       else continue;
   }
   cout << count << endl;

}

Measured memory_bytes: 3608
//HOW YOU DOI'N........................JT
//Could this code be more bad..........CB
//I know...............................MG
//Hii..................................RG
//Noooooooo............................RG
//I wish I could but I don't want to...PB

//That's what she said.................MS


#include <bits/stdc++.h>

#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);

#define ll long long
#define ld long double
#define pb push_back
#define mkpr make_pair
#define fi(i,a,b) for (ll i=a;i<b;i++)
#define vll vector<ll>
#define vch vector<char>
#define vst vector<string>
#define vpll vector<pll>
#define vvl vector<vector<ll>>
#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(), v.rend())
#define mxe(v) *max_element(v.begin(),v.end())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define mll map<ll, ll>
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)
#define nl "\n"
#define sp " "
#define sz(x)  (int)x.size()

using namespace std;

double PI = (acos(-1));
ll md = 1000000007;
//ll md = 998244353;

ll pw(ll a, ll b){ll c=1,m=a;while (b){if (b&1)c=(c*m);m=(m*m);b/=2;}return c;}
ll pwmd(ll a, ll b){ll c = 1, m = a;while (b){if (b & 1)c = ((c * m)) % md;m = (m * m) % md;b /= 2;}return c;}
ll modinv(ll n){return pwmd(n, md - 2);}
ll min(ll a,ll b){if(a>=b)return b;return a;}
ll nc2(ll n){return (1ll * n * (n - 1)) / 2;}
ll nsum(ll n){return (1ll * n * (n + 1)) / 2;}
bool prime(ll a){for(int i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}

#define MAX_SIZE 1005
void Sieve(vector<int> &primes){bool IsPrime[MAX_SIZE];memset(IsPrime, true, sizeof(IsPrime));
for (int p = 2; p * p < MAX_SIZE; p++){if (IsPrime[p] == true){
			for (int i = p * p; i < MAX_SIZE; i += p)IsPrime[i] = false;}}
	for (int p = 2; p < MAX_SIZE; p++)if (IsPrime[p])primes.push_back(p);}


vector<char> sml={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char> cap={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};



// Lets start ...

void solve(){
    ll k,ans=0;
    cin>>k;
    fi(i,1,k+1){
        fi(j,1,k+1){
            ll q=gcd(i,j);
            fi(z,1,k+1)ans+=gcd(q,z);
        }
    }cout<<ans;
}



int main(){
    //vector<int> primes;
    //Sieve(primes);

    fast
    ll tests=1;
    //cin>>tests;
    while(tests--){
        solve();
    }

    return 0;
    }

// Done:)









Measured memory_bytes: 3612
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
	ll mx = 0;
	ll mn = 20000;
	ll n;
	cin>>n;
	vector<string> v;
	rep(i,0,n){
		string s;
		cin>>s;
		v.pb(s);
	}
	string s1;
	cin>>s1;

	vector<string> va;
	rep(i,0,v.sz){
		string s = v[i];
		rep(j,0,s.sz){
			if(s[j]=='?')s[j] = 'z';
		}
		va.pb(s);
	}
	string s2 = s1;
	rep(i,0,s2.sz){
		if(s2[i]=='?')s2[i] = 'a';
	}
	va.pb(s2);
	sort(all(va));
	rep(i,0,va.sz){
		if(va[i]==s2){
			mx = max(mx,i);
			mn = min(mn,i);
		}
	}

	vector<string> vb;
	rep(i,0,v.sz){
		string s = v[i];
		rep(j,0,s.sz){
			if(s[j]=='?')s[j] = 'a';
		}
		vb.pb(s);
	}
	string s3 = s1;
	rep(i,0,s3.sz){
		if(s3[i]=='?')s3[i] = 'z';
	}
	vb.pb(s3);
	sort(all(vb));
	rep(i,0,vb.sz){
		if(vb[i]==s3){
			mx = max(mx,i);
			mn = min(mn,i);
		}
	}
	
	vector<ll> ans;
	rep(i,mn,mx+1){
		ans.pb(i+1);
	}
	rep(i,0,ans.sz){
		cout << ans[i];
		if(i!=ans.sz-1)cout << " ";
	}
	cout << endl;
	
	return 0;
}




Measured memory_bytes: 2048
#include <bits/stdc++.h>
//#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<double,double> P;
const ll INF = 4*1e18;
const int MOD = 1000000007;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


int h,w;
int memo[110][110];
bool s[110][110];

int dfs(int r, int c){
  if(r >= h || c >= w)return INF;
  if(memo[r][c] != -1)return memo[r][c];
  if(r == h-1 && c == w-1)return memo[r][c] = (!s[r][c]);
  int x = dfs(r, c+1) + (!s[r][c] && s[r][c] != s[r][c+1]),
      y = dfs(r+1, c) + (!s[r][c] && s[r][c] != s[r+1][c]);
  return memo[r][c] = min(x, y);
}

signed main(){
  cin>>h>>w;
  rep(i,110)rep(j,110)memo[i][j] = -1;
  rep(i,h){
    rep(j,w){
      char cc;cin>>cc;
      s[i][j] = (cc == '.');
    }
  }
  cout << dfs(0,0) << endl;;

}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;

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

const int inf = 100100100;
int edge[30][30];

int main() {
  int N, M; scanf("%d%d", &N, &M);
  REP(i, N) REP(j, N) edge[i][j] = inf;
  REP(i, N) edge[i][i] = 0;
  
  REP(m, M) {
      int a, b, c, d;
      scanf("%d,%d,%d,%d", &a, &b, &c, &d);
      a--, b--;
      edge[a][b] = c;
      edge[b][a] = d;
  }
  REP(k, N) REP(i, N) REP(j, N)
      edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);

  int start, end, have, price;
  scanf("%d,%d,%d,%d", &start, &end, &have, &price);
  start--, end--;
  int ans = have - (edge[start][end] + edge[end][start] + price);
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
	int i,j,k,n;
	cin>>n;
	int m=0;
	int ans=0;
	k=n;
	while(k){
		m++;
		k/=10;
	}
	if(m%2==0){
		m--;
		if(m>=1)ans+=9;
		if(m>=3)ans+=900;
		if(m>=5)ans+=90000;
	}
	else{
		if(m==1)ans=n-1+1;
		else if(m==3)ans=9+n-100+1;
		else if(m==5)ans=9+900+n-10000+1;
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

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

    int cnt=0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            b[cnt++]=a[i]*a[j];
        }
    }

    sort(b.begin(), b.end(), greater<ll>());

    for(int i=0; i<n*n && b[i]!=0; i++){
        ll num=b[i];
        vector<int> c(20);
        int cnt2=0;
        while(num>0){
            c[cnt2++]=num%10;
            num/=10;
        }

        bool increasing=true;
        for(int j=0; j<cnt2-1; j++){
            if(c[j]!=c[j+1]+1) increasing=false;
        }

        if(increasing){
            cout << b[i] << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


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

using namespace std;

long long inf=1000000007;

long long modpow(long long n,long long p,long long mod);

int main(){
	long long w,h;
	cin>>w>>h;

	while(w!=0 || h!=0){
		struct mass{
			long long up=1;
			long long down=1;
			long long right=1;
			long long left=1;
		};

		vector<vector<mass>> grid(h,vector<mass>(w));

		for(long long i=0;i<h*2-1;i++){
			if(i%2==0){
				for(long long j=1;j<=w-1;j++){
					long long hoge;
					cin>>hoge;
					grid.at(i/2).at(j-1).right=hoge;
					grid.at(i/2).at(j).left=hoge;
				}
			}else{
				for(long long j=0;j<w;j++){
					long long hoge;
					cin>>hoge;
					grid.at(i/2).at(j).down=hoge;
					grid.at(i/2+1).at(j).up=hoge;
				}
			}
		}

		//TANSAKU START

		vector<vector<long long>> dis(h,vector<long long>(w,-1));
		queue<pair<long long,long long>> que;
		dis.at(0).at(0)=0;
		que.push(make_pair(0,0));

		while(!que.empty()){
			long long y=que.front().first;
			long long x=que.front().second;
			if(y==h-1 && x==w-1){
				break;
			}
			que.pop();

			if(grid.at(y).at(x).up==0 && dis.at(y-1).at(x)==-1){
				que.push(make_pair(y-1,x));
				dis.at(y-1).at(x)=dis.at(y).at(x)+1;
			}

			if(grid.at(y).at(x).down==0 && dis.at(y+1).at(x)==-1){
				que.push(make_pair(y+1,x));
				dis.at(y+1).at(x)=dis.at(y).at(x)+1;
			}

			if(grid.at(y).at(x).right==0 && dis.at(y).at(x+1)==-1){
				que.push(make_pair(y,x+1));
				dis.at(y).at(x+1)=dis.at(y).at(x)+1;
			}

			if(grid.at(y).at(x).left==0 && dis.at(y).at(x-1)==-1){
				que.push(make_pair(y,x-1));
				dis.at(y).at(x-1)=dis.at(y).at(x)+1;
			}
		}
		cout<<dis.at(h-1).at(w-1)+1<<endl;

		cin>>w>>h;
	}

	return 0;
}

long long modpow(long long n,long long p,long long mod){
	if(p==0) return 1;
	if(p%2==0) return (modpow(n,p/2,mod)*modpow(n,p/2,mod))%mod;
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}



Measured memory_bytes: 3072
#include<cstdio>
#include<map>
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
#include<stack>
#include<vector>
#include<cmath>
using namespace std;

char s[100005],a[100005];

int main(){
	int flag = 0,all = 0,sum = 0;
	cin >> s + 1;
	int n = strlen(s + 1);
	for(int i = 1;i <= n;i++){
		if(s[i] != 'x') a[++all] = s[i];
	}
	for(int i = 1;i <= all / 2;i++){
		if(a[i] != a[all - i + 1]) flag = 1;
	}
	if(flag){
		cout << "-1";
		return 0;
	}
	int head = 1,tail = n;
	while(head <= tail){
		if(s[head] != s[tail]){
			sum++;
			if(s[head] == 'x') head++;
			else tail--;
		}
		else tail--,head++;
	}
	cout << sum;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>

using namespace std;

double p[3001];
double dp[2][3001]; //dp[n-koin][head cnt]

int main() {
    int n;
    cin >> n;
    
    for (int i=1;i<=n;i++)
        cin >> p[i];
    
    for (int i=0;i<=n;i++)
        dp[1][i]=0;
    
    dp[1][0]=1-p[1];
    dp[1][1]=p[1];
        
    for (int i=2;i<=n;i++){
        dp[i%2][0]=(1-p[i])*dp[(i+1)%2][0];
        for (int j=1;j<=n;j++){
            dp[i%2][j]=p[i]*dp[(i+1)%2][j-1]+(1-p[i])*dp[(i+1)%2][j];
        }
    }
    
    double ans=0;
    for (int i=n/2+1;i<=n;i++)
        ans+=dp[1][i];
    
    cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#ifdef _debug
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#define dout(i) 0&&0
#endif
#define rout(i) (cout << i << '\n', 0)
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
using db = double;
template<typename T, typename S>
inline istream& operator >> (istream &in, const pair<T, S> &a){
	return in >> a.first >> a.second;
}
template<typename T, typename S>
inline ostream& operator << (ostream &ou, const pair<T, S> &b){
	return ou << b.first << ' ' << b.second;
}
const int maxn = 400000;
int n, a[maxn], cnt[maxn], res[maxn];
vector<int> qu;
int h[maxn], w[maxn], m;
int pref[maxn];
int ph[maxn];
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for(int i = 0;i < n;++i)cin >> a[i];
	for(int i = 0;i < n;++i)++cnt[a[i]];
	qu.reserve(n);
	for(int i = 1;i <= n;++i)if(cnt[i])qu.emplace_back(cnt[i]);
	sort(qu.begin(), qu.end());
	for(int i = 0, last = 0;i < qu.size();++i){
		if(qu[i] != last){
			++m;
			w[m] = qu.size()-i, h[m] = qu[i]-last;
		}
		last = qu[i];
	}
	// 
	reverse(w+1, w+1+m);
	reverse(h+1, h+1+m);
	for(int i = 1;i <= m;++i)pref[i] = pref[i-1] + w[i] * h[i], ph[i] = ph[i-1] + h[i];
	for(int i = 1, j = 1;i <= n;++i){
		for(;j <= m and w[j] < i;++j);
		res[i] = ph[m] - ph[j-1];
		int la = (n - pref[j-1] - res[i] * i), lw = w[m]-i;
		for(int k = j-1;k > 0 and la > 0 and i-w[k] <= lw;--k){
			int ad = min(h[k], la / (i-w[k]));
			if(!ad)break;
			res[i] += ad;
			la -= ad * (i-w[k]);
			if(ad != h[k])break;
		}
		res[i] += la / i;
	}
	for(int i = 1;i <= n;++i)cout << res[i] << '\n';
}

Measured memory_bytes: 10496
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static final int MODULUS = 1_000_000_007;

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

        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] a = new int[N - 1];
        int[] b = new int[N - 1];
        for (int i = 0; i < N - 1; ++i) {
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
        }

        System.out.println(solve(a, b, K));

        sc.close();
    }

    static int solve(int[] a, int[] b, int K) {
        int N = a.length + 1;

        @SuppressWarnings("unchecked")
        List<Integer>[] adjLists = new List[N];
        for (int i = 0; i < adjLists.length; ++i) {
            adjLists[i] = new ArrayList<>();
        }

        for (int i = 0; i < a.length; ++i) {
            adjLists[a[i]].add(b[i]);
            adjLists[b[i]].add(a[i]);
        }

        return search(K, adjLists, new boolean[N], 0, false, 0);
    }

    static int search(int K, List<Integer>[] adjLists, boolean[] visited, int excludeNum, boolean hasGrandParent,
            int node) {
        visited[node] = true;

        int result = Math.max(0, K - excludeNum);
        int nextExcludeNum = 1 + (hasGrandParent ? 1 : 0);
        for (int adj : adjLists[node]) {
            if (!visited[adj]) {
                result = multiplyMod(result, search(K, adjLists, visited, nextExcludeNum, true, adj));

                ++nextExcludeNum;
            }
        }

        return result;
    }

    static int multiplyMod(int x, int y) {
        return (int) ((long) x * y % MODULUS);
    }
}

Measured memory_bytes: 82516
#include <bits/stdc++.h>
using namespace std;
int main() {
	string a;
	cin>>a;
	int b=0,c=0;
	
	for(int i=0; i<a.size(); i++){
		if((a.at(i)=='A')||
		(a.at(i)=='T')||
		(a.at(i)=='G')||
		(a.at(i)=='C')){
			b++;
			if(b>=c){
				c=b;
			}
		}
		else{
			b=0;
		}
		
	}cout<<c<<endl;
}

Measured memory_bytes: 256
count, total = map(int, input().split())
turtle = 4
clain = 2

def assert_pattern(count, total):
    if turtle * count < total:
        return False
    if clain * count > total:
        return False
    if total % clain != 0:
        return False
    return True
    

print('Yes' if assert_pattern(count, total) else 'No')

Measured memory_bytes: 9176
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	N := nextInt()
	M := map[int]int{1: 0, 0: 1}
	fmt.Println(M[N])
}

Measured memory_bytes: 1808
import sys
input = sys.stdin.readline
from collections import deque

k, q = int(input()), deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(1, k):
    x = q.popleft()
    if x % 10 != 0: q.append(10 * x + (x % 10) - 1)
    q.append(10 * x + (x % 10))
    if x % 10 != 9: q.append(10 * x + (x % 10) + 1)
print(q.popleft())

Measured memory_bytes: 74672
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
long long mod=1000000009;
int x[32];
long long y[32];
int mat[63][75][75];
int val[75][75];
int tmp[75][75];
int sen[75][75];
long long now[110];
long long to[110];
long long z[110];
int v[110];

int main(){
	int tc=0;
	int a,c;
	long long b;
	while(scanf("%d%lld%d",&a,&b,&c),a){
		bool dame=false;
		for(int i=0;i<c;i++){
			scanf("%d%lld",x+i,y+i);
			x[i]--;y[i]--;
			z[i]=y[i];
			if(x[i]==a-1&&y[i]==b-1){
				dame=true;
			}
		}
		if(dame){
			printf("Case %d: 0\n",++tc);continue;
		}
		std::sort(z,z+c);
		z[c]=b-1;
		for(int i=0;i<a;i++)for(int j=0;j<a;j++)sen[i][j]=0;
		for(int i=0;i<a;i++){
			sen[i][i]++;
			if(i)sen[i-1][i]++;
			if(i<a-1)sen[i+1][i]++;
		}
		for(int i=0;i<a;i++){
			for(int j=0;j<a;j++)mat[0][i][j]=sen[i][j];
		}
		for(int i=1;i<63;i++){
			for(int j=0;j<a;j++)for(int k=0;k<a;k++)mat[i][j][k]=0;
			for(int j=0;j<a;j++)for(int k=0;k<a;k++)for(int l=0;l<a;l++)
				mat[i][j][k]=(mat[i][j][k]+(long long)mat[i-1][j][l]*mat[i-1][l][k])%mod;
		}
		for(int i=0;i<a;i++)now[i]=0;
		now[0]=1;
		int at=0;
		long long last=0;
		for(int i=0;i<=c;i++){
			if(i&&z[i]==z[i-1])continue;
			for(int j=0;j<a;j++)for(int k=0;k<a;k++)val[j][k]=0;
			for(int j=0;j<a;j++)val[j][j]=1;
			long long d=z[i]-last;
			for(int s=0;s<63;s++){
				if(d&(1LL<<s)){
					for(int j=0;j<a;j++)for(int k=0;k<a;k++)tmp[j][k]=0;
					for(int l=0;l<a;l++)for(int j=0;j<a;j++)if(mat[j][l])for(int k=0;k<a;k++){
						if(val[l][k])tmp[j][k]=(tmp[j][k]+(long long)mat[s][j][l]*val[l][k])%mod;
					}
					for(int j=0;j<a;j++)for(int k=0;k<a;k++)val[j][k]=tmp[j][k];
				}
			}
			for(int j=0;j<a;j++){
				to[j]=0;
			}
			for(int j=0;j<a;j++){
				for(int k=0;k<a;k++)to[j]=(to[j]+now[k]*val[j][k])%mod;
			}
			for(int j=0;j<a;j++)now[j]=to[j];
			if(i==c)break;
			last=z[i]+1;
			for(int j=0;j<a;j++)v[j]=0;
			for(int j=0;j<c;j++)if(z[i]==y[j])v[x[j]]=1;
			for(int j=0;j<a;j++)to[j]=0;
			for(int j=0;j<a;j++){
				if(v[j])continue;
				for(int k=-1;k<=1;k++){
					if(0<=j+k&&j+k<a)to[j+k]=(to[j+k]+now[j])%mod;
				}
			}
			for(int j=0;j<a;j++)now[j]=to[j];
		}
		printf("Case %d: %lld\n",++tc,now[a-1]);
	}
}

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


int main(){
  string S;
  cin >> S;
  if(S[0] != 'A'){ cout << "WA" << endl; return 0; }
  int sum = 0;
  for(int i = 2; i < S.size() - 1; i++){
    if(S[i] == 'C'){ sum++; }
  }

  if(sum == 0 || sum >= 2){ cout << "WA" << endl; return 0; }
  
  sum = 0;
  for(int i = 0; i < S.size(); i++){
    if(isupper(S[i])){ sum++; }
  }

  if(sum == 2){ cout << "AC" << endl; }
  else{ cout << "WA" << endl; }
 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in n;
VVI egs;
in gn(in u, in pr){
  in tn;
  in txor=0;
  forv(i,egs[u]){
    if(egs[u][i]==pr)
      continue;
    tn=gn(egs[u][i],u);
    txor^=tn;
  }
  return txor+1;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin>>n;
  egs.resize(n);
  in ta,tb;
  forn(z,n-1){
    cin>>ta>>tb;
    --ta;
    --tb;
    egs[ta].PB(tb);
    egs[tb].PB(ta);
  }
  if(gn(0,0)==1)
    cout<<"Bob"<<endl;
  else
    cout<<"Alice"<<endl;
  return 0;
}


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

int main() {
  string a, b;
  cin >> a >> b;

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  reverse(b.begin(), b.end());

  if (a < b) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
N=int(input())
A=[int(i) for i in input().split()]
dp=[0 for i in range(N)]
AL=A[0]
AR=A[0]
flag0=0
for i in range(1,N):
    AL=AL^A[i]
    AR=AR+A[i]
    if AL!=AR:
        dp[0]=i
        AL=A[i]^AL
        AR-=A[i]
        flag0=1
        break
if flag0==0:
    dp[0]=N
for i in range(1,N):
    AL=AL^A[i-1]
    AR=AR-A[i-1]
    flag=0
    for j in range(dp[i-1],N):
        AL=AL^A[j]
        AR=AR+A[j]
        if AL!=AR:
            dp[i]=j
            AL=A[j]^AL
            AR-=A[j]
            flag=1
            break
    if flag==0:
        dp[i]=N
print(sum(dp)-(N*(N-1))//2)


Measured memory_bytes: 23560
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] card = new int[4][13];
        for (int i = 0; i < n; i++) {
            switch (sc.next()) {
                case "S":
                    card[0][sc.nextInt()-1]++;
                    break;
                case "H":
                    card[1][sc.nextInt()-1]++;
                    break;
                case "C":
                    card[2][sc.nextInt()-1]++;
                    break;
                case "D":
                    card[3][sc.nextInt()-1]++;
                    break;
            }
        }
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 13; j++) {
                if (card[i][j] == 0) {
                    switch (i) {
                        case 0:
                            System.out.println("S " + (j+1));
                            break;
                        case 1:
                            System.out.println("H " + (j+1));
                            break;
                        case 2:
                            System.out.println("C " + (j+1));
                            break;
                        case 3:
                            System.out.println("D " + (j+1));
                            break;
                    }
                }
            }
        }
        sc.close();
    }
}


Measured memory_bytes: 26376
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
//#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<vi> vvi;
int gcd(int x,int y){
	if(y==0)return x;
	return gcd(y,x%y);
}
int n,x,a,g;
int main() {
	cin>>n>>x>>a;
	g=abs(a-x);
	for(int i=0;i<n-1;i++){
		cin>>a;
		g=gcd(abs(a-x),g);
	}
	cout<<g<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int num[3];
	int i, j;
	int tmp;
	for (i = 0; i < 3; i++)
		scanf("%d", &num[i]);
	for(i=0;i<3;i++)
		for(j=i;j<3;j++)
			if (num[i]>num[j])
			{
				tmp = num[i];
				num[i] = num[j];
				num[j] = tmp;
			}
	printf("%d %d %d\n", num[0], num[1], num[2]);
	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        
        int a = scan.nextInt();//
        int b = scan.nextInt();// 
        
        
        
               
            System.out.println((a+b)/2);
     
        }
        
    }





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


const int maxn = 1000;

char s[maxn];
int n;

bool solve()
{
    for(int i = 0;i < n;++i)
        if(s[i] == 'C')
        {
            for(int j = i+1;j < n;++j)
            {
                if(s[j] == 'F')
                {
                    return true;
                }
            }
            return false;
        }
    return false;
}

int main()
{
   // freopen("./test.txt","r",stdin);
    scanf("%s",s);
    n = strlen(s);
    if(solve())
        puts("Yes");
    else
        puts("No");
    return 0;
}


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

using namespace std;

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

    long long n, d, a, ans = 0, b = 0;
    cin >> n >> d >> a;
    vector<pair<long long, long long>> v(n);
    queue<pair<long long, long long>> q;
    q.push({-1, 0});

    for (int i = 0; i < n; i++)
        cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end(), greater<pair<long long, long long>>());

    while (!v.empty()) {
        while (!q.empty() && v.back().first > q.front().first)
            b -= q.front().second, q.pop();
        v.back().second -= b * a;

        if (v.back().second > 0) {
            int cur = v.back().second / a + (v.back().second % a != 0);
            int range = v.back().first + 2 * d;
            q.push({range, cur});
            b += cur;
            ans += cur;
        }
        v.pop_back();
    }

    cout << ans << '\n';

    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S,T;
deque<pair<int,int>> Q;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S>>T;
	
	if(S==T) return _P("0\n");
	
	int R=N-1;
	int ma=0;
	int dif=0;
	for(i=N-1;i>=0;i--) {
		if(i==0 || T[i]!=T[i-1]) {
			R=min(i,R);
			while(R>=0 && T[i]!=S[R]) R--;
			if(R<0) return _P("-1\n");
			
			if(i==R) {
				Q.clear();
			}
			else {
				if(Q.empty()) dif=0;
				else dif++;
				Q.push_back({R+dif,1-dif});
			}
			R--;
		}
		
		ma=max(ma,(int)Q.size()+1);
		/*
		_P("%d ",Q.size());
		FORR(r,Q) _P("(%d,%d) ",r.first-dif,r.second+dif);
		_P("\n");
		*/
		if(Q.size() && Q.front().first-dif>=i) Q.pop_front();
	}
	cout<<ma<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 10396
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int x;cin>>x;
    cout << x*x*x << endl;
    return 0;
}


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

int main() {
    int n,m;
    cin>>n>>m;
    vector<bool> dp(n);
    dp[0]=true;
    vector<int> cnt(n,1);
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        x--;
        y--;
        cnt[x]--;
        cnt[y]++;
        if(dp[x]) dp[y]=true;
        if(cnt[x]==0) dp[x]=false;
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(dp[i]) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def group(x):
    if x in [1, 3, 5, 7, 8, 10, 12]:
        return "A"
    if x in [4, 6, 9, 11]:
        return "B"
    if x in [2]:
        return "C"


x, y = map(int, readline().split())
ans = 'Yes' if group(x) == group(y) else 'No'
print(ans)

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

using namespace std;

int main() {
    int N, a, d;
    cin >> N >> a >> d;

    int M;
    cin >> M;

    unordered_map<int, int> A;
    int x, y, z;
    int Ay, Az;

    while (M--) {
        cin >> x >> y >> z;
        Ay = A.find(y) != A.end() ? A[y] : (a + d * (y - 1));
        Az = A.find(z) != A.end() ? A[z] : (a + d * (z - 1));
        if (x == 0) {
            A[y] = Az;
            A[z] = Ay;
        } else {
            A[y] = Az;
        }
    }

    int K;
    cin >> K;
    cout << (A.find(K) != A.end() ? A[K] : (a + d * (K - 1))) << endl;
}


Measured memory_bytes: 3108
#include<stdio.h>

int main(){
   int a,b,c;
   scanf("%d %d %d", &a, &b, &c);

   if(a == b && c != a && c != b){
      printf("Yes\n");
   }else if(b == c && a != b && a != c){
      printf("Yes\n");
   }else if(c == a && b != a && b != c){
      printf("Yes\n");   
   }else{
      printf("No\n");
   }
   return 0;
}


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

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

	string ans;
	for( int i = 0; i < S.size(); i++ ) {
		ans += (char)(((S[i] - 'A' + N) % 26) + 'A');
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<map>
#include<cstring>
#define H(tx,ty) tx<0||tx>=h||ty<0||ty>=w||MAS[tx][ty]==1
using namespace std;
int h,w,tx,ty,kx,ky,d[]={0,1,0,-1},MAS[51][51];
bool used[51][51][51][51];
struct P{
  int tx,ty,kx,ky,cnt;
  P(int tx,int ty,int kx,int ky,int cnt):tx(tx),ty(ty),kx(kx),ky(ky),cnt(cnt){}
};
int bfs();
int main(){
  while(cin >> w >> h && w|h){
    cin >> ty >> tx >> ky >> kx;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	cin >> MAS[i][j];
    memset(used,false,sizeof(used));
    int ans = bfs();
    if(ans==-1)cout << "NA" << endl;
    else cout << ans << endl;
  }
}
int bfs(){
  queue<P>que;
  que.push(P(tx-1,ty-1,kx-1,ky-1,0));
  used[tx-1][ty-1][kx-1][ky-1] = true;
  while(!que.empty()){
    P p = que.front();
    if(p.tx == p.kx && p.ty == p.ky) return p.cnt;
    else if(p.cnt >= 100) return -1;
    for(int i=0;i<4;i++){
      int ntx = p.tx + d[i],nty = p.ty + d[3-i];
      int nkx = p.kx - d[i],nky = p.ky - d[3-i];
      if(H(ntx,nty))ntx = p.tx,nty = p.ty;
      if(H(nkx,nky))nkx = p.kx,nky = p.ky;
      if(!used[ntx][nty][nkx][nky]){
	que.push(P(ntx,nty,nkx,nky,p.cnt+1));
	used[ntx][nty][nkx][nky] = true;
      }
    }
    que.pop();
  }
  return -1;
}

Measured memory_bytes: 7996
n = gets.to_i
count = 0

for i in 0..n-1 do
  a = gets.to_i
  x = 1
  e = true
  while 2 * x * (x + 1) <= a
    if (a - x) % (2 * x + 1) == 0
      e = false
      break
    end
    x = x + 1
  end
  x = 0
  if e == true then
    count = count + 1
  end
end

puts count



Measured memory_bytes: 6852
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
        for (int i=0;i<26;i++) {
            ArrayList<Integer> add = new ArrayList<Integer>();
            list.add(add);
        }
        for (int i=0;i<s.length();i++) {
            list.get((int)s.charAt(i)-97).add(i);
        }

        int index = 0;
        int ans = 0;
        for (int i=0;i<t.length();i++) {
            if (list.get((int)t.charAt(i)-97).size()==0) {
                System.out.println(-1);
                return;
            }
            int tmp = ~Collections.binarySearch(list.get((int)t.charAt(i)-97), index, (o1, o2)->o1>=o2?1:-1);
            if (tmp==list.get((int)t.charAt(i)-97).size()) {
                ans++;
                index = list.get((int)t.charAt(i)-97).get(0)+1;
            } else {
                index = list.get((int)t.charAt(i)-97).get(tmp)+1;
            }
        }
        System.out.println((long)ans*s.length()+index);
        // System.out.println(list);
    }
}

Measured memory_bytes: 33808
from collections import deque


n, q = map(int, input().split())
graph = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    graph[a - 1] += [b - 1]
    graph[b - 1] += [a - 1]


cost = [0] * n
for j in range(q):
    p, x = map(int, input().split())
    cost[p - 1] += x



visited = [0] * n
visited[0] = 1
que = deque([0])

while que:
    cur = que.popleft()
    for nxt in graph[cur]:
        if visited[nxt]:
            continue
        cost[nxt] += cost[cur]
        que.append(nxt)
        visited[nxt] = 1


print(*cost)

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

int main()
{
    int h,w;
    cin >> h >> w;

    vector<string> v(h);

    for(size_t i=0;i<v.size();i++){
        cin >> v.at(i);
    }

    bool ans =true;

    for(size_t y=0;y<v.size();y++){

        for(size_t x=0;x<v.at(y).size();x++){
            bool judge=true;
            if(v.at(y).at(x)=='#'){

                judge=false;
                for(int dy =-1;dy<=1;dy+=2){
                    int ny=y+dy;
                    if(ny==-1||ny==h)
                        continue;
                    if(v.at(ny).at(x)=='#')
                        judge=true;
                }
                for(int dx =-1;dx<=1;dx+=2){
                    int nx=x+dx;
                    if(nx==-1||nx==w)
                        continue;
                    if(v.at(y).at(nx)=='#')
                        judge=true;
                }
            }

            if(!(judge))
                ans=false;
        }
    }

    if(ans) cout << "Yes"<<endl;
    else    cout << "No"<<endl;

}

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

#define ll long long

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> p(n+1);
	vector<ll> c(n+1);
	vector<ll> q;
	ll i, j;
	ll buf;
	ll total;
	ll ans = -1e10;
	for (i = 1; i <= n; i++) {
		cin >> p[i];
	}
	for (i = 1; i <= n; i++) {
		cin >> c[i];
	}
	for (i = 1; i <= n; i++) {
		buf = i;
		total = 0;
		while (1) {
			buf = p[buf];
			total += c[buf];
			q.push_back(c[buf]);
			if (buf == i)break;
		}
		buf = 0;
		for (j = 0; j < q.size(); j++) {
			buf += q[j];
			if (total > 0)ans = max(ans, buf + total * ((k - j - 1) / (ll)q.size()));
			else ans = max(ans, buf);
			if (j + 1 == k)break;
		}
		q.clear();
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3824
n = int(input())
all_h_or_u = []

#証言リスト
for i in range(n) :
    x = int(input())
    h_or_u = []
    for j in range(x) :
        h_or_u.append(list(map(int, input().split())))
    
    for k in range(x) :
        h_or_u[k][0] -= 1
    
    all_h_or_u.append(h_or_u)
    
#真偽パターン 
all_t_or_f = []
for a in range(2 ** n) :
    t_or_f = []
    for b in range(len(bin(2**n)) - 3) :
        if (a >> b) & 1 :
            t_or_f.append(1)
        else :
            t_or_f.append(0)
        
    all_t_or_f.append(t_or_f)

#真偽パターンに応じた証言の検証
max_cnt = 0
for c in all_t_or_f :
    cnt = 0
    for d in range(n) :
        if c[d] == 1 :
            for e in all_h_or_u[d] :
                if c[e[0]] != e[1] :
                    cnt += 1
    
    if cnt == 0 :
        max_cnt = max(max_cnt, sum(c))
            
print(max_cnt)

Measured memory_bytes: 15420
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define nl '\n'
#define INF 2147483647
#define si(i) scanf("%d", &i)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int n, k, ans = INF;
int hgt[100005];

int main(){
    cin >> n >> k;
    for( int i = 0 ; i < n ; i++ ){
        si(hgt[i]);
    }
    sort(hgt, hgt + n);
    ans = hgt[k - 1] - hgt[0];
    for( int i = 1 ; i <= n - k ; i++ ){
        ans = min( ans, hgt[i + k - 1] - hgt[i]);
    }
    cout << ans << nl;
}

Measured memory_bytes: 640
import itertools

N, M = tuple([int(x) for x in input().split(' ')])

tmp = [[int(x) for x in input().split(' ')] for i in range(M)]
k, s = zip(*[(t[0], t[1:]) for t in tmp])
p = [int(x) for x in input().split(' ')]

pats = itertools.product([0,1], repeat=N)

count = 0
for pat in pats:
    flag = True
    for m in range(M):
        tmp = [pat[ss-1] for ss in s[m]]
        flag = flag and sum([pat[ss-1] for ss in s[m]]) % 2 == p[m]
    if flag:
        count += 1

print(count)

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

int main(void){
  int n;
  scanf("%d", &n);
  int l;
  scanf("%d", &l);
  int i;
  int aji[n];
  int sum=0;
  for(i=0;i<n;i++){
    aji[i] = l + i;
    sum += aji[i];
  }
  int j;
  int max = 10000000;
  int maxidx = 0;
  int now;
  for(i=0;i<n;i++){
    now = sum - aji[i];
    if(abs(sum-now)<max){
      max = abs(sum-now);
      maxidx = i;
    }
  }
  printf("%d", sum-aji[maxidx]);
}

Measured memory_bytes: 128
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
l = inp.shift().split(' ')
N = l.shift() * 1
K = l.shift() * 1 
H = inp.shift().split(' ').map(x => x - 0).sort((a,b) => a - b).slice(0, N > K ? N - K : 0).reduce(((c, a) => a + c), 0)
console.log(H)

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

int main(){
    int a, b;
    cin >> a >> b;
    int ans = 1;
    int n = a*1000 + b;
    if(n >= 2002) ans++;
    if(n >= 3003) ans++;
    if(n >= 4004) ans++;
    if(n >= 5005) ans++;
    if(n >= 6006) ans++;
    if(n >= 7007) ans++;
    if(n >= 8008) ans++;
    if(n >= 9009) ans++;
    if(n >= 10010) ans++;
    if(n >= 11011) ans++;
    if(n >= 12012) ans++;

    cout << ans << endl;

}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 60;

template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

long long dp[110][100010];
int main() {
  int n, w; cin>>n>>w;
  rep(i, n) {
    int wt, v; cin>>wt>>v;
    rep(j, w+1) {
      if (j >= wt) dp[i+1][j] = max(dp[i][j-wt] + v, dp[i][j]);
      else dp[i+1][j] = dp[i][j];
    }
  }
  print(dp[n][w]);
  return 0;
}

Measured memory_bytes: 79360
/*
 * Created By : pash123
 * 2020-09-13-17.50
*/


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

const int M=1e9+7;

vector<ll> points1;
vector<int> points2;
vector<pair<int,int>> input;

int main()
{
    int n;
    cin>>n;
    int x,y;
    input.push_back(make_pair(0,0));
    for(int i=0;i<n;++i)
    {
        cin>>x>>y;
        input.push_back(make_pair(x,y));
    }
    sort(input.begin(),input.end());
    for(int i=1;i<(int)input.size();++i)
    {
        if((input[i].first==input[i-1].first)&&(input[i].second==input[i-1].second)) continue;
        else
            points1.push_back(input[i].first+input[i].second);
    }

    for(int i=1;i<(int)input.size();++i)
    {
        if((input[i].first==input[i-1].first)&&(input[i].second==input[i-1].second)) continue;
        else
            points2.push_back(input[i].first-input[i].second);
    }

    sort(points1.begin(),points1.end());
    sort(points2.begin(),points2.end());

    ll ans1=abs(points1[0]-points1[points1.size()-1]);
    ll ans2=abs(points2[0]-points2[points2.size()-1]);

    if(ans1>ans2)
        cout<<ans1;
    else
        cout<<ans2;
    return 0;
}


Measured memory_bytes: 8020
import copy

D = int(input())
c = list(map(int,input().split()))
s = []
for i in range(D):
    s.append(list(map(int,input().split())))
last = [0]*26
    
ans = 0
md = [0]*26
cand = []
cand2 = []
tl = []

for day in range(D):
    for j in range(26):
        last[j] += 1
    
    for k in range(26):
        #k番目を選ぶことによる
        merit = s[day][k]
        merit += last[k] * c[k]
        demerit = 0
        for j in range(26):
            if j != k:
                demerit += c[j] * last[j]
        md[k] = merit - demerit

    #日程の確定
    md2 = sorted(md)
    t = md.index(md2[-1])
    last[t] = 0
    tl.append(t+1)
    
    can = md.index(md2[-2])
    cand.append(can+1)
    
    can2 = md.index(md2[-3])
    cand2.append(can2+1)
    #print(t+1)
    

    
#得点計算

def calcans(tl):
    last = [0]*26
    ans = 0
    for day in range(D):
        #満足度プラス計算
        ans += s[day][tl[day]-1]
        for j in range(26):
            last[j] += 1
        last[tl[day]-1] = 0
        #満足度マイナス計算
        minus = 0
        for j in range(26):
            minus += c[j] * last[j]
        ans -= minus
    return ans

normal = calcans(tl)
change = -1

tl2 = copy.deepcopy(tl)
for ii in range(D):
    tl2[ii] = cand[ii]
    challenge = calcans(tl2)
    if normal < challenge:
        normal = challenge
        tl2[ii] = cand2[ii]
        challenge = calcans(tl2)
        if normal < challenge:
            normal = challenge
        else:
            tl2[ii] = cand[ii]
    else:
        tl2[ii] = cand2[ii]
        challenge = calcans(tl2)
        if normal < challenge:
            normal = challenge
        else:
            tl2[ii] = tl[ii]
        
    
for tlc in tl2:
    print(tlc)

Measured memory_bytes: 9556
#include <iostream>
#include <vector>

int get_hit(std::vector<u_int> *A, std::vector<u_int> *B)
{
    u_int hit = 0;
    for(u_int i = 0; i < A -> size(); ++i)
        if(A -> at(i) == B -> at(i))
            ++hit;
            
    return hit;
}

int get_blow(std::vector<u_int> *A, std::vector<u_int> *B)
{
    u_int blow = 0;
    for(u_int i = 0; i < A -> size(); ++i){
        for(u_int j = 0; j < B -> size(); ++j){
            if(A -> at(i) == B -> at(j)){
                if(i != j)
                    ++blow;
                break;
            }
        }
    }
            
    return blow;
}

int main()
{
    const u_int number = 4;
    std::vector<u_int> A;
    std::vector<u_int> B;
    A.reserve(number);
    B.reserve(number);
    
    u_int num1, num2, num3, num4;
    bool flag = true;
    while(std::cin >> num1 >> num2 >> num3 >> num4){
        if(flag){
            A.clear();
            B.clear();
            A.push_back(num1);
            A.push_back(num2);
            A.push_back(num3);
            A.push_back(num4);
            flag = !flag;
        }else{
            B.push_back(num1);
            B.push_back(num2);
            B.push_back(num3);
            B.push_back(num4);
            std::cout << get_hit(&A, &B) << " " << get_blow(&A, &B) << std::endl;
            flag = !flag;
        }
    }
        
    return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
 
using ll = long long int;
 
int main(void){
    
    int n;
    cin >> n;
    
    ll answer = pow(3,n);
    ll sub = 1;
    
    
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        if(a % 2 == 1){
            
        }else{
            sub *= 2;
        }
    }
    
    cout << answer - sub << endl;
    
}

Measured memory_bytes: 256