akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

ll lcm(ll u, ll v) {
  return u*v/gcd(u,v);
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  string s;
  ll c=0;
  cin >> s;
  rep(i,s.length())if(s[i]=='o')c++;
  if(c+15-s.length()>=8)printf("YES");
  else printf("NO");
}

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

#define ll long long

using namespace std;

const int MAXN = 1010;
const int MAXM = 100010;
const int MAXINT = 2147483647;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n, m, k;
int ans, tot, cnt;

int a[MAXN][MAXN], b[MAXN][MAXN];

string s;

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

void re() {
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			a[i][j] = b[i][j];
		}
	}
}

int count() {
	int res = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i][j] == 1) {
				res++;
			}
		}
	}
	return res;
}

int main(){
	int T;
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; i++) {
		cin >> s;
		for (int j = 0; j < s.size(); j++) {
			if (s[j] == '#') a[i][j + 1] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			b[i][j] = a[i][j];
		}
	}
	for (int i = 0; i < (1 << n); i++) {
		for (int j = 0; j < (1 << m); j++) {
			int x = i, y = j, num = 1;
			while (num <= n) {
				if (x & 1) for (int k = 1; k <= m; k++) a[num][k] = 2;
				x >>= 1;
				++num;
			}
			num = 1;
			while (num <= m) {
				if (y & 1) for (int k = 1; k <= n; k++) a[k][num] = 2;
				y >>= 1;
				++num;
			}
			num = count();
			if (num == k) ans++;
			re();
		}
	}
	printf("%d\n", ans);
	return 0;
}

/*

*/


Measured memory_bytes: 3776
local k = io.read("*n")
local div = k // 50
local rem = k % 50
local ary = {}
ary[1] = 0
for i = 2, 50 do ary[i] = 49 end
for i = 1, rem do
  for j = 1, 50 do
    ary[j] = ary[j] + (j == i and 50 or -1)
  end
end
for i = 1, 50 do ary[i] = ary[i] + div end
print(50)
for i = 1, 50 do
  io.write(ary[i])
  io.write(i == 50 and "\n" or " ")
end


Measured memory_bytes: 760
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    string S;
    cin >> S;
    int N = S.size();
    bool ans = true;
    rep(i, N / 2) {
        if (S[i] != S[N - 1 - i]) ans = false;
    }
    rep(i, N / 2 / 2) {
        if (S[i] != S[N / 2 - 1 - i]) ans = false;
    }
    write(ans ? "Yes" : "No");
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct damage {
    int d; //ダメージ量
    bool isT; //ダメージの種類

    bool operator<( const damage& right ) const {
        return d > right.d;
    }
};

