akhauriyash/Code-Regression huggingface dataset:
import numpy as np

A=np.array([list(map(int, input().split())) for i in range(3)])
N=int(input())
B=[int(input()) for i in range(N)]

for b in B:
  for i in range(3):
    for j in range(3):
      if A[i, j]==b:
        A[i, j]=0

if (A[:,0].sum()==0) or (A[:,1].sum()==0) or (A[:,2].sum()==0):
  print("Yes")
elif (A[0,:].sum()==0) or (A[1,:].sum()==0) or (A[2,:].sum()==0):
  print("Yes")
elif A[0,0]+A[1,1]+A[2,2]==0 or A[2,0]+A[1,1]+A[0,2]==0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 12488
#include<stdio.h>
#include<string.h>

int min(int a,int b){
  if(a<b)return a;
  return b;
}

int main(){
  int i,j,len,N,cnt=0,fcnt=0,lcnt=0,f,k=1;
  char ss[20];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%s",ss);
    len=strlen(ss);
    if(ss[0]=='B')fcnt++;
    if(ss[len-1]=='A')lcnt++;
    if( (ss[0]!='B'&&ss[len-1]=='A') || (ss[0]=='B'&&ss[len-1]!='A') )k=0;
    f=0;
    for(j=0;j<len;j++){
      if(f==1&&ss[j]=='B'){
        cnt++;
        f=0;
      }else if(ss[j]=='A'){
        f=1;
      }else{
        f=0;
      }
    }
  }
  if(fcnt==0)k=0;
  printf("%d\n",cnt+min(fcnt,lcnt)-k);
  return 0;
}


Measured memory_bytes: 128
def func2(l, value):
    i = -1
    c = len(l)
    result = []
    while i < c:
        try:
            i = l.index(value, i + 1)
            result.append(i)
        except:
            return result
    return result

T=list(input())
que_list=(func2(T,"?"))
for i in que_list:
    T[i]='D'
print(''.join(T))

Measured memory_bytes: 18336
#include <bits/stdc++.h>
#define ll long long
#define Android ios::sync_with_stdio(false), cin.tie(NULL)
#define F(i, n) for(int i=0, _iter_max=(n); i<_iter_max; i++)
#define range(i, l, r) for(int i=(l), _iter_max=(r); i<_iter_max; i++)
#define debug(s, r) std::cerr << #s << ": " << (s) << (r==0?' ':'\n')
#define pii pair<int, int>  

using namespace std;

void redirect_input() { freopen("./input.txt", "r", stdin); }
void redirect_output() { freopen("./output.txt", "w", stdout); }

const int maxn = 1000 + 100;

char matrix[maxn][maxn];
char pattern[][100] = {
    "", "", "", 
    "aa...b..b", 
    "aabcddbcefggefhh",
    "aabbcdde.cffegg..hij..hij",
    "aabee.d.b..fdcc..fgg.iij..hl.j..hlkk",
    "beh....beh....cf.jj..cf.kk..dgg..mmd.i..nn..illoo"
}; 
int n, pos;

void solve(){
    pos = 0;
    memset(matrix, '.', sizeof matrix);
    if(n == 2){
        cout << -1 << endl;
        return;
    }
    while(pos + 7 < n){
        for(int i=0; i<4; i++){
            for(int j=0; j<4; j++){
                matrix[i+pos][j+pos] = pattern[4][i*4+j];
            }
        }
        pos += 4;
    }
    int k = n-pos;
    for(int i=0; i<k; i++){
        for(int j=0; j<k; j++){
            matrix[i+pos][j+pos] = pattern[k][i*k+j];
        }
    }
    for(int i=0; i<n; i++) matrix[i][n] = 0;
    for(int i=0; i<n; i++) cout << matrix[i] << '\n';
    // for(int i=0; i<30; i++) cout << '-'; cout << endl;
}

signed main(){
    Android;
    while(cin >> n) solve();
}


Measured memory_bytes: 2432
#include<stdio.h>

int main(void)
{
	int k = 0;
	char m[20];
	scanf("%s", m);
	int i;
	int n = 0;
	for (i = 0; i < 15; i++) {
		if ('o' == m[i] || 'x' == m[i]) {
			k++;
		}


	}
	for (i = 0; i < k; i++) {
		if ('o' == m[i]) {
			n++;
		}


	}
	if (n >= 8) {
		printf("YES");
	}
	else if (8 - n <= 15 - k) {
		printf("YES");
	}
	else {
		printf("NO");
	}
	return 0;
}

Measured memory_bytes: 128
# Setup
import sys
import collections
import heapq
sys.setrecursionlimit(4100000)
import math
n,m = [int(i) for i in input().split()]
b = [-int(i) for i in input().split()]
heapq.heapify(b)
for i in range(m):
    temp = heapq.heappop(b)
    # print(temp)
    temp = temp/2
    # print(math.ceil(temp))
    heapq.heappush(b,math.ceil(temp))
print(-sum(b))

