akhauriyash/Code-Regression huggingface dataset:
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N, A, B, C, D; cin >> N >> A >> B >> C >> D;
    string s; cin >> s;

    A--; B--; C--; D--;
    bool ok = true;
    {
        // A -> C
        int cons = 0, max_cons = 0;
        for(int i=A; i<=C; i++) {
            if(s[i] == '.') {
                max_cons = max(max_cons, cons);
                cons = 0;
            }
            else {
                cons++;
            }
        }

        ok &= (max_cons < 2);
        fprintf(stderr, "ok1 = %d\n", max_cons < 2);
    }
    {
        // B -> D
        int cons = 0, max_cons = 0;
        for(int i=B; i<=D; i++) {
            if(s[i] == '.') {
                max_cons = max(max_cons, cons);
                cons = 0;
            }
            else cons++;
        }
        ok &= (max_cons < 2);
        fprintf(stderr, "ok2 = %d\n", max_cons < 2);
    }

    if(C > D) {
        bool can = false;
        
        // 追い越す場合は 3 マス以上の空きがどこかに必要
        int cons = 0, max_cons = 0;
        for(int i=B-1; i<=D+1; i++) {
            if(s[i] == '#') {
                max_cons = max(max_cons, cons);
                cons = 0;
            }
            else cons++;
        }
        max_cons = max(max_cons, cons);
        can |= (max_cons >= 3);
        // fprintf(stderr, "max_cons = %lld, can = %d\n", max_cons, can);

        ok &= can;
    }

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 640
import sys
import math
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	N = INT()
	A, B = [], []
	for _ in range(N):
		a, b = MAP()
		A.append(a)
		B.append(b)
	
	C = [-1] * N
	for i in range(N-1, -1, -1):
		C[i] = B[i] * math.ceil(A[i]/B[i]) - A[i] if B[i]>1 else 0
	# print(C)
	
	ans = 0
	for i in range(N-1, -1, -1):
		c = C[i]
		if B[i] == 1:
			continue
		if c >= ans:
			ans += c-ans
		else:
			ans += B[i] * math.ceil((A[i]+ans)/B[i]) - (A[i]+ans)
	print(ans)

if __name__ == '__main__':
	main()

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

