akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;

// Frog1
// int frog(int i, int n, vector<int> arr) {
// 	if (i >= n)
// 		return INT_MAX / 2;

// 	if (i == n - 1)
// 		return 0;

// 	int op1 = abs(arr[i] - arr[i + 1]) + frog(i + 1, n, arr);
// 	int op2 = abs(arr[i] - arr[i + 2]) + frog(i + 2, n, arr);
// 	return min(op1, op2);
// }


// int frog2(int i, int n, int k, vector<int> arr) {
// 	if (i >= n)
// 		return INT_MAX / 2;

// 	if (i == n - 1)
// 		return 0;

// 	int ans = abs(arr[i] - arr[i + 1]) + frog2(i + 1, n, k, arr);
// 	for (int j = 2; j <= k; j++) {
// 		if (i + j < n)
// 			ans = min(ans, abs(arr[i] - arr[i + j]) + frog2(i + j, n, k, arr));
// 	}
// 	return ans;
// }

// Vacation Top Down
// int dp[1000000][3];
// int Vac(int arr[][3], int i, int n, int last) {
// 	if (i >= n)
// 		return 0;

// 	if (last >= 0 && dp[i][last] != -1)
// 		return dp[i][last];

// 	int max_ele = INT_MIN;
// 	for (int j = 0; j < 3; j++) {
// 		if (j != last) {
// 			max_ele = max(arr[i][j] + Vac(arr, i + 1, n, j), max_ele);
// 		}
// 	}
// 	if (last >= 0)
// 		dp[i][last] = max_ele;
// 	return max_ele;
// }


int main() {
	int n;
	cin >> n;
	// vector<int> arr(n);
	// for (int i = 0; i < n; i++)
	// 	cin >> arr[i];
	// dp.resize(n, vector<int>(3, -1));
	// memset(dp, -1, sizeof(dp));
	// vector<vector<int>> arr(n, vector<int>(3));
	int arr[n][3];
	for (int i = 0; i < n; i++)
		cin >> arr[i][0] >> arr[i][1] >> arr[i][2];


	int dp[n][3];
	dp[0][0] = arr[0][0];
	dp[0][1] = arr[0][1];
	dp[0][2] = arr[0][2];
	for (int i = 1; i < n; i++) {
		dp[i][0] = arr[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = arr[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = arr[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
	}
	cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
	// cout << Vac(arr, 0, n, -1);
	// vector<int> dp(n, INT_MAX);
	// dp[0] = 0;
	// for (int i = 0; i < n; i++) {
	// 	for (int j = 1; j <= k; j++) {
	// 		if (i + j < n) {
	// 			dp[i + j] = min(dp[i + j], abs(arr[i] - arr[i + j]) + dp[i]);
	// 		}
	// 	}
	// }
	// cout << dp[n - 1];
	// cout << frog2(0, n, k, arr);
	// cout << frog(0, n, arr);
	// vector<int> dp(n);
	// dp[0] = 0;
	// dp[1] = abs(arr[0] - arr[1]);
	// for (int i = 2; i < n; i++) {
	// 	int one = dp[i - 1] + abs(arr[i] - arr[i - 1]);
	// 	int two = dp[i - 2] + abs(arr[i] - arr[i - 2]);
	// 	dp[i] = min(one, two);
	// }
	// cout << dp[n - 1];
	return 0;
}

Measured memory_bytes: 5924
#include<stdio.h>
#define M 100000

int A[M],n;

int partition(int ,int );

int main(){
  int i,q;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  q=partition(0,n-1);
  for(i=0;i<n;i++){
    if(i>0)printf(" ");
    if(i==q)printf("[");
    printf("%d",A[i]);
    if(i==q)printf("]");
  }
  printf("\n");

}

int partition(int p,int r){
  int x,j,i,l;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      l=A[i];
      A[i]=A[j];
      A[j]=l;
    }
  }
    l=A[i+1];
    A[i+1]=A[r];
    A[r]=l;
    return i+1;
}



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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

class Cycle {
 private:
  ll _index = 1;
  ll _cycle_entrance = -1;
  ll _cycle_length = -1;
  ll _cycle_sum = 0;

  vector<ll> _list;
  map<ll, ll> _m;

 public:
  Cycle() {
    _list.emplace_back(-1);  // dummy
  }

  bool add(ll value) {
    if (_m[value]) {
      _cycle_entrance = _m[value];
      _cycle_length = _index - _cycle_entrance;

      ll cycle_sum = 0;
      for (ll i = 0; i < _cycle_length; i++) {
        ll index = _cycle_entrance + i;
        cycle_sum += _list[index];
      }
      _cycle_sum = cycle_sum;

      return false;
    }

    _m[value] = _index;
    _list.emplace_back(value);
    _index++;
    return true;
  }

  ll sum(ll length) {
    ll result = 0;
    ll rest = length;

    for (ll i = 1; i < _cycle_entrance; i++) {
      if (rest <= 0) {
        break;
      }
      result += _list[i];
      rest--;
    }
    ll cycle_num = rest / _cycle_length;
    result += (_cycle_sum * cycle_num);

    rest = rest % _cycle_length;

    for (ll i = 0; i < rest; i++) {
      ll index = _cycle_entrance + i;
      result += _list[index];
    }
    return result;
  }
};

int main() {
  ll N, X, M;
  scanf("%lld %lld %lld", &N, &X, &M);

  auto cycle = Cycle();

  ll x = X;
  for (;;) {
    if (!cycle.add(x)) {
      break;
    }
    x = x * x % M;
  }

  cout << (cycle.sum(N)) << endl;
}


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

const int dx[] = {0, 0, -1, 1};
const int dy[] = {1, -1, 0, 0};
int W, H;
char board[30][30];

int dfs(int y, int x) {
   board[y][x] = '#';
   int ret = 1;
   for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx >= 0 && nx < W && ny >= 0 && ny < H && board[ny][nx] == '.') {
         ret += dfs(ny, nx);
      }
   }
   return ret;
}

