akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here! 
        Scanner sc = new Scanner(System.in);
        
        // n (10^12以下なら高速)
        long n = sc.nextLong();
        
        // map: nの素因数の頻度 (60 => (2 -> 2, 3 -> 1, 5 -> 1)
        // list: nの素因数のリスト (60 => [2, 2, 3, 5])
        Map<Long, Integer> map = new HashMap<Long, Integer>();
        List<Long> list = new ArrayList<Long>();
        long m = n;
        for (long i = 2; (i * i) <= n; i++) {
            int cnt = 0;
            
            while ((m % i) == 0) {
                cnt++;
                m /= i;
                list.add(i);
            }
            
            if (cnt > 0) {
                map.put(i, cnt);
            }
        }
        if (m > 1) {
            map.put(m, 1);
            list.add(m);
        }
        
        int count = 0;
        for (Long key : map.keySet()) {
            int val = map.get(key);
            
            // System.out.println(key + " " + val);
            int tmp = 1;
            while (true) {
                val -= tmp;
                
                if (val >= 0) {
                    tmp++;
                    count++;
                } else {
                    break;
                }
            }
        }
        System.out.println(count);
    }
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

int main(){
  string S;cin >> S;
  cout << count(S.begin(),S.end(),'2') << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[200005], price[200005];
int main()
{
    int n, tot = 0;
    cin >> n;
    for ( int i = 1; i <= n; i++ )
    {
        cin >> a[i];
    }
    for ( int i = 0; i <= n; i++ )
    {
        tot = tot + abs( a[i+1] - a[i] );
    }
    for ( int i = 1; i <= n; i++ )
    {
        price[i] = tot - abs( a[i] - a[i-1] ) - abs( a[i] - a[i+1] ) + abs( a[i+1] - a[i-1] );
        cout << price[i] << endl;
    }
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
#define all(x) (x).begin(),(x).end()
using namespace std;
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a*b/gcd(a,b);
}
signed main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int x=1,y=1,ans=1;
	f(i,n*2-1){
		if((x&&s[i]!=s[i+1])||(!x&&s[i]==s[i+1])){
			y++;
			x=1;
		}
		else{
			ans*=y;
			y--;
			x=0;
		}
		ans%=mod;
	}
	f(i,n){
		ans*=i+1;
		ans%=mod;
	}
	if(s[0]=='B'&&s[n*2-1]=='B'&&y==0)cout<<ans<<endl;
	else cout<<0<<endl;
}


Measured memory_bytes: 640
<?php
  declare(strict_types=1);

  fscanf(STDIN, "%i %i", $n, $m);
  $ferries = [];
  for ($i = 0; $i < $m; ++$i)
  {
      fscanf(STDIN, "%i %i", $a, $b);
      if (!isset($ferries[$a]))
      {
          $ferries[$a] = [];
      }
      if (!isset($ferries[$b]))
      {
          $ferries[$b] = [];
      }
      $ferries[$a][$b] = TRUE;
      $ferries[$b][$a] = TRUE;
  }
  
  $any = FALSE;
  foreach ($ferries[1] as $island => $_)
  {
      $any = $any || isset($ferries[$n][$island]);
      if ($any)
      {
          break;
      }
  }

  if ($any)
  {
      echo "POSSIBLE", PHP_EOL;
  }
  else
  {
      echo "IMPOSSIBLE", PHP_EOL;
  }


Measured memory_bytes: 94712
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
struct edge {
    int to;
    ll cost;
};
vector<edge> G[100005];
ll dist[100005];
void dfs(int from, int s, ll cost) {
    if (dist[s] == 1LL << 60) {
        if (from != -1)
            dist[s] = dist[from] + cost;
        else
            dist[s] = 0;
        rep(i, G[s].size()) { dfs(s, G[s][i].to, G[s][i].cost); }
    } else {
        if (dist[s] != dist[from] + cost) {
            puts("No");
            exit(0);
        }
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int l, r;
        ll d;
        cin >> l >> r >> d;
        l--, r--;
        G[l].push_back(edge{r, d});
        G[r].push_back(edge{l, -d});
    }
    fill(dist, dist + n, 1LL << 60);
    rep(i, n) {
        if (dist[i] == 1LL << 60) {
            dfs(-1, i, 0);
        }
    }
    puts("Yes");
    return 0;
}

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

using namespace std;

const int inf = 1e9;

int main () {

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  
  int N; cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; ++i)
    cin >> a[i];
  int ans = inf;
  for (int i = -100; i < 101; ++i) {
    int curr = 0;
    for (int j = 0; j < N; ++j) {
      curr += (a[j] - i) * (a[j] - i);
    }ans = min(ans, curr);
  }cout << ans << '\n';

  return 0;
}




Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 1000005

//Suffix_Array
//O(|T|log|S|) S??????????????????T????????????????????????????´¢
#define rank A
int n,Len;
int rank[MAX_N+1];
int tmp[MAX_N+1];

