akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main(){
    char S[101];
    cin >> S;
    
    for(int i = 0; S[i] != '\0'; i++){
        if(i % 2 == 0){
            if(S[i] == 'L'){
                cout << "No" << endl;
                return 0;
            }
        }else{
            if(S[i] == 'R'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    
    cout << "Yes" << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int r=0,l=0;
  string s;
  cin>>s;
  for(int i=0;i<n;i++){
    if(s[i]=='('){
      l++;
    }else{
      if(l>0){
        l--;
      }else{
        r++;
      }
    }
  }
  for(int i=0;i<r;i++){
    cout<<'(';
  }
  cout<<s;
  for(int i=0;i<l;i++){
    cout<<')';
  }
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
b = inpl()
c = inpl()
a.sort()
b.sort()
c.sort()
lb = [0] * n
res = 0
for i in range(n):
    tmp = bisect.bisect_right(b,a[i])
    if tmp == n: continue
    lb[tmp] += 1
llb = list(itertools.accumulate(lb))
# print(lb,llb)
rr = [0] * n
for i in range(n):
    tmp = bisect.bisect_right(c,b[i])
    if tmp == n: continue
    rr[tmp] += llb[i]
print(sum(list(itertools.accumulate(rr))))

Measured memory_bytes: 30272
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def check(S):
    T = S[::-1]
    return S == T

S = input()
N = len(S)

S1 = S[:N//2]
S2 = S[N//2+1:]
if check(S) and check(S1) and check(S2):
    Yes()
else:
    No()


Measured memory_bytes: 3064
var
  n,m,q,x,y,i,j:longint;
  b,a:array[0..1000,0..1000]of longint;
begin
  readln(n,m,q);
  for i:=1 to m do
  begin
    readln(x,y);
    inc(a[x,y]);
  end;
  for i:=n downto 1 do
    for j:=1 to n do
      b[i,j]:=a[i,j]+b[i+1,j]+b[i,j-1]-b[i+1,j-1];
  for i:=1 to q do
  begin
    readln(x,y);
    writeln(b[x,y]);
  end;
end.

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set

                                            /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }

    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }

    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }

    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

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

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
        return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21736
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;

int a,b,c;

int main(){
    cin>>a>>b>>c;
    int s = max(a,b);
    s = max(s,c);
    cout<<9*s+a+b+c<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define tll tuple<ll, ll, ll>
#define all(c) c.begin(),c.end()

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
 
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;

//vector<ll> g[202020];
//fill(score, score+202020, 0);
//vector<ll> v[505];

int main(){
  ll n;
  cin >> n;
  DEBUG(n);
  set<ll> s;
  for (int i=0;i<n;i++){
    ll tmp;
    cin >> tmp;
    s.insert(tmp);
  }
  for (auto it=s.begin();it!=s.end();++it) DEBUG(*it);
  
  cout << s.size() << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = sum(a)
for i in range(n):
    if a[i] <= b[i]:
        b[i] -= a[i]
        a[i] = 0
    else:
        a[i] -= b[i]
        b[i] = 0
    if a[i+1] <= b[i]:
        b[i] -= a[i]
        a[i+1] = 0
    else:
        a[i+1] -= b[i]
        b[i] -= a[i+1]
print(m - sum(a))


Measured memory_bytes: 18624
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define dbg_v(v) cout<<#v<<":";for(int i=0;i<(int)v.size();i++) cout<<" "<<v[i]; cout<<endl;
int power(ll x,ll y){ll res = 1;while(y>0){if(y&1)res = (res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int main(){ 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	int n;
	cin>>n;
	n=n%10;
	if(n==0||n==1||n==6||(n==8))
		cout<<"pon\n";
	else if(n==3)
		cout<<"bon\n";
	else
		cout<<"hon\n";
}



Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> x(n);
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    int sum=1000000000;
    for(int i=1;i<=100;i++){
        int tmp=0;
        for(int j=0;j<n;j++){
            tmp+=(x[j]-i)*(x[j]-i);
        }
        sum=min(sum,tmp);
    }
    cout<<sum<<endl;
    return 0;
}


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

int gcd(int x, int y){
	if(y == 0){
		return x;
	}
	return gcd(y, x%y);
}

int main(){
	int x,y;
	cin >> x >> y;
	int GCD = gcd(x, y);
		
	cout << GCD << endl;
	return 0;
}
		


Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    int N; cin >> N;
    vector<int> a(N);
    bool ok = false;
    rep(i,N){
        cin >> a[i];
        if(a[i] % 2 == 1) ok = true;
    }
    if(ok) cout << "first" << endl;
    else cout << "second" << endl;

}

    



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); i++)
#define rrep(i, to) for (int i = to - 1; i >= 0; i--)
#define repf(i, from, to) for (int i = (from); i < (to); i++)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

struct Point {
  int x;
  int y;
};

double dist(Point from, Point to) {
  int dx = to.x - from.x;
  int dy = to.y - from.y;

  double dist = sqrt(dx * dx + dy * dy);
  return dist;
}

int main() {
  int n;
  V<Point> grid;
  cin >> n;
  grid.resize(n);

  rep(i, n) {
    cin >> grid[i].x >> grid[i].y;
  }
  V<int> p(n, 0);
  rep(i, n) {
    p[i] = i;
  }

  double len = 0;
  int count = 0;

  do {
    rep(i, n - 1) {
      int from = p[i];
      int to = p[i + 1];
      len += dist(grid[from], grid[to]);
    }
    count++;
  } while(next_permutation(p.begin(), p.end()));


  double ans = len / count;

  printf("%.9f\n", ans);
}


Measured memory_bytes: 3792
n =gets.to_i
a = gets
b = gets
c = gets
num = 0
n.times do |i|
  if  a[i] == b[i] 
    if a[i]  == c[i] 
       num += 0
    else num += 1
    end
  elsif  b[i] == c[i]
     num += 1
  elsif a[i] == c[i]
     num += 1
  else num += 2
end 
end
puts num


Measured memory_bytes: 1788
#include<iostream>
#include<string.h>
using namespace std;

int main(){
  int i,j;
  char str[128],ans[8]="keyence";
  cin>>str;
  if(strlen(str)<strlen(ans)){
    cout<<"NO"<<endl;
    return 0;
  }
  
  for(i=0;i<7;i++){
    if(str[i]!=ans[i])break;
    if(i==6){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  for(j=0;j<7;j++){
    if(str[strlen(str)-1-j]!=ans[6-j])break;
    if(j==6){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  if(i+j>=7)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int A,B; cin>>A>>B;
  cout<<100<<" "<<100<<endl;
  vector<vector<char>> S(50,vector<char>(100,'#')),T(50,vector<char>(100,'.'));
  A--;
  B--;
  rep(i,0,25){
    rep(j,0,50){
      if(A==0) break;
      S[i*2][j*2]='.';
      A--;
    }
  }
  rep(i,0,25){
    rep(j,0,50){
      if(B==0) break;
      T[i*2][j*2]='#';
      B--;
    }
  }
  rep(i,0,50){
    rep(j,0,100) cout<<S[i][j];
    cout<<endl;
  }
  rep(i,0,50){
    rep(j,0,100) cout<<T[49-i][j];
    cout<<endl;
  }
  }



Measured memory_bytes: 256
#include <iostream> // includes cin to read from stdin and cout to write to stdout
#include <math.h>
using namespace std; // since cin and cout are both in namespace std, this saves some text

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

int main()
{
    int X;
    cin >> X;
    
    int result = 0;
    
    for (int i=1; i < 32; ++i) {
        for (int j = 2; j < 10; ++j) {
            int ans = pow(i, j);
            if (ans > X) break;
            if (ans > result) result = ans;
        }
    }
    cout << result << endl;
    
    return 0;
}


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

using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	bool flag =0;
	if(a == b && a != c){
		flag =1;
		cout<<"Yes"<<endl;
	}
	if(a == c && a != b){
		flag =1;
		cout<<"Yes"<<endl;
	}
	if(b ==  c && b != a){
		flag =1; 
		cout<<"Yes"<<endl;
	}
	if(!flag)
		cout<<"No"<<endl;
		
	
	return 0;
} 

Measured memory_bytes: 256
#include<fstream>
#include<string>
#include<iostream>
#include<sstream>
#include<iterator>
#include<cmath>
 
using namespace std;
 
int main(){
 int N;
 int A;
 int B;
 cin >> N >> A >> B;
 cout << min(N*A,B) << endl;
  return 0;
}

Measured memory_bytes: 256
n500 = gets.chomp.to_i
n100 = gets.chomp.to_i
n50 = gets.chomp.to_i
amount = gets.chomp.to_i
# puts "#{n500}, #{n100}, #{n50}: #{amount}"

# 解答
pattern_num = 0

# 500円玉を使える最大枚数
max500 = [amount / 500, n500].min

0.upto(max500) do |cur500|
  rest = amount - 500 * cur500

  # 100円玉を使える最大枚数
  max100 = [rest / 100, n100].min

  0.upto max100 do |cur100|
    rest_inner = rest - 100 * cur100

    # 必要な50円玉の枚数 ※ここは必ず割り切れる
    cur50 = rest_inner / 50

    # 持っている枚数以下ならパターンとして有効
    if cur50 <= n50
      pattern_num += 1
    end
  end
end

puts pattern_num


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

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

#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()

ll n, m, ans;
vector<pii> dt;

int main() {
	cin >> n >> m;
	for (ll i = 0; i < n; i++) {
		ll x; cin >> x;
		dt.pb({x, 0});
	}
	for (ll i = 0; i < m; i++) {
		ll x; cin >> x;
		dt.pb({x, 1});
	}
	sort(all(dt));
	n++, m++;
	for (pii p: dt) {
		if (p.S == 0) {
			ans += p.F * m;
			n--;
		} else {
			ans += p.F * n;
			m--;
		}
	}
	cout << ans;
}


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

typedef unsigned long long  ULL;
typedef long long LL;

#define PB push_back
#define MP make_pair
#define RESET(a, b) memset(a, b, sizeof(a))
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define F first 
#define S second

 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes";
    else cout<<"No";

    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,K;
string S,T;

int dp[555555];
int sum[555555];

signed main(){
    cin>>N>>K>>S>>T;

    for(int i=1;i<N;i++)sum[i+1]=T[i]!=T[i-1];
    for(int i=0;i<N;i++)sum[i+1]+=sum[i];

    deque<pint>d;
    d.pb({0,3});
    for(int i=0;i<N;i++){
        if(S[i]==T[i])dp[i+1]=dp[i];
        else{
            while(d.size()&&i+1-d.front().fi>K)d.pop_front();
            dp[i+1]=(sum[i+1]+d.front().se)/2;
        }
        while(d.size()&&d.back().se>2*dp[i+1]+3-sum[i+2])d.pop_back();
        d.push_back({i+1,2*dp[i+1]+3-sum[i+2]});
    }

    cout<<dp[N]<<endl;
    return 0;
}

Measured memory_bytes: 20032
tmp = input().split()
X = int(tmp[0])
Y = int(tmp[1])

ans = 0

if X == 1 and Y == 1:
    ans += 400000

if X == 1:
    ans += 300000
if X == 2:
    ans += 200000
if X == 3:
    ans += 100000

if Y == 1:
    ans += 300000
if Y == 2:
    ans += 200000
if Y == 3:
    ans += 100000

print(ans)


Measured memory_bytes: 3060
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	ll weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
ll powMod(ll x, ll k, ll m) {//x^k (mod n)
	if (k == 0)     return 1;
	if (k % 2 == 0) return powMod(x*x % m, k/2, m);
	else            return x*powMod(x, k-1, m) % m;
}
int N;
ll M;
vector<ll> xx,yy;
int main(){
	cin>>N>>M;
	rep(i,N){
		ll x;
		cin>>x;
		xx.pb(x);
	}
	rep(i,N){
		ll x;
		cin>>x;
		yy.pb(x);
	}	
	sort(all(yy));
	sort(all(xx));
	reverse(all(yy));
	ll ng=-1,ok=1e12+1;//ok以下にするコストがM以下
	while(ok-ng>1){
		ll mid=(ok+ng)/2;
		ll cost=0;
		rep(i,N){
			ll res=mid/yy[i];
			cost+=max((ll)0, xx[i]-res);
		}
		if(cost<=M)ok=mid;
		else ng=mid;
	}
	cout<<ok<<endl;

}



Measured memory_bytes: 4848
#include<stdio.h>

int main(){
int n;
int a[6];

while(1){
	int ma=0;int min=0;
scanf("%d",&n);if(n==0)break;
for(int i=0;i<n;i++){
int s=0;
for(int j=0;j<5;j++)
{int x;scanf("%d",&x);s+=x;}
if(i==0)min=s;
if(s>ma)ma=s;
if(s<min)min=s;
}
printf("%d %d\n",ma,min);
}
return 0;
}

Measured memory_bytes: 1028
import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner scan= new Scanner(System.in);

while(true){
int a=scan.nextInt();
String b=scan.next();
int c=scan.nextInt();
if("?".equals(b))
break;
if("+".equals(b)){
System.out.println((a+c));
}
if("-".equals(b)){
System.out.println(a-c);
}
if("*".equals(b)){
System.out.println(a*c);
}
if("/".equals(b)){
System.out.println(a/c);

}

}
}
}

Measured memory_bytes: 26204
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

struct Y{
    string name;
    int start,end;
    Y(string name,int start,int end) : name(name),start(start),end(end) {};
};

int main(){
    while(true){
        int N,Q;
        cin >> N >> Q;

        if(N == 0 and Q == 0) break;
        vector<Y> years;
        for(int i=0;i<N;i++){
            string name;
            int start,end,d;
            cin >> name >> d >> end;
            start = end-d + 1;
            years.push_back(Y(name,start,end));
        }
        for(int i=0;i<Q;i++){
            int year;
            cin >> year;
            for(int j=0;j<years.size();j++){
                if(years[j].start <= year and year <= years[j].end){
                    cout << years[j].name << " " << year-years[j].start+1 << endl;
                    goto end;
                }
            }
            cout << "Unknown" << endl;
        end:
            ;
        }
    }
    return 0;
}

Measured memory_bytes: 1284
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

H, W, A, B = MAP()

ans = [[0]*W for _ in range(H)]
for y in range(H):
	for x in range(W):
		if x < A and y < B:
			ans[y][x] = 1
		if A <= x and B <= y:
			ans[y][x] = 1

for i in range(H):
	print(*ans[i], sep="")

Measured memory_bytes: 18968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll MOD = (int)1e9 + 7;

vector<long long> fact, fact_inv, inv;

template< typename T >
void init_combi(size_t size, const T mod) {
    fact.resize(size);
    fact_inv.resize(size);
    inv.resize(size);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 1; i < size-1; i++) {
        fact[i+1] = fact[i] * (i + 1) % mod;
        inv[i+1] = mod - inv[mod % (i+1)] * (mod / (i+1)) % mod;
        fact_inv[i+1] = fact_inv[i] * inv[i+1] % mod;
    }
}

template< typename T >
T mod_combi(T n, T k, T mod) {
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    init_combi(N, MOD);
    sort(A.begin(), A.end());
    ll ans = 0;
    for (ll i = 0; i < N - K + 1; ++i) {
        ll n = N - i - 1;
        ll c = mod_combi(n, K - 1, MOD);
        ans = (ans - (A[i] * c) % MOD ) % MOD;
        ans = (ans + (A[A.size() - 1 - i] * c) % MOD ) % MOD;
    }
    ans = (ans + MOD) % MOD;
    cout << ans << endl;
}


Measured memory_bytes: 6424
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,sum=0;
	cin>>n;
	int a=n;
	while(n){
		sum+=n%10;
		n=n/10;
	}
	if(a%sum==0)
		printf("Yes\n");
	else
		printf("No\n");
}




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

const int N = 1e5 + 5;

int n, head[N], to[N * 2], nxt[N * 2], tot, num[N * 2], cur, ans[N];

inline void addedge(int x, int y, int z) {
    nxt[++tot] = head[x], head[x] = tot, to[tot] = y, num[tot] = z;
}

void dfs(int x, int fa, int c) {
    if (c > cur) cur = c;
    int cc = 0;
    for (int i = head[x]; i; i = nxt[i]) {
        int v = to[i];
        if (v == fa) continue;
        ++cc;
        if (cc == c) ++cc;
        ans[num[i]] = cc;
        dfs(v, x, cc);
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i < n; ++i) {
        int x, y; scanf("%d%d", &x, &y);
        addedge(x, y, i), addedge(y, x, i);
    } 
    dfs(1, 0, 0);
    printf("%d\n", cur);
    for (int i = 1; i < n; ++i)
        printf("%d\n", ans[i]);
    return 0;
}

Measured memory_bytes: 4864
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

N, A, B = ri_()
S = rs()
a = 0
b = 0
for i in S:
    if i == 'a':
        if a < A + B:
            print('Yes')
            a += 1
        else:
            print('No')
    elif i == 'b':
        if a < A + B and b <= B - 1:
            print('Yes')
            a += 1
        else:
            print('No')
        b += 1
    else:
        print('No')

Measured memory_bytes: 4016
from heapq import *
belong=list()
group=list()
def init(X):
  global belong
  global group
  belong=list(range(X))
  group=[[i] for i in range(X)]

def unite(x,y):
  if len(group[belong[x]])<len(group[belong[y]]):
    x,y=y,x
  if belong[x]==belong[y]:
    return True
  z=belong[y]
  for i in range(len(group[z])):
    belong[group[z][-1]]=belong[x]
    group[belong[x]].append(group[z][-1])
    del group[z][-1]
  return False

N=int(input())
X=[list(map(int,input().split())) for i in range(N)]
for i in range(N):
  X[i].append(i)
X.sort()
init(N)
Q=[]
heapify(Q)
v=0
heappush(Q,(X[0][1],X[0][2]))
for i in range(1,N):
  v=Q[0]
  while len(Q):
    if Q[0][0]<X[i][1]:
      unite(X[i][2],Q[0][1])
      heappop(Q)
    else:
      break
  if len(Q)==0:
    heappush(Q,v)
  if Q[0]!=v:
    heappush(Q,v)
  heappush(Q,(X[i][1],X[i][2]))
for i in range(N):
  print(len(group[belong[i]]))

Measured memory_bytes: 142200
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const ll mod=1e9+7;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n;
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                ans+=gcd(i,gcd(j,k));
            }
        }
    } 
