akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int longestCommonSubsequence(string X, string Y) {
	int DP_memory[1000+1][1000+1]; //0~length??????
	int sizeX = X.length(); //0????????????????????????????????????????????????????????§???
	int sizeY = Y.length(); //???????????£???????????????
	X = " " + X;
	Y = " " + Y;
	for (int i = 0; i <= sizeX; i++)
		DP_memory[i][0] = 0;
	for (int i = 0; i <= sizeY; i++)
		DP_memory[0][i] = 0;

	for (int i = 1; i <= sizeX; i++) {
		for (int j = 1; j <= sizeY; j++) {
			if (X[i] == Y[j])
				DP_memory[i][j] = DP_memory[i - 1][j - 1] + 1;
			else if (DP_memory[i - 1][j] >= DP_memory[i][j - 1])
				DP_memory[i][j] = DP_memory[i - 1][j];
			else
				DP_memory[i][j] = DP_memory[i][j - 1];
		}
	}
	return DP_memory[sizeX][sizeY];
}

int main() {
	string lcsX[1000];
	string lcsY[1000];
	int setNum;

	cin >> setNum;
	for (int i = 0; i < setNum; i++) {
		cin >> lcsX[i];
		cin >> lcsY[i];

		int lcs = longestCommonSubsequence(lcsX[i], lcsY[i]);
		cout << lcs << endl;
	}
	return 0;
}

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


