akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

int main() {
   int N;
   int count = 0;
   cin >> N;
   vector<int> L(N,0);
   rep(i,N){ cin >> L[i]; }
   for(int i = 0; i < N; ++i){
     for(int j = i; j < N; ++j){
       for(int k = j; k < N; ++k){
         if( (L[k] < L[i] + L[j]) && (L[i] < L[k] + L[j]) && (L[j] < L[i] + L[k])){
           if( L[i] == L[j] || L[j] == L[k] || L[k] == L[i] ){}
           else {count++;}
         }
       }
     }
   }
   cout << count << endl;
   return 0;
}

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

class UnDirectedTree {
  struct edge {
      int to;
      int cost;
  };

  vector<vector<edge>> table;
  int N;
  vector<int> distances;

  void dfs(int now, int par) {
      for (edge e : table[now]) {
          if (e.to == par) continue;
          distances[e.to] = distances[now] + e.cost;
          dfs(e.to, now);
      }
  }
public:
    UnDirectedTree (int n) {
        table.resize(n);
        distances.resize(n);
        N = n;
    }

    void add_edge(int s, int t, int cost) {
        table[s].push_back({t, cost});
        table[t].push_back({s, cost});
    }

    int diameter(void) {
        fill(distances.begin(), distances.end(), 0);
        dfs(0, -1);

        int mx_idx = -1;
        int mx = -1;
        for (int i = 0; i < N; i++) {
            if (distances[i] > mx) {
                mx_idx = i;
                mx = distances[i];
            }
        }

        fill(distances.begin(), distances.end(), 0);
        dfs(mx_idx, -1);

        int ret = -1;
        for (int d : distances) ret = max(ret, d);
        return ret;
    }
};

int main(void) {
    int N;
    cin >> N;
    UnDirectedTree dt = UnDirectedTree(N);
    for (int i = 0; i < N - 1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        dt.add_edge(s, t, w);
    }
    cout << dt.diameter() << endl;
}


Measured memory_bytes: 11776
#include<bits/stdc++.h>
using namespace std;
double mn,mx;
struct num{int A,B;}a[1000009];
bool cmp1(const num&a,const num&b){return a.A<b.A;}
bool cmp2(const num&a,const num&b){return a.B<b.B;}
int main(){
	int n; scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i].A,&a[i].B);
	sort(a+1,a+n+1,cmp1); mn=(a[(n+1)/2].A+a[(n+2)/2].A)/2.;
	sort(a+1,a+n+1,cmp2); mx=(a[(n+1)/2].B+a[(n+2)/2].B)/2.;
	if(n&1) printf("%d",(int)(mx-mn+1));
	else printf("%d",(int)(2*(mx-mn+0.5)));
	return 0;
} 

Measured memory_bytes: 5288
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>

using namespace std;

int main(void){

    int n, m, ans = 0;

    cin >> n >> m;

    vector<int> x(m);
    priority_queue<int> sub;

    for(int i = 0;i < m;i++) cin >> x[i];

    sort(x.begin(), x.end());

    if(n < m){
        for(int i = 0;i < m - 1;i++){
            sub.push(x[i+1] - x[i]);
            ans += x[i+1] - x[i];
        }

    
        for(int i = 0;i < n-1;i++){
            ans -= sub.top();
            sub.pop();
        }
    }

    cout << ans << endl;




    return 0;
}

Measured memory_bytes: 1276
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    sc.nextLine()

    val values: List[Int] = sc.nextLine().split(" ").map(_.toInt).toList
    val costs: List[Int] = sc.nextLine().split(" ").map(_.toInt).toList

    println((values zip costs).map(item => item._1 - item._2).filter(profit => profit >= 0).sum)

  }
}

Measured memory_bytes: 27332
n = int(input())
l = list(input().split())

target_num = 1
for i in range(n):
  if target_num == int(l[i]):
    target_num += 1
  else:
    target_num = target_num

if target_num == 1:
  print("-1")
else:
  print(n - target_num +1)


Measured memory_bytes: 18216
import math
Q = int(input())

for _ in range(Q):
    A, B = map(int, input().split())
    score = A*B #高橋君のスコア
    if A > B:
        A, B = B, A #常にAを小さくする
    if A == B:
        print  (2 * A -2)
    elif A+1 == B:
        print (2 * A - 2)
    else:
        c = int(math.sqrt(A*B))
        if c ** 2 == A * B:
            c -= 1
        if c * (c+1) >= A * B:
            print (2 * c -2)
        else:
            print (2 * c -1)


Measured memory_bytes: 3064
class Factorial():
    def __init__(self, n, mod):
        self.mod = mod
        self.fct = [0 for _ in range(n + 1)]
        self.inv = [0 for _ in range(n + 1)]
        self.fct[0] = 1
        self.inv[0] = 1
        for i in range(n):
            self.fct[i + 1] = self.fct[i] * (i + 1) % mod
        self.inv[n] = pow(self.fct[n], mod - 2, mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i + 1] * (i + 1) % mod

    def comb(self, m, k):
        if m < k: return 0
        return self.fct[m] * self.inv[k] * self.inv[m - k] % self.mod

def ex_euclid(x, y):
    c0, c1 = x, y
    a0, a1 = 1, 0
    b0, b1 = 0, 1
    while c1:
        a0, a1 = a1, a0 - c0 // c1 * a1
        b0, b1 = b1, b0 - c0 // c1 * b1
        c0, c1 = c1, c0 % c1
    return c0, a0, b0

