akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
#define watch(x) cout << (#x)<<" = "<<x<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}

int main() {
	file();
	fast();
	int n, k; cin >> n >> k;
	vii v1(k);
	for (auto& it : v1)
		cin >> it.first >> it.second;
	vector<ll> mem(n + 9), pre(n + 9);
	mem[n] = pre[n] = 1;
	int mod = 998244353;
	for (int i = n - 1; i >= 1; i--) {
		for (auto& it : v1) {
			if (i + it.first > n) continue;
			int L = i + it.first;
			int R = min(n, i + it.second);
			mem[i] += ((pre[L] - pre[R + 1] + mod) % mod);
			mem[i] += mod;
			mem[i] %= mod;
		}
		pre[i] = mem[i] + pre[i + 1];
		pre[i] %= mod;
	}
	cout << mem[1] << endl;
	return 0;
}


Measured memory_bytes: 6344
#include<bits/stdc++.h>
using namespace std;
const int MN = 81, LOG = 60, MOD = 1e9+7, ADD = MN*MN*2;
using pii = pair<int,int>;
using ll = long long;
int dp[6005];
int main () {
	int n,t;
	scanf ("%d %d",&n,&t);
	vector<pii> stuff(n);
	for (auto &au : stuff) scanf ("%d %d",&au.first,&au.second);
	sort(stuff.begin(),stuff.end());
	for (auto &a : stuff) {
		for (int i = t-1; i >= 0; i--)
			dp[i+a.first] = max(dp[i+a.first],dp[i]+a.second);
	}
	int ret = 0;
	for (int i = 0; i <= 6000; i++) ret = max(ret,dp[i]);
	printf ("%d\n",ret);
	return 0;
}

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

long long D = 365, type = 26, inf = 1001001001;
vector<long long> C(type);
vector<vector<long long>> S(D,vector<long long>(type));

struct STR{
  long long score;
  vector<long long> ans;
  vector<long long> last;
};
bool operator<(const STR &left, const STR &right) {
  if(left.score<right.score) return true;
  else return false;
}

void input(){
  cin >> D;
  for(int i=0;i<type;i++) cin >> C[i];
  for(int i=0;i<D;i++){
    for(int j=0;j<type;j++){
      cin >> S[i][j];
    }
  }
  return;
}

long long calc(long long day, long long t, vector<long long> &last){
  long long score = S[day][t];
  for(int i=0;i<type;i++){
    score -= C[i] * (day - last[i]);
  }
  return score;
}

int main(){
  input();
  
  long long score = 0;
  vector<long long> last(type,-1), V(0);
  vector<priority_queue<STR>> Q(2);
  STR s = {score,V,last};
  Q[0].push(s);
  for(int i=0;i<D;i++){
    while(!Q[(i+1)%2].empty()) Q[(i+1)%2].pop();
    for(int j=0;j<50;j++){
      if(Q[i%2].empty()) break;
      STR str = Q[i%2].top();
      Q[i%2].pop();
      
      for(int k=0;k<type;k++){
        long long x = calc(i,k,str.last);
        vector<long long> y = str.last, z = str.ans;
        y[k] = i;
        z.push_back(k);
        STR str2 = {x,z,y};
        Q[(i+1)%2].push(str2);
      }
    }
  }
  
  vector<long long> ans = Q[D%2].top().ans;
  for(int i=0;i<D;i++) cout << ans[i]+1 << endl;
  return 0;
}


