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

public class Main {
	final static char BOMB = '#';
	final static char EMPTY = '.';
	final static int MAX_H = 50;
	final static int MAX_W = 50;
	static char[][] grid = new char[MAX_H + 2][MAX_W + 2];
	final static int[] DR = {-1, -1, -1, 0, 0, 1, 1, 1};
	final static int[] DC = {-1,  0,  1,-1, 1,-1, 0, 1};

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

		while(input.hasNext()){
			int H = input.nextInt();
			int W = input.nextInt();		
			
			for(int i = 1; i <= H; ++i){
				System.arraycopy(input.next().toCharArray(), 0, grid[i], 1, W);
			}
			
			for(int i = 1; i <= H; ++i){
				for(int j = 1; j <= W; ++j){
					
					if(grid[i][j] == EMPTY){
						int bombNum = 0;
						for(int d = 0; d < DR.length; ++d){
							if(grid[i + DR[d]][j + DC[d]] == BOMB){
								++bombNum;
							}
						}
						
						grid[i][j] = (char) (bombNum + '0');
					}
				}
			}
			
			for(int i = 1; i <= H; ++i){
				System.out.println(new String(grid[i], 1, W));
			}
		}
	}

}


Measured memory_bytes: 22868
import sys

readline = sys.stdin.readline

def main():
    n, m = map(int, readline().split())
    c = list(map(int, readline().split()))

    maxnum = 50001
    DP = [maxnum] * (n+1)
    DP[0] = 0
    for ctmp in c:
        for j in range(ctmp, n+1):
            if DP[j-ctmp] == maxnum:
                continue
            else:
                DP[j] = min(DP[j], DP[j-ctmp] + 1)
    
    ans = DP[n]
    print(ans)


if __name__ == "__main__":
    main()



Measured memory_bytes: 7520
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

struct UnionFind {
    vector <int> par;

    UnionFind(int n) : par(n) {
        for(int i = 0; i < n; i++) par[i] = i;
    }

