akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

ll N, M;
vector<ll> X;

const ll base = 100001;

signed main()
{
    cin >> N >> M;
    X.resize(M);
    REP(i, M) {
        cin >> X[i];
        X[i] += base;
    }
    SORT(X);

    if(N >= M) {
        printf("0\n");
        return 0;
    }

    // first: 間隔の大きさ second: 左インデックス
    vector< pair<ll, ll> > interval;
    REP(i, M-1) {
        interval.push_back(make_pair(X[i+1] - X[i], i));
    }
    sort(interval.begin(), interval.end(), greater< pair<ll, ll> >());
    // 間隔がでかいやつを N-1 個選ぶ
    vector<ll> choise;
    REP(i, N-1) {
        choise.push_back(interval[i].second);
    }
    choise.push_back(M-1);
    choise.push_back(-1);
    SORT(choise);

    ll ans = 0;
    for(int i = 1; i < choise.size(); ++i) {
        ans += X[choise[i]] - X[choise[i-1] + 1];
    }
    printf("%lld\n", ans);

    return 0;
}


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

ll n, x, s, a[105];

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

	cin >> n >> x;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	sort(a, a+n);

	for (int i = 0; i < n; ++i) {
		int t = a[i];
		s += t;
		if (s > x) {
			cout << i << endl;
			return 0;
		}
	}

	if (s == x) {
		cout << n << endl;
		return 0;
	} else {
		cout << n-1 << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long long n,a[200010],ans=0;
	cin>>n>>a[0];
	for(int i=1;i<n;i++)
	{
		cin>>a[i];
		if(a[i]<a[i-1])
		{
			ans+=(a[i-1]-a[i]);
			a[i]=a[i-1];
		}
	}
	cout<<ans<<"\n";	
	return 0;
}

Measured memory_bytes: 5088
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct Edge{
  int to;int cost;
  Edge(int t,int c):to(t),cost(c){};
};

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n,m,p;
  cin>>n>>m>>p;
  std::vector<Edge> node[2501];
  for(int i=0;i<m;i++){
    int a,b,c;
    cin>>a>>b>>c;
    node[a].push_back(Edge(b,c-p));
  }
  int maxcost[2501]={};
  const int INF=-INT32_MAX/3;
  for(int i=2;i<=n;i++){
    maxcost[i]=INF;
  }
  for(int loop=1;loop<=2*n;loop++){
    for(int from=1;from<=n;from++){
      for(auto e:node[from]){
        if(e.to==n){
          if(loop>=n&&maxcost[e.to]<maxcost[from]+e.cost){
            cout<<-1<<endl;
            return 0;
          }
        }

        maxcost[e.to]=std::max(maxcost[e.to],maxcost[from]+e.cost);

      }
    }
  }
  cout<<std::max(maxcost[n],0)<<endl;


  return 0;
}


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

int main(){
	ios::sync_with_stdio(false);
	
	int N,M; cin>>N>>M;
	vector<set<int>> frend(N+1,set<int>());
	rep(i,M){
		int a,b; cin>>a>>b;
		frend[a].insert(b);
		frend[b].insert(a);
	}

	vector<int> pe(N+1,0);
	int ans=0;
	for(int i=1; i<=N; i++){
		if(pe[i]==1) continue;
		queue<int> que;
		set<int> ch;
		ch.insert(i);
		que.push(i);
		while(!que.empty()){
			int q = que.front(); que.pop();
			for(int x:frend[q]){
				if(ch.count(x)) continue;
				ch.insert(x);
				que.push(x);
				pe[x]=1;
			}
		}
		// for(int x:ch){
		// 	cerr << x << " ";
		// }cerr<<endl;
		
		int t = ch.size();
		ans = max(ans,t);
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 41628
#include <bits/stdc++.h>
using namespace std;
int main(){
  long n,a;
  cin >> n;
  long x = n,k=0,l=0;
  while(x>0){
      a = x%10;
      x /= 10;
      k++;
  }
  if((n+1)%long(pow(10,k-1))==0) cout << 9*(k-1)+a << endl;
  else cout << 9*(k-1)+a-1 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n;
	while(~scanf("%d",&n)){
        int a[100],sum=0;
        for(int i=0;i<n;i++)
            scanf("%d",a+i);
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                sum+=a[i]*a[j];
            }
        }
        printf("%d\n",sum);
	}
}


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



