akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define range(v)                v.begin(),v.end()
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

void ssolve(std::istream& in, std::ostream& out){
    int n;
    s(n);
    vi a(n), b(n), c(n);
    f(i, 0, n){
        in >> a[i] >> b[i] >> c[i];
    }
    vector<vector<int>> dp(n + 1, vector<int>(3, 0));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            int prizea;
            if(j==0){
                prizea = b[i];
            }else if(j==1){
                prizea = c[i];
            }else{
                prizea = a[i];
            }
            int prizeb;
            if(j==0){
                prizeb = c[i];
            }else if(j==1){
                prizeb = a[i];
            }else{
                prizeb = b[i];
            }
            dp[i + 1][j] = max(dp[i][(j + 1) % 3] + prizea, dp[i][(j+2)% 3] + prizeb);
        }
    }

    int maxx = *max_element(dp[n].begin(), dp[n].end());
    p(maxx);
    return;
}

class CVacation {
public:
void solve(std::istream& in, std::ostream& out) {
    ios_base::sync_with_stdio(false);
    in.tie(0);out.tie(0);
    int t;
    int READ = 0;
    if(READ) s(t);
    else t = 1;
    while(t--){
        ssolve(in, out);
    }
}
};

integer main() {
    CVacation solver;
    std::istream& in(std::cin);
     std::ostream& out(std::cout);
     solver.solve(in, out);
}

Measured memory_bytes: 10992
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define mod 1000000007
#define N 500043
#define mp(a,b) make_pair(a,b)
#define loop(a,b) for(int i=a;i<b;i++)
#define test int t; cin >> t; while(t--)
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<vector<ll>>dp(n,vector<ll>(n,0));
    for(int i=0;i<n;i++)
        cin >> dp[i][i];
    for(int i=1;i<n;i++){
        for(int j=0;i+j<n;j++)
            dp[j][i+j]=max(dp[j][j]-dp[j+1][i+j],dp[i+j][i+j]-dp[j][i+j-1]);
    }
   /* for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }*/
    cout << dp[0][n-1] << endl;
}

Measured memory_bytes: 73660
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;

const double EPS = 1E-8;
typedef vector<double> vd;
typedef vector<vd> mat;

// 拡大係数行列で解く
vector<double> GaussJordan(const mat& A, const vd b) {
  int n = A.size();
  mat B(n, vd(n+1));
  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) B[i][j] = A[i][j];
  }
  for(int i=0; i<n; i++) {
    B[i][n] = b[i];
  }

  for(int i=0; i<n; i++) {
    int pivot = i;
    for(int j=i; j<n; j++) {
      if(abs(B[j][i]) > abs(B[pivot][i])) pivot = j;
    }
    swap(B[i], B[pivot]);

    if(abs(B[i][i]) < EPS) return vd();
    
    for(int j=i+1; j<=n; j++) B[i][j] /=B[i][i];
    for(int j=0; j<n; j++) {
      if(i != j) {
	for(int k=i+1; k<=n; k++) B[j][k] -= B[j][i] * B[i][k];
      }
    }
  }
  vd x(n);
  for(int i=0; i<n; i++) x[i] = B[i][n];
  return x;
}

int main() {
  int tcase;
  cin >> tcase;
  while(tcase--) {
    double x[3], y[3];
    cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2];
    
    mat A(3, vd(3, 0));
    for(int i=0; i<3; i++) {
      for(int j=0; j<3; j++) {
	if(j == 2) A[i][j] = 1;
	else A[i][j] = (j % 2 ? y[i] : x[i]);
      }
    }
    
    vd b(3);
    for(int i=0; i<3; i++) b[i] = -(x[i]*x[i] + y[i]*y[i]);

    vd v = GaussJordan(A, b);
    
    double cX = -v[0]/2, cY = -v[1]/2;
    double r = sqrt(pow(x[0]-cX, 2) + pow(y[0]-cY, 2));
    printf("%.3f %.3f %.3f\n", cX, cY, r);
  }
  
  return 0;
}

Measured memory_bytes: 1264
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Long[] a = new Long[n];
        Arrays.setAll(a, i -> Long.parseLong(sc.next()));
        sc.close();

        // 主処理
        long left = 0;
        long right = 0;
        int leftIndex = 0;
        int rightIndex = n - 1;
        for (int i = 0; i < n; i++) {
            if (left <= right) {
                left += a[leftIndex];
                leftIndex++;
            } else {
                right += a[rightIndex];
                rightIndex--;
            }
        }
        long result = Math.abs(left - right);

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 66720
#include <bits/stdc++.h>
using namespace std;
signed main(){
  char c[4];
  for(int i=0;i<4;i++)
    cin>>c[i];

  if(c[0] == 'Y'&& c[1] == 'A' && c[2] == 'K' && c[3] == 'I')
    cout<<"Yes"<<'\n';
  else
    cout<<"No"<<'\n';
  return(0);
}


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

using namespace std;

