akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

int main(void)
{
	ll n;
	scanf("%lld",&n);
	
	int sqn = sqrt(n);
	int ans = 0;
	for(int i=2; i<=sqn && n>1; ++i)
	{
		if(n%i) continue;
		int cnt = 0;
		while(n%i==0)
			++cnt, n/=i;
		
		for(int j=1; j<=cnt; ++j)
			++ans, cnt-=j;
	}
	if(n>1) ++ans;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3808
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String O = sc.next();
		String E = sc.next();
		int kisu = 0;
		int gusu = 0;
		for (int i = 0; i < O.length() + E.length(); i++) {
			if (i % 2 == 0) {
				System.out.print(O.charAt(kisu));
				kisu++;
			} else {
				System.out.print(E.charAt(gusu));
				gusu++;
			}
		}

	}

}

Measured memory_bytes: 21076
M=10**9+7
def extended_gcd(a, b)
  last_remainder, remainder = a.abs, b.abs
  x, last_x, y, last_y = 0, 1, 1, 0
  while remainder != 0
    last_remainder, (quotient, remainder) = remainder, last_remainder.divmod(remainder)
    x, last_x = last_x - quotient*x, x
    y, last_y = last_y - quotient*y, y
  end
  return last_remainder, last_x * (a < 0 ? -1 : 1)
end
 
def invmod(e)
  g, x = extended_gcd(e, M)
  x % M
end

n,k,*as=$<.read.split.map &:to_i
as.sort!

cvs=[0]*(k-1)
t=1
(n-k+1).times{|i|
  cvs.push(t)
  t=t*(i+k)*invmod(i+1)%M
}
puts (0...n).reduce(0){|s,i|
  (s+(cvs[i]-cvs[n-i-1])*as[i])%M
}

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

const int N = 2e5+2;
pair<int,int> input[N];

ll findWhenMinMax(int n,int maxi,int rem) {
   int mini = input[1].first;
   int rem2 = input[1].second;
   ll ret = 4e18;
   const int inf = 2e9;
   priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >pq;
   int R = 0;
   for(int i=2;i<=n;++i) {
      pq.push(input[i]);
      R = max(R,input[i].first);
   }
   pq.push(make_pair(rem2,inf));
   pq.push(make_pair(rem,inf));
   R = max(R,max(rem,rem2));
   ll len = maxi - mini;
   while(!pq.empty()) {
      pair<int,int> cur = pq.top();
      pq.pop();
      ret = min(ret, len * ( R - cur.first));
      if(cur.second == inf) {
         break;
      }
      pq.push(make_pair(cur.second,inf));
      R = max(R, cur.second);
   }
   return ret;
}

ll findWhenMinMaxDiff(int n,int maxi,int rem) {
   ll ret= 4e18;
   int yourMini = min(rem,input[1].first);
   int yourMaxi = max(rem,input[1].first);
   int myMini = input[1].second;

   for(int i=2;i<=n;++i) {
      int curYourMaxi = yourMaxi;
      int curMyMini = myMini;
      if(i!=n) {
         curYourMaxi = max(curYourMaxi, input[n].first);
      }
      curYourMaxi = max(curYourMaxi,input[i].second);
      curMyMini = min(curMyMini,input[i].first);
      yourMaxi = max(yourMaxi,input[i].first);
      myMini = min(myMini,input[i].second);
   }
   ll tmp = yourMaxi - yourMini;
   tmp *= (maxi - myMini);
   ret = min(ret,tmp);
   return ret;
}
void solve() {
   int n;
   scanf("%d",&n);
   if(n==1) {
      printf("0\n");
      return;
   }
   int ind = -1,maxi = 0;
   for(int i=1;i<=n;++i) {
      scanf("%d%d",&input[i].first,&input[i].second);
      if(input[i].first>input[i].second) {
         swap(input[i].first,input[i].second);
      }
      if(maxi< input[i].second) {
         ind = i;
         maxi = input[i].second;
      }
   }
   int rem = input[ind].first;
   for(int i=ind;i<n;++i) {
      swap(input[i],input[i+1]);
   }
   --n;
   sort(input+1,input+n+1);
   //case 1
   ll ret= findWhenMinMax(n,maxi,rem);

   //case2
   ret = min(ret, findWhenMinMaxDiff(n,maxi,rem));
   printf("%lld\n", ret);
}

int main() {
   //freopen("input.txt","r",stdin);
   solve();
}

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

int main(){
    set<int> d;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int v;
        cin>>v;
        d.insert(v);
    }
    cout<<d.size()<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <map>
#include <queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle
{
    int f[N2];
    int space;
    string path;
    bool operator < (const Puzzle &p) const
    {
        for(int i=0; i<N2; i++)
        {
            if(f[i]==p.f[i]) continue;
            return f[i] > p.f[i];
        }
        return false;
    }
};

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};

bool isTarget(Puzzle p)
{
    for(int i=0; i<N2; i++)
    {
        if(p.f[i] != (i+1)) return false;
    }
    return true;
}

