akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
n, a, b, c, d = map(int, input().split())
s = input()

if '##' in s[a - 1:c] or '##' in s[b - 1:d]:
    print('No')
else:
    if c < d:
        print('Yes')
    else:
        if '...' in s[b - 2:d + 1]:
            print('Yes')
        else:
            print('No')

Measured memory_bytes: 3640
#include<stdio.h>

int main(){

int n,i,x;

scanf("%d",&n);

for(i=1;i<=n;i++){
x=i;
if(x%3==0){
printf(" %d",i);

}else{
while(x!=0){
if(x%10==3){
printf(" %d",i);
break;
}
x/=10;
}}}


printf("\n");

return 0;
}

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



int main() {
	string ans = "";
	ll n; cin >> n;
	
	ll nc = n;
	
	int cnt = 0;
	
	while(nc > 0){
		nc --;
		nc /= 26;
		cnt++;
	}
	
	vector<int> a(cnt);
	
	nc = n;
	
	rep(i, cnt){
		a[i] = nc % 26;
		if(a[i] == 0) a[i] = 26;
		nc = (nc-1)/26;
	}
	
	rep(i, cnt) {
		char c = 'a' + a[i]-1;
		ans = ans + c;
	}
	
	reverse(ans.begin(), ans.end());
	
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-9, pi = acos(-1.0);
namespace std {
    bool operator<(const Point &lhs, const Point &rhs) {
        if (lhs.real() < rhs.real() - eps) return true;
        if (lhs.real() > rhs.real() + eps) return false;
        return lhs.imag() < rhs.imag();
    }
}
Point input_point() {ld x, y; cin >> x >> y; return Point(x, y);} // ????????\???
bool eq(ld a, ld b) {return (abs(a - b) < eps);} // ????????????????????????
ld dot(Point a, Point b) {return real(conj(a) * b);} // ??????
ld cross(Point a, Point b) {return imag(conj(a) * b);} // ??????

// ??´????????????
class Line {
public:
    Point a, b;
    Line() : a(Point(0, 0)), b(Point(0, 0)) {}
    Line(Point a, Point b) : a(a), b(b) {}
    Point operator[](const int _num) {
        if (_num == 0)return a;
        else if (_num == 1)return b;
        else assert(false);
    }
};

// ????????????
class Circle {
public:
    Point p;
    ld r;
    Circle() : p(Point(0, 0)), r(0) {}
    Circle(Point p, ld r) : p(p), r(r) {}
};

/*
 ??????????????´??????
 ?????????2 ?????´???1 otherwise???0
 */
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    int q; cin >> q;
    for(int i = 0; i < q;i++){
        Point p0 = input_point();
        Point p1 = input_point();
        Point p2 = input_point();
        Point p3 = input_point();
        
        Point s1 = p1 - p0, s2 = p3 - p2;
        if(abs(cross(s1,s2)) < eps) cout << 2 << endl;
        else if(abs(dot(s1,s2)) < eps) cout << 1 << endl;
        else cout << 0 << endl;
    }
    return 0;
}

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

int main(){
  int N, L;
  scanf("%d",&N);
  scanf("%d",&L);
  int min = abs(L);
  int eating = 1;
  
  for(int i = 2; i <= N; i++){
    if(abs(L + i - 1) < min){
      min = abs(L + i - 1);
      eating = i;
    }
  }
  
  int sum = 0;
  for(int i = 1; i <= N; i++){
    sum += L + i - 1;
  }
  sum -= L + eating - 1;
  printf("%d", sum);
  return 0;
}

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

