akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  while(true){
   int n = sc.nextInt();
   if(n == 0)
    break;
   int data[] = new int[n];
   for(int i = 0 ; i < n ; i++)
    data[i] = sc.nextInt();
   int sum = data[0];
   for(int i = 1 ; i < n ; i++)
    sum += data[i];
   double ave = (double)sum / n;
   double a2 = 0;
   for(int i = 0 ; i < n ; i++)
    a2 += Math.pow(data[i]-ave , 2.0);
   a2 /= (double)n;
   double a = Math.sqrt(a2);
   System.out.println(a);
  }
 }
}


Measured memory_bytes: 31552
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define hashset unordered_set
#define hashmap unordered_map
#define getbit(x, i) (((x) >> (i)) & 1)
using namespace std;
typedef pair<int, int> pii; 
template <typename T>
inline vector<T> readvector(size_t size) {
    vector<T> res(size);
    for (size_t i = 0; i < size; ++i) {
        cin >> res[i];
    }
    return res;
}
template <typename T>
inline void printvector(vector<T>& arr, string sep = " ", string ends = "\n") {
    for (size_t i = 0; i < arr.size(); ++i) {
        cout << arr.at(i) << sep;
    }
    cout << ends;
}
inline int binPow(int x, int deg, int mod) {
    int ans = 1;
    for (int i = sizeof(x) * CHAR_BIT - 1; i >= 0; i--) {
        ans *= ans;
        ans %= mod;
        if (getbit(deg, i)) ans *= x;
        ans %= mod;
    }
    return ans;
}
// ====================== END ======================
const int MAXN = 1e6 + 10;
const int MOD = 1e9 + 7;


int cnt[MAXN];

void proc(int x) {
    for (int div = 2; div * div <= x; div++) {
        int cn = 0;
        while (x % div == 0) {
            cn++;
            x /= div;
        }
        if (cn) {
            cnt[div] = max(cnt[div], cn);
        }
    }
    if (x) {
        cnt[x] = max(cnt[x], 1ll);
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int n;
    cin >> n;
    auto arr = readvector<int>(n);
    int x = 1;
    for (auto e : arr) proc(e);

    for (int i = 0; i < MAXN; ++i) {
        if (cnt[i]) {
            x *= binPow(i, cnt[i], MOD);
            if (x > MOD) {
                x %= MOD;
            }
        }
    }
    // cout << x << endl;

    int sm = 0;
    for (auto e : arr) {
        sm += binPow(e, MOD - 2, MOD);
    }
    sm %= MOD;
    cout << (sm * x) % MOD << endl;

    return 0;
}   

Measured memory_bytes: 6656
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < N; i++) {
			list.add(scan.nextInt());
		}
		selectionSort(list);
	}

	public static void selectionSort(List<Integer> list) {
		int tail = -1;
		int count = 0;
		while (tail < list.size() - 1) {
			int min = list.get(tail + 1);
			int minIdx = tail + 1;
			for (int i = minIdx + 1; i < list.size(); i++) {
				if (min > list.get(i)) {
					min = list.get(i);
					minIdx = i;
				}
			}
			if (list.get(tail + 1) > min) {
				list.set(minIdx, list.get(tail + 1));
				list.set(tail + 1, min);
				count++;
			}
			tail++;
		}
		showList(list);
		System.out.println(count);
	}

	public static void showList(List<Integer> list) {
		for (int i = 0; i < list.size() - 1; i++) {
			System.out.print(list.get(i));
			System.out.print(" ");
		}
		System.out.println(list.get(list.size() - 1));
	}
}



Measured memory_bytes: 26688
n = gets.to_i
mat = Array.new(n){Array.new(n){0}}
n.times{
  i, m, *arr = gets.split.map(&:to_i)
  if m != 0
    arr.each{|j|
      mat[i-1][j-1] = 1
    }
  end
}

n.times{|i|
  puts mat[i].join(" ")
}

Measured memory_bytes: 8836
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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; }

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

int main () {
  int N; cin >> N;
  vector<tuple<string,int,int>> data(N);

  REP(i,N) {
    string S; int P;
    cin >> S >> P;
    data[i] = make_tuple(S,-P,i+1);
  }

  SORT(data);

  REP(i,N) {
    cout << get<2>(data[i]) << endl;
  }  
}

Measured memory_bytes: 256
#include <stdio.h>
char* F(char *b,int n,FILE *f){char *r=fgets(b,n,f);if(!r)return NULL;b[strlen(b)-1]=0;return r;}
char Q[29999],*q[9],L[29999];
n;D(old_indent,depth){for(;;){
	int indent=0;
	if(!F(L,sizeof(L),stdin))puts("no such property"),exit(0);
	for(;L[indent]==' ';indent++);
	if(old_indent>=indent)puts("no such property"),exit(0);
	char *name=strtok(L+indent,":"),*value=name+strlen(name)+1;
	if(!strcmp(name,q[depth])){
		if(depth==n-1)
			if(*value)printf("string \"%s\"\n",value+1),exit(0);
			else puts("object"),exit(0);
		old_indent=indent,depth++;
	}
}}
main(){F(Q,sizeof(Q),stdin);q[0]=strtok(Q+1,".");for(n=1;;n++)if(!(q[n]=strtok(NULL,".")))break;D(-1,0);}

