akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,a[10001],ans;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++){
			if(a[i]<a[j]) swap(a[i],a[j]);
		}
	for(int i=1;i<=k;i++){
		ans+=a[i]; 
	}
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
long long Q,H,S,D,n;
int main()
{
	cin>>Q>>H>>S>>D;
	H=min(H,Q+Q);
    S=min(S,H+H);
    D=min(D,S+S);
	cin>>n;
	cout<<n/2*D+(n%2==1)*S;
}

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

int main(){
    int n,k;cin>>n>>k;
    int ans =1;
    rep(i,n){
        ans+=min(ans,k);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <climits>
#include <cstring>
using namespace std;

int R, C;
char grid[105][105];
int memo[105][105];

bool inside(int r, int c){
  return 1<=r && r<=R && 1<=c && c<=C;
}

int dp(int r, int c){
  // base case
  if(r == R && c == C){
    return (grid[r][c] == '#');
  }

  // memo
  if(memo[r][c] != -1) return memo[r][c];

  // transisi
  int result = INT_MAX;
  int dx[] = {1, 0};
  int dy[] = {0, 1};
  for(int d=0; d<2; d++){
    int nxr = r+dx[d];
    int nxc = c+dy[d];

    if(!inside(nxr, nxc)) continue;
    if(grid[r][c] == '.') result = min(result, dp(nxr, nxc));
    else if(grid[r][c] == '#' && grid[nxr][nxc]=='#') result = min(result, dp(nxr,nxc));
    else if(grid[r][c] == '#' && grid[nxr][nxc]=='.') result = min(result, dp(nxr,nxc) + 1);									
  }

  return memo[r][c] = result;
}

int main(){

  cin >> R >> C;
  for(int i=1; i<=R; i++){
    for(int j=1; j<=C; j++){
      cin >> grid[i][j];
    }
  }

  memset(memo, -1, sizeof(memo));
  cout << dp(1,1) << endl;

} 

Measured memory_bytes: 3668
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
//typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 1000 * 100 + 47;
const int MAX1 = 1000 * 100 + 47;

int A[MAX];

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	FOR(i, 0, n) cin >> A[i];
	sort(A, A + n);
	reverse(A, A + n);
	int x = 0, y = 1;
	FOR(i, 0, n + 1)
	{
		if (i + 1 > A[i])
		{
			x = i - 1;
			y = i;
			break;
		}
	}

	//cout << "*" << x << " " << y << endl;

	bool v1 = (A[x] - y + 1) % 2;
	int cnt = 0;
	FOR(i, x + 1, n)
	{
		cnt += A[i] == y;
	}

	//cout << "!!" << cnt << endl;
	bool v2 = (cnt + 1) % 2;
	//cout << "!!" << v1 << " " << v2 << endl;
	if (!v1 || !v2)
	{
		cout << "First" << endl;
		return 0;
	}

	cout << "Second" << endl;
}

Measured memory_bytes: 640
N=int(input())
l = [input() for _ in range(N)]

def ans115(N:int,l:list):
    l=sorted(map(int,l))
    count=0
    for i in range(0,N-1):
        count+=l[i]
    return(int(count+l[N-1]*0.5))

print(ans115(N,l))

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

int main(){
  int n;cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  if(a[2/n-1]!=a[n/2]){
    cout << a[n/2]-a[n/2-1] << endl;
  }
  else cout << "0" << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <random>
#include <string.h>      //文字列の代入に使う
#include <bits/stdc++.h> //piの利用で必要(M_PI)
#include <algorithm>

int main()
{
    std::string S;
    std::cin >> S;
    int S_size = S.size();
    for (int i = 0; i < S_size; i++)
    {
        std::cout << "x";
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
const int MOD = 1000000007;
int main(){
    int n; cin >> n;
    int c[3];
    rep(i,3) c[i]=0;
    ll ans=1;
    rep(i,n){
        int a; cin >> a;
        int res=0;
        rep(j,3){
            if(c[j]==a) res++;
        }
        ans*=res;
        ans%=MOD;
        rep(j,3){
            if(c[j]==a){
                c[j]++;
                break;
            }
        }
    }
    cout << ans;
}


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

int main(){
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  cout << s1[0] << s2[0] << s3[0] << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c[] = new int[n - 1];
        int s[] = new int[n - 1];
        int f[] = new int[n - 1];
        for (int i = 0; i < n - 1; i++) {
            c[i] = sc.nextInt();
            s[i] = sc.nextInt();
            f[i] = sc.nextInt();
        }
        for (int i = 0; i < n - 1; i++) {
            int time = s[i] + c[i];
            for (int j = i + 1; j < n - 1; j++) {
                if (s[j] >= time) {
                    time = s[j] + c[j];
                } else {
                    for (int k = 1; ; k++) {
                        if (s[j] + f[j] * k >= time) {
                            time = s[j] + f[j] * k + c[j];
                            break;
                        }
                    }
                }
            }
            System.out.println(time);
        }
        System.out.println(0);
    }
}

Measured memory_bytes: 28148
n = int(input())
as_ = list(map(int, input().strip().split()))

current_idx = -1
next_num = 1
broken = 0
success = False

while broken < n:
    # current_idx より右で next_num が見つかるまで探す
    found = False
    for idx in range(current_idx + 1, n):
        if as_[idx] == next_num:
            # 見つかった
            current_idx = idx
            next_num += 1
            found = True
        else:
            broken += 1

    if n - broken == next_num - 1:
        success = True
        break

if n - broken > 0 and success:
    print(broken)
else:
    print(-1)


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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		100050

const ll LINF = (ll)1e18+7;		//
const int INF = 1e9+7;			//2147483647 (Max int)
const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい]
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}
		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}

	bool same(int x,int y){
		return root(x) == root(y);
	}
};


