akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;

vector<string> v;
bool used[55][55];
int w,h,x,y;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
bool flag_W,flag_B;
int cnt;

bool can(int y,int x) {
    if(0 <= y && y < h && 0 <= x && x < w) return true;
    return false;
}

void dfs(int y,int x) {
    cnt++;
    rep(i,4) {
        int ny = y + dy[i];
        int nx = x + dx[i];

        if(can(ny,nx)) {
            if(v[ny][nx] == 'W') flag_W = true;
            else if(v[ny][nx] == 'B') flag_B = true;
            else {
                if(!used[ny][nx]) {
                    used[ny][nx] = true;
                    dfs(ny,nx);
                }
            }
        }
    }
}

int main()
{
    while(cin >> w >> h) {
        if(w == 0 && h == 0) break;
        
        v.clear();
        v.resize(h);
        rep(i,h) cin >> v[i];

        memset(used,0,sizeof(used));
        int a = 0,b = 0;
        rep(i,h) {
            rep(j,w) {
                if(!used[i][j] && v[i][j] == '.') {
                    flag_W = false;
                    flag_B = false;
                    cnt = 0;
                    used[i][j] = true;

                    dfs(i,j);
                    if(flag_B && !flag_W) a += cnt;
                    if(flag_W && !flag_B) b += cnt;
                }
            }
        }

        cout << a << " " << b << endl;

    }

    return 0;
}

Measured memory_bytes: 1460
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
int dp[100050]={};
ll pow6[8]={1,6,36,216,1296,7776,46656,279936};
ll pow9[7]={1,9,81,729,6561,59049,531441};
int min3(int const& i){
  int num6=0;
  int num9=0;
  int buf=i;
  while(buf>0){
    buf/=6;
    num6++;
  }
  num6--;
  buf=i;
  while(buf>0){
    buf/=9;
    num9++;
  }
  num9--;
  int min=1000000007;
  rep(j,num6+1){
    if(min>dp[i-pow6[j]]+1)min=dp[i-pow6[j]]+1;
  }
  rep(j,num9+1){
    if(min>dp[i-pow9[j]]+1)min=dp[i-pow9[j]]+1;
  }
  return min;
}

void calc(int const& n){
  rep1(i,n){
    dp[i]=min3(i);
  }
}
int main(){
  rep(i,100050)dp[i]=0;
  int n;
  cin>>n;
  dp[0]=0;
  calc(n);
  cout<<dp[n]<<endl;
  return 0;
}


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

