akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long int;

const int MAX_N = (int)(1e5 + 5);

int n;
ll t, a[MAX_N];

ll buys[MAX_N];
ll sells[MAX_N];

set<int> buyset, sellset;

int ans;

int main(void) {
  // Here your code !
  scanf("%d %lld", &n, &t);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &(a[i]));
  }

  buys[0] = a[0];
  for (int i = 1; i < n - 1; ++i) {
    buys[i] = min(buys[i - 1], a[i]);
  }

  sells[n - 2] = a[n - 1];
  for (int i = n - 3; i >= 0; --i) {
    sells[i] = max(sells[i + 1], a[i + 1]);
  }

  ll maxprohit = -1;
  for (int i = 0; i < n - 1; ++i) {
    maxprohit = max(maxprohit, sells[i] - buys[i]);
  }

  vector<int> cand;
  for (int i = 0; i < n - 1; ++i) {
    if (maxprohit == (sells[i] - buys[i])) {
      buyset.insert(buys[i]);
      sellset.insert(sells[i]);
    }
  }

  ans = buyset.size() > sellset.size() ? sellset.size() : buyset.size();

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

  return 0;
}

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

using namespace std;

const int mod = 1e9 + 7;

int n, c[3];
double dp[310][310][310];

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        c[x - 1]++;
    }
    for(int k = 0; k <= c[2]; k++){
        for(int j = 0; j <= n; j++){
            for(int i = 0; i <= n; i++){
                int tc = i + j + k;
                if(!tc || tc > n) continue;
                dp[i][j][k] = 1;
                if(i) dp[i][j][k] += dp[i - 1][j][k] * i / n;
                if(j) dp[i][j][k] += dp[i + 1][j - 1][k] * j / n;
                if(k) dp[i][j][k] += dp[i][j + 1][k - 1] * k / n;
                dp[i][j][k] *= (double) n / tc;
            }
        }
    }
    cout << fixed << setprecision(10) << dp[c[0]][c[1]][c[2]] << '\n';
}

Measured memory_bytes: 225536
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}



signed main() {
	int n, h, w;
	cin >> n >> h >> w;
	cout << (n - h + 1)*(n - w + 1) << endl;
	getchar(); getchar();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
//251103FD
using namespace std;
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define bf push_front
#define mp make_pair
#define s second
#define f first
#define mt make_tuple
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define forn(i, a) for(int i=0; i<a; i++)
#define Forn(i, a) for(int i=1; i<=a; i++)
#define read(x) ((scanf("%s", &_), (x) = _))
#define INF 1e9
#define memINF 127
#define inf 1e18
#define all(x) x.begin(), x.end()
#define MOD 1e9+7 
#define HASH 1543 

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;

using namespace std;

inline int in() 
{
    int x=0, c;
    for(; (uint)((c=getchar())-'0')>=10;) 
	{ 
		if(c=='-') 
			return -in(); 
		if(!~c)
			throw ~0; 
	}
    do 
	{ 
		x=(x<<3)+(x<<1)+(c^48); 
	} 
	while((uint)((c=getchar())^48)<10);
    return x;
}
inline int gcd(int a, int b){if(a>b) swap(a, b); return a==0?b:gcd(b%a, a);}
inline int lcm(int a, int b){return a*b/gcd(a, b);}

int N, M, dist[200010], a, b, c;
vector<pi> e[200010];
bool vis[200010];
unordered_set<int> inr[200010];

int main()
{
	while(~scanf("%d %d",&N,&M))
	{
		memset(vis, false, sizeof(vis));
		memset(dist, 63, sizeof(dist));
		Forn(i, 200005)
			e[i].clear(), inr[i].clear();
		while(M--)
		{
			a=in(), b=in(), c=in();
			e[a].eb(mp(b, c));
			e[b].eb(mp(a, c));
		}
		priority_queue<pi> q;
		dist[1]=0;
		vis[1]=true;
		q.push(mp(0, 1));
		while(!q.empty())
		{
			int st=q.top().s, cost=-q.top().f;
			q.pop();
			vis[st]=true;
			if(cost>dist[st])
				continue;
			foreach(it, e[st])
			{
				int ed=it->f, c=it->s, d=dist[st]+(!inr[st].count(c));
				if(vis[ed]||dist[ed]<d)
					continue;
				if(dist[ed]>d)
				{
					dist[ed]=d;
					q.push(mp(-d, ed));
					inr[ed].clear();
				}
				inr[ed].insert(c);
			}
		}
		if(dist[N]>INF)
			puts("-1");
		else
			printf("%d\n", dist[N]);
	}
	return 0;
}

Measured memory_bytes: 33268
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

counter = 0
N = 1
A,B = MAP()

while N<B:
    N -= 1
    N+= A
    counter+=1

print(counter)


Measured memory_bytes: 3060
import sys
bbn=1000000007
	
#+++++

def mk_path(a_i, max_n, ret):
	#a_i = 1 ... max_n
	#7 => 7,(6,1),(5,2),(4,3)
	#8 => (8,1),(7,2),(6,3),(5,4)
	off=0 if max_n % 2 == 1 else 1
	
	for i in range(a_i+1, max_n+1):
		if i == max_n - a_i + off:
			continue
		else:
			ret.append((a_i, i))
			
	return 
	
def check_constraint(graph, n):
	cc=[0]*n
	for f,t in graph:
		cc[f-1] += t
		cc[t-1] += f
	
	pa(('max:',max(cc),', min:', min(cc) ))
	return
	
		
def main():
	n = int(input())
	ret=[]
	for i in range(1,n+1):
		mk_path(i,n,ret)
	
	#check_constraint(ret, n)
	print(len(ret))
	for f,t in ret:
		pass
		print(f,t)

	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
#define PII pair<LL,LL>
#define FOR(i,a,b) for (LL i=(a);i<=(b);++i)
#define ROF(i,b,a) for (LL i=(b);i>=(a);--i)
typedef long long LL;
inline LL read(){
	LL x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}
LL Manacher(string s) {
    // Insert '#'
    string t = "$#";
    for (int i = 0; i < s.size(); ++i) { t += s[i]; t += "#"; }
	cout<<t<<endl;
    // Process t
    vector<int> p(t.size(), 0);
    int mx = 0, id = 0, resLen = 0, resCenter = 0;
    for (int i = 1; i < t.size(); ++i) {
        p[i] = mx > i ? min(p[2 * id - i], mx - i) : 1;
        while (t[i + p[i]] == t[i - p[i]]) ++p[i];
        if (mx < i + p[i]) {
            mx = i + p[i];
            id = i;
        }
    }
	for (int i=0;i<p.size();++i) printf("%d",p[i]); printf("\n");
	LL ans=0;
	for (int i=2;i<=s.size()*2;i++)
	if (p[i]>2) ans+=(p[i]/2*2-1)/2;
	return ans;
}
const LL MAXN=350005,Mo=1000000007;
LL n,m,a[26];
int main(){
	char t[MAXN];
	scanf("%s",t+1); n=strlen(t+1);
	memset(a,0,sizeof(a));
	LL ans=0,tmp;
	ROF(i,n,1) {
		tmp=0;
		FOR(j,0,25) if (t[i]-'a'!=j) tmp+=a[j];
		ans+=tmp;
		a[t[i]-'a']++;
	}
	cout<<ans+1<<endl;
	return 0;
}

/*
*/


Measured memory_bytes: 512
#include<stdio.h>

int main(void) {
	
	char S[10000];
	int N, i=0;

	scanf("%d", &N);
	scanf("%s", &S);

	for (i = 0; S[i] != NULL; i++) {
		S[i] += N;
		
		if (S[i] > 'Z') {
			S[i] -= 26;
		}
		printf("%c", S[i]);
	}
	
}

Measured memory_bytes: 128
n, m = map(int, input().split())
lst = list(map(int, input().split()))
pair_lst = [list(map(int, input().split())) for _ in range(m)]


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
        
    def same_check(self, x, y):
        return self.find(x) == self.find(y)    

    
uf = UnionFind(n)
for pair in pair_lst:
    uf.union(pair[0], pair[1])
    
count = 0
for i in lst:
    if uf.same_check(i, lst[i-1]):
        count += 1
print(count)

Measured memory_bytes: 36100
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)

