akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF (long long) 1e18//1234567890987654321
#define INF 1234567890
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN 300006
#define MAXK 26
#define MAXX 15000006
#define ll long //long int
#define ld long double
#define rep0(kk, l1, l2)for(ll kk = l1; kk < l2; kk++)
#define rep1(kk, l1, l2)for(ll kk = l1; kk <= l2; kk++)
#define foritr(itr, A) for(set<ll>::iterator itr = A.begin(); itr != A.end(); itr++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ii++)
#define cr(x) cerr << #x << " = " << x << "\n";
#define crA(x, A) cerr << #x << " = " << A[x] << "\n";
#define spacing cout << " ";
#define mmst(x, v) memset((x), v, sizeof ((x)));
#define bg(ms) (*ms.begin())
#define ed(ms) (*prev(ms.end(), 1))
#define addedge(a, b, c, v) v[(a)].pb(pi((b), (c))); v[(b)].pb(pi((a), (c)))
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n, A[MAXN], val[MAXN];
vector <ll> v;
ll index_c(ll x)
{
	auto lb = lbd(v, x) - v.begin();
	if(v[lb] != x) return -LLINF;
	else return lb;
}
int main()
{
	FAST
	cin >> n;
	FOR(i,0,n) { cin >> A[i]; v.pb(A[i]); }
	sort(all(v)); v.resize(unique(all(v))-v.begin());
	FOR(i,0,n) { val[index_c(A[i])] ++; }
	ll co = 1;
	while(co <= (ll) 1e14) co *= 2;
	while(co > 0)
	{
		FOR(i, 0, n)
		{
			if(val[index_c(A[i])] == 0 || A[i] > co) continue;
			val[index_c(A[i])] --;
			if(index_c(co-A[i]) != -LLINF && val[index_c(co-A[i])] > 0) { val[index_c(co-A[i])] --; continue; }
			val[index_c(A[i])] ++;
		}
		co /= 2;
	}
	ll ans = 0;
	for(ll i = 0; i < v.size(); i++) ans += val[i];
	cout << (n-ans)/2 << "\n";
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

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

    map<int, int> mp;
    int cnt = 0;

    rep(i, n)
    {
        int a;
        cin >> a;
        if (!mp[a] || mp[a] == 0)
        {
            mp[a] = 1;
            cnt++;
        }
        else
        {
            mp[a] = 0;
            cnt--;
        }
    }
    OP(cnt);

    return 0;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;


const ll N   =  500005;
const ll mod = 1e9 + 7;



void solve(){

  ll x=1,c=0,ans=0,y = 1e18;
  ll n,m,k;
  cin>>n ;
  ll a[n];
  for (ll i = 0; i < n; ++i){
  	cin >> a[i];
  }
  sort(a,a+n);

  for (ll i = 0; i < n; ++i){
  	if(a[i] == 0){
  		cr(0);
  	}
  	if(y/a[i] < x){
  		cr(-1);
  	}
  	x *=a[i];
  }
  c(x);
  
 
}

signed main(){
     
  ios_base::sync_with_stdio(false);   
  cin.tie(NULL);
  //int T;cin >> T;while (T--)
  solve();
  return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORD(i,b,a) for (int i = (int)(b) - 1; i >= a; --i)
#define REP(i,N) FOR(i,0,N)
#define st first
#define nd second
#define pb push_back

typedef pair<int, int> PII;
typedef long long LL;

int N;
int A[222222];

const char* FIRST = "First\n";
const char* SECOND = "Second\n";

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
}

bool go() {
  LL sum = 0;
  REP(i,N) sum += A[i];
  if (sum % 2 == 0) {
    return true;
  }

  bool found = false;
  REP(i,N) if (A[i] % 2 && A[i] > 1) {
    --A[i];
    found = true;
    break;
  }
  if (!found) return false;

  int g = A[0];
  REP(j,N) g = gcd(g, A[j]);
  REP(j,N) A[j] /= g;

  return !go();
}

int main() {
  scanf("%d", &N);
  LL sum = 0;
  REP(i,N) {
    scanf("%d", &A[i]);
    sum += A[i];
  }
  if (N == 1) {
    printf(A[0] == 1 ? SECOND : FIRST);
    return 0;
  }
  if (N % 2 == 0) {
    printf(sum % 2 ? FIRST : SECOND);
    return 0;
  }

  bool res = go();
  printf(res ? FIRST : SECOND);
  return 0;
}


Measured memory_bytes: 640
n=int(input())
t=[list(map(int,input().split())) for _ in range(n)]
ans=[0,0,0]
for i in t:
    if (i[0]-ans[0])%2==((i[1]-ans[1])+(i[2]-ans[2]))%2 and i[0]-ans[0]>=(i[1]-ans[1])+(i[2]-ans[2]):
        ans=i
    else:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 27300
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <queue>
#include <cstring>
#include <set>
#include <cctype>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long LL;

const LL MAXN = 1000000000, MAXQN = MAXN * MAXN;

bool makeGuess(LL n) {
  printf("? %lld\n", n);
  fflush(stdout);
  char c;
  scanf(" %c", &c);
  return (c == 'Y');
}

void giveAnswer(LL n) {
  printf("! %lld\n", n);
  fflush(stdout);
}

void treatSpecialCase() {
  for (LL i = MAXN; i > 1; i /= 10)
  if (!makeGuess(i - 1))
    return giveAnswer(i);
  giveAnswer(1);
}

LL getUBound() {
  for (LL i = 10;; i *= 10)
  if (!makeGuess(i)) return i;
}

void treatNormalCase() {
  LL right = getUBound(), left = right / 10;
  --right, ++left;
  LL found = -1;
  while (left <= right) {
    LL mid = left + (right - left) / 2;
    if (makeGuess(mid * MAXN)) {
      found = mid;
      right = mid - 1;
    }
    else left = mid + 1;
  }
  giveAnswer(found);
}

int main() {
  if (makeGuess(MAXN))
    treatSpecialCase();
  else treatNormalCase();
  return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string a,b;
    cin>>a>>b;
    if (a.size()>b.size()){
        cout<<"GREATER"<<endl;
    }else if(a.size()<b.size()){
        cout<<"LESS"<<endl;
    }else{
        for (int i=0;i<a.size();i++){
            if (int(a.at(i))>int(b.at(i))){
                cout<<"GREATER"<<endl;
                break;
            }else if (int(a.at(i))<int(b.at(i))){
                cout<<"LESS"<<endl;
                break;
            }else if (i==a.size()-1){
                cout<<"EQUAL"<<endl;
            }
        }
    }
    
}



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

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

	int n[100];

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

	for (int i = 0; i < count - 1; i++)
	{
		//cout << count - i << endl;
		cout << n[count -1 - i] << " ";
	}
	cout << n[0] << endl;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define DEBUG

using namespace std;

string s;
int k;
long long ans;

inline int solve(string str)
{
    int res = 0, cnt = 1;
    for (int i = 1; i < str.length(); ++i) {
        if (str[i] == str[i-1]) {
            ++cnt;
        } else {
            res += cnt/2;
            cnt = 1;
        }
    }
    return res+cnt/2;
}

int main()
{
    cin >> s >> k;
    if (k&1) {
        int x = solve(s), y = solve(s+s+s);
        ans = (1ll*(y-x)*k+(x-y)+x*2)/2;
    } else {
        int x = solve(s+s), y = solve(s+s+s+s);
        ans = 1ll*(y-x)*k/2+2*x-y;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int sumt,sums,sum;
int main()
{
	std::ios::sync_with_stdio(false);
	cin>>s;
	int n=s.size();
	for(int i=0;i<n;i++)
	{
		if(s[i]=='S') sums++;
		else if(sums) sumt++;
		if(sums>=sumt)
		{
			sum+=min(sums,sumt)*2;
			sums-=min(sums,sumt);
			sumt=0;
		}
	}
	cout<<n-sum<<endl;
	return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>

template <class T>
inline void read(T &x)
{
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

long long n, ans = 1e12;

int main()
{
    read(n);
    long long q = sqrt(n);
    for (int i = 1; i <= q; ++i)
    {
        if (n % i == 0)
        {
            ans = std::min(ans, (i + n / i) - 2);
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
n=int(input())
d=[int(i) for i in input().split()]
m=int(input())
t=[int(i) for i in input().split()]
p=1
w={}
for i in d:
    if i in w: w[i]+=1
    else: w[i]=1
for i in t:
    if i in w and w[i]>0:
        w[i]-=1
    else:
        p=0
        break
print(["NO","YES"][p])


Measured memory_bytes: 127572
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

int d[1000005] = {};
int main(){
    
    int n;
    cin >> n;
    ll a[n] = {};
    inrep(n,a);

    rep(i,1,n)a[i] += a[i-1];

    map<ll,ll> m;
    ll ans = 0;
    m[0]++;
    rep(i,0,n){
	ans += m[a[i]];
	m[a[i]]++;
    }
    P(ans);
    
    return  0;
}


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

long long n;
vector<long long> a, memo;

long long solve();

int main() {
  cin >> n;
  ++n;
  a.resize(n);
  for (auto &p : a) cin >> p;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0, now = 1;
  memo.assign(n, 0);
  memo[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; --i) memo[i] = memo[i + 1] + a[i];
  now = 1;
  for (int i = 0; i < n; ++i) {
    now = min(memo[i], now);
    res += now;
    now -= a[i];
    if (now < 0) return -1;
    now *= 2;
  }
  if (n == 1 && a[0] != 1) return -1;
  return res;
}


Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
//for(int i = 0; i < n; i++){}

int main()
{
    int p , q , r;
    cin  >> p >> q >> r;
    int m = max(p, max(q,r));
    cout << p + q +  r - m;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>

using namespace std;

int main()
{
	int a;
	int b;
	int c;
	int d;
	int e;
	int f;
	int g;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	cin >> e;
	f = a*e;
	if (c < e)
	{
		g = b + (e - c)*d;
	}
	else
	{
		g = b;
	}
	if (f > g)
	{
		cout << g << endl;
	}
	else
	{
		cout << f << endl;
	}
		return 0;
}

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

using namespace std;
typedef long long int ll;
ll N1097 = 1000000007LL;

int h[100000];
ll dp[100000];
int main(){
    int N, K;
    cin >> N >> K;
    for(int i=0;i<N;i++){
        scanf("%d", &h[i]);
        dp[i] = INT64_MAX;
    }
    dp[0] = 0;
    for(int i=0;i<N;i++){
        for(int k=1;k<=K;k++){
            int pos = i+k;
            if(pos>=N) break;
            dp[pos] = min(dp[pos], dp[i]+abs(h[i]-h[pos]));
        }
    }
    cout << dp[N-1] << endl;
}




Measured memory_bytes: 1408
n = int(input())
s = input()
q = int(input())


class SegmentTree:
    def __init__(self, a, func=max, one=-10 ** 18):
        self.logn = (len(a) - 1).bit_length()
        self.n = 1 << self.logn
        self.func = func
        self.one = one

        self.b = [self.one] * (2 * self.n - 1)
        for i, j in enumerate(a):
            self.b[i + self.n - 1] = j
        for i in reversed(range(self.n - 1)):
            self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])

        self.ll = []
        self.rr = []
        i = self.n
        for _ in range(self.logn+1):
            for j in range(0, self.n, i):
                self.ll.append(j)
                self.rr.append(j + i)
            i //= 2

    def get_item(self, i):
        return self.b[i + self.n - 1]

    def update(self, index, x):
        i = index + self.n - 1
        self.b[i] = x
        while i != 0:
            i = (i - 1) // 2
            self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])

    def update_func(self, index, x):
        i = index + self.n - 1
        self.b[i] = self.func(self.b[i], x)
        while i != 0:
            i = (i - 1) // 2
            self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])

    def get_segment(self, l, r, i=0):
        ll = self.ll[i]
        rr = self.rr[i]
        if l <= ll and rr <= r:
            return self.b[i]
        elif rr <= l or r <= ll:
            return self.one
        else:
            return self.func(self.get_segment(l, r, i * 2 + 1),
                             self.get_segment(l, r, i * 2 + 2))


def get_int(s):
    abc = "abcdefghijklmnopqrstuvwxyz"
    return 1 << abc.index(s)


seg = SegmentTree([get_int(i) for i in s], int.__or__, 0)

for _ in range(q):
    q, i, j = input().split()
    if q == "1":
        seg.update(int(i) - 1, get_int(j))
    else:
        aa = seg.get_segment(int(i) - 1, int(j))
        ans = 0
        for i in range(26):
            if (aa >> i) & 1 == 1:
                ans += 1
        print(ans)


Measured memory_bytes: 135236
def linearSearch(A, n, key):
	i = 0
	A.append(key)
	while (A[i] != key):
		i += 1
	del A[n]

	return i != n


if __name__ == '__main__':
	
	n = int(input())
	L = list(map(int, input().split()))

	q = int(input())
	Key = list(map(int, input().split()))

	count = 0
	for i in range(q):
		if (linearSearch(L, n, Key[i])):
			count += 1
print(count)



Measured memory_bytes: 6552
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int maisu=sc.nextInt();
		long sum=sc.nextLong();
		long kei=0;
		for(int i=0; i<=maisu; i++) {
			for(int j=0; j<=maisu-i; j++) {
				kei=i*1000+j*5000+(maisu-i-j)*10000;
				if(kei==sum) {
					System.out.println((maisu-i-j)+" "+j+" "+i);
					System.exit(0);
				}
			}
		}
		System.out.println("-1 -1 -1");
	}
}

Measured memory_bytes: 21844
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val s = next()
    println(if (s.substring(5, 7).toInt() < 5) "Heisei" else "TBD")
}

