akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>

const int MAX_LEN = 3000;

struct Cell {
  int i;
  int j;
};

char s[MAX_LEN + 1];
char t[MAX_LEN + 1];
int maxMatch[MAX_LEN + 1][MAX_LEN + 1];
Cell from[MAX_LEN + 1][MAX_LEN + 1];

int main() {
  scanf("%s%s", s, t);
  int sSize = strlen(s);
  int tSize = strlen(t);
  for (int i = 0; i < sSize; i++) {
    for (int j = 0; j < tSize; j++) {
      if (s[i] == t[j] && maxMatch[i + 1][j + 1] < maxMatch[i][j] + 1) {
        maxMatch[i + 1][j + 1] = maxMatch[i][j] + 1;
        from[i + 1][j + 1] = Cell{i, j};
      }
      if (maxMatch[i][j + 1] < maxMatch[i][j]) {
        maxMatch[i][j + 1] = maxMatch[i][j];
        from[i][j + 1] = Cell{i, j};
      }
      if (maxMatch[i + 1][j] < maxMatch[i][j]) {
        maxMatch[i + 1][j] = maxMatch[i][j];
        from[i + 1][j] = Cell{i, j};
      }
    }
  }
  Cell finish = Cell{0, 0};
  for (int i = 0; i <= sSize; i++)
    for (int j = 0; j <= tSize; j++)
      if (maxMatch[finish.i][finish.j] < maxMatch[i][j])
        finish = Cell{i, j};
  //printf("%d\n", maxMatch[finish.i][finish.j]);
  std::vector<char> answer;
  while (finish.i > 0 && finish.j > 0) {
    Cell prev = from[finish.i][finish.j];
    if (maxMatch[finish.i][finish.j] > maxMatch[prev.i][prev.j])
      answer.push_back(s[prev.i]);
    finish = prev;
  }
  std::reverse(answer.begin(), answer.end());
  for (char c : answer)
  	printf("%c", c);
  printf("\n");
  return 0;
}


Measured memory_bytes: 105728
#include <iostream>
#include <queue>
#include <algorithm>

#define INF (1LL<<40)
#define MAXN 200
#define WHITE 0
#define BLACK 1
#define GRAY 2
#define MAXR 8

typedef long long ll;

using namespace std;

struct NODE { int no; ll d; } typedef node;
bool operator> ( const node& x, const node& y ) { return x.d > y.d; }

class Graph{

  //struct NODE { int no; ll d; } typedef node;
  int E[MAXN][MAXN];
  ll mind[MAXN][MAXN];
  int V, M;

  //bool operator< ( const node& x, const node& y ) { return x.d < y.d; }

public:
  Graph ( int n, int m) : V(n),M(m){
    for ( int i = 0; i < V; ++i ) for ( int j = 0; j < V; ++j ) E[i][j] = -1;
    for ( int i = 0; i < M; ++i ) {
      int a,b,c;
      scanf("%d%d%d",&a,&b,&c);
      --a; --b;
      E[a][b] = E[b][a] = c;
    }
  }

  void dicstra ( int s ) {
    int color[V];
    priority_queue<node,vector<node>,greater<node>> Q;

    for ( int i = 0; i < V; ++i ) color[i] = WHITE, mind[s][i] = INF;
    color[s] = GRAY;
    mind[s][s] = 0;
    Q.push({s,mind[s][s]});

    while(!Q.empty()) {
      node top = Q.top(); Q.pop();

      if ( mind[s][top.no] != top.d ) continue;
      for ( int i = 0; i < V; ++i ) {
        if ( E[top.no][i] != -1 && color[i] != BLACK ) {
          if ( mind[s][i] > mind[s][top.no]+E[top.no][i] ) {
            mind[s][i] = mind[s][top.no]+E[top.no][i];
            if ( color[i] == WHITE ) color[i] = GRAY;
            Q.push({i,mind[s][i]});
          }
        }
      }
      color[top.no] = BLACK;
    }

  }

  void alldicstra ( void )
  {
    for ( int i = 0; i < V; ++i ) dicstra(i);
  }

  void print(void) {
    for ( int i = 0; i < V; ++i ) {
      for ( int j = 0; j < V; ++j ) printf("%ld ",mind[i][j]);
      cout << "\n";
    }
  }

  ll getsum ( int R[], int rn )
  {
    ll ans = 0;
    for ( int i = 1; i < rn; ++i ) ans += mind[R[i-1]][R[i]];
    return ans;
  }

  ll getmin ( int R[], int rn )
  {
    sort(R, R+rn);

    ll min = getsum(R,rn);
    do {
      ll tmp = getsum(R,rn);
      if ( min > tmp ) min = tmp;
    } while(next_permutation(R, R+rn));

    return min;
  }
};

int main()
{
  int VR[MAXR];
  int N,M,R;

  cin >> N >> M >> R;
  for ( int i = 0; i < R; ++i ) {
    scanf("%d", &VR[i]);
    --VR[i];
  }

  Graph G(N,M);
  G.alldicstra();
  cout << G.getmin(VR, R) << "\n";

/*
  cout << "R[] :";
  for ( int i = 0; i < R; ++i ) cout << VR[i] << " "; cout << "\n";

  cout << "\n";
  G.print();
  */

}


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

