akhauriyash/Code-Regression huggingface dataset:
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let input = readIntSplit(by: " ")
let (N, K) = (input[0], input[1])
let l = readIntSplit(by: " ").sorted().reversed()
var ans = 0
for i in 0..<K {
    ans += l[i]
}
print(ans)


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

int main(){

    string s;
    cin >> s;
    int n=s.size();
    vector<int> abc(3,0);

    for(int i=0; i<n; i++){
        if(s.at(i)=='a') abc.at(0)++;
        if(s.at(i)=='b') abc.at(1)++;
        if(s.at(i)=='c') abc.at(2)++;
    }

//    for(int i=0; i<3; i++){
//        cout << abc.at(i) << endl;
//    }

    if(abs(abc.at(0)-abc.at(1))<=1 && abs(abc.at(0)-abc.at(2))<=1 && abs(abc.at(2)-abc.at(1))<=1) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 

using namespace std;

map<long long, long long> prime_list(long long n){
  map<long long, long long> ans;
  for(long long i=2;i*i<=n;++i){
    while(n%i==0){
      ++ans[i];
      n=n/i;
    }
  }
  if(n!=1){
    ++ans[n];
  }
  return ans;
}

long long X;

int main(){
	cin >> X;
	while(1) {
		map<long long, long long> memo = prime_list(X);
		if(memo.size() == 1 && memo.count(X) == 1){
			cout << X << endl;
			return 0;
		}
		X++;
	}

}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a.rbegin(),a.rend());
    map<int,int>mp;
    const int d = a[0];
    //d = 2, 2,1,2
    //d = 4, 1--2--3--4--5, 4,3,2,3,4
    //d = 5, 1--2--3--4--5--6, 5,4,3,3,4,5
    rep(i,n){
        mp[a[i]]++;
    }
    for(int i = d; i >= d/2+1; i--){
        mp[i]-=2;
    }
    if(d%2==0){
        mp[d/2]--;
    }
    for(auto &x:mp){
        if(x.second < 0){
            cout << "Impossible" << endl;
            return 0;
        }else if(x.second > 0){
            if(x.first <= (d+1)/2){
                cout << "Impossible" << endl;
                return 0;
            }
        }
    }
    cout << "Possible" << endl;
    return 0;
}

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

Measured memory_bytes: 256
row_num, col_num = (int(i) for i in input().split())
matrix = [ list(input()) for i in range(row_num)]
transpose_matrix = []
for i in range(col_num):
    transpose_matrix.append([])
    for j in range(row_num):
        transpose_matrix[i].append(matrix[j][i])

empty_rows = []
# row check
for i,line in enumerate(matrix):
    if '#' in line:
        continue
    empty_rows.append(i)
empty_cols = []
# col check
for i,line in enumerate(transpose_matrix):
    if '#' in line:
        continue
    empty_cols.append(i)

for i in range(row_num):
    if i in empty_rows:
        continue
    for j in range(col_num):
        if j in empty_cols:
            continue
        print(matrix[i][j],end="")
    print()
        

Measured memory_bytes: 4596
#include<iostream>
#include<stdio.h>
#include<string>
#include <algorithm>
#include<cstring>
#include <math.h>
using namespace std;

int main()
{
  double x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  double ans=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  printf("%.6f\n",ans);
  return 0;
}      



Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int n;
	cin>>n; 
	long long int a[n+5];
	for(long long int i=1;i<=n;i++)
		cin>>a[i];
	long long int b[n+5];
	long long int s=0;
	for(long long int i=1;i<=n/2;i++)
		s+=a[i*2];
	long long int s2=0;
	for(long long int i=1;i<=n;i++)
		s2+=a[i];
	b[n]=s2/2-s;
	for(long long int i=n-1;i>=1;i--)
		b[i]=a[i+1]-b[i+1];
	cout<<b[n]*2<<" ";
	for(long long int i=1;i<=n-1;i++)
		cout<<b[i]*2<<" ";
} 

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

int main() {
  int N;
  cin >> N ;
  vector<int> A(N);
  for (int i;i<N;i++) {
    cin >> A[i];
  }
  int s=0;
  bool a=false;
  while(true){
    for(int i=0;i<N;i++){
      if(A[i]%2!=0) {a=true;break;}
      A[i]/=2;
    }
    if(a) break;
    s++;
  }
  cout<<s<<endl;
}


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