cout<<ans;

    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    int N, Q;
    cin>>N>>Q;
    string s;
    cin>>s;
    vector<char> t(Q), d(Q);
    for (int i=0; i<Q; i++)
        cin>>t[i]>>d[i];

    auto f = [&](int p) -> int
    {
        if (p>=N)
            return 1;
        for (int i=0; i<Q; i++)
        {
            if (s[p]==t[i])
                if (d[i]=='L')
                    p--;
                else
                    p++;
            if (p<0)
                return -1;
            if (p>=N)
                return 1;
        }
        return 0;
    };

    int B = 1;
    while (B<N)
        B *= 2;

    int l = -1;
    for (int b=B; b>0; b/=2)
        if (f(l+b)==-1)
            l += b;
    int r = -1;
    for (int b=B; b>0; b/=2)
        if (f(r+b)!=1)
            r += b;
    cout<<r-l<<endl;
}


Measured memory_bytes: 900
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	int ans = 0;
	rep(i, a + 1) rep(j, b + 1) rep(k, c + 1){
		if(x == (i * 500 + j * 100 + k * 50)) ans++;
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 60;
constexpr double EPS = 1e-9;

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

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new custom_tf));
  }
} initializer;

template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pa) {
  return os << "(" << pa.first << ", " << pa.second << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }
