akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))

//魔剤！？

bool pairComp(const pair<ll,ll>& fElof,const pair<ll,ll>& sElof){
    return fElof.first<sElof.first;

}

int main(){
    ll ans=0,n,m;
    cin >>n>>m;
    pair<ll,ll> s[n];

    for(int i=0;i<n;i++){
        cin >>s[i].first>>s[i].second;
    }
    sort(s,s+n,pairComp);

    for(int i=0;i<n;i++){
        if(m>s[i].second){//まだ余る
            ans+=s[i].first*s[i].second;
            m-=s[i].second;
        }else{//足りる
            ans+=s[i].first*m;
            break;
        }
    }

    cout <<ans<<endl;
    

    return 0;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b)
{
    if (a % b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int main() {
  int n,a,b,ans=0;
  cin >> n >> a >> b;
  for(int i=1;i<=n;i++){
    int sum = i/10000 + (i%10000)/1000 + (i%1000)/100 + (i%100)/10 + i%10;
    if(a<=sum&&sum<=b){
      ans+=i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
typedef vector<int,vector<int>> vec;
typedef pair<int,int> P;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define all(vec) vec.begin(),vec.end()
#define mod 1000000007
const int INF = 1e9;

int main(){
  ll N; cin>>N;
  ll res=N;
  REP(i,0,N+1){
    ll cc=0,t=i;
    while(t>0){cc+=t%6;t/=6;}
    t=N-i;
    while(t>0){cc+=t%9;t/=9;}
    if(res>cc)res=cc;
  }
  print(res)
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 55
using namespace std;
int n,num,a[maxn],b[maxn];
map<int,map<int,int> > mp;
int main()
{
    scanf("%d",&n);
    for (int i=1; i<=n; ++i)
        scanf("%d%d",a+i,b+i);
    for (int i=1; i<=n; ++i)
        for (int j=1; j<=n; ++j)
            if (i!=j) 
                num=max(num,++mp[a[i]-a[j]][b[i]-b[j]]);
    printf("%d\n",n-num);
    return 0;
}



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

int main(){
    int N;
    cin >> N;
    for(int h=1;h<=(int)(3*N)/4&&h<=3500;h++){
        for(long n=1;(n*(4*h-N)<=2*N*h)&&(4*h-N)>0;n++){
            if((4*n*h-N*h-N*n)>0&&(N*n*h)%(4*n*h-N*h-N*n)==0){
                long long w=(N*n*h)/(4*h*n-N*n-h*N);
                if(w>0){
                    cout << h << " " << n << " " << w << "\n" ;
                    return 0;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
// import lib.util.*;
// import lib.graph.*;
// import lib.io.*;
// import lib.math.*;
import java.math.BigInteger;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] L = new long[N];
        for (int i = 0; i < N; i++) {
            L[i] = sc.nextLong();
        }
        int res3 = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                for (int k = 0; k < N; k++) {
                    long a = L[i];
                    long b = L[j];
                    long c = L[k];
                    if (a == b || b == c || a == c) {
                        continue;
                    }

                    if (Math.abs(b - c) < a && a < b + c) {
                        res3++;
                    }
                }
            }
        }
        System.out.println(res3 / 6);
    }
}

Measured memory_bytes: 35776
#include <bits/stdc++.h>
/**
*   author: j o s e m a g o
*   date:
**/
using namespace std;
#pragma GCC optimize ("Ofast")
#define f first
#define s second
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mset(a,v) memset(a,v,sizeof(a))
#define pb push_back
#define sz(x) ((int)(x).size())
#define rsz resize
#define ln "\n"

typedef double db;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const ld PI = 2*acos(0.0);
const int MOD = 1000000007;
const int JJJ = 100009;




int main(){

  //freopen("input.in","r",stdin);
  //freopen("input.out","w",stdout);

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

    int N,k;
    cin >> N >> k;
    vector<int>h(N+k+1);
    for(int i = 0;i < N;i++){
        cin >> h[i];
    }
    vector<int>dp(N+k+1,INT_MAX);
    dp[0] = 0;
    for(int i = 1;i < k;i++) dp[i] = abs(h[i]-h[0]);
    for(int i = k;i < N;i++){
        for(int j = 1;j <= k;j++){
            dp[i] = min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
        }
    }

//    for(int i = 0;i < N;i++) cerr<<dp[i]<<" ";
    cout<<dp[N-1];




    return 0;
}


Measured memory_bytes: 1024
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w, n;
    cin >> h >> w >> n;
    ll k = max(h, w);
    ll f = min(h, w);
    if(n%k==0){
        cout << n / k << endl;
    }else{
        cout << n / k + 1 << endl;
    }
}


Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func rev(s []byte) string {
	N := len(s)
	for i := 0; i < N/2; i++ {
		s[i], s[N-1-i] = s[N-1-i], s[i]
	}
	return string(s)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N := getInt()
	s := make([]string, N)
	for i := 0; i < N; i++ {
		s[i] = rev([]byte(getString()))
	}
	sort.Slice(s, func(i, j int) bool {
		return len(s[i]) < len(s[j])
	})
	ans := 0
	mp := make(map[int]int)
	off := 1009
	for _, x := range s {
		hash := make([]int, len(x))
		hash[0] = int(x[0])
		for i := 1; i < len(x); i++ {
			hash[i] = hash[i-1]*off + int(x[i])
		}
		cnt := make([]int, 26)
		for i := 0; i < len(x); i++ {
			cnt[int(x[i]-'a')]++
		}
		for c := 0; c < 26; c++ {
			if cnt[c] == 0 {
				continue
			}
			h := c + 'a'
			ans += mp[h]
		}
		for i := 0; i < len(x)-1; i++ {
			h := hash[i] * off
			cnt[x[i]-'a']--
			for c := 0; c < 26; c++ {
				if cnt[c] == 0 {
					continue
				}
				h += c + 'a'
				ans += mp[h]
				h -= c + 'a'
			}
		}
		mp[hash[len(x)-1]]++
	}
	out(ans)
}


Measured memory_bytes: 19880
n = int(input())
l = list(map(int, input().split()))
c = 0
for i in range(1,n-1):
    if l[i] > l[i-1]:
        if l[i] < l[i+1]:
            c += 1
    else:
        if l[i] > l[i+1]:
            c += 1
print(c)

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

int main(){
	int x,y,bip,bap;
	cin >> x >> y;
	if (x==2){
		bip=1;
	}
	else if (x==4 || x==6 || x==9 || x==11){
		bip =2;
	}
	else {
		bip =3;
	}
	
	if (y==2){
		bap=1;
	}
	else if (y==4 || y==6 || y==9 || y==11){
		bap =2;
	}
	else {
		bap =3;
	}
	
	if (bip==bap){
		cout << "Yes"  << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

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

    //good luck kittu!
    string s, t = "";
    cin>>s;
    int n = s.size();
    for(int i = 0; i<n; i++){
        if(s[i]=='0') t.push_back('0');
        else if(s[i]=='1') t.push_back('1');
        else if(t.size()!=0) t.pop_back();
    }
    cout<<t<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,m;
	cin>>n>>m;
	int w=n-m;
	LL t=w*100;
	int mmm=1<<m;
	t+=1900*m;
	t*=mmm;
	cout<<t<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define ll long long
int main(){
    int n,k;
    cin >> n;
    cin >> k;
    ll ans=0;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        ans+=2*min(a,k-a);
    }
    cout <<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
from bisect import bisect
n = int(input())
d = [int(i) for i in input().split()]
m = int(input())
t = [int(i) for i in input().split()]
d,tc,flag = sorted(d),Counter(t),True
for i in tc.most_common():
	if bisect(d,i[0])-bisect(d,i[0]-1)<i[1]:
		flag = False
		break
if flag: print("YES")
else: print("NO")

Measured memory_bytes: 49248
#include <stdio.h>
#include <math.h>

int main() {
  int input[1000];
  int n;
  int keta;
  int box[10000];
  int temp[2];
  int i, j, k, count;
  int max;
  int judge;

  scanf("%d", &n);

  for(i = 0; i < n; i++) {
    scanf("%d", &input[i]);
    if(input[i] < 10) {
      printf("0\n");
      continue;
    }

    count = 0;
    while(1) {
      if(input[i] / 10 == 0) break;
      max = 0;
      keta = 0;
      judge = 0;
      for(j = 1;; j++) {
	if(input[i] / pow(10, j) > 0) keta++;
	else  break;
      }
	 
      for(j = 0; j < keta; j++) {
	temp[0] = input[i] / pow(10, keta - j);
	temp[1] = input[i] - temp[0] * pow(10, keta - j);
	box[j] = temp[0] * temp[1];
      }
      
      for(j = 0; j < keta; j++) {
	if(box[j] > max) max = box[j];
      }
      input[i] = max;
      count++;      
    }
    printf("%d\n", count);
  }

  
  return 0;
}

Measured memory_bytes: 692
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(x) cout<<#x<<":";cout<<x<<endl;
#define debugs(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

ll ans;
int n,m,q;
struct qu{
    ll a,b,c,d;
    qu(ll a,ll b,ll c,ll d):a(a),b(b),c(c),d(d){}
    qu(){}
};
vector<qu> v;

vector<int> A;

void dfs(int d,int las){
    if(d==n){
        ll res=0;
        rep(i,q){
            if(A[v[i].b]-A[v[i].a]==v[i].c) res+=v[i].d;
        }
        chmax(ans,res);
        return ;
    }
    for(int i=las;i<=m;i++){
        A.push_back(i);
        dfs(d+1,i);
        A.pop_back();
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    cin>>n>>m>>q;
    v.resize(q);
    rep(i,q){
        ll a,b,c,d;cin>>a>>b>>c>>d;a--,b--;
        v[i]=qu(a,b,c,d);
    }
    dfs(0,1);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);

int main(){
	int x,n;
    cin>>x>>n;
    int p[n];
    rep(i,n)cin>>p[i];
    map<int,int>ma;
    rep(i,n)ma[p[i]]++;
    rep(i,1000){
        if(!ma[x-i]){
            cout<<x-i<<endl;
            return 0;
        }
        if(!ma[x+i]){
            cout<<x+i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
    using namespace std;
    int N, a[109];
    int main() {
    	cin >> N;
    	for (int i = 0; i < N; i++) cin >> a[i];
    	sort(a, a + N, greater<int>());
    	int ret = 0;
    	for (int i = 0; i < N; i++) ret += a[i] * (i & 1 ? -1 : 1);
    	cout << ret << endl;
    	return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
using namespace std;

typedef long long ll;

#define MAX_V 100
#define INF int(1e9)

// g : ??°??????, V : g???????????°, s : ????????????????????????
int Prim (int g[MAX_V + 1][MAX_V + 1], int V, int s) {
    ll ret = 0, min_, nxtv, v = s, size_;
    // bool used[V] = {false}; // c++11??????
    bool used[V]; memset(used, 0, sizeof(used)); // c++11??\???
    vector<int> usedv;
    usedv.push_back(s);
    used[s] = true;

    while (usedv.size() < V) {
        min_ = INF;
        size_ = usedv.size();

        // ?????¨???????????????????????°?????????????????\?¶????????????????????°????????????¢???
        for (int i = 0; i < size_; ++i) {
            for (int j = 0; j < V; ++j) {
                if (usedv[i] == j) continue;
                if (!used[j] && min_ > g[usedv[i]][j]) {
                    min_ = g[usedv[i]][j];
                    v = j;
                }
            }
        }

        ret += min_;
        usedv.push_back(v);
        used[v] = true;
    }

    return ret;
}

int n, g[MAX_V + 1][MAX_V + 1];

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

    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> g[i][j];
            if (g[i][j] == -1) g[i][j] = INF;
        }
    }

    cout << Prim(g, n, 0) << endl;


    return 0;
}

Measured memory_bytes: 3212
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p,lc,rc;}; 
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void Preorder(int u){
  printf(" %d",u);
  if(T[u].lc!=NIL) Preorder(T[u].lc);
  if(T[u].rc!=NIL) Preorder(T[u].rc);
}

void Inorder(int u){
  if(T[u].lc!=NIL) Inorder(T[u].lc);
  printf(" %d",u);
  if(T[u].rc!=NIL) Inorder(T[u].rc);
}
void Postorder(int u){
  if(T[u].lc!=NIL) Postorder(T[u].lc);
  if(T[u].rc!=NIL) Postorder(T[u].rc);
  printf(" %d",u);
}

int main(){
  int i, j, k;
  int n;
  int id, sib;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].lc = T[i].rc = NIL;
  
  for(i=0; i<n; i++){
    scanf("%d", &id);
    scanf(" %d %d",&T[id].lc, &T[id].rc);
    
    if(T[id].lc!=-1) T[ T[id].lc ].p=id;
    if(T[id].rc!=-1) T[ T[id].rc ].p=id;
    
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1){
      root = i;
      break;
    }
  }

  printf("Preorder\n");
  Preorder(root);

  printf("\nInorder\n");
  Inorder(root);

  printf("\nPostorder\n");  
  Postorder(root);
  
  printf("\n"); 
  return 0;
}



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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

ll F(int a, int b){
  ll ans = 0;
  for(int i = 0; i < b; ++i){
    ans *= 10;
    ans += a;
  }
  return ans;
}

int main(){
  int a,b; cin >> a >> b;
  cout << min(to_string(F(a,b)), to_string(F(b,a))) << endl;
  return 0;
}


Measured memory_bytes: 256
import time
startTimeProblem=time.time()

import fileinput, sys, itertools, functools
from math import *
from bisect import *
from heapq import *
from collections import *

def lcm(a, b):  
    return (a*b)/gcd(a, b)

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()

######################################

N, M = In.ints()

conn = [set() for j in range(N+1)]

for i in range(M):
    A, B = In.ints()

    conn[A].add(B)
    conn[B].add(A)

que = deque([1])
selection = [0]*(N+1)
seen = set([1])

while len(que)>0:
    el = que.popleft()

    for nextVert in conn[el]:
        if nextVert not in seen:
            selection[nextVert] = el 
            seen.add(nextVert)
            que.append(nextVert)

Out.str("Yes")
for i in range(2, len(selection)):
    Out.int(selection[i])

######################################

if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

Measured memory_bytes: 127928
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define int long long
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
const double EPS = 1e-6 ; 
signed main(){
    fastio
    int n , k ; 
    cin >> n >> k ; 
    vector<int> v(n) ; 
    for(int i = 0; i < n; i++){
        cin >> v[i] ; 
    }
    sort(v.begin(), v.end());
    int ans = 0 ; 
    for(int i = 0; i < n - k; i++){
        ans += v[i] ;
    }
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
//l={1,2,3,4}
//greater<int>()
//sort(l,l+n)

int main(void)
{
	int a, b;
	cin >> a >> b;
	if (a*b % 2 == 0)
		cout << "Even" << endl;
	else
		cout << "Odd" << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
int n,m;
int main(){
    cin >> n;
    int a, b;
    if(n-1){
        cin >> a >> b;
        cout << a+b << endl;
    }else{
        cout << "Hello World" << endl;
    }

}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

void solve(int n, vector<int> const &inittime, vector<vector<int>> const &time) {
  vector<int> dp(1<<n, infty<int>);
  dp[(1<<n)-1] = 0;
  RREP(S, (1<<n)-1) {
    REP(play, n) {
      if (S & (1<<play)) { continue; }
      int playtime = inittime[play];
      REP(i, n) {
        if (S & (1<<i)) { chmin(playtime, time[play][i]); }
      }
      chmin(dp[S], playtime + dp[S|(1<<play)]);
    }
  }
  cout << dp[0] << endl;
}

int main() {
  // cout << fixed << setprecision(10);

  int N;
  while (cin >> N && N) {
    vector<int> T0(N);
    vector<vector<int>> T(N, vector<int>(N));
    REP(i, N) {
      cin >> T0[i];
      REP(j, N) { cin >> T[i][j]; }
    }
    solve(N, T0, T);
  }
  return 0;
}



Measured memory_bytes: 3388
using System;
using System.Collections.Generic;
using System.Linq;

namespace procon
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var map = new Dictionary<string, bool>();
            for (int i = 1; i <= 13; i++) map.Add("S " + i, false);
            for (int i = 1; i <= 13; i++) map.Add("H " + i, false);
            for (int i = 1; i <= 13; i++) map.Add("C " + i, false);
            for (int i = 1; i <= 13; i++) map.Add("D " + i, false);
            
            var n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                var input = Console.ReadLine();
                map[input] = true;
            }

            map.Where((s, index) => s.Value == false)
                .Select(s => s.Key)
                .ToList()
                .ForEach(s => Console.WriteLine(s));
        }
    }
}

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

int main()
{
    int D, T, S;
    cin >> D >> T >> S;
    if (D > S * T)
    {
        cout << "No"
             << "\n";
    }
    else
    {
        cout << "Yes"
             << "\n";
    }
    return 0;
}

Measured memory_bytes: 3592
H, W = map(int, input().split())
s_list = []
for i in range(H):
    s = list(input())
    s_list.append(s)

dp = [[0 for _ in range(W)] for _ in range(H)]
dp[0][0] = 1
mod = 10 ** 9 + 7
for i in range(H):
    for j in range(W):
        if s_list[i][j] == "#":
            continue
        if i + 1 < H and s_list[i + 1][j] == ".":
            dp[i + 1][j] += dp[i][j] % mod
        if j + 1 < W and s_list[i][j + 1] == ".":
            dp[i][j + 1] += dp[i][j] % mod
print(dp[H - 1][W - 1] % mod)



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

int main()
{
  int n,m;
  cin >> n;
  string s[100],t[100],u[200];
  int a[100];

  for(int i = 0;i < n;i++){
    cin >> s[i];
    u[i] = s[i];
    a[i] = 0;
  }
  cin >> m;
  for(int i = 0;i < m;i++){
    cin >> t[i];
    u[n+i] = t[i];
  }
  int max1 = 0;

  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      if(u[i] == u[j]) a[i]++;
    }
    for(int j = n;j < n + m;j++){
      if(u[i] == u[j]) a[i]--;
    }
    max1 = max(max1,a[i]);

  }
  cout << max1 << endl;
  return 0;

}


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

int main() {
	int N; cin >> N;
	int sum = 0;
	int K = N;
	while (N > 0) {
		sum += N % 10;
		N /= 10;
	}
	if (K % sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int i;
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int q = sc.nextInt();
			List<Queue<Integer>> array = new ArrayList<>();
			for(i = 0; i < n; i++) {
				array.add(new PriorityQueue<Integer>(4 ,new MyComparator()));
			}
			for(i = 0; i < q; i++) {
				int order_number = sc.nextInt();
				int t = sc.nextInt();
				//命令1と2は配列が空なら処理しない
				if(array.get(t).isEmpty() && order_number != 0) {
					continue;
				}
				switch(order_number) {
				case 0 :
					array.get(t).add(sc.nextInt());
					break;
				case 1 :
					System.out.println(array.get(t).peek());
					break;
				case 2 :
					array.get(t).remove();
					break;
				}
				// for(Queue<Integer> output : array) {
				// 	System.out.println(output);
				// }
			}
		}
	}
}
class MyComparator implements Comparator<Object> {
	 
    public int compare(Object obj1, Object obj2) {
         
        int num1 = (int)obj1;
        int num2 = (int)obj2;
         
        if(num1 < num2) {
            return 1;
        } else if(num1 > num2) {
            return -1;
        } else{
            return 0;
        }
    }
}


Measured memory_bytes: 168308
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
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; }
using namespace std;
typedef long long ll;