string bfs(Puzzle s)
{
    queue<Puzzle> Q;
    map<Puzzle, bool> V;
    Puzzle u, v;
    s.path = "";
    Q.push(s);
    V[s] = true;

    while(!Q.empty())
    {
        u = Q.front(); Q.pop();
        if(isTarget(u)) return u.path;
        int sx = u.space / N;
        int sy = u.space % N;
        for(int r=0; r<4; r++)
        {
            int tx = sx + dx[r];
            int ty = sy + dy[r];
            if(tx<0 || ty<0 || tx>=N || ty>=N) continue;
            v = u;
            swap(v.f[u.space], v.f[tx*N+ty]);
            v.space = tx*N + ty;
            if(!V[v])
            {
                V[v] = true;
                v.path += dir[r];
                Q.push(v);
            }
        }
    }
    return "unsolvable";
}

int main()
{
    Puzzle in;

    for(int i=0; i<N2; i++)
    {
        cin >> in.f[i];
        if(in.f[i] == 0)
        {
            in.f[i] = N2;
            in.space = i;
        }
    }
    string ans = bfs(in);
    cout << ans.size() << endl;
    return 0;
}


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

class lazy_segtree {
    private:
        int size;
        vector<int> node,lazy;
    public:
        lazy_segtree(int n_) {
            size=1;
            while (size<n_) size*=2;
            node.resize(2*size, 0);
            lazy.resize(2*size, 0);
        }

        void setlazy(int k, int v) {
            if (2*size-1<=k) return ;
            lazy[k] += v;
            node[k] += v;
        }

        void push(int k) {
            if (lazy[k] == 0) return ;
            setlazy(k * 2 + 1, lazy[k]);
            setlazy(k * 2 + 2, lazy[k]);
            lazy[k] = 0;
        }

        void range_add(int queryL,int queryR,int val,int k=0,int nodeL=0,int nodeR=-1) {
            if (nodeR==-1) nodeR=size;
            if (nodeR<=queryL || queryR<=nodeL) return ;
            if (queryL<=nodeL && nodeR<=queryR) {
                setlazy(k,val);
                return ;
            }
            else {
                push(k);
                int nodeM=(nodeL+nodeR)/2;
                range_add(queryL,queryR,val,k*2+1,nodeL,nodeM);
                range_add(queryL,queryR,val,k*2+2,nodeM,nodeR);
                return ;
            }
        }

        int get_node(int queryL,int queryR,int k=0,int nodeL=0,int nodeR=-1) {
            if (nodeR==-1) nodeR=size;
            if (nodeR<=queryL || queryR<=nodeL) return 0;
            if (queryL<=nodeL && nodeR<=queryR) return node[k];
            else {
                push(k);
                int nodeM=(nodeL+nodeR)/2;
                int vl=get_node(queryL,queryR,k*2+1,nodeL,nodeM);
                int vr=get_node(queryL,queryR,k*2+2,nodeM,nodeR);
                return vl+vr;
            }
        }
};

int n,q;

int main(){
    cin >> n >> q;
    lazy_segtree ls(n);
    for (int i=0; i<q; i++) {
        int que,s,t,x,idx;
        cin >> que;
        if (que==0) {
            cin >> s >> t >> x;
            ls.range_add(s-1,t,x);
        }
        else {
            cin >> idx;
            cout << ls.get_node(idx-1,idx) << endl;
        }
    }
    return 0;
}

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

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

const int MAXN = 100;
const int MAXW = 1e5;

int n, m;
int w[MAXN+10], v[MAXN+10];
ll dp[MAXN+10][MAXW+10];

int main()
{
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(false);
    int i, j;

    scanf("%d%d", &n, &m);
    for(i=1; i<=n; i++) scanf("%d%d", &w[i], &v[i]);

    for(i=1; i<=n; i++) for(j=0; j<=m; j++)
    {
        dp[i][j]=dp[i-1][j];
        if(j>=w[i]) dp[i][j]=max(dp[i][j], dp[i-1][j-w[i]]+v[i]);
    }

    printf("%lld", dp[n][m]);
    return 0;
}


Measured memory_bytes: 79360
import java.util.*;
import java.util.stream.Collectors;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
      
        int n = sc.nextInt();
        ArrayList<Point> points = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            points.add(new Point(sc.nextInt(), sc.nextInt(), sc.nextInt()));
        }
      
        Point beforePoint = new Point(0, 0, 0);
        boolean isFail = false;
        for (Point point : points) {
            int diffTime = point.getTime() - beforePoint.getTime();
            int diffX = point.getX() - beforePoint.getX();
            int diffY = point.getY() - beforePoint.getY();

            if (diffX + diffY > diffTime) {
                isFail = true;
                break;
            }

            if (diffTime % 2 == 0 && (diffX + diffY) % 2 != 0) {
                isFail = true;
                break;

            } else if (diffTime % 2 != 0 && (diffX + diffY) % 2 == 0) {
                isFail = true;
                break;

            }

            beforePoint = point;

        }
        if (isFail) {
            System.out.println("No");

        } else {
            System.out.println("Yes");

        }
    }
    public static class Point {
        private int time;
        private int x;
        private int y;

        public int getTime() {
            return time;
        }

        public int getX() {
            return x;
        }

        public int getY() {
            return y;
        }

        public Point(int time, int x, int y) {
            this.time = time;
            this.x = x;
            this.y = y;
        }
    }

}

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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define REP64(i, s,  n) for(int64 i = s;i < (n);i++)
#define INF 999999999
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

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

