akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    string s;
    cin>>s;
    long long int c;
    cin>>c;
    long long int digit_num = s.size();
    long long int zero_num = digit_num - c;
    if(zero_num<0){
        cout<<0<<endl;
        return 0;
    }
        //cout << zero_num << endl;
    vector<vector<vector<long long int>>> dp(digit_num+1, vector<vector<long long int>>(2, vector<long long int>(120, 0)));
    long long int x0 = (long long int)(s[0] - '0');
    dp[0][0][0] = x0-1 ;
    dp[0][0][1] = 1;
    dp[0][1][0] = 1;
    FOR(i,1,digit_num){
        long long int xi = (long long int)(s[i] - '0');
        //cout << xi << endl;
        if(xi==0){
            dp[i][0][0] += dp[i - 1][0][0] * 9 + dp[i - 1][0][0 + 1] * 0 + dp[i - 1][1][0] * (0) + dp[i - 1][1][0 + 1] * 0;

            REP(j,110){
                
                dp[i][0][j+1]+=dp[i - 1][0][j] * 1 + dp[i - 1][0][j + 1] * 9 + dp[i - 1][1][j] * (0) + dp[i - 1][1][j + 1] * 0;
         
                //dp[i][1][j]=dp[i - 1][0][j] * 9 + dp[i - 1][0][j + 1] * 0 + dp[i - 1][1][j] * (0) + dp[i - 1][1][j + 1] * 0;
                dp[i][1][j+1]+=dp[i - 1][0][j] * 0 + dp[i - 1][0][j + 1] * 0 + dp[i - 1][1][j] * (1) + dp[i - 1][1][j + 1] * 0;
            }
        }else{
            dp[i][0][0] += dp[i - 1][0][0] * 9 + dp[i - 1][0][0 + 1] * 0 + dp[i - 1][1][0] * (xi-1ll) + dp[i - 1][1][0 + 1] * 0;

            REP(j,110){
                
                dp[i][0][j+1]+=dp[i - 1][0][j] * 1 + dp[i - 1][0][j + 1] * 9 + dp[i - 1][1][j] * (1) + dp[i - 1][1][j + 1] * (xi-1ll);
                dp[i][1][j]+=dp[i - 1][0][j] * 0 + dp[i - 1][0][j + 1] * 0 + dp[i - 1][1][j] * (1) + dp[i - 1][1][j + 1] * 0;
                //dp[i][1][j+1]=dp[i - 1][0][j] * 0 + dp[i - 1][0][j + 1] * 0 + dp[i - 1][1][j] * (0) + dp[i - 1][1][j + 1] * 0;
            }
            
        }

      /*  cout << i << endl;
        FOR(j,i,i+5){
            cout<<"j="<<j<<" " << dp[i][0][j] << " " << dp[i][1][j] << endl;
        }
        cout << endl;*/
    }
    cout << dp[digit_num - 1][1][zero_num]+ dp[digit_num - 1][0][zero_num] << endl;
    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
char ss[25];
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    scanf("%s",ss+1);
    printf("%c%c%c",ss[1],ss[2],ss[3]);
    puts("");
    return 0;
}

Measured memory_bytes: 1704
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < n; i++)

int main() {
	string s;
	cin >> s;
	int n = s.size();
	int minDifference = 1000;
	rep(i, n - 2) {
		int now = 100 * (s[i] - '0') + 10 * (s[i + 1] - '0') + s[i + 2] - '0';
		int difference = max(now - 753, 753 - now);
		minDifference = min(minDifference, difference);
	}
	cout << minDifference << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int main() {

	int A, B, C, D, E;

	scanf("%d", &A);
	scanf("%d", &B);
	scanf("%d", &C);
	scanf("%d", &D);
	scanf("%d", &E);

	if (A < 0) {
		printf("%d\n", -A*C + D + B*E);
	}
	else {
		printf("%d\n", (B - A)*E);
	}

	return 0;
}

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



int main(){
	int H,W,N;
  
  	cin>>H;
  	cin>>W;
  	cin>>N;
  	
  	int sum=0;
  	int count=0;
  	for(int i=1;i<=max(H,W);i++){
      sum+=max(H,W);
      count=i;
      if(sum>=N)
        break;
    }
  
  	cout<<count<<endl;
  
  	return 0;
}



Measured memory_bytes: 256
import math


ordinal_n = int(input())
n = ordinal_n
sosuu_candidate = []
answer_list = []
for i in range(2, int(math.sqrt(n)+1)):
    sosuu_candidate.append(i)

for p in sosuu_candidate:
    while True:
        if n % p == 0:
            answer_list.append(str(p))
            n = int(n / p)
        else:
            break
if n == 1:
    print(str(ordinal_n) + ":" + ' ' + ' '.join(answer_list))
else:
    answer_list.append(str(n))
    print(str(ordinal_n) + ":" + ' ' + ' '.join(answer_list))


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

using namespace std;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef pair<int,int> pii;
typedef long long ll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}