int main() {
	int N;
	int ans = 0;
	string S;

	cin >> N;
	cin >> S;

	for (int i = 0; i < N - 2; i++) {
		if (S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C') {
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long N, M, Q;
long long a[100005];
long long b[100005];
long long idx[100005];

vector<long long> ans;
set<long long> done;

int main(){
	cin >> N >> M >> Q;
	for(int i = 0; i < Q; i++){
		cin >> a[i];
		a[i]--;
	}

	//create correct
	for(int i = Q - 1; i >= 0; i--){
		if(done.count(a[i]) == 0){
			ans.push_back(a[i]);
			done.insert(a[i]);
		}
	}
	for(int i = 0; i < M; i++){
		if(done.count(i) == 0){
			ans.push_back(i);
			done.insert(i);
		}
	}

	for(int i = 0; i < ans.size(); i++){
		idx[ans[i]] = i;
	}
	b[0] = N;
	
	for(int i = Q - 1; i>=0;i--){
		if(b[idx[a[i]]] > 0){
			b[idx[a[i]]]--;
			b[idx[a[i]]+1]++;
		}
	}

	long long mini = M;
	for(long long i = 0; i < M; i++){
		//cout << "b[" << i << "]=" << b[i] << endl;
		if(b[i]>0){
			mini = min(mini, i);
		}
	}

	done.clear();
	for(int i = 0; i < mini; i++){
		done.insert(ans[i]);
	}
	long long idx = mini;

	for(int i = 0; i < M; i++){
		if(done.count(i) == 0){
			//cout << "i=" << i << " idx = " << idx << endl;
			if(ans[idx] != i){
				cout << "No" << endl;
				return 0;
			}
			idx++;
		}
	}
	cout << "Yes" << endl;


	//for(long long i = mini; i < M; i++){
	//	if(ans[i] != i){
	//		cout << "No" << endl;
	//		return 0;
	//	}
	//}
	//cout << "Yes" << endl;
}


Measured memory_bytes: 8180
#include<bits/stdc++.h>
using namespace std;
#define gc() getchar()
#define pc(a) putchar(a)
#define int long long
#define inf (1ll<<60)
inline int read()
{
    int x=0,f=1;
    char c=gc();
    while(c>'9'||c<'0')
    {
        if(c=='-') f=-f;
        c=gc();
    }
    while(c>='0'&&c<='9') x=x*10+c-'0',c=gc();
    return x*f;
}
int Num[25];
inline void write(int x)
{
    if(!x) {pc('0');return;}
    if(x<0) x=-x,pc('-');
    int top=0;
    while(x) Num[++top]=x%10,x/=10;
    while(top) pc(Num[top--]+'0');
    return;
}
#define ma 300005

signed main()
{
   int n=read(),ans=0;
   int mx=0;
   for(int i=1;i<=n;i++)
   {
		int x=read(),y=read();
		if(x==y) ans++,mx=max(mx,ans);
		else ans=0;
   }
   puts(mx>=3?"Yes":"No");
}










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

#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define ld long double
#define pb push_back
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000000

ll mulmod(ll, ll);
ll fastpower(ll, ll);
void getprime(vector<ll>&);
void getfact(vector<ll>&, vector<ll>&);
ll ncr(ll, ll, vector<ll>&, vector<ll>&);

void solve()
{
    ll n, k;
    cin>>k>>n;
    if(500 * k >= n)
        Yes();
    else
        No();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t = 1;
    //cin>>t;
    while(t--)
    {
        solve();        
    }
    return 0;
}

ll mulmod(ll a, ll b)
{
    ll res = 0; 
    a = a % MOD;
    while(b > 0)
    {
        if (b % 2 == 1)
            res = (res + a) % MOD;
 
        a = (a * 2) % MOD; 
        b /= 2;
    } 
    return res % MOD; 
}

ll  fastpower(ll a, ll n)
{
    ll res = 1;
    while(n > 0)
    {
        if(n % 2 != 0)
        {
            res = (res * a) % MOD;
        }
        n /= 2;
        a = (a * a) % MOD;
    }
    return res;
}

void getprime(vector<bool>&prime)
{
    prime[0] = false;
    prime[1] = false;
    
    for(ll i = 2;i <= MAX; i++)
    {
        if(prime[i])
        {
            for(ll j = i*i; j <= MAX; j += i)
                prime[j] = false;
        }
    }
}

void getfact(vector<ll> &fact, vector<ll> &ifact)
{
    fact[0] = 1;
    ifact[0] = 1;
    
    for(ll i = 1; i <= MAX; i++)
    {
        fact[i] = (fact[i-1] * i)%MOD;
        ifact[i] = (ifact[i-1] * fastpower(i, MOD -2) )%MOD;
    }
}

ll ncr(ll n, ll r, vector<ll>&fact, vector<ll>&ifact)
{
    ll res;
    res = (((fact[n] * ifact[r]) % MOD) * ifact[n-r]) % MOD;
    return res;
}


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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		
		ArrayList<ArrayList<Integer>> lists = new ArrayList<ArrayList<Integer>>(); 
		
		for(int i = 0; i < r; i++) {
			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int j = 0; j < c; j++) {
				list.add(scan.nextInt());
			}
			lists.add(list);
		}
		
		int temp = 0;
		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				temp += lists.get(i).get(j);
			}
			lists.get(i).add(temp);
			temp = 0;
		}
		
		ArrayList<Integer> list_kari = new ArrayList<Integer>();
		int tempForAll = 0;
		for(int i = 0; i < c; i++) {
			for(int j = 0; j < r; j++) {
				temp += lists.get(j).get(i);
			}
			list_kari.add(temp);
			tempForAll += temp;
			temp = 0;
		}
		list_kari.add(tempForAll);
		lists.add(list_kari);
		
		for(int i = 0; i < r + 1; i++) {
			for(int j = 0; j < c + 1; j++) {
				if(j == 0) System.out.print(lists.get(i).get(j));
				else System.out.print(" " + lists.get(i).get(j));
			}
			System.out.println();
		}
		
	}

}



Measured memory_bytes: 42724
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int a,b;
    cin >> a >> b;
    bool ok=false;
    if(b<10){
        rp(i,100){
            if(a*10+b==i*i) ok=true;
        }
    }else if(b<100){
        rp(i,1000){
            if(a*100+b==i*i) ok=true;
        }
    }else{
        rp(i,1000){
            if(a*1000+b==i*i) ok=true;
        }
    }
    Yes(ok);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#define LL long long 
using namespace std;