int main(){
	vector<int>v;
  	int n,k,sum=0;
  	cin>>n>>k;
	v.resize(n);
  	for(int i=0;i<n;i++){
    	cin>>v[i];
    }
  	sort(v.begin(),v.end());
  	for(int i=0;i<k;i++){
    	sum+=v[i];
    }
  	cout<<sum<<endl;
  	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
using namespace std;
#define ll long long

int main() {
	int N, K; cin >> N >> K;
	double P=0.0, b=(double) 1/N;
	int now=1;
	for(int i=N; i>0; --i){
	    while(i*now<K) now *= 2;
	    P += b/now;
	}
	cout << setprecision(15) << P << endl;
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  vector<int> comp(N);
  for(int i=0; i<N; i++){
    cin >> v[i];
    comp[i]=v[i];
  }
  sort(comp.begin(), comp.end());
  int dif=0;
  for(int i=0; i<N; i++){
    if (comp[i]!=v[i]) dif++;
  }
  if(dif==2 || dif==0) cout <<"YES"<<endl;
  else cout <<"NO"<<endl;
  
}

Measured memory_bytes: 256
def velsup(a,b,c,x):
    if a<=x<=b:
        return c
    elif x<a:
        return (a-x)+c
    else:
        return (x-b)+c

N=int(input())
t=[int(i) for i in input().split()]
v=[int(i) for i in input().split()]
S=[0 for i in range(N+1)]
for i in range(N):
    S[i+1]=t[i]+S[i]
TT=S[N]
vt=[0 for i in range(2*TT+1)]
for tt in range(TT*2+1):
    ta=tt/2
    va=min(velsup(-1,0,0,ta),velsup(TT,TT+1,0,ta))
    for i in range(N):
        va=min(va,velsup(S[i],S[i+1],v[i],ta))
    vt[tt]=va
ans=0
for i in range(2*TT):
    ans+=(vt[i]+vt[i+1])*0.25
print(ans)


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

using namespace std;
using ll = long long;

int main(void)
{
    ll n;
    cin >> n;

    ll d0 = 1;
    for (int i = 1, m = sqrt(n); i <= m; ++i)
    {
        if (n % i == 0)
        {
            d0 = i;
        }
    }

    cout << d0 + n / d0 - 2 << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
   int  a,b,c;
   cin>>a>>b>>c;
   int k;
   cin>>k;
   
    while(b<=a&&k>0)
       {
           b*=2;
           k--;
       }
   
   
   while(c<=b&&k>0)
   {
       c*=2;
       k--;
   }
   
   if(a<b&&b<c)
   cout<<"Yes";
   else
   cout<<"No";
   return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<cstring>
#include<bitset>
using namespace std;
#define N 2002
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n;
char s[N];
bitset<N> dpL[N],dpR[N],a[N];
int main(){
	n=read();
	for(int i=2;i<=n;++i){
		scanf("%s",s+1);
		for(int j=1;j<i;++j){
			a[i][j]=s[j]-'0';
			a[j][i]=a[i][j]^1;
		}
	}
	for(int i=1;i<=n;++i){
		dpL[i][i]=dpR[i][i]=1;
	}
	for(int len=2;len<=n;++len){
		for(int l=1;l+len-1<=n;++l){
			int r=l+len-1;
			if((a[l]&dpR[l+1]&dpL[r]).any())dpL[r][l]=1;
			if((a[r]&dpR[l]&dpL[r-1]).any())dpR[l][r]=1;
		}
	}
	printf("%d\n",(int)(dpL[n]&dpR[1]).count());
	return 0;
}



Measured memory_bytes: 5288
#include <iostream>
 #include <map>
 using namespace std;
 void setYakusuuNums(map<int,int> &yakusuMap,int n)
 {
	 map<int,int>::iterator mit;
	int i=2;
	while (i<=n){
		if (n%i==0){
			mit=yakusuMap.find(i);
			if (mit==yakusuMap.end()){
				yakusuMap.insert(map<int,int>::value_type(i,1));
			}else{
				(*mit).second++;
			}
			n = n/i;
		}else{
			i++;
		}
	}
 }
 int main(int argc, char* argv[])
 {
	long long MOD=1000000000+7;
	map<int,int> yakusuMap;
	int n;
	cin>>n;
	for (int i=n;i>=2;i--){
		setYakusuuNums(yakusuMap,i);
	}
	map<int,int>::iterator mit;
	int yakusuNum;
	long long aw=1;
	for (mit=yakusuMap.begin();mit!=yakusuMap.end();mit++){
		yakusuNum = (*mit).second + 1;
		aw*=yakusuNum;
		aw%=MOD;
	}
	cout<<aw<<endl;
	return 0;
 }

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

class Main{
  public static void main(String[] args) throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] line = br.readLine().split(" ");
    int[] list = {Integer.parseInt(line[0]),Integer.parseInt(line[1]),Integer.parseInt(line[2])};
    Arrays.sort(list);
    System.out.println(list[0]+" "+list[1]+" "+list[2]);
  }
}

Measured memory_bytes: 24092
h, w = map(int, input().split())
a = [input() for _ in range(h)]

b = []
for y in range(len(a)):
    for x in range(len(a[y])):
        if a[y][x] != '.':
            b.append(a[y])
            break

c = ['' for _ in range(len(b))]
for x in range(len(b[0])):
    for y in range(len(b)):
        if b[y][x] != '.':
            for y in range(len(b)):
                c[y] += b[y][x]
            break

