akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ITP1_1_C
{
    class Program
    {
        static void Main(string[] args)
        {
            int length, breadth;
            string[] str = Console.ReadLine().Split(' ');
            length = int.Parse(str[0]);
            breadth = int.Parse(str[1]);

            Console.WriteLine("{0} {1}",length * breadth, (length+breadth)*2);
        }
    }
}



Measured memory_bytes: 18024
n,k = map(int,input().split())
num_list = [0]*10**5
for i in range(n):
    a,b = map(int,input().split())
    num_list[a-1] += b
cnt = 0
for i in range(len(num_list)):
    cnt += num_list[i]
    if cnt >= k:
        print(i+1)
        break

Measured memory_bytes: 5744
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int n,a=0,c=1,i,max=1,d[100010];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&d[i]);
  for(i=1;i<n;i++){
    if(d[i]==d[i-1])continue;
    if(d[i-1]<d[i]){
      if(a==1)c++;
      else{
	a=1;
	max=MAX(max,c);
	c=2;
      }
    }
    else{
      if(a==-1)c++;
      else{
	a=-1;
	max=MAX(max,c);
	c=2;
      }
    }
  }
  printf("%d\n",MAX(max,c));
  return 0;
}
      

Measured memory_bytes: 2112
#include<bits/stdc++.h> 
using namespace std;
const int N=1e5+100;
bool mark[N];
int main()
{
	for (int i=1;i<=5;i++)
	{
		int x;
		scanf("%d",&x);
		mark[x]=1;
	}
	for (int i=0;i<=5;i++)
	if (!mark[i])
	{
		printf("%d\n",i);
		return 0;
	}
	return 0;
}

Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int x, a, b; cin >> x >> a >> b;
  cout << (abs(a - x) < abs(b - x) ? 'A' : 'B') << '\n';
}

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

using namespace std;

#define ll long long

ll N, A, B;
vector < ll > h;

bool check(ll x)
{
	ll need = 0;
	for (ll i = 0; i < N; i++) {
		ll tmp = h[i] - B * x;
		if (tmp <= 0) {
			break;
		}
		need += (tmp + (A - B) - 1) / (A - B);
	}

	return need <= x;
}

int main()
{
	cin >> N >> A >> B;
	h = vector < ll > (N);
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}

	sort(h.begin(), h.end(), greater < int >());

	ll l = 0, r = pow(10, 9) + 1;

	while (r - l > 1) {
		ll m = (l + r) / 2;
		if (check(m)) {
			r = m;
		} else {
			l = m;
		}
	}

	cout << r << endl;

	return 0;
}


Measured memory_bytes: 1024
a,b = map(int,input().split())
#ans = 0
x = 1

# if a==b:
#     print(1)
# if b==1:
#     print(1)

if b==1:
    print(0)
    exit()

while a*x-(x-1) < b:
    x += 1
print(x)


Measured memory_bytes: 2940
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include <sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using Int = int64_t;
using pint = pair<Int, Int>;
using vint = vector<Int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;  } return 0;  }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;  } return 0;  }
template<class T>void put_double(T a){cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<((itr==--v.end())?"\n":" ");}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

int main(void) {
    string s, t; cin >> s >> t;
    t.pop_back();
    if(s != t) println("No");
    else println("Yes");

    return 0;
}


Measured memory_bytes: 3600
x=int(input())
l=[]
s=x
for x in map(int,input().split()):
    l.append(x)
if(s==1):
    print(0)
    exit()    
z=0
suml=0
h=[]
while(z<s-1):
    if(l[z]>=l[z+1]):
        suml+=1
    elif(l[z]>=l[z+1]):
        suml+=1
    else:
        h.append(suml)
        suml=0    
    z+=1
    if(z==s-1):
        h.append(suml)
print(max(h))        



Measured memory_bytes: 14252
#include <iostream>
#include <algorithm>
#include <vector>
#include<string>
#include <set>
#include <map>
#include <queue>
#include <limits.h>
#include <cmath>

using namespace std;

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

struct UnionFind{
    int size;
    vector<int> par;
    vector<int> rank;
    UnionFind(int x){
        size=x;
        par=vector<int> (x);
        rank=vector<int> (x,1);
        for (int i=0;i<x;i++){
            par[i]=i;
        }
    }
    int root(int x){
        if(par[x]==x){
            return x;
        }
        else{
            return par[x]=root(par[x]);
        }
    }
    void unite(int x,int y){
        x=root(x);y=root(y);
        if(x==y){
            return;
        }
        if(rank[x]<rank[y]){
            par[x]=y;
        }
        else{
            par[y]=x;
        }
        if(rank[x]==rank[y]){
            rank[x]++;
        }
    }
    bool check(int x,int y){
        return root(x)==root(y);
    }
    void initialize(){
        for (int i=0;i<size;i++){
            par[i]=i;
        }
    }
};

typedef pair<int,pair<int,int>> P;

int main(){
    int n;
    cin >> n;
    UnionFind uf(n);
    priority_queue<P,vector<P>,greater<P>> q;
    int v;
    P now;
    rip(i,n,0){
        rip(j,n,0){
            cin >> v;
            if(v>=0 && i>j){
                now.first=v;
                now.second.first=i;
                now.second.second=j;
                q.push(now);
            }
        }
    }
    int co=n-1;
    int ans=0;
    while (co){
        now=q.top();
        q.pop();
        if(uf.check(now.second.first,now.second.second)){
            continue;
        }
        ans+=now.first;
        uf.unite(now.second.first,now.second.second);
        co--;
    }
    printf("%d\n",ans);
}


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

