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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

//文字から数値に変換
int getChar(char ch){
    if(ch=='A') return 1;
    else if(ch=='C') return 2;
    else if(ch=='G') return 3;
    else if(ch=='T') return 4;
    else return 0;
}

//文字列から数値へ変換してkeyを生成する
long long getKey(char str[]){   // long long = long long int のこと　intは省略可能
    long long sum=0,p=1,i;
    for(i=0;i<strlen(str);i++){
        sum+=p*(getChar(str[i]));
        p*=5;   //4文字だから？
    }
    return sum;
}

int h1(int key){return key%M;}
int h2(int key){return 1+(key%(M-1));}

int find(char str[]){
    long long key,i,h;
    key = getKey(str); //文字列を数値に変換
    for(i=0;;i++){
        h = (h1(key) + i*h2(key)) % M;
        if(strcmp(H[h],str)==0) return 1;
        else if(strlen(H[h])==0) return 0;
    }
    return 0;
}

int insert(char str[]){
    long long key,i,h;
    key = getKey(str); //文字列を数値に変換
    for(i=0;;i++){
        h = (h1(key) + i*h2(key)) % M;
        if(strcmp(H[h],str)==0) return 1;
        else if(strlen(H[h])==0){
            strcpy(H[h],str);
            return 0;
        }
    }
}

