akhauriyash/Code-Regression huggingface dataset:
def f(x):
    if x%4 == 0:
        return x
    if x%4 == 1:
        return 1
    if x%4 == 2:
        return x + 1
    else:
        return 0

A, B = map(int, input().split())

ans = 0
if A == 0:
    ans = f(B)
else:
    ans = f(A - 1) ^ f(B)

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;
//|\_
//g++ -std=c++1z temp.cpp
//./a.out

int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    /* int n,x,i;
    cin>>n>>x;
    int l[n];
    rep(i,n)cin>>l[i];
    int ans=0,place=0;
    rep(i,n){
        if(x>=place)ans++;
        place+=l[i];
    }
    fin(ans);
    int x,a;
    cin>>x>>a;*/
    int a,x;
    cin>>x>>a;
    if(a<=x)fin(10);
    else fin(0);
//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long int
#define INF 210000000
using namespace std;
int main(void)
{
	int i,j,k,n,m,cost,time,a,b,wrc[100][100],wrt[100][100];
	while(1) {
		cin>>n>>m;
		if(n==0&&m==0) break;
		for(i=0;i<m;i++)for(j=0;j<m;j++) wrc[i][j]=INF,wrt[i][j]=INF;
		for(i=0;i<m;i++) wrc[i][i]=0,wrt[i][i]=0;
		for(i=0;i<n;i++) {
			cin>>a>>b>>cost>>time;
			a--,b--;
			wrc[a][b]=cost,wrc[b][a]=cost;
			wrt[a][b]=time,wrt[b][a]=time;
		}
		for(k=0;k<m;k++)for(i=0;i<m;i++)for(j=0;j<m;j++) {
			wrc[i][j]=min(wrc[i][j],wrc[i][k]+wrc[k][j]);
			wrt[i][j]=min(wrt[i][j],wrt[i][k]+wrt[k][j]);
		}
		int p,r,c,cc;
		cin>>cc;
		for(i=0;i<cc;i++) {
			cin>>p>>r>>c;
			p--,r--;
			if(c==0) cout<<wrc[p][r]<<endl;
			else cout<<wrt[p][r]<<endl;
		}
	}
}

Measured memory_bytes: 3064
N=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()

h=[]
count=0
f=0
for i in a:
 if f==i:
  h.append(i)
  count+=1
  f=0
 else:
   f=i
   if count==2:
       break 
if count==2:
 print(h[0]*h[1])
else:
 print(0)

Measured memory_bytes: 14252
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

using mint = modint998244353;

struct S { mint x; ll size; };
S op(S a, S b) { return S{a.x + b.x, a.size + b.size}; }
S e() { return {0, 0}; }
struct F { mint b, c; };
S mapping(F f, S x) { return S{f.b * x.x + f.c * x.size, x.size}; }
F composition(F f, F g) { return F{f.b * g.b, f.b * g.c + f.c}; }
F id() { return F{1, 0}; }

void solve() {
    ll n, q;
    cin >> n >> q;
    vector<S> a(n);
    rep(i, n) {
        ll _a;
        cin >> _a;
        a[i] = S{mint(_a), 1};
    }
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
    while(q--) {
        ll t, l, r;
        cin >> t >> l >> r;
        if(t == 0) {
            ll b, c;
            cin >> b >> c;
            seg.apply(l, r, F{b, c});
        }
        else cout << seg.prod(l, r).x.val() << endl;
    }
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 31492
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
 
#define LOCAL  1
#define UPLOAD 2
 
#define ll long long
const long long INF = 1LL << 60;
 
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';
 
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

  ll n = input();
  ll x = input();
  ll y = input();

  vector<vector<ll>> d(n+100, vector<ll>(n+100));
  for(ll i=0;i<n;i++){
    for(ll j=i+1;j<n;j++){
      ll num1 = i + 1;
      ll num2 = j + 1;

      bool b1 = num1 <= x && x <= num2;
      bool b2 = num1 <= y && y <= num2;
      bool b3 = x <= num1 && num2 <= y;

      ll dist1 = abs(x - num1) + abs(num2 - y) + 1;
      ll dist2 = j - i;

      if(b1 && b2){
        d[i][j] = dist1;
      }
      else if(b1 || b2 || b3){
        d[i][j] = min(dist1, dist2);
      }
      else{
        d[i][j] = dist2;
      }
    }
  }

  map<ll, ll> ans;
  for(ll i=0;i<n;i++){
    for(ll j=i;j<n;j++){
      // cout << i+1 << "," << j+1 << " : " << d[i][j] << endl;
      ans[d[i][j]]++;
    }
  } 
  
  for(ll i = 1;i<n;i++){
    cout << ans[i] << endl;
  }
 
  return 0;
}