Measured memory_bytes: 14636
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, x = 0, y = 0;
    cin >> n;
    while (n--){
        string s, t;
        cin >> s >> t;
        if (s < t) y += 3;
        else if (s > t) x += 3;
        else{ x++; y++;}
    }
    cout << x << " " << y << endl;
    return 0;
}

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

#define ll long long

using namespace std;


int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   
   string s; cin >> s;

   if(s[2] == s[3] && s[4] == s[5]) cout << "Yes";
   else cout << "No";

   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  int n = s.size();
  reverse(all(s));
  vector<vi> dp(n + 1, vi(2, 1e8));
  dp[0][0] = 0;
  rep(i, n) {
    int d = s[i] - '0';
    int ni = i + 1;
    rep(j, 2) {
      dp[ni][0] = min(dp[ni][0], dp[i][j] + d + j);
      dp[ni][1] = min(dp[ni][1], dp[i][j] + 10 - d - j);
    }
  }
  cout << min(dp[n][0], dp[n][1] + 1) << endl;
}

Measured memory_bytes: 55940
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
 
int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i=0;i<n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    ll right=ll(1e18)+1;
    ll left=-right;
    while (right-left>1) {
        ll mid=(left+right)/2;
        ll cnt=0;
        for (ll i=0;i<n;i++) {
            if (a[i]<0) {
                ll ng=-1,ok=n;
                while (ok-ng>1) {
                    ll m=(ng+ok)/2;
                    if (a[i]*a[m]<mid) ok=m;
                    else ng=m;
                }
                cnt+=n-ok;
            } else {
                ll ng=-1,ok=n;
                while (ok-ng>1) {
                    ll m=(ng+ok)/2;
                    if (a[i]*a[m]<mid) ng=m;
                    else ok=m;
                }
                cnt+=ok;
            }
            if (a[i]*a[i]<mid) cnt--;
        }
        if (cnt/2<k) left=mid;
        else right=mid;
    }
    cout << left << endl;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	string s; cin >> s;
	map<char, int>Map;

	FOR(i, 0, SZ(s)) {
		Map[s[i]]++;
	}
	LL ans = 1;
	for (auto it : Map) {
		ans &= (it.second %2==0);
	}
	cout <<( ans?"Yes":"No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n;
  scanf("%d", &n);

  if(n<=9) printf("%d\n", n);
  else if(n>=10 && n<=99) printf("9\n");
  else if(n>=100 && n<=999) printf("%d\n",n-99+9);
  else if(n>=1000 && n<=9999) printf("909\n");
  else if(n>=10000 && n<=99999) printf("%d\n",n-9999+909);
  else printf("90909\n");

  return 0;
  
}


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

int main(){
    int n;
    ll ans = 404040404000000, dif;
    ll sum=0;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a.at(i);
        sum += a.at(i);
    }
    ll left = 0, right;
    for(int i = 0; i < n; ++i){
        left += a.at(i);
        right = sum - left;
        dif = left - right;
        if(dif<0) dif *= -1;
        ans = min(dif, ans);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
bool change(bool now,bool input){
  return (!now)||input;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  bool now=true;
  for(int i=0;i<n;i++){
    char c;cin>>c;
    if(c=='T')now=change(now,true);
    else now=change(now,false);
  }
  cout<<(now?'T':'F')<<endl;
  return 0;
}



Measured memory_bytes: 3136
#include<stdio.h>
#include<stdlib.h>
 
#define Ni 3
 
int Pz[Ni][Ni],tmp[Ni][Ni];
int Dx[4]={0,1,0,-1},Dy[4]={1,0,-1,0};
 
void emblem(int *a,int *b){
  int i,j;
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      if(!Pz[i][j]){
    *a = j;
    *b=i;
      }
    }
  }
}
 
void swap(int *a,int *b){
  int tmp;
  tmp =*a;
  *a = *b;
  *b = tmp;
}
 
int check(){
  int i,A,S=0;
  for(i=0;i<9;i++){
    A = Pz[i/3][i%3];
    if(A){
      A--;
      S += abs(i/3-A/3) + abs(i%3 - A%3);
    }
  }
  return S;
}
 
int defain(int a,int b,int P,int D,const int shin){
  int i,hi,A,B,result;
  hi = check();
  if(hi==0){
    return D;
  }
  if(D+hi>shin){
    return -1;
  }
 
  for(i=0;i<4;i++){
    A = a+Dx[i];
    B = b+Dy[i];
    if(~P && i==(P+2)%4) {
      continue;
    }
    if(!(0<=A && A<3 && 0<=B && B<3)){
      continue;
    }
    swap(&Pz[b][a],&Pz[B][A]);
    result = defain(A,B,i,D+1,shin);
    if(~result){
      return result;
    }
    swap(&Pz[b][a],&Pz[B][A]);
  }
  return -1;
}
 
