akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int64_t answer;
  cin >> N;
  vector<int64_t> vec(N + 1);
  vec.at(0) = 2;
  vec.at(1) = 1;
  
  if (N == 1) {
    answer = 1;
  }
  if (N > 1) {
    for (int64_t i = 2; i < N + 1; i++) {
    vec.at(i) = vec.at(i-1) + vec.at(i-2);
    }
    answer = vec.at(N);
  }
   cout << answer << endl;
  
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

int main(){
	int s;
	cin >> s;
	int head = s/100;
	int tail = s%100;

	if(1 <= head && head <= 12 && 1 <= tail && tail <= 12){
		cout << "AMBIGUOUS" << endl;
	}else if(1 <= head && head <= 12){
		cout << "MMYY" << endl;
	}else if(1 <= tail && tail <= 12){
		cout << "YYMM" << endl;
	}else{
		cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stdio.h>

using namespace std;



int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int k;
    cin>>k;
    int ans=1<<k;
    int max=a;if(b>max)max=b;if(c>max)max=c;
    if(max==a)
    {
    cout<<ans*a+b+c<<endl;
    return 0;
    }
    if(max==b)
    {
    cout<<ans*b+a+c<<endl;
    return 0;
    }
    if(max==c)
    {
    cout<<ans*c+a+b<<endl;
    return 0;}

    return 0;
}

Measured memory_bytes: 256
N,Y=list(map(int,input().split()))

c=[]
for i in range(N+1):
    for j in range(N+1-i):
        if 10000*i+5000*j+1000*(N-i-j)==Y:
            c.append(str(i))
            c.append(str(j))
            c.append(str(N-i-j))
            break
            
            
if  len(c)==0:
    print('-1 -1 -1')
else:
    print(c[0]+' '+c[1]+' '+c[2])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int l,r,d;
    in(l,r,d);
    int ans=0;
    if(d==1){
        ans=r-l+1;
    }else{
        for(int i=l;i<=r;i++){
            if(i%d==0)ans++;
        }
    }
    out(ans);
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

int solve(int x) {
    int di = 0;
    for(int d = 1; d <= x; d++) {
        if(x % d == 0) {
            di++;
        }
    }
    return di == 8;
}

int solve() {
    int n;
    cin >> n;
    int ans = 0;
    rep(x, 1, n) {
        if(x & 1) {
            ans += solve(x);
        }
    }
    cout << ans << endl;
    return 0;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3620
//AtCoder ABC109 C - Skip
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    ll N,X; cin>>N>>X;
    vector<ll> xn(N);
    for(auto&& x:xn){
        cin>>x;
        x=abs(x-X);
    }
    //gcd
    ll ans=xn[0];
    for(ll i=1;i<xn.size();++i){
        ans=__gcd(ans,xn[i]);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int>P(N);
    for (int i = 0; i < N; ++i) {
        cin >> P[i];
    }

    // 一番左が最小, 追加されるのが最大ならソートされない
    set<int> se;
    for (int i = 0; i < K; ++i) {
        se.insert(P[i]);
    }

    ll ans = N - K + 1;
    int cnt = 1;
    int def = 0;
    set<int>flag;
    for (int i = 1; i < N; ++i) {
        if(P[i-1] < P[i]) {
            cnt++;
        } else{
            cnt = 1;
        }
        if(cnt >= K){
            flag.insert(i);
            def++;
            cnt--;
        }
    }
    if(def) ans = ans + 1 - def;

    for (int i = K; i < N; ++i) {
        if(*se.begin() == P[i-K] && se.upper_bound(P[i]) == se.end()){
            if(! flag.count(i)) ans--;
        }
        se.erase(P[i-K]);
        se.insert(P[i]);
    }
    cout << ans;
    return 0;
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    vector<ll> A(N);
    multiset<ll, greater<ll>> M;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        M.insert(A[i]);
    }
    int ans = 0;
    while(!M.empty()) {
        ll v = *M.begin(); M.erase(M.begin());
        ll j = 1;
        while(j <= v) j *= 2;
        if (M.find(j - v) != M.end()) {
            M.erase(M.find(j - v));
            ans++;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 11264
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);


	public static void main(String[] args) {
		//?????°?¨????
		double num;
		String str;

		while(sc.hasNext()) {
			num = sc.nextDouble();

			if(num <= 48.00) {
				str = "light fly";
			} else if(num <= 51.00) {
				str = "fly";
			} else if(num <= 54.00) {
				str = "bantam";
			} else if(num <= 57.00) {
				str = "feather";
			} else if(num <= 60.00) {
				str = "light";
			} else if(num <= 64.00) {
				str = "light welter";
			} else if(num <= 69.00) {
				str = "welter";
			} else if(num <= 75.00) {
				str = "light middle";
			} else if(num <= 81.00) {
				str = "middle";
			} else if(num <= 91.00) {
				str = "light heavy";
			} else {
				str = "heavy";
			}

			System.out.println(str);
		}

	}

}

Measured memory_bytes: 28168
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int a,n,i,x,y,z;
	x=-1;
	y=1001;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a;
		if(a>x) x=a;
		if(y>a) y=a;
	}
	z=x-y;
	cout<<z<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (ll)1e9 //10^9:∞
#define LLINF (ll)1e12
#define MOD (ll)(1e9+7) //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)
#define endl "\n"

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/



/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__


	string S;
	cin >> S;
	ll w = 0;
	vector<ll> wlist;
	REP(i, S.size()) {
		if (S[i] == 'W') {
			w++;
			wlist.PB(i);
		}
	}

	ll ans = 0;

	REP(i, w) {ans += wlist.at(i) - i;}
	cout << ans << endl;







	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, int> P;

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

	if(n>=10){
		cout << r << endl;
	}else{
		cout << r + (10-n)*100 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X, A, B ;
  cin >> X >> A >> B;
  
  if (-A + B <= 0){
    cout<< "delicious" << endl;
  }
    else if(0 <= (-A + B) && (-A + B) <= X) {
      cout << "safe" << endl;
    }
            else{
              cout << "dangerous" <<endl;
  }

            }
      
    
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < n;i++)
using ll = long long;