int main()
{
    int n,a,b,xa=0;
   scanf("%d %d %d",&n,&a,&b);
   for(int i=0;i<n;i++)
   {
        int  x;
        scanf("%d",&x);
        if(x>=a&&x<b)
            xa++;
   }
   printf("%d\n",n-xa);
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, C, d[31][31], c[51][51], cnt[3][51];
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> C;
    rep(i, 0, C) rep(j, 0, C) cin >> d[i][j];
    rep(i, 0, n) rep(j, 0, n) {
        int p;
        cin >> p;
        cnt[(i+j)%3][p-1]++;
    }
    int ans = INF;
    rep(i, 0, C) rep(j, 0, C) rep(k, 0, C) {
        if (i != j && j != k && k != i) {
            int tmp = 0;
            rep(l, 0, C) tmp += d[l][i] * cnt[0][l];
            rep(l, 0, C) tmp += d[l][j] * cnt[1][l];
            rep(l, 0, C) tmp += d[l][k] * cnt[2][l];
            ans = min(ans, tmp);            
        }
    }
    cout << ans << endl;
    return 0;
}


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



int main() 
{
  ll N,M; cin>>N>>M;
  vector<ll> keiyu(N,0);
  rep(i,M)
  {
    ll a,b; cin>>a>>b;
    a--; b--;
    if(a==0||a==N-1) {keiyu.at(b)++;}
    if(b==0||b==N-1) {keiyu.at(a)++;}
  }
  rep(i,N){if(keiyu.at(i)==2) {cout<<"POSSIBLE"<<endl; return 0;}}
  cout<<"IMPOSSIBLE"<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long
template <class Q>
void clearQueue(Q & q) {
    q = Q();
}
void solve(){
	int n,w;cin>>n>>w;
	vector<int>wt(n),val(n);
	for(int i=0;i<n;i++) cin>>wt[i]>>val[i];
	int dp[n][1000*n+5];
	for(int i=0;i<n;i++){
		for(int j=0;j<=1000*n+4;j++){
			dp[i][j]=INT_MAX;
		}
	}
	dp[0][0]=0;
	dp[0][val[0]]=wt[0];
	for(int i=1;i<n;i++){
		dp[i][0]=0;
		for(int j=1;j<=1000*n;j++){
			dp[i][j]=min(dp[i][j],dp[i-1][j]);
			if(j>=val[i]){
				dp[i][j]=min(dp[i][j],wt[i]+dp[i-1][j-val[i]]);
			}
		}
	}
	for(int i=1000*n;i>=0;i--){
		if(dp[n-1][i]<=w){
			cout<<i;return;
		}
	}
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL); 
	int T=1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

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

using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl


const ll INFL = 1LL << 60;

struct Edge{
    int to;
    ll cost;
    int from; // from は使わないことも多い
    Edge(int to, ll cost, int from = -1):to(to), cost(cost), from(from) {}
};

using EdgeList = vector<vector<Edge>>;

struct State {
    int index;
    ll cost;
    int step;
    State(int i, ll c, int step):index(i), cost(c), step(step) {}
    bool operator > (const State &r) const { return cost > r.cost; }
};

// O(ElogV)
ll dijkstra(const EdgeList &G, int start, int end) {
    priority_queue<State, vector<State>, greater<State>> que;
    vector<vector<ll>> dist(G.size(), vector<ll>(3, INFL));
    que.emplace(start, 0, 0);
    dist[start][0] = 0;
    while(not que.empty()){
        State now = que.top(); que.pop();
        int next_step = (now.step + 1) % 3;
        for(Edge e : G[now.index]){
            if(dist[e.to][next_step] > now.cost + e.cost){
                State nxt = State(e.to, now.cost + e.cost, next_step);
                dist[e.to][next_step] = nxt.cost;
                que.push(nxt);
            }
        }
    }
    return dist[end][0];
}


int main() {
    int N, M; cin >> N >> M;
    EdgeList E(N);
    rep(i, M) {
        int a, b; cin >> a >> b;
        a--; b--;
        E[a].emplace_back(b, 1, a);
    }

    int S, T; cin >> S >> T;
    S--; T--;

    ll min_dist = dijkstra(E, S, T);
    assert(min_dist == INFL or min_dist % 3 == 0);
    cout << (min_dist == INFL ? -1 : min_dist / 3) << endl;

    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


//————————Fenwick  BIT  転倒数———————————————————————

template<typename T>
class BIT{
  public:
    int N;
    vector<T> data;
    BIT(T _N):N(_N){
        data.assign(N+1, 0);
    };
    
    // a is 1-indexed
    void add(int a, T w){
        for(int x = a; x <= N; x += x & -x) data[x] += w;
    }
    // 1-indexed sum of prefix [0, a]
    T sum(int a){
        T res = 0;
        for(int x = a; x > 0; x -= x & -x) res += data[x];
        return res;
    }
    // 1-indexed sum of range [l, r]
    T sum(int l, int r){return sum(r) - sum(l-1);}

    // 0-indexed add
    void add0(int a, T w){add(a + 1, w);}
    // 0-indexed sum
    T sum0(int a){return sum(a + 1);}
    // 0-indexed sum of range
    T sum0(int l, int r){return sum0(r) - sum0(l-1);}

    //1-indexed でv1+v2+...+vx >= w となる最小のx
    T blb(T w) {
      if(w <= 0) return 0;
      int res = 0;
      int i=1;
      while(i*2 <= N) {i *= 2;}
      //i は N以下の最大の２べき
      for(int k = i; k > 0; k /= 2) {
        if(res + k <= N && data[res + k] < w) {
          w -= data[res + k];
          res += k;
        }
      }
      return res+1;
    }

    /* debug */
    void print() {
        rep(i,N) cout << sum0(i,i) << ",";
        cout << endl;
    }

};


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

  int n,m;
  string s; 
  cin>>n>>s>>m;

  vector<BIT<int>> bit(26,BIT<int>(n));
  rep(i,n){
    bit[s[i]-'a'].add0(i,1);
  }

  int a,b,d;
  char c;
  rep(i,m){
    cin>>a;
    if(a==1) {
      cin>>b>>c;
      bit[s[b-1]-'a'].add(b,-1);
      bit[c-'a'].add(b,1);
      s[b-1]=c;
    }
    if(a==2){
      cin>>b>>d;
      int res=0;
      rep(j,26){
        if(bit[j].sum(b,d)) res++;
      }
      cout << res << endl;
    }
  }

}


Measured memory_bytes: 56536
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};