print('\n'.join(c))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cmath>
#include <string>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#define lowbit(x) (x &(-x))
#define me(ar) memset(ar, 0, sizeof ar)
#define mem(ar,num) memset(ar, num, sizeof ar)
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define pre(i, n, a) for(int i = n; i >= a; i --)
#define rp(i, n) for(int i = 0, i < n; i ++)
using namespace std;
typedef long long ll;
const int  INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-10;
const ll   mod = 1e9 + 7;
const int  N = 150;
int n, x, vis;
signed main(void)
{
   cin >> n;
   while(n --){
      cin >> x;
      if(x % 2 == 0 && x % 3 != 0 && x % 5 != 0) vis = 1;
   }
   if(vis) cout << "DENIED" << endl;
   else cout << "APPROVED" << endl;
   return 0;
}


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

int V,E;
const int MAX = 1 << 20;
const int V_MAX = 15;

int dp[1<<V_MAX][V_MAX];

int G[V_MAX][V_MAX];

/// 110111
/// 001000

int rec(int bits, int cur)
{
  if(dp[bits][cur]>-1){return dp[bits][cur]; }
  
  //if((~bits)==0){ return MAX;}
  
  int cost = MAX;
  for(int i=0;i<V;i++){
    //if((~bits)&(1<<i) && G[cur][i] > 0){
    //if(!(bits >> i & 1)){
    if((~bits)&(1<<i)){
      cost = min(rec(bits|1<<i,i) + G[cur][i],cost);
    }
  }
  
  //cout << "COST:" << cost << ",bits:" << bitset<8>(bits) << ",cur:" << cur << endl;
  
  dp[bits][cur] = cost;
  return dp[bits][cur];
}

void clear()
{
  for(int i=0;i<V_MAX;i++){
    for(int j=0;j<V_MAX;j++){
      G[i][j] = MAX;
    }
  }
  
  for(int i=0;i<1<<V_MAX;i++){
    for(int j=0;j<V_MAX;j++){
      dp[i][j] = -1;
    }
  }
}


int main(void){
  cin >> V >> E;
  
  clear();
  
  for(int i=0;i<E;i++){
    int s,t,d;
    cin >> s >> t >> d;
    G[s][t] = d;
  }
  
  dp[(1<<V)-1][0] = 0;
  
  int answer = rec(0,0);
  
  /*
  for(int i=0;i<V;i++){
    cout << bitset<8>((1<<V)-1) << endl;
    cout << "i:"<< i << ",dp:" << dp[(1<<V)-1][i] << endl;
  }
  */
  
  if(answer == MAX){ answer = -1; }
  
  cout << answer << endl;
}



Measured memory_bytes: 5028
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

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

// UnionFind木(サイズ持ち)
class UnionFind {
    public : 

        vector<int> par;

        UnionFind(int N){
            par = vector<int>(N, -1);
        }

        int parent(int x){
            return par[x];
        }

        int root(int x){
            if(par[x] < 0)return x;
            return par[x] = root(par[x]);
        }

        int size(int x){
            return -par[root(x)];
        }

        void connect(int x, int y){
            int rx = root(x);
            int ry = root(y);
            if(rx == ry)return;

            if(size(rx) < size(ry))swap(rx, ry);

            par[rx] += par[ry];
            par[ry] = rx;

            return;
        }

        bool same(int x, int y){
            return root(x) == root(y);
        }
};

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

    UnionFind UF(n);
    Graph Friend (n);

    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--;b--;

        if(!UF.same(a, b))UF.connect(a, b);
        Friend[a].push_back(b);
        Friend[b].push_back(a);
    }

    vector<int>res(n, 0);
    rep(i, n){
        res[i] = UF.size(i) - Friend[i].size() - 1;
    }
    rep(i, k){
        int c, d;
        cin >> c >> d;
        c--;d--;
        if(UF.same(c, d)){
            res[c]--;
            res[d]--;
        }
    }
    rep(i, n)cout << res[i] << " ";
}



Measured memory_bytes: 7544
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

int main() {
    using vi = vector<int>;
    
    string s;
    cin >> s;
    if(s.at(2) == s.at(3) && s.at(4) == s[5]) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}

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

using namespace std;

int main(){
    long long sx,sy,ex,ey;
    cin >> sx >> sy >> ex >> ey;
    long long abx = 1,aby = 1;
    if(sx > ex){
        abx = -1;
        sx = -sx;
        ex = -ex;
    }
    if(sy > ey){
        aby = -1;
        sy = -sy;
        ey = -ey;
    }
    long long n;
    cin >> n;
    long long x,y;
    vector<pair<long long,long long> > vertical;
    for(long long i = 0;i < n;i++){
        cin >> x >> y;
        x = abx*x;
        y = aby*y;
        vertical.push_back(make_pair(x,y));
    }
    vertical.push_back(make_pair(LONG_MAX,LONG_MAX));
    sort(vertical.begin(),vertical.end());
    vector<long long> dpv(n+1,LONG_MAX);
    dpv[0] = sy;
    long long ansv = 1;
    long long index;
    for(index = 0;vertical[index].first < sx;index++);
    for(;vertical[index].first <= ex;index++){
        int ubi = upper_bound(dpv.begin(),dpv.end(),vertical[index].second) - dpv.begin();
        if(ubi == 0) continue;
        dpv[ubi] = vertical[index].second;
        //*(upper_bound(dpv.begin(),dpv.end(),vertical[index].second)) = vertical[index].second;
    }
    ansv = upper_bound(dpv.begin(),dpv.end(),ey) - dpv.begin();
    ansv--;
    long long mi = min(ex-sx,ey-sy)+1;
    if(ansv == mi){
        printf("%.15f\n",100*(ex-sx+ey-sy)-ansv*(20-5*M_PI)+5*M_PI);
    }
    else{
        printf("%.15f\n",100*(ex-sx+ey-sy)-ansv*(20-5*M_PI));
    }
}