int main() {
  int n; cin >>n;
  vector<int> a(n+2, 0);
  int sum = 0;
  rep(i,n) {
    cin >>a[i+1];
    sum += abs(a[i+1]-a[i]);
  }
  sum+=abs(a[n]);
  rep(i,n){
    int x = abs(a[i+1]-a[i])+abs(a[i+2]-a[i+1])-abs(a[i+2]-a[i]);
    cout << sum - x << endl;
  }
  return 0;
}

Measured memory_bytes: 3768
import java.io.*;
import java.util.*;

 
public class Main{
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      
      out.println((long)Math.pow(2, Math.floor(Math.log(sc.nextDouble())/Math.log(2))+1)-1L);
      
      out.close();
   }

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;
      
   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }
   }
}

Measured memory_bytes: 21460
#include <iostream>
#include <cstdio>
#include <queue>
#include <cmath>
#include <random>
#include <fstream>
#include <string>

#define REP(i, N) for(int i = 0; i< N; i++)
using namespace std;
#define ll long long
const int INF = 1 << 29;

const int mod = 1000000007;

int main(){
    int N;
    cin >> N;
    int a[110];
    int chigau = 0;
    int kaeru = 0;
    REP(i, N){
        cin >> a[i];
        if(i > 0 && a[i] == a[i -1]){
            chigau ++;
        }else{
            kaeru += (chigau + 1) / 2;
            chigau = 0;
        }
    }
    kaeru += (chigau + 1) / 2;
    printf("%d\n", kaeru);
}


Measured memory_bytes: 888
import math
ab = n = int(input())
sqrt = math.sqrt(n)
ans = 0
for i in range(int(sqrt)+1):
  if n % (i+1) == 0:
    ab = min(n/(i+1), ab)
while(ab > 0):
  ab = ab // 10
  ans += 1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	string s;
	cin >> s;
	ll n = s.size();

	ll a = 0, b = 0;
	for (ll i = 0; i < n; i++) {
		if (s[i] == '0') a++;
		else b++;
	}
	cout << min(a, b) * 2 << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