int n,m,k;
LL s,d;
int main()
{
	scanf("%lld",&s);
	d=(LL)1e9-s%(LL)1e9;
	if(d==(LL)1e9) d=0;
	s/=(LL)1e9;
	if(d) s++;
	printf("0 0 %lld %d %lld %d",s,1,d,(int)1e9);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

long long n, k, mx, a[N], s[N], l[N], r[N];
int main() {
	int i;
	scanf("%d%d", &n, &k);
	for(i=1; i<=n; i++) {
		scanf("%lld", &a[i]);
		s[i] = s[i-1] + a[i];
		l[i] = l[i-1] + max(0LL, a[i]);
	}
	for(i=n; i>=k; i--) {
		r[i] = r[i+1] + max(0LL, a[i]);
		mx = max(mx, l[i-k] + r[i+1] + max(0LL, s[i] - s[i-k]));
	}
	printf("%lld", mx);
	return 0;
}

Measured memory_bytes: 3328
a,b,c,d=map(int,input())
l=[a+b+c+d,a-b+c+d,
   a+b+c-d,a-b+c-d,
   a+b-c+d,a-b-c+d,
   a+b-c-d,a-b-c-d]
if a+b+c+d==7:
  print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7");exit()
if a+b+c-d==7:
  print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7");exit()
if a+b-c+d==7:
  print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7");exit()
if a-b+c+d==7:
  print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7");exit()
if a+b-c-d==7:
  print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7");exit()
if a-b+c-d==7:
  print(str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7");exit()
if a-b-c+d==7:
  print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7");exit()
if a-b-c-d==7:
  print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7");exit()


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

const int N = 1e5 + 5;

int n, m;
int uf[N];
int d[N];
vector<int> G[N];

int find(int x) {
	return uf[x] == x ? x : (uf[x] = find(uf[x]));
}

void dfs(int p, int fa) {
	for (auto e : G[p]) {
		if (e ^ fa) {
			dfs(e, p);
		}
	}
	if (!fa)
		return;
	if (d[p]) {
		d[p] ^= 1;
		printf("%d %d\n", p, fa);
	} else {
		d[fa] ^= 1;
		printf("%d %d\n", fa, p);
	}
}

int main() {
	scanf("%d%d", &n, &m);
	if (m & 1) {
		puts("-1");
		return 0;
	}
	for (int i = 1; i <= n; i++)
		uf[i] = i;
	for (int i = 1, u, v; i <= m; i++) {
		scanf("%d%d", &u, &v);
		if (find(u) ^ find(v)) {
			uf[find(u)] = find(v);
			G[u].push_back(v);
			G[v].push_back(u);
		} else {
			printf("%d %d\n", u, v);
			d[u] ^= 1;
		}
	}
	dfs(1, 0);
	assert(!d[1]);
	return 0;
}


Measured memory_bytes: 11648
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}


 main()

{
    fast
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ses=0;
    if(k%2==0)ses+=(a-b);
    else ses+=(b-a);
    cout<<ses<<endl;
    return 0;

}













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

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

typedef long long ll;

using namespace std;

int INF = 1e9;

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

  int ans = 0;
  rep(i,n-1){
    for(int j = i+1; j < n; j++){
      ans += v[i] * v[j];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    private static int gcd(int a, int b) {
        if (a % b == 0) {
            return b;
        } else {
            return gcd(b, a % b);
        }
    }

    private static void solve() {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            System.out.println(gcd(a, b));
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,a,b;
  cin>>N;
  vector <int> num(N);
  vector <int> ans(N);
  for(int i = 0;i<N;i++){
    cin >> num.at(i);
    ans.at(i) = num.at(i);
  }
  sort(num.begin(),num.end());
  a = num.at(N/2-1);
  b = num.at(N/2);
  if(a == b){
    for(int i = 0;i<N;i++){
      cout << a << endl;
    }
  }
  else{
    for(int i = 0;i<N;i++){
      if(ans.at(i)<=a){cout << b << endl;}
      else{cout << a << endl;}
    }
  }
  return 0;
}
  
  
  
  
  

Measured memory_bytes: 3712
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new MyInputStream(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(MyInputStream cin)
        {
            var s = cin.Read();
            WriteLine($"{s.First()}{s.Length - 2}{s.Last()}");
        }
    }

    public class MyInputStream
    {
        private readonly System.IO.TextReader _stream;
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(System.IO.TextReader s, char separator = ' ')
        {
            this.separator = separator;
            this._stream = s;
            inputStream = new Queue<string>();
        }
        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = _stream.ReadLine().Split(separator);
            for (int i = 0; i < tmp.Length; ++i)
                inputStream.Enqueue(tmp[i]);
            return inputStream.Dequeue();
        }
        public string ReadLine() { return _stream.ReadLine(); }
        public int ReadInt() { return int.Parse(Read()); }
        public long ReadLong() { return long.Parse(Read()); }
        public double ReadDouble() { return double.Parse(Read()); }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read(); return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt(); return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong(); return ret;}
    }
}

Measured memory_bytes: 11476
#include <bits/stdc++.h>
using namespace std;
int n, k;
const int nx = 1e5 + 5;
long long ac[nx][2];
long long dp[105][nx];
long long go(long long i, long long w) {
	if (w > k) return -INT_MAX;
	if (i == n) return 0;
	if (dp[i][w] != -1) return dp[i][w];
	long long& ans = dp[i][w];
	ans = max(ans, go(i + 1, w));
	if (w + ac[i][0] <= k) ans = max(ans, go(i + 1, w + ac[i][0]) + ac[i][1]);
	return ans;
}
int main() {

	cin >> n >> k;
	memset(dp, -1, sizeof dp);
	for (int i = 0; i < n; i++) cin >> ac[i][0] >> ac[i][1];
	cout << go(0, 0) << "\n";
}

Measured memory_bytes: 82304
#include<iostream>
#include<queue>
#include<map>
#define LEN 100
#define BASE 25

using namespace std;

int maps[LEN][LEN];
int off[LEN][LEN];

int checker[4];
int ncheck[4];

map<int, int> points[LEN];

