akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define PMAX 1000000000
int wmax=0;
int n,k,w[100000];

int check(int P){
    int i;
    int count=1,now=P;
    if(P<wmax) return 0;
    for(i=0;i<n;i++){
        if(now>=w[i]){
           now-=w[i];
        }else{
            count++;
            now=P-w[i];
        }
    }
    if(count>k) return 0;
    else return 1;
}

int main(void){
    int i;
    int left,right,mid;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&w[i]);
        if(w[i]>wmax) wmax=w[i];
    }

    left=0,right=PMAX;
    while(right-left>1){
        mid=(left+right)/2;
        if( check(mid) ) right=mid;
        else left=mid;
    }
    printf("%d\n",right);
    return 0;
}

   

Measured memory_bytes: 984
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)
	a *= b
	c *= d
	if a < c {
		fmt.Println(c)
	} else {
		fmt.Println(a)
	}
}

Measured memory_bytes: 512
// C++ implmentation to find the 
// Kth number in the list formed 
// from product of any two numbers 
// in the array and sorting them 

#include <bits/stdc++.h> 
using namespace std; 
#define int             long long

// Function to find number of pairs 
bool check(long long x, 
		vector<int>& pos, 
		vector<int>& neg, int k) 
{ 
	long long pairs = 0; 

	int p = neg.size() - 1; 
	int nn = neg.size() - 1; 
	int pp = pos.size() - 1; 

	// Negative and Negative 
	for (int i = 0; i < neg.size(); i++) { 
		while (p >= 0 and neg[i] * neg[p] <= x) 
			p--; 

		// Add Possible Pairs 
		pairs += min(nn - p, nn - i); 
	} 

	// Positive and Positive 
	p = 0; 
	for (int i = pos.size() - 1; i >= 0; i--) { 
		while (p < pos.size() and pos[i] * pos[p] <= x) 
			p++; 

		// Add Possible pairs 
		pairs += min(p, i); 
	} 

	// Negative and Positive 
	p = pos.size() - 1; 
	for (int i = neg.size() - 1; 
		i >= 0; 
		i--) { 
		while (p >= 0 and neg[i] * pos[p] <= x) 
			p--; 

		// Add Possible pairs 
		pairs += pp - p; 
	} 

	return (pairs >= k); 
} 

// Function to find the kth 
// element in the list 
long long kth_element(int a[], 
					int n, int k) 
{ 
	vector<int> pos, neg; 

	// Seperate Postive and 
	// Negative elements 
	for (int i = 0; i < n; i++) { 
		if (a[i] >= 0) 
			pos.push_back(a[i]); 
		else
			neg.push_back(a[i]); 
	} 

	// Sort the Elements 
	sort(pos.begin(), pos.end()); 
	sort(neg.begin(), neg.end()); 

	long long l = -1e18, 
			ans = 0, r = 1e18; 

	// Binary search 
	while (l <= r) { 
		long long mid = (l + r) >> 1; 
		if (check(mid, pos, neg, k)) { 
			ans = mid; 
			r = mid - 1; 
		} 
		else
			l = mid + 1; 
	} 

	// Return the required answer 
	return ans; 
} 

// Driver code 
int32_t main() 
{ 
	int n;cin>>n;
	int a[n], k ; cin>>k;

	for(int i=0;i<n;i++)
		cin>>a[i];
	// Function call 
	cout << kth_element(a, n, k); 

	return 0; 
} 