int main(){
    long long int n, T;
    cin >> n >> T;

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

    long long int ans = T;// last person
    for(int i=0; i<n-1; i++){
        ans += min(t[i+1] - t[i], T);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

int n;

signed main(){
    while(cin >> n, n){
        int t[10010];
        rep(i, 0, n) cin >> t[i];
        sort(t, t + n);
        int ans = 0;
        rep(i, 0, n){
            ans += t[i] * (n - 1 - i);
        }
        cout << ans << endl;
    }

}

Measured memory_bytes: 3224
#include<stdio.h>
	int main(void)
{
	int i, n, a[10000], min, max;
	double sum;
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	min = a[0];
	max = a[0];
	sum = a[0];
	for(i = 1; i < n; i++){
		if(min > a[i]){
			min = a[i];
		}else if(max < a[i]){
			max = a[i];
		}
		sum += a[i];
	}
	printf("%d %d %.0f\n", min, max, sum);
	return 0;
}

Measured memory_bytes: 668
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfInt()
    fun gcd(a: Int, b: Int): Int = if (b > 0) gcd(b, a % b) else a
    val ans = A.reduce { acc, value -> gcd(acc, value) }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)

Measured memory_bytes: 53684
init=list(map(int,input().split()))
a=[[0 for i in range(init[1]+1)] for j in range(init[0]+1)]

for i in range(init[0]):
    row=list(map(int,input().split()))
    sum=0
    for j in range(init[1]):
        a[i][j]=row[j]
        sum+=row[j]
    a[i][init[1]]=sum


for i in range(init[1]+1):
    sum=0
    for j in range(init[0]):
        sum+=a[j][i]
    a[init[0]][i]=sum

for i in range(init[0]+1):
    for j in range(init[1]):
        print(a[i][j],end=' ')
    print(a[i][init[1]])


Measured memory_bytes: 6184
// 2013 7/2
import java.lang.*;
import java.util.*;
//1179
public class Main
{
    static Scanner sc = new Scanner(System.in);
        
    public static void main(String args[])
    {
        int[][][] p = new int[1001][11][21];
        int c=1;
        int k=0;
        for(int i=999; i>0; i--){ 
            for(int j=10; j>0; j--){
                if(j%2 == 1 || i%3 == 0)  k = 20;
                else  k = 19;
                for(; k>0; k--){
                    p[i][j][k] = c++;
                                        
                }
            }
        }
        
        int n = sc.nextInt();
        for(int i=0; i<n; i++){
            System.out.println(p[sc.nextInt()][sc.nextInt()][sc.nextInt()]);
            
        }
        
                         
        
    }
}


	    

Measured memory_bytes: 24060
#include <cstdio>
#include <cstring>
int n,tb[5][5],dp[4][1<<8],score[]={0,0,60,70,80};
int main() {
	scanf("%d",&n);
	for(int i=0;i<n;i++) {
		for(int i=0;i<5;i++) for(int j=0;j<5;j++)
			scanf("%d",&tb[i][j]);
		memset(dp,0,sizeof(dp));
		for(int i=0;i<(1<<8);i++) for(int j=0;j<5;j++) {
			if(tb[0][j]) {
				int sc=tb[0][j];
				if(j>0)sc+=i>>2*j-2&3;
				if(j<4)sc+=i>>2*j&3;
				while(sc>4)sc-=4;
				dp[0][i]+=score[sc];
			}
		}
		for(int i=1;i<4;i++) for(int j=0;j<(1<<8);j++) for(int jj=0;jj<(1<<8);jj++) {
			int sum=dp[i-1][j];
			for(int k=0;k<5;k++) {
				if(tb[i][k]) {
					int sc=tb[i][k];
					if(k>0)sc+=(j>>2*k-2&3)+(jj>>2*k-2&3);
					if(k<4)sc+=(j>>2*k&3)+(jj>>2*k&3);
					while(sc>4)sc-=4;
					sum+=score[sc];
				}
			}
			if(dp[i][jj]<sum)dp[i][jj]=sum;
		}
		int ans=0;
		for(int i=0;i<(1<<8);i++) {
			int sum=dp[3][i];
			for(int j=0;j<5;j++) {
				if(tb[4][j]) {
					int sc=tb[4][j];
					if(j>0)sc+=i>>2*j-2&3;
					if(j<4)sc+=i>>2*j&3;
					while(sc>4)sc-=4;
					sum+=score[sc];
				}
			}
			if(ans<sum)ans=sum;
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
int n, m, a[55], vis[55][55][2505]; long long dp[55][55][2505];
long long solve(int d, int t, int sum) {
	if(d == n) return (t * m == sum ? 1 : 0);
	if(vis[d][t][sum]) return dp[d][t][sum];
	long long ret = 0;
	ret += solve(d + 1, t, sum);
	ret += solve(d + 1, t + 1, sum + a[d]);
	vis[d][t][sum] = 1;
	return dp[d][t][sum] = ret;
}
int main() {
	cin >> n >> m;
	for(int i = 0; i < n; i++) cin >> a[i];
	cout << solve(0, 0, 0) - 1 << endl;
	return 0;
}

Measured memory_bytes: 16000
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    int n;
    cin >> n;
    ll a[n], b[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    ll need = 0LL;
    ll give = 0LL;
    int need_count = 0;
    vector <ll> givers;
    for (int i = 0; i < n; i++) {
        if (a[i] < b[i]) {
            need_count++;
            need += b[i] - a[i];
        } else {
            give += a[i] - b[i];
            givers.push_back(a[i] - b[i]);
        }
    }

    if (need > give) {
        cout << -1 << endl;
    } else {
        sort(givers.begin(), givers.end(), greater<ll>());
        int p = 0;
        while (need > 0) {
            need -= givers[p];
            p++;
            need_count++;
        }
        cout << need_count << "\n";
    }

    return 0;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    int a;
    cin >> a;
    cout << (24 - a) + 24;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string ch;
    cin>>ch;
    for(int i=0;i<ch.size();i++)
    {
        if(ch[i]=='1')
        {
            ch[i]='9';
        }

        else if(ch[i]=='9')
        {
            ch[i]='1';
        }
        else
        {
            cout<<"nothing";
        }
    }

    cout<<ch<<endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
#define MAX 100
 
int pop();
void push(int);
 
int stack[MAX];
int top = 0;
 
int main(){
 
  int a, b, d;
  char c[7];
 
  while((scanf("%s", &c))!= EOF){
 
    if(c[0] == '+' || c[0] == '-' || c[0] == '*'){
 
      switch(c[0]){
 
      case '+':
       
    a = pop();
       
    b = pop();
       
    push(a + b);
       
    break;
 
 
      case '-':
       
    a = pop();
       
    b = pop();
 
    push(b - a);
 
    break;
 
 
      case '*':
      
    a = pop();
       
    b = pop();
 
    push(a * b);
 
    break;
 
 
      default:
 
    break;
     
      }
    }
 
    else{
 
      d = atoi(c);
 
      push(d);
 
    }
 
  }
 
  printf("%d\n", pop());
   
  return 0;
 
}
 
int pop(){
 
  if(top <= 0)
    return 0;
  else
    top = top - 1;
 
 
  return stack[top + 1];
  
}
 
void push(int data){
 
  top++;
   
  stack[top] = data;
   
}

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

using namespace std;
using ull = unsigned long long;
using ll = long long;

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

Measured memory_bytes: 3616
#include <iostream>

using namespace std;
using ll = long long;

int main(){
    ll N, M;
    cin >> N >> M;
    if(2*N > M){
        cout << M/2 << endl;
        return 0;
    }

    M -= 2*N;
    cout << M/4 + N << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;
static const int M = 1046527;
static const int NIL = -1;
static const int L = 14;
char H[M][L];

// ??????????????°????????????
int getChar(char ch){
    if(ch == 'A') return 1;
    else if(ch == 'C') return 2;
    else if(ch == 'G') return 3;
    else if(ch == 'T') return 4;
    else return 0;
}

long long getKey(char str[]){
    long long sum = 0, p=1, i;
    for(i=0; i<strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

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

int find(char str[]){
    long long key, i, h;
    key = getKey(str);
    for (int i = 0; ; ++i)
    {
        h = (h1(key) + i * h2(key)) % M;
        if( strcmp(H[h],str) == 0) return 1;
        else if( strlen(H[h]) == 0) return 0; //??????????????£???????????????
    }
    return 0;
}

int insert(char str[]){
    long long key, i, h;
    key = getKey(str);
    for (int i = 0; ; ++i)
    {
        h = (h1(key) + i * h2(key)) % M;
        if( strcmp(H[h],str) == 0) return 1;
        else if( strlen(H[h]) == 0){
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

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

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

using namespace std;

int d[13][13];
const int N = 100; 
int f[N+1][N+1];

void solve() {
    int A,B;
    cin >> A >> B;
    for (int i = 1; i <= A; i++) {
        for (int j = 1; j <= B; j++) {
            cin >> d[i][j];
        }
    }
    memset(f, 0, sizeof f);
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            for (int x = 1; x <= A; x++) {
                for (int y = 1; y <= B; y++) {
                    f[i][j] = max(f[i][j], d[x][y] - x*i - y*j);
                }
            }
        }
    }
    for (int x = 1; x <= A; x++) {
        for (int y = 1; y <= B; y++) {
            int mi =  1e5;
            for (int i = 0; i <= N; i++) {
                for (int j = 0; j <= N; j++) {
                    mi = min(mi, x*i+y*j + f[i][j]);
                }
            }
            if (mi != d[x][y]) {
                cout << "Impossible"; return;
            }
        }
    }
    vector<int> a(N+1), b(N+1);
    iota(a.begin(), a.end(), 1);
    iota(b.begin(), b.end(), 102);
    int s = a[0], t = b[0];
    int m = 100*2 + 101*101;
    cout << "Possible\n";
    cout << "202 " << m << "\n";
    for (int i = 1; i <= N; i++) {
        cout << a[i-1] << ' ' << a[i] << " X\n";
        cout << b[i] << ' ' << b[i-1] << " Y\n";
    }
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            cout << a[i] << ' ' << b[j] << ' ' << f[i][j] << "\n";
        }
    }
    cout << s << ' ' << t;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 384
import Foundation
let n = Int(readLine()!)!
var a: [Int] = .init(repeating: 0, count: n)
for i in 0..<n {
  a[i] = Int(readLine()!)!
}
let sort = a.sorted()
let maxV = sort.last!
let maxVPrev = sort[sort.count - 2]

for i in 0..<n {
  if maxV == maxVPrev {
    print(maxV)
  } else if maxV == a[i] {
    print(maxVPrev)
  } else {
    print(maxV)
  }
}

Measured memory_bytes: 16388
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;


int main() {
	int i;
	int count = 0;
	int A, B;
	int K;

	cin >> A >> B>> K;
	int n = min(A,B) + 1;

	while (count < K)
	{
		n--;
		if ((A%n == 0) && (B%n == 0))
		{
			count++;
		}		
	}
	
	cout << n <<endl;

}

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

using namespace std;
typedef long long ll;
typedef double ld;

ll n, m;

int main(void)
{
	scanf("%lld %lld", &n, &m);
	
	for(ll i = 0 ; i <= n ; i++)
	{
		if(i * 2 + (n - i) * 4 == m)
		{
			printf("Yes");
			return 0;
		}
	}
	
	printf("No");
	return 0;
}

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

int desc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int main()
{
    int n,l[2000],i,j,k;

    scanf("%d",&n);
    for (i = 0; i < n; i++)
    {
        scanf("%d",&l[i]);
    }
    
    qsort(l,n,sizeof(int),desc);

    long long ans = 0;

    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            for (k = j + 1; k < n; k++)
            {
                if(l[i] < l[j] + l[k])ans++;
            }
        }
    }
    
    printf("%lld",ans);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define INF (1e9)
#define M 1005
#define N 205
using namespace std;
typedef long long ll;

ll n,m,r,z[M],sld[2][N][N];

void init(){
  rep(i,2)
    rep(j,n)
      rep(k,n)
        sld[i][j][k]=INF; 
}

void add_edge(ll sl,ll x,ll y,ll t){
  sld[sl][x][y]=sld[sl][y][x]=min(sld[sl][x][y],t);
}

void warshall_floyd(){
  rep(sl,2) rep(k,n) rep(i,n) rep(j,n)
    sld[sl][i][j]=min(sld[sl][i][j],sld[sl][i][k]+sld[sl][k][j]);
  rep(sl,2)
    rep(i,n)sld[sl][i][i]=0;
}

ll dp[M][N];

void solve(){
  rep(i,r)
    rep(j,n)dp[i][j]=INF;
  dp[0][z[0]]=0;
  
  rep(i,r-1)
    rep(j,n){
      if(dp[i][j]==INF)continue;
      ll cost=dp[i][j]+sld[0][z[i]][z[i+1]];
      dp[i+1][j]=min(dp[i+1][j],cost);
      rep(k,n){
	ll cost2=dp[i][j]+sld[0][z[i]][j];
	cost2+=sld[1][j][k]+sld[0][k][z[i+1]];
	dp[i+1][k]=min(dp[i+1][k],cost2);
      }
    }
  
  ll ans=INF;
  rep(i,n)ans=min(ans,dp[r-1][i]);
  cout<<ans<<endl;
}

int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    ll x,y,t;
    char sl;
    
    init();
    
    rep(i,m){
      cin>>x>>y>>t>>sl;
      x--,y--;
      if(sl=='L')add_edge(0,x,y,t);
      else add_edge(1,x,y,t);
    }
    
    warshall_floyd();
 
    cin>>r;
    rep(i,r)cin>>z[i],z[i]--;
    
    solve();
  }
  return 0;
}

Measured memory_bytes: 5252
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(void){
  ll n, m = 0, a = 0, c = 0, h = 0, r = 0;
  cin >> n;
  rep(i, n) {
    string s;
    cin >> s;
    if(s[0] == 'M') m++;
    else if(s[0] == 'A') a++;
    else if(s[0] == 'R') r++;
    else if(s[0] == 'C') c++;
    else if(s[0] == 'H') h++;
  }
  ll sum = (ll)m*a*r +(ll) m*a*c +(ll) m*a*h +(ll) m*r*c +(ll) m*r*h +(ll) m*c*h +(ll) a*r*c +(ll) a*r*h +(ll) r*c*h +(ll) a*c*h;
  cout << sum << endl;
  return 0;
}


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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}


int main(int argc, char const* argv[])
{
    string r,g,b;
    cin >> r >> g >> b;
    int x = stoi(g+b);
    if (x % 4 == 0) {
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }


    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


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

#define MAX 1000
#define INF 100000

using namespace std;

//[0] = id, [1] = cost
int A[MAX][2],SortedA[MAX][2],NumT[MAX];
bool comp[MAX] = {};
vector<int> Typelist[MAX];
int MIN = INF;

void sorts(int n){
    priority_queue<pair<int, int> > PQ;
    for (int i = 0; i < n; i++) {
        PQ.push(make_pair(-1*A[i][1], A[i][0]));
    }
    for (int i = 0; i < n; i++) {
        SortedA[i][0] = PQ.top().second;
        SortedA[i][1] = (-1)*PQ.top().first;
        PQ.pop();
    }
}

void trace(int i,int type){
    while (!comp[i]) {
        comp[i] = true;
        Typelist[type-1].push_back(i);
        i = SortedA[i][0];
    }
}

int makeType(int n){
    int type = 0;
    for (int i = 0; i < n; i++) {
        if (!comp[i]) {
            type++;
            trace(i,type);
        }
    }
    return type;
}

int rec(int type){
    if (Typelist[type].size() == 1) return 0;
    if (Typelist[type].size() == 2) {
        return A[Typelist[type][0]][1] + A[Typelist[type][1]][1];
    }
    int minc = INF,sum = 0;
    int n = Typelist[type].size();
    for (int i = 0; i < n; i++) {
        sum += A[Typelist[type][i]][1];
        if (minc > A[Typelist[type][i]][1]) minc = A[Typelist[type][i]][1];
    }
    sum -= minc;
    return sum + min((n-1)*minc, (n-1)*MIN+2*(MIN+minc));
}

int main(){
    int N,NofT;
    cin >> N;
    for (int i = 0; i < N; i++) {
        scanf("%d",&A[i][1]);
        A[i][0] = i;
        if (MIN > A[i][1]) MIN = A[i][1];
    }
    sorts(N);
    NofT = makeType(N);
    
    int cost = 0;
    
    for (int i = 0; i < NofT; i++) {
        cost += rec(i);
    }
    
    printf("%d\n",cost);
    
    return 0;
}

Measured memory_bytes: 1316
from scipy.misc import comb

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

#num2alpha = lambda c: chr(c+93)
#num2alpha(3) #==> C


alpha2num = lambda c: ord(c) - ord('a')

#alpha2num('Y') #==> 25



s_list = [[0 for i in range(26)]for j in range(n)]

#print(s_list[26][0])

#exit()

for i in range(n):
    for j in range(10):
        #print(alpha2num(s[i][j]))
        s_list[i][alpha2num(s[i][j])] += 1
        
#print(s_list)
s_list.sort()

#print(s_list)

ans = []
tmp = 0

for i in range(n-1):
    if s_list[i] == s_list[i+1]:
        if i == n-2:
            tmp += 1
            ans.append(tmp)
        tmp += 1
    else:
        ans.append(tmp)
        tmp = 0

f_ans = 0

for i in range(len(ans)):
    f_ans += (ans[i] + 1) * ans[i] * 0.5

print(int(f_ans))

Measured memory_bytes: 57444
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vll = vector<ll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();
  ll N;
  cin >> N;
  unordered_map<ll, ll> A;
  REP(i, 0, N) {
    ll a;
    cin >> a;
    if (A.find(a) == A.end()) {
      A.emplace(a, 1);
    } else {
      A[a] += 1;
    }
  }

  ll result = 0;
  for (auto const& a : A) {
    if (a.first < a.second) {
      result += a.second - a.first;
    } else if (a.first == a.second) {
      // nop
    } else {
      result += a.second;
    }
  }
  cout << result << endl;


  return 0;
}


Measured memory_bytes: 4260
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define ls(x) (x<<1)
#define rs(x) (ls(x)|1)
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef double db;
const int mod = 998244353;
const int N = 1e6 + 5;
const int M = 1e3 + 5;
ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
ll lcm(ll a,ll b){ return a*b/gcd(a,b); }
inline ll qsm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
int n, m, k;

int main(){
    scanf("%d",&n);
    ll ans=1ll*n/500*1000+1ll*(n%500)/5*5;
    printf("%lld\n", ans);
    return 0;
}
/*

*/
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                     佛祖保佑      永无BUG


Measured memory_bytes: 256
import std.stdio,std.string;

void main(){
	string s, a;
	while (s = readln.chomp, s != "0") {
		foreach (i; 1..3) s ~= readln.chomp;
		a = "NA";
		foreach (w; ["www", "bbb"]) {
			foreach (i; 0..3) {
				if (s[i*3..i*3+3] == w) a = [w[0]];
				if ([s[i],s[i+3],s[i+6]] == w) a = [w[0]];
			}
			if ([s[0],s[4],s[8]] == w) a = [w[0]];
			if ([s[2],s[4],s[6]] == w) a = [w[0]];
		}
		writeln(a);
	}
}

Measured memory_bytes: 972
#include<bits/stdc++.h>
#include<vector>
#include<string>
#define rep(i,a,b) for(long long int i=(a);i<(b);i++)
#define se(a) a.begin(),a.end()
#define ll unsigned long long int
#define mll map<ll,ll>
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define mk make_pair
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
	boost;
	string a,b;
	cin>>a>>b;
	ll n=a.length(),m=b.length();
	ll dp[n+1][m+1];
	rep(i,0,n+1)
	rep(j,0,m+1)
	{
		if(i==0||j==0)
		dp[i][j]=0;
		else if(a[i-1]==b[j-1])
		dp[i][j]=1+dp[i-1][j-1];
		else
		dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	}
	ll k=dp[n][m];
	string ans;
	if(k==0)
	cout<<ans;
	else{
		ll i=n,j=m;
		while(i>0&&j>0)
		{
			if(a[i-1]==b[j-1])
			{
				ans.push_back(a[i-1]);
				i--;j--;
			}
			else if(dp[i-1][j]>dp[i][j-1])
			i--;
			else
			j--;
		}
		reverse(se(ans));
		cout<<ans;
	}
}

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

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    for(int i = 0; i < S.size(); i++) {
        S[i] = S[i] + N;
        if('Z' < S[i])
            S[i] -= 26;
    }
    cout << S << endl;
}

Measured memory_bytes: 256
// 2012/07/16 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int x, y;
		cin >> x >> y;

		if(x==0&&y==0)
			break;

		int X, Y;
		if(x>=y){
			X = x;
			Y = y;
		}
		else{
			X = y;
			Y = x;
		}

		int cnt = 0;

		do{
			X = X%Y;

			int tmp = X;
			X = Y;
			Y = tmp;

			cnt++;
		}while(Y!=0);

		cout << X << ' ' << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define all(t) (t).begin(),(t).end()
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	int n,k;
	cin >> n >> k;
	int ans=0;
	FOR(i,n){
		int h;
		cin >> h;
		if(h>=k)ans++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
//vector<int> g[200020];
int main()
{
	cin>>n;
	string s[4]={"AC", "WA", "TLE", "RE"};
	map<string, int> mp;
	for(int i=0; i<n; i++){
		string t; cin>>t;
		mp[t]++;
	}
	for(int i=0; i<4; i++){
		cout<<s[i]<<" x "<<mp[s[i]]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#define rep(i,m,n) for(int i=m; i<(n); i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
typedef long long ll;
using namespace std;

ll ans = 0;
ll n;

void dfs(ll x)
{
    if(x > n) return ;
    int flag1=0;
    int flag2=0;
    int flag3=0;
    ll tmp = x;
    while(tmp!=0)
    {
        if(tmp%10 == 3) flag1++;
        else if(tmp%10 == 5) flag2++;
        else if(tmp%10 == 7) flag3++;
        tmp /= 10;
    }
    if((flag1>0 && flag2>0) && flag3>0) ans++;
    if(x < n)
    {
        dfs(10*x+3);
        dfs(10*x+5);
        dfs(10*x+7);
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    dfs(0);
    cout << ans << endl;
}


Measured memory_bytes: 256
#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,m;
int ans=0;
cin>>n>>m;
vector<vector<bool>>root(n);
rep(i,n){root[i].resize(n);}
rep(i,m){
    int a,b;
    cin>>a>>b;
    
    root[a-1][b-1]=root[b-1][a-1]=true;
}
vector<int>v(n);
rep(i,n)v[i]=i;

do{
    bool ok =true;
    rep(i,n){   
       
        if(!v[0]==0){
    
        ok=false;
        }
        if(i==n-1){
            break;
            ok=false;
        }
        
        if(!((root[v[i]][v[i+1]])||(root[v[i+1]][v[i]])))ok=false;

    }
    
    if(ok)ans++;
}while(next_permutation(v.begin(),v.end()));
cout<<ans<<endl;

}


Measured memory_bytes: 3608
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, X, Y):
    MOD = 10**9+7

    xs = 0
    for i in range(N):
        xs += (i-(N-(i+1)))*X[i]
        xs %= MOD
    ys = 0
    for i in range(M):
        ys += (i-(M-(i+1)))*Y[i]
        ys %= MOD
    return xs*ys % MOD


def main():
    N, M = read_int_n()
    X = read_int_n()
    Y = read_int_n()
    print(slv(N, M, X, Y))


if __name__ == '__main__':
    main()


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

int main(){
    int n,sum=0;
    cin>>n;
    int m=n;
    while(n>0) {
        sum+=n%10;
        n/=10;
    }
   if(m%sum==0) cout << "Yes" << endl;
   else cout << "No"<< endl;
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	ll n,a[100010],ans=0,ans2=0;
	cin>>n;
	REP(i,n){
		cin>>a[i];
	}
	sort(a,a+n);
	if(n%2==0){
		for(int i=0;i<(n-1)/2;i++){
			ans+=(a[n-i-1]-a[i])*2;
		}
		ans+=a[(n-1)/2+1]-a[(n-1)/2];
		cout<<ans<<endl;
	}
	else{
		for(int i=0;i<(n-2)/2;i++){
			ans+=(a[n-i-1]-a[i])*2;
			ans2+=(a[n-i-1]-a[i])*2;
		}
		ans+=a[(n-2)/2+2]+a[(n-2)/2+1]-a[(n-2)/2]*2;
		ans2+=a[(n-2)/2+2]*2-a[(n-2)/2+1]-a[(n-2)/2];
		cout<<std::max(ans,ans2)<<endl;
	}
	return 0;
}
/*
N=6
0 1 2 3 4 5
N=5
0 1 2 3 4
*/

Measured memory_bytes: 1024
n,r,l=map(int,raw_input().split())
log=[map(int,raw_input().split()) for i in range(r)]
log.insert(0,[1,0,0])
log.append([1,l,0])
id_t=[0]*n
id_x=[0]*n
max_id=0
for i in range(1,r+2):
	cur_id=log[i][0]-1
	id_t[max_id]+=log[i][1]-log[i-1][1]
	id_x[cur_id]+=log[i][2]
	if cur_id==max_id and log[i][2]<0:
		max_id=id_x.index(max(id_x))
	elif id_x[max_id]<id_x[cur_id] or (id_x[max_id]==id_x[cur_id] and max_id>cur_id):
		max_id=cur_id
print id_t.index(max(id_t))+1

Measured memory_bytes: 145564
#include<iostream>
#include<vector>
using namespace std;
typedef unsigned long long ull;
#define f(i) for(int i=0;i<n;i++)
int main() {
    int n;
    cin>>n;
    vector<int>vec(n),s,l,r;
    f(i)
        cin>>vec[i];
    f(i){
        while(s.size()&&vec[s.back()]>vec[i])
            s.pop_back();
        l.push_back(s.size()?i-s.back()-1:i);
        s.push_back(i);
    }
    s.clear();
    for(int i=n-1;i>=0;i--){
        while(s.size()&&vec[s.back()]>vec[i])
            s.pop_back();
        r.push_back(s.size()?s.back()-i-1:n-i-1);
        s.push_back(i);
    }
    ull ans=0;
    f(i)
        ans+=(ull)(r[n-1-i]+1)*(l[i]+1)*vec[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-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 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)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

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

    ll N;
    cin >> N;
    vector<ll> a(N), b(N);
    rep(i, N)
    {
        cin >> a[i] >> b[i];
    }

    sort(ALL(a));
    sort(ALL(b));

    if (N % 2) {
        ll M = N / 2;

        cout << b[M] - a[M] + 1 << endl;

    } else {
        ll Ml = N / 2 - 1;
        ll Mr = N / 2;

        ll A = a[Mr] + a[Ml];
        ll B = b[Mr] + b[Ml];

        cout << -A + B + 1 << endl;
    }
}


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


bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}


int main() {
    
    int N, tmp, sum=0;
    std::scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        std::scanf("%d", &tmp);
        if (isPrime(tmp)) sum++;
    }
    std::cout << sum << std::endl;
    
    return 0;
}


Measured memory_bytes: 3248
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>

char S[10+1];

int main()
{
  int cnt;
  int N,K;
  int i;

  cnt = scanf("%d", &N);
  scanf("%*c");
  for (i=1; i<=N; i++) {
    cnt = scanf("%c", &S[i]);
  }
  cnt = scanf("%d", &K);

  for (i=1; i<=N; i++) {
    if (S[i] != S[K]) {
      printf("*");
    } else {
      printf("%c", S[K]);
    }
  }

  return 0;
}


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

using namespace std;

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

    int n, k;
    cin >> n >> k;
    int arr[n], ans = 2e9;

    for (int i = 0; i < n; i++)
        cin >> arr[i];

    for (int i = k - 1; i < n; i++) {
        if (arr[i] <= 0)
            ans = min(ans, abs(arr[i - k + 1]));
        else if (arr[i - k + 1] >= 0)
            ans = min(ans, arr[i]);
        else
            ans = min(ans, min(abs(arr[i - k + 1]) * 2 + arr[i], abs(arr[i - k + 1]) + arr[i] * 2));
    }

    cout << ans << '\n';

    return 0;
}


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

int main() {
	int A, B;
	char op;
	cin >> A >> op >> B;
	if (op == '+') cout << A + B;
	else cout << A - B;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

……解説不要よね
*/

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

const int maxn(2e5 + 5);
const int mod(1e9 + 7);

int n, mn[maxn], inv[maxn], size[maxn], mn1 = mod, mn2 = mod, x, y, id[maxn], ans = 1, cnt;
vector <int> ball[maxn];

inline bool Cmp(int i, int j) {
	return mn[i] < mn[j];
}

int main() {
	register int i, w, c, nmn;
	scanf("%d%d%d", &n, &x, &y), inv[1] = inv[0] = 1;
	for (i = 2; i <= n; ++i) inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
	for (i = 1; i <= n; ++i) inv[i] = 1LL * inv[i] * inv[i - 1] % mod;
	for (i = 1; i <= n; ++i) scanf("%d%d", &c, &w), ball[c].push_back(w), ++size[c], id[i] = i;
	for (i = 1; i <= n; ++i)
		if (size[i]) {
			sort(ball[i].begin(), ball[i].end());
			mn[i] = ball[i][0], mn2 = min(mn[i], mn2);
			if (mn2 < mn1) swap(mn2, mn1);
		}
		else mn[i] = mod;
	for (i = 1; i <= n; ++i)
		if (size[i]) {
			nmn = mn[i] == mn1 ? mn2 : mn1;
			while (size[i] > 1 && mn[i] + ball[i][size[i] - 1] > x && nmn + ball[i][size[i] - 1] > y) --size[i];
		}
	sort(id + 1, id + n + 1, Cmp), nmn = mn[id[1]];
	for (i = 1; i <= n; ++i)
		if (i == 1 || mn[id[i]] + nmn <= y) ans = 1LL * ans * inv[size[id[i]]] % mod, cnt += size[id[i]];
	for (i = 1; i <= cnt; ++i) ans = 1LL * ans * i % mod;
	printf("%d\n", ans);
	return 0;
}

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

int judge(int P, int k, vector<int>& v){
  int capa = P, truck = k;
  for(int i=0; i<v.size(); i++){
    while(capa < v[i]){
      capa = P;
      truck--;
      if(truck==0) return -1;
    }
    if(capa >= v[i]){
      capa -= v[i];
    }
  }
  return 1;
}

int main(){
  int n,k; cin >> n >> k;
  vector<int> W;
  for(int i=0; i<n; i++){
    int t; cin >> t;
    W.push_back(t);
  }
  int l=0,r=1000000000;
  int P = (r+l)/2;
  while(r-l>=1){
    if(judge(P,k,W) == -1) l = P+1;
    if(judge(P,k,W) == 1 )  r = P;
    P = (r+l)/2;
  }
  cout << P << "\n";
}

Measured memory_bytes: 1672
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
    FIO;
    int n; cin >> n;
    if(n >= 30)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    ll n, nn;
    cin >> n;
    nn = n;

    if (n != 0)
    {
        vector<ll> v;
        vector<ll> tp;
        for (ll tmp = 0; tmp <= pow(2, 16) - 1; tmp++)
        {
            int sum = 0;
            for (int j = 0; j <= 15; j++)
            {
                if ((tmp) & (1 << j))
                    sum += pow(-2, j * 2);
            }
            v.push_back(sum);
            tp.push_back(tmp);
        }
        // cout << v.size() << endl;
        sort(v.begin(), v.end());
        sort(tp.begin(), tp.end());

        for (ll tmp = 0; tmp <= pow(2, 16) - 1; tmp++)
        {
            int sum = 0;
            for (int j = 0; j <= 15; j++)
            {
                if ((tmp) & (1 << j))
                    sum += pow(-2, j * 2 + 1);
            }
            auto itr = lower_bound(v.begin(), v.end(), n - sum);
            if (itr != v.end() && *itr == abs(n - sum))
            {
                // cout << *itr << "," << sum << endl;
                int idx = itr - v.begin();
                int ret = 0;
                // cout << "a" << bitset<16>(tp[idx]) << endl;
                // cout << "b" << bitset<16>(tmp) << endl;
                for (int i = 0; i <= 16; i++)
                {
                    ret |= (tp[idx] & (1 << i)) << i * 2;
                }
                bool f = false;
                for (int i = 15; i >= 0; i--)
                {
                    int a = (tp[idx] & (1 << i)) >> i;
                    int b = (tmp & (1 << i)) >> i;
                    if (b)
                        f = true;
                    if (f)
                        cout << b;
                    if (a)
                        f = true;
                    if (f)
                    {
                        // cout << "=";
                        cout << a;
                    }
                }
                cout << endl;
                for (int i = 0; i <= 16; i++)
                {

                    /*
                if (tmp & (1 << i))
                {
                    cout << "a" << i << endl;
                    cout << ((tmp & (1 << i)) >> i) << endl;
                    cout << bitset<31>(ret) << endl;
                }
                */
                    ret |= ((tmp & (1 << i)) >> i) << (i * 2 + 1);
                    /*
                if (tmp & (1 << i))
                {
                    cout << i * 2 + 1 << endl;
                    cout << bitset<31>(ret) << endl;
                }
                */
                }
                // cout << bitset<31>(ret) << endl;
                // break;
            }
        }
    }
    else
        cout << "0" << endl;
}

Measured memory_bytes: 1524
#include <iostream>

using namespace std;
int main(){
    int x,y;
    cin>>x>>y;

    if((x+y)>(x-y)){
        if((x+y)>(x*y)){
            cout<<x+y;
        }else{
            cout<<x*y;
        }
    }else{
        if((x-y)>(x*y)){
            cout<<x-y;
        }else{
            cout<<x*y;
        }
    }
    return 0;
}

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

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll sum(ll n) {
    return n * (n + 1) / 2;
}

void Main() {
    int N;
    cin >> N;
    ll ans = sum(N) - 3 * sum(N / 3) - 5 * sum(N / 5) + 15 * sum(N / 15);
    cout << ans << endl;
}


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main()
{   
    int n,a,b;
    n=12;
    cin >> n >> a >>b;
if(a+b+n>=22){
    cout <<"bust"<<endl;
}else{
    cout <<"win"<<endl;
}
    return 0;

}


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

int n, k;
string s;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> s >> k;
    for (int i = 0; i < n; ++i) {
        if (s[i] != s[k - 1]) s[i] = '*';
    }    
    cout << s << '\n';
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int a;
    cin >> a;
    int b;
    cin >> b;
    int c;
    cin >> c;
    int x;
    cin >> x;


    
    int cnt = 0;
    
    for(int i = 0; i <= a; i++){
        
        for(int j = 0; j <= b; j++){
            
            for(int k = 0; k <= c; k++){

                int sum = 500 * i + 100 * j + 50 * k;
                if(sum == x){
                    cnt++;
                }
            }
        }
    }
    
    // 出力
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
s = list(input())
fl = False
rig_w = -1
for i in range(n)[::-1]:
    if fl and s[i] == 'W':
        rig_w = i
        break
    elif s[i] == 'R':
        fl = True
res1 = 0

if rig_w != -1:
    res1 = s[:rig_w+1].count('W')

r_count = s.count('R')
res2 = s[:r_count].count('W')

print(min(res1,res2))

Measured memory_bytes: 83696
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int M;
    cin >> M;
    cout << 48-M << endl;
    
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    if(s == "Sunny")        cout << "Cloudy" << endl;
    else if(s == "Cloudy")  cout << "Rainy" << endl;
    else if(s == "Rainy")   cout << "Sunny" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> ans;
vector<int> g[1011];
bool vis[1011];
int dist[1011];
int n,m;
bool dfs1(int x,int s) {
	if(vis[s]){
		return true;
	}
	vis[x] = 1;
	for(int u:g[x]){
		if(!vis[u]){
			if(dfs1(u,s)){
				return true;
			}
		}
	}
	return false;
}
void dfs2(int x,vector<int>& path,int s){
	path.push_back(x);
	for(int u:g[x]){
		if(u == s) {
			if(ans.size()==0||path.size()<ans.size())
				ans = path;
			path.pop_back();
			return;
		}
		if(dist[u] > dist[x] + 1) {
			dist[u] = dist[x] + 1;
			dfs2(u,path,s);
		}
	}
	path.pop_back();
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;++i) {
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
	}
	for(int i=1;i<=n;++i) {
		if(!vis[i]) {
			if(dfs1(i,i)){
				memset(dist,0x7f,sizeof dist);
				dist[i] = 0;
				vector<int> path;
				dfs2(i,path,i);
			}
		}
	}
	if(ans.size() == 0) {
		cout<<-1<<endl;
	}else {
		cout<<ans.size()<<endl;
		for(int x:ans) {
			cout<<x<<endl;
		}
	}
} 

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

int main(){

	double v;

	while(cin >> v){
		for(int i=1;; i++){
			if(v <= 9.8 * sqrt((5 * i -5) / 4.9)){
				cout << i << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1224