class State {
public:
	char where;
	int enemy;
	int budget;
	int check[4];
	State() {check[0]=0;check[1]=0;check[2]=0;check[3]=0;}
	State(char w, int e, int b ) {
		where = w;
		enemy = e;
		budget = b; 
		check[0] = ncheck[0];
		check[1] = ncheck[1];
		check[2] = ncheck[2];
		check[3] = ncheck[3];
	}
};


inline bool operator< ( const State& a, const State& b) {
	if( a.enemy == b.enemy )
		return a.budget > b.budget;
	return a.enemy < b.enemy;
}

inline bool operator> ( const State& a, const State& b) {
	if ( a.enemy == b.enemy )
		return a.budget < b.budget;
	return a.enemy > b.enemy;
}

priority_queue<State, vector<State>, greater<State> > status;

inline void copy ( State now ) {
	checker[0] = now.check[0];
	checker[1] = now.check[1];
	checker[2] = now.check[2];
	checker[3] = now.check[3];
}

inline void ncopy ( ) {
	ncheck[0] = checker[0];
	ncheck[1] = checker[1];
	ncheck[2] = checker[2];
	ncheck[3] = checker[3];
}

inline bool check ( int i ) {
	return 0 == ((1<<(i%25)) & checker[i/BASE]);
}

inline void add ( int i ) {
	ncheck[i/BASE] = ((1<<(i%25)) | checker[i/BASE]);
}

inline void insert ( int i, int e, int b ) {
	
	map<int,int>::iterator itr = points[i].find(e);
	if ( itr == points[i].end() ) {
		points[i][e] = b;
		status.push(State(i,e,b));
	} else if ( (*itr).second < b ) {
		(*itr).second = b;
		status.push(State(i,e,b));
	}
	/*
	itr++;
	int min = b+1;
	
	while( itr != points[i].end() ) {									
		if ((*itr).second > min) {
			(*itr).second = min;
		} else {
			min = (*itr).second+1;
		}
		itr++;
	}
	*/
}

int main () {


	while ( true ) {
		int n,m,l;
		cin >> n >> m >> l;

		if ( n == 0 )
			break;

		for ( int i=0; i<n; i++ ) {
			for ( int j=0; j<n; j++ ) {
				maps[i][j] = -1;
				off[i][j] = 0;
			}
			points[i].clear();
		}

		for ( int i=0; i<m; i++ ) {
			int a,b,d,e;
			cin >> a >> b >> d >> e;

			maps[a-1][b-1] = maps[b-1][a-1] = d;
			off[a-1][b-1] = off[b-1][a-1] = e;
		}

		for ( int i=0; i<4; i++ ) {
			ncheck[i] = 0;
			checker[i] = 0;
		}

		priority_queue<State, vector<State>, greater<State> > empty;
		status = empty;

		ncheck[0] = 1;
		status.push(State(0,0,l));
		int count = 0;
		while(!status.empty()) {
			State now = status.top();
			status.pop();
			if ( now.where == n-1 ) {
				cout << now.enemy << endl;
				break;
			}

			copy(now);

			for ( int i=0; i<n; i++ ) {
				if ( maps[now.where][i] > 0 ) {
					if ( check( i ) ) {
						ncopy();
						add(i);
						int e, b;
						if ( off[now.where][i] == 0 ) {
							e = now.enemy;
							b = now.budget;
							insert(i,e,b);
						} else {
							if ( now.budget - maps[now.where][i] >= 0 ) {
								e = now.enemy;
								b = now.budget - maps[now.where][i];
								insert(i,e,b);
							}
							e = now.enemy + off[now.where][i];
							b = now.budget;
							insert(i,e,b);
						}
					}
				}
			}
		}
	}
}

		

