akhauriyash/Code-Regression huggingface dataset:
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  int[] s; readA(n, s);

  auto p = Prime(n.nsqrt);

  auto cl = new long[][](n);
  foreach (i; 1..n) {
    for (auto j = 0; j < n; j += i)
      cl[i] ~= s[j];
    foreach (j; 1..cl[i].length) cl[i][j] += cl[i][j-1];
  }
  

  auto cr = new long[][](n);
  foreach (i; 1..n) {
    for (auto j = n-1; j >= 0; j -= i)
      cr[i] ~= s[j];
    foreach (j; 1..cr[i].length) cr[i][j] += cr[i][j-1];
  }

  auto r = 0L;
  foreach (a; 2..n-1) {
    auto d = p.divisors(n-a-1);
    foreach (di; d) {
      auto b = a-(n-a-1)/di;
      if (b < 0) continue;
      auto c = a-b;

      auto k = (n-a-1)/c;
      if (a%c == 0 && k >= a/c) continue;
      r = max(r, cl[c][k]+cr[c][k]);
    }
  }

  writeln(r);
}

struct Prime
{
  import std.algorithm, std.bitmanip, std.math, std.range, std.typecons;
  alias Factor = Tuple!(int, size_t);

  int n;
  int[] primes;
  alias primes this;

  this(int n)
  {
    this.n = n;

    auto sieve = BitArray();
    sieve.length((n+1)/2);
    sieve = ~sieve;

    foreach (p; 1..((nsqrt(n)-1)/2+1))
      if (sieve[p])
        for (auto q = p*3+1; q < (n+1)/2; q += p*2+1)
          sieve[q] = false;

    primes = sieve.bitsSet.map!(p => cast(int)p*2+1).array;
    primes[0] = 2;
  }

  pure auto div(int x)
  in { assert(x > 0 && nsqrt(x) <= n); }
  body {
    Factor[] factors;
    auto t = nsqrt(x);
    foreach (p; primes) {
      if (p > t) {
        factors ~= Factor(x, 1);
        break;
      }
      auto c = size_t(0);
      for (; x%p == 0; x /= p) ++c;
      if (c > 0) factors ~= Factor(p, c);
      if (x == 1) break;
    }
    return factors;
  }

  pure auto divisors(int x)
  {
    auto factors = div(x);
    auto r = divisorsProc(factors, 0, 1);
    r.sort();
    return r;
  }

  pure int[] divisorsProc(Factor[] factors, size_t i, int c)
  {
    if (i == factors.length) return [c];
    int[] r;
    foreach (j; 0..factors[i][1]+1)
      r ~= divisorsProc(factors, i+1, c*factors[i][0]^^cast(int)j);
    return r;
  }

  pure auto nsqrt(int n)
  {
    if (n <= 1) return n;
    auto m = 1<<(n.ilogb/2+1);
    return cast(int)iota(1, m).map!"a*a".assumeSorted!"a <= b".lowerBound(n).length;
  }
}

pure auto nsqrt(T)(T n)
{
  import std.algorithm, std.conv, std.math, std.range;
  if (n <= 1) return n;
  T m = T(1) << (n.ilogb/2+1);
  return iota(1, m).map!"a*a".assumeSorted!"a <= b".lowerBound(n).length.to!T;
}


Measured memory_bytes: 70148
#include<iostream>
#include<cmath>
#include<vector>
#include<climits>
#include<cstdio>
#include<queue>

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

using namespace std;

#define MAX 100100

typedef long long ll;

struct Edge {
  int s;
  ll w;
};

struct Data {
  int cur;
  ll w;
  bool operator < ( const Data &data ) const {
    if( w != data.w ) return w > data.w;
    return cur < data.cur;
  }
};

int V,E,R,Q;
ll x[MAX],y[MAX],z[MAX];
vector<Edge> G[MAX];
ll mini[20][MAX];

const bool debug = false;

void dijkstra(int mod) {
  rep(i,V+1) mini[mod][i] = LLONG_MAX;
  priority_queue<Data> Q;
  REP(i,1,V+1) if( i % R == mod ) {
    mini[mod][i] = 0;
    Q.push((Data){i,0});
  }
  while( !Q.empty() ) {
    Data data = Q.top(); Q.pop();
    rep(i,(int)G[data.cur].size()) {
      Edge &e = G[data.cur][i];
      if( mini[mod][e.s] > data.w + e.w ) {
	mini[mod][e.s] = data.w + e.w;
	Q.push((Data){e.s,mini[mod][e.s]});
      }
    }
  }
}

void compute() {
  rep(r,R) dijkstra(r);
  if( debug ) {
    rep(r,R) {
      puts("");
      cout << "mod R == " << r << endl;
      REP(i,1,V+1) {
	cout << "mini[" << r << "][" << i << "] = " << mini[r][i] << ", ";
      } puts("");
    }
  }

  ll ans = 0;
  rep(i,Q) {
    ll cost = LLONG_MAX;
    rep(r,R) {
      int Y = r;
      if( mini[r][x[i]] == LLONG_MAX || mini[Y][y[i]] == LLONG_MAX ) continue;
      cost = min(cost,
		 mini[r][x[i]]+mini[Y][y[i]]);
    }
    if( cost == LLONG_MAX ) continue;
    ans += max((ll)z[i]-cost,0LL);
  }
  cout << ans << endl;
}

