akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;
const int INF=1001001001;
int main(){
	char c;
	cin >> c ;
	cout << (char)(c+1) << endl;


	return 0;

}




Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		long r = solve(n);
		System.out.println(r);
		in.close();
	}

	private static long solve(int n) {
		long r = 0;
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				for (int k = 1; k <= n; k++) {
					r += gcm(i, gcm(j, k));
				}
		return r;
	}

	private static int gcm(int a, int b) {
		if (a < b)
			return gcm(b, a);
		if (a % b == 0)
			return b;
		return gcm(b, a % b);
	}

}

Measured memory_bytes: 36196
import os
import sys
from io import BytesIO, IOBase


def main():
    n = int(input())
    nums = list(map(int, input().split()))
    answer = 0
    for i in range(1, n):
        if nums[i-1] > nums[i]:
            answer += nums[i-1] - nums[i]
            nums[i] = nums[i-1]
    print(answer)

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 35720
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。
int main () {
    ll A , B , K;
    cin >> A >> B >> K;
      for(int i = 0; i < K; i++){
          if(i % 2 == 0){
              B+=A / 2;
              A/=2;               
          }
          else{
              A+=B / 2;
              B/=2;
          }
      }
      cout << A << ' ' << B << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<map>
#include<cstring>
using namespace std;
int a[110000];
const int maxn=1e5;
string code="AKIHABARA",st;
int cnt[5]={0};
int main(int argc, const char * argv[])
{
    cin>>st;
    int len=st.length();
    for(int i=0;i<len;i++)cnt[st[i]-'a']++;
    sort(cnt+0,cnt+3);
    if(cnt[2]-cnt[0]>1)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
using namespace std;
long long read()
{
	long long x=0,f=1;
	char c=getchar();
	while('0'>c||c>'9'){ if(c=='-') f=-1;c=getchar();}
	while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
long long minl(long long a,long long b)
{
	return a < b ? a : b;
}
int main()
{
	long long a,b,c;
	a=read(),b=read(),c=read();
	//printf("%lld",a);
	if(a%2==0||b%2==0||c%2==0) 
	{printf("0\n");return 0;}
	printf("%lld",minl(a*b,minl(a*c,b*c)));
}

Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll n;
  cin>>n;
  ll res = 1;
  while(n){
    (res*=n)%=mod;
    n--;
  }
  cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
const ll inf = 9e18;
const ll mod = 1e9 + 7;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

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

	ll n;
	cin>>n;
	ll a[n];
	ll c=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=1;i<n-1;i++){
		if(a[i] > a[i-1] && a[i] < a[i+1]) c++;
		if(a[i] < a[i-1] && a[i] > a[i+1]) c++;
	}
	cout<<c;
	return 0;
}


Measured memory_bytes: 256
def track_number_needed(p, n_track):
    global W
    n_luggage = 0
    for j in range(n_track):
        weight_sum = 0
        while (weight_sum + W[n_luggage] <= p):
            weight_sum += W[n_luggage]
            n_luggage += 1
            if n_luggage == len(W):
                return n
    return n_luggage


def binary_search():
    global n
    global k
    left = 0
    right = 100000 * 10000
    while(right - left > 1):
        mid = (left + right) // 2
        n_luggage = track_number_needed(mid, k)
        if n_luggage >= n:
            right = mid
        else:
            left = mid
    return right
            


if __name__ == "__main__":
    n, k = map(int, input().split())
    W = [int(input()) for i in range(n)]
    print(binary_search())




Measured memory_bytes: 9576
#include<bits/stdc++.h>
#define pb push_back
#define pob pop_back
#define vi vector<ll>
#define mp make_pair
#define sz size()
#define rep1(i,n) for(i=1;i<=n;i++)
#define ll long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define maxx 10000005
#define en "\n"
#define se second
#define fi first
#define vs vector<string>
#define edge pair<ll,ll>
#define mod 1073741824
using namespace std;
 
 
// ¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++¦¦¦++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦¦¦¦¦¦¦¦¦+++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦+++++++¦++¦¦
// ¦¦¦¦¦¦¦¦++¦¦¦¦¦¦++++++¦¦¦¦+++++++++++++¦
// ¦¦¦¦¦¦¦++++++¦¦¦++++++¦¦++++++++++++++¦¦
// ¦¦¦¦¦¦¦+++++++¦¦¦+++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++¦¦¦¦¦¦¦¦+++++++¦ 
// ¦¦¦¦¦¦¦¦¦¦++¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦++++¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦ 
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦+¦++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++¦¦+++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦¦+++¦¦¦¦++++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++¦¦+¦¦¦¦¦+++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦+++++++++++¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦¦¦¦


//ll d[1000007];
int main()
{
	fast;
	ll n;
	ll m;
	cin>>n>>m;
	ll a[m],i;
	ll d=0;
	for(i=0;i<m;i++)
	{
		cin>>a[i];
		d+=a[i];	
	}
	if(d>n)
	cout<<-1<<endl;
	else
	cout<<n-d<<endl;
	return 0;
	
}	
//cout<<"YES"<<endl;

//cout<<"NO"<<endl;

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

int main(){
	int a, b, d, r;
	double f;
	
	cin >> a >> b;
	
	d = a / b;
	r = a % b;
	f = (double)a / b;
	printf("%d %d %.5f\n", d, r, f);
	
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  string s; cin >> s;
  s.erase(unique(all(s)), s.end());
  std::cout << s.size()-1 << '\n';
}


Measured memory_bytes: 512
s = gets.chomp.chars

before = nil
traps = []
s.each_with_index do |letter, index|
  if index == 0
    before = s[0]
    next
  end
  if before == "R" && letter == "L"
    traps << index - 1
    traps << index
  end
  before = letter
end

traps_r = traps.reverse

# さいしゅうけっか
res = Array.new(s.size, 0)

# 順番に何回でtrapにはまるか見ていく
s.size.times do |i|
  if s[i] == "R"
    neibor_r = traps.bsearch{|x| x >= i}
    if neibor_r == i
      # はじめからハマっている
      res[neibor_r] += 1
    else
      # 最終位置は、neibor_r か neibor_r + 1
      if (10**100 - (neibor_r - i)) % 2 == 0
        # 偶数回のときはr
        res[neibor_r] += 1
      else
        res[neibor_r+1] += 1
      end
    end
  end

  if s[i] == "L"
    neibor_l = traps_r.bsearch{|x| x <= i}
    if neibor_l == i
      # はじめからハマっている
      res[neibor_l] += 1
    else
      # 最終位置は、neibor_l か neibor_l - 1
      if (10**100 - (i - neibor_l)) % 2 == 0
        # 偶数回のときはl
        res[neibor_l] += 1
      else
        res[neibor_l-1] += 1
      end
    end
  end
end

puts res.join(" ")


Measured memory_bytes: 12540
target_word = raw_input()
text = ''
while True:
    raw = raw_input()
    if raw == "END_OF_TEXT":
        break
    # text += raw.strip('.') + ' '
    text += raw + ' '

# ans = 0
print(text.lower().split().count(target_word))
# for word in text.lower().split():
#     if word == target_word:
#         ans += 1
# print(ans)

Measured memory_bytes: 6236
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

const int INF = 10000;

int main(){
	while(1){
		int h,w;
		scanf("%d%d",&h,&w);
		if(h == 0 && w == 0)break;
		
		vector<int> G[1100];
		int a;
		for(int i = 1 ; i <= h ; i ++){
			for(int j = 1 ; j <= w-1 ; j ++){
				scanf("%d",&a);
				if(a == 0){
					G[i*(w+2)+j].push_back(i*(w+2)+j+1);
					G[i*(w+2)+j+1].push_back(i*(w+2)+j);
				}
			}
			if(i == h)break;
			for(int j = 1 ; j <= w ; j ++){
				scanf("%d",&a);
				if(a == 0){
					G[i*(w+2)+j].push_back((i+1)*(w+2)+j);
					G[(i+1)*(w+2)+j].push_back(i*(w+2)+j);
				}
			}
		}
		
		/*for(int i = 1 ; i <= h ; i ++){
			for(int j = 1 ; j <= w ; j ++){
				printf("%d,%d:%d\n",i,j,G[i*(w+2)+j].size());
				for(int k = 0 ; k < G[i*(w+2)+j].size() ; k ++){
					printf("%d ",G[i*(w+2)+j][k]);
				}
				printf("\n");
			}
		}*/
		
		int memo[1100][2];
		for(int xi = 1 ; xi <= h ; xi ++){
			for(int xj = 1 ; xj <= w ; xj ++){
				int x = xi*(w+2)+xj;
				int cost[1100];
				for(int i = 0 ; i < 1100 ; i ++)cost[i] = INF;
				queue<int> que;
				cost[h*(w+2)+w] = 0;
				que.push(h*(w+2)+w);
				while(!que.empty()){
					int q = que.front(); que.pop();
					if(q == x)continue;
					for(int i = 0 ; i < G[q].size() ; i ++){
						if(cost[G[q][i]] > cost[q]+1){
							cost[G[q][i]] = cost[q]+1;
							que.push(G[q][i]);
						}
					}
				}
				memo[x][0] = INF;
				memo[x][1] = INF;
				for(int i = 0 ; i < G[x].size() ; i ++){
					if(memo[x][1] > cost[G[x][i]]){
						memo[x][1] = cost[G[x][i]];
						if(memo[x][0] > memo[x][1]){
							swap(memo[x][0],memo[x][1]);
						}
					}
				}
				if(xi == h && xj == w){
					memo[x][0] = 0;
					memo[x][1] = 0;
				}
			}
		}
		
		/*for(int i = 1 ; i <= h ; i ++){
			for(int j = 1 ; j <= w ; j ++){
				printf("%d,%d:%d %d\n",i,j,memo[i*(w+2)+j][0],memo[i*(w+2)+j][1]);
			}
		}*/
		
		int l = memo[w+3][1] , r = INF;
		while(l < r){
			int m = (l+r)/2;
			int cost[1100];
			for(int i = 0 ; i < 1100 ; i ++)cost[i] = INF;
			queue<int> que;
			cost[w+3] = 0;
			que.push((w+2)+1);
			while(!que.empty()){
				int q = que.front(); que.pop();
				for(int i = 0 ; i < G[q].size() ; i ++){
					if(memo[G[q][i]][1]+2+cost[q] <= m && cost[G[q][i]] > cost[q]+1){
						cost[G[q][i]] = cost[q]+1;
						que.push(G[q][i]);
					}
				}
			}
			if(cost[h*(w+2)+w] < INF)r = m;
			else l = m+1;
		}
		
		if(l < INF)printf("%d\n",l);
		else puts("-1");
	}
}

Measured memory_bytes: 3312
import itertools
import math

N = int(input())
root = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for l in list(itertools.permutations(root)):
    total = 0
    for i in range(len(l) - 1):
        total += math.sqrt(((l[i][0] - l[i + 1][0]) ** 2) + ((l[i][1] - l[i + 1][1]) ** 2))
    ans += total
print(ans / math.factorial(N))

Measured memory_bytes: 7972
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    a, b, k = list(map(int, input().rstrip('\n').split()))
    t = min(a, k)
    a -= t
    k -= t
    t = min(b, k)
    b -= t
    print(a, b)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
    
        int x = scanner.nextInt();
        int h = x / 3600;
        int m = (x - h*3600) / 60;
        int s = x - h*3600 - m*60;

        System.out.print(h);
        System.out.print(":");
        System.out.print(m);
        System.out.print(":");
        System.out.println(s);
    }
}