Measured memory_bytes: 12652
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b[110000],cnt=0;
string s;
signed main()
{
	cin>>a>>s;
	rep(i,a-1){
		if(s[i]!=s[i+1]){
			cnt++;
		}
	}
	cout<<cnt+1;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> d(100001);
	rep(i, n) {
		cin >> a[i];
		d[a[i]]++;
		if (a[i] != 0) { d[a[i] - 1]++; }
		d[a[i] + 1]++;
	}
	sort(a.begin(), a.end());
	int ans = 0;
	for (int i = 0; i <= a[n-1];i++) {
		ans = max(ans, d[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
N = int(input())
towns = []
for i in range(N):
    town = list(map(int, input().split(" ")))
    towns.append(town)

def distance(town1,town2):
    x1,y1 = town1
    x2,y2 = town2
    return ((x1-x2)**2 + (y1-y2)**2)**0.5

total_distance = 0

for i in range(0, len(towns)):
    town1 = towns[i]
    for j in range(0, len(towns)):
        if i != j:
            town2 = towns[j]
            total_distance += distance(town1,town2)

avg_distance = (1/N)*total_distance
print(avg_distance)


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

int main(){
	int N, X;
	cin >> N >> X;
	int ans = 0;
	int D = 0;
	for (int i = 0; i < N; i++)
	{
		if (D <= X) ans++;
		int L;
		cin >> L;
		D += L;
	}
	if (D <= X) ans++;
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define ff first
#define ss second
#define pb push_back
using namespace std;

void solve(int test){
	int x;
	cin>>x;
	cout<<(!x)<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1,k;
	//cin>>t;
	k = t;
	while(t--){
		solve(k - t);
	}
	cerr<<"Timpe elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " mps\n" ;
	return 0;
}

Measured memory_bytes: 3812
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;

const int MAXN = 123;
const int MAXM = 1234;
const int INF = 2100000000;

struct edge
{
    int to;
    int cost;
};

struct status
{
    int id;
    int acv;
    int cost;
    bool operator < (struct status t) const
    {
        return acv > t.acv;
    }
};

int dp[MAXN][MAXM], n, m, c;
int vis[MAXN][MAXM];
vector<edge> G[MAXN];

int dij()
{
    memset(dp, inf, sizeof dp);
    memset(vis, 0, sizeof vis);
    dp[1][0] = 0;
    int ans;
    priority_queue< status > heap;//?????????£?¬?????????±??
    heap.push((status)
    {
        1, 0, 0
    });
    while(!heap.empty())
    {
        status u = heap.top();
        heap.pop();
        vis[u.id][u.cost] = 1;
        if(u.cost > m) continue;
        for(int i = 0; i < G[u.id].size(); i++)
        {
            edge e = G[u.id][i];
            if(dp[e.to][u.cost] > dp[u.id][u.cost] + e.cost && !vis[e.to][u.cost])
            {
                dp[e.to][u.cost] = dp[u.id][u.cost] + e.cost;
                heap.push((status)
                {
                    e.to, dp[e.to][u.cost], u.cost
                });
            }
            if(dp[e.to][u.cost + 1] > dp[u.id][u.cost] && !vis[e.to][u.cost + 1])
            {
                dp[e.to][u.cost + 1] = dp[u.id][u.cost];
                heap.push((status)
                {
                    e.to, dp[e.to][u.cost + 1], u.cost + 1
                });
            }
        }
    }

    /*printf("\n");
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            printf("%d ",dp[i][j]);
        }
        printf("\n");
    }*/

    for(int j = 0; j <= m; j++)
    {
        if(dp[n][j] < c)
        {
            ans = j;
            break;
        }
    }

    return ans;
}

int main()
{
    while(~scanf("%d%d%d", &n, &m, &c), n + m + c)
    {
        for(int i=0;i<=n;i++) G[i].clear();
        for(int i = 0; i < m; i++)
        {
            int tx, ty, tc;
            scanf("%d%d%d", &tx, &ty, &tc);
            G[tx].push_back((edge)
            {
                ty, tc
            });
        }
        printf("%d\n", dij());
    }
    return 0;
}

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

int read(){
	int a = 0; char c = getchar(); while(!isdigit(c)) c = getchar();
	while(isdigit(c)){a = a * 10 + c - 48; c = getchar();} return a;
}

const int _ = 1e5 + 7;
long long N , dp[_][2] , val[_][2] , cnt;

int main(){
	N = read(); val[0][1] = read();
	for(int i = 1 ; i < N ; ++i) if(getchar() == '-') val[++cnt][0] = read(); else val[cnt][1] += read();
	memset(dp , -0x3f , sizeof(dp)); dp[0][0] = 0;
	for(int i = 1 ; i <= cnt ; ++i){
		dp[i][0] = max(dp[i - 1][0] , dp[i - 1][1]) + val[i][1] - val[i][0];
		dp[i][1] = max(dp[i - 1][0] - val[i][0] - val[i][1] , dp[i - 1][1] + val[i][0] + val[i][1]);
	}
	cout << max(dp[cnt][0] , dp[cnt][1]) + val[0][1];
	return 0;
}

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

int order_2(int n){
  int ans=0;
  while(n%2==0){
    n/=2;
    ans++;
  }
  return ans;
}

string bit(int n){
  if(n==0){
    return "0";
  }
  else{
    string ans="";
    while(n>0){
      char c='0'+n%2;
      n/=2;
      ans=c+ans;
    }
    return ans;
  }
}
  
int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  int k=0;
  for(int i=0;i<n;i++){
    k=k^a[i];
    a[i]=order_2(a[i]);
  }
  int ans=0;
  bool check=true;
  sort(a,a+n);
  string s=bit(k);
  int p=s.size();
  for(int i=0;i<p;i++){
    if(s[i]=='1'){
      if(binary_search(a,a+n,p-i-1)==false){
        check=false;
      }
      else{
        ans++;
        for(int j=i+1;j<p;j++){
          if(s[j]=='1'){
            s[j]='0';
          }
          else{
            s[j]='1';
          }
        }
      }
    }
  }
  if(check) cout << ans << endl;
  else cout << -1 << endl;
}

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

using namespace std;

long long F(long long A, long long B) {
    long long n = max(A, B);
    long long ret = 0;
    while (n > 0) {
        n /= 10LL;
        ++ret;
    }
    return ret;
}

void Main() {
    long long N;
    cin >> N;

    set<long long> factors;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            factors.insert(i);
            factors.insert(N / i);
        }
    }
    long long ans = 1000000000000000000LL;
    for (long long l : factors) {
        long long f = F(l, N / l);
        ans = min(ans, f);
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3676
/* Never Say Die */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double D;
typedef pair<int, int> pii;
#define mp(a, b) make_pair(a, b)
#define fir first
#define sec second
inline int min(int a, int b) {return a < b ? a : b;}
inline int max(int a, int b) {return a > b ? a : b;}
int ch = 0;
template <class T> inline void read(T &a) {
	bool f = 0; a = 0;
	while (ch < '0' || ch > '9') {if (ch == '-') f = 1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {a = a * 10 + ch - '0'; ch = getchar();}
	if (f) a = -a;
}

int N, M, n, m;

#define D 100000

bool solve() {
	LL tot = 0;
	int nega = -n * m - D * (n + m - 1 - (n == 1) - (m == 1));
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			tot += i % n == 0 && j % m == 0 ? nega : ((i - 1) % n == 0 || (j - 1) % m == 0 ? D + 1 : 1);
		}
	}
	return tot > 0;
}


int main() {
	read(N); read(M); read(n); read(m);
	if (n == 1 && m == 1) return puts("No"), 0;
	if (solve()) {
		puts("Yes");
		int nega = -n * m - D * (n + m - 1 - (n == 1) - (m == 1));
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= M; j++) {
				printf("%d%c", i % n == 0 && j % m == 0 ? nega : ((i - 1) % n == 0 || (j - 1) % m == 0 ? D + 1 : 1), j == M ? '\n' : ' ');
			}
		}
	}
	else puts("No");
	return 0;
}




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

int main() {
	//code
	ll n;
	cin>>n;
	int x=n;
	ll a[100000];
    ll dp[100000];
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++){
	    cin>>a[i];
	}
	//cout<<fun(a,n,dp)<<endl;
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++){
	    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1]<<endl;
	return 0;
}


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