int main() {
  cin >> V >> E >> R >> Q;
  rep(i,E) {
    int a,b,c;
    cin >> a >> b >> c;
    G[b].push_back((Edge){a,c});
  }
  rep(i,Q) {
    cin >> x[i] >> y[i] >> z[i];
  }
  compute();
  return 0;
}

Measured memory_bytes: 19004
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
class Program
{
    public static long ReadInt()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] ReadInts()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
       
     
        var input = ReadInts();
        var N = input[0];
        var M = input[1];

        var min = N;
        var max = (long)0;
        for(int i = 0; i < M; i++)
        {
            var input0 = ReadInts();
            var L = input0[0];
            var R = input0[1];
            if (max< L)
                max = L;
            if (min > R)
                min = R;
        }
        if (min - max + 1 >= 0)
            Console.WriteLine(min - max + 1);
        else
            Console.WriteLine(0);
        Console.Out.Flush();
    }
}

Measured memory_bytes: 17456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
ll modpow(ll b,ll i){
  ll s=1;
  while(i){
    if(i%2) s=(s*b)%MOD;
    b=(b*b)%MOD; i/=2;
  }
  return s;
}
int main(){
  //clock_t start,end;
  //start=clock();

  int x,y; cin >>x >>y;
  int m=2*y-x,n=2*x-y;
  if(m<0||n<0||m%3||n%3){cout <<0; return 0;}
  else{
    ll p=(m+n)/3,q=min(m,n)/3,pp=1,qq=1;
    for(int i=0; i<q; i++){
      pp=(pp*(p-i))%MOD; qq=(qq*(q-i))%MOD;
    }
    cout <<(pp*modpow(qq,MOD-2))%MOD<<endl;
  }

  //end=clock();
  //double time_taken=double(end-start)/double(CLOCKS_PER_SEC); 
  //cout <<"Time taken: "<<fixed<<setprecision(5);
  //cout <<time_taken<<"s/"<<time_taken*1000<<"ms"<<endl;
return 0;}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m, v[101];
    cin >> n >> m;
    int cnt = 0;
    int sum = 0;
    for (int i = 1; i <= n; i ++)
    {
        cin >> v[i];
        sum += v[i];
    }
    int prod = 4 * m;
    for (int i = 1; i <= n; i ++)
    {
        if (v[i] * prod >= sum)
            ++ cnt;
    }
    cout << (cnt >= m ? "Yes" : "No");
    
}


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

int n, A[2000100], B[2000100];

void countingSort() {
    int cnt[10010] = {};
    for (int i = 0; i < n; i++) cnt[A[i]]++;
    for (int i = 1; i <= 10000; i++) cnt[i] += cnt[i - 1];
    for (int i = n - 1; i >= 0; i--) {
        B[cnt[A[i]] - 1] = A[i];
        cnt[A[i]]--;
    }
    return;
}

void print() {
    for (int i = 0; i < n; i++) {
        if (i) cout << " ";
        cout << B[i];
    }
    cout << endl;
    return;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> A[i];
    countingSort();
    print();
    return 0;
}


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

const int MOD=1e9+7;

int main(){
    string l; cin >> l;
    int N=l.size();
    long long dp[N+1][2]={};
    dp[0][0]=1;
    for(int i=0;i<N;i++){
        dp[i+1][1]+=dp[i][1]*3%MOD;
        if(l[i]=='1'){
            dp[i+1][0]+=2*dp[i][0]%MOD;
            dp[i+1][1]+=dp[i][0]%MOD;
        }else{
            dp[i+1][0]+=dp[i][0]%MOD;
        }
    }
    long long ans=(dp[N][0]+dp[N][1])%MOD;
    cout << ans << endl;
}

Measured memory_bytes: 2048
#include<stdio.h>
#include<stdlib.h>
#define N 500001
void maxHeap(int);
void buildMaxHeap(void);
void swap(int *, int *);
int n, heap[N];
int main() {
  int i, j;
  
  scanf("%d", &n);
  
  for (i = 1; i <= n; i++) scanf("%d", &heap[i]);
  
  buildMaxHeap();
  
  for (i = 1; i <= n; i++) printf(" %d",heap[i]);
  printf("\n");

  return 0;
}
void maxHeap(int u) {
  int left = 2 * u;
  int right = left + 1;
  int max;
  
  if (left <= n && heap[u] < heap[left]) max = left;
  else max = u;
  if (right <= n && heap[max] < heap[right]) max = right;
  
  if (u != max) {
    swap(&heap[u], &heap[max]);
    maxHeap(max);
  }
}
void buildMaxHeap(void) {
  int i;
  for (i = n; i > 0; i--) maxHeap(i);
}
void swap(int *x, int *y) {
  int tmp = *x;
  *x = *y;
  *y = tmp;
}