int main(){
  int i,j,li,TA,a,b;
 
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      scanf("%d",&Pz[i][j]);
    }
  }
 
  emblem(&a,&b);
  for(li=0;li<100;li++){
    for(i=0;i<3;i++){
      for(j=0;j<3;j++){
    tmp[i][j]=Pz[i][j];
      }
    }
    TA = defain(a,b,-1,0,li);
    if(TA!=-1){
      printf("%d\n",TA);
      break;
    }
 
    for(i=0;i<3;i++){
      for(j=0;j<3;j++){
    Pz[i][j]=tmp[i][j];
      }
    }
 
    TA = -1;
    if(li==99){
      printf("%d\n",TA);
    }
  }
 
  return 0;
}



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

int main() {
  int n, k, ans, ind_mi;
  cin >> n >> k;
  if (n <= k) cout << "1\n";
  else {
    if ((n-1) % (k-1) == 0) cout << (n-k) / (k-1) + 1 << "\n";
    else cout << 1 + (n-k) / (k-1) + 1 << "\n";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vector<P> p(N);
  for(int i = 0; i < N; i++){
    p.at(i).second = i;
    cin >> p.at(i).first;
  }
  sort(ALL(p));
  int right = 0;
  int m = 0;
  for(int left = 0; left < N; left++){
    while(right + 1 < N && p[right].second < p[right+1].second) right++;
    chmax(m, right - left + 1);
    left = right;
    right = left+1;
  }
  cout << N - m << endl;
}

Measured memory_bytes: 1792
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = ((int)(n) - 1); i >= 0; i--)
#define repn(i, n) for(int i = 1; i <= (int)(n); i++)
#define reprn(i, n) for(int i = ((int)(n)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define BIG_PRIME_NUM 1000000007
using ll = long long;

#include <iostream>
#include <array>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <numeric>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << endl;
	return 0;
}

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

int main() {
  ll A;
  float B;
  cin >> A >> B;
  ll B100 = round(B * 100);
  ll ans = A * B100 / 100;
  cout << ans << endl;
}


Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
    
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    
// #define int long long
#define double long double
    
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
    
#define ff first
#define ss second
#define mp make_pair
         
#define pb push_back
#define endl "\n" 
         
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)    

#define bp __builtin_popcountll
#define inf 3e15
    
const int N=1e5+2;
const int M=1e9+7;
int dp[N][3][3][3];
int n,a,b,c;
string s[N];
int go(int idx,int aa,int bb,int cc)
{
	if(aa<0 || bb<0 || cc<0)
	return 0;
	if(idx==n+1){
		return 1;
	}
	int &ans=dp[idx][aa][bb][cc];
	if(ans!=-1)
	return ans;
	ans=0;
	if(s[idx]=="AB")
	{
		int pp=bb+1,qq=aa+1;
		if(bb+1>2)
		pp=2;
		if(aa+1>2)
		qq=2;
		ans=ans|(go(idx+1,aa-1,pp,cc));
		ans=ans|(go(idx+1,qq,bb-1,cc));
	}
	else if(s[idx]=="AC")
	{
		int pp=aa+1,qq=cc+1;
		if(aa+1>2)
		pp=2;
		if(cc+1>2)
		qq=2;
		ans=ans|(go(idx+1,aa-1,bb,qq));
		ans=ans|(go(idx+1,pp,bb,cc-1));
	}
	else
	{
		int pp=bb+1,qq=cc+1;
		if(bb+1>2)
		pp=2;
		if(cc+1>2)
		qq=2;
		ans=ans|(go(idx+1,aa,bb-1,qq));
		ans=ans|(go(idx+1,aa,pp,cc-1));
	}
	return ans;
}
void god(int idx,int aa,int bb,int cc)
{
	
	if(idx==n+1){
		return;
	}
	
	if(s[idx]=="AB")
	{
		int pp=bb+1,qq=aa+1;
		if(bb+1>2)
		pp=2;
		if(aa+1>2)
		qq=2;
		// ans=ans|(go(idx+1,aa-1,pp,cc));
		// ans=ans|(go(idx+1,qq,bb-1,cc));
		if(go(idx+1,aa-1,pp,cc))
		{
			cout<<"B"<<endl;
			god(idx+1,aa-1,pp,cc);
		}
		else
		{
			cout<<"A"<<endl;
			god(idx+1,qq,bb-1,cc);
		}
		
		
	}
	else if(s[idx]=="AC")
	{
		int pp=aa+1,qq=cc+1;
		if(aa+1>2)
		pp=2;
		if(cc+1>2)
		qq=2;
		// ans=ans|(go(idx+1,aa-1,bb,qq));
		// ans=ans|(go(idx+1,pp,bb,cc-1));
		if(go(idx+1,aa-1,bb,qq))
		{
			cout<<"C"<<endl;
			god(idx+1,aa-1,bb,qq);
		}
		else
		{
			cout<<"A"<<endl;
			god(idx+1,pp,bb,cc-1);
		}
	}
	else
	{
		int pp=bb+1,qq=cc+1;
		if(bb+1>2)
		pp=2;
		if(cc+1>2)
		qq=2;
		// ans=ans|(go(idx+1,aa,bb-1,qq));
		// ans=ans|(go(idx+1,aa,pp,cc-1));
		if(go(idx+1,aa,bb-1,qq))
		{
			cout<<"C"<<endl;
			god(idx+1,aa,bb-1,qq);
		}
		else
		{
			cout<<"B"<<endl;
			god(idx+1,aa,pp,cc-1);
		}
	}
	// return ans;
}
void solve()
{
	cin>>n>>a>>b>>c;
	f(i,1,n) cin>>s[i];
	a=min(a,2);
	b=min(b,2);
	c=min(c,2);
	memset(dp,-1,sizeof(dp));
	int res=go(1,a,b,c);
	if(res==false)
	{
		cout<<"No";
		return;
	}
	cout<<"Yes"<<endl;
	god(1,a,b,c);
	
}
signed main()  
{
	FAST
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": ";
    	solve();
    }
}