Measured memory_bytes: 6512
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, K) = (input[0], input[1]-1)
let x = readLine()!.characters.split(" ").map{Int(String($0))!}
var ans = 300000000
for i in 0..<N-K {
    let time = min(abs(x[i]), abs(x[i+K])) + abs(x[i]-x[i+K])
    ans = min(time, ans)
}
print(ans)

Measured memory_bytes: 7452
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 998244353
#define ll long long
using namespace std;
int N;
ll data[530000],datb[530000];
void init(int n_){
	N = 1;
	while(N<n_)N*=2;
}
void add(int a,int b, int x,int k,int l,int r){
	if(a <= l && r<=b){
		data[k] += x;
	}
	else if( l<b && a<r ){
		datb[k] += (min(b,r)-max(a,l)) * x;
		add( a,b,x,k*2+1,l,(l+r)/2);
		add( a,b,x,k*2+2,(l+r)/2,r);
	}
}
ll sum(int a,int b,int k,int l,int r){
	if(b<=l || r<=a){
		return 0;
	}
	else if(a<= l && r<=b){
		return data[k]*(r-l)+datb[k];
	}
	else{
		ll res = (min(b,r) -max(a,l)) * data[k];
		res += sum(a,b,k*2+1,l,(l+r)/2);
		res += sum(a,b,k*2+2,(l+r)/2,r);
		return res;
	}
}
signed main(){
	int n,m;
	cin>>n>>m;
	init(114514);
	int kakujitu = n;
	priority_queue< pair< int, pair<int,int> > > que;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		que.push( mp( x-y-1, mp(x,y) ) );
	}
	for(int i=1;i<=m;i++){
		int ans = 0;
		while( !que.empty() && -1 * que.top().first < i){
			//cout<<-1*que.top().first<<" "<<i<<endl;
			pair<int,int> P = que.top().second; que.pop();
			kakujitu--;
			int cl = P.first;
			int cr = P.second;
			//cout<<cl<<" "<<cr<<endl;
			add( cl, cr+1, 1, 0, 0, N);
		}
		for(int j=1;j*i<=m;j++){
			ans += sum( j*i, j*i+1, 0, 0, N);
			//cout<<"pos "<<j*i<<" "<<sum( j*i, j*i+1, 0, 0, N)<<endl;
		}
		ans += kakujitu;
		cout<<ans<<endl;
	}
	return 0;
}

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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;
string S;

int main()
{
	cin >> S;
	N = S.size();
	cout << S.substr(0,N - 8) << endl;

	return 0;
}


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

int main() {
    int h,w; cin>>h>>w;
    int a[h][w],d[h][w];
    string s;

    for(int i=0;i<h;++i){
            cin>>s;
      for(int j=0;j<w;++j){
        char tmp=s[j];
            if(tmp=='#') a[i][j]=1;
            else a[i][j]=0;
        }
    }

    d[0][0]=a[0][0];
    
    for(int i=1;i<h;++i){
    d[i][0]=d[i-1][0]+a[i][0];
    if(a[i-1][0]==1 && a[i][0]==1)d[i][0]-=1;
    }
    
    for(int j=1;j<w;++j){
    d[0][j] = d[0][j-1]+a[0][j];
    if(a[0][j-1]==1 && a[0][j]==1)d[0][j]-=1;
    }
    
    int tmp1,tmp2;
       
    for(int i=1;i<h;++i){
        for(int j=1;j<w;++j){
        tmp1 =d[i-1][j]+a[i][j];
        tmp2 =d[i][j-1]+a[i][j];
        
        if(a[i-1][j]==1&&a[i][j]==1)tmp1-=1;
        if(a[i][j-1]==1&&a[i][j]==1)tmp2-=1;
        
        d[i][j]= min(tmp1,tmp2);
        }
    }
    
    cout<<d[h-1][w-1]<<endl;
	return 0;
}

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

int main() {
    int N, M;
    while (cin >> N >> M, N | M) {
        int r, q;
        cin >> r;
        vector<vector<int> > v(10001, vector<int>(1265, 0));
        for (int i = 0; i < r; i++) {
            int t, n, m, s;
            cin >> t >> n >> m >> s;
            for (int j = 0; j < 1260; j++) {
                if (j >= t) {
                    if (s) {
                        v[m][j]++;
                    } else {
                        v[m][j]--;
                    }
                }
            }
        }
        cin >> q;
        for (int i = 0; i < q; i++) {
            int ts, te, m, ans = 0;
            cin >> ts >> te >> m;
            for (int j = ts; j < te; j++) {
                if (v[m][j]) ans++;
            }
            cout << ans << endl;
        }
    }
    return 0;
}


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