Measured memory_bytes: 26236
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define F first
#define S second
#define ll long long
#define N 2100000
#define M 22
using namespace std;
ll n,dp[M][N],a[M][M];
ll dfs(ll x,ll s)
{
	if(s==0)
	{
		return 1;
	}
	if(dp[x][s]!=-1)
	{
		return dp[x][s];
	}
	ll i;
	dp[x][s]=0;
	for(i=0;i<n;i++)
	{
		if((s&(1<<i))!=0&&a[x][i]==1)
		{
			dp[x][s]=(dp[x][s]+dfs(x-1,s-(1<<i)))%MOD;
		}
	}
	return dp[x][s];
}
int main(){
	ll i,j;
	cin>>n;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			cin>>a[i][j];
		}
	}
	memset(dp,-1,sizeof(dp));
	cout<<dfs(n-1,(1<<n)-1);
	return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(string S){
    LL a1 = 0;
    LL a2 = 0;
    REP(i, S.length()) {
        if(S[i] == '0' && i % 2 == 0) a1++;
        if(S[i] == '1' && i % 2 == 1) a1++;
        if(S[i] == '0' && i % 2 == 1) a2++;
        if(S[i] == '1' && i % 2 == 0) a2++;
    }

    cout << min(a1, a2) << endl;
}

