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

const int N=100005;
vector <int> E[N];
int n, num1, num2;
int dist1[N], dist2[N];

void dfs (int v, int p)
{
	if (!dist1[v]) dist1[v] = dist1[p] + 1;
	else{
		dist2[v] = dist2[p] + 1;
		if (dist1[v] > dist2[v])  num2++;
		else  num1++;	
	}
	
	for (int i=0; i<E[v].size(); i++){
		if (E[v][i] == p)  continue;
		dfs (E[v][i], v);
	}
}

int main()
{
	cin >> n;
	for (int i=1; i<n; i++){
		int u, v;
		cin >> u >> v;
		E[u].push_back (v);
		E[v].push_back (u);
	}
	
	dfs (1, 0);
	dfs (n, 0);
	if (num1 > num2)
		puts ("Fennec");
	else
		puts ("Snuke");
		
	return 0;
}

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

int main(){
  int N,A[110] ;
  int i,j,c,d ;
  	
  cin >> N ;
  
  for(i=0;i<N;i++){
    cin >> A[i] ;
  }
  
  for(i=0;i<N-1;i++){
    for(j=0;j<N-1;j++){
      c = A[j] ;
      d = A[j+1] ;
      if(A[j+1]>A[j]){
        A[j] = d ;
       	A[j+1] = c ;
      }
    }
  }
  
  cout << A[0]-A[N-1] <<endl ;

}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>

using namespace std;

int main() {
  int bits;
  scanf("%d", &bits);
  int n = 1 << bits;
  vector<pair<int, int>> bestValues(n, make_pair(-1, -1));
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    bestValues[i].first = a;
  }

  int arr[4];
  for (int i = 0; i < bits; i++) {
    for (int j = 0; j < n; j++) {
      if (j & (1 << i)) continue;
      int nj = j | (1 << i);
      arr[0] = bestValues[j].first;
      arr[1] = bestValues[j].second;
      arr[2] = bestValues[nj].first;
      arr[3] = bestValues[nj].second;
      sort(arr, arr + 4, greater<int>());
      bestValues[nj].first = arr[0];
      bestValues[nj].second = arr[1];
    }
  }
  int ans = -1;
  for (int k = 1; k < n; k++) {
    ans = max(ans, bestValues[k].first + bestValues[k].second);
    printf("%d\n", ans);
  }
  return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define INF (1LL<<59)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

const int MOD = 1000000007;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_of_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int t;
		cin>>t;
		ar[t]++;
	}	
	for(int i=1;i<=n;i++)
	cout<<ar[i]<<"\n";
	return;	
}

int main(void)
{
	FLASH();
	int T;
	T = 1;

// #ifndef ONLINE_JUDGE
// 	time_t time_t1, time_t2;
// 	time_t1 = clock();
// #endif

	//cin>>T;
	while(T--)
	solve(T);

// #ifndef ONLINE_JUDGE
// 	time_t2 = clock();
// 	SETF();
// 	cout<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
// 	UNSETF();
// #endif

	return 0;
}

Measured memory_bytes: 4404
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define int long long int
using namespace std;
#define pii pair <int, int>
#define mii map<int, int>
#define pb push_back
#define deb(x) cout << #x << " " << x << endl
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl
#define Loop(s, e, itr) for (int itr = s; itr < e; itr++)
#define loop(n) for(int i = 0; i < n; i++)
#define vin vector<int>
#define w(t) int tc; cin >> tc; for(int t = 1; t <= tc; t++)
#define vec vector
#define mod 1000000007
#define all(x) x.begin(), x.end()

int n, k;
int heights[100005];
int dp[100005];

void solve_itr(){
    cin >> n >> k;
    loop(n) cin >> heights[i+1];
    dp[n] = 0;
    for(int i = n-1; i > 0; i--){
        int temp = INT_MAX;
        for(int j = 1; j <= k; j++){
            if(i+j > n) break;
            temp = min(temp, dp[i+j] + abs(heights[i] - heights[i+j]));
        }
        dp[i] = temp;
    }
    
    cout << dp[1] << endl;
}

int go(int step){
    if(step > n) return INT_MAX;
    if(step == n) return 0;
    if(dp[step] == -1){
        int temp = INT_MAX;
        for(int j = 1; j <= k; j++){
            if(step+j > n) break;
            temp = min(temp, go(step+j) + abs(heights[step] - heights[step+j]));
        }
        dp[step] = temp;
    }
    return dp[step];
}

void solve_rec(){
    cin >> n >> k;
    loop(n) cin >> heights[i+1];
    memset(dp, -1, sizeof(dp));
    cout << go(1) << endl;
}

int32_t main(){
    // solve_itr();
    solve_rec();
}

Measured memory_bytes: 11396
N = int(input())
a = list(map(int,input().split()))

x = a[0]
y = sum(a[1:N])
ans = abs(x-y)
for i in range(1,N-1):
    x += a[i]
    y -= a[i]
    ans = min(ans,abs(x-y))

print(ans)

Measured memory_bytes: 100300
import java.util.*;
public class Main {

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

		char[] n = sc.next().toCharArray();
		int k = sc.nextInt();
		
		int len = n.length;
		int ans = 0;
		
