akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 200005
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007
#define PI acos(-1.0)
#define eps 1e-9

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;

vector<int>edge[MAX];
int dp[2][MAX];
int cnt = 0;

void dfs(int u, int tt, int p = -1)
{
    for(auto v : edge[u])
    {
        if(v==p)
            continue;
        dp[tt][v] = dp[tt][u] + 1;
        dfs(v, tt, u);
    }
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    int n, x, y;
    cin>>n>>x>>y;
    for(int i = 1; i < n; i++)
    {
        int u, v;
        cin>>u>>v;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    dfs(x, 0);
    dfs(y, 1);
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        error(dp[1][i]);
        error(dp[0][i]);
        if(dp[1][i] > dp[0][i])
            ans = max(ans, dp[1][i]-1);
    }
    cout<<ans<<endl;

    //End();
    return 0;
}


Measured memory_bytes: 15232
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define INF 1000000000007
 

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


void solve()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(a>=k)
    {
        cout<<min(k,a)<<"\n";
        return;
    }
    if(a+b>=k)
    {
        cout<<a<<"\n";
        return;
    }
    ll rem=k-(a+b);
    ll no=(a)-rem;
    cout<<no<<"\n";
    
}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 3652
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
using namespace std;

#define N  100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll a,k,b;
        cin>>a>>b>>k;
        ll x=a;
        if(a<=k)
        	a=0;
        else
        {
        	a=a-k;
        	cout<<a<<" "<<b;
        	continue;
        }
        if(b>=k-x)
        	b=b-k+x;
        else
        	b=0;
        cout<<a<<" "<<b<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,x,i;
  cin>>N>>x;
  long long ans=0;

  long long a[N];
  for (i=0;i<N;i++)cin>>a[i];
  sort(a,a+N);
  //reverse(a,a+N);
  
  for (i=0;i<N;i++){
    x -= a[i];
    if(x>=0){
      ans++;
    }else{
      break;
    }
  }
  if(x<=0){
    cout << ans << endl;
  }else{
    cout << ans - 1 << endl;
  }
}

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

using namespace std;
int n,a,b;
int main(){
    cin >> n;
    if(n < 1000){
        cout << 1000 - n << endl;
        return 0;
    }
    a = n / 1000;
    b = n % 1000;
    if(b == 0)cout << a*1000 - n << endl;
    else cout << (a+1)*1000 - n << endl;
    }

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <string>
#include <cmath>
#include <algorithm>
#define DATA_NUM 10
#define swap(type, x, y) do{ type temp = x; x = y; y = temp;}while(0);

using namespace std;

void quick_sort(int x[], int left, int right);
int main(void) {
    int x[10] = {0};
    int i;
    
    for(i = 0; i < DATA_NUM; i++)
        scanf("%d", &x[i]);
    
    quick_sort(x, 0, DATA_NUM - 1);
    
    for(i = DATA_NUM - 1; i > 6; i--)
        cout << x[i] << endl;
    
    return(0);
}

void quick_sort(int x[], int left, int right) {
    int i, j;
    int pivot;
    
    i = left;
    j = right;
    
    pivot = x[(left + right) / 2];
    
    while(1) {
        while(x[i] < pivot) i++;
        while(x[j] > pivot) j--;
        
        if(i >= j) break;
        
        swap(int, x[i], x[j]);
        i++;
        j--;
    }
    if(i - 1 > left) quick_sort(x, left, i - 1);
    if(j + 1 < right) quick_sort(x, j + 1, right);
}

Measured memory_bytes: 1208
#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 = 510000;
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;
	edge(int _t) : t(_t) {}
};
bool use[100010];


vector<edge> te[100010];
vector<edge> fe[100010];
int t[64];
int d[100100];
ll rec(int num) {
	if (num == 0) return 0;
	return rec(num - 1) + num;
}

void Solve() {

	int n;
	ll x;
	cin >> n >> x;
	ll a[2010];
	ll best = 0;
	ll b[2010];

	for (size_t i = 0; i < n; i++)
	{
		cin >> a[i];
		best += a[i];
		b[i] = a[i];
	}

	for (int i = 1; i < n; i++)
	{
		ll bt[2010];
		ll sum = 0;
		for (size_t j = 0; j < n; j++)
		{
			int from = (j + n - i) % n;
			b[j] = min(b[j], a[from]);
			sum += b[j];
		}
		best = min(sum + i * x, best);

	}

	cout << (best) << endl;
}


int main() {
	Solve();
	return 0;
}



Measured memory_bytes: 6016
#include <iostream>

using namespace std;

void swap (unsigned long int* a) {
  unsigned long int store = *(a+1);
  *(a+1) = *a;
  *a = store;
}

int main () {
  int n;
  cin >> n;
  if (n < 1 || n > 86) {
    cout << "wrong entry\n";
    return 0;
  }
  unsigned long int a[] = {2,1};
  if (n != 1) {
    for (int i = 0; i < n-1; i++) {
      a[0] += a[1];
      swap(a);
    }

  }

  cout << a[1] << "\n";
  return 0;
}


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

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

	int left[n+1];
	int right[n+1];

	memset(left, 0, sizeof(left));
	memset(right, 0, sizeof(right));

	for(int i = 0; i < n; i++)
		left[i+1] = __gcd(left[i], a[i]);

	for(int i = n - 1; i >= 0; i--)
		right[i] = __gcd(right[i+1], a[i]);

	int ans = 0;
	for(int i = 0; i < n; i++)
		ans = max(ans, __gcd(left[i], right[i+1]));

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

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

