akhauriyash/Code-Regression huggingface dataset:
#include <unordered_map>
#include <string>
#include <vector>
#include <iostream>

class Item {
public:
	Item(const std::string &n, const int &p) :name(n), price(p), made_from() {};
	Item() :name(), price(), made_from() {};
	void add_recipe(Item* item) {
		made_from.push_back(item);
	}
	int get_price() {
		if (made_from.size() == 0) {
			return price;
		}
		else {
			int temp = 0;
			for (auto i : made_from) {
				temp += i->get_price();
			}
			return (price > temp) ? temp : price;
		}
	}
private:
	std::string name;
	int price;
	std::vector<Item*> made_from;
};
int main() {
	int n = 1;
	std::cin >> n;
	while (n != 0) {
		std::unordered_map<std::string, Item> map;
		for (auto i = 0; i < n; ++i) {
			std::string name;
			int price;
			std::cin >> name >> price;
			map[name] = Item(name, price);
		}
		std::cin >> n;
		for (auto i = 0; i < n; ++i) {
			std::string item;
			std::cin >> item;
			int m;
			std::cin >> m;
			for (auto j = 0; j < m; ++j) {
				std::string factor;
				std::cin >> factor;
				map[item].add_recipe(&map[factor]);
			}
		}
		std::string order;
		std::cin >> order;
		std::cout << map[order].get_price() << std::endl;
		std::cin >> n;
	}
	return 0;
}

Measured memory_bytes: 1252
#include <iostream>
#include <string>

using namespace std;