Measured memory_bytes: 2980
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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; }

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  long double d, t, s;
  cin >> d >> t >> s;
  if(t*s >= d) cout << "Yes" << endl;
  else cout << "No" <<endl;
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  string s;
  cin>>s;
  int n=s.size(),ans=0;
  for(int i=0;i<=n;i++)
  {
    for(int j=0;j<n;j++)
    {
      if(j+i<n)
      {
        int cnt=0;
        for(int k=j;k<=(j+i);k++) if(s[k]=='A' || s[k]=='G' || s[k]=='T' || s[k]=='C') cnt++;
        if(cnt==(i+1)) ans=max(ans,cnt);
        // cout<<j<<" "<<cnt<<" "<<i<<endl;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

int n;
int p, maxp, sum;

int main()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
    {
        cin >> p;
        maxp = max(maxp, p);
        sum += p;
    }
    cout << sum-maxp/2 << endl;
    return 0;
}


Measured memory_bytes: 256
/*
 * A.cpp
 *
 *  Created on: 2020/08/02
 *      Author: 17k1028
 */



#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=a; i>=ll(b); i--)

int main(){
	ll X;
	cin >> X;
	if(30<=X){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}





Measured memory_bytes: 3600
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
x=i2()
k=i1()
import heapq
z=[-i for i in x]
heapq.heapify(z)
for i in range(k):
 y=heapq.heappop(z)
 heapq.heappush(z,2*y)
print(-sum(z))

Measured memory_bytes: 38384
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

template <typename T>
constexpr bool chmin(
    T a, T b, function<bool(T, T)> f = [](T a, T b) { return a > b; }) {
  // when f is true, b is more 'smaller'
  if (f(a, b)) {
    swap(a, b);
    return true;
  }
  return false;
}
template <typename T> constexpr bool chmax(T a, T b) {
  return chmin(a, b, [](T a, T b) { return a < b; });
}
template <typename ite> void print_ite(ite start, ite end, char c = ' ') {
  for (auto i = start; i != end; i++)
    cout << i << c;
  cout << endl;
}
template <typename ite> void scan_ite(ite start, ite end) {
  for (auto i = start; i != end; i++)
    cin >> (*i);
}
inline void Yes(bool condition) { cout << (condition ? "Yes\n" : "No\n"); }

int main() {
  double long n, m;
  cin >> n >> m;
  vector<ll> a(n);
  double long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  double long bord = sum / 4 / m;
 // cout << bord << endl;
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] >= bord)
      count++;
  }
  //cout << count << endl;
  Yes(count >= m);
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		System.out.println(a + b + c - Math.max(Math.max(a, b), c));
	}
}


Measured memory_bytes: 23636
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    int k;
    string s;
    cin >> k >> s;
    if(s.size() <= k) {
        cout << s << endl;
    } else {
        string s2 = s.substr(0, k);
        cout << s2 << "..." << endl;
    }
}

Measured memory_bytes: 3620
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner s=new Scanner(System.in);
    int n,l,r,res=0;
    
    l=s.nextInt();
    r=s.nextInt();
    n=s.nextInt();
    for(int i=l;i<=r;i++)
    {
      if(i%n==0)
      {
        res++;
      }
    }
    System.out.println(res);
  }
}
      
      

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

#define i64 long long int

int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	
	if(min(a, b)==1) {
		puts("1");
		return 0;
	}
	
	i64 ans = a;
	ans *= b;
	printf("%lld\n", (ans+1)/2);
	
	return 0;
}

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

using namespace std;
#define BUF (1000)
#define ll long long 

#define INF INT_MAX
#define MAX_KEY 1005
#define MAX_STATE (1<<12)
int n,m;
int states[MAX_KEY];
int costs[MAX_KEY];

int total_costs[MAX_KEY][MAX_STATE];

int main(void){
	cin >> n >> m;
	for(int i=0;i<m;i++){
		int num;
		cin >> costs[i] >> num;
		for(int j=0;j<num;j++){
			int box;
			cin >> box;
			states[i] |= 1<<(box-1);
		}
		//cout << costs[i] << " " <<  states[i] << endl;
	}

	//initialize 
	for(int j=0;j<(1<<n);j++)total_costs[0][j] = INF;
	total_costs[0][0] = 0; //never chose 0
	total_costs[0][states[0]] = costs[0]; //chose 0

	for(int i=1;i<m;i++){
		// never chose i th key
		for(int j=0;j< 1<<n;j++){
			total_costs[i][j] = total_costs[i-1][j];
			//cout << total_costs[i][j] << " ";
		} 
		cout << endl;

		// user i th key
		for(int j=0;j< 1<<n;j++){
			int state = states[i]|j;
			if(total_costs[i-1][j] != INF){
				total_costs[i][state] = min(total_costs[i][state], total_costs[i-1][j]+costs[i]);
			} 
		} 
	}

	if(total_costs[m-1][ (1<<n) -1] == INF) cout << -1 << endl; 
	else cout << total_costs[m-1][(1<<n)-1] << endl;
	return 0;
}


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

using namespace std;

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

#define int ll

const int N = 110;

int k, dp[N];

