akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

const ll MAX = 1000000; //テーブルの数
const ll MOD = 1e9+7; //mod宣言

long long fac[MAX], finv[MAX], inv[MAX];
// finv ->階乗割り算
// fac ->階乗掛け算

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long POM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return (fac[n] * ( finv[n - k] % MOD)) % MOD;
}


vector<vector<int> > tree;

int main(){
    COMinit();
    int n, k; cin >> n >> k;
    tree = vector<vector<int> >(n);
    REP(i, 0, n-1){
        int a, b; cin >> a >> b;
        a--; b--;
        tree[a].pb(b);
        tree[b].pb(a);
    }
    ll ans = 1;
    vector<int> flag(n, 0);
    flag[0] = 1;
    queue<int> que;
    int count = 0;
    REP(i, 0, tree[0].size()){
        que.push(tree[0][i]);
        flag[tree[0][i]] = 1;
    }
    ans *= POM(k, tree[0].size()+1);
    //cout << ans << endl;
    while(!que.empty()){
        int now = que.front();
        //cout << now << endl;
        que.pop();
        int count = 0;
        REP(i, 0, tree[now].size()){
            if(flag[tree[now][i]] == 0){
                count++;
                flag[tree[now][i]] = 1;
                que.push(tree[now][i]);
            }
        }
        ans *= POM(k-2, count);
        ans %= MOD;
    }
    cout << ans << endl;
}

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

#define int    long long

void fast()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
//a^n O(log(n))

int power(int a, int n)
{
	int result = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			result = result * a;
		}
		a = a * a;
		n = n >> 1;

	}
	return result;
}


bool compare(string &s1, string &s2)
{
	return s1.size() < s2.size();
}