string divide[4] = {"dream","dreamer","erase","eraser"};

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

    reverse(S.begin(),S.end());
    for(int i=0; i<4; i++){
        reverse(divide[i].begin(),divide[i].end());
    }

    bool can = true;

    for(int i=0; i<S.size();){
        bool can2 = false;
        for(int j=0; j<4; j++){
            string d = divide[j];
            if(S.substr(i,d.size()) == d){
                can2 = true;
                i += d.size();
            }
        }
        if(!can2){
            can = false;
            break;
        }
    }

    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3748
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

const int MOD = 998244353;
class mint {
    ll x;
public:
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
    
    mint operator -() const {
        return mint(-x);
    }
    
    mint &operator +=(const mint &a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator -=(const mint &a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator *=(const mint &a) {
        (x *= a.x) %= MOD;
        return *this;
    }

    mint operator +(const mint &a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator *(const mint &a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(MOD - 2);
    }

    mint &operator /=(const mint &a) {
        return (*this) *= a.inv();
    }

    mint operator /(const mint &a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream &operator<<(ostream& os, const mint &m) {
        os << m.x;
        return os;
    }
};


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

    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    
    vector<vector<vector<mint>>> dp(3, vector<vector<mint>>(C+1, vector<mint>(D+1, mint(0))));
    dp[0][A][B] = mint(1);
    for (ll i = A; i <= C; i++) {
        for (ll j = B; j <= D; j++) {
            Rep (k, 3) {
                if (i+1 <= C) {
                    dp[1][i+1][j] += mint(j-1) * dp[k][i][j];
                    dp[1][i+1][j] += dp[k][i][j];
                }

                if (j+1 <= D) {
                    if (k != 1 || i == A) dp[k][i][j+1] += mint(i-1) * dp[k][i][j];
                    dp[min<ll>(2, k+1)][i][j+1] += dp[k][i][j];
                }
            }
        }
    }

    cout << dp[0][C][D] + dp[1][C][D] + dp[2][C][D] << endl;
}


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

int main() {
	int h,n,s;
	s = 0;
	cin >> h >> n;
	vector<int>a(n);
	for (int g = 0; g < n; g++) {
		cin >>a.at(g);
		s += a.at(g);
	}
	if (h <= s) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 640
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String X=sc.next();
        String Y=sc.next();
        
        if(X.compareTo(Y)<0){
            System.out.println("<");
        }else if(Y.compareTo(X)<0){
            System.out.println(">");
        }else{
            System.out.println("=");
        }
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    int i, j;
    for(i = 0; i < n; i++) {
        if(s[i] == 'A') {
            break;
        }
    }
    for(j = n - 1; j >= 0; j--) {
        if(s[j] == 'Z') {
            break;
        }
    }
    cout << j - i + 1 << "\n";
}

Measured memory_bytes: 3768
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <tuple>
#include <climits>

using namespace std;


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

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int a,b,c,d,e;
	scanf("%d",&a);
	scanf("%d",&b);
	c = a+b;
	d = a-b;
	e = a*b;
	if(e>d)
	{
		if(e>c)
		{
			printf("%d",e);
		}
		else
		{
			printf("%d",c);
		}
	}
	else if(d>c)
	{
		printf("%d",d);
	}
	else 
	{
		printf("%d",c);
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll int
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define For(i,x,y)	for(ll i=x;i<=y;++i)
using namespace std;
const ll N=4010;
char s1[N],s2[N];
ll L[N],R[N],pre[N],nxt[N],a[N],b[N],now[N],n,dd[N],gg[N],answ=1e9;
bool pd(){
	bool a_has_1=0,b_has_1=0;
	For(i,0,n-1)	a_has_1|=a[i],
					b_has_1|=b[i];
	return a_has_1&&!b_has_1;
}
void Max(ll &x,ll y){	if (y>=x)	x=y;	}
int main(){
//	freopen("flip.in","r",stdin);
//	freopen("flip.out","w",stdout);
	scanf("%s%s",s1,s2);	n=strlen(s1);
	For(i,0,n-1)	a[i]=s1[i]-'0';
	For(i,0,n-1)	b[i]=s2[i]-'0';
	if (pd())	return puts("-1"),0;
	For(i,0,n-1)	L[i]=i-1,R[i]=i+1;	L[0]=n-1;	R[n-1]=0;
	For(i,0,n*2)	pre[i%n]=b[i%n]?i%n:pre[L[i%n]];
	FOr(i,n*2,0)	nxt[i%n]=b[i%n]?i%n:nxt[R[i%n]];
	For(i,0,n-1)	pre[i]=(i-pre[i])<0?(i-pre[i]+n):(i-pre[i]);
	For(i,0,n-1)	nxt[i]=(nxt[i]-i)<0?(nxt[i]-i+n):(nxt[i]-i);
	For(rev,1,n*2){//枚举 向左移动i
		ll ned_right=0,ned_left=0,cost=0;
		For(i,0,n-1)	now[i]=a[(i+rev)%n];
		For(i,0,n-1)	dd[i]=gg[i]=0;
		For(i,0,n-1)	cost+=now[i]!=b[i];
		For(i,0,n-1)	if (now[i]!=b[i]&&nxt[i]>rev&&pre[i])	Max(dd[nxt[i]-rev-1],pre[i]),
																Max(gg[pre[i]-1],nxt[i]-rev);
		FOr(i,n-1,0){
			Max(dd[i],dd[i+1]);	Max(gg[i],gg[i+1]);
			answ=min(answ,rev+cost+(min(dd[i],gg[i])+i)*2);
		}
	}
	For(rev,0,n*2){//枚举 向右移动i
		ll ned_left=0,ned_right=0,cost=0;
		For(i,0,n-1)	now[i]=a[(i-rev+n*2)%n];
		For(i,0,n-1)	dd[i]=gg[i]=0;
		For(i,0,n-1)	cost+=now[i]!=b[i];
		For(i,0,n-1)	if (now[i]!=b[i]&&pre[i]>rev&&nxt[i])	Max(dd[pre[i]-rev-1],nxt[i]),
																Max(gg[pre[i]-1],pre[i]-rev);
		FOr(i,n-1,0){
			Max(dd[i],dd[i+1]);	Max(gg[i],gg[i+1]);
			answ=min(answ,rev+cost+(dd[i]+i)*2);
		}
	}printf("%d",answ);
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
void insertion_sort(int a[], int n)
{ 
     int i,j;
     for (i=1;i<n;i++)
      {
        int key=a[i];
        j=i-1;	
        while((j>=0)&&(a[j]>key))
            {
            a[j+1] = a[j];
            j--; 
            }
        a[j+1] = key;

		for(j = 0; j < n; ++j){
            if(j) cout << " ";
            cout << a[j];
        }
        cout << endl;
     }
}
int main()
{
    int n,i;
    cin >> n;
    int a[101];
    for(int i=0;i<n;i++)
    {
        cin >>a[i];
    }
	for(i = 0; i < n; ++i){
        if(i) cout << " ";
        cout << a[i];
    }
	cout << endl;
    insertion_sort(a,n);
}

Measured memory_bytes: 3092
N,M=map(int,input().strip().split(" "))

a=[]
b=[]

for i in range(N):
    a.append(input())

N=0

for i in range(M):
    b.append(input())
    if(b[i] in a[i]):
        N+=1

if(N==M):
    print("Yes")
else:
    print("No")
#コピペです。

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cmath>
using namespace std;

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


const int BIG_NUM = 1e8;
const ll INF = 1000000000000000000;

const int MAX_A = 1000000;

int main() {
	char a;
	cin >> a;
	if (a >= 'a' && a <= 'z') {
		cout << "a";
	}
	else {
		cout << "A";
	}
	
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >>n;
int num=0;
int output=1;
for(int i=1;i<=n;i++){
int count=0;
int kazu = i;
while(kazu%2==0){
count++;
kazu = kazu/2;
}

if(count>num){
num = count;
output= i;
}

}
  
cout << output <<endl; 
}

Measured memory_bytes: 3576
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

int main(){
  int N;
  string name = "ABC";
  cin >> N;
  name[2] += (N/1000) ;
  cout << name << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vi A(N);
  ll sum=0;
  vi cnt(101000,0);
  rep(i,N) {
    cin >> A[i];
    sum += A[i];
    cnt[A[i]]++;
  }
  int q;
  cin >> q;
  rep(qi,q) {
    int b,c;
    cin >> b >> c;
    int x = cnt[b];
    cnt[b]=0;
    cnt[c]+=x;
    sum += ll(x)*(c-b);
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <climits>
using namespace std;

#define INF 324890148923489LL

#define FOR(i, j, k) for(int i=j ; i<k ; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define MAX_V 100005

struct edge{
    int to;
    long long cost;
    edge(int i, long long j) {to = i, cost = j; };
};

vector<edge> G[MAX_V];

void dfs(vector<ll> &d, int e) {

    REP(i, G[e].size()) {
        int to = G[e][i].to;
        if (d[to] == INF) {
            d[to] = d[e] + G[e][i].cost;
            dfs(d, to);
        }
    }

}

int main() {

    int N, M; cin >> N >> M;
    
    REP(i, M) {
        int l, r, d;
        cin >> l >> r >> d;
        l--; r--;
        G[l].push_back(edge(r, d));
        G[r].push_back(edge(l, -d));
    }

    vector<ll> d(N, INF);
    REP(i, N) {
        if (d[i] == INF) {
            d[i] = 0;
            dfs(d, i);
        }
    }

    REP(i, MAX_V) REP(j, G[i].size()) {
        if (d[i] + G[i][j].cost != d[G[i][j].to]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    
    return 0;
}


Measured memory_bytes: 17408
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		String s = stdIn.next();
		int cnt = 0;
		
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == 'R')cnt++;
		}
		
		if(cnt == 2) {
			if(s.charAt(1) == 'S') {
				cnt = 1;
			}
		}
		System.out.println(cnt);
		
	}

}


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

using namespace std;

int N;
int r[101];
int v[3][101];

bool check(int k, int mb) {
  //if(v[k][0] + mb > 100) return false;

  v[k][0] += mb;
  int score[101] = {0};
  for(int i = 0; i < 3; i++) {
    vector<int> ts[303];
    for(int j = 0; j < N; j++) {
      ts[v[i][j]].push_back(j);
    }
    int cnt = 0;
    for(int j = 300; j >= 0; j--) {
      for(int id : ts[j]) {
	score[id] += r[cnt];
      }
      cnt += ts[j].size();
    }
  }
  v[k][0] -= mb;
  {
    vector<int> ts[303];
    for(int j = 0; j < N; j++) {
      ts[score[j]].push_back(j);
    }
    int cnt = 0;
    for(int j = 300; j >= 0; j--) {
      for(int id : ts[j]) {
	if(id == 0) return cnt < 8;
      }
      cnt += ts[j].size();
    }
  }
  assert(false);
}

int main() {
  cin >> N;
  for(int i = 0; i < N; i++) cin >> r[i];
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < 3; j++) cin >> v[j][i];
  }

  int ans = 1000;
  for(int i = 0; i < 3; i++) {
    for(int mb = 0; mb <= 101; mb++) {
      if(check(i, mb)) {
	ans = min(ans, mb);
	break;
      }
    }
  }
  if(ans == 1000) cout << "Saiko" << endl;
  else cout << ans << endl;


  return 0;
}

Measured memory_bytes: 3160
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();
    long K = sc.nextLong();
    sc.close();

    long ans = Long.min(K, A);
    ans -= Long.max((K - A - B), 0);
    System.out.println(ans);
  }
}


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

int main () {
    int x, y;
    cin >> x >> y;
    int tmp;
    while(0 < x || 0 < y) {
        if (x > y) {
            tmp = x;
            x = y;
            y = tmp;
        }
        cout << x << " " << y << endl;
        cin >> x >> y;
    }
}


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