Measured memory_bytes: 34944
#include <bits/stdc++.h>
using namespace std;
// ==================================================
using i64 = int64_t; using u64 = uint64_t;
#define rep(i,a,b) for(i64 i=(int64_t)(a);i<(int64_t)(b);i++)
#define repn(i,n) rep(i,0,n)
#define din(t, ...) t __VA_ARGS__;_din(__VA_ARGS__)
#define v(t,n) vector<t> n
void _din() {} void dout() { cout << endl; }
template <typename T, typename ... Args> inline void _din(T& head, Args& ... rest) { cin >> head; _din(rest...); }
template <typename T, typename ... Args> inline void dout(T head, Args ... rest) { cout << head; if (sizeof...(rest)) cout << ' '; dout(rest...); }
template <typename T>inline void vsortg(vector<T>& v) { sort(v.begin(), v.end(), greater<T>()); }
template <typename T>inline void vsortl(vector<T>& v) { sort(v.begin(), v.end(), less<T>()); }
template <typename T> inline T nmax(T f1, T f2) { return max(f1, f2); }
template <typename T, typename ... Args> inline T nmax(T first, Args ... rest) { return nmax(first, nmax(rest...)); }
template <typename T> inline T nmin(T f1, T f2) { return min(f1, f2); }
template <typename T, typename ... Args> inline T nmin(T first, Args ... rest) { return nmin(first, nmin(rest...)); }
// ==================================================
int main()
{
	v(int, l(3));
	din(, l[0], l[1], l[2]);
	vsortl(l);
	int s = l[0] * l[1] / 2;
	dout(s);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
 
int main() {
 
  int n;
  cin>>n;
 
  vector<int> ai(n);
  for(int i=0;i<n;i++){
    cin>>ai.at(i);
  }
  
  for(int i=n-1;i>=0;i--){
    cout<<ai.at(i);
    if(i==0){
      cout<<endl;    
      break;
    }
    else
      cout<<" ";
  }
  
  return 0;
}


Measured memory_bytes: 3072
#include <stdio.h>

int main(void)
{
	int a, b, tmp;
	while (scanf("%d %d",&a, &b) != EOF) {		
		tmp = a + b;
		if (tmp < 10) {
			printf("1");
		} else if (tmp < 100) {
			printf("2");
		} else if (tmp < 1000) {
			printf("3");
		} else if (tmp < 10000) {
			printf("4");
		} else if (tmp < 100000) {
			printf("5");
		} else if (tmp < 1000000) {
			printf("6");
		} else if (tmp < 10000000) {
			printf("7");
		}
		printf("\n");
		
	}
	return 0;
}

Measured memory_bytes: 572
#include"bits/stdc++.h"

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin >> N;
	vector<int>H(N);
	for (int i = 0; i < N; i++)
	{
		cin >> H[i];
	}
	int ans = 0;
	int cnt = 0;

	for (int i = 1; i < N; i++)
	{
			if (H[i - 1] >= H[i]) {
				cnt++;
			}
			else {
				cnt = 0;
			}
			ans = max(ans, cnt);
	}

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

Measured memory_bytes: 640
/*
 Sarthak Jain
*/
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
int mod=1e9+7;
int min(int a,int b){
  return (a<b)?a:b;
}
int max(int a,int b){
  return (a>b)?a:b;
}
int fp(int a,int b){
  if(b==0) return 1;
  int x=fp(a,b/2);
  x=(x*x)%mod;
  if(b&1) x=(x*a)%mod;
  return x;
}


signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
 double r;
 cin>>r;
 double ans=6.28318530717958623200*r;
 cout<<ans;

}

Measured memory_bytes: 3808
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A[] = new int[3];
		for (int i = 0; i < 3; i++) {
			A[i] = sc.nextInt();
		}

		Arrays.sort(A);

		int sumCost = A[2] - A[0];
		System.out.println(sumCost);

		return;
	}
}


Measured memory_bytes: 22612
#include <iostream>

using namespace std;