int main(){
  int A, B;
  string S;
  cin >> A >> B >> S;

  for (int i = 0; i < S.size(); i++){
    if (i==A){
      if (S[i]!='-'){
        printf("No\n");
        return 0;
      }
    }else if (S[i]-'0' > 9 || S[i]-'0' < 0){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
}


Measured memory_bytes: 3640
#include<queue>
#include<cstdio>
#include<algorithm>

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

using namespace std;

template<class T>
struct interval{
	T a,b,w;
	interval():a(0),b(0){}
	interval(const T &a,const T &b):a(a<b?a:b),b(a<b?b:a){}
	bool operator<(const interval &I)const{ return b<I.b || b==I.b && a<I.a; }
};

const int V_MAX=2003;
const int CAPA_INF=1<<29;
const int COST_INF=1<<29;

template<class T,class U>
struct edge{
	int v,rev;
	T capa;
	U cost;
	T flow;
};

template<class T,class U>
void add_directed_edge(vector< edge<T,U> > *G,int u,int v,T capa,U cost){
	G[u].push_back((edge<T,U>){v,G[v].size()  ,capa, cost,0});
	G[v].push_back((edge<T,U>){u,G[u].size()-1,   0,-cost,0});
}

template<class T,class U>
pair<T,U> augment(int n,vector< edge<T,U> > *G,int s,int t,U *pot,bool fir){
	static int pre[V_MAX];
	static U d[V_MAX];
	rep(u,n) d[u]=(u==s?0:COST_INF);

	bool ok;
	if(fir){
		// Bellman-Ford
		while(1){
			bool end=true;
			rep(u,n) rep(i,G[u].size()) {
				edge<T,U> &e=G[u][i];
				if(e.capa-e.flow>0 && d[u]<COST_INF && d[u]+e.cost<d[e.v]){
					d[e.v]=d[u]+e.cost;
					pre[e.v]=e.rev;
					end=false;
				}
			}
			if(end) break;
		}
		ok=(d[t]<COST_INF);
	}
	else{
		// Dijkstra
		ok=false;
		priority_queue< pair<U,int> > Q; Q.push(make_pair(0,s));
		while(!Q.empty()){
			int u=Q.top().second;
			U cost=-Q.top().first; Q.pop();

			if(cost<d[u]) continue;
			if(u==t) ok=true;

			rep(i,G[u].size()){
				edge<T,U> &e=G[u][i];
				U cost2=cost+e.cost+pot[u]-pot[e.v];
				if(e.capa-e.flow>0 && cost2<d[e.v]){
					d[e.v]=cost2;
					pre[e.v]=e.rev;
					Q.push(make_pair(-cost2,e.v));
				}
			}
		}
	}

	if(!ok) return make_pair(0,0);

	T water=CAPA_INF;
	for(int v=t;v!=s;){
		edge<T,U> &e1=G[v][pre[v]];
		edge<T,U> &e2=G[e1.v][e1.rev];
		water=min(water,e2.capa-e2.flow);
		v=e1.v;
	}

	U cost=0;
	for(int v=t;v!=s;){
		edge<T,U> &e1=G[v][pre[v]];
		edge<T,U> &e2=G[e1.v][e1.rev];
		e1.flow-=water;
		e2.flow+=water;
		cost+=water*e2.cost;
		v=e1.v;
	}

	rep(u,n) pot[u]+=d[u];

	return make_pair(water,cost);
}

template<class T,class U>
pair<T,U> primal_dual(int n,vector< edge<T,U> > *G,int s,int t){
	static U pot[V_MAX];
	rep(u,n) pot[u]=0;

	T ans1=0;
	U ans2=0;
	for(bool fir=true;;fir=false){
		pair<T,U> tmp=augment(n,G,s,t,pot,fir);
		if(tmp.first==0) break;
		ans1+=tmp.first;
		ans2+=tmp.second;
	}
	return make_pair(ans1,ans2);
}

int main(){
	for(int n;scanf("%d",&n),n;){
		interval<int> I[1000];
		rep(i,n) scanf("%d%d%d",&I[i].a,&I[i].b,&I[i].w);

		sort(I,I+n);

		int s=2*n,t=s+1;
		vector< edge<int,int> > G[V_MAX];
		rep(u,n) for(int v=u+1;v<n;v++) if(I[u].b<I[v].a) {
			add_directed_edge(G,2*u+1,2*v,1,-I[v].w);
		}
		rep(u,n){
			add_directed_edge(G,s,2*u,1,-I[u].w);
			add_directed_edge(G,2*u,2*u+1,1,0);
			add_directed_edge(G,2*u+1,t,1,0);
		}
		int tt=t+1;
		add_directed_edge(G,t,tt,2,0);

		printf("%d\n",-primal_dual(2*n+3,G,s,tt).second);
	}

	return 0;
}

Measured memory_bytes: 27320
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<ll,ll>;


ll m=1000000007;

ll mod=1e9+7;
ll dp[2000+4];


int main()
{
  ll h,w,k;
  cin>>h>>w>>k;
  vector<string>s(h);
  rep(i,h)cin>>s[i];
  ll ans=0;
  rep(i,1<<h){
      rep(j,1<<w){
          ll cnt=0;
          for(ll ii=0;ii<h;ii++){
              for(ll jj=0;jj<w;jj++){
                  if(i>>ii&1)continue;
                  if(j>>jj&1)continue;
                  if(s[ii][jj]=='#')cnt++;
              }
          }
          if(cnt==k)ans++;
      }
  }
  cout<<ans<<endl;
}
 


 

 




Measured memory_bytes: 3576
import collections
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
a = list(map(int, input().split()))
d = collections.Counter(a)
v = list(d.values())
v = sorted(v)

ans = 0
i = 0
while len(v) - i > k:
    ans += v[i]
    i += 1

print(ans)



Measured memory_bytes: 34036
val=list(map(float,input().split()))
if(val[0]>val[2]):
    x=(val[0]-val[2])**2
else:
    x=(val[2]-val[0])**2
if(val[1]>val[3]):
    y=(val[1]-val[3])**2
else:
    y=(val[3]-val[1])**2
    
length=(x+y)**0.5
print(length)


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  int x[2],y[2];
  while(true){
    cin >> s;
    if(s == "#") break;
    cin >> y[0] >> x[0] >> y[1] >> x[1];
    y[0]--;
    y[1]--;
    x[0]--;
    x[1]--;

    vector<vector<char>> board;
    vector<char> line;
    rep(i,s.size()){

      if(isdigit(s[i])){
        int lim = s[i] - '0';
        rep(j,lim){
          line.push_back('.');
        }
      }
      else if(s[i] == 'b'){
        line.push_back('b');
      }
      else if(s[i] == '/'){
        board.push_back(line);
        line.clear();
      }
      if(i == s.size() - 1) board.push_back(line);
    }

    // rep(i,board.size()){
    //   rep(j,board[0].size()){
    //     cout << board[i][j];
    //   }
    //   cout << endl;
    // }
    board[y[0]][x[0]] = '.';
    board[y[1]][x[1]] = 'b';
    string ans = "";
    rep(i,board.size()){
      int cnt = 0;
      rep(j,board[0].size()){
        if(board[i][j] == '.') cnt++;
        if(board[i][j] == 'b'){
          if(cnt > 0)ans += toString(cnt);
          ans.push_back('b');
          cnt = 0;
        }
      }
      if(cnt > 0) ans += toString(cnt);
      ans.push_back('/');
    }
    ans.pop_back();
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3224
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(vec) (vec).begin(), (vec).end()
#define SUM(...) accumulate(ALL(__VA_ARGS__),0LL)
#define DSUM(...) accumulate(ALL(__VA_ARGS__),0.0)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 便利関数
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

// 出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}

void solve(long long N, std::string S){
    REP(i, S.size()) {
        if (S[i] + (int)N <= 'Z')
            printf("%c", S[i] + (int)N);
        else
            printf("%c", S[i] + (int)N - 26);
    }
    cout << '\n';
}

int main(){
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;

int main(){
	int m;
	cin >> m;
	int mx=0;
	int f,y,n;
	int i,j,k;
	for(i=0;i<m;i++){
		cin >> f >> y>>n;
		mx=0;
		for(j=0;j<n;j++){
			int ri,tes;
			double r;
			cin >> ri >> r >> tes;
			
			int tmp=f;
			int risi=0;
			for(k=0;k<y;k++){
				if(ri==0){
					risi+=(tmp*r);
				}else{
					tmp*=(1+r);
				}
				tmp-=tes;
			}
			mx=max(mx,tmp+risi);
		}
		cout << mx << endl;
	}
	
	return 0;
}
	

Measured memory_bytes: 0
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int main(void){
    
    int N;
    int count = 1;
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    string str_P;
    string str_Q;
    map<string, int> mp;
    
    for(int i = 0; i < N; i++){
        cin >> P[i];
        str_P += to_string(P[i]);
    }

    for(int i = 0; i < N; i++){
        cin >> Q[i];
        str_Q += to_string(Q[i]);
    }
    
    sort(P.begin(), P.end());
    
    do {
        string s = {};
        for(int i = 0; i < N; i++){
            s += to_string(P[i]);  
        } 
        mp[s] = count;
        count++;
    } while (next_permutation(P.begin(), P.end()));
    
    cout << abs(mp[str_P] - mp[str_Q]) << endl;
    
}


Measured memory_bytes: 4608
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int a = input[0];
        int b = input[1];
        int c = input[2];
        int x = input[3];
        int y = input[4];

        long ab = 2 * c * Math.Max(x, y);
        long st = 2 * c * Math.Min(x, y) + a * (x - Math.Min(x, y)) + b * (y - Math.Min(x, y));
        long no = a * x + b * y;

        long ans = Math.Min(ab, Math.Min(st, no));

        Console.WriteLine(ans);

    }
}

Measured memory_bytes: 13396
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <bitset>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;

int n,lst,a[100005];
string s;

int main()
{
	cin>>s;
	n=s.length();
	s="#"+s;
	for(int i=1;i<=n;i++)
		if(s[i]=='L')
			a[lst+(i-lst)%2]++;
		else
			lst=i;

	for(int i=n;i>=1;i--)
		if(s[i]=='R')
			a[lst-(lst-i)%2]++;
		else
			lst=i;
	
	for(int i=1;i<=n;i++)
		cout<<a[i]<<" ";
	
	cout<<endl;
	return 0;
}
 
/*
 
 
 
 
 
*/

Measured memory_bytes: 1020
#include<string>
#include<vector>
#include<iostream>

using namespace std;

int main() {

	int a, b, c;

	cin >> a >> b >> c;

	if (a == b) {
		if (b == c)
			cout << "No";
		else
			cout << "Yes";
	}
	else if (b == c) {
		cout << "Yes";
	}
	else {
		if (a == c) {
			cout << "Yes";
		}
		else {
			cout << "No";
		}
	}
		
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define DEBUG 0
#define nl          '\n'
#define fori(n)			for(int i = 0; i < n; ++i) 
#define forj(n)			for(int j = 0; j < n; ++j)
#define fork(n)			for(int k = 0; k < n; ++k)
#define forl(n)			for(int l = 0; l < n; ++l)
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define ppb push_back
typedef long long ll;typedef pair<int,int> pii;typedef vector<bool> vbool;
typedef vector<int> vint;typedef vector<ll> vll;typedef long double ld;
typedef vector<vector<int>> vvi; typedef vector<vbool> vvb;

const ll N = 100010;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, a, b ; cin >> n >> a >> b;
	if ((b-a)%2) {
		ll ans = min(n - b + 1 + (b-a-1)/2, a + (b-a-1)/2);
		cout << ans << nl;
	} else {
		cout << (b-a)/2 << nl;
	}
	
	#if DEBUG
	cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << " s" << nl;
	#endif
	return 0;
}


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

#define ll long long 
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()

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

	int h, w, k;
	cin >> h >> w >> k;
	char ch[h][w];
	string s;
	for(int i = 0; i < h; i++) {
		cin >> s;
		for(int j = 0; j < w; j++) {
			ch[i][j] = s[j];
		}
	}
	ll ans = 0;
	for(int i = 0; i < (1 << h); i++) {
		for(int j = 0; j < (1 << w); j++) {
			vector<int> bit1(h, 0), bit2(w, 0);
			for(int k1 = 0; k1 < h; k1++) {
				bit1[k1] = (i & (1 << k1)) ? 1 : 0;
			}
			for(int k1 = 0; k1 < w; k1++) {
				bit2[k1] = (j & (1 << k1)) ? 1 : 0;	
			}
			int c = 0;
			for(int m = 0; m < h; m++) {
				for(int n = 0; n < w; n++) {
					if(bit1[m] == 0 && bit2[n] == 0) {
						if(ch[m][n] == '#') c++;
					}
				}
			}

			if(c == k) ans++;
		}
	}

	cout << ans;
	return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    vector<int> data(n);
    for (int i = 0; i < n; i++) {
        cin >> data[i];
    }

    vector<i_i> ans(0);
    
    auto yui = max_element(all(data)), kyoko = min_element(all(data));

    if (abs(*yui) < abs(*kyoko)) {
        // 負
        //cout << "hu" << endl;
        ans.pb(mp(kyoko - data.begin()+1, n));
        ans.pb(mp(kyoko - data.begin()+1, n));
        for (int i = n; i >= 2; i--) {
            ans.pb(mp(i, i-1));
            ans.pb(mp(i, i-1));
        }
    } else {
        ans.pb(mp(yui - data.begin()+1, 1));
        ans.pb(mp(yui - data.begin()+1, 1));
        Rep(i, n) {
            ans.pb(mp(i, i+1));
            ans.pb(mp(i, i+1));
        }
    }

    cout << ans.size() << endl;
    rep(i, ans.size()) {
        cout << ans[i].fir << " " << ans[i].sec << endl;
    }

    /*
    rep(i, ans.size()) {
        data[ans[i].sec] += data[ans[i].fir];
    }
    rep(i, n) {
        cout << data[i] << " ";
    }
    cout << endl;
    */


    return 0;
}






Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
void koch(int n, double p1_x, double p1_y, double p2_x, double p2_y);
 
int main(int argc, char *argv[])
{
  int n;
  double p1[2], p2[2];
 
  p1[0] = 0;
  p1[1] = 0;
  p2[0] = 100;
  p2[1] = 0;
 
  scanf("%d", &n);
 
  printf("%f %f\n", p1[0], p1[1]);
  koch(n, p1[0], p1[1], p2[0], p2[1]);
 
  return 0;
}
 
void koch(int n, double p1_x, double p1_y, double p2_x, double p2_y)
{
  double s[2], t[2], u[2];
  double r3 = sqrt(3.0);
 
  if (n == 0) {
    printf("%f %f\n", p2_x, p2_y);
    return;
  } else {
    s[0] = p1_x + (p2_x - p1_x)/3.0;
    s[1] = p1_y + (p2_y - p1_y)/3.0;
    t[0] = p1_x + 2*(p2_x - p1_x)/3.0;
    t[1] = p1_y + 2*(p2_y - p1_y)/3.0;
    u[0] = s[0] + (-s[0] + r3*s[1] + t[0] - r3*t[1])/2.0;
    u[1] = s[1] + (-r3*s[0] - s[1] + r3*t[0] + t[1])/2.0;
     
    koch(n - 1, p1_x, p1_y, s[0], s[1]);
    koch(n - 1, s[0], s[1], u[0], u[1]);
    koch(n - 1, u[0], u[1], t[0], t[1]);
    koch(n - 1, t[0], t[1], p2_x, p2_y);
  }
}

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

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
using namespace std;
typedef long long ll;
vector<pair<ll, ll> > pack;
ll w, h;


int main(){
    cin >> w >> h;
    ll wholescore = 0;
    REP(i, w){
        ll tmp;
        cin >> tmp;
        wholescore = wholescore + tmp * (h + 1);
        pack.push_back(pair<ll, ll>(tmp, 1));
    }
    REP(i, h){
        ll tmp;
        cin >> tmp;
        wholescore = wholescore + tmp * (w + 1);
        pack.push_back(pair<ll, ll>(tmp, 2));
    }
    sort(pack.begin(), pack.end());
    ll pmax = w, qmax = h, maxsum = w * h, sum = 0, delsum = 0;
    FOR(i, pack.size() - 1){
        int type = pack[i].second;
        if(type == 2){
            qmax--;
            delsum = delsum + pmax * pack[i].first;
            sum = sum + pmax;
            //cout << pack[i].first << "*" << pmax << "\n";
        }
        else{
            pmax--;
            delsum = delsum + qmax * pack[i].first;
            sum = sum + qmax;
            //cout << pack[i].first << "*" << qmax << "\n";
        }
        if(sum >= maxsum){
            break;
        }
    }
    cout << wholescore - delsum << "\n";
    return 0;
}


Measured memory_bytes: 6512
#include <iostream>
#include<algorithm>
#include <vector>
#include <iomanip>
#include<string.h>
#include<stdio.h>

int main()
{
    long N;
    long B[100];
    std::cin >> N;
    for(long i=0; i<N-1; i++){
        std::cin >> B[i];
    }
    long sum=0;
    sum+=B[0];
    sum+=B[N-2];
    for(long i=1; i<N-1;i++){
        if(B[i]<B[i-1]){
            sum+=B[i];
        }else{
            sum+=B[i-1];
        }
    }
    std::cout << sum << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef long long ll;

bool srt(const pair <pair <string, int>, int>& a, const pair <pair <string, int>, int>& b){
	if(a.first.first ==  b.first.first){
		return a.first.second >  b.first.second;
	}
	return a.first.first <  b.first.first;
}

int main(){
	int N;
	cin >> N;
	string s;
	int p;
	vector< pair <pair <string, int>, int> > X; //nombre, puntos  , id
	for ( int i = 0 ; i < N; i++){
		cin >> s >> p;
		X.push_back( make_pair ( make_pair(s, p) , (i + 1) ) );
	}
	sort(X.begin(), X.end(), srt);
	for( auto y : X){
		cout << y.second << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x1 = sc.nextInt();
    int y1 = sc.nextInt();
    int x2 = sc.nextInt();
    int y2 = sc.nextInt();
    int x3, y3, x4, y4;
    int x = x2 - x1;
    int y = y2 - y1;
    
    x4 = -y + x1;
    y4 = x + y1;
    x3 = x4 + x;
    y3 = y4 + y;
    
    System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);
  }
}

Measured memory_bytes: 23252
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}