  int N , M ;
  int ans = 0 ;
  cin >> N >> M ;
  vector<int> A(N) ;
  int D = 0 ;
  rep(i,N) cin >> A.at(i) ;
  rep(i,N){
    if( D <= M )ans++ ;
    D = D + A.at(i) ;
  }
  if( D <= M )ans++ ;
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            String[] s = sc.next().split("S");
            int max = 0;
            for (String str : s) {
                max = Math.max(str.length(), max);
            }
            System.out.println(max);
        }
    }
}


Measured memory_bytes: 35624
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

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

  int n;
  cin >> n;
  
  int sum = 0;
  int p[n];
  REP(i,n){
    cin >> p[i];
    sum += p[i];
  }
  
  if(sum % 10 != 0){
    cout << sum << endl;
    return 0;
  }
  
  sort(p,p+n);
  
  REP(i,n){
    if(p[i] % 10 != 0){
      cout << sum-p[i] << endl;
      return 0;
    }
  }
  
  cout << 0 << endl;
  

  return 0;
}

Measured memory_bytes: 256
let rec is_uniq l = match l with
    [] -> true
  | x::xs -> not (List.mem x xs) && is_uniq xs;;

let rec ok l = match l with
    [] -> true
  | x::[] -> true
  | x::y::xs -> x.[String.length x - 1] = y.[0] && ok (y::xs);;