const int inf = 1000000000;
int dp[1001][1 << 12];

// AtCoder Beginner Contest 142
int main(){

    int n, m;
    cin >> n >> m;

    rep(i, 1001)rep(j, 1 << 12)dp[i][j] = inf;
    dp[0][0] = 0;

    rep(loop, m){
        int a, b;
        cin >> a >> b;
        int bit = 0;
        rep(i, b){
            int c;
            cin >> c;
            c--;
            bit |= (1 << c);
        }
        rep(i, 1 << n){
            chmin(dp[loop + 1][i], dp[loop][i]);
            chmin(dp[loop + 1][i | bit], dp[loop][i] + a);
        }
    }

    cout << (dp[m][(1 << n) - 1] == inf ? -1 : dp[m][(1 << n) - 1]) << endl;
    return 0;


}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int D;
    cin >> D;
    ll c[26];
    rep(i, 26) cin >> c[i];
    ll s[D][26];
    rep(i, D){
        rep(j, 26) cin >> s[i][j];
    }
    int pre[26];
    fill(pre, pre+26, -1);
    ll ans = 0;
    int t[D];
    set<int> ids[26];
    rep(i, 26) ids[i].insert(-1);
    rep(i, D){
        cin >> t[i]; t[i]--;
        ans += s[i][t[i]];
        pre[t[i]] = i;
        ids[t[i]].insert(i);
        rep(j, 26){
            ans -= c[j]*(i-pre[j]);
        }
    }
    rep(i, 26) ids[i].insert(D);
    int M;
    cin >> M;
    rep(i, M){
        int d, q;
        cin >> d >> q;
        d--, q--;
        int p = t[d];
        ans = ans-s[d][p]+s[d][q];
        set<int>::iterator it1, it2;
        it1 = ids[p].upper_bound(d);
        it2 = ids[q].upper_bound(d);
        int a1, a2, b1, b2;
        b1 = *it1, b2 = *it2;
        it1--, it1--, it2--;
        a1 = *it1, a2 = *it2;
        //cout << a1 << ' ' << b1 << ' ' << a2 << ' ' << b2 << endl;
        ans -= c[p]*(b1-d)*(d-a1);
        ans += c[q]*(b2-d)*(d-a2);
        cout << ans << endl;
        t[d] = q;
        ids[p].erase(d);
        ids[q].insert(d);
    }
}