int main(void){
	int N,a;
	cin>>N;
	set<int> st;
	rep(i,N){
		cin>>a;
		st.insert(a);
	}
	int res = st.size();
	if(res%2==0)res--;
	cout<<res<<endl;

	return 0;
}


Measured memory_bytes: 4864
#include <iostream>

using namespace std;

const int CMIN = -100;
const int CMAX = 100;
const int MIN = 0;
const int MAX = 100;

class CIRCLE
{
  public:
    CIRCLE(int x, int y);
    ~CIRCLE();
    bool isIN(int w, int h, int r);

  private:
    int x;
    int y;
};

CIRCLE::CIRCLE(int x, int y)
{
    this->x = x;
    this->y = y;
}

CIRCLE::~CIRCLE()
{
}

bool CIRCLE::isIN(int w, int h, int r)
{

    if ((r <= this->y) && (r <= this->x) && (this->x <= (w - r)) && (this->y <= (h - r)))
    {
        return true;
    }
    return false;
}

int main(int argc, char *argv[])
{
    int w, h, x, y, r;
    while (cin >> w >> h >> x >> y >> r)
    {
        if (((MIN < w) && (w <= MAX)) && ((MIN < h) && (h <= MAX)) && ((MIN < r) && (r <= MAX)) && ((CMIN <= x) && (x <= CMAX)) && ((CMIN <= y) && (y <= CMAX)))
        {
            CIRCLE *circle = new CIRCLE(x, y);
            if (circle->isIN(w, h, r))
            {
                cout << "Yes" << endl;
            }
            else
            {
                cout << "No" << endl;
            }
            delete circle;
            circle = 0;
        }
    }
}

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int maxn = 15;
const int mod = 1e9+7;

using namespace std;

int n,m,k;
string mat[maxn];
vi sum[maxn];
int mark[maxn];

int bits(int x){
	int res=0;
	while(x){
		++res;
		x-=x&-x;
	}
	return res;
}

int extra_cut(){
	vector<pair<int, int>> ranges;
	for(int i = 0; i < n; i++) {
		int j = i;
		while(j + 1 < n and !mark[j]) j++;
		ranges.emplace_back(i, j);
		i = j;
	}
	vector<int> sum(ranges.size());
 
	int ans = 0;
	for(int j = 0; j < m; j++) {
		bool ok = true;
		for(int id = 0; id < (int)ranges.size(); id++) {
			int l, r;
			tie(l, r) = ranges[id];
			for(int i = l; i <= r; i++) {
				sum[id] += mat[i][j] == '1';
			}
			if(sum[id] > k) ok = false;
		}
		if(ok) continue;
 
		ans++;
 
		fill(sum.begin(), sum.end(), 0);
 
		ok = true;
		for(int id = 0; id < (int)ranges.size(); id++) {
			int l, r;
			tie(l, r) = ranges[id];
			for(int i = l; i <= r; i++) {
				sum[id] += mat[i][j] == '1';
			}
			if(sum[id] > k) ok = false;
		}
		if(!ok) return 1000000;
	}
	return ans;
}