ll moddividing(ll x,ll y){
    vector<ll> vec(30);
    rep(i,30){
        vec[i] = y;
        y = y * y % 1000000007;
    }
    ll c = x;
    c = c * vec[0] % 1000000007;
    c = c * vec[2] % 1000000007;
    c = c * vec[9] % 1000000007;
    c = c * vec[11] % 1000000007;
    c = c * vec[14] % 1000000007;
    c = c * vec[15] % 1000000007;
    c = c * vec[17] % 1000000007;
    c = c * vec[19] % 1000000007;
    c = c * vec[20] % 1000000007;
    c = c * vec[23] % 1000000007;
    c = c * vec[24] % 1000000007;
    c = c * vec[25] % 1000000007;
    c = c * vec[27] % 1000000007;
    c = c * vec[28] % 1000000007;
    c = c * vec[29] % 1000000007;
    return c;
}

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> fact(500000);
    ll num = 1;
    for (ll i = 0; i < 500000; i++){
        fact[i] = num;
        num = (num * (i + 1)) % 1000000007;
    }
    ll ans = 0;
    ans += moddividing(fact[2 * n - 1], (fact[n - 1] * fact[n]) % 1000000007);
    if (n - k > 1){
        for (ll i = 1; i < n - k; i++){
            ll comb = moddividing(fact[n], (fact[n - i] * fact[i]) % 1000000007);
            comb = (comb * moddividing(fact[n - 1], (fact[n - i] * fact[i - 1]) % 1000000007)) % 1000000007;
            ans = (ans + 1000000007 - comb) % 1000000007;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 7196
import java.util.*;
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt(),a = sc.nextInt(),b = sc.nextInt();
    boolean flg=false;
    for(int i=a;i<=b;i++){
      if(i%k==0){
        flg=true;
        break;
      }
    }
    if(flg){
      pl("OK");
    }else{
      pl("NG");
    }
  }

  public static void pr(String str){
    System.out.print(str);
  }
  public static void pl(String str){
    System.out.println(str);
  }
}


Measured memory_bytes: 35808
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#include <fstream>
#include<string.h>
#include <algorithm>
#include<math.h>
#include<vector>
#include <queue>
#include <deque> 
#define ll long long
#define M 1000000007 
#define MM 998244353
#define INF 4e18
using namespace std;

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*ll t,tcitr;
    cin>>t;
    tcitr=0;
    while(tcitr<t)
    {*/
        ll n;
        cin>>n;
        ll i,j,k;
        ll mnsm=INF,mndif=INF,mxsm=-INF,mxdif=-INF;
        for(i=0;i<n;i++)
        {
            cin>>j>>k;
            mnsm=min(mnsm,j+k);
            mxsm=max(mxsm,j+k);
            mndif=min(mndif,j-k);
            mxdif=max(mxdif,j-k);
        }
        cout<<max(mxsm-mnsm,mxdif-mndif)<<"\n";
        /*tcitr++;
    }*/
    return 0;
}


Measured memory_bytes: 3656
eval"N,K,*A="+`dd`.split*?,
S=->a{a.reduce:+}
s,*l=S[A]
1.upto(3e4){|i|s%i<1&&l<<i<<s/i}
p l.select{|d|a=A.map{|a|a%d}.sort
S[a[0,N-S[a]/d]]<=K}.max