//
int main(){
	int N,M;cin>>N>>M;
	vector<P> edge(M);
	REP(i,M){
		cin>>edge[i].first>>edge[i].second;
		--edge[i].first,--edge[i].second;
	}

	UnionFind U(N);

	vector<ll> ans(M+1);
	ans[M] = (ll)N*(N-1)/2;
	for(int i=M-1;i>=0;--i){
		if(U.same(edge[i].first,edge[i].second)){
			ans[i] = ans[i+1];
		}
		else{
			ans[i] = (ll)ans[i+1] - U.size(edge[i].first)*U.size(edge[i].second);
			U.connect(edge[i].first,edge[i].second);
		}
	}

	REPS(i,1,M+1)cout << ans[i] << endl;

	return 0;
}




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

int main(void){
    int x,y;
    scanf("%d%d",&x,&y);
    if (x%y==0){
        printf("-1\n");
        exit (0);
    }
    for (long long i=0; i<1e18; i++){
        if ( (i*x)%y!=0 ){
            printf("%lld\n",i*x);
            exit (0);
        }
    }
    printf("-1\n");
	return 0 ;
}

Measured memory_bytes: 128
w,h,n = map(int, input().split())
x1,x2,y1,y2 = 0,w,0,h
for _ in range(n):
  xi,yi,ai = map(int, input().split())
  if ai==1: x1 = max(xi,x1)
  elif ai==2: x2 = min(xi,x2)
  elif ai==3: y1 = max(yi,y1)
  else: y2 = min(yi,y2)
dx = max(0, x2-x1)
dy = max(0, y2-y1)
print(dx*dy)

Measured memory_bytes: 9068
sec2hms :: Int->[Int]
sec2hms sec = [h, m, s]
  where h = sec `quot` 3600
        m = (sec - h * 3600) `quot` 60
        s = sec - h * 3600 - 60 * m

main = do
  sec <- readLn
  let [h, m, s] = sec2hms sec
  putStr $ show $ h
  putChar ':'
  putStr $ show $ m
  putChar ':'
  putStr $ show $ s
  putChar '\n'

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second

int main(void){
    int n;
    cin>>n;
    if(n%2){
        cout<<"NA"<<endl;
        return 0;
    }
    
    vector<pii> v(n);
    double xtotal=0,ytotal=0;
    rep(i,n){
        cin>>v[i].fs>>v[i].sc;
        xtotal+=v[i].fs;
        ytotal+=v[i].sc;
    }
    rep(i,n/2){
        int a=i,b=i+1,c=i+n/2,d=(i+n/2+1)%n;
        
        if(hypot(v[a].fs-v[b].fs, v[a].sc-v[b].sc ) != hypot(v[c].fs-v[d].fs, v[c].sc-v[d].sc) || hypot(v[a].fs-v[d].fs, v[a].sc-v[d].sc ) != hypot(v[b].fs-v[c].fs, v[b].sc-v[c].sc )){
            cout<<"NA"<<endl;
            return 0;
        }
    }
    cout<<fixed<<setprecision(5)<<xtotal/n<<" "<<ytotal/n<<endl;
    
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define P pair<ll,ll>
#define lvector vector<ll> 
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,ans=0;cin>>n;
  lvector v(5,0);rep(i,5) cin>>v[i];
  ll pos=min_element(v.begin(),v.end())-v.begin();
  ll num=(n+v[pos]-1)/v[pos];
  ans=4+num;
  print(ans);
  return 0;
}

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

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

    vector<int> x(26);
    vector<int> y(26);

    string s, t;
    cin >> s >> t;

    int b = 100;

    for(int i = 0; i < s.length(); i++) {
        x[s[i] - 'a']++;
        b = min(b, s[i] - 'a');
    }

    for(int i = 0; i < t.length(); i++) {
        y[t[i] - 'a']++;
        if(b < int(t[i] - 'a')) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    bool c = false;

    for(int i = 0; i < 26; i++) {
        if(x[i]) {
            if(c) {
                c = false;
                break;
            }
            if(y[i]) {
                if(x[i] < y[i]) {
                    c = true;
                } else {
                    break;
                }
            } else {
                break;
            }
        } else if(y[i]) {
            break;
        }
    }

    if(c) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
}

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

class UnionFind {
public:
    vector<int> par;  // 各頂点の親
    vector<int> rank;  // 各頂点の深さ
    vector<int> sz;  // 各頂点の属する頂点の個数
    int sum_sz;  // 独立集合の個数