void solve(){
	int ans=1e9+10;
	cin>>n>>m>>k;
	for(int i=0;i<n;++i){
		cin>>mat[i];
	}
	for(int i=0;i<(1<<n);++i){
		for(int x=0;x<n;++x) mark[x]=(i&(1<<x));
		ans = min(ans,bits(i) + extra_cut());
	}
	cout<<ans<<endl;
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int A,B;
  cin>>A>>B;
  
  string S;
  cin>>S;
  
  bool res=true;
  
  
  for(int i=0;i<S.size();i++){
    if(i==A){
      if(isdigit(S[i])!=0){
        res=false;
      }
    }
    else{
      if(S[i]=='-'){
        res=false;
      }
    }
  }
  
  if(res){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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

int main(){
  int a,b,c;
  int temp;

  cin>>a>>b>>c;

  if(a>b){
    temp=a;
    a=b;
    b=temp;
  }if(b>c){
    temp=b;
    b=c;
    c=temp;
  }if(a>b){
    temp=a;
    a=b;
    b=temp;
  }

  cout<<a<<" "<<b<<" "<<c<<endl;

  return 0;
}

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
 
int main() {
 
  int a, b;
  cin >> a >> b;
 
  if (a < b) {
    cout << "a < b" << endl;
} else if (a > b) {
  cout << "a > b" << endl;
} else {
  cout << "a == b" << endl;
}
 
return 0;
}

Measured memory_bytes: 1160
from fractions import gcd
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(n**0.5)+1):
        if temp%i == 0:
            cnt = 0
            while temp%i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == [] and n != 1:
        arr.append([n, 1])
    return arr

a, b = map(int, input().split())
gcd_ab = gcd(a, b)
print(len(factorization(gcd_ab)) + 1)

Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
int main(){
  int t,n;
  double a[11]={};
  cin>>t;
  for(int i=0;i<=t;i++){
    double v[100],r[100],s=0;
    cin>>n>>n;
    for(int j=0;j<n;j++)
      cin>>v[j]>>r[j],s+=r[j];
    for(int j=0;j<n;j++)
      a[i]+=v[j]*r[j]/s;
  }
  bool f=0;
  for(int i=0;i<t;i++)
    if(a[i]-a[t]>0.0000001)f=1;
  if(f)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 1232
n = int(input())
alist = list(map(int, input().split()))

adic = {}
for a in alist:
  if a in adic:
    adic[a] += 1
  else:
    adic[a] = 1

res = sum([v-1 for v in adic.values()])
print(n - res - res%2)


Measured memory_bytes: 17396
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	S = input()
	
	ans = [-1 for _ in range(3)]
	
	for i in range(3):
		if S[i] == "a":
			ans[0] = 1
		elif S[i] == "b":
			ans[1] = 1
		elif S[i] == "c":
			ans[2] = 1
	
	if ans[0] == ans[1] == ans[2] == 1:
		print("Yes")
	else:
		print("No")
			
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 23052
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
#include <list>
#include <queue>
#include <stack>
#include <map>
#define modulus 1000000007
#define ll long long
using namespace std;

int main(){
    int x1, x2, x3, x4, x5;
    cin >> x1 >> x2 >> x3 >> x4 >> x5;
    if(x1 == 0) cout << 1 << endl;
    else if(x2 == 0) cout << 2 << endl;
    else if(x3 == 0) cout << 3 << endl;
    else if(x4 == 0) cout << 4 << endl;
    else cout << 5 << endl;
}

Measured memory_bytes: 3596
N = int(input())
A = list(map(int, input().split()))
count = 0

for i in range(N):
    for j in range(N - 1, i, -1):
        if A[j] < A[j-1]:
            A[j], A[j - 1] = A[j -1], A[j]
            count += 1

print(*A)
print(count)

Measured memory_bytes: 6724
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}

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

signed main(void)
{
  int x, y;
  cin >> hex >> x >> y;
  if(x < y) cout << "<" << endl;
  else if(x > y) cout << ">" << endl;
  else cout << "=" << endl;

  return 0;
}


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

int main()
{
    double time1,time2;
    while(cin>>time1>>time2)
    {
        if(time1<35.5&&time2 <71){cout<<"AAA"<<endl;continue;}
        if(time1<37.5&&time2 <77){cout<<"AA"<<endl;continue;}
        if(time1<40&&time2 <83){cout<<"A"<<endl;continue;}
        if(time1<43&&time2 <89){cout<<"B"<<endl;continue;}
        if(time1<50&&time2 <105){cout<<"C"<<endl;continue;}
        if(time1<55&&time2 <116){cout<<"D"<<endl;continue;}
        if(time1<70&&time2 <148){cout<<"E"<<endl;continue;}
        cout <<"NA"<<endl;
    }
    return 0;
}

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

using namespace std;

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

  vector<int>V(N);
  for(int i = 0 ; i < N; ++i) V.at(i) = i + 1;

  vector<vector<int>>D;

  do {
    D.emplace_back(V);
  } while (std::next_permutation(V.begin(), V.end()));

  vector<int>P(N);
  for(auto& p: P)cin >> p;
  vector<int>Q(N);
  for(auto& q: Q)cin >> q;

  int p_i = 1 ,q_i = 1;
  for(auto& it: D){
    if(it != P) ++p_i;
    else break;
  }

  for(auto& it: D){
    if(it != Q) ++q_i;
    else break;
  }

  cout << abs(p_i - q_i) << endl;
}

Measured memory_bytes: 3256
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int num[4] = {0};
    string s;
    for (int i = 0; i < n; i++)
    {
        cin>>s;
        if (s[0] == 'A')
            num[0]++;
        else if (s == "WA")
            num[1]++;
        else if (s == "TLE")
            num[2]++;
        else
            num[3]++;
    }
    cout << "AC x " << num[0] << endl
         << "WA x " << num[1] << endl
         << "TLE x " << num[2] << endl
         << "RE x " << num[3] << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 3692
import java.io.InputStreamReader
import java.io.BufferedReader

fun main(args: Array<String>) {
  val br = BufferedReader(InputStreamReader(System.`in`))

  val n = br.readLine().toLong()

  tailrec fun rec(i: Long, cnt: Long, b: Long): Long =
    if(i < 10) cnt
    else rec(i / b, cnt + i / 2L / b, b)

  val ans = if(n % 2L == 1L) 0L else rec(n, 0L, 5L)

  println(ans)
}

Measured memory_bytes: 31652
while True:
    H, W = map(int, input().split())
    if H == W == 0:
        break
    frame = ["#", "#"]
    inside = ["#", "#"]
    for i in range(W - 2):
        frame.insert(1, "#")
        inside.insert(1, ".")
    frame = "".join(frame)
    inside = "".join(inside)
    print(frame)
    for i in range(H - 2):
        print(inside)
    print(frame)
    print()


Measured memory_bytes: 5616
#include <bits/stdc++.h>  
 
using namespace std;
 
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
 
const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};
 
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
 