int32_t main()
{
	fast();
	int n;
	cin >> n;

	int change = 0;

	for (int i = 1000; i <= 10000; i += 1000)
	{
		if (i < n)
			continue;
		else
		{
			change = i - n;
			break;
		}
	}
	cout << change << '\n';
	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;
int main() {
    int n;
    cin >> n;
    int ans = 1;
    vector<int> num;
    while(true){
        auto result = find(num.begin(), num.end(), n);
        if(result != num.end()) {
            cout << ans << endl;
            return 0;
        }
        num.push_back(n);
        if(n % 2 == 0) n = n / 2;
        else n = 3 * n + 1;
        ans += 1;
    }

}

Measured memory_bytes: 256
n = int(input())
inputs = [list(map(int,input().split())) for i in range(n-1)]
out = []
for station_st in range(n-1):
    spend_time = inputs[station_st][1]+inputs[station_st][0] #次の駅に着く時間

    for st_num_cur in range(station_st+1,n-1):
        if spend_time < inputs[st_num_cur][1]:
            spend_time = inputs[st_num_cur][1]

        train_leave_time = inputs[st_num_cur][1] 
        train_i = 0
        wait_time = 0
        if (spend_time%inputs[st_num_cur][2])!=0:
            wait_time = inputs[st_num_cur][2] - (spend_time%inputs[st_num_cur][2])
        spend_time += wait_time + inputs[st_num_cur][0] #次の駅で乗れる電車が出発する時間
        #print("spend",wait_time,spend_time)
    print(spend_time)
print(0)

Measured memory_bytes: 42476
import Data.List
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as B
main=do
    (n:m:_)<-map read.words<$>getLine::IO[Int]
    --
    xm<-foldl (\m a->M.insertWith(+)a 1 m) M.empty.map (flip mod m).tail.scanl' (+) 0.unfoldr (B.readInt.B.dropWhile(==' ')) <$> B.getLine
    --
    print $ (n0 xm) + (sum.map (\a->(a*a-a)`div`2).M.elems $ xm)
--
n0 m = case M.lookup 0 m of
    Nothing -> 0
    Just n  -> n

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

int main()
{
    int n, tmp;
    vector <int> p, q, p_raw, q_raw;
    cin >> n;
    
    for(int i=1; i<n+1; i++){
        p_raw.push_back(i);
        q_raw.push_back(i);
    }
    
    for(int i=0; i<n; i++){
        cin >> tmp;
        p.push_back(tmp);
    }
    for(int i=0; i<n; i++){
        cin >> tmp;
        q.push_back(tmp);
    }
    
    int p_num=0, q_num=0, fact=1;
    for(int i=n; i>0; i--){
        for(int j=1; j<=i-1; j++){
            fact = fact * j;
        };
//        cout << "fact: " << fact << endl;
        
        p_num += fact * (p_raw[p[n-i]-1] - 1);
        q_num += fact * (q_raw[q[n-i]-1] - 1);

//        cout << p_num << ", " << q_num << endl;
        
        for(int j=p[n-i]; j<n; j++){
            p_raw[j] -= 1;
        }
        for(int j=q[n-i]; j<n; j++){
            q_raw[j] -= 1;
        }
        
//        cout << "p_raw: " ;
//        for(int j=0; j<n; j++){ cout << p_raw[j] << ", ";}
//        cout << endl << "q_raw: " ;
//        for(int j=0; j<n; j++){ cout << q_raw[j] << ", ";}
//        cout << endl;
        
        fact = 1;
    }
    
//    cout << p_num << ", " << q_num << endl;
    cout << abs(p_num - q_num) << endl;
    
    return 0;
}


Measured memory_bytes: 256
/* -> Written by <-
   -----------
  |K_A_Z_A_M_A|
  |___________|
  |    ___    |
  |   (^_^)   |
  |  /( | )\  |
  |____|_|____|
    H O A N G
*/

// i hope i get better

// Task name:
#define Task ""
using namespace std;

// Include
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <string>
#include <sstream>
#include <cstdio>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>

// Define
#define reset(x, value) memset((x), (value) ,sizeof((x)))
#define fr(i,a,b) for(int i = (a); i <= (b); i++)
#define FR(i,a,b) for(int i = (a); i < (b); i++)
#define frr(i,a,b) for(int i = (a); i >= (b); i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define nl "\n"
#define bit(x,i) (x >> i) & 1
#define all(x) (x).begin(), (x).end()
#define optimize(x) (x).resize(unique(all(x)) - (x).begin())
#define Inpf freopen(Task".inp","r",stdin)
#define Outf freopen(Task".out","w",stdout)
#define fasterIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

// typedef
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vii;
typedef vector<ll> vll;

const int base = 131;
const int MOD = 1e9 + 7;
const ll MM = 1ll * MOD * MOD;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

void AddMOD(int &x, int y)
{
    x += y;
    if (x >= MOD)
        x -= MOD;
}
int Gcd(int x, int y)
{
    if (y == 0)
        return x;
    return Gcd(y, x % y);
}
template <class T> inline void Gmax(T &x,T y)
{
    x = max((x), (y));
}
template <class T> inline void Gmin(T &x,T y)
{
    x = min((x), (y));
}

void exit_with_runtime()
{
    db x = 1.0 * clock() / CLOCKS_PER_SEC;
	cerr << "\n\n---------------------\nTime elapsed: " << x << " s.\n\n";
	if (x > 1) cerr << "TIME LIMIT EXCEEDED!\n\n";
	exit(0);
}

// --------------------------------------------------------------------
const int maxn = 2e5 + 5;
// --------------------------------------------------------------------
void Solve()
{
    ll a, b, n;
    cin >> a >> b >> n;
    ll x = min(b - 1, n);
    cout << a * x / b - a * (x / b);
}

int main()
{
#ifndef ONLINE_JUDGE
    Inpf;
    Outf;
#endif // ONLINE_JUDGE
    fasterIO;
    int test = 1;
//    cin >> test;
    while (test --)
        Solve();

    // Did you check with the special test case n = 0, n = 1??
    exit_with_runtime();
}

// Goodbye, see u again


Measured memory_bytes: 3796
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;

//ll num[50];
//ll num2[50];
ll num[ten52];
//stack<char> stk;
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<char> deq;
//vector<ll> vll;


int main(void)
{
    //double ans=0.0,d,d1,d2;
    //float f,g,h;
    long long int m,n,i,j,k=1;
    long long int a,a1,a2,a3,sum;
    //string s,s1,s2;
    //char c,c1;
    sum=a=a1=a2=a3=0;
    cin>>n;a=100;
    while(a<n)
    {
        a*=1.01;
        a1++;
    }
    cout<<a1;
    return 0;
}





Measured memory_bytes: 3596
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<n; ++i)
const int inf = 100100100;
const long long INF = 1LL<<60;
const int MOD = (int)1e9 + 7;
typedef long long ll;

//aとbのうち小さい値をaとして採用する
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false;}

int main(){
    int n,k;cin>>n>>k;
    vector<ll> h(110000);rep(i,n)cin>>h[i];
    vector<ll> costs(110000,INF);

    costs[0] = 0;
    rep(i,n){
        for(int j = 1; j<=k; ++j){
            chmin(costs[i+j], costs[i]+abs(h[i+j]-h[i]));
        }
    }
    cout<<costs[n-1]<<endl;return 0;
}