Measured memory_bytes: 2352
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int n, m, r, rs[8], a, b, c, adj[200][200], dist[200][200];
static int prev[200], q[200];
int q_is_empty(void) {
    int i;
    for (i = 0; i < n; ++i)
        if (q[i])
            return 0;
    return 1;
}
int q_pop_min(int s) {
    int i, min_dist = INT_MAX, min_dist_v = -1;
    for (i = 0; i < n; ++i)
        if (q[i])
            if (dist[s][i] < min_dist) {
                min_dist = dist[s][i];
                min_dist_v = i;
            }
    q[min_dist_v] = 0;
    return min_dist_v;
}
void dijkstra(int s) {  // start
    int i, v, u;
    for (i = 0; i < n; ++i) {
        if (i == s)
            dist[s][i] = 0;
        else
            dist[s][i] = INT_MAX;
    }
    for (i = 0; i < n; ++i)
        prev[i] = -1;
    for (i = 0; i < n; ++i)
        q[i] = 1;
    while (!q_is_empty()) {
        u = q_pop_min(s);
        for (i = 0; i < n; ++i) {
            if (adj[u][i]) {
                v = i;
                if (dist[s][v] > dist[s][u] + adj[u][v]) {
                    dist[s][v] = dist[s][u] + adj[u][v];
                    prev[v] = u;
                }
            }
        }
    }
}
void print_rs(int *rs, int r) {
    int i;
    for (i = 0; i < r; ++i) {
        printf("%d, ", rs[i]);
    }
    putchar('\n');
}
int rec(int *rs, int r, int parent, int d, int depth) {
    int i, *rs2, num_child = 0, min = INT_MAX, min_children;
//    print_rs(rs, r);
    for (i = 0; i < r; ++i) {
        if (rs[i] != -1) {
            ++num_child;
            rs2 = malloc(sizeof(int) * r);
            memcpy(rs2, rs, sizeof(int) * r);
            rs2[i] = -1;
            min_children = rec(rs2, r, rs[i], d + dist[parent][rs[i]], depth + 1);
            if (min_children < min)
                min = min_children;
            free(rs2);
        }
    }
    if (!num_child) {
        return d;
    } else
        return min;
}
void print_adj(void) {
    int i, j;
    puts("adjacency matrix:");
    for (i = 0; i < n; ++i) {
        for (j = 0; j < n; ++j) {
            printf("%d, ", adj[i][j]);
        }
        putchar('\n');
    }
}
void print_dist(void) {
    int i, j;
    puts("distance:");
    for (i = 0; i < n; ++i) {
        for (j = 0; j < n; ++j) {
            printf("%d, ", dist[i][j]);
        }
        putchar('\n');
    }
}
int main(void) {
    int i, *rs2, min = INT_MAX, min_children;
    scanf("%d%d%d", &n, &m, &r);
    for (i = 0; i < r; ++i) {
        scanf("%d", rs + i);
        --rs[i];
    }
    for (i = 0; i < m; ++i) {
        scanf("%d%d%d", &a, &b, &c);
        --a;
        --b;
        adj[a][b] = c;
        adj[b][a] = c;
    }
    for (i = 0; i < n; ++i) {
        dijkstra(i);
    }
//    print_adj();
//    print_dist();
    for (i = 0; i < r; ++i) {
        rs2 = malloc(sizeof(int) * r);
        memcpy(rs2, rs, sizeof(int) * r);
        rs2[i] = -1;
        min_children = rec(rs2, r, rs[i], 0, 100);
        if (min_children < min)
            min = min_children; 
        free(rs2);
    }
    printf("%d\n", min);
    return 0;
}


Measured memory_bytes: 512
int main()
{
    signed long n,i,min,count=0;
    scanf("%ld",&n);
    signed long* arr = (signed long*) malloc(n * sizeof(signed long));
    i = n;
    while(i>0)
    {
        scanf("%ld",arr+n-i);
        i--;
    }
   
    if(n==1)
     printf("%d",1);
    else
    {
        min = arr[0];
        i=0;
        count++;
      while(i<n)
      {
          if(arr[i]<min)
          {
           min = arr[i];
           count++;
          }
           i++;
      }
      printf("%ld",count);
    }
     
    
    return 0;
}

Measured memory_bytes: 1664
class UnionFind():
    def __init__(self,size):
        self.table=[-1]*size
    def root(self,x):
        while self.table[x]>=0:
            x=self.table[x]
        return x
    def unite(self,x,y):
        s1=self.root(x)
        s2=self.root(y)
        if s1!=s2:
            if self.table[s1]>self.table[s2]:
                s1,s2=s2,s1
            self.table[s1]+=self.table[s2]
            self.table[s2]=s1
        return
    def same(self,x,y):
        return self.root(x)==self.root(y)
    def size(self,x):
        return -self.table[self.root(x)]
n,*z=map(int,open(0).read().split())
u=UnionFind(10**5*2+1)
for x,y in zip(*[iter(z)]*2):
    u.unite(x,10**5+y)
d=[[0,set(),set()]for _ in range(10**5*2+1)]
for x,y in zip(*[iter(z)]*2):
    t=d[u.root(x)]
    t[0]+=1
    t[1].add(x)
    t[2].add(y)
print(sum(len(x)*len(y)-a for a,x,y in d))

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<tuple<string,int,int>> p(n);
    for(int i=0;i<n;i++){
        string s; int a;
        cin >> s >> a;
        p[i] = make_tuple(s,a*(-1),i+1);
    }
    sort(p.begin(),p.end());
    rep(i,n){
        cout << get<2>(p[i]) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;

bool smaller_third(const pair<pair<int, string>, pair<int, int>> &a, const pair<pair<int, string>, pair<int, int>> &b)
{
  if (a.second.second == b.second.second)
    return a.second.first < b.second.first;
  return a.second.second < b.second.second;
}
bool smaller_first(const pair<pair<int, string>, pair<int, int>> &a, const pair<pair<int, string>, pair<int, int>> &b)
{
  return a.first.first < b.first.first;
}

int main()
{
  int n, m;
  cin >> n >> m;
  vector<pair<pair<int, string>, pair<int, int>>> py(m);
  for (int i = 0; i < m; ++i)
  {
    py[i].first.first = i;
    cin >> py[i].second.first >> py[i].second.second;
  }

  sort(py.begin(), py.end(), smaller_third);
  unordered_map<int, int> mp;

  for (int i = 0; i < m; ++i)
  {
    ostringstream sout;
    mp[py[i].second.first]++;
    sout << setfill('0') << setw(6) << py[i].second.first;
    sout << setfill('0') << setw(6) << mp[py[i].second.first];
    py[i].first.second = sout.str();
  }
  sort(py.begin(), py.end(), smaller_first);
  for (int i = 0; i < m; ++i)
  {
    cout << py[i].first.second << endl;
  }

  return 0;
}


Measured memory_bytes: 12580
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

typedef vector<long long> row;
typedef vector<row> matrix;

const long long mod = 1000 * 1000 * 1000 + 7;

matrix operator*(const matrix &a, const matrix &b) {
  assert(a[0].size() == b.size());

  int n = a.size();
  int x = a[0].size();
  int m = b[0].size();
  matrix c(n, row(m, 0));

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int k = 0; k < x; ++k) {
        c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % mod;
      }
    }
  }

  return c;
}

