akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

      long n = sc.nextLong();
      int ans = 0;
      long a = 0;
      long i;
      long j = 0;
      for(i = 1; i*i <= n; i++){
	    if(n % i == 0){
		a = (int) (n / i);
		j = i;
	    }
	}
      
	int p = String.valueOf(a).length();
	int q = String.valueOf(j).length();
	if(p < q){
		System.out.println(q);
	}else{
		System.out.println(p);
	}    
    
  }   
}


Measured memory_bytes: 22996
#include <stdio.h>

int main(void){
    int n = 0, pages = 0;
    scanf("%d\n", &n);

    if (n % 2 == 0){
        pages = n / 2;
    } else {
        pages = n / 2;
        pages += 1;
    }
    printf("%d\n", pages);
    return 0;
}


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

using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

const ll INF = (ll)1e11;
const ll MOD = 998244353;

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<int> A;
    ll S = 0;
    for (int i = 0, a; i < N; ++i) {
        cin >> a;
        A.push_back(a);
        S += a;
    }

    ll cnt = 1;
    for (int i = 0; i < N; ++i) {
        cnt *= 3;   // all ways to paint stones
        cnt %= MOD;
    }

    // subtract the numbers of ways to paint such that R,G,B cannot construct a triangle from all.

    {   // reduce the number of ways to paint such that R >= G + B, G >= B + R, B >= R + G
        vector<ll> dp(S + 10, 0);
        dp[0] = 1;  // assume that R = max(R,G,B) here
        for (auto a : A) {
            for (ll s = S; s > a - 1; --s) {
                dp[s] += 2 * dp[s-a];   // select a_i in G or B
                dp[s] %= MOD;
            }
        }
        
        for (ll s = 0; s <= S / 2; ++s) {
            cnt -= 3 * dp[s];   // subtract sum of R, G, B = max(R,G,B)
            while (cnt < 0) cnt += 3 * MOD;
            cnt %= MOD;
        }
    }

    if (S % 2 == 0) {   // add the number of ways to paint such that R == G && B == 0, G == B && R == 0, B == R && G == 0
        vector<ll> dp(S + 10, 0);
        dp[0] = 1;  // assume that R == G && B == 0 here
        for (auto&& a : A) {
            for (ll s = S; s > a - 1; --s) {
                dp[s] = (dp[s] + dp[s-a]) % MOD;   // select a_i in R (G)
                dp[s] %= MOD;
            }
        }

        cnt += 3ll * dp[S/2];   // add sum of R,G,B == 0
        cnt %= MOD;
    }

    cout << cnt << endl;

    return 0;
}


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


int main(){
  
  int H, N, A, c;
  cin >> H >> N;
  
  for(int i = 0; i < N; i++){
    cin >> A;
    H = H - A;
    if(H <= 0){
      cout << "Yes" << endl;
      break;
    }
    else{
      if(i == N - 1){
        cout << "No" << endl;
      }
    }
  }
  
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>
void read(T &x)
{
    char ch=getchar();
    int f=1;
    for (x=0;ch!='-'&&(ch<'0'||ch>'9');ch=getchar());
    if (ch=='-') f=-1,ch=getchar();
    for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
    x*=f;
}
#define MAXN 200010
int n,m,ans,u,v;
int a[MAXN],cov[MAXN],num[MAXN];
int main()
{
	read(n),read(m);
	for (int i=1;i<=n;i++)
	{
		read(a[i]);
		num[a[i]]++;
	}
	for (int i=1;i<=n;i++)
		for (int j=1;j<=num[i];j++)
			if (i-j+1>=1)
				cov[i-j+1]++;
	for (int i=1;i<=n;i++)
		if (!cov[i])
			ans++;
	for (int i=1;i<=m;i++)
	{
		read(u),read(v);
		if (a[u]-num[a[u]]+1>=1)
		{
			cov[a[u]-num[a[u]]+1]--;
			if (cov[a[u]-num[a[u]]+1]==0)
				ans++;
		}
		num[a[u]]--;
		
		a[u]=v;
		num[a[u]]++;
		if (a[u]-num[a[u]]+1>=1)
		{
			cov[a[u]-num[a[u]]+1]++;
			if (cov[a[u]-num[a[u]]+1]==1)
				ans--;
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

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

int main(void)
{
	int n, k, count = 0, moto = 0;
	string s;
	cin >> n >> k >> s;
	rep(i, n - 1) {
		if(s[i] != s[i + 1]){
			count++;
		}else{
			moto++;
		}
	}
	count = (count + 1) / 2;
	// cout << count << " " << moto << endl;
	cout << min(n - 1, moto + 2 * min(count, k)) << endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();

        int num = Integer.valueOf(line).intValue();

        if(num >= 3200){
            line = sc.nextLine();
            System.out.println(line);
        }else{
            System.out.println("red");
        }
    }
}

Measured memory_bytes: 21844
# -encoding:utf-8
class itp1_1c:
    def cal(self,a,b):
        self.a=a
        self.b=b
        print str(a*b)+" "+str(2*a+2*b)
        
if __name__=="__main__":
    ip=map(int,raw_input().split(" "))
    run=itp1_1c()
    run.cal(ip[0],ip[1])

Measured memory_bytes: 4200
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)

def main():
    s = input().strip()
    n = len(s)
    ans = 0
    i = 0
    j = n-1
    while i < j:
        if s[i] != s[j]:
            if s[i] == 'x':
                i += 1
                ans += 1
            elif s[j] == 'x':
                j -= 1
                ans += 1
            else:
                print(-1)
                return
        else:
            i += 1
            j -= 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 39536
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		boolean ans = false;
		
		if(!(A > 8) && !(B > 8)){
			ans = true;
		}
		
		System.out.println(ans?"Yay!":":(");
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);


int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> w(n+1);
  vector<int> e(n+1);

  rep(i,n){
    if(s[i]=='W'){
      w[i+1]=w[i]+1;
    }
    else {
      w[i+1]=w[i];
    }
  }
  
  rep(i,n){
    if(s[i]=='E'){
      e[i+1]=e[i]+1;
    }
    else {
      e[i+1]=e[i];
    }
  }
  int ans = n;
  rep(i,n){
    ans=min(ans,w[i]+e[n]-e[i+1]);
  }

  cout << ans << endl;

  return 0;
}

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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)

