akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359
/*
int main(){
    iostream::sync_with_stdio(false);
    
    int D;
    cin >> D;
    if(D == 22) cout << "Christmas Eve Eve Eve" << endl;
    if(D == 23) cout << "Christmas Eve Eve" << endl;
    if(D == 24) cout << "Christmas Eve" << endl;
    if(D == 25) cout << "Christmas" << endl;
    
    return 0;
}*/

/*
int main(){
    iostream::sync_with_stdio(false);
    
    int N;
    cin >> N;
    int sum = 0;
    int m = 0;
    for(int i=0; i<N; i++){
        int tmp;
        cin >> tmp;
        sum += tmp;
        m = max(m, tmp);
    }
    cout << sum - m/2 << endl;
    
    return 0;
}*/


int main(){
    iostream::sync_with_stdio(false);
    
    int N,K;
    cin >> N >> K;
    int p[100000];
    for(int i=0; i<N; i++) cin >> p[i];
    sort(p, p+N);
    int ans = INT_MAX;
    for(int i=0; i+K-1<N; i++){
        ans = min(ans, p[i+K-1]-p[i]);
    }
    cout << ans << endl;
    return 0;
}

/*
int main(){
    iostream::sync_with_stdio(false);
    
    
    
    return 0;
}*/

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

int main()
{
  int n, a, b;
  cin >> n >> a >> b;

  if(n*a > b) cout << b << endl;
  else cout << n*a << endl;
  return 0;
}


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

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

  br.readLine()
  val a = br.readLine().split(" ").map { it.toLong() }
    .toLongArray()

  fun solve(init: Int): Long {
    return a.foldIndexed(Pair(0L,0L)) { i, acc, e ->
      val v = acc.second + e
      // println("${i}: ${acc}, ${v}")
      if(i % 2 == init) {
        if(v > 0) Pair(acc.first, v)
        else Pair(acc.first - v + 1L, 1L)
      }
      else {
        if(v < 0) Pair(acc.first, v)
        else Pair(acc.first + v + 1L, -1L)
      }
    }.first
  }

  val ans = Math.min(solve(0), solve(1))
  println(ans)
}

Measured memory_bytes: 74556
#include<stdio.h>
int main(void){
	int d;
	int len;
	int i;
	int s = 0;
	int y;
	while(scanf("%d",&d) != EOF){
	y = d;
	len = 600 / d;
	for(i = 1;i < len;i++){
		s += d * y * y;
		y += d;
	}
	printf("%d\n",s);
		d = 0;
		s = 0;
	}
	return 0;
}

Measured memory_bytes: 596
from collections import Counter

n, *a = map(int, open(0).read().split())
n += 1


def cmb(n, r, mod):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10 ** 9 + 7
N = n
# 元テーブル
g1 = [0] * (N + 1)
g1[0] = 1
g1[1] = 1

# 逆元テーブル
g2 = [0] * (N + 1)
g2[0] = 1
g2[1] = 1

# 逆元テーブル計算用テーブル
inverse = [0] * (N + 1)
inverse[0] = 0
inverse[1] = 1

for i in range(2, N + 1):
    g1[i] = (g1[i - 1] * i) % mod
    inverse[i] = (-inverse[mod % i] * (mod // i)) % mod
    g2[i] = (g2[i - 1] * inverse[i]) % mod

d = Counter(a).most_common(1)[0][0]
lr = [i for i, e in enumerate(a) if e == d]
l = lr[1] - lr[0] + 1

answer = [(cmb(n, i, mod) - cmb(n - l, i - 1, mod)) % mod for i in range(1, n + 1)]
print('\n'.join(map(str, answer)))

Measured memory_bytes: 31704
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split())) + [X]
y = list(map(int, input().split())) + [Y]

x_max = max(x)
y_min = min(y)

if x_max >= y_min:
    war_happen = True
else:
    war_happen = False

print('War' if war_happen else 'No War')

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>