Measured memory_bytes: 3688
L = input()
dp1 = 2
dp2 = 1
MOD = 10**9+7
for c in L[1:]:
  if c=='1':
    ndp1 = 2*dp1
    ndp2 = dp1 + 3*dp2
  else:
    ndp1 = dp1
    ndp2 = 3*dp2
  dp1,dp2 = ndp1%MOD,ndp2%MOD
print((dp1+dp2)%MOD)

Measured memory_bytes: 3188
# include<iostream>
# include<algorithm>

using namespace std;

int main(void){
  int n;
  cin >> n;
  int d[n];
  for(int i=0; i<n; i++)
    cin >> d[i];
  sort(d, d+n);
  // for(int i=0; i<n; i++)
  //   cout << d[i] << ' ';
  // cout << '\n';
  cout << d[((n - 1)/ 2) + 1] - d[((n - 1)/ 2)] << endl;
  return 0;
}

Measured memory_bytes: 640
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

blk_wh = '#.' * 151  # Max 300 char
while True:
    h, w = map(int, sys.stdin.readline().split())
    if h == 0  and w == 0:
        break

    for row in range(h):
        if row % 2 == 0:
            print(blk_wh[:w])
        else:
            print(blk_wh[1:w+1])
    print()



Measured memory_bytes: 5628
import std.conv, std.stdio;
import std.algorithm, std.range, std.string;

