akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
using namespace std;
typedef pair<int,int> P;
int h,w;
char s[50][50];
long long int d[50][50];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int search(){
    queue<P> que;
    que.push(P(0,0));
    d[0][0] = 0;
    while(que.size()){
        P p = que.front(); que.pop();
        int y = p.first;
        int x = p.second;
        if(x == w-1 && y == h-1){
            continue;
        }
        for(int i=0;i<4;i++){
            int nx = x + dx[i], ny = y + dy[i];
            if(0 <= nx && nx < w && 0 <= ny && ny < h && d[ny][nx] > d[y][x]+1 && s[ny][nx] != '#'){
                que.push(P(ny,nx));
                d[ny][nx] = d[y][x] + 1;
            }
        }
    }
    return d[h-1][w-1];
}
int main(){
    cin >> h >> w;
    int kuro = 0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> s[i][j];
            if(s[i][j] == '#') kuro++;
            d[i][j] = 1e8;   
        }
    }
    int res = search();
    int ans;
    if(res == 1e8) cout << -1 << endl;
    else cout << h*w - res - 1 - kuro << endl;
    return 0;
}

Measured memory_bytes: 256
n, y = gets.strip.split.map(&:to_i)
 
(0..n).each do |i|
  (0..(n-i)).each do |j|
    if y == 10000*i + 5000*j + 1000*(n-i-j)
      puts "#{i} #{j} #{n-i-j}"
      exit
    end
  end
end
 
puts "-1 -1 -1"


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;



