akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
inline int gcd(int a,int b){
	if(b==0){
		return a;
	}
	return gcd(b,a%b); 
}
int main(){
	long long N;
    while(cin>>N){
        for(long long h=1;h<=3500;h++){
        	for(long long n=1;n<=3500;n++){
            	long long t1=N*h*n;
            	long long t2=4*n*h-N*(h+n);
            	if((t2>0)&&(t1%t2==0)){
               	 	cout<<h<<" "<<n<<" "<<t1/t2<<endl;
                	return 0;
            	}
        	}
		}
    }
	/*
	int gcdd=gcd(n,4);
	if(gcdd==4){
		cout<<n/gcdd*3<<" "<<n/gcdd*3<<" "<<n/gcdd*3<<endl;
	}else if(gcdd==2){
		cout<<n/gcdd<<" "<<n/gcdd*2<<" "<<n/gcdd*2;
	}else{
		int gcdd=gcd(n,n/4+1);
		cout<<n/4+1<<" "<<(n*(n*4+1)/gcdd)/(4*(4*n+1)*gcdd-n*gcdd);
	}
	*/
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		int N=sc.nextInt(),answer=0;
		int smaller=0,smallest=0;
		int larger=0,largest=0;
		int[] A=new int[N+2];
		A[0]=0;
		A[N+1]=0;
		for(int i=1;i<N+1;i++){
			A[i]=sc.nextInt();
			answer=answer+Math.abs(A[i-1]-A[i]);
		}
		answer=answer+Math.abs(A[N]);
		for(int i=1;i<N+1;i++){
			if(A[i-1]<A[i] &&A[i+1]<A[i]){
				System.out.println(answer-Math.abs(A[i-1]-A[i])-Math.abs(A[i]-A[i+1])+Math.abs(A[i-1]-A[i+1]));
			}else if(A[i-1]>A[i] && A[i+1]>A[i]){
				System.out.println(answer-Math.abs(A[i-1]-A[i])-Math.abs(A[i]-A[i+1])+Math.abs(A[i-1]-A[i+1]));
			}else{
				System.out.println(answer);
			}
		}
	}
}


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