matrix matrix_identity(int n) {
  matrix a(n, row(n));
  for (int i = 0; i < n; ++i) {
    a[i][i] = 1;
  }

  return a;
}

matrix matrix_powmod(const matrix &b, long long exp, long long mod) {
  matrix t = b;
  matrix ans = matrix_identity(b.size());

  for (int i = 0; i < 60; ++i) {
    if ((1LL << i) & exp) {
      ans = ans * t;
    }

    t = t * t;
  }

  return ans;
}

int main() { IO;
  int n;
  long long k;
  cin >> n >> k;

  matrix m(n);
  for (auto &row : m) {
    row.resize(n);
    for (auto &x : row) cin >> x;
  }

  matrix mm = matrix_powmod(m, k, 1000 * 1000 * 1000 + 7);

  long long sum = 0;
  for_each(mm.begin(), mm.end(), [&sum](row &row) {
                                  sum = accumulate(row.begin(), row.end(), sum);
                                });
  cout << sum % mod << endl;

  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <ctime>
#include <list>
#include <numeric>
#include <fstream>

using namespace std;
static const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> PI;
#ifndef M_PI
const double M_PI=acos(-1.0);
#endif
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FORR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int((a).size()))
#define F first
#define S second
void pkuassert(bool b){if(!b){int a=0;cout << 1/a << endl;}};
int dx[]={0,-1,0,1,1,1,-1,-1},dy[]={1,0,-1,0,1,-1,1,-1};

string in[8];

int cnt(int x,int y,char a,bool fi=false){
  int ret=0;
  for(int i=-1;i<=1;++i)
    for(int j=-1;j<=1;++j){
      if((i|j)==0) continue;
      int cx=x+i,cy=y+j;
      int cnt=0;
      while(true){
        if(min(cx,cy)<0 || max(cx,cy)>=8) break;
        if(in[cx][cy]==a){
          if(fi){
            while(true){
              cx-=i;
              cy-=j;
              in[cx][cy]=a;
              if(cx==x && cy==y) break;
            }
          }
          ret += cnt;
          break;
        }
        if(in[cx][cy]=='.') break;
        cx+=i;
        cy+=j;
        ++cnt;
      }
    }

  return ret;
}

int main(){
  rep(i,8) cin >> in[i];

  while(true){
    bool end=true;

    PI pos=mp(-1,-1);
    int maxv=0;
    rep(i,8)rep(j,8){
      if(in[i][j]!='.') continue;
      int tv=cnt(i,j,'o');
      if(tv>maxv){
        pos=mp(i,j);
        maxv=tv;
      }
    }

    if(maxv){
      cnt(pos.F,pos.S,'o',true);
      in[pos.F][pos.S]='o';
      end=false;
    }

    
    pos=mp(-1,-1);
    maxv=0;    
    
    rep(i,8)rep(j,8){
      if(in[i][j]!='.') continue;      
      int tv=cnt(i,j,'x');
      if(tv>=maxv){
        pos=mp(i,j);
        maxv=tv;
      }
    }

    if(maxv){
      cnt(pos.F,pos.S,'x',true);
      in[pos.F][pos.S]='x';
      end=false;
    }    

    //rep(i,8) cout << in[i] << endl;
    if(end) break;
  }

  rep(i,8) cout << in[i] << endl;
}

Measured memory_bytes: 1184
let for_range s e step f =
  let rec loop i =
    if i <= e then begin f i;loop (i + step) end
  in loop s;;

let sieve num =
  let p = Array.init num (fun x -> x mod 2) in
  let rec loop i =
    if i*i < num then
      begin
        if p.(i) = 1 then for_range (i*i) num (i*2) (fun x -> p.(x) <- 0);
        loop (i+2)
      end
  in
  p.(0) <- 0; p.(1)<-(0);p.(2)<-1;loop 3;
  for i = 3 to num-1 do
    p.(i) <- p.(i) + p.(i-1);
  done;
  p
;;

let _ =
  let p = sieve 1000000 in
  let rec read () =
    try let n = read_int () in
        Printf.printf "%d\n" p.(n);
        read ()
    with End_of_file -> ()
  in read ()
;;

Measured memory_bytes: 10260
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a, b, c;
    cin >> a >> b >> c;
    if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void solve()
{
	int K;
	while(cin >> K, K)
	{
		int sum = 0;
		int n = K * (K - 1) / 2;
		for(int i = 0; i < n; ++i)
		{
			int a;
			cin >> a;
			sum += a;
		}
		cout << sum / (K - 1) << endl;
	}
}

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

Measured memory_bytes: 1160
N, M, Q = map(int, input().split())
 
A = []
B = []
C = []
D = []
 
for i in range(Q):
    a, b, c, d = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)
 
 
def dfs(nums):
 
    if len(nums) == N + 1:
        score = 0
        for j in range(Q):
            if nums[B[j]] - nums[A[j]] == C[j]:
                score += D[j]
        return score
 
    max_score = 0
    for i in range(nums[-1], M+1):
        new_nums = nums + [i]
        max_score = max(max_score, dfs(new_nums))
 
    return max_score
 
nums = [1]
res = dfs(nums)
print(res)

Measured memory_bytes: 9240
import sys
sys.setrecursionlimit(10**9)

