akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] d = new int[N];
        for (int i = 0; i < N; i++) {
            d[i] = sc.nextInt();
        }
        Arrays.sort(d);

        int sheets = 0;
        for (int i = 0; i < N; i++) {
            if (i==0 || d[N-1-i]<d[N-i]) {
                sheets++;
            }
        }

        System.out.printf("%d\n", sheets);
        sc.close();
    }
}

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

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

    cout << max(0, a - 2*b) << endl;
    
    return 0;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
dp =[]

for i in range(n):
  if i == 0:
    dp.append(0)
  elif i == 1:
    dp.append(abs(h[1]-h[0]))
  else:
    dp.append(min(abs(h[i]-h[i-2])+dp[i-2],abs(h[i]-h[i-1])+dp[i-1]))    

print('{}'.format(dp[n-1]))

Measured memory_bytes: 13928
import Data.List
import Data.Array

main = readLn >>= print.sum.gcds

gcds :: Int -> [Int]
gcds n = map (gcd3.calcK) [ [x,y,z] | x <- [1..n], y <- [1..x], z <- [1..y]]
calcK [x,y,z] = a : [x,y,z] where
  a = if x == y && y == z then 1
    else if x == y || y == z then 3 else 6
gcd3 [a,x,y,z] = a * gcd(gcd x y) z

Measured memory_bytes: 3972
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll mod = 1000000007;
#pragma GCC optimization ("O3")
const int N = 1000010;
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
ll lcm(ll a,ll b)
{
  return (a*b)/__gcd(a,b);
}
int main()
{
  // int x = -1, y = 10000;
  // double z = 0.2;
  // string s2 = "beginner1010";
  // long long b = 1LL << 60;
    
  // // debug(x, y, z, s, b);
    
  // double aux = 1010.0;
  // string code = "code";
    
  // debug(code + "forces",-aux / 10 * 2.3);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  ll n,a,m = 2e+18+1e+17,c=0;
  cin >> n;
  for (int i = 0; i < n; ++i)
  {
    cin >> a;
    m = min(a,m);
    if(a <= m)
      c++;
  }
  cout << c;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define contains(c, i) ((c).find(i) != (c).end())
#define present(i, c) (find(all(c), i) != (c).end())

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++)
#define repa(i, a, b) for(int i = (a); i < (b); i++)
#define repd(i, n) for(int i = (n)-1; i >= 0; i--)

#define TRACE(x...) x
#define dbg(x) TRACE(cerr << #x" = " << x << endl)
#define dbgall(x) TRACE(cerr << #x" = "; for(auto __i : x) cerr << __i << " "; cerr << endl)
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<class T, class S>  ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }

//=========================

const int MAXN = (int) 1e5+1;

void run_test() {
    int n; cin >> n;
	vi cnt(MAXN);
    ll sum = 0;
    rep(i, n) {
        int a; cin >> a;
        sum += a;
        cnt[a]++;
    }
    int q; cin >> q;
    rep(i, q) {
        int f, t; cin >> f >> t;
        sum += (ll) (t - f) * cnt[f];
        cnt[t] += cnt[f];
        cnt[f] = 0;
        cout << sum << endl;
    }
}

//=========================

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	//int _t = 1, __t; cin >> __t; while(_t <= __t) { cout << "Case #" << _t++ << ": "; run_test(); }
	// int _t; cin >> _t; while(_t--) run_test();
	run_test();
	return 0;	
}



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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()         

#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

inline void INP();
const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q, x, y;
int arr[N+2], dis[N];


void solve()
{
      cin >> n >> x >> y;
      lop(i,1,n+1)
      {
            lop(j,i+1,n+1)
            {
                  if( abs(i-j) == 1)
                  {     
                        dis[ abs(i-j) ]++;
                  }
                  else
                  {     
                        int d1 = j - i;
                        int d2 = abs(x - i) + 1 + abs(y-j);
                        dis[ min(d1,d2) ]++;
                  } 
            }
      }

      lop(i,1,n) cout << dis[i] << endl;

      
}

int32_t main()
{
      ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);
      //INP(); 
      int test = 1;
      // cin >> test;

      // cout << setprecision(9) << fixed;
      // clock_t z = clock();
      while(test--)solve();
      // cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);
}











inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //






Measured memory_bytes: 256
n = int(input())
a = sorted(list(map(int, input().split())),reverse=True)
d = {}
for i in a:
  try:d[i] += 1
  except:d[i] = 1

ans = 0
t = 0
for i in d:
  if(d[i] >= 4 and ans == 0):print(i*i);exit()
  if(d[i] >= 2 and ans == 2):print(t*i);exit()
  if(d[i] >= 2 and ans == 0):t=i;ans=2
