akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> P;

int main(){
	string s ;
	cin >> s;
	bool one = false;//falseになったらおしまいして、WAを出力
	bool two = false;
	bool three = false;
	//1つ目の条件１文字目が大文字のAであるか
	if(s.at(0)=='A'){
	  one = true;
	  }
//	  cout <<one<<endl;
	int a =s.size();
	//ch(a,'a');
	int count = 0;
	int k = -1;//Cが何番目か
	for(int i =2;i < a-1;i++){
		if(s.at(i)=='C'){
		  count++;
		  if(count==1){
			  k = i;
		//	  ch(k,'k');
			}
		  two = true;
		  if(count>=2){
			  two =false;
			  break;
			}
			}
	  }
//	  cout<<two<<endl;
	  //最後に他はすべて小文字かどうか。
	  if(two){
		for(int i = 1 ;i < a;i++){
			  if(i!=k){
			  if(s.at(i)<='z'&&s.at(i)>='a'){
			//	cout<<s.at(i)<<"<="<<'z'<<endl;
				three = true;
				}
				
				else if(s.at(i)>='A'&&s.at(i)<='Z'){
				  three =false;
				  break;}
				  }
			}
		}
//		cout<<three<<endl;
		if(one&&two&&three){
			cout<<"AC"<<endl;
		  }
		  else{
			  cout <<"WA"<<endl;
			}
	  }



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

using namespace std;

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

	int h, w;
	cin >> h >> w;
	string s[50];
	for(int i = 0; i < h; i++)cin >> s[i];
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++)
		{
			if(s[i][j] == '#')
			{
				bool ok = false;
				if(i > 0 && s[i - 1][j] == '#')ok = true;
				if(i < h-1 && s[i + 1][j] == '#')ok = true;
				if(j > 0 && s[i ][j-1] == '#')ok = true;
				if(j < w-1 && s[i ][j+1] == '#')ok = true;
				if(!ok)
				{
					cout << "No" << endl;
					return 0;
				}
			}
		}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
main(){
	for(int Q,L,q,x;scanf("%d%d",&Q,&L),Q;puts("end"))
		for(std::vector<int>v;Q--;){
			if(v.size()>L)v.erase(v.begin());
			if(scanf("%d%d",&q,&x),!q)v.push_back(x);
			if(q==1)v.erase(v.begin()+x-1);
			if(q==2)printf("%d\n",v[x-1]);
			if(q==3)v.erase(std::find(v.begin(),v.end(),x));
		}
}

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