int N, H, W;

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

	cin >> N >> H >> W;
	int ans = 0;
	int A, B;
	REP(i, 0, N) {
	    cin >> A >> B;
		if(A >= H && B >=W) ans++;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
import heapq
N, M = [int(x) for x in input().split()]
h = []
[heapq.heappush(h, -int(x)) for x in input().split()]
for _ in range(M):
    tmp = heapq.heappop(h)
    if (tmp == 0): break
    heapq.heappush(h, -1*(-tmp//2))
print(-1 * sum(h))


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

#ifndef ONLINE_JUDGE
	#define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y;
#else
	#define W(x, y)
#endif


#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define vl vector<ll>
#define vll vector<pll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi acos(-1)
#define ld long double
#define prime (1000000000 + 7)

using namespace std;

#define INF 1000000000



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

	
	string s;
	cin >> s;

	stack<ll> pilha;
	for(int i = 0; i < s.size(); ++i){
		if(pilha.empty()){
			pilha.push(s[i]);
		} else{
			if(pilha.top() != s[i]){
				pilha.pop();
			} else{
				pilha.push(s[i]);
			}
		}
	}
	cout << s.size() - pilha.size() << endl;

	return 0;
}

Measured memory_bytes: 1232
import bisect

n = int(input())
ls = [int(elem) for elem in input().split()]
ls = sorted(ls)

cnt = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        k = bisect.bisect_left(ls, ls[i] + ls[j])
        k -= 1
        cnt += k - j
print(cnt)

Measured memory_bytes: 3188
use std::io;
use std::str::FromStr;

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();

    let mut it = buf.split_whitespace().map(|n| String::from_str(n).unwrap());
    let n = it.next().unwrap();

    print!("ABC{}\n", n);

}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {
	
	

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Reader.init(System.in);
		StringBuilder output=new StringBuilder("");
		PrintWriter out=new PrintWriter(System.out);
		int n=Reader.nextInt();
		double[] arr=new double[n+1];
		for(int i=1;i<=n;i++) arr[i]=Reader.nextDouble();
		double[][] dp=new double[n+1][n+1];
		dp[1][0]=1-arr[1];
		dp[1][1]=arr[1];
		for(int i=2;i<=n;i++) {
			dp[i][0]=(dp[i-1][0]*(1-arr[i]));
			for(int j=1;j<=i;j++) {
				dp[i][j]=dp[i-1][j]*(1-arr[i])+dp[i-1][j-1]*arr[i];
			}
		}
		double ans=0;
		for(int i=1;i<=n;i++) {
			if(i>n-i) {
				ans+=dp[n][i];
			}
		}
		output.append(ans);
		out.write(output.toString());
		out.flush();
	}

}

class DE{
	int a;
	int b;
	int c;
	DE(int aa,int ab){
		a=aa;b=ab;
	}
}
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
 
    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
 
    /** get next word */
    static String nextLine() throws IOException{
    	return reader.readLine();
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}




 
 

 


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

int main(void)
{
    string str;
    getline(cin, str);
    for (int i = 0; i < str.size(); ++i) {
        if ('a'<= str[i] && str[i] <= 'z')
            str[i] = 'A' + str[i] - 'a';
    }
    cout << str << endl;
    return 0;
}



Measured memory_bytes: 3160
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n, k, c;
    cin >> n >> k >> c;

    string s;
    cin >> s;

    vector <bool> ans(n, false); // 働かなくてもいい日はtrue
    vector <int> work;
    int prev = -c-1;

    for (int i = 0; i < n; i++) {
        if (s[i] == 'o') {
            if (prev + c < i && work.size() < k) {
                work.push_back(i);
                prev = i;
            } else {
                ans[i] = true;
            }
        }
    }

    int idx = k - 1;
    prev = n + c + 1;
    for (int i = n - 1; i >= 0; i--) {
        if (s[i] == 'x') continue;
        if (i > work[idx]) {
            if (i + c < prev) {
                ans[work[idx]] = true;
                prev = i;
                idx--;
            }
        } else if (i == work[idx]) {
            idx--;
            prev = i;
        }
        
        if (idx == -1) break;
    }

    for (int i = 0; i < n; i++) {
        if (s[i] == 'o' && ans[i] == false) {
            cout << i + 1 << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 2804
#include <bits/stdc++.h>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
int main() {
    int n;
    cin >> n;
    
    int x[n];
    rep(i, n) cin >> x[i];
    
    int flag = 1, tmp = 0, cnt = 0;
    while(flag) {
        flag = 0;
        for(int i=n-1; i > 0; i--) {
            if(x[i-1] > x[i]) {
                tmp = x[i-1];
                x[i-1] = x[i];
                x[i] = tmp;
                flag = 1;
                cnt++;
            }
        }

    }
    
    rep(i, n) cout << x[i] << ((i == n-1) ? "\n" : " ");
    cout << cnt << endl;
    
    
    
}
    



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, n) {
    cin >> c[i];
    rep(j, m) {
      cin >> a[i][j];
    }
  }

  LL sum = 1e9;
  for (int bits = 0; bits < (1 << n); bits ++) {
    LL t = 0;
    vector<int> check(m);
    for (int i = 0; i < n; i ++) {
      if (bits & (1 << i)) {
        t += c[i];
        for (int j = 0; j < m; j ++) {
          check[j] += a[i][j];
        }
      }
    }

    bool ok = true;
    for (int i = 0; i < m; i ++) {
      if (check[i] < x) {
        ok = false;
        break;
      }
    }
    if (ok) sum = min(sum, t);
  }

  if (sum == 1e9) sum = -1;
  cout << sum << endl;
}


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