MOD = 998244353
N, A, B, K =map(int,input().split())

f = Factorial(N, MOD)
c, a, b = ex_euclid(A, B)

if K == 0:
    print(1)

elif K % c != 0:
    print(0)

else:
    lo = -10**18
    hi = 10**18
    while hi - lo > 1:
        mid = (hi + lo) // 2
        if a * K // c + mid * B // c >= 0:
            hi = mid
        else:
            lo = mid
    x0 = a * K // c + hi * B // c

    lo = -10**18
    hi = 10**18
    while hi - lo > 1:
        mid = (hi + lo) // 2
        if b * K // c - mid * A // c >= 0:
            lo = mid
        else:
            hi = mid
    y0 = b * K // c - lo * A // c

    res = 0
    x = x0
    y = (K - A * x0) // B

    while True:
        res += f.comb(N, x) * f.comb(N, y)
        res %= MOD
        if y == y0:
            break
        x += B // c
        y -= A // c

    print(res)

Measured memory_bytes: 32780
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.lang.Math.abs
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val ar = Array(3){sc.nextInt()}
    ar.sort()
    if(ar[0] == ar[1]) println(ar[2])
    else println(ar[0])


}


class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}




Measured memory_bytes: 29908
S=input()

cc=0
nc=0
for i in range(2,len(S)-1):
    if S[i]=='C' and S[i].islower()==False:
        cc+=1
        nc=i

if cc==1 and not nc==0:
    p1=True
else:
    p1=False

if S[0]=='A' and S[0].islower()==False:
    p2=True
else:
    p2=False

bc=0
for i in range(len(S)):
    if i==0 or i==nc:
        pass
    else:
        if S[i].islower()==False:
            bc+=1

if p1==True and p2==True and bc==0:
    print('AC')

else:
    print('WA')


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <queue>
using namespace std;
 
//          1  2  3  4  5  6  7  8  9 10 11 12
int h[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
 
bool is_leap(int y){
	if( y % 4 == 0 ){
		if( y % 100 == 0 ){
			if( y % 400 == 0 ){
				return true;
			}else{
				return false;
			}
		}else{
			return true;
		}
	}
	return false;
}
 
struct Time{
	int y,m,d;
	Time(int y_, int m_, int d_){
		y = y_;
		m = m_;
		d = d_;
	}
	void inc(){
		if( is_leap( y ) && m == 2 && d == 28 ){
			d++;
		}else if(is_leap( y ) && m == 2 && d == 29 ){
			m++;
			d = 1;
		}else{
			if( d < h[m-1] ){
				d++;
			}else{
				d = 1;
				if( m == 12 ){
					m = 1;
					y++;
				}else{
					m++;
				}
			}
		}
	}
	bool equal(Time t){
		return ( y == t.y && m == t.m && d == t.d );
	}
};
 
int main(){
	int y1, m1, d1, y2, m2, d2;
	while( cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2 ){
		if( y1 == -1 || m1 == -1 || d1 == -1 || y2 == -1 || m2 == -1 || d2 == -1 ) break;
		Time t1( y1, m1, d1 );
		Time t2( y2, m2, d2 );
		int cnt = 0;
		while( !t1.equal(t2) ){
			t1.inc();
			cnt++;
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

bool is_prime(ll n){
	if(n==1)return false;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0)return false;
	}
	return true;
}
vector<ll>divsor(ll n){
	vector<ll>res;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			res.push_back(i);
			if(i!=n/i)res.push_back(i);
		}
	}
	return res;
}
map<ll,int>prime_factor(ll n){
	map<ll,int>res;
	for(ll i=2;i*i<=n;i++){
		while(n%i==0){
			res[i]++;
			n/=i;
		}
	}
	if(n!=1)res[n]++;
	return res;
}

ll dp[200][200];
int main(){
	int n;scanf("%d",&n);
	vector<P>v;
	for(int i=2;i<=n;i++){
		if(is_prime(i)){
			int cnt=0;
			for(int j=i;j<=n;j=j*i)cnt+=n/j;
			v.push_back(P(i,cnt));
		}
	}
	//~ for(auto p:v){
		//~ cout<<p.first<<' '<<p.second<<endl;
	//~ }
	dp[0][1]=1;
	rep(i,v.size())rep(j,100){
		if(dp[i][j]==0)continue;
		for(int k=0;k<=v[i].second;k++){
			if(j*(k+1)<=75){
				dp[i+1][j*(k+1)]+=dp[i][j];
			}
		}
	}
	cout<<dp[v.size()][75]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < n; ++i)
using namespace std;
const int INF = 2147483647;
using ll = long long;
// cout << typeid('変数').name() << endl;

bool which(char c){
    bool wh=0;
    if(c=='1') wh=1;
    return wh;
}