int main(){
    string S;
    cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 512
#
# File    : B.rb
# Author  : Kazune Takahashi
# Created : 2018-9-23 21:03:15
# Powered by Visual Studio Code
#

n, m, x, y = gets.chomp.split(" ").map{|i| i.to_i}
k = gets.chomp.split(" ").map{|i| i.to_i}
l = gets.chomp.split(" ").map{|i| i.to_i}
if [x, k.max].max < [y, l.min].min
  puts "No War"
else
  puts "War"
end


Measured memory_bytes: 1788
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    akari<int> as(n);
    akari<pair<i64, int>> ps(n);
    for (int i = 0; i < n; i++)
    {
        cin >> as[i];
        ps[i] = {as[i], i};
    }
    sort(ps.rbegin(), ps.rend());
    akari<i64> dp(n, -1e18);
    dp[0] = 0;
    for (int i = 0; i < n; i++)
    {
        auto new_dp(dp);
        int k = ps[i].second;
        i64 a = ps[i].first;
        for (int j = 0; j < n; j++)
        {
            if (j)
            {
                new_dp[j] = max(new_dp[j], dp[j - 1] + abs(j - k - 1) * a);
            }
            new_dp[j] = max(new_dp[j], dp[j] + abs(n - 1 - i + j - k) * a);
        }
        swap(dp, new_dp);
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DEC(i, a, b) for (int i = (a); i > (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int A,B;
  cin>>A>>B;
  int ans;
  ans = max(A+B,A-B);
  ans = max(ans,A*B);
  cout << ans << endl;
  return 0;
}

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

 using namespace std;

 int main() {
   int H, W, i, j;

   cin >> H >> W;

   vector<vector<char>> S(H + 2, vector<char>(W + 2, '.'));
   vector<vector<int>> ANS(H + 1, vector<int>(W + 1, 0));

   for (i = 1; i <= H; i++) {
     for (j = 1; j <= W; j++) {
       cin >> S.at(i).at(j);
     }
   }

   for (i = 1; i <= H; i++) {
     for (j = 1; j <= W; j++) {
       if (S.at(i).at(j) == '.') {
         if (S.at(i - 1).at(j - 1) == '#') ANS.at(i).at(j)++;
         if (S.at(i - 1).at(j) == '#') ANS.at(i).at(j)++;
         if (S.at(i - 1).at(j + 1) == '#') ANS.at(i).at(j)++;
         if (S.at(i).at(j - 1) == '#') ANS.at(i).at(j)++;
         if (S.at(i).at(j + 1) == '#') ANS.at(i).at(j)++;
         if (S.at(i + 1).at(j - 1) == '#') ANS.at(i).at(j)++;
         if (S.at(i + 1).at(j) == '#') ANS.at(i).at(j)++;
         if (S.at(i + 1).at(j + 1) == '#') ANS.at(i).at(j)++;
       }
     }
   }

   for (i = 1; i <= H; i++) {
     for (j = 1; j <= W; j++) {
       if (S.at(i).at(j) == '.') cout << ANS.at(i).at(j);
       else cout << '#';
     }
     cout << endl;
   }
 }


Measured memory_bytes: 256
#include <iostream>
using namespace std;
bool is_prime(int a)
{
	int n = 2;
	while(n*n <= a){
		if(a%n == 0) return false;
		n ++;
	}
	return true;
}

int main(int argc, char const *argv[])
{
	int n = 0 ;
	cin >> n;
	int count = 0;
	for(int i = 0; i < n ; i ++){
		int a = 0;
		cin >> a ;
		if(is_prime(a)) count ++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653


int main(){
	ll k,a,b; cin >> k >> a >> b;
	ll x = k;
	while(x<a){
		x += k;
	}
	if (x<=b){
		cout << "OK" << endl;
	}
	else{
		cout << "NG" << endl;
	}
}

Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const int mod = (int)1e9 + 7;
const int mod2 = 998244353;

ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
	if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll mul(ll a, ll b, ll md){
	return a*b % md;
}

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
	fact.resize(n+5);
	inv_fact.resize(n+5);
	fact[0] = inv_fact[0] = 1;
	for(int i = 1; i <= n; i++){
		fact[i] = (fact[i-1] * i) % mod;
		inv_fact[i] = exp(fact[i], mod-2, mod);
	}
}

ll komb(ll a, ll b){
	if(a < b) return 0;
	return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}

const int N = 1e5+5;

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL);
	int a[5];
	for(int i = 0; i < 5; i++) cin>>a[i];
	for(int i = 0; i < 5; i++) if(!a[i]) cout<<i+1;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n,m;
  cin >> n >> m;
  vector<int64_t> h(n);
  rep(i,n){
    cin >> h.at(i);
  }
  vector<pair<int,int>> a(m);
  rep(i,m){
    int b,c;
    cin >> b >> c;
    a.at(i)=make_pair(b,c);
  }
  sort(a.begin(),a.end());
  vector<bool> ans(n);
  rep(i,n){
    ans.at(i)=true;
  }
  rep(i,m){
    if(h.at(a.at(i).first-1)<h.at(a.at(i).second-1)){
      ans.at(a.at(i).first-1)=false;
    }
    if(h.at(a.at(i).first-1)>h.at(a.at(i).second-1)){
      ans.at(a.at(i).second-1)=false;
    }
    if(h.at(a.at(i).first-1)==h.at(a.at(i).second-1)){
      ans.at(a.at(i).second-1)=false;
      ans.at(a.at(i).first-1)=false;
    }
  }
  int count=0;
  rep(i,n){
    if(ans.at(i)){
      count++;
    }
  }
  cout << count;
}
    
    
      
    
  

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

const int INF = 2e9;

int main(){
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
}


Measured memory_bytes: 3636
/* Aditya0412 */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define all(a)      (a).begin(),(a).end()
#define si(x)       (int)((x).size())
#define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();  
#define se second 
#define endl        '\n'
#define f(i,a,b)    for(int i=a;i<b;i++)
#define mem(a,x)          memset(a,x,sizeof(a))

// const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=1000000+6;
#define M_PI           3.14159265358979323846



// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
    os<<"[";
    for(auto& x:v){os<<x<<", ";}
    return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
    return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===


void inp(ll *arr,ll n)
{
  for(int i=0;i<n;i++)
    cin>>arr[i];
}
void inp_mat(ll *arr,ll n,ll m)
{
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
        {
          ll x;cin>>x;
          *((arr+i*m) + j)=x;
        }
}
// syntax for inp_mat inp_mat((ll *)arr,n,m);
// int x2[]={+1,-1,+0,+0};
// int y2[]={+0,+0,+1,-1};
// int x2[]={+0,+0,+1,-1,-1,+1,-1,+1};
// int y2[]={-1,+1,+0,+0,+1,+1,-1,-1};
// int x2[]={-2,-2,-1,-1,+1,+1,+2,+2};
// int y2[]={-1,+1,-2,+2,-2,+2,-1,+1};
int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //  #ifndef ONLINE_JUDGEc
    //   freopen ("INPUT.txt" , "r" , stdin);
    //   freopen ("OUTPUT.txt", "w" , stdout);
    // #endif 
   ll x;cin>>x;
   ll y=7;
   int c=1;
   map<int , int > m;
   while(1)
   {
      if(y%x==0)
      {
        cout<<c;
        return 0;
      }
      else
      {
        y*=10;
        y+=7;
        y%=x;
        c++;
        if(m[y]==0)
        {
          m[y]++;
        }
        else
        {
          cout<<"-1";
          return 0;
        }
        
      }
      
   }
} 

Measured memory_bytes: 50516
#include <stdio.h>

int main(void)
{

	char ch[1200];
	int i, n;
	n = 0;
	char a[1200];

	while (1) {
		scanf("%c", &a[n]);
		if (a[n] == '\n') {
			break;
		}
		ch[n] = a[n];
		if ('A' <= a[n] && a[n] <= 'Z') {
			ch[n] = a[n] + 32;
		}
		else if (a[n] >= 'a' && a[n] <= 'z') {
			ch[n] = a[n] - 32;

		}


		n = n + 1;

	}

	for (i = 0; i < n; i++) {
		printf("%c", ch[i]);
	}
	printf("\n");
	return 0;

}


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

int main(){
  int S,a,b,c,d,x,y,z;
  cin>>S;
  a=S/1000;
  x=S%1000;
  b=x/100;
  y=x%100;
  c=y/10;
  d=y%10;
  if(a==b){
    cout<<"Bad";
  }else if(b==c){
    cout<<"Bad";
  }else if(c==d){
    cout<<"Bad";
  }else{
    cout<<"Good";
  }
  cout<<endl;
return 0;
}

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

int main() {
  int n;
  cin >> n;
  long double num;
  long double ans = 0;
  string tem;
  for(int i = 0; i < n; i++) {
    cin >> num >> tem;
    if(tem == "JPY") {
      ans += num;
    }
    else {
      ans += num * 380000.0;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
import bisect

s = int(input())

a = [s]
n = s
for i in range(1000000):
    
    o = n
    n = 3 * o + 1
    if o % 2 == 0:
        n = o // 2
    # print(bisect.bisect_left(a,n),bisect.bisect_right(a,n),n)
    if bisect.bisect_left(a,n) == bisect.bisect_right(a,n):
        bisect.insort(a,n)
        # print(s)
    else:
        # print(i,n)
        print(i+2)
        exit()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

ll modpow(ll x, ll b){
  ll res = 1;
  while(b){
    if(b&1)res = res * x % MOD;
    x = x * x % MOD;
    b>>=1;
  }
  return res;
}

ll modinv(ll x){
  return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
  if(was_output)cout << " ";
  cout << a;
  was_output = true;
}
void outendl(){
  was_output = false;
  cout << endl;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

template<class t>
void out(t x){
  cout << x;
}

int main(){
  ll n = in();
  ll ans = n-1;
  for(ll i=2;i*i<=n;++i){
    if(n%i==0)chmin(ans,i+n/i-2);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
  ps = list(map(int, [input() for _ in range(5)]))
  k = int(input())
  for i in range(len(ps)):
    for j in range(i, len(ps)):
      if abs(ps[i] - ps[j]) > k:
        print(':(')
        return
  print('Yay!')
  
main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()



int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a*n, b) << endl;
    return 0;
}


Measured memory_bytes: 256
downs, ponds = [], []
for i, s in enumerate(input()):
  if s == "\\":
    downs.append(i)
  elif s == "/" and downs:
    i_down = downs.pop()
    area = i - i_down
    while ponds and ponds[-1][0] > i_down:
      area += ponds.pop()[1]
    ponds.append([i_down, area])
print(sum(p[1] for p in ponds))
print(len(ponds), *(p[1] for p in ponds))


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

using ll = long long;
using namespace std;

#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define LFOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define FORR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define LFORR(i,a,b) for(ll i = (int)(a); i >= (ll)(b); i--)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define LREP(i,n) LFOR(i,0,(ll)(n)-1)
#define REPR(i,n) FORR(i,(int)(n)-1,0)
#define LREPR(i,n) LFORR(i,(ll)(n)-1,0)

#define SIZ(v) int(v.size())
const int INF = 1e8;
const ll LINF = 1e15;
const int MOD = 1e9+7;



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,t;
  cin >> s;
  cin >> t;
  int ans=0;
  REP(i,3){
    if (s[i]==t[i]) ans++;
  }
  cout << ans << endl;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 0x3fffffff;
const ll MOD = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(0);
	ll N;

	cin >> N;

	ll dp[1000006]={}, sum=N-1;
	dp[0] = N;
	rep(i,N){
		// 1
		dp[i+1] = (dp[i+1] + dp[i]) % MOD;
		// larger than 1
		dp[i+1] = (dp[i+1] + sum) % MOD;
		//dp[i+1] = (dp[i+1] + min(N-1, (N-i+1))) % MOD;
		dp[i+1] = (dp[i+1] + ( (N-1)*(N-1) )%MOD ) % MOD;
		// sum
		if( i >= 1 ) sum = (sum + dp[i-1] - 1) % MOD;

		//cout << dp[i] << endl;
	}

	cout << dp[N-1] << endl;

	return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c, cnt=0;
  cin >> a >> b >> c;
  if ( a==b && b==c && c==a ){
    if( a%2 == 0 && b%2 == 0 && c%2 == 0 )  cout << -1 << endl;
    else cout << 0 << endl;
    return 0;
  }
  int al=0, bl=0, cl=0;
  for(int i; i<1e9+7; i++){
    if( a%2 ==1 || b%2 == 1 || c%2 == 1)  break;
    al = (b+c)/2;
    bl = (a+c)/2;
    cl = (a+b)/2;
    a = al;
    b = bl;
    c = cl;
    cnt++;
  }
  cout << cnt << endl;
}

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

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int map[100][100];
int n, m;
int maxi;

void Search(int y, int x, int d)
{
	maxi = max(maxi, d);
	
	map[y][x] = 0;
	
//	bool f = false;
	
	for (int i = 0; i < 4; i++){
		if (map[y + dy[i]][x + dx[i]]){
			Search(y + dy[i], x + dx[i], d + 1);
//			f = true;
		}
	}
	
	map[y][x] = 1;
}

int main()
{
	while (scanf("%d %d", &m, &n), m + n){
		memset(map, 0, sizeof(map));
		maxi = 0;
		
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= m; j++){
				scanf("%d", &map[i][j]);
			}
		}
		
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= n; j++){
				if (map[i][j]){
					Search(i, j, 1);
				}
			}
		}
		
		printf("%d\n", maxi);
	}
	
	return 0;
}

