akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) { // nCr の計算
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

int main() {
	int a, b;
	cin >> a >> b;
	cout << (a * b) << endl;
	return 0;
}

Measured memory_bytes: 3616
import sys
import numpy as np
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
    h, w, m = MII()
    bombs = [MIIZ() for _ in range(m)]
    a = [0]*h
    b = [0]*w
    for y,x in bombs:
        a[y] += 1
        b[x] += 1
    maxa = max(a)
    maxb = max(b)
    sumv = maxa + maxb
    c = a.count(maxa)*b.count(maxb) - sum(a[y]+b[x] == sumv for y,x in bombs)
    print(sumv - (c<=0))

if __name__ == '__main__':
    main()

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

#define IOS ios::sync_with_stdio(0)
#define F first
#define S second
#define MP make_pair
#define PB emplace_back

using namespace std;

const int N = 1;

int main () {
    IOS;
    string s;
    cin >> s;
    if(s[2]==s[3]&&s[4]==s[5])cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=(1LL<<63) - 600;
const ll mod=1e9+7 ;


int main(){
  int N, M; cin >> N >> M;
  vector<pair<int, string>> P(M); vector<bool> check(N);
  rep(i, M){
    int a; string S; a--; cin >> a >> S; P[i].first=a; P[i].second=S;
    if(S=="AC") check[a] = true;
  }
  vector<int> q(N); int pena=0, ac=0;
  rep(i, M){
    if(P[i].second=="AC"){
      if(q[P[i].first]==0){ac++;}
      q[P[i].first] = 1;
    }
    if(P[i].second=="WA" && q[P[i].first]==0 && check[P[i].first]) pena++;
  }
  cout << ac << " " << pena << endl;
    
}

Measured memory_bytes: 8192
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n,k;
    cin>>n>>k;
    vector<int> a(n+1);
    REP(i,n) cin >> a[i+1];
    rep(i,n){
        a[i+1]+=a[i];
    }
    map<int,int> mp;
    for(int i=1;i<n+1;i++){
        for(int j=0;j<i;j++){
            mp[a[i]-a[j]]++;
        }
    }
    ll ans=0;
    for(int i=(1LL << 40);i>=1;i/=2){
        // cout<<i<<endl;
        map<int,int> nw;
        int cnt=0;
        for(auto x:mp){
            if(i&x.fs){
                nw[x.fs]=x.sc;
                cnt+=x.sc;
            }
        }
        if(cnt>=k){
            mp=nw;
            ans+=i;
        }
    }    
    cout<<ans<<endl;
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const ll LINF = 1e15;
const int MOD = 1e9 + 7;

int main(){
    int H, W;
    cin >> H >> W;

    if (H % 3 == 0 || W % 3 == 0) {
        puts("0");
        return 0;
    }

    ll ans = LINF;
    for (int i = 1; i <= H; ++i) {
        ll a = (ll)i * W;
        ll b = W / 2 * (ll)(H - i);
        ll c = (W + 1) / 2 * (ll)(H - i);

        ans = min(ans, max({a, b, c}) - min({a, b, c}));

        b = (H - i) / 2 * (ll)W;
        c = (H - i + 1) / 2 * (ll)W;

        ans = min(ans, max({a, b, c}) - min({a, b, c}));
    }

    for (int i = 1; i <= W; ++i) {
        ll a = (ll)i * H;
        ll b = H / 2 * (ll)(W - i);
        ll c = (H + 1) / 2 * (ll)(W - i);

        ans = min(ans, max({a, b, c}) - min({a, b, c}));

        b = (W - i) / 2 * (ll)H;
        c = (W - i + 1) / 2 * (ll)H;

        ans = min(ans, max({a, b, c}) - min({a, b, c}));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class DPredictionAndRestriction {
public:
    void solve(std::istream& in, std::ostream& out) {
        int N, K, R, S, P;
        in >> N >> K >> R >> S >> P;
        string T;
        in >> T;
        unordered_map<char, int> score = {
                {'r', P},
                {'s', R},
                {'p', S}
        };
        int answer = 0;
        REP(i,0,N) {
            if (i - K >= 0 && T[i] == T[i-K]) {
                T[i] = '#';
                continue;
            }
            answer += score[T[i]];
        }
        out << answer << "\n";
    }
};


int main() {
	DPredictionAndRestriction solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
char c[15][15];
int h,w;
vector<string>v;
vector<pair<int,bitset<10397> > >ava[13];
bitset<10397>dp[1<<12];
vector<vector<pair<int,int> > >way;
set<int>us;
vector<pair<int,int> >C;
void dfs(int cur,bool pass=false)
{
	if(cur==v[0].size())
	{
		way.push_back(C);
		return;
	}
	if(us.count(cur))
	{
		dfs(cur+1,pass);
		return;
	}
	else
	{
		if(pass==false)
		{
			dfs(cur+1,true);
		}
	}
	us.insert(cur);
	for(int i=cur+1;i<v[0].size();i++)
	{
		if(us.count(i))
		{
			continue;
		}
		C.push_back(make_pair(cur,i));
		us.insert(i);
		dfs(cur+1,pass);
		C.pop_back();
		us.erase(i);
	}
	us.erase(cur);
}
char tmp[15][15];
map<char,int>mp;
int main()
{
	cin>>h>>w;
	if(h==1 && w==1)
	{
		cout<<"YES"<<endl;
		return 0;
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin>>c[i][j];
		}
	}
	if(w==1)
	{
		for(int i=0;i<h;i++)
		{
			c[0][i]=c[i][0];
		}
		swap(h,w);
	}
	for(int i=0;i<h;i++)
	{
		string t="";
		v.push_back(t);
		for(int j=0;j<w;j++)
		{
			v.back().push_back(c[i][j]);
		}
	}
	dfs(0);
	if(h==1)
	{
		for(int i=0;i<w;i++)
		{
			mp[c[0][i]]++;
			mp[c[0][i]]%=2;
		}
		int cnt=0;
		for(map<char,int>::iterator it=mp.begin();it!=mp.end();it++)
		{
			if(it->second)
			{
				cnt++;
			}
		}
		if(cnt>1)
		{
			cout<<"NO"<<endl;
		}
		else
		{
			cout<<"YES"<<endl;
		}
		return 0;
	}
	for(int i=0;i<v.size();i++)
	{
		for(int j=i+1;j<v.size();j++)
		{
			bitset<10397>can;
			int len=v[i].size();
			for(int k=0;k<way.size();k++)
			{
				bool ok=false;
				for(int l=0;l<way[k].size();l++)
				{
					pair<int,int>it=way[k][l];
					int a=it.first,b=it.second;
					if(v[i][a]!=v[j][b] || v[i][b]!=v[j][a])
					{
						ok=true;
						break;
					}
				}
				if(ok)
				{
					continue;
				}
				can.set(k,true);
			}
			if(can.any())
			{
				ava[i].push_back(make_pair(j,can));
			}
		}
	}
	for(int i=0;i<way.size();i++)
	{
		dp[0].set(i,true);
	}
	for(int i=0;i<v.size();i++)
	{
		for(int j=(1<<12)-1;j>=0;j--)
		{
			if((j>>i)&1)
			{
				continue;
			}
			if(dp[j].any())
			{
				for(int k=0;k<ava[i].size();k++)
				{
					int go=ava[i][k].first;
					if((j>>go)&1)
					{
						continue;
					}
					dp[j|(1<<i)|(1<<go)]|=(dp[j]&ava[i][k].second);
				}
			}
		}
	}
	int need=v.size()/2;
	need*=2;
	for(int i=0;i<(1<<v.size());i++)
	{
		int z=0;
		for(int j=0;j<v.size();j++)
		{
			if((i>>j)&1)
			{
				z++;
			}
		}
		if(z==need)
		{
			if(dp[i].any())
			{
				cout<<"YES"<<endl;
				return 0;
			}
		}
	}
	cout<<"NO"<<endl;
	return 0;
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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 (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,m;
cin>>n;
map<int,int> d_dic;
rep(i,n){
    int d;
    cin>>d;
    d_dic[d]++;
}
cin>>m;
int ok=true;
int t;
rep(i,m){
    cin>>t;
    if(d_dic.count(t)&&d_dic[t]>0){
        d_dic[t]--;
    }
    else{
        ok=false;
        break;
    }
}
if(ok){
    cout<<"YES"<<endl;
}
else{
    cout<<"NO"<<endl;
}

return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
const int inf = 1<<30;
int c[10][1010];

int main() {
  int h, w, k; cin >> h >> w >> k;
  vector<string> s(h);
  for(int i = 0; i < h; i++) cin >> s[i];
  int ans = inf;
  rep(div, 1<<(h-1)) {
    int g = 0;
    vector<int> id(h);
    rep(i, h) {
      id[i] = g;
      if(div>>i&1) ++g;
    }
    ++g;

    rep(i,g)rep(j,w) c[i][j] = 0;
    rep(i,h)rep(j,w) c[id[i]][j] += (s[i][j] - '0');

    int num = g-1;
    vector<int> now(g);
    auto add = [&](int j) {
      rep(i,g) now[i] += c[i][j];
      rep(i,g) if(now[i] > k) return false;
      return true;
    };
    rep(j, w) {
      if(!add(j)) {
        num++;
        now = vector<int>(g);
        if(!add(j)) {
          num = inf;
          break;
        }
      }
    }
    ans = min(ans, num);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

//(int)'a'は97 (int)'A'は65
//おまじない



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

	cout << (a - 1)*(b - 1) << endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

bool sec_do(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) {
    return a.first < b.first;
  } else {
    return a.second > b.second;
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> A(M);
  int sheet[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  rep(i, M) {
    cin >> A[i].second;
    A[i].first = sheet[A[i].second];
  }
  sort(all(A), sec_do);

  vector<pair<int,int>> s;
  int prev_stick = 0;
  for (auto elem : A) {
    if (elem.first != prev_stick) {
      s.push_back(elem);
      prev_stick = elem.first;
    }
  }


  vector<vector<int>> dp(N+1, vector<int>(10, 0));

  for (int i = 1; i <= N; i++) {
    bool flag_zero = true;
    int max_dp = 0, max_i, max_s = 0;
    for (auto elem : s) {
      int prev_dp = dp[max(i-elem.first, 0)][0];
      if (prev_dp != 0) {
        flag_zero = false;
        if (prev_dp >= max_dp && elem.second > max_s) {
          max_dp = prev_dp;
          max_i = max(i-elem.first, 0);
          max_s = elem.second;
        }
      }
    }
    
    if (flag_zero) {
      dp[i][0] = 0;
    } else {
      rep(k, 10) dp[i][k] = dp[max_i][k];
      dp[i][0]++;
      dp[i][max_s]++;
    }

    for (auto elem : s) {
      if (dp[i][0] == 0 && i == elem.first) {
        dp[i][0] = 1;
        dp[i][elem.second] = 1;
      }
    }

  }

  for (int i = 9; i > 0; i--) {
    rep(j, dp[N][i]) cout << i;
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 896
n = int(input())
d = list(map(int, input().split()))
if d[0]!=0:
    print(0)
    exit()
node = [0]*(max(d)+1)
for i in d:
    node[i] += 1
if node[0]>1:
    print(0)
    exit()
ans = 1
for i in range(len(node)-1):
    ans *= node[i]**node[i+1]
    ans %= 998244353
print(ans)

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

int main() {
  int N,K;
  cin >> N>>K;
  vector<int> x(N);
  for (int i = 0; i < N; i++) {
    cin>>x.at(i);
  }
  int ans=2000000000;
  if(x.at(0)>=0){
    
      ans=x.at(K-1);
    
   cout<<ans<<endl;
  }
  else if(x.at(N-1)<=0){
    
      ans=-x.at(N-K);
    
    cout<<ans<<endl;
  }
  else{
    int b=0;
    for (int i = 0; i < N-K+1; i++) {
      if(x.at(K-1+i)<=0){
        b=abs(x.at(0));
        ans=min(ans,b);
      }
      else if(x.at(i)>=0){
        b=x.at(K+i-1);
        ans=min(ans,b);
      }
      else{
        b=min(2*x.at(K+i-1)-x.at(i),x.at(K+i-1)-2*x.at(i));
        ans=min(ans,b);
      }
    }
    cout<<ans<<endl;
  }
}





Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

const int MAX = 510000;

ll dp[100010][4];

ll pow_mod(ll n, ll x)
{
    ll res = 1;
    while (n > 0)
    {
        if ((n & 1) == 1)
        {
            res *= x;
            res %= MOD;
        }
        x = x * x;
        x %= MOD;
        n >>= 1;
    }
    return res;
}

ll a[100010], c[100010], q[100010];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(5);

    int N;
    cin >> N;
    int sum = 0;
    int t = N;
    while (t)
    {
        sum += t % 10;
        t /= 10;
    }

    if (N % sum == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
//const long long INF = 10000000000;

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

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

    long long sums = 0;
    map<long long, long long> nums;
    nums[sums]++;

    for (int i = 0; i < N; i++){
        sums += A[i];
        nums[sums % M]++;
    }
    
    long long res = 0;
    for (map<long long, long long>::iterator it = nums.begin(); it != nums.end(); ++it){
        res += it->second * (it->second-1) / 2;
    }
    
    cout << res << endl;   
}

Measured memory_bytes: 4992
n = int(input())
A = list(map(int, input().split()))

ans = 10**18
Rui = []
r = 0
for i in range(n):
    r += A[i]
    Rui.append(r)

for i in range(0,n-1):
    can = abs(2 * Rui[i] - Rui[-1])
    if can <= ans:
        ans = can
print(ans) 


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

int main() {
  string s, ans;
  vector<string> vo ={"a","i","u","e","o"};

  ans = "consonant";
  cin >> s;
  for (int i=0;i<5;i++){
	if (vo.at(i) == s){
	  ans = "vowel";
    }
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b;
  vector<int> p;
  cin >> n >> a >> b;
  p.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  int i = 0;
  int num[3];
  for (; i < n and p[i] <= a; ++i) ;
  num[0] = i;
  int oi = i;
  for (; i < n and p[i] <= b; ++i);
  num[1] = i - oi;
  num[2] = n - i;
  cout << min({num[0], num[1], num[2]});
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long mod = 1000000007l;
long modpow(long x, long y, long m){
	long res = 1, tmp = x;
	while(y){
		if(y&1)res = res * tmp % m;
		tmp = tmp * tmp % m;
		y >>= 1;
	}
	return res;
}
int main(){
	int N, sz = 0, cnt_zero = mod - 1;
	long ans = 1;
	map<pair<long, long>, int> M;
	cin >> N;
	for(int i=0; i<N; i++){
		long A, B;
		cin >> A >> B;
		if(A == 0){
			if(B == 0){
				cnt_zero++;
				continue;
			}else {
				B = 1;
			}
		}else if(B == 0){
			A = 1;
		}else {
			long t = gcd(labs(A), labs(B));
			A /= t;
			B /= t;
			if(B < 0){
				A *= -1;
				B *= -1;
			}
		}
		M[pair<long, long>(A, B)]++;
	}
	for(const auto& [key, val] : M){
		pair<long, long> X = pair<long, long>(key.second,-key.first);
		if(X.second < 0){
			X.first *= -1;
			X.second *= -1;
		}
		auto tmp = M.find(X);
		if(tmp == M.end()){
			ans *= modpow(2, val, mod);
			ans %= mod;
		}else {
			if(key < X){
				ans *= (modpow(2, val, mod) + modpow(2, (*tmp).second, mod) - 1);
				ans %= mod;
			}
		}
	}
	cout << (ans + cnt_zero) % mod << endl;
	pair<int, int>a=pair<int,int>(0,1), b=pair<int,int>(0,0);
	if(a<b)cout << "Yay!" << endl;
	return 0;
}

Measured memory_bytes: 16088
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <numeric>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define itr(i, x) for(auto i = (x).begin(); i != (x).end(); i++)
#define ritr(i, x) for(auto i = (x).rbegin(); i != (x).rend(); i++)
#define INF 1010101010
#define MOD 1000000007
#define LL long long
using Coord = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<int> an(n);
    for (auto& e: an) cin >> e;

    double sum = (double)accumulate(all(an), 0);
    int ave = (int)round(sum / n);

    int ans = 0;
    for (const auto e: an) {
        int diff = e - ave;
        ans += diff * diff;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,m;
    cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2;
}

Measured memory_bytes: 3588
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    ll s;
    cin >> s;
    ll d = sqrt(s);
    if (d > 0) d--;
    while (d * d < s) d++;
    ll r = d * d - s;
    ll x = 0, y = 0;
    if (r > 0){
        for (x = 1; ; x++){
            if (r % x == 0 && r / x <= d){
                y = r / x;
                break;
            }
        }
    }
    printf("0 0 %lld %lld %lld %lld\n", d, y, x, d);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <sstream>
#include <cctype>
using namespace std;

void print(string &str){
	int a, b;
	cin >> a >> b;
	cout << str.substr(a, b - a + 1) << endl;
}

void reverse(string &str){
	int a, b;
	cin >> a >> b;
	string strR = str.substr(a, b - a + 1);
	for (int i = 0; i < strR.size()/2; i++){
		char a = strR[i];
		strR[i] = strR[strR.size() - i - 1];
		strR[strR.size() - i - 1] = a;
	}
	str.replace(a, b - a + 1, strR);
}

void replace(string &str){
	int a, b;
	string p;
	cin >> a >> b >> p;
	str.replace(a, b - a + 1, p);
}

int main(){

	string str;
	int q = 0;
	cin >> str;
	cin >> q;
	for (int i = 0; i < q;i++){
		string c;
		cin >> c;
		if (c == "replace")replace(str);
		else if (c == "reverse")reverse(str);
		else if (c == "print")print(str);
	}
	return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

int search(int x,int temp,int ans) {
	if (temp > x) return ans;
	if (x%temp == 0) {
		ans += 1;
		temp += 1;
		return search(x, temp, ans);
	}
	else {
		temp += 1;
		return search(x, temp, ans);
	}
}

int main() {
	int n;
	int a = 0;
	std::cin >> n;

	for (int i = 1; i <= n; ++i) {
		if (search(i, 1, 0) == 8) {
			if (i % 2 != 0) {
				a += 1;
			}
		}
	}

	std::cout << a << std::endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb insert
typedef long long ll;
using namespace std;
int main() {
	int h, w, m;
	cin >> h >> w >> m;
	int row[h + 1] = {};
	int col[w + 1] = {};
	map <pair<int, int>, bool> mp;
	while (m--) {
		int r, c;
		scanf("%d %d", &r, &c);
		++row[r];
		++col[c];
		mp[{r, c}] = true;
	}

	set <int> roww, coll;
	int mx = 0;
	for (int i = 1; i <= h; ++i)
		mx = max(mx, row[i]);
	for (int i = 1; i <= h; ++i)
		if (row[i] == mx)
			roww.pb(i);
	int ans = mx;

	mx = 0;
	for (int i = 1; i <= w; ++i)
		mx = max(mx, col[i]);
	for (int i = 1; i <= w; ++i)
		if (col[i] == mx)
			coll.pb(i);
	ans += mx;

	int temp = 1;

	for (int a : roww)
		for (int b : coll)
			if (!mp.count({a, b})){
				temp = 0;
				break;
			}
	cout << ans - temp << endl;

}

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

int main()
{
	int n,F[45];
	F[0] = 1;
	F[1] = 1;
	cin >> n;
	for (int i = 2; i <= n; i++) {
		F[i] = F[i - 2] + F[i - 1];
	}
	cout << F[n] << endl;
    return 0;
}

Measured memory_bytes: 3004
s = str(input())

for l in range(2 ** (len(s)-1)):
    s3 = list(s)
    h = 0
    for i in range(len(s)-1):
        if (l >> i) & 1:
            s3.insert(i+h+1,'+')
            h += 1
        else:
            s3.insert(i+h+1,'-')
            h += 1
    e = ''.join(s3)
    if eval(e) == 7:
        print(str(e)+'=7')
        break

Measured memory_bytes: 3064
#include <stdio.h>

int main(int argc, const char * argv[])
{

    int a, b;
    int di;
    int counter = 0;
    int i;
    while (scanf("%d %d",&a ,&b) != EOF) {
    
        
        di = a + b;
        for (i = 0; i < 8; i++) {
            di /= 10;
            if (di == 0 && counter == 0) {
                printf("%d\n",i + 1);
                counter++;
            }
        }
        counter = 0;
    }
    
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > piii;
#define pb push_back
#define debug(x) cout << x << endl
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
#define PI acos(-1)
#define all(c) c.begin(), c.end()
#define SET(x, y) memset((x), y, sizeof(x))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const LL INF64 = 1e18;

const int N = 1e5 + 5;

vector<int> adjList[N];
int dist[N];

int dfs(int now) {
	if (dist[now] != -1)
		return dist[now];
	int tmp = 0;
	for (auto it : adjList[now]) {
		tmp = max(tmp, dfs(it) + 1);
	}
	return dist[now] = max(tmp, dist[now]);
}

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		adjList[a].pb(b);
	}
	SET(dist, -1);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (dist[i] == -1) {
			dist[i] = dfs(i);
			ans = max(ans, dist[i]);
		}
	}
	printf("%d\n", ans);
	return 0;
}
		

Measured memory_bytes: 8192
#include <stdio.h>
int main(void){
    
   int x,i;
   
   i=0;
   
   while(1){
       scanf("%d",&x);
       if(x==0) break;
       else{
           i++;
           printf("Case %d: %d\n",i,x);
       }
   }
 
    return 0;
    
}


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

using namespace std;

using int64 = long long;

// たぷ

int main() {
  int N, X;
  cin >> N >> X;
  vector< int > V(N);
  for(int i = 0; i < N; i++) cin >> V[i];
  sort(begin(V), end(V));
  int ret = 0;
  for(int i = 0; i < N; i++) {
    if(V[i] <= X) {
      X -= V[i];
      ++ret;
    }
  }
  if(ret == N && X > 0) --ret;
  cout << ret << endl;
}


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

#define ll long long int
#define maximum 0x7f

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

double dp[301][301][301];

double call(int a,int b,int c)
{
    if(dp[a][b][c]!=-1)
        return dp[a][b][c];
    double ret=0.0;
    if(a)
        ret+=call(a-1,b,c)*a;
    if(b)
        ret+=call(a+1,b-1,c)*b;
    if(c)
        ret+=call(a,b+1,c-1)*c;
    ret+=n;
    ret/=(a+b+c);
    return dp[a][b][c]=ret;
}

int main()
{
    double a=0,b=0,c=0;
    cin>>n;
    int p[n+1];
    for(int i=1; i<=n; i++)
    {
        cin>>p[i];
        if(p[i]==1)
            a++;
        else if(p[i]==2)
            b++;
        else
            c++;
    }
    for(int i=0; i<=300; i++)
        for(int j=0; j<=300; j++)
            for(int k=0; k<=300; k++)
                dp[i][j][k]=-1.0;
    dp[0][0][0]=0;
    cout<<fixed<<setprecision(10)<<call(a,b,c)<<endl;
    return 0;
}


Measured memory_bytes: 213376
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
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 Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int h[100000];

int main() {
  int n;
  while(cin>>n) {
    inputs(h,n);
    int t = 0;
    int ans = 0;
    for (int i=1; i<n; i++) {
      if (h[i] > h[i-1]) {
        chmax(ans,t);
        t = 0;
      } else t++;
    }
    chmax(ans,t);
    cout << ans << endl;
  }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n,m,ans,x,y,vis[maxn],num[maxn];
int main()
{
	scanf("%d%d",&n,&m);
	vis[1]=1;
	for(int i=1;i<=n;i++) num[i]=1;
	for(int i=0;i<m;i++){
		scanf("%d%d",&x,&y);
		if(vis[x]) vis[y]=1;
		num[x]--;
		num[y]++;
		if(num[x]==0) vis[x]=0;
	}
	for(int i=1;i<=n;i++){
		if(vis[i]) ans++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 1024
#include <stdio.h>

#define N 25
#define NILL -1

struct Tree{int parent,right,left;};

struct Tree T[N];
int D[N];
int H[N];
int n;
int root;

void setdepth(int u,int p){
	D[u] = p;
	if(T[u].left != NILL) setdepth(T[u].left,p+1);
	if(T[u].right != NILL) setdepth(T[u].right,p+1);
}

int  Height(int u){
	int h1,h2;
	h1 = h2 = 0;
	if(T[u].right != NILL) h1 = Height(T[u].right) + 1;
	if(T[u].left != NILL) h2 = Height(T[u].left) + 1;
	if(h1 > h2) H[u] = h1;
	else H[u] = h2;
	return H[u];
}

void tree(){
	setdepth(root,0);
	Height(root);
	int i,j;
	int sib,deg;
	for(i=0;i<n;i++){
		printf("node %d: parent = %d, ",i,T[i].parent);
		sib = -1;
		deg =0;
		for(j=0; j<n; j++){
			if(i != j && D[i] == D[j] && T[i].parent == T[j].parent) {
				sib = j;
				break;
			}
		}
		if(T[i].right!=NILL) deg++;
		if(T[i].left!= NILL) deg++;
		printf("sibling = %d, ",sib);
		printf("degree = %d, ",deg);
		printf("depth = %d, height = %d, ",D[i],H[i]);
		if(T[i].parent== NILL) printf("root\n");
		else if(T[i].left!= NILL || T[i].right!= NILL) printf("internal node\n");
		else printf("leaf\n");
	}
}
int main(){
	scanf("%d",&n);
	int i;
	int id,l,r;
	for(i=0;i<n;i++) T[i].parent = NILL;
	for(i=0;i<n;i++){
		scanf("%d",&id);
		scanf("%d%d",&l,&r);
		T[id].left = l;
		T[id].right = r;
		if(l != NILL) T[l].parent = id;
		if(r != NILL) T[r].parent = id;
	}
	for(i=0;i<n;i++)if(T[i].parent == NILL) root = i;
	tree();
}

Measured memory_bytes: 2732
import java.util.Scanner;

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

		// 入力値の取得
		int H = sc.nextInt();
		int W = sc.nextInt();
		int K = sc.nextInt();
		
		char[][] table = new char[H][W];
		for (int i = 0; i < H; i++) {
			table[i] = sc.next().toCharArray();
		}
		
		int count = 0;
		for (int i = 0; i < (1 << H); i++) {
			for (int j = 0; j < (1 << W); j++) {
				int black = 0;
				for (int k = 0; k < H; k++) {
					for (int l = 0; l < W; l++) {
						if (table[k][l] == '#' && (i >> k & 1) == 0 && (j >> l & 1) == 0) {
							black++;
						}
					}
				}
				if (black == K) {
					count++;
				}
			}
		}
		// 結果の出力
		System.out.println(count);
		
		sc.close();
	}
}


Measured memory_bytes: 27256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int H[] = new int[N];
		int max = 0;
		int a = 0;

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

		for (int i = 1; i < N; i++) {
			if (H[i - 1] >= H[i]) {
				a++;
				if (a > max) {
					max = a;
				}
			} else {
				a = 0;
			}
		}
		sc.close();
		System.out.println(max);
	}
}


Measured memory_bytes: 52128
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> numList = new ArrayList<Integer>();
        while(sc.hasNext()){
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(a == 0 && b == 0){
                break;
            }
            numList.add(a);
            numList.add(b);
        }
        for(int i = 0; i < numList.size() / 2; i++){
            for(int j = 0; j < numList.get(i * 2); j++){
                for(int k = 0; k < numList.get(i * 2 + 1); k++){
                    if(j == 0 || j == numList.get(i * 2) - 1
                            || k == 0 || k == numList.get(i * 2 + 1) - 1){
                        System.out.print("#");
                    }else{
                        System.out.print(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 37740
#include<stdio.h>
int main(void)
{
	int i,j,n,a[1000],b[1000],c[1000],C,A,B;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
	}
	for(i=0;i<n;i++){
	A=a[i]*a[i];
	B=b[i]*b[i];
	C=c[i]*c[i];
		if(C==A+B || A==B+C || B==A+C){
			printf("YES\n");
		}

		else{
			printf("NO\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2040
import sys
N,M=map(int,input().split())
come=[0]*N
for i in range(M):
  ab=list(map(int,input().split()))
  if ab[0]==1:
    if come[ab[1]]:
      print("POSSIBLE")
      sys.exit()
    come[ab[1]]=1
  if ab[1]==N:
    if come[ab[0]]:
      print("POSSIBLE")
      sys.exit()
    come[ab[0]]=1
 
print("IMPOSSIBLE")

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

int main(){
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin >> a[i];
    sort(a.begin(), a.end());

    int ans = 0;
    int nCand = 0;
    int n = 0;
    while(nCand < x && n < N){
        nCand += a[n];
        if(nCand <= x) ans++;
        if(n==N-1 && nCand<x) ans--;
        if(nCand >= x) break;
        n++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


N = int(input())

primes = prime_factorize(N)

num = 0
hist = [1]
c = 1

tmp = 1
for p in primes:
    # 前回と異なる場合
    if tmp != p:
        c = 1
    tmp = p
    c *= p
    if c not in hist:
        hist.append(c)
        num += 1
        c = 1
print(num)


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

using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define lson root<<1,l,(l+r)/2
#define rson root<<1|1,(l+r)/2+1,r
const int N = 1e5+5;
const ll INF = 1e18;
const ll p = 1e9+7;
int ans=0,a[20]={0};
ll n;
void dfs(int sum,int id,int flag)
{
	if(id<0){ans=max(ans,sum);return;}
	if(flag){
		if(sum+(id+1)*9>ans){
			dfs(sum+a[id],id-1,flag);
			for(int i=a[id]-1;i>=0;i--)dfs(sum+i,id-1,0);
		}
	}else{
		if(sum+(id+1)*9>ans){
			for(int i=9;i>=0;i--)dfs(sum+i,id-1,0);
		}
	}
}
int main()
{
	scanf("%lld",&n);
	ll tmp=n;int tot=0;
	while(tmp){a[tot++]=tmp%10;tmp/=10;}
	dfs(a[tot-1],tot-2,1);
	for(int i=a[tot-1]-1;i>=0;i--)dfs(i,tot-2,0);
	printf("%d\n",ans);
	return 0;
}


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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  while(A>0 && C>0){
    C-=B;
    A-=D;
  }
  if(C<=0){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
typedef long long ll;

int main(){
    int n,ans = 0;
    scanf("%d",&n);
    int p[n];
    for(int i=0;i<n;i++) scanf("%d",&p[i]);
    for(int i=1;i<n-1;i++){
        if((p[i-1] > p[i] && p[i] > p[i+1]) || (p[i-1] < p[i] && p[i] < p[i+1])) ans++;
    }
    printf("%d",ans);
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n;
 cin>>n;
 int a[n];
 int b[n];
 int c[n];
 int i;
 for(i=0;i<n;i++)
 cin>>a[i]>>b[i]>>c[i];
 int dp[n][3];
 dp[0][0]=a[0];
 dp[0][1]=b[0];
 dp[0][2]=c[0];
 for(i=1;i<n;i++)
 {
 	dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=c[i]+max(dp[i-1][1],dp[i-1][0]); 
 }
 cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;
ll sum[1000000];

int main() {
	cin >> n;
	ll MAX = 0;
	rep(i, n) {
		cin >> sum[i];
		MAX += sum[i];
		if (i >= 1)sum[i] += sum[i - 1];
	}
	ll ans = INF;
	rep(i, n - 1) {
		//cout << abs(MAX - sum[i] - sum[i]) << endl;
		ans = min(ans, abs(MAX - sum[i] - sum[i]));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>

 

using namespace std;

 

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


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
int s[400][30];
signed main(){
    int d;cin >> d;
    int c[26];
    rep(i,26)cin >> c[i];
    rep(i,d)rep(j,26)cin >> s[i][j];
    vector<P> res;
    rep(i,26){
        res.emplace_back(c[i],i);
    }
    sort(res.rbegin(),res.rend());
    
    rep(i,d){
        cout << res[0].second +1 << endl;

    }
    
    return 0;
}

Measured memory_bytes: 3728
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<P> x(n);
	vector<P> y(m);
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		x[i] = make_pair(a, b);
	}
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		y[i] = make_pair(a, b);
	}
	REP(i, n) {
		int num = 0;
		int leng = abs(x[i].first - y[0].first) + abs(x[i].second - y[0].second);
		FOR(j, 1, m) {
			int tmp = abs(x[i].first - y[j].first) + abs(x[i].second - y[j].second);
			if (tmp < leng) {
				leng = tmp;
				num = j;
			}
		}
		cout << num  + 1 << endl;
	}
}



Measured memory_bytes: 256
use std::io::{Read, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    let mut iter = input.split_whitespace();

    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();
    let mut a = [[0i32; 100]; 100];
    let mut b = [0i32; 100];

    for i in 0..n {
        for j in 0..m {
            a[i][j] = iter.next().unwrap().parse().unwrap();
        }
    }
    for i in 0..m {
        b[i] = iter.next().unwrap().parse().unwrap();
    }
    for i in 0..n {
        let mut s=0;
        for j in 0..m {
            s += a[i][j]*b[j];
        }
        out.write_fmt(format_args!("{}\n", s)).unwrap();
    }
}



Measured memory_bytes: 5076
#include <iostream>
#include <string>

using namespace std;

int main () {
    string s;
    cin >> s;

    bool flag = false;
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < s.size(); j++) {
            if (i != j && s[i] == s[j]) {
                flag = true;
            }
        }
    }

    if (flag == true) cout << "no" << endl;
    else cout << "yes" << endl;
}

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

int main(){
	int n,m,k;
	cin >> n >> m >> k;
	int ok = 0;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= m; j++){
			if(i * (m - j) + j *(n - i) == k)ok = 1;
			if(ok)break;
		}
		if(ok)break;
	}
	if(ok)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    from itertools import groupby
    r = p = 0
    for k,g in groupby(input()):
        l = sum([1 for _ in g])
        r += l*(l+1)//2
        if k == ">":
            r -= min(l,p)
        p = l
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 67528
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 1e9 + 7;

int main() {
    int n; cin >> n;
    vector<int> as(n), bs(n), cs(n);
    rep(i, n) cin >> as[i];
    rep(i, n) cin >> bs[i];
    rep(i, n) cin >> cs[i];
    sort(all(as)); sort(all(bs)); sort(all(cs));
    vector<ll> cs1(n), cs2(n);
    rep(i, n) {
        cs1[i] = bs.end() - upper_bound(all(bs), as[i]);
        cs2[i] = cs.end() - upper_bound(all(cs), bs[i]);
    }
    gnr(i, 1, n) cs2[i-1] += cs2[i];
    ll cnt = 0; 
    rep(i, n) {
        if (cs1[i] > 0) cnt += cs2[n-cs1[i]];
    }
    cout << cnt << endl; 
    return 0;
}

Measured memory_bytes: 2944
n = int(input())
l = []
for i in range(n):
    a, b = map(int, input().split())
    l.append([a,b])

cnt = 0
for e in l:
    if e[0] == e[1]:
        cnt += 1

    if cnt == 3:
        print("Yes")
        exit()

    if e[0] != e[1]:
        cnt = 0

print("No")

Measured memory_bytes: 9184
n = int(input())
s = input()
total = 1
for c in 'RGB':
  total *= s.count(c)
for i in range(1, n - 1):
  for j in range(1, min(i + 1, n - i)):
    if s[i] != s[i - j] and s[i - j] != s[i + j] and s[i] != s[i + j]:
      total -= 1
print(total)

Measured memory_bytes: 9164
a = int(raw_input())
b = raw_input().split(" ")

s = 1000000000
c = 1
for i in range(len(b)-1):
  cur = int(b[i])
  nex = int(b[i+1])
  if cur < s:
      s = cur

  if s < nex:
    continue



  c += 1
print(c)

Measured memory_bytes: 19964