int solve(string s){
	int n = s.size();
	for(int i=0 ; i<n ; i++){
		int cur = 1e9;
		for(int j=i-1 ; j>0 ; j--){
			if(s[j] == s[j-1]){
				cur = min(cur, dp[j]);
				cur = min(cur, dp[j-1]);
				break;
			}
		}
		if(cur>n)
			cur = 0;
		dp[i] = 1 + cur;
	}
	int ret=0, all=0;
	for(int i=n-1 ; i>0 ; i--)
		if(s[i] == s[i-1]){
			all = min(dp[i-1], dp[i]);
			break;
		}
	if(s[0] != s[n-1])
		return all*k;
	return dp[n-1]*(k-1) + all;
}

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	string s;cin >> s;
	cin >> k;
	bool f = true;
	for(auto c : s)
		f &= (c == s[0]);
	if(f){
		cout << k*s.size()/2 << "\n";
		return 0;
	}
	string t = s;
	reverse(t.begin(), t.end());
	cout << min(solve(s), solve(t)) << "\n";
}

























Measured memory_bytes: 256
//Atcoder M-SOLUTIONS Programming Contest 2020
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 2e6 + 5;
const double E = 1e-9;

//------------------------------------------------------------------------------

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*ifstream cin("input.txt");
    ofstream cout("output.txt");*/
    int x;
    cin >> x;
    if (x <= 599)
        cout << 8;
    else if (x >= 600 && x <= 799)
        cout << 7;
    else if (x >= 800 && x <= 999)
        cout << 6;
    else if (x >= 1000 && x <= 1199)
        cout << 5;
    else if (x >= 1200 && x <= 1399)
        cout << 4;
    else if (x >= 1400 && x <= 1599)
        cout << 3;
    else if (x >= 1600 && x <= 1799)
        cout << 2;
    else
        cout << 1;
    return 0;
}
//Date:###### Sat Jul 25 17:34:10 IST 2020
//------------------------------------------------------------------------------

Measured memory_bytes: 3644
#include <algorithm>
#include <cassert>
#include <vector>

namespace atcoder {

// Implement (union by size) + (path compression)
// Reference:
// Zvi Galil and Giuseppe F. Italiano,
// Data structures and algorithms for disjoint set union problems
struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};

}  // namespace atcoder

#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
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; }
const ll INF = 1e18;


int main(){
    //input
    ll n,q;
    cin >> n >> q;
    dsu d(n);
    rep(i,q){
        ll t,u,v;
        cin >> t >> u >> v;
        if(t==0){
            d.merge(u,v);
        }
        else{
            if(d.same(u,v))cout<<1<<endl;
            else cout << 0 << endl;
        }
    }

    
    return 0;
}


Measured memory_bytes: 3912
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n<=1000)
    {
        cout<<1000-n;
    }
    else if(n>1000 && n<=2000)
        cout<<2000-n;
     else if(n>2000 && n<=3000)
        cout<<3000-n;
         else if(n>3000 && n<=4000)
        cout<<4000-n;
         else if(n>4000 && n<=5000)
        cout<<5000-n;
         else if(n>5000 && n<=6000)
        cout<<6000-n;
         else if(n>6000 && n<=7000)
        cout<<7000-n;
         else if(n>7000 && n<=8000)
        cout<<8000-n;
         else if(n>8000 && n<=9000)
        cout<<9000-n;
         else if(n>9000 && n<=10000)
        cout<<10000-n;
}


Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

/**
 * 0007:Debt Hellの解答
 * 
 * @author MS14A
 * @version 2015/04/15
 */
public class Main {

    /** 初期借金額：10万円 */
    private static final BigDecimal INITIAL_DEBT = new BigDecimal("100000");

    /** 利子：5% */
    private static final BigDecimal INTEREST_RATE = BigDecimal.valueOf(0.05);

    /** \1000未満の繰り上げ計算用 */
    private static final BigDecimal DIVISOR_FOR_ROUND_UP = BigDecimal.valueOf(1000);

    /**
     * n 週間後の借金の残高を出力する。<br>
     * ※n は 100 以下とする。
     * 
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        // 標準入力読み取り
        int weeks = getWeeks();

        // n週間後の借金額計算
        System.out.println(calcDebt(weeks));
    }

    /**
     * 標準入力を読み取り、"n"の値を返す。
     * 
     * @return n：入力値
     * @throws IOException 
     */
    private static int getWeeks() throws IOException {
        
        InputStreamReader streamReader = new InputStreamReader(System.in);
        BufferedReader bufferedReader = new BufferedReader(streamReader);
        
        int n = Integer.parseInt(bufferedReader.readLine());
        
/*        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();*/
        
        return n;
    }

    /**
     * n週間後の借金額を計算する。
     * 
     * @param weeks
     */
    private static BigDecimal calcDebt(int weeks) {
        BigDecimal finalDebt = INITIAL_DEBT;

        for (int i = 0; i < weeks; i++) {
            // 利子額計算。1000で割った小数部を繰り上げる。
            BigDecimal interestAmount = finalDebt.multiply(INTEREST_RATE)
                    .divide(DIVISOR_FOR_ROUND_UP, 0, BigDecimal.ROUND_UP);

            // 借金額 = 前週の借金額 + 利子額
            finalDebt = finalDebt.add(interestAmount.multiply(DIVISOR_FOR_ROUND_UP));
        }

        return finalDebt;
    }

}