unordered_map<ll,ll> memo;
vl mult = {2,3,5};
vl cst = {-1,-1,-1};
ll d;
const double inf = 1e18;

ll f(ll n){
    auto it = memo.find(n);
    if(it != memo.end()) return it->second;
    ll ans = inf;
    if(double(n) * d < inf){
        ans = n*d;
    }
    for(int i=0;i<3;i++){
        auto k = mult[i];
        ll cr = ((n%k)*d) + f(n/k) + cst[i];
        ans = min(ans, cr);
        if(n%k != 0){
            cr = ((k - (n%k))*d) + f((n+k-1)/k) + cst[i];
            ans = min(ans, cr);
        }
    }
    memo[n] = ans;
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int nt;
    cin >> nt;
    for(int tt=1;tt<=nt;tt++){
        memo.clear();
        ll  n;
        cin >> n >> cst[0] >> cst[1] >> cst[2] >> d;
        memo[0] = 0;
        memo[1] = d;
        cout << f(n) << "\n";
    }
    return 0;
}

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

//solution:
#define block(i) (i / B)
constexpr int N = 500001, A = 500'001, Q = 500'001;
int f[A], a[N], ans[Q], B = 707, answer;

struct query {
    int lo, hi, idx;
    query() {}
    query(int lo, int hi, int idx): lo(lo), hi(hi), idx(idx) {}
    bool operator < (const query& q) {
        return block(lo) < block(q.lo) || (block(lo) == block(q.lo) and hi < q.hi);
    }
} q[Q];

void hike() {
    int n, m; cin >> n >> m;
    for(int i = 0; i < n; ++i) cin >> a[i];
    for(int i = 0; i < m; ++i) {
        cin >> q[i].lo >> q[i].hi;
        --q[i].lo; --q[i].hi; q[i].idx = i;
    }
    sort(q, q + m);
    auto insert = [&](int i) {
        f[a[i]]++;
        if(f[a[i]] == 1) ++answer;
    };
    auto remove = [&](int i) {
        f[a[i]]--;
        if(f[a[i]] == 0) --answer;
    };
    int l = 0, r = -1;
    for(int i = 0; i < m; ++i) {
        int lo = q[i].lo, hi = q[i].hi;
        while(lo < l) insert(--l);
        while(hi > r) insert(++r);
        while(lo > l) remove(l++);
        while(hi < r) remove(r--);
        ans[q[i].idx] = answer;
    }
    for(int i = 0; i < m; ++i) cout << ans[i] << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int t = 1; //cin >> t;
    while(t--) hike();
    return 0;
} //farewell, until we meet again..

Measured memory_bytes: 15516
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iomanip>
//#include <chrono>
//#include <random>

#define fio ios_base::sync_with_stdio(false)
#define pdl cout << "*" << endl
#define MOD 1000000007
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define long int64_t
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1){ std::cerr << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args)
{ const char* comma = strchr(names + 1, ','); std::cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma+1, args...); }

using namespace std;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//uniform_int_distribution<> dis(0, INF<<1);

const int N = 1000001;

int c[N];

int p2(int v)
{
	int ret = 0;
	while((v & 1) == 0)
	{
		v >>= 1;
		ret++;
	}
	return ret;
}

int main()
{
	fio;
	for(int i=1; i<N; i++)
		c[i] = c[i-1] + p2(i);
	int n, x = 0;
	cin >> n;
	n--;
	bool f = false;
	for(int i=0; i<=n; i++)
	{
		char a;
		cin >> a;
		if(a == '2')
			f = true;
		int v = c[n] - c[i] - c[n-i];
		if(v == 0)
			x ^= a - '1';
	}
	if(x == 3)
		x = 1;
	else if(x == 2 and f)
		x = 0;
	cout << x << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
const int MAXN  = 5*1e5+5;
const ll mod = 1e9+7;
int cha[MAXN], num[MAXN];
int n;
void init()
{
    for(int i=1; i<=n; ++i)
    {
        cha[i]=i;
        num[i]=1;
    }
}

int Find(int x)
{
    if (cha[x]!=x) cha[x]=Find(cha[x]);
    return cha[x];
}

void join(int x, int y)
{
    int u= Find(x);
    int v= Find(y);
    if (u==v) return;
    if (rand()&1) swap(u,v);
    cha[v]=u;
    num[u]+=num[v];
    return;
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    double odd = n+(n&1);
    odd/=2;
    cout << setprecision(10) << fixed << odd/n ;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import math

def gcd(a, b):
    return math.gcd(a, b)

def lcm(a, b):
    return a * b / gcd(a, b)

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)


if __name__ == '__main__':
    W, H, x, y = map(float, input().split())
    if x == W / 2.0 and y == H / 2.0:
        print('{0} {1}'.format(W * H / 2.0, 1))
    else:
        print('{0} {1}'.format(W * H / 2.0, 0))


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < n; i++)
#define rep2(i,start,end) for(ll i = start; i < end; i++)
#define dwn(i,n) for(int i = n; i >= 0; i--)
#define dwn2(i,start,end) for(ll i = start; i >= end; i--)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int main(){
	ll n;
	cin>>n;
	ll k = (ll)sqrt(n);