int main()
{
	ll n,a,t[100005]={},ans[2]={},r=0,k;
	cin>>n;
	map<ll,ll>m;
	for(ll i=0;i<n;i++)
	{
		cin>>a;
		m[a]++;
	}
	vector<ll>v;
	for(auto i=m.begin();i!=m.end();i++) 
	{
		ll s=i->second;
		if(s>=4)r=i->first;
		if(s>=2)v.push_back(i->first);
	}
	if(v.size()<2)k=0;
	else k=v[v.size()-1]*v[v.size()-2];
	cout<<max(r*r,k)<<endl;	
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
#include <cmath>
#include <cstring>
using namespace std;
int main()
{
    int a,b,c,d;
    while(scanf("%d %d %d %d",&a,&b,&c,&d)!=EOF)
    {
        int temp;
        temp=abs(a-c);
        int temp1=abs(a-b);
        int temp2=abs(b-c);
        if(temp<=d)
         printf("Yes\n");
        else if(temp1<=d&&temp2<=d)
            printf("Yes\n");
        else
            printf("No\n");
    }
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

res = 0
mod = 10**9 + 7

sum_A = 0
for i in range(N):
  sum_A += A[i]

for i in range(N-1):
  sum_A -= A[i]
  res += sum_A * A[i]
  
print(res % mod)

Measured memory_bytes: 31444
<?php
fscanf(STDIN, "%d", $K);
$ans = 1;
$num = 7;
$arr = [];
while ($num % $K !== 0) {
    $m = $num % $K;
    if (isset($arr[$m])) {
        $ans = -1;
        break;
    }
    $arr[$m] = 1;
    $num = $num * 10 + 7;
    $num %= $K;
    $ans++;
}
printf("%d", $ans);


Measured memory_bytes: 57764
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>

#include <math.h>

using namespace std;

int main()
{
	double a, b, C;
	cin >> a >> b >> C;

	double angle = C * M_PI / 180.0;

	double S = 0.5 * a * b * sin(angle);
	cout << fixed << setprecision(8) << S << endl;

	double c = sqrt(a*a + b*b - 2*a*b*cos(angle));
	double l = a + b + c;
	cout << l << endl;

	double h = b * sin(angle);
	cout << h << endl;

}


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

int main(){
  string A,B;
  cin >> A >> B;
  int An,Bn;
  cin >> An >> Bn;
  string C;
  cin >> C;
  if (C == A) {
    An -=1;
  }
  else {
    Bn -=1;
  }
  cout << An <<' ' << Bn << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using i64 = int64_t;
#define rep(i, s, n) for (i64 i = (s); i < (n); ++i)

void run() {
  const i64 big{10000000000};
  i64 n;
  cin >> n;
  i64 amax{-big}, amin{big}, smax{-big}, smin{big};
  rep(i, 0, n){
    i64 x, y;
    cin >> x >> y;
    i64 a{x + y}, s{x - y};
    amax = max(a, amax);
    amin = min(a, amin);
    smax = max(s, smax);
    smin = min(s, smin);
  }
  cout << max(amax - amin, smax - smin) << endl;
}

int main() {
  cin.tie(nullptr);
  run();
  return 0;
}


Measured memory_bytes: 3188
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

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

    for(int i = 0; i < s.size(); i++){
        cout << 'x';
    }
    cout << endl;
}

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

using namespace std;

int main()
{
	string o, e;
	cin >> o >> e;
	for (int i = 0; i < e.length(); i++) {
		cout << o[i];
		cout << e[i];
	}
	if (o.length() == e.length()) {
		cout << endl;
	}
	else {
		cout << o[o.length() - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 string Y;
  string G;
  int ans = 0;
  cin >> Y >> G;
  for(int i = 0; i < 3; i++){
   if(Y[i] == G[i]) ans++; 
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 256
N,M=map(int, input().split())
G=[[] for _ in range(N)]
for i in range(M):
    a,b=map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

siru=[-1]*(N-1)#2~~N
que=[0]

while len(que)>0:
    #print(que)
    now=que.pop(0)
    nexlist=G[now]
    for nex in nexlist:
        if nex==0:
            continue
        if siru[nex-1]==-1:
            siru[nex-1]=now
            que.append(nex)
X=siru.count(-1)
if X>=1:
    print("No")
else:
    print("Yes")
    for num in siru:
        print(num+1)


Measured memory_bytes: 33640
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        
        int a = stdIn.nextInt();
        String s = stdIn.next();
        
        if(a >= 3200){
            System.out.println(s);
        }else{
            System.out.println("red");
        }
    }
}


Measured memory_bytes: 21332
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef pair<int,int> P;
typedef long long ll;

ll num[200010]={0};

int main(void){
    ll n;
    cin>>n;
    vector<ll>a(n+1),b(n+1),c;
    for(ll i=0;i<n;i++)cin>>a[i+1];
    for(ll i=n;i>=1;i--){
        if(num[i]%2==0){
            if(a[i]==0)b[i]=0;
            else{
                b[i]=1;
                for(ll j=1;j<=(ll)sqrt(i);j++){
                    if(i%j==0){
                        num[j]++;
                        if(j==i/j)continue;
                        num[i/j]++;
                    }
                }
            }
        }
        else{
            if(a[i]==1)b[i]=0;
            else{
                b[i]=1;
                for(ll j=1;j<=(ll)sqrt(i);j++){
                    if(i%j==0){
                        num[j]++;
                        if(j==i/j)continue;
                        num[i/j]++;
                    }
                }
            }
        }
    }
    for(ll i=1;i<=n;i++){
        if(b[i])c.push_back(i);
    }
    if((ll)c.size()==0){
        cout<<0<<endl;
        return 0;
    }
    cout<<(ll)c.size()<<endl;
    for(ll i=0;i<(ll)c.size();i++){
        if(i==(ll)c.size()-1)cout<<c[i]<<endl;
        else cout<<c[i]<<" ";
    }
    return 0;
}


Measured memory_bytes: 6516
k,n = map(int,input().split())
a = list(map(int,input().split()))

for i in range(n):
  if i == 0:
    sa = a[i + 1] - a[i]
  elif i == (n - 1):
    if sa < (k + a[0]) - a[i]:
      sa = (k + a[0]) - a[i]
  else:
    if sa < a[i + 1] - a[i]:
      sa = a[i + 1] - a[i]

min = k - sa
print(min)

Measured memory_bytes: 33212
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF=int(1e9);
double A,B,C,D,E,F;
double Ai,Bi;
double maxx1=-1,maxx2=1;
int main()
{
    cin>>A>>B>>C>>D>>E>>F;
    Ai=A*E; Bi=B*E;
    double tan,kefan,sum;
    for(int a=0;a*A*100<=F;a++)
    for(int b=0;b*B*100<=F-a*A*100;b++)
    for(int c=0;c*C<=F-a*A*100-b*B*100;c++)
    for(int d=0;d*D<=F-a*A*100-b*B*100-c*C;d++)
    {
        tan=c*C+d*D;
        sum=A*a*100+B*b*100+tan;
        kefan=Ai*a+Bi*b;
        if(kefan<tan||sum>F)continue;
        if(sum!=0&&tan/sum>maxx2/maxx1){
            maxx1=sum;
            maxx2=tan;
        }
    }
    cout<<int(maxx1)<<" "<<int(maxx2)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double PI = 3.14159265358979323846;
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0; i < (n); ++i)

int main() {
  ll n, ans = 0;
  cin >> n;
  for (ll i = 1; i <= n; i += 2) {
    ll count = 0;
    ll j = 0;
    for (j = 1; j * j < i; j += 2) {
      if (i % j == 0) count += 2;
    }
    if (j * j == i) count++;
    // if (i % (ll)sqrt(i) == 0) count++;
    if (count == 8) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define inf (int)(1e18)

int ABS(int a){
	return a >= 0 ? a : -a;
}

int max(int a, int b){
	return a >=b ? a : b;
}

int min(int a, int b){
	return a <= b ? a : b;
}

int sub(int h, int i, int j, int *sum){
	int Q = sum[h] - sum[i];
	int R = sum[j] - sum[h];
	return ABS(Q - R);
}
/*
int maxmin(int P, int S, int h, int *sum, int i, int j){
	int Q = sum[h] - sum[i];
	int R = sum[j + 1] - sum[h];
	return max(max(P, Q), max(R, S)) - min(min(P, Q), min(R, S));
}
*/
signed main(){
	int N, i, j, k, P, Q, R, S;
	scanf("%lld", &N);
	int *A = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
	}
	int *sum = (int *)malloc(sizeof(int) * (N + 1));
	sum[0] = 0;
	for(i = 1; i <= N; i++){
		sum[i] = sum[i - 1] + A[i - 1];
	}
	int l ,h1, h2, r, ans = inf;
	for(k = 2; k <= N - 2; k++){
		l = 0;
		r = k;
		while(r - l > 2){
			h1 = (r + 2 * l) / 3;
			h2 = (2 * r + l) / 3;
			if(sub(h1, 0, k, sum) < sub(h2, 0, k, sum)){
				r = h2;
			}
			else{
				l = h1;
			}
		}
		if(sub(l, 0, k, sum) < sub(r, 0, k, sum) && sub(l, 0, k, sum) < sub((l + r) / 2, 0, k, sum)){
			P = sum[l] - sum[0];
			Q = sum[k] - sum[l];
		}
		else if(sub(r, 0, k, sum) < sub((l + r) / 2, 0, k, sum)){
			P = sum[r] - sum[0];
			Q = sum[k] - sum[r];
		}
		else{
			P = sum[(r + l) / 2] - sum[0];
			Q = sum[k] - sum[(r + l) / 2];
		}

		l = k;
		r = N;
		while(r - l > 2){
			h1 = (r + 2 * l) / 3;
			h2 = (2 * r + l) / 3;
			if(sub(h1, k, N, sum) < sub(h2, k, N, sum)){
				r = h2;
			}
			else{
				l = h1;
			}
		}
		if(sub(l, k, N, sum) < sub(r, k, N, sum) && sub(l, k, N, sum) < sub((l + r) / 2, k, N, sum)){
			R = sum[l] - sum[k];
			S = sum[N] - sum[l];
		}
		else if(sub(r, 0, k, sum) < sub((l + r) / 2, 0, k, sum)){
			R = sum[r] - sum[k];
			S = sum[N] - sum[r];
		}
		else{
			R = sum[(r + l) / 2] - sum[k];
			S = sum[N] - sum[(r + l) / 2];
		}
		ans = min(ans, max(max(P, Q), max(R, S)) - min(min(P, Q), min(R, S)));
	}
	printf("%lld\n", ans);
	return 0;



/*	P = A[0];
	S = 0;
	int ans = inf;
	for(i = 1, j = N - 1; i < j; ){
		if(P < S){
			P += A[i];
			i++;
		}
		else if(P > S){
			S += A[j];
			j--;
		}
		else{
			if(A[i] < A[j]){
				P += A[i];
				i++;
			}
			else{
				S += A[j];
				j--;
			}
		}
		int l = i;
		int r = j;
		int h1, h2;
		while(r - l > 2){
			h1 = (r + 2 * l) / 3;
			h2 = (2 * r + l) / 3;
			if(sub(h1, i, j, sum) < sub(h2, i, j, sum)){
				r = h2;
			}
			else{
				l = h1;
			}
		}
		ans = min(min(ans, maxmin(P, S, (l + r) / 2, sum, i, j)), min(maxmin(P, S, l, sum, i, j), maxmin(P, S, r, sum, i, j)));
	}
	printf("%lld\n", ans);
	return 0;*/
}

Measured memory_bytes: 3328
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  sort(a.begin(), a.end());
  int ans = 1;
  function<int(int, int)> gcd = [&](int a, int b) { return b ? gcd(b, a % b) : a; };
  for (int i = 0; i < n; ++i)
    ans = ans * (ll)gcd(a[i], i) % 998244353;
  cout << ans;

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 640
s = input()
n = len(s)

ans = 0

for i in range(2**(n-1)):
  f = s[0]
  
  for j in range(n-1):
    if i & (1<<j):
      f += '+'
    f += s[j+1]
    
  ans += sum(map(int, f.split('+')))
  
print(ans)

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

using namespace std;

const int N = 2e5 + 5;
vector<int> adj[N];
int in[N] , sz[N] , nxt;

int dfs(int node , int par = -1) {
    in[node] = nxt++;
    sz[node] = 1;
    for (int child : adj[node])
        if (child != par)
            sz[node] += dfs(child  , node);
    return sz[node] ;
}

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

    int n , q;
    cin >> n >> q;

    for (int i = 0 ;i < n - 1 ;i++) {
        int u , v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dfs(1);

    vector<int> ans(n + 1 , 0);
    while (q--) {
        int u , inc;
        cin >> u >> inc;
        ans[in[u]] += inc;
        ans[in[u] + sz[u]] -= inc;
    }

    for (int i = 1 ;i < n ;i++)
        ans[i] += ans[i - 1];

    for (int i = 1 ;i <= n ;i++)
        cout << ans[in[i]] << ' ';
}

Measured memory_bytes: 25088
#include <iostream>

using namespace std;

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

    if (a > b)
    {
        cout << "a > b" << endl;
    }
    else if (a < b)
    {
        cout << "a < b" << endl;
    }
    else
    {
        cout << "a == b" << endl;
    }

    return 0;
}


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

#define MAX_N 300005
#define INF 0x3f3f3f3f3f3f3f3f

int n;
int a[MAX_N];

int main()
{
    scanf("%d",&n);
    for(int i=0; i<3*n; i++)
        scanf("%d",&a[i]);

    vector <long long> dp1(3*n ,-INF) ,dp2(3*n ,INF);
    multiset <int> ms;
    long long sum = 0LL;
    for(int i=0; i<3*n; i++){
        ms.insert(a[i]) ,sum += a[i];
        if(ms.size() > n){
            sum -= *ms.begin();
            ms.erase(ms.begin());
        }
        if(ms.size() == n)
            dp1[i] = sum;
    }
    sum = 0 ,ms.clear();
    for(int i=3*n-1; ~i; i--){
        ms.insert(a[i]) ,sum += a[i];
        if(ms.size() > n){
            sum -= *prev(ms.end());
            ms.erase(prev(ms.end()));
        }
        if(ms.size() == n)
            dp2[i] = sum;
    }

    long long ans = -INF;
    for(int i=0; i<3*n-1; i++)
        ans = max(ans ,dp1[i]-dp2[i+1]);
    printf("%lld\n",ans);
}


Measured memory_bytes: 10752
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;

typedef pair<string, int> P;

int main() {
	int n;
	while(cin >> n && n){
		int x[20], y[20];
		for(int i = 0; i < n; ++i)
			cin >> x[i] >> y[i];
		int m;
		cin >> m;
		queue<P> q;
		string s;
		int d;
		for(int i = 0; i < m; ++i){
			cin >> s >> d;
			q.push(P(s, d));
		}
		int c = n, nowx = 10, nowy = 10;
		bool ca[20] = {false};
		while(!q.empty()){
			P p = q.front(); q.pop();
			for(int i = 0; i < p.second; ++i){
				string str = p.first;
				if(str == "N") nowy++;
				else if(str == "E") nowx++;
				else if(str == "S") nowy--;
				else if(str == "W") nowx--;
				
				for(int j = 0; j < n; ++j){
					if(nowx == x[j] && nowy == y[j] && !ca[j]){
						ca[j] = true;
						c--;
					}
				}
				if(c == 0)
					break;
				
			}
		}
		if(c == 0)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000000000000000;
int main(){
  int N;
  cin >> N;
  vector<vector<int>> A(N, vector<int>(N));
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      cin >> A[i][j];
    }
  }
  long long ans = 0;
  bool ok = true;
  for (int i = 0; i < N; i++){
    for (int j = i + 1; j < N; j++){
      bool use = true;
      for (int k = 0; k < N; k++){
        if (k != i && k != j && A[i][j] == A[i][k] + A[k][j]){
          use = false;
        }
        if (A[i][j] > A[i][k] + A[k][j]){
          ok = false;
        }
      }
      if (use){
        ans += A[i][j];
      }
    }
  }
  if (!ok){
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}


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

#define int long long

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

signed main() {
    int N, a[51] = {};
    cin >> N;
    int p_max = 0, n_min = 0;
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
        if (a[i] >= a[p_max]) {
            p_max = i;
        }
        if (a[i] <= a[n_min]) {
            n_min = i;
        }
    }
    int c;
    if (abs(a[p_max]) > abs(a[n_min])) {
        c = p_max;
    } else {
        c = n_min;
    }
    cout << 2 * N - 1 << endl;
    for (int i = 1; i <= N; i++) {
        a[i] += a[c];
        cout << c << " " << i << endl;
    }
    int start, cond, inc;
    if (a[1] > 0) {
        start = 1, cond = N, inc = 1;
    } else {
        start = N, cond = 1, inc = -1;
    }
    for (int i = start; i != cond; i += inc) {
        cout << i << " " << i + inc << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    int xa = 0, ba = 0, bx = 0, inne = 0;
    int odp = 0;
    for (int i = 0; i < n; ++i)
    {
        string x;
        cin >> x;
        int d = x.size();
        for (int j = 1; j < d; ++j)
            if (x[j] == 'B' && x[j - 1] == 'A')
                ++odp;
        if (x[0] == 'B' && x[d - 1] == 'A')
            ++ba;
        else
        {
            if (x[0] != 'B' && x[d - 1] == 'A')
                ++xa;
            else
            {
                if (x[0] == 'B' && x[d - 1] != 'A')
                    ++bx;
                else
                    ++inne;
            }
        }
    }
    if (ba != 0)
        odp += ba - 1;
    if (ba != 0)
    {
        if (xa != 0)
        {
            ++odp;
            --xa;
        }
        if (bx != 0)
        {
            ++odp;
            --bx;
        }
    }
    odp += min(xa, bx);
    cout << odp;
    return 0;
}


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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main() {
    ll l, r;
    cin >> l >> r;
    ll d = r-l;
    if(d>=2020){
        cout << 0 << endl;
        return 0;
    }
    ll ans = inf;
    lrep(i, l, r){
        lrep(j, i+1, r+1){
            ans = min(ans,(i%2019)*(j%2019)%2019);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
local n=io.read("*n","*l")
local s=tostring(io.read())

local t={}
for i=0,9 do
    for j=0,9 do
        for k=0,9 do
            pin=tostring(i..j..k)
            table.insert(t,pin)
        end
    end
end

local counter=0
for i=1,1000 do
    k=t[i]
    a,b=0,0
    for j=1,n do
        if s:sub(j,j)==k:sub(1,1) then
            a=j
            break
        end
    end
    if a>0 then
        for j=a+1,n do
            if s:sub(j,j)==k:sub(2,2) then
                b=j
                break
            end
        end
        if b>0 then
            for j=b+1,n do
                if s:sub(j,j)==k:sub(3,3) then
                    counter=counter+1
                    break
                end
            end
        end
    end
end
print(counter)

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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)

// policy-based
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;	


using namespace std;


typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

/*
typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
 
const ll MAX = 4e5+100;
const ll inf = 1e15;

ll fil[MAX],col[MAX];
map< ii ,ll > t;
int main(){
	fastio;
	ll n,m,x,a,b;
	cin >> n >> m >> x;
	f(i,0,x){
		cin >> a >> b;
		fil[a]++;
		col[b]++;
		t[{a,b}] = 1;
	}
	ll maxi1 = 0,maxi2  = 0;
	f(i,0,MAX) if(fil[i] > maxi1) maxi1 = fil[i];
	f(i,0,MAX) if(col[i] > maxi2) maxi2 = col[i];
	vi p,q;
	f(i,0,MAX) if(fil[i] == maxi1) p.push_back(i);
	f(i,0,MAX) if(col[i] == maxi2) q.push_back(i);
	if(p.size() * q.size() >= MAX){
		cout << maxi1 + maxi2 << endl;
	}
	else{
		for(ll u:p){
			for(ll v:q){
				if(t[{u,v}] == 0){
					cout << maxi1 + maxi2 << endl;
					return 0;
				}
			}
		}
		cout << maxi1 + maxi2  - 1 << endl;
	}
}

Measured memory_bytes: 35032
<?php
$N=fgets(STDIN);
$A=explode(" ",trim(fgets(STDIN)));
$count=0;
while (true) {
  // code...
  for ($i=0; $i <$N-1 ; $i++) {
    // code...
    if($A[$i]%2==0){
      $A[$i]=$A[$i]/2;
    }else{
      break 2;
    }
  }
  $count++;
}
echo $count;

 ?>


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i < (n);i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define SCANF(i) int i;scanf("%d",&i)
typedef long long ll;
using namespace std;
using P = pair<int,int>;
const long long INF = 1LL << 60;
const int IINF=100000000;
const int MOD = (int)1e9 + 7;
//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
vector<int> dx={1,0,-1,0};vector<int> dy={0,-1,0,1};

signed main () {
    ll n;cin >> n;
    vector<ll> inlist(n);
    REP(i,n)cin >> inlist[i];
    ll ans = 0;
    FOR(i,1,n){
        ll dif = inlist[i-1] - inlist[i]; 
        if(dif>0){
            ans+=dif;
            inlist[i]=inlist[i-1];
        }
    }
    cout << ans << endl;
}//https://atcoder.jp/contests/abc176/tasks/abc176_c

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

int main(){
    int n; cin >> n; int64_t ans = 0;
    vector<int64_t> a(n), b(n);
    priority_queue<pair<int64_t, int>> que;
    for (auto i = 0; i < n; i++) {
        cin >> a[i] >> b[i]; que.push({{a[i] + b[i]}, i});
    }
    for (auto i = 0; i < n; i++) {
        auto p = que.top(); que.pop();
        if(i % 2 == 0) ans += a[p.second];
        else ans -= b[p.second];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6872
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 200000;
const int MOD = 1000000007;

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;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % 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;
}
struct edge {
	int t;
	ll cost;
	edge(int _t, ll _cost) : t(_t)
		, cost(_cost) {
	}
};
bool isPrime(int n) {

	if (n == 1) return false;
	for (ll i = 2; i * i <= n; i++)
	{
		if (n % i == 0) return false;
	}
	return true;
}
int anyDigitSum(int n) {
	int res = 0;
	while (n > 0)
	{
		res += n % 10;
		n /= 10;
	}
	return res;
}
ll f(double n) {

	n *= n;
	n += 4.0;
	return n / 8.0;
}
ll calc(ll a, ll b, ll c) {
	int half = a / 2;
	if (a % 2 == 0) {
		return 0;
	}
	else {
		return b * c;
	}

}
void Solve() {
	int n;
	cin >> n;
	string s, t;
	cin >> s;
	cin >> t;
	string res = s + t;
	for (size_t i = 1; i <= n; i++)
	{
		bool ok = true;
		for (size_t j = 0; j < i; j++)
		{
			if (s[n - i + j] != t[j]) {
				ok = false;
				break;
			}
		}
		if (!ok) continue;
		string tm = "";
		res = s + t.substr(i, n - i);
	}
	cout << res.size() << endl;
}
int main() {
	Solve();
	return 0;
}



Measured memory_bytes: 256
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!{
        n: usize, a: i32, b: i32, c:i32,
        ls: [i32; n],
    }
    let solver = Solver{ a:a, b:b, c:c, n:n, ls:ls };
    println!("{}", solver.solve(0,0,0,0));
}

struct Solver {
    a: i32,
    b: i32,
    c: i32,
    n: usize,
    ls: Vec<i32>
}

impl Solver {
    fn solve(&self, num: usize, ca:i32, cb:i32, cc:i32) -> i32 {
        if num == self.n {
            return if *[ca,cb,cc].iter().min().unwrap() > 0 {
                (ca-self.a).abs() + (cb-self.b).abs() + (cc-self.c).abs() - 30
            } else {
                std::i32::MAX - 10
            }
        }
        let sx = self.solve(num + 1, ca, cb, cc);
        let sa = self.solve(num + 1, ca + self.ls[num], cb, cc) + 10;
        let sb = self.solve(num + 1, ca, cb + self.ls[num], cc) + 10;
        let sc = self.solve(num + 1, ca, cb, cc + self.ls[num]) + 10;
        *[sx,sa,sb,sc].iter().min().unwrap()
    }
}


Measured memory_bytes: 4352
a,b = list(map(int,input().split()))
x = [1]

for i in range(2,1000):
    v = x[i-2] + i
    x.append(v)
#print(x)

for i in range(1,len(x)):
    if x[i-1]-a == x[i]-b:
        ans = x[i-1] - a
        break
print(ans)

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

char field[101][101];
int N, n, now;
int x, y;
bool flag;

void print(){
  for(int i = 0 ; i <= n ; i++){
    for(int j = 0 ; j <= n ; j++){
      cout << field[i][j];
    }
    cout << endl;
  }
}

void init(){
  flag = false;
  for(int i = 0 ; i < 101 ; i++){
    for(int j = 0 ; j < 101 ; j++){
      field[i][j] = ' ';
    }
  }
  for(int i = n ; i >= 0 ; i--){
    field[i][0] = '#';
  }
  for(int i = 0 ; i < n ; i++){
    field[0][i] = '#';
  }
  for(int i = 0 ; i <= n ; i++){
    field[i][n] = '#';
  }
}

void left(){
  int j;
  for(j = x ; field[y][j-1] != '#' ; j--){
    field[y][j] = '#';
  }
  x = j+1;
}

void up(){
  int i;
  for(i = y ; field[i-1][x] != '#' ; i--){
    field[i][x] = '#';
  }
  y = i+1;
}

void right(){
  int j;
  for(j = x ; field[y][j+1] != '#' ; j++){
    field[y][j] = '#';
  }
  x = j-1;  
}

void down(){
  int i;
  for(i = y ; field[i+1][x] != '#' ; i++){
    field[i][x] = '#';
  }
  y = i-1;
}

    
int main(){
  cin >> N;
  for(int cs = 0 ; cs < N ; cs++){
    cin >> n;
    n--;
    
    if(n == 0) cout << '#' << endl << endl;
    else if(n == 1){
      cout << "##" << endl << "# " << endl << endl;
    }
    else{
    init();
    x = n, y = n;
    int cnt = 3;
    while(1){
      if(cnt == n+1) break;
      left();
      cnt++;
      if(cnt == n+1) break;
      up();
      cnt++;
      if(cnt == n+1) break;
      right();
      cnt++;
      if(cnt == n+1) break;
      down();
      cnt++;
    }
    print();
    if(cs != N-1) cout << endl;
    }
  } 
  return 0;
}
    

    
    

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

int main() {
	int N;
	int64_t L0 = 2, L1 = 1;
	cin >> N;
	for (int i = 2;i <= N;i ++) {
		if (i % 2 == 0) L0 += L1;
		else L1 += L0;
	}
	cout << (N % 2 == 0 ? L0 : L1);
	return 0;
}

Measured memory_bytes: 256
import sys


class UnionFind:
    def __init__(self, n):
        self.root = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1] * (n+1)

    def find(self, x):
        if self.root[x] == x:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] == self.rank[y]:
          self.rank[x] += 1
          self.root[y] = x
          self.size[x] += self.size[y]
        elif self.rank[x] < self.rank[y]:
            self.root[x] = y
            self.size[y] += self.size[x]
        else:
            self.root[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)


def main():
  input = sys.stdin.readline
  N, M = map(int, input().split())
  total = N * (N-1) // 2
  Bridge = []
  for _ in range(M):
    a, b = map(int, input().split())
    Bridge.append([a, b])
  Bridge = Bridge[::-1]
  
  uf = UnionFind(N)
  ans = [0 for _ in range(M+1)]
  for i in range(M):
    a, b = Bridge[i][0], Bridge[i][1]
    if uf.is_same(a, b):
      ans[i+1] = ans[i]
    else:
      a_root = uf.find(a)
      b_root = uf.find(b)
      a_size = uf.size[a_root]
      b_size = uf.size[b_root]
      
      ans[i+1] = ans[i] + a_size * b_size
      uf.unite(a, b)    

  ans = ans[::-1]
  for i in ans[1:M+1]:
    print(total - i)


if __name__ == '__main__':
  main()


Measured memory_bytes: 30564
#include <stdio.h>

char fld[12][12];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

void F(int x, int y)
{
    if (x < 0 || 12 <= x || y < 0 || 12 <= y || fld[y][x] == '0') return;
    fld[y][x] = '0';
    int i;
    for (i = 0; i < 4; i++)
    {
        F(x + dx[i], y + dy[i]);
    }
}

int main()
{
    int i, j;
    while (1)
    {
        for (i = 0; i < 12; i++)
        {
            for (j = 0; j < 12; j++)
            {
                if (scanf(" %c", &fld[i][j]) == EOF) return 0;
            }
        }
        int ans = 0;
        for (i = 0; i < 12; i++)
        {
            for (j = 0; j < 12; j++)
            {
                if (fld[i][j] == '1')
                {
                    F(j, i);
                    ans++;
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 544
#include <bits/stdc++.h>
#define int long long
#define FLASH                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

const int MAX = 3000000;
const int P = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

void COMBinit()
{
    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 % P;
        inv[i] = P - inv[P % i] * (P / i) % P;
        finv[i] = finv[i - 1] * inv[i] % P;
    }
}

int COMB(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % P) % P;
}

signed main()
{
    COMBinit();
    int X, Y;
    cin >> X >> Y;
    int K = X + Y;
    if (K % 3 != 0)
        return cout << 0, 0;
    int n = (2*Y - X) / 3;
    int m = (2*X - Y) / 3;
    if (n < 0 || m < 0)
        return cout << 0, 0;
    cout << COMB(n+m, n);
    return 0;
}

Measured memory_bytes: 73912
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] P = new int[N];
        for ( int i = 0; i < N; i++ ) P[i] = sc.nextInt();

        int ans = 0;
        for ( int A = 0; A <= 100; A++ ){
            int cnt = 0;
            for ( int i = 0; i < N; i++ ){
                if ( A <= P[i] ) cnt++;
            }
            if ( A <= cnt ) ans = A;
        }

        System.out.println(ans);
    }

    public static void main(String[] a){
        new Main().solve();
    }
}



Measured memory_bytes: 26372
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
using namespace std;

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



int main() {
	string s, t;
	cin >> s >> t;

	for (int i = 0; i < s.length(); i++) {
		if (s[i] != t[i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

}

Measured memory_bytes: 3548
def binary_search(array, target)
  head = 0
  tail = array.count - 1
  
  while head <= tail
    center = (head + tail) / 2
    if array[center] == target
      return center
    elsif array[center] < target
      head = center + 1
    else
      tail = center - 1
    end
  end
  tail
end

N = gets.to_i
array = []
N.times do
  val = gets.to_i
  diff = 1_000_000_001
  idx = nil
  if !array.empty? && array[0] < val
    idx = binary_search(array, val-1)
    idx += 1 if idx <= array.length-2 && array[idx+1] < val
  end
  if idx.nil?
    array.unshift(val)
  else
    array[idx] = val
    ((idx+1)..(array.length-1)).each do |i|
      break if array[i] >= array[i-1]
      array[i-1], array[i] = array[i], array[i-1]
    end
  end
  # puts "#{array}"
end

puts array.length


Measured memory_bytes: 4092
# http://tsutaj.hatenablog.com/entry/2017/03/29/204841
class SegmentTree:
    def __init__(self, v, func, init_val):
        self.func = func
        self.init_val = init_val

        sz = len(v)

        self.n = 1
        while self.n < sz:
            self.n *= 2

        self.node = [self.init_val for _ in range(2 * self.n - 1)]
        # 元配列 v をセグメント木で表現する
        # 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく
        # セグメント木全体で必要なノード数は 2n - 1 個である

        for i in range(sz):
            self.node[i + self.n - 1] = v[i]
        # 最下段に値を入れたあとに、下の段から順番に値を入れる

        for i in range(self.n - 2, -1, -1):
            self.node[i] = self.func(self.node[2 * i + 1], self.node[2 * i + 2])
        # 値を入れるには、自分の子の 2 値を参照すれば良い

    def update(self, x, val):
        x += self.n - 1
        # 最下段のノードにアクセスする

        self.node[x] = val
        while x > 0:
            x = (x - 1) // 2
            self.node[x] = self.func(self.node[2 * x + 1], self.node[2 * x + 2])
        # 最下段のノードを更新したら、あとは親に上って更新していく

    # 要求区間 [a, b) 中の要素の最小値を答える
    # k := 自分がいるノードのインデックス
    # 対象区間は [l, r) にあたる

    def get_val(self, a, b, k, l, r):
        if r <= a or b <= l: return self.init_val
        # 要求区間と対象区間が交わらない -> 適当に返す

        if a <= l and r <= b: return self.node[k]
        # 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う

        vl = self.get_val(a, b, 2 * k + 1, l, (l + r) // 2)
        vr = self.get_val(a, b, 2 * k + 2, (l + r) // 2, r)
        return self.func(vl, vr)
        # 要求区間が対象区間の一部を被覆 -> 子について探索を行う
        # 左側の子を vl ・ 右側の子を vr としている
        # 新しい対象区間は、現在の対象区間を半分に割ったもの


def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)


N = int(input())
a = tuple(map(int, input().split()))

st = SegmentTree(v=a, func=gcd, init_val=0)

g = max(
    gcd(
        st.get_val(0, drop_idx, 0, 0, st.n),
        st.get_val(drop_idx + 1, N, 0, 0, st.n)
    ) for drop_idx in range(N)
)
print(g)


Measured memory_bytes: 87944
// counting sort

import java.util.*;

public class Main {
	public static void main(String[] args)  {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] A = new int[n];
		for (int i = 0; i < n; i++) {
			A[i] = scanner.nextInt();
		}
		int p = partation(A, 0, n - 1);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			if (i == p) {
				sb.append("[").append(A[i]).append("]");
			} else {
				sb.append(A[i]);
			}
			sb.append((i != n - 1) ? " " : "\n");
		}
		System.out.print(sb);
	}
	public static int partation(int[] A, int p, int r) {
		int x = A[r];
		int i = p - 1;
		int t;
		for (int j = p; j < r; j++) {
			if (A[j] <= x) {
				i++;
				t = A[i];
				A[i] = A[j];
				A[j] = t;
			}
		}
		t = A[r];
		A[r] = A[i + 1];
		A[i + 1] = t;
		return i + 1;
	}	
}

Measured memory_bytes: 68668
#include<stdio.h>
int main(void){
	int A1,A2,A3,t,total;
	scanf("%d %d %d",&A1,&A2,&A3);
	if(A1>A2)
	{
	   t=A1;A1=A2;A2=t;
	}
	if(A2>A3)
	{
	   t=A2;A2=A3;A3=t;
	}
	if(A1>A2)
	{
	   t=A1;A1=A2;A2=t;
	}
	total=(A3-A2)+(A2-A1);
	printf("%d",total);
}

Measured memory_bytes: 128
#include <stdio.h>

int main ()
{
    int a, b;
    scanf("%d %d", &a, &b);
    if(a >= 1 && a <= 16 && b >= 1 && b <= 16)
    {
        if(a <= 8 && b <= 8)
        {
            printf("Yay!\n");
        }
        else
        {
            printf(":(\n");
        }
    }
    else
    {
        printf(":(\n");
    }
    return 0;
}


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

// Efficient program to print all prime factors of a given number
// https://www.geeksforgeeks.org/print-all-prime-factors-of-a-given-number/
// 与えられた正整数についての素因数分解を計算.
// @param X: 素因数分解を行う整数.
// @return ret: 素因数分解 の 結果 を 返却.
map<LL, int> div(LL X){
    
    // 1. X を 2で割り切れなくなるまで割っていく.
    map<LL, int> ret;
    while(X % 2 == 0) ret[2]++, X >>= 1;
    
    // 2. X を 3以上の奇数で, 割り切れなくなるまで順次割っていく.
    for(LL i = 3; i <= sqrt(X); i += 2){
        while(X % i == 0){
            ret[i]++;
            X /= i;
        }
    }
    
    // 3. X が 2 より 大きな素数であれば, 追加.
    if(X > 2) ret[X]++;
    
    // 4. 本問では, 1 も 追加.
    ret[1]++;
    
    // 5. 出力.
    return ret;
}

int main(){
    
    // 1. 入力情報取得.
    LL a, b;
    scanf("%lld %lld", &a, &b);
    
    // 2. a, b の 最大公約数.
    LL g = __gcd(a, b);
    // printf("g=%lld\n", g);
    
    // 3. g を 素因数分解.
    map<LL, int> m = div(g);
    // for(auto &p : m) printf("%lld ", p.first);
    // printf("\n");
    
    // 4. 出力 ～ 後処理.
    printf("%d\n", m.size());
    return 0;
    
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main()
{
	int a,n,i;
	cin>>a>>n;
	int b,count=0;
	for(i=1;i<=n;i++)
	{
		cin>>b;
		count+=b;
		if(count>=a)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	if(count>=a)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a,b,d,f,y,m,h;
    while(scanf("%d%d",&a,&b)!=EOF){
        m = b;
        h = a;
        if(a<b){
            int c = a;
            a = b;
            b = c;
        }
        while(1){
            d = a % b;
            if(d == 0)break;
            a = b;
            b = d;
        }
        y = h / b;
        f = y * m;
    printf("%d %d\n",b,f);
    }

    return 0;
}

Measured memory_bytes: 596
import heapq
def dijkstra(s, n, g): # s: start, n: |V|, g; glaph 
    INF = 10**18
    prev_vl = [-1]*n # record the prev vertex of each one for restoring the route
    d = [INF] * n
    d[s] = 0
    que = [] # (a,b): a... shortest dist, b... v
    heapq.heappush(que, (0, s))

    while que:
        dist, v = heapq.heappop(que)
        if d[v] < dist: continue # if v has been already used -> continue
        for next_v, cost in g[v]:
            if d[next_v] > d[v] + cost:
                d[next_v] = d[v] + cost
                prev_vl[next_v] = v
                heapq.heappush(que, (d[next_v], next_v))
    
    # resotre the route
    # route = [g]
    # curr_v = g
    # while True:
    #     prev_v = prev_vl[curr_v]
    #     if prev_v == -1: break
    #     else: route.append(prev_v)
    # route = route[::-1]
    # return d, route

    used_edges = []
    for i in range(n):
        if i == s: continue
        used_edges.append((prev_vl[i],i))
    return d, used_edges


n,m = map(int, input().split())
g = [ [] for _ in range(n)]
edges = [ [False]*n for _ in range(n)]

for _ in range(m):
    a,b,c = map(int, input().split())
    a-=1
    b-=1
    g[a].append((b,c))
    g[b].append((a,c))
    edges[a][b] = True
    edges[b][a] = True

for i in range(n):
    d, used_edges = dijkstra(i, n, g)
    for a,b in used_edges:
        edges[a][b] = False
        edges[b][a] = False

ans = 0
for i in range(n):
    for j in range(n):
        if edges[i][j]: ans += 1

print(ans//2)


Measured memory_bytes: 81112
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long a,b,d,flag=0;
    cin>>a>>b;
    if(a>b)
        d=a;
    else if(a<b)
        d=b;
   else if(a=b)
        {
            cout<<0;
            return 0;
        }
        for(long i=0;i<d;i++)
        {
            if(abs(a-i)==abs(b-i))
                {
                    cout<<i;
                    flag=1;
                   break;

                }
        }
        if(flag==0)
            cout<<"IMPOSSIBLE";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1000000000
#define mod 1000000007
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
int kaijo(int n){
	int ans=1;
	for(int i=2;i<=n;i++){
		ans*=i;
		ans%=mod;
	}
	return ans;
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%mod;
	return modpow(a,b/2)*modpow(a,b/2)%mod;
}
int n,m,a[111111],b[111111];
signed main(){
	cin>>n>>m;
	rep(i,m)cin>>a[i];
	sort(a,a+m);
	rep(i,m)b[i]=a[i+1]-a[i];
	sort(b,b+m-1);
	int ans=0;
	rep(i,m-n){
		ans+=b[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

const int nax=55;
int a[nax];
int n,k;
ll dp[nax][nax*nax];

int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int z=n;z>=1;z--)
        {
            for(int j=0;j<=2500;j++)
            {
                if(j<a[i]) continue;
                dp[z][j]+=dp[z-1][j-a[i]];
            }
        }
    }
    ll res=0;
    for(int i=1;i<=n;i++)
    {
        res+=dp[i][i*k];
    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 1408
#include <cstdio>

int main(void)
{
    while (1) {
        int h, w;
        scanf("%d %d", &h, &w);
        if (!h && !w)
            break;

        for (int y=0; y<h; y++) {
            for (int x=0; x<w; x++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m), c(m);
    vector<vector<int>> dist(n, vector<int>(n, 1e7));
    rep(i, n) dist[i][i] = 0;
    rep(i, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
        dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
    }
    rep(k, n) rep(i, n) rep(j, n) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }
    int ans = m;
    rep(i, m) {
        bool isCandidate = false;
        rep(s, n) rep(t, n) {
            if (s == t) continue;
            if (dist[s][t] == dist[s][a[i]] + c[i] + dist[b[i]][t]) {
                isCandidate = true;
            }
        }
        if (isCandidate) ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3676