let n = read_int () in
let a = Array.make n "" in
for i = 0 to n - 1 do
  a.(i) <- read_line ()
done;
if is_uniq (Array.to_list a) && ok (Array.to_list a) then
  print_string "Yes"
else
  print_string "No";
print_newline ()


Measured memory_bytes: 384
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(a==b){
      System.out.println("Yay!");
    }else if((a+b < 16)&&(Math.abs(a-b)==1)){
      System.out.println("Yay!");
    }else if((a+b < 15)&&(Math.abs(a-b)==2)){
      System.out.println("Yay!");
    }else{
      System.out.println(":(");
    }
  }
}

Measured memory_bytes: 21844
#include<stdio.h>

int main(){
  char str[10][10] = {};
  int h = 0;
  int w = 0;
  int i = 0;
  int j = 0;
  int cnt = 0;
  int x = 0;
  int y = 0;
  
  scanf("%d %d",&h,&w);
  for(i=0;i<h;i++){
    scanf(" %s",str[i]);
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(str[i][j] == '#'){
        cnt++;
      }
    }
  }
  //printf("%d",cnt);
  if(cnt == h+w-1){
    printf("Possible");
  }else{
    printf("Impossible");
  }
  return 0;
  
}

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

int main(){
    
    // 1. 入力情報.
    int A, B, C, D;
    scanf("%d %d %d %d", &A, &B, &C, &D);
    
    // 2. 線分が横切るマスの数は？
    int dx = abs(A - C);
    int dy = abs(B - D);
    int gxy = __gcd(dx, dy);
    dx /= gxy;
    dy /= gxy;
    
    // 3. 出力.
    printf("%d\n", (dx + dy - 1) * gxy);
    return 0;
}

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

int dp[100000], h[100000];

int recurse(int i) {
	int& state = dp[i];
  	if(state != -1) return state;
  	if(i == 0) return state = 0;
  	if(i == 1) return state = abs(h[1] - h[0]);
  	return state = min(
      recurse(i - 1) + abs(h[i] - h[i - 1]), 
      recurse(i - 2) + abs(h[i] - h[i - 2])
    );
}