//	cout<<k<<endl;
	ll ans = n;
	int flag = 0;
	for(int i = 1; i <= k; i++){
		ll tmp = n/i;
		if(tmp * i == n && ( i+ tmp) <= ans){
			ans = i+tmp;
			flag = 1;
//			cout<<ans<<" "<<i<<" "<<tmp<<endl;
		}
	}
	if(flag)
	cout<<ans-2<<endl;
	else cout<<ans-1<<endl;

	return 0;
}
//abc





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

long F(long A,long B)
{
    int countA=0,countB=0;
    while(1){
        A/=10;
        countA++;
        if(A==0) break;
    }
    while(1){
        B/=10;
        countB++;
        if(B==0) break;
    }
    return max(countA,countB);
}

int main()
{
    long N;
    cin >> N;
    long A,B;
    long mini=N;
    for(int i=1;i<=sqrt(N);i++){
        if(N%i==0) {
            A=i;
            B=N/i;
            mini=min(F(A,B),mini);
        }
    }
    cout << mini << endl;
}

Measured memory_bytes: 256
n = int(input())
t,x,y = (0,0,0)
Flag = True
for i in range(n):
    nt,nx,ny = list(map(int,input().split()))
    dist = abs(nx-x) + abs(ny-y)
    if dist > nt-t or (nt+nx+ny)%2 != 0:
        Flag = False