Measured memory_bytes: 25136
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

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

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

long numDivisors(long n, long k) {
    return n / k;
}

long calc(long a, long b, long c, long d) {

    long x = numDivisors(b, c) + numDivisors(b, d) - numDivisors(b, lcm(c, d));
    long y = numDivisors(a-1, c) + numDivisors(a-1, d) - numDivisors(a-1, lcm(c, d));


    return (b - a + 1) - (x - y);
}

void main() {
    long a, b, c, d; scan(a, b, c, d);
    writeln(calc(a, b, c, d));
}


Measured memory_bytes: 256
N = int(input())
red = [list(map(int, input().split())) for _ in range(N)]
blue = [list(map(int, input().split())) for _ in range(N)]

red.sort(key=lambda x: x[1])
red.sort()
blue.sort(key=lambda x: x[1])
blue.sort()
answer = 0
for bx, by in blue:
    l = []
    for i in range(len(red)):
        rx, ry = red[i]
        if rx < bx and ry < by:
            l.append((ry, rx, i))
    if len(l) >= 1:
        l.sort(reverse=True)
        answer += 1
        red.pop(l[0][2])
print(answer)




Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long N,K,a,b;
    cin>>N>>K;
    
    a=N/K;
    if(K%2!=0){
        cout<<a*a*a<<endl;
    }else{
        b=(N+K/2)/K;
        cout<<a*a*a+b*b*b<<endl;
        
    }
    
}

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

int main()
{
    int N,M;cin >> N >> M;
    vector<bool> part(N,false);
    ll j=0;
    ll a=M/2;
    ll b=M-M/2;
    for (int i=0;i<b;i++)
    {
        cout <<b-i <<" " << b+i+1 << endl;
    }
    for (int i=0;i<a;i++)
    {
        cout << N-a-i-1<<" " <<N-a+i+1<<endl;
    }
return 0;
}

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

using namespace std;

typedef long long int lli;

// ####################
//  Calc nCr
// ####################
const lli MAX = 1000000;
const lli MOD = 1000000007;

lli fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void NCRinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
lli NCR(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// ####################
//  Calc nCr END
// ####################

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

    // 前処理
    NCRinit();

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

    int m = n-k;

    for (int i=0; i<k; i++) {
        if (m==0 && i==0) cout << 1 << endl;
        else cout << (NCR(k-1, i) * ((NCR(m-1, i-1)+2*NCR(m-1, i)+NCR(m-1, i+1))%MOD)) % MOD << endl;
    }

    return 0;
}


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

typedef vector<int> vi;

int N;
vi A, B, C;

void input_init(void) {
	cin >> N;
	A.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> A[i];
	B.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> B[i];
	C.resize(N - 1);
	for (int i = 0; i < N - 1; ++i)
		cin >> C[i];
}

int solve(void) {
	int sum = 0;
	int pre = -2;
	for (int i = 0; i < N; ++i) {
		int id = A[i];
		--id;
		sum += B[id];
		if (id == pre + 1)
			sum += C[id - 1];
		pre = id;
	}
	return sum;
}

int main(void) {
	input_init();
	int ans = solve();
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class A
{
	static void Main()
	{
		var d = Console.ReadLine().GroupBy(c => c).ToDictionary(g => g.Key, g => g.Count());
		Console.WriteLine(d.Count == 2 && d.First().Value == 2 ? "Yes" : "No");
	}
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int n=s.size();
	ll cnt=0,ans=0;
	rrep(i,n-1){
		if(s[i]=='B'&&s[i+1]=='C')cnt++;
		else if(s[i]=='A'){ans+=cnt;}
		else if(i==0||(!(s[i-1]=='B'&&s[i]=='C')))cnt=0;
	}
	puta(ans);
}


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

typedef long long ll;
#define debug(x) cerr << #x <<" : "<< x << endl;
#define INF (1<<20)
const int MAX_N = (1 << 18);

int main() {
	char b;
	cin >> b;
	if (b == 'A') {
		cout << 'T' << endl;
	}
	else if (b == 'T') {
		cout << 'A' << endl;
	}
	else if (b == 'C') {
		cout << 'G' << endl;
	}
	else {
		cout << 'C' << endl;
	}
}

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> a(M+1);
  for (int i=0; i<M; i++) {
    cin >> a[i];
  }
  a[M] = 0;
  vector<int> dp(N+1,0);
  dp[0] = 1;
  int now = 0;
  
  for (int i=1; i<N+1; i++) {
    if (a[now] == i) {
      now++;
      continue;
    }
    if (i == 1) {
      dp[1] = dp[0];
    }
    dp[i] = (dp[i-1] + dp[i-2]) % 1000000007;
  }
    
  cout << dp[N] << endl;
  return 0;
  
}

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