N, WW = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(N)]
W, V = zip(*l)
M = [{} for i in range(N + 1)]
def cal(i, w):
  if w in M[i]:
    return M[i][w]
  if i == N:
    v = 0
  elif w < W[i]:
    v = cal(i + 1, w)
  else:
    v = max(cal(i + 1, w), cal(i + 1, w - W[i]) + V[i])
  M[i][w] = v
  return v

print(cal(0, WW))

Measured memory_bytes: 10940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

ll ans = 0;
int main(){
    int N;
    cin >> N;
    Rep(i,N){
        if(i%3==0 || i%5==0 || i %15==0){

        }else {
            ans += i;
        }
    }
    cout << ans<< endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define reup(a, b) for(int i = a; i <= b; ++i)

int main(void) {
    char x, y;
    scanf("%c %c", &x, &y);
    if(x > y) puts(">");
    else if(x == y) puts("=");
    else puts("<");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int N;
  cin >> N;
  vector<string> s(N);
  rep(i, N) {
    cin >> s[i];
  }

  int ans = 0;

  int B__ = 0;
  int __A = 0;
  int B_A = 0;
  rep(i, N) {
    int M = len(s[i]);
    rep(j, M - 1) {
      if (s[i][j] == 'A' && s[i][j + 1] == 'B')
        ans++;
    }

    bool B = s[i][0] == 'B';
    bool A = s[i][M - 1] == 'A';

    if (A && B)
      B_A++;
    else if (A)
      __A++;
    else if (B)
      B__++;
  }

  if (B_A) {
    ans += B_A - 1;
    if (__A) {
      ans++;
      __A--;
    }
    if (B__) {
      ans++;
      B__--;
    }
  }

  ans += min(__A, B__);
  cout << ans << endl;
}

Measured memory_bytes: 768
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <time.h>
#include <stdlib.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(a) a.begin(),a.end()
#define ign cin.ignore();
 
#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
 
using namespace std;
using namespace __gnu_pbds;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
vll a,f;
 
ll n,k;
 
bool ok(ll num){
    ll sub=0;
    for(int i=0;i<n;i++)
    {
        ll p=a[i]*f[i];
        if(p>num){
            sub+=a[i]-num/f[i];
        }
    }
    if(sub<=k)
        return true;
    else
        return false;
}
 
int main()
{
    IOS
    cin>>n>>k;
    a.resize(n);f.resize(n);
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>f[i];
    }
    if(sum<=k){
        cout<<"0\n";
        exit(0);
    }
    sort(all(a),greater<>());
    sort(all(f));
    ll high=LLONG_MAX;
    ll low=0;
    ll mid=(high+low)/2;
    while(high-low>1){
            //debug(high,low);
        mid=(high+low)/2;
        if(ok(mid))
            high=mid;
        else
            low=mid+1;
    }
    if(ok(low))
        cout<<low;
    else
        cout<<high;
    return 0;
}

Measured memory_bytes: 3328
a = int(input())
b = list(map(int, input().split()))
c = list(map(int, input().split()))
bb = [0] * a
cc = [0] * a
for i in range(a):
    if i == 0:
        bb[i] = b[i]
        cc[-i-1] = c[-i-1]
    else:
        bb[i] = b[i] + bb[i-1]
        cc[-i-1] = c[-i-1] + cc[-i]