int main(){
    int N,H,a,b,i;
    int ans=0;
    vector<damage> dlist;
    damage d;
    cin >> N >> H;
    for(i=0;i<N;i++){
        cin >> a >> b;
        d.d = a;
        d.isT = false;
        dlist.push_back(d);
        d.d = b;
        d.isT = true;
        dlist.push_back(d);
    }
    sort(dlist.begin(),dlist.end());
    i = 0;
    while(H>0){
        d = dlist[i];
        if(d.isT == true){
            H -= d.d;
            ans++;
        }
        else{
            ans += H/d.d;
            if(H%d.d != 0) ans++;
            break;
        }
        i++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <numeric>

using namespace std;


void func()
{
	int N, K;
	cin >> N >>K;

	vector<int>sunuke(N, 0);
	for (int i = 0; i < K; ++i)
	{
		int di;
		cin >> di;
		for (int j = 0; j < di; ++j)
		{
			int index;
			cin >> index;
			sunuke[index - 1]++;
		}
	}
	cout << count(sunuke.begin(), sunuke.end(), 0)  << endl;
}

int main() {

//	while (1)
		func();
	return 0;
}


Measured memory_bytes: 3148
print(' '.join(map(str, [11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381][:int(input())])))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

int cnt[maxn];
int done[maxn];

int32_t main(){
	fastio();
	int n , m;
	cin >> n >> m;
	for(int i = 1; i <= m; i++){
		int k;
		cin >> k;
		string s;
		cin >> s;
		
		if(s =="AC") done[k] = 1;
		if(!done[k]) cnt[k]++;
	}

	int a = 0, b = 0;
	for(int i = 1; i <=n;i++){
		if(done[i]) a++, b+=cnt[i];
	}

	cout << a <<" "<<b;
}

Measured memory_bytes: 5144
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n)  RFOR(i,0,n)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
#define P pair<int,int>
#define PPi pair<P,int>
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

struct vertex{ vector<int> edge;};
vertex G[100001];
int N,d1[100001],dN[100001];

void dfsN(int p){	
	REP(i,G[p].edge.size()){
		int tem=G[p].edge[i];
		if(tem!=1&&dN[tem]==INF){
			dN[tem]=dN[p]+1;
			dfsN(tem);
		}
	}
	return;
}

void dfs1(int p){
	REP(i,G[p].edge.size()){
		int tem=G[p].edge[i];
		if(tem!=N&&d1[tem]==INF){
			d1[tem]=d1[p]+1;
			dfs1(tem);
		}
	}
	return;
}
int main(void){
	int a,b,result=0;
	REP(i,100001){
		d1[i]=INF;
		dN[i]=INF;
	}
	cin>>N;
	REP(i,N-1){
		cin>>a>>b;
		G[a].edge.pb(b); 
		G[b].edge.pb(a);
	}
	d1[1]=0; dN[N]=0;
	dfs1(1); 
	dfsN(N);
	FOR(i,2,N){
		if(d1[i]<=dN[i]) result++;
		else result--;
	}

	string S=result>0 ? "Fennec" : "Snuke";

	print(S);
	return 0;
}




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

using namespace std;

int main() {
	long long a, b;
	cin >> a >> b;
	
	if (a > 0){
		cout << "Positive";
	}
	else if (a == 0 || b == 0) {
		cout << "Zero";
	}
	else if (a < 0 && 0 < b) {
		cout << "Zero";
	}
	else {
		if ((b - a + 1) % 2 == 0) {
			cout << "Positive";
		}
		else {
			cout << "Negative";
		}
	}
	
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;



public class Main{
  static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}



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

    long a = sc.nextLong();
    long b = sc.nextLong();

    long m = gcd(a,b);
    if(m==1){
      System.out.println(1);
    }else{
      int count =1; //1は事前にカウント

      if(m%2==0){
        count +=1; //素数2のカウント
        m = m/2;
        while(m%2==0){
          m = m/2;
        }
      }
      for(int i=3; i<=Math.sqrt(m); i+=2){
        if(m%i==0){
          count +=1;
          while(m%i==0){
            m = m/i;
          }
        }
      }
      //System.out.println(m);
      if(m>1){
        count+=1; //m =3,5,7の時for分でカウントされない分
      }
      System.out.println(count);
    }



  }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define PI pair<int,int>
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL) 

	


int32_t main()
{
    boost;
    
     int n,k,s;
     cin>>n>>k>>s;
     for(int i=1;i<=k;i++)
     	cout<<s<<" ";
    
     if(s==1){
     	for(int i=k+1;i<=n;i++)
     		cout<<s+1<<" ";
     }
     else{
     	for(int i=k+1;i<=n;i++)
     		cout<<s-1<<" ";
     }
}


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

// # DEFINES # //
#define ll long long
#define M (ll)(1e9+7)
#define EPS 1e-9

using namespace std;

ll s(ll n) {
    ll count = 0;
    while(n) {
        count += n % 10;
        n /= 10;
    }
    return count;
}

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

    ll n;

    cin >> n;

    if(n % s(n)== 0)
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;


    return 0;
}

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;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;}
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;}
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M; cin >> N >> M;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    sort(all(A));
    ll lb=0,ub=1e9;
    while(ub-lb>1){
        ll mid=(lb+ub)/2;
        ll cnt=0;
        for (int i=N-1;i>=0;--i){
            ll a=A.end()-lower_bound(all(A),mid-A[i]);
            a-=N-1-i;
            if (a<=0) break;
            cnt+=a*2-1;
        }
        if (cnt>=M) lb=mid;
        else ub=mid;
    }
    vector<ll> B(N+1,0);
    rep(i,N) B[i+1]=B[i]+A[i];
    ll ans=0,cnt=0;
    for (int i=N-1;i>=0;--i){
        ll a=A.end()-lower_bound(all(A),lb-A[i])-(N-1-i);
        ll b=lower_bound(all(A),lb-A[i])-A.begin();
        if (a<=0) break;
        ans+=(B[i+1]-B[b])*2+A[i]*(2*a-2);
        cnt+=a*2-1;
    }
    rep(i,cnt-M) ans-=lb;
    cout << ans << endl;
}

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