struct edge{ll from,to,cost;};

void bfs(ll s,vvll tt,vb &ch,ll n){
  vb gg(n,false);
  gg[s]=true;
  queue<ll> que;
  que.pu(s);
  while(sz(que)){
    ll now=que.front();
    que.pop();
    for(auto p:tt[now]){
      if(gg[p]) continue;
      gg[p]=true;
      que.pu(p);
    }
  }
  rep(i,n){
    ch[i]=gg[i]&ch[i];
  }
}
void rbfs(ll s,vvll ttt,vb &ch,ll n){
  vb gg(n,false);
  gg[s]=true;
  queue<ll> que;
  que.pu(s);
  while(sz(que)){
    ll now=que.front();
    que.pop();
    for(auto p:ttt[now]){
      if(gg[p]) continue;
      gg[p]=true;
      que.pu(p);
    }
  }
  rep(i,n){
    ch[i]=gg[i]&ch[i];
  }
}
int main(){
  ll n,m;cin>>n>>m;
  vector<edge> t(m);
  vvll tt(n,vll(0));
  vvll ttt(n,vll(0));
  vb ch(n,true);
  rep(i,m){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    tt[a].pb(b);
    ttt[b].pb(a);
    edge e;
    e.from=a;
    e.to=b;
    e.cost=-1*c;
    t[i]=e;
  }
  bfs(0,tt,ch,n);
  rbfs(n-1,ttt,ch,n);
  vll d(n,INF);
  d[0]=0;
  ll cu=0;
  while(1){
    bool up=false;
    rep(i,m){
      edge e=t[i];
      if(ch[e.from]&&ch[e.to]&&d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
        d[e.to]=d[e.from]+e.cost;
        up=true;
        if(cu==n-1){
          COUT("inf");
          return 0;
        }
      }
    }
    
    cu++;
    if(!up) break;
  }
  COUT(-1*d[n-1]);
}

Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
	int n, m;
	cin >> n >> m;
    vector<int> ac(n), wa(n);
    rep(i,m) {
        int p;
        string s;
        cin >> p >> s;
        --p;
        if (ac[p]) continue;
        if (s == "AC") ac[p] = 1;
        else           wa[p]++;
    }
    int ac_cnt = 0, wa_cnt = 0;
    rep(i,n) {
        ac_cnt += ac[i];
        if (ac[i]) wa_cnt += wa[i];
    }
    printf("%d %d\n", ac_cnt, wa_cnt);
	// cout << ac_cnt << ' ' << wa_cnt << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
using namespace std;

const long long int mod=998244353;
const long long int INF=99999999999999999;

long long int n,m,sum=0,res;
int main() {
	cout << fixed << setprecision(10);
    cin>>n;
    cout<<n*n;
} 


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