ans = 0
for i in range(a):
    ans = max(ans, bb[i] + cc[i])
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
ll x[maxn];
int main()
{
    ll n,a,b,ans=0,sum=0;
    scanf("%lld%lld%lld",&n,&a,&b);
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&x[i]);
        if(i) sum+=x[i]-x[i-1];
    }
    if(b*(n-1)<sum)
    {
        printf("%lld\n",b*(n-1));
        return 0;
    }
    for(int i=1;i<n;i++)
    {
        ans+=min((x[i]-x[i-1])*a,b);
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
static const int INF = 1000000007;
using ll = long long;
using namespace std;

int main() {
    vector<int> v(5, 0);
    string s = "MARCH";
    ll ans = 0;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string a;
        cin >> a;
        for (int j = 0; j < 5; ++j) {
            if(s[j] == a[0]) v[j]++;
        }
    }
    vector<int> v2 = {0, 0, 1, 1, 1};
    do{
        ll a = 1;
        for (int i = 0; i < 5; ++i) {
            if(v2[i]){
                a *= v[i];
            }
        }
        ans += a;
    }while (next_permutation(v2.begin(), v2.end()));
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
signed main(){
  ll n,a[1000],sum=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  for(int i=0;i<n-1;i++){
    sum += a[i];
  }
  if(a[n-1]<sum){
    cout<<"Yes\n";
  }else{
    cout<<"No\n";
  }
  return(0);
}


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

int main(){
  string S,T="CODEFESTIVAL2016";
  cin>>S;
  int j=0;
  for(int i=0;i<16;i++)
    if(S.at(i)!=T.at(i))
      j++;
  cout<<j<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<int,int>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	vector<ll> prim;
	FOR(i,2,101) {
		bool ok = true;
		for(ll j = 2; j < i; j++) {
			if(i % j == 0) ok = false;
		}
		if(ok) prim.pb(i);
	}
	ll m = prim.size();
	vector<ll> cnt(m, 0);
	FOR(i,2,n + 1) {
		ll tmp = i;
		REP(j,m) {
			while(tmp % prim[j] == 0) {
				tmp /= prim[j];
				cnt[j]++;
			}
		}
	}
	ll ans = 0;
	REP(i,m) if(cnt[i] >= 74) ans++;
	REP(i,m) REP(j,m) {
		if(i == j) continue;
		if(cnt[i] >= 2 && cnt[j] >= 24) ans++;
	}
	REP(i,m) REP(j,m) {
		if(i == j) continue;
		if(cnt[i] >= 4 && cnt[j] >= 14) ans++;
	}
	REP(i,m) REP(j,m) FOR(k,j+1,m) {
		if(i == j || i == k) continue;
		if(cnt[i] >= 2 && cnt[j] >= 4 && cnt[k] >= 4) ans++;
	}
	cout << ans << endl;
	return 0;
}

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


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

const int M = 2005;
const int N = 30005;
const int o = 15000;

bool ab[N],ac[N],bc[N];

bool match(char x,char y) {
    return x=='?' || y=='?' || x==y;
}

string a,b,c;
int la,lb,lc;

signed main() {
    ios::sync_with_stdio(false);
    cin>>a>>b>>c;
    la=a.length();
    lb=b.length();
    lc=c.length();
    for(int i=0;i<la;i++) for(int j=0;j<lb;j++)
        if(!match(a[i],b[j])) ab[i-j+o]=1;
    for(int i=0;i<la;i++) for(int j=0;j<lc;j++)
        if(!match(a[i],c[j])) ac[i-j+o]=1;
    for(int i=0;i<lb;i++) for(int j=0;j<lc;j++)
        if(!match(b[i],c[j])) bc[i-j+o]=1;
    int ans=N;
    for(int i=-2*M;i<=2*M;i++) for(int j=-2*M;j<=2*M;j++) {
        if(!ab[i+o] && !ac[j+o] && !bc[j-i+o]) {
            ans=min(ans, max(la,max(lb+i,lc+j))-min(0,min(i,j)));
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func SomeSums(N int, A int, B int) int {
	var o5 int
	var o4 int
	var o3 int
	var o2 int
	var o1 int
	var Sum int
	var result int
	for i := 1; i <= N; i++ {
		o5 = (i / 10000) % 10
		o4 = (i / 1000) % 10
		o3 = (i / 100) % 10
		o2 = (i / 10) % 10
		o1 = i % 10
		Sum = o5 + o4 + o3 + o2 + o1
		if A <= Sum && Sum <= B {
			result += i
		}
	}
	return result
}

func main() {
	var N int
	var A int
	var B int

	fmt.Scan(&N)
	fmt.Scan(&A)
	fmt.Scan(&B)
	fmt.Println(SomeSums(N, A, B))
}


Measured memory_bytes: 512
#include<stdio.h>
 
int main()
{
  int n,m,ai,i;
 
  scanf("%d%d", &n,&m);
  
  for(i = 0;i < m;i++){
    scanf("%d", &ai);
    n -=ai;
  }
  
  if(n >= 0)
    printf("%d\n",n);
  else
    printf("-1\n");
  
  return 0;
}

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

#define M 1000000007

int main()
{   
    long long N, K;
    std::cin >> N >> K;
    
    long long sum = 0;
    long long min, max, temp;
    
    for(long long i=K; i<=N+1; i++){
        min = i*(i-1)/2;
        max = (2*N-(i-1))*i/2;
        temp = max-min+1;
        if(temp>M){
            temp%=M;
        }
        sum += temp;
        if(sum>M){
            sum%=M;
        }
    }
    std::cout << sum << std::endl;

    return 0;
}


Measured memory_bytes: 3636
from itertools import accumulate
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))


a = accumulate(A)
C = Counter(a)


def comb(v):
    return (v)*(v-1)//2


ans = 0
for i, v in C.items():
    if i == 0:
        ans += v
    if v > 1:
        ans += comb(v)
print(ans)


Measured memory_bytes: 39016
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#pragma comment(linker, "/STACK:16000000")
using namespace std;

const int Maxn = 200005;
const int Maxm = 100;

bool has[Maxn][Maxm];
int res[Maxn];
bool tk[Maxn];
int root, rootval;
int n;
vector <int> neigh[Maxn];
int P[Maxn];

void Solve(int v)
{
	for (int i = 0; i < neigh[v].size(); i++) {
		int u = neigh[v][i];
		if (u == root) has[v][rootval] = true;
		else { Solve(u); has[v][res[u]] = true; }
	}
	res[v] = 0;
	while (has[v][res[v]]) res[v]++;
	for (int i = 0; i < neigh[v].size(); i++) {
		int u = neigh[v][i];
		if (u == root) has[v][rootval] = false;
		else has[v][res[u]] = false;
	}
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &P[i]); 
		neigh[P[i]].push_back(i);
	}
	root = 1;
	while (!tk[root]) {
		tk[root] = true; root = P[root];
	}
	for (rootval = 0; rootval < Maxm; rootval++) {
		res[root] = rootval;
		for (int j = 0; j < neigh[root].size(); j++) {
			int u = neigh[root][j]; Solve(u);
			has[root][res[u]] = true;
		}
		int my = 0;
		while (has[root][my]) my++;
		if (res[root] == my) { printf("POSSIBLE\n"); return 0; }
		for (int j = 0; j < neigh[root].size(); j++) {
			int u = neigh[root][j];
			has[root][res[u]] = false;
		}
	}
	printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 44160