#define dump(...) cout<<#__VA_ARGS__<<": [L_"<<__LINE__<<"]"<<'\n'; print(__VA_ARGS__);cout<<'\n';

template<class T, class U>inline bool chmax(T &a, const U &b) { if(a<b){ a=b; return 1; } return 0; }
template<class T, class U>inline bool chmin(T &a, const U &b) { if(b<a){ a=b; return 1; } return 0; }


int main() {
  int n; cin>>n;
  vector<int> h(n); cin>>h;
  vector<int> dp(n, 0);
  dp[1] = abs(h[1]-h[0]);
  REP(i, 2, n) {
    dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]));
  }
  print(dp[n-1]);

  return 0;
}


Measured memory_bytes: 1024
from heapq import heappush, heappushpop

N, M = map(int, input().split())

tasks = [[] for _ in range(M)]

for _ in range(N):
    a, b = map(int, input().split())
    if a <= M:
        tasks[M-a].append(b)
q = []
for day in range(M):
    for v in tasks[day]:
        if len(q) < day + 1:
            heappush(q, v)
        else:
            heappushpop(q, v)
ans = sum(q)
print(ans)                

Measured memory_bytes: 18412
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

vector<pair<ll, ll>> primeFactorization(ll n) {
    vector<pair<ll, ll>> result;
    for (ll i = 2; i * i <= n; i++) {
        ll num = 0;
        while (n % i == 0) {
            n /= i;
            num++;
        }
        if (num != 0) {
            result.push_back({ i, num });
        }
    }

    if (n != 1) {
        result.push_back({ n, 1 });
    }

    return result;
}

