akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;

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

int H, W, K;
vector<vector<char> > G;
pii S;
vector<vector<int> > dist;

int main() {
    scanf("%d %d %d", &H, &W, &K);
    G = vector<vector<char> >(H, vector<char>(W));
    for(int i = 0; i < H; i++) {
        scanf("\n");
        for(int j = 0; j < W; j++) {
            scanf("%c", &G[i][j]);
            if(G[i][j] == 'S') S = pii(i, j);
        }
    }
    queue<pii> q;
    dist = vector<vector<int> >(H, vector<int>(W, -1));
    q.push(S);
    dist[S.first][S.second] = 0;
    while(!q.empty()) {
        pii u = q.front(); q.pop();
        int y = u.first;
        int x = u.second;
        if(dist[y][x] == K) break;
        for(int i = 0; i < 4; i++) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if(ny < 0 || H <= ny) continue;
            if(nx < 0 || W <= nx) continue;
            if(G[ny][nx] == '#') continue;
            if(dist[ny][nx] != -1) continue;
            q.push(pii(ny, nx));
            dist[ny][nx] = dist[y][x] + 1;
        }
    }
    int ans = 1e9;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(dist[i][j] != -1) {
                int d = min(min(i, H - 1 - i), min(j, W - 1 - j));
                ans = min(ans, 1 + (d + K - 1) / K);
            }
        }
    }
    printf("%d", ans);
}


Measured memory_bytes: 3456
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<list>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<numeric>
using namespace std;

using ll = int64_t;

/// <summary>
/// 単純なcoutの時に使う
/// </summary>
#define co(a) cout<<a<<endl


/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define rep(i,a) for(ll i=0; i<a; ++i)

/// <summary>
/// 迷路等で使う方向のベクトル
/// </summary>
const vector<ll> dx = { 0, 1, 0, -1 }, dy = { 1, 0, -1, 0 };

/// <summary>
/// デバッグ時に使う
/// </summary>
#define DEBUG(x)     std::cout << #x << " : " << x << "\n"


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

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

	string S;
	cin >> S;

	S[3] = '8';
	
	cout << S << endl;
}

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


using namespace std;

int main(){
  int n;
  string s;
  cin >> n >>s;
  for(int i = 0; i < s.size()+1; i++){
    for(int j = 0; j < n; j++) {
      if(s[i] == 'Z') {
        s[i] = 'A';
      } else {
        s[i] = s[i] + 1;
      }
    }
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n, K;
    cin >> n >> K;

    ll res = 0;
    for (ll b = K + 1; b <= n; b++) {
        res += (b - K) * (n / b);
        res += max(0LL, 1 + (n % b) - K);
        if (K == 0) {
            res--; // a=0を除く
        }
    }

    put(res);
}
signed main(){ Main();return 0;}

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

typedef long long ll;

template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }

int main(int argc, char* argv[])
{
  std::string s;
  std::cin >> s;

  ll ans = 0;
  ll max_b = (ll)s.size() - 1;
  for (int i = (ll)s.size() - 1; i >= 0; i--) {
    if (s[i] == 'B') {
      ans += max_b - i;
      max_b--;
    }
  }

  print(ans);
  return 0;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, m, k, u, v;
string s, t;

// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n>>m;
	ll outlet = 1;
	ll ans = 0;
	while(outlet < m) {
		--outlet;
		outlet += n;
		++ans;
	}
	cout<<ans;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))
#define LLONG_MAX numeric_limits<long long>::max()
#define INT_MAX numeric_limits<int>::max()

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vs>		vvs;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " " << p.second << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}


template <typename T>
void vecOutPadding(vector<T>& vec, string pad = " ") {
	for (const T& elem : vec)
		cout << elem << pad;
}

template <typename T>
void matOut(vector<vector<T>>& mat) {
	for (const auto& row : mat) {
		for (const T& col : row)
			cout << col << " ";
		cout << endl;
	}
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	int H, W;
	cin >> H >> W;
	vvs S(H, vs(W));
	cin >> S;

	for (int i = 0; i < H; i++)
		for (int j = 0; j < W; j++)
			if (S[i][j] == "snuke") {
				cout << char('A' + j) << i + 1 << endl;
			}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];
int id[30];