bool even(vector<int> no,int n)
{
    for (int i = 0; i<n; i++ )
    {
        if (no.at(i)%2 == 1)
        {
            return 0;
        }
    }

    return 1;
}
int main ()
{
    int n,count=0;
    cin>> n;
    vector<int> no(n);
    
    for (int i =0; i<n;i++)
        cin>> no.at(i);
    
    while (even(no,n))
    {
        count += 1;
        for (int i =0; i<n;i++)
        no.at(i)/=2 ;
    }

    cout<< count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    int n, k; cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    
    //dp[i] denotes the minimum cost to reach ith stone
    // 0 < i < n - 1 are the stones
    //We are asked to dind the cost to reach last stone i.e dp[n - 1]
    //Initially there is infinite cost to reach ith stones
    vector<int> dp(n, INT_MAX);
  
    //To reach first stone there is no cost. SO dp[0] = 0
    dp[0] = 0;
   //To reach second stone the frog can jump from 0th stone costing dp[1] = abs(h[1] - h[0])
    dp[1] = abs(h[1] - h[0]);
    
    //For every other stones 2 <= i < n, the frog can jump from the (i - 1), (i - 2)...(i - k)th stones 
    for(int i = 2; i < n; i++){
      for(int j = i - 1, jump = 0; j  >= 0 && jump < k; j--, jump++){
        dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
      }
    }
    //Print minm cost to reach (n - 1)th stone
    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){
int H,N;


cin>>H>>N;

int moves[N];

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




    int sum = 0;
    for(int i=0;i<N;i++){
        sum = sum + moves[i];
    }

    if(sum>=H){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }




return 0;
}



Measured memory_bytes: 640
from collections import defaultdict
N, M = map(int, input().split())
route = defaultdict(int)
for _ in range(M):
    a, b = map(int, input().split())
    route[a, b] = 1
for i in range(2, N):
    if route[1, i] == route[i, N] == 1:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')

