akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
import copy
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)

a, b, c, d = map(int, input().split())
ans = max(a*c, a*d, b*c, b*d)
print(ans)


Measured memory_bytes: 68072
type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.Scan2 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1]))
  member this.Scan3 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2]))
  member this.Scan4 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2], a.[3]))
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f
  member this.ScanVecV n f = [| for i in 1..n -> stream.ReadLine() |> f |]
  member this.ScanMatrix n f  = [| for i in 1..n -> stream.ReadLine().Split() |> Array.map f |]
  member this.ScanCharMatrix n = [| for i in 1..n -> stream.ReadLine().ToCharArray() |]

let util = ABC(stdin)

let xs = util.ScanVecH int

let ys = Array.sortDescending xs

10 * ys.[0] + ys.[1] + ys.[2]
|> printfn "%d"





Measured memory_bytes: 14044
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}
ipnl = lambda n: [input() for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]
mp = lambda :map(int,input().split())

n = inp()
x = ipnl(n)
print(len(set(x)))

Measured memory_bytes: 107760
K, T = map(int,input().split())
list = list(map(int, input().split()))

list.sort()
if T > 1:
        p = list[-1] - list[-2]

        sum = 0
        for k in list[:-2]:
                sum += k

        if p - sum <= 1:
                print(0)
        else:
                print(p - sum - 1)
else:
        print(K-1)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e7+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;

ll a, b, x;

int main(){
	cin >> a >> b >> x;
	ll ans = b / x - a / x;
	if (a%x == 0)ans++;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



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

    bool ans=true;
    vector<pair<char,char> > p1,p2;
    set<pair<char,char> > s1,s2;
    string s,t;
    cin>>s>>t;
    rep(i,s.length()){
        if(s1.find(mp(s[i],t[i]))==s1.end()){
            p1.push_back(mp(s[i],t[i]));
            s1.insert(mp(s[i],t[i]));
        }
        if(s2.find(mp(t[i],s[i]))==s2.end()){
            p2.push_back(mp(t[i],s[i]));
            s2.insert(mp(t[i],s[i]));
        }
    }
    Sort(p1);
    Sort(p2);
    rep(i,p1.size()-1){
        if(p1[i].first==p1[i+1].first){
            ans=false;
        }
    }
    rep(i,p2.size()-1){
        if(p2[i].first==p2[i+1].first){
            ans=false;
        }
    }
    if(ans)fin("Yes");
    else fin("No");
    

//////////////////////////////////////////////////////
return 0;}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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



void func(long long W, long long H, long long x, long long y){

    double ans = W*H/2.0;
    cout<<setprecision(15);
    if(W%2==0 && W/2 == x && H%2==0 && H/2==y){
        cout<<ans<<" "<<1<<endl;
    }
    else{
        cout<<ans<<" "<<0<<endl;
    }

}