using namespace std;

const int N = 1e6 + 10;

char S[N], T[N];
int n;
int delt[N];

int main(){
	scanf("%d%s%s", &n, S + 1, T + 1);

	bool flag = true;
	For(i, 1, n) if(S[i] ^ T[i]){
		flag = false;
		break;
	}
	if(flag){
		puts("0");
		return 0;
	}

	int ans = 0, cnt = 0, d = 0;
	int j = n;
	Forr(i, n, 1){
		cnt -= delt[i + d], delt[i + d] = 0;
		ans = max(ans, cnt + 1);
		
		//printf("%d %d %d\n", i, d, cnt);

		if(T[i] == T[i - 1]) continue;

		if(j > i) j = i;
		while(j && S[j] != T[i]) --j;
		if(!j){
			puts("-1");
			return 0;
		}

		++cnt, ++d;
		delt[j - 1 + d]++;
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N;
    cin>>N;
    vector<ll> A(N);
    vector<ll> L(N);
    vector<ll> R(N);
    rep(i,N){
        L[i]=i-1;
        R[i]=i+1;
    }
    R[N-1]=-1;
    rep(i,N) cin>>A[i];
    priority_queue<P> Q;
    rep(i,N){
        Q.emplace(A[i],i);
    }
    vector<bool> kesu(N,false);
    ll ans=0;
    rep(i,N/2){
        ll kot,ba;
        while(1){
            kot=Q.top().first;
            ba=Q.top().second;
            Q.pop();
            if(!kesu[ba]) break;
        }
        ans+=A[ba];
        if(L[ba]==-1){
            kesu[ba]=true;
            kesu[R[ba]]=true;
            if(R[R[ba]]!=-1) L[R[R[ba]]]=-1; 
        }
        else if(R[ba]==-1){
            kesu[ba]=true;
            kesu[L[ba]]=true;
            if(L[L[ba]]!=-1) R[L[L[ba]]]=-1;
        }
        else{
            kesu[R[ba]]=true;
            kesu[L[ba]]=true;
            A[ba]=A[L[ba]]+A[R[ba]]-A[ba];
            Q.emplace(A[ba],ba);
            if(R[R[ba]]!=-1) {L[R[R[ba]]]=ba; R[ba]=R[R[ba]];}
            else R[ba]=-1;
            if(L[L[ba]]!=-1) {R[L[L[ba]]]=ba; L[ba]=L[L[ba]];}
            else L[ba]=-1;
        }
    }
    cout<< ans <<"\n";

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 12084
n = int(input())
s = [input()[0] for _ in range(n)]
c = [s.count("M"), s.count("A"), s.count("R"), s.count("C"), s.count("H")]
ans =  c[0] * c[1] *c [2]
ans += c[0] * c[1] *c [3]
ans += c[0] * c[1] *c [4]
ans += c[0] * c[2] *c [3]
ans += c[0] * c[2] *c [4]
ans += c[0] * c[3] *c [4]
ans += c[1] * c[2] *c [3]
ans += c[1] * c[2] *c [4]
ans += c[1] * c[3] *c [4]
ans += c[2] * c[3] *c [4]
print(ans)

Measured memory_bytes: 9828
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

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

	if (a <= b) cout << a << endl;
	else cout << a - 1 << endl;
}


Measured memory_bytes: 256
n = int(input())

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

trans = [a,b,c,d,e]

def wari(a,n):
    if n%a == 0:
        return n//a
    else:
        return n//a + 1


modtrans = [wari(i,n) for i in trans]

print(max(modtrans) + 4)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int>pii;
const int N = 1e6+5;
int ABS(int a)
{
    if(a < 0) return -a;
    return a;
}
int main()
{
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    if(ABS(a-c) <= d)
    {
        printf("Yes\n");
    }
    else
    {
        if(ABS(a-b)<=d && ABS(b-c)<=d)
            printf("Yes\n");
        else printf("No\n");
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
int main() {
  std::ios::sync_with_stdio(false);
  int N;
  std::unordered_map<int, int> m;
  std::cin >> N;
  std::vector<int> A;
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    int Ai;
    std::cin >> Ai;
    m[Ai]++;
    A.push_back(Ai);
    sum += Ai;
  }
  int Q;
  std::cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    std::cin >> B >> C;
    if (m.find(B) == m.end()) {
      std::cout << sum << std::endl;
      continue;
    }
    sum += (C-B) * m[B];
    m[C] += m[B];
    m.erase(B);
    std::cout << sum << std::endl;
  }
  return 0;
}

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

int main(){
	int vote[101];
	int N,Q,M;
	int day;
	int tmp;
	int ans;
	int i,j;
	while(1){
		tmp=0;
		ans=0;
		for(i = 0 ; i < 101 ; i++){
			vote[i]=0;
		}
		cin >> N >> Q;
		if(N == 0 && Q == 0){
			break;
		}
		
		tmp=Q-1;
		
		for(i = 0 ; i < N ; i++){
			cin >> M;
			for(j = 0 ; j < M ; j++){
				cin >> day;
				 vote[day]++;
			}
		}
		for(i = 0 ; i < 101 ; i++){
			if(vote[i] > tmp){
				ans = i;
				tmp = vote[i];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
def main():
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
    a.append(-1)
    cnt=1
    ans=0
    for i in range(n):
        if a[i]==a[i+1]:
            cnt+=1
        else:
            if cnt>=a[i]:
                ans+=cnt-a[i]
            else:
                ans+=cnt
            cnt=1
    print(ans)
if __name__=="__main__":
    main()

Measured memory_bytes: 14268
n = int(input())
a = list(map(int, input().split()))

class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i&(-i)
        return s

    def add(self, i, x):
        while i <= self.n:
            self.bit[i] += x
            i += i&(-i)
            
left, right = 0, 10**9
geta = n+1
while right-left > 1:
    mid = (left+right)//2
    num = 0
    bit = BIT(2*n+1)
    sum_ = 0
    bit.add(sum_+geta, 1)
    for i in range(n):
        val = 1 if a[i] <= mid else -1
        sum_ += val
        num += bit.sum(sum_+geta-1)# - bit.sum(0)
        bit.add(sum_+geta, 1)

    if num > n*(n+1)//4:
        right = mid
    else:
        left = mid
print(right)


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

template <typename T>
struct RangeMinimumQuery {
	vector<T> value;
	int size;
	
	RangeMinimumQuery(int N, T x = numeric_limits<T>::max()){
		for (size = 1; size < N; size *= 2){}
		value.assign(size * 2 - 1, x);
	}
	
	void update(int k, int x){
		k += size - 1;
		value[k] = x;
		while (k > 0){
			k = (k - 1) / 2;
			value[k] = min(value[k * 2 + 1], value[k * 2 + 2]);
		}
	}
	
	T _getMin(int l, int r, int k, int a, int b){
		if (b <= l || r <= a) return numeric_limits<T>::max();
		if (l <= a && b <= r) return value[k];
		int m = (a + b) / 2;
		T vl = _getMin(l, r, k * 2 + 1, a, m);
		T vr = _getMin(l, r, k * 2 + 2, m, b);
		return min(vl, vr);
	}
	
	T getMin(int l, int r){
		return _getMin(l, r, 0, 0, size);
	}
};

typedef long long lint;
typedef tuple<int, int, int> Star;
const int INF = 1 << 28;

int n, d;
Star star[200001];

int main()
{
	scanf("%d %d", &n, &d);
	for (int i = 0; i < n; i++){
		int x, y, b;
		scanf("%d %d %d", &x, &y, &b);
		star[i] = Star(b, x, y);
	}
	star[n] = Star(INT_MAX, 0, 0);
	
	sort(star, star + n);
	
	RangeMinimumQuery<int> seglx(n), segly(n);
	RangeMinimumQuery<int> segrx(n, -INF), segry(n, -INF);
	for (int i = 0; i < n; i++){
		seglx.update(i, get<1>(star[i]));
		segly.update(i, get<2>(star[i]));
		segrx.update(i, -get<1>(star[i]));
		segry.update(i, -get<2>(star[i]));
	}
	
	lint res = 0;
	for (int left = 0, right = 0; left < n; left++){
		while (true){
			int ld = get<0>(star[left]);
			int rd = get<0>(star[right]);
			if (rd - ld > d) break;
			right++;
		}
		
		int width = -segrx.getMin(left, right) - seglx.getMin(left, right);
		int height = -segry.getMin(left, right) - segly.getMin(left, right);
		lint area = (lint)width * height;
		res = max(res, area);
	}
	
	printf("%lld\n", res);
	
	return 0;
}

Measured memory_bytes: 11556
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	A := make([][]int, n)
	for i := range A {
		A[i] = make([]int, m)
		for j := range A[i] {
			fmt.Scan(&A[i][j])
		}
	}
	B := make([]int, m)
	for i := range B {
		fmt.Scan(&B[i])
	}
	// fmt.Println(A, B)
	ans := make([]int, n)
	for i := 0; i < len(A); i++ {
		for j := 0; j < len(A[i]); j++ {
			ans[i] += A[i][j] * B[j]
		}
	}
	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i])
	}
}



Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
int main(){
    // Your code here!
    string s,t;
    cin>>s>>t;
    string r="";
    int n=s.length(),m=t.length();
    int dp[n+1][m+1];
    for(int i=0;i<=n;i++)
    {
        dp[i][0]=0;
    }
    for(int i=0;i<=m;i++)
    {
        dp[0][i]=0;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            int q=0;
            if(s[i-1]==t[j-1])
            {
                q=1+dp[i-1][j-1];
               // 
            }
            else
            {
                q=max(dp[i-1][j],dp[i][j-1]);
            }
            dp[i][j]=q;
        }
    }
    /*for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cout<<dp[i][j]<<" ";
        }
        cout<<'\n';
    }*/
    int i=n,j=m;
    while(i>0||j>0)
    {
        if(i>0&&j>0&&dp[i][j]!=dp[i-1][j]&&dp[i][j]!=dp[i][j-1])
        {
            r=r+s[i-1];
            i--;
            j--;
        }
        else if(i>0&&dp[i][j]==dp[i-1][j])
        {
            i--;
        }
        else if(j>0&&dp[i][j]==dp[i][j-1])
        {
            j--;
        }
    }
    string ans="";
    for(int k=r.length()-1;k>=0;k--)
    {
        ans=ans+r[k];
    }
    cout<<ans;
    return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    // vector<ll> A(N);
    map<ll,ll> M;
    REP(i, N){
        ll a;
        cin >> a;
        M[a]++;
    }

    if(M.size()%2 == 0){
        cout << M.size()-1 << endl;
    } 
    else{
        cout << M.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vi a(N);
    cin >> a;
    cout << *max_element(ALL(a)) - *min_element(ALL(a)) << endl;
}

Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,w;
    cin>>n>>w;
    vector<pair<ll,ll>>v(n);
    for(ll i=0;i<n;i++)
        cin>>v[i].first>>v[i].second;
    ll dp[w+1][n];
    sort(v.begin(),v.end());
    for(ll i=0;i<min(v[0].first,w+1);i++)
        dp[i][0]=0;
    for(ll i=v[0].first;i<=w;i++)
        dp[i][0]=v[0].second;
    for(ll i=1;i<n;i++)
    {
        for(ll j=0;j<min(v[i].first,w+1);j++)
            dp[j][i]=dp[j][i-1];
        for(ll j=v[i].first;j<=w;j++)
        {
            dp[j][i]=max(dp[j][i-1],dp[j-v[i].first][i-1]+v[i].second);
        }
    }
    cout<<dp[w][n-1];
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
const int N=21;
int n,m,f[N][1<<N];
char s[1<<N];
int main(){
	scanf("%d%d",&n,&m);
	for (int i=0;i<=n;i++){
		scanf("%s",s);
		for (int j=0;j<1<<i;j++)f[0][j<<n-i+1|1<<n-i]=s[j]-'0';
	}
	for (int i=0;i<n;i++)
		for (int j=0;j<1<<n+1;j++)
			if (f[i][j]){
				int a=j&(1<<i)-1,b=j^a,c=__builtin_ctz(b);
				b^=1<<c;
				if (b)f[i+1][b|1<<i|a]+=f[i][j];
				if (b+(1<<c+1)<(1<<n+1)){
					int nc=__builtin_ctz(~b>>c+1<<c+1);
					f[i+1][b>>nc<<nc|1<<nc|a]+=f[i][j];
				}
			}
	for (int i=n;i>=0;i--)
		for (int j=0;j<1<<i;j++){
			int res=0;
			for (int k=0;k<1<<n+1-i;k++)res+=f[i][k<<i|j];
			if (res>=m){
				for (int k=i-1;k>=0;k--)putchar('0'+(j>>k&1));
				return 0;
			}
		}
}


Measured memory_bytes: 171264
#include "vector"
#include "iostream"
#include <fstream>
#include <string>
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;


typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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


	int N, K;
	string S;
	cin >> N >> K >> S;

	K--;

	if (S[K] == 'A') S[K] = 'a';
	if (S[K] == 'B') S[K] = 'b';
	if (S[K] == 'C') S[K] = 'c';

	cout << S << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
restaurants = []

for i in range(n):
    s, p = input().split()
    p = 100 - int(p)
    restaurant = "{} {:03} {}".format(s, p, i+1)
    restaurants.append(restaurant)
sorted_restaurants = sorted(restaurants)

for i in range(n):
    id = sorted_restaurants[i].split()[-1]
    print(id)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    vi a(n); for(auto& e : a) cin >> e;

    int cnt0, cnt1 = 0, cnt2 = 0;
    for(auto& e : a){
        if(e % 4 == 0){
            cnt2++;
        }
        else if(e % 2 == 0){
            cnt1++;
        }
        else cnt0++;
    }

    if(cnt1 >= 1) cnt0++;
    bool ok = true;
    if(cnt0 > cnt2 + 1){
        ok = false;
    }

    cout << (ok ? "Yes":"No") << endl;

    return 0;
}