    // コンストラクタ
    UnionFind(int n) {
        for (int i = 0; i < n; ++i) {
            par.push_back(i);
            rank.push_back(0);
            sz.push_back(1);
        }
        sum_sz = n;
    }

    // 木の根を求める
    int find(int x) {
        if (par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    // x と y の属する集合を併合
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        // 深さが小さいものから大きい方の根へ辺を張る
        if (rank[x] < rank[y]) par[x] = y;
        else if (rank[x] > rank[y]) par[y] = x;
        else {
            par[y] = x;
            ++rank[x];
        }
        --sum_sz;
        sz[x] = sz[y] = sz[x] + sz[y];
    }

    // x と y が同じ木に属するかの判定
    bool is_same(int x, int y) {
        return find(x) == find(y);
    }

    // 頂点 x が属する集合の頂点数
    int size(int x) {
        return sz[find(x)];
    }

    // 独立した集合の個数(島の個数)
    int size() {
        return sum_sz;
    }
};

int main() {
    int N, Q;
    cin >> N >> Q;
    UnionFind uf(N);

    for (int i = 0; i < Q; ++i) {
        int A, B;  cin >> A >> B;
        --A;  --B;
        uf.unite(A, B);
    }
    cout << uf.size() - 1 << endl;
}


Measured memory_bytes: 4584
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define N 200005
vector<int> marked(4*N,-1);
int t[4*N];
int pws[N+5];
#define mod 998244353
int n;
int mypower(int a, int b)
{
    int ans = 1;
    while(b)
    {
        if(b%2)
            ans = ans*a%mod;
        b=b/2;
        a=a*a%mod;
    }
    return ans;
}
int inv9 = mypower(9, mod-2);
int get_sum(int l, int r)
{
    int ans = pws[n-l+1] - pws[n - r];
    ans = ans*inv9%mod;
    return ans;
}
void push(int v, int l, int r) {
    if (marked[v]!=-1) {
        t[v] = get_sum(l, r)*marked[v]%mod;
        if(l!=r) marked[2*v] = marked[2*v+1] = marked[v];
        marked[v] = -1;
    }
}

void update(int v, int tl, int tr, int l, int r, int new_val) {
    push(v, tl, tr);
    if (l == tl && tr == r) {
        t[v] = get_sum(tl, tr)*new_val%mod;
        if(tl!=tr) marked[2*v] = marked[2*v+1] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if(r<=tm) update(2*v, tl, tm, l, r, new_val), push(2*v+1, tm+1, tr);
        else if(l>tm) update(2*v+1, tm+1, tr, l, r, new_val), push(2*v, tl, tm);
        else update(2*v, tl, tm, l, tm, new_val), update(2*v+1, tm+1, tr, tm+1, r, new_val);
        t[v] = (t[2*v] + t[2*v+1])%mod;
    }
}

// int get(int v, int tl, int tr, int pos) {
//     if (tl == tr) {
//         return t[v];
//     }
//     push(v);
//     int tm = (tl + tr) / 2;
//     if (pos <= tm) 
//         return get(v*2, tl, tm, pos);
//     else
//         return get(v*2+1, tm+1, tr, pos);
// }

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int  q;
    cin >> n >> q;
    pws[0] = 1;
    for(int i = 1;i < N+5;i++)
        pws[i] = (10*pws[i-1])%mod;
    for(int i=1;i<=n;i++)
    {
        update(1, 1, n, i, i, 1);
    }
    while(q--)
    {
        int l, r, d;
        cin >> l >> r >> d;
        update(1, 1, n, l, r, d);
        cout << (t[1] + mod)%mod << '\n';
    }
}

Measured memory_bytes: 15084
int main(void){
  int n;
  int a[50];
  int count=0;
  scanf("%d",&n);
  
  
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    
  }
  for(int i=0;i<n;i++){
    if(a[i]!=i+1){
      count++;
    }
  }
    if(count<3){    
  printf("YES");
    }else{
      printf("NO");
    }
  
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using namespace std;

int main(){
    string s;
    ll k;
    cin >> s >> k;
    for(int i=0; i<min(k,(ll)s.size()); i++){
        if(s[i] != '1'){
            cout  << s[i] << endl;
            return 0;
        }
    }
    cout << "1" << endl;
    return 0;
}

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

int main()
{
    //freopen("IN.txt","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, s=0;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x;
        cin>>x;
        s+=x;
    }
    if(s>n)cout<<-1;
    else cout<<n-s;
    return 0;
}

Measured memory_bytes: 3664
from math import gcd
ans=0
K=int(input())
for i in range(1,K+1):
  for j in range(1,K+1):
    if abs(i-j)==1 or j==1 or i==1:
      a=1
    else:
      a=gcd(i,j)
    for k in range(1,K+1):
        if a==1:
            ans+=K
            break
        elif abs(a-k)==1:
            ans+=1
        else:
            ans+=gcd(a,k)
