akhauriyash/Code-Regression huggingface dataset:
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever while (true)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
using namespace std;
// clang-format on

main {
  ios::sync_with_stdio(false);
  int n, t;
  cin >> n >> t;
  vi dp(t + 1);
  while (n--) {
    int l, r;
    cin >> l >> r;
    dp[l]++;
    dp[r]--;
  }
  loop(i, 1, dp.size()) dp[i] += dp[i - 1];
  cout << *max_element(all(dp)) << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int n, q;
  string s;
  cin >> n >> q >> s;
  vector<int> l(q), r(q);
  rep(i, q) {
    cin >> l[i] >> r[i];
  }

  vector<int> memo(n+1);
  rep(i, n-1) {
    if (s[i] == 'A' && s[i+1] == 'C') {
      memo[i+2]++;
    }
  }

  rep(i, n) {
    memo[i+1] += memo[i];
  }

  rep(i, n+1) {
    cerr << memo[i] << endl;
  }
  cerr << endl;

  rep(i, q) {
    cout << memo[r[i]] - memo[l[i]] << endl;
  }
}


Measured memory_bytes: 2256
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
#debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N = II()
    a_list = LI()
    b_list = LI()

    ans = 0
    left = a_list[0]

    for i in range(N):
        power = b_list[i]
        if power >= left:
            # 左をすべて倒せる
            ans += left
            power = power - left
        else:
            # 左をすべて倒せない
            ans += power
            power = 0

        right = a_list[i+1]
        if power >= right:
            # 右をすべて倒せる
            ans += right
            left = 0 # 次の勇者のleftは0
        else:
            # 右が余るとき
            ans += power
            left = right - power # 次の勇者にはあまりがある

    print(ans)
solve()

Measured memory_bytes: 19220
#include <stdio.h>
int main(void){
  int a[4][3][10]={0},n,b,f,r,v,i,j,k;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d %d",&b,&f,&r,&v);
    a[b-1][f-1][r-1]+=v;
  }
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
	printf(" %d",a[i][j][k]);
      }
      printf("\n");
    }
    if(i<3)
      printf("####################\n");
  }
  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define ll long long

using namespace std;
int n , k , w;
ll dp[105][100005];
ll a[105] , b[105] , c[100005];
int main()
{
    ios::sync_with_stdio(0);
    cin >> n;
    cin >> w;
    ll ans = 0;
    for (int i=1;i<=n;i++)cin >> b[i] >> a[i];
    for (int i=1;i<=n;i++)
    {
        ans = 0;
        for (int j=0;j<=w;j++)
        {
            if (j >= b[i])
            dp[i][j] = max(dp[i][j] , a[i] + dp[i - 1][j - b[i]]);
            dp[i][j] = max(dp[i][j] , dp[i - 1][j]);
            ans = max(ans , dp[i][j]);
        }
    }
    cout << ans << endl;
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 78592
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		if (N < 10) {
			System.out.print(N);
		} else if (N < 100) {
			System.out.print(9);
		} else if (N < 1000) {
			System.out.print(9 + (N - 99));
		} else if (N < 10000) {
			System.out.print(909);
		} else if (N < 100000) {
			System.out.print(909 + (N - 9999));
		}else {
			System.out.print(90909);
		}
	}
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int int_fast64_t

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

INTV G[200];
int colors[200];

bool dfs(int pos, int color){
  colors[pos] = color;
  for(auto to : G[pos]){
    if(colors[to] == color) return 0;
    if(colors[to] == 0 and !dfs(to, -color)) return 0;
  }
  return 1;
}

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

  int N; string S; cin >> N;
  vector<INTV> d(N, INTV(N, BIG));
  REP(i, N) d[i][i] = 0;
  REP(i, N){
    cin >> S;
    REP(j, N){
      if(S[j]=='1'){
        G[i].eb(j); d[i][j] = 1;
      }
    }
  }
  if(!dfs(0, 1)){
    cout << -1 << endl; return 0;
  }
  
  REP(k, N) REP(i, N) REP(j, N){
    d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
  }
  int mx = 0;
  REP(i, N) REP(j, N){
    mx = max(mx, d[i][j]);
  }
  cout << mx+1 << endl;
}

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

int main(void){
  int n;
  bool y = false;
  char s[100];
  cin >> n;
  for(int i = 0; i < n;i ++){
    cin >> s[i];
  }
  for(int i = 0; i < n;i ++){
    if(s[i] == 'Y'){
      y = true;
    }
  }
  
  if(y)cout << "Four" << endl;
  else cout << "Three" <<endl;
}


Measured memory_bytes: 256
def main():
    S = input()
    A = []
    i, t = 1, S[0]
    for s in S[1:]:
        if s != t:
            A.append(i)
            i = 1
            t = s
        else:
            i += 1
    A.append(i)

    m, l  = len(S), 0
    for a in A:
        t = max(l + a, len(S) - l - a)
        m = min(m, t)
        l += a
    return m

print(main())


Measured memory_bytes: 3676
N = int(input())
# 愚直に求めるならば
# f(n) = n(n-2)(n-4)...(n%2+4)(n%2+2)f(n%2)

if N % 2:
    print(0)
    exit()
# n が奇数ならば0を出力すればよい

# nが偶数ならば
# f(n) = n(n-2)(n-4)...(n%2+4)(n%2+2)

# 小問題
# n , n-2, n-4, ... , n%2+4, n%2+2
# の中に含まれるNの倍数の数を求めよ
def a(n,N):
    n -= n % (2 * N)
    return n // N // 2

