akhauriyash/Code-Regression huggingface dataset:
def main():
    N, K = list(map(int, input().split()))
    hs = [int(input()) for i in range(N)]
    hs.sort()
    i = 0
    r = 10 ** 9
    while True:
        if i + K > N:
            break
        r = min(r, hs[i + K - 1] - hs[i])
        i += 1
    print(r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 7444
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  string strs,strt;
  cin >> strs >> strt;
  int sizes = strs.size();
  char temp;
  int i,j;
  for(i = 0;i < sizes;++i){
    char temp = strs.at(sizes-1);
    for(j = sizes-2;j >= 0;--j){
      strs.at(j+1) = strs.at(j);
    }
    strs.at(0) = temp;
    if(strs == strt){
      cout << "Yes" << endl;
      return 0;
    }else{
      continue;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	m := make(map[byte]int, 0)
	for i := 0; i < 4; i++ {
		m[s[i]]++
	}
	
	for i := 0; i < 4; i++ {
		if len(m) > 2 || m[s[i]] > 2 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int len, bigmod = 1000000007, memo[100010][15];
char s[100010];

int dp(int pos, int sisa) {
	int ret = 0, temp;
	if (pos == len)
		return ((sisa == 5) ? 1 : 0);
	if (memo[pos][sisa] != -1)
		return memo[pos][sisa];
	temp = (10 * sisa) % 13;
	if (s[pos] != '?')
		ret = dp(pos + 1, (temp + s[pos] - '0') % 13);
	else
		for (int i = 0; i < 10; i++)
			ret = (ret + dp(pos + 1, (temp + i) % 13)) % bigmod;
	memo[pos][sisa] = ret;
	return ret;
}

int main() {
	scanf("%s", s);
	len = strlen(s);
	memset(memo, -1, sizeof memo);
	printf("%d\n", dp(0, 0));
	return 0;
}

Measured memory_bytes: 13952
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// del

const i64 MAXN = 100005;


i64 a[MAXN];
i64 b[MAXN];

i64 n, k, q;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> k >> q;

    for (i64 i = 1; i <= q; i++) {
        cin >> a[i];
        b[a[i]]++;
    }

    for (i64 i = 1; i <= n; i++) {
        bool f = q - b[i] < k;
        if (f) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 2176
#include <iostream> //cout
#include <cstring> //c
#include <string> //c
#include <vector> //vector
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main() {
    string S, T;
    cin >> S;
    cin >> T;

    if(S == T.substr(0, S.size())){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 1000000000
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
//int fx[]={0,0,1,-1};
//int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
const int N=100010;
ll a[N],b[N];
int main()
{
    IOS;
    int n;cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    ll cnt=0;
    for(int i=0;i<n;i++)
    {
        if(b[i]>=a[i])cnt+=(b[i]-a[i])/2;
        else cnt-=(a[i]-b[i]);
    }
//    cout<<"cnt = "<<cnt<<endl;
    if(cnt>=0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}








Measured memory_bytes: 3772
N,T = map(int,input().split())
A = list(map(int,input().split()))
mn = A[0]
gain = 0
ans = 1
for a in A[1:]:
    if a < mn:
        mn = a
        continue
    if a-mn == gain:
        ans += 1
    elif a-mn > gain:
        gain = a-mn
        ans = 1
print(ans)

Measured memory_bytes: 14252
import numpy as np

N, M, Q = map(int, input().split())

S = np.zeros((N+1, M+1), dtype='float32')

for n in range(1, N+1):
    S[n, 1:] = list(map(int, list(input())))

# count nodes
N_cum = np.cumsum(np.cumsum(S, axis=0), axis=1) 
# count edges(row)
ER_cum = np.cumsum(np.cumsum(S[:N, :]*S[1:, :], axis=0), axis=1) 
# count edges(col)
EC_cum = np.cumsum(np.cumsum(S[:, :M]*S[:, 1:], axis=0), axis=1) 

sol_list = []

for _ in range(Q):
    x1, y1, x2, y2 = map(int, input().split())
    # nodes
    N_nodes = N_cum[x2, y2] - N_cum[x1-1, y2] - N_cum[x2, y1-1] + N_cum[x1-1, y1-1]
    # edges(row)
    N_edges1 = ER_cum[x2-1, y2] - ER_cum[x1-1, y2] - ER_cum[x2-1, y1-1] + ER_cum[x1-1, y1-1]
    # edges(col)
    N_edges2 = EC_cum[x2, y2-1] - EC_cum[x1-1, y2-1] - EC_cum[x2, y1-1] + EC_cum[x1-1, y1-1]
    
    sol_list.append(N_nodes - N_edges1 - N_edges2)

for q in range(Q):
    print(int(sol_list[q]))

Measured memory_bytes: 100860
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int binpow(int a, int b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

ll gcd(ll a,ll b)
{
    if (b==0) return a;
    return gcd(b,a%b);
}
string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m;
    cin>>n>>m;
    if (n==m)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
import sys
S=list(input())

#print(S[0::2])
for i in S[0::2]:
    if i!="R" and i!="U" and i!="D":
        print("No")
        sys.exit()
for i in S[1::2]:
    if i!="L" and i!="U" and i!="D":
        print("No")
        sys.exit()
print("Yes")

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

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

  if( n%500 == 0 ){ //500の倍数
    cout << "Yes" << endl;
  }
  else if( n < a ){ //1円がnよりたくさんある
    cout << "Yes" << endl;
  }
  else if( n%500 < a ){ //
    cout << "Yes" << endl;
  }
  else { //
    cout << "No" << endl;
  }
  
}


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

int main()
{
	int n;
	string s;
	cin >> n >> s;
	
	if (n == 0) {
		cout << 0;
		return 0;
	}
	
	vector<int> count(26, 1);
	
	for (int i = 0; i < n; ++i) {
		++count[s[i] - 'a'];	
	}
	
	const int MOD = 1000000007;
	long long ans = 1;
	for (int i = 0; i < 26; ++i) {
		ans *= count[i];
		ans %= MOD;
	}
	
	ans -= 1;
	ans = ans % MOD;
	
   cout << ans;
   return 0;
}

Measured memory_bytes: 512
n, a, b = [int(x) for x in input().split()]

repeat_num = n // (a+b)
bluenum = repeat_num*a
if a != 0:
  over = (n - (a+b)*repeat_num)
  if over > a:
    bluenum += a
  else:
    bluenum += over
print(bluenum)

Measured memory_bytes: 3060
import sys

# from collections import Counter, deque, defaultdict
# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
# N = int(input())
# A,B,C = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]

H, W = [int(x) for x in input().split()]
S = []
for h in range(H):
    S.append(input())

Th = [[0] * W for _ in range(H)]
Tw = [[0] * W for _ in range(H)]

for h in range(H):
    cnt = 0
    st = 0
    for w in range(W):
        if S[h][w] == "#":
            for i in range(st, w):
                Tw[h][i] = cnt
            st = w + 1
            cnt = 0
        else:
            cnt += 1
    for i in range(st, W):
        Tw[h][i] = cnt

for w in range(W):
    cnt = 0
    st = 0
    for h in range(H):
        if S[h][w] == "#":
            for i in range(st, h):
                Th[i][w] = cnt
            st = h + 1
            cnt = 0
        else:
            cnt += 1
    for i in range(st, H):
        Th[i][w] = cnt

ALL = []
for w in range(W):
    for h in range(H):
        ALL.append(Tw[h][w] + Th[h][w])

print(max(ALL) - 1)


Measured memory_bytes: 220080
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
def sol():
    h,w=map(int,input().split())
    d=[]
    for i in range(h):
        s=input()
        d.append(s)
    x=h*w
    p=[[x+1]*x for i in range(x)]
    for i in range(x):
        for j in range(i+1):
            if i==j:
                p[i][j]=0
                p[j][i]=0
            ih,iw,jh,jw=i//w,i%w,j//w,j%w
            if d[ih][iw]==d[jh][jw]=="." and ih==jh and abs(iw-jw)==1:
                p[i][j]=1
                p[j][i]=1
            if d[ih][iw]==d[jh][jw]=="." and iw==jw and abs(ih-jh)==1:
                p[i][j]=1
                p[j][i]=1


    for i in range(x):
        ih,iw=i//w,i%w
        if d[ih][iw]!=".": continue
        for j in range(x):
            ih,iw=i//w,i%w
            jh,jw=j//w,j%w
            if d[jh][jw]!=".": continue
            for k in range(j+1):
                ih,iw=i//w,i%w
                jh,jw=j//w,j%w
                kh,kw=k//w,k%w
                if d[kh][kw]==".":
                    p[j][k]=min(p[j][k],p[j][i]+p[i][k])
                    p[k][j]=min(p[k][j],p[j][i]+p[i][k])
    ans=0
    for i in p:
        for j in i:
            if j<x+1:
                ans=max(ans,j)
    print(ans)

if __name__=="__main__":
    sol()

Measured memory_bytes: 47344
#include<iostream>

int main(){
  int D;
  std::cin>>D;

  if (D == 25)
    std::cout<<"Christmas";

  else if(D == 24)
   std::cout<<"Christmas Eve";

  else if(D == 23)
   std::cout<<"Christmas Eve Eve";

  else
   std::cout<<"Christmas Eve Eve Eve";

  return 0;
}

Measured memory_bytes: 256
/*  Success may not come to me immediately,
 *  but it will come definitely....
 */
#include <bits/stdc++.h>
//=====================================================================
using namespace std;
//=====================================================================
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//=====================================================================
#define li      int64_t
#define ld      double_t
#define ulli    uint64_t
//=====================================================================
#define rep(i,a,b)  for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define repi(i,v)   for(i=v.begin();i!=v.end();i++)
#define repir(i,v)  for(i=v.rbegin();i!=v.rend();i++)
#define elif        else if
#define mset(a,b)   memset(a,b,sizeof(a))
#define nl          cout<<'\n'
//=====================================================================
typedef vector<li>       vli;
typedef vector<string>   vstr;
typedef pair<li,li>      pli;
typedef pair<li,pli >    ppli;
typedef pair<li,ppli >   pppli;
typedef vector<pli >     vpl;
typedef vector<ppli >    vppli;
typedef vector<pppli >   vpppli;
//=====================================================================
#define pb  push_back
#define pob pop_back
#define pf  push_front
#define pof pop_front
#define all(v)  v.begin(),v.end()
#define itr iterator
#define rtr reverse_iterator
#define sz  size()
#define lb  lower_bound
#define ub  upper_bound
#define bs  binary_search
#define mp  make_pair
#define F   first
#define S   second
//=====================================================================
#define mod (li)(1e9+7)
#define inf (li)(1e18)
#define MX1 (li)(1e5+5)
#define MX2 (li)(1e6+5)
#define pi  acos(-1)
//=====================================================================
li power(li a,li b){li ans=1;while(b){if(b&1){ans=(ans*a)%mod;}
a=(a*a)%mod;b>>=1;}return ans;}
//=====================================================================
li mmi(li n){return power(n,mod-2);}
//=====================================================================
li two(li n){return (1LL<<n);}
//=====================================================================
void onbit(li &n,li x){n|=two(x);}
//=====================================================================
void offbit(li &n,li x){n&=~two(x);}
//=====================================================================
li cntbit(li n){li res=0;while(n and ++res)n-=n&-n;return res;}
//=====================================================================
li dx[]={-1,0,1,0},dy[]={0,-1,0,1};
//=====================================================================
/*------------------------MAIN CODE BEGINS NOW!------------------------*/

li n,a[MX1];
map<li,li> mpp;

void solve(){
  li i;cin>>n;
  rep(i,0,n) cin>>a[i],mpp[a[i]]++,mpp[a[i]+1]++,mpp[a[i]-1]++;
  li ans=0;
  rep(i,1,MX1){
    ans=max(ans,mpp[i]);
  }
  cout<<ans;
}

int main(){
  opt
  #ifndef ONLINE_JUDGE
  #endif
  li t=1;
  //cin>>t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 7296
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
vector<int> e[200010];
ll cnt[200010];
void dfs(int u,int fa)
{
	cnt[u]+=cnt[fa];
	for(auto v:e[u])if(v!=fa)dfs(v,u);
}
int main()
{
	int n,q;
	scanf("%d%d",&n,&q);
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	while(q--)
	{
		ll x,y;
		scanf("%lld %lld",&x,&y);
		cnt[x]+=y;
	}
	dfs(1,0);
	for(int i=1;i<=n;i++) printf("%lld%c",cnt[i],i==n?'\n':' ');
}

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


int main(){
    int N, x;
    cin >> N >> x;
    int ans [200000];
    ans[N-1] = x;
    ans[N-2] = x-1;
    ans[N] = x+1;
    if(x == 1 || x == 2*N-1){
        cout << "No" << endl;
        return 0;
    }
    x += 2;
    for(int i = 2; i <= N - 1; i++){
        ans[(N-1) - i] = (x-1) % (2*N-1) + 1;
        x++;
        ans[(N-1) + i] = (x-1) % (2*N-1) + 1;
        x++;
    }
    cout << "Yes" << endl;
    for(int i = 0; i < 2*N-1; i++){
        cout << ans[i] << endl;
    }

}

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

using namespace std;

int n, h[100000], dp[100000];

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


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

int main() {
  int n;
  cin >> n;
  vector<int> b(n-1);
  rep(i,n-1) cin >> b[i];
  vector<int> a(n);
  
  a[0] = b[0];
  rep(i,n-2){
    a[i+1] = min(b[i],b[i+1]);
  }
  a[n-1] = b[n-2];
  int ans = 0;
  rep(i,n) ans+=a[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin>>n;
  ll a[n+1]={};
  ll sum=0,ma=0;
  bool flag=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
    if(a[i]%2) flag=1;
  }

  if(flag)cout<<"first"<<endl;
  else cout<<"second"<<endl;




  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define lli long long
const lli INF = (lli)(1e12);
lli dp[100002];
lli w[102],val[102];
lli n,W;

int main() 
{
    cin >> n >> W;
    
    for(lli i=1;i<=n;i++){
         cin >> w[i] >> val[i];
    }
    
    for(lli j=0;j<=100001;j++) dp[j] = INF;
    
    dp[0]=0;
    
    for(lli i=1;i<=n;i++){
        for(lli j=100001;j>=val[i];j--){
            dp[j]=min(dp[j],dp[j-val[i]]+w[i]);
        }
    }
    
    lli ans = 0;
    for(lli i=1;i<=100001;i++){
        if(dp[i]<=W) ans=max(ans,1LL*i);
    }
    
    cout<<ans<<endl;
    
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>

#define rep(i,n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> h(N);
  rep(i,N) cin >> h[i];

  int ans = 0;
  for(auto &i:h){
    if(i >= K) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	double s=0,a[1001];
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		s=s+1/a[i];
	}
	s=1/s;
	cout<<s;
	return 0;
}

Measured memory_bytes: 384
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 2005
#define oo 1000000000000000007LL
#define sz(a) (int)a.size()
#define left aofnojaef
#define right aionfeoangrou

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

template<typename T>
struct slopeQueue {
private:
    T pq;
    ll delta;
public:
    void push(ll x) {pq.push(x-delta);}
    void update(ll x) {delta += x;}
    ll top() {return pq.top() + delta;}
    void pop() {pq.pop();}
    void print() {
        T tmp = pq;
        while (!tmp.empty()) {
            cout << tmp.top() + delta << " ";
            tmp.pop();
        }
        cout << endl;
    }
};

ll cost(ll l, ll r, ll x) {
    if (x < l) return l-x;
    if (x > r) return x-r;
    return 0;
}

int main () {
    int n; scanf("%d", &n);
    vector<int> l(n), r(n);
    fto(i, 0, n-1) scanf("%d%d", &l[i], &r[i]);

    slopeQueue<priority_queue<ll> > left;
    slopeQueue<priority_queue<ll, vector<ll>, greater<ll> > > right;
    left.push(l[0]);
    right.push(l[0]);

    ll ans = 0;
    fto(i, 1, n-1) {
        left.update(l[i]-r[i]);
        right.update(r[i-1]-l[i-1]);

        ans += cost(left.top(), right.top(), l[i]);

        left.push(l[i]);
        right.push(l[i]);

        while (left.top() > right.top()) {
            ll x = left.top(); left.pop();
            ll y = right.top(); right.pop();
            left.push(y); right.push(x);
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 2804
from collections import  Counter
N = int(input())
A = list(map(int, input().split()))
A = dict(Counter(A))
even = len(list(filter(lambda x: x%2==0, list(A.values()))))
if even % 2 == 1:
    print(len(A)-1)
else:
    print(len(A))

Measured memory_bytes: 21724
A,B,C=map(int,input().split())
arr=[]
if((A>=1 and A<=9)and(B>=1 and B<=9)and(C>=1 and C<=9)):
    arr=[A,B,C]
    arr=sorted(arr, reverse=True)
    mystr=str(arr[0])+str(arr[1])
    print(int(mystr)+arr[2])

Measured memory_bytes: 3060
from collections import deque
N = int(input())
node_dic = {}
ab_array = [list(map(int,input().split())) for _ in range(N-1)]

for a,b in ab_array:
    if a in node_dic:
        node_dic[a][b] = 0
    else:
        node_dic[a] = {b : 0}
    if b in node_dic:
        node_dic[b][a] = 0
    else:
        node_dic[b] = {a : 0}

# print(node_dic)

max_color = 0

queue = deque()
flag = [0] * N
first = ab_array[0][0]
queue.append((first,0))
flag[first-1] = 1

while len(queue):
    p, ban_color = queue.popleft()
    now_color = 1
    for key in node_dic[p].keys():
        if now_color == ban_color:
            now_color += 1
        if flag[key-1] == 0:
            queue.append((key,now_color))
            node_dic[p][key] = now_color
            node_dic[key][p] = now_color
            flag[key-1] = 1
            max_color = max(max_color,now_color)
            now_color += 1
print(max_color)
for a,b in ab_array:
    print(node_dic[a][b])


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

int n, l;
int sum, mn = 1000000000, bi;

int main()
{
    cin >> n >> l;
    for (int i = 0; i < n; i++) {
        sum += l + i;
        if (abs(l + i) < mn) {
            mn = abs(l + i);
            bi = l + i;
        }
    }
    printf("%d\n", sum - bi);
    return 0;
}


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

using namespace std;

void solve()
{
  string str;
  cin >> str;
  if(str.size() >= 4 && str.substr(0, 4) == "YAKI") {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}

int main()
{
  solve();
}

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

using namespace std;


int main() {
    long long a;
    int x,y;
    scanf("%lld %d.%d",&a,&x,&y);
    int z = 100 * x + y;
    long long ans = a * z;
    ans /= 100;
    printf("%lld\n",ans);
    return 0;
}

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


int A[100];
int main(){
	int n,a,ans=0;
	cin >> n;
	
	for(int i=0;i<n;i++){
		cin >> a;
		A[i]=a;
	}
	for(int i=0;i<n;i++){
		cin >> a;
		if(A[i]>a) ans+=(A[i]-a);
	}
	
	cout << ans << endl;
	return 0;
}

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

int main() {
	string s;
	cin>>s;
	int n = s.length();
	int ans = n / 2;
	for(int big = 0; big < 2; big++) {
		if((n % 2) == 0) {
			for(int i = n/2, j = n/2 - 1; i < n; i++, j--) {
				if(s[i] == '1' or s[j] == '1')	break;
				else ans = max(ans, i + 1);
			}
		} else {
			for(int i = n/2, j = n/2; i < n; i++, j--) {
				if(s[i] == '1' or s[j] == '1')	break;
				else	ans = max(ans, i + 1);
			}
		}
		for(int i = 0; i < n; i++) {
			if(s[i] == '0')	s[i] = '1';
			else			s[i] = '0';
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 200005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans;
int N,M;
vi A, B;
bool visited[MAXN] = {}, flag=false;;

void solve(){
    rep(i, M){
        if(A[i] == 0) visited[B[i]] = true;
    }

    rep(i, M){
        if(B[i] == (N-1) && visited[A[i]]) {
            flag = true;
            break;
        }
    }

    if(flag) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

int main(){
    cin >> N >> M;
    A.resize(M);
    B.resize(M);

    rep(i, M) {
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
    }
    solve();
}


Measured memory_bytes: 2048
// Created by arvybhatt

#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define p_b push_back
#define m_p make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)

#define ll long long int
using namespace std;


ll power(ll x, ll y) { ll temp; if( y == 0) return 1; temp = power(x, y/2); if (y%2 == 0) return temp*temp; else return x*temp*temp; } 

int main()
{
	fast;

	int a,b;cin>>a>>b;
	cout<<a*b;

}


Measured memory_bytes: 3544
# input n
# input height

n = int(input())
height = list(map(int,input().split()))

count = 0
i = 0


for i in range(n-1):
    if height[i] > height[i+1]:

        count += height[i] - height[i+1]
        height[i+1] += height[i] - height[i+1]


print(count)

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

typedef long long int ll;

int main(){
    ll n,W;
    cin>>n>>W;
    ll i,j;
    ll w[n+1],v[n+1];
    w[0]=0;v[0]=0;
    ll sum=0;
    for(i=1;i<=n;i++){
        cin>>w[i]>>v[i];
        sum+=v[i];
    }
    ll dp[n+1][sum+1];
    for(i=0;i<sum+1;i++)
        dp[0][i]=1e18+5;
    for(i=0;i<n+1;i++)
        dp[i][0]=0;
    for(i=1;i<n+1;i++){
        for(j=1;j<sum+1;j++){
            if(v[i]<=j)
                dp[i][j]=min(w[i]+dp[i-1][j-v[i]],dp[i-1][j]);
            else
                dp[i][j]=dp[i-1][j];    
        }
    }
    ll ans=0;
    for(i=1;i<n+1;i++){
        for(j=1;j<sum+1;j++){
            if(dp[i][j]<=W)
                ans=max(ans,j);
        }
    }
    cout<<ans<<endl;      
    return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

ll W, H, P[100000], Q[100000];

int main(void) {
  cin >> W >> H;
  REP(i, 0, W) cin >> P[i];
  REP(i, 0, H) cin >> Q[i];

  vector<pll> len;
  REP(i, 0, W) len.push_back(pll(P[i], 0));
  REP(i, 0, H) len.push_back(pll(Q[i], 1));
  sort(len.begin(), len.end());

  ll wcnt = 0, hcnt = 0, ans = 0;
  REP(i, 0, len.size()) {
    ll l = len[i].first;
    ll t = len[i].second;

    if(t == 0) {
      ans += (H + 1 - hcnt) * l;
      wcnt++;
    } else {
      ans += (W + 1 - wcnt) * l;
      hcnt++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 7792
<?php
$array = str_split(trim(fgets(STDIN)));

$count = count($array);

if ($count % 2 === 0) { // 文字数が偶数
  $c = $count / 2;
} else { // 文字数が奇数
  $c = floor($count / 2);
}

$array1 = array();
for ($i=0; $i<$c; $i++) {
  $array1[] = $array[$i];
}

$array2 = array();
for ($i=$count-1; $i>=$count-$c; $i--) {
  $array2[] = $array[$i];
}

echo count(array_diff_assoc($array1, $array2));


Measured memory_bytes: 4856
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void)
{
	char c;
	int i = 1, flag = 0;

	while ((c = getchar()) != '\n')
	{
		if (i % 2 == 1)
		{
			if (!(c == 'R' || c == 'U' || c == 'D'))
			{
				flag = 1;
				break;
			}
		}
		else 
		{
			if (!(c == 'L' || c == 'U' || c == 'D'))
			{
				flag = 1;
				break;
			}
		}
		i++;
	}

	if (flag == 0)printf("Yes");
	else printf("No");


	return 0;
}


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

long long n,ans,f[3];
string s[10004];

int main(){

	cin>>n;
	
	for(int i=0;i<n;i++){
	    cin>>s[i];
        for(int j=0;j+1<s[i].size();j++)if(s[i][j]=='A' && s[i][j+1]=='B')ans++;
	    if(s[i][0]=='B' && s[i][s[i].size()-1]=='A')f[0]++;
	    else{
	        if(s[i][0]=='B')f[1]++;
	        if(s[i][s[i].size()-1]=='A')f[2]++;
        }
    }

    if(f[0]>0){
        
        ans+=f[0]-1;
        if(f[1]>0){
            ans++;
            f[1]--;
        }
        
        if(f[2]>0){
            ans++;
            f[2]--;
        }
        
    }
    
    ans+=min(f[1],f[2]);
    
    cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 768
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x) for x in sys.stdin.readline().split()]

def solv(a,b):
    a_ = a
    b_ = b
    while(a_%b_ != 0):
        a_,b_ = b_,a_%b_
    return a*b//b_
    
def main():
    A,B = LI()
    print(solv(A,B))

if __name__ == "__main__":
    main()


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

int main(){
    int maxn = 0;
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i != j){
                maxn = max(maxn, abs(a[i] - a[j]));
            }
        }
    }
    put(maxn);
}

Measured memory_bytes: 256
#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
long long int f[1000000];

long long int final(long long int *a,int i,int n,int k)
{
    if (f[i]!=1e18)
        return f[i];
    for (int j=1;j<=k;j++)
        f[i]=min(f[i],final(a,i+j,n,k)+abs(a[i]-a[i+j]));
    return f[i];
}

signed main()
{
   faster;
   //#ifndef ONLINE_JUDGE
     //freopen("ip.txt", "r", stdin);
    // freopen("op.txt", "w", stdout);
   //#endif
     // int t;cin>>t;
     // t=1;
     // while(t--)
     {
        int n,k,tem;
        cin>>n>>k;
        long long int a[n];
        for (int i=0;i<n;i++)  f[i]=1e18;
        for (int i=0;i<n;i++)
            cin>>a[i];
        f[n-1]=0;
        if (k>n)
            tem=-1;
        else
            tem=n-1-k;
        for (int i=n-2;i>tem;i--)
        {
            for (int j=i+1;j<n;j++)
                f[i]=min(f[i],f[j]+abs(a[i]-a[j]));
        }
       // cout<<f[2]; 
         cout<<final(a,0,n,k);
        // cout<<final(a,0,n);

     }
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int main(){
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    double tha = 2.0 * M_PI * (60.0*h+m) / (60.0*12.0);
    double thb = 2.0 * M_PI * m / 60.0;
    double thab = abs(thb - tha);
    if(thab > M_PI) thab = 2*M_PI - thab;
    double ans = sqrt(a*a+b*b - 2*a*b*cos(thab));
    printf("%.10f\n",ans);
    return 0;
}

Measured memory_bytes: 4208
from collections import Counter
mod=998244353
N=int(input())
D=list(map(int,input().split()))
if D[0]!=0:
  print(0)
else:
  tmp=Counter(D)
  if tmp[0]!=1:
    print(0)
  else:
    ans=1
    for i in tmp.keys():
      if i==0 or i==1:
        continue
      ans*=tmp[i-1]**tmp[i]
      ans%=mod
    print(ans)

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

int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
int H,W,M;
int sy,sx;
char t[50][50];
int p[50][50];
int q[50][50];
int a[50][50];
int b[50][50];
int c[50][50];
int g[50][50];

vector<int> calc(int ay,int ax,int by,int bx){
  vector<int> c,d;
  while(ay!=by||ax!=bx){
    if(q[ay][ax]>q[by][bx]){
      int dir=p[ay][ax];
      c.push_back(dir);
      ay+=dy[dir];
      ax+=dx[dir];
    }else{
      int dir=p[by][bx];
      d.push_back(dir);
      by+=dy[dir];
      bx+=dx[dir];
    }
  }
  reverse(d.begin(),d.end());
  for(int i=0;i<(int)d.size();i++)c.push_back((d[i]+2)%4);
  return c;
}

void rec(int y,int x,int z){
  for(int i=0;i<4;i++){
    int ny=y+dy[i],nx=x+dx[i];
    if(ny<0||nx<0)continue;
    if(ny>=H||nx>=W)continue;
    if(t[ny][nx]=='#')continue;
    if(p[ny][nx]==-1){
      p[ny][nx]=(i+2)%4;
      q[ny][nx]=z+1;
      rec(ny,nx,z+1);
    }
  }
}

void init(){
  sy=-1;
  for(int i=0;i<50;i++){
    for(int j=0;j<50;j++){
      p[i][j]=-1;
      g[i][j]=-1;
    }
  }
}

int main(){
  cin>>H>>W>>M;
  init();
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>t[i][j];
      if(t[i][j]=='.'&&sy==-1)sy=i,sx=j;
    }
  }
  
  p[sy][sx]=-2;
  q[sy][sx]=0;
  rec(sy,sx,0);
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>a[i][j];
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>b[i][j];
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>c[i][j];  
  int ay,ax,by,bx,cnt=0,ans=0;
  cin>>by>>bx;
  for(int i=0;i<M-1;i++){
    ay=by;ax=bx;
    cin>>by>>bx;
    vector<int> v=calc(ay,ax,by,bx);
    for(int j=0;j<(int)v.size();j++){
      if(g[ay][ax]==-1){
        ans+=b[ay][ax]+c[ay][ax];
      }else{
        int A=b[ay][ax]+c[ay][ax];
        int d=cnt-g[ay][ax];
        int B=d*a[ay][ax];
        ans+=min(A,B);
      }
      g[ay][ax]=cnt;
      ay+=dy[v[j]];
      ax+=dx[v[j]];
      cnt++;
    }
  }
  if(g[ay][ax]==-1){
    ans+=b[ay][ax]+c[ay][ax];
  }else{
    int A=b[ay][ax]+c[ay][ax];
    int d=cnt-g[ay][ax];
    int B=d*a[ay][ax];
    ans+=min(A,B);
  }
 
  cout<<ans<<endl;

  return 0;
}
  

Measured memory_bytes: 1364
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
vector<ll> num;
vector<ll> p;

//レベルN層の左からXにあるPの数
ll findNum(int N, ll X)
{
    if(N==0)
        return 1;

    if(X==1)
        return 0;
    else if(X<=num[N]/2)
    {
        return findNum(N-1, X-1);
    }
    else if(X==(num[N]/2+1))
    {
        return 1+p[N-1];
    }

    return 1 + p[N-1] + findNum(N-1, X-2-num[N-1]);

}

int main()
{
    int N;
    ll X;
    cin>>N>>X;

    num.resize(50);
    p.resize(50);

    num[0] = 1;
    p[0] = 1;
    for(int i=0; i<50; ++i)
    {
        num[i+1]= 2 * num[i] + 3;
        p[i+1] = 2 * p[i] + 1;
    }

    ll ans = findNum(N, X);

    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <vector>

#include <iostream>
#define rep(i,n) for(int i=0; i<(n); i++)

using namespace std;

typedef vector<int> vi;

// ?????£?????????????§£ (Strongly Connected Component)
// ????????°???????????°????????????????????£??¬??????????????? ???????????§
struct SCCGraph: public vector<vi> {

	vector<int> order;    // ????????????????????????(?????£?????????????£?????????????)
	vector<int> vs;   // ??°????????????
	vector<bool> used;    // ?????§???????????????

	using vector::vector;

	// a -> b ????????????????????????push_back()??§?????????
	void add_edge(int a, int b){
		(*this)[a].push_back(b);
	}

	// ??¢??°???????????§?????????scc(v)??¨????????????????????????
	vector<int> operator()(vector<vi> v){
		(*this).assign( v.begin(), v.end() );
		scc();
		return order;
	}

	// scc()??§??????
	void dfs(int n, int k, vector<vi> &v, vector<vi> &rv){
		used[n] = true;
		order[n] = k;
		for(auto t: v[n]){
			if( !rv.empty() ) rv[t].push_back(n);	// ???????????°???????????????
			if( !used[t] ) dfs(t, k, v, rv);
		}
		vs.push_back(n);
	}

	// ?????£?????????????§£?????????
	int scc(){
		int N = size();
		used.assign(N, false);
		order.resize(N);
		vs.clear();
		vector<vi> rG(N), tmp;   // ????????????????????°????????¨
		for(int n=0; n < N; n++){
			if( !used[n] ) dfs(n, n, (*this), rG);
		}
		used.assign(N, false);
		int k = 0;
		for(int i = vs.size()-1; i >= 0; i--){
			if( !used[ vs[i] ] ) dfs(vs[i], k++, rG, tmp);
		}
		return k++;
	}

	// ?±????????????£????????????????????????????????????
	bool find(int x, int y){
		return order[x] == order[y];
	}

} scc(0);

// 2-SAT ??????
class TwoSAT{
};


// test
// AOJ GRL_3_C (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_C&lang=jp)
int main(){
	int V, E;
	cin >> V >> E;
	//SCCGraph graph(V);
	vector<vi> edge(10005);
	rep(i,E){
		int s, t;
		cin >> s >> t;
		//graph.add_edge( s, t );
		edge[s].push_back( t );
	}

	//graph.scc();
	//rep(i,V) cout << "graph: " << i << " " << graph.order[i] << endl;

	auto g = scc(edge);

	int Q;
	cin >> Q;
	rep(i,Q){
		int u, v;
		cin >> u >> v;
		//cout << (int)graph.find(u, v) << endl;
		cout << (int)(g[u] == g[v]) << endl;
	}

	return 0;
}

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

using namespace std;

int main(void) {
    int N, Y;
    cin >> N >> Y;
    int x = -1;
    int y = -1;
    int z = -1;

    for(int i = 0; i < N+1; i++) {
        for (int j = 0; j < N+1; j++) {
            if (N < (i + j)) {
                break;
            }
            int k = N - (i + j);
            unsigned long sum = (10000 * i) + (5000 * j) + (1000 * k);
            if (sum == Y) {
                x = i;
                y = j;
                z = k;
            }
            if (x != -1) break;
        }
        if (x != -1) break;
    }

    cout << x << ' ' << y << ' ' << z << endl;

    return 0;
}

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

int main(){
  int n;
  int ans=100000;

  cin >> n;

  for(int i=0;i<n;i++){
    ans *= 1.05;
    if((int)ans%1000){
      ans-=(ans%1000);
      ans+=1000;
    }
  }

  cout<<ans<<"\n";
}

Measured memory_bytes: 0
X = [[int(a) for a in input().split()] for _ in range(3)]
f = 0
for i in range(1, 3):
    for j in range(1, 3):
        if X[i][j] + X[0][0] != X[i][0] + X[0][j]:
            print("No")
            f = 1
            break
    if f:
        break
else:
    print("Yes")

Measured memory_bytes: 38384
#include "stdio.h"

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

  int count = 0;
  for(int i=0; i<n; i++){
    int minj = i;
    for(int j=i; j<n; j++){
      if(a[j]<a[minj]) minj = j;
    }
    if(a[i] != a[minj]){
       int tmp = a[i];
       a[i] = a[minj];
       a[minj] = tmp;
       count++;
     }
  }

  for(int i=0; i<n; i++){
    if(i>0) printf(" ");
    printf("%d", a[i]);
  }
  printf("\n%d\n", count);
  return 0;
}

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

int main(){
    int n;
    cin>>n;
    int v[n],c[n];
    rep(i,n)cin>>v[i];
    rep(i,n)cin>>c[i];

    int wa[n];
    rep(i,n)wa[i] = v[i] - c[i];

    int sum=0;
    rep(i,n){
        if(wa[i] >= 0){
            sum += wa[i];
        }
    }
    cout<<sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力
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;
}


int main() {
    //COMinit();
    ll N;
    cin >>N;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    map<ll,ll> m;
    ll ans = 1;
    m[-1] = 3;
    rep(i,N){
      
        ans = (ans* max(m[A[i]-1]-m[A[i]],ll(0)))%MOD;
        m[A[i]]++;
    }


    cout << ans << endl;


    return 0;
    

}

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


typedef complex<double> P; //Point
typedef pair<P,P> L; //Line, Segment

const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);

namespace std {
  bool operator < (const P& a, const P& b){
    return fabs(real(a)-real(b)) < EPS ? imag(a) < imag(b) : real(a) < real(b);
  }
}

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


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


// ???????????? a,b ???????????¢???
int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1; 
  if(cross(b,c) < -EPS) return -1; 
  if(dot(b,c) < -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

// ????????¨???????????¢
double getDistanceSP(L s, P p){
  if(dot(s.second - s.first, p - s.first) < -EPS) return abs(p - s.first);
  if(dot(s.first - s.second, p - s.second) < -EPS) return abs(p - s.second);
  return abs(cross(s.second - s.first, p - s.first) / abs(s.second - s.first));  //??´?????¨???????????¢
}
 
// ?????´???????????????
P crossPoint(L l, L m){
  double A = cross(l.second - l.first, m.second - m.first);
  double B = cross(l.second - l.first, l.second - m.first);
  if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
  else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}


/*
  ???????§???¢?????´?????§??????????????´?????¨????????????
  ???????§???¢??????????¨???????????????????
  vector<P>??????????§???¢
*/
vector<P> convex_cut(vector<P> G, L l){
  vector<P> ans;
  for(int i=0;i<(int)G.size();i++){
    P A = G[i];
    P B = G[(i+1)%G.size()];
    if(ccw(l.first, l.second, A) != -1) ans.push_back(A);
    if(ccw(l.first, l.second, A) * ccw(l.first, l.second, B) < 0)
      ans.push_back(crossPoint(L(A,B), l));
  }
  return ans;
}

//??´??????????????????????????????????±???????
vector<P> getUnitNormalV(P A,P B){
  vector<P> v;
  v.push_back( ((B-A)*P(0,1))/abs(B-A) );
  v.push_back( ((B-A)*P(0,-1))/abs(B-A) );
  return v;
}

//??????s????????¢d?????????????§????
vector<L> getTranslation(L s,double d){
  vector<P> p = getUnitNormalV(s.first,s.second);
  vector<L> ret;
  for(int i=0;i<2;i++){
    ret.push_back( L( s.first + p[i]*d , s.second + p[i]*d ) );
  }
  return ret;
}

int N;
vector<P> v;

const double WPS = 35.0;
const double BPS = 10.0;

int main(){
  while( (~scanf("%d",&N)) && N ){
    v.clear();
    for(int i=0;i<N;i++) {
      int x,y;
      scanf("%d%d",&x,&y); v.push_back( P(x,y) );
    }
    v.push_back(P(v[0]));
    double st = 0.0, ed = 1e5;
    while( (ed-st) > EPS ){
      double d = (st+ed)/2.0;
      vector<P> Q = v;
      Q.pop_back();
      for(int i=0;i<N;i++){
	L s = L(v[i],v[i+1]);
	vector<L> tr = getTranslation(s,d);
	if( ccw(s.first,s.second,tr[0].first) == 1 )
	  Q = convex_cut(Q,tr[0]);
	 else 
	  Q = convex_cut(Q,tr[1]);	
      }
      if( Q.empty() )
	ed = d;
      else
	st = d;
    }

    printf("%.8lf\n",ed);
  }
}

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

long long int M=1e+9+7;
long long int power(long long int x, long long int n)
{
    if (n == 0)
        return (long long)1;
    else if (n % 2 == 0) //n is even
        return power((x * x) % M, n / 2);
    else //n is odd
        return (x * power((x * x) % M, (n - 1) / 2)) % M;
}
long long int cans(long long int p, long long int q)
{
    return ((p * power(q, M - 2)) % M + M) % M;
}
const int N=2e+5+5;
long long int n,fact[N],facti[N];

long long int ncr1(long long int r)
{
    long long int ans1=1;
    for(long long int i=0;i<r;i++)
        ans1=(ans1*(n-i))%M;
    // cout<<r;
    ans1=(ans1*facti[r]);

    return ans1;
}
int main()
{
    long long int a,b;
    cin>>n>>a>>b;
    // cout<<a<<" "<<b<<" ";
    fact[0]=facti[0]=1;
    for(int i=1;i<N;i++)
    {
        fact[i]=(i*fact[i-1])%M;
        facti[i]=cans(1,fact[i]);
    }
    long long int ans=power(2,n);
    // cout<<facti[1]<<" "<<a<<" ";
    ans=(ans-ncr1(a))%M;
    ans=(ans-ncr1(b)-1)%M;
    ans=(ans+M)%M;
    cout<<ans;
}

Measured memory_bytes: 3328
--lemma:n頂点n-1辺で閉路を持たないならば木である。
--proof:n=1の時、明らか。
--      n=kまでの題意を仮定する。辺を１つ削除すると、
--      閉路を持たないので真に頂点の少ない木が２つ出来、仮定よりこれらは木。
--      削除辺を復活させるとこれもまた木である。
--
--したがって、n頂点重み付きグラフの最小全域木は、閉路を構成しないn-1個の辺の選択の内、最小の選びかたをすればよい。
--次の貪欲法を考える：
--Kruskal:n頂点重み付きグラフに対して、最小重み辺を選択する。「既に選択した辺とで閉路をなさない」限りで小さい重みをもつ辺を順次n-1個選択する。
--theorem:Kruskalは最小全域木の１つを構成する。
--proof:最小全域木は必ず存在するのでこれをS、Kruskalで構成される全域木をKとし、この重みはSより大きいと仮定する。
--      S,Kの辺を重みでソートする。Kの並びは各々その構成時のものに一致させられる。この並びで最初に重みが食い違うS,Kの辺をe_s,e_kとする。
--      Kの構成法から、w(e_s)>=w(e_k)である。重みは異なるとしたのでw(e_s)>w(e_k)でなければならない。
--      しかしSにおいてe_kとe_sを入れ替えたものをS'とすると、
--      S'は全域木であり、かつw(S')<w(S)で最小性に反する。したがって、Kの重みはSに一致し、Kruskalは最小全域木の１つを構成する。

--問題の場合、(W+1)*(H+1)格子グラフ上で、辺をソートし、Kruskalにしたがって、閉路を回避しつつ選択できる辺の重み総和を計算すればよい。
--最初の最小重み辺p_iH+1個(として一般性を失わない)は確実に選択できる。次の重み辺からは閉路を回避する必要があり、その条件は
--p_k重み辺H+1個から選択する場合：特に条件なし。
--q_jW+1個から選択する場合：(i,j)-(i+1,j),(i,j+1)-(i+1,j+1)が既にあるのでこれに接続する二辺はどちらか一方のみしか選択できない。
--となる。ところが以上の条件に該当する辺の数は、
--(i,j)-(i+1,j),(i,j+1)-(i+1,j+1)を縮約したW*(H+1)格子グラフ上での、
--p_k重み辺H+1個
--q_j重み辺W個((i,j)-(i,j+1),(i+1,j)-(i+1,j+1)は同一視される)
--に一致する。((W+1)*(H+1)->W*(H+1)格子グラフ準同型が存在する)。つまり問題を変形した上で、まっさらなところから選び直せる。
--したがってこの問題は次の再帰構造をもつ：
--solver(W,H,[p],[q])=let x = min[p,q] in if x==p_i then (H+1)*x+solver(W-1,H,[p]\p_i,[q])
--                                   else if x==q_j then (W+1)*x+solver(W,H-1,[p],[q]\q_j)
--solver(0,0,[][])=0

import Text.Regex
import GHC.Exts

data PQ = P | Q deriving (Eq,Show)

main::IO()
main =do
  wh<-getLine
  let w:h:[]=map read (words wh)::[Int]
  ps<-get_n w
  qs<-get_n h
  let pp= map (\x->(P,x)) ps
  let qq= map (\x->(Q,x)) qs
  let pq= sortWith (\(_,x)->x) (pp++qq)
  print (solver w h pq)

get_n::Int -> IO [Int]
get_n 0 = return []
get_n n = do
          c<-getLine
          let m = read c ::Int
          rest<- (get_n (n-1))
          return (m:rest)

solver::Int -> Int -> [(PQ,Int)] -> Int
solver 0 0 [] = 0
solver w h ((P,p_i):rest) = ((h+1)*p_i)+(solver (w-1) h rest)
solver w h ((Q,q_j):rest) = ((w+1)*q_j)+(solver w (h-1) rest)

Measured memory_bytes: 130428
import sys
for line in sys.stdin:
    h, w = map(int, line.rstrip('\n').split(' '))
    if h == 0 and w == 0: break
    for row in range(h):
        if row in (0, h-1):
            print '#' * w
        else:
            print '#' + '.'*(w-2) + '#'
    print ''

Measured memory_bytes: 4208
from collections import Counter

s = input()

cnt = Counter(s)

if len(cnt.keys()) == 1:
    print(0)
    
else:
    al_set = set(s)
    c = list(s)
    
    dic = {}
    for alpha in al_set:
        c_prev = [ci for ci in c]
        count = 0
        while any([ci != alpha for ci in c_prev]):
            c_new = []
            for j in range(len(c_prev) - 1):
                if c_prev[j] == alpha or c_prev[j+1] == alpha:
                    c_new.append(alpha)
                else:
                    c_new.append("0")
                    
            c_prev = c_new
            count += 1

            
        dic[alpha] = count
        
    print(min(dic.values()))
            

Measured memory_bytes: 3444
#include <bits/stdc++.h> 
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 2e3+10;
const int N = 1e6+10;
const int E = 1e6+10;  
ll n,x,y;
ll f[maxn][maxn];
vector<int> g[maxn];
ll cnt[maxn];
bool vis[maxn];
struct node{
	int v,len;
	node(int v,int len):v(v),len(len){}
};

void bfs(int u,int v){
	queue<node> Q;
	Q.push(node(u,v));
	memset(vis,0,sizeof(vis));
	f[u][u] = v;
	vis[u]=1;
	while(!Q.empty()){
		node tmp  = Q.front();
		Q.pop();
		F(i,0,g[tmp.v].size()-1){
			int k = g[tmp.v][i];
			if(!vis[k]){
				vis[k]=1;
				f[u][k] = tmp.len+1;
				Q.push(node(k,tmp.len+1));
			}
		}
	}
}

int main(){
	cin>>n>>x>>y;
	F(i,1,n){
		if(i<n) g[i].pb(i+1);
		if(i>1) g[i].pb(i-1);
	}
	g[x].pb(y);
	g[y].pb(x);
	F(i,1,n){
		bfs(i,0);
	} 
	F(i,1,n){
		F(j,i+1,n){
			cnt[f[i][j]]++;
		}
	}
	F(i,1,n-1){
		cout<<cnt[i]<<endl;
	}
}

Measured memory_bytes: 31744
#define taskname ""

#include <iostream>
#include <algorithm>

using namespace std;
#define long long long

const int N = 1e5 + 10;
const long INF = 1e16;

int n, total;
typedef pair<int, int> pii;
pii pack[N];
long f[N];

int main()
{
//    freopen(taskname".INP", "r", stdin);
//    freopen(taskname".OUT", "w", stdout);
    cin.tie(nullptr); ios_base::sync_with_stdio(false);

    cin >> n >> total;
    for (int i = 1; i <= n; ++i) cin >> pack[i].first >> pack[i].second;

    fill(f, f + N, INF); f[0] = 0;

    for (int i = 1; i <= n; ++i)
        for (int val = N - 1; val; --val)
            if (val >= pack[i].second) f[val] = min(f[val], f[val - pack[i].second] + pack[i].first);

    for (int val = N - 1; val; --val)
        if (f[val] <= total) {cout << val; return 0;}

    return 0;
}


Measured memory_bytes: 1024