akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

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()
{
    int n;
    cin >> n;
    vector<int> l(n);
    for(int i = 0; i< n; i++){
        cin >> l[i];
    }
    int ans = 0;
    sort(l.begin(), l.end());

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

    for(int i = 0; i< n-2; i++){
        for(int j = i+1; j< n-1; j++){
            //int mx = max(l[i]- l[j], l[j]-l[i]);
            ans += (lower_bound(l.begin(),l.end() ,l[i]+l[j])-l.begin())-j-1;
            
            //cout << ans << endl;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int x,y,w,h,r;
	cin >> w >> h >> x >> y >> r;
	
	if((x<=w-r)&&(x>=r)&&(y<=h-r)&&(y>=r )) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 3072
using System;
using System.Collections.Generic;
public class Hello{
    public static void Main(){
        string s = Console.ReadLine();
        char a = s[0];
        char b = s[2];
        if(a < b){
            Console.WriteLine("<");
        }else if(a > b){
            Console.WriteLine(">");
        }else{
            Console.WriteLine("=");
        }
    }
}


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

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

  vector<ll> neg;
  int z = 0;
  rep(i,n) {
    if (a[i] < 0) neg.push_back(a[i]);
    if (a[i] == 0) z++;
  }

  ll ans = 0;
  rep(i,n) ans += abs(a[i]);

  if (neg.size() % 2 == 1 && z == 0) {
    ll mn = 100100100;
    rep(i,n) mn = min(mn,abs(a[i]));
    ans -= mn*2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4956
char s[9999],t[999];
main(i,j,m,r){
	scanf("%s",&s);
	for(i=j=0;i<strlen(s);){
		if(s[i]=='e')t[j++]='e',i+=3;
		else t[j++]='c',i+=7;
	}
	t[j]=0;
	for(m=i=0;i<strlen(t);){
		for(j=i+1;j<strlen(t);j++)if(t[j]==t[j-1])break;
		if(m<j-i)m=j-i,r=t[j-1];
		i=j;
	}
	puts(r=='c'?"chicken":"egg");
	exit(0);
}

Measured memory_bytes: 524
n, k, l = [int(i) for i in input().split()]
P = [[int(i) for i in input().split()] for j in range(k)]
R = [[int(i) for i in input().split()] for j in range(l)]

class UnionFind():
  def __init__(self, elements):
    self.elements = elements
    self._root = {}
    for e in self.elements:
      self._root[e] = e
    
  def unite(self, x, y):
    x = self.root(x)
    y = self.root(y)
    if not x == y:
      self._root[x] = y
    
  def root(self, x):
    if not self._root[x] == x:
      self._root[x] = self.root(self._root[x])
    return self._root[x]
  
  def count(self):
    cnt = {}
    for e in self.elements:
      cnt[self.root(e)] += cnt.get(self.root(e), 0)
      
    for e in self.elements:
      yield cnt.get(e, 0)
      
  def get_union(self):
    union = {}
    for e in self.elements:
      if self.root(e) in union:
        union[self.root(e)].add(e)
      else:
        union[self.root(e)] = {e}
    return union
      
  
road = UnionFind(range(1, n+1))
rail = UnionFind(range(1, n+1))

for i in range(k):
  road.unite(P[i][0], P[i][1])
  
for i in range(l):
  rail.unite(R[i][0], R[i][1])

ans = {}
key = []
for e in range(1, n+1):
  key.append((road.root(e), rail.root(e)))
  ans[key[-1]] = ans.get(key[-1], 0) +1
  
for k in key:
  print(ans[k], end=' ')

Measured memory_bytes: 110056
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000007
int u[1100000];
vector<int> y;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0;
  string s,w;
  cin >>s>>w;
  for(int n=0;n<s.size();n++){
    if(s[n]=='1') d+=1;
    if(s[n]=='2') d+=2;
    if(s[n]=='3') d+=3;
    if(s[n]=='4') d+=4;
    if(s[n]=='5') d+=5;
    if(s[n]=='6') d+=6;
    if(s[n]=='7') d+=7;
    if(s[n]=='8') d+=8;
    if(s[n]=='9') d+=9;
    d=d*10;
  }
  for(int n=0;n<w.size();n++){
    if(w[n]=='1') d+=1;
    if(w[n]=='2') d+=2;
    if(w[n]=='3') d+=3;
    if(w[n]=='4') d+=4;
    if(w[n]=='5') d+=5;
    if(w[n]=='6') d+=6;
    if(w[n]=='7') d+=7;
    if(w[n]=='8') d+=8;
    if(w[n]=='9') d+=9;
    d=d*10;
  }
  d=d/10;
  double h=sqrt(d);
  int o=h;
  if(o==h) cout <<"Yes\n";
  else cout <<"No\n";
  return (0);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str ;
    int[] a = new int[128];
    int i; 
    while(sc.hasNext()){
      str = sc.nextLine().toLowerCase();
    for(i=0;i<str.length();i++){
      a[str.charAt(i)]++;;
    }
    }
    for(char ch='a';ch<='z';ch++){
      System.out.println(ch+" : "+a[ch]);
    }
    sc.close();
    
  }
}



Measured memory_bytes: 26144
a,b,ab,x,y = gets.split.map(&:to_i)
case1 = a*x+b*y
case2 = x<y ? ab*2*x+b*(y-x) : ab*2*y+a*(x-y)
case3 = ab*2*[x,y].max
p [case1,case2,case3].min

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

int main() {
  int a, b, c, d; cin >> a >> b >> c >> d;

  int l, r; l=max(a, c); r=min(b, d);

  if (l < r) p(r-l);
  else p(0);
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args){
    Scanner nyuryoku = new Scanner(System.in);
    int n = nyuryoku.nextInt();
    int[] num = new int[n];
    for (int i = 0; i < n; i++){
      num[i] = nyuryoku.nextInt();
    }
    int ans = prime(n, num);
    System.out.println(ans);
  }
  public static int prime(int n, int[] num){
    int count = 0;
    IN:for (int i = 0; i < n; i++){
      for (int j = 2; j*j <= num[i];j++)
        if (num[i] % j == 0) {continue IN;}
    count++;
    }
    return count;
  }
}


Measured memory_bytes: 43168
#include <iostream>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    int a[n][m], b[m],c[n]={};
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<m; j++) cin>>a[i][j];
    }
    for (int i=0; i<m; i++) cin>>b[i];
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<m; j++) c[i]+=a[i][j]*b[j];
        cout<<c[i]<<'\n';
    }
    return 0;
}