void main()
{
    immutable n = readln.chomp.to!size_t;
    size_t[immutable(ubyte)[]] d;
    foreach (i; 0..n)
    {
        auto s = cast(ubyte[])(readln.chomp);
        auto k = s.sort().array.idup;
        if (auto p = k in d)
            (*p)++;
        else
            d[k] = 1;
    }
    ulong answer;
    foreach (v; d.byValue)
        answer += v*(v-1)/2;
    answer.writeln;
}


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

#define pb push_back
#define fi first
#define se second
#define eb emplace_back

using namespace std;
typedef pair<int, int> ii;
typedef long long ll;

// pivot de um caminho eh o vertice colorido que tem o menor tempo de visita
/*
    Considera todos os caminhos em que u eh o lca (facil, multiplicacao do cnt dos filhos)
    Considera todos os caminhos em que o lca nao ta pintado e so vai pra direita
    Acha o primeiro acima pintado
 */

const int N = 200007;
vector<int> e[N], que[N];
stack<int> colors[N];
int cnt[N], col[N], aux[N];
ll ans[N];

void dfs(int u, int p = -1) {
    cnt[u] = 1;

    int c = col[u];
    int w = colors[c].size()? colors[c].top() : 1;
    if(u != 1) que[w].pb(u);
    for(int v : e[u]) {
        if(v == p) continue;
        colors[col[u]].push(v);
        dfs(v, u);
        colors[col[u]].pop();
        ans[c] -= (ll) cnt[v] * (cnt[v] + 1)/2;
        cnt[u] += cnt[v];
    }
    ans[c] += (ll)cnt[u] * (cnt[u] + 1)/2;
}

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

    for(int i = 1; i <= n; ++i) {
        cin >> col[i];
    }

    for(int i = 1; i < n; ++i) {
        int u, v; cin >> u >> v;
        e[u].pb(v);
        e[v].pb(u);
    }

    dfs(1);

    for(int u = 2; u <= n; ++u) {
        int tot = 0;
        for(int v : que[u]) {
            int c = col[v];
            tot += cnt[v];
            ans[c] += (ll) cnt[v] * (cnt[u] - tot);
        }
    }

    ll tot = 0;
    for(int v : que[1]) {
        int c = col[v];
        aux[c] += cnt[v];
        ans[c] += (ll) cnt[v] * (n - aux[c]);
    }

    for(int i = 1; i <= n; ++i) {
       cout << ans[i] << '\n';
    }
}

