akhauriyash/Code-Regression huggingface dataset:
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("board.in");ofstream out("board.out");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid u1(5, 10); u1(rnd);

int main() {
    fast;
    ll a,b; cin>>a>>b;
    if(a<6) cout<<0<<endl;
    else if(a<13) cout<<b/2<<endl;
    else cout<<b<<endl;
}

Measured memory_bytes: 256
# jsc2019-qualB - Kleene Inversion
from collections import Counter
from itertools import accumulate


def main():
    N, K = tuple(map(int, input().split()))
    A = tuple(map(int, input().split()))
    MOD = 10 ** 9 + 7
    C = list(Counter(A).values())
    ac = list(accumulate(C[:-1]))
    x = sum(i * j for i, j in zip(C[1:], ac)) % MOD
    y = 0
    for i, a in enumerate(A[:-1]):
        y += sum(b > a for b in A[i + 1 :])
    ans = (x * (1 + K) * K // 2) % MOD
    ans = (ans - y * K) % MOD
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3564
#include <bits/stdc++.h>
template <typename T>
T gcd(const T x, const T y) {
  if (x == 0) {
    return y;
  } else if (y == 0) {
    return x;
  } else if (x < y) {
    return gcd(x, y % x);
  } else if (y < x) {
    return gcd(y, x % y);
  } else {
    return x;
  }
}

template <typename T>
T lcm(const T x, const T y) {
  if (x == 0 || y == 0) {
    return 0;
  } else {
    return x / gcd(x, y) * y;
  }
}

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<int64_t> a(n);

  for (auto &i : a) {
    std::cin >> i;
  }

  std::vector<int64_t> f(n), b(n);

  f[0] = a[0];
  for (int64_t i = 1; i < n; i++) {
    f[i] = gcd(f[i - 1], a[i]);
  }

  b[n - 1] = a[n - 1];
  for (int64_t i = n - 2; 0 <= i; i--) {
    b[i] = gcd(b[i + 1], a[i]);
  }

  int64_t ans = std::max(f[n - 2], b[1]);

  for (int64_t i = 1; i < n - 1; i++) {
    ans = std::max(ans, gcd(f[i - 1], b[i + 1]));
  }

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

Measured memory_bytes: 2560
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
//#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define MOD 998244353
#define SIZE 1000005

int N;
ll POW[SIZE];
ll x[SIZE];

ll mod_pow(ll x,ll count, ll mod){

	if(count == 0)return 1;
	ll ret = mod_pow((x*x)%mod,count/2,mod);
	if(count%2 == 1){

		ret = (ret*x)%mod;
	}
	return ret;
}

int main(){

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
		POW[i] %= MOD;
	}

	scanf("%d",&N);

	for(int i = 1; i <= N; i++){

		scanf("%lld",&x[i]);
	}

	ll ans = 0;

	for(int i = 1; i <= N; i++){

		ll tmp = mod_pow(1+x[i],i-1,MOD);

		tmp *= x[i];
		tmp %= MOD;

		tmp *= POW[N-i];
		tmp %= MOD;

		ans += tmp;
		ans %= MOD;
	}

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 18748
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
typedef long long ll;
using namespace std;

int main() {
	int n,a,ans;
	double t,mi=100001;
	cin>>n>>t>>a;
	double h[n],b[n],c[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
		b[i]=t-h[i]*0.006;
		c[i]=a-b[i];
		c[i]=abs(c[i]);
		if(mi>c[i]){
			ans=i;
			mi=c[i];
		}
	}
	cout << ans+1<<endl;
	return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main (){
    long long int N,H,a[100000],b[100000];
    cin >> N >> H;
    for(int i = 0 ; i < N ; i++){
        cin >> a[i] >> b[i];
    }
    int aMax=0;
    for(int i = 0 ; i < N ; i++){
        aMax=(aMax<a[i])? a[i] : aMax;
    }
   
    long long int count=0;
    sort(b,b+N);
    
    
   
    
    
    while(H > 0){
        count++;
        if(b[N-1]>aMax){
           
            H=H-b[N-1];
            N--;
        }else{
            H=H-aMax;
             
        }
        
    }
    cout << count;
    return 0;
    
}


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

typedef long long lint;
typedef long double louble;

#define so(a) ((int)((a).size()))

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const char lf = '\n';

namespace ae86
{
	const int bufl = 1 << 15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 5007 , mo = 1000000007;

inline int upd(int x){return x+((x>>31)&mo);}
inline lint upd(lint x){return x+((x>>63)&mo);}
template<typename T1,typename T2> inline T1 ad(T1 &a,T2 b){return a=upd(a+b-mo);}
template<typename T1,typename T2> inline T1 dl(T1 &a,T2 b){return a=upd(a-b);}
template<typename T1,typename T2> inline T1 add(T1 a,T2 b){return upd(a+b-mo);}
template<typename T1,typename T2> inline T1 del(T1 a,T2 b){return upd(a-b);}

int n,pa,pb;
lint f[_][_][2]={0},sf[_][2]={0},g[_][_][2]={0};

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

	n=ty(),pa=ty(),pb=ty();

	if(pa<pb)swap(pa,pb);

	f[0][0][0]=sf[0][0]=g[0][0][0]=1;
	f[0][0][1]=sf[0][1]=g[0][0][1]=1;

	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<pa;j++)
		{
			if(i>=1 && j>=1)ad(f[i][j][0],g[i-1][j-1][1]);
			if(i>=pb && j>=pb)ad(f[i][j][1],g[i-pb][j-pb][0]);
		}
		for(int j=1;j<=min(i,pb-1);j++)ad(f[i][0][1],sf[i-j][0]);

		g[i][0][1]=f[i][0][1];
		for(int j=1;j<pa;j++)
		{
			g[i][j][0]=add(g[i-1][j-1][0],f[i][j][0]);
			g[i][j][1]=add(g[i-1][j-1][1],f[i][j][1]);
		}

		for(int j=0;j<pa;j++)ad(sf[i][0],f[i][j][0]),ad(sf[i][1],f[i][j][1]);
	}

	lint ans=1;
	for(int i=1;i<=n;i++)ad(ans,ans);
	for(int i=0;i<pa;i++)
		for(int j=0;j<2;j++)
			dl(ans,f[n][i][j]);
	cout<<ans<<lf;
	
	return 0;
}