Measured memory_bytes: 4084
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func main() {
	list := getStdinIntArr()
	A := list[0]
	B := list[1]

	y := B - 2*A

	if y%2 == 0 {
		y = y / 2
		x := A - y
		if x+y == A && x >= 0 && y >= 0 {
			fmt.Printf("Yes\n")
			return

		}
	}

	fmt.Printf("No\n")
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 2140
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 100005
#define LL long long
#define rep(i,j,k) for(i=j;i<=k;++i)
struct E{
	int to,nxt;
	bool canbe;
}ed[N<<1];
int a,b,top,n,m,i,j,lca,u,v,sum,num;
int dep[N],head[N],val[N],s[N],fa[N],q[N];
LL ans;
void read(int &p){
	p=0; char x=getchar();
	while(x<'0' || x>'9') x=getchar();
	while(x>='0'&&x<='9'){p=p*10+x-'0'; x=getchar();}
}
void add(int u,int v){
	top++; ed[top]=(E){v,head[u]}; head[u]=top; ed[top].canbe=true;
}
void dfs(int x){
	int i;
	for(i=head[x];i;i=ed[i].nxt)
	if(!dep[ed[i].to]){
		dep[ed[i].to]=dep[x]+1;
		fa[ed[i].to]=x;
		dfs(ed[i].to);
	}else 
	if(fa[x]!=ed[i].to){
		ed[i].canbe=false;
		a=ed[i].to; b=x;
	}
}
void solve(int x){
	int i;
	s[x]=val[x];
	for(i=head[x];i;i=ed[i].nxt)
	if((ed[i].to!=fa[x])&&(ed[i].canbe)){
		solve(ed[i].to);
		s[x]+=s[ed[i].to];
	}
}
int main(){
	read(n); read(m);
	rep(i,1,m){
		read(a); read(b);
		add(a,b); add(b,a);
	}
	dep[1]=1; a=b=0;
	dfs(1);
	rep(i,1,n)
	if(dep[i]&1) num++,val[i]=1;
	else num--,val[i]=-1;
	if(n-1==m){
		if(num) { puts("-1"); return 0; }
		solve(1);
		rep(i,1,n) ans+=abs(s[i]);
		printf("%lld\n",ans);
		return 0;
	}
	u=a; v=b;
	if(dep[a]<dep[b]) swap(a,b);
	while(dep[a]>dep[b]) sum++,a=fa[a];
	while(a!=b){ a=fa[a]; b=fa[b]; }
	lca=a;
	if(!(sum&1)){//odd
		if(num&1) { puts("-1"); return 0; }	
		if(num>0) { val[u]-=(num>>1); val[v]-=(num>>1); }
		if(num<0) { val[u]+=((-num)>>1); val[v]+=((-num)>>1); }
		ans+=(abs(num)>>1);
		solve(1);
		rep(i,1,n) ans+=abs(s[i]);
		printf("%lld\n",ans);
		return 0;
	}
	if(num) { puts("-1"); return 0; }
	a=u; b=v; top=1; q[1]=0;
	solve(1);
	rep(i,1,n) ans+=abs(s[i]);
	while(a!=lca){
		top++; q[top]=(-s[a]); ans-=abs(s[a]);
		a=fa[a];
	}
	while(b!=lca){
		top++; q[top]=s[b]; ans-=abs(s[b]);
		b=fa[b];
	}
	sort(q+1,q+1+top);
	num=q[((top+1)>>1)];
	rep(i,1,top) ans+=abs(q[i]-num);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7936
def main():
    x, n = map(int, input().split())
    p = [i for i in map(int, input().split())]

    if not x in p:
        print(x)
        exit()

    i = 0
    while 1:
        if not x-i in p:
            print(x-i)
            break
        elif not x+i in p:
            print(x+i)
            break
        i += 1


main()


# def f(n):
#     return n-x


# p_x = list(map(f, p))
# p_x_abs = list(map(abs, p_x))

# min_p_x = min(p_x)

# i = 0
# print(p_x)
# print(p_x_abs)
# while 1:
#     if i in p_x_abs:
#         i = i+1
#     else:

# print(ans)


Measured memory_bytes: 61612
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.ArrayDeque
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (n, m) = readLongList()
    if (n > m / 2) {
        out.println(m / 2)
    } else {
        val remain = m - 2 * n
        out.println(n + remain / 4)
    }
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 36484
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define endl '\n'
#define pi 3.1415926536
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
signed main()
{
    SPEED;
  	int n,i,c=0,max=0;
  	cin>>n;
  	int a[n],b[200001]={0};
  	for(i=0;i<n;i++)
    {
      cin>>a[i];
      if(b[a[i]]==0 && a[i]==1)
        b[a[i]]=i+1;
      else if(a[i]>1 && b[a[i]-1]>0)
        b[a[i]]=i+1;
      if(a[i]>max)
        max=a[i];
    }
  	for(i=1;i<=max;i++)
    {
      if(b[i]!=0)
        c++;
    }
    if(b[1]==0)
      cout<<-1;
    else
    {
      if(c==0)
        cout<<n-1;
      else
        cout<<n-c;
    }
}

Measured memory_bytes: 3328
#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 << "\n";
    }
    else if((a-b >= a+b) && (a-b >= a*b)){
        cout << a-b << "\n";
    }
    else cout << a*b << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define FOR(i, a, b) for (ll i = (signed)(a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define MOD 1000000007
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
using namespace std;

int main() {
  ll n;
  cin >> n;
  ll last = 0, lx = 0, ly = 0;
  REP(i, n) {
    ll t, x, y, h = last, hx = lx, hy = ly;
    cin >> t >> x >> y;
    last = t;
    t = t - h;
    ly = y, lx = x, x = abs(x - hx), y = abs(y - hy);
    if (x + y > t || (t - x - y) % 2)
      return !printf("No\n");
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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


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

	int a[100001], b[100001];
	rep1(i, A) cin >> a[i];
	rep1(i, B) cin >> b[i];

	int kotae = *min_element(a + 1, a + A + 1) + *min_element(b + 1, b + B + 1);

	rep(i, M) {
		int x, y, c;
		cin >> x >> y >> c;

		int tmp = a[x] + b[y] - c;
		chmin(kotae, tmp);
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 1024
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>

using namespace std;

template<typename T, typename S>
istream& operator >> (istream& is, pair<T, S>& p) {
    is >> p.first >> p.second;
    return is;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& v) {
    for (auto& x : v) {
        is >> x;
    }
    return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    for (auto& x : v) {
        os << x << " ";
    }
    os << "\n";
    return os;
}

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

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    cin >> a;
    int en = 0;
    for (int x : a) en += x / 2;
    if (en + int(n / 2) >= n - 1) {
        if (m == 1) {
            if (a[0] == 1) {
                cout << a << "1\n" << n;
            } else {
                cout << a << "2\n1 " << n - 1;
            }
            return 0;
        }
        if (n <= 3) {
            cout << a << "1\n" << n;
            return 0;
        }


        if (n % 2 == 1) {
            for (int i = 1; i < m; ++i) {
                if (a[i] % 2 == 1) swap(a[i], a[0]);
            }
        } else {
            for (int i = 1; i < m - 1; ++i) {
                if (a[i] % 2 == 1) {
                    if (a[0] % 2 == 0) swap(a[0], a[i]);
                    else swap(a[i], a[m - 1]);
                }
            }
        }
        vector<int> A;
        for (auto x : a) A.push_back(x * 2);
        vector<int> centers;
        for (int i = 0, s = 0; i < m; ++i) {
            centers.push_back(s + a[i]);
            s += A[i];
        }
        vector<int> bcenters;
        bcenters.push_back(centers[0] + 1);
        for (int i = 1; i < m - 1; ++i) bcenters.push_back(centers[i] + 2);
        bcenters.push_back(centers[m - 1] + 1);

        vector<int> b;
        for (int i = 0,s = 0; i < m; ++i) {
            b.push_back(bcenters[i] - s);
            s += 2 * b.back();
        }
        if (b.back() == 0) b.pop_back();

        cout << a << b.size() << "\n" << b;
    } else {
        cout << "Impossible";
    }
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int p = 1;
  for (int i = 0; i < n; i++) {
    if (p > k) {p+= k;}
    else {p *= 2;}
  }
  
  cout << p << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n)
    cin >> a[i];
  sort(all(a));
  double buf = (a[0] + a[1]) / 2.0;
  rep(i,n-2) buf = (buf + a[i+2]) / 2.0;
  cout << setprecision(12) << buf << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  int n;
  cin >> n;
  vector<pair<string, pair<int, int>>> a(n);

  int p;
  string s;
  for (int i = 0; i < n; i++){
    cin >> a[i].first >> a[i].second.first;
    a[i].second.first *= -1;
    a[i].second.second = i + 1;
  }

  sort(a.begin(), a.end());

  for (int i = 0; i < n; i++){
    cout << a[i].second.second << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void dfs(int now, int parent, vector<vector<int>> &children, vector<bool> &reached) {
    if(reached.at(now)) return;
    reached.at(now) = true;
    for(int child : children.at(now)){
        if(child==parent) continue;
        dfs(child, now, children, reached);
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    for(int i = 0; i < M; i++) {
        cin >> a.at(i) >> b.at(i);
        a.at(i)--;
        b.at(i)--;
    }
    
    int ans = 0;
    for(int i = 0; i < M; i++) {
        vector<vector<int>> children(N, vector<int>());
        for(int j = 0; j < M; j++) {
            if(j==i) continue;
            int A = a.at(j), B = b.at(j);
            children.at(A).push_back(B);
            children.at(B).push_back(A);
        }
        vector<bool> reached(N);
        dfs(0,-1,children,reached);
        
        int x = 0;
        for(int j = 0; j < N; j++) {
            if(!reached.at(j)) {
                x = 1;
                break;
            }
        }
        ans += x;
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int, int>
#define ld long double
const int mod = 1e9 + 7;
 
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
 
 
 
 
 int bin(multiset<int>&s)
 {

	 
	 int l=0,r=s.size()-1,mid,ans=1;
	 while(l<=r)
	 {
		 mid=(l+r)/2;
		 auto k =s.begin();
	   	advance(k,mid);
		 if(*k>=s.size()-mid)
		 { 
			 ans=s.size()-mid; r=mid-1;
		 }
		 else l=mid+1;
	 }
	 return ans;
 }
 
 
 
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);

 

int n; cin>>n;

int sum=0,sqsum=0;

for(int i=0;i<n;i++)
{
	int x;
	cin>>x;
	sum+=x; sqsum+=x*x; 
}

cout<<(sum*sum-sqsum)/2;
 
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
vector<int> to[100005];
void solve() {
	int n, m; cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int a, b; cin >> a >> b;
		--a; --b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	queue<int> q;
	vector<int> dist(n, INF);
	vector<int> pre(n, -1);
	dist[0] = 0;
	q.push(0);
	while(!q.empty()) {
		int v = q.front(); q.pop();
		for (int u : to[v]) {
			if (dist[u] != INF) continue;
			dist[u] = dist[v] + 1;
			pre[u] = v;
			q.push(u);
		}
	}
	cout << "Yes" << endl;
	for (int i = 0; i < n; ++i) {
		if (i == 0) continue;
		int ans = pre[i];
		++ans;
		cout << ans << endl;
	}
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 10744
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long int a,b,c=1,d,e;
  cin>>a>>b;
  d=a;
  e=b;
    
    for(long int i=2;i<max(a,b);i++){
    if(a%i==0 && b%i==0){
      c*=i;
      a/=i;
      b/=i;
      i--;
    }
}
  cout<<d*e/c;
}

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

int main(){

	int n,d1,d2, ct=0;
	vector<pair<int,int>> s;
	cin>>n;
	while(n--){
		cin>>d1>>d2;
		s.push_back({d1,d2});
	}


	for(int i=0;i<s.size(), i+1<s.size(), i+2<s.size();i++)
	{
		if(s[i].first == s[i].second){
			if(s[i+1].first == s[i+1].second){
				if(s[i+2].first == s[i+2].second)
				{
					cout<<"Yes";
					exit(0);
				}
				
			}
		}
	}

	
	cout<<"No";

}


Measured memory_bytes: 3604
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    int X, Y; std::cin >> X >> Y;
    if(Y % 2){
        std::cout << "No" << std::endl;
        return 0;
    }
    bool okay(2*X <= Y && Y <= 4*X);
    std::cout << (okay ? "Yes" : "No") << std::endl;
    return 0;
}


Measured memory_bytes: 3592
a = list(map(int, input().split()))
HP = a[0]

x = []
for i in range(a[1]):
    x1, y1 = [int(i) for i in input().split()]
    x.append((x1, y1))

max_tup = max(x, key=lambda x: x[0]) #最高攻撃力の呪文を記憶
max_a = max_tup[0] #その攻撃力を記録
#1次元　横：与えるダメージ　中身：最小魔力
dp = [10**10] * (HP + max_a)  #DP表はHP+最高攻撃力
dp[0] = 0

for i in range(1, len(dp)):
    for a, b in x:
        if i >= a:
            dp[i] = min(dp[i],dp[i - a] + b )

print(min(dp[HP:]))

Measured memory_bytes: 42092
n=int(input())
mansion = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for i in range(n):
    a=list(map(int,input().split()))
    b=a[0] #what building
    f=a[1] #what floor
    r=a[2] #room number
    v=a[3] #how many
    mansion[b-1][f-1][r-1]+=v
for i in range(4):
    for j in range(3):
        print('', *mansion[i][j])
    if i < 3:
        print("#" *20)


Measured memory_bytes: 5624
N = int(input())
A = list(map(int, input().split()))

from collections import deque
dA = deque(A)
ans= deque([])
Nans = 0
for itr, val in enumerate(dA):
  if itr % 2 == 0:
    Nans += val
  else:
    Nans -= val
ans.append(Nans)

for i in A:
  Nans = 2*i - Nans
  ans.append(Nans)
ans.pop()
print(' '.join(map(str, ans)))


Measured memory_bytes: 20300
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] c = sc.next().toCharArray();
        List<Character> fumiyasuiKisu = new ArrayList<Character>(Arrays.asList('R', 'U', 'D'));
        List<Character> fumiyasuiGusu = new ArrayList<Character>(Arrays.asList('L', 'U', 'D'));
        String fumiyasui = "Yes";

        for (int i = 0; i < c.length; i++) {
            if ((i + 1) % 2 == 0) {
                if (!fumiyasuiGusu.contains(c[i])) {
                    fumiyasui = "No";
                    break;
                }
            } else {
                if (!fumiyasuiKisu.contains(c[i])) {
                    fumiyasui = "No";
                    break;
                }
            }
        }

        System.out.println(fumiyasui);
        sc.close();
    }
}

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

const int sz = 1e6 + 1;
bool sieve[sz], f;
int cnt[sz], num[sz];

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

void func(int n) {
	int d = 2, pre = 0;
	while (sieve[n]) {
		if (n % d == 0) {
			n /= d;
			if (pre != d) {
				if (++cnt[d] > 1) f = true;
				pre = d;
			}
		}
		else d++;
	}

	if (n != 1) {
		if (pre != n) {
			if (++cnt[n] > 1) f = true;
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
	int N;
	cin >> N;

	for (int i = 2; i < sz; i++) {
		if (sieve[i]) continue;
		for (int j = i + i; j < sz; j += i) sieve[j] = true;
	}

	for (int i = 0; i < N; i++) {
		cin >> num[i];
		func(num[i]);
	}

	if (!f) cout << "pairwise coprime";
	else {
		int g = num[0];
		for (int i = 1; i < N; i++) g = gcd(g, num[i]);
		if (g == 1) cout << "setwise coprime";
		else cout << "not coprime";
	}
}

Measured memory_bytes: 12396
import java.util.Scanner;
  class Main {
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in) ;
        int n = scan.nextInt();
        int arr[] = new int[n+1] ;
        for(int i = 1 ; i<=n ;i++){
           arr[i] = scan.nextInt();
        }
        for(int i =1  ; i<=n ; i++){
            if(arr[i] > arr[i-1]){
               
                arr[i]--;
               
            } 
        }
        int count =  0 ; 
        for(int i = 1 ; i< n ;i++){
            if(arr[i] > arr[i+1]){
                count ++ ;
            }
        }
        if(count == 0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 51076
#include<cstdio>


int main(void)
{
	int a, b;

	while(scanf("%d%d", &a, &b)==2)
	{
		int ans=a;
		if(ans>b) ans--;
		if(ans>12) ans=12;
		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//int n;
//vector< int > a(n);
//void solve() {
	//cin >> n;
	//a.resize(n);
	//for(auto& e:a) cin >> e;
//}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//int t;
	//cin >> t;
	//while (t--) solve();
	int a,b;
	cin >> a >> b;
	b -= a-1;
	for(int i=0; i<2*a-1; i++) 
	{
		cout << b << ' ';
		b++;
	}
	cout << '\n';
	return 0;
}


Measured memory_bytes: 3620
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);// ????¬???????
		String[] k1 = new String[2];
		for (int i = 0; i < 2; i++) {
			k1[i] = sc.nextLine();// ?????????????????????
		}
		String[] k2 = k1[0].split(" ");
		String[] k3 = k1[1].split(" ");// ???????????????String?????????
		Double[] d1 = new Double[v];
		Double[] d2 = new Double[v];// ?????????double
		for (int i = 0; i < v; i++) {
			d1[i] = Double.parseDouble(k2[i]);
			d2[i] = Double.parseDouble(k3[i]);// double?????£??\?????????
		}
		Double[] p = new Double[4];// ?????????????????????????????????
		for (int i = 0; i < p.length; i++) {// ???????????°??????

			if (i == 0) { // i???1??????
				Double[] an1 = new Double[v];
				p[0] = 0.0;
				for (int j = 0; j < an1.length; j++) {
					an1[j] = Math.abs(d1[j] - d2[j]);

					p[0] += an1[j];

				}
			}
			if (i == 1) {
				Double[] an2 = new Double[v];
				p[1] = 0.0;
				for (int j = 0; j < an2.length; j++) {
					an2[j] = Math.pow(Math.abs(d1[j] - d2[j]), 2);

					p[1] += an2[j];

				}
				p[1]=Math.sqrt(p[1]);
			}
			if (i == 2) {
				Double[] an3 = new Double[v];
				p[2] = 0.0;
				for (int j = 0; j < an3.length; j++) {
					an3[j] = Math.pow(Math.abs(d1[j] - d2[j]), 3);
					
					p[2] += an3[j];

				}
				p[2]=Math.cbrt(p[2]);
			}
			if (i == 3) {
				Double[] an4 = new Double[v];
				p[3] = 0.0;
				for (int j = 0; j < an4.length; j++) {
					an4[j] = Math.abs(d1[j] - d2[j]);

					if (p[3] < an4[j]) {
						p[3] = an4[j];
					}

				}
			}

		}
		BigDecimal ans0 = new BigDecimal(p[0]);
		ans0.setScale(6, BigDecimal.ROUND_HALF_DOWN);
		BigDecimal ans1 = new BigDecimal(p[1]);
		ans1.setScale(6, BigDecimal.ROUND_HALF_DOWN);
		BigDecimal ans2 = new BigDecimal(p[2]);
		ans2.setScale(6, BigDecimal.ROUND_HALF_DOWN);
		BigDecimal ans3 = new BigDecimal(p[3]);
		ans3.setScale(6, BigDecimal.ROUND_HALF_DOWN);
		for (int j = 0; j < p.length; j++) {
			System.out.println(p[j]);
		}

	}
}

Measured memory_bytes: 26584
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;

int a,b;

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

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
//using lint = long long;

struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x)
              return x>a.x;
        return y>a.y;
    }

};

vector<int> v[111111],v1;

//bitset<4001000> b;
int i,n,d,m,k,a,b,c,h;

int o[111];
long long l[111][111115];
int j[111];
int e[111111];


//int dx[10]={2,2,-2,-2,1,1,-1,-1},dy[10]={1,-1,1,-1,2,-2,2,-2};

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[311111];
stack<int> s;
//set<int> s[222][22];
//priority_queue<P> q;
queue<int> q;
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
/*
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> safe_map;
*/
//list<int> l;

string r;
//char r[2];
//deque<int> de;
//srand((int)time(NULL));
/*bool as(P a,P b)
{
    if(a.x!=b.x)
    return a.x<b.x;
    return a.y<b.y;
}*/



bool as(P a,P b)
{
    if(a.x!=b.x)
        return a.x<b.x;
    return a.y<b.y;

}

long long f(int n,int m)
{
    if(m>b) return -987654321987654321;
    if(n>a) return 0;
    if(l[n][m]>=0) return l[n][m];
    return l[n][m]=max(f(n+1,m),f(n+1,m+o[n])+j[n]);
}

int main()
{
    memset(l,-1,sizeof(l));
    scanf("%d %d",&a,&b);
    for(int t=1;t<=a;t++)
        scanf("%d %d",&o[t],&j[t]);
    printf("%lld",f(1,0));
}





Measured memory_bytes: 100096
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;

int main() {

    lli x1, y1, x2, y2, x3, y3, x4, y4;
    cin >> x1 >> y1 >> x2 >> y2;
    
    lli x = x2 - x1;
    lli y = y2 - y1;

    x3 = x2 - y;
    y3 = y2 + x;
    x4 = x1 - y;
    y4 = y1 + x;

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

int main() {
    ll k;
    cin >> k;

    int N = 50;
    vector<ll> a(N, k / N);
    REP(i, N) a[i] += i;

    REP(j, k % N) REP(i, N) {
        if(i == j) a[i] += N;
        else a[i] -= 1;
    }

    cout << N << endl;

    REP(i, N) cout << (i == 0 ? "" : " ") << a[i];
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int n,p,d,i;(n=s.nextInt())>0;){int[][]a=new int[2][n];int[]b={-1,0,0,1,1,0,0,-1};for(i=1;i<n;a[1][i++]=a[1][p]+b[d+1])a[0][i]=a[0][p=s.nextInt()]+b[d=2*s.nextInt()];Arrays.sort(a[0]);Arrays.sort(a[1]);System.out.println((a[0][--n]-a[0][0]+1)+" "+(a[1][n]-a[1][0]+1));}}}

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

using namespace std;

void solve()
{
	int N, K;
	cin >> N >> K;
	cout << ((2*K-1 <= N) ? "YES" : "NO") << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 998244353;
// 0~3までは右下左上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, 1, 0, -1, -1, 1, 1, -1 };

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

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t szi, szj;
        inp(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; }
        template <typename T> operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a;
        }
    };
    inp inp1;
}