s = 0
result = 1
NN = 5
while result:
    result = a(N,NN)
    s += result
    NN *= 5

print(s)

Measured memory_bytes: 3060
N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans  = sum(B)
memo = A[0]
for i in range(1,N):
	if memo == A[i]-1:
		ans += C[memo-1]
		
	memo = A[i]
print(ans)

Measured memory_bytes: 3064
using System;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine();
        string[] strinputArray = input.Split(' ');
        int[] intinputArray = Array.ConvertAll<string, int>(strinputArray, delegate (string value) { return int.Parse(value); });
        if(intinputArray[2] >= intinputArray[4] 
            && intinputArray[3] >= intinputArray[4] 
            && intinputArray[2] <= intinputArray[0] - intinputArray[4]
            && intinputArray[3] <= intinputArray[1] - intinputArray[4])
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 17948
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;


int main()
{
    ll R, G;
    cin >> R >> G;
    cout << G*2 - R << endl;
    return 0;
}


Measured memory_bytes: 256
# ABC049 D
n, k, l = gets.chomp.split(" ").map(&:to_i)
roads = Array.new(n+1){Array.new()}
rails = Array.new(n+1){Array.new()}

k.times do
  p_, q_ = gets.chomp.split(" ").map(&:to_i)
  roads[p_] << q_
  roads[q_] << p_
end

l.times do 
  a, b = gets.chomp.split(" ").map(&:to_i)
  rails[a] << b
  rails[b] << a
end


def dfs(i, a, v)
  if @visited[i]
    return
  else
    @visited[i] = true
    @ret[i] = v
    j = 0
    while j < a[i].length
      if !@visited[a[i][j]]
        dfs(a[i][j], a, v)
      end
      j += 1
    end
  end
end


@visited = Array.new(n+1, false)
@ret = Array.new(n+1, 0)
v = 1
1.upto(n) do |i|
  dfs(i, roads, v)
  v += 1
end
a1 = @ret.clone

@visited = Array.new(n+1, false)
@ret = Array.new(n+1, 0)
v = 1
1.upto(n) do |i|
  dfs(i, rails, v)
  v += 1
end
a2 = @ret.clone

h = Hash.new(0)
1.upto(n) do |i|
  k = [a1[i], a2[i]]
  h[k] += 1
end

ans = []
1.upto(n) do |i|
  k = [a1[i], a2[i]]
  ans << h[k]
end

puts ans.join(" ")


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

int main() {
    int a,b;
    string s,t,u;

    cin >> s >> t >> a >> b >> u;

    if(s==u)
        cout << a-1 << " " << b << endl;
    else
        cout << a << " " << b-1 << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;
// constexpr int MOD = 1e9+7;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(int, h, w, n);
    Cins(int, n, a);
    
    Vec2(int, h, w, c);
    int ij = 0;
    For(i, n){
        Rep(a[i]){
            c[ij / w][ij % w] = i+1;
            ij ++;
        }
    }
    
    For(i, (int)c.size()){
        if(i % 2 == 1) Reverse(c[i]);
        Couts(c[i]);
    }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int main()
{
    string s;
    cin>>s;
    int n=s.size(),ma=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i;j<n;j++)
        {
            bool flag=true;
            for(int k=i;k<=j;k++)
            {
                if(s[k]!='A'&&s[k]!='T'&&s[k]!='C'&&s[k]!='G')
                {
                    flag=false;
                    break;
                }
            }
            if(flag)
                ma=max(ma,j-i+1);
        }
    }
    cout<<ma<<endl;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  int k=sc.nextInt();
  String po=sc.next();
  if(po.length()>k){
  System.out.println(po.substring(0,k)+"...");
  }else
  System.out.println(po);
}
}


Measured memory_bytes: 38568
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>
#include<iomanip>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main() {
	double a,b,v;
	cin >> a >> b >> v;
	double ans = 0;
	if (v < static_cast<double>(1) / 2 * a * a * b) {
		ans = atan(a * b * b / 2 / v)/2/M_PI*360;
	}
	else {
		ans = atan((a * a * b - v) * 2 / pow(a, 3)) /2/M_PI*360;
	}

	cout <<setprecision(10)<<ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod=1e9+7;
int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    ll n,k;
    cin>>n>>k;
    ll x[n],dp[k+1]={};
    dp[0]=1;
    for(ll &i:x) cin>>i;
    for(ll i=0;i<n;i++){
        ll pre[k+2]={};
        for(ll j=0;j<=k;j++) pre[j+1]=pre[j]+dp[j],pre[j+1]%=mod;
        for(ll j=k;j>=0;j--){
            dp[j]+=pre[j]-pre[max(j-x[i],0ll)];
            dp[j]=(dp[j]+mod)%mod;
        }
    }
    cout<<dp[k];
}


Measured memory_bytes: 5208
#include<bits/stdc++.h>
typedef long long ll;
#define M 998244353
using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
int n;
cin>>n;
int c=0;
while(n!=0)
{
	if(n%10==7)
		c++;
	n/=10;
}
if(c>0)
cout<<"Yes"<<"\n";
else
cout<<"No"<<"\n";
return 0;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(){
    int time;
    cin >> time;
    int hour=time/3600;
    int min=(time-hour*3600)/60;
    int sec=time-hour*3600-min*60; 
    cout << hour << ':' << min << ':' << sec << endl;
    return 0;
}

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

template<class T>
struct SegTree {
    int NN;
    T default_value;
    vector<T> data;