print(ans)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;

    bool result = true;

    for(int i = 1; i < 4; i++){
        if(S.at(i) == S.at(i-1)){
            result = false;
        }else{
        }
    }
    if(result){
        cout << "Good" << endl;
    }
    else {
        cout << "Bad" << endl;
    }
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;
const bool debug = 0;
//---------------------------------//

int X, Y, Z, N;
int A[112345], B[112345], C[112345];
int ord[112345];
bool isa[112345], valid[112345];

int main() {
	cin >> X >> Y >> Z;
	N = X + Y + Z;
	REP(i, N) scanf("%d %d %d", A + i, B + i, C + i);
	
	vector<pii> v(N);
	REP(i, N) v[i] = pii(A[i] - B[i], i);
	sort(ALL(v));
	REP(i, N) ord[i] = v[i].se;
	
	ll a = 0, b = 0, c = 0;
	priority_queue<pii> pql, pqr;
	
	REP(i, Y) {
		b += B[ord[i]];
		pql.push(pii(C[ord[i]] - B[ord[i]], ord[i]));
	}
	
	FOR(i, Y, N) {
		c += C[ord[i]];
		valid[ord[i]] = true;
		pqr.push(pii(A[ord[i]] - C[ord[i]], ord[i]));
	}
	REP(i, X) {
		int idx = pqr.top().se; pqr.pop();
		isa[idx] = true;
		valid[idx] = false;
		a += A[idx]; c -= C[idx];
	}
	
	ll ans = a + b + c;
	
	FOR(i, Y, N - X) {
		pii nowl = pii(C[ord[i]] - B[ord[i]], ord[i]);
		
		if (nowl > pql.top()) c += C[ord[i]];
		else {
			int tidx = pql.top().se; pql.pop();
			b -= B[tidx]; c += C[tidx];
			b += B[ord[i]];
			pql.push(nowl);
		}
		
		if (isa[ord[i]]) {
			isa[ord[i]] = false;
			a -= A[ord[i]];
			int tidx = -1;
			while (true) {
				tidx = pqr.top().se; pqr.pop();
				if (valid[tidx]) break;
			}
			a += A[tidx]; c -= C[tidx];
			isa[tidx] = true;
			valid[tidx] = false;
		}
		else {
			valid[ord[i]] = false;
			c -= C[ord[i]];
		}
		
		chmax(ans, a + b + c);
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define loop(i, a, b) for(ll i = a; i < b; i++)
#define rloop(i, e, s) for(ll i = e; i >= s; i--)
#define mod 1000000007
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr);

int main()
{//CITY SAVERS
     ll n, ans = 0, x = 0;
     cin >> n;
     ll a[n+1], b[n];
     loop(i, 0, n+1){
         cin >> a[i];
         x += a[i];
     }
     loop(i, 0, n) cin >> b[i];
     rloop(i, n-1, 0){
         if(a[i+1] > b[i]) {
             a[i+1] -= b[i];
         }
         else if (a[i+1]== b[i]) a[i+1] = 0;
         else{
             b[i] -= a[i+1];
             a[i+1] = 0;
             if(a[i] >= b[i]) a[i] -= b[i];
             else a[i] = 0;
         }
     }
     loop(i, 0, n+1) ans += a[i];
    cout << x - ans << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
int main(void){
	char tex[30];
	int pat[2][1001],p;
	for(p=0;p<1001;p++){
		pat[0][p]=0;pat[1][p]=0;
	}
	while(fgets(tex,30,stdin)!=NULL){
		if(tex[0]=='\n')break;
		sscanf(tex,"%d,%*d",&p);
		pat[0][p]++;
		pat[1][p]=1;

	}
	while(fgets(tex,30,stdin)!=NULL){
		sscanf(tex,"%d,%*d",&p);
		pat[0][p]++;
		if(pat[1][p]==1)pat[1][p]=2;
	}
	for(p=0;p<1001;p++){
		if(pat[1][p]==2)printf("%d %d\n",p,pat[0][p]);
	}
	return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
int main(){ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n; cin>>n; long long s=0;
for(int i=1;i<=n;i++) 
                      {if(i%3!=0 && i%5!=0 && i%15!=0)
                      {s+=i;}} cout<<s;}


Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <map>
using namespace std;
typedef long long int64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int P = 998244353;
string s;
map<string, int64> f, g;
int64 F(string s);
int64 G(string s)
{
    if(g.count(s)) return g[s];
    int n = s.size(); int64 &ret = g[s];
    if(n == 1) ret = s[0]-'0'+1;
    for(int i = 1; i <= n-1; ++i)
        if(n%i == 0)
        {
            string t = "";
            for(int j = 1; j <= i; ++j)
            {
                int c = 1;
                for(int k = j-1; k < n; k += i) c &= s[k]-'0';
                t += char(c+'0');
            }
            ret = (ret+F(t))%P;
        }
    return ret;
}
int64 F(string s)
{
    if(f.count(s)) return f[s]; 
    int n = s.size(); int64 &ret = f[s]; 
    if(!n) return ret = 1;
    for(int i = 1; i <= n; ++i) 
        ret = (ret+G(s.substr(0, i))*F(s.substr(i, n))%P)%P;
    return ret;
}
int main()
{
    cin>>s; printf("%lld\n", F(s));
    return 0;
}

Measured memory_bytes: 12928
/**
 *    author:   K.R.Surrya  
 *    created:  03/05/2020 14:40:16
**/
#include<bits/stdc++.h>
#define vi vector<int>
#define vii vector<vector<int> >
#define vpi vector<pair<int,int> >
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pb push_back
using namespace std; 

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it)  { return ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a,Args... args)
{
    cerr << *it << " = " << a <<endl;
    err(++it,args...);   //args is going to end.
}

void solve() { 
  int N,M,Q;
  cin >> N >> M >> Q;
  vector<int> A(Q),B(Q),C(Q),D(Q);
  rep(i,0,Q) cin >> A[i] >> B[i] >> C[i] >> D[i];
  vector<int> start(N+1,1);
  int ret=0;
  auto dfs=[&](auto &&func,int d) -> void {
       if(d == N) {
           int tmp=0;
           rep(i,0,Q) {
               tmp += (start[B[i]-1]-start[A[i]-1]==C[i])*D[i];
           }
           ret=max(ret,tmp);
           return ;
       }

       for(int nxt=start[d];nxt<=M;++nxt) {
           start[d]=nxt;
           start[d+1]=nxt;
           func(func,d+1);
       }
  };

  dfs(dfs,0);
  cout << ret << '\n';
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);


     auto start = chrono::high_resolution_clock::now();
     solve();
     auto end = chrono::high_resolution_clock::now();

     cerr << " Execution time : " << chrono::duration_cast<chrono::milliseconds>(end-start).count()<<"ms"<<endl;

   
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <ctype.h>
#include <string.h>
void sfl(char card[],int len, int m){
    int i,n;
    char ss[1];
    for(n=0;n<m;n++){
        ss[0]=card[0];
        for(i=0;i<len-1;i++){
            card[i]=card[i+1];
        }
        card[len-1]=ss[0];
        
    }
}


int main(void){
   int i,n,m,len;
   char c[201]={};
   char brun[2]="-";
   for(;;){
       scanf("%s",c);
       if(strcmp(c,brun)==0)break;
       scanf("%d",&m);
       len=strlen(c);
       for(i=0;i<m;i++){
           scanf("%d",&n);
           sfl(c,len,n);
          // printf("%s\n",c);
       }
       printf("%s\n",c);
   }
   
    return 0;
}


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

int gcd(int a, int b){
  //a < b ユークリッドの互除法
  if(a==0) return b;
  return gcd(b%a,a);
}

//lcm = a*b/gcd
int main(){
  int a,b;
  while(cin >> a >> b){
    int g = gcd(a,b);
    cout << g << " " << a/g *b << endl;
  }
  return 0;
}

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


int main() {
  long S;cin>>S;
  vector<long> dp(S+1,0);
  long mod=1000000007;
  dp[0]=1;
  for(int i=0;i<=S-3;i++){
    for(int j=i+3;j<=S;j++){
      dp[j]=(dp[j]+dp[i])%mod;
    }
  }
  cout<<dp[S]%mod<<endl;
}

Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);

		while (true) {
			String str = br.readLine();

			String[] num = getElement(str);

			int h = Integer.parseInt(num[0]);
			int w = Integer.parseInt(num[1]);

			if (h == 0 && w == 0) {
				break;
			}
			for (int i = 0; i < h; i++) {
				if(i==0||i==h-1){
					for (int j = 0; j < w; j++) {
						System.out.print("#");
					}
				}else{
					for (int j = 0; j < w; j++) {
						if(j==0||j==w-1){
							System.out.print("#");
						}else{
							System.out.print(".");
						}
					}
				}
				System.out.print("\r\n");
			}
			System.out.print("\r\n");
		}

	}

	//??????????????????????????????????????????
	public static String[] getElement(String element) {
		return (element.split(" "));
	}
}