Measured memory_bytes: 1920
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};
const ll MAX=114514;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    ll n,k;cin>>n>>k;
    vl a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    COMinit();
    ll ans=0;
    if(k==1){
      cout<<0<<endl;
      return 0;
    }
    rep(i,n-k+1){
        ans-=a[i]*COM(n-1-i,k-1);
        ans%=MOD;
    }
    ans=(ans+MOD)%MOD;
    reverse(a.begin(),a.end());
    rep(i,n-k+1){
        ans+=a[i]*COM(n-1-i,k-1);
        ans%=MOD;
    }
    cout<<(ans+MOD)%MOD<<endl;
}



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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }

    vector<long long> x(n);
    x[0] = sum;
    for (int i = 1; i < n - 1; i += 2) {
        x[0] -= 2 * a[i];
    }

    cout << x[0] << " ";
    for (int i = 0; i < n - 1; i++) {
        x[i + 1] = 2 * a[i] - x[i];
        cout << x[i + 1] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2432
import java.util.ArrayList;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	static boolean EQ(double x, double y) {
		return Math.abs(x - y) < 1.0e-9;
	}
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			double[] xs = new double[n], ys = new double[n];
			for(int i = 0; i < n; i++) {
				xs[i] = sc.nextInt();
				ys[i] = sc.nextInt();
			}
			if(n % 2 == 0) {
				int c = n/2;
				double x0 = (xs[0] + xs[c])/2;
				double y0 = (ys[0] + ys[c])/2;
				for(int i = 1; i < c; i++) {
					double x = (xs[i] + xs[c+i])/2;
					double y = (ys[i] + ys[c+i])/2;
					if(!EQ(x0, x) || !EQ(y0 , y)) {
						System.out.println("NA");
						return;
					}
				}
				System.out.printf("%.6f %.6f", x0, y0);
			}
			else {
				System.out.println("NA");
			}
		}
	}
}



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

using namespace std;

typedef long long ll;

const int mx = (int) 1e3 * 100 + 5;
const int inf = (int) 1e9 + 778;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, w;
	cin >> n >> w;
	vector<long long> dp(mx + 1, inf);
	dp[0] = 0;
	for (int t = 0; t < n; t++) {
		int x, y;
		cin >> x >> y;
		// weight, value
		for (long long i = mx - y; i >= 0; i--) {
			// look at dp[i] for result
			// working on dp[i + this.value
			long long mv = i + y;
			dp[mv] = min(dp[mv], dp[i] + (ll) x);
		}
	}
	long long ans = 0;
	for (long long i = 0; i < mx; i++) {
		if (dp[i] <= w) {
			ans = max(ans, i);
		}
	}
	cout << ans << '\n';
	/* for (int i = mx; i >= 0; i--) { */
	/* 	if (dp[i] <= w) { */
	/* 		cout << i << '\n'; */
	/* 		break; */
	/* 	} */
	/* } */
	return 0;
}

/*
- minimize the weight but maximize the value
dp[value] = total weight required to aquire
that value
- make sure dp[value] <= weight given.
dp[0] = 0
*/


Measured memory_bytes: 3988
from sys import stdin
import sys
import math
from functools import reduce
import itertools

n, m, q = [int(x) for x in stdin.readline().rstrip().split()]

A = []
for i in range(q):
    A.append([int(x) for x in stdin.readline().rstrip().split()])

nums = [x for x in range(1,m+1)]

max_point = 0
for balls in itertools.combinations_with_replacement(nums, n):
    point = 0
    for i in range(q):
        if balls[A[i][1]-1] - balls[A[i][0]-1] == A[i][2]: point = point + A[i][3]
    max_point = max([max_point, point])

print(max_point)


Measured memory_bytes: 9576
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
const int INF = 1e9+1;

int lis(vector<int> a) {
    int dp[100000];
    fill(dp, dp + a.size(), INF);
	for(int i = 0; i < a.size(); i++){
		*lower_bound(dp, dp + a.size(), a[i]) = a[i];
	}
    return (lower_bound(dp, dp + a.size(), INF) - dp);
}

int main(){

	int n;
    cin >> n;

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

    cout << lis(a) << endl;
    
	return 0;
}


Measured memory_bytes: 3848
#include <stdio.h>
#define M 100005
#define NIL -1

struct Node {
    int parent, left ,right ;
};
struct Node T[M];
int n,D[M];

int setDepth(int,int);
void pr(int);

int main(void){
    int limit,i,c,l,v,d,r,j;
    scanf("%d",&limit);
    for(i=0;i<M;i++){
        T[i].parent=T[i].left=T[i].right=NIL;
    }
    for(i=0;i<limit;i++){
        scanf("%d%d",&v,&d);
        for(j=0;j<d;j++){
            scanf("%d",&c);
            if(j==0)T[v].left=c;
            else T[l].right=c;
            l=c;
            T[c].parent=v;
        }
    }
    for(i=0;i<limit;i++){
        if(T[i].parent==NIL)r=i;
    }
    setDepth(r,0);

    for(i=0;i<limit;i++)pr(i);
    return 0;
}

int setDepth(int u,int p){
    D[u]=p;
    if(T[u].right!=NIL)setDepth(T[u].right,p);
    if(T[u].left!=NIL)setDepth(T[u].left,p+1);
}

void pr(int u){
    int i,c;
    printf("node %d: ",u);
    printf("parent = %d, ",T[u].parent);
    printf("depth = %d, ", D[u]);
    if(T[u].parent == NIL)printf("root, ");
    else if(T[u].left ==NIL)printf("leaf, ");
    else printf("internal node, ");
    printf("[");

    for(i=0,c=T[u].left;c!=NIL;i++,c=T[c].right){
        if(i!=0)printf(", ");
        printf("%d",c);
    }
    printf("]\n");
}