int main() {
	long a,b,n,worst=0,d;

	cin >> n;
	for (int i=0;i<n;i++) {
		cin >> a >> b;
		if (a > worst) {
			worst = a;
			d = b;
		}
	}

	cout << worst + d << endl;
	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define f(i,l,h) for(ll i=l;i<h;i++)
#define fr(i,h,l) for(ll i=h;i>=l;i--)

using namespace std;

typedef pair<ll,ll> pll;
const ll INF=(ll)(1e9+7);
typedef vector<ll> vll;



int main()
{
    ll n,a,b,c;
    cin>>n>>a>>b>>c;
    ll sum=a+b+c;
    string s[n];
    f(i,0,n) cin>>s[i];
    vector<char>v;
    if(sum==0){
        cout<<"No"<<endl;
        return 0;
    }
    bool flag=true;
    f(i,0,n){
       if(s[i]=="AB"){
           if((a+b)==0){
                flag=false;
                break;
           }
           if(a==1 && b==1 && sum==2 && (i+1)!=n){
                if(s[i+1]=="BC"){
                    b++;
                    a--;
                    v.pb('B');
                }else{
                    a++;
                    b--;
                    v.pb('A');
                }
                continue;
           }

            if(a<b){
                a++;
                b--;
                v.pb('A');
            }else{
                b++;
                a--;
                v.pb('B');
            }



       }else if(s[i]=="BC"){
            if((b+c)==0){
                flag=false;
                break;
           }
           if(b==1 && c==1 && sum==2 && (i+1)!=n){
                if(s[i+1]=="AB"){
                    b++;
                    c--;
                    v.pb('B');
                }else{
                    c++;
                    b--;
                    v.pb('C');
                }
                continue;
           }

           if(b<c){
                b++;
                c--;
                v.pb('B');
            }else{
                b--;
                c++;
                v.pb('C');
            }

       }else{
           if((a+c)==0){
                flag=false;
                break;
           }

           if(a==1 && c==1 && sum==2 && (i+1)!=n){
                if(s[i+1]=="AB"){
                    a++;
                    c--;
                    v.pb('A');
                }else{
                    c++;
                    a--;
                    v.pb('C');
                }
                continue;
           }

           if(a<c){
                a++;
                c--;
                v.pb('A');
            }else{
                a--;
                c++;
                v.pb('C');
            }
       }

    }

    if(!flag){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
        for(auto u:v){
            cout<<u<<endl;
        }
    }


}


Measured memory_bytes: 6864
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <list>
#define INF 0x3f3f3f3f
#define maxn 105000
#define maxnn 6000
#define juzheng 300
#define line cout << "-------------------------" << endl;
#define PI acos(-1.0)
#define mem(a,b) memset(a,b,sizeof(a))
#define fill_(a,b,n) fill(a,a + n,b)
#define esp 1e-9
 
#define ri(n) scanf("%d",&n)
#define ri2(a,b) scanf("%d %d",&a,&b)
#define ri3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define rd(n) scanf("%lf",&n)
#define rd2(a,b) scanf("%lf %lf",&a,&b)
#define rd3(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define rl(n) scanf("%lld",&n)
#define rl2(a,b) scanf("%lld %lld",&a,&b)
#define rl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define rui(n) scanf("%u",&n)
#define rui2(a,b) scanf("%u %u",&a,&b)
#define rui3(a,b,c) scanf("%u %u %u",&a,&b,&c)
#define rs(str) scanf("%s",str)
#define pr(n) cout << n << endl
#define ll long long
#define int64 __int64
#define ui unsigned int

using namespace std;

const ll mod = 1e9 + 7;

//Date:2018-8-11
//Author：HarryBlackCat

int main() {
	//cin.sync_with_stdio(false);//降低cin，cout时间
	int n;
	while(~ri(n)){
		bool flag = false;
		
		for(int i = 0;i <= n;i += 7){
			for(int j = 0;j <= n;j += 4){
				if(i + j == n){
					flag = true;
					break;
				}
			}
			if(flag)
				break;
		}
		
		if(flag)
			puts("Yes");
		else
			puts("No");
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a > b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a < b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////


int main() {
	ll N; cin >> N;
	ll A[100010];
	REP(i, N)cin >> A[i];
	ll ans = 1;
	ll r = 0;
	ll b = 0;
	ll g = 0;
	for (ll i = 0; i<N; ++i) {
		if (r == A[i] && b == A[i] && g == A[i]) {
			ans *= (ll)3;
			r++;
		}
		else if (r == A[i] && b == A[i]) {
			ans *= (ll)2;
			r++;
		}
		else if (b == A[i] && g == A[i]) {
			ans *= (ll)2;
			b++;
		}
		else if (r == A[i]) {
			r++;
		}
		else if (b == A[i]) {
			b++;
		}
		else if(g==A[i]){
			g++;
		}
		else {
			cout << 0 << endl;
			return 0;
		}
		ans = ans % 1000000007;
	}
	ans %= INF;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,d;
  cin>>n>>d;
  vector<Int> ds(n);
  for(Int i=0;i<n;i++) cin>>ds[i];
  // [0, i)
  vector<Int> ps(n);
  {
    Int cur=d;
    for(Int i=0;i<n;i++){
      ps[i]=cur;
      cur=min(cur,abs(cur-ds[i]));
    }
  }

  // min r s.t. before i
  // [i, n)
  vector<Int> rs(n+1);
  rs[n]=1;
  for(Int i=n-1;i>=0;i--){
    rs[i]=rs[i+1]+ds[i];
    if(abs(rs[i+1]-ds[i])>=rs[i+1])
      chmin(rs[i],rs[i+1]);
  }

  Int q;
  cin>>q;
  vector<Int> qs(q);
  for(Int i=0;i<q;i++){
    cin>>qs[i],qs[i]--;
    // cout<<rs[qs[i]+1]<<" "<<ps[qs[i]]<<":";
    cout<<(rs[qs[i]+1]<=ps[qs[i]]?"YES":"NO")<<endl;
  }
  return 0;
}


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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



int main(){
    int h,w;
    cin >> h >> w;
    char a[h][w];

    rep(i,h){
        rep(j,w){
            cin >> a[i][j];
        }
    }

    for(int i=0;i<w+2;i++){
        cout << '#';
    }
    cout << endl;


    for(int i=0;i<h;i++){
        cout << '#';
        for(int j=0;j<w;j++){
            cout << a[i][j];
        }
        cout << '#' << endl;
    }



    for(int i=0;i<w+2;i++){
        cout << '#';
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	ll N,K;
	cin >> N >> K;
	long long ans = 0;
	for(ll b=1;b<=N;b++){
		ans += max((ll)0,b-K)*(N/b) + max((ll)0,N%b-K+1);
	}
	if(K==0)ans = N*N;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n, b, f, r, v;
    int room[4][3][10];
    for(int i=0; i<4; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<10; k++){
                room[i][j][k] =0;
            }
        }
    }
    
    cin>>n;
    for(int num=0; num<n; num++){
        cin >> b >> f >> r >> v;
        room[b-1][f-1][r-1] += v;
    }
    
    for(int i=0; i<4; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<10; k++){
                cout << " " << room[i][j][k];
            }
            cout <<endl;
        }
        if(i!=3) cout<< "####################" <<endl;
    }
    return 0;
}