Measured memory_bytes: 10112
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define print(x) cout << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T> >
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  string s;
  cin >> s;
  int ans = 1001001001;
  rep(i, 26) {
    string t = s;
    char c = 'a' + i;
    int cnt = 0;
    while (1) {
      bool ok = true;
      rep(j,sz(t)) ok&=(t[j]==c);
      if(ok)break;
      string tt = "";
      rep(j, sz(t) - 1) {
        if (t[j + 1] == c)
          tt.push_back(t[j + 1]);
        else
          tt.push_back(t[j]);
      }
      t = tt;
      cnt++;
    }
    mins(ans,cnt);
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
import java.awt.*;
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;
import java.time.*;
import java.util.List;


//给出两个数a,b 求出[a,b]中各位数字之和能整除原数的数的个数。
public class Main {
    int[][] dirs = new int[][]{{0, -1}, {0, 1}, {1, 0}, {-1, 0}};

    int find_max(int[] arr) {
        int max = Integer.MIN_VALUE;
        int n = arr.length;
        for (int i = 0; i < n; i++) {
            max = Math.max(max, arr[i]);
        }
        return max;
    }

    int sum(int[] arr, int md) {
        int res = 0;
        for (int i = 0; i < arr.length; i++) {
            res += arr[i];
            res %= mod;
        }
        return res;
    }

    long db(long sx, long mx, long xs) {//等比数列
        return (sx + mx) * xs / 2;
    }

    int mod = (int) 1e9 + 7;
    int mx = 0;
    long[] dp;

    ///int v = (int) 1e5;
    ///
    void solve(int n) {
        int[] res = new int[n+1];
        int x=1,y=1,z=1;
        for(int i=1;i<=100;i++){
            for(int j=1;j<=100;j++){
                for(int k=1;k<=100;k++){
                    int v = cnt(i,j,k);
                    if(v>n) break;
                    res[v]++;
                }
            }
        }

        for(int i=1;i<=n;i++){
            System.out.println(res[i]);
        }

    }
    int cnt(int x,int y,int z){
        return x*x+y*y+z*z+x*y+x*z+y*z;
    }



    public static void main(String[] args)  throws IOException {
        // Use the Scanner class
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Main test = new Main();
//        String[] s = br.readLine().split(" ");
//        int n = Integer.parseInt(s[0]);
//        int[] arr = new int[n];
//        s = br.readLine().split(" ");
//        for(int i=0;i<n;i++){
//            arr[i] = Integer.parseInt(s[i]);
//        }
        test.solve(Integer.parseInt(br.readLine()));
    }
}


Measured memory_bytes: 35680
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.14 18:21:10
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int n;
vector<vector<int>> g;
vector<int> x;
int INF = 1e9 + 6;
int dfs(int v, int p = -1) {
    vector<int> a,b;
    for(int u : g[v]) {
        if (u == p) continue;
        a.push_back(x[u]);
        b.push_back(dfs(u,v));
        if (b[b.size()-1] == INF) {
            return INF;
        }
    }
    vector<vector<int>> dp(a.size()+1,vector<int>(x[v] + 1,INF));
    for (int i = 0; i <= x[v]; i++) {
        dp[0][i] = 0;
    }
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j <= x[v]; j++) {
            if (j-a[i] >= 0 && dp[i][j-a[i]] != INF) dp[i + 1][j] = min(dp[i+1][j],dp[i][j-a[i]] + b[i]);
            if (j-b[i] >= 0 && dp[i][j-b[i]] != INF) dp[i + 1][j] = min(dp[i+1][j],dp[i][j-b[i]] + a[i]);
        }
    }
    return dp[a.size()][x[v]];
}
int main() {
    cin >> n;
    g.resize(n);
    for (int i = 0; i < n-1; i++) {
        int p;cin >> p;
        p--;
        g[i+1].push_back(p);
        g[p].push_back(i+1);
    }
    x.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    auto ans = dfs(0);
    if (ans == INF) {
        puts("IMPOSSIBLE");
    }
    else {
        puts("POSSIBLE");
    }
    return 0;
}


Measured memory_bytes: 4264
a, b, c, x = map(int, [int(input()) for i in range(4)])
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500 * i + 100 *j + 50 * k == x:
                ans += 1
print(ans)

Measured memory_bytes: 9112
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int M,D;
  cin>>M>>D;
  int cnt=0;
  REP(m,1,M+1){
    REP(d,2,D+1){
      int d1 = d%10;
      int d10 = d/10;
      if(d1<2 || d10 <2)continue;
      if(m == d1*d10){
        // DUMP(m,d10,d1);
        ++cnt;
      }
    }
  }
  cout<<cnt<<endl;

  return 0;
}


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

vector<int> v[200001];
int vis[200001]={0};
int P =0;
int dfs(int root, int p)
{
	int i;
	vis[root] = 1;
	P++;
	for(i=0; i<v[root].size(); i++)
	{
		int x = v[root][i];
		if(vis[x]==0)
		dfs(x,p);
	}
	return p;
}
int main()
{
	int n ,m, i;
	cin >> n >> m;
	while(m--)
	{
		int a,b;
		cin >> a>> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	int sz = 0;
	for(i=1;i<=n;i++)
	{
		int p = 0;
		P=0;
		if(vis[i]==0){
			dfs(i,0);
			sz = max(sz, P);
		}
			
	}
	cout<<sz<<endl;
}


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

using lint = int64_t;
#define bit(n) (lint(1) << n)
const int INF = 1e9;
const lint LINF = 1e18;

const lint MOD = 1e9 + 7;
// const lint MOD = 998244353;

class IoSetup {
    public:
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);

        cout << fixed << setprecision(12);
    }
} iosetup;

int main() {
    int n, m;
    cin >> n >> m;
    vector<lint> num(n + 1);
    for (int i = 0; i < m; i++) {
        int bad;
        cin >> bad;
        num[bad] = -1;
    }
    num[0] = 1;
    for (int i = 1; i <= n; i++) {
        if (num[i] == -1) {
            continue;
        }
        if (i == 1) {
            num[1] = max(lint(0), num[0]);
        } else {
            num[i] = (max(lint(0), num[i - 2]) + max(lint(0), num[i - 1])) % MOD;
        }
    }

    cout << max(lint(0), num[n]) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    int n;
    cin >> n;

    map<int,int> mp;
    ll total = 0;
    rep(i,n) {
        int a;
        cin >> a;
        mp[a]++;
        total += a;
    }

    int q;
    cin >> q;
    vector<P> que(q);
    rep(i,q) cin >> que[i].first >> que[i].second;

    rep(i,q) {
        int b = que[i].first, c = que[i].second;
        total = total + mp[b] * (c - b);
        mp[c] += mp[b];
        mp[b] = 0;
        cout << total << endl;
    }

    return 0;
}