Measured memory_bytes: 6392
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
typedef pair<int,int> P;
std::vector<P> ans;//答え
void pushans(int x,int y){
  ans.push_back(P(x,y));
}
//main
signed main(){
  int k,x,y;cin>>k>>x>>y;
  if(k%2==0&&((x+y)&1)){cout<<-1<<endl;return 0;}//いけない時
  if(abs(x)+abs(y)==k){cout<<1<<endl<<x<<" "<<y<<endl;return 0;}//一回で行ける場合
  int X=abs(x),Y=abs(y);//x,y>=0にしておく
  int cou;//相殺分
  for(int j=k*2;;j+=k){
    if(X+Y>j)continue;
    if((j-(X+Y))%2==0){
      cou=(j-(X+Y))/2;
      break;
    }
  }
  //couが相殺分になった
  int nowx=0,nowy=0;//現在のxとyの場所
  if(cou){
    while(cou+nowx-k>=0){//まず(-k,0)でxを反対方向に行かせる（相殺分を稼ぐ）（cou>=kの時のみ使える）
      nowx-=k;
      cou-=k;
      pushans(nowx,nowy);
    }
    if(nowx<0){//上のwhileが行われた時:残りのcou分yを反対方向に行かせて、xは目的地を目指し始める　
      nowy-=cou;
      nowx+=(k-cou);
    }
    else{//上のwhileが行われなかった時:xかyのどっちかをcou分反対方向に行かせなくてはならない
         //この時、xとyの小さい方を反対方向に行かせるべき
         //反対方向に行かなかったやつは正方向にk-cou進むので、そこで目的地を通り越さないようにするため
        //この解法が正しいか自信がないのはここのパート
      if(X>Y){
        nowy-=cou;
        nowx+=k-cou;
      }
      else {
        nowx-=cou;
        nowy+=k-cou;
      }
    }
    pushans(nowx,nowy);
  }
  while(nowx+k<=X){//(k,0)でxを目的地に行かせる
    nowx+=k;
    pushans(nowx,nowy);
  }
  while(nowy+k<=Y){//(0,k)でyを目的地に行かせる
    nowy+=k;
    pushans(nowx,nowy);
  }
  if(nowx!=X||nowy!=Y)pushans(X,Y);//もしxとyがたどり着いてないなら最後の一回でたどり着ける
  cout<<ans.size()<<endl;
  for(auto p:ans){
    if(x<0)cout<<p.first*(-1);//xが負ならxの動き全てに-1倍をすればよい
    else cout<<p.first;
    cout<<" ";
    if(y<0)cout<<p.second*(-1);//yが負の時も同様
    else cout<<p.second;
    cout<<endl;
  }
}


Measured memory_bytes: 5484
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        new Main().solve(System.in, System.out);
    }

    public void solve(InputStream in, PrintStream out) {
        Scanner sc = new Scanner(in);

        int a = sc.nextInt();
        for (int i = a; i < 1000000; i++) {
            if (isPrime(i)) {
                out.println(i);
                return;
            }
        }

    }
    boolean isPrime(int a) {
        for(int i=2; i*i<=a; i++) {
            if(a%i == 0) return false;
        }
        return true;
    }
}

Measured memory_bytes: 23764
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);

#ifdef BUGGY
	bool DEBUG = 1;
#endif
#ifndef BUGGY
	bool DEBUG = 0;
#endif

ll N, K, ans = 1;

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

	for(int i = 0; i < N; i++) {
		ll op[2];
		op[0] = ans * 2;
		op[1] = ans + K;
		ans = min(op[0], op[1]);
	}

	cout << ans;

	return 0;
}
/*
	Powered by Buggy Plugin
*/

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    ll ans = 0, ans2 = 0;
    vector<ll> c(n);

    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0) {
            if (i == 0 || i == n - 1)
                c[i] = 1;
            else
                c[i] = 2;
        } else {
            if (i == 0 || i == n - 1)
                c[i] = -1;
            else
                c[i] = -2;
        }
    }
    sort(c.begin(), c.end());
    for (int i = 0; i < n; ++i) {
        ans += a[i] * c[i];
    }

    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0) {
            if (i == 0 || i == n - 1)
                c[i] = -1;
            else
                c[i] = -2;
        } else {
            if (i == 0 || i == n - 1)
                c[i] = 1;
            else
                c[i] = 2;
        }
    }
    sort(c.begin(), c.end());
    for (int i = 0; i < n; ++i) {
        ans2 += a[i] * c[i];
    }

    cout << max(ans, ans2) << endl;
    return 0;
}

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

using namespace std;

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

  string s;
  cin >> s;
  set<char> hash;
  for (auto &ss: s) hash.insert(ss);
  string res = "None";
  for (char i = 'a'; i <= 'z'; ++i) {
    if (hash.find(i) == hash.end()) {
      res = i;
      break;
    }
  }
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 512
import sys
input=sys.stdin.readline