typedef long long LL;

const int MAX_N = 1000005;
const int mod = 1e9 + 7;

LL pow_mod(LL a, LL k, LL m) {
    LL r = 1;
    for(;k>0; k>>=1) {
        if(k&1) r= (r*a)%m;
        a=(a*a)%m;
    }
    return r;
}

LL inverse(LL a, LL m) {
    return pow_mod(a, m-2, m);
}

int x, y;
LL fac[MAX_N], inv[MAX_N];
int main() {
    scanf("%d %d", &x, &y);
    int n = max(x, y);

    fac[0]=1;
    inv[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        fac[i] = (fac[i-1] * i)%mod;
        inv[i] = inverse(fac[i], mod);
    }
    
    LL ans=0;
    for(int i=0; i<=n; i++) {
        if(i>x)
            break;
        if ((x - i) % 2)
            continue;
        int b = (x-i)/2;
        if(2*i+b != y) continue;
        ans = (ans + ((((fac[i+b]*inv[i])%mod)*inv[b])%mod))%mod ;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 15872
import java.util.*;

class Main
 {
	public static void main(String[] args){
		
	Scanner sc = new Scanner(System.in);
		
		int w=sc.nextInt();
		int h=sc.nextInt();
		int x=sc.nextInt();
		int y=sc.nextInt();
		int r=sc.nextInt();
		
		if( 0<=x-r && x+r<=w && 0<=y-r && y+r<=h ){
			
		    System.out.println("Yes");
		}
		
		else{
		    System.out.println("No");
		}
		
    }
}


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

const int mod = 1e9+7;

int main() {
    int N;
    cin >> N;
    int a[N];
    rep(i,N) cin >> a[i];
    ll m = 1 << 30;
    for(int i=-100;i<=100;++i) {
        ll c=0;
        for(int j=0;j<N;++j) {
            c += (a[j]-i)*(a[j]-i);
        }
        if(c < m) {
            m = c;
        }
    }
    cout << m << endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

#define ll long long
#define vec vector
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
	ll a,b;

	scanf("%lld%lld", &a, &b);


	if (a < b)
		cout << "0" << endl;
	else
		cout << "10" << endl;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  string input;
  cin>>input;
  int N = (int)(input.length());
  int *correct1 = new int[N];
  int *correct2 = new int[N];
  for(int i=0; i<N; i++){
   if(i%2==0){
     correct1[i]='0'; 
     correct2[i]='1';  
   }
    else{
      correct1[i]='1'; 
      correct2[i]='0';  
   }  
  }
  
  int correct1rate=0;
  int correct2rate=0;
  int result;
  
  for(int i=0; i<N; i++){
   if(input[i]==correct1[i]) correct1rate+=1; 
   else correct2rate+=1  ;
  }
  if(correct1rate>=correct2rate) result=N-correct1rate;
  else result=N-correct2rate;
  cout<<result;
  return 0;
}

Measured memory_bytes: 1280
n = int(raw_input())
if n <= 111:
    print 111
elif n <= 222:
    print 222
elif n <= 333:
    print 333
elif n <= 444:
    print 444
elif n <= 555:
    print 555
elif n <= 666:
    print 666
elif n <= 777:
    print 777
elif n <= 888:
    print 888
else:
    print 999


Measured memory_bytes: 2568
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

int main() {
  int k;
  int flg=0;

  //長さNの配列を作成.
  vector<int> A(5);
  for(int i = 0; i < 5; i++){
    cin >> A[i];
  }

  cin >> k;

  for(int j =0; j<4; j++){
    if(A[4-j]-A[0] > k){
      cout << ":(" << endl;
      flg++;
      break;
    }
  }

  if(flg==0){
  cout << "Yay!" << endl;
  }

}


Measured memory_bytes: 256
N = int(input())
S = input()

ans = 0
for i,s in enumerate(S):
    T = S[i:]
    d = [0]*(N-i)
    d[0] = -1
    k,j = 0,1
    while j< (N-i-1):
        matched = T[k] == T[j]
        if not matched and k>0:
            k = d[k]
        else:
            if matched:
                k += 1
            j += 1
            d[j] = k
    j,p = 1,0
    while j< (N-i) and p< (N-i):
        if (T[j] == T[p]) and (p*2 < j):
            j += 1
            p += 1
            ans = max(ans,p)
        elif p == 0:
            j += 1
        else:
            p = d[p]
print(ans)

Measured memory_bytes: 50348
l = [[0.25],[0.5],[1],[2]]
tmp = list(map(int,input().split()))

for i in range(4):
    l[i].append(tmp[i])

for i in range(4):
    l[i].append(l[i][1]*4/(l[i][0]*4))

from operator import itemgetter
l = sorted(l, key=itemgetter(2))

ans = 0
n = 4*int(input())
for i in range(4):
    tmp = n//int(l[i][0]*4)
    if tmp >= 1:
        ans += tmp * l[i][1]
        n -= tmp*int(l[i][0]*4)

print(int(ans))


Measured memory_bytes: 9068
#include <bits/stdc++.h>
#define maxn 310
using namespace std;

int n;
int a = 0, b = 0, c = 0;
double f[maxn][maxn][maxn];

double dfs(int x, int y, int z)
{
    if (f[x][y][z])
        return f[x][y][z];
    double sum = x + y + z;
    double t = n / sum;
    if (x)
        t += dfs(x - 1, y, z) * x / sum;
    if (y)
        t += dfs(x + 1, y - 1, z) * y / sum;
    if (z)
        t += dfs(x, y + 1, z - 1) * z / sum;
    f[x][y][z] = t;
    return f[x][y][z];
}

int main()
{
    cin >> n;
    f[1][0][0] = n;
    int t;
    for (int i = 1; i <= n; ++i)
    {
        cin >> t;
        switch (t)
        {
        case 1:
            a++;
            break;
        case 2:
            b++;
            break;
        case 3:
            c++;
            break;
        }
    }
    double ans = dfs(a, b, c);
    printf("%.16f", ans);
    return 0;
}

Measured memory_bytes: 225536
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

int main() {
    ll x, k, d;
    cin >> x >> k >> d;

    x = abs(x);

    ll ans;
    if(k < x / d) ans = x - d * k;
    else {
        ll q = (ll) (x / d);
        ll ans1 = x % d;
        ll ans2 = abs(ans1 - d);
        if(q % 2 == 0 && k % 2 == 0) ans = ans1;
        if(q % 2 == 0 && k % 2 != 0) ans = ans2;
        if(q % 2 != 0 && k % 2 == 0) ans = ans2;
        if(q % 2 != 0 && k % 2 != 0) ans = ans1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
    int Q;
    cin >> Q;
    deque<int> d;
    for(int i = 0;i < Q;i++) {
        int A;
        cin >> A;
        if(A == 0) {
            int B,C;
            cin >> B >> C;
            if(B == 0) {
               d.push_front(C); 
            }
            else {
                d.push_back(C);
            }
        }
        else if(A == 1) {
            int B;
            cin >> B;
            cout << d[B] << endl;
        }
        else {
            int B;
            cin >> B;
            if(B == 0) {
                d.pop_front();
            }
            else {
                d.pop_back();
            }
        }
    }
}


Measured memory_bytes: 6240
n,m = map(int,input().split())
L = [0]*n
AC = 0
WA = 0
tmp = [0]*n
for i in range(m):
	x,y = input().split()
	x = int(x)
	if L[x-1] == 0:
		if y == "WA":
			tmp[x-1] += 1
		else:
			AC += 1
			WA += tmp[x-1]
			L[x-1]=1
print(AC,WA)


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

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

    int N,A; cin >>N>>A;
    ANS(N*N-A);
}


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


int main() {
	int n,m;
	vector <int>s, t;
	int tmp;
	int cnt = 0;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		s.push_back(tmp);
	
	}
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> tmp;
		t.push_back(tmp);
	}
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	int next=0;
	int s_b = -1,t_b=-1;
	
	for (int i = 0; i < n; i++) {
		if (s[i] == s_b) {
			continue;
		}

		for (int j = next; j < m;j++) {
			if (t_b == t[j]) {
				continue;
			}
			//cout << s[i]<<" "<<t[j]<<endl;
			if (s[i]==t[j]) {
				cnt++;
				next = j;
				break;
			}
			t_b = t[j];
		}
		s_b = s[i];
	}
	cout << cnt<<endl;
	
	return 0;
}




