akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <math.h>
using namespace std;

typedef long long ll;

/*
const ll M = 1000000007;
vector<ll> fac(3001);
vector<ll> ifac(3001);
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
 
ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}
*/


ll lcm(ll a,ll b){
 
  ll r, x, tmp;
  x = a * b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return x/b;
}

ll gcd(ll a ,ll b){
    if(a==0){return b;}
    else if(b==0){return a;}
    else{
    ll tmp,r;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
    }
}

bool sosu(ll p){
    bool ans = true;
    double psqrtd = pow(p, 0.5);
    ll psqrt = psqrtd;
    for(ll i = 2; i <= psqrt; i++){
        if(p%i==0)ans = false;
    }
    if(p==1)ans = false;
    return ans;
}



int main(void){
    ll ans = 0;
    ll n;
    cin >> n;
    ll a[n],b[n],c[n-1];
    for(ll i=0;i<n;i++)cin >> a[i];
    for(ll i=0;i<n;i++)cin >> b[i];
    for(ll i=0;i<n-1;i++)cin >> c[i];
    for(ll i=0;i<n;i++){
        ans += b[a[i]-1];
        if(i!=0)if(a[i]==a[i-1]+1)ans += c[a[i-1]-1];
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <iomanip>
using namespace std;

int n;
int a[200100];
int b[200100];
int ans[200100];
int m = 0;

int count(int cur) {
  int cnt = 0;
  for (int i = 2 * cur; i <= n; i += cur) {
    if (b[i] == 1) {
      cnt++;
    }
  }
  return cnt;
}

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  for (int i = n; i >= 1; i--) {
    if (count(i) % 2 == 0) {
      if (a[i] == 0) {
        b[i] = 0;
      } else {
        b[i] = 1;
        ans[m] = i;
        m++;
      }
    } else {
      if (a[i] == 0) {
        b[i] = 1;
        ans[m] = i;
        m++;
      } else {
        b[i] = 0;
      }
    }
  }

  if (m == 0) {
    cout << 0 << endl;
  } else {
    cout << m << endl;
    for (int i = 0; i < m-1; i++) {
      cout << ans[i] << ' ';
    }
    cout << ans[m-1] << endl;
  }
}


Measured memory_bytes: 2944
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;

int main() {
    int h, w, d;
    cin >> h >> w >> d;
    VVI a(h, VI(w));
    REP(i,h) REP(j,w){
        scanf("%d", &a[i][j]);
        a[i][j]--;
    }

    vector<P> pos(h*w);
    REP(i,h) REP(j,w){
        pos[a[i][j]] = P(i, j);
    }

    VVI cost(d, VI(h*w/d + 2));
    REP(i,d){
        for (int j = 0; i + (j + 1) * d < h * w; j++){
            cost[i][j+1] = cost[i][j] + abs(pos[i+j*d].first - pos[i+(j+1)*d].first) + abs(pos[i+j*d].second - pos[i+(j+1)*d].second);
        }
    }

    int q;
    cin >> q;
    while (q--){
        int l, r;
        scanf("%d %d", &l, &r);
        l--;
        r--;
        printf("%d\n", cost[l % d][r / d] - cost[l % d][l / d]);
    }

    return 0;
}

Measured memory_bytes: 6400
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

int n;
vector<string> s(50);

int main(){
  cin >> n;
  rep(i, n) cin >> s[i];
  int pnt = 0;
  rep(i, n) if(s[pnt].size() > s[i].size()) pnt = i;

  string candidate;
  rep(i, s[pnt].size()){
    const char c = s[pnt][i];
    bool flag = true;
    rrep(j, n-1){
      if((int)s[j].find(c) != -1){
        s[j].erase(s[j].begin() + s[j].find(c));
      }
      else{
        flag = false;
        break;
      }
    }
    if(flag) candidate.push_back(c);
  }
  sort(candidate.begin(), candidate.end());
  cout << candidate << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int ans = 1<<30;
  int n, T; cin >> n >> T;
  for(int i = 0; i < n; i++){
  	int c, t; cin >> c >> t;
    if(t <= T) ans = min(ans, c);
  }
  if(ans == (1<<30)) cout << "TLE" << endl;
  else cout << ans << endl;
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  string s;
  while(cin >> s) {
    if(s == "0") return 0;

    int a = 0, b = 0;
    rep(i, 1, s.length()) {
      if(s[i] == 'A') a++;
      else b++;
    }

    cout << (a == max(a, b) ? a + 1 : a) << " " << (b == max(a, b) ? b + 1 : b) << endl;
  }
}

Measured memory_bytes: 3240
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,k,l[55]={},ans=0;
  cin >> n >> k;
  for(int i=0; i<n; i++) {
    cin >> l[i];
  }
  sort(l,l+n,greater<int>());
  for(int i=0; i<k; i++) {
    ans+=l[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define double long double
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define inf 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
	int n;
	cin>>n;
	int a=inf;
	int cnt[n][26];
	string y="abcdefghijklmnopqrstuvwxyz";
	rep(i,n) rep(j,26) cnt[i][j]=0;
	rep(i,n) {
		string s;
		cin>>s;
		int m=s.size();
		rep(j,m) {
			cnt[i][s[j]-'a']++;
		}
	}
	rep(i,26) {
		rep(j,n) {
			a=min(a,cnt[j][i]);
		}
		rep(j,a) cout<<y[i];
		a=inf;
	}
	cend;
}


Measured memory_bytes: 256
// ABC113B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;
int main()
{
	int N, T, A;
	int H[1001];
	double I[1001];
	cin >> N >> T >> A;
	double B;
	B = A;//型変換
	double S;
	S = T;//型変換
	for (int i = 1; i <= N; i++)cin >> H[i];

	double temp[1001];
	for (int i = 1; i <= N; i++)
	{
		I[i] = H[i];//型変換
		temp[i] = T - I[i] * 0.006;
		temp[i] = A - temp[i];
		if (temp[i] < 0) temp[i] = -temp[i];
	}
	double  d[2][1001] = {};
	for (int i = 1; i <= N; i++)
	{
		d[0][i] = i;
		d[1][i] = temp[i];
	}

	for (int i = 1; i <= N; i++)
	{

		if (d[1][1] > d[1][i])
		{
			d[1][1] = d[1][i];
			d[0][1] = d[0][i];
		}

	}
	cout << d[0][1] << endl;
	return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


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

int main(){
  int N;
  cin >> N;
  int M = 0, S = 0;

  for (int i = 0; i < N; i++){
    int P;
    cin >> P;
    M += P;
    S = max(P,S);
  }
  int ans = M - (S/2);
  cout << ans <<endl;
}


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

int main(void)
{
    char x;
    cin >> x;
    if (isupper(x))
      {
      cout << "A"  << endl;
    } else {
      cout << "a" << endl;
      }
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main(){
    int n, k;
    int answer = 1;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        if(answer > k) answer += k;
        else answer = answer * 2;
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    int n,k;
    vector<vector<int>> ans;

    void solve(){
        k=38;
        n=k*k-k+1;
        ans= vector<vector<int>> (n,vector<int>(k));
        cout << n <<' ' <<k<<"\n";;
        ans[0][0]=1;
        for(int i=1; i<=k*(k-1); ++i){
            ans[i][0]=(i-1)/(k-1)+1;
        }
        vector<vector<int>> rem (k-1,vector<int>(k-1));

        for(int i=0,cnt=2; i<k; ++i){
            for(int j=1; j<k; ++j){
                if(i>=1)rem[j-1][i-1]=cnt;
                ans[i][j]=cnt;
                cnt++;
            }
        }
        for(int i=k; i<2*k-1; ++i){
            for(int j=1; j<k; ++j){
                ans[i][j]=rem[i-k][j-1];
            }
        }
        for(int i=k; i<n; ++i){
            int p=ans[i][0]-2;
            for(int j=1; j<k; ++j){
                //DBG(p,(i-((j-1)*p)%(k-1)+(k-1))%(k-1),j-1)
                ans[i][j]=rem[((i-k)%(k-1)-((j-1)*p)%(k-1)+(k-1))%(k-1)][j-1];
            }
        }

        for(int i=0; i<n; ++i){
            for(int j=0; j<k; ++j){
                cout << ans[i][j] <<' ';
            }
            cout <<"\n";
        }
        //DBG(rem)
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    Problem p;
    p.solve();
    return 0;
}



Measured memory_bytes: 768
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <string>
using namespace std;
typedef long long LL;
const LL N = 1000000007;

string s;
LL n;
LL to0[7] = {2,4,0,0,6,5,4},to1[7] = {3,5,0,1,1,5,4}; 
LL dp[7][300005];

int main(){
	cin >> s; n = s.length(); s = ' ' + s;
	dp[0][1] = (s[1] != '1'); dp[1][1] = (s[1] != '0');
	for(LL i = 2;i <= n;i ++){
		for(LL j = 0;j < 7;j ++){
			if(s[i] != '0') dp[to1[j]][i] = (dp[to1[j]][i] + dp[j][i - 1]) % N;
			if(s[i] != '1') dp[to0[j]][i] = (dp[to0[j]][i] + dp[j][i - 1]) % N;
		}
	}
	cout << (dp[1][n] + dp[5][n]) % N << '\n';
	return 0;
}

Measured memory_bytes: 17116
let f s = Array.init (String.length s) @@ fun i -> s.[i]
let g cs = String.init (Array.length cs) @@ fun i -> cs.(i)
let s, t = Scanf.scanf " %s %s" @@ fun a b -> f a, f b
let _ = Array.sort compare s; Array.sort (fun x y -> compare y x) t;
  print_endline @@ if g s < g t then "Yes" else "No"

Measured memory_bytes: 384
import sys
def q(a,h):
 d[a]=h
 for b in t[a]:q(b,h+1)
t,p,d={},{},{}
n=int(input())
for e in sys.stdin:
 e=e.split()
 t[e[0]]=e[2:]
 for i in e[2:]:p[i]=e[0]
r=(set(t)-set(p)).pop()
p[r]='-1'
q(r,0)
print('\n'.join(f"node {i}: parent = {p[i]}, depth = {d[i]}, {'root'if'-1'==p[i]else'internal node'if t[i]else'leaf'}, [{', '.join(t[i])}]"for i in map(str,range(n))))


Measured memory_bytes: 59744
N, M = map(int, input().split())
S = list(reversed(input()))

ans = []
cur = 0
while cur < N:
    for m in range(M, 0, -1):
        ncur = cur + m
        if ncur <= N and S[ncur] == '0':
            ans.append(m)
            cur = ncur
            break
    else:
        print(-1)
        exit()

print(*reversed(ans))


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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000001)
#define MOD (1000000007)
#define PI (acos(-1))

ll y[100010]={}; //iの４進法

ll yon(int x){//４進法に変換する
  if(y[x]>0)return y[x];
  ll res=0;
  for(int i=0; x>0; i++){
    res += (x%4)*pow(10,i);
    x /= 4;
  }
  return y[x] = res;
}

int yonbit(int x,int i){//４進法でxのi桁目
  ll n = yon(x);
  string s = to_string(n);
  char c;
  int siz = s.size();
  if(siz-1-i>=0)c = s[siz-1-i];
  else return 0;
  return c-'0'+0;
}

int main(){
  
  /*cout << yon(100000) << endl;
  rep(i,10){
    cout << yonbit(100000,i);
  }
  cout << endl;*/
  
  int n,a,b,c,l[10];
  cin >> n >> a >> b >> c;
  rep(i,n){
    cin >> l[i];
  }
  int ans = INF;
  rep(i,pow(4,n)){
    int al=0,bl=0,cl=0,mp=0;
    rep(j,n){
      int sb = yonbit(i,j);
      if(sb == 0){
        mp += al ? 10 : 0;
        al += l[j];
      }
      if(sb == 1){
        mp += bl ? 10 : 0;
        bl += l[j];
      }
      if(sb == 2){
        mp += cl ? 10 : 0;
        cl += l[j];
      }
    }
    if(min({al,bl,cl})<=0)continue;
    mp += abs(al-a)+abs(bl-b)+abs(cl-c);
    ans = min(ans,mp);
  }
  cout << ans << endl;
}
  

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 305;
ld dp[N][N][N];
int n, t[4];

void table() {
	for (int t3 = 0; t3 <= n; t3++)
		for (int t2 = 0; t2 + t3 <= n; t2++)
			for (int t1 = 0; t1 + t2 + t3 <= n; t1++) {

				int t0 = n - (t1 + t2 + t3);
				ld &ans = dp[t1][t2][t3];
				if (t0 == n)
					ans = 0;
				else {
					ans = 1;
					if (t1)
						ans += dp[t1 - 1][t2][t3] * ((ld) t1 / n);
					if (t2)
						ans += dp[t1 + 1][t2 - 1][t3] * ((ld) t2 / n);
					if (t3)
						ans += dp[t1][t2 + 1][t3 - 1] * ((ld) t3 / n);
					ans /= (1 - ((ld) t0 / n));
				}
			}
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		t[a]++;
	}
	table();
	cout << fixed << setprecision(12) << dp[t[1]][t[2]][t[3]];
	return 0;
}


Measured memory_bytes: 215652
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define vii vector<pii>
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int solve(){
    string s;cin>>s;
    int x=0;
    for(auto i:s){
        x+=(i-'0');
    }
    if(x%9==0){
        cout<<"Yes";
    }
    else cout<<"No";



    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

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

typedef long long ll;

int main() {
    int N; cin >> N;
    vector<double> v(N);
    rep(i,N) cin >> v[i];
    sort(v.begin(), v.end());
    double res = v[0];
    for(int i=1;i<N;i++){
        res = (res+v[i])/2;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
//😄😄😄😄😄😄😄😄😄😄😄😄😄
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pi>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define For(i,a,b) for(int i=a;i<b;i++)
#define debug(x) cout<<"DEBUG------> "<<#x<<" -> "<<x<<endl
#define endl "\n"
#define all(x) x.begin(),x.end()

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string a, b;
	cin >> a >> b;
	int ans = 0;
	For(i, 0, a.size()) {
		if (a[i] != b[i])
			ans++;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3836
import sys
input = sys.stdin.readline
n = 0
m = 0
s = []
p = []
ans = 0

def rec(v, y):
	global n, m, p, s, ans
	if y == 0:
		# ひかる電球数
		d = 0
		for i in range(m):
			# ONスイッチ数
			c = 0
			for j in range(s[i][0]):
				if v[s[i][1 + j]-1] == 1:
					c += 1
			if c % 2 == p[i]:
				d += 1
		if d == m:
			ans += 1
		return
	rec(list(v + [0]), y-1)
	rec(list(v + [1]), y-1)

def main():
	global n, m, s, p, ans
	n, m = map(int, input().strip().split())
	s = [[] for _ in range(m)]
	for i in range(m):
		s[i] = list(map(int, input().strip().split()))
	p = list(map(int, input().strip().split()))
	rec([], n)
	print(ans)

if __name__ == '__main__':
	main()


Measured memory_bytes: 43736
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	string s,t;
	cin>>s>>t;
	string r="";
	for(int i=0;i<t.size()-1;i++)
	{
		char tt=t.at(i);
		r+=tt;
	}
	if(s.compare(r)==0)
	cout<<"Yes\n";
	else
	cout<<"No\n";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
  int s;
  cin >> s;
  set<int> st;
  while (st.count(s) == 0)
  {
    st.insert(s);
    if (s % 2)
      s = 3 * s + 1;
    else
      s = s / 2;
  }
  cout << st.size() + 1 << endl;
  return 0;
}


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

ll findXOR(ll n)
{
	ll mod = n % 4;

	if (mod == 0)
		return n;

	else if (mod == 1)
		return 1;

	else if (mod == 2)
		return n + 1;

	else if (mod == 3)
		return 0;
}

ll findXOR(ll l, ll r)
{
	return (findXOR(l - 1) ^ findXOR(r));
}
int main()
{
	ll x,y;
	cin>>x>>y;

	cout << findXOR(x, y);

	return 0;
}


Measured memory_bytes: 3608
import numpy as np

a, b, h, m = map(int,input().split())

beta = 2*np.pi / 60 * float(m)
alpha = 2*np.pi / 12 * h + 2*np.pi /12 /60 * m
theta = abs(alpha - beta)

ans = np.sqrt((a - b*np.cos(theta))**2 + (b*np.sin(theta))**2)

print(ans)

Measured memory_bytes: 27192
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int P = 1e9 + 7;
inline int add(int a, int b) {if((a += b) >= P) a -= P; return a;}
inline int sub(int a, int b) {if((a -= b) < 0) a += P; return a;}
inline int mul(int a, int b) {return 1ll * a * b % P;}
inline int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----
const int N = 201010;
int n;
int a[N], b[N];
int main(){
	scanf("%d", &n);
	rep(i, 1, n + 1) scanf("%d", a + i);
	rep(i, 1, n + 1) b[i] = a[i] - i;
	sort(b + 1, b + n + 1);
	ll ans = 1e18, l = 0, r = 0;
	rep(i, 1, n + 1) r += b[i];
	rep(i, 1, n + 1) {
		r -= b[i];
		l += b[i];
		ll t = 1ll * b[i] * i - l + r - 1ll * b[i] * (n - i);
		ans = min(ans, t);
	}
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <string.h>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
 
using namespace std;

int main (){
    int c0=0,c1=0;
	char S[100000];
	
	cin >> S;

	int str = strlen(S);

	rep(i,0,str){
		if(S[i]=='0'){
			c0++;
		}
		else{
			c1++;
		}
	}

	if(c0<c1){
		cout << c0*2 << endl;
	}
	else{
		cout << c1*2 << endl;
	}
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
 
int main(){
 
  int n, x, y, m, l;
  char d;
 
  while(cin>>n, n){
    bool p[21][21]={};
    
    for(int i=0;i<n;i++){
      cin>>x>>y;
      p[y][x]=true;
    }
    
    cin>>m;
    int nx=10, ny=10;
    for(int i=0;i<m;i++){
      cin>>d>>l;
      
      if(d=='N'){
	for(int j=0;j<l;j++){
	  ny++;
	  if(p[ny][nx]==true){
	    n--;
	    p[ny][nx]=false;
	  }
	}
      }else if(d=='E'){
	for(int j=0;j<l;j++){
	  nx++;
	  if(p[ny][nx]==true){
	    n--;
	    p[ny][nx]=false;
	  }
	}
      }else if(d=='S'){
	for(int j=0;j<l;j++){
	  ny--;
	  if(p[ny][nx]==true){
	    n--;
	    p[ny][nx]=false;
	  }
	}
      }else if(d=='W'){
	for(int j=0;j<l;j++){
	  nx--;
	  if(p[ny][nx]==true){
	    n--;
	    p[ny][nx]=false;
	  }
	}
      }
    }
    
    if(n) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }
   
  return 0;
}

Measured memory_bytes: 3044
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;


int main() {
    ll n, x; cin>>n>>x;
    ll ans = n;
    ll a = max(x, n-x), b = min(x, n - x);
    while(true) {
        ll c = a % b;
        ans += (a /b *b * 2LL);
        //cout << a << " " << b << " " << c << " " << ans << endl;
        if(c == 0LL) break;
        a = b; b = c;
    }
    ans -= b;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	char b;
	cin >> b;
	switch(b){
	case 'A':
		cout << 'T' << endl;
		break;	
	case 'T':
		cout << 'A' << endl;
		break;
	case 'C':
		cout << 'G' << endl;
		break;
	case 'G':
		cout << 'C' << endl;
		break;
	}
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc054/tasks/abc054_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if (a == 1)
        a = 14;
    if (b == 1)
        b = 14;
    if (a > b) {
        cout << "Alice\n";
    } else if (a == b) {
        cout << "Draw\n";
    } else {
        cout << "Bob\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

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

    ll N;
    vector<ll> abc;
    cin >> N;
    REP(i, 5) {
        ll a;
        cin >> a;
        abc.push_back(a);
    }

    ll min_e = *min_element(ALL(abc));

    cout << ((N + min_e - 1LL) / min_e - 1LL) + 5LL << "\n";

    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main ()
  {
    int n,a,b,c;
    cin>>n;
    a=n%10;
    n/=10;
    b=n%10;
    c=n/10;
    if (a==7 || b==7 || c==7 )
       cout << "Yes" <<endl;
    else 
       cout << "No" <<endl;
  return 0;
  }

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

int main() {
    string s;
    int cnt;
    cin >> s;
    
    if (s[0] == '1') cnt++;
    if (s[1] == '1') cnt++;
    if (s[2] == '1') cnt++;
    
    cout << cnt << endl;
}


Measured memory_bytes: 764
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
string a;
int main()
{
	cin>>a;
	for(int s=0;s<a.size();s++)
	{
		cout<<a[s];
		if(s==3)cout<<" ";
	}
	cout<<endl;
}

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

int main(){
	int n, k;
	cin >> n >> k;
	vector<bool> have(n, false);
  //rep(i, n) cout << have[i] << endl;
	vector<int> d(k);
	rep(i, k) {
		cin >> d[i];
     // cout << d[i];
		vector<int> a(d[i]);
		rep(j, d[i]) {
			cin >> a[j];
          //cout << a[j];
			have[a[j]-1] = true;
         // rep(h, n) cout << have[h];
         // cout << endl;
		}
	}
	int ans = 0;
	rep(i, n) {
		if (!(have[i])) ans++;
	}
	cout << ans << endl;
  //rep(i, n) cout << have[i] << endl;
}


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

int main() {
  string S,T;
  cin >> S >> T;
  
  int ans = T.size();
  
  for (int i = 0; i <= S.size() - T.size(); i++) {
    int diff = 0;
    for (int j =0; j< T.size(); j++) {
      if (T.at(j) != S.at(i + j)) {
        diff++;
      }
    }
    ans = min(ans,diff);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3628
import scala.io.StdIn.{readLine,readInt}
/**
  * AOJ
  */

object Main {

  def main(args: Array[String]): Unit = {

    val dice = readLine().split(" ").map(_.toInt)
    val q =readInt()
    for(_ <- 1 to q){
      val sides = readLine().split(" ").map(_.toInt)
      println(findSide(sides(1),4,"HHH",findSide(sides(0),0,"WNNNW",dice))(3))
    }
  }

  def findSide(up:Int,findSide:Int,searchCommands:String,dice:Array[Int]) : Array[Int] = {
    if(dice(findSide) == up){return dice}
    var d = dice
    for(c <- searchCommands.toCharArray){
      d = getNextStatus(c,d)
      if(d(findSide) == up){return d}
    }
    throw new Exception()
  }

  def getNextStatus(cmd:Char,dice:Array[Int]): Array[Int] = cmd
    match {
      case 'N' => Array(dice(1),dice(5),dice(2),dice(3),dice(0),dice(4))
      case 'W' => Array(dice(2),dice(1),dice(5),dice(0),dice(4),dice(3))
      case 'H' => Array(dice(0),dice(3),dice(1),dice(4),dice(2),dice(5))
    }
}

Measured memory_bytes: 43932
#include "bits/stdc++.h"
#include <set>

using namespace std;
#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 rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int n, m;
	cin >> n >> m;
	typedef pair<int, int>pairs;
	vector<pairs>ab(n);
	rep(i, n) {
		cin >> ab[i].first >> ab[i].second;
	}
	sort(ab.begin(), ab.end());
	int bottle = 0;//購入本数
	int ans = 0;//値段
	int i = 0;
	while (bottle<m) {
		int buybottle = min(m - bottle, ab[i].second);
		ans += ab[i].first * buybottle;
		bottle += buybottle;
		i++;
	}
	print(ans);
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e6
using namespace std;

int main(){
	int n,m,a,b,c,d,s,g,v,p;
	scanf("%d %d",&n,&m);
	int dist[n][n];
	rep(i,n)rep(j,n)dist[i][j]=INF;
	rep(i,m){
		scanf("%d,%d,%d,%d",&a,&b,&c,&d);
		dist[a-1][b-1]=c;
		dist[b-1][a-1]=d;
	}
	scanf("%d,%d,%d,%d",&s,&g,&v,&p);
	rep(k,n){
		rep(i,n){
			rep(j,n){
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}
	cout<<v-(dist[s-1][g-1]+dist[g-1][s-1]+p)<<endl;
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <cstdio>
#include <cmath>


using namespace std;
int a[3];
char b[3];

int main()
{
    a[0] = 1;
    while (scanf("%s",b) != EOF){
        swap(a[b[0] - 65],a[b[2] - 65]);
    }
    if (a[0] == 1)
        cout << "A" << endl;
    else if (a[1] == 1)
        cout << "B" << endl;
    else if (a[2] == 1)
        cout << "C" << endl;

    return 0;
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

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


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

long long int n, k;
long long int h[100005], dp[100005];

void init() {
	for (int i = 0; i < n + 3; i++) dp[i] = -1;
}


long long int tab() {
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);

	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]),
			    dp[i - 2] + abs(h[i] - h[i - 2]));

		long long int temp = dp[i - 1] + abs(h[i] - 
				h[i - 1]);

		for (int j = 1; j <= k; j++) {
			if (i - j < 0) break;
			temp = min(temp, 
				dp[i - j] + abs(h[i] - h[i - j]));
		}
		dp[i] = temp;
	}
	return dp[n - 1];
}

int main() {
	cin >> n >> k;
	init();
	for (int i = 0; i < n; i++) cin >> h[i];
	cout << tab() << endl;
	

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define fi(a,b,c) for(int i=a;i<b;i=i+c)
#define fj(a,b,c) for(int j=a;j<b;j+=c)
using namespace std;
 
ll gcd(ll n1,ll n2) {
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent) {
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll max(ll a,ll b,ll c) {
	return max(a,max(b,c));
}
int max(int a,int b,int c) {
	return max(a,max(b,c));
}

int main()
{
	int n;
	sd(n);
	map<string, int> m;
	while(n--){
		string s;
		cin>>s;
		if(m[s]>0){
			m[s]++;
		}else{
			m[s]=1;
		}
	}
	pd(m.size());
}

Measured memory_bytes: 19296
#include <bits/stdc++.h>
#include <cstdint>
#include <sys/time.h>

typedef std::int_fast32_t  s32;
typedef std::uint_fast32_t u32;
typedef std::int_fast64_t  s64;
typedef std::uint_fast64_t u64;

typedef std::pair<int, int> P;

int main(void) {
  
  for(;;) {
    int N;
    std::cin >> N;
    if( N == 0 ) break;
    
    P p[256];
    p[0].first = p[0].second = 0;
    for(int i = 1; i < N; ++i) {
      int n, d;
      std::cin >> n >> d;

      int dx[4] = {-1, 0, 1, 0};
      int dy[4] = {0, -1, 0, 1};
      p[i].first  = p[n].first  + dx[d];
      p[i].second = p[n].second + dy[d];
    }

    int left, right, down, up;
    left = right = down = up = 0;
    for(int i = 0; i < N; ++i) {
      left  = std::min(left, p[i].first);
      right = std::max(right, p[i].first);

      down = std::min(down, p[i].second);
      up   = std::max(up, p[i].second);
    }

    std::cout << right - left + 1 << " " << up - down + 1 << std::endl;
  }
  
  return 0;
}

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

int main(){
	string s,t;
	cin>>s>>t;
	int ans=0;
	for(int i=0;i<s.length();i++){
		if(s[i]!=t[i] ) ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3860
import java.util.Scanner;


public class Main {

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

		long[] A = new long[N+1];
		long[] B = new long[N];

		for (int i = 0; i < N+1; i++) {
			A[i] = sc.nextLong();
		}

		for (int i = 0; i < N; i++) {
			B[i] = sc.nextLong();
		}

		long ans = 0;

		for (int i = N - 1; i >= 0 ; i--) {
			if (A[i+1] >= B[i]) {
				A[i+1] -= B[i];
				ans+=B[i];
			}else {
				B[i] -= A[i+1];
				ans += A[i+1];
				A[i+1] = 0;
				if (A[i] >= B[i]) {
					A[i] -= B[i];
					ans+=B[i];
				}else {
					B[i] -= A[i];
					ans += A[i];
					A[i] = 0;
				}
			}
		}

		System.out.println(ans);

	}
}


Measured memory_bytes: 60616
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500010
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans;

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

	ll A,B,C;
	cin >> A >> B >> C;

	ans = min(C,B/A);

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

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container;

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

alias sread = () => readln.chomp();
enum MOD = 10 ^^ 9 + 7;

void main()
{
    long N, M;
    scan(N, M);
    auto uf_same = unionFind(N);
    auto uf_diff = unionFind(N);
    foreach (_; 0 .. M)
    {
        long X, Y, Z;
        scan(X, Y, Z);
        // if (Z & 1)
        //     uf_diff.unite(X - 1, Y - 1);
        // else
        //     uf_same.unite(X - 1, Y - 1);
        uf_same.unite(X - 1, Y - 1);
    }
    foreach (i; 0 .. N)
        uf_same.root(i);
    // uf_same.writeln();
    uf_same.sort();
    uf_same.uniq().walkLength().writeln();
}

long[] unionFind(long N)
{
    return iota!long(N).array;
}

long root(long[] uf, long x)
{
    if (uf[x] == x)
        return x;
    long r = root(uf, uf[x]);
    uf[x] = r;
    return r;
}

void unite(long[] uf, long x, long y)
{
    long rx = root(uf, x);
    long ry = root(uf, y);
    if (rx != ry)
        uf[rx] = ry;
}

bool same(long[] uf, long x, long y)
{
    return root(uf, x) == root(uf, y);
}


Measured memory_bytes: 5116
from collections import deque

def push(duque, d, x):
    if d == 1:
        duque.append(x)
    else:
        duque.appendleft(x)
    return duque

def randomAccess(duque, p):
    print(duque[p])

def pop(duque, d):
    if d == 1:
        duque.pop()
    else:
        duque.popleft()
    return duque

if __name__ == '__main__':
    l = deque([])
    n = int(input())
    for i in range(n):
        j= input().split()

        if int(j[0]) == 0:
            push(l, int(j[1]), int(j[2]))
        elif int(j[0]) == 1:
            randomAccess(l, int(j[1]))
        else:
            pop(l, int(j[1]))


Measured memory_bytes: 21956
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
using namespace std;

int main(){
    int a, b;
    string op;
    cin >> a >> op >> b;
    while(1){
        if(op == "?"){
            break;
        }
        if(op == "+"){
            cout << a + b <<endl;
        }
        if(op == "-"){
            cout << a - b <<endl;
        }
        if(op == "*"){
            cout << a * b <<endl;
        }
        if(op == "/"){
            cout << a / b <<endl;
        }
        cin >> a >> op >> b;
    }
    return 0;
}

Measured memory_bytes: 3136
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <string>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <deque>
using namespace std;
long long  a[200005];
bool cmp(int a, int b)
{
    return a > b;
}
int main()
{
    int n;
    cin >> n;
    long long sum = 0;
    for (int i = 0; i < n; ++i)
    {
        scanf("%lld", &a[i]);
    }
    sort(a, a + n, cmp);
    sum = a[0];
    for (int i = 1; i < n / 2; ++i)
    {
        sum += 2 * a[i];
    }
    if (n & 1)
        sum += a[n / 2];
    printf("%lld\n", sum);
}

Measured memory_bytes: 5384
N = int(input())
H = list(map(int, input().split()))
total = 0
max_total = 0

for i in range(N-1):
    if H[i] >= H[i+1]:
        total += 1
        max_total = max(max_total, total)
    else:
        total = 0

print(max_total)

Measured memory_bytes: 15020
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        ((a)*((b)/gcd((a),(b))))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

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

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

map<pii,int> dp;
map<int,vi> mp;

int n,w;
int start;

int rec(int ind,int w)
{
    if(ind==start+4)
        return 0;

    if(dp.find({ind,w})!=dp.end())
        return dp[{ind,w}];

    int res=rec(ind+1,w);
    int val=0,cur=0;
    for(auto c:mp[ind])
    {
        val+=c;
        cur+=ind;

        if(w-cur<0)
            break;

        remax(res,rec(ind+1,w-cur)+val);
    }

    dp[{ind,w}]=res;
    return res;
}

void solve()
{
    cin>>n>>w;

    int x,y;
    for(int i=0;i<n;++i)
    {
        cin>>x>>y;
        mp[x].pb(y);

        if(!i)
            start=x;
    }

    for(auto& c:mp)
    {
        sort(all(c.S));
        reverse(all(c.S));
    }

    int ans=rec(start,w);
    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 384
def main():
    S = input()
    alpha = "abcdefghijklmnopqrstuvwxyz"
    alpha_rev = alpha[::-1]
    if S == alpha_rev:
        return -1
    Sset = set(list(S))
    if len(Sset) != 26:
        for c in alpha:
            if c not in Sset:
                return S + c
    else:
        for i in range(len(S)-1, 0, -1):
            if S[i] > S[i-1]:
                target = sorted(S[i-1:])
                for j in range(len(target)):
                    if target[j] > S[i-1]:
                        ref = target[j]
                        break
                t = S[:i-1] + ref
                return t
        return -1

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    
    char now=s.at(0);
    int ans=0;
    rep(i,n){
        if(now!=s.at(i)){
            ans++;
            now=s.at(i);
        }
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    double l;
    cin >> l;
    cout << setprecision(15) << (l/3)*(l/3)*(l/3);
}      

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
	int H,W,cnt;
	cin>>H>>W;
	int X[H][W];
	int Y[H][W]={0};
	cnt=0;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>X[i][j];
			if(X[i][j]%2==0)X[i][j]=-1;
			else X[i][j]=1;
          Y[i][j]=0;
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(X[i][j]<1){
				
			}
			else if(j==(W-1)){
				if(i==(H-1))break;
				else {
					X[i][j]*=-1;
					X[i+1][j]*=-1;
					Y[i][j]=2;
					//cout<<i+1<<" "<<j+1;
					//cout<<i+2<<" "<<j+1<<endl;
					cnt++;
				}
			}else{
				X[i][j]*=-1;
				X[i][j+1]*=-1;
				Y[i][j]=1;
				//cout<<i+1<<" "<<j+1;
				//cout<<i+1<<" "<<j+2<<endl;
				cnt++;
			}
		}
	}
	cout<<cnt<<endl;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(Y[i][j]==2){
				cout<<i+1<<" "<<j+1<<" "<<i+2<<" "<<j+1<<endl;
			}else if(Y[i][j]==1){
				cout<<i+1<<" "<<j+1<<" "<<i+1<<" "<<j+2<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 4096
#!/usr/bin/env python3

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    ans = 0
    for k in range(30):
        C = [x & ((1 << (k+1)) - 1) for x in A]
        D = [x & ((1 << (k+1)) - 1) for x in B]
        C.sort()
        D.sort()
        # print(f'k = {k}')
        # print(f'C = {C}')
        # print(f'D = {D}')
        p, q, r = 0, 0, 0
        for i in range(N-1, -1, -1):
            while p < N:
                if C[i] + D[p] >= 1 << k: break
                p += 1
            while q < N:
                if C[i] + D[q] >= 2 << k: break
                q += 1
            while r < N:
                if C[i] + D[r] >= 3 << k: break
                r += 1
            x = ((q - p) + (N - r)) % 2
            # print(p, q, r, x)
            ans = ans ^ (x << k)
    print(ans)

main()


Measured memory_bytes: 138496
#include <bits/stdc++.h>
using namespace std;
//互いにある一つの種を二個以上残そうとする
int main(){
  int n; cin>>n;
  vector<int> num(n);
  for(int i=0;i<n;i++){
    cin>>num[i];
    if(num[i]%2==1){
      cout<<"first"<<endl;
      return 0;
    }
  }cout<<"second"<<endl;
}

Measured memory_bytes: 640
/*in the name of Allah the most beneficent the most merciful.*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
//#define mod2 20071027
//#define MOD 998244353
#define base 139
//#define mod 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case #%lld: ", ++c)
#define out(x) cout << #x << " -> " << x << endl;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FILE   freopen("input.txt", "r", stdin);  freopen("out.txt", "w", stdout);
using namespace std;
const int B = 16, N = 100010, M = 5000010;
ll n, d, x, y, res;
string s, r;
int solve()
{
    cin>>n>>s;
    r=s;
    sort(r.begin(), r.end());
    for(int i=0;i<n;i++)
    {
        if(r[i]!=s[i])
            res++;
    }
    printf("%lld\n", res/2);
    return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    return solve();
}
/*

*/

Measured memory_bytes: 3884
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    cin >> s;
    int n = s.size();
    int ans = s[0] == 'A';
    for(int i = 1; i < n; i++){
        if(s[i-1] >= s[i])ans++;
    }
    cout << ans << endl;
}



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

int n, m, q;
vector<int> pos;
vector<vector<int>> g;
ll ans;

void dfs(int p)
{
  if (p < n)
    for (int i = pos[p-1]; i <= m; i++)
    {
      pos[p] = i;
      dfs(p + 1);
    }
  else
  {
    ll tmp = 0;
    rep(i, q)
      if (pos[g[i][1]] - pos[g[i][0]] == g[i][2])
        tmp += g[i][3];
    ans = max(ans, tmp);
  }
}

int main()
{
  cin >> n >> m >> q;
  pos.resize(n);
  g.resize(q);
  rep(i, q)
  {
    g[i].resize(4);
    cin >> g[i][0] >> g[i][1] >> g[i][2] >> g[i][3];
    g[i][0]--;
    g[i][1]--;
  }
  ans = 0;
  for (int i = 1; i <= m; i++)
  {
    pos[0] = i;
    dfs(1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <cstring>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

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

  int count;
  count = n / 2 + n % 2;
  cout << count;
  return 0;
}


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

int main(){
  ll n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n){
    cin>>a[i];
  }
  sort(a.begin(),a.end(),greater<ll>());
  ll ans=0;
  for(int i=1; i<=n-1; i++){
    if(i%2==1){
      ans+=a[(i-1)/2];
    }else{
      ans+=a[i/2];
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 4852
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define B begin()
#define E end()
using namespace std;
int main()
{
    ll n,k; cin>>n>>k;
    if(k<(n*2) || k>(n*4) || k%2) cout<<"No";
    else cout<<"Yes";
}


Measured memory_bytes: 3592