def calc():
  mod=10**9+7
  fact=[1]
  for i in range(1,5*10**5+1):
    fact.append((fact[-1]*i)%mod)
  revfact=[1]
  for i in range(1,5*10**5+1):
    revfact.append(pow(fact[i],mod-2,mod))
  n,m=map(int,input().split())
  patternA=(fact[m]*revfact[n]*revfact[m-n]*fact[n])%mod
  patternB=0
  for i in range(n+1):
    tmp=(fact[n]*revfact[i]*revfact[n-i])*(fact[m-i]*revfact[m-n])
    if i%2==0:
      patternB+=tmp
    else:
      patternB-=tmp
      patternB%=mod
  print((patternA*patternB)%mod)
calc()

Measured memory_bytes: 48476
# ライブラリのインポート
#import re #正規表現
import sys
#import heapq
#import collections
#import math

def main():
    s = set()
    for inst in sys.stdin:
        if inst[0] == 'f': print('yes' if inst[5:] in s else 'no')
        else: s.add(inst[7:])
    

if __name__ == '__main__':
    main()



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

using namespace std;

using ll = long long;

constexpr ll MOD = 998244353;
ll dp[516][510], sum[529][510];
int main() {
    ll N, X, i, j, k;
    cin >> N >> X;
    ll M = 0;
    for(i = 0; i <= 10; i++) {
        if(1ll << i > X) {
            M = 1ll<<i;
            break;
        }
    }
    //M = 1ll << (M);
    //cout << M << endl;
    //ll dp[N + 1][M][X + 1], sum[N + 1][M][X + 1];
    /*for(i = 0; i < N + 1; i++) {
        for(j = 0; j < M; j++) {
            for(k = 0; k < X + 1; k++) {
                dp[i][j][k] = sum[i][j][k] = 0;
            }
        }
    }*/

    dp[0][0] = 1;
    sum[0][0] = 1;
    for(k = 0; k < M; k++) {
        for(j = 1; j <= X; j++) {
            sum[k][j] += sum[k][j - 1] + dp[k][j];
            sum[k][j] %= MOD;
        }
    }
    
    for(i = 1; i <= N; i++) {
        for(j = 0; j <= X; j++) {
            for(k = 0; k < M; k++) {
                dp[k][j] = 0;
            }
        }
        for(j = 0; j <= X; j++) {
            for(k = 0; k < M; k++) {
                dp[j ^ k][j] += sum[k][j];
                dp[j ^ k][j] %= MOD;
            }
        }
        for(j = 0; j <= X; j++) {
            for(k = 0; k < M; k++) {
                sum[k][j] = 0;
            }
        }
        sum[0][0] = 1;
        for(k = 0; k < M; k++) {
            for(j = 1; j <= X; j++) {
                sum[k][j] += sum[k][j - 1] + dp[k][j];
                sum[k][j] %= MOD;
            }
        }
    }

    cout << sum[X][X] % MOD << endl;
    return 0;
}


Measured memory_bytes: 7192
def slove():
    import sys
    input = sys.stdin.readline
    x, y = list(map(int, input().rstrip('\n').split()))
    t = x
    cnt = 1
    while True:
        t *= 2
        if t <= y:
            cnt += 1
        else:
            print(cnt)
            exit()


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>
#include <atcoder/all>
 
using namespace std;
using namespace atcoder;
 
/* template */
 
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
 
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};
 
struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};
 
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}
 
template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
 
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
 
constexpr ll LNF = 1LL<<50;
 
constexpr int INF = 1e9+7;
 
const long double PI=acos(-1);

vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};

/* template */

int op(int a,int b){ return max(a,b);}
int e(){ return -1;}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    vector<int> a(n);
    rep(i,0,n){
        cin >> a[i];
    }
    int ans = 0;
    segtree<int, op, e> seg(300010);
    rep(i,0,n){
        int s = seg.prod(max(0,a[i]-k),min(300001,a[i]+k+1));
        chmax(s,0); s++;
        chmax(ans,s);
        seg.set(a[i],s);
    }

    cout << ans << endl;
}


Measured memory_bytes: 9836
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

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

  string ans = "AC";
  if(s[0] != 'A') ans = "WA";
  int c = 0;
  for(int i = 2; i < s.size()-1; i++){
    if(s[i] == 'C') c++;
  }
  if(c != 1) ans = "WA";
  c = 0;
  for(int i = 0; i < s.size(); i++){
    if('A' <= s[i] && s[i] <= 'Z') c++;
  }
  if(c != 2) ans = "WA";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int depth[1000], num[1000], T[1000], n; string S[1000];
int main() {
    while (true) {
        cin >> n; if (n == 0)break;
        for (int i = 0; i < 999; i++) num[i] = 0;
        for (int i = 0; i < n; i++) {
            cin >> S[i]; depth[i] = S[i].size() - 1;
            char F = S[i][S[i].size() - 1];
            if (F == '+') { T[i] = 1; }
            else if (F == '*') { T[i] = 2; }
            else { num[i] = F - '0'; T[i] = 0; }
        }
        for (int i = 9; i >= 0; i--) {
            int J = -1, sum = 1;
            for (int j = 0; j < n; j++) {
                if (depth[j] == i) {
                    if (J != -1) {
                        if (T[J] >= 1)num[J] = sum;
                    }
                    if (T[j] == 1) { sum = 0; J = j; }
                    if (T[j] == 2) { sum = 1; J = j; }
                }
                if (depth[j] == i + 1) {
                    if (T[J] == 1)sum += num[j];
                    if (T[J] == 2)sum *= num[j];
                }
            }
            if (J >= 0) { num[J] = sum; }
        }
        cout << num[0] << endl;
    }
    return 0;
}

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