bool use[10]={0};

double NN;
double yx[50][2]={0};
double sumj=0;

ll kai(ll a){
if(a<=1){
  return 1;
}
return a*kai(a-1);
}

ll ser(ll c,double prex,double prey,double ss){

if(c==NN){
  sumj+=ss;
  //cout<<ss<<endl;
  return 0;
}
for(ll i=0;i<NN;i++){
if(use[i]==0){
  use[i]=1;
  double tmp = sqrt((prex-yx[i][0])*(prex-yx[i][0])+(prey-yx[i][1])*(prey-yx[i][1]));
  ser(c+1,yx[i][0],yx[i][1],tmp+ss);
  use[i]=0;
}
}
}

int main(){


ll N;cin>>N;
NN=N;
for(ll i=0;i<N;i++){
  cin>>yx[i][0]>>yx[i][1];
}


for(ll i=0;i<N;i++){
  use[i]=1;
  ser(1,yx[i][0],yx[i][1],0);
    use[i]=0;
}

//cout<<sumj/kai(N)<<endl;
printf("%.15f\n",sumj/kai(N));


}

Measured memory_bytes: 256
// C++(Clang 10.0.0)

//GCC用 ナゾです
//#pragma GCC target("avx")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <stdio.h>
#include <stdlib.h> //rand() 0~RAND_MAX2147483647
#include <math.h>
#include <time.h>   //srand((unsigned int)time(NULL));
#include <unistd.h> //sleep
#include <algorithm>
#include <cmath>
#include <vector>
#include <regex> //正規表現
#include <map>
#include <unordered_map>
#include <set>
#include <cassert> //assart(x>=0) -> x<0の時異常終了
#include <numeric>
#include <iterator>
#include <list>
#include <tuple>
#include <queue>

using namespace std;
#define ll long long int
#define FOR(i,min,max) for(ll i=(min);i<(max);i++)
#define FOReq(i,min,max) for(ll i=(min);i<=(max);i++)
#define FORREV(i,max,min) for(ll i=(max)-1;i>=(min);i--)
#define FORREVeq(i,max,min) for(ll i=(max);i>=(min);i--)

#define all(vec) (vec).begin(),(vec).end()

const int MOD=1e9+7;
const int MOD2=998244353;
const int not0=1;
const int INF=2000000001;
const ll INFll=2e18;
//const int MAX_V=10000;
const double  Micro=1e-5;

int UnUsedVariable(){
    if(INF || Micro || MOD || INFll || MOD2 || not0){;}
    return 0;
}

#define inarray(array,min,max) FOR(i,min,max){cin>>array[i];}
#define inarrayW(arrayA,arrayB,min,max) FOR(i,min,max){cin>>arrayA[i]>>arrayB[i];}
#define br printf("\n");
#define OutputAndReturn0(x) {cout<<(x)<<endl;return 0;}
#define elif else if

#define issame(a,b,c,d) ((a)==(b) and (b)==(c) and (c)==(d))
#define isdiff3(a,b,c) ((a)!=(b) and (b)!=(c) and (c)!=(a))
#define isdiff4(a,b,c,d) ((a)!=(b) and (b)!=(c) and (c)!=(a) and (d)!=(a) and (d)!=(b) and (d)!=(c))
#define isdiff5(a,b,c,d,e) ((a)!=(b) and (b)!=(c) and (c)!=(a) and (d)!=(a) and (d)!=(b) and (d)!=(c) and (e)!=(a) and (e)!=(b) and (e)!=(c) and (e)!=(d))
#define Func3(f,a,b,c) (f)((f)((a),(b)),(c))
#define Func4(f,a,b,c,d) (f)((f)((f)((a),(b)),(c)),(d))