Measured memory_bytes: 8536
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://agc013.contest.atcoder.jp/tasks/agc013_a>
問題文============================================================
長さ N の配列 A が与えられます。
 A を何箇所かで切って、A の連続した部分であるようないくつかの数列に分けます。
 この時、分けられたあとの数列は全て、単調非減少または単調非増加な列になっている必要があります。
 最小で何個の数列に分ければ良いかを求めて下さい。
=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> A(N); for(auto& in:A) cin >> in;
    A.erase(unique(A.begin(),A.end()),A.end());
    int mode = 0;
    int ans = 1;
    for(int i = 0 ; i < (int)A.size()-1;i++){
        if(mode == 0){
            if(A[i] < A[i+1]) mode = 1;
            else mode = -1;
        }else{
            if(mode == 1){
                if(A[i] > A[i+1]){
                    ans++;
                    mode = 0;
                }
            }else{
                if(A[i] < A[i+1]){
                    ans++;
                    mode = 0;
                }
            }
        }
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
# include <bits/stdc++.h>
using namespace std;
namespace Base{
	# define mr make_pair
	typedef long long ll;
	typedef double db;
	const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
	const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
	template<typename T> void read(T &x){
    	x = 0; int fh = 1; double num = 1.0; char ch = getchar();
		while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); }
		while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); }
	    if (ch == '.'){
	    	ch = getchar();
	    	while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();}
		}
		x = x * fh;
	}
	template<typename T> void chmax(T &x, T y){x = x < y ? y : x;}
	template<typename T> void chmin(T &x, T y){x = x > y ? y : x;}
}
using namespace Base;

const int N = 210;
ll a[N], b[N];
char s[N];
int n, m, t;
bool add(ll x){
	for (int i = 1; i <= m; i++){
		if (x > b[i]) swap(x, b[i]);
		if ((x ^ b[i]) < x) x ^= b[i];
	}
	if (x == 0) return 0;
	b[++m] = x;
	return 1;
}
int main(){
	read(t);
	while (t--){
		read(n); m = 0;
		for (int i = 1; i <= n; i++) read(a[i]);
		scanf("\n%s", s + 1);
		bool flag = true;
		for (int i = n; i >= 1; i--)
			if (add(a[i]) && s[i] == '1')
				flag = false;
		if (flag == false)
			cout << 1 << endl;
			else cout << 0 << endl; 
	} 
    return 0;
}


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

int main(){
  int N; cin >> N;
  long long sum=0;
  vector<int>d(N);
  for(int i=0;i<N;i++){
    cin >> d.at(i);
  }

  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      sum += d.at(i)*d.at(j);
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.StringTokenizer;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final BigDecimal a = BigDecimal.valueOf(scanner.nextDouble());
        final BigDecimal b = BigDecimal.valueOf(scanner.nextDouble());
        System.out.println(a.multiply(b).longValue());
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }
    }
}


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

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var N = int.Parse(inputs[0]);
        var K = int.Parse(inputs[1]);

        var kCount = 0;
        var halfKCount = 0;
        for (int i = 1; i <= N; i++)
        {
            if (i % K == 0)
            {
                kCount++;
            }

            if (K % 2 == 0 && i % K == K / 2)
            {
                halfKCount++;
            }
        }

        var ans = 0L;
        if (K % 2 == 0)
        {
            ans = pow(kCount, 3) + pow(halfKCount, 3);
        }
        else
        {
            ans = pow(kCount, 3);
        }
        Console.WriteLine(ans);
    }

    static long pow(long baseValue, long n)
    {
        var ans = 1L;
        for (long i = 1; i <= n; i++)
        {
            ans *= baseValue;
        }

        return ans;
    }
}



Measured memory_bytes: 13140
# AtCoder
N, M, X = map(int, input().split())
A = []
c = []

for i in range(N):
    lst = list(map(int, input().split()))
    c.append(lst[0])
    A.append(lst[1:])

inf = 10**9
ans = inf