int main() {
  	int n; cin >> n;
  	for(int i = 0; i < n; ++i) cin >> h[i];
  	memset(dp, -1, sizeof dp);
  	cout << recurse(n - 1) << endl;
	return 0;
}

Measured memory_bytes: 2560
n,k = map(int, raw_input().split())
l = map(int, raw_input().split())
mn = 10**9
for i in range(n-k+1):
    if l[i] * l[i+k-1] < 0:
        p = max(abs(l[i]), abs(l[i+k-1])) + 2 * min(abs(l[i]), abs(l[i+k-1]))
    else:
        p = max(abs(l[i]), abs(l[i+k-1]))
    mn = min(mn, p)
print mn


Measured memory_bytes: 11344
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i)
#define ALL(n) begin(n), end(n)

int main()
{
  int N, res = 0;
  cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a.at(i);
  sort(ALL(a), greater<int>());
  rep(i, N) res += a.at(i) * (i % 2 ? -1 : 1);
  cout << res << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


class Solver():
    def __init__(self, target):
        self.target = target

    def bin_search(self, l, r):
        if l + 1 == r:
            if self.check(l):
                return l - 1
            return l

        c = (l+r) // 2

        is_c_achieve = self.check(c)

        if is_c_achieve:
            return self.bin_search(l, c)
        else:
            return self.bin_search(c, r)

    def check(self, c):
        others = cl.deque(self.target)
        others.remove(self.target[c])
        mine = self.target[c]

        while len(others) > 0:
            minest = others.popleft()
            if mine * 2 >= minest:
                mine += minest
            else:
                return False
        return True


def main():
    N = II()
    target = LI()
    target.sort()
    solver = Solver(target)
    ans = solver.bin_search(0, N - 1)
    print(N - ans - 1)


main()


Measured memory_bytes: 91920
#include <iostream>
using namespace std;
int main(void){
    long long S,n,N,i;
    cin >> S;
    N=S;
    for(i=0;N>0;i++){
        N=N/10;
    }
    n=i;
    long long a[n];
    N=S;
    for(i=0;i<n;i++){
        a[n-1-i]=N%10;
        N=N/10;
    }
    long long j,k,d;
    d=100000;
    for(i=0;i<n-2;i++){
        if(d>abs(a[i]*100+a[i+1]*10+a[i+2]-753)){
            d=abs(a[i]*100+a[i+1]*10+a[i+2]-753);
        }
    }
    cout << d << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1000000007;
const int64_t MAXN = 100010;

int64_t P[MAXN];
int64_t pow_mod(int64_t x, int64_t n)
{
  int64_t res = 1;
  if (n > 0)
  {
    res = pow_mod(x, n / 2);
    if (n % 2 == 0)
      res = (res * res) % MOD;
    else
      res = (((res * res) % MOD) * x) % MOD;
  }
  return res;
}

int main()
{
  int64_t N, K, ans = 0;
  cin >> N >> K;
  for (int64_t i = 1; i <= K; i++)
  {
    P[i] = pow_mod(i, N);
  }
  vector<int64_t> v(K + 1, 0);
  for (int64_t k = K; k >= 1; k--)
  {
    v[k] = P[K / k];
    for (int64_t i = 2; i * k <= K; i++)
    {
      v[k] -= v[i * k];
    }
    (ans += (k * v[k]) % MOD) %= MOD;
  }
  cout << (ans + MOD) % MOD << endl;
}

Measured memory_bytes: 4832
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in a:
  ans+=b[i-1]
for i in range(n-1):
  if a[i]+1==a[i+1]:ans+=c[a[i]-1]
print(ans)

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string s; cin>>s;
	if(s.size()==2){
		if(s.at(0)==s.at(1)){
			cout<<"1 2\n"s;
			return 0;
		}
	}
	else for(int i=0;i+3<s.size();++i){
		if(s.at(i)==s.at(i+1)||s.at(i+1)==s.at(i+2)||s.at(i+2)==s.at(i)){
			cout<<i+1<<" "s<<i+3<<"\n"s;
			return 0;
		}
	}
	cout<<"-1 -1\n"s;
}


Measured memory_bytes: 3740
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int[] a = new int[5];
		
		boolean ch = true;


		for(int i=0;i<5;i++) {
			a[i] = sc.nextInt();
		}
		
		int k = sc.nextInt();

		out: for(int i=0; i<4;i++) {
			for(int j=i+1;j<5;j++) {
				if(a[j]-a[i]<=k ) ch=true;
				else {
					ch=false;
					break out;
				}
			}
		}
		if(ch==true)System.out.print("Yay!");
		else System.out.print(":(");
	}
}


Measured memory_bytes: 21716
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
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, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	int pn = 1;
	if (*ci == '-') {
		pn = -pn;
		ci++;
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return pn * tmp;
}