Measured memory_bytes: 588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class t, class u> bool cmax(t& a, u b) { if (a<b) {a = b; return true;} else return false; }
template<class t, class u> bool cmin(t& a, u b) { if (a>b) {a = b; return true;} else return false; }

ll modpow(ll a, ll n, ll p) {
  ll res = 1;
  while (n) {
    if (n&1) res = res * a % p;
    a = a * a % p;
    n >>= 1;
  }
  return res;
}

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

  string l;
  cin >> l;
  int n = l.size();

  const ll mod = 1e9+7;
  ll ans = 0;
  int bit_cnt = 0;

  rep(i, n) {
    if (l[i] == '1') {
      ans = (ans + modpow(2, bit_cnt, mod)*modpow(3, n-(i+1), mod)) % mod;
      bit_cnt++;
    }
  }
  ans = (ans + modpow(2, bit_cnt, mod)) % mod;
  cout << ans << endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int[] nums = new int[w];
		for (int i = 0; i < w; ++i) {
			nums[i] = i + 1;
		}
		int n = sc.nextInt();
		int[][] sw = new int[n][2];
		for (int i = 0; i < n; ++i) {
			String[] str = sc.next().split(",");
			sw[i][0] = Integer.parseInt(str[0]) - 1;
			sw[i][1] = Integer.parseInt(str[1]) - 1;
		}
		for (int i = 0; i < n; ++i) {
			int temp = nums[sw[i][0]];
			nums[sw[i][0]] = nums[sw[i][1]];
			nums[sw[i][1]] = temp;
		}
		for (int i = 0; i < w; ++i) {
			System.out.println(nums[i]);
		}
		sc.close();
	}
}


Measured memory_bytes: 25828
#include <bits/stdc++.h>
 
using namespace std;
 
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b) for(int (i) = (a); (i) < (b); (i)++)
#define debug(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<pair<int,int>>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3fLL;
const int maxn = 1e3+10;

int main(int argc,const char** argv){

	//fastio;

	ll n,k;

	cin >> n >> k;

	double ans = 0;

	for(int i=1;i<=n;++i){
		double chance = 1.0/n;
		for(int j=i;j<k;j*=2){
			chance/=2;
		}
		ans+=chance;
	}

	printf("%.12lf\n",ans);

	return 0;
}

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

typedef long long ll;

