akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n"
#define DEBUG3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define ld long double
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  int even = 0;
  int odd = 0;
  REP(i, N) {
    int p;
    cin >> p;
    if (p % 2 == 0) {
      even++;
    } else {
      odd++;
    }
  }
  even += odd / 2;
  odd %= 2;
  if (odd == 1 && even > 0)
    print("NO");
  else
    print("YES");
}

Measured memory_bytes: 256
import java.util.*

fun main(args:Array<String>?): Unit {
    val (n, m, e, s, t, r) = readLine()!!.trim().split(' ').map(String::toInt)
    val nodes = Array(n){Stack<Int>()}
    repeat(m){
        val (a, b) = readLine()!!.trim().split(' ').map(String::toInt)
        nodes[a].push(b)
        nodes[b].push(a)
    }
    val events = Array(e){
        val (a, b, c) = readLine()!!.trim().split(' ').map(String::toInt)
        Event(a, b, c)
    }
    val minStep = Array(1 shl e){Array(r + 1){BooleanArray(n){false}}}
    val queue: Queue<Pair<State, Int>> = LinkedList<Pair<State, Int>>()
    val start = State(s, (0 until e).find{events[it].c == s})
    queue.add(Pair(start, 0))
    minStep[start] = true
    while(queue.isNotEmpty() && queue.peek().first.position != t){
        val (state, step) = queue.poll()
        if (state.day != r) {
            for (to in nodes[state.position]) {
                val next = (0 until e).find{events[it].c == to}?.let{state.moveWithEvent(to, it)} ?: state.move(to)
                if (!minStep[next]){
                    minStep[next] = true
                    queue.add(Pair(next, step + 1))
                }
            }
            for (i in events.indices) if (state.isEventHappened(i) && (events[i].a == state.position || events[i].b == state.position)) {
                val to = if (events[i].a == state.position) events[i].b else events[i].a
                val next = (0 until e).find{events[it].c == to}?.let{state.moveWithEvent(to, it)} ?: state.move(to)
                if (!minStep[next]){
                    minStep[next] = true
                    queue.add(Pair(next, step + 1))
                }
            }
        }
        val next = state.ocarina(s)
        if (!minStep[next]){
            minStep[next] = true
            queue.add(Pair(next, step + 1))
        }
    }
    println(if (queue.isEmpty()) -1 else queue.peek().second)
}
operator fun Array<Array<BooleanArray>>.get(state: State): Boolean = this[state.events][state.day][state.position]
operator fun Array<Array<BooleanArray>>.set(state: State, value: Boolean): Unit {
    this[state.events][state.day][state.position] = value
}
operator fun List<Int>.component6(): Int = this[5]
data class Event(val a: Int, val b: Int, val c: Int)
class State private constructor(val events: Int, val day: Int, val position: Int) {
    fun move(destination: Int): State = State(events, day + 1, destination)
    fun moveWithEvent(destination: Int, event: Int): State = State(events or (1 shl event), day + 1, destination)
    fun ocarina(start: Int): State = State(events, 0, start)
    fun isEventHappened(event: Int): Boolean = (events and (1 shl event)) != 0
    constructor(start: Int):this(start, null)
    constructor(start: Int, event: Int?): this(event?.let{1 shl it} ?: 0, 0, start)
}


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

int main(int argc, char const *argv[]) {
  int D, G, min;
  cin >> D >> G;
  vector<int> p(D + 1);
  vector<int> c(D + 1);
  min = 0;

  for (int i = 1; i < D + 1; i++) {
    cin >> p[i] >> c[i];
    min += p[i];
  }

  for (int bit = 0; bit < 1 << D; bit++) {
    int score = 0;
    int count = 0;

    //点数が高い方から取っていく
    for (int i = D - 1; i >= 0; i--) {
      // i+1桁目を使うか否か
      if (bit & (1 << i)) {
        for (int j = 1; j <= p[i + 1]; j++) {
          score += 100 * (i + 1);
          count++;
          if (j == p[i + 1]) {
            score += c[i + 1];
          }
          if (score >= G && count < min) {
            min = count;
          }
        }
      }
    }
  }

  cout << min << "\n";
  return 0;
}


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

int main() {
  int n, t; cin >> n >> t;
  int minc = 10000;
  for (int i = 0; i < n; i++) {
    int c, time; cin >> c >> time;
    if (t >= time && minc > c) minc = c;
  }
  cout << (minc != 10000 ? to_string(minc) : "TLE") << endl;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
field=[]
field.append([True for i in range(w+2)])
start=[]
for i  in range(h):
    s=input()
    sub=[True]
    for j in range(w):
        if s[j]=="#":
            sub.append(True)
        else:
            sub.append(False)
            start.append((i+1,j+1))
    
    sub.append(True)
    field.append(sub)

            
        
    
field.append([True for i in range(w+2)])

from collections import deque
import copy
dis=[]
for i in range(len(start)):

        fields=copy.deepcopy(field)
        d=deque()
        e=deque()
        distance=0
        fields[start[i][0]][start[i][1]]=True

        d.append((start[i][0],start[i][1]))
        while d:
            for some in d:
                index1,index2=some[0],some[1]
                if fields[index1-1][index2]==False:
                    fields[index1-1][index2]=True
                    e.append((index1-1,index2))
                if fields[index1+1][index2]==False:
                    fields[index1+1][index2]=True
                    e.append((index1+1,index2))
                if fields[index1][index2+1]==False:
                    fields[index1][index2+1]=True
                    e.append((index1,index2+1))
                if  fields[index1][index2-1]==False:
                    fields[index1][index2-1]=True
                    e.append((index1,index2-1))
            distance+=1
            d=e
            e=deque()

        dis.append(distance)
    


print(max(dis)  -1)      

Measured memory_bytes: 3572
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		final int MAX = 123457;
		
		boolean[] isPrime = new boolean[2*MAX];
		for(int i = 0; i < 2*MAX; i++){
			isPrime[i] = true;
		}
		isPrime[0] = false;
		isPrime[1] = false;
		
		for(int i = 2; i < 2*MAX; i++){
			if(isPrime[i]){
				for(int j = i*2; j < 2*MAX; j+=i){
					isPrime[j] = false;
				}
			}
		}
		
		while(true){
			int n = sc.nextInt();
		
			if(n == 0){
				break;
			}
			
			int count = 0;
			for(int i = n+1; i <= 2*n; i++){
				if(isPrime[i]){
					count++;
				}
			}
		
			System.out.println(count);
		}
		
		
	}
}	

