akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int n, k;
int a[100];
vector<int> v;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

    int ans = 0;
    for(int l=0;l<=n;l++)
    {
        for(int r=l;r<=n;r++)
        {
            int tmp = 0;
            int nk = k - (n - (r-l));
            if(nk < 0) continue;
            v.clear();
            for(int i=0;i<l;i++)
            {
                v.push_back(a[i]);
                tmp += a[i];
            }
            for(int i=r;i<n;i++)
            {
                v.push_back(a[i]);
                tmp += a[i];
            }
            sort(v.begin(), v.end());
            ans = max(ans, tmp);
            for(int i=0;i<min((ll)nk, (ll)v.size());i++)
            {
                tmp -= v[i];
                ans = max(ans, tmp);
            }
        }
    }
    cout << ans;
}

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

#define ll long long

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

    int a, b;
    string s;
    cin >> a >> b;
    cin >> s;

    for (int i = 0; i < s.length(); i++){
        if (i == a){
            if (s[i] != '-'){
                cout << "No" << endl;
                return 0;
            }
        }else {
            if (s[i] - '0' < 0 || s[i] - '0' > 9){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
using namespace std;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
#define pb push_back
template<class T> void print(const T& x){cout << x << endl;}
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;

int main(){
    int N, M; cin >> N >> M;
    vi food(M+1, 0);
    rep(i, 0, N){
        int k; cin >> k;
        rep(j, 0, k){
            int a; cin >> a;
            food[a]++;
        }
    }
    int cnt = 0;
    rep(i, 0, M+1){
        if(food[i] == N) cnt++;
    }
    cout << cnt << endl;
    return 0;
}




Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  
  vector<int> vec(K);
  for (int i = 0; i < K; i++) {
    cin >> vec.at(i);
  }
  
  for (int x = N; x < 100000; x++) {
    int tmp = x;
    set<int> s;
    
    while(tmp!=0) {
      s.insert(tmp%10);
      tmp /= 10;
    }
    
    bool flag = true;
    
    for (int i = 0; i < K; i++) {
      if(s.count(vec.at(i))) {
        flag = false;
      }
    }
    
    if(flag) {
      cout << x << endl;
      break;
    }
  }

}

Measured memory_bytes: 3580
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{
// }}}


signed main()
{
    i64 A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    A *= 100;
    B *= 100;

    i64 ansSum = 0;
    i64 ansSuger = 0;
    long double noudo = 0.0;

    for (int a = 0; a <= 3000; ++a) {
        if (A * a > F) continue;
        for (int b = 0; b <= 3000; ++b) {
            if (B * b + A * a > F) continue;
            for (int c = 0; c <= 3000; ++c) {
                for (int d = 0; d <= 3000; ++d) {
                    const i64 water = A*a + B*b;
                    const i64 suger = C*c + D*d;
                    const i64 sum = water + suger;
                    if (sum > F || sum <= 0) continue;
                    if (suger > (water / 100) * E) continue;

                    if (chmax(noudo, (long double)(suger * 100) / (long double)(sum))) {
                        ansSum = sum;
                        ansSuger = suger;
                    }
                }
            }
        }
    }

    if (ansSum == 0) {
        ansSum = A;
    }
    cout << ansSum << ' ' << ansSuger << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n, x;
	cin >> n >> x;
	int l[n];
	ll ans = 1;
	ll current = 0;
	REP(i, n) cin >> l[i];
	REP(i, n){
		current += l[i];
		if (current <= x) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
def getval():
    h,n = map(int,input().split())
    m = [list(map(int,input().split())) for i in range(n)]
    return h,n,m

def main(h,n,m):
    #DP for minimal mp needed to do h damage
    dp = [0]
    for i in range(h):
        update = 2**60
        for j in m:
            if j[0]>=(i+1):
                update = min(update,j[1])
            else:
                update = min(update,j[1]+dp[i+1-j[0]])
        dp.append(update)
    print(dp[h])    
                
if __name__=="__main__":
    h,n,m = getval()
    main(h,n,m)

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

using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

/*
)()( -> ()()()
))(( -> (())(())
sからペアを削っていき、残ったものを考える
*/

void solve(){;
    int n;
    cin >> n;
    string s;
    cin >> s;
    string t;
    t=s;
    rep(i,n){
        for(int j=1; j<n; j++){
            if(s[j-1]=='('&&s[j]==')'){
                s.erase(s.begin()+j-1, s.begin()+j+1);
            }
        }
    }
    int c1=0;
    int c2=0;
    //cout << s << endl;
    rep(i,s.size()){
        if(s[i]=='(') c1++;
        if(s[i]==')') c2++;
    }
    rep(i,c2){
        t = '(' + t;
    }
    rep(i,c1){
        t = t + ')';
    }
    cout << t << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1(i,n) for(int i=1;i<n;i++)
using namespace std;

int main(){
    int h,n,i,j;
    cin>>h>>n;
    std::vector< std::pair<int,int> > ab(n);
    rep(i,n){
        cin>>ab[i].first>>ab[i].second;
    }
    int maxa=0;
    rep(i,n){
        maxa=max(maxa,ab[i].first);
    }
    std::vector<int> dp(h+maxa,-1);
    dp[0]=0;
    rep_1(i,h+maxa){
        rep(j,n){
            if(dp[i]==-1){
                if(i-ab[j].first>-1){
                    if(dp[i-ab[j].first]!=-1){
                        dp[i]=dp[i-ab[j].first]+ab[j].second;
                    }
                }
            }else{
                if(i-ab[j].first>-1){
                    if(dp[i-ab[j].first]!=-1){
                        dp[i]=min(dp[i], dp[i-ab[j].first]+ab[j].second);
                    }
                }
            }
        }
    }

    int ans=2E31-1;
    rep(i,maxa){
        if(dp[i+h]!=-1){
            ans=min(ans, dp[i+h]);
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S;
    cin >> S;
    int count=0;
    for (int i = 0; i < S.size(); ++i) {
        if(S.at(i)=='1'){
            count++;
        }
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int N;
scanf("%d",&N);
int a[N];
for(int i=0;i<N;i++){
scanf("%d",&a[i]);
}
int b;
for(int i=1;i<N;i++){
if(a[0]>a[i]){
b=a[0];
a[0]=a[i];
a[i]=b;
}
}
for(int i=1;i<N;i++){
if(a[N-1]<a[i]){
b=a[N-1];
a[N-1]=a[i];
a[i]=b;
}
}
printf("%d",a[N-1]-a[0]);
}

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

int main() 
{
   char s[11];
   cin>>s;
   int prevcount=0,i;
   int count=0;
   int arrSize = sizeof(s)/sizeof(s[0]);
   for(i=0;i<arrSize;i++)
   {
       if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G')
       {
           count++;
       }
       else
       {
           if(count>prevcount)
           {prevcount=count;}
           count=0;
       }
   }
   if(count>prevcount)
   {prevcount=count;}
   
   
   cout<<prevcount;
   return 0;
   
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
string A , B; cin >> A >> B;
if(A.size() > B.size())
cout << "GREATER" << endl;
else if(A.size() < B.size())
cout << "LESS" << endl;

else{
  rep(i,A.size()){
    if(A[i] > B[i]){
      cout << "GREATER" << endl;
      exit(0);
    }
    else if(A[i] < B[i]){
      cout << "LESS" << endl;
      exit(0);
    }
  }
  if(A[A.size()-1] == B[B.size()-1]){
  cout << "EQUAL" << endl;
  }
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf=1ll<<50;
typedef pair<ll,ll> ii;
const int N=4e3+20;
ll d[N],n,m;
vector<ii> e[N];
bool neg[N];
void calc()
{
    fill(d,d+1+n,inf);
    memset(neg,false,sizeof(neg));
    d[1]=0;
    for(int k=1;k<n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<e[i].size();j++)
            {
                ll v=e[i][j].first,w=e[i][j].second;
                if(d[i]==inf)
                    continue;
                if(d[v]>d[i]+w)
                    d[v]=d[i]+w;
            }
        }
    }


    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<e[i].size();j++)
            {
                ll v=e[i][j].first,w=e[i][j].second;
                if(d[i]==inf)
                    continue;
                if(d[v]>d[i]+w)
                {
                    d[v]=d[i]+w;
                    neg[v]=true;
                }
                if(neg[i]==true)
                    neg[v]=true;
            }
        }
    }
    if(neg[n]==false)
        cout<<-d[n]<<endl;
    else
        puts("inf");

}
int main()
{
    while(cin>>n>>m)
    {
        for(int i=0;i<=n;i++)
            e[i].clear();
        ll u,v,w;
        while(m--)
        {
            cin>>u>>v>>w;
            e[u].push_back(ii(v,-w));
        }
        calc();
    }
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl

const ll INF = 100000000005;
int main() {
  int a, b, q;
  cin >> a >> b >> q;

  vector<ll> S, T;
  S.push_back(-INF);
  T.push_back(-INF);
  rep(i, a) {
    ll s;
    cin >> s;
    S.push_back(s);
  }
  rep(j, b) {
    ll t;
    cin >> t;
    T.push_back(t);
  }
  S.push_back(INF);
  T.push_back(INF);

  vector<ll> x(q);
  rep(k, q) cin >> x[k];

  rep(k, q) {
    auto ubs = upper_bound(all(S), x[k]);
    auto ubt = upper_bound(all(T), x[k]);

    ll ans = INF;
    for(ll s : {*(ubs - 1), *ubs})
      for(ll t : {*(ubt - 1), *ubt}) {
        ll D[2] = {abs(s - x[k]) + abs(t - s),
                   abs(t - x[k]) + abs(s - t)};
        for(ll d : D) ans = min(ans, d);
      }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3828
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    String s = sc.next();

    sc.close();

    String[] S = s.split("");

    String result = "Yes";

    for (int i = 0; i < S.length; i++) {
      if (i % 2 == 0) {
        if(!(S[i].equals("R")) && !(S[i].equals("U")) && !(S[i].equals("D"))) {
          result = "No";
          break;
        }
      } else {
        if(!(S[i].equals("L")) && !(S[i].equals("U")) && !(S[i].equals("D"))) {
          result = "No";
          break;
        }
      }
    } 

    System.out.println(result);

  }

}

Measured memory_bytes: 23636
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;
#define MAX_N 100000
#define INF 100000000000
ll dp[MAX_N];

int main()
{
	int n;
	cin>>n;
	int sum = 0;
	int *t = new int[n];
	rep(i,n){
		cin>>t[i];
		sum += t[i];
	}
	int m;
	cin>>m;
	pair<int,int> *drink = new pair<int,int>[m];
	rep(i,m){
		int no,t2;
		cin>>no>>t2;
		no--;
		drink[i].first = no;
		drink[i].second = t2;
	}
	rep(i,m){
		cout<< sum - t[drink[i].first] + drink[i].second<<endl;
	}
	return 0;
}



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

int main() {
 string alpha, beta  ;
  int a,b;
string u;
  cin >> alpha >> beta ;
  cin >> a >> b;
  cin >> u;
  if(alpha == u){
    cout << a-1 << " " << b ;
  }
  if(beta == u){
    cout << a << " " << b-1;
  }
 
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
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; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll countDigit(int n);

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	vector<ll>a(n);
	rep(i, n)cin >> a[i];
	sort(all(a));
	a.push_back(-100);
	ll cnt = 0;
	for (ll i = 0; i < n; i++) {
		if (a[i] != a[i + 1])cnt++;
	}
	cout << (cnt%2 == 1 ? cnt : cnt-1) << endl;
}




Measured memory_bytes: 1792
public class Main {
	public static void main(String args[]) {
System.out.print("1x1=1\n1x2=2\n1x3=3\n1x4=4\n1x5=5\n1x6=6\n1x7=7\n1x8=8\n1x9=9\n2x1=2\n2x2=4\n2x3=6\n2x4=8\n2x5=10\n2x6=12\n2x7=14\n2x8=16\n2x9=18\n3x1=3\n3x2=6\n3x3=9\n3x4=12\n3x5=15\n3x6=18\n3x7=21\n3x8=24\n3x9=27\n4x1=4\n4x2=8\n4x3=12\n4x4=16\n4x5=20\n4x6=24\n4x7=28\n4x8=32\n4x9=36\n5x1=5\n5x2=10\n5x3=15\n5x4=20\n5x5=25\n5x6=30\n5x7=35\n5x8=40\n5x9=45\n6x1=6\n6x2=12\n6x3=18\n6x4=24\n6x5=30\n6x6=36\n6x7=42\n6x8=48\n6x9=54\n7x1=7\n7x2=14\n7x3=21\n7x4=28\n7x5=35\n7x6=42\n7x7=49\n7x8=56\n7x9=63\n8x1=8\n8x2=16\n8x3=24\n8x4=32\n8x5=40\n8x6=48\n8x7=56\n8x8=64\n8x9=72\n9x1=9\n9x2=18\n9x3=27\n9x4=36\n9x5=45\n9x6=54\n9x7=63\n9x8=72\n9x9=81");
				System.out.println();
}
}


Measured memory_bytes: 24000
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	static PrintWriter out = new PrintWriter(System.out);
	static Scanner sc = new Scanner(System.in);
	static int INF = 2 << 20;
	static Node[] node;
	public static void main(String[] args) {
		while(true) {
			int n = sc.nextInt();
			if(n == 0)break;
			node = new Node[101];
			for(int i = 0; i < 101; i++) {
				node[i] = new Node(i);
			}
			for(int i = 0; i < n; i++) {
				int a = sc.nextInt();
				int b = sc.nextInt();
				node[a].to.add(node[b]);
				node[b].to.add(node[a]);
			}
			int ans = 0;
			boolean[] tmp = new boolean[101];
			for(int i = 1; i < 101; i++) {
				if(node[i].to.size() == 0) continue;
				tmp[i] = true;
				ans = Math.max(ans,dfs(i,tmp,1));
				tmp[i] = false;
			}
			System.out.println(ans);
		}
	}
	static int dfs(int now, boolean[] use, int count) {
		int ret = count;
		for(int i = 0; i < node[now].to.size(); i++) {
			int tmp = node[now].to.get(i).id;
			if(use[tmp]) continue;
			use[tmp] = true;
			ret = Math.max(ret, dfs(tmp,use,count+1));
			use[tmp] = false;
		}
		return ret;
	}
	static class Node {
			int id;
			ArrayList<Node> to = new ArrayList<Node>();
			Node(int a) {
				id = a;
			}
	}

}

Measured memory_bytes: 30764
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>

#define CK(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long  LLINF = 1e15;

using namespace std;


#include <string>
#include <cctype>
typedef string::const_iterator State;

int expression(State &);
int term(State &);
int number(State &);
int factor(State &);

// ?????????????????????????????????????????????????????????????????????
int expression(State &begin) {
    int ret = term(begin);
    for (;;) {
        if (*begin == '+') {
            begin++;
            ret += term(begin);
        } else if (*begin == '-') {
            begin++;
            ret -= term(begin);
        } else {
            break;
        }
    }
    return ret;
}

// ?????????????????????????????????????????????????????????????????????
int term(State &begin) {
    int ret = factor(begin);
    for (;;) {
        if (*begin == '*') {
            begin++;
            ret *= factor(begin);
        } else if (*begin == '/') {
            begin++;
            ret /= factor(begin);
        } else {
            break;
        }
    }
    return ret;
}

// ??¬??§?????°???????????????????????????????????????????????????
int factor(State &begin) {
    if (*begin == '(') {
        begin++; // '('????£???°??????
        int ret = expression(begin);
        begin++; // ')'????£???°??????
        return ret;
    } else {
        return number(begin);
    }
}

// ??°??????????????????????????????????????°????????????
int number(State &begin) {
    int ret = 0;
    while (isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    return ret;
}



int main(){
  int n;
  cin>>n;
  REP(i,0,n){
    string s;
    cin>>s;
    State begin = s.begin();
    int ans = expression(begin);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
const int maxn=200100;
int c[maxn],cnt_color;
int n;
void No(){
	puts("No");
	exit(0);
}
void Yes(){
	puts("Yes");
	for(int i=1;i<=n*2;i++)
		printf("%d ",c[i]);
	printf("\n");
	exit(0);
}
char str[maxn];
vector<int> vec[maxn];
int num;
void get_vec(){
	int las=0;
	for(int i=0;i<=n*2;i++){
		if(str[i]=='1'){
			if(las==0){
				num++;
				vec[num].push_back(i);
				vec[num].push_back(i+1);
			}
			else
				vec[num].push_back(i+1);
			las=1;
		}
		else
			las=0;
	}
}
int stk[maxn],top;
void color_all(){
	int las=0;
	for(int i=1;i<=n*2;i++){
		if(!c[i]){
			if(!las) c[i]=++cnt_color;
			else c[i]=cnt_color;
			las^=1;
		}
	}
}
void get_ans(){
	if(top%4!=0) No();
	for(int i=1;i<=top;i+=4){
		c[stk[i]]=c[stk[i+2]]=++cnt_color;
		c[stk[i+1]]=c[stk[i+3]]=++cnt_color;
	}
	color_all();
	Yes();
}
void get_stk(){
	for(int i=1;i<=num;i++)
		if(vec[i].back()==n*2+1)
			swap(vec[i],vec[num]);
	int las;
	for(int i=1;i<=num;i++){
		if(i!=1) c[vec[i][0]]=c[las]=++cnt_color;
		for(int j=1;j<(int)vec[i].size()-1;j++)
			stk[++top]=vec[i][j];
		las=vec[i].back();
	}
	get_ans();
}
void get_pos(int &p1,int &p2){
	p1=0,p2=0;
	for(int i=1;i<=n;i++){
		if((int)vec[i].size()>2){
			if(p1==0) p1=i;
			else if(p2==0) p2=i;
			else break;
		}
	}
}
void trans(){
	int p1,p2,x;
	get_pos(p1,p2);
	if(p2==0) No();
	if(vec[p1].front()==0&&vec[p2].back()==n*2+1)
		No();

	x=vec[p2].back();
	vec[p2].pop_back();

	c[vec[p1][1]]=c[vec[p2].back()]=++cnt_color;
	vec[p2].pop_back();

	for(int j=2;j<(int)vec[p1].size();j++)
		vec[p2].push_back(vec[p1][j]);
	vec[p1].resize(2);
	vec[p1][1]=x;
}
int main(){
//	freopen("G.in","r",stdin);
//	freopen("G.out","w",stdout);
	scanf("%d",&n);
	scanf("%s",str+1);
	str[0]='1',str[n*2]='1';
	int cnt=0;
	for(int i=1;i<=n*2;i++)
		if(str[i-1]=='1'&&str[i]=='1')
			cnt++;
	if(cnt&1) No();
	if(cnt==n*2){
		top=n*2;
		for(int i=1;i<=n*2;i++)
			stk[i]=i;
		get_ans();
		return 0;
	}
	get_vec();
	if(cnt%4==2)
		trans();
	get_stk();
	return 0;
}


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


int main()
{
    int n;

    cin >> n;

    int p[20];

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

    int count = 0;
   
    for (int j = 1; j < n - 1; j++) {

        if(    ( ( p[j-1] < p[j] ) && ( p[j] < p[j+1] ) )
            || ( ( p[j-1] > p[j] ) && ( p[j] > p[j+1]) ) ){
            count++;
        }

    }


    cout << count;


}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <random>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
long A[100001];
long B[100000];
void Calc(){
	int N = rei();
	for(int i=0;i<=N;i++){
		A[i] = rei();
	}
	for(int i=0;i<N;i++){
		B[i] = rei();
	}
	long ans = 0;
	for(int i=0;i<N;i++){
		long v = min(A[i],B[i]);
		ans += v;
		A[i] -= v;
		B[i] -= v;
		v = min(A[i+1],B[i]);
		ans += v;
		A[i+1] -= v;
		B[i] -= v;
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
long long dp[11][1010];// dp[i][j] := i個からjを作る組み合わせの数

int main()
{
  for(int i=0;i<10;i++)for(int j=0;j<=1000;j++)dp[i][j] = 0;
  
  dp[0][0] = 1;

  for(int i=0;i<=100;i++)
    {
      for(int j=9;j>=0;j--)	
	{
	  for(int k=0;k<=1000;k++)
	    {
	      if(dp[j][k] == 0)continue;
	      if(k+i>1000)continue;
	    
	      dp[j+1][k+i] += dp[j][k];
	    }
	}
    } 
  int n,s;
  while(cin >> n >> s,n|s)cout << dp[n][s] << endl;
  return 0;
}

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

/*
int sortup(const void *a, const void *b){
    return *(int*)a-*(int*)b ;
}
int sortdown(const void *a, const void *b){
    return *(int*)b-*(int*)a ;
}
    qsort (a,n,sizeof(long long),sortup);
    */
    
int main(void){
    char s[60],t[60];
    scanf("%s%s",s,t);
    int count=0,start=-1;
    for (int i=0; i<strlen(s); i++){
        count=0;
        for (int j=0; j<strlen(t); j++){
            if(s[i+j]==t[j] || s[i+j]=='?'){
                count++;
            }
        }
        if(count==strlen(t)){
            start=i;
        }
    }
    if (start==-1){
        printf("UNRESTORABLE\n");
        exit(0);
    }
    for (int i=0; i<strlen(t); i++){
        s[start+i]=t[i];
    }
    for (int i=0; i<strlen(s); i++){
        if (s[i]=='?'){
            s[i]='a';
        }
    }
    printf("%s\n",s);
	return 0 ;
}

Measured memory_bytes: 128
import time
n, a, b = map(int, input().split())
index=0
flag=1
start = time.time()
while True:
    if a == 1 and b == a+1 and index % 2 == 0:
        print("Borys")
        break
    elif b == n and b == a+1 and index % 2 == 1:
        print("Alice")
        break
    if b == a+1:
        flag=0
    else:
        flag=1
    if flag:
        if index%2==0:
            a+=1
        else:
            b-=1
    else:
        if index%2==0:
            a-=1
        else:
            b+=1
    index+=1
    if time.time()-start > 1:
        print("Draw")
        break
    

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> 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 n;

int main(){
    
    cin >> n;
    vector<int>  b(n);
    REP(i,n){
        cin >> b[i];
        b[i]--;
    }
    int maxl=-1;
    vector<int> res;
    REP(i,n){
        maxl=-1;
        REP(j,b.size()){
            if(b[j]==j){
                maxl=j;
            }
        }
        if(maxl!=-1){
            res.push_back(maxl+1);
            b.erase(b.begin()+maxl,b.begin()+maxl+1);
        }else{
            put(-1);
            return 0;
        }
    }
    for(int i=n-1;i>=0;--i){
        put(res[i]);
    }
    return 0;
}


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

int main(void){
	int w,h;
	int n;
	while(cin>>w,w){
		cin>>h>>n;
		vector<vector<int> > maze(h+1,vector<int>(w+1,0));
		
		int x,y;
		for(int i = 0 ; i < n ; i ++){
			cin>>x>>y;
			maze[--y][--x] = -1;
		}
		for(int i = 0 ; i < h ; i ++)
			if(maze[i][0] != -1)maze[i][0] = 1;
			else break;
		for(int i = 0 ; i < w ; i ++)
			if(maze[0][i] != -1)maze[0][i] = 1;
			else break;
		for(int i = 1 ; i < h ; i ++){
			for(int j = 1 ; j < w ; j ++){
				if(maze[i][j] == -1)continue;
				maze[i][j] = max(0,maze[i-1][j]) + max(0,maze[i][j-1]);
			}
		}
		cout<<maze[h-1][w-1]<<endl;
	}
}

Measured memory_bytes: 1216
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int mod = 1_000_000_007;
        long[] A = new long[N];
        ArrayList<int[]> a_bin = new ArrayList<int[]>();
        for (int i=0;i<N;i++) {
            A[i] = Long.parseLong(sc.next());
            int[] a = new int[62];
            long tmp = A[i];
            for (int j=0;j<62;j++) {
                if ((tmp&1)==1) {
                    a[j] = 1;
                }
                tmp=tmp>>1;
            }
            // int[] b = new int[62];
            // for (int j=0;j<62;j++) {
            //     b[j] = a[61-j];
            // }
            a_bin.add(a);
            // System.out.println(Arrays.toString(a));
        }
        int[][] dp = new int[N+1][62];
        for (int i=0;i<N;i++) {
            for (int j=0;j<62;j++) {
                dp[i+1][j] = dp[i][j]+a_bin.get(i)[j];
            }
        }
        long ans = 0L;
        for (int i=0;i<N;i++) {
            for (int j=0;j<62;j++) {
                if (a_bin.get(i)[j]==0) {
                    ans = (ans + ((long)(1L<<j)%mod*((long)dp[N][j]-dp[i+1][j])%mod))%mod;
                } else {
                    ans = (ans + ((long)(1L<<j)%mod*((long)(N-1-i)-(dp[N][j]-dp[i+1][j]))%mod))%mod;
                }
                // if (0<=j && j<3) {
                //     System.out.print(dp[N-1][j]-dp[i][j]+" ");
                //     System.out.println((N-1-i)-(dp[N-1][j]-dp[i][j]));
                // }
            }
        }
        System.out.println(ans);
        // System.out.println(Arrays.deepToString(dp));
    }
}

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

using namespace std;

int main(){
int n,m; cin >> n >> m;
int ans[n],c[m],s[m],flag = 1;

for (int i = 1; i <= n; ++i)
{
  ans[i] = -1;
}
for (int i = 0; i < m; ++i) cin >> s[i] >> c[i];
for (int i = 0; i < m; ++i)
{
  if (ans[s[i]] ==-1) ans[s[i]] = c[i]; 
  else {
    if(ans[s[i]] != c[i]){
     flag = 0;
     break;
    }
  }
}
if (ans[1] == 0 && n!=1)
{
 flag = 0;
}

for (int i = 1; i <=n ; ++i)
{
 if (ans[i] == -1) {
  if (i==1 && n!=1)
  {
    ans[1] = 1; 
  }
  else if (i==1 && n==1)
  {
    ans[1] =0;
  }
  else ans[i] = 0; 
}
}

if (flag == 1)
{
for (int i = 1; i <= n; ++i)
{
 cout << ans[i];
}
}
else cout << -1;
  return 0;

}


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

int main(void){
    int n;long int sum = 0;
    cin >> n;
    long int a[n*3];
    for(long int i = 0;i < n*3;i++)cin >> a[i];
    sort(a,a+(n*3),greater<long int>());
    for(int i = 0;i < n;i++){
        sum += a[2*i+1];
    }
    cout << sum << endl;
}

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

using namespace std;

#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;

ll k;
string s;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> s >> k;
  bool as = true;
  for (int i = 1; i < sz(s); i++)
    if (s[i] != s[0])
      as = false;
  if (as) {
    cout << (sz(s) * k) / 2 << "\n";
    return false;
  }
  int i = 0;
  int c[2] = {0, 0};
  while (i + 1 < sz(s) * k && i + 1 < 2 * sz(s)) {
    if (s[i % sz(s)] != s[(i + 1) % sz(s)])
      i++;
    else
      c[(i + 1) / sz(s)]++, i += 2;
  }
  if (k == 1)
    cout << c[0] << "\n";
  else
    cout << c[0] + c[1] * (k - 1) << "\n";
}


Measured memory_bytes: 256
H, W = map(int, input().split())
S = []
S.append(['#' for _ in range(W+2)])
for _ in range(H):
  s = input()
  s = '#' + s + '#'
  S.append([])
  for k in range(W+2):
    S[-1].append(s[k])
S.append(['#' for _ in range(W+2)])
b = 0
start = []
for h in range(1, H+1):
  for w in range(1, W+1):
    if S[h][w] == '.':
      c = 0
      b += 1
      if S[h+1][w] == '.':
        c += 1
      if S[h-1][w] == '.':
        c += 1
      if S[h][w+1] == '.':
        c += 1
      if S[h][w-1] == '.':
        c += 1
      if c == 1:
        start.append([h, w])
if len(start) == 0:
  for h in range(1, H+1):
    for w in range(1, W+1):
      if S[h][w] == '.':
        c = 0
        if S[h+1][w] == '.':
          c += 1
        if S[h-1][w] == '.':
          c += 1
        if S[h][w+1] == '.':
          c += 1
        if S[h][w-1] == '.':
          c += 1
        if c == 2:
          start.append([h, w])
#dfs 121ms
"""
def solve(nowh, noww, point):
  counter[nowh][noww] = point
  flag = True
  if counter[nowh+1][noww] > point + 1:
    solve(nowh+1, noww, point+1)
    flag = False
  if counter[nowh-1][noww] > point + 1:
    solve(nowh-1, noww, point+1)
    flag = False
  if counter[nowh][noww+1] > point + 1:
    solve(nowh, noww+1, point+1)
    flag = False
  if counter[nowh][noww-1] > point + 1:
    solve(nowh, noww-1, point+1)
    flag = False
  if flag:
    return 0
ans = 0
for item in start:
  original_counter = [[b for _ in range(W+2)] for _ in range(H+2)]
  for k in range(H+2):
    for j in range(W+2):
      if S[k][j] == '#':
        original_counter[k][j] = -1
  counter = original_counter
  solve(item[0], item[1], 0)
  anskouho = 0
  for h in range(1, H+1):
    for w in range(1, W+1):
      anskouho = max(anskouho, counter[h][w])
  ans = max(ans, anskouho)

print(ans)
"""
#bfs
def solve(now, point):
  nextlist = []
  for n in now:
    if counter[n[0]+1][n[1]] > point + 1:
      counter[n[0]+1][n[1]] = point + 1
      nextlist.append([n[0]+1, n[1]])
    if counter[n[0]][n[1]+1] > point + 1:
      nextlist.append([n[0], n[1]+1])
      counter[n[0]][n[1]+1] = point + 1
    if counter[n[0]-1][n[1]] > point + 1:
      nextlist.append([n[0]-1, n[1]])
      counter[n[0]-1][n[1]] = point + 1
    if counter[n[0]][n[1]-1] > point + 1:
      nextlist.append([n[0], n[1]-1])
      counter[n[0]][n[1]-1] = point + 1
  if len(nextlist) == 0:
    anskouho.append(point)
    return 0
  else:
    solve(nextlist, point+1)

anskouho = []
for item in start:
  original_counter = [[b for _ in range(W+2)] for _ in range(H+2)]
  for k in range(H+2):
    for j in range(W+2):
      if S[k][j] == '#':
        original_counter[k][j] = -1
  counter = original_counter
  counter[item[0]][item[1]] = 0
  solve([item], 0)
print(max(anskouho))


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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, M;
  priority_queue<ll> A;
  ll tmp_a;

  cin >> N >> M;
  REP(i, N) {
    cin >> tmp_a;
    A.push(tmp_a);
  }

  REP(i, M) {
    tmp_a = A.top();
    A.pop();
    A.push(floor(tmp_a / 2));
  }

  ll result = 0;
  REP(i, N){
    result += A.top();
    A.pop();
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vi vector<int>

int main(){

  int n;
  cin>>n;

  string s;
  cin>>s;
  
  int answer=1;
  
  for (int i=1;i<n;i++){
    if (s.at(i)!=s.at(i-1)){
      answer++;
    }
  }
  
  cout<<answer<<endl;
  
  
   
  
  


  
}



Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int[] list = new int[N + 1];
		int ans = 0;

		for (int i = 1; i < N+1; i++) {
			list[i] = sc.nextInt();
		}

		for (int i = 1; i < list.length; i++) {
			if (i == list[list[i]]) {
				ans++;
			}
		}

		System.out.println(ans/2);

	}

}


Measured memory_bytes: 59472
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <math.h>
#include <sstream>
#include <iomanip>
#define REP(i,n,s) for (int i = (s);i < (int)( n ); i++)
#define REP0(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define ll long long
using namespace std;

ll i,j;
const int MOD = 1000000000 + 7;

int main(){
    string n;
    string ans;
   

    cin>>n;

    if(n[n.size()-1]=='s'){
        ans=n+"es";
    }
    else{
        ans=n+"s";
    }
    
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int main() {
  string S; cin >> S;
  int N = S.length();
  ll ans = 0;
  for ( int bit = 0; bit < (1<<N-1); bit++ ) {
    ll sum = 0;
    ll a = S[0]-'0';
    for ( int i = 0; i < N-1; i++ ) {
      if ( bit&(1<<i) ) {
	sum += a;
	a = 0;
      }
      a = a*10+S[i+1]-'0';
    }
    ans += sum;
    ans += a;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int bfs(int s, vector<vector<int>> &g, vector<bool> &flg) {
    queue<int> que;
    que.push(s);
    flg[s] = true;
    int ret = 1;
    while(!que.empty()) {
        int now = que.front(); que.pop();
        for (auto v: g[now]) {
            if (flg[v]) continue;
            ++ret;
            flg[v] = true;
            que.push(v);
        }
    }
    return ret; 
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int ans = 0;
    vector<bool> flg(n, false);
    rep(i, n) {
        //cout << i << endl;
        if (!flg[i]) {
            ans = max(ans, bfs(i, g, flg));
        }
    }
    cout << ans << endl;
    return 0;
}


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

		long L = sc.nextLong();
		long R = sc.nextLong();
		long ans = 0;
		long minium = 2019;
		if( R-L < 2019 ){
			loop:for( long i=L; i<=R-1; i++ ){
				for( long j=i+1; j<=R; j++ ){
					ans = ((i%2019L)*(j%2019L))%2019L;
					minium = Math.min(ans,minium);
					if( minium==0 ){
						break loop;
					}
				}
			}
		}else{
			minium = 0;
		}
		System.out.println(minium);
	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

	          int A,B,C,D;
	          cin >> A >> B >> C >> D;

	          int d=min(B,D)-max(A,C);

	          cout << max(d,0) << endl;

	          return 0;
}


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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    double d, e;
    while(cin>>d>>e, d) {
        double ans = INF;
        for(int i=0; i<d; ++i) {
            ans = min(ans, abs(e-sqrt(i*i+(d-i)*(d-i))));
        }
        printf("%.10f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3100
import java.util.Scanner;

/**
 *
 * @author lenovo
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int x[] = new int[N];
        int move = 0;
        for (int i=0;i<N;i++){
            x[i] = sc.nextInt();
            if (x[i] > (K/2)){
                move += (K - x[i])*2;
            }else{
                move += x[i] * 2;
            }
        }
        System.out.println(move);
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define local
//if you find any bug in my code, please tell me.
int main()
{
#ifdef local
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    int w,a,b;
    cin>>w>>a>>b;
    if(a+w<b) printf("%d",b-a-w);
    else if(b+w<a) printf("%d",a-b-w);
    else printf("0");
    return 0;
}


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

int main(){
	char str[256],tmp[256],input[16];
	int num,cut,i,j,slen;
	
	while(1){
		fgets(str,sizeof str,stdin);
		if(str[0]=='-'){
			break;
		}
		
		slen=strlen(str);
		slen--;
		str[slen]='\0';
		
		
		fgets(input,sizeof input,stdin);
		sscanf(input,"%d",&num);
		for(i=0;i<num;i++){
			strcpy(tmp,str);
			fgets(input,sizeof input,stdin);
			sscanf(input,"%d",&cut);
			for(j=0;j<slen-cut;j++){
				str[j]=str[cut+j];
			}
			for(j=0;j<cut;j++){
				str[slen-cut+j]=tmp[j];
				
			}
			
		}
		printf("%s\n",str);
	}
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,A,B; cin>>N>>A>>B;

    if(A>B){
        cout<<0<<endl;
        return 0;
    }
    if(N==1){
        if(A==B) cout<<1<<endl;
        else cout<<0<<endl;
    }
    else{
        int l=A*(N-1)+B;
        int r=A+B*(N-1);
        cout<<r-l+1<<endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static long gcd(long a, long b) {
		if(a < b) {
			long tmp = a;
			a = b;
			b = tmp;
		}
		while(b != 0) {
			long r = a % b;
			a = b;
			b = r;
		}
		return a;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			
			long g = gcd(a, b);
			long l = a / g * b;
			System.out.println(g + " " + l);
		}
		sc.close();
	}

}



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

int mod = 1e9 + 7;

ll choose(ll n, ll k)
{
	if (n < k || k < 0 || n < 0)
		return 0;
		
	ll r = 1;
	for (ll d = 1; d <= k; --n, ++d)
	{
		ll g = __gcd(r, d);
		r /= g;
		r *= n / (d / g);
	}
	return r;
}

ll c[2001][2001];


int main()
{
	int N, K;
	cin >> N >> K;
	
	c[0][0] = 1;
	
	for (int i = 1; i <= 2000; ++i)
	{
		c[i][0] = c[i][i] = 1;
		for (int j = 1; j <= i - 1; ++j)
			c[i][j] = (c[i-1][j-1]%mod + c[i-1][j]%mod)%mod;
	}
	
	for (int i = 1; i <= K; ++i)
		cout << (c[K-1][i-1] * c[N-K+1][i])%mod << '\n';
}


Measured memory_bytes: 30080
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)                  cerr<<#x<<": "<<x<<endl
#define trace2(x, y)              cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)              cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)          cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)     cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    ll h[n];
    rep(i,0,n) cin >> h[i];
    std::vector<ll> dp(n,inf);
    dp[0]=0;
    for (ll i = 0; i < n; ++i){
        for(ll j=i+1; j<=i+2; j++){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]));
            }
        }
    }
    cout << dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
using namespace std;


int main(int argc, const char * argv[]) {

  int a, b, k;
  cin >> a >> b >> k;
  int i = 1;
  int count = 0;
  for(int i = min(a,b); i > 0; i--){
    if((a % i) == 0 && (b % i) == 0){
      count++;
      if(count == k){
        cout << i << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
// package app;

import java.util.Arrays;
import java.util.Objects;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        // final String s = sc.next();
        final int A = sc.nextInt();
        final String op = sc.next();
        final int B = sc.nextInt();
        // final String s = sc.next();
        // final String b = sc.next();

        // final int b = sc.nextInt();
        // final int D = sc.nextInt();
        // System.out.println();

        int result = op.equals("+") ? A + B : A - B;

        System.out.println(result);

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

Measured memory_bytes: 23124