akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
    int N;
    int A[200];
    int i, j, k;
    int flag;
    int tmp, count=0;

    scanf("%d", &N);
    for(i=0; i<N; i++){
        scanf("%d", &A[i]);
    }

    for(i=0; i<N; i++){
        for(j=N-1; j>i; j--){
            if(A[j]<A[j-1]){
                tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                count += 1;
            }
        }
    }

    for(i=0; i<N; i++){
        if(i>0){
            printf(" ");
        }
        printf("%d", A[i]);
    }

    printf("\n%d\n", count);

    return 0;
}


Measured memory_bytes: 2140
#include <iostream>
using namespace std;
int main ()
{
	int a, b, c;
	cin >> a >> b >> c;
	if ( a > b )
		swap( a, b );
	if ( b > c )
		swap( b, c );
	if ( a > b )
		swap( a, b );
	cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 1168
a = input()
if a == "SUN":
  print("7")
elif a == "MON":
  print("6")
elif a == "TUE":
  print("5")
elif a == "WED":
  print("4")
elif a == "THU":
  print("3")
elif a == "FRI":
  print("2")
else:
  print("1")

Measured memory_bytes: 2940
N = int(input())
C = 4*[0]
W = ['AC', 'WA', 'TLE', 'RE']
for i in range(N):
	S = input()
	for j in range(4):
		if S==W[j]:
			C[j] += 1

for j in range(4):
	print(W[j],'x', C[j])



Measured memory_bytes: 8992
# -*- coding: utf-8 -*-
n = int(input())
hs = list(map(int, input().split()))

flag = True
pre = hs[-1]

for h in hs[::-1]:
    if h <= pre:
        pre = h
    elif h-1 <= pre:
        pre = h-1
    else:
        flag = False
        break

print("Yes" if flag else "No")


Measured memory_bytes: 14396
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

struct edge{/*重み付き,有向*/
	int to , cost;/*toは接続先*/
	ll id = 0;
	edge(ll to_ ,ll cost_ = 1){ to=to_; cost=cost_; };/*全てのcost=1 <=> 無向グラフ*/
};
bool operator<(edge e1 ,edge e2){return e1.cost < e2.cost; }
bool operator>(edge e1 ,edge e2){return e1.cost > e2.cost; }
using graph =  vector< vector<edge> >;

ll n;
ll m;
graph g;
vector<edge> ve;
vector<PLL> vv;

matrix mx;
ll dp[50][1LL<<20];

void dfs(ll id,PLL pl,ll pre,Vi &v,edge e){
	v.pb(e.id);
	if(pl.second==id){
		mx.pb(v);
		v.pop_back();
	}else{
		rep(i,g[id].size()){
			edge e = g[id][i];
			if(e.to == pre)continue;
			dfs(e.to,pl,id,v,e);
		}
		v.pop_back();
	}
}


int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	std::cout<<std::fixed<<std::setprecision(30);
	cin>>n;
	g.resize(n);
	rep(i,n-1){
		ll in,inp;
		cin>>in>>inp;
		in--;inp--;
		edge e(inp),e2(in);
		e.id = i;
		e2.id = i;
		g[in].pb(e);
		g[inp].pb(e2);
	}
	cin>>m;
	rep(i,m){
		ll in,inp;
		cin>>in>>inp;
		in--;inp--;
		vv.pb(mp(in,inp));
		Vi v;
		rep(j,g[in].size())dfs(g[in][j].to,mp(in,inp),in,v,g[in][j]);
	}
	rep(i,50){
		rep(j,1LL<<20){
			dp[i][j] = 0;
		}
	}
	matrix ed(n-1);
	rep(i,m){
		rep(j,mx[i].size()){
			ed[mx[i][j]].pb(i);
		}
	}
	dp[0][0] = 1;
	rep(i,n-1){
		ll mask = 0;
		rep(j,1LL<<m){
			mask = j;
			rep(k,ed[i].size()){
				mask |= (1LL<<ed[i][k]);
			}
			dp[i+1][mask] += dp[i][j];
			dp[i+1][j] += dp[i][j];
		}
	}
	print(dp[n-1][(1LL<<m)-1]);
	return 0;
}

Measured memory_bytes: 409856
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, m, sum = 0;
    cin >> n >> m;
    int arr[n];
    for(int i = 0;i < n;++i)
        cin >> arr[i], sum += arr[i];
    sort(arr, arr + n);
    reverse(arr, arr + n);
    int mn = sum / (4 * m) + (sum % (4 * m) != 0);
    for(int i = 0;i < m;++i)
        if(arr[i] < mn)
            return cout << "No", 0;
    cout << "Yes";
    return 0 ;
}


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

main (){
  int N;
  cin >> N;
  for(int i=0; i<26; i++){
    for(int j=0; j<15; j++){
      if( N ==4*i+7*j){
        cout << "Yes" << endl;
        return 0;
      }  
    }
  }
  cout << "No" << endl;
}  

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

