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

using namespace std;
using lli = int_fast64_t;
using ulli = unsigned long long;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = copy(x);cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;

constexpr lli plusScore = (lli)1e6;
constexpr size_t D = 365;
constexpr size_t asize = 26;

array<lli, asize> C;
array<array<lli,asize>,D> S;

lli calcScore(const vector<lli>& t) {
	vector<lli> last_open(asize, -1);
	lli score = 0;
	for (int i = 0; i < D; i++) {
		score += S[i][t[i] - 1];
		last_open[t[i] - 1] = i;
		for (int j = 0; j < asize; j++) {
			score -= C[j] * (i - last_open[j]);
		}
		//cout << score << "\n";
	}
	return score;
};

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

	int devNull;
	cin >> devNull;
	for (lli& i : C)cin >> i;
	for (auto& arr : S) {
		for (lli& i : arr) {
			cin >> i;
		}
	}

	vector<lli> T(D);
	for (lli& i : T)cin >> i;

	vector<int> lastOpen(asize, -1);

	//calcScore(T);

	
	int M;
	cin >> M;
	while (M--) {
		int d, q;
		cin >> d >> q;
		T[d-1] = q;
		cout << calcScore(T) << endl;
	}




	cout << flush;
	return 0;
}



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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;



  
int main() {
  int a,b,c;
  cin >>a>>b>>c;
  if(b-a==c-b){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}
      

Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n, p[20], ans = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    for(int i = 2; i < n; i++){
        if(max({p[i-2], p[i-1], p[i]}) != p[i-1] && min({p[i-2], p[i-1], p[i]}) != p[i-1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define dump(x)  cout << #x << " = " << (x) << endl;

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
//             0123456789 - digits. check the limits, int vs long
const int MX = 100001;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(0);
    cout << std::fixed;
    // freopen("ex.in","r",stdin);
    // freopen("ex.out","w",stdout);
    int a, b;
    cin >> a >> b;
    if (a > 9 || b > 9) cout << "-1";
    else cout << a * b;
    cout << "\n";
    return 0;
}

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

#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000000
#define ll long long
#define db double
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define all(v) v.begin(),v.end()
#define vll vector<ll>
#define vs vector<string>

#define mapll map<ll,ll>
#define mapss map<string,string>
#define mapsl map<string,ll>
#define mapls map<ll,string>

#define pll pair<ll,ll>
#define pss pair<string,string>
#define psl pair<ll,string>
#define pls pair<string,ll>

#define minheap priority_queue<ll>
#define maxheap priority_queue<ll,vector<ll> ,greater<ll>>

#define ff first
#define ss second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
const ll mod=1e9 + 7;


ll takemod(ll a) {
    return ((a%mod)+mod)%mod;
}

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

ll fast_exp(ll base, ll expo) {
    ll res=1;
    while(expo>0) {
        if(expo&1) res=(res*base)%mod;
        base=(base*base)%mod;
        expo>>=1;}
    return res;
}

ll modinv(ll a) {
    return takemod(fast_exp(takemod(a), mod-2));
}

stack<ll> s1;
signed main() 
{
    fast_cin();
    string s;
    cin>>s;
    ll ans=0;
    For(i,0,s.length())
    {
        if(s1.size()==0)
        {
            s1.push(s[i]-'0');
        }
        else
        {
            if(s1.top()!=s[i]-'0')
            {
                s1.pop();
                ans+=2;
            }
            else
                s1.push(s[i]-'0');
        }
    }
    cout<<ans<<endl;
    return 0;    
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] != a[2] && (a[0] == a[1] || a[1] == a[2]))
		cout << "Yes";
	else
		cout << "No";
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from bisect import bisect, bisect_left
def inpl(): return list(map(int, input().split()))

N, Q = inpl()
S = input()
D = [i for i in range(N-1) if S[i:i+2] == "AC"]
for _ in range(Q):
    l, r = inpl()
    a = bisect_left(D, l-1)
    b = bisect(D, r-2)
    print(b-a)

Measured memory_bytes: 5760
//設定言語check
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <queue>
using namespace std;

int main(){
  long long int N, ans = 0, X, M, kind = 1, count = 1, type = 0 ;
  cin >> N >> X >> M ;
  long long int exists[M+5] = {}, A[M+5] = {} ;
  A[1] = X ;
  exists[X] = 1 ;
  while(type == 0 ){
    count++ ;
    A[count] = (A[count-1] * A[count-1]) % M ;
    if(exists[A[count]] == 1){
      type = 1 ;
    }
    else if(count == N){
      type = 2 ;
    }
    else{
      exists[A[count]] = 1 ;
      kind++ ;
    }
  }
  if(type == 2){
    for(int i=1;i<N+1;i++){
      ans += A[i] ;
    }
  }
  else{
    int loops = 0 ;
    while(( A[count] != A[count - loops]) || (loops == 0) ){
      ans += A[count - loops] ;
      loops++ ;
    }

    int unloop = count - loops - 1 ;
    long long int many = (N-unloop) / loops ;
    ans = ans * many ;
    int left = ( (N-unloop) % loops) + unloop ;
    for(int i=1;i<left+1;i++){
      ans += A[i] ;
    }
  }
  cout << ans << endl ;
  return 0 ;
}

Measured memory_bytes: 5116
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int n,k;
  cin>>n>>k;

  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
  }

  for(int i=k;i<n;i++){
    if(p[i]>p[i-k]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

}

Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, ans = 1000000000;
    cin >> N;
    for (int i = 0; i < N; i++){
        int A, a = 0;
        cin >> A;
        while(A % 2 == 0) {
            A /= 2;
            a++;        
        }

        ans = min(ans, a);
    }
    cout << ans << endl;
}

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

int main(){
  int W,a,b;
  cin >> W >> a >> b;
  
  if(abs(a-b) <= W){
    cout << "0" << endl;
  }else if(b > a){ //bが右にある
    cout << b-(a+W) << endl; 
  }else{
	cout << abs((b+W)-a) << endl;
  }
}

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

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

vector<int> edge[1010];
int match[1010];
bool used[1010];

bool dfs(int v){
  used[v] = true;
  rep(i,edge[v].size()){
    int u = edge[v][i];
    int w = match[u];
    if( w<0 || !used[w]&&dfs(w) ){
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}
int solve(int sz){
  int ret = 0;
  memset(match,-1,sizeof(match));
  rep(i,sz)if( match[i]<0 ){
    memset(used,false,sizeof(used));
    if( dfs(i) )ret++;
  }
  return ret;
}


int gcd(int x, int y){
  return y ? gcd(y,x%y) : x;
}

int main(){
  int n,m;
  int blue[500],red[500];

  while(cin>>n>>m, n|m){
    // init
    rep(i,n+m+1)edge[i].clear();

    
    rep(i,n)scanf("%d",&blue[i]);
    rep(i,m)scanf("%d",&red[i]);
    rep(i,n){
      rep(j,m){
        if( gcd(blue[i], red[j])!=1 ){
          edge[i].push_back(j+n);
          edge[j+n].push_back(i);
        }
      }
    }
    cout << solve(n+m) << endl;
  }
  return 0;
}

Measured memory_bytes: 3104
// header {{{
// #define NDEBUG
#include <bits/stdc++.h>
using namespace std;

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)
#define EPS         (1e-10)
#define EQ(a, b)        (abs((a)-(b)) < EPS)
#define CILING(a, b)    (((a)+(b)-1LL)/(b))

template<class T>
using PIT = pair<int, T>;
template<class T>
using PTI = pair<T, int>;
using PII = pair<int, int>;
using PDI = pair<double, int>;
using LL  = long long;
using ULL = unsigned long long;
// }}}

int main() {
    int n;cin >> n;
    vector<int> a(n);
    for(auto &aa : a) cin >> aa;
    int count2 = 0;
    int count4 = 0;
    int odd = 0;
    for(int i=0;i<n;i++){
        if(a[i]%4 == 0){
            count4++;
        }else if(a[i]%2 == 0){
            count2++;
        }else{
            odd++;
        }
    }
    bool flag = false;
    if(count4 == 0){
        if(odd == 0){
            flag = true;
        }
    }else{
        if(count2 == 0){
            if(count4 >= odd-1) flag = true;
        }else{
            if(count4 >= odd) flag = true;
        }
    }
    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}


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

using namespace std;

#define int long long

const int NUM = 26;
const int INF = (int)(1e17);


struct in{
  int ymax, ymin, xmax, xmin;
};

signed main(){
  int N;

  cin>>N;
  
  for(int nn = 0; nn < N; nn++){
    vector<string> field;
    vector<int> count;
    vector<in> info;
    vector<vector<int>> con1;
    vector<vector<vector<int>>> con2;
    vector<int> used;
    bool flag = true;
    int temp = 0;

    int H, W;

    cin>>H>>W;


    field.resize(H);
    count.resize(NUM);
    info.resize(NUM,{-INF,INF,-INF,INF});
    used.resize(NUM,0);
    
    for(int i = 0; i < H; i++){
      cin>>field[i];
      for(int j = 0; j < W; j++){
	if(field[i][j] != '.'){
	  count[field[i][j] - 'A']++;
	  info[field[i][j] - 'A'].ymax = max(info[field[i][j] - 'A'].ymax, i);
	  info[field[i][j] - 'A'].xmax = max(info[field[i][j] - 'A'].xmax, j);
	  info[field[i][j] - 'A'].ymin = min(info[field[i][j] - 'A'].ymin, i);
	  info[field[i][j] - 'A'].xmin = min(info[field[i][j] - 'A'].xmin, j);
	}
      }
    }

    for(int i = 0; i < NUM; i++){//cout<<"i = "<<i<<" count "<<count[i]<<" temp "<<temp<<endl;
      if(!count[i]) continue;
      temp++;
    }
     
    for(int i = 0; temp; i = (i + 1)%NUM){ //cout<<"i = "<<i<<" temp "<<temp<<endl;
      int cona = 0, conb = 0, conc = 0;
      if(!count[i]) continue;
      // cout<<"COUTN "<<count[i]<<endl;
      
      if(used[i]){
	//	cout<<"USED "<<endl;
	flag = false;
	break;
      }
      
      used[i] = true;
      // cout<<info[i].ymin<<" <>  "<<info[i].ymax<<endl;
      // cout<<info[i].xmin<<" <> "<<info[i].xmax<<endl;
      for(int j = info[i].ymin; j <= info[i].ymax; j++){
	for(int k = info[i].xmin; k <= info[i].xmax; k++){

	  if(field[j][k] - 'A' == i || field[j][k] == ','){
	    cona++;
	  } else{
	    conc++;
	    break;
	  } 

	  if(conc) break;
	}
	if(conc) break;
      }
      //   cout<<cona<<" "<<conc<<endl;
      
      if(conc){
	continue;
      }

      //     cout<<"IIII = "<<i<<endl;
      
      used.clear();
      used.resize(NUM,0);
      temp--;
      count[i] = 0;
      
      for(int j = info[i].ymin; j <= info[i].ymax; j++){
	for(int k = info[i].xmin; k <= info[i].xmax; k++){

	  if(field[j][k] - 'A' == i){
	    field[j][k] = ',';
	  }
	  
	}
      }
      
    }
    
    cout<<(flag?"SAFE":"SUSPICIOUS")<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

using namespace std;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}
 
const int mod = (int)1e9 + 7;
 
int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();
	int a, b;
	cin >> a >> b;
	if(a > 0) cout << "Positive", exit(0);
	int neg = 0;
	neg += max(0, b - a + 1);
	if(a <= 0 && b >= 0) cout << "Zero", exit(0);
	if(neg & 1) cout << "Negative", exit(0);
	else cout << "Positive", exit(0);
}


Measured memory_bytes: 256
import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as C

readInt' = fst.fromJust.C.readInt
readLnInt = map readInt'.C.words<$>C.getLine
readCsInt n = concat<$>replicateM n readLnInt

x ? (a,b) = if x then a else b
a~>(f,x) = [a] ++ (null x)?([],f x)
half = flip div 2
aliq = ((0==).).mod

main = do
 inputs <- getLine
 putStr $ solve inputs

solve s = (any (=='7') s)?("Yes","No")


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

using namespace std;

int ispn(int n)
{
	int i;
	char d[10];
	int t;

	i = 0;
	while(n > 0) {
		d[i] = n % 10;
		n /= 10;
		i++;
	}
	for(int j = 0; j < i / 2; j++ ) {
		if(d[j] != d[i-j-1]) {
			return false;
		}
	}
	return true;
}


int main()
{
//	cout << ispn(11011) << ispn(12345) << endl;
	int a, b;

	int count = 0;

	cin >> a >> b;
	for(int i = a; i <= b; i++) {
		if(ispn(i)) {
			count ++;
		}
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const ll INFLL = 1001001001001001001;  // > 10^18
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

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

    for (int i = 0; i < s.length(); i++) {
        if (i % 2 == 0 && s[i] == 'L') {
            cout << "No" << endl;
            return 0;
        } 
        if (i % 2 == 1 && s[i] == 'R') {
            cout << "No" << endl;
            return 0;
        } 
    }
    cout << "Yes" << endl;
    return 0;
}


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

int main()
{
    int A, B;
    cin >> A >> B;
    vector<bool> ans(3, true);
    ans.at(A - 1) = false;
    ans.at(B - 1) = false;
    for (int i = 0; i < 3; i++)
    {
        if (ans.at(i))
            cout << i + 1 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;

const int MOD=1e9+7;

int main(){
    int n,m;
    cin>>n>>m;
    char g[n][m];
    int dp[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>g[i][j];
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    if(g[0][0]=='#'){
        cout<<0;
        return 0;
    }
    bool ok=false;
    for(int i=0;i<n;i++){
        if(g[i][0]=='#')ok=true;
        if(ok)dp[i][0]=0;
        else dp[i][0]=1;
    }
    ok=false;
    for(int j=0;j<m;j++){
        if(g[0][j]=='#')ok=true;
        if(ok)dp[0][j]=0;
        else dp[0][j]=1;
    }
    for(int i=1;i<n;i++){
        for(int j=1;j<m;j++){
            if(g[i-1][j]=='#' and g[i][j-1]=='#')dp[i][j]=0;
            else if(g[i-1][j]=='#')dp[i][j]=dp[i][j-1];
            else if(g[i][j-1]=='#')dp[i][j]=dp[i-1][j];
            else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
        }
    }
    // for(int i=0;i<n;i++){
    //     for(int j=0;j<m;j++)cout<<dp[i][j]<<" ";cout<<endl;
    // }
    cout<<dp[n-1][m-1];
}

Measured memory_bytes: 8464
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	N,D = map(int,input().split())
	#S = list(input())
	#L,R = map(int, input().split(" "))
	#L = list(map(int, input().split(" ")))

	ans = N // ((2*D)+1)
	#print(N % (2*D))
	if N % ((2*D)+1) != 0:
		ans += 1

	print(ans)


if __name__ == "__main__":
	main()


Measured memory_bytes: 3572
N = input()
l = input().split()

N=int(N)
a=range(1,N+1)
b=range(1,N+1)
a=[i*N for i in a]
b=[i*N for i in b]
b.reverse()

c=0
for i in l:
    i=int(i)
    b[i-1]+=c
    c+=1

for i in a:
    print(i,end=" ")
print("")
for i in b:
    print(i,end=" ")


Measured memory_bytes: 6512
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long max =0;
        ArrayList<Integer> monster = new ArrayList<>();
        ArrayList<Integer> player = new ArrayList<>();
        for(int i=0;i<N+1;i++) monster.add(sc.nextInt());
        for(int i=0;i<N;i++) player.add(sc.nextInt());
        for(int i=0;i<N;i++){
            int num1 = monster.get(i);
            int num2 = monster.get(i+1);
            int num3 = player.get(i);
            if(num1-num3>=0){
                max+=num3;
                monster.set(i,num1-num3);
            }
            else if(num1-num3<0) {
                max+=num1;
                num3-=num1;
                monster.set(i,0);
                if(num2-num3>=0){
                    max+=num3;
                    monster.set(i+1,num2-num3);
                }
                else if(num2-num3<0) {
                    max+=num2;
                    monster.set(i+1,0);
                }
            }
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 96728
n = int(input())
task =[]
for i in range(n):
  task.append(list(map(int,input().split())))

task.sort(key = lambda x:x[1])


total = 0
for j in range(n):
  total += task[j][0]
  if(total > task[j][1]):
    print("No")
    break
  if(j == n-1):
    print("Yes")
  

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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main() {
    fast;
    int d,t,s;
    cin >> d >> t >> s;
    
    cout << (d <= t*s ? "Yes" : "No") << "\n";
}

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

int main() {
    int N;
    int64_t x;

    cin >> N >> x;

    vector<int64_t> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    int ans = 0;
    int64_t sum = 0;

    for (int i = 0; i < N; i++) {
        ans = max(ans, i);

        for (int j = i; j < N; j++) {
            if (sum + a[j] == x) {
                ans = max(ans, i + 1);
            }
        }
        if (sum + a[i] > x) break;
        sum += a[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
 
#define int long long int
#define ld long double
#define mod 1000000007 
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define forn(i,s, e) for (int i = s; i <= e; i++)
#define fornd(i,s, e) for (int i = s ; i >= e; i--)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define print(x) for(auto el: x) cout<<el<<" ";cout<<"\n"
#define PSET(x,y) fixed<<setprecision(y)<<x
// #define bits(x) __builtin_popcount(x)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
// void fileio()
// {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
// }
 
 
template <typename T> 
void swap(T& a, T& b){
    T temp = a;
    a = b;
    b = temp;
}
void selfadd(int& a, int b){
    a = a+b;
    if(a>mod)
        a = a-mod;
}
void selfsub(int& a, int b){
    a = a-b+mod;
    if(a>mod)
        a = a-mod;
}  
const int N = 200005; 
 
int dp[10002][103][2];
int D;
string s;
int rec( int index,int d, int state){
    
    if(index==s.size()){
        if(d==0)
            return 1;
        else
            return 0;
    }
    if(dp[index][d][state] !=-1){
        return dp[index][d][state];
    }
 
    int a = s[index]-'0';
 
    int ans = 0;
    if(state){
        for(int i=0;i<a;i++){
            selfadd(ans ,rec(index+1,(d+i)%D, 0)); 
        }
        selfadd(ans ,rec(index+1,(d+a)%D,1));
    }
    else{
        for(int i=0;i<=9;i++){
            selfadd(ans ,rec(index+1,(d+i)%D, 0)); 
        }
    }
    // cout<<index<<" "<<d<<" "<<state<<" "<<ans<<endl;
    return dp[index][d][state] = ans;
 
}
 
void solve(){
    
    // string s;
    // int D;
    cin>>s;
    cin>>D;
     for(int i=0;i<10002;i++){
        for(int j = 0;j<103;j++){
            for(int k = 0;k<2;k++){
                dp[i][j][k] = -1;
            }
        }
    }
    cout<<(rec(0,0,1)-1)%mod;
}
 
int32_t main()
{
    // fileio();
    fast;
    // int t;
    // cin>>t;
    // for(int y=1;y<=t;y++)
    {
        // cout<<"Case #"<<y<<": ";
        solve();
    }
    return 0;
} 

Measured memory_bytes: 17152
<?php
  const DIRS = "RDLU";
  $h[] = "000000";
  $v[] = "0000000";
  for($i=0;$i<4;$i++) {
      $h[] = "0".trim(fgets(STDIN))."0";
      $v[] = "0".trim(fgets(STDIN))."0";
  }
  $h[] = "0".trim(fgets(STDIN))."0";
  $v[] = $v[0];
  $h[] = $h[0];

  $x=2; $y=1; $dir=0; $p='R';
  $stepx =  array(1,0,-1,0);
  $stepy = array(0,1,0,-1);

  while(!($x==1 && $y==1)) {
    for($i=0;$i<4;$i++) {
      $d = ($dir+$i+3)%4;
      if(($d==3 && $v[$y-1][$x]) || ($d==0 && $h[$y][$x])
        || ($d==1 && $v[$y][$x]) || ($d==2 && $h[$y][$x-1])) {
        $x += $stepx[$d];
        $y += $stepy[$d];
        $dir = $d;
        break;
      }
    }
    $p.=DIRS[$dir];
  }

  echo $p.PHP_EOL;

Measured memory_bytes: 15292
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
 
int main(){
	int H,W,n,mean=0;
	cin>>H>>W;
	string A[100];
	for(int i=0;i<H;i++)cin>>A[i];
	for(int i=0;i<W+2;i++)cout<<"#";
	cout<<endl;
	for(int i=0;i<H;i++)cout<<"#"<<A[i]<<"#"<<endl;
	for(int i=0;i<W+2;i++)cout<<"#";
	cout<<endl;
}

Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double eps = 1e-8;

struct Player{
	int load;
	int arv;
	int dpt;
};

struct Load{
	int time;
	int w;
};

class mycmp{
public:
	bool operator()(const Player p1,const Player p2){
		return p1.arv < p2.arv;
	}
};

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		Load* load = new Load[n+1];
		Player* player = new Player[n];
		for(int i=0;i<n;i++){
			int m,a,b;
			scanf("%d %d %d",&m,&a,&b);
			Player p = {m,a,b};
			player[i] = p;
		}

		sort(player,player+n,mycmp());

		load[0].w = 0;
		load[0].time = -1;
		for(int i=0;i<=n;i++){
			Load l = {player[i].arv,player[i].load + load[i].w};
			load[i+1] = l;
		}

		for(int i=0;i<n;i++){
			for(int j=0;j<=n;j++){
				if(player[i].dpt <= load[j].time){
					for(int k=j;k<=n;k++){
						load[k].w -= player[i].load;
					}
					goto next;
				}
			}
next:;
		}

		int max_v = -1;
		for(int i=0;i<=n;i++){
			//printf("i=%d time=%d load=%d\n",i,load[i].time,load[i].w);
			max_v = max(load[i].w,max_v);
		}

		if(max_v > 150) printf("NG\n");
		else printf("OK\n");

	}
}

Measured memory_bytes: 0
ai = lambda: list(map(int, input().split()))

n,m = ai()
x = ai()
y = ai()
mod = 10**9+7

from itertools import accumulate as acc
sx = list(acc(x))
ssx = list(acc(x[::-1]))
sy = list(acc(y))
ssy = list(acc(y[::-1]))
    

a = sum(ssx[i] - sx[i] for i in range(n)) % mod
b = sum(ssy[i] - sy[i] for i in range(m)) % mod

print(a*b % mod)

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

using namespace std;

const int maxn = 100010;

typedef long long ll;

int a[maxn], n;
ll sum[maxn];

ll mx = 0;
int ans = 0;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++) sum[i] = sum[i-1] + a[i];
	for (int i = n; i >= 1; i--) {
		if (2*sum[i] >= mx) ans ++;
		mx = max(0ll + a[i], mx - 2*a[i]);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    int N, K, result = 0, tmp;
    cin >> N >> K;
    vector<int> d(K);
    vector<int> a(N);
    REP(i, N) {
        a[i] = 0;
    }
    REP(i, N) {
        cin >> d[i];
        REP(j, d[i]) {
            cin >> tmp;
            a[tmp-1] = 1;
        }
    }
    REP(i, N) {
        if (a[i] != 0) {
            result++;
        }
    }
    cout << N - result << endl;
    return 0;
}


Measured memory_bytes: 3636
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() (int, error) {
	sc.Scan()
	s := sc.Text()
	return strconv.Atoi(s)
}

func comp(a []int, p int) {
	if a[p+1] < a[p] {
		buf := a[p]
		a[p] = a[p+1]
		a[p+1] = buf
	}
}

func main() {
	sc.Split(bufio.ScanWords)

	ans := make([]int, 3)
	for i := 0; i < 3; i++ {
		s, _ := nextInt()
		ans[i] = s
	}

	comp(ans, 0)
	comp(ans, 1)
	comp(ans, 0)

	fmt.Printf("%d %d %d\n", ans[0], ans[1], ans[2])
}



Measured memory_bytes: 1092
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  ll t=1;
  while(t--)
  {
    int n;
    cin>>n;
    int t[n],x[n],y[n];
    REP(i,n)
    {
        cin>>t[i]>>x[i]>>y[i];
    }
    int cur_x=0,cur_y=0;
    bool flag=true;
    REP(i,n)
    {
        int u=abs(x[i]-cur_x)+abs(y[i]-cur_y);
        if(i==0)
        {
            if(t[i]<u)
            flag=false;
        }
        else if((t[i]-t[i-1])<u)
        flag=false;
        else if(u%2==0 && (t[i]-t[i-1])>=u && (t[i]-t[i-1])%2!=0)
        flag=false;
        else if(u%2==1 && (t[i]-t[i-1])>=u && (t[i]-t[i-1])%2!=1)
        flag=false;
        cur_y=y[i];
        cur_x=x[i];
    }
    if(flag)cout<<"Yes";
    else cout<<"No";
  }  
  return 0;
}

Measured memory_bytes: 1408
while True:
    mid, final, makeup = list(map(int, input().split(" ")))
   
    if mid == -1 and final == -1 and makeup == -1:
        break
    elif mid == -1 or final == -1:
            print("F")
    else:
        if mid + final >= 80:
            print("A")
        elif mid + final >=65:
            print("B")
        elif mid + final >= 50:
            print("C")
        elif mid + final >=30:
            if makeup >= 50:
                print("C")
            else:
                print("D")
        
        else:
            print("F")


Measured memory_bytes: 5592
#include <bits/stdc++.h>
    
using namespace std;
    
#define endl "\n"
#define ll unsigned long long
#define int long long int
#define vi vector <int >
#define vii vector < pii >
#define vll vector <ll >
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
#define double long double
#define a first
#define b second

    
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);	
    int h, n, k, sum = 0;
    cin >> h >> n;
    forn(i,n){
        cin >> k;
        sum += k;
    }
    if(sum >= h)
        cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <cmath>
#include <string.h>
#include <queue>
#include <functional>

#define NMAX 100010
#define MOD 1000000007
#define INF 2000000000
#define PI 3.1415926535
#define EPS 1.e10-6

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) > 0 ? (a) : (-a))

typedef unsigned long long ull;
typedef long long ll;

using namespace std;

char c;

int main()
{
	cin >> c;
	cout << (char)((int)c + 1) << '\n';
}


Measured memory_bytes: 256
S = [input() for _ in range(3)]
D = {'a':0, 'b':1, 'c':2}
N = [0]*3
p = 0
while N[p]<len(S[p]):
    p_new = D[S[p][N[p]]]
    N[p]+=1
    p = p_new

print('ABC'[p])

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)

ll n, a[210];

int main() {
	ll ans = 0;
	bool flag = false;

	cin >> n;
	repi(i, 0, n) cin >> a[i];

	while (1) {
		repi(i, 0, n) {
			if (a[i] % 2 == 0) a[i] /= 2;
			else flag = true;
		}
		if (flag) break;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))

#define MAX3(x, y, z) ( (x) > (y)  ? ( (x) > (z) ? (x) : (z)  ) : ( (y) > (z) ? (y) : (z) )  )
#define MIN3(x, y, z) ( (x) < (y)  ? ( (x) < (z) ? (x) : (z)  ) : ( (y) < (z) ? (y) : (z) )  )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 987654321
#define IINF 987654321987654321
int N,M,K,T,tc;
ll x[100500], y[100500];
ll MOD = 1e9+7;
int main(void){
    geti(N,M);
    repp(i,N){
        scanf("%lld",&x[i]);
    }
    repp(i,M){
        scanf("%lld",&y[i]);
    }

    sort(x+1,x+1+N); sort(y+1,y+1+M);
    vector<ll> dx,dy;
    for(int i=1;i<=N-1;i++){
        dx.push_back(x[i+1]-x[i]);
    }
    for(int i=1;i<=M-1;i++){
        dy.push_back(y[i+1]-y[i]);
    }
    ll ans = 0;
    ll ansx=0, ansy=0;
    for(int i=0;i<=N-1;i++){
        ll t = dx[i]*(i+1); t %= MOD;
        t *= (N-(i+1)); t %= MOD;
        ansx += t; ansx %= MOD;
    }

    for(int i=0;i<=M-1;i++){
        ll t = dy[i]*(i+1); t %= MOD;
        t *= (M-(i+1)); t %= MOD;
        ansy += t; ansy %= MOD;
    }
    ans = ansx * ansy; ans %= MOD;
    cout << ans;
}



Measured memory_bytes: 4084
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second

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

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

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

int main(){
	string s;
	cin >> s;
	for(int i=0; i<s.size(); i++){
		if(s[i] == ',') s[i] = ' ';
	}

	cout << s << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
 
ll n,k,x,y;
 
int main(){
  ll ans=0;
  cin >> n ;
  vi a(n+1),b(n+1),c(n+1),d(n+1);
  REP(i,n+1) cin>>a[i];



  if (n==0){
    if (a[0]==1){
      cout<<1<<endl;
      return 0;
    }else{
      cout<<-1<<endl;
      return 0;
    }
  }
  


  if (a[0]!=0){
    cout<<-1<<endl;
    return 0;
  }

 
 

  d[n]=a[n];
  for(ll i=n-1;i>=0;i--){
    d[i]=d[i+1]+a[i];
  }

  ll nown=1;
  b[0]=1;
  c[0]=1;
  for(ll i=1;i<n+1;i++){
    nown=min(min(nown*2,d[i]),llMAX);
    b[i]=nown;
    nown-=a[i];
    if (nown<0){
      cout<<-1<<endl;
      return 0;
    }


    c[i]=nown;
  }

  

 
 
 
  int flag=0;
  for(ll i=0;i<n+1;i++){
    ans+=b[i];
    flag+=(b[i]<=0);
    //flag+=(c[i]<0);
  }
  if (flag!=0){
    cout<<-1<<endl;
    return 0;
  }
 
 
 
  cout<<ans<<endl;
  return 0;
}
 
/*
10
0 0 1 1 2 3 5 8 28 21 34
*/

Measured memory_bytes: 6404
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @n = gets.to_s.to_i
    @m = n / 2
    @a = Array.new(n){ gets.to_s.to_i }.sort
  end
  
  def solve
    ans = 0
    n.times do |i|
      ans += a[i] * weight(i)
      # print "(#{a[i]} * #{weight(i)}) + "
    end
    ans
  end
  
  def weight(i)
    return weight_even(i) if n.even?
    return weight_odd_top(i) if top_heavy
    return weight_odd_bottom(i)
  end

  def top_heavy
    @top_heavy ||= a[m+1] - a[m] < a[m] - a[m-1]
  end
    
  def weight_even(i)
    return -2 if i < n / 2 - 1
    return -1 if i == n / 2 - 1
    return 1 if i == n / 2
    return 2
  end
  
  def weight_odd_top(i)
    return -2 if i < m
    return 1 if i == m
    return 1 if i == m + 1
    return 2
  end
  
  def weight_odd_bottom(i)
    return -2 if i < m - 1
    return -1 if i == m - 1
    return -1 if i == m
    return 2
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 16696
S = gets.chomp!

max_num = 0
count = 0
S.chars {|ch|
  case ch
  when 'A','T','G','C' then
    count += 1
  else
    max_num = [max_num, count].max
    count = 0
  end
}

max_num = [max_num, count].max
print max_num


Measured memory_bytes: 1788
N = int(input())
H = list(map(int, input().split()))
I = []
ans = f = 0
for i in range(N-1):
    I.append(H[i+1]-H[i])
for i in I:
    if i<=0:
        f+=1
        ans = max(f,ans)
    elif i>0:
        ans = max(f,ans)
        f=0
print(ans)

Measured memory_bytes: 64228
n = gets.to_i
sa = gets.chomp.split(" ").map &:to_i
q = gets.to_i
ta = gets.chomp.split(" ").map &:to_i

c = 0
ta.each { |t|
	sa.each { |s|	
		if t == s
			c += 1
			break
		end
	}
}
puts c

Measured memory_bytes: 9032
import java.util.*;

public class Main{
    static int n;
    static int[] arr;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        arr = new int[n+1];
        for(int i=1; i<=n; i++)
            arr[i] = sc.nextInt();
        
        for(int i=1; i<=n; i++){
            System.out.println("node "+i+": key = "+arr[i]+", "+getParent(i)+getLeft(i)+getRight(i));
        }
    }

    static String getParent(int i){
        return (i>1)? "parent key = "+arr[i/2]+", " : "";
    }

    static String getLeft(int i){
        return (i*2<=n)? "left key = "+arr[i*2]+", " : "";
    }

    static String getRight(int i){
        return (i*2+1<=n)? "right key = "+arr[i*2+1]+", " : "";
    }
}


Measured memory_bytes: 27668
h, w, a, b = map(int, input().split())

MOD = 10 ** 9 + 7
N = h + w + 10
fact = [0 for _ in range(N)]
invfact = [0 for _ in range(N)]
fact[0] = 1
for i in range(1, N):
    fact[i] = fact[i - 1] * i % MOD

invfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD)

for i in range(N - 2, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % MOD
def nCk(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return fact[n] * invfact[k] * invfact[n - k] % MOD
        
ans = 0
a += 1
b += 1
n = h - a + b - 1
n2 = w - b + a - 1
while a <= h and b <= w:
    ans += nCk(n, b - 1) * nCk(n2, w - b)
    ans %= MOD
    a += 1
    b += 1
print(ans)

Measured memory_bytes: 24756
dance = ['L', 'R', 'U', 'D']

line = gets.split("").map(&:to_s)

# p line

G = line.select.with_index { |_, i| i.even? }.include?('L')
K = line.select.with_index { |_, i| i.odd? }.include?('R')
if G == false && K == false
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll a,b,c,i,o,p,q,j,k,l;
	cin>>a>>b>>c;
	a=a-b;
	a=a%c;
	while(a>b)
	{
		a-=b;
	}
	cout<<a;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace ForAizuSol
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = Console.ReadLine().Split(' ');
            var a = int.Parse(list[0]);
            var b = int.Parse(list[1]);

            var seq = a * b;
            var len = 2 * (a + b);

            Console.WriteLine(seq.ToString() + " " + len.ToString());
        }
    }
}



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

