akhauriyash/Code-Regression huggingface dataset:
// Contest: AtCoder Beginner Contest 177 (https://atcoder.jp/contests/abc177)
// Problem: D: Friends (https://atcoder.jp/contests/abc177/tasks/abc177_d)


// region boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion

namespace snippets_dsu {
    struct DSU {
        vi p;
        explicit DSU(int n) : p(n, -1) {}

        int find(int i) { return p[i] < 0 ? i : p[i] = find(p[i]); }
        bool same(int i, int j) { return find(i) == find(j); }
        int size(int i) { return -p[find(i)]; }
        bool join(int i, int j) {
            i = find(i), j = find(j);
            if (i == j) return false;
            if (p[i] > p[j]) swap(i, j);
            p[i] += p[j], p[j] = i;
            return true;
        }
    };
} using namespace snippets_dsu;

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

    int n, m; cin >> n >> m;
    DSU d(n);
    rep(i, m) {
        int a, b; cin >> a >> b; --a, --b;
        d.join(a, b);
    }

    int mx = 0;
    rep(i, n)
        mx = max(mx, d.size(i));
    cout << mx << '\n';

    return 0;
}


Measured memory_bytes: 4028
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto a = readln.chomp.split.to!(long[]);
  auto l = 0;
  auto r = n - 1;
  long ls, rs;
  while (l <= r) {
    if (ls <= rs) {
      ls += a[l];
      l++;
    } else if (rs < ls) {
      rs += a[r];
      r--;
    }
  }
  abs(ls - rs).to!long.writeln;
}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    int w[n+1];
    for(int i=1;i<=n;i++){
        cin >> w[i];
    }
    int sumw[n+1];
    sumw[0] = 0;
    for(int i=1;i<=n;i++){
        sumw[i] = sumw[i-1] + w[i];
    }

    int ans = MOD;
    for(int p=1;p<=n-1;p++){
        ans = min(abs(sumw[p] - (sumw[n] - sumw[p])), ans);
    }
    cout << ans << endl;
}


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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

long long N, K;
vector<long long> A;

bool isOK(long long mid) {
    long long k = 0;
    for (int i = 0; i < N; i++) {
        k += (A[i] - 1) / mid;
    }
    if (k <= K) return true;
    else return false;
}

void solve() {
    cin >> N >> K;
    A.resize(N);
    long long ma = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        ma = max(ma, A[i]);
    }

    long long ok = ma;
    long long ng = 0;
 
    while (abs(ok - ng) > 1) {
        long long mid = (ok + ng) / 2;
        if (isOK(mid)) ok = mid;
        else ng = mid;
    }

    cout << ok << '\n';
}

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

    solve();

    return 0;
}

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

struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n, -1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y){
        x = find(x); y = find(y);
        if(x == y) return false;
        if(d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
};

int main(){
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    int a, b;
    rep(i, m){
        cin >> a >> b;
        a--; b--;
        uf.unite(a, b);
    }
    int ans = 0;
    rep(i, n) {
        ans = max(ans, uf.size(i));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3996
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s1 = sc.next();
		String s2 = sc.next();
		String s3 = sc.next();
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (s1.charAt(i) == s2.charAt(i)) {
				if (s2.charAt(i) != s3.charAt(i)) {
					count++;
				}
			} else {
				if (s2.charAt(i) == s3.charAt(i)) {
					count++;
				} else if (s1.charAt(i) == s3.charAt(i)){
					count++;
				} else {
					count += 2;
				}
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 23636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
const ll mod = 1e9+7;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6+5;
const ll N = 1e3+5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;

int main(){
    ll r;
    cin>>r;
    printf("%.20lf\n",2*r*pi);
}


Measured memory_bytes: 3764
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

using namespace std;

int vs[15][15];

int main(void) {
  int n, d;
  cin >> n >> d;
  REP(i, n) REP(j, d) {
    cin >> vs[i][j];
  }
  int res = 0;
  REP(i, n) REP(j, i) {
    int dist = 0;
    REP(k, d) {
      dist += (vs[i][k] - vs[j][k]) * (vs[i][k] - vs[j][k]);
    }
    int t = round(sqrt(dist));
    if(t*t == dist) {
      ++res;
    }
  }
  cout << res << endl;
  return 0;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  if((a%2)&&(b%2)) cout << "Odd" << endl;
  else cout << "Even" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		int fee = x * Math.min(n, k);
		if (n > k) fee += y * (n - k);
		
		System.out.println(fee);
		
		sc.close();
	}
}



Measured memory_bytes: 27040
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    string N;
    cin >> N;
    LL ans = 0;
    FORE(e, N) ans += e - '0';
    chmax(ans, (LL)((N[0] - 1 - '0') + 9 * N.size() - 9));
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main()
	{
		int N = GetInt();
		long K = GetLong();
		long[] A = Enumerable.Repeat(1, N).Select(_ => GetLong()).ToArray();
		long G = A[0];
		for(int i = 1; i < N; i++)
			G = gcd(G, A[i]);
		long M = A.Max();
		Console.WriteLine(((K <= M) && (K % G == 0)) ? "POSSIBLE" : "IMPOSSIBLE");
	}
	
	private static long gcd(long x, long y)
	{
		return (y == 0) ? x : gcd(y, x % y);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 26720
import sys

message = str(input())

for c in message:
	order = ord(c)
	if order >= 65 and order <= 90:
		sys.stdout.write(chr(order + 32))
	elif order >= 97 and order <= 122:
		sys.stdout.write(chr(order - 32))
	else:
		sys.stdout.write(c)
print()


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

using namespace std;

#define MAX (1<<19)
#define INF INT_MAX

class RMQ{
public:
  int N,dat[2*MAX-1];

  void init(int n){
    N = 1;
    while(N < n) N *= 2;
    for(int i = 0 ; i < 2*N-1 ; i++){
      dat[i] = INF;
    }
  }

  void update(int i,int x){
    i += N-1; dat[i] = x; 
    while(i > 0){
      i = (i-1) / 2;
      dat[i] = min(dat[2*i+1],dat[2*i+2]);
    }
  }

  int find(int s,int t,int k,int l,int r){
    if(r <= s || t <= l) return INF;
    if(s <= l && r <= t) return dat[k];
    return min(find(s,t,2*k+1,l,(l+r)/2),find(s,t,2*k+2,(l+r)/2,r));
  }
};

int main(){
  int N,Q,com,x,y;
  RMQ rmq;

  cin >> N >> Q;
  rmq.init(N); 
  while(Q--){
    cin >> com >> x >> y;
    if(com == 0){
      rmq.update(x,y);
    }else{
      cout << rmq.find(x,y+1,0,0,rmq.N) << endl;
    }
  }

  return 0;
}

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

class BIT:
    def __init__(self, size):
        self.bit = [0] * (size + 1)
        self.size = size

    def sum(self, i):
        i += 1
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.bit[i] += x
            i += i & -i

    def lower_bound(self, x):
        if x <= 0:
            return 0
        k = 1
        while k * 2 <= self.size:
            k *= 2
        j = 0
        while k > 0:
            if j + k <= self.size and self.bit[j + k] < x:
                x -= self.bit[j + k]
                j += k
            k //= 2
        return j

N, Q = map(int, input().split())
c = [0] + list(map(int, input().split()))
queries = [list(map(int, input().split())) + [i] for i in range(Q)]
queries.sort(key=lambda q: q[1])
last = [-1] * (N+1)
ans = [0] * Q
bit = BIT(N + 1)
j = 0
for l, r, i in queries:
    while j < r:
        j += 1
        if last[c[j]] != -1:
            bit.add(last[c[j]], -1)
        bit.add(j, 1)
        last[c[j]] = j
    ans[i] = bit.sum(r) - bit.sum(l - 1)
print(*ans, sep='\n')


Measured memory_bytes: 199488
#include <bits/stdc++.h>
#define MAXN 100005
using namespace std;
int bit[MAXN];
int n;

void add(int s,int t,int x) {
  while (t) {
    bit[t]+=x;
    t-=t&(-t);
  }
  s--;
  while (s) {
    bit[s]+=(-x);
    s-=s&(-s);
  }
}
int get(int i) {
  int ans=0;
  while (i<=n) {
    ans+=bit[i];
    i+=i&(-i);
  }
  return ans;
}
int main() {
  int q;
  cin >> n >> q;
  while (q--) {
    int f;
    cin >> f;
    if (f==0) {
      int s, t, x;
      cin >> s >> t >> x;
      add(s,t,x);
    } else {
      int i;
      cin >> i;
      printf("%d\n",get(i));
    }
  }
  return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	int r, D;
	vector<int> x(11);
	cin >> r >> D >> x[0];
	for (int i = 0; i < 10; i++) {
		x[i + 1] = r * x[i] - D;
		cout << x[i + 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if(s.equals("SUN")) {
			System.out.println(7);
		}else if(s.equals("MON")) {
			System.out.println(6);
		}else if(s.equals("TUE")) {
			System.out.println(5);
		}else if(s.equals("WED")) {
			System.out.println(4);
		}else if(s.equals("THU")) {
			System.out.println(3);
		}else if(s.equals("FRI")) {
			System.out.println(2);
		}else{
			System.out.println(1);
		}
		sc.close();
	}
}


Measured memory_bytes: 23252
#include<cstdio>
using namespace std;

int main(){
    int a,b = 0;
    scanf("%d",&a);
    scanf("%d",&b);

    if(a < b){
        printf("a < b\n");
    }else if(a == b){
        printf("a == b\n");
    }else{
        printf("a > b\n");
    }
}

Measured memory_bytes: 1012
import sys
from collections import deque
s=sys.stdin.readlines()
q=int(s[0].split()[1])
f=lambda x,y:(x,int(y))
d=deque(f(*e.split())for e in s[1:])
t=0
while d:
 k,v=d.popleft()
 if v>q:v-=q;t+=q;d.append([k,v])
 else:t+=v;print(k,t)


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

struct POINT{
	double x,y;
};

double area(double a,double b,double c){
	double s;

	s = (a+b+c)/2.0;

	return sqrt(s*(s-a)*(s-b)*(s-c));
}

int main(){
	int h,i,j,k,l,n,cnt;
	int flag[100];
	double len[6],s[4];
	struct POINT p[4];
	struct POINT pin[100];

	while(1){
		scanf("%d",&n);
		if(!n){
			break;
		}
		for(i = 0;i < n;i++){
			scanf("%lf,%lf",&pin[i].x,&pin[i].y);
		}

		memset(flag,0,sizeof(flag));

		for(i = 0;i < n;i++){
			if(flag[i]){
				continue;
			}
			p[0] = pin[i];
			for(j = 0;j < n;j++){
				if(i == j || flag[j]){
					continue;
				}
				p[1] = pin[j];
				for(k = 0;k < n;k++){
					if(i == k || j == k || flag[k]){
						continue;
					}
					p[2] = pin[k];
					for(h = 0;h < 3;h++){
							len[h] = sqrt(pow(p[(h+1)%3].x-p[h].x,2)+pow(p[(h+1)%3].y-p[h].y,2));
					}
					s[3] = area(len[0],len[1],len[2]);
					for(l = 0;l < n;l++){
						if(i == l || j == l || k == l || flag[l]){
							continue;
						}
						p[3] = pin[l];
						for(h = 0;h < 3;h++){
							len[3+h] = sqrt(pow(p[3].x-p[h].x,2)+pow(p[3].y-p[h].y,2));
						}
						for(h = 0;h < 3;h++){
							s[h] = area(len[h],len[3+h],len[(h+1)%3+3]);
						}
						if(fabs(s[3]-s[0]-s[1]-s[2])/(s[0]+s[1]+s[2]) < 1e-5){
							flag[l] = 1;
						}
					}
				}
			}
		}

		cnt = 0;
		for(i = 0;i < n;i++){
			if(flag[i]){
				cnt++;
			}
		}

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

	return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;

map<VI,int> mp;

void Rev(int l,int r,vector<int> &v){
  for(int i=0;i<=10;i++){
    if(l+i>=r-i)break;
    swap(v[l+i],v[r-i]);
  }
  return;
}

void bfs(vector<int> v,int depth){
  if(depth>=4)return;
  for(int i=0;i<v.size();i++){
    for(int j=i+1;j<v.size();j++){
      vector<int>v1;
      v1 = v;
      Rev(i,j,v1);
      if(mp[v1]!=0){
        if(mp[v1]>depth){
          mp[v1] = depth;
          bfs(v1,depth+1);
        }
      }else if(mp[v1]==0){
        mp[v1] = depth;
        bfs(v1,depth+1);
      }
    }
  }
  return;
}

void bfs2(vector<int> v,int depth,int &ans){
  if(depth>=4)return;
  for(int i=0;i<v.size();i++){
    for(int j=i+1;j<v.size();j++){
      vector<int>v1;
      v1 = v;
      Rev(i,j,v1);
      if(mp[v1]!=0){
        ans = min(ans,mp[v1]+depth);

      }else if(mp[v1]==0){
        bfs2(v1,depth+1,ans);
      }
    }
  }
  return;
}



int main(){
  int n;
  cin >>n;
  VI a(n);
  rep(i,n)cin>>a[i];
  mp[a]=0;
  bfs(a,1);
  VI b(n);
  rep(i,n)b[i]=i+1;
  if(a==b){
    cout << 0 << endl;
    return 0;
  }
  int ans = 10000;
  if(mp[b]!=0){
    ans = mp[b];
  }
  bfs2(b,1,ans);
  if(ans==10000){
    cout << n-1 << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 9644
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int L = scan.nextInt();

		BigDecimal a = new BigDecimal(String.valueOf(L));
		BigDecimal div = new BigDecimal("3.0");
		a = a.divide(div, 8, RoundingMode.DOWN);
		
		BigDecimal length = new BigDecimal(String.valueOf(a));
		BigDecimal ans = length.multiply(length);
		ans = ans.multiply(length);
		
		System.out.print(ans);
	}

}


Measured memory_bytes: 35912
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<algorithm>

using namespace std;

int main(void) {
    int price, k;
    map<int, bool> hate_num;
    vector<int> like_num;
    cin >> price >> k;
    for (int i = 0; i < k; ++i) {
        int t;
        cin >> t;
        hate_num[t] = true;
    }
    for (int i = 0; i < 10; i++) {
        if (!hate_num[i]) {
            like_num.push_back(i);
        }
    }

    for (int p = 1; p <= 99999; ++p) {
        if (p >= price) {
            string p_str = to_string(p);
            bool is_like = true;
            for (int i = 0; i < p_str.length(); ++i) {
                if (hate_num[p_str[i] - '0']) {
                    is_like = false;
                    break;
                }
            }
            if (is_like) {
                cout << p << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
N,A,B = map(int,input().split())
con = 0
for i in range(1 , N + 1):
  a1 = i // 10000
  a2 = (i - a1 * 10000)// 1000
  a3 = (i - a1 * 10000 - a2 * 1000)// 100
  a4 = (i - a1 * 10000 - a2 * 1000 - a3 * 100) // 10
  a5 = i % 10
  if A <= a1 + a2+ a3 + a4 + a5 <= B:
    con += i
print(con)

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	reverse(all(a));
	ll ans = 0;
	int p = 0;
	rep(i, n) {
		if (i==0) continue;
		if(i%2==0) p++;
		ans += a[p];
		// cout << a[p] << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4052
IDENTIFICATION DIVISION.
       PROGRAM-ID. test1.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 A PICTURE 999.
       01 B PICTURE 999.
       01 REN PICTURE 9999.
       01 RE PIC Z(4).
       PROCEDURE DIVISION.
       MAIN.
        ACCEPT A.
        ADD 1 TO A GIVING B.
        COMPUTE REN=A*B/2.
        MOVE REN TO RE.
        DISPLAY RE.
        STOP RUN.

Measured memory_bytes: 636
N,M=map(int,input().split())

H=[0]+list(map(int,input().split()))
L=[[]for i in range(N+1)]

for i in range(M):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)
ans=0
for i in range(1,N+1):
    F=1
    for j in L[i]:
        if H[i]<=H[j]:
            F=0
    if F==1:
        ans+=1
print(ans)

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

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

    sort(d.begin(), d.end());

    int res = 0;
    for (int i = 1; i <= 100000; i++) {
        int t = (int)(lower_bound(d.begin(), d.end(), i) - d.begin());
        if (t == N / 2) res++;
    }
    cout << res << endl;
    return 0;
}

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

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

nodeS = [0 for i in range(N+1)]
nodeS[0] = 1
laS = [0 for i in range(N+1)]
laS[-1] = A[-1]

for i in range(N):
    laS[-2-i] = A[-2-i] + laS[-1-i]
    nodeS[i+1] = min(10**18,(nodeS[i]-A[i])*2)

for i in range(N+1):
    if nodeS[i] <= 0:
        print(-1)
        exit()

for i in range(N+1):
    if nodeS[i] >= laS[i]:
        break
    if i == N:
        print(-1)
        exit()

print(sum(nodeS[:i]) + sum(laS[i:]))


Measured memory_bytes: 672296
#include<iostream>
#include<algorithm>
#include<cstring>
#include<numeric>
#include<vector>
using namespace std;

#define int long long

#ifdef lioraju
	#define ndbg(x) 
#else
	#define ndbg(x) x
#endif

const int mxsz = 100 + 5;
const int mxV = 1e5 + 5;

int w[mxsz], v[mxsz];

int dp[mxsz][mxV];
bool vis[mxsz][mxV];

int d(int n, int V)
{
	if (V<=0) return 0;
	if (n<0) return 2e9;
	if (vis[n][V]) return dp[n][V];
	
	vis[n][V] = 1;
	int mnn = min(d(n-1, V), d(n-1, V-v[n])+w[n]);
	
	return dp[n][V] = mnn;
}

signed main()
{
	ndbg( ios::sync_with_stdio(0); cin.tie(0); );
	int n, W; cin>>n>>W;
	for (int i=0;i<n;i++) cin>>w[i]>>v[i];
	
	int ans = 0;
	while (ans+1<mxV && d(n-1, ans+1) <= W) ans++;
	cout<<ans<<'\n';
}

Measured memory_bytes: 90368
#include<iostream>
using namespace std;
int main()
{
    int A[100];
    int N;
    int num = 0;
    int minj;
    cin >> N;
    for(int i=0; i<N; i++)
        cin >> A[i];
    for(int i=0; i<N-1;i++)
    {
        minj = i;
        for(int j=i+1; j<N; j++)
        {
            if(A[j] < A[minj])
            {
             //   min = A[j];
                minj = j;
            }
        }
        if(minj != i)
        {
            int temp = A[i];
            A[i] = A[minj];
            A[minj] = temp;
            num++;
        }
        
    }
    for(int i=0; i<N; i++)
    {
        if(i) cout<<" ";
        cout<<A[i];
    }
    cout<<endl<<num<<endl;
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  ll N;
  scanf("%lld", &N);

  vector<tuple<ll, ll, ll>> list(N);
  for (ll i = 0; i < N; i++) {
    ll x, l;
    scanf("%lld %lld", &x, &l);

    ll c = x + l;

    list[i] = make_tuple(c, x, l);
    // cout << get<0>(list[i]) << endl;
  }
  sort(list.begin(), list.end());

  ll removed = 0;

  ll right = get<1>(list[0]) + get<2>(list[0]);

  for (ll i = 1; i < N; i++) {
    ll x = get<1>(list[i]);
    ll l = get<2>(list[i]);

    if (x - l >= right) {
      right = x + l;
    } else {
      removed++;
    }
  }

  cout << (N - removed) << endl;
}


Measured memory_bytes: 2688
n = int(input())
arr = list(map(int,input().split()))

tarr = list(arr)

tarr.sort()

num1 = tarr[len(tarr) // 2 - 1]
num2 = tarr[len(tarr) // 2]

for i in range(n):
    if arr[i] < num2:
        print(num2)
    else:
        print(num1)

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod =1000000007;




int main() {
	ll r, d, x;
	cin >> r >> d >> x;
	REP(i, 10) {
		x = r * x - d;
		cout << x << endl;
	}

}



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

typedef long long ll;
typedef unsigned long long ull;

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

  vector<ll> v(n, 0);
  for (ll i = 0; i < n; ++i) {
    cin >> v[i];
  }
  vector<ll> c(n, 0);
  for (ll i = 0; i < n; ++i) {
    cin >> c[i];
  }

  ll ans = 0;
  for (ll i = 0; i < n; ++i) {
    if (v[i] > c[i]) {
      ans += v[i]-c[i];
    }
  }

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <string>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
using namespace std;

#define LSB(x) ((x) & -(x))
const int MAXN = 300000;

struct BIT
{
	vector<int> tree;
	
	BIT() : tree(MAXN + 1) {}
	
	void upd(int idx, int delta)
	{
		for (int i = idx; i <= MAXN; i += LSB(i))
			tree[i] += delta;
	}
	
	int qry(int idx)
	{
		int ret = 0;
		
		for (int i = idx; i != 0; i -= LSB(i))
			ret += tree[i];
		
		return ret;
	}
} fw1, fw2;

int get_ans(int k, int l, int r)
{
	while (r - l != 1)
	{
		int m = l + r >> 1;
		
		int tmp = fw2.qry(m) + m * (fw1.qry(MAXN) - fw1.qry(m));
		
		if (k * m <= tmp)
			l = m;
		else
			r = m;
	}
	
	return l;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	vector<int> arr(n);
	for (int i = 0; i != n; ++i)
		cin >> arr[i];
	sort(arr.begin(), arr.end());
	
	vector<int> counts;
	int cnt = 1;
	for (int i = 1; i != n; ++i)
	{
		if (arr[i] != arr[i - 1])
		{
			counts.push_back(cnt);
			cnt = 1;
		}
		else
			cnt++;
	}
	counts.push_back(cnt);
	
	for (int i = 0; i != counts.size(); ++i)
	{
		fw1.upd(counts[i], 1);
		fw2.upd(counts[i], counts[i]);
	}
	
	for (int i = 1; i <= n; ++i)
		cout << get_ans(i, 0, n / i + 1) << '\n';
	
	return 0;
}


Measured memory_bytes: 5876
#include<iostream>

using namespace std;

int main() {
	int N;
	string S;
	cin >> N >> S;

	if (N % 2 == 0) {
		//偶数のとき
		for (int i = 0; i < N / 2; i++) {
			if (S[i]!=S[i+N/2]) {
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
	}
	else {
		//奇数の時
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;


int main(){
    ull n, sum = 0, q;
    cin >> n;
    vector<ull> a(100001);
    fill(a.begin(), a.end(), 0);
    for(int i = 0; i < n; i++){
        int y;
        cin >> y;
        sum += y;
        a.at(y)++;
    }
    cin >> q;
    for(int i = 0; i < q; i++){
        int b, c;
        cin >> b >> c;
        ull count = a.at(b);
        a.at(b) = 0;
        sum += (c - b) * count;
        a.at(c) += count;
        cout << sum << endl;
    }
}

Measured memory_bytes: 4044
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
	#define ld long double
 	#define lb lower_bound 
	#define ub upper_bound
	#define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define mi          map<int,int>
	#define mii         map<pi,int>
	#define vi vector<int> 
	#define vvi vector<vi>
	#define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
	#define all(c) (c).begin(),(c).end()
	#define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
	
	 const int N =3e5+5;
	 const int lg=20;
	
	 int mod= 1e9+7;
	 int dx[4]={0,0,+1,-1};
	 int dy[4]={+1,-1,0,0};  
	 
	 
	int po(int a, int b) {
		a %= mod;
		int res = 1;
		while (b > 0) {
			if (b & 1)
				res = (res * a) % mod;
			a =(a*a) % mod;
			b >>= 1;
		}
		 return res;	
	   }
	   


void solve() {
	   int a,b;
	   cin>>a>>b;
	   cout<<a*b<<endl;      
	}
 
int32_t main() {
	cool;
	int t=1;	
	   //~ cin>>t;
	while(t--)
	   solve();		   
	   
	   return 0;	   
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,ans,k;
const ll mod=1e9+7;
int main()
{
	cin>>n>>k;
	for(ll i=k;i<=n+1;i++)
	{
		ll l=(0+i-1)*i/2;
		ll r=(n-i+1+n)*i/2;
		ans=(ans+r-l+1)%mod;
	}
	cout<<ans;
return 0;
}


Measured memory_bytes: 3584
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int n;

  cin >> n;
  lll sum = 0;
  for(ii=1;ii<=n;ii++){
    if((ii % 3 == 0) &&
       (ii % 5 == 0)){

    }
    else if(ii % 3 == 0){

    }
    else if(ii % 5 == 0){

    }
    else{
      sum += ii;
    }

  }

  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <string>
#include <string.h>
#include <cmath>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#define pi 3.1415926535
#define INF 0x3f3f3f3f
using namespace std;
typedef	long long ll;
ll n, m, i, j, k, h, t, maxn, ttt, t1, t2, sig = 0, l, d;

int main()
{
	cin >> n >> m >> k;
	if (n == m && m == k)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


class Edge{
	public:
	int t;
	int w;
	Edge(){}
	Edge(int t, int w) : t(t),w(w){}
};

int n;
static const int MAX = 100000;
vector<Edge> G[MAX];
bool vis[MAX];
int d[MAX];
static const int INFTY = (1<<30);

void bfs(int s){
	rep(i,n) d[i] = INFTY;
	queue<int> q;
	q.push(s);
	d[s] = 0;
	while(!q.empty()){
		int u = q.front();
		q.pop();
		rep(i,G[u].size()){
			Edge e = G[u][i];
			if(d[e.t] == INFTY){
				d[e.t] = d[u] + e.w;
				q.push(e.t);
			}
		}
	}
}

void solve(){
	bfs(0);
	int maxv = 0;
	int tgt = 0;
	rep(i,n){
		if(maxv < d[i]){
			maxv  = d[i];
			tgt = i;
		}
	}
	bfs(tgt);
	maxv = 0;
	rep(i,n){
		if(d[i] == INFTY) continue;
		maxv = max(maxv,d[i]);
	}
	cout << maxv << '\n';
}

signed main() {
	ios::sync_with_stdio(false);
    cin >> n;
	rep(i,n-1){
		int s,t,w;
		cin >> s >> t >> w;
		G[s].pb(Edge(t,w));
		G[t].pb(Edge(s,w));
	}
	solve();
	return 0;
}



Measured memory_bytes: 11860
N = int(input())
ans = {'AC':0,'WA':0,'TLE':0,'RE':0}
for i in range(N):
    a = input()
    if a in ans.keys():
        ans[a] +=1
    else:
        ans[a] = 1

for k,v in ans.items():
    print('{} x {}'.format(k,v))

Measured memory_bytes: 9200
import java.util.Scanner;

/**
 * https://atcoder.jp/contests/dp/tasks/dp_b
 * Frog 2
 */
public class Main {
	public static void main(String...args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			int[] h = new int[n];
			for (int i = 0; i < n; i++) {
				h[i] = sc.nextInt();
			}

			int[] dp = new int[n];
			for (int i = 0; i < n; i++) {
				if (i == 0) dp[i] = 0;
				else dp[i] = Integer.MAX_VALUE;
				for (int j = 1; j <= k; j++) {
					if (i >= j)	dp[i] = mindp(dp[i], dp[i-j] + Math.abs(h[i]-h[i-j]));
				}
			}

			System.out.println(dp[n-1]);
		}
	}

	public static int mindp(int a, int b) {
		if (a > b) {
			a = b;
		}
		return a;
	}
}


Measured memory_bytes: 50212
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>

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

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
    string s, t;
    cin >> s >> t;
    cout << t + s << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	while(1){
int d,e;
cin>>d>>e;
if(d==0)break;
double ans= (double)(e+d);
for(int i=0;i<=d/2;i++){
	int x=i;
	int y=d-i;
	double temp=sqrt(x*x+y*y);
ans=min(ans,abs(temp-e));
//cout<<temp<<endl;
}
cout<<ans<<endl;
}
return 0;
}



Measured memory_bytes: 3184
#include <stdio.h>
#include <math.h>
#define ok printf("ok\n");
#define inf 110000
#define z x[i]

int max(int a, int b){
    if(a>=b)
        return a;
    else
        return b;
}

int tmax(int a, int b, int c){
    return max(a, max(b, c));
}

int qmax(int a, int b, int c, int d){
    return max(max(a,b),max(c,d));
}


int x[inf][3];
int A[inf];
int B[inf];
int C[inf];


int main(){
    //printf("%d", max(10, 20));
    int n, prev;
    int start[9];
    scanf("%d", &n);

    for(int i=0; i<n; i++){
        scanf("%d%d%d", A+i, B+i, C+i);
    }

    for(int i=0; i<n; i++){
        //printf("%d %d %d\n", A[i], B[i], C[i]);
    }

    for(int i=0; i<n+1; i++){
        if(i==0){
            z[0]=A[0];
            z[1]=B[0];
            z[2]=C[0];
        }
        else{
            for(int j=0; j<3; j++){
                if(j==0){
                    int a = x[i-1][1];
                    int b = x[i-1][2];
                    int c = A[i];
                    //printf("%d %d %d\n", a, b, c);
                    z[0]=max(x[i-1][1]+A[i], x[i-1][2]+A[i]);
                }
                else if(j==1){
                    int a = x[i-1][0];
                    int b = x[i-1][2];
                    //printf("%d %d %d\n", a, b, B[i]);
                    z[1]=max(x[i-1][0]+B[i], x[i-1][2]+B[i]);
                }
                else{
                    int a = x[i-1][0];
                    int b = x[i-1][1];
                    //printf("%d %d %d\n", a, b, C[i]);
                    z[2]=max(x[i-1][0]+C[i], x[i-1][1]+C[i]);
                }
            }
            //printf("%d %d %d\n", z[0], z[1], z[2]);
        }
    }

    int ret=0;
    ret=max(ret, x[n-1][0]);
    ret=max(ret, x[n-1][1]);
    ret=max(ret, x[n-1][2]);
    printf("%d", ret);








}


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

using namespace std;

int main() {
   int n,l;
   cin>>n>>l;
   int flag=0;
   int a[n+1];
   a[0]=0;
   int min=100000;
   long long sum=0;
   for(int i=1;i<=n;i++)
   {
       sum+=i+l-1;
       a[i]=i+l-1;
   }
   
      for(int i=1;i<=n;i++)
   {
if(a[i]>=0&&abs(a[i])<min)
{
    min=a[i];
    flag=1;
    
}
   else if(a[i]<0&&abs(a[i])<min)
   {
       min=abs(a[i]);
   flag=0;
   }
   }
   
   if(flag==1)
   cout<<sum-min;
   else
   cout<<sum+min;
return 0;   
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,len;
	int c1,c2;
	char a[10001];
	
	while(scanf("%s",a)!=EOF){
		c1=0;
		c2=0;
		len=strlen(a);
		for(i=0;i<len;i++){
			if(a[i]=='J' && a[i+1]=='O' && a[i+2]=='I'){
				c1++;
			}
			if(a[i]=='I' && a[i+1]=='O' && a[i+2]=='I'){
				c2++;
			}
		}
		printf("%d\n%d\n",c1,c2);
	}
	return 0;
}

Measured memory_bytes: 980
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin >> n;
    string ans = "Yes";
    string list[n];
    for(int i=0;i<n;i++){
        string x;
        cin >> x;
        list[i] = x;
        if (i != 0){
           if(list[i].substr(0,1) != list[i-1].substr(list[i-1].length()-1,1)){
            ans = "No";
            break;
           }
        }
        for(int j=0;j<i;j++){
        if(list[i] == list[j] ){
            ans = "No";
            break;
        }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
gate=[input() for __ in range(M)]
s,e=map(int,gate[0].split())
for n in gate:
    pre_s,pre_e=map(int,n.split())
    s=(s if s>pre_s else pre_s)
    e=(e if e<pre_e else pre_e)

print(e+1-s if e>=s else 0)


Measured memory_bytes: 10272
#include <iostream>
#include <string>
using namespace std;
class Display
{
	string msg[2] = { "Yes","No" };
public:
	void disp(bool result) { 
		cout << msg[result] << endl;
	}
};
bool under(int b, int r)
{
	return (b - r < 0) ? true : false;
}
bool over(int b, int r,int m)
{
	return (b + r > m) ? true : false;
}
bool error(int w, int h, int x, int y, int r)
{
	if (!under(x, r) && !under(y, r) && !over(x, r, w) && !over(y, r, h)) return false;
	return true;

}
int main()
{
	int w,h,x,y,r;
	cin >> w>>h>>x>>y>>r;
	Display dsp;
	dsp.disp(error(w, h, x, y, r));
	return 0;

}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    cout << setprecision(20);
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];

    ll count = 1;
    //ll color = 0;
    ll c[3] = {};
    rep(i, n){
        ll cands = 0;
        rep(j, 3) if(a[i]==c[j]) ++cands;
        count = (count*cands) % 1000000007;
        rep(j, 3){
            if(a[i]==c[j]){
                ++c[j];
                break;
            }
        }
    }
    cout << count << endl;
}


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

using namespace std;

const int MAXN = 300;
int a[MAXN + 1][MAXN + 1];

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
            cin >> a[i][j];
    }
    bool valid = true;
    long long ans = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = i + 1; j <= n; j++)
        {
            int d = 2E9 + 5;
            for (int k = 1; k <= n; k++)
            {
                if (k == i || k == j)
                    continue;
                d = min(d, a[i][k] + a[k][j]);
            }
            if (d < a[i][j])
                valid = false;
            else if (d > a[i][j])
                ans += a[i][j];
        }
    }
    if (valid)
        cout << ans << endl;
    else
        cout << -1 << endl;
}


Measured memory_bytes: 640
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int main()
{
	int h, w, i, j;
	while (true)
	{
		cin >> h >> w;
		if (h == 0 && w == 0) break;
		for (i = 0; i < h; i++ )
		{
			for (j = 0; j < w; j++)
			{
				if (i == 0 || i ==h-1 || j == 0 || j == w - 1 )
					cout << '#';
				else cout << '.';
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = "";

        while ((line = br.readLine()) != null && !line.isEmpty()) {
            int len = line.length();
            char[] str = new char[len];

            len--;
            for (char c : line.toCharArray()) {
                str[len--] = c;
            }
            System.out.println(new String(str));
        }
    }
}

Measured memory_bytes: 16852
//import java.io.File;
import java.util.Scanner;
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.HashMap;

class Main{
  public static void main(String[] args) throws Exception {
    //Scanner scan = new Scanner(new File("in.txt"));
    Scanner scan = new Scanner(System.in);

    int input1 = scan.nextInt();
    int input2 = scan.nextInt();

    int[] things = new int[input1];
    int total = 0;
    int maxWeight = 0;
    for(int i = 0; i < input1; i++) {
      things[i] = scan.nextInt();
      total += things[i];
      maxWeight = Math.max(maxWeight,things[i]);
    }
    maxWeight = Math.max(maxWeight,total/input2);

    //System.out.println(total+","+maxWeight);

    while(true) {
      boolean flag = true;
      int weightTotal = 0;
      int track = 0;
      for(int j = 0; j < input1; ) {
        //System.out.println("track:"+track+",put:"+things[j]+",weightTotal:"+weightTotal+",maxWeight:"+maxWeight);
        if(weightTotal + things[j] > maxWeight) {
          if(track >= input2-1) {
            flag = false;
            break;
          }
          weightTotal = 0;
          track++;
          continue;
        }else {
          weightTotal += things[j];
          j++;
        }
      }
      if(flag) break;
      maxWeight++;
    }
    System.out.println(maxWeight);
  }
}

Measured memory_bytes: 70796
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    h, w, k = nm()
    g = [ns() for _ in range(h)]
    ans = 0
    for bih in range(1 << h):
        for biw in range(1 << w):
            cnt = 0
            for i in range(h):
                for j in range(w):
                    if bih & (1 << i) and biw & (1 << j) and g[i][j] == '#':
                        cnt += 1
            if cnt == k:
                ans += 1
    print(ans)
    return

solve()


Measured memory_bytes: 9156
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;

int main(void)
{
	int n,x;
	n=1;
	while(1)	{
		scanf("%d",&x);
		if(x==0)	break;
		printf("Case %d: %d\n",n,x);
		n++;
	}
	return 0;
}


Measured memory_bytes: 2584
// Problem Code: abc158_a

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

string station_and_bus(string& S) {
	sort(S.begin(), S.end());
	return (S.front() != S.back()) ? "Yes" : "No";
}

int main() {
	string S;
	cin >> S;
	cout << station_and_bus(S);
	return 0;
}

Measured memory_bytes: 256
n=int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
    cc,ss,ff=map(int,input().split())
    c.append(cc)
    s.append(ss)
    f.append(ff)

for i in range(n-1):
    x=s[i]+c[i]
    for j in range(i+1,n-1):
        if x<=s[j]:
            x=s[j]+c[j]
        else:
            if (x-s[j])%f[j]==0:
                x+=c[j]
            else:
                t=int((x-s[j])/f[j])
                x=s[j]+f[j]*(t+1)+c[j]
    print(x)
print(0)

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int dp[3010][3010];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    rep(i, S.length()) {
        rep(j, T.length()) {
            if (S[i] == T[j])
                dp[i + 1][j + 1] = dp[i][j] + 1;
            else 
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], max(dp[i + 1][j], dp[i][j + 1]));
        }
    }
    string ans;
    int i = S.length();
    int j = T.length();
    while(i > 0 && j > 0) {
        if (S[i - 1] == T[j - 1]) {
            ans = S[i - 1] + ans;
            i--; j--;
        }
        else if (dp[i][j] == dp[i][j - 1])
            j--;
        else 
            i--;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 35584