for s in range(1 << N):
    un = [0]*M
    price = 0
    for i in range(N):
        if (s >> i) % 2 == 0:
            continue
        price += c[i]
        for j in range(M):
            un[j] += A[i][j]

    ok = True
    for j in range(M):
        if un[j] < X:
            ok = False
    if ok:
        ans = min(ans, price)

if ans == inf:
    print(-1)
    exit()

print(ans)


Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int sum = 0, i;
	string s;
	cin >> s;
	rep(i, s.size()) {
		sum += s[i] - '0';
	}
	if (sum % 9)
		printf("No\n");
	else
		printf("Yes\n");
	return 0;
}

Measured memory_bytes: 3692
#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() {
  int a[5];
  int x = 10000;
  int minus;  
  for ( int i = 0; i < 5; i++ ) {
    cin >> a[i];

    if ( a[i] % 10 > 0 && a[i] % 10 < x   ) {
      x = a[i] % 10;
      minus = a[i];
    }
  }
  int ans = 0;
  for ( int i = 0; i < 5; i++ ) {
    if ( a[i] == minus ) {
      a[i] = 0;
      break;
    }
  }
  //cout << minus << endl;
  for ( int i = 0; i < 5; i++ ) {
    if ( a[i] == 0 ) continue;
    int tmp = a[i];
    int k = (tmp-1)/10;
    ans += 10*(k+1);
  }
   cout << ans+minus << endl;
  return 0;
}


Measured memory_bytes: 256
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
#include <functional>

//#include "All.h"

using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    REP(i, b) tmp *= a;
    return tmp;
}

int x[10];

int main() {
    REP(i, 5) cin >> x[i];
    REP(i, 5) {
        if (x[i] == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<string> W(N);
  rep(i, N)
  {
    cin >> W[i];
  }
  map<string, int> m;
  rep(i, N)
  {
    m[W[i]]++;
    //cout << m[W[i]] << endl;
    if (m[W[i]] != 1)
    {
      cout << "No" << endl;
      return 0;
    }
    if (i != 0 && (W[i].at(0) != W[i - 1].at(W[i - 1].size() - 1)))
    {
      //  cout << W[i].at(0) << W[i - 1].at(W[i - 1].size() - 1) << endl;
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
x, y = map(int, input().split())


def gcd(x, y):
    lg = max(x, y)
    sm = min(x, y)
    div = True
    while div:
        lg_temp = sm
        sm = lg % sm
        lg = lg_temp
        if sm == 0:
            div = False
            return lg_temp




print(gcd(x, y))


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int a,b;
  cin>>a>>b;
  if(a<=0 and b>=0) cout<<"Zero"<<endl;
  else if(a>0) cout<<"Positive"<<endl;
  else{
    if((b-a+1)%2==1) cout<<"Negative"<<endl;
    else cout<<"Positive"<<endl;
  }
  return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    long long s = 0;  
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j+=i) {
            s += j;
        }
    }
    cout << s;
}


Measured memory_bytes: 3612
#include<cstdio>
using namespace std;
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b)	printf("0\n");
	else if(a<b*2)	printf("0\n");
	else	printf("%d\n",a-b*2);
	return 0;
}


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

int n, k;
long long int dp[110][100010];
long long int pref[100010];
int a[110];
const int MOD = 1e9 + 7;

int main () {
	
	cin >> n >> k;
	for (int i = 0; i < n; i ++) cin >> a[i];
	dp[n][k] = 1;
	for (int i = n-1; i >= 0; i --) {
		pref[0] = dp[i+1][0];
		for (int j = 1; j <= k; j ++) {
			pref[j] = pref[j-1] + dp[i+1][j];
		}
		
		for (int j = 0; j <= k; j ++) {
			dp[i][j] = pref[min(j+a[i], k)];
			if (j != 0) {
				dp[i][j] -= pref[j-1];
			}
			
			dp[i][j] %= MOD;
			
			//cout<< dp[i][j] << " ";
		}
		//cout << endl;
	}
	cout << dp[0][0];
	return 0;
}

Measured memory_bytes: 80128
N, K = gets.split.map(&:to_i)
S = gets.strip

A = []
x = S[0]
A << 0 if x == '0'
c = 1
for i in 1...N
  if S[i] != x
    A << c  
    x = S[i]
  end 
  c += 1
end 
A << c
A << c if x == '0'

if A.size <= K * 2 + 1
  puts A.last
else  
  m = A[K * 2]
  i = 2
  while i + K * 2 < A.size
    tmp = A[i + K * 2] - A[i - 1]
    m = tmp if tmp > m
    i += 2
  end
  puts m