Measured memory_bytes: 1072
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;


int main(int argc, const char * argv[]) {
    int n, m;
    cin >> n >> m;
    int l, r;
    int ml = 0;
    int mr = 9999999;
    for(int i = 0; i < m; i++){
        cin >> l >> r;
        ml = max(ml, l);
        mr = min(mr, r);
    }
    
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        if(i >= ml && i <= mr){
            ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
   		String s = sc.nextLine();
      	if(s.substring(2,3).equals(s.substring(3,4)) && s.substring(4,5).equals(s.substring(5,6)))
           System.out.println("Yes");
        else System.out.println("No");
    	
    }
}


Measured memory_bytes: 22612
#include <iostream>

using namespace std;

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

	long long ans = 0;

	for (int i = 1; i <= N; ++i) {
		if (i % 3 != 0 && i % 5 != 0) {
			ans += i;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n,m,x;
	cin>>n>>m>>x;
	vector<int> c(n);
	vector<int> a(n*m);
	for(int i=0;i<n;i++){
		cin>>c[i];
		for(int j=0;j<m;j++){
			cin>>a[i*m+j];
		}
	}
	vector<int> sum(m);
	int cost,min=-1;
	for(int i=0;i<(1<<n);i++){
		//initialize
		for(int j=0;j<m;j++)sum[j]=0;
		cost = 0;
		//
		for (int k=0;k<n;k++){
			if((i&(1<<k))>0){
				for(int j=0;j<m;j++){
					sum[j]+=a[k*m+j];
				}
				cost += c[k];
			}
		}

		for(int j=0;j<m;j++){
			if(sum[j]<x)break;
			else if(j==m-1){
				if(min==-1||min>cost)min=cost;
			}
		}
	}
	cout<<min<<endl;
	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, a[200008], x[200008], ans[200008];
vector<vector<ll>> g;

bool f(ll xi, ll aa){
	return x[xi] >= aa;
}

ll cal(ll aa){
	ll ok = n+1;
	ll ng = 0;
	while(ok-ng > 1){
		ll mid = (ok+ng)/2;
		
		if(f(mid, aa)){
			ok = mid;
		}
		else{
			ng = mid;
		}
	}
	return ok; 
}

void dfs(ll at, ll from){
	
	ll ind = cal(a[at]);
	ans[at] = (from == -1)? 1 : max(ans[from], ind);
	
	ll tmp = x[ind];
	x[ind] = a[at];
	
	zep(i, 0, g[at].size()){
		ll nx = g[at][i];
		if(nx != from){
			dfs(nx, at);
		}
	}
	
	x[ind] = tmp;
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n;
	zep(i, 0, n)cin >> a[i];
	g.resize(n);
	zep(i, 0, n-1){
		ll u, v; cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	rep(i, 1, n)x[i] = INF;
	x[0] = 0;
	
	dfs(0, -1);
	
	zep(i, 0, n){
		print(ans[i])
	}
	return 0;
}

Measured memory_bytes: 33208
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll N;
    cin >> N;
    ll A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    //和がマイナスから始まる
    ll sumP = 0;
    ll costP = 0;
    for(int i = 0; i < N; i++){
        sumP += A[i];
        if(i % 2 == 0){
            if(sumP >= 0){
                costP += sumP + 1;
                sumP = -1;
            }
        }else{
            if(sumP <= 0){
                costP += -sumP + 1;
                sumP = 1;
            }
        }
        //cout << costP << endl;
    }
    //和がプラスから始まる
    ll sumM = 0;
    ll costM = 0;
    for(int i = 0; i < N; i++){
        sumM += A[i];
        if(i % 2 == 1){
            if(sumM >= 0){
                costM += sumM + 1;
                sumM = -1;
            }
        }else{
            if(sumM <= 0){
                costM += -sumM + 1;
                sumM = 1;
            }
        }
    }
    //cout << costM << "," << costP << endl;
    cout << min(costM,costP) << endl;

}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int h, w;
  cin >> h >> w;

  char a[h + 2][w + 2];
  REP (i, h) {
    REP (j, w) {
      cin >> a[i][j];
    }
  }

  bool z = false;
  while(!z) {
    z = true;
    REP (i, h) {
      bool flag = true;
      REP (j, w) {
        if (a[i][j] == '#') flag = false;
      }
      if (flag) {
        FOR(k, i, h - 1) {
          REP (j, w) {
            a[k][j] = a[k + 1][j];
          }
        }
        z = false;
        h--;
      }
    }
    REP (j, w) {
      bool flag = true;
      REP (i, h) {
        if (a[i][j] == '#') flag = false;
      }
      if (flag) {
        FOR(k, j, w - 1) {
          REP (i, h) {
            a[i][k] = a[i][k + 1];
          }
        }
        z = false;
        w--;
      }
    }
  }

  REP (i, h) {
    REP (j, w) {
      cout << a[i][j];
      if (j == w - 1) cout << endl;
    }
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <vector>
#include <iterator>
using namespace std;
int main()
{
    int n,c = 0,w = 0,t = 0,r = 0;
    cin >> n;
    vector<string>v(n);
    vector<string> :: iterator it;

    for(it = v.begin();it != v.end();it++)
        cin >> *it;

    for(it = v.begin();it != v.end();it++)
    {
        if(*it == "AC")
        c++;
        else if(*it == "WA")
            w++;
        else if(*it == "TLE")
            t++;
        else if( *it  == "RE")
            r++;
    }
    cout << "AC x " << c << endl;
    cout << "WA x " << w << endl;
    cout << "TLE x " << t << endl;
    cout << "RE x " << r << endl;



}


Measured memory_bytes: 6436
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long int ll;

int memo[2020][2020], memo2[2020][2020], memo3[2020][2020], memo4[2020][2020];

int main(){
	int h, w;
	cin >> h >> w;
	vector<string> s(h + 2);
	for(int i = 1; i <= h; i++){
		cin >> s[i];
		s[i] = "@" + s[i] + "@";
	}
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++){
			if(s[i][j] == '#') continue;
			else memo[i][j] = memo[i][j - 1] + 1;
		}
	}
	for(int i = 1; i <= h; i++){
		for(int j = w; j >= 1; j--){
			if(s[i][j] == '#') continue;
			else memo2[i][j] = memo2[i][j + 1] + 1;
		}
	}
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++){
			if(s[i][j] == '#') continue;
			else memo3[i][j] = memo3[i - 1][j] + 1;
		}
	}
	for(int i = h; i >= 1; i--){
		for(int j = 1; j <= w; j++){
			if(s[i][j] == '#') continue;
			else memo4[i][j] = memo4[i + 1][j] + 1;
		}
	}
	int res = 0;
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++){
			if(s[i][j] == '#') continue;
			int num = memo[i][j] + memo2[i][j] + memo3[i][j] + memo4[i][j];
			num -= 3;
			res = max(res, num);
		}
	}
	cout << res << endl;
	return 0;
}


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