int main()
{
    string s;
    cin >> s;
    // for(int i=0;i<s.size();i++) if(!(i&1)) cout << s[i];
    for(int i=0;i<s.size();i+=2) cout << s[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;


inline bool isin(int x, int y, int w, int h)
{
	return 0 <= x && x < w && 0 <= y && y < h;
}


void dfs(int x, int y, int d, vector<vector<int> > &f, int &ans)
{
	int dxs[] = {-1, 0, 0, 1};
	int dys[] = {0, -1, 1, 0};
	int w = f.size(), h = f[0].size();
	d += 1;
	if(d > 10)
		return;
	//printf("debug: %d %d %d\n", x, y, d);

	for(int dir = 0; dir < 4; ++dir) {

		int cx = x, cy = y;
		int dx = dxs[dir], dy = dys[dir];

		if(!isin(x + dx, y + dy, w, h) || f[x + dx][y + dy] == 1)
			continue;

		while(true) {

			int nx = cx + dx;
			int ny = cy + dy;

			if(!isin(nx, ny, w, h))
				break;

			if(f[nx][ny] == 3) {
				ans = min(ans, d);
				break;
			}

			if(f[nx][ny] == 1) {
				f[nx][ny] = 0;
				dfs(cx, cy, d, f, ans);
				f[nx][ny] = 1;
				break;
			}

			cx = nx;
			cy = ny;
		}
	}
}


int main()
{
	while(true) {

		int w, h;
		vector<vector<int> > f;
		int sx, sy;

		scanf("%d%d", &w, &h);
		if(w == 0)
			break;

		f.resize(w);
		for(int i = 0; i < f.size(); ++i)
			f[i].resize(h);

		for(int y = 0; y < h; ++y) {
			for(int x = 0; x < w; ++x) {
				scanf("%d", &f[x][y]);
				if(f[x][y] == 2) {
					sx = x;
					sy = y;
				}
			}
		}

		const int inf = 1000000;
		int ans = inf;
		dfs(sx, sy, 0, f, ans);
		if(ans >= inf)
			ans = -1;

		printf("%d\n", ans);
	}

	return 0;
}

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

const int mn=2e5+7;
int ans[mn];
string s[mn],t;

int main()
{
	int n,a,b,c;
	scanf("%d%d%d%d",&n,&a,&b,&c);
	if(a+b+c==0) {puts("No");return 0;}
	if(a+b+c==1) {
		for(int i=1;i<=n;++i) {
			cin>>t;
			if(t=="AB") {
				if(a+b==1) {ans[i]=(b?1:2);swap(a,b);}
				else {puts("No");return 0;}
			}
			if(t=="BC") {
				if(b+c==1) {ans[i]=(c?2:3);swap(b,c);}
				else {puts("No");return 0;}
			}
			if(t=="AC") {
				if(a+c==1) {ans[i]=(a?3:1);swap(a,c);}
				else {puts("No");return 0;}
			}
		}
		puts("Yes");
		for(int i=1;i<=n;++i) {putchar('A'+ans[i]-1);puts("");}
		return 0;
	}
	for(int i=1;i<=n;++i) cin>>s[i];
	for(int i=1;i<=n;++i) {
		if(s[i]=="AB") {
			if(a==b&&a==0&&i==1) {puts("No");return 0;}
			if(a==b&&a==1) {
				if(s[i+1]=="AC") ans[i]=1,a++,b--;
				else ans[i]=2,a--,b++;
				continue;
			}
			if(a>=b) ans[i]=2,a--,b++;
			else ans[i]=1,a++,b--;
		}
		if(s[i]=="BC") {
			if(b==c&&b==0&&i==1) {puts("No");return 0;}
			if(b==c&&b==1) {
				if(s[i+1]=="AB") ans[i]=2,b++,c--;
				else ans[i]=3,b--,c++;
				continue;
			}
			if(b>=c) ans[i]=3,c++,b--;
			else ans[i]=2,c--,b++;
		}
		if(s[i]=="AC") {
			if(a==c&&a==0&&i==1) {puts("No");return 0;}
			if(a==c&&a==1) {
				if(s[i+1]=="AB") ans[i]=1,a++,c--;
				else ans[i]=3,a--,c++;
				continue;
			}
			if(a>=c) ans[i]=3,a--,c++;
			else ans[i]=1,a++,c--;
		}
	}
	puts("Yes");
	for(int i=1;i<=n;++i) {putchar('A'+ans[i]-1);puts("");}
}

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

int main() {
  int a,b;
  std::cin >> a >> b;
  if ((a*b)%2 == 0){
    std::cout << "Even" << '\n';
  }
  else {
    std::cout << "Odd" << '\n';
  }
}


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

int main()
{
   char s[3],t[3];
   cin >> s >> t;
   int ans = 0;
   if(s[0] == t[0])
     ans++;
   if(s[1] == t[1])
     ans++;
   if(s[2] == t[2])
     ans++;
   cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n, m;
	int i;
	int count;
	int persons;
	int a[1000];

	while (1){
		scanf("%d %d", &n, &m);

		if (n == 0 && m == 0){
			break;
		}

		for (i = 1; i <= n; i++){
			a[i] = 1;
		}

		persons = n;
		count = 1;

		for (i = 1; i <= n; i++){
			if (a[i] == 1 && count % m == 0){
				a[i] = 0;
				persons--;
			}
			else if (a[i] == 0){
				count--;
			}

			count++;

			if (persons == 1){
				break;
			}

			if (i == n){
				i = 0;
				continue;
			}
		}

		for (i = 1; i <= n; i++){
			if (a[i] == 1){
				printf("%d\n", i);
			}
		}
	}

	return (0);
}

Measured memory_bytes: 600
#include <stdio.h>
#define MOD 1000000007
long long int power(long long int s, long long int t)
{
	long long int ans = 1;
	long long int k = s;
	while(t)
	{
		if(t%2==1) ans*=k, ans%=MOD;
		k*=k, k%=MOD;
		t/=2;
	}
	return ans;
}

long long int inv(long long int t)
{
	return power(t,MOD-2);
}

long long int fact[500010];
long long int comb(int s, int t)
{
	long long int ans = fact[s];
	ans *= inv(fact[t]), ans %= MOD;
	ans *= inv(fact[s-t]), ans %= MOD;
	return ans;
}

long long int func(int s, int t)
{
	long long int C = comb(t,s);
	C *= fact[s], C%=MOD;
	return (C*C)%MOD;
}
int main()
{
	fact[0] = 1;
	for(int i=1;i<=500000;i++) fact[i] = fact[i-1]*i, fact[i]%=MOD;
	
	
	long long int a,b;
	scanf("%lld%lld",&a,&b);
	
	long long int ans = 0;
	for(int i=0;i<=a;i++)
	{
		long long int C = 1;
		if(i%2==0)
		{
			C *= comb(a,i), C%= MOD;
			C *= comb(b,i), C%= MOD;
			C *= fact[i], C%= MOD;
			C *= func(a-i,b-i), C%= MOD;
			ans += C;
		}
		else
		{
			C *= comb(a,i), C%= MOD;
			C *= comb(b,i), C%= MOD;
			C *= fact[i], C%= MOD;
			C *= func(a-i,b-i), C%= MOD;
			ans -= C;
		}
		ans += MOD;
		ans %= MOD;
	}
	printf("%lld",ans);
	
}

Measured memory_bytes: 5644
a, b = map(int, input().split())

# p = max(1, b) - max(1, a) + 1
n = min(-1, b) - min(0, a) + 1

if a <= 0 <= b:
    print("Zero")
elif n % 2 == 0:
    print("Positive")
else:
    print("Negative")


Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,p;
  cin >> n >> p;
  bool check = true;
  rep(i, n){
    int a; cin >> a;
    if(a & 1) check = false;
  }
  if(p && check) cout << 0 << endl;
  else if(check) cout << (ll)pow(2, n) << endl;
  else cout << (ll)pow(2, n - 1) << endl;
}

Measured memory_bytes: 4108
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<utility>
#include<vector>
#include<stack>
#include<queue>
#include<cstring>
#include<set>
#include<map>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define st first
#define nd second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long lo;
const int mod=1000000007,N=500005;
lo a,b,c,d,e,f,g=1,h[N],arr[N];
string s;
vector<lo>v;
 
void solve(){
	cin >> a >> b >> c;
	if((b-1)/a!=c/a)cout << "OK" << endl;
	else cout << "NG" << endl;
}
 
int main(){
	#ifdef local
		freopen("in.txt","r",stdin);
		freopen("out.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	// cin >> g;
	while(g--)solve();
}

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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int) 1e5 + 7;
int n, k, a[N], dp[N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 2; i <= n; i++) {
    dp[i] = (int) 1e9;
    for (int j = i - 1; j >= i - k && j >= 1; j--) {
      dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
    }
  }
  cout << dp[n] << "\n";
  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

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

    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (i * j == n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 888
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var dishes = new List<long[]>();
            for (int i = 0; i < N; i++)
            {
                var input = ReadArrayInt();
                dishes.Add(new long[] { input[0], input[1], input[0] + input[1] });
            }
            dishes = dishes.OrderByDescending(d => d[2]).ToList();
            var ans = 0L;
            for (int i = 0; i < N; i++)
            {
                if (i % 2 == 0) ans += dishes[i][0];
                else ans -= dishes[i][1];
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 30508
s = list(input())

ans = min(1, len(s) // 2)
prev = -1
for i in range(ans, len(s) + 1):
    m_b = len(s) - i
    m_e = i
    is_ok = True
    if m_b < m_e:
        m_e = m_e - 1
        if prev == -1:
            prev = s[m_b]
        if prev != s[m_b] or prev != s[m_e]:
            is_ok = False
    if is_ok:
        ans = i
    else:
        break
print(ans)

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> b = a;
    sort(b.begin(),b.end());
    for (int i = 0; i < n; i++) {
        if (a[i] == b[n-1]) {
            cout << b[n-2] << endl;
        }
        else {
            cout << b[n-1] << endl;
        }
    }
}


Measured memory_bytes: 3200
import java.util.Scanner;

class Main {

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

        boolean yes = true;
        int kyori = 0;
        int ima = 0;

        for (i = 0; i < N; i++) {
            kyori = i * 10;

            if (ima < kyori) {
                //ここで飛距離とトランポリンの場所を求めてkyoriよりimaが下だったときyesをfalseにして計算を終わる

                yes = false;
                //kyoriはトランポリンのある場所。飛距離は場所とトランポリンの合計

            }
            int hikyori = kyori + d[i];
            if (hikyori > ima) {
                ima = hikyori;
            }
        }
            ima = 0;
            for (i = 0; i < N; i++) {
                kyori = i * 10;

                if (ima < kyori) {
                    yes = false;
                }
               int  hikyori = kyori + d[N-1-i];
                
                
                if (hikyori > ima) {
                    ima = hikyori;
                }
            }
            if (yes) {
                System.out.println("yes");

            } else {
                System.out.println("no");

            }
        

    }
}



Measured memory_bytes: 103572
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a = list(map(int, readline().split()))

    ans = 0
    while all([x % 2 == 0 for x in a]):
        a[0], a[1], a[2] = a[1] + a[2], a[2] + a[0], a[0] + a[1]
        a[0] //= 2
        a[1] //= 2
        a[2] //= 2
        ans += 1
        if a[0] == a[1] == a[2]:
            return print(-1)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62000
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

void divisor(int n, vector<int>& a) {
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            a.push_back(i);
            if (i * i != n) a.push_back(n / i);
        }
    }
}