fun next() = readLine()!!

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 29736
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

int main() {
    int N;
    cin>>N;
    for (int i = 1; i < 10; ++i) {
        if(N%i==0&&N/i<10){
            cout<<"Yes"<<endl;
            return 0;
        }

    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
#include <random>
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;
 
long long gcd(long long a, long long b) {
    if (b == 0) return a;
    return gcd(b,a%b);
}
 
long long lcm(long long a, long long b) {
    return a / gcd(a,b) * b;
}
 
int main() {
 
    ll N;
    cin >> N;
    ll ans = 1;
    REP(i,N) {
        ll t; cin >> t;
        ans = lcm(ans,t);
    }
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
w = gets.to_i
n = gets.to_i
c = []
w.times{|i| c[i] = i + 1}
for i in 1..n do
  a, b = gets.split(",").map(&:to_i)
  tem = c[a-1]
  c[a-1] = c[b-1]
  c[b-1] = tem
end
puts c

Measured memory_bytes: 6112
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cctype>
#include <utility>

using namespace std;

using int64 = long long;

template <class T>
class CoodinateCompression {
 public:
  CoodinateCompression(const std::vector<T>& vec) : vec_(vec) {
    result_.resize(vec_.size());
    Compress();
  }
  struct state {
    T before;
    int after;
  };
  state operator[](int pos) const { return result_[pos]; }

 private:
  std::vector<T> vec_;
  std::vector<state> result_;
  void Compress() {
    std::vector<T> t = vec_;
    std::sort(t.begin(), t.end());
    t.erase(std::unique(t.begin(), t.end()), t.end());
    for (size_t i = 0; i < vec_.size(); ++i) {
      result_[i] = {vec_[i], static_cast<int>(std::distance(
                                t.begin(),
                                std::lower_bound(t.begin(), t.end(), vec_[i])))};
    }
  }
};

template <class Monoid, class Function>
class SegmentTree {
 public:
  SegmentTree(const std::vector<Monoid>& data, Monoid identity_element,
              Function function)
      : identity_element_(identity_element), data_(data), function_(function) {
    Build();
  }
  void Update(size_t position, Monoid new_value) {
    position += n_;
    node_[position] = new_value;
    while (position > 0) {
      position >>= 1;
      node_[position] = function_(node_[2 * position], node_[2 * position + 1]);
    }
  }

  Monoid Query(int left, int right) {
    Monoid vl = identity_element_, vr = identity_element_;
    for (left += n_, right += n_; left < right; left >>= 1, right >>= 1) {
      if (left & 1) vl = function_(vl, node_[left++]);
      if (right & 1) vr = function_(node_[--right], vr);
    }
    return function_(vl, vr);
  }

  Monoid operator[](size_t position) const { return node_[n_ + position]; }

 private:
  size_t n_;
  Monoid identity_element_;
  std::vector<Monoid> data_;
  std::vector<Monoid> node_;
  Function function_;
  void Build() {
    size_t SIZE = data_.size();
    n_ = 1;
    while (n_ < SIZE) {
      n_ <<= 1;
    }
    node_.assign(2 * n_, identity_element_);
    for (size_t i = 0; i < SIZE; ++i) {
      node_[i + n_] = data_[i];
    }
    for (size_t i = n_ - 1; i > 0; --i) {
      node_[i] = function_(node_[2 * i], node_[2 * i + 1]);
    }
  }
};

template<class T> inline void fastin(T &num) {
  T c;
  num = 0;
  c = getchar_unlocked();
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
}

int main() {
  int n; fastin(n);
  int64 k; fastin(k);
  vector<int64> a(n);
  for (int i = 0; i < n; ++i) {
    fastin(a[i]);
    a[i] -= k;
  }

  vector<int64> sum(n + 1, 0LL);
  for (int i = 0; i < n; ++i) {
    sum[i + 1] = sum[i] + a[i];
  }

  auto f = [](int x, int y){ return x + y; };
  SegmentTree<int, decltype(f)> seg(vector<int>(n + 1, 0), 0, f);

  CoodinateCompression<int64> cc(sum);
  seg.Update(cc[0].after, 1);

  int64 ans = 0;

  for (int i = 1; i < n + 1; ++i) {
    ans += static_cast<int64>(seg.Query(0, cc[i].after + 1));
    seg.Update(cc[i].after, seg[cc[i].after] + 1);
  }

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

  return 0;
}

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

public class Main {
	public static void main(String[] args){
		try(Scanner sc=new Scanner(System.in)){
			while(sc.hasNext()) {
				int n=sc.nextInt();
				if(n==0)	break;
				int[] p=new int[n];
				int[] plu=new int[n-1];
				long plength=0, ans=0;
				for(int i=0; i<n; i++) {
					p[i]=sc.nextInt();
					plength+=p[i];
				}
				for(int i=0; i<n-1; i++) {
					plu[i]=sc.nextInt();
				}
				Arrays.sort(plu);
				ans=plength*n;
				for(int i=n-2; i>=0; i--) {
					plength+=plu[i];
					if(ans<plength*(i+1))	ans=plength*(i+1);
					else	break;
				}
				System.out.println(ans);
			}
			
		}
	}	
}


Measured memory_bytes: 150196
n = int(input())
al = [int(i) for i in input().split()]
m = int(input())
bl = [int(i) for i in input().split()]


ans_set = set()
for i in range(1,1<<n):
    num = 0
    for j in range(n):
        if (i >> j) & 1:
            num += al[j]
    ans_set.add(num)
    
    
for i in bl:
    if i in ans_set:
        print('yes')
    else:
        print('no')



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

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> S(N+1);
    vector<int> K(M);
    vector<bool> broken(N,false);
    for(int i=0;i<M;i++){
        cin>>K[i];
        broken[K[i]]=true;
    }
    S[0]=1;
    if(broken[1]==true){
        S[1]=0;
    }
    else{
        S[1]=1;
    }
    int mod=pow(10,9)+7;
    for(int i=2;i<N+1;i++){
        if(broken[i]==true){
            S[i]=0;
        }
        else{
            S[i]=S[i-1]+S[i-2];
            S[i]%=mod;
        }
    }
    cout<<S[N]<<endl;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] arr = new int[3];
        for (int i = 0; i < 3; ++i) {
            arr[i] = in.nextInt();
        } Arrays.sort(arr);
        int ans = 0;
        for (int i = 1; i < 3; ++i) {
            ans += Math.abs(arr[i] - arr[i - 1]);
        }

        System.out.println(ans);
    }


}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#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)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    ll X; cin >> X;
    int ans = 0;
    ll now = 100;
    while(now < X){
        now += now/100;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int n, m;
    cin >> n >> m;
    int co = 0;
    int wa = 0;
    vector<int> ac(n);
    vector<int> wc(n);
    rep(i, n){
      ac.at(i) = 0;
      wc.at(i) = 0;
    }
    rep(i, m){
      int a;
      string st;
      cin >> a >> st;
      a--;
      if(st == "AC"){
        if(ac.at(a) == 0){
          co++;
          wa += wc.at(a);
          ac.at(a) = 1;
        }
      }else{
        wc.at(a)++;
      }
    }
    cout << co << ' ' << wa << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
  long a,b,x;
  cin>>a>>b>>x;
  long c,d;
  if(a==0){
      d=long(b/x);
      cout<<d+1<<endl;
  }
  else{
    c=long((a-1)/x);
    d=long(b/x);
    cout<<d-c<<endl;
  }
}

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

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

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second