		if(k==1) {
			ans = (len-1) * 9 + (n[0]-'0');
		}
		else if(k==2 && len>=2) {
			ans = (len-1) * (len-2) / 2 * 81;
			int zero = 0;
			int a = n[0] - '0';
			for(int i=1;i<len;i++) {
				int b = 0;
				if(zero<i-1) {
					b = 9;
				}
				else {
					b = n[i]-'0';
				}
				
				ans = ans + (a-1)*9 + b;

				if(n[i]=='0')
					zero++;
			}
		}
		else if(k==3 && len>=3){
			ans = (len-1) * (len-2) * (len-3) / 3 / 2 * 729;
			
			int[] nonZero = new int[1000];
			for(int i=111;i<1000;i++) {
				int c = i % 10, b = i / 10 % 10, a = i / 100;
				if(a!=0 && b!=0 && c!=0)
					nonZero[i]++;
				nonZero[i] += nonZero[i-1];
			}
			
			int a = n[0]-'0';
			
			int zeroi = 0;
			for(int i=1;i<len;i++) {
				int b = 0;
				if(zeroi<i-1) {
					b = 9;
				}
				else {
					b = n[i]-'0';
				}
				
				int zeroj = 0;
				for(int j=i+1;j<len;j++) {
					int c = 0;
					if(zeroi<i-1 || zeroj<j-i-1) {
						c = 9;
					}
					else {
						c = n[j]-'0';
					}
					
					ans += nonZero[a*100+b*10+c];
					
					if(n[j]=='0')
						zeroj++;
				}
				
				if(n[i]=='0')
					zeroi++;
			}
		}
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int n;
    string s;
    cin >> n >> s;
    int count = 0;
    for(int i=0;i<n-2;i++){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
            count++;
        }
    }
    cout << count <<endl;
}

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

typedef long long int ll;

int main() {
  int n, a, other = 0, two = 0, four = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a % 4 == 0)
      four++;
    else if (a % 2 == 0)
      two++;
    else
      other++;
  }
  if (two == 0) {
    cout << ((four + 1 >= other) ? "Yes" : "No") << endl;
  } else {
    cout << ((four >= other) ? "Yes" : "No") << endl;
  }
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
 
