akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using Pair = pair<int, int>;
const ll mod = 1e9 + 7;

struct Sieve {
  vector<int> table;
  Sieve(int n=2): table(n+1) {
    table[0] = table[1] = -1;
    for (int i=2; i<=n; i++) {
      if (table[i]) continue;
      for (int j=i+i; j<=n; j+=i) {
        table[j] = i;
      }
    }
  }

  void print() {
    for (auto e: table) {
      cout << e << " ";
    }
    cout << endl;
  }

  map<int, int> primes(int i) {
    map<int, int> m;
    if (i < 2) return m;
    // (素数, カウント)
    // ex. primes(12) == {(2, 2), (3, 2)}
    while(table[i]) {
      m[table[i]]++;
      i /= table[i];
    }
    m[i]++;
    return m;
  }
};

ll power(ll base, ll exponent, ll module)
{
  if(exponent % 2) {
    return power(base, exponent - 1, module) * base % module;
  } else if(exponent) {
    ll root_ans = power(base, exponent / 2, module);
    return root_ans * root_ans % module;
  } else {
    return 1;
  }
}


int main(int argc, char const* argv[])
{
  int n;
  cin >> n;

  int max_ = 0;
  vector<int> as;
  REP(i, n) {
    int a;
    cin >> a;
    as.push_back(a);
    if (max_ < a) max_ = a;
  }

  Sieve sieve(max_);

  map<int, int> lcm_map;
  for (auto a: as) {
    map<int,int> ps = sieve.primes(a);
    for (auto p: ps) {
      if (lcm_map[p.first] < p.second) lcm_map[p.first] = p.second;
    }
  }

  ll c = 1;
  for (auto e: lcm_map) {
    c = (c * power(e.first, e.second, mod)) % mod;
  }

  ll ans = 0;
  for (auto a: as) {
    ll b = (c * power((ll)a, mod-2, mod)) % mod;
    ans = (ans + b) % mod;
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    int N, M; cin >> N >> M;
    vector<int> A(N);
    int MAX = 0;
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
        MAX += A.at(i);
    }
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    double ex = (double) MAX/(4*M);
    int count = 0;
    for (int i = 0; i < M; i++)
    {
        if(A.at(i) >= ex){
            count++;
        }
    }
    if(count == M) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

ll n, m, q, t, ans = 0;
vector<ll> a, b, c, d, A;
void dfs(int dep, int num) {
  if (dep == n) {
    t = 0;
    rep(i, q) if (A[b[i]] - A[a[i]] == c[i]) t += d[i];
    ans = max(ans, t);
    return;
  }

  for (int i = num; i <= m; ++i) A[dep] = i, dfs(dep + 1, i);
}

int main() {
  cin >> n >> m >> q;
  A.resize(n);
  a.resize(q);
  b.resize(q);
  c.resize(q);
  d.resize(q);
  rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i], a[i]--, b[i]--;

  dfs(0, 1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define f1(n) for(int i=0;i<n;++i)
#define f2(n) for(int i=1;i<=n;++i)
#define lson(x) x<<1
#define rson(x) x<<1|1
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
const int maxn = 4e5 + 5;
const int mod = 0x3f3f3f3f;
const ll Mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll Inf = (ll)1e15;
int a[maxn];

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

	int k, n;
	cin >> k >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a, a + n);
	int res = 0;
	for (int i = 0; i < n; ++i) {
		if (i == n - 1)res = max(res, k - a[n - 1] + a[0]);
		else res = max(res, a[i + 1] - a[i]);
	}

	cout << k - res << endl;
	
	
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
int cnt=0;
int a[3],b[3]={50,100,500},n;
int main()
{
	scanf("%d%d%d%d",&a[2],&a[1],&a[0],&n);
	for(int i=0;i<=a[0];i++)
	{
		int x=i*50;
		if(x>n) break;
		for(int j=0;j<=a[1];j++)
		{
			int y=x+j*100;
			if(y>n) break;
			for(int k=0;k<=a[2];k++)
			{
				int z=y+k*500;
				if(z>n) break;
				if(z==n) cnt++;
			}
		}
	}
	printf("%d\n",cnt);		
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define COUT(x) cout << (x) << endl
using namespace std;
typedef pair<int,int> P;
typedef long long int ll;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main() {
    int n; cin >> n;
    pair<pair<string, int>, int> p[110];
    rep(i, n) {
        string s;
        int score;
        cin >> s >> score;
        p[i] = make_pair(make_pair(s, score * -1), i + 1);
    }
    sort(p, p + n);
    rep(i, n) COUT(p[i].second); 
    
    return 0;
}

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

int main() {
    ll n, m; cin >> n >> m;
    ll ans;
    if (n == m / 2) ans = n; 
    else if (n > m / 2) ans = m / 2;
    else ans = n + (m - n * 2) / 4;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void){
	int n;
	//d[0] = 1patern d[1] = 1paten d[2] = 2patern
	int dp[41] = {1, 1, 2};
	for(int i = 3; i <= 31; i++){
		dp[i] = dp[i-3] + dp[i-2] + dp[i-1];
	}
	while(cin >> n, n)
		FIN(dp[n]/3650 + 1);

	return 0;
}

Measured memory_bytes: 1160
import math

mod=1000000007

count=[0 for i in range(1000005)]

def factorize(x):
	lim= int(math.sqrt(x))
	for i in range(2,lim+1):
		if x%i == 0:
			c=0
			while x%i==0:
				x/=i
				c+=1
			x=int(x)

			if count[i]<c: count[i]=c
	if x>1:	
		if count[x]<1: count[x]=1

def minus(ans,x):
	lim= int(math.sqrt(x))
	for i in range(2,lim+1):
		if x%i == 0:
			c=0
			while x%i==0:
				x/=i
				c+=1
			x=int(x)

			ans*= pow(pow(i,c),mod-2,mod)
			ans%=mod

	ans*= pow(pow(x,1),mod-2,mod)
	ans%=mod

	return int(ans)

n=int(input())
l= list(map(int,input().split()))

ans=0
for x in l:
	factorize(x)

ans=1
for i in range(1,1000005):
	ans*= pow(i,count[i],mod)
	ans%=mod

lc=ans
res=0
for x in l:
	res+=minus(lc,x)
	res%=mod

print(res)

Measured memory_bytes: 115440
judge={"AC":0,"WA":0,"TLE":0,"RE":0}
n=int(input())
for i in range(n):
    s=input()
    judge[s]+=1
ans=["AC","WA","TLE","RE"]
for i in ans:
    ans=i+" x "
    ans+=str(judge[i])
    print(ans)


Measured memory_bytes: 9076
import math
N = int(input())
C = [0]*(N-1)
S = [0]*(N-1)
F = [0]*(N-1)

for i in range(N - 1):
    C[i], S[i], F[i] = map(int, input().split())

times = [0]*N
for j in range(N-1):
    time = 0
    for i in range(j, N-1):
        if time <= S[i]:
            time = S[i]
        else:
            time = math.ceil(time / F[i]) * F[i]
        time += C[i]

    times[j] = time
for i in range(N):
    print(times[i])


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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(),(c).end())

// repetition
// -----------------------------------------------------------------------------
#define FOR(i, a, b) for(ll i= (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
// -----------------------------------------------------------------------------
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int N; cin >> N;
    int ans = (1000 - (N % 1000)) % 1000;
    cout << ans << "\n";
}

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