int main() {
    string S;
    cin >> S;
    for (int i=0; i<S.length(); i++) {
        if (i % 2 == 0 && S[i] == 'L') { cout << "No\n"; return 0; }
        else if (i % 2 != 0 && S[i] == 'R') { cout << "No\n"; return 0; }
    }
    cout << "Yes\n";
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    ll ans = 0;
    vector<ll> a(N); rep(i, N){cin >> a.at(i); ans += a.at(i) - 1;}
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

int main(){
    int N, M;
    cin >> N >> M;
    int H[N];
    int G[N] = {};
    for(int i = 0; i < N; i++){
        cin >> H[i];
    }
    int A[M], B[M];
    for(int i = 0; i < M; i++){
        cin >> A[i] >> B[i];
        if(H[A[i]-1] < H[B[i]-1]){
            G[A[i]-1] = 1;
        }
        else if(H[A[i]-1] > H[B[i]-1]){
            G[B[i]-1] = 1;
        }
        else{
            G[A[i]-1] = 1;
            G[B[i]-1] = 1;
        }
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(G[i] == 0){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5184
MOD = 10**9 + 7


def dup(x, y):
    return x + x*y + 1 - y**2


def main():
    n, m = map(int, input().split())
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    tmp = 0
    for i in range(n-1):
        tmp = (tmp + (x[i+1] - x[i]) * dup(n-2, i)) % MOD
    ans = 0
    for i in range(m-1):
        ans = (ans + (y[i+1] - y[i]) * dup(m-2, i) * tmp) % MOD
        ans = ans % MOD
    print(ans)


if __name__ == "__main__":
    main()


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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}


int H, W;
char S[20][20];
char C[20][20];
int rowperm[20];
bool row_used[20];

bool is_match(const string &s1, const string &s2){
    for(int i = 0; i < (int)s1.size(); i++){
        if(s1[i] != s2[(int)s1.size() - 1 - i]){
            return false;
        }
    }
    return true;
}

bool rec(int depth){
    if(depth == H / 2){
        // rowpermの順番に文字列をセット
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                C[i][j] = S[rowperm[i]][j];
            }
        }
        // colを決定する
        string ss[20];
        for(int j = 0; j < W; j++){
            for(int i = 0; i < H; i++){
                ss[j] += C[i][j];
            }
        }

        // 奇数の場合、どれか一つを除いて判定
        for(int i = 0; i < W; i++){
            bool used[20] = {};
            if(W % 2){
                if(!is_match(ss[i], ss[i])){
                    continue;
                }
                used[i] = true;
            }
            
            // ２つのペアを作っていく
            for(int j = 0; j < W; j++){
                if(used[j]) continue;
                used[j] = true;
                bool ok = false;
                for(int k = 0; k < W; k++){
                    if(used[k]) continue;
                    if(j == k) continue;
                    if(is_match(ss[j], ss[k])){
                        used[k] = true;
                        ok = true;
                        break;
                    }
                }
                if(!ok) break;
            }

            int cnt = 0;
            for(int i = 0; i < W; i++)
                if(used[i]) cnt++;
            
            if(cnt == W) return true;

            if(W % 2 == 0) break;

            if(W % 2) used[i] = false;
        }
        return false;
    }
    else{
        int start = -1;
        // 使っていない一番左の要素は確定
        for(int i = 0; i < H; i++){
            if(row_used[i]) continue;
            start = i;
            break;
        }

        row_used[start] = true;
        rowperm[depth] = start;

        for(int i = start + 1; i < H; i++){
            if(row_used[i]) continue;
            rowperm[H - 1 - depth] = i;
            row_used[i] = true;
            if(rec(depth + 1))
                return true;
            row_used[i] = false;
        }
        row_used[start] = false;
    }
    return false;
}

bool solve(){
    // rowを決める
    if(H % 2){
        for(int i = 0; i < H; i++){
            row_used[i] = true;
            rowperm[H / 2] = i;
            if(rec(0)){
                return true;
            }
            row_used[i] = false;
        }
        return false;
    }
    else{
        return rec(0);
    }
}

int main(){
    cin >> H >> W;
    for(int i = 0; i < H; i++) cin >> S[i];
    if(solve()){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 384
N,M = map(int,input().split())
H = list(map(int,input().split()))

A = []
B = []

for i in range(M):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

x = 0
bad = []

while x < M:
    if H[A[x]-1] > H[B[x]-1]:
        bad.append(B[x])
    elif H[A[x]-1] < H[B[x]-1]:
        bad.append(A[x])
    else:
        bad.append(A[x])
        bad.append(B[x])

    x += 1


print(N-len(set(bad)))


Measured memory_bytes: 24880
import math
MAX=510000
fac=[0]*MAX
finv=[0]*MAX
inv=[0]*MAX
MOD=10**9+7
#テーブルを作る前処理
def COMinit():
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,MAX):
      fac[i] = fac[i-1] * i % MOD
      inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
      finv[i] = finv[i - 1] * inv[i] % MOD

#二項係数計算
def comb(n,k):
  if (n < k):
    return 0
  if (n < 0 or k < 0):
    return 0
  else:
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

COMinit()
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
#print(A)
sum=0
for i in range(N-K+1):
  sum+=(A[N-1-i]-A[i])*(comb(N-i-1,K-1))%(10**9+7)
print(sum%(10**9+7))

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

int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;
	int a[m]={},b,c,op[m]={};
	for (int i = 0; i < m; ++i)
	{
		cin>>a[i]>>b;
		for (int j = 0; j < b; ++j)
		{
			cin>>c;--c;
			op[i]+=(1<<c);
		}
	}
	int dp[m+5][(1<<n)+5]={};
	for (int i = 0; i <= m; ++i)
	{
		for (int j = 0; j < (1<<n)+5; ++j)
		{
			dp[i][j]=1000000000;
		}
	}
	dp[0][0]=0;
	for (int i = 0; i < m; ++i)
	{
		for (int j = 0; j < (1<<n); ++j)
		{
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
			dp[i+1][(j|op[i])]=min(dp[i+1][(j|op[i])],dp[i][j]+a[i]);
		}
	}
	if (dp[m][(1<<n)-1]==1000000000)
	{
		cout<<"-1\n";
	}
	else
	{
		cout<<dp[m][(1<<n)-1]<<endl;
	}
	return 0;
}


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

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		int k = Integer.parseInt(br.readLine());
		br.close();

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			int a = 26 - (c - 'a');
			if (a == 26) {
				sb.append('a');
			} else if (a <= k) {
				sb.append('a');
				k -= a;
			} else {
				sb.append(c);
			}
		}

		if (k > 0) {
			char c = sb.charAt(sb.length() - 1);
			int a = 26 - (c - 'a');
			k %= 26;
			if (k < a) {
				sb.setCharAt(sb.length() - 1, (char) (c + k));
			} else {
				sb.setCharAt(sb.length() - 1, (char) ('a' + (k - a)));
			}
		}
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 28628
use std::cmp::min;