end

Measured memory_bytes: 2812
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll D;
  cin>>D;
  ll c[26];
  ll s[D][26];
  rep(i,26){
    cin>>c[i];
  }
  rep(i,D){
    rep(j,26){
      cin>>s[i][j];
    }
  }
  ll t[D];
  rep(i,D){
    cin>>t[i];
  }
  ll satis=0;
  ll last[26];
  rep(i,26){
    last[i]=-1;
  }
  rep(i,D){
    satis+=s[i][t[i]-1];
    last[t[i]-1]=i;
    rep(j,26){
      satis-=c[j]*(i-last[j]);
    }
    cout<<satis<<endl;
  }
  
}

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

#define min(a, b) a < b ? a : b
#define max(a, b) a > b ? a : b

#define MAXS 200000

int main(void)
{
	int i, j, ans = 0;
	char s[MAXS + 1];

	scanf("%s", s);

	for (i = 0; i < strlen(s); i++) {
		if (s[i] == 'A') {
			break;
		}
	}
	for (j = strlen(s) - 1; j >= 0; j--) {
		if (s[j] == 'Z') {
			break;
		}
	}
	ans = j - i + 1;

	printf("%d\n", ans);

	return (0);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n; cin>>n;
  ll ans=1e12;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){ ans=min(i+n/i-2,ans); }
  }
  cout<<ans<<endl; 
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define fr first
#define se second

void solve(ll cas){
    int x;cin>>x;
    cout<<!x<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll qu=1;
    // cin>>qu;
    for(ll cas=1;cas<=qu;cas++){
        solve(cas);
    }
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAXN 510000

ll h, w, a, b, ans;
ll fac[MAXN], finv[MAXN], inv[MAXN];

void calc() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAXN; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

ll comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
    calc();
    cin >> h >> w >> a >> b;

    for(ll i = b; i <= w - 1; i++){
        ans = (ans + comb(h - 1 - a + i, i) * comb(a - 1 + w - 1 - i, a - 1) % mod) % mod;
    }
    cout << ans << endl;
}


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

void strInit(char str[]);//str[]を0で初期化
void extIntStr(char str[],int data[]);//str[]から数値(int)を抽出しdata[]に順次格納
void incsort(int data[],int len);//data[]を昇順ソート
void decsort(int data[],int len);//data[]を降順ソート
void printIntArray(int data[],int len);//data[]をprint
int* inputArray(int n);//文字列を受け取り数値を抽出、n個の数値(int)を格納した配列のポインタをreturn
int* cpyArray(int data[],int len);//配列(int)を複製した配列のポインタをreturn

//don't forget free(data);

int main(){
    int n;
    scanf("%d ",&n);
    int *data;
    int a[n];
    data = inputArray(n-1);
    a[0]=data[0];
    for(int i=1;i<n-1;i++){
        a[i]=(data[i-1]>data[i]?data[i]:data[i-1]);
    }
    a[n-1]=data[n-2];
    int sum=0;
    for(int i=0;i<n;i++){
        sum += a[i];
    }
    printf("%d",sum);
    free(data);
    return 0;
}

//temp##############################################

void strInit(char str[]){
    int len=strlen(str);
    for(int i=0;i<len;i++){
        str[i]=0;
    }
}

void extIntStr(char str[],int data[]){
    int length=strlen(str);
    str[length-1]=' ';
    char buff[12];
    int j,index;
    index=j=0;
    for(int i=0;i<length;i++){
        if(str[i]!=' '){
            buff[j++]=str[i];
        }else{
            data[index++]=atoi(buff);
            strInit(buff);
            j=0;
        }
    }
}

void incsort(int data[],int len){
    for(int i=0;i<len-1;i++){
        for(int j=i+1;j<len;j++){
            if(data[i]>data[j]){
                int tmp=data[i];
                data[i]=data[j];
                data[j]=tmp;
            }
        }
    }
}

void decsort(int data[],int len){
    for(int i=0;i<len-1;i++){
        for(int j=i+1;j<len;j++){
            if(data[i]<data[j]){
                int tmp=data[i];
                data[i]=data[j];
                data[j]=tmp;
            }
        }
    }
}

void printIntArray(int data[],int len){
    for(int i=0;i<len;i++){
        printf("%d\n",data[i]);
    }
}

int* inputArray(int n){
    int *data;
    data=(int*)malloc(sizeof(int)*n);
    char *get;
    get=(char*)malloc(sizeof(char)*11*n+1);
    fgets(get,11*n+1,stdin);
    extIntStr(get,data);
    free(get);
    return data;
}

