akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define repd(i,x,y) for(int i=x; i>=y; --i)

using namespace std;
const int N=2005,mod=998244353;
typedef long long LL;
int n,k,bin[5005],len;
LL flv[N<<1],inv[N<<1],A[5005],B[5005],b[N<<1],f[N][N];

LL getmi(LL a,LL x)
{
	LL rt=1;
	while(x)
	{
		if(x&1) rt=rt*a%mod;
		a=a*a%mod,x>>=1;
	}
	return rt;
}

void FFT(LL a[],int len,int tp)
{
	rep(i,0,len-1) bin[i]=bin[i>>1]>>1|((i&1)*(len>>1));
	rep(i,0,len-1) if(i<bin[i]) swap(a[i],a[bin[i]]);
	for(int i=1; i<len; i<<=1)
	{
		LL wn=getmi(3,(mod-1)/(i<<1));
		if(tp==-1) wn=getmi(wn,mod-2);
		for(int j=0; j<len; j+=i<<1)
		{
			LL w=1,x,y;
			rep(k,0,i-1)
			{
				x=a[j+k],y=a[i+j+k]*w%mod,w=w*wn%mod;
				a[j+k]=(x+y)%mod,a[i+j+k]=(x-y+mod)%mod;
			}
		}
	}
	if(tp==-1)
	{
		LL x=getmi(len,mod-2);
		rep(i,0,len-1) a[i]=a[i]*x%mod;
	}
}		

LL C(int n,int m)
{
	return n<m?0:flv[n]*inv[m]%mod*inv[n-m]%mod;
}

void solve(int x)
{
	LL rt=0;
	int l=max(1,x-k),r=min(k,x-1),tot=l-1+k-r;
	rep(i,0,n)
	{
		if(!tot && i) break;
		LL cnt=!tot?1:C(tot+i-1,tot-1);
		rt=(rt+cnt*f[n-i][(k-tot)>>1])%mod;
		if(((k-tot)&1) && i!=n)
			rt=(rt+cnt*(f[n-i-1][(k-tot)>>1]))%mod;
	}
	printf("%lld\n",rt);
}

void pre()
{
	rep(i,0,k) f[0][i]=1;
	rep(j,1,k)
	{
		memset(A,0,sizeof(A));
		memset(B,0,sizeof(B));
		rep(i,1,j) A[i]=b[i]*inv[i-1]%mod*inv[i]%mod*inv[j-i]%mod;
		rep(i,0,n) B[i]=inv[i];
		for(len=1; len<=j+n; len<<=1);
		FFT(A,len,1),FFT(B,len,1);
		rep(i,0,len-1) A[i]=A[i]*B[i];
		FFT(A,len,-1);
		rep(i,1,n) f[i][j]=A[i]*flv[i-1]%mod*flv[j]%mod;
	}
}

int main()
{
	scanf("%d%d",&k,&n);
	flv[0]=b[0]=1;
	rep(i,1,n+k) flv[i]=flv[i-1]*i%mod,b[i]=b[i-1]*2%mod;
	inv[n+k]=getmi(flv[n+k],mod-2);
	repd(i,n+k,1) inv[i-1]=inv[i]*i%mod;
	pre();
	rep(i,2,2*k)
		solve(i);
	return 0;
}

Measured memory_bytes: 31744
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N;
  cin >> N;
  vector<int> C(N-1), S(N-1), F(N-1);
  for (int i=0; i<N-1; i++) cin >> C[i] >> S[i] >> F[i];
  for (int i=0; i<N; i++) {
    int x = 0;
    for (int j=i; j<N-1; j++) {
      if (x<S[j]) x = S[j];
      else if (x%F[j]!=0) x += F[j]-x%F[j];
      x += C[j];
    }
    cout << x << endl;
  }
  return 0;
}

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

// 插入此處

int main() {
    int q;
    cin >> q;
    priority_queue<LL> left;
    priority_queue<LL, vector<LL>, greater<LL>> right;
    LL B = 0;
    LL A = 0;
    while (q--) {
        int t;
        cin >> t;
        LL last_mid;
        if (t == 1) {
            LL a, b;
            cin >> a >> b;
            B += b;
            if (left.empty() || left.top() >= a) {
                if (left.size() > right.size()) {
                    LL tmp = left.top();
                    left.pop();
                    right.push(tmp);
                }
                left.push(a);
            } else {
                if (left.size() == right.size()) {
                    right.push(a);
                    LL tmp = right.top();
                    right.pop();
                    left.push(tmp);
                } else {
                    right.push(a);
                }
            }
            if (left.size() > 0 && left.size() == right.size()) {
                A += abs(left.top() - last_mid);
            }
            A += abs(a - left.top());
            // printf("A = %lld, B = %lld\n", A, B);
            last_mid = left.top();
        } else {
            cout << left.top() << " " << A + B << endl;
        }
    }
}


Measured memory_bytes: 4916
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int[] a=new int[n];
        a[0]=sc.nextInt();
        int min=Math.abs(a[0]);
        long sum=min;
        int fu=0;
        if(a[0]<0){
            fu++;
        }
        for(int i=1; i<n; i++){
            a[i]=sc.nextInt();
            if(a[i]<0){
                fu++;
            }
            int temp=Math.abs(a[i]);
            sum+=temp;
            if(min>temp){
                min=temp;
            }
        }

        if(fu%2==0){
            // System.out.println("0");
            System.out.println(sum);
        }else{
            // System.out.println(fu);
            System.out.println(sum-2*min);
        }
    }
}