int main() {

    ll s = inp1;

    ll x2, x3, y2, y3;

    // |x2 * y3 - x3 * y2| == s となるものを探す

    x2 = 1e9;
    x3 = 1;

    if (s % x2 == 0) {
        y2 = 0;
        y3 = s / x2;
    }
    else {
        // 少しプラス
        y3 = s / x2 + 1;
        y2 = x2 * y3 - s;
    }

    cout << 0 << " " << 0 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;
using ll = long long;
const ll INF = 1e9;

int H, W, N;
vector<int> a(10001);
vector<vector<int>> m(101);

void paint(int y, int x, int cur, int dx) { // paint if possible
    if (a[cur] == 0) cur++;
    if (y >= H || y < 0 || x < 0 || x >= W) return;
    if (m[y][x] == -1) {
        m[y][x] = cur;
        a[cur]--;
    }
    int dy = 0;
    if (dx == -1 && x == 0) { x = -1; dx = 1; dy = 1; }
    if (dx == 1 && x == W - 1) { x = W; dx = -1; dy = 1; }
    paint(y + dy, x + dx, cur, dx);
}

int main() {
    cin >> H >> W >> N;
    for (int i = 0; i < N; i++) cin >> a[i];
    for (int i = 0; i < H; i++) for (int k = 0; k < W; k++) m[i].push_back(-1);

    paint(0, 0, 0, 1);

    for (int i = 0; i < H; i++) {
        for (int k = 0; k < W; k++) {
            cout << m[i][k] + 1 << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 384
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

W, H, N = mi()

#H[0], H[1]が白い部分の左端～右端を表す
H = [0, H]
W = [0, W]

for i in range(N):
  x, y, a = mi()
  if a == 1:
    W[0] = max(x,W[0])
  elif a == 2:
    W[1] = min(x,W[1])
  elif a == 3:
    H[0] = max(y,H[0])
  else:
    H[1] = min(y,H[1])

print(max((H[1]-H[0]),0)*max((W[1]-W[0]),0))



Measured memory_bytes: 38384
from __future__ import print_function

from functools import reduce
from operator import mul
from collections import Counter
from collections import deque
from itertools import accumulate
from queue import Queue
from queue import PriorityQueue as pq
from heapq import heapreplace
from heapq import heapify
from heapq import heappushpop
from heapq import heappop
from heapq import heappush
import heapq
import time
import random
import bisect
import itertools
import collections
from fractions import Fraction
import fractions
import string
import math
import operator
import functools
import copy
import array
import re
import sys
sys.setrecursionlimit(500000)


input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    #
    n, W_max = map(int, input().strip().split())
    lv = []
    lw = []
    for _ in range(n):
        a, b = map(int, input().strip().split())
        lv.append(a)
        lw.append(b)

    l_maxSumVal = [[-1 for _ in range(n+1)] for _ in range(W_max + 1) ]
    # function to return "max sum of values" (when picking up [i-th Elarger items] into [W-spaced bagage])
    def calc_maxSumVal(i, W):
        if i > n-1: # 
            return 0
        elif l_maxSumVal[W][i] != -1:
            return l_maxSumVal[W][i]
        elif W < lw[i]: #
            l_maxSumVal[W][i+1] = calc_maxSumVal(i + 1, W)
            return l_maxSumVal[W][i+1]
        else: # if [the free space of bagage] is << Elarger than [the weight] (of items now u r looking at) >>
            l_maxSumVal[W - lw[i]][i+1] = calc_maxSumVal(i + 1, W - lw[i]) # [value of the item now u r looking at] + [max sum of values when u picking up items from i-th Elarger ones and put them into bagage whose free space is W - l_w[i]]
            l_maxSumVal[W][i+1] = calc_maxSumVal(i+1, W)
            return max(lv[i] + l_maxSumVal[W - lw[i]][i+1], l_maxSumVal[W][i+1])
    
    #
    print(calc_maxSumVal(0,W_max))

if __name__ == '__main__':
    main()



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

using namespace std;
int mod=1e9+7;
int tot[100005];
bool vis[2005][2005];
int mp[2005][2005];
int ph[2005][2005];
int pl[2005][2005];
int hdfs(int a,int h,int l,int yh,int yl,int flag)
{
    vis[h][l]=1;
    if(!mp[h][l])
    {
        if(flag>0)
            return hdfs(a,yh-1,yl,yh,yl,-1);
        else
            return a;
    }
    return ph[h][l]=hdfs(a+1,h+flag,l,yh,yl,flag);
}
int ldfs(int a,int h,int l,int yh,int yl,int flag)
{
    vis[h][l]=1;
    if(!mp[h][l])
    {
        if(flag>0)
            return ldfs(a,yh,yl-1,yh,yl,-1);
        else
            return a;
    }
    return pl[h][l]=ldfs(a+1,h,l+flag,yh,yl,flag);

}
int main()
{
    int h,l;
    scanf("%d%d",&h,&l);
    for(int i=1;i<=h;i++)
    for(int j=1;j<=l;j++)
    {
        int ch;
        while((ch=getchar()) && ch=='\n');
        if(ch=='.')mp[i][j]=1;
    }
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=l;j++)
        {
            if(mp[i][j] && !vis[i][j])
            {
                hdfs(0,i,j,i,j,1);
                ldfs(0,i,j,i,j,1);
            }
        }
    }
    int ma=-(1<<30);
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=l;j++)
        {
            ma=max(ma,ph[i][j]+pl[i][j]);
        }
    }
    printf("%d\n",ma-1);
    return 0;
}