Measured memory_bytes: 13000
N, M, Q = map(int, input().split())
bord = [[0 for _ in range(N + 2)] for _ in range(N + 2)]

for _ in range(M):
    left, right = map(int, input().split())
    bord[left][right] += 1
# print(bord)
for i in range(1, N + 2):
    for j in range(1, N + 2):
        bord[i][j] += bord[i][j - 1]
# print(bord)
for _ in range(Q):
    left, right = map(int, input().split())
    cost = 0
    for i in range(left, right + 1):
        cost += bord[i][right] - bord[i][left - 1]
    print(cost)


Measured memory_bytes: 53744
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
	double n,k;
	cin >> n >> k;
	double ans=0;
	for (int i=1; i<=n; i++){
		long long temp = 0;
		long long x=i;
		while (x<k){
			x*=2;
			temp++;
		}
		double r  = pow(0.5,temp);
		ans+= (r/n);
	}
	cout << fixed << setprecision(15);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////
#define N 20000004

ll kai[N];
ll kai2[N];
ll po(ll i,ll p){
    if(p==0)return 1;
    else if(p==1)return mod(i);
    else if(p%2==0)return po(mod(mod(i)*mod(i)),p/2);
    else  return mod(mod(i)*po(i,p-1));
}
void calc(){
    kai[0]=1;
    kai2[0]=1;
    rep(i,1,N-1){
        kai[i]=mod(kai[i-1]*i);
    }
    kai2[N-1]=po(kai[N-1],i_5);
    for(int i=N-2;i>=0;i--){
        kai2[i]=mod(kai2[i+1]*(i+1));
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    else if(n==0)return 1;
    else return mod(mod(kai[n]*kai2[n-k])*kai2[k]);
}
ll bunbo(ll n){
    return po(n,i_5);
}

int main(){
    calc();
    /*rep(i,1,5){
     cout<<kai[N-i]<<" "<<kai2[N-i]<<endl;
     }*/
    ll h,w,k;cin>>h>>w>>k;
    ll x[4];
    for(ll p=1;p<=min(3,k);p++){
        ll sum=0;
        for(ll i=max(0,p-w);i<=min(h,p);i++){
            ll res=(i+1)*(p-i+1)*comb(p,i)*comb(w+h-p,h-i);
            sum+=res;
        }//cout<<"sum:"<<sum<<endl;
        x[p]=sum;
    }
    ll ans=mod(mod(kai[h]*kai[w])*kai2[h+w-k]);
    if(k<=3){
        ll res=0;
        rep(i,1,k)res=mod(res+x[i]);
        cout<<mod(ans*res);
    }else{
        ll y1=x[2]-x[1];
        ll y2=x[3]-x[2];
        ll z=y2-y1;
        ll res=mod(x[1]*k)+mod(mod((y1-z)*k)*mod((k+1)*bunbo(2)))-mod((y1-z)*k)+mod(mod(k*(k+1))*mod(mod((2*k+1)*z)*bunbo(12)))-mod(mod(z*k)*mod((k+1)*bunbo(4)));
        cout<<mod(res*ans)<<endl;
    }
    return 0;
}


Measured memory_bytes: 312832
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  int n;
  cin>>n;
  string s;
  cin>>s;
  int cnt=0;
  for(int i=0;i<s.length();i++)
  {
    if(s[i]=='A'&& s[i+1]=='B' && s[i+2]=='C')
    {
      cnt++;
    }
  }
  cout<<cnt<<endl;
}


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

int main(){
  string S;
  cin >> S;
  int diff = 753, temp = 0;
  for (int i=0; i < S.size() - 2; i++) {
    temp = abs(753 - atoi(S.substr(i, 3).c_str()));
    if (temp < diff) {
      diff = temp;
    }
  }
  cout << diff << endl;
  return 0;
}


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

using namespace std;

#define INP "solve"
#define OUT "solve"

const int QQ = 3e5 + 10;
const int maxN = 6e5 + 10;
const int maxM = 1e5 + 100;
const int oo = 1e9;
const int MOD = 1e9 + 7;
const int Base = 311;
const long double du = 1e-9;
const string YES = "YES";
const string NO = "NO";
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};

void doc() {
    freopen(INP ".inp","r",stdin);
    freopen(OUT ".out","w",stdout);
}

void solve() {
    int n, k, S;
    cin >> n >> k >> S;
    if (S == oo) {
        for (int i = 0; i < k; i++) cout << S << ' ';
        for (int i = 0; i < n - k; i++) cout << S - 1 << ' ';
        return;
    }
    for (int i = 0; i < k; i++) cout << S << ' ';
    for (int i = 0; i < n - k; i++) cout << oo << ' ';
}
int main(int argc,char *argv[]) {
    ///srand(time(nullptr));
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    ///doc();
    solve();
}


Measured memory_bytes: 1280
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

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