Measured memory_bytes: 16980
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>

typedef long long ll;
#define fi first
#define se second

int a[55];
int b[55];
int c[55];
int d[55];


using namespace std;

int main(){
  
  int N, M; 
  int i;
  int j;
  int x, y;
  int num;
  int sum;
  int ans;
  
  
  cin>>N>>M;
  
  for( i = 0; i < N; i++ ){
    scanf("%d %d", a+i, b+i);
  }
  
  for( i = 0; i < M; i++ ){
    scanf("%d %d", c+i, d+i);
  }
  
  for( i = 0; i < N; i++ ){
    num = 1123456789;
    for( j = 0; j < M; j++ ){
      x = a[i] - c[j];
      y = b[i] - d[j];
      if( x < 0 ) x *= -1;
      if( y < 0 ) y *= -1;
      sum = x + y;
      if( num > sum ){
        num = sum;
        ans = j;
      }
    }
    
    printf("%d\n", ans+1);
  }
  
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define dl double
#define mp make_pair
#define pb push_back
using namespace std;

//***********************************************************************

// hash struct for unordered_map
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

void solve()
{
    int a,b;
    cin >>a >> b;
    cout << a*b << endl;
}


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

	return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define pb push_back
#define fi first
#define se second

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

const int mod = 998244353;
int add(int x, int y) {x += y; if(x >= mod) return x - mod; return x;}
int sub(int x, int y) {x -= y; if(x < 0) return x + mod; return x;}
int mul(int x, int y) {return (ll) x * y % mod;}

int ones, tones, doubles, tdoubles;

map<char, int> m = {{'R', 1}, {'G', 2}, {'B', 3}};

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

  int n; cin >> n;
  int sol = 1, cnt = n;

  REP(i, 3 * n) {
    char c; cin >> c;
    int x = m[c];

    if(tdoubles && doubles == x) {
      sol = mul(sol, tdoubles);
      tdoubles --;
    }
    else if(tones && ones != x) {
      sol = mul(sol, tones);
      tones --;
      tdoubles ++;
      if(tdoubles == 1) doubles = 6 - x - ones;
    }
    else {
      sol = mul(sol, cnt);
      cnt --;
      ones = x;
      tones ++;
    }
  }

  cout << sol << endl;
}


Measured memory_bytes: 256
#include <iostream>

int n;

int cand[9] = {111, 222, 333, 444, 555, 666, 777, 888, 999};

void solve() {
    for (int i=0; i<9; i++) {
        if (cand[i] >= n) {
            std::cout << cand[i] << std::endl;
            break;
        }
    }
}
int main() {
    std::cin >> n;

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);
#define int long long
signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int q,h,s,d,n;
	cin>>q>>h>>s>>d>>n;
	int min1 = min3(q*4,h*2,s);
	int min2 = min3(q*8,h*4,min(s*2,d));
	cout<<((n/2)*min2)+((n%2)*min1)<<endl;	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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 ctoi(char c){return ('0' <= c && c <= '9')?(c - '0'):-1;}