ll A[200001];
void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	ll tmp[200001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	int N = getint();
	rep1(i, N) {
		A[i] = getint() + A[i - 1];
	}

	pakuri_sort(N + 1, A);

	ll kotae = 0;
	ll mae = 1e18;
	int kazu = 0;
	rep(i, N + 1) {
		if (mae != A[i]) {
			mae = A[i];
			kazu = 0;
		}
		kotae += kazu++;
	}

	printf("%lld\n", kotae);

	Would you please return 0;
}

Measured memory_bytes: 6452
def main():
    n = int(input())
    R = [list(map(int,input().split())) for _ in range(n)]
    B = [list(map(int,input().split())) for _ in range(n)]

    R = sorted(R, key=lambda x: x[1], reverse=True)
    B = sorted(B, key=lambda x: x[0])

    used = []
    for i in range(n):
        for j in range(n):
            if (R[j] not in used) and (R[j][0] < B[i][0]) and R[j][1] < B[i][1]:
                used.append(R[j])
                break
    print(len(used))


if __name__ == '__main__':
    main()


Measured memory_bytes: 39792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

#define EPS (1e-10)
#define equals(a,b) (fabs(a)-fabs(b)<EPS)

using namespace std;

class Point{
public:
    double x,y;

    Point(double x=0,double y=0):x(x),y(y){}

    Point operator + (Point &p) { return Point(x+p.x,y+p.y); }
    Point operator - (Point &p) { return Point(x-p.x,y-p.y); }
    Point operator * (double a) { return Point(x*a,y*a); }
    Point operator / (double a) { return Point(x/a,y/a); }

    double abs() { return sqrt(norm()); }
    double norm() { return x*x+y*y; }

    bool operator < (const Point &p) const {
        return x!=p.x?x<p.x:y<p.y;
    }

    bool operator == (const Point &p) const {
        return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
    }
};

typedef Point Vector;
///内积
double dot(Vector a,Vector b){
    return a.x*b.x+a.y*b.y;
}
///外积
double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

int cow(Point p0,Point p1,Point p2){
    Vector a=p1-p0;
    Vector b=p2-p0;
    if(cross(a,b)>EPS)  {printf("COUNTER_CLOCKWISE\n"); return 1;}
    if(cross(a,b)<-EPS) {printf("CLOCKWISE\n"); return -1;}
    if(dot(a,b)<-EPS)   {printf("ONLINE_BACK\n"); return 2;}
    if(a.norm()<b.norm())  { printf("ONLINE_FRONT\n");return -2;}

    printf("ON_SEGMENT\n");
    return 0;
}

int main()
{
    Point p0,p1,p2;
    scanf("%lf%lf%lf%lf",&p0.x,&p0.y,&p1.x,&p1.y);
    int q;
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%lf%lf",&p2.x,&p2.y);
        cow(p0,p1,p2);
    }
    return 0;
}


Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

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

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

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    ll ret = 0;
    while(true) {
        ll cnt = 0;
        vector<ll> cnt2(N);
        for(int i = 0;i < N;i++) {
            cnt2.at(i) = vec.at(i) / N;
            vec.at(i) = vec.at(i) % N;
        }
        ll sum = 0;
        for(int i = 0;i < N;i++) {
            sum += cnt2.at(i);
        }
        ret += sum;
        for(int i = 0;i < N;i++) {
            vec.at(i) += sum - cnt2.at(i);
        }
        bool cnt3 = true;
        for(int i = 0;i < N;i++) {
            if(vec.at(i) >= N) {
                cnt3 = false;
            }
        }
        if(cnt3 == true) {
            break;
        }
    }
    cout << ret << endl;
}          

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
ll arr[maxn], prefix[maxn];
ll check(int val, int n) {
    ll cnt = 0;
    for (int i = 1; i <= n; ++i) {
        int pos = lower_bound(arr + 1, arr + 1 + n, val - arr[i]) - arr;
        cnt += n + 1 - pos;
    }
    return cnt;
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n; ll m; cin >> n >> m;
    for (int i = 1; i <= n; ++i) cin >> arr[i];
    sort(arr + 1, arr + 1 + n);
    for (int i = 1; i <= n; ++i) prefix[i] = prefix[i - 1] + arr[i];
    int left = 0, right = 2 * maxn; ll res = 0;
    while (left <= right) {
        int mid = (left + right) / 2; ll cnt;
        if ((cnt = check(mid, n)) < m)
            right = mid - 1;
        else {
            left = mid + 1, res = 0;
            for (int i = 1; i <= n; ++i) {
                int pos = lower_bound(arr + 1, arr + 1 + n, mid - arr[i]) - arr;
                res += (n + 1 - pos) * arr[i] + prefix[n] - prefix[pos - 1];
            }
            if (cnt > m) res -= (cnt - m) * mid;
        }
    }
    cout << res << '\n';
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,a[300001];
signed main()
{
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++)cin>>a[i],a[i]-=i;
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)ans+=abs(a[i]-a[(n+1)/2]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll a,p;
	cin>>a>>p;
	cout << (a*3+p)/2;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <fstream>
#include <cmath>
#include <list>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long

#define MOD 1000000007

void show(vector<ll>* g, ll s, ll from) {
  cout << from << " -> " << s << endl;
  rep(i,g[s].size()) {
    if(g[s][i] != from) show(g,g[s][i],s);
  }
}


ll calc(vector<ll>* g, ll s, ll from, ll k) {
  ll color_num,child_num;
  if(from==-1) {
    color_num = k-1;
    child_num = g[s].size();
  }else {
    color_num = k-2;
    child_num = g[s].size()-1;
  }

  if(child_num>color_num) return 0;
  
  ll sum = 1;
  rep(i,g[s].size()) {
    if(g[s][i] == from) continue;
    
    sum *= color_num; if(sum==0) break;
    sum %= MOD;
    color_num--;
  }
  rep(i,g[s].size()) {
    if(g[s][i] == from) continue;
    
    sum *= calc(g,g[s][i],s,k); if(sum==0) break;
    sum %= MOD;
  }
  return sum;
}

int main(int argc, char *argv[]) {
  ll n,k;
  ll x,y;
  vector<ll> *g;
  
  cin >> n >> k;
  g = new vector<ll>[n];
  rep(i,n-1) {
    cin >> x >> y;
    g[x-1].push_back(y-1);
    g[y-1].push_back(x-1);
  }

  //show(g,0,-1);

  ll ans = k*calc(g,0,-1,k);
  ans %= MOD;
  cout << ans << endl;;
  

  delete[] g;
  
  return 0;
}


Measured memory_bytes: 11520
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
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...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 60;
char s[N][N];

const int M = N * N;
int f[M], c[M];

int find(int x) {
  if (f[x] != f[f[x]]) f[x] = find(f[x]);
  return f[x];
}

void join(int x, int y) {
  int rx = find(x), ry = find(y);
  if (rx == ry) return;
  f[ry] = rx;
  c[rx] += c[ry];
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
  }
  for (int i = 0; i < n * m; ++i) {
    f[i] = i;
    c[i] = 1;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == '.') continue;
      if (i + 1 < n && s[i + 1][j] == '#') {
        join(i * m + j, (i + 1) * m + j);
      }
      if (j + 1 < m && s[i][j + 1] == '#') {
        join(i * m + j, i * m + j + 1);
      }
    }
  }
  bool found = false;
  for (int i = 0; i < n * m; ++i) {
    if (s[i / m][i % m] == '.') continue;
    if (find(i) != i) continue;
    if (c[i] == 1) {
      found = true;
      break;
    }
  }
  puts(found ? "No" : "Yes");
  return 0;
}