inline int isEven(int x){return x%2==0;}
inline int isOdd (int x){return x%2==1;}
inline ll samepair(ll x){return x*(x-1)/2;}
inline ll  gcd(ll a,ll b){ if(b==0)return a;else return gcd(b,a%b);}//最大公約数 なお一方が0なら答えは他方になるので番兵は０で良い また、負の数もOK -4%3=-1となるため
inline ll  lcm(ll a,ll b){return a*b/gcd(a,b);}//MODやオーバーフローには注意！
//inline ll  ceil(double a){return (ll)a+1;}
//ans = accumulate(A, A+N, 0, [](int a, int b) {return gcd(a,b);});
//auto count = std::count_if(v.begin(), v.end(), [](int x) { return x == 1 || x == 3; } );

ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

//累積和　しゃくとり法　木構造　DP キュー　乱択アルゴリズム　嘘解法　ハッシュ　next_permulation

//課題：DP 木構造　Xor

ll probNow(){
    double ans;ans=0;
    double N;
    cin>>N;
    
    
    printf("%15.15lf",(pow((N/3),3))  );
    return 0;
}

signed main(){
    cin.tie(0);    //cinとcoutの結び付き解除（cout時にcinの内容を吐き出さなくなる）
    ios::sync_with_stdio(false);  //coutとprintfの結び付き解除（coutとprintfを同時に使うな！）
    probNow();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

int main(){
  int n, m, l;
  std::cin >> n >> m >> l;
  int A[100][100], B[100][100];
  long long C[100][100];

  /*imput A*/
  for(int i=0; i<n; i++){
    for(int j=0; j<m; j++){
      std::cin >> A[i][j];
    }
  }
  /*imput B*/
  for(int j=0; j<m; j++){
    for(int k=0; k<l; k++){
      std::cin >> B[j][k];
    }
  }
  /*imput C*/
  for(int i=0; i<n; i++){
    for(int k=0; k<l; k++){
      C[i][k]=0;
      for(int j=0; j<m; j++){
        C[i][k] += A[i][j] * B[j][k];
      }
    }
  }
  /*output*/
  for(int i=0; i<n; i++){
    for(int k=0; k<l; k++){
      if(k<l-1){
        std::cout << C[i][k] <<" ";
      }else{
        std::cout << C[i][k];
      }
    }
    std::cout << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int dg[N], par[N];
vector<int> gr[N];
bool mark[N];
set<pair<int, int> > s;
void dfs(int v, int pr, int h) {
	par[v] = pr;
	s.insert({-h, v});
	for (auto u : gr[v]) 
		if (u != pr)
			dfs(u, v, h + 1);
	return;
}
int main() {
	int n;
	cin >> n;
	if (n % 2 == 1) {
		cout << "First";
		return 0;
	}
	for (int i = 0; i < n - 1; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		dg[x]++, dg[y]++;
		gr[x].push_back(y);
		gr[y].push_back(x);
	}
	dfs(0, 0, 1);
	int z = 0;
	while (!s.empty()) {
		auto p = *s.begin();
		s.erase(s.begin());
		int v = p.second, pr = par[v];
//		cout << "v = " << v << " h = " << h << " pr = " << pr << endl;
		if (mark[v])
			continue;
		if (dg[pr] > 2 || dg[pr] == 2 && dg[par[pr]] == 1 || dg[pr] == 2 && pr == 0) {
			z = 1;
			break;
		}
		dg[par[pr]]--, mark[pr] = 1;
	}
	if (z)
		cout << "First";
	else
		cout << "Second";
	return 0;
}


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

int main(){
  int n, q;
  string s;
  cin >> n >> q >> s;
  int c[n+1];
  for ( int i = 2; i <= n; i++){
    if ( s[i-2] == 'A' && s[i-1] == 'C'){
      c[i] = c[i - 1] + 1;
    } else {
      c[i] = c[i - 1];
    }
  }

  int l, r;
  for ( int i = 0; i < q; i++){
    cin >> l >> r;
    cout << c[r] - c[l] << endl;
  }


  return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<long long> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
 
	vector<long long> s(n + 1, 0);
	map<long long, long long> nums;
	for (int i = 0; i < n; i++) s[i + 1] = s[i] + a[i];
	for (int i = 0; i < n + 1; i++) nums[s[i]]++;

	long long ans = 0;
	for (auto it : nums) {
		long long num = it.second;
		//nC2通り
		ans += num * (num - 1) / 2;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  ll x;
  cin >> x;
  ll m = 100;
  ll cnt = 0;
  while(1){
    m = floor(m*1.01);
    cnt++;
    if (m >= x) {
      break;
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5e2+2;
const int mod=998244353;
char dime[N][N];
int ans=1,pw2[N*N],deg[N],cnt,cnt_deg,cnt_ver;
bool used[N];
vector<int> adj[N];
int mul(int x,int y){
	return (1ll*x*y)%mod;
}
void upd(char &c,char x){
	if(c=='?'){
		c=x;
	}
	else{
		if(x!='?'&&x!=c){
			ans=0;
		}
	}
}
void dfs(int x){
	cnt+=adj[x].size();
	cnt_deg+=deg[x];
	cnt_ver++;
	used[x]=true;
	for(int i:adj[x]){
		if(!used[i]){
			dfs(i);
		}
	}
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,x;
	cin>>n;
	pw2[0]=1;
	for(i=1;i<=n*n;i++){
		pw2[i]=mul(pw2[i-1],2);
	}
	for(i=1;i<n;i++){
		for(j=1;j<n;j++){
			cin>>dime[i][j];
			k=i,l=j;
			if(k>l){
				swap(k,l);
			}
			if(k+l>n){
				x=l; l=n-k; k=n-x;
			}
			upd(dime[k][l],dime[i][j]);
		}
	}
	for(i=1;i<n;i++){
		for(j=1;j<n;j++){
			if(i>j||i+j>n){
				continue;
			}	
			k=j-i; l=i+j;
			if(dime[i][j]=='o'){
				deg[k]++; deg[l]++;
			}
			if(dime[i][j]=='?'){
				adj[k].push_back(l);
				adj[l].push_back(k);
			}
		}
	}
	for(i=0;i<=n;i+=2){
		if(!used[i]){
			cnt=cnt_deg=cnt_ver=0;
			dfs(i);
			if((n/2+1)%2==1){
				if(cnt_deg&1){
					ans=0;
				}
				ans=mul(ans,pw2[cnt/2-cnt_ver+1]);
			}
			else{
				ans=mul(ans,pw2[cnt/2]);	
			}
		}
	}
	for(i=1;i<=n;i+=2){
		if(!used[i]){
			cnt=cnt_deg=cnt_ver=0;
			dfs(i);
			if((n-n/2)%2==1){
				if(cnt_deg&1){
					ans=0;
				}
				ans=mul(ans,pw2[cnt/2-cnt_ver+1]);
			}
			else{
				ans=mul(ans,pw2[cnt/2]);	
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 17792
l, r = map(int, input().split())

if r - l >= 2019:
    pass
    print(0)
    exit()
ans = 2020
for i in range(l, r):
    for j in range(l+1, r+1):
        if ans > i * j % 2019:
            ans = i * j % 2019
print(ans)


Measured memory_bytes: 2940
S = input()
k = "keyence"

if S == k:
    print("YES")
else:
    ans = "NO"
    s = S
    for i in range(8):
        S = list(s)
        del S[i:i+(len(S)-7)]
        if "".join(S) in k:
            ans = "YES"
            break
    
    print(ans)

Measured memory_bytes: 9028
#include<bits/stdc++.h>
using namespace std;
int main(){
	double a,b,c,d,e,f,x,y;
	while(cin>>a>>b>>c>>d>>e>>f){
        x = (double)((e*c-b*f) / (a*e-b*d));
		y = (double)((-(d*c)+a*f) / (a*e-b*d));
		if(x==0)	x=0;
		if(y==0)	y=0;
    	cout<<setiosflags(ios::fixed)<<setprecision(3)<<x<<" "<<y<<endl;
    }
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  int odd_p[] = {105, 135, 165, 189, 195};
  
  int res = 0;
  
  for(int i = 1; i <= n; i+=2){
    for(int j = 0; j <= 4; ++j){
   		if(i == odd_p[j]){
          ++res;
          break;
        }
    }
  }
  
  cout << res << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
const int N=1e5+100;
const int mod=998244353;
typedef long long ll;

ll f[N],sum[N],p[N<<2],add[N<<2],a[N];


int main()
{
    int n;scanf("%d",&n);
     n%=10;
     if(n==3) cout<<"bon"<<endl;
     else if(n==0||n==1||n==6||n==8) cout<<"pon"<<endl;
     else cout<<"hon"<<endl;
    return 0;
}


Measured memory_bytes: 3660
//最短経路を求め、それ以外の白を黒にしたらいい
#include<iostream>
#include<tuple>
#include<queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
int main() {
    int h, w; cin >> h >> w;
    char table[h][w];
    int cnt = 0;
    rep(i, h) {
        rep(j, w) {
            cin >> table[i][j];
            if (table[i][j] == '.') cnt++;
        }
    }
    int reached[50][50] = {0};
    using key = tuple<int, int, int>;
    queue<key> q; //y, x, cnt
    key s;
    q.push(key{0, 0, 0});
    while (!q.empty()) {
        s = q.front();
        int y = get<0>(s);
        int x = get<1>(s);
        int cost = get<2>(s);
        q.pop();
        int dy[] = {0, 0, -1, 1};
        int dx[] = {1, -1, 0, 0};
        rep(i, 4) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
            if (table[ny][nx] == '#' || reached[ny][nx]) continue;
            if (ny == h - 1 && nx == w - 1) {
                cout << cnt - 1 - (cost + 1) << endl;
                return 0;
            }
            /*
            rep(j, h) {
                rep(k, w) cout << reached[j][k] << " ";
                cout << endl;
            }
            cout << endl;
            */
            if (reached[ny][nx] == 0) {
                reached[ny][nx] = cost + 1;
                q.push(key{ny, nx, cost + 1});
            }
            
        }
    }
    cout << -1 << endl;
    return 0;
}



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

int main() {
	int s, ans = 1;
	bool flag = false;
	cin >> s;
	vector<int> a(s);
	a.push_back(s);
	while (flag == false){
		ans++;
		if (s % 2 == 0) s = s / 2;
		else s = s * 3 + 1;
		if (find(a.begin(), a.end(), s) != a.end()) flag = true;
		else a.push_back(s);
	}
	cout << ans << endl;
}

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

typedef long long ll;
typedef pair<ll,int> Pa;

ll N,P,Q;
Pa C[500005];
int main(){
  cin >> N >> P >> Q;
  ll sum = 0;
  for(int i=0;i<N;i++){
    ll c; cin >> c; sum+=c;
    C[i] = Pa( (ll)(Q-i)*P - c , i );
  }
  sort( C, C + N );
  ll res = sum;
  for(int i=N-1;i>-1;i--){
    ll p = N-1-i;
    res = max( res, sum + C[i].first + 2LL*p*P );
    sum = sum + C[i].first + 2LL * p * P;
  }
  cout << res << endl;
}

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

int main()
{


    int A,B;
    cin >> A >> B;

    for (int i = 0; i < 10000; i++){
        if(int(i*0.08)==A && int(i*0.10)==B){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n, i;
    string s;
    int a = 0;
    int w = 0;
    int t = 0;
    int r = 0;
    cin >> n;
    for (i = 1; i <= n; i++){
        cin >> s;
        if(s == "AC"){
            a++;
        }
        else if (s == "WA"){
            w++;
        }
        else if (s == "TLE"){
            t++;
        }
        else{
            r++;
        }
    }
    
        cout << "AC x " << a << endl;
        cout << "WA x " << w << endl;
        cout << "TLE x " << t << endl;
        cout << "RE x " << r << endl;
    
    
    return 0;
}

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

int main()
{
   int N,K;
   cin >> N >> K;
   long H[N],sum=0,D[N],sum2=0;
   for(int i=0;i<N;i++){
       cin >> H[i];
       sum += H[i];
   }
   int n = sizeof(H)/sizeof(H[0]);
   sort(H, H+n);
   if(K>=N){
       printf("0");
   }
   else if (K == 0){
       cout << sum;
   }
   else {
       for(int j=0;j<N-K;j++){
           sum2+=H[j];
       }
       cout << sum2;
   }
   return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


bool check(string s){
  for(int i=0;i<(int)s.size();i++){
    if(s[i] != 'z' - i) return 0;
  }
  return 1;
}
string get(string s){
  string res;
  for(int i=0;i<(int)s.size();i++){
    res += s[i];
    if(s[i] != 'z' - i) return res;
  }
  return res;
}


signed main(){
  string s;
  cin>>s;
  int n = s.size();
  if(s == "zyxwvutsrqponmlkjihgfedcba") {
    cout<<-1<<endl;
    return 0;
  }

  {
    set<char> used;
    for(int i=0;i<n;i++) used.insert(s[i]);
    for(int i='a';i<='z';i++){
      if(used.count(i)) continue;
      cout<<s + char(i)<<endl;
      return 0;
    }  
  }

  {
    set<char>used;
    for(int i=0;i<n;i++) used.insert(s[i]);
    for(int i=0;i<n;i++){
      used.erase(s[n-1-i]);
      if(s[n-i-2] < s[n-i-1]) {
        string ans = s.substr(0,n - i - 1);
        while(used.count(++ans.back()));
        cout<<ans<<endl;
        return 0;
      }
 
    }
  }
  
  assert(0);

  return 0;
}


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

const int64_t MOD = 1e9+7;

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

    map<char, int> mp;
    for(char c: S) mp[c]++;
    int64_t ans = 1;
    for(auto& p : mp){
        ans *= p.second + 1;
        ans %= MOD;
    }
    ans = (ans + MOD - 1) % MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while(true) {
			String input = sc.next();
			if(input.equals("0")) break;
			int sum = 0;
			for(int i=0; i<input.length(); i++) {
				sum += Integer.parseInt(input.split("")[i]);
			}
			System.out.println(sum);
		}

		sc.close();

	}

}



Measured memory_bytes: 67912
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int d[1000];
int main()
{
	ll a, b, x;
	cin >> a >> b >> x;
	if (a != 0)printf("%lld\n", b / x - (a - 1) / x);
	else printf("%lld\n", b / x + 1);
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
const int mod = 998244353;

int main() {
    string S;
    long long N;
    cin >> S;
    N = S.length();
    string ans(N, 'x');
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
ll ans = 0;
void dfs (string S, int i) {
    if (i >= S.length() - 1) {
        int begin = 0;
        for (int j = 1, len = S.length(); j < len; j++) {
            if (S[j] == '+' || j == len - 1) {
                ans += stol(S.substr(begin, j - begin + 1));
                begin = j;
            }
        }
    } else {
        dfs(S, i + 1);
        S.insert(S.begin() + i + 1, '+');
        dfs(S, i + 2);
    }
}
int main (void) {
    string S;

    cin >> S;

    if (S.length() == 1) {
        cout << S << endl;
        return 0;
    }
    
    dfs(S, 0);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN
 main() {
   ll l,r,ans = 2020;
   cin >> l >>r;
   if((r-l)+1>=2019)return cout << 0,0;
   for(ll j=l;j<=r;j++){
     for(ll i=l;i<j;i++)
       ans = min(ans,(i*j)%2019);
     
   }
   cout << ans<<endl;
 }
 


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1, n-1):
    if p[i-1] < p[i] and p[i] < p[i+1]:
        ans += 1
    elif p[i+1] < p[i] and p[i] < p[i-1]:
        ans += 1
print(ans)

Measured memory_bytes: 9176
#include <iostream>

using namespace std;

int main()
{
    int a,b;

    cin>>a>>b;

    if (a==1 && b==2 || a==2 && b==1)
        cout<<"3"<<endl;
    else if (a==1 && b==3 || a==3 && b==1)
        cout<<"2"<<endl;
    else
        cout<<"1"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,c,ans=0,count=0;
    cin >> n >> m >> c;
    vector<int> b(m);
    for(int i=0;i<m;i++){
        cin >>b.at(i);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            int a;
            cin >> a;
            ans += a*b.at(j);
        }
        if(ans+c>0)count++;
        ans=0;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

dp = [[10**18]*N for i in range(N)]

cA = [0]*(N+1)
for i in range(1,N+1) :
    cA[i] = cA[i-1] + A[i-1]

    dp[i-1][i-1] = 0

for d in range(1,N) :
    for i in range(N-d) :
        for cut in range(i, i+d) :
            dp[i][i+d] = min(dp[i][i+d], dp[i][cut] + dp[cut+1][i+d] + cA[i+d+1] - cA[i])

ans = dp[0][N-1]

print(ans)


Measured memory_bytes: 42988
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,g;
  cin >> a >> b;
  g=__gcd(a,b);
  cout << a*b/g << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
#define EPS (1e-15)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0


struct Segment;
class Point;
typedef Point Vector;
typedef Segment Line;

class Point {
public:
	double x, y;
	Point() {}
	Point(double xx, double yy) {
		x = xx;
		y = yy;
	}
	Point operator + (Point& p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point& p) { return Point(x - p.x, y - p.y); }
	Point operator * (double k) { return Point(x * k, y * k); }
	Point operator / (double k) { return Point(x / k, y / k); }

	double norm() { return x * x + y * y; }
	double abs() { return sqrt(norm()); }
	double dot(Point p) { return x * p.x + y * p.y; }
	double cross(Point& p) { return x * p.y - y * p.x; }
	double distance(Point& p) { return (*this - p).abs(); }

	bool operator == (const Point& p) const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}
};

struct Segment {
	Point p1, p2;
};

double distance(Point p,Line s) {
	Vector a = s.p2 - s.p1;
	Vector b = p - s.p1;
	return a.cross(b) / a.abs();
}

double distanceS(Point p,Segment s) {
	Vector p1p = p - s.p1;
	Vector p2p = p - s.p2;
	Vector p1p2 = s.p2 - s.p1;
	Vector p2p1 = s.p1 - s.p2;
	if (p1p.dot(p1p2) < 0) {
		return p1p.abs();
	}
	else if (p2p.dot(p2p1) < 0) {
		return p2p.abs();
	}
	else {
		return distance(p,s);
	}
}

Point project(Point p,Segment s) {
	Vector hepo = p - s.p1;
	Vector base = s.p2 - s.p1;
	Vector t = base * (hepo.dot(base) / base.norm());
	return s.p1 + t;
}

int ccw(Point p0, Point p1, Point p) {
	Vector p0p1 = p1 - p0;
	Vector p0p;
	p0p = p - p0;
	if (p0p1.cross(p0p) > EPS) {
		return COUNTER_CLOCKWISE;
	}
	else if (p0p1.cross(p0p) < -EPS) {
		return CLOCKWISE;
	}
	else if (p0p1.dot(p0p) < -EPS) {
		return ONLINE_BACK;
	}
	else if (p0p1.norm() < p0p.norm()) {
		return ONLINE_FRONT;
	}
	else {
		return ON_SEGMENT;
	}
}


int main() {
	Point p0, p1, p;
	cin >> p0.x >> p0.y >> p1.x >> p1.y;
	int q;
	cin >> q;
	while (q--) {
		cin >> p.x >> p.y;
		switch (ccw(p0, p1, p)) {
		case COUNTER_CLOCKWISE:
			cout << "COUNTER_CLOCKWISE" << endl;
			break;
		case CLOCKWISE:
			cout << "CLOCKWISE" << endl;
			break;
		case ONLINE_BACK:
			cout << "ONLINE_BACK" << endl;
			break;
		case ONLINE_FRONT:
			cout << "ONLINE_FRONT" << endl;
			break;
		case ON_SEGMENT:
			cout << "ON_SEGMENT" << endl;
			break;
		default:
			break;
		}
	}
}


Measured memory_bytes: 3200
#include<stdio.h>
void SelectionSort(int *,int);
#define N 100 
  
 main(){
   int i ,A[N] ,n;
   scanf("%d", &n);
   for(i = 0; i < n; i++) scanf("%d", &A[i]);
   SelectionSort(A, n);
 
  return 0;
}
 
 void SelectionSort(int *a, int b){
   int i,j,minj, koukan ,count=0;
   for(i=0; i < b; i++){
     minj = i;
     for(j=i; j < b ; j++) {
      if(a[j] < a[minj]){
     minj = j;
      }
    }
    
    if(i != minj) {
     count++;
    }
    koukan = a[i];
    a[i] = a[minj];
      a[minj] = koukan;
  }
   
  for(i=0; i < b - 1; i++){
  printf("%d ",a[i]);
  }
  printf("%d\n", a[b-1]);
  printf("%d\n", count);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)

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

	bool error = false;
	int cnt = 0;
	if (S.at(0) != 'A') error = true;
	int i = 1;
	while (!error && i < (int)(S.size())){
		if (!('a' <= S.at(i) && S.at(i) <= 'z')){
			if (S.at(i) == 'C' && 1 < i && i < (int)(S.size()) - 1) cnt++;
			else error = true;
		}
		i++;
		// cout << i << endl;
	}
	if (cnt != 1) error = true;
	if (error) cout << "WA" << endl;
	else cout << "AC" << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int a[3];
  for (int i=0; i<=2; i++)
    cin >> a[i];
  for (int i=0; i<=1; i++) {
    for (int j=1; j<=2-i; j++) {
      if (a[i] > a[i+j]) {
	swap(a[i], a[i+j]);
      }
    }
  }
  for (int i=0; i<=2; i++) {
    if (i != 2)
      cout << a[i] << " ";
    else
      cout << a[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3096
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}

void solve()
{
	int H;
	int n;
	cin >> H >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++)
		cin >> a[i] >> b[i];
	vector<int> dp(H + 1,INF);
	dp[0] = 0;
	for (int i = 0; i < n; i++)
		dp[a[i]] = b[i];

	for (int j = 1; j <= H; j++)
		for (int i = 0; i < n; i++)
			if (j >= a[i])
				dp[j] = min(dp[j], dp[j - a[i]] + b[i]);
			else
				dp[j] = min(dp[j], b[i]);
	cout << dp[H];

}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	int tst = 1;
	//cin >> tst;
	while (tst--)
		solve();

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <random>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  long long n;
  string s;
  cin >> n >> s;
  long long ans   = 1;
  long long c[26] = { };
  for (int i = 0; i < n; i++) {
	  c[s[i] - 'a']++;
	}
  for (int i = 0; i < 26; i++) {
	  ans *= (c[i] + 1);
	  ans %= mod;
	}
  cout << (ans - 1) % mod << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
bool isPrime(ll n) 
{ 
    
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
   
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
ll minthis(ll a, ll b){
if(a < b){
return a;
}
return b;
}
ll maxthis(ll a, ll b){
if(a > b){
return a;
}
return b;
}
int gcd(int a, int b){
    if( a<0 ) a = -a;
    if( b<0 ) b = -b;
    while( b!=0 ){
        a %= b;
        if( a==0 ) return b;
        b %= a;
    }
    return a;
}
 
int findLargestDivisor(int n) 
{ 
	int max = 1;
    for (int i = 2; i < n; i++) {        
        if(n %(i) == 0) { 
            max = i;
        } 
    }
    return max;     
} 
	 
 
ll power(ll x, ll y)  
{  
    ll temp;  
    if(y == 0)  
        return 1;  
    temp = power(x, y / 2);  
    if (y % 2 == 0)  
        return (temp * temp)%1000000007;  
    else
    {  
        if(y > 0)  
            return (x * temp * temp)%1000000007;  
        else
            return (temp * temp)%1000000007 / x;  
    }  
} 
bool sortbysec(const pair<int, int>& a, 
               const pair<int, int>& b) 
{ 
    return (a.second < b.second); 

} 


void solve(){
    int n;
    cin >> n;
    int arr[n];
    for(int i = 0 ; i < n ; i++){
        cin >> arr[i];
    }
    int ans = 0;
    for(int i = 0 ; i < n ; i++){
        for(int j = i+1 ; j < n ; j++){
            ans += arr[i]*arr[j];
        }
    }
    cout << ans << "\n";
}


int main(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
		solve();
	}
    return 0; 
}





Measured memory_bytes: 3564
str = gets.chomp
q = gets.to_i

for i in 1..q
  command = gets.split(" ")
  command[1] = command[1].to_i; command[2] = command[2].to_i

  str = str[0, command[1]] + command[3] + str[command[2] + 1, str.length - command[2]] if command[0] == "replace"
  str = str[0, command[1]] + str[command[1], command[2] - command[1] + 1].reverse + str[command[2] + 1, str.length - command[2]] if command[0] == "reverse"
  puts str[command[1], command[2] - command[1] + 1] if command[0] == "print"

end

Measured memory_bytes: 6252
#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()
{
    ll ans = 1;
    ll mx = 1e18;
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    rep(i, n)
    {
        if (a[i] == 0)
        {
            cout << '0' << endl;
            return 0;
        }
    }
    rep(i, n)
    {
        if (mx / ans < a[i])
        {
            cout << "-1" << endl;
            return 0;
        }
        ans *= a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4012
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

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

    vector<int> b(n + 2);
    for (int i = 1; i <= n; i++) {
        b[i] = b[i-1] + abs(a[i-1] - a[i]);
    }
    vector<int> c(n + 2);
    for (int i = n; i >= 1; i--) {
        c[i] = c[i+1] + abs(a[i+1] - a[i]);
    }

    for (int i = 1; i <= n; i++) {
        long sum = b[i-1] + abs(a[i-1] - a[i+1]) + c[i+1];
        cout << sum << endl;
    }

    return 0;
}

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

#define form2(i, a, b) for (int i = (a); i < (b); ++i)
#define ford2(i, a, b) for (int i = (a-1); i >= (b); --i)
#define form(i, n) form2(i, 0, n)
#define ford(i, n) ford2(i, n, 0)

#define chmax(x, v) x = max(x, (v))
#define chmin(x, v) x = min(x, (v))
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define vsz(v) (int)(v.size())

const long long BIG = 1000000000000000000LL;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

void solve();
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

const int maxLignes = 50*1000 + 5;
bitset<maxLignes> info[maxLignes];
bool canAc[maxLignes];
int repr[maxLignes];
int occ[maxLignes];
int nbLignes, nbEscaliers, mode;

void solve()
{
	cin >> nbLignes >> nbEscaliers >> mode;
	vector<pii> esc;
	form(i, nbEscaliers) {
		int x,y; cin >> x >> y;
		esc.emplace_back(x-1, y-1);
	}
	reverse(all(esc));

	if (mode == 1) {
		form(i, nbLignes) info[i][i] = true;
		for (auto e : esc) {
			info[e.fi] |= info[e.se];
			info[e.se] |= info[e.fi];
		}
		form(i, nbLignes-1) info[i+1] &= info[i];
		int choix = -1;
		form(i, nbLignes) if (info[nbLignes-1][i]) { choix = i; break; }
		if (choix == -1) { cout << "-1\n"; return; }
		canAc[choix] = true;
		string s;
		for (auto e : esc) {
			if (canAc[e.fi]) { s.push_back('^'); canAc[e.se] = true; }
			else { s.push_back('v'); canAc[e.fi] |= canAc[e.se]; }
		}
		reverse(all(s));
		cout << s << "\n";
	} else {
		if (nbLignes == 2) { cout << "-1\n"; return; }
		form(i, nbLignes) { repr[i] = i; occ[i] = 1; }
		string s;
		for (auto e : esc)
		{
			if (occ[repr[e.fi]] >= 2) {
				s.push_back('v');
				--occ[repr[e.fi]];
				++occ[repr[e.se]];
				repr[e.fi] = repr[e.se];
			} else {
				s.push_back('^');
				++occ[repr[e.fi]];
				--occ[repr[e.se]];
				repr[e.se] = repr[e.fi];
			}
		}
		reverse(all(s));
		cout << s << "\n";
	}
}


Measured memory_bytes: 306932
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <numeric>    // accumulate
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll N, cnt = 0, d, m, b, c;
  cin >> N;
  for (ll a = 1; a <= N; a++) {
    b = (N - 1) / a;
    // c = N % a;
    cnt += b;
  }
  // cnt = (N - 1) / a * ((1 + N) / 2) * N;
  cout << cnt << endl;
}


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

using namespace std;

#define ll long long
#define pb push_back
#define p_b pop_back
#define pf push_front
#define p_f pop_front
#define sc second
#define fr first
#define in freopen("input.txt" , "r", stdin)
#define out freopen("output.txt" , "w", stdout)
#define mod 1000000007
#define inf 1000000007
vector<int> v;
ll a[100005];
ll n;
int main ()
{
   // in;
    //out;
    ios_base::sync_with_stdio(0);

    ll k , x;
    cin >> x >> k;
    for (int i = k - x + 1; i < k + x; i++) cout << i << " ";
}


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

  ll N, K;
  cin >> N >> K;

  ll ans = 0;

  for (ll a = K; a <= N; a += K) {
    ll b = N / K;
    ans += (b - 1LL) * (b - 2LL);
    ans += (b - 1LL) * 3LL;
    ans += 1LL;
  }

  if (K % 2 == 0) {
    for (ll a = K / 2LL; a <= N; a += K) {
      ll b = (N - K / 2LL) / K + 1LL;
      ans += (b - 1LL) * (b - 2LL);
      ans += (b - 1LL) * 3LL;
      ans += 1LL;
    }
  }

  cout << ans << endl;

  /*
  FOR(i, 1, N + 1) FOR(j, 1, N + 1) FOR(k, 1, N + 1) {
    if ((i + j) % K == 0 and (j + k) % K == 0 and (k + i) % K == 0)
      cout << i << " " << j << " " << k << endl;
  }
  */

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
typedef unsigned long long ull;
typedef signed long long sll;
using namespace std;

#define INF 0x7FFFFFFFFFFFFFFF
#define BIG_PRIME 1000000007

int main()
{
  string s;
  ull i,j,N,sum;
  cin >> N >> s;
  vector<vector<ull>> dp(N);
  dp[0].resize(1,1);
  for(i=1;i<N;++i)
  {
    dp[i].resize(i+1,0);
    if(s[i-1]=='<')
    {
      for(j=1;j<=i;++j)
      {
        dp[i][j]=(dp[i][j-1]+dp[i-1][j-1])%BIG_PRIME;
      }
    }
    else
    {
      for(j=1;j<=i;++j)
      {
        dp[i][i-j]=(dp[i][i-j+1]+dp[i-1][i-j])%BIG_PRIME;
      }
    }
  }
  sum=0;
  for(j=0;j<N;++j)
  {
    sum = (sum + dp[N-1][j])%BIG_PRIME;
  }
  cout << sum;
  return 0;
}


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

int main()
{
    //データ定義
    int count[4][3][10]; /*入居者*/
    int occupierData;    /*入居者情報の数*/
    int i;
    int j;
    int k;
    int buildingNumber; /*棟番号*/
    int floorNumber; /*階*/
    int roomNumber; /*部屋番号*/
    int variationData; /*人数変動情報*/

    //入居者情報の初期化
    for(i = 0; i < 4; i++){
        for (j = 0; j < 3; j++){
            for (k = 0; k < 10; k++){
                count[i][j][k] = 0;
            }
        }
    }

    //データ読み込み
    //入居者情報の数を読み込む
    cin >> occupierData;
    //メイン処理
    for(i = 0; i < occupierData; i++){
        //棟情報を読み込む
        cin >> buildingNumber;
        //階情報を読み込む
        cin >> floorNumber;
        //部屋番号を読み込む
        cin >> roomNumber;
        //人数変動情報を読み込む
        cin >> variationData;

        //入居者情報を更新する
        count[buildingNumber - 1][floorNumber - 1][roomNumber - 1] += variationData;
    }

    //結果出力
    for (i = 0; i < 4; i++)
    {
        for (j = 0; j < 3; j++)
        {
            for (k = 0; k < 10; k++)
            {
                cout << " ";
                cout << count[i][j][k];

            }
            cout << endl;
        }
        if(i != 3){
            cout << "####################" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3124
S = input()
N = len(S)

A = [0 for i in range(N)]

c = 0
for i in range(N) :
    if S[i] == "R" :
        c += 1
    else :
        if c % 2 == 0 :
            A[i] += c//2
            A[i-1] += c//2
        else :
            A[i] += c//2
            A[i-1] += c//2 + 1
        c = 0

c = 0
for i in range(N-1,-1,-1) :
    if S[i] == "L" :
        c += 1
    else :
        if c % 2 == 0 :
            A[i] += c//2
            A[i+1] += c//2
        else :
            A[i] += c//2
            A[i+1] += c//2 + 1
        c = 0
print(*A)


Measured memory_bytes: 6520
#include<bits/stdc++.h>
#define prDouble(x) cout<<fixed<<setprecision(10)<<x
using namespace std;
int n;
double dp[301][301][301];

double solve(int x, int y, int z){
    if(x<0 || y<0 || z<0)
        return 0.0;
    if(x==0&&y==0&&z==0)
        return 0.0;
    if(dp[x][y][z] > -0.9)
        return dp[x][y][z];
    double exp = n + x*solve(x-1,y,z) + y*solve(x+1,y-1,z) + z*solve(x,y+1,z-1);

    return dp[x][y][z] = exp/(x+y+z);
}

int main(){
    cin>>n;
    int x,y,z;
    x = y = z = 0;
    memset(dp, -1, sizeof(dp));
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        if(t==1)
            x++;
        else if(t==2)
            y++;
        else
            z++;
    }
    //cout<<solve(x,y,z)<<endl;
    cout<<fixed<<setprecision(10)<<solve(x,y,z)<<endl;
    return 0;
}


Measured memory_bytes: 216864
(let ((x (read)))
  (format t "~A~%" (cond ((<= 400 x 599) 8)
                         ((<= 600 x 799) 7)
                         ((<= 800 x 999) 6)
                         ((<= 1000 x 1199) 5)
                         ((<= 1200 x 1399) 4)
                         ((<= 1400 x 1599) 3)
                         ((<= 1600 x 1799) 2)
                         (t 1))))


Measured memory_bytes: 24388