print(0)

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

long long n,a,b;

bool ok(long long mid, vector<long long> h){
  long long cnt=0;
  for(int i=0;i<n;i++){
    if(h[i]>b*mid){
      h[i]-=b*mid;
      cnt+=h[i]/(a-b);
      if(h[i]%(a-b)!=0) cnt++;
    }
  }
  return cnt<=mid;
}

int main(){
  cin >> n >> a >> b;
  vector<long long> h(n);
  for(int i=0;i<n;i++){
    cin >> h.at(i);
  }
  long long r=1e9, l=0;
  while(abs(r-l)>1){
    long long mid=(r+l)/2;
    if(ok(mid, h)){
      r=mid;
    }else{
      l=mid;
    }
  }
  cout << r << endl;  
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n,k;
long long a[200005];
long long ans;
int main() {
	cin>>n>>k;
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n-k;i++) ans+=a[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#define M 5070721
#define NIL (-1)
#define L 14
typedef long long ll;
char H[M][L];

int getChar(char ch){
	if(ch=='A')return 1;
	else if(ch=='C')return 2;
	else if(ch=='G')return 3;
	else if(ch=='T')return 4;
	else return 0;
}

ll getKey(char str[]){
	ll sum=0,p=1,i;
	int len=strlen(str);
	for(i=0;i<len;i++){
		sum+=p*(getChar(str[i]));
		p*=5;
	}
	return sum;
}

int h1(int key){
	return key%M;
}

int h2(int key){
	return 1+(key%(M-1));
}

int find(char str[]){
	ll key,i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)return 1;
		else if(strlen(H[h])==0)return 0;
	}
	return 0;
}

int insert(char str[]){
	ll key,i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)return 1;
		else if(strlen(H[h])==0){
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}


int main(void){
	int n;
	char str[L],com[9];
	for(int i=0;i<M;i++){
		H[i][0]='\0';
	}
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s %s",com,str);
		if(com[0]=='i'){
			insert(str);
		}else{
			if(find(str)){
				printf("yes\n");
			}else{
				printf("no\n");
			}
		}
	}
	return 0;
}



Measured memory_bytes: 72040
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;
using Graph = vector<vector<ll>>; // グラフ型

//数の書かれた N 個のボールが一列に並んでいる。すぬけ君は左から k 番目のボールに k と書いてあ
//るとき、それを選んで取り除くことができる。全てのボールを取り除くことは可能か？
//agc032_a
int main()
{
    ll N;
    cin >> N;

    vector <ll> a(N);

    REP(i, N)
    {
        cin >> a[i];
        --a[i];
    }

    vector<ll> res;

    for (ll i = 0; i < N; ++i)
    {
        ll pivot = -1;
        //最大のものを取り除く
        for (ll j = a.size() - 1; j >= 0; --j)
        {
            if (a[j] == j)
            {
                pivot = j;
                break;
            }
        }
        if (pivot == -1)
        {
            cout << -1 << endl;
            return 0;
        }
        //追加の逆順に出力
        res.push_back(pivot + 1);
        a.erase(a.begin() + pivot);
    }

    reverse(res.begin(),res.end());
    for(auto v:res)
    {
        cout << v << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int count(int n, int s, int a) {
  if (n == 1) {
    if (0 <= s && s <= 9 && a <= s) {
      return 1;
    } else {
      return 0;
    }
  }
    else {
      int c = 0;
      for (int b = a; s - b > 0; b++) {
      c += count(n - 1, s - b, b + 1);
  }
  return c;
}
}
int main() {
  int n, s;
  while (cin >> n >> s, n || s) {
    cout << count(n, s, 0) << endl;
  }
  return 0;
}



Measured memory_bytes: 3044
// 競プロ.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
using namespace std;




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

	vector<pair<int, int> > p(n);

	for (int i = 0; i < n; i++) {
		long x, l, st, et;
		cin >> x >> l;
		et = x + l - 1;
		st = x - l;
		if (st < 0)st = 0;
		p[i] = make_pair(et, st);
	}

	sort(p.begin(), p.end());

	long sp = 0;
	int r = 0;

	while (sp<n) {
		r++;
		int co = p[sp].first;
		while (sp < n) {
			if (p[sp].second > co) {
				break;
			}
			sp++;
		}
	}
	cout << r;
	
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  string ss="";
  for(int i=s.length()-1;i>=0;i--){
    ss+=s[i];
    if(ss=="maerd" || ss=="remaerd" || ss=="esare" || ss=="resare") ss="";
  }
  cout<<((ss=="")?"YES":"NO")<<endl;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,ans=1000000000000000000;
	cin>>n;
	ll a[n],s[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	s[0]=a[0];
	for(int i=1;i<n;i++)
		s[i]=a[i]+s[i-1];
	for(int i=0;i<n-1;i++)
	  ans=min(ans,abs(s[i]-(s[n-1]-s[i])));
	cout<<ans;
	return 0;
}

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

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

int main(){
    string s;
    cin >> s;
    int countA = 0,countB = 0;
    if(s.size() == 1){
        cout << 0 << endl;
        return 0;
    }
    for(int i = 0; i < s.size(); i++){
        if(i % 2 ){
            if(s[i] == '1'){
                countA++;
            }
        }
        else{
            if(s[i] == '0'){
                countA++;
            }
        }
    }
    countB = s.size() - countA;
    cout << min(countA, countB) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,k;
	cin>>n>>k;
	long double p[200010];
	for(ll i=0;i<n;i++){
		long double x;
		cin>>x;
		p[i]=x;
	}
	long double ch[200010]={};
	for(ll i=0;i<n;i++){
		long double now=(p[i]+1.0)/2;
		if(p[i]==1){
			now=1.0;
		}
		ch[i]=now;
		//printf("%.10Lf\n",now);
	}
	long double ans=0;
	for(ll i=0;i<k;i++){
		ans+=ch[i];
	}
	long double now=ans;
	for(ll i=0;i<n-k;i++){
	//printf("%.10Lf\n",now);		
		now-=ch[i];
		now+=ch[i+k];
		ans=max(now,ans);
	}
	printf("%.10Lf",ans);
	// your code goes here
	return 0;
}

Measured memory_bytes: 10004
#include <iostream>
#include <vector>
#include <set>

using namespace std;

const int maxn = 1e5 + 9;
pair<int, int> arr[maxn];
vector<int> adj[maxn];
int n, m;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
	}
	int ans = 0;
	set<int> st;
	for (int i = 1; i <= n; i++) {
		if (st.find(i) != st.end()) { 
			st.clear();
			ans++;
		}
		for (auto v : adj[i]) {
			st.insert(v);
		}
	}
	cout << ans << '\n';
	return 0;
}

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