Measured memory_bytes: 50244
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;

template <typename T>
using TABLE = vector<vector<T>>;

using LONG = long long;
using LVEC = vector<long long>;

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


int main(){
    LONG N;

    string S, T;
    cin >> S;
    cin >> T;

    for(int i = 0; i < S.size(); ++i){
        if(S[i] != T[i]){
            cout << "No";
            return 0;
        }
    }

    cout << "Yes";

}


Measured memory_bytes: 3616
n = int(input())
arr = list(map(int, input().split()))

step = 0
while max(*arr) >= n:
    arr = sorted(arr)
    cnt = arr[-1] // n
    arr[-1] -= cnt * n
    for i in range(n - 1):
        arr[i] += cnt
    step += cnt

print(step)

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

int n, m, q;
vector<int> a, b, c, d;
int ans;

void show(vector<int> x) {
    rep(i, x.size()) {
        if (i == 0) {
            cout << x[i];
        } else {
            cout << " " << x[i];
        }
    }
    cout << "\t" << &x << endl;
}

void dfs(vector<int> A) {
    if (A.size() == n + 1) {
        int now = 0;
        rep(i, q) {
            if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
        }
        ans = max(ans, now);
        return;
    }

    // show(A);
    A.push_back(A.back());
    while (A.back() <= m) {
        dfs(A);
        A.back()++;
    }
}