    T aggr(int a, int b) {
        return max(a, b);
    }

    SegTree(int N, T val) {
        default_value = val;
        NN = 1; while (NN < N) NN <<= 1;
        data = vector<T>(2 * NN, val);
    }

    SegTree(const vector<T> v, T val) {
        default_value = val;
        int N = v.size();
        NN = 1; while (NN < N) NN <<= 1;
        data = vector<T>(2 * NN, val);
        copy(v.begin(), v.end(), data.begin() + (NN - 1));
        build(0, 0, NN);
    }

    void build(int u, int l, int r) {
        if (r - l == 1) return;
        int m = (l + r) / 2;
        build(u * 2 + 1, l, m);
        build(u * 2 + 2, m, r);
        data[u] = aggr(data[2 * u + 1], data[2 * u + 2]);
    }

    T query(int a, int b, int u, int l, int r) {
        if (l >= b || r <= a)
            return default_value;
        if (l >= a && r <= b)
            return data[u];
        int m = (l + r) / 2;
        T res1 = query(a, b, u * 2 + 1, l, m);
        T res2 = query(a, b, u * 2 + 2, m, r);
        return aggr(res1, res2);
    }

    void update_value(int idx, T x, int u, int l, int r) {
        if (idx < l || idx >= r)
            return;
        if (idx == l && r - l == 1) {
            data[u] = x;
            return;
        }
        int m = (l + r) / 2;
        update_value(idx, x, u * 2 + 1, l, m);
        update_value(idx, x, u * 2 + 2, m, r);
        data[u] = aggr(data[2 * u + 1], data[2 * u + 2]);
    }

    void update_delta(int idx, T x, int u, int l, int r) {
        update_value(idx, data[NN - 1 + idx] + x, u, l, r);
    }
};

int solve() {
    int H, W, M;
    cin >> H >> W >> M;

    auto cntR = vector<int>(H, 0);
    auto cntC = vector<int>(W, 0);
    auto t = vector<vector<int>>(H, vector<int>());
    for (int i = 0; i < M; i++) {
        int r, c; 
        cin >> r >> c;
        r--; c--;
        cntR[r]++;
        cntC[c]++;
        t[r].push_back(c);
    }

    auto seg = SegTree<int>(cntC, 0);
    int ans = -1;
    for (int r = 0; r < H; r++) {
        for (auto c : t[r]) {
            seg.update_delta(c, -1, 0, 0, seg.NN);
        }
        int val = cntR[r] + seg.query(0, W, 0, 0, seg.NN);
        ans = max(ans, val);
        for (auto c : t[r]) {
            seg.update_delta(c, +1, 0, 0, seg.NN);
        }
    }
    return ans;
}

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

    cout << solve() << endl;

    return 0;
}

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

vector<int> g[100001];
vector<int> tree[100001];
vector<int> l[100001];
int p[100001];
int bye[100001];

int ans1 = 0;
int lim = 0;

void dfs1(int x){
    int cntt = 0;
    for(auto &nxt: g[x]){
        if(nxt == p[x]) continue;
        tree[x].push_back(nxt);
        p[nxt] = x;
        dfs1(nxt);
        cntt++;
    }
    ans1 += (cntt / 2);
    if(x == 1 && (cntt % 2) == 1) ans1++;
}

bool dfs2(int x){
    l[x].clear();
    for(auto &nxt: tree[x]){
        if(!dfs2(nxt)) return false;
        //printf("bye %d -> %d: %d\n", nxt, x, bye[nxt]);
        l[x].push_back(bye[nxt]+1);
    }
    int m = (int)l[x].size();
    if(x == 1){
        sort(l[x].begin(), l[x].end());
        for(auto &val: l[x]){
            if(val > lim) return false;
        }
        if(m%2 == 0){
            for(int i=0;i<m;i++){
                if(l[x][i] + l[x][m-1-i] > lim) return false;
            }
        }else{
            for(int i=0;i<m-1;i++){
                if(l[x][i] + l[x][m-2-i] > lim) return false;
            }
        }
        return true;
    }
    if(m%2 == 0){
        l[x].push_back(0);
        m++;
    }
    sort(l[x].begin(), l[x].end());
    for(auto &val: l[x]){
        if(val > lim) return false;
    }
    bye[x] = 0;
    int ss = 0, ee = m-1, ans = m;
    while(ss <= ee){
        int mid = (ss + ee) / 2;
        int s = 0, e = m-1;
        bool can = true;
        while(s < e){
            if(s == mid) s++;
            if(e == mid) e--;
            if(s >= e) break;
            if(l[x][s] + l[x][e] > lim){
                can = false;
                break;
            }else{
                s++; e--;
            }
        }
        if(can){
            ans = mid;
            ee = mid - 1;
        }else{
            ss = mid + 1;
        }
    }
    if(ans == m) return false;
    bye[x] = l[x][ans];
    return true;
}

int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<n;i++){
        int aa, bb;
        scanf("%d%d", &aa, &bb);
        g[aa].push_back(bb);
        g[bb].push_back(aa);
    }
    p[1] = 1;
    dfs1(1);
    int ss = 0, ee = n+1, ans2 = n+1;
    while(ss <= ee){
        lim = (ss + ee) / 2;
        //printf("%d\n", lim);
        if(dfs2(1)){
            ans2 = lim;
            ee = lim - 1;
        }else{
            ss = lim + 1;
        }
    }
    printf("%d %d\n", ans1, ans2);
}