int main() {
    int n;
    cin >> n;
    int ans = 0;
    vector<int> a(n);
    map<int, vector<int>> d;
    map<int, int> c;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (c[a[i]] == 0) divisor(a[i], d[a[i]]);
        c[a[i]] += 1;
    }
    for (int i = 0; i < n; i++) {
        bool cond = true;
        for (int j : d[a[i]]) {
            if (!d[j].empty()) {
                if (j == a[i] && c[j] == 1) continue;
                cond = false;
                break;
            }
        }
        if (cond) ans += 1;
    }
    cout << ans << endl;
}


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

d = 0
cnt = 0
min_a = A[0]
for i in range(1, N):
  a = A[i]
  if min_a > a:
    min_a = a
    continue
 
  if d < a - min_a:
    d = a - min_a
    cnt = 1
  elif d == a - min_a:
    cnt += 1
print(cnt)

Measured memory_bytes: 20500
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)

L = 10**14
num = -1
for n in range(N):
    q = [n]
    checked = [False]*N
    checked[n] = True
    before = [None]*N
    c = 0
    ok = False
    while q:
        c += 1
        qq = []
        for p in q:
            for np in graph[p]:
                if not checked[np]:
                    before[np] = p
                    qq.append(np)
                    checked[np] = True
                elif np == n:
                    before[np] = p
                    ok = True
                    break
        if ok: break
        q = qq
    
    if ok and c < L:
        L = c
        num = n
        ans = []
        k = n
        for _ in range(c):
            k = before[k]
            ans.append(k+1)