int main(){
	ll A, B, K;
	cin >> A >> B >> K;
	if(A >= K){
		cout << A-K << " " << B << endl;
		return 0;
	}
	cout << 0 << " " << max((ll)0, B - (K-A)) << endl;
	return 0;

}



Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	string s,t;
	int ans=0;
	cin>>s>>t;
	for(int i=0;i<s.size();i++)
		ans+=s[i]!=t[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3960
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

a, b, c, d = map(int, input().split())

num_all = b - a + 1
num_c = (b // c) - (a // c)
if a % c == 0:
    num_c += 1
num_d = (b // d) - (a // d)
if a % d == 0:
    num_d += 1
lcm_cd = lcm(c, d)
num_cd = (b // lcm_cd) - (a // lcm_cd)
if a % lcm_cd == 0:
    num_cd += 1

print(num_all - num_c - num_d + num_cd)


Measured memory_bytes: 3064
#include <vector>
#include <iostream>
using namespace std;
using ll = long long int;
 
int main(){
    int n; cin >> n;
    int current = 0;
    ll ans = 0;
    for(int i=0; i<n; i++){
        int a; cin >> a;
        if(i == 0){
            current++;
            if(a > 1){
                ans += a-1;
            }
            continue;
        }
        else if(a == current + 1){
            current++;
            continue;
        }
        if(a % (current + 1) == 0){
            ans += (a - 2) / (current + 1);
        }
        else{
            ans += (a - 1) / (current + 1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
S=input().split()
q=int(input())
T=input().split()

S=list(map(int,S))
T=list(map(int,T))

cnt=0

for i in range(q):
	left=0
	right=n-1
	while left<=right:
		mid=int((left+right)/2)
		if S[left]>T[i] and S[right]<T[i]:
			break
		if S[mid]==T[i]:
			cnt+=1
			break
		elif S[mid]>T[i]:
			right=mid-1
		elif S[mid]<T[i]:
			left=mid+1

print(cnt)


Measured memory_bytes: 19616
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
template<class T>bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
// clang-format on

void solve(long long X) {
  ll minnum = X / 100;
  // ll maxnum = X / 105;
  ll minmod = X % 100;
  // ll maxmod = X % 105;

  cout << ((long double)minmod / minnum <= 5.0 ? 1 : 0) << endl;
  return;
}

int main() {
  long long X;
  scanf("%lld", &X);
  solve(X);
  return 0;
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

const int N=1e5+19;

struct Edge{
	int y,nxt;
} E[N*2];
int las[N],val[N],mx[N],dep[N];
int n,cnt,m,x,y;

void Link(int x,int y){
	E[cnt]=(Edge){y,las[x]};las[x]=cnt++;
	E[cnt]=(Edge){x,las[y]};las[y]=cnt++;
}
void dfs(int x,int fa){
	if (~val[x]) mx[x]=val[x]-dep[x];
	for (int i=las[x],y;~i;i=E[i].nxt)
		if ((y=E[i].y)!=fa){
			dep[y]=dep[x]+1;
			dfs(y,x);
			mx[x]=max(mx[x],mx[y]);
		}
}
void work(int x,int fa){
	if (val[x]==-1){
		if (val[fa]-1>=mx[x]+dep[x]){
			val[x]=val[fa]-1;
		} else{
			val[x]=val[fa]+1;
		}
	}
	for (int i=las[x],y;~i;i=E[i].nxt)
		if ((y=E[i].y)!=fa){
			work(y,x);
		}
}
void check(int x,int fa){
	if (x>1&&abs(val[x]-val[fa])!=1){
		puts("No");
		exit(0); 
	}
	for (int i=las[x],y;~i;i=E[i].nxt)
		if ((y=E[i].y)!=fa){
			check(y,x);
		}
}

int main(){
	memset(las,-1,sizeof(las));
	memset(val,-1,sizeof(val));
	n=IN();
	For(i,1,n) Link(IN(),IN());
	m=IN();
	while (m--){
		x=IN(),y=IN();
		val[x]=y;
	}
	memset(mx,200,sizeof(mx));
	dfs(1,-1);
	if (val[1]==-1){
		val[1]=mx[1]+dep[1];
	}
	work(1,-1);
	check(1,-1);
	puts("Yes");
	For(i,1,n+1) printf("%d\n",val[i]);
}

Measured memory_bytes: 8704
#include<stdio.h>
#define mod 1000000000+7

long long row(int n,int x){
  long long ans=1;
  for(int i=0;i<n;i++){
    ans*=x;
	ans%=mod;
  }
  return ans;
}

int main(void){
	int n;
	long long ans;

	scanf("%d",&n);
    ans=row(n,10)+row(n,8);
	ans%=mod;
for(int i=0;i<2;i++){
    ans-=row(n,9);
	ans%=mod;
	if(ans<0) ans+=mod;
}

	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3224
while True:
    H,W = [int(i) for i in input().split()]

    if H == 0 and W == 0:
        break

    else:
        for i in range(H):
            if i == 0 or i == H-1:
                for j in range(W):
                    print("#", end="")

            else:
                for j in range(W):
                    if j == 0 or j == W-1:
                        print("#", end="")
                    else:
                        print(".", end="")
            print()
    print()



Measured memory_bytes: 7012
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <map>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

int limit;
int as[100000+10];
int bs[100000+10];
int n;


ll calc(int permitted) {
  ll res = 0;
  REP(i, n) {
    if((as[i] & permitted) == as[i]) {
      res += bs[i];
    }
  }
  return res;
}

int main(void) {
  scanf("%d%d", &n, &limit);
  REP(i, n) {
    scanf("%d%d", &as[i], &bs[i]);
  }
  ll res = calc(limit);
  REP(i, 30) {
    if(limit & (1 << i)) {
      int mask = (1 << i) - 1;
      int pat = (limit & ~(1 << i) & ~mask) | mask;
      res = max(res, calc(pat));
    }
  }
  printf("%lld\n", res);
  
  return 0;
}


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

#include <math.h>
#include <stdlib.h>


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


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int a, b; cin >> a >> b;
    int ans = 0;
    if(b < a) swap(a,b);
    for(int i = 0; i < b; i++) ans = ans * 10 + a;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long a, b, c;
	scanf("%lld%lld%lld", &a, &b, &c);
	long long ans = 0x3fffffffffffffffll;
	ans = min(ans, (b & 1) * (a * c));
	ans = min(ans, (a & 1) * (b * c));
	ans = min(ans, (c & 1) * (a * b));
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 256
N, *A = $stdin.read.split.map(&:to_i)
CT = Array.new(10**5, 0)

A.each do |a|
  CT[a] += 1
  if (N-a).even? || CT[a] > 2
    puts 0; exit
  end
end

if N.odd? && CT[0] != 1
  puts 0; exit
end
p((2**(N/2)) % (10**9+7))


Measured memory_bytes: 9852
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String a = sc.next();
		String b = sc.next();
		String c = sc.next();

		if(a.charAt(a.length() -1) == b.charAt(0)
				&& b.charAt(b.length() -1) == c.charAt(0)) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}

	}

}


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

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a==b)
    {
        cout<<"Draw"<<endl;
    }
    else if(a>b && b!=1)
    {
        cout<<"Alice"<<endl;
    }
    else if(a<b && a !=1)
    {
        cout<<"Bob"<<endl;
    }
    else if(a>b && b==1)
    {
        cout<<"Bob"<<endl;
    }
    else if(a<b && a==1)
    {
        cout<<"Alice"<<endl;
    }
    return 0;
}




Measured memory_bytes: 256
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
x3, y3 = map(int, input().split())
v1 = x1 + y1 * 1j
v2 = x2 + y2 * 1j
v3 = x3 + y3 * 1j

v12 = v2 - v1
v13 = v3 - v1
s = abs(v12.real * v13.imag - v12.imag * v13.real) / 2
d12 = abs(v12)
d23 = abs(v3 - v2)
d13 = abs(v13)
r = 2 * s / (d12 + d23 + d13)
a = max(d12, d23, d13)
print(a * r / (2 * r + a))


Measured memory_bytes: 3064
import sys

stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


a = stdin.readline().split()
A = int(a[0])
B = float(a[1])


print(int(A * int(B * 100 + 0.1) // 100))


Measured memory_bytes: 61920
N, K = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for _ in range(K)]
mod = 998244353


class SegmentTree():
    def __init__(self, array, f, ti):
        """
        Parameters
        ----------
        array : list
            to construct segment tree from
        f : func
            binary operation of the monoid
        ti : 
            identity element of the monoid
        """
        self.f = f
        self.ti = ti
        self.n = n = 2**(len(array).bit_length())
        self.dat = dat = [ti] * n + array + [ti] * (n - len(array))
        for i in range(n - 1, 0, -1):  # build
            dat[i] = f(dat[i << 1], dat[i << 1 | 1])

    def update(self, p, v):  # set value at position p (0-indexed)
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = v
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])

    def operate_right(self, p, v):  # apply operator from the right side
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = f(dat[p], v)
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])

    def operate_left(self, p, v):  # apply operator from the left side
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = f(v, dat[p])
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])

    def query(self, l, r):  # result on interval [l, r) (0-indexed)
        f, ti, n, dat = self.f, self.ti, self.n, self.dat
        vl = vr = ti
        l += n
        r += n
        while l < r:
            if l & 1:
                vl = f(vl, dat[l])
                l += 1
            if r & 1:
                r -= 1
                vr = f(dat[r], vr)
            l >>= 1
            r >>= 1
        return f(vl, vr)