class Combination {
public:
    Combination(ll max_num, ll mod) {
        fact_.resize(max_num + 1, 1);
        inv_fact_.resize(max_num + 1, 1);
        mod_ = mod;
        for (ll i = 2; i <= max_num; i++) {
            fact_[i] = i * fact_[i - 1] % mod_;
            inv_fact_[i] = MODpow(fact_[i], mod_ - 2);
            assert(fact_[i] * inv_fact_[i] % mod_ == 1);
        }
    }
    ll operator()(ll n , ll m) const {
        return fact_[n] * inv_fact_[n - m] % mod_ * inv_fact_[m] % mod_;
    }
private:
    ll MODpow(ll n, ll m) const {
        ll result = 1;
        while (m) {
            if (m % 2 == 1) {
                result *= n;
                result %= mod_;
            }

            m /= 2;
            n *= n;
            n %= mod_;
        }

        return result;
    }

    vector<ll> fact_, inv_fact_;
    ll mod_;
};

int main() {
    ll N, M;
    cin >> N >> M;

    constexpr ll MAX = (ll)1e5 + 100;
    constexpr ll MOD = (ll)1e9 + 7;
    Combination comb(MAX, MOD);

    ll ans = 1;
    for (auto p : primeFactorization(M)) {
        ans *= comb(N - 1 + p.second, p.second);
        ans %= MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1920
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
typedef long long ll;
using namespace std;
struct edge {
	ll to;
};
vector<edge>G[100010];

int main(void){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    cout<<-a[n/2-1]+a[n/2]<<endl;
    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>
#include <stack>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<vector<ll>> edges(N, vector<ll>());
  vector<ll> cs(N);
  vector<ll> degrees(N, 0);
  for (auto i = 0; i < N-1; i++) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    degrees[a]++;
    degrees[b]++;
    edges[a].push_back(b);
    edges[b].push_back(a);
    // cout << "input edge [" << a << ", " << b << "]" << endl;
  }
  // cout << endl;
  for (auto i = 0; i < N; i++){
    cin >> cs[i];
  }
  // cout << "input finished" << endl;
  vector<ll> res(N);
  vector<bool> used(N, false);
  sort(cs.rbegin(), cs.rend());

  ll max_degree_idx = 0;
  for (ll i = 0; i < N; i++)
  {
    if (degrees[max_degree_idx] < degrees[i]) {
      max_degree_idx = i;
    }
  }
  // cout << "max_degree_idx=" << max_degree_idx << endl;
  stack<ll> st;
  ll n = 0;
  st.push(max_degree_idx);
  while (!st.empty()) {
    // cout << "st.top()=" << st.top() << endl;
    ll idx = st.top();
    st.pop();

    used[idx] = true;
    // cout << "res.size()=" << res.size()
    // << " cs.size()=" << cs.size()
    // << " n=" << n
    // << " idx=" << idx << endl;
    res[idx] = cs[n++];
    // cout << "hoge" << endl;

    // cout << "edge of [" << idx << "]=";
    for (ll e : edges[idx]){
      // cout << e << ", " << flush;
      if (!used[e])
      {
        st.push(e);
        // cout << e << ", ";
      }
    }
    // cout << endl;
  }

  ll M = 0;
  for (auto i = 0; i < N; i++) {
    for (auto j : edges[i]) {
      if (i < j) {
        M += min(res[i], res[j]);
      }
    }
  }

  cout << M << endl;
  cout << res[0];
  for (auto i = 1; i < N; i++)
    cout << " " << res[i];
  cout << endl;

  return 0;
}


Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc085.contest.atcoder.jp/tasks/abc085_d>
問題文============================================================
 あなたが散歩していると、突然一体の魔物が出現しました。
 幸い、あなたは N 本の刀、刀 1、刀 2、…、刀 N を持っていて、次の二種類の攻撃を自由な順番で行うことができます。
 
 持っている刀のうち一本を振る。
     刀 i (1≤i≤N) を振ると、魔物は ai ポイントのダメージを受ける。同じ刀を何度振ることもできる。
 持っている刀のうち一本を投げつける。
     刀 i (1≤i≤N) を投げつけると、魔物は bi ポイントのダメージを受け、あなたはその刀を失う。
     すなわち、あなたは以後その刀を振ることも投げつけることもできなくなる。
 
 魔物は、受けたダメージの合計が H ポイント以上になると消滅します。
 魔物を消滅させるには、最小で合計何回の攻撃が必要でしょうか。
=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N,H; cin >> N >> H;
    vector<ll> a(N),b(N);
    for(int i = 0; i < N;i++) cin >> a[i] >> b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end()); reverse(b.begin(),b.end());
    ll Maxa = *max_element(a.begin(), a.end());
    ll cnt = 0;
    for(int i = 0; i < N;i++){
        if(H <= 0) break;
        if(Maxa > b[i]) break;
        cnt++; H -= b[i];
    }
    if(H <= 0){
        cout << cnt << endl;
        return 0;
    }
    cout << cnt + (H + Maxa-1)/Maxa << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