bool ch[101];
bool chk[1010];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;
    cin>>S;

    for(int i=0;i<10;i++)
        id[i] = -1;

    for(int i=0;i<n;i++){
        cur = S[i]-'0';
        id[cur] = i;
    }

    for(int i=0;i<n;i++){
        cur = S[i]-'0';

        if(id[cur]==i){
            for(int j=0;j<100;j++){
                if(chk[j]){
                    cnt++;
                }
            }
        }

        for(int j=0;j<10;j++){
            if(ch[j]){
                chk[j*10+cur] = true;
            }
        }

        ch[cur] = true;
    }

    cout<<cnt<<"\n";


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	int a,b,c,d;
	C4(a,b,c,d);
	P(min(a,b)+min(c,d));
	ret 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2305>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
typedef long double ld;
ld solve(){
    ld res = 0;
    int N; cin >> N;
    vector<ll> a(N); for(auto& in:a) cin >> in;
    ll MAXA = *a.rbegin();
    vector<vector<ld>> dp(N+1,vector<ld>(2*MAXA+1,INF));
    vector<vector<ll>> Next(2*MAXA+1);
    for(int i = 1; i <= 2*MAXA;i++){
        for(int j = i; j <= 2*MAXA;j+=i){
            Next[i].push_back(j);
        }
    }
    for(int i = 1; i <= 2*MAXA;i++) dp[0][i] = 0; //abs(i-a[0])/(ld)a[0];
    for(int i = 0; i < N;i++){
        for(int j = 1; j <= 2*MAXA;j++){
            for(int k = 0; k < Next[j].size(); k++){
                dp[i+1][Next[j][k]] = min(dp[i+1][Next[j][k]],
                                          max(dp[i][j],abs(Next[j][k]-a[i])/(ld)a[i]));
            }
        }
    }
    res = *min_element(dp[N].begin(), dp[N].end());
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12) << solve() << endl;
    return 0;
}



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