#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(s) s.begin(),s.end()
#define vll vector<ll>
#define vi vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define vull vector<ull>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define fi first
#define se second
#define sz(x) x.size()
#define cinarr(n,a) for(int i = 0; i < n; i++) cin >> a[i];
#define coutarr(n,a) for(int i = 0; i < n; i++) cout << a[i] << (i+1==n?'\n':' ');
#define fori(i,a,b,x) for(int i = a; i <= b; i+=x)
#define ford(i,a,b,x) for(int i = a; i >= b; i-=x)
#define tc int tt; cin >> tt; for(int cs = 1; cs <= tt; cs++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define reset(x,y) memset(x,y,sizeof x);
#define EPS 1e-10
#define INF 2000000000
#define mod 1000000007
#define debug(val) cerr << "The value of " << #val << " is = " << val << endl;
#define testing cerr << "--------------------------\n";

int main() {
	IOS
	ll n,m,k;
	cin>>n>>m>>k;
	ll a[n+5],b[m+5],prea[n+5],preb[m+5];
	prea[0]=preb[0]=0;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		prea[i]=prea[i-1]+a[i];
	}
	for(int i = 1; i <= m; i++) {
		cin >> b[i];
		preb[i]=preb[i-1]+b[i];
	}
	ll res=0;
	for(int i = 0; i <= n; i++) {
		ll tmp=0;
		if(prea[i]<=k) {
			ll x=upper_bound(preb+1,preb+1+m,k-prea[i])-(preb+1);
//			debug(k-prea[i])
//			debug(x)
			tmp=i+x;
		}
		res=max(res,tmp);
	}
////	testing
//	for(int i = 0; i <= m; i++) {
//		ll tmp=0;
//		if(preb[i]<=k) {
//			ll x=upper_bound(prea+1,prea+1+m,k-preb[i])-(prea+1);
////			debug(k-preb[i])
////			debug(x)
//			tmp=i+x;
//		}
//		res=max(res,tmp);
//	}
	cout<<res<<endl;
}

Measured memory_bytes: 9916
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.Set as S

main :: IO ()
main = do
  s <- getLine
  putStrLn . maybe "None" (:[]) $ solve s

solve :: String -> Maybe Char
solve s = if S.null diff then Nothing else Just $ S.findMin diff where
  diff = S.difference (S.fromList "abcdefghijklmnopqrstuvwxyz") (S.fromList s)


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

long dp[31];

int main(){
	int n;
	dp[0] = 1;
	for(int i = 0; i <= 30; i++) {
		for(int j = 1; j <= 3; j++) {
			if(i+j <= 30) dp[i+j] += dp[i];
		}
	}
	while(1) {
		scanf("%d", &n);
		if(n == 0) break;
		printf("%ld\n", dp[n]/3650+1);
	}
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	ll ans=n%1000;
	if(ans==0){
		ans=1000;
	}
	cout << 1000-ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
void solve(){
	string s;
	cin>>s;
	if(s[0]=='7'||s[1]=='7'||s[2]=='7'){
		cout<<"Yes";
	} else{
		cout<<"No";
	}
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}






Measured memory_bytes: 3656
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final long MOD = 1000000007;
	public static void main(String[] args) {
		int i=0,j=0,k=0;
		Scanner sc = new Scanner(in);
		char[] s = sc.next().toCharArray();
		sc.close();
		int cnt=0;
		char pre  = s[0];
		for (i = 1; i < s.length; i++) {
			if(pre!=s[i]) {
				cnt++;
				pre=s[i];
			}
		}
		out.println(cnt);
	}
}