int main() {
    int s;
    cin >> s;
    int i = 1;
    if (s == 1 or s ==2)
        cout << 4;
    else
    {
    while (s != 4) {
        i++;
        if (s % 2) {
            s = 3 * s + 1;
        } else
            s /= 2;
    }
        cout << i + 3;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  bool flag = false;
  REP(i,n-1) if(a[i+1]-a[i]>1) flag = true;
  if(flag || a[0]!=0){
    cout << -1 << endl;
    return 0;
  }
  
  ll ans = 0;
  FOR(i,1,n){
    if(a[i]-a[i-1]==1) ans++;
    else ans += a[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#define INF 1000000000
#define nmax 500005
using namespace std;

int n;
int cnt = 0;
int a[nmax];

void merge(int left, int mid, int right){
  int n1 = mid -left;
  int n2 = right - mid;
  int l[nmax];
  int r[nmax];

  int i, j;
  
  for(i = 0; i < n1; i++) l[i] = a[left + i];
  for(i = 0; i < n2; i++) r[i] = a[mid + i];

  l[n1] = INF;
  r[n2] = INF;

  i = 0;
  j = 0;

  for(int k = left; k < right; k++){
    if(l[i] <= r[j]) a[k] = l[i++];

    else a[k] = r[j++];

    cnt++;
    
  }
}

void mergeSort(int left, int right){
  if(left+1 < right){
    int mid = (left + right) / 2;

    mergeSort(left, mid);
    mergeSort(mid, right);
    merge(left, mid, right);
  }
}

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

  mergeSort(0, n);

  for(int i = 0; i < n; i++){
    if(i) cout << " ";

    cout << a[i];
  }

  cout << endl;
  cout << cnt << endl;
  

  return 0;

}



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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define llong long long
#define INF 999999999
#define pb(a) push_back(a)

using namespace std;



vector<string> split(string str, char delim)
{
	vector<string> res;
	size_t current = 0, found;
	while ((found = str.find_first_of(delim, current)) != string::npos)
	{
		string tmp = string(str, current, found - current);
		res.push_back(tmp);
		current = found + 1;
	}
	string tmp = string(str, current, found - current);
	tmp.replace(tmp.size()-1,tmp.size(),"\0");
	res.push_back(string(str, current, str.size() - current));
	return res;
}

int main()
{
	char ch[1000];
	stack<int> st;

	fgets(ch, 1000, stdin);
	vector<string> vec = split(string(ch), ' ');

	REP(i,vec.size())
	{
		if(vec[i].find_first_of("+") != -1)
		{
			int buf1 = st.top();
			st.pop();
			int buf2 = st.top();
			st.pop();
			st.push(buf2 + buf1);
		}
		else if (vec[i].find_first_of("-") != -1)
		{
			int buf1 = st.top();
			st.pop();
			int buf2 = st.top();
			st.pop();
			st.push(buf2 - buf1);
		}
		else if (vec[i].find_first_of("*") != -1)
		{
			int buf1 = st.top();
			st.pop();
			int buf2 = st.top();
			st.pop();
			st.push(buf2 * buf1);
		}
		else if (vec[i].find_first_of("/") != -1)
		{
			int buf1 = st.top();
			st.pop();
			int buf2 = st.top();
			st.pop();
			st.push(buf2 / buf1);
		}
		else
		{
			st.push(atoi(vec[i].c_str()));
		}
	}


	printf("%d\n", st.top());

}

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

result=[]

for item in range(n):
  s=list(input())
  #print(s)
  s.sort()
  result.append("".join(s))

tmp_cnt=0
count=0
temp=""
result.sort()
result.append("")


for item in result:
    if temp!=item:
        count+=tmp_cnt*(tmp_cnt-1)//2
        tmp_cnt=1
        temp=item
    else:
        tmp_cnt+=1

print(count)
    




Measured memory_bytes: 57048
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func stringifyArray(arr []int) string {
	return strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]")
}

func swap(a []int, i, j int) {
	tmp := a[j]
	a[j] = a[i]
	a[i] = tmp
}
func reverse(a []int, b, e int) {
	for i := b; i <= b+(e-b)/2+1; i++ {
		j := (e - 1) - (i - b)
		if i < j {
			swap(a, i, j)
		}
	}
}

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

	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	nQueries := nextInt()
	for i := 0; i < nQueries; i++ {
		b := nextInt()
		e := nextInt()
		// fmt.Println(stringifyArray(a))
		reverse(a, b, e)
	}
	fmt.Println(stringifyArray(a))
}



Measured memory_bytes: 1244
import heapq

N, M = list(map(int,input().split()))
A = [[] for _ in range(M)]

for i in range(N):
    a, b = list(map(int,input().split()))
    if a <= M:
        A[a-1].append(-b)
    
ans = 0
cand = []

for i in range(M):
    
    for j in A[i]:
        heapq.heappush(cand, j)
        
    if cand:
        ans -= heapq.heappop(cand)
    
print(ans)

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

#define MAX_N 50

int main() {
  int N;
  int p[MAX_N], p2[MAX_N];
  int cnt = 0;

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


  sort(p, p + N);
  for (int i = 0; i < N; i++) {
    if (p[i] != p2[i]) cnt++;
  }
  if (cnt <= 2) printf("%s", "YES");
  else printf("%s", "NO");

  return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main {

    public void countFrequency(String[] verdict) {
        HashMap<String, Integer> frequency = new HashMap();
        String[] key = new String[]{"AC", "WA", "TLE", "RE"};
        for (String v : verdict) {
            frequency.put(v, frequency.getOrDefault(v, 0) + 1);
        }
        StringBuilder sb = new StringBuilder();
        for (String k : key) {
            if (frequency.containsKey(k)) {
                sb.append(k).append(" x ").append(frequency.get(k)).append("\n");
            } else {
                sb.append(k).append(" x ").append(0).append("\n");
            }
        }
        System.out.println(sb.toString());
    }

    public static void main(String args[]) {
        Main jss = new Main();
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] arr = new String[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = sc.next();
        }
        jss.countFrequency(arr);
    }
}


Measured memory_bytes: 63632
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a1 = 0
b1 = a[0] - a1
b2 = a[1] - a1
b3 = a[2] - a1
a2 = b[0] - b1
a3 = c[0] - b1
if b[1] == a2 + b2 and b[2] == a2 + b3 and c[1] == a3 + b2 and c[2] == a3 + b3:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
from bisect import bisect_right
from math import log

N = int(input())
X = list(map(int, input().split()))
L = int(input())

R = [[-1] * N for i in range(int(log(N, 2) + 1))]
# 1日で行けるところをにぶたんで求める
for i in range(N):
    R[0][i] = bisect_right(X, X[i] + L) - 1

# ダブリング
for k in range(1, len(R)):
    for i in range(N):
        R[k][i] = R[k-1][R[k-1][i]]

# にぶたんでクエリに答えていく
Q = int(input())
for q in range(Q):
    a, b = map(int, input().split())
    a, b = min(a, b)-1, max(a, b)-1

    ans = 0
    for k in range(len(R))[::-1]:
        if R[k][a] < b:
            a = R[k][a]
            ans += 2 ** k
    print(ans + 1)


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

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;


set<char> s;


int main()
{
    int n; cin >> n;
    char c;
    while(n--) cin >> c, s.insert(c);
    if(s.size()==4) cout << "Four";
    else cout << "Three";
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;
ll INF = 9999999999999999;
 
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;
}
ll max(ll a, ll b){
    if(a > b) return a;
    else return b;
}
 
ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}
 
