akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if ((a + b) > (c + d)) {
    cout << "Left" << endl;
  } else if ((a + b) < (c + d)) {
    cout << "Right" << endl;
  } else {
    cout << "Balanced" << endl;
  }
}

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

int main(void) {
    string S,T;
    cin>>S>>T;
    int A,B;
    cin>>A>>B;
    string U;
    cin>>U;
    if (U == S) cout << A - 1 << " " << B << endl;
    else cout << A << " " << B - 1 << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  for(int i=0;i<9;i++){
    int A=100*(i+1)+10*(i+1)+i+1;
    if(N<=A){
      cout << A << endl;
      break;
    }
  }
}
  

Measured memory_bytes: 3580
S = tuple(input()) # これで文字列を一文字にできる
T = input()

for i in range(0, len(S)):
    word = ''
    for j in range(0, len(S)):
        index = (i + j) % len(S)
        word += S[index]
    if word == T:
        print('Yes')
        break
    elif i == j:
        print('No')
        break


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    repr(i,1,10) {
        repr(j,1,10) {
            if(i*j==n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define INFL 2000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;

int main() {
	int N;
	cin >> N;
	vi a(3 * N);
	rep(i, 3 * N) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	ll ans = 0;
	rep(i, N) {
		ans += a[i * 2 + 1];
	}

	cout << ans << endl;

	return 0;
}

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

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N;
  cin >> N;

  int cont = 0;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    if (tmp % 2 == 1) {
      cont++;
    }
  }

  if (cont % 2) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }

  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
void dfs(int frm,int now,int sss,vector<int> &ans,vector<vector<int>> &tree, vector<int> &s){
  		sss+=s[now];
    ans[now]=sss;
    for (int x:tree[now]){
        if (x!=frm){
            dfs(now,x,sss,ans,tree,s);
        }
    }
}
int main() {
    int n,q;
    cin>>n>>q;
    vector<vector<int>> tree;
    rep(i,n+1){
        tree.push_back({});
    }
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<int> ans,s;
    rep(i,n+1){
        ans.push_back(0);
        s.push_back(0);
    }
    rep(i,q){
        int p,x;
        cin>>p>>x;
        s[p]+=x;
    }
    
    dfs(0,1,0,ans,tree,s);
    rep(i,n-1){
        cout<<ans[i+1]<<" ";
    }
    cout<<ans[n]<<endl;


    return 0;
}

Measured memory_bytes: 32620
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

int main() {
  std::unordered_map<std::string, int> map;
  
  int N;
  std::cin >> N;
  std::string temp;
  int max = 0;
  while (std::cin >> temp) {
    ++map[temp];
    max = std::max(max, map[temp]);
  }
  std::vector<std::string> result;
  for (auto &&e : map) {
    if (e.second == max)
      result.emplace_back(e.first);
  }
  std::sort(result.begin(), result.end());
  
  for (auto &&e : result) {
    std::cout << e << "\n";
  }
}

Measured memory_bytes: 26692
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int bm = 400400;
const int mod = 998244353;
ll BIT[bm];
void add(int A, ll B) {
	while (A <= bm) {
		BIT[A] += B;
		BIT[A] %= mod;
		A += A & -A;
	}
}
ll query(int A) {
	ll ret = 0;
	while (A > 0) {
		ret += BIT[A];
		A -= A & -A;
	}
	return ret % mod;
}

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


	int N, K;
	cin >> N >> K;
	int L[10], R[10];
	rep(i, K) cin >> L[i] >> R[i];

	add(1, 1);
	add(2, -1);
	rep1(i, N) {
		ll kari = query(i);

		rep(j, K) {
			add(i + L[j], kari);
			add(i + R[j] + 1, -kari);
		}
	}

	co((query(N) + mod) % mod);

	Would you please return 0;
}

Measured memory_bytes: 6740
x, n = map(int, input().split())
a = [int(x) for x in input().split()]
b = [i for i in range(0,102) if i not in a] 
b_tmp = list(map(lambda s:abs(s-x), b)) 
address = b_tmp.index(min(b_tmp))
print(b[address])

Measured memory_bytes: 9188
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading;

class Program
{

    static void Main(string[] args)
    {
        int[] arr = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        int turn = 0;
        while(arr[0] > 0)
        {
            arr[0] -= arr[1];
            turn++;
        }
        Console.WriteLine(turn) ;
    }




}