Measured memory_bytes: 3236
# (c) midandfeed
r, c = [int(x) for x in input().split()]
q = []
sumr = [0]*c
tempr = 0
for i in range(r):
	col = [int(x) for x in input().split()]
	for j in range(c):
		sumr[j] += col[j]
	col.append(sum(col))
	q.append(col)
sumr.append(sum(sumr))
q.append(sumr)
for i in range(r+1):
	for j in range(c+1):
		print(q[i][j], end='')
		if (j != (c)):
			print(' ', end='')
	# if (i != (r) ):
	print()

Measured memory_bytes: 8760
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())


int par[100010];  //親
int _rank[100010]; //木の深さ

// n要素で初期化
void init(int n){
      REP(i, n){
		par[i] = i;
          _rank[i] = 0;
	}
}
//木の根を求める
int find(int x){
	if(par[x] == x) return x;
	else return par[x] = find(par[x]);
}
//xとyの属する集合を結合
void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(_rank[x] < _rank[y]) par[x] = y;
	else{
		par[y] = x;
		if(_rank[x] == _rank[y]) _rank[x]++;
	}
}

int n, x[100010], y[100010];
VI idxs[100010];

map<int, int> x_to_idx;
map<int, int> y_to_idx;

void solve() {
  cin >> n;
  init(n+1);
  REP(i, n) {
    cin >> x[i] >> y[i];
    if (x_to_idx[x[i]] == 0 && y_to_idx[y[i]] == 0) {
      x_to_idx[x[i]] = i+1;
      y_to_idx[y[i]] = i+1;
      continue;
    }
    if (x_to_idx[x[i]] > 0 && y_to_idx[y[i]] > 0) {
      unite(x_to_idx[x[i]], i+1);
      unite(y_to_idx[y[i]], i+1);
      continue;
    }
    if (x_to_idx[x[i]] > 0) {
      unite(x_to_idx[x[i]], i+1);
      y_to_idx[y[i]] = i+1;
      continue;
    }
    if (y_to_idx[y[i]] > 0) {
      unite(y_to_idx[y[i]], i+1);
      x_to_idx[x[i]] = i+1;
      continue;
    }
  }
  REP(i, n) {
    idxs[find(i+1)-1].push_back(i);
  }
  LL res = 0;
  REP(i, n) {
    set<int> xs, ys;
    for(auto j : idxs[i]) {
      xs.insert(x[j]);
      ys.insert(y[j]);
    }
    res += (LL)SZ(xs) * SZ(ys) - SZ(idxs[i]);
  }
  cout << res << endl;
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 13944
// -*- coding:utf-8-unix -*-

use proconio::input;

// ABC169B - Multiplication 2
// https://atcoder.jp/contests/abc169/tasks/abc169_b

fn main() {
    input! {
        n: usize,
        mut datas: [i64; n],
    }

    datas.sort();

    let o: Option<i64> = datas
        .iter()
        // ↓これ消したい
        .map(|&v| v as i64)
        .fold(Some(1), |sum, i| match sum {
            Some(num) => num.checked_mul(i),
            None => None,
        });

    let max = 10i64.pow(18);
    let none_value = -1;
    let res = match o {
        Some(num) => {
            if num > max {
                none_value
            } else {
                num
            }
        }
        None => none_value,
    };

    println!("{}", res);
}


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

long long int dp[101][100001];

long long int solve(int* wt, int* val, int W, int N) {
	// BAse
  	if(N<=0 || W<=0) return 0;
  
    if(dp[N][W] != -1) return dp[N][W];

  	// Rec
  	long long int op1 = solve(wt, val, W, N-1);
  	long long int op2 = 0;	
  	if(wt[N-1] <= W) {
    	op2 = val[N-1] + solve(wt, val, W-wt[N-1], N-1);
    }
  
  return dp[N][W] = max(op1, op2); 	
	
}

int main() {
  	int N;
  	cin>>N;
  
  	int W;
  	cin>>W;
  
  	int* wt = new int[N];
  	int* val = new int[N];
  
  	for(int i=0; i<N; i++) {
    	cin>>wt[i]>>val[i];
    }
    memset(dp, -1, sizeof(dp));
  	cout<<solve(wt, val, W, N);
	return 0;
}

Measured memory_bytes: 82532
n = int(input())
a = list(map(int, input().split()))
a.append(0)

same = 1
ans = 0
for i in range(1, len(a)):
    if a[i] == a[i-1]:
        same += 1
    else:
        ans += same // 2
        same = 1

print(ans)



Measured memory_bytes: 3060
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n;
    cin >> n;
    int minp = INF;
    int maxpos = INF;
    int minpos = 0;
    for( int i = 0; i < n; ++i ) {
        int a, b;
        cin >> a >> b;
        minp = min( b, minp );
        maxpos = min( maxpos, a );
        minpos = max( minpos, a );

    }

    cout << ( maxpos - 1 ) + ( minpos - maxpos + 1 ) + minp << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int nigarel[100001];

int main()
{
    int a, b, i, sum=0;

    cin >> a >> b;

    for( i = 0 ; i < b ; i++ )
    {
        cin >> nigarel[i];
        sum += nigarel[i];
    }

    if ( sum >= a )
        cout << "Yes";
    else
        cout << "No";

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N, Q;
	cin >> N >> Q;
	string s;
	cin >> s;
	vector<int> d(s.size() + 1, 0);
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == 'A' && s[i + 1] == 'C') { ++d[i + 1]; }
		d[i + 1] += d[i];
	}
	vector<int> ans(Q);
	for (int i = 0; i < Q; ++i) {
		int l, r;
		cin >> l >> r;
		--l; --r;
		ans[i] = d[r] - d[l - 1];
		if (s[l - 1] == 'A' && s[l] == 'C') { ans[i] -= 1; }
	}
	for (auto val : ans) { cout << val << endl; }

	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h> 