int main() {
   while (cin >> W >> H, W) {
      for (int i = 0; i < H; i++) {
         cin >> board[i];
      }
      for (int i = 0; i < H; i++) {
         for (int j = 0; j < W; j++) {
            if (board[i][j] == '@') {
               cout << dfs(i, j) << endl;
            }
         }
      }
   }

   return 0;
}


Measured memory_bytes: 3028
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// How to use 「map」
/*
  - 宣言
    map<{key_type}, {value_type}> salary;
  - 要素の挿入
    salary["Alice"] = 1000;
  - 要素の取得 O(logn)
    salary.at("Alice");
  - 要素の削除
    salary.erase("Alice");
  - キー検索
    salary.find("Alice"); -> true
    salary.find("Bob");   -> false
  - イテレーション
    for(auto& [key, value] : salary) {...}
 */
// -------------------------------------


// How to use 「lower_bound」, 「upper_bound」
/*
  vector<int> a = {1, 2, 3, 4, 5};
  auto iter1 = lower_bound(all(a), 3);  <- 第二引数「以上」の最小イテレータが返る
  auto iter2 = upper_bound(all(a), 3);  <- 第二引数「より大きい」最小のイテレータが返る
 */
// -------------------------------------


// How to use 「struct sort」
/*
  struct Person {
    string name;
    int age;

    Person(string _name, int _age) {
      name = _name;
      age = _age;
    }

    bool operator<(const Person &another) const {
      return age < another.age;
    }
  };

  vector<Person> people;
  people.pb(Person("Alice", 20));
  people.pb(Person("Bob", 19));
  people.pb(Person("John", 40));
  people.pb(Person("Chris", 30));
  sort(all(people));
 */
 // -------------------------------------

// -------------------------------------------------------------------------------------