using namespace std;
using ll = long long;
const ll mod = 1000000007;

void fact(ll n, map<ll,ll>& Map){
    for(ll i = 2; i * i <= n; i++){
        while(n % i == 0){
            Map[i]++;
            n /= i;
        }
    }
    if(n == 1)return;
    Map[n]++;
}

ll powll(ll base,ll exp) {
    ll res = 1;
    while(exp>0){
        if(exp & 1)res = res * base;
        base = base * base;
        exp >>= 1;
    }
    return res;
}
ll pow_mod(ll base,ll exp,ll mod) {
   ll res = 1;
   while(exp>0){
       if(exp & 1)res = res * base % mod;
       base = base * base % mod;
       exp >>= 1;
   }
   return res;
}

int main()
{
    ll n, p;
    cin >> n >> p;
    map<ll, ll> mp;
    fact(p, mp);
    ll ans = 1;
    for(auto i : mp){
        cerr << i.first << " : " << i.second << endl;
        ans *= powll(i.first, i.second / n);
    }
    cout << ans << endl;
}

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

#define ll long long int
#define str string

ll MOD = 1000000007, INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Max = INF, Min = -1;
ll a = 0, b = 0, c = 0, n = 0, m=0,k=0,sum = 0,MASK=0;
ll A[500000] = {}, B[500000] = {}, X[1500][13],rui[500000] = {},dp[1<<12] = {};
int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
vector <ll> v;
str S, T;
bool check = true, check2 = false;

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int main() {
	//Code Line
cin >> n >> S;

for(int i = 0;i < n-1;i++){
	if(S[i] != S[i+1])sum++;
}
cout << sum+1 << endl;
	return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;
import java.util.HashSet;

class Main{
   public static void main(String[] args) {

     Scanner sc = new Scanner(System.in);
     HashSet hs = new HashSet();

     int preCounter = 0;
     int counter = 0;
     int N = sc.nextInt();
     String S = sc.next();


     for(int i = 1; i < N; i++) {
     String front = S.substring(0, i);
     String back = S.substring(i, N);
     front = removeDup(front);
     back = removeDup(back);



     preCounter = 0;


     for(int n = 0; n < front.length(); n++) {

       char frontChar = front.charAt(n);

       for(int t = 0; t < back.length(); t++) {
         char backChar = back.charAt(t);
         if (frontChar == backChar) {
           preCounter++;
         }
       }
     }
     if(counter < preCounter) {
       counter = preCounter;
     }
   }
   System.out.println(counter);
   return;
 }

 private static String removeDup(String str){
   String result = new String("");

   for (int i = 0; i < str.length(); i++) {
       if (!result.contains("" + str.charAt(i))) {
           result += "" + str.charAt(i);
       }
   }

   return result;
  }
}


Measured memory_bytes: 26068
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n, m = map(int, input().split())
es = [[] for i in range(n)]
co = [[] for i in range(n)] # 有効辺の向きを逆にした
for i in range(n - 1 + m):
    a, b = map(int, input().split())    
    es[a - 1].append(b - 1)
    co[b - 1].append(a - 1)

dp = [-1] * n

def memo(v):
    if dp[v] != -1: #更新済
        return dp[v]

    for i in co[v]:
        x = memo(i) + 1
        if x > dp[v]:
            parent[v] = i + 1
            dp[v] = x

    return max(dp[v], 0)

parent = [0] * n
for i in range(n):
    memo(i)


for i in parent:
    print(i)


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

using namespace std;

using ll = long long;

bool Solve() {
    int n;
    string s;

    cin >> n >> s;
    vector<char> sw(n, 3); // S: 0, W: 1
    for (int t1 = 0; t1 <= 1; ++t1) {
        for (int t2 = 0; t2 <= 1; ++t2) {
            sw[0] = t1; sw[1] = t2;

            if (t1 == 0) sw[n - 1] = (s[0] == 'o' ? sw[1] : 1 - sw[1]);
            else sw[n - 1] = (s[0] == 'x' ? sw[1] : 1 - sw[1]);

            for (int i = 1; i < n - 2; ++i) {
                if (sw[i] == 0) sw[i + 1] = (s[i] == 'o' ? sw[i - 1] : 1 - sw[i - 1]);
                else sw[i + 1] = (s[i] == 'x' ? sw[i - 1] : 1 - sw[i - 1]);
            }

            if (sw[n - 2] == 0) { // 羊
                if ((s[n - 2] == 'o' && sw[n - 1] != sw[n - 3]) ||
                    (s[n - 1] == 'x' && sw[n - 1] == sw[n - 3])) continue;
            }
            else { // 狼
                if ((s[n - 2] == 'x' && sw[n - 1] != sw[n - 3]) ||
                    (s[n - 2] == 'o' && sw[n - 1] == sw[n - 3])) continue;
            }

            if (sw[n - 1] == 0) { // 羊
                if ((s[n - 1] == 'o' && sw[0] != sw[n - 2]) ||
                    (s[n - 1] == 'x' && sw[0] == sw[n - 2])) continue;
            }
            else { // 狼
                if ((s[n - 1] == 'x' && sw[0] != sw[n - 2]) ||
                    (s[n - 1] == 'o' && sw[0] == sw[n - 2])) continue;
            }

            for (int i = 0; i < n; ++i) cout << (sw[i] == 0 ? 'S' : 'W');
            cout << endl;
            return true;
        }
    }

    return false;
}

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

    if (!Solve()) cout << -1 << endl;

    return 0;
}


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

int main(){
    string a,b,c;
    cin>>a>>b>>c;
    cout<<a[0]<<b[0]<<c[0]<<endl;
    return 0;
}

Measured memory_bytes: 256