akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    char[] cs;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        cs = sc.next().toCharArray();
        solve();
    }

    void solve() {
        int j = 0;
        for (; j < cs.length - 1; j++) {
            if (cs[j] == cs[j + 1]) {
                System.out.println((j + 1) + " " + (j + 2));
                return;
            } else if (j < cs.length - 2 && cs[j] == cs[j + 2]) {
                System.out.println((j + 1) + " " + (j + 3));
                return;
            }
        }
        System.out.println("-1 -1");
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

using namespace std;
int n,a[100100],Ans[100100];

int main()
{
    cin >> n;
    for(int i = 1;i<=n;i++)  cin >> a[i];
    for(int i = 1;i<=n;i++){
        Ans[a[i]] = i;
    }
    for(int i = 1;i<=n;i++)  cout << Ans[i] << " ";
    return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>
#define ll long long
#define MOD 998244353

ll dp[200010],cum[200010];
int l[20],r[20];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<k;i++){
		scanf("%d%d",l+i,r+i);
		r[i]++;
	}
	
	dp[1]=1;
	cum[1]=1;
	for(int i=2;i<=n;i++){
		for(int j=0;j<k;j++){
			if(i-l[j]>=0)dp[i]+=cum[i-l[j]];
			if(i-r[j]>=0)dp[i]-=cum[i-r[j]];
		}
		dp[i]=(dp[i]%MOD+MOD)%MOD;
		cum[i]=(cum[i-1]+dp[i])%MOD;
	}
	printf("%lld\n",dp[n]);
}

Measured memory_bytes: 4856
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int n,ans;
vector<vector<int>> v(111111);
map<P,int> f,m;
int col[111111];
void dfs(int i,int now){
    int val=1;
    for(auto x:v[i]){
        if(val==now)val++;
        if(!f[{i,x}]&&!f[{x,i}]){
            f[{i,x}]=1;f[{x,i}]=1;
            col[m[{i,x}]]=val;
            dfs(x,val);
            val++;
        }
    }
}

signed main(){
	cin>>n;

    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        v[a].push_back(b);
        v[b].push_back(a);
        m[{a,b}]=i;
        m[{b,a}]=i;
    }
    dfs(0,0);
    rep(i,n-1)ans=max(ans,col[i]);
    cout<<ans<<endl;
    rep(i,n-1){
        cout<<col[i]<<endl;
    }

}

Measured memory_bytes: 32512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int main() {
	int A, B, K;
	cin >> A >> B >> K;
	for (int i = A; i < min(A + K, B - K + 1); i++) printf("%d\n", i);
	for (int i = max(A, B - K + 1); i <= B; i++) printf("%d\n", i);
	
	return 0;
}

Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,numpy,string,decimal
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def is_square_num(n):
  i2 = 0
  for i in range(0, n + 1):
    if i2 == n:
      return True
    if i2 > n:
      return False
    i2 += i * 2 + 1

a,b = SS()
N = int(a + b)

if is_square_num(N):
  print("Yes")
else:
  print("No")


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

using namespace std;

int main() {
    int w, a, b;
    int x0, x1;
    int d;

    cin >> w >> a >> b;

    if (a < b) {
        x0 = a;
        x1 = b;
    } else {
        x0 = b;
        x1 = a;
    }

    if ( x1 <= (x0 + w)) {
        d = 0;
    } else {
        d = x1 - (x0 + w);
    }

    cout << d << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007
#define ll long long
#define int long long 
# define INF 2e5+5
#define ar array
# define fr first
# define sc second
#define wt(x) int x;cin>>x;while(x--)
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
//#define cerr if(false)cerr
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> pbds;

void  c_p_c(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
 
#ifndef ONLINE_JUDGE
  freopen("input1.txt","r",stdin);
  freopen("output1.txt","w",stdout);
#endif
 }
 
int power(int a,int b,int mod){
    a=a%mod;
    if(a==0){
        return 1;
    }
    int res=1;
    while(b){
        if(b&1){
            res=(res*a)%mod;
        }
        b>>=1;
        a=(a*a)%mod;
    }
    return res;
 }
 
int  MMI(int p){
    return power(p,MOD-2,MOD);
}


int32_t main()
{
    
    c_p_c();
   int N;
   cin>>N;
    map<string, int> mp;
    while(N--){
        string s;
        cin >> s;
        mp[s]++;
    }
    for(string s : {"AC", "WA", "TLE", "RE"}) cout << s << " x " << mp[s] << endl;
    return 0;
         


             
    
}
 


Measured memory_bytes: 3676
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))
#define LLONG_MAX numeric_limits<long long>::max()
#define INT_MAX numeric_limits<int>::max()

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vs>		vvs;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

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

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	int ma = B / A;
	cout << min(ma, C) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

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

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