Measured memory_bytes: 187276
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main()
{int n,m;
 cin >> n >> m;
 
 if (n >= m){
  cout << 0 << endl;
   return 0;   
 }
 
 vector<int> x(m);
 rep(i,m) cin >> x.at(i);
 
 sort (x.begin(),x.end());
 
 vector<int> l(m-1);
 rep(i,m-1) l.at(i) = x.at(i+1) - x.at(i);
 
 sort(l.begin(),l.end(),greater<int>());
 
 int L = 0;
 rep(i,n-1) L += l.at(i); 

 int ans = x.at(m-1) - x.at(0) - L;
 
 
 cout << ans  << endl;

 
 
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cout << v << " ";                                                          \
  }                                                                            \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vec< int > a(N);
  int maxa = -1, maxaI = -1;
  REP(i, N) {
    cin >> a[i];
    bool p = chmax(maxa, a[i]);
    if (p)
      maxaI = i;
  }
  int maxj = -1, maxJval = -1;
  REP(i, N) {
    if (i != maxaI) {
      bool p = chmax(maxj, min(maxa - a[i], a[i]));
      if (p)
        maxJval = a[i];
    }
  }
  cout << maxa << " " << maxJval << "\n";
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void){

	int sum=100000,i,data;

	scanf("%d",&data);

	for(i=0;i<data;i++){

		sum=sum+(sum*0.05);

		if(0!=sum%1000){
			sum=sum+1000;
		}
		
		sum=sum/1000;
		sum=sum*1000;

	}


	printf("%d\n",sum);

	return 0;

}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>


typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++);
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/

using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}
map<string, int> memo;


int main() {
	//sort(a.begin(),a.end());
	string s;
	cin >> s;
	if (s == "AAA" || s == "BBB") cout << "No"; else cout << "Yes";
	return 0;
}









Measured memory_bytes: 256
/*      ░░█ ▄▀█ █   █▀ █░█ █▀█ █▀▀ █▀▀   █▀█ ▄▀█ █▀▄▀█  
        █▄█ █▀█ █   ▄█ █▀█ █▀▄ ██▄ ██▄   █▀▄ █▀█ █░▀░█     */


// [agc006_a.cpp] => [27-07-2020 @ 21:43:29] 
// Author & Template by : Udit "luctivud" Gupta
// https://www.linkedin.com/in/udit-gupta-1b7863135/


#include <bits/stdc++.h>
// #include <iostream>
// #include <string>
// #include <vector>
// #include <algorithm>
// #include <sstream>
// #include <queue>
// #include <deque>
// #include <bitset>
// #include <iterator>
// #include <list>
// #include <stack>
// #include <map>
// #include <set>
// #include <functional>
// #include <numeric>
// #include <utility>
// #include <limits>
// #include <time.h>
// #include <math.h>
// #include <stdio.h>
// #include <string.h>
// #include <stdlib.h>
// #include <assert.h>