Measured memory_bytes: 25472
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

  int N=in(),M=in(),C=in();
  vector<int> B(M);
  for(auto& x:B) x=in();
  int num=0;
  for(int i=0;i<N;i++){
    int sum=0;
    for(auto& x:B){
      sum+=in()*x;
    }
    if(sum+C>0) num++;
  }
  
  cout << num << endl;
  return 0;
}


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

int main()
{
	int a,b,c,d,sum=0;
	string s;

    cin>>a>>b;
    if((a*b)%2==0)
        cout<<"Even";
    else
    {
        cout<<"Odd";
    }
    
	
	return 0;
}
	

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
#define MOD 1000000007
#define PI 3.14159265358979323846
using namespace std;
typedef long long ll;



int main(void) {
	int n, m; cin >> n >> m;
	vvint e(n);
	vint d(n,INT_MAX);
	vint ans(n);
	rep(i, m) {
		int x, y; cin >> x >> y;
		x--; y--;
		e[x].push_back(y);
		e[y].push_back(x);
	}

	queue<int> q;
	q.push(0);
	d[0] = 0;
	while (q.size()!=0) {
		int now = q.front(); q.pop();
		rep(i, e[now].size()) {
			if (d[e[now][i]] > d[now]+1) {
				d[e[now][i]] = d[now] + 1;
				ans[e[now][i]] = now;
				q.push(e[now][i]);
			}
		}
	}

	cout << "Yes" << endl;
	for (int i = 1; i < n; i++) {
		cout << ans[i]+1 << endl;;
	}

	return 0;
}


Measured memory_bytes: 10640
#include <iostream>



int main()
{
	int a, b;

	while (std::cin >> a >> b) {
		if (a == 0 && b == 0) break;
		if(b > a)
			printf("%d %d\n", a, b);
		else
			printf("%d %d\n", b, a);
	}

	return 0;
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(min(b, d) - max(a, c),0) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	static final String CODE = "012345024135031425043215103254120534135024152304201453215043240513254103304152310542345012351402402351425031430521453201513240521430534120542310";

	static class Dice {
		private int[] dig;
		private int[] pat;
		public Dice(Scanner s) {
			dig = new int[6];
			for (int i = 0; i < dig.length; i++) {
				dig[i] = s.nextInt();
			}
			pat = new int[CODE.length()];
			for (int i = 0; i < pat.length; i++) {
				int p = CODE.charAt(i) - '0';
				pat[i] = dig[p];
			}
		}
		public int scan(int x, int y) {
			int p = 0;
			for (; p < pat.length; p += 6) {
				if (pat[p] == x && pat[p + 1] == y) {
					return pat[p + 2];
				}
			}
			return -1;
		}
	}

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			Dice d = new Dice(sc);
			int q = sc.nextInt();
			for (int i = 0; i < q; i++) {
				int x = sc.nextInt();
				int y = sc.nextInt();
				int s = d.scan(x, y);
				System.out.println(Integer.toString(s));
			}
		}
	}
}



Measured memory_bytes: 26040
#include <bits/stdc++.h>
#define INF 1000000000000000001
#define ll long long
#define pll pair<ll, ll>
using namespace std;

//ture == sheep
vector<bool> next(bool fir, bool sec, string& s)
{
  vector<bool> res = {fir, sec};

  ll N = s.size();
  for (ll i = 0; i < N; ++i)
  {
    if (sec)
    {
      if (s[i] == 'o')
      {
        res.push_back(fir);
      }
      else
      {
        res.push_back(!fir);
      }
    }
    else
    {
      if (s[i] == 'o')
      {
        res.push_back(!fir);
      }
      else
      {
        res.push_back(fir);
      }
    }
    fir = sec;
    sec = *(res.end() - 1);
  }
  return res;
}