st = SegmentTree([0] + [1] + [0] * N, lambda x, y: x + y, 0)
for i in range(2, N + 1):
    v = 0
    for l, r in LR:
        il = max(0, i - r)
        ir = max(0, i - l + 1)
        v += st.query(il, ir)
        v %= mod
    st.update(i, v)
ans = st.query(N, N + 1)
print(ans)


Measured memory_bytes: 92932
N,M=map(int,input().split())
s_l=[]
c_l=[]
ans=0
order_l=[-1]*3
if M==0 and N>1:
	print(10**(N-1))
	exit()
if M==0 and N==1:
	print(0)
	exit()
for _ in range(M):
	S,C=list(map(int,input().split()))
	s_l.append(S-1)
	c_l.append(C)
for i in range(M):
	if order_l[s_l[i]] ==-1 or order_l[s_l[i]] ==c_l[i]:
		order_l[s_l[i]]=c_l[i]
	else:
		print(-1)
		exit()
if order_l[0]==0:
	if N>1:
		print(-1)
		exit()
	else:
		print(0)
		exit()
else:
	order_l[0]=max(1,order_l[0])
order_l[1]=max(0,order_l[1])
order_l[2]=max(0,order_l[2])
if N>1:
  ans=order_l[0]*10**(N-1)+order_l[1]*10**(N-2)+order_l[2]*(max(0,N-2))