Measured memory_bytes: 256
march = ['M', 'A', 'R', 'C', 'H']
counts = [0 for _ in range(len(march))]
N = int(input())

for _ in range(N):
    tmp = input()[0]
    if tmp in march:
        counts[march.index(tmp)] += 1

res = 0
c = 0
for i in range(len(counts)):
    for j in range(i + 1, len(counts)):
        for k in range(j + 1, len(counts)):
            tmp = counts[i] * counts[j] * counts[k]
            res += tmp

print(res)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String w = scanner.next();
		w = w.toLowerCase();
		String t;
		int count = 0;

		while (true) {
			t = scanner.next();
			if (t.equals("END_OF_TEXT")) {
				break;
			}
			t = t.toLowerCase();
			if (t.equals(w)) {
				count = count + 1;
			}
		}

		System.out.println(count);
	}

}



Measured memory_bytes: 26320
n = int(input())
a = list(map(int,input().split()))
a1 = {'emp':0}
a2 = {'emp':0}

for i in range(0,n,2):
    # print(i)
    if str(a[i]) in a1.keys():
        a1[str(a[i])] += 1
    else :
        a1[str(a[i])] = 1
    if str(a[i+1]) in a2.keys():
        a2[str(a[i+1])] += 1
    else :
        a2[str(a[i+1])] = 1
# print(a1,a2)

a1 = sorted(a1.items(), key=lambda x: -x[1])
a2 = sorted(a2.items(), key=lambda x: -x[1])

# print(a1,a2)
if a1[0][0] == a2[0][0]:
    print(n-max(a1[0][1]+a2[1][1],a1[1][1]+a2[0][1]))
else :
    print(n-a1[0][1]-a2[0][1])

Measured memory_bytes: 23260
import sys
readline = sys.stdin.buffer.readline
n,k = map(int,readline().split())
r = n-k
mod = 10**9+7
def pow(n,p,mod=10**9+7): #繰り返し二乗法(nのp乗)
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod
def factrial_memo(n=10**5+1,mod=10**9+7):
    fact = [1, 1]
    for i in range(2, n + 1):
        fact.append((fact[-1] * i) % mod)
    return fact
def fermat_cmb(n, r, mod=10**9+7): #needs pow,factrial_memo(only fact). return nCk
    return fact[n] * pow(fact[r],mod-2) * pow(fact[n-r],mod-2) %mod
fact = factrial_memo()
for i in range(1,k+1):
    if r+1 < i:
        print(0)
        continue

    res = fermat_cmb(r+1,i)*fermat_cmb(k-1,k-i)
    print(res%mod)
    