Measured memory_bytes: 28272
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	long long N, M;

	vector<pair<long long, long long>> v;

	cin >> N >> M;

	for(long long i = 0; i < N; i++){
		long long a, b;
		cin >> a >> b;
		v.push_back(make_pair(a, b));
	}

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

	long long ans = 0, m = M;
	for(long long i = 0 ; i < N; i++){
		long long b = min(m, v[i].second);
		ans += b * v[i].first;
		m -= b;
		if(m == 0) break;
	}

	cout << ans << endl;

	return 0;
}


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

int main(){
    int n, m, i, j;
    string s;
    map<string, int> mp;
    bool flag = 1;
    vector<string> str;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> s;
        mp[s]++;
        str.push_back(s);
    }
    cin >> m;
    for(i = 0; i < m; i++){
        cin >> s;
        mp[s]--;
        str.push_back(s);
    }
    str.erase(unique(str.begin(), str.end()), str.end());
    int ans = 0;
    for(i = 0; i < str.size(); i++){
        ans = max(ans, mp[str.at(i)]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
MOD = 998244353

n,k = map(int,input().split())
lr = [list(map(int,input().split())) for _ in range(k)]
dp = [0]*n
dp[0] = 1

newdp = 0

for i in range(1,n):
    for l,r in lr:
        if i-l>=0:
            newdp += dp[i-l]
            newdp %= MOD
        if i-r-1>=0:
            newdp -= dp[i-r-1]
            newdp %= MOD
        
        dp[i] = newdp

print(dp[-1])

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

void printArray(int* a, int n){
  for(int i = 0; i < n - 1; i++){
    cout << a[i] << " ";
  }
  cout << a[n-1] << endl;
  
  return;
}

void insertionSort(int* a, int n){
  for(int i = 1; i < n; i++){
    int v = a[i];
    int j = i - 1;

    while(j >= 0 && a[j] > v){
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;
    
    printArray(a, n);
  }  
  
  return;
}

int main() {
  int len;
  cin >> len;

  int a[len];
  for(int i = 0; i < len; i++) cin >> a[i];

  printArray(a, len);
  
  insertionSort(a, len);

  return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,s=0;
    cin>>n;
    int a[n],b[n],c[n];
    for(i=0;i<n;i++)
    cin>>a[i]>>b[i]>>c[i];
    for(i=1;i<n;i++)
    {
        a[i]=a[i]+max(b[i-1],c[i-1]);
        b[i]=b[i]+max(a[i-1],c[i-1]);
        c[i]=c[i]+max(a[i-1],b[i-1]);
    }
    s=max(a[n-1],s);
    b[n-1]=max(b[n-1],c[n-1]);
    s=max(s,b[n-1]);
    cout<<s<<"\n";
}


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

#define watch(x) cout << (#x) << " = " << x << endl;
#define mkp make_pair
#define mkt make_tuple
#define pb push_back
#define ll long long
#define ld long double

using namespace std;

int n, k, a[110];
ll dp[110][100010], dppref[110][100010];
const int MOD = 1e9 + 7;

int main(){
	scanf("%d%d", &n, &k);

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

	dp[0][0] = 1;
	dppref[0][0] = 1;
	for(int i = 1; i <= k; i++) dppref[0][i] += dppref[0][i - 1];

	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= k; j++){
			dp[i][j] = dppref[i - 1][j];
			if(j - a[i] - 1 >= 0) dp[i][j] -= dppref[i - 1][j - a[i] - 1];

			dp[i][j] %= MOD;
			if(dp[i][j] < 0) dp[i][j] += MOD;
			dppref[i][j] = dp[i][j];
			if(j > 0) dppref[i][j] += dppref[i][j - 1];
			dppref[i][j] %= MOD;
		}
	}

	printf("%lld\n", dp[n][k]);

	return 0;
}

Measured memory_bytes: 162048
#include<bits/stdc++.h>
using namespace std;
int n,d;
int X[15][15];
int main(){
	scanf("%d%d",&n,&d);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=d;j++){
			scanf("%d",&X[i][j]);
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			int res=0;
			for(int k=1;k<=d;k++)
				res+=(X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
			int cur=0;
			while(cur*cur<res)cur++;
			if(cur*cur==res)ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;

LL ll[400005],rr[400005];
LL stk[400005],tp = 0;
LL n,a[400005],tot = 0;

int main(){
	cin >> n;
	for(LL i = 1;i <= n;i ++) cin >> a[i];
	for(LL i = 1;i <= n;i ++){
		ll[i] = 0;
		rr[i] = n + 1;
	}
	
	tp = 0;
	for(LL i = 1;i <= n;i ++){
		while(tp && a[stk[tp]] > a[i]){
			rr[stk[tp]] = i;
			tp --;
		}
		stk[++ tp] = i;
	}
	
	tp = 0;
	for(LL i = n;i >= 1;i --){
		while(tp && a[stk[tp]] > a[i]){
			ll[stk[tp]] = i;
			tp --;
		}
		stk[++ tp] = i;
	}
	
	for(LL i = 1;i <= n;i ++) tot += (rr[i] - i) * (i - ll[i]) * a[i];
	cout << tot << endl;
	return 0;
}

Measured memory_bytes: 12032
if __name__ == '__main__':
    
    N, A, B = [int(x) for x in input().split(' ')]
    
    while True:
        
        if (A+1) == B:
            if A == 1:
                print('Borys')
                break
            else:
                A -= 1
        else:
            A += 1

        if (B-1) == A:
            if B == N:
                print('Alice')
                break
            else:
                B += 1
        else:
            B -= 1


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  int n,a,b;
  cin >> n >> a >> b;
  cout << min(n*a,b) << endl;
    
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int n;
	int a[100];
	int i, j,count,x, min;
	scanf("%d", &n);
	for(i = 0;i<n;i++){
		scanf("%d", &a[i]);
	}
	count =0;
	for(i = 0;i<n;i++){
		min =i;
		for(j =i;j<n;j++){
			if(a[min] > a[j]){
				min =j;
			}
		}
		if(min != i){
		x = a[i];
		a[i] = a[min];
		a[min] = x;
		count++;
		}
	}
	
	for(i = 0;i<n-1;i++){
		
		printf("%d ", a[i]);
	}
	printf("%d\n", a[n-1]);
	printf("%d\n", count);
	
	return 0;
	
	
	}


Measured memory_bytes: 2096
#include <cstdio>
#include <algorithm>
#include <queue>
#include <utility>

int h, w;
char s[20][21];
int cnt[20][20];

int bfs(int y, int x)
{
	cnt[y][x] = 0;
	const int dir[] = {0, -1, 0, 1, 0};
	using p = std::pair<int ,int>;
	std::queue<p> q;
	q.push({y, x});
	while (q.size() > 0)
	{
		p a = q.front();
		q.pop();
		for (int i = 0; i < 4; ++i)
		{
			int Y = a.first + dir[i];
			int X = a.second + dir[i + 1];
			if (0 <= X && X < w && 0 <= Y && Y < h && s[Y][X] == '.' && cnt[Y][X] == -1)
			{
				q.push({Y, X});
				cnt[Y][X] = cnt[a.first][a.second] + 1;
			}
		}
	}
}

int main()
{
	scanf("%d%d", &h, &w);
	for (int i = 0; i < h; ++i)
	{
		scanf("%s", s[i]);
	}
	int ans = 0;
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			if (s[i][j] == '#') continue;
			for (int k = 0; k < h; ++k)
			{
				std::fill(cnt[k], cnt[k] + w, -1);
			}
			bfs(i, j);
			int max = 0;
			for (int a = 0; a < h; ++a)
			{
				for (int b = 0; b < w; ++b)
				{
					if (max < cnt[a][b]) max = cnt[a][b];
				}
			}
			if (ans < max) ans = max;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
n = int(input())
k = int(input())

r = 0
tp = n
while tp != 0:
    r += 1
    tp = tp//10

p = n//pow(10,r-1)

res = 0

if k == 1:
    res = (r-1)*9 + p
    print(res)

elif k == 2:
    if r <= 1:
        print(0)
        exit()
    if r >= 3:
        res = (r-1)*(r-2)*81//2
    
    res += (p-1)*9*(r-1)

    tmp = p*pow(10,r-1)
    for i in range(r-1):
        for j in range(1,10):
            if tmp + j*pow(10,i) <= n:
                res += 1
    
    print(res)
else:
    if r <= 2:
        print(0)
        exit()
    
    if r >= 4:
        res = pow(9,3)*(r-1)*(r-2)*(r-3)//6
    
    res += (p-1)*81*(r-1)*(r-2)//2

    tmp = p*pow(10,r-1)

    for i in range(r-1):
        for j in range(i+1,r-1):
            for w in range(1,10):
                for q in range(1,10):
                    if tmp + w*pow(10,i) + q*pow(10,j) <= n:
                        res += 1
    
    print(res)





Measured memory_bytes: 42972
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.Exception
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    println(n * (n + 1) / 2)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

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

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

        return st.nextToken()
    }

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


Measured memory_bytes: 34304
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime>
#include <bitset>

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};

int main() {
  string s; cin>>s;
  string t; cin>>t;
  int n=s.size();
  int m=t.size();
  int an=2000;
  for(int i=0;i<=n-m;i++) {
    int sm=0;
    for(int j=0;j<m;j++) {
      sm+=s[i+j]!=t[j];
    }
    chmin(an,sm);
  }
  cout<<an<<endl;
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;

  int co=0;
  for(int a=0; a<=A; a++){
    for(int b=0; b<=B; b++){
      for(int c=0; c<=C; c++){
        int total = 500*a + 100*b + 50*c;
        if(total == X) co++;
      }
    }
  }

  cout << co << endl;

  return 0;
}

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

int main() {
	int n; scanf("%d", &n);
	vector<string>v;
	rep(i, n) {
		string s; cin >> s;
		v.push_back(s);
	}
	int m; scanf("%d", &m);
	bool b = false;
	rep(i, m) {
		string s; cin >> s;
		if (find(v.begin(), v.end(), s) == v.end())
			cout << "Unknown " << s << endl;
		else {
			if (b)cout << "Closed by " << s << endl;
			else cout << "Opened by " << s << endl;
			b = !b;
		}
	}
}

Measured memory_bytes: 3308
n, p = map(int, input().split())

if n == 1:
    print(p)
    exit()

b = [False] * 1000001
prime = []
b[1] = True

for i in range(2, 1000001):
    if b[i]:
        continue
    k = i + i
    while k < 1000001:
        b[k] = True
        k += i

    prime.append(i)

prime_num = [0] * len(prime)

for i in range(len(prime)):
    while p % prime[i] == 0:
        prime_num[i] += 1
        p //= prime[i]

if sum(prime_num) == 0:
    print(1)
    exit()

idx = []
for i in range(len(prime) - 1, -1, -1):
    if prime_num[i] >= n:
        idx.append(i)

if len(idx) == 0:
    print(1)
    exit()

ans = 1
for x in idx:
    a = prime_num[x] // n
    ans *= prime[x] ** a

print(ans)


Measured memory_bytes: 54108
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <P,P> PP;
typedef pair <int,PP> PPP;

static const double eps = 1e-8;

int main(){
	int n,m;
	while(~scanf("%d %d",&n,&m)){
		if(n==m && m==0) break;
		int* bag = new int[n];
		for(int i=0;i<n;i++){
			scanf("%d",bag+i);
		}

		sort(bag,bag+n,greater<int>());

		int sum = 0;
		for(int i=1;i<=n;i++){
			if(i%m==0) continue;
			sum += bag[i-1];
		}
		printf("%d\n",sum);
		delete[] bag;
	}
}

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

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

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

ll n,cnt,ans,asum,bsum,sum,till;
P p[100010];
vector<P>v;
bool fl,used[100010];

void input(){
	cin>>n;
	till=n;
	for(int i=0;i<n;i++){
		cin>>p[i].fr>>p[i].sc;
		asum+=p[i].fr;
		bsum+=p[i].sc;
		v.eb(P(p[i].fr,i));
		v.eb(P(p[i].sc,i));
	}
	return;
}

void solve(){
	sort(ALL(v));
	ans=min(asum,bsum);
	for(int i=0;i<n;i++){
		if(used[v[i].sc]){
			fl=true;
			sum+=v[i].fr;
		}
		else{
			used[v[i].sc]=true;
			sum+=v[i].fr;
		}
	}
	if(fl)ans=min(ans,sum);
	else{
		for(int i=n;i<v.size();i++){
			ll nsum=sum;
			nsum+=v[i].fr;
			for(int j=n-1;j>=0;j--){
				if(v[j].sc!=v[i].sc){
					nsum-=v[j].fr;
					break;
				}
			}
			ans=min(ans,nsum);
		}
	}
	cout<<ans<<endl;
	return;
}

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


Measured memory_bytes: 7536
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		int ans = 0;
		for(int i = 0; i < 3; i++) {
			if(S.substring(i, i + 1).equals(T.substring(i, i + 1))) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

string str[4] = {"dream", "dreamer", "erase", "eraser"};
string s;
int sz;

int dp[100009];

int dfs(int k) {
    if (k == sz) return 1;
    if (dp[k] != -1) return dp[k];
    // cout << k << endl;
    bool ret = false;
    REP(i, 4) {
        bool b = true;
        int l = 0;
        for (; l < SZ(str[i]); l++) {
            if (k + l >= sz) {
                b = false;
                break;
            }
            if (s[k + l] != str[i][l]) {
                // cout << "asdfdas\n";
                b = false;
                break;
            }
        }
        // cout << str[i] << " " << b << endl;
        if (b && l == SZ(str[i])) {
            ret = dfs(k + l);
            if (ret) return dp[k] = true;
        }
    }
    return dp[k] = false;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> s;
    sz = SZ(s);
    memset(dp, -1, sizeof(dp));
    bool ans = dfs(0);
    cout << (ans ? "YES\n" : "NO\n");
}

Measured memory_bytes: 2000
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1e9+7 ;
//long double pie = acos(-1) ;
//ll INF = 1e15 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	cout << (n+110)/111*111 << endl ;
}


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

int main(){
  int n;
  cin>>n;
  int cnt=0;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    cnt+=a%2;
  }
  cout<<(cnt%2?"NO":"YES")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n; cin>>n;
  VI a(n-1); rep(i,n-1) cin>>a[i];
  VI ans(n,0);
  rep(i,n-1) ans[a[i]-1]++;
  rep(i,n) cout<<ans[i]<<endl;

	return 0;
}