int main(){
    int n,m,p,i;
    while( cin >> n >> m >> p, n||m||p ){
        m--;
        int x[100], sum=0;
        for(i=0;i<n;i++){
            cin >> x[i];
            sum += x[i] * 100;
        }
        cout << (x[m]?sum*(100-p)/100/x[m]:0) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
#define INF -99999999 
using namespace std;
 
int main()
{
    int N,K; cin >> N >> K;
    int a[200000] = {0};
    for (int i = 0; i < N; i++)
    {
        int A; cin >> A;
        a[A-1]++;
    }
    int sy = 0;
    for (int i = 0; i < 200000; i++)
    {
        if(a[i] != 0) sy++;
    }
    if(sy<=K) cout << 0 << endl;
    else{
        int ans = 0;
        sort(a,a+200000);
        for (int i = 0; i < 200000; i++)
        {
            if(a[i]==0) continue;
            else{
                ans += a[i];
                sy--;
                if(sy<=K){
                    cout << ans << endl;
                    return 0;
                }
            }
        }
        
    }

}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	static int bord[][];
	static int mx[]={-1,0,1,0,-1,-1,1,1};
	static int my[]={0,-1,0,1,-1,1,1,-1};
	static int count,w,h;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int i,j;
		while(true){
			count=0;
			w=sc.nextInt();
			h=sc.nextInt();
			if(w+h==0) break;
			bord=new int[w][h];
			for(i=0;i<h;i++){
				for(j=0;j<w;j++){
					bord[j][i]=sc.nextInt();
				}
			}

			for(i=0;i<h;i++){
				for(j=0;j<w;j++){
					if(bord[j][i]==1){
						bord[j][i]=0;
						count++;
						dfs(j,i);
					}
				}
			}
			System.out.println(count);
		}

	}
	static void dfs(int x,int y){
		int i,nx,ny;
		for(i=0;i<8;i++){
			nx=x+mx[i];
			ny=y+my[i];
			if(0<=nx && nx<w && 0<=ny && ny<h && bord[nx][ny]==1){
				bord[nx][ny]=0;
				dfs(nx,ny);
			}
		}
	}
}

Measured memory_bytes: 12000
import scala.io.StdIn.readLine

object Main extends App {
  val Array(x1,y1,x2,y2) = readLine.split(" ").map(_.toDouble)

  printf("%.8f\n",Math.sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) ))
}

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

int main() {
    ll x;
    cin >> x;
    if (x % 11 == 0) {
        cout << (x / 11) * 2 << endl;
    }
    else if (x % 11 <= 6) {
        cout << (x / 11) * 2 + 1 << endl;
    }
    else {
        cout << (x / 11) * 2 + 2 << endl;
    }
}



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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if (a+b==c || b+c==a || c+a==b) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const long double EPS = 1E-10;

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



int main(){
    int K, S; std::cin >> K >> S;
    int cnt(0);
    {
        int Z;
        for(int X(0); X <= K; ++X){
            for(int Y(0); Y <= K; ++Y){
                Z = S - X - Y;
                if(0 <= Z && Z <= K) ++cnt;
            }
        }
    }
    std::cout << cnt << std::endl;
    return 0;
}


Measured memory_bytes: 256
#import pysnooper
#import numpy
#import os,re,sys,operator
from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6)
input=stdin.readline

def main():
    n=int(input().rstrip())
    d=dict()
    for _ in range(n):
        s=input().rstrip()
        if s not in d: d[s]=1
        else: d[s]+=1
    ans=Counter(d).most_common()
    ans.sort(key=lambda x: (-x[1],x[0]))
    ma=ans[0][1]
    for i in ans:
        if i[1]!=ma: break
        print(i[0])

if __name__=="__main__":
    main()

Measured memory_bytes: 59480
MOD = 998244353
N, K = map(int, input().split())
kukan = [list(map(int, input().split())) for _ in range(K)]
step = [0 for _ in range(K)]
ans = [0] * (2 * N)
ans[N] = 1
for i in range(N):
    for k in range(K):
        step[k] += (ans[N + i - kukan[k][0]] - ans[N + i - kukan[k][1] - 1])
    ans[N + i] += sum(step) % MOD
print(ans[-1])



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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n,ans=0;
    cin>>n;
    Vi a(n);
    REP(i,0,n) cin>>a[i];
    ans+=a[0];
    ans+=a[n-2];
    REP(i,0,n-2){
        ans+=min(a[i],a[i+1]);
    }
    cout<<ans<<endl;
    return 0;
}


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

int M, N, K;
int Js[1010][1010];
int Os[1010][1010];
int Is[1010][1010];

using namespace std;

int main(void){
	scanf("%d %d\n", &M, &N);
	scanf("%d\n", &K);

	char c;

	for(int j = 1;j <= M;++j){
		for(int i = 1;i <= N;++i){
			scanf("%c", &c);
			if(c == 'J'){
				Js[j][i] = Js[j][i-1] + 1;
				Os[j][i] = Os[j][i-1];
				Is[j][i] = Is[j][i-1];
			}
			if(c == 'O'){
				Os[j][i] = Os[j][i-1] + 1;
				Js[j][i] = Js[j][i-1];
				Is[j][i] = Is[j][i-1];
			}
			if(c == 'I'){
				Is[j][i] = Is[j][i-1] + 1;
				Js[j][i] = Js[j][i-1];
				Os[j][i] = Os[j][i-1];
			}
		}
		getchar();
	}

	for(int i = 0;i < K;++i){
		int n, w, s, e, jc=0, oc=0, ic=0;
		scanf("%d %d %d %d", &n, &w, &s, &e);
		for(int j = n;j <= s;++j){
			jc += Js[j][e] - Js[j][w-1];
			oc += Os[j][e] - Os[j][w-1];
			ic += Is[j][e] - Is[j][w-1];
		}
		printf("%d %d %d\n", jc, oc, ic);
	}

	return 0;
}


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