#define REP(i, l, n) for(ll i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

int main(){
    int k; cin >> k;
    ll ans = 0;
    REP(a, 1, k+1){
        REP(b, 1, k+1){
            REP(c, 1, k+1){
                ans += gcd(gcd(a, b), c);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;


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

  string s; cin >> s;
  int ssize = s.size();
  int pcnt = 0;
  rep(i, ssize) {
    if (s[i] == 'p') {
      pcnt++;
    }
  }

  cout << ssize/2 - pcnt << endl;
}

Measured memory_bytes: 512
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

# 締め切りで昇順にソート
ab.sort(key=lambda x: x[1])

# accumerate a
for i, (a, _) in enumerate(ab):
    if i == 0:
        continue
    ab[i][0] = ab[i-1][0] + a

if all(ab[i][0] <= ab[i][1] for i in range(n)):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 89048
from sys import stdin
from collections import deque

n = int(stdin.readline())
g = [None] * n
for _ in range(n):
    u, _, *cs = [int(s) for s in stdin.readline().split()]
    g[u-1] = [c - 1 for c in cs]
ds = [-1] * n
v = [False] * n
v[0] = True
q = deque([(0, 0)])
while len(q):
    u, d = q.popleft()
    ds[u] = d
    for c in g[u]:
        if not v[c]:
            v[c] = True
            q.append((c, d + 1))
for u, d in enumerate(ds):
    print(u + 1, d)

Measured memory_bytes: 8092
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def Prim(g):
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v.keys()))
    V = list(set(V))

    used = set([])
    q = []
    heapq.heappush(q, (0, V[0]))

    ret = 0
    while q:
        c, v = heapq.heappop(q)

        if v in used:
            continue
        used.add(v)
        ret += c
        for u in g[v]:
            heapq.heappush(q, (g[v][u], u))
    return ret


@mt
def slv(N, A):
    c = Counter()

    for a in A:
        if a % 4 == 0:
            c[2] += 1
        elif a % 2 == 0:
            c[1] += 1
        else:
            c[0] += 1

    if c[0] - c[2] > 1:
        return 'No'

    if c[0] - c[2] == 1 and c[1] > 0:
        return 'No'

    return 'Yes'


def main():
    N = read_int()
    A = read_int_n()

    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 17472
#include<iostream>
#include<string>
#include<vector>
#include<utility>
using namespace std;
int main(){
  string s,t;
  bool can=true;
  char s_chs[26],t_chs[26];
  cin >> s >> t;
  fill(s_chs,s_chs+26,-1);
  fill(t_chs,t_chs+26,-1);
  for(int i=0;i<s.size();i++){
    if(s_chs[s[i]-'a']==-1){
      s_chs[s[i]-'a'] = t[i];
    }
    if(t_chs[t[i]-'a']==-1){
      t_chs[t[i]-'a'] = s[i];
    }
    if(s_chs[s[i]-'a']!=t[i]){
      can=false;
      break;
    }
    if(t_chs[t[i]-'a']!=s[i]){
      can=false;
      break;
    }
  }
  if(can){
    cout <<"Yes\n";
  }else{
    cout <<"No\n";
  }
}


Measured memory_bytes: 776
import collections
import math
import operator as op
from functools import reduce
from collections import Counter
import numpy as np
import math
import bisect
import heapq


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def main():
    N, M = get_inputs(int)
    H = get_inputs(int)

    adj_list = [[] for _ in range(N+1)]
    for i in range(M):
        A, B = get_inputs(int)
        adj_list[A].append(B)
        adj_list[B].append(A)

    # is_visited = [False for _ in range(N+1)]
    # num_good = 0
    # for i in range(1, N+1):
    #     if not is_visited[i]:
    #         queue = []
    #         queue.append(i)
    #         max_heights = [0, ]
    #         while len(queue) > 0:
    #             cur_node = queue.pop(0)
    #             if H[cur_node-1] > max_heights[0]:
    #                 max_heights = [H[cur_node-1], ]
    #             elif H[cur_node-1] == max_heights[0]:
    #                 max_heights.append(H[cur_node-1])
    num_good = 0
    for  i in range(1, N+1):
        H_i = H[i-1]
        if all([H[j-1] < H_i for j in adj_list[i]]):
            num_good += 1

    print(num_good)





if __name__ == '__main__':
    main()


Measured memory_bytes: 47872
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <deque>
#include <math.h>
#include <map>
#include <bitset>
#include <queue>
#include <list>
#include <utility>

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

using namespace std;
using ll = long long;
using ld = long double;
using p = pair<int, int>;
using Graph = vector<vector<int>>;
#define rep(i,n)  for(int i = 0; i < n ; i++)
int dx[4]{ -1,0,1,0 };
int dy[4]{ 0,1,0,-1 };
int main()
{
	// 頂点数と辺数
	int N, X,Y;
	cin >> N >> X>>Y;
	X--;Y--;
	vector<int> ans(N);	
	rep(sv, N)
	{
		vector<int> dist(N,-1);
		queue<int> q;
		auto push = [&](int v, int d)
		{
			if (dist[v] != -1) {
				return;
			}
			dist[v] = d;
			q.push(v);
		};
		push(sv, 0);
		while (!q.empty())
		{
			int  v = q.front(); q.pop();
			int d = dist[v];
			if (v - 1 >= 0) { push(v - 1, d + 1); }
			if (v + 1 < N) { push(v + 1, d + 1); }
			if (v == X) { push(Y, d + 1); }
			if (v == Y) { push(X, d + 1); }
		}
		rep(i, N) { ans[dist[i]] ++; }
	}
		rep(i, N) { ans[i] /= 2; }
	for (int i = 1; i < N; i++)
	{
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
 
typedef long long LL;
typedef pair<int, int> PII;
 
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = (LL)INF * INF;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, k, s;
	cin >> n >> k >> s;
	int b = (s == 1000000000 ? s - 1 : s + 1);
	FOR(i, 0, k)
		cout << s << " ";
	FOR(i, 0, n - k)
		cout << b << " ";
	return 0;
}


Measured memory_bytes: 1280
n,k = map(int,list(input().split()))
a = list(map(int,list(input().split())))

next=1
visited = [0]*n
visited2 = [0]*n
flg=0

for i in range(k):
    #print(visited)
    if i==k-1:
        result = next
    if visited[next-1]==0:
        visited[next-1]=1
        next = a[next-1]
    elif visited2[next-1]==1:
        # (k-i-1) : 残り回数
        remain = (k-i-1)%sum(visited2)
        next = a[next-1]
        flg=1
        break
    elif visited[next-1]==1:
        visited2[next-1]=1
        next = a[next-1]

        
if flg:
    for i in range(remain):
        next = a[next-1]
    result  = next


print(next)

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

int main() {
  int N=0,n=0,a=0,x=0;
  
  cin >> N;
  n = N;
  
  while (n) {
    a = (n/10)*10;
    x += n-a;
    n = n/10;
  }
  
  if (N%x==0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

using namespace std;

int main()
{
    long n, k; 
    cin >> n >> k;
    
    double total_probability = 0;

    for(long i = 1; i <= n; i++){
        long k_per_a = (long)ceil((double)k / i);

        long denomi = 0;
        for(long multi = 0; multi < 32; multi++){
            if(k_per_a >> multi == 1){
                denomi = 1 << multi;
                if(k_per_a != denomi){
                    denomi <<= 1;
                }
                break;
            }
        }
        total_probability += (1.0 / n) * (1.0 / denomi);
    }

    cout << std::setprecision(12) << total_probability << endl;

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<stack>
#include<queue>

#define REP(i, N) for(int i = 0; i < N; ++i)
#define FOR(i, M, N) for(int i = M; i < N; ++i)

using namespace std;

int main() {
	int N;
	int A, B;
	cin >> N;
	if (N == 2) {
		cin >> A;
		cin >> B;
		cout << A + B << endl;
	}
	else {
		cout << "Hello World" << endl;
	}



	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

const ll mod = 1e9 + 7;

ll C[2005][2005];
ll dp[100005][13];


int main(){
    int R;
    cin >> R;
    if(R%2 == 0)cout << R/2 << endl;
    else cout << R/2 +1 << endl;
}

Measured memory_bytes: 256
class SegmentTree:
    def __init__(self, n, cal, unit): #example (12, min, 2**31-1)
        for k in range(40):
            if 2**k > N:
                break
        self.powers = pow(2,k)
        self.segTree = [unit]*(2*self.powers)
        self.cal = cal
        self.unit = unit
    
    def update(self, i, x):#i番目(0-indexed)にx代入, segTree = [0,*,*,...], 1-indexed, N < k
        i += self.powers
        self.segTree[i] = x
        while i > 1:
            i //= 2
            self.segTree[i] = self.cal(self.segTree[i*2],self.segTree[i*2+1])

    def getCal(self, i, j, k=1, l=0, r=-1): #get self.cal of [i,j)!!!!!
        if r < 0: #initization, we want to r = self.powers as an initial value.
            r = self.powers
        if j <= l or r <= i:
            return self.unit
        if i <= l and r <= j:
            return self.segTree[k]
        return self.cal( self.getCal(i ,j, k*2, l, (l+r+1)//2) ,self.getCal(i ,j, k*2+1, (l+r+1)//2, r))

N, Q = map( int, input().split())
segmentTree = SegmentTree(N, min, 2**31-1)
for _ in range(Q):
    com, x, y = map( int, input().split())
    if com == 0:#0-indexed
        segmentTree.update(x,y)
    else:#""[x,y]"
        print(segmentTree.getCal(x,y+1)) #remark. we need "+1".




Measured memory_bytes: 8692
#include<stdio.h>

int main(){
    int i,j,k,x,n;
    int count;
    while(1){
        scanf("%d %d", &n ,&x);
        if(x == 0 && n == 0) break;
        count = 0;
        for(i = 1;i <= n-2;i++){
            for(j = i + 1; j <= n-1; j++){
                for(k = j + 1; k <= n; k++){
                    if(i+j+k==x) count+=1;
                }
            }
        }
        printf("%d\n",count);
    }
    return 0;
}



Measured memory_bytes: 2076
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>
#include <unordered_set>
#include <stack>
#include <iterator>
#include <random>
#include <fstream>
#include <chrono>
using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    double n;
    cin >> n;
    double k = n/3.0;
    cout << setprecision(15)<<fixed << k*k*k << "\n";
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
left, right = 1, n
for _ in range(m):
  l, r = map(int, input().split())
  if l > left:
    left = l
  if r < right:
    right = r
  if left > right:
    print(0)
    quit()
print(right - left + 1)

Measured memory_bytes: 3060
/*
***AUTHOR***
*ADVAITVD99*
*/
#include<bits/stdc++.h>

using namespace std;


int main(){
	clock_t tim;
    tim = clock();
	const long long MOD=1e9+7;
    {
		int N;
		cin>>N;
		long long res=1;
		//unordered_set<int> s;
		for(int a=1;a<N-1;a++){
			int b=(N-1)/a;
			res+=b;
		}
		cout<<res<<endl;
	}

    //tim = clock() - tim;
    //double time_taken = ((double)tim)/CLOCKS_PER_SEC;
    //cout<< fixed << setprecision(3) << time_taken << "seconds" <<endl;

	return 0;
}


Measured memory_bytes: 3648
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}

signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	int n;
    cin>>n;
    string p;
    cin>>p;
    int cnt=0;
    for(int i=0;i<p.length()-2;i++)
    {
        if(p[i]=='A'&&p[i+1]=='B'&&p[i+2]=='C')
        cnt++;
    }
    cout<<cnt;
    

return 0;
}

Measured memory_bytes: 3668
def solve(h):
    if len(h)<2:
        return h[0]
    s=[i for i in range(len(h))if h[i]<1]
    s=[-1]+s+[len(h)]
    a=0
    for l in[h[i+1:j]for i,j in zip(s,s[1:])]:
        if not l:continue
        v=min(l)
        l=[t-v for t in l]
        a+=v+solve(l)
    return a
input()
print(solve(list(map(int,input().split()))))

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

int a[10000];

int main()
{
    int n;
    int i, j;
    long long amore=0;
    long long bmore=0;
    long long cnt = 0;

    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    for(i=0;i<n;i++)
    {
        cin >> j;
        a[i] -= j;
        if(a[i]>0) amore += a[i];
        if(a[i]<0) bmore -= (a[i])/2;
        cnt -= a[i];
    }
    if(amore > bmore || cnt < amore) cout << "No\n";
    else cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
// Problem : C - H and V
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_c
// Memory Limit : 1024 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	// && has higher precedence than ||
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int N,M,K;
	cin>>N>>M>>K;
	vi v[N];
	vi smc(M),smr(N);
	int sum=0;
	F0R(x,N)
	{
		string str;
		cin>>str;
		// bug(str);
		F0R(y,M)
		{
			v[x].pb(str[y]=='.'?0:1);
			smr[x]+=v[x][y];
			// bug(smr[x]);
			smc[y]+=v[x][y];
		}
	}
	F0R(x,N)
	    sum+=smr[x];
	// bug(sum);
	int ans=0;
	int bts=0;
	while(bts<(1<<(N+M)))
	{
		int c=0,res=sum;
		while(c<N)
		{
			if((bts>>c)&1)
			{
				res-=smr[c];
			}
			c++;
		}
		while(c<N+M)
		{
			if((bts>>c)&1)
			{
				res-=smc[c-N];
				F0R(x,N)
				{
					if(bts>>x&1 && v[x][c-N])res++;//,bug(res);
				}
			}
			c++;
		}
		// bug(res);
		if(res==K)ans++;
		bts++;
	}
	cout<<ans<<nl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3496
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


template<class T, class Comp=std::less<T>>
struct ConvexHullTrick {
public:
    ConvexHullTrick(const Comp &comp = Comp()) : comp(comp) {};

    void add_line(T slope, T intercept) {
        Line line(slope, intercept);
        while (lines.size() >= 2) {
            if (check_valid(*(lines.end() - 2), lines.back(), line)) break;
            lines.pop_back();
        }
        lines.emplace_back(slope, intercept);
    }

    T evaluate(T x) {
        assert(!lines.empty());

        int lo = -1, hi = (int)lines.size() - 1;
        while (hi - lo > 1) {
            int mid = lo + (hi - lo) / 2;
            T v1 = evaluate(lines[mid], x);
            T v2 = evaluate(lines[mid + 1], x);
            if (comp(v1, v2)) hi = mid;
            else lo = mid;
        }
        return evaluate(lines[hi], x);
    }

private:
    const Comp comp;
    using Line = std::pair<T, T>;
    std::vector<Line> lines;

    T check_valid(Line l1, Line l2, Line l3) {
        if (l1.first < l3.first) std::swap(l1, l3);
        T lhs = (l3.second - l2.second)*(l2.first - l1.first);
        T rhs = (l2.second - l1.second)*(l3.first - l2.first);
        return lhs < rhs;
    }

    T evaluate(const Line &line, T x) {
        return line.first*x + line.second;
    }
};


int main() {
    int n; long long c; std::cin >> n >> c;
    std::vector<long long> h(n);
    for (int i = 0; i < n; i++) std::cin >> h[i];
    ConvexHullTrick<long long> cht;
    cht.add_line(-2*h[0], h[0] * h[0] + c);
    for (int i = 1; i < n - 1; i++) {
        long long v = h[i] * h[i] + cht.evaluate(h[i]);
        v += h[i] * h[i] + c;
        cht.add_line(-2*h[i], v);
    }
    std::cout << h[n - 1]*h[n - 1] + cht.evaluate(h[n - 1]) << std::endl;
    return 0;
}

Measured memory_bytes: 7920
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int N=65;
int n,sum,a[N],b[1000005];
/*char buf[1ll<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1ll,1ll<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1ll;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
void add(int x)
{
	for(int i=60;i>=0;i--)
		if(!(sum&(1ll<<i)))
		if(x&(1ll<<i))
		{
			if(!a[i])
			{
				a[i]=x;
				return;
			}
			x^=a[i];
		}
	for(int i=60;i>=0;i--)
		if(sum&(1ll<<i))
		if(x&(1ll<<i))
		{
			if(!a[i])
			{
				a[i]=x;
				return;
			}
			x^=a[i];
		}	
}
signed main()
{
	n=read();
	for(int i=1ll;i<=n;i++)
	{
		b[i]=read();
		sum^=b[i];
	}
	for(int i=1ll;i<=n;i++)add(b[i]);
	int now=0;
	for(int i=60;i>=0;i--)
		if(!(sum&(1ll<<i)))
		if(!(now&(1ll<<i)))now^=a[i];
	for(int i=60;i>=0;i--)
		if(sum&(1ll<<i))
		if(!(now&(1ll<<i)))now^=a[i];
	cout<<(sum^now)+now;
	return 0;	
}

Measured memory_bytes: 1024
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	n = readline() |> parseInt
	l = readline() |> split |> parseMap
	s = 0
	for i in 1:n-2
		for j in i+1:n-1
			for k in j+1:n
				if l[i]+l[j]>l[k] && l[j]+l[k]>l[i] && l[k]+l[i]>l[j] && l[i]!=l[j]&&l[j]!=l[k]&&l[k]!=l[i]
					s += 1
				end
			end
		end
	end
	println(s)
end

main()

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

int main(){
    int N,K,R,S,P;
    string T;
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;
    for(int i=K-1;i<N;i++){
        if(T[i]==T[i-K]) T[i]='0';
    }

    int ans=0;
    for(int i=0;i<N;i++){
        if(T[i]=='r'){
            ans+=P;
        }else if(T[i]=='s'){
            ans+=R;
        }else if(T[i]=='p'){
            ans+=S;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl

int n;
int main() {
    cin >> n;
    vector<pair<int, int>> range(n);
    rep(i, 0, n){
        int a, b; cin >> a >> b;
        range[i] = {a+b, b+b};
    }

    sort(ALL(range));

    int nowPos = range[0].first;
    int ans = n;
    rep(i, 1, n){
        if (range[i].first - range[i].second < nowPos) ans--;
        else{
            nowPos = range[i].first;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int s,i=1;
    cin >> s;
    vector<int> suuzi(1000000,0);
    suuzi.at(s)++;
    while(true){
        i++;
        if(s%2==0)s /= 2;
        else s = 3*s+1;
        suuzi.at(s)++;
        if(suuzi.at(s)==2)break;
    }
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 4096
n = int(input())
D = []
A = []
B = []
m = 1000000000
res = 0
for i in range(n):
    a,b = map(int,input().split())
    point = a+b
    D.append([point,i])
    A.append(a)
    B.append(b)
else:
    D.sort()
    D.reverse()

ans_a = 0
ans_c = 0
for i in range(n):
    if i%2 == 0:
        res += A[(D[i][1])]
        ans_a += A[(D[i][1])]
    else:
        res -= B[(D[i][1])]
        ans_c += B[(D[i][1])]
else:
    #print(res)
    print(ans_a-ans_c)


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

using ei = tuple<int, int, int>;

ei pajie[] = {ei(0, 1, 2), ei(0, 2, 1), ei(1, 0, 2), ei(1, 2, 0), ei(2, 0, 1), ei(2, 1, 0), ei(0, 1, 2)};

ei latte(ei be, ei et) {
  int a[3], b[3];
  tie(a[0], a[1], a[2]) = be;
  tie(b[0], b[1], b[2]) = et;
  return ei(b[a[0]], b[a[1]], b[a[2]]);
}

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

  vector<ei> v;
  for (int i = 0; i < n; ++i) {
    int a = 0, b = 1, c = 2;

    int w;
    cin >> w;

    while (w--) {
      int f;
      cin >> f;

      if (f)
        swap(a, b);
      else
        swap(b, c);
    }

    v.push_back(ei(a, b, c));

    // cerr << "{" << a << ", " << b << ", " << c << "}" << endl;
  }

  map<ei, int> unzip;
  for (int i = 0; i < 6; ++i) {
    unzip[pajie[i]] = i;
  }

  int dp[50][7] = {};
  dp[0][6] = 1;

  // cerr << unzip[v[0]] << endl;

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 7; ++j) {
      if (dp[i][j]) {
        dp[i + 1][j] = 1;
        dp[i + 1][unzip[latte(pajie[j], v[i])]] = 1;
      }
    }
  }

  cout << (dp[n][0] ? "yes" : "no") << endl;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int a[200000], b[200000];
int main()
{
    int n;
    cin >> n;
    for(int i=0; i<n; ++i)cin >> a[i];
    for(int i=0; i<n; ++i)cin >> b[i];
    vector<int> ab(2*n);
    for(int i=0; i<n; ++i)ab[i]= a[i];
    for(int i=0; i<n; ++i)ab[n+i]= b[i];
    sort(ab.begin(), ab.end());
    int count = 1, max_count = 1;
    for(int i=1; i<2*n; ++i){
        if(ab[i] == ab[i-1]){
            count += 1;
            max_count = max(count, max_count);
        }else{
            count = 1;
        }
    }
    // 過半数が同じならダメ（鳩ノ巣原理）
    if (max_count > n){
        cout << "No";
        return 0;
    }
    // 逆順にソートするとたかだか連続した1か所だけ被る。この値を c とする
    sort(b, b+n, [](int x, int y){return x>y;});
    int c = -1;
    for(int i=0; i<n; ++i){
        if(a[i]==b[i]){
            c = a[i];
            break;
        }
    }
    if (c>=0){
        // cがいるところどうしが当たらないようにする
        int al=-1, ar=-1, bl=-1, br=-1;
        for(int i=0; i<n; ++i){
            if (a[i]==c){
                if(al==-1){
                    al=i;
                }
            }else{
                if(al>=0 && ar==-1){
                    ar=i;
                }
            }
            if (b[i]==c){
                if(bl==-1){
                    bl=i;
                }
            }else{
                if(bl>=0 && br==-1){
                    br=i;
                }
            }
        }
        int l = max(al, bl), r = min(ar, br);
        int ll = min(al, bl), rr = max(ar, br);
        int j = 0;
        for(int i=l; i<r; ++i){
            if(j == ll)j=rr;
            int tmp=b[i];
            b[i]=b[j];
            b[j]=tmp;
            j+=1;
        }
    }
    cout << "Yes" << endl;
    for(int i=0; i<n-1; ++i)cout << b[i] << " ";
    cout << b[n-1] << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int>A(6);
  A.at(0) = 2;
    
  for (int i = 1; i < 6; i++) {
    A.at(i) = A.at(i-1)*2;
  }
  
  if (N < A.at(0)) {
    cout << 1 << endl;
  }
  else if (N < A.at(1)) {
    cout << 2 << endl;
  }
  else if (N < A.at(2)) {
    cout << 4 << endl;
  }
  else if (N < A.at(3)) {
    cout << 8 << endl;
  }
  else if (N < A.at(4)) {
    cout << 16 << endl;
  }
  else if (N < A.at(5)) {
    cout << 32 << endl;
  }
  else {
    cout << 64 << endl;
  }
}

  

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq as hq
import itertools as its
import operator as op


# globals
inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    n = get_int()
    a, b = get_data(n-1, [int, int])
    c = get_li()
    c.sort()
    node2children = defaultdict(set)
    for ai, bi in zip(a, b):
        node2children[ai].add(bi)
        node2children[bi].add(ai)
    leaves = deque()
    for node, children in node2children.items():
        if len(children) == 1:
            leaves.append(node)
    sequence = []
    score = 0
    i = 0
    while len(leaves) > 0:
        node = leaves.popleft()
        sequence.append(node)
        if len(node2children[node]) == 0:
            break
        score += c[i]
        i += 1
        parent = node2children[node].pop()
        node2children[parent].discard(node)
        if len(node2children[parent]) == 1:
            leaves.append(parent)
    print(score)
    print(" ".join(
        map(
            lambda x: str(x[1]),
            sorted(
                enumerate(c),
                key=lambda x: sequence[x[0]]
            )
        )
    ))
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()


Measured memory_bytes: 80644
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)

// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	ll N;
	cin >> N;
	ll A[2][N];
	for (ll i = 0; i < N; ++i) cin >> A[0][i];
	for (ll i = 0; i < N; ++i) cin >> A[1][i];
 
	// 解法
	ll ans = 0;
	for (ll i = 0; i < N; ++i){
		ll tmp = 0;
		for (ll j = 0; j <= i; ++j) tmp += A[0][j];
		for (ll j = i; j < N; ++j) tmp += A[1][j];
		if (tmp>ans) ans = tmp;
	}

	//出力
	cout << ans << endl;
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    s[k-1] = tolower(s[k-1]);
    cout << s;
    return 0;
}
                

Measured memory_bytes: 256