akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=105;
const int mod=1e9+7;
vector<pll> vec[MAXN];
LL f[MAXN],tot;
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
int main()
{
	f[0]=f[1]=1;tot=1;
	while(f[tot]<1e18)
	{
		f[tot+1]=f[tot]+f[tot-1];
		++tot;
	}
	vec[1].push_back(mp(1,2));vec[1].push_back(mp(1,3));vec[1].push_back(mp(1,4));
	for(int i=2;i<=tot;i++)
		for(int j=0;j<vec[i-1].size();j++)
		{
			LL x=vec[i-1][j].first,y=vec[i-1][j].second;
			x+=y;
			while(x<=f[i-1]+f[i+2])
			{
				vec[i].push_back(mp(y,x));
				x+=y;
			}
		}
	int T=read();while(T--)
	{
		LL n=read(),m=read();
		if(n>m)swap(n,m);int ans=1;
		while(f[ans+1]<=n&&f[ans+2]<=m)++ans;
		pr1(ans);
		if(ans==1){pr2(1LL*n*m%mod);continue;}
		int sum=0;
		for(int i=0;i<vec[ans-1].size();i++)
		{
			LL x=vec[ans-1][i].first,y=vec[ans-1][i].second;
			if(y<=n)ad(sum,1LL*(m-x)/y%mod);
			if(y<=m)ad(sum,1LL*(n-x)/y%mod);
		}
		pr2(sum);
	}
	return 0;
}


Measured memory_bytes: 4096
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define fi first
//#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


template<class M, class N>
constexpr common_type_t<M, N> gcd(M m, N n) {

  common_type_t<M, N> a = m, b = n;

  if (b > a) {
    swap(a, b);
  }

  while (true) {
    common_type_t<M, N> c = a % b;
    if (c == 0) break;

    a = move(b);
    b = move(c);
  }

  return b;
}
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  // 整数列 A を全て 2 で割った整数列 B = b1, b2,...,bN
  // bk * (2p + 1) = X
  // つまりどの数にも奇数をかけて得られる最小公倍数がX
  // B に偶数が含まれていた場合、いずれのbkに対しても2がかけられている個数が同じでないといけない
  // そうでない場合は、個数は 0 になる
  // 最小公倍数を m とすると、m, 3m, 5m, 7m... が答えになるのでそれを数える
  
  int N, M;
  cin >> N >> M;

  vector<int> as(N);
  bool fail = false;

  cin >> as[0];
  as[0] >>= 1;
  int ns = 0;
  while (!(as[0] & 1)) {
    as[0] >>= 1;
    ns++;
  }

  FOR(i, 1, N) {
    cin >> as[i];
    as[i] >>= 1;

    int n = 0;
    while (!(as[i] & 1)) {
      as[i] >>= 1;
      n++;
    }
    if (n != ns) fail = true;
  }

  i64 result;
  if (!fail) {
    M >>= ns;

    i64 lcm = 1;
    F0R(i, N) {
      lcm = ::lcm(lcm, as[i]);
      if (lcm > M) {
        fail = true;
        break;
      }
    }
    if (!fail)
      result = (M / lcm + 1) / 2;
  }

  cout << (fail ? 0 : result);
}
#endif


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

using namespace std;

/*****************MACRO*****/

#define ll long long
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

/*******CONSTANT***********/
#define INF (1<<30) //infinity value
#define EPS 1e-9
#define MOD 10000007
#define SIZ 1005
#define PI (acos(-1))


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    --n;
    ll b[n];
    for(ll i=0;i<n; ++i) cin>>b[i];
    ll sum= b[0];
    for(ll i=0; i<n-1; ++i){
        sum+= min(b[i],b[i+1]);
    }
    sum+= b[n-1];
    cout<<sum<<"\n";



    return 0;
}

/**********************************************************************************

stdin copy
6
6 12 9 4 7
 stdout copy
36





*************************************************************************************/


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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }


int main() {
    int A, B; cin >> A >> B;
    if (B%A == 0) {
        cout << A+B << endl;
    } else {
        cout << B-A << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int k = scan.nextInt();
        int a = scan.nextInt();
        int b = scan.nextInt();
        scan. close();
        
        int flag = 0;
        for(int i = a; i <= b; i++){
            if(i % k == 0){
                flag = 1;
                break;
            }
        }
        if(flag == 1){
            System.out.println("OK");
        }else{
            System.out.println("NG");
        }
    }
}

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

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

  if((a+b) >= n){
    if(a<=n){
      cout << "YES" << endl;
    }
    else{
      cout << "NO" << endl;
    }
  }
  else{
    cout << "NO" << endl;
  }

  return 0;
}




Measured memory_bytes: 256
N, M = map(int, input().split())
s = []
k = []

for _ in range(M):
    tmp = list(map(int, input().split()))
    k.append(tmp.pop(0))
    s.append(tmp)
p = list(map(int, input().split()))
counter = 0