struct p
{
	ll a;
	int b;
	int c;
};

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

	printf("%d", n * (n - 1) / 2 + m * (m - 1) / 2);
	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
// clang-format off
#define FOR(i, n) for (int i=0; i<(int)n; ++i)
#define RFOR(i, n) for (int i=n-1; i>=0; --i)
#define FORR(x,arr) for(auto& x:arr)
#define OUTV(x) FOR(j,x.size()) cerr<<x[j]<<(x.size()-j-1?' ':'\n');
#define OUTM(x) FOR(i,x.size()) {OUTV(x[i])}
#define DEBUG(x) cerr<<"DEBUG: "<<#x<<" = "<<x<<endl;
#define PB push_back
#define MP make_pair
#define INF 0x3f3f3f3f
// clang-format on
using namespace std;
typedef signed long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  std::random_device rd;
  std::mt19937 ran(rd());

  char b;
  cin >> b;
  if (b == 'A')
    cout << 'T' << endl;
  else if (b == 'T')
    cout << 'A' << endl;
  else if (b == 'C')
    cout << 'G' << endl;
  else if (b == 'G')
    cout << 'C' << endl;

  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <numeric>
#include <type_traits>
#include <limits>
#include <random>
#include <iomanip>

using namespace std;

using ll = long long;

typedef pair<ll, ll> P;

#define rep(i,N) for(long long i = 0;i < (long long)N; ++i)

static int mod = 1000000007;
static int large_int = 1000000000;
static ll large_ll = 1000000000000000000;

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

char b;

int main() {
	cin >> b;
	switch (b)
	{
	case 'A':
		cout << 'T' << endl;
		break;
	case 'G':
		cout << 'C' << endl;
		break;
	case 'T':
		cout << 'A' << endl;
		break;
	case 'C':
		cout << 'G' << endl;
		break;
	default:
		break;
	}
	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 ll long long

int main(){
	int n;
	cin >> n;
	set<int> num;
	rep(i, n){
		int d;
		cin >> d;
		num.insert(d);
	}

	if(num.size() == n) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b,int m) {
    if (b==0) return 1;
    ll c = power(a,b>>1,m);
    c = (c*c)%m;
    if (b&1) return (c*a)%m;
    return c;
}
ll powerwithoutmod(ll a,ll b) {
    if (b==0) return 1;
    ll c = powerwithoutmod(a,b>>1);
    c = (c*c);
    if (b&1) return (c*a);
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int Q = 301;
const int logN = 16;

void solve() {
    int x,y,c,a,b,m;
    cin>>a>>b>>m;
    vector<int> refrigerator(a+1), microwave(b+1);
    REP(i,1,a) {
        cin>>refrigerator[i];
    }
    REP(i,1,b) {
        cin>>microwave[i];
    }
    int ans = INT_MAX;
    REP(i,1,m) {
        cin>>x>>y>>c;
        ans = min(ans, refrigerator[x] + microwave[y] - c);
    }
    sort(all(refrigerator));
    sort(all(microwave));
    ans = min(ans, refrigerator[1] + microwave[1]);
    cout<<ans;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC080A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b, p1, p2,x;

            var word = Console.ReadLine().Split(' ');

            n = int.Parse(word[0]);
            a = int.Parse(word[1]);
            b = int.Parse(word[2]);


			p1 = a * n;
			p2 = b;

			x = p1 - p2;
			if (p1 < p2)
				Console.WriteLine(p1);
			else
				Console.WriteLine(p2);


            Console.ReadKey();
        }
    }
}


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