using namespace std;

typedef long long int lld;
typedef unsigned long long int llu;
typedef vector<int> v_int;
typedef vector<lld> v_lld;
typedef vector<llu> v_llu;
typedef pair<int, int> p_int;
typedef pair<lld, lld> p_lld;


#define   INDEPENDENT_CASES()  cin >> (T3X0); T353 = T3X0; while(T3X0--)
#define          _input(V3C0)  for(auto &V3C0_IT7 : (V3C0)) cin >> (V3C0_IT7)
#define     mems(A77AY, V4LU)  memset((A77AY), (V4LU), sizeof((A77AY)))
#define   CH3K(IT7, EN4, S7P)  (((S7P)<0) ? (IT7)>(EN4) : (IT7)<(EN4))
#define for4(IT7,ST4,EN4,S7P)  for(auto IT7=(ST4); CH3K(IT7,EN4,S7P); (IT7)+=(S7P))
#define    FORE4CH(IT7, V3C0)  for(auto IT7=(V3C0).begin(); IT7!=(V3C0).end(); IT7++)


// template<typename T> void _SC4N(T &x) { 
//     x = 0; bool neg = 0; 
//     register T c = getchar();
//     if (c == '-') neg = 1, c = getchar();
//     while ((c < 48) || (c > 57)) c = getchar();
//     for ( ; c < 48||c > 57 ; c = getchar());
//     for ( ; c > 47 && c < 58; c = getchar() ) x= (x << 3) + ( x << 1 ) + ( c & 15 );
//     if (neg) x *= -1;
// }





void solveEachTest(lld T35TC453N = 1) {
    // auto S34t = chrono:: high_resolution_clock::now(); 

    lld n; cin >> n;
    string a, b;
    cin >> a >> b;
    lld j = 0;
    for4(i, 0LL, n, 1LL) {
        if(a[i] == b[j]) j++;
        else{
            j=0;
            if (a[i] == b[j]) j++;
        }
    }

    cout << 2 * n - j;

    cout << "\n"; 

    // auto S34p = chrono::high_resolution_clock::now(); 
    // auto D34n = chrono::duration_cast<chrono::microseconds>(S34p - S34t);
    // cout << "Time Elapsed: " << D34n.count() / (long double) 1e6 << " seconds" << endl; 
    return;
}


