akhauriyash/Code-Regression huggingface dataset:
from collections import deque
from math import gcd
import sys

def input():
    return sys.stdin.readline().rstrip()

MOD = 10**9 + 7
n = int(input())
cnt = {}
zero_cnt = 0
ans = 1

for _ in range(n):
    a, b = map(int, input().split())
    if (a, b) == (0, 0):
        zero_cnt += 1
        continue
    g = gcd(abs(a), abs(b))
#    if a == 0 or b == 0: g = max(abs(a), abs(b))
    a //= g
    b //= g

    rotate = 0
    while not (a > 0 and b >= 0):
        a, b = -b, a
        rotate += 1
    if (a, b) not in cnt:
        cnt[(a, b)] = [0, 0]

    cnt[(a, b)][rotate%2] += 1

for key in cnt:
    A, B = cnt[key]
    ans *= 1 + pow(2, A, MOD) - 1 + pow(2, B, MOD) - 1
    ans %= MOD

ans += zero_cnt
ans -= 1 #for empty set
print(ans % MOD)


Measured memory_bytes: 60692
def median(q):
    l = len(q)
    q = sorted(q,reverse=True)
    if l%2 == 0:
        return (q[int(l/2)]+q[int(l/2)-1])/2
    else:
        return q[int((l+1)/2-1)]

n = int(input())
a = []
b = []
for i in range(n):
    x,y = map(int,input().split())
    a.append(x)
    b.append(y)

med_a = median(a)  # aの中央値を計算
med_b = median(b)  # bの中央値を計算

if n%2 == 0:  # nが偶数
    print(int(2*(med_b-med_a)+1))
else:  # nが奇数
    print((med_b-med_a)+1)

Measured memory_bytes: 26908
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))

manzoku=0

for i in range(n):
    manzoku+=b[a[i]-1]
    if i < n-1:
        if a[i+1]==(a[i]+1):
            manzoku+=c[a[i]-1]
print(manzoku)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <map>
using namespace std;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif
#define PI 3.1415926535897932384626433832795
#define SINV(t) greater<t>()
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP2(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()

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

typedef long long ll;
#define vv(t) vector<t>

template<typename T>
void SV(vector<T> v){
    REP(i,v.size()){
        #ifdef LOCAL
            cout << i << " : " << v[i] << endl;
        #endif
    }
}

int bitCount(int bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >> 16);
}



int main(){
    int N, M, A;
    cin >> N >> M;
    ll sum = 0;
    REP(i, M){
        cin >> A;
        sum += A;
    }
    N-=sum;
    if(N < 0){
        cout << -1 << endl;
    }else{
        cout << N << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define len(val) static_cast<long long>(val.size())
#define rep(i, n) for(int i=0; i<(n); i++)
typedef long long ll;
typedef pair<int, int> P;


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

    int N, A, B;
    cin >> N >> A >> B;
    string s;
    cin >> s;

    for(int i=0; i<len(s); i++){
      if(s[i] == 'c'){
        cout << "No" << endl;
      }else if(s[i] == 'a'){
        if(A+B > 0){
          if(A > 0) A--;
          else B--;
          cout << "Yes" << endl;
        }else{
          cout << "No" << endl;
        }
      }else{
        if(A+B > 0 && B > 0){
          B--;
          cout << "Yes" << endl;
        }else{
          cout << "No" << endl;
        }
      }
    }

}


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

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);

    string s, ss;
    cin >> s >> ss;
    bool ans = 1;

    for(unsigned i = 0; i < s.size(); ++i) {
        if(s[i] != ss[i]) 
            ans = 0;
    }

    ans ? cout << "Yes\n" : cout << "No\n";
    return 0;
}



Measured memory_bytes: 3616
N = int(input())
red_point=[]
blue_point=[]
for i in range(N):
    red_point.append(list(map(int,input().split())))
for i in range(N):
    blue_point.append(list(map(int,input().split())))
red_point.sort(reverse=True)
blue_point.sort(key=lambda x:x[1])
# print(blue_point)
ans = 0
# temp = 0 
# print(red_point)
for i in range(N):
    redx,redy=red_point[i][0],red_point[i][1]
    for j in range(len(blue_point)):
        # print("({},{})".format(i,j))
        # print(blue_point)
        bluex,bluey=blue_point[j][0],blue_point[j][1]
        if redx<bluex and redy<bluey:
            # if temp<redx:
                # temp = redx
                # tempj=j   
            ans +=1
            # red_point.pop(i)
            blue_point.pop(j)
            break
