akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

int digits(int num);

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

    int a, b;
    while (std::cin >> a >> b)
        std::cout << digits(a + b) << std::endl;
}

int digits(int num)
{
    int cnt = 0;
    do {
        num /= 10;
        ++cnt;
    } while(num != 0);

    return cnt;
}




Measured memory_bytes: 3020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007

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

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) {
	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;
}

int main() {
	string s;
	cin >> s;
	vector<string> ans = split(s);

	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << " ";
	}

	return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(false);
	int N, ans=0;
	int D[200];

	cin >> N;
	rep(i,N) cin >> D[i];
	D[N] = 0;
	N++;
	sort(D, D+N);

	rep(i,N) if(i%2) D[i] *= -1;
	sort(D, D+N);
	rep(i,N) D[i+N] = D[i] + 24;

	ans = INF;
	rep(i,N*2-1) chmin(ans, D[i+1]-D[i]);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
#define CEIL_DIV(a, b) (a % b ? a / b + 1 : a / b)
#define FLOOR_DIV(a, b) (a / b)

using namespace std;

#define MAX_OF_SUM (2000 * 2000 + 100)
bitset<MAX_OF_SUM> set;

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

    set[0] = true;

    long long sum = 0;

    REP(i, N) {
        int a;
        cin >> a;
        // (これまでに到達できたもの << a) : aを足した場合に到達できるもの
        // これと，これまでに到達できるもののORを取れば，両方の組み合わせを列挙できたことになる
        set |= set << a;
        sum += a;
    }

    // 組み合わせの全列挙のうち，中央値とは，sum/2以降に最初に現れるもの
    // 理由:
    // ある部分数列には，対応する部分数列が存在する(2進表現でNOTしたもの)
    // 大きい方をP, 小さい方をSとすると，P+S = sumになる．
    // ここで，S<=Pより，S <= sum/2 <= P が全ての組み合わせについて成立
    // よってソートすると，S_s(1), S_s(2), ..., sum/2, P_p(1), P_p(2) ... sum が成立．
    // n=2だと，01 (sum/2) 10 11 なので，中央値は10，一般に中央値はP_p(1)．
    // より，sum/2以降で最初に現れる和が求める答えである．
    //
    // 2 1を考えると，sum = 3, sum/2 = 1，和は 1 (sum/2) (2) 3
    // 1 1を考えると，sum = 2, sum/2 = 1, 和は 1 (sum/2) (2) 2
    // より，sum/2はCEIL_DIVする必要がある．

    for (long long i = CEIL_DIV(sum, 2); i < MAX_OF_SUM; i++) {
        if (set[i]) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


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

using namespace std;

string calc(string a, string b){
  string tmp;
  int n3=0;
  int size1, size2;
  size1=a.size();
  size2=b.size();

  if(a.size()>b.size()){
    for(int i=0;i<size1;i++){
      int n1, n2;
      if(i>=size2){
	n2=0;
      }else{
	n2=b[size2-1-i]-'0';
      }
      n1=a[size1-1-i]-'0';
      int t=n1+n2+n3;
      n3=t/10;
      t-=n3*10;
      tmp+=t+'0';
    }
  }else if(a.size()<b.size()){
    for(int i=0;i<size2;i++){
      int n1, n2;
      if(i>=size1){
	n1=0;
      }else{
	n1=a[size1-1-i]-'0';
      }
      n2=b[size2-1-i]-'0';
      int t=n1+n2+n3;
      n3=t/10;
      t-=n3*10;
      tmp+=t+'0';
    }
  }else{
    for(int i=0;i<size1;i++){
      int n1, n2;
      n1=a[size1-1-i]-'0';
      n2=b[size1-1-i]-'0';
      int t=n1+n2+n3;
      n3=t/10;
      t-=n3*10;
      tmp+=t+'0';
    }
  }
  if(n3!=0){
    tmp+=n3+'0';
  }
  string ans="";
  for(int i=0;i<tmp.size();i++){
    ans+=tmp[tmp.size()-1-i];
  }
  return ans;
}

main(){
  string in;
  while(cin >> in){
    string a, b, c;
    int size=in.size();
    int i;
    bool f=false;
    for(int num=0;num<10;num++){
      a=b=c="";
      for(i=0;i<size;i++){
	if(in[i]=='+'){
	  i++;
	  break;
	}
	if(in[i]=='X'){
	  a+=(char)num+'0';
	}else{
	  a+=in[i];
	}
      }
      for(;i<size;i++){
	if(in[i]=='='){
	  i++;
	  break;
	}
	if(in[i]=='X'){
	  b+=(char)num+'0';
	}else{
	  b+=in[i];
	}
      }
      for(;i<size;i++){
	if(in[i]=='X'){
	  c+=(char)num+'0';
	}else{
	  c+=in[i];
	}
      }
      if(a[0]=='0' && a.size()>1) continue;
      if(b[0]=='0' && b.size()>1) continue;
      if(c[0]=='0' && c.size()>1) continue;
      string ans1=calc(a, b);
      string ans2=c;
      /*string tmp1="", tmp2="";
      bool first=true;
      for(int i=0;i<a.size();i++){
	if(a[i]=='0' && first) continue;
	if(a[i]!='0') first=false;
	tmp1+=a[i];
      }
      if(first) tmp1+='0';
      first=true;
      for(int i=0;i<b.size();i++){
	if(b[i]=='0' && first) continue;
	if(b[i]!='0') first=false;
	tmp2+=b[i];
      }
      if(first) tmp2+='0';
      string left=clac(tmp1, tmp2);
      string ans1="", ans2="";
      first=true;
      for(int i=0;i<left.size();i++){
	if(left[i]=='0' && first) continue;
	if(left[i]!='0') first=false;
	ans1+=left[i];
      }
      if(first) ans1+='0';
      first=true;
      for(int i=0;i<c.size();i++){
	if(c[i]=='0' && first) continue;
	if(c[i]!='0') first=false;
	ans2+=c[i];
      }
      if(first) ans2+='0';*/
      //cout << ans1 << '=' << ans2 << endl;
      if(ans1==ans2){
	cout << num << endl;
	f=true;
	break;
      }
    }
    if(!f) cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	cin >> n;
	int sum = 0;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	if (sum % 2 == 0 && n % 2 == 0) cout << "Second" << endl;
	else if (sum % 2 == 0 && n % 2 == 1) cout << "First" << endl;
	else if (sum % 2 == 1 && n % 2 == 0) cout << "First" << endl;
	else {
		int cnt = 0; int p = -1;
		rep(i, n) {
			if (a[i] & 1) {
				cnt++; p = i;
			}
		}
		if (cnt > 1 || a[p] == 1) {
			cout << "Second" << endl;
		}
		else {
			int check = 0;
			while (a[p] != 1) {
				a[p]--; int g = a[0];
				rep(i, n) g = gcd(g, a[i]);
				rep(i, n) a[i] /= g;
				check ^= 1;
				if (a[p] % 2 == 0) {
					int cnts = 0; int q = -1;
					rep(i, n) {
						if (a[i] & 1) {
							cnts++; q = i;
						}
					}
					if (cnts > 1 || a[q] == 1) {
						int sums = 0;
						rep(i, n) sums += a[i];
						if (sums % 2 == check) cout << "First" << endl;
						else cout << "Second" << endl;
						return 0;
					}
					else {
						p = q;
					}
				}
			}
			if (check) cout << "First" << endl;
			else cout << "Second" << endl;
		}
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (size_t i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (size_t k = 1; k < v.size(); k++)
	{
		for (size_t j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
ll repeat_squaring(ll n, ll p, ll m)
{
	if (p == 0)
		return 1;
	if (p % 2 == 0)
	{
		ll t = repeat_squaring(n, p / 2, m);
		return t * t % m;
	}
	return n * repeat_squaring(n, p - 1, m);
}

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

Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
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();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int h,w; cin >> h >> w;
    char c[h][w]; REP(i,h)REP(j,w) cin >> c[i][j];
    REP(i,h){
        REP(j,w){
            cout << c[i][j];
        }
        cout << endl;
        REP(j,w){
            cout << c[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import itertools
from math import factorial
from collections import Counter

ans = 0
N=int(input())
x = list(map(int, input().split()))
y = itertools.accumulate(x)
counter = Counter([0]+list(y))
#print(counter.values())
#print
for i in counter.values():
    #print(ans)
    if i>1:ans+=factorial(i) // 2 // factorial(i-2)
print(ans)

Measured memory_bytes: 41984
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
const int Max=1000+9;
char a[Max][Max];
bool vis[Max][Max];
int n,m,num;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
struct node{
    int x,y,t;
    int path;
};
int bfs(int x,int y,int t){
    memset(vis,0,sizeof(vis));
    queue<node> q;
    q.push(node{x,y,t,0});
    while(!q.empty()){
        int cx=q.front().x;
        int cy=q.front().y;
        int ct=q.front().t;
        int path=q.front().path;
        q.pop();
        for(int i=0;i<4;i++){
            int nx=cx+dx[i];
            int ny=cy+dy[i];
            if(nx<1||nx>n||ny<1||ny>m||vis[nx][ny]||a[nx][ny]=='X'){
                continue;
            }
            vis[nx][ny]=1;
            if(a[nx][ny]==ct+'0'){
                //cout<<nx<<"!!"<<ny<<"!!"<<ct<<"!!"<<path<<endl;
                if(ct==num){
                    return path+1;
                }
                return bfs(nx,ny,ct+1)+path+1;
            }else{
                q.push(node{nx,ny,ct,path+1});
            }
        }
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    cin>>num;
    int sx,sy;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
            if(a[i][j]=='S'){
                sx=i;
                sy=j;
            }
        }
    }
    cout<<bfs(sx,sy,1)<<endl;
    return 0;
}


Measured memory_bytes: 4960
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int A, B, C; cin >> A >> B >> C;

	int res = 0;
	set<tuple<int,int,int> > same; same.clear();	
	while(A % 2 == 0 && B % 2 == 0 && C % 2 == 0){
		int next[3] = {0};
		next[0] = (B + C) / 2;
		next[1] = (C + A) / 2;
		next[2] = (A + B) / 2;

		sort(next, next + 3);

		tuple<int,int,int> curr = make_tuple(next[0],next[1],next[2]);
		if (!same.count(curr)){
			A = next[0];
			B = next[1];
			C = next[2];
			same.insert(curr);
			++res;
		}else{
			res = -1;
			break;
		} // end if
	} // end whlie

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a[3],b[3];
	int c1=0,c2=0,c3=0,c4=0;
	int i;
	for(i=0;i<3;i++){
		scanf("%d%d",&a[i],&b[i]);
		switch(a[i]){
			case 1:c1++;break;
			case 2:c2++;break;
			case 3:c3++;break;
			case 4:c4++;break;
		}
		switch(b[i]){
			case 1:c1++;break;
			case 2:c2++;break;
			case 3:c3++;break;
			case 4:c4++;break;
		}
	}
	if(c1>2||c2>2||c3>2||c4>2)printf("NO\n");
	else printf("YES\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i(0);i<n;i++)
#define fast  ios_base::sync_with_stdio(0); cin.tie(0);
#define open freopen("input.txt","r",stdin) ; freopen("output.txt","w",stdout);
#define watch(x) cout<<(#x)<<" is "<<x<<"\n";
#define mod 1000000007

int32_t main(){
	
	fast;
	//open;

	string s;
	cin>>s;
	if((s[0] == s[1])||(s[1]==s[2])||(s[2]==s[3]))cout<<"Bad";
	else cout<<"Good";


	return 0;
}

Measured memory_bytes: 256
S = list(input())

good_o = ['R', 'U', 'D']
good_e = ['L', 'U', 'D']

ans = 'No'
for i, Si in enumerate(S):
    if i % 2 == 0:
        if Si not in good_o: break
    else:
        if Si not in good_e: break
else:
    ans = 'Yes'

print(ans)

Measured memory_bytes: 3060
N = int(input())
t_bef = 0
x_bef = 0
y_bef = 0

flag = False
for i in range(N):
    t, x, y = map(int, input().split())
    t_diff = t - t_bef
    dist = abs(x - x_bef) + abs(y - y_bef)
    if (t_diff - dist)%2 != 0 or dist > t_diff:
        flag = True
    else:
        t_bef = t
        x_bef = x
        y_bef = y

if flag:
    print("No")
else:
    print("Yes")



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

int main(){
  string S; cin >> S;
  
  if(S.at(2) == S.at(3) && S.at(4) == S.at(5)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

int ubound(vector<long long>&v, long long b){
	int s = 0, e = v.size() - 1;
	int l = v.size();
	int m;
	while(e - s > 1){
		m = (s + e) / 2;
		if(v[m] <= b){
			s = m;
		}
		else{
			e = m;
		}
	}
	if(v[max(s - 1, 0)] > b) return max(s - 1, 0);
	else if(v[s] > b) return s;
	else if(v[min(s + 1, l - 1)] > b) return min(s + 1, l - 1);
	else return v.size();
}

LL N, H, W;
vector<LL> A, B;

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

	cin >> N >> H;

	for(int i=0; i<N; i++){
		LL a, b;
		cin >> a >> b;
		A.push_back(a);
		B.push_back(b);
	}
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());

	LL m = A[A.size()-1];
	int pos = ubound(B, m);
	long long ans = 0;

	for(int j=B.size()-1; j>=pos; j--){
		H -= B[j];
		ans++;
		if(H <= 0){
			break;
		}
	}
	if(H > 0){
		ans += H / m;
		if((H % m) != 0){
			ans++;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 5096
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 998244353;

template <ll mod> class ModInt {
    ll a;
public:
    constexpr ModInt(const ll a = 0) noexcept : a((a % mod + mod) % mod) {}
    constexpr ll &value() noexcept { return a; }
    constexpr ModInt operator + (const ModInt &rhs) const noexcept { return ModInt(*this) += rhs; }
    constexpr ModInt operator - (const ModInt &rhs) const noexcept { return ModInt(*this) -= rhs; }
    constexpr ModInt operator * (const ModInt &rhs) const noexcept { return ModInt(*this) *= rhs; }
    constexpr ModInt operator / (const ModInt &rhs) const noexcept { return ModInt(*this) /= rhs; }
    constexpr ModInt &operator += (const ModInt &rhs) noexcept {
        a += rhs.a;
        if (a >= mod) a -= mod;
        return *this;
    }
    constexpr ModInt &operator -= (const ModInt &rhs) noexcept {
        a += mod - rhs.a;
        if (a >= mod) a -= mod;
        return *this;
    }
    constexpr ModInt &operator *= (const ModInt &rhs) noexcept {
        a = a * rhs.a % mod;
        return *this;
    }
    constexpr ModInt pow(ll t) const noexcept {
        if (t == 0) return 1;
        auto ret = pow(t >> 1);
        ret *= ret;
        if (t & 1) ret *= *this;
        return ret;
    }
    constexpr ModInt inv() const noexcept { return pow(mod - 2); }
    constexpr ModInt operator /=(const ModInt &rhs) { return (*this) *= rhs.inv(); }
    constexpr bool operator == (const ModInt &rhs) const noexcept { return this->a == rhs.a; }
    constexpr bool operator != (const ModInt &rhs) const noexcept { return this->a != rhs.a; }
    friend constexpr ostream &operator << (ostream &os, const ModInt &rhs) noexcept { return os << rhs.a; }
    friend constexpr istream &operator >> (istream &is, ModInt &rhs) {
        is >> rhs.a;
        return is;
    }
};
using mint = ModInt<MOD>;

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

    vector<int> l(n), r(n);
    for (int i = 0; i < k; i++) {
        cin >> l[i] >> r[i];
        r[i]++;
    }

    vector<mint> dp(2 * n, 0);
    dp[1] = 1;
    dp[2] = MOD - 1;

    for (int i = 1; i < n; i++) {
        dp[i + 1] += dp[i];
        for (int j = 0; j < k; j++) {
            dp[i + l[j]] += dp[i];
            dp[i + r[j]] -= dp[i];
        }
    }

    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 8008
use std::cmp::Ordering;
use whiteread::parse_line;

fn main() {
    let (a, b, c, x, y): (u32, u32, u32, u32, u32) = parse_line().unwrap();
    let ans;

    if c <= (a + b) / 2 {
        match x.cmp(&y) {
            Ordering::Equal => ans = 2 * c * x,
            Ordering::Greater => ans = 2 * c * y + (a * (x - y)).min(2 * c * (x - y)),
            Ordering::Less => ans = 2 * c * x + (b * (y - x)).min(2 * c * (y - x)),
        }
    } else {
        ans = a * x + b * y;
    }
    println!("{}", ans);
}


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

#define PI acos(-1)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define all(c) (c).begin(), (c).end()
#define TIMESTAMP fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock()/CLOCKS_PER_SEC)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair <int, int> pii;
typedef vector <vi> vvi;
typedef vector <pii> vpii;
typedef vector<string> vs;

const int INF = 100500;
const int MAXN = 1e5 + 9;

int tx, ty, sx, sy;

void input() {            
	cin >>sx >> sy >> tx >> ty;
}

void solve() {
	for(int i = 1; i <= tx - sx; i++) cout << 'R';
	for(int i = 1; i <= ty - sy; i++) cout << 'U';
	for(int i = 1; i <= tx - sx; i++) cout << 'L';
	for(int i = 1; i <= ty - sy + 1; i++) cout << 'D';
	for(int i = 1; i <= tx - sx + 1; i++) cout << 'R';
	for(int i = 1; i <= ty - sy + 1; i++) cout << 'U';
	cout << "LU";
	for(int i = 1; i <= tx - sx + 1; i++) cout << 'L';
	for(int i = 1; i <= ty - sy + 1; i++) cout << 'D';
	cout << 'R';
}

int main() {     
#ifdef LOCAL
	freopen("xxx.in", "r", stdin);
	freopen("xxx.out", "w", stdout);
#else
	//freopen("xxx.in", "r", stdin);
	//freopen("xxx.out", "w", stdout);
#endif	
	input();
	solve();
	return 0;
}


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

int main(){
  int n,ans=0,t;string s,s1,s2;cin>>n>>s;
  REP(i,n-1){
    map<char,int> mp;
    s1=s.substr(0,i+1);
    s2=s.substr(i+1,s.size()-i-1);
    for(int j=0;j<s1.size();j++) if(s2.find(s1.at(j))!=-1) mp[s1.at(j)]++;
    t=mp.size();
    ans=max(ans,t);
  }
  cout<<ans;
}

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

//関数

//main関数
int main() {
    //入力
    long N,X;
    cin>>N>>X;
    vector<long> x(N+1);
    x.at(0)=X;
    for(int i=1;i<=N;i++){
        cin>>x.at(i);
    }
    //計算
    long ans=0;
    for(int i=1;i<=N;i++){
        ans=__gcd(ans,abs(x.at(i)-x.at(i-1)));
    }
    
    //出力
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(false);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int k = sc.nextInt();
    Long h[] = new Long[n];

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

    Arrays.sort(h, Collections.reverseOrder());

    long sum = 0;
    for (int i = k; i < n; i++) {
      sum += h[i];
    }

    System.out.println(sum);
  }
}


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

using namespace std;

int main() {
    string A, B, C;
    cin >> A >> B >> C;
    
    if(A[A.length()-1]==B[0] && B[B.length()-1]==C[0]){
        cout << "YES" <<endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
slist = []
for _ in range( M ):
    slist.append( list(map( int,input().split()[1:])))
plist = list(map(int,input().split()))

ans = 0
for pat in range(2**N):
    flag = True
    for sw in range(M):
        count = 0
        for x in slist[sw]:
            #print( "pat ={} x-1 ={} ans ={}".format( pat,x-1,(pat >> (x-1)) & 1))
            if ( (pat >> (x-1)) & 1 ) == 1:
                count += 1
        if count % 2 != plist[ sw ]:
            flag = False
            break
            
    if flag == True:
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<functional>
#include<algorithm>
using namespace std;

int T, N, K ,X[100000+10], A[100000+10];
int main() {
	cin >> T;
	for(int t=0; t<T; ++t){
		cin >> N;
		cin >> K;
		for(int i=0; i<N; ++i) cin >> X[i];
		for(int i=0; i+1<N; ++i) A[i] = X[i+1]-X[i];
		sort(A,A+N-1,greater<int>());
		if (K>N) K=N;
		int sum = 0;
		for(int i=0; i<K-1;++i) sum += A[i];
		cout << X[N-1]-X[0]-sum << endl;	
	}
	return 0;
}

Measured memory_bytes: 1960
def solve():
    N = int(input())
    cnt = 0
    flg = False
    for _ in range(N):
        d1, d2 = map(int,input().split())
        if d1 == d2:
            cnt += 1
        else:
            cnt = 0
        
        if cnt == 3:
            flg = True
    
    if flg:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    solve()

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

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	for(int i=0; i<n; i++) {
		cin >> a[i];
	}
	for(int i=0; i<n; i++) {
		cin >> b[i];
	}
	for(int i=0; i<n-1; i++) {
		cin >> c[i];
	}
	int ans = 0;
	for(int i=0; i<n; i++) {
		ans += b[a[i]-1];
		if(i && a[i-1]+1==a[i])
			ans += c[a[i-1]-1];
	}
	cout << ans;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    string S;
    cin >> S;
    vec C(3, 0);
    REP(i,0,SZ(S)) ++C[S[i]-'a'];
    if(abs(C[0]-C[1])<=1 && abs(C[1]-C[2])<=1 && abs(C[2]-C[0])<=1) PR("YES");
    else PR("NO");

    return 0;
}

/*



*/

Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define F(a,b,c) for(int a=b;a<=c;++a)
#define ms(a) memset(a,0,sizeof(a))
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define pb push_back
using namespace std;
typedef long long ll;
int read()
{
	int ans=0,w=1;
	char s=getchar();
	while(!isdigit(s))
	{
		if(s=='-')w=-1;
		s=getchar();
	}
	while(isdigit(s))
	{
		ans=ans*10+s-'0';
		s=getchar();
	}
	return ans*w;
}
const int MOD=1e9+7;
typedef long long ll;
struct node
{
	ll z[3][3];
	node(){ms(z);}
};
node operator*(node a,node b)
{
	node ans;
	F(z,0,2)F(x,0,2)F(y,0,2)ans.z[x][y]=(ans.z[x][y]+a.z[x][z]*b.z[z][y])%MOD;
	return ans;
}
node Pow(node a,ll p)
{
	node ans;
	F(i,0,2)ans.z[i][i]=1;
	while(p)
	{
		if(p&1)ans=ans*a;
		a=a*a;
		p>>=1;
	}
	return ans;
}
int n,m,d[100050];
int main()
{
	n=read();m=read();
	F(i,1,m)d[i]=read();
	d[++m]=n;
	node A,B,ans;
	A.z[0][0]=A.z[0][2]=A.z[1][1]=A.z[1][2]=A.z[2][0]=1;
	A.z[0][1]=A.z[2][1]=A.z[2][2]=2;
	B=A;
	--B.z[2][0];--B.z[2][2];B.z[2][1]=0;
	int ls=1;
	ans.z[0][0]=ans.z[0][2]=1;ans.z[0][1]=2;
	F(i,1,m)
	{
		ans=ans*Pow(A,d[i]-ls);
		if(i==m)break;
		ans=ans*B;
		ls=d[i]+1;
	}
	printf("%lld",ans.z[0][2]);
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
using namespace std;
int a[100000+10],n;
int cnt;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	if (a[n]-a[1]>1) return printf("No"),0;
	if (a[1]==a[n]) return printf("%s",n==a[1]+1||n>=a[1]*2?"Yes":"No"),0;
	//if (a[1]    )
	for(int i=1;i<=n;++i) if (a[i]==a[1]) ++cnt;
	if (cnt>a[1]) return printf("No"),0;
	return printf("%s",(n-cnt)>=(a[n]-cnt)*2?"Yes":"No"),0;
	//return printf("%s",a[1]==a[2]?:)
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A(N), B(N), C(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) cin >> C[i];
    A.push_back(-INF);
    C.push_back(INF);
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    ll ans = 0;
    rep(i, N) {
        ll k1 = distance(A.begin(), lower_bound(A.begin(), A.end(), B[i])-1);
        ll k2 = distance(C.begin(), upper_bound(C.begin(), C.end(), B[i]));
        ans += k1 * (N - k2);
        //cout << k1 << " " << N - k2 << endl;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int MOD=1000000007;
const int nmax=201234;

ll h,w,n,r,c,res,fac[nmax],fac2[nmax],inv[nmax],a[3012];
vector<pair<ll,ll> > v2;

inline ll solve(ll a,ll b)
{
    return fac[a+b]*fac2[b]%MOD*fac2[a]%MOD;
}

int main()
{
    scanf("%lld %lld %d",&h,&w,&n);
    v2.pb({0,0});
    for(ll i=1; i<=n; ++i)
    {
        scanf("%lld %lld",&r,&c);
        v2.pb({r,c});
    }
    sort(v2.begin(),v2.end());
    fac[0]=1;
    fac2[0]=1;
    inv[1]=1;
    for(ll i=2; i<200012; ++i)
        inv[i]=inv[MOD%i]*(MOD-MOD/i)%MOD;
    for(ll i=1; i<200012; ++i)
    {
        fac[i]=fac[i-1]*i%MOD;
        fac2[i]=fac2[i-1]*inv[i]%MOD;
    }
    for(ll i=1; i<=n; ++i)
    {
        a[i]=(a[i]+solve(v2[i].first-1,v2[i].second-1))%MOD;
        if(a[i]<0)
            a[i]+=MOD;
        for(ll j=i+1; j<=n; ++j)
            if(v2[i].first<=v2[j].first && v2[i].second<=v2[j].second)
                a[j]=(a[j]-a[i]*solve(v2[j].first-v2[i].first,v2[j].second-v2[i].second)%MOD)%MOD;

    }
    res=solve(h-1,w-1);
    for(ll i=1; i<=n; ++i)
        res=(res-a[i]*solve(h-v2[i].first,w-v2[i].second)%MOD)%MOD;
    if(res<0)
        res+=MOD;
    printf("%lld",res);
    return 0;
}


Measured memory_bytes: 5120
N, L = gets.chomp.split.map(&:to_i)

tem = 0

i = 1

while i < N
	tem += i
	i += 1
end

sum = N * L + tem

if L >= 0
	puts sum - L
elsif L < 0  &&   0 <= sum
     puts  sum
else
	puts  sum - L - N + 1
end

Measured memory_bytes: 1916
#from math import sqrt
#from heapq import heappush, heappop
#from collections import deque

n, k = [int(v) for v in input().split()]
p = [int(v) for v in input().split()]

max_p = max(p)

dp = [0] * (max_p+1)
dp[1] = 1
for i in range(2, max_p+1):
    dp[i] = dp[i - 1] + i
    dp[i - 1] /= (i - 1)
dp[max_p] /= max_p

e = 0
for i in range(k):
    e += dp[p[i]]

max_e = e

for i in range(k, n):
    e -= dp[p[i - k]]
    e += dp[p[i]]
    max_e = max(max_e, e)

print(max_e)


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


int main() {
  ll n,c,k;cin>>n>>c>>k;
  vector<ll> v(n);
  rep(i,n){cin>>v[i];}
  sort(v.begin(),v.end());
  ll i=0;
  
  ll ans=0;
  while(true){
    if(i>=n)break;
    ll j=1;
    while(true){
      if(i+j>=n||j==c||v[i+j]>v[i]+k){ans++;break;}
      else{j++;}
    }
  i+=j;//cout<<i<<" ";
  }
  cout<<ans;
}

Measured memory_bytes: 4020
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include <iostream>
#include<stdlib.h>
//#include <algorithm>
#include <limits>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
int main(void){
  ll x,k;
  cin >> k >> x;
  for(ll i=x-(k-1); i<=x+k-1;i++){
    if(i>=-1000000&&i<=1000000){
      cout << i << " ";
    }
  }
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX_LIST 105000
int main(){
bool prime[MAX_LIST];
for(int i=0;i<MAX_LIST;i++){
prime[i]=1;
}
prime[0]=prime[1]=0;
for(int i=0;i*i<MAX_LIST;i++){
if(prime[i]==1){
for(int j=i*2;j<MAX_LIST;j=j+i){
prime[j]=0;
}
}
}
int primelist[10000];
int j=0;
for(int i=0;i<MAX_LIST;i++){
if(prime[i]==1){
primelist[j]=i;
j++;
if(j>10000-1){
break;
}
}
}
int ans;
while(cin>>j,j){
ans=0;
for(int i=0;i<j;i++){
ans=ans+primelist[i];
}
cout<<ans<<endl;
}
return 0;
}

Measured memory_bytes: 1300
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n; 
	string s;
	string res="";
	stack<char>br;
	cin>>n>>s;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='('){
			br.push(s[i]);
			res=res+"(";
		}
		else if(s[i]==')')
		{
			if(br.size()==0){
				res="("+res;
				res=res+")";}
			else
				{
					br.pop();
					res=res+")";
				}
		}
	}
	for(int i=0;i<br.size();i++)
		res=res+")";
	cout<<res<<"\n";
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#include <queue>
#define INF INT_MAX
typedef long long ll;
struct edge{int to, cost;};
typedef pair<int,int> P;



struct StronglyConnectedComponents
{
  int n;
  vector<vector<int>> oG, rG;
  vector<int> comp, order, used;
  vector<pair<int, int>> edges;

  StronglyConnectedComponents (int n) : n(n), oG(n), rG(n), comp(n, -1), used(n, 0) {}

  int operator[] (int k)
  {
    return comp[k];
  }

  void add_edge(int u, int v)
  {
    oG[u].push_back(v);
    rG[v].push_back(u);
    edges.emplace_back(u, v);
  }

  void dfs(int v)
  {
    if (used[v]) return;
    used[v] = true;
    for (int to : oG[v]) dfs(to);
    order.push_back(v);
  }

  void rdfs(int v, int k)
  {
    if (~comp[v]) return;
    comp[v] = k;
    for (int to : rG[v]) rdfs(to, k);
  }

  void build(vector<vector<int>> &t)
  {
    for (int i = 0; i < n; ++i) dfs(i);

    reverse(order.begin(), order.end());
    int k = 0;
    for (int i : order) if (comp[i] == -1) rdfs(i, k++);

    t.resize(k);
    set<pair<int, int>> connect;
    for (auto &e : edges) {
      int u = comp[e.first], v = comp[e.second];
      if (u == v || connect.count({u, v})) continue;
      t[u].push_back(v);
      connect.emplace(u, v);
    }
  }
};

VI dist;
VVI G;
int ans = 0;
void solve(){
  rep(i,G.size()){
    for(int idx : G[i]){
      dist[idx] = max(dist[i] + 1, dist[idx]);
      ans = max(ans,dist[idx]);
    }
  }
}

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

  VVI a(n,VI(n-1));
  VVI mp(n,VI(n));


  rep(i,n) rep(j,n-1) {
    cin >> a[i][j];
    a[i][j]--;
    mp[i][a[i][j]] = j;
  }

  StronglyConnectedComponents g2(n * (n-1) + 1);

  rep(i,n)rep(j,n-2){
    g2.add_edge(i*(n-1)+j, i*(n-1)+j+1);
  }

  rep(i,n)rep(j,n-1){
    int idx = a[i][j];
    int idx2 = mp[idx][i] ;
    g2.add_edge(i*(n-1)+j, idx*(n-1) + idx2);
  }
  rep(i,n){
    g2.add_edge(n*(n-1),i*(n-1));
  }

  g2.build(G);
  if(G.size() != n*(n-1)/2 + 1){
    cout << -1 << endl;
    return 0;
  }


  dist.resize(G.size(),0);
  solve();

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


Measured memory_bytes: 221156
import java.util.*;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        String iro = sc.next();
        int ans = 1;
        for (int i = 0; i < iro.length() -1; i++) {
            char iro1 = iro.charAt(i);
            char iro2 = iro.charAt(i + 1);
            //System.out.println("iro1 "+iro.charAt(i));
            //System.out.println("iro2 "+iro.charAt(i + 1));
            if(iro1 != iro2){
                ans++;
                //System.out.println("ans "+ans);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25804
//
//  lucky7.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>

using namespace std;
typedef long long ll;

int main(int argc, const char* argv[]) {
  int n;
  std::cin >> n;

  bool is_7 = false;
  while (n>0) {
    if (n%10 == 7) {
      is_7 = true;
      break;
    }
    n = (n - (n%10)) / 10;
  }

  if (is_7) {
    std::cout << "Yes" << std::endl;
  }
  else {
    std::cout << "No" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3672
using System;
using System.Linq;

    class Program
    {
        static void Main(string[] args)
        {
            var table = new[] {
                new []{ "H", "H","H" },
                new []{ "H", "D","D" },
                new []{ "D", "H","D" },
                new []{ "D", "D","H" },
            };
            var ab=Console.ReadLine().Split(' ');
            var arr = table.Where(a => a[0] == ab[0]).First(b => b[1] == ab[1]).ToArray();
            Console.WriteLine(arr[2]);
        }
    }

Measured memory_bytes: 11476
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,q = inpl()
g = [[] for _ in range(n)]
c = [0] * n
for _ in range(n-1):
    a,b = inpl()
    a,b = a-1,b-1
    g[a].append(b)
    g[b].append(a)
for _ in range(q):
    x,y = inpl()
    c[x-1] += y
seen = [False] * n
seen[0] = True
q = deque()
q.append(0)
while q:
    now = q.popleft()
    for v in g[now]:
        if seen[v]: continue
        c[v] += c[now]
        seen[v] = True
        q.append(v)
print(*c)

Measured memory_bytes: 127912
// D - Static Sushi

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

ll x[100001];

ll d[100001];
ll r_d[100001];

ll v[100001];
ll r_v[100001];

ll cum_v[100001];
ll r_cum_v[100001];

ll max_cal[100001];
ll r_max_cal[100001];

int main() {
	ll N, C;
	cin >> N >> C;

	for (int i=0; i<N; i++) {
		cin >> x[i] >> v[i];
		r_v[i] = v[i];
	}
	reverse(r_v, r_v+N);

	for (int i=0; i<N; i++) {
		d[i+1] = x[i];
		r_d[i+1] = C - x[N-1-i];
	}

	for (int i=0; i<N; i++) {
		cum_v[i+1] = cum_v[i] + v[i];
		r_cum_v[i+1] = r_cum_v[i] + r_v[i];
	}

	ll tmp_max_cal = 0;
	for (int i=1; i<=N; i++) {
		ll cal = cum_v[i] - d[i];
		tmp_max_cal = max(tmp_max_cal, cal);
		max_cal[i] = tmp_max_cal;
	}

	tmp_max_cal = 0;
	for (int i=1; i<=N; i++) {
		ll cal = r_cum_v[i] - r_d[i];
		tmp_max_cal = max(tmp_max_cal, cal);
		r_max_cal[i] = tmp_max_cal;
	}

	ll ans = 0;

	/*
	// 時計回りのみ
	for (int i=0; i<=N; i++) {
		ll cal = cum_v[i] - d[i];
		ans = max(ans, cal);
	}

	// 反時計回りのみ
	for (int i=0; i<=N; i++) {
		ll cal = r_cum_v[i] - r_d[i];
		ans = max(ans, cal);
	}
	*/

	// 反時計回り→時計回り
	for (int i=0; i<N; i++) {
		ll cal = r_cum_v[i] - r_d[i]; // 反時計回り
		cal -= r_d[i]; // 原点に戻る
		cal += max_cal[N-i]; // 時計回り
		ans = max(ans, cal);
	}

	// 時計回り→反時計回り
	for (int i=0; i<N; i++) {
		ll cal = cum_v[i] - d[i];// 時計回り
		cal -= d[i]; // 原点に戻る
		cal += r_max_cal[N-i]; // 反時計回り
		ans = max(ans, cal);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 10664
#pragma GCC optimize ("O3")
//#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
int ne[100001];
int H[100001];
int n[100001], kari[100001];
int sagasu(int A) {
	if (n[A] == n[A - 1]) return 0;
	if (n[A] == n[A - 1] + 1) {
		return sagasu(H[A]) + 1;
	}
	int k = n[A - 1];
	for (int i = H[A]; i; i = ne[i]) {
		kari[k++] = sagasu(i);
	}
	sort(kari + n[A - 1], kari + n[A], greater<int>());
	int ret = 0;
	for (int i = 0; i < n[A] - n[A - 1]; i++) ret = max(ret, kari[n[A - 1] + i] + i);
	return ret + 1;
}

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


	int N = getint();

	for (int i = 2; i <= N; i++) {
		int a = getint();
		n[a]++;
		ne[i] = H[a];
		H[a] = i;
	}
	rep1(i, N) n[i] = n[i - 1] + n[i];

	printf("%d\n", sagasu(1));

	Would you please return 0;
}

Measured memory_bytes: 3840
a,b,c,d=map(int,input().split())
if a>-1 and b<1:
  print(max(a*c,a*d,b*c,b*d,0))
elif c>-1 and d<1:
  print(max(a*c,a*d,b*c,b*d,0))
else:
  print(max(a*c,a*d,b*c,b*d))

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

void solver(int N, int X, int T, int &ans){

    int div, mod;
    div = N/X;
    mod = N%X;

    if(mod != 0) ans = (div+1)*T;
    else ans = div*T;

    return;
}

int main(){

    int N, X, T;
    cin >> N >> X >> T;

    int ans{};
    solver(N, X, T, ans);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
def nCr(n, r)
  [*1..n].combination(r).size
end

N = gets.to_i
A = gets.split.map &:to_i
cusum = [sum = 0] + A.map{|a|sum += a}
p cusum.group_by{|n|n}.map{|k, v|
  nCr(v.size, 2)
}.inject:+


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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef pair<double, string> P;

bool sorter(const P p1, const P p2){
    if(p1.first==p2.first) return p1.second < p2.second;
    else return p1.first > p2.first;
}

int main(){
    int n;
    while(cin>>n ,n){
        vector<P> vec;
        rep(i,n){
            int p,a,b,c,d,e,f,s,m;
            string l;
            cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
            vec.pb(mp(1.*(f*s*m-p)/(a+b+c+(d+e)*m), l));
        }
        sort(all(vec), sorter);
        rep(i,n){
            cout<<vec[i].second<<endl;
        }
        cout<<"#"<<endl;
    }

    return 0;
}

Measured memory_bytes: 1224
import java.util.Scanner;

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

        int a, b, c;
        a = cin.nextInt();
        b = cin.nextInt();
        c = cin.nextInt();

        if (a == b | b == c | a == c) {
            if (a == b && b == c) {
                System.out.println("No");
            } else {
                System.out.println("Yes");
            }
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 22740
// 2014/11/05 Tazoe

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

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

	int sum = 0;

	int X, Y, A, B;
	cin >> A >> B;

	for(int i=1; i<N; i++){
		cin >> X >> Y;

		int dx = X-A;
		int dy = Y-B;

		if(dx*dy<0){
			sum += (abs(dx)+abs(dy));
		}
		else{
			sum += max(abs(dx), abs(dy));
		}

		A = X;
		B = Y;
	}

	cout << sum << endl;

	return 0;
}

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

int main() {
    int a11, a12, a13, a21, a22, a23, a31, a32, a33;
    cin >> a11 >> a12 >> a13 >> a21 >> a22 >> a23 >> a31 >> a32 >> a33;

    int n;
    cin >> n;

    bool b11 = false, b12 = false, b13 = false, b21 = false, b22 = false, b23 = false, b31 = false, b32 = false, b33 = false;

    for(int i = 0; i < n; i++) {
        int b;
        cin >> b;
        if(b == a11) b11 = true;
        if(b == a12) b12 = true;
        if(b == a13) b13 = true;
        if(b == a21) b21 = true;
        if(b == a22) b22 = true;
        if(b == a23) b23 = true;
        if(b == a31) b31 = true;
        if(b == a32) b32 = true;
        if(b == a33) b33 = true;
    }

    string result = "No";
    if(b11 && b12 && b13) result = "Yes"; 
    if(b21 && b22 && b23) result = "Yes";
    if(b31 && b32 && b33) result = "Yes";
    if(b11 && b21 && b31) result = "Yes";
    if(b12 && b22 && b32) result = "Yes";
    if(b13 && b23 && b33) result = "Yes";
    if(b11 && b22 && b33) result = "Yes";
    if(b13 && b22 && b31) result = "Yes";

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256