Measured memory_bytes: 3112
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] L = new int[M];
		int[] R = new int[M];
		for (int i=0;i<M;i++) {
			L[i]=sc.nextInt();
			R[i]=sc.nextInt();
		}
		int l = 0;
		int r = 100001;
		for (int i=0;i<M;i++) {
			l=Math.max(l,L[i]);
			r=Math.min(r,R[i]);
		}
		if (r>=l) {
			System.out.println(r-l+1);
		} else {
			System.out.println(0);
		}
	}
}

Measured memory_bytes: 65344
def resolve():
	n, x = map(int, input().split())
	a = list(map(int, input().split()))
	c = 0
	for i in range(n-1):
		if a[i] + a[i+1] > x:
			st = (a[i] + a[i + 1]) - x
			a[i+1] = a[i+1] - st if a[i+1] > st else 0
			c += st
	print(c)
resolve()

Measured memory_bytes: 63984
#include <bits/stdc++.h>
using namespace std;
const long INF=1000000000000000;

int main() {
    long N;
    cin>>N;
    vector<double> v(N);
    for(int i=0;i<N;i++) cin>>v.at(i);
    
    sort(v.begin(),v.end());
    
    double ans=v.at(0);
    
    for(int i=1;i<N;i++){
        ans=(ans+v.at(i))/2;
    }
    
    cout<<setprecision(15)<<ans<<endl;
}

Measured memory_bytes: 256
n,m=gets.chomp.split(" ").map(&:to_i)

inputs = {}
(0..(n-1)).each do |i|
    a,b=gets.chomp.split(" ").map(&:to_i)
    next if m < a
    if inputs[a]
        inputs[a].push(b)
    else
        inputs[a] = [b]
    end
end

inputs.each do |key, value| 
    inputs[key] = value.sort.reverse()
end

ans = 0
ret = []
(1..m).each do |day|
    if inputs[day]
        bs = inputs[day]
        bs.each do |b|
            index = ret.bsearch_index {|x| x<=b } 
            if index
                break if index >= m -day+1
                ret.insert(index, b)
            else
                ret.push(b)
            end
        end
    end
    ans += ret.shift if ret[0]
end

puts ans



Measured memory_bytes: 20860
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <bitset>

using namespace std;
typedef long long LL;
const int maxn = 6005;

int ehead[maxn],ecnt;
struct edge {
	int u,v,next;
}edg[maxn];
void add(int u,int v) {
	edg[++ecnt]=(edge){u,v,ehead[u]};
	ehead[u]=ecnt;
	edg[++ecnt]=(edge){v,u,ehead[v]};
	ehead[v]=ecnt;
}
int n,a[maxn],ord[maxn],ans;bool f[maxn];
int stk[maxn],top;
bool comp(int x,int y) {return a[x]<a[y];}
int main()
{
	#ifdef Amberframe
		freopen("agc010f.in","r",stdin);
		freopen("agc010f.out","w",stdout);
	#endif
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int u,v,i=1;i<n;i++)
		scanf("%d %d",&u,&v),add(u,v);
	for (int i=1;i<=n;i++) ord[i]=i;
	sort(ord+1,ord+n+1,comp);
	
	for (int i=1;i<=n;i++)
	{
		int u=ord[i];
		for (int v,j=ehead[u];j;j=edg[j].next)
			if (a[v=edg[j].v]<a[u]) f[u]|=!f[v];
		if (f[u]) stk[++top]=u;
	}
	sort(stk+1,stk+top+1);
	for (int i=1;i<=top;i++)
		printf("%d ",stk[i]);
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, l; cin >> n >> l;
  vi a(n);
  REP(i, n) cin >> a[i];
  int pos = -1;
  REP(i, n-1) {
    if(a[i] + a[i+1] >= l) {
      pos = i;
      break;
    }
  }
  if(pos == -1) {
    cout << "Impossible" << endl;
  } else {
    cout << "Possible" << endl;
    REP(i, pos) {
      cout << i+1 << endl;
    }
    RFOR(i, n-2, pos+1) {
      cout << i+1 << endl;
    }
    cout << pos+1 << endl;
  }
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;

template<typename T>inline T get(){T x;cin>>x;return x;}