if num == -1:
    print(-1)
else:
    print(len(ans))
    for a in reversed(ans):
        print(a)    


Measured memory_bytes: 3316
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    long N, M;
    scan(N, M);
    auto f = factorize(M);
    long ans = 1;
    auto C = Combination_mod(500000);
    foreach (key, val; f)
    {
        ans *= C(val + N - 1, val);
        ans %= MOD;
    }
    writeln(ans);
}

T[U] factorize(T = long, U = long)(T x)
{
    assert(0 < x, "x is negative");
    long[long] ps;
    while ((x & 1) == 0)
        x /= 2, ps[2] = (2 in ps) ? ps[2] + 1 : 1;
    for (long i = 3; i * i <= x; i += 2)
        while (x % i == 0)
            x /= i, ps[i] = (i in ps) ? ps[i] + 1 : 1;
    if (x != 1)
        ps[x] = (x in ps) ? ps[x] + 1 : 1;
    return ps;
}

/// Number of k-combinations % m (precalculated)
alias Combination_mod = Combination_modImpl!long;
struct Combination_modImpl(T)
{
    T _n, _m;
    T[] _fact, _factinv;
    this(T maxnum, T mod = 10 ^^ 9 + 7)
    {
        _n = maxnum, _m = mod, _fact = new T[](_n + 1), _factinv = new T[](_n + 1), _fact[0] = 1;
        foreach (i; 1 .. _n + 1)
            _fact[i] = _fact[i - 1] * i % _m;
        T powmod(T x, T n, T m)
        {
            if (n < 1)
                return 1;
            if (n & 1)
            {
                return x * powmod(x, n - 1, m) % m;
            }
            T tmp = powmod(x, n / 2, m);
            return tmp * tmp % m;
        }

        foreach (i; 0 .. _n + 1)
            _factinv[i] = powmod(_fact[i], _m - 2, _m);
    }

    T opCall(T n, T k, T dummy = 10 ^^ 9 + 7)
    {
        return n < k ? 0 : ((_fact[n] * _factinv[n - k] % _m) * _factinv[k] % _m);
    }
}


Measured memory_bytes: 11424
<?php
fscanf(STDIN, "%d%d", $n, $p);
$aArray = array_map("intval", explode(" ", trim(fgets(STDIN))));

$odd[0] = 0;
$even[0] = 1;
for($i = 1; $i <= $n; $i++){
  if($aArray[$i-1] % 2){
    $odd[$i] = $odd[$i-1]+$even[$i-1];
    $even[$i] = $odd[$i-1]+$even[$i-1];
  }else{
    $odd[$i] = $odd[$i-1]*2;
    $even[$i] = $even[$i-1]*2;
  }
}

if($p == 1){
  printf("%d", $odd[$n]);
}else{
  printf("%d", $even[$n]);
}