else:
  ans=order_l[0]
print(ans)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

N = int(input())
deck = list(map(int, input().split()))
Alice = 0
Bob = 0

deck.sort(reverse=True)
for i, card in enumerate(deck):
    if i % 2 == 0:
        Alice += card
    else:
        Bob += card

print(Alice - Bob)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int sz = 1 << 16;
typedef pair< unsigned short, int > Pi;
vector< Pi > seg[2 * sz + 1];
int x[500000], y[500000];
int sx[20000], sy[20000], tx[20000], ty[20000];
vector< pair< unsigned short, Pi > > buff;
vector< int > nums, nums2;
vector< int > ret;
void InitRange(int k, int l, int r) {
  if(l + 1 >= r) {
    return;
  } else {
    InitRange(2 * k + 1, l, (l + r) >> 1);
    InitRange(2 * k + 2, (l + r) >> 1, r);
    if(k >= 114) {
      seg[k].resize(seg[2 * k + 1].size() + seg[2 * k + 2].size());
      merge(seg[2 * k + 1].begin(), seg[2 * k + 1].end(), seg[2 * k + 2].begin(), seg[2 * k + 2].end(), seg[k].begin());
    }
  }
}
void PrintRange(unsigned short a, unsigned short b, unsigned short low, unsigned short high, int k, int l, int r) {
  if(a >= r || b <= l) {
    return;
  } else if(a <= l && r <= b && k >= 114) {
    for(vector< Pi >::iterator it = lower_bound(seg[k].begin(), seg[k].end(), Pi(low, -1)); it != seg[k].end() && it -> first < high; it++) { 
      ret.push_back(it -> second);
    }
  } else {
    PrintRange(a, b, low, high, 2 * k + 1, l, (l + r) >> 1);
    PrintRange(a, b, low, high, 2 * k + 2, (l + r) >> 1, r);
  }
}
  