int main(){
  int n[10001],i=1,ans=0;
  while(1){
    cin >> n[i];
    if(n[i]==0){
      break;
    }
    i++;
    ans++;
  }
  for(i=1;i<=ans;i++){
    cout << "Case " << i << ": " << n[i] << '\n';
  }
  return 0;
}



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

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}
const long long INF = 1LL<<60;

const int DIAGONAL = 0;
const int HORIZONTAL = 1;
const int VERTICAL = 2;

int main(){
    string s, t; cin >> s >> t;
    vector<vector<int> > dp(s.size()+1, vector<int>(t.size()+1, 0));
    vector<vector<int> > pointer(s.size()+1, vector<int>(t.size()+1, 0));
    // DP
    for(int i = 1; i <= s.size(); i++) {
        for(int j = 1; j <= t.size(); j++) {
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
                pointer[i][j] = DIAGONAL;
            }
            else {
                dp[i][j] = dp[i - 1][j];
                pointer[i][j] = VERTICAL;
                if (dp[i][j] < dp[i][j - 1]) {
                    dp[i][j] = dp[i][j - 1];
                    pointer[i][j] = HORIZONTAL;
                }
            }   
        }
    }
    // view(dp);
    // trace back
    int ss = s.size();
    int tt = t.size();
    string lcs;
    while (ss > 0 && tt > 0) {
        if (s[ss - 1] == t[tt - 1]) lcs += s[ss - 1];
        if (pointer[ss][tt] == DIAGONAL) {
            ss--;
            tt--;
        } else if (pointer[ss][tt] == VERTICAL) {
            ss--;
        } else {
            tt--;
        }
    }
    reverse(lcs.begin(), lcs.end());
    cout << lcs << endl;
    // view(pointer);
    return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <locale>
using namespace std;
#define FORN(i,m,n) for(int i=m; i<(n); i++)
#define PRINTVEC(v) FORN(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define PRINTMAT(m) FORN(j,0,m.size()) {PRINTVEC(m[j]);}
#define p_b(x) push_back(x)
#define m_p(a,b) make_pair(a,b)
typedef long long ll;

int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int n; cin>>n;
  vector<double> v(n);
  FORN(i,0,n) cin>>v[i];
  FORN(i,0,n) v[i] = 1 / v[i];
  double sum = 0;
  FORN(i,0,n) sum += v[i];
  cout<<fixed<<setprecision(10)<<1/sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,m;
   cin >> n >> m;
   int x,sm = 0;
   f(i,0,m){
      cin >> x;
      sm += x;
   }
   if(sm<=n){
      cout << n-sm;
   }else{
      cout << "-1\n";
   }
   return 0;
} 


Measured memory_bytes: 3624
n = int(input())
block = [list(map(lambda x: int(x), input().split())) for _ in range(2)]
dp = [[0] * n] * 2

for row in range(2):
  for column in range(n):
    numbers = []
    if column != 0:
      numbers.append(dp[row][column - 1])
    if row != 0:
      numbers.append(dp[row - 1][column])
    if len(numbers) > 0:
      dp[row][column] = max(numbers) + block[row][column]
    else: 
      dp[row][column] = block[row][column]

print(dp[1][n - 1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	double a[30000];
	cin>>n;
	for (int i=0;i<n;i++)cin>> a[i];
	double dp[3001][3001];
	dp[0][0]=1;
	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<=i;j++)
		{
			if (j) dp[i][j]+=dp[i-1][j-1]*a[i-1];
			dp[i][j]+=dp[i-1][j]*(1-a[i-1]);
			
		}
	}
	double ans=0; 
	for (int i=0;i<=n;i++)
	{
		if (i>n-i) ans+=dp[n][i];
	}
	printf("%.12f\n",ans);
	return 0;
}

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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M] [L];

int getChar(char ch) {
if ( ch == 'A' ) return 1;
else if ( ch == 'C' ) return 2;
else if ( ch == 'G' ) return 3;
else if ( ch == 'I' ) return 4;
else return 0;
}