int N;

double DP[3000][3000];
double chance[3000];

double solve(){
	double ret=0;
	for(int i=0;i<=N;i++){
		for(int j=0;j<=N;j++){
			DP[i][j]=0.0;
		}
	}
	DP[0][0]=1.0;
	for(int i=1;i<=N;i++){
		for(int j=0;j<=i;j++){
			int x=i-j;
			if(j){
				DP[x][j]+=DP[x][j-1]*(1-chance[i]);// this round gets tail
			}
			if(x){
				DP[x][j]+=DP[x-1][j]*chance[i];//this round gets head
			}
		}
	}
	
	int l=0,r;
	r=(N/2);
	if(N%2) r++;
	while(l<r){
		ret+=DP[N-l][l];
		l++;
	}
	
	return ret;
}

int main(){
	cin>>N;
	for(int i=1;i<=N;i++){
		cin>>chance[i];
	}
	printf("%.10lf",solve());
	return 0;
}

Measured memory_bytes: 70528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  string s; cin >> s;
  int n = s.size();
  int fa = 0;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A') {
      fa++;
      continue;
    }
    if (i + 1 == n) break;
    if (s[i] == 'B' && s[i + 1] == 'C') {
      ans += fa;
      i++;
    } else {
      fa = 0;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3756
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
string a;
int main()
{
	int sum=0;
    cin>>a;
    if(a[0]!='C') sum++;
    if(a[1]!='O') sum++;
    if(a[2]!='D') sum++;
    if(a[3]!='E') sum++;
    if(a[4]!='F') sum++;
    if(a[5]!='E') sum++;
    if(a[6]!='S') sum++;
    if(a[7]!='T') sum++;
    if(a[8]!='I') sum++;
    if(a[9]!='V') sum++;
    if(a[10]!='A') sum++;
    if(a[11]!='L') sum++;
    if(a[12]!='2') sum++;
    if(a[13]!='0') sum++;
    if(a[14]!='1') sum++;
    if(a[15]!='6') sum++;
    printf("%d\n",sum);
    return 0;
}

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

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

        if (k <= a) cout << k;
        if (k > a && k <= a + b) cout << a;
        if (k > a + b) cout << a - (k - (a + b)); 
        return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<pair<long long, long long>> xys(N);
    set<long long> xset;
    set<long long> yset;
    for (int i = 0; i < N; ++i){
        cin >> xys[i].first >> xys[i].second;
        xset.insert(xys[i].first);
    }
    vector<long long> xs(begin(xset), end(xset));
    long long ans = 9e18;
    for (auto xfirst = begin(xs); xfirst != end(xs); ++xfirst){
        for (auto xlast = xfirst; xlast != end(xs); ++xlast){
            vector<long long> candidates;
            for (auto xy : xys){
                long long x = xy.first;
                long long y = xy.second;
                if (x >= *xfirst and x <= *xlast) candidates.push_back(y);
            }
            long long x_span = *xlast - *xfirst;
            sort(begin(candidates), end(candidates));
            for (int head = 0; head + K <= candidates.size(); ++head){
                int tail = head + K - 1;
                ans = min(ans, (candidates[tail] - candidates[head]) * x_span);
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if ((i < b) ^ (j < a)) {
        cout << '1';
      } else {
        cout << '0';
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
#define fs first
#define sc second

const int nmax = 100;
int t = 1;
int a, b;

void INPUT()
{
     cin >> a >> b;
}

void INIT()
{

}

void SOLVE()
{
     int tmp = a - b * 2;
     if(tmp > 0) cout << tmp;
     else cout << 0;
}

int main()
{
    //freopen("test.inp","r",stdin);
    INPUT();
    INIT();
    while (t--) SOLVE();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define ll long long

int main(){
	ll a, b, k;
	scanf("%lld%lld%lld", &a, &b, &k);
	ll num = 0;
	while (k--)
	{
		if (num % 2)
		{
			a += b / 2;
			b = b / 2;
		}
		else
		{
			b += a / 2;
			a = a / 2;
		}
		++num;
	}
	printf("%lld %lld\n", a, b);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct data_t {
	int ID;
	int time;
	int ac;

	bool operator<(const data_t& right) const {
		if (ac == right.ac) {
			if (time == right.time) {
				return (ID > right.ID);
			}
			else {
				return (time < right.time);
			}
		}
		else {
			return (ac > right.ac);
		}
	}
};

int main(void) {
	int M,T,P,R;
	while (cin >> M >> T >> P >> R, M) {
		vector<data_t> data(T);
		for (int i = 0; i < T; ++i) {
			data[i].ID = i+1;
			data[i].time = 0;
			data[i].ac = 0;
		}

		int m,t,p,judge;
		vector< vector<int> > wrong(T,vector<int>(P,0));
		for (int i = 0; i < R; ++i) {
			cin >> m >> t >> p >> judge;
			if (judge != 0) {
				++wrong[t-1][p-1];
			}
			else {
				++data[t-1].ac;
				data[t-1].time += m + (20 * wrong[t-1][p-1]);
			}
		}
		sort(data.begin(),data.end());
		for (int i = 0; i < T; ++i) {
			cout << data[i].ID;
			if (i < T-1) {
				if (data[i].ac == data[i+1].ac && data[i].time == data[i+1].time) {
					cout << "=";
				}
				else {
					cout << ",";
				}
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3144
N = int(input())
T = [int(i) for i in input().split()]
M = int(input())
PX = [tuple(map(int,input().split())) for i in range(M)]

for i in range(M):
    ans = 0
    ex = PX[i][0]-1
    ans += PX[i][1]
    for j in range(N):
        if j != ex:
            ans += T[j]
    print(ans)

Measured memory_bytes: 3064
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main implements Runnable {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        int n = sc.nextInt(), x = sc.nextInt();
        int[] c = new int[n + 1];
        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
        }
        c[n] = x;
        c = sortDescending(c);

        int[] diff = new int[n];
        for (int i = 0; i < n; i++) {
            diff[i] = c[i] - c[i + 1];
        }
        System.out.println(gcd(diff));
    }

    private static int gcd(int[] c) {
        return Arrays.stream(c)
                .mapToObj(BigInteger::valueOf)
                .reduce(BigInteger::gcd)
                .orElse(BigInteger.ZERO)
                .intValue();
    }

    private static int[] sortDescending(int[] array) {
        return IntStream.of(array).boxed()
                .sorted(Comparator.reverseOrder())
                .mapToInt(Integer::intValue)
                .toArray();
    }
}


Measured memory_bytes: 67348
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,M,answer;
  cin >> N;
  vector<string> plus(N);
  for(int i=0;i<N;i++){
    cin >> plus.at(i);
  }
  cin >> M;
  vector<string> minus(M);
  for(int i=0;i<M;i++){
    cin >> minus.at(i);
  }
  int S,T;
  string A;
  for(int i=0;i<N;i++){
    A = plus.at(i);
    for(int j=0;j<N;j++){
      if(A == plus.at(j)){
        S++;
      }
    }
    for(int j=0;j<M;j++){
      if(A == minus.at(j)){
        T++;
      }
    }
    if(S-T>answer){answer = S-T;}
    S=0;
    T=0;
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <stack>

using namespace std;

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;

const int N = 2e5 + 10;

char s[N];
int main() {
  scanf("%s", s);
  stack<char> A;
  for (int i = 0; s[i]; ++i) {
    if (s[i] == 'S') {
      A.push(s[i]);
    } else {
      if (!A.empty() && A.top() == 'S') {
        A.pop();
      } else {
        A.push(s[i]);
      }
    }
  }
  printf("%d\n", A.size());
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
    using namespace std;
    #define mod 1000000000000000000
    #define MOD 		1000000007
    #define ll long long
    #define mp 		make_pair
    #define pb 		push_back
    #define forn(i,n) 	for(ll i=0;i<n;i++)
    #define for1(i,n) 	for(ll i=1;i<=n;i++)
    #define forn1(i,n) 	for(int i=1;i<n;i++)
    #define rep(i,x,n)  for(ll i=x;i<=n;i++)
    #define repr(i,x,j) for(ll i=x;i>=j;i--)
    #define vi vector<ll>
    #define mii map<ll,ll>
    #define vii vector<pair<int,int>>
    #define vvi vector<vector<ll>>
    #define pii pair<ll,ll>
    #define F first
    #define S second
    #define fill(a,x) memset(a,x,sizeof a);
    #define all(x) x.begin(),x.end()
    #define test ll t;cin>>t;while(t--)
    #define yes cout<<"YES"<<endl
    #define no cout<<"NO"<<endl
    #define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define R return 0
    ll flag[10000];
    int main()
    {
    	IOS;
        ll n,a;
        mii cnt;
        cin>>n;
        forn(i,n)
        {
            cin>>a;
            cnt[a]++;
        }
        ll ans=0;
        for(auto u:cnt)
        {
            if(u.S>=u.F) ans+=u.S-u.F;
            else
            ans+=u.S;
        }
        cout<<ans<<endl;
        R;
    }


Measured memory_bytes: 9472
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}

ll N,A,B,C;
 vector<ll>l;

ll dfs(ll a,ll b,ll c,ll d){
  if(d==N){
    if(min(min(a,b),c)==0){
      return INF;
    }
else{
return abs(A-a)+abs(B-b)+abs(C-c)-30;
}

  }

  ll MP1=dfs(a+l[d],b,c,d+1)+10;//dfsの中に数字を蓄えてるイメージ
  ll MP2=dfs(a,b+l[d],c,d+1)+10;//dfsを生成
  ll MP3=dfs(a,b,c+l[d],d+1)+10;
  ll MP4=dfs(a,b,c,d+1);
  
  return min(min(MP1,MP2),min(MP3,MP4));//深さdにおける最小値なためほぼ最終項に適用されると言って良い
  
}
int main(){
  
 
  cin>>N>>A>>B>>C;
  
   l.resize(N);// cin>>l[i]の前にやらなければならない。これはlの大きさがNでなければDFSが止まらないためNを取得している
  rep(i,N){
    cin>>l[i];
  }
  
  
  cout<<dfs(0,0,0,0)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> X(n), Y(n), P(n);
  rep(i, n) cin >> X[i] >> Y[i] >> P[i];
  vector<vector<ll>> xmin(1<<n, vector<ll>(n)), ymin(1<<n, vector<ll>(n));
  rep(i, 1<<n) {
    rep(j, n) {
      xmin[i][j] = abs(X[j]);
      ymin[i][j] = abs(Y[j]);
    }
    rep(k, n) {
      if((i>>k)&1) {
        rep(j, n) {
          xmin[i][j] = min(abs(X[j]-X[k]), xmin[i][j]);
          ymin[i][j] = min(abs(Y[j]-Y[k]), ymin[i][j]);
        }
      }
    }
  }
  vector<ll> ans(n+1, longinf);
  auto dfs = [&](auto dfs, int i, ll xb, ll yb) -> void {
    if(i == n) {
      ll cost = 0;
      rep(j, n) cost += P[j] * min(xmin[xb][j], ymin[yb][j]);
      int cnt = __builtin_popcount(xb) + __builtin_popcount(yb);
      if(cnt > n) return;
      ans[cnt] = min(cost, ans[cnt]);
      return;
    }
    dfs(dfs, i+1, xb, yb);
    dfs(dfs, i+1, xb|(1<<i), yb);
    dfs(dfs, i+1, xb, yb|(1<<i));
  };
  dfs(dfs, 0, 0, 0);

  /* dummy */
  vector<ll> pw(n+1);
  pw[0] = 1;
  rep(i, n) pw[i+1] = pw[i] * 3;
  rep(i, pw[n]) {
    ll x = 0, y = 0;
    rep(j, n) {
    }
    ll cur = 0;
    rep(j, n) cur += P[j] * min(xmin[x][j], ymin[y][j]);
    int cnt = __builtin_popcount(x) + __builtin_popcount(y);
    if(cnt > n) continue;
  }
  /* dummy */

  rep(i, n+1) cout << ans[i] << "\n";
  return 0;
}


Measured memory_bytes: 12860
n = int(input())

a = list(map(int,input().split()))

a.sort(reverse=True)

ans = 0

ans += a[0]

for i in range(1, int(len(a)/2)):
    ans += a[i] * 2

if len(a) % 2 == 0:
    print(ans)
else:
    print(ans + a[int(len(a)/2)])

Measured memory_bytes: 94284
#include <iostream>
#include <cstdio>
using namespace std;
//#define B
#define B



#ifdef B
const double PI = 3.141592653589;
int main(void)
{
	double r;
	cin >> r;

	printf("%.6f %.6f\n", PI*r*r, 2.0*PI*r);

	return 0;
}
#endif // B

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

ll fpow(ll a, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a;
		a = a * a;
		n >>= 1;
	}
	return res;
}

int main() {
	ll n;
	cin >> n;
	ll keta=1,sum=0;
	while (1) {
		ll tmp = fpow(26, keta);
		if (sum + tmp >= n) {
			n -= sum;
			break;
		}
		sum += tmp;
		keta++;
	}
	n--;
	string res;
	FOR(i, 0, keta - 1) {
		res.PB('a');
	}
	FOR(i, 0, keta - 1) {
		ll tmp = n / fpow(26,keta-1-i);
		res[i] += tmp;
		n -= tmp * fpow(26, keta - 1 - i);
	}
	pv(res)
	return 0;
}

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

using Weight = long long;
using Vertex = int;
struct Edge {Vertex from, to; Weight weight;};
using Graph = std::vector<std::vector<Edge>>;

std::vector<Weight> BellmanFord(const Graph& G, Vertex s, Weight INF = 1e18) {
  std::vector<Weight> d(G.size(), INF);
  d[s] = 0;
  for(auto k = 0; k < G.size(); ++k) for(auto v = 0; v < G.size(); ++v) for(const auto& e: G[v]) {
    if(d[e.to] > d[e.from] + e.weight) {
      d[e.to] = d[e.from] + e.weight;
      if(k == G.size()-1) d[e.to] = -INF;
    }
  }
  return d;
}

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

  Graph G(N);
  for(auto i=0; i<M; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    G[a].push_back({a, b, -c});
  }

  auto d=BellmanFord(G, 0);
  if(d[N-1]==-1e18) cout << "inf" << endl;
  else              cout << -d[N-1] << endl;
}


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


int gcd(int a,int b)
{
    if(a%b==0)return b;
    else gcd(b,a%b);
}

int main()
{
    int a,b;
    cin >>a >> b;
    if(a<=b)
    {
        int t=a;
        a=b;
        b=t;
    }
    cout << gcd(a,b)<< endl;
}


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

int main(){
  int n, a[101] = {0};
  int amin = 100, amax = -100;
  int ans = 1e6;
  
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    amin = min(amin, a[i]);
    amax = max(amax, a[i]);
  }
  
  for(int i = amin; i < amax+1; i++){
    int d = 0;
    for(int j = 0; j < n; j++){
      d += ( a[j] - i ) * ( a[j] - i );
    }
    ans = min(ans, d);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int, int>pii;
typedef pair<int, pii>pi3;
ll mod = 1000000007;
int m[100][100];
bool flag[100][100];
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
int main()
{
	for (int i = 0; i < 3; i++)for (int j = 0; j < 3; j++)scanf("%d", &m[i][j]);
	bool f = true;
	for (int i = 0; i < 3; i++)for (int j = 0; j < 3; j++)for (int k = 0; k < 3; k++)for (int l = 0; l < 3; l++)if (m[i][j] + m[k][l] != m[i][l] + m[k][j])f = false;
	printf(f ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        k: usize,
    }
    puts!("{}\n", if n >= 2 * k - 1 { "YES" } else { "NO" });
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<cctype>
#include<climits>
#include<bitset>
#include<stack>

using namespace std;

typedef long long ll;

const int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int MAX = 19;
int W, H, fld[10][10];
int P, sx, sy;
map<pair<pair<int, int>, int>, int> memo;

inline int CountBit(int s)
{
	int res = 0;
	for (int i = 0; i < P; i++) res += (s >> i) & 1;
	return res;
}

inline bool IsInside(int x, int y)
{
	return 0 <= x && x < W && 0 <= y && y < H;
}

inline bool CanDown(int x, int y, int s, int noBits)
{
	if (x == sx && y == sy && noBits == P) return true;
	if (fld[y][x] == -1) return false;
	return ((s >> fld[y][x]) & 1) == 0;
}

int DFS(int x, int y, int s, int &order)
{
	order++;
	int noBits = CountBit(s);
	if (x == sx && y == sy && noBits == P) return 1;
	pair<pair<int, int>, int> state = make_pair(make_pair(x, y), s);
	if (noBits < MAX)
	{
		map<pair<pair<int, int>, int>, int>::iterator itr = memo.find(state);
		if (itr != memo.end()) return itr->second;
	}
	int sum = 0, cnt = 0;
	for (int i = 0; i < 4; i++)
	{
		int nx = x + dx[i], ny = y + dy[i];
		while (IsInside(nx, ny) && !CanDown(nx, ny, s, noBits))
			nx += dx[i], ny += dy[i];
		if (!IsInside(nx, ny)) continue;
		sum += DFS(nx, ny, s | (1 << fld[ny][nx]), cnt);
	}
	order += cnt;
	if (noBits < MAX && !(noBits >= 14 && cnt <= 10)) memo[state] = sum;
	return sum;
}

signed main()
{
	while (cin >> W >> H, W || H)
	{
		memo.clear();
		P = 0;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				cin >> fld[i][j];
				if (fld[i][j] == 0) fld[i][j] = -1;
				else if (fld[i][j] == 1) fld[i][j] = P++;
				else sx = j, sy = i, fld[i][j] = -1;
			}
		}
		int cnt = 0;
		printf("%d\n", DFS(sx, sy, 0, cnt));
	}
	return 0;
}

Measured memory_bytes: 38644
#include <iostream>
#include <vector>
#include <algorithm>

#define MOD 1000000007

typedef long long ll;

using namespace std;

vector<ll> p, f;

void factorize(ll n) {
    ll r = n;
    for (ll i = 0; i < p.size() && p.at(i) * p.at(i) <= r; ++i) {
        while (r % p.at(i) == 0) {
            ++f.at(i);
            r /= p.at(i);
        }
    }
    if (r == n) {
        p.push_back(n);
        f.push_back(1);
    } else if (r > 1) ++f.at(find(p.begin(), p.end(), r) - p.begin());
}

int main() {
    ll n, ans = 1;
    cin >> n;
    for (ll i = 2; i <= n; ++i) factorize(i);
    for (ll i = 0; i < f.size(); ++i) ans = ans * (f.at(i) + 1) % MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  string s;

  cin >> s;

  cout << 700 + ((s[0] == 'o') + (s[1] == 'o') + (s[2] == 'o')) * 100 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end()))
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

bool ok(string a, string b) {
  debug2(a, b);
  ll alen = a.size(), blen = b.size();
  for (int i = 0; i < min(alen, blen); i++) {
    if (a[i] < b[i]) return true;
    else if (a[i] > b[i]) return false;
  }
  return alen < blen;
}

void solve() {
  string s, t; cin >> s >> t;
  vector<ll> numss(26, 0), numst(26, 0);
  for (char c : s) numss[c-'a']++;
  for (char c : t) numst[c-'a']++;
  string ss = "";
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < numss[i]; j++) ss += (char)('a'+i);
  }
  string tt = "";
  for (int i = 25; i >= 0; i--) {
    for (int j = 0; j < numst[i]; j++) tt += (char)('a'+i);
  }

  if (ok(ss, tt)) {
    Yes();
  } else {
    No();
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
s = input()
t = input()
lent = len(t)
a = len(s)
for i in range(len(s)-len(t)+1):
  s1 = s[i:i+lent]
  c = 0
  for j in range(len(s1)):
    if s1[j] != t[j]:
      c+= 1
  a = min(a,c)
print(a)

Measured memory_bytes: 67732
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 3e5 + 5;
struct node1 {
    int x,val;
    node1(int _x = 0,int _val = 0) {
        x = _x; val = _val;
    }
    bool operator < (node1 a) const {
        return a.val>val;
    }
};
struct node2 {
    int x,val;
    node2(int _x = 0,int _val = 0) {
        x = _x; val = _val;
    }
    bool operator < (node2 a) const {
        return a.val<val;
    }
};
int n;
int l[maxn], r[maxn];
bool vis[maxn];
priority_queue<node1> L;
priority_queue<node2> R;

ll calc(int &pos, int x) {
//    printf("%d : %d %d\n",pos,l[x],r[x]);
    if(l[x]<=pos && pos<=r[x]) return 0;
    ll res = min(abs(l[x]-pos),abs(pos-r[x]));
    if(abs(l[x]-pos) < abs(pos-r[x])) pos = l[x];
    else pos = r[x];
    return res;
}

ll solve() {
    while(!L.empty()) L.pop();
    while(!R.empty()) R.pop();
    for(int i=1;i<=n;i++) vis[i] = 0;
    for(int i=1;i<=n;i++) L.push(node1(i,l[i])), R.push(node2(i,r[i]));
    int last = 0;
    ll ans = 0;
    while(!L.empty() || !R.empty()) {
        //get right
        while(!L.empty()) {
            int x = L.top().x; L.pop();
            if(vis[x]) continue;
            else {
                ans += calc(last, x);
                vis[x] = 1;
                break;
            }
        }
        //get right
        while(!R.empty()) {
            int x = R.top().x; R.pop();
            if(vis[x]) continue;
            else {
                ans += calc(last, x);
                vis[x] = 1;
                break;
            }
        }
    }
    ans += calc(last, 0);
    return ans;
}

int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d",&l[i],&r[i]);

    ll ans = solve();
    for(int i=1;i<=n;i++) l[i] = -l[i], r[i] = -r[i], swap(l[i], r[i]);
    ans = max(ans, solve());

    printf("%lld",ans);
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
#define ALL(x) begin(x), end(x)
using ll = long long;
using namespace std;
template <class T> inline void chmin(T & a, T const & b) { a = min(a, b); }

template <typename T>
vector<T> apply_permutation(vector<int> const & sigma, vector<T> const & xs) {
    int n = sigma.size();
    vector<T> ys(n);
    REP (i, n) ys[i] = xs[sigma[i]];
    return ys;
}

template <class Semilattice>
struct sparse_table {
    typedef typename Semilattice::underlying_type underlying_type;
    vector<vector<underlying_type> > table;
    Semilattice lat;
    sparse_table() = default;
    sparse_table(vector<underlying_type> const & data, Semilattice const & a_lat = Semilattice())
            : lat(a_lat) {
        int n = data.size();
        int log_n = 32 - __builtin_clz(n);
        table.resize(log_n, vector<underlying_type>(n));
        table[0] = data;
        REP (k, log_n - 1) {
            REP (i, n) {
                table[k + 1][i] = i + (1ll << k) < n ?
                    lat.append(table[k][i], table[k][i + (1ll << k)]) :
                    table[k][i];
            }
        }
    }
    underlying_type range_concat(int l, int r) const {
        if (l == r) return lat.unit();  // if there is no unit, remove this line
        assert (0 <= l and l < r and r <= table[0].size());
        int k = 31 - __builtin_clz(r - l);  // log2
        return lat.append(table[k][l], table[k][r - (1ll << k)]);
    }
};
struct max_semilattice {
    typedef int underlying_type;
    int unit() const { return INT_MIN; }
    int append(int a, int b) const { return max(a, b); }
};
struct min_semilattice {
    typedef int underlying_type;
    int unit() const { return INT_MAX; }
    int append(int a, int b) const { return min(a, b); }
};

int main() {
    // input
    int n; scanf("%d", &n);
    vector<int> x(n), y(n);
    REP (i, n) scanf("%d%d", &x[i], &y[i]);

    // solve
    { // prepare
        REP (i, n) if (x[i] > y[i]) swap(x[i], y[i]);
        vector<int> order(n);
        iota(ALL(order), 0);
        sort(ALL(order), [&](int i, int j) { return x[i] < x[j]; });
        x = apply_permutation(order, x);
        y = apply_permutation(order, y);
    }
    ll result = LLONG_MAX;
    { // min_x is red and max_y is blue
        int r_min = *min_element(ALL(x));
        int r_max = *max_element(ALL(x));
        int b_min = *min_element(ALL(y));
        int b_max = *max_element(ALL(y));
        chmin(result, (r_max - r_min) *(ll) (b_max - b_min));
    }
    { // min_x and max_y are red
        int r_min = *min_element(ALL(x));
        int r_max = *max_element(ALL(y));
        sparse_table<max_semilattice> y_max(y);
        sparse_table<min_semilattice> y_min(y);
        REP (i, n) {
            int b_min = min(x[i],     y_min.range_concat(0, i));
            int b_max = max(x[n - 1], y_max.range_concat(0, i));
            if (b_max < b_min) break;
            chmin(result, (r_max - r_min) *(ll) (b_max - b_min));
        }
    }

    // output
    printf("%lld\n", result);
    return 0;
}


Measured memory_bytes: 30672
import numpy as np

A, B, M = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
minimum = np.min(a) + np.min(b)
for i in range(M):
    x,y,c = map(int, input().split())
    price = a[x-1] + b[y-1] - c
    if price < minimum:
        minimum = price

print(minimum)

Measured memory_bytes: 27508
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod=1e9+7,n;

map<ll,ll> mp;

void dfs(vector<ll> v[],ll idx,ll parent)
{
  if(idx==1) mp[1]=n;
  else
  {
    if(parent>idx) mp[idx]=idx*(parent-idx);
    else mp[idx]=(idx-parent)*(n-idx+1);
  }
  for(auto a:v[idx])
  {
    if(a!=parent) dfs(v,a,idx);
  }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b;cin>>n;
    vector<ll> v[n+1];
    for(int i=0;i<n-1;i++)
    {
      cin>>a>>b;
      v[a].push_back(b);
      v[b].push_back(a);
    }
    dfs(v,1,1);
    ll ans=0;
    for(int i=1;i<=n;i++) ans+=mp[i];
      cout<<ans;
}

Measured memory_bytes: 45804
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

int main(int argc, char *argv[]) {
  int N, M, Q;
  cin >> N >> M >> Q;

  boost::multi_array<int, 2> mat(boost::extents[N + 1][N + 1]);

  FOR(i, M) {
    int L, R;
    cin >> L >> R;
    mat[L][R]++;
  }

  FOR(i, N + 1) {
    FOR(j, N) { mat[i][j + 1] += mat[i][j]; }
  }

  for (int i = N; i > 0; i--) {
    FOR(j, N + 1) { mat[i - 1][j] += mat[i][j]; }
  }

  while (Q--) {
    int p, q;
    cin >> p >> q;
    cout << mat[p][q] << "\n";
  }

  return 0;
}


Measured memory_bytes: 1920
from collections import defaultdict
from itertools import count
from math import ceil
from fractions import Fraction

def main():
    n = int(input())
    A, B = map(int, input().split())
    for _ in range(n - 1):
        t, a = map(int, input().split())
        n = ceil(max(Fraction(A, t), Fraction(B, a)))
        A, B = n * t, n * a

    print(A + B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

    int digsum = 0;
    int len = N.size();
    for (int i = 0; i < len; i++)
    {
        digsum += (N[i] - '0');
    }

    if(digsum % 9 == 0){
        cout << "Yes" <<endl;
    } else {
        cout << "No" <<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3752
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int K = sc.nextInt();
        boolean ans = false;
        for(int n=0;n<=N;n++){
        	for(int m=0;m<=M;m++){
        		int black = n*m + (N-n)*(M-m);
        		if(black==K) ans = true;
        	}
        }
        if(ans) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 23636
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        m: u32,
    }
    println!("{}", 24 - m + 24);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int dp[200000];
int main(){
    int n;
    cin>>n;
    int k;cin>>k;
    int a[200000];
    for(int i=0;i<n;i++)cin>>a[i];

    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);

    for(int i=2;i<n;i++){
        int x=INT_MAX;
        for(int z=1;z<=k;z++){
            if(i-z>=0)
            x=min(x,abs(a[i]-a[i-z])+dp[i-z]);
        }
        dp[i]=x;
    }

    cout<<dp[n-1];
}

Measured memory_bytes: 1024
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

scores = {'r': p, 's': r, 'p': s}
not_scored = set()
res = 0

for i in range(n):
    if i < k:
        res += scores[t[i]]
    else:
        if t[i] == t[i-k] and i-k in not_scored:
            res += scores[t[i]]
        elif t[i] == t[i-k]:
            not_scored.add(i)
        else:
            res += scores[t[i]]

print(res)


Measured memory_bytes: 6964