Measured memory_bytes: 786100
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner st = new Scanner(System.in);
		int n = st.nextInt();
		int a = st.nextInt();
		int b = st.nextInt();
		String s = st.next();
		char[] sAr = s.toCharArray();
		int counta=0;
		int countb = 0;
		for (int i=0;i<n;i++){
		
			if (sAr[i]=='c'){
				System.out.println("No");
			}
			else{
				if (counta+countb>=a+b){
					System.out.println("No");
				}
				else {
					if (sAr[i]=='a'){
						counta++;
						System.out.println("Yes");
					}
					else if (sAr[i]=='b'&&countb<b){
						countb++;
						System.out.println("Yes");
					}
					else {
						System.out.println("No");
					}
				}
			}
		}
	}

}

Measured memory_bytes: 23980
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
struct poi{ll sum,pos;}a[200010];
ll n,k,ans,cnt,tree[200010],lisan[200010];
void read(ll &k)
{
	k=0;int f=1;char c=getchar();
	while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar();
	k*=f;
}
bool cmp(poi a,poi b){return a.sum<b.sum;}
int lowbit(int x){return x&-x;}
void add(int x,int delta)
{
	for(int i=x;i<=cnt;i+=lowbit(i))
	tree[i]+=delta;
}
int sum(int x)
{
	int s=0;
	for(int i=x;i>=1;i-=lowbit(i))
	s+=tree[i];
	return s;
}
int main()
{
	read(n);read(k);
	for(int i=1;i<=n;i++)read(a[i].sum),a[i].sum-=k;
	for(int i=1;i<=n;i++)a[i].sum+=a[i-1].sum,a[i].pos=i;
	sort(a,a+1+n,cmp);
	for(int i=0;i<=n;i++)
	{
		if(a[i].sum!=a[i-1].sum||i==0)cnt++;
		lisan[a[i].pos]=cnt;
	}
	for(int i=n;i>=0;i--)
	{
		ans+=sum(cnt)-sum(lisan[i]-1);
		add(lisan[i],1);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 6528
#include <stdio.h>
#define MAX_N 100
#define INF 2001

struct vertex
{
  int distance;
  int Edge[MAX_N];
  int visitFlag;
} typedef vertex;

int n;
vertex V[MAX_N]; 

int SumWeightMST();

int main()
{
  int i, j;

  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      for(j = 0; j < n; j++)
	{
	  scanf("%d", &V[i].Edge[j]);
	}
    }

  printf("%d\n", SumWeightMST());

  return 0;
}

int SumWeightMST()
{
  int i, j;
  int join = 0;
  int d, mini_d;
  int sum = 0;

  // Set default
  for(i = 0; i < n; i++)
    {
      V[i].distance = INF;
      V[i].visitFlag = 0;
    }

  // Make minimum spanning Tree
  for(i = 0; i < n; i++)
    {
      V[join].visitFlag = 1;

      // Set  new distance
      for(j = 0; j < n; j++)
	{
	  d = V[join].Edge[j];

	  if(V[j].visitFlag == 0 && d < V[j].distance && d != -1)
	    V[j].distance = d;
	}

      // Serch nearest Vertex
      mini_d = INF;
      for(j = 0; j < n; j++)
	{
	  if(mini_d > V[j].distance && V[j].visitFlag == 0) 
	    {
	      mini_d = V[j].distance;
	      join = j;
	    }
	}
      if(mini_d != INF)
	sum += mini_d;
    }

  return sum;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9+7;
const int INF = 0x3f3f3f3f;
ll max(ll a, ll b){return a > b ? a : b;}
ll min(ll a, ll b){return a < b ? a : b;}

int n, x;
vector<int> v(4);
double dp[303][303][303];
double ev[303][303][303];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("C.txt", "r", stdin);
    #endif
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> x;
        v[x]++;
    }
    dp[v[1]][v[2]][v[3]] = 1;
    for(int c=n; c>=0; c--)
    {
        for(int b=n; b>=0; b--)
        {
            for(int a=n; a>=0; a--)
            {
                if(a+b+c>n||a+b+c==0) continue;
                ev[a][b][c] += (double)n/(a+b+c)*dp[a][b][c];
                if(a!=0)
                {
                    dp[a-1][b][c] += dp[a][b][c] * (double)a / (a + b + c);
                    ev[a-1][b][c] += ev[a][b][c] * (double)a / (a + b + c);
                }
                if(b!=0)
                {
                    dp[a+1][b-1][c] += dp[a][b][c] * (double)b / (a + b + c);
                    ev[a+1][b-1][c] += ev[a][b][c] * (double)b / (a + b + c);
                }
                if(c!=0)
                {
                    dp[a][b+1][c-1] += dp[a][b][c] * (double)c / (a + b + c);
                    ev[a][b+1][c-1] += ev[a][b][c] * (double)c / (a + b + c);
                }
            }
        }
    }
    cout << fixed << setprecision(9) << ev[0][0][0];
}



