akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, m, q;
    int l, r;
    int qp, qq;
    int ans;
    cin >> n >> m >> q;

    vector<vector<int>> x(n+1, vector<int>(n+1, 0));
    vector<vector<int>> c(n+1, vector<int>(n+1, 0));
    vector<vector<int>> z(n+1, vector<int>(n+1, 0));

    for(auto i=0;i<m;++i) {
        cin >> l >> r;
        x[l][r] += 1;
    }

    for(auto i=1;i<n+1;++i) {
        for(auto j=1;j<n+1;++j) {
            c[i][j] = c[i][j-1] + x[i][j];
        }
    }

    for(auto i=1;i<n+1;++i) {
        for(auto j=1;j<n+1;++j) {
            z[i][j] = z[i-1][j] + c[i][j];
        }
    }

    for (auto i=0;i<q;++i) {
        cin >> qp >> qq;
        cout << (z[qq][qq] - z[qp-1][qq] - z[qq][qp-1] + z[qp-1][qp-1]) << endl;
        //ans = 0;
        //for (auto j=qp;j<=qq;++j) {
        //    ans += c[j][qq] - c[j][qp-1];
        //}
        //cout << ans << endl;
    }
}

Measured memory_bytes: 3968
c=(1..3).map{gets.split.map(&:to_i)}
b=c[0]
a=[0,c[1][0]-b[0],c[2][0]-b[0]]
puts (0..2).all?{|i|(0..2).all?{|j|a[i]+b[j]==c[i][j]}}?:Yes: :No

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

const int N = 1e5 + 5, M = N * 2;
int n;
int adj[N], nxt[M], v[M], e;
__inline void ins(int u0, int v0) {
    v[e] = v0; nxt[e] = adj[u0]; adj[u0] = e ++;
}

int dep[N], size[N], pa[N];
void dfs(int u, int p, int d) {
    dep[u] = d;
    size[u] = 1;
    pa[u] = p;

    for (int e = adj[u]; ~e; e = nxt[e])
        if (v[e] != p) {
            dfs(v[e], u, d + 1);
            size[u] += size[v[e]];
        }
}

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

    std::cin >> n;
    memset(adj + 1, -1, sizeof (*adj) * n);
    for (int i = 1; i < n; ++ i) {
        int a, b; std::cin >> a >> b;
        ins(a, b); ins(b, a);
    }

    dfs(1, 0, 0);

    int len = dep[n] + 1;
    int up = len / 2;

    int u = n;
    for (int i = 0; i < up - 1; ++ i) u = pa[u];
    int A = n - size[u], B = size[u];

    if (A > B) std::cout << "Fennec\n";
    else std::cout << "Snuke\n";
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
const int mod = 200003;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define fr(s,n) for (int i=(int)(s);i<(int)(n);i++)
#define lc cout<<"\n"
double pi=2*acos(0.0);
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    long double rad= min(pi*((h+m/60)/6-m/30),2*pi-pi*((h+m/60)/6-m/30));
    double ans= a*a + b*b -2*a*b*cos(rad);
    ans = sqrt(ans);
    cout<<fixed<<setprecision(20)<<ans;
}


Measured memory_bytes: 4100
while True:
    a, op, b = input().split()
    a, b = map(int, [a, b])
    if op == '?':
        break
    elif op == "+":
        print(a+b)
    elif op == "-":
        print(a-b)
    elif op == "*":
        print(a*b)
    elif op == "/":
        print(a//b)



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

int main(){
    int n;
    cin>>n;
    if(n >= 400 and n <= 599)
        cout<<"8\n";
    else if(n >= 600 and n <= 799)
        cout<<"7\n";
    else if(n >= 800 and n <= 999)
        cout<<"6\n";
    else if(n >= 1000 and n <= 1199)
        cout<<"5\n";
    else if(n >= 1200 and n <= 1399)
        cout<<"4\n";
    else if(n >= 1400 and n <= 1599)
        cout<<"3\n";
    else if(n >= 1600 and n <= 1799)
        cout<<"2\n";
    else if(n >= 1800 and n <= 1999)
        cout<<"1\n";
    
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

#define TOPSZ ( 3 )

/** Application main entry point. */
int main (
  int argc,
  char *argv[ ]
  )
{
  int top[ 3 ] = { 0 };
  int i, j, k;

  for ( j = 0; j < 10; ++j )
  {
    int d;

    scanf ( "%d", &d );

    for ( i = 0; i < TOPSZ; ++i )
    {
      if ( d > top[ i ] )
      {
        for ( k = TOPSZ - 1; k > i; --k )
        {
          top[ k ] = top[ k - 1 ];
        }
        top[ i ] = d;
        break;
      }
    }
  }

  for ( i = 0; i < TOPSZ; ++i )
  {
    printf ( "%d\n", top[ i ] );
  }

  return ( 0 );
}

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

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

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

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

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

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

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

int main(void){
    int X,A,B; cin >> X >> A >> B;
    cout << X-A-(X-A)/B*B << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma comment (linker, "/STACK:256000000")
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long a = 0;a < b;++a)
#define ALL(x) (x).begin(),(x).end()
void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}
void solve() {
    long long n;
    cin >> n;
    long long ans = 0;
    REP(i, n) {
        long long t;
        cin >> t;
        ans += t;
    }
    ans -= n * (n + 1LL) / 2LL;
    cout << ans << endl;
}
int main() {
    init();
    solve();
}


Measured memory_bytes: 3216
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	
	cout <<  s1[0] << s2[0] << s3[0] << endl;
	
	return 0;
}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int S = Integer.parseInt(sc.next());
        int[] S_each = new int[4];
        for (int i = 0; i < S_each.length; i++) {
            S_each[i] = S % 10;
            if (i != 4) {
                S = (S - S_each[i]) / 10;
            }
        }
        boolean check = false;
        for (int i = 0; i < S_each.length - 1; i++) {
            if (S_each[i] == S_each[i + 1]) {
                check = true;
                break;
            }
        }
        if (check) {
            System.out.print("Bad");
        } else {
            System.out.print("Good");
        }
        sc.close();
    }
}