#define ll long long
#define length 1  //10万
#define kw_len 102
int compare(const int*a,const int *b){
    if(*a<*b)
      return -1;
    else if(*a>*b)
      return 1;
    return 0;
}

ll nCr(int n,int r){
  ll val;
  int i;
  if(r==0)return 1;
  for(i=0;i<r;i++){
		val *= (n-i);
		val /= (i+1);
	}
  return val;
}

ll nPr(int n,int r){
  ll val=1;
  int i;
  for(i=0;i<r;i++){
    val *= (n-i);
  }
  return val;
}
/*
qsort(array,length,sizeof(int),(int(*)(const int*, const int*))compare);
使う時これをコピペ
*/
int main(){
    int array[length];
    int N,K,i,j;
    int *inp;
    char *chp;
    ll sum=0;
    char chara[length][kw_len];
    scanf("%s",chara);
    K = strlen(chara)-2;
    printf("%c%d%c",chara[0][0],K,chara[0][K+1]);
    return 0;
}


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

int main(){
	int x,y,z;
	scanf("%d %d %d",&x,&y,&z);
	swap(x,y);
	swap(x,z);
	printf("%d %d %d",x,y,z);
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  if (S.at(0) == 'R') {
    if (S.at(1) == 'R') {
      if (S.at(2) == 'R') {
       cout << 3 << endl;
      }
      else {
        cout << 2 << endl;
      }
    }
    else {
      cout << 1 << endl;
    }
  }
  else {
    if (S.at(1) == 'R') {
      if (S.at(2) == 'R') {
        cout << 2 << endl;
      }
      else {
        cout << 1 << endl;
      }
    }
    else {
      if (S.at(2) == 'R') {
        cout << 1 << endl;
      }
      else {
        cout << 0 << endl;
      }
    }
  }
}


Measured memory_bytes: 3604
import sys
input = lambda: sys.stdin.readline().rstrip()

match_dict = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

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

def greater(a, b):
    if len(a) == len(b):
        return max(a, b)
    elif len(a) > len(b):
        return a
    else:
        return b        