void solve() {
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    rep(i,q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    dfs(vector<int>(1,1));
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3620
#入力
N, M = map(int,input().strip().split(' '))
KA = []
for i in range(N):
    KA.append(list(map(int, input().strip().split(' '))))	#[A][B]

#処理用
i = 0
j = 0
k = 0
syurui = 0
suki_cnt = [0] * (M + 1)  #種類カウンタ


#処理
##print(suki_cnt)

for i in range(N):
    for j in range(1,len(KA[i])):
        suki_cnt[KA[i][j]] += 1

for i in range(len(suki_cnt)):
    if suki_cnt[i] == N:        #人数と同じか
        syurui += 1
    else:
        pass
    
print(syurui)



Measured memory_bytes: 3064
import java.util.*;

public class Main {
	void solve() {
		Scanner scan = new Scanner(System.in);
		long x = Math.abs(scan.nextLong());
		long k = scan.nextLong();
		long d = scan.nextLong();
		if(k < x / d) {
			System.out.println(x - d * k);
			return;
		} else {
			k -= x / d;
			x %= d;
			if(k % 2 == 0) {
				System.out.println(x);
			} else {
				System.out.println(d - x);
			}
		}
		scan.close();
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
}


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


int main(){
  int n,p,i;
  cin >> n >> p;
  int ki=0;
  int gu=0;
  vector<int> a(n);
  for(i=0;i<n;++i){
    cin >> a[i];
    if(a[i]%2==0){
      gu++;
    }else{
      ki++;
    }
  }
  long long ans=0;
  if(p==0){
    if(ki==0){
      ans=pow(2,n);
    }else{
      ans=pow(2,n-1);
    }
  }else{
    if(ki==0){
      ans=0;
    }else{
      ans=pow(2,n-1);
    }
  }
  cout << ans << endl;
  return 0;
}


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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int x;
    cin >> x;
    
    cout << x/500*1000 + (x - x/500*500)/5*5 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int l[105];
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>l[i];
	sort(l+1,l+n+1);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			for(int k=j+1;k<=n;k++)
			{
				if(l[i]==l[j]||l[i]==l[k]||l[j]==l[k]) continue;
				if(l[i]+l[j]>l[k]) ans++;
			}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
  string s;
  for(;cin>>s;)
    {
      int mem[10];
      int cnt=0;
      int bit=0;
      memset(mem,0,sizeof(mem));
      for(int i=0;i<s.size();i++)
	{
	  int pos=(s[i]-33)/10;
	  while(pos!=bit)
	    {
	      if(pos>bit)
		{
		  bit++;
		  cout<<">";
		}
	      else
		{
		  bit--;
		  cout<<"<";
		}
	    }
	  int move = mem[pos]-s[i];
	  while(mem[pos]!=s[i])
	    {
	      if(move>0)
		{
		  mem[pos]--;
		  cout<<"-";
		}
	      else
		{
		  mem[pos]++;
		  cout<<"+";
		}
	    }
	  cout<<".";
	}
      cout<<endl;
    }

}

Measured memory_bytes: 1180
// checking graph cycle with dfs algorithm
// reference Programming Contest Challenge Book Second Edition
// verify https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/1/GRL_4_A

#include <iostream>
#include <set>
#include <vector>

using namespace std;

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

template<typename T> struct edge {
  int to;

  edge(int to_) : to(to_) {}
};

template<typename T,template <typename ELEM> class C> struct Check_Cycle {
  vector<vector<C<T>>> G;
  vector<bool> used;
  int V;//0,...,|V|-1

  Check_Cycle (int V_) {
    init(V_);
  }

  void init(int V_) {
    V = V_;

    G.clear();
    G.resize(V);
  }

  void add_edge(int from,int to) {
    G[from].push_back(C<T>(to));
  }

  bool dfs (int i,set<int> pars) {
    pars.insert(i);
    used[i] = true;

    rep(j,(int)G[i].size()) {
      if (!used[G[i][j].to]) {
        if(dfs(G[i][j].to,pars)) {
          return true;
        }
      } else {
        if (pars.find(G[i][j].to) != pars.end())  {
          return true;
        }
      }
    }

    pars.erase(i);
    return false;
  }

  bool check_cycle () {
    used.clear();
    used.resize(V,false);

    rep (i,V) {
      if (!used[i] && dfs(i,set<int>())) {
        return true;
      }
    }

    return false;
  }

};

using ll = long long;

int main() {
  ll V,E;
  cin >> V >> E;
  Check_Cycle<ll,edge> cc(V);
  rep(i,E) {
    ll s,t;
    cin >> s >> t;
    cc.add_edge(s,t);
  }

  cout << cc.check_cycle() << endl;

  return 0;
}



Measured memory_bytes: 3112
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum L = 10L^^9;

void main() {
  try {
    for (; ; ) {
      const S = readLong();
      
      const q = S / L, r = S % L;
      long x1, y1, x2, y2, x3, y3;
      if (q < L) {
        x1 = 0;
        y1 = r;
        x2 = q;
        y2 = 0;
        x3 = q + 1;
        y3 = L;
      } else {
        x1 = 0;
        y1 = 0;
        x2 = L;
        y2 = 0;
        x2 = L;
        y3 = L;
      }
      const area = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1);
      debug {
        writeln(S, " ", area);
      }
      writeln(x1, " ", y1, " ", x2, " ", y2, " ", x3, " ", y3);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 256
#include<iostream>
#include <cstring>
#include<algorithm>
using namespace std;
int dp[10001];
typedef struct sp {
	int cost;
	int damage;
};
bool cmp(sp s1, sp s2){
	return s1.damage < s2.damage;
}
sp s[1001];
int main(){
  int h, n;
  cin >> h >> n; 
  for(int i = 0; i < n; i++)
  	cin >> s[i].damage >> s[i].cost;

  // sort
  sort(s, s + n, cmp);
  for(int j = h; j >= 0; j-- )
  	dp[j] = 100000000;
 // for(int i = 0; i < n; i++)
//  	cout << s[i].damage << s[i].cost << endl;
//  	dp[s[i].damage] = s[i].cost;

  dp[0] = 0;
  for(int i =0 ; i < n; i++){
//  	cout << i << ":";		
  	for(int j = 0; j <= h; j++){
  		if (j <= s[i].damage)
  		  dp[j] = min(dp[j], s[i].cost);
  		//cout << "compared :" << dp[j - s[i].damage] + s[i].cost<<" " << dp[j]<< "  result: "<< min(dp[j - s[i].damage] + s	[i].cost, dp[j])<< endl;
  		else 
		  dp[j] = min(dp[j - s[i].damage] + s[i].cost, dp[j]);
  	}	
  }
  cout << dp[h]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int INF = 10000000;

int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
    char a;
    cin >> a;

    if(isupper(a)) {
        cout << 'A' << endl;
    }else {
        cout << 'a' << endl;
    }

}

Measured memory_bytes: 3596
#include <algorithm>
#include <cassert>
#include <iostream>
#include <queue>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef pair<int, int> BC;
#define mp(a, b) make_pair(a, b)

int main(int argc, char const *argv[]) {
  int p, q, r;

  cin >> p;
  cin >> q;
  cin >> r;

  cout << std::min(std::min(p + q, p + r), q + r);

  return 0;
}


Measured memory_bytes: 256
def getlist():
    return list(map(int, input().split()))


N = int(input())
H = getlist()

j = "Yes"
val = H[0]
for i in range(1, N):
    if H[i] > val:
        val = H[i]
    else:
        if H[i] + 2 <= val:
            j = "No"
            break

print(j)

Measured memory_bytes: 63984
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <climits>
int main()
{
    long s;
    std::cin >> s;
    bool table[1000000+1]={};

    table[s]=1;
    long count=2;
    while(1){
        if(s%2==0){
            s=s/2;
        }else{
            s=3*s+1;
        }
        if(table[s]==1){
            break;
        }else{
            table[s]=1;
            count++;
        }
    }
    std::cout << count << std::endl;
    return 0;
}

Measured memory_bytes: 4612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
ll N;
string tmp;

string convertToRadix(ll x, int radix)
{
    x = abs(x);
    ll r = 0, q = 0;
    string ans = "";
    while (x >= 1)
    {
        r = x / radix;
        q = x % radix;
        ans.push_back((char)(q + '0'));
        x = r;
    }
    reverse(all(ans));
    return ans;
}
ll convertToInteger(string S, int radix)
{
    ll ans = 0;
    rep(i, S.size())
    {
        ans += (S[i] - '0') * pow(radix, i);
    }
    return ans;
}
typedef bitset<10> bs;
void solve(int k, int m, string s)
{
    if (k == N)
    {
        cout << s << '\n';
        return;
    }
    for (int i = 0; i < min(k + 1, m + 2); i++)
    {
        solve(k + 1, max(m, i), s + (char)('a' + i));
    }
}
int main()
{

    cin >> N;
    solve(0, 0, "");
    return 0;
}

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

class dice{
private:
	int D1;
	int D2;
	int D3;
	int D4;
	int D5;
	int D6;
public:
	dice(){
	D1=1;
	D2=2;
	D3=3;
	D4=4;
	D5=5;
	D6=6;
	}
	dice(int d1,int d2,int d3,int d4,int d5,int d6){
	D1=d1;
	D2=d2;
	D3=d3;
	D4=d4;
	D5=d5;
	D6=d6;
	}
	void turn(char a){
		int front=D2;
		int back=D5;
		int top=D1;
	        int botton=D6;
		int right=D3;
		int left=D4;
		if(a=='E'){
			top=D4;
			right=D1;
			left=D6;
			botton=D3;
		}
		if(a=='N'){
			top=D2;
			front=D6;
			botton=D5;
			back=D1;
		}
		if(a=='S'){
			top=D5;
			front=D1;
			botton=D2;
			back=D6;
		}
		if(a=='W'){
			top=D3;
			left=D1;
			botton=D4;
			right=D6;
		}
		D1=top;
		D2=front;
		D3=right;
		D4=left;
		D5=back;
		D6=botton;
	}
	void in(int a,int b,int c,int d,int e,int f){
		D1=a;
		D2=b;
		D3=c;
		D4=d;
		D5=e;
		D6=f;
	}
	int get_d1(){
		return D1;
	}
	int get_d2(){
		return D2;
 	}
 	int get_d3(){
		return D3;
 	}
 	int get_d4(){
		return D4;
 	}
 	int get_d5(){
		return D5;
 	}
 	int get_d6(){
		return D6;
 	}	
};

int main(){
	int d[100][6]={0};
	int count=0;
	int n;
	
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<6;j++){
			cin>>d[i][j];
		}
	}
	dice p[100];
	
	for(int i=0;i<n;i++)
		p[i].in(d[i][0],d[i][1],d[i][2],d[i][3],d[i][4],d[i][5]);

	for(int x=0;x<n;x++){
	for(int y=x+1;y<n;y++){
	for(int i=0;i<4;i++){
		p[x].turn('S');
		for(int j=0;j<4;j++){
			p[x].turn('E');
			for(int k=0;k<4;k++){
				p[x].turn('S');
				for(int l=0;l<4;l++){
					p[x].turn('E');
					count++;
					if(p[x].get_d1()==p[y].get_d1() && p[x].get_d2()==p[y].get_d2() && p[x].get_d3()==p[y].get_d3() && p[x].get_d4()==p[y].get_d4() && p[x].get_d5()==p[y].get_d5() && p[x].get_d6()==p[y].get_d6()){
						cout<<"No\n";
						goto exit;
					}
					/*else if((p1.get_d1()!=p2.get_d1() || p1.get_d2()!=p2.get_d2() || p1.get_d3()!=p2.get_d3() || p1.get_d4()!=p2.get_d4() || p1.get_d5()!=p2.get_d5() || p1.get_d6()!=p2.get_d6()) && count==4*4*4*4){
						cout<<"No\n";
						goto exit;
					}*/
				}
			}
		}
	}
	}
	}
	cout<<"Yes\n";
	exit:;
					
}

Measured memory_bytes: 1128
(* O(log(k)) *)
let rec find acc k x =
  if x >= k then acc
  else find (acc + 1) k (x * 2)

(* O(n * log(k)) *)
let _ =
  Scanf.scanf "%d %d" @@ fun n k ->
    let sum = ref 0. in
    for i = 1 to n do
      let p = float @@ find 0 k i in
      sum := !sum +. 1. /. float n *. (0.5 ** p)
    done;
    Printf.printf "%.12f\n" !sum

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

using namespace std;

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;


int main(){
    int N;
    cin >> N;
    vector<double> ts(N + 2, 0);
    vector<double> vs(N + 2, 0);
    int T = 0;
    rep(i, N){
        cin >> ts[i + 1];
        T += ts[i + 1];
    }

    rep(i, N){
        cin >> vs[i + 1];
    }

    rep(i, N + 1){
        // 感覚から時刻に直す.
        ts[i + 1] += ts[i];
    }

    double ans = 0.0;

    double prev_v = 0.0;

    for(double i = 0.5; i <= T; i += 0.5){
        double v = 100;
        for(int j = 0; j < N + 2; j ++){
            if(j >= 1 && ts[j - 1] <= i && i <= ts[j]){
                v = min(v, (double)vs[j]);
            }
            if(ts[j] < i){
                v = min(v, (double)(vs[j] + (i - ts[j])));
            }
            if(j >= 1 && ts[j - 1] > i){
                v = min(v, (double)(vs[j] + (- i + ts[j - 1])));
            }
        }
        ans += (v + prev_v) * 0.25;
        prev_v = v;
    }
    cout.precision(20);
    cout << fixed << ans << endl;
    return 0;
}


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

typedef long long int ll;
typedef pair<int,int> pi;
priority_queue<pi, vector<pi>, greater<pi> > pq; //min heap

ll mini(ll a,ll b){	return a<b?a:b;}
ll maxi(ll a,ll b){	return a>b?a:b;}
ll gcd(ll a,ll b){	if(b == 0)	return a;return gcd(b,a%b);}
ll binpow(ll n,ll x){	ll ans = 1;while(x){if(x & 1)	ans *= n;n *= n;x >>= 1;}return ans;}

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

    int n;
    cin>>n;

    vector<int> tot(3,0);
    vector<int> vals(3,0);

    for(int i=0;i<n;++i){
        vector<int> cur(3,0);
        for(int j=0;j<3;++j)    cin>>vals[j];
        
        for(int i=0;i<3;++i){
            for(int j=0;j<3;++j){
                if(i!=j){
                    cur[j] = max(cur[j], tot[i] + vals[j]);
                }
            }
        }

        tot = cur;
    }

    cout<<max(tot[0], max(tot[1], tot[2]))<<"\n";

    return 0;
}

Measured memory_bytes: 3588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _0030
{
    class Program
    {
        internal static int _answer = 0;
        internal static int _goal = 0;
        internal static int _termNum = 0;
        static void Main(string[] args)
        {
            Calc calc = new Calc();
            string input;
            while ((input = Console.ReadLine()) != "0 0")
            {
                _answer = 0;
                _termNum = input.Split(' ').Select(int.Parse).ToArray()[0];
                _goal = input.Split(' ').Select(int.Parse).ToArray()[1];
                if (_goal <= 45)
                {
                    calc.CalcCombination(0, _termNum, 0);
                }
                Console.WriteLine(_answer);
            }
        }
    }
    class Calc
    {
        internal void CalcCombination(int currentSum, int restTerms, int currentNum)
        {
            if (currentSum == Program._goal && restTerms == 0)
            {
                ++Program._answer;
                return;
            }
            if (restTerms == 0)
                return;
            for (int i = currentNum; i <= 9; ++i)
            {
                CalcCombination(currentSum + i, restTerms - 1, i + 1);
            }
            return;
        }
    }
}



Measured memory_bytes: 16348
s=input()[::-1]
n=0
import sys
while n<len(s):
    if s[n:n+5]=="maerd" or s[n:n+5]=="esare":
        n+=5
    elif s[n:n+6]=="resare":
        n+=6
    elif s[n:n+7]=="remaerd":
        n+=7
    else:
        print("NO")
        sys.exit()
print("YES")

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

signed main(){
    int N; cin >> N;
    vector<int> a(N + 1);
    int S = 0;
    for(int i = 1; i <= N; i++){ cin >> a[i]; S += a[i];};
    int x1 = S;
    for(int i = 2; i <= N; i += 2){
        x1 -= 2 * a[i];
    }
    cout << x1 << " ";
    for(int i = 2; i <= N; i++){
        x1 = 2 * a[i - 1] - x1;
        cout << x1 << " ";
    }
    cout << endl;
}

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

#define Bye return 0
#define ll long long
const ll MAX = 1e2;

void solve(){
    int a, b; cin>>a>>b;
    int sum = a + b;
    if((a + b) < 10) cout<<(a+b)<<endl;
    else cout<<"error"<<endl;
}

int main(){
    solve();
    Bye;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
const ll M = pow(10,9)+7;
/*template*/

int main()
{
  int x,y,z;cin>>x>>y>>z;
  cout<<z<<' '<<x<<' '<<y<<endl;
  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> pos, neg;
  rep(i, n) {
    cin >> a.at(i);
    if (a.at(i) < 0) neg.push_back(a.at(i));
    else pos.push_back(a.at(i));
  }

  int posSize = pos.size();
  int negSize = neg.size();
  bool ok = false; // 選び方によって、答えを正にすることができる場合 true
  if (posSize > 0) {
    if (n == k) ok = (negSize % 2 == 0);
    else ok = true;
  } else {
    ok = (k % 2 == 0);
  }

  ll ans = 1;
  if (!ok) {
    sort(a.begin(), a.end(), [](int x, int y) {
      return abs(x) < abs(y);
    });
    rep(i, k) ans = ans * a.at(i) % mod;
    ans = mod + ans;
  } else {
    sort(pos.begin(), pos.end());
    sort(neg.rbegin(), neg.rend());
    if (k % 2 == 1) {
      ans = ans * pos.back() % mod;
      pos.pop_back();
    }

    vector<ll> p;
    while (pos.size() >= 2) {
      ll x = pos.back(); pos.pop_back();
      x *= pos.back(); pos.pop_back();
      p.push_back(x);
    }
    while (neg.size() >= 2) {
      ll x = neg.back(); neg.pop_back();
      x *= neg.back(); neg.pop_back();
      p.push_back(x);
    }
    sort(p.rbegin(), p.rend());
    rep(i, k/2) ans = ans * (p.at(i) % mod) % mod;
  }

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

Measured memory_bytes: 6304
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

S=get_nsp
if S[2]==S[3] and S[4]==S[5]
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 1788
//https://atcoder.jp/contests/keyence2019/tasks/keyence2019_d
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int R,C;
int r[11234];
int c[11234];
constexpr int mod = 1e9+7;
int main(){
    cin>>R>>C;
    LL ret=1;
    LL f=0;
    for(int i:range(R))cin>>r[i];
    for(int i:range(C))cin>>c[i];
    sort(r,r+R);
    sort(c,c+C);
    int x=R-1,y=C-1;
    LL useR=0;
    LL useC=0;
    for(int i=R*C;i>=1;i--){
        int rp=(x>=0?r[x]:0);
        int cp=(y>=0?c[y]:0);
        if(rp==i&&cp==i){
            f+=useR+useC;
            useR++;
            useC++;
            x--;
            y--;
        }
        else if(rp!=i&&cp!=i){
            ret=(ret*f)%mod;
            f--;
        }
        else if(rp==i){
            ret=(ret*useC)%mod;
            f+=(useC-1);
            useR++;
            x--;
        }
        else{ //cp==i
            ret=(ret*useR)%mod;
            f+=(useR-1);
            useC++;
            y--;
        }
        //cout<<i<<" "<<ret<<endl;
    }
    cout<<ret<<endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
h=input().split()
h=list(map(int,h))
cnt=0
i=0
while(True):
    
    if(sum(h)==0):
        break 
    else:
        if h[i]!=0:
            for j in range(n-i):
                if(h[i+j]==0):
                    i=0
                    j=0
                    break
                else:
                    h[i+j]-=1
            cnt+=1            
        elif h[i]==0:
            i+=1               
                                   
                   
print(cnt)             

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

Measured memory_bytes: 21132
#include<stdio.h>

int main(void)
{
        int a,b,c,sum;

        scanf("%d%d%d",&a,&b,&c);

        if(a<b){
                sum = a;
                if(b<c)
                        sum += b;
                else
                        sum += c;
        }
        else if(b<a){
                sum = b;
                if(a<c)
                        sum += a;
                else
                        sum += c;
        }
        else if(c<a){
                sum = c;
                if(a<b)
                        sum += a;
                else
                        sum += b;
        }
        else
                sum = a + b;

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

        return 0;
}


Measured memory_bytes: 128
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,child,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

vector<int> V[100001];
vector<int> v;
int visited[100001];
int ans[100001];
void tsort(int x){
  if(visited[x]) return;
  visited[x] = 1;
  for(auto y: V[x]){
    tsort(y);
  }
  v.push_back(x);
}

int main(){
  int N, M;
  cin >> N >> M;
  rep(i, N + M - 1){
    int a, b;
    cin >> a >> b;
    V[a].push_back(b);
  }
  rep(i, N) tsort(i + 1);
  reverse(v.begin(), v.end());
  for(int parent: v){
    for(int child: V[parent]){
      ans[child] = parent;
    }
  }
  rep(i, N) cout << ans[i + 1] << endl;
  return 0;
}


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

int k, s;

int main()
{
    cin >> k >> s;
    int ans = 0;
    for (int i = 0; i <= k; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            if (s - i - j >= 0 && s - i - j <= k)
                ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
//配列の添字ズレに注意
//=に注意

int main(){
  int l,r,d; cin>>l>>r>>d;
  
  //string s; cin>>s;
  
  cout<<r/d - (l-1)/d  <<endl;
}

Measured memory_bytes: 3632
A, B, C = [int(x) for x in input().split()]

count = 0
while B - A >= 2 or C - A >= 2:
    A += 2
    count += 1

while A - B >= 2 or C - B >= 2:
    B += 2
    count += 1

while B - C >= 2 or A - C >= 2:
    C += 2
    count += 1


t = sorted([A, B, C])
if t[0] == t[2]:
    print(count)
elif t[0] == t[1]:
    print(count + 1)
else:
    print(count+2)


Measured memory_bytes: 3064
N = gets.to_i
S = gets.chomp

left = 0
count = 0
N.times do |i|
    count += (S[i] == '(' ? 1 : -1)
    if count < 0
        left += 1
        count += 1
    end
end
right = count

puts "#{'('*left}#{S}#{')'*right}"

Measured memory_bytes: 1788
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
arr = []
a.each do |i|
    if i % 2 == 0
        arr << i
        # if i % 3 == 0 || i % 5 == 0
        #     count += 1
        # end
    end
end

# arr.each do |j|
#     if j % 3 != 0 || j % 5 != 0
#             puts "DENIED"
#     end
# end
all = arr.size
# p count
 count = 0
# p count
# p arr
ans = 0
if arr == []
    ans += 1
else

    arr.each do |j|
    if j % 3 == 0 || j % 5 == 0
            count += 1
    end
end
end
# p count
# p count_size

if count == all  || ans >= 1
    puts "APPROVED"
else
    puts "DENIED"
end



Measured memory_bytes: 14420
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    if (S[i] == 'L') {
      if (i > 0 && S[i - 1] == 'L') {
        cnt++;
      }
    } else {
      if (i + 1 < N && S[i + 1] == 'R') {
        cnt++;
      }
    }
  }
  cout << min(N - 1, cnt + 2 * K) << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=1010;
int n,k,a[N],pos[N],cnt[N],b[N],pmx[N],pmn[N];
bool check(int l) {
	int mx=0;
	rep(i,0,k) mx=max(mx,b[i]+(l<i));
	for (int j=l-1;j>=0;j--) {
		mx=max(mx,b[j+1]+1);
		pmx[j]=mx;
	}
	int mn=(1<<20);
	rep(i,0,k) mn=min(mn,2*b[i]);
	rep(i,0,l-1) {
		mn=min(mn,2*b[i]-1);
		pmn[i]=mn;
	}
	for (int j=l-2;j>=0;j--) {
		if (pmx[j]<=pmn[j]) return 1;
	}
	mx=0,mn=1<<20;
	rep(i,0,k) {
		mx=max(mx,b[i]);
		mn=min(mn,2*b[i]-(i<l));
	}
	if (mx<=mn) return 1;
	return 0;
}
bool check(int l,int r) {
	rep(z,0,k) cnt[z]=0;
	rep(z,l+1,r+1) cnt[pos[z]]++;
	rep(z,0,k) if (cnt[z]>=2) return 0;
	for (int i=l;i>=0;i--) {
		cnt[pos[i]]++;
		if (cnt[pos[i]]>=2) return 0;
		int t=0;
		rep(j,i,r+1) b[t++]=a[pos[j]]+1;
		rep(j,0,k) if (!cnt[j]) b[t++]=a[j];
		if (check(r-i+1)) return 1;
	}
	return 0;
}

int main() {
	scanf("%d",&k);
	rep(i,0,k) scanf("%d",a+i),n+=a[i];
	if (*max_element(a,a+k)>*min_element(a,a+k)*2) {
		puts("-1");
		return 0;
	}
	int lastp=-1;
	rep(i,0,n) {
		bool vv=0;
		rep(j,0,k) if (a[j]>0) {
			a[j]--;
			pos[i]=j;
			if (check(lastp+1,i)) {
				if (i>=k-1) {
					rep(z,0,k) cnt[z]=0;
					rep(z,i-k+1,i+1) cnt[pos[z]]++;
					bool val=1;
					rep(z,0,k) if (cnt[z]==0) val=0;
					if (val) lastp=i;
				}
				//printf("valid %d %d\n",i,j);
				vv=1;
				break;
			}
			a[j]++;
		}
		assert(vv);
	}
	rep(i,0,n) printf("%d ",pos[i]+1); puts("");
}

Measured memory_bytes: 3848
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int N,L;
int main() {
  cin >> N >> L;
  string S[100];
  for(int i=0;i<N;i++) {
    char tmp[256];
    scanf("%s", tmp);
    S[i] = tmp;
  }
  sort(S, S+N);
  for(int i=0;i<N;i++) {
    cout << S[i];
  }
  cout << endl;
  return(0);
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var b [3][3]int
	for i:=0; i<3; i++ {
		fmt.Scan(&b[i][0], &b[i][1], &b[i][2],)
	}
	var N int
	fmt.Scan(&N)
	var tmp int
	for i:=0; i<N; i++ {
		fmt.Scan(&tmp)
		for j:=0; j<3; j++ {
			for k:=0; k<3; k++ {
				if(b[j][k] == tmp) {
					b[j][k] = 0
				}
			}
		}
	}

	for i:=0; i<3; i++ {
		if((b[i][0] == b[i][1] && b[i][1] == b[i][2]) || (b[0][i] == b[1][i] && b[1][i] == b[2][i])) {
			fmt.Println("Yes")
			return
		}
	}
	if((b[0][0] == b[1][1] && b[1][1] == b[2][2]) || (b[2][0] == b[1][1] && b[1][1] == b[0][2])) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys


def solve(K: int, A: int, B: int):
    i = 1
    while K * i <= B:
        if K * i >= A:
            print("OK")
            return
        i += 1
    print("NG")
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(K, A, B)

if __name__ == '__main__':
    main()

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

int sumOfDigits(const int N){
    int sum=0;
    string Ns = to_string(N);
    for(int i=0; i<Ns.size(); i++){
        sum += (int)Ns[i] - (int)'0';
    }
    return sum;
}

int main(){
    int N; cin >> N;
    int A, B; cin >> A >> B;
    
    int sum=0;
    for(int i=1; i<=N; i++){
        int sumD = sumOfDigits(i);
        if( A<=sumD && sumD<=B ){ sum += i; }
    }
    
    cout << sum;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int M=sc.nextInt();
        
        if(N>=M){
            System.out.println(0);
            return;
        }
        
        int[] X=new int[M];
        
        for(int i=0;i<M;i++){
            X[i]=sc.nextInt();
        }
        
        Arrays.sort(X);

        int[] Xdif=new int[M-1];
        
        for(int i=0;i<M-1;i++){
            Xdif[i]=X[i+1]-X[i];
        }
        
        Arrays.sort(Xdif);
        int SUM=0;
                
        for(int i=0;i<M-1;i++){
            SUM+=Xdif[i];
        }
        
        for(int i=0;i<N-1;i++){
            SUM-=Xdif[M-i-2];
        }
        
        System.out.println(SUM);
    }
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<vector<int>> judge(n);
  for(int i = 0; i < n; i++) {
    int a;
    cin >> a;
    h.at(i) = a;
  }
  
  for(int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    judge.at(a).push_back(b);
    judge.at(b).push_back(a);
  }
  
  /*for(int i = 0; i < n; i++) {
    cout << judge.at(i).size() << endl;
  }*/
  
  int ans = 0;
  for(int i = 0; i < n; i++) {
    if(judge.at(i).size() == 0) {
      ans++;
      continue;
    }
    for(int j = 0; j < judge.at(i).size(); j++) {
      if(h.at(i) <= h.at(judge.at(i).at(j))) {
        break;
      }
      if(j == judge.at(i).size()-1 && h.at(i) > h.at(judge.at(i).at(j))) {
        ans++;
      }
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl);
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    ll n, T;
    cin >> n >> T;
    vector<ll> a(n);
    rep(i, n) scanf("%lld", &a[i]);
    ll stop = 0;
    ll ans = 0;
    rep(i, n){
        ans += T;
        ans -= max(0ll, stop-a[i]);
        stop = a[i]+T;
    }
    ppp(ans);

    return 0;
}


Measured memory_bytes: 1792
N = int(input())

def f(limit):
    i = 1
    j = 2
    while True:
        if i > limit:
            break
        yield i
        i += j
        j += 1

def h1(l, n):
    s = 0
    for i in range(n):
        yield l[s:s+i+1]
        s += i+1

def h2(p, l):
    if not l:
        return
    for pp, ll in zip(p, l):
        ll.append(pp)
    h2(l[0], l[1:])

l = list(f(10**5))

if N in l:
    print("Yes")

    n = l.index(N)+1
    print(N*2//n)

    t = list(h1(list(range(1, N+1)), n))
    t.reverse()
    t.append([])

    h2(t[0], t[1:])

    for i in t:
        print(len(i), " ".join(str(j) for j in i))
else:
    print("No")


Measured memory_bytes: 10472
#include <iostream>

using namespace std;

int main()
{
    char S,yes=0,no=0;
    for(int i=0;i<3;i++){
        cin>>S;
        if(S=='A')
            yes++;
        else if(S=='B')
            no++;
    }
    if(yes==3 || no==3)
        cout<<"No"<<endl;
    else
        cout<<"Yes";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
#define x1 qeerdx
#define y1 qeerdy
 
#define lb lower_bound
#define ub upper_bound
 
#define endl '\n'
#define fast_in ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
#define mp  make_pair
#define pb  push_back
 
#define fi first
#define se second
 
#define   sz(x)  (int)x.size()
#define  all(x)  x.begin(), x.end()
#define  bit(x)  __builtin_popcountll(x)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair <int,int> pii;
 
const int inf = (int) 1e9+99999, mod = (int)1e9+7;
const ll linf = (ll) 2e18+99999;
 
int kob (int x, int y) { return ((ll)x * y) % mod; } 
int aza (int x, int y) { x -= y; if (x < 0) return x + mod; return x; } 
int kos (int x, int y) { x += y; if (x >= mod) return x - mod; return x; }
 
const int maxn = (int)3e5, maxn2 = (int) 1e6+55;
 
static long holdrand = 1L;
void srand(unsigned int seed){holdrand = (long) seed;} 
int rand() {return (((holdrand = holdrand * 214013L + 2531011L) >> 16) & 0x7fff);}

int main () {
	int a, p;
	cin >> a >> p;
	cout << ((a * 3) + p) / 2;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string s; cin >> s;
    int win = 0, lose = 0;
    for(int i = 0; i < s.length();i++){
        if(i%2 == 0){
            if(s[i]=='p') lose++;
        }else{
            if(s[i]=='g') win++;
        }
    }
    res = win - lose;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#define M 100000
#define SENTINEL 2000000000

struct Card{
  char suit;
  int value;
};

struct Card L[M/2+2], R[M/2+2];

void merge(struct Card A[], int n, int left, int mid, int right){
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for ( i = 0; i < n1; i++ ) L[i] = A[left + i];
  for ( i = 0; i < n2; i++ ) R[i] = A[mid + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for ( k = left; k < right; k++ ){
    if ( L[i].value <= R[j].value ){
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}
 
void mergeSort(struct Card A[], int n, int left, int right ){
  int mid;
  if ( left+1 < right ){
    mid = (left + right)/2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int partition(struct Card A[], int n, int p, int r){
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p - 1;
  for ( j = p; j < r; j++ ){
    if ( A[j].value <= x.value ){
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }
  t = A[i+1]; A[i+1] = A[r]; A[r] = t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r){
  int q;
  if ( p < r ){
    q = partition(A, n, p, r);
    quickSort(A, n, p, q - 1);
    quickSort(A, n, q + 1, r);
  }
}

main(){
  int n, i, v;
  struct Card A[M], B[M];
  char S[10];
  int stable = 1;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A, n, 0, n);
  quickSort(B, n, 0, n-1);

  for ( i = 0; i < n; i++ ){
    if ( A[i].suit != B[i].suit ) stable = 0;
  }

  if ( stable == 1 ) printf("Stable\n");
  else printf("Not stable\n");
  for ( i = 0; i < n; i++ ) {
    printf("%c %d\n", B[i].suit, B[i].value);
  }
}



Measured memory_bytes: 4072