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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>; 
#define INF INT_MAX //(1<<(4*4-1))
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

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

   int N,M,Q;
   cin>>N>>M>>Q;
   vector<int>L(M),R(M),p(Q),q(Q);
   for(int i=0;i<M;i++)cin>>L[i]>>R[i];
   for(int i=0;i<Q;i++)cin>>p[i]>>q[i];

   vector<vector<int> >sum(N+1,vector<int>(N+1,0));
   for(int i=0;i<M;i++){
      sum[L[i]][R[i]]++;
   }
   for(int i=0;i<=N;i++){
      for(int j=1;j<=N;j++){
         sum[j][i]+=sum[j-1][i];
      }
   }

   for(int i=0;i<Q;i++){
      int res=0;
      for(int j=p[i];j<=q[i];j++){
         res+=sum[q[i]][j]-sum[p[i]-1][j];
      }
      cout<<res<<endl;
   }
   return 0;
}



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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pair<ll, ll>> vpll;

//mt19937 random(566);
//uniform_int_distribution<ll> distr;
//ll rnd(ll a, ll b) {return a + distr(random) % (b - a + 1);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vi a(n);
    forn(i, n) cin >> a[i];
    int mn = 2e9;
    forab(i, -100, 101) {
        int cur = 0;
        forn(j, n) {
            cur += (i - a[j]) * (i - a[j]);
        }
        mn = min(mn, cur);
    }
    cout << mn << "\n";
    return 0;

}

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

int w(int n){
  if (n==0) return 0;
  else return n%10+w(n/10);
}

int main(){
  int a;
  cin >> a;
  int m=10000000;
  for(int i=1;i<a;i++){
    int b=i;
    int c=a-i;
    m=min(w(b)+w(c),m);
  }
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args) {
	while(kbd.hasNext()){
	    int n = kbd.nextInt();
	    if(n!=0){
		int sum = 0;
		int t = n/4;
		for(; t>0; t--){
		    sum += kbd.nextInt();
		}
		System.out.println(sum);
	    }
	}
    }
}

Measured memory_bytes: 11000
#include<iostream>
#include<algorithm>
#include<unordered_map>


using namespace std;

int main(){
  int N;
  cin >> N;
  string str;
  unordered_map<string, int> hash;
  long count=0;
  for(int i=0;i<N;i++){
    cin >> str;
    sort(str.begin(), str.end());
    if(hash[str]!=0){
      count =count + hash[str];
    }else{
      count=count;
    }
    hash[str]++;


  }

  cout << count << endl;




  return 0;

	

}

Measured memory_bytes: 10660
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
#define PI acos(-1)
using namespace std;
int main(){
  int num[50001]={1,1,0};
  for(int i=3;i<50001;i+=2){
    if(num[i]==1)
      continue;
    for(int j=3*i;j<50001;j+=i*2)
      num[j]=1;
  }
  for(int i=4;i<50001;i+=2)num[i]=1;

  int in;
  while(cin>>in,in){
    int co=0;
    loop(i,2,(in+2)/2)if(!(num[i]||num[in-i]))co++;
    cout<<co<<endl;
  }
}

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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const int N = 100010;

inline int in() {int x; scanf("%d",&x); return x;}
inline ll lin() {ll x; scanf("%lld",&x); return x;}

int fx[]={1,-1,0,0};
int fy[]={0,0,-1,1};

pii inp[N];
int dp[N];

ll cum[N];