int main(void){
    int N; cin >> N;
    vector<int> h(N+10, 0); for(int i = 0; i < N; i++) cin >> h[i];
    vector<int> dp(N+10, INF);
    
    dp[0] = 0;
    for(int i = 0; i < N; i++){
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
class Solution:
  def solve(self, sHeights):
    if not sHeights or len(sHeights) == 0:
      return 0
    
    n = len(sHeights)
    
    dp = [0 for _ in range(n)]
    dp[0] = 0
    dp[1] = abs(sHeights[1] - sHeights[0])
    
    for i in range(2, n):
      dp[i] = min(dp[i-1] + abs(sHeights[i] - sHeights[i-1]), dp[i-2] + abs(sHeights[i] - sHeights[i-2]))
      
    return dp[n-1]
  
sol = Solution()

n = int(input().strip())

s = list(map(int, input().strip().split()))

print(sol.solve(s))

Measured memory_bytes: 13908
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

using Graph = vector<vector<P>>;
Graph G;
vector<int> res;

//v:は現在見ている頂点, p:vの親
void dfs(int v, int p, int c) {
    res[v] = c;
    for (auto nv : G[v]) {
        if (nv.first == p) continue;
        if (nv.second & 1) dfs(nv.first, v, 1 - c);
        else dfs(nv.first, v, c);
    }
}

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

    G = vector<vector<P>>(N);
    res = vector<int>(N, 0);

    rep(i, N - 1) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        G[u].push_back(P(v, w));
        G[v].push_back(P(u, w));
    }

    dfs(0, -1, 0);

    rep(i, N) {
        cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 8960
#include<iostream>
#include<iomanip>
#include<sstream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<numeric>

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = atan(1.0) * 4 ;
double eps = 1e-10 ;

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int num,el = 1,x,y;
  while(cin >>num){
    if(num == 0){
      break;
    }
    el = 1;
    deque<di> ddi(num,di(num,0));
    x = num/2+1,y = num/2;
    ddi[x][y] = el;
    while(el != num*num){
      ++x ;++y ;
      if(x >= num){
        x = 0;
      }
      if(y >= num){
        y = 0;
      }
      if(ddi[x][y] == 0){
        ++el ;
        ddi[x][y] = el ;
      }
      else{
        --y;
        ++x;
        if(y < 0 ){
          y = num-1;
        }
        if(x >= num){
          x = 0;
        }
        ++el ;
        ddi[x][y] = el ;
      }
    }
    rep(n,num){
      rep(n2,num){
        scout(4) << ddi[n][n2] ;
      }
      cout << endl ;
    }
  }
  return 0;
}

Measured memory_bytes: 3220
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <climits>
#include <utility>
#include <deque>
#include <list>
#include <stdexcept>
using namespace std;

int main()
{
	cout << fixed << setprecision(6);
	int n, d;
	cin >> n >> d;


	cout << (n + (2 * d)) / (2 * d + 1) << endl;

	return 0;
}

Measured memory_bytes: 256
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;

cin>>n;

      ll ara[n+2];



      for(i=0; i<n; i++)
      {
          cin>>ara[i];

          sum+=ara[i];
      }

      ll mi=1e18;

      for(i=0; i<n-1; i++)
      {
          ans+=ara[i];

          cnt=sum-ans;



          mi=min(mi,abs(ans-cnt));
      }

      cout<<mi<<endl;











}



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