int* cpyArray(int data[],int len){
    int *cp;
    cp=(int*)malloc(sizeof(int)*len);
    for(int i=0;i<len;i++){
        cp[i]=data[i];
    }
    return cp;
}

//temp##############################################


Measured memory_bytes: 128
S = input()

ans = [0]*len(S)
S += ' '
count = 0
last = 'R'
for i in range(len(S)):
    if S[i] != last:
        if last == "R":
            ans[i-1] += count - count // 2
            ans[i] += count // 2
        else:
            ans[i-count] += count - count // 2
            ans[i-count-1] += count // 2
        count = 1
        last = S[i]
    else:
        count += 1

print(' '.join(str(i) for i in ans))

Measured memory_bytes: 10484
from collections import defaultdict
from collections import deque
h, w = list(map(int, input().split()))
s = [list(map(str, list(input()))) for i in range(h)]  # 文字列の二次元配列入力
cnt_sharp = 0
G = defaultdict(lambda: [])
vec = [(0, 1), (0, -1), (1, 0), (-1, 0)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            cnt_sharp += 1
        for dy, dx in vec:
            if 0 <= i+dy < h and 0 <= j+dx < w and s[i+dy][j+dx] == '.':
                G[(i+dy, j+dx)].append((i, j))
# G[v]: 頂点vに隣接する頂点list
dist = defaultdict(lambda: -1)
que = deque([(0, 0)])
dist[(0, 0)] = 1
while que:
    v = que.popleft()
    d = dist[v]
    for ww in G[v]:
        if dist[ww] > -1:
            continue
        dist[ww] = d + 1
        que.append(ww)
if dist[(h-1, w-1)] == -1:
    print(-1)
else:
    print(h*w-cnt_sharp-dist[(h-1, w-1)])


Measured memory_bytes: 69828
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int h = scanner.nextInt(), w = scanner.nextInt();
			int n = scanner.nextInt();
			int[] a = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
			int[][] result = new int[h][w];
			int color = 1, currentX = 0, currentY = 0;
			for (int ai : a) {
				while (currentY + ai >= w) {
					// 改行が発生する
					fill(result, currentX, currentY, w, color);
					currentX++;
					ai -= (w - currentY);
					currentY = 0;
				}
				fill(result, currentX, currentY, currentY + ai, color);
				currentY += ai;
				color++;
			}
			IntStream.range(0, h).forEach(i -> println(result[i], i));
		}
	}

	/**
	 * 結果配列にx座標のy座標開始〜y座標終了-1までに色を塗る
	 * 
	 * @param result 結果配列
	 * @param x      x座標
	 * @param yStart y座標開始
	 * @param yEnd   y座標終了
	 * @param color  色
	 */
	private static void fill(int[][] result, int x, int yStart, int yEnd, int color) {
		for (int i = yStart; i < yEnd; i++) {
			result[x][i] = color;
		}
	}

	/**
	 * 数列を出力する
	 * 
	 * @param a      出力する数列
	 * @param lineNo 行数
	 */
	private static void println(int[] a, int lineNo) {
		if (0 == (lineNo & 1)) {
			// lineNoが偶数の場合，左から右へ出力する
			System.out.println(Arrays.stream(a).mapToObj(String::valueOf).collect(Collectors.joining(" ")));
		} else {
			// 右から左へ出力する
			System.out.println(IntStream.range(0, a.length).mapToObj(i -> String.valueOf(a[a.length - 1 - i]))
					.collect(Collectors.joining(" ")));
		}
	}
}


Measured memory_bytes: 47988
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

using namespace std;
static const long k10E7 = 1000000007;

int main()
{
    long n;
    cin >> n;

    vector<long> an(n);
    for(long& a : an){
        cin >> a;
    }

    auto first_max_it = max_element(an.begin(), an.end());
    size_t first_max_index = distance(an.begin(), first_max_it);

    const long ai_tmp = an[first_max_index];
    an[first_max_index] = 0;
    auto second_max_it = max_element(an.begin(), an.end());
    size_t second_max_index = distance(an.begin(), second_max_it); 
    an[first_max_index] = ai_tmp;

    for(size_t i = 0; i < (size_t)n; i ++){
        if(i == first_max_index){
            cout << an[second_max_index] << endl;
        } else {
            cout << an[first_max_index] << endl;
        }
    }    

    return 0;
}


Measured memory_bytes: 3200