Measured memory_bytes: 82364
//Tanzim bin nasir
#include<bits/stdc++.h>
typedef long long ll;
#define ff first
#define ss second
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    else
    gcd(b,a%b);
}
ll lcd(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>b)
    {
        for(int i=0;i<a;i++)
        cout<<b;
    }
    else
    {
        for(int i=0;i<b;i++)
        cout<<a;
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 3512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define ld double
#define llu unsigned long long
#define rep(i,x,y)  for(ll i=x;i<y;++i)
#define For(i,x,y)  for(ll i=x;i<=y;++i)
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define pi acos(-1)
#define mk make_pair<ll,ll>
#define pa pair<ll,ll>
#define lf else if
#define fi first
#define se second
typedef complex<double> E;
ll n,q[100],Q[100],top,answ;
int main(){
	cin>>n;
	while(n)q[++top]=n%10,n/=10,answ+=q[top];
	For(lcp,1,top-1){
		ll now=0;
		memcpy(Q,q,sizeof Q);
		For(j,1,lcp)Q[j]=9;
		Q[lcp+1]--;
		for(ll j=lcp+1;Q[j]<0;++j)
			Q[j]--,Q[j]+=10;
		For(i,1,top)now+=Q[i];
		answ=max(answ,now);
	}
	cout<<answ<<endl;
}
/*
*/

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

const int MAX = 10000000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// コンビネーションを計算する関数
ll modpow(ll a, ll n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main()
{
    cout << fixed << setprecision(15);
    ll K;
    string S;
    cin >> K;
    cin >> S;

    ll N = S.length();
    // 前処理
    COMinit();

    ll ans = 0;
    for(ll i=0; i<=K; i++){
        ans += (((modpow(26, K-i) * modpow(25, i)) % MOD) * COM(N-1+i, i)) % MOD;
        ans = ans % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 238648
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define L (idx*2)
#define R ((idx*2)+1)
#define imx INT_MAX
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
typedef pair<int,int> pii;
int n,x[200005],ap,bp,ss,ee;
pii seq[800005][2];
priority_queue<pair<int,pair<pii,pii> > >pq;
void up(int st,int ed,int idx,int pos,int val)
{
    int mid=(st+ed)/2;
    if(st>pos||ed<pos)return;
    if(st==ed)
    {
        seq[idx][pos%2]={val,pos};
        return;
    }
    up(st,mid,L,pos,val);
    up(mid+1,ed,R,pos,val);
    if(seq[L][0].F>seq[R][0].F)
    {
        seq[idx][0]=seq[R][0];
    }
    else
    {
        seq[idx][0]=seq[L][0];
    }
    if(seq[L][1].F>seq[R][1].F)
    {
        seq[idx][1]=seq[R][1];
    }
    else
    {
        seq[idx][1]=seq[L][1];
    }
    return;
}
pii mx(int st,int ed,int idx,int l,int r,int tp)
{
    int mid=(st+ed)/2;
    if(st>r||ed<l)return {imx,imx};
    if(l<=st&&r>=ed)return seq[idx][tp];
    pii a,b;
    a=mx(st,mid,L,l,r,tp);
    b=mx(mid+1,ed,R,l,r,tp);
    if(a.F>b.F)
    {
        return b;
    }
    else
    {
        return a;
    }
}
void pq_push(int st,int ed)
{
    //printf("%d %d\n",st,ed);
    if(ed-st+1<2)return;
    //printf("%d %d\n",st,ed);
    pii a=mx(1,n,1,st,ed,st%2);
    pii b=mx(1,n,1,a.S+1,ed,(st+1)%2);
    pq.push({-a.F,{{st,ed},{a.S,b.S}}});
    return;
}
int main()
{
    for(int i=0;i<800005;i++)seq[i][0]={imx,imx},seq[i][1]={imx,imx};
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x[i]);
        up(1,n,1,i,x[i]);
    }
    pq_push(1,n);
    while(!pq.empty())
    {
        ap=pq.top().S.S.F;
        bp=pq.top().S.S.S;
        ss=pq.top().S.F.F;
        ee=pq.top().S.F.S;
        pq.pop();
        printf("%d %d ",x[ap],x[bp]);
        pq_push(ss,ap-1);
        pq_push(ap+1,bp-1);
        pq_push(bp+1,ee);
    }
}


Measured memory_bytes: 18016
#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() {
    int n;
    cin >> n;

    vector<ll> a(n + 1), sm(n + 1);
    for (int i = 0; i <= n; i++) {
        cin >> a[i];
        if (i) sm[i - 1] = a[i];
    }

    for (int i = n; i; i--) sm[i - 1] += sm[i];

    ll ans = 0, cur = 1;
    for (int i = 0; i <= n; i++) {
        ans += cur;

        cur -= a[i];

        if (cur < 0) {
            cout << -1 << endl;
            return 0;
        }

        cur = min(cur * 2, sm[i]);
    }

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

Measured memory_bytes: 4768
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b;
    cin >> a >> b;
    if (a > b)
      cout << "a > b" << endl;
    else if (a < b)
      cout << "a < b" << endl;
    else if (a == b)
      cout << "a == b" << endl;    
}


Measured memory_bytes: 3092
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define pb push_back
#define fi first
#define se second
#define PAD 400
#define SIZE 500333
#define MAXV 222
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;

ll n,a[100111], psum[100111];

bool chk(ll limit) {
	ll p = a[limit];
	for(int i=1;i<=n;i++) {
		if(i == limit)	continue;
		if(2 * p < a[i])	return false;
		p += a[i];
	}
	return true;
}

int main () {
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)	scanf("%lld",a+i);
	sort(a+1,a+n+1);
	ll hi = n, lo = 0, mid, ret = 0;
	for(int i=0;i<100;i++) {
		mid = (lo+hi)/2;
		// printf("mid %lld ret %lld\n",mid,ret);
		if(chk(mid))	hi = mid - 1, ret = mid;
		else		lo = mid + 1;
	}	
	printf("%lld\n",n - ret + 1);
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main() {
  int N;
  int *A;
  int *a;
  int minabs = INFINITY;
  int minabs_pos;
  long long int sum = 0;
  int i;

  scanf("%d", &N);

  A = (int *)malloc(N * sizeof(int));
  a = A;

  for(i = 0; i < N; i++) {
    scanf("%d", a);
    a++;
    if(abs(A[i]) < minabs) {
      minabs = abs(A[i]);
      minabs_pos = i;
    }
  }

  for(i = 0; i < minabs_pos; i++) {
    if(A[i] < 0) {
      A[i] *= -1;
      A[i+1] *= -1;
    }
  }

  for(i = N - 1; i > minabs_pos; i--) {
    if(A[i] < 0) {
      A[i-1] *= -1;
      A[i] *= -1;
    }
  }

  for(i = 0; i < N; i++) {
    sum += A[i];
  }

  printf("%lld\n", sum);

  free(A);

  return 0;
}


Measured memory_bytes: 640
//package BeginnerContest142;

import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {
        FastReader sc = new FastReader();
        PrintWriter pw = new PrintWriter(System.out);
        TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
        int n = sc.nextInt();
        for(int i = 1; i<=n; i++){
            map.put(sc.nextInt(),i);
        }
        for(int i : map.keySet()){
            pw.print(map.get(i) + " ");
        }
        pw.println();
        pw.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 50388
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ll 				long long
#define int             long long int
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define modp            998244353
#define inf             (ll)1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define FIO           	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl 			'\n'
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void solve()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max({a*c, a*d, b*c, b*d}) << endl;
}
 
int32_t main()
{
	FIO
    // w(t)
    {
    	solve();
    }
    return 0;
}
	

	

Measured memory_bytes: 3652
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <set>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define PRIME1 99999883
#define PRIME2 99999893
#define EPS 0.00000001
using namespace std;

struct Info{
	int length;
};

int main(){

	int N,start,pre,tmp,count;

	scanf("%d",&N);

	Info* info = (Info*)malloc(sizeof(Info)*N);
	int info_index = 0;

	scanf("%d",&pre);
	count = 1;
	start = pre;

	int maximum = 0;

	for(int i = 1; i < N; i++){
		scanf("%d",&tmp);
		if(tmp != pre){
			count++;

			if(i == N-1){
				info[info_index].length = count;
				info_index++;
				maximum = max(maximum,count);
			}
		}else{
			info[info_index].length = count;
			info_index++;

			maximum = max(maximum,count);

			start = tmp;
			count = 1;

			if(i == N-1){
				info[info_index].length = count;
				info_index++;
			}

		}
		pre = tmp;
	}

	if(info_index > 1){
		maximum = info[0].length+info[1].length;
	}

	for(int i = 1; i < info_index-1; i++){
		maximum = max(maximum,info[i-1].length+info[i].length+info[i+1].length);
	}

	if(info_index > 1){
		maximum = max(maximum,info[info_index-2].length+info[info_index-1].length);
	}

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

    return 0;
}

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

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

int main() {
    int N, M;
    cin >> N >> M;
    int A = 0;
    for(int i = 0; i < M; i++){
        int a;
        cin >> a;
        A += a;
    } 
    if( N - A >= 0){
        cout << N-A;
    } else {
        cout << -1;
    }
}

Measured memory_bytes: 3640
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define N 8

const int nil = -1;
bool x[N][N];
int row[N];
bool col[N];
bool dpos[2 * N - 1], dneg[2 * N - 1];

void
print_board()
{
	int i, j;

	for (i = 0; i < N; ++i)
	{
		for (j = 0; j < N; ++j)
		{
			if (x[i][j] && row[i] != j)
				return;
		}
	}

	for (i = 0; i < N; ++i)
	{
		for (j = 0; j < N; ++j)
			printf("%c", (row[i] == j) ? 'Q' : '.');

		printf("\n");
	}
}

void
backtrack(int i)
{
	int j;

	if (i == N)
	{
		print_board();
		return;
	}

	for (j = 0; j < N; ++j)
	{
		if (!col[j] && !dpos[i + j] && !dneg[i - j + N - 1])
		{
			row[i] = j;
			col[j] = dpos[i + j] = dneg[i - j + N - 1] = true;

			backtrack(i + 1);
			row[i] = nil;
			col[j] = dpos[i + j] = dneg[i - j + N - 1] = false;
		}
	}
}

void
initialize()
{
	int i, j;

	for (i = 0; i < N; ++i)
	{
		row[i] = nil;
		col[i] = false;

		for (j = 0; j < N; ++j)
			x[i][j] = false;
	}

	for (i = 0; i < 2 * N - 1; ++i)
	{
		dpos[i] = false;
		dneg[i] = false;
	}
}

int
main(int argc, char** argv)
{
	int r, c;
	int k;
	int i;

	initialize();

	scanf("%d", &k);
	for (i = 0; i < k; ++i)
	{
		scanf("%d %d", &r, &c);
		x[r][c] = true;
	}

	backtrack(0);
	return 0;
}



Measured memory_bytes: 2112
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let n = input::<i64>();
    let a = (0..n).map(|_| input()).collect::<Vec<i64>>();

    let ans = a
        .iter()
        .map(|a| {
            let mut temp = *a;
            let mut cnt = 0;
            while temp % 2 == 0 {
                cnt += 1;
                temp /= 2;
            }
            cnt
        })
        .sum::<i64>();
    println!("{}", ans);
}


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

