akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const int N = 15;

int cnt[N];
vi loc[N];

int main(){
    fIO

    int n;
    cin >> n;

    string s;
    cin >> s;

    int idx = 0;
    for(auto let : s) {
        cnt[let - '0']++;
        loc[let - '0'].pb(idx++);
    }

    ll ans = 0;
    for(int i = 0; i <= 9; i++) {
        if(cnt[i] == 0) continue;
        cnt[i]--;
        int near = loc[i][0];
        for(int j = 0; j <= 9; j++) {
            if(cnt[j] == 0) continue;
            auto it = upper_bound(all(loc[j]), near);
            if(it == loc[j].end()) continue;
            int nearj = *it;
            cnt[j]--;
            for(int k = 0; k <= 9; k++) {
                if(cnt[k] == 0) continue;
                auto it2 = upper_bound(all(loc[k]), nearj);
                if(it2 == loc[k].end()) continue;
                //cout << i << " " << j << " " << k << "\n";
                ans++;
            }
            cnt[j]++;
        }
        cnt[i]++;
    }
    cout << ans;


}








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

const int N = 1000000;

int ch[26][N + 5], cnt[N + 5], sum[N + 5], ncnt;

int tot[26][N + 5];

long long ans;

void dfs(int x) {
	if( !x ) return ;
	for(int i=0;i<26;i++)
		dfs(ch[i][x]), sum[x] += sum[ch[i][x]];
	sum[x] += cnt[x];
		
	for(int i=0;i<26;i++) for(int j=0;j<26;j++)
		if( ch[j][x] && i != j ) tot[i][x] += tot[i][ch[j][x]];
	for(int i=0;i<26;i++) if( ch[i][x] ) tot[i][x] += sum[ch[i][x]];
	for(int i=0;i<26;i++) if( ch[i][x] && cnt[ch[i][x]] )
		ans += 1ll * cnt[ch[i][x]] * tot[i][x];
}

void insert(char *s, int n) {
	int nw = 0;
	for(int i=0;i<n;i++) {
		if( ch[s[i] - 'a'][nw] == 0 )
			ch[s[i] - 'a'][nw] = (++ncnt);
		nw = ch[s[i] - 'a'][nw];
	}
	cnt[nw]++;
}

char str[N + 5];

int main() {
	int n; scanf("%d", &n);
	for(int i=1;i<=n;i++) {
		scanf("%s", str); int len = strlen(str);
		reverse(str, str + len), insert(str, len);
	}
	for(int i=0;i<26;i++) dfs(ch[i][0]);
	for(int i=0;i<26;i++) for(int j=0;j<26;j++)
		if( ch[j][0] && i != j ) tot[i][0] += tot[i][ch[j][0]];
	for(int i=0;i<26;i++) if( ch[i][0] ) tot[i][0] += sum[ch[i][0]];
	for(int i=0;i<26;i++) if( ch[i][0] ) ans += 1ll * cnt[ch[i][0]] * tot[i][0];
	printf("%lld\n", ans - n);
}

Measured memory_bytes: 258780
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var n = int.Parse(spl[0]);
        var m = int.Parse(spl[1]);

        if(n==1 && m == 1) {
            return 1;
        }

        if(n==1 || m == 1) {
            var x = n == 1 ? m : n;
            return x - 2;
        }

        return ((long)n - 2L) * ((long)m - 2L);
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


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

using namespace std;

const int logMaxStep = 30;

typedef long long ll;
typedef vector< vector<ll> > Graph;