Measured memory_bytes: 4728
N = int(input())
L = list(map(int, input().split()))
l = len(L)
L2 = sorted(L)
ans = (L2[l//2 - 1], L2[l//2])

if ans[0] == ans[1]:
    for n in range(N):
        print(ans[0])
else:
    for n in L:
        if n < ans[1]:
            print(ans[1])
        else:
            print(ans[0])
            

Measured memory_bytes: 26772
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n;
  cin >> n;

  int k = 1;
  while(true){
    if(k * (k + 1) / 2 >= n) break;
    ++k;
  }

  vector< int > p;
  for(int i = 1; i <= k; i++){
    if(i == k * (k + 1) / 2 - n) continue;
    p.push_back(i);
  }

  string buf;
  for(int i: p){
    buf += to_string(i) + "\n";
  }

  cout << buf;

  return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int N;
	int m1=-1,m2=-1;
	vector<int>A;
	cin>>N;
	for(int i=0;i<N;i++)
	{
		int a;
		cin>>a;
		A.push_back(a);
		if(m1<a)
		{
			m2=m1;
			m1=a;
		}
		else if(m2<a)
		{
			m2=a;
		}
	}
	for(int i=0;i<N;i++)
	{
		if(A[i]==m1)
		{
			cout<<m2<<endl;
		}
		else
		{
			cout<<m1<<endl;
		}
	}
}

Measured memory_bytes: 2548
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int r, g, b;
    cin >> r >> g >> b;
    int num = 100 * r + 10 * g + b;
    
    
    if (num % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>

int main(void){
  char s[1001], order[8], ch[1001];
  int i, j, n, a, b;

  scanf("%s\n%d", s, &n);

  for(i=0;i<n;i++){
    scanf("%s %d %d", order, &a, &b);
    
    if(!strcmp(order, "reverse")){
      for(j=a;j<=b;j++)
        ch[b-j] = s[j];
      for(j=a;j<=b;j++)
        s[j] = ch[j-a];
    }

    if(!strcmp(order, "replace")){
      scanf("%s", ch);
      for(j=0;ch[j]!='\0';j++)
        s[a+j] = ch[j];
    }

    if(!strcmp(order, "print")){
      for(j=a;j<=b;j++)
        printf("%c", s[j]);
      printf("\n");
    }
  }

  return 0;
}


Measured memory_bytes: 2096
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<complex>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int grid[20][20000];
int solve() {
    int R, C;
    scanf("%d%d", &R, &C);
    if (R==0 && C==0) return -1;
    REP(i, R) REP(j, C) scanf("%d", &grid[i][j]);
    int powR = pow(2, R);
    int ans = 0;
    REP(i, powR) {
        int sum = 0;
        REP(k, C) {
            int a=0, b=0;
            REP(j, R) (i>>j&1)^(grid[j][k]) ? a++ : b++;
            sum += max(a, b);
        }
        ans = max(ans, sum);
    }
    return ans;
}
int main() {
    int ans;
    while((ans = solve())>=0){
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1656
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};

int main(){
	int N,L;
	cin>>N>>L;
	multiset<string> tes;
	for(int i=0;i<N;i++){
		string S;
		cin>>S;
		tes.insert(S);
	}
	for(auto it=tes.begin();it!=tes.end();it++){
		cout<<*it;
	}
	cout<<endl;
	return 0;
}

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

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

const int N = 1e5 + 11;
const int M = 1e6 + 11;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);

int main(int argc, char **args){
    //freopen("in.txt", "r", stdin);
    double r; cin >>r;
    cout << 2 * PI * r<<"\n";
return 0;
}


Measured memory_bytes: 3784
n = int(input())
dics = {}
for i in range(n):
    try:
        s = input()
        dics[s] += 1
    except KeyError:
        dics[s] = 1
max_v = max(dics.values())

max_k_list = [kv[0] for kv in dics.items() if kv[1] == max_v]
max_k_list.sort()
for i in max_k_list:
    print(i)

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

int main()
{
  int H, W;
  cin >> H >> W;
  
  for (int h = 1; h <= H; h++)
  {
    string C; cin >> C;
    cout << C << endl << C << endl;
  }
  
  return 0;
}

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

ans = 0
while True:
    ok = True
    for i, a in enumerate(A):
        if a % 2 == 0:
            A[i] //= 2
        else:
            ok = False
            break
    if not ok:
        break
    ans += 1

print(ans)    


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << ((sizeof...(tail)!=0)?" ":""); print(forward<Tail>(tail)...); }
template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a << ((&a!=&vec.back())?" ":""); } cout << endl; }
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }

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

    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    rep(i, n) rep(j, n) cin >> a[i][j];

    vector<vector<int>> b = a; 
    rep(k, n) rep(i, n) rep(j, n) {
        b[i][j] = min(b[i][j], b[i][k]+b[k][j]);
    }

    if (a!=b) print(-1);
    else {
        rep(k, n) rep(i, n) rep(j, n) {
            if (i==k || j==k) continue;
            if (a[i][j]==a[i][k]+a[k][j]) {
                // print(i, j, k);
                b[i][j]=0;
            }
        }
        // print(b);
        ll total = 0;
        rep(i, n) FOR(j, i, n) total += b[i][j];
        print(total);
    }
}

Measured memory_bytes: 1024
//#pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007// prime modulo value 
#define C 1000000001
#define M 998244353
#define all(x) x.begin(),x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y)
{
	ll res = 1;

	x = x;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x);
		y = y >> 1;
		x = (x * x);
	}
	return res;
}
double dist(ll x1, ll y1, ll x2, ll y2)
{
	double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = 0;
	if (((b - a) % 2 )== 0)
	{
		ans= (b - a) / 2;
	}
	else
	{
		if (b - 1 <= n - a)
		{
			ans += a;
			b -= a;
			a = 1;
			ans += (b - a) / 2;
		}
		else
		{
			ans += n-b+1;
			a += n-b+1;
			b = n;
			ans += (b - a) / 2;
		}
	}
	
	cout << ans;
	return 0;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define li long
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pli pair<li,li>
#define pll pair<ll,ll>
#define pb push_back
#define fori(i,k,n) for(int i = k;i<n; i++)
#define rfori(i,k,n) for(int i = k; i>=n; i--)
#define tc int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define inf INT_MAX
#define ninf INT_MIN
#define W(x) cout<<x<<endl
#define WW(x,y) cout<<x<<' '<<y<<endl;
#define in(x) cin>>x
//#define int long long
const ll mod = 998244353;
const ll mod2 = 1e9+7;
template <class T>
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
} 
template<class T>
T power(T a,T b){
    T res = (T)1;
    while(b>0){
        if(b&1)res = res*a;
        b>>=1;
        a*=a;
    }
    return res;
}
struct Node{
    int first;int second;
    Node(int x,int y){
        this->first = x;
        this->second = y;
    }
};
struct comparator{
    bool operator()(const Node &a,const Node &b){
        int lena = a.second-a.first+1;
        int lenb = b.second-b.first+1;
        if(lena == lenb)return a.first<b.first;
        else return lena>lenb;
    }
};
ll power(ll x,ll y,ll mod){
    ll res = 1;
    x%=mod;
    while(y>0){
        if(y&1)res = (res*x)%mod;
        y>>=1;
        x = (x*x)%mod;
    }
    return res;
}