using namespace std;

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

    int n, k;
    cin >> n >> k;

    const unsigned int pattern = k * pow(k - 1, n - 1);

    cout << pattern;

    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n, k;
	while (scanf("%d%d", &n, &k), n|k)
	{
		int a[100000];
		for (int i = 0; i < n; ++i)
			scanf("%d", a + i);
		int res, sum;
		res = sum = accumulate(a, a+k, 0);
		for (int i = k; i < n; ++i)
		{
			sum += a[i] - a[i-k];
			res = max(res, sum);
		}
		printf("%d\n", res);
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<cmath>
#include<algorithm>
#define MINF -1e9
using namespace std;

struct cloth
{
  int hi,lo,point;
};

int dp[201][201];

int main(){
  int d,n;
  cin >> d >> n;
  int t[d];
  cloth *c;
  c = new cloth[n];
  for(int i = 0; i < d; i++){
    cin >> t[i];
  }
  for(int i = 0; i < n; i++){
    cin >> c[i].lo >> c[i].hi >> c[i].point;
  }

  for(int i = 0; i < n; i++){
    if(c[i].lo <= t[0] && t[0] <= c[i].hi){
    }else{
      dp[0][i] = MINF;
    }
  }

  for(int i = 1; i < d; i++){
    for(int j = 0; j < n; j++){
      for(int k = 0; k < n; k++){
	if(c[j].lo <= t[i] && t[i] <= c[j].hi){
	  dp[i][j] = max(dp[i][j],
			 dp[i-1][k] + abs(c[k].point - c[j].point));
	}else{
	  dp[i][j] = MINF;
	}
      }
    }
  }
  int res = 0;
  for(int i = 0; i < n; i++){
    res = max(dp[d - 1][i], res);
  }
  
  // for(int i = 0; i < d; i++){
  //   for(int j = 0; j < n; j++){
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1344
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    string s; cin >> s;
    if (s == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
}


Measured memory_bytes: 3620
//editorial was used
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ldbl;
typedef pair<string,int> P;
typedef vector<int> vec;

#define for_n(i, init, n) for(int i = init; i < (n); i++)
#define pb push_back


ll mod = 1e9+7;

int main(){
  // USE THIS FOR FAST I/O
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int v[3]; cin >> v[0] >> v[1] >> v[2];
  int count = 0;
  //sort(v,v+3);
  int e = 0, o = 0;
  for_n(i,0,3){
    if(v[i]&1) o++;
    else e++;
  }

  if(o==2&&e==1) {for_n(i,0,3) {if(v[i]&1) v[i]++;} count++;}
  else if(e==2&&o==1) {for_n(i,0,3) {if(!(v[i]&1)) v[i]++;} count++;}

  sort(v,v+3);

  //for_n(i,0,3) cout << v[i] << " ";
  count += (v[1]-v[0])/2;
  count += v[2]-v[1];

  cout << count << endl;

  return 0;
}
// notes
//


Measured memory_bytes: 256
N, K, Q = map(int, input().split())
A = [None]*Q
for i in range(Q):
    A[i] = int(input())

score = [K-Q]*N

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

for i in range(N):
    if score[i] > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 10544
#include <bits/stdc++.h>
     
    #define endl '\n'
    #define fi first
    #define se second
    #define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
    #define forn(i,n) for (int i = 0; i < n; i++)
    #define forr(i,a,b) for (int i = a; i <= b; i++)
    #define all(v) v.begin(), v.end()
    #define pb(x) push_back(x)
     
    using namespace std;
     
    typedef long long ll;
    typedef long double ld;
    typedef pair<int, int> ii;
    typedef vector<int> vi;
    typedef vector<vi> vvi;
    typedef vector<ii> vii;
     
    int n,k,h[100005],ans=2e9;
     
    int main () {
    	ios_base::sync_with_stdio(0); cin.tie(0);
     
    	cin >> n >> k;
    	for(int i = 0; i < n; i++)
    		cin >> h[i];
    	sort(h, h + n);
     
    	for(int i = 0; i + k - 1 < n; i++)
    		ans = min(ans, h[i+k-1] - h[i]);
    	cout << ans << endl;
     
    	return 0;
    }

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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()
#define endl "\n"

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int main(){

    int x;
    cin >> x;

    rep(i, 8){
        if(400 + 200 * i <= x && x < 600 + 200 * i){
            cout << 8 - i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <stack>
using namespace std;
#define FI(n) FastIO::read(n)
namespace FastIO{
    const int SIZE  = 1<<16;
    char buf[SIZE] , obuf[SIZE] , str[60];
    int bi = SIZE , bn = SIZE , opt;
    int read(char *s){
        while( bn ){
            for(;bi<bn && buf[bi] <= ' ';bi++);
            if( bi < bn )   break;
            bn = fread(buf,1,SIZE,stdin);
            bi = 0;
        }
        int sn = 0;
        while( bn ){
            for(;bi<bn && buf[bi] > ' ';bi++)   s[sn++] = buf[bi];
            if( bi < bn )   break;
            bn = fread(buf,1,SIZE,stdin);
            bi = 0;
        }
        s[sn] = 0;
        return sn;
    }
    bool read(int& x){
        int n = read(str) , bf;
        if(!n)  return 0;
        int i = 0;
        if( str[i] == '-' ) bf = -1 , i++;
        else bf = 1;
        for(x = 0 ; i < n ; i++)    x = x*10 + str[i] - '0';
        if( bf < 0 )    x = -x;
        return 1;
    }
};
typedef long long LL;
const int N = 1e5+7 , INF = 0x3f3f3f3f , mz = 1e9+7;
const double PI = acos(0.0) * 2;
template<typename T1>
T1 gcd(T1 a , T1 b){ return b ? gcd(b,a%b) : a;}

int vis[N];

int main(){
#ifdef LOCAL
    freopen("F:\\c++\\in.txt", "r", stdin);
//  freopen("F:\\c++\\out1.txt","w",stdout);
#endif
    int n,x;
    FI(n);
    for(int i = 0 ; i < n ; i++){
        FI(x);
        vis[x]++;
        vis[x+1]++;
        if( x ) vis[x-1]++;
    }
    x = 0;
    for(int i = 0 ; i < N ; i++){
        if( vis[i] > vis[x] ){
            x = i;
        }
    }
    printf("%d\n",vis[x]);
    return 0;
}

Measured memory_bytes: 640
import java.util.*;
class Main{
		public static void main(String argsp[]){
        	Scanner s=new Scanner(System.in);
 			int k=s.nextInt();
          	int a=s.nextInt();
          	int b=s.nextInt();
          	for(int i=a;i<=b;i++){
            	if(i%k==0){
                System.out.println("OK");
                  return;
                }
            }
          System.out.println("NG");
        }
}

Measured memory_bytes: 35732
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)1e6+5;
const int M = (int)8e3+5;
const int Q = 102;
const int logN = 19;

void solve() {
    int ans = 0;
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    ans += min(a,k);
    k -= min(a,k);
    k -= min(b,k);
    ans -= min(c,k);
    cout<<ans;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 3652
/*
~Like a small boat
~On the ocean
~Sending big waves
~Into motion
!Like how a single word
!Can make a heart open
!I might only have one match
!But I can make an explosion
#And all those things I didn't say
#Wrecking balls inside my brain
#I will scream them loud tonight
#Can you hear my voice this time?
@This is my fight song
@Take back my life song
@Prove I'm alright song
@My power's turned on
$Starting right now I'll be strong
$I'll play my fight song
$And I don't really care if nobody else believes
$'Cause I've still got a lot of fight left in me!!!
*/

#include "bits/stdc++.h"
using namespace std;

typedef long long int ll;
const int N = 1e5+5,mod = 1e9+7;
pair<int,int>P[N];
vector<int>vec[N];
int dep[N],Cnt,k,Res;

void dfs( int u,int lev )
{
    dep[u] = 1;
    if( lev>k )Cnt++;
    for(auto v:vec[u])
    {
        if(dep[v])continue;
        dfs(v,lev+1);
    }
}

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

    int n;cin>>n>>k;
    for(int i=1;i<n;i++)
    {
        int u,v;cin>>u>>v;
        vec[u].push_back(v);
        vec[v].push_back(u);
        P[i] = make_pair(u,v);
    }
    Res = n;
    if(k%2==0)
    {
        k /= 2;
        for(int i=1;i<=n;i++)
        {
            Cnt = 0;
            memset(dep,0,sizeof dep);
            dfs(i,0);
            Res = min(Res,Cnt);
        }
    }
    else
    {
        k = (k-1)/2;
        for(int i=1;i<n;i++)
        {
            Cnt = 0;
            memset(dep,0,sizeof dep);
            dep[P[i].first] = dep[P[i].second] = 1;
            dfs(P[i].first,0);
            dfs(P[i].second,0);
            Res = min(Res,Cnt);
        }
    }
    cout<<Res<< "\n";



    return 0;
}


Measured memory_bytes: 3200
/*input
9
*/
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mss map <string,string>
#define msl map <string,ll>
#define mll map <ll,ll>
#define mcl map <char,ll>
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define sz(a) int((a).size())
#define pb push_back
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())     
#define rep(i,j,n) for(ll i=j;i<n;i++)
#define mp make_pair
#define N 998244353
#define PI acos(-1.0)
//if (s.find('R') != std::string::npos)
//s.replace(s.find("10"), sizeof("10") - 1, "");
using namespace std;
bool comp(pair<string,ll>a,pair<string,ll>b){
  if(a.first==b.first) return a.second>b.second;
  return a.first<b.first;
}

int main()
{
  // added the two lines below 
  ios_base::sync_with_stdio (false); 
  cin.tie(NULL);
  cout.tie(0);
  
  ll n;
  cin>>n;
   priority_queue <double, vector<double>, greater<double> > pq;
  double x;
  rep(i,0,n) {
    cin>>x;
    pq.push(x);
  }
  n--;
  while(n--){
    double a=pq.top();
    pq.pop();
    double b=pq.top();
    pq.pop();
    pq.push((a+b)/2);
  }
  cout<<pq.top();


}



Measured memory_bytes: 256
h,w = gets.split.map(&:to_i)
board = h.times.map{ gets.chomp.split('') }
dx=[-1,0,1,0]
dy=[0,1,0,-1]
(0..h-1).each do |i|
  (0..w-1).each do |j|
    next if board[i][j] == '.'

    b_cnt = 0
    (0..3).each do |k|
      x = i + dx[k]
      y = j + dy[k]
      next if (x < 0 || x >= h)
      next if (y < 0 || y >= w)

      b_cnt += 1 if board[x][y] == '#'
    end
    if b_cnt == 0
      puts 'No'
      exit 0
    end
  end
end
puts 'Yes'

Measured memory_bytes: 2172
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// 処理対象個数の入力
		Scanner sc = new Scanner(System.in);
		int input_range = sc.nextInt();
		int input_min = sc.nextInt();
		int input_max = sc.nextInt();
		int result = 0;
		sc.close();

		int sum;
		for(int i=1;i<=input_range;i++) {
			sum = findSumOfDigits(i);
			if(input_min <= sum && sum <= input_max) {
              result += i;
			}
		}

		// 出力
		System.out.println(result);

	}

	// 各桁の和を計算する関数
	static int findSumOfDigits(int n) {
		int sum = 0;
		while (n > 0) { // n が 0 になるまで
			sum += n % 10;
			n /= 10;
		}
		return sum;
	}

}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define sp(x) fixed << setprecision(x)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
 
}