//(rank[i],rank[i+k])??¨(rank[j],rank[j+k])?????????
bool compare_sa(int i,int j){
  if(rank[i]!=rank[j])return rank[i]<rank[j];
  int ri=i+Len<=n?rank[i+Len]:-1;
  int rj=j+Len<=n?rank[j+Len]:-1;
  return ri<rj;
}

//?????????S?????\?°??????????????§????
void construct_sa(string S,int *sa){
  n=S.length();
  //?????????????????????????????????????????????????????????
  for(int i=0;i<=n;i++){
    sa[i]=i;
    rank[i]=i<n?S[i]:-1;
  }
  //k????????????????????????????????????????????¨???????????????2k????????§?????????
  for(Len=1;Len<=n;Len*=2){
    sort(sa,sa+n+1,compare_sa);
    //?????£??????tmp????¬?????????????????¨?????????????rank?????£??\
    tmp[sa[0]]=0;
    for(int i=1;i<=n;i++)
      tmp[sa[i]]=tmp[sa[i-1]]+(compare_sa(sa[i-1],sa[i])?1:0);
    for(int i=0;i<=n;i++)rank[i]=tmp[i];
  }
}

//S??????????????????T????????????????????????????´¢??????
bool contain(string S,int *sa,string T){
  int left=0,right=S.length();
  while(right-left>1){
    int mid=(left+right)/2;
    if(S.compare(sa[mid],T.length(),T)<0)left=mid;
    else right=mid;
  }
  return S.compare(sa[right],T.length(),T)==0;
}


string t,p;
int q,sa[MAX_N];
int main(){
  cin>>t;
  construct_sa(t,sa);
  cin>>q;
  while(q--){
    cin>>p;
    if(contain(t,sa,p))cout<<1<<endl;
    else cout<<0<<endl;
  }
  return 0;
}

Measured memory_bytes: 16500
#include<iostream>
#include <vector>
#include <algorithm>
#include "math.h"
using namespace std;