for bit in range(1 << N):
    hantei = True
    for n1, j in enumerate(s):
        tmp = 0
        for i in j:
            if(bit & (1 << (i-1))):
                tmp += 1
        if(tmp % 2 != p[n1]):
            hantei = False
    if(hantei == True):
        counter += 1

print(counter)



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

int main(){
  // start process
  string s;
  int i,j;
  cin >> s;
  int even = 0, odd = 0;
  for(i=0; i<s.length(); i++){
    if(s[i]=='0'){
      if(i%2==0){
        even++;
      }else{
        odd++;
      }
    }
  }
  int change = 0;
  if(even>odd){
    for(i=0; i<s.length(); i++){
      if(i%2==0){
        if(s[i]!='0'){
          change++;
        }
      }else{
        if(s[i]=='0'){
          change++;
        }
      }
    }
  }else{
    for(i=0; i<s.length(); i++){
      if(i%2==0){
        if(s[i]=='0'){
          change++;
        }
      }else{
        if(s[i]!='0'){
          change++;
        }
      }
    }
  }
  cout << change << endl;
  // end process
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <ctime>
#include <vector>
#include <climits>
#include <algorithm>
#include <random>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <bitset> 
#include <queue>
#define inf 0x3f3f3f3f
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define rep(i, a, n) for(register int i = a; i <= n; ++ i)
#define per(i, a, n) for(register int i = n; i >= a; -- i)
#define ONLINE_JUDGE
using namespace std;
typedef long long ll;
const int mod=1e9+7;
template<typename T>void write(T x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
}
 
template<typename T> void read(T &x)
{
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;};
ll ksm(ll a,ll n){//¿´ÊÇ·ñÒªmod 
	ll ans=1;
	while(n){
		if(n&1) ans=(ans*a)%mod;
		a=a*a%mod;
		n>>=1;
	}
	return ans%mod;
}
//==============================================================
const int maxn=1e6+10;
int n;
set<int> a;
int mark[maxn];
int vis[maxn];

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	//clock_t c1 = clock();
	//===========================================================
    int lim=-inf;
    read(n);
    rep(i,1,n){
        int t;read(t);
        if(a.count(t)) mark[t]++;
        lim=max(lim,t);
        a.insert(t);
    }
    int ans=0;
    for(auto it=a.begin();it!=a.end();++it){
        if(vis[*it]) continue;
        if(!mark[*it]){
            ans++;
        }
        for(int i=1;i*(*it)<=lim;++i){
            vis[i*(*it)]=1;
        }
    }
    write(ans);
	//===========================================================
	//std::cerr << "Time:" << clock() - c1 << "ms" << std::endl;
	return 0;
}

Measured memory_bytes: 19860
card_1 = [i for i in input().split()]
card_2 = [i for i in input().split()]
card_3 = [i for i in input().split()]
call_cnt = int(input())
call_num = [input() for i in range(call_cnt)]

cent_num = card_2[1]

tate_1 = [card_1[0], card_2[0], card_3[0]]
tate_2 = [card_1[1], card_2[1], card_3[1]]
tate_3 = [card_1[2], card_2[2], card_3[2]]

cross_l = [card_1[0], card_2[1], card_3[2]]
cross_r = [card_1[2], card_2[1], card_3[0]]

if cent_num in call_num:
    if len(set(call_num)&set(card_1)) == 3:
        print('Yes')
    elif len(set(call_num)&set(card_2)) == 3:
        print('Yes')
    elif len(set(call_num)&set(card_3)) == 3:
        print('Yes')
    elif len(set(call_num)&set(tate_1)) == 3:
        print('Yes')
    elif len(set(call_num)&set(tate_2)) == 3:
        print('Yes')
    elif len(set(call_num)&set(tate_3)) == 3:
        print('Yes')
    elif len(set(call_num)&set(cross_l)) == 3:
        print('Yes')
    elif len(set(call_num)&set(cross_r)) == 3:
        print('Yes')
    else:
        print('No')
else:
    if len(set(call_num)&set(card_1)) == 3:
        print('Yes')
    elif len(set(call_num)&set(card_3)) == 3:
        print('Yes')
    elif len(set(call_num)&set(tate_1)) == 3:
        print('Yes')
    elif len(set(call_num)&set(tate_3)) == 3:
        print('Yes')
    else:
        print('No')

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

int main() {
  int A, B;
  cin >> A >> B;
  
  if ((A + B) % 3 == 0 || A % 3 == 0 || B % 3 == 0) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize(2,3,"Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
namespace fast_io
{
    char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0,ny;
    in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
    in int read()
    {
        int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;Bi=1;if(nc<0)return nc;
        x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*ny;
    }
    in db gf() {int a=read(),y=ny,b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi)*y:a);}
    in int gs(char *s) {char c,*t=s;while(c=gc(),c<32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
    in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
    in void flush() {if(C>1<<22) ot();}
    template <typename T>
    in void write(T x,char t)
    {
        int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
        if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
    }
    in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
};
using namespace fast_io;
const int N=3e5+5,p=998244353;
char s[N];
int main()
{
	int n=gs(s+1),ans=0;
	for(int i=1;i<=n/2;i++) ans+=(s[i]!=s[n-i+1]);
	write(ans,'\n');
	return ot(),0;
}
//Author: disangan233
//In my dream's scene,I can see the everything that in Cyaegha.

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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c)

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}