Measured memory_bytes: 45296
//おまじない
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int a,b;
  cin>>a>>b;
  
  if (b%a==0){
    cout<<a+b<<endl;
  }
  
  else{
    cout<<b-a<<endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100000

struct Node{
  int p,l,r;
};
struct Node NT[N];
int D[N];
void SetDepth(int u,int p){
  D[u]=p;
  if(NT[u].r!=-1)SetDepth(NT[u].r,p);
  if(NT[u].l!=-1)SetDepth(NT[u].l,p+1);
}

int main(){
  int i,j,n,id,k,c,l,r;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    NT[i].p=-1;
    NT[i].l=-1;
    NT[i].r=-1;
  }

  for(i=0;i<n;i++){
    scanf("%d",&id);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&c);
      if(j==0)NT[id].l=c;
      else NT[l].r=c;
      l=c;
      NT[c].p=id;
    }
  }
  for(i=0;i<n;i++){
    if(NT[i].p==-1)r=i;
  }
  SetDepth(r,0);

  for(i=0;i<n;i++){
    printf("node %d: ",i);
    printf("parent = %d, ",NT[i].p);
    printf("depth = %d, ",D[i]);
    if(NT[i].p==-1)printf("root, ");
    else if(NT[i].l==-1)printf("leaf, ");
    else printf("internal node, ");
    printf("[");
    for(j=0,c=NT[i].l;c!=-1;j++,c=NT[c].r){
      if(j==0)printf("%d",c);
      else printf(", %d",c);
    }
    printf("]\n");
  }
  return 0;
}



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

int main(){
    int a;
    
    int 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: 3100
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int i,j,k,n,m,l,count1=0;
void ABC140(void);
void ABC141(void);
void ABC142(void);
void ABC143(void);
void ABC144(void);
void ABC145(void);
void ABC146(void);
void ABC147(void);
void ABC148(void);
void ABC149(void);

int main(void){
    ABC149();
}

void ABC149(){
    long long int a,b,k;
    cin>>a>>b>>k;
    //最終的に減るクッキーはk枚
    cerr<<a<<" "<<b<<" "<<k<<endl;
    if(a>=k)a-=k;
    else if((a+b)>=k){
        b=a+b-k;
        a=0;
    }else{
        a=0;
        b=0;
    }
    cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
s = int(input())
temp = []
temp.append(s)
former = s
idx = 1

while True:
    idx += 1
    later = former / 2 if former % 2 == 0 else former * 3 + 1

    if later in temp:
        print(idx)
        break
    temp.append(later)
    former = later


Measured memory_bytes: 3064
n = int(input())
height_lst = list(map(int,input().split()))
move_lst = [0]
move = 0

for i in range(n-1):
    height1 = height_lst[i]
    height2 = height_lst[i+1]

    if height1>=height2:
        move += 1
        if i==n-2:
            move_lst.append(move)
    else:
        if move!=0:
            move_lst.append(move)
        move = 0

print(max(move_lst))

Measured memory_bytes: 14252
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<stack>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	string S;
	cin >> S;
	bool A = true;
	for(int i = 0;i < S.size();i++) {
		if(i % 2 == 0) {
			if(S.at(i) == 'L') {
				A = false;
			}
		}
		else {
			if(S.at(i) == 'R') {
				A = false;
			}
		}
	}
	if(A == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int calculateDigitSum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n = n / 10;
    }
    return sum;
}

int main() {
    int N;
    int A, B;

    std::cin >> N >> A >> B;

    int result = 0;
    for (int i = 1; i <= N; ++i) {
        int digitSum = calculateDigitSum(i);
        if ((A <= digitSum) && (digitSum <= B))
            result += i;
    }

    std::cout << result << std::endl;
    return 0;
}

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

vector<int> G[100001];
bool visited[100001];

int dfs(int v){
    int g=0;
    for(int i=0; i<G[v].size(); i++){
        if(visited[G[v][i]]==0){
            visited[G[v][i]]=1;
            g^=(dfs(G[v][i])+1);
        }
    }
    return g;
}

int main(){
    //input
    int N;
    cin >> N;
    int x,y;
    N--;
    while(N--){
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    //calc
    for(int i=0; i<=100000; i++){
        visited[i]=0;
    }
    visited[1]=1;
    int grundy=dfs(1);
    

    //output
    if(grundy!=0){
        cout << "Alice" << endl;
    }else{
        cout << "Bob" << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 13844
<?php

$A = trim(fgets(STDIN));
$B = trim(fgets(STDIN));
$C = trim(fgets(STDIN));
$X = trim(fgets(STDIN));
$count = 0;

for($i = 0; $i <= $A; $i++) {
  for($j = 0; $j <= $B; $j++) {
    for($k = 0; $k <= $C; $k++) {
      $total = (500 * $i) + (100 * $j) + (50 * $k);
      if($X == $total) {
        $count++;
        // echo "$i,$j,$k\n";
      }
    }
  }
}

echo "$count\n";
exit;
?>


Measured memory_bytes: 4856