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

#define ld long double
#define int long long
#define pb push_back 
#define Z(c) (int)(c).size()
#define L(c) c[Z(c)-1]
#define F first
#define S second
#define nl "\n"
#define mii map<int,int> 
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define rep(i,iv,n) for(int (i)=(iv);(i)<(n);++(i))
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<nl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<nl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<nl
#define tr(it,ct) for(auto &(it) : (ct))
#define pi acos(-1)
#define prt(ct) for(auto &(it) : (ct)) cerr<<it<<" "; cerr<<nl

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
typedef vector< pii > vp;
void swap(int &a,int &b)
{ auto tm=a; a=b; b=tm; }
 
  //Take care of duplicates

  const int mod=1000000007;
  const int mod2=998244353;
  const int INF=(1LL<<50)-1;
  const int N=2e5+25;
  const int M=123456;
 

 void bheja_fry()
 {  
   int n; cin>>n; vi v(n); rep(i,0,n) cin>>v[i];

   int id=1,ct=0;

   tr(i,v) if(i==id) id++; else ct++;

   if(ct==n)
    cout<<-1;
   else
    cout<<ct;
 }
                                                         
signed main()
{ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
  
   int t=1;                         
 //  cin>>t;
  rep(i,1,t+1)
  { // cout<<"Case #"<<i<<": ";
   bheja_fry();
   if(i<t)
   cout<<nl;
  }
 
 return 0; 
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cstring>

using namespace std;

int main(){
	int cnt[256];
	string str;
	while(cin >> str){
		memset(cnt, 0, sizeof(cnt));
		for(int i=0;i<str.size();i++) cnt[str[i]]++;
		cout << min(cnt['K'], min(cnt['U'], min(cnt['P'], cnt['C']))) << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
using ll = long long;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
long long dfs(int K,const vector<vector<int> > &graph, int now, int from){
    int can_use_color_num;
    if (from == -1){
        can_use_color_num = K-1;
    } else {
        can_use_color_num = K-2;
    }
    if (K < graph[now].size()){
        return 0;
    } else {
        long long case_num = 1;
        for(auto e:graph[now]){
            if (e == from) continue;
            case_num *= can_use_color_num;
            can_use_color_num--;
            case_num %= MOD;
        }
        for(auto e:graph[now]){
            if (e == from) continue;
            case_num *= dfs(K,graph,e,now);
            case_num %= MOD;
        }
        return case_num;
    }
}
int main(){
    int N,K; cin >> N >> K;
    vector<vector<int> > graph(N);
    for (int i = 0; i < N-1; i++){
        int a,b; cin >> a >> b; a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    long long ans = K*dfs(K,graph,0,-1);
    ans %= MOD;
    cout << ans << endl;
}
  



Measured memory_bytes: 11520
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define fi first
#define ii pair<ll,ll>
#define iii pair<pair<ll, ll>, ll >
#define se second
#define ld long double
#define mod 1000000007
#define popcount __builtin_popcountll
#define x0 zxcxzcsacasd
#define x1 ghfghujfgfg
#define y0 olkjhdnncvcv
#define y1 bhvgrewm345345435
using namespace std;

int main(){
    ll r, g, b, k;
    cin>>r>>g>>b>>k;
    while(g<=r){
        g*=2;
        k--;
    }
    while(g>=b){
        b*=2;
        k--;
    }
    if(k>=0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#define ll long long

using namespace std;


int main(void){
   ll a, b;
   cin >> a >> b;
   ll rA, RA;
   double mA = double(a)*12.5; double MA = double((a+1))*12.5-1;
   if(ceil(mA) != floor(mA))
      mA+=0.5;
   if(ceil(MA) != floor(MA))
      MA+=0.5;
   ll mB = b*10; ll MB = (b+1)*10-1;
   rA = mA; RA = MA;
   ll ans;
   //cout << rA << " " << RA << " " << mB << " "<< MB << endl;
   if(rA <= MB || mB <= RA)
      ans = max(rA, mB);
   if(RA < mB || MB < rA)
      ans = -1;
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdbool.h>
#define swap(a,b) a^=b^=a^=b 
#define inf 1000000007

int main(void) {
	// your code goes here
	int n;
	scanf("%d",&n);
	if(n<1000) printf("ABC\n");
	else printf("ABD\n");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,t,m,n,a)vector<vector<t> > name(m,vector<t> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 100000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
  int a,b,c,d;
  std::cin >> a>>b>>c>>d;
  if(abs(c-a)<=d||abs(c-b)<=d&&abs(b-a)<=d)std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
}

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

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

    string s;
    cin >> s;
    vector<int> prev(26, -1);
    vector<int> len(26);
    REP(i, s.size()) {
        int c = s[i] - 'a';
        len[c] = max(len[c], i - prev[c] - 1);
        prev[c] = i;
    }
    REP(c, 26) {
        len[c] = max(len[c], (int) s.size() - prev[c] - 1);
    }
    cout << *min_element(ALL(len)) << endl;
}

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

int main(){
  int N;
  cin >> N;
  int a[N+1];
  int index=1;
  for(int i=1;i<N+1;i++) cin >> a[i];
  
  for(int i=1;i<N+1;i++){
    if(a[index]==2){
	  cout << i << endl;
	  return 0;
	}
    index = a[index];
  }
  cout << -1 << endl;

  return 0;
}



Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#define ll long long
using namespace std;
int n,f[200005],a[200005];
int getnum()
{
    int ans=0;
    bool f=1;
    char c=getchar();
    while(!isdigit(c))
    {
        if(c=='-')f=0;
        c=getchar();
    }
    while(isdigit(c))
    {
        ans=ans*10+c-'0';
        c=getchar();
    }
    return f? ans : -ans;
}
int max(int a,int b)
{
    return a>b ? a : b;
}
int main()
{
    n=getnum();
    for(int i=1;i<=n;i++)
    {
        a[i]=getnum();
        f[a[i]]=i;
    }
    int cnt=1,ans=1;
    for(int i=1;i<n;i++)
    {
        if(f[i]<f[i+1])cnt++;
        else cnt=1;
        ans=max(cnt,ans);
    }
    cout<<n-ans;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
using namespace std;
int h,w;
int n;
int a[10010];
int ans[110][110];
int dir;
int v[4][2]={0,1,1,0,0,-1,-1,0};
bool check(int x,int y)
{
	if(x<1 || x>h || y<1 || y>w)return false;
	return true;
}
int main()
{
	scanf("%d%d%d",&h,&w,&n);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	int x=1,y=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=a[i];j++)
		{
			ans[x][y]=i;
			if(!check(x+v[dir][0],y+v[dir][1]) || ans[x+v[dir][0]][y+v[dir][1]])
			{
				dir++;
				if(dir>=4)dir=0;
			}
			x+=v[dir][0];
			y+=v[dir][1];
		}
	}
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)printf("%d ",ans[i][j]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <cmath>
#include <iterator>
#include <math.h>
#include <cstdio>
#include <map>

using namespace std;
using lli = long long int;

int main(void){
    map <int ,int> A;
    vector <int> B;
    int stk;
    int roop;
    cin >> roop;
    for(int i=0;i<roop;i++){
        cin >> stk;
        if(A.find(stk) != A.end()){
            A[stk]++;
        }else{
            A.emplace(stk,1);
            B.push_back(stk);
        }
    }
    int ans = 0;
    for(int b:B){
        if(A[b] > b){
            ans += A[b] - b;
        }else if(A[b] < b){
            ans += A[b];
        }
        
    }
    cout << ans << endl;
}


Measured memory_bytes: 5112
N,M = input().split(" ")
A = list(map(int, input().split(" ")))
count = 0
temp = 0
for x in A:
    temp += x
num = (1/(4*int(M)))*temp
for x in A:
    if x >= num:
        count += 1
    elif count >= int(M):
        break
    else:
        continue
if count>=int(M):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
// at_abc146b.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
using namespace std;
int main()
{
	int num; string str; cin >> num >> str;
	for (int i = 0; i < str.length(); i++) {
		int temp = str[i] - 'A';
		temp += num; temp %= 26;
		temp += (int)'A';
		cout << (char)temp;
	}
	cout << "\n";
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, m; cin >> n >> m;
	cout << (n == m ? "Yes" : "No") << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main (void) {
    string S;
    cin >> S;

    char c = S[0];
    int ans = 0;
    for (int i = 1, len = S.length(); i < len; i++) {
        if (S[i] != c) {
            ans++;
            c = S[i];
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

int a[100];
int cells[100][100]; // r * c

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

  vector<ll> primes(100005, 0);
  
  primes[0] = -1;
  primes[1] = -1;
  
  rep(i, 2, 100001) {
    if (primes[i] == 0) {
      primes[i] = 1;
      rep(j, 2, 100001) {
        if (i * j >= 100001) break;
        primes[i * j] = -1;
      }
    }
  }
  
  repR(i, 2, 100001) {
    if (primes[i] == 1 && primes[(i + 1) / 2] == 1) {
      primes[i] = 2;
    }
  }

  vector<ll> sum(100005, 0);
  ll temp = 0;
  rep0(i, 100001) {
    if (primes[i] == 2) {
      temp++;
    }
    sum[i] = temp;
  }

  rep0(i, Q) {
    ll l, r;
    cin >> l >> r;
    cout << sum[r] - sum[l - 1] << BR;
  }

  return 0;
}


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

struct Lowlink{
    int n,time;
    vector<int> ord,low;
    vector<vector<int>> G;
    vector<int> articulation;
    vector<pair<int,int>> bridge;
    Lowlink(int n):n(n),time(0),ord(n,-1),low(n),G(n){}
    void add_edge(int u,int v){
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    void dfs(int v,int p){
        ord[v]=low[v]=time++;
        bool is_articulation=false;
        int cnt=0;
        for (int u:G[v]){
            if (u==p) continue;
            if (~ord[u]){
                low[v]=min(low[v],ord[u]);
                continue;
            }
            ++cnt;
            dfs(u,v);
            low[v]=min(low[v],low[u]);
            is_articulation|=(~p&&ord[v]<=low[u]);
            if (ord[v]<low[u]) bridge.emplace_back(v,u);
        }
        is_articulation|=(p<0&&cnt>1);
        if (is_articulation) articulation.emplace_back(v);
    }
    void build(){
        for (int v=0;v<n;++v){
            if (ord[v]<0) dfs(v,-1);
        }
    }
};

// https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/3/GRL_3_A

void GRL_3_A(){
    int V,E; cin >> V >> E;
    Lowlink L(V);
    for (int i=0;i<E;++i){
        int s,t; cin >> s >> t;
        L.add_edge(s,t);
    }
    L.build();
    vector<int> ans=L.articulation;
    sort(ans.begin(),ans.end());
    for (int v:ans) cout << v << '\n';
}

// https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/3/GRL_3_B

void GRL_3_B(){
    int V,E; cin >> V >> E;
    Lowlink L(V);
    for (int i=0;i<E;++i){
        int s,t; cin >> s >> t;
        L.add_edge(s,t);
    }
    L.build();
    vector<pair<int,int>> ans=L.bridge;
    for (auto &e:ans) if (e.second<e.first)
        swap(e.first,e.second);
    sort(ans.begin(),ans.end());
    for (auto e:ans) cout << e.first << ' ' << e.second << '\n';
}

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


Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
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; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

string a,b,c;

void input(){
    cin >> a;
    cin >> b;
    cin >> c;    
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    cout << a[0] << b[1] << c[2] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
//const long long mod = 1000000007;
//const long long mod = 998244353;


int main() {
	int N;
	scanf("%d", &N);
	double *v = new double[N];
	for (int i = 0; i < N; i++) {
		scanf("%lf", v + i);
	}
	std::sort(v, v + N);
	for (int i = 0; i < N - 1; i++) {
		double u = (v[0] + v[1]) / 2;
		v[0] = u;
		for (int j = 1; j < N - 1; j++) {
			v[j] = v[j + 1];
		}
		v[N - 1] = 2000;
	}
	printf("%lf", v[0]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)
#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
typedef long long ll;
typedef long long int lln;
ll INF=1<<28;
//typedef long long lld;
const double pi=acos(-1.0);
int fx[]={1,-1,0,0}; //direction array
int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
const long double EPS=1e-7;
//#define INF 10000
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

bool cmp(int a, int b)
{
    return a<b;
}

struct compare
{
  bool operator()(const int& l, const int& r)
  {
      return l>r;
  }
};
ll inf=1e18;
int mod=1e9+7;

int tim=0;
int color;
double dp[3005][3005];
int vis[3005][3005];
double arr[3005];
int n,h;
double fun(int pos,int c)
{
    if(pos==n)
    {
        return c>h;
    }
    if(vis[pos][c]==1)
    {
        return dp[pos][c];
    }
    vis[pos][c]=1;
    double ans=0.0;
    ans+=(arr[pos]*fun(pos+1,c+1));
    ans+=((1.0-arr[pos])*fun(pos+1,c));
    return dp[pos][c]=ans;
}
int main()
{
//    READ;
    sf(n);
    h=n/2;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    cout<<setprecision(10)<<fun(0,0)<<endl;
    return 0;
}


Measured memory_bytes: 104832
#include <stdio.h> 

 int main(){
		char N[5];
		gets(N);
		int i=0;
		while(N[i]){
			i++;
		}
		i--; 
		if(N[i]==51)
		printf("bon\n");
		else if(N[i]==48||N[i]==49||N[i]==54||N[i]==56)
		 printf("pon\n");
		else
		 printf("hon\n"); 
		      
 }

Measured memory_bytes: 1512
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <time.h>
#include <complex>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;
using std::complex;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;
typedef complex<double> cd;

inline ll max(ll a, ll b)
{
    if (a > b)
        return a;
    return b;
}

inline ll min(ll a, ll b)
{
    if (a < b)
        return a;
    return b;
}

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

const ll MOD = 1e9 + 7;
ll n;
ll b[500000];
ll a[500000];

int main()
{
    ios_base::sync_with_stdio();
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> b[i];
        if (i % 2 == 1)
        {
            a[1] += b[i];
        }
        else
        {
            a[1] -= b[i];
        }
    }
    cout << a[1] << " ";
    for (int i = 2; i <= n; i++)
    {
        a[i] = 2 * b[i - 1] - a[i - 1];
        cout << a[i] << " ";
    }
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int N, M;
    cin >> N >> M;

    vector<int> num(N);
    vector<bool> red(N);

    for(int i = 0; i < N; i++) {
        num[i] = 1;
        red[i] = 0;
    }
    red[0] = 1;

    int x, y;
    for(int i = 0; i < M; i++) {
        cin >> x >> y;
        if (red[x-1]) red[y-1] = 1;
        
        num[x-1] = num[x-1] - 1;
        num[y-1] = num[y-1] + 1;
        
        if (num[x-1] == 0) red[x-1] = 0;
    }

    int ans = 0;
    for(int i = 0; i < N; i++) {
        if (red[i] == 1) ans++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class KMP
    {
        int[] lps;

        public void PrintIndex(string text, string pattern)
        {
            StringBuilder sb = new StringBuilder();

            int M = pattern.Length;
            int N = text.Length;
            int i = 0;
            int j = 0;

            ComputeLPS(pattern, M);

            while (i < N)
            {
                if (pattern[j] == text[i])
                {
                    j++;
                    i++;
                }

                if (j == M)
                {
                    sb.AppendLine((i - j).ToString());
                    j = lps[j - 1];
                }

                else if (i < N && pattern[j] != text[i])
                {
                    if (j != 0) j = lps[j - 1];
                    else i++;
                }
            }

            Console.Write(sb);
        }

        private void ComputeLPS(string pattern, int M)
        {
            lps = new int[M];
            lps[0] = 0;

            int len = 0;
            int i = 1;
            
            while (i < M)
            {
                if (pattern[i] == pattern[len])
                {
                    len++;
                    lps[i] = len;
                    i++;
                }
                else
                {
                    if (len != 0)
                    {
                        len = lps[len - 1];
                    }
                    else
                    {
                        lps[i] = 0;
                        i++;
                    }
                }
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string T = Console.ReadLine();
            string P = Console.ReadLine();

            KMP kmp = new KMP();
            kmp.PrintIndex(T, P);
        }
    }
}

Measured memory_bytes: 55684
Q = int(input())
ab = [tuple(map(int, input().split())) for _ in range(Q)]

for a, b in ab:
    if a > b:
        tmp = a
        a = b
        b = tmp
    elif a == b:
        print(2 * a - 2)
        continue

    ans = 2 * a - 2

    # x の二分探索
    x = 0
    low_x = 0
    upper_x = b - a + 1
    while upper_x - low_x > 1:
        mid_x = (low_x + upper_x) // 2

        # 与えられた x の中央値付近で a * b 未満を満たすか調べる
        flg = 1
        for j in range(mid_x//2-2,  mid_x//2+2 + 1):
            if j < 0 and b - a < j:
                continue
            if (a + j) * (a + mid_x - j) >= a * b:
                flg = 0
                break
        # mid_rank = a + (mid_x // 2)  # a ＋ xの幅の半分（中央）
        # for i in range(mid_rank - 2, (mid_rank + 2) + 1):
        #     k = mid_rank * 2 - i
        #     if a < i <= b and a <= k < b:
        #         if i * k >= a * b:
        #             flg = 1
        #             break
        if flg:
            low_x = mid_x
            x = mid_x
        else:
            upper_x = mid_x
            x = mid_x

    print(ans + low_x)

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

int main()
{
  long long n, k, r, s, p, ans;
  cin >> n >> k >> r >> s >> p;
  vector<char> t(n);
  for(long long i=0; i<n; i++){
    cin >> t[i];
  }
  vector<char> m(n);

  for(long long i=0; i<n; i++){
    if(i<k){
      if(t[i]=='s'){
        ans += r;
        m[i] = 's';
      }else if(t[i]=='p'){
        ans += s;
        m[i] = 'p';
      }else{
        ans += p;
        m[i] = 'r';
      }
    }else{
      if(t[i]==m[i-k]){
        if(i<n-k){
          if(t[i+k]=='r'){
            m[i] = 's';
          }else if(t[i+k]=='s'){
            m[i] = 'p';
          }else{
            m[i] = 'r';
          }
        }
      }else{
        if(t[i]=='s'){
          ans += r;
          m[i] = 's';
        }else if(t[i]=='p'){
          ans += s;
          m[i] = 'p';
        }else{
          ans += p;
          m[i] = 'r';
        }
      }
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void){
    long long N, M, t;
    scanf("%lld %lld", &N, &M);
    if (N>M) {
        t=N;
        N=M;
        M=t;
    }
    if (N==1) {
        if (M==1) printf("%d", 1);
        else if (M==2) printf("%d", 0);
        else printf("%lld", M-2);
    }
    else if (N==2) {
        printf("%d", 0);
    }
    else printf("%lld", (N-2)*(M-2));
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
    int L, R, d;
    cin >> L >> R >> d;
    if (L % d == 0)
    {
        cout << R / d - L / d + 1 << endl;
    }
    else
    {
        cout << R / d - L / d << endl;
    }
    return 0;
}

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


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define sqr(x) (x*x)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;


using ll = long long;

//#define int ll


const int N = 1e5+33, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const char pxy[] = {'R' , 'L' , 'D' , 'U'};
const double EPS = 1e-4;
const double PI = acos(-1.0);

template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;        // #include <ext/pb_ds/assoc_container.hpp>
typedef pair <ll, ll> pll;         // #include <ext/pb_ds/tree_policy.hpp>
typedef vector <int> vi;          // #include <ext/rope>
                // #include <ext/rope>
                                 // #include <ext/rope>
bool prime(int n) {             // template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){return 0;}
    }return 1;}
ll bp(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

void solve() {
    int n , m;
    cin >> n >> m;
    ll ans = 0;
    for(int i = 1 , x; i <= m; i ++) {
        cin >> x;
        ans += x;
    }
    n -= ans;
    cout << max(-1 , n);
}

/*
*/

main() {
    ios;
    int tt = 1;
//    cin >> tt;
    while(tt --) {
        solve();
        cout << '\n';
    }
    return 0;
}
/*
++>
+++>
<[<+>-]<
++++++++++++++++++++++++++++++++++++++++++++++++.

500000000000000000000000000000000000000000000000

1 1 2 3 6


*/


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;

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

    vector<long long int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    vector<vector<int>> digit(60, vector<int>(2));
    for(int i=0; i<n; i++){
        for(int j=0; j<60; j++){
            digit[j][(a[i]>>j) & 1] += 1;
        }
    }

    long long int ans = 0, pow2 = 1;
    for(int i=0; i<60; i++){
        //cout << digit[i][0] << " " << digit[i][1] << endl;
        ans += ((pow2 * digit[i][0]) % MOD) * digit[i][1];
        ans %= MOD;

        pow2 *= 2;
        pow2 %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int k = in.nextInt();
		System.out.println(solve(n, k));
		in.close();
	}

	private static double solve(int n, int k) {
		double r = 0;
		for (int i = 1; i <= n; i++) {
			int p = i;
			double x = 1;
			x /= n;
			while (p < k) {
				p *= 2;
				x /= 2;
			}
			r += x;
		}
		return r;
	}
}

Measured memory_bytes: 21844
h = int(input())
w = int(input())
n = int(input())
ans = 0
if h >= w :
  if n%h != 0:
    ans = (n//h) +1
  else:
    ans = n//h
elif  w > h:
  if n%w != 0:
    ans  = (n//w) +1
  else:
    ans = n//w
print(ans)

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#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 mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    map<int,int> cnt;
    rep(i,n){
        int a; cin>>a;
        cnt[a]++;
    }
    int ans=0;
    for(auto e:cnt){
        if (e.fi>e.se){
            ans+=e.se;
        }else{
            ans+=e.se-e.fi;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 4736
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

bool isMonth(int m){
    return (1 <= m && m <= 12);
}

void solution()
{
    int s;
    cin >> s;
    int lower = s % 100;
    int upper = s / 100;
    if(isMonth(lower) && isMonth(upper)){
        cout << "AMBIGUOUS\n";
    }else if(!isMonth(lower) && isMonth(upper)){
        cout << "MMYY\n";
    }else if(isMonth(lower) && !isMonth(upper)){
        cout << "YYMM\n";
    }else {
        cout << "NA\n";
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


Measured memory_bytes: 256
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  // "math"
)

// 行単位で読み込む場合
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Scan()
  N, _ := strconv.Atoi((strings.Split(sc.Text(), " "))[0])
  sList := []string{}
  for i := 0; i < N; i++ {
    sc.Scan()
    s := (strings.Split(sc.Text(), " "))[0]
    sList = append(sList, s)
  }

  sc.Scan()
  M, _ := strconv.Atoi((strings.Split(sc.Text(), " "))[0])
  tList := []string{}
  for i := 0; i < M; i++ {
    sc.Scan()
    t := (strings.Split(sc.Text(), " "))[0]
    tList = append(tList, t)
  }

  words := map[string]int{}
  for _, val := range sList {
    _, ok := words[val]
    if ok {
      words[val]++
    } else {
      words[val] = 1
    }
  }
  for _, val := range tList {
    _, ok := words[val]
    if ok {
      words[val]--
    } 
  }
  max := 0
  for _, val := range words {
    if val > max {
      max = val
    }
  }
  fmt.Println(max)

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
          if(n/i==i)
            c++;
          else
            c+=2;
        }

    }

    
    return  c;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   
   int n;
   cin>>n;
   for(int i=0;i<=25;i++)
   {
    for(int j=0;j<=14;j++)
    {
        if(7*j+4*i==n)
            {
                cout<<"Yes";
                return 0;
            }
        if(7*j+4*i>n)
        {
            break;
        }
    }
   }
   cout<<"No";




 return 0;
}








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

int main() {
    int N, T, A;
    cin >> N >> T >> A;
    vector<int> H(N);
    for (int i=0; i<N; i++) cin >> H.at(i);
    int mini = abs(1000*T - 6*H.at(0) - 1000*A);
    int site = 1;
    for (int i=1; i<N; i++) {
        int diff = abs(1000*T - 6*H.at(i) - 1000*A);
        if (mini > diff) {
            mini = diff;
            site = i + 1;
        }
    }
    cout << site << endl;
}

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;

  vector<string> s(h);
  //vectorに全入力値を代入する
  rep(i,h) cin >> s[i];
  int ans = 0;
  rep(is,1<<h) rep(js,1<<w) {
    int cnt = 0;
    rep(i,h) rep(j,w) {
      if (is >> i&1) continue;
      if (js >> j&1) continue;
      if (s[i][j] == '#') cnt++;
    }
    if (cnt == k) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    int a[n], b[n], c[n-1];
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }
    rep(i, n) {
        cin >> b[i];
    }
    rep(i, n-1) {
        cin >> c[i];
    }

    int ans = 0;
    int mae = -3;
    rep(i, n) {
        ans += b[a[i]];
        
        if(mae == a[i] - 1) {
            ans += c[mae];
        }

        mae = a[i];
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
N,M = map(int,input().split())
E = [[] for _ in range(N+1)]
for i in range(M):
    x,y,z = map(int,input().split())
    E[x].append(y)
    E[y].append(x)

d = [-1]*(N+1)

def dfs(start,num):
    q = deque([start])
    d[start] = num
    while(q):
        v = q.pop()
        for s in E[v]:
            if(d[s] == -1):
                d[s] = num
                q.append(s)

group_num = 0
for i in range(1,N+1):
    if(d[i] == -1):
        group_num += 1
        dfs(i,group_num)

print(group_num)        

Measured memory_bytes: 23868
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
//const in MOD = 1000000007;
const in INF=1<<30;
#define vec2(a,y,x) vector<vector<int>> a(y,vector<int>(x))
#define vec1(a,n) vector<int> a(n);rep(i,n)cin>>a[i]
using P=pair<int,int>;

const int MAX = 510000;
const int MOD = 1000000007;

in fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
in COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int nhr(int n,int r){return COM(n+r-1ll,r);}

int main(){
  COMinit();
  int n,m;
  cin>>n>>m;
  vector<int> soi(0);
  int x=2;
  while(m>1){
    if(m%x==0){ m/=x; soi.push_back(x);}
    else x ++;
  }
  sort(all(soi));
  auto y=soi.begin();
  vector<int> sp(0);
  while(y<soi.end()){
    sp.push_back(upper_bound(all(soi),*y)-lower_bound(all(soi),*y));
    y=upper_bound(all(soi),*y);
  }
  in ans=1ll;
  rep(i,sp.size()){
  	ans *=nhr(n,(sp[i]));
    ans%=MOD;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 12288
colors = {"hai": False,
          "cha": False,
          "midori": False,
          "mizu": False,
          "ao": False,
          "ki": False,
          "daidai": False,
          "aka": False}
i2c = [None]*3200
for i in range(3200):
    if i < 400:
        i2c[i] = "hai"
    elif i < 800:
        i2c[i] = "cha"
    elif i < 1200:
        i2c[i] = "midori"
    elif i < 1600:
        i2c[i] = "mizu"
    elif i < 2000:
        i2c[i] = "ao"
    elif i < 2400:
        i2c[i] = "ki"
    elif i < 2800:
        i2c[i] = "daidai"
    else:
        i2c[i] = "aka"
n = int(input())
rates = [int(i) for i in input().split()]
jiyu = 0
for x in rates:
    if x >= 3200:
        jiyu += 1
    else:
        colors[i2c[x]] = True
saisho = 0
# print(jiyu, colors)
for x in colors:
    if(colors[x]):
        saisho += 1
if(saisho < 1):
    saisho = 1
    jiyu -= 1
print(saisho, saisho+jiyu)


Measured memory_bytes: 3188
N, M = map(int, input().split())
s = []
for _ in range(M):
    _, *si = map(int, input().split())
    s += [si]
p = list(map(int, input().split()))

ans = 0
for b in range(1 << N):
    for i in range(M):
        on = 0
        for j in range(N):
            if j + 1 not in s[i]:
                continue
            if b & (1 << j):
                on += 1
        if on % 2 != p[i]:
            break
    else:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


long long dp[2];

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

	int n,p;
	cin>>n>>p;
	dp[0]=1;
	rep(i,n){
		int a;
		cin>>a;

		if (a & 1){
			long long s = dp[0] + dp[1];
			rep(j, 2)dp[j] = s;
		}
		else{
			rep(j, 2)dp[j]*=2;
		}

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

	return 0;
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
bool chmax(T &a, const T &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

int dp[105][4][2];  //桁dp全然わからん
signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  string s;
  cin >> s;
  int n = s.size();
  int k;
  cin >> k;

  dp[0][0][0] = 1;
  rep(i, 0, n) rep(j, 0, 4) rep(l, 0, 2) {
    int nd = s[i] - '0';
    rep(d, 0, 10) {
      int ni = i + 1, nj = j, nl = l;
      if (d != 0) ++nj;
      if (nj > k) continue;
      if (l == 0) {
        if (d > nd) continue;
        if (d < nd) nl = 1;
      }
      dp[ni][nj][nl] += dp[i][j][l];
    }
  }

  int ans = dp[n][k][0] + dp[n][k][1];
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))

mFR = [0]*(N+1)
for i in range(N):
    mFR[1] += A[i]*((-1)**i)
for i in range(2,N+1):
    mFR[i] = A[i-2]*2-mFR[i-1]
print(*mFR[1:])


Measured memory_bytes: 19996
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
using namespace std;
int main(void){
    long A,B,C,X,Y;
    cin>>A>>B>>C>>X>>Y;
    long min=1000000000; 
    for(long i=0;i<=X;i++){
        long j=2*(X-i);
        long k=0;
        if(Y-X+i>=0){k=Y-X+i;}
        long sum=A*i+B*k+C*j;
        if(sum<min){min=sum; }
    }
    for(long i=0;i<=Y;i++){
        long j=2*(Y-i);
        long k=0;
        if(X-Y+i>=0){k=X-Y+i;}
        long sum=A*k+B*i+C*j;
        if(sum<min){min=sum;}
    }
    cout<<min;
    return 0;
}

Measured memory_bytes: 256
using System;
class Program
{
  static void Main()
  {
    string S = Console.ReadLine();
    const long mod = 1000000007;
    int dig = S.Length;
    long [,] dp = new long[dig + 5, 13];
    
    // 初期化
    for (int i = 0; i < 13; i++)
    {
      string s = S.Substring(0, 1);
      if ((s == "?") && (i <= 9))
        dp[1, i] = 1;
      else if (s != "?" && int.Parse(s) == i)
        dp[1, i] = 1;
      else
        dp[1, i] = 0;
    }
    
    // dp
    for (int i = 2; i <= dig; i++)
    {
      // S の上から i 桁目の文字
      string s = S.Substring(i - 1, 1);
      
      for (int j = 0; j < 13; j++)
      {
        // 上 i 桁の %13 が j　になる場合の数 =: dp[i, j]
        long sum = 0;
        
        for (int k = 0; k < 13; k++)
        {
          if (s == "?")
          {
            int newmod = (1300 + j - k * 10) % 13;
            if (newmod >= 0 && newmod <= 9)
            {
              sum += dp[i-1, k];
              sum %= mod;
              continue;
            }
          }
          else
          {
            int sint = int.Parse(s);
            if ((k * 10 + sint) % 13 == j)
            {
              sum += dp[i-1, k];
              sum %= mod;
              break;
            }
          } //else
        } // for
        
        dp[i, j] = sum;
      }
    }
    
    // 結果
    Console.WriteLine(dp[dig, 5]);
    
  }
}

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

struct process
{
	string name;
	int time;
};
const int Len=100005;
process p[Len];
int n,head,tail;

void enqueue(process x){
	p[tail]=x;
	tail=(tail+1)%Len;
}

process dequeue(){
	process x=p[head];
	head=(head+1)%Len;
	return x;
}
int main(){
    int n,q;
    cin>>n>>q; 

    for(int i=0;i<n;i++)
    	cin>>p[i].name>>p[i].time;
    head=0,tail=n;
    process u;
    int elapse=0;
    while(head!=tail){
       u=dequeue();
       if(u.time>q){
       	 elapse+=q;
       	 u.time-=q;
       	 enqueue(u);

       }
       else{
       	 elapse+=u.time;
       	 cout<<u.name<<' '<<elapse<<endl;
        }



    }
}





Measured memory_bytes: 6888
#include<bits/stdc++.h>
#define INF 1000000000000000

using namespace std;
using ll = long long;


typedef pair<ll, int> P; //コスト, 頂点の番号
struct edge{
    int to;
    ll cost;
};

int N; //ノード数
vector<edge> G[100000]; //各ノードの持つ辺
ll d[100000]; //ノードの現時点での最小コスト

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>> pq;
    fill(d, d+N, INF);
    pq.push(P(0, s));
    d[s] = 0;

    while(!pq.empty()){
        P p = pq.top();
        pq.pop();
        ll now = p.second;
        if(p.first > d[now]) continue; //取り出した値が既に更新した値より大きいことがある

        for(int i = 0; i < G[now].size(); i++){
            edge e = G[now][i];
            if(d[e.to] > d[now] + e.cost){
                d[e.to] = d[now] + e.cost;
                pq.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(void){
    int E, r; cin >> N >> E >> r;
    for(int i = 0; i < E; i++){
        int a, b; ll d;
        cin >> a >> b >> d;
        edge e; e.to = b; e.cost = d;
        G[a].push_back(e);
    }
    dijkstra(r);
    for(int i = 0; i < N; i++){
        if(d[i] != INF) cout << d[i] << endl;
        else cout << "INF" << endl;
    }
}




Measured memory_bytes: 19588
from math import sqrt
from sys import stdin
N = int(stdin.readline().rstrip())
nums = [int(stdin.readline().rstrip()) for _ in range(N)]

def is_prime(x):
    if x == 2:
        return True

    if x < 2 or x % 2 == 0:
        return False

    i = 3
    while i <= sqrt(x):
        if x % i == 0:
            return False
        i = i + 2
    
    return True

print(sum(is_prime(n) for n in nums))


Measured memory_bytes: 6024
N, D = list(map(int, input().split()))
X = [0]*N
Y = [0]*N
for i in range(N):
    X[i], Y[i] = list(map(int, input().split()))

cnt = 0

for i in range(N):
    if X[i]**2 + Y[i]**2 <= D**2:
        cnt += 1

print(cnt)

Measured memory_bytes: 24700
from collections import defaultdict
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    K = int(input())

    if not K % 2:
        print(-1)
        return

    x = defaultdict(int)
    mod = 7 % K
    for i in range(K):
        if not mod:
            print(i + 1)
            break
        if x[mod]:
            print(-1)
            break
        x[mod] = 1
        mod = (mod * 10 + 7) % K


main()


Measured memory_bytes: 92916