typedef long long ll;
ll n, a, t, i, s;
int main()
{
	t = -1;
	cin >>n;
	for (i= 0; i < n; i++) {
		scanf ("%lld", &a);
		if (a - t >= 2) {
			cout << -1;
			return 0;
		}
		if (a != 0) {
			if (a - t == 1) s++;
			else s += a;
		}
		t =a;
	}
    cout << s;
    return 0;
}


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

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

	string s;
	for( char c = 'a'; c <= 'z'; c++ ) {
		s += c;
	}
	reverse( s.begin(), s.end() );
	if( S == s ) {
		cout << -1 << endl;
		return 0;
	}
	int n = S.size();
	string ans;
	if( n < 26 ) {
		map<char, int> mp;
		for( int i = 0; i < n; i++ ) {
			mp[ S[i] ]++;
		}
		for( int i = s.size() - 1; i >= 0; i-- ) {
			if( mp[ s[i] ] ) continue;
			ans = S + s[i];
			break;
		}
	}
	else {
		int j;
		char c = S[n - 1];
		for( int i = n - 2; i >= 0; i-- ) {
			if( S[i] > c ) {
				c = S[i];
				continue;
			}
			j = i;
			c = S[i];
			break;
		}
		char cc = 'z';
		for( int i = n - 1; i > j; i-- ) {
			if( S[i] > c ) {
				cc = min( cc, S[i] );
			}
		}
		ans = S.substr( 0, j ) + cc;
	}

	cout << ans << endl;
}


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