int main() {
	int A, B;
	scanf("%d %d", &A, &B);
	if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
/*
[ ( ^ _ ^ ) ]
*/
// problem: atc/abc172/C
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000

#define tep template <
#define tem template < typename T
#define tee typename ...E
#define szn size_t N
#define rge int x1=0, int x2=1e9
#define tst string to_string(const
tem, szn > int SIZE(const T (&t)[N]) {return N;}
tem > int SIZE(const T &t) {return t.size();}
tst string s, rge) {return x1<int(s.size())?s.substr(x1, x2-x1+1):"";}
tst char *s) {return to_string((string)s);}
tst bool b) {return b?"true":"false";}
tst char c) {return string({c});}
tep szn > tst bitset<N> &b, rge) {
    string t="";
    for(int s=min(x1,SIZE(b)), e=min(x2,SIZE(b)-1); s<=e; ++s)
    {t += b[s] + '0';} return t;}
tem, tee > tst T (&v), rge, E... rem);
tem, typename E > tst pair<T, E> &p)
{return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
tem, tee > tst T (&v), int x1, int x2, E... rem) {
    string res = "["; bool first = true;
    x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v));
    auto l = begin(v); advance(l, x1);
    auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v)));
    for (auto e = l; e != r; e = next(e), first=false)
    {if (!first) { res += ", "; } res += to_string(*e, rem...);}
    res += "]"; return res;}
void dbgm(){;}
tem, tee > void dbgm(T t, E... e) {cout<<to_string(t)<<", "; dbgm(e...);}
#define dbg(...) cout<<"[ "<<#__VA_ARGS__<<" : ";cout<<to_string(__VA_ARGS__)<< " ]"<<endl
#define dbgm(...) cout<<"[ "<<#__VA_ARGS__<<" : ";dbgm(__VA_ARGS__);cout<<" ]"<<endl


const ll llinf = LLONG_MAX/3;

int main() {
    int n, m;
    ll k;
    scanf("%d %d %lld", &n, &m, &k);
    vector<ll> a(n), b(m);
    for(auto &ai: a) {
        scanf("%lld", &ai);
    }
    for(auto &bi: b) {
        scanf("%lld", &bi);
    }
    vector<ll> prefa(n), prefb(m);
    for(int i=0; i<n; i++) {
        prefa[i] = a[i] + (i > 0 ? prefa[i-1] : 0);
    }
    for(int i=0; i<m; i++) {
        prefb[i] = b[i] + (i > 0 ? prefb[i-1] : 0);
    }

    // dbgm(prefa);
    // dbgm(prefb);
    int rs = 0;
    int j = upper_bound(prefb.begin(), prefb.end(), k) - prefb.begin() - 1;
    if(0<=j && j<m && prefb[j]<=k) {
        rs = max(rs, j + 1);
    }
    for(int i=0; i<n; i++) {
        if(prefa[i] <= k) {
            // dbgm(i, prefa[i]);
            ll rem = k - prefa[i];
            j = upper_bound(prefb.begin(), prefb.end(), rem) - prefb.begin();
            // dbgm(rem, j);
            --j;
            if(0<=j && j<m && prefb[j]<=rem) {
                rs = max(rs, i + j + 2);
            } else {
                rs = max(rs, i + 1);
            }
        } else {
            break;
        }
    }
    printf("%d\n", rs);
}


Measured memory_bytes: 9596
x,y=[int(j) for j in input().split()]
U = 2*10**6
MOD = 10**9+7
 
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
 
for i in range(1,U+1):
  fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U],MOD-2,MOD)
 
for i in range(U,0,-1):
	fact_inv[i-1] = (fact_inv[i]*i)%MOD
 
def comb(n,k):
  if k < 0 or k > n:
    return 0
  x = fact[n]
  x *= fact_inv[k]
  x %= MOD
  x *= fact_inv[n-k]
  x %= MOD
  return x

if (2*y-x)//3==(2*y-x)/3 and (2*x-y)//3==(2*x-y)/3:
    i=(2*y-x)//3
    j=(2*x-y)//3
    print(comb(i+j,min(i,j)))
else:
    print(0)


Measured memory_bytes: 161268
n, m = (int(x) for x in input().split())
A = sorted([int(x) for x in input().split()])[::-1]
cost = (0, 2, 5, 5, 4, 5, 6, 3, 7, 6)
dp = [[0] * (n+1) for _ in range(m+1)]
for i in range(m):
  for j in range(1, n+1):
    dp[i+1][j] = max(dp[i+1][j], dp[i][j])
    if j >= cost[A[i]]:
      if dp[i+1][j-cost[A[i]]] == 0:
        if j == cost[A[i]]:
          dp[i+1][j] = max(A[i], dp[i][j])
        else:
          dp[i+1][j] = max(dp[i+1][j], dp[i][j])
      else:
        dp[i+1][j] = max(dp[i+1][j], 10 * dp[i+1][j-cost[A[i]]] + A[i])
print(dp[m][n])