long long getKey(char str[]) {
	long long sum = 0, p = 1, i;
	for (i = 0; i < strlen(str); i++ ) {
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key){ return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[]) {
	long long key, i, h;
	key = getKey(str);
	for (i = 0;; i++ ) {
		h = (h1(key) + i * h2(key)) % M;
		if ( strcmp(H[h],str) == 0 ) return 1;
		else if ( strlen(H[h]) == 0 ) return 0;
	}
	return 0;
}

int insert(char str[]) {
	long long key, i, h;
	key = getKey(str);
	for (i = 0; ; i++ ) {
		h = (h1(key) + i * h2(key)) % M;
		if ( strcmp(H[h],str) == 0 ) return 1;
		else if ( strlen(H[h]) == 0 ) {
			strcpy(H[h], str);
			return 0;
		}
	}
	return 0;
}

int main() {
	int i, n, h;
	char str[L], com[9];
	for (i = 0; i < M; i++ ) H[i][0] = '\0';
	scanf("%d", &n);
	for (i = 0; i <n; i++){
		scanf("%s %s", com, str);

		if ( com[0] == 'i' ) {
			insert(str);
		} else {
			if ( find(str)){
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}
	return 0;
}


Measured memory_bytes: 16100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;} return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;} return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    rep(i,S.size()){
        int x=S[i]-'A';
        x=(x+23)%26;
        S[i]=(char)x+'A';
    }
    cout << S << endl;
}


Measured memory_bytes: 3180
#include<iostream>
#include<set>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		int sum = 0;
		for (int i = 0; i < n / 4; i++) {
			int a;
			cin >> a;
			sum += a;
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 3080
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<int> A(N+2);
  for (size_t i = 1; i <= N; ++i)
    scanf("%d", &A[i]);

  int whole = 0;
  for (size_t i = 1; i <= N+1; ++i)
    whole += abs(A[i]-A[i-1]);

  for (size_t i = 1; i <= N; ++i) {
    int cur = whole;
    cur -= abs(A[i]-A[i-1]);
    cur -= abs(A[i+1]-A[i]);
    cur += abs(A[i+1]-A[i-1]);
    printf("%d\n", cur);
  }
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    cout << fixed << setprecision(15);
    ll r, D, x;
    cin >> r >> D >> x;
    
    ll ans = x;
    for(int i=0; i<10; i++){
        ans = r*ans - D;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 384
if __name__ == '__main__':
    N = int(input())
    H = [int(i) for i in input().split()]
    step_max = 0
    step = 0
    for i in range(N-1):
        if H[i] >= H[i+1]:
            step += 1
        else:
            step_max = max(step_max, step)
            step = 0
    step_max = max(step_max, step)
    print(step_max)


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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i >= 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define INFD 1e18
#define PI 3.14159265358979
#define MOD 1000000007
#define vl vector<ll>

vector<ll> dx = {-1, 1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


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

	vector<ll> A(N);
	REP(i, N) cin >> A[i];
	reverse(ALL(A));

	vector<ll> dp(N, INF);
	REP(i, N) {
		*upper_bound(ALL(dp), A[i]) = A[i];
	}
	auto iter = lower_bound(ALL(dp), INF);
	PRINT(distance(dp.begin(), iter));
	return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#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 ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> L(N);
    rep(i,N) cin >> L[i];

    sort(all(L));
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            for (int k = j+1; k < N; k++) {
                if (L[i] + L[j] <= L[k]) break;
                ans++;
            }
        }
    }

    cout << ans << ln;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n, m, q; std::cin >> n >> m >> q;
    std::vector<std::vector<int>> cnt(n + 2, std::vector<int>(n + 2));
    for (int i = 0; i < m; i++) {
        int a, b; std::cin >> a >> b;
        cnt[b][a]++;
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            cnt[i + 1][j] += cnt[i][j];
        }
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            cnt[i][j + 1] += cnt[i][j];
        }
    }
    while (q--) {
        int a, b; std::cin >> a >> b;
        std::cout << cnt[b][n] - cnt[b][a - 1] << std::endl;
    }
    return 0;
}


Measured memory_bytes: 1920
import sys

w = sys.stdin.readline().strip().lower()

cnt = 0
while True:
    line = sys.stdin.readline().strip()
    if line == 'END_OF_TEXT':
        break
        
    words = line.split(' ')
    for i in words:
        if i.lower() == w:
            cnt += 1

print(cnt)

Measured memory_bytes: 7440
#include<cstdio>
#include<cstring>
using namespace std;

int w,h,sx,sy,visit[100][100],cnt;
char s[100][100];

void dfs(int x,int y){
    visit[x][y]=1;
    if(x>0&&s[x-1][y]=='.'&&!visit[x-1][y]){
        dfs(x-1,y);
    }
    if(x<h-1&&s[x+1][y]=='.'&&!visit[x+1][y]){
        dfs(x+1,y);
    }
    if(y>0&&s[x][y-1]=='.'&&!visit[x][y-1]){
        dfs(x,y-1);
    }
    if(y<w-1&&s[x][y+1]=='.'&&!visit[x][y+1]){
        dfs(x,y+1);
    }
}