Measured memory_bytes: 23252
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <tuple>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sys/time.h>

using namespace std;

const long long mod = 1000000007;

int sqr(int n) {
  return static_cast<long long>(n)*n%mod;
}

long long bipow(long long c, long long n) {
  if (n == 0) {
    return 1;
  } else if(n == 1) {
    return c;
  } else if(n%2 == 0) {
    return sqr(bipow(c, n/2))%mod;
  } else {
    return (c*sqr(bipow(c, (n-1)/2)))%mod;
  }
}

void solve(string L){
  long long ans = 0;
  long long c = 0;
  for (int i = 0; i < L.size(); i++) {
    if (L[i] == '1') {
      ans += bipow(3, L.size()-i-1) * bipow(2, c) % mod;
      ans %= mod;
      c++;
    }
  }
  ans += bipow(2, c) % mod;
  ans %= mod;
  std::cout << ans << std::endl;
}

int main(){
  string L;
  std::cin >> L;
  solve(L);
  return 0;
}


Measured memory_bytes: 1144
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll beki[200020];
ll l[200020],r[200020];

int main(){
  int n;
  cin >> n;
  ll p;
  cin >> p;
  string s;
  cin >> s;
  if(p==2 || p==5){
    ll ans=0;
    rep(i,n){
      if((s[i]-'0')%p==0)ans+=i+1;
    }
    cout << ans << endl;
    return 0;
  }
//  l[0]=(s[0]-'0')%p;
  ll x=1;
//  rep(i,n)if(i>0)l[i]=((10*l[i-1])%p+(s[i]-'0')%p)%p;
  r[n]=0;
  for(int i=n-1;i>=0;i--){
    r[i]=(r[i+1]+((s[i]-'0')*x)%p)%p;
    beki[n-1-i]=x;
    x*=10;
    x%=p;
  }
  /*
  rep(i,n){
    l[i]*=beki[n-1-i];
    l[i]%=p;
  }
  */
  ll ans=0;
  ll cnt[p]={};
  cnt[0]++;
  for(int i=n-1;i>=0;i--){
//    cout << cnt[r[i]] << ' ' << i << endl;
    ans+=cnt[r[i]];
    cnt[r[i]]++;
    /*
    ll m=r[0]-r[0]*beki[n-i]+r[i]*beki[n-i];
    m%=p;
    m+=p;
    m%=p;
    */
  }
  cout << ans << endl;
return 0;}

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

typedef long long ll;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

typedef double D;
typedef complex<D> P;

#define X real()
#define Y imag()

const D eps=1e-8;
const D inf=1e12;
const D PI=acos(-1);

bool cmp_x(const P& a,const P& b){ return a.X==b.X?a.Y<b.Y:a.X<b.X; }
bool cmp_y(const P& a,const P& b){ return a.Y==b.Y?a.X<b.X:a.Y<b.Y; }
bool cmp_a(const P& a,const P& b){ return arg(a)==arg(b)?norm(a)<norm(b):arg(a)<arg(b); }
D cross(P a,P b){ return (conj(a)*b).Y; }
D dot(P a,P b){ return (conj(a)*b).X; }
D toRag(D deg){ return deg*PI/180.0; }
P rot(P base,P a,D theta){ return base+polar(abs(a-base),arg(a-base)+theta); }

struct L : public vector<P> { // line and segment
  L(const P& a,const P &b){
    push_back(a);
    push_back(b);
  }
};

int main(){
  while(1){
    int Q;
    D d;
    cin>>Q>>d;
    if(Q==0)break;
    P p1,p2;
    p1=P(-d,0); p2=P(d,0);
    while(Q--){
      D Lsp,Rsp,T;
      cin>>Lsp>>Rsp>>T;
      Lsp*=PI/180.0; Rsp*=PI/180.0;
      D dl=Lsp*T,dr=Rsp*T;
      if(abs(dl-dr)<eps){
        P ac=p2-p1;
        P dir=P(-ac.Y,ac.X);
        dir=dir*(1.0/abs(dir));
        p1+=dir*dl;
        p2+=dir*dr;
      }else{
        D theta=(dr-dl)/(2.0*d); D r=dl/theta;
        P ac=p1-p2;
        ac=ac*(1.0/abs(ac));
        P cent=p1+ac*r;
        p1=rot(cent,p1,theta);
        p2=rot(cent,p2,theta);
      }
    }
    P mid=(p1+p2)*0.5;
    printf("%.10f %.10f\n", mid.X,mid.Y);
  }
  return 0;
}



Measured memory_bytes: 3540
#include <stdio.h>

long long GCD(long long x, long long y){
  long long tmp;
  while(y != 0){
    tmp = x % y;
    x = y;
    y = tmp;
  }
  return x;
}
  
long long Count(long long A, long long B, long long C, long long D){
  return B - A - (B / C - A / C) - (B / D - A / D) + (B / (C * D / GCD(C, D)) - A / (C * D / GCD(C, D)));
}
  