void out(vector<int> &v){
	for(int x : v) cout << x << " ";
}
ll h[N];
vector<pii> g[N];
void solve()
{
	int n;
	cin >> n;
	rep(i, n - 1){
		int x, y, z;
		cin >> x >> y >> z;
		g[--x].pb({--y, z});
		g[y].pb({x, z});
	}
	ll Q, k;
	cin >> Q >> k;
	int s = k - 1;
	const ll INF = 1e18;
	vector<ll> d (n, INF),  p (n);
	d[s] = 0;
	set < pair<int,int> > q;
	q.insert (make_pair (d[s], s));
	while (!q.empty()) {
		int v = q.begin()->second;
		q.erase (q.begin());
		for (size_t j=0; j<g[v].size(); ++j) {
			int to = g[v][j].first,
				len = g[v][j].second;
			if (d[v] + len < d[to]) {
				q.erase (make_pair (d[to], to));
				d[to] = d[v] + len;
				p[to] = v;
				q.insert (make_pair (d[to], to));
			}
		}
	}
	while(Q--){
		int l, r;
		cin >> l >> r;
		cout << d[l - 1] + d[r - 1] << '\n';
	}
}

 
int main()
{
	// freopen("crosses.in", "r", stdin);
	// freopen("crosses.out", "w", stdout);
    Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

Measured memory_bytes: 36716
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define ALL(x) (x).begin(),(x).end()
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define int ll

int C[51][51];

void comb_table(int N){ 
	for(int i=0;i<=N;i++){
		for(int j=0;j<=i;j++){
			if(j==0 || j==i){
				C[i][j]=1;
			}else{
				C[i][j]=(C[i-1][j-1]+C[i-1][j]);
			}
		}
	}
}

signed main(){
    int n,a,b,v[51];
    scanf("%lld%lld%lld",&n,&a,&b);
    comb_table(n);
    REP(i,n) scanf("%lld",&v[i]);
    sort(v,v+n);
    reverse(v,v+n);

    bool rullonz = (v[0]==v[a-1]);
    double ave=0;
    int cnt=0;
    REP(i,a){
        ave += (double)v[i];
        if(v[i]==v[a-1]) cnt++;
    }
    ave /= double(a);
    printf("%lf\n",ave);

    if(rullonz){
        int k = 0;
        REP(i,n) if(v[i]==v[0]) k++;
        int ans = 0;
        for(int i=a;i<=min(b,k);i++){
            ans += C[k][i];
        }
        printf("%lld\n",ans);
    } else {
        int k = 0;
        REP(i,n) if(v[i]==v[a-1]) k++;
        printf("%lld\n",C[k][cnt]);
    }

    return 0;
}

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

int N;
int L[200];
int sum;

int main(){

    cin>>N;

for(int i=0;i<2*N;i++){
    cin>>L[i];
}

sort(L,L+2*N);

sum=0;

for(int i=0;i<2*N;i=i+2){
    sum+=L[i];
}

cout<<sum<<endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp
ll ans = 0;
vector<vector<ll>> vec;
vector<ll> p;



void bit_full_search(int n, int m)
{
    for(int bit = 0; bit < (1 << n); bit++){
        //cout << "{";
        vector<ll> res(m);
        for(int i = 0; i < n; i++){
            if(bit & (1<<i)){
                //cout << " " << i << " ";
                rep(j, m){
                    rep(k, vec[j].size()){
                        if(i == vec[j][k]){
                            res[j]++;
                        }
                    }
                }
            }
        }

        bool flag = true;
        rep(i, m){
            if(res[i] % 2 == p[i]){
                continue;
            }else{
                flag = false;
            }
        }
        if(flag) ans++;

        //cout << "}" << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n, m;
    cin >> n >> m;

    vec.resize(m);
    rep(i, m){
        ll k;
        cin >> k;
        rep(j, k){
            ll s;
            cin >> s;
            s--;
            vec[i].pb(s);
        }
    }

    p.resize(m);
    rep(i, m){
       cin >> p[i];
    }

    
    bit_full_search(n, m);

    cout << ans << endl;

}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  int M = max(max(A,B),max(B,C));//maximum of three integers
  int sum = A + B + C; //invariant of three integers
  
  while( (sum+M) %2 == 1){
    M ++;
  }
  
  int dif = 3*M - (A+B+C);
  int count = dif / 2;
  
  cout << count << endl;
}

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

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

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

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

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int depth = 0;
ll ans = 0;

void attack(ll hp) {
    ans += pow(2, depth);
    if (hp > 1) {
        depth++;
        attack(hp / 2);
    }
}

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

    ll H; cin >> H;
    attack(H);

    cout << ans << endl;
}


Measured memory_bytes: 384
from sys import stdin

def main():
    N = int(stdin.readline().rstrip())
    l = list(map(int, stdin.readline().rstrip().split()))
    result = 1000000
    for i in range(0, max(l)+1):
        sum = 0
        for x in l:
            sum += (x - i)**2
        if result > sum:
            result = sum
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<cstdio>
#include<iostream>
#include<vector>
using namespace std;
const int Maxn=100000+10;
vector <int> e[Maxn];
int a[Maxn];
int n,m,ans;
bool check(int x)
{
	for(int i=0;i<e[x].size();++i)
	{
		int y=e[x][i];
		if(a[y]>=a[x])return 0;
	}
	return 1;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
	scanf("%d",a+i);
	while(m--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	for(int i=1;i<=n;++i)
	if(check(i))++ans;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 9340
/*
* @Author: Kabid
* @Date:   2020-04-19 17:59:10
*/

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define in(x)  scanf("%d", &x);
#define ins(x)  scanf("%s", &x);
#define out(x) printf("%d", x);
#define lin puts("");
#define _ putchar(' ');

int main(){
	int n,m,a[200001]={0},b[200001]={0},s=0,i,c=0,j;
	in(n) 
	for(i=0;i<n-1;i++){
		in(a[i])
		b[a[i]]++;
	}
	for(i=1;i<=n;i++){
		out(b[i]) lin
	}
	

	

	
    return 0;
}

Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a))
#define F0R(a, b) FOR (a, 0, (b))
#define CEIL(a, b) ((a) + (b)-1) / (b)
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
  if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << mt(__VA_ARGS__) << "] "
template <typename T>
struct IsC {
  template <typename C>
  static char test(typename C::const_iterator*);
  template <typename C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
  static const bool value = false;
};
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream&, const C&);
template <typename T1, typename T2>
ostream& operator<<(ostream&, const pair<T1, T2>&);
template <typename... T> using TS = tuple_size<tuple<T...>>;
template<size_t idx, typename... T>
typename enable_if<TS<T...>::value == idx + 1, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return o << ", " << get<idx>(t) << ')';
}
template<size_t idx, typename... T>
typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << ", " << get<idx>(t), t);
}
template<size_t idx = 0, typename... T>
typename enable_if<1 < TS<T...>::value && !idx, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << '(' << get<idx>(t), t);
}
template<typename T>
ostream& operator<<(ostream& o, const tuple<T>& t) {
  return o << get<0>(t);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p) {
  return o << mt(p.fi, p.se);
}
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(
    ostream& o, const C& c) {
  o << '[';
  for (auto it = c.cbegin(); it != c.cend(); ++it)
    o << *it << (next(it) != c.cend() ? ", " : "");
  return o << ']';
}
template <typename T>
void tprint(vector<vector<T>>& v, size_t width = 0, ostream& o = cerr) {
  if (!DEBUG) return;
  for (const auto& vv : v) {
    for (const auto& i : vv) o << setw(width) << i;
    o << endl;
  }
}

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

  int n; cin >> n;
  vector<ll> a(n), b(n);
  F0R (i, n) {
    int x, y; cin >> x >> y;
    a[i] = x + y; b[i] = x - y;
  }
  sort(ALL(a)); sort(ALL(b));
  cout << max(a[n - 1] - a[0], b[n - 1] - b[0]) << endl;;
  
  return 0;
}


