akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int x[100010];
ll f[100010];
int que[100010],hd,tl;
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),E=gi(),T=gi();
	for(int i=1;i<=n;++i)x[i]=gi();x[++n]=E;
	ll MN=9e18;
	for(int i=n-1;i;--i){
		f[i]=9e18;
		while((hd^tl)&&f[que[tl-1]]+x[que[tl-1]]>f[i+1]+x[i+1])--tl;
		que[tl++]=i+1;
		while((hd^tl)&&2*(x[que[hd]-1]-x[i])>T)MN=std::min(MN,f[que[hd]]+x[que[hd]]+2*x[que[hd]-1]),++hd;
		if(hd^tl)f[i]=f[que[hd]]+x[que[hd]]-x[i]+T;
		f[i]=std::min(f[i],MN-3ll*x[i]);
	}
	printf("%lld\n",f[1]+x[1]);
	return 0;
}


Measured memory_bytes: 1792
N = int(input())
S = input()

kind = []
stone = []
s = 0

for i in range(N):
    if i == 0:
        kind.append(S[i])
        s += 1
    elif S[i-1] != S[i]:
        stone.append(s)
        kind.append(S[i])
        s = 1
    else:
        s += 1
    if i == N-1:
        stone.append(s)

if len(kind)==1:
    print(0)
elif len(kind)==2 and kind[0]=='#':
    print(min(stone[0],stone[1]))
else: 
    min = 0
    # print(kind, stone)
    if kind[0] == '.':
        start = 1
    else:
        start = 0 
    # 最初の#郡より右にある.の数を数えて足す
    for i in range(start+1,len(stone),2):
        min += stone[i]

    # #の個数を持つstoneのindexがi
    for i in range(start,len(stone),2):
        if i==start:
            tmp = min
        else:
            tmp += stone[i-2]
            tmp -= stone[i-1]
        if tmp < min:
            min = tmp
    print(min)


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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    ll s=0;
    for(auto &x : a)
        cin >> x, s+=x;
    s/=n;
    ll ans=0, ans2=0;
    for(auto x : a){
        ans += (x-s)*(x-s);
    }
    ++s;
    for(auto x : a){
        ans2 += (x-s)*(x-s);
    }
    cout << min(ans, ans2);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
b = 96
ans = ""
while N > 0:
  r = N % 26
  if r == 0:
    ans = "z" + ans
  else:
    ans = chr(b + r) + ans
  if N % 26 == 0:
    N = N // 26  -1
  else:
    N = N // 26
print(ans)

Measured memory_bytes: 9180
#include <iostream>
#include <stdio.h>
using namespace std;

int main(int argc, char const *argv[])
{
    short w, h, x, y, r;

    cin >> w >> h >> x >> y >> r;

	if((x >= r && x <= w-r) && (y >= r && y <= h-r))
		puts("Yes");
	else{
		puts("No");
	}
    
    return 0;
}



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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

string s;
int n, ans = 0;

void check() {
  set<char> d;
  for (auto &i : s) d.insert(i);
  if (d.size() < 3) return;
  int k = stoi(s);
  if (k <= n) ans++;
}

void brute(int i) {
  for (auto &j : {'3', '5', '7'}) {
    s += j;
    check();
    if (i < 9) brute(i + 1);
    s.pop_back();
  }
}

void MAIN() {
  cin >> n;
  brute(1);
  cout << ans << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define nodes 400005
#define int long long int
void fast(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
main()
{
    // cout<<(atan(1)*180)/3.14159<<endl;
    double a,b,x;
    cin>>a>>b>>x;
    double pp=(a*b*a)/(double)2;
    if(x>=pp){
        double y=(double)(2*x)/(double)(a*a);
        y=y-(double)b;
        y=(b-y)/(double)a;
        // cout<<y<<endl;
        double ans=atan(y)*180;
        ans=ans/(double)(3.14159);
        printf("%.10lf\n",ans);
    }
    else {
        double z=(2*x)/(double )(b*a);
        double ans=atan(b/(double)z)*180;
        ans=ans/(double)(3.14159);
        printf("%.10lf\n",ans);
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    boolean result = true;
    char[] cs = sc.next().toCharArray();
    for (int i = 0; i < cs.length; i++)
      if (cs[i] == (i % 2 == 0 ? 'L' : 'R'))
        result = false;
    System.out.println(result ? "Yes" : "No");
  }
}

Measured memory_bytes: 23124
n,x=map(int,input().split())
l=list(map(int,input().split()))
ns=1
dis=0
i=0
while dis<=x:
  
  dis+=l[i]
  i+=1
  if dis>x:
    break
  elif i==n:
    ns+=1
    break
  ns+=1
print(ns)


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.math.BigDecimal;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String[] line = br.readLine().split(" ");
        int N = Integer.parseInt(line[0]);
        int K = Integer.parseInt(line[1]);

        int multipleOfK = N / K;
        int modK_HalfOfK = 0;
        double output = 0.0d;

        if (K % 2 == 1) {
            output = Math.pow(multipleOfK, 3);
        } else {
            if (multipleOfK * K + K / 2 <= N) {
                modK_HalfOfK = multipleOfK + 1;
            } else {
                modK_HalfOfK = multipleOfK;
            }
            output = Math.pow(multipleOfK, 3) + Math.pow(modK_HalfOfK, 3);
        }
        out.println(BigDecimal.valueOf(output).toPlainString().replace(".0", ""));
        out.close();
    }
}