int main(){
    int n = in();
    for(int i = 1; i <= n; i++){
        inp[i].fs = in();
        inp[i].se = i;
    }

    sort(inp + 1, inp + n + 1);

    for(int i = 1; i <= n; i++){
        cum[i] = cum[i - 1] + inp[i].fs;
    }

    memset(dp, 0, sizeof dp);

    dp[n] = 1;

    for(int i = n - 1; i >= 1; i--){
        if((ll)inp[i + 1].fs <= cum[i] + cum[i]){
            dp[i] = 1;
        }else {
            break;
        }
    }

    int ans = 1;

    for(int i = n - 1; i >= 1; i--){
        if(dp[i]){
            ans++;
        }
    }

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


Measured memory_bytes: 2176
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int main(){
  int n;
  string s;
  cin >> n >> s;
  int x = 0, res = 0;
  each(c, s){
    if (c == 'I') x++;
    else x--;
    chmax(res, x);
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n;
    cin >> n;
    int a[n];
    rep(i,n){
        cin >> a[i];
    }
    int cnt=0;
    for(int i=1;i<n-1;i++){
        if(a[i-1]<=a[i]&&a[i]<a[i+1]||a[i+1]<=a[i]&&a[i]<a[i-1])cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 2*1e5;
const ll LINF = 1LL<<61;

int main()
{
    string s, t;
    cin >> s >> t;
    s += "X";
    t += "Y";
    int n = s.size(), m = t.size();
    auto dp = make_vec(n+1, m+1, 0); //i文字見た時の～
    rep(i,n) rep(j,m)
    {
        chmax(dp[i+1][j], dp[i][j]);
        chmax(dp[i][j+1], dp[i][j]);
        if(s[i] == t[j])
        {
            chmax(dp[i+1][j+1], dp[i][j] + 1);
        }
    }
    // cout << dp << endl;
    // cout << dp[n-1][m-1] << endl;
    string ans;
    int si = n-1;
    int ti = m-1;
    while(si + ti)
    {
        if(si && dp[si][ti] == dp[si-1][ti])
        {
            si--;
            continue;
        }
        else if(ti && dp[si][ti] == dp[si][ti-1])
        {
            ti--;
            continue;
        }
        if(si && ti && s[si-1] == t[ti-1])
        {
            si--;
            ti--;
            ans += s[si];
            continue;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 38500
#include<iostream>
#include<vector>
#include<algorithm>
#define INF 100000000
using namespace std;
int main(){
	int n,m,x,cb[20];//now,now
	int temp;
	while(cin>>n>>m,n||m){
		vector<int> input;
		vector<int> dp[256];
		for(int i=0;i<m;i++){
			cin>>cb[i];
		}
		for(int i=0;i<n;i++){
			cin>>x;
			input.push_back(x);
		}
		for(int i=0;i<=n;i++)
		for(int j=0;j<=255;j++)
		dp[j].push_back(INF);
		dp[128][0]=0;
		for(int i=0;i<n;i++)
		for(int j=0;j<=255;j++){
			
				if(dp[j][i]!=INF){
					for(int k=0;k<m;k++){
						temp=j+cb[k];
						if(temp>255)
						temp=255;
						else if(temp<0)
						temp=0;
						dp[temp][i+1]=min(dp[temp][i+1],dp[j][i]+(temp-input[i])*(temp-input[i]));
					}
				}
		}
		int ans=INF;
		for(int i=0;i<=255;i++){
		if(ans>dp[i][n])
		ans=dp[i][n];
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 27000
#include "bits/stdc++.h"
using namespace std;
#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
typedef long long ll;

const int INF = 1e9;
const long long LLINF = 1e18;

int n, m;
int t[101], p[101], x[101];
int sum;
int main() {
    cin>>n;
    REP(i, 0, n){
        cin>>t[i];
        sum+=t[i];
    }
    cin>>m;
    REP(i, 0, m) cin>>p[i]>>x[i];

    REP(i, 0, m){
        cout<<sum-(t[p[i]-1]-x[i])<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.reflect.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        ArrayList<Integer> array = new ArrayList<Integer>();
        for(int i = 0; i < n; ++i){
            int e = sc.nextInt();
            array.add(e);
        }
        int ans = 0;
        for(int i = 1; i < n-1; ++i){
            if((array.get(i-1) < array.get(i) && array.get(i) < array.get(i+1))
             ||(array.get(i-1) > array.get(i) && array.get(i) > array.get(i+1))){
                ++ans;
            }
        }
        System.out.print(ans);
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pvllvll pair <vector <ll>, vector <ll> >
#define ld long double
#define veci vector <int>
#define vecll vector <ll>


const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

void solve() {
    ll a[4];
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    ll ans = -1e18;
    ans = max(ans, a[0] * a[2]);
    ans = max(ans, a[0] * a[3]);
    ans = max(ans, a[1] * a[2]);
    ans = max(ans, a[1] * a[3]);
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    ///cin >> T;
    while(T--) solve(), cout << '\n';
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int,int>P;
typedef long long ll;

P p[200000];
int main(){
	int n,m;cin>>n>>m;
	rep(i,n){
		scanf("%d%d",&p[i].first,&p[i].second);
	}
	sort(p,p+n,[](P a,P b){return a.first<b.first;});
	ll ans=0;
	rep(i,n){
		if(m<=p[i].second){
			ans+=m*(ll)p[i].first;
			m=0;break;
		}
		else{
			ans+=p[i].second*(ll)p[i].first;
			m-=p[i].second;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
n = STDIN.readline.strip.to_i
read = lambda{||STDIN.readline.strip.split(' ').map(&:to_i)}
abc = [read[].sort!, read[].sort!, read[].sort!]
r = [Array.new(n, 1), Array.new(n, 0), Array.new(n, 0)]

# puts "abc:#{abc}"

j = 0
(0...n).each do |i|
  r[1][i] = r[1][i - 1] if i > 0
  while j < n and abc[0][j] < abc[1][i]
#    puts "i:#{i}, j:#{j}, n:#{n}, abc[0][j]:#{abc[0][j]}, abc[1][i]:#{abc[1][i]}"
    r[1][i] += 1
    j += 1
  end
end

j = 0
(0...n).each do |i|
  r[2][i] = r[2][i - 1] if i > 0
  while j < n and abc[1][j] < abc[2][i]
    # puts "i:#{i}, j:#{j}, n:#{n}, abc[1][#{j}]:#{abc[1][j]}, abc[2][#{i}]:#{abc[2][i]}"
    r[2][i] += r[1][j]
    j += 1
  end
end

# puts "r1: #{r[1]}"
# puts "r2: #{r[2]}"
def sum(a)
  a.inject(0){|n, i| n += i}
end
# puts "r:#{r}"
puts sum(r[2])


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

int main(){
    cout << fixed << setprecision(12);

    double a, b, c;
    cin>> a >> b >> c;
    double PI = acos(-1.0);
    c = c/180.0*PI;
    cout << a*b*sin(c)/2.0 << endl;

    double cc = a*a + b*b -2*a*b*cos(c);
    cout << a + b + sqrt(cc) << endl;
    cout << b*sin(c) << endl;
    return 0;
}


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

#define FOR(i, j, k) for(int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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

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

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int m, k;
    cin >> m >> k;

    // m = 1, k = 0 : 0 0 1 1
    // m = 1, k = 1 : -1
    // m = 2, k = 0 : 0 0 1 1 2 2 3 3
    // m = 2, k = 1 : 0 2 1 0 2 3 1 3
    // m = 2, k = 2 : 0 3 1 0 2 1 3 2
    // m = 2, k = 3 : -1
    // m = 3, k = 3 : 0 4 1 0 2 4 5 1
    // 0 1 3 2 3 1 0 2

    if(m == 1 and k == 0) {
        cout << "0 0 1 1" << endl;
        return 0;
    }

    if(m == 1 and k == 1) {
        cout << -1 << endl;
        return 0;
    }

    if((1 << m) <= k) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> v;
    REP(i, (1 << m)) {
        if(i != k) {
            v.push_back(i);
        }
    }
    v.push_back(k);

    for(int i = (1 << m) - 1; i >= 0; i--) {
        if(i != k) {
            v.push_back(i);
        }
    }
    v.push_back(k);

    REP(i, v.size()) { cout << v[i] << " "; }
    cout << endl;

    return 0;
}


Measured memory_bytes: 2932
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int a = sc.NextInt();
        int b = sc.NextInt();
        int c = sc.NextInt();

        int answer = 0;
        if (a + b + 1 >= c)
        {
            answer = b + c;
        }
        else
        {
            answer = b + c - (c - (a + b + 1));
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092
#include<cstdio>
#include<cctype>

int main() {
	char ch,a;

	while (1) {
		scanf("%c", &ch);

		if (isalpha(ch)) {
			if (islower(ch))
				printf("%c", toupper(ch));
			else printf("%c", tolower(ch));
		}
		else printf("%c", ch);

		if (ch == '\n')
			break;
	}

	return 0;
}

Measured memory_bytes: 944
#include <stdio.h>

int main ()
{
	int a, b, s, p;
	
	scanf ("%d %d", &a, &b);
	
	s = a * b;
	p = 2 * ( a + b );
	
	printf ("%d %d\n", s, p);
	
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    long long int ans=0;
    for (int i=1;i<=n;i++)
        if(i%3 and i%5) ans+=i;
    cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>

int
main(void)
{
	int i, h, w;
	char o_str[301];
	char e_str[301];

	for (;;) {
		scanf("%d %d", &h, &w);

		if (h == 0 && w == 0)
			break;

		for (i = 0; i < w; i++) {
			o_str[i] = i & 1 ? '#' : '.';
			e_str[i] = i & 1 ? '.' : '#';
		}
		o_str[i] = '\0';
		e_str[i] = '\0';

		for (i = 0; i < h; i++)
			puts(i & 1 ? o_str : e_str);

		printf("\n");

	}

	return 0;
}



Measured memory_bytes: 2036
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

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

func nextFloat() float64 {
	sc.Scan()
	f, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func readInts(n int) []int {
	result := make([]int, n)
	for i := 0; i < n; i++ {
		result[i] = nextInt()
	}
	return result
}

var COST, M int

func main() {
	N := nextInt()
	M = nextInt()
	SS := make([][2]int, N)
	for i := 0; i < N; i++ {
		p := nextInt()
		num := nextInt()
		SS[i] = [2]int{p, num}
	}
	sort.Slice(SS, func(i, j int) bool { return SS[i][0] < SS[j][0] })
	for i := 0; i < N; i++ {
		buy(SS[i])
		if M == 0 {
			fmt.Println(COST)
			return
		}
	}
}

func buy(shop [2]int) {
	if M <= shop[1] {
		COST += M * shop[0]
		M = 0
	} else {
		COST += shop[0] * shop[1]
		M -= shop[1]
	}
}


Measured memory_bytes: 5916
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(M)]
#print(AB)

C=[[0 for _ in range(N)] for _ in range(N)]
for ab in AB:
  C[ab[0]-1][ab[1]-1]=1
  C[ab[1]-1][ab[0]-1]=1
#print(C)

ans=0
D=[0]*N

def dfs(n):
  if D[n]==0:
    D[n]=1
    for i in range(N):
      if C[n][i]==1:
        dfs(i)
      
for i,ab in enumerate(AB):
  C[ab[0]-1][ab[1]-1]=0
  C[ab[1]-1][ab[0]-1]=0

  if i<M-1:
    dfs(AB[i+1][0]-1)
  else:
    dfs(AB[i-1][0]-1)
  if sum(D)!=N:
    ans+=1  

  D=[0]*N
  C[ab[0]-1][ab[1]-1]=1
  C[ab[1]-1][ab[0]-1]=1
  
print(ans)

Measured memory_bytes: 3064
import bisect
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for a in range(N):
    for b in range(a+1, N):
        c = bisect.bisect_left(L, L[a] + L[b])
        if c > b:
            ans += c - b - 1
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
using Graph = vector<vector<int>>;
using Graph_Wei = vector<vector<pair<int,int>>>;
using ll = long long;
const long long INF = 1LL<<60; // 仮想的な無限大の値
vector<bool> seen;

Graph G;


int a[4];
int main() {

    string str;
    cin >> str;
    for(int i=0;i < 4;i++){
        a[i] = str[i] - '0';
    }
    string ans;
    int sum =0;
    //総当たりをどう記述するか
    for(int x =0;x < 8;x++){

        
        sum = a[0];
        ans = char('0' + a[0]);
        for(int i =0;i < 3;i++){
           if(x & (1 << i)){
               ans += '+';
               ans += (char)('0' + a[i+1]);
               sum += a[i+1];
           }else{
               ans += '-';
               ans += (char)('0' + a[i+1]);
               sum -= a[i+1];
           }
       }
       if(sum == 7){
           
           cout << ans + "=7"<< endl;
           break;
       }
        

    }
    
    return 0;

}

Measured memory_bytes: 256
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<LL> a(n);
	int neg_cnt = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		neg_cnt += a[i] < 0;
		a[i] = abs(a[i]);
	}
	sort(a.begin(), a.end());
	if (neg_cnt % 2) {
		a[0] = -a[0];
	}
	LL ans = accumulate(a.begin(), a.end(), 0LL);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
# ABC061D - Score Attack
import sys
input = sys.stdin.readline

def bellman_ford(N: int, M: int, E: "Array[Array[int]]") -> int or None:
    INF = float("inf")
    dist = [INF] * (N + 1)
    dist[1] = 0

    # relax edges
    for i in range(N):
        for v, u, w in E:  # w: positive -> -w
            if v != INF and dist[v] - w < dist[u]:
                dist[u] = dist[v] - w
                if i == N - 1 and u == N:  # detect negative cycles
                    return None
    return dist[-1]


def main():
    # reverse weights -> shortest path problem containing negative cycles
    N, M = tuple(map(int, input().split()))  # vertices, edges
    E = tuple(tuple(map(int, input().split())) for _ in range(M))
    ans = bellman_ford(N, M, E)
    flg = ans is not None
    print(-ans if flg else "inf")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
vector<P> v;
int main(){
	cin >> N;
	if(N%2==1){
		for(int i=1;i<=N;i++){
			for(int j=i+1;j<=N;j++){
				if(i+j!=N){
					v.pb(P(i,j));
				}
			}
		}
	}else{
		for(int i=1;i<=N;i++){
			for(int j=i+1;j<=N;j++){
				if(i+j!=N+1){
					v.pb(P(i,j));
				}
			}
		}
	}
	cout << v.size() << endl;
	for(int i=0;i<v.size();i++){
		cout << v[i].fi << ' ' << v[i].sec << endl;
	}
	return 0;
}

Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		long n = s.length();
		long p = 0;
		
		long[] oc = new long[26];
		
		for(int i = 0; i < n; i++)
			oc[s.charAt(i)-'a']++;
		
		for(int i = 0; i < 26; i++)
		{
			p += (oc[i]*(oc[i]-1))/2;
			
			
		}

		
		long an = (n*(n-1))/2;
		an-=p;
		an++;
		System.out.println(an);

	}

}


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

using namespace std;

#define Vi vector<int>
#define FOR(i,s,e) for (int i=s; i<e; i++)
#define ITER(v) v.begin(), v.end()

constexpr int MAX_N = 25;

struct Node {
    int parent, left, right;
    Node(int parent=-1, int left=-1, int right=-1) :
        parent(parent), left(left), right(right) {}
};

Node tree[MAX_N];

void add_node_to_tree(int id, int left, int right) {
    tree[id].left = left;
    tree[id].right = right;
    if (left != -1) {
        tree[left].parent = id;
    }
    if (right != -1) {
        tree[right].parent = id;
    }
}

void preorder_print(int id) {
    if (id == -1) return;
    cout << " " << id;
    preorder_print(tree[id].left);
    preorder_print(tree[id].right);
}

void inorder_print(int id) {
    if (id == -1) return;
    inorder_print(tree[id].left);
    cout << " " << id;
    inorder_print(tree[id].right);
}

void postorder_print(int id) {
    if (id == -1) return;
    postorder_print(tree[id].left);
    postorder_print(tree[id].right);
    cout << " " << id;
}

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

    int n;
    cin >> n;

    int id, left, right;
    FOR(i,0,n) {
        cin >> id >> left >> right;
        add_node_to_tree(id, left, right);
    }
    int root = -1;
    FOR(i,0,n) {
        if (tree[i].parent == -1) {
            root = i;
            break;
        }
    }
    assert(root != -1);
    cout << "Preorder" << endl;
    preorder_print(root);
    cout << endl;
    cout << "Inorder" << endl;
    inorder_print(root);
    cout << endl;
    cout << "Postorder" << endl;
    postorder_print(root);
    cout << endl;

    return 0;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define int long long
using namespace std;

int a[5005];
int dp[5005][5005];
int n,A,B;

int solve(int i, int maxx)
{
    if (i == n) return 0;
    if (dp[i][maxx] != -1) return dp[i][maxx];
    dp[i][maxx] = 0;
    if (a[i + 1] > maxx)
    {
        dp[i][maxx] = min(solve(i + 1, maxx) + A, solve(i + 1, a[i + 1]));
    } else {
        dp[i][maxx] = solve(i + 1, maxx) + B;
    }
    return dp[i][maxx];
}

signed main()
{
    //freopen("file.inp","r",stdin);
    cin >> n >> A >> B;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        for (int j = 0; j <= n; j++)
        {
            dp[i][j] = -1;
        }
    }
    dp[0][0] = -1;
    cout << solve(0, 0);
    return 0;
}


Measured memory_bytes: 195968
/* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;
#define SZ(x)               ((int)(x).size())
#define all(x)              (x).begin(), (x).end()
#define loop(i, n)          for(int i = 0; i < (n); i++)
#define cont(i, n)          for(int i = 1; i <= (n); i++)
#define circ(i, a, b)       for(int i = (a); i <= (b); i++)
#define range(i, a, b, c)   for(int i = (a); ((c) > 0 ? i <= (b) : i >= (b)); i += (c))
#define foreach(it, v)      for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define y0          y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1          y1II11II11III11I1III11II111IIII1II1I1
#define pub         push_back
#define pob         pop_back
#define mak         make_pair
typedef long long   ll;
typedef long double lf;
const int   Inf = 0x3f3f3f3f;
const ll    INF = 0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */

struct UnionFind {
	int fa[1 << 17];
	void inline init() {memset(fa, -1, sizeof(fa));}
	UnionFind() {init();}
	int inline root(int x) {return fa[x] < 0 ? x : fa[x] = root(fa[x]);}
	bool inline conn(int a, int b) {
		a = root(a); b = root(b);
		if(a == b) return 0;
		if(fa[a] < fa[b]) swap(a, b);
		return fa[b] += fa[a], fa[a] = b, 1;
	}
} dsu;

int n, m;

int main() {
	scanf("%d%d", &n, &m);
	dsu.init();
	cont(i, m) {
		int a, b; scanf("%d%d", &a, &b);
		dsu.conn(a, b);
	}
	int bl = 0;
	cont(i, n) if(dsu.root(i) == i) bl++;
	printf("%d\n", bl - 1);
	return 0;
}


Measured memory_bytes: 4332
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	int n;
	scanf("%d", &n);
	printf("Christmas");
	f(i, 25-n){
		printf(" Eve");
	}
	printf("\n");


	return 0;
}

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

using namespace std;

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

#define sz(a) int(a.size())

#define dbg(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {
    cerr << str << " : " << t << "\n";
}
template <class T, class... S> void dbs(string str, T t, S... s) {
    int idx = str.find(',');
    cerr << str.substr(0, idx) << " : " << t << ",";
    dbs(str.substr(idx + 1), s...);
}
template <class S, class T>
ostream& operator <<(ostream& os, const pair<S, T>& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template <class T> void debug(T a, T b) {
    cerr << "[";
    for (T i = a; i != b; ++i) {
        if (i != a) cerr << ", ";
        cerr << *i;
    }
    cerr << "]\n";
}

int sign(int x) {
    return x >= 0 ? 1 : -1;
}

int solve(int x, int y) {
    int diff = abs(abs(x) - abs(y));
    if (x <= y) {
        if (sign(x) != sign(y)) {
            if (y != 0) ++diff;
        }
    } else {
        ++diff;
        if (sign(x) == sign(y)) {
            if (y != 0) ++diff;
        }
    }
    return diff;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    srand(time(NULL));
    int x, y;
    cin >> x >> y;
    cout << solve(x, y) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = (n / (a+b)) * a;
  n = n % (a+b);
  if(n > a) ans += a;
  else ans += n;
  cout << ans << endl;
} 






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

int main(){
    string w;
    cin >> w;
    bool a[27]={0};
    for(int i=0;i<w.size();++i){
        a[w[i]-'a'] = !a[w[i]-'a'];
    }
    bool flag=false;
    for(int i=0;i<26;++i){
        if(a[i]){
            flag = true;
            break;
        }
    }
    if(flag)cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define lld long long int

int main(){
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if(a<=c && d<=b){
        printf("%d", d-c);
    }else if(c<=a && b<=d){
        printf("%d", b-a);
    }else if(a<=c && c<=b && b<=d){
        printf("%d", b-c);
    }else if(c<=a && a<=d && d<=b){
        printf("%d", d-a);
    }else{
        printf("0");
    }

    return 0;
}

Measured memory_bytes: 128
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int miseCount = int.Parse(Reader.ReadLine());
        for (int i = 0; i < miseCount; i++) {
            int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            eigyoDic.Add(i, new Dictionary<int, bool>());
            for (int j = 0; j < inpt.Length; j++) {
                eigyoDic[i].Add(j, inpt[j] == 1);
            }
        }
        for (int i = 0; i < miseCount; i++) {
            int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            rieki.Add(i, new Dictionary<int, long>());
            for (int j = 0; j < inpt.Length; j++) {
                rieki[i].Add(j, inpt[j]);
            }
        }
        Nullable<long> ans = GetAns(new int[miseCount], false, 0);
        if(ans == null) {
            ans = 0;
        }
        Console.WriteLine(ans.Value);
    }

    private Nullable<long> GetAns(int[] eigyoCount, bool hasEigyo, int idx) {
        if(idx >= 10) {
            if(hasEigyo) {
                long total = 0;
                for (int i = 0; i < eigyoCount.Length; i++) {
                    total += rieki[i][eigyoCount[i]];
                }
                return total;
            } else {
                return null;
            }
        }

        Nullable<long> ans = null;
        Nullable<long> ret = GetAns(eigyoCount, hasEigyo, idx + 1);
        if(ret!=null) {
            ans = ret;
        }
        int[] newCount = new int[eigyoCount.Length];
        for (int i = 0; i < eigyoDic.Count; i++) {
            newCount[i] = eigyoCount[i];
            if(eigyoDic[i][idx]) {
                newCount[i]++;
            }
        }
        ret = GetAns(newCount, true, idx + 1);
        if(ret != null) {
            if(ans == null) {
                ans = ret;
            } else {
                ans = Math.Max(ans.Value, ret.Value);
            }
        }
        return ans;
    }

    /// <summary>
    /// miseban, idx,
    /// </summary>
    private Dictionary<int, Dictionary<int, bool>> eigyoDic = new Dictionary<int, Dictionary<int, bool>>();

    private Dictionary<int, Dictionary<int, long>> rieki = new Dictionary<int, Dictionary<int, long>>();

    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"





2
1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1




";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 13524
#include<stdio.h>
#include<iostream>
using namespace std;

int N;
int main (){
    cin >> N;
    long long int ans = 0;
    int head = 0;
    int tail = 0;
    int d = 0;
    for(int i=0; i<N; i++) {
        string S;
        cin >> S;
        if(S[0] == 'B' && S[S.size()-1] == 'A') d++;
        else if(S[0] == 'B') head++;
        else if(S[S.size()-1] == 'A') tail++;
        for(int j=1; j<S.size(); j++) {
            if( S[j-1] == 'A' && S[j] == 'B') ans++;
        }
    }
    if(N == 1) cout << ans << endl;
    else {
        if(head <= 0 && tail <= 0) {
            cout << max(0,d-1) + ans << endl;
        } else {
            ans += min(head,tail) + min( d,max(head,tail)-min(head,tail));
            d -= max(head,tail)-min(head,tail);
            if(d > 0) ans += d;
            cout << ans << endl;
            }
        }
    return 0;
}


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


int main()
{
  int n; cin >> n;
  map<int, int> m;
  rep(i, n-1)
  {
    int a; cin >> a;
    m[a]++;
  }
  for (int i=1; i<=n; i++)
    printf("%d\n", m[i]);
  return 0;
}

Measured memory_bytes: 13104
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

const long double EPS = 1e-6, PI = acos((long double)-1);

//ここから編集

ll dp[1010101][2][2];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(4);

  ll N; cin >> N;

  dp[0][0][0] = 1;
  for(int i=0; i<N; i++){
    
    for(int j=0; j<2; j++){
      for(int k=0; k<2; k++){

        for(int d=0; d<10; d++){

          if(d == 0){
            if(j == 0){
              dp[i+1][1][k] += dp[i][j][k];
              dp[i+1][1][k] %= MOD;
            }else{
              dp[i+1][j][k] += dp[i][j][k];
              dp[i+1][j][k] %= MOD;
            }
          }else if(d == 9){
            if(k == 0){
              dp[i+1][j][1] += dp[i][j][k];
              dp[i+1][j][1] %= MOD;
            }else{
              dp[i+1][j][k] += dp[i][j][k];
              dp[i+1][j][k] %= MOD;
            }
          }else{
            dp[i+1][j][k] += dp[i][j][k];
            dp[i+1][j][k] %= MOD;
          }
        }
      }
    }
  }

  cout << dp[N][1][1] << endl;
}

Measured memory_bytes: 34844
extern crate core;

use std::fmt;
use std::cmp::{Ordering, min, max};
use std::fmt::{Display, Error, Formatter};
use std::collections::{VecDeque, BinaryHeap, BTreeMap};
use std::f32::MAX;

fn show<T: Display>(vec: &Vec<T>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        print!("[{}", vec[0]);
        for i in 1 .. vec.len() {
            print!(", {}", vec[i]);
        }
        println!("]");
    }
}
macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
fn main() {
    loop {
        let_all!(n: usize);
        if n == 0 {
            return
        }
        let heights = read_line!(' '; i32);
        for i in 0 .. n + 1 {
            let mut vec = Vec::with_capacity(n);
            for j in 0 .. n + 1 {
                if i != j {
                    vec.push(heights[j]);
                }
            }
            let mut res = true;
            for j in 1 .. n - 1 {
                if vec[j] - vec[j - 1] != vec[j + 1] - vec[j] {
                    res = false;
                }
            }
            if res {
                println!("{}", heights[i]);
                break
            }
        }
    }
}



Measured memory_bytes: 5056
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 1005;

ll a[MAX_N];
ll b[MAX_N];
ll c[MAX_N];
ll d[MAX_N];
map<ll,int> comb;

int main()
{
	int n;
	ll V;
	cin >> n >> V;
	rep(i,n){
		scanf("%lld",&a[i]);
	}
	rep(i,n){
		scanf("%lld",&b[i]);
	}
	rep(i,n){
		scanf("%lld",&c[i]);
	}
	rep(i,n){
		scanf("%lld",&d[i]);
	}
	rep(i,n){
		rep(j,n){
			comb[a[i]+b[j]]++;
		}
	}
	ll ans;
	rep(i,n){
		rep(j,n){
			ans += comb[V-c[i]-d[j]];
		}
	}
	cout << ans <<"\n";
	return 0;
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int main(){
    int r, g, b;
    cin >> r >> g >> b;

    int N = 100 * r + 10 * g + b;

    if (N % 4) puts("NO");
    else puts("YES");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[10000];
int sol[101][101];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, n;
    cin >> h >> w >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    int k = 1;
    for (int i = 0; i < h; ++i)
    {
        if (i % 2)
        {
            for (int j = 0; j < w; ++j)
            {
                if (a[k] == 0)
                    k++;
                a[k]--;
                sol[i][j] = k;
            }
        }
        else
        {
            for (int j = w - 1; j >= 0; --j)
            {
                if (a[k] == 0)
                    k++;
                a[k]--;
                sol[i][j] = k;
            }
        }
    }
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
            cout << sol[i][j] << ' ';
        cout << '\n';
    }
}


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

const int maxn =2e5+5;
ll a[maxn];
map<ll,ll> mp;
int main()
{
    ios::sync_with_stdio(false);
    int N;cin>>N;
    ll sum=0;
    for(int i=0;i<N;i++)
    {
        cin>>a[i];
        sum+=mp[i-a[i]];
        mp[i+a[i]]++;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 27912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7,INF=1e17;
const int iINF=1e9;
#define enld endl
bool comp(int a,int b){
    return a>b;
}
int main(){
    int n;
    cin>>n;
    vector<int>a(n),b(n);
    for(int i=0;i<n;i++)cin>>a[i];
    b=a;
    sort(b.begin(),b.end(),comp);
    for(int i=0;i<n;i++){
        if(a[i]!=b[0]){
            cout<<b[0]<<endl;

        }
        else {
            cout<<b[1]<<endl;
        }
    }

}

Measured memory_bytes: 3200
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
a = A.pop()
Res = [a]

ans = 0
flg = True
pointer = 0
for i in range(n-1):
    ans += A[pointer]
    if flg == True:
        pointer += 1
        flg = False
    else:
        flg = True
print(ans)


Measured memory_bytes: 105072
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

template<int mod>
struct ModInt {
    int x;

    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }

    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }

    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

const int mod = 1e9 + 7;
using modint = ModInt<mod>;



int main(){
    LL n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    modint ans = 0;
    rep(i, n){
        modint tmp = 0;
        REP(j, i+1, n){
            if(a[i] > a[j]) tmp+=1;
        }
        modint tmp2 = 0;
        for(int j=i-1; j>=0; j--){
            if(a[i] > a[j]) tmp2+=1;
        }
        ans += tmp * k * (k+1) / 2;
        ans += tmp2 * (k-1) * k / 2;
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  switch(s[k-1]){
    case 'A': s[k-1] = 'a';break;
    case 'B': s[k-1] = 'b';break;
    case 'C': s[k-1] = 'c';break;
  }
  cout << s << endl;
}

Measured memory_bytes: 256