dp = ["0"] * 11000

dp[0] = "" 

for i in range(N+1):
    
    for a in A:
        if i - match_dict[a] >= 0 and dp[i-match_dict[a]] != '0':
            dp[i] = greater(dp[i - match_dict[a]] + str(a), dp[i])

print(dp[N])

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

using namespace std;
#define N 200100
#define SIGMA 26
int v[N];
int x, i, n;
int main()
{
    cin >> n;
    for (i = 1; i < n; ++i){
        cin >> x;
        --x;
        ++v[x];
    }
    for (i = 0; i < n; ++i)
        cout << v[i] << '\n';
    return 0;
}


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

int main() {
	string s;
	cin >> s;
	s.pop_back();
	while (s.size() % 2 == 1 || s.substr(0, s.size() / 2) != s.substr(s.size() / 2, s.size() / 2)) s.pop_back();
	cout << s.size() << endl;
	return 0;
}


Measured memory_bytes: 256
while True:
  h, w = map(int, input().split())
  if h == 0:
    break

  mp = []
  for _ in range(h):
    lst = list(input())
    cum = []
    acc = 0
    for i in lst:
      acc = acc + 1 if i == "." else 0
      cum.append(acc)
    mp.append(cum)
  mp.append([-1] * w)
  
  ans = 0
  for i in range(w):
    stack = []
  
    for j in range(h + 1):
      score = mp[j][i]
  
      if not stack:
        stack.append((score, j))
  
      else:
        last_score, last_ind = stack[-1][0], stack[-1][1]
        if score > last_score:
          stack.append((score, j))
        
        elif score == last_score:
          continue
        
        else:
          while stack != [] and stack[-1][0] >= score:
            last_score, last_ind = stack.pop()
            ans = max(ans, last_score * (j - last_ind))
          stack.append((score, last_ind))
  
  print(ans)