int main(){
    // cout << fixed << setprecision(5);

    long long W;
    scanf("%lld",&W);
    long long H;
    scanf("%lld",&H);
    long long x;
    scanf("%lld",&x);
    long long y;
    scanf("%lld",&y);
    func(W, H, x, y);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int a,b;cin>>a>>b;
  int p[3];rep(i,3)p[i] = i+1;
  rep(i,3){
    if(p[i] != a && p[i] != b){
      print(p[i]);
    }
  }
  return 0;
}


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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    string S, T; cin >> S >> T;
    cout << T + S << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))

    dp = [[0, 0] for _ in range(N + 1)]
    dp[1] = [A[0], -A[0]]

    for i, n in enumerate(A[1:-1], start=2):
        dp[i][0] = max(dp[i - 1][0] + n, dp[i - 1][1] - n)
        dp[i][1] = max(dp[i - 1][0] - n, dp[i - 1][1] + n)

    dp[-1] = [dp[N - 1][0] + A[-1], dp[N - 1][1] - A[-1]]

    print(max(dp[-1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 74272
import itertools
N = int(input())
M_Dict = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(N):
    moji = str(input())
    if moji[0] in M_Dict.keys():
        M_Dict[moji[0]] += 1
M_Dict = {k: v for k, v in M_Dict.items() if v != 0}    
if len(M_Dict) < 3:
    ans = 0
else:
    ans = 0
    for k in itertools.combinations(list(M_Dict.keys()),3):
        ans += int(M_Dict[k[0]]) * int(M_Dict[k[1]]) * int(M_Dict[k[2]])
    
print(ans)    

Measured memory_bytes: 9228
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define fi first
#define se second
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define v(T) vector<T>
#define p(T, N) pair<T, N>
#define tp(A, B, C) tuple<A, B, C>
#define ii p(int, int)
#define vi v(int)
#define vii v(p(int, int))
#define vvi v(v(int))
#define vl v(long long)
#define vll v(p(long long, long long))
#define si set<int>
#define msi map<string, int>
#define rsz(a) resize(a)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define qsortsi(v) sort(v.begin(), v.end(), [](pair<int, int> a, pair<int, int> b){return a.se < b.se;})
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define pt(a, b, c) emplace_back(make_tuple(a, b, c))
#define elif else if
#define fori(i, n) for(ll i = 0; i < n; ++i)
#define foris(i, a, b) for(ll i = a; i < b; ++i)
#define forise(i, a, b) for(ll i = a; i <= b; ++i)
#define ford(i, n) for(ll i = n; i >= 0; --i)
#define fords(i, a, b) for(ll i = a; i >= b; --i)
#define fordse(i, a, b) for(ll i = a; i > b; --i)
#define fora(i, a) for (auto &i: a)
#define rev(a) reverse(a.begin(), a.end())
#define revf(a, b, c) (reverse(a.begin() + b, a.begin() + c))
#define umap unordered_map
#define uset unordered_set
#define pq(T) priority_queue<T>
#define rpq(T) priority_queue<T, vector<T>, greater<T> >
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
const int mod = 1000000007;
int digits(int n) {
  n = abs(n);
  if(n < 10) return 1;
  elif(n < 100) return 2;
  elif(n < 1000) return 3;
  elif(n < 10000) return 4;
  elif(n < 100000) return 5;
  elif(n < 1000000) return 6;
  elif(n < 10000000) return 7;
  elif(n < 100000000) return 8;
  elif(n < 1000000000) return 9;
  else return 10;
}


int main() {
  io();
  
  char c;
  cin >> c;
  cout << (char)(c + 1);
  
  return 0;
}

Measured memory_bytes: 256
#A
N=int(input())
if N<600 and N>=400:
    print(8)
elif N<800 and N>=600:
    print(7)
elif N<1000 and N>=800:
    print(6)
elif N<1200 and N>=1000:
    print(5)
elif N<1400 and N>=1200:
    print(4)
elif N<1600 and N>=1400:
    print(3)
elif N<1800 and N>=1600:
    print(2)
elif N<2000 and N>=1800:
    print(1)

Measured memory_bytes: 9196
al = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' ,'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y','z']

n = input()
s = al.index(n)
print(al[s + 1])

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

using namespace std;
 
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(x) (int) ((x).size()) 
#define forn(i, n) for (int i = 0; (i) < (n); ++i)
#define fornr(i, n) for (int i = (n) - 1; (i) >= 0; --i)
#define forab(i, a, b) for (int i = (a); (i) < (b); ++i)
#define forba(i, a, b) for (int i = (b) - 1; (i) >= (a); --i)
#define forit(it, c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end() 

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) static_cast<void>(0)   
#endif

#ifdef _WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
typedef vector <int> vi;
typedef pair <int, int> pii;

#define FNAME ""

const int MAX_N = 1e5 + 5;

int a[MAX_N];

int main() {
#ifdef LOCAL    
	freopen(FNAME".in", "r", stdin);
	freopen(FNAME".out", "w", stdout); 
#endif    

	int n;
	scanf("%d", &n);
	forn (i, n)
		scanf("%d", &a[i]);
	int cnt = 0;
	forn (i, n)
		if (a[a[i] - 1] == i + 1)
			cnt++;
	printf("%d\n", cnt / 2);

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

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

int main(void){
  int d;
  cin >> d;

  for(int i=0;i<d;i++){
    int n;
    cin >> n;
    bool sharp[n+4][n+4];

    memset(sharp, true,sizeof(sharp));
    for(int p=1;p<=n+2;p++){
      for(int q=0;q<=n+2;q++){
	sharp[p][q] = false;
      }
    }


    int x=n+1,y=2;
    int vec=0;
    int cnt=0;
    if(i) cout << endl;

    while(1){
      sharp[x][y] = true;
      if(sharp[x+dx[vec]*2][y+dy[vec]*2]){
	if(cnt > 0) break;
	cnt = 2;
	vec = (vec+1)%4;
      }else{
	x += dx[vec];
	y += dy[vec];
	cnt--;
      }
    }
    
    for(int p=2;p<n+2;p++){
      for(int q=2;q<n+2;q++){
	if(sharp[p][q]){
	  cout << "#";
	}else{
	  cout << " ";
	}
      }
      cout << endl;
    }
  }
}

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	int c1 = 0,c2 = 0,c3 = 0,c4 = 0;
	while(t--)
	{
		string s;
		cin>>s;
		if(s=="AC")
		c1++;
		if(s=="TLE")
		c2++;
		if(s=="WA")
		c3++;
		if(s=="RE")
		c4++;
		
	}
	cout<<"AC x "<<c1<<"\n";
	cout<<"WA x "<<c3<<"\n";
	cout<<"TLE x "<<c2<<"\n";
	cout<<"RE x "<<c4<<"\n";
	
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
const int N = 1e+5+2;
long long array[N][3] = {0};

using P  = pair<char,int>;
long long solve(vector<P>& inputs) {
	int n = inputs.size();
	long long (*dp)[3] = array+1;
	dp[-1][1] = -1e+18;
	dp[-1][2] = -1e+18;

	for(int i = 0; i < n; i++) {
		auto pair = inputs[i];

		if(pair.first == '+'){
			dp[i][0] = max(dp[i-1][0] + pair.second, dp[i-1][1] + pair.second);
			dp[i][1] = max(dp[i-1][1] - pair.second, dp[i-1][2] + pair.second);
			dp[i][2] = dp[i-1][2] + pair.second;
		}else{
			dp[i][0] = max(dp[i-1][0] - pair.second,dp[i-1][1] - pair.second);
			dp[i][1] = max(dp[i-1][0] - pair.second, max(dp[i-1][1] - pair.second, dp[i-1][2] + pair.second));
			dp[i][2] = max(dp[i-1][1] + pair.second, dp[i-1][2] + pair.second);
		}
// 		cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl;
	}

	return max(dp[n-1][0], max(dp[n-1][1],dp[n-1][2]));
}

int main() {
	vector<P> inputs;

	int n;
	cin >> n;

	int first;
	cin >> first;
	inputs.push_back(P('+',first));

	for(int i = 0; i < n-1; i++) {
		char op;
		int m;
		cin >> op >> m;
		inputs.push_back(P(op,m));
	}

// 	for( auto pair: inputs)
// 		cout << pair.first << ":" << pair.second << endl;
	cout << solve(inputs) << endl;
}



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

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> abs(n);
    rep(i, n) cin >> abs[i].first >> abs[i].second;

    sort(abs.begin(), abs.end());
    ll ans = abs[0].first-1;
    for (int i = 0; i < n - 1; i++){
        ans += min(abs[i + 1].first - abs[i].first, abs[i].second - abs[i+1].second);
    }
    ans += abs[n - 1].second + 1;
    cout << ans << endl;
}


Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1 << 21;
const ll MOD = 1e9 + 7;
static const int N = 100;

int n;
int M[N][N];
int d[N]; // 距離で訪問状態を管理する

void bfs(int s)
{
    queue<int> q;
    q.push(s);
    rep(i, n)
    {
        d[i] = INF;
    }
    d[s] = 0;
    int u;
    while (!q.empty()) {
        u = q.front();
        q.pop();
        rep(v, n)
        {
            if (M[u][v] == 0) { // u->vに行けないなら飛ばす
                continue;
            }
            if (d[v] != INF) { // d[v]に行ったことがあるなら飛ばす
                continue;
            }
            d[v] = d[u] + 1; // u->vが始めてなら距離を更新
            q.push(v); // queueにvを入れる
        }
    }
    rep(i, n)
    {
        cout << i + 1 << " " << ((d[i] == INF) ? (-1) : d[i]) << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int u, k, v;
    cin >> n;
    rep(i, n)
    {
        rep(j, n)
        {
            M[i][j] = 0;
        }
    }
    rep(i, n)
    {
        cin >> u >> k;
        u--;
        rep(j, k)
        {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    bfs(0); // 0から出発

    return 0;
}


Measured memory_bytes: 3152
#include <iostream>
#include <string>
#include <unordered_map>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
int main() {
  char b;
  cin >> b;
  char ans;
  string s = "ACGT", t = "TGCA";
  unordered_map<char, char> mp;
  rep(i, 4) mp[s[i]] = t[i];
  cout << mp[b] << endl;
  return 0;
}

Measured memory_bytes: 256
/*================= *\
|  ID : aman__guta__ |
|      LANG: C++     |
\*==================*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double 
#define pb push_back
#define mk make_pair
#define fs first
#define sc second 
#define mod 1000000007
#define sp <<" "<<
#define JOKER ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
int spf[10000001];
long long int fac[200005]; 
void sieve(int n)
{
    spf[1]=1;
    for(int i=2;i<=n;i++) spf[i]=i;
    for(int i=4;i<=n;i+=2) spf[i]=2;
    for(int i=3;i*i<=n;i++)
    {
        if(spf[i]==i)
        {
            for(int j=i*i;j<=n;j+=i)
            {
                if(spf[j]==j) spf[j]=i;
            }
        }
    }
}
long long int power(long long int x, long long int y, long long int p) 
{ 
    long long int res = 1;
    x = x % p;
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;
        x = (x*x) % p; 
    } 
    return res; 
}
long long int modInverse(long long int n, long long int p) 
{ 
    return power(n, p-2, p); 
} 
long long int nCrModPFermat(long long int n, long long int r, long long int p) 
{ 
   if (r==0) 
      return 1; 
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}
int lps(string s)
{
    int n=s.size();
    int lps[n];
    lps[0]=0;
    int i=1;
    int j=0;
    while(i<n)
    {
        if(s[i]==s[j])
        {
            j++;
            lps[i]=j;
            i++;
        }
        else 
        {
            if(j)
            {
                j=lps[j-1];
            }
            else 
            {
                lps[i]=0;
                i++;
            }

        }
    }
    return min(n/2,lps[n-1]);
}
main()
{
    JOKER
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes\n";
    else cout<<"No\n";
    cerr<<"Time elapsed : "<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n'; 
    return 0;
} 



Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {

  public static void main(String[] args) {
  
  	try {
    
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      String s1 = br.readLine();
      String s2 = br.readLine();
      int m = s1.length();
      int n = s2.length();
      int[][] dp = new int[m+1][n+1];
      int[][] trace = new int[m+1][n+1];
      
      for(int i = 0 ; i <= m ; i++) {
      
        for(int j = 0 ; j <= n ; j++) {
        	
          if(i == 0 || j == 0) {
          	dp[i][j] = 0;
          } else if(s1.charAt(i-1) == s2.charAt(j-1)) {
          	dp[i][j] = dp[i-1][j-1] + 1;
            trace[i][j] = 2;
          } else if(dp[i-1][j] > dp[i][j-1]) {
          	dp[i][j] = dp[i-1][j];
            trace[i][j] = 1;
          } else {
          	dp[i][j] = dp[i][j-1];
            trace[i][j] = 0;
          }
          
          //System.out.print(dp[i][j]);
        }
      	//System.out.println();
      }
      
      String str = findLCS(trace, m ,n, s1);              
    
      System.out.println(str);
		                         
    } catch(Exception ex) {
    
    }
  
  }
     
   private static String findLCS(int[][] trace, int i, int j, String s) {
   	
     if(i == 0 || j == 0) {
     	return "";
     }
     
     String str = "";
     if(trace[i][j] == 2) {
       str = findLCS(trace, i-1, j-1, s) + s.charAt(i-1);
     } else if(trace[i][j] == 0) {
     	str = findLCS(trace, i, j-1, s);
     } else {
     	str = findLCS(trace, i-1, j, s);
     }
   	
     //System.out.println("str is " + str);
     return str;
     
   }                                     

}

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

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

using namespace std;

long ans(string);

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

    cout << ans(s) << endl;
}

long ans(string s) {
    // base case
    if (s.size() == 1) {
        return stoi(s);
    }

    // recursion step
    long result = 0;

    // 数字列を左と右に分けて考える
    // 左を1桁ずつ増やし、右に対して再帰を使って和を求めていく
    // 例えば、数字列 1234 について可能な数式を紙に書きだして考えるといい
    rep(i, s.size()) {
        if (i == 0) {
            result = stol(s);
            continue;
        }

        string left = s.substr(0, i);
        string right = s.substr(i);
        int max_plus = right.size() - 1;

        result += stoi(left) * pow(2, max_plus) + ans(right);
    }

    return result;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

int main() {
    char b;
    cin >> b;
    switch (b) {
    case 'A':
        cout << 'T' << endl;
        break;
    case 'C':
        cout << 'G' << endl;
        break;
    case 'T':
        cout << 'A' << endl;
        break;
    case 'G':
        cout << 'C' << endl;
    }
    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  int mn      = INT_MAX;
  int mnIndex = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] < mn) {
      mn      = a[i];
      mnIndex = i;
    }
  }
  bool c    = true;
  int cnt   = 0;
  int index = 0;
  for (int i = 0; i < n; i++) {
    if (index > 0 && index % k == 0) {
      c = true;
      i--;
    }
    if (c && a[i] != mn) {
      cnt++;
      a[i] = mn;
      c    = false;
    }
    index++;
  }

  cout << cnt << endl;
}

Measured memory_bytes: 640
/*
    author: masab hasnain
*/

/*
    Formulae:
    total number of subsegments = (n*(n+1))/2
*/

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b){
    return b == 0LL ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b){
    return (a * b) / gcd(a, b);
}
ll mod_pow(ll base, ll power, ll mod){
    base %= mod;
    ll ret = 1LL;
    while(power){
        if(power&1)
            ret = (ret * base) % mod;
        base = (base * base) % mod;
        power >>= 1;
    }
    return ret;
}
vector<ll> primes_global;
vector<ll> seive(ll _upper_bound = 10000000){//be careful when calling with a value.
    bitset<10000007> bs;
    bs.set();
    if(_upper_bound > 10000000)
        _upper_bound = 10000000;
    vector<ll> primes;
    ll _seive_size = _upper_bound ;
    bs[0] = bs[1] = 0;
    for (ll i = 2; i <= _seive_size; i++){
        if(bs[i]){
            for (ll j = i * i; j <= _seive_size; j += i)
                bs[j] = 0;
            primes.push_back(i);
        }
    }
    primes_global = primes;
    return primes;
}
bool is_prime(ll _number){
    if(primes_global.empty())
        seive();
    for (int i = 0; primes_global[i] * primes_global[i] <= _number and i < primes_global.size(); i++){
        if(_number % primes_global[i] == 0)
            return false;
    }
    return true;
}
vector<ll> prime_factors(ll _number){ //be careful about the upperbound of seive.
    if(primes_global.empty()){ //calls seive() if seive() was not called before.
        seive();
    }
    vector<ll> factors;
    ll pf_idx = 0, pf = primes_global[pf_idx];
    if(is_prime(_number)){
        factors.push_back(_number);
        return factors;
    }
    while (pf * pf <= _number )
    {
        if(_number % pf == 0){
            factors.push_back(pf);
            while(_number % pf == 0)
                _number /= pf;
        }
        
        pf = primes_global[++pf_idx];
    }
    if(_number != 1)
        factors.push_back(_number);

    return factors;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin.tie(0);
    int k;
    int a, b;
    cin >> k;
    cin >> a >> b;
    for (int i = 1;; i++){
        ll now = k * i;
        if(now>= a and now<= b){
            cout << "OK" << endl;
            return 0;
        }
        if(now>b)
            break;
    }
    cout << "NG" << endl;
}


Measured memory_bytes: 3644
#include <iostream>
#define NMax 105
using namespace std;

int mat[NMax][NMax], H, W, colors, count, i, j;
int main() {
    cin >> H >> W;
    cin >> colors;
    i = 1;
    j = 1;
    for (int color = 1; color <= colors; color++) {
        cin >> count;
        while (count) {
            mat[i][j] = color;
            if (i % 2 == 1) {
                i = (j == W) ? (i + 1) : i;
                j = (j < W) ? (j + 1) : W;
            } else {
                i = (j == 1) ? (i + 1) : i;
                j = (j > 1) ? (j - 1) : 1;
            }
            count--;
        }
    }
    for (int i = 1; i <= H ; i++) {
        for (int j = 1; j <= W; j++) {
            cout << mat[i][j] << ' ';
        }
        cout << '\n';
    }
    return 0;
}

Measured memory_bytes: 384
n, A, B, C = map(int, input().split())
l = []
for i in range(n):
	l.append(int(input()))

INF = 10 ** 9

def dfs(idx, a, b, c) -> int:
	if idx == n:
		return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else INF
	res0 = dfs(idx + 1, a, b, c)
	res1 = dfs(idx + 1, a + l[idx], b, c) + 10
	res2 = dfs(idx + 1, a, b + l[idx], c) + 10
	res3 = dfs(idx + 1, a, b, c + l[idx]) + 10
	return min(res0, res1, res2, res3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
n,m = map(int,input().split())
data = []
G = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    data.append((a-1,b-1))
    G[a-1].append(b-1)
    G[b-1].append(a-1)

def dfs(v,seen):
    if seen[v]: return
    seen[v] = True
    for nv in G[v]:
        dfs(nv,seen)

cnt = 0

for i in range(m):
    ra,rb = data[i]
    G[ra].remove(rb)
    G[rb].remove(ra)
    seen = [False]*n
    dfs(0,seen)
    cnt += (sum(seen) != n)
    G[ra].append(rb)
    G[rb].append(ra)

print(cnt)

Measured memory_bytes: 3064
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> dp(m + 1, vector<int>(1 << n, M));
    dp[0][0] = 0;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        int cs = 0;
        for(int i = 0; i < b; i++){
            int c; cin >> c;
            cs |= 1 << (c - 1);
        }
        for(int j = 0; j < (1 << n); j++){
            dp[i + 1][j] = dp[i][j];
        }
        for(int j = 0; j < (1 << n); j++){
            if(dp[i][j] == M){ continue; }
            dp[i + 1][j | cs] = min(dp[i + 1][j | cs], dp[i][j] + a);
        }
    }
    printde(dp);
    if(dp[m][(1 << n) - 1] == M){
        cout << -1 << '\n';
    }else{
        cout << dp[m][(1 << n) - 1] << '\n';
    }
}


Measured memory_bytes: 16384
def main():
    N = int(input())

    reddots = [list(map(int, input().split())) for _ in range(N)]
    bluedots = [tuple(map(int, input().split())) for _ in range(N)]

    reddots = sorted(reddots, key=lambda x: x[1], reverse=True)
    bluedots = sorted(bluedots, key=lambda x: x[0])

    ans = 0
    for blue in bluedots:
        for red in reddots:
            if red[0] < blue[0] and red[1] < blue[1]:
                ans += 1
                red[0] = 201
                break

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38640
#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int d,c;
	cin>>d>>c;
	cout<<d*c<<endl;
	//cout << "Hello world!!" << endl;
	return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll  long long
#define INF (ll)1e18 + 50
#define MAXN (int)1e5 + 50
#define fi first
#define se second
#define MOD 1000000007
#define all(v)((v).begin()), ((v).end())
#define A 911382323
#define B 972663749


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

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

int main() {
  
  vector<char> a(6);
  
  for ( int i = 0; i < 6; i++){
    cin >> a.at(i);
  }
  
  
  
  if ( (a.at(0) == a.at(5)) && (a.at(1) == a.at(4)) && (a.at(2) == a.at(3)) ){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  
  
}



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

ll n,m;
struct Edge {
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

int main(){
    cin >> n >> m;
    Graph G(n);
    for(ll i=0;i<m;i++){
        ll l,r,d;
        cin >> l >> r >> d;
        l--;
        r--;
        G[l].push_back(Edge(r, d));
		G[r].push_back(Edge(l, -d));
    }
    bool flag=true;
    vector<ll> dist(n,-1e9);
    for(ll i=0;i<n;i++){
        if(dist[i]!=-1e9) continue;
        dist[i]=0;
        queue<ll> que;
        que.push(i);
        while(!que.empty()){
            auto v=que.front();
            que.pop();
            for(auto nv:G[v]){
                if(dist[nv.to]==-1e9){
                    dist[nv.to]=dist[v]+nv.weight;
                    que.push(nv.to);
                }else{
                    if(dist[nv.to]!=dist[v]+nv.weight){
                        flag=false;
                    }
                }
            }
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 12908
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<ll>>;
#define MAX 1000000007

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    ssort(a);
    int i=1;int tmp=a[0];
    while(a[i]==tmp){
        ++i;
        if(i==n){
            break;
        }
    }
    n-=i;
    k-=1;
    int ans=n/k;
    if(n%k!=0){
        ans+=1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3800
#include<iostream>

int main(){
        int a,b;
        
        for(a=1;a<10;a++){
           for(b=1;b<10;b++){
              std::cout<<a<<"x"<<b<<"="<<a*b<<std::endl;
                         
                         }
                      }
   
        return 0;
}           

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

using namespace std;

#define eb emplace_back
#define ii pair<string, int>
#define pss pair<string, string>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define mp make_pair
#define int long long
#define tt tuple<int, string, string>
#define all(x) x.begin(), x.end()
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

pss match(string a, string b) {
  reverse(all(a));
  while (!a.empty() && !b.empty()) {
    if (a.back() != b.back())
      return pss("#", "#");
    a.pop_back(), b.pop_back();
  }
  reverse(all(a));
  return mp(a, b);
}

bool pal(string a, string b) {
  a += b;
  string y = a;
  reverse(all(y));
  return a == y;
}

// #define MULTIPLE_TEST_CASES
void solve() {
  int n;
  cin >> n;

  vector<ii> arr(n);

  for (ii &x : arr)
    cin >> x.ff >> x.ss;

  priority_queue<tt, vector<tt>, greater<tt>> pq;
  map<pss, int> dist;
  set<pss> vis;

  for (ii x : arr) {
    pq.emplace(x.ss, x.ff, "");
    pq.emplace(x.ss, "", x.ff);
    dist[mp(x.ff, "")] = dist[mp("", x.ff)] = x.ss;
  }

  int ans = INF;
  while (!pq.empty()) {
    auto [d, p, s] = pq.top();
    pq.pop();

    if (pal(p, s)) {
      ans = min(ans, d);
      continue;
    }

    if (vis.count(mp(p, s))) {
      continue;
    }
    vis.emplace(p, s);

    for (int i = 0; i < n; ++i) {
      ii x = arr[i];
      if (s == "") {
        pss m = match(p, arr[i].ff);
        if (!dist.count(m))
          dist[m] = INF;
        if (m.ff != "#" && dist[mp(p, s)] + x.ss < dist[m]) {
          dist[m] = dist[mp(p, s)] + x.ss;
          tt nxt = tt(d + x.ss, m.ff, m.ss);
          pq.emplace(nxt);
        }
      } else {
        pss m = match(arr[i].ff, s);
        if (!dist.count(m))
          dist[m] = INF;
        if (m.ff != "#" && dist[mp(p, s)] + x.ss < dist[m]) {
          dist[m] = dist[mp(p, s)] + x.ss;
          tt nxt = tt(d + x.ss, m.ff, m.ss);
          pq.emplace(nxt);
        }
      }
    }
  }

  cout << (ans == INF ? -1 : ans) << endl;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

Measured memory_bytes: 3792
n,y = map(int, input().split())

a = -1
b = -1
c = -1

for i in range(n+1):
    for j in range(n+1-i):
        money = 10000 * i + 5000 * j + 1000 * (n - i - j)
        if y == money:
            a = i
            b = j
            c = n - i - j
            

print(str(a)+" ",str(b)+" ",str(c))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vi vector<int>
#define sl set<ll>
#define sc set<char>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mpi map<ll,ll>
#define mpc map<char,ll>
#define forn(i,n) for(ll i=0;i<n;i++)
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inf        10000000
#define MOD        1000000007


int main()
{
	ll n,m;
	cin>>n>>m;
	string s[n];
	forn(i,n)
	{
		cin>>s[i];
	}
	ll dp[n][m];
	forn(i,n)
	{
	    forn(j,m)
	    dp[i][j]=0;
	}
	dp[0][0]=1;
	forn(i,n)
	{
		forn(j,m)
		{
		    if(j+1<m && s[i][j+1]=='.')
		    {
		        dp[i][j+1]+=dp[i][j];
		        dp[i][j+1]%=MOD;
		    }
		    if(i+1<n && s[i+1][j]=='.')
		    {
		        dp[i+1][j]+=dp[i][j];
		        dp[i+1][j]%=MOD;
		    }
		}
	}
	cout<<dp[n-1][m-1];
}

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

int main() {
  string S, T;
  cin >> S >> T;
  int A, B;
  cin >> A >> B;
  string U;
  cin >> U;
  
  if(S == U) A -= 1;
  if(T == U) B -= 1;
  
  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int maxX = x;
		int minY = y;
		for(int i = 0; i < n; i++){
		    int tmp = sc.nextInt();
		    maxX = max(maxX, tmp);
		}
		for(int i = 0; i < m; i++){
		    int tmp = sc.nextInt();
		    minY = min(minY, tmp);
		}
		
		// 計算
		String result = "No War";
		if(minY <= maxX) result = "War";
		
		// 出力
		System.out.println(result);
		
	}
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define mod 1000000007

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int n ;
int arr[500005] ;
string str ;
int dp[2005] ;
int hf(int rem)
{
    if(rem == 0)
        return 1 ;
    if(rem < 0)
        return 0 ;
    if(dp[rem]!=-1)
        return dp[rem] ;
    int ans = 0 ;
    for(int i=3 ; i<=rem ; i++)
    {
        ans += hf(rem-i) ;
        ans %= mod ;
    }
    return dp[rem] = ans ;
}
void solve()
{
    cin >> n ;
    memset(dp,-1,sizeof(dp)) ;
    int ans = hf(n) ;
    cout << ans ;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int tt = 1;
	//cin >> tt ;
	while(tt--)
	{
	     solve() ;
	}
}


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

int main() {
  char S[101010];
  cin >> S;
  bool app[26];
  for (int i = 0; i < 26; i++) app[i] = false;
  for (int i = 0; S[i] != '\0'; i++) app[S[i] - 'a'] = true;
  for (int i = 0; i < 26; i++) {
    if (!app[i]) {
      cout << (char)(i + 'a') << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


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


#define M_MAX 20
#define N_MAX 50000
#define INFTY 1 << 29
int main(){

int n;
cin >> n ;

int a[n];
int res[n];
for(int i=0;i<n;i++) cin >> a[i];
for(int i=0;i<n;i++)res[a[i]-1]=(i+1);

for(int i=0;i<n;i++){
cout << res[i] << " ";
}



}


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

int main() {
  long long n,m=0,sum=0, mod=2019;
  cin>>n;
  
  int water[n+1]; int x[n+1];
  rep(i,n){
    cin>>water[i+1];
    m+=water[i+1];
  }
  
  for(int i=1; i<=n/2; i++){
    sum+=water[2*i];
  }

  x[1]=m-sum*2;
  for(int i=1; i<n; i++){
    x[i+1]=(water[i]-x[i]/2)*2;
  }
  
  for(int i=1; i<=n; i++)  
    cout<<x[i]<<endl;
}

Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
// #define req(j, n) for (ll j = 1; j < (n+1); j++)
// #define rer(k, n) for (ll k = 1; k < (n+1); k++)


int main()
{
    int k;
    string s;
    cin >> k;
    cin >> s;
    if ((int)(s.length()) <= k) {
        cout << s << endl;
    } else {
        string ans = s.substr(0, k) + "...";
        cout << ans << endl;
    }
}

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

public class Main 
{
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in); 
		while(sc.hasNext())
		{
			int n = sc.nextInt();
			if(n==0)
				return;
			int ans =0;
			boolean a[] = new boolean[1000001];
			Arrays.fill(a, true);
			a[0]=a[1]=false;

			for(int i=0; i*i<=1000000; i++)
			{
				if(!a[i])
					continue;
				for(int j=i+i; j<=1000000; j+=i)
				{
					a[j] = false;
				}
			}

			int i=0;
			while(n>0)
			{
				
				if(a[i])
				{
					ans+=i;
					n--;
				}
				i++;
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 16000
#include "bits/stdc++.h"

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define int ll
int INF = 1e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
typedef pair<int, int> Vec2;
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

signed main() {
	ios::sync_with_stdio(false);
	string s;
	map<string, int> si;
	//SUN, MON, TUE, WED, THU, FRI, SAT
	si.insert(make_pair("SUN",7));
	si.insert(make_pair("MON",6));
	si.insert(make_pair("TUE",5));
	si.insert(make_pair("WED",4));
	si.insert(make_pair("THU",3));
	si.insert(make_pair("FRI",2));
	si.insert(make_pair("SAT",1));
	cin >> s;
	cout << si[s] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int n;
  while(cin >> n, n){
    int s = 0;
    for(int i = 0; i < (n * (n - 1)) / 2; i++){
      int t; cin >> t;
      s += t;
    }
    cout << s / (n - 1) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

signed main(){
	int s=0;
	int n;
	cin>>n;
	while(n--){
		int a;
		cin>>a;
		if(a%2==0)s++;
	}
	cout<<s<<endl;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,q,x,d;
  list<int>l;
  list<int>::iterator it=l.end();
  cin>>n;
  for(int i=0;i<n;i++)
  {
    cin>>q;
    if(q==0)
    {
      cin>>x;
      it=l.insert(it,x);
    }
    else if(q==1)
    {
      cin>>d;
      int t=abs(d);
      while(t--)
      {
        if(d<0)
        {
          it--;
        }
        else
        {
          it++;
        }
      }
    }
      else
      {
        it=l.erase(it);
      }
    }
    for(it=l.begin();it!=l.end();it++)
    {
      cout<<*it<<endl;
    }
  }



Measured memory_bytes: 18668
n = int(input())

dic = {}
for i in range(n):
  s = input()
  s = sorted(s)
  s = ''.join(s)
  if not s in dic.keys():
    dic[s] = 1
  else:
    dic[s] +=1 
ans = 0

for i in dic:
  ans += dic[i]*(dic[i]-1)//2
  
print(ans)

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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

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

u64 lcm(u64 a, u64 b) { return (a / gcd(a, b)) * b; }

int main() {
  u64 N, K;
  cin >> N >> K;
  vector<u64> H(N);
  ArrayInput(H);
  sort(H.begin(), H.end(), greater<u64>());
  u64 sum = 0;
  for (u64 i = K; i < N; ++i) {
    sum += H[i];
  }
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<string>
#include<set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<n; i++)

const int INF = 1001001001;

void solve(){
  int n,m;  cin >> n >> m;
  cout << (n*(n-1) + m*(m-1))/2 << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
bool BN(ll l,ll a,ll b,ll k){
  a=a-k*l; b=b-l;
  if(a<0||b<0)return 0;
  ll r=b/k;
  return a>=r;
}
char Beta(ll l,ll a,ll b,ll k,ll x){
  if(x<(k+1)*l){
    if(x%(k+1)==k)return 'B';
    return 'A';
  }
  x-=(k+1)*l;
  if(x<a)return 'A';
  x-=a;
  if(x<b)return 'B';
  x-=b;
  if(x%(k+1)==0)return 'A';
  return 'B';
}
ll K(ll a,ll b){
  if(a<b)swap(a,b);
  return a/(b+1)+!!(a%(b+1));
}
void Alpha(ll a,ll b,ll c,ll d){
  //if(a>1e3||b>1e3)return;
  ll k=K(a,b);
  ll l=0,r=1e9,m;
  
  while(l<r-1){
    m=(l+r)/2;
    if(BN(m,a,b,k))l=m;
    else r=m;
  }
  /*
  for(m=0;m<1010;m++){
    if(BN(m,a,b,k))l=m;
  }*/
  
  ll L=l,R=(b-L)/k;
  ll am=a-k*L-R; ll bm=b-L-k*R;
  for(ll i=c-1;i<d;i++)cout<<Beta(l,am,bm,k,i);cout<<endl;
}
int main(){
   ll q;cin>>q;
   lol(i,q){
     ll a,b,c,d;cin>>a>>b>>c>>d;
     Alpha(a,b,c,d);
   } 
    return 0;
}


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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;


signed main(){
    int N, A[20], B[20], C[20];
    cin >> N;
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];
    REP(i, N - 1) cin >> C[i];
    int prev = -INT32_MAX, ans = 0;
    REP(i, N){
        ans += B[A[i] - 1];
        if(A[i] - 1 - prev == 1) ans += C[prev];
        prev = A[i] - 1;
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 256