/*-------------------------------------------------*/

int main(){
  int n, ans = 0;
  cin >> n;
  vector<int> L(n);
  rep(i, n) cin >> L[i];

  sort(all(L));

  for(int i = 0; i < n; i++){
    for(int j = i + 1; j < n; j++){
      for(int k = j + 1; k < n; k++){
        if(L[k] < L[i] + L[j] &&
           L[i] != L[j] &&
           L[j] != L[k] &&
           L[k] != L[i] )
          ans++;
      }
    }
  }
  cout << ans << endl;
return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n, m = f.read_int_list()
    c = [f.read_int_list() for _ in xrange(n)]

    ans = -float('inf')
    for sgn in itertools.product([1,-1], repeat=3):
        cand = [sgn[0]*ci[0]+sgn[1]*ci[1]+sgn[2]*ci[2] for ci in c]
        cand.sort(reverse=True)
        ans = max(sum(cand[:m]), ans)

    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Measured memory_bytes: 6288
def popcount(n):
    ans=0
    for i in range(20):
        if n>>i & 1:
            ans+=1
    return ans

N=int(input())
X=input()
n=0

for i in range(N):
    if X[i]=='1':
        n+=1
np1=0
nm1=0
temp1=1
temp2=1
nm=n-1
if nm==0:
    nm=1
for i in range(N-1,-1,-1):
    if X[i]=='1':
        np1=(np1+temp1)%(n+1)
        nm1=(nm1+temp2)%nm
    temp1=(temp1*2)%(n+1)
    temp2=(temp2*2)%nm
    
for i in range(N):
    ans=1
    if X[i]=='1':
        if n==1:
            print(0)
            continue
        temp=(nm1-pow(2,(N-1-i),n-1))%(n-1)
        while temp>0:
            pop_n=popcount(temp)
            temp=temp%pop_n
            ans+=1
    elif X[i]=='0':
        temp=(np1+pow(2,(N-1-i),n+1))%(n+1)
        while temp>0:
            pop_n=popcount(temp)
            temp=temp%pop_n
            ans+=1
    print(ans)

Measured memory_bytes: 9440
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        bool f=1;
        rep(i,0,200)
        {
            if(i%2==0)
            {
                c-=b;
                if(c<=0)
                {
                    break;
                }
            }
            else
            {
                a-=d;
                if(a<=0)
                {
                    f=0;
                    break;
                }
            }

        }
        if(f)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3668
use bigint;
$n=<>;
$p=$q=1;
for(1..$n){
    ($x,$y)=glob<>;
    $m1=int(($p+$x-1)/$x);
    $m2=int(($q+$y-1)/$y);
    $m=($m1>$m2)?$m1:$m2;
    $p=$x*$m;$q=$y*$m;
}
print $p+$q

Measured memory_bytes: 4992
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

A = list(map(int,input().split()))
count = 0
while not (A[0] == A[1] == A[2]):
  count += 1
  A.sort()
  if A[0] != A[1]:
    A[0] += 2
  else:
    A[0] += 1
    A[1] += 1
print(count)
  
  


Measured memory_bytes: 38256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int main()
{
	std::vector<int>e(4);
	in >> e[0] >> e[1] >> e[2] >> e[3];
	std::sort(e.begin(), e.end());
	if (e[0] == e[1] && e[2] == e[3]) out << "yes" << std::endl;
	else out << "no" << std::endl;
}



Measured memory_bytes: 3160
#include <iostream>
using namespace std;
int main () {
    int m, n, b;
    cin >> n >> m;
    int a[n][m];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> a[i][j];
    
    for (int i = 0; i < m; i++) {
        cin >> b;
        for (int j = 0; j < n; j++)
            a[j][i] *= b;
    }

    for (int i = 0; i < n; i++) {
        int sum = 0;
        for (int j = 0; j < m; j++)
            sum += a[i][j];
        cout << sum << "\n";
    }
}


Measured memory_bytes: 3120
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

long dp[110][100010];

int main(){
    int n, W;
    cin >> n >> W;
    int w[n], v[n];
    for(int i = 0; i < n; i++){
        cin >> w[i] >> v[i];
    }

    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= W; j++){
            if(j>=w[i-1]) {
                dp[i][j] = max(max(dp[i][j - 1], dp[i - 1][j - w[i - 1]] + v[i - 1]), dp[i-1][j]);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }

//    for(int i = 0; i <= n; i++) {
//        for(int j = 0; j <= W; j++) {
//            cerr << dp[i][j] << " ";
//        }
//        cerr << endl;
//    }

    cout << dp[n][W] << endl;

    return 0;
}


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

int main() {
  int X;
  cin >> X;
 
  vector<int> M(51);
  for (int i = 0; i < 31; i++) {
    M.at(i) = (i + 1)*(i + 1);
  }
  for (int i = 1; i < 10; i++) {
    M.at(i+30) = (i + 1)*(i + 1)*(i + 1);
  }
  for (int i = 1; i < 5; i++) {
    M.at(i+39) = (i + 1)*(i + 1)*(i + 1)*(i + 1);
  }
  for (int i = 1; i < 3; i++) {
    M.at(i+43) = (i + 1)*(i + 1)*(i + 1)*(i + 1)*(i + 1);
  }
  for (int i = 1; i < 3; i++) {
    M.at(i+45) = (i + 1)*(i + 1)*(i + 1)*(i + 1)*(i + 1)*(i + 1);
  }
  M.at(48) = 128;
  M.at(49) = 256;
  M.at(50) = 512;
  sort(M.begin(), M.end());
  
  int count = 0;
  int A;
  for (int i = X; i > 0; i--) {
    if (count == 1){
      break;
    }
    for (int j = 50; j >= 0; j--) {
      if (M.at(j) == i){
        count++;
        A = i;
        break;
      }
    }
  }
  cout << A << endl;
}



Measured memory_bytes: 256
n,a,b = map(int, input().split())
ans = b-a
if ans%2==0:
    print(ans//2)
else:
    if a-1 > n-b:
        a = a+ n-b+1
        print((n-a)//2 + n-b+1)
    else:
        b = b-a+2
        print((b-1)//2 +a-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fordec(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define int long long
#define fi first
#define se second

const int maxn=1e5+5;
int f[maxn]; ///f[i]=1 neu nguoi 1 thang khi con i vien soi
int a[maxn],k,n ;
main()
{
    cin>>n>>k;
    forinc(i,1,n) cin>>a[i];

    forinc(x,1,k)
    {
        forinc(i,1,n)
        {
            /// den turn minh con x soi
            /// gia su lay ai soi thi con x-a[i]
            /// vi f[x-a[i]]=0 nghia la nguoi thu 2 thua nen trang thai f[x]=1 la nguoi 1 thang
            if(x>=a[i]&&!f[x-a[i]]) f[x]=1;
        }
    }
    cout<<(f[k]==1?"First":"Second");
}


Measured memory_bytes: 1024
#include <stdio.h>
#define M 10000

int linearSearch(int [ ], int , int );

int main (){
	int n, S[M],q,i,fact;
	int count = 0;
	scanf("%d",&n);
	for(i = 0; i < n ; i++){
		scanf("%d",&S[i]);
	}
	scanf("%d",&q);
	for(i = 0; i < q ; i++){
		scanf("%d",&fact);
		if( linearSearch(S,n,fact)) count++;
	}
	printf("%d\n",count);
}

int linearSearch(int R[ ],int n,int x) {
int i;
	for(i = 0; i < n; i++){
		if(R[i] ==  x) {
			return 1;
			}
	}
	return 0;
}


Measured memory_bytes: 2108
#include<iostream>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a + b >= a - b && a + b >= a* b) {
		cout << a + b << endl;
	}
	else if (a - b >= a + b && a - b >= a* b) {
		cout << a - b << endl;
	}
	else cout << a * b << endl;
}

Measured memory_bytes: 256
from itertools import permutations
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    m,k=MI()
    if (m,k)==(1,1) or k>=2**m:ans=[-1]
    elif k==0:
        ans=list(range(1<<m))
        ans+=ans[::-1]
    else:
        ans=[]
        for i in range(1<<m):
            if i==k:continue
            ans.append(i)
        rev=ans[::-1]
        ans.append(k)
        ans+=rev
        ans.append(k)
    print(*ans)

main()


Measured memory_bytes: 16604
import java.util.*;
 
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
 
    label:
    while(sc.hasNextLine()){
      int h = sc.nextInt();
      int w = sc.nextInt();
       
      if(h==0 && w==0) break label;
      for(int j = 1; j<=h; j++){
        for(int i = 1; i<=w; i++){
          System.out.print("#");
        }
        System.out.println("");
      }
        System.out.println("");
    }
     
  }
}