int main() {
  string s;
  cin >> s;
  s.pop_back();
  while(s.size() >= 1){
    if(s.size() == 1){
      cout << 1 << endl;
      return 0;
    }
    else if(s.size()%2 == 1){
      s.pop_back();
      continue;
    }
    int l = s.size();
    string a = s.substr(0,l/2),b = s.substr(l/2);
    if(a == b){
      cout << s.size() << endl;
      return 0;
    }
    s.pop_back();
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#include <numeric>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define pb push_back
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<ll> > mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;
const int dx[9] = {-1, 0, 0, 1, -1, -1, 1, 1, 0};
const int dy[9] = {0, -1, 1, 0, -1, 1, -1, 1, 0};

string S, T;
 
signed main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> S >> T;

  REP(i,S.size()) {
    if (S == T) {
      cout << "Yes" << endl;
      return 0;
    }
    S = S[S.size()-1] + S.substr(0, S.size() - 1);
  }

  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mod 1000000007
#define null NULL
#define test cout<<"#"
#define maX 1000000000
 
ll ans[100001][3];

void solve(ll ar[][3], ll n)
{	
	ans[0][0] = ar[0][0];
	ans[0][1] = ar[0][1];
	ans[0][2] = ar[0][2];
	for(ll x = 1; x < n; x++)
	{
		ans[x][0] = max(ans[x-1][1], ans[x-1][2])+ar[x][0];
		ans[x][1] = max(ans[x-1][0], ans[x-1][2])+ar[x][1];
		ans[x][2] = max(ans[x-1][0], ans[x-1][1])+ar[x][2];
	}
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	memset(ans, 0, sizeof(ans));
    ll n;
	cin>>n;
    ll ar[n][3];
    for(ll x = 0; x < n; x++)
	{
		for(ll y = 0; y < 3; y++)
		{
			cin>>ar[x][y];
		}
	}
	solve(ar, n);
	cout<<max(ans[n-1][0], max(ans[n-1][1], ans[n-1][2]));
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	int N, K;
	cin >> N >> K;
	vector<ll> V(N);
	for(int i = 0; i < N; i ++){
		cin >> V[i];
	}

	ll ans = 0;
	//iは取る個数
	for(int i = 0; i <= min(N, K); i ++){
		//l, rはそれぞれ左と右からとる数
		for(int l = 0; l <= i; l ++){
			int r = i - l;
			vector<int> have;
			for(int j = 0; j < l; j ++){
				have.pb(V[j]);
			}
			for(int j = 0; j < r; j ++){
				have.pb(V[N - 1 - j]);
			}
			sort(all(have));
			for(int j = 0; j < K - i; j ++){
				if(j < have.size() && have[j] < 0){
					have[j] = 0;
				}
				else break;
			}
			ll sum = 0;
			for(int j = 0; j < have.size(); j ++){
				sum += have[j];
			}
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
from math import cos, radians, sqrt

a, b, h, m = [int(i) for i in sys.stdin.readline().split()]
theta_m = 360 * (m / 60)
theta_h = 30 * (m / 60) + 30 * h
diff_theta = min(abs(360 - abs(theta_h - theta_m)), abs(theta_h - theta_m))
c = sqrt(a**2 + b**2 - 2 * a * b * cos(radians(diff_theta)))
print(c)

Measured memory_bytes: 9448
#!/usr/bin/perl

my ($n) = map {$_ - 0} split(/\s+/o,<STDIN>);

my @d = (+[0,0,0]);
for(my $i=0;$i<$n;$i++){
  my @a = map {$_ - 0} split(/\s+/o,<STDIN>);
  push(@d,\@a);
}

for(my $i=1;$i<=$n;$i++){
  my $t1 = $d[$i-1]->[0];
  my $x1 = $d[$i-1]->[1];
  my $y1 = $d[$i-1]->[2];
  my $t2 = $d[$i]->[0];
  my $x2 = $d[$i]->[1];
  my $y2 = $d[$i]->[2];
  
  my $d_t = $t2 - $t1;
  my $d_x = $x2 - $x1;
  my $d_y = $y2 - $y1;
  
  $d_x = - $d_x if $d_x < 0;
  $d_y = - $d_y if $d_y < 0;
  my $d_xy = $d_x + $d_y;
  
  if( $d_xy > $d_t ){
    print "No\n";
    exit(0);
  }
  if( ( $d_xy & 1 ) != ( $d_t & 1 ) ){
    print "No\n";
    exit(0);
  }
}
print "Yes\n";

exit(0);



Measured memory_bytes: 21760
def primes(n):
  is_prime = [True] * (n + 1)
  is_prime[0] = False
  is_prime[1] = False
  for i in range(2, int(n**0.5) + 1):
    if not is_prime[i]:
      continue
    for j in range(i * 2, n + 1, i):
      is_prime[j] = False
  return [i for i in range(n + 1) if is_prime[i]]
n=int(input())
P=primes(55555)
Ans=[]
i=0
while len(Ans)<n:
  if P[i]%5==1:
    Ans.append(P[i])
  i+=1
print(*Ans)

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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i, m, n) for(int i = (int)m; i < (int)n; i++)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;

/*FUNCs=================================================*/



/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int n; cin >> n;
    vll a(n); rep(i,n) cin >> a[i];

    int condition = 0;
    int counting = 1;  //最後の部分列の分があるのでcounting=1
    for(int i = 0; i < n-1; i++){
        if(condition == 0){
            if(a[i] < a[i+1]) condition = 1;
            else if(a[i] > a[i+1]) condition = -1;

        }else if(condition == 1){
            if(a[i] > a[i+1]){
                condition = 0;
                counting++;
            }
        }else if(condition == -1){
            if(a[i] < a[i+1]){
                condition = 0;
                counting++;
            }
        }
    }
    cout << counting << '\n';
}

Measured memory_bytes: 1024
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
ans=0
ab=[]
for i in range(n):
  a=list(map(int,input().split()))
  for j in range(m):
    ab+=[a[j]*b[j]]
ab=[sum(ab[k:k+m]) for k in range(0,len(ab),m)]
for l in range(n):
  if ab[l]+c>0:
    ans+=1
  else:
    pass
print(ans)

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

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

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

    if(abs(c-a)<=d || (abs(b-a)<=d && abs(c-b)<=d)) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY
N=gets.to_i
a=get_i
odd=[]
even=[]
N.times do|i|
  if (i+1).odd?
    odd.push(a[i])
  else
    even.push(a[i])
  end
end
odd_sum=odd.inject(:+)
even_sum=even.inject(:+)
ans=array(N,0)
ans[0]=odd_sum-even_sum
1.upto(N-1) do|i|
    ans[i]=2*a[i-1]-ans[i-1]
end
puts ans.join(" ")

Measured memory_bytes: 16004
#include <bits/stdc++.h>
typedef long long int ll;

using namespace std;
const double PI = 3.14159265358979323846;


int main()
{

    ll X,K,D;


    cin >> X >> K >> D;


    ll n= abs(X)/D;


    if(n>=K){


        cout << abs(X) -K*D << endl;
        return 0;
    }


    ll r_n = K-n;


    if(r_n%2==0){

        cout << abs(X) -D*n << endl;
    }
    else{

        cout<< abs(abs(X) -D*(n+1)) << endl;

    }


    return 0;






}

Measured memory_bytes: 3616
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[110];
int main(){
	int n,k,i,s;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)scanf("%d",a+i);
	sort(a+1,a+n+1);
	s=0;
	for(i=1;i<=n;i++){
		if(a[i]<=k){
			k-=a[i];
			s++;
		}
	}
	if(s==n&&k)s--;
	printf("%d",s);
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

template <typename T> inline void voutput(T &v){
    rep(i, v.size()){
        if (i) cout << " " << v[i];
        else cout << v[i];
    }
    cout << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<int> P(N);
    rep(i, N) cin >> P[i];
    vector<int> A(N), B(N);
    vector<int> S(N);
    rep(i, N) A[i] = i;
    rep(i, N) B[P[i] - 1] = i - A[P[i] - 1], S[P[i] - 1] = i;
    
    rep(i, 1, N){
        if(A[i] <= A[i - 1]) A[i] = A[i - 1] + 1, B[i] = S[i] - A[i];
        if(B[i] >= B[i - 1]) {
            int diff = B[i] - B[i - 1] + 1;
            B[i] = B[i] - diff;
            A[i] = A[i] + diff;
        }
    }
    
    int m = 1;
    rep(i, N) m = min(m, A[i]), m = min(m, B[i]);
    if(m < 1){
        int diff = 1 - m;
        rep(i, N) A[i] += diff, B[i] += diff;
    }
    
    voutput(A);
    voutput(B);
    return 0;
}

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

using namespace std;

int main(){
    int n, a;
    cin>>n;
    int cnt=0;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a!=i+1){
            cnt++;
        }
    }
    if(cnt<=2){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int n;
    int l[10]={0};
    int i;
    int sum = 0, max = 0;
    scanf("%d",&n);
    for(i=0; i < n; i++){
        scanf("%d",&l[i]);
    }
    for(i=0;i < n;i++){
        if (l[i] > max)
        {
            max = l[i];
        }
        sum += l[i];
    }
    sum -= max;
    if(sum <= max){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 128
/**
            C++14 (GCC 5.4.1)
**/
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;

int main() {
    long double L;
    cin >> L;

    cout << std::fixed <<setprecision(10) <<pow(L / 3, 3) << endl;
}

Measured memory_bytes: 256
/*	MASTER HAS FAILED MORE TIMES
	THAN BEGINNER HAS EVER TRIED
*/

#include <bits/stdc++.h>

using namespace std;

#define endl             '\n'
#define all(a)           a.begin(), a.end()
#define mem(a, n)        memset(a, n, sizeof(a))
#define Unique(n)        (n).erase(unique(all(n)), (n).end())
#define NumofDigits(n)   ((long long)log10(n)+1)
#define repeat(i, a, n)  for(int i=a; i<n; i++)
#define isPowerOfTwo(n)  (n && !(n & (n - 1)))

typedef long long ll;
typedef long double ld;

int sieve(int n);
unsigned long long pow(long long base, long long power);
long long gcd(long long a, long long b){ return a%b ? gcd(b, a%b) : b; }
long long lcm(long long a, long long b){ return a*b/gcd(a, b); }

void quicken(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
void file(){
    #ifdef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif /*ONLINE_JUDGE*/
}

int main(){
    quicken();

    ll n, num=0; cin >> n;
    string arr[n];

    map<string, int> mp;
    repeat(i, 0, n){
        cin >> arr[i];
        sort(all(arr[i]));
        mp[arr[i]]++;
    }


    for(auto it:mp){
        pair<string, ll> p = it;
        num += p.second*(p.second-1)/2;
    }
    cout << num;

    return 0;
}

unsigned long long pow(long long base, long long power){ /// mod?
    if(power==0) return 1;
    if(power==1) return base;

    unsigned long long ans = pow(base, power/2); /// mod?
    ans *= ans; /// ((ans%mod)*(ans%mod))%mod;

    if(power&1) return ans*base; /// ((ans%mod)*(base%mod))%mod;
    return ans;
}

int sieve(int n){
    int c = 0;
    vector<bool> isPrime(n+1, true);
    isPrime[0] = isPrime[1] = 0;

    for(long long i=2; i*i<=n; i++)
        if(isPrime[i])
            for(long long j=i*2; j<=n; j+=i)
                isPrime[j] = 0;
    repeat(i, 0, n+1)
        if(isPrime[i]) c++;
    return c; /// primeCount [1:n]
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


void solve(){
	string s,t;
	cin >> s >> t;
	int cnt = 0;
	int n = s.length();
	forn(i,0,n){
		if(s[i]!=t[i])
			cnt++;
	}
	cout << cnt << endl;
}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	// int t;cin >> t;while(t--)
		solve();
}


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

const int mod = 1000000007;

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

  ll p = 0, q = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i < j && a[i] > a[j]) p++;
      if (a[i] > a[j]) q++;
    }
  }

  // cerr << p << " " << q << endl;
  ll x = (p * k) % mod;
  ll y = (k * (k - 1) / 2) % mod * q;
  ll ans = (x + y) % mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3560
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>


#ifdef _DEBUG
#define typeof(X) std::identity<decltype(X)>::type //C++0x (for vs2010)
#else
#define typeof(X) __typeof__(X) // for gcc
#endif

#define sz(a)  int((a).size())
#define FOREACH(it, c) for (typeof((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define FOR(i,count) for (int i = 0; i < (int)(count); i++)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
const int MODULO = 100000 ;
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef complex<double> Cd;

using namespace std;

int x,y,n,a[10],b[10];

void solve(){
	cin>>n;
	FOR(i,n) cin>>a[i]>>b[i];
	vector<Pii> ok;
	ok.push_back(Pii(x,y));
	FOR(i,n){
		vector<Pii> nxt;
		for(int j = -1; j <= 1; j++) for(int k = -1; k <= 1; k++){
			int nx = a[i]+j,ny = b[i]+k;
			if(0 <= nx && nx <= 9 && 0 <= ny && ny <= 9){
				FOR(l,sz(ok)){
					int dx = abs(ok[l].first - nx),dy = abs(ok[l].second - ny);
					if((dx == 2 || dy == 2) && dx + dy < 4){
						nxt.push_back(Pii(nx,ny));
						break;
					}
				}
			}
		}
		swap(ok,nxt);
	}
	if(ok.size() != 0){
		puts("OK");
	} else {
		puts("NA");
	}
}

int main()
{
	while(cin>>x>>y,(x||y)){
		solve();
	}

	return 0;
}

Measured memory_bytes: 1144
n = int(input())
pf = {}
mod = 10**9 + 7

for m in range(1, n + 1):
    for i in range(2, int(m**0.5) + 1):
        while not m % i:
            pf[i] = pf.get(i, 0) + 1
            m //= i
    if m > 1:
        if m in pf:
            pf[m] += 1
        else:
            pf[m] = 1

res = 1
for i, j in pf.items():
    res *= j + 1
print(res % mod)

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

#define MOD (1000000000+7)

long long fact( long long x )
{
	long long res = 1;
	while( x > 1 ) {
		res = res * x % MOD;
		x--;
	}
	return res;
}

int main()
{
	long long N, M;

	cin >> N >> M;

	if( abs( N - M ) > 1 ) {
		cout << 0 << endl;
	}
	else if( ( N + M ) % 2 ) {
		cout << fact( N ) * fact( M ) % MOD << endl;
	}
	else {
		long long tmp = fact( N ) * fact( M ) % MOD;
		cout << 2 * tmp % MOD << endl;
	}

	return 0;
}


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

int main() {
  int n; cin >>n;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  int kotae=0;
  sort(a.begin(),a.end());
  int sum=0;
  map<int,int>mp;
  for(int x:a){
    if(mp.count(x))mp.at(x)++;
    else mp[x]=1;
  }
  auto begin=mp.begin(),end=mp.end();
  for(auto iter=begin;iter!=end;iter++){
    sum=iter->second;
    if(mp.count(iter->first-1))sum+=mp.at(iter->first-1);
    if(mp.count(iter->first+1))sum+=mp.at(iter->first+1);
    kotae=max(kotae,sum);
  }
  cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
        cout << it << " ";        \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
#define deb3a(v)                               \
    cout << #v << "-->" << endl;               \
    for (auto it : v)                          \
    {                                          \
        cout << it.fi << " " << it.se << endl; \
    }
#define mod 1000000007
#define so(v) sort(v.begin(), v.end())
#define fi first
#define se second
#define db1(x) cout << #x << "=" << x << endl
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
int power(int x, unsigned int y, int p)
{
    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;
}
int mI(int a, int m)
{
    return power(a, m - 2, m);
}
vector<vector<int>> dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

#define MAXN 10000001
#define double long double



void solve()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = max({a * c, a * d, b * c, b * d});
    cout << ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    srand(time(0));

    // FILE *fin = freopen("ip.txt","r",stdin);
    // FILE *fout = freopen("op.txt","w",stdout);
    int t = 1, nn = 1;
    //cin >> t;
    while (t--)
    {
        // cout << "Case #" << nn << ":"
        //      << " ";
        // nn++;
        
        solve();
    }
}

Measured memory_bytes: 3652
import java.util.*;

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

    String s = sc.next();

    int n = s.length();
    char[] a = new char[n];
    a = s.toCharArray();

    for (int i = 0; i < n - 1; i++) {
      if (a[i] == a[i+1]) {
        System.out.println((i + 1) + " " + (i + 2));
        return;
      }
      if (i != n - 2 && a[i] == a[i+2]){
        System.out.println((i + 1) + " " + (i + 3));
        return;
      }
    }
    
    System.out.println("-1 -1");
  }
}