Measured memory_bytes: 34848
from collections import deque
import sys
input = lambda: sys.stdin.readline().rstrip()
d = deque(input())

reverse = -1
n = int(input())
for i in range(n):
    query = input().split()
    if len(query) == 1:
        reverse *= (-1)
    else:
        f = int(query[1])
        c = query[2]
        if reverse == -1:
            if f == 1:
                d.appendleft(c)
            else:
                d.append(c)
        else:
            if f == 1:
                d.append(c)
            else:
                d.appendleft(c)

if reverse == 1:
    d.reverse()
# print(d)
print("".join(d))


Measured memory_bytes: 8692
a = list(input())
b = list(input())
c = list(input())
pre = a

def abcpop(lis):
    if lis[0] == "a":
        lis.pop(0)
        pre = a
    elif lis[0] == "b":
        lis.pop(0)
        pre = b
    elif lis[0] == "c":
        lis.pop(0)
        pre = c
    return pre
while a != [] and b != [] and c != []:
    pre = abcpop(pre)
if a == []:
    print("A")
elif b == []:
    print("B")
elif c == []:
    print("C")
    
        
    
    

Measured memory_bytes: 3064
import std.algorithm;
import std.range;
import std.math;
import std.regex;
import std.array;
import std.container;
import std.stdio;
import std.string;
import std.conv;