int main() {
  int N, a, ans = 0;
  map<int, int> mp;

  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> a;
    if (mp.find(a) != mp.end()) {
      mp[a]++;
    } else {
      mp[a] = 1;
    }
  }
  for (map<int, int>::iterator it=mp.begin(); it!=mp.end(); ++it) {
    ans += (it->second < it->first) ? it->second : it->second - it->first;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4736
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#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>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//ここまでテンプレ
int main(){
	int N,x;
	cin>>N>>x;
	if(x==1 || x==2*N-1){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	bool done[SIZE]={};
	deque<int> deq;
	if(N==2){
		cout<<x+1<<endl<<x<<endl<<x-1<<endl;
		return 0;
	}
	if(x==2){
		deq.pb(2);
		done[2]=1;
		deq.pb(3);
		done[3]=1;
		deq.push_front(1);
		done[1]=1;
		deq.push_front(4);
		done[4]=1;
	}
	else{
		deq.pb(x);
		done[x]=1;
		deq.pb(x-1);
		done[x-1]=1;
		deq.push_front(x+1);
		done[x+1]=1;
		deq.push_front(x-2);
		done[x-2]=1;
	}
	int ind=1;
	for(int i=0;i<2*N-5;i++){
		while(done[ind])
			ind++;
		if(i%2==0)
			deq.pb(ind);
		else
			deq.push_front(ind);
		done[ind]=1;
	}
	//vint vec;
	for(int i:deq){
		//vec.pb(i);
		cout<<i<<endl;
	}
	/*
	for(int i=0;i<vec.size()-1;i++){
		cout<<vec[i]<<" ";
	}
	cout<<vec.back()<<endl;
	*/
	return 0;
}

Measured memory_bytes: 2560
# vim: ft=ruby

class Solver
  def prepare
    @d = gets.to_i
    @cs = gets.split(" ").map(&:to_i)
    @mans = []  # mans[date][contest]

    @last = [0] * 26

    @d.times do
      @mans << gets.split(" ").map(&:to_i)
    end
  end

  # ----------- #

  def score(contest_id, date)
    @mans[date][contest_id]
  end

  def decrease_per_contest(contest_id, date)
    @cs[contest_id] * (date - @last[contest_id])
  end

  def decrease_all(date)
    (0..25).map do |contest_id|
      decrease_per_contest(contest_id, date)
    end.sum
  end


  # TOOLS

  def evaluate(ts)
    res = 0
    ts.each.with_index do |t, d|  # d = date
      t -= 1
      res += score(t, d)
      @last[t] = d+1
      res -= decrease_all(d+1)
    end
    res
  end

  def random_contest
    (0..25).to_a.sample
  end

  def random_pattern
    @d.times.map { random_contest }
  end

  def uniform_pattern
    ((0..25).to_a * 20)[0, @d]
  end

  def print_result(pattern)
    pattern.each do |p|
      puts p+1
    end
  end

  def elapsed_time
    time_now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    time_now - $time_start
  end

  ALPHA = 0.6
  MAX_TIME = 2
  def temperature
    r = elapsed_time / MAX_TIME
    ALPHA ** r
  end

  def probability(e_prev, e_next)
    t = temperature

    if e_next > e_prev
      # if e_next is better, always move
      1
    else
      # temperature
      remaining_time = MAX_TIME - elapsed_time
      remaining_time ** 2
      # Math.exp((e_prev - e_next) / t)
    end
  end

  # TOOLS END

  def change_randomly(pattern)
    pattern = pattern.dup
    pos = random_contest
    pattern[pos] = random_contest
    pattern
  end

  def swap_randomly(pattern)
    pattern = pattern.dup
    pos = rand(@d-1)
    c = pattern[pos]
    pattern[pos] = pattern[pos+1]
    pattern[pos+1] = c
    pattern
  end

  def solve
    pattern = uniform_pattern
    e = evaluate(pattern)

    count = 0
    movecount = 0

    # namasu
    loop do
      count += 1
      break if elapsed_time > 1.87
      new_pattern = swap_randomly(pattern)
      e_next = evaluate(new_pattern)

      r = rand
      if r < probability(e, e_next)
        movecount += 1
        pattern = new_pattern
        e = e_next
      end
    end

    # end namasu

    if ENV['DEBUG']
      STDERR.puts movecount
      STDERR.puts count
    end

    print_result(pattern)
  end

end

$time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
solver = Solver.new
solver.prepare
solver.solve


Measured memory_bytes: 15892
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll INF = ll(1e18)+1;


int main(void) {
  int n;
  cin >> n;
  cout << (n+1)/2 << endl;

  return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

int v[MAXN];

/*ll calc(int *v1, int *v2, int n1, int n2) {
	ll ans = 0ll;
	int i1 = 0, i2 = 0;
	for(; i1 < n1 && i2 < n2; ) {
		ans += abs(v1[i1] - v2[i2]);
		if (i1 == i2) {
			i1++;
		} else {
			i2++;
		}
	}
	return ans;
}*/

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, n) {
		scanf("%d", &v[i]);
	}
	sort(v, v + n);
/*ll ans = calc(v, v + (n + 1) / 2, (n + 1) / 2, n - (n + 1) / 2);
	if (n % 2 == 1) {
		ans = max(ans, calc(v + n / 2, v, n - n / 2, n / 2));
	}
	printf("%lld\n", ans);*/
	ll ans = 0ll;
	if (n % 2 == 0) {
		REP(i, 0, n) {
			if (i == n / 2 - 1) {
				ans -= v[i];
			} else if (i < n / 2 - 1) {
				ans -= 2 * v[i];
			} else if (i == n / 2) {
				ans += v[i];
			} else {
				ans += 2 * v[i];
			}
		}
	} else {
		REP(i, 0, n) {
			if (i == n / 2 - 1 || i == n / 2) {
				ans -= v[i];
			} else if (i < n / 2 - 1) {
				ans -= 2 * v[i];
			} else {
				ans += 2 * v[i];
			}
		}
		ll cur = 0ll;
		REP(i, 0, n) {
			if (i == n / 2 || i == n / 2 + 1) {
				cur += v[i];
			} else if (i < n / 2) {
				cur -= 2 * v[i];
			} else {
				cur += 2 * v[i];
			}
		}
		ans = max(ans, cur);
	}
	printf("%lld\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int a = in.nextInt();
        int b = in.nextInt();
        boolean[] ans = new boolean[3];
        ans[a - 1] = true;
        ans[b - 1] = true;
        for (int i = 0; i < 3; i++) {
            if (!ans[i]) {
                out.println(i + 1);
            }
        }
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 22228
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val d = Array(N) { sc.next().toInt() }.sorted()
        val ABC = d.take(N / 2)
        val ARC = d.takeLast(N / 2)
        pw.println(ARC.first() - ABC.last())
    }
}


Measured memory_bytes: 56128
s = input()
ans = 'AC'

if s[0] != 'A':
  ans = 'WA'

if 'C' not in s[2:-1]:
  ans = 'WA'
  
if s[2:-1].count('C') != 1:
  ans = 'WA'
  
if not s.replace('A', '').replace('C', '').islower():
  ans = 'WA'
  
print(ans)


Measured memory_bytes: 3060
n,a,b=map(int,input().split())
def ssum(l):
  q=0
  for i in range(len(str(l))):
    q+=int(str(l)[i])
  return q
ans=0
for i in range(1,1+n):
  if a<= ssum(i) <= b:
    ans+=i
print(ans)

Measured memory_bytes: 2940
#include <iostream>

using namespace std;


long long solve(long long x){
    if(x % 2 == 1){
        return ((x+1)/2 % 2);
    }else{
        return (((x+1+1)/2 % 2) ^ (x+1));
    }
}


int main(){
    long long A, B;
    cin >> A >> B;

    cout << (solve(B) ^ solve(A-1)) << endl;


    return 0;
}

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

using namespace std;

typedef long long ll;

#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = b - 1; i >= ll(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> vvc(H);
    REP(i, H)
    {
        string s;
        cin >> s;
        vvc[i] = s;
    }
    int ans = 0;
    REP(i, 1 << H)
    REP(j, 1 << W)
    {
        int cnt = 0;
        REP(k, H)
        REP(l, W)
        if (!((1 << k) & i) && !((1 << l) & j) && (vvc[k][l] == '#'))
            cnt++;
        if (cnt == K)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<cstring>

using namespace std;

#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif

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

typedef unsigned long long u64;
typedef long long i64;

int n;
int w[105];
int s[105];


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

        cin >> n;
        REP(i,n)
                cin >> w[i];

        s[0] = w[0];
        for(int i=1; i<n; i++)
                s[i] = s[i-1] + w[i];

        int m = 0xffffff;
        REP(i,n) {
                int k = s[n-1]-2*s[i];
                m = min(m, k > 0 ? k : -k);
        }

        cout << m << endl;


        return 0;
}


Measured memory_bytes: 256
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

from collections import Counter

def main():
    N = i2n()
    A = i2nn()
    # 問題を数式化
    #   A[i-1] ^ A[i+1] = A[i] 
    # 移項する
    #   A[i-1] ^ A[i+1] - A[i] = 0
    #   A[i-1] ^ A[i+1] ^ A[i] = 0
    # 漸化式を考える
    #   A[i+1] = A[i-1] ^ A[i] 
    #   A[2] = A[0] ^ A[1] 
    # 漸化式をもう少し考える
    #   A[3] = A[1] ^ A[2] 
    #       A[1] ^ A[2] = A[0] なので
    #   A[3] = A[0]
    #   A[i+3] = A[i]
    # Nが3の倍数でないとき
    #   A[i] = A[j]
    #   A[i] ^ A[i+1] = A[i+2]
    #       A[i] = A[i+1] なので
    #   A[i+2] = 0
    #   よって, Aの要素は全てゼロ
    # Nが3の倍数のとき
    #   Counterを使う
    #       要素数1: 全てゼロ
    #       要素数2: 片方ゼロ, ゼロのカウンタ*2 = もう一方のカウンタ (0,x,x)=>{0:1, x:2}
    #       要素数3: カウント値は全て同じ
    c = Counter(A)
    k = list(c.keys())
    v = list(c.values())
    if len(c) == 1:
        if k[0] == 0:
            print('Yes')
            return
    if len(c) == 2:
        if k[0] == 0 and v[0] * 2 == v[1]:
            print('Yes')
            return
        if k[1] == 0 and v[1] * 2 == v[0]:
            print('Yes')
            return
    if len(c) == 3:
        if k[0] ^ k[1] ^ k[2] == 0:
            if v[0] == v[1] and v[1] == v[2]:
                print('Yes')
                return
    print('No')

main()


Measured memory_bytes: 57136
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;

int dx[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

typedef struct {
	int a; int b; int c; int d;
} MT;

int n, m, q, a, b, c, d, ans, selected[20];
vector<MT> v;

int calc() {
	int ret = 0;
	for (int i = 0; i < q; i++) {
		if (selected[v[i].b] - selected[v[i].a] == v[i].c) {
			ret += v[i].d;
		}
	}
	return ret;
}

void f(int idx, int vmax) {
	if (idx > n) {
		ans = max(ans, calc());
		return;
	}
	for (int i = vmax; i <= m; i++) {
		selected[idx] = i;
		f(idx + 1, i);
	}
}

int main() {
	cin >> n >> m >> q;
	for (int i = 0; i < q; i++) {
		cin >> a >> b >> c >> d;
		v.pb({ a, b, c, d });
	}
	f(1, 1);
	cout << ans;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
int main () {
  int K;
  vector<int> data(3);
  cin >> data[0] >> data[1] >> data[2] >> K;
  sort(data.begin(),data.end());
  cout <<(int) data[2] * pow(2, K) + data[1] + data[0] << endl;
  return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

const int MAX_N = 110;
const int MAX_V = 100100;

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

int N;
LL W, weight[MAX_N], value[MAX_N];

LL dp[MAX_N][MAX_V];

int main() {

	cin >> N >> W;
	for (int i = 0; i < N; i++) {
		cin >> weight[i] >> value[i];
	}

	for (int i = 0; i < MAX_N; i++) {
		for (int j = 0; j < MAX_V; j++) {
			dp[i][j] = INF2;
		}
	}

	dp[0][0] = 0;

	for (int i = 0; i < N; i++) {
		for (int sum_v = 0; sum_v < MAX_V; sum_v++) {
			if (sum_v - value[i] >= 0)chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]);

			chmin(dp[i + 1][sum_v], dp[i][sum_v]);
		}
	}

	LL res = 0;
	for (int sum_v = 0; sum_v < MAX_V; sum_v++) {
		if (dp[N][sum_v] <= W)res = sum_v;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 86272
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end() 
using namespace std;
typedef long long ll;

int n;

int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cin >> n;
   string ret = "";
   ll x = 1l;
   while(n != 0) {
       if(n % abs(2*x) != 0) 
           ret = '1' + ret, n -= x;
       else
           ret = '0' + ret;
       x *= -2;
   }
   if(ret.length() == 0) ret = '0';
   cout << ret << "\n";
   return 0;
} 


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

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

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

    ll a = n/k;
    ll b = (n+(k/2))/k;

    if (k%2 == 0) {
        cout << a*a*a + b*b*b;
    } else {
        cout << a*a*a;
    }

    cout << endl;


    
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a[100010];
ll b[100100];
ll c[100010];
int main()
{
    int i, j, k;
    int n, t, m;
    int x, y;
    cin >> x >> y;
    int A, B;
    cin >> A >> B;
    int C;
    cin >> C;
    for(i = 0; i < A; i++) scanf("%lld", &a[i]);
    for(i = 0; i < B; i++) scanf("%lld", &b[i]);
    for(i = 0; i < C; i++) scanf("%lld", &c[i]);
    sort(a, a+A, greater<int>() );
    sort(a, a+x);
    sort(b, b+B, greater<int>() );
    sort(b, b+y);
    sort(c, c+C, greater<int>() );
    ll sum = 0;
    int la = 0;
    int lb = 0;
    int lc = 0;
    while((la < x || lb < y) && lc < C) {
        int mx = 1e9+10000;
        int ty = -1;
        if(la < x && a[la] < mx) {
            mx = a[la];
            ty = 1;
        }
        if(lb < y && b[lb] < mx) {
            mx = b[lb];
            ty = 2;
        }
        if(c[lc] > mx) {
            sum += c[lc];
            lc++;
            if(ty == 1) la++;
            else lb++;
        }
        else {
            if(ty == 1) {
                sum += a[la];
                la++;
            }
            else sum += b[lb], lb++;
        }
    }
    while(la < x) {
        sum += a[la];
        la++;
    }
    while(lb < y) {
        sum += b[lb];
        lb++;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
long long n;
long long arr[500];
long long prefix[500]={};
long long dp[500][500];
long long rec(int l, int r){
	if(l == r)return 0;
	if(dp[l][r] != -1)return dp[l][r];
	long long ret = 1e18;
	for(int i = l; i < r; i++){
		ret = min(ret, rec(l, i) + rec(i+1, r));
	}
	ret += prefix[r] - prefix[l-1];
	return dp[l][r] = ret;
}
int main(){
	cin >> n;
	prefix[0] = 0;
	for(int i = 1; i <= n; i++)
		cin >> arr[i], prefix[i] = prefix[i-1] + arr[i];
	for(int i = 0; i < 500; i++)
		for(int j = 0; j < 500; j++)
			dp[i][j] = -1;
	cout << rec(1, n);
		
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define INF 100000000000000000ll
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

void subsetsUtil(vector<ll>& A, vector<vector<ll> >& res, 
                 vector<ll>& subset, ll index) 
{ 
    res.push_back(subset); 
    for (int i = index; i < A.size(); i++) { 
        subset.push_back(A[i]); 
        subsetsUtil(A, res, subset, i + 1); 
        subset.pop_back(); 
    } 
  
    return; 
} 
  
vector<vector<ll>> subsets(vector<ll>& A) 
{ 
    vector<ll> subset; 
    vector<vector<ll>> res; 
    ll index = 0; 
    subsetsUtil(A, res, subset, index); 
    return res; 
} 

int main() {
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll n,m,x;
    cin>>n>>m>>x;
    vector<ll> v;
    for (int i = 0; i < n; ++i)
    {
        v.push_back(i);
    }
    vector<vector<ll>> res = subsets(v);
    vector<ll> val[n];
    vector<ll> cost;
    for (int i = 0; i < n; ++i)
    {
        ll c;
        cin>>c;
        cost.push_back(c);
        for (int j = 0; j < m; ++j)
        {
            ll a1;
            cin>>a1;
            val[i].push_back(a1);
        }
    }

    map<ll, vector<ll>> m1;
    for (int i = 0; i < res.size(); i++)
    { 
        vector<ll> v2;
        for (int j = 0; j < res[i].size(); j++)
        {
               v2.push_back(res[i][j]);
        }
        vector<ll> tot;
        if(v2.size()>0){
            for (int it = 0; it < m; ++it)
            {
                ll sum=0;
                ll cos=0;
                for (int j = 0; j < v2.size(); ++j)
                {
                    sum = sum + val[v2[j]][it];
                    cos = cos + cost[v2[j]];
                }
                m1[cos].push_back(sum);
            }
        }
    }

    ll an=-1;
    for (auto it = m1.begin(); it != m1.end(); ++it)
    {
        ll fg=0;
        vector<ll> v5 = it->S;
        for (int i = 0; i < v5.size(); ++i)
        {
            if(v5[i]<x){
                fg=1;
                break;
            }
        }
        if(fg==0){
            an=it->F;
            break;
        }
    }
    cout<<an;

    return 0;
}


Measured memory_bytes: 4780
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
using P=pair<int,int>;

const int MAX=2011;

int n,k,xy[MAX][MAX],X[MAX][MAX];

void prepare(){
  for(int i=1;i<=2*k+2;i++)
    for(int j=1;j<=2*k+2;j++)
      X[i][j]=xy[i][j]+X[i-1][j]+X[i][j-1]-X[i-1][j-1];
}

int getsize(int x1,int y1,int x2,int y2){
  if(x1>x2 || y1>y2)
    return 0;
  else
    return X[x2][y2]-X[x1-1][y2]-X[x2][y1-1]+X[x1-1][y1-1];
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>k;
  for(int i=0;i<n;i++){
    int x,y;
    char c;
    cin>>x>>y>>c;
    if(c=='W') y+=k;
    x%=(2*k);
    y%=(2*k);
    xy[x+1][y+1]++;
  }
  prepare();
  int ans=0;
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      int tmp=getsize(1,1,i-1,j-1)+getsize(i,j,i+k-1,j+k-1)+getsize(i+k,j+k,2*k,2*k)+getsize(1,j+k,i-1,2*k)+getsize(i+k,1,2*k,j-1);
      ans=max(ans,max(tmp,n-tmp));
	}
  }
  cout<<ans<<endl;
  return 0;
}
   

Measured memory_bytes: 31744
from collections import defaultdict
import bisect


S = input()
T = input()

if set(T) - set(S):
    print(-1)
    exit()

dic = defaultdict(list)
for pos, s in enumerate(S):
    dic[s].append(pos)

now = -1
count = 0
for t in T:
    if dic[t][-1] < now+1:
        now = -1
        count += 1
    idx = bisect.bisect_left(dic[t], now+1)
    now = dic[t][idx]

ans = count*len(S) + now + 1
print(ans)

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
 
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
void fastscan(int &x)
 {
        bool neg=false;
        register int c;
        x =0;
        c=getchar();
        if(c=='-')
        {
            neg = true;
            c=getchar();
        }
        for(;(c>47 && c<58);c=getchar())
            x = (x<<1) + (x<<3) +c -48;
        if(neg)
            x *=-1;
    } 
string alpha = "abcdefghijklmnopqrstuvwxyz";
const int mod = 1e9+7;
const int inf = 2e18+5;
const int nax = 100010;
const int mod1 = 998244353;

signed main()
 {
     int n,m,sum = 0;
      cin>>n>>m;
      vector<int> v(n);
      loop(i,0,n)
        {
          cin>>v[i];
          sum += v[i];
        }
      //sort(v.begin(),v.end(),greater<int>());
       //sum = ceil((sum/(4*m))+0.005);
       //cerr<<sum;
    int rp = 4*m;
       int ok = 0;
      loop(i,0,n)
         {
          if(v[i]*rp>=sum)
             ok++;
         }
      if(ok<m)
         cout<<"No"<<END;
      else
         cout<<"Yes"<<END;
     return 0;
}


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

int main(){
  string s,t;
  cin >>s>>t;
  bool ans=false;
  for(int i=0;i<s.size();i++){
    if(s==t){
      ans=true;
      break;
    }
    s=s.back()+s.substr(0,s.size()-1);
  }
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
signed main(){
int a,b;
cin>>a>>b;
vector<int> w(a),v(a);
rep(i,a)
cin>>w[i]>>v[i];
int dp[110][100010];
rep(i,110)rep(j,100010)
dp[i][j]=INF;
dp[0][0]=0;

rep(i,a)rep(j,100010){
if(j>=v[i])
  chmin(dp[i+1][j],dp[i][j-v[i]]+w[i]);
chmin(dp[i+1][j],dp[i][j]);
}
int ans=0;
rep(i,100010){
if(dp[a][i]<=b)
  ans=i;
}
cout<<ans<<endl;
}

Measured memory_bytes: 86144
#include <bits/stdc++.h>
using namespace std;
int N,M;
int L,R;
int ans=0;
int main(){
    cin >> N >> M;
    vector<int> le(M+1);
    vector<int> ri(M+1);
    for(int i=0;i<M;i++){
        cin >> le.at(i) >> ri.at(i);
    }
    L=le[0];
    R=ri[0];
    for(int i=1;i<M;i++){
//        if(ri.at(i)>=L || le.at(i)<=R){
            if(L<le.at(i)){
                L=le.at(i);
            }
            if(R>ri.at(i)){
                R=ri.at(i);
            }
        }
//    }
    if(L<=R){
        ans=R-L+1;
    }
    cout << ans;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;

int main() {
	int n,flag = 0;
	cin >> n ;
	string s[101];
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		if (s[i] == "Y") flag = 1;
	}

	if (flag == 1) cout << "Four" << endl;
	else cout << "Three" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static double _theta = Math.PI / 6;
	static double _2r3 = 2 * Math.sqrt(3);
	static double _6sub2r3 = 6 - _2r3;
	static Main m = new Main();

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		Vec right = m.new Vec(0, 0);
		Vec left = m.new Vec(100, 0);
		koch(n, right, left);
		System.out.println(left);
	}

	static void koch(int n, Vec l, Vec r) {
		if (n == 0) {
			System.out.println(l);
			return;
		}
		Vec inleft = m.new Vec((2 * l.x + r.x) / 3, (2 * l.y + r.y) / 3);
		double tmpx = (_6sub2r3 * l.x + _2r3 * r.x) / 6 - l.x;
		double tmpy = (_6sub2r3 * l.y + _2r3 * r.y) / 6 - l.y;
		double x = tmpx * Math.cos(_theta) - tmpy * Math.sin(_theta) + l.x;
		double y = tmpx * Math.sin(_theta) + tmpy * Math.cos(_theta) + l.y;
		Vec incent = m.new Vec(x, y);
		Vec inright = m.new Vec((l.x + 2 * r.x) / 3, (l.y + 2 * r.y) / 3);
		koch(n - 1, l, inleft);
		koch(n - 1, inleft, incent);
		koch(n - 1, incent, inright);
		koch(n - 1, inright, r);
	}

	class Vec {
		double x = 0;
		double y = 0;

		public Vec(double x, double y) {
			this.x = x;
			this.y = y;
		}

		public String toString() {
			return new StringBuilder(30).append(x).append(' ').append(y).toString();
		}
	}
}


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

int main(){
    int W, H, x, y;
    cin >> W >> H >> x >> y;
    if ( 2 * x == W && 2 * y == H){
        cout << fixed;
        cout << setprecision(10) << double(W) * double(H) / 2;
        cout << " " << 1 << endl;
    }
    else {
        cout << fixed;
        cout << setprecision(10) << double(W) * double(H) / 2;
        cout << " " << 0 << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
#define int long long
int N, K;
signed main()
{
    scanf("%lld", &N);
    scanf("%lld", &K);
    int ans = 1;
    for (int i = 0; i < N; i++) {
        if (ans + K > ans * 2) {
            ans *= 2;
        } else {
            ans += K;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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


int main(){
    ll N; cin >> N;
    vector<pair<ll, ll>> A(N);
    rep(i, N){
        ll a, b; cin >> a >> b;
        A[i].first = min((ll)1e9, a + b );
        A[i].second = max((ll)0, a - b);
    }
    sort(begin(A), end(A));
    ll ans = 0;
    ll end = -1;
    rep(i, N){
        if(end <= A[i].second){
            ans++;
            end = A[i].first;
        }
    }
    cout << ans << endl;

}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second

struct info
{
	ll b, l, u;
};

int main()
{
	#ifdef DGC
		//freopen("a.txt", "r", stdin);
		//freopen("b.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	ll n, x;
	cin >> n >> x;
	vector<info> a(n);
	for (auto &i : a)
		cin >> i.b >> i.l >> i.u;

	sort(a.begin(), a.end(), [&](const info &i, const info &y){ return i.b*i.l + i.u * (x - i.b) > y.b*y.l + y.u * (x - y.b); });

	vector<ll> temp(1);
	for (int i = 0; i < n; ++i)
		temp.push_back(temp.back() + a[i].u * (x - a[i].b));

	vector<ll> temp2(1);
	for (int i = 0; i < n; ++i)
		temp2.push_back(temp2.back() + a[i].l * (-a[i].b));

	temp.erase(temp.begin());
	temp2.erase(temp2.begin());

	auto get = [&](vector<ll> &q, int i, int j)
	{
		j = min((ll)j, n-1);
		i = max(0, i);
		if (i > j) return 0LL;
		if (i == 0) return q[j];
		return q[j] - q[i-1];
	};

	ll l = 0, r = x*n;
	while (l < r)
	{
		ll m = (l+r) >> 1;

		ll k = m;
		ll take = min(n, k/x);
		k -= take * x;

		if (take == n) k = 0;

		ll best = numeric_limits<ll>::min();
		for (int i = 0; i < n; ++i)
		{
			ll cur = 0;
			if (k == 0)
			{
				cur = get(temp, 0, take-1) + get(temp2, take, n-1);
			}
			else if (i <= take)
			{
				cur = get(temp, 0, take) - get(temp, i, i) + max((k - a[i].b)*a[i].l, (k - a[i].b)*a[i].u) + get(temp2, take+1, n-1);
			}
			else
			{
				cur = get(temp, 0, take-1) + max((k - a[i].b)*a[i].l, (k - a[i].b)*a[i].u) + get(temp2, take, n-1) - get(temp2, i, i);
			}

			best = max(best, cur);
		}

		if (best >= 0)
			r = m;
		else
			l = m+1;
	}

	cout << l << "\n";

	return 0;
}


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

// dp[i][500yen][num_1000yen] := remain ([i] is deleted)
int dp[128][512];
int n;
int P[128];

void init() {
  for(int j = 0; j < 128; ++j) {
    for(int k = 0; k < 512; ++k) {
      dp[j][k] = -1;
    }
  }
}

int main() {
  for(;;) {
    init();
    scanf("%d", &n);
    if( n == 0 ) break;
    for(int i = 0; i < n; ++i) {
      scanf("%d", &P[i]);
    }
    int k_max = 0;
    dp[0][0] = 0;
    for(int i = 0; i < n; ++i) {
      k_max += (P[i] + 999) / 1000;
      for(int j = i; j >= 0; --j) {
        for(int k = k_max; k >= 0; --k) {
          if( dp[j][k] == -1 ) continue;
          int n1kyen = (P[i] + 999) / 1000;
          int rem = dp[j][k] + n1kyen * 1000 - P[i];
          int next_num500yen = j + (rem >= 500 ? 1 : 0);
          int next_num1kyen  = k + n1kyen;
          int next_rem       = rem >= 500 ? rem - 500 : rem;
          int& next = dp[next_num500yen][next_num1kyen];
          next = std::max(next, next_rem);
        }
      }
    }    
    int res = (1 << 28);
    int max = -1;
    for(int j = n; j >= 0; --j) {
      for(int k = 0; k < 512; ++k) {
        if( dp[j][k] == -1 ) continue;
        int cost = k * 1000 - 500 * j - dp[j][k];
        res = std::min(res, cost);
      }
      if( res != (1 << 28) ) {
        max = j;
        break;
      }
    }
    printf("%d %d\n", max, res);
  }

  return 0;
}

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


int main(){
    int s;
    int ans=1;
    cin >> s;
    int x=s;
    while(1){
        if(s==1) break;
        else if(s%2==0)s=s/2;
        else s=3*s+1;
        ans++;
    }
    if(x==2) ans+=1;
    if(x==1) ans+=2;
    cout << ans+1 << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

def 解():
    input = sys.stdin.readline
    H,W = [int(_) for _ in input().split()]
    aM = [""]*H
    for i in range(H):
        aM[i] = input().rstrip()

    adxy=[(0,1),(1,0),(-1,0),(0,-1)]
    dsVBs=set()

    def bfsM(i,j):
        aS = [(i,j)]
        dsV = set()
        dsVB = set()
        iC = 0
        while aS:
            th,tw = aS[0]
            del aS[0]
            if aM[th][tw] == ".":
                iC += 1
                for dh,dw in adxy:
                    nh,nw=dh+th,dw+tw
                    nP = (nh,nw)
                    if 0 <= nh < H and 0 <= nw < W:
                        if aM[nh][nw] == "#" and nP not in dsV:
                            aS.append(nP)
                            dsV.add(nP)
                            dsVB.add(nP)
            else:
                for dh,dw in adxy:
                    nh,nw=dh+th,dw+tw
                    nP = (nh,nw)
                    if 0 <= nh < H and 0 <= nw < W:
                        if aM[nh][nw] == "." and nP not in dsV:
                            aS.append(nP)
                            dsV.add(nP)
        iB = len(dsVB)
        for nP in dsVB:
            dsVBs.add(nP)
        return iC*iB

    iAns = 0
    for i in range(H):
        for j in range(W):
            if aM[i][j] == "#" and (i,j) not in dsVBs:
                iAns += bfsM(i,j)
    print(iAns)
解()


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

int n,a[200];

bool Solve(int m, int x, int indx){

  if(x==m)return true;
  if(indx == n)return false;

  if( Solve(m,x,indx+1)==true )return true;
  if( Solve(m,x+a[indx+1],indx+1)==true )return true;

  return false;

}


int main(){

  int m,q;

  cin >> n;
  for(int i=0; i<n; i++)cin >> a[i];

  cin >> q;

  for(int i=0; i<q; i++){

    cin >> m;

    if( Solve(m,a[0],0) || Solve(m,0,0) )cout << "yes"<<endl;
    else cout << "no" << endl;

  }

  return 0;
}

Measured memory_bytes: 1152
import math

def is_prime(n):
  if n == 1: return False

  for k in range(2, int(math.sqrt(n)) + 1):
    if n % k == 0:
      return False

  return True

n = int(input())

for i in range(n, 10000000):
  if (is_prime(i)):
    print(i)
    break

Measured memory_bytes: 38384
input1 = list(map(int,input("").split(" ")))
A = list(map(int,input("").split(" ")))
N = input1[0]
P = input1[1]

even = []
odd = []
for a in A:
	if a % 2 == 0:
		even.append(a)
	else:
		odd.append(a)

if len(odd) == 0:
	if P == 0:
		result = 2**N
	else:
		result = 0
else:
	result = 2**len(even) * 2**(len(odd)-1)

print(result)

Measured memory_bytes: 3064
using System;
using System.Linq;

namespace _2_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if(x[0]<x[1]&& x[1] < x[2])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 9468
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
int main(){
  double d,t,s;
  cin>>d>>t>>s;
  if(ceil(d/s)<=t) cout<<"Yes";
 else cout<<"No";
return 0;
}

Measured memory_bytes: 3716
import math

N=int(input())
zahyo=[input().split() for i in range(N)]

dis=[0]*(int(0.5*(N-1)*N))
k=0
for i in range(0,N-1):
    for j in range(i+1,N):
        dis[k]=math.sqrt((int(zahyo[i][0])-int(zahyo[j][0]))*(int(zahyo[i][0])-int(zahyo[j][0]))+(int(zahyo[i][1])-int(zahyo[j][1]))*(int(zahyo[i][1])-int(zahyo[j][1])))
        k+=1

add=0
ans=0
for i in range(0,int((N*(N-1))/2)):
    add+=dis[i]

ans=add*math.factorial(N-1)*2

print(ans/math.factorial(N))

Measured memory_bytes: 3064