// TODO: write
int main() {
  int n,a,b;cin>>n>>a>>b;
  
  int m   = n - 2;
  int dif = b - a;
  if(n == 1 && dif == 0){
    print(1);
    return 0;
  }
  if(m < 0 || dif < 0){
    print(0);
    return 0;
  }
  
  ull ans = ((ull)m * dif) + 1;
  print(ans);

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int x,a;
	cin>>x>>a;
	if(x<a){
		cout<<0;
	}else{
		cout<<10;
	}







	
	
return 0;	
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
using namespace std;
const int INF = 1000000;
// memo 
int dp[INF + 1];


int f(int n) {
    int result;
    if (n % 2 == 0) result = n / 2;
    else result = 3 * n + 1;
    return result;
}
int a(int n, int s) {
    if (dp[n] != -1) return dp[n];
    if (n == 1) { dp[1] = s; return s;}
    else {
        dp[n] = f(a(n - 1, s));
        return dp[n];
    }
}

int main(void) {
    int s;cin>>s;
    for (int i = 0 ; i < INF + 1; i++) dp[i] = -1;
    set<int> se;
    int result;
    for (int i = 1; i <= INF; i++) {
        int r = a(i, s);
        if (se.find(r) != se.end()) {
            result = i;
            break;
        }
        se.insert(r);
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 4224
<?php
  $n = trim(fgets(STDIN));
  $a = explode(" ", trim(fgets(STDIN)));
  $ans = 0;
  for($i = 0; $i < $n; $i = $i+2){
    if($a[$i] % 2 != 0){
      $ans++;
    }
  }
  echo $ans;
?>

Measured memory_bytes: 16044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<18,INF=1<<30;

int main(){
    
    string ans;
    cout<<"? 49999999999"<<endl;
    char a;cin>>a;
    if(a=='Y'){
        for(int i=1;i<=4;i++){
            cout<<"? "<<i<<"9999999999"<<endl;
            cin>>a;
            if(a=='Y'){
                ans+='0'+i;
                break;
            }
        }
    }else{
        for(int i=5;i<=9;i++){
            cout<<"? "<<i<<"9999999999"<<endl;
            cin>>a;
            if(a=='Y'){
                ans+='0'+i;
                break;
            }
        }
    }
    bool ok=true;
    
    while(ans.size()<=8){
        cout<<"? "<<ans<<'4';
        for(int j=0;j<13-ans.size();j++){
            cout<<9;
        }
        cout<<endl;
        cin>>a;
        if(a=='Y'){
            for(int i=0;i<=4;i++){
                cout<<"? "<<ans<<i;
                for(int j=0;j<13-ans.size();j++){
                    cout<<9;
                }
                cout<<endl;
                cin>>a;
                if(a=='Y'){
                    if(i==0){
                        if(ans=="9"){
                            cout<<"? "<<10<<endl;
                            cin>>a;
                            if(a=='N'){
                                ok=false;
                                break;
                            }else{
                                ans+='0';
                                break;
                            }
                        }else{
                            string T=ans;
                            T[T.size()-1]++;
                            cout<<"? "<<T<<endl;
                            cin>>a;
                            if(a=='Y'){
                                ok=false;
                                break;
                            }else{
                                ans+='0';
                                break;
                            }
                        }
                    }else{
                        ans+='0'+i;
                        break;
                    }
                }
            }
            if(!ok) break;
        }else{
            for(int i=5;i<=9;i++){
                cout<<"? "<<ans<<i;
                for(int j=0;j<13-ans.size();j++){
                    cout<<9;
                }
                cout<<endl;
                cin>>a;
                if(a=='Y'){
                    ans+='0'+i;
                    break;
                }
            }
        }
    }
    
    if(ans=="100000000"){
        cout<<"? "<<100000001<<endl;
        cin>>a;
        if(a=='N') ans+='0';
    }
    
    cout<<"! "<<ans<<endl;
}




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

int check(int a, int b, int c){
    if( a < b && b < c){
        return 1;
    }else if(a > b && b > c){
        return 1;
    }else{
        return 0;
    }
}

int main(){
    int n;
    cin >> n;
    int p[n];
    int ans = 0;
    rep(i,n) cin >> p[i];
    rep(i,n-2) ans+=check(p[i],p[i+1],p[i+2]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
h, w = gets.split.map(&:to_i)
cells = h.times.map{|h_i|
    line = gets.split.map(&:to_i).map{|it| it % 2 == 0}.each_with_index.map{|is_even, w_i| [[h_i + 1, w_i + 1], is_even] }
    if h_i % 2 == 0
        line
    else
        line.reverse()
    end
}.flatten(1)

carrying = false
opes = []
cells.drop(1).zip(cells).each{|it|
    current_coord = it[1][0]
    next_coord = it[0][0]
    is_even = it[1][1]
    carrying = carrying ^ !is_even
    if carrying
        opes.push [current_coord, next_coord].join(" ")
    end
}

puts opes.count
opes.each{|it|
    puts it
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")


int main()
{
	string S;
	cin >> S;
	if (S[2]==S[3]&&S[5]==S[4]) {
		cey;
	}
	else {
		cen;
	}

    return 0;
}



Measured memory_bytes: 764
#include<bits/stdc++.h> 
using namespace std; 
int main(){
long long 	int n;
	cin>>n;
long long 	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
long long 	int res=1000;
	for(int i=0;i<n-1;i++){
		if(a[i]<a[i+1]){
	long long 		int ret=a[i+1]-a[i];
		long long 	int rett=res/a[i];
			res=res+ret*rett;
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h> 
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (998244353)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
						For(j,m-1) cout<<a[i][j]<<' ';\
						cout<<a[i][m]<<endl; \
						} 
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
	while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
	return x*f;
} 
#define MAXN (312345)
ll inj[MAXN],jie[MAXN];
ll C(ll a,ll b) {
	return jie[a]*inj[b]%F*inj[a-b]%F;
}
int main()
{
//	freopen("B.in","r",stdin);
//	freopen(".out","w",stdout);
	ll n,a,b,k,ans=0;
	cin>>n>>a>>b>>k;
	jie[0]=1;For(i,n) jie[i]=mul(jie[i-1],i);
	inj[0]=inj[1]=1;Fork(i,2,n) inj[i]=(F-(F/i))*inj[F%i]%F;
	For(i,n) inj[i]=mul(inj[i],inj[i-1]);  
	for(int i=0;i<=n;i++) {
		ll t=k-a*i;
		if(t<0 || t%b!=0) continue;
		if(t/b>n) continue;
		ans+=C(n,i)*C(n,t/b)%F;ans%=F;
	}cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
 
using namespace std;
 
#define eb emplace_back
#define pb push_back
#define MP make_pair
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define rep(i,j,n) for (int i = j; i < n; ++i)
#define repn(i,j,n) for (int i = j; i <= n; ++i)
#define revn(i,j,n) for (int i = j; i >= n; --i)
#define sz(i) i.size()
#define mem(i,v) memset(i,v,sizeof(i))
#define all(v) v.begin(), v.end()
#define endl '\n'
#define int long long
#define INF 1e18
#define ss second
#define ff first

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
const int mod=1e9+7;
//const int mod=998244353;
const int up=1e5+10;
const int MAXN=1e5+10;
int par[up];

int find(int x)
{
    if(par[x]==x)
        return x;
    else
        return par[x]=par[find(par[x])];
}

// int merge(int u,int v)
// {
//     int x=find(u);
//     int y=find(v);
//     if(x!=y)
//     {
//         if(size[x]<=size[y])
//         {
//             par[x]=y;
//         }
//     }
// }
const int chk=1e18;
int n,k,a[up];
int s[up];

void solve()
{
    int a;
    string s;
    cin>>a;
    cin>>s;
    int i=s[0]-'0';
    int d=(s[2]-'0')*10+s[3]-'0';
    cout<<a*i+(int)(a*d/100)<<endl;
}

int32_t main()
{
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}



Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>

#define IF 1300500010
#define lengthof(x) (sizeof(x) / sizeof(*(x)))

using namespace std;

int main(int argc, char const *argv[])
{
	int n,m;
	long long dp[1<<8][2];
	long long min_;

	while(1){
		cin>>n>>m;
		if(n+m==0) break;

		vector<long long> cb(m);
		vector<long long> x(n);
		for(int i1=0;i1<m;i1++){
			cin>>cb[i1];
		}

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

		fill((long long*)dp,(long long *)(dp+lengthof(dp)),IF);

		dp[128][0]=0;
		for(int i1=0;i1<n;i1++){
			for(int i2=0;i2<(1<<8);i2++){
				if(dp[i2][i1%2]!=IF){

					for(int i3=0;i3<m;i3++){
						int temp=i2+cb[i3];
						if(temp<0) temp=0;
						if(temp>255) temp=255;
						dp[temp][(i1+1)%2]=min(dp[temp][(i1+1)%2],dp[i2][i1%2]+(temp-x[i1])*(temp-x[i1]));
					}
					dp[i2][i1%2]=IF;
				}

			}
		}

		min_=IF;
		for(int i1=0;i1<(1<<8);i1++){
			min_=min(min_,dp[i1][n%2]);
		}

		cout<<min_<<endl;
	}
	return 0;
}

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

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

unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
 
unsigned binarySearch(ll target, ll max, ll min) {
  while((max - min) > 1) {
      if((max + min)/2 > target) {
        max = (max + min)/2;
        min = min;
      } else {
        max = max;
        min = (max + min)/2;
      }
    }
}

//v検査対象
//vp全ての発言
bool valid(vector<ll> v, vector<pair<ll, pair<ll, ll>>> vp) {
  REP(i, vp.size()){
    // 発言者が正直　
    if(v.at(vp.at(i).first) == 1) {
      // 発言内容と実際の値が異なる場合は不適
      if(v.at(vp.at(i).second.first - 1) != vp.at(i).second.second) return false;
    /*
    } else {
      if(v.at(vp.at(i).second.first - 1) == vp.at(i).second.second) return false;
    */
    }
  }
  return true;
}
 
int main() {
  ll n;
  cin >> n;
  
  vector<pair<ll, pair<ll, ll>>> vp;
  // 全員の発言が成立するbitを取得しそのbitの正直者の数を数える
  REP(m, n) { //全ての集合
    ll r;
    cin >> r;
    REP(l, r) {
      ll p,q;
      cin >> p >> q;
      vp.push_back( make_pair(m, make_pair(p, q)) );
    }
  }
  
  ll maxC = 0;
  
  REP(i, (1<<n)) {
    vector<ll> v(15, 0);
    ll tmp = 0;
    REP(l, n) {
      if (i & (1 << l)) {
        v.at(l) = 1;
        tmp++;
      }
    }
    //cout << "{" << v.at(0) << ", " << v.at(1) << ", " << v.at(2) << "}" << endl;

    if (valid(v, vp)) {
      maxC = max(maxC, tmp);
    }
  }
  cout << maxC << endl;
  
}

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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000001
#define INFL (1LL << 60)
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if(k%2 == 0) cout << a-b << endl;
  else cout << b-a << endl;
  return 0;
}


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

#define pb push_back
#define eb emplace_back

using namespace std;

using vi = vector<int>;
using ll = long long;

int main(){
    ios :: sync_with_stdio(false);
    string s;
    cin >> s;
    string a = s.substr(0, 2);
    int a1 = stoi (a);
    string b = s.substr(2, 3);
    int b1= stoi(b);
    bool a2=false, b2=false;

    cerr << a1 << " " << b1 << endl;

    if(a1>0 and a1<=12) a2=true;
    if(b1>0 and b1<=12) b2=true;

    if(a2 and b2) cout << "AMBIGUOUS\n";
    else if(a2) cout << "MMYY\n";
    else if(b2) cout << "YYMM\n";
    else cout << "NA\n";


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static final int NUM_INPUT = 3;

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] str = new String[3];

		for (int i = 0; i < NUM_INPUT; i++) {
			str[i] = scanner.next();
		}

		int max = 0;
		for (int i = 0; i < NUM_INPUT; i++) {
			for (int j = 0; j < NUM_INPUT; j++) {
				if (i == j) {
					continue;
				}
				int index = 0;
				for (int k = 0; k < NUM_INPUT; k++) {
					if (i == k || j == k) {
						continue;
					}
					index = k;
				}
				int num = Integer.parseInt(str[i] + str[j]) + Integer.parseInt(str[index]);
				if (num > max) {
					max = num;
				}
			}
		}

		System.out.println(max);

	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int n,m,i,ans=INT_MAX,a[100002];
int main()
{
  cin>>n>>m;
  for(i=1;i<=n;i++)cin>>a[i];
  sort(a+1,a+n+1);
  for(i=1;i<=n-m+1;i++)
    ans=min(ans,a[i+m-1]-a[i]);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
n,k=map(int,input().split())

now = 0
a=list(map(int,input().split()))

s = []
od = [-1]*(n+1)
c=1
l=0

v=1

while od[v] == -1:
  od[v] = len(s)
  s.append(v)
  v = a[v-1]

c=len(s)-od[v]
l=od[v]

if k<l:
  print(s[k])
else:
  k-=l
  k%=c
  print(s[l+k])

Measured memory_bytes: 32352
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

namespace Solver {

    int N, M;
    vector<pair<int, int>> DP;
    inline bool Read() {
        cin >> N >> M;
        if (N == 0) return false;
        DP.resize(N, make_pair<int, int>(0, 0));
        for (int i = 0; i < N; i++) cin >> DP[i].second >> DP[i].first;

        return true;
    }

    inline void Work() {
        sort(DP.rbegin(), DP.rend());
        int P = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < DP[i].second; j++) {
                if (M == 0) {
                    P += DP[i].first;
                } else {
                    M--;
                }
            }
        }
        cout << P << endl;
    }

    inline void Solve() {
        while(Read()) Work();
    }
}

int main() {
    Solver::Solve();
}

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

int main() {
  int N;
  cin >> N;
  vector<long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (!A.at(i)) return cout << 0 << "\n", 0;
  }
  long ans = 1;
  for (int i = 0; i < N; i++) {
    if ((long double) ans * A.at(i) > 1e18) return cout << -1 << "\n", 0;
    ans *= A.at(i);
  }
  cout << ans << "\n";
}


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

int main(){
int a;scanf("%d",&a);
int L=a/100;
int R=a%100;
if(1<=L&&L<=12){
if(1<=R&&R<=12)printf("AMBIGUOUS\n");
else printf("MMYY\n");
}else{
if(1<=R&&R<=12)printf("YYMM\n");
else printf("NA\n");
}
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    auto K = nk[1];
    auto PS = readln.split.to!(int[]).map!"a-1"().array();
    auto CS = readln.split.to!(long[]);

    long max_c = long.min;
    foreach (i; 0..N) {
        auto hs = new int[](N);
        auto cs = new long[](N+2);
        int p = PS[i];
        long c = CS[p];
        max_c = max(max_c, c);
        hs[p] = 1;
        cs[1] = c;
        foreach (j; 2..K+1) {
            p = PS[p];
            c += CS[p];
            cs[j] = c;
            max_c = max(max_c, c);
            if (hs[p] != 0) {
                long n = j - hs[p];
                long d = c - cs[hs[p]];
                if (d < 0) goto end;
                long l = (K-hs[p]) / n;
                long r = (K-hs[p]) % n;
                c = cs[hs[p]] + d * l;
                max_c = max(max_c, c);
                foreach (_; 0..r) {
                    p = PS[p];
                    c += CS[p];
                    max_c = max(max_c, c);
                }
                goto end;
            }
            hs[p] = j;
        }
        end:
    }
    writeln(max_c);
}

Measured memory_bytes: 6868
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
 
# 入力
#A, B, X = map(int, input().split())
N = int(input())
V = []
for _ in range(N) :
  S = str(input())
  V.append(list(map(int, S.split())))

#print (V)

#N日目にA,B,C,それぞれを選んだときの最大の幸福度
dp = [[0 for _ in range(3)] for _ in range(N+1)]

for i in range(N) :
  if i == 0 :
      dp[i][0] = V[i][0]
      dp[i][1] = V[i][1]
      dp[i][2] = V[i][2]
  else :
      dp[i][0] = V[i][0] + max(dp[i-1][1], dp[i-1][2])
      dp[i][1] = V[i][1] + max(dp[i-1][0], dp[i-1][2])
      dp[i][2] = V[i][2] + max(dp[i-1][0], dp[i-1][1])


#print (dp)
print (max(dp[N-1][0], dp[N-1][1], dp[N-1][2]))



Measured memory_bytes: 76376
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main()
{
  int N;
  cin >> N;
  int a = 0, b = 0, c = 0;
  FOR(i,0,N) {
    ll in;
    cin >> in;
    if(in % 4 == 0) a++;
    else if(in % 2 == 0) b++;
    else c++;
  }
  if(b > 0) c++;
  if(c - 1 <= a || c == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<double> v(N);
  for (int i = 0; i < N; i++)
  {
      cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  
  double S = 0;
  for (int i = 0; i < N-1; i++)
  {
      int z = std::pow(2, i+1);
      S += v.at(i)/z;
  }
  int z = std::pow(2, N-1);
  S += v.at(N-1)/z;
  cout << S << endl;
  }

Measured memory_bytes: 384