Measured memory_bytes: 640
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

int main(){
  string S, T; cin >> S >> T;
  vector<string> xs;
  rep(i, S.size() - T.size() + 1){
    string r = "";
    for(int j = 0; j < S.size(); j++){
      if(j < i){
        if(S[j] == '?'){
          r += 'a';
        }else{
          r += S[j];
        }
      }else if(j < i + T.size()){
        if(S[j] == '?' || S[j] == T[j-i]){
          r += T[j-i];
        }else break;
      }else{
        if(S[j] == '?'){
          r += 'a';
        }else{
          r += S[j];
        }
      }
    }
    if(r.size() == S.size()) xs.push_back(r);
  }
  if(xs.size()){
    sort(xs.begin(), xs.end());
    cout << xs[0] << endl;
  }else{
    cout << "UNRESTORABLE" << endl;
  }
}


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

int main(){
    string s;
    cin >> s;

    int n = s.length();

    int sum = 0;
    for(int i = 0; i < n; i++){
        sum += s[i] - '0';
    }

    if(sum % 9 == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3732
import sys
input = sys.stdin.readline
h, n = map(int, input().split())
ab = []
ma = 0
for i in range(n):
    a, b = map(int, input().split())
    ma = max(ma, a)
    ab.append([a, b])
ab.sort(key = lambda x:x[1]/x[0])
INF = 10 ** 9
dp = [[INF for i in range(h + ma + 1)] for j in range(n+1)]
ans = INF
for i, (a, b) in enumerate(ab):
    dp[i + 1][0] = 0
    for j in range(a, h + ma + 1):
        # print(dp[i + 1][j - a] + b)
        dp[i + 1][j] = min(dp[i + 1][j - a] + b, dp[i][j])
        if j >= h:
            ans = min(ans, dp[i + 1][j])
# print(dp)
print(ans)


Measured memory_bytes: 133640
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <iomanip>
#include <string>
#include <bitset>
using namespace std;

int main()
{
	int n, ans = 0;
	cin >> n;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		v.push_back(x);
	}
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n - 1; j++) {
			for (int t = j + 1; t < n; t++) {
				if (v[i] != v[j] && v[j] != v[t] && v[t] != v[i]) {
					if ((v[i] + v[j] > v[t]) && (v[j] + v[t] > v[i]) && (v[i] + v[t] > v[j])) ans++;
				}
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 3628
n=int(input())
s=input()
r=0
g=0
b=0
for i in range(n):
  if s[i]=="R":
    r+=1
  if s[i]=="G":
    g+=1 
  if s[i]=="B":
    b+=1 
ans=r*g*b
for i in range(n-2):
  for j in range(i+1,n-1):
    k=2*j-i
    if k>=n:
      continue
    if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
      ans-=1
print(ans)

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

int main(){
    string S;
    cin >> S;

    int num[4];
    for(int i=0; i<4; i++){
        num[i] = S[i] - '0';
    }
    
    int left = num[0]*10 + num[1];
    int right = num[2]*10 + num[3];

    string ans;
    if(left < 13 && right < 13){
        if(left == 0 && right == 0){
            ans = "NA";
        }else if(left == 0){
            ans = "YYMM";
        }else if(right == 0){
            ans = "MMYY";
        }else{
            ans = "AMBIGUOUS";
        }
    }else if(left < 13 && right >= 13 && left > 0){
        ans = "MMYY";
    }else if(left >= 13 && right < 13 && right > 0){
        ans = "YYMM";
    }else{
        ans = "NA";
    }

    cout << ans << endl;

    return 0;
}

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

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int A, B, C;
    cin >> A >> B >> C;
    int ans = -1;
    REP (_, 0, 10000) {
        if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) {
            ans = _;
            break;
        }
        int a = (B + C) / 2;
        int b = (A + C) / 2;
        int c = (A + B) / 2;
        if (A == a && B == b && C == c) break;
        A = a;
        B = b;
        C = c;
//        cout << A << ' ' << B << ' ' << C << endl;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())

alpha = input()

str_alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'


new_str_alphabet=''
for i, alphabet in enumerate(alpha):
    new_idx = str_alphabet.find(alphabet) + N
    new_alphabet = str_alphabet[new_idx%26]
    new_str_alphabet = new_str_alphabet + new_alphabet

print(new_str_alphabet)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int INF=1000000000;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
vector<string> v;
queue<P> Q;
int main(){
   string S;
   cin>>S;
   int i=10*(S.at(0)-'0')+(S.at(1)-'0');
   int j=10*(S.at(2)-'0')+(S.at(3)-'0');
  if(j>0 && j<=12) {
       if(i>0 &&i<=12){
       cout<<"AMBIGUOUS"<<endl;
   }
       else cout<<"YYMM"<<endl;
   }
   else if(i>0 && i<=12){
       cout<<"MMYY"<<endl;
   }
   else{
       cout<<"NA"<<endl;
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define pr pair<int, int>
#define x first
#define y second
using namespace std;

template<typename T>
void read(T& n){
	char ch; int sign = 1;
	while (!isdigit(ch = getchar())) if (ch == '-') sign = -1;
	n = ch - '0';
	while (isdigit(ch = getchar())) n = n * 10 + ch - '0';
	n *= sign;
}
typedef long long ll;
const int INF = 1e9 + 7;
const int N = 211111;
int n, m, tt(1);
pr seg[N];
struct segtr{int lc, rc, mx, tag;} tr[N*8];

void pushdown(int x){
	if (!tr[x].tag) return; tr[x].mx += tr[x].tag;
	if (tr[x].lc) tr[tr[x].lc].tag += tr[x].tag;
	if (tr[x].rc) tr[tr[x].rc].tag += tr[x].tag; tr[x].tag = 0;
}
void update(int x){
	pushdown(x), pushdown(tr[x].lc), pushdown(tr[x].rc);
	tr[x].mx = max(tr[tr[x].lc].mx, tr[tr[x].rc].mx);
}
void build(int x, int l, int r){
	if (l == r) tr[x].mx = -(m - l + 1);
	else{
		int mid = (l + r) >> 1;
		tr[x].lc = ++tt, build(tt, l, mid);
		tr[x].rc = ++tt, build(tt, mid + 1, r);
		update(x);
	}
}
void modify(int x, int l, int r, int nl, int nr, int k){
	pushdown(x);
	if (nl <= l&&r <= nr){tr[x].tag += k; return;}
	int mid = (l + r) >> 1;
	if (nl <= mid) modify(tr[x].lc, l, mid, nl, nr, k);
	if (mid <  nr) modify(tr[x].rc, mid + 1, r, nl, nr, k);
	update(x);
}
int query(int x, int l, int r, int nl, int nr){
	pushdown(x);
	if (nl <= l&&r <= nr) return tr[x].mx;
	int mid = (l + r) >> 1, ans = -INF;
	if (nl <= mid) ans = max(ans, query(tr[x].lc, l, mid, nl, nr));
	if (mid <  nr) ans = max(ans, query(tr[x].rc, mid + 1, r, nl, nr));
	return ans;
}

int main(){
	read(n), read(m);
	rep(i, 1, n) read(seg[i].x), read(seg[i].y);
	sort(seg + 1, seg + n + 1);
	int pos = 1, ans = 0; build(1, 0, m + 1);
	rep(i, 0, m + 1){
		for (; pos <= n&&seg[pos].x <= i; ++pos)
			modify(1, 0, m + 1, i + 1, seg[pos].y, 1);
		ans = max(ans, query(1, 0, m + 1, i + 1, m + 1) - i);
	}
	printf("%d\n", max(ans, n - m));
	return 0;
}

Measured memory_bytes: 11776
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem2546 : Chocolate **/
int main()
{
	int M, N;

	cin>>M>>N;
	vector<vector<int> > C(M);
	rep(i, M) {
		C[i].resize(N);
		rep(j, N) {
			cin>>C[i][j];
		}
	}
	
	int ans=0;
	rep(i, M) {
		int l=0, r=N-1;
		
		while (l != r) {
			if (C[i][l]) {
				ans++;
				C[i][l+1] = 1 - C[i][l+1];
				l++;
			} else if (C[i][r]) {
				ans++;
				C[i][r-1] = 1 - C[i][r-1];
				r--;
			} else {
				C[i][l+1] = 1 - C[i][l+1];
				l++;
			}
		}
		ans += C[i][l];
		
		if (i < M-1) {
			rep(j, N) {
				C[i+1][j] = 1 - C[i+1][j];
			}
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 1240
#include<stdio.h>

int solve(int,int);
int a[2000],b[2000];
int n1,n2;
int main(){
  int i;

  scanf("%d",&n1);

  for(i=0;i<n1;i++){
    scanf("%d",&a[i]);
  }

  scanf("%d",&n2);

  for(i=0;i<n2;i++){
    scanf("%d",&b[i]);
  }
  for(i=0;i<n2;i++){
    if(solve(0,b[i]))printf("yes\n");
    else printf("no\n");
  }

  return 0;
}



int solve(int i,int m){
  int res;
	if(m == 0)
	  return 1;
	if(i >= n1)
	  return 0;
	res = solve(i + 1, m) || solve(i + 1, m - a[i]);
	return res;
      }



Measured memory_bytes: 2052
// AOJ 1518: Last One
// 2018.1.17 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char buf[15];

int main()
{
	int n, m;
	int ans;
	char *p;

	fgets(buf, 15, stdin), n = atoi(buf);
	ans = 0;
	while (n--) {
		fgets(p=buf, 15, stdin);
		while (isdigit(*p)) p++;
		m = 0; while (*++p > ' ') {
			if      (isdigit(*p)) m += *p - '0';
			else if (isupper(*p)) m += *p - 'A' + 10;
			else                  m += *p - 'a' + 36;
		}
		ans ^= m;
	}
	puts(ans? "win": "lose");
	return 0;
}


Measured memory_bytes: 2072
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int Length, L, R, result = 987654321, Sum[100005], idx;
char S[100005];

int main()
{
    scanf("%s", S);
    Length = strlen(S);
    int count = 1;
    for(int i = 0; i < Length; i++)
    {
        if(S[i] == S[i + 1])
        {
            count++;
        }
        else
        {
            Sum[idx++] = count;
            count = 1;
        }
    }
    L = Sum[0];
    R = Sum[idx - 1];
    int sl, sr;
    sl = 1;
    sr = idx - 2;
    while(L + R < Length)
    {
        if(L < R)
        {
            result = min(result, Length - L);
            L += Sum[sl++];
        }
        else
        {
            result = min(result, Length - R);
            R += Sum[sr--];
        }
    }
    printf("%d", min(result, max(L, R)));
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back

char s[55];
int cnt[26], cnt2[26];
int main(){
    int n;
    scanf("%d", &n);
    for(int i=0;i<26;i++) cnt[i] = 1e9;
    for(int i=1;i<=n;i++){
        scanf("%s", s);
        int l = strlen(s);
        memset(cnt2, 0, sizeof(cnt2));
        for(int i=0;i<l;i++){
            cnt2[s[i]-'a']++;
        }

        for(int i=0;i<26;i++){
            cnt[i] = min(cnt[i], cnt2[i]);
        }
    }   
    for(int i=0;i<26;i++){
        for(int j=0;j<cnt[i];j++) printf("%c", i+'a');
    }
}

Measured memory_bytes: 3724
import sys
import  math
from heapq import *
import fractions
import bisect
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())

ans=0
for i in range(1,N+1):
    num=(N//i)
    ans+=i*(1+num)*num//2
    
print(ans)

Measured memory_bytes: 72824
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

bool check(string s, string ans, int n)
{
    if (s[n - 1] == 'o')
    {
        if (ans[n - 1] == 'S')
        {
            return (ans[n - 2] == ans[0]);
        }
        else
        {
            return (ans[n - 2] != ans[0]);
        }
    }
    else
    {
        if (ans[n - 1] == 'S')
        {
            return (ans[n - 2] != ans[0]);
        }
        else
        {
            return (ans[n - 2] == ans[0]);
        }
    }
    return false;
}

bool check2(string s, string ans, int n)
{
    if (s[0] == 'o')
    {
        if (ans[0] == 'S')
        {
            return (ans[1] == ans[n - 1]);
        }
        else
        {
            return (ans[1] != ans[n - 1]);
        }
    }
    else
    {
        if (ans[0] == 'S')
        {
            return (ans[1] != ans[n - 1]);
        }
        else
        {
            return (ans[1] == ans[n - 1]);
        }
    }
    return false;
}

string koutiku(string s, int n, string ans)
{
    for (int i = 1; i < n - 1; i++)
    {
        if (s[i] == 'o')
        {
            if (ans[i] == 'S')
            {
                ans += ans[i - 1];
            }
            else
            {
                ans += (ans[i - 1] == 'S' ? 'W' : 'S');
            }
        }
        else
        {
            if (ans[i] == 'S')
            {
                ans += (ans[i - 1] == 'S' ? 'W' : 'S');
            }
            else
            {
                ans += ans[i - 1];
            }
        }
    }
    return ans;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s, ans;
    cin >> n >> s;
    // 1番目がS,2番目がWであると仮定
    ans = "SW";
    ans = koutiku(s, n, ans);
    if (check(s, ans, n) && check2(s, ans, n))
    {
        cout << ans << endl;
        return 0;
    }
    // 1番目がS,2番目がSであると仮定
    ans = "SS";
    ans = koutiku(s, n, ans);
    if (check(s, ans, n) && check2(s, ans, n))
    {
        cout << ans << endl;
        return 0;
    }
    // 1番目がW,2番目がSであると仮定
    ans = "WS";
    ans = koutiku(s, n, ans);
    if (check(s, ans, n) && check2(s, ans, n))
    {
        cout << ans << endl;
        return 0;
    }
    // 1番目がW,2番目がWであると仮定
    ans = "WW";
    ans = koutiku(s, n, ans);
    if (check(s, ans, n) && check2(s, ans, n))
    {
        cout << ans << endl;
        return 0;
    }
    cout << "-1" << endl;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long> VLL;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
/*--------------------------------------------*/

int main(){
    int h,w;cin>>h>>w;
    vector<vector<char>> m(101,vector<char>(101));
    rep(i,h){
        rep(j,w){
            cin>>m[i][j];
        }
    }
    V wflag(101,0),hflag(101,0);
    rep(i,h){
        int flag=1;
        rep(j,w){
            if(m[i][j]=='#')flag=0;
        }
        if(flag){wflag[i]++;
        //printf("i,wf=%d,%d\n",i,wflag[i]);
        }
    }
    rep(i,w){
        int flag=1;
        rep(j,h){
            if(m[j][i]=='#')flag=0;
        }
        if(flag){hflag[i]++;
        //printf("i,hf=%d,%d\n",i,hflag[i]);
        }
    }
 
    rep(i,h){
        if(wflag[i])continue;   
        rep(j,w){
            if(hflag[j]){
                //printf("wflag,hflag=%d,%d\n",wflag[i],hflag[j]);
                
                continue;
            }
            cout<<m[i][j];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
h,w=map(int,input().split())
S=[list(input()) for _ in range(h)]
dx=[-1,0,1]
dy=[-1,0,1]
for i in range(h):
    for j in range(w):
        count=0
        if S[i][j]=='#':
            continue
        else:
            for l in dx:
                for m in dy:
                    if i+l<0 or i+l>h-1 or j+m<0 or j+m>w-1:
                        continue
                    if S[i+l][j+m]=='#':
                        count+=1
        S[i][j]=str(count)
for i in S:
    k=''.join(i)
    print(k)

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

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) { return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M; }
inline ll sum_1(const ll i, const ll j) { return (sum_1(j) - sum_1(i - 1) + M) % M; }
inline ll sum_2(const ll i, const ll j) { return (sum_2(j) - sum_2(i - 1) + M) % M; }
inline ll sum_3(const ll i, const ll j) { return (sum_3(j) - sum_3(i - 1) + M) % M; }

ll pow_f(ll b, ll e, ll M = ::M) {
    ll ans = 1;
    b = b % M;
    while (e) {
        if (e&1) {
            ans = (ans * b) % M;
        }
        b = (b * b) % M;
        e >>= 1;
    }
    return ans;
}

ll nCr(ll n, ll r) {
    if (r > n || n < 0 || r < 0) { return 0; }
    if (n == r || r == 0) { return 1; }
    r = min(r, n-r);
    ll ans = 1;
    for (ll i = 1; i <= r; ++i) {
        ans = (ans * (n-i+1))/(i); 
    }
    return ans;
}

ll nCr(tuple<ll,ll> t) {
    auto n = get<0>(t);
    auto k = get<1>(t);
    return nCr(n+k-1, k);
}

template<typename T>
void print(T v) {
    cout << v << " ";
}

template<typename T>
void print(vector<T> v) {
    for (auto &i : v) {
        print(i);
    }
    cout << endl;
}

void solve() {
    /**
     * 
     * Si...j = 10**(j-i)*ai + 10**(j-i-1)*ai+1 + 10**(j-i-2)*ai+2 + ... + aj
     * 
     * Si...j = 0 (mod 2019)
     * 
     * 
     * S1.....n = 10**(n-1)*a1 +... an
     * T1 = 10**(n-1)*a1
     * T2 = 10**(n-1)*a1 + 10**(n-2)*a2
     * Tn <- prefix sum
     * 
     * Si...j = 10**(-(n-j))*(Tj - T(i-1)) == 0 (mod 2019)
     * 
     * Tj = Ti-1 mod 2019
     */
    string s;
    cin >> s;
    vector<ll> T(s.size(), 0);
    ll prev = 0;
    ll n = s.size();
    map<ll, ll> m;
    for (int i = 0; i < n; ++i) {
        T[i] = ((pow_f(10, n-i-1, 2019)*(s[i]-'0'))%2019 + prev) % 2019;
        prev = T[i];
        m[T[i]]++;
    }
    // print(T);

    ll ans = 0;
    for (auto &i : m) {
        ans += nCr(i.second, 2);
    }
    ans+=m[0];
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifdef D_LOCAL
        freopen("in.in", "r", stdin);
        freopen("out.out", "w", stdout);
    #endif

    solve();

    return 0;
}

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

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

    bool on[n + 1];
    fill(on, on + n + 1, false);
    on[1] = true;

    int count = 1;
    int p = 1;
    for ( ; count <= 100000; count++) {
        if (on[p] == false) break;
        on[p] = false;
        p = a[p];
        if (p == 2) {
            cout << count << endl;
            return 0;
        }
        on[p] = true;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep2(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)

int main(){

    int n; cin >> n;
    int b[n-1];

    rep(i, n-1){
        cin >> b[i];
    }

    ll a[n];

    rep2(i, 1, n-1){
        a[i] = min(b[i], b[i-1]);
    }

    a[0]   = b[0];
    a[n-1] = b[n-2];

    cout << accumulate(a, a+n, 0LL);

    return 0;
}

Measured memory_bytes: 256