Measured memory_bytes: 51456
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup \
  cin.tie(0);  \
  ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (int i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < v.size() - 1; ++i) {
    os << v[i] << " ";
  }
  if (v.size() > 0) {
    os << v[v.size() - 1] << endl;
  }
  return os;
}

int convert(vint vals, vector<bool> flag){
  int now = vals[0], h = flag.size() + 1;
  vint ans;
  REP(i, h - 1) {
    if (flag[i]) {
      ans.push_back(now);
      now = vals[i + 1];
    } else {
      now += vals[i + 1];
    }
  }
  ans.push_back(now);
  int maxv = ans[0];
  REP(i, ans.size()) { maxv = max(maxv, ans[i]); }
  return maxv;
}

int main() {
  int h,w,k;
  cin >> h >> w >> k;
  vector<vector<char>> G(h, vector<char>(w));
  REP(i, h) {
    REP(j, w) { cin >> G[i][j];
    }
  }
  int ans = INT_MAX;
  REP(i, (1 << (h - 1))) {
    vector<bool> flag(h-1, false);
    int tmp = 0;
    bool impossible = false;
    REP(j, h - 1) {
      if (i & (1 << j)){
        flag[j] = true;
        ++tmp;
      }
    }
    vint cums(h, 0);
    REP(j, w){
      REP(k,h){
        if (G[k][j] == '1'){
          cums[k]++;
        }
      }
      if (convert(cums, flag) > k){
        ++tmp;
        REP(k, h) {
           cums[k] = (G[k][j] == '1' ? 1 : 0);
        }
        if (convert(cums, flag) > k){
          impossible = true;
          break;
        }
      }
    }
    if (!impossible) ans = min(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
    ll n;   cin >> n;
    vector<ll> v(n+1, 0);
    rep(i, n)   cin >> v[i+1];
    sort(ALL(v));
    FOR(i, 1, n+1)   if(i%2) v[i] = 24-v[i];
    v.push_back(24);
    sort(ALL(v));
    ll res=LINF;
    rep(i, n+1) res = min(res, v[i+1]-v[i]);
    cout << res << endl;
}


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

using namespace std;

typedef long long int ll;
#define MAXN 100010



ll N, M;
char S[MAXN], T[MAXN];

ll gcd(ll a, ll b){return (b==0)?a:gcd(b, a%b);}



int main(){

	while(scanf("%lld %lld\n", &N, &M)!=EOF){

		scanf("%s\n", S);
		scanf("%s\n", T);
		ll n = M, m = N, d = gcd(n, m);
		n/=d; m/=d; 
		int pos = true;
		for(int i=0, j=0; i<N; i+=m, j+=n){
			if(S[i]!=T[j]){
				pos = false;
			}
		}
		printf("%lld\n", (pos)?(n*m*d):-1);

	}

	return 0;

}



Measured memory_bytes: 384
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
using namespace std;
using ll = long long;
const int mod = 1000000007;
using plong = pair<ll,ll>;

int main(){
    ll N;
    string S;
    string _S;
    cin>>N>>S;

    ll pre=0,pro=0;
    for(ll i=0;i<N;i++){
        if(S[i]=='(')pro++;
        else{
            if(pro==0){
                pre++;
            }else pro--;
        }

    }

    for(ll i=0;i<pre;i++){
        cout<<"(";
    }
    cout<<S;
    for(ll i=0;i<pro;i++){
        cout<<")";
    }
     cout<<endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int A,B,C,D,e,f;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    e=(A<B)?A:B;
    f=(C<D)?C:D;
    printf("%d\n",e+f);
	return 0;		
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
    int t;
    int n;
    int s, f;
    int sum;
    int i;
    
    while (1){
        scanf("%d", &t);
        if (t == 0){
            break;
        }
        
        sum = 0;
        scanf("%d", &n);
        for (i = 0; i < n; i++){
            scanf("%d%d", &s, &f);
            sum += (f - s);
        }
        
        if (sum >= t){
            printf("OK\n");
        }
        else {
            printf("%d\n", t - sum);
        }
    }
    return (0);
}

Measured memory_bytes: 612
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(S, T):
    if len(set(c for c in T) - set(c for c in S)) > 0:
        return -1

    from collections import defaultdict
    si = defaultdict(list)
    for i, c in enumerate(S):
        si[c].append(i)

    ans = 0
    ci = 0
    from bisect import bisect_left
    for i, c in enumerate(T):
        j = bisect_left(si[c], ci)
        if j == len(si[c]):
            j = 0
            ans += 1
        ci = si[c][j] + 1
    return (ans)*len(S) + ci





def main():
    S = read_str()
    T = read_str()
    print(slv(S, T))


if __name__ == '__main__':
    main()


Measured memory_bytes: 63844
#include<stdio.h>	
int main(void)
{
		int n,a,b,c,d;
		scanf("%d %d",&n,&a);
		b=n/500;
		c=n-(500*b);
		d=a-c;
		if(d>=0){
		printf("Yes\n",d);
		}	
		else{
		printf("No\n",d);
		}
		return 0;		
}					

Measured memory_bytes: 128
def gcd(a, b):
    while b: a, b = b, a % b
    return abs(a)
N, X, D = map(int, input().split())
if D == 0:
    print(N+1 if X else 1)
    exit()
g = gcd(X, D)
X //= g
D //= g
if D < 0:
    X, D = -X, -D

E = {}
for i in range(N+1):
    k = i % D
    l, r = i * (2*X+(i-1)*D) // 2, i * (2*X+(2*N-i-1)*D) // 2
    c = (r - l) // D + 1 if D else 1
    if k not in E:
        E[k] = (l, r, c)
    else:
        ll, rr, cc = E[k]
        if r < ll:
            E[k] = (l, rr, cc + c)
        elif l > rr:
            E[k] = (ll, r, cc + c)
        elif l < ll:
            E[k] = (l, rr, cc + ((ll - l) // D if D else 1))
        elif r > rr:
            E[k] = (ll, r, cc + ((r - rr) // D if D else 1))

ans = 0
for e in E:
    l, r, c = E[e]
    ans += c

print(ans)


Measured memory_bytes: 79828
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())
    S = readline().strip()

    COM_MAX = 2 * 10 ** 6

    fac, finv, inv = [0] * (COM_MAX + 1), [0] * (COM_MAX + 1), [0] * (COM_MAX + 1)
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2, COM_MAX + 1):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    def mod_com(n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0
        return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD

    M = len(S)
    L = K + M

    ans = 0
    p = pow(25, K + 1, MOD)
    for i in range(M - 1, -1, -1):
        ans += mod_com(L, i) * p
        p = p * 25 % MOD

    ans = (pow(26, L, MOD) - ans) % MOD
    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 123044
#include<iostream>

using namespace std;
int main()
{
	int n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	int moneyX=0,moneyY=0;
	for(int i=0;i<n;){
		moneyX+=b;
		i+=a;
	}
	//cout<<moneyX<<endl; 	
	for(int i=0;i<n;){
		moneyY+=d;
		i+=c;
		
	}	
	//cout<<moneyY<<endl;
	if (moneyX<=moneyY){
		cout<<moneyX<<endl; 
	}
	else cout<<moneyY<<endl;

} 


Measured memory_bytes: 3096
#include <iostream>
#include <map>
#include <algorithm>
#include <string>

using namespace std;

string ch = "UPC";

int main()
{
  string str;
  map<char, int> mpp;
  int p;
  while(cin>>str){
    for(int i = 0; i < str.size(); i++){
      if(mpp.find(str[i]) != mpp.end()) mpp[str[i]]++;
      else mpp[str[i]] = 1;
    }

    p = mpp['K'];
    for(int i = 0; i < 3; i++) p = min(p, mpp[ch[i]]);

    cout << p << endl;
    mpp.clear();
  }


  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = s; i < (int)(n); i++)
#define print(a) cout << (a) << endl; 
typedef long long ll;
const int MOD = 1000000007; 

int GCD(int a, int b) {
    if (a < b) swap(a, b); 
    if (b == 0) return a;
    return GCD(b, a%b);
}

int main() {
    int K; 
    cin >> K;
    int ret = 0;
    REP(a, K) {
        REP(b, K) {
            REP(c, K) {
                int g = GCD(a+1, GCD(b+1, c+1));
                ret += g;
            }
        }
    } 
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3636