int main() {
	int n, c, k, t[100000];
	cin >> n >> c >> k;
	for (int i = 0; i < n; i++) {
		cin >> t[i];
	}
	sort(t, t + n);
	int m = 0;
	int a = 0;
	int b = 0;
	for (int i = 0; i < n; i++) {
		if (m == 0 || a >= c || t[i] > b + k) {
			m++;
			a = 1;
			b = t[i];
		} else {
			a++;
		}
	}
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
ll n,cnt=0;
ll a[N];
bool prime[N];
string s1,s2;
multiset<int> s;
map<int,int>mp;
int main() {
 //   freopen("../in.in", "r", stdin);
//    freopen("../out.out","w",stdout);
    ios::sync_with_stdio(false);
    ll t, i, j = 0;
    ll m, x, y,k;
    cin>>n>>m;
    for(i=1;i<=m;i++) mp[i]=i,s.insert(0);
    for(i=1;i<=n;i++){
        int l,r;
        cin>>l>>r;
        auto it=mp.lower_bound(l);
        int mx=0;
        while(it->first<=r&&it!=mp.end()){
            mx=max(mx,it->second);
            s.erase(s.find(it->first-it->second));
            mp.erase(it++);
        }
        if(mx!=0&&r<m&&mp.find(r+1)==mp.end()){
            mp[r+1]=mx;
            s.insert(r+1-mx);
        }
        if(s.size()) cout<<*(s.begin())+i<<endl;
        else cout<<-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 22308
import math

a, b, x = map(int, input().split())

if (a**2*b / 2) <= x:
    theta = 90 - 180 * math.atan(2 * (a**2 * b - x)/a**3) / 3.1415926
else:
    theta = 180 * math.atan(2 * x / (a * b ** 2)) / 3.1415926

print(90 - theta)


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

int main(){
    int N;
    cin >> N;
    vector<int> A(100100);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A.rbegin(),A.rend());

    int num=A[0],ct=0,sum=0;
    for(int i=0;i<N;i++){
        if(num==A[i]){
            ct++;
        }
        else{
            if(ct<num)sum+=ct;
            else sum+=ct-num;
            num=A[i];
            ct=1;
        }
        if(i==N-1){
            if(ct<num)sum+=ct;
            else sum+=ct-num;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <iomanip> // << fixed << precision(10)
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"
#define NEWMAT(N, M, ini) MAT(N, vector<lint>(M, ini))
#define MOD 1000000007

typedef long long lint;
typedef pair<lint, lint> P;
typedef vector<lint> V;
typedef vector<vector<lint>> MAT;
bool lessPair(const P& l, const P& r){return l.second < r.second;}

lint cost(lint a) {
  lint c[] = {2,5,5,4,5,6,3,7,6};
  return c[a-1];
}

lint calcdp(lint i, V &dp, V &A) {
  if(i < 0) return -1000;
  if(dp[i] != -1) return dp[i];

  lint res = -1;
  REP(j, A.size()) {
    res = max(res, calcdp(i-cost(A[j]), dp, A)+1);
  }
  dp[i] = res;
  return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    lint N; cin >> N;
    lint M; cin >> M;

    V A(M);
    REP(i, M) {
      lint x; cin >> x; A[i] = x;
    }

    sort(A.rbegin(), A.rend());
    V dp(N+1, -1);
    dp[0] = 0;

    lint current = calcdp(N, dp, A);

    string res = "";

    lint match = N;
    while(current > 0) {
      REP(j, M) {
        if(match-cost(A[j]) >=0 && dp[match-cost(A[j])] == current-1) {
          match -= cost(A[j]);
          res += "123456789"[A[j]-1];
          current--;
          break;
        }
      }
    }

    PRINT(res);
    return 0;
}


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

typedef  long long ll;
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;}

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

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int n;
int main(){
    ll w,h;
    cin>>w>>h;
    int x,y;
    cin>>x>>y;
    double half=w*h/2.0;
    cout<<fixed<<setprecision(10)<<half;
    double dw=w,dh=h;
    if((x==dw/2)&&(y==dh/2))cout<<" "<<1<<endl;
    else{
        cout<<" "<<0<<endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int ans = s.size();
	for (int i = 0; i < s.size(); i++) {
	  char c = s[i];
	  int cnt=0,temp=0;
	  for (int j = 0; j < s.size(); j++) {
	    if (s[s.size() - j - 1] != c) {
		  cnt++;
		}
        else {
		  cnt=0;
		}
		temp = max(temp, cnt);
	  }
	  ans = min(ans, temp);
	}
  cout << ans << endl;
}

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

int fibonacci(int n, vector<int> &memo) {
  if (n == 0 || n == 1) return 1;
  if (memo[n] != -1) return memo[n];
  return memo[n] = fibonacci(n - 1, memo) + fibonacci(n - 2, memo);
}

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

  vector<int> memo(50, -1);
  cout << fibonacci(N, memo) << endl;
}


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

int main() {
    string s;
    cin >> s;

    regex re(regex_replace("AKIHABARA", regex("A"), "A?"));

    cout << (regex_match(s, re) ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define vi vector <int>
#define vl vector <long long>
#define pb push_back
#define mk make_pair
#define pi pair <int,int>
#define pl pair <ll,ll>
#define rep(i,a,n) for(int i=a;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define rep_(i,a,n) for(int i=(n-1);i>=a;i--)
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int x=n,d=0;
    while(x>0)
    {
    	d++;
    	x/=10;
	}
	ll ans=0;
	for(int i=1;i<d;i+=2)
	{
		ans+=9*(pow(10,i-1));
	}
	if(d%2!=0)
	{
		ans+=(n-(pow(10,d-1))+1);
	}
	cout<<ans<<endl;
}

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

int main() {
	int n;
	string s;
	cin >> n >> s;
	int w[n], e[n];
	w[0] = 0, e[n - 1] = 0;
	for (int i = 0; i < n - 1; i++) {
		w[i + 1] = w[i] + (s[i] == 'W');
		e[n - 1 - (i + 1)] = e[n - 1 - i] + (s[n - 1 - i] == 'E');
	}
	int m = w[0] + e[0];
	for (int i = 1; i < n; i++) {
		m = min(m, w[i] + e[i]);
	}
	cout << m << endl;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,cnt=0;
  cin>>n>>m;
  int ara[n+5];
  long int sum=0;
  for(int i=0;i<n;i++) {
    cin>>ara[i];
    sum+=ara[i];
  }
  //int ok = (sum/4*m);
  for(int i=0;i<n;i++){
    if(ara[i]*4*m>=sum) {
      cnt++;
    }
  }
  if(cnt>=m) cout<<"Yes"<<endl;
    else  cout<<"No"<<endl;
}

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

long long int abs(long long x, long long y)
{
    if(x>=y) return (x-y);
    else return (y-x);
}

using namespace std;

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

    int n;
    cin >> n;

    vector<long long int> a(n);
    int temp;
    cin >> temp;
    a[0] = temp;
    for(int i=1; i<n; i++)
    {
        cin >> temp;
        a[i] = a[i-1] + temp;
    }

    long long int sum = a[n-1];
    long long int min = abs(2*a[0],sum);
    //cout << sum << "\n";

    long long int temps;
    int m = n-1;
    for(int i=0; i<m; i++)
    {
        temps = abs(2*a[i], sum);
        //cout << temps << "\n";
        if(temps < min) min = temps;
    }

    cout << min << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, t, x, y, nt, nx, ny;
	cin >> n;
	nt = nx = ny = 0;
	bool f = 0;
	for (int i = 0; i < n; i++) {
		cin >> t >> x >> y;
		int T = t - nt, X = abs(x - nx), Y = abs(y - ny);
		if (T < X + Y) {
			f = 1;
			break;
		}
		T -= X;
		if (T % 2 != Y % 2) {
			f = 1;
			break;
		}
		nt = t, nx = x, ny = y;
	}
	cout << (f ? "No" : "Yes") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, k; cin >> n >> k;
  int ans = 0;
  REP(i, n) {
    int x; cin >> x;
    ans += min(x*2, (k-x)*2);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "vector"
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main(void) {
  int N;
  cin >> N;
 
  vector<int> P(N);
  rep(i, N) {
    cin >> P[i];
  }
 
  int curMin = 1e9;
  int count = 0;
  rep(i, N) {
    curMin = min(curMin, P[i]);
    if (curMin == P[i]) {
      count++;
    }
  }
 
  cout << count << endl;
 
  return 0;
}


Measured memory_bytes: 1024
import sys
from collections import Counter
N, W = map(int, input().split())

dp = Counter()
dp[0] = 0

for _ in range(N):
    w, v = map(int, sys.stdin.readline().split())
    for k, x in dp.copy().items():
        if k + w <= W:
            dp[k + w] = max(dp[k + w], x + v)

print(max(dp.values()))

Measured memory_bytes: 134868
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<int,int>
const int M=100010;
const int MOD=1000000007;
const long long INF=1000000007;
using ll=long long;


//vars;
int W,H,ans=0,shortest_pass=0;
char s[55][55];

int BFS(){
	//前後左右に動くことを想定するため,
	//(x,y)を(x+dx[i],y+dy[i])に移動させることを考える.
	int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
	queue<P> que;
	//初期位置からの距離(distance)を調べる;
	int dist[55][55];
	//わかりやすさのため,初期位置を(0,0)ではなく(1,1)にした.
	//すべての点をINF(=未訪であるというフラグ)にする.
	rep(j,1,H+1)rep(i,1,W+1)dist[i][j]=INF;
	//最初の点をスタートでありゴールと考えると,
	//dist[1][1]==1である.
	dist[1][1]=1;
	//(1,1)はすでに訪れた,という指標を立てる.
	que.push(P(1,1));
	//s[i][j]がゴール,もしくはゴールに行けないと
	//わかったときに終了する.
	while(que.size()){ 
		P p=que.front();
		que.pop();
		rep(i,0,4){
			//まず(1,1)の前後左右を調べる.
			int next_x=p.first+dx[i];
			int next_y=p.second+dy[i];
			if(s[next_x][next_y]=='.'&&
				next_x>0&&next_x<=W&&
				next_y>0&&next_y<=H&&
				dist[next_x][next_y]==INF){
				que.push(P(next_x,next_y));
				dist[next_x][next_y]=dist[p.first][p.second]+1;
			}
		}
	}
	return dist[W][H];
}

int main() {
	//input;
	cin>>H>>W;
	rep(j,1,H+1)rep(i,1,W+1){
		cin>>s[i][j];
		//'.'の点を数える.
		if(s[i][j]=='.')ans++;
	}

	//output;
	shortest_pass=BFS();
	//ゴールに行けないとき,dist[W][H]は更新されず
	//INFのままなので,"-1"を出力する.
	if(shortest_pass==INF)cout<<"-1"<<endl;
	//ゴールに行けるとき、その最短コース以外の'.'は
	//全て'#'にしても問題ない.
	else cout<<ans-shortest_pass<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x,n,p[101],num[110]={0};
    cin>>x>>n;
    rep(i,n) cin>>p[i],num[p[i]]=1;
    int ans=0;
    rep(i,101){
        if(num[i+1]==0&&abs(x-i-1)<abs(ans-x)) ans=i+1;
    }
    cout<<ans;
}

Measured memory_bytes: 3668
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main() {
	string card, card_next;
	int m;
	int h;

	while(1) {
		getline(cin, card);
		if(card == "-") break;
		scanf("%d", &m);
		int i = 0;
		char nl;
		for(i = 0; i < m; i++) {
			scanf("%d%c", &h, &nl);
			card_next = card.substr(h, card.size()) + card.substr(0, h);
			card = card_next;
		}
		cout << card << endl;
	}
		
	return 0;
}

Measured memory_bytes: 3220
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>

using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  string s;
  cin >> s;
  if (s == "ABC"){
    cout << "ARC\n";
  }
  else{
    cout << "ABC";
  }
  return 0;
}

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

int main() {
    // エラトステネスのふるい
    int MAX = 101010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }

    // 2017-like 数かどうか
    vector<int> a(MAX, 0);
    for (int i = 0; i < MAX; ++i) {
        if (i % 2 == 0) continue;
        if (is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
    }

    // 累積和
    vector<int> s(MAX+1, 0);
    for (int i = 0; i < MAX; ++i) s[i+1] = s[i] + a[i];

    // クエリ処理
    int Q; cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int l, r;
        cin >> l >> r;
        ++r;

        cout << s[r] - s[l] << endl;
    }
}


Measured memory_bytes: 1792
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <memory>
#include <numeric>
#include <type_traits>

using namespace std;

#define rep(i,n) for (int (i)=0;(i)<(n);i++)
typedef long long ll;
const int MAXV = 1e9;



int main(){
  int a[5];
  int ans;
  rep(i,5){
    cin >> a[i];
    if (a[i] != i+1)
    ans = i+1;
  }
  cout << ans;


  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;



int main() {
    string s;
    cin >> s;
    int ans = 0;
    if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) ans= 1;
    if(s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) ans= 1;
    if(s[0] == s[3] && s[2] == s[1] && s[0] != s[2]) ans= 1;
    if(ans) cY
    else cN
}



Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int sch[4][3][10] ={},n,b,f,r,v;
    scanf("%d\n",&n);
    for(int i=0;i<n;i++){
        scanf("%d %d %d %d\n",&b,&f,&r,&v);
        sch[b-1][f-1][r-1] += v;
    }
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int a=0;a<10;a++){
                printf(" %d",sch[i][j][a]);
            }
        printf("\n");
        }
    if(i != 3)
    printf("####################\n");
    }
    return 0;
}