Measured memory_bytes: 4840
#include<bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define rep(i,a,b) for (int i=(a); i<(b); i++)
#define per(i,a,b) for (int i=(b-1); i>=(a); i--)
#define debug(x) cout << #x << " => " << x << endl
using namespace std;

#define fi first
#define se second
#define mp make_pair
typedef pair<int,int> pii;

#define pb push_back
typedef vector<int> vi;

typedef long long ll;
typedef long double ld;

const int MAX_N = 7 + 200000;
///----------------------------------------------
struct UF {
	static const int UF_N = MAX_N;
	int far[UF_N];
	void init() { rep(i,0,UF_N) far[i]=i; }
	int getf(int d) { return far[d]==d ? d : far[d]=getf(far[d]); }
	bool same(int a,int b) { return getf(a)==getf(b); }
	void comb(int a,int b) {
		if (same(a=getf(a),b=getf(b))) return;
		far[a]=b;
	}
}	uf1,uf2;
int main() {
	
	///read
	int n,m1,m2; cin>>n>>m1>>m2;
	
	///prework
	uf1.init();
	rep(i,0,m1) {
		int a,b; scanf("%d%d",&a,&b);
		uf1.comb(a,b);
	}
	uf2.init();
	rep(i,0,m2) {
		int a,b; scanf("%d%d",&a,&b);
		uf2.comb(a,b);
	}
	map<pii,int> M;
	rep(i,1,n+1) M[mp(uf1.getf(i),uf2.getf(i))]++;
	
	///work
	rep(i,1,n+1) {
		printf("%d ",M[mp(uf1.getf(i),uf2.getf(i))]);
	}


}