if Flag == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

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

  int cnt =0;

  for(int i=1; i<n-1; ++i){
    if(p[i-1]<p[i] && p[i]<p[i+1]) cnt++;
    else if(p[i-1]>p[i] && p[i]>p[i+1]) cnt++;
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    string t = "";
    for(int i = 0; i < s.size(); i++){
        t += "*";
    }
    t += s + t;
    int ans = 0;
    for(int i = 0; i < t.size() - s.size(); i++){
        if(i == s.size()){
            continue;
        }
        int tmp = 0, pre = 0, post = -1;
        for(int j = 0; j < s.size(); j++){
            if(s[j] == t[i + j]){
                if(tmp == 0){
                    pre = j;
                }
                tmp++;
            }else{
                tmp = 0;
            }
            if(tmp > 0){
                post = i + j - s.size();
            }
            ans = max(ans, tmp - max(0, post - pre + 1));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

template <typename T> T gcd(T m, T n) {
  T temp = 0;
  while(m % n != 0) {
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

template <typename T> T lcm(T m, T n) { return m / gcd(m, n) * n; }

int main() {
  int N;
  cin >> N;
  vector<ll> ts(N);
  for(int i = 0; i < N; ++i) {
    cin >> ts[i];
  }
  ll ans = ts[0];
  for(int i = 1; i < N; ++i) {
    ans = lcm(ans, ts[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args) {
    int[] array = new int[2];
    Scanner scanner = new Scanner(System.in);
    int i = 0;
    while(i < array.length) {
      array[i] = scanner.nextInt();
      i++;
    }
    
    if(array[0] * array[1] % 2 == 0) {
      System.out.println("Even");
    } else {
      System.out.println("Odd");
    }
  }
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)



int main(){
  string S;
  cin >> S;
  int Q;
  cin >> Q;
  deque<char> deq;
  REP(i, S.size()){
    deq.push_back(S[i]);
  }
  int flag = true;
  REP(i, Q){
    int T;
    cin >> T;
    if(T == 1){
      flag = !flag;
    }
    else{
      int F;
      char C;
      cin >> F >> C;
      if(F ==1 && flag || F == 2 && !flag){
        deq.push_front(C);
      }
      else{
        deq.push_back(C);
      }
    }
  }
  if(flag){
    for_each(deq.begin(), deq.end(), [](char c){
      cout << c;
    });
  }
  else{
    for_each(deq.rbegin(), deq.rend(), [](char c){
      cout << c;
    });
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int main()
{
	char d[3][3];
	for(int i=0;i<3;i++)
		for (int j = 0;j < 3;j++) {
			cin >> d[i][j];
		}

	cout << d[0][0] << d[1][1] << d[2][2] << endl;

	return 0;
}


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

int main(){
    int i;
    int a,b;
    while(cin>>a>>b){
        int c = a+b;
        int res = 1;
        while(c>=10){
            c/=10; res++;
        }
        cout << res << endl;
    }
    return 0;
}

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

using namespace std;


const int INF = 1e9 + 5;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N, K ;

    cin >> N >> K;

    vector<int> vi(N);

    for(int i = 0; i < N; ++i){
        cin >> vi[i];
    }

    vector<int> dp(K+1, INF);
    dp[0] = 0;

    for(int i = 1; i < N ; ++i){
        
        dp[ i % (K+1)] = INF;
        for(int j = i-1 ; j >= max(i-K, 0); --j ){
            // dp[i % (K +1)] = INF;

            dp[i % (K+1)] = min (dp[i % (K+1)] , abs(vi[i] - vi[j]) + dp[j % (K+1)]);
            // cout << " i is " << i << " and dp of " << i % (K+1) << " is " << dp[i % (K+1)] << "\n";
        }
    }

    /*
    for(int i : dp){
        cout << i << " ";
    }
    cout << "\n";

    */

    cout << dp[ (N-1) % (K+1)] << "\n";
    
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int N,K;
    cin>>N>>K;
    ll sum=0;
    int val;
    vi v;
    rep(i,0,N)cin>>val,v.push_back(val);
    ll ans=-INF;

    rep(l,0,K+1){
        rep(r,0,K-l+1){
            ll rest=K-(l+r);
            if(l+r>N||rest<0)break;
            ll sum=0;
            priority_queue<int,vi,greater<int>> q;
            rep(i,0,r)q.push(v[i]),sum+=v[i];
            rep(i,0,l)q.push(v[N-1-i]),sum+=v[N-1-i];
            int cnt=0;
            while(cnt<(r+l)&&cnt<rest){
                int minus=q.top();
                q.pop();
                if(minus>=0)break;
                cnt++;
                sum-=minus;
            }
            chmax(ans,sum);
        }
    }
    cout<<ans<<endl;
    return 0;
}




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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int H, W, h, w;

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

    std::cin >> H >> W >> h >> w;

    int res = H * W - h * W - H * w + h * w;
    std::cout << res << std::endl;
}


Measured memory_bytes: 256
A = [list(map(int,input().split())) for i in range(3)]
A_flat=[]
for i in range(len(A)):
    A_flat.append(A[i][0])
    A_flat.append(A[i][1])
    A_flat.append(A[i][2])

N = int(input())
b = [int(input()) for i in range(N)]
for i in range(len(b)):
    if b[i] in A_flat:
        index = A_flat.index(b[i])
        A_flat[index] = 0

judge=False
for i in range(3):
    if A_flat[0+i] == A_flat[3+i] == A_flat[6+i]:
        print("Yes")
        judge = True
        break
    elif A_flat[0+i*3]==A_flat[1+i*3]==A_flat[2+i*3]:
        print("Yes")
        judge = True
        break
    elif A_flat[0]==A_flat[4]==A_flat[8] or A_flat[2]==A_flat[4]==A_flat[6]:
        print("Yes")
        judge = True
        break

if judge is False:
    print("No")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph = vector<vector<int>>;

P enum_div(ll n){
    P ret = make_pair(n,n);
    for(ll i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            if(ret.first + ret.second > i + n/i){
                ret.first = i;
                ret.second = n/i;
            }
        }
    }
    return ret;
}

int main()
{
    ll n; cin >> n;
    P p = enum_div(n);
    cout << p.first + p.second -2 << endl;
}

/*
g++ c.cpp
./a.out

oj d https://atcoder.jp/contests/abc144/tasks/abc144_c
oj t
*/


Measured memory_bytes: 256
N=int(input())
num = list(map(int,input().split()))
tf = True
for i in range(N):
  if num[i]%2==0:
    if num[i]%3==0 or num[i]%5==0:
      pass
    else:
      tf = False
if tf:
  print("APPROVED")
else:
  print("DENIED")
      

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

const int MOD = 1000000007;

int main() {
  int a, b;
  cin >> a >> b;
  int d = abs(a - b);
  vector<long long> ex(100001);
  ex[0] = 1;
  for (long long i = 1; i <= 100000; i++) {
    ex[i] = (ex[i-1] * i) % MOD;
  }
  if (d == 0) {
    cout << ex[a] * ex[a] * 2 % MOD << endl;
  } else if (d == 1) {
    cout << ex[a] * ex[b] % MOD << endl;
  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>

#define roop(i,n,k) for(i=k;i<n;i++)

using namespace std;

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	char s[10];
	cin >> s;
	if (s[0] == 'S') {
		cout << "Cloudy";
	} else if (s[0] == 'C') {
		cout << "Rainy";
	} else {
		cout << "Sunny";
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	int k;
	cin >> k;
	int a, b;
	a = k / 2;
	b = k / 2;
	if (k % 2 == 1)
		b++;
	cout << a * b << endl;
}

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

int main(){
  int N,M;
  cin >> N >> M ;
  int a,b;
  vector <int> vec(N);

  for (int i_1 = 0; i_1 < M; i_1 ++){
    cin >> a >> b;
    for (int i_2 = 0; i_2 < N; i_2 ++){
      if (a == i_2 + 1 || b == i_2 + 1) vec.at(i_2) ++;
    }  
  }

  for (int i_3 = 0; i_3 < N; i_3 ++){
    cout << vec.at(i_3) <<endl;
  }

}


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

int main(void)
{
   int k, i;
   char s[101];

   scanf("%d%s",&k,s);

   if(k>=strlen(s))
      printf("%s",s);
   else{
      for(i=0;i<k;i++)
         printf("%c",s[i]);
      printf("...\n");
   }

   return 0;
}

Measured memory_bytes: 1672
#include<stdio.h>

int main(void)
{
	int a, b, c, i;
	int x = 0;
	scanf("%d %d %d", &a, &b, &c);
	for (i = a; i <= b; i++){
		if (c % i == 0)x++;
	}
	printf("%d\n", x);

	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<iomanip>
#include<string>
#include<string.h>
#include<cctype>
using namespace std;
int main()
{
    int n,t=0,t2=0,t3=0,t4=0;
    cin>>n;
    while(n--)
    {
        string s;
        cin>>s;
        if(s=="AC")
            t++;
        else if(s=="TLE")
            t2++;
        else if(s=="WA")
            t3++;
        else if(s=="RE")
            t4++;
    }
    cout<<"AC x " <<t<<endl;
    cout<<"WA x " <<t3<<endl;
    cout<<"TLE x " <<t2<<endl;
    cout<<"RE x " <<t4<<endl;















    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

map<ll,ll> lcm;
set<ll> c;
void prime_factor(ll n){
	map<ll,ll> res;
	for(ll i = 2; i * i  <= n; i++) {
		bool flag = false;
		while(n % i == 0){
			res[i]++;
			n /= i;
			flag = true;
		}
		if (flag){
			lcm[i] = max(lcm[i],res[i]);
			c.insert(i);
		}
	}
	if (n != 1){
		res[n] = 1;
		lcm[n] = max(lcm[n],res[n]);
		c.insert(n);
	}
}

ll mod_pow(ll x,ll n){
	ll res = 1;
	while(n > 0){
		if(n & 1){
			res = res * x % mod;
		}
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}


int main(){
	ll n;cin>>n;
	vector<ll> a(n);
	ll m = 0;
	for(int i = 0; i < n; i++) {
		cin>>a[i];
		prime_factor(a[i]);
		m = max(m,a[i]);
	}
	ll l = 1;
	// for(auto i = c.begin();i != c.end();i++) {
	// 	cout << *i << endl;
	// }
	for (auto i = c.begin();i != c.end();i++){
		l *= ((mod_pow(*i,lcm[*i])) % mod);
		l %= mod;
    }
	l %= mod;
	
	ll ans = 0;
	for(int i = 0; i < n; i++) {
		ans += (l * mod_pow(a[i],mod - 2)) % mod;
	}
	cout << ans % mod << endl;
	
	return 0;
}

Measured memory_bytes: 1408
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Map<String, Long> map = new HashMap<>();
		long cnt = 0;

		for ( int i = 0; i < n; i++ ) {
			char[] s = in.next().toCharArray();
			Arrays.sort(s);
			String key = new String(s);

			if(map.containsKey(key)) {
				map.put(key, map.get(key) + 1);
			}else {
				map.put(key, (long) 1);
			}			
		}

		for ( Entry<String, Long> en : map.entrySet() ) {
			// System.out.println(en);
			cnt += nCr(en.getValue(), 2);
		}

		System.out.println(cnt);
		in.close();
	}
	
	private static long nCr(long n, long r) {
		if ( r == 0 ) return 1;
		return n * nCr(n - 1, r - 1) / r;
	}
}


Measured memory_bytes: 53328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.*;

class Main {
    
    public static void main(String[] args) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	int q = Integer.parseInt(br.readLine());
	for (int i = 0; i < q; i++) {
	    String X = br.readLine();
	    String Y = br.readLine();
	    
	    int[][] dp = new int[X.length() + 1][Y.length() + 1];
	    int lc = 0;
	    for (int j = 1; j <= X.length(); j++) {
		for (int k = 1; k <= Y.length(); k++) {
		    char x = X.charAt(j - 1);
		    char y = Y.charAt(k - 1);
		    if (x == y) {
			lc = dp[j][k] = dp[j - 1][k - 1] + 1;
		    } else {
			lc = dp[j][k] = Math.max(dp[j][k - 1], dp[j - 1][k]);
		    }
		}
	    }
	    System.out.println(lc);
	}
    }
}



Measured memory_bytes: 63912
n,t = map(int, input().split())
T = list(map(int, input().split()))

prev,now,ans = T[0],0,0

for i in range(n):
    if not i:
        continue
    now = T[i]
    if now-prev > t:
        ans += t
    else:
        ans += now-prev
    prev = now
ans += t
print(ans)

Measured memory_bytes: 30912
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
int n;
int ans;

int main(){
  cin >> n;
  REP(i,n){
    int k;
    cin >> k;
    while(k%2==0){
      k = k/2;
      ans ++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, B, C, K):
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    def s(i, j, k):
        return A[i] + B[j] + C[k]
    used = set()
    
    cand = []
    if 1 < len(A):
        heapq.heappush(cand, (-s(1, 0, 0), (1, 0, 0)))
        used.add((1, 0, 0))
    if 1 < len(B):
        heapq.heappush(cand, (-s(0, 1, 0), (0, 1, 0)))
        used.add((0, 1, 0))
    if 1 < len(C):
        heapq.heappush(cand, (-s(0, 0, 1), (0, 0, 1)))
        used.add((0, 0, 1))
    print(s(0, 0, 0))
    for _ in range(K-1):
        v, i = heapq.heappop(cand)
        print(-v)
        
        ti = (i[0]+1, i[1], i[2])
        if ti[0] < len(A) and ti not in used:
            heapq.heappush(cand, (-s(*ti), ti))
            used.add(ti)
        
        ti = (i[0], i[1]+1, i[2])
        if ti[1] < len(B) and ti not in used:
            heapq.heappush(cand, (-s(*ti), ti))
            used.add(ti)
        
        ti = (i[0], i[1], i[2]+1)
        if ti[2] < len(C) and ti not in used:
            heapq.heappush(cand, (-s(*ti), ti))
            used.add(ti)



def main():
    # for _ in range(1000):
    #     K = 3000
    #     A = [random.randint(1, 10000000000) for _ in range(random.randint(1, 1000))]
    #     B = [random.randint(1, 10000000000) for _ in range(random.randint(1, 1000))]
    #     C = [random.randint(1, 10000000000) for _ in range(random.randint(1, 1000))]
    #     K = min(K, len(A) + len(B) + len(C))
    #     slv(A,B,C,K)
    # N = read_int()
    X, Y, Z, K = read_int_n()
    A = read_int_n()
    B = read_int_n()
    C = read_int_n()
    (slv(A, B, C, K))


if __name__ == '__main__':
    main()


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

using namespace std;
#define ll long long


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int ans = s.size();
    for (int i = 0; i + t.size() <= s.size(); i++) {
        int cnt = 0;
        for (int j = 0; j < t.size(); j++) {
            if (t[j] != s[i + j])cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
using  namespace std;
int main(){
    int n,y;
    cin>>n>>y;
    int ans1000,ans5000,ans10000;
    ans1000=ans5000=ans10000=-1;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            int k=n-(i+j);
            if(y==(i*10000+j*5000+k*1000)){
                ans1000=k;
                ans5000=j;
                ans10000=i;
            }
        }
    }
    cout<<ans10000<<" "<<ans5000<<" "<<ans1000<<endl;
}

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

int main() {
    string S;
    cin >> S;
    int ans = 700;
    for(int i; i<3; ++i){
        if (S.at(i) == 'o'){
            ans += 100;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
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 VI = vector<int>;
using VVI = vector<vector<int>>;
using P = pair<int, int>;

int main(){
	int n;
    cin >> n;
    VI x(n),y(n),h(n);
    rep(i,n) cin >> x[i] >> y[i] >> h[i];

    rep(cx,101){
        rep(cy,101){
            int H;
            rep(i,n){
                if(h[i] != 0){
                    H = h[i] + abs(x[i]-cx) + abs(y[i]-cy);
                    break;
                }
            }
            bool flag=true;
            rep(i,n){
                if(h[i] != max(H-abs(x[i]-cx)-abs(y[i]-cy), 0)){
                    flag = false;
                    break;
                }
            }
            if(flag) cout << cx << " " << cy << " " << H << endl;
        }
    }

	return 0;
}

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

int main(){
    int a, b, x;
    cin >> a >> b >> x;
    double ok = M_PI / 2;
    double ng = 0;
    while (abs(ok - ng) > 1e-10){
        double mid = (ok + ng) / 2;
        if (tan(mid) >= (double)a / b){
            if (a * a * (b - a / tan(mid) / 2) >= x) ok = mid;
            else ng = mid;
        }
        else {
            if (a * b * b * tan(mid) / 2 >= x) ok = mid;
            else ng = mid;
        }
    }
    cout << setprecision(15) << (double)90 - ok / M_PI * 180 << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    
    int T[N], A[N];
    for(int i=0; i<N; i++){
        cin >> T[i] >> A[i];
    }

    ll t, a;
    t = T[0];
    a = A[0];

    for(int i=1; i<N; i++){
        ll m1, m2;
        if(a % A[i] == 0) m1 = a/A[i];
        else m1 = a/A[i] + 1;

        if(t % T[i] == 0) m2 = t/T[i];
        else m2 = t/T[i] + 1;

        ll m = max(m1, m2);
        t = T[i] * m;
        a = A[i] * m;
    }

    cout << a+t << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int n,i;
    long int sum=0;
    scanf("%d",&n);
    int a[n+1],b[n];
    for(i=0;i<n+1;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++){
        scanf("%d",&b[i]);
    }
    for(i=0;i<n;i++){
        if(a[i]<b[i]){
            sum+=a[i];
            b[i]-=a[i];
            if(b[i]<a[i+1]){
                sum+=b[i];
                a[i+1]-=b[i];
            }else{
                sum+=a[i+1];
                a[i+1]=0;
            }
        }else{
            sum+=b[i];
        }
    }
    printf("%ld\n",sum);
    return 0;
}




Measured memory_bytes: 896
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using namespace std;



int main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	ll q, h, o, d, n;
	cin >> q >> h >> o >> d >> n;
	o = min({4 * q, 2 * h, o});
	d = min(2 * o, d); 
	cout << (n / 2) * d + (n % 2) * o << "\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)2e9)
#define INFLL ((LL)2e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (2 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 2, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 1) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL res = 2;
    LL sum = a;
    while(b){
        if(b&2)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

double exp(double a, LL b){
    double res = 1;
    double sum = a;
    while(b){
        if(b&1)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

class now{
public:   
    int place;
    int step;
    int time;
    now(int a, int b, int c){
        time = a;
        place = b;
        step = c;
    }
};

bool operator<(const now &a, const now &b){
    return a.time < b.time;
}
bool operator==(const now &a, const now &b){
    return a.time == b.time;
}
bool operator>(const now &a, const now &b){
    return a.time > b.time;
}
signed  main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int> > roads(N+1);
    REP(i, M){
        int a, b;
        cin >> a >> b;
        roads[a].push_back(b);
    }
    vector<vector<int> > fast(N+1, vector<int>(3, INF));
    int S, T;
    cin >> S >> T;
    fast[S][0] = 0;
    priority_queue<now, vector<now>, greater<now> > que;
    que.push(now(0, S, 0));
    while(!que.empty()){
        now d = que.top();
        que.pop();
        if(fast[d.place][d.step]!=d.time)continue;
        for(auto &i:roads[d.place]){
            int time = d.time + 1;
            now ne(time, i, (d.step+2)%3);
            if(fast[ne.place][ne.step]>time){
                fast[ne.place][ne.step]=time;
                que.push(ne);
            }
        }
    }
    cout << (fast[T][0]==INF?-1:fast[T][0]/3) << endl;
    return 0;
}



Measured memory_bytes: 11136
// 0501 Data Conversion
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0501
// by Equim on 16-12-20

using System;
using System.Collections.Generic;

class Program
{
    public static void Main(string[] args)
    {
        int Total;

        while ((Total = int.Parse(Console.ReadLine())) != 0)
        {
            Dictionary<string, string> Dict = new Dictionary<string, string>();

            for (int t = 1; t <= Total; t++)
            {
                string[] Raw = Console.ReadLine().Split(' ');
                Dict.Add(Raw[0], Raw[1]);
            }

            Total = int.Parse(Console.ReadLine());

            for (int t = 1; t <= Total; t++)
            {
                string Raw = Console.ReadLine();

                if (Dict.ContainsKey(Raw))
                    Console.Write(Dict[Raw]);
                else
                    Console.Write(Raw);
            }
            Console.WriteLine();
        }
    }
}

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

minus = []
plus = []
for i in A:
    if (i < 0):
        minus.append(i)
    else:
        plus.append(i)

if (len(minus) % 2 == 0 or 0 in plus):
    # 全てを正にできる
    print(sum(plus) - sum(minus))
    exit()

# 絶対値がもっとも小さいものを探す
min_abs = 10**9 + 7
for i in A:
    min_abs = min(min_abs, abs(i))

sum_ans = 0
for i in A:
    sum_ans += abs(i)

print(sum_ans - min_abs * 2)


Measured memory_bytes: 20040
import sys
input = sys.stdin.readline
K, S = map(int, input().split())
table = [0] * (3 * K + 1)
for x in range(K + 1):
  for y in range(K + 1):
    table[x + y] += 1
res = 0
#print(table)
for z in range(3 * K + 1):
  if (S - z) in range(K + 1): res += table[z]
print(res)

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

int main()
{
  int i,diff,ans=1002;
  char S[1002],T[1002];

  scanf("%s%s", S,T);
  for(int start=0; start<= strlen(S)-strlen(T); start++)
  {
    diff = 0;
    for(i=0; i<strlen(T); i++)
    {
      if(T[i] != S[start+i])
        diff++;
    }
    if(ans > diff)
    ans = diff;
  }

  printf("%d", ans);
  return 0;
}


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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	map<int,int> m;
	for(int i=1,x;i<=n;i++){
		cin>>x;
		m[x]++;
	}
	if(n%3!=0){
		if(m.size()==1&&m.begin() -> first == 0)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
	else{
		vector<int> v;
		for(auto it:m)
			if(it.second %(n/3) !=0){
				cout<<"No"<<endl;
				return 0;
			}
			else{
				for(int i=0;i<it.second/(n/3);i++)
					v.emplace_back(it.first);
			}
		if(v[0]^v[1]^v[2])
			cout<<"No"<<endl;
		else
			cout<<"Yes"<<endl;	
	}
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
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;
}
const long long INF = 1LL << 60;

int main(){
int N; cin >> N;
long long a[100010][3];
long long dp[100010][3] = {0};
for (int i = 0; i < N; i++){
    for(int j = 0; j < 3; j++){
        cin >> a[i][j];
    }
}

//ループでdpテーブルを更新する。
for (int i = 0; i < N; i++){
    for(int j = 0; j < 3; j++){
        for(int k = 0; k < 3; k++){
            if(j == k){
                continue;
            } else {
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }
}

long long ans = 0;
for(int i = 0; i < 3; i++){
    chmax(ans, dp[N][i]);
}

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

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    int ans = 1001001001;
    for(int i = 0; i <= n - k; i++){
        ans = min(ans, h[i+k-1] - h[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>

#define SIZE 100005
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
 
using namespace std;


int main()
{	
	
	ll H, W;
	scanf("%lld %lld", &H, &W);
	ll ans;
	ans=H*W-H*W/2;
	if( (H==1) || (W==1) )
	{
		ans=1;
	}
	printf("%lld", ans);
}


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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

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

  int n, m; cin >> n >> m;
  vvi v(m+1);
  REP(i, n) {
    int a, b; cin >> a >> b;
    if(a > m) continue;
    v[a].push_back(b);
  }

  priority_queue<int> pq;
  ll ans = 0;
  FOR(i, 1, m+1) {
    REP(j, SZ(v[i])) {
      pq.push(v[i][j]);
    }
    if(!pq.empty()) {
      ans += pq.top(); pq.pop();
    }
  }
  cout << ans << endl;

}
























Measured memory_bytes: 5632
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<list>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;



int main() {
   string s;
   long long k;
   cin >> s >> k;
   VI ary;
   ary.push_back(1);
   for (int i = 1; i < s.size(); i++)
   {
	  if (s[i] == s[i - 1])ary.back()++;
	  else ary.push_back(1);
   }
   ll cnt = 0;
   for (int i = 0; i < ary.size(); i++)
   {
	  cnt += ary[i] / 2;
   }
   ll ans = 0;
   if (s.size() == 1) {
	  cout << k / 2 << endl;
	  return 0;
   }
   if (ary.size() == 1) {
	  cout << k * s.size() / 2 << endl;
	  return 0;
   }
   if (s[0] == s.back()) {
	  cnt -= (ary[0] / 2 + ary.back() / 2);
	  ans += cnt * k;
	  ans += (ary[0] + ary.back()) / 2 * (k - 1) + ary[0] / 2 + ary.back() / 2;
   }
   else {
	  ans += cnt * k;
   }
   cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

struct Card{
  char s;
  char v;
};

void bubble(struct Card A[], int n);
void selection(struct Card A[], int n);
void printer(struct Card A[], int n);
int isstable(struct Card C1[], struct Card C2[], int n);

int main(){
  struct Card C1[101], C2[101];
  int n, i;
  char ch;

  scanf("%d\n", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%c%c ", &C1[i].s, &C1[i].v);
  }

  for ( i = 0; i < n; i++ ) C2[i] = C1[i];

  bubble(C1, n);
  selection(C2, n);

  printer(C1, n);
  printf("Stable\n");
  printer(C2, n);
  if ( isstable(C1, C2, n) ){
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}

void bubble(struct Card A[], int n){
  int i, j;
  struct Card t;
  for ( i = 0; i < n; i++ ){
    for ( j = n-1; j >= i+1; j-- ){
      if ( A[j].v < A[j-1].v ){
        t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(struct Card A[], int n){
  int i, j, mini;
  struct Card t;
  for ( i = 0; i < n; i++ ){
    mini = i;
    for ( j = i; j < n; j++ ){
      if ( A[j].v < A[mini].v ) mini = j;
    }
    t = A[i]; A[i] = A[mini]; A[mini] = t;
  }
}

void printer(struct Card A[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( i ) printf(" ");
    printf("%c%c", A[i].s, A[i].v);
  }
  printf("\n");
}

int isstable(struct Card C1[], struct Card C2[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( C1[i].s != C2[i].s ) return 0;
  }
  return 1;
}



Measured memory_bytes: 2032
#include<bits/stdc++.h>
using namespace std;
long long a[100010],x,m,n,cnt,blag,cx=0,t;
long long ans=0,res,jyz[100010]={0};
int main()
{
	cin>>n>>x>>m;
	memset(a,0,sizeof a);
	res=x;ans=res;jyz[1]=res;a[res]=1;
	for (register int i=2;i<=n;i++) 
	{
		res=res*res;
		if (res>=m) res%=m;
		//if (res==0) break;
		if (a[res]!=0) {cnt=i-a[res];blag=a[res];jyz[i]=jyz[i-1]+res;t=i;cx=233;break;}
		else {a[res]=i;jyz[i]=jyz[i-1]+res;ans+=res;}
	}
	if (cx==233) 
	{
		ans+=(n-t)/cnt*(jyz[t]-jyz[blag]); 
		for (register int i=1;i<a[res];i++) x=x*x%m;
		for (register int i=a[res];i<a[res]+(n-t)%cnt;i++) ans+=x,x=x*x%m;
		if (t!=n) ans+=x;
	}  
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 4780