int main() {

  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  bool ans = false;
  
  if (abs(a-c) <= d) ans = true;
  else if (abs(a-b) <= d) {
    if (abs(b-c) <= d) ans = true;
  }
  
  cout << ((ans) ? "Yes" : "No") << endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	
	int num;
	int aci;
	char total[52];
	
	scanf("%d %d", &num, &aci);
	scanf("%s", &total);
	
	total[aci - 1] = total[aci - 1] + 32;
	
	printf("%s", total);
	
	return 0;
}

Measured memory_bytes: 3204
#include <cstdio>
typedef long long ll;

const int N=20,mod=1e9+7;;
int n,m,a[N];
ll fac[1<<(N-3)],ifac[1<<(N-3)],dp[N][1<<(N-3)],ans;
inline int read() {
	int x=0,flag=0;char ch=getchar();
	while(ch<'0'||ch>'9'){flag|=(ch=='-');ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return flag?-x:x;
}
inline int mx(int x,int y) {return x>y?x:y;}
inline int mn(int x,int y) {return x<y?x:y;}

inline int ksm(int a,int b,int p){
	int ans=1;
	for(;b;b>>=1,a=1ll*a*a%p)
		if(b&1)ans=1ll*ans*a%p;
	return ans;
}
inline void init(int n) {
	fac[0]=ifac[0]=1;
	for(int i=1;i<=n;++i)
		fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n]=ksm(fac[n],mod-2,mod);
	for(int i=n-1;i>=1;--i)
		ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
}
inline ll C(int m,int n) {
	if(n<m||m<0) return 0;
	return 1ll*fac[n]*ifac[n-m]%mod*ifac[m]%mod;
}
int main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();m=read();
	for(int i=1;i<=m;++i)
		a[i]=read();
	init(1<<n);
	dp[m+1][0]=1;
	for(int i=m;i>=1;--i)
		for(int j=0;j<(1<<n);++j) {
			dp[i][j]+=dp[i+1][j];dp[i][j]%=mod;
			for(int k=0;k<n;++k) {
				if((j>>k)&1) continue;
				dp[i][j|(1<<k)]+=1ll*dp[i+1][j]*C((1<<k)-1,(1<<n)-j-a[i])%mod*fac[1<<k]%mod;
				dp[i][j|(1<<k)]%=mod;
			}
		}
	for(int j=0;j<(1<<n);++j) {
		int cnt=0;
		for(int i=j;i;i-=i&-i) ++cnt;
		if(cnt&1) ans+=mod-1ll*dp[1][j]*fac[(1<<n)-j-1]%mod;
		else ans+=1ll*dp[1][j]*fac[(1<<n)-j-1]%mod;
		ans%=mod;
	}
	printf("%lld\n",ans*(1<<n)%mod);
	return 0;
}