#define llint long long int

using namespace std;

int N, A, B, C;
vector<string> s;
vector<char> ans;

bool solve(int i, int a, int b, int c){
    if(A + a < 0 || B + b < 0 || C + c < 0){
        return false;
    }
    if(a < -2 || 2 < a || b < -2 || 2 < b || c < -2 || 2 < c){
        return false;
    }
    if(i == N){
        return true;
    }
    if(s[i] == "AB"){
        ans[i] = 'A';

        bool ret = solve(i + 1, a + 1, b - 1, c);

        if(ret == false){
            ans[i] = 'B';
            ret = solve(i + 1, a - 1, b + 1, c);
        }
        return ret;
    }
    if(s[i] == "AC"){
        ans[i] = 'A';

        bool ret = solve(i + 1, a + 1, b, c - 1);

        if(ret == false){
            ans[i] = 'C';
            ret = solve(i + 1, a - 1, b, c + 1);
        }
        return ret;
    }
    if(s[i] == "BC"){
        ans[i] = 'B';

        bool ret = solve(i + 1, a, b + 1, c - 1);

        if(ret == false){
            ans[i] = 'C';
            ret = solve(i + 1, a, b - 1, c + 1);
        }
        return ret;
    }
    return false;
}

int main(){
    cin >> N >> A >> B >> C;

    s = vector<string>(N);

    for(int i = 0; i < N; i ++){
        cin >> s[i];
    }
    ans = vector<char>(N);

    if(solve(0, 0, 0, 0) == true){
        cout << "Yes" << endl;

        for(int i = 0; i < N; i ++){
            cout << ans[i] << endl;
        }
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 9780
#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
int main(){
	int N,K,p[200000];
	long sum=0,maxL;
	cin>>N>>K;
	for(int i=0;i<K;i++){
		cin>>p[i];
		p[i]++;
		sum+=p[i];
	}
	maxL=sum;
	for(int i=K;i<N;i++){
		cin>>p[i];
		p[i]++;
		sum+=p[i]-p[i-K];
		maxL=max(maxL,sum);
	}
	cout<<std::setprecision(10)<<(double)maxL/2;
	return 0;
}

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

int main(){
  double r;
  cin >> r;
  double pi = 3.14159265358979;
  printf("%.9lf\n",2*r*pi);
  return 0;
}


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

int main(){

	int a[3000] = { 0 };
	int c[3000] = { 0 };
	int b[10000] = { 0 };
	int x = 0;


	for (int i = 0; i < 10000; i++){
		cin >> a[i] >> c[i];
		if (a[i] == 0 && c[i] == 0){
			break;
		}
	}
	for (int i = 0; i < 10000;i++){
		if (a[i] == 0&&c[i]==0){
			break;
		}
		if (a[i] < c[i]){
			cout << a[i] << " " << c[i] << endl;
		}
		else{
			cout << c[i] << " " << a[i] << endl;
		}
		
	}

}

Measured memory_bytes: 3048
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};

int main(){
	ll A,B,C;
	cin>>A>>B>>C;
	ll count=0;
	while(A%2==0 && B%2==0 && C%2==0){
		count++;
		ll a,b,c;
		a=B/2+C/2;
		b=A/2+C/2;
		c=A/2+B/2;
		A=a;
		B=b;
		C=c;
		if(count==1000000){
			cout<<-1<<endl;
			return 0;
		}
		//cout<<A<<" "<<B<<" "<<C<<endl;
	}
	cout<<count<<endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()

left_W = [0] * N
right_E = [0] * N
for i in range(N-1):
    if S[i] == "W":
        left_W[i+1] = left_W[i] + 1
    else:
        left_W[i+1] = left_W[i]

    if S[N-i-1] == "E":
        right_E[N-i-2] = right_E[N-i-1] + 1
    else:
        right_E[N-i-2] = right_E[N-i-1]


min_count = 100000000

for i in range(N):
    change_count = left_W[i] + right_E[i]
    if change_count < min_count:
        min_count = change_count
print(min_count)


Measured memory_bytes: 17636
#include<iostream>
using namespace std;
int main() {
	int n, x, count;
	while (true) {
		count = 0;
		cin >> n >> x;
		if (n == 0 && x == 0)break;
		for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) 
			if (x-i-j>j&&x-i-j<=n) count++;
		cout << count << endl;
	}
}


Measured memory_bytes: 3080
#include <stdio.h>
#include<string.h>
int main()
{
    char a[19];
    int i,k;
    gets(a);
    k=strlen(a);
    for(i=0;i<k;i++)
    {
        if(a[i]==',')
            a[i]=' ';
    }
    for(i=0;i<k;i++)
        printf("%c",a[i]);
    return 0;
}


Measured memory_bytes: 128
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    string s;
    cin >> n >> s;

    ll ans = 1;
    ll cur = 0;
    for (int i = 0; i < 2 * n; i++) {
        if (s[i] == 'B') {
            if (cur % 2 == 0) {
                cur++;
            } else {
                ans = ans * cur % MOD;
                cur--;
            }
        } else {
            if (cur % 2 == 0) {
                ans = ans * cur % MOD;
                cur--;
            } else {
                cur++;
            }
        }
    }

    if (cur != 0) {
        ans = 0;
    }

    for (ll i = 1; i <= n; i++) {
        ans = ans * i % MOD;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 832
N,M = map(int, input().split())
connect = [[0,0,0]]
on_off = [0]*(N+1)
result = 0
for _ in range(M):
    k = list(map(int, input().split()))
    connect.append(k[1:])
p = list(map(int, input().split()))

for cnt in range(0,2**N):
    bin_str = list(format(cnt, 'b'))
    i = len(on_off)-len(bin_str)
    for num in bin_str:
        on_off[i] = int(num)
        i += 1
    for i in range(1,M+1):
        total = 0
        for j in connect[i]:
            total += on_off[j]
        if total % 2 != p[i-1]:
            break
        elif i == M:
            result += 1
print(result)


Measured memory_bytes: 3064
#2019=3*673

L,R = map(int, input().split())

if R-L>2019:
    print(0)
else:
    amalist = [i%2019 for i in range(L, R+1)]
    min_value=2020
    for i in range(len(amalist)-1):
        for j in range(i+1, len(amalist)):
            if (amalist[i]*amalist[j])%2019 < min_value:
                min_value = (amalist[i]*amalist[j])%2019
    print(min_value)

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <regex>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

const int MAX = 200010;
const long long INF = 1 << 30;



int main() {
	int N;
	long long a[MAX];

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		a[i] -= i + 1;
	}

	sort(a, a + N);

	long long mid = a[N / 2];
	long long ans = 0;

	for (int i = 0; i < N; i++) {
		ans += abs(mid - a[i]);
	}

	cout << ans << endl;

	return 0;
}


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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i];
        int x;
        cin >> x;
        for (int j = 0; j < x; j++) {
            int y;
            cin >> y;
            y--;
            b[i] |= 1 << y;
        }
    }

    vector<int> d(1 << n, MAX_INT);
    d[0] = 0;
    for (int i = 0; i < (1 << n); i++) {
        if (d[i] == MAX_INT) continue;
        for (int j = 0; j < m; j++) {
            int ii = i | b[j];
            d[ii] = min(d[ii], d[i] + a[j]);
        }
    }
    if (d[(1 << n) - 1] == MAX_INT) cout << -1; else cout << d[(1 << n) - 1];

    return 0;
}

Measured memory_bytes: 384
const main = input => {
  const i = input.split(" ").map(e => parseInt(e))
  const [a, b, c, d] = i
  return Math.ceil(c / b) <= Math.ceil(a / d) ? "Yes" : "No"
}

console.log(main(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 29600
#include<iostream>
using namespace std;
int main()
{
	int S,T;
	int a,b,c,d,e,f,g,h;
	cin>>a>>b>>c>>d;
	cin>>e>>f>>g>>h;
	S=a+b+c+d;
	T=e+f+g+h;
	if(S<T){
	cout<<T<<endl;
	}
	else{
	cout<<S<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160