akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        var (N, K) = ReadTuple<int,int>();
        var S = RString().ToCharArray();
        S[K - 1] = (char)(S[K - 1] + 'a'-'A');
        WriteLine(string.Join("",S));
    }
}



class Scanner
{
    public static string RString() => Console.ReadLine();
    public static int RInt() => ReadTuple<int>();
    public static long RLong() => ReadTuple<long>();
    public static double RDouble() => ReadTuple<double>();

    public static string[] RStrings() => Console.ReadLine().Split();
    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();

    public static T1 ReadTuple<T1>()
    {
        var r = RString();
        var r1 = (T1)Convert.ChangeType(r, typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadTuple<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadTuple<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}


Measured memory_bytes: 27644
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
using namespace std;
int main()
{
  int N,K,Q,a;
  cin>>N>>K>>Q;
  vector<int> game(N+1,K);
  rep(i,Q){cin>>a;game.at(a-1)++;}
  rep(i,N){(game.at(i)-Q>0)?cout<<"Yes\n":cout<<"No\n";}
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#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++)
#define FORR(i, m, n) for(int i=m; i>=n; i--)
#define INF 1999999999
#define ll long long
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;

#ifdef INPUT
stringstream input(R"(
4 54
)");
#define cin input
#endif

int main()
{
	int a, b;
	cin >> a >> b;
	cout << a + b/2 << endl;
}

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

size_t combination(size_t n, size_t k) {
    if (n < k) {
        return 0;
    }
    size_t ns = 1, ks = 1;
    for (; k > 0; k--, n--) {
        ns *= n;
        ks *= k;
    }
    return ns / ks;
}

size_t count(const string& s, size_t i, int k) {
    if (i == s.size() && k != 0) {
        return 0;
    }
    if (k == 0) {
        return 1;
    }
    int topNum = s[i] - '0';
    assert(topNum != 0);
    size_t next = i + 1;
    while (next < s.size() && s[next] == '0') {
        next++;
    }
    size_t restSize = s.size() - i - 1;
    return pow(9, k) * combination(restSize, k)
        + (topNum - 1) * pow(9, k - 1) * combination(restSize, k - 1)
        + count(s, next, k - 1);
}

int main() {
    string s;
    int k;
    cin >> s >> k;
    cout << count(s, 0, k) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  int n;
  cin >> n;
  V<int> f(n);
  rep(i, n) {
    int p = 0;
    rep(j, 10) {
      p <<= 1;
      int b;
      cin >> b;
      p += b;
    }
    f[i] = p;
  }
  V<V<ll>> p(n, V<ll>(11));
  rep(i, n) rep(j, 11) cin >> p[i][j];

  ll ans = -1e10;
  for (int i = 1; i < 1 << 10; i++) {
    ll val = 0;
    rep(j, n) {
      int idx = __builtin_popcount(i & f[j]);
      val += p[j][idx];
    }
    ans = max(ans, val);
  }
  cout << ans << endl;
}


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

typedef long long LL;

const int N = 50;
const int M = 250;

bool mat[N][N];

int n, m, s;
LL mod;

LL pow_mod(LL x, int p){
    LL s = 1;
    while(p){
        if(p & 1)   s = s * x % mod;
        x = x * x % mod;
        p >>= 1;
    }
    return s;
}

int query(int a, int b, int c, int d){
    printf("? %d %d %d %d\n", a, b, c, d);
    fflush(stdout);
    int x;
    scanf("%d", &x);
    return x;
}

void solve(int x1, int x2, int y1, int y2, int div, int s){
    if(s == 0 || x1 > x2 || y1 > y2)  return;
    int area = (x2 - x1 + 1) * (y2 - y1 + 1);
    if(area == s){
        for(int i=x1; i<=x2; i++){
            for(int j=y1; j<=y2; j++){
                mat[i][j] = 1;
            }
        }
        return;
    }
    if(x1 == x2 && div){
        div ^= 1;
    } else if(y1 == y2 && !div){
        div ^= 1;
    }
    if(div){
        int mid = x1 + x2 >> 1;
        int ans = query(x1, y1, mid, y2);
        solve(x1, mid, y1, y2, 1^div, ans);
        solve(mid+1, x2, y1, y2, 1^div, s - ans);
    } else {
        int mid = y1 + y2 >> 1;
        int ans = query(x1, y1, x2, mid);
        solve(x1, x2, y1, mid, 1^div, ans);
        solve(x1, x2, mid+1, y2, 1^div, s - ans);
    }
}

int main(){
    while(~scanf("%d %d %d %lld", &n, &m, &s, &mod)){
        memset(mat, 0, sizeof(mat));
        solve(0, n-1, 0, m-1, 1, s);
        LL ans = 0;
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(mat[i][j]){
                    ans = (ans + pow_mod(2, i*m+j)) % mod;
                }
            }
        }
        printf("! %lld\n", ans);
        fflush(stdout);
    }
    return 0;
}


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

int c[10][10];
int H, W, A, ans;

int main(){
	cin>>H>>W;
	for(int i = 0; i < 10; i ++)
		for(int j = 0; j < 10; j ++)cin>>c[i][j];
		
	for(int k = 0; k < 10; k ++)	
		for(int i = 0; i < 10; i ++)
			for(int j = 0; j < 10; j ++)
				if(c[i][j] > c[i][k] + c[k][j])
					c[i][j] = c[i][k] + c[k][j];
					
	for(int i = 0; i < H; i ++)
		for(int j = 0; j < W; j ++){
			cin>>A;
			if(A >= 0)ans += c[A][1];
		}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long N,ans=LONG_MAX,i;
int main(){
  cin>>N;
  for(i=1;i*i<=N;i++)if(N%i==0)ans=min(ans,max((long)log10(i)+1,(long)log10(N/i)+1));
  cout<<ans<<endl;
}


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

#define int long long
#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 REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vec;
typedef vector<P> pvec;
typedef vector<vector<int>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<int> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<int,vector<int>,greater<int>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const ll INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001); // 10^(-10)

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec G(nmax);





void solve4ts()
{
    
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double x=h/(double)12;
    double y=m/(double)60;
    x*=360;y*=360;
    x+=30*(m/60);
    double sa=abs(x-y);
    sa=min(sa,360-sa);
    double kd=2*PI*sa/360;
    cout<<sqrt(a*a+b*b-2*a*b*cos(kd))<<endl;
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve4ts();
}

Measured memory_bytes: 7840
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
	T f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 100003, M = N << 1;
const string ss[] = {"dream", "dreamer", "erase", "eraser"};

char s[N];
bool dp[N];

int main()
{
	//File("");
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	dp[0] = true;
	for (int i = 5; i <= n; i+=1)
		for (int j = 0; j < 4; j+=1)
			if (i >= ss[j].size())
			{
				bool ok = true;
				for (int k = i - ss[j].size() + 1; k <= i; k+=1)
					if (ss[j][k - (i - ss[j].size() + 1)] != s[k]) ok = false;
				if (ok) dp[i] |= dp[i - ss[j].size()];
			}
	if (dp[n]) puts("YES");
	else puts("NO");
	return 0;
}


Measured memory_bytes: 3880
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC
{
    class ProgramC
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            var list = new int[3, n];
            for (var i = 0; i < n; i++)
            {
                var inputs = Console.ReadLine().Split(" ");
                list[0, i] = int.Parse(inputs[0]);
                list[1, i] = int.Parse(inputs[1]);
                list[2, i] = int.Parse(inputs[2]);
            }

            var dp = new int[3, n];
            dp[0, 0] = list[0, 0];
            dp[1, 0] = list[1, 0];
            dp[2, 0] = list[2, 0];

            for (var i = 1; i < n; i++)
            {
                for (var j = 0; j < 3; j++)
                {
                    var j1 = (j + 1) % 3;
                    var j2 = (j + 2) % 3;
                    dp[j, i] = list[j, i] + Math.Max(dp[j1, i - 1], dp[j2, i - 1]);
                }
            }

            var result = 0;
            for (var i = 0; i < 3; i++)
            {
                result = Math.Max(dp[i, n - 1], result);
            }

            Console.WriteLine(result);
        }
    }
}


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


