akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

vector<int> X;
vector< pair<int, int> > roads, rails;
int A[2][200005], L[2][200005], R[2][200005];
int parent[200005], sizex[200005], P[200005];
int BIT[200005], F[200005];

int find_parent(int x)
{
    if(x == parent[x])
        return x;
    
    return parent[x] = find_parent(parent[x]);
}

void unite(int a, int b)
{
    a = find_parent(a);
    b = find_parent(b);

    if(a == b)
        return;
    
    if(sizex[a] > sizex[b])
        swap(a, b);
    
    parent[a] = b;
    sizex[b] += sizex[a];
}

void fillRange(int left, int right, int f)
{
    for(int i=left; i<=right; i++)
        L[f][i] = left, R[f][i] = right;
}

void update(int i, int val)
{
    for(; i<=200000; i+= (i&(-i)))
        BIT[i] += val;
}

int query(int i)
{
    int ans = 0;

    for(; i>0; i-= (i&(-i)))
        ans += BIT[i];

    return ans;
}

void func(vector< pair<int, int> > &edges, int f, int N)
{
    for(int i=1; i<=N; i++)
        parent[i] = i, sizex[i] = 1;
    
    for(auto e : edges)
        unite(e.first, e.second);
    
    vector< pair<int, int> > rep;

    for(int i=1; i<=N; i++)
        rep.push_back({find_parent(i),  i});
    
    int prev = -1, ptr = 0, k = 0;
    sort(rep.begin(), rep.end());

    for(auto r : rep)
    {
        A[f][++k] = r.second;

        if(r.first != prev)
        {
            fillRange(ptr+1, k-1, f);
            ptr = k-1;
        }

        prev = r.first;
    }

    fillRange(ptr+1, k, f);
}

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

    int N, K, M;
    cin >> N >> K >> M;

    roads.resize(K);
    rails.resize(M);

    for(int i=0; i<K; i++)
        cin >> roads[i].first >> roads[i].second;
    for(int i=0; i<M; i++)
        cin >> rails[i].first >> rails[i].second;
    
    func(roads, 0, N);
    func(rails, 1, N);

    for(int i=1; i<=N; i++)
        P[ A[1][i] ] = i;
    
    for(int i=1; i<=N; i=R[0][i]+1)
    {
        int left = L[0][i], right = R[0][i];
        int ptr = left;

        while(ptr <= right)
        {
            int x = P[ A[0][ptr] ];
            update(x, 1);
            X.push_back(x), ptr++;
        }

        for(int j=left; j<=right; j++)
        {
            int x = A[0][j];
            int indx = P[x];
            F[x] = query(R[1][indx]) - query(L[1][indx]-1);
        }

        while(!X.empty())
        {
            update(X.back(), -1);
            X.pop_back();
        }
    }

    for(int i=1; i<=N; i++)
        cout << F[i] << " ";

    return 0;
}


Measured memory_bytes: 12424
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <set>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IFOR for(VI::iterator it = v_inhand(); it != v_inhand.end(); ++it) {}


int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int x = sx, y = sy;
  while (y < ty) {
    ++y;
    cout << "U";
  }
  while (x < tx) {
    ++x;
    cout << "R";
  }
  while (y > sy) {
    --y;
    cout << "D";
  }
  while (x > sx) {
    --x;
    cout << "L";
  }
  --x;
  cout << "L";

  while (y <= ty) {
    ++y;
    cout << "U";
  }
  while (x < tx) {
    ++x;
    cout << "R";
  }
  --y; ++x;
  cout << "DR";
  while (y >= sy) {
    --y;
    cout << "D";
  }
  while (x > sx) {
    --x;
    cout << "L";
  }
  cout << "U" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=1e9;