int main()
{
  int d = get<int>(), g = get<int>();
  vector<int> p(d+1);
  vector<int> c(d+1);
  for (int i = 1; i <= d; i++) {
    p[i] = get<int>();
    c[i] = get<int>();
  }

  int ans = INT_MAX;
  function<void(int,int,int,bool)> recur =
    [&](int i, int acc, int count, bool canPartial)
    {
      // cout << i << ", "
      //      << acc  << ", "
      //      << count << ", "
      //      << canPartial << endl;
      if (acc >= g) {
        ans = min(ans, count);
        //cout << "min=" << ans << endl;
        return;
      } else if (i > d)
        return; // 必要点数に満たず。
      // 全問解く場合。
      recur(i+1, acc + p[i]*i*100 + c[i], count + p[i], canPartial);
      // １問も解かない場合。
      recur(i+1, acc, count, canPartial);
      // 中途半端に解く場合。
      if (canPartial) {
        //cout << "partial" << endl;
        for (int j = 1; j < p[i]; j++) {
          recur(i+1, acc + j*i*100, count + j, false);
        }
      }
    };
  recur(1, 0, 0, true);

  cout << ans << endl;

  return 0;
}

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

int main()
{
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    for (int i = 0; i < N - 2; ++i)
    {
        if ((S[i] == 'A') && (S[i + 1] == 'B') && (S[i + 2] == 'C'))
        {
            ++ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    ll m1=s, m2=d;
    chmin(m1, 4*q);
    chmin(m1, 2*h);
    chmin(m2, 2*s);
    if (2*m1 <= m2) cout << n * m1 << endl;
    else cout << (n/2)*m2 + (n%2)*m1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
	int R[MAX],n;
	
	cin >> n;
    for(int i=0; i<n; i++){
    	cin >> R[i];
    }  
    
    int maxv = R[1] - R[0];
    int minv = R[0];
    
    for(int a=1; a<n; a++){
    	maxv = max(maxv,R[a]-minv);
		minv = min(minv,R[a]); 
    }
    
    cout << maxv << endl;
    return 0;
}

Measured memory_bytes: 3860
#include<stdio.h>
#include<string.h>
    
int main(){
    
    char W[205],TEMP[205];
    int m,i,j,k,h;
    while(1){
        scanf("%s",W);
        if(strcmp(W,"-")==0)break;
        scanf("%d",&m);
        for(i=0;i<205;i++)TEMP[i]='\0';
        for(i=0;i<m;i++){
            scanf("%d",&h);
            strncpy(TEMP,W,h);
            j=0;
            while(W[h+j]!='\0'){
                W[j]=W[h+j];
                j++;
            }
            for(k=0;k<h;k++){
                W[j+k]=TEMP[k];
            }
        }
        printf("%s\n",W);
    }
    return 0;
}


Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
int main() {
  int H,N;
  cin>>H>>N;
  int A[N],sum=0;
  for(int i=0;i<N;i++) {
    cin>>A[i];
    sum+=A[i];
  }
  if(H<=sum) {
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
 
typedef struct{
  char name[10];
  int  time;
} Process;

Process dequeue();
void enqueue(Process);
int calc(int,int);
 
Process Q[100000];
int n,q,head,tail;

int main() {
  /* code */
  Process p;
  int min_time=0;
  int sum_time=0;
  int i;
 
  scanf("%d %d\n",&n,&q);
 
  for(i=1;i<=n;i++){
    scanf("%s %d",Q[i].name,&Q[i].time);
  }
 
  head=1;
  tail=n+1;
 
  while(head!=tail){
    p=dequeue();
    min_time=calc(q,p.time);
    p.time-=min_time;
    sum_time+=min_time;
 
    if(p.time>0){
      enqueue(p);
    }else{
      printf("%s %d\n",p.name,sum_time);
    }
  }
  return 0;
}

Process dequeue(){
  Process x;
  x=Q[head];
  if((head+1)>n+1) head=1;
  else            head++;
  return x;
}
 
void enqueue(Process x){
  Q[tail]=x;
  if((tail+1)==n+2)  tail=1;
  else             tail++;
}
 
int calc(int x,int y){
  if(x>=y) return y;
  else     return x;
}

Measured memory_bytes: 1384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    int h,w,a,b; cin >> h >> w >> a >> b;
    int M[h][w];
    int row[h+1], colom[w+1];
    for(int i = 0; i < h; i++) row[i] = 0;
    for(int i = 0; i < w; i++) colom[i] = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            M[i][j] = 0;
        }
    }

    // if(h == 1) b = 1;
    // if(w == 1) a = 1;

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(i < b && j < a) M[i][j] = 0;
            if(i < b && j >= a) M[i][j] = 1;
            if(i >= b && j < a) M[i][j] = 1;
            if(i >= b && j >= a) M[i][j] = 0;

        }
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cout << M[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 5120
#141 b
ki=["R","U","D"]
gu=["L","U","D"]
s=input()
ans=True
i=1
for c in s:
    if ans==False:
        break
    if i%2==1:
        if c not in ki:
            ans=False
    if i%2==0:
        if c not in gu:
            ans=False
    i+=1
print("Yes" if ans else "No")

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

int main(){
    string s;
    cin >> s;
    vector<bool> d(256, false);
    for(int i=0; i<(int)s.length(); i++){
        d[s[i]] = true;
    }
    if((d['N']&&!d['S']) || (d['S']&&!d['N']) || (d['E']&&!d['W']) || (d['W']&&!d['E'])){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }  
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    Scanner sc = new Scanner(System.in);
    public static void main(String[] args){
        new Main().run();
    }
    void run() {

        int n = sc.nextInt();
        int[][] arr = new int[n][2];
        for (int i=0; i<n; i++) {
            arr[i][0] = sc.nextInt();
            arr[i][1] = sc.nextInt();
        }

        int[] z = new int[n];
        for (int i=0; i<n; i++) z[i] = arr[i][0] + arr[i][1];
        int[] w = new int[n];
        for (int i=0; i<n; i++) w[i] = arr[i][0] - arr[i][1];

        Arrays.sort(z);
        Arrays.sort(w);

        System.out.print(Math.max(z[n-1]-z[0], w[n-1]-w[0]));
    }
}



Measured memory_bytes: 56692
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let x: Vec<i64> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };
    let L: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let Q: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let (a, b): (Vec<usize>, Vec<usize>) = {
        let (mut a, mut b) = (vec![], vec![]);
        for _ in 0..Q {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            a.push(iter.next().unwrap().parse().unwrap());
            b.push(iter.next().unwrap().parse().unwrap());
        }
        (a, b)
    };

    let mut dp = vec![vec![]; N];
    let mut k = 1;
    for i in 0..N {
        while k < N && x[k] - x[i] <= L {
            k += 1;
        }
        dp[i].push(k - 1);
    }
    for j in 1..20 {
        for i in 0..N {
            let l = dp[i][j - 1];
            let x = dp[l][j - 1];
            dp[i].push(x);
        }
    }

    fn f(s: usize, g: usize, dp: &Vec<Vec<usize>>) -> usize {
        if g <= dp[s][0] {
            1
        } else {
            let i = (0..20).find(|&j| g <= dp[s][j]).unwrap() - 1;
            f(dp[s][i], g, dp) + (1 << i)
        }
    }

    let ans = (0..Q).map(|i| {
        let s = std::cmp::min(a[i], b[i]);
        let g = std::cmp::max(a[i], b[i]);
        f(s - 1, g - 1, &dp).to_string()
    }).collect::<Vec<_>>().join("\n");

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

Measured memory_bytes: 41128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a == (b+c)){
    cout << "Yes";
  }else if(b == (a+c)){
    cout << "Yes";
  }else if(c == (a+b)){
    cout << "Yes";
  }else{
    cout << "No";
  }

}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int N;//会員のコンテスト参加回数
    int dispR;//表示レーティング
    int inteR;//内部レーティング
    //入力
    scanf("%d %d",&N,&dispR);

    //エラー排除
    if(N>=1 && N<=100 && dispR>=0 && dispR<=4111){
        //処理
        if(N >= 10){
            inteR = dispR;
        }else{
            inteR = dispR + 100*(10 - N);
        }
    
        //出力
        printf("%d",inteR);
    }
    return 0;
}

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

