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

using namespace std;

class UnionFind {
    vector<int> par;
    vector<int> tree_count;

public:
    UnionFind(int N) : par(N), tree_count(N) {
        for(int i = 0; i < N; i++) {
            par[i] = i;
            tree_count[i] = 1;
        }
    }

    int size(int x) {
        return tree_count[root(x)];
    }

    int root(int x) {
        if(par[x] == x) return x;
        //親を探すときに経路上のノードを親にくっつける
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        //ryに所属するグループの頂点数を格納(親でなくなった頂点は-1)
        tree_count[ry] += tree_count[rx];
        tree_count[rx] = -1;
        //xの親をyの親の下にくっつける
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


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

    vector<long long> A(M, 0);
    vector<long long> B(M, 0);
    for(long long i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
    }

    vector<long long> ret(M, 0);
    UnionFind uf(N);
    long long change = 0;
    ret[M-1] = (long long)((N*(N-1))/2);
    for(long long i = M - 2; i >= 0; i--) {
        if (!uf.same(A[i+1] - 1, B[i+1] - 1)) 
            change =  (uf.size(A[i+1]-1) * uf.size(B[i+1]-1));
        else 
            change = 0;

        //cout << "change:" << change   << endl;
        
        uf.unite(A[i+1]-1, B[i+1]-1);
        ret[i] = ret[i+1] - change;
        //cout << (uf.size(A[i]-1)) << "," << (uf.size(B[i]-1)) <<endl;

    }
    
    for(long long i = 0; i < M; i++) {
        cout << ret[i] << endl;
    }
}

Measured memory_bytes: 4480
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;
int main()
{
    string a, b, c;
    cin >> a >> b >> c;
    cout << a[0] << b[1] << c[2] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d,e;
  while(cin >>a,a){
    cin >>b>>c>>d>>e;
    int x;
    for(int i=b/c; i>=0; i--){
      if(i == 0){cout <<"NA"<<endl;break;}
      if(e>=i){
	x = (b-i*c)/d;
	if(x+i >= a){cout <<i<<" "<<x<<endl;break;}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define int           long long
#define	pb            push_back
#define all(a)        (a).begin(),(a).end()
#define sz(x)         (int)x.size()
#define F             first
#define S             second
#define endl          "\n"
#define inf           1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
#define bigboi        1e18
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
#define SHUF(v) shuffle(all(v), RNG);
// Use mt19937_64 for 64 bit random numbers. 

int n;
int len(int n){
	int res=0;
	while(n){
		n/=10;
		res++;
	}
	return res;
}
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
int bfs(){
	queue<int> q;
	FOR(i, 1, 10) q.push(i);
	int k=0;
	while(!q.empty()){
		int x = q.front();
		q.pop();
		k++;
		if(k==n){
			return x;
		}
		if(x%10!=0){
			q.push(10*x+x%10 -1);
		}	
		q.push(10*x+x%10);
		if(x%10!=9){
			q.push(10*x+x%10+1);
		}
	}
}
void solve(){
	cin>>n;
	cout<<bfs();	
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0); 	
	int t=1;
	//cin>>t;
	FOR(i, 1, t+1){	
		//cout<<"Case #"<<i<<": ";
		solve();
	}
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
 
}


Measured memory_bytes: 1792
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

h = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

puts a.inject(:+) >= h[0] ? "Yes" : "No"

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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)

#define ll long long

#define pq(name,type) priority_queue<type> name
#define vec(name,type,length,value) vector<type> name(length,value)
#define vec2(name,type,length,width,value) vector<vector<type>> name(length,vector<type>(width,value));

int main(){
	ll N;
  cin >> N;
  vector<ll> p(N);
  froop1(0,N){
   cin >> p.at(i); 
  }
  ll money = 1000;
  froop1(0,N - 1){
    ll a = 0;
   if(p.at(i + 1) > p.at(i)){
	 a = money / p.at(i);
     money = a * p.at(i + 1) + (money % p.at(i));
   }
  }
  cout << money << endl;
return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

int main(int argc, char const *argv[])
{
    char c;
    cin >> c;
    printf("%c", c + 1);
    return 0;
}


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

int main() {
  int M;
  int N;
  cin >> N >> M;
  int S[M];
  char C[M];
  for(int i=0; i<M; i++){
    cin >> S[i] >> C[i];
  }
  
  stringstream ss;
  ss << setw(N) << setfill('0') << 0 ;
  string ans = ss.str();
  
  if(N==1 && M==0) cout << 0 << endl;

  else if(M==0){
    ans.at(0) = '1';
    cout << ans <<endl;
  }
  else if(N == 1){
    bool can = true;
    ans = C[0];
    for(int i=0; i<M; i++){
      if(ans.at(S[i]-1) != C[i]){
      can = false;
      }
    }
    if(!can) cout << -1 << endl;
    else cout << ans << endl;
  }
    
  else{
  bool can = true;
  for(int i=0; i<M; i++){
    if(S[i] == 1 && C[i] == '0') can = false;
  }
    
  for(int i=0; i<M; i++){
    if(ans.at(S[i]-1) == '0'){
      ans.at(S[i]-1) = C[i];
    }
    else if(ans.at(S[i]-1) != C[i]){
      can = false;
      break;
    }
  }
  if(!can) cout << -1 << endl;
  
  else{
    if(ans.at(0) == '0'){
      ans.at(0) = '1';
      cout << ans << endl;
    }
    else cout << ans << endl;
  }
  }
}
  

Measured memory_bytes: 384
N = gets.to_i
S = N.times.map { gets.to_i }
MAX_S = N * 100

dp = Array.new(N + 10) { Array.new(MAX_S + 10, false) }
dp[0][0] = true
N.times do |i|
  s = S[i]
  (0..MAX_S).each do |j|
    if j - s < 0
      dp[i + 1][j] = dp[i][j]
    else
      dp[i + 1][j] = dp[i][j] || dp[i][j - s]
    end
  end
end
ans = 0
(0..MAX_S).each do |i|
  if i % 10 != 0 && dp[N][i]
    ans = i
  end
end
puts ans

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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    string ans;
    for(int i=0;i<s.size();i++){
        int d = s.at(i);
        //cout << "d(" << i << ")=" << d << endl; 
        if(d+n>90){
            d = d + n - 26;
            cout << char(d);
        }else{
            cout << char(d+n);
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
al = [chr(i) for i in range(97,97+26)]

N = int(input())
S = input()

X = 0

for i in range(N):
	x = 0
	a = S[:i]
	b = S[i:]

	for j in range(26):
		if al[j] in a and al[j] in b:
			x += 1
	if x >= X:
		X = x

print(X)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int sum(string j)
{
long long int s1=0,i=0;
while(j[i])
{
s1=s1+(int(j[i])-48);
i++;
}
return s1;
}
main()
{
string s;
cin>>s;
  if(sum(s)%9==0)
    cout<<"Yes";
  else
    cout<<"No";

}

Measured memory_bytes: 3784
const val MOD: Long = (1e9+7).toLong()

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    val c = Array(26, {1L})
    s.forEach{
        c[it - 'a'] = c[it - 'a'] + 1
    }
    val res = c.reduce { l, r ->
        (l * r) % MOD
    }
    println(res-1)
}


Measured memory_bytes: 34632
#include <iostream>
#include <vector>
#include <stack>

using namespace std;

int main() {
	string str;
	while ( getline(cin, str), str != "." ) {
		int k = 0, K = 0;
		stack<int> last;
		bool ans = true;
		for (int i = 0; i < str.size(); ++i) {
			switch (str[i]) {
				case '(':
					++k;
					last.push(0);
					break;

				case ')':
					if (last.empty() || last.top() != 0) {
						ans = false;
					}
					else {
						if (--k < 0) ans = false;
						last.pop();
					}
					break;

				case '[':
					++K; last.push(1);
					break;

				case ']':
					if (last.empty() || last.top() != 1) {
						ans = false;
					}
					else {
						if (--K < 0) ans = false;
						last.pop();
					}
					break;
			}
		}
		if (k != 0 || K != 0) ans = false;
		if (ans) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

Measured memory_bytes: 1176
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
#include <assert.h>
#include <cstring>
#include <set>

using namespace std;

typedef long long ll;

int main()
{
    string s;
    cin >> s;
    if(s[0]=='R')
    {
        if(s[1]=='R')
        {
            if(s[2]=='R')
            {
                cout << "3\n";
            }
            else cout << "2\n";
        }
        else cout << "1\n";
    }
    else if(s[1]=='R')
    {
        if(s[2]=='R')
            cout << "2\n";
        else cout << "1\n";
    }
    else if(s[2]=='R')
    {
        cout << "1\n";
    }
    else cout << "0\n";
    
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j;
  //ll n; cin>>n;
  //ll a,b,c,d,e,f; cin>>a>>b;
  string a,b,c,d,e,f; cin>>a>>b>>c;
  //ll a,b,c,d,e,f; cin>>a>>b>>c>>d;
  //string s; cin >> s;
  ll result = 0;
  bool judge = true;
  d.push_back(a[0]);
  d += b[1];
  d += c[2];
  cout<<d<<endl;

  /*
  vector<ll> a(n);
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  
  for(i=0;i<n;i++){

  }
  */

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    ll sum=0;
    rep(i,n-1) sum=(sum+a[i])%MOD;

    ll ans=0;
    for(int i=n-1;i>=1;i--){
        ll tmp=(a[i]*sum)%MOD;
        ans=(ans+tmp)%MOD;
        sum=(sum-a[i-1])%MOD;
        if(sum<0) sum+=MOD;
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 4808
#include<bits/stdc++.h>
#define fi                first
#define se                 second
#define ll               long long
#define mod              1000000007LL
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb                push_back
#define all(v)             v.begin(),v.end()
#define inp(V,n)      for(int i=0;i<n;i++){cin >> V[i];}
#define oup(V,n)     {for(int i=0;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define pll              pair<long long,long long>
using namespace std;
//queue<ll> q;
ll cnt=0;
//vector<ll> adj[3000005];
//vector<ll> a(1000005),b(100005);
//vector<bool> vis(3000005,false);
//ll ed,ve;
ll timer =0;
set<ll> s;
vector<pll> vp;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<double,double> &a,
              const pair<double,double> &b)
{
    if(a.fi==b.fi)
    {
    return (a.se >b.se);
    }
    else
        return (a.fi<b.fi);
}
ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}
/*ll  dfs(ll node)
{
   vis[node]=true;
   ll c=1;
   //ll c=adj[node].size();
   for(auto x:adj[node])
   {
       if(vis[x]==false)
       {
           c+=dfs(x);
       }
   }
   a[node]=c;
   return c;
}
void bfs(ll node)
{
    vis[node]=true;
    for(auto x:adj[node])
    {
        if(vis[x]==false)
        {
            bfs(x);
        }
    }
}*/
int main()
{
 fast;
     int t=1;
     //cin>>t;
     while(t--)
     {
       ll k,n,i=0,j=0,c=0,d=0,e=0,f=0,g=0,h=0,sum=0,maxi=0,to=0;
       string a;
       cin>>a;
       n=a.size()-1;
       if(a[n]=='s')
       {
           a=a+'e';
           a=a+'s';
       }
       else
        a=a+'s';
       cout<<a;

     }
}


Measured memory_bytes: 3652
import sys

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()

A, B = nm()


def solve():
    return A * B


print(solve())


Measured memory_bytes: 9168
K, N = map(int, input().split())
A = list(map(int, input().split()))
a_dis = [A[i + 1] - A[i] for i in range(N - 1)]
a_dis.append(A[0] + K - A[N - 1])
max_dis = max(a_dis)
print(K - max_dis)

Measured memory_bytes: 26420
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

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

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
//#include <queue>

using namespace std;
#define n_max 10000
#define INF 10001000

#define rep(i, a, n) for(int i = a; i < n; i++)
#define rep2(i, a, n) for(int i = a; i <= n; i++)
#define rrep(i, a, n) for(int i = a; i > n; i--)
#define rrep2(i, a, n) for(int i = a; i >= n; i--)
#define lrep(i, a, n) for(long int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

int digits(int n)
{
    int digits=1;

    while(n) {
        if(n/=10) digits++;
    }
    return digits;
}

int main()
{
    int N;
    int ans = 0;

    cin >> N;

    for(int i = 1; i <= N; i++) { 
        if(digits(i)%2 == 0) { continue; }
        ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int ans[200010];

void dfs(vector<vector<int>> const& g, int from, int now, vector<ll> const& q, ll next) {
  ans[now] += q[now] + next;
  for (auto itr : g[now]) {
    if (itr == from) continue;
    dfs(g, now, itr, q, ans[now]);
  }
}

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

  int n, q;
  cin >> n >> q;
  vector<vector<int>> g(n+2);

  vector<ll> a(n), b(n), p(q), x(q);

  rep(i, n-1) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  vector<ll> query(n+1);

  rep(i, q) {
    cin >> p[i] >> x[i];
    query[p[i] - 1] += x[i];
  }

  dfs(g, -1, 0, query, 0);

  for (int i = 0; i < n; ++i) cout << ans[i] << " ";
  END;
}


Measured memory_bytes: 37632
import math

A, B = input().split()
A = int(A)
B = int(B)

S=[]

for i in range(1251):
    if math.floor(0.08*i)==A and math.floor(0.1*i)==B:
        S.append(i)
    else:
        S.append(10000)
        
S.sort()

if S[0]==10000:
    print('-1')
else:
    print(S[0])

Measured memory_bytes: 3064
#include<stdio.h>
#define M 1000

int main(void){
  int i,j;
  int n,m;
  char ta[M],tb[M];
  char ch[5];

  for(;;){
    scanf("%d",&n);
    if(n==0)
      break;

    for(i=0;i<n;i++){
      scanf("%s",&ta[i]);
      scanf("%s",&tb[i]);
    }

    scanf("%d",&m);
    for(i=0;i<m;i++){
      scanf("%s",ch);

      for(j=0;j<n;j++)
        if(ch[0]==ta[j]){
          ch[0]=tb[j];
          break;
        }

      printf("%c",ch[0]);
    }
    puts("");
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF -99999999
typedef pair<int, int> P;
int main(void)
{
  ll A,B,M;cin>>A>>B>>M;

  vector<ll> ai(A,0);
  vector<ll> bi(B,0);
  ll amin=1e9;
  ll bmin=1e9;
  for(int i=0;i<A;i++){
    cin>>ai[i];
    if(amin>ai[i]){
      amin = ai[i];
    }
  }
  for(int i=0;i<B;i++){
    cin>>bi[i];
    if(bmin>bi[i]){
      bmin = bi[i];
    }
  }
  ll res = amin+bmin;

  for(int i=0;i<M;i++){
  ll x,y,c;cin>>x>>y>>c;
  ll p = ai[x-1]+bi[y-1]-c;

  if(res>p)res=p;
  }

  cout<<res<<endl;

  return 0;
}

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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)

#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(void)
{
    int m,f,r,sum=0;
    cin >> m >> f >>r;
    while(!(-1==m&&-1==f&&-1==r)) {
        if(-1==m||-1==f) cout << 'F' << endl;
        else {
            sum=m+f;
            if(80<=sum) cout<<'A'<<endl;
            else if(30>sum) cout<<'F'<<endl;
            else if(65<=sum) cout<<'B'<<endl;
            else if(50<=sum||50<=r) cout<<'C'<<endl;
            else cout<<'D'<<endl;
        }
        cin>>m>>f>>r;
    }
}



Measured memory_bytes: 3084
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

double getCircleIntegral(double r, double h, double x1, double x2, bool isUpper)
{
    double ans = x2 * sqrt(r * r - x2 * x2) - x1 * sqrt(r * r - x1 * x1);
    ans += r * r * (asin(x2 / r) - asin(x1 / r));
    ans /= 2.0;
    if(!isUpper)
        ans = -ans;
    ans += h * (x2 - x1);

    return ans;
}

int main()
{
    int n, r;
    cin >> n >> r;
    vector<int> height(2*r, 0);
    for(int i=0; i<n; ++i){
        int x, w, h;
        cin >> x >> w >> h;
        for(int j=x; j<x+w; ++j){
            if(0 <= j+r && j+r < 2*r)
                height[j+r] = h;
        }
    }

    double left = 0.0;
    double right = 200.0;
    for(int t=0; t<50; ++t){
        double mid = (left + right) / 2.0;
        double area = 0.0;
        for(int i=0; i<2*r; ++i){
            vector<double> vx;
            vx.push_back(i - r);
            vx.push_back(i - r + 1);
            if(height[i] - mid < r){
                double x = sqrt(r*r - pow(height[i] - mid, 2.0));
                if(vx[0] < -x && -x < vx[1])
                    vx.insert(vx.begin()+1, -x);
                else if(vx[0] < x && x < vx[1])
                    vx.insert(vx.begin()+1, x);
            }

            for(unsigned j=0; j<vx.size()-1; ++j){
                double y = sqrt(r*r - pow((vx[j] + vx[j+1])/2.0, 2.0));
                if(height[i] < mid - y){
                    area += getCircleIntegral(r, mid, vx[j], vx[j+1], true);
                    area -= getCircleIntegral(r, mid, vx[j], vx[j+1], false);
                }
                else if(height[i] < mid + y){
                    area += getCircleIntegral(r, mid, vx[j], vx[j+1], true);
                    area -= height[i] * (vx[j+1] - vx[j]);
                }
            }
        }

        if(area < r * r * M_PI / 2.0)
            left = mid;
        else
            right = mid;
    }

    printf("%.10f\n", left);

    return 0;
}

Measured memory_bytes: 3428
package main

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

func main() {
    var str string
    stdin := bufio.NewScanner(os.Stdin)

    if stdin.Scan() {
        str = stdin.Text()
        arr := strings.Split(str, " ")
        A, _ := strconv.Atoi(arr[0])
        B, _ := strconv.Atoi(arr[1])
        K, _ := strconv.Atoi(arr[2])
        cnt := 0
        var max int
        var list []int

        if A >= B {
            max = A
        } else {
            max = B
        }

        for i := 1; i <= max; i++ {
            if A % i == 0 && B % i ==0 {
                cnt++
                list = append(list, i)

                if cnt == K + cnt {
                    break
                }
            }
        }

        sort.Sort(sort.Reverse(sort.IntSlice(list)))
        fmt.Println(list[K-1])
    }
}

Measured memory_bytes: 640
#include <stdio.h>
int main (void)
{
    int f[14][14]={0},x,y,size,i,j,mu=0,st=0;
    while(scanf("%d,%d,%d",&x,&y,&size)!=EOF){
        for(i=x+1;i<=x+3;i++){
            for(j=y+1;j<=y+3;j++){
                f[i][j]++;
            }
        }
        if(size==1){
            for(i=x+1;i<=x+3;i=i+2){
                for(j=y+1;j<=y+3;j=j+2){
                    f[i][j]--;
                }
            }
        }
        else if(size==3){
            f[x][y+2]++;
            f[x+4][y+2]++;
            f[x+2][y]++;
            f[x+2][y+4]++;
        }
    }
    for(i=2;i<12;i++){
        for(j=2;j<12;j++){
            if(f[i][j]==0){
                mu++;
            }
            if(f[i][j]>st){
                st=f[i][j];
            }
        }
    }
    printf("%d\n%d\n",mu,st);
    return 0;
}

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

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

// K 回以下の修行で max{ A_i * F_i } <= X にできるか判定
bool func(long long X) {
  long long cnt = 0;  // 必要な修行回数
  for (int i = 0; i < N; i++) {
    long long a = X / F.at(i);
    cnt += max(0LL, A.at(i) - a);
  }
  return cnt <= K;
}

int main() {
  cin >> N >> K;
  A.resize(N);
  F.resize(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  for (int i = 0; i < N; i++) cin >> F.at(i);
  sort(A.begin(), A.end());
  sort(F.begin(), F.end(), greater<int>());
  // 達成可能なスコア X の最小値を求める
  long long left = -1;  // NG
  long long right = 1LL << 50;  // OK
  while (right - left > 1) {
    long long mid = (left + right) / 2;
    if (func(mid)) right = mid;
    else left = mid;
  }
  cout << right << endl;
}

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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<ll,ll> pii;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define ff it->first
#define ss it->second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define LOOP_IT(it,s) for(auto it=(s).begin();it!=(s).end();++it)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);


#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif



int main(int argv, char* argc[])
{
    FASTIO

    int n,m,votes=0;
    cin>>n>>m;
    vii v(n);
    rep(i,n)
    {
        cin>>v[i];
        votes+=v[i];
    }
    double mn = (double)votes/(4*m);

    int cnt=0;
    rep(i,n)
    {
        if((double)v[i]>=mn)
            ++cnt;
        if(cnt==m)
            break;
    }
    if(cnt==m)
        cout<<"Yes";
    else
        cout<<"No";



    return 0;
}



Measured memory_bytes: 3608
#include <iostream>

#include <map>
#include <string>

#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cinttypes>


using namespace std;

int main()
{
	long double n, k;
	cin >> n >> k;

	cout << (int)ceil(log(n+1) / log(k)) << endl;

	return 0;
}


Measured memory_bytes: 640
def solve(level, eat_layer, all_layers, meat):
    if eat_layer == 1:
        return 0 if level > 0 else 1
    elif eat_layer <= all_layers[level - 1] + 1:
        return solve(level - 1, eat_layer - 1, all_layers, meat)
    elif eat_layer == all_layers[level - 1] + 2:
        return 1 + meat[level - 1]
    elif eat_layer <= 2 + 2 * all_layers[level - 1]:
        return 1 + meat[level - 1] + solve(level - 1, eat_layer - 2 - all_layers[level - 1], all_layers, meat)
    elif eat_layer == 3 + 2 * all_layers[level - 1]:
        return 2 * meat[level - 1] + 1


def main():
    level, eat_layer = map(int, input().split())
    level_layer = [1]
    meat = [1]
    for _ in range(level):
        level_layer.append(2 * level_layer[-1] + 3)
        meat.append(2 * meat[-1] + 1)
    print(solve(level, eat_layer, level_layer, meat))


if __name__ == '__main__':
    main()



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

int main() {
  int N;
  cin >> N;
  vector<int> D1(N);
  vector<int> D2(N);
  int same = 0;
  for(int i = 0; i < N; i++) {
    cin >> D1[i] >> D2[i];
  }
  for(int i = 0; i < N; i++) {
    if(D1[i] == D2[i]) {
      same++;
      if(same == 3) {
        cout << "Yes" << endl;
        return 0;
      }
    } else {
      same = 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	string S;
	cin >> N >> S;
	S.erase(unique(all(S)), S.end());

	cout << SZ(S) << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long int
signed main() 
{
int n,k;
cin>>n>>k;
vector<int>visit(n+1);
vector<int>arr(n+1);
for(int i=1;i<=n;i++)
{
      cin>>arr[i];    
}
int pos=1;
int len=0;
while(visit[pos]==0)
{     
          visit[pos]=1;
          pos=arr[pos];
          len++;
}
int pos1=arr[pos];
int cycle=1;
while(pos1!=pos)
{
          pos1=arr[pos1];
          cycle++;
}

int j;
if(k<=(len-cycle))
{
          j=k;
          pos=1;
}
else
{
          k=(k-(len-cycle));
          j=k%cycle;
}

while(j--)
{
          pos=arr[pos];
}
cout<<pos<<"\n";
}


Measured memory_bytes: 6432
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,k;
    cin>>a>>b>>k;
    if(k<=a)
    {
        cout<<a-k<<" "<<b<<endl;
    }
    else if(k<=b+a)
    {
        cout<<a-a<<" "<<b-(k-a)<<endl;
    }
    else
    {
        cout<<"0"<<" " <<"0"<<endl;
    }

}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int i,dice[7];
    char order[101];
    
    for(i=1;i<7;i++)
        scanf("%d", &dice[i]);
    
    scanf("%s", order);
    
    for(i=0;order[i]!='\0';i++){
        
        dice[0] = dice[1];
        
        switch(order[i]){
                
            case 'E':
                dice[1] = dice[4];
                dice[4] = dice[6];
                dice[6] = dice[3];
                dice[3] = dice[0]; 
                break;
            
            case 'N':
                dice[1] = dice[2];
                dice[2] = dice[6];
                dice[6] = dice[5];
                dice[5] = dice[0]; 
                break;
            
            case 'S':
                dice[1] = dice[5];
                dice[5] = dice[6];
                dice[6] = dice[2];
                dice[2] = dice[0]; 
                break;
                
            case 'W':
                dice[1] = dice[3];
                dice[3] = dice[6];
                dice[6] = dice[4];
                dice[4] = dice[0]; 
                break;

        }
    }
    
    printf("%d\n", dice[1]);
    
    return 0;
}


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

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

  int len = S.length();
  sort(S.begin(), S.end());
  S.erase(unique(S.begin(), S.end()), S.end());

  if (len == S.length())
    printf("yes");
  else
    printf("no");
  return 0;
}


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

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/
  int a,b,c;

  cin>>a>>b>>c;

  cout<<a+b+c<<endl;

  return 0;

}



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

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if (A == B)
    {
        cout << C << endl;
    }
    if (B == C)
    {
        cout << A << endl;
    }
    if (C == A)
    {
        cout << B << endl;
    }
}


Measured memory_bytes: 256
S = input()
K = int(input())

results = [0]*2
result = 0

lastchanged = False
pre = None
for r in range(2):
    for i, x in enumerate(S):
        if pre is not None and not lastchanged and x == pre:
            results[r] += 1
            lastchanged = True
        else:
            lastchanged = False
        pre = x

if results[0] == results[1]:
    result = results[0] * K
else:
    if lastchanged:
        result = (results[0] + results[1]) * (K // 2)
        if K % 2 != 0:
            result += results[0]
    else:
        result = results[1] * K
        result -= 1

print(result)

Measured memory_bytes: 3064
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))

    res = [True for _ in range(N)]
    for _ in range(M):
        A, B = map(int, input().split())
        A -= 1
        B -= 1
        if H[A] < H[B]:
            res[A] = False
        elif H[A] > H[B]:
            res[B] = False
        elif H[A] == H[B]:
            res[A] = False
            res[B] = False

    print(sum(res))


if __name__ == '__main__':
    main()


Measured memory_bytes: 89264
#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
LL dp[105][100005];
const int INF = 1e18; 

LL knap(int wt[],int val[],int n,int W){
  if(W<=0) return 0;
  if(n<0) return INF;
  if(dp[n][W]!=-1) return dp[n][W];
  dp[n][W] = min(knap(wt,val,n-1,W-val[n])+wt[n],knap(wt,val,n-1,W));
  return dp[n][W];
}
 
int main(){
	int n,W;
  	cin>>n>>W;
  	int w[105],v[105];
  	for(int i=0;i<n;i++) cin>>w[i]>>v[i];
  int sum = 0;
  for(int i=0;i<n;i++) sum += v[i];
  	for(int i=0;i<n;i++){
    	for(int j=0;j<=sum;j++){
        	dp[i][j] = -1;
        }
    }
  
  	for(int j=sum;j>=0;j--){
    	LL ans = knap(w,v,n-1,j);
      	if(ans<=W){
          	//cout<<ans<<endl;
        	cout<<j<<endl;return 0;
        }
    }
}

Measured memory_bytes: 81628
#include <bits/stdc++.h>
#define LL long long
#define FOR(i,c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define F first
#define S second
using namespace std;

const LL mod = 1e9 + 7;

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*(b/gcd(a, b)); }
template<typename T, typename S> T expo(T b, S e, const T &m){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b)%m, e>>1, m): (b*expo((b*b)%m, e>>1, m))%m;}
template<typename T, typename S> T expo(T b, S e){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b), e>>1): (b*expo((b*b), e>>1));}
template<typename T, typename S> T modinv(T a, S mod) { return expo(a, mod-2, mod); }
template<class T, class S> std::ostream& operator<<(std::ostream &os, const std::pair<T, S> &t) {
	os<<"("<<t.first<<", "<<t.second<<")";
	return os;
}
template<class T> std::ostream& operator<<(std::ostream &os, const std::vector<T> &t) {
	os<<"["; FOR(it,t) { if(it != t.begin()) os<<", "; os<<*it; } os<<"]";
	return os;
}

const int MAXN = 10;

int n, m;
bool mat[MAXN][MAXN];

int main() {
  ios_base::sync_with_stdio(false);
  int a, b;
  cin >> n >> m;
  for(int i = 0; i < m; i++) {
    cin >> a >> b;
    mat[a][b] = mat[b][a] = true;
  }
  vector<int> perm(n, 0);
  for(int i = 0; i < n; i++) {
    perm[i] = i + 1;
  }
  LL res = 0;
  do {
    int p = 1;
    bool ok = true;
    for(int i = 1; i < perm.size(); i++) {
      if(!mat[p][perm[i]]) {
        ok = false;
        break;
      }
      p = perm[i];
    }
    if(ok) res++;
  } while(next_permutation(next(perm.begin()), perm.end()));
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;

int main(){
  int x;
  cin >> x;
  ll ans = 1000 * (x / 500) + ((x%500)/5) * 5;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define lint long long

using namespace std;

int main()
{
  map<string,int> freq;
  int n,max=0;
  cin >> n;
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    freq[s]++;
    if(max<freq[s]){
      max = freq[s];
    }
  }
//    cout << max << endl;


  for(pair<string,int> p:freq){
    if(p.second==max){
      cout << p.first << endl;
    }
  }
   return 0;


}


Measured memory_bytes: 25216
import math

class point:

    def __init__(self, p):
        self._x = p[0]
        self._y = p[1]

    def disp(self):
        print("{0:f} {1:f}".format(self._x, self._y))

    @property
    def x(self):
        return self._x

    @property
    def y(self):
        return self._y


def get_s(p1, p2):
    p = point((p1.x/3*2 + p2.x/3, p1.y/3*2 + p2.y/3))
    return p


def get_t(p1, p2):
    p = point((p1.x/3 + p2.x/3*2, p1.y/3 + p2.y/3*2))
    return p


def get_u(s, t):
    x = (t.x - s.x)*math.cos(math.radians(60)) - (t.y - s.y)*math.sin(math.radians(60)) + s.x
    y = (t.x - s.x)*math.sin(math.radians(60)) + (t.y - s.y)*math.cos(math.radians(60)) + s.y
    return point((x, y))


def kock(n, p1, p2):
    if n == 0:
        return
    else:
        s = get_s(p1, p2)
        t = get_t(p1, p2)
        u = get_u(s, t)

        kock(n-1, p1, s)
        s.disp()
        kock(n-1, s, u)
        u.disp()
        kock(n-1, u, t)
        t.disp()
        kock(n-1, t, p2)

        return


if __name__ == '__main__':

    n = int(input())

    p1 = point((0, 0))
    p2 = point((100, 0))

    p1.disp()
    kock(n, p1, p2)
    p2.disp()


Measured memory_bytes: 5784
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
#define NUM 1000000007
typedef long long int lli;

int getAbs(int x);

int main(){
    int n;
    cin >> n;
    vector<int> zahyou(1, 0);
    int sum = 0;
    for(int i = 1; i <= n + 1; i++){
        if(i <= n){
            int q;
            cin >> q;
            zahyou.push_back(q);
        }else{
            zahyou.push_back(0);
            //zahyou[n + 1] == 0
        }
        sum += getAbs(zahyou[i] - zahyou[i - 1]);
    }
    //cout << sum << endl;
    for(int i = 1; i <= n; i++){
        cout << (sum - getAbs(zahyou[i] - zahyou[i - 1]) - getAbs(zahyou[i + 1] - zahyou[i]) + getAbs(zahyou[i + 1] - zahyou[i - 1])) << endl;
    }
    //cout << ans << endl;
    return 0;
}

int getAbs(int x){
    return (x > 0)? x : -x;
}

Measured memory_bytes: 1784
#coding:utf-8

n = int(input())

x = 0
y = 0
z = 0
for i in range(n):
    a,b,c = map(int,input().split())
    nx = max(y,z) + a
    ny = max(x,z) + b
    nz = max(x,y) + c
    x = nx
    y = ny
    z = nz

print(max(x,y,z))

Measured memory_bytes: 3064
#include<bits/stdc++.h>    
using namespace std;
#define ll long long 
#define pi pair<ll,ll>
#define pd pair<ld,ld>
#define pb push_back
#define inf 1e15
#define mod 1000000007
#define en '\n'
#define ld long double
#define ff first
#define ss second
#define ull unsigned long long 
#define lb lower_bound
#define ub upper_bound
#define fr(a,b,c) for(ll a = b ; a <= c ; ++a )
#define frn(a,b,c) for(ll a = b ; a >= c ; a -- )
#define fra(a,b) for(auto a: b)
#define ms(a) memset(a,0,sizeof a);
#define alla(a) a,a+n
#define allv(a) a.begin(),a.end()
#define size(a) (ll)a.size()
#define getMat(x,n,m,val) vector<vector<ll>>x(n,vector<ll>(m,val))
const ll MAXN = 1e5+5;
#define pii 3.14159265358979323846 
ll pw(ll b, ll r, ll md){
	ll ans = 1;
	while(r){
		if(r&1)ans = (ans*b)%md;
		b = (b*b)%md;
		r>>=1;
	}
	return ans;
}
struct node{
	ll d,c,p;
};
bool cmp(node a, node b){
	if(a.d==b.d){
		return a.p<b.p;
	}
	return a.d<b.d;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,w;cin>>n>>w;
	pi arr[n];fr(i,0,n-1)cin>>arr[i].ff>>arr[i].ss;
	ll dp[n+1][w+1];ms(dp);
	fr(i,1,n){
		fr(j,0,w){
			dp[i][j]=dp[i-1][j];
			if(j>=arr[i-1].ff)dp[i][j]=max(dp[i][j],dp[i-1][j-arr[i-1].ff]+arr[i-1].ss);
		}
	}
	cout<<dp[n][w]<<en;
	return 0 ;

}

Measured memory_bytes: 82516
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;
 
int main(){
    ll x, y, ans=0;
    cin >> x >> y;
    ll now=x;
    while(now <= y){
        ans++;
        now*=2;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int h,w;
	cin>>h>>w;
	char a[h+2][w+2];
	for(int i=0;i<=h+1;i++)
		for(int j=0;j<=w+1;j++)
			{
				a[i][j]='.';
			}
			
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			{
				cin>>a[i][j];
			}
			
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			{
				if(a[i][j]=='#'&&a[i-1][j]!='#'&&a[i+1][j]!='#'&&a[i][j-1]!='#'&a[i][j+1]!='#')
				{
					cout<<"No";
					return 0;
				}
			}
			
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    int N;
    cin >> N;
    int p[N];
    rep(i,N) cin >> p[i];
    int p2[N];
    rep(i,N) p2[p[i]-1]=i+1;
    int A[N],B[N];
    A[0]=1,B[0]=1000000000;
    for(int i=1;i<N;i++){
        lint dis=p2[i]-p2[i-1];
        lint up=1,down=1;
        if(dis>0) up+=2*dis;
        else down-=2*dis;
        A[i]=A[i-1]+up;
        B[i]=B[i-1]-down;
    }
    rep(i,N) cout << A[i] << " ";
    cout << endl;
    rep(i,N) cout << B[i] << " ";
    cout << endl;
}

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

#define int long long
#define rep(i,a,b) for(int i = a; i < b; i++)
const int mod = 1e9 + 7;

signed main() {
    int N, M;
    cin >> N >> M;
    int S[N];
    rep(i,0,N) cin >> S[i];
    int T[M];
    rep(j,0,M) cin >> T[j];

    int dp[N+1][M+1];
    rep(i,0,N+1) {
        rep(j,0,M+1) {
            if (i == 0 || j == 0) {
                dp[i][j] = 1;
            }
            else {
                dp[i][j] = 0;
            }
        }
    }

    rep(i,1,N+1) {
        rep(j,1,M+1) {
            if (S[i-1] == T[j-1]) {
                dp[i][j] = dp[i][j-1] + dp[i-1][j];
            }
            else {
                dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1];
            }
            dp[i][j] = (dp[i][j] + mod) % mod;
        }
    }

    int ans = dp[N][M];
    cout << ans << endl;
}

Measured memory_bytes: 31616
def resolve():
    N, K = list(map(int, input().split()))
    XY = []
    X = []
    Y = []
    for _ in range(N):
        x, y = list(map(int, input().split()))
        XY.append((x, y))
        X.append(x)
        Y.append(y)
    
    X.sort()
    Y.sort()
    
    ans = float("inf")
    for i in range(N-1):
        for j in range(i+1, N):
            for k in range(N-1):
                for l in range(k+1, N):
                    cnt = 0
                    xmin, xmax, ymin, ymax = X[i], X[j], Y[k], Y[l]
                    for x, y in XY:
                        if xmin <= x <= xmax and ymin <= y <= ymax:
                            cnt += 1
                    if cnt >= K:
                        ans = min(ans, abs(xmax-xmin)*abs(ymax-ymin))
    print(ans)




if '__main__' == __name__:
    resolve()

Measured memory_bytes: 73940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}


int main() {
    string s;
    cin >> s;
    string ans;
    for(int i = 0; i < s.length();i++){
        ans += 'x';
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, C;
long long w[101];
int v[101];
 
long long dp[101][1000001];
 
long long solve(int i, int value){
	if(value <= 0) return 0;
	if(i == n) return 1000000000;
	if(dp[i][value] != -1) return dp[i][value];
	
	dp[i][value] = solve(i+1, value);
	dp[i][value] = min(dp[i][value], solve(i+1, value-v[i]) + w[i]);	
	return dp[i][value];
}
 
int main(){
	cin>>n>>C;
	long long v_sum = 0;
	for (int i = 0; i < n; ++i){
		cin>>w[i]>>v[i];
		v_sum += v[i];
	}
 
	memset(dp, -1, sizeof dp);
	for(int i = v_sum; i>=0; i--){
		if(solve(0, i) <= C){
			cout<<i<<endl;
			return 0;	
		}
	}
}

Measured memory_bytes: 789376
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define ll long long

using namespace std;
int calc_sum(int m, vector<int> a){
    int sum = 0;
    for (int num : a){
        sum  += m%num;
    }
    return sum;
}

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

    int n;
    cin >> n;
    vector<int> a;
    int num;
    REP(_,n){
        cin >> num;
        a.PB(num-1);
    }

    cout << accumulate(ALL(a),0);
    return 0;
}


Measured memory_bytes: 256