void solve(long long N, long long R){
    if(N<10){
        cout << R + 100*(10-N) << endl;
        return;
    }
    cout << R << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long R;
    scanf("%lld",&R);
    solve(N, R);
    return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<long>v;
    while(n--){
        long a;
        cin>>a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    long res = v[0];
    for(int i=1;i<v.size();i++){
        res = __gcd(res,v[i]);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <string>
#define MAX_N 100000
using namespace std;

int dp[MAX_N+1];

int main() {
  int N,Q; cin >> N >> Q;
  string S; cin >> S;
  vector<int> l(Q), r(Q);
  for (int i=0; i<Q; ++i) cin >> l[i] >> r[i];

  dp[0] = 0;
  for (int j=0; j<N-1; ++j) {
    dp[j+1] = (S[j] == 'A' && S[j+1] == 'C') ? dp[j]+1 : dp[j];
  }

  for (int i=0; i<Q; ++i) {
    cout << (dp[r[i]-1] - dp[l[i]-1]) << endl;
  }
}


Measured memory_bytes: 2176
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll n, a, b, c;

    ll ans = INF;
    ll ans1 = INF;

    cin >> n >> a >> b >> c;

    vector<ll> l(n);

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

    ll al, bl, cl;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (j == i)
            {
                continue;
            }

            for (int k = 0; k < n; k++)
            {
                if (j == k || k == i)
                {
                    continue;
                }
                
                for (int x = 0; x < 32; x++)
                {
                    for (int y = 0; y < 32; y++)
                    {
                        al = l[i], bl = l[j], cl = l[k];
                        ll res = 0;

                        for (int z = 0, count = 0; z < n; z++)
                        {
                            if (z == i || z == j || z == k)
                            {
                                continue;
                            }

                            res += 10;

                            if (x & (1 << count))
                            {
                                if (y & (1 << count))
                                {
                                    al += l[z];
                                }
                                else
                                {
                                    bl += l[z];
                                }
                            }
                            else
                            {
                                if (y & (1 << count))
                                {
                                    cl += l[z];
                                }
                                else
                                {
                                    res -= 10;
                                }
                            }

                            count++;
                        }

                        ans = min(ans, res + abs(a - al) + abs(b - bl) + abs(c - cl));
                    }
                }
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename T> void vdeb(vector<T> v){
    cout << "#vdebug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    int n;
    ll a[10010], b[10010];
    cin >> n;
    rep(i, n){
        cin >> a[i];
    }
    rep(i, n){
        cin >> b[i];
    }

    ll a_than_b_sum = 0, b_than_a_sum = 0;
    rep(i, n){
        if(a[i] > b[i]) a_than_b_sum += a[i] - b[i];
        else if(a[i] < b[i]) b_than_a_sum += (b[i] - a[i]) / 2;
    }

    ans(a_than_b_sum <= b_than_a_sum);

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,m,q,a[55],b[55],c[55],d[55],ans,cn[55];
inline void dfs(int p,int x)
{
	if(p==n)
	{
		int hs=0;
		for(int i=0;i<q;i++)
		{
			if(cn[b[i]]-cn[a[i]]==c[i])
			{
				hs+=d[i];
			}
		}
		ans=max(ans,hs);
		return;
	}
	for(int i=x;i<=m;i++)
	{
		cn[p]=i;
		dfs(p+1,i);
	}
}
int main()
{
	cin>>n>>m>>q;
	for(int i=0;i<q;i++)
	{
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--;
		b[i]--;
	}
	dfs(0,1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf = 1e9+7;

const int MAX_N = 200010;
struct UnionFind {
    int par[MAX_N];    // 親ノードの番号
    int deph[MAX_N];   // ノードの深さ

    /* ↑以外に持っておくデータ
    // 例)木であるかどうか(bool値)を持つ場合
    // bool istree[MAX_N];
    */

    UnionFind(int n) {
        fill(par, par + MAX_N, -1);  // -1で初期化
        for (int i = 0; i<n; i++) {
            par[i] = i;
            deph[i] = 0;

            /* 持っておくデータにおいて初期化が必要な場合
            // istree[i] = true;
            */
        }
    }

    int find(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            return par[x] = find(par[x]);
        }
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            /* 同じグループに属しているときの処理
            // istree = false;
            */
            return;
        }
        if (deph[x] < deph[y]) {
            par[x] = par[y];
            /* ルートをyとする時の処理
            */
        }
        else {
            par[y] = par[x];
            if (deph[x] == deph[y]) deph[x]++;
            /* ルートをxとする時の処理
            */
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};
int N, K, L;
map<pair<int,int>,int> m;
int main() {
    cin>>N>>K>>L;
    UnionFind uf(N), uf2(N);
    REP(i,0,K){
        int p,q;
        cin>>p>>q;
        p--;q--;
        uf.unite(p,q);
    }
    REP(i,0,L){
        int p,q;
        cin>>p>>q;
        p--;q--;
        uf2.unite(p,q);
    }
    REP(i,0,N){
        m[{uf.find(i), uf2.find(i)}]++;
    }
    REP(i,0,N-1){
        cout<<m[make_pair(uf.find(i), uf2.find(i))]<<" ";
    }
    p(m[make_pair(uf.find(N-1), uf2.find(N-1))]);

    return 0;
}

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

int main(){
    long long n;
    cin >> n;
    long long n_sqrt = pow(n, 0.5);

    long long i,j;
    for (long long karen = n_sqrt; karen > 0; karen--){
        if (n % karen == 0){
            i = karen;
            j = n / karen;
            break;
        }
    }
    long long ans;
    ans = i + j - 2;

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

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

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;

int printYes() {
    cout << "Yes" << endl;
    return 0;
}

int printNo() {
    cout << "No" << endl;
    return 0;
}

int main(int argc, char const *argv[])
{
    long N, M;
    cin >> N >> M;
    
    vector<long> vec;
    rep(i, M) {
        long a;
        cin >> a;
        vec.push_back(a);
    }
    sort(ALL(vec));
    vector<long> sub;
    rep(i, M -1) {
        sub.push_back(vec[i + 1] - vec[i]);
    }
    sort(ALL(sub));
    long ans = 0;
    rep(i, M - N) {
        ans += sub[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2548
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    for(int i = a; i <= b*a; i+=a){
        if(i%b == c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int n = s.size();
	bool f = true;
	rep(i, 0, n){
		if(s[i] != s[0]) f = false;
	}
	if(f){
		cout << 0 << endl;
		return 0;
	}
	int ans = INF;
	rep(i, 0, n){
		char c = s[i];
		string t = s;
		rep(j, 0, n - 1){
			string nxt = "";
			rep(k, 0, t.size() - 1){
				if(t[k] == c || t[k + 1] == c) nxt += c;
				else nxt += t[k];
			}
			t = nxt;
			bool g = true;
			rep(k, 0, t.size()){
				if(t[k] != t[0]) g = false;
			}
			if(g){
				ans = min(ans, j + 1);
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int ans =0;
  for (int i = 0; i <= a; ++i) {
    
    for (int j = 0; j <= b; ++j) {
      for (int k = 0; k <= c; ++k) 
      {
      	if ((i * 500 + j * 100 + k * 50) == x )  ans += 1;
      }
    }
  }
  
  cout << ans << endl;
}
      

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

int main() {
   ll N;
   cin >> N;
   ll ans = N - 1;
   for (ll i = 2; i * i <= N; i++) {
       if (N % i == 0) {
           ans = min(ans, i + N / i - 2);
       }
   }
    cout << ans << endl;
}




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

int main(){
    char s[200000];
    gets(s);

    int v=0;
    int sum=0;

    while(1){
        sum+=s[v]-'0';
        v++;
        if(s[v]=='\0')break;
    }
    if(sum%9==0)printf("Yes");
    else printf("No");
}

Measured memory_bytes: 1780
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int[] distance = new int[5];
		for(int i = 0; i < 5; i++) {
			distance[i] = sc.nextInt();
		}
		int k = sc.nextInt();
		int count = 0;
		boolean flag = true;

		for(int i = distance.length - 1; i >= 0; i--) {
			for(int j = i-1; j >= 0; j--) {
//				System.out.println(k);
//				System.out.println(distance[i]);
//				System.out.println(distance[j]);
//				System.out.println();
				if(k < distance[i] - distance[j]) {
					flag = false;
					break;
				}
			}
			if(!flag) {
				break;
			}

		}
		if(flag) {
			System.out.println("Yay!");
		}
		else {
			System.out.println(":(");
		}

	}

}


Measured memory_bytes: 35620
# -*- coding: utf-8 -*-

N, M = map(int, input().split())
result = [-1] * N

for i in range(1, M + 1):
    s, c = map(int, input().split())
    if result[s - 1] == -1:
        result[s - 1] = c
    elif result[s - 1] == c:
        continue
    else:
        print(-1)
        exit(0)

if N != 1 and result[0] == 0:
    print(-1)
    exit(0)

if N == 1 and result[0] == -1:
    print(0)
    exit(0)

if N != 1 and result[0] == -1:
    result[0] = 1

for i in range(len(result)):
    if result[i] == -1:
        print(0, end="")
    else:
        print(result[i], end="")
print()


Measured memory_bytes: 3064
/**
*
* Author: MARS
* Lang: GNU C++14
*
**/

#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >

typedef unsigned long long ull;
typedef long double ldbl;
typedef long long ll;
typedef double dbl;

const ldbl E = 2.71828182845904523536;
const ldbl pi = acos(-1);
const dbl eps = 1e-9;
const ll mod = 1e9+7;
const ll inf = 1LL<<30;

/** /////////// ** Code ** /////////// **/

const int N=100100;

int main()
{
    int n;
    scanf("%d",&n);
    int ans=0;
    for(int i=0 ; i<n ; i++){
        int x;
        scanf("%d",&x);
        if(x&1) continue;
        while(x%2 == 0){
            ans++;
            x/=2;
        }
    }

    printf("%d",ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
struct block {
	int wt, st;
	long long val;
	bool operator < (const block &b) const {
		return wt+st < b.wt+b.st;
	}
};
int n;
block a[1010];
long long dp[20010];
long long o = 0;
int main () {
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> a[i].wt >> a[i].st >> a[i].val;
	}
	sort(a, a+n);
	for (int i=0; i<n; i++) {
		for (int j=min(a[i].st, 20005-a[i].wt); j>=0; j--) {
			dp[j+a[i].wt] = max(dp[j+a[i].wt], dp[j]+a[i].val);
			o = max(o, dp[j+a[i].wt]);
		}
	}
	cout << o << endl;
}

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

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define INFL 9000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;

vvc A;
vvi dist;
int W, H, K;

int dir[4][2] = { {0,1},{0,-1},{1,0},{-1,0} };

int main() {
	cin >> H >> W >> K;
	A = vvc(H);
	P start;
	rep(i, H) {
		A[i] = vc(W);
		string s;
		cin >> s;
		rep(j, W) {
			A[i][j] = s[j];
			if (A[i][j] == 'S') {
				start = mp(i, j);
			}
		}
	}

	dist = vvi(H);
	vvb visited(H);
	rep(i, H) {
		dist[i] = vi(W, INF);
		visited[i] = vb(W, false);
	}
	dist[start.first][start.second] = 0;
	visited[start.first][start.second] = true;
	
	queue<P> q;
	q.push(start);
	while (!q.empty()) {
		P pos = q.front();
		q.pop();
		if (dist[pos.first][pos.second] > K) {
			break;
		}
		rep(d, 4) {
			int x = pos.first + dir[d][0];
			int y = pos.second + dir[d][1];
			if (x < 0 || x >= H || y < 0 || y >= W || A[x][y] == '#')continue;
			if (!visited[x][y]) {
				dist[x][y] = dist[pos.first][pos.second] + 1;
				visited[x][y] = true;
				q.push(mp(x, y));
			}
		}
	}

	/*
	rep(i, H) {
		rep(j, W) {
			if (dist[i][j] <= K) {
				cout << dist[i][j];
			}
			else {
				cout << 'm';
			}
		}
		cout << endl;
	}
	*/

	int minimum = INF;
	rep(i, H) {
		rep(j, W) {
			if (dist[i][j] <= K) {
				minimum = min(minimum, min(min(i, H - 1 - i), min(j, W - 1 - j)));
			}
		}
	}

	cout << (minimum + K - 1) / K + 1 << endl;

	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	long long b;
	cin>>a>>b;
	for(int i=0;i<b;i++)
	{
		if(a[i]!='1')
		{
			cout<<a[i]<<endl;
			break;
		}
		if(i==b-1) cout<<1<<endl;
	}
	return 0;
}

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

int main() {
    int room[4][3][10] = {};
    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        room[b - 1][ f - 1][ r - 1] += v;
    }

    for (int b = 0; b < 4; b++) {
        for (int f = 0; f < 3; f++) {
            for (int r = 0; r < 10; r++) {
                cout << " " << room[b][f][r];
            }
            cout << endl;
        }
        if (b != 3) cout << "####################" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
//#include <algorithm>
//#include <vector>
//#include <string>
using namespace std;
//#include <stdio.h>

 
int main(void)
{
    long long a, b, c, x, y, ans = 0, nokori;
    cin >> a >> b >> c >> x >> y;
    nokori = abs(x - y);
    
    if(a + b < c * 2) 
        ans += min(x, y) * (a + b);
    else
        ans += min(x, y) * c * 2;
    
    if(x > y){
        if(a < c * 2)
            ans += a * nokori;
        else
            ans += c * 2 * nokori;
    }
    else{
        if(b < c * 2)
            ans += b * nokori;
        else
            ans += c * 2 * nokori;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef priority_queue<double, vector<double>, less<double> > QUE_double;
typedef priority_queue<int, vector<int>, less<int> > QUE_int;//lessは大きい順にならべるよ
const int MAX = pow(10, 5)+1;//+1しないとREになる(out of rangeになるんかな?? )
int main(){
  int N;
  cin >> N;
  string S, T;
  cin >> S >> T;
  string ans;
  
  for(int i=0; i<N; i++){
    ans.push_back(S.at(i));
    ans.push_back(T.at(i));
  }
  cout << ans << endl;
                     
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    a,b = LI()
    r = (a+b) // 2 + (a+b) % 2

    return r



print(main())




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

int main(){
    string S, T;
    cin >> S >> T;
    if(T.size() > S.size()){
        cout << "UNRESTORABLE";
        return EXIT_SUCCESS;
    }
    for(int i=S.size()-T.size(); i>=0; i--){
        bool flag = true;
        for(int j=0; j<T.size(); j++){
            if(S[i+j] != '?' && S[i+j] != T[j]){
                flag = false;
                break;
            }
        }
        if(flag){
            S.replace(i, T.size(), T);
            replace(S.begin(), S.end(), '?', 'a');
            cout << S;
            return EXIT_SUCCESS;
        }
    }
    cout << "UNRESTORABLE";
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
import sys

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

X,Y = (int(x) for x in input().split())

if (X+Y) % 3 != 0:
  print(0)
  sys.exit()

if (2*Y-X) % 3 == 0:
  n = (2*Y-X) // 3  
else:
  n = -1

if (2*X-Y) % 3 == 0:
  m = (2*X-Y) // 3
else:
  m = -1

if n < 0 or m < 0:
  print(0)
  sys.exit()
print(int(cmb(n+m,n)) % (10**9 +7))


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

int main() {
  int n; cin >> n;
  vector<int> vec(n);
  for (int i=0; i<n; i++) cin >> vec[i];
  
  bool can = true;
  for (int i=0; i<n; i++){
    if(vec[i]%2==0 && vec[i]%3!=0 && vec[i]%5!=0){
      can = false;
    }
  }
  
  if(can)cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long double pi=3.1415926535897;
int main()
{
	int a,b,n,m;
	cin>>a>>b>>n>>m;
	long double k=n*30,l=m*6;
	long double v=l/12;
	k+=v;
	long double ds=min(k-l,360-k+l);
	cout<<setprecision(20)<<sqrt(a*a+b*b-2*a*b*cos(ds*pi/180));
	return 0;
}

Measured memory_bytes: 4164
N,M = map(int,input().split())

class UnionFind:
    def __init__(self, n):
        #ノード数nの配列を作る
        #親の番号を格納する
        #-> 自分が根だった場合は、-(その集合のサイズ)とする
        #作るときはparentの値を全て-1にする
        #こうすると全てバラバラになる
        self.parent = [-1 for _ in range(n)]
        self.n = n
    def root(self, x):
        #要素xの根の番号を返す
        if self.parent[x] < 0:
            # 自分が根
            return x
        # 要素xの親を要素xの根に変えておく(付け替える)
        # 次の呼び出しが早くなる
        self.parent[x] = self.root(self.parent[x])
        return self.parent[x]
    def size(self, x):
        #要素xの所属するグループの頂点数を調べる
        #根のparentにサイズが格納されている
        return -self.parent[self.root(x)]
    def merge(self, x, y):
        #xとyを結合する
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        #大きい方(x)に小さい方(y)をくっつけたい
        if self.parent[x] > self.parent[y]:
            x, y = y, x
        self.parent[x] += self.parent[y]
        self.parent[y] = x
        return True
    def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue
        return self.root(x) == self.root(y)
    def family(self,x): # xが属する連結集合を返す
        return [i for i in range(self.n) if self.issame(i,x)]
    def maximum(self): # 連結最大集合を返す
        return self.family(self.parent.index(min(self.parent)))
    def all_family(self): # 根集合P, 子集合の集合C(C[P[i]]にはiを根とする子集合が入る)
        P = {} # 根のindexの集合はP.keys()で取得できる．これは根iが何番目の根かを返すdict
        now = 0
        for i in range(self.n):
            if self.parent[i] < 0:
                P[i] = now
                now += 1
        C = [[] for _ in range(len(P))] # P[i]
        for i in range(self.n):
            C[P[self.root(i)]].append(i)
        return P,C


p = list(map(int,input().split()))
UF = UnionFind(N)
for i in range(M):
    x,y = map(int,input().split())
    UF.merge(x-1,y-1)

ans = 0
_,C = UF.all_family()
for i in range(len(C)):
    S = C[i]
    T = [p[i]-1 for i in S]
    ans += len(set(S).intersection(set(T)))

print(ans)

Measured memory_bytes: 35292
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

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

    string s;
    ull k;
    cin >> s >> k;

    // 先頭から何文字が1なのかが重要。これをnとすると
    // k > n のとき答えは最初の1以外の数字になる

    // 1が連続する数を数える
    ull continuous_one = 0;
    char second_char;
    REP(i, s.length()) {
        if (s[i] != '1') {
            second_char = s[i];
            break;
        }
        continuous_one++;
    }

    if (k > continuous_one) {
        P(second_char);
    }
    else {
        P("1");
    }

    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 FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int k;
	cin >> k;
	if (k % 2 == 0 || k % 5 == 0) {
	  cout << -1 << endl;
	  return 0;
	}
	ll m = 10;
	k *= 9;
	FOR (i, 1, k + 1) {
	  ll t = 7 * (m - 1);
	  if (t % k == 0) {
		cout << i << endl;
		return 0;
	  }
	  m *= 10;
	  m %= k;
	}
	cout << -1 << endl;
    
    return 0;
}



Measured memory_bytes: 3656
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let x: Vec<u64> = (0..n).map(|_| read()).collect();
    let mut ans = 0;
    let mut d: Vec<u8> = Vec::new();
    let mut skip = false;

    if n == 1{
        println!("1");
        return;
    }


    for i in 0..n-1 {
        if x[i] < x[i+1]{ //増加
            d.push(1);
        }else if x[i] > x[i+1]{ //減少
            d.push(2);
        }else{
        }
    }

    let mut status = d[0]; //増加:1 減少：2

    //Down UpやUp Downの切れ目を探す。
    for i in 0..d.len() {
        if skip {
            status = d[i];
            skip = false;
            continue;
        }
        if status != d[i] {
            status = d[i];
            ans += 1;
            skip = true;
        }
    }

    //println!("{:?}", d);
    println!("{}", ans+1);
}

Measured memory_bytes: 4352
#include<stdio.h>
 
int main(void){
    int a[5],t,i,l;
     
    for(i=0;i<5;i++)scanf("%d",&a[i]);
     
    for(i=0;i<5-1;i++){
        for(l=i+1;l<5;l++){
            if(a[i]<a[l]){
                t=a[i];
                a[i]=a[l];
                a[l]=t;
            }
        }
    }
    printf("%d %d %d %d %d\n",a[0],a[1],a[2],a[3],a[4]);
     
    return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//

        int N, D;
        cin >> N;

        vector<int> vec(N);

        for (int i = 0; i < N; i++)
        {

                cin >> vec[i];
        }
        int ans = (int)1e9;
        for (int i = 0; i < N - 1; i++)
        {
                int S = 0;
                int T = 0;
                for (int j = 0; j <= i; j++)
                {
                        T += vec[j];
                }
                for (int k = i + 1; k < N; k++)
                {
                        S += vec[k];
                }
                ans = min(ans, abs(S - T));
        }

        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int n,x,d=0,count=0;
  cin >> n >> x;
  vector<int> v=input(n);
  rep(i,n){
    if(d<=x){
      count++;
    }
    d = d+v[i];
  }
  if(d<=x){count++;}
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }



int main(){
    LL k, a, b;
    cin >> k >> a >> b;
    LL ans = 0;
    if(b - a >= 2){
        LL req = a - 1;
        LL k2 = max<LL>(0, k - req);
        ans = 1 + req + (k2%2) + (k2/2) * (b - a);
    }else{
        ans = 1 + k;
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;

string s;

int main()
{
    cin >> s;
    if(s[0]=='0' && s[1]!='0'){
        if(s[2]=='0' && s[3]!='0'){
            cout << "AMBIGUOUS";
            return 0;
        } if(s[2]=='1' && s[3]<'3'){
            cout << "AMBIGUOUS";
            return 0;
        } else {
            cout << "MMYY";
            return 0;
        }
    }
    if(s[0]=='1' && s[1]<'3'){
        if(s[2]=='0' && s[3]!='0'){
            cout << "AMBIGUOUS";
            return 0;
        } if(s[2]=='1' && s[3]<'3'){
            cout << "AMBIGUOUS";
            return 0;
        } else {
            cout << "MMYY";
            return 0;
        }
    }
    if(s[2]=='0' && s[3]!='0'){
        if(s[0]=='0' && s[1]!='0'){
            cout << "AMBIGUOUS";
            return 0;
        } if(s[0]=='1' && s[1]<'3'){
            cout << "AMBIGUOUS";
            return 0;
        } else {
            cout << "YYMM";
            return 0;
        }
    }
    if(s[2]=='1' && s[3]<'3'){
        if(s[0]=='0' && s[1]!='0'){
            cout << "AMBIGUOUS";
            return 0;
        } if(s[0]=='1' && s[1]<'3'){
            cout << "AMBIGUOUS";
            return 0;
        } else {
            cout << "YYMM";
            return 0;
        }
    } else {
        cout << "NA";
        return 0;
    }
}

Measured memory_bytes: 384
a,b,c = gets.strip.split.map(&:to_i)
d = [a,b,c].sort
s = d[2]-d[0]
t = d[2]-d[1]
u = d[1]-d[0]
if u%2==0
  puts u/2+t
else
  puts (u+3)/2+t
end

Measured memory_bytes: 14324
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.Exception;
import java.lang.Integer;
import java.lang.StringBuffer;
import java.lang.System;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.math.BigDecimal;

public class Main {
    public static void main(String[] a) {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        double num[] = new double[6];
        String s, tmp[];
        double x, y;
        try {
            while((s = r.readLine()) != null) {
                tmp = s.split(" ");
                for (int i = 0; i < 6; i++) {
                    num[i] = Double.parseDouble(tmp[i]);
                }

                y = (num[0]*num[5] - num[2]*num[3])/(num[0]*num[4] - num[1]*num[3]);
                x = (num[2] - num[1]*y)/num[0];

                System.out.printf("%4.3f %4.3f\n", x, y);
            }
        } catch (Exception ex) {
            System.exit(0);
        }
    }
}

Measured memory_bytes: 15148
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, x[55];
int main(){
scanf("%i%i", &n, &m);
for(int i=0;i<m;i++) {scanf("%i%i", &a, &b); x[a]++; x[b]++;}
for(int i=1;i<=n;i++){printf("%i\n", x[i]);}
}

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

    string s, t;
    cin >> s >> t;

    vector<vector<int> > dp(s.size()+1, vector<int>(t.size()+1, 0));

    rep( i, s.size() ){
        rep( j, t.size() ) {
            if( s[i] == t[j] )  dp[i+1][j+1] = dp[i][j] + 1;
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
        }
    }

    string ans = "";
    int i = s.size(), j = t.size();
    while( i > 0 && j > 0 ) {
        if(dp[i][j] == dp[i][j-1]) j--;
        else if(dp[i][j] == dp[i-1][j] ) i--;
        else {
            ans = s[i-1] + ans;
            i--;
            j--;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
    string s;
    cin >> s;
    string ss;
    for (int i = 1; i <= s.size(); i++)
    {
        if (i % 2 != 0)
            ss += s[i - 1];
    }
    cout << ss << endl;
    return 0;
}

Measured memory_bytes: 3732