akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {

	static BufferedReader reader;
	final static boolean MODE_DEBUG = false;
	//static field here
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		//code here
		int[] NM = readLineInt();
		int N = NM[0];
		int M = NM[1];
		String S = readLine()[0];
		
		char[] c = S.toCharArray();
		c[M-1] += 32;
		
		
		print(new String(c));
		//String[] s = readLine();
		//print(num);
	}
	
	//functions here
	//note that all methods should be STATIC


	private static <T> int arraySearch(T needle, T[] heystack) {
		for(int i=0;i<heystack.length;i++) {
			if(needle.equals(heystack[i])) {
				return i;
			}
		}
		return -1;
	}
	private static int[] sort(int[] base) {
		int[] copy = array_copy(base);
		Arrays.sort(copy);
		return copy;
	}
	private static int[] array_copy(int[] base) {
		int[] copy = new int[base.length];
		for(int i=0;i<base.length;i++) {
			copy[i] = base[i];
		}
		return copy;
	}
	private static int[] asArray(ArrayList<Integer> ints) {
		int[] intlist = new int[ints.size()];
		for(int i=0;i<intlist.length;i++) {
			intlist[i] = ints.get(i);
		}
		return intlist;
	}
	private static String[] readLine(){
		try{
			return reader.readLine().split(" ");
		}catch(Exception e){
			e.printStackTrace();
			return new String[]{e.getMessage()};
		}
	}
	private static int[] readLineInt(){
		try{
			String[] s = readLine();
			int[] ints = new int[s.length];
			for(int i=0;i<ints.length;i++) {
				ints[i] = Integer.parseInt(s[i]);
			}
			return ints;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static byte[] readLineByte(){
		try{
			String[] s = readLine();
			byte[] bytes = new byte[s.length];
			for(int i=0;i<bytes.length;i++) {
				bytes[i] = Byte.parseByte(s[i]);
			}
			return bytes;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static char[] readLineChar(){
		try{
			String[] s = readLine();
			char[] chars = new char[s.length];
			for(int i=0;i<chars.length;i++) {
				chars[i] = (char)Integer.parseInt(s[i]);
			}
			return chars;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static void print(Object o){
		System.out.println(o);
	}
	private static void print(){
		System.out.println();
	}
	private static void printd(Object o){
		if(MODE_DEBUG)System.err.println(o);
	}
	private static void printd(){
		if(MODE_DEBUG)System.err.println();
	}
}


Measured memory_bytes: 21076
#include<stdio.h>
int main()
{
    int a,b,k,i;
    scanf("%d %d %d",&a,&b,&k);

    if((b-a+1)>=2*k)
    {
      for(i=0;i<k;i++)
      {
          printf("%d\n",a+i);
      }
      for(i=k-1;i>=0;i--)
        printf("%d\n",b-i);
    }
    else
    {
        for(i=0;i<(b-a+1);i++)
        {
            printf("%d\n",a+i);
        }
    }
return 0;

}


Measured memory_bytes: 128
object Main extends App {
    val lines = io.Source.fromInputStream(System.in).getLines()
    val n = lines.next().toInt
    val a: Array[Int] = lines.next().split(" ").map(_.toInt - 1)
    val cnt: Array[Int] = new Array(n)
    for(i <- 0 until n) { cnt(a(i)) += 1 }
    val total = cnt.map(x => choose2(x)).sum
    for(i <- 0 until n) {
        val c = cnt(a(i))
        println(total - (c - 1))
    }
    
    def choose2(n: Long): Long = n * (n - 1) / 2
}


Measured memory_bytes: 65180
#include <iostream>
#include <algorithm>
#include <string>
#include <cctype>
using namespace std;

typedef string::const_iterator iter;
int factor(iter &p);
int number(iter &p);

int exprA(iter &p) {
  // cerr << "exprA" << endl;
  int res = number(p);
  while(true) {
    if(*p == '+') {
      ++p;
      res += number(p);
    }
    else if(*p == '*') {
      ++p;
      res *= number(p);
    }
    else break;
  }
  return res;
}

int exprB(iter &p) {
  // cerr << "exprB" << endl;
  int res = factor(p);
  while(true) {
    if(*p == '+') {
      ++p;
      res += factor(p);
    }
    else break;
  }
  return res;
}

int factor(iter &p) {
  // cerr << "factor" << endl;
  int res = number(p);
  while(true) {
    if(*p == '*') {
      ++p;
      res *= number(p);
    }
    else break;
  }
  return res;
}

int number(iter &p) {
  // cerr << "number" << endl;
  int res = 0;
  while(isdigit(*p)) {
    res *= 10;
    res += *p - '0';
    ++p;
  }
  return res;
}

int main() {
  string S; cin >> S;
  int T; cin >> T;
  iter p;
  p = S.begin();
	bool l2 = exprA(p)==T;
  p = S.begin();
	bool l1 = exprB(p)==T;
	if (l1 && l2) cout << "U" << endl;
	if (l1 && !l2) cout << "M" << endl;
	if (l2 && !l1) cout << "L" << endl;
	if (!l2 && !l1) cout<< "I" << endl;
}

Measured memory_bytes: 1200
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstring>
using namespace std;
typedef long long int ll;
const int MAX=100;
const int MAX_cap=10000;

class edge
{
public:
	int to,cap,rev;
	edge(){}
	edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
};

vector<edge> G[MAX];
int level[MAX];//s->v distance
int iter[MAX];

void add_edge(int from,int to,int cap)
{
	G[from].push_back(edge(to,cap,G[to].size()));
	G[to].push_back(edge(from,0,G[from].size()-1));
	return;
}

void bfs(int s)
{
	memset(level,-1,sizeof(level));
	queue<int> Q;
	level[s]=0;
	Q.push(s);
	
	while(!Q.empty())
	{
		int v=Q.front();Q.pop();
		for(int i=0;i<G[v].size();i++)
		{
			edge e=G[v][i];
			if(e.cap>0&&level[e.to]<0)
			{
				level[e.to]=level[v]+1;
				Q.push(e.to);
			}
		}
	}
	return;
}

int dfs(int v,int t,int f)
{
	if(v==t)return f;
	for(int i=iter[v];i<G[v].size();i++)
	{
		edge &e=G[v][i];
		if(e.cap>0&&level[v]<level[e.to])
		{
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0)
			{
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

int maxflow(int s,int t)
{
	int flow=0;
	while(1)
	{
		bfs(s);
		if(level[t]<0)return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while((f=dfs(s,t,MAX_cap))>0)flow+=f;
	}
}
int main()
{
	int V,E;cin>>V>>E;
	int u,v,c;
	for(int i=0;i<E;i++)
	{
		cin>>u>>v>>c;
		add_edge(u,v,c);
	}
	cout<<maxflow(0,V-1)<<endl;
	return 0;
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 302, M = 1e9 + 7	;
int main() {
	int n;
	cin >> n;
	int fe = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x & 1)fe = 1;
	}
	if (fe)puts("first");
	else puts("second");
}

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

using namespace std;

int main(void) {
	int num, t, ans = 0, i = 1, a, b;
	cin >> num >> t >> b;
	for (; i < num; i++) {
		scanf("%d", &a);
		ans += min(t, a - b);
		b = a;
	}
	cout << ans + t << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

// ^= -> ビットごとの排他的論理和を計算する



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c, k; cin >> a >> b >> c >> k;
	if (k % 2 == 0) {
		cout << a - b << endl;
	}
	else {
		cout << b - a << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
unordered_map<int,bool> mp;
int n,a[14],ans[52],c;

int cal(){
  int res=0;
  for(int i=1;i<=13;i++)res=res*5+a[i];
  return res;
}

bool dfs(int s,int d){
  if(!d)return 1;
  int y=cal();
  if(mp.count(y))return mp[y];
  for(int i=13;i>0;i--){
    if(a[i]&&(s-i)%i==0){
      ans[d-1]=i;
      a[i]--;
      if(dfs(s-i,d-1))return mp[y]=1;
      a[i]++;
    }
  }
  return 0;
}

int main(){
  while(cin>>n,n){
    memset(a,0,sizeof(a));
    mp.clear();
    c=0;
    for(int i=0,b;i<n;i++)scanf("%d",&b),a[b]++,c+=b;
    if(dfs(c,n)){
      for(int i=0;i<n;i++){
	if(i)printf(" ");
	printf("%d",ans[i]);
      }
    }else printf("No");
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 3136
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#define LL long long
#define inl inline
#define re register
#define MAXN 10100
using namespace std;
int n,k;
int v[54];
int ans;int g[55];
int work(int l,int r)
{
	int cnt=k;
	if(l+r>k)return 0;
	int ind=0;
	for(int i=1;i<=l;i++)g[++ind]=v[i];
	for(int i=n;i>=n-r+1;i--)g[++ind]=v[i];
	sort(g+1,g+ind+1);
	cnt-=ind;
	int t=1;
	for(int i=1;i<=ind;i++)
	{
		if(g[i]<0&&cnt>0)
			cnt--,t++;
	}
	int tmp=0;
	for(;t<=ind;t++)tmp+=g[t];
	return tmp;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",&v[i]);
	for(int l=0;l<=n;l++)
		for(int r=0;r<=n-l;r++)
		{
			ans=max(ans,work(l,r));
		}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 256
//Dlove's template
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

#define R register
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define sqr(_x) ((_x) * (_x))
#define Cmax(_a, _b) ((_a) < (_b) ? (_a) = (_b), 1 : 0)
#define Cmin(_a, _b) ((_a) > (_b) ? (_a) = (_b), 1 : 0)
#define Max(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define Min(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define Abs(_x) (_x < 0 ? (-(_x)) : (_x))

using namespace std;

namespace Dntcry
{
	inline int read()
	{
		R int a = 0, b = 1; R char c = getchar();
		for(; c < '0' || c > '9'; c = getchar()) (c == '-') ? b = -1 : 0;
		for(; c >= '0' && c <= '9'; c = getchar()) a = (a << 1) + (a << 3) + c - '0';
		return a * b;
	}
	inline ll lread()
	{
		R ll a = 0, b = 1; R char c = getchar();
		for(; c < '0' || c > '9'; c = getchar()) (c == '-') ? b = -1 : 0;
		for(; c >= '0' && c <= '9'; c = getchar()) a = (a << 1) + (a << 3) + c - '0';
		return a * b;
	}
	const int Maxn = 110, Mod = 1000000007;
	int n, m, K, f[Maxn][Maxn], g[Maxn];
	int Pow(R int a, R int b)
	{	
		R int res = 1;
		for(; b; b >>= 1, a = 1ll * a * a % Mod) if(b & 1) res = 1ll * res * a % Mod;
		return res;
	}
	int Main()
	{
		m = read(), n = read(), K = read();
		g[0] = g[1] = 1, g[2] = 2;
		for(R int i = 3; i <= m; i++) g[i] = (g[i - 1] + g[i - 2]) % Mod;
		f[1][1] = 1;
		for(R int i = 1; i <= m; i++) f[0][i] = 1;
		for(R int j = 2; j <= m + 1; j++)
			for(R int i = 1; i <= n; i++)
			{
				f[i][j] = (f[i][j] + 1ll * f[i][j - 1] * g[i - 1] % Mod * g[n - i] % Mod) % Mod;
				if(i > 1) f[i][j] = (f[i][j] + 1ll * f[i - 1][j - 1] * g[Max(0, i - 2)] % Mod * g[n - i] % Mod) % Mod;
				if(i < n) f[i][j] = (f[i][j] + 1ll * f[i + 1][j - 1] * g[i - 1] % Mod * g[Max(0, n - i - 1)] % Mod) % Mod;
			}
		printf("%d\n", f[K][m + 1]);
		return 0;
	}
}
int main()
{
	return Dntcry :: Main();
}


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

#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define bg begin()
#define ed end()
#define pii pair<int,int>

int main(){
	int n , m;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//int r,d,x;
	while(cin >> n >> m){
		vector<ll>v;
		vector<pii>op;
		ll sum = 0;
		f(n){
			int add;
			cin >> add;
			sum += add;
			v.pb(add);
		}
		sort(v.begin(),v.end());
		f(m){
			ll add1,add2;
			cin >> add2 >> add1;
			op.pb({add1,add2});
		}
		sort(op.bg,op.ed);
		reverse(op.bg,op.ed);
		vector<ll>adj;
		f(m){
			if(adj.size()>n)break;
			while(op[i].second--){
				adj.pb(op[i].first);
			}
		}
		f(min(n,(int)adj.size())){
			if(adj[i]>v[i]){
				sum += adj[i] - v[i];
			}
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 3956
import math
from collections import deque
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

n = readInt()
a = readInts()
a.sort(reverse=True)
if len(a)%2:
	a.append(0)
alice = 0
bob = 0
for i in range(0,len(a),2):
	alice+=a[i]
	bob+=a[i+1]
print(alice-bob)

Measured memory_bytes: 3444
import itertools
import heapq
from bisect import bisect_left


def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]

N = int(input())
L = list(map(int, input().split()))
L.sort()
# L_sort = heapsort(L)
# print (L)
answer = 0
for i, a in enumerate(L[0:N-2]):
    for j, b in enumerate(L[i+1:N-1]):
        index = bisect_left(L, a+b)
        answer += max(index - (j+i+1) -1, 0)
        # print(L, a+b, index, j+i+1, answer)
print(answer)

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

int main(){
  int N;
  cin >> N;
  int A[60], B[60], C[60];
  int ans=0;
  for(int i=0; i<N; i++){
    cin >> A[i];}
   for(int i=0; i<N; i++){
     cin >> B[i];
   ans += B[i];}
  for(int i=0; i<N; i++){
     cin >> C[i];}
  for(int i=0; i<N-1; i++){
    if(A[i+1]==A[i]+1){
      ans += C[A[i]-1];
      }
 }
  cout <<ans << endl;
 
    
    
}

Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll x,k,d; cin >> x >> k >> d;
    x = abs(x);
    ll r = x / d;
    if(r > k){
        cout << x - d * k << "\n";
        return 0;
    }
    k -= r;
    x %= d;
    if(k & 1){
        cout << abs(x - d) << "\n";
    }
    else{
        cout << x << "\n";
    }
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll N = S.length();
    REP(i, N - 1) {
        if (S[i] == 'A' && S[i + 1] == 'C') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  vector<int> data(N);
  rep(i,N) {
    cin >> data.at(i);
  }
  ll low = (ll)data.at(0);
  for(int i = 1; i < N; i++){
    if(low < (ll)data.at(i)){
	    if(low > (ll)(data.at(i) - 1)){
    	 	cout << "No" << endl;
			return 0;
	    }else if(low == data.at(i) - 1){
    	  //nothing.do
	    }else{
    	  low = (ll)data.at(i)-1;
    	}
  	}else if(low == data.at(i)){
      //nothing.do
    }else{
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const int N = 3005;
int n,t, max_value;
int a[N], b[N];
ll dp[N][N]; // i時間以下で食べ終わるときの最大値

int main () {
  ios::sync_with_stdio(false);
  cin >> n >> t;
  P p[N];
  // rep(i,N) rep(j,N) dp[i][j] = -1;
  rep(i,n) {
    cin >> a[i] >> b[i];
    max_value = max(b[i], max_value);
    p[i] = P(a[i], b[i]);
  }
  rep(i,n+1) {
    dp[0][i] = 0;
  }
  SORT(p, n);
  // rep(i,n) cout << p[i].first << endl;
  rep(i, n) {
    rep(j, t+1) {
      if(p[i].first > j) {
        dp[i+1][j] = dp[i][j];
      } else {
        dp[i+1][j] = max(dp[i][j-p[i].first] + p[i].second, dp[i][j]);
      }
    }
  }
  ll ans = 0;
  rep(i,n) ans = max(ans, dp[i][t-1] + p[i].second);
  cout << ans << endl;
}


Measured memory_bytes: 70784
#ifdef __unix__
#include <bits/stdc++.h>
#else
#include <iostream>
#include <algorithm>
#include <math.h>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#include <bitset>
#endif

#define fastIO ios_base::sync_with_stdio(0), cin.tie(NULL)
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
#define mkp make_pair
/*#define NUMTOSTR(x)  (unsigned char)((x) + 48);*/
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long  ull;
using namespace std;

bool isok(int n) {
	unordered_multiset<char> ums;
	for (auto& i : to_string(n)) ums.insert(i);
	if (ums.count(n % 10 + '0') == ums.size()) return true;
	return false;
}

int main(){
	fastIO;
	int n;
	cin >> n;
	while (true)
	{
		if (isok(n)) {
			cout << n;
			return 0;
		}
		n++;
	}
	return 0;
}



Measured memory_bytes: 3704
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define all(v) (v).begin(),(v).end()
#define clr(a,b) memset((a),(b),sizeof(a))
#define sz size()
#define pb push_back
#define print(x) cout << x << endl
int n,m;
int a,b,c;
int ans;
string s,t;
vector<int> vec;

int main(){
  cin >> s;
  if(s[0] == '9' || s[1] == '9')print("Yes");
  else print("No");
  return 0;
}


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

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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cerr << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define debug(...) CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) (__VA_ARGS__)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  int ans = h[0];
  rep(i, n-1) {
    if (h[i+1] > h[i]) ans += h[i+1] - h[i];
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define endl        '\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x)  for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)    (a>b?a:b)
#define min(a,b)    (a<b?a:b)

/*  For Debugging   */
#define DEBUG       cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  100005

void solve()
{
    ll a,b,n;
    cin>>a>>b>>n;
    if(n<b){
        cout<<(n*a)/b<<endl;
    }
    else{
        cout<<((b-1)*a)/b<<endl;
    }
    return;
}
int main()
{
    FAST
    int TESTS=1;
//  cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    TIME
    return 0;
}

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

a = [6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]

memo = [0 for i in range(N + 1)]

for i in range(N + 1):
    if i < a[0]:
        memo[i] = i
    elif i < a[1]:
        memo[i] = min(memo[i - 1], memo[i - a[0]]) + 1
    elif i < a[2]:
        memo[i] = min(memo[i - 1], memo[i - a[0]], memo[i - a[1]]) + 1
    elif i < a[3]:
        memo[i] = min(memo[i - 1], memo[i - a[0]], memo[i - a[1]],
                      memo[i - a[2]]) + 1
    elif i < a[4]:
        memo[i] = min(memo[i - 1], memo[i - a[0]], memo[i - a[1]],
                      memo[i - a[2]], memo[i - a[3]]) + 1
    elif i < a[5]:
        memo[i] = min(memo[i - 1], memo[i - a[0]], memo[i - a[1]],
                      memo[i - a[2]], memo[i - a[3]], memo[i - a[4]]) + 1
    elif i < a[6]:
        memo[i] = min(memo[i - 1], memo[i - a[0]], memo[i - a[1]],
                      memo[i - a[2]], memo[i - a[3]], memo[i - a[4]],
                      memo[i - a[5]]) + 1
    elif i < a[7]:
        memo[i] = min(memo[i - 1], memo[i - a[0]], memo[i - a[1]],
                      memo[i - a[2]], memo[i - a[3]], memo[i - a[4]],
                      memo[i - a[5]], memo[i - a[6]]) + 1
    elif i < a[8]:
        memo[i] = min(memo[i - 1], memo[i - a[0]], memo[i - a[1]],
                      memo[i - a[2]], memo[i - a[3]], memo[i - a[4]],
                      memo[i - a[5]], memo[i - a[6]], memo[i - a[7]]) + 1
    elif i < a[9]:
        memo[i] = min(memo[i - 1], memo[i - a[0]], memo[i - a[1]],
                      memo[i - a[2]], memo[i - a[3]], memo[i - a[4]],
                      memo[i - a[5]], memo[i - a[6]], memo[i - a[7]],
                      memo[i - a[8]]) + 1
    elif i < a[10]:
        memo[i] = min(memo[i - 1], memo[i - a[0]], memo[i - a[1]],
                      memo[i - a[2]], memo[i - a[3]], memo[i - a[4]],
                      memo[i - a[5]], memo[i - a[6]], memo[i - a[7]],
                      memo[i - a[8]], memo[i - a[9]]) + 1
    else:
        memo[i] = min(memo[i - 1], memo[i - a[0]], memo[i - a[1]],
                      memo[i - a[2]], memo[i - a[3]], memo[i - a[4]],
                      memo[i - a[5]], memo[i - a[6]], memo[i - a[7]],
                      memo[i - a[8]], memo[i - a[9]], memo[i - a[10]]) + 1

print(memo[N])


Measured memory_bytes: 4100
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
const ll inf = 1e10 + 2 ;
const int nmax = 1e5 + 1 ;
void solve(){
    int n ;
    cin >> n ;
    for( int i = 1 ; i <=n ; i++){
        if(n%i==0){
            int x = n/i ;
            if(i<=9 && x <=9){
                cout <<"Yes";
                return ;
            }
        }
    }
    cout << "No";

}
int main(){
//      #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
    int t = 1  ;
    //cin >> t ;
    while(t--)
        solve();
}
// logc (ai*aj) = k logc (x)
// logc ( ai*aj - x ) =  k  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> pos(n + 1);
    rep(i, n) pos[a[i]] = i + 1;
    multiset<int> s = {0, 0, n + 1, n + 1}, t = {0, 0, n + 1, n + 1};
    int ans = 0;
    for (int p = n; p > 0; p--)
    {
        auto x = s.lower_bound(pos[p]);
        auto y = t.lower_bound(pos[p]);
        x--;
        auto w = x, z = y;
        w--, z++;
        int q = (*x - *w) * (*y - pos[p]) + (pos[p] - *x) * (*z - *y);
        // cout << *w << " " << *x << endl;
        // cout << *y << " " << *z << endl;
        // cout << q << endl;
        ans += p * q;
        s.insert(pos[p]);
        t.insert(pos[p]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

bool vis[10];
int n,m;
vector<vi> g;
int dfs(int u) {
    bool fin=true;
    REP(i,n) {
        if(!vis[i]) {
            fin=false;
            break;
        }
    }
    if(fin) {
        return 1;
    }
    int ret=0;
    FORE(v,g[u]) {
        if(vis[v]) continue;
        vis[v]=true;
        ret+=dfs(v);
        vis[v]=false;
    }
    return ret;
}
signed main() {
    cin>>n>>m;
    g=vector<vi>(n);
    REP(i,m) {
        int a,b;
        cin>>a>>b;
        g[a-1].push_back(b-1);
        g[b-1].push_back(a-1);
    }
    vis[0]=true;
    cout<<dfs(0)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>

typedef struct{
  int w;
  long long v;
}pair;

int main(){
  int N,W;
  long long DP[101][100001];
  pair data[100001];
  std::cin >> N >> W;
  for(int i=1 ;i<=N;i++){
    std::cin >> data[i].w >> data[i].v;
  }
  for(int i=0;i<=W;i++)
    DP[0][i]=0;

  for(int i=1;i<=N;i++){
    for(int j=1;j<=W;j++){
      if(j-data[i].w>=0 && DP[i-1][j]<DP[i-1][j-data[i].w] + data[i].v)
        DP[i][j]=DP[i-1][j-data[i].w] + data[i].v;
      else
        DP[i][j]=DP[i-1][j];
    }
  }

  std::cout<<DP[N][W];

  return 0;
}


Measured memory_bytes: 80640
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val S = readLine()!!


    val w = IntArray(N + 1) // [0, i) までのw数
    w[0] = 0
    val e = IntArray(N + 1) // [i, N) までのw数
    e[N] = 0
    for (i in 0 until N) {
        if (S[i] == 'W') {
            w[i + 1] = w[i] + 1
        } else {
            w[i+1] = w[i]
        }
    }
    for (i in N - 1 downTo 0) {
        if (S[i] == 'E') {
            e[i] = e[i + 1] + 1
        } else {
            e[i] = e[i + 1]
        }
    }


    var answer = Int.MAX_VALUE
    for (leader in 0 until N) {
        val num = w[(leader + 1) - 1] + e[leader + 1]
        answer = Math.min(answer, num)
    }
    println(answer)
}


Measured memory_bytes: 39424
k=int(input())
 
from collections import deque
q = deque(range(1, 10))

for i in range(k-1):
    d = q.popleft()
    if d % 10 != 0:
        q.append(10 * d + d % 10 - 1)
    q.append(10 * d + d % 10)
    if d % 10 != 9:
        q.append(10 * d + d % 10 +1)
    
print(q.popleft())



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

int main() {
	int A, B, C, D;
	int ans = 0;
	cin >> A >> B >> C >> D;

	if (A < B)ans += A;
	else ans += B;
	if (C < D) ans += C;
	else ans += D;

	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int f[10050];
int main()
{
    int n,x;
    cin >> n >> x;
    for(int i=0;i<n;i++)
        cin >> f[i];
    int s=0,cnt=1;
    for(int i=0;i<n;i++){
        s+=f[i];
        if(s>x)
            break;
        cnt++;
    }
    cout  << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int x[MAX],y[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,mx=0,z=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
        if(x[i]==y[i])
            z++;
        else
            z=0;
       mx=max(mx,z);
    }
    if(mx>=3)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 3696
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

template <class T>
void VecRowShow(vector<T> vec) {
	rep(i, vec.size()) {
		if (i != vec.size() - 1) cout << vec[i] << " ";
		else cout << vec[i] << endl;
	}
}

//素数判定配列を入手
vector<bool> GetPrimes(int n) {
	vector<bool> ans(n + 1, true);
	ans[0] = false, ans[1] = false;
	int maxDiv = sqrt(n) + 1;
	FOR(i, 2, maxDiv + 1) {
		if (ans[i]) {
			FOR(t, i + 1, n + 1) {
				if (t % i == 0) {
					ans[t] = false;
				}
			}
		}
	}
	return ans;
}

int main() {
	int n;
	cin >> n;
	auto a = GetPrimes(100000 * 10);
	FOR(i, n, 100000 * 10) {
		if (a[i]) {
			cout << i << endl;
			return 0;
		}
	}

}



Measured memory_bytes: 384
n = int(input())
s = input()
w_cnt = [0] * (n+1)
e_cnt = [0] * (n+1)
w_cnt[0], e_cnt[0] = 0, 0
for i in range(1, n+1):
    if s[i-1] == 'W':
        w_cnt[i] = w_cnt[i-1] + 1
        e_cnt[i] = e_cnt[i-1]
    else:
        w_cnt[i] = w_cnt[i-1]
        e_cnt[i] = e_cnt[i-1] + 1
#print(w_cnt)
#print(e_cnt)
ans = n
for i in range(1, n+1):
    ans = min(ans, w_cnt[i-1] + (e_cnt[n] - e_cnt[i]))
print(ans)

Measured memory_bytes: 45680
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <map>

#define ll long long

using namespace std;

void
solve() {
  ll n, w;
  cin>>n>>w;

  vector<ll> dp(100005, -1);
  dp[0] = 0;

  ll x, v;
  for (ll i=0; i<n; i++) {
    cin>>x>>v;

    for (ll j=w; j>=0; j--) 
      if (dp[j] >= 0 && j + x <= w && (dp[j+x] == -1 || dp[j+x] < dp[j] + v)) 
        dp[j+x] = dp[j] + v;
  }

  ll ans = 0;
  for (ll i=0; i<=w; i++) 
    if (dp[i] >= 0)
      ans = max(ans, dp[i]);
  cout<<ans<<endl;
}

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

  ll t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 3960
def main():
	n, m = map(int, input().split())
	bridge = [[0, 0]]*m
	for i in range(m):
		bridge[i] = list(map(int, input().split()))
	inconveniences = [0]*(m+1)
	inconveniences[m] = (n*(n-1))//2
	union_find = [[i, 0, 1] for i in range(n+1)]

	for i in range(m-1, -1, -1):
		if inconveniences[i+1] == 0:
			break
		if same(union_find, bridge[i][0], bridge[i][1]):
			inconveniences[i] = inconveniences[i+1]
			continue
		rx = root(union_find, bridge[i][0])
		ry = root(union_find, bridge[i][1])
		inconveniences[i] = inconveniences[i+1] - union_find[rx][2]*union_find[ry][2]
		unite(union_find, bridge[i][0], bridge[i][1])

	for i in range(1, m+1):
		print(inconveniences[i])

def root(union_find, val:int) -> int:
	if union_find[val][0] == val:
		return val
	return root(union_find, union_find[val][0])

def same(union_find, x:int, y:int) -> bool:
	rx = root(union_find, x)
	ry = root(union_find, y)
	return rx == ry

def unite(union_find, x:int, y:int):
	rx = root(union_find, x)
	ry = root(union_find, y)
	if rx == ry:
		return
	if union_find[rx][1] < union_find[ry][1]:
		union_find[rx][0] = ry
		union_find[ry][2] += union_find[rx][2]
	else:
		union_find[ry][0] = rx
		union_find[rx][2] += union_find[ry][2]
		if union_find[rx][1] == union_find[ry][1]:
			union_find[rx][1] += 1

if __name__ == '__main__':
    main()

Measured memory_bytes: 39752
from heapq import heappush, heappop
from math import ceil, floor
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

ng, ok = 0, 10 ** 9
for _ in range(50) :
  mid = (ng + ok) / 2
  ret = 0
  for a in A :
    ret += floor(a / mid)
  if ret <= K :
    ok = mid
  else :
    ng = mid
    
print(ceil(ng))

Measured memory_bytes: 93704
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<cstdlib>
#include<list>
#include<set>
#include<numeric>

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

int len[100003],len_sa[100003];

int main()
{
	int N, L,ans=0;
	cin >> N >> L;
	priority_queue<P> qu;

	for (int i = 1; i <= N; i++) {
		cin >> len[i];
		qu.push(P(len[i],i));
	}

	while (qu.size()) {
		P q = qu.top(); qu.pop();
		len_sa[q.second] = max(len_sa[q.second+1],len_sa[q.second-1])+L-q.first;
		ans = max(ans,len_sa[q.second]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4600
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt  // num
  val C = in.next().toLong  // dist
  val x = new Array[Long](N+1) // dist
  val v = new Array[Long](N+1) // ene
  for(i <- 1 to N){
    val a, b = in.next().toLong
    x(i) = a
    v(i) = b
  }


  //
  import Math._

  var ans = 0L

  var cnt = 0L
  val dpr = new Array[Long](N+2) // dist
  for(i <- 1 to N) {
    cnt += v(i)
    val now = cnt-x(i)
    ans = max(ans, now)
    dpr(i) = max(dpr(i-1), now)
  }


  cnt = 0L
  val dp = new Array[Long](N+2) // dist
  for(i <- (1 to N).reverse) {
    cnt += v(i)
    val now = cnt - (C - x(i))
    ans = max(ans, now)
    dp(i) = max(dp(i+1), now)
  }


  cnt = 0L
  for(i <- 1 to N) {
    cnt += v(i)
    val now = cnt - 2*x(i) + dp(i+1)
    ans = max(ans, now)
  }

  // will fix
  cnt = 0L
  for(i <- (1 to N).reverse) {
    cnt += v(i)
    val now = cnt - (C - x(i))*2 + dpr(i-1)
    ans = max(ans, now)
  }


  println(ans)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}



Measured memory_bytes: 48348
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try(Scanner scan = new Scanner(System.in)) {
			int a = scan.nextInt();
			int b = scan.nextInt();
			int c = scan.nextInt();
			int temp = 0;

			if(a > b) {
				temp = a;
				a = b;
				b = temp;
			}
			if(b > c) {
				temp = b;
				b = c;
				c = temp;
			}
			if(a > b) {
				temp = a;
				a = b;
				b = temp;
			}

			System.out.println(a + " " + b + " " + c);
		}
	}

}

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

int main(){
  int n,m;
  cin >> n >> m;
  priority_queue<double> pq;
  int pushnum;
  for(int i=0;i<n;i++){
    cin >> pushnum;
    pq.push(pushnum);
  }
  int kari;
  for(int i=0;i<m;i++){
    kari = pq.top();
    pq.pop();
    kari /= 2;
    pq.push(kari);
  }
  long long ans = 0;
  for(int i=0;i<n;i++){
    ans = (long long)ans + pq.top();
    pq.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 1400
fun main(args : Array<String>){
    val INF = 1000000000000000000L
    var (n,m) = readLine()!!.split(' ').map(String::toInt)
    var dp = Array(1111,{Array(1111,{LongArray(8,{-INF})}) })
    for(i in 0 until 8)dp[0][0][i] = 0

    for(i in 0 until n){
        val x = readLine()!!.split(' ').map(String::toLong)
        for(j in 0 until i+1){
            for(k in 0 until 8){
                if(dp[i][j][k] != -INF) {
                    var tmp = 0L
                    for (l in 0 until 3) {
                        if (k and (1.shl(l)) > 0){
                            tmp += x[l]
                        }
                        else{
                            tmp -= x[l]
                        }
                    }
                    dp[i+1][j][k] = Math.max(dp[i+1][j][k],dp[i][j][k])
                    dp[i+1][j+1][k] = Math.max(dp[i+1][j+1][k],dp[i][j][k]+tmp)
                }
            }
        }
    }

    var ans = -INF
    for(i in 0 until 8)ans = Math.max(ans,dp[n][m][i])

    println(ans)

}

Measured memory_bytes: 156160
line = require('fs').readFileSync('/dev/stdin', 'ascii').split('\n');
line[0] = line[0].split(' ').map(Number);
n = line[0][0];
m = line[0][1];
b = line.slice(n+1, n+m+1).map(Number);

for (i = 0; i < n; i++) {
	ai = line[i+1].split(' ').map(Number);
	console.log(inner_product(m, ai, b));
}

function inner_product(m, a, b) {
	var sum = 0, i;
	for (i = 0; i < m; i++)
		sum += a[i] * b[i];
	return sum;
}

Measured memory_bytes: 17412
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>

using namespace std;

typedef long long ll;

int main(void){
    ll a,p;
    cin >> a >> p;
    p += a*3;
    cout << p / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;

int main(){
    int n,r;
    cin >> n >> r;
    if (n>=10) cout << r<< endl;
    else{
        cout << r + 100 * (10-n) << endl;
    }
    return 0;



}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int a = cin.nextInt();
        int b = cin.nextInt();
        int c = cin.nextInt();
        int x = cin.nextInt();
        int y = cin.nextInt();

        if (a + b < c * 2) {
            System.out.println(a * x + b * y);
        } else if (x == y) {
            System.out.println(c * x * 2);
        } else {
            int majorityPrice = x > y ? a : b;
            int distance = Math.max(x, y) - Math.min(x, y);
            int price = c * Math.min(x, y) * 2 +
                    (majorityPrice < c * 2 ? majorityPrice * distance
                                           : c * 2 * distance);
            System.out.println(price);
        }
    }
}


Measured memory_bytes: 21972