fn main() {
    let vec = read_line();
    let n = vec[0];
    let m = vec[1];

    let vec = read_lines(m);
    let mut a = vec![];
    let mut b = vec![];
    let mut c = vec![];
    let mut dist = vec![vec![0; 100]; 100];    
    for v in vec {
        a.push(v[0] - 1);
        b.push(v[1] - 1);
        c.push(v[2]);
    }

    // すべての頂点について辞書をつくる
    for i in 0..n as usize {
        for j in 0..n as usize {
            if i == j {
                dist[i][j] = 0;
            } else {
                dist[i][j] = 100000000; // INF
            }
        }
    }

    // 辞書に移動距離を埋める
    for i in 0..m as usize {
        let idx_ai = a[i] as usize;
        let idx_bi = b[i] as usize;
        dist[idx_ai][idx_bi] = min(dist[idx_ai][idx_bi], c[i]);
        dist[idx_bi][idx_ai] = min(dist[idx_bi][idx_ai], c[i]);
    }

    for k in 0..n as usize {
        for i in 0..n as usize {
            for j in 0..n as usize {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    // let mut ans = m;
    // for i in 0..m as usize {
    //     let mut shortest = false;
    //     for j in 0..n as usize {
    //         if dist[j][a[i] as usize] + c[i] == dist[j][b[i] as usize] {
    //             shortest = true;
    //         }
    //     }
    //     if shortest {
    //         ans -= 1;
    //     }
    // }
    let mut ans = 0;
    for i in 0..m as usize {
        if dist[a[i] as usize][b[i] as usize] < c[i] {
            ans += 1;
        }
    }

    println!("{}", ans);
}

fn read_line() -> Vec<i32> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let v = s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect();
    return v
}

fn read_lines(n : i32) -> Vec<Vec<i32>> {
    let mut v2 = Vec::new();
    for _ in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let v = s.trim()
            .split_whitespace()
            .map(|e| e.parse().ok().unwrap())
            .collect();
        v2.push(v);
    }
    v2
}

Measured memory_bytes: 4352
n = int(input())
a = list(map(int,input().split()))
from collections import Counter
dp = [[0 for _ in range(n+1)] for _ in range(n)]
cnt = Counter()
dic= {}
for i in range(n):
    if dic.get(a[i]) is None:
        dic[a[i]] = [i]
    else:
        dic[a[i]] += [i]
    cnt[a[i]]+=1

def maximize(rang, pos):
    lb_rang = 0
    ub_rang = len(rang) - 1
    lb_pos = 0
    ub_pos = len(pos) - 1
    ret= 0 
    while lb_rang <= ub_rang:
        if abs(rang[lb_rang]-pos[ub_pos]) < abs(rang[ub_rang]-pos[lb_pos]):
            ret += abs(rang[ub_rang]-pos[lb_pos])
            ub_rang -= 1
            lb_pos += 1
        else:
            ret += abs(rang[lb_rang]-pos[ub_pos]) 
            lb_rang += 1
            ub_pos -= 1
    return ret

sorted_keys = sorted(cnt.keys())
acm=0
for x in sorted_keys:
    num = cnt[x]
    for i in range(n):
        if i + acm + num <= n:
            if acm == 0:
                dp[i][acm+num] = x*maximize(list(range(i,i+num)), dic[x])
            else:
                for j in range(i,i+num+1):
                    #print(f"dp[{i}][{acm}+{num}] = max(dp[{i}][{acm}+{num}],dp[{j}][{acm}] + {x}*maximize(list(range({i},{j}))+list(range({j}+{acm},{i}+{acm}+{num})), dic[{x}]))")
                    #print(j,acm,dp[j][acm])
                    dp[i][acm+num] = max(dp[i][acm+num],dp[j][acm] + x*maximize(list(range(i,j))+list(range(j+acm,i+acm+num)), dic[x]))
    acm += num

print(max(dp[0]))

Measured memory_bytes: 112520
//AUTHOR - NAVEEN KUMAR(@naveen19991124)
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#inlcude<boost/multiprecision/cpp_dec_float.hpp>
#define ll long long
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define v vector<ll>
#define mp make_pair
#define fir first
#define sec second
#define _fast_ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
//using boost :: multiprecision :: cpp_int;
//using boost :: multiprecision :: cpp_dec_float_50;
//using boost :: multiprecision :: cpp_dec_float_100;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}

ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1;
a *= a; a %= mod;} return p % mod;}
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)); }
int main()
{
	_fast_
	ll t = 1;
	//cin>>t;
	while(t--){
	ll n;
	cin>>n;
	ll val = log2(n);
	ll ans = pow(2,val+1)-1;
	cout<<ans<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1 << 21;
int main() {
	//int g, r;
	//cin >> r >> g;
	//cout << 2 * g - r << endl;
	int n, k;
	int ans = 1;
	cin >> n >> k;
	if (k > 0) {
		for (int i = 0; i < n; i++) {
			if (ans * 2 > ans + k) {
				ans = ans + k;
			}
			else {
				ans = ans * 2;
			}
		}
	}
	else {
		ans += k;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
local mab = math.abs
local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local b = {mab(a[1])}
for i = 2, n do
  b[i] = mab(a[i] - a[i - 1])
end
b[n + 1] = mab(a[n])
local left = {b[1]}
for i = 2, n + 1 do
  left[i] = left[i - 1] + b[i]
end
local right = {}
for i = 1, n + 1 do right[i] = 0 end
right[n + 1] = b[n + 1]
for i = n, 1, -1 do
  right[i] = right[i + 1] + b[i]
end

for i = 1, n do
  if i == 1 then
    print(mab(a[2]) + right[3])
  elseif i == n then
    print(left[n - 1] + mab(a[n - 1]))
  else
    print(left[i - 1] + right[i + 2] + mab(a[i + 1] - a[i - 1]))
  end
end


Measured memory_bytes: 11080
import math
N = int(input())
lim = N
half_lim = int(math.sqrt(N)//1)
lis = [1  for i in range(0,half_lim+1,)]

result = N
for i in range(2,len(lis)):
    if lis[i] == 1:
        if N % i ==0:
            tmp = i-1  + (N//i -1)
            if result > tmp:
                result = tmp
    else :
        continue

if result ==N:
    print(result-1)
else :
    print(result)


Measured memory_bytes: 11032
from collections import Counter
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))

d_c=Counter(d)
t_c=Counter(t)
for i in t_c.keys():
    if t_c[i]>d_c[i]:
        print('NO')
        exit()
print('YES')


Measured memory_bytes: 57048
#include <iostream>
#include <vector>

using namespace std;

const int MOD = 1000000007;

int main()
{
	//H+1cm,W本の線,到着はKに.
	int H, W, K;
	cin >> H >> W >> K;
	//dp[i][j]=縦棒を上からi刻み分についての入れ方のうち、
	//1からスタートしてjで終わるようなものの個数。
	vector<vector<int>> dp(H + 1, vector<int>(W, 0));
	dp[0][0] = 1;
	for (int i = 0;i < H;i++) {
		for (int j = 0;j < W;j++) {
			//bitは横棒の存在を表す.W本の縦線があるため、横線はW-1本であるのは当然である。
			for (int bit = 0;bit < (1 << (W - 1));bit++) {
				bool ok = true;
				for (int k = 0;k < W - 2;k++) {
					//横棒が被っている場合は抜ける。
					if ((bit & (1 << k)) && (bit & (1 << (k + 1)))) {
						ok = false;
					}
				}
				if (!ok) {
					continue;
				}
				//左からj本目を見ているとき、j本目からj+1本目へ横線が引かれていた時はdp[i+1][j+1]を変更し、
				//j-1本目からj本目へ横線が引かれていた時にはdp[i+1][j-1]を変更する。
				int nj = j;
				if (bit & (1 << j)) {
					nj = j + 1;
				}
				else if (j > 0 && (bit & (1 << (j - 1)))) {
					nj = j - 1;
				}
				//
				dp[i + 1][nj] = (dp[i + 1][nj] + dp[i][j]) % MOD;
			}
		}
	}

	//K-1は、入力は1始まりで数えているため。
	cout << dp[H][K-1] << endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n,m; cin >> n >> m;
	vector<pair<int,P>> a(m);
	rep(i,m){
		int p,y; cin >> p >> y;
		a[i].fi = y;
		a[i].se.fi = p;
		a[i].se.se = i;
	}
	SORT(a);
	vp num(m);
	vi b(n,0);
	rep(i,m){
		num[a[i].se.se].fi = a[i].se.fi; //県の番号
		num[a[i].se.se].se = ++b[a[i].se.fi];
	}
	rep(i,m) printf("%06d%06d\n",num[i].fi, num[i].se);
//	rep(i,m) cout << num[i].fi << " " << num[i].se << endl;
}


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

int main(){
	while(1){
		int n;
		string f[100];		
		int left=0, right=0; //両足とも床に有る
		int ans=0;
		
		scanf(" %d", &n);
		if(n==0) break;
		for(int i=0; i<n; ++i) cin >> f[i];
		
		int now=0;
		n-=n%2;
		while(now<n){
			if(left==0 && right==0){
				if( (f[now]=="lu" && f[now+1]=="ru") || (f[now+1]=="lu" && f[now]=="ru") ){ 
					left=1;
					right=1;
					ans++;
				}
			}
			else if(left==1 && right==1){
				if( (f[now]=="ld" && f[now+1]=="rd") || (f[now+1]=="ld" && f[now]=="rd") ){ 
					left=0;
					right=0;
					ans++;
				}
			}
			
			now+=2;
		}
		
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=(n); ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int n,k;cin>>n>>k;
    vint x(n);rep(i,n)cin>>x[i];
    int ans = 0;
    rep(i,n){
        ans += min(x[i], abs(x[i]-k))*2;
    }
    cout<<ans<<endl; return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(void){
    while(true){
        int h, w; scanf("%d%d", &h, &w);
        if(h == 0 and w == 0) break;
        for(int x = 0; x < h; x++){
            for(int y = 0; y < w; y++) putchar('#'); putchar('\n');
        } putchar('\n');
    }
    return 0;
}


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

int n,m;

vector<vector<int> > to;
vector<int> color;

bool can;

void dfs(int id, int c)
{
	color[id]=c;

	for(int i=0;i<to[id].size();i++)
	{
		int nxid=to[id][i];
		if(color[nxid]==-1)
			dfs(nxid,(c+1)%2);
		else
		{
			if(color[nxid]==c)
				can=false;
		}
	}


}

int main() {
	while(true)
	{
		cin >> n >> m;
		if(n==0)break;
		to=vector<vector<int> >(n);
		for(int i=0;i<m;i++)
		{
			int x,y;
			cin >> x >> y;
			x--;y--;
			to[x].push_back(y);
			to[y].push_back(x);
		}

		color=vector<int>(n,-1);
		can=true;
		dfs(0,0);

		if(can==false)
			cout << 0 << endl;
		else
		{
			int g1=0,g2=0;
			for(int i=0;i<n;i++)
			{
				if(color[i]==0)g1++;
				else g2++;
			}

			set<int> cnt;
			if(g1%2==0)cnt.insert(g1/2);
			if(g2%2==0)cnt.insert(g2/2);
			cout << cnt.size() << endl;
			for(auto itr=cnt.begin();itr != cnt.end();itr++)
				cout << *itr << endl;



		}

	}	

}


Measured memory_bytes: 3272
#include <bits/stdc++.h>
#define ll  long long int
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i :c)
#define pii pair< int,int >
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
const int MOD = 1000 * 1000 * 1000 + 7;
const int N = 1000000;
using namespace std;
clock_t time_p=clock();
void dem()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
ll fac[N] ;
ll mul ( ll a , ll b )
{
    return ((a % MOD )* (b % MOD )) % MOD ;

}
ll fastExp( ll base , ll pow )
{
    ll res = 1 ;
    while ( pow > 0 )
    {

        if ( pow & 1 ) res = mul ( res , base );
        base = mul ( base , base ) ;
        pow >>= 1 ;

    }
    return res ;
}
ll Inv ( ll base  )
{
    return fastExp( base , MOD - 2  );
}
void fact()
{
    fac[0] = 1 ;
    for ( int i = 1 ; i < N ; ++i )
        fac[i]= mul( fac[i-1] , i );

}
ll nCr ( ll n , ll r ){
ll C = fac[n];
if ( n < r   ||  n < 0 || r < 0 ) return 0 ;
C = mul(C , Inv(fac[r]));
C = mul (C , Inv ( fac[n - r] ));
return C ;


}
ll  solve(  ){
    fact();
    ll x , y ;
    cin >> x >> y ;
    if ((  x + y ) % 3 )  return 0 ; 
    else {
    ll n =  ( x + y ) / 3 ;
    x -= n , y-= n ;
    return nCr(  x + y  , x ) ;
    }
}

int main()
{
    fast_io();
    cout << solve () ;



    return 0 ;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vl;
 
const int N = 1e5 + 123;
const ll inf = 1e18;
ll n, a[N];
ll p[N];
 
int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++) {
		p[i] = p[i - 1] + a[i];
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ll have = a[i], cur = a[i];
		while (true) {
			int pos = upper_bound(a + 1, a + n + 1, 2 * cur) - a - 1;
			ll s = p[pos] - have;
			if (s == 0) {
				break;
			}
			cur += s;
			have = p[pos];
		}
		if (cur == p[n]) {
			ans++;
		}
	}
	cout << ans;
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <cmath>
#include <ctime>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#include <chrono>
#include <functional>
#include <random>
#include <numeric>
#include <tuple>
#include <bitset>
using namespace std;
#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef pair<int, int> ii;
template<class T> string toString(T x) { ostringstream ss; ss << x; return ss.str(); }
void solve();
int main() {
#ifdef LOCAL_COMP
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);
	solve();
#ifdef LOCAL_COMP
	cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve() {
	int n, h, w;
	while (cin >> n >> h >> w) {
		cout << (n - h + 1) * (n - w + 1) << endl;
	}
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d,x,y;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	x=a*b;
	y=c*d;
	if(x>y) {
		printf("%d\n",x);
	}
	else {
		printf("%d\n",y);
	}
	return 0;
}

Measured memory_bytes: 128
def solve() :
    n = int(input())
    s = []

    for _ in range(n) :
        s.append(input())

    print("AC x {}".format(s.count("AC")))
    print("WA x {}".format(s.count("WA")))
    print("TLE x {}".format(s.count("TLE")))
    print("RE x {}".format(s.count("RE")))

if __name__ == "__main__":
    solve()

Measured memory_bytes: 79280
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
struct block {
	int w, s, v;
};
bool operator<(const block &lhs, const block &rhs) {
	return lhs.w + lhs.s < rhs.w + rhs.s;
}
signed main() {
	cin >> N;
	vector< block > B(N);
	rep(i, N) cin >> B[i].w >> B[i].s >> B[i].v;
	sort(B.begin(), B.end());
	int W = 0;
	rep(i, N) W += B[i].w;
	vector< int > dp(W * 2 + 10, -1);
	dp[0] = 0;
	rep(i, N) for (int j = min(W, B[i].s); j >= 0; j--) {
		if (dp[j] >= 0)
			chmax(dp[j + B[i].w], dp[j] + B[i].v);
	}
	int ans = 0;
	rep(j, W + 1) chmax(ans, dp[j]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 156544
#include <iostream>                                  
#include <vector>                                    
#include <algorithm>                                 
using namespace std;                                 
                                                     
int main(void) {                                     
  int x;                                             
  vector<int> v;                                     
  for (int i=0; i<3; i++) {                          
    cin >> x;                                        
    v.push_back(x);                                  
  }                                                  
  sort(v.begin(),v.end());                           
  for (int i=0; i<3; i++) {                          
    cout << (i==0?"":" ") << v[i] << flush;          
  }                                                  
  cout << endl;                                      
  return 0;                                          
}                                   

Measured memory_bytes: 3156
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#define N 110000
using namespace std;
int n,a[N],ans;
int gcd(int a,int b)
{
	if(b==0) return a;
	return gcd(b,a%b);
}
int dfs()
{
	int t=0;
	for(int i=1;i<=n;i++) if(a[i]%2==0) t++;
	if(t%2) return 1;
	if(t!=n-1) return 0;
	int g=0;
	for(int i=1;i<=n;i++) 
	{
		if(a[i]%2) {if(a[i]==1) return 0;a[i]--;}
		g=gcd(g,a[i]);
	}
	for(int i=1;i<=n;i++) a[i]/=g;
	return dfs()^1;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	ans=dfs();
	if(ans==1) printf("First\n");
	else printf("Second\n");
	return 0;
}

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

using namespace std;

int main() {

    int v[3];
    
    for (int i = 0; i < 3; ++i)
        cin >> v[i];

    int k;
    cin >> k;

    int p = 1;
    while(k-- and p < 3) {
        if(v[p] <= v[p - 1]) v[p] *= 2;
        else p++, k++;
    }

    if(v[0] < v[1] and v[1] < v[2]) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3612
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    int mx = -123;

    int res = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (x >= mx) {
            ++res;
            mx = x;
        } 
    }
    cout << res << "\n";
    
    return 0;
}

Measured memory_bytes: 256
# AtCoder Beginner Contest 095
# C - Half and Half

A,B,C,X,Y=map(int,input().split())
if X>Y: 
    X,Y=Y,X
    A,B=B,A
                # ここまでで、X<=Yが保証された


nomal=X*A+Y*B
buyCuntilX=2*X*C+(Y-X)*B
allC=2*X*C+(Y-X)*2*C

print(min(nomal,buyCuntilX,allC))

Measured memory_bytes: 9068
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include<bits/stdc++.h>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>*/

#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define rep(a, b, c) for(int a = b; a <= c; ++a)
#define per(a, b, c) for(int a = b; a >= c; --a)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
//using namespace __gnu_pbds;

typedef unsigned long long ull;
typedef long long ll;
/*typedef tree<pair<int, int>, 
null_type, less<pair<int, int>>, 
rb_tree_tag, tree_order_statistics_node_update>
ordered_set;*/
//find_by_order() order_of_key()

const double eps = 1e-7;
const int mod = 1e9+7, MXN = 5e5+17;
const int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};

template<typename T>inline bool updmin(T &a, const T &b) {return a > b ? a = b,1 : 0;}
template<typename T>inline bool updmax(T &a, const T &b) {return a < b ? a = b,1 : 0;}

int32_t main() { _
#ifdef DanQQQQQ
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	int a, b, c; cin >> a >> b >> c;
	set<int>s; s.insert(a); s.insert(b); s.insert(c);
	cout << sz(s) << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())

A, B = mi()
S = input()
number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

if S[A] != '-':
    print('No')
    exit()

for i in range(A+B+1):
    if i != A and S[i] not in number:
        print('No')
        exit()

print('Yes')

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

const int MAXN = 505, MAXM = 1e5 + 10;

int n, m;
long long ans;
int a[MAXM], b[MAXM];
bool jh[MAXN][MAXN], p[MAXN];

int main() {
	cin >> n >> m;
	for(int i = 1; i <= m; i++)
		cin >> a[i] >> b[i];
	
  	for(int i = 1; i <= n; i++) {
		p[i] = 1;
		jh[i][i] = 1;
		for(int j = m; j >= 1; j--) {
			int x = a[j], y = b[j];
			if(!jh[i][x] && !jh[i][y])
				continue;
			if(jh[i][x] && jh[i][y]) {
				p[i]=0;
				break;
			}
			jh[i][x] = jh[i][y] = 1;
		}
	}
	for(int i = 1; i <= n - 1; i++)
		for(int j = i + 1; j <= n; j++) {
			if(p[i] && p[j]) {
				int key = 0;
				for(int k = 1; k <= n; k++)
					if(jh[i][k] && jh[j][k]) {
						key  =1;
						break;
					}
				if(!key)
					ans++;
			}
		}
	cout << ans << '\n';
  	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define f(i, k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define len(s) s.size()
#define all(v) v.begin(), v.end()
#define tr(it, v) for (auto &it : v)
#define bit(x) __builtin_popcount(x)
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
// =================
void impgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1e9;
const int N = 3e5 + 1;

vi g[N];
int a[N];

void solve()
{
    int n, m, ans = 0, k;
    cin >> n;
    vi dp(3);
    f(i, 0, n)
    {
        vi new_dp(3);
        vi a(3);
        tr(it,a) cin>>it;
        f(j,0,3) 
            f(k,0,3) 
                if(j!=k) 
                    new_dp[k]=max(new_dp[k],dp[j]+a[k]); 
        dp=new_dp;
    }
    cout<<max({dp[0],dp[1],dp[2]});
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

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

void impgraph(int n, int m)
{
    int i, u, v;
    while (m--)
    {
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
}

void dfs(int u, int par)
{
    for (int v : g[u])
    {
        if (a[v])
        {
        }
        dfs(v, 0);
    }
}

Measured memory_bytes: 10628