Measured memory_bytes: 2060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int h = Integer.parseInt(str[0]);
		int w = Integer.parseInt(str[1]);

		String matrix[][] = new String[h][w];

		for (int i = 0; i < h; i++) {
			str = br.readLine().split("");
			for (int j = 0; j < w; j++) {
				matrix[i][j] = str[j];
			}
		}

		String ans[][] = new String[h][w];

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

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (matrix[i][j].equals(".")) {
					int count = 0;
					for (int k = 0; k < 8; k++) {
						int nx = j + dx[k];
						int ny = i + dy[k];

						if (nx >= 0 && nx < w && ny >= 0 && ny < h) {
							if (matrix[ny][nx].equals("#")) {
								count++;
							}
						}
					}
					ans[i][j] = String.valueOf(count);
				} else {
					ans[i][j] = "#";
				}
			}
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				System.out.print(ans[i][j]);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 34676
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    x, y = LI()

    if abs(x) <= abs(y):
        cnt = abs(y) - abs(x)
        if x >= 0:
            if y < 0:
                cnt += 1
        else:
            if y >= 0:
                cnt += 1
            else:
                cnt += 2
    else:
        cnt = abs(x) - abs(y)
        if x <= 0:
            if y > 0:
                cnt += 1
        else:
            if y <= 0:
                cnt += 1
            else:
                cnt += 2

    return cnt