Measured memory_bytes: 12456
#include <iostream>
#include <cmath>

typedef long long ll;
using namespace std;

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

Measured memory_bytes: 256
n = gets().to_i
arr = gets().split.map(&:to_i)

def selection_sort(n, arr)
  cnt = 0
  for i in 0...n
    minj = i
    for j in i...n
      if arr[j] < arr[minj]
        minj = j
      end
    end
    if i != minj
      arr[i], arr[minj] = arr[minj], arr[i]
      cnt += 1
    end
  end
  return arr, cnt
end

arr, cnt = selection_sort(n, arr)
puts arr.join(' ')
puts cnt


Measured memory_bytes: 8868
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  bool TorF=false;
  cin>>n;
  for(int cakes=0;cakes<=100;cakes++){
    for(int donuts=0;donuts<=100;donuts++){
      int price=4*cakes+7*donuts;
      if(n==price){
        TorF=true;
      }
    }
  }
  if(TorF==true){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

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

int main(){
    string x, y;
    cin >> x;
    y = x;
    reverse(y.begin(), y.end());

    if(x == y){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


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

int main () {
  int num;
  int surpass;
  cin >> num;
  
  surpass = num % 10;
  
  if (surpass == 3) {
   cout << "bon" << endl; 
  } else if (surpass == 0 || surpass == 1 || surpass == 6 || surpass == 8) { // 0,1,6,8
   cout << "pon";
  } else {
   cout << "hon" << endl;
  }
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  ll n;
  string s, t;
  cin >> n >> s >> t;

  ll res = 2*n;

  for (int i = 0; i < n; i++){
    int ok = 1;
    for (int j = i; j < n; j++){
      if (s[j] != t[j - i])
        ok = 0;
    }
    if(ok)
      res = min(res, i + n);
  }

  cout << res << endl;
  

  return 0;
}


Measured memory_bytes: 256