Measured memory_bytes: 36328
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
    int n;
    cin >> n;
    int a=0;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            if(i*j==n) a=1;
        }
    }
    cout << ( a==1 ? "Yes":"No" )  << endl;
}

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

#define MOD 998244353LL

using namespace std;

int main() {
  int A, B, C, D;
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> D;
  vector <vector <long long> > dp(C + 1, vector <long long> (D + 1, 0LL));
  dp[A][B] = 1LL;
  for (int c = A; c <= C; ++c) {
    for (int d = B; d <= D; ++d) {
      if (c == A && d == B) continue;
      dp[c][d] = 
        ((long long)d * dp[c - 1][d] % MOD)
        + ((long long)c * dp[c][d - 1] % MOD)
        - (dp[c - 1][d - 1] * (long long)(c - 1) * (d - 1) % MOD);
      if (dp[c][d] < 0) dp[c][d] += MOD;
      dp[c][d] %= MOD;
    }
  }

  cout << dp[C][D] << endl;
  return 0;
}

Measured memory_bytes: 73312
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}

//combination(Nが小さい時はこれを使う)
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

//debug処理
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
signed main() {
	int x;
	cin >> x;
	cout << x / 500 * 1000 + (x % 500) / 5 * 5 << endl;
	ggr
}


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