int main() {
    ll a[7];
    rep(i, 7) cin >> a[i];
    ll ans = a[1] + a[0] / 2 * 2 + a[3] / 2 * 2 + a[4] / 2 * 2;
    if (a[0] > 0 && a[3] > 0 && a[4] > 0) {
        ans = max(ans, a[1] + 3 + (a[0] - 1) / 2 * 2 + (a[3] - 1) / 2 * 2 + (a[4] - 1) / 2 * 2);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();



int main(){

  int n,t,a; cin>>n>>t>>a;



  int min_num, min_diff =MAX ;

  REP(i,n){
    int h;
    cin >> h;
    if(min_diff>abs((t*1000-h*6)-a*1000)){
      min_diff = abs((t*1000-h*6)-a*1000);
      min_num = i + 1;
    }
  }

  cout << min_num << endl;
}



Measured memory_bytes: 256
S = input()
T = input()
 
ans = 'UNRESTORABLE'
for i in range(len(S) - len(T) + 1):
    s = S[i:i+len(T)+1]
    flag = 1
    for j in range(len(T)):
        if s[j] == T[j] or s[j] == '?':
            pass
        else:
            flag = 0
    if flag:
        ans = S[0:i] + T + S[i+len(T):]
        ans = ans.replace('?', 'a')
print(ans)

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

using namespace std;

int main()
{
    //simple approach by using 3*3 matrix and searching the given elements one by one
    int n,a[3][3],i,j,cnd=0;
    for(i=0;i<3;i++){
        for(j=0;j<3;j++)
            scanf("%d",&a[i][j]);
    }
    scanf("%d",&n);
    int b;
    //creating c matrix of n*2 to store positions of each element in the given 3*3 matrix
    bool c[3][3];
    for(i=0;i<3;i++){
        for(j=0;j<3;j++)
            c[i][j]=false;
    }
    while(n--){
        scanf("%d",&b);
        for(i=0;i<3;i++){
            for(j=0;j<3;j++){
               if(b==a[i][j])
                  c[i][j]=true;
            }
        }
    }

    for(i=0;i<3;i++){
        if(c[i][0]&&c[i][1]&&c[i][2]||c[0][i]&&c[1][i]&&c[2][i]){
          cnd=1;
          break;
        }
    }
    if(cnd==1||c[0][0]&&c[1][1]&&c[2][2]||c[0][2]&&c[1][1]&&c[2][0]) printf("Yes\n");
        else printf("No\n");

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long w,h,x,y,r;
	cin >> w >> h >> x >> y >> r;
	if (r <= x && x <= w - r && r <= y && y <= h - r){
		cout << "Yes" << endl;
	} else cout << "No" << endl;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  int ans = 0;
  for(int i = 0; i < N - 1; ++i){
    ans += (S[i] == S[i + 1]);
  }
  ans = min(N - 1, ans + 2 * K);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int N=1e6+5;
int n,m,ans,a[N];
char s[N];
//char buf[1<<21],*p1=buf,*p2=buf;
//inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
signed main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	if(n&1){puts("No");return 0;}
	for(int i=1;i<=n;i++)
	{
		if(i&1)
		{
			if(s[i]!='h'){puts("No");return 0;}
		}
		else{
			if(s[i]!='i'){puts("No");return 0;}
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
    int i,n,m,min,max;
    long long sum;
    sum = 0;
    scanf("%d", &n);
    for (i = 0;i<n;i++){
        scanf("%d", &m);
        if(i == 0){
            min = m;
            max = m;
        }
        if (min > m){
            min = m;
        }
        if (max < m){
            max = m;
        }
        sum += m;
    }
    printf("%d %d %lld\n",min,max,sum);
    return(0);
}

Measured memory_bytes: 600
# ABC 143 D - Triangles
# https://atcoder.jp/contests/abc143/tasks/abc143_d

n = gets.chomp.to_i
l = gets.chomp.split(/ /).map(&:to_i).sort.reverse

class Stick
  def initialize(length, index)
    @length = length
    @index = index
  end

  attr_reader :length, :index
end

sticks = l.map.with_index(0) { |length, i| Stick.new(length, i) }

# puts sticks.inspect
# puts ""

count = 0
0.upto(n - 3) do |i|
  a = sticks[i]
  (i + 1).upto(n - 2) do |j|
    b = sticks[j]
    c_candidates = sticks[(j + 1)..(n - 1)]
    t = a.length - b.length
    c_over = c_candidates.bsearch { |stick| stick.length <= t }
    if c_over.nil?
      c_last_index = n - 1
    else
      c_last_index = c_over.index - 1
    end
    # puts c_candidates.inspect
    # puts "a: #{a}, b: #{b}, a - b: #{t} -> #{c_last_index - j}"
    # puts ""
    count += c_last_index - j
  end
end

puts count


Measured memory_bytes: 2296
class segtree:
    def __init__(self,N):
        self.n=(1<<len(bin(N-1)[2:]))
        self.x=[0 for _ in range(2*self.n)]
    def build(self,seq):
        for i, j in enumerate(seq, start=self.n):
            self.x[i]=1<<j
        for i in range(self.n-1, 0, -1):
            self.x[i]=self.x[i*2]|self.x[i*2+1]
    def update(self, i, c):
        j=i+self.n
        self.x[j]=1<<c
        while j>1:
            j//=2
            self.x[j]=self.x[j*2]|self.x[j*2+1]
    def get(self,l,r):
        ans=0
        l+=self.n
        r+=self.n
        while l<r:
            if l%2==1:
                ans|=self.x[l]
                l+=1
            if r%2==0:
                ans|=self.x[r]
                r-=1
            l//=2
            r//=2
        if l==r:
            ans|=self.x[l]
        cnt=sum(list(map(int, list(bin(ans)[2:]))))
        print(cnt)
        
n=int(input())
s=list(input())
s=[ord(i)-97 for i in s]
seg=segtree(n)
seg.build(s)
#print(seg.x)
for _ in range(int(input())):
    que=list(input().split())
    if que[0]=='1':
        seg.update(int(que[1])-1, ord(que[2])-97)
    elif que[0]=='2':
        seg.get(int(que[1])-1,int(que[2])-1)

Measured memory_bytes: 118288
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int a,b;
	cin>>a>>b;
	if(a%3==0||b%3==0||(a+b)%3==0){
		cout<<"Possible"<<endl;
	}
	else{
		cout<<"Impossible"<<endl;
	}
}

Measured memory_bytes: 256
s = input()
oz = 0
zo = 0
for i in range(len(s)):
  if i%2 == 0 and s[i] == '0':
    oz += 1
  elif i%2 == 0 and s[i] == '1':
    zo += 1
  elif i%2 == 1 and s[i] == '1':
    oz += 1
  elif i%2 == 1 and s[i] == '0':
    zo += 1
print(min(zo, oz))   

Measured memory_bytes: 3188
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if X == 500*a+100*b+50*c:
                ans +=1
print(ans)

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N,M;
    Scd2(N,M);
    vi h(N);
    Rep(i,N) Scd(h[i]);

    vector<vi> e(N);
    int u,v;
    Rep(i,M){
        Scd2(u,v);
        u--,v--;
        e[u].push_back(v);
        e[v].push_back(u);
    }

    vi ht(N,0);
    int ans = 0;
    Rep(from,N){
        bool ht = true;
        for( int to : e[from] ){
            if( h[from] <= h[to] ) ht = false;
        }
        ans += ht;
    }

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


    return 0;
}



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

bool isPalindrome(string a) {
    string arev = a;
    reverse(arev.begin(), arev.end());
    if(a==arev) {
        return true;
    }
    else {
        return false;
    }
}

int main() {
    string a;
    cin >> a;
    int len = a.length();
    if(!isPalindrome(a)) cout << "No\n";
    else if(!isPalindrome(a.substr(0, (len-1)/2))) cout << "No\n";
    else if(!isPalindrome(a.substr(((len+3)/2)-1, (len-1)/2))) cout << "No\n";
    else cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>

using namespace std;

static uint64_t Gcd(uint64_t m, uint64_t n)
{
    uint64_t temp;
    while (m % n != 0)
    {
        temp = n;
        n = m % n;
        m = temp;
    }
    return n;
}

static uint64_t Lcm(uint64_t m, uint64_t n)
{
    uint64_t gcd = Gcd(m,n);
    return (m * n / gcd);
}

int main(int argc, const char * argv[]) {
    uint64_t A = 0;
    uint64_t B = 0;
    uint64_t C = 0;
    uint64_t D = 0;
    cin >> A >> B >> C >> D;

    uint64_t cx = (B/C) - (A-1)/C;// C の倍数を数える
    uint64_t dx = (B/D) - (A-1)/D;// D の倍数を数える

    const uint64_t lcm = Lcm(C, D);
    uint64_t cdx = (B/lcm) - (A-1)/lcm;

    uint64_t all = B-A+1;
    uint64_t result = all - cx - (dx-cdx) ;
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	int A;
	for (int i=0;i<N;i++){
		cin>>A;
		if (A%2==0){
			if (A%3==0 || A%5==0){
			}else{
				cout<<"DENIED"<<endl;
				return 0;
			}
		}
	}
	cout<<"APPROVED"<<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)

int M, N;
string grid[1010], pat[2], JOI = "JOI";

bool isok(int i, int j) {
	if (i < 0 || j < 0 || i >= M - 1 || j >= N - 1) return false;
	for_(k,0,2) for_(l,0,2) if (grid[i + k][j + l] != pat[k][l]) return false;
	return true;
}

int center(int i, int j) {
	int res = 0;
	for_(y,-1,1) for_(x,-1,1) if (isok(i+y, j+x)) ++res;
	return res;
}

int main() {
	cin >> M >> N;
	for_(i,0,M) cin >> grid[i];
	for_(i,0,2) cin >> pat[i];
	
	int ini = 0;
	for_(i,0,M) for_(j,0,N) {
		if (isok(i, j)) ++ini;
	}
	
	int ans = 0;
	for_(i,0,M) for_(j,0,N) {
		int cur = center(i,j), nx = 0;
		
		char c = grid[i][j];
		for_(k,0,3) {
			grid[i][j] = JOI[k];
			nx = max(nx, center(i,j));
		}
		grid[i][j] = c;
		
		ans = max(ans, ini + nx - cur);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2264
s=input()
arr1=["R","U","D"]
arr2=["L","U","D"]
for i in range(len(s)):
  if (i%2==0 and not (s[i] in arr1)) or (i%2==1 and not (s[i] in arr2)):
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 3060
#include<stdio.h>

typedef struct pair* ppair;

typedef struct pair{
    int first, second;
} pair;


int size;
pair v[1000000];
int psize;
int preorder[1000000];

void swap(ppair a, ppair b){
    pair t = *a;
    *a = *b;
    *b = t;
}

int getp(int begin, int end){
    int i;
    int p = begin;
    for(i = begin+1; i <end; ++i){
        if(v[i].first < v[p].first){
            p = i;
        }
    }
    swap(&v[end-1], &v[p]);
    return end-1;
}

void qsort(int begin, int end){
    int i, j;
    if(begin >= end) return;
    getp(begin,end);
    preorder[psize++] = v[end-1].second;
    if(begin+1 == end) return;
    for(i = begin, j = begin; i<end; i++){
        if(v[i].second < v[end-1].second){
            swap(&v[i], &v[j++]);
        }
    }
    swap(&v[j],&v[end-1]);
    qsort(begin, j);
    qsort(j+1, end);
}

int main(){
    int i, j;
    int n, k;
    char s[100];
    size = 0;
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%s", s);
        if(s[0] == 'i'){
            scanf("%d", &k);
            v[size++] = (pair){i,k};
        } else {
            psize = 0;
            qsort(0, size);
            for(j=0; j<size; j++){
                printf(" %d", v[j].second);
            }
            printf("\n");
            for(j=0; j<size; j++){
                printf(" %d", preorder[j]);
            }
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 7704
#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;
    int M;
    map<int,string> ans_list;
    cin >> N >> M;
    int tmp1;
    string tmp2;
    map<int,int> WA_count;
    set<int> ans_num;
    int count = 0;
    rep (i,M){
        cin >> tmp1 >> tmp2;
        if (tmp2 == "AC"){
            ans_num.insert(tmp1);
            ans_list[tmp1] = tmp2;
        }
        else{
            if(ans_list[tmp1] != "AC"){
                 WA_count[tmp1] += 1;
            }
        }
    }
    for (const auto& [key, value] : ans_list){
            if (ans_list[key] == "AC"){
                count += WA_count[key];
            }
    }
    cout << ans_num.size() << " " << count << endl;
    return 0;
}

Measured memory_bytes: 20780
#include<cstdio>
#include<algorithm>
using namespace std;



long long n,a[1008],b[1008],k,c[1008],val[1008],ans,tmp;

void meiju(long long qw)
{
	for(long long i=1;i<=n;i++)
	{
	if(qw&1) a[i]=-a[i];
	if(qw&(1<<1)) b[i]=-b[i];
	if(qw&(1<<2)) c[i]=-c[i];
}
}

bool cmp(long long a,long long b)
{return a>b;}

int main()
{
	scanf("%lld%lld",&n,&k);
	long long i,j;
	for(i=1;i<=n;i++) scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
	for(i=0;i<8;i++)
	{
		meiju(i);
		for(j=1;j<=n;j++) val[j]=a[j]+b[j]+c[j];
		sort(val+1,val+n+1,cmp);
		tmp=0;		
		for(j=1;j<=k;j++)
		tmp+=val[j];
		ans=max(tmp,ans);
		meiju(i);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

int main(){

  int n;
  cin >> n;

  cout << n/3 << endl;

  return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    ll rn = (ll)sqrt(n);
    
    cout << n << ":";
    
    for(ll i=2; i<=rn; ++i){
        while((n % i) == 0){
            cout << " " << i;
            n /= i;
            if(n == 1){ break; }
        }
    }
    if(n != 1){
        cout << " " << n;
    }
    
    cout << endl;
    
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) {__l(__LINE__);__f(#__VA_ARGS__, __VA_ARGS__);}
inline void __l(int line) { cerr << "#" << line << ": "; }template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = 5*(int)1e5 + 10;
// make sure N size is correctttt!!!!!!!!!


int n;
vector<P> v;

int32_t main(){_

   cin>>n;

   for (int i = 0; i < n; ++i)
   {
      int a, b;
      cin>>a>>b;
      v.pb({a+b, b});
   }

   sort(v.rbegin(), v.rend());

   int ans = 0;
   for (int i = 0; i < n; ++i)
   {
      v[i].F -= v[i].S;
      if(i % 2 == 0){
         ans += v[i].F;
      }  
      else{
         ans -= v[i].S;
      }
   }

   cout<<ans;
   //make sure N size is correct!!!!!!!!!
   return 0;
}

Measured memory_bytes: 2420
#include<stdio.h>

int main(void){
	
    int a,i,b[100];
	
    scanf("%d",&a);
	
    for(i=0;i<a;i++){
        scanf("%d",&b[i]);
    }
	
    for(i=a-1;i>=0;i--){
       printf("%d",b[i]);
        if(i!=0){
            printf(" ");
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 2672
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int a,b;
int pd(int m)
{
	for(int i=1;i<=10000;i++)
	if(sqrt(m)==i) return 1;
	return 0;
}
int main()
{
	scanf("%d %d",&a,&b);
	int m=b;
	int len=0;
	while(m!=0)
	{
		len++;
		m/=10;
	}
	int num=1;
	for(int i=1;i<=len;i++)
	{
		num*=10; 
	}
	m=a*num+b;
	//printf("%d",m);
	if(pd(m))printf("Yes\n");
	else printf("No\n");
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int d[20], dp[50010];
signed main(void)
{
  int n, m;
  cin >> n >> m;
  REP(i, m) cin >> d[i];
  REP(j, n+5) dp[j] = INF;
  dp[0] = 0;
  REP(i, m) FOR(j, d[i], n+1) {
    if(j >= d[i]) dp[j] = min(dp[j], dp[j-d[i]]+1);
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 3244
#include <cstdio>

const long long mod=1000000007ll;

long long sq(long long a){return a*a%mod;}

long long pw(long long a,long long n)
{
  return n==0?1ll:sq(pw(a,n/2))*(n%2==1?a:1ll)%mod;
}
long long inv(long long a){return pw(a,mod-2);}

int main()
{
  int H,W,A,B;
  scanf("%d%d%d%d",&H,&W,&A,&B);
  static long long P[200010],rP[200010];
  P[0]=rP[0]=1;
  for(int i=1;i<=H+W;i++){
    P[i]=P[i-1]*i%mod;
    rP[i]=rP[i-1]*inv(i)%mod;
  }
  long long ans=0ll;
  for(int i=0;i<=H-A-1;i++){
    ans+=(P[B+i-1]*rP[B-1]%mod*rP[i]%mod)*(P[H-i+W-B-2]*rP[H-i-1]%mod*rP[W-B-1]%mod)%mod;
    ans%=mod;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 3328
n,m=map(int,input().split())
oya=[set() for i in range(n)]
ko=[set() for i in range(n)]
rank=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    ko[a-1].add(b-1)
    oya[b-1].add(a-1)
q=[]
for i in range(n):
    if not oya[i]:
        q.append([i,ko[i]])
while q:
    now,path=q.pop()
    for i in path:
        oya[i].remove(now)
        if not oya[i]:
            q.append([i,ko[i]])
        rank[i]=max(rank[i],rank[now]+1)
print(max(rank))


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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n,r;
    cin >> n >> r;

    if(n<10) print(r+100*(10-n));
    else print(r);
    return 0;
}

Measured memory_bytes: 256
d,n=map(int,input().split())
if d==0:
    if n==100:
        print(101)
    else:
        print(n)
elif d==1:
    if n==100:
        print(10100)
    else:
        print(100*n)
else:
    if n==100:
        print(1010000)
    else:
        print(10000*n)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    ll A,B,C;
    cin>>A>>B>>C;
    cout<<B+min(A+B+1,C)<<endl;;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n,k,s=0,t;cin>>n>>k;
	ll arr[n];
	for(ll i=0;i<n;i++){
		cin>>arr[i];
	}
	sort(arr,arr+n);
	if(n-k>0){
		for(int i=0;i<n-k;i++){
			s += arr[i];
		}
		cout<<s;
	}
	else cout<<0;
}

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

int N, M, Q;
int ce[100000];
vector<int> ve[100000];
int vv[100000], dd[100000], cc[100000];
int x[100000];

void paint( int v, int d, int c ) {
  if ( x[v] == -1 ) {
    ce[v] = c;
    x[v] = 0;
  }
  if ( x[v] >= d ) return;
  if ( ce[v] == 0 ) ce[v] = c;
  if ( d == 0 ) return;
  x[v] = d;
  for ( int i = 0; i < ve[v].size(); i++ ) {
    paint( ve[v][i], d-1, c );
  }
}

int main()
{
  for ( int i = 0; i < 100000; i++ )
    x[i] = -1;

  cin >> N >> M;
  for ( int i = 0; i < M; i++ ) {
    int a, b;
    scanf("%d %d", &a, &b );
    a--; b--;
    ve[a].push_back( b );
    ve[b].push_back( a );
  }

  cin >> Q;
  for ( int i = 0; i < Q; i++ ) {
    scanf( "%d %d %d", &vv[i], &dd[i], &cc[i] );
    vv[i]--;
  }

  for ( int i = Q - 1; i >= 0; i-- ) {
    paint( vv[i], dd[i], cc[i] );
  }

  for ( int i = 0; i < N; i++ ) {
    printf( "%d\n", ce[i] );
  }

  return 0;
}


Measured memory_bytes: 8440
#include<cstdio>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<iostream>
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define rep(i,n) for(int i=1;i<=n;i++)
#define c(ans) cout<<ans<<endl;
using namespace std;
typedef long long ll;

int main(){
	IO;
	ll a, b, c;
	while(cin >> a >> b >> c){
		int n2 = 0;
		if (a % 2 == 0) n2++;
		if (b % 2 == 0) n2++;
		if (c % 2 == 0) n2++;
		if (n2 > 0) cout << "0" << endl;
		else{
			if (a > b) swap(a, b);
			if (b > c) swap(b, c);
			cout << a*b << endl;
		}
	}
	return 0;
}

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

int main()
{
int N1,N2,W1,W2;
cin >> N1 >>N2;
cin >> W1 >>W2;
int chk=0;
if((W2-N2)<0)
{
    chk=1;
}
cout << chk << endl;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S, std::string T){
    if (T.length() > 0) {
        string R = T.substr(0, T.length() - 1);
        if (R.compare(S) == 0) {
            printf("Yes\n");
            return;
        }
    }
    printf("No\n");
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 3592
// Optimised solution (Saves space)
// Converted matrix to an array
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int inf = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 105;

int w[N], v[N];
int dp[100005];

signed main(){
    IOS;
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
    }
    for (int i = 1; i <= n; i++) {
        for (int j = k; j >= 1; j--) {
            if (j - w[i] >= 0)
                dp[j] = max(dp[j], dp[j-w[i]] + v[i]);
        }
    }
    cout << dp[k] << endl;
    return 0;
}


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

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define dbg(x) std::cerr<<#x<<" = " << (x) << std::endl
#define pnl(x) std::cout << x << "\n"

typedef	std::vector<int>	vi;
typedef std::pair<int,int>	ii;
typedef std::vector<std::string>	vs;
typedef std::vector<ii>	vii;
typedef std::vector<long long>	vl;
typedef	long long ll;


const int	NB_D = 4;
const int	DY[] = {-1, 1, 0, 0};
const int	DX[] = {0, 0, -1, 1};

int		main(void)
{
	std::ios_base::sync_with_stdio(false);
	int	n;
	std::cin >>n;
	pnl(48 - n);
}



Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<utility>
#include<set>

using namespace std;

int main(){
  int N;
  cin>>N;
  set<int> s;
  for(int i=0;i<N;i++){
    int H,W;
    cin>>H>>W;
    for(int i=0;i<7;i++){
      for(int j=0;j<7;j++){
	bool f[10][10]={};
	for(int k=0;k<H;k++){
	  for(int l=0;l<W;l++){
	    f[i+k][j+l]=true;
	  }
	}
	int b=0;
	for(int k=0;k<4;k++){
	  for(int j=0;j<4;j++){
	    b|=f[k+3][j+3]<<k*4+j;
	  }
	}
	s.insert(b);
      }
    }
  }
  char C[4][5];
  for(int i=0;i<4;i++){
    cin>>C[i];
  }
  int cb[3]={};
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
      for(int k=0;k<3;k++){
	cb[k]|=(C[i][j]=="RGB"[k])<<i*4+j;
      }
    }
  }
  queue<pair<int,int> > que;
  bool p[1<<16]={};
  que.push({0,(1<<16)-1});
  for(;;){
    auto cs=que.front();
    if(cs.second==0)break;
    que.pop();
    if(p[cs.second]++)continue;
    for(auto e:s){
      int c=0;
      for(int i=0;i<3;i++){
	c+=(cb[i]&cs.second&e)>0;
      }
      if(c==1){
	que.push({cs.first+1,cs.second&~e});
      }
    }
  }
  cout<<que.front().first<<endl;
}

  

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

int max(int a,int b){
  if(a>b) return a;
  else return b;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int x, y, z;
    cin >> x >> y >> z;

    cout << (x - z) / (z + y) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
template<typename A> using V = std::vector<A>;
using vi = V<int>;
using vvi = V<vi>;
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
using namespace std;

int main() {
  int N, W;
  cin >> N >> W;
  vvi dp(N + 1, vi(W + 1));
  vi v(N), w(N);
  rep(i, N) cin >> v[i] >> w[i];
  loop(i, 1, N + 1) rep(j, W + 1) {
    dp[i][j] = dp[i - 1][j];
    if (j - w[i - 1] >= 0) cmax(dp[i][j], dp[i][j - w[i - 1]] + v[i - 1]);
  }
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 6852
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	
	static void aryExchng(double[] a,double[] b){
		for(int i=0; i < ((a.length > b.length) ? b.length:a.length); i++){
			double t = a[i];
			a[i] = b[i];
			b[i] = t;
		}
	}

	static double minOf(double[] a){
		double m = a[0];
		for(double i:a)
			if(m > i) m = i;
		return m;		
	}
	
	static double maxOf(double[] a){
		double m = a[0];
		for(double i:a)
			if(m < i) m = i;
		return m;		
	}
	
	
	public static void main(String[] args) {
		double[] read = new double[10000];
		int i = 0;
		while(sc.hasNext()) read[i++] = sc.nextDouble();
		double[] data = new double[i];
		aryExchng(read,data);
		System.out.printf("%.1f",maxOf(data)-minOf(data));
	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int n; cin>>n;
    vector<int> a(100004,0);
    rep(i,0,n){
        int x; cin>>x;
        a[x+1]++; a[x]++; a[x+2]++;
    }
    int ans=0;
    rep(i,0,100004){
        ans=max(ans,a[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
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);
}
/*-------------------------------------------*/

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

    int n;
    cin >> n;

    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(ALL(a), greater<int>());

    ll sum = 0;
    priority_queue<int> pq;
    pq.push(0);

    rep(i, n) {
        sum += pq.top();
        pq.pop();
        pq.push(a[i]);
        if(i) pq.push(a[i]);
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 5064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        char prev = s.charAt(0);
        for (int i = 1; i < s.length(); ++i) {
            char c = s.charAt(i);
            if (prev == c) {
                System.out.println("Bad");
                return;
            }
            prev = c;
        }
        System.out.println("Good");
    }
}


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

int n, m, s, ans;
int a[105];

int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &a[i]), s += a[i];
	
	s = ceil(s / (4.0 * m));
	
	for(int i = 1; i <= n; ++i)
		if(a[i] >= s) ++ans;
	
	if(ans >= m) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
s = [input() for _ in range(n)]

counter = Counter(s)
count = counter.most_common()
most = count[0][1]

c = []
for i in range(len(count)):
    if most == count[i][1]:
        c.append(count[i][0])

c.sort()
print(*c, sep='\n')

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

int main() {
  int N, X; cin >> N >> X;
  vector<int> x(N);
  for (int i = 0; i < N; ++i) cin >> x[i];
  x.push_back(X);
  sort(begin(x), end(x));
  int ans = x[1] - x[0];
  for (int i = 2; i <= N; ++i) {
    ans = __gcd(ans, x[i] - x[i - 1]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#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);
}

const int N = 1e5+34;

int a[3*N];
map<int, int> s[2];
map<int, int> q;

void solve() {
	int n; scanf("%d", &n);
	for (int i = 0; i < 3*n; ++i) {
		scanf("%d", a+i);
		++s[1][a[i]];
	}
	long long sum[2] = {};
	for (int i = 0; i < n; ++i) {
		sum[0] += a[i];
		++s[0][a[i]];
		if (--s[1][a[i]] == 0) s[1].erase(a[i]);
	}
	for (int i = 0; i < n; ++i) {
		auto x = *s[1].rbegin();
		++q[x.first];
		if (--s[1][x.first] == 0) s[1].erase(x.first);
	}
	for (const auto &e: s[1]) {
		sum[1] += (long long)e.first*e.second;
	}
	long long ans = sum[0]-sum[1];
	debug(sum[0]);
	debug(sum[1]);
	for (int i = n; i < 2*n; ++i) {
		sum[0] += a[i];
		++s[0][a[i]];
		int x = (*s[0].begin()).first;
		sum[0] -= x;
		if (--s[0][x] == 0) s[0].erase(x);
		
		if (q.find(a[i]) != q.end()) {
			if (--q[a[i]] == 0) q.erase(a[i]);
		} else {
			if (--s[1][a[i]] == 0) s[1].erase(a[i]);
			sum[1] -= a[i];
			int x = (*q.begin()).first;
			sum[1] += x;
			if (--q[x] == 0) q.erase(x);
		}
		
		ans = max(sum[0]-sum[1], ans);
	}
	printf("%lld", ans);
}

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


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int A, B;

int main(){
  cin >> A >> B;
  int now = 1, ans = 0;

  while (now < B){
    now += A - 1;
    ans++;
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main() {
   int x;
   cin >> x;
   cout << (x==7 || x==5 || x==3 ? "YES" : "NO") << endl;
}

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

int main() {
	int x[5];
	for (int i = 0; i <= 5; i++) {
		cin >> x[i];
	}
	for (int i = 0; i <= 5; i++) {
		if(x[i] == 0) {
			cout << i+1 <<endl;
			break;
		}
	}
	return 0;
}	

Measured memory_bytes: 3528
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <list>
#include <numeric>
using namespace std;

int main(){    
  int N,R;
  cin >> N >> R;
  if(N>=10){
    cout << R << endl;
  }else{
    cout << R+(100*(10-N))<< endl; 
  }
}


Measured memory_bytes: 256
/*
 ***
 Question Name:
 ***
 Question Link:
 
 ***
 Idea:
 */

#include <memory.h>
#include <iomanip>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<LL> vL;
typedef vector<bool> vb;
typedef unordered_set<int> ui;
typedef pair<LL,LL> pLL;

int main(){
    int H,W,N,dx = 1, x = 0, y = 0, a;
    cin>>H>>W>>N;
    vector<vi> ans(H,vi(W,0));
    for(int i=1;i<=N;++i){
        cin>>a;
        while(a){
            ans[y][x] = i;
            int tmpx = x + dx;
            if(tmpx<0 || tmpx>=W){
                ++y;
                dx *= -1;
            }
            else x = tmpx;
            --a;
        }
    }
    for(auto v:ans){
        for(auto u:v) cout<<u<<' ';
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

#include<string>
#include<stdlib.h>

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

struct Edge {
	int from, to, cost;
	void print() {
		cout << from+1 << " " << to+1 << " " << cost << endl;
	}
};

//変数
int L;
vector<bool> bin;
vector<Edge> edges;




//サブ関数
//入力
void input()
{
	cin >> L;
	while (L > 0) {
		bin.push_back(L % 2);
		L /= 2;
	}
	reverse(bin.begin(), bin.end());
}

int mpow(int a, int b) {
	int res = 1;
	REP(i, b)res *= a;
	return res;
}

//計算
void calc()
{
	REP(i, (int)bin.size()-1) {
		Edge u, d;
		u.from = d.from = i;
		u.to = d.to = i + 1;
		u.cost = mpow(2, (int)bin.size() - i - 2);
		d.cost = 0;
		edges.push_back(u);
		edges.push_back(d);
	}

	int tmp = mpow(2, (int)bin.size() - 1);
	FOR(i, 1,(int)bin.size()) {
		if (bin[i] == 1) {
			Edge e;
			e.from = 0;
			e.to = i;
			e.cost = tmp;
			tmp += mpow(2, (int)bin.size() - i - 1);
			edges.push_back(e);
		}
	}
}


//出力
void output()
{
	cout << bin.size() << " " << edges.size() << endl;
	for (auto edge : edges) {
		edge.print();
	}
}


//デバッグ
void debug()
{
	for (auto c : bin) {
		//cerr << c << " ";
	}
	cerr << endl;
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv){vprint(v)};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

    ll N;
    cin >> N;
    vll A(N), B(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];

    vll C(200001, 0), D(200001, 0), E(200001, 0);
    rep(i, N){ ++C[A[i]]; ++D[B[i]]; }
    REP(i, 1, 200001){ C[i] += C[i-1]; D[i] += D[i-1]; }
    REP(i, 1, 200001) E[i] = C[i] - D[i-1];
    ll d = *max_element(all(E));
    rep(i, N) if(A[i]==B[(i-d+N)%N]){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    rep(i, N) cout << B[(i-d+N)%N] << " ";
    cout << endl;
}


Measured memory_bytes: 11120
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int kaisuu = sc.nextInt();
        int tasi = sc.nextInt();
        int ans = 1;
        for (int i = 0; i < kaisuu; i++) {
            if (ans <= tasi) {
                ans *= 2;
            } else {
                ans += tasi;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716