print(ans)

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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) if((x)>(y))(x)=(y)
#define chmax(x,y) if((x)<(y))(x)=(y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

string s;
int k;
vst a;

signed main() {
	cin >> s >> k;
	int n = s.size();
	rep(i,n) repst(l,1,min(n-i,10)) a.pb(s.substr(i,l));
	unq(a);
	cout << a[k-1] << ln;
}

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int a[] = new int[n];
		int b[] = new int[n];
		int c[] = new int[n];

		String str[] = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(str[i]);
		}

		str = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			b[i] = Integer.parseInt(str[i]);
		}

		str = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			c[i] = Integer.parseInt(str[i]);
		}

		Arrays.sort(a);
		Arrays.sort(c);

		long ans = 0;
		for (int i = 0; i < n; i++) {
			int left = -1;
			int right = n;

			long temp1;
			long temp2;

			while (right - left > 1) {
				int mid = (right + left) / 2;

				if (a[mid] >= b[i]) {
					right = mid;
				} else {
					left = mid;
				}
			}
			temp1 = right;

			left = -1;
			right = n;
			while (right - left > 1) {
				int mid = (right + left) / 2;

				if (c[mid] > b[i]) {
					right = mid;
				} else {
					left = mid;
				}
			}
			temp2 = n - right;

			ans += temp1 * temp2;
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 54776
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#define dd double
#define ll long long
dd PI = acos(-1);
//ios::sync_with_stdio(false);
using namespace std;
const ll MAXN = 5e6 + 5;
const ll INF = 0xffffffff;

struct node {
	string s;
	char ss;
}no[100005];

ll a[15];

bool cmp(node x, node y) {
	return x.s < y.s;
}

int main() {
	ios::sync_with_stdio(false);
	string s1;
	ll n; cin >> n;
	for (ll i = 0; i < n; i++) {
		cin >> s1;
		for (ll i = 0; i < s1.size(); i++) {
			a[i] = (ll)(s1[i]);
		}
		sort(a, a + s1.size());
		for (ll i = 0; i < s1.size(); i++) {
			s1[i] = (char)(a[i]);
		}
		no[i].s = s1;
		no[i].ss = s1[0];
	}
	sort(no, no + n, cmp);
	ll cnt = 0;
	ll count = 0;
	for (ll i = 0; i < n - 1; i++) {
		//cout << no[i].s << endl;
		if (no[i].s == no[i + 1].s) {
			count++;
		}
		else {
			if (count == 0) {
				continue;
			}
			else if (count == 1) {
				cnt++;
				count = 0;
			}
			else {
				for (ll k = 0; k <= count; k++) {
					cnt += k;
				}
				count = 0;
			}
		}
	}
	if (count == 0) {
		cnt = cnt;
	}
	else if (count == 1) {
		cnt++;
		count = 0;
	}
	else {
		for (ll i = 0; i <= count; i++) {
			cnt += i;
		}
		count = 0;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 6528
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
using namespace std;

//common
typedef long long i64,ll;

#define BR "\n"
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,r) for(int i=(l);i<(int)(r);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}

template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

string BITtoString(int bit){
    stringstream ss;
    while(bit!=0){ss<<(bit%2);bit/=2;}
    string res=ss.str();reverse(ALL(res));
    return res;
}

template<typename T,typename V> inline T pmod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}


ll MOD=1000000007;

class Main{
public:
	
	void run(){
		
		int Q;cin >> Q;
		REP(q,Q){
			int c,a,n;cin >> c >> a >> n;

			//can
			int u=min(c,min(a,n));
			c-=u;a-=u;n-=u;
			//cca
			int u2=min(c/2,a);
			c-=u2*2;a-=u2;
			//ccc
			int u3=c/3;
			
			cout <<(u+u2+u3)<<endl;
		}

	}
};

 int main(){
	//ios::sync_with_stdio(false);
 	Main().run();
 	return 0;
 }

Measured memory_bytes: 1164
#include<iostream>
#include <string>
typedef long long ll;

using namespace std;
int main()
{
	string s;
	int k;
	cin >> s;
	cin >> k;

	int one = 0;
	char afone = '1'; //1以外で最初に表れる数字.1以外が現れない場合は1

	int i = 0;
	while (i<s.size() && s[i] == '1') {
		one++;
		i++;
	}
	if (i<s.size()) afone = s[i];

	char kotae;
	if (k <= one) {
		kotae = '1';
	}
	else {
		kotae = afone;
	}

	cout << kotae << endl;
	return 0;
}

Measured memory_bytes: 256
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});
process.stdin.on('end', () => {
  const cards = {
    S: new Set(),
    H: new Set(),
    C: new Set(),
    D: new Set(),
  };

  const [, ...lines] = content.trim().split('\n');
  for (let line of lines) {
    const [kind, num] = line.split(' ');
    cards[kind].add(parseInt(num, 10));
  }

  for (let kind of ['S', 'H', 'C', 'D']) {
    const nums = getMissingNums(cards[kind]).sort((a, b) => a - b);
    if (nums.length > 0) {
      console.log(nums.map(n => `${kind} ${n}`).join('\n'));
    }
  }
});