int main(){
    long int n;
    cin >> n;
    long int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    long int max=a[0];
    long int min=a[0];
    long int sum=0;

    for(int i=1; i<n; i++){
        if (a[i] > max){
            max=a[i];
        }
    }
    for(int i=1; i<n; i++){
        if (a[i] < min){
            min=a[i];
        }
    }
    for(int i=0; i<n; i++){
        sum=a[i]+sum;
    }
    cout << min <<" "<< max <<" "<< sum <<"\n";
    return 0;
}



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

int *F;

void defFibonacci(int n){
  int i;

  F[0] = 1;
  F[1] = 1;
  for (i = 2; i <= n; i++) {
    F[i] = -1;
  }
}

int fibonacci(int n){
  if (n==0 || n==1) {
    return F[n]=1;
  }
  if (F[n]!=-1) {
    return F[n];
  }else{
    return F[n] = fibonacci(n - 2) + fibonacci(n - 1);
  }
}

int main() {
  int n;
  int i;

  scanf("%d",&n);
  F = malloc(sizeof(int) * (n+1));
  defFibonacci(n);
  printf("%d\n",fibonacci(n));

  free(F);
  return 0;
}



Measured memory_bytes: 2104
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
const int Mod = 1e9 + 5;
int lst[Max];
int ls[Max];