int main(){
    scanf("%d %d",&w,&h);
    while(w&&h){
        for(int i=0;i<h;i++){
            scanf("%s",s[i]);
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(s[i][j]=='@'){
                    sx=i;
                    sy=j;
                }
                visit[i][j]=0;
            }
        }
        dfs(sx,sy);
        cnt=0;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cnt+=visit[i][j];
            }
        }
        printf("%d\n",cnt);
        scanf("%d %d",&w,&h);
    }
}


Measured memory_bytes: 2620
#include <cstdio>
#include <iostream>
#include <string>
#define INF (1<<21)
using namespace std;

int main(){
  int i,j,k,l,n,nn,a,min;
  int m[4],ma[4],min2[4];
  bool f=false;
  while(1){
    cin >> n;
    if(n == 0) break;

    if(f) cout << endl;
    f = true;
    cin >> m[0] >> m[1] >> m[2] >> m[3];

    for(i=0;i<4;i++) min2[i] = 0;

    min = INF;
    for(i=0;i<=m[0];i++){
      for(j=0;j<=m[1];j++){
	for(k=0;k<=m[2];k++){
	  for(l=0;l<=m[3];l++){
	    nn = n;
	    nn = i*10 + j*50 + k*100 + l*500 - nn;
	    if(nn < 0) continue;

	    a = m[0]-i + m[1]-j + m[2]-k + m[3]-l;
	    // printf("i=%d,j=%d,k=%d,l=%d [%d]",i,j,k,l,a);

	    for(int ii=0;ii<4;ii++){
	      ma[ii] = 0;
	    }

	    while(nn >= 500){
	      nn -= 500;
	      a++;
	    }
	    while(nn >= 100){
	      nn -= 100;
	      a++;
	    }
	    while(nn >= 50){
	      nn -= 50;
	      a++;
	    }
	    while(nn >= 10){
	      nn -= 10;
	      a++;
	    }
	    //cout << " <"<< a  << ">" << endl;
	    if(min > a){
	      min = a;
	      min2[3] = l;
	      min2[2] = k;
	      min2[1] = j;
	      min2[0] = i;
	    }
	  }
	}
      }
    }
    if(min2[0]) cout << "10 " << min2[0] << endl;
    if(min2[1]) cout << "50 " << min2[1] << endl;
    if(min2[2]) cout << "100 " << min2[2] << endl;
    if(min2[3]) cout << "500 " << min2[3] << endl;
  }
  return 0;
}

Measured memory_bytes: 868
p = 998244353
n, k = map(int, input().split())
LRs = []
for j in range(k):
    lj, rj = map(int, input().split())
    LRs.append((lj, rj))
A = [0] * (n + 1)
i0 = min(lj for lj, rj in LRs)
A[0] = 1
A[i0] = 1
for i in range(i0 + 1, n):
    A[i] = A[i - 1]
    for j in range(k):
        lj, rj = LRs[j]
        if i - lj >= 0:
            A[i] += A[i - lj]
        if i - 1 - rj >= 0:
            A[i] -= A[i - 1 - rj]
        A[i] %= p
print(A[n - 1])