Measured memory_bytes: 6344
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College

'''
from os import path
import sys
from heapq import heappush,heappop
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input().rstrip()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
mod=1000000007
# mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

def bo(i):
    return ord(i)-ord('a')

file = 1




    
def solve():

    # k = ii()
    # for _ in range(ii()):
       
        
        n,q = mi()
        par = [i for i in range(n+1)]

        def find(u):
            if u==par[u]:
                return u
            par[u] = find(par[u])
            return par[u]

        def union(u,v):
            u = find(u)
            v = find(v)
            if u != v:
                par[v] = u

        for i in range(q):
            t,u,v = mi()
            if t==0:
                union(u,v)

            else:
                u = find(u)
                v = find(v)
                print(1 if u==v else 0)        


















        

    




        
if __name__ =="__main__":

    if(file):

        if path.exists('input.txt'):
            sys.stdin=open('input.txt', 'r')
            sys.stdout=open('output.txt','w')
        else:
            input=sys.stdin.readline

    # for _ in range(ii()):
    solve()


Measured memory_bytes: 85140
"use strict"
var input = require("fs").readFileSync("/dev/stdin", "utf8");

var readlines = input.split("\n");
var n = readlines[0];
var a = readlines[1].split(" ").map(Number);
var ans = 0;
for(let i = 0; i < n; i++){
  if(i % 2 === 0 && a[i] % 2 === 1){
    ans++;
  }
}

console.log(ans);

Measured memory_bytes: 29476
import java.util.*
import java.math.*
import java.lang.Math.*

val readString: ()->String = {readLine()!!}
val readInt: ()->Int = {readLine()!!.toInt()}
val readLong: ()->Long = {readLine()!!.toLong()}
val readIntArray: ()->IntArray = {readLine()!!.split(' ').map{it.toInt()}.toIntArray()}
val readLongArray: ()->LongArray = {readLine()!!.split(' ').map{it.toLong()}.toLongArray()}
val errPrintln: (String)->Unit = {msg -> System.err.println(msg)}
val MOD = 1e9.toLong()+7
val INF = Int.MAX_VALUE/2
val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)


fun factorize(N: Long): LongArray {
    var factors = ArrayList<Long>()
    var i = 1L
    while(i*i <= N) {
        if (N % i == 0L) {
            val j = N/i
            if (i == j) factors.add(i)
            else {
                factors.add(i)
                factors.add(j)
            }
        }
        i++
    }
    return factors.toLongArray()
}


fun solve(N: Long): Long {
    val fac = factorize(N)
    return fac.filter { it - 1 >  N/it }.map{ it -1 }.sum()
}


fun main(args: Array<String>) {
    val N = readLong()

    val ans = solve(N)

    println(ans)
}


Measured memory_bytes: 33820
using System;

class MainClass {
  public static void Main (string[] args) {
    //入力
    var X = long.Parse(Console.ReadLine());
    var n = 0;
    for(var i = 1; i <= X; i++){
      n += i;
      if(n >= X){
        Console.WriteLine(i);
        return;
      }
    }
    //出力
    
  }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int64_t K;
    string S;
    cin >> S >> K;
    pair<int,char> IC;
    for (int i = 0; i < S.size(); i++) {
        if (S.at(i) != '1') {
            IC.first = i;
            IC.second = S.at(i);
            break;
        }
        if (i == S.size() - 1) {
            cout << 1 << endl;
            return 0;
        }
    }
    if (K - 1 >= IC.first) {
        cout << IC.second << endl;
    }
    else {
        cout << 1 << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	string sp,sq;
	int n;cin>>n;
	cin>>sq>>sp;
	long long ans;
	int pnt;
	if(sp[0]==sq[0]){
		ans=3;
		pnt=1;
	}
	else{
		ans=6;
		pnt=2;
	}
	while(pnt<n){
		if(sp[pnt]==sq[pnt]){
			if(sp[pnt-1]==sq[pnt-1]){
				ans*=2;
				ans%=1000000007;
			}
			pnt++;
		}
		else{
			if(sp[pnt-1]==sq[pnt-1]){
				ans*=2;
				ans%=1000000007;
			}
			else{
			ans*=3;
			ans%=1000000007;
			}
			pnt+=2;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

if n%2 == 0:
  l_ = [0]*(n//2)
  for i in range(n):
    l_[(n-(l[i])-1)//2] += 1
  for j in range(len(l_)):
    if l_[j] != 2:
      print(0)
      exit()
  else:
    print((2**(n//2))%(10**9+7))

else:
  l_ = [0]*(n//2+1)
  for i in range(n):
    l_[(n-(l[i])-1)//2] += 1
  for j in range(len(l_)):
    if j != len(l_)-1: 
      if l_[j] != 2:
        print(0)
        exit()
    else:
      if l_[j] != 1:
        print(0)
        exit()
  else:
    print((2**(n//2))%(10**9+7))


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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define popcnt __builtin_popcount
#define getBit(x, k) ((x >> k) & 1)
#define all(x) (x).begin(),(x).end()
// ---------------------------------

void Main() {
  int s, n;
  cin >> s >> n;
  int m = 0;
  for (int i = 0; i < n; i++) {
    int t; cin >> t;
    m = max(m, t);
  }
  cout << max(m - (s - m + 1), 0ll) << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  cerr << "i love ------- <3 \n";
#endif
  cin.tie(0)->sync_with_stdio(0);
  int T = 1;
  // cin >> T;
  while (T--) Main();
}


Measured memory_bytes: 3612
n=int(input())
h=list(map(int,input().split()))

i, ans = 0, 0

while i<n:
    tmp=0
    j = i+1
    while j<n and h[j-1] >= h[j] :
        tmp += 1
        j+=1
    ans = max(ans, tmp)
    i+=(j-i)
print(ans)

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

int main() {
  string S;
  cin >> S;
  
  if(S == "SUN") {
    cout << "7" << endl;
  }
  else if(S == "MON") {
    cout << "6" << endl;
  }
  else if(S == "TUE") {
    cout << "5" << endl;
  }
  else if(S == "WED") {
    cout << "4" << endl;
  }
  else if(S == "THU") {
    cout << "3" << endl;
  }
  else if(S == "FRI") {
    cout << "2" << endl;
  }
  else if(S == "SAT") {
    cout << "1" << endl;
  }
}


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

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let s: String =input();
    let s: Vec<char> = s.chars().collect();
    for i in 0..3 {
        print!("{}", s[i]);
    }
    println!();
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
using namespace std;
int main(){
	int A, B;
	int ans = 0;
	scanf("%d %d",&A,&B);
	for (int i = 0; i < 2; ++i)
	{
		if (A >= B){
			ans += A;
			A--;
		}else {
			ans += B;
			B--;
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <math.h>
using namespace std;
int main(){
  int a,l,x;
  double s;
  while(cin >> a){
    cin >> l >> x;
    s=sqrt(((l+x)*(l+x)-l*l)/4.0)*l+a*sqrt(l*l-a*a/4.0)/2.0;
    printf("%.10f\n",s);
  }
  return 0;
}

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

using namespace std;

const int NMAX = 100000;

int s[NMAX+2], f[NMAX+2], c[NMAX+2], d[NMAX+2];
int N;

int main()
{
    cin >> N;
    for( int i = 1;  i < N;  ++i ) {
        cin >> c[i] >> s[i] >> f[i];
    }
    for( int i = 1;  i < N;  ++i ) {
        int tm = s[i];
        for( int j = i;  j < N;  ++j ) {
            tm = max(tm, s[j]);
            tm += (f[j] - (tm % f[j])) % f[j];
            tm += c[j];
        }
        cout << tm << '\n';
    }
    cout << "0\n";
    return 0;
}


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

typedef long long ll;
typedef long double ld;

ll a[1000005];

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int k, n;
    cin >> k >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    ll res = k;
    a[0] = a[n]-k;
    for(int i=1; i<=n; i++){
        res = min(res, k-a[i]+a[i-1]);
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <utility>
#include <stdint.h>

using namespace std;

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

  if (A < 10 && B < 10)
    cout << A*B << endl;
  else
    cout << -1 << endl;

  return 0;
}


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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

void solve() {
  int N;
  int M;
  cin >> N >> M;
  //   string ans(N, '$');
  //   for (int i = 0; i < M; i++) {
  //     int s, c;
  //     cin >> s >> c;
  //     s--;
  //     if (ans[s] != '$' && ans[s] != (char)('0' + c)) {
  //       cout << -1 << endl;
  //       return;
  //     }
  //     ans[s] = (char)('0' + c);
  //   }
  //   if (ans[0] == '$') ans[0] = '1';
  //   for (int i = 1; i < N; i++) {
  //     if (ans[i] == '$') ans[i] = '0';
  //   }
  //   if (N > 1 && ans[0] == '0') {
  //     cout << -1 << endl;
  //     return;
  //   }
  //   cout << ans << endl;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  for (int i = 0; i < 1000; i++) {
    string a = to_string(i);
    if (a.size() != N) continue;
    bool judge = true;
    for (int j = 0; j < M; j++) {
      if (a[s[j]] != (char)('0' + c[j])) {
        judge = false;
        break;
      }
    }
    if (judge) {
      cout << i << endl;
      return;
    }
  }
  cout << -1 << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 256
import math

x, y = 0.0, 0.0
theta = 0.0
while True:
	d, t = [eval(num) for num in input().split(',')]
	if d == 0 and t == 0:
		break
	x += d * math.sin(theta)
	y += d * math.cos(theta)
	theta += t * math.pi / 180.0
print(int(x))
print(int(y))

Measured memory_bytes: 7712
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
typedef long long ll;
using namespace std;

int main(void)
{
	int a, b, c; cin >> a >> b >> c;

	if (a == b + c || b == a + c || c == a + b) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
# ABC085 D - Katana Thrower
import numpy as np
n,h = map(int,input().split())
A = []
B = []
ans = 0

for i in range(n):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

B = np.array(B)
a = max(A)
B = B[B > a]
B = np.sort(B)[::-1]

for i in range(len(B)):
    if h <= 0:
        break
    h -= B[i]
    ans += 1

if h > 0:
    ans += (h-1)//a + 1
print(ans)

Measured memory_bytes: 20784
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int tmp = n / 2;
        if (n % 2 == 1)
            tmp++;
        if (k <= tmp)
            System.out.println("YES");
        else
            System.out.println("NO");
    }

}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    int h, w;
    cin >> h >> w;

    // vector<string> grid(h, "");
    string grid[50];
    REP(i, h) cin >> grid[i];

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

    int ct = 0;

    REP(i, h){
        REP(j, w){
            int x, y = 0;
            ct = 0;
            REP(k, 8){
                x = j+dx[k];
                y = i+dy[k];

                if (x < 0 || x > w -1 || y < 0 || y > h-1) continue;
                if (grid[y][x] == '#') ct++;
            }
            if (grid[i][j] == '#' && j == w-1) cout << '#' << endl;
            else if (grid[i][j] == '#') cout << '#';
            else if (j == w-1) cout << ct << endl;
            else cout << ct; 
        }
    }

}

Measured memory_bytes: 256
import Control.Applicative ((<$>))
import Data.List (foldl')
import Data.Vector.Unboxed (Vector, (!), (//))
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = getLine >> solve <$> map read <$> words <$> getLine >>= print

solve :: [Int] -> Int
solve (x:xs) = f ((V.replicate 21 0) // [(x,1)]) xs
  where f :: Vector Int -> [Int] -> Int
        f v [y] = v ! y
        f v (y:ys) = f nv ys
          where nv = foldl' g (V.replicate 21 0) [0..20]
                g :: Vector Int -> Int -> Vector Int
                g v' i = v' // [(i, (if i-y>=0 then (v ! (i-y)) else 0) + (if i+y<=20 then (v ! (i+y)) else 0))]



Measured memory_bytes: 4780