int main()
{
  long long N;
  cin >> N;
  std::vector<long long> X;
  for (long long  i=0; i < N; i++) {
    long long n;
    cin >> n;
    X.push_back(n);
  }
  long long max = *std::max_element(X.begin(), X.end());
  long long mid1, mid2;
  if (max % 2 == 0) {
    mid1 = max / 2;
    mid2 = max / 2;
  } else {
    mid1 = max / 2;
    mid2 = max / 2 + 1;
  }
  long long max_b = 0;
  long long min_diff = 10000000000;
  for (long long n : X) {
    if (n == max) {
      continue;
    }
    if (abs(mid1 - n) < min_diff)  {
      min_diff = fabs(mid1 - n);
      max_b = n;
    }
    if (abs(mid2 - n) < min_diff)  {
      min_diff = fabs(mid2 - n);
      max_b = n;
    }
  }
  std::cout << max << " " << max_b << endl;
  return 0;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                double x = int.Parse(Console.ReadLine());
                double h = int.Parse(Console.ReadLine());

                if (x == 0 && h == 0) break;

                double th = Math.Sqrt((x / 2) * (x / 2) + h * h);

                double area = x * x + (x * th) * 2;

                sb.AppendLine(area.ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9040
def solve():
    N, K = map(int, input().split())
    cs = [0] * (N + 1)
    for i in range(1, N + 1):
        cs[i] = cs[i - 1] + i
    # print(cs)
    ans = 0
    for i in range(K, N + 2):
        if i == N + 1:
            ans += 1
        else:
            mn = cs[i - 1]
            mx = cs[-1] - cs[-1 - i]
            ans += mx - mn + 1
        # print(i, mx, mn, ans)
        ans = ans % (10**9 + 7)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 19108
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
//#define __int64 long long
//const ll M=1000000007;
int a,b,c,x,y;

int main(){
	cin>>a>>b>>c>>x>>y;
	int ans=0;
	int mi=min(x,y),ma=max(x,y);
	ans+=mi*min(a+b,c*2);

	if(x>y){
		ans+=(x-y)*min(a,c*2);
	}
	else{
		ans+=(y-x)*min(b,c*2);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const double EPS = 1e-10;

double intersect(double xa, double ya, double xb, double yb, double xc, double yc, double xd, double yd){
    double g =  (xb - xa)*(yd - yc) - (yb - ya)*(xd - xc);
    if (fabs(g) < EPS) return -1;
    double r = ((yd - yc)*(xc - xa) - (xd - xc)*(yc - ya)) / g;
    double s = ((yb - ya)*(xc - xa) - (xb - xa)*(yc - ya)) / g;
    if (r < 0 || r > 1 || s < 0 || s > 1) return -1;
    return r;
}

int calc(){
    double xa, ya, xb, yb;
    cin >> xa >> ya >> xb >> yb;
    int n;
    cin >> n;
    vector<pair<double, int> > a;
    while (n--){
        double xs, ys, xt, yt;
        int p, q;
        cin >> xs >> ys >> xt >> yt >> p >> q;
        double r = intersect(xa, ya, xb, yb, xs, ys, xt, yt);
        if (r > 0 && r < 1){
            a.push_back(make_pair(r, p^q));
        }
    }
    sort(a.begin(), a.end());
    if (a.size() <= 1) return 0;
    int ans = 0;
    REP(i,a.size()-1){
        if (a[i].second != a[i+1].second) ans++;
    }
    return ans;
}

int main() {
    int m;
    cin >> m;
    while (m--){
        cout << calc() << endl;
    }

    return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

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

	
	int n;
	cin >> n;
	vector<string> w(n);
	for (int i = 0; i < n; ++i)
		cin >> w[i];
	for(int i = 0; i + 1 < n; ++i)
		if (w[i].back() != w[i + 1].front()) {
			cout << "No\n";
			return 0;
		}

	if (set<string>(w.begin(), w.end()).size() != n) {

		cout << "No\n";
		return 0;

	}
	cout << "Yes\n";
	return 0;
	// return 0;
}

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

using CP = complex<long double>;
#define X real()
#define Y imag()
const long double PI = acos(-1);
const long double EPS = 1e-10;
// conj(x) : complex conjugate,(0,1)->(0,-1)
// abs(x) : dist between(0,0) and x
// norm(x) : abs(x) * abs(x)
// arg(x) : argment
long double dot(CP a, CP b) { return (a * conj(b)).X; }
long double cross(CP a, CP b) { return (a * conj(b)).Y; }
long double corner(CP a, CP b) {
  //[0,pi]
  return acos(dot(a, b) / (abs(a) * abs(b)));
}

CP intersection(CP a, CP b, CP c, CP d) {
  return a + (b - a) * (cross(d - c, c - a) /
                        cross(d - c, b - a));
}

bool on_seg(CP a, CP b, CP p) {
  // if not use end point, dot(a - p, b - p) < 0
  return abs(cross(a - p, b - p)) <= 1e-10 &&
         dot(a - p, b - p) <= 0;
}

// crossing lines? (a,b) and (c,d)
bool iscross(CP a, CP b, CP c, CP d) {
  // parallel
  if(abs(cross(a - b, c - d)) <= 1e-10) {
    return on_seg(a, b, c) || on_seg(a, b, d) ||
           on_seg(c, d, a) || on_seg(c, d, b);
  }
  CP isp = intersection(a, b, c, d);
  return on_seg(a, b, isp) && on_seg(c, d, isp);
}

long double distLP(CP a, CP b, CP p) {
  return abs(cross(b - a, p - a) / abs(b - a));
}

// segmentver.
long double distSP(CP a, CP b, CP p) {
  if(dot(b - a, p - a) < 0) return abs(p - a);
  if(dot(a - b, p - b) < 0) return abs(p - b);
  return distLP(a, b, p);
}

long double distSS(CP a, CP b, CP c, CP d) {
  long double res = 1e18;
  res = min(res, distSP(a, b, c));
  res = min(res, distSP(a, b, d));
  res = min(res, distSP(c, d, a));
  res = min(res, distSP(c, d, b));
  return res;
}

long long n;
long double res = 1e18;
CP s, t;

int main() {
  cout << fixed << setprecision(10);
  while(1) {
    cin >> n;
    if(n == 0) break;
    long double a, b, c, d, h, dist;
    cin >> a >> b >> c >> d;
    s = CP(a, b);
    t = CP(c, d);
    res = 1e18;
    for(int i = 0; i < n; ++i) {
      cin >> a >> b >> c >> d >> h;
      if(iscross(s, t, CP(a, b), CP(c, d)) ||
         iscross(s, t, CP(a, d), CP(c, b)))
        res = 0;
      dist = 1e18;
      dist = min(dist, distSS(s, t, CP(a, b), CP(c, b)));
      dist = min(dist, distSS(s, t, CP(a, b), CP(a, d)));
      dist = min(dist, distSS(s, t, CP(c, b), CP(c, d)));
      dist = min(dist, distSS(s, t, CP(a, d), CP(c, d)));
      if(dist <= h)
        res = min(res, dist);
      else
        res = min(res, (h * h + dist * dist) / (2 * h));
    }

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



Measured memory_bytes: 3284
fun main(args: Array<String>) {
    var str = readLine()
    if(str != null) {
        val ary = str.split(Regex("\\s+"))
        val a = ary[0].toInt()
        val b = ary[1].toInt()
        val ans = if (a > b) "a > b"
        else if (a < b) "a < b"
        else "a == b"
        println(ans)
    }
 }


Measured memory_bytes: 29568
from copy import copy

def merge(arr, left, middle, right):
    L = arr[left:middle]
    L.append([None, float('inf')])
    R = arr[middle:right]
    R.append([None, float('inf')])

    iterL, iterR = iter(L), iter(R)
    l,r = next(iterL), next(iterR)

    for index in range(left, right):
        if l[1] <= r[1]:
            arr[index] = l
            l = next(iterL)
        else:
            arr[index] = r
            r = next(iterR)


def merge_sort(arr, left, right):
    if left + 1 < right:
        pivot = (left + right) // 2
        merge_sort(arr, left,  pivot)
        merge_sort(arr, pivot, right)
        merge(arr, left, pivot, right)


def partition(arr, start, end):
    criteria = arr[end][1]
    idx1 = start
    for idx2 in range(start, end):
        if arr[idx2][1] <= criteria:
            arr[idx1],arr[idx2] = arr[idx2],arr[idx1]
            idx1 += 1
    arr[idx1],arr[end] = arr[end],arr[idx1]
    return idx1

def quick_sort(arr, start, end):
    if start < end:
        pivot = partition(arr, start, end)
        quick_sort(arr, start, pivot - 1)
        quick_sort(arr, pivot +1, end)


num = int(input())
arr = []
for index in range(num):
    sign, number = input().split()
    arr.append([sign, int(number)])

arr1 = copy(arr)
arr2 = copy(arr)

merge_sort(arr1, 0, num)
quick_sort(arr2, 0, num - 1)

print("Stable" if arr1 == arr2 else "Not stable")
for sign, number in arr2:
    print(sign + " " + str(number))


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

int main()
{
  int n, m;
  cin >> n >> m;
  int a[n], b[n];
  int c[m], d[m];
  rep(i, n) cin >> a[i] >> b[i];
  rep(i, m) cin >> c[i] >> d[i];
  
  ll mi = 10000000000;
  
  int ans;
  rep(i, n){
    mi = 10000000000;
    rep(j, m){
      if((abs(a[i] - c[j]) + abs(b[i] - d[j])) < mi){
        mi = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
      

  return 0;
}

Measured memory_bytes: 3588
import java.io.*;

class Main{
 
  public static void main(String args[])throws IOException{
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();
    
    if(str.length() != 6)
      System.out.println("No");
    else{
      if((str.charAt(2) == str.charAt(3)) && (str.charAt(4) == str.charAt(5))){
      	System.out.println("Yes");
      }
      else{
        System.out.println("No");
      }
    }
  }
}

Measured memory_bytes: 21204
#include<iostream>
#include<string>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

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

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

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

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

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

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

int main() {
	int N; string S[2];

	cin >> N >> S[0] >> S[1];

	ll ans = 1;

	int x = 0;
	int pre = -1;

	while (x < N) {

		//縦
		if (S[0][x] == S[1][x]) {

			//初回は自由に3つ選べる。
			if (pre < 0)ans = 3;

			//前回が縦なら、使っていない2色選べる。
			else if (pre == 0)ans=ans * 2 % MOD;

			//前回が横なら、残り1色しかおけない。
			else ans *= 1;

			//幅を1個進める。
			//履歴を縦を選んだことにする。
			x++; pre = 0;
		}

		//横
		else {

			//初回、6 3色選んで、残った2色を選ぶ
			if (pre < 0)ans = 6;
			//前回が縦なら、使ってない2色、残りの1色で2*1=2
			else if (pre == 0)ans =ans*2%MOD;

			//前回が横ならBA BC CAの3種類
			//A| BB C
			//B| AC A

			else ans =ans*3%MOD;

			//幅を2個進める。
			//履歴を横に選んだことにする。
			x += 2; pre = 1;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;
 
 int main(void){
	 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
def function(n):
    if n < 3:
        lis.append(0)
    elif 3 <= n < 6:
        lis.append(1)
    else:
        lis.append(lis[n-1] + lis[n-3])
    

def recri(s):
    for n in range(s):
        function(n)

# for n in range(20):
    # print(function(n))
if __name__ == '__main__':
    lis = []
    s = int(input()) + 1
    recri(s)
    print(lis[s-1]%(10 ** 9 + 7))

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

int main () {
  while(1){
    int a , b ;
    cin >> a >> b ;
    if( a == 0 && b == 0 ) {
      break ;
    }
    int ans = 0 ;
    for(int i = 1 ; i <= a ; i++ ){
      for(int j = i+1 ; j <= a ; j++ ){
        for(int k = j+1 ; k <= a ; k++ ){
          if(i+j+k==b) ans++ ;
        }
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3080
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	long long X, Y;
	cin >> X >> Y;

	int ret = 0;
	for(long long i=X; i<=Y; i+=i){
		ret++;
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main () {

	int a,b,c,x;
    int count = 0;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &x);

  	int ai, bi, ci;
	for(ai = 0 ; ai <= a; ++ai) {
      	for(bi = 0 ; bi <= b; ++bi) {
      		for(ci = 0 ; ci <= c; ++ci) {
      			int total;
                total = 500 * ai + 100 * bi + 50 * ci;
                if (total == x) {
                  ++count;
                }
   			}
    	}
    }
  
  printf("%d", count);
}

Measured memory_bytes: 1736
N = int(input())
t = [0 for i in range(N)]
x = [0 for i in range(N)]
y = [0 for i in range(N)]
for i in range(N):
    t[i], x[i], y[i] = map(int, input().split())
t.insert(0,0)
x.insert(0,0)
y.insert(0,0)
flag = True
for i in range(1, N + 1):
    dist = abs(t[i] - t[i-1]) - abs(x[i] - x[i-1]) - abs(y[i] - y[i-1])
    if dist < 0 or dist % 2 != 0:
        flag = False
        break
print("Yes") if flag else print("No")


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

using namespace std;

int k;
string st;

int main(int argc, char ** argv)
{
	cin >> st;
	cin >> k;
	for (int i = 0; i < st.length(); i++)
	{
		int cur = st[i] - '0';
		if (cur != 1 && k > i)
		{
			cout << cur << endl;
			return 0;
		}
	}
	cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdio.h>

using namespace std;

int main(){
    char s[200];
    char p[100];

    scanf("%s", s);
    scanf("%s", p);

    int length = strlen(s);
    for(int i = 0; i < length; i++){
        s[i + length] = s[i];
    }

    string s_str = s;//translate char to string
    string p_str = p;

    if(s_str.find(p_str) != string::npos){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;
}


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

int main(){
    int n;
    int div = 0;
    string s;
    cin >> n;
    s = to_string(n);
    for(int i=0; i<s.length(); i++){
        div += s[i] - '0';
    }
    if (n%div == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#include<tuple>
#include <numeric>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
#define REP(i,n) for (int i = 1; i <= (int)n; i++)//i=1からi=nまで
#define RREP(i,n)for(int i=n;i>=1;i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int N; cin >> N;
    vector<char> c(N);
    int cr = 0;
    int ans = 0;
    rep(i, N) {
        cin >> c[i];
        if (c[i] == 'R') {
            cr++;
        }
    }
    rep(i, cr) {
            if (c[i] == 'W') {
                ans++;
            }
        }
cout << ans << endl;
}



  

























Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
#define MOD 1000000007
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<lint, lint>;

// cout << fixed << setprecision(12)

lint modpow(lint a, lint n, lint m = MOD){
  lint ans = 1;
  while(n>0){
    if(n%2==1) ans *= a; 
    ans %= m;
    a *= a; 
    a %= m;
    n /= 2;
  }
  return ans;
}

lint inv(lint a, lint m = MOD){
  return modpow(a, m-2, m);
}

///////////////////////////////////

int main(){
  lint d,t,s; cin>>d>>t>>s;
  if(t*s>=d) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	string S;
	cin >> S;
	ll A=0, B=0, C=0;
	REP(i, S.size()){
		if(S[i]=='a') A++;
		if(S[i]=='b') B++;
		if(S[i]=='c') C++;
	}
	ll tmp = (S.size()-1)/3+1;
	if(A<=tmp&&B<=tmp&&C<=tmp){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  vector<int> hantei(4);
  for(int i =0;i<4;i++){
    for(int j=0;j<4;j++){
      if(S.at(i) ==S.at(j)){
        hantei.at(i) +=1;
      }
    }
  }
  bool kotae = true;
  for(int i=0;i<4;i++){
    if(hantei.at(i) !=2){
      kotae =false;
      break;
    }
  }
  if(kotae){
    cout<< "Yes"<<endl;
  }
  else{
    cout<< "No"<<endl;
  }
}

Measured memory_bytes: 256
#include<string.h>
 
 
int main(){
   
  char u[256][20], t[256][20];
  int n, m, i, j, cnt=0;
 
  scanf("%d", &n);
  for(i=0;i<n;i++) scanf("%s", u[i]);
  scanf("%d", &m);
  for(i=0;i<m;i++) scanf("%s", t[i]);
 
  for(i=0;i<m;i++){
    for(j=0;j<n;j++){
      if(strcmp(t[i],u[j])==0){
        if(cnt%2==0){
          printf("Opened by %s\n", t[i]);
          cnt++;
          break;
       }else{
          printf("Closed by %s\n", t[i]);
          cnt++;
          break;
       }
     }
      if(j==n-1) printf("Unknown %s\n", t[i]);
    }
  }
   
  return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int n;
  cin >> n;
  vi p(n);
  rep(i,n) cin >> p[i];
  int cnt=0;
  rep(i,n){
    if(p[i] != i+1) cnt++;
  }
  if(cnt == 0 || cnt == 2) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
def factors(n):
    res = {}
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            res[i] = 0
            while n % i == 0:
                res[i] += 1
                n //= i
    if n > 1: res[n] = 1
    return res

def sel2(f, a, b):
    g = [(k, v) for k, v in f.items() if v >= a]
    res = 0
    for ik, iv in g:
        for jk, jv in g:
            if ik == jk: continue
            if jv < b: continue
            res += 1
    return res

def sel3(f, a, b, c):
    g = [(k, v) for k, v in f.items() if v >= a]
    res = 0
    for ik, iv in g:
        for jk, jv in g:
            if ik == jk: continue
            if jv < b: continue
            for kk, kv in g:
                if kk in (ik, jk): continue
                if kk < jk: continue
                if kv < c: continue
                res += 1
    return res

n = int(input())
facs = {}
for i in range(2, n+1):
    tmp = factors(i)
    for k, v in tmp.items():
        if k in facs: facs[k] += v
        else: facs[k] = v

res = 0
res += sum(1 for k, v in facs.items() if v >= 74)
res += sel2(facs, 2, 24)
res += sel2(facs, 4, 14)
res += sel3(facs, 2, 4, 4)
print(res)

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

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];

    vector<ll> ra(n + 1), rb(m + 1);
    for (int i = 1; i <= n; i++)
        ra[i] = a[i - 1] + ra[i - 1];
    for (int i = 1; i <= m; i++)
        rb[i] = b[i - 1] + rb[i - 1];

    int ia = upper_bound(ra.begin(), ra.end(), k) - ra.begin() - 1;
    int ib = upper_bound(rb.begin(), rb.end(), k - ra[ia]) - rb.begin() - 1;

    int ans = ia + ib;
    ll sum = 0;

    for (int i = ia; i >= 0; i--) {
        sum += ra[i];

        ib = upper_bound(rb.begin(), rb.end(), k - ra[i]) - rb.begin() - 1;

        ans = max(ans, i + ib);
        sum -= ra[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8000
S = input()
if S == 'SUN':
    print('7')
elif S == 'MON':
    print('6')
elif S == 'TUE':
    print('5')
elif S == 'WED':
    print('4')
elif S == 'THU':
    print('3')
elif S == 'FRI':
    print('2')
elif S == 'SAT':
    print('1')
else:
    print('入力エラー')

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

int main() {
    int n;
    cin >> n;
    int card[n];
    for (int i = 0; i < n; i++) cin >> card[i];
    // sort
    sort(card, card + n, greater<int>());

    int alice = 0, bob = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) alice += card[i];
        else bob += card[i];
    }

    cout << alice - bob << endl;
    
} // namespace std;



Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)

//変数
vector<int> vec(3);

//解法
void solve() {

	sort(vec.begin(), vec.end(),greater<int>());

	int ans = 0;
	ans += (vec[1] - vec[2]) / 2;
	vec[2] += ans * 2;

	if (vec[1] != vec[2]) {
		ans++;
		vec[0]++;
		vec[2]++;
	}

	ans += vec[0] - vec[1];

	cout << ans;

	return;
}

int main() {
	//入力
	cin >> vec[0] >> vec[1] >> vec[2];
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] t = new int[N+1];
        t[0]= 0;
        int[] x = new int[N+1];
        x[0]= 0;
        int[] y = new int[N+1];
        x[0]= 0;
        
        for (int i = 1; i <= N; i++){
            t[i] = sc.nextInt();
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }

        for(int i = 0; i < N; i++){
            int abs_t = t[i + 1] - t[i];
            int abs_x = Math.abs(x[i + 1] - x[i]);
            int abs_y = Math.abs(y[i + 1] - y[i]);
            if(abs_t < abs_x + abs_y || abs_t % 2 != (abs_x + abs_y) % 2 ) {
                System.out.println("No");
                System.exit(0);
            } 
        }
        System.out.println("Yes");
    }
}

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

vector<int> x(101,0);
int n;

int cal(int p){
    int ans = 0;
    rep(i, n) ans+= (x[i] - p) * (x[i] - p);
    return ans;
}

int main(){
    cin >> n;
    int xsum = 0;
    rep(i, n){
        cin >> x.at(i);
        xsum += x[i];
    }
    int ans = 0;
    if(xsum%n==0){
        ans = cal(xsum/n);
    }
    else{
        ans = min(cal(xsum/n),cal(xsum/n +1));
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = float("inf")

for i in range(2**n):
    highest = a[0]
    color = 1
    money = 0
    for j in range(1,n):
        if a[j] > highest:
            color += 1
            highest = a[j]
        elif (i>>j)&1:
            color += 1
            highest = highest + 1
            money += highest - a[j]
        
    if color >= k:
        ans = min(ans,money)
print(ans)

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,k=map(int,input().split())
data=[]
A=list(map(int,input().split()))
for i in range(n):
    for j in range(i+1,n+1):
        data.append(sum(A[i:j]))
# print(sorted(data))
for exp in range(41,-1,-1):
    candi=[]
    count=0
    for i,di in enumerate(data):
        if di>>exp & 1:
            count+=1
            candi.append(di)
    if count >= k:
        data = candi
p=data[0]
for ci in data:
    p=p & ci
print(p)
# print(data)
# def test():
#     ans=inf
#     data=[]
#     for i in range(n):
#         for j in range(i+1,n+1):
#             data.append(sum(A[i:j]))
#     nd=len(data)
#     for i in range(nd-1):
#         for j in range(i+1,nd):
#             ans=max(ans,data[i] & data[j])
#     return ans
# if p!=test():
#     print(p,test())

Measured memory_bytes: 84700
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

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()
{
  string s;

  cin >> s;

if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2]){
    cout << "Yes";
    return 0;
    }
if(s[0] == s[2] && s[1] == s[3] && s[0] != s[1]){
    cout << "Yes";
    return 0;
    }
if(s[0] == s[3] && s[1] == s[2] && s[0] != s[1]){
    cout << "Yes";
    return 0;
    }
      cout << "No";
  return 0;
}


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

int main(){
  string s;
  cin>>s;
  
  if(s[0]=='S'){
         cout<<"Cloudy"<<endl;
  } else if(s[0]=='C'){
         cout<<"Rainy"<<endl;
  }else {
         cout<<"Sunny"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef struct node_t {
    int key;
    struct node_t *p;
    struct node_t *l;
    struct node_t *r;
} Node;

Node* nNode(int);
void print(Node *);
void inorder(Node *);
void preorder(Node *);
void insert(int, Node *);
Node* find(int, Node *);
void free_tree(Node *);


int main() {
    int i,n,k;
    char com[10];
    Node *tree_root;
    
    tree_root = nNode(0);
    
    scanf("%d",&n);
    
    for (i=0; i<n; i++) {
        scanf("%s",com);
        
        if(com[0] == 'p') print(tree_root->l);
        else {
            scanf("%d",&k);
            
            if(com[0] == 'i') insert(k, tree_root);
            else if(com[0] == 'f') {
                if(find(k, tree_root) != NULL) printf("yes\n");
                else printf("no\n");
            }
        }
    }
    
    free_tree(tree_root);
    
    return 0;
}


Node* nNode(int key) {
    Node *tmp;
    
    tmp = (Node *)malloc(sizeof(Node));
    if(tmp==NULL) exit(0);
    
    tmp->key = key;
    tmp->p = NULL;
    tmp->l = NULL;
    tmp->r = NULL;
    
    return tmp;
}


void print(Node *root) {
    inorder(root);
    printf("\n");
    
    preorder(root);
    printf("\n");
}


void inorder(Node *node) {
    if(node->l!=NULL) inorder(node->l);
    printf(" %d",node->key);
    if(node->r!=NULL) inorder(node->r);
}


void preorder(Node *node) {
    printf(" %d",node->key);
    if(node->l!=NULL) preorder(node->l);
    if(node->r!=NULL) preorder(node->r);
}


void insert(int k,Node *tree_root) {
    Node *x, *y, *z;
    
    z = nNode(k);
    y = tree_root;
    x = tree_root->l;
    
    while (x!=NULL) {
        y = x;
        if(z->key < x->key) x = x->l;
        else x = x->r;
    }
    
    z->p = y;
    
    if(y==tree_root || z->key<y->key) y->l = z;
    else y->r = z;
}


Node* find(int k,Node *tree_root) {
    Node *x;
    
    x = tree_root->l;
    
    while (x->key!=k) {
        if(x->key>k) {
            if(x->l==NULL) return NULL;
            x = x->l;
        }
        else {
            if(x->r==NULL) return NULL;
            x = x->r;
        }
    }
    
    return x;
}


void free_tree(Node *root) {
    if(root->l != NULL) free_tree(root->l);
    if(root->r != NULL) free_tree(root->r);
    free(root);
}

Measured memory_bytes: 19364
import numpy as np
from math import sqrt,factorial
N = int(input())
M = [0]*N
edge = np.zeros([N,N])
sum=0
for i in range(N):
    M[i] = list(map(int,input().split()))
for i in range(N):
    for k in range(i+1,N):
        edge[i,k] = sqrt((M[i][0]-M[k][0])**2 + (M[i][1]-M[k][1])**2)
        sum+=edge[i,k]
average = sum/N*2
print(average)

Measured memory_bytes: 12500
def gcd(n, m):
    if m == 0: return n
    return gcd(m , n%m)

def lcm(n, m): 
    g = gcd(n, m)
    return n * m // g

N, M = map(int, input().split())
A = list(map(int, input().split()))
res = 1
for a in A:
    res = lcm(res, a)

cnt = 0
while A[0] % 2 == 0:
    A[0] //= 2;
    cnt += 1

ok = True
for i in range(1, N):
    c = 0
    while A[i] % 2 == 0:
        A[i] //= 2;
        c+= 1
    if cnt != c :ok = False
    
if res // 2 > M or ok == False: print(0)
else: print((M + res//2 ) // res)



Measured memory_bytes: 14244
/* ANTHOR KUMAR DAS
KUET ECE 2K18*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sc(a) scanf("%d",&a)
#define sc1(n) scanf("%lld",&n)
#define sc2(b,c) scanf("%lld%lld",&b,&c)
#define f(a,b) for(a=0;a<b;a++)
#define pb(a) push_back(a)
#define br break
int main()
{
    int a,b;
    cin>>a>>b;
    if(a==0||b==0)
    {
        cout<<"-1"<<endl;
    }
    else if(a<=9&&b<=9)
    {
        cout<<a*b<<endl;
    }
    else{
        cout<<"-1"<<endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a, n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a  ,min(b, c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a, n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;

int32_t main()
{
    string s, t;
    cin>>s>>t;
    int n = s.length();
    int m = t.length();
    int dp[n+1][m+1];
    for(int i=0;i<m+1;i++)
    {
        dp[0][i] = 0;
    }
    for(int i=0;i<n+1;i++)
    {
        dp[i][0] = 0;
    }
    for(int i=1;i<n+1;i++)
    {
        for(int j=1;j<m+1;j++)
        {
            if(s[i-1] == t[j-1])
            {
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else
            {
                dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
            }
        }
    }
    int index = dp[n][m];
    char arr[index+1];
    arr[index] = '\0';
    int i = n, j = m;
    while(i>0 && j>0)
    {
        if(s[i-1] == t[j-1])
        {
            arr[index-1] = s[i-1];
            i--;
            j--;
            index--;
        }
        else
        {
            if(dp[i-1][j] > dp[i][j-1])
            {
                i--;
            }
            else
            {
                j--;
            }
        }
    }
    cout<<arr;
    return 0;
}


Measured memory_bytes: 70656
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    N = II()
    A = LI()
    sma = 0

    for i in range(1, N, 2):
        sma += A[i]
    ans = [-1] * N
    ans[0] = sum(A) - 2 * sma

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


if __name__ == '__main__':
    solve()


Measured memory_bytes: 14400
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("atcoder-problems/sumitb2019_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

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

  cout << (a == c ? 0 : 1) << endl;
}

Measured memory_bytes: 3648
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
ans=0
count=10000000000
for j in range(n):
    if abs((t-0.006*h[j])-a)<count:
        count=abs((t-0.006*h[j])-a)
        ans=j
print(ans+1)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

#ifdef LOCAL
  #define debug_echo(expr) cout << expr << "\n";
#else
  #define debug_echo(expr)
#endif

using namespace std;

#define at ,<=,
#define to ,<,
#define in ,
#define forrange(...)  forrange1(forrange2, (__VA_ARGS__))
#define forrange1(X, A) X A
#define forrange2(i, s, op, e) for (int i = (s); i op (e); i++)

int main() {
  int n;
  cin >> n;
  vector<int> as(n);
  forrange (i in 0 to n) {
    cin >> as[i];
  }

  int start;
  if (n % 2 == 0) {
    start = 0;
  } else {
    start = 1;
  }

  vector<int> bs;
  for (int i = n-1; i >= 0; i -= 2) {
    bs.push_back(as[i]);
  }
  for (int i = start; i < n; i += 2) {
    bs.push_back(as[i]);
  }

  string s;
  s += to_string(bs[0]);
  forrange (i in 1 to n) {
    s += " ";
    s += to_string(bs[i]);
  }
  cout << s << endl;
}


Measured memory_bytes: 5752
#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

typedef	vector<int>	vi;
typedef	vector<vi>	vvi;

bool cmp(const vi &va,const vi &vb){ return va.size()<vb.size(); }

vvi pile;

void findPos(int id,int &p,int &h){
	rep(i,pile.size())rep(j,pile[i].size()){
		if(pile[i][j]==id){ p=i,h=j; return; }
	}
}

int main(){
	for(int m;scanf("%d",&m),m;){
		pile=vvi(m);
		rep(i,m)	pile[i].pb(i+1);

		for(int pck,put;scanf("%d%d",&pck,&put),pck||put;){
			if(pck==put)	continue;

			int pckp,pckh;	findPos(pck,pckp,pckh);
			int putp,puth;	findPos(put,putp,puth);

			if(put==0){
				if(pckh>0){
					while(1){
						int cube=pile[pckp].back();
						pile[pckp].pop_back();
						pile.pb(vi(1,cube));
						if(cube==pck)	break;
					}
				}
			}
			else{
				if(pckp!=putp || (pckp==putp && pckh<puth)){
					while(1){
						int cube=pile[pckp].back();
						pile[pckp].pop_back();
						if(cube==pck)	break;
						pile.pb(vi(1,cube));
					}
					findPos(put,putp,puth);
					pile[putp].pb(pck);
				}
			}
		}

		sort(pile.begin(),pile.end(),cmp);

		rep(i,pile.size()) if(pile[i].size()>0) printf("%d\n",pile[i].size());
		puts("end");
	}

	return 0;
}

Measured memory_bytes: 0
import Control.Monad
import Data.List

solveSub [] ts [] = True
solveSub (bs:bss) ts (p:ps)
    | mod (sum (zipWith (*) bs ts)) 2 == p = solveSub bss ts ps
    | otherwise = False

solve bss [] ps = 0
solve bss (ts:tss) ps
    | solveSub bss ts ps = 1 + solve bss tss ps
    | otherwise = solve bss tss ps

main = do
    [n,m] <- map read . words <$> getLine :: IO [Int]
    kss <- replicateM m (sort.tail.map read . words <$> getLine) :: IO [[Int]]
    ps <- map read . words <$> getLine :: IO [Int]
    let bss = map (\ks -> map (\x-> if elem x ks then 1 else 0 ) [1..n]) kss
    let tss = replicateM n [0,1]
    print $ solve bss tss ps


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

#define M 1046527/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

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

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return /* your task */key % M; }
int h2(int key){ return /* your task */1 + (key % (M - 1)); }

int find(char str[]){

    /* your task */

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

  return 0;
}

int insert(char str[]){

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

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

    return 0;
}


Measured memory_bytes: 16048
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e2 + 10;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	vector<int> v;
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = 0; i < k && a + i <= b - i; i++)
	{
		v.push_back(a + i);
		if (a + i != b - i)v.push_back(b - i);
	}
	sort(v.begin(), v.end());
	for (auto& x : v)
		printf("%d\n", x);
	return 0;
}


Measured memory_bytes: 256