int main(){
  int K,N;
  cin >> K >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++)  cin >> A.at(i);

  int ans=A.at(N-1)-A.at(0);
  for(int i=1;i<N;i++){
    int tmp=K-(A.at(i)-A.at(i-1));
    ans=min(ans,tmp);
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;



int main(int argc, char *argv[])
{
	int n;
	double jpy = 0;
	double btc = 0;


	//input
	cin >> n;

	for (int i = 0; i < n; i++){
		double val;
		string cur;

		cin >> val >> cur;

		if (cur == "JPY"){
			jpy += val;
		}
		else{
			btc += val;
		}
	}






	//calc
	double ans = 0;
	ans = jpy + btc * 380000.0;




	//ans
	cout << ans << endl;


	return 0;
}


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

int main() {
  string s;
  cin>>s;
  bool ans=true;
  for(int i=0;i<(s.size())/2;i++){
    if(s[i]!=s[s.size()-i-1])ans=false;
    if(s[i]!=s[(s.size())/2-i-1])ans=false;
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> n(3);
  REP(i, 3) cin >> n[i];

  int k;
  cin >> k;
  int maxi = -1;
  int max = -10;
  for(int i = 0; i < 3; i++) {
    if(max < n[i]) {
      maxi = i;
      max = n[i];
    }
  }
  int ans = 0;
  for(int i = 0; i < 3; i++) {
    if(i == maxi) {
      ans += n[i] * pow(2, k);
      continue;
    }
    ans += n[i];
  }

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

Measured memory_bytes: 256
// Last Change: 07/15/2019 20:06:39.
//////////////////////////////////////////////////////////////////////////////
//ワーシャルフロイド法：全点対最短経路問題, O(V^3)
//下記は無向グラフの場合。
//
// Reference:
//   https://triple-four.hatenablog.com/entry/2019/04/02/143939
//   http://dai1741.github.io/maximum-algo-2012/docs/shortest-path/
// 上がわかりやすい。
//////////////////////////////////////////////////////////////////////////////
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

//'100'は適宜変更。入れないとあふれる。
const ll INF = numeric_limits<ll>::max() / 100;
// cost[i][j]:iからjへ行くまでの最短コスト
vector<vector<ll>> cost;

// i->jへの既知のルートと、kを経由していくのとでどちらが近いか。
bool WarshallFloyd(int V) {
  for (int k = 0; k < V; ++k) {
    for (int i = 0; i < V; ++i) {
      for (int j = 0; j < V; ++j) {
        if (cost[i][k] != INF and cost[k][j] != INF)
          cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
      }
    }
  }

  //負の経路判定
  for (int i = 0; i < V; ++i) {
    if (cost[i][i] < 0) {
      return true;
    }
  }

  return false;
}

int main() {
  //頂点数, 辺の数
  int V, E;
  cin >> V >> E;

  cost.assign(V, vector<ll>(V, INF));

  for (int i = 0; i < V; ++i) {
    cost[i][i] = 0;
  }

  // 辺
  for (int i = 0; i < E; ++i) {
    int u, v;
    ll c;
    cin >> u >> v >> c;

    cost[u][v] = min(cost[u][v], c);
  }

  bool flag = WarshallFloyd(V);

  if (flag) {
    cout << "NEGATIVE CYCLE" << endl;
  } else {
    for (int i = 0; i < V; ++i) {
      for (int j = 0; j < V; ++j) {
        if (cost[i][j] == INF) {
          cout << "INF";
        } else {
          cout << cost[i][j];
        }
        if (j < V - 1) {
          cout << " ";
        }
      }
      cout << endl;
    }
  }
}




Measured memory_bytes: 3236
def solve(aa,bb,cc,dd):
  a,b,c,d=aa,bb,cc,dd
  mx=my=0
  for i in range(1,31):
    if a==c and a%3==2 and abs(b-d)>=2:mx=i
    if b==d and b%3==2 and abs(a-c)>=2:my=i
    a=0--a//3
    b=0--b//3
    c=0--c//3
    d=0--d//3
  a,b,c,d=aa,bb,cc,dd
  if mx==my==0:return abs(a-c)+abs(b-d)
  if mx<my:
    ans=abs(a-c)
    mi=3**(my-1)
    ma=2*3**(my-1)+1
    bd=(3**my)*((0--b//(3**my))-1)
    b-=bd
    d-=bd
    ans+=min(abs(mi-b)+abs(mi-d),abs(ma-b)+abs(ma-d))
    return ans
  if mx>my:
    ans=abs(b-d)
    mi=3**(mx-1)
    ma=2*3**(mx-1)+1
    ac=(3**mx)*((0--a//(3**mx))-1)
    a-=ac
    c-=ac
    ans+=min(abs(mi-a)+abs(mi-c),abs(ma-a)+abs(ma-c))
    return ans
  if mx==my==0:return abs(a-c)+abs(b-d)
  ans=1/0#正しければ実行されないはず
q=int(input())
for _ in range(q):
  a,b,c,d=map(int,input().split())
  print(solve(a,b,c,d))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    string s;
    cin >> s;
    ll ans=0;
    ll n=s.size();
    vector<ll>a(n+1,0);
    for(ll i=0;i<n;i++){
        if(s[i]=='<'){
            a[i+1]=max(a[i+1],a[i]+1);
        }
    }
    for(ll i=n-1;i>=0;i--){
        if(s[i]=='>'){
            a[i]=max(a[i],a[i+1]+1);
        }
    }
    for(ll i=0;i<n+1;i++){
        ans+=a[i];
    }
    cout << endl;
    cout << ans << endl;
}

Measured memory_bytes: 7664
while true
  n, m = gets.chomp.split(' ').map(&:to_i)
  break if n == 0 && m == 0
  data = []
  n.times do
    d, p = gets.chomp.split(' ').map(&:to_i)
    data << [ p, d ]
  end
  data.sort!

  while true
    if m > data[-1][1]
      m -= data[-1][1]
      data.pop
    elsif m == data[-1][1]
      data.pop
      break
    elsif m < data[-1][1]
      data[-1][1] -= m
      break
    end 
    break if data.size == 0
  end

  sum = 0
  data.each do |ary|
    sum += ary[0] * ary[1]
  end
  puts sum
end

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

int main(){
  int n,m,q;
  int64_t g;
  g=0;
  map<int,int> bro;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> m;
    if(bro.count(m)){
      bro[m] += 1;
    }
    else{
      bro[m] = 1;
    }
    g+=m;
  }
  cin >> q;
  for(int i=0;i<q;i++){
    int b,c;
    cin >> b >> c;
    if(bro.count(b)){
      g += bro[b]*(c-b);
      if(bro.count(c)){
        bro[c] += bro[b];
        bro[b] = 0;
      }
      else{
        bro[c] = bro[b];
        bro[b] = 0;
      }
    }
    cout << g << endl;
  }
}

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

int main(int argc, char const *argv[])
{
    string num;
    string mum;
    string mim;
    cin >> num >> mum >> mim;
    char A = toupper(num[0]);
    char B = toupper(mum[0]);
    char C = toupper(mim[0]);

    cout<< A << B << C<< endl;

    return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  
  if(a == 1 || b == 1){
    if(a == 1 && b != 1) cout << "Alice" << endl;
    if(a != 1 && b == 1) cout << "Bob" << endl;
    if(a == 1 && b == 1) cout << "Draw" << endl;
  }else{ //a,bともに1以外であれば通常の大小関係のみで判定可能
    if(a>b) cout << "Alice" << endl;
    if(a==b) cout << "Draw" << endl;
    if(a<b) cout << "Bob" <<endl;
  }
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod(ll a){
  return a % 1000000007;
}


int main(){
  ll n,k; cin >> n >> k; ll sum = 0;
  
  for(ll i=0; i < n; i++){
    ll x; cin >> x;
    sum += min (2*x,2*(k-x));
  }
  
  cout << sum << endl;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, H, W;
    cin >> N >> H >> W;
    vector<int> X(N);
    for (int i = 0; i < N; i++) cin >> X[i];
    vector<int> window(N * W, 1);
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            for (int j = i * W; j < (i + 1) * W; j++) {
                window[j]--;
            }
            for (int j = i * W + X[i]; j < (i + 1) * W + X[i]; j++) {
                window[j]++;
            }
        }
        else {
            for (int j = i * W; j < (i + 1) * W; j++) {
                window[j]--;
            }
            for (int j = i * W - X[i]; j < (i + 1) * W - X[i]; j++) {
                window[j]++;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < N * W; i++) {
        if (window[i] == 0) ans++;
    }
    ans *= H;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3220
#include <stdio.h>
#include <numeric>
#include <time.h>
#include <bitset>
#include <string.h>
#include <stack>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <math.h>
#include <queue>
#include <complex>
#include <functional>
#include <limits.h>
using namespace std ;
typedef long long ll ;
typedef long double ld ;
typedef unsigned long long ull ;
#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define pi (acos(-1.0))
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define lson (o<<1),l,mid
#define rson (o<<1|1),mid+1,r
#define MP make_pair
#define sqr(x) ((x)*(x))
#define ALL(v) (v).begin(),(v).end()
#define showtime fprintf(stderr,"time = %.15f\n",clock() / (double)CLOCKS_PER_SEC)
const double eps = 1e-9 ;
const int MOD=(int)1e9+7,BAS=233;
inline int sign(double x){return x<-eps?-1:x>eps;}
inline int clz(int x){return __builtin_clz(x);}
inline int clz(ll x){return __builtin_clzll(x);}
inline int lg2(int x){return !x ? -1 : 31-clz(x);}
inline int lg2(ll x){return !x ? -1 : 63-clz(x);}
int AP (char *s) {
	unsigned hash=0;
	for(int i=0; s[i]; i++){
		if (i & 1) hash ^= (~((hash<<11)^s[i]^(hash>>5)));
		else hash ^= ((hash<<7)^s[i]^(hash>>3));
   } return hash & 0x7FFFFFFF;
}

const int M = 10;
vector<int> g[M];
int n, m;
bool vis[M];

int dfs (int u,int deep) {
	if (deep==n) return 1;
	int ret=0;
	for (int &v:g[u]) if (!vis[v]) {
		vis[v] = true;
		ret += dfs (v, deep+1);
		vis[v] = false;
	}
	return ret;
}

int main () {
	scanf ("%d%d", &n,&m);
	for (int i=0,u,v; i<m; i++) {
		scanf ("%d%d", &u,&v);
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	vis[1] = 1;
	printf ("%d\n", dfs(1,1));
	return 0;
}

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

int main(){
    string s;
    cin>>s;
    int a[4];
    rep(i,4)a[i]=s[i]-'0';
    for(int bit=0; bit<(1<<3); ++bit){
        int sum=a[0];
        rep(i,3){
            if(bit&(1<<i))sum+=a[i+1];
            else sum-=a[i+1];
        }
        if(sum==7){
            cout<<a[0];
            rep(i,3){
                if(bit&(1<<i))cout<<'+';
                else cout<<'-';
                cout<<a[i+1];
            }
            cout<<"=7"<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int h,w;
    cin >> h >> w;
    string s,a;
    rep(i, h)rep(j, w){
        cin >> s;
        if (s == "snuke") {
            a = j + 65;
            cout << a << i + 1 << endl;
            goto loopend;
        }
    }
loopend:;
    
    return 0;
}


Measured memory_bytes: 256
function main(input){
  var int = parseInt;
  var lines = input.split("\n");
  var typeCount = parseInt(lines[0].split(" ")[0]);
  var eatCount = parseInt(lines[0].split(" ")[1]);
  var numLines = lines.slice(1);
  var answer=0;
  
  for (var i=0;i<numLines.length;i++){
    numLines[i] = arrayParseInt(numLines[i].split(" "));
  }
  for(var i=0;i<2;i++){
    for(var j=0;j<2;j++){
      for(var k=0;k<2;k++){
        var cake = Array(typeCount).fill(0);
        for(var s =0; s<typeCount;s++){
          var sum = 0;
          var x,y,z;
          x = i===0 ? numLines[s][0] : numLines[s][0] *(-1);
          y = j===0 ? numLines[s][1] : numLines[s][1] *(-1);
          z = k===0 ? numLines[s][2] : numLines[s][2] *(-1);
          cake[s] = x+y+z;
        }
        cake.sort((a,b) =>b-a);
        var result = 0;
        for( var p =0;p<eatCount;p++){
          result += cake[p];
          
        }
        answer = Math.max(answer,result);
      }
    }
  }
  
  console.log(answer);
}

function arrayParseInt(array){
  return array.map(Number);
}

main(require("fs").readFileSync("/dev/stdin","utf-8"));

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

int main(){
  int n,M,p;
  while(cin>>n>>M>>p,n){
    vector<int> vec[7][7];
    for(int i=0;i<p;i++){
      int x,y;
      cin>>x>>y;
      vec[y-1][x-1].push_back(i+1);
    }

    int m[7][7][7][13][2]={0};

    int xyz[13][3]={{0,0,1},{0,1,1},{0,1,0},{1,0,0},{1,1,0},{1,0,1},{1,1,1},
		 {1,0,-1},{1,1,-1},{0,1,-1},{1,-1,0},{1,-1,1},{1,-1,-1}
    };
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	for(int k=0;k<(int)vec[i][j].size();k++){
	  for(int l=0;l<13;l++){
	    if(m[i][j][k][l][0] == 0){
	      m[i][j][k][l][0]=1;
	      m[i][j][k][l][1]=vec[i][j][k];
	    }
	    int x=j+xyz[l][1];
	    int y=i+xyz[l][0];
	    int z=k+xyz[l][2];
	    if(0<=x&&x<n&&0<=y&&y<n&&0<=z&&z<(int)vec[y][x].size()){
	      //	      cout<<vec[i][j][k]<<"-"<<vec[y][x][z];

	      if(vec[i][j][k]==0){
		m[y][x][z][l][0]=1;
		m[y][x][z][l][1]=vec[y][x][z];
		//		cout<<"a";
	      }else if((vec[y][x][z]&1)==(vec[i][j][k]&1)){
		m[y][x][z][l][0]=m[i][j][k][l][0]+1;
		if(m[y][x][z][l][0]>=M){
		  for(int a=1,ii=y,jj=x,kk=z;a<=M;a++,ii-=xyz[l][0],jj-=xyz[l][1],kk-=xyz[l][2]){
		    m[y][x][z][l][1]=max(m[y][x][z][l][1],vec[ii][jj][kk]);
		  }
		}
		//m[y][x][z][l][1]=max(m[i][j][k][l][1],vec[y][x][z]);
		//	       	cout<<"b";
	      }else{
		m[y][x][z][l][0]=1;
		m[y][x][z][l][1]=vec[y][x][z];
		//	       	cout<<"c";
	      }
	      //	      cout<<m[y][x][z][l][0]<<" ";
	    }
	  }
	}
      }
    } 
    int mi=(1<<30);
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	for(int k=0;k<(int)vec[i][j].size();k++){
	  for(int l=0;l<13;l++){
	    if(m[i][j][k][l][0] >= M)
	      mi=min(mi,m[i][j][k][l][1]);
	  }
	}
      }
    }
    if(mi==(1<<30)){
      cout<<"Draw"<<endl;
    }else if((mi&1)){
      cout<<"Black "<<mi<<endl;
    }else{
      cout<<"White "<<mi<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1260
#include<iostream>

using namespace std;

int main() {
	int a, b, c, e;
	


	cin >> a >> b >> c;

	
	e = a;
	if (e < b) {
		e = b;
	}
	if (e < c) {
		e = c;
	}


	if (e * 3 % 2 == (a+b+c) % 2) {
		cout << (e * 3 - (a+b+c)) / 2 << endl;
	}
	if (e * 3 % 2 != (a + b + c) % 2) {

		cout << (e * 3 + 3 - (a + b + c)) / 2 << endl;
	}
	
		


	
	


	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

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

	string s;
	cin>>s;
	deque<char> q;
	for(ll i=0;i<s.length();++i)
    {
        q.push_back(s[i]);
    }
    int ok=1;

    ll t;
    cin>>t;
    while(t--)
    {
        int aa;
        cin>>aa;
        if(aa==1)
        {
            ok=ok^1;
        }
        else{
            int f;
            cin>>f;
            char c;
            cin>>c;
            if(f==1){
                if(ok){
                    q.push_front(c);
                }
                else{
                    q.push_back(c);
                }
            }
            else{
                if(ok){
                    q.push_back(c);
                }
                else{
                    q.push_front(c);
                }
            }
        }
    }
    while(!q.empty())
    {
        if(ok)
        {cout<<q.front();
        q.pop_front();}
        else{
            cout<<q.back();
            q.pop_back();
        }
    }

	return(0);
}


Measured memory_bytes: 976
#include<stdio.h>
#define N 2000001
#define NIL 2000000001

int A[N];
int hs = 0;

void maxheap(int i){
  int le, ri, lar;
  int temp;
  le = 2*i;
  ri = 2*i+1;
  if(le <= hs && A[le] > A[i]) lar = le;
  else lar = i;
  if(ri <= hs && A[ri] > A[lar]) lar = ri;
  if(lar != i){
    temp = A[i];
    A[i] = A[lar];
    A[lar] = temp;
    maxheap(lar);
  }
}
void heapincrease(int i, int key){
  int temp;
  A[i] = key;
  while(i > 1 && A[i/2] < A[i]){
    temp = A[i];
    A[i] = A[i/2];
    A[i/2] = temp;
    i /= 2;
  }
}

void heapinsert(int key){
  hs++;
  A[hs] = NIL;
  heapincrease(hs, key);
}

int heapextract(void){
  int max;
  max = A[1];
  A[1] = A[hs];
  hs--;
  maxheap(1);
  return max;
}

int main(){
  int k;
  char word[20];
  while(1){
    scanf("%s", word);
    if(word[0] == 'i'){
      scanf("%d", &k);
      heapinsert(k);
    }
    if(word[0] == 'e' && word[1] == 'x') printf("%d\n", heapextract());
    if(word[0] == 'e' && word[1] == 'n') break;
  }
return 0;
}

Measured memory_bytes: 4696
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	ll n;
	ll sum = 0;
	ll sumj = 0;
	vector<ll> p;
	vector<ll> j;
	cin >> n;
	if(n==0) break;
	REP(i,n){
	    ll temp;
	    cin >> temp;
	    sum += temp;
	    p.PB(temp);
	}
	REP(i,n-1){
	    ll temp;
	    cin >> temp;
	    j.PB(temp);
	}
	sort(RALL(j));
	ll ans = n * sum;
	REP(i,n){
	    sumj += j[i];
	    ans = max(ans,(n-i-1) * (sum + sumj));
	}
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2652
nums = gets.split.map(&:to_i) 
points = Array.new(nums[0], nums[1] - nums[2])
answerers = nums[2].times.map { gets.to_i }

answerers.each do |a|
  points[a - 1] += 1 
end
points.each do |p|
  puts p > 0 ? 'Yes' : 'No'
end

Measured memory_bytes: 4148
<?php
$x = (int)trim(fgets(STDIN));

if ($x === 1) {
    echo 1 . PHP_EOL;
    exit;
}
$max = 0;
for ($i = 2; $i < $x; $i++) {
    for ($j = 2; $j < $x; $j++) {
        $n = pow($i, $j);
        if ($n > $x) {
            break;
        }
        if ($n > $max) {
            $max = $n;
        }
    }
}
echo $max . PHP_EOL;

Measured memory_bytes: 4728
import sys


#https://note.nkmk.me/python-union-find/
class AlgUnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

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

        if x == y:
            return

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

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

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

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

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

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

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

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    p = list(map(int, input().rstrip('\n').split()))
    uf = AlgUnionFind(n)
    for i in range(m):
        x, y = list(map(int, input().rstrip('\n').split()))
        uf.union(x-1, y-1)
    for i in range(n):
        p[i] = [p[i]-1, p[i]-1 == i]
    while True:
        c_sw = False
        for i in range(len(p)):
            tn = p[i][0]
            if not p[i][1] and not p[tn][1]:
                if uf.same(tn, p[tn][0]):
                    p[tn][0], p[i][0] = p[i][0], p[tn][0]
                    p[i][1] = p[i][0] == i
                    p[tn][1] = p[tn][0] == tn
                    c_sw = True
        if not c_sw:
            break
    cnt = 0
    for i in range(n):
        cnt += p[i][1]
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 103532
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_155
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] abc = ReadInts();
            if((abc[0]==abc[1]&&abc[1]!=abc[2])
                || (abc[1] == abc[2] && abc[2] != abc[0])
                || (abc[2] == abc[0] && abc[0] != abc[1]))
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
N = int(input())
h = list(map(int, input().split()))

dp = [float('inf')] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1], abs(h[i] - h[i-2]) + dp[i-2])

print(dp[-1])


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

int main(){
	int N;
	cin>>N;
	
	for(int i=0;i<=N/4;i++){
		for(int j=0;j<=N/7;j++){
			if(N==4*i+7*j){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	
	cout<<"No"<<endl;
	return 0;
}

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


public class Main {

	public static void main(String args[] ) throws Exception {
		// TODO Auto-generated method stub
		BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
		String in1 = br1.readLine();
		//アルファベットの出現数を数える
		int [] cnt = new int [26];
		cnt[0] = in1.length() - in1.replaceAll("a", "").length();
		cnt[1] = in1.length() - in1.replaceAll("b", "").length();
		cnt[2] = in1.length() - in1.replaceAll("c", "").length();
		cnt[3] = in1.length() - in1.replaceAll("d", "").length();
		cnt[4] = in1.length() - in1.replaceAll("e", "").length();
		cnt[5] = in1.length() - in1.replaceAll("f", "").length();
		cnt[6] = in1.length() - in1.replaceAll("g", "").length();
		cnt[7] = in1.length() - in1.replaceAll("h", "").length();
		cnt[8] = in1.length() - in1.replaceAll("i", "").length();
		cnt[9] = in1.length() - in1.replaceAll("j", "").length();
		cnt[10] = in1.length() - in1.replaceAll("k", "").length();
		cnt[11] = in1.length() - in1.replaceAll("l", "").length();
		cnt[12] = in1.length() - in1.replaceAll("m", "").length();
		cnt[13] = in1.length() - in1.replaceAll("n", "").length();
		cnt[14] = in1.length() - in1.replaceAll("o", "").length();
		cnt[15] = in1.length() - in1.replaceAll("p", "").length();
		cnt[16] = in1.length() - in1.replaceAll("q", "").length();
		cnt[17] = in1.length() - in1.replaceAll("r", "").length();
		cnt[18] = in1.length() - in1.replaceAll("s", "").length();
		cnt[19] = in1.length() - in1.replaceAll("t", "").length();
		cnt[20] = in1.length() - in1.replaceAll("u", "").length();
		cnt[21] = in1.length() - in1.replaceAll("v", "").length();
		cnt[22] = in1.length() - in1.replaceAll("w", "").length();
		cnt[23] = in1.length() - in1.replaceAll("x", "").length();
		cnt[24] = in1.length() - in1.replaceAll("y", "").length();
		cnt[25] = in1.length() - in1.replaceAll("z", "").length();
		int hantei =1;
		for (int i = 0 ;i<26 ; i++){
			if(cnt[i]%2 !=0 )
				hantei = -1;
		}
		if(hantei == 1)
			System.out.println("Yes");
		else System.out.println("No");
	}
}


Measured memory_bytes: 7892
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int MAXN = 200005;
vector<vector<ll>> dp(MAXN, vector<ll>(3));

int main() {
    int n;
	cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    bool odd_flg = false;
    if (n%2) odd_flg = true;
    // rep(j,3) dp[0][j] = 0;
    rep(i,n/2) {
        dp[i+1][0] = dp[i][0] + a[i*2];
        dp[i+1][1] = max(dp[i][0]+a[i*2+1], dp[i][1]+a[i*2+1]);
        if(odd_flg) {
            dp[i+1][2] = max(max(dp[i][0]+a[i*2+2], dp[i][1]+a[i*2+2]), dp[i][2]+a[i*2+2]);
        }

    }
    ll ans = max(dp[n/2][0], dp[n/2][1]);
    if(odd_flg) ans = max(ans, dp[n/2][2]);
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 15588
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 2E5;
struct Node {
    int p, x, y;
    Node(int p, int x, int y) : p(p), x(x), y(y) {}
};
bool operator<(const Node &lhs, const Node &rhs) {return 1LL * lhs.x * rhs.y < 1LL * lhs.y * rhs.x;}
int n;
int parent[N], v[N], fa[N], x[N], y[N];
LL ans;
int find(int x) {
    while (fa[x] >= 0 && fa[fa[x]] >= 0)
        x = fa[x] = fa[fa[x]];
    return fa[x] >= 0 ? fa[x] : x;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    memset(fa, -1, n * sizeof(int));
    for (int i = 1; i < n; ++i) {
        cin >> parent[i];
        --parent[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        (v[i] == 0 ? x[i] : y[i]) = 1;
    }
    priority_queue<Node> h;
    for (int i = 1; i < n; ++i)
        h.emplace(i, x[i], y[i]);
    while (!h.empty()) {
        auto u = h.top();
        h.pop();
        int p = u.p;
        if (u.x != x[p] || u.y != y[p])
            continue;
        int pa = find(parent[p]);
        ans += 1LL * y[pa] * x[p];
        x[pa] += x[p];
        y[pa] += y[p];
        fa[p] = pa;
        if (pa != 0)
            h.emplace(pa, x[pa], y[pa]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8820
n=int(input())
s1=input()
s2=input()

v=3
for i in range(1,n):
  if s1[i-1]==s2[i-1] or i==1:
    v*=2
  elif s1[i-1]!=s1[i] and s1[i]!=s2[i]:
    v*=3

print(v%1000000007)    


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define eps 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
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<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



int N;
int p[210000];
int d[210000];

int main () {
  cin >> N;
  rep(i, N) cin >> p[i];

  int tmp = INF;
  d[0] = INF;
  rep(i, N) {
    chmin(tmp, p[i]);
    d[i] = tmp;
  }

//  rep(i, N) {
//    cout << d[i] << "\n";
//  }

  int ans = 0;

  rep(i, N) {
    if (d[i-1] > p[i]) ans++;
  }

  cout << ans << "\n";
}

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

inline int read(){
    char ch=getchar();int x=0,f=1;
    while(ch>'9' || ch<'0'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}

int n,a[20000015];

int small(int i,int j,int k) {
    return a[i]<=k && a[j]<=k;
}

int big(int i,int j,int k){
    return a[i]>k && a[j]>k;
} 

int check(int k){
    for(int i=0;i<n-1;i++){
        if(big(n+i,n+i+1,k) || big(n-i,n-i-1,k)) return 0;
        if(small(n+i,n+i+1,k) || small(n-i,n-i-1,k)) return 1;
    }
    return small(1,1,k);
}

int main(){
    n=read();
    for(int i=1;i<=2*n-1;i++){
        a[i]=read();
    }
    int l=1,r=2*n-1,ans;
    while(l<r){
        int mid=l+r>>1;
        if(check(mid)) {
            r=mid;
        }
        else l=mid+1;
    }
    cout<<r;
    return 0; 
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(std::string T){
    rep(i,0,T.size()) if (T[i] == '?') T[i] = 'D';
    cout << T << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    std::string T;
    std::cin >> T;
    solve(T);
    return 0;
}


Measured memory_bytes: 3920
import math
x =int(input())

def beki(x):
    M = 1
    for p in range(2,int(math.sqrt(x))+1):
        for b in range(1,x+1):
            tmp =  pow(b,p)
            if tmp > M and tmp <= x:
                M = tmp
    return (M)

result = beki(x)

print(result)

Measured memory_bytes: 3060
import sys
N = int(input())
W = []
for i in range(N):
    W.append(input())

if len(set(W)) < N:
    print("No")
    sys.exit()

for i in range(N - 1):
    if W[i][-1] != W[i + 1][0]:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 3060
from __future__ import division, print_function
from sys import stdin, maxint
 
 
def main():
    x = int(stdin.readline())
 
    y = []
    for _ in xrange(x):
        y.append([int(s) for s in stdin.readline().split()])
 
    g = set(xrange(1, x+1))
    index = g.pop()
    h = {index}
    leng = 0
 
    while g:
        minimum = maxint

        for j in h:
            mj = y[j-1]
            for i in g:
                if 0 <= mj[i-1] < minimum:
                    index = i
                    minimum = mj[i-1]

        h.add(index)
        g.remove(index)
        leng += minimum
 
    print(leng)
 
 
main()

Measured memory_bytes: 6476
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;

int main() {
 int N;
  in(N);
  ll ans =1;
for(int i=2;i<=N;i++){
   ans *= i;
  ans %= mod;
 }
  out(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int r,d,x;
int main() 
{
	cin>>r>>d>>x;
	for(int i=1;i<=10;i++)
	{
		cout<<r*x-d<<endl;
		x=r*x-d;
	}
	return 0;
}

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

using namespace std;

using int64 = long long;

struct Combination {
  int mod;
  vector< int64_t > mfact, rfact;

  Combination(int sz, int mod) : mfact(sz + 1), rfact(sz + 1), mod(mod) {
    mfact[0] = 1;
    for(int i = 1; i < mfact.size(); i++) {
      mfact[i] = mfact[i - 1] * i % mod;
    }
    rfact[sz] = inv(mfact[sz]);
    for(int i = sz - 1; i >= 0; i--) {
      rfact[i] = rfact[i + 1] * (i + 1) % mod;
    }
  }

  int64_t fact(int k) const {
    return (mfact[k]);
  }

  int64_t pow(int64_t x, int64_t n) const {
    int64_t ret = 1;
    while(n > 0) {
      if(n & 1) (ret *= x) %= mod;
      (x *= x) %= mod;
      n >>= 1;
    }
    return (ret);
  }

  int64_t inv(int64_t x) const {
    return (pow(x, mod - 2));
  }

  int64_t P(int n, int r) const {
    if(r < 0 || n < r) return (0);
    return (mfact[n] * rfact[n - r] % mod);
  }

  int64_t C(int p, int q) const {
    if(q < 0 || p < q) return (0);
    return (mfact[p] * rfact[q] % mod * rfact[p - q] % mod);
  }

  int64_t H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return (r == 0 ? 1 : C(n + r - 1, r));
  }
};

const int mod = 1e9 + 7;

int main() {
  int N;
  cin >> N;
  Combination beet(N, mod);
  int ret = 0, pv = 0;
  for(int i = 1; i < N; i++) {
    auto curr = beet.C(i - 1, N - 1 - i) * beet.mfact[i] % mod * beet.mfact[N - 1 - i] % mod;
    auto sz = (curr + mod - pv) % mod;
    ret += sz * i % mod;
    ret %= mod;
    pv = curr;
  }
  cout << ret << endl;
}

Measured memory_bytes: 15872
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		int left = 0;
		int right = Integer.MAX_VALUE;
		while (right - left > 1) {
		    int m = (left + right) / 2;
		    int idx = 0;
		    int count = 1;
		    int current = 0;
		    boolean enable = true;
		    while (idx < n) {
		        if (current + arr[idx] > m) {
		            current = 0;
		            count++;
		            if (count > k) {
		                enable = false;
		                break;
		            }
		        } else {
		            current += arr[idx];
		            idx++;
		        }
		    }
		    if (enable) {
		        right = m;
		    } else {
		        left = m;
		    }
		}
		System.out.println(right);
	}
}



Measured memory_bytes: 70524
#include <stdio.h>
#include <math.h>

typedef struct{
  double x;
  double y;
}zahyo;


void koch(int, zahyo, zahyo);

zahyo a,b,s,t,u;
int n;

int main(){

  scanf("%d",&n);

  a.x=0;
  a.y=0;
  b.x=100;
  b.y=0;

  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);

  return 0;
}

void koch(int n, zahyo a, zahyo b){
  zahyo s,t,u;
  double th = M_PI*60.0/180.0;

  if(n == 0) return;

  s.x=((2.0 * a.x) + (1.0 * b.x))/3.0;
  s.y=((2.0 * a.y) + (1.0 * b.y))/3.0;
  t.x=((1.0 * a.x) + (2.0 * b.x))/3.0;
  t.y=((1.0 * a.y) + (2.0 * b.y))/3.0;
  u.x=(t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y=(t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;


  koch(n-1,a,s);
  printf("%.8f %.8f\n", s.x, s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n", u.x, u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n", t.x, t.y);
  koch(n-1,t,b);
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
using namespace std;
typedef long long ll;



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

	int N,M,Q;
	cin>>N>>M>>Q;
	vector<int> a(Q),b(Q),c(Q),d(Q);
	rep(i,0,Q) {
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--, b[i]--;
	}

	int res=0;

	vector<int> A(N);
	function<void(int)> gen=[&](int i) {
		if (i==N) {
			int s=0;
			rep(j,0,Q) if (A[b[j]]-A[a[j]]==c[j]) s+=d[j];
			res=max(res,s);
			return;
		}

		int start=(i==0?1:A[i-1]);
		rep(val,start,M+1) {
			A[i]=val;
			gen(i+1);
		}
	};
	gen(0);

	cout<<res<<'\n';
}


Measured memory_bytes: 3660
A, B, M = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

xyc_list = []
for i in range(M):
    xyc_list.append(list(map(int, input().split())))

total_min = min(a_list) + min(b_list)
for x,y,c in xyc_list:
    total = a_list[x-1] + b_list[y-1] - c
    if total_min > total:
        total_min = total

print(total_min)


Measured memory_bytes: 38492
#include<iostream>
#include<vector>
#include<string>
#include<map>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    map<ll, ll> cnt;
    for (auto& a : A) {
        cin >> a;
        ++cnt[a];
    }
    ll ans = 0;
    for (auto c : cnt) {
        ans += c.second * (c.second - 1) / 2;
    }
    rep(i, 0, N) {
        cout << ans - (cnt[A[i]] - 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 11264
# -*- coding: utf-8 -*-
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

S1 = []
S2 = []

S2_sum = 0
for a2 in A2:
    S2_sum += a2

S1_sum = 0
for a1,a2 in zip(A1,A2):
    S1_sum += a1
    S1.append(S1_sum)

    S2.append(S2_sum)
    S2_sum -= a2

ans_list = []
for s1,s2 in zip(S1,S2):
    ans_list.append(s1+s2)

print(max(ans_list))


Measured memory_bytes: 3064
#include<stdio.h>

int main(void)
{
  int x, a;
  if(scanf("%d %d", &x, &a) == 1);
  if(0<x||x<10||0<x||x<10)
  {
    if(x<a) printf("0");
    else    printf("10");
  }
  return 0;
}

Measured memory_bytes: 128
#include <cassert>
#include <cstdio>
#include <vector>
#include <set>

#include <map>
#include <unordered_map>
#include <deque>
#include <string>
#include <utility>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <climits>

using namespace std;

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 long long LINF = 1e18;

double expectedValue(int n) {
    return (1 + n) / 2.0;
}

int main() {
	int N, K;
	cin >> N >> K;

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

    double sum = 0.0;
    for (int i = 0; i < K; i++) {
        sum += expectedValue(p[i]);
    }
    double ans = sum;
    for (int i = 1; i < N - K + 1; i++) {
        sum -= expectedValue(p[i - 1]);
				sum += expectedValue(p[i + K - 1]);
        ans = max(ans, sum);
    }

    // cout << ans << endl;
    printf("%.12f\n", ans);
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define desync              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define EPS                 0.00000001
#define LL_MAX              1e18
#define LL_MIN              -1e18
#define MAX                 0x3f3f3f3f
#define MIN                 -0x3f3f3f3f
#define MOD                 1000000007
#define DEBUG(x)            cout << '>' << #x << ':' << x << endl;
#define REP(i,n)            for(int i=0;i<(n);i++)
#define FOR(i,a,b)          for(int i=(a);i<=(b);i++)
#define FORD(i,a,b)         for(int i=(a);i>=(b);i--)
#define n1                  '\n'

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<ld> pt;
typedef vector<pt> pol;

ll power(ll b, int e) {
    ll res = 1;
    for ( ; e>0; e/=2) {
        if (e&1) res = res*b % MOD;
        b = b*b % MOD;
    }
    return res;
}

string LCS(string s, string t) {
    // construct the substring length matrix
    int n = s.length(), m = t.length();
    int mat[n+1][m+1];
    REP(i, n+1) {
        REP(j, m+1) {
            if (i == 0 || j == 0) mat[i][j] = 0;
            else if (s[i-1] == t[j-1]) mat[i][j] = 1 + mat[i-1][j-1];
            else mat[i][j] = max(mat[i-1][j], mat[i][j-1]);
        }
    }
    int i = n, j = m;
    string ret = "";
    while(i > 0 && j > 0) {
        if (s[i-1] == t[j-1]) {
            ret.insert(0, 1, s[i-1]);
            i--;j--;
        } else if (mat[i][j] == mat[i-1][j]) i--;
        else j--;
    }
    return ret;
}

int main()
{
    desync
    string s, t;
    cin >> s >> t;
    cout << LCS(s, t) << n1;
    return 0;
}


Measured memory_bytes: 35456
#include<cstdio>
#include<iostream>
using namespace std;
const int MAXN=11;
int D,G,tot,ans=2147483647;
int num[MAXN],extra[MAXN];
int judge(int key){
	int tempsum=0,tempans=0;
	for(int i=1;i<=D;++i){
		if(key&(1<<(i-1))){
			tempsum+=(num[i]*i*100+extra[i]);
			tempans+=num[i];
		}
	}
	if(tempsum>=G) return tempans;
	for(int i=D;i>=1;--i){
		if(key&(1<<(i-1))) continue;
		if(tempsum+(num[i]-1)*i*100<G){
			tempsum+=(num[i]-1)*i*100;
			tempans+=(num[i]-1);
		}
		else{
			tempans+=(G-tempsum)/(i*100);
			tempsum+=(G-tempsum)/(i*100)*(i*100);
			if(tempsum<G){
				++tempans;
				tempsum=G;
			}
			break;
		}
	}
	if(tempsum<G) tempans=2147483647;
	return tempans;
}
int main(){
	scanf("%d%d",&D,&G);
	for(int i=1;i<=D;++i)
		scanf("%d%d",&num[i],&extra[i]);
	tot=1<<D;
	for(int w=0;w<tot;++w)
		ans=min(ans,judge(w));
	printf("%d",ans);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N+2,0);
  
  A.at(0) = 2;
  A.at(1) = 1;
  for (int i=2; i <N + 1; i++) {
    A.at(i) = A.at(i-2) + A.at(i-1);
  }
    
  cout << A.at(N) << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String yyyy = S.substring(0, 4);
		String mm = S.substring(5, 7);
		String dd = S.substring(8, 10);

		if (Integer.parseInt(yyyy) >= 2019 && Integer.parseInt(mm) >= 5) {
			System.out.println("TBD");
		} else {
			System.out.println("Heisei");
		}



	}
}

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


int main(){
  int a,b,c;
  cin>>a>>b>>c;
  swap(a,b);
  swap(a,c);
  cout<<a<<" "<<b<<" "<<c<<endl;

}


Measured memory_bytes: 256
#include <cmath>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
//~ #include <cstring>

using namespace std;

#define forsn(i,s,n) for (int i = (s);i < (int)(n);i++)
#define forn(i,n) forsn(i,0,n)
#define dforsn(i,s,n) for (int i = (n-1);i >= (int)(s);i--)
#define dforn(i,n) dforsn(i,0,n)
#define all(v) (v).begin(), (v).end()
#define F first
#define S second

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

	int n, a, b; cin >> n >> a >> b;
	
	cout << ((a + b) % 2? "Borys" : "Alice") << endl;
}


Measured memory_bytes: 256
X = int(input())
C= [i**5 for i in range(1000)]

a = 0
b = 0

for a in range(len(C)):
    for b in range(len(C)):
        if C[a] + C[b] == X:
            print(a, -b)
            exit(0)
        elif C[a] - C[b] == X:
            print(a, b)
            exit(0)


Measured memory_bytes: 9072
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
unordered_map<string, bool> M;
int n;
string s;
int main() {
    DAU
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> s;
        M[s] = true;
    }
    cout << M.size();
    PLEC
}


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

using namespace std;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    int ma=max(a,b);
    ma=max(ma,c);
    int ans=0,t=0;
    if((ma-a)%2) t++;
    if((ma-b)%2) t++;
    if((ma-c)%2) t++;
    ans+=(ma-a)/2;
    ans+=(ma-b)/2;
    ans+=(ma-c)/2;
    if(t==2) ans+=1;
    if(t==1) ans+=2;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256