int main(){
    long long int a,b,k;
    cin>>a>>b>>k;
    long long int x=min(a,k);
    a-=x;
    k-=x;
    b-=min(b,k);
    cout<<a<<" "<<b<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
using namespace std;
using ll =long long;
int main() {
	int N;
	vector<int>A;
	cin >> N;
	int c;
	for (int i = 0; i < N; i++)
	{
		cin >> c;
		A.push_back(c);
		
		if (A[i] % 2 == 0 && (A[i] % 3 != 0 && A[i] % 5 != 0)) {

			cout << "DENIED";
			return 0;
		}
	
	}
	cout << "APPROVED";
	


}

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

    int a,b;
    cin>>a>>b;
    int ans;

    ans=a-2*b;

    if(ans>0)   cout<<ans<<endl;
    else    cout<<0<<endl;

 return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long double lb;

const int INF=1<<27;
const int MOD=(int)1e9+7;

int main(void)
{
    int n;
    int t[100010];
    int x[100010];
    int y[100010];

    cin >> n;
    rep(i,n) cin >> t[i] >> x[i] >> y[i];

    int dt, dx, dy;
    rep(i,n){
        if(i == 0){
            dt = t[i];
            dx = x[i];
            dy = y[i];
        }else{
            dt = t[i] - t[i-1];
            dx = x[i] - x[i-1];
            dy = y[i] - y[i-1];
        }
        dy = abs(dy); dx = abs(dx);
        int d = dx + dy;
        if(dt%2 != d%2 || d > dt){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}



Measured memory_bytes: 1408
def how_many_times_divisible(n):
    ans = 0
    while  n % 2 == 0:
        n = n / 2
        ans += 1
    return ans

n = input()
a = list(map(int,input().split()))

a_divided = list(map(how_many_times_divisible,a))

ans = min(a_divided)

print(ans)


Measured memory_bytes: 2940
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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 main(){
    int n, m; cin >> n >> m;
    vector<ll> A(n); int sum = 0;
    rep(i, n) {cin >> A[i]; sum += A[i];}
    int cnt = 0;
    rep(i, n){
        if(A[i] >= (double)sum / (4 * m))cnt++;
    }
    
    if(cnt >= m) cout << "Yes" << ln;
    else cout << "No" << ln;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <cmath>


using namespace std;
using ll = long long;
using ull = unsigned long long;


#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)

class employee {
public:
	int id;
	vector<int> children;
	int salary;
	
	employee(int _id) {
		id = _id;
		children = {};
		salary = -1;
	}



};


double length(pair<double, double> coord) {
	return sqrt(coord.first * coord.first + coord.second * coord.second);
}


int main() {
	int N;
	cin >> N; 
	int sum = 0;
	int now;
	rep(i, 1, N + 1) {
		sum += i;
		if(sum >= N){
			now = i;
			break;
		}
	}
	int remove = sum - N;

	rep (i, 1, now + 1) {
		if (i != remove) {
			cout << i << endl;
		}
	}
	return 0;

}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	int H;
	int W;
	int C;
	int[][] map;
	int[] DR = {1, 0, -1, 0};
	int[] DC = {0, 1,  0, -1};

	public void solve() {
		while (true) {
			H = nextInt();
			W = nextInt();
			C = nextInt();
			if (H == 0) break;
			
			map = new int[H][W];
			for(int r = 0; r < H; r++){
				for(int c = 0; c < W; c++){
					map[r][c] = nextInt();
				}
			}
			out.println(recur(map, 0));
		}
	}
	
	public int recur(int[][] map, int cnt){
		if(cnt == 5){
			return countrecur(map, 0, 0);
		}else{
			int ans = 0;
			int cc = map[0][0];
			int[][] nmap = new int[H][W];
			for(int i = 1; i <= 6; i++){
				if(cc == i) continue;
				for(int r = 0; r < H; r++){
					for(int c = 0; c < W; c++){
						nmap[r][c] = map[r][c];
					}
				}
				flip(nmap, 0, 0, cc, i);
				ans = Math.max(ans, recur(nmap, cnt + 1));
			}
			return ans;
		}
	}
	
	public void flip(int[][] map, int r, int c, int color, int nc){
		if(r < 0 || r >= H || c < 0 || c >= W || map[r][c] != color){
			return;
		}
		map[r][c] = nc;
		for(int i = 0; i < 4; i++){
			flip(map, r + DR[i], c + DC[i], color, nc);
		}
	}
	
	
	public int countrecur(int[][] map, int r, int c){
		if(r < 0 || r >= H || c < 0 || c >= W || map[r][c] != C){
			return 0;
		}else{
			int ans = 1;
			map[r][c] = 0;
			for(int i = 0; i < 4; i++){
				ans += countrecur(map, r + DR[i], c + DC[i]);
			}
			return ans;
		}
	}

	private static PrintWriter out;

	public static void main(String[] args) {
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}

	public static int nextInt() {
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if (str.charAt(0) == '-') {
			minus = true;
			i++;
		}
		int len = str.length();
		for (; i < len; i++) {
			char c = str.charAt(i);
			if (!('0' <= c && c <= '9'))
				throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}

	public static long nextLong() {
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if (str.charAt(0) == '-') {
			minus = true;
			i++;
		}
		int len = str.length();
		for (; i < len; i++) {
			char c = str.charAt(i);
			if (!('0' <= c && c <= '9'))
				throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}

	public static String next() {
		int c;
		while (!isAlNum(c = read())) {
		}
		StringBuilder build = new StringBuilder();
		build.append((char) c);
		while (isAlNum(c = read())) {
			build.append((char) c);
		}
		return build.toString();
	}

	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;

	private static int read() {
		if (bufferLength < 0)
			throw new RuntimeException();
		if (bufferIndex >= bufferLength) {
			try {
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			if (bufferLength <= 0)
				return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}

	private static boolean isAlNum(int c) {
		return '!' <= c && c <= '~';
	}
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int cnt = 0;
  string ans = s;
  for(int i=0; i<n; ++i){
    if(s[i] == '(') ++cnt;
    else{
      --cnt;
      if(cnt <0){
        ans = '(' + ans;
        ++cnt;
      }
    }
  }
  while(cnt>0){
    ans += ')';
    --cnt;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
fun main(args: Array<String>) {
    abc105b()
}

fun abc105b() {
    val n = readLine()!!.toInt()

    val (cakePrice, donutPrice) = listOf(4, 7)

    val answer = (0..25).any { i ->
        (0..14).any { j ->
            cakePrice * i + donutPrice * j == n
        }
    }.let { if (it) "Yes" else "No" }

    println(answer)
}


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

#define loop(i,j) for(int i = 0;i < j;i++)
using namespace std;

int n,*s,q,*t,r;

bool find(int e){
	int begin=0,end=n;
	while(begin != end) {
		int middle = (begin + end) / 2;
		if(s[middle] < e) {
			begin = middle+1;
		} else if (s[middle] > e) {
			end = middle;
		} else return true;
	}
	if(s[begin] == e) return true;
	return false;
}

int main() {
	cin >> n;
	s = new int[n];
	loop(i,n) cin >> s[i];
	cin >> q;
	t = new int[q];
	loop(i,q) {
		cin >> t[i];
		if(find(t[i])) r++;
	}
	cout << r << endl;
}



Measured memory_bytes: 3684
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.close();

		int a = m / n;
		int b = (int) Math.sqrt(m);
		int ans = 1;
		Set<Integer> set = new HashSet<Integer>();
		for (int i = 1; i <= a && i <= b; i++) {
			if (m % i == 0) {
				ans = i;
				set.add(i);
			}
		}
		for (int i : set) {
			int c = m / i;
			if (c <= a) {
				ans = Math.max(ans, c);
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
package main

import "fmt"

func solve() {
	var N, K int
	fmt.Scan(&N, &K)
	x := make([]int, N)
	ans := 0
	for i := range x {
		fmt.Scan(&x[i])
		ans += min(x[i], abs(K-x[i])) * 2
	}
	fmt.Println(ans)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	solve()
}


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

int main()
{
    char ans[10000];
    char s[10000];
    int w, i = 0, j = 0;

    cin >> s >> w;
    
    while (s[i] != '\0') {
        if (i % w == 0) {
            ans[j] = s[i];
            j++;
        }
        i++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,d,a;
	cin>>n>>k;
	bool m[101]={0};
	while(k--)
    {
        cin>>d;
        while(d--)
        {
            cin>>a;
            if(!m[a])
            {
                m[a]=1;
                n--;
            }
        }
    }
    cout<<n<<endl;
	return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<vector>
#include<string>
using namespace std;

int main(){
  int a, b, c;
  scanf("%d", &a); scanf("%d", &b); scanf("%d", &c);
  int hen[3] = {a, b, c};
  bool res = false;
  for (int i = 0; i < 3; i++){
    if (hen[i] == hen[(i+1)%3] && hen[i] == hen[(i+2)%3]){
      res = true;
      break;
    }
  }
  if(res){
    printf("Yes");
  }
  else{
    printf("No");
  }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	
	ll n;
	cin>>n;
	map<ll,ll> check;
	for(ll i=0;i<n;i++){
		ll z;
		cin>>z;
		check[z] = i+1;
	}
	for(ll i=0;i<n;i++){
		cout<<check[i+1] << " ";
	}

	return 0;
}


Measured memory_bytes: 7040
# n個の具材
# i個目の価値はvi
# 2個の具材を入れると価値は元の具材の価値の平均
# 全部合成した後の価値の最大値

# 合成を重ねると価値が下がるので価値の低いものから合成していく

n = int(input())
v = sorted(list(map(int, input().split())))
value = (v[0]+v[1])/2
for i in range(2, n):
    value = (value + v[i])/2

print(value)


Measured memory_bytes: 2940
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] d = new int[n];
		for (int i = 0; i < n; i++) {
			d[i] = sc.nextInt();
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				ans += d[i] * d[j];
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include<stdio.h>

int main(void){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if((a==7 && b==5 && c==5) || (a==5 && b==7 && c==5) || (a==5 && b==5 && c==7)){
    printf("YES\n");
  }else{
    printf("NO\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int getPattern(int,int,int,int);
int main(void)
{
  int n,x;
  for(;;)
    {
      scanf("%d%d",&n,&x);
      if(n==0&&x==0) break;
      printf("%d\n",getPattern(1,n,3,x));
    }
  return 0;
}
int getPattern(int min,int max,int num,int goal)
{
  int i;
  int ret=0;
  if(num<0) return 0;
  if(num==0)
    {
      if(goal==0) return 1;
      else return 0;
    }
  for(i=min;i<=max;i++)
    {
      ret+=getPattern(i+1,max,num-1,goal-i);
    }
  return ret;
}


Measured memory_bytes: 2104
#include <iostream>
using namespace std;
typedef long long ll;
ll k, n, res;
int main(void){
    // Your code here!
    cin >> n >> k;
    if (k == 0) {
        cout << n * n << endl;
        return 0;
    }
    for (ll i = k + 1; i <= n; i++) {
        res += n / i * (i - k) + (n % i - k + 1 < 0 ? 0 : n % i - k + 1);
    }
    cout << res << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    char[] cs;
    int[] cnt = new int[3];
    int n;
    public static void main(String[] args) {
        Main m = new Main();
        m.read();
        m.solve();
    }

    private void read() {
        Scanner sc = new Scanner(System.in);
        cs = sc.nextLine().toCharArray();
        n = cs.length;
        for (char c: cs)
            cnt[c - 'a']++;
    }

    private void solve() {
        int mx = 0, mn = 0;
        mn = Arrays.stream(cnt).min().getAsInt();
        mx = Arrays.stream(cnt).max().getAsInt();
        if (mx - mn <= 1)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


Measured memory_bytes: 29652