Measured memory_bytes: 27348
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        for(int i=0; i<n; i++){
            int a = sc.nextInt();
            if(a%2 == 0){
                if(a%3!=0 && a%5!=0){
                    System.out.println("DENIED");
                    return;
                }
            }
        }
        
        System.out.println("APPROVED");
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  ll n;
  cin>>n;
  string ans="";
  vector<char>alpha;
  for(char i='a';i<='z';i++){
    alpha.push_back(i);
  }
  while(n>0){
    n--;
    ans+=alpha[n%26];
    n/=26;
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3600
#include <stdio.h>

int main( void ) {
	double n;
	int i, ni;
	char res[ 14 ] = { "        ." };

	while ( scanf( "%lf", &n ), ( n *= 16 ) >= 0 )
		if ( n - ( ni = n ) > 0 || ni > 4095 )
			puts( "NA" );
		else {
			for ( i = 13; i--; i != 8 ? res[ i ] = '0' + ni % 2, ni /= 2 : 0 ) ;

			printf( "%s\n", res );
		}

	return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    string s; cin>>s;
    sort(s.begin(), s.end());
    if(s=="abc") cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const ll INF = ll(1e18) + 1;

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());

  ll l = -INF, r = INF;
  while (l + 1 < r) {
    ll x = (l + r) / 2;

    bool ok = [&] {
      ll total = 0;
      rep(i, n) {
        int l = -1, r = n;
        if(a[i] >= 0) {
          while (l + 1 < r) {
            int c = (l + r) / 2;
            if(a[i] * a[c] < x) l = c; else r = c;
          }
          total += l + 1;
        } else {
          while (l + 1 < r) {
            int c = (l + r) / 2;
            if(a[i] * a[c] < x) r = c; else l = c;
          }
          total += n - r;
        }
        if(a[i] * a[i] < x) total--;
      }
      total /= 2;
      return total < k;
    }();
    if(ok) l = x;
    else r = x;
  }
  cout << l << endl;

}

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

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

    int a, b, c;
    a = b = c = 0;
    // Sの文字は自由に並び替え可能なのでa, b, cの数で回文の部分文字列があるかどうかが決まる
    for (char tmp: S) {
        if (tmp == 'a')
            a++;
        else if (tmp == 'b')
            b++;
        else
            c++;
    }
    if (abs(a-b) <= 1 && abs(b-c) <= 1 && abs(c-a) <= 1) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x,t,i,p;
  cin>>n>>x>>t;
  for(i=0;i<n;i++){
      i=i+x;
  }
  p=i/x;
  cout<<p*t<<'\n';
  return(0);
}


Measured memory_bytes: 3600
#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>;

int INF = 1 << 30;

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

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