int main(void){
    int n,ans;
    while(cin>>n){
        for(int i=0;i<10;i++){
            if(n&1){
                ans=1<<i;
                cout<<ans;
                if(n>>1)
                    cout<<' ';
            }
            n>>=1;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1156
import sys


def input():
    return sys.stdin.readline().strip()
# sys.setrecursionlimit(100000)


def main():
    _ = int(input().strip())
    A = [int(i) for i in input().strip().split()]
    cnt = 0
    for a in A:
        x = a
        while x % 2 == 0:
            x = x // 2
            cnt += 1
    print(cnt)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 70160
local n=io.read("n")
local a={}
for i=1,n do
    a[i]=io.read("n")
end
table.sort(a,function(a,b)
    return a>b
end)

if n%2==0 then
    local total=0
    for i=1,n//2-1 do
        total=total+a[i]*2
    end
    total=total+a[n//2]
    total=total-a[n//2+1]
    for i=n//2+2,n do
        total=total-a[i]*2
    end
    print(total)
else
    local total1=0
    for i=1,n//2-1 do
        total1=total1+a[i]*2
    end
    total1=total1+a[n//2]+a[n//2+1]
    for i=n//2+2,n do
        total1=total1-a[i]*2
    end

    local total2=0
    for i=1,n//2 do
        total2=total2+a[i]*2
    end
    total2=total2-(a[n//2+1]+a[n//2+2])
    for i=n//2+3,n do
        total2=total2-a[i]*2
    end
    print(math.max(total1,total2))
end

Measured memory_bytes: 4240
#include<bits/stdc++.h>
const int MN=1e5+4;
int N,M,deg[MN],dp[MN];
std::vector<int>adj[MN];
std::queue<int>q;
int main() {
    scanf("%d%d",&N,&M);
    for(int i=0,a,b;i<M;++i) {
        scanf("%d%d",&a,&b);
        adj[b].push_back(a);
        deg[a]++;
    }
    for(int i=1;i<=N;++i)
        if(!deg[i]) q.push(i);
    while(!q.empty()) {
        int cur=q.front();
        q.pop();
        for(int i:adj[cur]) {
            dp[i]=std::max(dp[i],dp[cur]+1);
            if(!--deg[i]) q.push(i);
        }
    }
    printf("%d\n",*std::max_element(dp,dp+N+1));
}


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

long long N, A[200009];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) { cin >> A[i]; A[i] -= (i + 1); }
	sort(A, A + N);

	long long mid = A[N / 2], sum = 0;
	for (int i = 0; i < N; i++) sum += abs(mid - A[i]);
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", v)
#define PRIY PRI("Yes")
#define PRIN PRI("No")
#define MINS(a,b) a = min(a,(decltype(a))(b))
#define MAXS(a,b) a = max(a,(decltype(a))(b))



int main() {
	ll N;
	cin >> N;
	vector<ll> A(N+1);
	REP(i, 1, N+1) cin >> A[i];
	vector<unordered_map<ll, ll>> dp(N/2+1);
	dp[1][1] = A[1];
	dp[1][2] = A[2];
	if (N % 2 == 1) dp[1][3] = A[3];
	REP(j, 2, N/2+1) {
		REP(x, 2 * j - 1, N - 2 * (N / 2) + 2 * j + 1) {
			if (x > N) break;
			dp[j][x] = -1e18;
			REP(y, 2 * (j - 1) - 1, N - 2 * (N / 2) + 2 * (j - 1) + 1) {
				if (y > x - 2) break;
				if (dp[j - 1].count(y) == 0) continue;
				else MAXS(dp[j][x], dp[j - 1][y]);
			}
			dp[j][x] += A[x];
		}
	}
	ll ans = -1e18;
	for (auto p : dp[N / 2]) MAXS(ans, p.second);
	PRI(ans);
	return 0;
}

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

int main()
{
    double xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3;
    int q;

    cin >> q;

    for( int i = 0; i < q; i++ )
    {
        cin >> xp0 >> yp0 >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3;

        double a, b, c, d, s, t, x, y;
        a = xp1 - xp0;
        b = yp1 - yp0;
        c = xp3 - xp2;
        d = yp3 - yp2;

        if( a != 0 && c != 0 )
        {
            s = yp0 - b * xp0 / a;
            t = yp2 - d * xp2 / c;
            if( b == 0 )
            {
                y = s;
                x = ( y - t ) / ( d / c );
            }
            else if( d == 0 )
            {
                y = t;
                x = ( y - s ) / ( b / a );
            }
            else
            {
                x = ( s - t ) / ( d / c - b / a );
                y = b / a * x + s;
            }
        }
        else if( a == 0 )
        {
            if( d == 0 )
            {
                x = xp0;
                y = yp2;
            }
            else
            {
                t = yp2 - d * xp2 / c;
                y = d * xp0 / c + t;
                x = ( y - t ) / ( d / c );
            }
        }
        else
        {
            if( b == 0 )
            {
                x = xp2;
                y = yp0;
            }
            else
            {
                s = yp0 - b * xp0 / a;
                x = xp2;
                y = b * x / a + s;
            }
        }
        cout << fixed << setprecision(10) << x << " " << y << endl;
    }
    return 0;
}


Measured memory_bytes: 3292
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;

int main()
{
    string s;
    cin >> s;

    for ( int i = 0; i < s.size(); i++ ) {
	printf("%c", s[i]);
	if ( i == 3 ) printf(" ");
    }
    printf("\n");

    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> d(N);
    rep(i, N)cin >> d[i];

    ll res = 0;
    rep(r, N)rep(l, r)res += d[l] * d[r];
    cout << res << endl;
    return 0;
}


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

 using namespace std;
 
 int main(){
     
   int x, y;
   string picture;

   cin>>x>>y;
  
   cout<<'#';
   
   for(int i=0;i<y;i++){
     cout<<'#';
   }
   cout<<'#'<<endl;
  
  
   for(int i=0;i<x;i++){
       cin>>picture;
       cout<<'#'<<picture<<'#'<<endl;
   }
 
   cout<<'#';
   for(int i=0;i<y;i++){
     cout<<'#';
   }
   cout<<'#'<<endl; 
   
   
   return 0;
    
 }


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

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

const ll INF = 1LL << 60;


int main(){
  int n;
  cin >> n;
  ll dp[1000000],v;
  dp[0]=0;
  for(int i=1;i<n+1;i++){
    dp[i]=INF;
  }
  for(int i=1;i<n+1;i++){
    for(int j=1;j<7;j++){
      v=pow(9,j);
      if(i>=v){
        chmin(dp[i],dp[i-v]+1);
      }
    }
    for(int j=1;j<8;j++){
      v=pow(6,j);
      if(i>=v){
        chmin(dp[i],dp[i-v]+1);
      }
    }

    chmin(dp[i],dp[i-1]+1);
  }

  cout << dp[n] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int app() {
  int n,m;
  cin>>n>>m;

  vector<int> h(n);
  rep(i,n){
    cin>>h[i];
  }

  vector<bool> ans(n,true);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    --a;--b;
    if(h[a]<=h[b]) ans[a]=false;
    if(h[a]>=h[b]) ans[b]=false;
  }

  int count=0;
  rep(i,n) if(ans[i]) count++;

  return count;
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 3788
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <string>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
using namespace std;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h1, h2, m1, m2, k, mcount=0;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  
  while(1){
    m1++;
    mcount++;
    if(m1==60){
      m1=0;
      h1++;
      if(h1==24){
        h1=0;
      }
    }
    if(m1==m2&&h1==h2) break;
  };
  
  cout << mcount-k << endl;
  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1

int main() 
{
  string S;
  cin >>S;
  rep(i, S.size()){
  cout<<"x";
  }
  cout<<endl;
}

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

int main() {
	int lim, num, min, max;
	long sum;
	cin >> lim >> num;
	min = max = sum = num;
	for(int i = 1; i < lim; i++){
		cin >> num;
		if(min > num){
			min = num;
		}else if(max < num){
			max = num;
		}
		sum += num;
	}
	cout << min << " " << max << " " << sum << endl;
	return 0;
}

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

int selectionsort(int a[], int n)
{
	int i, j, t, sw = 0, minj;
	for (i = 0; i < n - 1; i++)
	{
		minj = i;
		for (j = i; j < n; j++)
		{
			if (a[j] < a[minj]) minj = j;
		}
		swap(a[i], a[minj]);
		if (i != minj) sw++;
	}
	return sw;
}

int main()
{
	int a[100], n, i, sw;
	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &a[i]);
	
	sw = selectionsort(a, n);

	for (i = 0; i < n; i++)
	{
		if (i > 0) printf(" ");
		printf("%d", a[i]);
	}
	printf("\n%d\n", sw);

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int c[252521];
vi nxt[252521];

ll dp[252521];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",c+i);
  REP(i,n){
    nxt[c[i]].push_back(i);
  }
  dp[0] = 1ll;
  REP(i,n){
    dp[i+1] += dp[i]; dp[i+1] %= MOD;
    auto it = upper_bound(ALL(nxt[c[i]]),i);
    if(it==nxt[c[i]].end())continue;
    if(*it==i+1)continue;
    dp[*it] += dp[i]; dp[*it] %= MOD;
  }
  printf("%lld\n",dp[n]);
  return 0;
}


Measured memory_bytes: 14720
/*
 * src.cpp
 *
 *  Created on: 2016/09/04
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

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

typedef long long ll;

int a[3];

int main(){
	bool even=false;
	REP(i,3){
		cin>>a[i];
		if (a[i]%2==0){
			even=true;
		}
	}
	if (even){
		cout<<0<<endl;
	}else{
		sort(a,a+3);
		cout<<(ll)a[0]*a[1]<<endl;
	}
	return 0;
}




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

int main(){
  int i,a,b;
  char op;

  while(1){
    cin >> a >> op >> b;
    if(op=='+'){
      cout << a+b << "\n";
    }
    if(op=='-'){
      cout << a-b << "\n";
    }
    if(op=='*'){
      cout << a*b << "\n";
    }
    if(op=='/'){
      cout << a/b << "\n";
    }
    if(op=='?'){
      break;
    }
  }
  return 0;
}  

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
const int N=15;
char s[N][10000];
int cnt[N];
int h,w,K,ans=0x3f3f3f3f;
int main()
{
	scanf("%d %d %d",&h,&w,&K);
	for(int i=0;i<h;i++) cin>>s[i];
	for(int i=0;i<1<<h-1;i++) //枚举横切 
	{
		memset(cnt,0,sizeof cnt); //记录每一块区域1的个数 
		bool f=0;
		int now=0;//记录总共的切数 
		for(int j=0;j<h-1;j++) if(i>>j&1) now++;
		for(int j=0;j<w;j++)//枚举竖切 
		{
			int id=0;
			bool flag=0;
			for(int k=0;k<h;k++) //遍历横切和竖切所包围的区域1的个数 
			{
				cnt[id]+=(s[k][j]=='1');
				if(cnt[id]>K)  flag=1; //这个说明需要竖切 
				if(i>>k&1) id++; //跳到下个区域中 
			}
			if(flag==1) 
			{
				now++;//总切数+1 
		
				memset(cnt,0,sizeof cnt); //把之前的切数置0，但是后面的不需要，因为后面的还是满足条件的 
				id=0;
				for(int k=0;k<h;k++)
				{
					cnt[id]+=(s[k][j]=='1');
					if(cnt[id]>K) {
					 f=1; break;}//这边不满足的意思和上面的那个不满足意义不一样。这次不满足说明了我需要横切了 
					if(i>>k&1) id++;
				}
			}
			if(f) break; 
		}
		if(!f&&now<ans) 
		{
			ans=now;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include <cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<unordered_map>
using namespace std;

int main()
{ 
    long long x, k, d, ans;
    cin >> x >> k >> d;
    
    long long divid = abs(x) / d;
    
    if(k <= divid){
        ans = abs(x) - d*k;
    }else{
        if((k - divid) % 2 == 0){
            ans = abs(x) - d*divid;
        }else{
            ans = abs(abs(x) - d * (divid+1));
        }
    }
        
    cout << ans << endl;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

struct union_find{
    vector<ll> parent;
    vector<ll> nums;
    union_find(ll n){
        parent.resize(n);
        nums.resize(n, 1LL);
        rep(i, 0, n) parent[i] = i;
    }

    ll root(ll x){
        if(parent[x] == x) return x;
        parent[x] = root(parent[x]);
        return parent[x];
    }

    void unite(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        if(rx != ry){
            parent[rx] = ry;
            nums[ry] += nums[rx];
        }
    }

    bool same(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        if(rx == ry) return true;
        return false;
    }

    ll size(ll x){
        return nums[root(x)];
    }
};  

int main(){
    ll N, M;
    cin >> N >> M;
    vector<ll> a(M), b(M);
    union_find t(N);
    rep(i, 0, M){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }

    vector<ll> ans(M+1);
    ans[M] = N * (N-1) / 2;
    for(ll i = M-1; i >= 0; i--){    
        if(t.same(a[i], b[i])){
            ans[i] = ans[i+1];
        }else{
            ans[i] = ans[i+1] - t.size(a[i]) * t.size(b[i]);
        }
        t.unite(a[i], b[i]);
    }
    rep(i, 1, M+1) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 5248
import java.util.Scanner;

/**
 * @author subaru
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int K = sc.nextInt();
        char targetChar = S.charAt(K - 1);
        StringBuilder result = new StringBuilder();
        for (char c : S.toCharArray()) {
            if (c == targetChar) {
                result.append(c);
            } else {
                result.append("*");
            }
        }
        System.out.println(result);
    }
}


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

int main(){
	string s;
	cin >> s;
	ll white = 0,res = 0;
	for(ll i = s.length() - 1; i >= 0; i--){
		if(s[i] == 'W') white++;
		else res += white;
	}
	cout << res << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<math.h>
using namespace std;

int main(){
  long int N, P;
  cin >> N >> P;
 
  long double logP=log(double(P));
  long int i=1;
  long int start=0;
  long int tempP;
  int cnt=0;
  if(P==1){
    cout << 1;
    return 0;
  }
  if(N==1){
    cout << P;
    return 0;
  }
  for(i=1;i<=P;i++){
    if(N*log(double(i))>=logP || i==P){
      start=i;
      break;
    }
  }
  for(i=start;i>1;i--){
    tempP=P;
    cnt=0;
    while(tempP%i==0){
      cnt++;
      tempP/=i;
    }
    if(cnt>=N){
      cout<<i;
      return 0;
    }
  }
  cout<<1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);

	int n, k;
	cin >> n >> k;

	vi as(n);
	trav(x, as) cin >> x;
	vi dp(n, k);

	vi ans;

	while(true){
		int mx = -1;
		trav(x, dp) mx = max(mx, x);
		if(mx <= -1) break;
		int i0 = -1;
		rep(i,0,n) if(dp[i] == mx && 
			(i0 == -1 || as[i] < as[i0]))
			i0 = i;
		if(as[i0] <= 0){
			puts("-1");
			return 0;
		}
		rep(i,0,n) if(dp[i] == mx && i != i0)
			--dp[i], --as[i], ans.push_back(i);
		dp[i0] -= 2;
		as[i0] -= 1;
		ans.push_back(i0);
	}
	cout << sz(ans) << endl;
	trav(x, ans) cout << x+1 << ' ';
	cout << endl;
}

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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

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

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	if(k <= a){
		cout << k << endl;
	}
	else if(a < k && k <= a + b){
		cout << a << endl;
	}
	else{
		cout << a - (k - a - b) << endl;
	}

}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

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

int main() {
    int n, ret = 0, cnt = 0, t;
    std::cin >> n;
    for (int i = 1; i <= n; i++) {
        std::cin >> t;
        if (t == i) {
            cnt++;
        } else if (cnt > 0) {
            ret += (cnt + 1) / 2;
            cnt = 0;
        }
    }
    ret += (cnt + 1) / 2;
    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			long n = sc.nextLong();
			long a = sc.nextLong();
			long b = sc.nextLong();
			
			long repCount = n / (a+b);
			
			long residual = n % (a+b);
			
			long ans = repCount * a;
			
			if ( a <= residual ) {
				ans += a;
			}
			else {
				ans += residual;
			}
			
			System.out.println(ans);
		}
	}
}

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

typedef long long int in;

in tree[800005],dp[200005];

void update(in node,in s,in e,in ind,in val)
{
    if(s==e)
    {
        tree[node]=val;
    }
    else
    {
        in m=(s+e)/2;
        
        if(s<=ind&&ind<=m)
        update(2*node,s,m,ind,val);
        else
        update(2*node+1,m+1,e,ind,val);
        
        tree[node]=max(tree[2*node],tree[2*node+1]);
    }
}

in query(in node,in s,in e,in l,in r)
{
    if(r<s||e<l)
    return 0;
    
    if(l<=s&&e<=r) 
    return tree[node];
    
    in m=(s+e)/2;
    
    in max1=query(2*node,s,m,l,r);
    in max2=query(2*node+1,m+1,e,l,r);
    
    in maxi=max(max1,max2);
    
    return maxi;
}

int main()
{
    in n,i,j;
    cin>>n;
    
    in h[n+2],v[n+2];
    
    for(i=1;i<=n;++i)
    cin>>h[i];
    
    for(i=1;i<=n;++i)
    cin>>v[i];
    
    for(i=1;i<=n;++i)
    {
        dp[i]=query(1,1,n,0,h[i]-1)+v[i];
        
        update(1,1,n,h[i],dp[i]);
    }
    
    cout<<query(1,1,n,1,n)<<"\n";
    
    return 0;
}


Measured memory_bytes: 9472
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;
#define int long long

signed main(){
  int N,M;cin>>N>>M;
  std::vector<int> v(M);
  for(int i=0;i<M;i++)cin>>v[i];
  map<int,int> m;
  for(int i=1;i<M;i++)m[v[i]-v[i-1]]++;
  m[N-v[M-1]+1]++;
  map<int,int> memo;
  int Q;cin>>Q;
  std::vector<int> iiii(Q);
  for(int i=0;i<Q;i++)cin>>iiii[i];
  for(int i=0;i<Q;i++){
    int L=iiii[i];
    L-=v[0]-1;
    if(L<0){cout<<-1<<endl;continue;}
    if(memo[L]){cout<<memo[L]<<endl;continue;}
    int l=0;int r=N+1;
    while(r-l>1){
      int me=(l+r)/2;
      int t=0;
      for(auto p:m){
        t+=max(p.first-me,0LL)*p.second;
      }
      if(t<=L)r=me;
      else l=me;
    }
    memo[L]=r;cout<<r<<endl;
  }
}



Measured memory_bytes: 10760
#include <string>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;


int main()
{
	int N;
	cin >> N;
	long long L[100] = { 0 };

	L[0] = 2;
	L[1] = 1;

	for (int i = 2; i <= N; i++) {
		L[i] = L[i - 1] + L[i - 2];
	}


	cout << L[N] << endl;

    return 0;
}

Measured memory_bytes: 256
s = input()
if s[0] == s[2] and s[1] == s[3] or s[0] == s[1] and s[2] == s[3] or s[0] == s[3] and s[1] == s[2]:
    if not (s[0] == s[1] and s[1] == s[2] and s[2] == s[3]):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3060
let n, k, r, s, p = Scanf.scanf " %d %d %d %d %d" @@ fun a b c d e -> a, b, c, d, e
let f = function 'r' -> 'p' | 's' -> 'r' | _ -> 's'
let ws = Array.init n @@ fun _ -> Scanf.scanf " %c" f
let ans = ref 0
let g t u = List.(filter (fun x -> x <> t && x <> u) ['r'; 's'; 'p'] |> hd)
let h = function 'r' -> r | 's' -> s | _ -> p
let _ = Array.iteri (fun i w -> if i - k >= 0 && ws.(i - k) = w then ws.(i) <- g w @@ if i + k < n then ws.(i + k) else w else ans := !ans + h w) ws; Printf.printf "%d\n" !ans

Measured memory_bytes: 5376
#define RUN
#ifdef RUN
#include <bits/stdc++.h>
using namespace std;

#define int long long

int A, B;
vector<int> Adiv;
vector<int> Bdiv;
vector<int> Cdiv;

int gcd(int a, int b) {
    int t;
    while (b != 0) {
        t = a % b; a = b; b = t;
    }
    return a;
}

signed main() {
    cin >> A >> B;
    if (A == 1 && B == 1) {
        cout << 1 << endl;
        return 0;
    }
    for (int i = 1; i * i <= A; ++i) {
        if (A % i == 0) {
            Adiv.push_back(i);
            Adiv.push_back(A / i);
        }
    }
    for (int i = 1; i * i <= B; ++i) {
        if (B % i == 0) {
            Bdiv.push_back(i);
            Bdiv.push_back(B / i);
        }
    }
    sort(Adiv.begin(), Adiv.end());
    sort(Bdiv.begin(), Bdiv.end());
    set_intersection(Adiv.begin(), Adiv.end(), Bdiv.begin(), Bdiv.end(), inserter(Cdiv, Cdiv.end()));
    sort(Cdiv.begin(), Cdiv.end());
    vector<int> ansList;
    for (int i = 0; i < Cdiv.size(); ++i) {
        int x = Cdiv[i];
        bool ok = true;
        for (int j = 0; j < ansList.size(); ++j) {
            int y = ansList[j];
            if (gcd(x, y) != 1) {
                ok = false;
                break;
            }
        }
        if (ok) {
            ansList.push_back(x);
        }
    }
    cout << ansList.size() << endl;
    return 0;
}
#endif


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

int main() {
	int n; cin >> n;
	int a[n]; for(int i = 0; i < n; ++i) cin >> a[i];
	// {num, idx}
	pair<int64_t, int64_t> p[n + 1];
	for(int i = 0; i < n; ++i) {
		p[i] = {a[i], i};
	}
	p[n] = {0, 0};
	sort(p, p + n + 1);
	reverse(p, p + n + 1);
	int64_t ans[n] = {};
	for(int64_t mini = 1e9, i = 0; i < n; ++i) {
		mini = min(mini, p[i].second);
		if(p[i].first == p[i + 1].first) continue;
		ans[mini] += (i + 1) * (p[i].first - p[i + 1].first);
	}
	for(int i = 0; i < n; ++i) {
		cout << ans[i] << '\n';
	}
	return 0;
}



Measured memory_bytes: 3840
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  ll graph[305][305]={0};
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++) cin>>graph[i][j];
  }
  ll ans=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      bool f=false;
      for(int k=0;k<n;k++){
        if(graph[i][j]>graph[i][k]+graph[k][j]){
          cout<<-1<<endl;
          return 0;
        }
        else if(graph[i][j]==graph[i][k]+graph[k][j]&&i!=k&&j!=k) f=true;
      }
      if(!f) ans+=graph[i][j];
    }
  }
  cout<<ans/2<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<limits.h>
#include<string>
#include<iomanip>
using namespace std;

long long  mod = 1000000007;

long max(long x, long y) {
	return x > y ? x : y;
}

long min(long x, long y) {
	return x < y ? x : y;
}

long factorial(long n) {
	if (n == 1) {
		return 1;
	}
	else {
		return n * factorial(n - 1);
	}
}

long long  fel(long long  n,long long  f) {

		if (f == 1) {
			return n % mod;
		}
		else if (f % 2 == 0) {
			return (fel(n,f / 2) * fel(n,f / 2)) % mod;
		}
		else {
			return ((n  * fel(n,f / 2) %mod) * fel(n,f / 2))% mod;
		}
	

}


int main()
{
	string s;
	cin >> s;
	/*vector<vector<double>> a(2, vector<double>(n));
	vector<int> b(n);
	*/

	/*long long kai;
	kai = 1;
	for (long long i = 1; i <= nm; i++) {
		kai = (kai * i) % mod;
	}*/

   
	//cout << fel(kai,mod-2);

	//vector<long long> sei(nm), gyaku(nm);

	if (s == "Sunny") {
		cout << "Cloudy";
	}
	else if (s == "Cloudy") {
		cout << "Rainy";
	}
	else {
		cout << "Sunny";
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int main(){
        int n , q;
        cin>>n>>q;
        string s;
        cin>>s;
        vector<int> pref(n+1);
        pref[0];
        string t = "AC";
        for(int i = 0 ; i<n-1 ; i++){
            bool found = true;
            for(int j = 0 ; j<2 ; j++){
                if(s[i+j]!=t[j]){
                    found = false;
                }
            }
            if(found){
                pref[i+1] = pref[i]+1;
            }
            else{
                pref[i+1] = pref[i];
            }
        }
        while(q--){
            int l , r;
            cin>>l>>r;
            --l;
            --r;
            if(r>l){
                cout<<pref[r] - pref[l]<<"\n";
            }
            else{
                cout<<"0";
            }
        }
        return 0;
    }

Measured memory_bytes: 1408
import math

N, H = map(int, input().split())
Swords_a = []
Swords_b = []
for i in range(N):
  
  a, b = map(int, input().split())
  Swords_a.append(a)
  Swords_b.append(b)
  
ma = max(Swords_a)
sb = 0 # bのうち「maより大きい成分」の和

Swords_b = sorted(Swords_b, reverse = True)

c = 0
k = 0

for i in range(N):
  if ma < Swords_b[i]:
    sb += Swords_b[i]
    c += 1
  if sb >= H:
    k = c
    break

if sb < H:
  print(c + math.ceil((H-sb)/ma))
else:
  print(k)

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long 
#define ret return
#define PB push_back
#define lc 2 * v
#define rc 2 * v + 1
#define mid (s + e) / 2
#define pii pair <int,  int>
#define pll pair <long long , long long>  
#define FAST ios::sync_with_stdio(false);cin.tie(0);
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

const ll maxn = 2e5 + 10 , INF = 1e18;

ll a[maxn];


int main() {
    FAST
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a , a + n);
    ll ans = 1;
    for (int i = 0; i < n; ++i) {
        if(ans == 0) {
            cout << 0 << endl;
            return 0;
        }
        if(a[i] > (INF / ans)) {
            // cout << INF / ans << endl;
            cout << -1 << endl;
            return 0;
        }
        ans = ans * a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4440
import java.util.*;
import static java.lang.Math.*;

public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i=0; i<n; i++){
            h[i] = sc.nextInt();
        }

        int res = 0;
        while(true){
            int max = 0;
            for(int i=0; i<n; i++){
                max = max(max,h[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j<n){
                if(h[j]==0) j++;
                else{
                    res++;
                    while(j < n && h[j] > 0){
                        --h[j];
                        j++;
                    }
                }
            }
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 22996
# coding: utf-8
# Your code here!
l=[]
for _ in range(3):
    l.append(list(input()))


tgt=0 #target
while True:
    if len(l[tgt])==0:
        if tgt==0:
            print("A")
        elif tgt==1:
            print("B")
        else:
            print("C")
        break
    nxt=l[tgt].pop(0)
    if nxt=="a":
        tgt=0
    elif nxt=="b":
        tgt=1
    else:
        tgt=2
    
    

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<string>
#include<utility>
#include<iomanip>
#include<bitset>
#include<math.h>
using namespace std;


int main(){

    long long n;
    cin >> n;
    long long ans = 0;
    vector<long long> m(n);
    vector<long long> d(n);
    
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        d[i] = a;
    }
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        if(i%2 == 0){
            sum += d[i];
        }else{
            sum -= d[i];
        }
    }
    m[0] = sum;
    
    for (int i = 1; i < n; i++)
    {
        m[i] = (d[i-1]-(m[i-1]/2))*2;
    }
    
    for (int i = 0; i < n; i++)
    {
        cout << m[i] << " ";
    }
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
const int N = 1000001;
using namespace std;


void f() {

}


int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    string t, s;
    cin >> s >> t;
    int ans = t.size();
    for (int i = 0; i + t.size() - 1 < s.size(); i++) {
        int h = 0;
        for (int j = i; j < i + t.size(); j++) {
            h += s[j] != t[j - i];
        }
        ans = min(ans, h);
    }
    
    cout << ans;

}

Measured memory_bytes: 3656
using System;
    class Program
    {
        static void Main(string[] args)
        {
            
            // 整数の入力
            string input = Console.ReadLine();
            int N = int.Parse(input);


            // この問題でもうすでによくわからない
            int saidai = (N / 7) + 1;
            int OK = 0;

            for (int i = 0; i < saidai; i++)
            {
                int amari = N - 7 * i;
                if (amari % 4 == 0)
                {
                    OK = 1;
                }
            }

            //出力
            if (OK == 1)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            
        }
    }

Measured memory_bytes: 13140
n,m = map(int, input().split())
ab = []
c = []
for i in range(m):
  ab.append(list(map(int, input().split())))
  c.append(list(map(int, input().split())))
dp = [[10**18] * (2 ** n) for i in range(m+1)]
dp[0][0] = 0
for i,((a,b),c) in enumerate(zip(ab,c)):
  d = 0
  for x in c:
    d += 2 ** (x-1)
  for j in range(2**n):
    NEXT = j | d
    dp[i+1][j] = min(dp[i+1][j], dp[i][j])
    dp[i+1][NEXT] = min(dp[i+1][NEXT], dp[i][j]+a)
ans = dp[m][2**n-1]
if ans == 10 ** 18:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 78296
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000 , mod = 1000000007;
#define PI 3.14159265
int main()
{
    fastio;
    ll x;
    cin>>x;
    for(int a=0;a<=300;a++)
    {
        for(int b=0;b<=300;b++)
        {
            ll f = 1LL*a*a*a*a*a;
            ll s = 1LL*b*b*b*b*b;
            if((f+s)==x)
            {
                cout<<a<<" -"<<b<<endl;
                return 0;
            }
            if((f-s)==x)
            {
                cout<<a<<" "<<b<<endl;
                return 0;
            }
        }
    }
    return 0;
}

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

int  gcd(int a, int b){
	if (b == 0){ return a; }
	return gcd(b, a%b);
}
int lcm(int a, int b){
	return a / gcd(a, b)*b;
}
int main(){
	int a, b;
	while (scanf("%d%d", &a, &b) != EOF){
		cout << gcd(a, b) << " ";
		cout << lcm(a, b) << endl;
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n,m;
	while(cin>>n>>m){
		if(n==0&&m==0) break;
		int d[n],p[n];
		for(int i=0;i<n;i++){
			cin>>d[i]>>p[i];
		}
		int pm=0,nowp;
		while(m>0){
			for(int i=0;i<n;i++){
				pm=max(pm,p[i]);
				if(pm==p[i]) nowp=i;
			}
			if(pm==0) break;
			if(m>=d[nowp]){
				m=m-d[nowp];
				d[nowp]=0;
				p[nowp]=0;
			}
			else{
				d[nowp]=d[nowp]-m;
				m=0;
			}
			pm=0;
		}
		int ptotal=0;
		for(int i=0;i<n;i++){
			ptotal=ptotal+p[i]*d[i];
		}
		cout<<ptotal<<endl;
	}
    return 0;
}

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

int n;
int cnt[101], perfect[101];
int req;
int indx[101];

int simulate()
{
    int curScore = 0, curC = 0;
    int lastindx = -1;
    for(int i = 0; i < n; i++)
    {
        if(curScore + (cnt[indx[i]] * (indx[i] + 1) * 100) + perfect[indx[i]] >= req)
        {
            lastindx = i;
            break;
        }
        curScore += (cnt[indx[i]] * (indx[i] + 1) * 100) + perfect[indx[i]];
        curC += cnt[indx[i]];
    }
    int s = 0, e = cnt[indx[lastindx]], mid;
    int res;
    while(s < e)
    {
        mid = s + (e - s) / 2;
        if(mid == cnt[indx[lastindx]])
        {
            if(curScore + mid * (indx[lastindx] + 1) * 100 + perfect[indx[lastindx]] >= req)
                e = mid;
            else
                s = mid + 1;
        }
        else if(curScore + mid * (indx[lastindx] + 1) * 100 >= req)
        {
            e = mid;
        }
        else
        {
            s = mid + 1;
        }
    }

    return curC + e;
}

int main()
{
    while(cin >> n >> req)
    {
        int res = INT_MAX;
        for(int i = 0; i < n; i++)
        {
            cin >> cnt[i] >> perfect[i];
            indx[i] = i;
        }
        do{
            res = min(res, simulate());
        }while(next_permutation(indx, indx + n));

        cout << res << endl;
    }
    return 0;
}


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

int main(){

  int N,Q;
  string S;

  cin >> N;
  cin >> S;
  cin >> Q;

  vector<int> k(Q);
  for (int i = 0; i < Q ; i++){
    cin >> k.at(i);
  }

  for (int i = 0; i < Q ; i++){

    long long dnum = 0,mnum = 0,dmnum = 0,ans = 0;

    for (int j = 0 ; j < N ; j++){

      if (j >= k.at(i)){

	if (S.at(j-k.at(i)) == 'D'){
	  dnum -= 1;
	  dmnum -= mnum;
	}else if (S.at(j-k.at(i)) == 'M'){
	  mnum -= 1;
	}
      }

      if (S.at(j) == 'D'){
	dnum += 1;
      }else if (S.at(j) == 'M'){
	mnum += 1;
	dmnum += dnum;
      }else if (S.at(j) == 'C'){
	ans += dmnum;
      }

    }

    cout << ans << endl;

  }

  return 0;
}


Measured memory_bytes: 1412
#include<stdio.h>
#include<string.h>
int main(void){
    int f = 0, i,o, j, l, z, q, k[6], s[100][6], n[6], n2[6];
    char c;
    scanf("%d",&q);
    for (z = 0; z < q; z++){
        for (i = 0; i < 6; i++){
            scanf("%d", &s[z][i]);
            n[i] = i;
        }
    }
    for (i = 0; i < q; i++){
        for (z = 0; z < q; z++){
            if (i != z){
                for (j = 0; j < 5000; j++){
                    if (j % 6 < 3 && j % 5 == 4){
                        n2[0] = n[1]; 
                        n2[1] = n[5]; 
                        n2[3] = n[3]; 
                        n2[4] = n[0]; 
                        n2[2] = n[2]; 
                        n2[5] = n[4];
                    }
                    else {
                        n2[0] = n[3]; 
                        n2[1] = n[1]; 
                        n2[3] = n[5]; 
                        n2[4] = n[4]; 
                        n2[2] = n[0]; 
                        n2[5] = n[2];
                    }
                    for (o = 0; o < 6; o++){
                        n[o] = n2[o];
                    }
                    for (l = 0; l < 6; l++){
                        if (s[i][l] != s[z][n[l]])break;
   
                    }
                    if (l == 6){ 
                        f = 1; 
                        break;
                    }
   
                }
            }
            if (f == 1)break;
        }
        if (f == 1)break;
    }
        if (f == 1)printf("No\n");
        else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 2080