int main() {
  int n;

  cin >> n;

  int count[n];
  rep(i, n) {
    count[i] = 0;
  }

  int d[n], max_d = 0;
  rep(i, n) {
    cin >> d[i];
    count[d[i]]++;
    max_d = max(d[i], max_d);
  }

  if (count[0]!=1 || d[0]!=0) {
    cout << 0 << endl;
  } else {
    ll ans = 1;
    for (int i = 1; i <= max_d; i++) {
      for (int j = 0; j < count[i]; j++) {
        ans *= count[i-1];
        ans %= 998244353;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


int main() {
  int N,Y; cin >>N >>Y;
  vector<int> res = {-1, -1, -1};

  for (int i=0; i<=N; i++){
    for (int j=0; j<=N-i; j++){
      int sum = i * 10000 + j * 5000 + (N-i-j) * 1000;
      if (sum == Y){
        res.at(0) = i, res.at(1) = j, res.at(2) = N-i-j;
      }
    }
  }
  cout <<res[0] <<" " <<res[1] <<" " <<res[2] <<endl;
}

Measured memory_bytes: 256
program jihanki
  implicit none
  integer :: i, j, n
  integer :: a, b, c
  integer :: count

  read(*,*)a,b,c
  n=a+b
  if (n>=c-1) then
     write(*,*)b+c
  else
     write(*,*)b+n+1
  end if
  
end program jihanki

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

int main()
{
    string S; cin >> S;
    int len = S.length();
    ll bitnum = len - 1;
    ll ans = 0;
    for (int i = 0; i < (1 << bitnum); ++i) {
        ll index = 0;
        ll ti = 0;
        char v[len]; v[ti] = S[index];
        index++;
        ti++;
        for (int j = 0; j < bitnum; ++j) {
            if ((i>>j) & 0x01) {
                v[ti] = '\0';
                //cout << "v = " << v << endl;
                ti = 0;
                ll ii;
                sscanf(v, "%ld", &ii);
                ans += ii;
                v[ti] = S[index];
                index++; ti++;
            }
            else {
                v[ti] = S[index];
                index++;
                ti++;
            }
        }
        v[ti] = S[index];
        ti++;
        v[ti] = '\0';
        //cout << "v = " << v << endl;
        ll ii;
        sscanf(v, "%ld", &ii);
        ans += ii;
        //cout << endl;
    }    
    cout << ans << endl;
    
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (long long i = (a); i < (n); i++)
#define REP(i, n) for(long long i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
using namespace std;

typedef long long ll;

long long Mygcd(long long a, long long b)
{
	if (a % b == 0)return b;
	return Mygcd(b, a % b);
}

int Mygcd(int a, int b)
{
	if (a % b == 0)return b;
	return Mygcd(b, a % b);
}

long long Mylcm(long long a, long long b)
{
	return a * b / Mygcd(a, b);
}

int Mylcm(int a, int b)
{
	return a * b / Mygcd(a, b);
}

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

	int S, W;

	cin >> S >> W;

	if (S <= W)
	{
		cout << "unsafe" << endl;
	}
	else
	{
		cout << "safe" << endl;
	}

	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define inf 1<<29
#define MAX 101
using namespace std;

int a,b,h,w,t,s,p,P[12];
string dungeon[MAX];
int grid[MAX][MAX];
pair<char,int> S[1001];
int Steps[1001];
int dp[1001][(1<<12)];
int X[4]={0,1,0,-1};
int Y[4]={-1,0,1,0};

int f(char c){
  if(c=='U')return 0;
  if(c=='R')return 1;
  if(c=='D')return 2;
  return 3;
}

int main()
{
  while(1){
    cin>>a>>b;
    if(a+b==0)break;
    cin>>h>>w;
    for(int i=0;i<h;i++){
      cin>>dungeon[i];
    }
    cin>>t;
    map<char,int> T;
    for(int i=0;i<t;i++){
      char t1;
      int t2;
      cin>>t1>>t2;
      T[t1]=t2;
    }
    cin>>s;
    for(int i=0;i<s;i++)cin>>S[i].f>>S[i].s;
    cin>>p;
    for(int i=0;i<p;i++)cin>>P[i];

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++)grid[i][j]=T[dungeon[i][j]];
    }
    int ni=0,nj=0,c=0;
    Steps[c++]=0;
    for(int i=0;i<s;i++){
      int muki=f(S[i].f);
      for(int j=0;j<S[i].s;j++){
	ni+=Y[muki];
	nj+=X[muki];
	Steps[c++]=grid[ni][nj];
      }
    }
    for(int i=0;i<c;i++){
      for(int j=0;j<(1<<p);j++)dp[i][j]=0;
    }
    dp[0][(1<<p)-1]=a;
    for(int step=1;step<c;step++){
      for(int i=0;i<(1<<p);i++){
	if(dp[step-1][i]==0)continue;
	for(int j=0;j<p;j++){
	  if((i>>j)%2==0)continue;
	  int nhp=min(dp[step-1][i]+P[j],b);
	  dp[step][i-(1<<j)]=max(dp[step][i-(1<<j)],max(0,nhp-Steps[step]));
	}
	dp[step][i]=max(dp[step][i],dp[step-1][i]-Steps[step]);
      }
    }
    bool flag=false;
    for(int i=0;i<(1<<p);i++){
      if(0<dp[c-1][i])flag=true;
    }
    if(flag)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 17288
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    int n; cin >> n;
    int q; cin >> q;
    vector <ll> values(n+1, 0);
    vector <bool> visited(n+1, false);
    vector <vector <int>> edges(n+1, vector <int>());
    REP(i, n-1){
        int a; cin >> a;
        int b; cin >> b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    REP(i, q){
        int p; cin >> p;
        int x; cin >> x;
        values[p] += x;
    }
    queue <int> que;
    que.push(1);
    visited[1] = true;
    while(!que.empty()){
        int node = que.front();
        que.pop();
        for(auto child: edges[node]){
            if (visited[child]){
                continue;
            }
            values[child] += values[node];
            que.push(child);
            visited[child] = true;
        }
    }
    for(int i=1; i<n+1; i++){
        if (i!=n){
            cout << values[i] << " ";
        } else {
            cout << values[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 16372
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    map<int, int> mp;
    int n, m;
    cin >> n;
    for(int i = 0; i < n; i++){
        int d;
        cin >> d;
        mp[d]++;
    }
    cin >> m;
    for(int i = 0; i < m; i++){
        int t;
        cin >> t;
        mp[t]--;
        if(mp[t] < 0){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main(){
    ll n; cin >> n;
    vector<ll> A(n);

    ll ans = 0, res = 0;
    rep(i, n) {
        cin >> A[i];
        res += A[i];
    }

    
    rep(i, n){
        res -= A[i];
        ll tmp = res % MOD;
        ans += tmp * A[i];
        ans %= MOD;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4840
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
using namespace std;
signed main() {

    string N;
    cin >> N;

    if (N.at(0) == '9' || N.at(1) == '9') {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3544
import math
N,D = map(int,input().split())
ans = 0
pos = []
for _ in range(N):
    tmp = list(map(int,input().split()))
    pos.append(tmp)

for i in range(N-1):
    for q in range(i+1,N):
        res_doubled = 0
        for a,b in zip(pos[i],pos[q]):
            res_doubled += (a-b)**2
        res = math.sqrt(res_doubled)
        if res==int(res):
            ans += 1
print(ans)

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

int main() {
 int N, sum ,a;
  cin >> N;
  
  a = N;
  for(int i=0; i<8; i++){
    sum += a%10;
    a /= 10;
  }
  if( N%sum == 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
      

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
string s0,t0;
char s[222],t[111];
int l,i,j;
bool k;
int main(){
	cin>>s0>>t0;
	l=s0.length();
	for(i=0;i<l;i++)
	  s[i]=s[i+l]=s0[i],
	  t[i]=t0[i];
	for(i=0;i<l;i++){k=1;
	  for(j=0;j<l;j++)
	  	if(s[i+j]!=t[j])k=0;
	  if(k){puts("Yes");return 0;}
	}puts("No");
}


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

int main() {
	// your code goes here
	string s,t;
	cin>>s;
	cin>>t;
	int n=t.size();
	string p=t.substr(0,n-1);
	if(s==p) cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 3624
def dfs(s,com):
    if s==0:
        ans.append(" ".join(map(str,com)))
        return
    for i in xrange(s,0,-1):
        if len(com)>0 and com[-1]<i:continue
        com.append(i)
        dfs(s-i,com)
        del com[-1]
    return ans

while 1:
    n=int(raw_input())
    if n==0:break
    ans=[]
    com=[]
    ans=dfs(n,com)
    for i in xrange(len(ans)):
        print(ans[i])

Measured memory_bytes: 6624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int w,h;
  cin>>h>>w;
  string s[h];
  for(int i=0;i<h;i++)
    cin>>s[i];
  int a[h][w]={};
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      a[i][j]=-2;
      if(s[i][j]=='c')a[i][j]=0;
      else if(j)if(a[i][j-1]!=-1)a[i][j]=a[i][j-1]+1;
      if(a[i][j]==-2)a[i][j]=-1;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(j)cout<<' ';
      cout<<a[i][j];
    }
    cout<<endl;
  }

}

Measured memory_bytes: 3200
#include<stdio.h>
int main(void)
{
  int a, b, n, x;

  scanf("%d\n", &a);  
  scanf("%d\n", &b);  
  scanf("%d\n", &n);

  x = a + b;

  if (x>=n) {
    printf("Yes");
  } else{
    printf("No");
  } 
  return 0;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)

int L[4][5] = {
	{1,4,7,10,16},
	{3,6,9,12,13},
	{1,2,3,15,19},
	{7,8,9,10,13}
};

int R[4][5] = {
	{24,27,30,21,18},
	{22,25,28,19,15},
	{28,29,30,16,21},
	{22,23,24,12,18}
};

struct Cube {
	int cube[31], s;
	
	Cube() {}
	
	void rot(int t) {
		for_(i,0,5) swap(cube[L[t][i]], cube[R[t][i]]);
	}
	
	bool fail(int a, int b) {
		for_(i,a+1,b+1) if (cube[a] != cube[i]) return 1;
		return 0;
	}
	
	bool solved() {
		if (fail(1,9)) return 0;
		if (fail(10,12)) return 0;
		if (fail(13,15)) return 0;
		if (fail(16,18)) return 0;
		if (fail(19,21)) return 0;
		if (fail(22,30)) return 0;
		return 1;
	}
};

int main() {
	int N;
	cin >> N;
	
	for_(i,0,N) {
		Cube ini;
		for_(j,1,31) cin >> ini.cube[j];
		ini.s = 0;
		
		queue< Cube > q;
		q.push(ini);
		
		while (!q.empty()) {
			Cube c = q.front(); q.pop();
			
			if (c.solved()) {
				cout << c.s << endl;
				break;
			}
			
			++c.s;
			
			for_(j,0,4) {
				c.rot(j);
				q.push(c);
				c.rot(j);
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 12164
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
#define MAX 1000
 
int LCS(char*, char*);
 
int main(void){
  int i, j, q, sharerow;
  char X[MAX], Y[MAX];
 
  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%s%s", X, Y);
    printf("%d\n", LCS(X, Y));
  }
 
  return 0;
}
 
int LCS(char *X, char *Y){
  int i, j;
  int x = strlen(X), y = strlen(Y);
  int Z[MAX+1][MAX+1];
 
  for(i=1; i<=x; i++){
    for(j=1; j<=y; j++){
      if(X[i-1] == Y[j-1]) Z[i][j] = Z[i-1][j-1] + 1;
      else if(Z[i-1][j] >= Z[i][j-1]) Z[i][j] = Z[i-1][j];
      else Z[i][j] = Z[i][j-1];
    }
  }
 
  return Z[x][y];
}

Measured memory_bytes: 4524
#include <stdio.h>

int main(){
    int s, sec, min, hour;

    scanf("%d", &s);

    hour = s/3600;
    s = s - hour*3600;
    min = s/60;
    s = s - min*60;
    sec = s;

    printf("%d:%d:%d\n", hour, min, sec);
    return 0; 
}



Measured memory_bytes: 2048
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    string s; cin >> s;
    int n = s.size();
    int pr = n % 2;
    int ev = s.front() == s.back();
    
    puts(pr^ev ? "First" : "Second");
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3780
n,l=map(int,input().split())
a=0
for i in range(1,n+1):
  a+=(l+i-1)

m=10**9
idx=1
for i in range(1,n+1):
  if abs(l+i-1)<m:
    m=abs(l+i-1)
    idx=i
        
print(a-(l+idx-1))

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  int N;
  cin >> N;
  vector<vector<int>> A(2, vector<int>(N));
  REP(i, 2) REP(j, N) cin >> A[i][j];
  ll mx = 0;
  REP(i, N) {
    ll num = 0, t = 0;
    REP(j, N) {
      num += A[t][j];
      if (i == j) {
        t++;
        num += A[t][j];
      }
    }
    mx = max(mx, num);
  }
  cout << mx << endl;
}

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

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

    int mm = 1001,t = 0;

    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        t += a;
        mm = min(mm,a);
    }

    cout << n + (x - t)/mm << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int cnt;
  int i;
  int x[10000],y[10000];
  while(1){
    scanf("%d %d",&x[cnt],&y[cnt]);
    if(x[cnt]==0&&y[cnt]==0)break;
    cnt++;
  }
  
  int tmp;
  for(i=0;i<cnt;i++){
    if(x[i]>y[i]){
    tmp=x[i];
    x[i]=y[i];
    y[i]=tmp;
    }
    printf("%d %d\n",x[i],y[i]);
  }
  return 0;
}

Measured memory_bytes: 620
import copy
s = input()
t = input()
if(set(t) - set(s)):
  print(-1)
  exit()

t_index = 0
s_index = 0
count = 0
copy_s = copy.deepcopy(s)
while len(t) > t_index:
  index = copy_s.find(t[t_index])
  if index >= 0:
    t_index+=1
    copy_s = copy_s[index+1:]
  else:
    copy_s = copy.deepcopy(s)    
    count += 1
print(count*len(s)+len(s)-len(copy_s))

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

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

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
    int n; cin >> n;
    vector<int> itm(n); REP(i,n) cin >> itm[i];

    sort(ALL(itm));
    ll ans = 0;
    if (SIZE(itm) % 2 == 0) {
        FOR(i, SIZE(itm)/2, SIZE(itm)-1) ans += itm[i];
        ans *= 2;
        ans -= itm[SIZE(itm) -1];
    } else {
        FOR(i, SIZE(itm)/2, SIZE(itm) - 1) ans += itm[i];
        ans *= 2;
        ans -= itm[SIZE(itm) - 1];
        ans -= itm[SIZE(itm)/2];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4060
/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  debug      printf("Come here!")
#define  inf        1000000000000000000
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         1000000007
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpll       vector < pair <ll, ll> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >
#define  pql        priority_queue<ll>
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define  setbits(x)     __builtin_popcountll(x)
#define  zerobits(x)    __builtin_ctzll(x)

#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/

int main()
{
    fastt;
    ll n, m, k, i, j, x, y, p=0, s=0, h, f=0;
    cin>>n;
    ll a[n+1];
    for(i=1; i<=n; i++){
        cin>>a[i];
    }
    x=1;
    while(1){
        p++;
        y=a[x];
        x=y;
        if(x==2)break;
        if(p>100000)break;
    }
    if(p>100000)cout<<"-1"<<endl;
    else cout<<p<<endl;
    return 0;
}



Measured memory_bytes: 4420
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

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

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

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

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

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

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

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

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin>>x;
    if(x == 3 || x == 5 || x == 7){
        PUTS("YES");
    }
    else {
        PUTS("NO");
    }
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: chars
    }
    let n = s.len();
    let mut res = vec![0;n];
    let mut l = 0;
    for i in 0..n {
        l = std::cmp::max(l,i);
        if s[i] == 'R' {
            while s[l] != 'L' {
                l += 1;
            }
            let idx = if i % 2 != l % 2 { l - 1 } else { l };
            res[idx] += 1;
        }
    }
    let mut r = n-1;
    for i in (0..n).rev() {
        r = std::cmp::min(i,r);
        if s[i] == 'L' {
            while s[r] != 'R' {
                r -= 1;
            }
            let idx = if i % 2 != r % 2 { r + 1 } else { r };
            res[idx] += 1;
        }
    }
    for r in res {
        print!("{} ", r);
    }
}


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}


const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n;
  string s;
  cin>>n>>s;
  int ans=0;
  rep(i,10){
    rep(j,10){
      rep(k,10){
        int l=0;
        while(l<n){
          if(s[l]=='0'+i){
            l++;
            break;
          }
          l++;
        }
        while(l<n){
          if(s[l]=='0'+j){
            l++;
            break;
          }
          l++;
        }
        bool flg=false;
        while(l<n){
          if(s[l]=='0'+k){
            flg=true;
            l++;
            break;
          }
          l++;
        }
        if(flg) ans++;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

// ----------- VECTOR ------------
template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}
// ----------- VECTOR ------------

int main() {
  int N; cin >> N;
  vector<LL> A(N), B(N), C(N);
  cin >> A >> B >> C;
  sort(A.begin(), A.end());
  sort(C.begin(), C.end());

  LL sum = 0;
  for (LL b : B) {
    LL num_a = std::lower_bound(A.begin(),  A.end(),  b) - A.begin();
    LL num_c = C.end() - std::upper_bound(C.begin(),  C.end(),  b);
    sum += num_a * num_c;
  }
  cout << sum << endl;
}


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

#define mod 1000000007
#define int long long

signed main() {
    int n, k;
    cin>>n>>k;
    
    vector<int> arr(n+1);
    for(int i=1; i<=n; i++){
        cin>>arr[i];
    }
    
    vector<vector<int>> dp(n+1, vector<int> (k+1, 0));
    
    for(int i=0; i<=k; i++){
        if(i<=arr[1]) dp[1][i]=1;
        else break;
    }
    
    if(n!=1){
        for(int i=1; i<=k; i++){
            dp[1][i]=(dp[1][i]+dp[1][i-1])%mod;
        }
    }
    
    for(int i=2; i<=n; i++){
        for(int j=0; j<=k; j++){
            int a=j-arr[i];
            if(a>0) dp[i][j]=(dp[i][j]+(dp[i-1][j]-dp[i-1][a-1]+mod))%mod;
            else dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
        }
        if(i!=n){
            for(int j=1; j<=k; j++){
                dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
            }
        }
    }
    
    cout<<dp[n][k]%mod<<endl;
}

Measured memory_bytes: 83244
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	ll a,b;
	cin >> a >> b;
	for(int i=1,x,y;i<n;i++) {
		cin >> x >> y;
		ll base = max((a-1)/x+1,(b-1)/y+1);
		a = base * x;
		b = base * y;
	}
	cout << a + b << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define name(x) #x
using namespace std;


const int INF = INT_MAX;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}




const ll MAX_SIZE = 3005;
ll memo[MAX_SIZE][MAX_SIZE];
string s;
int N;
vint p;



int main() {
    cin >> N;
    cin >> s;
    
    rep(i,MAX_SIZE){
        rep(j,MAX_SIZE){
            memo[i][j] = -999;
        }
    }
    
    for(auto i = 1; i<=N; i++){
        memo[i-1][N-i] = 1;
    }
    
    vector<ll> cumsum(N,0);
    cumsum[0] = memo[N-1][0];
    for(auto i = 1; i<=N-1; i++){
        cumsum[i] = cumsum[i-1] + memo[N-1-i][i];
        cumsum[i]%=MOD;
    }

    for(auto i = 1; i<N; i++){
        
        
        if (s[i-1] == '<'){
        
            for(auto j = 0; i + j <= N-1; j++){
                
                auto n = N-1 - i - j;

                memo[j][n] = cumsum[n]%MOD;
              
            }
            
        }else{
            
            for(auto n = 0; i + n <= N-1; n++){
                
                auto j = N-1 - i - n;
                
                memo[j][n] = (cumsum[n+j+1] - cumsum[n] + MOD)%MOD;

                
            }
            
        }
        
        cumsum[0] = memo[N-1-i][0] %MOD;
        for(auto j = 1; j<=N-1-i; j++){
            cumsum[j] = cumsum[j-1] + memo[N-1-i-j][j];
            cumsum[j]%=MOD;
        }
    }
    
    cout << memo[0][0] << endl;
    
    
    return 0;
}











Measured memory_bytes: 70784
#include <bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("outp.txt","w",stdout);
    #endif
    ll x,a,b,f=0;
    cin>>x;
    for(ll i=1;i<=1000;i++)
    {
        for(ll j=0;j<i;j++)
        {
            if(x%(i-j)==0)
            {
                if(pow(i,5)-pow(j,5)==x)
                {
                    a=i;b=j;
                    f=1;
                    break;
                }
            }
            if(x%(i+j)==0)
            {
                if(pow(i,5)+pow(j,5)==x)
                {
                    a=i;b=-j;
                    f=1;
                    break;
                }
            }
            if(f==1)
                break;
        }
    }
    cout<<a<<" "<<b;
}

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

int main(void){
    int X, A, B, C;
    cin >> A >> B >> C >> X;
    
    int ans = 0;
    
   for(int a =0; a <=A; a++) for(int b =0; b <=B; b++) for(int c =0; c <=C; c++){
       if(X == a*500 + b * 100 + c*50){
           ans++;
       } 
   }
    cout << ans << endl;    
    return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        ans += bisect_left(l, l[i] + l[j]) - j - 1

print(ans)

Measured memory_bytes: 9312
n = int(input())
A = list(map(int, input().split()))

ans = [sum((1 if i%2==0 else -1)*v for i, v in enumerate(A))//2]

while len(ans)<n:
  ans.append(A[len(ans)-1]-ans[-1])

print(' '.join(map(str, map(lambda x: 2*x,ans))))

Measured memory_bytes: 19132
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#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())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


 
void solve(){
    ll a,b;
    char s;
    cin>>a>>s>>b;
    if(s=='+') cout<<a+b<<endl;
    else cout<<a-b<<endl;
}
 
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
     
    ll Q=1;
    // cin>>Q;
    rep(_,Q){
 
        solve();
 
    }
   
 
 
    return 0;
}

Measured memory_bytes: 256
#179-B

N = int(input())
A = []

for i in range(N):
    D,H = map(int,input().split())

    if D == H:
        A.append(i)

#print(A)
cnt = 0
if len(A) <= 2:
    cnt = 0
    #print("No")

else:
    for j in range(len(A)-2):
        if A[j]+1 == A[j+1] and A[j+1]+1 == A[j+2]:
            #print("Yes")
            cnt = 1
            break


#print(cnt)
            
if cnt == 1:
    print("Yes")

else:
    print("No")


Measured memory_bytes: 9128
def main():
    s = list(input().rstrip())
    ans = 0
    cnt = 0
    for i in range(len(s)-2):
        if s[i] == "A":
            cnt += 1
        else:
            cnt = 0
        if s[i] == "A" and s[i+1] == "B" and s[i+2] == "C":
            ans += cnt
            if cnt == 1:
                s[i+2] = "A"
                cnt = 0
            else:
                s[i+1] = "A"
                s[i+2] = "A"
                cnt -= 2
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 4840
from itertools import permutations
N,M=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(M)]
g=[[False]*N for i in range(N)]
for a,b in ab:
  g[a-1][b-1]=True
  g[b-1][a-1]=True
nodes=[i for i in range(1,N)]
ans=0
for route in permutations(nodes):
  if g[0][route[0]]== False:
    continue
  for i in range(N-1):
    if i == N-2:
      ans+=1
      
      break
    elif g[route[i]][route[i+1]]:
      continue
    else:
      break
print(ans)
      
    
    


Measured memory_bytes: 3064
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int H,W;
    while (1) {
        scanf("%d %d",&H,&W);
        if(H==0 && W==0) break;
        for(int i=0; i<H; i++) {
            for(int j=0; j<W; j++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k;
	cin >>n >>k;
	VI ct(n);
	rep(i, k){
		int d; cin >>d;
		rep(j, d){
			int z; cin >>z;
			ct[z-1]++;
		}
	}
	int ans = 0;
	rep(i, n) if(ct[i]==0) ans++;
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 3632
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

S_list = []
for s in S:
    S_list.append(s)

c = Counter(S)

ans = 1
for v in c.values():
    ans *= (v + 1)
ans = ans - 1
ans = ans % mod
print(ans)


Measured memory_bytes: 10860
def display(l):
    for item in l:
        if not item == l[-1]:
            print(f"{item}", end=' ')
        else:
            print(item)


n = int(input())
lst = list(map(int, input().split()))
display(lst)

for i in range(1, len(lst)):
    key = lst[i]
    j = i - 1
    while j >= 0 and lst[j] > key:
        lst[j+1] = lst[j]
        j -= 1
    lst[j+1] = key
    display(lst)


Measured memory_bytes: 5988
"D equeue"
N, K = map(int, input().split())  # N個の宝石, K回数の操作
V = list(map(int, input().split()))

max_value = 0
for a in range(K+1):
    for b in range(K+1):
        gain_tresure = []
        if (a + b) > min(K, N):
            continue
        gain_tresure.extend(V[:a])
        gain_tresure.extend(V[N-b:])
        # print("------------------")
        # print(gain_tresure)
        # print(K-(a+b))
        # print("------------------")
        gain_tresure = sorted(gain_tresure)
        for i in range(min(K-(a+b), len(gain_tresure))):
            if gain_tresure[i] < 0:
                gain_tresure[i] = 0
        max_value = max(max_value, sum(gain_tresure))

print(max_value)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
#define inf 1e9
int main(){
    string O,E;
    cin >> O >> E;
    REP(i,E.length()){
        cout << O[i] << E[i];
    }
    if(E.length() != O.length()) cout << O[O.length()-1];
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())
if a == b and b == c:
    if a % 2 == 0:
        print(-1)
    else:
        print(0)
else:
    count = 0
    while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
        a, b, c = (b + c) // 2, (c + a) // 2, (a + b) // 2
        count += 1
    print(count)

Measured memory_bytes: 9128