signed main(){
    long long n;
	cin>>n;
	string s;
	cin>>s;
	long long a = (s[0]-'0')*100 + (s[2]-'0')*10 + (s[3]-'0');
	n *= a;
	cout<<n/100;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define present(i, c) ((c).find(i) != (c).end())

#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define fora(i, a, b) for(int i = (a); i < (b); i++)
#define ford(i, n) for(int i = (n)-1; i >= 0; i--)

#define TRACE(x...) x
#define watch(x) TRACE(cerr << #x" = " << x << endl)
#define watch_all(x) TRACE(cerr << #x" = "; for(auto __i : x) cerr << __i << " "; cerr << endl)
	
#define INF 0x3F3F3F3F

//=========================

int A[100001][3];
int dp[100001][3];

void run_test() {
	int N; cin >> N;
    for1(i, N) cin >> A[i][0] >> A[i][1] >> A[i][2];
    ini(dp, 0);
    for1(i, N)
        for0(a, 3) 
            for0(b, 3)
                if(a != b)
                    dp[i][a] = max(dp[i][a], dp[i-1][b] + A[i][a]);
    int ans = 0;
    for0(i, 3) ans = max(ans, dp[N][i]);
    cout << ans << endl;
}

//=========================

ifstream infile;
clock_t start__;
void open_func();
void close_func();

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	open_func();
	//int t; cin >> t; while(t--) run_test();
	run_test();
	close_func();
	return 0;	
}

void open_func() {
	//infile = ifstream("input.in"); if(infile.good()) cin.rdbuf(infile.rdbuf());
	start__ = clock();
	cerr << "---" << endl;
}

void close_func() {
	clock_t elapsed = clock()-start__;
	cerr << "---" << endl << "(time " << fixed << setprecision(2) << elapsed * (1.0/CLOCKS_PER_SEC) << "s)" << endl;	
	//if(infile.good()) infile.close();
}


Measured memory_bytes: 6144
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a,b,c,d = map(int, input().split())

g = math.gcd(c, d)
l = lcm(c, d)