int main(){
    ll n;
    char ch[]={'z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y'};
    ll num[]={26, 702, 18278, 475254, 12356630, 321272406, 8353082582, 217180147158, 5646683826134, 146813779479510, 3817158266467286};
    cin>>n;

    ll digit=0;
    rep(i,11){
        if(num[i]>=n){
            digit=i+1;
            break;
        }
    }

    vector<ll> ans_;
    rep(i, digit){
        ans_.push_back(n%26);
        if(n%26==0) n=(n-1)/26;
        else n/=26;
    }

    // cout<<"===="<<endl;
    // rep(i,ans_.size()){
    //     cout<<ans_[i]<<endl;
    // }
    // cout<<"===="<<endl;

    string ans="";
    rep(i,digit){
        char tmp;
        tmp = ch[ans_[i]];
        ans = tmp+ans;
    }

        cout<<ans<<endl;

}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long n,k,i,j,f[2005][2005];
long long ksm(long long u,long long v){
	if(v<0)
		return 1;
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
int main(){
	//freopen("7.in","r",stdin);
    //freopen("7.out","w",stdout);
    n=read();k=read();
  	f[0][0]=1;
  	for(i=1;i<n;i++){
  		f[i][0]=f[i-1][0];
  		for(j=1;j<=i;j++)
  			f[i][j]=(f[i][j-1]+f[i-1][j])%mo;
  	}
  	pus(f[n-1][k-1]*ksm(2,n-k-1)%mo,2);
    return 0;
}

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

int N;
int field[100050];
bool visited[100050];

int solve()
{
	memset(visited, 0, sizeof(visited));

	queue<pair<int, int> > q;
	q.push(make_pair(0,0));

	while(1)
	{
		pair<int, int> p = q.front(); q.pop();
		int pos = p.first, cost = p.second;

		cost++;
		for(int i=1; i<=6; i++)
		{
			int tp = pos + i;
			if(tp >= N-1) return cost;

			while(1)
			{
				if(visited[tp]) break;
				if(field[tp] == 0) break;

				visited[tp] = true;

				tp += field[tp];
			}

			if(tp == N-1) return cost;

			if(!visited[tp])
			{
				visited[tp] = true;
				q.push(make_pair(tp, cost));
			}
		}
	}

	return -1;
}

int main()
{
	cin >> N;
	for(int i=0; i<N; i++)
		cin >> field[i];

	cout << solve() << endl;


}

Measured memory_bytes: 1208
#include <iostream>
#include <string>
#include <vector>

int main() {
  int N;
  size_t result;
  bool prev_yoko;

  std::string line;
  std::cin >> N >> line;

  for (int i = 0; i < N; i++) {
    bool yoko;
    if (i < N - 1) {
      yoko = line[i] == line[i + 1];
    } else {
      yoko = false;
    }
    if (i == 0) {
      if (yoko) {
        result = 6;
      } else {
        result = 3;
      }
    } else if (yoko) {
      if (prev_yoko) {
        result *= 3;
      } else {
        result *= 2;
      }
    } else {
      if (prev_yoko) {
        result *= 1;
      } else {
        result *= 2;
      }
    }
    if (yoko) {
      i++;
    }

    result %= 1000000007;
    prev_yoko = yoko;
  }
  std::cout << result << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define ANTHRO(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define ANTHRO(x...)
#endif


#define ll long long
#define MOD 1000000007
#define INF (int)1e9
#define EPS 1e-9
/*
    3.cpp
*/
#define cond (ll)2e5+17
/*vector<ll> fen(cond,0);
void upd(ll x,ll i){
    for(i++;i<cond;i+=(i-(&i))){
        fen[i]+=x;
    }
}
ll gs(ll i){
    ll ans=0;
    for(i++;i;i-=(i&(-i))){
        ans+=fen[i];
    }
    return ans;
}*/
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll k,n; cin>>k>>n;
    vector<ll> a(n),dif(n);//,ac(n+1,0),c(n+1,0);
    ll maxdif=-INF,s=0;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        /*if(a[i]>k/2){
            a[i]=a[i]-k;
        }*/
        if(i!=0){
            dif[i]=a[i]-a[i-1];
            maxdif=max(dif[i],maxdif);
            s+=dif[i];
        }
    }
    dif[0]=a[0]+(k-a[n-1]);
    maxdif=max(maxdif,dif[0]);
    s+=dif[0];
    //ANTHRO(dif,s);
    cout<<s-maxdif<<"\n";
    return 0;
}



Measured memory_bytes: 3328
while 1:
    try:
        data = list(map(str, input().split()))
    except EOFError:
        break

    numlist = []
    for d in data:
        if d == "+":
            val = float(numlist.pop(-2)) + float(numlist.pop(-1))
            numlist.append(val)
        elif d == "-":
            val = float(numlist.pop(-2)) - float(numlist.pop(-1))
            numlist.append(val)
        elif d == "*":
            val = float(numlist.pop(-2)) * float(numlist.pop(-1))
            numlist.append(val)
        elif d == "/":
            val = float(numlist.pop(-2)) / float(numlist.pop(-1))
            numlist.append(val)
        else:
            numlist.append(d)

    print(numlist[0])



Measured memory_bytes: 5576
//  ITP1_10_C
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
namespace you {
    std::string to_string(char val) {
        return std::string(1, val);
        // return std::string{val};
        // you::to_string(char)
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int n,s;
    cin>>n;
    while(n!=0){
        vector<int> score(n);
        double ave=0;
        for(int i=0;i<n;i++){
            cin>>s;
            ave+=s;
            score[i]=s;
        }
        ave=ave/n;
        double ans=0;
        for(int i=0;i<n;i++){
            ans+=pow((score[i]-ave),2);
        }
        //cout<<score<<endl;
        //cout<<ans<<endl;
        ans=sqrt(ans/n);
        cout<<ans<<endl;
        cin>>n;
    }
    return 0;
}


Measured memory_bytes: 3264
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
    int n;cin>>n;
    string s;cin>>s;
    ll r=count(s.begin(), s.end(), 'R');
    ll g=count(s.begin(), s.end(), 'G');
    ll b=count(s.begin(), s.end(), 'B');
    ll ans=r*g*b;
    for(int i=0;i<n-2;i++)for(int j=i+1;j<n-1;j++){
        int d=j-i;
        if(j+d>=n)break;
        else if(s[i]!=s[j]&&s[j]!=s[j+d]&&s[i]!=s[j+d])ans--;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
h,w,n=map(int,input().split())
import collections
tot=(h-2)*(w-2)
S=[]
append=S.append
for i in range(n):
  a,b=map(int,input().split())
  for j in range(3):
    for k in range(3):
      if 0<=a-3+j<h-2 and 0<=b-3+k<w-2:
        append((a-3+j,b-3+k))
SS=collections.Counter(collections.Counter(S).values())
print(tot-sum(SS.values()))
for i in range(1,10):
  print(0 if i not in SS.keys() else SS[i])

Measured memory_bytes: 156736
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    string s;
    cin>>s;
    if((s[0]==s[1] && s[1]==s[2]) || (s[1]==s[2] && s[2]==s[3]) || (s[0]==s[1] && s[1]==s[2] && s[2]==s[3]))
    cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

int A,B;
string huka = "-1";

int main(void){
    cin >> A >> B;
    
    if( A > 9 ){
        cout << huka << endl;
        return 0;
    }
        
    if( B > 9 ){
        cout << huka << endl;
        return 0;
    }
    
    cout << A * B << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void fast(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
}
long long find_it(long long n){
	if(n == 1){
		return 1;
	}
	return 1 + (2 * find_it(n /2));
}
int main(){
	fast();	
	long long h;
	cin >> h;
	cout << find_it(h) << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(ll i=0;i<n;i++){
    cin>>a[i];
  }
  int ans=0;
  sort(a.begin(),a.end());
  for(ll i=0;i<n;i++){
    for(ll j=i+1;j<n;j++){
      if(i==j){
        continue;
      }
      for(ll k=j+1;k<n;k++){
        if(a[i]==a[j]||a[j]==a[k]||a[i]==a[k]){
          continue;
        }
        if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i]){
          //printf("%lld %lld %lld\n",a[i],a[j],a[k]);
          ans++;
        }
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3628
using System;

class Program
{
  static void Main(string[] args)
  {
    int N = int.Parse(Console.ReadLine());
    int[] A = new int[N];
    int[] B = new int[N];
    int[] C = new int[N - 1];

    InsertArray(A);
    InsertArray(B);
    InsertArray(C);

    int manzoku = 0;
    int prevIndex = -2;

    for (int i = 0; i < N; i++)
    {
      int index = A[i];
      manzoku += B[index - 1];
      if(index == prevIndex + 1)
      {
        manzoku += C[index - 2];
      }
      prevIndex = index;
    }
    Console.WriteLine(manzoku);
  }

  static void InsertArray(int[] target)
  {
    string[] inputs = Console.ReadLine().Split(' ');
    for (int i = 0; i < target.Length; i++)
    {
      target[i] = int.Parse(inputs[i]);
    }
  }
}


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

using namespace std;

#define db(x) //cerr << #x << " = " << x << endl;
#define MAXN 3123 
#define ll long long
#define fi first
#define se second
#define pll pair<ll, ll>

int N;
int vals[MAXN];
int vis[MAXN][MAXN][2];
pll dp[MAXN][MAXN][2];

pll solve(int l, int r, int turn)
{
	if (l > r)
	{
		return {0, 0};
	}
	
	if (vis[l][r][turn])
	{
		return dp[l][r][turn];
	}
	vis[l][r][turn] = 1;
	
	pll left_rec = solve(l + 1, r, !turn);
	pll right_rec = solve(l, r - 1, !turn);
	pll res;
	
	if (turn == 0)
	{
		if (left_rec.fi + vals[l] > right_rec.fi + vals[r])
		{
			res = left_rec;
			res.fi += vals[l];
		}
		else
		{
			res = right_rec;
			res.fi += vals[r];
		}
	}
	else
	{
		if (left_rec.se + vals[l] > right_rec.se + vals[r])
		{
			res = left_rec;
			res.se += vals[l];
		}
		else
		{
			res = right_rec;
			res.se += vals[r];
		}
	}
	
	dp[l][r][turn] = res;
	return res;
}

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
	{
		scanf("%d", &vals[i]);
	}
	
	pll res = solve(0, N - 1, 0);
	printf("%lld\n", res.fi - res.se);
	
	return 0;
}


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



int main() {

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
   	string s;
   	cin>>s;
   	int longest = 0;
   	int ans = INT_MIN;
   	for(int i = 0; i < s.length(); i++) {
   		if(s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C') 
   			longest += 1;
   		else 
   			longest = 0;
   		ans = max(ans, longest);
   	}
   	cout<<ans;


	return 0;		
}


Measured memory_bytes: 256
///スマホコーディング
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
typedef long long ll;
const int inf=1e9;
int main(){
  int n,t; cin>>n>>t;
  int minv=inf;
  rep(i,0,n){
    int c,p; cin>>c>>p;
    if(p<=t)minv=min(minv,c);
  }
  if(minv==inf)cout<<"TLE"<<endl;
  else cout<<minv<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
H = input().split()
h = []
cnt = 0
for i in range(N):
  h.append(int(H[i]))

h1 = [0 for i in range(N)]
for i in range(N):
  h1[h[i] - 1] = i+1
  
      
str1 = map(str, h1)
str1 = " ".join(str1)
print(str1)

Measured memory_bytes: 24204
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)
const ll INF = 10010001010;
const int inf = 1000034000;
typedef vector<ll> vecl;
typedef vector<int> veci;
typedef tuple<string, int, int> TUP;

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

int main()
{
    int N;
    cin >> N;
    ll ans = 0;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> 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; i++)
    {
        cin >> C[i];
    }
    sort(all(A));
    sort(all(C));
    for (int i = 0; i < N;i++)
    {
        auto itA = lower_bound(A.begin(),A.end(),B[i]);
        auto itC = upper_bound(C.begin(), C.end(),B[i]);
        ll a = itA - A.begin();
        ll b = C.end() - itC;
        //cout << a <<" " << b << endl;
        ans += a * b;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4564
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main() {
  int n, l;
  cin >> n >> l;
  vector<pair<int, int>> pd(n);
  int i, j;
  for (i = 0; i < n; i++) {
    cin >> pd[i].first >> pd[i].second;
  }
  sort(pd.begin(), pd.end());
  long long score = 0, result = 0;
  for (i = 0; i < n; i++) {
    score += (pd[i].second ? -(pd[i].first - i - 1) : pd[i].first - i - 1);
    result = max(result, score);
  }
  for (i = n - 1; i >= 0; i--) {
    score += (pd[i].second ? l - n : -(l - n));
    result = max(result, score);
  }
  result = max(result, score);
  cout << result << endl;

  return 0;
}



Measured memory_bytes: 3536
require 'pp'
n = gets.to_i
a = gets.split.map(&:to_i).sort

# p a

y = a[-1]
# p y

x = a[0..-2].map{|xx| [y - xx, xx].min }.max

if a.include?(x)
  puts "#{y} #{x}"
else
  puts "#{y} #{y - x}"
end


Measured memory_bytes: 12904
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int p = sc.nextInt();

        int total_p = a*3 + p;
        int result = total_p / 2;
        
        System.out.println(result);
    }
}


Measured memory_bytes: 35580
#include<stdio.h>

using namespace std;

int main(){
    int a, b, c, d, e, k;
    scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &k);
    if(e-a <= k){
        printf("Yay!\n");
    }
    else{
        printf(":(");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

int add(int a, int b, int m = MOD){
	return a + b < m? a + b : a + b - m;
}

int mul(ll a, ll b, int m = MOD){
	return (a * b) % m;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 100000+5;

int n;
vi G[N];
int in[N];
int out[N];

void DFS(int u, int id, int p = 0){
	if(id == 0){
		in[u] = 1;
		for(int v : G[u]){
			if(v == p) continue;
			DFS(v, id, u);
			in[u] = mul(in[u], in[v] + 1);
		}
	}
	else{
		int sum = 1;
		for(int i=0; i<G[u].size(); i++){
			int v = G[u][i];
			if(v == p) continue;
			out[v] = sum;
			sum = mul(sum, in[v] + 1);
		}
		sum = 1;
		for(int i = G[u].size() - 1; i >= 0; i--){
			int v = G[u][i];
			if(v == p) continue;
			out[v] = mul(out[v], sum);
			sum = mul(sum, in[v] + 1);
		}
		for(int v : G[u]){
			if(v == p) continue;
			out[v] = mul(out[v], out[u]);
			out[v] = add(out[v], 1);
			DFS(v, id, u);
		}
	}
}

int main(){
	ri(n);
	rll(MOD);
	for(int i=1; i<n; i++){
		int u, v;
		ri2(u, v);
		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}
	DFS(1, 0);
	out[1] = 1;
	DFS(1, 1);
	for(int i=1; i<=n; i++){
		printf("%d\n",mul(in[i], out[i]));
	}
	return 0;
}

Measured memory_bytes: 11904
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll n;
  cin >> n;
  ll a[n];
  REP(i,n) cin >> a[i];
  ll b[n],c[n];
  ll sum_b[n], sum_c[n];
  b[0] = (a[0]>0) ? a[0] : 1;
  c[0] = (a[0]<0) ? a[0] : -1;
  sum_b[0] = b[0], sum_c[0] = c[0];
  for(ll i = 1; i < n; i++){
    if(i%2==0){
      b[i] = (sum_b[i-1]+a[i]>0) ? a[i] : -sum_b[i-1]+1;
      c[i] = (sum_c[i-1]+a[i]<0) ? a[i] : -sum_c[i-1]-1;
    }else{
      b[i] = (sum_b[i-1]+a[i]<0) ? a[i] : -sum_b[i-1]-1;
      c[i] = (sum_c[i-1]+a[i]>0) ? a[i] : -sum_c[i-1]+1;
    }
    sum_b[i] = sum_b[i-1]+b[i];
    sum_c[i] = sum_c[i-1]+c[i];
  }
  ll b_abs = 0, c_abs = 0;
  REP(i,n){
    b_abs+=abs(b[i]-a[i]);
    c_abs+=abs(c[i]-a[i]);
  }
  cout << min(b_abs,c_abs) << endl;
  return 0;
}


Measured memory_bytes: 4096
n = int(input())
p = list(map(int,input().split()))

ans = 0

for i in range(0,len(p)-2):
    if( (max(p[i],p[i+1],p[i+2]) != p[i+1]) and min(p[i],p[i+1],p[i+2]) != p[i+1] ):
        ans+=1

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,m;
        cin>>n>>m;
        ll h[n]={0};
        bool b[n]={0};
        for(ll i=0;i<n;i++)
            cin>>h[i];
        ll ab[m][2];
        for(ll i=0;i<m;i++)
        {
            cin>>ab[i][0]>>ab[i][1];
        }
        for(ll i=0;i<m;i++)
        {
            if(h[ab[i][0]-1]<h[ab[i][1]-1])
            {
                b[ab[i][0]-1] = 1;
            }
            else if(h[ab[i][0]-1]>h[ab[i][1]-1])
                b[ab[i][1]-1] = 1;
            else
            {
                b[ab[i][0]-1] = 1;
                b[ab[i][1]-1] = 1;
            }
        }
        //cout<<h[ab[4][0]-1]<<" "<<h[ab[4][1]-1]<<endl;
        ll c=0;
        for(ll i=0;i<n;i++)
        {
            //cout<<b[i]<<" ";
            if(b[i]==0)
             {
                 c++;

             }
        }
        cout<<c<<endl;
    }
    return 0;
}




Measured memory_bytes: 6072
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

#define N 100

using namespace std;

int main() {
    int n,l;
    scanf("%d%d", &n, &l);
    int a[n];
    int max_seq_2 = 0;
    int last_knot = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d",&a[i]);
    }
    int pair[n];
    for (int i = 0; i < n - 1; i++) {
        pair[i + 1] = a[i] + a[i+1];
        if (max_seq_2 < pair[i + 1]) {
            max_seq_2 = pair[i + 1];
            last_knot = i+1;
        }
    }
    if(l>max_seq_2)printf("Impossible\n");
    else {
        printf("Possible\n");
        for(int i=1;i<n;i++){
            if(i!=last_knot)printf("%d\n",i);
            else break;
        }
        for(int i=n-1;i>=last_knot;i--){
            printf("%d\n",i);
        }
    }
    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<cstdlib>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
ll a[maxn],r[maxn],l[maxn];
inline ll Pow2(int i){
    if(i<63) return 1ll<<i;
    else return 1e18;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0; i<=n; i++) cin>>a[i];
    ll ans=0;
    l[n+1]=0,r[n+1]=0;
    for(int i=n; i>=0; --i)
    {
        l[i]=l[i+1]/2+l[i+1]%2;
        r[i]=r[i+1];
        l[i]+=a[i];
        r[i]+=a[i];
        if(l[i]>Pow2(i))
        {
            cout<<-1<<endl;
            return 0;
        }
        r[i]=min(r[i],Pow2(i));
    }
    for(int i=1; i<=n-1; i++)
    {
        ll x=l[i-1],y=r[i-1];
        x-=a[i-1];
        y-=a[i-1];
        y=2*y;
        l[i]=max(l[i],x);
        r[i]=min(r[i],y);
    }
    for(int i=0; i<=n; i++)
    {
        ans+=r[i];
    }
    cout<<ans<<endl;
    return 0;
}


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

string a,b,c;

char game(int i, int j, int k, char turn){
	
	if(i == 0){
		if(a[i] == 'a') return game(i+1, j, k, 'a');
		if(a[i] == 'b') return game(i+1,j,k,'b');
		if(a[i] == 'c') return game(i+1,j,k,'c');
	}
	
	if(turn == 'a'){
		if(i == a.size()) return 'A';
		if(a[i] == 'a') return game(i+1, j, k, 'a');
		if(a[i] == 'b') return game(i+1, j, k, 'b');
		if(a[i] == 'c') return game(i+1, j, k, 'c');
	}
	
	if(turn == 'b'){
		if(j == b.size()) return 'B';
		if(b[j] == 'a') return game(i,j+1,k,'a');
		if(b[j] == 'b') return game(i,j+1,k,'b');
		if(b[j] == 'c') return game(i,j+1,k,'c');
 	}
	
	if(turn == 'c'){
		if(k == c.size()) return 'C';
		if(c[k] == 'a') return game(i,j,k+1,'a');
		if(c[k] == 'b') return game(i,j,k+1,'b');
		if(c[k] == 'c') return game(i,j,k+1,'c');
	}
}

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



Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define int long long
#define double long double
#define INF LLONG_MAX/1000
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int w, h, p, q;
signed main() {
	cin >> w >> h;
	prique<P, vector<P>, greater<P>> que;
	rep(i, w) {
		cin >> p;
		que.push(make_pair(p, 0));
	}
	rep(i, h) {
		cin >> q;
		que.push(make_pair(q, 1));
	}
	w++; h++;
	int ans = 0;
	while (!que.empty()) {
		P p = que.top();
		que.pop();
		if (p.second) {
			ans += p.first * w;
			h--;
		}
		else {
			ans += p.first * h;
			w--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


int main(){
	ll n,m;
	cin >> n >> m;
	if(n==1 && m==1){
		cout << 1 << endl;
	}else if(n==1){
		cout << m-2 << endl;
	}else if(m==1){
		cout << n-2 << endl;
	}else{
		cout << (n-2)*(m-2) << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  vector<int> dish=input(5);
  int sum1=0;
  rep(i,5){
    sum1 += dish[i];
  }
  
  rep(i,5){
    dish[i] %= 10;
    if(dish[i]!=0){
      dish[i] = 10-dish[i];
    }
  }
  sort(dish.begin(),dish.end());
  
  int sum2=0;
  rep(i,4){
    sum2 += dish[i];
  }
  
  cout << sum1+sum2 << endl;
}

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

const int maxn = 500010;
int n,D;
int d[maxn];
int a[maxn], b[maxn];

void pre()
{
	a[0] = D;
	for (int i=1;i<=n;i++)
	{
		if (a[i-1] <= d[i]/2) a[i] = a[i-1];
		else
		{
			if (a[i-1] >= d[i]) a[i] = a[i-1] - d[i];
			else a[i] = d[i] - a[i-1];
		}
	}
	b[0] = 1;
	for (int i=1;i<=n;i++)
	{
		if (d[n-i+1]/2 >= b[i-1]) b[i] = b[i-1];
		else b[i] = b[i-1] + d[n-i+1];
	}
}

int main()
{
	//freopen("E.in","r",stdin);
	scanf("%d%d",&n,&D);
	for (int i=1;i<=n;i++) scanf("%d",&d[i]);
	pre();
	
	int qnum;
	scanf("%d",&qnum);
	while (qnum--)
	{
		int q;
		scanf("%d",&q);
		if (a[q-1] >= b[n-q]) puts("YES");
		else puts("NO");
	}
	return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define retunr return
#define pb push_back
#define mp make_pair
#define null NULL
#define sc(x) scanf("%d", &x)
#define sc64(x) scanf("%I64d", &x)
#define pr(x) printf("%d", (x))
#define sp putchar(' ')
#define ln putchar('\n')
#define pr64(x) printf("%I64d", (x))
#define rep(i,l,r) for (int i = l, lim = r;i <= lim; ++i)
#define repr(i,l,r) for (int i = r, lim = l;i >= lim; --i)
#define fi first
#define se second
#define SET(__set, val) memset(__set, val, sizeof __set)
#define fill(a,v,n) memset((a),(v),sizeof(a[0])*(n))
#define copy(a,b,n) memcpy((a),(b),sizeof(a[0])*(n))
#define ALL(x) (x.begin(),x.end())
#define prf(x) printf("%.20f", x)
#define for_each_edge(u) for(int i = point[u];i;i=G[i].n)
typedef unsigned int uint;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define N 100010
#define M 1024
#define MOD 1000000007
void _add(int &a, int b){a = (a+b)%MOD;}
void _sub(int &a, int b){a = (a+MOD-b)%MOD;}
void _mul(int &a, int b){a = (ll)a*b%MOD;}
void _max(int &a, int b){a = max(a,b);}
void _min(int &a, int b){a = min(a,b);}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b,a%b);}
ll pw(ll a, ll b){ll res(1);while(b){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
ll pwM(ll a, ll b, ll mod){ll res(1);while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

const int infi = 2147483647;
const ll infl = 9223372036854775807ll;
const db PI = 3.14159265358979323846;

/*
struct E{
	int v, w, n;
}G[N];
int cnt, point[N];
void adde(int u, int v, int w = 0){
	G[++cnt]=(E){v,w,point[u]},point[u]=cnt;
	G[++cnt]=(E){u,w,point[v]},point[v]=cnt;
}
void Ginit(){
	cnt = 0;
	SET(point,0);
}
*/
/*
struct hh{
	int a, b;
	bool operator < (const hh &x) const{
		if(a==x.a)return b<x.b;
		return a<x.a;
	}
}a[N];
*/
int n, m, k,q;
char s[N];
int main(){
//	freopen("1", "r", stdin);
	scanf("%s", s+1);
	ll K;
	cin>>K;
	rep(i,1,strlen(s+1)){
		if(s[i]=='1'){
			K--;
			if(!K){
				pr(1),ln;return 0;
			}
		}
		else{
			pr(s[i]-'0'),ln;return 0;
		}
	}
/*
	int Case;
	sc(Case);
	rep(ca, 1, Case){
	    printf("Case #%d: ", ca);
	}
*/
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,h,dp[10010],a[10010],b[10010];


void solve(){
  cin >> h >> n;
  rep(i,n){
    cin >> a[i] >> b[i];
  }
  rep(s,h+1){
    dp[s]=100000000;
  }
  dp[0]=0;
  Rep(s,1,h+1){
    rep(i,n){
      dp[s]=min(dp[s],dp[max(s-a[i],0)]+b[i]);
    }
  }
  cout << dp[h] << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
#define INF 1000000000
#define M_INF -1000000000
typedef long long int ll;

int main(){
    ll n,k,flag=0,ich,ans=1e18;
    cin>>n>>k;
    vector<ll> v(n);
    for(ll i=0;i<n;i++){
        cin>>v[i];
        if(v[i]==0){//座標0にろうそくが存在するか
            flag=1;
            ich=i;
        }
    }
    for(ll i=0;i+k-1<n;i++){
        ll left=i,right=i+k-1;
        if((flag==1&&right==ich)||(flag==0&&v[left]<0&&v[right]<0)){
            ans=min(ans,abs(v[left]));
        }else if((flag==1&&left<ich&&ich<right)||(flag==0&&v[left]<0 && v[right]>0)){
            ll a=abs(v[left])+abs(v[left]-v[right]);
            ll b=abs(v[right])+abs(v[left]-v[right]);
            ans=min(ans,min(a,b));
        }else if((flag==1&&left==ich)||(flag==0&&v[left]>0)){
           ans=min(ans,v[right]);
        }
    }
    cout<<ans<<endl;
    return 0;
}
    

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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)

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

const int MAXN =  5e5 + 5;

ll ps[MAXN];
ll px[MAXN];

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

  REP(i, n) {
    int x; cin >> x;

    px[i + 1] = px[i] ^ x;
    ps[i + 1] = ps[i] + x;
  }

  ll sol = 0;
  FOR(i, 1, n + 1) {
    int lo = i, hi = n;
    while(lo < hi) {
      int mid = (lo + hi + 1) >> 1;

      if((px[mid] ^ px[i - 1]) < ps[mid] - ps[i - 1]) {
        hi = mid - 1;
      }
      else {
        lo = mid;
      }
    }
    sol += lo - i + 1;
  }

  cout << sol;
}


Measured memory_bytes: 5888
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long N, std::string S, std::string T){
    REP(i, N){
        cout << S[i]<<T[i];
    }
    cout << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(N, S, T);
    return 0;
}


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

int main(void) {
    long long int N, A,B,ans=0;
    cin >> N >> A >> B;

    long long int tmp1,tmp2,tmp3;

    tmp1 = N/(A+B);
    tmp2 = N -tmp1*(A+B); //残りのA,B
    if(tmp2-A<0)
     ans = tmp1*A + tmp2;
     else{
    tmp3 = tmp2-A; // Bの数
    ans = tmp1*A + tmp2-tmp3;
}

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import math
N, M = map(int, input().split())
if N >= 2:
  pn = math.factorial(N) // math.factorial(N - 2)
else:
  pn = 0
if M >= 2:
  pm = math.factorial(M) // math.factorial(M - 2)
else:
  pm = 0
total = pn // 2 + pm // 2
print(total)

Measured memory_bytes: 3060
from itertools import product

x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

AB = []
for (a, b) in product(A, B):
	AB.append(a + b)

AB.sort(reverse=True)

res = []
for (ab, c) in product(AB[:min(3000, x*y*z)], C):
	res.append(ab + c)

res.sort(reverse=True)

for i in range(k):
	print(res[i])

Measured memory_bytes: 152256
def main():
  s=input()
  if(s=='SUN'):
    print(7)
  elif(s=='MON'):
    print(6)
  elif(s=='TUE'):
    print(5)
  elif(s=='WED'):
    print(4)
  elif(s=='THU'):
    print(3)
  elif(s=='FRI'):
    print(2)
  else:
    print(1)
    
main()

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

using namespace std;

int main()
{
    long long int n,i,c=0,total=0,j;
    cin>>n;
    if(n==1)
        cout<<"0";
    else{for(i=2;i*i<=n;i++)
        {c=0;
            while(n%i==0)
            {
                n/=i;
                c++;
            }
            for(j=1;;j++)
            {
                if(c<j)
                    break;
                else
                {
                    total++;
                    c=c-j;
                }
            }
        }
        if(n!=1)
            cout<<total+1;
        else
            cout<<total;

    }

}


Measured memory_bytes: 3644
#include <cstdio>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    typedef complex<double> C;
    double eps = 1e-9;

    while (true)
    {
        int n;
        scanf("%d", &n);
        if (n==0)
            break;

        vector<C> P;
        for (int i=0; i<n; i++)
        {
            double re, im;
            scanf("%lf,%lf", &re, &im);
            P.push_back(C(re,im));
        }

        int ans = 1;

        for (auto p1: P)
        for (auto p2: P)
        if (p1!=p2)
        {
            double d = abs(p1-p2);
            if (d<2)
            {
                C t = C(d/2,sqrt(1-d*d/4))*(p2-p1)/abs(p2-p1)+p1;
                //printf("%f %f\n", t.real(), t.imag());

                if (0<t.real() && t.real()<10 &&
                    0<t.imag() && t.imag()<10)
                {
                    int c = 0;
                    for (auto p: P)
                        if (abs(p-t)<1+eps)
                            c++;
                    ans = max(ans, c);
                }
            }
        }

        printf("%d\n", ans);
    }
}

Measured memory_bytes: 2724
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

from collections import deque

def main():
	h,w,m=MI()
	A=[0]*(h+1)
	B=[0]*(w+1)
	C=[[] for _ in range(h+1)]

	for _ in range(m):
		hh,ww=MI()
		A[hh]+=1
		B[ww]+=1
		C[hh].append(ww)


	for i in range(h+1):
		C[i].sort()

	AA=max(A)
	BB=max(B)

	x=[]
	y=[]

	for i,v in enumerate(A):
		if v==AA:
			x.append(i)

	for i,v in enumerate(B):
		if v==BB:
			y.append(i)

	#print(x,y,AA,BB)
	#print(C)
	ans=0

	for i in x:
		C[i].append(10**7)
		#print("a")
		#print(C[i])
		#print(y)
		a=0
		for j in y:
			while a<len(C[i]):
				if j==C[i][a]:
					a+=1
					break
				elif j<C[i][a]:
					print(AA+BB)
					exit()
				else:
					a+=1

	print(AA+BB-1)
















if __name__ == "__main__":
	main()


Measured memory_bytes: 151144
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = n-1; i > 0; i--)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl((ld)1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

bool solve(){
  ll n,k;cin>>n>>k;
  ll ans=0;
  if(k==0){
    cout<<n*n<<endl;
    return false;
  }
  for(ll b=1;b<=n;b++){
    if(b<=k)continue;
    ans+=n/(b)*(b-k);
    ans+=max((ll)0,n%b-k+1);
    // cout<<b<<" "<<ans<<endl;
  }
  cout<<ans<<endl;
  return false;
}


signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
	return solve();
}


Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,x,t=1;
int main(){
    cin>>n>>x;
    if(x==1||x==2*n-1){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    for(int i=1;i<n-1;i++){
        while(t==x||t==x-1||t==x+1) t++;
        cout<<t++<<endl;
    }
    cout<<x-1<<endl<<x<<endl<<x+1<<endl;
    for(int i=1;i<n-1;i++){
        while(t==x||t==x-1||t==x+1) t++;
        cout<<t++<<endl;
    }
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>

using namespace std;
int main() 
{
	int n, k;
	string s;
	cin >> n >> s >> k;
	
	char str = s[k - 1];

	for (int i = 0; i < n; i++) {
		if(s[i] != str){
			s[i] = '*';
		}
	}
	cout << s << endl;	
}

Measured memory_bytes: 256
for e in iter(input,'0 0'):
 N,M=map(int,e.split())
 k,p=1,0
 S=[int(input()) for _ in[0]*N]
 for d in[int(input())for _ in[0]*M]:
  p+=d if N<=p+d else d+S[p+d]
  if N<=p+1:break
  k+=1
 print(k)


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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr ll mod = static_cast<ll>(1e9 + 7);

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

    std::cin >> n;

    double sum = 0;
    for (int i = 0; i < n; ++i) {
        int a;
        std::cin >> a;

        sum += 1.0 / a;
    }

    std::cout << std::fixed << std::setprecision(10) << 1.0 / sum << std::endl;

    return 0;
}


Measured memory_bytes: 256
import math


n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
x_b = 1
y_b = 1
for i in range(b):
    x_b = x_b * (n - i) % mod
    y_b = y_b * (i + 1) % mod
    if i == a - 1:
        x_a = x_b
        y_a = y_b
z_a = x_a * pow(y_a, mod - 2, mod)
z_b = x_b * pow(y_b, mod - 2, mod)
print((pow(2, n, mod) - 1 - z_a - z_b) % mod)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define lw(vc,num) lower_bound(vc.begin(), vc.end(), num) - vc.begin();
#define hg(vc,num) upper_bound(vc.begin(), vc.end(), num) - vc.begin();
#define bn(v,x) binary_search (v.begin(), v.end(), x)
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool isprime(int n)
{
    if(n == 1) return false;
    if(n == 2 || n == 3) return true;
    if(n%2 == 0 || n%3 == 0) return false;
    for(int i=5; i*i<=n; i+=6){
        if((n%i == 0)||(n%(i+2) == 0)) return false;
    }
    return true;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
ll ncr(ll x, ll y) {
	ll ans = 1;
	for (ll i = 1; i <= y; ++i) {
		ans *= (x - y + i);
		ans /= i;
	}

	return ans;
}
int main()
{
    fio;
 ll a,b,k;
	cin>>a>>b>>k;
	if(a+b<=k)
	{
		cout<<"0"<<" "<<"0";
	}
  else if(k>=a)
	{
		k = k-a;
		a = 0;
		b = abs(k-b);
		cout<<"0"<<" "<<b;
	}
	else
	{
		a = a-k;
		cout<<a<<" "<<b;
	}
    return 0;
}



Measured memory_bytes: 3656
use List::Util 'sum';

@r = ();
while(<>){
	chomp;
	if($. == 1){
		($n, $m) = split(/ /, $_);
	}elsif($. == 2){
		@h = ("", split(/ /, $_));
		@r = map { "1" } @h;
	}else{
		($a, $b) = split(/ /, $_);
		if($h[$a] == $h[$b]){
			$r[$a] = 0;
			$r[$b] = 0;
		}elsif($h[$a] > $h[$b]){
			$r[$b] = 0;
		}else{
			$r[$a] = 0;
		}
	}
}

printf (sum(@r) - 1) . "\n";


Measured memory_bytes: 29228
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll x, y, z;std::cin >> x >> y >> z;
  cout << max((ll)0, (x-z)/(y+z)) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,n) cin>>v[i];//価値を入力v[0]から入力
    sort(v.begin(),v.end());//小さい順にします
    double ans=v[0];//v[0]を起点に1,2,3,4,5,で処理
    for(int i=1; i<n; i++) ans=(ans+v[i])/2;
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    long n;cin>>n;
    vector<long> W(n);
    long sum=0;
    for(long i=0;i<n;i++){
        cin>>W.at(i);
        sum+=W.at(i);
    }
    long s=sum;
    long ans=10000000000000;
    for(long i=0;i<n;i++){
        s-=2*W.at(i);
        ans=min(ans,abs(s));
    }    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
    int n, m, d; cin >> n >> m >> d;
    double e = (d != 0) ? 2.0 * (n-d) : n;
    e /= n;
    e = (e/n) * (m-1);
    printf("%.9lf\n", e);
    return 0;
}

Measured memory_bytes: 256
def main():
    S = input()
    before_c = None
    cnt = 0
    for c in S:
        c = int(c)
        if before_c == c:
            before_c = 1 - c
            cnt += 1
        else:
            before_c = c
    print(cnt)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
// B.

#include <iostream>
#include <sstream>

using namespace std;

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	bool three = true;
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		if (s == "Y") {
			three = false;
		}
	}
	cout << (three ? "Three" : "Four") << endl;
	return 0;
}


Measured memory_bytes: 256