Measured memory_bytes: 25912
#include <cstdio>
#include <vector>
#define rep(i,l,n) for(int i = l; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
    int n,q,ans = 0;
    scanf("%d",&n);
    vector<int> s(n);
    rep(i,0,n) scanf("%d",&s[i]);
    scanf("%d",&q);
    int t;
    rep(i,0,q) {
        scanf("%d",&t);
        rep(j,0,n) {
            if(s.at(j) == t) {
                ans++;
                break;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 2744
A,B=map(int,input().split())
X=A/0.08
Y=B/0.1
Z=max(X,Y)
if not int(Z*0.08) == A:
	Z=-1
if not int(Z*0.1) == B:
	Z=-1
if int(Z) == Z:
	print(int(Z))
else:
	print(int(Z)+1)

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

int main() {
    int n,x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i=0;i<n;i++) cin >> a[i];
    ll ans=max(0,a[0]-x);
    a[0]=min(x,a[0]);
    for (int i=1;i<n;i++) {
        if (a[i]+a[i-1]>x) {
            ans+=a[i]-(x-a[i-1]);
            a[i]=x-a[i-1];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
N = int(input())
H = list(map(int, input().split()))

 
for i in range(N-1, 1, -1):
    if H[i]-H[i-1] ==-1:
        H[i-1]-=1
    elif H[i]-H[i-1]>=0:
        continue
    else:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 63984
#include <stdio.h>
#include <stdlib.h>
static int n, as[100000], i, sum;
int cmp(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}
int main(void) {
    scanf("%d", &n);
    for (i = 0; i < n; ++i) {
        scanf("%d", as + i);
    }
    qsort(as, n, sizeof(int), cmp);
    for (i = 0; i < n - 1; ++i) {
        if (as[i] == as[i + 1])
            ++i;
        else
            ++sum;
    }
    if (i == n - 1)
        ++sum;
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	char s[11];
	scanf("%s",s);

	int ans = 999;
	for(int i=0;i+2<strlen(s);i++){
		int tmp = 0;
		tmp += (s[i]-'0')*100;
		tmp += (s[i+1]-'0')*10;
		tmp += (s[i+2]-'0')*1;
		if(ans>abs(753-tmp)){
			ans = abs(753-tmp);
		}
	}

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

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


int N;
string S;
stack<char> s;


string solve(){
	string front, back;
	rep(i, 0, N)
		if(!s.empty() && s.top() == '(' && S[i] == ')') s.pop();
		else s.push(S[i]);
	while(!s.empty()){
		char c = s.top();
		s.pop();
		if(c == '(') back.pb(')');
		else front.pb('(');
	}
	return front+S+back;
}


signed main(){
	cin >> N;
	cin >> S;

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <functional>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
string X; long long cnt = 0;
int main() {
	cin >> X;
	for (int i = 0; i < X.size(); i++)cnt += (X[i] - '0');
	long long V = stoll(X);
	if (V%cnt == 0)cout << "Yes" << endl; else cout << "No" << endl;
	return 0;
}

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

int sum_L(vector<int> a , int b){
  	int sum = 0;
  
  	for( int i = 0 ; i < b ; i++){
    	sum += a.at(i);
    } 
  	return sum;
}

int main() {
	int N,X;
  	cin >> N >> X;
  
  	vector<int> L(N+1);
  	for ( int i = 0 ; i < N+1 ; i++ ){
    	cin >> L.at(i);
    }
  
  	vector<int> D(N+1);
    D.at(0) = 0;
  	bool judge = false;
  	for( int i = 1 ; i < N+1 ; i++ ){
    	D.at(i) = sum_L(L,i);

      	if(D.at(i) > X ){
          judge = true;
          cout << i << endl;
          break;
        }  
    }
  	if(!judge)
      cout << N + 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
int32_t main(){
    SPEED;
    string s;
    cin >> s;
    int cnt = 0, ans = 0;
    for(char c: s){
        if(c == 'R') cnt++;
        else{
            ans = max(cnt, ans);
            cnt = 0;
        }
    }
    cout << max(ans, cnt) << endl;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
long p[10];
bool cm(const long l, const long r) {
	return p[l] > p[r];
}
int main() {
	long n, i, w, l, d, id[10], f = 0;
	string s[10];
	while (cin >> n) {
		if (n == 0)
			break;
		if (f > 0)
			cout << endl;
		f = 1;
		for (i = 0; i < n; i++)
			p[i] = 0;
		for (i = 0; i < n; i++) {
			cin >> s[i] >> w >> l >> d;
			p[i] += 3 * w + d;
			id[i] = i;
		}
		sort(id, id + n, cm);
		for (i = 0; i < n; i++) {
			cout << s[id[i]] << "," << p[id[i]] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
int main(){
    int lose=0;
    string input;
    cin >> input;
    for(int i=0; i<input.length(); i++){
        if(input.at(i)=='x') lose++;
    }
    if(lose>=8) cout << "NO";
    else cout << "YES";
}

Measured memory_bytes: 256
L = int(input())
N = len(str(bin(L)))-3
E = []

for n in range(N):
  E.append((n+1,n+2,0))
  E.append((n+1,n+2,2**(N-n-1)))
  
H = 2**N

for i,c in enumerate(str(bin((L)))[2:]):
    if c=="1" and i:
      E.append((1,i+1,H))
      H+=2**(N-i)

print(N+1,len(E))
for e in E:
  print(*e)


Measured memory_bytes: 9212
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


#define int ll

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void solve(){
    string s;
    cin >> s;
    deque<char> ans;
    for (int i = 0; i < s.length(); ++i) {
        ans.push_back(s[i]);
    }
    int query;
    cin >> query;
    int itring = 0;
    REP(tea, query) {
        int a;
        cin >> a;
        if (a == 1) {
            itring++;
            itring %= 2;
        }
        else {
            int b;
            string c;
            cin >> b >> c;
            b += itring;
            b %= 2;
            if (b % 2 == 0) {
                ans.push_back(c[0]);
            }
            else {
                ans.push_front(c[0]);
            }
        }
    }
    string answer;
    while (ans.empty() == false) {
        answer.push_back(ans.front());
        ans.pop_front();
    }
    if (itring % 2 == 1) {
        reverse(ALL(answer));
    }
    cout << answer << endl;
}

#undef int
int main() {
    init();
        solve();
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

ll N, A, B, K; 
const ll MOD = 998244353;

ll pow_mod(ll x, ll y)
{
    ll res=1;
    for (; y>0; y>>=1, x=(x*x) % MOD) {
        if (y&1) res = (res*x) % MOD;
    }
    return res;
}

vector<ll> fact, fact_inv;
void comb_init(int max_n)
{
    fact.resize(max_n + 1), fact_inv.resize(max_n + 1);
    fact[0] = fact_inv[0] = 1;
    for (int i=1; i <= max_n; i++) {
        fact[i] = fact[i-1] * i % MOD;
        fact_inv[i] = fact_inv[i-1] * pow_mod(i, MOD-2) % MOD;
    }
}

ll comb(int n, int r)
{
    if (n < r) return 0;
    return fact[n] * fact_inv[r] % MOD * fact_inv[n-r] % MOD;
}

int main()
{
    ios::sync_with_stdio(false);
    
    cin >> N >> A >> B >> K;
    comb_init(N);

    ll ans = 0;
    for (ll k=0; k<=N; k++) {
        ll tmp = 0;
        if ((K - k*A)%B == 0) {
            ll l = (K - k*A) / B;
            if (0 <= l && l <= N) {
                (ans += comb(N, k) % MOD * comb(N, l) % MOD) %= MOD;
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 4992
//code by lynmisakura.wish to be accepted
/****************************/
#include<bits/stdc++.h>
using namespace std;
/***************************/
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi;

const long long Mod = 998244353;
const long long mod = 1000000007;
const long long INF = 10000000000000;

#define itn int
#define pb push_back
#define mp make_pair
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
	
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
 
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

/***************************/
/***************************/

int main(void){
	int n,m;cin >> n >> m;
	ll ans = 0;
	int d = 1;
	vpi p;
	rep(i,n){
		int a,b;cin >> a >> b;
		b *= -1;
		p.pb(mp(a,b));
	}
	
	sort(all(p));
	int j = 0;
	
	priority_queue<int> q;
	while(d <= m){
		while(p[j].first <= d && j < n){
			pi b = p[j];
			int s = p[j].second * -1;
			q.push(s);
			j++;
		}
		if(!q.empty()){
			ans += q.top();
			q.pop();
		}
		d++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1908
# input
N = int(input())
page = []
p_append = page.append
for n in range(1, N + 1):
    S, P = map(str, input().split())
    p_append(
        {
            "number": n,
            "city": S,
            "point": int(P)
        }
    )

# check
page = sorted(page, key=lambda x: x["point"], reverse=True)
page = sorted(page, key=lambda x: x["city"])
for p in page:
    print(p["number"])

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

const int mod = 1e9 + 7;

using VB = vector<bool>;
using VVB = vector<VB>;
using VVVB = vector<VVB>;

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

	VVB a(n, VB(n, false));

	int tmp;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> tmp;
			a[i][j] = tmp;
		}
	}

	long long limit = 1LL << n;

	// 状態i(bitがたってる女性がペア成立済み)のときの数
	// 男性は __builtin_popcount(i)までみてる
	vector<long long> dp(limit, 0);

	dp[0] = 1;
	for (long long i = 0; i < limit - 1; i++) {
		int idx = __builtin_popcount(i);
		for (int j = 0; j < n; j++) {
			if (!a[idx][j]) {
				continue;
			}
			if ((i >> j) & 1) {
				continue;
			}

			long long to = (i | (1LL << j));
			dp[to] += dp[i];
			dp[to] %= mod;
		}
	}

	cout << dp[limit - 1] << endl;
	return 0;
}


Measured memory_bytes: 16640
#include "stdio.h"
long long int sum[100500],num[100500],ans=0,ma=0,plu[100500];
int n,k;
main()
{
    scanf("%d %d",&n,&k);
    sum[0]=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&num[i]);
        sum[i]=num[i]+sum[i-1];
        if(num[i]>0) plu[i]=num[i];
    }
    for(int i=1;i<=n;i++) plu[i]+=plu[i-1];
    for(int i=1;i<=n-k+1;i++)
    {
        long long int x=0;
        if(sum[i+k-1]-sum[i-1]>0) x+=(sum[i+k-1]-sum[i-1]);
        x+=plu[i-1];
        x+= (plu[n] - plu[i+k-1]);
        if(ans<x) ans=x;
    }
    printf("%lld",ans);

}



Measured memory_bytes: 2560
#include<iostream>

using namespace std;

int N, M, T[100], P[100], X[100], d[100], sum = 0;

int main(){
	
	cin >> N;
	for(int l = 0; l < N ; l++){
		cin >> T[l];
		sum += T[l];
	}
	cin >> M;
	for(int l = 0; l < M ; l++){
		cin >> P[l] >> X[l];
	}
	
	//cout << "AAA" << endl;
	
	for(int l = 0; l < M ; l++){
		cout << sum + X[l] - T[P[l]-1] << endl;
	}
	
	return 0;
	
}
	

Measured memory_bytes: 256