const getMissingNums = map => {
  const missingNums = [];
  for (let i = 1; i <= 13; i++) {
    if (!map.has(i)) {
      missingNums.push(i);
    }
  }

  return missingNums;
};


Measured memory_bytes: 15608
/*
  Lower bound: first element that is greater-or-equal.
  int i=lower_bound(a,a+n,x)-a;
  Upper bound: first element that is strictly greater.
  #include<boost/multiprecision/cpp_int.hpp>
  namespace mp=boost::multiprecision;
  mp::cpp_int u=1; for(unsigned i=1;i<=n;i++) u*=i;
*/
#pragma GCC optimize("O3")  
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define mem(z,i) memset(z,i,sizeof(z))
#define I (int)
const int mod=(int)1e9+7;
const long long INF = 1000000000000000000LL;
const int WASTE=(int)2e5;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    #define int long long
    int n;
    cin>>n;
    int a[n],b[n],c[n];
    for(int x=0;x<n;x++) cin>>a[x];
    	sort(a,a+n);
    for(int x=0;x<n;x++) cin>>b[x];
    	sort(b,b+n);
    for(int x=0;x<n;x++) cin>>c[x];
    	sort(c,c+n);
    int ans=0;
    for(int x=0;x<n;x++){
    	int i=b[x];
    	int t=lower_bound(a,a+n,i)-a;
    	int j=n-(upper_bound(c,c+n,i)-c);
    	ans+=(t*j);
    }
    cout<<ans;
	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

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

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    int n;
    cin>>n;
    int a[n], d[n];
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
        d[i]=a[i];
    }
    sort(a, a+n);
    int b=a[n-1], c=a[n-2];
    for (int i=0;i<n;i++)
    {
        if (d[i]==b)
        {
            cout<<c<<"\n";
        }
        else
        {
            cout<<b<<"\n";
        }

    }
    return 0;
}


Measured memory_bytes: 5152
//vec[i]の範囲外エラー表示
#define _GLIBCXX_DEBUG
//includeとusing
#include <bits/stdc++.h>
using namespace std;
//型名省略
using ll = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using pll = pair<ll, ll>;
//定数
const ll INF = 1e9;
const ll MOD = 1e9+7;
//マクロ
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define xrep(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define all(A) A.begin(), A.end()
//入力
ll llin() {ll x; cin >> x; return x;}
string stin() {string s; cin >> s; return s;}
vl vlin(ll n) {vl a(n); rep(i,n){cin >> a[i];} return a;}
//正誤判定
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}


//main関数
int main() {
    ll d, t, s; cin >> d >> t >> s;
    Yes(d <= s * t);
}



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