signed main() {

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

    lld T3X0 = 0, T353 = 1;

    // INDEPENDENT_CASES()
        solveEachTest(T353 - T3X0);
    return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}


int main() {
    ll n, m;
    cin >> n >> m;
    if (n == 1 and m == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (n == 1) {
        cout << max(0LL, m-2) << endl;
        return 0;
    }
    else if (m == 1) {
        cout << max(0LL, n-2) << endl;
        return 0;
    }
    else if (n == 2 or m == 2) {
        cout << 0 << endl;
        return 0;
    }
    else {
        cout << max(n*m - 2*n - 2*m + 4, 0LL) << endl;
        return 0;
    }
}


Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	int N;
	long K;
	int []A;
	Integer[] F;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		N = nextInt();
		K = nextLong();
		A = new int[N];
		long S = 0;
		for (int i=0;i<N;i++) {
			A[i] = nextInt();
			S+=A[i];
		}
		F = new Integer [N];
		for (int i=0;i<N;i++) {
			F[i] = nextInt();
		}
		if(S<=K) {
			out.println(0);
			return;
		}

		Arrays.sort(A);
		Arrays.sort(F, Collections.reverseOrder());
		long mi = 1L<<60;

		for(int i=59;i>=0;i--) {
			if(ok(mi-(1L<<i))) mi-=1L<<i;
		}
		out.println(mi);
	}

	boolean ok(long v) {
		long sum=0;
		for(int i=0;i<N;i++) {
			long ma=v/F[i];
			if(ma<A[i]) sum+=A[i]-ma;
			if(sum>K) return false;
		}
		return true;
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

	long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}
}

Measured memory_bytes: 68648
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 要素の入力、格納
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int ans = 0;

		for (int i = 0; i <= X / 500; i++) {
			if (i > A) {
				continue;
			}
			for (int j = 0; j <= (X - i * 500) / 100; j++) {
				if (j > B) {
					continue;
				}
				if ((X - i * 500 - j * 100) / 50 <= C) {
					ans++;
				}
			}
		}

		// 出力
		System.out.println(ans);
	}
}


Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <limits>

#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;
typedef long long int lli;


int main(void)
{
	int D, N; cin >> D >> N;
	lli ans = pow(100, D)*(N != 100 ? N : 101);
	cout << ans << endl;

	return 0;
}

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

string Y = "Possible";
string N = "Impossible";

int a[110];
int cnt[110] = {};
int main(){
    int n;
    cin >> n;

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

    sort(a, a+n);

    if(a[n-1] % 2 == 0){
        int c = 0;
        for(int i = a[n-1];i > a[n-1]/2;i--){
            if(cnt[i] < 2){
                cout << N << endl;
                return 0;
            }
            c += cnt[i];
        }
        if(cnt[a[n-1]/2] == 1 && c+1 == n){
            cout << Y << endl;
        }else{
            cout << N << endl;
        }
    }else{
        int c = 0;
        for(int i = a[n-1];i > a[n-1]/2+1;i--){
            if(cnt[i] < 2){
                cout << N << endl;
                return 0;
            }
            c += cnt[i];
        }
        if(cnt[a[n-1]/2+1] == 2 && c+2 == n){
            cout << Y << endl;
        }else{
            cout << N << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> p(n);
    vector<vector<int>> A(n,vector<int> (m));
    
    for(int i = 0; i < n; i++) {
        cin >> p.at(i);
        for(int j = 0; j < m; j++) {
            cin >> A.at(i).at(j);
        }
    }
    int minp = 10000000;
    
    for(int tmp = 0; tmp < (1 << 12); tmp++) {
        int price = 0;
        vector<int> r(m);
        bitset<12> s(tmp);
        for(int i = 0; i < n; i++) {
            if(s.test(i)) {
                price += p.at(i);
                for(int j = 0; j < m; j++) {
                    r.at(j) += A.at(i).at(j);
                }
            }
        }
        bool b = true;
        for(int i = 0; i < m; i++) {
            if(r.at(i) < x) b = false;
        }
        if(b && price < minp) {
            minp = price;
        }
    }

    if(minp == 10000000) {
        cout << -1;
    }
    else cout << minp;
}

Measured memory_bytes: 3632