int main()
{
int n,m;
cin>>n>>m;

vector<vector<int> > matrix(n,vector<int>(m+1,0));

for(int i=0;i<n;i++)
{
	int k;
	cin >> k;
	for(int j=0;j<k;j++)
	{
		int temp;
		cin >> temp;

		matrix[i][temp]=1;
	}
}

int ans=0;
for(int j=1;j<=m;j++)
{
	int flag=1;
	for(int i=0;i<n;i++)
	{
		if(matrix[i][j]!=1)
		{
			flag=0;
			break;
		}
	}
	if(flag==1)
		ans+=1;
	
}

cout<<ans;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct edge{
	int f,t,nxt;
}; 
edge e[400200];
int head[200100],cnt;
int num;
int sg[200100];
void add_edge(int f,int t){
	e[cnt]=(edge){f,t,head[f]};
	head[f]=cnt;
	cnt++;
	return;
}
queue<int> q;
int vis[200100];
int bfs(int st){
	while(!q.empty()) q.pop();
	memset(vis,0,sizeof(vis));
	q.push(st);
	vis[st]=1;
	int ans=0;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		ans=x;
		for(int i=head[x];i;i=e[i].nxt){
			int v=e[i].t;
			if(!vis[v]){
				vis[v]=vis[x]+1;
				q.push(v);
			}
		}
	}
	return ans;
} 
int main(){
	cnt=2;
	memset(head,0,sizeof(head));
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int f,t;
		scanf("%d%d",&f,&t);
		add_edge(f,t);
		add_edge(t,f);
	}
	num=0;
	int pt1=bfs(1);
	num=0;
	int pt2=bfs(pt1);
	int ans=vis[pt2];
	sg[0]=0;
	sg[1]=1;
	sg[2]=0;
	for(int i=3;i<=ans;i++){
		for(int j=0;;j++){
			if(j!=sg[i-1] && j!=sg[i-2]){
				sg[i]=j;
				break;
			}
		}
	}
	if(sg[ans]){
		printf("First\n");
	}
	else{
		printf("Second\n");
	}
	return 0;
}


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

main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long i,j,m,a,b,k,n,w,p,l;
    while(cin>>n)
    {
        long long x[n],sum=0;
        for(i=0; i<n; i++)cin>>x[i];
      //sort(x,x+n);
        for(i=0; i<n; i++)
        {
            sum+=x[i];

        }
        j=0;
        long long ans=0;
        for(i=0; i<n-1; i++)
        {
            sum-=x[i];
       ans+=(((x[i]%1000000007)*(sum%1000000007))%1000000007);
      // cout<<ans<<" ";
        }
        cout<<ans%1000000007<<endl;
    }
    return 0;
}


Measured memory_bytes: 5212
n, q = map(int, input().split())
s = input()
SUM = [0]*n

for i in range(1, n):
  if s[i] == "C" and s[i-1] == "A":
    SUM[i] = SUM[i-1] + 1
  else:
    SUM[i] = SUM[i-1]

for i in range(q):
  l, r = map(int, input().split())
  print(SUM[r-1] - SUM[l-1])

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
using ll = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;