const long long LINF=1e18;
#define int long long
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  int n;  //セグ木の幅
  F f;  //モノイドの作用
  T ti;  //初期値
  vector<T> dat;  //セグ木で使う配列 一番上に使われるのがdat[1] 一番下の段の左端がdat[n]
  SegmentTree(){};
  SegmentTree(F f,T ti):f(f),ti(ti){}  //fがモノイドとしての作用、tiが初期値

  void init(int n_){  //ただの初期化
    n=1;
    while(n<n_) n<<=1;  //nが実際にとる２べきの幅
    dat.assign(n<<1,ti);  //dat配列は幅の２倍あってその全てにtiを代入
  }

  void build(const vector<T> &v){  //vector vに合わせた初期化
    int n_=v.size();
    init(n_);
    for(int i=0;i<n_;i++) dat[n+i]=v[i];  //v[i]を一番子の所に代入
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);  //iの子供は2*i、2*i+1
  }

  void set_val(int k,T x){  //（0-indexedで）kにxを代入
    dat[k+=n]=x;
    while(k>>=1)  //kがどんどん自分の親になっていく、0になったらおしまい
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
  }

  T query(int a,int b){  //[a,b)の範囲のモノイドの作用を返す
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);  //左端を使いたくなるのはブロックが奇数の時
      if(r&1) vr=f(dat[--r],vr);  //右端〃偶数の時（開区間なのでr:奇数で反応）
    }
    return f(vl,vr);
  }

  template<typename C>
  int find(int st,int v,C &check,T &acc,int k,int l,int r){  //dat[k]:[l,r)の間にいるenを返す
    //下のfind用なので先にそっち読むべき
    //accはst~lとかで確定している値
    if(l+1==r){  //答えがちゃんと存在するならこのlが答え
      acc=f(acc,dat[k]);
      return check(v,acc)?k-n:-1; //入るならk-n(==l)を、入らないなら-1を返す
    }
    int m=(l+r)>>1;  //にぶたんのそれ
    if(m<=st) return find(st,v,check,acc,(k<<1)|1,m,r);  //mがstより後ろなら明らかにl=m;
    if(st<=l&&!check(v,f(acc,dat[k]))){  //今見てるk全部でもダメ(mだと足りないのでl=mにする）
      acc=f(acc,dat[k]);  //kは全部accに加えた上で-1を返す
      return -1;
    }
    int vl=find(st,v,check,acc,(k<<1)|0,l,m);  //まず[l,m)の中にenがいるか探す
    if(~vl) return vl;  //いたならそれを返す(if(~vl)は-1以外にのみ反応する)
    return find(st,v,check,acc,(k<<1)|1,m,r);  //いなかったら[m,r)の中にenがいるのでそれを返す
    //acc=f(acc,dat[k]);がここで効いてる
  }

  template<typename C>
  int find(int st,int v,C &check){
    //check(f(dat[st]~dat[en-1]))=false,check(f(dat[st]~dat[en]))＝trueとなるenを返す
    T acc=ti;
    return find(st,v,check,acc,1,0,n);
  }
};
//main
signed main(){
  int N;cin>>N;
  std::vector<int> v(N),w(N);
  for(int i=0;i<N;i++)cin>>v[i];
  for(int i=0;i<N;i++)w[i]=v[i];
  reverse(w.begin(),w.end());
  auto f=[](int a,int b){return max(a,b);};
  SegmentTree<int> seg(f,0),seg2(f,0);
  seg.build(v);seg2.build(w);
  auto check=[&](int v,int d){return d>v;};
  int ans=0;
  for(int i=0;i<N;i++){
    int idx=seg.find(i,v[i],check);
    int idx2=-1,idx3=-1,idx4=-1;
    if(~idx)idx2=seg.find(idx+1,v[i],check);
    idx3=seg2.find(N-1-i,v[i],check);
    if(~idx3)idx4=seg2.find(idx3+1,v[i],check);
    if(idx3==N-1)idx4=N;
    if(idx==N-1)idx2=N;
    if(idx<0)idx=N;if(idx2<0)idx2=N;
    if(idx3<0)idx3=N;if(idx4<0)idx4=N;
    idx3=N-1-idx3;idx4=N-1-idx4;
    //cout<<idx<<" "<<idx2<<" "<<idx3<<" "<<idx4<<endl;
    ans+=v[i]*((idx2-idx)*(i-idx3)+(idx-i)*(idx3-idx4));
    //cout<<ans<<endl;
  }
  fin(ans);
}


Measured memory_bytes: 5888
#include<iostream>
#include<string.h>
typedef unsigned long long ULL;
using namespace std;

int main(){
  int A,B,M,a[100001],b[100001],x,y,c,i,j,amin=2<<29,bmin=2<<29;
  ULL temp,min;
  cin>>A>>B>>M;
  for(i=0;i<A;i++){
    cin>>a[i];
    if(amin>a[i]) amin=a[i];
  }
  for(i=0;i<B;i++){
    cin>>b[i];
    if(bmin>b[i]) bmin=b[i];
  }
  min=amin+bmin;
  for(i=0;i<M;i++){
    cin>>x>>y>>c;
    temp=a[x-1]+b[y-1]-c;
    if(temp<min) min=temp;
  }
  cout<<min<<endl;
}

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