Measured memory_bytes: 31968
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
Int Max = 101010;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	//素数判定
	vector<Int> is_prime(Max, 1);
	is_prime[0] = 0;
	is_prime[1] = 0;
	for (int i = 2; i < Max; i++) {
		if (is_prime[i] == 0)continue;
		for (int j = 2*i; j < Max; j+=i) {
			is_prime[j] = 0;
		}
	}

	//累積和
	vector<Int> s(Max + 1,0);
	for (int i = 0; i < Max; i++) {
		if (i % 2 == 0) {
			s[i + 1] = s[i];
			continue;
		}
		if (is_prime[i] && is_prime[(i + 1) / 2]) {
			s[i + 1] = s[i] + 1;
			continue;
		}
		s[i + 1] = s[i];
	}

	Int Q;
	cin >> Q;

	//答えの出力
	Int l, r;
	for (int i = 0; i < Q; i++) {
		cin >> l >> r;
		r++;
		printf("%lld\n", s[r] - s[l]);

	}

}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
vector<int> a,b,c;
vector<vector<int> >m;
int f(int n,int s){
	if(n==a.size()){
		return 0;
	}
	if(m[n][s]!=-1){
		return m[n][s];
	}
	if(s==0){
	 m[n][s]=max(max(f(n+1,1)+a[n],f(n+1,2)+b[n]),f(n+1,3)+c[n]);
	}
	if(s==1){
	 m[n][s]=max(f(n+1,2)+b[n],f(n+1,3)+c[n]);
	}
	if(s==2){
	 m[n][s]=max(f(n+1,1)+a[n],f(n+1,3)+c[n]);
	}
	if(s==3){
	 m[n][s]=max(f(n+1,1)+a[n],f(n+1,2)+b[n]);
	}
	return m[n][s];
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	a.resize(n);
	b.resize(n);
	c.resize(n);
	m.resize(n,vector<int>(4));
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
		m[i][0]=m[i][1]=m[i][2]=m[i][3]=-1;
	}
	cout<<f(0,0);
}


Measured memory_bytes: 14720
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>

using namespace std;

int main() {
    
    while (true){
        int a,b;
        char op;
        cin >> a >> op >> b;
        if(op == '?'){
            break;
        }
        if(op == '+'){
            cout << a+b << endl;
        }else if(op == '-'){
            cout << a-b << endl;
        }else if(op == '*'){
            cout << a*b << endl;
        }else{
            cout << a/b << endl;
        }
    }


}


Measured memory_bytes: 3052
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)


def main():
    A, B, C, K =map(int, input().split()) 

    ans = 0
    
    if A > K:
        ans += K * 1
        K = 0
    else:
        ans += A
        K = K - A
        if B > K:
            ans += K * 0
            K = K - B
        else:
            K = K - B
            if C > K:
                ans -= K
            else:
                ans -= C

    print(ans)

                
        
if __name__ == "__main__":
    main()