int GetLogStep(int S) {
	int res;
	for (res = 0; (1 << res) <= S; ++res);
	return res;
}
Graph nextG(const Graph& g1, const Graph& g2) {
	int N = g1.size();
	Graph res(N, vector<ll>(N, 0));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			for (int k = 0; k < N; ++k) {
				if (g1[i][k] > 0 && g2[k][j] > 0) {
					res[i][j] = max(res[i][j], g1[i][k]+g2[k][j]);
				}
			}
		}
	}
	return res;
}
vector<int> nextDP(vector<ll>& dp, Graph& g) {
	int N = g.size();
	vector<int> prevV(N, -1);
	vector<ll> ndp(N, -1);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (dp[i] >= 0 && g[i][j] > 0) {
				if (dp[i]+g[i][j] > ndp[j]) {
					ndp[j] = dp[i]+g[i][j];
					prevV[j] = i;
				}
			}
		}
	}
	for (int i = 0; i < N; ++i) {
		dp[i] = ndp[i];
	}
	return prevV;
}
ll GetMaxScore(vector<Graph>& powG, int S) {
	int N = powG[0].size();
	int logS = GetLogStep(S);
	vector<ll> dp(N, 0);
	for (int i = 0; i < logS; ++i) {
		Graph& g = powG[i];
		if ( (1 << i) & S ) {
			nextDP(dp, g);
		}
	}
	ll res = -1;
	for (int i = 0; i < dp.size(); ++i) {
		res = max(res, dp[i]);
	}
	return res;
}
ll check200Step(Graph& G, int K) {
	int N = G.size();
	vector<ll> dp(N, 0);
	vector< vector<int> > prevV;
	ll lastAns = -1;
	for (int t = 0; t < 1000; ++t) {
		prevV.push_back( nextDP(dp, G) );
		int aid = 0;
		for (int i = 0; i < dp.size(); ++i) {
			if (dp[i] > dp[aid]) aid = i;
		}
		if (dp[aid] >= K) {
			cout << t+1 << endl;
			if (t+1 <= 100) {
				vector<int> vl;
				int v = aid; vl.push_back(v);
				for (int i = t; i >= 0; --i) {
					v = prevV[i][v];
					vl.push_back(v);
				}
				reverse(vl.begin(), vl.end());
				for (int i = 0; i < vl.size(); ++i) {
					if (i) cout << " ";
					cout << vl[i];
				}
				cout << endl;
			}
			return -2;
		}
		lastAns = dp[aid];
	}
	return lastAns;
}
int main() {
	int N, E, K; cin >> N >> E >> K;
	Graph G(N, vector<ll>(N, 0));
	for (int i = 0; i < E; ++i) {
		int a, b; ll c; cin >> a >> b >> c;
		G[a][b] = max(G[a][b], c);
	}
	ll result = check200Step(G, K);
	if (result > 0) {
		vector<Graph> powG(logMaxStep+1); powG[0] = G;
		for (int i = 0; i < logMaxStep; ++i) {
			powG[i+1] = nextG(powG[i], powG[i]);
		}
/*
		for (int i = N; i <= N+100; ++i) {
			if (GetMaxScore(powG, i+1) >= result) {
				assert(GetMaxScore(powG, i+1) > GetMaxScore(powG, i));
			}
		}
*/
		int ans = K;
		for (int rest = 0; rest < N; ++rest) {
			int l = 0, r = K/N+2;
			while (r-l > 1) {
				int m = (l + r)/2;
				if ( GetMaxScore(powG, m * N + rest) >= K ) {
					r = m;
				}
				else {
					l = m;
				}
			}
			ans = min(ans, r*N+rest);
		}
		cout << ans << endl;
	}
	else if (result == -1) {
		cout << -1 << endl;
	}
}

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

using namespace std;

const int KMAX = 1e5;
const int mod = 1e9 + 7;

int N, K;
int a[105];
int dp[105][KMAX + 5];
int sum[105][KMAX + 5];

int getsum(int i, int st, int dr)
{
    if(st < 0)  st = 0;
    if(dr > K)  dr = K;
    if(st == 0) return sum[i][dr];
    return (sum[i][dr] - sum[i][st - 1] + mod) % mod;
}

int main()
{
    cin >> N >> K;
    for(int i = 1; i <= N; i++) cin >> a[i];

    dp[0][0] = 1;
    sum[0][0] = 1;
    for(int i = 1; i <= K; i++) sum[0][i] = 1;
    for(int i = 1; i <= N; i++)
        for(int j = 0; j <= K; j++)
        {
            dp[i][j] = getsum(i - 1, j - a[i], j);
            sum[i][j] = dp[i][j];
            if(j > 0)   sum[i][j] = (sum[i][j - 1] + sum[i][j]) % mod;
        }

    cout << dp[N][K] << '\n';
    exit(0);
}

Measured memory_bytes: 82176
import sys


def main():
    n, s = sys.stdin.read().split()
    n = int(n)

    left, right = 0, 0
    for char in s:
        if char == '(':
            # if left:
            #     left -= 1
            # else:
                right += 1
        elif char == ')':
            if right:
                right -= 1
            else:
                left += 1
    
    ans = '(' * left + s + ')' * right
    print(ans)

            

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
N,M=map(int,input().split())
S=[list(map(int,input().split())) for _ in range(N)]
C=[list(map(int,input().split())) for _ in range(M)]
for a,b in S:
	m=10**9
	cnt=0
	for c,d in C:
		l=abs(c-a)+abs(d-b)
		cnt+=1
		if m>l:
			m=min(m,l)
			ans=cnt
	print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    rep(i, n) {
        while (a[i]%2 == 0) {
            a[i] /= 2;
            ans++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

const long long r = 1e9 + 7;

long long d[42][1 << 17], p[41];

int main() {
	p[0] = 1;
	for (int i = 1; i <= 40; ++i)
		p[i] = p[i - 1] * 10 % r;

	int n, x, y, z;
	scanf("%d %d %d %d", &n, &x, &y, &z);

	long long ans = 0;
	d[0][0] = 1;
	int msk = (1 << (z - 1)) + (1 << (y + z - 1)) + (1 << (x + y + z - 1));
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j < (1 << 17); ++j) {
			if ((j & msk) == msk) 
				ans = (ans + d[i][j] * p[n - i]) % r;
			else
				for (int k = 1; k <= 10; ++k)
					d[i + 1][((j % (1 << (17 - k))) << k) + (1 << (k - 1))] = (d[i + 1][((j % (1 << (17 - k))) << k) + (1 << (k - 1))] + d[i][j]) % r;
		}
	}

	printf("%lld", ans);

	return 0;
}