    int root (int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite (int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same (int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int n, m; cin >> n >> m;
    UnionFind tree(n);
    for (int i = 0; i < m; i++)
    {
        int x, y, z; cin >> x >> y >> z;
        x--; y--;
        tree.unite(x, y);
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (i == tree.root(i)) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(((a==b) && b!=c) || ((a==c) && a!=b) || ((b==c) && b!=a))
    {
     cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
    return 0;


}


Measured memory_bytes: 256
a, b = map(int, input().split())
ans = 1
if abs(a - b) <= 1:
    for i in range(1, a + 1):
        ans = (ans * i) % (10**9+7)
    for i in range(1, b + 1):
        ans = (ans * i) % (10**9+7)
    if a == b:
        print(ans * 2 % (10**9+7))
    else:
        print(ans)
else:
    print(0)


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

int main() {
  int h,w;
  cin>>h>>w;
  
  vector<vector <char>> s(h,vector<char>(w));
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>s.at(i).at(j);
      cout<<s.at(i).at(j);
    }
    cout<<endl;
    for(int j=0;j<w;j++){
      cout<<s.at(i).at(j);
    }
    cout<<endl;
  }
  
  
  
}


Measured memory_bytes: 256
// 2014/07/07 Tazoe

#include <iostream>
using namespace std;

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

		if(n==0)
			break;

		int h[101];
		for(int i=0; i<n+1; i++){
			cin >> h[i];
		}

		for(int i=0; i<n+1; i++){
			int tmp[100];
			for(int j=0; j<i; j++){
				tmp[j] = h[j];
			}
			for(int j=i+1; j<n+1; j++){
				tmp[j-1] = h[j];
			}

			bool flg = true;

			int d = tmp[1]-tmp[0];
			for(int j=1; j<n-1; j++){
				if(tmp[j+1]-tmp[j]!=d){
					flg = false;
					break;
				}
			}

			if(flg){
				cout << h[i] << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1160
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    auto K = nk[1];

    auto AS = readln.split.to!(int[]);
    sort!"a > b"(AS);
    auto x = AS[0];
    foreach (a; AS[1..$]) x = gcd(x, a);

    if (K > AS[0] || K%x != 0) {
        writeln("IMPOSSIBLE");
    } else {
        writeln("POSSIBLE");
    }
}

Measured memory_bytes: 3964
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

/*
  K=101000
  101000
  100111
  011111
*/

int main(){
  ll N, K; cin >> N >> K;
  vector<pair<ll,ll>> AB(N);
  rep(i,N){
    cin >> AB[i].first >> AB[i].second;
  }
  ll ans = 0;
  //cout << bitset<30> (K) << endl;
  ll K_ = K;
  ll tmp = 0;
  ll preans = 0;
  rep(i,N){
    if(((tmp | AB[i].first)|K_) <= K_){
      tmp |= AB[i].first;
      preans += AB[i].second;
    }
  }
  ans = preans;
  for(int i=0;i<=31;i++){
    K_ = K;
    K_ >>= i;
    K_ <<= i;
    K_ = max(K_-1, (ll)0);
    if(K_ > K) continue;
    //cout << bitset<30> (K_) << endl;
    preans = tmp = 0;
    rep(i,N){
      if(((tmp | AB[i].first)|K_) <= K_){
        tmp |= AB[i].first;
        preans += AB[i].second;
      }
    }
    ans = max(ans, preans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define ifYN(x) cout<<(x?"APPROVED":"DENIED")<<"\n"
using namespace std;
//-------------------------------------------

int main(void){
  ll a,b;cin>>a>>b;
  cout<<6-a-b;
  return 0;
}


Measured memory_bytes: 256
from sys import exit 
N,Y = map(int,input().split())

for i in range(N+1):
    for j in range(N-i+1):
        Sum = 10000*i + 5000*j + 1000*(N-i-j)
        if Sum == Y:
            print(str(i)+' '+str(j)+' '+str(N-i-j))
            exit(0)

print(str(-1)+' '+str(-1)+' '+str(-1))


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

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

    cout << a*b/2 << endl;
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    a = LI()
    s = sum(a)
    r = abs((s - a[0]) - a[0])
    t = a[0]
    for i in range(1,n-1):
        t += a[i]
        tr = abs((s - t) - t)
        if tr < r:
            r = tr

    return r


print(main())





Measured memory_bytes: 26192
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n, m;
    string s;
    cin >> n >> m >> s;
    queue<int> que;
    vector<int> pre(n + 1);
    rep(i, n + 1)
    {
        if (s[i] == '0')
            que.push(i);
        if (que.size() == 0)
        {
            cout << -1 << endl;
            return 0;
        }
        int pos = que.front();
        int len = i - pos;
        while (len > m)
        {
            if (que.size() == 0)
            {
                cout << -1 << endl;
                return 0;
            }
            que.pop();
            pos = que.front();
            len = i - pos;
        }
        pre[i] = pos;
    }
    vector<int> ans;
    int now = n;
    while (now > 0)
    {
        int nxt = pre[now];
        ans.push_back(now - nxt);
        if (now == nxt)
        {
            cout << -1 << endl;
            return 0;
        }
        now = nxt;
    }
    reverse(all(ans));
    rep(i, ans.size()) cout << ans[i] << " ";
    cout << endl;
}

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

int main() {
  int A,B,i,N,ans;
  cin >> A >> B;
  i = 0;
  N = B-A+1;
  
  while(i<N){
    int a,b,c,d,e;
    a = A%10;
    b = (A/10)%10;
    c = ((A/10)/10)%10;
    d = (((A/10)/10)/10)%10;
    e = ((((A/10)/10)/10)/10)%10;
    
    if(a==e && b==d){
      ans ++;
    }
    
    A++;
    i++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  char r, g;
  cin >> r >> g;

  if(r > g)
  	cout << ">" << endl;
  else if(r == g)
  	cout << "=" << endl;
  else
  	cout << "<" << endl;
  
  return 0;
}



Measured memory_bytes: 256
h, n = map(int, input().split())

ab_list = [0]*n

for i in range(n):
    ab_list[i] = list(map(int, input().split()))

ma_list = [0]*h

for i in range(h):
    ma_list[i] = 10000000000
    for item in ab_list:
        ma = 0
        if item[0] >= (i + 1):
            ma = item[1]
        else:
            ma = item[1] + ma_list[i - item[0]]
        if ma_list[i] > ma:
            ma_list[i] = ma

print(ma_list[-1])


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

const int inf = 1e9;
const ll linf = 1e18;

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

template <typename T>
class SegTree
{
private:
    using F = function<T(const T&, const T&)>;

    int n;          // 要素数
    vector<T> data; // データを格納する配列
    T unity;        // 単位元
    F opr;          // クエリ処理の関数
    F upd;          // 点更新の関数

    // [a, b)の区間クエリ
    T _query(int a, int b, int k, int l, int r) {
        // [a, b)と[l, r)が交差しないとき
        if (r <= a || b <= l) return unity;

        // [l, r)が[a, b)に完全に含まれているとき
        if (a <= l && r <= b) {
            return data[k];
        } else {
            // そうでなければ、子ノードのoprを返す
            T v1 = _query(a, b, 2*k+1, l, (l+r)/2);
            T v2 = _query(a, b, 2*k+2, (l+r)/2, r);
            return opr(v1, v2);
        }
    }

public:
    SegTree(const int n_, const T unity_, const F opr_, const F upd_) : 
        n(1 << __lg(2*n_-1)), data(2*n-1, unity_), unity(unity_), opr(opr_), upd(upd_) {}
    
    T query(int a, int b) { return _query(a, b, 0, 0, n); }

    // k番目の値をxで更新
    void update(int k, T x) {
        k += n - 1; // 葉の節点に変換
        data[k] = upd(data[k], x);
        // 各節点を更新
        while (k > 0) {
            k = (k - 1) / 2;
            data[k] = opr(data[2*k+1], data[2*k+2]);
        }
    }

    T operator[](size_t i) {
        return data[i + n - 1];
    }
};

template <typename T>
class RMQ : public SegTree<T>
{
public:
    RMQ(int n, T init = numeric_limits<T>::max()) : SegTree<T> (
        n, init,
        [](T a, T b) { return min(a, b); },
        [](T a, T b) { return b; }
    ) {}
};

template <typename T>
class RSQ : public SegTree<T>
{
public:
    RSQ(int n, T init = static_cast<T>(0)) : SegTree<T> (
        n, init,
        [](T a, T b) { return a + b; },
        [](T a, T b) { return a + b; }
    ) {}
};

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

    int n; cin >> n;
    SegTree<int> seg(
        n, 0, 
        [](int a, int b) {return gcd(a, b);},
        [](int a, int b) {return b;}
    );

    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        seg.update(i, a);
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int left = seg.query(0, i);
        int right = seg.query(i + 1, n);
        ans = max(ans, gcd(left, right));
    }

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

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    string a;
    cin >> a;
    bool big = regex_match(a, regex("[A-Z]"));
    cout << (big?"A":"a") << endl; // Yes
}


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

int main() {

	long long X;
	cin >> X;

	long long A = 0;
	long long B = 0;
	for (long long i = 1; i <= 1000; i++) {
		for (long long j = -1000; j <= i; j++) {
			if (X == (i * i * i * i * i - j * j * j * j * j)) {
				A = i;
				B = j;
				break;
			}
		}
	}

	cout << A << " " << B << endl;

	return 0;
}

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

using namespace std;
#define dtype long long

int main() {

    dtype n, x, y;
    cin >> n;
    string str,fi="111";
    while (n--){
        cin >> x >> y;
        if (x == y)
            str += '1';
        else
            str += '0';
    }

    if(str.find(fi)!=string::npos)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

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

#define mod 1000000007;
int main(){
	int r,c;
	cin >> r >> c;
	char a[r][c];
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			cin >> a[i][j]; 
		}
	}
	int dp[r][c];
	memset(dp,0,sizeof(dp));
	for(int i=1;i<r;i++){
		dp[i][0] = 1;
		if(a[i][0]=='#'){
			dp[i][0] = 0;
			break;
		}
	}
	for(int i=1;i<c;i++){
		dp[0][i] = 1;
		if(a[0][i]=='#'){
			dp[0][i] = 0;
			break;
		}
	}
	for(int i=1;i<r;i++){
		for(int j=1;j<c;j++){
			if(a[i][j]=='#'){
				dp[i][j]=0;
			}
			else{
				dp[i][j] = (dp[i-1][j]+dp[i][j-1])%mod ;
			}
		}
	}
	/*for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			cout << dp[i][j] << " "; 
		}
		cout << "\n";
	}*/
	cout << dp[r-1][c-1];
}

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;


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

	string s;
	cin >> s;
	
	int n = sz(s);
	
	int l = 0 , r = n - 1;
	int ans = 0;
	while(r > l){
		if(s[l] == s[r]){
			++l;
			--r;
		}else if(s[l] == 'x' && s[r] != 'x'){
			++ans;
			++l;
		}else if(s[r] == 'x' && s[l] != 'x'){
			++ans;
			--r;
		}else{
			dier(-1);
		}
	}
	die(ans);

	return 0;
}

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

int amt(int h[],int dp[],int i,int N){
	
	if(i>=N){
		return 0;
	}
	
	if(dp[i]!=-1){
		return dp[i];
	}
	else{
		return dp[i] = min( abs(h[i+1] - h[i])  + amt(h,dp,i+1,N) , abs(h[i+2] - h[i]) + amt(h,dp,i+2,N)) ;
	}
	
}


int main(){
  
	int n,x;
	cin>>n;
	int h[n+1];
	
	for(int i=1;i<=n;i++){
		cin>>h[i];
		
	}
	
	int dp[n+1];
	for(int i=0;i<n+1;i++){
		dp[i] = -1;
	}
	
	cout<<amt(h,dp,1,n);

}

Measured memory_bytes: 8212
#include<bits/stdc++.h>
using namespace std;
int d(int n){
	int ans = 0;
  	do{
    	ans+=n%10;
    }while(n/=10);
  	return ans;
}
int main(){
	int n;cin>>n;
  	int mn = 100000000;
  	for(int i=1;i<n;i++){
    	mn = min(mn,d(i)+d(n-i));
    }
  	cout<<mn;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;
#define PI  3.14159265358979323846

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll N, M, Q;
ll ans = 0;
vector<ll>a, b, c, d;

void dfs(vector<ll> A) {
    if (A.size()==N) {
        ll tmpMax = 0;
        rep(i,Q) {
            if (A[b[i]-1] - A[a[i]-1] == c[i])tmpMax += d[i];
        }
        ans = max(ans,tmpMax);
        return;
    }
    A.push_back(A.back());
    while (A.back()<=M) {
        dfs(A);
        A.back()++;
    }
}

int main() {
    cin >> N >> M >> Q;
    a = b = c = d = vector<ll>(Q);
    rep(i,Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(vector<ll>(1,1));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
n = int(input()) 
TXY = [[0,0,0]] + [list(map(int, input().split())) for _ in range(n)]
diff = [[t2 - t1, abs(x2 - x1), abs(y2 - y1)] for (t1, x1, y1), (t2, x2, y2) in zip(TXY, TXY[1:])]
for t, x, y in diff:
  if x + y > t or (t - (x + y)) % 2 == 1:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 37260
#include<bits/stdc++.h>
using namespace std;
int arr[2*100000+5];
long long Abs(long long a,long long b)
{
	if(a>b)
		return a-b;
	else
		return b-a;
}
int main()
{
	int t;
	long long m,s=0,s1=0,s2=0,mins=2*1e15;
	cin>>t;
	for(int i=0;i<t;i++)
	{
		scanf("%d",&arr[i]);
		s+=arr[i];
	}
	for(int i=0;i<t-1;i++)
	{
		s1+=arr[i];
		s2=s-s1;
		if(mins>Abs(s1,s2))
			mins=Abs(s1,s2);
		if(mins==0)
			break;
	}
	cout<<mins<<endl;
	return 0;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	count := 0
	for n := a; n <= b; n++ {
		if c%n == 0 {
			count++
		}
	}

	fmt.Println(count)
}



Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define int long long int
const int INF = 1000000007;
using namespace std;
void solve() {
    int n;
    cin >> n;
    int a[n];
    int sum = 0;
    for(int i=0;i<n;i++) {
        cin >> a[i];
        sum += a[i];
    }   
    int temp[n];
    int ans[n];
    int sum1 = 0, sum2 = 0;
    for(int i=0;i<n;i++)
        temp[i] = a[i]*2;
    for(int i=0;i<n;i++) {
        if(i%2 == 0 && i != n-1)
            sum1 += temp[i];
        else if(i%2 != 0)
            sum2 += temp[i];
    }
    ans[n-1] = sum - sum1;
    ans[0] = sum - sum2;
    //cout << ans[0] << " " << ans[n-1] << '\n';
    for(int i=1;i<n-1;i++) {
        ans[i] = temp[i-1] - ans[i-1];
    }
    for(int i=0;i<n;i++)
        cout << ans[i] << " ";
    cout << '\n';
    return ;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define ll long long
#define INF (1LL << 60)
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 2005;

template<typename V> class BIT {
private:
	int n; vector<V> bit;
public:
	void add(int i,V x){ i++; while(i < n) bit[i] += x, i += i & -i;}
	V sum(int i){ i++; V s = 0; while(i>0) s += bit[i], i -= i & -i; return s;} //0_indexedで[0,i]の要素の和
	BIT(){} BIT(int sz){ n = sz + 1, bit.resize(n,0);} //初期値がすべて0の場合
	BIT(vector<V>& v){ n = (int)v.size()+1; bit.resize(n, 0); rep(i,n-1) add(i,v[i]);}
	void print(){ rep(i,n-1)cout<<sum(i)-sum(i-1)<< " ";cout<<endl;}
	void print_sum(){ rep(i,n)cout<<sum(i-1)<<" ";cout<<endl;}	//-1スタート
};

ll dp[2*MAX_N][MAX_N];
int p[MAX_N][MAX_N], q[MAX_N][MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    rep(i,2*n){
        string s;
        int x;
        cin >> s >> x;
        if(s == "W"){
            a[x-1] = i;
        }else{
            b[x-1] = i;
        }
    }
    BIT<int> bta(2*n);
    rep(i,n+1){
        BIT<int> btb(2*n);
        rep(j,n+1){
            q[i][j] = b[j] - bta.sum(b[j]) - btb.sum(b[j]);
            btb.add(b[j],1);
        }
        bta.add(a[i],1);
    }
    BIT<int> btd(2*n);
    rep(j,n+1){
        BIT<int> btc(2*n);
        rep(i,n+1){
            p[i][j] = a[i] - btc.sum(a[i]) - btd.sum(a[i]);
            btc.add(a[i],1);
        }
        btd.add(b[j],1);
    }
    rep(i,2*n+1){
        rep(j,n+1){
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    rep(i,2*n){
        rep(j,n+1){
            cmn(dp[i+1][j], dp[i][j]+q[j][i-j]);
            if(j < n){
                cmn(dp[i+1][j+1], dp[i][j]+p[j][i-j]);
            }
        }
    }
    cout << dp[2*n][n] << "\n";
    return 0;
}


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

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

    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    
    sort(a, a+3);
    
    int d = a[1] - a[0];
    
    cout << d/2 + d%2 + a[2] - a[1] + d%2 << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"

	"strconv"
	"strings"
)

//  長い入力を読む
func ReadLongLines(times int) ([]string, error) {
	result := make([]string, times)
	reader := bufio.NewReader(os.Stdin)
	buffer := bytes.NewBuffer(make([]byte, 0))
	readBytes := int64(2)
	for i := 0; i < times; i++ {
		for {
			readBuf, isPrefix, err := reader.ReadLine()
			// fmt.Printf("Reader.Read: %d\n", len(readBuf))
			readBytes += int64(len(readBuf) + 1)
			if err != nil {
				if err == io.EOF {
					fmt.Println("EOF")
					break
				} else {
					return result, err
				}
			}
			_, err = buffer.Write(readBuf)
			if err != nil {
				return result, err
			}
			// end of line
			if !isPrefix {
				result[i] = buffer.String()
				buffer.Reset()
				// reader = bufio.NewReader(os.Stdin)
				break
			}
		}
	}
	// 先読みしてしまうようなので、戻しておく
	os.Stdin.Seek(-int64(reader.Buffered()), os.SEEK_CUR)
	return result, nil
}

// 出力 for 競プロ
type Console struct {
	writer *bufio.Writer
}

func NewConsole() Console {
	return Console{bufio.NewWriter(os.Stdout)}
}
func (this *Console) Printf(format string, a ...interface{}) {
	fmt.Fprintf(this.writer, format, a...)
}
func (this *Console) Println(s string) {
	fmt.Fprintln(this.writer, s)
}
func (this *Console) Close() {
	this.Flush()
}
func (this Console) Flush() {
	this.writer.Flush()
}

func PrintList(list []int) {
	con := NewConsole()
	defer con.Flush()
	for i := range list {
		if i == 0 {
			con.Printf("%d", list[i])
		} else {
			con.Printf(" %d", list[i])
		}
	}
	con.Println("")
}

func Insert(m *map[string]int, key string, val int) {
	(*m)[key] = val
}
func Get(m *map[string]int, key string) int {
	return (*m)[key]
}
func main() {
	con := NewConsole()
	defer con.Flush()

	// create list
	var n int
	fmt.Scanf("%d", &n)

	m := make(map[string]int)
	lines, _ := ReadLongLines(n)
	for i := range lines {
		args := strings.Split(lines[i], " ")
		command, _ := strconv.Atoi(args[0])

		switch command {
		case 0: //insert
			k := args[1]
			v, _ := strconv.Atoi(args[2])
			Insert(&m, k, v)
		case 1: //get
			k := args[1]
			v := Get(&m, k)
			con.Printf("%d\n", v)
			// case 2: // delete
			// 	set.Remove(x)
			// case 3: // dump
			// 	l, _ := strconv.Atoi(args[1])
			// 	r, _ := strconv.Atoi(args[2])
			// 	result := set.Dump(l, r)
			// 	for i := range result {
			// 		con.Printf("%d\n", result[i])
			// 	}
		}

	}
}



Measured memory_bytes: 29788
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
typedef long long int ll;
using namespace std;

int main()
{
    ll n,k;
    cin>>n>>k;

    if(n%k==0 || n==k)
    {
        cout<<0<<endl;
        return 0;
    }

    if(n>k)
    {
        n=n-(n/k)*k;
    }

    while(n>abs(n-k))
        n=abs(n-k);

    cout<<n<<endl;

    return 0;
}



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

const int INF = 2e9;

int main(){
    int x,y;
    cin >> x >> y;
    rep(i,x+1){
        if((i*2 + (x-i)*4) == y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3632
N, M, X, Y = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
ifwar = 1
for i in (X+1)..Y
  ok = 1
  a.each do |ax|
    if ax >= i
      ok = 0
      break
    end
  end
  if ok == 1
    b.each do |by|
      if by < i
        ok = 0
        break
      end
    end
  end
  if ok == 1
    ifwar = 0
    break
  end
end
if ifwar == 0
  puts "No War"
else
  puts "War"
end

Measured memory_bytes: 1788
if __name__ == '__main__':
    time_in_second = int(input())

    hour = time_in_second // 3600
    minute = (time_in_second % 3600) // 60
    second = time_in_second % 60

    print('{0:d}:{1:d}:{2:d}'.format(hour, minute, second))

Measured memory_bytes: 7636
#include <bits/stdc++.h>
using namespace std;
#define finish(x) reutrn cout << x << endl, 0;
#define ll long long

int n, x;
ll dp[3001][3001][2];
vector <int> a;

ll solve(int l, int r, int cur){
    if(r < l) return 0;
    ll &ret = dp[l][r][cur];
    if(ret != -1) return ret;
    if(cur == 0) return ret = max(solve(l + 1, r, cur ^ 1) + a[l], solve(l, r - 1, cur ^ 1) + a[r]);
    return ret = min(solve(l + 1, r, cur ^ 1) - a[l], solve(l, r - 1, cur ^ 1) - a[r]);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    memset(dp, -1, sizeof dp);
    cin >> n;
    for(int i = 0 ; i < n && cin >> x ; i++)
        a.push_back(x);
    cout << solve(0, n - 1, 0) << endl;
}


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

using namespace std;

#define endl '\n'
#define ll long long

const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 5;
const double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078;

//iostream::sync_with_stdio(false);

int main()
{
    double r;
    cin >> r;
    printf("%.4lf",2.00*r*pi);
    return 0;
}



Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int N;
ll X[1000], Y[1000];

int main() {
	cin >> N;
	REP(i, N) scanf("%lld %lld", X + i, Y + i);
	
	bool par = X[0] + Y[0] & 1;
	
	vector<ll> cx(N), cy(N);
	REP(i, N) {
		if (par ^ X[i] + Y[i] & 1) {
			puts("-1");
			return 0;
		}
		if (!par) --X[i];
		cx[i] = X[i] - Y[i];
		cy[i] = X[i] + Y[i];
	}
	
	vector<ll> d;
	REP(i, 32) d.push_back(1ll<<i);
	ll S = accumulate(ALL(d), 0ll);
	
	vector<vector<bool> > fx(N, vector<bool>(d.size())), fy(N, vector<bool>(d.size()));
	REP(i, N) {
		ll x = cx[i] + S, y = cy[i] + S;
		FOR(j, 1, 33) {
			if (x >> j & 1) fx[i][j - 1] = 1;
			if (y >> j & 1) fy[i][j - 1] = 1;
		}
		
		if (!par) {
			fx[i].push_back(1);
			fy[i].push_back(1);
		}
	}
	if (!par) d.push_back(1);
	
	vector<string> ans;
	REP(i, N) {
		string cur;
		REP(j, d.size()) {
			string dat = "LUDR";
			cur += dat[fx[i][j] * 2 + fy[i][j]];
		}
		ans.push_back(cur);
	}
	
	cout << d.size() << endl;
	REP(i, d.size()) printf("%lld%c", d[i], i == d.size() - 1 ? '\n' : ' ');
	REP(i, N) cout << ans[i] << endl;
	
	if (debug) {
		if (!par) REP(i, N) ++X[i];
		REP(i, N) {
			ll x = 0, y = 0;
			REP(j, ans[i].size()) {
				switch (ans[i][j]) {
					case 'L': x -= d[j]; break;
					case 'R': x += d[j]; break;
					case 'U': y += d[j]; break;
					case 'D': y -= d[j]; break;
				}
			}
			printf("X:%lld x: %lld, Y:%lld, y:%lld\n", X[i], x, Y[i], y);
		}
	}
	
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	int pos = 0;
	string s1,s2;
	cin>>s1>>s2;
	int ans = 1;
	int prv = -1;
	for(int i=0;i<n;i++){
		if( i == 0 && s1[i] == s2[i] ){
			ans *= 3;
			prv = 1;
		}
		else if( i == 0 && s1[i] != s2[i] ){
			ans *= 6;
			prv = 2;
		}
		else if( s1[i] == s2[i] ){
			ans *= ( 3-prv );
			prv = 1;
		}
		else{
			if( prv == 2 ){
				ans *= 3;
			}
			else{
				ans *= 2;
			}
			prv = 2;
		}
		ans %= inf;
		if( prv == 2 )i++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
s = int(input())
X = [s]
m = 1
while True:
    m += 1
    if s % 2 == 0:
        s = s / 2
    else:
        s = 3 * s + 1
    
    Y = [s]
    if len(set(X) & set(Y)) == 1:
        break
    X.append(s)

print(m)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    
    string str = "";
    
    string r = "No";
    
    cin >> str;
    
    
    if(str.at(2) == str.at(3) && str.at(4) == str.at(5)) {
        r = "Yes";
    }
    
    cout << r << endl;
}

Measured memory_bytes: 256
n,c = map(int,input().split())
d = [list(map(int,input().split())) for _ in range(c)]

a = [[0]*c for _ in range(3)]
b = [[[0,i] for i in range(c)] for _ in range(3)]

for i in range(n):
  l = list(map(int,input().split()))
  for j in range(n):
    a[(i+j)%3][l[j]-1] += 1
    
for i in range(3):
  for k in range(c):
    b[i][k][0] = sum([a[i][t]*d[t][k] for t in range(c)])
p = [[],[],[]]
for i in range(3):
  p[i] = sorted(b[i])[:3]
m = []
for t in p[0]:
  for s in p[1]:
    for u in p[2]:
      if (t[1] != s[1]) and (t[1] != u[1]) and (s[1] != u[1]):
        m.append(t[0]+s[0]+u[0])
print(min(m))

Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int n, k;
  while(cin >> n, n) {
    cin >> k;
    set<string> SET;
    vector<string> vs(n); FOR(i,0,n) cin >> vs[i];
    FOR(i,0,1<<n) {
      vector<int> v;
      int cnt = 0;
      FOR(j,0,n) {
        if((i>>j)&1) {
          cnt++;
          v.push_back(j);
        }
      }
      if(cnt != k) continue;
      do {
        string s = "";
        FOR(l,0,k) s = s + vs[v[l]];
        SET.insert(s);
      } while(next_permutation(v.begin(), v.end()));
    }
    cout << SET.size() << endl;
  } 
  
  return 0;
}

Measured memory_bytes: 3388
#include <bits/stdc++.h>
using namespace std;
int arr[100005];
vector<int> edgeList[100005];
bool visited[100005];
set<int> contain[100005];
int parent[100005];
void DFS(int idx,int pp)
{
    if(visited[idx])
        return;
    parent[idx] = pp;
    contain[pp].insert(arr[idx]);
    visited[idx] = true;
    for(int i = 0;i < edgeList[idx].size();i++)
        DFS(edgeList[idx][i],pp);
}
int main()
{
    int n,m;
    cin >> n >> m;
    for(int i = 1;i <= n;i++)
        scanf("%d",&arr[i]);
    for(int i = 1;i <= m;i++)
    {
        int u,v;
        scanf("%d %d",&u,&v);
        edgeList[u].push_back(v);
        edgeList[v].push_back(u);
    }
    for(int i = 1;i <= n;i++)
    {
        if(visited[i])
            continue;
        parent[i] = i;
        DFS(i,i);
    }
    int ans = 0;
    for(int i = 1;i <= n;i++)
    {
        if(contain[parent[i]].find(i) != contain[parent[i]].end())
            ans++;
    }
    cout << ans;
}


Measured memory_bytes: 19968
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;

int main() {
    int N, a, b, c, d;
    cin >> N;
    
    a = N/1000;
    b = (N%1000)/100;
    c = (N%100)/10;
    d = (N%10);
    
    int x, y, z;
    rep(i,2){
        rep(j,2){
            rep(k,2){
                x = i==0 ? b : -b;
                y = j==0 ? c : -c;
                z = k==0 ? d : -d;
                
                if((a+x+y+z)==7) {
                    printf("%d%s%d%s%d%s%d=7\n", a, i==0?"+":"-", b, j==0?"+":"-",c, k==0?"+":"-", d);
                    return 0;
                }
            }
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
    char a[3][2];
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 2; j++ ){
            cin >> a[i][j];
        }
    }

    bool jud = false ;
    if(a[1][0]==a[1][1]){
        if(a[0][0]==a[2][1]){
            if(a[0][1]==a[2][0]){
                jud =true;
            }
        }
    }

    if(jud==true){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

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

n, m = map(int, input().split())
pairs = []
for _ in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    pairs.append((a, b))

pairs.sort(key=lambda x: x[1])  # 右端の値でソート
current_right = 0
ans = 0
for (l, r) in pairs:
    if l >= current_right:
        current_right = r
        ans += 1
print(ans)


Measured memory_bytes: 52060
s = input()
n1 = int(len(s)/2)
n2 =  int(n1/2)
t1 = s[:n1]
t2 = s[::-1][:n1]
if t1 == t2 and t1[:n2] == t1[::-1][:n2] and t2[:n2] == t2[::-1][:n2] :
    print('Yes')
else :
    print('No')


Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <algorithm>
#define R register
#define MN 2005
typedef long long ll;
namespace IO{
	inline int read(){
		R int x; R bool f; R char c;
		for (f=0; (c=getchar())<'0'||c>'9'; f=c=='-');
		for (x=c^'0'; (c=getchar())>='0'&&c<='9'; x=(x<<1)+(x<<3)+(c^'0'));
		return f?-x:x;
	}
}
namespace sol{
	int n,k,q,vl[MN],seq[MN],ans=0x3f3f3f3f,vn,tmp[MN];
	void solve(int mi){
		vn=0;for (R int l=1,r; l<=n; l=r){
			for (;seq[l]<mi&&l<=n;++l);
			for (r=l;seq[r]>=mi&&r<=n;++r);
			if (r-l>=k){
				for (R int i=l; i<r; ++i)
					tmp[i-l]=seq[i];
				std::sort(tmp,tmp+r-l);
				for (R int i=0; i<r-l-k+1; ++i)
					vl[++vn]=tmp[i];
			}
		}
		if (vn<q) return;
		std::sort(vl+1,vl+vn+1);
		ans=std::min(ans,vl[q]-vl[1]);
	}
	void main(){
		n=IO::read(),k=IO::read(),q=IO::read();
		for (R int i=1; i<=n; ++i) seq[i]=IO::read();
		for (R int i=1; i<=n; ++i) solve(seq[i]);
		printf("%d\n",ans);
	}
}
int main(){sol::main();return 0;}

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

const long long MOD = 1000000007;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

void solve(long long n, long long a, long long b){
    ll all = modpow(2, n, MOD)-1;
    ll uku = 1;
    for(ll i = n;i >= n-(a-1);i--){
        uku *= i;
        uku %= MOD;
    }
    for(int i = 1;i <= a;i++){
        uku *= modinv(i, MOD);
        uku %= MOD;
    }
    //cout<<uku<<endl;
    ll uku1 = uku;
    
    uku = 1;
    for(ll i = n;i >= n-(b-1);i--){
        uku *= i;
        uku %= MOD;
    }
    for(int i = 1;i <= b;i++){
        uku *= modinv(i, MOD);
        uku %= MOD;
    }
   // cout<<all<<" "<<uku<<" "<<uku1<<endl;
    cout<<(all + MOD - uku + MOD - uku1)%MOD<<endl;
}

int main(){
    long long n;
    scanf("%lld",&n);
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    solve(n, a, b);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include<list>
#include<map>
#include<utility>
#include<tuple>
#include<numeric>
#include<set>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) a.begin(),a.end()
using namespace std;

int main()
{
	int n, s = 1;
	cin >> n;
	set<int> tb;

	while (tb.find(n) == tb.end()) {
		++s;
		tb.insert(n);
		if (n%2) {
			n = n * 3 + 1;
		}
		else {
			n =n/2;
		}
	}
	cout << s << endl;

	return 0;
}


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

int main() {
	char s;
	int ans = 700;
	for (int i = 0; i < 3; i++) {
		cin >> s;
		if (s == 'o') {
			ans += 100;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

int main(){
  ll n;
  cin >> n;
  map<string,ll> map;
  ll ans = 0;
  rep(i,n){
    string s;
    cin >> s;
    sort(all(s));
    map[s] += 1;
  }

  for (auto& p: map){
    ll s = p.second;
    ans += s*(s-1)/2;
  }
  cout << ans << endl;



    
}

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

int main()
{
	int n, q;
	int S[10000];
	int T[500];

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> S[i];
	cin >> q;
	for (int i = 0; i < q; i++)
		cin >> T[i];

	int count = 0;
	for (int i = 0; i < q; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (S[j] == T[i])
			{
				count++;
				break;
			}
		}
	}
	cout << count << endl;
    return 0;
}




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

int main() {
  int D, T, S;
  cin >> D >> T >> S;

bool ans = false;
  double x;
  x = ((double)D) / S;
  
  if(x <= T){
    ans = true;
  }
    
if(ans){
  cout << "Yes" << endl;
}
else{
  cout << "No" << endl;
}

return 0;
}

Measured memory_bytes: 3620
# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
from collections import deque,Counter
# from bisect import bisect_left
from heapq import heapify,heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if N == 1:
    print(0)
    exit()

ans = 0
cnt_primes = Counter(prime_factorize(N))

for i in cnt_primes:
    j = 1
    while cnt_primes[i]>=0:
        cnt_primes[i] -= j
        if cnt_primes[i]>=0:
            ans += 1
        else:
            break
        j += 1

print(ans)

Measured memory_bytes: 9468
s = input()
lst = [int(i) for i in s]
f1 = lambda x: '+' if x else '-'
f2 = lambda x: 1 if x else - 1
for i in range(16):
  tmp1 = [f1(i >> x & 1) for x in range(3)]
  tmp1.reverse()
  tmp2 = [f2(i >> x & 1) * lst[ - x - 1] for x in range(3)]
  if lst[0] + sum(tmp2) == 7:
    print(''.join([s[i] + tmp1[i] for i in range(3)] + [s[3] + '=7']))
    break

Measured memory_bytes: 3064
package main

import (
    "fmt"
    "math"
)

func min(nums ...int) int {
    res := nums[0]
    for i := 0; i < len(nums); i++ {
        res = int(math.Min(float64(res), float64(nums[i])))
    }
    return res
}

func main() {
    var N, M int
    fmt.Scan(&N, &M)
    var broken = make([]bool, N+1)
    for i := 0; i < M; i++ {
        var a int
        fmt.Scan(&a)
        broken[a] = true
    }
    var dp = make([]int, N+1)
    dp[0] = 1
    for i := 1; i <= N; i++ {
        dp[i] = dp[i-1]
        if i -2 >= 0 {
            dp[i] += dp[i-2]
        }
        dp[i] %= 1000000007
        if broken[i] {
            dp[i] = 0
        }
    }
    fmt.Println(dp[N])
}

Measured memory_bytes: 5504
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    Int L, R; cin >> L >> R;
    if (R-L == 1) {
        cout << (L*R)%2019 << endl;
        return 0;
    }

    if (L%2019 == 0 or R%2019 == 0 or L%2019 > R%2019) {
        cout << 0 << endl;
        return 0;
    }

    Int res = 2019;
    rep(i, L, min(R, L+2018)) {
        rep(j, L+1, min(R+1, L+2019)) {
            res = min(res, (i*j)%2019);
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++)cin>>a.at(i);
  sort(a.begin(),a.end(),greater<int>());
  int ans=a.at(0)/2;
  for(int i=1;i<N;i++)ans+=a.at(i);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import itertools
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
f = list(map(lambda x:list(x),list(itertools.permutations([i+1 for i in range(n)],n))))
print(abs(f.index(p) - f.index(q)))

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

int main(){
    int r, c, hsum, hsum2, vsum, vsum2;
    cin >> r >> c;
    int A[200][200];
    for (int i = 0; i < r; ++i){
        hsum = 0;
        for (int j = 0; j < c; ++j){
            cin >> A[i][j];
            hsum += A[i][j];
        }
        A[i][c] = hsum;
        hsum2 += hsum;
    }
    
    // すでに行の合計は求めている
    for (int j = 0; j <= c; ++j){
        vsum = 0;
        for (int i = 0; i < r; ++i){
            vsum += A[i][j];
        }
        A[r][j] = vsum;
    }
    
    
    for (int i = 0; i <= r; ++i){
        for (int j = 0; j <= c; ++j){
            if (j == 0) cout << A[i][j];
            else cout << " " << A[i][j];
        }
        cout << endl;
    }

    return 0;
}


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

int main(){
	float max = 0, min = 1000000, in;
	while (true)
	{
		cin >> in;
		if (cin.eof()) { break; }
		if(max<in){
			max = in;
		}
		else if (min > in){
			min = in;
		}
	}
	cout << max - min << endl;

	return 0;
}

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

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    ll cR=0,cG=0,cB=0;
    for(int i=0;i<N;i++){
        if(S[i]=='R') cR++;
        if(S[i]=='G') cG++;
        if(S[i]=='B') cB++;
    }
    ll ans = cR*cG*cB; // 異なる3文字を選ぶのはそれぞれの文字の選びかたの積.
    for(int j=1;j<N-1;j++){
        for(int d=1;j-d>=0&&j+d<N;d++){ // jを中心に左右に1つずつ端にぶつかるまで探索する.
            if(S[j-d]!=S[j]&&S[j]!=S[j+d]&&S[j-d]!=S[j+d]){ // 3つの文字がすべて異なるなら.
                ans--; // 条件2に合致した分を答えから引く.
            } 
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
"""
各山に振った雨をm1,m2,...とすると
a1 + a2 + ... + aN = m1 + m2 + ... + mN
また、あるダムについて、左右の山の雨が半分ずつたまるから
(mi + mi+1)/2 = ai -> mi + mi+1 = 2*ai
これらより
m1 = (a1 + ... + aN) - (m2 + m3 + ... + mN)
m2+m3 = 2*a2, m4+m5 = 2*a4, ...
からm1が決まる
m1 + m2 =2*a1 からm2がきまって～がmNまで続く
"""

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

total = sum(A)
tmp = 0
for i in range(1,N,2):
    tmp += 2 * A[i]

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

print(*ans)

Measured memory_bytes: 14132