int main() {
  char b;
  cin >> b;

  if (b == 'A') {
    cout << 'T';
  }
  else if (b == 'T') {
    cout << 'A';
  }
  else if (b == 'C') {
    cout << 'G';
  }
  else if (b == 'G') {
    cout << 'C';
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pb push_back
#define ii pair<int,int>
#define ppb pop_back
#define orta ((bas+son)/2.0)
#define st first
#define nd second
#define ll long long
#define N 55
#define inf 1000000000000000001
#define MOD 998244353 
using namespace std;

ll go(ll to,ll a,ll b) {

	ll res=abs(to-a);

	if(to==1) b=max(to,b-res);
	else b=min(to,b+res);
	
	a=to;

	if(b==a) return res;

	return res+1+(abs(b-a)-1)/2;

}

ll solve(ll to,ll a,ll b) {

	return min(go(to,a,b),go(to,b,a));

}

int main() {

	ll n,a,b;

	scanf("%lld %lld %lld",&n,&a,&b);

	if((b-a)%2) {

		printf("%lld",min(solve(1,a,b),solve(n,a,b)));

	}
	else {
		printf("%lld",(b-a)/2);
	}

}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc079/tasks/abc079_d
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int H, W;
    vector<vector<int>> c(10, vector<int>(10));
    cin >> H >> W;
    REP(i, 10) REP(j, 10) cin >> c[i][j];
    vector<vector<int>> A(H, vector<int>(W));
    REP(i, H) REP(j, W) cin >> A[i][j];

    // Warchall-Floyed 法を用いて最小コストを求める
    REP (k, 10) // 中継する番号
    REP (i, 10) // スタート番号
    REP (j, 10) // ゴール番号
    {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    }

    int ans = 0;
    REP (i, H) REP(j, W)
    {
        if (-1 < A[i][j])
        {
            ans += c[A[i][j]][1];
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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

    int a,b,c;
    cin >> a >> b >> c;
    if(a + b >= c)
        cout << b + c;
    else {

        cout <<  c - (c - a - b) + b + 1;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 998244353;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template<class T>
vector<T> divisor(T n){
    vector<T> ret;
    for(T i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret), greater<>());
    return(ret);
}

int main() {
    ll n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    ll s = accumulate(v.begin(),v.end(), 0LL);
    auto div = divisor(s);
    for (auto &&x : div) {
        vector<int> u(n);
        for (int i = 0; i < n; ++i) u[i] = v[i]%x;
        sort(u.begin(),u.end());
        vector<int> A(n+1), B(n+1);
        for (int i = 0; i < n; ++i) {
            A[i+1] = A[i] + u[i];
        }
        for (int j = n-1; j >= 0; --j) {
            B[j] = B[j+1] + (x-u[j]);
        }
        for (int i = 0; i <= n; ++i) {
            if(A[i]%x == B[i]%x && max(A[i], B[i]) <= k){
                cout << x << "\n";
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int H = sc.nextInt();
        int M = sc.nextInt();
        int minute = 60 * H + M;
        double w_a = Math.PI * (180 - minute) / 360;
        double w_b = Math.PI * (15 - minute) / 30;
        double c = Math.sqrt(Math.pow(A, 2) + Math.pow(B, 2) - 2 * A * B * Math.cos(w_a - w_b));
        System.out.println(c);
        sc.close();
    }
}

Measured memory_bytes: 36032
// Aaradhya Beri
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define w(x) int x; cin>>x; while(x--)
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
 

signed main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cout<<fixed<<setprecision(8);
   string a ,b;
    cin >> a >> b;
    int n1 = a.size(), n2 = b.size();
    if(n1>n2){
        cout << "GREATER";
    }
    else if(n1<n2){
        cout << "LESS";
    }
    else{
        for(int i = 0; i < n1;i++){
            if(a[i]>b[i]){
                cout << "GREATER";
                return 0;
            }
            else if(a[i]<b[i]){
                cout << "LESS";
                return 0;
            }
        }
        cout << "EQUAL";
    }
    return 0;
}

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

int main()
{
  long long a,b;
  cin >> a >> b;
  
  int min;

  if(a>b)	min=b;
  else	min = a;
  
  long long com=1;
  
  for(long long i=min;i>1;i--){
    if(a%i==0 && b%i==0){
      com = i;
      break;
    }
  }
  long long ans = a*b/com;
  
  cout << ans << endl;
  
  return 0;
}


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

int main(){
    int  a;
    cin >> a;
    int ans = a;
    ans = ans + a * a + a*a*a;
    cout << ans <<  endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  ll N;
  IN(N);
  vll p(N);
  REP(i,N) IN(p[i]);

  ll ans = 0;
  FOR(i,1,N-1){
    if(p[i-1]<p[i] && p[i]<p[i+1]) ans++;
    else if(p[i+1]<p[i] && p[i]<p[i-1]) ans++;
  }

  OUT(ans);

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

class Sai {
public:
	int up;
	int down;
	int north;
	int east;
	int west;
	int south;

	Sai()
	{
		up = 1;
		down = 6;
		south = 2;
		east = 3;
		north = 5;
		west = 4;
	}
	void North()
	{
		int temp = up;
		up = south;
		south = down;
		down = north;
		north = temp;
	}
	void East()
	{
		int temp = up;
		up = west;
		west = down;
		down = east;
		east = temp;
	}
	void West()
	{
		int temp = up;
		up = east;
		east = down;
		down = west;
		west = temp;
	}
	void South()
	{
		int temp = up;
		up = north;
		north = down;
		down = south;
		south = temp;
	}
	void Right()
	{
		int temp = south;
		south = east;
		east = north;
		north = west;
		west = temp;
	}
	void Left()
	{
		int temp = south;
		south = west;
		west = north;
		north = east;
		east = temp;
	}
};

int main()
{
	int n;
	std::string str;
	std::vector<int> ans;

	while (1) {
		std::cin >> n;
		if (n == 0) {
			break;
		}

		int answer = 1;
		Sai sai;

		for (int i = 0; i < n; i++) {
			std::cin >> str;
			if (str == "North") {
				sai.North();
				answer += sai.up;
			}
			else if (str == "East") {
				sai.East();
				answer += sai.up;
			}
			else if (str == "West") {
				sai.West();
				answer += sai.up;
			}
			else if (str == "South") {
				sai.South();
				answer += sai.up;
			}
			else if (str == "Right") {
				sai.Right();
				answer += sai.up;
			}
			else if (str == "Left") {
				sai.Left();
				answer += sai.up;
			}
		}
		ans.push_back(answer);
	}

	for (unsigned int i = 0; i < ans.size(); i++) {
		std::cout << ans[i] << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3132
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    vector<string> days = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string s; cin >> s;
    for (int i = 0; i < days.size(); i++) {
        if (days[i] == s) {
            cout << 7 - i << "\n";
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cfloat>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

inline llong sum(llong n) {
    return n * (n + 1) / 2;
}

llong n, k;
llong p[200005];
__float128 d[200005];

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        d[i] = (__float128)sum(p[i]) / p[i];
    }

    __float128 ans = -1;
    __float128 s = 0;
    for (int i = 0; i < n; i++) {
        if (i < k) {
            s += d[i];
            ans = max(ans, s); 
        }
        else {
            ans = max(ans, s);
            s -= d[i - k];
            s += d[i];
            ans = max(ans, s);
        }
    }

    double x = ans;

    printf("%.*lf\n", DBL_DIG, x);

    return 0;
}


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

typedef unsigned long long uLL;
typedef long long int LL;
typedef pair <int,int> pii;
typedef pair <int,pii> piii;
typedef pair <long long,long long> pll;
typedef pair <long long,pll> plll;
const int N = 1e5 + 5;
const int inf = 1e9;
const long long INF = 1e18;
const double PI = acos(-1.0);
const double EPS = 1e-8;
const int MOD = 1000000007;

int n;
LL a[ N ];
LL dp[ 505 ][ 505 ];
LL sum[ N ];

LL getsum( int l , int r ) {
        return ( sum[r] - sum[l-1] );
}
LL MCM( int l , int r ) {
        if( l >= r ) return 0;
        if( dp[l][r] != -1 ) return dp[l][r];
        LL ret = INF;
        for( int i = l; i < r; i++ ) {
                LL temp = getsum( l , i ) + getsum( i + 1 , r );
                ret = min( ret , MCM( l , i ) + MCM( i + 1 , r ) + temp );
        }
        return dp[l][r] = ret;
}
int main( int argc , char const *argv[] ) {
        ios_base::sync_with_stdio( false ); cin.tie( NULL );
        cin >> n;
        for( int i = 1; i <= n; i++ ) cin >> a[i];
        for( int i = 1; i <= n; i++ ) sum[i] += sum[i-1] + a[i];
        memset( dp , -1 , sizeof( dp ) );
        cout << MCM( 1 , n ) << endl;
        return 0;
}













Measured memory_bytes: 2304
A, B, C, D, E, F = map(int,input().split())
water = [0 for _ in range(31)]
sugar = [0 for _ in range(3001)]
water[0] = 1
sugar[0] = 1
for i in range(30):
    if water[i] == 0:
        continue
    if i + A <= 30:
        water[i+A] = 1
    if i + B <= 30:
        water[i+B] = 1
for i in range(3000):
    if sugar[i] == 0:
        continue
    if i + C <= 3000:
        sugar[i+C] = 1
    if i + D <= 3000:
        sugar[i+D] = 1

MAX = -1
ans = None
for i in range(1, 31):
    for j in range(3001):
        if water[i] == 0 or sugar[j] == 0 or i * 100 + j > F or i * E < j:
            continue
        if MAX < 100 * j / (j + i * 100):
            MAX = 100 * j / (j + i * 100)
            ans = [i * 100 + j, j]
print(*ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int a,b,r1,r2,l1,l2,i,j,n;
    scanf("%d",&b);
    if(b==22){
        printf("Christmas Eve Eve Eve\n");
    } else if(b==23){
        printf("Christmas Eve Eve\n");
    }
    else if(b==24){
        printf("Christmas Eve\n");
    }
    else if(b==25){
        printf("Christmas\n");
    }
    return 0;
}


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

int main(){
  int r;
  cin>>r;
  cout<<2*r*3.141592;
}


Measured memory_bytes: 3776
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()

	ans := []rune{}
	for n > 0 {
		n--
		ans = append(ans, rune('a'+n%26))
		n /= 26
	}
	for i := 0; i < len(ans)/2; i++ {
		ans[i], ans[len(ans)-1-i] = ans[len(ans)-1-i], ans[i]
	}

	fmt.Fprintln(wr, string(ans))
}


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

std::string str;
std::vector<std::string> strs;
bool flags[26];

void dfs(std::string& s, int k) {
  if( k >= (int)s.size() ) {
    strs.push_back(s);
    return;
  }
  bool flag = false;
  for(int i = 0; i < k; ++i) {
    if( s[i] == s[k] ) {
      flag = true;
      break;
    }
  }
  if( s[k] == 'a' ) flag = true;
  if( flag ) {
    dfs(s, k + 1);
  }
  if( s[k] != 'z' and not ( flags[s[k]-'a'] ) ) {
    flags[s[k]-'a'] = true;
    s[k] = s[k] + 1;
    dfs(s, k + 1);
    s[k] = s[k] - 1;
    flags[s[k]-'a'] = false;
  }
}

int main(int argc, char *argv[]) {

  for(;;) {
    strs.clear();
    std::cin >> str;
    if( str == "#" ) break;
    dfs(str, 0);
    printf("%zu\n", strs.size());
    for(std::string S : strs) {
      //std::cout << ' '<< S << std::endl;
    }
    if( (int)strs.size() <= 10 ) {
      for(std::string S : strs) {
        std::cout << S << std::endl;
      }
    }
    else {
      for(int i = 0; i < 5; ++i) {
        std::cout << strs[i] << std::endl;
      }
      for(int i = (int)strs.size() - 5; i < (int)strs.size(); ++i) {
        std::cout << strs[i] << std::endl;
      }
    }
  }
  

  return 0;
}

Measured memory_bytes: 4320
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n;
string s[55];
int t[55][30];
int ans[30];

int main(){
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>s[i];
	
	for(int i=0;i<n;i++){
		for(int j=0;j<s[i].size();j++){
			t[i][s[i][j]-'a']++;
		}
	}
	
	for(int i=0;i<26;i++)
		ans[i]=t[0][i];
	for(int j=0;j<26;j++){
		for(int i=1;i<n;i++){
			ans[j]=min(ans[j],t[i][j]);
		}
	}
	string ansi;
	for(int i=0;i<26;i++){
		for(int j=0;j<ans[i];j++){
			ansi+=('a'+i);
		}
	}
	cout<<ansi<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  string num;
  cin >> num;
  for(int tmp= 0; tmp < 3; tmp++) {
    if (num.at(tmp) == '1') {
      cout << 9;
    }
    else if (num.at(tmp) == '9') {
      cout << 1;
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
n,a,b = map(int,input().split())
c = n//(a+b)
d = (n%(a+b))
if a ==0:
    print(0)
elif n%(a+b)==0:
    print(c*a)
elif n%(a+b)!= 0 and d <=a :
    print((c*a)+d)
else:
    print((c*a)+a)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int N, A, B;
    int b, s;

    cin >> N >> A >> B;

    if(A >= B){
        b = B;
    }else{
        b = A;
    }

    if(N <= A + B){
        s = A + B - N;
    }

    cout << b << " " << s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int T, X; cin >> T >> X;

	double res = (double)T/(double)X;
	printf("%.6lf\n", res);

	return 0;
}

Measured memory_bytes: 256
url = "https://atcoder.jp//contests/abc115/tasks/abc115_b"

def main():
    n = int(input())
    t = [int(input()) for i in range(n)]
    ind = t.index(max(t))
    t[ind] = t[ind] // 2
    print(sum(t))


if __name__ == '__main__':
    main()


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

// 累積和
struct cumulative_sum {
    using lint = long long int;
    int sz;
    // data[i]:元の数列
    vector<lint> data;
    // cum[i]:[0,i)の和
    vector<lint> sum;
    // 要素数を指定して初期化
    cumulative_sum(const int _sz) : sz(_sz) {
        data.assign(sz, 0);
        sum.assign(sz + 1, 0);
    }
    lint& operator[](const int k) {
        return data[k];
    }
    // dataに基づいてsumを構築
    void build() {
        for (int i = 0; i < sz; i++) sum[i + 1] = sum[i] + data[i];
    }
    // [a,b)の和を求める
    lint query(const int a, const int b) {
        return sum[b] - sum[a];
    }
};

int q;

bool isPrime(int p) {
    if (p < 2) return false;
    for (int i = 2; i * i <= p; i++) {
        if (p % i == 0) return false;
    }
    return true;
}

int main() {
    cumulative_sum cum(1e+5 + 1);
    for (int i = 0; i <= 1e+5; i++) {
        if (i % 2 == 1 && isPrime(i) && isPrime((i + 1) / 2)) cum[i] = 1;
    }
    cum.build();
    cin >> q;
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        r++;
        cout << cum.query(l, r) << endl;
    }
}

Measured memory_bytes: 2176
n=int(input())
graph=[]
ans=[0]*n
zisuu={}
for i in range(n):
    graph.append([])
for i in range(n-1):
    a,b=map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
from collections import deque
zisuu_1=deque([])
for i in range(n):
    zisuu[i]=len(graph[i])
    if len(graph[i])==1:
        zisuu_1.append(i)
c=list(map(int,input().split()))
c.sort()
if n==1:
    ans[0]=c[0]
else:
    for i in range(n):
        x=zisuu_1.popleft()
        ans[x]=c[i]
        for j in graph[x]:
            zisuu[j]=zisuu[j]-1
            if zisuu[j]==1:
                zisuu_1.append(j)
print(sum(c[:n-1]))
for i in ans:
    print(i)
    
             
    



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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

// #define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}
void _main();
int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); return 0;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 

void _main() {
  string s;
  cin >> s ;
  int N = s.size();
  vl ss(N+1);
  rep(i,N) ss[i+1] = int(s[i]=='B');
  rep(i,N) ss[i+1] += ss[i];
  ll ans = 0;
  rep(i,N){
    if(s[i]=='W') ans += ss[i+1];
  }
  cout << ans << endl;
}

Measured memory_bytes: 2196
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0004
  * Simultaneous Equation
  */
object Main {
  def main(args: Array[String]): Unit = {
    Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).map(_.split(" +").map(BigDecimal(_)))
      .map { case Array(a, b, c, d, e, f) => solve(a, b, c, d, e, f) }
      .foreach { case (x, y) =>
        println(s"${x.setScale(3, BigDecimal.RoundingMode.HALF_UP)} ${y.setScale(3, BigDecimal.RoundingMode.HALF_UP)}")
      }
  }

  def solve(a: BigDecimal, b: BigDecimal, c: BigDecimal, d: BigDecimal, e: BigDecimal, f: BigDecimal): (BigDecimal, BigDecimal) = {
    val x = (e * c - b * f) / (a * e - b * d)
    val y = (-d * c + a * f) / (a * e - b * d)
    (x, y)
  }

}

Measured memory_bytes: 44088
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <functional>
#include <queue>

using namespace std;
typedef long long ll;
class Edge
{
	public:
	int cost;
	int from;
	int to;

	Edge(int n,int c)
	{
		to=n;
		cost=c;
	}

	Edge(int f,int t,int c)
	{
		from=f;
		to=t;
		cost=c;
	}
};
class Cycle
{
	public:
	int size;
	vector<int> node;
	Cycle(){}
	Cycle(int s,vector<int> n)
	{
		size=s;node=n;
	}
	bool operator<(Cycle &rhs)
	{
		return size<rhs.size;
	}
};
typedef vector<vector<Edge>> Graph;
Graph g;
vector<Cycle> res;
void bfs(int now)
{
	deque<Cycle> que;
	que.push_back(Cycle(1,vector<int>(1,now)));
	Cycle c;
	int cnt=0;
	bool f=false;
	while(!que.empty())
	{
		cnt++;
		if(cnt>1000)
			break;
		c=que[0];
		que.pop_front();
		//cerr<<now<<" "<<c.size<<" "<<c.node[c.node.size()-1]<<endl;
		vector<int> r=c.node;
		for(int i=0;i<g[c.node[c.node.size()-1]].size();i++)
		{
			Edge e=g[c.node[c.node.size()-1]][i];
			if(e.to==c.node[0])
			{
				f=true;
				break;
			}
			r=c.node;
			r.push_back(e.to);
			que.push_back(Cycle(c.size+1,r));
		}
		if(f)
			break;
	}
	if(f)
		res.push_back(c);
	return;
}
int main()
{
	int n,m;
	cin>>n>>m;
	g=Graph(n);
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(Edge(b,1));
	}
	//各頂点を始点とする最小サイクルを探す
	for(int i=0;i<n;i++)
	{
		bfs(i);
	}
	if(res.size()==0)
	{
		cout<<-1<<endl;
		return 0;
	}
	sort(res.begin(),res.end());
	cout<<res[0].size<<endl;
	for(int i=0;i<res[0].node.size();i++)
		cout<<res[0].node[i]+1<<endl;
	return 0;
}

Measured memory_bytes: 4224
/*
by.YXH_XianYu
   2018.9.1
 */
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LLI long long
#define DBL double
#define CHR char
#define BOL bool
#define REG register
#define rep(i, j, k) for(int i = j, lim = k; i <= lim; i++)
#define req(i, j, k) for(int i = j, lim = k; i >= lim; i--)
#define MXN 100005

int n, k;

LLI Pow(LLI a, LLI n) {
	LLI res = 1;
	while(n) {if(n & 1) res *= a; a *= a; n /= 2;}
	return res;
}

LLI Magic(LLI n) {
	REG LLI res = 0, t = 0, i;
	for(i = 1; i <= n; i ++) {
		if(i & 1) t += i / 2;
		res += 6 * t + 1;
	}
	return res;
}

int main() {
	//freopen("TEMPLATE.in", "r", stdin);
	//freopen("TEMPLATE.out", "w", stdout);
	REG LLI ans = 0;

	scanf("%d %d", &n, &k);
	if(k & 1) {
		if(n < k) {printf("0\n"); return 0;}
		n -= k;
		n = n / k + 1;
		ans = Pow(n, 3);
		printf("%lld\n", ans);
	}
	else {
		k /= 2;
		if(n < k) {printf("0\n"); return 0;}
		n -= k;
		n = n / k + 1;
		ans = Magic(n);
		printf("%lld\n", ans);
	}
	


	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author SimplyDivine
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            long k = in.nextLong();
            long a[] = new long[100000 + 1];
            for (int i = 0; i < n; i++) {
                a[in.nextInt()] += in.nextLong();
            }
            long cnt = 0;
            for (int i = 0; i < 100001; i++) {
                cnt += a[i];
                if (cnt >= k) {
                    out.println(i);
                    break;
                }
            }
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream i) {
            br = new BufferedReader(new
                    InputStreamReader(i));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 45228
num, time_lim = list(map(int, input().split()))
ans = 'TLE'
for i in range(num):
  cost, time_data = list(map(int, input().split()))
  if time_data > time_lim:
    continue
  if ans == 'TLE':
    ans = cost
  if ans > cost:
    ans = cost
print(ans)

Measured memory_bytes: 3060
n, k = gets.split.map(&:to_i)
s = gets.chomp.chars
cnt = 0
n.pred.times do |i|
  cnt += 1 if s[i] == s[i + 1]
end
if cnt + 2 * k > n - 1
  puts n - 1
else
  puts cnt + 2 * k
end

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

int main()
{
    int n;
    cin >> n;
    while(n)
    {
        n--;
        string X,Y;
        int i=0,j=0;
        cin >> X;
        cin >> Y;
        int L[1001][1001];
        for(i=0;i<1001;i++)
            for(j=0;j<1001;j++)
               L[i][j]=0;
        for(i=1;i<=X.size();i++)
            for(j=1;j<=Y.size();j++)
            {
                if(X[i-1]==Y[j-1])
                    L[i][j]=1+L[i-1][j-1];
                else    L[i][j]=max(L[i][j-1],L[i-1][j]);
            }
        cout << L[X.size()][Y.size()] << endl;
    }
    return 0;
}


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

a, b = [], []
for i in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)

#%%
# n, h, w = [3, 5, 2]

# a = [10, 5, 2]
# b = [3, 2, 5]


#%%
ans = 0
for i in range(n):
    
    # print(a[i], h, b[i], w)
    if a[i] >= h:
        if b[i] >= w:
            ans += 1
print(ans)
#%%
w


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
string a[101];int n,i,l;

int main(){
  cin >>n>>l;
  for(i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n);
  for(i=0;i<n;i++)
    cout<<a[i];
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bitset>
using namespace std;
int main() {
  long long a,b;
  cin >> a >> b;
  bitset<32> ba(a),bb(b);
  cout << (ba&bb) << endl;
  cout << (ba|bb) << endl;
  cout << (ba^bb) << endl;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl

bool ok(string s1,string s2){
	if(s1.size()!=s2.size())return false;
	FOR(i,0,s1.size()){
		if(s1[i]=='?' || s2[i]=='?')continue;
		if(s1[i]!=s2[i])return false;
	}
	return true;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string sd,t;
	cin >> sd >> t;
	FORR(i,0,sd.size()-t.size()+1){
		if(ok( sd.substr(i,t.size()),t)) {
			FOR(j,0,i){
				if(sd[j]=='?')cout<<'a';
				else cout << sd[j];
			}
			cout << t;
			FOR(j,i+t.size(),sd.size()){
				if(sd[j]=='?')cout<<'a';
				else cout << sd[j];
			}
          	cout << endl;
			return 0;
		}
	}
	cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

void debug_out() {};
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1
#endif

struct C1 {
    vector<ll> A_{};
    vector<ll> B_{};
    vector<ll> C_{};
    ll N_{};
    explicit C1(vector<ll> A, vector<ll> B, vector<ll> C) : A_(move(A)), B_(move(B)), C_(move(C)), N_(A_.size()){}
    ll resolve() {
        ll sum = 0;
        for(auto b : B_) {
            sum += b;
        }
        for(ll i=0; i < N_-1; ++i) {
            if (A_[i] + 1 == A_[i+1]) {
                sum += C_[A_[i]-1];
            }
        }
        return sum;
    }
};

int main() {
    ll N;
    cin >> N ;
    vector<ll> A{};
    vector<ll> B{};
    vector<ll> C{};
    for (int i=0; i < N; ++i) {
        ll x;
        cin >> x;
        A.emplace_back(x);
    }
    for (int i=0; i < N; ++i) {
        ll x;
        cin >> x;
        B.emplace_back(x);
    }
    for (int i=0; i < N-1; ++i) {
        ll x;
        cin >> x;
        C.emplace_back(x);
    }
    C1 c{move(A), move(B), move(C)};
    cout << c.resolve() << endl;
    debug(c.resolve());
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.begin(), v.end(),greater<int>());
#define INF 999999999
#define MOD 1000000007
#define M_PI 3.14159265358979323846
#define ALL(X) (X).begin(),(X).end()

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<int> A;

void input(){
  fast_io();
  #ifdef __LOCAL
    fs::path p = __FILE__;
    fs::path input,output;
    input = output = p.parent_path();
    input += string("/input/") + string(p.stem()) + string(".txt");
    output += string("/output/") + string(p.stem()) + string(".txt");
    freopen(input.c_str(), "r", stdin);
    freopen(output.c_str(), "w", stdout);
  #endif
  cin >> N;
  A = fetch_vec<int>(N);
}


int solve(){
  vector<int> R(N,0);
  for (int i = 0; i < N; i++)
  {
    R[0] += A[i]*pow(-1,i);
  }
  for (int i = 0; i < N-1; i++)
  {
    R[i+1] = 2*A[i]-R[i];
  }
  cout << R << endl;
  
  return 0;
}

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


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

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

  int n,a,b,c; cin >> n >> a >> b >> c;
  vector<int> l(n);
  for(int i = 0; i < n; i++){
    cin >> l[i];
  }
  sort(l.begin(),l.end());

  int ans = 1LL << 60;
  do{
    for(int i = 0; i < n; i++){
      for(int j = i+1; j < n; j++){
        for(int k = j+1; k < n; k++){
          int cost = 0,A = 0,B = 0,C = 0;

          cost += i*10 + (j-i-1)*10 + (k-j-1)*10;

          for(int p = 0; p <= i; p++) A += l[p];
          for(int p = i+1; p <= j; p++) B += l[p];
          for(int p = j+1; p <= k; p++) C += l[p];

          cost += abs(A - a) + abs(B - b) + abs(C - c);

          ans = min(ans,cost);
        }
      }
    }
  }while(next_permutation(l.begin(),l.end()));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


ll gcd(ll a, ll b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b % a, a);
}

int main(void) {
    int n, i, x, y;
    ll a, b, kgcd, bi[200003], ks, lh, ans;
    map<Pl, int> sd;
    map<Pl, bool> u;

    x = y = 0;
    lh = 0;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%lld%lld", &a, &b);
        if (a == 0 || b == 0) {
            if (a == 0 && b == 0) lh++;
            else if (a == 0) y++;
            else if (b == 0) x++;
        }
        else {
            kgcd = gcd(abs(a), abs(b));
            a /= kgcd;
            b /= kgcd;
            if (a < 0) {
                a = -a;
                b = -b;
            }
            sd[Pl(a, b)]++;
            if (-b < 0) {
                a = -a;
                b = -b;
            }
            sd[Pl(-b, a)] += 0;
        }
    }

    bi[0] = 1;
    for (i = 1; i <= n; i++) {
        bi[i] = bi[i - 1] * 2 % mod;
    }

    ans = (bi[x] + bi[y] - 1) % mod;

    for (auto& mp : sd) {
        Pl ml, tu = Pl(-mp.first.second, mp.first.first);
        ml = mp.first;
        if (tu.first < 0) {
            tu.first = -tu.first;
            tu.second = -tu.second;
        }
        if (u[ml]) {
            continue;
        }
        u[ml] = u[tu] = true;
        ks = (bi[mp.second] + bi[sd[tu]] - 1) % mod;
        ans = ans * ks % mod;
    }

    ans = (ans + lh + mod - 1) % mod;

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 55320
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	vector<int> cnt(9, 0);
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		int tmp = min(a / 400, 8);
		cnt[tmp]++;
	}
	
	int sum = 0;
	for(int i = 0; i < 8; i++){
		if(cnt[i] > 0) sum++;
	}

	if(cnt[8] == n){
		cout << 1 << " " << n << endl;
	}else{
		cout << sum << " " << sum + cnt[8] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<cassert>
#include<sstream>
using namespace std;

string stest;

void test(int N,int K){  
for(int i=N;i<N+K;i++)
    cout << stest[i];
cout << endl;
}
string itos(int a){stringstream ss; ss << a; return ss.str();}
long long d[] = {0,10,90,900,9000,90000,900000,9000000,90000000,900000000,9000000000,90000000000};
int getD(int g){return !g?1:(int)log10(g)+1;}


void print(int now,int K,int dif)
{
  string s;
  for(int i=now;s.size() <= K+dif;i++)
    s += itos(i);
  
  for(int i=dif;i<dif+K;i++)
    cout << s[i];   
  cout << endl;
}

void DO(int N,int K)
{
  long long total = 0;
  int now = 0;
  for(int kt = getD(now);total+kt < N;kt = getD(now))
    {
      if(kt <= 10 && total+kt*d[kt] <= N)
	{
	  total += kt*d[kt];
	  now += d[kt];
	  continue;
	}
      int use = (N-total)/kt;
      if(use > d[kt])
	use = d[kt];
      total += kt*use;
      now+=use;
    }
 
  print(now,K,N-total);
}



int main()
{
  /*
  for(int i=0;i<=10000;i++)
    stest += itos(i);
  */
  int N,K;
  while(cin >> N >> K,N|K)
        DO(N,K);
  
 
  return 0;
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int N, M;
    cin >> N >> M;
    if (N == 0 && M == 0){
      break;
    }
    vector<vector<pair<int, int>>> R(M);
    vector<int> cnt(M, 0);
    int r;
    cin >> r;
    for (int i = 0; i < r; i++){
      int t, n, m, s;
      cin >> t >> n >> m >> s;
      m--;
      if (s == 1){
        if (cnt[m] == 0){
          R[m].push_back(make_pair(t, -1));
        }
        cnt[m]++;
      }
      if (s == 0){
        cnt[m]--;
        if (cnt[m] == 0){
          R[m].back().second = t;
        }
      }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++){
      int ts, te, m;
      cin >> ts >> te >> m;
      m--;
      int ans = 0;
      int cnt = R[m].size();
      for (int j = 0; j < cnt; j++){
        int s = R[m][j].first;
        int e = R[m][j].second;
        ans += max(min(te, e) - max(ts, s), 0);
      }
      cout << ans << endl;
    }
  }
}


Measured memory_bytes: 3264
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;

/**
 * Created by nakatsukatakahiro on 2017/06/11.
 */
class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        int sum = 0;
        ArrayList<Integer> a = new ArrayList<>();

        for (int i = 0; i < N; i++) {
            int tmp = scanner.nextInt();
            sum += tmp;
            if (tmp % 10 != 0) {
                a.add(tmp);
            }
        }
        a.sort(Comparator.naturalOrder());

        int i = 0;
        while (sum % 10 == 0 && i < a.size()) {
            sum -= a.get(i);
            i++;
        }
        if (sum % 10 == 0) {
            sum = 0;
        }

        System.out.println(sum);
    }
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> left(N + 1);
    vector<ll> right(N + 1);
    for (ll i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    if (N == 2) {
        cout << max(A.at(0),A.at(1)) << endl;
        return 0;
    }
    for (ll i = 0; i <= N; i++) {
        if (i == 0) {
            left.at(i) = A.at(i);
        }
        else {
            left.at(i) = __gcd(A.at(i - 1),left.at(i - 1));
        }
    }
    for (ll i = N; i >= 0; i--) {
        if (i == N) {
            right.at(i) = A.at(i - 1);
        }
        else {
            right.at(i) = __gcd(A.at(i),right.at(i + 1));
        }
    }
    ll ans;
    for (ll i = 0; i < N; i++) {
        if (i == 0) {
            ans = __gcd(left.at(i),right.at(i + 1));
        }
        else {
            ans = max(ans,__gcd(left.at(i),right.at(i + 1)));
        }
    }
    ll first = A.at(1);
    for (ll i = 1; i < N; i++) {
        first = __gcd(first,A.at(i));
    }
    ll fin = A.at(0);
    for (int i = 0; i < N - 1; i++) {
        fin = __gcd(fin,A.at(i));
    }
    cout << max(ans,max(first,fin)) << endl;
    /*for (int i = 0; i <= N; i++) {
        cout << left.at(i) << ' ' << right.at(i) << endl;
    }*/
}

Measured memory_bytes: 5636
#include<bits/stdc++.h>
using namespace std;
 
int main(){

    int x,a,b;
    cin >> x >> a >> b;

    if(b - a > x){
        cout << "dangerous" << endl;
    }else if (b - a >0){
        cout << "safe" << endl;
    }else{
        cout << "delicious" << endl;
    }


}

Measured memory_bytes: 256