int main(){

    int n, m, x;
    cin >> n>> m>> x;

    int r=0, l=0,tmp;

    REP(i,m){
        cin >> tmp;
        if(tmp<x){
            l++;
        }else{
            r++;
        }
    }

    cout << l * (l < r) + r * (l > r) << endl;

    return 0;
}

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

using namespace std;

int main(void)
{
    int n;
    cin >> n;
    vector<unsigned long long> num(n);
    int cnt4 = 0;
    int cnt1 = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> num.at(i);
        if (num.at(i) % 4 == 0)
        {
            cnt4++;
        }
        else if (num.at(i) % 2 != 0)
            cnt1++;
    }

    if (cnt1 - cnt4 == 1 && cnt1 + cnt4 == n)
    {
        cout << "Yes" << endl;
        return 0;
    }

    else
    {
        puts(cnt1 - cnt4 >= 1 ? "No" : "Yes");
    }
    return 0;
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(br.readLine());
        int array[] = new int[n + 1];
        long sum = 0;
        for(int i = 1;i <= n;i++){
            int a = Integer.parseInt(st.nextToken());
            array[i] = a;
            sum += a;
        }
        if(sum * 2 % (n * 1L * (n + 1)) != 0){
            System.out.println("NO");
            return;
        }
        long times = sum * 2 / (n * 1L * (n + 1));
        int cnt = 0;
        array[0] = array[n];
        for(int i = 1;i <= n;i++){
            long diff = array[i] - array[i - 1] - times;
            if(diff > 0){
                System.out.println("NO");
                return;
            }
            if(diff < 0){
                if(Math.abs(diff) % n > 0){
                 System.out.println("NO");
                 return;
                }
                cnt += Math.abs(diff)/n;
            }
        }
        if(cnt > times){
            System.out.println("NO");
            return;
        }
        System.out.println("YES");
    }
}

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

