akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

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

	int menseki;
	menseki = a*b;

	int syuu;
	syuu = a*2 + b*2;

	printf("%d %d\n", menseki, syuu);
}

Measured memory_bytes: 1752
n = int(input())
t = [0]
x = [0]
y = [0]

for i in range(n):
  ti, xi, yi = [int(li) for li in input().split()]
  t.append(ti)
  x.append(xi)
  y.append(yi)


def distance(x1, y1, x2, y2):
  return abs(x1 - x2) + abs(y1 - y2)


result = "Yes"
for i in range(n):
  if t[i+1] - t[i] < distance(x[i+1], y[i+1], x[i], y[i]):
    result = "No"
    break
  if ((t[i+1] - t[i]) + distance(x[i+1], y[i+1], x[i], y[i])) % 2 != 0:
    result = "No"
    break

print(result)

Measured memory_bytes: 11816
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	fmt.Println(maxpow2(n))

}

// nを超えない最大の2^m
// ex. 100->64, 32->32, 1->1
func maxpow2(n int) int {
	return 1 << int(math.Log2(float64(n)))
}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

int main(){

  int n,m,l,i,j;

cin >> n >> m >> l;

int matrixA[100][100];
int matrixB[100][100];
long long matrixC[100][100];


for(i = 0; i < n; i++){
  for(j = 0; j < l; j++){
  matrixC[i][j] = 0;
  }
}

  for(i = 0; i < n; i++){
    for(j = 0; j < m; j++){
      cin >> matrixA[i][j];
    }
  }
  for(i = 0; i < m; i++){
    for(j = 0; j < l; j++){
      cin >> matrixB[i][j];
    }
  }

  for(i = 0; i < n; i++){
    for(j = 0; j < l; j++){
      for(int k = 0; k < m; k++){
        matrixC[i][j] += matrixA[i][k] * matrixB[k][j];
      }
    }
  }
  for(i = 0; i < n; i++){
    for(j = 0; j < l; j++){
      cout << matrixC[i][j];
      if(j != l-1){
         cout << ' ';
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
#include <limits>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fi(i,n) for( int i=0 ; i<n ; i++ )
#define f(i, a, b) for( int i=a ; i<b ; i++ )
#define vi vector<int>
#define pb push_back
#define mod 1000000007
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
ll fact(ll n)
{
    ll ans = 1e14;
    for(ll i = 1; i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            ll sol = (i - 1) + (n/i - 1);
            ans = min(ans,sol);
        }
    }
    return ans;
}
int visited[200000] = {0};
vector<vector<int> > v(200000);
int dfs(int x)
{
    int ans = 0;
    if(visited[x]==0)
    {
        visited[x] = 1;
        ans++;
        int a = v[x].size();
        for(int j = 0; j<a; j++)
        {
            int data = v[x][j];
            ans = ans + dfs(data);
        }
    }
    return ans;
}
void primefactors(int n)
{
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            cout << i << " ";
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        cout << n << " ";

}
double fib(int n)
{
    double sol1,sol2;
    sol1 = (1 + sqrt(5))/2;
    sol2 = (1 - sqrt(5))/2;
    sol1 = pow(sol1,n);
    sol2 = pow(sol2,n);
    double ans = sol1 - sol2;
    ans = ans/sqrt(5);
    //ans = int(ans);
    return ans;
}

ll digits(ll n)
{
    return floor(log10(double(n))) + 1;
}

ll index(ll n)
{
    n = double(n);
    double sol = n*n + n;
    sol = sol*2 + 1;
    double ans = -1 + sqrt(sol);
    ans = ans/2;
    ans = ll(ans);
    return ans;
}
int main()
{
    ll n;
    cin>>n;
    ll a = INT_MIN;//xi + yi max
    ll b = INT_MIN;//xi - yi max
    ll c = INT_MAX;// xj + yj min
    ll d = INT_MAX;// xj - yj min
    fi(i,n)
    {
        ll x,y;
        cin>>x>>y;
        a = max(a,x + y);
        b = max(b,x - y);
        c = min(c,x + y);
        d = min(d,x - y);
    }
    ll ans = max(a - c,b - d);
    cout<<ans;
}


Measured memory_bytes: 7852
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans[ohara],a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll r,l;
ll cut[ohara];
ll la_r[ohara];

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>s;
    rep(i,Size(s)){
        if(s[i]=='R'){
            if(l){
                cut[i-1]=1;
                la_r[i-1]=tmp;
                r=0;l=0;
            }
            tmp=i;
        }
        if(s[i]=='R')r=1,tmp=i;
        else l=1;
    }
    la_r[Size(s)-1]=tmp;
    cut[Size(s)-1]=1;
    ll l_cou=0,r_cou=0;
    //rep(i,Size(s))Cout(la_r[i]);
    rep(i,Size(s)){
        if(s[i]=='R')r_cou++;
        else l_cou++;
        if(cut[i]==1){
            ll r_ans=0,l_ans=0;
            r_ans=(r_cou+1)/2;
            l_ans=r_cou/2;
            r_ans+=l_cou/2;
            l_ans+=(l_cou+1)/2;
            ll ind=la_r[i];
            ans[ind]=r_ans;
            ans[ind+1]=l_ans;
            r_cou=0;
            l_cou=0;
        }
    }
    rep(i,Size(s)){
        if(i==Size(s)-1)Cout(ans[i]);
        else cout<<ans[i]<<" ";
    }
    return 0;
}


Measured memory_bytes: 9680
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int N,M;
	int mas[1001];
	while(scanf("%d %d",&N,&M)){
		if(N==0&&M==0)
		break;
		for(int i=0;i<N;i++){
			scanf("%d",&mas[i]);
		}
		int count=0,temp=0;
		int sai;
		while(temp<N-1){
			count++;
			scanf("%d",&sai);
			temp+=sai;
			temp+=mas[temp];
		}
		for(int i=count;i<M;i++) scanf("%d",&temp);
		printf("%d\n",count);
	}
}

Measured memory_bytes: 3212
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }
        long res = 0;
        long base = 1;
        long mod = 1000000007;
        for(int j=0; j<61; j++) {
            int c1 = 0;
            int c0 = 0;
            for(int i=0; i<n; i++) {
                if((a[i] >> j) % 2 == 1) {
                    c1++;
                } else {
                    c0++;
                }
            }
            if(c1 == 0 || c0 == 0) {
                base *= 2;
                base %= mod;
                continue;
            }
            long add = base;
            add *= c1;
            add %= mod;
            add *= c0;
            add %= mod;
            res += add;
            res %= mod;
            base *= 2;
            base %= mod;
        }
        System.out.println(res);
    }
}


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