int main()
{
  ios::sync_with_stdio(0);
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  bool turn = 0;
  while(a > 0 && c > 0)
  {
    if(turn)
      a -= d;
    else
      c -= b;
    turn ^= 1;
  }
  cout << (turn ? "Yes" : "No") << endl;
  return 0;
}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}

long long int fac(long long int n){
  long long int m=1;
  while(n>=1) m*=n,m%=1000000007,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int w_max,w_min=0,h_max,h_min=0,n,w,h;
  cin>>w_max>>h_max>>n;
  vector<int> x(n),y(n),a(n);
  rep(i,n) cin>>x[i]>>y[i]>>a[i];
  rep(i,n){
    if(a[i]==1) w_min=max(w_min,x[i]);
    if(a[i]==2) w_max=min(w_max,x[i]);
    if(a[i]==3) h_min=max(h_min,y[i]);
    if(a[i]==4) h_max=min(h_max,y[i]);
  }
  w=w_max-w_min;
  h=h_max-h_min;
  if(w<0 || h<0){
    cout<<0<<endl;
  }else{
    cout<<w*h<<endl;
  }
}
///////////////////////////




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

#define INF 1000000000000
#define MOD 1000000007

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

    string s;
    cin>>s;
    int ans=0;
    for(int i=0; i<s.length()/2; i++){
        if(s[i]!=s[s.length()-i-1])   ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ACはうれCすぎてうれD */

int main(void){ 
    int n,t;
    cin >> n >> t;
    vector<pair<int, int>> v;
    for(int i=0; i<n; i++){
        int cost, time;
        cin >> cost >> time;
        v.push_back(make_pair(cost, time));
    }

    int ans = 10000;
    for(int i=0; i<n; i++){
        if(v[i].second <= t){
            if(v[i].first < ans){
                ans = v[i].first;
            }
        }
    }

    if(ans == 10000) cout << "TLE";
    else cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int cmp(int a, int b) {
	return abs(a) < abs (b);
}
int main() {
	int n,l;
	cin>>n>>l;
	int a[205];
	for (int i = 0; i < n; ++i) {
		a[i] = l+i;
	}
	sort(a , a + n, cmp);
	int sum=0;
	for(int i = 1; i < n; ++i) {
		sum+=a[i];
	}
	cout<<sum<<endl;
}  

Measured memory_bytes: 256
n = gets.to_i
a = gets
a = a.split("")
b = Array.new(n)
WtoE = Array.new(n)
EtoW = Array.new(n)
for i in 0..(n-1) do
  if i == 0
    if a[i] == "W"
      WtoE[i] = 1
    else
      WtoE[i] = 0
    end
  else
    if a[i] == "W"
      WtoE[i] = WtoE[i-1] + 1
    else
      WtoE[i] = WtoE[i-1]
    end
  end

  j = (n-1) - i
  if j == (n-1)
    if a[j] == "E"
      EtoW[j] = 1
    else
      EtoW[j] = 0
    end
  else
    if a[j] == "E"
      EtoW[j] = EtoW[j+1] + 1
    else
      EtoW[j] = EtoW[j+1]
    end
  end
end

for i in 0..(n-1) do
  if i == 0
    b[i] = EtoW[i+1]
  elsif i == (n-1)
    b[i] = WtoE[i-1]
  else
    b[i] = WtoE[i-1] + EtoW[i+1]
  end
end

p b.min

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

int main(){
  string s;
  int cnt=0;
  cin>>s;
  for(int i=0;i<2;i++){
    if(s[i]==s[i+1]&&s[i+1]==s[i+2]){
      cout<<"Yes"<<endl;
      break;
    }
    else{cnt +=1;}
  }
  if(cnt==2)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;
typedef long long ll;

int main() {
	ll N,j = 0,ans = 0;
	cin >> N;
	vector<ll> data(N);
	rep(i,N){
		cin >> data.at(i);
	}
    vector<ll> tentou(N);
    rep(i,N-1){
        if(data.at(i) >= data.at(i+1)){
            tentou.at(j)++;
        }else{
            j++;
        }
    }
    rep(i,N){
        if(ans <= tentou.at(i)){
            ans = tentou.at(i);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
  int N;
  scanf("%d", &N);
  int A[N];
  long long ans = 0;
  for (int i = 0; i < N; ++i) scanf("%d", &A[i]);
  if (A[0] != 0) {
    printf("-1");
    return 0;
  }
  for (int i = 1; i < N; ++i) {
    if (A[i] - A[i - 1] > 1) {
      printf("-1");
      return 0;
    } else if (A[i] <= A[i - 1]) ans += A[i];
    else ++ans;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 2492
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define pi 3.14159265359
#define mp make_pair
#define ff first
#define ss second
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define sc(a) scanf("%lld",&a)
#define pf printf
#define sz(a) (ll)(a.size())
#define psf push_front
#define ppf pop_front
#define ppb pop_back
#define pb push_back
#define pq priority_queue
#define all(s) s.begin(),s.end()
#define sp(a) setprecision(a)
#define rz resize
#define ld long double

using namespace std;

vector<vector<ll> > dp;

bool cmp(const pair<int,pair<int,int> > &a,const pair<int,pair<int,int> > &b)
{
	return a.ff+a.ss.ff<b.ff+b.ss.ff;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<pair<int,pair<int,int> > > p(n);
	int val[n],w=0;
	f(i,0,n)
	{
		cin>>p[i].ff>>p[i].ss.ff>>p[i].ss.ss;
		w+=p[i].ff;
	}
	dp.rz(n+1,vector<ll> (20202));
	sort(all(p),cmp);
	f(i,1,n+1)
		dp[i][0]=0;
	f(i,1,20202)
		dp[0][i]=0;
	dp[0][0]=0;
	// f(i,0,n)
	// 	cout<<p[i].ff<<' '<<p[i].ss.ff<<' '<<p[i].ss.ss<<"\n";
	f(i,1,n+1)
	{
		f(j,p[i-1].ff,20202)
		{
			if(p[i-1].ss.ff>=j-p[i-1].ff)
				dp[i][j]=max(dp[i-1][j],p[i-1].ss.ss+dp[i-1][j-p[i-1].ff]);
			dp[i][j-p[i-1].ff]=max(dp[i][j-p[i-1].ff],dp[i-1][j-p[i-1].ff]);
		}
	}
	// cout<<dp[n][w]<<"\n";
	ll mx=-1;
	// f(i,0,n+1)
	// {
	// 	f(j,0,w+1)
	// 		cout<<dp[i][j]<<' ';
	// 	cout<<"\n";
	// }
	f(i,1,20202)
		mx=max(mx,dp[n][i]);
	cout<<mx<<"\n";
}

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

using namespace std;

class PictureFarame {
public:
	PictureFarame(int h, int w)
		:_h(h), _w(w)
	{};

	void setContent() {
		vStr.reserve(_h);
		for (int n = 0; n < _h; n++) {
			string temp;
			cin >> temp;
			vStr.push_back(temp);
		}
	};

	void pHeader() {
		for (int n = 0; n < (_w + 2); n++) {
			cout << "#";
		}
		cout << endl;
	};

	void pContent() {
		for (int n = 0; n < vStr.size(); n++) {
			cout << "#" << vStr[n] << "#" << endl;
		}
	};

private:
	int _h, _w;
	vector<string> vStr;
};

int main() {
	int h, w;
	cin >> h >> w;

	PictureFarame pic(h, w);

	pic.setContent();
	pic.pHeader();
	pic.pContent();
	pic.pHeader();

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define ALL(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl

int main() {
    IN(int, n);
    vector<int> a(n);
    int m = 0;
    REP(i, n){
        cin >> a[i];
        m = max(a[i], m);
    }
    int count = 0;
    
    REP(i, m){
        bool flag = false;
        REP(j, n){
            if (a[j]>0) {
                a[j]--;
                if (!flag) {
                    flag = true;
                    count++;
                }
            }else if (flag){
                flag = false;
            }
        }
    }
    COUT(count);
}


Measured memory_bytes: 256
A, B = map(int, input().split())

x_low = (A * 100 + 7) // 8
x_high = ((A + 1) * 100 + 7) // 8 - 1
y_low = (B * 100 + 9) // 10
y_high = ((B + 1) * 100 + 9) // 10 - 1

result = max(x_low, y_low)
if result > min(x_high, y_high):
    result = -1
print(result)


Measured memory_bytes: 3188
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a,b,flag,f=0;
		while(true) {
			flag = 0;
			a=sc.nextInt();
			b=sc.nextInt();
			if ( a == 0 && b == 0 )break;
			else if ( f != 0 )
				System.out.println();
			f++;
			while ( a <= b ) {
				if ( a % 4 == 0 && a % 100 != 0 || a % 400 == 0 ) {
					System.out.println(a);
					flag=1;
				}
				a++;
			}
			if ( flag == 0 )
				System.out.println("NA");
		}
	}
}

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

char m[2001][2001];
int ans[2001][2001];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h,w;
	cin>>h>>w;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			cin>>m[i][j];
	for(int i=1;i<=h;i++){
		int pre=0;
		for(int j=1;j<=w;j++){
			if(m[i][j]=='#')
				pre=j;
			else
				ans[i][j]+=j-pre;
		}
	}
	for(int j=1;j<=w;j++){
		int pre=0;
		for(int i=1;i<=h;i++){
			if(m[i][j]=='#')
				pre=i;
			else
				ans[i][j]+=i-pre;
		}
	}
	for(int i=1;i<=h;i++){
		int pre=w+1;
		for(int j=w;j>0;j--){
			if(m[i][j]=='#')
				pre=j;
			else
				ans[i][j]+=pre-j;
		}
	}
	for(int j=1;j<=w;j++){
		int pre=h+1;
		for(int i=h;i>0;i--){
			if(m[i][j]=='#')
				pre=i;
			else
				ans[i][j]+=pre-i;
		}
	}
	int out = 0;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			out=max(out,ans[i][j]);
	cout<<out-3<<endl;
}




Measured memory_bytes: 19840
#include<bits/stdc++.h>
using namespace std;
int main(){
	string S,T;cin>>S>>T;
	for(int i=S.size()-T.size();i>=0;i--){
		for(int j=i;j<i+T.size();j++){
			if(S.at(j)!= '?'&&S.at(j)!=T.at(j-i)){
				break;
			}else if(j==i+T.size()-1){
				for(int k=0;k<S.size();k++){
					if(k==i){
						cout<<T;
						k=i+T.size()-1;
					}else{
					    if(S.at(k)== '?'){
							    cout<<'a';
						}else{
							cout<<S.at(k);
						}
					}
				}cout<<endl;
				return 0;
			}
		}
	}cout<<"UNRESTORABLE"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int a = sc.nextInt();
		int p = sc.nextInt();
        int sum = a * 3 + p;
    
		// 出力
		System.out.println((sum - (sum % 2)) / 2);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <map>
using namespace std;

int main() {
	int n, cnt = 0, next = 1;
	cin >> n;
	vector <int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int j = 0; j < n; j++) {
		cnt++;
		next = a[next - 1];
		if (next == 2) {
			break;
		}
	}
		if (next != 2) {
			cnt = -1;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3764
#include "bits/stdc++.h"
using namespace std;

typedef vector<long long> vec;
typedef vector<vec> mat;

mat Mul(mat& A, mat& B, long long MOD) {
	mat C(A.size(), vec(B.front().size()));
	for (int i = 0; i < A.size(); i++) {
		for (int k = 0; k < B.size(); k++) {
			for (int j = 0; j < B.front().size(); j++) {
				C[i][j] += ((A[i][k] % MOD) * (B[k][j] % MOD) % MOD);
				C[i][j] = C[i][j] % MOD;
			}
		}
	}
	return C;
}

mat Calc(mat A, long long N, long long M) {
	if (N == 1) return A;
	if (N % 2 == 0) {
		mat B = Calc(A, N / 2, M);
		return Mul(B, B, M);
	}
	mat B = Calc(A, N - 1, M);
	return Mul(B, A, M);
}

int main() {
	long long N, MOD = 1000000007, ANS = 0;
	cin >> N;
	mat P(64, vec(64));
	for (int i = 0; i < 64; i++) {
		if (i == 6 || i == 9 || i == 18) {
			for (int j = 0; j < 64; j++) P[i][j] = 0;
			continue;
		}
		int X[3] = {}, I = i;
		for (int j = 0; j < 3; j++) {
			X[2 - j] = I % 4;
			I /= 4;
		}
		for (int j = 0; j < 64; j++) {
			if (j == 6 || j == 9 || j == 18) {
				P[i][j] = 0;
				continue;
			}
			int Y[3] = {}, J = j;
			for (int k = 0; k < 3; k++) {
				Y[2 - k] = J % 4;
				J /= 4;
			}
			if (X[1] != Y[0] || X[2] != Y[1]) P[i][j] == 0;
			else {
				if (X[0] == 0 && X[1] == 1 && Y[2] == 2) P[i][j] = 0;
				else if (X[0] == 0 && Y[1] == 1 && Y[2] == 2) P[i][j] = 0;
				else P[i][j] = 1;
			}
		}
	}
	P = Calc(P, N, MOD);
	for (int i = 0; i < 64; i++) ANS = (ANS + P[63][i]) % MOD;
	cout << ANS << endl;
}

Measured memory_bytes: 640
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


//x^nをmodのもとで計算する
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow((x*x) % mod, n/2, mod);
  if (n & 1) res = (res*x) % mod;
  return res;
}

ll pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = pow(x*x, n/2);
  if (n & 1) res *= x;
  return res;
}

const int MAX_N = 100000, MOD = 1e9+7;
int N;
int a[MAX_N];

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

  sort(a, a+N);
  if (N%2 == 0) {
    for (int i = 0; i < N; i += 2) {
      if (a[i] != i+1 || a[i+1] != i+1) {
        cout << 0 << endl;
        return 0;
      }
    }
  } else {
    if (a[0] != 0) {
      cout << 0 << endl;
      return 0;
    }
    for (int i = 1; i < N; i += 2) {
      if (a[i] != i+1 || a[i+1] != i+1) {
        cout << 0 << endl;
        return 0;
      }
    }
  }

  cout << mod_pow(2, N/2, MOD) << endl;

  return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
 
using namespace std;

int main()
{
	long long int N,M;
	cin>>N>>M;
	long long int Lmax = 0;
	long long int Rmin = N;
	for(int i = 0; i < M; i++){
		long long int l,r;
		cin>>l>>r;
		Lmax = max(l,Lmax);
		Rmin = min(r,Rmin);
	}
	int ans = Rmin-Lmax+1;
	
	if( ans < 0){
		cout<<0<<endl;
	}else{
		cout<<Rmin-Lmax+1<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    for(int i=0; i<n; ++i)
        cin >> x[i];
    int len;
    cin >> len;

    vector<vector<int> > to(n);
    int k = n-1;
    for(int i=n-2; i>=0; --i){
        while(x[k] - x[i] > len)
            -- k;
        to[i].push_back(k);

        for(unsigned j=0; j<to[to[i][j]].size(); ++j)
            to[i].push_back(to[to[i][j]][j]);
    }

    int q;
    cin >> q;
    while(--q >= 0){
        int a, b;
        cin >> a >> b;
        -- a;
        -- b;
        if(a > b)
            swap(a, b);

        int ans = 0;
        while(a < b){
            int i = 0;
            while(i < (int)to[a].size() && to[a][i] <= b)
                ++ i;
            i = max(0, i - 1);

            ans += 1 << i;
            a = to[a][i];
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 13440
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX

using namespace std;

using ll = long long;

#define mp make_pair

const int p = 1000000007;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/


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

    int n, m;
    cin>>n>>m;
    vector<int> x(n), y(m);
    for (int i = 0; i<n; i++) cin>>x[i];
    for (int i = 0; i<m; i++) cin>>y[i];

    int totx = 0;
    for (int i = 0; i<n; i++) totx = add(totx, mul((x[i]+p)%p, (i - (n-1-i) + p)%p));
    int toty = 0;
    for (int i = 0; i<m; i++) toty = add(toty, mul((y[i]+p)%p, (i - (m-1-i) + p)%p));
    cout<<mul(totx, toty);
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;

typedef struct{
	int f; //first
	int s; //second
}point;

int main(){
	while(1){	
		int w, h;
		int f[60][60];
		int field[30][30];
		int df[4]={0, -1, 0, 1}, ds[4]={1, 0, -1, 0};
		
		scanf(" %d %d", &w, &h);
		if(w==0) break;
		
		for(int i=0; i<2*h-1; ++i){
			int t;
			if(i%2==1) t=w;
			else t=w-1;
			for(int j=0; j<t; ++j) scanf("  %d", &f[i][j]);
		}
	
		for(int i=0; i<30; ++i)
		for(int j=0; j<30; ++j)
		field[i][j]=0;
		
		point start, goal;
		start.f=0;
		start.s=0;
		goal.f=h-1;
		goal.s=w-1;
		
		queue<point> que;
		field[start.f][start.s]=1;
		que.push(start);
		while(!que.empty()){
			point now=que.front();
			que.pop();
			
			int nf, ns;
			if(now.s+1<w &&f[2*now.f][now.s]==0 && field[now.f][now.s+1]==0){ //右側
				nf=now.f;
				ns=now.s+1;
				field[nf][ns]=field[now.f][now.s]+1;
				point tmp;
				tmp.f=nf;
				tmp.s=ns;
				que.push(tmp);
			}
			if(now.s-1>=0 &&f[2*now.f][now.s-1]==0 && field[now.f][now.s-1]==0){ //左側
				nf=now.f;
				ns=now.s-1;
				field[nf][ns]=field[now.f][now.s]+1;
				point tmp;
				tmp.f=nf;
				tmp.s=ns;
				que.push(tmp);
			}
			if(now.f-1>=0 &&f[2*now.f-1][now.s]==0 && field[now.f-1][now.s]==0){ //上側
				nf=now.f-1;
				ns=now.s;
				field[nf][ns]=field[now.f][now.s]+1;
				point tmp;
				tmp.f=nf;
				tmp.s=ns;
				que.push(tmp);
			}
			if(now.f+1<h &&f[2*now.f+1][now.s]==0 && field[now.f+1][now.s]==0){ //下側
				nf=now.f+1;
				ns=now.s;
				field[nf][ns]=field[now.f][now.s]+1;
				point tmp;
				tmp.f=nf;
				tmp.s=ns;
				que.push(tmp);
			}
		}
	
		printf("%d\n", field[goal.f][goal.s]);
	}
	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <iterator>
#include <algorithm>
#include <map>
using namespace std;

int main(void){
    // Your code here!
    int r;
    cin >> r;
    if(r < 1200){
        cout << "ABC";
    }else if(r < 2800){
        cout << "ARC";
    }else{
        cout << "AGC";
    }
    cout << endl;

}


Measured memory_bytes: 256
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

ans = 0
m = [0 for _ in range(n)]

for i in range(k):
    if t[i] == 'r':
        ans += p
    elif t[i] == 's':
        ans += r
    else:
        ans += s

for i in range(k, n):
    if t[i] != t[i-k] or m[i-k] == 1:
        if t[i] == "r":
            ans += p
        elif t[i] == "s":
            ans += r
        else:
            ans += s
    else:
        m[i] = 1

print(ans)


Measured memory_bytes: 10008
/* ex7_3
   tamayama */

#include<stdio.h>
#include<stdlib.h>

int main(void){
    int field_Height;
    int field_Width;
    char **ia;
    int i,j,k;
    int count=0;

    scanf("%d %d",&field_Height,&field_Width);
    ia = (char**)calloc(field_Height,sizeof(char*));
    if(ia == NULL){
        exit(1);
    }
    for(i=0;i<field_Height;i++){
        ia[i] = (char*)calloc(field_Width,sizeof(char));
        if(ia[i] == NULL){
            exit(1);
        }
    }
    
    for(i=0;i<field_Height;i++){
        for(j=0;j<field_Width;j++){
            scanf(" %c",&ia[i][j]);
        }
    }

    for(i=0;i<field_Height;i++){
        for(j=0;j<field_Width;j++){
            if(ia[i][j] == '.' || ia[i][j] == 'x'){
                count++;
                if(count == field_Width){
                    for(k=0;k<field_Width;k++){
                        ia[i][k] = 'x';
                    }
                }
            }
        }
        count = 0;
    }
    
    for(j=0;j<field_Width;j++){
        for(i=0;i<field_Height;i++){
            if(ia[i][j] == '.' || ia[i][j] == 'x'){
                count++;
                if(count == field_Height){
                    for(k=0;k<field_Height;k++){
                        ia[k][j] = 'x';
                    }
                }
            }
        }
        count = 0;
    }



    for(i=0;i<field_Height;i++){
        for(j=0;j<field_Width;j++){
            if(ia[i][j] != 'x'){
                printf("%c",ia[i][j]);
            }else{
                count++;
            }
        }
        if(count != field_Width){
            printf("\n");
        }
        count = 0;
    }

    for(i=0;i<field_Height;i++){
        free(ia[i]);
    }
    free(ia);
    return 0;
}

Measured memory_bytes: 1672
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long ans = 1;
		long mod = (long)(1e9)+7;
		int N = I.nextInt();
		long[] pos = new long[N+1]; //Using long since pos[i] is a factor of final answer
		//Avoiding potential overflow
		Arrays.fill(pos,2); //Each |L-R| has two possible indices (except for |L-R| 
		//that have same parity as N 
		pos[0]=1; //There's only one middle slot in array (special case for odd parity N)
		for (int i = 0; i < N; i++) {
			int x = I.nextInt(); 
			if (x%2==N%2) ans=0; //Same parity is literally impossible 
			//(N=5 --> Pos = {4,2,0,2,4}; N=4 --> Pos = {3,1,1,3}
			if (ans==0) break;
			ans*=pos[x];
			ans%=mod;
			pos[x]--; //One possible slot has been used
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 39524
import sys
sys.setrecursionlimit(300000)
from heapq import heappush, heappop

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
A = LMI()
A.sort(reverse=True)

ans = 0
q = []
for i, a in enumerate(A):
    if i == 0:
        heappush(q, -a)
    else:
        m = -heappop(q)
        ans += m
        heappush(q, -a)
        heappush(q, -a)
print(ans)

Measured memory_bytes: 104460
import numpy as np
import itertools
N, M = list(map(int, input().split()))
tmp = [[int(i) for i in input().split()] for i in range(M)]
p = list(map(int, input().split()))
ans = 0
for switch in itertools.product(range(2),repeat=N):
    #print(switch)
    num_clear_light = 0
    for i in range(M):
        count = 0
        for j in range(tmp[i][0]):
            #print(tmp[i][j+1])
            if(switch[tmp[i][j+1] - 1] == 1):
                count += 1
        if(count % 2 == p[i]):
            num_clear_light += 1
    if(num_clear_light == M):
        ans += 1
    num_clear_light = 0

print(ans)

Measured memory_bytes: 12408
#include<bits/stdc++.h>
using namespace std;
const int maxn = 300001;
char val[maxn];
int n;
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	int a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	for(int i = 1;i <= n;++i)cin >> val[i];
	for(int i = n + 1;i < maxn;++i)val[i] = '#';
	bool ok = true;
	if(b > d || a > c)ok = false;
	if((a < b and c < d) || (a > b and c > d)){
		for(++a;a + 1 < c and ok;++a){
			if(val[a] == val[a + 1] and val[a] == '#')ok = false;
		}
		for(++b;b + 1 < d and ok;++b){
			if(val[b] == val[b + 1] and val[b] == '#')ok = false;
		}
	}
	else{
		if(a > b){
			swap(a, b);
			swap(c, d);
		}
		while(a < c and ok and b <= d){
			if(val[a + 1] == '.'){
				if(a + 1 != b)++a;
				else if(val[a + 2] == '.')a += 2;
				else if(val[a + 3] == '.')b += 2, ++a;
				else ok = false;
			}
			else if(val[a + 2] == '.'){
				if(a + 2 != b)a += 2;
				else if(val[a + 3] == '.')++b, a += 2;
				else if(val[a + 4] == '.')b += 2, a += 2;
				else ok = false;
			}
			else ok = false;
		}
		if(b > d)ok = false;
		for(++b;b + 1 < d and ok;++b){
			if(val[b] == val[b + 1] and val[b] == '#')ok = false;
		}
	}
	if(ok)puts("Yes");
	else puts("No");
}


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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,k; cin>>n>>k;
	cout << (n%k ? 1 : 0) << endl;
	return 0;
}


Measured memory_bytes: 256
import math

H, W = map(int,input().split())

if H==1 or W==1:
    print(1)
elif W%2 == 0:
    print(int((W/2)*H))
else:
    if H%2 == 0:
        print(int(W*(H/2)))
    else:
        print(int((W*H+1)/2))

Measured memory_bytes: 3060
#include<stdio.h>
#define MAX 100000

int main() {
  int n,i;
  int A[MAX+1];

  scanf("%d",&n);
  for(i = 1 ; i <= n ; i++) {
    scanf("%d",&A[i]);
  }
  for(i = 1 ; i <= n ; i++) {
    printf("node %d: key = %d, ",i,A[i]);
    if(i / 2 >= 1)
      printf("parent key = %d, ", A[i/2]);
    if(i * 2 <= n)
      printf("left key = %d, ", A[i*2]);
    if(i * 2 + 1 <= n)
      printf("right key = %d, ", A[i*2+1]);
    printf("\n");
  }
  return 0;
}



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

int main(){
    int N,A=0,B=0;
    cin>>N;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin>>a.at(i);
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    for(int i=0;i<N;i++){
        if(i%2==0){
            A+=a.at(i);
        }else{
            B+=a.at(i);
        }
    }
    
    cout<<A-B<<endl;
}


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

#define ALL(obj) (obj).begin(),(obj).end()
template<class T> using priority_queue_reverse = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = 1'000'000'000LL + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
vector<string> split(const string &str, const char delemiter) {vector<string> res;stringstream ss(str);string buffer; while( getline(ss, buffer, delemiter) ) res.push_back(buffer); return res;}
int msb(int x) {return x?31-__builtin_clz(x):-1;}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    ll N,X,T;
    cin >> N >> X >> T;
    ll ans = 0,cnt = 0;
    while(1) {
        ans+=T;
        cnt+=X;
        if(cnt >= N) break;
    }
    cout << ans << endl;
    return 0;
}


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

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

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

    vector<pair<int, int>> cb(m);
    for (size_t i = 0; i < m; i++)
    {
        int b, c;
        cin >> b >> c;
        cb.push_back(make_pair(c, b));
    }

    sort(a.begin(), a.end());
    sort(cb.begin(), cb.end());

    auto itr = prev(cb.end());
    int alt = itr->first;
    int cnt = itr->second;
    long long sum = 0LL;
    for (size_t i = 0; i < n; i++)
    {
        if (a[i] < alt)
        {
            sum += alt;
            --cnt;
            if (alt != 0 && cnt == 0)
            {
                if (itr == cb.begin())
                {
                    alt = 0;
                }
                else
                {
                    itr = prev(itr);
                    alt = itr->first;
                    cnt = itr->second;
                }
            }
        }
        else
        {
            sum += a[i];
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
using namespace std;
int h,w,cnt,Cnt,p,P;
int main() {
	cnt=0;
	Cnt=0;
  p=0;P=0;
	cin>>h>>w;
	char a[h][w];
	int b[h]={0};
	int c[w]={0};
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w-1;j++){
			if(a[i][j]!=a[i][j+1]||a[i][j]=='#'){
				break;
			}else if(j==w-2){
				b[i]=1;
				cnt++;
			}
		}
	}
	for(int j=0;j<w;j++){
		for(int i=0;i<h-1;i++){
			if(a[i][j]!=a[i+1][j]||a[i][j]=='#'){
				break;
			}else if(i==h-2){
				c[j]=1;
				Cnt++;
			}
		}
	}
	for(int i=0;i<h;i++){
		if(b[i]==0){
          p++;
		for(int j=0;j<w;j++){
			if(c[j]==0){
              P++;
				cout<<a[i][j];
				if(Cnt!=w-P){}//cout<<" ";
              else if(cnt!=h-p)cout<<endl;
			}
		}
		P=0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())
xtmp = abs(sx - tx)
ytmp = abs(sy - ty)
ans = 'U' * ytmp
ans += 'R' * xtmp
tmp1 = ans
tmp1 = tmp1.replace('R', 'L')
tmp1 = tmp1.replace('U', 'D')
tmp2 = 'LU' + ans + 'RD'
tmp3 = 'RD' + tmp1 + 'LU'
print(ans + tmp1 + tmp2 + tmp3)

Measured memory_bytes: 3064