print(main())


Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;
const ll INF = ll(1e18)+1;

int main(){
   ll n, k;
   cin >> n >> k;
   cout << min(k-n%k, n%k) << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main() {
	ll a, b, c, cnt = 0;
	cin >> a >> b >> c;
	for (int i = 1; i <= c; i++) {
		if (c%i==0&&i >= a && i <= b)cnt++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const int INF = 1<<29;

int N,A,B,C;
vector<int> l;

int dfs(int cur, int a, int b, int c){
    if(cur == N){
        if(min(a, min(b, c)) > 0) return abs(a-A)+abs(b-B)+abs(c-C)-30;
        else return INF;
    }

    int ret0 = dfs(cur+1, a, b, c);
    int ret1 = dfs(cur+1, a+l[cur], b, c)+10;
    int ret2 = dfs(cur+1, a, b+l[cur], c)+10;
    int ret3 = dfs(cur+1, a, b, c+l[cur])+10;

    return min(min(ret0, ret1), min(ret2, ret3));
}

int main(){
    cin >> N >> A >> B >> C;
    for(int i=0; i<N; i++){
        int a; cin >> a;
        l.push_back(a);
    }

    cout << dfs(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int A, B;

int main() {
	cin >> A >> B;
	if (A % 2 != B % 2) {
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		cout << (A + B) / 2 << endl;
	}
}

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

using namespace std;

int main()
{
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;

	vector<int> A(N);
	for (auto &x : A) {
		cin >> x;
	}
	A.push_back(X);

	vector<int> B(M);
	for (auto &y : B) {
		cin >> y;
	}
	B.push_back(Y);

	sort(A.begin(), A.end());
	sort(B.begin(), B.end());

	if (A.back() < B.front()) {
		cout << "No War" << endl;
	}
	else {
		cout << "War" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
 
using namespace std;
const int p=1e9+7;
inline ll qpow(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans*=a,ans%=p;
        a*=a,a%=p;
        n>>=1;
    }
    return ans;
}
ll C(ll m,ll n){
    ll ans=1;
    for(int i=1;i<=m;++i){
//        ll a=(n-i+1)%p;
//        ll b=i%p;
        ans=ans*(1ll*(n-i+1)*qpow(i,p-2)%p)%p;
    }
    return ans;
}
ll work(ll n){
	if(n<=4)return 0;
	ll ans=0;
	rep(i,0,11){
		if(n-5-i<0)continue;
		if((n-5-i)&1)continue;
		ans+=C(i,11)*C(15,(n-5-i)/2+15)%p;
	}

	return ans%p;
}
int main(){
//	freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;ll n;
	cin>>t;
	while(t--){
			cin>>n;
			cout<<1ll*work(n)<<endl;
	}

	
	
	
	


}

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

using namespace std;

int main() {
    int a, b, c, K;
    cin >> a >> b >> c >> K;

    if (K <= a) {
        cout << K;
    } else if (K <= a + b) {
        cout << a;
    } else {
        cout << a - (K - a - b);
    }
    return 0;
}



Measured memory_bytes: 3588
object Main extends App {
    val ary = scala.io.StdIn.readLine().split(" ")
    val l1 = List(1,3,5,7,8,10,12)
    val l2 = List(4,6,9,11)
    val l3 = List(2)
    val a = ary(0).toInt
    val b = ary(1).toInt
    
    if (isExist(l1,a,b) || isExist(l2,a,b) || isExist(l3,a,b)) {
        println("Yes")
    } else {
        println("No")
    }

    def isExist(list: List[Int], a: Int, b: Int): Boolean =
        list.exists(_==a) && list.exists(_==b)
}


Measured memory_bytes: 27196
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define mx INT_MAX
#define mn INT_MIN
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define itr set<int> :: iterator
const int N = 1e5+10;

ll dp[101][100001];

ll knapsack(int W, vector<int> wt, vector<int> val, int n){

    for(int i=0; i<=W; i++)  dp[0][i] = 0;
    for(int i=0; i<=n; i++) dp[i][0] = 0;

    for(int i=1; i<=n; i++){
        for(int j=1; j<=W; j++){
            if(wt[i-1] > j)
                dp[i][j] = dp[i-1][j];
            else
                dp[i][j] = max(val[i-1]+dp[i-1][j-wt[i-1]], dp[i-1][j]);
        }
    }

    return dp[n][W];
}

int main(){
    // ******* START HERE ******
    
    int n,W;
    cin>>n>>W;

    vector<int> val;
    vector<int> wt;
    for(int i=0; i<n; i++){
      int v, w;
      cin>>w>>v;
      val.pb(v);
      wt.pb(w);
    }

    ll res = knapsack(W, wt, val , n);
    cout<<res<<endl;

    // ***** END HERE ***** 
    return 0;
}

Measured memory_bytes: 82488
def Attention(n , s):

    ans = 10**9
    west = [0] * (n + 1)
    east = [0] * (n + 1)

    for i in range(n):
        if s[i] == 'W':
            west[i + 1] = west[i] + 1
            east[i + 1] = east[i]
        else:
            west[i + 1] = west[i]
            east[i + 1] = east[i] + 1

    for i in range(n):
        count = west[i] + (east[-1] - east[i + 1])
        ans = min(ans , count)

    return ans

def main():
    n = int(input())
    s = list(str(input()))
    print(Attention(n , s))

if __name__ == '__main__':
    main()

Measured memory_bytes: 20060
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout cout << fixed << setprecision(15)

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)       for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

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

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; string s; cin >> n >> s;
    int sl = s.length();
    rep(i, sl){
        int x = s[i] - 'A';
        x = (x + n) % 26;
        cout << (char)(x + 'A');
    }

    cout << endl;

return 0;
}

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

string S;
char F[10][10];

int main(){
    while(cin >> S && S!="#"){
        int a,b,c,d;
        vector<string> v;
        cin >> a >> b >> c >> d;
        a--; b--; c--; d--;
        string T = "";
        int h = 0;
        for(int i=0;i<S.size();i++){
            if(S[i]!='/') T += S[i];
            if(S[i]=='/' || i==S.size()-1){
                v.push_back(T);
                T = "";
                h++;
            }
        }
        assert(v.size()==h);
        int w = 0;
        for(int i=0;i<v.size();i++){
            int a = 0;
            for(int j=0;j<v[i].size();j++){
                if(v[i][j]=='b'){
                    F[i][a] = '#';
                    a++;
                }else{
                    int n = v[i][j]-'0';
                    for(int k=a;k<a+n;k++) F[i][k] = '.';
                    a += n;
                }
            }
            w = a;
        }
        F[a][b] = '.'; F[c][d] = '#';
        vector<string> ans;
        for(int i=0;i<h;i++){
            string now = "";
            int num = 0;
            for(int j=0;j<w;j++){
                if(F[i][j]=='#'){
                    char c = '0'+num;
                    if(num!=0) now += c;
                    now += 'b';
                    num = 0;
                }else num++;
            }
            if(num!=0){
                char c = '0'+num;
                now += c;
            }
            ans.push_back(now);
        }
        for(int i=0;i<ans.size();i++) cout << ans[i] << (i!=ans.size()-1? "/":"\n");
    }
}


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

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

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

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

    dp[0] = 0;
    dp[1] = dp[0] + abs(h[0] - h[1]);
    for (int i = 2; i < N; i++)
    {
        dp[i] = dp[i - 1] + abs(h[i - 1] - h[i]);
        chmin(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]));
    }

    cout << dp[N - 1] << endl;
}


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

#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/

using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

map<string, int> memo;
int main() {
	//sort(a.begin(),a.end());
	int h, n;
	cin >> h >> n;
	vector<int> a(n);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ans += a[i];
	}

	if (h > ans) {
		cout << "No";
	}
	else {
		cout << "Yes";
	}
	return 0;
}









Measured memory_bytes: 640