Measured memory_bytes: 434560
#include<bits/stdc++.h>
 
#define INF 1000000007
#define LINF 1000000000000000007
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;


int a, b;

int main(){
	cin >> a >> b;
	
	if(a == b) cout << "Draw" << endl;
	else if(a > b && b != 1 || a == 1) cout << "Alice" << endl;
	else cout << "Bob" << endl;
	
	return 0;
}

Measured memory_bytes: 256
//abc142_e.cpp
//Sat Oct 26 17:46:17 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	P key[m];
	for (int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		key[i] = P(a,0);
		for (int j=0;j<b;j++){
			int c;
			cin >> c;
			c--;
			key[i].second += 1<<c;
		}
	}

	int dp[1<<n][m+1];
	for (int i=0;i<m+1;i++){
		for (int j=0;j<1<<n;j++){
			dp[j][i] = INTINF;
		}
	}

	dp[0][0] = 0;
	for (int i=0;i<m;i++){
		for (int j=0;j<1<<n;j++){
			dp[j][i+1] = min(dp[j][i],dp[j][i+1]);
			int nextj = j|key[i].second;
			if (j==nextj || dp[j][i]==INTINF) continue;
			dp[nextj][i+1]=min(dp[nextj][i+1],dp[j][i]+key[i].first);
		}
	}

	if (dp[(1<<n)-1][m]==INTINF){
		cout << -1 << endl;
	}else {
		cout << dp[(1<<n)-1][m] << endl;
	}
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 16256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int c[27];
int s[366][27];
int last[27];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int D;
    cin >> D;
    for(int i = 1; i <= 26; ++i) cin >> c[i];
    for(int i = 1; i <= D; ++i){
        for(int j = 1; j <= 26; ++j){
            cin >> s[i][j];
        }
    }
    ll score = 0;
    for(int d = 1; d <= D; ++d){
        int t;
        cin >> t;
        score += s[d][t];
        last[t] = d;
        for(int i = 1; i <= 26; ++i){
            score -= c[i] * (d - last[i]);
        }
        cout << score << endl;
    }
    return 0;
}