Measured memory_bytes: 10828
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int m, d; cin >> m >> d;
	int res = 0;
	for (int i = 1; i <= m; ++i)
	{
		for (int j = 22; j <= d; ++j)
		{
			int d10 = j / 10;
			int d1 = j % 10;
			if (d1 < 2)continue;
			if (d1*d10 == i)++res;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)



int main() {
	map<string, ll> m;
	string s;
	ll cnt = 0;

	ll N;
	std::cin >> N;
	
	rep(i, 0, N) {
		std::cin >> s;
		m[s]++;
		cnt = max(cnt, m[s]);
	}

	for (auto itr = m.begin(); itr != m.end(); itr++) {
		if (itr->second == cnt) {
			std::cout << itr->first << endl;
		}
	}
	
	return 0;
}

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

int get_min(int A, int B){
	if(A<B) return A;
	else	return B;

}


int main(){
	int A,B,C,D;
	cin >> A >> B >> C >> D;
	cout << get_min(A,B) + get_min(C,D) ;	
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char name[9][15];
	int i = 9, a[9], b[9];
	
	while (i > 0){
		scanf("%s %d %d", name[i], &a[i], &b[i]);
		if (a[i] > 400){
			a[i] = 400;
		}
		if (b[i] > 400){
			b[i] = 400;
		}
		printf("%s %d %d\n", name[i], a[i] + b[i], a[i] * 200 + b[i] * 300);
		i--;
	}
	
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int inf = 1000000007;
int a[26] = {};
signed main() {
	string s;
	cin >> s;
	int n = s.size();
	rep(i, n) {
		a[s[i] - 97]++;
	}
	rep(i, 26) {
		if (a[i] % 2 != 0) { cout << "No" << endl; return 0; }
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl


int main() {
    int A, B;  cin >> A >> B;

    if (A-B>0) print(A*2-1);
    else if (B-A>0) print(B*2-1);
    else print(A*2);
}

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

using namespace std;
typedef long long ll;

int main(){
	ll n;
	cin >> n;
	ll N = sqrt(n);

//	cout << N << endl;
	ll ans = 1001001001001; 
	for(ll i = 1; i <= N; i++){
		if(n % i == 0){
			ll temp = n / i;
			ans = min(ans, temp + i - 2);
		}
	}

	cout << ans << endl;
}

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

public class AtCoderA
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        decimal answer = (n / 2 + (n % 2 == 0 ? 0 : 1)) / (decimal)n;
        Console.WriteLine(answer);
    }
}

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

int main()
{
    string S;
    cin >> S;
    if(S[S.length()-1] =='s')
    {
        S.push_back('e');
      	S.push_back('s');
    }else{
        S.push_back('s');
    }

    cout <<S <<endl;
    return 0;
}

Measured memory_bytes: 3124
#include <stdio.h>
#include <stdlib.h>
int main(void){
    char c[10000];
    int a[2000];
    int i=0,j=0;
    while(scanf("%s",c) != EOF){
        switch(c[0]){
        case '%':
        a[i-2]=a[i-1]/a[i-2];
        i--;
        break;
        case '*':
        a[i-2]=a[i-1]*a[i-2];
        i--;
        break;
        case '+':
        a[i-2]=a[i-1]+a[i-2];
        i--;
        break;
        case '-':
        a[i-2]=a[i-2]-a[i-1];
        i--;
        break;
        default:
        a[i]=atoi(c);
        i++;
        break;
}
    }
    printf("%d\n",a[i-1]);
    return 0;
}

Measured memory_bytes: 1768
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
using namespace std;
enum COLOR {BLACK, WHITE};
int main(){
    int V, E;
    cin >> V >> E;
    vector<vector<pair<int, int> > > G(V);
    for (int i = 0; i < E; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        G[s].push_back(make_pair(t, w));
        G[t].push_back(make_pair(s, w));
    }
    vector<COLOR> color(V, WHITE);
    priority_queue<pair<int, int> > Q;
    color[0] = BLACK;
    int u = 0;
    int sum = 0;
    while(1) {
        for (int i = 0; i < G[u].size(); i++) {
            int v = G[u][i].first;
            if (color[v] == BLACK) continue;
            int w = G[u][i].second;
            Q.push(make_pair(w * (-1), v));
        }
        while (!Q.empty() && color[Q.top().second] == BLACK) Q.pop();
        if (Q.empty()) break;
        u = Q.top().second;
        color[u] = BLACK;
        sum += Q.top().first * (-1);
        Q.pop();
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 6728
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

const int MAX_N = 100100;
const int INF = INT_MAX / 2;

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

	int dp[MAX_N]; //??????n??????????¢??????¨??????????????£?????????????°?????????????????´?
	fill_n((int *)dp, MAX_N, INF);	

	dp[0] = -1;
	for(int i = 0; i < N; ++i) {
		int j = lower_bound(dp, dp+N, A[i]) - dp;	
		dp[j] = A[i];	
	}

	int ans = 1;
	for(int i = 1; i <= N; ++i) {
		if(dp[i] != INF) ans = i;		
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

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

ll nCr(ll n,ll r){
  if(r == 1) return n;
  else if(r == 0) return 1;
  else return nCr(n-1,r-1)*n/r;
}

int main(){
  long double n,t,a; cin >> n >> t >> a; ll ans = 0; long double goodtem = 1000;
  
  rep(i,n){
    long double x; cin >> x;
    if(abs(goodtem-a) > abs(t-0.006*x-a)){
      ans = i+1;
      goodtem = t-0.006*x;
    }
  }
  
  cout << ans << endl;
  
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, a[100000];

bool f(int v) {
	int b = 0, c = 0;
	inc(i, n) {
		if(! (a[i] == v || a[i] == v - 1)) { return false; }
		if(a[i] == v) { c++; } else { b++; }
	}
	
	return ( v - 1 >= b - 1 + (c != 0) && v - b <= c / 2 );
}

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	sort(a, a + n);
	int ma = a[n - 1];
	
	cout << (f(ma) || f(ma + 1) ? "Yes" : "No") << endl;
	
	
	return 0;
}


Measured memory_bytes: 640
// AtCoder A - Air Conditioner
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X; //温度
  cin >> X;
  
  //loop
  if (X >= 30){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

can_flg = True

lst_A = input().split()

for i in range(len(lst_A)):
    lst_A[i] = int(lst_A[i])

lst_A.sort()

while 1:
    if len(lst_A) % 2 == 1:
        if lst_A[0] != 0:
            can_flg = False
            break
        for i in range(1, len(lst_A), 2):
            if not((lst_A[i] == (i + 1)) and (lst_A[i + 1] == (i + 1))):
                can_flg = False
                break
    else:
        for i in range(0, len(lst_A), 2):
            if not ((lst_A[i] == (i + 1)) and (lst_A[i + 1] == (i + 1))):
                can_flg = False
                break
    break

if can_flg == True:
    ans = 2 ** (len(lst_A) // 2)
    ans = ans % (10 ** 9 + 7)
else:
    ans = 0

print(ans)

Measured memory_bytes: 10612
n,q=map(int,input().split())
s=input()
lr=[list(map(int,input().split())) for _ in range(q)]

AC=[]
for i in range(n-1):
    if s[i]=="A":
        if s[i+1]=="C":
            AC.append(i)
#print(AC)
from bisect import bisect_right as br
from bisect import bisect_left as bl
for i in range(q):
    a=bl(AC,lr[i][0]-1)
    b=br(AC,lr[i][1]-2)
    #print(a,b)
    print(b-a)


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

import sys
import os
import math

def length(v, w):
    x_diff = v[0] - w[0]
    y_diff = v[1] - w[1]
    return math.sqrt(x_diff ** 2 + y_diff ** 2)

X = []
Y = []
for s in sys.stdin:
    x, y = map(float, s.split(','))
    X.append(x)
    Y.append(y)

n = len(X)
answer = 0
for i in range(1, n-1):
    p0 = (X[0], Y[0])
    p1 = (X[i], Y[i])
    p2 = (X[i+1], Y[i+1])

    a = length(p0, p1)
    b = length(p1, p2)
    c = length(p2, p0)

    z = (a + b + c) / 2
    S = math.sqrt(z * (z - a) * (z - b) * (z - c))
    answer += S
print(answer)

Measured memory_bytes: 7568
while True:
    try:
     (a,b,c)  =  map(str,input().split())
    except:
     exit
    if ( b == "?"):
        break

    a = int(a)
    c = int(c)

    if ( b == "+"):
        print (a + c)
    elif (b == "-"):
        print (a - c)
    elif (b == "*"):
        print (a * c)
    elif (b == "/"):
        print (a // c)


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

int main() {
  int N;cin>>N;
  int odd=0;
  int even=0;
  int x;
  for(int i=0;i<N;i++){
    cin>>x;
    if(x%2==0) even++;
    else odd++;
  }
  bool can=true;
  if(odd%2==1) can=false;
  //else if((odd/2+even)%2==1) can=false;
  if(can) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 3636
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
mod = 10 ** 9 + 7

dp = [0] * (1 << n)
dp[0] = 1

bitcount = [0]
for _ in range(n):
    bitcount += [i+1 for i in bitcount]

# 集めるDP
for bit in range(1,1 << n):
    i = bitcount[bit]
    for j in range(n):
        if ((bit >> j) & 1 == 1) and (a[i - 1][j] == 1):
            dp[bit] += dp[bit ^ (1 << j)]
    dp[bit] %= mod
print(dp[-1])


Measured memory_bytes: 130048
#include <iostream>
using namespace std;
int main(){
	int N, i, j;
	while( 1 ){
		cin >> N;
		if( N == 0 ) break;
		int x, y;
		pair<int, int> robot = make_pair(10,10);
		int map[21][21] = {{}};
		for( i = 0; i < N; i++ ){
			cin >> x >> y;
			map[x][y] = 1;
		}
		int M;
		cin >> M;
		char news;
		int dist;
		for( i = 0; i < M; i++ ){
			cin >> news >> dist;
			for( j = 0; j < dist; j++ ){
				if( news == 'N' ) robot.second += 1;
				if( news == 'E' ) robot.first += 1;
				if( news == 'W' ) robot.first -= 1;
				if( news == 'S' ) robot.second -= 1;
				if( map[robot.first][robot.second] ) map[robot.first][robot.second] = 0;
			}
		}
		for( i = 0; i <= 20; i++ ){
			for( j = 0; j <= 20; j++ ){
				if( map[i][j] == 1 ) goto end;
			}
		}
		end:
		if( i == 21 && j == 21 ) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 1152
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1001113
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FDR(i,a,n) for(int i=a; i>=n; --i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline int Scan() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
inline void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}

const int N=100005;
//Code begin...

struct Edge{int p, next, w;}edge[N<<1];
int head[N], cnt=1, n;
LL d[N], dist[N];
int p[N][25];

void add_edge(int u, int v, int w){
    edge[cnt].p=v; edge[cnt].next=head[u];  edge[cnt].w=w; head[u]=cnt++;
}
void dfs(int u){
    for(int i=head[u];i;i=edge[i].next){
        int to=edge[i].p;
        if(to==p[u][0])continue;
        d[to]=d[u]+1;
        dist[to]=dist[u]+edge[i].w;
        p[to][0]=u; //p[i][0]存i的父节点
        dfs(to);
    }
}
void init(){
    for(int j=1;(1<<j)<=n;j++){
        for(int i=1;i<=n;i++){
            p[i][j]=p[p[i][j-1]][j-1];
        }
    }
}
int lca(int a,int b){
    if(d[a]>d[b])swap(a,b); //b在下面
    int f=d[b]-d[a];//f是高度差
    for(int i=0;(1<<i)<=f;i++){//(1<<i)&f找到f化为2进制后1的位置，移动到相应的位置
        if((1<<i)&f)b=p[b][i];//比如f=5(101),先移动2^0祖先，然后再移动2^2祖先
    }
    if(a!=b){
        for(int i=(int)log2(N);i>=0;i--){
            if(p[a][i]!=p[b][i]){//从最大祖先开始，判断a,b祖先，是否相同
                a=p[a][i]; b=p[b][i];//如不相同，a b同时向上移动2^j
            }
        }
        a=p[a][0];//这时a的father就是LCA
    }
    return a;
}
int main ()
{
    int u, v, w, q, k;
    LL ans1, ans2, ans3;
    scanf("%d",&n);
    FOR(i,1,n-1) scanf("%d%d%d",&u,&v,&w), add_edge(u,v,w), add_edge(v,u,w);
    dfs(1);
    init();
    scanf("%d%d",&q,&k);
    while (q--) {
        scanf("%d%d",&u,&v);
        int m1=lca(k,u), m2=lca(k,v), m3=lca(u,v);
        ans1=abs(dist[m1]-dist[u])+abs(dist[m1]-dist[k])+abs(dist[m2]-dist[k])+abs(dist[m2]-dist[v]);
        //ans2=abs(dist[m1]-dist[u])+abs(dist[m1]-dist[k])+abs(dist[m3]-dist[u])+abs(dist[m3]-dist[v]);
        //ans3=abs(dist[m2]-dist[v])+abs(dist[m2]-dist[k])+abs(dist[m3]-dist[u])+abs(dist[m3]-dist[v]);
        //cout<<ans1<<' '<<ans2<<' '<<ans3<<' '<<abs(dist[m1]-dist[u])<<endl;
        printf("%lld\n",ans1);
    }
    return 0;
}


Measured memory_bytes: 20608
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main()
{   long long k;
    string s;
    cin>>k;
    cin>>s;
    if(s.length()<=k){cout<<s;}
    else{cout<<s.substr(0,k);cout<<"...";}

    return 0;
}


Measured memory_bytes: 3600
N = gets.to_i
xs = gets.split.map(&:to_i)
ys = []
xs.each_with_index{|x, i| ys << [x, i]}
ys.sort_by!{|y| y[0]}
res = []
N.times{|i|
  if ( i < N/2) 
    res << [ys[N/2][0], ys[i][1]]  
  else
    res << [ys[N/2-1][0], ys[i][1]]  
  end
}
res.sort_by!{|r| r[1]}
res.each{|r|
  puts r[0]
}


Measured memory_bytes: 52376
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long  long int ll;

int main() {
	int N;
	cin>>N;
	vector<int>A(N);
	vector<int>B(N);
	int sum=0;
	
	for(int i=0;i<N;i++){
		cin>>A.at(i);
	}
	for(int i=0;i<N;i++){
		cin>>B.at(i);
	}
	for(int i=0;i<N;i++){
		if(A.at(i)-B.at(i)>0)sum+=A.at(i)-B.at(i);
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
hoge=list(map(int,input().split()))
hoge.reverse()
now=hoge[0]
use=0
for i in range(n-1):
  x=hoge[i+1]
  if(now<x-1):
    print("No")
    exit()
  elif(now==x-1 and use==0):
    use=1
    now=x-1
  elif(now==x-1 and use==1):
    use=1
    now=x-1
  elif(now==x and use==0):
    use=0
    now=x
  elif(now==x and use==1):
    use=0
    now=x
  else:
    use=0
    now=x
    
print("Yes")

Measured memory_bytes: 14396
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
typedef long long int ll;
const int INF = 1 << 30;
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()
int main() {
	int a, b, c, d, e,ans=0;
	string s, ss, sss;
	cin >> s;
	s[0] = '2';
	s[1] = '0';
	s[2] = '1';
	s[3] = '8';
	cout<<    s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define debug(x) cerr<<#x<<" = "<<x<<endl
#define debug2(a, b) cerr<<#a<<" = "<<a<<" | "<<#b<<" = "<<b<<endl
#define debug3(a, b, c) cerr<<#a<<" = "<<a<<" | "<<#b<<" = "<<b<<" | "<<#c<<" = "<<c<<endl
#define debug4(a, b, c, d) cerr<<#a<<" = "<<a<<" | "<<#b<<" = "<<b<<" | "<<#c<<" = "<<c<<" | "<<#d<<" = "<<d<<endl
#define debug5(a, b, c, d, e) cerr<<#a<<" = "<<a<<" | "<<#b<<" = "<<b<<" | "<<#c<<" = "<<c<<" | "<<#d<<" = "<<d<<" | "<<#e<<" = "<<e<<endl
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
const int N = 1000 + 5;
const int MOD = 1e9 + 7;
const int INF = 2e9;

int main() {
	int n, m, X, Y;
	cin>>n>>m>>X>>Y;
	int x[n], y[m];
	for(int i=0; i<n; ++i)
		scanf("%d", &x[i]);
	for(int i=0; i<m; ++i)
		scanf("%d", &y[i]);
	sort(x, x+n);
	sort(y, y+m);
	if(x[n-1]<y[0] && x[n-1]>X && y[0]<=Y) {
		printf("No War\n");
	} else {
		printf("War\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int ans = 0;
    SORT(a);
    for (int i = 1; i <= 100000;i++) {
        auto itr = lower_bound(a.begin(), a.end(), i);
        int it = itr - a.begin();
        if (it * 2 == n)ans++;
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int  long long
#define tc(t)  int t; cin>>t; while(t--)
#define f(n)    for(int i=0;i<n;i++)
#define endl   "\n"
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    if(n==1) {
        cout<<"0"<<endl;
        return 0;
    }
    if(n==2)
    {
        cout<<"1"<<endl;
        return 0;
    }
    int a=1;
    int b=1;
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            a=i;
            b=n/i;
        }


    }
    if(a==1&&b==1)
    {
        a=n;
        b=1;
    }
    //cout<<a<<" "<<b<<endl;
    cout<<(a+b-2)<<endl;


}

Measured memory_bytes: 3648
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */

#define MAXN (100000)
#define MOD (1000000007)

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

   for(int i=0;i<n;i++)for(int j=i+1;j<n;j++)
   {
       int level=0;
       while( (i&(1<<level))==(j&(1<<level)) ) level++;
       printf("%d ",level+1);

   }
   printf("\n");

    return 0;
}





Measured memory_bytes: 384
from collections import defaultdict
N = int(input())
p = 10 ** 9 + 7
C = [0] * (N + 1)
D = defaultdict(lambda: -1)
DP = [[0, 0] for i in range(N + 1)]
DP[0] = [1, 0]
for i in range(1, N + 1):
  C[i] = int(input())
  DP[i][0] = sum(DP[i - 1]) % p
  if C[i] != C[i - 1]:
    DP[i][1] = sum(DP[D[C[i]]]) if D[C[i]] != -1 else 0
    D[C[i]] = i
print(sum(DP[N]) % p)

Measured memory_bytes: 55056