akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}

int main(){
    int A=in(),B=in(),M=in();
    vec a(A),b(B);
    int b_min = 100005;
    rep(i,A)a[i]=in();
    rep(i,B){
        b[i]=in();
        b_min = min(b_min,b[i]);
    }
    vector<vector<pii>> p(A);
    rep(i,M){
        int x=in()-1,y=in()-1,c=in();
        p[x].pb(mp(y,c));
    }
    int ans = 200020;
    rep(i,A){
        int tmp = a[i] + b_min;
        REP(e,p[i]){
            int y = e.first,c=e.second;
            tmp = min(tmp,a[i] + b[y] - c);
        }
        ans = min(ans,tmp);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5504
ABM = input().split()
A = int(ABM[0])
B = int(ABM[1])
M = int(ABM[2])

aas = input().split()
aas = [int(a) for a in aas]
as2 = sorted(aas)

bbs = input().split()
bbs = [int(b) for b in bbs]
bs2 = sorted(bbs)
mini = bs2[0] + as2[0]
xycs = []
for i in range(M):
  xyc = input().split()
  xycs.append([int(xyc[0]), int(xyc[1]), int(xyc[2])])
  
for xyc in xycs:
  a = aas[xyc[0]-1]
  b = bbs[xyc[1]-1]
  c = xyc[2]
  if a + b - c < mini:
    mini = a+b-c
print(mini)

Measured memory_bytes: 34292
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    int ans = n;
    vector<int> a(n);
    REP(i,n){
        cin>>a[i];
    }
    sort(all(a));
    REP(i,n-1){
        if(a[i]==a[i+1]) {
            ans-=2; a[i+1]=0;
        }
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 640
#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 w[n];
    rep(i,n)cin>>w[i];

    int t;
    int left2,right2;
    int MIN=100000;
    rep(i,n){
        t = i;
        left2=0;
        right2=0;
        rep(j,t+1){
            left2 += w[j];
        }
        for(int j=t+1;j<n;++j){
            right2 += w[j];
        }
        MIN = min(MIN,abs(left2-right2));
    }

    cout<<MIN;
}

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

int main() {
  string S, T;
  cin >>S>>T;
  
  for (int i = 0; i<S.size(); i++) {
    if (S[i] != T[i]) {
      cout<< "No";
      return 0;
    }
  }
  cout<< "Yes";
	return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<int, int> mp;
map<int, int>mm;
#define ll long long
#define ld long double
#define PI 3.14159265358979l

int main() {
    int n;
    int l[100];
    cin >> n;
    int max = 0;
    int sum=0;
    rep(i, n) {
        cin >> l[i];
        if (l[i] > max)max = l[i];
        sum += l[i];
    }
    sum -= max;
    if (max < sum)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//using lint = long long;
typedef pair<int, int> P;

vector<P> prime_factorize(int N){
	vector<P> ans;
	for(int a = 2; a*a <= N; a++){
		if(N%a == 0){
			int ex = 0;
			while(N%a == 0){
				ex++;
				N /= a;
			}
			ans.push_back(P(a, ex));
		}
	}
	if(N != 1) ans.push_back(P(N, 1));
	return ans;
}

signed main(){
	int N; cin >> N;
	vector<P> vec = prime_factorize(N);
	int ans = N;
	for(int i = 0; i < vec.size(); i++){
		ans /= vec[i].first;
		ans *= (vec[i].first - 1);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3104
def i1str():
    return input()


def istrs(n=None):
    if n is None:
        return input().split()
    a = []
    for _ in range(n):
        a.append(istrs())
    return a


def i1num():
    return int(input())


def inums(n=None):
    if n is None:
        return list(map(int, input().split()))
    a = []
    for _ in range(n):
        a.append(inums())
    return a


def ostrs(l, sp=" "):
    print(sp.join(l))


def onums(l, sp=" "):
    print(sp.join(map(str, l)))


def solve(n, a):
    res = n-sum(a)
    if res < 0:
        res = -1
    return res


if __name__ == "__main__":
    n, m = inums()
    a = inums()
    print(solve(n, a))


Measured memory_bytes: 9996
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;




int main() {
    ios_base::sync_with_stdio(false);

    int k;
    cin >> k;
    string s;
    cin >> s;
    if (s.size()<=k) cout << s << endl;
    else {
        rep(i,k) cout << s[i];
        cout << "..." << endl;
    } 

    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n = 5;
  vector<int> a(n);rep(i,n)cin>>a[i];
  rep(i,n)if(a[i] == 0)print(i+1);
  return 0;
}


Measured memory_bytes: 3556
class Node:
    def __init__(self, n, left=None, right=None, parent=None):
        self.n = n
        self.parent = parent
        self.left = left
        self.right = right

    @property
    def depth(self):
        count = 0
        p = self.parent
        while p is not None:
            count += 1
            p = p.parent
        return count

    @property
    def height(self):
        if self.left is None and self.right is None:
            return 0
        elif self.left is None:
            return 1 + self.right.height
        elif self.right is None:
            return 1 + self.left.height
        else:
            left_h = 1 + self.left.height
            right_h = 1 + self.right.height
            return max(left_h, right_h)

    @property
    def sibling(self):
        if self.parent is None:
            return -1
        for node in [self.parent.right, self.parent.left]:
            if node is None:
                return -1
            if node.n != self.n:
                return node.n

    @property
    def degree(self):
        count = 0
        if self.right:
            count += 1
        if self.left:
            count += 1
        return count

    @property
    def type(self):
        if self.parent is None:
            return "root"
        elif self.left is None and self.right is None:
            return "leaf"
        else:
            return "internal node"

    def __str__(self):
        if self.parent is None:
            parent = -1
        else:
            parent = self.parent.n

        return "node {}: parent = {}, sibling = {}, degree = {}, " \
               "depth = {}, height = {}, {}".format(
            self.n, parent, self.sibling, self.degree,
            self.depth, self.height, self.type
        )


n = int(input())
nodes = []
for i in range(n):
    nodes.append(Node(i))

for _ in range(n):
    x, y, z = map(int, input().split())
    node = nodes[x]

    if y == -1:
        node.left = None
    else:
        nodes[y].parent = node
        node.left = nodes[y]

    if z == -1:
        node.right = None
    else:
        nodes[z].parent = node
        node.right = nodes[z]

for n in nodes:
    print(n)



Measured memory_bytes: 5608
/*
Author : Devil088
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define sep cout<<"\n";
#define Yes cout<<"Yes\n";
#define No cout<<"No\n";
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
int main(){
	long N,s =0;
	cin>>N;
	long A[N];
	for(int i=0;i<N;i++){
		cin>>A[i];
		A[i] = A[i]-(i+1);
	}
	
	sort(A,A+N);
	long ele;
	if(N%2 == 0)ele = (A[N/2] + A[(N/2)-1])/2;
	else ele = A[N/2];
	long ans = 0;
	for(int i=0;i<N;i++){
		ans+=abs(A[i]-ele);
	}
	cout<<ans<<"\n";
}
/*
7
1 1 1 1 2 3 4
1  2  3  4  5  6  7
0 -1 -2 -3 -3 -3 -3
-3 -3 -3 -3 -2 -1 0
-3 -2 -1 0 0 0 0
A - ( b + i )
A - i = b ;
*/


Measured memory_bytes: 1792
//                        Bismillahir Rahmanir Rahim
//ALGO:
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define FILL(a, x) memset(a, x, sizeof(a))
#define ll long long
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define INF INT_MAX
#define mx 1000010
#define mod 1000000007
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<pair<int, int>, null_type,less<pair<int, int> >, rb_tree_tag,tree_order_statistics_node_update>
*/
const double Pi=acos(-1);
using namespace std;
int debug=01;
string g[1010];
int n, m;
ll dp[1010][1010];
ll solve(int i, int j){
    if(i==n||j==m) return 0;
    if(g[i][j]=='#') return 0;
    if(~dp[i][j]) return dp[i][j];
    return dp[i][j]= (solve(i+1, j)+solve(i, j+1))%mod;
}
int main() {
    cin>>n>>m;
    for(int i=0; i<n; i++) cin>>g[i];
    FILL(dp, -1);
    dp[n-1][m-1]=1;
    cout<<solve(0, 0);
}


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

int main() {

	int place[31];
	int w, n;
	cin >> w >> n;
	for(int i = 1; i <= w; i++)
		place[i] = i;
	
	int a, b;
	char c;
	for(int i = 1; i <= n; i++){
		cin >> a >> c >> b;
		
		int temp = place[a];
		place[a] = place[b];
		place[b] = temp;
	}
	
	for(int i = 1; i <= w; i++)
		cout << place[i] << endl;
	
	return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}

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

signed main(void)
{
  string s, t;
  cin >> s >> t;
  if(s[0] == t[2] && s[1] == t[1] && s[2] == t[0]) cout << "YES" << endl;
  else  cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
A, B, C, X = [int(input()) for i in range(4)]

counter = 0

for i in range(0, A + 1):
    for j in range(0, B + 1):
        for k in range(0, C + 1):
            if 500 * i + 100 * j + 50 * k == X:
                counter += 1

        # remain_num = X - (i * 500 + j * 100)
        # divisible = (remain_num % 50 == 0)
        #
        # if divisible and (remain_num / 50) > 0:
        #     counter += 1

print(counter)


Measured memory_bytes: 39536
LI = lambda: list(map(int, input().split()))

N = int(input())
L = LI()


def judge(i, j, k):
    if len(set([L[i], L[j], L[k]])) < 3:
        return False
    a = L[i] + L[j] > L[k]
    b = L[j] + L[k] > L[i]
    c = L[k] + L[i] > L[j]
    if a and b and c:
        return True
    else:
        return False


def main():
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            for k in range(j + 1, N):
                if judge(i, j, k):
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()


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

ll powr(ll a,ll b, ll mod)
{
	if(b<=0)
		return 1;
	else if(b%2==0)
		return (powr(a,b/2,mod)*powr(a,b/2,mod))%mod;
	else
		return (a*powr(a,b-1,mod))%mod;
}

void solve()
{
	ll n;
	cin>>n;
	ll mod = 1000000007;
	ll a[n], b[n];
	// vector<double> q,w;
	map<pair<ll,ll>,ll> m1,m2;
	ll k1 = 0; ll k2 = 0;
	ll az = 0;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i]>>b[i];
		if(a[i]!=0&&b[i]!=0)
		{
			ll g = __gcd(abs(a[i]),abs(b[i]));
			if((double)a[i]/b[i]>0)
			{
				// cout<<"lhelj"<<endl;
				// q.push_back((double)a[i]/b[j]);
				m1[{abs(a[i]/g),abs(b[i]/g)}]++;
			}
			else
			{
				// cout<<"lsjdlfjj"<<endl;
				// w.push_back(-1*(double)a[i]/b[i]);
				m2[{(-abs(a[i])/g),(abs(b[i])/g)}]++;
			}
		}
		if(a[i]==0&&b[i]==0)
			az++;
		else if(a[i]==0)
			k1++;
		else if(b[i]==0)
			k2++;
	}
	ll ans = (powr(2,k1,mod) + powr(2,k2,mod)-1+mod)%mod;
	// ans = (ans + powr(2,n-az-k1) - powr(2,n-az-k2-k1));
	for(auto i: m1)
	{
		// cout<<i.first<<" "<<i.second<<endl;
		ll e1 = i.second;
		ll e2 = m2[{-i.first.second,i.first.first}];
		// cout<<e1<<" "<<e2<<endl;
		m2.erase({-i.first.second,i.first.first});

		ans = (ans*(powr(2,e2,mod) + powr(2,e1,mod)-1+mod))%mod;
		// ans = (ans + powr(2,n-az-k1) - powr(2,n-az-k2-k1));
	}
	for(auto i: m2)
	{
		// cout<<i.first<<endl;
		ans = (ans*(powr(2,i.second,mod)))%mod;
	}
	cout<<(ans+az-1+mod)%mod<<endl;
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 19156
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

ll beki(ll a, ll b) {
	ll tmp = 1;
	REP(i, b) tmp *= a;
	return tmp;
}

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int D = A - B;
	cout << max(0, C - D) << endl;
}

Measured memory_bytes: 256
module mod_factorization
  implicit none
  integer(8), parameter :: d = 10**9 + 7
contains
  function h(a,b) result(c)
    implicit none
    integer(8), intent(in) :: a, b
    integer(8)             :: c, i, u, l, n, k
    u = 1
    l = 1
    n = a+b-1
    k = b
    if (n-k .lt. k) k = n-k
    do i = 1, k
       u = u * (n-i+1)
       u = mod(u,d)
       l = l * i
       l = mod(l,d)
    end do
    c = mod(u*pinv(l,d-2),d)
    return
  end function h

  recursive function pinv(m,p) result(k)
    implicit none
    integer(8), intent(in) :: m, p
    integer(8)             :: k, h
    if (p .eq. 0) then
       k = 1
       return
    end if
    if (mod(p,2) .eq. 0) then
       h = mod(pinv(m,p/2),d)
       k = mod(h*h,d)
       return
    else
       k = mod(m*pinv(m,p-1),d)
       return
    end if
  end function pinv
end module mod_factorization

program factorization
  use mod_factorization
  implicit none
  integer(8) :: n, m
  integer(8) :: i, sup, count, ans
  read(*,*) n, m
  sup = m
  ans = 1
  do i = 2, sup
     count = 0
     do while (mod(sup,i) .eq. 0)
        count = count + 1
        sup = sup / i
     end do
     if (count .gt. 0) then
        ans = mod(ans*h(n,count),d)
     end if
     if (sup .eq. 1) exit
  end do
  write(*,'(i0)') ans
  stop    
end program factorization

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  string s, t;
  cin >> s >> t;
  t.pop_back();
  if (s == t) puts("Yes");
  else puts("No");

  return 0;
}

// created by Daniel yuan
/*
     ________
    /        \
   / /      \ \
  / /        \ \
  \            /
   \  ______  /
    \________/
*/


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

int main() {
  long long int H, N = 0;
  cin >> H;
  int n = 0;
  H *= 2;
  while(H /= 2) { 
    N += pow(2,n);
    n++;
  }
  
  cout << N << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
vvi g;
vi a,d;

int main(){
	cin>>n;
	a=d=vi(n);
	g=vvi(n);
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u].push_back(v);
		g[v].push_back(u);
		d[u]++;d[v]++;
	}
	queue<int> q;
	for(int i=0;i<n;i++) if(d[i]==1) q.push(i);
	for(auto &i:a) cin>>i;
	sort(a.begin(),a.end());
	int S=0;
	vi res(n);
	for(int i=0;i<n-1;i++){
		int v=q.front();q.pop();
		res[v]=a[i];
		S+=a[i];
		for(auto u:g[v]) if(d[u]){
			d[u]--;
			if(d[u]==1) q.push(u);
		}
	}
	for(int i=0;i<n;i++) if(!res[i]) res[i]=a[n-1];
	cout<<S<<endl;
	for(int i=0;i<n;i++) cout<<res[i]<<" \n"[i==n-1];
}

Measured memory_bytes: 1024
from math import factorial

N, M, K = map(int, input().split())
mod = 10 ** 9 + 7

def f(N):
    a = 1
    for i in range(1, N+1):
        a *= i
        a %= mod
    return a % mod

def Comb(N, K):
    a = f(N)
    b = f(K)
    c = f(N-K)
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod


c = Comb(N*M-2, K-2)

ans = 0

for d in range(M):
    ans += d * (M - d) * (N ** 2)
    ans %= mod

for d in range(N):
    ans += d * (N - d) * (M ** 2)
    ans %= mod

ans *= c
ans %= mod

print(ans)

Measured memory_bytes: 38768
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
routes = [[] for _ in range(len(h) + 1)]
for _ in range(m):
    a, b = list(map(int, input().split()))
    routes[a].append(b)
    routes[b].append(a)
good = 0
for i in range(1, len(routes)):
    if len(routes[i]) == 0:
        good += 1
        continue
    if h[i - 1] > max([h[j - 1] for j in routes[i]]):
        good += 1
print(good)

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

int main() {
  int i, n, m;
  string o, e, ans;
  cin >> o >> e;
  n = o.size();
  m = e.size();
  if (n == m) {
    for (int i = 0; i < n; ++i) {
      ans += o[i];
      ans += e[i];
    }
  } else {
    for (int i = 0; i < m; ++i) {
      ans += o[i];
      ans += e[i];
    }
    ans += o[n - 1];
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*n
for i in list(range(n))[1:]:
    tmp = max(0, i-k)
    dp[i] = min([dpk+abs(h[i]-hk) for dpk, hk in zip(dp[tmp:i], h[tmp:i])])
print(dp[-1])

Measured memory_bytes: 54240
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
int n;
string s;
long long ans=0,prd[2][250007],cur1=1,cur2=1,cnt[250007];
map < pair<long long,long long> ,long long> val;
const long long mod1=1e9+7,mod2=1e9+9;
const long long base=500007;
const long long inv1=433573933, inv2=446715750;
long long pw(long long a,long long b,long long mod){
	if(b==0) return 1LL;
	if(b==1) return a;
	long long ret=pw(a,b/2,mod);
	if(b%2==0) return ret*ret%mod;
	return ret*ret%mod*a%mod;
}
int main(){
	ios_base::sync_with_stdio(0);
	//cout<<pw(base,mod1-2,mod1)<<endl;
	//cout<<pw(base,mod2-2,mod2)<<endl;
	cin>>n;
	cin>>s;
	for(int i=1;i<=n;i++){
		cnt[i]=cnt[i-1];
		prd[0][i]=prd[0][i-1];
		prd[1][i]=prd[1][i-1];
		if(s[i-1]=='>'){
			cur1=(cur1*base)%mod1;
			cur2=(cur2*base)%mod2;
			cnt[i]++;
		}
		else if(s[i-1]=='<'){
			cur1=(cur1*inv1)%mod1;
			cur2=(cur2*inv2)%mod2;
			cnt[i]--;
		}
		else if(s[i-1]=='+'){
			prd[0][i]=(prd[0][i]+cur1)%mod1;
			prd[1][i]=(prd[1][i]+cur2)%mod2;
		}
		else{
			prd[0][i]=(prd[0][i]-cur1+mod1)%mod1;
			prd[1][i]=(prd[1][i]-cur2+mod2)%mod2;
		}
	}
	for(int i=n;i>=1;i--){
		val[mp(prd[0][i],prd[1][i])]++;
		long long dif=cnt[0]-cnt[i-1];
		long long val1=0,val2=0;
		//cout<<dif<<" ";
		if(dif>=0){
			val1=(prd[0][i-1]+prd[0][n]*pw(inv1,dif,mod1)%mod1)%mod1;
			val2=(prd[1][i-1]+prd[1][n]*pw(inv2,dif,mod2)%mod2)%mod2;
		}
		else{
			val1=(prd[0][i-1]+prd[0][n]*pw(base,-dif,mod1)%mod1)%mod1;
			val2=(prd[1][i-1]+prd[1][n]*pw(base,-dif,mod2)%mod2)%mod2;
		}
		ans+=val[mp(val1,val2)];
		//cout<<ans<<endl;
	}
	cout<<ans;
}


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

using namespace std;

int main(){
    int N;
    int count1;
    int count2 = 0;
    cin >> N;

    int A[N];

                for(int i = 0; i < N; i++) cin >> A[i];

    while(1){
            count1 = 0; 
            for(int i = 0; i < N; i++) if(A[i] % 2 == 0) count1++;

                if(count1 == N){
                        for(int i = 0; i < N; i++) A[i] /= 2;
                        count2++;
                }
                else break;
    }
    cout << count2 << endl;
}

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

const int N = 1e5 + 1;

int n, m;
int dp[N];

vector < int > g[N];

int dfs(int v)
{
	if(g[v].size() == 0)
		return (dp[v] = 0);
	
	if(dp[v] != -1)
		return dp[v];
	
	for(int u : g[v])
		dp[v] = max(dp[v], dfs(u) + 1);
	
	return dp[v];
}

int main()
{
	cin >> n >> m;
	
	while(m--)
	{
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
	}
	
	memset(dp, -1, sizeof(dp));
	
	for(int i = 1; i <= n; i++)
		dp[i] = dfs(i);
	
	int mx = 0;
	for(int i = 1; i <= n; i++)
		mx = max(dp[i], mx);
	
	cout << mx << endl;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define pll pair<ll,ll>
const int mod=(int)1e9+7;

using namespace std;
pll reduce(ll a,ll b){
   if(a==0 and b==0) return make_pair(0,0);
   //if(b==0) return make_pair(1,0);
   ll g=__gcd(a,b);
   a=a/g,b=b/g;
   if(a<0){a*=-1,b*=-1;}
   return make_pair(a,b);
}
pll comp(pll frac){
   pll r = make_pair(frac.second,frac.first);
   if(r.first<0) r.first=-r.first;
   else r.second=-r.second;
   return r;
}

ll fpow(ll a,ll b){
   ll res=1;
   while(b>0){
     if(b&1) res=(res*a)%mod;
     a=(a*a)%mod;
     b/=2;
   }
   return res;
}

int main(){
   int n;
   ll a,b,ans=1,tc=0;
   cin>>n;
   map<pll,ll> cnt;
   for(int i=0;i<n;i++){
      cin>>a>>b;
      cnt[reduce(a,b)]++;
   }
   auto x = cnt.find({0,0});
   if(x!=cnt.end()){
      tc=x->second;
      cnt.erase({0,0});
   }
   //cout<<tc<<"\n";
   for(auto x:cnt){
      pll frac=x.first;
      ll c=x.second;
      auto y=cnt.find(comp(frac));
      if(y==cnt.end())
         ans=(ans*fpow(2,c))%mod;
      else{
         ll temp=(fpow(2,c)+fpow(2,y->second)-1+mod)%mod;
         ans=(ans*temp)%mod;
         cnt.erase(y);
      }	
      //cout<<"("<<frac.first<<","<<frac.second<<","<<ans<<") ";
   }
   //cout<<ans<<"\n";
   ans=(ans+tc+mod-1);
   cout<<ans%mod;
   return 0;

} 


Measured memory_bytes: 16124
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;


int main()
{
     ios::sync_with_stdio(0);
    cin.tie(0);
   int a,b,c,d,i;
   cin>>a>>b>>c>>d>>i;
   int e=(c-a)*60;
   int f=d-b;
   
   int result=(e+f)-i;
   cout<<result;
   
   
    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<bool> sunuke(n, false);
  rep(i, k) {
    int d;
    cin >> d;
    rep(j, d) {
      int a;
      cin >> a;
      sunuke[a - 1] = true;
    }
  }
  
  int answer = 0;
  rep(i, n) if(sunuke[i] == false) ++answer;
  
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 
using namespace std;
int main()
{
    int n,k;
    while (~scanf("%d %d", &n,&k)) {
        if (k==1) puts("0");
        else printf("%d\n", n-k);
    }
    return 0;
}


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

int main()
{
  string S;
  cin >> S;
  string K("keyence");
  for (int i = 1; i < K.size(); ++i)
  {
    if (S.substr(0, i) != K.substr(0, i))
      continue;
    if (S.substr(S.size() - (K.size() - i), K.size() - i) != K.substr(i, K.size() - i))
      continue;
    cout << "YES";
    return 0;
  }
  for (int i = 0; i <= S.size() - K.size(); ++i)
  {
    if (S.substr(i, K.size()) == K)
    {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);


//入力変数
int X=sc.nextInt();
int A=sc.nextInt();
int B=sc.nextInt();

//入力値変換


//出力変数
int ans;

//計算
ans=(X-A)%B;

//出力
System.out.println(ans);

}}

Measured memory_bytes: 21844
N, T = map(int,input().split())

ans = 10**9
TLE = 1
for i in range(N):
    ct = list(map(int,input().split()))
    if ct[1] <= T:
        TLE = 0
        if ct[0] < ans:
            ans = ct[0]

if TLE == 0:
    print(ans)
else:
    print('TLE')

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

int main(){
	int n,a[200000],sum=0,l=0,first=0;
	long long ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(sum&a[i]){
			for(int j=first;j<i;j++){
				sum = sum^a[j];
				first++;l--;
				if(!(sum&a[i])){
					break;
				}
			}
		}
		sum=sum^a[i];
		l++;
		ans+=l;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:256000000")
#include<utility>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

int const mod = 1e9 + 7;
int const maxn = 2e5 + 5;

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

	ll m, k; cin >> m >> k;
	ll mx = (1LL << m) - 1;
	if (m == 1 && k == 0) {
		cout << "0 0 1 1";
	}
	else if (m == 1 && k == 1) {
		cout << -1;
	}
	else if (mx < k) {
		cout << -1;
	}
	else {
		for (ll i = 0; i <= mx; i++) {
			if (i == k) continue;
			cout << i << " ";
		}
		cout << k << " ";
		for (ll i = mx; i >= 0; i--) {
			if (i == k) continue;
			cout << i << " ";
		}
		cout << k;
	}

	return 0;
}
/*

*/

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

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


void dk()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int n;
int a[3000];
int gameeven()
{
    int dp[n][n];
    int i = 0, j = 1;
    while (j < n)
    {
        dp[i][j] = max(a[i], a[j]);
        i++;
        j++;
    }
    for (int p = 3; p < n; p = p + 2)
    {
        int ii = 0, jj = p;
        while (jj < n)
        {
            int k1 = dp[ii + 2][jj];
            int k2 = dp[ii + 1][jj - 1];
            int k3 = dp[ii][jj - 2];
            int a1 = min(k1, k2) + a[ii];
            int a2 = min(k2, k3) + a[jj];
            dp[ii][jj] = max(a1, a2);
            jj++;
            ii++;
        }
    }
    return dp[0][n - 1];
}
int gameodd()
{
    int dp[n][n];
    int i = 0, j = 0;
    while (j < n)
    {
        dp[i][j] = a[i];
        i++;
        j++;
    }
    for (int p = 2; p < n; p = p + 2)
    {
        int ii = 0, jj = p;
        while (jj < n)
        {
            int k1 = dp[ii + 2][jj];
            int k2 = dp[ii + 1][jj - 1];
            int k3 = dp[ii][jj - 2];
            int a1 = min(k1, k2) + a[ii];
            int a2 = min(k2, k3) + a[jj];
            dp[ii][jj] = max(a1, a2);
            jj++;
            ii++;
        }
    }
    return dp[0][n - 1];
}
int32_t main()
{
    //dk();
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int ans;
    if (n % 2 == 0)
        ans = gameeven();
    else
        ans = gameodd();
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum += a[i];
    }
    sum -= ans;
    cout << ans - sum;
    return 0;
}

Measured memory_bytes: 70528
#include<cstdio>
using namespace std;
int sum=0;
int num(int n)
{
    int c=0;
    while(n)
    {
        c+=n%10;
        n/=10;
    }
    return c;
}
int main()
{
    int n,a,b,tmp;
    scanf("%d %d %d",&n,&a,&b);
    for(int i=1;i<=n;i++)
    {
        tmp=num(i);
        if(tmp>=a&&tmp<=b)
            sum+=i;
    }
    printf("%d",sum);
    return 0;
}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 153;

int mo;

template<typename T1,typename T2> inline T1 ad(T1 &a,T2 b){return a=a+b>=mo?a+b-mo:a+b;}
template<typename T1,typename T2> inline T1 dl(T1 &a,T2 b){return a=a>=b?a-b:a-b+mo;}

int n,tran;

namespace whentraniseven
{
	lint f[_][_];
	
	int main()
	{
		memset(f,0,sizeof(f)),f[0][0]=1;
		int lim=tran/2,len=(n+1)/2;
		for(int i=1;i<=len;i++)
		{
			for(int j=0;j<=lim;j++)ad(f[i][0],f[i-1][j]);
			for(int j=1;j<=lim;j++)ad(f[i][j],f[i-1][j-1]);
		}

		lint anse=0,anso=0;
		for(int i=0;i<=lim;i++)ad(anse,f[n/2][i]);
		for(int i=0;i<=lim;i++)ad(anso,f[(n+1)/2][i]);
		printf("%lld\n",anse*anso%mo);

		return 0;
	}
}

namespace whentranisodd
{
	lint f[_][_][_];

	int main()
	{
		memset(f,0,sizeof(f)),f[0][0][0]=1;
		int lim=tran+1;
		
		for(int i=1;i+i-tran<=n;i++)
			for(int j=0;j<=n;j++)
				for(int k=0;k<=lim;k++)
				{
					if(!f[i-1][j][k])continue;
					lint x=f[i-1][j][k];
					ad(f[i][0][0],x);
					if(i+i<=n)ad(f[i][j+1][0],x);
					if(i+i-tran>=1)ad(f[i][0][k==0?0:k+1],x);
					if(i+i<=n && i+i-tran>=1)ad(f[i][j+1][max(j+2,k+1)],x);
				}
		
		lint ans=0;
		for(int i=0;i<=n;i++)
			for(int j=0;j<=lim;j++)
				ad(ans,f[(n+tran)/2][i][j]);
		printf("%lld\n",ans);

		return 0;
	}
}

int main()
{
	n=ty(),tran=ty(),mo=ty();

	if(tran%2==0)return whentraniseven::main();
	return whentranisodd::main();
}


Measured memory_bytes: 28288
#include <set>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits>
#include <map>
#include <numeric>
#include <list>
using ll = long long;
using namespace std;
static ll imin = std::numeric_limits<ll>::min() / 2;
static ll imax = std::numeric_limits<ll>::max() / 2;
#define rep(i, n) for(ll i = 0; (i)<(n); ++(i))
#define rep1(i, n) for(ll i = 1; (i)<(n); ++(i))
#define rev_rep(i, n) for(ll i = (n) - 1; (i) >= 0; --(i))
#define range(a, i, b) for(ll i = (a); (i) < (b); ++(i))
#define dump(x) cout << #x << ":" << x << "\n";
#define all(v) v.begin(), v.end()
#define readl(N) ll N; cin >> N
#define readlv(N, vec) vector<ll> vec(N); rep(i, N){cin >> vec[i];}
#define greater_than [](ll l, ll r){return l > r;}
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::map<T1, T2>& mp);
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::pair<T1, T2>& pair);
template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec);
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::pair<T1, T2>& pair){
  os << '(' << pair.first << ',' << pair.second << ')';
  return os;
}

template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec){
  std::size_t n = vec.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(ll i = 0; i<n - 1; ++i){
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}

template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::map<T1, T2>& mp){
  std::size_t n = mp.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(auto && x:mp){
    os << x << " ";
  }
  os << std::endl;
  return os;
}

template<class T>
std::ostream& operator << (std::ostream& os, std::set<T>& mp){
  std::size_t n = mp.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(auto && x:mp){
    os << x << " ";
  }
  os << std::endl;
  return os;
}

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

ll fact(ll n){
  ll res=1;
  while(n>0){
    res*=n;
    n--;
  }
  return res;
}
    
ll pow(ll i, ll n){
  ll res=1;
  while(n>=0){
    res*=i;
    n--;
  }
  return res;
}

ll gcd(ll l, ll r){
  if(l<r){
    return gcd(r, l);
  }
  if(r == 0){
    return l;
  }
  return gcd(r, l % r);
}

template<class T>
vector<T> accum_sum(vector<T> a){
  vector<T> b(a.size() + 1);
  b[0] = a[0];
  rep(i, a.size()){
    b[i + 1] = b[i] + a[i];
  }
  return b;
}
constexpr ll mod = 1e9+7;

ll modfact(ll n){
  ll res=1;
  while(n>0){
    res %=mod;
    res*=n;
    n--;
  }
  return res%mod;
}
    
int main(int argc, char const* argv[])
{
  readl(n); readl(m);
  if (n-1==m || n+1==m) {
    cout<< modfact(n)*modfact(m) % mod << endl;
  }else if(n==m){
    cout<< (modfact(n)*modfact(m) % mod)  * 2 % mod<<endl;
  }else{
    cout<< 0 <<endl;
  }

  return 0;
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

inline double dist(int x, int y)
{
    return sqrt(x*x+y*y);
}

int main()
{
    int D,E;
    while(cin >>D >>E,D)
    {
        double ans=1e10;
        rep(x,D+1) ans=min(ans,fabs(dist(x,D-x)-E));
        printf("%.10f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3128
s=input()
t=input()
lens=len(s)
lent=len(t)
maxg=0
for i in range(lens-lent+1):
  x=s[i:i+lent]
  g=0
  for j in range(lent):
    if x[j]==t[j]:
      g+=1
  if g>maxg:
    maxg=g
print(lent-maxg)

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
typedef pair< int, int > pii;
template< typename T > using Vec = vector< T >;

int N, M, dp[301][301][301];
Vec< pii > seg[301];

const int MOD = (int)1e9 + 7;
void updateDP(int &a, int b) {
	if (a == -1 || b == -1) return;
	a = (a + b) % MOD;
}

bool validate(int r, int g, int b) {
	for (pii p : seg[r]) {
		int cnt = 1 + (p.first <= g) + (p.first <= b);
		if (p.second != cnt) return false;
	}
	return true;
}

int main() {
	cin >> N >> M;
	for_(i,0,M) {
		int l, r, x;
		cin >> l >> r >> x;
		seg[r].push_back(pii(l, x));
	}
	
	for_(r,0,N+1) for_(g,0,N+1) for_(b,0,N+1) {
		int k = max(r, max(g, b));
		bool valid = false;
		if (k == r) valid = validate(r, g, b);
		if (k == g) valid = validate(g, b, r);
		if (k == b) valid = validate(b, r, g);
		dp[r][g][b] = (valid ? 0 : -1);
	}
	
	dp[0][0][0] = 1;
	for_(r,0,N) for_(g,0,N) for_(b,0,N) {
		int k = max(r, max(g, b)), num = dp[r][g][b];
		updateDP(dp[k+1][g][b], num);
		updateDP(dp[r][k+1][b], num);
		updateDP(dp[r][g][k+1], num);
	}
	
	int ans = 0;
	for_(i,0,N) for_(j,0,N) {
		updateDP(ans, dp[N][i][j]);
		updateDP(ans, dp[i][N][j]);
		updateDP(ans, dp[i][j][N]);
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 106752
#include <stdio.h>

int main(void) {

	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	if (a >= c) {
		printf("0\n");
	}
	else if ((a + b) < c) {

		printf("NA\n");
	}
	else {
		printf("%d\n", c - a);

	}
	return 0;
}


Measured memory_bytes: 2680
#include"bits/stdc++.h"
using namespace std;

#define NIL -1

typedef struct Node {
	int p = NIL;
	int l = NIL;
	int r = NIL;
}tree;

void preorder(vector<tree>& t, int r, int d)
{
	if (r == NIL) return;

	cout << " " << r;
	preorder(t, t[r].l, d + 1);
	preorder(t, t[r].r, d + 1);
	
	if (!d) cout << endl;

	return;
}

void inorder(vector<tree>& t, int r, int d)
{
	if (r == NIL) return;

	inorder(t, t[r].l, d + 1);
	cout << " " << r;
	inorder(t, t[r].r, d + 1);

	if (!d) cout << endl;

	return;
}

void postorder(vector<tree>& t, int r, int d)
{
	if (r == NIL) return;

	postorder(t, t[r].l, d + 1);
	postorder(t, t[r].r, d + 1);

	cout << " " << r;
	if (!d) cout << endl;

	return;
}

int main(void)
{
	int N, i, r = 0;
	cin >> N;
	vector<tree> t(N);

	for (i = 0; i < N; i++)
	{
		int id = 0;
		cin >> id;
		cin >> t[id].l >> t[id].r;

		if (t[id].l != NIL) t[t[id].l].p = id;
		if (t[id].r != NIL) t[t[id].r].p = id;
	}

	for (i = 0; i < N; i++) if (t[i].p == NIL) r = i;

	cout << "Preorder" << endl;
	preorder(t, r, 0);

	cout << "Inorder" << endl;
	inorder(t, r, 0);

	cout << "Postorder" << endl;
	postorder(t, r, 0);

	return 0;
}


Measured memory_bytes: 3088
<?php
    # 整数の入力
    fscanf(STDIN, "%d", $N);
	$input = explode(" ", trim(fgets(STDIN)));
	$max = 0;
	$total = 0;
	for ($i=0; $i < $N; $i++) { 
		if ($input[$i]>$max) {
			$max = $input[$i];
		}
		$total += $input[$i];
	}
	
	echo ($total > $max * 2)?"Yes":"No";

    ?>

Measured memory_bytes: 4856
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int h = Integer.parseInt(sc.next());
    int w = Integer.parseInt(sc.next());
    int n = Integer.parseInt(sc.next());
    
    int p = 0;
    int pd = 0;
    
    if(h>w){
      p = h;
      for(int i=1; i<=w; i++){
        pd += p;
          if(pd >= n){
            System.out.println(i);
            return;
          }
      }
    } else {
      p = w;
      for(int i=1; i<=h; i++){
        pd += p;
          if(pd >= n){
            System.out.println(i);
            return;
          }
      }
    }
    
  }
}


Measured memory_bytes: 21716
//package hiougyf;
import java.io.*;
import java.util.*;

public class Main {
	  public static void main(String[] args) throws IOException
	    {
		 Scanner sc =new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n];
		int mod = 1000000007;
		long cs=0;
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
			cs+=a[i];
			cs%=mod;
			//cs=(cs+(a[i])%mod)%mod;
			
		}
		long ans=0;
		for(int i=0;i<(n-1);i++) {
			cs-=a[i];
		//	ans=(ans+((((a[i])%mod)*cs)%mod))%mod;
			if(cs < 0){
				cs += mod;
			}
			ans+=(cs*a[i])%mod;
			ans%=mod;
			
			
		}
		System.out.println((long)ans%(mod));
	
	    }
		static int div(int n,int b) {
			int g=-1;
			for(int i=2;i<=Math.sqrt(n);i++) {
				if(n%i==0&&i!=b) {
					g=i;
					break;
				}
			}
			return g;
		}
	 
	  
	  public static int gcd(int a, int b) 
	    { 
	        if (a == 0) 
	            return b; 
	          
	        return gcd(b%a, a); 
	    } 
	   public static int lcm(int a, int b)  
	  {  
	     return (a*b)/gcd(a, b);  
	  }  
	   public static boolean isPrime1(int n) {
           if (n <= 1) {
               return false;
           }
           if (n == 2) {
               return true;
           }
           for (int i = 2; i <= Math.sqrt(n) + 1; i++) {
               if (n % i == 0) {
                   return false;
               }
           }
           return true;
       }
       public static boolean isPrime(int n) {
           if (n <= 1) {
               return false;
           }
           if (n == 2) {
               return true;
           }
           if (n % 2 == 0) {
               return false;
           }
           for (int i = 3; i <= Math.sqrt(n) + 1; i = i + 2) {
               if (n % i == 0) {
                   return false;
               }
           }
           return true;
       }
	      
	
}

  


Measured memory_bytes: 61024
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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


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

    vector<int> d;

    if(a < b){
        for(int i = 1; i <= a; i++){
            if(a % i == 0 && b % i == 0){
                d.push_back(i);
            }
        }
    } else {
        for(int i = 1; i <= b; i++){
            if(b % i == 0 && a % i == 0){
                d.push_back(i);
            }
        }
    }

    sort(d.begin(), d.end(), greater<int>());

    for(int i = 0; i < d.size(); i++){
        if(i == k - 1){
            cout << d[i] << endl;
            break;
        }
    }
}



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

using namespace std;

int main(){
	int n; cin >> n;
	vector<string> v;
	bool flag = true;
	for (int i = 0; i < n; i++){
		string s;cin >> s;
		v.push_back(s);
		if(i > 0){
			if(v[i-1][v[i-1].size()-1] != v[i][0])flag = false;
			for(int j = 0; j < v.size(); j++){
				if(i != j && v[i] == v[j])flag = false;
			}
		}
	}
	cout << (flag ? "Yes" : "No" ) << endl;
}

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

long long N, a[3000];

int main() {
    cin >> N;
    rep(i, N) cin >> a[i];

    long long ans = 0;
    rep(i, N) ans += a[i] - 1;

    cout << ans << endl;
}

Measured memory_bytes: 256
//金桥 傅思程
#include <bits/stdc++.h>
using namespace std;

int main()
{
	int a,b,c,d,e,f=0;
	cin>>a>>b>>c>>d>>e;
	int aa=(a+9)/10*10-a;
	int bb=(b+9)/10*10-b;
	int cc=(c+9)/10*10-c;
	int dd=(d+9)/10*10-d;
	int ee=(e+9)/10*10-e;
	int ad=e;
	if(aa>ee){
		int t=aa;
		aa=ee;
		ee=t;
		ad=a;
	}
	if(bb>ee){
		int t=bb;
		bb=ee;
		ee=t;
		ad=b;
	}
	if(cc>ee){
		int t=cc;
		cc=ee;
		ee=t;
		ad=c;
	}
	if(dd>ee){
		int t=dd;
		dd=ee;
		ee=t;
		ad=d;
	}
	if(a==ad)a=e;
	f+=a;
	if(f%10!=0)f=(f+9)/10*10;
	if(b==ad)b=e;
	f+=b;
	if(f%10!=0)f=(f+9)/10*10;
	if(c==ad)c=e;
	f+=c;
	if(f%10!=0)f=(f+9)/10*10;
	if(d==ad)d=e;
	f+=d;
	if(f%10!=0)f=(f+9)/10*10;
	f+=ad;
	cout<<f<<endl;
	return 0;
}



Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
A = LIST()
sum_A = sum(A)
if sum([x >= sum_A/(4*M) for x in A]) >= M:
  		print("Yes")
else:
  		print("No")

Measured memory_bytes: 5148
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<sstream>
#define ll long long
#define mes(x,y) memset(x,y,sizeof(x))
using namespace std;
int main(){
	ll n,k;string s;
	while(cin>>n>>k>>s){
		s[k-1]+=32;
		cout<<s<<endl;
	} 
} 


Measured memory_bytes: 256