Measured memory_bytes: 13696
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  double a,b;cin >> a >> b;
  if(a>b){
    cout << "GREATER" << endl;
    return 0;
  }
  if(a<b){
    cout << "LESS" << endl;
    return 0;
  }
  else cout << "EQUAL" << endl;
  return 0;
}


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

using namespace std;
typedef long long int lli;

const int MAXN = 100010;
const int MOD = 1000000007;

int n, m;

lli x[MAXN];
lli y[MAXN];

int main()
{
	scanf("%d %d",&n,&m);

	for(int i = 1 ; i <= n ; i++)
		scanf("%lld",&x[i]);

	for(int i = 1 ; i <= m ; i++)
		scanf("%lld",&y[i]);

	lli ans = 0;
	lli sumY = 0;

	for(int i = 1 ; i <= m ; i++)
	{
		lli val = y[i]*(i - 1);
		val -= y[i]*(m - i);

		sumY += val;
		sumY %= MOD;
	}

	for(int i = 1 ; i <= n ; i++)
	{
		lli val = x[i]*sumY;
		val %= MOD;
		val *= (i - 1);

		ans += val;
		ans %= MOD;

		val = x[i]*sumY;
		val %= MOD;
		val *= (n - i);

		ans -= val;
		ans %= MOD;
	}

	ans %= MOD;
	ans += MOD;
	ans %= MOD;

	printf("%lld\n",ans);
}

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