Measured memory_bytes: 3672
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define int long long
#define ll long long
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
#ifdef int
constexpr int INF = LLONG_MAX / 10;
#else
constexpr int INF = INT_MAX / 10;
#endif
constexpr double eps = 1e-9;
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
using namespace std;
inline ll gcd(ll a, ll b) {
	while (b) {
		ll c = a;
		a = b; b = c % b;
	}
	return a;
}
inline ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
bool isprime(ll n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
ll mypow(ll a, ll b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	int memo = mypow(a, b >> 1);
	return memo * memo;
}
int n, m, a[110];
signed main() {
	cin >> n >> m;
	int oddcount = 0;
	rep(i, m) {
		cin >> a[i];
		if (a[i] & 1)oddcount++;
	}
	if (m == 1) {
		if (a[0] == 1) {
			cout << 1 << endl << 1 << endl << 1 << endl;
			return 0;
		}
		cout << a[0] << endl;
		cout << 2 << endl;
		cout << a[0] - 1 << " " << 1 << endl;
		return 0;
	}
	if (oddcount >= 3) {
		puts("Impossible");
		return 0;
	}
	if (oddcount == 2 && (n & 1)) {
		puts("Impossible");
		return 0;
	}
	if (oddcount == 2 && m == 2) {
		cout << a[0] << " " << a[1] << endl;
		cout << (a[0] + a[1]) / 2 << endl;
		rep(i, (a[0] + a[1]) / 2 - 1)cout << 2 << " ";
		cout << 2 << endl;
		return 0;
	}
	REP(i, m - 1) {
		if (a[i] & 1) {
			if (a[0] & 1) {
				swap(a[i], a[m - 1]);
				break;
			}
			swap(a[0], a[i]);
		}
	}
	mt19937_64 mt;
	if (oddcount == 0)shuffle(a, a + m, mt);
	if (oddcount == 1)shuffle(a + 1, a + m, mt);
	if (oddcount == 2 && m >= 3)shuffle(a + 1, a + m - 1, mt);
	vector<int> b;
	rep(i, m - 1) {
		if (i == 0) {
			b.push_back(a[i] + a[i + 1] - 1);
		}
		else b.push_back(a[i + 1]);
	}
	rep(i, m - 1)cout << a[i] << " ";
	cout << a[m - 1] << endl;
	cout << b.size() << endl;
	rep(i, b.size() - 1)cout << b[i] << " ";
	cout << b.back() + 1 << endl;
	return 0;
}

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

int main(){
    long long n;
    scanf("%lld",&n);
   long long  a[n];
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    long long max=a[0];
    long long sum=0;
    for(int i=1;i<n;i++){
        if(a[i]<max){
            sum=sum+(max-a[i]);
        }
        else{
            max=a[i];
        }
    }

    printf("%lld",sum);

}

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


#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
  Bint N;
  
  cin >> N;
  
  if(N%9 ==0){
  	cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 3736
S = input()

H = []
M = []
for i in range(len(S)):
    if i % 2 == 0:
        H.append('0')
        M.append('1')
    else:
        H.append('1')
        M.append('0')

count1 = 0
for i in range(len(S)):
    if S[i] != H[i]:
        count1 += 1
count2 = 0
for i in range(len(S)):
    if S[i] != M[i]:
        count2 += 1

ans = min(count1,count2)
print(ans)

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

using namespace std;

int g1[81][81];
int g2[81][81];
bool dp[81][81][6480];


int main() {
	int H, W;
	cin>>H>>W;
	for (int i = 0;i < H;++i) {
		for (int j = 0;j < W;++j) {
			cin>>g1[i][j];
		}
	}
	
	for (int i = 0;i < H;++i) {
		for (int j = 0;j < W;++j) {
			cin>>g2[i][j];
		}
	}
	
	dp[0][0][abs(g1[0][0] - g2[0][0])] = true;

	for (int i = 0;i < H;++i) {
		for (int j = 0;j < W;++j) {
			for (int k = 0;k < 6400;++k) {
				if (dp[i][j][k]) {
					dp[i][j+1][abs(k - abs(g1[i][j+1] - g2[i][j+1]))] = true;
					dp[i][j+1][abs(k + abs(g1[i][j+1] - g2[i][j+1]))] = true;
					dp[i+1][j][abs(k - abs(g1[i+1][j] - g2[i+1][j]))] = true;
					dp[i+1][j][abs(k + abs(g1[i+1][j] - g2[i+1][j]))] = true;
				}
			}
		}
	}
	
	for (int i = 0;i < 6400;++i) {
		if (dp[H-1][W-1][i]) {
			cout<<i<<endl;
			break;
		}
	}
	
	return 0;
}


Measured memory_bytes: 41728
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String ox = sc.next();
        int x_count = 0;
        
        for(int i = 0; i < ox.length(); i++){
            char c = ox.charAt(i);
            if(c == 'x'){
                x_count++;
            }
        }
        if(x_count<=7){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
const int mod=1e9+7;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int fac[N],inv[N],ifac[N];
void init() {
    const int n=1e6+5;
    fac[0]=1;for(int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
    inv[1]=1;for(int i=2;i<=n;i++) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
    ifac[0]=1;for(int i=1;i<=n;i++) ifac[i]=1ll*ifac[i-1]*inv[i]%mod;
}
int n;
int C(int n,int m) {
    if(n<0||m<0||n<m) return 0;
    return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int Calc(int s) {
    return (C(n-1,s)-C(s-1,n-s-1)+mod)%mod;
}
int calc(int s) {
    return 1ll*Calc(s)*fac[s]%mod*fac[n-1-s]%mod;
}
int main() {
    init(),n=gi();
    int ans=0;
    for(int i=0;i<n-1;i++) ans=(ans+calc(i))%mod;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int taka=0,aoki=0;
    while(a>0){
        a-=d;
        aoki++;
    }
    while(c>0){
        c-=b;
        taka++;
    }
    if(taka>aoki)cout<<"No";
    else cout<<"Yes";
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
double pi = acos(-1);
int main()
{
    double d,ans;
    double m,h,a,b;
    while(cin>>a>>b>>h>>m){

        h = (h*30) + ( m/2);
        m= m*6;
        ans = min( fabs(h-m), 360 - fabs(h-m));
        d= (ans*pi)/180;
        double c = (a*a) + ( b*b) - 2*a*b*cos(d);
        c= sqrt(c);
        cout<<setprecision(20)<<c<<endl;

    }

    return 0;
}


Measured memory_bytes: 4260
from collections import deque

N = int(input())

depth = [""] * N

lis = [0] * N

dic = {}

for i in range(N-1):

    a,b,c = map(int,input().split())

    a -= 1
    b -= 1

    if a not in dic:
        dic[a] = []
    if b not in dic:
        dic[b] = []

    dic[a].append([b,c])
    dic[b].append([a,c])

Q,K = map(int,input().split())
K -= 1

queue = deque([])
queue.append(K)
depth[K] = 0

while len(queue) > 0:

    now = queue.pop()

    if now not in dic:
        continue

    for bc in dic[now]:

        b = bc[0]
        c = bc[1]
        
        if depth[b] != "":
            continue

        depth[b] = depth[now] + 1
        lis[b] = lis[now] + c
        queue.append(b)

for i in range(Q):

    x,y = map(int,input().split())

    x -= 1
    y -= 1

    print (lis[x] + lis[y])


Measured memory_bytes: 61132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#define pi 3.14159265358979323846264338327950

int main() {
	int N, M, C; std::cin >> N >> M >> C;
	int count{ 0 };
	std::vector<int> B(M);
	for (auto& r : B) std::cin >> r;
	std::vector<std::vector<int>> A(N, std::vector<int>(M));
	for (int i = 0; i < N; ++i) {
		int sum = 0;
		for (int j = 0; j < M; ++j) {
			std::cin >> A[i][j];
			sum += A[i][j] * B[j];
		}
		if (sum + C > 0)
			++count;
	}
	std::cout << count << std::endl;

	return 0;
}

Measured memory_bytes: 3628
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let h: usize = read();
    let w: usize = read();
    let mut magic: Vec<Vec<usize>> = (0..10).map(|_| (0..10).map(|_| read()).collect()).collect();
    let a: Vec<Vec<i32>> = (0..w).map(|_| (0..h).map(|_| read()).collect()).collect();

    for k in 0..10 {
        for i in 0..10 {
            for j in 0..10 {
                magic[i][j] = std::cmp::min(magic[i][j], magic[i][k] + magic[k][j]);
            }
        }
    }

    let mut ans = 0;
    for i in 0..w {
        for j in 0..h {
            if a[i][j] != -1 {
                ans += magic[a[i][j] as usize][1];
            }
        }
    }

    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

void show(int arr[], int N){
	for(int i=0; i<N; i++)
		if(i<N-1)
			cout<<arr[i]<<' '<<flush;
		else
			cout<<arr[i]<<flush;
	cout<<endl;
}


void swap(int& a, int& b){
	int t=a;
	a=b;
	b=t;
}


int ShellSort(int* arr, int N);
int InsertionSort_r(int* arr, int N, int r);

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

	int* arr= new int[N];

	for(int i=0; i<N; i++)
		cin>>arr[i];

	int count=ShellSort(arr, N);

	cout<<count<<endl;

	for( int i=0; i<N; i++)
		cout<<arr[i]<<endl;

	delete[] arr;
}


int ShellSort(int* arr, int N)
{
	int counter=0;


	vector<int> range;

	for( int i=1; i<=N; i= i*3 +1 )
		range.push_back(i);






	
	cout<<range.size()<<endl;

	for( int i=range.size() -1; i >=0; i-- )
		cout<<range[ i ]<<' '<<flush;
	cout<<endl;







	 

	for( int i=range.size() -1; i>=0; i-- ) 
		counter=InsertionSort_r(arr, N, range[ i ]);
	
	return counter;

	
	



	
}

int InsertionSort_r(int arr[], int N, int r)
{

	static int counter=0;
	int compindex;
	int comp;
	int j;

	
	for( int i=0; i<r; i++) {


		for( int compindex=N- r -1 -i ; compindex> -1; compindex-=r ){
			
			comp=arr[compindex];
			j=r;
			for( ; compindex+j<N; j+=r ){

				if(comp > arr[compindex+j]){
					arr[compindex + j -r] = arr[compindex + j];
					counter++;
				}
				else
					break;
				
			}
			arr[compindex + j - r] = comp;

		


		}
	}
	return counter;
}
/* ?§£??????????????????????????????
	  o x x o x x x *
	  o x x o x x o *
	  x o x x o x x
	  x x o x x o x
  ??¨???????????????????????????????????????????????§???
  	  o x x o x x x *
	  x o x x o x x
	  x x o x x o x
	  o x x o x x o *
?????¨?????????????§£?????????
????????????????????¨????????????????????????(0.2?§????????§£?????????????????????????)
   
int InsertionSort_r(int arr[], int N, int r)
{
	static int cnt=0;
	bool changed=false;
	for( int compindex=r; compindex<N; compindex++) {

		int comp= arr[compindex];

		int j=compindex - r;

		for( ; j>=0; j-=r ) {
			if(arr[j] > comp){
				arr[ j+r ]=arr[j];
				cnt++;
				changed=true;
			}
			else
				break;
		}

		arr[ j+r ] =comp;


		changed=false;
	}
	return cnt;
}
*/

Measured memory_bytes: 4896
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;

long long x[105];

int main()
{
    long long n;
    cin>>n;
    for(long long i=1;i<=n;i++){
        cin>>x[i];
    }

    sort(x+1,x+1+n);

    long long ans=pow(10,16),tmp=0;
    for(long long i=x[1];i<=x[n];i++){
        tmp=0;
        for(int j=1;j<=n;j++){
            tmp+=pow(x[j]-i,2);
        }
        ans=min(ans,tmp);
    }


    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
@N=1..<>;/ .* /,$_[$`][$&]=$_[$&][$`]=$' for@M=<>;for$m(@N){for$x(@N){$_[$x][$_]=($%=$_[$x][$_]||1e9)<($==($_[$x][$m]||1e9)+($_[$m][$_]||1e9))?$%:$=for@N}}/ .* /,$\+=$_[$`][$&]<$' for@M;print

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<set>
#define N 100000
#define IOS ios::sync_with_stdio(false)
#define INF 1e9
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
using namespace std;
int abs(int x)
{return x>0?x:-x;}
int sqr(int x)
{return x*x;}
//coding......
ll a[100];
void db()
{
    a[0]=2;
    a[1]=1;
    for (int i=2;i<=86;i++)
        a[i]=a[i-1]+a[i-2];
}
int main()
{
    IOS;
   int n;
  scanf("%d",&n);
   db();
 printf("%lld\n",a[n]);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int K;
  cin >> N >> K;
  int min = 1;
  for(int i = 0; i < N; i++ ) {
    if (min < K)
      min *= 2;
    else
      min += K;
  }
  cout << min << endl;
}

Measured memory_bytes: 256
a,b,k = map(int, input().split())

l1=[]
l2=[]
for i in range(1,a+1):
    if a%i ==0:
        l1.append(i)

for i in range(1,b+1):
    if b%i ==0:
        l2.append(i)

l1 = set(l1)
l2 = set(l2)

l = sorted(l1 & l2, reverse=True)
print(l[k-1])

Measured memory_bytes: 3064
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U>
inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U>
inline void cmin(T& a, U b) { if (a > b) a = b; }

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;

constexpr char el = '\n';

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U>& p) {
  os << p.first << " " << p.second;
  return os;
}
template<typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template<typename T>
ostream &operator<<(ostream &os, const vector< T > &v) {
  rep(i, v.size())
    os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T>
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}
#line 2 "e.cpp"

int main() {
  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vl p(a), q(b), r(c);
  cin >> p >> q >> r;

  priority_queue<ll, vl, greater<>> pq;
  priority_queue<ll> pqr;

  sort(all(p));
  reverse(all(p));
  sort(all(q));
  reverse(all(q));

  rep(i, x) {
    pq.push(p[i]);
  }
  rep(i, y) {
    pq.push(q[i]);
  }

  for (auto&& i : r) {
    pqr.push(i);
  }

  while (pqr.size() and pq.top() < pqr.top()) {
    pq.pop();

    pq.push(pqr.top());
    pqr.pop();
  }

  ll ans = 0;
  while (pq.size()) {
    ans += pq.top();
    pq.pop();
  }

  cout << ans << endl;
}


Measured memory_bytes: 5872
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, k, a[N], b[N];
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	while (k--) {
		for (int i = 1; i <= n; i++) b[i] = 0;
		for (int i = 1; i <= n; i++) {
			b[max(1, i - a[i])]++;
			if (i + a[i] <= n - 1) b[i + a[i] + 1]--;
		}
		for (int i = 1; i <= n; i++) b[i] += b[i - 1], a[i] = b[i];
		int flag = 1;
		for (int i = 1; i <= n; i++) {
			if (a[i] != n) {
				flag = 0;
				break;
			}
		}
		if (flag) break;
	}
	for (int i = 1; i <= n; i++) printf("%d ", a[i]);
	return 0;
}

Measured memory_bytes: 5372
# https://atcoder.jp/contests/abc154/tasks/abc154_d
import numpy as np
N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))
p = (p + 1) / 2
cumsum = np.cumsum(np.array(p))
tmp = np.pad(cumsum[:-K], [K, 0], 'constant')
print((cumsum - tmp).max())


Measured memory_bytes: 33728
import sys
input = sys.stdin.readline

INF=float('inf')
n, k = map(int,input().split())
h = list(map(int, input().split()))
dp=[0]+[INF]*(n-1)
for i in range(1,n):
    for j in range(1,min(i+1,k+1)):
        dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[-1])


Measured memory_bytes: 55132
while True:
    s1 = input()
    if s1 == '.':
        break
    s2 = input()

    if s1 == s2:
        print("IDENTICAL")
        continue

    s2 = s2.split('"')
    s1 = s1.split('"')
    # print(s1)
    # print(s2)
    count = 0
    isTmp = False
    if s1[0] == '"' and s2[0] == '"':
        isTmp = True

    hoge = True
    for i in range(len(s1)):
        if len(s1) != len(s2):
            print("DIFFERENT")
            hoge = False
            break
        if count > 1:
            print("DIFFERENT")
            hoge = False
            break

        if not isTmp:
            if i % 2 == 0:
                if s1[i] != s2[i]:
                    print("DIFFERENT");
                    hoge = False
                    break
            if i % 2 == 1:
                if s1[i] != s2[i]:
                    count += 1
        else:
            if i+1 % 2 == 0:
                if s1[i] != s2[i]:
                    print("DIFFERENT");
                    hoge = False
                    break
            if i+1 % 2 == 1:
                if s1[i] != s2[i]:
                    count += 1

    if count == 1 and hoge:
        print("CLOSE")



Measured memory_bytes: 5584
n, m = map(int,input().split())
par=[i for i in range(n)]
ws =[0 for _ in range(n)]

def root(x):
    if par[x]==x:
        return x
    else:
        r =root(par[x])
        ws[x] +=ws[par[x]]
        par[x]=r
        return par[x]

def weight(x):
    root(x)
    return ws[x]
def diff(x,y):
    return weight(x) -weight(y)

def merge(x,y,w):
    if root(x)==root(y):
        if diff(x,y)!=w:
            print('No')
            exit()
        else:
            return
    else:
        wy=weight(y)
        wx=weight(x)
        x=root(x)
        y=root(y)
        if w+wy>=wx:
            
            par[x]=y
            ws[x]=w+wy-wx
        else:
            par[y]=x
            ws[y]=wx-w-wy

for _ in range(m):
    x,y,z= map(int,input().split())
    x -=1
    y -=1
    merge(x,y,z)

print('Yes')

Measured memory_bytes: 9108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] a = new int[n];
		StringTokenizer st = new StringTokenizer(reader.readLine());
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}
		int q = Integer.parseInt(reader.readLine());
		st = new StringTokenizer(reader.readLine());
		for (int i = 0; i < q; i++) {
			if (subsetSum(n, Integer.parseInt(st.nextToken()), a)) {
				System.out.println("yes");
			} else {
				System.out.println("no");
			}
		}
		reader.close();
	}

	private boolean subsetSum(int n, int s, int[] a) {
		int[][] dp = new int[n+1][s+1];
		for (int i = 0; i < n; i++) {
			int v = a[i];
			for (int j = 0; j <= s; j++) {
				if (v == j || (v < j && dp[i][j-v] > 0)) {
					dp[i+1][j] = dp[i][j] + 1;
				} else  {
					dp[i+1][j] = dp[i][j];
				}
			}
		}
		return dp[n][s] > 0;
	}
}