int main() {
    string s;
    cin >> s;
    int cnt=0;
    bool before;
    bool con=true;
    while(con){
        if(s.size()==0) break;
        before = which(s.at(0));
        con = false;
        for(int i=1;i<s.size();++i){
            bool now = which(s.at(i));
            if(before != now) {
                s.erase(i-1,2);
                cnt+=2;
                con = true;
                break;
            }
            before = now;

        }
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int MAX = 410000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;//i!(mod MOD)を計算
        inv[i] = MOD - inv[MOD%i]* (MOD / i) % MOD;//iの逆元を計算
        finv[i] = finv[i - 1] * inv[i] % MOD;//i!(mod MOD)の逆元を計算
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;//nCk = n!/(k!*(n-k)!)を計算
}
int main(){
    int S;
    cin >> S;
    if(S < 3){
        cout << 0 << endl;
        return 0;
    }
    COMinit();
    int t = S /3;
    long long ans = 0;
    for(int i = 0; i < t; i++){
        ans = (ans + COM(S - 1 - (i + 1) * 2, i)) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 13244
K = int(input())

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


if A[-1] != 2:
    print(-1)
    exit()

big = 2
small = 2
for i in reversed(range(K)):
    """
    smallのときにai人組つくると脱落者なし
    bigのときにai人組作るとai-1人脱落

    """


    # smallは元のsmall以上かつ、脱落者なし
    if small // A[i] > 0 and small % A[i] > 0:
        small = (small // A[i] + 1) * A[i]
    elif small // A[i] > 0 and small % A[i] == 0:
        small = small
    elif small // A[i] == 0:
        small = A[i] 
        
    # bigは元のbig以上かつ、脱落者がai-1
    big = (big // A[i]) * A[i] + A[i] - 1

    if big < small:
        print(-1)
        exit()


print(small, big)


Measured memory_bytes: 14428
#include<stdio.h>
#include <string.h>
#include <math.h>

int main(){
	int ssx,ssy,ttx,tty;
	int tx,ty,i;
	
	scanf("%d %d %d %d",&ssx,&ssy,&ttx,&tty);
	tx=ttx-ssx;
	ty=tty-ssy;
	
	for(i=0;i<ty;i++){
		printf("U");
	}
	for(i=0;i<tx;i++){
		printf("R");
	}
	for(i=0;i<ty;i++){
		printf("D");
	}
	for(i=0;i<tx;i++){
		printf("L");
	}
	printf("LU");
	for(i=0;i<ty;i++){
		printf("U");
	}
	for(i=0;i<tx;i++){
		printf("R");
	}
	printf("RDRD");
	for(i=0;i<ty;i++){
		printf("D");
	}
	for(i=0;i<tx;i++){
		printf("L");
	}
	printf("LU\n");
	
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int  main (){
  string a,b;
  cin>>a>>b;
  if(a==b){
    cout<<"="<<"\n";
    return(0);
  }
  if(a>b){
  cout<<">"<<"\n";
  return(0);
  }
  cout<<"<"<<"\n";
 return(0);
}


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

using namespace std;

int main()
{
  int n,R[200000],maxv=-2000000000;
  cin>>n;
  for(int i=0;i<n;i++) cin>>R[i];
  int minv=R[0];
  for(int i=1;i<n;i++){
    maxv=max(maxv,R[i]-minv);
    minv=min(minv,R[i]);
  }
  cout<<maxv<<endl;
  return 0;
}




Measured memory_bytes: 3868
#include<stdio.h>

int main(){
  int a[101][101];
  int i,j,u,k,v,n;

  scanf("%d",&n);

  for(i=1;i<=n;i++)
    for(j=1;j<=n;j++) a[i][j]=0;

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    if(k==0) continue;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      a[u][v]=1;
    }
  }

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      printf("%d",a[i][j]);
      if(j!=n) printf(" ");
    }
    printf("\n");
  }

  return 0;
}



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

// 約数列挙
vector<ll> divisor(ll N) {
    vector<ll> res;
    for (ll i = 1L; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            ll j = N / i;
            if (j != i)  {
                res.push_back(j);
            }
        }
    }
    sort(res.begin(), res.end());
    return res;
}


void Main() {
    ll N; cin >> N;
    vector<ll> ans = divisor(N);
    ll a = *lower_bound(ans.begin(), ans.end(), ceil(sqrt(N)));
    cout << (N / a) + a - 2 << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 384
N,L=map(int,input().split())

se=[]

for i in range(N):
    se.append(L+i)
#print(se)

if L<0:
    if N+L>=1:
        print(sum(se))
    else:
        print(sum(se)-max(se))
elif L==0:
    print(sum(se))
else:
    print(sum(se)-min(se))



Measured memory_bytes: 3064
#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 RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
            #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
            #define FILL(a,value) memset(a, value, sizeof(a))

            #define SZ(a) (int)a.size()
            #define ALL(a) a.begin(), a.end()
            #define PB emplace_back
            #define P push
            #define IN insert
            #define ER erase

            #define MP make_pair
            #define sc second
            #define fs first

            typedef long long LL;
            typedef vector<int> VI;
            typedef vector<LL>VL;
            typedef vector <bool >VB;
            typedef vector<vector<int>>WI;
            typedef vector<vector<LL>>WL;
            typedef pair<int, int> PII;
            typedef pair<double, double> PDD;

            const double PI = acos(-1.0);
            const int INF = int(1e9);
            const LL LINF = LL(1e18);
            const int MAS = int(1e6+10);
            const double EPS = 1e-7;
            const LL MAX = 4294967296;
            const LL MOD =LL(1e9+7);



            int main()
            {
                ios_base::sync_with_stdio(false);
                cin.tie(0);
                cout.tie(0);
                int a,b;
                cin >> a >> b;
                if(a > 9 || b > 9)cout << -1;
                else cout << a*b;
            }


Measured memory_bytes: 256
weight = Array.new(10) {|i| 2**i }
weight.sort!{|a,b| b<=>a}

while true do
  num = gets
  break if num == nil
  num = num.to_i
  result = Array.new
  weight.each do |w|
    next if num < w
    break if num == 0
    num -= w
    result.unshift w
  end
  puts result.join ' '
end

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()

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

    int N, M; cin >> N >> M;
    vi A(N, -1);

    bool flag = true;
    while(M--){
        int s, c; cin >> s >> c;
        s--;
        if(A[s] != -1 and A[s] != c) flag = false;
        A[s] = c;
    }
    if(!flag) cout << -1 << endl;
    else if(N == 1) cout << max(0, A[0]) << endl;
    else if(A[0] == 0) cout << -1 << endl;
    
    else for(int x = 0; x < N; x++){
        if(A[x] == -1 and x == 0) cout << 1;
        else if(A[x] == -1) cout << 0;
        else cout << A[x];
    }
    cout << endl;

    return 0;
}

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

typedef complex<double> P;

#define EPS (1e-10)

double dot(P a,P b){
	return (a.real() * b.real() + a.imag() * b.imag());
}

double cross(P a,P b){
	return (a.real() * b.imag() - a.imag() * b.real());
}

double distance_ls_p(P a,P b,P c){
	if(dot(b-a,c-a) < EPS) return abs(c-a);
	if(dot(a-b,c-b) < EPS) return abs(c-b);
	return abs(cross(b-a,c-a)) / abs(b-a);
}

bool intersected(P a,P b,P o,double r){
	double ao = abs(a-o);
	double bo = abs(b-o);

	if( (ao < r + EPS && r < bo + EPS || r < ao + EPS && bo < r + EPS) ||
			(r < ao + EPS && r < bo + EPS && distance_ls_p(a,b,o) < r + EPS) )
		return true;

	return false;
}

int main(void){
	int n,m;

	while(cin>>n && n){
		P o[n];
		double r[n];

		for(int i=0;i<n;i++){
			cin>>o[i].real()>>o[i].imag()>>r[i];
		}

		cin>>m;
		while(m--){
			P taro,oni;
			cin>>taro.real()>>taro.imag()>>oni.real()>>oni.imag();

			bool flg = true;
			for(int i=0;i<n;i++){
				if(intersected(taro,oni,o[i],r[i])){
					flg = false;
					break;
				}
			}

			if(flg) cout<<"Danger\n";
			else cout<<"Safe\n";
		}
	}

	return 0;
}

Measured memory_bytes: 0
<?php

fscanf(STDIN, "%d", $n);
$tkyk = explode(" ", trim(fgets(STDIN)));
$ans = 0;
for($i = 0;$i < $n -1 ; $i++){
    for($j = $i+1; $j < $n; $j++){
        $ans += $tkyk[$i] * $tkyk[$j];
    }
}

echo $ans;



Measured memory_bytes: 4856
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int r;
    cin>>r;
    if(r<1200) cout<<"ABC\n";
    else if(r<2800) cout<<"ARC\n";
    else cout<<"AGC\n";
	return 0;
}


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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int n,k;
  cin >> n >> k;
  int64_t sum = 0;
 for(int i=1;i <= n;i++){
   if(i < k+1){
     // through
   }else{
     sum += (((n+1) / i)*(i - k)) + max(0,((n+1) % i)-k);
     if(k == 0){
       sum--;
     }
   }
 }
  cout << sum << endl;
     
}

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