int main(void){
    int i,n,h;
    char str[L],com[9];
    for(i=0;i<M;i++) H[i][0]='\0';
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s %s",com,str);
        if(com[0]=='i'){
            insert(str);
        }else{
            if(find(str)){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
    return 0;
}



Measured memory_bytes: 16044
#include <set>
#include <cstring>
#include <vector>
#include <iostream>
using namespace std;

class UnionFind {
    vector<int> par, rank;
public:
    explicit UnionFind(int n) : par(n), rank(n) {
        for (int i = 0; i < n; i++) { par[i] = i; rank[i] = 0; }
    }

    int find(int i) {
        if (par[i] == i) return i;
        return par[i] = find(par[i]);
    }

    void unite(int i, int j) {
        int x = find(i), y = find(j);
        if (x != y) {
            if (rank[x] < rank[y])
                par[x] = y;
            else {
                par[y] = x;
                if (rank[x] == rank[y]) rank[x]++;
            }
        }
    }
};

int main() {
    long long n, m, q; cin >> n >> m >> q;
    vector<pair<int, int> > v;
    UnionFind uf(n);
    while (q--) {
        int a, b, c; cin >> a >> b >> c;
        if (c == 0) {
            uf.unite(a, b);
        } else v.push_back({a, b});
    }
    long long n_comp = 0;
    for (int i = 0; i < n; i++)
        if (uf.find(i) == i) n_comp++;
    UnionFind uf2(n);
    set<int> S;
    for (auto e : v) {
        int a = uf.find(e.first), b = uf.find(e.second);
        if (a == b) { cout << "No\n"; return 0; }
        uf2.unite(a, b);
        S.insert(a); S.insert(b);
    }
    if (S.size() == 2 && n_comp == 2) { cout << "No\n"; return 0; }
    long long e_min = n - n_comp + (S.size() == 0 ? 0 : max(int(S.size()), 3)),
        e_max = n - n_comp + n_comp * (n_comp - 1) / 2;
    cout << (e_min <= m && m <= e_max ? "Yes\n" : "No\n");
}


Measured memory_bytes: 7284
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
using namespace std;

#define max_n 1000
#define max_m 50
#define max_w 1000
#define max_h 1000
#define max_k 5000
#define max_l 10000
#define INF 9999999

typedef long long lint;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a<=c&&c<=b){
        cout<<"Yes"<<endl;
        
    }else{
        cout<<"No"<<endl;
    }
    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

signed main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	string ans;
	cin >> n;
	if(n < 105) ans = "0";
	elif(n < 135) ans = "1";
	elif(n < 165) ans = "2";
	elif(n < 189) ans = "3";
	elif(n < 195) ans = "4";
	else ans = "5";

	cout << ans << endl;
	rtn 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {

  int n, m;
  cin >> n >> m;
  vec1 h(n);
  for(int i = 0; i < n; i++) cin >> h.at(i);
  vec1 a(n);
  for(int i = 0; i < m; i++) {
    int c, d;
    cin >> c >> d;
    if(h.at(c-1) == h.at(d-1)) {
      a.at(c-1)++;
      a.at(d-1)++;
      continue;
    }
    int b = min(h.at(c-1),h.at(d-1));
    if(b == h.at(c-1)) {
      a.at(c-1)++;
    } else {
      a.at(d-1)++;
    }
  }
  int ans = 0;
  for(int i = 0; i < n; i++) {
    if(a.at(i) == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4052
/*------------
Name: Mohamed Anas
Program Description: Dp implementation of frog jumping
-----*/
#include<stdio.h>
#define LARGE 1000000000;
int* h;
int* dp;
int N;
int K;
int min(int a,int b){
	if(a<b)return a;
	else return b;
}
int absolute(int a){
	if(a<0)return -a;
	else return a;
}
int min_cost(int n){
	
		for (int i = 2; i<=N; ++i)
		{ for (int j = 1; j<=K; ++j)
		{
			if(i-j>0)dp[i]=min(dp[i],dp[i-j]+absolute(h[i]-h[i-j]));
			//if(j<=N)dp[j]= min(dp[j],dp[i]+absolute(h[i]-h[j]));
		}
		//printf("dp[%d] = %d\n",n,dp[n] );
		}
		return dp[n];
	
}

int main(){
	scanf("%d",&N);
	scanf("%d",&K);
	h = (int*)malloc(sizeof(int)*(N+2));
	dp = (int*)malloc(sizeof(int)*(N+2));
	for (int i = 0; i < N+2; ++i)
	{	dp[i]=LARGE;
		/* code */
	}
	dp[1]=0;
	for (int i = 1; i < N+1;++i)
	{
		scanf("%d",&h[i]);

	}
	h[0]=0;
	//printtall();
	printf("%d",min_cost(N));
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int ddx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1};

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

int extgcd(int a, int b, int& x, int&y) {
    int d = a;
    if(b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else {
        x = 1;
        y = 0;
    }
    return d;
}

int inv(int a) {
    int x, y;
    extgcd(a, MOD, x, y);
    return (x + MOD) % MOD;
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    ll ans = 0;
    for(ll i = 2; i * i <= g; i++) {
        if(g % i == 0) {
            ans++;
            while(g % i == 0) g /= i;
        }
    }
    if(g > 1) ans++;
    cout << ans + 1 << endl;
}


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


void main() {
    int a, b;
    scan(a, b);
    if (a == 1) a = 14;
    if (b == 1) b = 14;
    if (a < b) {
        writeln("Bob");
    }
    else if (a > b ) {
        writeln("Alice");
    }
    else {
        writeln("Draw");
    }
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define MAX 200005
#define INF 200005

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  int pre=s[0];
  int ans=1;
  repo(i, n-1){
    if(pre!=s[i]){
      ans++;
      pre=s[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,c = 0,a = 0,b = 0,ba = 0,i;string s;cin >> n;
  while(cin >> s){
    for(i=0;i<s.size()-1;i++){
      if(s.substr(i,2) == "AB") c++;
    }
    if(s[0]=='B' && s[s.size()-1]=='A') ba++;
    else if(s[s.size()-1]=='A') a++;
    else if(s[0]=='B') b++;
  }
  if(ba>0) c += ba-1;
  if(ba>0 && a>0){
    c++;a--;
  }
  if(ba>0 && b>0){
    c++;b--;
  }
  c += min(a,b);
  cout << c << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,i;
  cin>>N;
  vector<int> vec(N);
  for(i=0;i<N;i++){
    cin>>vec.at(i);
  }
  int max=0;
  for(i=0;i<N;i++){
    if(max<=vec.at(i)){
      max=vec.at(i);
    }
  }//max定義
  int c=0,submax=0,h=0;
  while(c==0){
    c++;
    for(i=0;i<N;i++){
      if(max>vec.at(i) && submax<=vec.at(i)){
        submax=vec.at(i);
      }
    }//submax定義
    for(i=0;i<N;i++){
      if(submax==vec.at(i)){
        c=0;
        max=submax;
        submax=0;
        h++;
        break;
      }
    }
  }
  cout<<h+1<<endl;
}
      

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
signed main()
{
	long long n, x;
	std::cin >> n >> x;
	std::vector<long long>a(n);
	std::vector<std::vector<long long>>minimum_time(n + 1, std::vector<long long>(n));
	for (long long i = 0; i < n; i++)
	{
		std::cin >> a[i];
		minimum_time[0][i] = a[i];
	}
	long long ans = 10000000000000000;
	for (long long i = 0; i < n; i++)
	{
		long long sum = i * x;
		for (long long j = 0; j < n; j++)
		{
			sum += minimum_time[i][j];
			minimum_time[i + 1][j] = std::min(minimum_time[i][j], minimum_time[i][(j - 1 + n) % n]);
		}
		if (ans > sum)
		{
			ans = sum;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 31616
#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int64_t A, B, C, K;
  cin >> A >> B >> C >> K;
  if (K <= (A + B)) {
    if (A <= K) {
      cout << A << endl;
    } else {
      cout << K << endl;
    }
    return 0;
  }
  K -= (A + B);
  cout << (A - K) << endl;

  return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<limits.h>
#define MAX 101

int p[300];
int m[MAX][MAX];

void matrixChainOrder(int n){
  int l,i,j,k,q;

  for(i=1;i<=n;i++)m[i][i]=0;

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=INT_MAX;

      for(k=i;k<=j-1;k++){
	q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	if(m[i][j]>q)m[i][j]=q;
      }
      
    }
  }
  
  
}

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

  for(i=0;i<n;i++){
    scanf("%d%d",&a,&b);
    if(i!=n-1)p[i]=a;
    else {
      p[i]=a;
      p[i+1]=b;
    }
  }

  matrixChainOrder(n);

  printf("%d\n",m[1][n]);
  return 0;
}



Measured memory_bytes: 2112
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言

void solve();

int a, b, c;

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

  solve();

  return 0;
}

void solve() {

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

  return;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int,int> P;
int N,M,q,a,b,u[100010],c[100010],d[100010];

int dp[100010][11] = {{0}};
vector<vector<int>> v(100010);


void bfs(int n,int d,int time){
	queue<P> Q;
	Q.push({n,d});
	for(int j=0;j<=d;j++){
		if(dp[n][j]==0) dp[n][j] = c[time];
	}
	while(!Q.empty()){
		P p = Q.front();
		int t = p.first,e = p.second;
		Q.pop();
		for(int i=0;i<v[t].size();i++){
			if(dp[v[t][i]][e-1]==0){
				for(int j=0;j<=e-1;j++){
					if(dp[v[t][i]][j]==0) dp[v[t][i]][j] = c[time];
				}
				if(e>1) Q.push({v[t][i],e-1});
			}
		}
	}
}

int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	cin >> q;
	for(int i=1;i<=q;i++){
		cin >> u[i] >> d[i] >> c[i];
	}
	for(int i=q;i>=1;i--){
		bfs(u[i],d[i],i);
	}
	for(int i=1;i<=N;i++){
		cout << dp[i][0] << endl;
	}
}


Measured memory_bytes: 12424
#include<bits/stdc++.h>
#define for(i,a,b) for(int i=a;i<=b;i++)
#define _inline __inline__ __attribute__((always_inline))
using namespace std;
_inline void read(int &x){
	int res=0,f=1;
	char c=getchar();
	if(c=='-') f=-1;
	while(c>'9'||c<'0') c=getchar();
	while(c>='0'&&c<='9'){
		res=res*10+c-'0';
		c=getchar();
	}
	x=res*f;
}
inline void print(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
int main(){
    int x,a,b,c,ans=0;
    read(a),read(b),read(c),read(x);
    for(i,0,a)
        for(j,0,b)
            for(z,0,c){
                int k=i*500+j*100+z*50;
                if(k==x) ans++;
                if(k>x) break;
            }
    print(ans),puts("");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;

void faster()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const ll MAXN = 1e6 + 10;
const ll N = 4000 + 10;
const ll MN = 200 + 10;
const ll mod = 1e6;

ll a[MAXN];
vector <int> p;

bool prime (int n)
{
	for (int i = 2; i * i <= n; i++)
		if(n % i == 0)
			return false;
	return true;
}

int main()
{
	faster();
	int n;
	cin >> n;
	for (int i = 2; p.size() < n; i++)
	{
		if(prime(i) && i % 5 == 1)
			p.push_back(i);
	}
	for (auto u : p)
		cout << u << " ";
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <math.h>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
#pragma GCC optimize ("-O3")
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
#define tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define ll long long int
ll max(ll a, ll b) {  return a > b ? a : b; }
ll gcd(ll a, ll b) { if (a == 0) return b; return b == 0 ? a : gcd(b, a % b);}
#define case(i) cout<<"Case #"<<i<<": ";
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
#define debug2(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
void err(istream_iterator<string> it, T a, Args... args) { cerr << "[ " << *it << " = " << a << " ]"; err(++it, args...);}
#define time__(d) for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); blockTime.second; debug2("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
#define pii pair <ll , ll >
#define pb push_back
#define PRECISION 10
const ll inf = 9223372036854775800;
const int MAXN = 100001;
const int LOGN = 22;
const int MAXBIT = 62;
const long double PI = 3.141592653589793;
const int DIGITSIZE = 18;
ll mod = 1e9 + 7;
ll MOD = 998244353;
int x4[] = {1, -1, 0, 0};
int y4[] = {0, 0, 1, -1};
int x8[] = {1, 1, 1, -1, -1, -1, 0, 0};
int y8[] = {1, 0, -1, 1, 0, -1, 1, -1};
bool takeTestCases = 0;
bool printCaseNo = 0;

void getac(int T) {
    char c;
    cin>>c;
    if(c>='A'&& c<='Z'){
        cout<<"A";
    }else{
        cout<<'a';
    }
}
int  main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
//     freopen("error.txt", "w", stderr);
// #endif
    fastio;
    int t = 1;
    if (takeTestCases) cin >> t;
    int t_t = 1;
    while (t--) {
        if (printCaseNo)
        case (t_t);
        getac(t_t);
        t_t++;
    }
    cerr << "Total time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 3804
#include <iostream>
using namespace std;
int main()
{
    int a[7]={1,3,5,7,8,10,12};
    int b[4]={4,6,9,11};
    int c[1]={2};

    int x,y;
    cin>>x>>y;
    int f=0,d=0,e=0;
    for(int i=0;i<7;i++){
        if(x==a[i])f++;
        if(y==a[i])f++;
    }
    for(int i=0;i<4;i++){
        if(x==b[i])d++;
        if(y==b[i])d++;
    }
    if(x==c[0]||y==c[0])e++;
    if(f==2||d==2)cout<<"Yes\n";
    else cout<<"No\n";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node {
	int key;
	struct node *n;
	struct node *p;
} Node;

Node *nil;

Node *search(int key) {
	Node *res = nil->n;
	while (res != nil && res->key != key) res = res->n;
	return res;
}

void init() {
	nil = (Node *)malloc(sizeof(Node));
	nil->n = nil;
	nil->p = nil;
}

void print() {
	Node *res = nil->n;
	int i;
	while (1) {
		if (res == nil) break;
		if (i++ > 0) printf(" ");
		printf("%d", res->key);
		res = res->n;
	}
	printf("\n");
}

void delete(Node *t) {
	if (t == nil) return;
	t->p->n = t->n;
	t->n->p = t->p;
	free(t);
}

void deleteFirst() {
	delete(nil->n);
}

void deleteLast() {
	delete(nil->p);
}

void deleteKey(int key) {
	delete(search(key));
}

void insert(int key) {
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->n = nil->n;
	nil->n->p = x;
	nil->n = x;
	x->p = nil;
}

int main() {
	int i,n;
	int key;
	char com[20];

	scanf("%d", &n);

	init();
	for (i=0;i<n;i++) {
		scanf("%s %d",com,&key);
		if (com[0] == 'i') {
			insert(key);
		}
		else  {
			if (strlen(com) > 6) {
				if (com[6] == 'F') deleteFirst();
				else if (com[6] == 'L') deleteLast();
			}
			else {
				deleteKey(key);
			}
		}
	}

	print();

	return 0;
}

Measured memory_bytes: 31784
#include <iostream>
#include <algorithm>
#include <vector>

int main()
{
  int h, w;
  std::cin >> h >> w;
  for (int i = 0; i < h; ++i)
  {
    std::string row;
    std::cin >> row;
    std::cout << row << std::endl << row << std::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 K;
    cin >> K;

    rep(i,K) {
        cout << "ACL";
        if (i==K-1) {
            cout << endl;
        }
    }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;

class Dijkstra
{
    int V;
    double inf;
    vector<double> distance;
    double eps;
public:
    vector<vector<double> > e;
    Dijkstra(int V, double inf) : V(V), inf(inf), eps(1E-5)
    {
        e = vector<vector<double> >(V, vector<double>(V, inf));
        for (int i=0; i<V; i++) e[i][i] = 0;
    }
    void update_edge(int v1, int v2, double d)
    {
        e[v1][v2] = e[v2][v1] = min(e[v1][v2], d);
    }

    double dijkstra(int from, int to)
    {
        distance = vector<double>(V, inf);
        using Pque = pair<double, int>;
        priority_queue<Pque, vector<Pque>, greater<Pque> > que;
        que.push(make_pair(0.0, from));
        while (true)
        {
            int now = que.top().second;
            double dist_tmp = que.top().first;
            if (now == to) return dist_tmp;
            que.pop();

            if (distance[now] > dist_tmp + eps)
            {
                distance[now] = dist_tmp;
                for (int i=0; i<V; i++)
                {
                    if (i == now) continue;
                    if (distance[i] > distance[now] + e[now][i] + eps)
                    {
                        que.push(make_pair(distance[now] + e[now][i], i));
                    }
                }
            }
        }
    }
};

int N;
lint xs, ys, xt, yt;
vector<int> r;
vector<P> x;

double d(P p1, P p2)
{
    return sqrt((double)((p1.first - p2.first) * (p1.first - p2.first) + (p1.second - p2.second) * (p1.second - p2.second)));
}

int main()
{
    cin >> xs >> ys >> xt >> yt >> N;
    r.resize(N);
    x.resize(N);
    for (int i=0; i<N; i++) cin >> x[i].first >> x[i].second >> r[i];

    Dijkstra dij(N+2, 1E10);
    for (int i=0; i<N; i++)
    {
        dij.update_edge(i+1, 0, max(d(make_pair(xs, ys), x[i]) - r[i], 0.0));
        dij.update_edge(i+1, N+1, max(d(make_pair(xt, yt), x[i]) - r[i], 0.0));
        for (int j=0; j<i; j++)
        {
            dij.update_edge(i+1, j+1, max(0.0, d(x[i], x[j]) - r[i] - r[j]));
        }
    }
    dij.update_edge(0, N+1,
     d(make_pair(xs, ys), make_pair(xt, yt)));

    cout << setprecision(11) << dij.dijkstra(0, N+1) << endl;
}


Measured memory_bytes: 18544
### C
from itertools import combinations
from math import factorial
from scipy.misc import comb

N = int(input())

x = []
y = []
for i in range(N):
    tmp = list(map(int, input().split()))
    x.append(tmp[0])
    y.append(tmp[1])

len_all = 0
for i, j in combinations(range(N), 2):
    len_all += ((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5
one_ave = len_all / comb(N,2)

print(one_ave*(N-1))

Measured memory_bytes: 16124
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値
#define _ceil(x) ceil(x)

int main()
{
	char c[3] = { 0 };
	char temp;
	uint32_t i;
	for (i = 0; i < 3; i++) {
		cin >> temp;
		if (c[temp - 'a']) {
			break;
		}
		c[temp - 'a']++;
	}
	if (i >= 3) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
	//	std::cout << "Hello World!\n"; 
}


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

int main(void) {
	// in
	int n;
	std::cin >> n;
	std::vector<int> d(n);
	for(int i = 0; i < n; ++i) std::cin >> d[i];
	
	// sort
	std::sort(d.begin(), d.end());
	
	int n_choice = 0;
	if(n % 2 == 1) {
		n_choice = 0;
	}
	else {
		// median
		int d_med1 = d[n/2 - 1];
		int d_med2 = d[n/2];
		n_choice = d_med2 - d_med1;
	}

	std::cout << n_choice << std::endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main()
{
  int n,x;
  int min=1000001,max=-1000001;
  long sum=0;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    cin>>x;
    if(x>max) max=x;
    if(x<min) min=x;
    sum+=x;
  }
  cout<<min<<' '<<max<<' '<<sum<<endl;
}

Measured memory_bytes: 3092
solve :: [Int] -> Int
solve [] = 0
solve (n:ns) = let (ded,x) = solve1 ns
               in n - ded + x

solve1 [] = (0,0)
solve1 (n:ns) = let (ded,x) = solve1 ns
                in if (ded == 0 && n == 9) then (0, 9+x)
                   else (1, 9+x)


main :: IO ()
main = do
  cont <- getContents
  let [s] = words cont
  let ns = map (read . (\c -> [c])) s
  putStrLn (show (solve ns))
  


Measured memory_bytes: 508
#include<stdio.h>
int main(){
    int a[33]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    scanf("%d",&k);
    printf("%d\n",a[k-1]);
    return 0;
}

Measured memory_bytes: 128
import itertools

input()

l = list(map(int, input().split()))

ans = 0
for a,b,c in itertools.combinations(l, 3):
    if a == b or b == c or c == a:
        continue
    if a+b>c and b+c>a and c+a>b:
        ans+=1

print(ans)

Measured memory_bytes: 9212
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();

        if (n < k)
        {
            long candidate = Math.abs(n-k);
            long candidate2 = Math.abs(candidate-k);
            System.out.println(Math.min(candidate,candidate2));
        }
        else
        {
            if (n%k == 0) System.out.println(0);
            else
            {
                long candidate = n%k;
                long candidate2 = Math.abs(candidate-k);
                System.out.println(Math.min(candidate,candidate2));
            }
        }

        sc.close();
    }
}

Measured memory_bytes: 21716
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define int long long
using namespace std;


int dp[105][200005];
int mod=1e9+7;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
// #ifndef ONLINE_JUDGE
//    freopen ("INPUT.txt" , "r" , stdin);
//    freopen ("OUTPUT.txt" , "w" , stdout);
// #endif

    clock_t clk;
	clk = clock();

// --------------Code starts here---------------------------------------------------------------------

    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    dp[0][0]=1;

    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=k;j++)
        {
            dp[i][j]=(dp[i][j]+dp[i-1][j]+mod)%mod;
            dp[i][j+a[i]+1]=(dp[i][j+a[i]+1]+mod-dp[i-1][j]);
        }

        for(int j=1;j<=k;j++)
        {
            dp[i][j]+=dp[i][j-1];
            dp[i][j]%=mod;
        }
    }
    cout<<dp[n][k];

// -------------------------------------Code ends here------------------------------------------------------

    clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}


Measured memory_bytes: 158464
a, b, c = map(int, input().split())
d, e, f = map(int, input().split())
g, h, i = map(int, input().split())
n = int(input())
for j in range(n):
    x = int(input())
    if a == x:
        a = 0
    elif b == x:
        b == 0
    elif c == x:
        c = 0
    elif d == x:
        d = 0
    elif e == x:
        e = 0
    elif f == x:
        f = 0
    elif g == x:
        g = 0
    elif h == x:
        h = 0
    elif i == x:
        i = 0
y =[[a, b, c], [d, e, f], [g, h, i], [a, d, g], [b, e, h], [c, f, i], [a, e, i], [c, e, g]]
print("Yes" if [0, 0, 0] in y else "No")

Measured memory_bytes: 9144
//#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 100;
const ll mod = 1e9 + 7;
ll ans;
int n;
int a[N],b[N],v[N];
queue <int> q;
int main()
{
//    freopen("in.txt", "r", stdin);
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
        scanf("%d", a + i);
    for (int i = 0; i < n; ++i)
        scanf("%d", b + i);
    for (int i = 0; i < n; ++i)
        if (b[i] >= b[(i + n - 1) % n] + b[(i + 1) % n])
        {
            q.emplace(i);
            v[i] = 1;
        }
    while (!q.empty())
    {
        int x = q.front();
        q.pop();
        v[x] = 0;
        ll c = (b[x] - a[x]) / (b[(x + n - 1) % n] + b[(x + 1) % n]);
        if (c <= 0 && a[x] != b[x])
        {
            ans = -1;
            break;
        }
        ans += c;
        b[x] -= c * (b[(x + n - 1) % n] + b[(x + 1) % n]);
        int t = (x + n - 1) % n;
        if (!v[t] && b[t] >= b[(t + n - 1) % n] + b[(t + 1) % n])
        {
            v[t] = 1;
            q.emplace(t);
        }
        t = (x + 1) % n;
        if (!v[t] && b[t] >= b[(t + n - 1) % n] + b[(t + 1) % n])
        {
            v[t] = 1;
            q.emplace(t);
        }
    }
    for (int i = 0; i < n; ++i)
        if (a[i] != b[i])
            ans = -1;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 9600
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(void) {
	int W, a, b;
	scanf("%d %d %d", &W, &a, &b);
	if (a + W < b) printf("%d\n", b- (a + W));
	else if (b + W < a) printf("%d\n", a - (b + W));
	else printf("0\n");

	return 0;
}


Measured memory_bytes: 3820
#include <stdio.h>
int main(void){
    int M1,M2,D1,D2;
    scanf("%d %d",&M1,&D1);
    scanf("%d %d",&M2,&D2);
    if(M1==M2){
        printf("0\n");
    }
    else{
        printf("1\n");
    }
}


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

using namespace std;

int main(){
	int d, t, s;
	cin >> d >> t >> s;
	if (t * s >= d) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
int main()
{
  int N,D,p,i=1,q;
  
  scanf("%d",&N);
  scanf("%d",&D);
  
  for(p=1;p<=N/(D*2+1);p++)
  {
    i++;
  }
  
  q=D*2+1;
  
  if((N%q)==0){
    i = i-1;
  }
  
  printf("%d",i);
  
  return 0;
}

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

#define DEBUG (0)

int main()
{
  ll K,N = 0;
  cin >> K >> N;
  
  vector<ll> A(N,0);
  vector<ll> B(N,0);
  ll bmax = 0;
  ll ans = 0;

  
#if DEBUG
//  cout << K << "," << N << endl;
#endif

  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
//  cout << "bmax1:" << bmax << endl;

  for(int i = 0; i < N -1; i++){
    B[i] = A[i+1] - A[i];
  }
//  cout << "bmax2:" << bmax << endl;
  
  B[N-1] = K - A[N-1] + A[0];
//  cout << "bmax3:" << bmax << endl;

  /* Bの最大値 */
#if DEBUG
//  cout << "===bmax===!!!:" << bmax << endl;
#endif
  
#if DEBUG
  for(int i = 0; i < N; i++){
    cout << "A[" << i << "]: " << A[i] << ", " << "B[" << i << "]: " << B[i] << endl;
  }
#endif
  
  for(int i = 0; i < N; i++){
//    cout << "loop:" << i << ",true/false: " << (bmax < B[i]) << ",bmax:" << bmax << endl;
    if(bmax < B[i]){
      bmax = B[i];
#if DEBUG
      cout << "===bmax===:" << bmax << endl;
#endif
    }
  }
  
  ans = K - bmax;
  cout << ans << endl;
  
#if DEBUG
  for(int i = 0; i < N; i++){
    cout << "A[" << i << "]: " << A[i] << ", " << endl;
    cout << "B[" << i << "]: " << B[i] << ", " << endl;
  }
  cout << "bmax:" << bmax << endl;
  cout << "K:" << K << ", bmax:" << bmax <<  ", B[N-1]:" << B[N-1] << endl;
#endif
  
}

Measured memory_bytes: 3328
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <stdio.h>


using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    char moji;
    cin >> s;
    vector<string> a={"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"} ;
    bool f = true;

    for (int i=0;i<s.length();i++){
        string m;
        m = s[i];
        if (a.size() == 1 ){
            if(a[0]==m){
                cout << "None";
                f = false;
            }
        }
        a.erase(remove(a.begin(),a.end(),m),a.end());
    }

    if (f){
    cout << a.front();
    }
    return 0;
}

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

int main () {
	int N;
	cin >> N;
	long long ans = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = i; j <= N; j+=i) {
			ans += j;
		}
	}
	cout << ans << endl;
}


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


// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef complex<int> ci;
typedef complex<double> cd;
typedef complex<long double> cld;

// macros
#define rep(i, a, b) for(int i=a; i<b; i++)
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define tr(c, it) for(auto it=(c).begin(); it!=c.end(); it++)
#define pb push_back
#define mp make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// template functions
template <typename T>
inline void printV(vector<T>& a) { rep(i, 0, sz(a)) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printV(vector<T>& a, int n) { rep(i, 0, n) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printVV(vector<vector<T>>& a)
{
	rep(i, 0, sz(a)) {
		printV(a[i]);
	}
	cout<<"\n";
}

template <typename T>
inline void clearVV(vector<vector<T>>& a)
{
	for(auto& x:a) {
		x.clear();
	}
	a.clear();
}
template <typename T>
inline void assignVV(vector<vector<T>> &a, T val)
{
	for(int i=0; i<sz(a); i++) {
		for(int j=0; j<sz(a[i]); j++) {
			a[i][j]=val;
		}
	}
}

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 5e8;
const int modn = 1e9+7;
const int MAX = 1e5;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
	int n;
	cin>>n;
	vector<int> a(n+1);
	vector<ll> pref(n+1);
	map<ll, int> mm;
	ll ans=0;
	mm[0]=1;
	for(int i=1; i<=n; i++) {
		cin>>a[i];
		pref[i]=pref[i-1]+a[i];
		ans+=mm[pref[i]];
		mm[pref[i]]++;
	}
	cout<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 15104
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
#MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	L,R=map(int,input().split())
	ans=0
	LL, RR = L % 2019, R % 2019
	if R-L<2019 and LL<RR:
		ans=2018
		L,R=L%2019,R%2019
		for i in range(LL,RR):
			j=1
			while i+j<=RR:
				ans=min(ans,(i*(i+j))%2019)
				j+=1
	print(ans)
	





if __name__ == '__main__':
	main()


Measured memory_bytes: 38768
#include <iostream>
int gcd(int a, int b)
{
  while (1) {
    if (b == 0) {
      return a;
    }
    int temp = b;
    b = a % b;
    a = temp;
  }
}

int lcm(int a, int b)
{
  return a / gcd(a, b) * b;
}

int main()
{
  int a, b;
  while (std::cin >> a >> b) {
    std::cout << gcd(a, b) << " " << lcm(a, b) << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n; cin >> n;
  vector<int> v(n);
  ll ans = 1e15;
  rep(i, n) cin >> v[i];
  for(int i = -100; i <= 100; i++){
    ll sum = 0;
    rep(j, n){
      int d = abs(i-v[j]);
      sum += d*d;
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;
  system("pause");
}


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

namespace AtCoderCs
{

    class Program
    {

        const int Mod = 1000000007;

        static void Main()
        {

            var arg = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            Console.WriteLine((arg[2] / arg[1] + (arg[2] % arg[1] == 0 ? 0 : 1)) <= (arg[0] / arg[3] + (arg[0] % arg[3] == 0 ? 0 : 1)) ? "Yes" : "No");

        }


    }
}


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

int main(void){
    int N,count = 0;
    cin >> N;
    int A[N];
    for(int i = 0;i < N;i++){
        cin >> A[i];
    }
    for(int i = 0;i < N;i++){
      		while(A[i]%2 == 0){
            if(A[i]%2 == 0){
                count++;
                A[i] /= 2;
            }
            }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
template <class T> bool chmin(T& a, T b){if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b){if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  int Mx = -1000, My = -1000, mx = 1000, my = 1000;
  for (int i = 0; i < N; i++) 
  {
    int x;
    cin >> x;
    chmax(Mx, x);
    //chmin(mx, x);
  }
  for (int i = 0; i < M; i++) 
  {
    int y;
    cin >> y;
    //chmax(My, y);
    chmin(my, y);
  }
  
  string ans = "War";
  if (Mx < my)
  {
    int Mz = my;
    int mz = Mx + 1;
    //cout << mz << " " << Mz << endl;
    X++;
    if (!(X > Mz || Y < mz)) ans = "No War";
  }
  
  //cout << mx << " " << Mx << " " << my << " " << My << endl;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << endl
#define print10(ele) cout << fixed << setprecision(10) << (ele) << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  int n, m;
  cin >> n >> m;
  lvec x(m);
  REP(i, m) cin >> x[i];
  sort(ALL(x));
  lvec dist(m - 1);
  REP(i, m - 1) {
    ll distance = x[i + 1] - x[i];
    dist[i] = distance;
  }
  sort(RALL(dist));

  ll ans = 0;
  FOR(i, n - 1, m - 1) ans += dist[i];

  print(n >= m ? 0 : ans);
  return 0;
}

Measured memory_bytes: 1792
#https://atcoder.jp/contests/abc138/submissions/8926003

S = input()
T = input()
if not set(T) <= set(S):
    print(-1)
    exit()
now = -1
rep = 0
for t in T:
    now = S.find(t,now+1)
    if now == -1:
        rep += 1
        now = S.find(t)
print(rep*len(S)+now+1)


Measured memory_bytes: 3316
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int H,W;
  cin>>H>>W;
  char A[H][W];
  set<pair<int,int> > s;
  REP(h,H)REP(w,W){
    cin>>A[h][w];
    if(A[h][w]=='#')s.insert(make_pair(h,w));
  }
  int ans=0;
  while(!s.empty()){
    set<pair<int,int> > s1;
    // cerr<<ans<<endl;
    for(auto e:s){
      int h=e.first;
      int w=e.second;
      // cerr<<h<<" "<<w<<endl;
      int i=-1;
      int j=0;
      if(h+i>=0 and h+i<H and w+j>=0 and w+j<W and A[h+i][w+j]=='.'){
        s1.insert(make_pair(h+i,w+j));
        A[h+i][w+j]='#';          
      }
      i=1;j=0;
      if(h+i>=0 and h+i<H and w+j>=0 and w+j<W and A[h+i][w+j]=='.'){
        s1.insert(make_pair(h+i,w+j));
        A[h+i][w+j]='#';          
      }
      i=0;j=-1;
      if(h+i>=0 and h+i<H and w+j>=0 and w+j<W and A[h+i][w+j]=='.'){
        s1.insert(make_pair(h+i,w+j));
        A[h+i][w+j]='#';          
      }
      i=0;j=1;
      if(h+i>=0 and h+i<H and w+j>=0 and w+j<W and A[h+i][w+j]=='.'){
        s1.insert(make_pair(h+i,w+j));
        A[h+i][w+j]='#';          
      }
    }
    s=s1;
    ans++;
  }
  cout<<ans-1<<endl;
  return 0;
}


Measured memory_bytes: 49024
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<utility>
#include<queue>
using namespace std;
#define LL long long
#define INF 9223372036854775807
#define Pl pair<LL, LL>

struct E {//edge from one vartex
	LL t, d;//to/dist
};

LL N, M, C, sum = 0, ans = INF;//[0] to i
bool flg[100001];//is undertown?
vector<Pl> cost;//cost[0] to i/vartex index
vector<E> con[100001];//connection
priority_queue<Pl, vector<Pl>, greater<Pl>> pq;//cost/vartex id

int main() {
	//input
	cin >> N >> M >> C;
	for (int i = 0; i < N; i++) { cost.push_back({ INF, i }); flg[i] = false; }
	for (int i = 0; i < M; i++) {
		LL a, b, d;  cin >> a >> b >> d;  a--; b--;
		sum += d;
		con[a].push_back({ b, d });
		con[b].push_back({ a, d });
	}
	//dijkstra
	pq.push({ 0ll, 0ll });
	while (!pq.empty()) {
		Pl tp = pq.top();
		pq.pop();
		if (cost[tp.second].first == INF) {
			cost[tp.second].first = tp.first;
			for (int i = 0; i < con[tp.second].size(); i++) {
				pq.push({ cost[tp.second].first + con[tp.second][i].d, con[tp.second][i].t });
				//コストが未確定頂点のうち最小のもの+辺のコスト, 辺の先の頂点
			}
		}
	}
	sort(cost.begin(), cost.end());
	//build underway
	for (int i = 0; i < N; i++) {
		flg[cost[i].second] = true;
		//erase road whose destination has underway
		for (int j = 0; j < con[cost[i].second].size(); j++) 
			if (flg[con[cost[i].second][j].t]) sum -= con[cost[i].second][j].d;
		ans = min(ans, sum + cost[i].first * C);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 21380
//#pragma GCC optimize "trapv"
//-D_GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define Max 100000+5
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f first
#define s second
#define pb push_back
int mod = 1000000007;
int mod1 = 998244353;
vector<int> g[Max];
bool vis[Max];
int d, x, y;
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
void ex(int A, int B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        ex(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}


void dfs(int u){

	vis[u]=1;
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(vis[v]!=1)
			dfs(v);
	}
}



int power(int a,int b){
    if(b==1)return a;
    if(a>mod)a%=mod;
    int r=1;
    while(b){
        if(b&1)r=r%mod*a%mod;
        a=a%mod*a%mod;
        b/=2;
    }
    return r;
}
class uf{
    vector<int> v;
    vector<int> sz;
    
    
    public :
    uf(int n){
        v.resize(n+1);
        iota(v.begin()+1,v.end(),1);
        sz.resize(n+1,1);
        //1 to sz
    }
    int root(int b){
        while(v[b]!=b){
            b = v[b];
        }   
        return b;
    }
    void u(int a, int b){
        //combine a and b
        
        int ra=root(a);
        int rb=root(b);
        if(ra==rb)return ;
        if(sz[ra]<sz[rb]){
            v[ra] = v[rb];
            sz[rb]+=sz[ra];
        }else{
            v[rb]=v[ra];
            sz[ra]+=sz[rb];
        }
    }
    bool f(int a,int b){
        //same set
        return (root(a)==root(b));
    }
   
    
};
vector<int> matmul(vector<int> a,vector<int> b){
    vector<int> c(4,0);
    c[0] = (a[0]%mod*b[0]%mod + a[1]%mod*b[2]%mod)%mod;
    c[1] = (a[0]%mod*b[1]%mod + a[1]%mod*b[3]%mod)%mod;
    c[2] = (a[2]%mod*b[0]%mod + a[3]%mod*b[2]%mod)%mod;
    c[3] = (a[2]%mod*b[1]%mod + a[3]%mod*b[3]%mod)%mod;
    return c;
}
vector<int> id={1,0,0,1};

int32_t main(){
	IO
	//freopen("input.txt","r",stdin);
    	//freopen("output.txt","w",stdout);
	int n,k;
  	cin>>n>>k;
  	vector<int> v(n+1);
  	for(int i=1;i<=n;i++)cin>>v[i];
  	int c=0;
  	for(int i=1;i<=k;i++)c+=v[i];
  	int ans=c;
  	
  	for(int i=k+1,j=2;i<=n;i++,j++){
     int nsum = c + v[i]-v[j-1];
     
     ans=max(ans,nsum);
     c = nsum;
    //  cout<<ans<<endl;
    }
    
  	cout<<fixed<<setprecision(6)<<(1.0*ans+k)/2.0;
}


Measured memory_bytes: 7092
#include<atcoder/all>
#include<bits/stdc++.h>

using namespace std;
using namespace atcoder;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  dsu d(n);
  int a[n];
  int ans[n];
  rep(i,n){
    int x,y;
    cin>>x>>y;
    a[x-1]=y-1;
    ans[i]=x-1;
  }
  stack<int> st;
  rep(i,n){
    // cout<<a[i]<<" ";
    if(st.empty() ){
      st.push(a[i]);
    }else{
      int num=st.top();
      if(num<a[i]){
	d.merge(a[i],num);
	st.pop();
	while(!st.empty() && st.top() < a[i]){
	  d.merge(st.top(),a[i]);
	  st.pop();
	}
	st.push(num);
      }else{
	st.push(a[i]);
      }
    }
    
    
   
  }
  // cout<<endl;
  rep(i,n){
    cout<<d.size(a[ans[i]])<<endl;
  }
	   
  

    
  return 0;
}


Measured memory_bytes: 7176
#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 main() {
  int n;
  string s;
  cin >> n >> s;
  
  int turn = 0;
  for (int i = 1; i < n; ++i) if (s[i] == 'E') ++turn;
  int min_turn = turn;
  for (int i = 1; i < n; ++i) {
    if (s[i] == 'E') --turn;
    if (s[i-1] == 'W') ++turn;
    min_turn = min(min_turn, turn);
  }
  cout << min_turn << endl;
  return 0;
}

Measured memory_bytes: 3904
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl

int n,q;
ll a[100005];
ll b[100005];
ll so[100005],se[100005];
int in[100005];
int qur[100005];

bool check(int x,int i)
{
	int diff=abs(a[i-1]-x);
	int j=lower_bound(a+1,a+n+1,x-diff)-a;
	return (i-j>n-i+1);
}

ll solve(int x)
{
	ll ans=0;
	int l=upper_bound(a+1,a+n+1,x)-a,r=n+1;
	int mid=(l+r)>>1;
	while(r-l>1)
	{
		if(check(x,mid))
			r=mid;
		else
			l=mid;
		mid=(l+r)>>1;
	}
	while(mid>1&&check(x,mid))mid--;
	while(mid<n&&!check(x,mid+1))
		mid++;
	mid=min(mid,n);
	ans=b[n]-b[mid-1];
	int cnt=n-mid+1;
	if((n-2*cnt)%2)
		return ans+so[n-2*cnt];
	return ans+se[n-2*cnt];
}

int main()
{
	SPEED;
	cin>>n>>q;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i],b[i]=a[i]+b[i-1];
		so[i]+=so[i-1];
		se[i]+=se[i-1];
		if(i%2)
			so[i]+=a[i];
		else
			se[i]+=a[i];
	}
	for(int i=1;i<=q;i++)
		cin>>qur[i];
	for(int i=1;i<=q;i++)
		cout<<solve(qur[i])<<endl;
	return 0;
}

Measured memory_bytes: 5248