int main(){
  int a, b;
  cin >> a >> b;

  if (((a >= 1) && ( a <= 9 )) &&((b >= 1)&&( b <= 9 ))){
    cout << a*b;
  }else{
    cout << -1;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P = 1e9+7;
const int N = 2010;
int f[N][N],g[N][N],A,B,com[N][N],h[N][N];
int main(){
	for(int i = 0;i<N;i++){
		com[i][0] =1;
		for(int j =1;j<=i;j++)com[i][j] =(com[i-1][j-1]+com[i-1][j])%P;
	}
	for(int j = 0;j<N;j++){
		f[0][j] = com[j][0];
		for(int i = 1;i<N;i++) f[i][j] = (f[i-1][j]+com[j][i])%P;
		g[0][j] = 0;
		for(int i =1;i<N;i++) g[i][j] = (g[i-1][j]+1ll*com[j][i]*i)%P;
	}
	scanf("%d%d",&A,&B);
	int ans = 1;
	for(int i = 0;i<A;i++){
		ans = (ans+1)%P;
		for(int j = 1;j<=A-i;j++){
			h[A-i-j][j] = (h[A-i-j][j]+com[B-1][j])%P;
		}
	}
	for(int i = 0;i<=A;i++) for(int j =1;j<=B;j++) {
		ans = (ans+1ll*h[i][j]*(1ll*(i+1)*f[i][j-1]%P-g[i][j-1]))%P;
	}
	ans = (ans+P)%P;
	printf("%d\n",ans);
	return 0;
}

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

const int N = 1e5 + 10;

vector<int> graf[N];
int dp[N], n, m;

int dfs(int u) {
  if (dp[u]) 
    return dp[u];
  for(int v : graf[u]) 
    dp[u] = max(dp[u], dfs(v));
  dp[u]++;
  return dp[u];
}

int main() {
  cin >> n >> m;
  while (m--) {
    int u, v;
    cin >> u >> v;
    graf[u-1].push_back(v-1);
  }
  
  int ret = -1;
  for (int i = 0; i < n; i++) {
    ret = max(dfs(i), ret);
  }
  
  cout << ret-1 << endl;
}


Measured memory_bytes: 7424
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n").map(Number);
while(true){
   var n=arr.shift();
   if(n==0)break;
   var ary=[];
   for(var i=0;i<n;i++)ary.push(arr.shift());
   var s=arr.shift();
   var cnt=0;
   var L=0;
   var R=ary.length-1;
   while(true){
      cnt++;
      var m=Math.floor((L+R)/2);
      if(ary[m]==s){
         break;
      }else if(ary[m]>s){
         R=m-1;
      }else if(ary[m]<s){
         L=m+1;
      }
      if(L>R)break;
   }
   console.log(cnt);
}

Measured memory_bytes: 15340
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    S = lines.pop(0)
    N = int(S)
    digit_sum = 0
    for i in S:
        digit_sum += int(i)
    if N % digit_sum == 0:
        print('Yes')
    else:
        print('No')


#
# main
#

# 1. use list instead of stdin

# contents = '''\
# 999999999\
# '''
# lines = contents.split('\n')

# 2. use stdin

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Measured memory_bytes: 3060
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static void Write(object obj) {
#if DEBUG
        Debug.Write(obj.ToString());
#else
        Console.Write(obj.ToString());
#endif
    }
    static void WriteLine(object obj) {
#if DEBUG
        Debug.WriteLine(obj.ToString());
#else
        Console.WriteLine(obj.ToString());
#endif
    }

    static long mod = 1000000007;

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var n     = int.Parse(spl[0]);
        var m     = int.Parse(spl[1]);

        var list = new List<Lamp>();
        for(int i=0; i<m; i++) {
            var l = new Lamp();
            spl = input.ReadLine().Split(' ');
            for(int j=1; j<spl.Length; j++) {
                l.sw.Add(int.Parse(spl[j]));
            }
            list.Add(l);
        }

        spl = input.ReadLine().Split(' ');
        for(int i=0; i<m; i++) {
            list[i].p = int.Parse(spl[i]);
        }

        var c = 0;
        for(int i=0; i<=Math.Pow(2,n)-1; i++) {
            if (list.All(x => x.IsOn(i)))
                c++;
        }
        return c;
    }

    class Lamp
    {
        public List<int> sw = new List<int>();
        public int p = 0;

        public bool IsOn(int i) {
            var sum = sw.Sum(x=>getbit(i, x));
            return sum % 2 == p;
        }

        public int getbit(int i, int pos) {
            return (i >> (pos-1)) % 2;
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>

using namespace std;

typedef pair<int, int> P;

int main() {
	int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		vector<char> isu(n, '#');
		char c;
		for (int i = 0; i < m; i++) {
			cin >> c;
			if (c == 'A') {
				for (int j = 0; j < n; j++) {
					if (isu[j] == '#') {
						isu[j] = 'A';
						break;
					}
				}
			} else if (c == 'B') {
				bool hantei = true;
				for (int j = n-1; j >= 0; j--) {
					if (isu[j] == '#') {
						if (j != 0 && j != n-1) {
							if (isu[j-1] != 'A' && isu[j+1] != 'A') {
								isu[j] = 'B';
								hantei = false;
								break;
							}
						} else if (j == 0) {
							if (isu[j+1] != 'A') {
								isu[j] = 'B';
								hantei = false;
								break;
							}
						} else {
							if (isu[j-1] != 'A') {
								isu[j] = 'B';
								hantei = false;
								break;
							}
						}
					}
				}
				if (hantei) {
					for (int j = 0; j < n; j++) {
						if (isu[j] =='#') {
							isu[j] = 'B';
							break;
						}
					}
				}
			} else if (c == 'C') {
				bool hantei = true;
				for (int j = 0; j < n; j++) {
					if (isu[j] != '#') {
						if (j != n-1 && isu[j+1] == '#') {
							isu[j+1] = 'C';
							hantei = false;
							break;
						} else if (j != 0 && isu[j-1] == '#') {
							isu[j-1] = 'C';
							hantei = false;
							break;
						}
					}
				}
				if (hantei) {
					isu[n/2] = 'C';
				}
			} else {
				queue<P> q;
				for (int j = 0; j < n; j++) {
					if (isu[j] == '#') {
						int counter = 1000;
						int counter2 = 1000;
						int d;
						for (int k = j-1; k >= 0; k--) {
							if (isu[k] != '#') {
								counter = j-k;
								break;
							}
						}
						for (int k = j+1; k < n; k++) {
							if (isu[k] != '#') {
								counter2 = k-j;
								break;
							}
						}
						d = min(counter, counter2);
						if (d == 1000) {
							break;
						}
						if (q.empty()) {
							P p;
							p.first = d;
							p.second = j;
							q.push(p);
						} else if ((q.front()).first < d) {
							while (!q.empty()) {
								q.pop();
							}
							P p;
							p.first = d;
							p.second = j;
							q.push(p);
						} else if ((q.front()).first == d) {
							P p;
							p.first = d;
							p.second = j;
							q.push(p);
						}
					}
				}
				if (q.empty()) {
					for (int j = 0; j < n; j++) {
						if (isu[j] == '#') {
							isu[j] = 'D';
							break;
						}
					}
				} else {
					P p = q.front();
					q.pop();
					isu[p.second] = 'D';
				}
			}
		}
		for (int i = 0; i < n; i++) {
			cout << isu[i];
		}
		cout << endl;
	}
	return 0; 
}

Measured memory_bytes: 1200
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <string>
#include <algorithm>

int N;

unsigned int GetDigit(long long N){
  std::string s = std::to_string(N);
  int digit = (int)s.size();
  return digit;
}

int make_num(int depth, long long Num){
  if(depth == 0){
    std::string num_str = std::to_string(Num);
    if((int)num_str.size()<=2){
      return 0;
    }
    bool check3 = std::any_of(num_str.begin(), num_str.end(), [](char c){return c == '3';});
    bool check5 = std::any_of(num_str.begin(), num_str.end(), [](char c){return c == '5';});
    bool check7 = std::any_of(num_str.begin(), num_str.end(), [](char c){return c == '7';});
    bool check0 = std::none_of(num_str.begin(), num_str.end(), [](char c){return c == '0';});
    if(check3 + check5 + check7 + check0 == 4){
      if(Num <= N){
		return 1;
      }else{
		return 0;
      }
    }else{
      return 0;
    }
  }
  int num3 = std::pow(10 ,depth - 1) * 3 + Num;
  int num5 = std::pow(10 ,depth - 1) * 5 + Num;
  int num7 = std::pow(10 ,depth - 1) * 7 + Num;
  int num0 = std::pow(10 ,depth - 1) * 0 + Num; 
  int init3 = make_num(depth - 1, num3);
  int init5 = make_num(depth - 1, num5);
  int init7 = make_num(depth - 1, num7);
  int init0 = make_num(depth - 1, num0);
  return init3 + init5 + init7 + init0;
}

int main(){
  std::cin >> N;
  int digit = GetDigit(N);
  if(digit <= 2){
    std::cout<< 0 << std::endl;
    return 0;
  }
  int num_753 = 0;
  num_753 += make_num(digit, 0);
  std::cout << num_753 << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	string s; cin >> s;

	for (int i = s.size() - 1; i >= 0; ) {
		if (s[i] == 'm') {
			if (s.substr(i - 4, 5) == "dream") {
				i -= 5;
			}
			else {
				cout << "NO" << endl;
				return 0;
			}
		}
		else if (s[i] == 'e') {
			if (s.substr(i - 4, 5) == "erase") {
				i -= 5;
			}
			else {
				cout << "NO" << endl;
				return 0;
			}
		}
		else if (s[i] == 'r') {
			if (s.substr(i - 5, 6) == "eraser") {
				i -= 6;
			}
			else if (s.substr(i - 6, 7) == "dreamer") {
				i -= 7;
			}
			else {
				cout << "NO" << endl;
				return 0;
			}
		}
		else {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<string>
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
const int maxn=5e5+100;
int f[maxn],fn[maxn],cnt[maxn],tot[maxn],ans[maxn],n,m,k;
void init(){
	for(int i=1;i<=n;i++){
		f[i]=i;
	}
}
int getf(int v){
	if(v==f[v]) return v;
	return f[v]=getf(f[v]);
}
void merge(int a,int b){
	int x=getf(a);
	int y=getf(b);
	if(x!=y) f[x]=y;
}
int main()
{
	cin>>n>>m>>k;
	init();
	for(int i=1;i<=m;i++){
		int a,b;
		cin>>a>>b;
		cnt[a]++; cnt[b]++;
		merge(a,b);
	}
	for(int i=1;i<=n;i++) f[i]=getf(i);
	for(int i=1;i<=n;i++) fn[f[i]]++;
	for(int i=1;i<=k;i++){
		int a,b; cin>>a>>b;
		if(f[a]==f[b]) tot[a]++,tot[b]++;
	}
	for(int i=1;i<=n;i++) ans[i]=fn[f[i]]-cnt[i]-tot[i]-1;
	for(int i=1;i<=n;i++) printf("%d%c",ans[i],i==n?'\n':' ');
    return 0;
 } 

Measured memory_bytes: 8064
#include <stdio.h>
 
int main(void) {
    int h, w;
    int i, j;
     
    while (scanf("%d %d", &h, &w), h || w) {
 
        for (i = 0; i < h; i++) {
            for (j = 0; j < w; j++) {
                putchar('#');
            }
            puts("");
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 2064
import sys, math
input= sys.stdin.readline

N = int(input())
A_lst = list(map(int, input().split()))
lst=[0]*(10**6+1)

# 割れる最大の素数を出す
for i in range(2, 10**6+1):
  if not lst[i]:
    for j in range(i, 10**6+1, i):
      lst[j] = i
      
# not coprimeか判定する
ans = 'not coprime'
GCD = A_lst[0]
for i in range(N):
  GCD = math.gcd(GCD, A_lst[i])
  
if GCD != 1:
  print(ans)
else:
  ans = 'setwise coprime'
  post = 1
  visited = [0]*(10**6+1)
  for i in range(N):
    a = A_lst[i]
    while a > 1:
      dv = lst[a]
      if visited[dv]:
        post = 0
        break
      while a % dv == 0:
        a //= dv
      visited[dv] = 1
  
  if post:
    ans = 'pairwise coprime'
  print(ans)


Measured memory_bytes: 127636
#include <iostream>
#include <tuple>
#include <vector>
#include <map>
#include <set>
#include <cinttypes>
#include <limits>
#include <stack>


namespace {
  int R, C, N;
  using edge_t = std::tuple<int, int, int>;
  std::map<std::tuple<int, int>, std::vector<edge_t>> G;

  void input() {
    std::cin >> R >> C;
    std::cin >> N;
    for (int i = 0; i < N; ++i) {
      int r, c, a;
      std::cin >> r >> c >> a;
      --r; --c;
      G[{0, r}].emplace_back(1, c, a);
      G[{1, c}].emplace_back(0, r, a);
    }

  }

  bool solve() {
    std::stack<std::tuple<int, int>> stack;
    std::map<std::tuple<int, int>, int> values;

    for (const auto &item : G) {
      const auto &v = item.first;
      if (values.find(v) != values.end()) {
        continue;
      }

      stack.push(v);
      values[v] = 0;
      while (!stack.empty()) {
        const auto v = stack.top(); stack.pop();
        for (const auto &edge : G[v]) {
          const int t = std::get<0>(edge);
          const int i = std::get<1>(edge);
          const int a = std::get<2>(edge);
          const auto w = std::make_tuple(t, i);

          if (values.find(w) != values.end()) continue;

          values[w] = a - values[v];
          stack.push(w);
        }
      }
    }

    // check contradiction
    for (const auto &item : G) {
      const auto &v = item.first;
      for (const auto &edge : item.second) {
        const int t = std::get<0>(edge);
        const int i = std::get<1>(edge);
        const int a = std::get<2>(edge);
        const auto w = std::make_tuple(t, i);
        if (values[v] + values[w] != a) {
          return false;
        }
      }
    }

    // check if we can set all elements to non-negative value
    std::set<std::tuple<int, int>> visited;
    for (const auto &item : G) {
      const auto &v = item.first;
      if (visited.find(v) != visited.end()) continue;

      std::int64_t min_0 = std::numeric_limits<std::int64_t>::max() / 3;
      std::int64_t min_1 = std::numeric_limits<std::int64_t>::max() / 3;

      stack.push(v);
      while (!stack.empty()) {
        const auto v = stack.top(); stack.pop();
        visited.insert(v);
        if (std::get<0>(v) == 0) {
          if (min_0 > values[v]) min_0 = values[v];
        } else {
          if (min_1 > values[v]) min_1 = values[v];
        }
        for (const auto &edge : G[v]) {
          const int t = std::get<0>(edge);
          const int i = std::get<1>(edge);
          const int a = std::get<2>(edge);
          const auto w = std::make_tuple(t, i);

          if (visited.find(w) != visited.end()) continue;
          stack.push(w);
        }
      }
      if (min_0 + min_1 < 0) return false;
    }

    return true;
  }
}


int main() {
  input();
  if (solve()) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 40832
while True:
	n = int(input())
	if n == 0:
	    break
	s = []
	u = 0
	v = 0
	s = list(map(int, input().split()))
	while True:
		t = []
		for i in range(n):
			for j in range(n):
				if s[i] == s[j]:
					u += 1
			t.append(u)
			t_str = list(map(str, t))
			u = 0
		if s == t:
			print(str(v))
			print(" ".join(t_str))
			break
		else:
			s = t
			v += 1

Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
#define MAXNUM 211111
#define rep(i,s,t) for(int i=s;i<t;i++)
int dp[MAXNUM][2];
char s[MAXNUM];
int main()
{
    scanf("%s",s+1);
    int n=strlen(s+1);
    dp[1][0]=1,dp[2][1]=1;
    if(s[2]!=s[1])dp[2][0]=2;
    rep(i,3,n+1)
    {
        if(s[i]!=s[i-1])dp[i][0]=max(dp[i-1][0]+1,dp[i][0]);
        dp[i][0]=max(dp[i][0],dp[i-1][1]+1);
        dp[i][1]=max(dp[i-2][0]+1,dp[i][1]);
        if(s[i]!=s[i-2]||s[i-1]!=s[i-3])dp[i][1]=max(dp[i][1],dp[i-2][1]+1);
    }
    printf("%d\n",max(dp[n][0],dp[n][1]));
}

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

const int LIM = 10000000;

int A[LIM + 7];

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

    for (int i=1; i<=LIM; i++)
        A[i] = 1;
    
    for (int i=2; i<=LIM; i++)
    {
        if (A[i] > 1)
            continue;
        
        for (int j=i; j<=LIM; j+= i)
        {
            int f = 0, x = j;

            while (x % i == 0)
                x /= i, f++;
            
            A[j] *= (f + 1);
        }
    }

    int n;
    cin >> n;

    long long ans = 0;

    for (int i=1; i<=n; i++)
        ans += 1LL * i * A[i];

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


Measured memory_bytes: 42704
def main(argv)
  (w, h, x, y) = gets.chomp.split(' ').map(&:to_i)
  
  s = (w * h).to_f / 2.0
  
  d = 0
  if (x.to_f == (w.to_f / 2.0)) && (y.to_f == (h.to_f / 2.0)) then
    d = 1
  end
  
  puts s.to_s + ' ' + d.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		if(n%k==0){
			System.out.println("0");
		}
		else{
			System.out.println("1");
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int dp[2001][2];

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

    int n, z[2];
    cin >> n >> z[0] >> z[1];

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

    // 手番、今までに何枚取ったか、でDP
    // 残りがi枚のとき、iがわかっていれば相手のカードは固定
    int t = abs(a[n - 1] - a[n - 2]); if (n == 1) t = abs(a[0] - z[1]);
    dp[n - 1][0] = dp[n - 1][1] = t;
    for (int i = n - 2; i >= 0; i--) {
        for (int j = 0; j < 2; j++) {
            int h = i - 1;
            int r = h < 0 ? z[j ^ 1] : a[h];
            int t = abs(r - a[n - 1]);
            for (int k = i; k < n - 1; k++) {
                int s = dp[k + 1][j ^ 1];
                if (j == 0) {
                    t = max(t, s);
                } else {
                    t = min(t, s);
                }
            }
            dp[i][j] = t;
        }
    }

    cout << dp[0][0] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100000

int partition(int *,int,int);
int main(){
  int A[N+1],n,i,t;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&A[i]);
  t=partition(A,1,n);
  for(i=1;i<t;i++)
    printf("%d ",A[i]);
  printf("[%d] ",A[t]);
  for(i=t+1;i<n;i++)
    printf("%d ",A[i]);
  printf("%d\n",A[n]);
  return 0;
}

int partition(int *A,int p,int r){
  int k,a,i,j;
  k=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=k){
      i++;
      a=A[i];
      A[i]=A[j];
      A[j]=a;
    }
  }
  a=A[i+1];
  A[i+1]=A[r];
  A[r]=a;
  return i+1;
}


Measured memory_bytes: 2160
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

typedef int type;
const type INIT = INT_MAX;

class segment_tree {
private:
	int n;
	vector<type> dat;

    inline type function(type a, type b) const {
		return min(a, b);
	}

	type query(int a, int b, int k, int l, int r) const {
		if(r <= a || b <= l)
			return INIT;

		if(a <= l && r <= b) {
			return dat[k];
		}
		else {
			const type vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			const type vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return function(vl, vr);
		}
	}

public:
	segment_tree(int n_) {
		n = 1;
		while(n < n_) n *= 2;
		dat.resize(2 * n - 1, INIT);
	}

	inline void update(int k, type a) {
		k += n - 1;
		dat[k] = a;

		while(k > 0) {
			k = (k - 1) / 2;
			dat[k] = function(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}

	inline type query(int a, int b) const {
		return query(a, b, 0, 0, n);
	}
};

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

	for(int r, c, q; cin >> r >> c >> q, r;) {
		bool is_row = (r <= c);
		vector<segment_tree> seg(min(r, c), segment_tree(max(r, c)));

		for(int i = 0; i < r; ++i) {
			for(int j = 0; j < c; ++j) {
				type in;
				cin >> in;

				if(is_row) seg[i].update(j, in);
				else seg[j].update(i, in);
			}
		}

		for(int i = 0; i < q; ++i) {
			int start, end, a, b;
			if(is_row) cin >> start >> a >> end >> b;
			else cin >> a >> start >> b >> end;
			++b;

			type ans = INIT;
			for(int j = start; j <= end; ++j) {
				chmin(ans, seg[j].query(a, b));
			}

			cout << ans << endl;
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 17484
n,k,q=map(int,input().split())
a=[] #正解者
p=[] #points
for i in range(0,q):
    a.append(int(input()))
for i in range(0,n):
    p.append(k-q)

for i in a:
    p[i-1] += 1

for i in p:
    if i <= 0:
        print('No')
    else:
        print('Yes')



Measured memory_bytes: 11784
#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 ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  cin >> a >> b;
  cout << max(a-2*b,0)<< endl;
}


Measured memory_bytes: 256
import math
Q=input()

a=[]
for i in range(Q):
	x,y=map(int, raw_input().split())
	if x<=y:
		A=x
		B=y
	else:
		A=y
		B=x
	a.append((x,y))


for A,B in a:
	C=int(math.sqrt(A*B))
	if C**2<A*B:
		pass
	else:
		C-=1
	if A==B:		print 2*A-2
	elif A+1==B:		print 2*A-2
	elif C*(C+1)>=A*B:	print 2*C-2
	else:			print 2*C-1

Measured memory_bytes: 2692
using System;
					
public class Program
{
	public static void Main()
	{
		//string w = Console.In.ReadLine();
		int n = int.Parse(Console.In.ReadLine());
		int k = int.Parse(Console.In.ReadLine());
		int x = int.Parse(Console.In.ReadLine());
		int y = int.Parse(Console.In.ReadLine());
		
		if(n>k)
			Console.WriteLine("{0}", x*k+y*(n-k));
		else
			Console.WriteLine("{0}", n*x);
	}
}

Measured memory_bytes: 2776
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <math.h>
#include <list>

using namespace std;

#define NIL -1
#define MAX 26

struct Node {
    int id;
    int parent;
    int left;
    int right;
};

Node T[MAX];

void preOrderTreeWalk(int u) {
    if (u == NIL) {
	return;
    }
    printf(" %d", u);
    preOrderTreeWalk(T[u].left);
    preOrderTreeWalk(T[u].right);
}

void inOrderTreeWalk(int u) {
    if (u == NIL) {
	return;
    }
    inOrderTreeWalk(T[u].left);
    printf(" %d", u);
    inOrderTreeWalk(T[u].right);
}

void postOrderTreeWalk(int u) {
    if (u == NIL) {
	return;
    }
    postOrderTreeWalk(T[u].left);
    postOrderTreeWalk(T[u].right);
    printf(" %d", u);
}

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

    int n; scanf("%d", &n);
    int id, left, right,root;

    for (int i = 0; i < n; i++) {
	T[i].id = i;
	T[i].parent = NIL;
    }
    for (int i = 0; i < n; i++) {
	scanf("%d %d %d", &id, &left, &right);
	T[id].left = left;
	T[id].right = right;
	if (T[id].left != NIL) {
	    T[T[id].left].parent = id;
	}
	if (T[id].right != NIL) {
	    T[T[id].right].parent = id;
	}
    }

    for (int i = 0; i < n; i++) {
	if (T[i].parent == NIL) {
	    root = i;
	}
    }

    printf("Preorder\n");
    preOrderTreeWalk(root); printf("\n");
    printf("Inorder\n");
    inOrderTreeWalk(root); printf("\n");
    printf("Postorder\n");
    postOrderTreeWalk(root); printf("\n");
}

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

int main(){
	int n; cin>>n;
	set<int> st;
	rep(i,n){
		int a; cin>>a;
		if(st.count(a)==1) st.erase(a);
		else st.insert(a);
	}
	cout<<st.size()<<endl;
}


Measured memory_bytes: 8088
#include <stdio.h>

int main(void)
{
	int N, A ,B;
	scanf("%d%d%d",&N, &A, &B);
	char s[N + 1];
	scanf("%s", s);
	int i = 0;
	int count = 0;
	int bcount = 0;
	while (s[i])
	{
		if (s[i] == 'a' || s[i] == 'b')
		{
			if (s[i] == 'a' && count < A + B)
			{
				printf("Yes\n");
				count++;
			}
			else if (s[i] == 'b' && count < A + B && bcount < B)
			{
				printf("Yes\n");
				bcount++;
				count++;
			}
			else
				printf("No\n");
		}
		else
			printf("No\n");
		i++;
	}
	return (0);
}

Measured memory_bytes: 640
N = int(input())
 
mes_dict = {}
for i in range(N):
  m = input()
  try:
    mes_dict[m] += 1
  except:
    mes_dict[m] = 1

ma =max(mes_dict.values())
answer = sorted([k for k, v in mes_dict.items() if v == ma])
for ans in answer:
  print(ans)

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


int main(){
    int n,m;
    cin >> n >> m;
    set<int> s;
    for(int i = 2;i<=sqrt(m);i++){
        if(m%i==0) {
            s.insert(i);
            s.insert(m/i);
        }
    }
    s.insert(m);

    int ans = 1;

    for(auto it = s.begin();it!=s.end();it++){
        if((*it)<=m/n) ans = *it;
        else break;
    }

    cout << ans << endl;

    //for(auto it=s.begin();it!=s.end();it++) cout << *it << endl;

 }

Measured memory_bytes: 3668
import java.util.*;
class Main{
    public static void main(String[]$){
        Scanner s=new Scanner(System.in);
        int f=s.nextInt(),t=s.nextInt(),k=s.nextInt();
        if(t-f>=k*2){
            for(int i=f;i<f+k;++i)
                System.out.println(i);
            for(int i=t-k+1;i<=t;++i)
                System.out.println(i);
        }else{
            for(int i=f;i<=t;++i)
                System.out.println(i);
        }
    }
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1e8;
typedef long long ll;
ll mod = 998244353;
long long fast_exp(long long a, long long b)
{
    if(b == 0)
	   return 1;
    else
    {
	   long long res = 1;
	   res = fast_exp(a,b/2);
	   res = (res*res)%mod;
	   if(b%2 == 1)
		  res = (res*a)%mod;
	   return res;
 
    }
}
const ll N = 1e6;




int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	
	long double w, h, x, y;
	cin>>w>>h>>x>>y;

	long double a = min(h*x, h*(w-x)) , b = min(w*y,w*(h-y));

	if(x == w/2 && y == h/2)
	{
		cout<<fixed<<setprecision(6)<<(h*w)/2<<' ';
	    cout<<1<<endl;
	}
	else
	{
		cout<<fixed<<setprecision(6)<<(h*w)/2<<' ';
	    cout<<0<<endl;
	}
	return 0;
	
}


Measured memory_bytes: 256
using System;
class gyakusu{
  public static void Main(){
    int n = int.Parse(Console.ReadLine());
    string[] s =  Console.ReadLine().Split(' ');
    double[] a = new double[n];
    double[] inverse = new double[n];
    double sum = 0;
    for (int i = 0; i<n; i++)
    {
      a[i]=double.Parse(s[i]);
      inverse[i]=1/a[i];
      sum+=inverse[i];
  }
  double answer = 1/sum;
  Console.WriteLine("{0}",answer);
}
}


Measured memory_bytes: 11092
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ITP1_10_B
{
    class Program
    {
        static void Main(string[] args)
        {
            // 三角形の2辺a、bとその挟む角Cが与えられる。
            // 三角形の面積S、周の長さL、aを底辺としたときの高さhを求めるプログラム

            double[] num = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
            double a = num[0];
            double b = num[1];
            double C = num[2] * Math.PI / 180;                                      //三角関数なのでラジアンを用いる

            // 三角形の高さhを求める
            // h = b sin C
            double h = b * Math.Sin(C);

            // 三角形の面積Sを求める
            double S = a * h / 2;

            // 三角形の周の長さLを求める
            // b cos C + (a-b) cos C+b +c(値の示されていない辺をcと置く)
            // c=√(a^2 + b^2 + 2ab cosC)
            double c = Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2) - 2 * a * b * (Math.Cos(C)));              
            double L = a+b+c;

            Console.WriteLine(S);
            Console.WriteLine(L);
            Console.WriteLine(h);
        }
    }
}



Measured memory_bytes: 18412
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(vector<string> C) {
  REP(i,3) {
    if (C[0][i] != C[1][2-i]) {
      cout << "NO" << endl;
      return;
    }
  }
  cout << "YES" << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	vector<string> C(2-1+1);
	for (int i = 0 ; i <= 2-1 ; i++) {
	  cin >> C[i];
	}
	solve(C);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int read(){
	int sum=0,f=1;
	char s=getchar();
	while (s<'0' or s>'9'){
		if (s=='-')f=-1;
		s=getchar();
	}
	while (s>='0' and s<='9'){
		sum=sum*10+s-'0';
		s=getchar();
	}
	return sum*f;
}
int n;
int main(){
	string s;
	cin>>s;
	bool flag=0;
	for (int i=0;i<s.size();i++){
		if (s[i]=='7'){
			flag=1;
			break;
		}
	}
	if (flag)cout<<"Yes";
	else cout<<"No";
	return 0;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll b,w,x[300000],y[300000],p[300000],c[300000],C[300000];
  cin >> b >> w;
  p[0]=1;
  rep(i,b+w+10){
    p[i+1]=p[i]*2%MOD;
  }
  rep(i,b+w+10){
    c[i]=0;
    C[i]=0;
     }
  c[b]=1;
  C[w]=1;
  FOR(i,b,b+w+10){
    c[i+1]=c[i]*(i+1)%MOD*modinv(i+1-b)%MOD;
  }
  FOR(i,w,b+w+10){
    C[i+1]=C[i]*(i+1)%MOD*modinv(i+1-w)%MOD;
  }
  FOR(i,1,b+w+1){
    if(i<=b)x[i]=0;
    else x[i]=(((x[i-1]*2%MOD-c[i-2]+c[i-1])%MOD)+10*MOD)%MOD;
    if(i<=w)y[i]=0;
    else y[i]=(((y[i-1]*2%MOD-C[i-2]+C[i-1])%MOD)+10*MOD)%MOD;
    printf("%lld\n",(((p[i-1]-x[i]+y[i])%MOD*modinv(p[i]))%MOD+10*MOD)%MOD);
  }    
}

Measured memory_bytes: 13184
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n-1):
  if i+1==p[i]:
    p[i], p[i+1] = p[i+1], p[i]
    ans += 1
if p[-1]==n:
  ans += 1
print(ans)

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

int main()
{
    int n;
    cin >> n;
    
    vector<int> a(n);
    vector<long long> p(300000,0),m(300000,0);
    int i,j,maxa = 0;
    long long ans = 0;
    for (i = 0; i < n; i++)
    {
        cin >> a[i];

        if(i - a[i] >= 0)ans += p[i - a[i]];
        if(i + a[i] <= n)ans += m[i + a[i]];
    
        if(i - a[i] >= 0)m[i - a[i]]++;
        if(i + a[i] <= n)p[i + a[i]]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(void){
    int N, K; cin >> N >> K;
    vector<ll> x(N), y(N);
    for(int i=0; i<N; i++) cin >> x[i] >> y[i];

    ll ans = (1LL<<62);
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            for(int k=0; k<N; k++){
                for(int l=0; l<N; l++){
                    ll x1 = x[i], x2 = x[j];
                    ll y1 = y[k], y2 = y[l];
                    int cnt = 0;
                    if(x2 <= x1 || y2 <= y1) continue;
                    for(int m=0; m<N; m++){
                        if(x1<=x[m] && x[m]<=x2 && y1<=y[m] && y[m]<=y2) cnt++;
                    }
                    if(cnt>=K) ans = min(ans, (x2-x1)*(y2-y1));
                }
            }
        }
    }

    cout << ans << endl;
}

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

// 得点pからゲームを開始して得点がkを超えるときにコインを振った回数
constexpr int winTimes(int p, int k)
{
    int count = 0;
    while (p < k)
    {
        p *= 2;
        count++;
    }
    return count;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(16);

    int n, k;
    cin >> n >> k;

    double ans = 0;

    for (int i = 1; i <= n; i++)
    {
        int flip = winTimes(i, k);
        double flip_p = pow(0.5, flip);
        ans += flip_p / n;
    }

    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, m, ans[maxn], range[maxn];
int Q, v[maxn], c[maxn], d[maxn];
int q[maxn], ql, qr;
vector<int> graph[maxn];

void bfs(int u, int d, int c) {
	if (range[u] >= d) {
		return;
	}
	ql = qr = 0;
	q[qr++] = u;
	range[u] = d;
	if (ans[u] == -1) {
		ans[u] = c;
	}

	while (qr - ql > 0) {
		int now = q[ql++];
		for (int i : graph[now]) {
			if (range[i] < range[now] - 1) {
				range[i] = range[now] - 1;
				if (ans[i] == -1) {
					ans[i] = c;
				}
				q[qr++] = i;
			}
		}
	}
}

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

	memset(ans, -1, sizeof(ans));
	memset(range, -1, sizeof(range));

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		graph[u].pb(v);
		graph[v].pb(u);
	}

	cin >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> v[i] >> d[i] >> c[i];
		v[i]--;
	}

	for (int i = Q - 1; i >= 0; i--) {
		bfs(v[i], d[i], c[i]);
	}

	for (int i = 0; i < n; i++) {
		cout << (ans[i] == -1 ? 0 : ans[i]) << endl;
	}
}



Measured memory_bytes: 11472
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  int total = 0;
  for (int i = A; i <= B; i++){
    if ((i / 10000 == i % 10)){
      if ((i % 10000)/1000 == (i % 100)/10){
        total += 1;
      }
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    long long k;
    cin >> n >> k;
    vector<long long>v(n + 3);
    for(int i = 1; i <= n; i++){
        cin >> v[i];
    }
    long long lo = 1, hi = 1e12;
    while(hi - lo >= 3){
        long long mid = (lo + hi)/2;
        long long cnt = 0;
        for(int i = 1; i <= n; i++){
            cnt = cnt + (v[i] - 1)/mid;
        }
        if(cnt <= k){
            hi = mid;
        }
        else{
            lo = mid;
        }
    }
    for(long long mid = lo; mid <= hi; mid++){
        long long cnt = 0;
        for(int i = 1; i <= n; i++){
            cnt = cnt + (v[i] - 1)/mid;
        }
        if(cnt <= k){
            cout << mid;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 4728
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(void)
{
	char s[200];
	char L='L';
	char R='R';
	char U='U';
	char D='D';
	int i, x;
	x=0;
	scanf("%s", s);
	for(i=0;i<strlen(s);i++){
		if(i%2==0 && s[i]==L){
			x=1;
		}
		else if(i%2==1 && s[i]==R){
			x=1;
		}
	}

	if(x==1){
		printf("No");	
	}

	else{
		printf("Yes");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  cin>>A>>B>>C;
  int Y=max(A,max(B,C));
  int X=Y*3-(A+B+C);
  if(X%2==1){
    cout<<X/2+2<<endl;
  }
  else{
    cout<<X/2<<endl;
  }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define pb push_back
#define all(v) (v).begin(), (v).end()
const int M=1e6+7;

ll get(ll l, ll r, ll a)
{
     ll j=l/a*a,k=r/a*a;
 ll cnt1=0;
 while(j<l) j+=a;
 cnt1+=max(0ll,(k-j)/a+1);
 return cnt1;
}
int main() {
    
 ll l,r,a,b;
 cin>>l>>r>>a>>b;
    cout<<r-l+1-(get(l,r,a)+get(l,r,b)-get(l,r,a/__gcd(a,b)*b));

}



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

typedef long long ll;
typedef pair<int,int> pri;
const int INF = 1e9 + 7;
const ll LINF = 1LL<<61;

int n;
int ans = 0;
int main(){
  cin >> n;
  vector<int> p(n,0);
  vector<int> q(n,0);
  int t = INF;
  for(int i = 0; i < n; i++){
    cin >> p[i];
    t = min(t,p[i]);
    q[i] = t;
  }
  for(int i = 0; i < n; i++){
    if(p[i] <= q[i]){
      ans++;
    }
  }
  cout << ans << endl;
}


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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			int[] arr1 = Console.ReadLine().Trim().Split(' ').Select(hogehoge => int.Parse(hogehoge)).ToArray<int>();

			int[] arr2 = Console.ReadLine().Trim().Split(' ').Select(hogehoge => int.Parse(hogehoge)).ToArray<int>();

			int[] arr3 = Console.ReadLine().Trim().Split(' ').Select(hogehoge => int.Parse(hogehoge)).ToArray<int>();

			int n = int.Parse(Console.ReadLine());


			for (int i = 0; i < n; i++)
			{
				bool flg = false;
				int num = int.Parse(Console.ReadLine()); 

				for (int j = 0; j < 3; j++)
				{
					if (num == arr1[j])
					{
						arr1[j] = 0;
						flg = true;
						break;
					} 
				}

				if (flg) continue;

				for (int j = 0; j < 3; j++)
				{
					if (num == arr2[j])
					{
						arr2[j] = 0;
						flg = true;
						break;
					}
				}

				if (flg) continue;

				for (int j = 0; j < 3; j++)
				{
					if (num == arr3[j])
					{
						arr3[j] = 0;
						flg = true;
						break;
					}
				}

			}

			if (arr1[0] + arr1[1] + arr1[2] == 0)
			{
				Console.WriteLine("Yes");
				return;
			}

			if (arr2[0] + arr2[1] + arr2[2] == 0)
			{
				Console.WriteLine("Yes");
				return;
			}

			if (arr3[0] + arr3[1] + arr3[2] == 0)
			{
				Console.WriteLine("Yes");
				return;
			}


			if (arr1[0] + arr2[0] + arr3[0] == 0)
			{
				Console.WriteLine("Yes");
				return;
			}

			if (arr1[1] + arr2[1] + arr3[1] == 0)
			{
				Console.WriteLine("Yes");
				return;
			}

			if (arr1[2] + arr2[2] + arr3[2] == 0)
			{
				Console.WriteLine("Yes");
				return;
			}


			if (arr1[0] + arr2[1] + arr3[2] == 0)
			{
				Console.WriteLine("Yes");
				return;
			}

			if (arr3[0] + arr2[1] + arr1[2] == 0)
			{
				Console.WriteLine("Yes");
				return;
			}

			Console.WriteLine("No");

		}


	}


}


Measured memory_bytes: 13396
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

// 5 4 3 2  1
// 0 5 9 12 14 15

void solve() {
  ll N, M, V, P;
  cin >> N >> M >> V >> P;
  vector<ll> A(N);
  rep (i, N) cin >> A[i];
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  vector<ll> accum(N + 1);
  accum[0] = 0;
  rep (i, N) {
    accum[i + 1] = accum[i] + A[i];
  }
  if (V <= P) {
    ll ans = 0;
    ll border_score = A[P-1];
    for (auto it: A) if (it + M >= border_score) ans++;
    cout << ans << endl;
    return;
  }
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    if (i <= P-1) {
      cerr << "add A: " << i << endl;
      ans ++;
      continue;
    }
    ll current = A[i] + M;
    cerr << "current:" << current << ", A[P-1]:" << A[P-1] << endl;
    if (current < A[P-1]) continue;
    ll votes = M * (V - P);
    cerr << "votes:" << votes << endl;
    votes -= (N-i-1) * M;
    cerr << "- votes:" << votes << endl;
    ll existing = accum[i] - accum[P-1];
    ll border = (current * (i - (P - 1))) - existing;
    cerr << "existing:" << existing << ", border:" << border << endl;
    if (votes <= border) {
      ans ++;
      continue;
    }
  }
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


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

int main()
{
    string S;
    cin >> S;
    vector<int> nearestR(S.size(), -1), nearestL(S.size(), S.size() + 1);
    rep(i, S.size())
    {
        if (S[i] == 'R')
            nearestR[i] = i;
        else
            nearestL[i] = i;
    }
    rep(i, S.size() - 1)
    {
        nearestR[i + 1] = max(nearestR[i + 1], nearestR[i]);
        nearestL[S.size() - 2 - i] = min(nearestL[S.size() - 2 - i], nearestL[S.size() - 1 - i]);
    }

    vector<int> ans(S.size());
    rep(i, S.size())
    {
        if (S[i] == 'R')
        {
            if (abs(nearestL[i] - i) % 2 == 0)
                ans[nearestL[i]]++;
            else
                ans[nearestL[i] - 1]++;
        }
        else
        {
            if (abs(nearestR[i] - i) % 2 == 0)
                ans[nearestR[i]]++;
            else
                ans[nearestR[i] + 1]++;
        }
    }
    rep(i, S.size())
    {
        cout << ans[i] << " ";
    }
    cout << endl;
}

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

const ll INF = 1LL << 60;

ll A, B, C, X;
int main() {
    cin >> A >> B >> C >> X;

    ll ans = 0;
    // 500 円 Aまい
    for (int i = 0; i <= A; i++) {
        for (int j = 0; j <= B; j++) {
            for (int k = 0; k <= C; k++) {
                if (X == i * 500 + j * 100 + k * 50) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256