typedef char *str;

int cmp_char(const void *x, const void *y) {
  return *(char *)x-*(char *)y;
}

int cmp_str(const void *x, const void *y) {
  return strcmp((str)x, (str)y);
}

int main() {
  int n; long long int ans = 0;
  scanf("%d\n", &n);
  char s[n][20];
  for (size_t i = 0; i < n; i++) {
    gets(s[i]);
    qsort(s[i], 10, sizeof(char), cmp_char);
  }
  qsort(s, n, sizeof(char)*20, cmp_str);
  int cnt = 0;
  for (int i = 1; i < n; i++) {
    if (strcmp(s[i], s[i-1]) == 0) {
      cnt++;
      ans += cnt;
    }else {
      cnt = 0;
    }
  }
  printf("%lld\n", ans);
  return 0;
}


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

int N;

int main() {
  cin >> N;
  int answer = 1;
  for (int i = 1; i <= 10; i++) {
    if (pow(2, i) <= N) answer = pow(2, i);
    else break;
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ii pair<int, int>
#define N 1023
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define pb push_back
#define fs first
#define sc second
#define sz(x) ((int)((x).size()))
#define oo 1000000123
#define mod 1000000007

using namespace std;

int tem[N], n, K, d, di;

int main(){
    ios_base::sync_with_stdio(0);
    cin >> n >> K;
    while(K--){
        cin >> d;
        int q = d;
        while(q--){
            cin >> di;
            tem[di] = 1;
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; ++i) if(tem[i] == 0) ans++;
    cout << ans << '\n';
    return 0;
}


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

int main() {
  int S;
  int W;
  cin >> S >> W;
  if(S <= W)
  {
    cout << "unsafe" << endl;
  }
  else
  {
    cout << "safe" << endl;
  }
  

}


Measured memory_bytes: 3564
p = 10**9+7
def exp(y,x):
  xbin=str(bin(x))[2:]
  ans=1
  yl=[0]*(len(xbin)+1)
  yl[0]=y
  yl[1]=y**2
  for d,i in enumerate(xbin[::-1],start=0):
    if d > 1:
      yl[d]=yl[d-1]**2%p
    if i == "1":
      ans=(ans*yl[d])%p
  return ans%p
import sys
sys.setrecursionlimit(200000000)

def ff(n,ca):
  if ca == 0:
    return 1
  if ca == 1:
    return n
  return n*ff(n-1, ca-1)%p

def main():
  n,k = map(int,input().split())
  fact=[1,1]
  for i in range(2,n+1):
    fact.append(fact[-1]*i % p)

  for i in range(1,k+1):
    t1 = ff(k-1,i-1)*exp(fact[i-1],p-2)%p
    t2 = ff(n-k+1,i)*exp(fact[i],p-2)%p
    print(t1*t2 % p)

if __name__ == '__main__':
  main()

Measured memory_bytes: 10884
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] v = new int[n];
      int[] c = new int[n];
      int count = 0;
      for(int i = 0;i < n;i++){
      	v[i] = sc.nextInt();
      }
      for(int i = 0;i < n;i++){
      	c[i] = sc.nextInt();
        v[i] -= c[i];
        if(v[i] >= 0) count += v[i];
      }
      System.out.println(count);
      
      
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
using namespace std;
 
int main() {
  int H,W;

  while(cin >> H >> W){
    if(H==0 && W==0){ break; }
    for(int i=0;i<H;i++){
        for(int  j=0;j<W;j++){
            if((i+j)%2==0){
                cout << "#";
            } else {
                cout << ".";
            }
            
        }
        cout << endl;
    }
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
    int day, tasks;
    cin >> day >> tasks;
    int sum_tasks=0;
    for(int i=0;i<tasks;i++){
        int tmp;
        cin >> tmp;
        sum_tasks += tmp;
    }
    if(sum_tasks>day){
        cout << "-1\n";
    }else{
        cout << day-sum_tasks << endl;
    }
    return 0;
}

Measured memory_bytes: 3164
#include<stdio.h>

int main(){

  int N,flag,sum=0,temp,i,j;
  int A[100];

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  for(i=0;i<(N-1);i++){

    for(j=N-1;j>i;j--){
      if(A[j-1]>A[j]){
      temp=A[j-1];
      A[j-1]=A[j];
      A[j]=temp;
      sum++;
      }
    }
  }
  for(i=0;i<N-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n%d\n",A[N-1],sum);
}



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

int main() {
    // your code goes here
    ll m,n,i,j,p[100005],a=0,b=0,pn[100005]={0};
    bool ac[100005];
    char ss[100005][5];
    cin >> n >> m;
    for(i=1;i<=m;i++){
        cin >> p[i] >> ss[i];
        if(ss[i][0]=='A'){
            if(!ac[p[i]]){
                ac[p[i]]=true;
                a++;
            }
        } else {
            if(!ac[p[i]]){
                pn[p[i]]++;
            }
        }
    }
    for(i=1;i<=n;i++){
        if(ac[i]) b+=pn[i];
    }
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(){
    int N;bool connect=true;
    cin>>N;
    vector<string> w(N);
    cin>>w[0];
    for(int i=1;i<N;i++){
        string s,t;
        t = w[i-1];
        cin>>s;
        if(s[0] != t[t.size()-1]){
            connect = false;
        }
        w[i] = s;
        for(int j=i-1;j>=0;j--){
            if(w[i]==w[j]){
                connect = false;
            }
        }
    }
    if(connect){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
typedef pair<ll, ll> P;
typedef map<string, ll> M;
typedef unordered_map<ll, ll> HM;
typedef set<ll> S;
typedef multiset<ll> MS;
typedef queue<ll> Q;

int main(){
    int n; cin>>n;
    int h, nh; cin>>h;
    int ans = 0, cnt = 0;
    for(int i=1; i<n; i++){
        cin >> nh;
        if(h >= nh) cnt++;
        else{
            ans = max(ans, cnt);
            cnt = 0;
        }
        h = nh;
    }
    if(cnt) ans = max(ans, cnt);
    OUT(ans);
}


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

int main()
{
	int N;
	cin >> N;
	map<int, int> cnt;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		cnt[a]++;
	}
	int res = 0;
	for (auto p : cnt) {
		res += p.first > p.second ? p.second : p.second - p.first;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 4736
R1 = list(map(int, input().split(" ")))
R2 = list(map(int, input().split(" ")))
R3 = list(map(int, input().split(" ")))
N = int(input())
for i in range(N):
    b = int(input())
    for j in range(3):
        if R1[j] == b:
            R1[j] = 0
        if R2[j] == b:
            R2[j] = 0
        if R3[j] == b:
            R3[j] = 0
C1 = [R1[0], R2[0], R3[0]]
C2 = [R1[1], R2[1], R3[1]]
C3 = [R1[2], R2[2], R3[2]]
D1 = [R1[0], R2[1], R3[2]]
D2 = [R1[2], R2[1], R3[0]]

judge = "No"
if R1[0] == 0 and R1[1] == 0 and R1[2] == 0:
    judge = "Yes"
if R2[0] == 0 and R2[1] == 0 and R2[2] == 0:
    judge = "Yes"
if R3[0] == 0 and R3[1] == 0 and R3[2] == 0:
    judge = "Yes"
if C1[0] == 0 and C1[1] == 0 and C1[2] == 0:
    judge = "Yes"
if C2[0] == 0 and C2[1] == 0 and C2[2] == 0:
    judge = "Yes"
if C3[0] == 0 and C3[1] == 0 and C3[2] == 0:
    judge = "Yes"
if D1[0] == 0 and D1[1] == 0 and D1[2] == 0:
    judge = "Yes"
if D2[0] == 0 and D2[1] == 0 and D2[2] == 0:
    judge = "Yes"
print(judge)

Measured memory_bytes: 3192
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


class UF_tree:
    def __init__(self, n):
        self.root = [-1] * (n + 1)  # -1ならそのノードが根,で絶対値が木の要素数
        self.rank = [0] * (n + 1)

    def find(self, x):  # xの根となる要素番号を返す
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]

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

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

    def getNodeLen(self, x):
        return -self.root[self.find(x)]


if __name__ == "__main__":
    N, M = map(int, input().split())
    edge = [tuple(map(int, input().split())) for _ in range(M)]
    edge.sort(key=lambda x: x[2])

    ans = 0
    uf = UF_tree(N)
    for s, t, c in edge:
        if uf.isSame(s, t):
            continue
        ans += c
        uf.unite(s, t)
    print(ans)


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

int main(){

  int n, k;
  
  while(cin >> n >> k, n|k){
    
    int ans = 0, data[111111] = {};
    for(int i=0;i<n;i++) cin >> data[i];
    for(int i=1;i<n;i++) data[i] += data[i-1];
    
    for(int i=0;i<n-k;i++) ans = max(ans, data[i+k] - data[i]);
    
    cout << ans << endl;
  }
  
}

Measured memory_bytes: 1600
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc149/tasks/abc149_b

a, b, k = [int(x) for x in input().split()]
if a >= k:
    print(a - k, b)
elif a + b >= k:
    print(0, a + b - k)
else:
    print(0, 0)


Measured memory_bytes: 2940
from collections import deque
import sys

input = sys.stdin.readline

def main():
  n, m= map(int, input().split())

  links = [deque() for x in range(n + 1)]
  sums = [0 for x in range(n + 1)]
  adds = [0 for x in range(n + 1)]

  links[0].append(1)

  buf = [map(int, input().split()) for _ in range(n - 1)]

  for link in buf:
    a, b= link
    links[a].append(b)
    links[b].append(a)


  buf = [map(int, input().split()) for _ in range(m)]
  for px in buf:
    p, x = px
    adds[p] += x

  que = [0,[1]]
  checked = [0 for x in range(n+1)]

  que = deque([[-1, [0]]])

  while que:
    link = que.popleft()
    par = link[0]
    childs = link[1]

    for child in childs:
      if checked[child] != 1:
        sums[child] = sums[par] + adds[child]
        que.append([child, links[child]])
        checked[child] = 1


  print(*sums[1:])

if __name__ == "__main__":
  main()

Measured memory_bytes: 268292
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    if B % A == 0:
        print(A+B)
    else:
        print(B-A)


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1e9 + 10;//10^9
ll MOD  = 1000000007;
int dy[] = {0,0,1,-1};
int dx[] = {1,-1,0,0};


int main(void){
    int N;
    cin >> N;
    vector<pair<string, pair<int, int>>> sp(N);
    set<string> all;
    for(int i = 0; i < N; i++){
        cin >> sp[i].first >> sp[i].second.first;
        sp[i].second.second = i + 1;
    }
    
    sort(sp.begin(), sp.end());
    sp.push_back({"zzzzzzzzzzzzzzz",{0, 0}});
    
    vector<pair<int, int>> p;
    vector<pair<int, int>> xs;
    for(int i = 0; i < N; i++){
        if(sp[i].first != sp[i+1].first){
            xs.push_back({sp[i].second.first, sp[i].second.second});
            sort(xs.begin(), xs.end());
            reverse(xs.begin(), xs.end());
            for(int j = 0; j < xs.size(); j++){
                cout << xs[j].second << endl;
            }
            xs = p;
        }else{
            xs.push_back({sp[i].second.first, sp[i].second.second});
        }
        
        
    }
    
    
    
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, m;
    cin >> n >> m;
    vector<tuple<int, int, int>> t(m);
    rep(i, 0, m) {
        int p, y;
        cin >> p >> y;
        t[i] = make_tuple(p, y, i);
    }

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

    vector<pair<ll, ll>> pr(m);

    pr[get<2>(t[0])] = make_pair(get<0>(t[0]), 1);
    int cnt = 1;
    rep(i, 1, m) {
        if (get<0>(t[i]) != get<0>(t[i - 1])) cnt = 1;
        else cnt++;
        pr[get<2>(t[i])] = make_pair(get<0>(t[i]), cnt);
    }

    rep(i, 0, m) {
        cout << setfill('0') << right << setw(6) << pr[i].first;
        cout << setfill('0') << right << setw(6) << pr[i].second << endl;
    }
    return 0;
}


Measured memory_bytes: 4224
import numpy as np

n, k = map(int, input().split())
a = np.array([list(map(int, input().split())) for i in range(n)])

b = a[np.argsort(a[:,0])]
c = np.cumsum(b[:,1])
d = np.min(np.where(k <= c))
ans = b[d, 0]
print(ans)

Measured memory_bytes: 37900
num = int(input())
targets = map(int, input().split())
targets = list(targets)


global water_cnt
water_cnt = 0
def exe_water(init_state):
    global water_cnt
    # break condition
    if sum(init_state) == 0:
        return
    temp_water_cnt = min(init_state)
    water_cnt += temp_water_cnt

    lowest = temp_water_cnt
    # init sub_state
    sub_state = []
    for h in init_state:
        substracted_h = h - lowest
        if substracted_h != 0:
            sub_state.append(substracted_h)
        else:
            exe_water(sub_state)
            # reinit for next sequence
            sub_state = []
    # end case where no trailing 0
    exe_water(sub_state)

exe_water(targets)
print(water_cnt)


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#define WMAX 10000
#define HMAX 10000

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

struct edge{
  int to,cost;
};

int A,B,C,D,N,W,H,ans,dp[HMAX][WMAX];
string S;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};

void solve(){
	A = N % 10;
	B = (N%100-A)/10;
	C = (N%1000-B)/100;
	D = N/1000;
	if((A == B && B == C) || (B == C && C == D)){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
}

void debug(){

}

void answer(){
	cout << ans << "\n";
}

int main(){
	cin >> N;
	solve();
	#ifdef DEBUG
	debug();
	#endif
	// answer();

	return 0;
}

Measured memory_bytes: 256