int main()
{
    long long person, points, seikai;
    map<long long, long long> m;

    long long pass;
    cin >> person >> points >> seikai;
    for (long long i = 0; i < seikai; i++)
    {
        cin >> pass;
        m[pass] += 1;
    }

    long long zero = points - seikai;
    for (long long i = 1; i <= person; i++)
    {
        if (m.count(i) != 0 && m[i] + zero > 0)
        {
            cout << "Yes" << endl;
        }
        else if (zero > 0)
        {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    
    return 0;

}


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

int main() {
  int N;
  cin >> N;
  int p;
  int count = 0;
  for(int i = 1; i <= N; i++) {
    cin >> p;
    if(p != i) count++;
  }
  if(count <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
n, m = gets.chomp.split(" ").map(&:to_i)
human,check,result = [], [], []
flag = 10**9
n.times do
	human.push(gets.chomp.split(" ").map(&:to_i))
end

m.times do
	check.push(gets.chomp.split(" ").map(&:to_i))
end

for i in 0..n-1
	for j in 0..m-1
		kyori = (human[i][0] - check[j][0]).abs + (human[i][1] - check[j][1]).abs
		if flag > kyori
			flag = kyori
			result[i] = j+1
		end
	end
	flag = 10**9
end


puts result.join("\n")

Measured memory_bytes: 1788
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Sun Dec 30 18:16:12 2018
//
package main

import (
	"fmt"
	"strconv"
)

func isPalidrome(s string) bool {
	for i := range s {
		if s[i] != s[len(s)-1-i] {
			return false
		}
	}
	return true
}

func main() {
	var A, B int
	fmt.Scan(&A, &B)

	ans := 0
	for i := A; i <= B; i++ {
		if isPalidrome(strconv.Itoa(i)) {
			ans++
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
	string s;
	cin >> s;
	for(char c:s){
		if(c == '7'){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;
}


Measured memory_bytes: 3624
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a+b==15) System.out.println("+");
        else if(a*b==15) System.out.println("*");
        else System.out.println("x");
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define PB push_back
#define P push
#define sz size()
#define L length()
#define INF 0x7f7f7f7f
#define loop(i,s,e) for(ll i=s;i<=e;i++)
#define rloop(i,s,e) for(ll i=s;i>=e;i--)
#define MEM(a,x) memset(a,x,sizeof a)
using namespace std;
const ll N=1100*3;
ll mem[N][N];
char s[N],t[N];
string ans;
ll n,m;
ll dp(int i,int j){
    if(i==n || j==m) return 0;
    if(mem[i][j]!=-1) return mem[i][j];
    if(s[i]==t[j]) return mem[i][j]=1+dp(i+1,j+1);
    ll p1=-INF,p2=-INF;
    p1=dp(i+1,j);
    p2=dp(i,j+1);
    return mem[i][j]=max(p1,p2);
}
void dp_path(int i,int j){
    if(i==n || j==m) return ;
    if(s[i]==t[j]){
        ans+=s[i];
        dp_path(i+1,j+1);
        return ;
    }
    ll p1=-INF,p2=-INF;
    p1=dp(i+1,j);
    p2=dp(i,j+1);
    if(p1>p2){
        dp_path(i+1,j);
        return ;
    }
    dp_path(i,j+1);
}
main()
{
    scanf("%s%s",&s,&t);
    n=strlen(s); m=strlen(t);
    MEM(mem,-1);
    dp_path(0,0);
    cout<<ans<<endl;
}


Measured memory_bytes: 85632
a, b = map(int, input().split())
s = input()
flg = True
for i in range(a):
    if s[i] == '-':
        flg = False
if s[a] != '-':
    flg = False
for i in range(a + 1, a + b + 1):
    if s[i] == '-':
        flg = False
if flg:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, m;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    cin >> m;
    vector<string> t(m);
    rep(i, m) cin >> t[i];

    map<string, int> map_s, map_t;
    rep(i, n) map_s[s[i]]++;
    rep(i, m) map_t[t[i]]++;

    int res = 0;

    for (auto&& p : map_s) {
        string str = p.first;
        int point = p.second;
        point -= map_t[str];
        res = max(res, point);
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input().strip()
dics = {}
for _s in s:
  if _s in dics:
    dics[_s] += 1
  else:
    dics[_s] = 1

ans = 1
for v in dics.values():
  ans *= v + 1
ans -= 1
print(ans % 1000000007)


Measured memory_bytes: 3188
import java.util.Scanner

import scala.util.control.Breaks

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt()
  val Y = sc.nextInt()

  var ans = ""
  val b = new Breaks

  b.breakable {
    for (i <- 0 to N) {
      for (j <- 0 to N - i) {
        for (k <- 0 to N - i - j) {
          if (i * 10000 + j * 5000 + k * 1000 == Y && i + j + k == N) {
            ans = i + " " + j + " " + k
            b.break
          }
        }
      }
    }
  }
  if (ans == "") ans = "-1 -1 -1"
  println(ans)

}


Measured memory_bytes: 56856
import sys
input = sys.stdin.readline
def print_ans(N,B):
    """Test Case
    >>> print_ans(3,"2 5")
    9
    >>> print_ans(2,"3")
    6
    >>> print_ans(6,"0 153 10 10 23")
    53
    """
    B_arr = list(map(int,B.split()))
    A_arr = [0] * N
    for i in range(N - 1):
        A_arr[i + 1] = B_arr[i]
        if i == 0:
            A_arr[i] = B_arr[i]
        else:
            A_arr[i] = min(A_arr[i],B_arr[i])
    print(sum(A_arr))
if __name__ == '__main__':
    N = int(input().rstrip())
    B = input().rstrip()
    print_ans(N,B)

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

using namespace std;
 
int main()
{

    int N;
    cin >> N;
    vector<int> A(N);

    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    
    sort(A.begin(), A.end());

    cout << A.at(N-1) - A.at(0) << endl;
}

Measured memory_bytes: 764
// Problem : D - Leaping Tak
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 998244353
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
int dp[maxn],n,k;
void update(int idx,int val){
	for(int i=idx;i<=n;i+=(i&-i))
	{
		dp[i] += val;
		dp[i] %= mod;
	}
}
int query(int idx)
{
	int sum = 0;
	for(int i=idx;i>0;i-=(i&-i))
	{
		sum += dp[i];
		sum %= mod;
	}
	return sum;
}
void solve()
{
	cin >> n >> k;
	vector<pp> v(k);
	for(int i=0;i<k;i++)
	{
		int x,y;
		cin >> x >>  y;
		v[i] = {x,y};
	}
	sort(all(v));
	update(1,1);
	for(int i=2;i<=n;i++)
	{
		int ans = 0;
		for(int j=0;j<k;j++)
		{
			int l = v[j].ff,r=v[j].ss;
			int x = i-l;
			if(x <= 0)
				break;
			int y = max((int)1,i-r);
			y--;
			int tmp = query(x);
			tmp -= query(y);
			tmp += mod;
			tmp %= mod;
			ans += tmp;
			ans %= mod;
		}
		update(i,ans);
		if(i== n)
		{
			cout << ans ;
			return;
		}
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


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

int main()
{
    long long int a, b, x, ans;

    cin>>a>>b>>x;
    ans = (a % x == 0) ? (((b / x) - (a / x)) + 1) : ((b / x) - (a / x));
    cout<<ans<<endl;

}


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

int main(){
    int S;
    cin >> S;
    
    int former = S / 100;
    int latter = S % 100;

    if(former <= 12 && latter <= 12 && 0 < former && 0 < latter){
        cout << "AMBIGUOUS" << endl;
    }else if(former <= 12 && 0 < former){
        cout << "MMYY" << endl;
    }else if(latter <= 12 && 0 < latter){
        cout << "YYMM" << endl;
    }else{
        cout << "NA" << endl;
    }

}

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

const int MOD = 1e9+7;
const int mxN = 300005;

int N,M;

vector<int>adj[mxN];
bool visited[mxN];

int dist[mxN];

void init()
{
    for(int i = 0 ; i < mxN; i++)
    {
        visited[i] = false;
        dist[i] = 0;
    }
}

void printVec(vector<int>V)
{
    for(int i = 0; i < V.size(); i++)
        cout<<V[i]<<" ";
    cout<<endl;
}

void dfs(int s)
{
    visited[s] = true;

    cout<<s<<" ";

    for(int i = 0 ; i < adj[s].size(); i++)
        if(!visited[adj[s][i]])
            dfs(adj[s][i]);
}

void bfs(int s)
{
    queue<int>q;

    visited[s] = true;

    q.push(s);

    while(!q.empty())
    {
        int p = q.front();
        q.pop();

        //cout<<p<<" ";

        for(int i = 0; i < adj[p].size(); i++)
        {
            if(!visited[adj[p][i]])
            {
                visited[adj[p][i]] = true;
                dist[adj[p][i]] = dist[p] + 1;
                q.push(adj[p][i]); 
            }
        }
    }
}

void solve()
{
    init();

    cin>>N>>M; //nodes and edges

    int x,y;

    for(int i = 0; i < M ;i++)
    {
        cin>>x>>y;
        adj[x].pb(y + N);
        adj[x + N].pb(y + 2*N);
        adj[x + 2*N].pb(y);
    }

    int src,dest;
    cin>>src>>dest;

    bfs(src);
    //cout<<endl;

    if(visited[dest])
        cout<<dist[dest]/3<<endl;
    else
        cout<<-1<<endl;
}

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

    solve();

    return 0;
}

Measured memory_bytes: 21492
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC161A
{
    class Program
    {
        static void Main(string[] args)
        {
            var B = RInt;
            var C = RInt;
            var A = RInt;

            Console.WriteLine(A + " " + B + " " + C);
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D<T>(T[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            string[,] map2 = new string[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0.ToString();
                    else if (i == 0) map2[i, j] = (j - 1).ToString();
                    else if (j == 0) map2[i, j] = (i - 1).ToString();
                    else map2[i, j] = map[i - 1, j - 1].ToString();
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j].Last());
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D<T>(T[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 27820
fn main() {
    let mut buf = String::new();
    let handle = std::io::stdin();
    let n: usize = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf.trim().parse().unwrap();
        buf.clear();
        tmp
    };
    let mut hs: Vec<usize> = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf
            .trim()
            .split_whitespace()
            .map(|a| a.parse().unwrap())
            .collect();
        buf.clear();
        tmp
    };
    let mut left = hs.iter().filter(|&&a| a != 0).count();
    let mut count = 0;
    loop {
        if left == 0 {
            break;
        }
        let (index, length) = find_tops(&hs);
        for i in index..index + length {
            hs[i] -= 1;
            if hs[i] == 0 {
                left -= 1;
            }
        }
        count += 1;
    }
    println!("{}", count);
}
fn find_tops(hs: &Vec<usize>) -> (usize, usize) {
    let mut i = 0;
    let mut length = 1;
    let mut start = 0;
    loop {
        if i == hs.len() {
            break;
        }
        let next = hs.get(i + 1);
        match next {
            Some(&h) => {
                if hs[i] < h {
                    i += 1;
                    start = i;
                    length = 1;
                    continue;
                } else if hs[i] == h {
                    i += 1;
                    length += 1;
                } else if hs[i] > h {
                    break;
                }
            }
            None => { break; }
        }
    }
    (start, length)
}


Measured memory_bytes: 4352
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def f(l, r, kousa=1):
    n = (r - l) // kousa
    return (r + l) * (n + 1) // 2

def solve():
    N = II()

    ans = 0
    for i in range(1, N+1):
        mx = i * (N // i)
        if mx == 0: mx = i
        # print(i, mx, f(i, mx, i))
        ans = ans + f(i, mx, i)

    print(ans)

if __name__ == '__main__':
    solve()


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

int main() {
    long long n,monster = 0,sum = 0;
    cin >> n;
    vector<int> city(n+1);
    vector<int> hero(n);
    for (int i = 0; i < n+1; i++){
        cin >> city.at(i);
        monster += city.at(i);
    }
    for (int i = 0; i < n; i++){
        cin >> hero.at(i);
    }
    for (int i = 0; i < n; i++){
        if(city.at(i) <= hero.at(i)){
        hero.at(i) -=city.at(i);
        city.at(i) = 0;
        }else{
            city.at(i) -= hero.at(i);
            hero.at(i) = 0;
            continue;
        }
        if(city.at(i+1) <= hero.at(i)){
        hero.at(i) -=city.at(i+1);
        city.at(i+1) = 0;
        }else{
            city.at(i+1) -= hero.at(i);
            hero.at(i) = 0;
            continue;
        }
    }
    for (int i = 0; i < n+1; i++){
        sum += city.at(i);
    }
    cout << monster - sum << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
  int K,S;
  cin >>  K >> S;
  int ans = 0;
  for(int i=0;i<=K;i++){
  for(int j=0;j<=K;j++){
  int l = S-i-j;
    if(0<=l && l <= K){
    ans++;
    }
  
  }}
  
  cout <<  ans;
return 0;
  
}

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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N, M;
    cin >> N >> M;
    ll Ai;
    ll sum = 0;
    for(int i=0;i<M;i++){
        cin >> Ai;
        N -= Ai;
    }
    if(N<0) cout << "-1" <<endl;
    else    cout << N << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>

#define int long long
#define p (int)(1e9 + 7)

signed main(){
	int N, i, ans, prev;
	scanf("%lld", &N);
	char *S1 = (char *)malloc(sizeof(char) * (N + 1));
	char *S2 = (char *)malloc(sizeof(char) * (N + 1));
	scanf("%s", S1);
	scanf("%s", S2);
	if(S1[0] == S2[0]){
		ans = 3;
		i = 1;
		prev = 0;
	}
	else{
		ans = 6;
		i = 2;
		prev = 1;
	}
	for(; i < N; i++){
		if(prev == 0){
			if(S1[i] == S2[i]){
				ans = (ans * 2) % p;
				prev = 0;
			}
			else{
				ans = (ans * 2) % p;
				i++;
				prev = 1;
			}
		}
		else{
			if(S1[i] == S2[i]){
				prev = 0;
			}
			else{
				ans = (ans * 3) % p;
				i++;
				prev = 1;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
import Control.Monad

data Grids = Grids Int Int [String]

grid :: Grids -> Int -> Int -> Char
grid (Grids _ _ grids) i j = (grids !! i) !! j

right :: Grids -> Int -> Int -> [Char]
right grids@(Grids _ w _) i j
  | j < (w - 1) = [grid grids i (j + 1)]
  | otherwise   = []

left :: Grids -> Int -> Int -> [Char]
left grids i j
  | 0 < j     = [grid grids i (j - 1)]
  | otherwise = []

up :: Grids -> Int -> Int -> [Char]
up grids i j
  | 0 < i     = [grid grids (i - 1) j]
  | otherwise = []

down :: Grids -> Int -> Int -> [Char]
down grids@(Grids h _ _) i j
  | i < (h - 1) = [grid grids (i + 1) j]
  | otherwise   = []

neighbors :: Grids -> Int -> Int -> [Char]
neighbors grids i j = right grids i j ++ left grids i j ++ up grids i j ++ down grids i j

isBlack :: Grids -> Int -> Int -> Bool
isBlack grids i j = grid grids i j == '#'

isAllNeighborsWhite :: Grids -> Int -> Int -> Bool
isAllNeighborsWhite grids i j = all (== '.') $ neighbors grids i j

solve :: Int -> Int -> [String] -> Bool
solve h w g = null blackAndAllNeighborsWhite
  where grids = Grids h w g
        points = [(i, j) | i <- [0..(h - 1)], j <- [0..(w - 1)]]
        blacks = filter (\(i, j) -> isBlack grids i j) points
        blackAndAllNeighborsWhite = filter (\(i, j) -> isAllNeighborsWhite grids i j) blacks

main :: IO ()
main = do
  [h, w] <- map read . words <$> getLine
  grids <- replicateM h getLine
  putStrLn $ if solve h w grids then "Yes" else "No"

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

int main(){
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == '9') cout << 1;
        else if (s[i] == '1') cout << 9;
        else cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 764
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        //bytesのiterを生成
        .bytes()
        //それをas charでchar型に変換したiterを生成
        .map(|c| c.expect("failed to read char") as char)
        //c.is_whitespace()がfalseになるまで（つまり普通の文字が出るまで）iterを進めたiterを生成
        .skip_while(|c| c.is_whitespace())
        // !c.is_whitespace()がtrue, 即ち（普通の文字の間）iterを進め, 進んだところまでのiterを生成
        .take_while(|c| !c.is_whitespace())
        // それをcollect()してiterからStringを作る
        .collect();
    // parse()で任意の型に変換して返す。
    token.parse().ok().expect("failed to parse token")
}

fn read_one_line_to_vec<T: FromStr>() -> Vec<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let v: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c == &'\x0d' || c == &'\x0a')
        .take_while(|c| !(c == &'\x0d' || c == &'\x0a'))
        .collect();
    v.split_whitespace()
        .map(|c| { let string = c.to_string();
            string.parse::<T>().ok().expect("failed to parse token")})
        .collect()
}

fn main() {
    let n: usize = read();
    let h: Vec<i32> = read_one_line_to_vec();

    let mut m = -1;
    for i in h.iter().rev() {
        if m == -1 {
            m = *i
        }
        else if m + 2 <= *i{
            println!("No");
            return;
        }
        if m > *i {
            m = *i;
        }
    }
    println!("Yes")
}

Measured memory_bytes: 6396
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<queue>
#include<string>
using namespace std;

int main(){

	int H, W;
	cin >> H >> W;
	vector<string>S(H);

	for (int i = 0; i < H; i++)
		cin >> S[i];

	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			if (S[i][j] == '.'){
				int count = 0;
				for (int k = -1; k <= 1; k++)
					for (int l = -1; l <= 1; l++)
						if (i+k>=0&&i+k<H&&j+l>=0&&j+l<W&&S[i + k][j + l] == '#')
							count++;
				S[i][j] = to_string(count).data()[0];
			}
		}
	}

	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++)
			cout << S[i][j];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	W, H, N := getInt(), getInt(), getInt()
	X := make([]int, W)
	Y := make([]int, H)
	for i := 0; i < N; i++ {
		x, y, a := getInt(), getInt(), getInt()
		switch a {
		case 1:
			for j := 0; j < x; j++ {
				X[j] = 1
			}
		case 2:
			for j := x; j < W; j++ {
				X[j] = 1
			}
		case 3:
			for j := 0; j < y; j++ {
				Y[j] = 1
			}
		case 4:
			for j := y; j < H; j++ {
				Y[j] = 1
			}
		}
	}
	ans := 0

	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if X[j] == 0 && Y[i] == 0 {
				ans++
			}
		}
	}
	out(ans)
}


Measured memory_bytes: 1780
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define fi first
#define se second
#define pii pair<int,int>
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
#define LONGLONG_MAX 10000000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(auto a,long long b){
    long long ans=1;
    //cout<<ans;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    ///cout<<ans<<" ";    
    return ans;
        
}
void maxi(auto &a,auto b){
    a=max(a,b);
}
void mini(auto &a,auto b){
    a=min(a,b);
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    cout<<(n*(n-1))/2;
    return 0;
}

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

#ifdef _DEBUG
#define ASSERT(x) cassert(x)
#define DLOG(x) cout << #x " " << x << endl;
#else
#define ASSERT(x)
#define DLOG(x)
#endif

using namespace std;

int insertSort(vector<int>& arr, int step) {
  int cnt = 0;
  for (auto i = step; i < arr.size(); ++i) {
    auto j = i - step;
    auto v = arr[i];
    for (; j >= 0 && arr[j] > v; j -= step) {
      arr[j + step] = arr[j];
      ++cnt;
    }
    arr[j + step] = v;
  }
  return cnt;
}

vector<int> makeSteps(int n) {
  vector<int> steps;
  for (int v = 1; v <= n; v *= 4) {
    steps.push_back(v);
  }
  sort(steps.begin(), steps.end(), greater<int>()); 
  return steps;
}

int main() {
  int n;
  cin >> n;
  vector<int> arr;
  arr.reserve(n);
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    arr.push_back(t);
  }
  auto steps = makeSteps(arr.size());
  int cnt = 0;
  for (auto step : steps) {
    cnt += insertSort(arr, step);
  }
  cout << steps.size() << endl;
  bool first = true;
  for (auto step : steps) {
    if (!first) {
      cout << " ";
    }
    first = false;
    cout << step;
  }
  cout << endl << cnt << endl;
  for (auto v : arr) {
    cout << v << endl;
  }
}



Measured memory_bytes: 6744
#include <stdio.h>

int main()
{
    int N, A, B;
    1 <= N <= 20;
    1 <= A <= 50;
    1 <= B <= 50;

    scanf("%d %d %d", &N, &A, &B);

    if (N * A <= B)
    {
        printf("%d\n", N * A);
    }
    else
    {
        printf("%d\n", B);
    }
    return 0;
}

Measured memory_bytes: 128
n, m, l = map(int, input().split())
x = [[] for _ in range(n)]
dp = [[n*10**9 for _ in range(n)] for _ in range(n)]
for _ in range(m):
  a, b, c = map(int, input().split())
  if c <= l:
    x[a-1].append(b-1)
    x[b-1].append(a-1)
    dp[a-1][b-1] = c
    dp[b-1][a-1] = c
q = int(input())
st = []
for _ in range(q):
  st.append(list(map(int, input().split())))
dp[0][0] = 0
for i in range(1,n):
  dp[i][i] = 0
  for j in range(i):
    for a in x[i]:
      dp[i][j] = min(dp[i][j],dp[i][a]+dp[a][j])
    dp[j][i] = dp[i][j]
  for j in range(i):
    for k in range(i):
      dp[j][k] = min(dp[j][k],dp[j][i]+dp[i][k])
dp2 = [[n for _ in range(n)] for _ in range(n)]
for i in range(n):
  for j in range(n):
    if dp[i][j] <= l:
      dp2[i][j] = 1
for i in range(1,n):
  for j in range(i):
    for k in range(i):
      dp2[i][j] = min(dp2[i][j],dp2[i][k]+dp2[k][j])
    dp2[j][i] = dp2[i][j]
  for j in range(i):
    for k in range(i):
      dp2[j][k] = min(dp2[j][k],dp2[j][i]+dp2[i][k])
for u in st:
  ans = dp2[u[0]-1][u[1]-1]
  if ans >= n:
    print(-1)
  else:
    print(ans-1)

Measured memory_bytes: 80600
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

typedef pair<string,int> P;

int main(void){

  int n,t;

  cin >> n >> t;

  char ch;
  vector<string>a(n),b(n);
  vector<int>ha(n),hb(n),ma(n),mb(n);
  for(int i=0;i<n;i++){
    cin >> ha[i] >> ch >> ma[i] >> a[i];
    cin >> hb[i] >> ch >> mb[i] >> b[i];
  }

  vector<P>ans;
  for(int i=0;i<n-1;i++){
    int time=(ha[i+1]*60+ma[i+1])-(hb[i]*60+mb[i]);
    if(time>=t)ans.push_back(P(b[i],time));
  }

  cout << ans.size() << endl;
  for(int i=0;i<ans.size();i++)
    cout << ans[i].first << " " << ans[i].second << endl;

  return 0;
}

Measured memory_bytes: 1220
<?php
fscanf(STDIN,"%d %d %d",$N, $A, $B);
$ans = 0;
$max = $A - $B;
if($max > 0) {
    $max = $A - $max;
}else{
    $max = $B - abs($max);
}
$min = $N - $A - $B;
if($min > 0) {
    $min = 0;
}else{
    $min = abs($min);
}

echo $max." ".$min;
?>

Measured memory_bytes: 3700
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>

using namespace std;

int main(){
    
    long long a, b, k;
    cin >> a >> b >> k;
    if(k>=a+b){
        cout << "0 0" << endl;
    }
    else {
        if(a>=k){
            a = a-k;
            cout << a << " " << b << endl;
        }
        else{
            k = k-a;
            b = b-k;
            cout << "0" << " " << b << endl;
        }
    }
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vst;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=(1e+9)+7;
const ll inf=1e+16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

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

 ll n;
  string s;
  cin >> n >> s;
  
  vll black(n+1,0),white(n+1,0);
  rep(i,0,n) {
   if(s[i]=='#') black[i+1]++;
   else white[i+1]++;
    black[i+1]+=black[i];
    white[i+1]+=white[i];
  }
  ll res=inf;
  
  rep(i,0,n+1) res=min(res,black[i]+white[n]-white[i]);

  cout << res << endl;
  
}


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

int main()
{
  int H, W, M, h, w;
  cin >> H >> W >> M;
  set<pair<int, int>> st;
  vector<int64_t> R(H, 0), C(W, 0), hs(M), ws(M);
  for (int i = 0; i < M; i++)
  {
    cin >> h >> w;
    h--, w--;
    R.at(h)++;
    C.at(w)++;
    hs.at(i) = h;
    ws.at(i) = w;
    st.insert({h, w});
  }
  priority_queue<pair<int, int>> pqr, pqc;
  for (int i = 0; i < H; i++)
  {
    pqr.push({R[i], i});
  }
  for (int i = 0; i < W; i++)
  {
    pqc.push({C[i], i});
  }
  int64_t tr = pqr.top().first, tc = pqc.top().first;
  int64_t ans = tr + tc;
  vector<int> vr, vc;
  while (pqr.size() && pqr.top().first == tr)
  {
    vr.push_back(pqr.top().second);
    pqr.pop();
  }
  while (pqc.size() && pqc.top().first == tc)
  {
    vc.push_back(pqc.top().second);
    pqc.pop();
  }
  int n = vr.size(), m = vc.size();
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < m; j++)
    {
      if (!st.count({vr[i], vc[j]}))
      {
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans - 1 << endl;
}


Measured memory_bytes: 35772
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; i++)
using namespace std;
typedef pair<int, int> P;
struct edge {
	int to, cost;
};
class dijkstra {
  private:
	int V;
	int d[100002];
	priority_queue<P, vector<P>, greater<>> que;

  public:
    dijkstra(int v, int s, vector<edge> G[]) {
        V = v;
        update(s, G);
    }

    void update(int s, vector<edge> G[]) {
        fill(d, d + V + 1, 100000000000ll);
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first)
                continue;
            rep(i, G[v].size()) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }
    }

	int find(int e) {
		return d[e];
	}
};

int gcd(int a, int b) {
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool prime(int a) {
	if (a == 1)
		return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0)
			return false;
	}
	return true;
}

class Union_Find {
  private:
	vector<int> t, s;

  public:
	Union_Find(int max_length) {
		rep(i, max_length + 1) {
			t.push_back(i);
			s.push_back(1);
		}
	}

	void Union(int x, int y) {
		if (same(x, y))
			return;
		int tx = Find(x), ty = Find(y);
		if (s[tx] < s[ty]) {
			s[ty] += s[tx];
			t[tx] = ty;
		}
		else if (s[tx] > s[ty]) {
			s[tx] += s[ty];
			t[ty] = tx;
		}
		else if (tx > ty) {
			t[tx] = ty;
			s[ty] += s[tx];
		}
		else {
			t[ty] = tx;
			s[tx] += s[ty];
		}
	}

	int Find(int n) {
		if (t[n] == n)
			return n;
		else
			return t[n] = Find(t[n]);
	}

	bool same(int x, int y) {
		return Find(x) == Find(y);
	}

	int get_Size(int a) {
		return s[a];
	}
};

vector<int> primeFactorization(int n) {
	vector<int> re;
	int cnt = 2;
	while (n != 1) {
		if (n % cnt != 0) {
			cnt++;
			continue;
		}
		n /= cnt;
		re.push_back(cnt);
	}
	return re;
}

signed main() {
	int n;
	cin >> n;
	vector<P> vec(n);
	rep(i, n) cin >> vec[i].second >> vec[i].first;
	sort(vec.begin(), vec.end(), greater<>());
	int time = 1000000012;
	rep(i, n) {
		time = min(vec[i].first, time);
		time -= vec[i].second;
	}
	if (time < 0)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
}


Measured memory_bytes: 3328
#include<iostream>
#include<string>
using namespace std;
int main(){
	string a;
	while(getline(cin,a)){
		int i=0;
		while(true){
			bool t=false;
			if(a[i]=='@'){
				for(int j=0;j<a[i+1]-'0';j++)
					cout<<a[i+2];
				i+=2;
				if(i>=a.size())
				break;
				t=true;
			}
			if(i>=a.size())
				break;
			if(t==false)
				cout<<a[i];
			i++;
			if(i>=a.size())
				break;
		}
		cout<<endl;
	}
	return 0;
}

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

from collections import defaultdict

dic=defaultdict(int)
for i in range(N):
    dic[A[i]]+=1

summ=sum(A)

for i in range(Q):
    B,C=map(int,input().split())
    summ+=(C-B)*dic[B]
    dic[C]+=dic[B]
    dic[B]=0
    print(summ)

Measured memory_bytes: 23840
import sys
import itertools as it

a = [row for row in map(lambda i:list(map(int, input().split())), range(3))]
n = int(input())
b = [int(input()) for i in range(n)]

res = False
for row in a:
    if all(i in b for i in row):
        res = True
for j in range(3):
    if all(a[i][j] in b for i in range(3)):
        res = True
if all(a[i][i] in b for i in range(3)):
    res = True
if all(a[i][2 - i] in b for i in range(3)):
    res = True

print('Yes' if res else 'No')


Measured memory_bytes: 8964
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()
	S = input()
	S = S[:-1]

	if N % 2 == 1:
		print("No")
		sys.exit()

	tmp = int(N / 2)
	if S[:tmp] == S[tmp:]:
		print("Yes")
	else:
		print("No")

if __name__ == "__main__":
	main()


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

int main() {
  int N, K, A = 1;
  cin >> N;
  cin >> K;
  for(int i = 0; i < N; i++){
    if(A + K < 2 * A){
      A = A + K;
      continue;
    }
    A = A * 2;
  }
  cout << A;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;


ll dp[100010][13];
void solve(std::string S){
  dp[0][0]=1;
  ll n = S.size();
  for(ll i=0; i<n; i++) {
    char x = S[i];
    ll s = (x=='?' ? 0 : x-'0');
    ll g = (x=='?' ? 9 : x-'0');
    for(ll j=s; j<=g; j++) {
      for(ll k=0; k<13; k++) {
	dp[i+1][(k*10+j) % 13] += dp[i][k];
	dp[i+1][(k*10+j) % 13] %= MOD;
      }
    }
  }
  std::cout << dp[n][5] << std::endl;
}

int main(){
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}



Measured memory_bytes: 10624
while(1):
    H, W = map(int, input().split())
    if H==0 and W==0:
        break
    for h in range(H):
        line = ""
        for w in range(W):
            if (h in range(1,H-1)) and (w in range(1,W-1)):
                line += "."
            else:
                line += "#"
        print(line)
    print("")

Measured memory_bytes: 7668
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[MAX][MAX];
void dijkstra(){
    int minv;
    int d[MAX],color[MAX];
    for(int i=0;i<n;i++){
        d[i]=INFTY;
        color[i]=WHITE;
    }
    d[0]=0;
    color[0]=GRAY;
    while(1){
        minv=INFTY;
        int u=-1;
        for(int i=0;i<n;i++){
            if(minv>d[i]&&color[i]!=BLACK){
                u=i;
                minv = d[i];
            }
        }
        if(u==-1) break;
        color[u]=BLACK;
        for(int v=0;v<n;v++){
            if(color[v]!=BLACK&&M[u][v]!=INFTY){
                if(d[v]>d[u]+M[u][v]){
                    d[v]=d[u]+M[u][v];
                    color[v]=GRAY;
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        cout << i <<" "<<(d[i]==INFTY ? -1:d[i])<<endl;
    }
}

int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            M[i][j]=INFTY;
        }
    }
    int k,c,u,v;
    for(int i=0;i<n;i++){
        cin>>u>>k;
        for(int j=0;j<k;j++){
            cin>>v>>c;
            M[u][v]=c;
        }
    }
    dijkstra();
    return 0;
}


Measured memory_bytes: 3136
import java.util.Scanner;

public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
       int sum = 0;
        for(int i = a; i <= b; i++ ){
            
        if(c%i==0)
        sum ++;
        }
        System.out.println(sum);
        sc.close();
    }
} 



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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  set<pair<int, int>> s;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    s.insert(make_pair(b, a));
  }
  int ans = 0;
  int end = 1;
  for (auto p: s) {
    if (p.second >= end) {
      ans++;
      end = p.first;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4992
import java.util.*;

class Main{
	static int[] swi = new int[11];

	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] k = new int[m];
		int[][] s = new int[m][];
		for(int i = 0; i < m; i++){
			k[i] = sc.nextInt();
			s[i] = new int[k[i]];
			for(int j = 0; j < k[i]; j++){
				s[i][j] = sc.nextInt()-1;
			}
		}
		int[] p = new int[m];
		for(int i = 0; i < m ; i++){
			p[i] = sc.nextInt();
		}
		int ans = 0;
		for(int i = 0; i < Math.pow(2,n); i++){
			pra();
			/*for(int aaa : swi){
				System.out.print(aaa);
			}
			System.out.println();*/
			int ba = 0;
			int sumsum = 0;
			for(int j = 0; j < m; j++){
				int sum = 0;
				for(int l = 0; l < k[j]; l++){
					if(swi[s[j][l]] == 1){
						sum++;
					}
				}
				if(sum%2 == p[j]){
					sumsum++;
				}
			}
			if(sumsum == m){
				ans++;
			}
		}
		System.out.print(ans);
	}

	static void pra(){
		int idx = 0;
		while(true){
			if(swi[idx] == 0){
				swi[idx] = 1;
				break;
			}else{
				swi[idx] = 0;
				idx++;
			}
		}
	}
}


Measured memory_bytes: 23636
#include <stdio.h>

int main()
{
    char a;
    scanf("%c", &a);

    if (a == 'A') {
        printf("T\n");
    } else if (a == 'T') {
        printf("A\n");
    } else if (a == 'C') {
        printf("G\n");
    } else if (a == 'G') {
        printf("C\n");
    }

    return 0;
}

Measured memory_bytes: 128