Measured memory_bytes: 41776
n = int(input())
ans = n
l9 = [9**i for i in range(6,0,-1)]
l6 = [6**i for i in range(7,-1,-1)]
for i in range(n//9+1):
  x9 = i*9
  x61= n-x9
  csum = 0
  for x in l9:
    csum += x9//x
    x9 %= x
  for x in l6:
    csum += x61//x
    x61 %= x
  if ans > csum:
    ans = csum
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 2001
#define NN (N*N)
ll inv[NN], fact[NN], ifact[NN];
ll n, k;
ll dp[N][N];

void init_fact(ll n = NN){
    inv[1] = 1;
    for(int i = 2; i < n;i++) inv[i] = inv[mod%i] * (mod - mod/i) % mod;
	fact[0] = ifact[0] = 1;
	for(int i = 1; i < n; i++){
		fact[i] = (fact[i-1]*i)%mod;
		ifact[i]=(ifact[i-1]*inv[i])%mod;
	}
}

ll comb(ll a, ll b){
	return fact[a+b]*ifact[a]%mod*ifact[b]%mod;
}

int main(){
	init_fact();
	cin>>n>>k;
	if(k==1){
		cout<<1<<endl;
		return 0;
	}
	fill(dp[0], dp[0]+N, fact[n]);
	for(int i = 1; i <= n; i++){
		for(int j = i; j <= n; j++){
			dp[i][j]=(dp[i][j-1]+dp[i-1][j]*comb(k-2, (n-i)*k+i-j))%mod;
		}
	}
	cout<<dp[n][n]<<endl;
	return 0;
}

Measured memory_bytes: 116736
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    s = input()[:-1].decode()

    ans = ''

    for si in s:
        ans += chr(ord('A') + (ord(si) - ord('A') + n) % 26)

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	string a,b; cin >> a >> b;
	int res = 0;
	forn(i,0,(int)a.size()){
		res += (a[i] != b[i]);
	}
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Measured memory_bytes: 3816
import Control.Monad (foldM, replicateM_)
import Data.Maybe (isJust)

main = do
    n <- readLn
    replicateM_ n (input >>= return . solve >>= output)

input :: IO [Int]
input = (map read . words) `fmap` getLine

output :: Bool -> IO ()
output b = putStrLn $ if b then "YES" else "NO"

solve :: [Int] -> Bool
solve = isJust . foldM push (0,0)
    where
    push (a,b) c
        | a < c = Just (c, b)
        | b < c = Just (a, c)
        | otherwise = Nothing

Measured memory_bytes: 4144
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  vector<int> abc(3);
  cin >> abc[0] >> abc[1] >> abc[2];

  int ans = 0;
  while (!(abc[0] == abc[1] && abc[1] == abc[2])) {
    sort(abc.begin(), abc.end());
    if (abc[0] == abc[1]) {
      abc[0]++;
      abc[1]++;
    }
    else {
      abc[0] += 2;
    }
    ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
"use strict"

const main = (input) => {
    input = input.split(" ");
    const N = Number(input[0]);
    const L = Number(input[1]);

    const tastes = [];
    for (let i = 1; i <= N; i++) {
        const taste = L + i - 1;
        tastes.push(taste);
    }

    const absTastes = tastes.map(taste => Math.abs(taste));
    const minAbsTaste = Math.min(...absTastes);

    const allTastes = tastes.reduce((sum, taste) => sum + taste);

    if (allTastes > 0) {
        const ans = allTastes - minAbsTaste;
        console.log(ans);
    } else {
        const ans = allTastes + minAbsTaste;
        console.log(ans);
    }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
from itertools import product

S=input()
n=len(S) #9文字

answer=0
for _l in product([0,1], repeat=n-1): #8個
  #print(_l)
  __l = [0] + list(filter(lambda x:_l[x-1], range(1,n))) + [n] #0,1,2,3,4,5,6,7
  #print(__l)
  answer += sum([int(S[__l[i]:__l[i+1]]) for i in range(len(__l)-1)])
  
print(answer)

Measured memory_bytes: 3060
#include <stdio.h>
#include <limits.h>

typedef long long ll;

int a[2005];
int b[2005];
ll c[2005];
ll dist[1005];
int negative[1005];

int main(){

	int N,M;

	scanf("%d %d",&N,&M);

	int i,j;

	for(i=0;i<M;i++){
		scanf("%d %d %lld",&a[i],&b[i],&c[i]);
		a[i]--;
		b[i]--;
		c[i]=-c[i];
	}

	for(i=0;i<N;i++){
		dist[i]=LLONG_MAX;
	}
	dist[0]=0ll;

	for(i=0;i<N;i++){
		for(j=0;j<M;j++){
			if(dist[a[j]]==LLONG_MAX){continue;}
			if(dist[b[j]]>dist[a[j]]+c[j]){
				dist[b[j]]=dist[a[j]]+c[j];
			}
		}
	}

	ll ans=dist[N-1];

	for(i=0;i<N;i++){
		for(j=0;j<M;j++){
			if(dist[a[j]]==LLONG_MAX){continue;}
			if(dist[b[j]]>dist[a[j]]+c[j]){
				dist[b[j]]=dist[a[j]]+c[j];
				negative[b[j]]=1;
			}
			if(negative[a[j]]==1){
				negative[b[j]]=1;
			}
		}
	}

	if(negative[N-1]==1){
	printf("inf\n");
	}
	else{
	printf("%lld\n",-ans);
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

//  さいころ定義構造体
typedef struct {
    int label[6];   //  各面の数
    int num;        //  上面の数
    char dir;       //  上面の向き
} Dice;

//  面の数からラベル番号を取得
int getlabel(Dice *dice, int num)
{
    int i;
    for ( i = 0; i < 6; i++ ) {
        if ( num == dice->label[i] ) {
            break;
        }
    }

    return i;
}

//  上面、全面の情報から右面の数を取得
int getright(Dice *dice, int upper, int front)
{
    int up;
    int fr;
    int ret;

    up = getlabel(dice, upper);
    fr = getlabel(dice, front);

    if ( up == 0 ) {
        if ( fr == 1 ) {
            ret = dice->label[2];
        } else if ( fr == 4 ) {
            ret = dice->label[3];
        } else if ( fr == 3 ) {
            ret = dice->label[1];
        } else {
            ret = dice->label[4];
        }
    } else if ( up == 1 ) {
        if ( fr == 5 ) {
            ret = dice->label[2];
        } else if ( fr == 0 ) {
            ret = dice->label[3];
        } else if ( fr == 3 ) {
            ret = dice->label[5];
        } else {
            ret = dice->label[0];
        }
    } else if ( up == 2 ) {
        if ( fr == 5 ) {
            ret = dice->label[4];
        } else if ( fr == 0 ) {
            ret = dice->label[1];
        } else if ( fr == 1 ) {
            ret = dice->label[5];
        } else {
            ret = dice->label[0];
        }
    } else if ( up == 3 ) {
        if ( fr == 5 ) {
            ret = dice->label[1];
        } else if ( fr == 0 ) {
            ret = dice->label[4];
        } else if ( fr == 4 ) {
            ret = dice->label[5];
        } else {
            ret = dice->label[0];
        }
    } else if ( up == 4 ) {
        if ( fr == 5 ) {
            ret = dice->label[3];
        } else if ( fr == 0 ) {
            ret = dice->label[2];
        } else if ( fr == 2 ) {
            ret = dice->label[5];
        } else {
            ret = dice->label[0];
        }
    } else {
        if ( fr == 4 ) {
            ret = dice->label[2];
        } else if ( fr == 1 ) {
            ret = dice->label[3];
        } else if ( fr == 3 ) {
            ret = dice->label[4];
        } else {
            ret = dice->label[1];
        }
    }

    return ret;
}

int main(void)
{
    Dice dice;
    int q;
    int upper;
    int front;
    int right;

    //  さいころの初期化
    for ( int i = 0; i < 6; i++ ) {
        scanf("%d", &dice.label[i]);
    }

    //  質問数を取得
    scanf("%d", &q);

    //  上面、前面の数を取得し、右面を出力
    for ( int i = 0; i < q; i++ ) {
        scanf("%d %d", &upper, &front);
        right = getright(&dice, upper, front);
        printf("%d\n", right);
    }

    return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void) {
    char a;
    cin >> a;
    if(isupper(a)) {
        cout << "A" << endl;
    } else {
        cout << "a" << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
X, Y = gets.split.map(&:to_i)

G = [[1, 3, 5, 7, 8, 10, 12], [4, 6, 9, 11], [2]]
puts G.index{|a| a.member?(X)} == G.index{|a| a.member?(Y)} ? 'Yes' : 'No'

Measured memory_bytes: 1788
#include<stdio.h>

int main(void) {

	int x;
	int a, b, c, d, e, f;
	int tmp;  
	
	scanf("%d", &x);

	for (a = 0; a <= (x/100); a++) {
		for (b = 0; b <= (x/100); b++) {
			for (c = 0; c <= (x / 100); c++) {
				for (d = 0; d <= (x / 100); d++) {
					for (e = 0; e <= (x / 100); e++) {
						for (f = 0; f <= (x / 100); f++) {
							tmp = 100*a + 101*b + 102*c + 103*d + 104*e + 105*f;
							if (tmp == x) {
								printf("1\n");
								return 0;
							}
						}
					}
				}
			}
		}
	}
	
	printf("0\n");

	return 0;
}

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

int main(){
	int c[3][3];
	bool flag = true;
	for (int i = 0; i < 3; i++){
		for (int j = 0; j < 3; j++){
			cin >> c[i][j];
		}
	}
	/*c00-c01==c10-c11 以下同じ*/
	for (int i = 0; i < 2; i++){
		if (c[0][i] - c[0][i + 1] != c[1][i] - c[1][i + 1] || c[1][i] - c[1][i + 1] != c[2][i] - c[2][i + 1]){
			flag = false;
		}
		if (c[i][0] - c[i + 1][0] != c[i][1] - c[i + 1][1] || c[i][1] - c[i + 1][1] != c[i][2] - c[i + 1][2]){
			flag = false;
		}
	}
	if (flag){
		cout << "Yes" << endl;
		return 0;
	}
	else{
		cout << "No" << endl;
		return 0;
	}
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
X = list(map(int, input().split()))

ans = 0
for i in range(N - 1) :
    if (X[i + 1] - X[i]) * A < B :
        ans += (X[i + 1] - X[i]) * A
    else :
        ans += B

print(ans)

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);
	cout.tie(0);
 	
 	int t=1;
 	//cin>>t;
 	while(t--)
 	{
 		int n,k;cin>>n>>k;
 		int r,p,s;cin>>r>>s>>p;
 		string a;cin>>a;

 		string as;
 		for(int i=0;i<n;i++)
 		{
 			if(a[i]=='r') as.push_back('p');
 			else if(a[i]=='p') as.push_back('s');
 			else as.push_back('r');
 		}
 		vector<pair<int,char>> v;
 		v.push_back({r,'r'});
 		v.push_back({p,'p'});
 		v.push_back({s,'s'});
 		sort(v.begin(),v.end());

 		for(int i=0;i<3;i++)
 		{
 			for(int j=0;j<n-k;j++)
 			{
 				if(as[j+k] == as [j] and v[i].second == as[j] and as[j+k] != a[j])
 					as[j+k] = a[j];
 				//else if(as[j+k] == as [j] and v[i].second == as[j] and as[j] != a[j])
 				//{
 					///cout<<"DFg";
 					//as[j] = a[j];
 				//}
 			}
 		}
 		//cout<<as;
 		long long int ans=0;
 		for(int i=0;i<n;i++)
 		{
 			if(as[i] != a[i])
 			{
 				if(as[i] == 'r') ans+=r;
 				else if(as[i] == 'p') ans+=p;
 				else if(as[i] == 's') ans+=s;
 			}
 		}
 		cout<<ans<<endl;
 	}	
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
const int INF = 1e9;
const llint llINF = 1e18;

int main () {
    vint n(4);
    rep(i, 4) cin >> n[i];
    sort(all(n));
    if (n[0] == 1 &&n[1] == 4 &&n[2] == 7 &&n[3] == 9){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
    char ch;
    while (true) {
        scanf("%c", &ch);
        if (isupper(ch)) {
            ch = tolower(ch);
        } else if (islower(ch)) {
            ch = toupper(ch);
        }
        printf("%c", ch);
        if (ch == '\n') {
            break;
        }
    }
}

Measured memory_bytes: 1100