Measured memory_bytes: 22484
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 1e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    int a, b;
    cin >> a >> b;
    if(a <= 5) cout << 0;
    else if(a <= 12) cout << b / 2;
    else cout << b;
    return 0;
}


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

int main()
{
    int N, M;
    cin >> N >> M;
    
    int sum=0;
    int tmp;
    for(int i = 0; i < M; i++)
    {
        cin >> tmp;
        sum += tmp;
    }
    if(sum <= N) cout << N - sum << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3636
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
  int n, max;
  bool b[10];
  int w[10] = {512, 256, 128, 64, 32, 16, 8, 4, 2, 1};

  while(cin >> n) {
    fill(b, b+10, false);
    max = 0;    
    for(int i = 0; i < 10; i++) {
      if(n/w[i] > 0) {
	b[i] = true;
	n -= w[i];
	if(max < w[i]) max = w[i];
      }
    }

    for(int i = 9; i >= 0; i--) {
      if(b[i]) {
	cout << w[i];
	if(w[i] == max) cout << endl;
	else cout << ' ';
      }
    }
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define sa(a,n,t) for(int ii=0;ii<n;ii++) scanf("%"#t"",&(a)[ii])
#define rep(i,n) for(int i=0;i<n;i++) 
#define reps(i,a,n) for(int i=a;i<n;i++) 
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rreps(i,a,n) for(int i=n-1;i>=a;i--)
#define validl(i,a,b) ((i>=a)&&(i<=b))?1:0
#define validmat(x,y,a,b,c,d) (validl(x,a,b) && validl(y,a,b))?1:0
#define validmn(x,y,m,n) validmat(x,y,0,m,0,n)
#define valid(i,n) validl(i,0,n)
#define v(t) vector<t>
#define vv(t) vector<vector<t> >
#define mk make_pair
#define pb push_back
#define pa(a,n,t)  for(int i=0;i<n;i++) printf("%"#t"",a[i])
#define p2 pair<int,int>
#define p3 pair<p2,int>
#define fi first
#define se second
#define sd(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld",a)
#define pd(a) printf("%d",a)
#define sf(a) scanf("%lf",&a)
#define pf(a) printf("%lf",a)
#define nline printf("\n")
#define ss(a) scanf("%s",a)
#define ps(a) printf("%s",a)
#define sc(a) scanf("%c",&a)
#define pc(a) printf("%c",&a)
#define mf(m,f) m.find(f)!=m.end()
#define pp3(m) cout<<m.fi.fi<<" "<<m.fi.se<<" "<<m.se<<" "
#define pp2(m) cout<<m.fi<<" "<<m.se<<" "
#define debug 0
#define MAX 1000000
lli ans=0;
bool prime[MAX+1]; 
int lprime[MAX+1]; 
int ar[1000001];
bool traverseondiv(int i){
    while(i!=1){
        //cout<<i<<" "<<lprime[i]<<endl;
        int lp=lprime[i];
        if(ar[lp])  return true;
        while((i%lp)==0) i=i/lp;
    }
    return false;
}
void adddiv(int i){
    while(i!=1){
        int lp=lprime[i];
        ar[lp]=1;
        while((i%lp)==0) i=i/lp;
    }
}
int main()
{
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=MAX; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            lprime[p]=p;
            for (int i=p*p; i<=MAX; i += p) 
                if(prime[i])
                    prime[i] = false,lprime[i]=p; 
        } 
    } 
    
    prime[1]=false;
    lprime[1]=1;
    rep(i,MAX+1) if(lprime[i]==0) lprime[i]=i;
    int n;
    int gcdtill=-1;
    bool pairwise=true;
    cin>>n;
    rep(i,n){
        int b;
        cin>>b;
        if(traverseondiv(b)) pairwise=false;
        adddiv(b);
        if(i==0) gcdtill=b;
        else gcdtill= __gcd(gcdtill,b);
    }
    if(pairwise) cout<<"pairwise coprime\n";
    else if(gcdtill==1) cout<<"setwise coprime\n";
    else cout<<"not coprime\n";
  return 0;
}

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

using namespace std;

#define fi first
#define se second

const int MAXN = 100000;

typedef pair<int, int> ii;
typedef vector<ii> vii;

vii adjList[MAXN];

int dist[MAXN]; bitset<MAXN> inq;
queue<int> q;

int main(){

    int N, E, S;
    cin >> N >> E >> S;

    for (int i=0; i<E; i++){
        int s, t, d;
        cin >> s >> t >> d;

        adjList[s].push_back(ii(d,t));
    }

    memset(dist, -1, sizeof(dist)); dist[S] = 0;
    inq.reset(); inq[S] = 1;
    
    q.push(S);
    while (!q.empty()) {
        int x = q.front(); q.pop();
        
        inq[x] = 0;
        for (vii::iterator it = adjList[x].begin(); it != adjList[x].end(); ++it) {
            int nn = it->se;
            int nd = dist[x]+it->fi;

            if (dist[nn] != -1 && dist[nn] <= nd) continue;
            
            dist[nn] = nd;
            if (!inq[nn]) q.push(nn);
            inq[nn] = 1;
        }
    }

    for (int i=0; i<N; i++){
        if (dist[i] == -1) cout << "INF" << endl;
        else cout << dist[i] << endl;
    }
}

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

int main() {
  int A,B,C,X,i,j,k,result,count=0;

  cin >> A;
  cin >> B;
  cin >> C;
  cin >> X;

  for (i=0; i<=A; i++) {
    for (j=0; j<=B; j++) {
      for (k=0; k<=C; k++) {
        result = 500*i + 100*j + 50*k;
        if (result == X) count++;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
n = int(input())
s = [i for i in str(input())]
alpha_lst = [i for i in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ']

tmp = [alpha_lst[(int(alpha_lst.index(i))+n)%26] for i in s]
#tmp = [alpha_lst.index(i) for i in s]
print(''.join(tmp))

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

using ll = long long;

const int N = 200005;

int n, a[N], p[N];
ll r;

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        scanf("%d", a + i);
        p[i] = a[i] ? i : p[i - 1];
    }
    for(int i = n, j, x; i; i--){
        for(j = i, x = 0; j && !(x & a[j]); j = p[j - 1]) x ^= a[j];
        r += i - j;
    }
    printf("%lld\n", r);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    ll a,b,c;
    cin>>a>>b>>c;
    ll ans=min(b/a,c);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

#define ATOI(c) ((c) - '0')
int main(void){
  char str[10];
  int n;
  long long ans = 0;
  
  scanf("%s", str);
  n = strlen(str);
  for (int i=0; i < 1<<(n-1); i++){
    long sum = 0, tmp;
    tmp = ATOI(str[0]);
    for (int j=0; j<n-1; j++){
      // if bit==1 -> insert '+' after str[i]
      if (i & (1<<j)){
//        printf("%ld ", tmp);
        sum += tmp;
        tmp = ATOI(str[j+1]);
      } else {
        tmp = tmp*10 + ATOI(str[j+1]);
      }
    }
    sum += tmp;
    ans += sum;
//    printf("%ld\n", tmp);
  }
  
  printf("%lld\n", ans);
  return 0;
}
        

Measured memory_bytes: 128
#apples
x, y, a, b, c = map(int, input().split())
red = list(map(int, input().split()))
green = list(map(int, input().split()))
white = list(map(int, input().split()))
red.sort()
green.sort()
white.sort()

apples = []
for i in range(x):
    apples.append(red[(a-1)-i])
for i in range(y):
    apples.append(green[(b-1)-i])
    
add = min(x+y, c)
for i in range(add):
    apples.append(white[(c-1)-i])

apples.sort()
sum = 0
for j in range(x+y):
    sum += apples[(x + y + add -1)-j]
print(sum)

Measured memory_bytes: 22720
function Main(input){
  input = input.trim().split(' ').map(x=>parseInt(x));
  var n = input[0];
  var m = input[1];
  var ans = [];
  var border = Math.floor((n+1)/2);
  var cnt = 0;
  while (cnt<m && 1+cnt < border-cnt){
    ans.push([1+cnt, border-cnt]);
    cnt++;
  }
  var newCnt = 0;
  var end = 2*border-1;
  while (cnt<m && border+1+newCnt < end - newCnt){
    ans.push([border+1+newCnt, end-newCnt]);
    cnt++;
    newCnt++;
  }
  ansStr = ''
  for (let i=0; i<ans.length; i++){
    ansStr += String(ans[i][0])+' '+String(ans[i][1]+'\n');
  }
  ansStr.slice(0,-1);
  console.log(ansStr);
}
  

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    int a, b;
    cin >> a >> b;

    if(a == b){
        cout << "Draw" << endl;
    }else if((a > b && a != 13)|| a == 1){
        cout << "Alice" << endl;
    }else{
        cout << "Bob" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:256000000")
#include<utility>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head
#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

// belik's shit
ll const mod = 1e9 + 7;
namespace {
	ll mult(ll& a, ll& b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) {
			val += mod;
		}
		if (val >= mod) {
			val -= mod;
		}
		return val;
	}
	ll poww(ll a, ll b)
	{
		ll val = 1;
		a %= mod;
		while (b > 0){
			if (b % 2) val = mult(a, val);
			a = mult(a, a);
			b >>= 1;
		}
		return val % mod;
	}
	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e3 + 5;
ll dp[maxn][maxn];
pair<ll, ll> p[maxn][maxn];
signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s, t; cin >> s >> t;
	ll n = s.size(), m = t.size();
	s = '#' + s;
	t = '$' + t;
	dp[0][0] = 0;
	dp[0][1] = 0;
	dp[1][0] = 0;
	for (ll i = 1; i <= n; i++) {
		for (ll j = 1; j <= m; j++) {
			if (dp[i][j] < dp[i - 1][j]) dp[i][j] = dp[i - 1][j], p[i][j] = mp(i - 1, j);
			if (dp[i][j] < dp[i][j - 1]) dp[i][j] = dp[i][j - 1], p[i][j] = mp(i, j - 1);
			if (dp[i][j] < dp[i - 1][j - 1]) dp[i][j] = dp[i - 1][j - 1], p[i][j] = mp(i - 1, j - 1);
			if (s[i] == t[j]) {
				if (dp[i][j] < dp[i - 1][j - 1] + 1) dp[i][j] = dp[i - 1][j - 1] + 1, p[i][j] = mp(i - 1, j - 1);
			}
			ll tt = 0;
		}
	}
	ll sz = dp[n][m];
	string ss = "";
	auto pa = mp(n, m);
	while (sz) {
		auto p1 = p[pa.X][pa.Y];
		if (dp[p1.X][p1.Y] == sz - 1) {
			ss += s[pa.X]; sz--;
		}
		pa = p1;
	}
	reverse(all(ss));
	//cout << dp[n][m] << endl;
	cout << ss;
	return 0;
}
/*

*/

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

int main()
{
  int A , B , sum ;
  
  cin >> A >> B ;
  
  int i = A ;
  
  while(i != B+1)
  {
    if(i%10==0)
    {
      i++ ;
      continue ;
    }
    
    if(i/10000==i%10 && i/1000%10==i%100/10)
      sum++ ;
    
    i++ ;
  }
  
  cout << sum << endl ;
}

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

int main(){
    double x1,y1,x2,y2,d,e,xd,yd;
    cin >> x1 >> y1 >> x2 >> y2;
    xd = (x1 - x2)*(x1 - x2);
    yd = (y1 - y2)*(y1 - y2);
    e = (xd + yd);
    
    d = sqrt(e);
    
    printf("%5f", d);
    cout <<endl;
    
}


Measured memory_bytes: 3264
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n, x; cin >> n >> x;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    
    ll ans = 0;
    REP(i, n-1) {
        ll et = a[i] + a[i+1] - x;
        if (et > 0) {
            et = min(et, a[i+1]);
            a[i+1] -= et;
            ans += et;
        }
    }
    ll ett = a[0] + a[1] - x;
    if (ett > 0) {
        a[0] -= ett;
        ans += ett;
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+7;
const ll mod = 998244353;
const int sz = 25;
#define afdafafafdafaf y1;
int n,m;
ll ar[maxn];

ll inv[maxn], d[maxn];
ll s[maxn], fs[maxn];
int main()
{
    scanf("%d", &n);
    ll ans = 0;
    for(int i=1;i<=n;i++){
        int x;scanf("%d", &x);
        ar[x]++;
        ans = (ans + mod - x) % mod;
    }
    inv[0] = inv[1] = 1;
    for(int i=2;i<maxn;i++){
        inv[i] = inv[mod % i] * (mod - mod / i) % mod;
        assert(inv[i] * i % mod == 1);
        d[i] = inv[i];
    }
    d[1] = 1;
    for(int i=1;i<maxn;i++){
        for(int j=i+i; j<maxn; j+=i){
            d[j] = (d[j] - d[i] + mod) % mod;
        }
    }
    for(ll j=1;j<maxn;j++){
        ll s=0;
        for(ll i=j; i<maxn; i+=j){
            s += ar[i] * i;
            s %= mod;
        }
        ans += s * s % mod * d[j] % mod;
        ans %= mod;
    }
    ans = ans * ((mod + 1) / 2) % mod;
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 24960
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var M1 = one[0];
	var D1 = one[1];
	var two = nextIntArray();
	var M2 = two[0];
	var D2 = two[1];
	if(D2 == 1){
		myout(1);
	}else{
		myout(0);
	}
}


Measured memory_bytes: 7628
let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let fs, bs = Array.fold_left (fun (xs, ys) a -> a :: ys, xs) ([], []) a_s
let _ = List.(fs @ rev bs |> iteri (fun i n -> Printf.printf (if i = 0 then "%d" else " %d") n)); print_newline ()

Measured memory_bytes: 17152
require "prime"

n = gets.to_i
numbers = gets.chomp.split.map(&:to_i)
table = Hash.new(0)
numbers.each{|x|
    Prime.prime_division(x).each{|p, x|
        table[p] = x if table[p] < x
    }
}
answer = 1
table.each{|k, v| v.times{answer *= k}}
puts answer


Measured memory_bytes: 7032
N = int(input())
S = input()
direction = [{"E": 0, "W": 0} for _ in range(N + 1)]  # direcion[i]["E"] ... i番目までにEを向いている人数
ans = N
for i in range(N):
    direction[i + 1]["E"] = direction[i]["E"] + (1 if S[i] == "E" else 0)
    direction[i + 1]["W"] = direction[i]["W"] + (1 if S[i] == "W" else 0)
for i in range(N):
    ans = min(ans, direction[i]["W"] + direction[N]["E"] - direction[i + 1]["E"])
print(ans)


Measured memory_bytes: 190436
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define int long long
using namespace std;

typedef pair<int, int> Pii;

void readint(int N, vector<int> &a);
void readdouble(int N, vector<double> &a);
void readindex(int N, vector<int> &a);



signed main(){

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

    if(A + B >= C){
        cout << "Yes";
    }else{
        cout << "No";
    }

    
    return 0;
}








void readint(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readdouble(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}
void readindex(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str()) - 1;
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str()) - 1;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,a,b,sum;
	while(~scanf("%d%d%d",&n,&a,&b)){
		sum = 0;
		for(int i = 1;i <= n;i++){
			if(i < 10){
				if(i >= a && i <= b)
					sum += i;
			}
			else if(10 <= i && i <100){
				int p = 0,q = 0;
				p = i / 10;
				q = i - p * 10;
				if((p + q) >= a && (p + q) <= b)
					sum += i;
			}
			else if(i >= 100 && i <1000){
				int p = 0,q = 0,r = 0;
				p = i / 100;
				q = (i - p * 100) / 10;
				r = i % 10;
				if((p + q + r) >= a && (p + q + r) <= b)
					sum += i;
			}
			else if(i >= 1000 && i < 10000){
				int p = 0,q = 0,r = 0,x = 0;
				p = i / 1000;
				q = (i - p * 1000) / 100;
				r = (i - p * 1000 - q * 100) / 10;
				x = i % 10;
				if((p + q + r + x) >= a && (p + q + r + x) <= b)
					sum += i;
			}
		}
		if(n == 10000)
			sum += 10000;
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    string S; cin >> S;
    string pre;
    pre += S[0];
    pre += S[1];
    string suf;
    suf += S[2];
    suf += S[3];
    
    if(pre > "12" || pre == "00"){
        if(suf > "12" || suf == "00"){
            cout << "NA" << endl;
            return 0;
        }else{
            cout << "YYMM" << endl;
            return 0;
        }
    }else{
        if(suf > "12" || suf == "00"){
            cout << "MMYY" << endl;
            return 0;
        }else{
            cout << "AMBIGUOUS" << endl;
            return 0;
        }
    }
    
    
    
    return 0;
}



Measured memory_bytes: 256
S = input()

ans = len(S)
tmp = 0
for i in range(len(S)):
    if int(S[i]) == i%2:
        tmp += 1
ans = min(ans,tmp)

tmp=0
for i in range(len(S)):
    if int(S[i]) == (i+1)%2:
        tmp += 1
ans = min(ans,tmp)

print(ans)


Measured memory_bytes: 40940
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, heapq

MOD = 1000000007  # type: int

def eratosthenes_sieve(n: int):
    """
    エラトステネスの篩を用いてn以下の素数を求める
    """
    table = [0] * (n + 1)
    prime_list = []
    
    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1
    
    return prime_list

def prime_factorization(n: int, prime_list: "List[int]"):
    """
    n: 素因数分解したい数
    prime_list: sqrt(n)までの素数が格納されたリスト
    -------------------
    prime_count: 素因数の個数が入ったCounterオブジェクト
    """
    prime_count = collections.Counter()
    
    for i in prime_list:
        if i * i > n:
            break
        while n % i == 0:
            n /= i
            prime_count[int(i)] += 1
    if n > 1:
        prime_count[int(n)] += 1
    
    return prime_count

def mfact(MAX=200000, MOD=1000000007) -> 'List[int]':
    """
    MAXまでの階乗のmodの配列を返します
    """
    f = [1]
    for i in range(1, MAX):
        f.append(f[-1] * i % MOD)
    return f

def inv(x):
    res = 1
    k = MOD - 2
    y = x
    while (k):
        if(k % 2 == 1):
            res = (res * y) % MOD
        y = (y ** 2) % MOD
        k = k // 2
    return res

def comb(n, k, f):
    a = f[n]
    b = f[n-k]
    c = f[k]
    bc = (b * c) % MOD
    return (a * inv(bc)) % MOD


def solve(N: int, M: int):
    prime_list = eratosthenes_sieve(math.ceil(math.sqrt(M)))
    prime_count = prime_factorization(M, prime_list)
    prime_keys = prime_count.keys()
    res = 1
    f = mfact()
    for k in prime_count.keys():
        res *= comb(prime_count[k]+N-1, prime_count[k], f)
    print(res % MOD)
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 13532
#include<iostream>
using namespace std;
inline int culrank(long long num) {
	int res = 0;
	while (num > 0) {
		res += num % 10;
		num /= 10;
	}
	return res;
}

inline long long culpow(long long x, int n) {
	long long res = x;
	for (int i = 1; i < n; ++i) {
		res *= x;
	}
	return res;
}
int main() {
	int a, n;
	long long m;
	cin >> a >> n >> m;
	int ans = 0;
	for (int i = 1; i <= 72; ++i) {
		long long x = culpow(i + a, n);
		if (x <= m && culrank(x) == i) {
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3092
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<set>
#include<vector>
#include<map>
#include<queue>

#define N 300005
#define M 8000005

#define ls (t<<1)
#define rs ((t<<1)|1)
#define mid ((l+r)>>1)

#define mk make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

int i,j,m,n,p,k,f[N],a[N];

int main()
{
		scanf("%d%d",&n,&k);
		memset(f,60,sizeof(f));
		f[1]=0; 
		for (j=1;j<=n;++j) scanf("%d",&a[j]);
		for (i=2;i<=n;++i)
			for (j=1;j<=k&&i-j>0;++j)
				f[i]=min(f[i],f[i-j]+abs(a[i]-a[i-j]));
		printf("%d\n",f[n]); 
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353 
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        int a[5];
        int ans=0;
        for(int i=0;i<5;i++){
            cin>>a[i];
            if(a[i]==0)
                ans=i+1;
        }
    cout<<ans<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3532
#include <stdio.h>
int main(void){
    // Your code here!
    int i,b;
    b = 1;
   while(1){  
       scanf("%d",&i);
       if(i == 0){
           break;
           
       }
     
       printf("Case %d: %d\n",b,i);
 
       b ++;
   }
  return 0;
}



Measured memory_bytes: 2576
#light "off"
open System;;
open System.IO;;

let reader = new StreamReader(new BufferedStream(Console.OpenStandardInput ()))
let writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput ()))

let skipSpaces () = while reader.Peek () <= int ' ' do reader.Read () |> ignore done;;
let read f = skipSpaces (); [|while reader.Peek () > int ' ' do yield char (reader.Read ()) done |] |> System.String |> f;;
let readint () = skipSpaces (); let mutable ans = 0 in while reader.Peek () > int ' ' do ans <- ans * 10 + (reader.Read () - int '0'); done; ans;;
let write (s : string) = writer.Write s;;
let writeln (s : string) = writer.WriteLine s;;

let divisors x = {1..x} |> Seq.takeWhile (fun i -> i * i <= x) |> Seq.filter (fun i -> x % i = 0) |> Seq.collect (fun i -> Seq.ofList [i; x / i]);;

let N, K = readint (), readint ();;
let A = Array.init N (fun _ -> readint ());;

let f d =
  let x = Array.init N (fun i -> A.[i] % d) |> Array.sort in
  let mutable i = 0 in
  let mutable j = N - 1 in
  let mutable souwa = 0 in
  while i < j do
    let tukau = min x.[i] (d - x.[j]) in
    souwa <- souwa + tukau;
    x.[i] <- x.[i] - tukau;
    x.[j] <- x.[j] + tukau;
    if x.[i] = 0 then i <- i + 1;
    if x.[j] = d then j <- j - 1;
  done;
  souwa <= K;;

divisors (Array.sum A) |> Seq.filter f |> Seq.max |> printf "%d";;

reader.Close();;
writer.Close();;

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

int main() {
  int total = 0;
  for(int i = 0; i < 4; ++i) {
    int buff;
    cin >> buff;
    total += buff;
  }
  int m = total / 60;
  cout << m << endl;
  cout << total - m * 60 << endl;
  return 0;
}

Measured memory_bytes: 1160
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;
    static int MOD = (int)1E9 + 7;
    public static void main(String[] args) {
        int H = ni();
        int W = ni();
        
        char[][] g = new char[H+2][W+2];
        for (int h = 1; h <= H; h++) {
            String s = ns();
            for (int w = 1; w <= W; w++) {
                g[h][w] = s.charAt(w-1);
            }
        }

        int[][] L = new int[H+2][W+2];
        int[][] R = new int[H+2][W+2];
        int[][] U = new int[H+2][W+2];
        int[][] D = new int[H+2][W+2];

        for (int h = 1; h <= H; h++) {
            for (int w = 1; w <= W; w++) {
                L[h][w] = g[h][w] == '#' ? 0 : L[h][w-1] + 1;
            }
            for (int w = W; w >= 1; w--) {
                R[h][w] = g[h][w] == '#' ? 0 : R[h][w+1] + 1;
            }
        }
        
        for (int w = 1; w <= W; w++) {
            for (int h = 1; h <= H; h++) {
                U[h][w] = g[h][w] == '#' ? 0 : U[h-1][w] + 1;
            }
            for (int h = H; h >= 1; h--) {
                D[h][w] = g[h][w] == '#' ? 0 : D[h+1][w] + 1;
            }
        }

        int maxCount = 0;
        for (int h = 1; h <= H; h++) {
            for (int w = 1; w <= W; w++) {
                if (g[h][w] == '#') continue;
                int temp = L[h][w] + R[h][w] + U[h][w] + D[h][w] - 3;
                maxCount = Math.max(maxCount, temp);
            }
        }
        so.println(maxCount);
    }

    private static long nl() {
        return sc.nextLong();
    }

    private static int ni() {
        return sc.nextInt();
    }

    private static String ns() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0);
    }
    private static int[] nints(int n) {
        return nints(n, 0);
    }

    private static long[] nlongs(int n, int offset) {
        long[] a = new long[offset + n];
        for (int i = 0; i < n; i++)
            a[offset + i] = nl();
        return a;
    }

    private static int[] nints(int n, int offset) {
        int[] a = new int[offset + n];
        for (int i = 0; i < n; i++)
            a[offset + i] = ni();
        return a;
    }
}


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

int main() {
  int A, B;
  cin >> A;
  B = 0;
  for (int i = 0; i < A; i++){
    int C, D;
    cin >> C;
    D = 0;
    for (int j = 0; j < 30; j++){
      if (C%2 == 0){
        D++;
        C /= 2;
      }
      else {
        break;
      }
    }
    if (i == 0){
      B = D;
    }
    if ( D < B ){
      B = D;
    }
  }
  cout << B << endl;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  if(a==b){
    cout << "Draw" << endl;
  }
  else if(a==1){
    cout << "Alice" << endl;
  }
  else if(b==1){
    cout << "Bob" << endl;
  }
  else if(a>b) {
    cout << "Alice" << endl;
  }
  else if(a<b){
    cout << "Bob" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
	while(cin>>n,n){
		int a=0,b=0;
		for(int i=0;;i++){
			int x=n-(i*i+i)/2;
			if(x<=0)break;
			if(x%(i+1)!=0)continue;
			a=x/(i+1);
			b=i+1;
		}
		cout<<a<<' '<<b<<endl;
	}
}


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if(a == b){
    cout << a * 2 << endl;
    return 0;
  }
  int c = max(a, b);
  cout << (c * 2 - 1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define faster() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const long long int infLL = 9000000000000000000;
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(a) (a).begin(),(a).end()
#define mx_int_prime 999999937
const int inf = 2000000000;
const double PI = acos(-1);
const double eps = 1e-9;
typedef long double ld;
#define MOD 1000000007
const unsigned int M = 1000000007;
typedef long long ll;
const int mx=2e5+125;
int ar[mx],br[mx],pos[mx];
#define PB push_back
#define endl '\n'
#define S second
#define F first
void solve()
{

    ll n;
    cin>>n;
    ll ans=(n*(n+1))/2;
    cout<<ans-n<<endl;


}
int main()
{
    faster();
    int tc;
    tc=1;
    while(tc--)
        solve();
    return 0;
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n;
	cin >> n;
	vector<string> w(n);
	for(int i=0;i<n;i++)
		cin >> w.at(i);

	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			if(w.at(i)==w.at(j)){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	for(int i=0;i<n-1;i++){
		if(w.at(i).at(w.at(i).size()-1)!=w.at(i+1).at(0)){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

typedef struct pp{
  char name[100];
  int t;
}PP;

PP Q[LEN];
int head,tail;
int n;

PP deque(void);
void enqueue(PP);
int min(int,int);

int main(){
  int lap=0;
  int c;
  int i,q;
  PP u;

  scanf("%d%d",&n,&q);

  for(i=1;i<=n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }

  head=1;
  tail=n+1;

  while(head!=tail) {
    u=deque();
    c=min(q,u.t);
    u.t-=c;
    lap+=c;
    if(u.t>0){
      enqueue(u);
    }else{
      printf("%s %d\n",u.name,lap);
    }
  }
  return 0;
}

PP deque(){
  PP x=Q[head];
  head=(head+1)%LEN;
  return x;
}

void enqueue(PP x){
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

int min(int a,int b){
  if(a>b)return b;
  else return a;
}

Measured memory_bytes: 21072
#include<bits/stdc++.h>
using namespace std;
 int main()
{
	long long int n;
	cin>>n;
	string str;
	cin>>str;
	vector<long long int>R,B,G;
	long long int countR=0,countB=0,countG=0;
	unordered_map<long long int,long long int> R1,B1,G1;
	for(long long int i=0;i<n;i++)
	{
		if(str[i]=='R')
		R.push_back(i+1),R1[i+1]++,countR++;
		else
		if(str[i]=='B')
		B.push_back(i+1),B1[i+1]++,countB++;
		else
		G.push_back(i+1),G1[i+1]++,countG++;
	}
	long long int count=0;
	for(long long int i=0;i<R.size();i++)
	{
		for(long long int j=0;j<B.size();j++)
		{
			if((R[i]+B[j])%2==0)
			{
				if(G1[(R[i]+B[j])/2])
				{
					count++;
				}
				
			}
	
		}
	}
	for(long long int i=0;i<R.size();i++)
	{
		for(long long int j=0;j<G.size();j++)
		{
			if((R[i]+G[j])%2==0)
			{
				if(B1[(R[i]+G[j])/2])
				count++;
			}
			
		}
	}
	for(long long int i=0;i<G.size();i++)
	{
		for(long long int j=0;j<B.size();j++)
		{
			if((G[i]+B[j])%2==0)
			{
				if(R1[(G[i]+B[j])/2])
				count++;
			}
		
		}
	}
	cout<<countR*countB*countG-count;
	
}

Measured memory_bytes: 4212
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    a.sort()
    val i = a.last()

    var minDis = Int.MAX_VALUE
    var result = 0
    a.removeAt(a.size - 1)
    a.forEach {
        if (Math.abs(it - i / 2) <= minDis) {
            minDis = Math.abs(it - i / 2)
            result = it
        }
    }
    print(i)
    print(' ')
    print(result)
}

Measured memory_bytes: 53616
from sys import stdin
from math import sin, cos, pi, sqrt

while True:
    n = int(stdin.readline().rstrip())
    if n == 0:
        break
    else:
        s = [int(x) for x in stdin.readline().rstrip().split()]
        ava = sum(s)/n
        alpha = sqrt(sum([(si-ava)**2 for si in s])/n)
        print(alpha)



Measured memory_bytes: 5708
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 入力値の取得
		int K = sc.nextInt();
		
		// Kが偶数なら -1 を出力して終了
		if (K % 2 == 0 || K % 5 == 0) {
			System.out.println(-1);
			sc.close();
			return;
		}
		
		int rem = 7;
		int index = 1;
		while (true) {
			if (rem % K == 0) {
				break;
			}
			rem = (rem % K) * 10 + 7;
			index++;
		}
		
		// 結果の出力
		System.out.println(index);
		
		sc.close();
	}
}


Measured memory_bytes: 27264
#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
#define de cout<<"test"<<endl;
#define st system("pause");
#define M_PI 3.1415926
int A[100005]={};
int main()
{
    int a;
    while(cin>>a){
        for(int i=0;i<a;i++){
            cin>>A[i];
        }
        int ans=0;
       int l=0,r=0;
while(1){
    if(A[l]==A[r]){
        r++;
        con;
        }
    else if(A[l]>A[r]){
            ans++;
        while(A[r+1]<=A[r]){
            r++;
            if(r>=a)
                bk;
        }
        r++;
    l=r;
    }
       else if(A[l]<A[r]){
           ans++;
        while(A[r]<=A[r+1]){
            r++;
            if(r>=a)
                bk;
        }
        r++;
        l=r;
       }
       if(r>=a)
        bk;
}
        ans=max(1,ans);
        cout<<ans<<endl;
    }
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int p[2] = {3, 2};

int main(void){
    int s = -50;
    rep(i, 2){
        int in, res = INF;
        rep(i, 3) cin >> in, res = min(in, res);
        s += res;
    }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 1160
def bubbleSort(A, N):
    flag = 1
    i = 0
    swapnum = 0
    while flag:
        flag = 0
        for j in range(N-1, i, -1):
            if A[j] < A[j-1]:
                temp = A[j-1]
                A[j-1] = A[j]
                A[j] = temp
                swapnum += 1
                flag = 1
        i = i + 1
    return swapnum
def showlist(A):
    for i in range(len(A)):
        if i==len(A)-1:
            print(A[i])
        else:
            print(A[i], end=' ')
N = eval(input())
A = list(map(int, input().split()))
swapnum = bubbleSort(A, N)
showlist(A)
print(swapnum)


Measured memory_bytes: 5616
# 桁DPぽいけどただの再帰でいい
n = input()


def rec(i):
    if int(i) > int(n):
        return 0
    ret = 0
    if "3" in i and "5" in i and "7" in i:
        ret += 1
    for j in ["3", "5", "7"]:
        ret += rec(i + j)
    return ret


ans = 0
for i in ["3", "5", "7"]:
    ans += rec(i)
print(ans)

Measured memory_bytes: 9132
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 2e5 + 17;

struct circle
{
	int x, y, r;
	circle() { x = y = r = 0; }
	circle(int x, int y, int r = 0) : x(x), y(y), r(r) { }
};

int n;
circle a[maxn];
long double d[maxn];
bool used[maxn];

bool read()
{
	if (scanf("%d %d", &a[0].x, &a[0].y) != 2)
		return false;

	scanf("%d %d", &a[1].x, &a[1].y);
	scanf("%d", &n);

	forn (i, n)
		scanf("%d %d %d", &a[i + 2].x, &a[i + 2].y, &a[i + 2].r);

	return true;
}

long double dist1(circle a, circle b)
{
	return sqrtl((long double) (a.x - b.x) * (a.x - b.x) + (long double) (a.y - b.y) * (a.y - b.y));
}

long double dist(circle a, circle b)
{
	return max((long double) 0, dist1(a, b) - a.r - b.r);
}

void solve()
{
	n += 2;
	swap(a[1], a[n - 1]);
	d[0] = 0;

	forn (i, n - 1)
		d[i + 1] = linf;

	forn (iter, n)
	{
		int v = -1;

		forn (i, n)
			if (!used[i] && (v == -1 || d[i] < d[v]))
				v = i;

		if (v == -1 || d[v] == linf)
			break;

		used[v] = true;

		forn (i, n)
			if (!used[i])
			{
				long double e = dist(a[v], a[i]);
				d[i] = min(d[i], d[v] + e);
			}
	}

	printf("%.9lf\n", (double) d[n - 1]);
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 3968
#include <stdio.h>

int main(){
  int A[100];
  int i, j, N, flag = 1,count = 0;

  scanf("%d",&N);

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

  while(flag){
    flag = 0;
    for(j = N-1; j > 0; j--){
      if(A[j] < A[j-1]){
	i = A[j];
	A[j] = A[j-1];
	A[j-1] = i;
	flag = 1;
	count++;
      }
    }
  }

  for(i = 0; i < N-1; i++){
    printf("%d ",A[i]);
  }

  printf("%d\n%d\n",A[i],count);
  
  return 0;
}


Measured memory_bytes: 2108