def main():
    a, b = raw_input().split()
    if a is "D":
        if b is "H":
            print "D"
        elif b is "D":
            print "H"
    elif a is "H":
        if b is "H":
            print "H"
        elif b is "D":
            print "D"

if __name__ == '__main__':
    main()

Measured memory_bytes: 2568
import itertools

n = int(input())
p = tuple(map(int, input().split(" ")))
q = tuple(map(int, input().split(" ")))

seq = tuple([i+1 for i in range(n)])
seqlist = list(itertools.permutations(seq))
pint = 0
qint = 0

for i, hoge in enumerate(seqlist):
  if hoge == p:
    pint = i
  if hoge == q:
    qint = i

print(abs(pint - qint))



Measured memory_bytes: 8052
#include <bits/stdc++.h>
#include<deque>
#define jio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
//#define mp make_pair
#define pb push_back
#define lld long long int
#define clr clear()
#define ff first
#define ss second
#define N 1000005
//#define M 1000
#define endl '\n'
#define c_s_b() __builtin_popcount()

#define sze 10000009
#define pii pair<int,int>
#define big 100005
#define int long long

using namespace std;

int n,W;
int val[big];
int wt[big];
int dp[105][big];

int ks(int n,int W){
    if(n<0 || W<0){
        return 0;
    }
  /*  if(n==0){
        return val[n];
    }   */
    if(dp[n][W]!=-1) return dp[n][W];
    if(W<wt[n]){
        return dp[n][W]=ks(n-1,W);
    }

    return dp[n][W]=max(ks(n-1,W-wt[n])+val[n],ks(n-1,W));

}




int32_t main(){
   jio;
    cin>>n>>W;
    for(int i=0;i<n;i++){
        cin>>wt[i]>>val[i];
    }
     memset(dp,-1,sizeof(dp));

     cout<<ks(n-1,W)<<endl;













    return 0;


}


Measured memory_bytes: 82304
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N, M; cin >> N >> M;

    cout << (N==M?"Yes":"No") << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        if(line.equals("ARC")){
            System.out.println("ABC");
        } else {
            System.out.println("ARC");
        }
    }
}


Measured memory_bytes: 35688
n = int(input())
a = [int(i) for i in input().split()]

a_max=max(a)
i_max=a.index(a_max) + 1
a_min=min(a)
i_min=a.index(a_min) + 1
ans=[]

if a_min>=0:
    print(n-1)
    for i in range(1,n):
        print(i,i+1)
elif a_max<0:
    print(n-1)
    for i in range(n,1,-1):
        print(i,i-1)
elif abs(a_max)>abs(a_min):
    print(2*n-2)
    for i in range(1,n+1):
        if i != i_max:
            print(i_max,i)

    for i in range(1,n):
        print(i,i+1)

else:
    print(2*n-2)
    for i in range(1,n+1):
        if i != i_min:
            print(i_min,i)
    for i in range(n,1,-1):
        print(i,i-1)


Measured memory_bytes: 9264
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define REP(i, n) for(int i=0; i<n; i++)
#define RER(i, n) for(int i=n-1; i>=0; i--)
#define ALL(v) v.begin() v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;

signed main(){
	cin >> n;
	if(n <= 111){
		cout << 111 << endl;
	}else if(n <= 222){
		cout << 222 << endl;
	}else if(n <= 333){
		cout << 333 << endl;
	}else if(n <= 444){
		cout << 444 << endl;
	}else if(n <= 555){
		cout << 555 << endl;
	}else if(n <= 666){
		cout << 666 << endl;
	}else if(n <= 777){
		cout << 777 << endl;
	}else if(n <= 888){
		cout << 888 << endl;
	}else if(n <= 999){
		cout << 999 << endl;
	}
    return 0;
}

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

using namespace std;

#define whole(xs) (xs).begin(),(xs).end()