Measured memory_bytes: 7836
n,p,i,a[50];
main(){
	for(;~scanf("%d", &n),n;) {
		for(p=i=0;i<n;i++)scanf("%d",&a[i]);
		for(i=1;i<n;i++){
			if(a[i-1]+1!=a[i]) {
				if(i-p-1)printf("%d-%d ",a[p],a[i-1]);
				else printf("%d ",a[p]);
				p=i;
			}
		}
		if(n-p-1)printf("%d-%d\n",a[p],a[n-1]);
		else printf("%d\n",a[p]);
	}
	exit(0);
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int N, M;
	cin >> N >> M;
	
	vector< int > red(N, 0), cnt(N, 1);
	red[0] = 1;
	
	for_(i,0,M) {
		int x, y;
		cin >> x >> y;
		--x; --y;
		
		--cnt[x];
		++cnt[y];
		
		if (red[x]) {
			red[y] = 1;
			if (cnt[x] == 0) red[x] = 0;
		}
	}
	
	int ans = 0;
	for_(i,0,N) if (red[i] && cnt[i] > 0) ++ans;
	cout << ans << endl;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

void solve() {
    int s, w;
    cin >> s >> w;

    cout << (s <= w ? "unsafe" : "safe") << endl;
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 3636
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
  return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
  read_all = [tuple(map(int, input().split())) for _ in range(N)]
  return map(list,zip(*read_all))

#################

n,m,s,t = II()
u,v,a,b = Line(m)

from heapq import heappop, heappush
def dijkstra(E,s,n):
  inf=float('inf')
  d=[inf for _ in range(n)]
  d[s]=0
  q=[]
  heappush(q,(0,s))
  while q:
    du, u1 = heappop(q)
    if d[u1]<du: continue
    for v1,weight in E[u1].items():
      alt=du+weight
      if d[v1]>alt:
        d[v1]=alt
        heappush(q, (alt,v1))
  return d

p = [dict() for _ in range(n)]
p2 = [dict() for _ in range(n)]
for i in range(m):
  p[u[i]-1][v[i]-1] = a[i]
  p[v[i]-1][u[i]-1] = a[i]
  p2[u[i]-1][v[i]-1] = b[i]
  p2[v[i]-1][u[i]-1] = b[i]

d = dijkstra(p,s-1,n)
d2 = dijkstra(p2,t-1,n)

ans = [0]*n
ans[0] = d[n-1]+d2[n-1]
for i in range(1,n):
  ans[i] = min(ans[i-1],d[n-1-i]+d2[n-1-i])

for i in ans[::-1]:
  print(10**15-i)

Measured memory_bytes: 130268
#include<stdio.h>
#define MAX 100

static const int INFTY=(1<<21);
static const int WHITE=0;
static const int PINK=1;
static const int RED=2;

int prim(int );

int m[MAX][MAX];

int main(){
  int number,i,j;
  int e;
  scanf("%d",&number);
  for(i=0;i<number;i++){
    for(j=0;j<number;j++){
      scanf("%d",&e);
      if(e==-1)m[i][j]=INFTY;
      else m[i][j]=e;
    }
  }
  printf("%d\n",prim(number));
   
  return 0;
}
int prim(int n){
  int res,minv;
  int d[MAX],parent[MAX],color[MAX];
  int i,j;
  int sum=0;
  for(i=0;i<n;i++){
    d[i]=INFTY;
    parent[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;
  while(1){
    minv=INFTY;
    res=-1;
    for(i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=RED){
	res=i;
	minv=d[i];
      }
    }
    if(res==-1)break;
    color[res]=RED;
    for(j=0;j<n;j++){
      if(color[j]!=RED&&m[res][j]!=INFTY){
	if(d[j]>m[res][j]){
	  d[j]=m[res][j];
	  parent[j]=res;
	  color[j]=PINK;
	}
      }
    }
  }

  for(i=0;i<n;i++){
    if(parent[i]!=-1)sum+=m[i][parent[i]];
  }
  return sum;
}

Measured memory_bytes: 636
n = int(input())
b = list(map(int, input().split()))

ans = []
for _ in range(200):
    if len(b) == 0:
        for i in reversed(ans):
            print(i)
        break
    for i, v in enumerate(reversed(b)):
        if len(b)-i == v:
            ans.append(len(b)-i)
            del b[len(b)-i-1]
            break
    else:
        print(-1)
        break



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int cnt[13]={};
int dif;
int n;
vector<int>v;
int rec(int x){
	int flag = 1;
	for(int i = 0; i < 13; i++)if(cnt[i] >= 1)flag = 0;
	if(x > 24)return 0;
	if(flag){
		return 1;
	}
	int y = x+dif;
	int ret = 0;
	if(x <= 12){
		ret |= rec(x+1);
		if(cnt[x] > 0){
			cnt[x]--;
//			cout << x <<" "<<y<<endl;
			v.push_back(x);
			ret |= rec(y);
			v.pop_back();
			cnt[x]++;
		}
	}else{
		ret |= rec(x+1);
		if(cnt[24-x] > 0){
			cnt[24-x]--;
//			cout << x <<" "<<y<<endl;
			v.push_back(x);
			ret |= rec(y);
			v.pop_back();
			cnt[24-x]++;
		}
	}
	return ret;
}
int main(){
	int ans = 12;
	cin >> n;
	cnt[0]++;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		cnt[x]++;
		if(x == 0){
			ans = 0;
		}
		if(x == 12){
			if(cnt[x] > 1)ans = 0;
		}else
		if(cnt[x] > 2)ans = 0;
	}
	if(ans == 0){
		cout<<0;
		return 0;
	}
	for(int i = 12; i > 0; i--){
//		cout<<i<<endl;
		dif = i;
		if(rec(0) == 1){
			ans = i;
			break;
		}
	}
	cout << ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    long long W, H, x, y;
    cin >> W >> H >> x >> y;

    double ans = (double)W * H * 0.5;
    int d = (x * 2 == W && y * 2 == H) ? 1 : 0;
    cout << setprecision(12) << ans << " " << d << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        do_(inp);
        inp.close();
    }
    public static void do_(Scanner inp) {
        char s[] = inp.next().toCharArray();
        Arrays.sort(s);
        if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) {
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 25044
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	int N;
	cin >> N;
	vector<int> a(N);
	rep(i,N) cin >> a[i];
	vector<bool> col(10);
	int free=0;
	rep(i,N){
		if(a[i]<3200) col[a[i]/400]=true;
		else free++;
	}
	int ans1=0, ans2=0;
	rep(i,10) if(col[i]) ans1++;
	ans2=ans1+free;
	if(ans1==0 && free!=0) ans1=1;
	cout << ans1 << " " << ans2 << endl;

	return 0;
}

Measured memory_bytes: 256
//kunal_goyal
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//#include"debug.h"
 
using namespace std;
using namespace __gnu_pbds;
 
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
 
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
 
#define pint(x) printf("%d",x)
#define plint(x) printf("%lld",x)
#define endl '\n'
#define nl printf("\n");
#define ps printf(" "); 
 
#define all(x) x.begin(),x.end()
#define pb push_back
#define Set(a, s) memset(a, s, sizeof (a))
#define mod1 (lli)(1e9 + 7)
#define mod2 (lli)(1e9 + 9)
 
#define fore(i,n) for(int i=n; i>=0; i--)
#define fors(i,a,n) for(int i=a; i<n; i++)
#define fora(i,ele) for(auto i: ele)
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<lli> vli;
 
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
 
double tick(){static clock_t oldt,newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt=newt;return diff;}
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
float roundoff(float val, float p){ return floor(val*pow(10.0,p)+0.5)/pow(10.0,p);}
lli pow(int a, int b){lli x=1,y=a; while(b > 0){if(b&1){x=(x*y)%mod2;}y = (y*y)%mod2; b /= 2;}return x;}
 
const int INF = 0x3f3f3f3f;
const float pi = 3.14159265;
 
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};
//int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1};
 
int main(void) {
    ios_base::sync_with_stdio(true);
    cin.tie(NULL);
    cout.tie(NULL);
	/*
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
	*/
    // cout<<"Execution time : "<<tick()<<"\n";
    
	int n;
	int1(n);
	vi arr;
	int prev = 0;
	lli sum = 0;
	fors(i,0,n){
		int t;int1(t);
		arr.pb(t);
		sum += abs(prev-t);
		prev=t;
	}
	sum += abs(prev-0);
	arr.pb(0);
	prev = 0;
	fors(i,0,n){
		lli tsum = sum;
		tsum -= abs(prev-arr[i])+abs(arr[i]-arr[i+1]);
		tsum += abs(prev-arr[i+1]);
		prev = arr[i];
		cout<<tsum<<endl;
	}
	
    return 0;
}


Measured memory_bytes: 1784
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <sstream>

using namespace std;
double root2 = 1.414213562373095048801688724209;
int main(){
	
	double d;
	cin >> d;
	
	double ans = 0;
	
	if(d >= 1.0){
		ans = (int)(d + 1.0);
	}
	
	ans = max(ans, d * root2);
	
	printf("%.12f\n", ans);
	
	return 0;
}

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

ll gcd(ll a,ll b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}

int main(){
  string S,T;
  cin >> S >> T;
  cout << T << S << endl;
}
      
  
  
  

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

int main() {
    int N;
    cin >> N;
    unordered_map<long long, long long> m;
    long long s = 0;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        m[a]++;
        s += a;
    }
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; ++i) {
        long long b, c;
        cin >> b >> c;
        s -= m[b] * b;
        s += m[b] * c;
        m[c] += m[b];
        m[b] = 0;
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 7084
#include <bits/stdc++.h>
using namespace std;
int main(){
    while(1) {
        int H,W;
        cin >> H >> W;
        if (H+W==0){
            break;
        }
        for(int i=0; i<H; i++) {
            for(int j=0; j<W; j++) {
                if(i==0 || j==0 || i==H-1 || j==W-1) cout <<'#';
                else cout <<'.';
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
using namespace std;
int C, D, W, X, a[33][17], b[33][17], dp[33][55][7];
int solve(int d, int s, int x) {
	if (d == D) return 0;
	if (dp[d][s][x]) return dp[d][s][x] - 1;
	int ret = solve(d + 1, s, x);
	for (int i = 0; i < C; i++) {
		if (s + b[d][i] <= W && a[d][i] != 0) {
			int res = solve(d + 1, s + b[d][i], x);
			ret = max(ret, res + a[d][i]);
		}
	}
	if (x != X) {
		for (int i = 0; i < C; i++) {
			int sum = 0, prof = 0;
			for (int j = i; j < C; j++) {
				prof += a[d][j];
				sum += b[d][j];
				if (a[d][j] == 0 || s + sum > W) break;
				int res = solve(d + 1, s + sum, x + 1);
				ret = max(ret, res + prof);
			}
		}
	}
	dp[d][s][x] = ret + 1;
	return ret;
}
int main() {
	while (cin >> C >> D >> W >> X, C) {
		for (int i = 0; i < C; i++) {
			for (int j = 0; j < D; j++) {
				cin >> a[j][i];
			}
		}
		for (int i = 0; i < C; i++) {
			for (int j = 0; j < D; j++) {
				cin >> b[j][i];
			}
		}
		for (int i = 0; i <= D; i++) {
			for (int j = 0; j <= W; j++) {
				for (int k = 0; k <= X; k++) {
					dp[i][j][k] = 0;
				}
			}
		}
		int ret = solve(0, 0, 0);
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 3064
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
left = []
right = []

left.append(a[0])
for i in range(1,n-1):
    left.append(gcd(left[-1],a[i]))
a = a[::-1]
right.append(a[0])
for i in range(1,n-1):
    right.append(gcd(right[-1],a[i]))
ans = 1
for i in range(n-1):
    ans = max(ans,gcd(left[i],right[n-i-3]))
ans = max(ans,left[n-2],right[n-2])
print(ans)


Measured memory_bytes: 16120
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>

typedef long long ll;
using namespace std;

typedef pair<int,int> P;

int main()
{
	int n;
	queue<int> que;
	while(~scanf("%d",&n)){
		for(int i = 0; i < 10; i++){
			if((n >> i) & 1) que.push(pow(2,(double)i));
		}

		while(!que.empty()){
			printf("%d%s",que.front(),que.size() == 1 ? "\n" : " ");
			que.pop();
		}
	}
}

Measured memory_bytes: 0
from fractions import gcd
 
def primeNum(n):
  ans = 1
  if n == 1:
    return ans
  if n % 2 == 0:
    ans += 1
    while n % 2 == 0:
      n = n // 2
  for k in range(3, int(n**0.5)+1, 2):
    if n % k == 0:
      ans += 1
      while n % k == 0:
        n = n // k
    if n == 1:
      return ans
  if n != 1:
    ans += 1
  return ans
  
a,b = list(map(int, input().split()))
n=gcd(a,b)
print(primeNum(n))

Measured memory_bytes: 5048
/*
C++ のソースコードのテンプレート
特にAOJ-ITP1に使いやすい
*/
#define _USE_MATH_DEFINES

#include <iostream> // 標準入出力
#include <fstream>  // ファイル入出力
#include <string>   // 文字列関係
#include <vector>   // 可変の配列
#include <cmath>    // 数学系
#include <iomanip>  // streamの書式関係
#include <algorithm>// max関数など

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;        // 要素数が可変のベクトル
using std::fixed;         // ストリームの設定をデフォルトにする
using std::setprecision;  // 引数に小数点以下の桁数を指定することが出来る

int main() {
	string S;

	cin >> S;

	for (size_t i = 0; i < S.length(); i++)
	{
		if (S[i] == 'A' && S[i+1] == 'C')
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;


	return 0;
}


Measured memory_bytes: 256
n = input()
if n[-1] == '2' or n[-1] == '4' or n[-1] == '5' or n[-1] == '7' or n[-1] == '9':
  print("hon")
elif n[-1] == '0' or n[-1] == '1' or n[-1] == '6' or n[-1] == '8':
  print("pon")
else:
  print("bon")

Measured memory_bytes: 9120
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>

using namespace std;
using ll = long long;

const ll mod = 1000000007;

pair<ll,ll> diofante(ll a, ll b){
	if(a==0)return {0,1};
	pair<ll,ll> t = diofante(b%a,a);
	return {t.second-(b/a)*t.first,t.first};
}

ll modinv(ll x){
	ll res = diofante(x,mod).first;
	return (res%mod+mod)%mod;
}

ll fact(ll x){
	ll res=1;
	for(ll i=2; i<=x; ++i){
		res=(res*(i%mod))%mod;
	}
	return res;
}
ll prod(ll a, ll b){
	ll res=1;
	for(;a<=b;++a){
		res=(res*(a%mod))%mod;
	}
	return res;
}



long long fastp(long long base,int exp){
	
	if(exp==0)return 1;
	
	long long tmp=fastp(base,exp/2);
	
	tmp=(tmp*tmp)%mod;
	
	if(exp%2==1)tmp*=base;
	
	return tmp%mod;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	ll x,y,a,b;
	cin>>x>>y;
	b=(2*x-y)/3;
	a=x-2*b;
	if(a<0 || b<0 || a+2*b!=x || b+2*a!=y){
		cout<<0<<endl;
		return 0;
	}
	cout<< (prod(a+1,a+b)*fastp(fact(b),mod-2))%mod << endl;
	return 0;
}



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

using namespace std;

typedef long long/*--------------------*/ll;
typedef long double/*------------------*/ld;
typedef unsigned long long/*-----------*/ull;
typedef pair<ll, ll >/*----------------*/pll;
typedef vector<pll >/*-----------------*/vpll;

#define rep(i,a)/*---------------------*/for(i = 0 ; i < a ; i++)
#define repr(i,a)/*--------------------*/for(i = a ; i >= 0 ; i--)
#define REP(i,a,b)/*-------------------*/for(i = a ; i <= b ; i++)
#define REPR(i,a,b)/*------------------*/for(i = a ; i >= b ; i--)
#define PRINT_CASE/*-------------------*/cout << "Case "<< i << ": ";
#define opt/*--------------------------*/ios_base::sync_with_stdio(false)

#define scan(N)/*----------------------*/scanf("%lld",&N)
#define print(N)/*---------------------*/printf("%lld",N)
#define scan2(N1,N2)/*-----------------*/scanf("%lld %lld",&N1,&N2)
#define print2(N1,N2)/*----------------*/printf("%lld %lld",N1,N2)
#define scan3(N1,N2,N3)/*--------------*/scanf("%lld %lld %lld",&N1,&N2,&N3)
#define print3(N1,N2,N3)/*-------------*/printf("%lld %lld %lld",N1,N2,N3)

#define lb/*---------------------------*/lower_bound
#define ub/*---------------------------*/upper_bound
#define mem(a,b)/*---------------------*/memset(a,b,sizeof(a))
#define gcd(a, b)/*--------------------*/__gcd(a, b)
#define lcm(a, b)/*--------------------*/((a)*((b)/gcd(a,b)))
#define all(a)/*-----------------------*/a.begin(),a.end()

#define endl/*-------------------------*/'\n'
#define inf/*--------------------------*/(ll)2e15
#define MOD/*--------------------------*/(ll)1000000007
#define MAXN/*-------------------------*/500005


int main()
{
	opt;
	std::vector<ll> v;
	ll n,i = 0;
	cin >> n;
	while(1)
	{
		if(i*i > (ll)1e9)
			break;
		v.push_back(i*i);
		i++;
	}
	if(binary_search(v.begin(), v.end(),n))
		cout << n << endl;
	else
	{
		std::vector<ll>::iterator it = upper_bound(v.begin(), v.end(),n);
		it--;
		cout << *it << endl;
	}
	return 0;
}





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


int main(){
    int N, Y;
    cin >> N >> Y;
    
    bool f=false;
    for(int x=0; x<=N; x++){
        for(int y=0; y<=N; y++){
            int z;
            z = Y - 10000*x - 5000*y;
            z /= 1000;
            if((x+y+z)==N && z>=0){
                f=true;
                cout << x <<" "<< y <<" "<< z << endl;
                break;
            }
        }
        if(f) break;
    }
    if(!f) cout << -1 <<" "<< -1 <<" "<< -1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

ll c[10000][10000];
bool v[10000];
ll N, M;
ll cnt = 0;

bool isVisitedAll() {
	bool valid = true;
	rep(i, 0, N) {
		valid &= v[i];
	}
	return valid;
}

void dfs(int id) {
	if (isVisitedAll()) {
		cnt++;
		return;
	}

	rep(i, 0, N) {
		if (id != i && c[id][i] != 0 && !v[i]) {
			v[i] = true;
			dfs(i);
			v[i] = false;
		}
	}
}

int main() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		c[a - 1][b - 1] = 1;
		c[b - 1][a - 1] = 1;
	}

	v[0] = true;
	dfs(0);

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

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

int main(){
    ll s;
    cin >> s;
    ll x,y,z,w;
    x=1000000000;
    w=s/x;
    ++w;
    ll sa;
    sa=w*x-s;
    y=sa;
    z=1;

    if(s==1000000000000000000){
        z=0;
        y=0;
        w=x;
    }
    


    cout << 0 << endl;
    cout << 0 << endl;
    cout << x << endl;
    cout << z << endl;
    cout << y << endl;
    cout << w << endl;
    

    return 0;
}

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

using namespace std;

#define ll long long
const ll mod = 1e9 + 7;

int main () {
    long long val;
    cin >> val;
    long long x = 100;
    int cnt = 0;
    while (x < val) {
        cnt++;
        x += x / 100;
    }
    printf ("%d\n", cnt);
    return 0;   
}


Measured memory_bytes: 3752