akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int D = scan.nextInt();
        int T = scan.nextInt();
        int S = scan.nextInt();
        float t = (float)D / (float)S;

        System.out.println(
            t <= (float)T ? "Yes" : "No"
        );
    }
}

Measured memory_bytes: 35500
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
typedef pair<int,int> P;

int main() {
  int n,m;
  cin >> n;
  string t;
  set<string> s;
  rep(i,n) {
    cin >> t;
    s.insert(t);
  }
  cin >> m;
  bool c=true;
  rep(i,m) {
    cin >> t;
    if(s.count(t)) {
      if(c) pr("Opened by "+t);
      else pr("Closed by "+t);;
      c=!c;
    }
    else pr("Unknown "+t);
  }
  return 0;
}


Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    int dp_1[200000]; // i文字目が1文字目として分割されるときの分割数の最大値
    int dp_2[200000]; // i文字目がその前の文字と連結されるときの分割数の最大値
    if (s[0] == s[1]) {
        dp_1[0] = dp_1[1] = 1;
        dp_2[0] = 0, dp_2[1] = 1;
    } else {
        dp_1[0] = 1, dp_1[1] = 2;
        dp_2[0] = 0, dp_2[1] = 1;
    }
    for (int i = 2; i < n; i++) {
        if (s[i - 1] == s[i]) {
            dp_1[i] = dp_2[i - 1] + 1;
            dp_2[i] = dp_1[i - 2] + 1;
        } else {
            dp_1[i] = dp_1[i - 1] + 1;
            dp_2[i] = dp_1[i - 2] + 1;
        }
    }
    cout << max(dp_1[n - 1], dp_2[n - 1]) << endl;
    return 0;
}

Measured memory_bytes: 2196
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int k = scanner.nextInt();

        final int threshold = (n - 1) * (n - 2) / 2;

        if (k > threshold) {
            System.out.println(-1);
            return;
        }

        System.out.println(n - 1 + threshold - k);

        for (int i = 2; i <= n; i++) {
            System.out.println("1 " + i);
        }

        int counter = threshold - k;
        for (int i = 2; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                if (counter-- == 0) {
                    return;
                }
                System.out.println(i + " " + j);
            }
        }
    }
}


Measured memory_bytes: 25940
//OPTIMIZATONS
#pragma GCC optimize("02")
//CODE
#include<bits/stdc++.h>
#define int long long
#define float double
#define endl "\n"
#define debug cout<<"Good uptill here"<<endl<<flush;
#define deb(x) cout<<#x<<":"<<x<<endl<<flush;

using namespace std;
const int N = 1e5+1;
string inp[N];
vector<string> ans;
int n;
bool flag = false;

bool check(int& a,int& b,int& c){
	if(a<0 || b<0 || c<0) return false;
	return true;
}

void recursion(int a,int b,int c,int iter){
	if(flag) return;
	if(iter==n){
		if(check(a,b,c)){
			flag = true;
			cout<<"Yes"<<endl;
		}
		return;
	}
	if(!check(a,b,c)) return;
	if(inp[iter]=="AB" || inp[iter]=="BA"){
		recursion(a+1,b-1,c,iter+1);
		if(flag){
			ans.push_back("A");
			return;
		}
		recursion(a-1,b+1,c,iter+1);
		if(flag){
			ans.push_back("B");
			return;
		}
	}else if(inp[iter]=="BC" || inp[iter]=="CB"){
		recursion(a,b+1,c-1,iter+1);
		if(flag){
			ans.push_back("B");
			return;
		}
		recursion(a,b-1,c+1,iter+1);
		if(flag){
			ans.push_back("C");
			return;
		}
	}else{
		recursion(a-1,b,c+1,iter+1);
		if(flag){
			ans.push_back("C");
			return;
		}
		recursion(a+1,b,c-1,iter+1);
		if(flag){
			ans.push_back("A");
			return;
		}
	}
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	//CODE FOR SPECIFIED INPUT AND OUTPUT
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a,b,c;
	cin>>n>>a>>b>>c;
	for(int i=0;i<n;i++) cin>>inp[i];
	recursion(a,b,c,0);
	if(!flag) cout<<"No"<<endl;
	else{
		for(int i=ans.size()-1;i>=0;i--)
			cout<<ans[i]<<endl;
	}	
	return 0;
}