Measured memory_bytes: 42240
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

int main(){
  int N, x;
  scanf("%d", &N);
  scanf("%d", &x);
  std::vector<int > a(N+1);
  long long ans = 0;
  a[0]=0;
  for (int i=0; i<N; i++){
    scanf("%d", &a[i+1]);
  }
  for (int i=0; i<N; i++){
    if(a[i]+(long long)a[i+1]>x){
      ans+=(long long)a[i+1]+a[i]-x;
      a[i+1] -= a[i]+a[i+1]-x;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

class DisjointSet{
    public:
        vector<int> rank, p, num;

        DisjointSet(){}
        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            num.resize(size, 0);
            for(int i = 0; i < size; i++) makeSet(i);
        }

        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
            num[x] = 1;
        }//グループを作る

        bool same(int x, int y){
            return findSet(x) == findSet(y); //x,yが同じグループに属しているか判定
        }

        void unite(int x, int y){
            link(findSet(x), findSet(y));
            
        }//xとyの属するsetを結合する

        void link(int x, int y){
            if(rank[x] > rank[y]){
                p[y] = x;
                num[x] += num[y];
                num[y] = 0;
            }else{
                p[x] = y;
                if( rank[x] == rank[y]){
                    rank[y]++;
                }
                num[y] += num[x];
                num[x] = 0;
            }
        }//rankが大きい方の下にrankが小さいものをくっつける

        int findSet(int x){
            if(x != p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }//再帰的にxの親を見つけている

        int size(int x){
            return num[findSet(x)];
        }// xの属する集合の大きさを返す
};//size分の0~n-1の数、setが生成されていることに注意(読み込む時に全て-1するのが良い)

//long long dp[100];
/*void factorial(){
    for(int i = 0; i<100; i++){
        if(i == 0) dp[i] = 0;
        else dp[i] = dp[i-1] * i;
    }
}*/

int main(){
    int n, m;
    cin >> n >> m;
    int a[m], b[m];
    vector<ll> v;
    //factorial();
    DisjointSet ds = DisjointSet(n);
    for(int i = 0; i < m; i++){
        cin >> a[m - i - 1] >> b[m - i - 1];
        a[m - i - 1]--;
        b[m-i-1]--;
    }
    v.push_back(0);
    ll sum = 0;
    for(int i = 0; i < m; i++){
        if(ds.same(a[i],b[i]) != true){
            ll p = ds.size(a[i]), q = ds.size(b[i]);
            sum += p * q;
            ds.unite(a[i], b[i]);
        }
        v.push_back(sum);
    }
    ll max = (long)n * (n - 1) / 2;
    for(int i = v.size() - 2; i >= 0; i--){
        cout << max - v[i] << endl;
    }
}


Measured memory_bytes: 4212
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

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

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    string s; cin >> s;
    vector<char> c;
    for(auto &x : s) c.pb(x);

    int size = c.size();
    rep(i, size){
        if(i % 2 != 0 && c[i] == 'R'){
            cout << "No" << endl;
            return 0;
        }
        if(i % 2 == 0 && c[i] == 'L'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 305;

int n, m, p[MAXN][MAXN], cur[MAXN], tot, ans, cnt[MAXN];
bool used[MAXN];

int main(){
	int i, j, mx;
	scanf("%d%d", &n, &m);
	for(i = 1; i <= n; ++ i)
		for(j = 1; j <= m; ++ j)
			scanf("%d", &p[i][j]);
	for(i = 1; i <= n; ++ i)
		cur[i] = 1;
	for(i = 1; i <= m; ++ i)
		used[i] = true;
	tot = m, ans = n;
	while(tot){
		memset(cnt, 0, sizeof(cnt));
		for(i = 1; i <= n; ++ i){
			while(!used[p[i][cur[i]]]) ++ cur[i];
			++ cnt[p[i][cur[i]]];
		}
		for(i = 1, mx = 0; i <= m; ++ i)
			if(cnt[i] > mx) mx = cnt[i];
		if(mx < ans) ans = mx;
		for(i = 1; i <= m; ++ i)
			if(cnt[i] == mx) used[i] = false, -- tot;
	} printf("%d\n", ans);
	return 0;
}

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

double p[3010];
double dp[3010][3010];

int main(){
	int n;
	scanf("%d", &n);
	for(int i=0; i < n; i++) {
		scanf("%lf", &p[i]);
	}
	dp[0][0] = 1;
	for(int i=1; i <= n; i++) {
		for(int j=0; j <= i; j++) {
			if(j > 0)
				dp[i][j] = dp[i-1][j-1] * p[i-1];
			dp[i][j] += dp[i-1][j] * (1 - p[i-1]);
		}
	}
	double ans = 0;
	for(int i=0; i <= n; i++) {
		if(i > n-i)
			ans += dp[n][i];
	}
	printf("%.12lf\n", ans);
}


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

int main()
{
    int n;
    cin >> n;
    deque<int> b;
    if(n % 2 == 0) {
        rep(i, n) {
            int a;
            cin >> a;
            if(i % 2 == 0) {
                b.push_back(a);
            }
            else b.push_front(a);
        }
    }
    else {
        rep(i, n) {
            int a;
            cin >> a;
            if(i % 2 == 1) {
                b.push_back(a);
            }
            else b.push_front(a);
        }
    }
    rep(i, n-1) cout << b[i] << " ";
    cout << b[n - 1] << endl;
    return 0;
}


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

int main(void) {
    string S;
    int Q;

    cin >> S >> Q;

    string U;
    for (int i=0; i<Q; i++) {
        int T;
        cin >> T;
        if (T == 2) {
            int F;
            string C;
            cin >> F;
            cin >> C;
            if (F == 1) {
                U+= C;
            } else {
                S+= C;
            }
        } else {
            swap(S, U);
        }
    }
    reverse(U.begin(), U.end());
    U += S;

    cout << U << endl;

    return 0;
}



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

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

    for (int i = k; i < n; i++)
    {
        if (a[i] > a[i - k])
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}


Measured memory_bytes: 4048
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <list>
#include <functional>
#include <algorithm>
#include <array>


using namespace std;

void f(array<array<int,14>,14>& color,int i,int j){
    if(color[i][j] != 1) return;
    color[i][j] = -1;
    f(color,i+1,j);
    f(color,i-1,j);
    f(color,i,j+1);
    f(color,i,j-1);
}

int main(int, char**){
    char b;
    while(cin >> b){
	array<array<int,14>,14> map;
	map[1][1] = b == '1';
	for(int i(2);i<=12;++i){
	    cin >> b;
	    map[1][i] = b == '1';
	}
	for(int i(2);i<=12;++i)
	    for(int j(1);j<=12;++j){
		cin >> b;
		map[i][j] = b == '1';
	    }
	array<array<int,14>,14> color=map;
	// for(auto e: map){
	//     for(auto el: e){
	// 	cout << el;
	//     }
	//     cout << endl;
	// }
	int cnt(0);
	for(int i(1);i<=12;++i)
	    for(int j(1);j<=12;++j)
		if(color[i][j] == 1) {
			++cnt;
			f(color,i,j);
		}
	cout << cnt << endl;
	cin.ignore();
    }

    return 0;
}

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

using ll = long long;

int main() {
    const int max_p = 1 << 18;

    int l, r; cin >> l >> r;

    vector<int> ns(r - l + 1);
    for(int i = 0; i <= r - l; ++i) {
        ns[i] = i + l;
    }
    vector<int> cnt(r - l + 1);
    vector<bool> is_prime(max_p, true);
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i < max_p; ++i) {
        if(is_prime[i]) {
            for(int j = i + i; j < max_p; j += i) is_prime[j] = false;
            ll x = i;
            while(x <= r) {
                for(int j = (l + x - 1) / x * x; j <= r; j += x) {
                    cnt[j - l] += 1;
                    ns[j - l] /= i;
                }
                x *= i;
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < r - l + 1; ++i) {
        if(ns[i] > 1) cnt[i] += 1;
        ans += is_prime[cnt[i]];
    }
    cout << ans << endl;
}



Measured memory_bytes: 10748
import sys

n, q = map(int, sys.stdin.readline().split())

near = [[] for _ in range(n+1)]
solved = [0] * (n+1)

child = [[] for _ in range(n+1)]
for i in range(n-1):
    a, b = map(int, sys.stdin.readline().split())
    near[a].append(b)
    near[b].append(a)

wait = [1]
solved[1] = 1
while True:
    target = wait.pop()
    for nex in near[target]:
        if solved[nex] != 1:
            child[target].append(nex)
            wait.append(nex)
            solved[nex] = 1
    if len(wait) == 0:
        break

score = [0] * (n+1)
for i in range(q):
    p, x = map(int, sys.stdin.readline().split())
    score[p] += x

wait = [1]

while True:
    target = wait.pop()
    for nex in child[target]:
        score[nex] += score[target]
        wait.append(nex)
    if len(wait) == 0:
        break

score.pop(0)

print(' '.join(map(str, score)))


Measured memory_bytes: 132984
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
//typedef pair<ll,ll> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

signed main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    while(true){
        int x,y,s;
        cin>>x>>y>>s;
        if(x==y && y==s && x==0) return 0;
        int ans=0;
        for(int a=1;a<=s-1;a++){
            for(int b=1;b<=s-1;b++){
                
                if(a*(100+x)/100+b*(100+x)/100==s){
                    chmax(ans,a*(100+y)/100+b*(100+y)/100);
                }
            }
        }
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll a,b;
  cin>>a>>b;
  ll c=a*b;
  if (a==1||b==1) cout<<1<<endl;
  else cout<<(c%2 ? (c+1)/2:c/2)<<endl;
  return 0;
}

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

int main() {
	int a,b,c,d;
  	cin>>a>>b>>c>>d;
  	if(a<1200) cout<<"ABC"<<endl;
  	else cout<<"ARC"<<endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c; cin >> a >> b >> c;
    if (c - a - b < 0) cout << "No\n";
    else if (4LL * a * b < (c - a - b) * (c - a - b)) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main()
{
	int plan;
	
	while (scanf("%d", &plan) && plan){
		int rec = 0;
		bool flag = false;
		
		for (int i = 0; i < 12; i++){
			int n, m;
			scanf("%d %d",&m, &n);
			rec += (m - n);
			if (flag == false && rec >= plan){
				printf("%d\n", i + 1);
				flag = true;
			}
		}
		
		if (flag == false){
			printf("NA\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vvi g;
vi dp,DP;

void dfs(int v,int p){
	vi a,b;
	for(auto u:g[v]) if(u!=p){
		dfs(u,v);
		a.push_back(dp[u]);
		b.push_back(DP[u]);
	}
	int N=a.size(),S=0;
	bool B=1,t=1;
	for(auto i:a){
		B&=i;
		if(i) S++;
	}
	DP[v]=B;
	B=0;
	for(int i=0;i<N;i++) if(b[i]) B=1;
	if(S!=N-1) B=0;
	dp[v]=B;
}

int main(){
	cin>>n;
	g=vvi(n);
	dp=DP=vi(n);
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0,-1);
	if(dp[0]) cout<<"Second"<<endl;
	else cout<<"First"<<endl;
}

Measured memory_bytes: 6656
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int min = 10000;
    int max = 0;
    for (int i = 0; i < n; i++) {
      int k = sc.nextInt();
      min = Math.min(min, k);
      max = Math.max(max, k);
    }
    System.out.println(max - min);
  }
}

Measured memory_bytes: 21844
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	while ( true ) {

	    final int n = stdin.nextInt();
	    if ( n == -1 ) {
		break;
	    }

	    double xn = n / 2.0;
	    while ( abs( xn * xn * xn - n ) >= n * 1.0e-5 ) {
		xn = xn - ( xn * xn * xn - n ) / ( 3 * xn * xn );
	    }
	    System.out.printf( "%.10f\n", xn );
	}	
    }    
}

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

using namespace std;

typedef long long LL;

const int N = 1010;

int n;
LL L[N];

int main()
{
    cin >> n;
    L[0] = 2, L[1] = 1;
    for(int i = 2; i <= n; i++) L[i] = L[i - 1] + L[i - 2];

    cout << L[n] << endl;
    return 0;
}


Measured memory_bytes: 256
using System;

class Plogram
{
    static void Main()
    {

        var n = Console.ReadLine().Split();
        int N = int.Parse(n[0]);
        int M = int.Parse(n[1]);

        int Lmax = 0;
        int Rmin = int.MaxValue;

        for (int i = 0; i < M; i++)
        {
            var num = Console.ReadLine().Split();
            int L = int.Parse(num[0]);
            int R = int.Parse(num[1]);

            if(Lmax < L)
            {
                Lmax = L;
            }
            if(Rmin > R)
            {
                Rmin = R;
            }
        }
        Console.WriteLine((Rmin - (Lmax - 1) < 1)? 0: Rmin - (Lmax - 1));
    }
}

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

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)


int main(int argc, char *argv[]) {
	i64 N, K;
	cin >> N >> K;
	i64 r = N % K;
	cout << min(r, K - r) << endl;

  return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
a=[list(map(int,input().split()))for _ in range(h)]
b=[list(map(int,input().split()))for _ in range(h)]
d=[[a[i][j]-b[i][j]for j in range(w)]for i in range(h)]
dp=[w*[0]for _ in range(h)]
dp[0][0]=1<<(80+d[0][0])|1<<(80-d[0][0])
for i in range(h):
  for j in range(w):
    if i!=0:
      dp[i][j]|=(dp[i-1][j]<<80+d[i][j])
      dp[i][j]|=(dp[i-1][j]<<80-d[i][j])
    if j!=0:
      dp[i][j]|=(dp[i][j-1]<<80+d[i][j])
      dp[i][j]|=(dp[i][j-1]<<80-d[i][j])
n=dp[-1][-1]|(1<<15000)
ans=1<<1000
for i in range(15000):
  if n&(1<<i):ans=min(ans,abs(i-(h+w-1)*80))
print(ans)


Measured memory_bytes: 15328
/*

*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <cstdlib>
#include <cmath>
#include <bitset>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second
#define ld long double
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rf(x) scnaf("%lf",&x)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
#define sz(x) ((int) x.size())
#define ld long double

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

//mt19937 myrand(time(0));
//int get_rand(int n){return myrand()%n + 1;}
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5;

int n,p[N+10];

int main(){
    //Open();
    //Close();
    ri(n);
    rep1(i,1,n) ri(p[i]);
    int ans = 0;
    rep1(i,1,n){
        if (p[i]!=i){
            continue;
        }
        int j = i;
        while (j+1<=n && p[j+1]==(j+1)){
            j++;
        }
        ans+=(j-i+1+1)/2;
        i = j;
    }
    oi(ans);puts("");
    return 0;
}


Measured memory_bytes: 640
K = int(input())
if K % 2 == 0 or K % 5 ==0:
    print(-1)
    exit()
else:
    n = 7
    n_before = 7
    count = 0
    while True:
        count += 1
        n = n % K
        if n == 0:
            print(count)
            exit()
        else:
            n_before = 10 * n_before % K
            n = n + n_before
print(count)


Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
#define F(i, s, t) for (int i = (s), _ = (t); i <= _; i ++)
const int N = 100005;
int n, a[N], bas;
int rd() {
	int x = 0, f = 1; char c;
	do { c = getchar(); if (c == '-') f = -1; } while (! isdigit(c));
	do { x = x*10+c-'0', c = getchar(); } while (isdigit(c));
	return x * f;
}
int main() {
	n = rd();
	F(i, 1, n) a[i] = rd();
	a[n+1] = 0;
	F(i, 1, n+1) bas += abs(a[i] - a[i-1]);
	F(i, 1, n) {
		int ans = bas - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i-1] - a[i+1]);
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
#define y1 y1___
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
ll read(){
    char ch=gc();ll x=0;int op=1;
    for (;!isdigit(ch);ch=gc()) if (ch=='-') op=-1;
    for (;isdigit(ch);ch=gc()) x=(x<<1)+(x<<3)+ch-'0';
    return x*op;
}
#define N 105
#define mod 1000000007
int ksm(int x,int p){
    int ret=1;
    for (;p;p>>=1,x=(ll)x*x%mod) if (p&1) ret=(ll)ret*x%mod;
    return ret;
}
int n,h[N];
pii solve(int l,int r,int lim){//区间[l,r]比lim高的部分的方案数
    int mi=inf,cnt=0;pii ret;//first：存在相邻格子颜色相同情况的方案数；second：不存在的方案数（固定第一个格子的颜色）
    rep (i,l,r) if (h[i]<mi) mi=h[i],cnt=1;else if (h[i]==mi) cnt++;
    if (cnt==r-l+1){//矩形
        ret.fi=(ksm(2,r-l+1)+mod-2)%mod;
        ret.se=ksm(2,mi-lim);
        return ret;
    }
    int rest=r-l+1,s0=1,s1=1,last=0;//rest：上方没有方格的列数；s0,s1：维护上方有方格的列，当前行存在/不存在的方案数
    rep (i,l,r+1)
        if (!last&&h[i]>mi) last=i;
        else if (last&&(h[i]<=mi||i>r)){
            rest-=i-last;
            pii tmp=solve(last,i-1,mi);//子问题，递归求解
            s0=(ll)s0*(tmp.fi+2ll*tmp.se%mod)%mod;//*4是因为上一行可以取反，当前行亦然，2*2
            s1=(ll)s1*(1ll*tmp.se%mod)%mod;
            last=0;
        }
    s0=(s0+mod-s1)%mod;
    ret.fi=(ll)s0*ksm(2,rest)%mod;//如果上方方格已经存在，剩下的列随意
    ret.fi=(ret.fi+(ll)s1*(ksm(2,rest)+mod-2)%mod)%mod;//否则需要去掉两种不合法的情况
    ret.se=(ll)2ll*s1*ksm(2,mi-lim-1)%mod;//固定第一个格子（第一行）颜色
    return ret;
}
int main(){
    n=read();rep (i,1,n) h[i]=read();
    if (n==1){//注意特判
        printf("%d\n",ksm(2,h[1]));
        exit(0);
    }
    int ex=1;
    rep (i,1,n) if (h[i]>h[i-1]&&h[i]>h[i+1]){
        ex=(ll)ex*ksm(2,h[i]-max(h[i-1],h[i+1]))%mod;
        h[i]=max(h[i-1],h[i+1]);
    }
    pii ans=solve(1,n,0);
    printf("%d",(ll)ex*(ans.fi+ans.se%mod)%mod);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll N) {
  cout << N * 800 - N / 15 * 200 << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	scanf("%lld", &N);
	solve(N);
	return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> vec(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> vec.at(i).at(j);
    }
  }
  int h = 0;
  vector<vector<char>> vec2(H, vector<char>(W));
  //行の探索
  for (int i = 0; i < H; i++) {
    int count = 0;
    for (int j = 0; j < W; j++) {
      if (vec.at(i).at(j) == '.') {
        count++;
      }
    }
    if (count == W) {
      h++;
    } else {
      for (int j = 0; j < W; j++) vec2.at(i - h).at(j) = vec.at(i).at(j);
    }
  }
  int w = 0;
  vector<vector<char>> vec3(H - h, vector<char>(W));
  for (int j = 0; j < W; j++) {
    int count = 0;
    for (int i = 0; i < H - h; i++) {
      if (vec2.at(i).at(j) == '.') {
        count++;
      }
    }
    if (count == H - h) {
      w++;
    } else {
      for (int i = 0; i < H - h; i++) {
        vec3.at(i).at(j - w) = vec2.at(i).at(j);
      }
    }
  }

  for (int i = 0; i < H - h; i++) {
    for (int j = 0; j < W - w; j++) {
      cout << vec3.at(i).at(j);
      if (j == W - w - 1) {
        cout << endl;
      }
    }
  }
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int A[] = new int[N];
    int Max = 0;
    int Maxi = 0;
    int Max2 = 0;
    
    for (int i = 0; i < N; i++){
      A[i] = scan.nextInt();
      if(A[i] >= Max){
        Max2 = Max;
        Max = A[i];
        Maxi = i;
      } else if(A[i] >= Max2){
        Max2 = A[i];
      }
    }
    
    for(int i = 0; i < N; i++){
      if(i == Maxi){
        System.out.println(Max2);
      } else {
        System.out.println(Max);
      }
    }
  }
}

Measured memory_bytes: 86628
#include<stdio.h>
 int main()
 {
     int n,c=0;
     scanf("%d",&n);
     for(int i=1;i<=n;i++)
     {
         int x;
         scanf("%d",&x);
         if(i!=x) c++;
         //printf("%d %d %d\n",c,i,x);
     }
     //printf("%d\n",c);
     if(c==2||c==0) printf("YES\n");
     else printf("NO\n");
 }


Measured memory_bytes: 1588
def chmin(a,b):
  if a > b:
    return b
  else:
    return a

n = int(input())
A = list(map(int,input().split()))
f_inf = float('inf')
dp = [f_inf]*n
dp[0]=0
dp[1]=abs(A[1]-A[0])
for i in range(n):
  if i<2:
    continue
  dp[i]=chmin(dp[i],dp[i-1]+abs(A[i]-A[i-1]))
  dp[i]=chmin(dp[i],dp[i-2]+abs(A[i]-A[i-2]))
print(dp[n-1])

Measured memory_bytes: 13908
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <array>
#include <functional>
#include <algorithm>
#include <numeric>
#include <string>
#include <stack>

int main()
{
	//std::cout << std::fixed << std::setprecision(15);

	int n, m;
	std::cin >> n >> m;

	std::array<bool, 100000> result{false};
	std::array<int, 100000> wa{ 0 };

	int ac_number = 0;
	int wa_number = 0;
	for (int i = 0; i < m; ++i)
	{
		int p;
		std::string s;
		std::cin >> p >> s;

		if (!result.at(p - 1))
		{
			if (s == "AC")
			{
				result.at(p - 1) = true;
				ac_number++;
			}
			else
			{
				wa.at(p - 1)++;
			}
		}
	}

	for (int i = 0; i < wa.size(); ++i)
	{
		if (result.at(i))
		{
			wa_number += wa.at(i);
		}
	}

	std::cout << ac_number << " " << wa_number << std::endl;
	   
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    for(int i = 0; i < N; i++) cin >> S[i];
    sort(S.begin(), S.end());
    for(int i = 0; i < N; i++) cout << S[i];
    cout << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    vector<int> v = {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 n; cin >> n;
    cout << v[n - 1] << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 998244353;

signed main() {
  int n;
  string s;
  cin>>n>>s;
  int ans=1;
  for(int i=1;i<n;i++)if(s[i-1]!=s[i])ans++;
  cout<<ans;
  



  return 0;
}


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


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

int main(){
    int n,i;
    int h[100100];
    int dp[100100] = {0};

    scanf("%d",&n);

    for(i = 1; i <= n ; i++){
        scanf("%d",&h[i]);
        dp[i] = 0;
    }
    dp[1] = 0;
    dp[2] = abs(h[1] - h[2]);
    for(i = 3 ; i <= n ; i++){
        dp[i] = min(dp[i-1]+abs(h[i] - h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    printf("%d\n",dp[n]);
    return 0;


}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

struct Point {
  int x, y;
};

int main(){
  int in(h, w, d);
  int a[300][300];
  Point points[300 * 300 + 1];
  rep(i, h) {
    rep(j, w) {
      cin >> a[i][j];
      points[a[i][j]] = {j, i};
    }
  }

  long long costs[300 * 300 + 1] = {};

  int end = h * w + 1;
  FOR(i, d + 1, end) {
    Point p1 = points[i - d];
    Point p2 = points[i];
    costs[i] = costs[i - d] + (long long)abs(p1.x - p2.x) + (long long)abs(p1.y - p2.y);
  }

  int in(q);
  rep(i, q) {
    int in(l, r);
    out(costs[r] - costs[l]);
  }
}


Measured memory_bytes: 2816
S = list(input())
ans = True
if S[0] != "A":
    ans = False
if sum(S[i] == "C" for i in range(2, len(S)-1)) != 1:
    ans = False
if sum(s.lower() != s for s in S) != 2:
    ans = False
print("AC" if ans else "WA")


Measured memory_bytes: 3064
#include <stdio.h>

int main(){
    int h, w;
    int i, j;
    while(1){
        scanf("%d %d", &h, &w);
        if(h==0&&w==0)break;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                if((i%2==0&&j%2==0)||(i%2==1&&j%2==1)){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    
    return 0;
}



Measured memory_bytes: 2072
#!/usr/bin/env python3
from scipy.sparse.csgraph import csgraph_from_dense, dijkstra
import numpy as np

def main():
    H, W = list(map(int, input().split()))
    N = H * W
    S = [[line for line in range(W)] for row in range(H)]
    for i in range(H):
        row = input()
        for j, line in enumerate(row):
            S[i][j] = line

    data = np.zeros([N, N])
    for i in range(H):
        for j in range(W):
            n = W * i + j
            if j<W-1 and S[i][j]=='.' and S[i][j+1]=='.':
                data[n][n+1] = data[n+1][n] = 1
            if i<H-1 and S[i][j]=='.' and S[i+1][j]=='.':
                data[n][n+W] = data[n+W][n] = 1

    G = csgraph_from_dense(data)
    answer = 0
    for n in range(N):
        result = dijkstra(G, indices=n)
        result = [x for x in result if x!=np.inf]
        answer = max(answer, max(result))
    print(int(answer))
    pass

if __name__ == '__main__':
    main()


Measured memory_bytes: 18728
#include <bits/stdc++.h> 
     
    using namespace std;
     
    set<string> st;
     
    int main(){
    	int n;
      	cin >> n;
     
    	while(n--){
          string s;
          cin >> s;
          
          st.insert(s);
        }
      
      	cout << st.size() << endl;
      
    }
      

Measured memory_bytes: 19260
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e9
#define INFL          static_cast<lint>(INF)
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)     for(lint i=n-1;i>=0;--i)
#define REPR1(i,n)    for(lint i=n;i>0;--i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
int main()
{
	int q = in();
	set<int>s;
	REP(i, q)
	{
		int n = in();
		int x, l, r;
		switch (n)
		{
		case 0:
			x = in();
			s.insert(x);
			cout << s.size() << endl;
			break;
		case 1:
			x = in();
			cout << (s.find(x) == s.end() ? 0 : 1) << endl;
			break;
		case 2:
			x = in();
			s.erase(x);
			break;
		case 3:
			l = in();
			r = in();
			for (auto start = s.lower_bound(l), last = s.upper_bound(r); start != last; start++)cout << *start << endl;
			break;
		}
	}
}


Measured memory_bytes: 12360
#include<stdio.h>

typedef long long ll;

int main(void){
    int N = 0;
    ll H[100000];
    int i = 0, j = 0;
    int flg = 0;

    scanf("%d", &N);
    for(i = 0 ; i < N; i++)
        scanf("%lld", &H[i]);
    
    for(i =  N-1; i > 0; i--){
        if(H[i-1]-H[i] == 1){
            H[i-1]--;
        }else if(H[i-1]-H[i] <= 0){
            continue;
        }else{
            printf("No");
            return 0;
        }
    }

    printf("Yes");

    return 0;

}

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

int main(void)
{
    int A, B, T;
    cin >> A >> B >> T;
    int ans = 0;
    
    for(int time = A; time < T + 0.5; time += A){
        ans += B;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
	#define debug printf
#else
	#define debug(...)
#endif
const ll maxn = 1e5 + 5;
ll n,a[maxn],b[maxn],sum[maxn],ans;
int main(int argc, char const *argv[])
{
	cin>>n;
	for(ll i = 0;i < n; ++i)
	{
		scanf("%lld%lld",a + i,b + i);
		ans -= b[i];
		sum[i] = a[i] + b[i];
	}
	sort(sum,sum + n);
	reverse(sum,sum + n);
	for(ll i = 0;i < n; i += 2)
	{
		ans += sum[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int K = Integer.parseInt(sc.next());
        int X = Integer.parseInt(sc.next());
        int Y = Integer.parseInt(sc.next());
        int cost = 0;

        for (int i = 1; i <= N; i++) {

            if (i <= K) {
                cost += X;
            } else {
                cost += Y;
            }
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(cost);

        sc.close();
        out.flush();
    }
}

Measured memory_bytes: 35576