int main() {
  int x,y;
  cin>>x>>y;
  for(int i = 0; i <= x; i++) {
    if ((i * 2 + (x-i) * 4) == y) {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll>
#define vv vector<v>
#define p pair<ll,ll>
int main()
{
	int n;
	cin>>n;
	v arr(n+1,-1);
	for (int i=1; i<=n; i++)
		cin>>arr[i];
	vv dp1(n+2,v(n+2,0));
	vv dp2(n+2,v(n+2,0));
	for (int i=n; i>=1; i--)
	{
		for (int j=i; j<=n; j++)
		{
			dp1[i][j]=max(dp2[i+1][j]+arr[i],dp2[i][j-1]+arr[j]);//+arr[i];
			dp2[i][j]=min(dp1[i+1][j]-arr[i],dp1[i][j-1]-arr[j]);
		}
	}
	cout<<dp1[1][n]<<endl;
	return 0;
}

Measured memory_bytes: 141312
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  string input;
  cin >> input;

  for(int i=0; i<N; i++) {
    if(i == K-1) cout << (char)tolower(input.at(i));
    else cout << (char)input.at(i);
  }

  cout << endl;
  return 0;
}



Measured memory_bytes: 3624
open System

[<EntryPoint>]
let main argv =
  let xs = Console.ReadLine().Split(' ') |> Array.map int
  let ans =
    let A = xs.[0] in
    let B = xs.[1] in
    if (A+B)%2 = 0 then string ((A+B)/2) else "IMPOSSIBLE"
  ans |> Console.WriteLine
  0


Measured memory_bytes: 11220
n=int(input())
G=[[] for i in range(n+1)]
G_order=[]
for i in range(n-1):
  a,b=map(int,input().split())
  G[a].append(b)
  G_order.append(b)

from collections import deque
q=deque([1])
color=[0]*(n+1)
while q:
  cur=q.popleft()
  c=1
  for nx in G[cur]:
    if c==color[cur]:
      c+=1
    color[nx]=c
    c+=1
    q.append(nx)

print(max(color))
for i in G_order:
  print(color[i])

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

int main(){
	int N; cin >> N;
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        long long tmp;
        cin >> tmp;
        ans += tmp;
    }
    cout << (ans%2 == 0 ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N,K;cin >> N >> K;
    string S;cin >> S;
    int ans = 0;
    rep(i,N){
        if(i==0)if(S[0] == 'L')continue;
        if(i==N-1)if(S[N-1] == 'R')continue;
        if(S[i] == 'L')if(S[i-1] == 'L')ans++;
        if(S[i] == 'R')if(S[i+1] == 'R')ans++;
    }
    ans = min(ans + K*2,N-1);
    cout << ans << endl;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int a[200001],b[200001];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	for(int i=n;i>=1;i--)
	cin>>b[i];
	int flag=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==b[i])
		{
			flag=0;
			for(int j=1;j<=n;j++)
			{
				if(a[i]!=b[j]&&a[j]!=b[i])
				{
					swap(b[i],b[j]);
					flag=1;
					break;
				}
			}
			if(!flag)
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	for(int i=1;i<=n;i++)
	cout<<b[i]<<" ";
	return 0;
}


Measured memory_bytes: 5172
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

/////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    map<string, int> mp;
    int n, m;
    cin >> n;
    REP(i, n) {
    	string s;
    	cin >> s;
    	mp[s]++;
    }
    cin >> m;
    REP(i, m) {
    	string s;
    	cin >> s;
    	mp[s]--;
    }
    int ans = 0;
    for(auto& p : mp) {
    	ans = max(ans, p.second);
    }
    cout << ans << endl;

    return 0;
}

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


#define MAX 52

string s;
string t;
vector<string> v;

int main() {
	cin >> s >> t;
	for (int i = 0; i + t.size() <= s.size(); i++) {
		string k = s.substr(i, t.size());
		bool ok = false;
		for (int j = 0; j < t.size(); j++) {
			if (k[j] == '?')continue;
			if (k[j] != t[j]) {
				ok = true;
				break;
			}
		}
		if (ok == false) {
			string ss = s;

			for (int j = 0; j < s.size(); j++) {
				if (i <= j&&j < i+t.size()) {
					continue;
				}
				if (s[j] == '?') {
					s[j] = 'a';
				}
			}
			for (int j = i; j < i + t.size(); j++) {
				s[j] = t[j - i];
			}
			v.push_back(s);
			s = ss;
			
		}
	}
	sort(v.begin(), v.end());
	if (v.size()) {
		cout << v[0] << endl;
		return 0;
	}
	puts("UNRESTORABLE");
	return 0;
}

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

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

	string s; cin >> s;
	int N = s.length();
	char x = s[0];
	int c = 0;
	for (int i = 1; i < N; i++) {
		if (s[i - 1] != s[i]) {
			c++;
		}
	}
	cout << c;
}


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