string[] readStrs() { return readln.chomp.split(' '); }
T[] readInts(T)() { return readln.chomp.split(' ').map!(to!T).array(); }


void main()
{
    auto ss = readStrs();
    if(ss[1] == "+")
        writeln(ss[0].to!long + ss[2].to!long);
    else
        writeln(ss[0].to!long - ss[2].to!long);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lg long long int
#define loop(i,s,e) for(lg i=s;i<=e;i++)
#define iloop(i,s,e) for(lg i=e;i>=s;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007


using namespace std;

lg min(lg a,lg b)
{return a<b?a:b;}
lg max(lg a,lg b)
{return a>b?a:b;}
lg lcm(lg a ,lg b)
{
    return (a*b)/__gcd(a,b);
}
lg n,m,k,ans;
int main()
{
    cin>>n;
    ans=0;
    for(lg i=1;i<n;i++)
    {
        lg a = n/i;
        ans+=a;
        if(n%i == 0) ans--;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3632
#define _CRT_SECURE_NO_WARINGS
#include <iostream>
#include <iomanip>
#include <map>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <fstream>
#include <map>
#include <unordered_map>

using namespace std;
typedef int me;
typedef long long ll;
typedef unsigned long long ull;

#define andrew ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define sz(v) (int)(v.size())
#define all(v) v.begin(), v.end()
#define PI 3.1415926535
#define sin(i) (long double)sin(i *PI / 180.0)
#define cos(i) (long double)cos(i * PI/ 180.0)

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ull lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int dy8[] = { 0, 0, 1, -1, 1, -1, -1, 1 };
int dx8[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int id8[] = { 0, 1, 2, 3, 4, 5, 6, 7 };

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

    vector<ll>mem(100005, 1e9);
    
    mem[0] = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j <= i + k; j++)
        {
            if (j < n)
                mem[j] = min(mem[j], mem[i] + abs(v[i] - v[j]));

        }
    }

    cout << mem[n - 1] << endl;

    




}


Measured memory_bytes: 4796
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

int main(){
    int n,ans = 0;
    int kane[] = {500,100,50,10,5,1};
    cin >> n;
    while(n) {
        ans = 0;
        n = 1000-n;
        for(int i = 0;i < 6;i++) {
            ans += n/kane[i];
            n %= kane[i];
        }
        cout << ans << endl;   
        cin >> n;
    }
}



Measured memory_bytes: 3032
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

using fint64 = int_fast64_t;
template<fint64 MOD>
struct ModInt{
    fint64 x;
    ModInt():x(0){}
    ModInt(fint64 x):
        x(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD)
        {}
    // 負号
    ModInt operator -() const{
        return ModInt(-x);
    }
    // 加算
    ModInt &operator +=(const ModInt &rhs){
        x+=rhs.x;
        if(x>=MOD) x-=MOD;
        return (*this);
    }
    ModInt operator +(const ModInt &rhs) const{
        return ModInt(*this)+=rhs;
    }
    // 減算
    ModInt &operator -=(const ModInt &rhs){
        x+=MOD-rhs.x;
        if(x>=MOD) x-=MOD;
        return (*this);
    }
    ModInt operator -(const ModInt &rhs) const{
        return ModInt(*this)-=rhs;
    }
    // 乗算
    ModInt &operator *=(const ModInt &rhs){
        x*=rhs.x;
        if(x>=MOD) x%=MOD;
        return (*this);
    }
    ModInt operator *(const ModInt &rhs) const{
        return ModInt(*this)*=rhs;
    }
    // 除算
    ModInt &operator /=(const ModInt &rhs){
        (*this)*=rhs.inverse();
        return (*this);
    }
    ModInt operator /(const ModInt &rhs) const{
        return ModInt(*this)/=rhs;
    }
    // 等号
    bool operator ==(const ModInt &rhs){
        return x==rhs.x;
    }
    bool operator !=(const ModInt &rhs){
        return x!=rhs.x;
    }
    // 累乗
    ModInt pow(fint64 n) const{
        fint64 tmp=x;
        fint64 ret=1;
        while(n>0){
            if(n&1) ret=ret*tmp%MOD;
            tmp=tmp*tmp%MOD;
            n>>=1ll;
        }
        return ModInt(ret);
    }
    // 逆元
    ModInt inverse() const{
        fint64 a=x,b=MOD,s=1,t=0;
        while(b>0){
            fint64 u=a/b;
            a-=u*b;
            s-=u*t;
            swap(a,b);
            swap(s,t);
        }
        return ModInt(s);
    }
    // 入出力
    friend istream &operator >>(istream &lhs,ModInt<MOD> &rhs){
        fint64 x; lhs>>x;
        rhs=ModInt<MOD>(x);
        return lhs;
    }
    friend ostream &operator <<(ostream &lhs,const ModInt<MOD> &rhs){
        return lhs<<rhs.x;
    }
};


int main() {
	int n; cin >> n;
	int64_t a[n]; rep(i,n) cin >> a[i];
	int64_t cnt[60] = {};
	for(int i = 0; i < n; ++i) {
		for(int64_t j = 0; j < 60; ++j) {
			if(a[i] >> j & 1) {
				cnt[j]++;
			}
		}
	}
	using mint = ModInt<MOD>;
	mint ans = 0;
	for(int i = 0; i < 60; ++i) {
		mint tmp = 2;
		tmp = tmp.pow(i);
		ans += tmp * cnt[i] * (n - cnt[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N, M;
    cin >> N >> M;
    priority_queue<int> q;
    rep(i, N) {
        int a;
        cin >> a;
        q.push(a);
    }

    rep(i, M) {
        int a = q.top();
        q.pop();
        q.push(a / 2);
    }

    ll ans = 0;

    rep(i, N) {
        ans += q.top();
        q.pop();
    }

    cout << ans << endl;
}


Measured memory_bytes: 892
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	s := readString()
	k := readInt()
	m := make(map[string]bool)
	for i := 1; i <= k; i++ {
		for j := 0; j+i <= len(s); j++ {
			m[s[j:j+i]] = true
		}
	}

	a := make([]string, 0, len(m))
	for w := range m {
		a = append(a, w)
	}
	sort.Strings(a)
	println(a[k-1])
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 2304
//Never stop chasing!-MdSourav.
#include <bits/stdc++.h>

#define yes            cout<<"YES"<<endl
#define no             cout<<"NO"<<endl
#define sz(x)          x.size()
#define ll                    long long int
#define ls             long int
#define start          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test           int t;cin>>t;while(t--)
#define f(i, a, n)     for(int i=a; i<n;i++)
#define gcd(a,b)7           __gcd(a,b)
#define lcd(a,b)       (a*b)/gcd(a,b)
#define pb             push_back
#define mp(x,y)        make_pair(x,y)
#define rsrt(v)        sort(v.begin(),v.end(),greater<int>())
#define srt(v)         sort(v.begin(),v.end())
#define basrt(a,n)     sort(a,a+n,greater<int>())
#define asrt(a,n)      sort(a,a+n)
#define fact(n)        ll x=1;for(ll i=1;i<=n;i++){x=(x*i);}
#define F              first
#define S              second
#define deb(x)         cout << #x << ": " << x << endl;
#define enter(v,n)     for(ll i=0;i<n;i++){ll x;cin>>x;v.pb(x);}
#define INF 	       1000000007
#define unique(v)      v.erase(unique(v.begin(),v.end()),v.end())
using namespace std;

double pi=3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664 ;
typedef vector<ll> vll ;
typedef vector<int> vii ;

template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v)
{
    os << '{';
    for (const auto &x : v) os << " " << x;
        return os << '}';
}

void solve()
{

        string s;cin>>s;
        for(int i=0;i<s.size();i++)
		{
			if(s[i]=='?')
			{
				s[i]='D';
			}
		}
		cout << s ;


}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    ll test_case=1;
    //cin>>test_case ;
    while(test_case--)
	{
		 solve();
	}

	return 0;
}

Measured memory_bytes: 3724
#include<stdio.h>
#include <map>

int main(){
	int n,a,s,t,w,i;

	for(;scanf("%d",&n),n;puts(!a?"Yes":"No")){
		w=a=0;
		std::multimap<int,int> m;
		for(i=n;i--;m.insert(std::pair<int,int>(s,t)))
			scanf("%d%d",&t,&s);
		for(std::multimap<int,int>::iterator i=m.begin();i!=m.end();++i){
			w+=i->second;
      		i->first<w?a=1:0;
    	}
	}
}

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


using namespace std;



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

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

	vector<int> b(n);

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

	sort(b.begin(), b.end());

	int mid_b;
	if (n % 2) {
		mid_b = (b[n / 2]);
	}
	else {
		mid_b = (b[n / 2] + b[n / 2 - 1])/2;
	}

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans += abs(b[i] - mid_b);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
import math
def isprime(N):
    if N==2:
        return True
    elif N<=1 or N%2==0:
        return False
    l = int(math.sqrt(N))
    for i in range(3,l+1,2):
        if N % i == 0:
            return False
        i += 2
    return True

N = int(input())
ans = 0
for i in range(N):
    ans += int(isprime(int(input())))
print(ans)


Measured memory_bytes: 5676
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define N 500009
#define M (L+R)/2
#define inf 999999999999
#define mod 1000000007
#define pb push_back
#define ll long long
map<vector<int>,int> m;
ll n,ans,sum,x,t;
vector <int> v1;
void go(int a,int b,int c,vector<int> v){
    t=1;x=0;
    if(m[v]==1)return;
    m[v]=1;
    for(int i=0;i<v.size();i++){
        x+=t*v[i];
        t*=10;
    }
    if(x>n)return;
    ans++;
    
    for(int i=0;i<=v.size();i++){
        v1.clear();
        for(int j=0;j<i;j++){
            v1.pb(v[j]);
        }
        v1.pb(3);
        for(int j=i;j<v.size();j++){
            v1.pb(v[j]);
        }
        go(a+1,b,c,v1);
        //3
        v1.clear();
        for(int j=0;j<i;j++){
            v1.pb(v[j]);
        }
        v1.pb(5);
        for(int j=i;j<v.size();j++){
            v1.pb(v[j]);
        }
        go(a,b+1,c,v1);
        //5
        v1.clear();
        for(int j=0;j<i;j++){
            v1.pb(v[j]);
        }
        v1.pb(7);
        for(int j=i;j<v.size();j++){
            v1.pb(v[j]);
        }
        go(a,b,c+1,v1);
    }
}

int main() {
    
    ios::sync_with_stdio(0);
    
    cin>>n;
    v1.clear();v1.pb(3);v1.pb(5);v1.pb(7);
    go(1,1,1,v1);
    v1.clear();v1.pb(3);v1.pb(7);v1.pb(5);
    go(1,1,1,v1);
    v1.clear();v1.pb(5);v1.pb(3);v1.pb(7);
    go(1,1,1,v1);
    v1.clear();v1.pb(5);v1.pb(7);v1.pb(3);
    go(1,1,1,v1);
    v1.clear();v1.pb(7);v1.pb(3);v1.pb(5);
    go(1,1,1,v1);
    v1.clear();v1.pb(7);v1.pb(5);v1.pb(3);
    go(1,1,1,v1);
  
    cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 10624
import java.util.*;
class Main{
	
    public static void main(String args[]){
    	Scanner sc=new Scanner(System.in);
    	String a=sc.next();
    	String b =sc.next();
    	int x=0;
    	int y=0;
    	switch(a) {
    	case "A":
    			x=0;
    			break;
    	case "B":
    			x=1;
    			break;
    	case "C":	
    			x=2;
    			break;
    	case "D":	
    			x=3;
    			break;
    	case "E":
    			x=4;
    			break;
    	case "F":
    			x=5;
    			break;
    	}
    	switch(b) {
    	case "A":
    			y=0;
    			break;
    	case "B":
    			y=1;
    			break;
    	case "C":	
    			y=2;
    			break;
    	case "D":	
    			y=3;
    			break;
    	case "E":
    			y=4;
    			break;
    	case "F":
    			y=5;
    			break;
    	}

    	System.out.println(x>y?">":x<y?"<":"=");
    }
}
  

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

char p[256], q[256];

void solve() {
  string s, t; cin >> s >> t;
  int n = s.size();
  for (int i = 0; i < n; ++i) {
    if (p[t[i]] && p[t[i]] != s[i]) {
      puts("No");
      return;
    }
    p[t[i]] = s[i];
    if (q[s[i]] && q[s[i]] != t[i]) {
      puts("No");
      return;
    }
    q[s[i]] = t[i];
  }
  puts("Yes");
}

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


Measured memory_bytes: 916
str = input()
ans = 0
list_ans=[]
flag = 0
for i in range(len(str)):
    if str[i] == 'R':
        if flag == 0:
            ans = 1
        else:
            ans += 1
        flag = 1
    else:
        flag = 0
        list_ans.append(ans)
list_ans.append(ans)
print(max(list_ans))

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

using namespace std;
typedef long long int ll;

int main()
{
    ll n;
    cin >> n;
    vector<ll>a(n),b(n),c(n);
    for(ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for(ll i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    for(ll i = 0; i < n; i++)
    {
        cin >> c[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    ll ans = 0;
    for(ll i = 0; i < n; i++)
    {
        vector<ll>::iterator itr1 = lower_bound(a.begin(),a.end(),b[i]);
        vector<ll>::iterator itr2 = upper_bound(c.begin(),c.end(),b[i]);
        itr1--;
        if(itr2 == c.end())
        {
            break;
        }
        ll dis1 = distance(a.begin(),itr1);
        ll dis2 = distance(c.begin(),itr2);
        ans += (dis1 + 1)*(n - dis2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5616
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	int n, a;
	cin >> n >> a;
	cout << n * n - a << endl;
}



Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(s);
  cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
}

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

int main()
{
  int N;
  int L[100];
  int max=0;
  int tmp=0;
  cin >> N;
  for(int i=0; i<N; i++)
  {
    cin >> L[i];
    if(L[i] > max){
      max = L[i];
    }
    tmp += L[i];
  }
  tmp = tmp-max;
  if (max<tmp)
  {
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  return 0;
}

  

Measured memory_bytes: 256
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for i in range(M):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    data.append((b,a))

data.sort()

ans = 1
right = data[0][0]
for b,a in data:
    if a < right:
        continue
    else:
        ans += 1
        right = b
print(ans) 

Measured memory_bytes: 17056
#include <cstdio>

int main(void)
{
	int ch;
	int chCounts[26] = {};
	while ((ch = getchar()) != EOF) {
		if ('a' <= ch && ch <= 'z') {
			chCounts[ch - 'a']++;
		}
		else if ('A' <= ch && ch <= 'Z') {
			chCounts[ch - 'A']++;
		}
	}
	for (int i = 0; i < 26; i++) {
		printf("%c : %d\n", 'a' + i, chCounts[i]);
	}
	return 0;
}

Measured memory_bytes: 2692