Measured memory_bytes: 21520
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define rep(i,j,k) for(int i=j;i<k;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int exp(int a,int b,int m){
    if(b==0) return 1LL;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
int fact[1000010];
int comb(int n,int k){
    return (fact[n] * exp(fact[n-k],M-2,M) % M) * exp(fact[k],M-2,M) % M;
}
main(){
    fastio;
    fact[0] = 1;
    for(int i=1;i<1000010;i++)
        fact[i] = fact[i-1] * i % M;
    
    int x,y;
    cin >> x >> y;
    //int k1 = x, k2 = y;
    int a = 0, b = 0;
    while(x>0 && y>0){
        if(x>y){
            a++;
            x-=2;
            y-=1;
        }
        else{
            b++;
            x-=1;
            y-=2;
        }
    }
    //cout << x << " " << y << " " << a << " " << b << endl;
    if(x==0 && y==0){
        int diff = abs(b-a);
        cout << comb(a+b,a) << endl;
    }
    else cout << 0 << endl;
    /*int dp[15][15];
    ms(dp,0);
    dp[0][0] = 1;
    for(int i=0;i<15;i++){
        for(int j=0;j<15;j++){
            if(i>=1 && j>=2){
                dp[i][j] += dp[i-1][j-2];
            }
            if(i>=2 && j>=1){
                dp[i][j] += dp[i-2][j-1];
            }
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    cout << dp[k1][k2] << endl;*/

}

Measured memory_bytes: 8064
#include <stdio.h>

int main(void) {
	int n;
	int edge[3];
	int i;
	int t;

	scanf("%d", &n);
	for(i = 0; i < n; i++) {
		scanf("%d", &edge[0]);
		scanf("%d", &edge[1]);
		scanf("%d", &edge[2]);

		if(edge[0] > edge[1]) {
			t = edge[0];
			edge[0] = edge[1];
			edge[1] = t;
		}
		if(edge[1] > edge[2]) {
			t = edge[2];
			edge[2] = edge[1];
			edge[1] = t;
		}

		if( (edge[0]*edge[0] + edge[1]*edge[1]) == edge[2]*edge[2] ) {
			printf("YES\n");
		} else {
			printf("NO\n");
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstring>
using namespace std;
int a[7][7],c[7][7];
int fn(int x,int y){
  int ct=0;
  if(a[y][x]>0&&c[y][x]){
    c[y][x]=0;
    ct=1;
    ct+=fn(x-1,y);
    ct+=fn(x+1,y);
    ct+=fn(x,y-1);
    ct+=fn(x,y+1);
  }
  return ct;
}
int main(){
  int i,j,k,l,m;
  int n;
  cin>>n;
  for(i=0;i<n;++i){
    int b[6]={};
    memset(a,-1,sizeof(a));
    for(j=1;j<=5;++j){
      for(k=1;k<=5;++k){
	cin>>a[j][k];
	if(a[j][k])
	  b[a[j][k]-1]++;
      }
    }
    for(j=0;j<6;++j){
      if(b[j]!=1)
	break;
    }
    if(j<6){
      cout<<"false"<<endl;
    }else{
      memset(c,-1,sizeof(c));
      for(j=1;j<=5;++j){
	for(k=1;k<=5;++k){
	  if(a[j][k])
	    break;
	}
	if(k<=5)
	  break;
      }
      if(fn(k,j)<6){
	cout<<"false"<<endl;
      }else{
	memset(c,-1,sizeof(c));
	for(j=1;j<=5;++j){
	  for(k=1;k<=5;++k){
	    if(a[j][k]&&c[j][k]){
	      int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
	      for(l=0;l<4;++l){
		for(m=0;;++m){
		  if(a[j+dy[l]+dx[l]*m][k+dx[l]+dy[l]*m]>0){
		    if(a[j+dy[l]*2+dx[l]*m][k+dx[l]*2+dy[l]*m]>0&&c[j+dy[l]*2+dx[l]*m][k+dx[l]*2+dy[l]*m]&&a[j][k]+a[j+dy[l]*2+dx[l]*m][k+dx[l]*2+dy[l]*m]==7){
		      c[j][k]=c[j+dy[l]*2+dx[l]*m][k+dx[l]*2+dy[l]*m]=0;
		      break;
		    }
		  }else{
		    break;
		  }
		}
		if(c[j][k]==0)
		  break;
		for(m=0;;++m){
		  if(a[j+dy[l]-dx[l]*m][k+dx[l]-dy[l]*m]>0){
		    if(a[j+dy[l]*2-dx[l]*m][k+dx[l]*2-dy[l]*m]>0&&c[j+dy[l]*2-dx[l]*m][k+dx[l]*2-dy[l]*m]&&a[j][k]+a[j+dy[l]*2-dx[l]*m][k+dx[l]*2-dy[l]*m]==7){
		      c[j][k]=c[j+dy[l]*2-dx[l]*m][k+dx[l]*2-dy[l]*m]=0;
		      break;
		    }
		  }else{
		    break;
		  }
		}
		if(c[j][k]==0)
		  break;
	      }
	      if(l==4)
		break;
	    }
	  }
	  if(k<=5)
	    break;
	}
	if(j>5)
	  cout<<"true"<<endl;
	else
	  cout<<"false"<<endl;
      }      
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
int main(void)
{
  std::string a, b;
  std::cin >> a >> b;
  
  int num = std::stoi(a + b);
  int i;
  for(i = 2; i < num; i++) {
    if((num % i == 0) && (num / i == i)) {
      std::cout << "Yes" << std::endl;
      break;
    }
  }
  if(!(i < num)) {
    std::cout << "No" << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
const ll MAX=100050;
const ll modn=1e9+7;
using namespace std;

void slove(){
    int n,d,a,b;
    cin>>n>>d;
    int ans=0;
    while(n--){
        cin>>a>>b;
        //cout<<hypot(a,b)<<endl;
        if(hypot(a,b)<=d)
            ans++;
    }
    cout<<ans<<endl;
}

int main() {
    int _;
    //scanf("%d",&_);
    _=1;
    while(_--) {
        slove();
    }
    return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmax(a, b) a = max(a, b)


using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;




int main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<vector<int>> v(n + 1);
    int now, cnt = 0;
    rep(i, s.size()){
        if(s[i] == 'A')now = 0;
        else if(s.substr(i, 2) == "BC"){now = 1;i++;}
        else {
            v[cnt].push_back(INF);
            cnt++;
            continue;
        }
        v[cnt].push_back(now);
    }
    v[cnt].push_back(INF);

    ll res = 0;
    rep(i, n){
        int lim = lower_bound(ALL(v[i]), INF) - v[i].begin() - 1;
        rep(j, v[i].size()){
            if(v[i][j] == INF)break;
            if(v[i][j] == 0){
                //if(lim < j)break;
                res += lim - j;
                lim--;
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 11396
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
const int INF = 1e+9;

int main() {
	int n;
	cin >> n;
	vector<vector<int>> dp(n + 10, vector<int>(3)), a(n, vector<int>(3));
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < 3; ++j)
			cin >> a[i][j];
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < 3; ++j) {
			dp[i][j] = max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) + a[i - 1][j];
		}
	}
	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
	return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define pb(v) push_back(v)
#define mp(x, y) make_pair(x, y)
#define fi first
#define se second
#define print(var)  do{ cout << #var << " : "; view(var); } while(0)
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using P = pair<int ,int>;
using Graph = vector<vector<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    while (true) {
        int h, w; cin >> h >> w;
        if (h+w==0) break;

        int hw = h*h + w*w;

        int cur = INF;
        int minh = INF;
        P ans = P(INF, INF);
        FOR(i, 1, 151) FOR(j, i+1, 151) {
            int tmp = i*i+j*j;

            // tmp が hwより大きいとき
            if (tmp>hw || (tmp==hw&&i>h)) {
                // tmp が curより小さい時
                if (tmp<cur || (tmp==cur&&i<minh)) {
                    cur = tmp;
                    minh = i;
                    ans = P(i, j);
                }
            }
        }

        cout << ans.fi << " " << ans.se << endl;
    }
}


Measured memory_bytes: 3228
def checkPrime(num) :
    flag = 0
    for i in range(2,num) :
        if num % i == 0 :
            flag = 1
            break
    if (flag) :
        return False
    else :
        return True
num = int(input())
i = num
while(True) :
    res = checkPrime(i)
    if (res) :
        print(i)
        break
    else :
        pass
    i += 1


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define mp make_pair
#define pii pair<int,int>
typedef long long ll;

using namespace std;
const int maxn=2e5+100;
int main(){
	string s,t;
	cin>>s;
	cin>>t;
	int ls=s.size(),lt=t.size(),ans=1010;
	rep(i,0,ls-1){
		if(i+lt-1>=ls)continue;
		int j=0,cnt=0;
		while(j<lt&&i+j<ls){
			if(t[j]==s[i+j])++cnt;
			++j;
		}
		ans=min(ans,lt-cnt);
	}
	cout<<ans;
    
 
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
//#include <boost/functional/hash.hpp>
//example: unordered_set< pair<int,int>,boost::hash< std::pair<int, int> > > used;
//priority_queue< pair<int,pair<int,int> >, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int> > > > pqueue;    //cost, vertex(行き先)
using namespace std;

#define MODULE 1000000007
#define MP make_pair
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

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

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

typedef pair<int, int> P;
typedef long long LL;
const LL INF = LLONG_MAX / 2;    //int_max->2*e+9 LLの時はLLONG_MAX
const int MAXN = 100001;

template<typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val){ //usage: int dp[10][10]; Fill(dp,INF);
    std::fill( (T*)array, (T*)(array+N), val );
}
/*struct edge {
    edge(int to, int cost) : to(to), cost(cost) {}
    int to, cost;
};
vector<edge> graph[MAXN];

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

//-----Template---------
int h, w;
char color[301][301];   //vector<string>でもいい
LL dp[301][301];
LL cost[301][301];
LL ans[301];
LL sum = 0;
string tmpS;

int main() {
    ios::sync_with_stdio(false); //cout<< fixed << setprecision(10);
    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        cin >> tmpS;
        for (int j = 0; j < w; ++j) {
            color[i][j] = tmpS[j];
        }
    }


    for (int i = 0; i < w - 1; ++i) {     //2列毎の最小コストを求める
        for (int j = 0; j <= h; ++j) {   //先にcostテーブルを作っておく．
            // 毎回計算するとdp更新にO(h)かかってTLE
            //cost[i][j]:i,j押されているときに
            //どちらかの列を押すコスト(2列の内どちらを押しても同じコスト)
            for (int k = 0; k <= h; ++k) {
                if (j == 0 || k == 0) {
                    LL tmp = 0;
                    for (int l = 0; l < h; ++l) {//0 .. h-1まで回して，変なとこを飛ばす
                        if (l - j >= 0 && l - k >= 0 && color[l - j][i] == color[l - k][i + 1])
                            tmp++;
                    }
                    cost[j][k] = tmp;
                } else {
                    cost[j][k] = cost[j - 1][k - 1] - (color[h - j][i] == color[h - k][i + 1] ? 1 : 0);
                }
            }
        }
        Fill(dp,INF);
        dp[0][0] = 0;
        for (int j = 0; j <= h; ++j) {
            for (int k = 0; k <= h; ++k) {
                LL tmpA = j > 0 ? dp[j - 1][k] + cost[j - 1][k] : INF;
                LL tmpB = k > 0 ? dp[j][k - 1] + cost[j][k - 1] : INF;
                chmin(dp[j][k], min(tmpA, tmpB));
            }
        }
        sum += dp[h][h];
    }
    cout << sum << endl;
}

Measured memory_bytes: 1920
<?php
// Your code here!
$s = trim(fgets(STDIN));
$n = (int)trim(fgets(STDIN));
$ans = [];

for($i=0; $i<$n; $i++){
    $meirei = explode(" ", trim(fgets(STDIN)));
    if($meirei[0] == 'replace'){
        $s = substr_replace($s, $meirei[3], $meirei[1], $meirei[2]-$meirei[1]+1);
    }elseif($meirei[0] == 'reverse'){
        $sub = substr($s, $meirei[1], $meirei[2]-$meirei[1]+1);
        // var_dump($sub);
        $sub = strrev($sub);
        $s = substr_replace($s, $sub, $meirei[1], $meirei[2]-$meirei[1]+1);
    }elseif($meirei[0] == 'print'){
        $ans[] = substr($s, $meirei[1], $meirei[2]-$meirei[1]+1);
    }
    
}
// var_dump($s);
echo implode(PHP_EOL, $ans);
echo PHP_EOL;


Measured memory_bytes: 9320
n = int(input())
words = []
before= input()
words.append(before)
flag = True
for _ in range(n-1):
  
  s = input()
  if before[-1] != s[0]:
    flag = False
  before = s
  words.append(s)

l = len(set(words))
if l != n:
  flag = False
if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define mod 998244353

string s;

map<string, int> dp;

void add(int& a, int b) {
    a += b;
    if (a >= mod) a -= mod;
}

int solve(string s) {
    int i, j, k, sz, n;
    vector<int> aux = vector<int>(s.size() + 2, 0);
    string saux;

    auto &act = dp[s];
    if (act != 0) return act - 1;

    n = s.size();
    aux[0] = 1;

    for (i = 1; i <= n; i++) {
        add(aux[i], aux[i - 1]);
        if (s[i - 1] == '1') add(aux[i], aux[i - 1]);

        for (sz = 1; 2 * sz <= i; sz++) {
            saux.clear();

            for (j = 0; j < sz; j++) saux.pb(s[i - j - 1]);
            for (k = 2; k * sz <= i; k++) {
                for (j = 0; j < sz; j++)
                    saux[j] = min(saux[j], s[i - j - 1 - (k - 1) * sz]);

                add(aux[i], (1LL * aux[i - k * sz] * solve(saux)) % mod );
            }
        }
    }

    act = aux[n] + 1;
    return aux[n];
}

int main()
{
    //freopen("test.in","r",stdin);

    cin >> s;
    cout << solve(s);



    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main()
{
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int ans = 0;
    for (int i = 0; i <= n / r; ++i)
    {
        for (int j = 0; j <= n / g; ++j)
        {
            int num = n - r * i - g * j;
            if (num >= 0 && num % b == 0)
            {
                ++ans;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  int i = N;
  while (0 < i) {
    if (floor(i * 1.08) == N) {
      cout << i << endl;
      return 0;
    }
    --i;
  }
  cout << ":(" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		char design[] = {'S', 'H', 'C', 'D'};
		HashMap<Character, boolean[]> trump = new HashMap<Character, boolean[]>();

		for (char d : design)
			trump.put(d, new boolean[13]);

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int i = 0; i < n; i++){
			char d = scan.next().charAt(0);
			int r = scan.nextInt();

			trump.get(d)[r-1] = true;
		}

		for (char d : design){
			boolean t[] = trump.get(d);
			for (int i = 0; i < t.length; i++)
				if(!t[i])
					System.out.println(String.format("%c %d", d, i+1));
		}
	}
}



Measured memory_bytes: 26340
#include <iostream>
#include <string>
using namespace std;
int main(){
  string str;
  string res = "";
  cin >> str;

  string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

  for (int i = 0; i <(int)str.size(); ++i) {
    char s  = str[i];
    for (int j = 0; j < (int)alphabet.size();j++) {
      if (s == alphabet[j]) {
        int size = (int)alphabet.size();
        res += alphabet[(size + j -3) % size];
      }
    }
  }
  cout << res << endl;
}

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

int main() {
   int n;
   cin >> n;
   int ans = 0;
   rep(i,n){
		int l,r; 
    cin >> l >> r;
    ans += r - l + 1;
	}
	 cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MN 100000
#define ll long long
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
ll m;
pair<int,int> a[MN+5];
int n,Q,s[MN+5],num,ans;
inline int getfa(int x){return s[x]?s[x]=getfa(s[x]):x;}
inline void Merge(int x,int y){if(getfa(x)!=getfa(y)) s[getfa(x)]=getfa(y);}
int main()
{
    n=read();cin>>m;Q=read();
    for(int i=1;i<=Q;++i)
    {
        int x=read()+1,y=read()+1,op=read();
        if(op==0) Merge(x,y);
        else a[++num]=make_pair(x,y);
    }
    for(int i=1;i<=num;++i) 
        if(getfa(a[i].first)==getfa(a[i].second)) return 0*puts("No");
    if(m==n-1) return 0*puts(num?"No":"Yes");
    for(int i=1;i<=n;++i) if(getfa(i)==i) ++ans;
    if(ans==2)
    {
        if(num) return 0*puts("No");
        else if(m>n-1) return 0*puts("No");
        else return 0*puts("Yes");
    }
    long long max=1LL*ans*(ans-1)/2;
    if(n-ans+max<m) return 0*puts("No");
    puts("Yes");
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

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

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	int x, a, b; cin >> x >> a >> b;
	x -= a;
	while (x >= 0)x -= b;
	cout << x + b << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

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

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> acc(n);
    acc[0] = 0;
    FOR(i,1,n){
        if(s[i-1]=='A'&&s[i]=='C'){
            acc[i] = acc[i - 1] + 1;
        }else{
            acc[i] = acc[i - 1];
        }
    }
    int a, b;
    REP(i,q){
        cin >> a >> b;
        cout << acc[b - 1] - acc[a - 1] << endl;
    }

    return 0;
}


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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int) 1e6 + 7;
int n, sumtop;

struct T {
  int top;
  int mn;
};

bool operator < (T a, T b) {
  return min(a.mn, a.top + b.mn) > min(b.mn, b.top + a.mn);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<T> a, b;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    int top = 0, mn = 0;
    for (auto &ch : s) {
      if (ch == '(') {
        top++;
      } else {
        top--;
      }
      mn = min(mn, top);
    }
    if (top >= 0) {
      a.push_back({top, mn});
    } else {
      b.push_back({top, mn});
    }
    sumtop += top;
  }
  if (sumtop != 0) {
    cout << "No\n";
    return 0;
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int cur = 0;
  for (auto &it : a) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.top;
  }
  for (auto &it : b) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.top;
  }
  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 11228
import itertools
import math

def kaijo(n):
    if n == 1:
        return 1
    return kaijo(n-1) * n

N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]
seq = [i for i in range(N)]

#階乗
ptrs = list(itertools.permutations(seq)) #組み合わせ列挙 5!

ans = 0
for ptr in ptrs:
    for i in range(N-1):
        ans += math.sqrt((L[ptr[i+1]][0] - L[ptr[i]][0]) ** 2 + (L[ptr[i+1]][1] - L[ptr[i]][1]) ** 2)

print(ans/kaijo(N))


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

int solve(int n){
    int i = 0;
    if((n % 10) == ((n/10) % 10)){
        if((n % 10) == ((n/100) % 10)){
            return 1;
        }
    }
    return 0;
}

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

    for(int i = N; i <= 999; i++){
        if(solve(i)){
            cout << i << endl;
            break;
        }
    }

    return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[10001],d,f,g,h,j,i,k;
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		d=0;
		f=0;
		for(i=0;i<a;i++){
			scanf("%d",&s[i]);
			if(s[i]>=2) d++;
			if(s[i]>=1) f++;
		}
		if(d<1)	printf("NA\n");
		else
			printf("%d\n",f+1);
	}
	return 0;
}

Measured memory_bytes: 2772
modulo = 1000000007

import sys
sys.setrecursionlimit(100000009)


muchii = []


def recursie(x, y):
    alb = 1
    negru = 1
    for elem in muchii[x]:
        if elem == y:
            continue
        result_1, result_2 = recursie(elem, x)
        alb = (alb * (result_1 + result_2)) % modulo
        negru = (negru * result_1) % modulo
    return alb, negru
    

if __name__ == "__main__":
    input = sys.stdin.readline
    n = int(input())
    for i in range(n):
        muchii.append([])
        
    for i in range(n-1):
        numbers = list(map(int, input().split(" ")))
        
        x = numbers[0]
        y = numbers[1]
        
        muchii[x-1].append(y-1)
        muchii[y-1].append(x-1)
        
    result_1, result_2 = recursie(0, None)
    
    result = (result_1 + result_2) % modulo
    
    print(result)


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

const int N = 256;

int main() {
    string a, b; cin >> a >> b;
    int n = a.size();
    set<int> A[N], B[N];
    for(int i = 0; i < n; ++i) A[a[i]].emplace(b[i]), B[b[i]].emplace(a[i]);
    for(int i = 0; i < 256; ++i) if(A[i].size() > 1 || B[i].size() > 1) return !printf("No");
    puts("Yes");
}

Measured memory_bytes: 776
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>

using namespace std;



int func(long long a, long long b) {
	return max(log10(a), log10(b)) + 1;
}

int main(void) {
	long long N, NN;
	cin >> N;

	NN = N;

	map<long long, long long> pf;

	if (N <= 10) {
		cout << 1 << endl;
		return 0;
	}

	for (long long i = 2; i <= NN && i <= sqrt(N); i++) {
		while (NN % i == 0) {
			pf[i]++;
			NN /= i;
		}
	}

	if (NN != 1) pf[NN]++;

	vector<long long> factor;

	factor.push_back(1);
	
	for (auto itr = pf.begin(); itr != pf.end(); itr++) {
		long long n = factor.size();
		for (long long i = 0; i < n; i++) {
			for (long long j = 1; j <= itr->second; j++)
				factor.push_back(factor[i] * pow(itr->first, j));
		}
	}

	long long ans = 11;

	for (auto itr = factor.begin(); itr != factor.end(); itr++) {
		if (ans > func(*itr, N / (*itr))) ans = func(*itr, N / (*itr));
	}

	cout << ans << endl;

	system("pause");
	return 0;
}

Measured memory_bytes: 504
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007


signed main(){
    int r,g,b,n;
    cin>>r>>g>>b>>n;

    int ans=0;
    for(int i=0;i<=3000;i++){
        for(int j=0;j<=3000;j++){
            int c=n-i*r-j*g;
            if(c>=0&&c%b==0) ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3564
a,b = [int(i) for i in input().split()]

l1 = [1,3,5,7,8,10,12]
l2 = [4,6,9,11]
l3 = 2

if 2 in (a,b):
  print('No')
elif a in l1 and b in l2:
  print('No')
elif a in l2 and b in l1:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

template <typename T>
class BIT{
public:
    vector<T> data;
    int n;
    BIT(int n_){
        n = n_;
        data.assign(n, T(0));
    }

    void add(int a, int w){
        for (int x = a; x < n; x |= x + 1) data[x] += w;
    }

    T sum(int a){
        int ret = 0;
        for (int x = a - 1; x >= 0; x = (x & (x + 1)) - 1) {
            ret += data[x];
        }
        return ret;
    }
};

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

    vector<ll> b(N+1);
    b[0] = 0;
    for(int i=0;i<N;i++){
        ll a;
        cin >> a;
        b[i+1] = b[i] + a - K;
    }

    vector<ll> b_s = b;
    sort(b_s.begin(), b_s.end());

    int idx = 0;
    map<ll, int> mp;
    for(int i=0;i<=N;i++){
        if(mp.find(b_s[i]) == mp.end()){
            mp[b_s[i]] = idx++;
        }
    }

    BIT<int> bit(N+1);
    ll ans = 0;
    for(int i=0;i<=N;i++){
        int c = mp[b[i]];
        ans += bit.sum(c+1);
        bit.add(c, 1);
    }
    cout << ans << endl;

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define rlo(i,n) for(int i=n-1;i>=0;i--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define pr(a) {for(auto x:a)cout<<x<<" ";cout<<nl;}

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

void f()
{
  int n,i;
  cin>>n>>i;
  cout<<n-i+1<<nl;
}

int main()
{
    su;
    f();
    return 0;
}


Measured memory_bytes: 3600
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include <random>
#define ll long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll x,y;
    cin>>x>>y;
    ll a=lcm(x,y);
    if(x%y==0){
        cout<<-1<<endl;
        return 0;
    }
    for(ll i=x;i<a;i+=x){
        if(i%y!=0){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let n: usize = read_line().trim().parse().unwrap();
    let a: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let ans = a.iter().fold(0, |sum, val| sum + val -1);
    println!("{}", ans);
}


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

#define LL long long
vector<int> v;
bool mark[100009];
int amount[100009];

void bfs(int n){
	queue<pair<int,int> > q;
	q.push(make_pair(n,0));

	while(!q.empty()){
		pair<int,int> p = q.front();q.pop();
		if(mark[p.first]){continue;}
		mark[p.first] = true;
		if(p.first == 0){cout<<p.second<<endl;return ;}
		amount[p.first] = p.second;

		for(int i=0;i<(int)v.size();i++){
			if((p.first - v[i])>=0 && !mark[p.first - v[i]]){
				q.push(make_pair(p.first-v[i],p.second+1));
			}
		}
	}
}

int main(){
	

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

	int n;
	cin>>n;

	v.push_back(1);
	for(int i=6;i<=n;i*=6){
		v.push_back(i);
	}
	for(int i=9;i<=n;i*=9){
		v.push_back(i);
	}

	bfs(n);
}

Measured memory_bytes: 2048
n = int(input())
ans = n

def calc(n, num):
    ret = 0
    while n > 0:
        ret += n % num
        n //= num
    return ret

for i in range(n + 1):
    cc = 0
    cc += calc(i, 6)
    cc += calc(n - i, 9)
    ans = min(ans, cc)

print(ans)



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

#include        <stdio.h>
#include        <stdlib.h>
#include        <string.h>

#define M 5000002
#define L 14
#define M5G12 244140625
#define KEYUP 11

char H[M][L]; /* Hash Table */

int getChar(char ch){
	if ( ch == 'A') return 1;
	else if ( ch == 'C') return 2;
	else if ( ch == 'G') return 3;
	else if ( ch == 'T') return 4;
	return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]){
	long long sum = 0, p = 1, i;
	for ( i = 0; i < strlen(str); i++ ){
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key){ return 0; /* your task */; }


int h2(int key){ return 0; /* your task */; }

int k1(long long sum) {
	long long kitei = M;
	int key;
	key = sum % kitei;
	return (key);
}

int k2(long long sum) { return 0; }

int find(char str[]){
	long long sum;
	int key;
	sum = getKey(str);
	key = k1(sum);
	if (H[key][0] == '\0') {
		return false;
	} else {
		if (strcmp(H[key], str) == 0) return true;
		sum = sum + KEYUP;
		while ((H[key = k1(sum)][0]) != '\0') {
			if (strcmp(H[key], str) == 0) {
				return true;
			}
			sum = sum + KEYUP;
		}
	}
	return false;
}

int insert(char str[]){
	long long sum;
	long long key;
	sum = getKey(str);
	key = k1(sum);
	if (H[key][0] == '\0') {
		strcpy(H[key], str);
	} else {
		do {
			if (strcmp(H[key], str) == 0) return true;
			sum = sum + KEYUP;
			key = k1(sum);
		} while ((H[key][0]) != '\0');
		strcpy(H[key], str);
	}

	return 0;
}

int main(){
	int i, n, h;
	char str[L], com[9];
	for ( i = 0; i < M; i++ ) H[i][0] = '\0';

	scanf("%d", &n);

	for ( i = 0; i < n; i++ ){
		scanf("%s %s", com, str);

		if ( com[0] == 'i' ){
			insert(str);
		} else {
			if (find(str)){
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}
	return 0;
}





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

using namespace std;

int main(){
  string s;
 cin >> s;
  int res=0;
  if(s[0]=='o') res++;
  if(s[1]=='o') res++;
  if(s[2]=='o') res++;

 cout << 700+res*100 << endl;
}

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

int main() {
	// your code goes here
string s;
cin>>s;

int ans=s.length();
for(int i=0;i<s.length()-1;i++)
{
	if(s[i]!=s[i+1])
	ans=min(ans,max(i+1,(int)s.length()-i-1));
}
;
cout<<ans<<endl;
}

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

int main() {
  //cin.tie(nullptr);
  //ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n, k;
  cin >> n >> k;
  vector<ll> minus;
  vector<ll> plus;
  rep(i, n) {
    ll temp;
    cin >> temp;
    if (temp < 0) minus.push_back(-temp); 
    else plus.push_back(temp);
  }
  reverse(minus.begin(), minus.end());
  ll ans = 1e16 + 10;
  rep(i, k+1) {
    int num_minus = i;
    int num_plus = k - i;
    if (minus.size() < num_minus || plus.size() < num_plus) continue;
    if (num_minus == 0) {
      ans = min(ans, plus[num_plus - 1]); 
    } else if (num_plus == 0) {
      ans = min(ans, minus[num_minus - 1]); 
    } else {
      ll temp = min(minus[num_minus - 1] * 2 + plus[num_plus - 1],
                    plus[num_plus - 1] * 2 + minus[num_minus -1]);
      ans = min(ans, temp);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int A = ni();
        int B = ni();
        int C = ni();
        if(A < C && C < B){
            out.println("Yes");
        }else if(B<C && C<A){
            out.println("Yes");
        }else{
            out.println("No");
        }
 
    }

    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);
    int upperBound(ArrayList<Long> list, Long target){
        int i = Collections.binarySearch(list, target, new UpperBoundComparator<Long>());
        return ~i;
    }
    class UpperBoundComparator<T extends Comparable<? super T>> implements Comparator<T>{
        public int compare(T x, T y){
            return (x.compareTo(y) > 0) ? 1 : -1;
        }
    }
    int lowerBound(ArrayList<Long> list, Long target){
        int i = Collections.binarySearch(list, target, new LowerBoundComparator<Long>());
        return ~i;
    }
    class LowerBoundComparator<T extends Comparable<? super T>> implements Comparator<T>{
        public int compare(T x, T y){
            return (x.compareTo(y) >= 0) ? 1 : -1;
        }
    }
    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

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

int input(vector <int> &a){
    int l, i=0;
    while(cin>>l){
        a.push_back(l);
        i++;
    }
  return 0;
}

int main(void){
  vector <int> x;
  input(x);
  int N = x[0];
  int A = x[1];
  int B = x[2];

  if(N*A > B){
    cout << B;
  }
  else{
    cout << N*A;
  } 
}

Measured memory_bytes: 256
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table


def main():
    n = int(input())
    ans = 0
    for i in range(1, n+1):
        if i % 2 != 0 and len(divisor(i)) == 8:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

int main() {
	int num;
	int count = 0;
	
	/*** loop ***/
	while (count < 10000) {
		/** scan **/
		scanf("%d", &num);
		
		/** judge **/
		if (!(num >= 1 & num <= 10000)) {
			if (num == 0) break;
			printf("error\n");
			exit(1);
		}
		
		/** print **/
		printf("Case %d: %d\n", count + 1, num);
		count++;
	}
	
	return 0;
	
}


Measured memory_bytes: 2032
#include "bits/stdc++.h"
using namespace std;
#define all(a)  (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
	int n,q;
	cin>>n>>q;
	vector<int> v(n);
	rep(i,n)cin>>v[i];
	sort(all(v));
	int vm = v[v.size()-1];
	
	rep(i,q){
		int a;
		scanf("%d",&a);
		
		int ans = 0;
		int c=1;
		while((c-1)*a<=vm){
			int p = lower_bound(all(v),c*a)-v.begin();
			c++;
			if(p==0)continue;
			ans = max(ans,v[p-1]%a);
		}
		cout<<ans<<endl;
	}
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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 GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

const int maxk=20000;
bool dp[100][100][maxk+1]; // dp[i][j][k]:=(i,j)の偏りをkにできるか
int h,w;
int a[100][100];
int b[100][100];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  cin>>h>>w;
  rep(i,h) rep(j,w) cin>>a[i][j];
  rep(i,h) rep(j,w) cin>>b[i][j];
  
  dp[0][0][0]=true;
  
  rep(i,h) rep(j,w){
    
    int d = abs(a[i][j]-b[i][j]);
    
    ireps(ki,0,maxk){
      if(dp[i][j][ki]){
        int e=abs(ki-d);
        dp[i+1][j][e]=true;
        dp[i][j+1][e]=true;
        dp[i+1][j][ki+d]=true;
        dp[i][j+1][ki+d]=true;
      }
    }
  }
  
  int ans=INF;
  for(int i=0; i<=maxk; i++){
    if(dp[h][w-1][i]){
      ans=i;
      break;
    }
    if(dp[h-1][w][i]){
      ans=i;
      break;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 158720
N = int(input())
b = list(map(int, input().split()))

ans = []

for i in range(0, N):
    for j in range(len(b)-1, -1, -1):
        if b[j] == j + 1:
            b.pop(j)
            ans.append(j + 1)
            break
ans = ans[::-1]

if len(b) != 0:
    print(-1)
else:
    for i in range(N):
        print(ans[i])


Measured memory_bytes: 3060
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
      	int x = sc.nextInt();
        int n = sc.nextInt();
      	int ps[] = new int[n];
      	int ans;
      	int istack;
      
      	for(int i = 0;i < n;i++){
          istack = sc.nextInt();
          if(istack < x) ps[i] = Math.abs(x-istack)*2;
          else ps[i] = Math.abs(x-istack)*2+1;
        }
      
      	Arrays.sort(ps);
      	ans = 1;
      	for(int i = 0;i < n;i++){
          if(ps[i] == ans) ans++;
          else break;
    	}
      	if(ans%2 == 0) x -= ans/2;
      	else x += ans/2;
            
      	System.out.println(x);
      
	}
}

Measured memory_bytes: 36108