int main(void){
  long long A, B, C, D;
  scanf("%lld %lld %lld %lld", &A, &B, &C, &D);
  printf("%lld\n", Count(A - 1, B, C, D));
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define FILL(a, value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
 
typedef long long LL;
typedef pair<int, int> PII;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int x;
	cin >> x;
	cout << 360 / __gcd(360, x) << "\n";
	return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<sstream>
#include<string>
#include<map>
using namespace std;

int main(){
	map<string,int> mp;
	string str,tmp[1111];
	getline(cin,str);
	istringstream ss(str);
	int i=0;
	while(getline(ss,tmp[i],' ')){
		mp[tmp[i]]++;
	}
	map<string,int>::iterator itr;
	int ans=0,len=0;
	string s1,s2;
	for(itr = mp.begin(); itr != mp.end(); ++itr) {
	   	string w = itr->first;
    	int c = itr->second;
    	if(c > ans) {
    		ans = c;
    		s1 = w;
    	}
    	int s = w.size();
    	if(s > len) {
    		len = s;
    		s2 = w;
    	}
	}
	cout << s1 << " " << s2 << endl;
}

Measured memory_bytes: 1208
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

X = int(stdin.readline().rstrip())

year = 1
num = 100
while True:
    num = math.floor(num * 1.01)
    if num >= X:
        print(year)
        exit()

    
    year += 1

Measured memory_bytes: 73080
def input_multiple_number():
    return map(int, input().split())

def cmb_mod(n,r,mod):
    x=1
    y=1
    if n/2<r:
        r=n-r
    for i in range(r):
        x*=n-i
        if x>mod:
            x%=mod
        y*=r-i
        if y>mod:
            y%=mod
    val=x*pow(y,mod-2,mod)%mod #pow(y,mod-2,mod)モジュラ逆数
    return val

def modulo(a,mod):
    return (a % mod + mod) % mod


n_given,a_given,b_given = input_multiple_number()

MOD = 10 ** 9 + 7
mod = MOD
ans = pow(2,n_given,MOD)

ans -= cmb_mod(n_given,a_given,mod)
ans -= cmb_mod(n_given,b_given,mod)


ans = modulo(ans,mod) - 1
print(ans)


Measured memory_bytes: 3064
var
  s:string;
  b:boolean;
  i,j,x,y,l:longint;
begin
  readln(s);
  l:=length(s);
  x:=-1;
  y:=-1;
  for i:=1 to l do
    if s[i]='C' then
                  x:=i;
  for i:=1 to l do
    if s[i]='F' then
                  y:=i;
  if (x>0)and(y>0)and(x<y) then
                             writeln('Yes')
                           else
                             writeln('No');
  //I CAN AK NOIP
end.

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

//INSERT ABOVE HERE
signed main(){
  Int n,h;
  cin>>n>>h;
  vector<Int> a(n),b(n),c(n),d(n);
  for(Int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i]>>d[i];
  
  auto idx=
    [&](Int k,Int s){
      if(s==0){
	if(c[k]==0) return 300+a[k];
	return c[k];
      }else{
	if(d[k]==0) return b[k];
	return 300+d[k];
      }
    };

  vector<vector<queue<Int> > > cnt(2,vector<queue<Int> >(600));
  for(Int i=0;i<n;i++){
    cnt[0][idx(i,0)].emplace(i);
    cnt[1][idx(i,1)].emplace(i);
  }
  
  auto NO=[](){cout<<"NO"<<endl;exit(0);};

  vector<Int> used(n),ok(600,0);
  vector<queue<Int> > q(600);
  vector<vector<Int> > lp;
  for(Int i=0;i<n;i++){
    if(used[i]) continue;
    used[i]=1;
    Int l=idx(i,0),r=idx(i,1);
    vector<Int> v;        
    while(1){
      v.emplace_back(l);
      v.emplace_back(r);
      Int flg=0;
      while(!cnt[1][l].empty()){
	Int k=cnt[1][l].front();cnt[1][l].pop();
	if(used[k]) continue;
	used[k]=1;
	assert(idx(k,1)==l);
	l=idx(k,0);
	flg=1;
	break;
      }
      if(flg) continue;
      while(!cnt[0][r].empty()){
	Int k=cnt[0][r].front();cnt[0][r].pop();
	if(used[k]) continue;
	used[k]=1;
	assert(idx(k,0)==r);
	r=idx(k,1);
	flg=1;
	break;
      }
      if(flg) continue;
      break;
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());    
    if(l==r){
      for(Int x:v) q[x].emplace(lp.size());
      lp.emplace_back(v);
      continue;
    }
    if(l<300||r>=300) NO();
    for(Int x:v) ok[x]=1;
  }

  vector<Int> ch(lp.size(),0),us(600,0);  
  queue<Int> q2;
  for(Int i=0;i<600;i++)
    if(ok[i]) q2.emplace(i);
  
  while(!q2.empty()){
    Int v=q2.front();q2.pop();
    if(us[v]) continue;
    us[v]=1;
    while(!q[v].empty()){
      Int u=q[v].front();q[v].pop();
      if(ch[u]) continue;
      ch[u]=1;
      for(Int w:lp[u]) q2.emplace(w);
    }
  }
  
  for(Int i=0;i<(Int)lp.size();i++) if(!ch[i]) NO();
  cout<<"YES"<<endl;
  return 0;
}


Measured memory_bytes: 9080
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> V(N);
  for(int i=0; i<N; i++){
    cin >> V[i];
  }
  int R;
  R = min(N,K);
  int ans=0;
  for(int A=0; A<=R; A++){
    for(int B=0; B<=R; B++){
      if(A+B>R){
        break;
      }
      int res=0;
      priority_queue<int,vector<int>,greater<int>> que;
      for(int i=0; i<A; i++){
        res += V[i];
        que.push(V[i]);
      }
      for(int i=1; i<=B; i++){
        res += V[N-i];
        que.push(V[N-i]);
      }
      for(int i=0; i<K-(A+B); i++){
        if(que.empty()){
          break;
        }
        int W=que.top();
        if(W>=0){
          break;
        }
        que.pop();
        res -= W;
      }
      ans = max(ans,res);
    }
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
  int D; cin >> D;
  if ( D == 25 ) 
    cout <<"Christmas" << endl; 
  else if ( D == 24 ) 
    cout <<"Christmas Eve" << endl; 
  else if ( D == 23 ) 
    cout << "Christmas Eve Eve" << endl; 
  else if ( D == 22 ) 
    cout <<"Christmas Eve Eve Eve" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

struct Train {
    int c,s,f;
    Train(int c_, int s_, int f_) :
        c(c_), s(s_), f(f_) {}
};
int main(){
  ll n;cin>>n;
  vector<Train> a;
  ll c,s,f;
  rep(i,n-1){
    cin>>c>>s>>f;
    a.emplace_back(c,s,f);
  }
  ll ans=0;
  rep(i,n){
    ans=0;
    FOR(j,i,n-1){
      if(ans>a[j].s){
        ll x=(ans+a[j].f-1)/a[j].f - a[j].s/a[j].f;
        ans=a[j].s+a[j].f*x;
        ans+=a[j].c;
      }else{
        ans=a[j].s+a[j].c;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int zeller(int Y,int M,int D){
    if(M < 3){
	Y--;
	M += 12;
    }
    return (Y+Y/4-Y/100+Y/400+(13*M+8)/5+D)%7;
}

int main(){
    string s[] = {"Sunday",
		  "Monday",
		  "Tuesday",
		  "Wednesday",
		  "Thursday",
		  "Friday",
		  "Saturday",
		  "Sunday"};
    int M,D;
    while(cin >> M >> D, M){
	cout << s[zeller(2004,M,D)] << endl;
    }
    return 0;
}

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

int main() {
	bool prime[100001] = { false };
	for (int i = 2; i < 100001; i++){
		if (!prime[i]) {
			for (int j = i + i; j < 100001; j += i) {
				prime[j] = true;
			}
		}
	}

	int c[100001] = { 0 };
	for (int i = 3; i < 100001; i++) {
		if (!prime[i] && !prime[(i + 1) / 2]) c[i]++;
	}

	for (int i = 2; i < 100001; i++) c[i] += c[i - 1];

	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int l, r;
		cin >> l >> r;
		cout << c[r] - c[l - 1] << endl;
	}

}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll a;
  double b;
  cin >> a >> b;
  ll bb = round(b * 100);
  cout << a * bb / 100 << endl;
}

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



int main(){
    int A,B,C;
    cin >> A >> B >> C;
    cout << max(C - (A - B), 0) << endl;
    return 0;
}

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

int main() {
  int n, qs;
  cin >> n >> qs;
  int64_t blacks = (int64_t) (n - 2) * (n - 2);
  vector<int> vcons, hcons;
  vcons.push_back(n);
  hcons.push_back(n);
  for (int q = 0; q < qs; ++q) {
    int type, x;
    cin >> type >> x;
    if (type == 1) {
      int iv = upper_bound(vcons.rbegin(), vcons.rend(), x) - vcons.rbegin();
      if (iv == 0) {
        hcons.push_back(hcons.back());
        vcons.push_back(x);
        blacks -= max(hcons.back() - 2, 0);
      } else {
        blacks -= max(*(hcons.rbegin() + iv) - 2, 0);
      }
    } else {
      int ih = upper_bound(hcons.rbegin(), hcons.rend(), x) - hcons.rbegin();
      if (ih == 0) {
        vcons.push_back(vcons.back());
        hcons.push_back(x);
        blacks -= max(vcons.back() - 2, 0);
      } else {
        blacks -= max(*(vcons.rbegin() + ih) - 2, 0);
      }
    }
//    cout << vcons.back() << ' ' << hcons.back() << '\n';
  }
  cout << blacks << '\n';
  return 0;
}

Measured memory_bytes: 5012
#include <cstdio>

int main()
{
    int n, l;
    while (scanf("%d%d", &n, &l), n) {
        int d[21], p[21];
        for(int i=0;i<n;++i) {
            char t[2];
            scanf("%s%d", t, p+i);
            d[i]=*t=='R'?1:-1;
        }
#define f(i) (0<p[i] and p[i]<l)
#define swap(x, y) { int $=x; x=y; y=$; }
        int sec=-1, last=-1;
        bool done=false;
        while (!done) {
            done=true;
            int x=-1;
            for(int i=0;i<n;++i) if (f(i)) {
                p[i]+=d[i];
                if (x<0) { last=i; x=p[i]; }
                else if (p[i]==0) { last=i; }
                done=false;
            }
            for(int i=0;i<n;++i) if (f(i))
                for(int j=i+1;j<n;++j) if (f(j) and p[i]==p[j])
                    swap(d[i], d[j]);
            ++sec;
        }
        printf("%d %d\n", sec, last+1);
    }
}

Measured memory_bytes: 1012
#include <bits/stdc++.h>
#include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++)
using namespace std;
int a[101][101],start[101],end[101],n,p=0,v[101];
queue<int> q;
void bfs(int u){
	q.push(u);
	v[u]++;
	while(!q.empty()){
		u=q.front();q.pop();
		r(i,1,n+1)if(!v[i]&&a[u][i]){
			v[i]++;
			q.push(i);
			start[i]=start[u]+1;
		}
	}
}
int main(){
	int q,qq,qqq;
	cin>>n;
	r(i,0,n){
		cin>>q>>qq;
		r(i,0,qq){
			cin>>qqq;
			a[q][qqq]++;
		}
	}
	bfs(1);
	r(i,1,n+1){
		if(i!=1&&start[i]==0)cout<<i<<' '<<-1<<endl;
		else cout<<i<<' '<<start[i]<<endl;
	}
}

Measured memory_bytes: 3116
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

map<ll, ll> mp;
ll A, B, C, D;
ll dp(ll N) {
    if(mp.count(N)) return mp[N];
    if(N == 0) return mp[N] = 0;
    
    ll ans;
    if(__builtin_mul_overflow(N, D, &ans)) ans = LONGINF;
    vector<ll> cal = {A, B, C};
    vector<ll> div = {2, 3, 5};

    for(int i=0; i<3; i++) {
        ll c = cal[i], d = div[i];
        // ceil
        {
            ll k = (N+d-1) / d;
            if(k!=N) chmin(ans, dp(k) + (k*d - N)*D + c);
        }
        // floor
        {
            ll k = N / d;
            if(k!=N) chmin(ans, dp(k) + (N - k*d)*D + c);
        }
    }
    return mp[N] = ans;
}

void solve() {
    mp.clear();
    ll N; cin >> N >> A >> B >> C >> D;
    cout << dp(N) << endl;
}

int main() {
    int T; scanf("%d", &T);
    while(T--) solve();
    return 0;
}


Measured memory_bytes: 4404
import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.numeric;

void main() {
  int k;
  readf (" %d", &k);
  long s;
  foreach (i; 1 .. k + 1) {
    foreach (j; 1 .. k + 1) {
      int g = gcd (i, j);
      foreach (u; 1 .. k + 1) {
        s += gcd (g, u);
      }
    }
  }
  writeln(s);
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll h, w; cin>>h>>w;
    vector<string> ss(h); cin>>ss;
    vvl hs(h, vl(w)), ws(h, vl(w));
    rep(i, h) {
        ll cnt = 0;
        rep(j, w) {
            if (ss[i][j] == '.') {
                cnt++;
                hs[i][j] = cnt;
            }
            else cnt = 0;
        }
        ll cur = 0;
        rep(j, w) {
            if (hs[i][w - j - 1] == 0) {
                cur = 0;
                continue;
            }
            chmax(cur, hs[i][w - j - 1]);
            hs[i][w - j - 1] = cur;
        }
    }
    rep(j, w) {
        ll cnt = 0;
        rep(i, h) {
            if (ss[i][j] == '.') {
                cnt++;
                ws[i][j] = cnt;
            }
            else cnt = 0;
        }
        ll cur = 0;
        rep(i, h) {
            if (ws[h - i - 1][j] == 0) {
                cur = 0;
                continue;
            }
            chmax(cur, ws[h - i - 1][j]);
            ws[h - i - 1][j] = cur;
        }
    }

    ll ans = 0;
    rep(i, h) {
        rep(j, w) {
            chmax(ans, hs[i][j] + ws[i][j] - 1);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 70168
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <climits>

using namespace std;

//BEGIN
template <typename T, typename E>
struct LazySegmentTree {
	using F = function<T(T, T)>;
	using G = function<T(T, E)>;
	using H = function<E(E, E)>;
	
	int n, height;
	vector<T> tree;
	vector<E> lazy;
	const F f;
	const G g;
	const H h;
	const T ti;
	const E ei;

	LazySegmentTree() {}
	LazySegmentTree(F f, G g, H h, T ti, E ei) :f(f), g(g), h(h), ti(ti), ei(ei) {}

	void init(int n_) {
		n = 1, height = 0;
		while (n < n_) n *= 2, ++height;
		tree.assign(2 * n, ti);
		lazy.assign(2 * n, ei);
	}

	void build(const vector<T>& v) {
		int n_ = v.size();
		init(n_);
		for (int i = 0; i < n_; ++i) tree[n + i] = v[i];
		for (int i = n - 1; i > 0; --i) tree[i] = f(tree[2 * i], tree[2 * i + 1]);
	}

	inline T reflect(int k) { return (lazy[k] == ei?tree[k]:g(tree[k], lazy[k])); }

	inline void eval(int k) {
		if (lazy[k] == ei) return;
		lazy[2 * k] = h(lazy[2 * k], lazy[k]);
		lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
		tree[k] = reflect(k);
		lazy[k] = ei;
	}

	inline void thrust(int k) { for (int i = height; i > 0; --i) eval(k >> i); }

	inline void recalc(int k) {
		while (k >>= 1)
			tree[k] = f(reflect(2 * k), reflect(2 * k + 1));
	}
	
	void update(int s, int t, const E& x) { // [l, r)
		s += n, t += n;
		thrust(s), thrust(t - 1);
		int l = s, r = t;
		while (l < r) {
			if (l & 1) lazy[l] = h(lazy[l], x), ++l;
			if (r & 1) --r, lazy[r] = h(lazy[r], x);
			l >>= 1, r >>= 1;
		}
		recalc(s), recalc(t - 1);
	}

	T find(int s, int t) { // [l, r)
		s += n, t += n;
		thrust(s), thrust(t - 1);
		int l = s, r = t;
		T ll = ti, rr = ti;
		while (l < r) {
			if (l & 1) ll = f(ll, reflect(l++));
			if (r & 1) rr = f(rr, reflect(--r));
			l >>= 1, r >>= 1;
		}
		return f(ll, rr);
	}

	T at(int i) { return find(i, i + 1); }
};
//END

void DSL_2_F() {
	int n, q; cin >> n >> q;
	auto f = [](int a, int b) { return min(a, b); };
	auto g = [](int a, int b) { return b; };
	LazySegmentTree<int, int> seg(f, g, g, INT_MAX, -1);
	seg.init(n);
	while (q--) {
		int com, s, t, x; cin >> com >> s >> t;
		if (com) cout << seg.find(s, t + 1) << endl;
		else cin >> x, seg.update(s, t + 1, x);
	}
}
/*
	created: 2019-12-05
	https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_F
*/

int main() {
	DSL_2_F();

	return 0;
}


Measured memory_bytes: 4964
# coding: utf-8
# Your code here!

# coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(10000000)

#const
dxdy=((1,0),(0,1))
# my functions here!
def pin(type=int):
    return map(type,input().rstrip().split())

def resolve():
    k,=pin()
    ans=0
    for i in range(1,k+1):
        if i%3!=0 and i%5!=0:
            ans+=i
    print(ans)
    
    
"""         
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じ,るの忘れてるだろ
"""
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """15"""
        output = """60"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """1000000"""
        output = """266666333332"""
        self.assertIO(input, output)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 16344
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int a = Integer.parseInt(scanner.next());
        int b = Integer.parseInt(scanner.next());
        int c = Integer.parseInt(scanner.next());
        ArrayList<Integer> i = new ArrayList<Integer>();
        int[][] s = new int[a][b];
        for(int x = 0; x < b; x++){
            i.add(Integer.parseInt(scanner.next()));
        }
        for(int xx = 0; xx < a; xx++){
            for(int xxx = 0; xxx < b ; xxx++ ){
                s[xx][xxx] = Integer.parseInt(scanner.next());
            }
        }
        scanner.close();
        int[] ii = i.stream().mapToInt(Integer::intValue).toArray();
        int count = 0;
        for(int y = 0; y < a; y++){
            int res = 0;
            for(int yy = 0; yy < b; yy++){
                res += ii[yy] * s[y][yy];
            }
            if(res + c > 0) count++;
        }

        System.out.println(count);
    }
}


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

using namespace std;

bool balanced(string s)
{
    deque<char> deq;
    for(string::iterator itr = s.begin(); itr!=s.end(); itr++)
    {
        switch(*itr)
        {
            case '(':
                deq.push_back(')');
                break;
            case '[':
                deq.push_back(']');
                break;
            case ')':
            case ']':
                if(deq.empty() || deq.back() != *itr) return false;
                deq.pop_back();
                break;
        }
    }
    return deq.empty();
}

int main()
{
    string s;
    while(getline(cin, s), s!=".")
    {
        cout << (balanced(s) ? "yes" : "no") << endl;
    }
}

Measured memory_bytes: 3160
<?php
list($n) = ints();
list($a, $b) = ints();
$p = ints();
$cnt1 = $cnt2 = $cnt3 = 0;
for ($i = 0; $i < $n; ++$i) {
    if ($p[$i] <= $a) ++$cnt1;
    elseif ($p[$i] <= $b) ++$cnt2;
    else ++$cnt3;
}
echo min($cnt1, $cnt2, $cnt3);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16076
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll inf = (1LL << 60LL);
const int maxn = 200006;
ll n, X;
ll arr[maxn];
bool can(ll dist){
    for(int i = 0; i < n; i ++){
        if(llabs(arr[i] - X) % dist != 0){
            return false;
        }
    }
    return true;
}
ll gcd(ll a, ll b){
    if(a < b){
        swap(a, b);
    }
    
    /// gcd(b, a % b)
    ll tmp;
    while(b){
        tmp = a;
        a = b;
        b = tmp % b;
    }
    return a;
}
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin >> n >> X;
    for(int i = 0; i < n; i ++){
        cin >> arr[i];
    }
    ll ret = llabs(arr[0] - X);
    for(int i = 1 ; i < n; i ++){
        ret = gcd(ret, llabs(arr[i] - X));
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(), k=sc.nextInt();
		final long mod = 1000000007;
		int[] array = new int[n];
		for(int i=0;i<n;i++) array[i]=sc.nextInt();
		sc.close();
		long count=0, temp=0;
		for(int i=0;i<n-1;i++) {
			for(int j=i+1;j<n;j++) {
				if(array[i]>array[j]) count++;
			}
		}
		count*=k;
		count%=mod;
		Arrays.sort(array);
		for(int i=0;i<n-1;i++) {
			for(int j=i+1;j<n;j++) {
				if(array[i]<array[j]) {
					temp++;
				}
			}
		}
		long sum2 = (temp * ((((long)k * (long)(k-1))/2)%mod));
		long sum = (count+sum2)%mod;
		System.out.println(sum);
	}
}


Measured memory_bytes: 26644
#include <iostream>
#include <vector>
#define llint long long

using namespace std;

struct edge{
	int to, k;
	edge(){}
	edge(int a, int b){
		to = a, k = b;
	}
};

llint n;
llint a[55], b[55];
vector<edge> G[55];
bool used[55];

bool dfs(int v, int t, llint mask)
{
	used[v] = true;
	if(v == t) return true;
	bool ret = false;
	for(int i = 0; i < G[v].size(); i++){
		if(used[G[v][i].to]) continue;
		if( (mask & (1LL << G[v][i].k)) == 0 ) continue;
		ret |= dfs(G[v][i].to, t, mask);
	}
	return ret;
}

bool check(llint mask)
{
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= 50; j++) used[j] = false;
		if(!dfs(a[i], b[i], mask)) return false;
	}
	return true;
}

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) cin >> b[i];
	
	for(int i = 0; i <= 50; i++){
		for(int j = 1; j <= 50; j++){
			G[i].push_back(edge(i%j, j));
		}
	}
	
	llint ans = 0;
	for(int i = 50; i >= 0; i--){
		if(!check(ans + (1LL<<i) - 1)) ans += (1LL<<i);
	}
	if(!check((1LL<<51)-1)) ans = -1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
class Stack:
    def __init__(self):
        self.stack = []

    def push(self, value):
        self.stack.append(value)

    def pop(self):
        return self.stack.pop(-1)

def calc(array):
    stack = Stack()
    for s in array:
        if s.isdigit():
            stack.push(int(s))
        else:
            o2 = stack.pop()
            o1 = stack.pop()
            ans = 0
            if s == '+':
                ans = o1 + o2
            elif s == '-':
                ans = o1 - o2
            elif s == '*':
                ans = o1 * o2
            elif s == '/':
                ans = o1 / o2
            stack.push(ans)
    return stack.pop()


def main():
    in_arr = input().split()
    print(calc(in_arr))

if __name__ == '__main__':
    main()

Measured memory_bytes: 7752
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
  int A = inputValue();
  int B = inputValue();

  int ans = 1;
  int kuchi = A;
  while(kuchi<B){
    ans++;
    kuchi += A-1;
  }
  if(B == 1){
    ans = 0;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int inf = 1e9;
const int mod = 1e9+7;

int main() {
    int N;
    cin >> N;
    int A[N];
    ll S = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        S += A[i];
    }

    ll x_sum = 0;
    for (int i = 1; i <= N-2; i+=2) {
        x_sum += (2 * A[i]);
    }

    int x[N];
    x[0] = (int)(S - x_sum);
    for (int i = 0; i < N-1; i++) {
        x[i+1] = 2 * A[i] - x[i];
    }

    for (int i = 0; i < N; i++) {
        cout << x[i];
        if (i != N-1) cout << " ";
        else cout << endl;
    }

    return 0;
}


Measured memory_bytes: 2048
N, K  = map(int, input().split())
S = input()

lst = [0]
for i in range(N - 1):
    if S[i] != S[i + 1]:
        lst.append(i + 1)
lst.append(N)
# print(lst)

sub = []
for j in range(1, len(lst)):
    sub.append(S[lst[j - 1]:lst[j]])
# print(sub)
diff = [lst[i + 1] -lst[i] for i in range(len(lst) - 1)]
# print(diff)

if S[0] == '1' and len(lst) - 1 <= 2 * K + 1:
    print(N)
elif S[0] == '0' and len(lst) - 1 <= 2 * K:
    print(N)
else:
    candicate = []
    for i in range(len(lst) - 1 - K * 2):
        if S[lst[i]] == '1':
            candicate.append(lst[i + K * 2 + 1] - lst[i])
    if S[-1] == '0':
        candicate.append(lst[-1] - lst[-1 - K * 2])
    for i in range(len(lst) - K * 2):
        if S[lst[i]] == '0':
            candicate.append(lst[i + K * 2] - lst[i])
    # print(candicate)
    print(max(candicate))





Measured memory_bytes: 50888
#include<stdio.h>
int main(void){
    while(1){
        int n;
        scanf("%d",&n);
        if(n==0) break;
        int r[1000],w[1000];
        int rL=0,r_sum=0,w_sum=0;
        int idx;
        for(int i=0;i<n;i++){
            scanf("%d%d",&r[i],&w[i]);
            r_sum+=r[i]; w_sum+=w[i];
            if(rL<r[i]){
                rL=r[i];
                idx=i;
            }
        }
        if(r_sum>=2*rL){
            printf("%d\n",r_sum+w_sum);
        }
        else{
            int sa=2*rL-r_sum;
            int dp[1001][1001]={0};
            int j=0;
            for(int i=0;i<n;i++){
                if(i==idx) continue;
                else w[j++]=w[i];
            }
            for(int i=0;i<n-1;i++){
                for(int j=0;j<=sa;j++){
                    if(w[i]<=j && dp[i][j]<dp[i][j-w[i]]+w[i]){
                        dp[i+1][j]=dp[i][j-w[i]]+w[i];
                    }else{
                        dp[i+1][j]=dp[i][j];
                    }
                }
            }
            int max=dp[n-1][sa];
            /*for(int j=0;j<=sa;j++)
                if(max<dp[n-1][j]) max=dp[n-1][j];*/
            printf("%d\n",2*rL+w_sum-max);
        }
    }
}



Measured memory_bytes: 5720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int a[10][10], h, w;
	cin >> h >> w;
	for (int i = 0; i < 10; i++)
		for (int j = 0; j < 10; j++)
			cin >> a[i][j];
	for (int k = 0; k < 10; k++)
		for (int i = 0; i < 10; i++)
			for (int j = 0; j < 10; j++)
				a[i][j] = min(a[i][k] + a[k][j], a[i][j]);
	int arr[h][w],ans = 0;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
		{
			int x;
			cin >> x;
			if(x != -1) ans+= a[x][1];
		}
	cout << ans << endl;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
void solve(){
	int a, b, c, k, ans = 0;
	cin >> a >> b >> c >> k;
	ans += min(k, a);
	k -= min(k, a);
	k -= min(k, b);
	ans -= min(k, c);
	k -= min(k, c);
	cout << ans << '\n';
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
}

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

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    string ans = "";
    ans += string(d - b, 'U');
    ans += string(c - a, 'R');
    ans += string(d - b, 'D');
    ans += string(c - a + 1, 'L');
    ans += string(d - b + 1, 'U');
    ans += string(c - a + 1, 'R');
    ans += 'D';
    ans += 'R';
    ans += string(d - b + 1, 'D');
    ans += string(c - a + 1, 'L');
    ans += 'U';

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3640
N = int(input())
S = str(N)
l = len(S)


ans = 0


def dfs(n):
    global ans
    if len(str(n)) == l:
        if len(set(list(str(n)))) == 3 and n <= N:
            ans += 1
        return
    else:
        if len(set(list(str(n)))) == 3:
            ans += 1

    dfs(int(str(n) + "3"))
    dfs(int(str(n) + "5"))
    dfs(int(str(n) + "7"))


dfs(3)
dfs(5)
dfs(7)

print(ans)


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

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

    double ans = 0;
    double x;
    string u;
    for (int i = 0; i < n; i++) {
        cin >> x >> u;

        if (u == "JPY") {
            ans += x;
        } else {
            ans += (x * 380000.0);
        }
    }


    cout << fixed << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INL inline
#define REG register
#define DB double
#define LDB long double
#define ULL unsigned long long
#define LL long long

#define RPT(i,x,y) for (REG int i=(x);i<(y);i++)
#define DRPT(i,x,y) for (REG int i=(x);i>(y);i--)
#define MST(a,b) memset((a),(b),sizeof(a))
#define MRK() cout<<"Mark"<<endl;
#define WRT(x) cout<<#x<<" = "<<(x)<<endl;
#define SUB(s,s0) for (REG int s=s0;s;s=(s-1)&s0)

#define MAXN 210000
#define MAXM 10000
#define MOD 998244353
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-5

#define _ 0
using namespace std;

int n;
int s;
int dp[10000000];
int node[MAXN];
int count(int cur)
{
	int ans=0;
	RPT(i,0,16)
		if (cur & (1<<i))
			ans++;
	return ans;
}

int xo(int cur)
{
	int ans=0;
	RPT(i,0,16)
		if (cur & (1<<i))
			ans^=(i+1);
	return ans;
}

int dfs(int cur)
{
	//WRT(cur);
	if (dp[cur]!=0)
		return dp[cur];
	dp[cur]=count(cur)-1;
	if (dp[cur]==-1)
	{
		dp[cur]=0;
		return 0;
	}
	SUB(s,cur)
		if (xo(s)==0 && s!=cur)
		{
			//cout<<s<<' '<<xo(s)<<endl;
			dp[cur]=min(dp[cur],dfs(s)+dfs(cur^s));
		}
	return dp[cur];
}

LL ans;
int main()
{
	cin>>n;
	int x,y,z;
	RPT(i,0,n-1)
	{
		scanf("%d%d%d",&x,&y,&z);
		node[x]^=z;
		node[y]^=z;
	}
	RPT(i,0,n)
	{
		//WRT(x);
		x=node[i];
		if (x==0)
			continue;
		if ((s&(1<<(x-1)))!=0)
			ans++;
		s^=(1<<(x-1));
	}
	//WRT(ans);
	//WRT(s);
	//WRT(xo(s));
	cout<<ans+dfs(s);
	return ~~(0^_^0);
}



Measured memory_bytes: 768
#!/usr/bin/env python3
import itertools

N = int(input().split()[0])
s = str(N)
l = list(range(1, 10))
p_gen = itertools.product(l, repeat=2)
p_list = list(p_gen)
K = len(str(s))


def count_kouho(x, y):
    count = 0
    for k in range(1, K + 1):
        # 1桁目
        if k == 1:
            if x == y:
                if x <= N:
                    count += 1
            continue
        # 2桁目
        if k == 2:
            if int(str(x) + str(y)) <= N:
                count += 1
            continue
        # 3桁目以上
        if k == K:
            # 一番大きい桁の場合
            # TODO
            if x < int(s[0]):
                count += 10 ** (k - 2)
            elif x > int(s[0]):
                pass
            else:
                if y <= int(s[-1]):
                    count += int(s[1:-1]) + 1
                else:
                    count += int(s[1:-1])
            continue
        count += 10 ** (k - 2)
    return count


c = 0

for p in p_list:
    head, tail = p
    kouho_1 = count_kouho(head, tail)
    if head == tail:
        kouho_2 = kouho_1
    else:
        kouho_2 = count_kouho(tail, head)
    if kouho_1 < 1 or kouho_2 < 1:
        # print("{} skip".format((head, tail)))
        continue
    new_c = kouho_1 * kouho_2
    # print("{}: {} ({})".format((head, tail), (kouho_1, kouho_2), new_c))
    c += new_c

ans = c
print(ans)


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

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

	int S, W;
	scanf("%d %d", &S, &W);

	if (W >= S) {
		printf("unsafe");
	} else {
		printf("safe");
	}
	return 0;
}

Measured memory_bytes: 3752
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int W = in.nextInt();
		int H = in.nextInt();
		int x = in.nextInt();
		int y = in.nextInt();
		int r = in.nextInt();
		if(x + r > W || x - r < 0){
			System.out.println("No");
		}else if(y + r > H || y - r < 0){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
	}
}

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

int main() {
  int H,W;
  cin >> H >> W;
  
  string pixels;
  string border;

  for (int i = 0; i < W+2; i++) {  
    border += "#";
  }

  cout << border << endl;

  for (int i = 0; i < H; i++) {
    cin >> pixels;
    cout << '#' + pixels + '#' << endl;
  }

  cout << border << endl;
}

Measured memory_bytes: 256