#define MOD 100000
int memo[101][101][4];
int calc_(int y, int x, int c){ // c : 2-3 turned 0,2 x++ 1,3 y++
  if(memo[y][x][c]) return memo[y][x][c];
  if(!x && !y) return 0;
  if(x && !y && c==0) return 1;
  if(!x && y && c==1) return 1;
  if(!x || !y) return 0;
  switch(c){
    case 0:
      if(!x) return 0;
      return memo[y][x][c] = (calc_(y, x-1, 0) + calc_(y, x-1, 2)) % MOD;
    case 1:
      if(!y) return 0;
      return memo[y][x][c] = (calc_(y-1, x, 1) + calc_(y-1, x, 3)) % MOD;
    case 2:
      if(!x) return 0;
      return memo[y][x][c] = calc_(y, x-1 ,1) % MOD;
    case 3:
      if(!y) return 0;
      return memo[y][x][c] = calc_(y-1, x, 0) % MOD;
  }
}

int calc(int y, int x){
  int ret = 0;
  if (x <= 0) x++;
  if (y <= 0) y++;
  REP(k,4) ret += calc_(y, x, k);
  return ret;
}

int main(){
  int w,h;
  while(cin>>w>>h){
    if(!w && !h) break;
    memset(memo,0,sizeof(memo));
    cout<<calc(w-1,h-1)%MOD<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define ALL(x) begin(x), end(x)
using namespace std;

template <typename UnaryPredicate>
int64_t binsearch_max(int64_t l, int64_t r, UnaryPredicate p) {
    assert (l <= r);
    ++ r;
    while (r - l > 1) {
        int64_t m = l + (r - l) / 2;  // avoid overflow
        (p(m) ? l : r) = m;
    }
    return l;
}

int get_k(int a, int b) {
    if (a < b) swap(a, b);
    return (a + (b + 1) - 1) / (b + 1);
}

string generate(int a, int b, int l, int r, int k) {
    assert (a >= 0 and b >= 0);
    assert (0 <= l and l <= r and r <= a + b);
    if (a < b) {
        string s = generate(b, a, a + b - r, a + b - l, k);
        reverse(ALL(s));
        for (char & c : s) c ^= 'a' ^ 'b';
        return s;
    }
    assert (a >= b);
    if (a < k) {
        string s;
        REP3 (i, l, r) {
            s += i < a ? 'A' : 'B';
        }
        return s;
    }
    int x = binsearch_max(0, a + b, [&](int x) {
        int na = a - k - k * x;
        int nb = b - x;
        return na >= 0 and nb >= 0 and get_k(na, nb) <= k;
    });
    string s;
    REP3 (i, l, r) {
        if (i < k) {
            s += 'A';
        } else if (i < k + (1 + k) * x) {
            s += (i - k) % (1 + k) ? 'A' : 'B';
        }
    }
    int na = a - k - k * x;
    int nb = b - x;
    if (nb == 0) assert (na == 0);
    if (nb >= 1) {
        nb -= 1;
        if (l <= k + (1 + k) * x and k + (1 + k) * x < r) {
            s += 'B';
        }
        int offset = k + (1 + k) * x + 1;
        s += generate(na, nb, max(0, l - offset), max(0, r - offset), k);
    }
    return s;
}
string generate(int a, int b, int l, int r) {
    int k = get_k(a, b);
    return generate(a, b, l, r, k);
}

int main() {
    int q; cin >> q;
    while (q --) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        cout << generate(a, b, c - 1, d) << endl;
    }
    return 0;
}


Measured memory_bytes: 384
object methods {
  def solver(): Unit = {

    val tempList: Seq[Seq[String]] = {
      for (line <- io.Source.stdin.getLines()) yield {
        line.split(' ').toSeq
      }
    }.toSeq
    val X: Int = tempList(0)(0).toInt
    val N: Int = tempList(0)(1).toInt

    val numList: Seq[Int] = if(N != 0) {
      tempList(1).map(_.toInt)
    } else {
      Seq()
    }

    // 0~101までで正数列が含まれない集合を求める
    val rangeList: Set[Int] = Range(0, 102).toList.toSet //これで0から101
    val diffRange: List[Int] = rangeList.diff(numList.toSet).toList
    val diffAbsRange: List[Int] = diffRange.map(x => (x-X).abs)
    val minIndex: Int = diffAbsRange.indexOf(diffAbsRange.min)
    val minOfRange: Int = diffRange(minIndex)


    println(minOfRange)
  }
}

object Main extends App {
  methods.solver()
}

Measured memory_bytes: 57880
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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 int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> b = a;
    sort(all(b));

    set<int> odd;
    for(int i=0; i<n; i+=2) odd.insert(a[i]);
    int ans = 0;
    for(int i=1; i<n; i+=2){
        if(odd.find(b[i]) != odd.end()) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3328
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
const int MaxN = 131172;
int N;
int Point[MaxN], Next[MaxN], To[MaxN], W[MaxN], q;
long long d[MaxN];
void Add(int u, int v, int w){ Next[++q] = Point[u]; Point[u] = q; To[q] = v; W[q] = w; }
void dfs(int u, long long tmp)
{
	d[u] = tmp;
	for(int j = Point[u]; j; j = Next[j])
		dfs(To[j], tmp + W[j]);
}
struct pair{ int fir, sec; };
typedef std::vector<pair>::iterator iter;
std::vector<pair> S[MaxN], t;
bool cmp1(pair i, pair j){ return d[i.fir] < d[j.fir]; }
bool cmp2(pair i, pair j){ return d[i.sec] > d[j.sec]; }
bool cmp3(pair i, pair j){ return d[i.fir] > d[j.fir]; }
bool cmp4(pair i, pair j){ return d[i.sec] < d[j.sec]; }
bool dfs1(int u, long long v)
{
	S[u].clear();
	for(int j = Point[u]; j; j = Next[j])
	{
		if(dfs1(To[j], v)) return 1;
		if(S[u].empty()) std::swap(S[u], S[To[j]]);
		else
		{
			if(S[u].size() > S[To[j]].size()) std::swap(S[u], S[To[j]]);
			std::sort(S[u].begin(), S[u].end(), cmp2);
			std::sort(S[To[j]].begin(), S[To[j]].end(), cmp1);
			t.clear();
			iter k = S[To[j]].begin(); int sec = 0;
			for(iter i = S[u].begin(); i != S[u].end(); ++i)
			{	
				while(k != S[To[j]].end() && d[i->sec] + d[k->fir] <= v + (d[u] << 1))
				{
					if(d[k->sec] < d[sec]) sec = k->sec;
					++k;
				}
			/*	for(iter k = S[To[j]].begin(); k != S[To[j]].end(); ++k)
					if(d[i->sec] + d[k->fir] <= v + (d[u] << 1) && d[sec] > d[k->sec]) 
						sec = k->sec;*/
				if(sec) t.push_back((pair){i->fir, sec});
			}
			std::sort(S[u].begin(), S[u].end(), cmp3);
			std::sort(S[To[j]].begin(), S[To[j]].end(), cmp4);
			k = S[To[j]].begin(); int fir = 0;
			for(iter i = S[u].begin(); i != S[u].end(); ++i)
			{	
				while(k != S[To[j]].end() && d[k->sec] + d[i->fir] <= v + (d[u] << 1))
				{
					if(d[k->fir] < d[fir]) fir = k->fir;
					++k;
				}
				/*for(iter k = S[To[j]].begin(); k != S[To[j]].end(); ++k)
					if(d[k->sec] + d[i->fir] <= v + (d[u] << 1) && d[fir] > d[k->fir]) 
						fir = k->fir;*/
				if(fir) t.push_back((pair){fir, i->sec});
			}		
			std::swap(t, S[u]);
		}
	}
	if(!Point[u]) S[u].push_back((pair){u, u});
	return S[u].empty();
}
int main()
{
	scanf("%d", &N);
	for(int i = 2; i <= N; ++i)
	{
		int a, v;
		scanf("%d %d", &a, &v);
		Add(a, i, v);
	}
	d[0] = 1ll << 60;
	dfs(1, 0);
	//for(int i = 1; i <= N; ++i) printf("%d ", d[i]); puts("");
	long long l = -1, r = 1ll << 35;
	while(r - l > 1)
	{
		long long mid = l + r >> 1;
	//	printf("%lld\n", mid);
		if(dfs1(1, mid)) l = mid;
		else r = mid;
	}
	printf("%lld\n", r);
	return 0;
}

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

int main() {
  int h, w, ch, cw, dh, dw;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--; cw--; dh--; dw--;
  vector<string> s(h);
  rep(i, h) {
    cin >> s.at(i);
  }

  vector<vector<int>> dp(h, vector<int>(w, 1e9));
  dp.at(ch).at(cw) = 0;
  deque<P> dq;
  dq.emplace_front(ch, cw);
  while (dq.size()) {
    P p = dq.front();
    dq.pop_front();
    int r = p.first, c = p.second;
    vector<int> dr = {1, -1, 0, 0};
    vector<int> dc = {0, 0, 1, -1};
    rep(i, 4) {
      int nr = r + dr.at(i);
      int nc = c + dc.at(i);
      if (nr < 0 || nc < 0 || nr >= h || nc >= w) continue;
      if (s.at(nr).at(nc) == '#') continue;
      if (dp.at(nr).at(nc) > dp.at(r).at(c)) {
        dp.at(nr).at(nc) = dp.at(r).at(c);
        dq.emplace_front(nr, nc);
      }
    }

    rep(i, 5) {
      rep(j, 5) {
        int nr = r - 2 + i;
        int nc = c - 2 + j;
        if (nr < 0 || nc < 0 || nr >= h || nc >= w) continue;
        if (s.at(nr).at(nc) == '#') continue;
        if (dp.at(nr).at(nc) > dp.at(r).at(c) + 1) {
          dp.at(nr).at(nc) = dp.at(r).at(c) + 1;
          dq.emplace_back(nr, nc);
        }
      }
    }
  }

  cout << (dp.at(dh).at(dw) == 1e9 ? -1 : dp.at(dh).at(dw)) << endl;
  return 0;
}

Measured memory_bytes: 9524
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll n;
	cin>>n;
	ll a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	vector<ll> v;
	for(int i=0;i<n;i+=2)
	{
		ll x=a[i]^a[i+1];
		v.push_back(x);
	}
	ll z=0;
	for(int i=0;i<v.size();i++)
	{
		z=z^v[i];
	}
	for(int i=0;i<n;i++)
	{
		ll x=z^a[i];
		cout<<x<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 5804
#include<iostream>
using namespace std;
int main() {
	const int ANT_NO = 5;
	int antnum[ANT_NO];
	int i,k;

	for (i = 0; i < ANT_NO; i++) {
		cin >> antnum[i];
	}

	cin >> k;
	if (k < antnum[ANT_NO - 1] - antnum[0]) {
		cout << ":(";
	}
	else {
		cout << "Yay!";
	}

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int a,b;
    cin>>a>>b;
    cout<<max(max(a+b,a-b),a*b);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i,s,n) for(int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
    ll h, w;
    cin >> h >> w;
    if(h==1||w==1){
        cout << 1 << endl;
    }else{
        cout << (h * w + 1) / 2 << endl;
    }
    return 0;
}

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

#define fi first
#define se second
#define mk(a,b) make_pair(a,b)

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

int N, K;
ll ans = 1;
vector<int> V[100010];
ll mod = 1000000007;

ll F[100010] = {1}, R[100010];

ll pow_mod(ll a, ll b)
{
    if(b == 0)return 1;
    ll ret = pow_mod(a * a % mod, b >> 1);
    if(b & 1)ret = ret * a % mod;
    return ret;
}

ll C(int a, int b)
{
    if(a < b || a < 0 || b < 0)return 0;
    return F[a] * R[b] % mod * R[a - b] % mod;
}

void DFS(int v, int p = 0)
{
    int ch = (int)(V[v].size()) - (p != 0);
    if(ch == 0)return;
    ans = ans * C(K - 1 - (p != 0), ch) % mod * F[ch] % mod;
    for(int i = 0; i < V[v].size(); i++)if(p != V[v][i])DFS(V[v][i], v);
}

int main()
{
    cin >> N >> K;
    for(int i = 0; i < N - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        V[a].push_back(b);
        V[b].push_back(a);
    }

    for(int i = 1; i < 100010; i++)F[i] = F[i - 1] * i % mod;
    for(int i = 0; i < 100010; i++)R[i] = pow_mod(F[i], mod - 2);

    ans = K;
    DFS(1);

    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define FORd(i, a, b) for (int i=a; i<(b); --i) 

int n, a,b;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    int ans = 0;
    while (n--){
        cin >> a >> b;
        if (a==b) ans++;
        else ans=0;
        if (ans==3){
            cout <<"Yes";
            return 0;
        }
    }
    cout <<"No";
    return 0; 
}

Measured memory_bytes: 3656
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,k,vis[10];
int check(int n){
	while(n){
		if(vis[n%10]==1)
		return 0;
		n/=10;
	}
    return 1;
	}
int main()
{
	cin>>n>>k;
	memset(vis,0,sizeof(vis));
	int a;
	for(int i=0;i<k;i++){
	cin>>a;
	vis[a]=1;
}
	int i=n;
	while(1){
		if(check(i)){
			cout<<i<<endl;
			break;
		}
		i++;
	}
	
	
 } 

Measured memory_bytes: 256
N, W = map(int, input().split())
v = []
w = []
for i in range(N):
    x, y = map(int, input().split())
    v.append(x)
    w.append(y)

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for j in range(W + 1):
        if j - w[i] >= 0:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i])
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

ans = dp[N][W]
print(ans)


Measured memory_bytes: 41892
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;

int date[101]={0};
int memo[101]={0};
int i=0;
int main(){
  int n,mc=1;
  //入力フェイズ
  while(cin >> n){
    date[n]=date[n]+1;
   // memo[i]=n;
   // i++;
    mc=max(mc,date[n]);
   // cout <<"最大値:" <<mc << endl;
   // cout << date[n] << endl;
   // cout << mc << endl;
    }
  //sort(date.begin(),date.end());
  for(int j=0;j<=100;j++){
    if(mc==date[j]){
      cout << j << endl;
    }
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int x,y;
string s;

int main(){
	cin >> s >> x >> y;
	
	bool f=true;
	int c=0,c2=0;
	vector<int> vec,vec2; vec.push_back(0); vec2.push_back(0);
	REP(i,0,s.size()){
		if(f and s[i]=='T') vec2.push_back(0),c2++,f=false;
		else if(!f and s[i]=='T') vec.push_back(0),c++,f=true;
		else if(f and s[i]=='F') vec[c]++;
		else if(!f and s[i]=='F') vec2[c2]++;
	}
	
	bool dp[c+10][8010*2+1]={}; dp[0][8010+vec[0]]=true;
	REP(i,0,vec.size()-1){
		int a=vec[i+1];
		RREP(j,8010*2,0){
			if(dp[i][j] and j-a>=0) dp[i+1][j-a]=true;
			if(dp[i][j] and j+a<8010*2) dp[i+1][j+a]=true;
		}
	}
	
	bool dp2[c2+10][8010*2+1]={}; dp2[0][8010+vec2[0]]=true;
	REP(i,0,vec2.size()-1){
		int a=vec2[i+1];
		RREP(j,8010*2,0){
			if(dp2[i][j] and j-a>=0) dp2[i+1][j-a]=true;
			if(dp2[i][j] and j+a<8010*2) dp2[i+1][j+a]=true;
		}
	}
	
	if(dp[c][8010+x] and dp2[c2][8010+y]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 124800
N=input()
S=[ list(raw_input()) for i in range(N)]

A=0
ans=0
for B in range(N):
	flag=0
	for i in range(N):
		if flag==-1: break
		for j in range(N):
			x1=(N+i-A)%N
			y1=(N+j-B)%N

			x2=(N+j-A)%N
			y2=(N+i-B)%N

			#print i,j,x1,y1,x2,y2
			if S[x1][y1]==S[x2][y2]:
				pass
			else:
				flag=-1
				#break
	else:
		ans+=1*N


print ans


Measured memory_bytes: 36328
#include <iostream>

typedef long long ll;
const ll MAX = 100000;


int check(ll P);	//checking how many goods can be loaded by k trucks whose largest carrying limits are P
//time complexity O(n)
ll solve();		//use binary search through the interval of input limit to determine min(P)
//time complexity O(logP)
//check(ll P) invoked in solve(), so the total time complexity is O(nlogP)
int n, k;
int T[100000];

	using namespace std;
int main()
{
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> T[i];
	}
	ll ans = solve();
	cout << ans << endl;
	return 0;
}

int check(ll P)
{
	int i = 0;
	for (int j = 0; j < k; j++)
	{
		int sum = 0;
		while (i<n&&sum + T[i] <= P)
		{
			sum += T[i];
			i++;
		}
		if (i >= n)
		{
			return n;
		}
	}
	return i;
}

ll solve()
{
	ll left = 0;
	ll right = 100000 * 10000;
	ll mid;
	while (right - left > 1)
	{
		mid = (left + right) / 2;
		int v = check(mid);
		if (v >= n)
		{
			right = mid;
		}
		else
		{
			left = mid;
		}
	}
	return right;
}


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

s = input()
t = input()

ls = len(s)
lt = len(t)

dp = [[0]*(lt+1) for _ in [0]*(ls+1)]

for i in range(1,ls+1):
    for j in range(1,lt+1):
        if s[i-1] != t[j-1]:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1], 1+dp[i-1][j-1])

L=dp[ls][lt]
ans = [0]*L
idx=L-1
i=ls
j=lt
while idx >= 0:
#    print(i,j,idx)
    if i>0 and dp[i-1][j] == dp[i][j]:
        i -= 1
    elif j>0 and dp[i][j-1] == dp[i][j]:
        j-=1
    else:
        i-=1
        j-=1
        ans[idx] = s[i]
        idx -= 1

#print(dp)
print(''.join(ans))








Measured memory_bytes: 113244
#include<stdio.h>
 int main(){

  int a,b,c,i,x,y;

  scanf("%d %d %d",&a,&b,&c);

  for(i=a;i<=b;i++){
      x=c%i;
      if(x==0) y++;
  }

  printf("%d\n",y);

return 0;
}

Measured memory_bytes: 1860
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
   int w,h,n;
   cin >> w >> h >>n ;
   VI x(n);
   VI y(n);
   VI a(n);
   rep(i,n){
      cin >> x[i] >> y[i] >> a[i];
   }
   int mxx,mnx,mxy,mny;
   mnx=w;
   mxx=0;
   mny=h;
   mxy=0;
   rep(i,n){
      if(a[i]==1){
         mxx=max(x[i],mxx);
      }
      else if(a[i]==2){
         mnx=min(x[i],mnx);
      }
      else if(a[i]==3){
         mxy=max(y[i],mxy);
      }
      else if(a[i]==4){
         mny=min(y[i],mny);
      } 
   }
   int ans;
   if(mxx>=mnx || mxy>=mny)ans=0;
   else{
      ans=(mnx-mxx)*(mny-mxy);
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

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

int N, A[2000], used[2001];
long long dp[2001][2001];

int prev(int idx) {
  return (idx - 1 + N) % N;
}

int next(int idx) {
  return (idx + 1) % N;
}

long long rec(int l, int r, bool turn) {
  
  if(l == r) return (turn ? A[l] : 0);
  if(~dp[l][r]) return dp[l][r];
  
  long long ret = 0;
  if(!turn) {
    if(A[l] > A[r]) ret = max(ret, rec(prev(l), r, true));
    else ret = max(ret, rec(l, next(r), true));
  } else {
    ret = max(ret, rec(prev(l), r, false) + A[l]);
    ret = max(ret, rec(l, next(r), false) + A[r]);
  }
  if(turn) 
    dp[l][r] = ret;
  return ret;
} 

int main(){
  
  cin >> N;
  for(int i = 0; i < N; i++)
    cin >> A[i];

  long long ans = 0;
  memset(dp, -1, sizeof(dp));
  for(int i = 0; i < N; i++) {
    ans = max(ans, rec(prev(i), next(i), false) + A[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 32548
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
	string s,t;
	int count=0,i,j;

	cin >> s >> t;
	i=0;
	for(i=0;i<s.length();i++){
	//while(s.at(i+1)!='\0'){
		if(s.at(i)!=t.at(i))count++;
	}
	
	cout << count << endl;
	
	
	return 0;
}

Measured memory_bytes: 3912
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq


def dfs(s, prev, pre):
  val[s] += Ope[s] + prev
  for i in G[s]:
    if(i == pre):
      continue
    dfs(i, val[s], s)

def bfs(sx, sy, n):
  que = deque([[sy,sx]])
  while que:
    y,x = que.popleft()
    for i,j in D:
      if(x+i<0 or y+j<0 or x+i>W-1 or y+j>H-1):
        continue
      dist = G[y+j][x+i]
      if(G[y+j][x+i] != "X"):
        if(type(G[y+j][x+i]) is str):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        elif(dist>G[y][x]+1):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        

def combinations_count(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]



K,N = map(int, input().split())
A = [int(i) for i in input().split()]
D = [0]*N
ans = 0

for i in range(N-1):
  D[i] = A[i+1] - A[i]
D[N-1] = (K-A[N-1])+A[0]

ans = K - max(D)

print(ans)


Measured memory_bytes: 78316
#include<stdio.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main (void)
{
	int N[5];
	scanf("%d %d %d", &N[0], &N[1], &N[2]);
	qsort(N, 3, sizeof(int), compare_int);

	printf("%d", N[0] + N[1]);
	
	return 0;
}



Measured memory_bytes: 128
import java.util.Arrays;

public class Main {
	Scanner sc = new Scanner();

	class Scanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}
	}

	void run() {
		for (;;) {
			int N = sc.nextInt();
			if (N == 0) {
				return;
			}
			Circle[] info = new Circle[N];
			for (int i = 0; i < N; i++) {
				info[i] = new Circle(sc.nextDouble(), sc.nextDouble(),
						sc.nextDouble());
			}
			double min = Double.MAX_VALUE;
			double dist = 0;
			Arrays.sort(info);
			for (int i = 0; i < N; i++) {
				for (int j = i + 1; j < N; j++) {
					if (j > i + 50) {
						break;
					}
					dist = Math.hypot(info[i].x - info[j].x, info[i].y
							- info[j].y);
					min = Math.min(min, dist - info[i].r - info[j].r);
				}
			}
			System.out.println(min);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	class Circle implements Comparable<Circle> {
		double r;
		double x;
		double y;

		Circle(double r, double x, double y) {
			this.r = r;
			this.x = x;
			this.y = y;
		}

		public int compareTo(Circle c) {
			return (int) (this.x - c.x);
		}
	}
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const ll MOD = (ll)(2019);

ll l, r;

ll ans;

int main(void) {
  // Here your code !
  scanf("%lld %lld", &l, &r);

  ans = INF;

  for (ll i = l; i <= l + MOD - 1; ++i) {
    for (ll j = i + 1LL; j <= i + MOD - 1; ++j) {
      if (i >= r || j > r) continue;
      ans = min(ans, (i * j) % MOD);
    }
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 256
n = int(input())
ab = [list(map(int,input().split())) for _ in range(n)]

l = sorted([[a + b, a, b] for a, b in ab])[::-1]
res = 0
for idx, i in enumerate(l):
    if idx % 2 == 0:
        res += i[1]
    else:
        res -= i[2]
print(res)


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll A, B1, B2;
    scanf("%lld %lld.%lld", &A, &B1, &B2);
    cout << A * (B1 * 100 + B2) / 100 << endl;
    return 0;
}


Measured memory_bytes: 3756
S = input()[::-1]
div = ["maerd", "remaerd", "esare", "resare"]

flag1 = True
i = 0
while i < len(S):
    flag2 = False
    for d in div:
        if S[i:i + len(d)] == d:
            flag2 = True
            i += len(d)
            break

    if not flag2:
        flag1 = False
        break

if flag1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
#include <iostream>
#include <set>
using namespace std;
#define P pair<int,int>
int main()
{
  int n,i;
  for(;;){
    cin >> n;
    if(n==0)break;
    set< P > se;
    while(n--){
      int c,m,s,j=0;
      cin >> c;
      for(i=0;i<4;i++){
	cin >> m >> s;
	j += m*60+s;
      }
      se.insert( P(j,c) );
    }
    set< P >::iterator it = se.begin();
    for(i=0;i<2;i++){
      cout << (*it).second << endl;
      it++;
    }
    set< P >::reverse_iterator r = se.rbegin();
    r++;
    cout << (*r).second << endl;
  }
  return 0;
}

Measured memory_bytes: 1064
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
const int N=1e18;



int32_t main()
{

	
    IOS;
	

	int n,W,x,y;
	cin>>n>>W;
	int w[n+1],v[n+1],dp[n+1][W+1];
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		w[i]=x;
		v[i]=y;
	}

	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=W;j++)
		{
			dp[i][j]=0;
		}
	}

	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=W;j++)
		{
			if(w[i]>j)
			{
				dp[i][j]=dp[i-1][j];
			}
			else
			{
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
			}
		}
	}

	cout<<dp[n][W]<<endl;
	return 0;
}

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

#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 SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define OUT(a) cout << (a) << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

template <class T, class S>
using umap = std::unordered_map<T, S>;
using ll = long long;
using namespace std;

int main() {
    ll n, ans = 0;;

    cin >> n;

    REP(i, n+1){
        if (i%3 != 0 && i%5 != 0){
          ans += i;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  int n;cin>>n;
  vector<int> a(n+1),b(n);
  rep(i,n+1)cin>>a[i];
  rep(i,n)cin>>b[i];
  ll ans=0;
  rep(i,n){
    if(a[i]>b[i])ans+=b[i];
    else {
      ans+=min(b[i],a[i]+a[i+1]);
      a[i+1]=max(a[i]+a[i+1]-b[i],0);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3996
#include <bits/stdc++.h>
#include <algorithm>
#include <stdlib.h>
#include <stack>
#include <queue>
using namespace std;
char A[60][60] = {}; 
int D[60][60] = {}; 
int R, C; 
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; 
int bfs(){
	queue<pair<int, int>> que;
	for(int i = 0; i < R; i++){
		for(int j = 0; j < C; j++){
			D[i][j] = 114514;
		}
	}
	que.push(pair<int, int>(0, 0)); 
	D[0][0] = 0; 
	while(que.size()){
		pair<int, int> p = que.front(); que.pop(); 
		if (p.first == R-1 && p.second == C-1){break;}
		for(int i = 0; i < 4; i++){
			int nx = p.first + dx[i], ny = p.second + dy[i]; 
			if(nx >= 0 && nx < R && ny >= 0 && ny < C && 
				A[nx][ny] != '#' && D[nx][ny] == 114514){
				que.push(pair<int, int>(nx, ny)); 
				D[nx][ny] = D[p.first][p.second] + 1; 
			}
		}
	}
	return D[R-1][C-1]; 
}
int main(){
	cin >> R >> C; 
  	int count = 0; 
	for(int i = 0; i < R; i++){
		for(int j = 0; j < C; j++){
			cin >> A[i][j];
			if(A[i][j] == '.'){count ++;}
		}
	}
	if(bfs() == 114514){cout << -1 << endl;}
	else{cout << count - bfs() - 1<< endl;}
}

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

using namespace std;

long long dp[200010] = {};
int mod = 998244353;

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

	int l[10], r[10];
	for (int i = 0; i < k; i++) {
		cin >> l[i] >> r[i];
	}
	
	long long ksum[10] = {};
	int pk[10] = {}, qk[10] = {};
	for (int i = 0; i < k; i++) {
		pk[i] = 2 - r[i];
		qk[i] = 2 - l[i] + 1;
	}
	dp[1] = 1;
	for (int i = 0; i < k; i++) {
		if (l[i] == 1) {
			ksum[i] = 1;
		}
	}
	for (int i = 2; i <= n; i++) {
		for (int j = 0; j < k; j++) {
			dp[i] += ksum[j];
			dp[i] %= mod;
		}
		for (int j = 0; j < k; j++) {
			ksum[j] += dp[max(0, qk[j])];
			ksum[j] %= mod;
			ksum[j] += mod;
			ksum[j] -= dp[max(0, pk[j])];
			ksum[j] %= mod;
			qk[j]++;
			pk[j]++;
		}
	}
	cout << dp[n] << endl;

	return 0;
}

Measured memory_bytes: 5160
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,M = LI()
s,c = LIR(M,2)

if M==0:
    if N==1:
        print(0)
    elif N==2:
        print(10)
    else:
        print(100)
    exit()


x = [-1]*N
for i in range(M):
    if x[s[i]-1]!=-1 and x[s[i]-1]!=c[i]:
        print(-1)
        exit()
    else:
        x[s[i]-1]=c[i]

if x[0]==0:
    if N==1:
        print(0)
        exit()
    else:
        print(-1)
        exit()

for i in range(N):
    if x[i]==-1:
        if i==0:
            x[i] = 1
        else:
            x[i] = 0

y = ''
for i in range(N):
    y += str(x[i])

print(int(y))

Measured memory_bytes: 38528
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

char s[100001];
int len;

bool find(int l, string word)
{
	for (int i = 0; i < word.length(); i++)
	{
		int j = i + l;
		if (j >= len)
		{
			return false;
		}
		if (s[j] != word.at(i))
		{
			return false;
		}
	}
	return true;
}

signed main()
{
	cin >> s;
	len = strlen(s);
	int l = 0;

	bool is_dream = false;

	while (true)
	{
		if (l == len)
		{
			cout << "YES" << endl;
			return 0;
		}

		if (find(l, "dream"))
		{
			is_dream = true;
			l += 5;
			continue;
		}

		if (find(l, "eraser"))
		{
			is_dream = false;
			l += 6;
			continue;
		}

		if (find(l, "erase"))
		{
			is_dream = false;
			l += 5;
			continue;
		}

		if (is_dream && find(l, "er"))
		{
			is_dream = false;
			l += 2;
			continue;
		}

		cout << "NO" << endl;
		return 0;
	}
}

Measured memory_bytes: 384
#include<stdio.h>
const int N=55;
char str1[N],str2[N]; 
char ans[2*N];
int main()
{
	bool flag=true;
	scanf("%s",&str1);
	scanf("%s",&str2);

	for(int i=0,j=0;str1[i]!='\0';i++,j=j+2)
	{
		ans[j]=str1[i];
	}
	for(int i=0,j=1;str2[i]!='\0';i++,j=j+2)
	{
		ans[j]=str2[i];
	}
	printf("%s\n",ans);
	return 0;
}

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

using namespace std;

int main(){
	long long n;
	cin >> n;
	if (n & 1LL)
		puts("0");
	else {
		n >>= 1;
		long long ans = 0;
		while (n > 0LL){
			ans += n / 5;
			n /= 5;
		}
		cout << ans << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static const int INF   = (1 << 21);
static const int WHITE = 0;
static const int GRAY  = 1;
static const int BLACK = 2;
static const int NIL   = -1;
static const int MAX   = 100;

int n;
vector<vector<int>> M(MAX, vector<int>(MAX, NIL));

void dijstra(int s) {
  vector<int> color(n, WHITE);
  vector<int> d(n, INF);
  vector<int> p(n);
  d[s] = 0;
  p[s] = NIL;

  while (true) {
    int u       = 0;
    int mincost = INF;
    for (int i = 0; i < n; i++) {
      if (color[i] != BLACK && d[i] < mincost) {
        mincost = d[i];
        u       = i;
      }
    }
    if (mincost == INF) { break; }

    color[u] = BLACK;

    for (int v = 0; v < n; v++) {
      if (color[v] != BLACK && M[u][v] != NIL) {
        if (d[u] + M[u][v] < d[v]) {
          d[v]     = d[u] + M[u][v];
          p[v]     = u;
          color[v] = GRAY;
        }
      }
    }
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    cout << i << " " << d[i] << endl;
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int id, k;
    cin >> id >> k;
    for (int j = 0; j < k * 2; j += 2) {
      int v, c;
      cin >> v >> c;
      M[id][v] = c;
    }
  }
  dijstra(0);
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
const int N=1e5+5,M=N<<2;
int ans,s,t,tot,now,n,m,head[N],nex[M],to[M];
int d[N];
bool vv[N];
void add(int u,int v)
{
    to[++tot]=v;nex[tot]=head[u];head[u]=tot;
}
struct node
{
    int u,x;
    node(int u,int x):u(u),x(x){}
    bool operator<(const node&o)const
    {
        return x>o.x;
    }
};
priority_queue<node>q;
bool vis[N][3];
void dfs(int u,int p)
{
    if(p==0)
    {
        if(d[u]>d[now]+1)
        {
            d[u]=d[now]+1;
            q.push(node(u,d[u]));
        }
        return;
    }
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];
        if(vis[v][p-1]) continue;
        vis[v][p-1]=true;
        dfs(v,p-1);
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        add(u,v);
    }
    memset(d,inf,sizeof(d));
    scanf("%d%d",&s,&t);
    d[s]=0;
    q.push(node(s,d[s]));
    while(!q.empty())
    {
        now=q.top().u;q.pop();
        if(vv[now]||d[now]>=d[t]) continue;
        vv[now]=true;
        dfs(now,3);
        if(d[t]!=d[0]) break;
    }
    if(d[t]!=d[0]) printf("%d\n",d[t]);
    else printf("-1\n");
}


Measured memory_bytes: 3840