int main() {
  int n, q;
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    scanf("%d %d", &x[i], &y[i]);
  }
  scanf("%d", &q);
  for(int i = 0; i < q; i++) {
    scanf("%d %d %d %d", &sx[i], &tx[i], &sy[i], &ty[i]);
    nums.push_back(sx[i] - 1);
    nums.push_back(tx[i]);
    nums2.push_back(sy[i] - 1);
    nums2.push_back(ty[i]);
  }
  sort(nums.begin(), nums.end());
  nums.erase(unique(nums.begin(), nums.end()), nums.end());
  sort(nums2.begin(), nums2.end());
  nums2.erase(unique(nums2.begin(), nums2.end()), nums2.end());
  for(int i = 0; i < n; i++) {
    x[i] = lower_bound(nums.begin(), nums.end(), x[i]) - nums.begin();
    y[i] = lower_bound(nums2.begin(), nums2.end(), y[i]) - nums2.begin();
    buff.push_back(make_pair(x[i], make_pair(y[i], i)));
  }
  sort(buff.begin(), buff.end());
  for(int i = 0; i < n; i++) {
    seg[buff[i].first + sz - 1].push_back(buff[i].second);
  }
  InitRange(0, 0, sz);
 
  for(int i = 0; i < q; i++) {
    sx[i] = lower_bound(nums.begin(), nums.end(), sx[i]) - nums.begin();
    tx[i] = upper_bound(nums.begin(), nums.end(), tx[i]) - nums.begin();
    sy[i] = lower_bound(nums2.begin(), nums2.end(), sy[i]) - nums2.begin();
    ty[i] = upper_bound(nums2.begin(), nums2.end(), ty[i]) - nums2.begin();

    PrintRange(sx[i], tx[i], sy[i], ty[i], 0, 0, sz);
    sort(ret.begin(), ret.end());
    for(vector< int >::const_iterator it = ret.begin(); it != ret.end(); it++) {
      printf("%d\n", *it);
    }
    printf("\n");
    ret.clear();
  }
  
}

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