using namespace std;

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

	int k;
	cin >> k;

	int cnt = 0;

	while(b <= a) {
		b *= 2;
		cnt += 1;
	}

	while(c <= b) {
		c *= 2;
		cnt += 1;
	}

	if(cnt <= k) {
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}

	return 0;
}


Measured memory_bytes: 3620
#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();
    int T=1,t,n,m,q,k,i,j;
    // cin>>T;
    while(T--)
    {
        cin>>n;
        int cs[n],va[n];
        FOR(i,0,n)  cin>>va[i];
        FOR(i,0,n)  cin>>cs[i];
        ll ans = 0;
        FOR(i,0,n) 
        {
            if(va[i]>cs[i])
                ans += (va[i]-cs[i]);
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
using ll = long long;

int main(){
    int bingo[3][3];
    for (int i=0;i<3;i++){
        for (int j=0;j<3;j++){
            int a; cin >> a;
            bingo[i][j] = a;
        }
    }
    int n;
    cin >> n;
    vector<int> b(n);
    for (int i=0;i<n;i++){
        int b; cin>> b;
        for (int i=0;i<3;i++){
            for (int j=0;j<3;j++){
            if(bingo[i][j]== b) bingo[i][j]=0;
            }
        }  
    }
    //判定
    bool can =false;
    for (int i=0;i<3;i++){
        int sum=0;
        for (int j=0;j<3;j++){
            sum+=bingo[i][j];
        }
        if (sum==0) can =true;
    }
    for (int j=0;j<3;j++){
        int sum=0;
        for (int i=0;i<3;i++){
            sum+=bingo[i][j];
        }
        if (sum==0) can =true;
    }
    if(bingo[0][0]+bingo[1][1]+bingo[2][2]==0) can = true;
    if(bingo[2][0]+bingo[1][1]+bingo[0][2]==0) can = true;

    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,ans;
char s[1000];
int main(){
	scanf("%s",s);
	s[3]='8';
	puts(s);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n,b[maxn],a[maxn];

int main(){
    cin>>n;
    for(int i=1;i<n;i++)
        scanf("%d",&b[i]);
    memset(a,0x3f,sizeof(a));
    for(int i=1;i<n;i++){
        a[i]=min(a[i],b[i]);
        a[i+1]=min(a[i+1],b[i]);
    }
    int sum=0;
    for(int i=1;i<=n;i++)
        sum+=a[i];
    printf("%d\n",sum);
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
 
int main() {
    int n;
    cin >> n;
    int ans=0;
    rep(i,n){
        rep(j,n){
            rep(k,n){
                int u=__gcd(i+1,j+1);
                u=__gcd(u,k+1);
                ans+=u;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <string>
#include <sstream>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define clr(a) memset(a, 0, sizeof(a))
#define set(a) memset(a, -1, sizeof(a))
#define pb push_back
#define sz(a) ((ll)a.size())
#define all(a) a.begin(), a.end()
#define mp make_pair
#define rep(i, a, y) for (ll i = a; i <= y; i++)
#define rep2(i, b) for (ll i = 0; i < b; i++)
#define repl(i, a, b) for (ll i = a; i <= b; i++)
#define ppi pair<int, int>
#define scl(x) scanf("%d", &x)
#define pcl(x) printf("%d", x)
#define FastRead                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0)
/*
 
     ██╗██╗   ██╗██╗  ██╗ █████╗ ███╗   ██╗
     ██║██║   ██║██║  ██║██╔══██╗████╗  ██║
     ██║██║   ██║███████║███████║██╔██╗ ██║
██   ██║██║   ██║██╔══██║██╔══██║██║╚██╗██║
╚█████╔╝╚██████╔╝██║  ██║██║  ██║██║ ╚████║
 ╚════╝  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝
 
*/
int main()
{
    FastRead;
    //set<ll>v;
    bool cnt=0;
    ll n,x=1;
    cin>>n;
    ll a[n+1];
    rep(i,1,n) 
    {
        cin>>a[i];
        if(a[i]==x) 
        {
            cnt=1;
            x++;
        }
    }
    if(!cnt) 
    {
        cout<<-1<<endl;
        return 0;
    }
    cout<<n-x+1<<endl;
    return 0;
}

Measured memory_bytes: 5204
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>

#define ff first
#define ss second

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

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

    string s;
    cin>>s;
    for(int i=0; i<s.length(); i++){
        if(i%2==0 && s[i]=='L' || i%2==1 && s[i]=='R'){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n, m, k := scanInt(), scanInt(), scanInt()
	a := scanInts(n)
	b := scanInts(m)
	sum := make([]int, n+1)
	for i := 0; i < n; i++ {
		sum[i+1] = sum[i] + a[i]
	}

	idx := sort.Search(n+1, func(idx int) bool { return k < sum[idx] }) - 1
	ans := idx
	t := 0
	for i := 0; i < m; i++ {
		t += b[i]
		idx := sort.Search(n+1, func(idx int) bool { return k-t < sum[idx] }) - 1
		if idx < 0 {
			continue
		}
		ans = max(ans, i+1+idx)
	}
	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 9536
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void solve() {
        Int N;
        cin >> N;
        Int n = 1;
        for (int i = 0; i < N; ++i) n <<= 1;
        vector<Int> S(n);
        for (int i = 0; i < n; ++i) {
            cin >> S[i];
        }


        sort(all(S));

        // 負の値
        multiset<Int> rest;
        multiset<Int> used;
        for (int i = 0; i + 1 < n; ++i) {
            rest.insert(-S[i]);
        }
        used.insert(-S[n - 1]);

        for (int i = 0; i < N; ++i) {
            multiset<Int> newst;
            for (auto e : used) {
                auto pt = rest.upper_bound(e);
                if (pt == rest.end()) {
                    cout << "No" << endl;
                    return;
                }
                newst.insert(*pt);
                rest.erase(pt);
            }
            used.insert(all(newst));
        }


//        Int st = 0;
//        for (Int i = N - 1; i >= 0; --i) {
//            Int diff = 1 << i;
//            for (Int idx = 0; idx < diff; ++idx) {
//                Int l = st + idx;
//                Int r = l + diff;
//                cerr << l << " " << r << endl;
//                if (S[l] >= S[r]) {
//                    cout << "No" << endl;
//                    return;
//                }
//            }
//            st += diff;
//        }
//
        cout << "Yes" << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 20736
import Data.Function
import Data.List
main =  do
  s <- getLine
  t <- getLine
  let a = all ((==) 1 . length) . groupBy ((==) `on` fst) . sortOn fst . nub $ zip s t
      b = all ((==) 1 . length) . groupBy ((==) `on` snd) . sortOn snd . nub $ zip s t
  putStrLn $ if a && b then "Yes" else "No"

Measured memory_bytes: 27516
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] p = new int[n+1];
        for(int i = 1; i <= n; i++){
            p[i] = Integer.parseInt(sc.next());
        }
        
        UnionFind uf = new UnionFind(n+1);
        int x, y;
        for(int i = 0; i < m; i++){
            x = Integer.parseInt(sc.next());
            y = Integer.parseInt(sc.next());
            uf.unite(x, y);
        }
        
        int ans = 0;
        for(int i = 1; i <= n; i++){
            if(uf.same(i, p[i])){
                ans++;
            }
        }
        
        System.out.println(ans);
    }
    
    static class UnionFind {
        int[] parent;
        int[] rank;
        
        public UnionFind(int n) {
            parent = new int[n];
            rank = new int[n];
            for(int i = 0; i < n; i++){
                parent[i] = i;
            }
        }
        private int root(int x){
            if(parent[x] == x){
                return x;
            }else{
                return parent[x] = root(parent[x]);
            }
        }
        private void unite(int x, int y){
            x = root(x);
            y = root(y);
            if(x == y) return;

            if(rank[x] < rank[y]){
                parent[x] = y;
            }else{
                parent[y] = x;
                if(rank[x] == rank[y]){
                    rank[x]++;
                }
            }
        }
        private boolean same(int x, int y){
            return root(x) == root(y);
        }
    }
}

Measured memory_bytes: 65752
n,x,y=map(int, input().split())
ans=[0]*n
for i in range(1,n+1):
    for j in range(1,n+1):
        if i>=j:
            continue
        ans[min(j-i, abs(x-i)+abs(y-j)+1)]+=1
for k in range(1,n):
    print(ans[k])

Measured memory_bytes: 46172