using ll = long long;
#define double long double
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x, c) for (auto&& x : (c))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))
#define endl _endl
const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n');

int main() {
  ll a, b;
  cin >> a >> b;
  cout << (a >= 13 ? b : a >= 6 ? b / 2 : 0) << endl;
}


Measured memory_bytes: 3600
#include<stdio.h>
#include<stdlib.h>
#define MAX 10000

int main(){
  unsigned short *a,*b;
  int n,i,c[MAX+1];
  
  scanf("%d",&n);

  a=(short*)malloc((n+1)*sizeof(short));
  b=(short*)malloc((n+1)*sizeof(short));
  
  for(i=1;i<=n;i++) scanf("%hu",&a[i]);

  for(i=0;i<=MAX;i++){
    c[i]=0;
  }

  for(i=0;i<n;i++){
    c[a[i+1]]++;
  }

  for(i=1;i<MAX;i++){
    c[i]=c[i]+c[i-1];
  }

  for(i=n;i>0;i--){
    b[c[a[i]]]=a[i];
    c[a[i]]--;
  }
  
  for(i=1;i<n;i++) printf("%d ",b[i]);
  printf("%d\n",b[i]);

  free(a);
  free(b);
  
  return 0;
}



Measured memory_bytes: 9160
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	ll n;
	cin >> n;
	ll res = 0;
	for (ll i = 1; i * i <= n; ++i) if (n % i == 0) {
		ll cnt = 0;
		for (ll t = n / i; t > 0; t /= 10) ++cnt;
		res = cnt;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "map"

using namespace std;
const long long int MOD = 1000000007;

int N,M;
int a, b;
int dp[40][401][401];
int num[40][2];
int cost[40];
int ans=1000000;

int main() {
	cin >> N>>a>>b;
	for (int i = 0; i < N; i++) {
		cin  >> num[i][0] >> num[i][1]>>cost[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 401; j++) {
			for (int k = 0; k < 401; k++) {
				dp[i][j][k] =1000000;
			}
		}
	}
	dp[0][0][0] = 0;
	dp[0][num[0][0]][num[0][1]] = cost[0];
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < 401; j++) {
			for (int k = 0; k < 401; k++) {
				if (dp[i - 1][j][k] != 1000000) {
					dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j][k]);
					dp[i][j + num[i][0]][k + num[i][1]] = dp[i - 1][j][k] + cost[i];
				}
			}
		}
	}
	for (int i = 1; i < 401; i++) {
		for (int j = 1; j < 401; j++) {
			if (i%a == 0 && j%b == 0&&dp[N-1][i][j]!=1000000) {
				if (i / a == j / b) {
					ans = min(ans, dp[N - 1][i][j]);
				}
			}
		}
	}
	if (ans == 1000000)cout << "-1\n";
	else cout << ans << endl;
	return 0;
}


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