int main()
{
	int n;
	cin >> n;
	int x = 0, y = 0;
	int t = 0;
	for (int i = 1;i <= n;i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		if (abs(b - x) + abs(c - y) > a-t)
		{
			cout << "No" << endl;
			return 0;
		}
		else
		{
			if (-(abs(b - x) + abs(c - y) + (a-t)) % 2 != 0)
			{
				cout << "No";
				return 0;
			}
		}
		t = a;x = b;y = c;
	}
	cout << "Yes";
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
inline int read()
{int x=0,f=0;
char c=getchar();
while (c<'0'||c>'9') 
{if (c=='-') f=1;
c=getchar();
}
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
if (f) x=-x;
return x;
}
int n;
ll num[100005],a[100005];
int main (){
	int i;
	n=read();
	for (i=1;i<=n;i++)
	{a[i]=read();}
	ll lo=2,hi=2;
	for (i=n;i>=1;i--)
	{if (lo%a[i]!=0&&hi%a[i]!=0&&lo/a[i]==hi/a[i]) {puts("-1");return 0;}
	lo=((lo-1)/a[i]+1)*a[i];
	hi=(hi/a[i])*a[i]+a[i]-1;
	}
	printf ("%lld %lld",lo,hi);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
int main() {
int N,M;
int i;
int a[3];
i = 0;
a[3] = {0};
scanf("%d", &N);
M = N;

a[i] = (N % 10); N /= 10;// 1桁目を取り出す
//printf("%d\n",a[i]);
// if(M >= 10){
//     i++;
//     a[i] = (N % 10); N /= 10;// 2桁目を取り出す
//     printf("%d\n",a[i]);
// }
// if(M >= 100){
//     i++;
//     a[i] = (N % 10); N /= 10;// 3桁目を取り出す
//     printf("%d\n",a[i]);
// }
if((a[i] == 2) || (a[i] == 4) || (a[i] == 5) || (a[i] == 7) || (a[i] == 9)){
     std::cout << "hon" <<  std::endl;
}else if((a[i] == 0) || (a[i] == 1) || (a[i] == 6) || (a[i] == 8)){
     std::cout << "pon" <<  std::endl;
}else{
     std::cout << "bon" <<  std::endl;
}

return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

template <typename T> T gcd(T a, T b) { while (a) { b %= a; swap(a, b); } return b; }
template <typename T> T lcm(T a, T b) { return a / gcd(a,b) * b; }

signed main()
{
    ll N;
    cin >> N;
    printf("%lld\n", lcm((ll)2, N));
    return 0;
}


Measured memory_bytes: 256
N = int(input())
mylist = [int(s) for s in input().split()]
mylist.sort()
#myans = 0

#for i in range(N):
#    myans += 1/int(mylist[i])
#print(mylist)

myans = (mylist[0]+mylist[1])/2 

for i in range(2, len(mylist)):
    myans = (myans + mylist[i])/2

print(myans)

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

int main() {
	// your code goes here
	int a,b;
	cin>>a>>b;
	if(a==b){
		cout<<"a == b"<<endl;
	}else{
		if(a>b){
			cout<<"a > b"<<endl;
		}else{
			cout<<"a < b"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int N, K;

int dfs(int fac, vector<int> &L, int s, int t){
  if(fac == 0){
    for(int i = 0; i < L.size(); i++){
      if(s + L[i] >= t){
        return s + L[i];
      }else{
        continue;
      }
      return -1;
    }
  }else if(fac == (int)log10(N)+1){
    int ans;
    if(dfs(fac - 1, L, s, t) != -1 && dfs(fac - 1, L, s, t) >= t){
      int tmp = dfs(fac - 1, L, s, t);
      ans = tmp;
      return ans;
    }else{
      for(int i = 0; i < L.size(); i++){
        int tmp = dfs(fac - 1, L, s+L[i]*pow(10,fac), t);
        if(tmp == -1) continue;
        if(tmp < t) continue;
        ans = tmp;
        break;
      }
    return ans;
    }
  }else{
    int ans;
    for(int i = 0; i < L.size(); i++){
      int tmp = dfs(fac - 1, L, s+L[i]*pow(10,fac), t);
      if(tmp == -1) continue;
      if(tmp < t) continue;
      ans = tmp;
      break;
    }
    return ans;
  }
}

int main(){
  //int N, K;
  cin >> N >> K;
  
  vector<bool> D(10, false);
  for(int i = 0; i < K; i++){
    int tmp;
    cin >> tmp;
    D[tmp] = true;
  }
  vector<int> L;
  for(int i= 0; i < 10; i++){
    if(!D[i])L.push_back(i);
  }
  int ans = 0;
  int f = (int)log10(N)+1;
  ans = dfs(f, L, 0, N);
  cout << ans;
}


Measured memory_bytes: 256