signed main(){
  
  string s;
  cin>>s;
  
  int cnt = 0, ans = 0;
  
  for(char c : s ){
    
    if( c == 'B' ) cnt++;
    else ans += cnt;
    
  }

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


Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
using namespace std;
int n, h[100000];
int dp[100010];

const int INF = (int)1e9;
int main() {
	cin >> n;
	dp[0] = 0;
	

	for (int i = 0; i < n; i++) cin >> h[i];
	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs( h[i]-h[i - 1] ), dp[i - 2] + abs(h[i] - h[i-2]));
	}
	cout << dp[n-1];
}

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

const int MAX = 2e5 + 5;
char a[MAX];

int main() {
	scanf("%s", a + 1);

	int n = strlen(a + 1);
	int k = 0;
	int ans = n;

	for(int i = 1; i <= n; i++) {
		if(a[i] == 'S')
			k++;

		else {
			if(k > 0) {
				k--;
				ans -= 2;
			}
		}
	}

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

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

void Main() 
{
	string str;
	int n;
	cin >> n;
	cin >> str;
	for (int i = 0; i < str.length(); i++)
	{
		if ((static_cast<int>(str[i])) + n > static_cast<int>('Z'))
		{
			cout << static_cast<char>((static_cast<int>(str[i])) + n - 26);
		}
		else 
		{
			cout << static_cast<char>((static_cast<int>(str[i])) + n);
		}
	}
}

int main() {
	Main();

	return 0;
}

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

int main(){
    int N;
    cin >> N;
    map<string, int> m;
    for(int i =0; i < N; i++){
        string s;
        cin >> s;
        m[s] ++;
    }
    cout << m.size() << endl;
}

Measured memory_bytes: 19260
N,M,C = map(int, input().split())
B = list(map(int, input().split()))

ans = 0

for _ in range(N):

    sum = 0
    A = list(map(int, input().split()))

    for i in range(M):
        sum += A[i]*B[i]
        
    if sum + C > 0:
        ans += 1

print(ans)


Measured memory_bytes: 3060
/*
THE BEST IS YET TO COME
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define r(i,s,l) for(int i=s;i<l;i++)
#define mod 1000000007
#define INT_BITS 32
#define ld long double
#define pp pair<long long,long long>
#define ss second
#define ff first
#define N 2000005
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int main(){
    fast();
    int n;
    cin>>n;
    vector<int> a(n);
    r(i,0,n)
    cin>>a[i];
    int dp[n];
    r(i,0,n)
    dp[i]=INT_MAX;
    dp[0]=0;
    r(i,0,n)
    {
        dp[i+1]=min(dp[i+1],dp[i]+abs(a[i]-a[i+1]));
        dp[i+2]=min(dp[i+2],dp[i]+abs(a[i]-a[i+2]));
    }
    cout<<dp[n-1];
	return 0;
}


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

int main(){
  string S;
  cin >> S;
  
  int ans = 0;
  int cnt = 0;
  for(auto s : S){
    if('A' == s || 'T' == s || 'C' == s || 'G' == s) cnt++;
    else cnt=0;
    ans = max(ans,cnt);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
public class Hello{
    public static void Main(){
      var lines = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      int coin_count = lines[0];
      int border = lines[1];
      
      int value = coin_count * 500;
      if (value >= border){
         Console.WriteLine("Yes");
      }else{
         Console.WriteLine("No");
      }
      
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <math.h>
#include<algorithm>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  string ans;
  for(int i=0;i<s.size();i++){
   if(s[i]=='1'){
    ans=ans+"1"; 
   }
    if(s[i]=='0'){
     ans=ans+"0"; 
    }
    if(s[i]=='B' && ans.size()!=0){
      ans.pop_back();
    }
  }
  cout << ans << endl;
  return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
const int maxn=2e5+10;
ll inv[maxn];
ll fac[maxn];
ll power(ll base,ll n)
{
    ll r=1;
    while(n)
    {
        if(n&1) r=r*base%mod;
        base=base*base%mod;
        n/=2;
    }
    return r;
}
void init()
{
    fac[0]=1;
    for(int i=1;i<=2e5;i++)
    {
        fac[i]=fac[i-1]*i%mod;
    }
    inv[200000]=power(fac[200000],mod-2);
    for(int i=2e5;i>=1;i--)
    {
        inv[i-1]=inv[i]*i%mod;
    }
}
ll C(ll m,ll n)
{
    return fac[n]*inv[m]%mod*inv[n-m]%mod;
}

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


    int red=n-k;
    for(int i=1;i<=k;i++)
    {
        if(i>red+1)
        {
            cout<<0<<'\n';
            continue;
        }
        int ans=(C(i,red+1)*C(i-1,k-1))%mod;
        cout<<ans<<'\n';
    }


}


Measured memory_bytes: 3456
package main

import (
	"bufio"
	"fmt"
	"math/rand"
	"os"
	"strconv"
	"time"
)

const (
	limitSecs = 2.0
)

// D
var (
	D         int
	c         [26]int
	s         [][26]int
	startTime time.Time
)

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func calcScore(t []int) int {
	var last [26]int
	score := 0
	S := 0
	for i := 0; i < 26; i++ {
		last[i] = -1
	}
	for d := 0; d < len(t); d++ {
		S += s[d][t[d]]
		last[t[d]] = d
		for i := 0; i < 26; i++ {
			S -= c[i] * (d - last[i])
		}
		score += max(1000000+S, 0)
	}
	return score
}

func solution3() []int {
	var t []int
	for d := 0; d < D; d++ {
		score := -1
		best := -1
		t = append(t, 0)
		for i := 0; i < 26; i++ {
			t[len(t)-1] = i
			newScore := calcScore(t)
			if newScore > score {
				best = i
				score = newScore
			}
		}
		t[len(t)-1] = best
	}
	return t
}

func optimize1(t []int) []int {
	var (
		d   [3]int
		old [3]int
	)
	rand.Seed(time.Now().UnixNano())
	score := calcScore(t)
	for time.Now().Sub(startTime).Seconds()+0.015 < limitSecs {
		n := rand.Intn(3) + 1
		for i := 0; i < n; i++ {
			d[i] = rand.Intn(D)
			old[i] = t[d[i]]
			t[d[i]] = rand.Intn(26)
		}
		newScore := calcScore(t)
		if newScore < score {
			for i := 0; i < n; i++ {
				t[d[i]] = old[i]
			}
		} else {
			score = newScore
		}
	}
	return t
}

func main() {
	defer flush()

	startTime = time.Now()

	D = readInt()
	for i := 0; i < 26; i++ {
		c[i] = readInt()
	}
	s = make([][26]int, D)
	for i := 0; i < D; i++ {
		for j := 0; j < 26; j++ {
			s[i][j] = readInt()
		}
	}

	t := solution3()
	t = optimize1(t)
	for d := 0; d < D; d++ {
		println(t[d] + 1)
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


Measured memory_bytes: 2196
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define MAX 300004

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string str;
    int xa = 0,bx = 0,ba = 0,n,tot = 0;
    cin>>n;
    while(n--) {
        cin>>str;
        int len  = str.length();
        for(int i=1;i<len;i++) {
            if(str[i] == 'B' && str[i-1] == 'A') tot++;
        }
        char s = str[0] , e = str[len-1];
        
        if(s == 'B' && e == 'A') {ba++;}
        else if(e == 'A') {xa++;}
        else if(s == 'B') {bx++;}
    }
    cout<<(tot + (ba ? ((ba-1) + (!(!xa)) + (!(!bx)) + max(0,min(xa-1,bx-1))) : min(xa,bx))); 
    return 0;
}

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



double P;
int N;
vector<pair<int, int>> E[101010];
//-----------------------------------------------------------------------------------
double dfs(int cu, int pa = -1) {
	double ret = 0;
	for (auto p : E[cu]) if (p.first != pa) {
		double ex = dfs(p.first, cu) + p.second;
		ret += ex * P;
	}
	return ret;
}
//-----------------------------------------------------------------------------------
double ex = 0;
double dfs2(int cu, int pa = -1) {
	double ret = ex;
	for (auto p : E[cu]) if (p.first != pa) {
		double ex = dfs2(p.first, cu) + p.second;
		ret += ex * P;
	}
	return ret;
}
//-----------------------------------------------------------------------------------
int main() {
	cin >> P >> N;
	rep(i, 0, N - 1) {
		int x, y, c; scanf("%d%d%d", &x, &y, &c);
		E[x].push_back({ y, c });
		E[y].push_back({ x, c });
	}

	ex = dfs(1);
	double ans = dfs2(1);

	printf("%.10f\n", ans);
}

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

int main() {
  int k,a,b; cin>>k>>a>>b;
  bool ok=false;
  for (int x=a; x<=b; x++) {
    if (x%k==0) ok=true;
  }
  if (ok) cout<<"OK"<<endl;
  else cout<<"NG"<<endl;
}


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

int main() {
  int a;
  cin >> a;
  int b = a /100, c = a % 100; // bが上二桁、cが下二桁
  int ym = 0, my = 0;
  if(b > 0 && b <= 12) {
    my = 1;
  }
  if(c > 0 && c <= 12) {
    ym = 1;
  }
  if(my == 1 && ym == 1) {
    cout << "AMBIGUOUS";
  } else if(my == 1) {
    cout << "MMYY";
  } else if(ym == 1) {
    cout << "YYMM";
  } else {
    cout << "NA";
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) cout << (x) << endl
typedef long long ll;

const long double PI = acos(-1);

int main() {
    long double a, b, x;
    cin >> a >> b >> x;
    long double ans;
    if (a * a * b > 2 * x) {
        ans = atan(a * b * b / 2 / x);
    } else {
        ans = atan(2 * (a * a * b - x) / a / a / a);
    }
    cout << setprecision(12) << ans / PI * 180 << endl;
}


Measured memory_bytes: 256
/*************************************************************************
>>> Author: WindCry1
>>> Mail: lanceyu120@gmail.com
>>> Website: https://windcry1.com
>>> Date: 12/30/2019 11:03:37 PM
*************************************************************************/
//#pragma GCC optimize(2)
//#pragma GCC diagnostic error "-std=c++11"
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <stack>
#include <bitset>
#include <iomanip>
#include <list>
#include <sstream>
#include <fstream>
#include <numeric>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define endl '\n'
#define ALL(x) x.begin(),x.end()
#define MP(x,y) make_pair(x,y)
#define ll long long
#define ull unsigned long long
#ifdef WindCry1
#define DEBUG(x) cout<<#x<<" : "<<x<<endl;
#endif
#define lowbit(x) x&(-x)
#define ls x<<1
#define rs x<<1|1
using namespace std;
template<typename T> inline T MIN(const T &a,const T &b) {return a<b?a:b;}
template<typename T> inline T MAX(const T &a,const T &b) {return a>b?a:b;}
template<typename T,typename ...Args> inline T MIN(const T &a,const T &b,Args ...args) {return MIN(MIN(a,b),args...);}
template<typename T,typename ...Args> inline T MAX(const T &a,const T &b,Args ...args) {return MAX(MAX(a,b),args...);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
ll a[200010],b[200010];
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifdef WindCry1
	freopen("C:/Users/LENOVO/Desktop/in.txt","r",stdin);
#endif
	int n;cin>>n;
	for(int i=0;i<n;i++) cin>>a[i]>>b[i];
	sort(a,a+n),sort(b,b+n);
	if(n&1){
		cout<<b[n/2]-a[n/2]+1<<endl;
	}
	else{
		cout<<b[(n-1)/2]+b[(n+1)/2]-a[(n-1)/2]-a[(n+1)/2]+1<<endl;
	}
	return 0;
}



Measured memory_bytes: 6704
def solve():
    H, W = map(int, input().split())
    A = [[i for i in input()] for _ in range(H)]
    
    x, y = 0, 0
    A[y][x] = '.'
    while True:
        if 0 <= x+1 < W and 0 <= y < H and A[y][x+1] == '#':
            x=x+1
            A[y][x] = '.'
        elif 0 <= x < W and 0 <= y+1 < H and A[y+1][x] == '#':
            y=y+1
            A[y][x] = '.'
        else:
            break
    
    for row in A:
        if '#' in row:
            return 'Impossible'

    return 'Possible' if x == W-1 and y == H-1 else 'Impossible'

print(solve())

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

int main() {
    int R0, W0, C, R;
    while(std::cin >> R0 >> W0 >> C >> R) {
        if(R0 == 0 && W0 == 0 && C == 0 && R == 0) break;
        std::cout << std::max(0, (C*W0-R0+R-1)/R) << std::endl;
    }
}


Measured memory_bytes: 3044
k = int(input())

import math


# a=b=c
# from 1 to  k  => (1+k)*k/2
ans = k * (k + 1) // 2

# a, b=c
# gcd(a,b)
for a in range(1, k):
    for b in range(a+1, k+1):
        ans += 3*2*math.gcd(a, b)

# a,b,c
for a in range(1, k-1):
    for b in range(a+1, k):
        for c in range(b+1, k+1):
            ans += 3*2*math.gcd(a, math.gcd(b, c))

print(ans)

Measured memory_bytes: 9204
import sys,collections as cl,bisect as bs,heapq as hq
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

t = onem()

for _ in range(t):
	n = onem()
	L = []
	R = []
	ans = 0
	for i in range(n):
		k,l,r = m()
		if l >= r:
			L.append([k,l-r])
			ans += r
		else:
			R.append([n-k + 1,r-l])
			ans += l
	L.sort()
	R.sort()

	po = []
	ii = 0
	for i in range(n):
		while ii < len(L):
			if L[ii][0] == i+1:
				hq.heappush(po,L[ii][1])
				ii += 1
			else:
				break
		while len(po) > i+1:
			hq.heappop(po)
	ans += sum(po)
	po = []
	ii = 0
	for i in range(n):
		while ii < len(R):
			if R[ii][0] == i+1:
				hq.heappush(po,R[ii][1])
				ii += 1
			else:
				break
		while len(po) > i:
			hq.heappop(po)
	ans += sum(po)
	print(ans)



Measured memory_bytes: 108168
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (ll i=0; i < (n); ++i)
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> inline bool change(T& a, T b) { if (a != b) { a = b; return 1; } return 0; }
using namespace std;

int main(){
    int l,r,d; cin >> l >> r >> d;
    int ans=0;
    for(int i=l;i<=r;i++){
        if(i%d==0) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    ll n;
    scanf("%d", &n);
    if (n == 1) {
        printf("0");
        return 0;
    }
    printf("%lld", n * (n - 1) / 2);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;
int main(){ 
   int n;
   cin>>n;
   int ans=0;
   for(int i=1;i*i<=n;i++){
      ans=max(ans,i*i);
   }
   cout<<ans;
   
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
const long d = 1000000007;

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
	int n;
	while(cin>>n&&n!=0){
		int p,a,b,c,d,e,f,s,m;
		string l;
		vector<pair<double,string> > vpii;
		for(int i = 0; i < n; i++){
			cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
			int time = a+b+c+d+e;
			for(int j = 1; j < m; j++)
				time+=d+e;
			int income=-p;
			for(int j = 0; j < m; j++)
				income+=s*f;
			double rate=(double)income/time;
			vpii.push_back(make_pair(-rate,l));
		}
		sort(vpii.begin(),vpii.end());
		for(int i = 0; i < vpii.size(); i++){
			cout<<vpii[i].second<<endl;
		}
		cout<<"#"<<endl;
	}

	return 0;
}

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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}

int main()
{
	cout <<setprecision(10);
	int x ; int y;
	cin >> x >> y;
	int three = 100000;
	int two = 200000;
	int one = 300000;
	int ans = 0;
	if(x <=3 ){
		ans += (4-x) * 100000;
	}
	if(y <= 3){
		ans += (4-y) * 100000;
	}
	if(x==1&&y==1) ans += 400000;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p,a,b) for(ll p=a ; p<b ; p++)
#define rap(p,a,b) for(ll p=a ; p<=b ; p++)
#define per(p,a,b) for(ll p=a ; p>=b ; p--)
#define F first
#define S second
using namespace std;

typedef vector <ll> vll;
typedef vector <ld> vld;
typedef pair< ll ,ll > pll;


int main()
{
    ll t,i,j,k,ans,n;

    //cin>>t;
    t=1;
    while(t--)
    {
        ll h,sum=0;
        cin>>h>>n;
        rep(p,0,n)
        {
            cin>>k;
            sum+=k;
        }

        sum>=h?cout<<"Yes":cout<<"No";
    }
    
    return 0;
}

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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define output(x) cout << ( x ? "Yes" : "No" ) << '\n' ;
#define mxn 100005
using namespace std;

void solve(){
    int n,m,k;
    cin >> n >> m >> k;
    map<pair<int,int>,int> mp;
    vector<pair<int,int>> row(n,{0,0}),col(m,{0,0});
    for(int i = 0; i < k; i++){
        int x,y;
        cin >> x >> y;
        x--;y--;
        mp[{x,y}] = 1;
        row[x].first++;
        col[y].first++;
    }
    for(int i = 0; i < n; i++){
        row[i].second = i;
    }
    for(int j = 0; j < m; j++){
        col[j].second = j;
    }
    sort(all(row));
    sort(all(col));
    int i = n - 1,j = m - 1;
    int ans = 0;
    while(i >= 0 || j >= 0){
        int cur = row[i].first + col[j].first - (mp[{row[i].second,col[j].second}] == 1);
        ans = max(ans,cur);
        if(j > 0){
            cur = row[i].first + col[j - 1].first - (mp[{row[i].second,col[j - 1].second}] == 1);
            ans = max(ans,cur);
        }
        if(i > 0){
            cur = row[i - 1].first + col[j].first - (mp[{row[i - 1].second,col[j].second}] == 1);
            ans = max(ans,cur);
        }
        if(i <= 0 && j <= 0){
            break;
        }
        else if(i == 0){
            j--;
        }
        else if(j == 0){
            i--;
        }
        else{
            i--;j--;
        }
    }
    for(int j = 0; j < m; j++){
        int cur = row[n - 1].first + col[j].first - (mp[{row[n - 1].second,col[j].second}] == 1);
        ans = max(ans,cur);
        if(n - 2 >= 0){
            cur = row[n - 2].first + col[j].first - (mp[{row[n - 2].second,col[j].second}] == 1);
            ans = max(ans,cur);
        }
    }
    for(int i = 0; i < n; i++){
        int cur = row[i].first + col[m - 1].first - (mp[{row[i].second,col[m - 1].second}] == 1);
        ans = max(ans,cur);
        if(m - 2 >= 0){
            cur = row[i].first + col[m - 2].first - (mp[{row[i].second,col[m - 2].second}] == 1);
            ans = max(ans,cur);
        }
    }
    cout << ans ;
}

int32_t main()
{
    FLASH
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}



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

long long n,a[3005],b[3005],conta,contb,cont;
string s,dp[3005],tmp1,tmp2;
vector<pair<int,char> > v; 

int main(){

	cin>>n>>s;
	
	for(int i=0;i<2*n;i++){
	    if(s[i]=='a')a[conta++]=i;
	    else b[contb++]=i;
    }
    
    dp[n]="";
    for(int i=n-1;i>=0;i--){
        tmp1=dp[i+1];
        tmp2.clear();
        cont=i;
        
        if(a[i]<b[i]){
            while(cont<n && a[cont]<b[i])cont++;
            
            tmp2="ab"+dp[cont];
        }
        else{
            v.clear();
            v.push_back({a[cont],'a'});
            v.push_back({b[cont],'b'});
            while(cont+1<n && b[cont+1]<a[cont]){
            cont++;
            v.push_back({a[cont],'a'});
            v.push_back({b[cont],'b'});
            }
            sort(v.begin(),v.end());
            for(int j=0;j<v.size();j++)tmp2.push_back(v[j].second);
            tmp2=tmp2+dp[cont+1];
        }
        
        
        dp[i]=max(tmp1,tmp2);
    }
	
	cout<<dp[0];
	
return 0;
}


Measured memory_bytes: 14720
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n=int(input())
s=["".join(sorted(list(input()))) for i in range(n)]
from collections import Counter
hoge=Counter(s)
res = 0
for key,value in hoge.items():
  if(value >= 2):
    res += combinations_count(value, 2)
print(res)
  


Measured memory_bytes: 19776
from collections import Counter

N = int(input())
S = []
for i in range(N):
    S.append(input())

counter = Counter(S)
counts = counter.most_common()
maxcnt = counts[0][1]
ans = []
for count in counts:
    if count[1] != maxcnt:
        break
    else:
        ans.append(count[0])
ans.sort()
for a in ans:
    print(a)

Measured memory_bytes: 47668
/*
 *  Author: Arpit Bhayani
 *  https://arpitbhayani.me
 */
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <deque>
#include <iostream>
#include <list>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

#define ll long long

#define MIN(a, b) a < b ? a : b
#define MAX(a, b) a > b ? a : b

using namespace std;

int readline(char *str) {
    int i = 0;
    char ch;
    while((ch = getchar()) != '\n') {
        str[i++] = ch;
    }
    str[i] = '\0';
    return i;
}

int arr1[200001];
int arr2[200001];

int foo(int n, int m, ll int x) {
    ll int sum = 0;
    int i = 0, j = 0;
    int count = 0;

    while (i < n) {
        sum += (ll int) arr1[i];
        i++;
        if (sum > x) {
            i--;
            sum -= (ll int) arr1[i];
            break;
        }
    }
    count = i;

    while (j < m) {
        sum += (ll int) arr2[j];
        j++;
        while (sum > x && i > 0) {
            i--;
            sum -= (ll int) arr1[i];
        }
        count = (sum <= x) ? MAX( (count), (i + j) ) : count;
    }

    return count;
}

int main(int argc, char *argv[]) {
    
        ll int x;
        int n, m;
        scanf("%d%d%lld", &n, &m, &x);

        for (int i = 0 ; i < n; i++) {
            scanf("%d", &arr1[i]);
        }

        for (int j = 0 ; j < m; j++) {
            scanf("%d", &arr2[j]);
        }

        printf("%d\n", foo(n, m, x));
   
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll dp[100005][105];
int main() {
    //cout.precision(10);
    int n, W;
    cin >> n >> W;
    for(int i = 1; i <= n; i++){
        int w;
        ll v;
        cin >> w >> v;
        for(int j = 0; j <= W; j++){
            dp[j][i] = dp[j][i - 1];
            if(j - w >= 0){
                dp[j][i] = max(dp[j][i], dp[j - w][i - 1] + v);
            }
        }
    }
    cout << dp[W][n] << endl;
    return 0;
}


Measured memory_bytes: 82304