int main() {
int X;
  cin >> X;
  int count = 0;
  for(int i = X; i < 100005; i++){
    count = 0;
  	for(int j = 2; j*j < i; j++){
    	if(i % j == 0){
        	count++;
        }
    }
    if(count == 0){
    	cout << i << endl;
      break;
    }
  }

  
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {

	int N, D, X;
	cin >> N >> D >> X;

	int total = 0;
	int v;
	for (int i = 0; i < N; i++) {
		cin >> v;
		int n = 0;
		for (int j = 1; j <= D; j += v) {
			++n;
		}
		total += n;
	}
	cout << (total + X) << endl;

	return 0;
}


Measured memory_bytes: 256
S = input()
T = input()

s = [[] for i in range(26)]
t = [[] for i in range(26)]

for i in range(len(S)):
    s[ord(S[i])-97].append(i)
    t[ord(T[i])-97].append(i)

s = sorted(s)
t = sorted(t)
if s == t:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 20336
import math

def primelist(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

def factorization(n):
    plist = primelist(int(n**0.5))
    factor = []
    for p in plist:
        k = 0
        while n%p==0:
            k+=1
            n//=p
        if k>0:
            factor.append((p,k))
        if n==1:
            break
    if n!=1:
        factor.append((n,1))

    return factor

def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


def main():
    a,b = tuple(map(int,input().split()))

    g = math.gcd(a,b)
    factors = factorization(g)
    print(len(factors)+1)

if __name__ == "__main__":
    main()


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

#define ll long long int

vector<int> to[200000];

void dfs(int m, int par, vector<ll> *count) {
  for(int v : to[m]) {
    if(v != par) {
      (*count)[v] += (*count)[m];
      dfs(v, m, count);
    }
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  int a, b;
  for(int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  vector<ll> count(n, 0);
  int p, x;
  for(int i = 0; i < q; i++) {
    cin >> p >> x;
    p--;
    count[p] += x;
  }
  dfs(0, -1, &count);
  for(int i = 0; i < n; i++) cout << count[i] << ' ';
  cout << endl;
  return 0;
}

Measured memory_bytes: 27392
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
#define rep(i,N) for (int i = 0; i < (N); i++)
using ll = long long;
using lb = long double;
using namespace std;
const int mod = 1000000007;

ll nCk(ll N, ll K){
    ll kid = 1;
  for(ll i = N; i > N - K; i--){
      kid = kid * i;
    }
    for(ll i = 1; i < K + 1; i++){
        kid = kid / i;
    }
  return kid;
}

ll gcd(ll P, ll Q){
  return Q ? gcd(Q,P % Q):P;
}

ll lcm(ll P, ll Q){
  return P / gcd(P,Q) * Q;
}

string change_big(string str){
  transform(str.begin(), str.end(), str.begin(), ::toupper);
  return str;
}

string change_small(string str){
  transform(str.begin(), str.end(), str.begin(), ::tolower);
  return str;
}

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

ll sum_of_num(ll num){
  ll dig;
  ll sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll how_many_break(ll n, ll m){
  ll counter = 0;
  while (n % m == 0){
    n = n / m;
    counter++;
  }
  return counter;
}

/*------------------------------------------------------------------------------------*/

int main(){
  ll N,K;
  ll ans= 1;
  cin >> N >> K;
  for(ll i = 0; i < N; i++){
    ans = ans * K % mod;
  }
  cout << ans << endl;
  return 0;
}



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

int main(){
  ll A, B;
  cin >> A  >> B;
  ll ans;
  if(A % 2 == 0 && B % 2 == 0){
    //A: even B:even
    if(((B-A)/2)%2 == 0){
      ans = 0 ^ B;
    }else{
      ans = 1 ^ B;
    }
  }else if(A % 2 == 0 && B % 2 != 0){
    //A:even B:odd
    if(((B-A+1)/2)%2 == 0){
      ans = 0;
    }else{
      ans = 1;
    }
  }else if(A % 2 != 0 && B % 2 == 0){
    //A:off B:even
    if(((B-A-1)/2)%2 == 0){
      ans = A ^ B;
    }else{
      ans = A ^ 1 ^ B;
    }
  }else{
    //A, B:odd
    if(((B-A)/2)%2 == 0){
      ans = A;
    }else{
      ans = A ^ 1;
    }
  }
  cout << ans << endl;

}


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

int main(){
  int N;
  cin>>N;
  int k=1000,l=0;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    k=min(k,a);
    l=max(l,a);
  }
  cout<<l-k<<endl;
}

Measured memory_bytes: 256
s=input()
wlist=[]
for ch in s:
  wlist.append(ch)
N=len(wlist)
F=int((N-1)/2)
A=int((N+3)/2)
r=0
for i in range(F-1):
  if wlist[i]!=wlist[N-1-i]:
    r=r+1
  if wlist[i]!=wlist[F-1-i]:
    r=r+1
  if wlist[A-1+i]!=wlist[N-1-i]:
    r=r+1
if r==0:
  print('Yes')
else:
  print('No')

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

int main() {
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	for (int i = 0; i < K; i++) {
		if (A >= B) {
			B *= 2;
		}
		else if (B >= C) {
			C *= 2;
		}
	}
	if (A < B && B < C) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3592