int book[12][12];

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> price(n);

  rep(i, n) {
    cin >> price[i];
    rep(j, m) {
      cin >> book[i][j];
    }
  }

  int result = INF;
  rep(s, 1 << n) {
    int cost = 0;

    vector<int> skill(m);
    rep(i, n) {
      if (s >> i & 1) {
        cost += price[i];
        rep(j, m) skill[j] += book[i][j];
      }
    }
    bool is_ok = true;
    rep(i, m) {
      if (skill[i] < x) is_ok = false;
    }
    if (is_ok) {
      result = min(result, cost);
    }
  }

  if (result == INF) {
    cout << -1 << endl;
  } else {
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=1e5+5,L=17;
int x[N];
int go[N][L];
int og[N][L];
int32_t main(){
    int n;cin>>n;
    for(int i=1;i<=n;++i)cin>>x[i];
    int pos=n,l,q;
    cin>>l>>q;
    for(int i=n;i>=1;--i){
        while(x[i]+l<x[pos])pos--;
        go[i][0]=pos;
        for(int j=1;j<L;++j)go[i][j]=go[go[i][j-1]][j-1];
    }
    pos=1;
    for(int i=1;i<=n;++i){
        while(x[i]-l>x[pos])pos++;
        og[i][0]=pos;
        for(int j=1;j<L;++j)og[i][j]=og[og[i][j-1]][j-1];
    }
    while(q--){
        int a,b;
        cin>>a>>b;
        int ans=1;
        if(a<b){
            for(int i=L-1;i>=0;--i){
                if(go[a][i]<b){
                    a=go[a][i];
                    ans+=1<<i;
                }
            }
        }else{
            for(int i=L-1;i>=0;--i){
                if(og[a][i]>b){
                    a=og[a][i];
                    ans+=1<<i;
                }
            }
        }
        cout<<ans<<'\n';
    }
    return 0;
}

Measured memory_bytes: 30948
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define int long long
using namespace std;
const int N = 5e3 + 5, inf = 1e18;
int read() {
	int x = 0, f = 1; char ch;
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
	return x * f;
}
template <class T> T Max(T a, T b) { return a > b ? a : b; }
template <class T> T Min(T a, T b) { return a < b ? a : b; }
int n, L, R, a[N], f[N];
signed main() {
	n = read(); R = read(); L = read();
	for(int i = 1; i <= n; ++ i) a[i] = read(), f[i] = 1e18;
	a[0] = 0; a[n + 1] = n + 1; f[0] = 0; f[n + 1] = 1e18;
	for(int i = 1; i <= n + 1; ++ i) {
		int cl = 0, cr = 0;
		for(int j = i - 1; j >= 0; -- j) {
			if(a[j] < a[i]) f[i] = min(f[i], f[j] + cl * L + cr * R);
			if(a[j] < a[i]) cl ++;
			if(a[j] > a[i]) cr ++;
		}
	}
	printf("%lld\n", f[n + 1]);
	return 0;
}

Measured memory_bytes: 888
#include <iostream>

int main()
{
	int n, a, b;
	std::cin >> n >> a >> b;
	if (n * a < b)
	{
		std::cout << n * a << std::endl;
	}
	else
	{
		std::cout << b << std::endl;		
	}
	
	return 0;
}

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

using namespace std;

struct odd : public unary_function<int, bool> { bool operator () (int x) const { return (x % 2) != 0; } };
void dis(int *Array, int N) { for(int i = 0; i < N; ++i) {std::cout.width(1); std::cout << Array[i];} std::cout << std::endl;}
signed fac(int n){return (n==1 || n==0) ? 1: n * fac(n - 1);}
bool V(char x) {return (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u'); } 
template<typename T, typename U> inline signed  amin(T &x, U y) { if(y < x) x = y; return x;}
template<typename T, typename U> inline signed  amax(T &x, U y) { if(x < y) x = y; return x;}
//signed m(){long long T, pp,p,ppp, ct, nn, xx; cin >> p; cin.ignore(); for(int k=0;k<n;k++){for(int l=0;l<(k+1);l++){cin>>a[k][l];}}
#define inn freopen("input.txt", "r", stdin) 
#define outt freopen("output.txt", "w",stdout)
#define all(cont) cont.begin(), cont.end()
#define ll          long long
#define sz(x)       (int)x.size()
#define endl        '\n'
#define rep(i,a,b)  for(int i=a;i<b;i++)

ll t,n,arr[123456],arr1[12345],max1=0,a,b,c=0,d,e,f,flag=0,j=0;

    

signed  solve()
{
   string s,t;
   cin>>s>>t;

   for(int i=0; i<3; i++)
   {
    if(s[i]==t[i])
    {
        c++;
    }
   }
   cout<<c;
    return 0;
}
signed main(){//inn;outt;
              ll t=1;//cin>>t;
    while(t--){solve();}}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int T[] = new int[N];
        int sum = 0;
        int U[] = new int[N];
       for(int i=0;i<N;i++){
           T[i] = sc.nextInt();
       }
       int M = sc.nextInt();
       int P[][] = new int[M][2];
       for(int i=0;i<M;i++){
           P[i][0] = sc.nextInt();
           P[i][1] = sc.nextInt();
       }
       for(int i =0;i<M;i++){
        for(int k=0;k<N;k++){
           U[k] = T[k];
        }
        sum = 0;
        int k1 = P[i][0] ;
        U[k1-1] = P[i][1]; 
        for(int j=0;j<N;j++){
            sum = sum + U[j];
        }
           System.out.println(sum);

        }
    } 
}

Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		
		String ans = "Impossible";
		
		if (a%3==0||b%3==0||(a+b)%3==0) {
			ans = "Possible";
		}
		System.out.println(ans);
		scanner.close();

	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	int n; scanf("%d", &n);
	int m=1; while(m<n) m*=2;
	if(n==m){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	REP(i, (n-1)/2){
		int a=i*2+2, b=i*2+3;
		printf("%d %d\n",   a,   b);
		printf("%d %d\n",   b,   1);
		printf("%d %d\n",   1, n+a);
		printf("%d %d\n", n+a, n+b);
	}
	printf("%d %d\n", n+3, n+1);
	if(n%2==0){
		int a = 2; while((n & a) == 0) a*=2;
		int b = n-a;
		b += 1;
		printf("%d %d\n",   n,   b);
		printf("%d %d\n", n+a, n+n);
	}
}


Measured memory_bytes: 2304
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String N_str = sc.nextLine();
		final int N = Integer.parseInt(N_str);
		String W[] = new String[N];
		for(int i = 0; i < N; i++) {
			W[i] = sc.nextLine();
		}
		
		boolean flag = true;
		
		for(int i = 0; i < N; i++) {
			if(i >= 1) {
				if(W[i].charAt(0) != W[i - 1].charAt(W[i - 1].length() - 1)) {
					flag = false;
				}
			}
			for(int j = 0; j < i; j++) {
				if(W[i].equals(W[j])) {
					flag = false;
				}
			}
		}
		
		if(flag) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
long long int a[100000],b[100000],c[100000],dp[100005][3],n;
long long int solve(int idx,int previousday)
{
    if(idx==n)
    return 0;

    if(dp[idx][previousday]!=-1)
    return dp[idx][previousday];
    
    long long int ans=INT_MIN;
    if(previousday==0)
    {
         ans=max(ans,b[idx]+solve(idx+1,1));
         ans=max(ans,c[idx]+solve(idx+1,2));
    }
    else if(previousday==1)
    {
         ans=max(ans,a[idx]+solve(idx+1,0));
         ans=max(ans,c[idx]+solve(idx+1,2));
    }
    else if(previousday==2)
    {
         ans=max(ans,a[idx]+solve(idx+1,0));
         ans=max(ans,b[idx]+solve(idx+1,1));
    }
    else
    {
         ans=max(ans,a[idx]+solve(idx+1,0));
         ans=max(ans,b[idx]+solve(idx+1,1));
         ans=max(ans,c[idx]+solve(idx+1,2));
    }
    dp[idx][previousday]=ans;
    return ans;
}
int main() 
{
  cin>>n;
  
  for(int i=0;i<n;i++)
  {
      cin>>a[i];  cin>>b[i];  cin>>c[i];
  }
  memset(dp,-1,sizeof(dp));
  cout<<solve(0,3);
}


Measured memory_bytes: 16084