// Longest Increasing Subsequence
int LIS(const vector<int>& xs) {
    vector<int> L(xs.size(), INT_MAX);
    for (int i = 0; i < xs.size(); i++) {
        (*lower_bound(whole(L), xs[i])) = xs[i];
    }
    return lower_bound(whole(L), INT_MAX) - L.begin();
}

int N;
vector<int> A;
int main() {
    cin >> N;
    A.resize(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    cout << LIS(A) << endl;
    return 0;
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;


int main(){
  int n;
  cin >>n;
  int a[n];
  rep(i,n)cin >> a[i];
  int ans=0;
  rep(i,n){
    if((i+1)%2==1 && a[i]%2==1)ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3616
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int N;
int to[200001], ne[200001], he[100001];
ll mod = 1e9 + 7;
pair<ll, ll> dfs(int A, int prev) {
	ll kuro = 1;
	ll siro = 1;
	for (int i = he[A]; i; i = ne[i]) {
		int To = to[i];
		if (To != prev) {
			auto k = dfs(To, A);
			kuro = (kuro * k.second) % mod;
			siro = (siro * k.first) % mod;
		}
	}
	return mp(kuro + siro, siro);
}

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	N = getint();
	int k = 1;
	rep(i, N - 1) {
		int x = getint(), y = getint();
		to[k] = y;
		ne[k] = he[x];
		he[x] = k++;
		to[k] = x;
		ne[k] = he[y];
		he[y] = k++;
	}

	auto M = dfs(1, 0);
	printf("%lld", M.first % mod);

	Would you please return 0;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;

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

  for(int i=0; i<s.size(); i++){
    if(s[i]=='1'){
      cout << '9';
    }else{
      cout << '1';
    }
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, sum=0, max=0, p; cin >> N;
  for (int i=N; i>0; i--){
    cin >> p;
    sum += p;
    max = max<p?p:max;
  }
  cout << sum - max/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

template < typename T > T local_max(T a, T b) {return a > b ? a : b;}

int main(int argc, char* argv[])
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll max_n = 1e6;
  std::vector< bool > is_prime(max_n+1, true);
  std::vector< ll > like_sum (max_n+1, 0L);

  is_prime[0] = false;
  is_prime[1] = false;
  for (ll i = 2 ; i <= max_n; i++) {
    if (is_prime[i]) {
      for (ll j = 2 * i; j <= max_n; j += i) {
	is_prime[j] = false;
      }
    }
  }

  like_sum[0] = 0;
  for (ll i = 1 ; i <= max_n; i++) {
    like_sum[i] = like_sum[i-1];
    if (is_prime[i] && is_prime[(i+1)/2]) {
      like_sum[i]++;
    }
  }

  ll Q;
  std::cin >> Q;
  for (ll i = 0; i < Q; i++) {
    ll l, r;
    std::cin >> l >> r;
    std::cout << like_sum[r] - like_sum[l-1] << std::endl;
  }

  return 0;
}


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

using ll = long long;
using ld  = long double;
using pll = pair<ll, ll> ;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=1LL<<60 ;
const ll MOD=1e9+7 ;
const ld PI=acos(-1);
const ld EPS = 1e-9; //微調整用（EPSより小さいと0と判定など）

#define gcd __gcd //llは受け取ってくれない
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define ALL(a) a.begin(),a.end() //sort(ALL(vec));
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define PB push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに

//最大値、最小値を更新する。aよりbのが大きい（小さい）か等しければaを更新してtrueを返す。そうでなければ何もせずfalseを返す chmax(nowmax,x);
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

// ----- template end ---- //

// ------- library ------- //


// ----- library end ----- //



int main() {
  string N;
  ll K;
  cin >> N >> K;

  set<char> NOs;
  rep(i,K){
    char a;
    cin >> a;
    NOs.insert(a);
  }

  bool ansflag = false; //答えが見つかったら1
  int ans = 0;
  REP(i, stoi(N), 100000){
    ansflag = true; //一旦1にする
    for (char c : to_string(i)){
      if (NOs.find(c) != NOs.end()){ //もしcがNOsに入っていたら(ダメな数字を使っていたら)
        ansflag = false;
      }
    }
    if (ansflag){
      ans = i;
      break;
    }
  }

  cout << ans << endl;



}


 

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "set"
#include "vector"
#include "map"
#include "cmath"
#define MAXN 506
//#define int long long
using namespace std;
typedef long long ll;
#define P 1000000007
int n;
int A[MAXN];

ll work( int l , int r , int L , int R ) {
    if( r - l <= 1 ) return 0;
    ll ans = 0x3f3f3f3f3f3f3f3f;
    for( int i = l + 1 ; i <= r - 1 ; ++ i ) ans = min( ans , work( l , i , L , L + R ) + work( i , r , L + R , R ) + 1ll * ( L + R ) * A[i] );
    return ans;
}

int main() {
    cin >> n;
    for( int i = 1 ; i <= n ; ++ i ) scanf("%d",&A[i]);
    cout << work( 1 , n , 1 , 1 ) + A[1] + A[n] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

vector<ii> vec[1000001];
int par[111111];
vi used;
vector<ii> adj[350001];

int rt(int u)
{
	if(par[u]<0) return u;
	return (par[u]=rt(par[u]));
}

void merge(int u, int v)
{
	u=rt(u); v=rt(v);
	if(u==v) return ;
	if(par[u]>par[v]) swap(u,v);
	par[u]+=par[v];
	par[v]=u;
}

int dist[311111];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,m; cin>>n>>m;
	memset(par,-1,sizeof(par));
	for(int i = 0; i < m; i++)
	{
		int u,v,w; cin>>u>>v>>w;
		u--; v--; w--;
		vec[w].pb(mp(u,v));
	}
	int cnt = n;
	for(int i = 0; i < 1000000; i++)
	{
		if(vec[i].empty()) continue;
		for(int j = 0; j < vec[i].size(); j++)
		{
			int u=vec[i][j].fi; int v=vec[i][j].se;
			used.pb(u); used.pb(v);
			merge(u,v);
		}
		map<int,int> ma;
		for(int j = 0; j < used.size(); j++)
		{
			int u=used[j];
			if(rt(u)==u) ma[u]=cnt++;
		}
		for(int j = 0; j < used.size(); j++)
		{
			int u=used[j];
			adj[u].pb(mp(ma[rt(u)],1));
			adj[ma[rt(u)]].pb(mp(u,0));
		}
		for(int j = 0; j < used.size(); j++)
		{
			int u=used[j]; par[u]=-1;
		}
		used.clear();
	}
	for(int i = 0; i < cnt; i++) dist[i]=int(1e9);
	dist[0]=0;
	deque<int> q;
	q.pb(0);
	while(!q.empty())
	{
		int u=q.front(); q.pop_front();
		for(int i=0;i<adj[u].size();i++)
		{
			int v=adj[u][i].fi; int w=adj[u][i].se;
			if(dist[v]>=int(1e9))
			{
				dist[v]=dist[u]+w;
				if(w==1) q.pb(v);
				else q.push_front(v);
			}
		}
	}
	if(dist[n-1]<int(1e9)) cout<<dist[n-1]<<'\n';
	else cout<<-1<<'\n';
}


Measured memory_bytes: 51456
#include<iostream>
#include<stdio.h>
using namespace std;
 
int main(){
  int N,D,a,b,c,d,e;
  cin>>N>>D;
  a=2*D;
  b=1+a;
  c=N/b;
  d=N%b;
  e=c+1;
  if(d==0){
    cout<<c;
  }else{
    cout<<e;
  }
return 0;
}

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

using namespace std;

int main() {
  int D, G;
  cin >> D >> G;
  int p[D+1];
  int c[D+1];
  p[0] = 0;
  c[0] = 0;

  int comp_score[D+1];

  for(int i=1; i<=D; i++){
    cin >> p[i] >> c[i];
    comp_score[i] = p[i]*i*100 + c[i];
  }

  int min = 1e9;
  for(int i = 0; i < pow(2,D); i++){
    int f[D+1];
    int a = i;
    for(int j = 1; j<=D; j++){
      f[j] = a%2;
      a /=2;
      //cout << f[j];
    }

    int score = 0;
    int num = 0;
    for(int j=1; j<=D; j++){
      if(f[j] == 1){
        score += comp_score[j];
        num += p[j];
      }
    }
    if(score < G){
      for(int j=D; j>0; j--){
        if(f[j] == 0){
          for(int k=0; k<p[j]-1; k++){
            score += j*100;
            num++;
            if(score >= G) break;
          }
          break;
        }
      }
    }

//cout << " num:" << num << " score:" << score <<  "\n";

    if(score >= G){
      if(min > num) min = num;
    }
  }

  cout << min;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long
#define re register
using namespace std;
struct ios{
	inline char fchar(){
		static char buf[100000],*p1=buf,*p2=buf;
		return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
	}
//	#define getchar fchar
	template <typename ty> inline ios& operator >> (ty &x)
	{
		register int f=1;x=0;register char c=getchar();
		for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
		for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
		x*=f;return *this;
	}
	template <typename ty>  inline ios& operator << (ty x)
	{
		if(x<0) x=-x,putchar('-');
		if(x>9) *this << x/10;
		putchar(x%10+48);
		return *this;
	}
	inline ios& operator << (char x){putchar(x);return *this;}
}io;
const int N = 1e5+5;
int n;
ll a[N],b[N];
int main()
{
	io>>n;
	for(int i=1;i<=n+1;i++) io>>a[i];
	for(int i=1;i<=n;i++) io>>b[i];
	ll ans = 0;
	for(int i=1;i<=n;i++)
	{
		if(b[i]>=a[i])
		{
			ans += a[i];
			b[i] -= a[i];
			a[i] = 0;
		}
		else 
		{
			ans+=b[i];
			a[i]-=b[i];
			b[i]=0;
		}
		if(b[i]>=a[i+1])
		{
			ans += a[i+1];
			b[i] -= a[i+1];
			a[i+1] = 0;
		}
		else
		{
			ans += b[i];
			a[i+1] -= b[i];
			b[i] = 0;			
		}
	}
	io<<ans;
	
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "";
const string NO  = "";

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

    double t, x;

    cin >> t >> x;

    cout << fixed << setprecision(10) << t / x << endl;

    return 0;
}



Measured memory_bytes: 768
/// Author: Sarfaraz Alam
# include <bits/stdc++.h>
# define pb push_back
# define ll long long

# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG
typedef unsigned long long int ull;
using namespace std;
#include<cmath>
const int N = 1e5 + 7;
const int mod = 1e9 + 7;

int n, a[N], ans = 1, x;

int main()
{
    speed;
    #ifdef DEBUGfd
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG

    //Code begins
    int n, c;
    cin>>n>>c;




    int a[n][2], b[c][2];


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

    // cout<<"value for the a : ";
    // for(int i = 0; i<n; i++)
    // cout<<a[i][0]<<a[i][1]<<endl;




    int d ;
    int min[n] ;

    for(int i = 0; i<n; i++)
    {
        int m = INT_MAX;
        int checkpoint = -1;
      for(int j = 0; j<c; j++)
      {
    //    cout<<"value of y coordinate: "<<a[i][1]<<" "<<b[i][1]<<endl;
      //  cout<<abs(a[i][0] - b[j][0])<<" "<<abs(a[i][1] - b[j][1])<<endl;
          d = abs(a[i][0] - b[j][0]) + abs(a[i][1] - b[j][1]);
      //    cout<<"value of d: "<<d<<endl;
          if(d < m)
          {
            m = d;
            checkpoint = j+1;
          }
      }
      min[i] = checkpoint ;
    }

    for(int i =0; i<n; i++)
    cout<<min[i]<<"\n";


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
const int MOD = 1e9 + 7;
 
vector<long long> fact_inv, inv, Com;
 
/*  init_nCk :二項係数のための前処理
    計算量:O(n)
*/
void init_nCk(int n, int SIZE) {
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
    Com.resize(SIZE + 5);
    Com[0] = 1;
    for (int i = 1; i < SIZE + 5; i++) {
        Com[i] = Com[i - 1] * ((n - i + 1) * inv[i] % MOD) % MOD;
    }
}
 
/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int k) {
    assert(!(k < 0));
    return Com[k];
}
int main() {
	ll n,a,b;
	cin>>n>>a>>b;
	init_nCk(n,10000000);		
    ll sum1=modpow(2, n, 1000000007)-1 ;
    ll suma=nCk(a);
    ll sumb=nCk(b);
    if(sum1<suma){
    	sum1+=-suma+inf;
    }
    else{
    	sum1+=-suma;
    }
    if(sum1<sumb){
    	sum1+=-sumb+inf;
    }
    else{
    	sum1+=-sumb;
    }    
    cout <<sum1;
	// your code goes here
	return 0;
}

Measured memory_bytes: 237632
#include<cstdio>
#include<algorithm>
using namespace std;
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MM 100000
#define MX 1600000
#define N 131072
struct work{int t,l,r;}w[MX+5];
bool cmp(const work&a,const work&b){return a.r!=b.r?a.r<b.r:a.t>b.t;}
int ans[MM+5],wn,t[N*2+5];
void inc(int k){for(k+=N;k;k>>=1)++t[k];}
int query(int l,int r)
{
	int res=0;
	for(l+=N-1,r+=N+1;l^r^1;l>>=1,r>>=1)
	{
		if(~l&1)res+=t[l+1];
		if( r&1)res+=t[r-1];
	}
	return res;
}
int main()
{
	int n,m,i,j;
	n=read();m=read();
	for(i=1;i<=n;++i)w[++wn].l=read(),w[wn].r=read();
	for(i=1;i<=m;++i)for(j=0;j<m;j+=i)w[++wn]=(work){1,i,j+i};
	sort(w+1,w+wn+1,cmp);
	for(i=1;i<=wn;++i)
		if(w[i].t)ans[w[i].l]+=query(w[i].r-w[i].l+1,MM);
		else inc(w[i].l);
	for(i=1;i<=m;++i)printf("%d\n",n-ans[i]);
}

Measured memory_bytes: 20352
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e9;//1<<30;
int main(){
	int n,m;
	cin>>n>>m;
	vi in(n);
	rep(i,n)cin>>in[i];
	vvi ta(m,vi(3));
	rep(i,m)rep(j,3)cin>>ta[i][j];
	vvi dp(n,vi(m,-inf));
	rep(i,m)if(ta[i][0]<=in[0]&&in[0]<=ta[i][1])dp[0][i]=0;
	loop(i,1,n)rep(j,m)if(ta[j][0]<=in[i]&&in[i]<=ta[j][1]){
		rep(k,m)if(dp[i-1][k]!=-inf){
			dp[i][j]=max(dp[i][j],dp[i-1][k]+abs(ta[j][2]-ta[k][2]));
		}
	}

	int out=0;
	rep(i,m)out=max(out,dp[n-1][i]);
//	rep(i,n){rep(j,m)cout<<" "<<dp[i][j];cout<<endl;}
	cout<<out<<endl;
}

Measured memory_bytes: 1352
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int p[N];
  for (int i = 0; i < N; i++)
    cin >> p[i];
  sort(p, p + N);
  cout << p[N / 2] - p[N / 2 - 1];
  
  return 0;
}

Measured memory_bytes: 640
# ABC150C - Count Order
from itertools import permutations


def main():
    N = int(input())
    P = tuple(map(int, input().split()))
    Q = tuple(map(int, input().split()))
    perms = tuple(permutations(range(1, N + 1)))
    ans = abs(perms.index(P) - perms.index(Q))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 7992
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <complex>
#include <cmath>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define X real()
#define Y imag()
using namespace std;
typedef complex<int> cld;
typedef vector<cld> vcl;
typedef vector<int> vi; 
typedef long long ll;
ll lcs(ll p, ll q){
	ll s=min(p,q),b=max(p,q);
	if(b%s ==0)
	return s;
	else
	return lcs(b%s,s);
}
ll gcd(ll p,ll q){
	return p*q/lcs(p,q);
}
int main() {
	int n;
	while(cin >> n && n){
	bool fin[101]={1,0};
	ll mobil[101][4]={};
	ll grav[101]={1,0};
	ll p,q,r,b;
	FOR(i,1,n+1){
		cin >> p >> q >> r >>b;
		ll d=lcs(p,q);
		mobil[i][0]=q/d;
		mobil[i][1]=p/d;
		mobil[i][2]=r;
		mobil[i][3]=b;
	}
	REP(j,101){
		FOR(i,1,n+1)
			if(fin[mobil[i][2]] && fin[mobil[i][3]] && !fin[i]){
				ll full=(mobil[i][0]+mobil[i][1]);
				ll needA=grav[mobil[i][2]]/lcs(grav[mobil[i][2]],mobil[i][0]);
				ll needB=grav[mobil[i][3]]/lcs(grav[mobil[i][3]],mobil[i][1]);
				grav[i]=full*(gcd(needA,needB));
					fin[i]=true;
			}
	}
	ll maxim=0;
	FOR(i,1,n+1)
	maxim=max(maxim,grav[i]);
	cout << maxim << endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <cstring>

using namespace std;

int main(void)
{
    int q;
    char x[1001], y[1001];
    int table[1001][1001];
    
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> x >> y;
        int xl = strlen(x), yl = strlen(y);

        for (int i = 0; i < xl; i++)
            for (int j = 0; j < yl; j++)
                if (x[i] == y[j])
                    table[i+1][j+1] = 1 + table[i][j];
                else
                    table[i+1][j+1] = max(table[i][j+1], table[i+1][j]);

        cout << table[xl][yl] << endl;
    }

    return 0;
}

Measured memory_bytes: 5080
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define int long long
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%lld",&a)
#define getII(a,b) scanf("%lld%lld",&a,&b)
#define getIII(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define VgetI(n) int (n); scanf("%lld",&(n))
#define VgetII(n,m) int (n),(m); scanf("%lld%lld",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define INF 2000000000
int a[200005],dis[200005];
bool vis[200005];
main(){
	int n,k;
	while(~getII(n,k)){
		FE(i,1,n) getI(a[i]);
		FE(i,1,n) vis[i]=0,dis[i]=INF;
		int u=1,chainLen=0,loopLen=0;
		dis[1]=0;
		while(1){
			vis[u]=1;
			int v=a[u];
			if(vis[v]){
				u=v;
				break;
			}
			dis[v]=dis[u]+1;
			u=v;
		}
		chainLen=dis[u];
		int op=u;
		while(1){
			loopLen++;
			u=a[u];
			if(op==u) break;
		}
		if(k<chainLen){
			u=1;
			while(k--) u=a[u];
			printf("%lld\n",u);
		}else{
			k-=chainLen;
			k%=loopLen;
			while(k--) u=a[u];
			printf("%lld\n",u);
		}
	}
}


Measured memory_bytes: 7184
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int n;
  string s;
  cin >> n >> s;
  map<pair<string, string>, int> mp;
  rep(i, 1 << n){
    string red = "";
    string blue = "";
    rep(j, n){
      if((i >> j) % 2 == 1){
        red += s[j];
      }else{
        blue += s[j];
      }
    }
    reverse(blue.begin(), blue.end());
    mp[mk(red, blue)]++;
  }
  ll res = 0;
  rep(i, 1 << n){
    string red = "";
    string blue = "";
    rep(j, n){
      if((i >> j) % 2 == 1){
        red += s[n+j];
      }else{
        blue += s[n+j];
      }
    }
    reverse(blue.begin(), blue.end());
    res += mp[mk(blue, red)];
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 87040
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int b[26];
signed main() {
	int n;
	cin>>n;
	int a[26];
	for(int i=0;i<26;i++){
		a[i]=inf;
	}
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		for(int j=0;j<26;j++)
			b[j]=0;
		for(int j=0;j<s.size();j++){
			b[(int)(s[j]-'a')]++;
		}
		for(int j=0;j<26;j++){
			a[j]=min(a[j],b[j]);
		}
	}
	string h="";
	for(int i=0;i<26;i++){
		if(a[i]==inf) continue;
		for(int j=0;j<a[i];j++){
			h+=(char)(i+'a');
		}
	}
	cout<<h<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int x[n];
  x[0] = 0;
  for (int i = 0; i < n; i++){
    if (i % 2) x[0] -= a[i];
    else x[0] += a[i];
  }
  for (int i = 1; i < n; i++){
    x[i] = 2 * a[i - 1] - x[i - 1];
  }
  
  for (int i = 0; i < n; i++){
    printf("%d ", x[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define d double
using namespace std;
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin>>s;
  size_t n=s.size();
  int i=n-1;
  int j=0;
  int count=0;
  while(i>j){
  	
  	if(s[j++]!=s[i--]){
  		count++;
  		
	  }
  	
  }
   cout<<count<<endl;

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
int main() {
    int R,G;
    cin >> R >> G;
	cout << (2*G-R) << endl;
	return 0;
}

Measured memory_bytes: 256
n,d = map(int,input().split())
L = []
for i in range(n):
    L.append(list(map(int,input().split())))
ans = 0
for i in range(n):
    for j in range(i+1,n):
        s = 0
        for k in range(d):
            s += (L[i][k]-L[j][k])**2
        s = s**0.5
        if s == int(s):
            ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(void)
{
    int N, N1, i, sum=0;

    cin >> N;

    N1 = N;

    while(N != 0){
        sum += (N%10);
        
        N /= 10;
    }

    if(N1 % sum == 0){
        cout << "Yes" << endl;
    }

    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
def main():
	mod=10**9+7
	k=int(input())
	s=input()
	n=len(s)
	fac=[1]
	for i in range(k+n+1):
		fac.append(fac[-1]*(i+1)%mod)
	def c(x,y):
		r=fac[y]*fac[x-y]%mod
		return fac[x]*pow(r,mod-2,mod)%mod
	ans=0
	for i in range(n,k+n+1):#iはSnの位置
		r=c(i-1,n-1)*pow(25,i-n,mod)*pow(26,n+k-i,mod)%mod
		ans+=r
		ans%=mod
	print(ans)
if __name__ == '__main__':
	main()

Measured memory_bytes: 210896
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    string s, t;
    cin >> s >> t;
    ll S = len(s), T = len(t);

    vector<vector<ll>> dp(S + 10, vector<ll>(T + 10, 0));

    rep(i,S) rep(j,T){
        if(s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1; 
        else dp[i + 1][j + 1] = max({dp[i][j + 1], dp[i + 1][j]});
    }

    string ans = "";

    ll i = S, j = T;
    while(i and j){
        if(dp[i][j] == dp[i-1][j]) --i;
        else if(dp[i][j] == dp[i][j-1]) --j;
        else ans += s[i-1], --i, --j;
    }

    reverse(ALL(ans));
    print(ans);

    return 0;
}

Measured memory_bytes: 71168
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template<typename T> void print(const T & v);


int main() {
    string S;
    cin >> S;
    ll cnt = 0;
    ll idx = 0;
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'W'){
            cnt += i - idx;
            idx++;
        }
    }
    cout << cnt << endl;
}






// Use For Debug
template <typename T>
void print(T const & v){
    for(int i = 0; i < v.size(); i++){
        if(i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}


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

#define ll            long long
#define pb            push_back
#define si            set <int>
#define F             first
#define S             second
#define mii           map<int ,int >
#define msi           map<string,int >
#define mis           map<int , string>
#define fr(i,a,b)     for(int  i=a;i<=b;i++)
#define loop(i,n)     for(int i=0;i<n;i++)
#define all(v)        v.begin(),v.end()
#define vi            vector<int >
#define vii           vector<pair<int , int >>
#define vs            vector<string>
#define sz(x)         (int )x.size()
#define M             1000000007
#define mp            make_pair
#define input(arr,n)  loop(i,n) cin>>arr[i]
#define output(arr,n) loop(i,n) cout<<arr[i]<<" "
#define mod           998244353
#define sof           sizeof
using namespace std;
int gcd(int a,int b){
  if(b==0)return a;
  return gcd(b,a%b);
}

bool isPrime(int num){
    
    if(num==2) return true;
    if(num<2 || num%2==0) return false;
    for(int i = 3; i*i <=num; i+=2) {
       if(num % i == 0) {
          
          return false;
       }
    }
    return true;
   
}

bool comp(const pair<int,int> &a,const pair<int,int> &b){
  return a.F>b.F;
}



void solve(){
  // a simple dp problem
  int n,k;
  cin>>n>>k;
  ll arr[n];
  ll f[n];
  loop(i,n){
    cin>>arr[i];
    f[i]=INT_MAX;
  }
  k=min(n,k);
  f[0]=0;
  fr(i,1,k-1){
    f[i]=abs(arr[i]-arr[0]);
  }
  fr(i,k,n-1){
    ll mi=INT_MAX;
    fr(j,i-k,i-1){
      mi=min(mi,abs(arr[i]-arr[j])+f[j]);
    }
    f[i]=mi;
  }
  cout<<f[n-1];
 


}




signed main()   
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); 
  cout.tie(0);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout); 
  #endif  

  int t;
  t=1;
  //cin>>t;
  loop(i,t){

      solve();
      if(i<t-1) cout<<"\n";
  }

  
  
  //directed graph
    



}
  


  



Measured memory_bytes: 5220
n=int(raw_input())
xy=[]
for i in xrange(n):
    x,y=map(int,raw_input().split())
    if x>y:x,y=y,x
    xy.append((x,y))
xy.sort()
mn=10**12;mx=0
for i in xrange(n):
    x,y=xy[i]
    mn=min(mn,x)
    mx=max(mx,y)
cntmx=0;cntmn=0
for i in xrange(n):
    x,y=xy[i]
    if mx==y:cntmx+=1
    if mn==x:cntmn+=1
if cntmx==1 and cntmn==1 and xy[0][0]==mn and xy[0][1]==mx:
    rmn=xy[0][1];rmx=xy[0][1];bmn=xy[0][0];bmx=xy[0][0]
    for i in xrange(1,n):
        x,y=xy[i]
        rmn=min(rmn,y)
        rmx=max(rmx,y)
        bmn=min(bmn,x)
        bmx=max(bmx,x)
    print (rmx-rmn)*(bmx-bmn)
    exit()
else:
    rmn=10**12;rmx=0;bmn=10**12;bmx=0
    for i in xrange(n):
        x,y=xy[i]
        rmn=min(rmn,y)
        rmx=max(rmx,y)
        bmn=min(bmn,x)
        bmx=max(bmx,x)
ans1=(rmx-rmn)*(bmx-bmn)
xy.sort()
ymn=[10**12]*n
rmn=bmn;bmn=xy[0][0];bmx=xy[n-1][0]
for i in xrange(n):
    x,y=xy[i]
    ymn[i]=min(ymn[max(0,i-1)],y)
ans2=(rmx-rmn)*(bmx-bmn)
for i in xrange(n-1):
    x,y=xy[i]
    if ymn[i]<x:
        bmn=max(bmn,ymn[i-1])
        break
    bmn=x
    bmx=max(bmx,xy[max(0,i-1)][1])
    ans2=min(ans2,(rmx-rmn)*(bmx-bmn))
ans2=min(ans2,(rmx-rmn)*(bmx-bmn))
print min(ans1,ans2)


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

int main() {
    int n, k;
    cin >> n >> k;
    int mx = (n-1)*(n-2)/2;
    if (mx < k) {
        cout << -1 << endl;
        return 0;
    }
    vector<P> ans;
    rep(i,n-1) {
        ans.push_back(P(i+1,n));
    }
    int add = mx-k;
    vector<P> edge;
    rep(i,n-1)rep(j,i) edge.push_back(P(i+1,j+1));
    rep(i,add) ans.push_back(edge[i]);
    cout << ans.size() << endl;
    rep(i,ans.size()) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}

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

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

void chmax(double &l, double r){if(l<r)l=r;}

int main(){

  int n; cin>> n;
  vector<double> r(n);
  rep(i, n) cin>> r[i];

  vector<double> x(n);
  rep(i, n){
    x[i]=r[i];
    rep(j, i){
      double a=r[j]+r[i], b=r[j]-r[i];
      chmax(x[i], x[j]+sqrt(a*a-b*b));
    }
  }

  double mx=0;
  rep(i, n) chmax(mx, x[i]+r[i]);
  printf("%.20f\n", mx);

  return 0;
}


Measured memory_bytes: 3296
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

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

typedef unsigned long long ull;
typedef std::pair<int,int> P;

int toMinute(int t){
    return t / 100 * 60 + t % 100;
}

int T[1500];

int main(){
    int N, S, E;
    while(std::cin >> N >> S >> E, N|S|E){
        S = toMinute(S);
        E = toMinute(E);

        REP(i, 1500){T[i] = 0;}

        REP(_, N){
            int K;
            std::cin >> K;
            
            REP(__, K){
                int s, e;
                std::cin >> s >> e;
                
                s = toMinute(s);
                e = toMinute(e);

                FOR(i, s, e){
                    T[i]++;
                }
            }
        }

        int res = 0, _res = 0;
        FOR(i, S, E){
            if(T[i] < N){
                _res++;
            }else{
                res = std::max(res, _res);
                _res = 0;
            }
        }

        res = std::max(res, _res);

        std::cout << res << std::endl;
    }
}

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

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

int main(){
	double x, k;
	cin >> x >> k;

	if((x + 1.0) / k >= 2)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}


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
int main(){
	ll n,count=0;
	string s;
	cin >> n >> s;
	ll r=0,g=0,b=0;
	for(int i=0;i<n;i++){
		if(s[i]=='R')r++;
		else if(s[i]=='G')g++;
		else if(s[i]=='B')b++;
	}
  count = r*g*b;
  for(int m=1;m<n-1;m++){
	for(int d=1;d<n;d++){
      	if(m-d<0||m+d>=n)continue;
    	if(s[m-d]!=s[m]&&s[m]!=s[m+d]&&s[m-d]!=s[m+d])count--;
    }
  }
	cout << count << endl;
}


Measured memory_bytes: 3636
sx,sy,tx,ty=map(int,input().split())
east=tx-sx
north=ty-sy
ans="R"*east+"U"*north
ans+="L"*east+"D"*north
ans+="D"+"R"*(east+1)+"U"*(north+1)+"L"
ans+="U"+"L"*(east+1)+"D"*(north+1)+"R"

print(ans)

Measured memory_bytes: 3060
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]

access = []
for i in 1..N do
  access[i-1] = []
end

for i in 1..N-1 do
  from = lines[i][0]
  to = lines[i][1]
  weight = lines[i][2]
  access[from-1].push([to,weight])
  access[to-1].push([from,weight])
end

visited = []
color = []
for i in 1..N do
  visited[i-1] = false
  color[i-1] = 0
end

target = [1]
visited[0] = true
color[0] = 1
while target != [] do
  i = target.pop
  access[i-1].each do |num|
    j = num[0]
    weight = num[1]
    if visited[j-1] == false then
      color[j-1] = (color[i-1] + weight) % 2
      target.push(j)
      visited[j-1] = true
    end
  end
end
  
puts color

Measured memory_bytes: 44696