Measured memory_bytes: 16820
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.root = [-1] * (n + 1)
		self.rank = [0] * (n + 1)

	def find(self, x):
		if self.root[x] < 0:
			return x
		else:
			self.root[x] = self.find(self.root[x])
			return self.root[x]

	def unite(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x == y:
			return 0
		elif self.rank[x] > self.rank[y]:
			self.root[x] += self.root[y]
			self.root[y] = x
		else:
			self.root[y] += self.root[x]
			self.root[x] = y
			if self.rank[x] == self.rank[y]:
				self.rank[y] += 1

	def isSame(self, x, y):
		return self.find(x) == self.find(y)

	def size(self, x):
		return - self.root[self.find(x)]

import sys
input = sys.stdin.buffer.readline
from collections import Counter
n,k,l=map(int,input().split())
uf1=UnionFind(n)
uf2=UnionFind(n)
for _ in range(k):
	uf1.unite(*map(int,input().split()))
for _ in range(l):
	uf2.unite(*map(int,input().split()))
ps=[(uf1.find(i),uf2.find(i)) for i in range(1,n+1)]
C=Counter(ps)
ans=[]
for i in range(n):
	if ps[i][0]<0 or ps[i][1]<0:
		ans.append(0)
	else:
		ans.append(C[ps[i]])
print(*ans)

Measured memory_bytes: 47324
#include <stdio.h>
int main()
{
	int a[51]={0},n,m,i,j;
	scanf("%d%d",&n,&m);
	while(m--)
	{
		scanf("%d%d",&i,&j);
		a[i]++;	a[j]++;
	}
	for(i=1;i<=n;i++)
	printf("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 128
H,W,K = map(int,input().split())
K -= 1
MOD = 10**9+7

dp = [[0]*W for i in range(H+1)]
dp[0][0] = 1

for i in range(H):
    for b in range(1<<(W-1)):
        if '11' in bin(b): continue
        b <<= 1
        for k in range(W):
            if b&(1<<k):
                dp[i+1][k] += dp[i][k-1]
            elif b&(1<<(k+1)):
                dp[i+1][k] += dp[i][k+1]
            else:
                dp[i+1][k] += dp[i][k]
            dp[i+1][k] %= MOD

print(dp[-1][K])

Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int lcm(int a,int b)
{
	if(a<b)swap(a,b);
	a/=__gcd(a,b);
	return a*b;
}
int32_t main()
{
	int n=in();
	vector<int> a(n);
	trav(i,a)i=in();sort(all(a));
	int ans=1;
	
	for(auto i:a)
	{
		ans=lcm(ans,i);
	}
	cout<<ans;
	
	
}

Measured memory_bytes: 3696
#include<bits/stdc++.h>    
using namespace std;
#define ll long long 
#define pi pair<ll,ll>
#define pd pair<ld,ld>
#define pb push_back
#define inf 1e16
#define mod 1000000007
#define en '\n'
#define ld long double
#define ff first
#define ss second
#define ull unsigned long long 
ll pw(ll b, ll r, ll md){
	ll ans = 1;
	while(r){
		if(r&1)ans = (ans*b)%md;
		b = (b*b)%md;
		r>>=1;
	}
	return ans;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,m;cin>>n>>m;
	ll ans = ((n*(n-1))>>1)+((m*(m-1))>>1);
	cout<<ans<<en;
	return 0 ; 
}



Measured memory_bytes: 256
#include <cstdio>

using namespace std;

const int table[] = { 0, 1, 2, 3, 5, 7, 8, 9 };

void solve(int n){
    
    if(n >= 8){
        solve(n / 8);
    }
    
    printf("%d", table[n % 8]);
}

int main(){
    int n;
    
    while(scanf("%d", &n), n > 0){
        solve(n);
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0; i<n ; ++i)
#define lpx(i,x,n) for(int i=x; i<n ; ++i)
#define all(v) v.begin() , v.end()
#define sz(v) (int(v.size()))
typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<char, int> pci;
typedef vector<pii> vp;
typedef vector<pci> vpc;
typedef pair<int,pii> piii;

int OO = 2e9;
const double eps = 1e-9 ;
const int N = 500000;
int mx = -1e9 , mn = 1e9 ;
pii arr[N] ;

int dcmp(double x, double y)
{
    return fabs(x - y) <= eps ? 0 : x > y ? -1 : 1;
}
ul fac(int n)
{
    if(n > 1)
        return n * fac(n - 1);
    else
        return 1;
}



int main()
{
    string a, b; cin>> a>> b;
    int ans = 0;
    lp(i,a.size()){
        if(a[i]==b[i])++ans;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int l;
   cin >> l;
   printf("%.6lf", pow(((double)l / 3), 3));
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
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 (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

int n, a[100005], w[100005];
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> n; 
  rep(i, 0, n) cin >> a[i];

  // w_0
  int t = 0;
  rep(i, 0, n) t += (i % 2 ? -1 : 1) * a[i];
  w[0] = t / 2;
  
  // w_1 to w_n-1
  rep(i, 1, n) {
    w[i] = a[i-1] - w[i-1];
  }
  rep(i, 0, n) {
    cout << 2 * w[i] << (i == n-1 ? "\n" : " ");
  }
  return 0;
}



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

const int MAX=1005,INF=1e9;
int m,n,f[MAX][MAX];
char a[MAX][MAX];

int main() {
#ifdef ACM
	freopen("input","r",stdin);
#endif
	cin>>m>>n;
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++)
			cin>>a[i][j];
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++) {
			if(i==1&&j==1)
				f[i][j]=(a[1][1]=='#');
			else {
				f[i][j]=INF;
				if(i>1)
					f[i][j]=min(f[i][j],f[i-1][j]+(a[i-1][j]=='.'&&a[i][j]=='#'));
				if(j>1)
					f[i][j]=min(f[i][j],f[i][j-1]+(a[i][j-1]=='.'&&a[i][j]=='#'));
			}
		}
	cout<<f[m][n];
}



Measured memory_bytes: 768
#include<stdio.h>

int main(){
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if (x - r >= 0 && y - r >= 0 
        && x + r <= W && y + r <= H){
            printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try(Scanner sc = new Scanner(System.in)) {

			String s = sc.next();
			int ans = 0;
			if("SUN".equals(s)) {
				ans = 7;
			}
			if("MON".equals(s)) {
				ans = 6;
			}
			if("TUE".equals(s)) {
				ans = 5;
			}
			if("WED".equals(s)) {
				ans = 4;
			}
			if("THU".equals(s)) {
				ans = 3;
			}
			if("FRI".equals(s)) {
				ans = 2;
			}
			if("SAT".equals(s)) {
				ans = 1;
			}

			System.out.println(ans);

		}

	}

}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++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;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int w, a, b;
    cin >> w >> a >> b;
    if( a > b ) swap(a, b);
    if( a + w >= b ) {
        cout << 0 << endl;

    } else {
        cout << b - (a + w) << endl;

    }
    return 0;
}



Measured memory_bytes: 256
_n = gets.to_i
as = gets.split.map(&:to_i)

if as.include?(0)
  puts '0'
  exit
end

MAX = 10 ** 18

result = 1
as.each do |i|
  result *= i
  if result > MAX
    puts '-1'
    exit
  end
end

puts result


Measured memory_bytes: 21580
s, t = [input() for _ in range(2)]
max_count = 0
for i in range(len(s) - len(t) + 1):
    m_count = 0
    for j in range(len(t)):
        if s[i:][j] == t[j]:
            m_count += 1
    if max_count < m_count:
        max_count = m_count

print(len(t)-max_count)



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

int main()
{
    int a[3][3],b,c,flag=0;
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
        {
            cin>>a[i][j];
        }
    }
    cin>>b;
    int counter=0;
    for(int i=0; i<b; i++)
    {
        cin>>c;
        for(int j=0; j<3; j++)
        {
            for(int k=0; k<3; k++)
            {
                if(a[j][k]==c)
                {
                    a[j][k]=-1;
                }
            }
        }
    }
    for(int i=0; i<3; i++)
    {
        if(a[i][0]==-1 && a[i][1]==-1 && a[i][2]==-1)
        {
            flag=1;
            break;
        }
        flag=0;
    }
    if(flag==0)
    {
        for(int i=0; i<3; i++)
        {
            if(a[0][i]==-1 && a[1][i]==-1 && a[2][i]==-1)
            {
                flag=1;
                break;
            }
            flag=0;
        }
    }
    if(flag==0)
    {
        if(a[0][2]==-1 && a[1][1]==-1 && a[2][0]==-1)
        {
            flag=1;
        }
    }
    if(flag==0)
    {
        if(a[0][0]==-1 && a[1][1]==-1 && a[2][2]==-1)
        {
            flag=1;
        }
    }
    if(flag)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define prvp(a) for(auto x : a) cout << "{" << x.ff << ',' << x.ss << "}";cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(int a, int b){return (int)((long long) a * b % mod);}
inline int modexpo(int a, int b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(int a, int b){ return mul(a, modexpo(b, mod - 2));}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

void pre(){ // Reset each global variable (esp. for graphs)
  
}

void solve(){
  ll n, ans = 0;
  cin >> n;
  if(n & 1){
    cout << 0 << '\n';
  }else{
    ll m = n / 2;
    ll two = m, five = 0;
    ll p = m;
    while(p){
      two += p / 2;
      p /= 2;
    }
    p = m;
    while(p){
      five += p / 5;
      p /= 5;
    }
    cout << min(two, five) << '\n';
  }
}

int main(){
  fastio

  pre();

  int t = 1;
  // cin >> t;
  while(t--){
    solve();
  }

  ktj();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef unsigned long long UL;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	vector<string> M,A,R,C,H;
	int i;
	string S;
	for (i=0;i<N;i++){
		cin>>S;
		switch(S[0]){
			case 'M':
				M.push_back(S);
				break;
			case 'A':
				A.push_back(S);
				break;
			case 'R':
				R.push_back(S);
				break;
			case 'C':
				C.push_back(S);
				break;
			case 'H':
				H.push_back(S);
				break;
		}
	}
	UL m=M.size();
	UL a=A.size();
	UL r=R.size();
	UL c=C.size();
	UL h=H.size();
	UL num=m*a*c+m*a*h+m*r*a+m*r*c+m*h*r+m*h*c+a*r*c+a*c*h+r*c*h+a*r*h;
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 5748
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  long long X = 0, x = 0, res = 1000000000000000000LL;
  vector<long long> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
    X += a[i];
  }
  for(int i = 0; i < n; i++){
    x += a[i];
    if(i+1 < n) res = min(abs(X-2*x), res);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1792