int main()
{
  ll N;
  cin >> N;
  string s;
  cin >> s;
  vector<bool> temp = next(true, true, s);
  for (ll i = 0; i < 2; ++i)
  {
    for (ll j = 0; j < 2; ++j)
    {
      temp = next(i, j, s);
      if (temp.at(0) == *(temp.end() - 2) && temp.at(1) == *(temp.end() - 1))
      {
        for (ll i = 1; i < N + 1; ++i)
        {
          if (temp.at(i))
          {
            cout << "S";
          }
          else
          {
            cout << "W";
          }
        }
        cout << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
struct edge{int to, cost;};
vector<edge> graph[100010];
long long dp[100010];

void dfs(int v, int p = -1, long long c = 0)
{
	dp[v] = c;
	for(int i = 0; i < graph[v].size(); i++)
	{
		if (graph[v][i].to == p) continue;
		dfs(graph[v][i].to, v, graph[v][i].cost + c);
	}
}

signed main(void)
{
	int n;
	cin >> n;
	rep(i, n - 1)
	{
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		graph[a].push_back({b, c});
		graph[b].push_back({a, c});
	}
	int q, k;
	cin >> q >> k;
	k--;
	dfs(k);
	rep(i, q)
	{
		int x, y;
		cin >> x >> y;
		x--; y--;
		cout << dp[x] + dp[y] << endl;
	}
	return 0;
}


Measured memory_bytes: 14336
H, W = map(int, input().split())
A = [list(map(int, input().split())) for i in range(H)]
B = [list(map(int, input().split())) for i in range(H)]
center = 80 * (H+W)
C = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]

dp = [[0] * W for i in range(H)]
dp[0][0] = (1 << (center + C[0][0])) | (1 >> (center - C[0][0]))

for i in range(H):
    for j in range(W):
        if i:
            dp[i][j] |= dp[i-1][j] << C[i][j]
            dp[i][j] |= dp[i-1][j] >> C[i][j]
        if j:
            dp[i][j] |= dp[i][j-1] << C[i][j]
            dp[i][j] |= dp[i][j-1] >> C[i][j]

ans = center * 2
for i in range(center*2):
    if (dp[H-1][W-1] >> i) & 1:
        ans = min(ans, abs(i-center))

print(ans)


Measured memory_bytes: 20340
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    vector<int> hoge(3);
    for(int i=0;i<3;i++) cin>>hoge.at(i);
    sort(hoge.begin(),hoge.end());
    cout<<hoge.at(2)*10+hoge.at(1)+hoge.at(0)<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
main(){
    int N,l,r;
    int cnt = 0;
    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> l >> r;
        cnt += r - l + 1;
    }
    cout << cnt << endl;
}

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

int main() {
  int N;
  cin >> N;
  int a[110], sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    sum += a[i];
  }

  double average = (double)sum / N;
  int target = round(average);

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += (target - a[i]) * (target - a[i]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

for i in range(n):
    A[i] -= (i+1)

A.sort()

med = [A[n//2]]
if n % 2 == 0:
    med.append(A[n//2 - 1])

ans = 1000000000000000000
for m in med:
    cnt = 0
    for a in A:
        cnt += abs(a-m)
    ans = min(ans, cnt)

print(ans)

Measured memory_bytes: 26020
N = int(input())
dp = [-1] * (N + 1)
dp[0] = 0
l = [1] + [6**i for i in range(1,7)] + [9**i for i in range(1,6)]

for n in range(1, N+1):
    tmp = float('inf')
    for j in l:
        if n-j >= 0:
            tmp = min(tmp, 1 + dp[n-j])
    dp[n] = tmp
print(dp[-1])

Measured memory_bytes: 3828
H, W, K = map(int, input().split())
X = []
for i in range(H):
    X.append(input().strip())

R = 0
for i in range(2**H):
    iis = [0]*H
    tmp = 0
    while i:
        if i%2:
            iis[tmp] = 1
        i = i//2
        tmp += 1
    for j in range(2**W):
        jjs = [0]*W
        tmp = 0
        while j:
            if j%2:
                jjs[tmp] = 1
            j = j//2
            tmp += 1
        co = 0
        for u in range(H):
            for v in range(W):
                if iis[u] or jjs[v]:
                    continue
                if X[u][v] == "#":
                    co += 1
        if co == K:
            R += 1

print(R)


Measured memory_bytes: 68368
n = int(input())
a = list(map(int, input().split()))
f = 0
t = 0
k = 0
for i in a:
    if i % 4 == 0:
        f += 1
    elif i % 2 == 0:
        t += 1
    else:
        k += 1

if t > 0:
    if f >= k:
        print("Yes")
    else:
        print("No")
else:
    if f + 1 >= k:
        print("Yes")
    else:
        print("No")


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

int main(){
    int h,n;
    cin >> h >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    int sum = 0;
    rep(i,n){
        sum += a.at(i);
    }
    if((h - sum) <= 0) cout << "Yes";
    else cout << "No";
    return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

const ll INF = 1LL << 60;

ll dp_memo[2010][2010];
ll sum_memo[2010][2010];
ll N,M; vector<ll> S; vector<ll> T;

ll dp( ll a, ll b);
ll sum ( ll c, ll d);

// dp(a,b)は最後にS[a],T[b]を使う共通部分列の個数
// sum(a,b)はdp(0,0) + dp(0,1) + ... + dp(a,b)のこと。　
//記号は基本解説PDF準拠

ll dp(ll a, ll b){
   if( a < 0 || b < 0){ return 0;}//やばい範囲は0で返す
   if( dp_memo[a][b] !=-1){ return dp_memo[a][b];}
   
  if( S[a] != T[b]){ return 0;}
  else{
  return  dp_memo[a][b] = sum(a-1, b-1) % MOD;}}
//漸化式は解説準拠

ll sum( ll c, ll d){
  if( c < 0 || d < 0){ return 0;}
  if(sum_memo[c][d] !=-1){ return sum_memo[c][d];}//すでに書き込まれている場合はメモカさいき
 
  
 return sum_memo[c][d] = (MOD +sum(c-1, d) + sum( c, d -1) - sum( c - 1, d - 1) + dp(c,d)) % MOD;}

  
  
  
int main(){
  cin >> N >> M; S.resize(N+1); T.resize(M+1);


  for(int i = 0; i < 2010; i++){
    for(int j = 0; j < 2010; j++){
      dp_memo[i][j] = -1; sum_memo[i][j] = -1;}}
  //-1は未更新
  
  for(int i = 0; i < 2010;i++){
    dp_memo[i][0] = 0; dp_memo[0][i] = 0;}
  
   dp_memo[0][0] = 1; //初期条件
        
        
  
  for(int i = 1; i <= N; i++){ cin >> S[i];}
  for(int j = 1; j <= M; j++){ cin >> T[j];}
  
  S[0] = INF; T[0] = INF; //()のこと
  
  
  cout << sum(N,M) << endl; return 0;}
   
                  

Measured memory_bytes: 63616
import collections

N = int(input())
A = collections.deque(sorted(map(int,input().split())))


def func1(a, r, rnext):
    p = a.popleft()
    q = a.pop()
    ans = 0
    a1 = collections.deque()
    while True:
        if p + q == r:
            ans += 1
            try:
                p = a.popleft()
            except:
                break
            try:
                q = a.pop()
            except:
                if p < rnext:
                    a1.append(p)
                break
        elif p + q > r:
            try:
                q = a.pop()
            except:
                if p < rnext:
                    a1.append(p)
                break
        else:
            a1.append(p)
            try:
                p = a.popleft()
            except:
                if q < rnext:
                    a1.append(q)
                break
    return ans, a1


if N == 1:
    print(0)
    exit(0)
t = int.bit_length(A[-1] + A[-2])
r = 2 ** t
rnext = 2 ** (t - 1)
anser = 0
a = A

while True:
    ans, a1 = func1(a, r, rnext)
    anser += ans
    if len(a1) < 2:
        break
    a = a1
    t -= 1
    r = rnext
    rnext = 2 ** (t - 1)

print(anser)


Measured memory_bytes: 25964
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
vector<long long> number(100001, 0);

int main() {
	
	unsigned long long N, K;
	unsigned long long saved ;
	unsigned long long nowpoint = 0;
	unsigned long long endpoint = 0;
	cin >> N >> K;
	for (int i = 0; i < N; i++)
	{
		unsigned long long tmp, set;
		cin >> tmp >> set;
		number[tmp-1] += set;
	}

	for (int i = 0; nowpoint < K; i++)
	{
		nowpoint += number[i];
		saved = i+1;
	}
	cout << saved << endl;

	return 0;
}

Measured memory_bytes: 1024
while 1:
    try:
        s=input()
        joi=0
        ioi=0
        for i in range(len(s)-2):
            oi=s[i]+s[i+1]+s[i+2]
            if oi=="JOI":joi+=1
            elif oi =="IOI":ioi+=1
        print(joi)
        print(ioi)
    except:break


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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct Point{
	double x,y,z;
	Point(){}
	Point(double x,double y,double z):x(x),y(y),z(z){}
	Point& operator+=(Point p){x+=p.x,y+=p.y,z+=p.z; return *this;}
	Point& operator-=(Point p){x-=p.x,y-=p.y,z-=p.z; return *this;}
	Point& operator*=(double c){x*=c,y*=c,z*=c; return *this;}
	Point& operator/=(double c){x/=c,y/=c,z/=c; return *this;}
};
Point operator+(Point a,Point b){return a+=b;}
Point operator-(Point a,Point b){return a-=b;}
Point operator*(Point a,double c){return a*=c;}
Point operator*(double c,Point a){return a*=c;}
Point operator/(Point a,double c){return a/=c;}
double Dot(Point a,Point b){return a.x*b.x+a.y*b.y+a.z*b.z;}
double Abs2(Point p){return Dot(p,p);}
double Abs(Point p){return sqrt(Abs2(p));}

struct Line{
	Point pos,dir;
	Line(){}
	Line(Point p,Point d):pos(p),dir(d){}
};

struct Sphere{
	Point center;
	double radius;
	Sphere(){}
	Sphere(Point c,double r):center(c),radius(r){}
	Sphere(double x,double y,double z,double r):center(x,y,z),radius(r){}
};

Point Proj(Line l,Point p){
	Point a=p-l.pos,b=l.dir;
	return l.pos+Dot(a,b)/Abs2(b)*b;
}
double DistLP(Line l,Point p){
	return Abs(Proj(l,p)-p);
}

pair<double,double> InterPoint(Sphere s,Line l){
	Point p=l.pos-s.center,d=l.dir;
	double a=Abs2(d),b=Dot(p,d),c=Abs2(p)-pow(s.radius,2);
	double t1=(-b-sqrt(b*b-a*c))/a;
	double t2=(-b+sqrt(b*b-a*c))/a;
	return mp(t1,t2);
}

ostream& operator<<(ostream& os,const Point& p){
	return os<<'('<<p.x<<','<<p.y<<','<<p.z<<')';
}

int main()
{
	for(int n;cin>>n && n;){
		Point d0; cin>>d0.x>>d0.y>>d0.z;
		vector<Sphere> ss(n);
		rep(i,n){
			double x,y,z,r; cin>>x>>y>>z>>r;
			ss[i]=Sphere(x,y,z,r);
		}
		
		Line l(Point(0,0,0),d0);
		for(;;){
			vd ts(n,INF);
			rep(i,n) if(DistLP(l,ss[i].center)<ss[i].radius){
				double t1,t2; tie(t1,t2)=InterPoint(ss[i],l);
				ts[i]=t1>EPS?t1:t2>EPS?t2:INF;
			}
			
			int i=min_element(all(ts))-begin(ts);
			if(ts[i]==INF){
				printf("%.4f %.4f %.4f\n",l.pos.x,l.pos.y,l.pos.z);
				break;
			}
			
			// aから球面上の点bで跳ね返りcへ
			Point a=l.pos,b=l.pos+l.dir*ts[i];
			Point p=Proj(Line(ss[i].center,b-ss[i].center),a);
			Point c=p+(p-a);
			l=Line(b,c-b);
		}
	}
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
template <typename T> T read() { T a; cin >> a; return a; }

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  auto k = read<int>();
  auto s = read<string>();
  if (s.length() > k) {
    s = s.substr(0, k);
    s += "...";
  }
  cout << s;
  return 0;
}

Measured memory_bytes: 3656
H, W = map(int, input().split())
maze = [input() for _ in range(H)]
seen = [[-1] * W for _ in range(H)]

from collections import deque


queue = deque()
for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            queue.append([i, j, 0])
            seen[i][j] = 0

def bfs(maze, seen):
    while queue:
        y, x, c = queue.popleft()
        for i, j in [1, 0], [-1, 0], [0, 1], [0, -1]:
            dy = y + i
            dx = x + j
            if dy < 0 or H <= dy or dx < 0 or W <= dx:
                continue
            if seen[dy][dx] > -1:
                continue
            if maze[dy][dx] == '#':
                continue
            seen[dy][dx] = c + 1
            queue.append([dy, dx, c+1])

def check_max(seen):
    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, seen[i][j])
    return ans
    
bfs(maze, seen)
print(check_max(seen))

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

int N,M;
int a[50],b[50];
bool g[50][50];
bool visited[50];

void dfs(int v){
    visited[v]=true;
    for(int v2=0;v2<N;++v2){
        if(!g[v][v2])continue;
        if(visited[v2])continue;
        dfs(v2);
    }
}

int main(void){
    cin>>N>>M;
    for(int i=0;i<M;i++){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        g[a[i]][b[i]]=g[b[i]][a[i]]=true;
    }
    
    int ans=0;
    
    for(int i=0;i<M;i++){
        g[a[i]][b[i]]=g[b[i]][a[i]]=false;
        
        for(int j=0;j<N;j++)visited[j]=false;
        
        dfs(0);
        
        bool bridge=false;
        for(int j=0;j<N;j++){
            if(!visited[j])bridge=true;
        }
        if(bridge)ans++;
        
        g[a[i]][b[i]]=g[b[i]][a[i]]=true;
    }
    
    cout<<ans<<endl;
    
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(true){
int H = sc.nextInt();
int W = sc.nextInt();
if(H == 0 && W == 0){
break;
}
for(int i = 0;i < H;i++){
for(int j = 0;j < W;j++){
System.out.printf("#");
}
System.out.printf("\n");
}
System.out.printf("\n");
}
}
}


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

int main(){
	int M;
	cin >> M;
	vector<long long> d(M);
	vector<long long> c(M);
	for(int i=0;i<M;i++){
		cin >> d[i] >> c[i];
	}
	long long ans=0;
	for(int i=0;i<M;i++)ans+=d[i]*c[i];
	ans--;
	ans/=9;
	ans+=accumulate(c.begin(),c.end(),0LL)-1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  set<set<int> > pr;
  int s ;
  if(n&1)
    s = n;
  else
    s=n+1;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      if(i!=j && j+i!=s){
        pr.insert({i,j});
      }
    }
  }
  cout<<pr.size()<<endl;
  for(auto it:pr){
    for(auto a:it){
      cout<<a<<" ";
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define read read()
inline int read{
   int s=0,w=1;
   char ch=getchar();
   while(ch<='0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
int main(){
	int a,b,c;
	a=read,b=read,c=read;
	a-=b;
	a%=c;
	cout<<a<<endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

#define MAX_V 100000
vector<int> G[MAX_V];


pii mergeSegment(pii a,pii b){	//returns pii(1,-1) when two segments don't crossed.
	if(a.first<=-INF) return b;
	if(b.first<=-INF) return a;
	if(abs(a.first)%2!=abs(b.first)%2) return pii(1,-1);
	
	if(a.second<b.first || b.second<a.first)	return pii(1,-1);
	if(a.first<=b.first && b.second<=a.second)	return b;
	if(b.first<=a.first && a.second<=b.second)	return a;
	if(a.first<b.first && a.second<b.second)	return pii(b.first,a.second);
	if(b.first<a.first && b.second<a.second)	return pii(a.first,b.second);
	
	return pii(1,-1);
}

vector<pii> dp;

pii dfs(int cur,vector<bool> &used){
	pii res = dp[cur];
	for(auto &e:G[cur]){
		if(used[e])continue;
		used[e]=true;
		pii p = dfs(e,used);
		p.first--,p.second++;
		res = mergeSegment(res,p);
	}
	return (dp[cur] = res);
}


int main(){
	int v,k,a,b;
	cin>>v;
	rep(i,v-1){
		cin>>a>>b;
		G[--a].pb(--b);
		G[b].pb(a);
	}
	
	cin>>k;
	int root=-1;
	dp.resize(v,pii(-INF,INF));
	rep(i,k){
		cin>>a>>b;
		dp[--a] = pii(b,b);
		root = a;
	}
	
	vector<bool> used(v,false);
	used[root] = true;
	dfs(root,used);
	
	rep(i,v)if(dp[i]==pii(1,-1)){cout<<"No"<<endl;return 0;}
	cout<<"Yes"<<endl;
	

	queue<int> que;
	que.push(root);
	vector<int> ans(v,-INF);
	ans[root] = dp[root].first;

	while(que.size()){
		int q = que.front();
		que.pop();
		
		int p=ans[q];
		for(auto &e:G[q]){
			if(ans[e]!=-INF)continue;
			
			if(dp[e].first<=p-1&&p-1<=dp[e].second)ans[e] = p-1;
			else ans[e] = p+1;
			que.push(e);
		}
	}
	rep(i,v)cout<<ans[i]<<endl;
}

Measured memory_bytes: 13824
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int q;
    cin >> q;
    vector<int> A;
    for(int i = 0; i < q; i++){
        int x;
        int y;
        cin >> x;
        if(x == 0){
            cin >> y;
            A.push_back(y);
        }else if(x == 1){
            cin >> y;
            cout << A[y] << "\n";
        }else{
            A.pop_back();
        }
    }


    return 0;
}


Measured memory_bytes: 3804
//srinivas
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
// using namespace __gnu_pbds;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define fr(x,in,n,r) for(x=in;x<n;x+=r)
#define ifr(x,n) for(x=0;x<n;x++)
#define dfr(x,n) for(x=n-1;x>=0;x--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pof(a) pop_front(a)
#define pob(a) pop_back(a)
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
typedef long long ll;
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007

struct chash{ 
    ll operator()(ll x) const {return hash<ll>{}(x);}
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt","r",stdin);
    ll n,k;
    cin>>n;
    string s;
    cin>>s;
    ll i,j;
    ll w[n]={0},b[n]={0},x=0,y=0;
    vector<ll> black;
    ifr(i,n)
    	if(s[i]=='#')
    		black.pb(i);
    dfr(i,n)
    {
    	if(s[i]=='#')
    		x++;
    	else
    		y++;
    	w[i]=y;
    	b[i]=x;
    }
    ll sum=black.size();
    ifr(i,black.size()){
    	sum=min(sum,i+w[black[i]]);
    }
    cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 5772
#include<stdio.h>
#include<math.h>

typedef long long ll;

ll keta(ll a){
  int count = 0;
  while(a > 0){
    a/= 10;
    count ++;
  }

  return count-1;
}

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

  int count = 0 , k = 0;
  ll a = n;
  while(a > 0){
    k += a%10; 
    a/= 10;
    count ++;
  }


  ll ans = 9*keta(n) + (n/(long long)pow(10,keta(n)))-1;
  if(k > ans){
    ans = k;
  }

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

  return 0;
}

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

typedef long long ll;

int main(void)
{
    int i,t;
    cin>>t;
    string val;
    vector<string> name;
    for(i = 0; i < t; i++)
    {
        cin>>val;
        name.push_back(val);
    }

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

    name.erase(unique(name.begin(),name.end()),name.end());

    cout<<name.size()<<endl;

    return 0;
}


Measured memory_bytes: 11644
# 2019-11-24 12:12:53(JST)
import sys
from collections import deque

def main():
    n, m = map(int, sys.stdin.readline().split())
    xy = map(int, sys.stdin.read().split())
    xy = zip(xy, xy)


    count = dict((i, 1) for i in range(1, n+1))
    may_contain_red = set([1])

    for x, y in xy:
        count[x] -= 1; count[y] += 1
        if x in may_contain_red:
            may_contain_red.add(y)
            if count[x] == 0:
                may_contain_red -= set([x])
    
    ans = len(may_contain_red)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 35324
#include<stdio.h>
int main()
{
	int a[101], n, i, j,t,sa,sb;
	while(~scanf("%d", &n))
	{
		for(i=0 ; i<n; i++)
			scanf("%d", a+i);
		for(i=0; i<n-1; i++)
			for(j=0; j<n-i-1; j++)
				if(a[j]<a[j+1])
					t = a[j],a[j] = a[j+1],a[j+1] = t;
		sa = sb = 0;
		for(i=0; i<n; i++)
		{
			if(i%2)
				sb+=a[i];
			else
				sa += a[i];
		}
		printf("%d\n", sa - sb);
	}
	return 0;
}

Measured memory_bytes: 128
# https://atcoder.jp/contests/abc153/tasks/abc153_d
H = int(input())

v = H
values = []
while v != 0:
    values.append(v)
    v = v // 2
values = sorted(values)
# print('values', values)

cost = [0 for _ in range(len(values))]
# print('cost', cost)
for i in range(len(cost)):
    if i == 0:
        cost[i] = 1
    else:
        cost[i] = cost[i - 1] * 2 + 1
# print('cost', cost)
print(cost[-1])


Measured memory_bytes: 3060
/*
 * Author       : YangDavid
 * Created Time : 2019年06月01日 星期六 20时16分46秒
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

const int maxn = 22222;
vector<int> G[maxn];
int c[maxn], n, xp, yp, tot, val[maxn], dfs_clock = 0;

void dfs(int v, int fa) {
    for(auto g : G[v]) if(g != fa) dfs(g, v);
    val[v] = c[++dfs_clock];
}

int main() {
    scanf("%d", &n);
    for(int i = 1; i < n; ++i) {
        scanf("%d%d", &xp, &yp);
        G[xp].push_back(yp);
        G[yp].push_back(xp);
    }
    rep(i, n) scanf("%d", &c[i]), tot += c[i];
    sort(c + 1, c + n + 1);
    tot -= c[n];
    dfs(1, -1);
    printf("%d\n", tot);
    rep(i, n) printf("%d%c", val[i], " \n"[i == n]);

    return 0;
}


Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] a = new int[n][m];
        int[] b = new int[m];
        int[] c = new int[n];
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        for(int i = 0; i < m; i++) {
            b[i] = sc.nextInt();
        }
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                c[i] += a[i][j] * b[j];
            }
        }
        for(int d : c) {
            System.out.println(d);
        }
    }
}


Measured memory_bytes: 40472
use std::io;
use std::str::FromStr;

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();

    let mut it = buf.split_whitespace().map(|n| i64::from_str(n).unwrap());
    let (a, b, c) = (it.next().unwrap(), it.next().unwrap(), it.next().unwrap());

    if c >= a && c <= b {
        println!("Yes");
        return;
    }
    println!("No");
    return;
}


Measured memory_bytes: 4352