Measured memory_bytes: 3148
#include <stdio.h>
int main(void) {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if (a <= b)
    if (c <= b)
      printf("%d\n", a + c);  // ac
    else
      printf("%d\n", a + b);  // ab
  else {
    if (a <= c)
      printf("%d\n", a + b);  // ab
    else
      printf("%d\n", b + c);  // bc
  }
  return 0;
}

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

int main(){
  int MAX = 1000000;
  int n;
  int cnt=0;
  vector<bool> num(n);
  
  for(int i=0; i<MAX; i++){
    num[i] = true;
  }
  num[0] = false;
  num[1] = false;

  for(int i=2; i<=sqrt(MAX); i++){
    if(num[i]){
      for(int j=i*2; j<MAX; j+=i){
	num[j] = false;
      }
    }
  }

  while(cin >> n){
    cnt = 0;
    for(int i=0; i<=n; i++){
      if(num[i]) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 16000
/**
 *    author:  math2do
 *    created: 20.04.2020 18:08:31 IST
**/

#include <bits/stdc++.h>

using namespace std;

template <typename T> 
inline bool smax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector <pair <int, int> > arr(n);
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    arr[i] = {v, i};
  }
  sort(arr.begin(), arr.end());
  vector <vector <long long>> dp(n, vector <long long>(n, -1));
  function <long long (int, int, int)> recur = [&](int L, int H, int cur) -> long long {
    if (cur == -1) return 0;
    if (dp[L][H] != -1) return dp[L][H];
    long long ans = 0;
    int pos = arr[cur].second;
    int v = arr[cur].first;
    smax(ans, (long long) v * abs(pos - L) + recur(L + 1, H, cur - 1));
    smax(ans, (long long) v * abs(pos - H) + recur(L, H - 1, cur - 1));
    return dp[L][H] = ans;
  };
  long long ans = recur(0, n - 1, n - 1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 34844
#pragma GCC optimize("Ofast")

//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

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() {
  // 高速化
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);


    ll n, m;
    cin >> n >> m;
    ll count = 0;

    REP(i, m){
        int a;
        cin >> a;
        count += a;
    }
    ll ans = n-count;
    if(ans < 0){
     cout <<   "-1"  << "\n"; 
    }else{
        cout << ans << "\n";
    }


    return 0;



}


Measured memory_bytes: 3672
n = int(input())
i = 0
ans = []
if n == 0:
    print(0)
    quit()
while n:
    i += 1
    if n%(2**i):
        n -= (-2)**(i-1)
        ans.append("1")
    else:
        ans.append("0")
print("".join(ans[::-1]))


Measured memory_bytes: 9104
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fixed cout.setf(ios::fixed);
#define rep1    for( i=0; i<n; i++)
#define Precise cout.precision(7);
using namespace std;

int main()
{
    ll a,b;
    cin>>a>>b;
    if(a==1||b==1)
    cout<<1<<endl;
    else
    cout<<(a*b+1)/2<<endl;

    return 0;
}





Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
typedef pair<int, P> PP;
int dp[7][5005];
int p[5010];
int cp[5010];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> p[i];
	int ans = 100000000;
	for (int x = 0; x <= p[0]; x++) {
		rep(i, n)cp[i] = p[i];
		int res = x;
		cp[0] -= x;
		rep(i, n - 1) {
			res += cp[i] * 2;
			cp[i + 1] -= cp[i];
			if (cp[i + 1] < 0)cp[i + 1] = 0;
		}
		res += max(0ll, cp[n - 1]);
		ans = min(ans, res);
	}
	cout << ans << endl;
}



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

typedef long long ll;
const int mod=1145411919;
const int p=810;

string s,t;
int ans;
ll pw[16000005];
ll h[16000005];
ll ht[16000005];
int suf[16000005];

inline ll gh(int x){
    if(x+t.size()>s.size())return -1;
    return (h[x+t.size()-1]-h[x-1]*pw[t.size()]%mod+mod)%mod;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>s>>t;
    while(s.size()<t.size()*2)s=s+s;
    s=s+s;
    s=s+s;
    s=s+s;
    pw[0]=1;
    for(int i=1;i<=16000000;i++){
        pw[i]=pw[i-1]*p%mod;
    }
    h[0]=s[0]-'a'+1;
    for(int i=1;i<s.size();i++){
        h[i]=(h[i-1]*p+s[i]-'a'+1)%mod;
    }
    ht[0]=t[0]-'a'+1;
    for(int i=1;i<t.size();i++){
        ht[i]=(ht[i-1]*p+t[i]-'a'+1)%mod;
    }
    for(int i=0;i<s.size();i++){
        suf[i]=ht[t.size()-1]==gh(i);
    }
    for(int i=s.size()-t.size();i>=0;i--){
        if(suf[i])suf[i]+=suf[i+t.size()];
        ans=max(ans,suf[i]);
    }
    if(ans+1>=s.size()/t.size()){
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 337616
#include <iostream>
using namespace std;
int main(){
    int A;
    int B;
    cin >> A >> B;
    if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <string.h>

using namespace std;

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

int main(){
    int w, h;
    string s[59];
    int step[30][30];
    while(cin >> w >> h, w){
        getline(cin, s[0]);
        for(int i=0;i<2*h-1;i++) getline(cin, s[i]);
        for(int i=0;i<2*h-1;i++) s[i] += " ";
        memset(step, -1, sizeof(step));
        queue< pair<int, int> > qu; qu.push(make_pair(0,0));
        step[0][0] = 1;
        while(!qu.empty()){
            pair<int, int> p = qu.front(); qu.pop();
            int x = p.first, y = p.second;
            for(int i=0;i<4;i++){
                int nx = x+dx[i], ny = y+dy[i];
                if(nx<0||h<=nx||ny<0||w<=ny) continue;
                if(s[2*x+dx[i]][2*y+dy[i]]=='1') continue;
                if(step[nx][ny]!=-1) continue;
                step[nx][ny] = step[x][y] + 1;
                qu.push(make_pair(nx, ny));
            }
        }
        cout << (step[h-1][w-1] == -1 ? 0 : step[h-1][w-1]) << endl;
    }
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n, d, a;
    cin >> n >> d >> a;
    vector<pair<ll, ll>> xh(n);
    for (int i = 0; i < n; ++i) {
        cin >> xh[i].first >> xh[i].second;
    }
    sort(xh.begin(), xh.end());
    ll ret = 0;
    deque<pair<ll, ll>> dmg;
    ll currdmg = 0;
    for (int i = 0; i < n; ++i) {
        while (!dmg.empty() && dmg.front().first < xh[i].first) {
            currdmg -= dmg.front().second;
            dmg.pop_front();
        }
        xh[i].second -= currdmg;
        if (xh[i].second > 0) {
            ll t = (xh[i].second + a - 1) / a;
            ret += t;
            currdmg += t * a;
            dmg.emplace_back(xh[i].first + 2 * d, t * a);
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 4992
hw = []
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    hw.append([h, w])

for h, w in hw:
    odd_line = ''
    even_line = ''
    if w == 1:
        odd_line = '#'
        even_line = '.'
    elif w % 2 == 0:
        odd_line = '#.' * (w // 2)
        even_line = '.#' * (w // 2)
    else:
        odd_line = '#.'*((w-1) // 2) + '#'
        even_line = '.#'*((w-1) // 2) + '.'

    for hi in range(h):
        if hi % 2 == 0:
            print(odd_line)
        else:
            print(even_line)

    print('')



Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
const int N=200010;

struct data{
	int l,r;
	bool operator<(const data&b)const{
		return l==b.l?r>b.r:l<b.l;
	}
}x[N];

int a[N];

bool cmp(int a,int b){return a>b;}

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d%d",&x[i].l,&x[i].r);
	sort(x+1,x+1+n);
	int cnt=0;
	
//	puts("sort");for(int i=1;i<=n;i++) printf("%d %d\n",x[i].l,x[i].r);
	
	int l=1;
	for(int i=1;i<=n;i++){
		if(x[i].l<l||l>m) a[++cnt]=x[i].r;
		else l++;
	}
	int ans=0;
	sort(a+1,a+cnt+1,cmp);
	int r=m;
	for(int i=1;i<=cnt;i++){
		if(a[i]>r||r<l) ans++;
		else r--;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	int n = N % 10;
	if (n == 3) { cout << "bon\n"; }
	else if (n == 0 || n == 1 || n == 6 || n == 8) {
		cout << "pon\n";
	} else {
		cout << "hon\n";
	}

	return 0;
}


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

int main() {
	
	string s;
	cin >> s;
	int n = s.size();
	int cnt = 0;
	for(int i=0;i<(n+1)/2;i++){
		if(s[i]!=s[n-i-1]) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
# min(n-1,k)以下の自然数mに対してnCm*n-1Cmの和を求める
n, k = map(int, input().split())
p = 10 ** 9 + 7
g1 = [1, 1]
g2 = [1, 1]

# 先にn!と(n!)^(-1)のリストを作っておく
for i in range(2, 2 * 10 ** 5 + 1):
    g1.append((g1[-1] * i) % p)
    g2.append((g2[-1] * pow(i, p-2, p)) % p)


def cmb(n, r):
    return g1[n] * g2[r] * g2[n - r] % p


ans = 0
for m in range(min(n - 1, k) + 1):
    ans += cmb(n, m) * cmb(n - 1, m) % p
print(ans % p)


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 0
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

int N, L;

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

    int all = 0;
    for(int i = 1; i <= N; ++i) {
        all += (L + i - 1);
    }
    DBG("all: %lld\n", all);
    int ans_diff = LLINF;
    int ans_val = 0;
    for(int i = 1; i <= N; ++i) {
        int cand = abs(L + i - 1);
        DBG("cand: %lld\n", cand);
        if(ans_diff > cand ) {
            ans_diff = cand;
            ans_val = all - (L + i - 1);
            DBG("ans_diff: %lld\n", ans_diff);
            DBG("ans_val:  %lld\n", ans_val);
        }
    }
    printf("%lld\n", ans_val);

    return 0;
}


Measured memory_bytes: 256
while (m,f,r=gets.split.map &:to_i)!=[-1,-1,-1]
s=m+f
if m==-1||f==-1
puts"F"
next
end
puts"A" if 79<s
puts"B" if 64<s&&s<80
puts"C" if (49<s&&s<65)||(29<s&&s<50&&49<r)
puts"D" if 29<s&&s<50&&r<50
puts"F" if s<30
end


Measured memory_bytes: 6872
N = int(input())
if N == 1:
    print(1)
else:
    m = 0
    ans = 0
    for n in range(1, N + 1):
        t = 0
        i = n
        while(i % 2 == 0):
            i /= 2
            t += 1
        if t > m:
            m = t
            ans = n
    print(ans)

Measured memory_bytes: 3060
N, K = map(int, input().split())
a = list(map(int, input().split()))
mae = 0
naka = sum(a[:K])
usiro = 0
for i in range(K, N):
    if a[i]>0:
        usiro+=a[i]
ans = max(mae+naka+usiro, mae+usiro)
for i in range(N-K):
    naka+=a[i+K]-a[i]
    if a[i]>0:
        mae+=a[i]
    if a[i+K]>0:
        usiro-=a[i+K]
    ans = max(ans, mae+naka+usiro, mae+usiro)
print(ans)

Measured memory_bytes: 14544
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
long mod = (long) 1e9 + 7;

int main(){
    
    string s;
    cin >> s;
    rep(i,3){
        if(s[i] == '7'){
            cout << "Yes" << "\n";
            return 0;
        }
    }
    
    cout << "No" << "\n";
    
    return 0;
}



Measured memory_bytes: 3128
n = int(input())
ds = {}
for i in range(1, n+1):
    s, p = input().split()
    dp = ds.get(s,{})
    dp[int(p)] = i
    ds[s] = dp
for si in sorted(ds.keys()):
    s = ds[si]
    for pi in sorted(s.keys(), reverse=True):
        print(s[pi])
 

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

int main(){
  ll n,k;cin >> n >> k;
  ll p = n/k;
  ll t = n-p*k;
  ll dest = min(t, abs(t-k));

  cout << dest << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] a = new int[N];
    for(int i = 0; i < N; i++ ){
      a[i] = sc.nextInt();
    }
    Main abc118C = new Main();
    System.out.println(abc118C.solve(a));
  }

  public int solve(int[] a) {
    ABC118CSolve abc118CSolve = new ABC118CSolve();
    return abc118CSolve.solve(a);
  }

  class ABC118CSolve{
    public int solve(int[] a){
      while(a.length != 1){
        Arrays.sort(a);
        Integer min = a[0];
        List<Integer> next = new ArrayList();
        next.add(min);

        for(int i=1; i < a.length; i++ ){
          int b = a[i] % min;
          if(b > 0) next.add(b);
        }
        a = new int[next.size()];
        for(int j = 0; j < next.size(); j++ ){
          a[j] = next.get(j);
        }
      }
      return a[0];
    }
  }
}


Measured memory_bytes: 52128
#include <iostream>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
using ll = long long;
const ll MOD = 1000000007;
int main() {
	ll n, k;
	cin >> n >> k;
	ll sum = 0;
	for (ll i = k; i <= n + 1; i++) {
		sum += i * (n - i + 1) + 1;
		sum %= MOD;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3604
// ConsoleApplication7.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include <stdio.h>

static const int N = 1000;

void trace(int A[], int n){
	int i;
	for (i = 0; i < n; i++){
		if (i > 0) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}

int main(int argc, char* argv[])
{
	int n, i, j;
	int key;
	int A[N + 1];
	scanf("%d", &n);

	for (i = 0; i < n; i++) scanf("%d", &A[i]);
	trace(A, n);
	for (i = 1; i < n; i++) {
		key = A[i];
		for (j = i - 1; j >= 0 && A[j] > key; j--) {
			A[j + 1] = A[j];
		}
		A[j + 1] = key;
		trace(A, n);
	}

	return 0;
}

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

using namespace std ;

int p[20];
int n ;

int main ()
{
	int i ;
	scanf("%d",&n);
	for ( i=1 ; i<=n ; i++ ) scanf("%d",p+i);
	sort(p+1,p+n+1);
	int sum=0;
	for ( i=1 ; i<=n ; i++ ) sum+=p[i];
	sum-=p[n]/2;
	printf("%d\n",sum);
	return 0 ;
}

Measured memory_bytes: 256
N, K = list(map(int, input().split()))
S = input()

S = S + 'E'   # 終端処理
ans = -1    # 答えの初期値（十分に小さい値）

# 立った人の連続の数
if (S[0] == '0'):
    stand = 1
else:
    stand = 0

L = 0
R = 0

# 尺取り法
while (R < N):
    # 右端を進めることが可能（立った人の連続の数がK以下）なら、右端を進める
    if (stand <= K):
        # 立った人の連続の集合数が増えるなら1足す
        if (S[R] == '1' and S[R + 1] == '0'):
            stand += 1
        ans = max(ans, R - L + 1)
        R += 1
    # 進められない場合、左端と右端が同じなら両者を進める
    # 左端が右端を追い越さないための処理
    elif (L == R):
        L += 1
        R += 1
    # それ以外は左端のみを進める
    else:
        # 立った人の連続の数が減るなら1減らす
        if (S[L] == '0' and S[L + 1] == '1'):
            stand -= 1
        L += 1

print(ans)


Measured memory_bytes: 3316
/*******************************
Author:Morning_Glory
LANG:C++
Created Time:2019骞?7鏈?0鏃?鏄熸湡鍏?21鏃?8鍒?1绉?
*******************************/
#include <cstdio>
#include <fstream>
#define ll long long
using namespace std;
//{{{cin
struct IO{
	template<typename T>
	IO & operator>>(T&res){
		res=0;
		bool flag=false;
		char ch;
		while((ch=getchar())>'9'||ch<'0')	 flag|=ch=='-';
		while(ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch^'0'),ch=getchar();
		if (flag)	 res=~res+1;
		return *this;
	}
}cin;
//}}}
int main()
{
	int n;
	cin>>n;
	printf("%d\n",3*n*n);
	return 0;
}

Measured memory_bytes: 128
#! python3
# findingMissingCards.py - 見つからなかったカードを出力するプログラム

# 全体のカードセットの辞書をつくる
cards = {}

marks = ['S', 'H', 'C', 'D']

for mark in marks:
  cards.setdefault(mark, [])
  for i in range(13):
    cards[mark].append(i + 1)

# print(cards)

# 入力されるカードの数を受け取る
number_of_cards = int(input())

# 入力されたカードを、全体のカードセットから削除する
for c in range(number_of_cards):
  card = input().split()
  card_mark = card[0]
  card_num = int(card[1])
  if card_num in cards[card_mark]:
    cards[card_mark].remove(card_num)

# print(cards)

# 残りのカードセットを（SHCDの順で出力する）
for mark in marks:
  each_mark_sets = cards[mark]
  for c in each_mark_sets:
    print(mark, c)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n, A, B, C, D;
string s;

int main() {
    cin >> n >> A >> B >> C >> D;
    cin >> s;
    A--; B--; C--; D--;
    bool flg = true;
    for(int i = max(1, A); i < max(C, D); ++i) {
        if(s[i-1] == '#' && s[i] == '#') {
            flg = false;
            break;
        }
    }

    if(!flg) {
        // 岩が2連続なのでどうやっても無理
        cout << "No" << endl;
    }else {
        if(C < D) {
            // Cの方が手前にゴールがある
            cout << "Yes" << endl;
        }else {
            // Dの方が手間にゴールがある
            bool flg2 = false;
            for(int i = B; i <= D; ++i) {
                if(s[i] == '.') {
                    if(s[i-1] == '.' && s[i+1] == '.') {
                        flg2 = true;
                        break;
                    }
                }
            }
            if(flg2) cout << "Yes" << endl;
            else cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 3728
N = int(input())
Michelin = dict()
seen = []
number = 1
for _ in range(N):
    shop,point = map(str,input().split())
    if shop not in seen:
        Michelin[shop] = [[],[]] #moscow:{[[],[]]} point,number
        Michelin[shop][0].append(int(point)) 
        Michelin[shop][1].append(number)
        number += 1
        seen.append(shop)
    else:
        Michelin[shop][0].append(int(point))
        Michelin[shop][1].append(number)
        number += 1
seen.sort() #店の名前が辞書順になる。
#{'khabarovsk': [[20, 40], [1, 6]], 'moscow': [[10, 60], [2, 5]], 'kazan': [[50, 35], [3, 4]]}
for shop in seen:
    while Michelin[shop][0] != []:
        shokai = max(Michelin[shop][0])
        bango = Michelin[shop][0].index(shokai)
        print(Michelin[shop][1][bango])
        Michelin[shop][0].remove(shokai)
        Michelin[shop][1].remove(Michelin[shop][1][bango])

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
 
public class Main {

    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        int H,W;
 
        String work[] = new String[2];
 
        while(true){
 
            try {
                work = br.readLine().split("[\\s]+");
                if(work[0].equals("0") && work[1].equals("0"))break;
 
                H = Integer.parseInt(work[0]);
                W = Integer.parseInt(work[1]);
 
                for(int row = 0; row < H; row++){
                    for(int col = 0; col < W; col++){
                        System.out.printf("#");
                    }
                    System.out.printf("\n");
                }
 
                System.out.printf("\n");
 
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}


Measured memory_bytes: 61808
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll f(ll h,ll n)
{
    ll a[100009],sum=0;
    for(ll i=1; i<=n; i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(h<=sum)
        cout<<"Yes";
    else
        cout<<"No";
    cout<<endl;
}
int main()
{
    ll h,n;
    while(cin>>h>>n)
    {
        f(h,n);
    }
    return 0;
}


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

using namespace std;

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

ll comb[55][55];

void init_comb (void){
	rep (i, 55) rep (j, 55) comb[i][j] = 0LL;
	rep (i, 55) comb[i][0] = comb[0][i] = 1LL;
	
	for (int k = 1; k < 55; ++k){
		for (int j = 1; j <= k; ++j){
			int i = k - (j - 1);
			comb[i][j] = comb[i][j-1] + comb[i-1][j];
		} // end for
	} // end for
}

ll nCr(int n, int r){
	if (n < r) return 0LL;
	if (n / 2 < r){
		r = n - r;
	} // end if

	return comb[n-r][r];
}

int main()
{
	init_comb();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, A, B; cin >> N >> A >> B;
	vector<ll> v(N, 0LL);
	rep (i, N){
		cin >> v[i];
	} // end rep

	sort(ALL(v), greater<ll>());
	double max_average = 0.0;
	rep (i, A){
		max_average += (double)v[i];
	} // end rep
	max_average /= (double)A;

	int a_th_val_num = 0, a_th_val_pos = 0;
	rep (i, N){
		if (v[i] == v[A-1]){
			++a_th_val_num;
			if (i < A){
				++a_th_val_pos;
			} // end if
		} // end if
	} // end rep

	ll cnt = 0LL;
	if (a_th_val_pos == A){	// v[0] = ... = v[A-1]
		for (a_th_val_pos = A; a_th_val_pos <= B; ++a_th_val_pos){
			cnt += nCr(a_th_val_num, a_th_val_pos);
		} // end for
	}else{
		cnt += nCr(a_th_val_num, a_th_val_pos);
	} // end if

	cout.precision(20);
	cout << fixed << max_average << endl;
	cout << cnt << endl;
			
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;
int main(){
  int R[MAX], n;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> R[i];
  int maxv = -2000000000;
  int minv = R[0];
  for(int i = 1; i < n; i++){
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }
  cout << maxv << endl;
  return 0;
}


Measured memory_bytes: 3884
def main():
    s = int(input())

    ans = solve(s)
    print(ans)


def solve(s):
    """
    数列 a={a1,a2,a3,......} は、以下のようにして定まります。
    初項 s は入力で与えられる。

    関数 f(n) を以下のように定める
    n が偶数なら f(n)=n/2
    n が奇数なら f(n)=3n+1

    i=1 のとき ai=s
    i>1 のとき ai=f(a(i−1))

    このとき、次の条件を満たす最小の整数 mを求めてください。
    a(m) = a(n) (m>n) を満たす整数 n が存在する。
    制約: 1 ≦ s ≦ 100
    入力はすべて整数である。
    a のすべての要素、および条件を満たす最小の m は 1000000 以下となることが保証される。
    """
    bef_a = s
    d = {s: None}

    def f(n):
        if n % 2 == 0:
            return n // 2
        else:
            return 3 * n + 1

    for i in range(2, 1000000 + 1):
        bef_a = f(bef_a)
        if bef_a in d:
            return i

        d[bef_a] = None


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include "stdio.h"

char letter[200002];
int next[200001];
int prev[200001];
int num;
int start;
int end;
int sum;
bool flag = true;

int main() {

	scanf("%s", letter);
	for (int i = 0; i <= 200000; i++) {
		next[i] = i + 1;
		prev[i] = i - 1;
		//printf("%d\n", next[i]);
		if (letter[i] == NULL) {
			num = i;
			break;
		}
	}
	sum = num;
	start = 0;
	while (flag) {
		for (int i = start; next[i] < num;) {
			if (letter[i] == 'S') {
				if (letter[next[i]] == 'T') {
					if (prev[i] >= 0) {
						if (next[next[i]] < num) {
							next[prev[i]] = next[next[i]];
							prev[next[next[i]]] = prev[i];
							start = prev[i];
						}
						else {
							flag = false;
						}
					}
					else {
						if (next[next[i]] < num) {
							prev[next[next[i]]] = -1;
							start = next[next[i]];
						}
						else {
							flag = false;
						}
					}
					sum -= 2;
					break;
				}
			}
			if (next[next[i]] >= num) {
				flag = false;
				break;
			}
			i = next[i];
		}
		
	}
	printf("%d\n", sum);

	return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

constexpr int MAX = 110;
constexpr int INF = (1 << 20);

int mem[MAX][MAX];

int solve(int L, int R, const vector<int>& c)
{
    if (L > R)  return 0;    
    if (L == R) return -INF;
    
    int& res = mem[L][R];
    if (res != -1) return res;
    
    if (c[L] == c[R]) {
        int nL = L + 1, nR = R - 1;
        while (nL < R  && c[nL] == c[L]) nL++;
        while (nR > nL && c[nR] == c[R]) nR--;
        res = max(res, solve(nL, nR, c) + (nL - L) + (R - nR));

        for (int i = nL + 1; i <= nR - 1; i++) {
            if (c[i] == c[L]) {
                int l = solve(nL, i - 1, c);
                int r = solve(i + 1, nR, c);
                if (l == (i - nL) && r == (nR - i)) {
                    res = max(res, l + r + (nL - L) + (R - nR) + 1);
                }
            }
        }
    }
    
    int nL = L + 1;
    while (nL <= R && c[nL] == c[L]) nL++;
    if (nL - L >= 2) {
        res = max(res, solve(nL, R, c) + (nL - L));
    }
    
    int nR = R - 1;
    while (nR >= L && c[nR] == c[R]) nR--;
    if (R - nR >= 2) {
        res = max(res, solve(L, nR, c) + (R - nR));
    }
        
    for (int i = L; i <= R - 1; i++) {       
        res = max(res, solve(L, i, c) + solve(i + 1, R, c));
    }
    return res;
}

int main()
{
    int N;
    cin >> N;
    vector<int> c(N);
    for (int i = 0; i < N; i++) {
        cin >> c[i];
    }
    memset(mem, -1, sizeof(mem));
    cout << (solve(0, N - 1, c) == N ? "yes" : "no") << endl;
    return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#include <cmath>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep01(i, n) for(int i = 0; i < (n) + 1; i++)
#define rep10(i, n) for(int i = 1; i < (n); i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
using namespace std;

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

    if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') {
        cout << 3 << endl;
    }
    else if ((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')) {
        cout << 2 << endl;
    }
    else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }


    return 0;
}

Measured memory_bytes: 3620
n = gets.to_i
h = [0, 0, 0]
c = 0

n.times do
    s = gets.chomp
    c += s.scan("AB").size
    
    if s[0] == "B" && s[-1] == "A"
        h[2] += 1
    elsif s[0] == "B"
        h[1] += 1
    elsif s[-1] == "A"
        h[0] += 1
    end
end

c += h[0] < h[1] ? h[0] : h[1]
if h[2] > 0
    c += h[2] - 1
    c += 1 if h[0] > 0 || h[1] > 0
end

puts c

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

int main(){
    int i,h,n,sum=0;
    cin >> h >> n;
    vector<int> a(n);
    for(i=0;i<n;i++){
        cin >> a.at(i);
        sum += a.at(i);
    }
    if(h<=sum)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 640
N,M = [int(x) for x in input().split()]
S = [[int(x) for x in input().split()]for _ in range(N)]
C = [[int(x) for x in input().split()]for _ in range(M)]
ans = []
for x in S:
  mindist = 10**10
  mincheck = 0
  for ind,j in enumerate(C):
    if(abs(j[0]-x[0])+abs(j[1]-x[1])<mindist):
      mindist = abs(j[0]-x[0])+abs(j[1]-x[1])
      mincheck = ind + 1
  ans.append(mincheck)
for i in ans:
  print(i)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
// http://agc011.contest.atcoder.jp/tasks/agc011_b
typedef long long ll;
#define INF 1<<30
#define LINF 1LL<<60
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N; cin >> N;
	vector<ll> A(N);
	vector<ll> Sum(N + 1, 0);
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A.begin(), A.end());
	for (int i = 0; i < N;i++) Sum[i + 1] = Sum[i] + A[i];
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		//cout << i << " : " << Sum[i] << " " << A[i] << endl;
		//cout << cnt << endl;
		if (Sum[i] * 2 < A[i]) {
			cnt = 0; continue;
		}
		else {
			cnt++;
		}
	}
	cnt++;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}

set<pair<int,int> >mm[100005];
int vis[100005][2];
vector<vector<pair<int,int> >>adj;
void dfs(int ver,int x,int y,int par)
{
    vis[ver][par]=1;
    mm[ver].insert({x,y});
    for(auto i:adj[ver])
    {
        if(!vis[i.first][!par])
            dfs(i.first,i.second-x,-y,!par);
        else
        {
            mm[i.first].insert({i.second-x,-y});
        }        
    }
}

int mn=1,mx=1e9;

void ganza(pair<int,int>p)
{
    if(p.second>0)
    {
        mn=max(mn,-p.first+1);
    }
    else
    {
        mx=min(mx,p.first-1);
    }            
}

signed main()
{

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n,m;
    cin>>n>>m;
    adj.resize(n+1);
    int x,y,z;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y>>z;
        adj[x].push_back({y,z});
        adj[y].push_back({x,z});
    }

    dfs(1,0,1,0);
    int ind=-1e17;
    for(int i=1;i<=n;i++)
    {
        if(mm[i].size()>2)
        {
            cout<<0;
            return 0;
        }
        else if(mm[i].size()==2)
        {
            auto j=mm[i].begin();
            pair<int,int>x=*j;
            j++;
            pair<int,int>y=*j;
            if(x.second==y.second)
            {
                cout<<0;
                return 0;
            }
            if(x.second<0)
                swap(x,y);
            int z=y.first-x.first;
            if(z<=0)
            {
                cout<<0;
                return 0;
            }
            else if(z&1)
            {
                cout<<0;
                return 0;
            }
            else
            {
                ind=z/2;
            }            
            ganza(x);
            ganza(y);
        }
        else
            ganza(*mm[i].begin());
    }
    
    if(ind==-1e17)
    {
        cout<<max(0LL,mx-mn+1);
    }
    else
    {
        if(ind>=mn && ind<=mx)
        {
            cout<<1;
        }
        else
        {
            cout<<0;
        }
        
    }
    

} 
    


Measured memory_bytes: 44516
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

inline void solve() {
	int n;
	cin >> n;
	vector<pair<int, int>> all;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		pair<int, int> cur = { 0, 0 };
		for (int j = 0; j < s.size(); j++) {
			if (s[j] == '(')
				cur.second++;
			else if (s[j] == ')' && cur.second > 0)
				cur.second--;
			else
				cur.first++;
		}
		all.push_back(cur);
	}
	sort(all.begin(), all.end());

	multiset<pair<int, int>> st;
	pair<int, int> cur = { 0, 0 };
	int u = 0;
	while (u != n || st.size()) {
		while (u < n && all[u].first <= cur.second) {
			st.insert({ all[u].second, all[u].first });
			u++;
		}
		if (st.size() == 0 || (--st.end())->second > cur.second) {
			cout << "No";
			return;
		}
		cur.second -= (--st.end())->second;
		cur.second += (--st.end())->first;
		st.erase((--st.end()));
	}
	if (cur.first == 0 && cur.second == 0)
		cout << "Yes";
	else
		cout << "No";
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 57972
S = input()
S = S.replace('BC', 'D')
S = S.replace('B', 'C')
S = S.split('C')
ans = 0

def count_inv(s):
  res = num = 0
  for si in s:
    if si == 'A':
      num += 1
    else:
      res += num
  return res


for s in S:
  ans += count_inv(s)
  
print(ans)

Measured memory_bytes: 11460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll N; cin >> N;
  vector<ll> A(N);
  
  for(ll i = 0; i < N; i++){ ll a; cin >> a; a -= i+1; A[i] = a;}
  
  sort(A.begin(),A.end());
  
  ll res = 0;
  
  if(N%2){
    for(int i = 0; i < N; i++){
      if( i <= (N-3)/2){ res -= A[i];} else if( i >= (N+1)/2){ res += A[i];}}}
  
  else{
    for(int i = 0; i < N; i++){
      if( i < N/2){ res -= A[i];} else{ res += A[i];}}}
  
  cout << res << endl; return 0;}

Measured memory_bytes: 1792
n,x=map(int,input().split())
if x==1 or x==2*n-1:print("No");exit()
print("Yes")
if n==2:print(*[1,2,3],sep="\n")
else:
 l=list(range(1,2*n))
 if x==2:a=[3,2,1,4]
 else:a=[x-1,x,x+1,x-2]
 l=list(set(l)-set(a))
 m=len(l)//2
 b=l[:m]+a+l[m:]
 print(*b,sep="\n")

Measured memory_bytes: 33248
import itertools

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

l = [x+1 for x in range(n)]
ans = []
count = 0
for v in itertools.permutations(l):
    count += 1
    ans = list(v)
    if ans == a:
        a1 = count
    if ans == b:
        b1 = count

print(abs(a1-b1))
        




Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
 
pair<int, int> join(pair<int, int> a, const pair<int, int> &b)
{
    for (int x : {b.first, b.second})
    {
        if (a.first < x) swap(a.first, x);
        if (a.second < x) swap(a.second, x);
    }
    return a;
}
 
int main()
{
#ifdef jcg
    assert(freopen("input.in", "r", stdin));
//    assert(freopen("output.out", "w", stdout));
#endif
 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    int N;
    cin >> N;
 
    N = 1 << N;
 
    vector<pair<int, int>> a(N);
    for (auto &p : a)
        cin >> p.first;
 
    for (int m, mh = 1; (m = mh << 1) <= N; mh = m)
        for (int i = 0; i < N; i += m)
            for (int j = i; j < i + mh; ++j)
                a[j + mh] = join(a[j + mh], a[j]);
 
    int best = 0;
    for (int i = 1; i < N; ++i)
        cout << (best = max(best, a[i].first + a[i].second)) << endl;
 
    return 0;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	bool f=false;
	ll sum=0;
	cin>>s;
	if(s.length()==1){
		sum=stoi(s);
	}else{
		for(int i=1;i<s.length();i++){
			if(s.substr(i,1)!="9") f=true;
		}
		if(f){
			sum+=stoi(s.substr(0,1))-1;
			sum+=(s.length()-1)*9;
		}else{
			sum+=stoi(s.substr(0,1));
			sum+=(s.length()-1)*9;
		}
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
ret=[str(i)+' 1'for i in range(2,n+1)]

m=(-2+n)*(n-1)//2-k
if m<0:print(-1);exit()
now=2
j=3
print(len(ret)+m)
while m:
    ret.append(str(now)+' '+str(j))
    j+=1
    if j==n+1:
        j=now+2
        now+=1
    m-=1
print("\n".join(ret))


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

using namespace std;

int n, a[200005], tot;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        tot ^= a[i];
    }
    for (int i = 1; i <= n; i++) {
        cout << (tot ^ a[i]) << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4400
#include <iostream>
#include <math.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
using namespace std;

typedef long long ll;
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define memset(v, h) memset((v), h, sizeof(v))
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using P = pair<ll, ll>;

ll m[20][20];

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

struct node
{
    public: ll x;
    public: ll y;

    node(ll xx, ll yy)
    {
        x = xx;
        y = yy;
    }
};

int main(){
    ll n;
    cin >> n;
    ll a[n];
    rep(i,n)cin >> a[i];
    string y = "YES";

    map<ll, ll> mp;

    rep(i, n)
    {
        if(mp[a[i]] == 1)
        {
            y = "NO";
            break;
        }
        else
        {
            mp[a[i]] = 1;
        }
    }

    cout << y << endl;
    return 0;
}

Measured memory_bytes: 14336
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

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

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

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

    vector<int> a(3);
    read(a);
    sort(all(a));
    const int x = a[2] - a[1];
    const int d = (a[2] - (a[0] + x));
    const int y = (d + 1) / 2 + (d & 1);
    print(x + y);

    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
abA = [abs(i) for i in A]
mc = [i < 0 for i in A].count(True)
mv = min(abA)
sm = sum(abA)

if mc % 2 == 0:
    print(sm)
else:
    print(sm - 2 * mv)


Measured memory_bytes: 66720
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll M=1e5+100;
ll a[M] , b[M];
map<ll , bool> m;
int main()
{
    ll n , ans=0;
    cin>>n;
    for( int i=0 ; i<n ; i++)
    {
        cin>>a[i];
        b[i]=a[i];
        if( i % 2 == 0)
        {
            m[a[i]]=true;
        }
    }
    sort( b , b+n );
    for( int i=0 ; i<n ; i++ )
    {
        if( i % 2 == 0 && m[b[i]] == false )
        {
            ans++;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 8064
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N = int(readline())
  K = int(readline())
  X = list(map(int, readline().split()))
  ans = 0
  for i in range(N):
    x = X[i]
    ans += 2 * min(x, K-x)
  print(ans)
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064