int main(void) {
    string s;
    cin >> s;
    string display = "";
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == 'B' && display != "") {
            display = display.substr(0, display.length() - 1);
        } else if (s[i] == '0' || s[i] == '1') {
            display += s[i];
        }
    }
    cout << display << endl;
    return 0;
}


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

const int N = 2e1 + 5;
int main() {
    int d, t, s;
    cin >> d >> t >> s;
    if (t * s >= d) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>

typedef long long ll;

using namespace std;

int main(){
    ll mod = pow(10, 9) + 7;
    ll n, k;
    cin >> n >> k;

    ll max = 0;
    ll min = 0;
    ll ans = 0;

    for(ll i = k; i <= n; i++){
        min = i * (0 + i - 1) / 2;
        max = i * (n + (n - i + 1)) / 2;
        ans += (max - min + 1);
        ans %= mod;
    }
    cout << ans + 1 << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define PI 3.1415926535898

int main(){
	double c;
	double a,b,h,m;
	cin>>a>>b>>h>>m; 
	double cal=abs(h*30+m/2-m*6);
	if(cal>=180) cal=360-cal;
	double val=PI/180;
	double ret=cos(cal*val);
	double ans=sqrt(a*a+b*b-2*a*b*ret);
	printf("%.10lf\n",ans);
	return 0;
} 

Measured memory_bytes: 4100
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int F(int a, int b)
{
    return (a + b - 1) / b * b;
}

void _main()
{
    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, 0, N) cin >> A[i];

    const ll sum = accumulate(all(A), 0);

    deque<int> divisors;
    for (int i = 1; i * i <= sum; ++i) {
        if (sum % i != 0)continue;
        divisors.push_back(i);
        if (i * i != sum)divisors.push_back(sum / i);
    }
    sort(rbegin(divisors), rend(divisors));

    for (const ll& v : divisors)
    {
        vector<pair<int, int>> ds;
 
        rep(i, 0, N)
        {
            const int x = F(A[i], v);
            const int d0 = x - A[i];
            const int d1 = A[i] - (x - v);
            ds.emplace_back(d0, d1);
        }
 
        sort(all(ds));
 
        vector<pair<int, int>> dsum(N + 1, make_pair(0, 0));
        rep(i, 0, N)
        {
            dsum[i + 1].first = dsum[i].first + ds[i].first;
            dsum[i + 1].second = dsum[i].second + ds[i].second;
        }
 
        rep(i, 0, N)
        {
            if (dsum[i + 1].first == (dsum[N].second - dsum[i + 1].second))
            {
                if (dsum[i + 1].first <= K)
                {
                    cout << v << endl;
                    return;
                }
            }
        }
    }
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

int N, M, Q;
vector<ll> a, b, c, d;
ll ans = 0;

void dfs(vector<ll> v) {
    ll sn = 1;
    if (v.size() != 0) sn = v.back();
    if (v.size() == N) {
        ll score = 0;
        rep(j, Q) {
            if (v[b[j]-1] - v[a[j]-1] == c[j]) {
                score += d[j];
            }
        }
        ans = max(ans, score);
        return;
    }
    REPS(i, sn, M) {
        vector<ll> tmp = v;
        tmp.pb(i);
        dfs(tmp);
    }
    return;
}

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

    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    rep(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i];

    dfs(vector<ll> {});

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

Measured memory_bytes: 3620
N = int(input())
A = input()
B = input()
C = input()

ans = 0
for i in range(N):
    if A[i] == B[i]:
        if B[i] != C[i]:
            ans += 1
    else:
        if B[i] == C[i]:
            ans += 1
        else:
            if C[i] == A[i]:
                ans += 1
            else:
                ans += 2
print(str(ans))

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
/*
题意:三种操作:添加0或者1到字符末尾,删除最右字符(若字符为空,则不变) 
给出string s 问有多少种长度为N的操作,能得到s n,|s|<=5000 .
*/
#define ll long long
const int mod=1e9+7;
int len,N,n;
ll dp[5021][5021];
string s;
ll powmod(ll x,ll n)
{
	ll s=1;
	while(n)
	{
		if(n&1)
			s=(s*x)%mod;
		x=(x*x)%mod;
		n>>=1;
	}
	return s;
}
int main(){
   dp[0][0]=1;
   for(int i=0;i<=5000;++i){
   	    for(int j=0;j<=5000;++j){
   	   	    if(dp[i][j]==0)continue;
   	   	    dp[i+1][j+1]=(dp[i+1][j+1]+2ll*dp[i][j]%mod)%mod;
   	   	    (dp[i+1][max(0,j-1)]+=dp[i][j]%mod)%=mod;
		}
   } 
   cin>>n>>s;
   ll l=s.size();
   ll ans=dp[n][l];
   ll t=powmod(2ll,l);
   ans=ans*powmod(t,mod-2)%mod;
   cout<<ans;
	return 0;
}


Measured memory_bytes: 195072
n, a, b = map(int, input().split())
s = input()
path_cnt = 0
b_cnt = 0
for i in range(n):
    if path_cnt < a + b:
        if s[i] == 'a':
            print('Yes')
            path_cnt += 1
        elif s[i] == 'b' and b_cnt < b:
            print('Yes')
            path_cnt += 1
            b_cnt += 1
        else:
            print('No')
    else:
        print('No')
            


Measured memory_bytes: 50136
/*
Original problem: https://atcoder.jp/contests/dp/tasks/dp_d
Author: sammochen
*/

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)

#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;

namespace SOLVE {
    void main() {
        ll n, w, a, b;
        cin >> n >> w;
        vector < PLL > objs(n);

        REP(i, 0, n) {
            cin >> a >> b;
            objs[i] = MP(a, b);
        }

        VLL dp(w + 1, -1); // dp[i] stores the best value for weight i

        dp[0] = 0;
        ll ans = 0;
        REP(i, 0, n) {
            RREP(oldw, w, 0) {
                if (dp[oldw] != -1) {
                    ll neww = oldw + objs[i].first;
                    if (neww <= w) {
                        dp[neww] = max(dp[neww], dp[oldw] + objs[i].second);
                    }
                }
            }
        }

        REP(weight, 0, w + 1) {
            ans = max(ans, dp[weight]);
        }
        cout << ans << endl;
    }
}


signed main() {
	int t;
	t = 1;
	// cin >> t;
	while (t--) {
		SOLVE::main();
	}

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

#define MAX 100

int main(void) {
  int k, i;
  char s[MAX];
  
  for (i = 0; i < MAX; i++) {
    s[i] = '\0';
  } 
  
  scanf("%d", &k);
  scanf("%s", s);
  
  if (strlen(s) <= k) {
    printf("%s\n", s);
  } else {
    for (i = 0; i < k; i++) {
      printf("%c", s[i]);
    } 
    printf("...\n");

  } 
  
  return 0;
} 




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

using namespace std;




int main(){
	int k,i,j,t;
	string s;
	cin>>k>>s;
	for(i=0;i<s.size();i++){
		s[i]+=k;
		if(s[i]>'Z')s[i]='A'+(s[i]%'Z')-1;

	}
	cout<<s;



    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define MAX 1000000
using namespace std;
int N;
char S[MAX];

int main(){
cin >> N >> S;
int ans = 1;
char buf = S[0];
for(int i=0;i<N;i++){
	if(buf == S[i]) continue;
	ans++;
	buf = S[i];
}
cout << ans << endl;
}


Measured memory_bytes: 384
// think twice code once
// Start:[]
// End  :[]
/*{{{*/
#include <bits/stdc++.h>
using namespace std;

#define rep(i, x, y) for(int i = (x), _ = (y); i <= _; ++ i)
#define per(i, x, y) for(int i = (x), _ = (y); i >= _; -- i)
#define dprintf(...) fprintf(stderr, __VA_ARGS__)
#define disp(x) cout << #x << " = " << x << "; "
#ifdef __linux__
#define getchar getchar_unlocked
#define LLFORMAT "%lld"
#else
#define LLFORMAT "%I64d"
#endif

typedef long long LL;

template <class T> bool chkmin(T& a, T b) { return a > b ? a = b, true : false; }
template <class T> bool chkmax(T& a, T b) { return a < b ? a = b, true : false; }

template <class T> void read(T& a) {
	char c = getchar(); T f = 1; a = 0;
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) a = a * 10 + c - '0';
	a *= f;
}
/*}}}*/

const int maxN = 55;

int a[maxN][maxN], b[maxN][maxN];
int N, M;

int main()
{
#ifdef Leeson
	freopen("tmp.in", "r", stdin);
	freopen("tmp.out", "w", stdout);
#endif

	read(N); read(M);
	rep(i, 1, N) rep(j, 1, N)
	{
		char c = getchar();
		while(c != '.' && c != '#') c = getchar();
		a[i][j] = c == '.';
	}

	rep(i, 1, M) rep(j, 1, M)
	{
		char c = getchar();
		while(c != '.' && c != '#') c = getchar();
		b[i][j] = c == '.';
	}

	rep(i, 1, N) rep(j, 1, N) if(i + M - 1 <= N)
	{
		bool ff = 1;
		rep(x, 1, M) rep(y, 1, M)
			if(a[i + x - 1][j + y - 1] != b[x][y])
			{
				ff = 0;
				break;
			}
		if(ff)
		{
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
  int num_people, interval;
  std::cin >> num_people >> interval;

  int total, start;
  total = start = 0;
  for (int i = 0; i < num_people; i++) {
    int time;
    std::cin >> time;
    int end = time + interval;

    if (start < time) start = time;
    total += end - start;
    start = end;
  }
  std::cout << total << std::endl;

  return 0;
}

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

int a[100000];
int search(int k){
  if(a[k]==k){
      return k;
  }
  int p=search(a[k]);
  a[k]=p;
  return p;
}

int main(){
  for(int i=0;i<100000;i++){
    a[i]=i;
  }
  int n,m,p,q,r,s,t;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>p>>q;
    a[search(p)]=search(q);
  }
  cin>>r;
  for(int i=0;i<r;i++){
    cin>>s>>t;
    if(search(s)==search(t)){
        cout<<"yes"<<endl;
    }
    else{
        cout<<"no"<<endl;
    }
  }
  return 0;
}




Measured memory_bytes: 4008