print(b-a+1 - (b//c - (a-1)//c + b//d - (a-1)//d -b//l + (a-1)//l))

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

int main(void){
    long long N;cin>>N;
    long long A[N],B[N-1];
    for(long long i=0;i<N-1;i++){
        cin>>B[i];
    }
    A[0]=B[0];
    for(long long i=1;i<N;i++){
        if(i==N-1){
            A[i]=B[i-1];    
        }
        else{
            A[i]=min(B[i],B[i-1]);
        }
    }
    long long ans=0;
    for(long long i=0;i<N;i++){
        ans+=A[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3476
import numpy as np
n,m,x=map(int,input().split())
c=[0]*n
a=[0]*n
for i in range(n):
  tmp=list(map(int,input().split()))
  c[i]=tmp[0]
  a[i]=tmp[1:]
price=sum(c)+1
for i in range(2**n):
  now_p=0
  score=np.zeros(m)
  
  for j in range(n):  # このループが一番のポイント
    if ((i >> j) & 1):
      score = score + np.array(a[j])
      now_p+=c[j]
  if np.count_nonzero(score < x) == 0 and price > now_p:
    price = now_p

if price < sum(c) +1:
  print(price)
else:
  print(-1)
  
     

Measured memory_bytes: 27092
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

sort_A = sorted(A)
max = sort_A[N - 1]
sec = sort_A[N - 2]

count = A.count(max)

if count == 1:
  p = A.index(max)
  
  for i in range(p):
    print(max)
  
  print(sec)
  
  for j in range(p,N - 1):
    print(max)

else:
  for k in range(N):
    print(max)

Measured memory_bytes: 14112
//Apparat : drobucs, aleonov, vit_72
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <iomanip>
#include <algorithm>
#include <string>
#include <queue>
#include <numeric>

//#pragma warning(disable : 4996)
//#pragma GCC optimize("O3")

using namespace std;

#define nptr nullptr
#define all(x) (x).begin(), (x).end()
#define drobucs ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define ff first
#define ss second
#define pb push_back
#define sz(x) (int)(x).size()

typedef  long long ll;

const int maxn = (int)2e6 + 13;
const ll INFL = 9223372036854775807;
const ll INF = 2147483647;
const ll MOD = (int)1e9 + 7, MOD2 = 998244353;//1e9 + 21, 1e9 + 33, 1e9 + 87, 1e9 + 93
const ll base = 101, base2 = 37;


int main() {
	drobucs;
	
	ll n;
	cin >> n;
	ll x = 2;
	ll nn = n;
	map<ll ,ll> mp;
	while (n != 1 && x * x <= nn) {
		while (n % x == 0)n /= x, mp[x]++;
		x++;
	}
	if (n != 1)mp[n]++;
	ll ans = 0;
	for (auto t : mp) {
		ll l = 1, r = t.second;
		while (r - l > 1) {
			ll m = (l + r) / 2;
			if (m * (m + 1) / 2 > t.second)r = m;
			else l = m;
		}
		ans += l;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define int long long
//BEGIN CUT HERE
struct UnionFind{
  int n;
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};
//END CUT HERE

signed main(){
  int n,q;
  cin>>n>>q;
  UnionFind uf(n);
  for(int i=0;i<q;i++){
    int c,x,y;
    cin>>c>>x>>y;
    if(c) cout<<uf.same(x,y)<<endl;
    else uf.unite(x,y);
  }
  return 0;
}
/*
verified on 2017/10/29
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A&lang=jp
*/

Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define count2way(v, x) high2way(v, x) - low2way(v, x)
#define lower(v, x) low2way(v, x) - v.begin()       //1番左が0、もし見つから無いならｎを出力
#define higher(v, x) high2way(v, x) - v.begin() - 1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout << a << endl
#define putout2(a, b) \
    putout(a);        \
    putout(b)
#define putout3(a, b, c) \
    putout(a);           \
    putout(b);           \
    putout(c)
#define putout4(a, b, c, d) \
    putout(a);              \
    putout(b);              \
    putout(c);              \
    putout(d)
#define putout5(a, b, c, d, e) \
    putout(a);                 \
    putout(b);                 \
    putout(c);                 \
    putout(d);                 \
    putout(e)
#define Gput(a, b) G[a].push_back(b)
#define cin1(a) cin >> a
#define cin2(a, b) cin >> a >> b
#define cin3(a, b, c) cin >> a >> b >> c
#define cin4(a, b, c, d) cin >> a >> b >> c >> d
#define cin5(a, b, c, d, e) cin >> a >> b >> c >> d >> e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
template <typename T>
T modinv(T a, T m)
{
    T b = m, u = 1, v = 0;
    while (b)
    {
        T t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//多次元配列の宣言法
//vector<vector<ll>> field(h, vector<ll>(w));
template <class T>
inline void chmax(T &a, T b)
{
    if (a < b)
        a = b;
}
template <class T>
inline void chmin(T &a, T b)
{
    if (a > b)
        a = b;
}
/*
ライブラリをここに置いてコメントを削除
*/

int main()
{
    cout << fixed << setprecision(30);
    long double a, b;
    cin >> a >> b;
    ll c = floor(a * b);
    putout(c);
    return 0;
}


Measured memory_bytes: 3792
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


//ABC123_b
int main() {
	int ans = 0;
	int ext = 0;
	rep(i, 5) {
		int a;
		cin >> a;
		ans += (a + 9) /10 * 10;
		ext = max(ext, (1000-a)%10);
	}
	ans = ans - ext;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 2e5 + 5;
class SegmentTree {
private:
	int lazy[N << 2], t[N << 2];
	void build() { memset(t, 0, sizeof t), memset(lazy, 0, sizeof lazy); }
	void push(int l, int r, int x) {
		t[x] += lazy[x];
		if (l != r) {
			lazy[x << 1] += lazy[x];
			lazy[x << 1 | 1] += lazy[x];
		}
		lazy[x] = 0;
	}
	void upd(int l, int r, int s, int e, int x, int val) {
		push(l, r, x);
		if (l > r || l > e || r < s) return;
		if (s <= l && r <= e) {
			lazy[x] += val;
			push(l, r, x);
			return;
		}
		int m = (l + r) >> 1;
		upd(l, m, s, e, x << 1, val);
		upd(m + 1, r, s, e, x << 1 | 1, val);
		t[x] = max(t[x << 1], t[x << 1 | 1]);
	}
	int get(int l, int r, int s, int e, int x) {
		push(l, r, x);
		if (l > r || l > e || r < s) return -infll;
		if (s <= l && r <= e) return t[x];
		int m = (l + r) >> 1;
		return max(get(l, m, s, e, x << 1), get(m + 1, r, s, e, x << 1 | 1));
	}
public:
	int n;
	void init(int _n) { n = _n, build(); }
	void upd(int l, int r, int val) { upd(0, n - 1, l, r, 1, val); }
	int get(int l, int r) { return get(0, n - 1, l, r, 1); }
} st;
typedef pair<int, int> ii;
int n, m, dp[N], f[N];
vector<ii> le[N];
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	st.init(n);
	cin >> m;
	fw (i, 0, m) {
		int l, r, c;
		cin >> l >> r >> c;
		l--, r--;
		le[r].pb(ii(l, c));
		st.upd(l, r, c);
	}
	fw (i, 0, n) f[i] = st.get(i, i);
	st.init(n);
	fw (i, 0, n) {
		dp[i] = max(0ll, st.get(0, i - 1));
		dp[i] += f[i];
		st.upd(i, i, dp[i] - f[i]);
		fa (j, le[i]) {
			int cost = j.se, l = j.fi;
			st.upd(l, i, cost);
		}
//		cout << "dp[" << i << "] = " << dp[i] << "\n";
	}
	int ans = 0;
	fw (i, 0, n) ans = max(ans, dp[i]);
	cout << ans;
	return 0;
}

Measured memory_bytes: 26880
#include<stdio.h>
int d[30][30],w,h;
int X[]={0,1,0,-1};
int Y[]={1,0,-1,0};
int f(int x,int y,int m){
  int i,j,ny,nx,b;
  if(m==0)return 0;
  for(i=0;i<4;i++){
    for(j=1;d[y+Y[i]*j][x+X[i]*j]==1;j++);
    if(d[ny=y+Y[i]*j][nx=x+X[i]*j]==4)return 1;
    if(d[ny][nx]==0||j==1)continue;
    if(d[ny][nx]==2)b=2;
    else            b=1;
    d[ny][nx]=1;
    if(f(nx-X[i],ny-Y[i],m-1))return 1;
    d[ny][nx]=b;
  }
  return 0;
}
int main(){
  int i,j,sy,sx;
  while(scanf("%d %d",&w,&h),w||h){
    for(i=1;i<=h;i++){
      for(j=1;j<=w;j++){
	scanf("%d",&d[i][j]);
	if(d[i][j]==2)d[sy=i][sx=j]=0;
	d[i][j]++;
      }
      d[i][j]=0;
    }
    for(j=1;j<=w;j++)d[i][j]=0;
    for(i=1;i<11;i++){
      if(f(sx,sy,i))break;
    }
    if(i-11)printf("%d\n",i);
    else    printf("-1\n");
  }
  return 0;
}
	

Measured memory_bytes: 616
# coding: utf-8
# Your code here!

import bisect
from collections import defaultdict

N = int(input())
X = sorted(list(map(int, input().rstrip().split(' '))), reverse=False)
included_X = defaultdict(int)
pow_2 = [2**i for i in range(1, 50)]

for x in X:
    included_X[x] += 1

count = 0
for i, x in enumerate(X[::-1]): 
    if included_X[x] > 0:
        index = bisect.bisect_left(pow_2, x + 1)
        if pow_2[index] - x == x:
            if included_X[pow_2[index] - x] > 1:
                included_X[pow_2[index] - x] -= 2
                count += 1
        else:
            if included_X[pow_2[index] - x] > 0:
                included_X[pow_2[index] - x] -= 1
                included_X[x] -= 1
                count += 1
         
print(count)


Measured memory_bytes: 56124
n,m = map(int, raw_input().split())

map = []
for i in xrange(n):
	map.append(list(raw_input()))
	if not 'c' in map[i]:
		map[i] = [-1 for _ in xrange(m)]
		continue
	elif map[i][0] == '.':
		for j in xrange(m):
			if map[i][j] == '.':
				map[i][j] = -1
			else : break
	for j in xrange(m):
		if map[i][j] == 'c':
			map[i][j] = 0
			hoge = 0
			for k in xrange(j + 1, m):
				hoge += 1
				if map[i][k] == 'c' : break
				else : map[i][k] = hoge
				
for var in map:
	for vin in var:
		print vin,
	print

Measured memory_bytes: 6444
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;
const int sz = 2005;

int n;
ll dp[sz];

ll go(int s) {
	if (s == 1 || s == 2)
		return 0;
	if (dp[s] != 0)
		return dp[s];
	for (int i = 3; i <= s; i++) {
		dp[s] += go(s - i) % mod;
		dp[s] %= mod;
	}
	return dp[s];
}

void solve() {
	cin >> n;
	dp[0] = 1;
	cout << go(n);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		//cout << endl;
	}
}

Measured memory_bytes: 3672
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n,m,a,b,c,d,x,y,z;
  string s,t;
  //

  // ここから
  IN(n);
  if(n<1200) OUT("ABC");
  else OUT("ARC");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    bool ans = true;
    for(int i=0; i<n; ++i) {
        int a;
        cin>>a;
        if(a%2)
            continue;
        if(a%3 && a%5) {
            ans = false;
            break;
        }
    } 
    if(ans) cout<<"APPROVED\n";
    else cout<<"DENIED\n";
}

Measured memory_bytes: 256
def rectangleArea(x,y)
  return x * y
end

def rectangleLength(x,y)
  return (x + y) * 2
end

s = gets.chomp
x = s.split(" ")[0].to_i
y = s.split(" ")[1].to_i

puts rectangleArea(x,y).to_s + ' ' + rectangleLength(x,y).to_s

Measured memory_bytes: 8652
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<ld> vld;

#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()

const int mod = 1e9 + 7;
ll ksm(ll x, int n)
{
	ll ans = 1;
	while(n)
	{
		if(n & 1) ans = (ans*x) % mod;
		x = x*x % mod;
		n >>= 1;
	}

	return ans % mod;
}

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

	if(n < 2) cout << 0 << endl;
	else if(n == 2) cout << 2 << endl;
	else 
	{
		ll ans;

		ans = ksm(10LL,n) - 2*ksm(9LL,n) + ksm(8LL,n);
		ans = (ans % mod + mod) % mod;

		cout << ans << endl;

	}

	return 0;
}

Measured memory_bytes: 3604
import math
N, H = map(int,input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int,input().split())
    A.append(a)
    B.append(b)
MAX = max(A)
B.sort(reverse = True)
ans = 0
for i in B:
    if i > MAX:
        ans += 1
        H -= i
    else:
        break
    if H <= 0:
        break
if H > 0:
    ans += math.ceil(H / MAX)
print(ans)

Measured memory_bytes: 11316