int main()
{
    int line[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int k;
    cin >> k;

    cout << line[k-1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 13;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int dp[N], h[N];

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++){
        cin >> h[i];
        if (i > 1) dp[i] = inf;
        for (int j = 1; j <= min(k, i -1); j++){
            dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
        }
    }
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

const ll M = 3010;
ll dp[M][2*M];

// v1をソートし、v2を対応する位置に移動する
template<typename T, typename U>
void pairSort(vector<T>& v1, vector<U>& v2, bool rev = false) {
    int n = v1.size();
    vector<pair<T, U>> p(n);
    for(int i = 0; i < n; i++) {
        p[i] = pair<T, U>(v1[i], v2[i]);
    }
    if(rev) {
        sort(p.begin(), p.end(), [&](const auto& l, const auto& r) {
            if(l.first == r.first)
                return l.second > r.second;
            else return l.first < r.first;
        });
    } else {
        sort(p.begin(), p.end());
    }
    for(int i = 0; i < n; i++) {
        v1[i] = p[i].first;
        v2[i] = p[i].second;
    }
}


int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, t;
    cin >> n >> t;
    vll a(n), b(n);
    rep(i, n){
        cin >> a[i] >> b[i];
    }
    pairSort(a, b);
    rep(i, 2*M){
        dp[0][i] = 0;
    }
    rep(i, n){
        rep(j, t){
            dp[i+1][j+a[i]] = max(dp[i][j] + b[i], dp[i][j+a[i]]);
        }
        rep(j, 2*M){
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }
    ll ans = 0;
    rep(i, 2*M){
        chmax(ans, dp[n][i]);
    }
    /*
    vvll dp2;
    rep(i, n+1){
        dp2.emplace_back(vll());
        rep(j, t+120){
            dp2[i].emplace_back(dp[i][j]);
        }
    }
    dump(dp2);
    */
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 141696
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
string s;
bool ok1,ok2;
int main(){
	cin >> s;
	for(int i = 0;i < 3;i++){
		if(s[i] == 'A') ok1 = 1;
		if(s[i] == 'B') ok2 = 1;
	}
	if(ok1&&ok2) cout << "Yes" << endl;
	else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>
#include <climits>
#include <numeric>
#include <functional>

#define lnd '\n'
// #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, n) for(ll i = 0; i < n; i++)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mk make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

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

template <class T>
T GCD (T a, T b) {
  if(a == 0) return b;
  return GCD(b%a, a);
}

template <class T>
T LCM(T a, T b){
  return a*b/GCM(a,b);
}

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
T modpow(T x, T p, ll mod){
    T res = 1;
    while(p > 0){
        if(p&1) res = (res*x)%mod;
        x = (x*x)%mod;
        p /= 2;
    }
    return res%mod;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

struct HASH{
  size_t operator()(const pair<long,long>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
    if(p1.first != p2.first) return p1.first < p2.first;
    else return p1.second < p2.second;
}

const int INF = std::numeric_limits<int>::max();
const ll M_INF = std::numeric_limits<ll>::min();
const ll LL_INF = std::numeric_limits<ll>::max();

void solution();
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

void solution(){
  double m, n;
  cin >> n >> m;
  vector<double> a(n);
  double d = 0;
  double div = 1/(4*m);
  for(int i = 0; i < n; i++){
    cin >> a[i];
    d += a[i]*div;
  }

  ll count = 0;
  for(int i = 0; i < n; i++){
    if(a[i] >= d) count++;
  }

  if(count >= m){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}     



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  VEC<int> c(n), s(n), f(n);
  REP(i, 0, n - 1) cin >> c[i] >> s[i] >> f[i];
  REP(i, 0, n - 1) {
    int start = s[i];
    int nextArrive = s[i] + c[i];
    REP(j, i+1, n - 1) {
      int mod = nextArrive % f[j];
      int wait;
      if (nextArrive >= s[j])
        wait = mod == 0 ? 0 : f[j] - mod;
      else
        wait = s[j] - nextArrive;
      nextArrive += wait + c[j];
    }
    cout << nextArrive << endl;
  }
  cout << 0 << 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;
using ll = long long;
using P = pair<int,int>;

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int dp[100010][3];

int main() {
    int N;
    cin >> N;
    for (int i=1; i<=N; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a;
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b;
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c;
    }
    cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;
    return 0;
}

Measured memory_bytes: 1408
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
   
#define M 1133331
#define NIL (-1)
#define L 14
   
char H[M][L]; /* Hash Table */
   
int getChar(char ch){
    if (ch == 'A') return 1;
    else if (ch == 'C') return 2;
    else if (ch == 'G') return 3;
    else if (ch == 'T') return 4;
}
   
/* convert a string into an integer value */
long long getKey(char str[]){
    long long sum = 0, p = 1, i;
    for (i = 0; i < strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}
   
int h1(int key){ return key%M; }
int h2(int key){ return 1 + (key % (M - 1)); }
   
int find(char str[]){
    long long ii = getKey(str);
    int i,k;
    int hh1 = h1(ii);
    int hh2 = h2(ii);
    for (i = 0; i<M ; i++){
      k=(hh1 + i*hh2) % M;
      if (H[k][0] == '\0'){return 0;}
        else if (strcmp(H[k], str) == 0){ return 1; }
    }
    return 0;
    /* your task */
   
}
   
int insert(char str[]){
    long long ii = getKey(str);
    int hh1 = h1(ii);
    int hh2 = h2(ii);
    int i,k;
    for (i = 0; i<M; i++){
        k=(hh1 + i*hh2) % M;
        if (H[k][0]== '\0'){
            strcpy(H[k], str);
            return 0;
        }
    }
    return 0;
    /* your task */
   
}
   
int main(){
    int i, n, h;
    char str[L], com[9];
    for (i = 0; i < M; i++) H[i][0] = '\0';
   
    scanf("%d", &n);
   
    for (i = 0; i < n; i++){
        scanf("%s %s", com, str);
   
        if (com[0] == 'i'){
            insert(str);
        }
        else {
            if (find(str)){
                printf("yes\n");
            }
            else {
                printf("no\n");
            }
        }
    }
   
    return 0;
}

Measured memory_bytes: 16100
#include <stdio.h>

int main(void)
{
    int tmp,n,x=0;
    
    scanf("%d",&n);
    int *A=malloc(sizeof(int)*n);
    
    for(int i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    
    int flag=1;
    while(flag){
        flag=0;
        for(int i=n-1;0<=i;i--){
            if(A[i-1]>A[i]){
              tmp    = A[i];
              A[i]   = A[i-1];
              A[i-1] = tmp;
              x++;
              flag=1;
            }
        }
    }
    for(int i=0;i<n;i++){
        if(n-1!=i) printf("%d ",A[i]);
        else printf("%d\n%d\n",A[i],x);
    }
    
    free(A);
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define rep(i,a,b) for(int (i) = (a); (i) <= (b); i++)
#define repd(i,a,b) for(int (i) = (a); (i) >= (b); i--)
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define mp make_pair
#define pb push_back
#ifndef ONLINE_JUDGE
	#define debug 1
#else
	#define debug 0
#endif
using namespace std;
#define is_digit(c) ((c) >= '0' && (c) <= '9')
#define is_upper(c) ((c) >= 'A' && (c) <= 'Z')
#define is_lower(c) ((c) >= 'a' && (c) <= 'z')
#define readchar() ((char)fgetc(stdin))
#define printchar(c) fputc((c), stdout)
void readline(char *s) {int len=0;char c;for(c=readchar(); c!='\n'; s[len++]=c, c=readchar());}
void readstr(char *s) {int len=0;char c;for(c=readchar(); c!=' '&&c!='\n'; s[len++]=c, c=readchar());}
void printstr(char *s) {int len=strlen(s);rep(i,0,len-1) printchar(s[i]);}
void to_lower(char *s, int L, int R) {rep(i,L,R) if (is_upper(s[i])) s[i]=s[i]-'A'+'a';}
void to_upper(char *s, int L, int R) {rep(i,L,R) if (is_lower(s[i])) s[i]=s[i]-'a'+'A';}
ll readll() {
	char c;ll ans=0, x=1;for (c=readchar(); !is_digit(c)&&c!='-'; c=readchar());
	if (c=='-') x=-1, c=readchar();for (; is_digit(c); ans=ans*10+c-'0', c=readchar());return ans*x;
}
void printll(ll x) {
	int a[25], cnt=0;if (x==0) { printchar('0'); return; }if (x<0) printchar('-'), x=-x;
	for (; x; a[cnt++]=x-x/10*10, x/=10);repd(i,cnt-1,0) printchar(a[i]+'0');
}
#define readint() ((int)readll())
#define printint(x) printll((ll)(x))
int n, cnt[26];
char s[105], t[105];
bool can(int tms) {
	rep(i,0,25) {
		rep(j,0,n-1) t[j]=s[j];
		repd(j,n-1,n-tms) rep(k,1,j) if (t[k]==i+'a') t[k-1]=t[k];
		bool f=true;
		rep(j,0,n-tms-1) if (t[j]!=i+'a') f=false;
		if (f) return true;
	}
	return false;
}
int main() {
	readstr(s);
	n=strlen(s);
	rep(i,0,n-1) cnt[s[i]-'a']++;
	int l=0, r=n, m=0;
	while (l<r) {
		m=(l+r)>>1;
		if (can(m)) r=m;
		else l=m+1;
	}
	printint(l);
	return 0;
}


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

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

int main()
{
	int N, K;
	std::cin >> N;
  std::cin >> K;
	int h[N];
	int mind = 1e+9;

	for(int i=0;i<N;i++){
		std::cin >> h[i];
	}

	std::sort(h, h + SIZE_OF_ARRAY(h));

	for(int i=0;i<=N-K;i++){
		if(h[i+K-1]-h[i]<mind){
			mind = h[i+K-1]-h[i];
		}
	}

	std::cout << mind << std::endl;

	return 0;
}

Measured memory_bytes: 640
if __name__ == '__main__':
    tmp = int(input())
    n = tmp
    tmp_n = n
    ad = 0
    while True:
        ad += tmp_n % 10
        tmp_n //= 10
        if tmp_n == 0:
            break
    if n % ad == 0:
        ans = 'Yes'
    else:
        ans = 'No'
    print(ans)
   

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n, 0);
    for (size_t i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    ll min_diff = 10000000000;
    for (size_t i = 0; i <= n - k; i++)
    {
        int diff = h[i + k - 1] - h[i];
        if (diff < min_diff)
        {
            min_diff = diff;
        }
    }
    cout << min_diff << endl;

    return 0;
}

Measured memory_bytes: 640
#energy drink collector
n,m=map(int,input().split())
lists=[]
for i in range(n):
    a,b=map(int,input().split())
    lists.append((a,b))
lists=sorted(lists,key=lambda x:x[0])
ans=0
sums=0
for i in range(n):
    if sums+lists[i][1]<m:
        ans+=lists[i][0]*lists[i][1]
        sums+=lists[i][1]
    else:
        ans+=lists[i][0]*(m-sums)
        break
print(ans)

Measured memory_bytes: 18948
object Main extends App {
  val n = readInt
  val ints = (1 to n).map(_ => readInt).map(_.toLong)
  lazy val (smallerInts, largerInts) = ints.sorted.splitAt(ints.length / 2)
  lazy val (largerInts2, smallerInts2) = ints.sorted.reverse.splitAt(ints.length / 2)
  val res = if (ints.length % 2 == 0) {
    largerInts.head - smallerInts.last - smallerInts.init.sum * 2 + largerInts.tail.sum * 2
  } else {
    val res1 = largerInts.head + largerInts.tail.head + largerInts.tail.tail.sum * 2 - smallerInts.sum * 2
    val res2 = - smallerInts2.head - smallerInts2.tail.head + largerInts2.sum * 2 - smallerInts2.tail.tail.sum * 2
    math.max(res1, res2)
  }
  println(res)
}


Measured memory_bytes: 48288
function main(input) {
  input = input.split("\n");
  const n = Number(input[0]);
  let prevX = 0;
  let prevY = 0;
  let prevT = 0;
  let result = "Yes";
  for (let i = 1; i <= n; i++) {
    const [t, x, y] = input[i].split(" ").map(n => Number(n));
    const diffT = t - prevT;
    const distance = Math.abs(x - prevX) + Math.abs(y - prevY);
    if (diffT < distance || diffT%2 !== distance%2) {
      	result = "No";
        break;
    }
  }
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29260
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int maxn =1e5+50;
int a[maxn];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int tot=0;
    for(int i=1;i<n;i++)
    {
        if(a[i]==i)
        {
            swap(a[i],a[i+1]);
            tot++;
        }
    }
    if(a[n]==n)
    {
        swap(a[n],a[n-1]);
        tot++;
    }
    cout << tot << endl;
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 640
n,l_ = (int(i) for i in input().split())
l = list(range(l_, l_+n))
if all(i > 0 for i in l):
  print(sum(l) - min(l))
elif all(i < 0 for i in l):
  print(sum(l) - max(l))
else:
  print(sum(l))

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,cnt,num;
  cin >> n;
  int d[n];
  for(int i=0;i<n;i++){
    cin >> d[i];
  }
  sort(d,d+n,greater<int>());
  num=d[0];
  cnt=1;
  for(int i=1;i<n;i++){
    if(d[i]<num){
      num=d[i];
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int A,B;
  cin >> A >> B;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin >> P.at(i);
  }
  int ans=0;
  int first=0,second=0,third=0;
  for(int i=0;i<N;i++){
    if (P.at(i)<=A) {first++;}
    if(P.at(i)>=A+1 && P.at(i) <= B){second++;}
    if(P.at(i)>=B+1){third++;}
  }
  ans=min(first,min(second,third));
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    string s;
    cin >> s;
    lint ns = s.size();
    map<char, int> color;
    color['R'] = 0;
    color['G'] = 1;
    color['B'] = 2;
    vector<vector<int>> rgb(n, vector<int>(3, 0));
    for (int i = 0; i < ns; ++i) {
        rgb[i][color[s[i]]]++;
    }
    for (int i = ns - 2; i >= 0; --i) {
        for (int j = 0; j < 3; ++j) {
            rgb[i][j] += rgb[i + 1][j];
        }
    }
    lint ret = 0;
    for (int i = 0; i < ns - 2; ++i) {
        for (int j = i + 1; j < ns - 1; ++j) {
            if (s[i] == s[j])
                continue;
            ret += ns - j - 1 - rgb[j + 1][color[s[i]]] - rgb[j + 1][color[s[j]]];
            if (2 * j - i < ns && s[2 * j - i] != s[i] && s[2 * j - i] != s[j])
                ret--;
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 3760
N = int(input())
lis = []
lstipt = []
cnt = 0
h = 0
while h == 0:
    x, y, h = map(int, input().split())
    if h == 0:
        lstipt.append([x,y,h])
    cnt += 1

for Cx in range(101):
    for Cy in range(101):
        Ph = abs(x-Cx) + abs(y-Cy) + h
        lis.append([Cx,Cy,Ph])

for _ in range(N-cnt):
    x, y, h = map(int, input().split())
    newlis = []
    if h == 0: 
        for l in lis:
            if abs(x-l[0]) + abs(y-l[1]) + h >= l[2]:
                newlis.append(l)
    else:
        for l in lis:
            if abs(x-l[0]) + abs(y-l[1]) + h == l[2]:
                newlis.append(l)
    lis = newlis

for ipt in lstipt:
    x, y, h = ipt[0], ipt[1], ipt[2]
    newlis = []
    if h == 0: 
        for l in lis:
            if abs(x-l[0]) + abs(y-l[1]) + h >= l[2]:
                newlis.append(l)
    else:
        for l in lis:
            if abs(x-l[0]) + abs(y-l[1]) + h == l[2]:
                newlis.append(l)
    lis = newlis

print(" ".join(map(str,lis[0])))



Measured memory_bytes: 4452