int main(){
    while (1){
	int n;
	int a = 0, b = 0;
	cin >> n;
	if (n == 0) break;
	int r, l;
	for (int i = 0; i < n; i++){
	    cin >> l >> r;
	    if (l == r){
		a += l;
		b += r;
	    }
	    else if (l > r){
		a += l + r;
	    }
	    else if (r > l){
		b += l + r;
	    }
	}
	cout << a << " " << b << endl;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int N, M;
bool graph[60][60];
bool seen[60];
set<pair<int, int>> ans;

void dfs(int ra, int rb, int cp = -1) {
    // printf("ra=%d, rb=%d, cp=%d ", ra, rb, cp);
    
    if (cp == -1) {
        //printf("-> skip\n");
        rep(i, N) seen[i] = false;
        seen[0] = true;
        
        rep(i, N) {
            if (
                ((ra != 0) || (rb != i)) &&
                (graph[0][i])
            ) {
                dfs(ra, rb, i);
            }
        }
        
        return;
    }
    else if (seen[cp]) {
        // printf("-> skip\n");
        return;
    }
    
    // printf("-> continue\n");
    seen[cp] = true;
    
    rep(i, N) {
        if (
            ((cp != ra) || (i != rb)) &&
            (graph[cp][i])
        ) {
            dfs(ra, rb, i);
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N >> M;
    rep(i, N) rep(ii, N) graph[i][ii] = false;
    
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a][b] = graph[b][a] = true;
    }
    
    rep(i, N) {
        rep(ii, N) {
            if (graph[i][ii]) {
                dfs(i, ii);
                
                // printf("(%d, %d) ", i, ii);
                // rep(iii, N) {
                //     printf("%d ", seen[iii] ? 1 : 0);
                // }
                // printf("\n");
                
                rep(iii, N) {
                    if (!seen[iii]) {
                        ans.insert(pair<int, int>(min(i, ii), max(i, ii)));
                        break;
                    }
                }
            }
        }
    }
    
    // rep(i, N) {
    //     rep(ii, N) {
    //         printf("%s%s", graph[i][ii] ? "#" : ".", ((ii == (N - 1)) ? "\n" : " "));
    //     }
    // }
    
    cout << sz(ans) << endl;
    return 0;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;

    if(a > b){
        if(b > c){
            cout << b + c << endl;
        }else{
            if(a > c){
                cout << b + c << endl;
            }else{
                cout << a + b << endl;
            }
        }
    }else{
        if(a > c){
            cout << a + c << endl;
        }else{
            if(b > c){
                cout << a + c << endl;
            }else{
                cout << a + b << endl;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  long long int N, K;
  cin >> N >> K;
  vector<long long int> w(N), d(N);
  for(int i = 0; i < N; ++i){
    cin >> w[i] >> d[i];
  }
  unsigned long long int ng = 0LL, ok = 4E18+1LL;
  while(ok-ng > 1){
    unsigned long long int m = (ok+ng)/2LL, t = 0LL;
    for(int i = 0; i < N; ++i){
      if(m >= w[i]){
        t += (m - w[i])/d[i] + 1LL;
        if(t >= K) break;
      }
    }
    if(t >= K) ok = m;
    else ng = m;
  }
  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l = sc.nextInt();
        
        long[][] a = new long[n][m];
        long[][] b = new long[m][l];
        long[][] c = new long[n][l];
        
        for(int i = 0;i < n;i++){
            for(int j = 0;j<m;j++){
                
                a[i][j] = sc.nextInt();
  	          }
   	     }
        
        
        for(int i = 0;i < m;i++){
            for(int j = 0;j<l;j++){
                
                b[i][j] = sc.nextInt();
  	          }
   	     }
        
        for(int i = 0 ;i<n;i++){
            for(int j=0;j<l;j++){
                for(int k =0;k<m;k++){
                    c[i][j] += a[i][k]*b[k][j];
                }
            }
        }
        
        for(int i = 0; i < n; i++){
            for(int j = 0; j < l; j++){
                System.out.print(c[i][j]);
                if(j != l-1) System.out.print(" ");
            }
            System.out.println();
        }
    }
} 



Measured memory_bytes: 53156
#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 A,B;
    cin >> A >> B;
    cout << max({A+B, A-B, A*B});
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int x,y,z,i,c=0;
    scanf("%d%d%d",&x,&y,&z);
    if(x>y){
        for(i=y;i<=x;i++){
            if(z%i==0)
                c++;
        }
    }
    else if(x<y){
            for(i=x;i<=y;i++){
            if(z%i==0)
                c++;
        }

    }
    else if(x==y){

            if(z%x==0)
                c++;
    }
    printf("%d\n",c);
}



Measured memory_bytes: 2128
#include <stdio.h>

int isPrime(int k);

int main() {
    int n, k, count = 0;

    scanf("%d", &n);

    for (int i = 0; i < n; ++i) {
        scanf("%d", &k);

        if (isPrime(k))
            count++;
    }

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

    return 0;
}

int isPrime(int k) {
    if (k == 2) {
        return 1;
    } else if (k % 2 == 0){
        return 0;
    }

    for (int i = 3; i < k && i <= 10000; i+=2) {
        if (k % i == 0)
            return 0;
    }
    return 1;
}


Measured memory_bytes: 2040
#include <cstdio>
#include <algorithm>
using namespace std;
int X, Y;
char flag[50][51];
int answer;
int sit[50][3];
int note[50][3];

inline int russia(char x){
	if (x == 'B')return 0;
	if (x == 'W')return 1;
	if (x == 'R')return 2;

}

int f(int x,int color){
	if (x == 0){
		if (color == 1)return sit[0][0] + sit[0][2];
		else return 100000000;
	}

	if (note[x][color] != 0)return note[x][color];
	//if (x == Y - 1)return note[x][color] = min(f(x - 1, 0), f(x - 1, 2)) + sit[x][0] + sit[x][1];
	if (color == 0)return note[x][color] = min(f(x - 1, 0), f(x - 1, 1)) + sit[x][1] + sit[x][2];
	if (color == 1)return note[x][color] = f(x - 1, 1) + sit[x][2] + sit[x][0];
	if (color == 2)return note[x][color] = min(f(x - 1, 2), f(x - 1, 0)) + sit[x][1] + sit[x][0];

	return 100000000;
}

int main(){
	scanf("%d %d", &Y, &X);
	for (int i = 0; i < Y; ++i){
		scanf("%s", &(flag[i]),X);
		for (int x = 0; x < X; ++x){
			sit[i][russia(flag[i][x])] += 1;
		}
	}
	printf("%d\n", f(Y - 1, 2));


	return  0;
}

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

int analyze (vector<int> weights)
{
  int minDiff = 99 * 100 - 1; // 重さの最小値の最大値
  int diff = 0;
  
  for (int i = 0; i < weights.size(); i++)
  {
    int weightSumA = 0;
    int weightSumB = 0;
    
    int j;
    for (j = 0; j < i; j++)
    {
      weightSumA += weights.at(j);
    }
    for (j = i; j < weights.size(); j++)
    {
      weightSumB += weights.at(j);
    }
    diff = weightSumA - weightSumB;
    if (diff < 0) diff *= -1;
    
    if (diff < minDiff) minDiff = diff;
  }
  
  return minDiff;
}

int main() {
  int N;
  cin >> N;
  vector<int> weights(N);

  for (int i = 0; i < N; i++)
  cin >> weights.at(i);
  
  cout << analyze(weights) << endl;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long n, t;
    cin >> n >> t;
    vector <long long> vec(n+1);
    for (long long l=0; l<n; l++)
        cin >> vec[l];
    long long ans = t * n;
    for (long long l=1; l<n; l++)
        if (vec[l] - vec[l-1] < t)
            ans -= vec[l-1] + t - vec[l];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
def main():
    s = input()
    k = int(input())
    count = 0
    last_num = 0
    for i in s:
        if i == '1':
            count += 1 
        else:
            last_num = i
            break
    if k > count:
        print(last_num)
    else:
        print(1)
if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define ll long long
#define mem(x) memset(x,0,sizeof(x))
#define sca(x) scanf("%d",&x)
#define scall(x) scanf("%lld",&x)
ll a[200005];
int main()
{
	int n,k;cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=k+1;i<=n;i++)
	{
		if(a[i]>a[i-k])
		cout<<"Yes"<<endl;
		else
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 5324
#EDP-F
import sys

S = sys.stdin.readline().rstrip()
T = sys.stdin.readline().rstrip()
sn, tn = len(S), len(T)
dp = [[0 for j in range(tn)] for i in range(sn)]

#方針:その時点での最長数を入れる
for j in range(tn):
    dp[0][j] = dp[0][j-1]
    if S[0]==T[j]:
        dp[0][j] = 1
for i in range(sn):
    dp[i][0] = dp[i-1][0]
    if S[i]==T[0]:
        dp[i][0] = 1
        

for i in range(1, sn):
    for j in range(1, tn):
        if S[i] == T[j]:
            dp[i][j] = dp[i-1][j-1]+1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

#pprint.pprint(dp)

i,j= sn-1, tn-1
ans =''
while True:
    if i ==0:
        if dp[i][j]==1:
            ans+= S[0]
        print(ans[::-1])
        break
    if j ==0:
        if dp[i][j]==1:
            ans+= T[0]
        print(ans[::-1])
        break
    if dp[i-1][j] == dp[i][j]:
        i-=1
    elif dp[i][j-1] == dp[i][j]:
        j-=1
    elif dp[i-1][j-1] +1 == dp[i][j]:
        ans += S[i]
        i-=1
        j-=1

Measured memory_bytes: 119900
#include <iostream>

using namespace std;

string s;

void solve() {
  int cnt = 0;
  char prev = s[0];
  for (int i=0;i<s.size();i++) {
    if (prev != s[i]) {
      cnt++;
      prev = s[i];
    }
  }
  cout << cnt << endl;
}

int main() {
  cin >> s;
  solve();
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,t,n,m,q,k,i,j;
    // cin>>T;
    while(T--)
    {
        cin>>n;
        string st;
        cin>>st;
        k=0;q=0;
        FOR(i,0,n)
        {
            if(st[i]=='R')
                k++;
            else
                q++;
        }
        i = 0;
        j = n - 1;
        ll res=0;
        while(i<j)
        {
            if(st[i]=='W'&&st[j]=='R'){
                res++;
                i++;
                j--;
            }
            if(st[i]=='R')
                i++;
            if(st[j]=='W')
                j--;
        }
        res = min(min(k,q),res);
        cout<<res<<endl;
    }
}

Measured memory_bytes: 3764
#include<iostream>

#define MAX_N 1000

int main(){
  int n,m;
  int a[MAX_N] = {};
  while(1){
    std::cin >> n >> m;
    if(n == 0&&m==0) break;
    int max;
    for(int i=0;i<n;i++){
      std::cin >> a[i];
    }
    max = 0;
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
	if(max < a[i]+a[j] && a[i]+a[j] <= m){
	  max = a[i]+a[j];
	  if(max == m) break;
	}
      }
    }
    if(max == 0){
      std::cout << "NONE\n";
    }else{
      std::cout << max << '\n';
    }
  }
  return 0;
}



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

int main(void) {
	long int n, sum = 0;
	cin >> n;
	vector<long int> a(n,0);

	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	sort(a.begin(), a.end(), greater<int>());

	for (int i = 0; i < n; i++) {
		sum = sum + a[i];
	}

	cout << a[n - 1] << " " << a[0] << " " << sum << endl;

	return 0;
}

Measured memory_bytes: 1296
#include <stdio.h>

int main(void)
{
    char op;
    long long int A, B;

    scanf("%lld %c %lld",&A, &op, &B);

    if(op == '+'){
        printf("%lld\n",A+B);
    } else {
        printf("%lld\n",A-B);
    }
    
    return 0;
}

Measured memory_bytes: 1712
#include <algorithm>
#include <functional>
#include <iostream>
#include <set>
#include<iomanip>
#include<queue>
#include <cstdint>
#include <string>


using namespace std;


int main() {
	string s;
	cin>>s;
	int min_number = 9999;
	int length = s.length();
	for(int i=0;i<=length-3;i++){
		string part = s.substr(i,3);
		int num = stoi(part);
		if(abs(num-753)<min_number){
			min_number=abs(num-753);
		}

	}
	cout<<min_number<<endl;


	return 0;

}


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

struct Node{
	long key;
	Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(long k){
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = new Node;
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL){
		y = x;
		if (z->key < x->key) x = x->left;
		else x = x->right;
	}
	z->parent = y;

	if (y == NIL) root = z;
	else {
		if (z->key < y->key) y->left = z;
		else y->right = z;
	}
}

void inorder(Node *u){
	if (u == NIL) return;
	inorder(u->left);
	cout << " " << u->key;
	inorder(u->right);
}

void preorder(Node *u){
	if (u == NIL) return;
	cout << " " << u->key;
	preorder(u->left);
	preorder(u->right);
}

long find(Node *u, long x){
	if (u == NIL) return 0;
	if (u->key == x) return 1;
	else if (u->key > x) return find(u->left, x);
	else return find(u->right, x);
}

int main(){
	long n, x;
	string com;
	cin >> n;
	for (long i = 0; i < n; i++){
		cin >> com;
		if (com == "insert"){
			cin >> x;
			insert(x);
		}
		else if (com == "print"){
			inorder(root);
			cout << endl;
			preorder(root);
			cout << endl;
		}
		else {
			cin >> x;
			if (find(root, x)) cout << "yes" << endl;
			else cout << "no" << endl;
		}
	}
	return 0;
}

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

int N;
vector<int> S;

int main() {
    scanf("%d", &N);
    S.resize(N);
    int mn = 1e9;
    int sum = 0;
    for(int i = 0; i < N; i++) {
        scanf("%d", &S[i]);
        if(S[i] % 10) mn = min(mn, S[i]);
        sum += S[i];
    }
    if(sum % 10) printf("%d", sum);
    else if(mn != 1e9) printf("%d", sum - mn);
    else printf("0");
}


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

int main(){
    int n;
    cin >> n;
    long long a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    for(int  i=1;i<n;i++){
        if(a[0]>1000000000000000000/a[i]){
            cout << -1 << endl;
            return 0;
        }
        else{
            a[0] *= a[i];
        }
    }
    cout << a[0] << endl;
}

Measured memory_bytes: 4404
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main() {
  int q = in();
  map<string, int> m;
  while (q--) {
    int t = in();
    if (t == 0) {
      string k;
      int x;
      cin >> k >> x;
      m[k] = x;
    }
    if (t == 1) cout << m[in<string>()] << endl;
    if (t == 2) m.erase(in<string>());
  }
}



Measured memory_bytes: 27872
#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>;
using G = vector<vector<int>>;
    
int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n){
        int in;
        cin >> in;
        in--;
        p[i] = in;
    }
    vector<ll> c(n);
    rep(i,n) cin >> c[i];

    
    vector<vector<ll>> dp(n, vector<ll>(n+1));
    vector<ll> anss(n, -2000000000);
    rep(i,n){
        int move = p[i];
        int maxj;
        bool flag = false;
        int cycle = 0;
        for(int j=1; j<=n; j++){
            if(j>k) break;
            dp[i][j] = dp[i][j-1]+c[move];
            //else dp[i][j] = max(dp[i][j-1], dp[i][j-1]+c[move]);
            move = p[move];
            if(dp[i][j]>anss[i]){
                anss[i] = dp[i][j];
                maxj = j;
            }
            //anss[i] = max(anss[i], dp[i][j]);
            cycle++;
            if(flag){
                if(dp[i][j]<=0) break;
                else{
                    int ind = k / cycle;
                    //ind--;
                    for(int l=(ind-1)*cycle+1; l<=ind*cycle; l++){
                        anss[i] = max(anss[i], dp[i][j]*(ind-1) + dp[i][l-(ind-1)*cycle]);
                    }
                    for(int l=(ind)*cycle+1; l<=k; l++){
                        anss[i] = max(anss[i], dp[i][j]*(ind) + dp[i][l-(ind)*cycle]);
                    }

                    break;
                }
            }
            if(move==i) flag = true;
        }
    }
    ll ans = *max_element(anss.begin(), anss.end());
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 199204
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{
    cout<<fixed<<setprecision(10);
    double h,m,a,b;
    cin>>a>>b>>h>>m;
    double theta=(((h+m/60)*30-m*6)/(double)180.0)*(acos(-1));
    cout<<sqrtl(a*a+b*b-2*a*b*cos(theta));
}


Measured memory_bytes: 4204
use std::io;
use std::cmp;

fn main() {
    let n: u32 = getline().trim().parse::<u32>().unwrap();
    let k: u32 = getline().trim().parse::<u32>().unwrap();
    let sum_min = getline().trim().split_whitespace()
        .map(|x| x.parse::<u32>().unwrap())
        .fold(0, |sum, x| sum + (cmp::min(x, k-x) * 2));

    println!("{}", sum_min);
}

fn getline() -> String {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();

    return line;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main() {
	char ch;
	long long n,q,u,v;
	map<long long, long long> m;
	scanf("%lld",&n);
	long long a[n+1];
	long long sum=0;
	
	for(int i=0;i<n;i++) scanf("%lld",&a[i]),m[a[i]]++, sum+=a[i];
	scanf("%lld",&q);
	while(q--) {
		scanf("%lld %lld",&u,&v);
		sum-=m[u]*u;
		sum+=m[u]*v;
		m[v]+=m[u];
		m[u]=0;
		//printf("%lld %lld\n",m[u],m[v]);
		printf("%lld\n",sum);
	}
}

Measured memory_bytes: 10480
#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include <map>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define rush() int T;scanf("%d",&T);while(T--)
#define f(i,a,b) for(int i=a;i<=b;i++)

typedef long long ll;
const int maxn = 1005;
const ll mod = 1e9+7;
const ll INF = 1e15;
const double eps = 1e-9;

int n,m,r;
ll dis[maxn][maxn];
int place[maxn];

void floyd()
{
    for(int k=1;k<=n;k++)
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    {
        dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
    }
}


ll solve(int *a)
{
    int pre=a[0];
    ll cnt=0;
    for(int i=1;i<r;i++)
    {
        int now=a[i];
        cnt+=min(dis[pre][now],dis[now][pre]);
        pre=now;
    }
    return cnt;
}

int main()
{
    while(~scanf("%d%d%d",&n,&m,&r))
    {
        for(int i=0;i<r;i++)
        {
            scanf("%d",&place[i]);
        }
        for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            if(i==j) dis[i][j]=0;
            else dis[i][j]=INF;
        }
        int x,y,w;
        for(int i=0;i<m;i++)
        {
            scanf("%d%d%d",&x,&y,&w);
            if(dis[x][y]>(ll)w)
            {
                dis[x][y]=dis[y][x]=(ll)w;
            }
        }
        sort(place,place+r);
        floyd();
        ll ans=INF;
        do
        {
            ans=min(ans,solve(place));
        }
        while(next_permutation(place,place+r));
        printf("%lld\n",ans);
    }
    return 0;
}


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

int main(){
    int a,b,c;
    cin >> a >> b >> c;

    int ans=0;
    for(int i=a;i<=b;++i){
        if(c%i==0){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int N,M;
  cin>>N>>M;
  int a;
  int ans=0;
  for(int i=0;i<M;i++){
    cin>>a;
    if(a>M)ans++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3136
#include<cstdio>
using namespace std;
int main()
{
    int m,n;
    scanf("%d %d",&m,&n);
    if(m*10000<n||m*1000>n||n%1000!=0){printf("-1 -1 -1");return 0;}
    for(int i=0;i<=m;i++)
     for(int j=0;j<=m;j++)
      for(int k=0;k<=m,i+j+k<=m;k++)
       {
            if(i+j+k==m&&i*1000+j*5000+k*10000==n)
            {
                printf("%d %d %d",k,j,i);
                return 0;   
            }
       }
    printf("-1 -1 -1");
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
int main(void)
{
	int n, s[1000], i;
	double SD, sum1, sum2, m;
	while(scanf("%d", &n), n != 0){
		sum1=sum2=0;
		for(i=0; i<n; i++){
			scanf("%d", &s[i]);
			sum1 += s[i];
		}
		m = sum1 / n;
		for(i=0; i<n; i++){
			sum2 += (s[i]-m)*(s[i]-m);
		}
		SD = sqrt(sum2 / n);
		printf("%f\n", SD);
	}
	return 0;
}

Measured memory_bytes: 636
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
class UnionFindTree {
	int[] parent; //インデックスにとノードを対応させ、そのルートノードのインデックスを格納	
	int[] rank; //parentと同様に、木の高さを格納
	int[] size;
	public UnionFindTree(int n) {
		this.parent = new int[n];
		this.rank = new int[n];
		this.size = new int [n];
		for (int i = 0; i < n; i++) {
			makeSet(i);
		}
	}
	
	public void makeSet(int i) {
		parent[i] = i;
		rank[i] = 0; //集合の高さ
		size[i] = 1;
	}
	
	public void union(int x, int y) {
		int xRoot = find(x);
		int yRoot = find(y);
		
		//xが属する木の方が大きい場合
		if (rank[xRoot] > rank[yRoot]) { 
			parent[yRoot] = xRoot; //yの親をxに更新 
			size[xRoot] += size[yRoot];
								   
		} else if(rank[xRoot] < rank[yRoot]) {
			parent[xRoot] = yRoot;
			size[yRoot] += size[xRoot];
			
		} else if (xRoot != yRoot){
			parent[yRoot] = xRoot;
			size[xRoot] += size[yRoot];
			rank[xRoot]++; //同じ高さの木がルートの子として着くから大きさ++;
		}
	}
	
	//引数の属する木のルートのidを返す
	public int find(int i) {
		if (i != parent[i]) {
			parent[i] = find(parent[i]);
		}
		return parent[i];
	}
	
	//同じ木に属しているか
	public boolean same(int x, int y) {
		return find(x) == find(y);
	}
	
	//木のsize取得
	public int getsize(int i) {
		return size[find(i)];
	}

}
 
public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
		int n = sc.nextInt();
		int m = sc.nextInt();
		UnionFindTree tree = new UnionFindTree(n);
		for(int i = 0; i < m; i++) {
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			tree.union(a,b);
		}
		int max = 0;
		for(int i = 0; i < n; i++) {
			if(max<tree.getsize(i))max = tree.getsize(i);
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 62028
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(obj) sort((obj).begin(), (obj).end())

/***** MAIN *****/
signed main() {
  int n;
  cin >> n;
  vector<int> v(n);
  REP(i, n) cin >> v[i];
  if(n%2 != 0) {
    cout << "0\n";
    return 0;
  }
  SORT(v);
  cout << v[n/2] - v[n/2-1];
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 768
n = int(input())
c = []
for _ in range(n):
    c.append(list(map(int,input().split())))

ans = 0
a = 100000000000000
m = 0
lm = 0
rm = 0
lt  = []
rt  = []
lb = []
rb = []

for l in c:
    m = max(m,l[0]+l[1])
    a = min(a,l[0]+l[1])
    if l[0] > l[1]:
        rm = max(rm,l[0]-l[1])
    if l[0] < l[1]:
        lm = max(lm,l[1]-l[0])

for l in c:
    if l[0] + l[1] == m:
        rt.append(l)
    if l[0] + l[1] == a:
        lb.append(l)
    if l[0] > l[1] and l[0] - l[1] == rm:
        rb.append(l)
    if l[0] < l[1] and l[1] - l[0] == lm:
        lt.append(l)


if len(lt)>0 and len(rb) > 0:
    i = lt[0]
    j = rb[0]
    ans = max(ans,abs(i[0]-j[0])+abs(i[1]-j[1]))

if len(rt)>0 and len(lb) > 0:
    i = rt[0]
    j = lb[0]
    ans = max(ans,abs(i[0]-j[0])+abs(i[1]-j[1]))
print(ans)




Measured memory_bytes: 50204
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,ll,ll> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> P;
int N,Q;
string road="0";
char T[200005];
char D[200005];
int lmax=0;
int rmin=200005;

int main(void)
{
  cin >> N >> Q;
  string tmp;
  cin >> tmp;
  road+=tmp;
  road+='0';
  for(int i=0;i<Q;i++)
    {
      char t,d;
      cin >> t >> d;
      T[i]=t;
      D[i]=d;
    }
  int l=0,r=N+1;
  while(r-l>1)
    {
      int mid=(l+r)/2;
      int nowindex=mid;
      char nowpoint=road[nowindex];
      for(int i=0;i<Q;i++)
	{
	  if(nowpoint==T[i])
	    {
	      if(D[i]=='L')
		{
		  nowindex--;
		  nowpoint=road[nowindex];
		}
	      else
		{
		  nowindex++;
		  nowpoint=road[nowindex];
		}
	    }
	  if(nowindex==0)
	    {
	      l=mid;
	      break;
	    }
	}
      if(nowindex!=0)
	{
	  r=mid;
	}
    }
  lmax=l;
  l=0,r=N+1;
  while(r-l>1)
    {
      int mid=(l+r)/2;
      int nowindex=mid;
      char nowpoint=road[nowindex];
      for(int i=0;i<Q;i++)
	{
	  if(nowpoint==T[i])
	    {
	      if(D[i]=='L')
		{
		  nowindex--;
		  nowpoint=road[nowindex];
		}
	      else
		{
		  nowindex++;
		  nowpoint=road[nowindex];
		}
	    }
	  if(nowindex==N+1)
	    {
	      r=mid;
	      break;
	    }
	}
      if(nowindex!=N+1)
	{
	  l=mid;
	}
    }
  rmin=l;
  cout << rmin-lmax << endl;
  return 0;
}



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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int cnt = 0, sum = 0;
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep (i, n) {
        cin >> a[i];
        sum += a[i];
    }
    sort(a.rbegin(), a.rend());
    rep (i, n) {
        if (a[i] >= ((sum + 4 * m - 1) / (4 * m))) cnt++;
    }
    if (cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

const long long MOD = 1000000007;

int main(){
  int n,t;
  int na=0,ma=0;
  cin >> n;
  vector<int> a(n);
  vector<set<int>> aa(200001);
  rep(i,n){
    cin >> t;
    a.at(i)=t;
    aa.at(t).insert(i);
    if(t>ma){
      na=ma;
      ma=t;
    }
    else if(t>na){
      na=t;
    }
  }
  if(aa.at(ma).size()==1){
    rep(i,n){
      if(a.at(i)==ma) cout << na <<endl;
      else cout << ma <<endl;
    }
  }
  else{
    rep(i,n) cout << ma << endl;
  }
}


Measured memory_bytes: 21120
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int N,K;
    string S;
    cin>>N>>K>>S;
    REP(i,N){
        if(i==K-1){
            printf("%c",tolower(S[i]));
        } else {
            printf("%c",S[i]);
        }
    }
    cout<<endl;
}

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;
typedef pair<int, int> P;

int main() {
  long long l, r; cin >> l >> r;
  long long mod = 2019;
  bool frag = false;
  long long minNum = -1;

  for (long long i = l; i < r+1; i++)
  {
    if(i % mod == 0) {
      frag = true;
      break;
    }
  }

  if(!frag){
    for (long long i = l; i < r+1; i++)
    {
      for (long long j = i+1; j < r+1; j++)
      {
        if(minNum == -1){
          minNum = (i%mod) * (j%mod) % mod;
        } else {
          minNum = min(minNum, (i%mod) * (j%mod) % mod);
        }
      }
      
    }
    
  }
    
  if(frag){
    cout << 0 << endl;
  } else {
    cout << minNum << endl;
  }
  
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = int(1e9) + 7;

#define int i64

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

  int n, m;
  cin >> n >> m;

  vector<int> a(n+5), b(n+5);
  reps(i, 1, n) cin >> a[i] >> b[i];

  vector<int> c(m+5), d(m+5);
  reps(i, 1, m) cin >> c[i] >> d[i];

  reps(i, 1, n) {
    vector<pii> res;
    reps(j, 1, m) {
      int x = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      res.push_back(pii(x, j));
    }
    sort(all(res));
    cout << res[0].second << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n)   for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(long long i=(a);((a)<(b)?i<=(b):i>=(b));((a)<(b)?++i:--i))
#define SZ(v)      ((int)(v).size())
#define ALL(v)     (v).begin(),(v).end()
#define debug(x)   cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}

int main(){
	string s,t;
	cin>>s>>t;
	
	int sn=s.size(), tn=t.size();
	
	int ans=INF;
	REP(i,sn-tn+1){
		int tmp=0;
		REP(j,tn){
			if(s[i+j]==t[j]){}
			else tmp++;
		}
		ans=min(ans,tmp);
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main(){
    int r,o,g;
    cin>>r>>o>>g;
    if(r==o&&g!=o){cout<<g;}
    if(g==o&&g!=r){cout<<r;}
    if(r==g&&g!=o){cout<<o;}















return 0;}


Measured memory_bytes: 256
//#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
string S[200001];
int saizu[200001];
int firsta[200001][26];
int alphanum[26]={};
vector<pair<string,int> > rsi;
int main(){
	int N;
	scan(N);
	fill(firsta[0],firsta[200001],INF);
	rep(i,N){
		scan(S[i]);
		saizu[i]=S[i].size();
		rep(j,S[i].size()){
			firsta[i][S[i][j]-'a']=min(firsta[i][S[i][j]-'a'],j);
		}
		rep(j,saizu[i]/2){
			swap(S[i][j],S[i][saizu[i]-1-j]);
		}
		rsi.push_back({S[i],i});
	}

	rep(i,N){
		if(saizu[i]>=2){
			rep(k,26){
				if(firsta[i][k]<INF){
					alphanum[k]++;
				}
			}
		}
	}
	sort(ALL(rsi));
	int ans=0;
	rep(i,N){
		string revs=rsi[i].first;
		int ind=rsi[i].second;
		int sai=saizu[ind];
		debug(i,revs,ind,sai);
		if(sai==1){
			ans+=alphanum[revs[0]-'a'];
			debug(alphanum[revs[0]-'a']);
		}
		else{
			string setu=revs.substr(0,sai-1);
			string setu2=setu+'|';
			debug(setu,setu2);
			int st1=lower_bound(ALL(rsi),make_pair(setu,-INF))-rsi.begin();
			int st2=lower_bound(ALL(rsi),make_pair(setu2,-INF))-rsi.begin();
			debug(st1,st2);
			for(int j=st1;j<st2;j++){
				int indj=rsi[j].second;
				int saij=saizu[indj];
				if(sai<saij&&firsta[indj][revs[sai-1]-'a']<=saij-sai) ans++;
			}
		}
		debug(ans);
	}
	prin(ans);
	return 0;
}


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


int main(){
    ll n, sum = 0;
    cin >> n;
    ll B[n-1 + 1], A[n + 1];
    fill_n(A, n+1, inf);
//    cout << A[0] << '\t' << A[10];
    for (ll i = 1; i <= n - 1; ++i) {
        cin >> B[i];
    }
    for (ll i = 1; i <= n - 1; ++i) {
        A[i] = min(A[i], B[i]);
        A[i+1] = B[i];
    }
    for (ll i = 1; i <= n; ++i) {
        sum += A[i];
    }
    cout << sum;






}

Measured memory_bytes: 256