int main(){
	int N, M;
	cin>>N>>M;
	int L=0,R=100000;
	int LL,RR;
	int ans;
	for(int i=1;i<=M;++i){
		cin>>LL>>RR;
		if (L<LL) L = LL;
		if (RR<R) R = RR;
	}
	if (R<L) cout<<0<<endl;
	else cout<<R-L+1<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const int INF=1e7;
const LL LINF=1e18;

int main(){
    string c;
    cin >> c;
    int n=-1,w=-1,s=-1,e=-1;
    for(int i=0;i<c.length();i++){
        if(c[i]=='W') w=1;
        if(c[i]=='N') n=1;
        if(c[i]=='S') s=1;
        if(c[i]=='E') e=1;
    }
    if(w*e>0&&n*s>0) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

#define N 1000

int main(void)
{
    int A, B, C, i;
    bool flag = false;

    scanf("%d%d%d", &A, &B, &C);

    for (i = 1; i <= N; i++){
        if ((A*i)%B == C){
            flag = true;
            break;
        }
    }
    if (flag)
        printf("YES");
    else
        printf("NO");
    return 0;
}


Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CTsundoku {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N, M, K;
        cin >> N >> M >> K;
        vector<int> A(N), B(M);
        REP(i, N) cin >> A[i];
        REP(i, M) cin >> B[i];

        vector<int> sum(M + 1);
        REP(i, M) sum[i + 1] = sum[i] + B[i];
        int res = 0;
        int cur = 0;
        REP(i, N + 1) {
            if (i > 0) cur += A[i-1];
            if (K - cur < 0) break;

            int num = upper_bound(sum.begin(), sum.end(), K-cur) - sum.begin() - 1;
            res = max(res, i + num);
        }
        cout << res << endl;

    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CTsundoku solver;
    solver.solve(in, out);
    return 0;
}


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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define FOR(i,a,b) for(lint i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009

typedef pair<int, int> P;
 
lint ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<vector<int> > memo(9);
    REP(i,9){
        REP(j,9){
            memo[i].push_back(0);
        }
    }
    REP(i,n){
        string s = to_string(i+1);
        int a = ctoi(s[0]);
        int b = ctoi(s[s.length()-1]);
        if(b==0) continue;
        memo[a-1][b-1]++;
    }
    lint ans = 0;
    REP(i,9){
        REP(j,9){
            ans += memo[i][j]*memo[j][i];
        }
    }
    print(ans);
    return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   int n;
   cin >> n;
   vec<int> v(n);
   rep (i, n) {
      cin >> v[i];
   }

   repp (i, 1, n) {
      if (v[i] == v[i-1]) {
         v[i] = -1;
      }
   }

   cout << count(all(v), -1) << endl;

   return 0;
}

Measured memory_bytes: 256
<?php


fscanf(STDIN,"%d",$N);
fscanf(STDIN,"%d %d",$A,$B);
$line = trim(fgets(STDIN));$P = explode(" ", $line);
//var_dump($P);

$A_count=0;
$B_count=0;
$C_count=0;


for ($i=0; $i<$N;$i++){
	if ($P[$i]<=$A) {$P[$i]=0;$A_count++;}
else
	if ($P[$i]<=$B) {$P[$i]=0;$B_count++;}
else
	{$P[$i]=0;$C_count++;}
}

//var_dump($P);

echo min($A_count,$B_count,$C_count);

Measured memory_bytes: 3956
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

typedef struct{
    LL high;
    LL count;
}POS;

int main(){
    int N;
    LL *H;
    int i;
    int max;
    int temp;
    cin >> N;
    H = new LL[N];
    for(i=0;i<N;i++){
        cin >> H[i];
    }
    temp = 0;
    max = 0;
    for(i=N-2;i>=0;i--){
        if( H[i+1] <= H[i]){
            temp++;
        }else{
            if( max < temp){
                max = temp;    
            }
            temp = 0;
        }
    }
    if( max < temp){
        max = temp;    
    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <bitset>
#include <algorithm>

std::bitset<4000000>b;

signed main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
	
	int n;
	std::cin >> n;
	
	int a[n];
	for(int i = 0; i < n; i++)
		std::cin >> a[i];
	
	//std::sort(a, a+n);
	
	long long sum = 0;
	for(int i = 0; i < n; i++)
		sum += a[i];
	
	b[0] = 1;
    for(int i = 0; i < n; i++)
    {
        b |= (b << a[i]);
    }
    
    for(long long i = (sum + 1)/2; i < 2*sum + 5; i++) {
		if(b[i]) {
			std::cout << i << std::endl;
			return 0;
		}
    }
    
    return 0;
}


Measured memory_bytes: 1792
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let x: Vec<u64> = sc.vec(n);
    let l: u64 = sc.read();

    let mut next = vec![vec![0; n]; 30];
    let mut tail = 0;
    for head in 0..n {
        while tail + 1 < n && x[tail + 1] <= l + x[head] {
            tail += 1;
        }
        next[0][head] = tail;
    }

    for b in 1..30 {
        for i in 0..n {
            next[b][i] = next[b - 1][next[b - 1][i]];
        }
    }

    let q: usize = sc.read();
    for _ in 0..q {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        let (a, b) = if a > b { (b, a) } else { (a, b) };

        let mut cur = a;
        let mut ng = 0;
        for i in (0..30).rev() {
            let days = 1 << i;
            let next_pos = next[i][cur];
            if next_pos < b {
                cur = next_pos;
                ng += days;
            }
        }

        println!("{}", ng + 1);
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 35580
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = new String();
		while(br.ready()){
			line= br.readLine();
		}
		String[] abc = line.split(" ");
		int a = Integer.parseInt(abc[0]);
		int b = Integer.parseInt(abc[1]);
		int c = Integer.parseInt(abc[2]);
		
		if(a<b && b<c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}

}

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

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

  rep(i, S.size() - 1){
      if (S.at(i) == S.at(i + 1)){
        cout << "Bad" << endl;
        return 0;
      }
  }
  cout << "Good" << endl;
}

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

using Weight=long long int;

struct Edge{
    int src,dest;
    Weight weight;
    bool operator<(const Edge& rhs){
        return weight<rhs.weight;
    }
};
using Edges=vector<Edge>;
using Graph=vector<Edges>;

class UnionFind {
    int N;
    vector<int> rank;
    vector<int> par;
    public:
    UnionFind(int n):N(n){
        rank.resize(n,0);
        par.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
        }
    }

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

    bool same(int x,int y){
        return find(x)==find(y);
    }

    void unite(int x,int y){
        x=find(x),y=find(y);
        if(rank[x]<rank[y]){
            par[x]=y;
        }
        else{
            if(rank[x]==rank[y]) rank[x]++;
            par[y]=x;
        }
    }

};

Weight kruskal(int V,Edges &edges){
    sort(edges.begin(),edges.end());
    Weight res=0;
    UnionFind uf(V);
    for(auto e:edges){
        if(!uf.same(e.src,e.dest)){
            uf.unite(e.src,e.dest);
            res+=e.weight;
        }
    }
    return res;
}

Weight kruskal(Graph& g){
    Edges edges;
    for(auto es:g){
        edges.reserve(edges.size()+es.size());
        edges.insert(edges.end(),es.begin(),es.end());
    }
    return kruskal(g.size(),edges);
}

int main(){
    int V,E;
    cin>>V>>E;
    Edges edges(E);
    for(int i=0;i<E;i++){
        int s,t;
        Weight w;
        cin>>s>>t>>w;
        edges[i]=Edge{s,t,w};
    }
    cout<<kruskal(V,edges)<<endl;
    return 0;
}

Measured memory_bytes: 4436
from math import *

def kaijou(n):
    ka = 1
    for e in range(1,n+1):
        ka *= e
    return ka

N = int(input())


coordinates = []
for _ in range(N):
    coordinates.append(list(map(int,input().split())))

all_distances = []

for i in range(N-1):
    for j in range(i+1,N):
        all_distances.append(sqrt(pow(coordinates[i][0]-coordinates[j][0],2) + pow(coordinates[i][1]-coordinates[j][1],2)))


sum_distances = sum(all_distances)

ans = (sum_distances ) * 2   /   N

print(ans)

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

int n, q;
int segSize = 1;
int tree[300000], lazy[300000] = {};
bool isLazy[300000];

void init(){
  while(segSize < n) segSize *= 2;

  for(int i = 0;i < segSize;i++){
    tree[segSize-1+i] = INT_MAX;
  }

  for(int i = segSize-2;i >= 0;i--){
    tree[i] = min(tree[i*2+1], tree[i*2+2]);
  }
}

void eval(int k, int l, int r){

  if(isLazy[k]){
    tree[k] = lazy[k];

    if(r - l > 1){
      isLazy[2*k+1] = isLazy[2*k+2] = true;
      lazy[2*k+1] = lazy[2*k+2] = lazy[k];
    }

    isLazy[k] = false;
  }

  return;
}

void update(int a, int b, int x, int k = 0, int l = 0, int r = -1){
  if(r == -1) r = segSize;

  eval(k, l, r);

  if(r <= a || b <= l) return;

  if(a <= l && r <= b){
    isLazy[k] = true;
    lazy[k] = x;
    eval(k, l, r);
  }else{
    update(a, b, x, 2*k+1, l, (l+r)/2);
    update(a, b, x, 2*k+2, (l+r)/2, r);
    tree[k] = min(tree[2*k+1],tree[2*k+2]);
  }
}

int getmin(int a, int b, int k = 0, int l = 0, int r = -1){
  if(r == -1) r= segSize;

  eval(k, l, r);

  if(r <= a || b <= l) return INT_MAX;
  if(a <= l && r <= b) return tree[k];

  return min(getmin(a, b, 2*k+1, l, (l+r)/2), getmin(a, b, 2*k+2, (l+r)/2, r));
}

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

  int p, s, t, x;
  for(int i = 0;i < q;i++){
    cin >> p;
    if(p == 0){
      cin >> s >> t >> x;
      update(s, t+1, x);
    }else{
      cin >> s >> t;
      cout << getmin(s, t+1) << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 5132
import java.util.*;

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

    int min = 753;
    for (int i = 0; i <= S.length()-3; i++) {
      int a = Integer.parseInt(S.substring(i, i+3));
      int diff = Math.abs(753-a);
      if (diff < min) {
        min = diff;
      }
    }
    System.out.println(min);
  }
}

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

int main(){
    int A,B;
    cin >> A >> B;
    int co1,co2,co3,co4,co5,temp,count=0;
    REP(i,A,B){
        temp=i;
        co1=temp%10;
        temp/=10;
        co2=temp%10;
        temp/=10;
        co3=temp%10;
        temp/=10;
        co4=temp%10;
        temp/=10;
        co5=temp%10;
        if(co1==co5&&co2==co4)count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = (int)1.05e9;

const i64 mod = 998244353;

i64 mof(i64 x)
{
	while(x >= mod) {
		x = x - mod;
	}
	return x;
}

int main()
{
	int n;
	vector<i64> as;
	i64 total = 0;

	scanf("%d", &n);
	as.resize(n);
	for(auto& a : as) {
		scanf("%lld", &a);
		total += a;
	}

	vector<vector<i64>> dp1(n + 1), dp2(n + 1);
	for(int i = 0; i < n + 1; i++) {
		dp1[i].resize(n * 300 + 1, 0LL);
		dp2[i].resize(n * 300 + 1, 0LL);
	}

	dp1[0][0] = 1;
	dp2[0][0] = 1;

	for(int pos = 0; pos < n; pos++) {

		vector<i64>& prev1 = dp1[pos];
		vector<i64>& cur1 = dp1[pos + 1];
		vector<i64>& prev2 = dp2[pos];
		vector<i64>& cur2 = dp2[pos + 1];
		i64 x = as[pos];

		for(i64 s = 0; s <= n * 300; s++) {
			cur1[s] = mof(prev1[s] * 2 + (s >= x ? prev1[s - x] : 0));
			cur2[s] = mof(prev2[s] + (s >= x ? prev2[s - x] : 0));
		}
	}

	i64 ans = 0;

	for(int i = 0; i <= n * 300; i++) {
		if(total > 2 * i) {
			continue;
		}
		ans = mof(ans + dp1[n][i]);
	}

	i64 f = 1;
	for(int i = 0; i < n; i++) {
		f = mof(f * 3);
	}
	ans = mof(ans * 3);

	if(total % 2 == 0) {
		i64 p = total / 2;
		ans = mof(ans + mod * 2 - dp2[n][p] * 3);
	}

	ans = mof(f + mod - ans);

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

	return 0;
}

/* waffle */


Measured memory_bytes: 424064
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)

	s := strconv.Itoa(n)

	if s[1] == s[2] && (s[0] == s[1] || s[3] == s[1]) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1776
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define MAX (1 << 29)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> A(N, vector<int>(M));
  FOR(i, N) FOR(j, M) cin >> A[i][j], A[i][j]--;
  vector<int> pt(N, 0);
  unordered_set<int> used;
  int ans = N;
  while (used.size() < M) {
    vector<int> list(M);
    FOR(i, N) { list[A[i][pt[i]]]++; }
    ans = min(ans, *max_element(ALL(list)));
    int most = max_element(ALL(list)) - list.begin();
    used.insert(most);
    FOR(i, N) {
      while (pt[i] < M && used.count(A[i][pt[i]]))
        pt[i]++;
    }
  }
  print(ans);
  return 0;
}


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

int main(){
  int a,b,c=0,i,array[1001],array2[1001];
  cin>>a;
  for(i=0;i<a;i++){
    cin>>array[i]>>array2[i];
    c+=array2[i]-array[i]+1;
    }
  cout<<c<<endl;
}

Measured memory_bytes: 256
import operator

ops = { "+": operator.add,
        "-": operator.sub,
        "/": operator.floordiv,
        "*": operator.mul}

while True:
    a,op,b = input().strip().split()
    a,b = int(a),int(b)
    if op == "?":
        break
    else:
        print(ops[op](a,b))



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

int main() {
  int N; cin >> N;
  int D[N][2]; for (int i = 0; i < N; i++) cin >> D[i][0] >> D[i][1];
  bool s = false;
  for (int i = 0; i < N-2; i++) {
    if (D[i][0]==D[i][1] && D[i+1][0]==D[i+1][1] && D[i+2][0] == D[i+2][1]) {
      s = true;
    }
  }
  cout << (s ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <limits>
#include <iomanip>
using namespace std;

int main(){

    int A,B;
    cin >> A >> B;

    int ans = A - 2*B;

    if( ans < 0){
        cout << 0 << endl;
    }else{
        cout << ans << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int sum=0;
  int t=n;
  for (int i=0;i<10;i++){
    sum+=t%10;
    t/=10;
  }
  if(n%sum==0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
main :: IO ()
main = getLine >> getContents >>= putStrLn . format . game . map words . lines
      where format (a, b) = show a ++ " " ++ show b

game :: [[String]] -> (Int, Int)
game [] = (0, 0)
game ([x, y]:xs)
    | x < y = (taro, hanako + 3)
    | x > y = (taro + 3, hanako)
    | otherwise = (taro + 1, hanako + 1)
    where (taro, hanako) = game xs

Measured memory_bytes: 4140
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
string s;
int n, m;
int a[10000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>m>>s;
    vector<int> ans;
    int now=n;
    while(now!=0){
        for(int j=max(0,now-m);j<=now;j++){
            if(j==now){
                cout<<-1<<"\n";
                return 0;
            }
            if(s[j]=='1'){
            }
            else{
                ans.push_back(now-j);
                now=j;
            }
        }
    }
    for(int i=0;i<ans.size();i++)
    cout << ans[ans.size()-1-i] << "\n";
}



Measured memory_bytes: 1096
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
void trace(int n, vector<ll> arr){for(int i = 0; i < n; i++){cout << arr[i] << " ";} cout << endl << endl;}
const ll mod = 1e9 + 7;
int main()
{
    Hello
    int n, k;
    ll ans = 1;
    cin >> n >> k;
    vector<ll> pos, neg;
    for(int i = 0; i < n; i++){
        ll a;
        cin >> a;
        ans = (ans * a) % mod;
        if(a < 0) neg.push_back(-a);
        else pos.push_back(a);
    }
    if(k == n) return cout << (ans + mod) % mod, 0;
    sort(neg.begin(), neg.end());
    sort(pos.begin(), pos.end());
    if(!pos.size()){
        ans = 1;
        if(k % 2){
            for(int i = 0; i < k; i++)
                ans = (ans * neg[i]) % mod;
            ans *= -1;
        }
        else
            for(int i = neg.size() - 1; i >= neg.size() - k; i--)
                ans = (ans * neg[i]) % mod;
        return cout << (ans + mod) % mod, 0;
    }
    else{
        vector<ll> final;
        if(k&1) final.push_back(pos.back()), pos.pop_back();
        while(final.size() < k){
            bool foundPos = false, foundNeg = false;
            ll positive1, negative1, negative2, positive2;
            if(pos.size() >= 2){
                foundPos = true;
                positive1 = pos.back();
                positive2 = pos[pos.size() - 2];
            }
            if(neg.size() >= 2){
                foundNeg = true;
                negative1 = neg.back();
                negative2 = neg[neg.size() - 2];
            }
            if(foundNeg && foundPos){
                if(positive1 * positive2 > negative1 * negative2){
                    pos.pop_back();
                    pos.pop_back();
                    final.push_back(positive1);
                    final.push_back(positive2);
                }
                else {
                    neg.pop_back();
                    neg.pop_back();
                    final.push_back(negative1);
                    final.push_back(negative2);
                }
            }
            else if(foundNeg){
                neg.pop_back();
                neg.pop_back();
                final.push_back(negative1);
                final.push_back(negative2);
            }
            else if(foundPos){
                pos.pop_back();
                pos.pop_back();
                final.push_back(positive1);
                final.push_back(positive2);
            }
            else
            {
                final.push_back(pos.back());
                final.push_back(neg.back());
            }
        }
        ans = 1;
        //trace(final.size(), final);
        for(int i = 0; i < final.size(); i++)
            ans = (ans * final[i]) % mod;
        return cout << ans, 0;
    }
    return 0;
}


Measured memory_bytes: 7860
#include <stdio.h>
#include <stdbool.h>
int main(void)
{

    int A[3][3];
    bool f[3][3];
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            scanf("%d", &A[i][j]);
            f[i][j] = false;
        }
    }
    int N;
    scanf("%d", &N);
    int *b;
    b = (int *)malloc(sizeof(int) * N);
    for(int i=0;i<N;i++){
        scanf("%d", &b[i]);
    }

    for(int i=0;i<3;i++){
        for (int j = 0; j < 3; j++)
        {
          for(int k=0;k<N;k++){
            if (A[i][j] == b[k])
            {
                f[i][j] = true;
            }
          }
        }
    }
    int bc[8];
    for(int i=0;i<8;i++){
        bc[i] = 0;
    }
    for(int i=0;i<3;i++){
        if (f[i][0] == true)
        {
            bc[0]++;
        }
        if (f[i][1] == true)
        {
            bc[1]++;
        }
        if (f[i][2] == true)
        {
            bc[2]++;
        }
        if (f[0][i] == true)
        {
            bc[3]++;
        }
        if (f[1][i] == true)
        {
            bc[4]++;
        }
        if (f[2][i] == true)
        {
            bc[5]++;
        }
        if (f[i][i] == true)
        {
            bc[6]++;
        }
    }
    if(f[0][2]==true&&f[1][1]==true&&f[2][0]==true){
        bc[7] += 3;
    }

    for(int i=0;i<8;i++){
        if (bc[i] % 3 == 0&&bc[i]>0)
        {
            printf("Yes");
            return 0;
        }
    }
        printf("No");
    return 0;
}

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

int main() {
  vector<int> vec(5);
  for (int i = 0; i < 5; i++) {
    cin >> vec.at(i);
  }
  
  for (int i = 0; i < 5; i++) {
    if (vec.at(i) == 0) {
      cout << i + 1 << endl;
      break;
    }
  }
}

Measured memory_bytes: 3532
#include<iostream>

using namespace std;

int main(){
int A,P,X,Y,Z;
cin >> A >> P;
X = 3*A;
Z= (X+P) % 2;
if(Z == 0){
  Y = (X+P)/2;
  cout << Y <<endl;
}else{
  Y = (X+P-1)/2;
  cout << Y <<endl;
}
  return 0;
}


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


int main(){
    char mozi;
    cin>>mozi;
    if(isupper(mozi)){
        cout<<"A";
    }else{
        cout<<"a";
    }
   
    }


Measured memory_bytes: 3556
program main
implicit none
 
integer(8) :: n,i,ans,minus=0
integer(8), allocatable :: a(:)
read(*,*)n
allocate(a(n))
read(*,*)a(1:n)
 
do i=1,n
	if (a(i) < 0) then
    	minus = minus +1
    end if
end do
ans = 0
if (mod(minus,2) == 0) then
	ans = sum(abs(a))
else 
	ans = sum(abs(a))
    ans = ans - 2*minval(abs(a))
end if
write(*,'(I0)')ans

end program

Measured memory_bytes: 1536
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
      int[] d = new int[N];
      long sum = 0;
      d[0] = sc.nextInt();
      for(int i=1;i<N;i++){
        d[i]=sc.nextInt();
        for(int j=0;j<i;j++){
          sum = sum + d[j]*d[i];
        }
      }

      System.out.println(sum);

    }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}

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

#define ll long long int
#define ld long double

void solve() {
	char ch;
	cin >> ch;
	if ((int)ch >= 65 && (int)ch <= 90) 
		cout << "A" << endl;
	else 
		cout << "a" << endl;
}

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

Measured memory_bytes: 3572
//
// Created on 2020/09/13.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



int main() {
    int x;
    cin>>x;
    if(x){
        cout<<0<<endl;
    }else{
        cout<<1<<endl;
    }
    return 0;
}


Measured memory_bytes: 3632
$m = [1,1]
def fib(n)
  if $m.size <= n
    $m.size.upto(n) {|i| $m[i] = $m[-1] + $m[-2] }
  end
  return $m[n]
end

N,M = gets.split.map(&:to_i)
A = readlines.map(&:to_i)
MOD = 1000000007
if A.each_cons(2).all? {|a,b| b - a > 1 }
  puts [0, A.map {|n| [n-1, n+1] }, N].flatten
	.each_slice(2).map {|n,m| (n...m).size }
	.map {|n| fib(n) }.inject(:*) % MOD
else
  puts 0
end

Measured memory_bytes: 433020
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

#define REP(i,n) for(int i = 0; i < (n); i++)
#define REPC(x,c) for(auto x:(c))
#define FOR(i, b, e) for(int i = (b); i < (e); i++)
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>

using namespace std;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if ((abs(a - b) <= d && abs(b - c) <= d) || (abs(a-c) <= d)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

if int(X // 500) < A:
    A = X // 500
if int(X // 100) < B:
    B = X // 100
if int(X // 50) < C:
    C = X // 50

count = 0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            sum = 500*a + 100*b + 50*c
            if X == sum:
                count += 1
print(count)

Measured memory_bytes: 3064