akhauriyash/Code-Regression huggingface dataset:
n = int(input())
D = list(map(int, input().split()))
from collections import Counter
C = Counter(D)
#print(C)

A = [0]
C = list(C.items())
C.sort()
#print(C)
for i in range(len(C)):
    k, v = C[i]
    if k != 0 and k != 12:
        if v == 1:
            A.append(k*(-1)**i)
        elif v == 2:
            A.append(k)
            A.append(-k)
        else:
            print(0)
            exit()
    else:
        if v == 1:
            A.append(k*(-1)**i)
        else:
            print(0)
            exit()

#print(A)
m = len(A)
ans = 10**18
for i in range(m-1):
    for j in range(i+1, m):
        temp = min(abs(A[i]-A[j]), 24-abs(A[i]-A[j]))
        ans = min(ans, temp)
print(ans)


Measured memory_bytes: 38460
fun main(args: Array<String>) {
    aising2019b()
}

fun aising2019b() {
    val n = readLine()!!.toInt()
    val (a, b) = readLine()!!.split(' ').map { it.toInt() }
    val pList = readLine()!!.split(' ').map { it.toInt() }

    val answer =
        Math.min(Math.min(pList.count { it <= a }, pList.count { it in a + 1..b }), pList.count { it > b })

    println(answer)
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    string s = std::to_string(n);
    for(char c : s) {
        if(c == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

int main(){
  int stones[51];
  int n,p,i,j,stone;
  cin >> n >> p;
  while(n!=0||p!=0){
    for(i=0;i<51;i++) stones[i]=0;
    i=0;
    stone=p-1;
    stones[0]=1;
    while(stones[i]!=p){
      i=(i+1)%n;
      if(stone > 0) {
	stones[i]++;
	stone--;
      }else if(stones[i]!=0){
	stone+=stones[i];
	stones[i]=0;
      }
    }
    cout << i << endl;
    cin >> n >> p;
  }
}

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

#define ll long long
#define pb push_back
#define mp make_pair
int main() 
{
	 ios_base::sync_with_stdio(false);
     cin.tie(NULL);
      int n;
      cin>>n;
      ll sum=0;
      for(ll i=1;i<=n;i++)
      {
		  if(i%3!=0 && i%5!=0)
		   sum+=i;
	   }
	   cout<<sum<<endl;
            
}

Measured memory_bytes: 3596
#include <cstdio>
int n,x,t;
int main(){
    while(~scanf("%d",&n)){
        t=0;
        for(int i=1;i<=n;i++){scanf("%d",&x);if(x%2)t++;}
        if(t%2)puts("NO");
        else puts("YES");
    }return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int main(){
	int N;
	while(cin >> N){
		int e = 0;
		while(e*(e+1)/2 < N) ++e;
		vector<int> r;
		for(int i=e;i>=1;i--){
			if(N >= i){
				r.push_back(i);
				N -= i;
			}
		}
		for(auto it=r.rbegin();it!=r.rend();++it) cout << *it << endl;
	}
}


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

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

    string s;
    cin >> s;

    int count = 0;
    for(int i=0; i<n; i++){
        if(s[i] != s[i+1]){
            count += 1;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 512
//
//  main.cpp
//  zero
//
//  Created by 叶金炜 on 2019/4/2.
//  Copyright © 2019 okstal. All rights reserved.
//

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(a<b&&b<c)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 3076
N = int(input())

if (N % 100) % 10 == 2 or (N % 100) % 10 == 4 or (N % 100) % 10 == 5 or (N % 100) % 10 ==7 or (N % 100) % 10 ==9:
    print("hon")
elif (N % 100) % 10 == 0 or (N % 100) % 10 ==1 or (N % 100) % 10 ==6 or (N % 100) % 10 ==8:
    print("pon")
elif (N%100)%10 == 3:
    print("bon")



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

using namespace std;

const int   mod = 998244353;
const int   N   = (1 << 18);

typedef vector<int> vi;

int add(int a,int b)    {
    a += b;
    if(a >= mod)a -= mod;
    if(a <  0)  a += mod;
    return  a;
}
int mul(int a,int b)    {
    return (long long)a * b % mod;
}
int Pow(int a,int b)    {
    int ans = 1;
    while (b)   {
        if(b & 1)   ans = mul(ans,a);
        a = mul(a,a);   b >>= 1;
    }
    return  ans;
}
void fwt(int *a,int n,int upd)  {
    upd = (mod + 1) / (upd + 1);
    upd =  upd % mod;
    for(int i = 1 ; i < n ; i <<= 1)
    for(int j = 0 ; j < n ; j += (i << 1))
    for(int k = j ; k < j + i ; ++k)    {
        int x = a[k];
        int y = a[k + i];
        a[k]     = mul(add(x, y),upd);
        a[k + i] = mul(add(x,-y),upd);
    }
}

int a[N], b[N];
int n, Sum = 0;

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    cin >> n;   n = (1 << n);
    
    for(int i = 0 ; i < n ; ++i)    cin >> a[i], Sum += a[i];
    for(int i = 0 ; i < n ; ++i)    a[i] = mul(a[i],Pow(Sum,mod - 2));
    for(int i = 0 ; i < n ; ++i)    b[i] = mod - 1;
    
    a[0] = add(a[0],-1);
    b[0] = add(b[0], n);
    
    fwt(a,n,0);
    fwt(b,n,0);
    
    for(int i = 0 ; i < n ; ++i)    a[i] = mul(b[i],Pow(a[i],mod - 2));
    
    fwt(a,n,1);
    
    for(int i = 0 ; i < n ; ++i)    cout << add(a[i],-a[0]) << "\n";
}

Measured memory_bytes: 4864
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for(int i = 0;i<n;i++)a[i]=sc.nextInt();
    int[] b = new int[n];
    for(int i = 0;i<n;i++)b[i]=sc.nextInt();
    int[] c = new int[n];
    for(int i = 0;i<n-1;i++)c[i]=sc.nextInt();
    c[n-1]=0;

    int count = 0;
    int now;
    int before=n-1;
    int satisfaction = 0;
    while(count<n){
      now = a[count]-1;
      satisfaction+=b[now];
      if(before+1==now)satisfaction+=c[before];
      before=now;
      count++;
    }
    System.out.println(satisfaction);
  }
}


Measured memory_bytes: 35548
/* Author rumoisen */
/* created 2018/11/08 */

#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <iostream>

using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

void no(){cout<<"No"<<endl;exit(0);}
void yes(){cout<<"Yes"<<endl;exit(0);}
void No(){cout<<"NO"<<endl;exit(0);}
void Yes(){cout<<"YES"<<endl;exit(0);}

using namespace std;

int main(void)
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((a+b)>(c+d)) cout<<"Left"<<endl;
    else if((a+b)<(c+d)) cout<<"Right"<<endl;
    else cout<<"Balanced"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define INF 0xfffffff
using namespace std;
int map[1100][1100];
int main()
{
	int n,m,k,i,j,a,b,c,sum1;
	while(scanf("%d",&n),n)
	{
		for(i=0;i<1100;i++)
		for(j=0;j<1100;j++)
		{
			map[i][j]=INF;
			map[i][i]=0;
		}
		int Max=0;
		for(i=0;i<n;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
			Max=max(Max,a);
			Max=max(Max,b);
			map[a][b]=c;
			map[b][a]=c;
		}
		for(k=0;k<=Max;k++)
		for(i=0;i<=Max;i++)
		for(j=0;j<=Max;j++)
		{
			if(map[i][j]>map[i][k]+map[k][j])
			map[i][j]=map[i][k]+map[k][j];
		}
		int sum=INF;
		int ans=0;
		for(i=0;i<=Max;i++)
		{
			sum1=0;
			for(j=0;j<=Max;j++)
		    {
			   sum1+=map[i][j];
		    }
		    if(sum1<sum)
			{
				sum=sum1;
				ans=i;
			}
		}
		printf("%d %d\n",ans,sum);
	}
	return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

/*
input 

8
1 2 3 4 5 6 7 8
*/

int main()
{
    int n; cin >> n;
    vector<int> A;
    rep(i,n){
        int Ai; cin >> Ai;
        A.push_back(Ai);
    }
    int q; cin >> q;
    rep(i,q){
        int b, e; cin >> b >> e;
        reverse(A.begin()+b, A.begin()+e);
    }
    rep(i,n){
        cout << A[i];
        if(i != n-1) cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3172
// CODING BEAST
/*******************************************************************************************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define Precision(a) cout << fixed << setprecision(a)

using ll = long long;
ll inf = 1e18;
using vb = vector<bool>; using vc = vector<char>; using vd = vector<double>; using vi = vector<int>; using vvi = vector<vi>;
using vll = vector<ll>; using vvll = vector<vll>; using pi = pair<int, int>; using pll = pair<ll, ll>;
#define endl "\n"
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i = 0; i < n; i++)
#define repc(i,a,n) for(ll i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define pow2(x) (1ll<<(x))
#define Blazing_fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define trav(a,v) for(auto &a:v)
int a[8] = { -1, -1, -1, 0, 0, 1, 1, 1};
int b[8] = { -1, 0, 1, -1, 1, -1, 0, 1};
inline ll power(ll x, ll y)
{
    ll temp;
    if ( y == 0)
        return 1;
    temp = power(x, y / 2) ;
    if (y % 2 == 0)
        return (temp * temp) ;
    else
        return (x * temp * temp) ;
}
bool sortbysec(pll & a, pll & b) {
    return (a.second < b.second);
}
/*
ll fact(ll n)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
        res = (res * i) ;
    return res;
}

ll ncr(ll n, ll r)
{
    return fact(n) / (fact(r) * fact(n - r));
}
bool isprime(ll n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if ((n % 2 == 0) || (n % 3 == 0)) return false;
    for (ll i = 5; i * i <= n; i = i + 6)
        if ((n % i == 0) || (n % (i + 2) == 0)) return false;

    return true;
}*/
/*********************************************************************************************************************************************************/
bool checkValidity(ll a, ll b, ll c)
{
    // check condition
    if (a + b <= c || a + c <= b || b + c <= a)
        return false;
    else
        return true;
}
signed main() {
    ll n; cin >> n;
    vll v(n);
    rep(i, n) {
        cin >> v[i];
    }
    sort(all(v));
    set<ll>s;
    ll ans = 0;
    rep(i, n - 2) {
        for (ll j = i + 1; j < n - 1; j++) {
            for (ll k = j + 1; k < n; k++) {
                s.insert(v[i]);
                s.insert(v[j]);
                s.insert(v[k]);
                if (s.size() == 3) {
                    if (v[i] + v[j] > v[k]) {
                        ans++;
                    }
                }
                s.clear();

            }
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define int long long
#define int32 int32_t
#define PI 2 * acos(0)

using namespace std;

vector<vector<int>>kek;

void print(vector<int>kek) {
    for(int i = 0; i < kek.size(); i++) {
        cout << kek[i] << " ";
    }
    cout << "\n";
}


void print(vector<vector<int>>kek) {
    for(int i = 0; i < kek.size(); i++) {
        print(kek[i]);
        cout << "\n";
    }
}

vector<int> generateSubsets(int s,int n) {
    vector<int>subset;
    for(int i = 0; i < n; i++) {
        if((s & (1<<i))) subset.push_back(i);
    }
    return subset;

}

int summ(vector<int>subset, int x) {
    int sum = 0;
    vector<int> knowledge(kek[0].size()  - 1,0);
    for(auto i : subset) {
        sum += kek[i][0];
        for(int j = 0; j < knowledge.size();j++) {
            knowledge[j] += kek[i][j+1];
        }
    }
    for(int j = 0; j < knowledge.size();j++) {
        if(knowledge[j]  < x) return 0;
    }
    return sum;
}

int32 main() {
    ios_base::sync_with_stdio(false);
    int n,m,x, k;
    cin >> n >> m >> x;
    for(int i = 0; i < n; i++) {
        vector<int>tmp;
        for(int j = 0; j <= m; j++) {
            cin >> k;
            tmp.push_back(k);
        }
        kek.push_back(tmp);
    }

    int mini = INT32_MAX;
    bool once = false;
    for(int i = 0; i < (1 << n); i++) {
        int res = summ(generateSubsets(i, n), x);
        if(res == 0) continue;
        mini = min(mini, summ(generateSubsets(i, n), x));
        once = true;
    }
    if(once) {
        cout << mini;
    }else cout << -1;

    return 0;
 }

Measured memory_bytes: 3588
(defun solver ()
  (let ((n (read))
        (a (read))
        (b (read))
        (sum 0))
    (loop for i from 1 to n do
          (when (<= a (apply #'+ (map 'list #'digit-char-p (format nil "~a" i))) b)
            (incf sum i)))
    (format t "~a~%" sum)))

(solver)

Measured memory_bytes: 19300
floor = [[[0] * 10 for x in range(3)] for y in range(4)]

for c in range(int(input())):
    (b,f,r,v) = [int(x) for x in input().split()]

    floor[b-1][f-1][r-1] += v

for x in range(3 * 4):
    if x % 3 == 0 and not x == 0:
        print('#' * 20)
    print('',' '.join(str(y) for y in floor[int(x / 3)][x % 3]))

Measured memory_bytes: 6732
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	int x,n;
	cin >> x >> n;
	set<int> s;
	for(int i=0;i<n;i++){
		int temp;
		cin >> temp;
		s.insert(temp);
	}
	int dif = 1000000;
	int ans = 0;
	for(int i=0;i<=101;i++){
		if(s.find(i) != s.end())
			continue;
		//cout << "dif:" << dif << "\n";
		//dif = min(dif,abs(x-i));
		if(dif > abs(x-i)){
			ans = i;
			dif = abs(x-i);
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main() {
    ll n, t;
    cin >> n >> t;
    vector<ll> z(n);
    ll ans = 1;
    ll rieki = 0;
    ll mn = 1341398495;
    for (int i = 0; i < n; i++) {
        cin >> z[i];
        mn = min(mn, z[i]);
        if (rieki == z[i] - mn)ans++;
        if (rieki < z[i] - mn) {
            rieki = z[i] - mn;
            ans = 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;

int main(){
    int n;
    string s;
    cin>>n;
    cin>>s;
    int r = 0;
    int g = 0;
    int b = 0;
    rep(i,0,n-1){
        if(s[i]=='R') r++;
        if(s[i]=='G') g++;
        if(s[i]=='B') b++;
    }
    ll ans = 1LL*r*g*b;

    rep(i,0,n-1){
        for(int d=1;i+2*d<n;d++){
            int j = i + d;
            int k = j + d;
            if(s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k]) ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using vec2div = vector<vector<long long>>;

int main(){
	long long a, b;
	cin >> a >> b;
	
	cout << a*b << endl;
	
	
	long long i;
	for(i=0;i<1;i++){
		
	}
	

}

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

using namespace std;

class UnionFind {
public:
  vector<int> par;
  vector<int> rank;
  
  void init(int n) {
    par.resize(n);
    rank.resize(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
      rank[i] = 0;
    }
  }
  
  int find(int x) {
    if (par[x] == x) {
      return x;
    }
    else {
      par[x] = find(par[x]);
      return par[x];
    }
  }
  
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) {
      return;
    }
    
    if (rank[x] < rank[y]) {
      par[x] = y;
    }
    else {
      par[y] = x;
      if (rank[x] == rank[y]) {
        rank[x]++;
      }
    }
  }
  
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(n), x(m), y(m);
  UnionFind uf;
  uf.init(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
    uf.unite(x[i], y[i]);
  }
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += uf.same(i, p[i]);
    fprintf(stderr, "%d %d %d\n", uf.same(i, p[i]), i + 1, p[i] + 1);
  }
  cout << ans << endl;
  return 0;
}

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

using namespace std;

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

    ll r;
    cin >> r;

    cout << 3 * r * r << endl;
}


Measured memory_bytes: 256
def ok(aa, bb, c):
    total = 0
    for j,a in enumerate(aa):
        total += a * bb[j]
    total += c
    return total > 0


def solver(aa, bb, c):
    count = 0
    for a in aa:
        if ok(a, bb, c):
            count += 1
    return count

if __name__ == '__main__':

    n, m, c = map(int, input().split())
    bb = list(map(int, input().split()))
    aa = []
    for _ in range(n):
        aa.append(map(int, input().split()))

    ans = solver(aa, bb, c)
    print(ans)

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

idxs = [[] for _ in range(3)]
for i in range(N):
    if S[i] == 'R':
        idxs[0].append(i)
    elif S[i] == 'G':
        idxs[1].append(i)
    else:
        idxs[2].append(i)

import itertools
import bisect

ans = 0
for ch in itertools.permutations(range(3)):
    for idx_a in idxs[ch[0]]:
        for idx_b in idxs[ch[1]]:
            if idx_b < idx_a: continue
            pos_c = bisect.bisect_left(idxs[ch[2]], idx_b)
            pos_ex = bisect.bisect_left(idxs[ch[2]], 2 * idx_b - idx_a)
            #
            ans_tmp = len(idxs[ch[2]]) - pos_c
            if pos_ex < len(idxs[ch[2]]) and idxs[ch[2]][pos_ex] == 2 * idx_b - idx_a:
                ans_tmp = max(0, ans_tmp - 1)
            #
            ans += ans_tmp

print(ans)

Measured memory_bytes: 70692
import math

def dfs(sc, i=0, qn=0, used=set()):
    if sc <= 0:
        return qn
    if i == d:
        i -= 1
        while i in used:
            i -= 1
        hanpa = math.ceil(sc / (100 * (i + 1)))
        if hanpa >= pc[i][0]:
            return inf
        return qn + hanpa
    p, c = pc[i]
    zenbu = (i + 1) * 100 * p + c
    used.add(i)
    re1 = dfs(sc - zenbu, i + 1, qn + p, used)
    used.remove(i)
    re2 = dfs(sc, i + 1, qn, used)
    return min(re1, re2)

inf = 10 ** 9
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(d)]
print(dfs(g))


Measured memory_bytes: 3188
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    string s;
    R(s);
    int an=0;
    REP(i,4){
        if(s[i]=='+')an++;
        else an--;
    }
    W(an);
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import functools


M = 10 ** 9 + 7


def sum_mod(xs):
    return functools.reduce(lambda x, y: (x + y) % M, xs) % M


def compute(bs):
    term1 = sum_mod(bs) * sum_mod(bs) % M
    term2 = sum_mod(b * b for b in bs)
    double_res = (term1 - term2) % M
    inv2 = pow(2, M - 2, M)
    res = double_res * inv2 % M
    return res


def main():
    n = int(input())
    bs = [int(b) for b in input().split()]
    res = compute(bs)
    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 31984
#include "bits/stdc++.h"
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

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

 #define rep(i, a, b) for (int i=a; i<(b); i++)
    
 #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 trav(container, it) for(typeof(container.begin()) it=container.begin(); it!=container.end(); it++)
 
 #define PI 3.14159265358979323846264338327950L
const int MOD = 1000000007;
const char nl = '\n';

vi v;
bool check(int i,int j,int k)
{
    if(v[i]+v[j]>v[k] and v[i]+v[k]>v[j] and v[j]+v[k]>v[i]) return true;

    return false;
}
int main() 
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;cin>>n;

    v.resize(n);

    rep(i,0,n)
    {
        cin>>v[i];
    }

    int c=0;

    for(int i=0;i<n-2;++i)
    {
        for(int j=i+1;j<n-1;++j)
        {
            if(v[i]!=v[j])
            {
                for(int k=j+1;k<n;++k)
                {
                    if(v[j]!=v[k] and v[i]!=v[k])
                    {
                        if(check(i,j,k)) c++;
                        /* cout<<v[i]<<v[j]<<v[k]<<nl; */
                    }
                }

            }
        }      
    }

    cout<<c;

}


Measured memory_bytes: 3660
#include<stdio.h>
int main(){
int a[3000],b[3000],i,N=0;
scanf("%d %d",&a[0],&b[0]);
for(i=1;a[i-1]!=0||b[i-1];i++)
{
scanf("%d %d",&a[i],&b[i]);
N++;
}
for(i=0;i<=N-1;i++)
{
     if(a[i]<=b[i])
     {
      printf("%d %d\n",a[i],b[i]);
      }
      else
      { 
      printf("%d %d\n",b[i],a[i]);
       }
}
return 0;
}


Measured memory_bytes: 2096
#include <iostream>
using namespace std;
int main(){
  int n,flag=0;
  cin >> n;
  
  for(int i=0;i<3;i++){
    if(n%10==7){
      cout << "Yes" << endl;
      break;
    }
    else{
      flag++;
    }
    n/=10;
  }
  if(flag==3) cout << "No" << endl;
}

Measured memory_bytes: 3628
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define range_for(i, b, e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define step(n) rep(_, n)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define Unique(a) a.erase(unique(Range(a)), a.end())
# define pb push_back
# define len(x) ((int)(x).size())
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
# define LINT_MAX (LONG_LONG_MAX)
# define cauto const auto
using namespace std;
using lint = long long;
template <class Type> inline constexpr Type Square(Type x) { return x * x; }
template <class Type> inline constexpr Type Pow5(Type x) { return (x)*(x)*(x)*(x)*(x); }
template <class Type> inline constexpr bool InRange(const Type& x, const Type& i, const Type& a) { return (i <= x) && (x <= a); }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a<b) { a=b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Integer>bool IsOdd(Integer &n) { return n & 1; }
template<class Integer>bool IsEven(Integer &n) { return !(n & 1); }
int ctoi(const char c) { return ('0' <= c && c <= '9') ? (c - '0') : -1; }
string YesNo(bool b) { return b ? "Yes" : "No"; }
string YESNO(bool b) { return b ? "YES" : "NO"; }
string yesno(bool b) { return b ? "yes" : "no"; }
void Print() { cout << endl; }
template <class Head, class... Tail> void Print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; Print(forward<Tail>(tail)...); }
template <class T> void Print(vector<T> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }
template <class T> void Print(vector<vector<T>> &df) { for (auto& vec : df) { Print(vec); } }

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

    for (lint x = 0; Pow5(x) < LINT_MAX; ++x)
    {
        lint y5 = Pow5(x) - X;
        lint y;
        if (y5 < 0)
        {
            y = powl((long double)-y5, (long double)0.2);
            if (-Pow5(y) == y5)
            {
                Print(x, -y);
                return 0;
            }
        }
        else
        {
            y = powl((long double)y5, (long double)0.2);
            if (Pow5(y) == y5)
            {
                Print(x, y);
                return 0;
            }
        }
    }

    for (lint x = 0; Pow5(x) > LLONG_MIN; --x)
    {
        lint y5 = Pow5(x) - X;
        lint y;
        if (y5 < 0)
        {
            y = powl((long double)-y5, (long double)0.2);
            if (-Pow5(y) == y5)
            {
                Print(x, -y);
                return 0;
            }
        }
        else
        {
            y = powl((long double)y5, (long double)0.2);
            if (Pow5(y) == y5)
            {
                Print(x, y);
                return 0;
            }
        }
    }


    return 0;
}



Measured memory_bytes: 3692
#include <stdio.h>
main(){
  int a,b,c,tmp,i,j;
  scanf("%d %d %d",&a,&b,&c);
  if(a>b){
    tmp=a;
    a=b;
    b=tmp;
  }
  if(a>c){
    tmp=a;
    a=c;
    c=tmp;
  }
  if(b>c){
    tmp=b;
    b=c;
    c=tmp;
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}
      

Measured memory_bytes: 596
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>

//エイリアス
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};



int main(){
    Stream io;

    int L, R, d;
    io.read(L, R, d);
    int ans = 0;
    for(int i = L; i <= R; i++){
        if(i % d == 0) ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3644
char*a,*b;main(i,m){for(;~scanf("%as%as",&a,&b);printf("%d\n",m)){int C[2][4001]={m=0},j,t,c;for(;c=*a++;i^=1)for(j=0;t=b[j++];t>m?m=t:0)t=C[1-i][j]=c-t?0:C[i][j-1]+1;}}

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

#define FILE
#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

int n;
string s;
map<string, int> a;
int main()
{
    #ifdef FILEs
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    cin >> n;
    for(int i = 1; i <= n; i ++){
        cin >> s;
        a[s] ++;
    }
    int mx = 0;
    for(auto x: a){
        mx = max(mx, x.se);
    }
    vector<string> res;
    for(auto x: a){
        if(x.se == mx){
            res.push_back(x.fr);
        }
    }
    sort(res.begin(), res.end());
    for(auto x: res){
        cout << x << "\n";
    }
}


Measured memory_bytes: 25584
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val op = sc.next()
    val b = sc.nextInt()
    println(when (op) {
        "+" -> a + b
        "-" -> a - b
        else -> 0
    })
}


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

int main()
{
    int x,y,x1,y1;
    cin>>x>>y>>x1>>y1;
    if(x + y < x1 + y1){
        cout<<"Right"<<endl;
    }else if(x + y > x1 + y1){
        cout<<"Left"<<endl;
    }else{
        cout<<"Balanced"<<endl;
    }
    return 0 ;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> hs(n);
    for (int& h : hs) {
        cin >> h;
    }
    sort(hs.begin(), hs.end());
    int best = hs[k-1] - hs[0];
    for (int i = 0; i + k <= n; ++i) {
        best = min(best, hs[i+k-1]-hs[i]);
    }
    cout << best << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    ll l, r; cin >> l >> r;
    ll ans = 2019;
    if (r - l >= 2019) {
        cout << 0 << endl;
        return 0;
    } else {
        FOR(i, l, r) {
            FOR(k, i + 1, r + 1) {
                ans = min(ans, (ll)(i * k) % 2019);
            }
        }
    }
    cout << ans << endl;
}


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

#define ll long long

int MAX(int a, int b){
    if(a >= b) return a;
    else return b;
}

int MIN(int a, int b){
    if(a >= b) return b;
    else return a;    
}

int main(){

    int N,M;
    int i,j,k;
    int count=1;
    bool flag = false;

    cin >> N;

    vector<int> a(100);

    for(i=0;i<N;i++)cin >> a.at(i);

    sort(a.begin(),a.end(),greater<int>());

    for(i=0;i<N-1;i++){
        if(a.at(i) == a.at(i+1)){
            continue;
        }
        count ++;
    }

    cout << count << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
const int MO=1e9+7;
int n,a[500010];
LL cnt[500010],f[500010];
int main(){
	cin>>n;
	FOR(i,1,n) getint(a[i]);
	cnt[a[1]]=1;
	FOR(i,1,n){
		f[i]=cnt[a[i]];
		if (a[i]!=a[i+1]) (cnt[a[i+1]]+=f[i])%=MO;
	}
	f[n]=(f[n]%MO+MO)%MO;
	cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 8320
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a;cin>>a;
  cout<<(1000-a%1000)%1000;
}


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

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

    ll a[n];
    ll b[n];
    ll c[n];
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < n; j++){
            if(i == 0){
                cin >> a[j];
            }else if(i == 1){
                cin >> b[j];
            }else{
                cin >> c[j];
            }
        }
    }

    sort(a, a + n);
    sort(b, b + n);
    sort(c, c + n);

    ll ans = 0;
    for(int i = 0; i < n; i++){
        ll poj = lower_bound(a, a + n, b[i]) - a;
        ll poj_2 = upper_bound(c, c + n, b[i]) - c;
        ans += poj * (n - poj_2);
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 2688
b = []
c = []
d = []
while True:
    a = input().split()
    a[0] = int(a[0])
    a[1] = int(a[1])
    if a[0] == 0 and a[1] == 0:
        break
    else:
        b.append("#"*a[1])
        d.append("#"+("."*(a[1]-2))+"#")
        c.append(a[0])
for i in range(len(c)):
    print(b[i])
    for j in range(c[i]-2):
        print(d[i])
    print(b[i])
    print("\n",end="")


Measured memory_bytes: 5624
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007ll
using namespace std;
int n,k;
ll jc[4000005],njc[4000005],dp[2005][2005];
ll fp(ll x,int k=1000000005){
    ll ans=1;
    while(k){
        if(k&1)ans=ans*x%orz;
        k>>=1,x=x*x%orz;
    }
    return ans;
}
int main(){
    scanf("%d%d",&n,&k);
    if(n==1||k==1){
        puts("1");
        return 0;
    }
    jc[0]=1;
    for(int i=1;i<=n*k;++i)jc[i]=jc[i-1]*i%orz;
    njc[n*k]=fp(jc[n*k]);
    for(int i=n*k;i;--i)njc[i-1]=njc[i]*i%orz;
    dp[0][1]=1;
    for(int i=2;i<=n;++i)dp[0][i]=dp[0][i-1]*jc[i*k-i-1]%orz*njc[k-2]%orz*njc[i*k-i-k+1]%orz;
    for(int i=1;i<n;++i){
        dp[i][i]=dp[i-1][i];
        for(int j=i+1;j<=n;++j)dp[i][j]=(dp[i][j-1]*jc[i+j*k-j-1]%orz*njc[k-2]%orz*njc[i+j*k-j-k+1]%orz+dp[i-1][j])%orz;
    }
    printf("%lld\n",dp[n-1][n]*jc[n]%orz);
    //system("pause");
    return 0;
}


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

int gcd(int p, int q) {
  if (!(p % q)) return q;
  else return gcd(q, p % q);
}

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


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

int main(){
	int a;
	int x=0;
	long long int min=10000000;
	int b[105];
	cin>>a;
	for(int i=0;i<a;i++){
		cin>>b[i];
	}
	for(int i=1;i<=100;i++){
		for(int j=0;j<a;j++){
			x=x+(b[j]-i)*(b[j]-i);
		}
		if(x<min){
			min=x;
		}
		x=0;
	}
	cout<<min<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pf push_front
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define SIZE 200010
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define print(x) for(auto el: x) cout<<el<<" ";cout<<endl
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<pii,vector<pii>,greater<pii> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define mitr map<int,int>:: iterator


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


int32_t main()
{
    fast;
    int n;cin>>n;
    int *arr=new int[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];

    sort(arr,arr+n);
    if(n&1)
    {
        cout<<0;
        return 0;
    }

    int val1=arr[n/2-1];
    int val2=arr[n/2];
    cout<<val2-val1;

}

Measured memory_bytes: 1152
# ABC151C - Welcome to AtCoder

n,m=map(int,input().split())
acs=[0]*n
was=[0]*n

for i in range(m):
    p,s=input().split()
    p=int(p)
    if s=="AC":
        acs[p-1]+=1
    else:
        if not acs[p-1]:
            was[p-1]+=1

ac,wa=0,0
for i in range(n):
    if acs[i]:
        ac+=1
        wa+=was[i]

print(ac,wa)

Measured memory_bytes: 4596
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int N;
int A[100000];
int Q;
int B;
int C;
int cnt[100000+1];
int main(){
  int i, xr20shxY;
  long long res = 0;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  rd(Q);
  for(i=(0);i<(N);i++){
    cnt[A[i]]++;
  }
  for(i=(0);i<(100000+1);i++){
    res += (long long) i * cnt[i];
  }
  for(xr20shxY=(0);xr20shxY<(Q);xr20shxY++){
    rd(B);
    rd(C);
    res += (long long)(C - B) * cnt[B];
    cnt[C] += cnt[B];
    cnt[B] = 0;
    wt_L(res);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// int N, A[1d5], Q, B, C;
// int cnt[1d5+1];
// {
//   ll res = 0;
//   rd(N,A(N),Q);
//   rep(i,N) cnt[A[i]]++;
//   rep(i,1d5+1) res += (ll) i * cnt[i];
//   rep(Q){
//     rd(B,C);
//     res += (ll)(C - B) * cnt[B];
//     cnt[C] += cnt[B];
//     cnt[B] = 0;
//     wt(res);
//   }
// }


Measured memory_bytes: 6460
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	class Hand {
		final String[] win = new String[] {
			"null", "one pair", "two pair", "three card", "straight", "full house", "four card"
		};

		int[] cards;

		public Hand(String s) {
			cards = new int[5];
			String[] ss = s.split(",");
			for (int i = 0 ; i < 5 ; i++) cards[i] = Integer.parseInt(ss[i]);
			Arrays.sort(cards);
		}

		public void display() {
			System.out.println(Arrays.toString(cards));
		}

		public int judge() {
			int[] temp = new int[5];
			int[] accum = new int[14];
			for (int i = 0 ; i < 5 ; i++) {
				temp[i] = cards[i] - cards[0];
				accum[temp[i]] += 1;
			}
			Arrays.sort(accum);
			if (Arrays.binarySearch(accum, 4) >= 0) return 6;
			if (Arrays.binarySearch(accum, 3) >= 0) {
				if (Arrays.binarySearch(accum, 2) >= 0) return 5;
				else return 3;
			}
			if (Arrays.equals(temp, (new int[] {0,1,2,3,4}))
				|| Arrays.equals(temp, (new int[] {0,9,10,11,12}))) return 4;
			int count = 0;
			for (int i = 1 ; i < 14 ; i++)
				if (accum[i] == 2) count++;
			switch (count) {
			case 1: return 1;
			case 2: return 2;
			default: return 0;
			}
		}
	}


	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Main m = new Main();

		String line;
		while ((line = br.readLine()) != null) {
			Hand hand = m.new Hand(line);
			System.out.println(hand.win[hand.judge()]);
		}

	}

}

Measured memory_bytes: 16924
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

void get_probability(int N, double *P){
    double dp[N+1][N+1];
    dp[0][0] = 1.0;
    for(int i=1; i<=N; i++){
	dp[i][0] = dp[i-1][0]*(1-P[i-1]);
        dp[0][i] = 0;
    }
    for(int i=1; i<=N; i++){
        for(int j=1; j<=N; j++){
	    dp[i][j] = dp[i-1][j]*(1-P[i-1])+dp[i-1][j-1]*P[i-1];
        }
    }
    double prob = 0.0;
    for(int i=N/2+1; i<=N; i++)
        prob += dp[N][i];
    cout.precision(10);
    cout << prob << endl;

}

int main()
{
    int N;
    cin >> N;
    double P[N];
    for(int i=0; i < N; i++)
        cin >> P[i];
    /*for(int i=0; i<N; i++)
        cout << P[i] << " ";
    cout << endl;
    */
    get_probability(N, P);
    return 0;
}


Measured memory_bytes: 70528
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
const int N=100005;
int n,m;
vector<int>G[N];
int d[N];
int x[N],y[N];
int fa[N];
int getf(int v)
{
	if(v==fa[v]) return v;
	fa[v]=getf(fa[v]);
	return fa[v];
}
bool merge(int u,int v)
{
	int f1=getf(u),f2=getf(v);
	if(f1!=f2)
	{
		fa[f2]=f1;
		return true;
	}
	else return false;
}
vector<pair<int,int> >res;
void kruskal()
{
	for(int i=1;i<=n;i++)
		fa[i]=i;
	for(int i=1;i<=m;i++)
		if(merge(x[i],y[i])) G[x[i]].push_back(y[i]),G[y[i]].push_back(x[i]);
		else res.push_back(make_pair(x[i],y[i])),d[x[i]]++;
	return;
}
void dfs(int u,int father)
{
	for(int v:G[u])
	{
		if(v==father) continue;
		dfs(v,u);
		if(d[v]&1) res.push_back(make_pair(v,u)),d[v]++;
		else res.push_back(make_pair(u,v)),d[u]++;
	}
	return;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
		scanf("%d%d",&x[i],&y[i]);
	if(m&1)
	{
		printf("-1");
		return 0;
	}
	kruskal();
	dfs(1,0);
	for(auto [u,v]:res)
		printf("%d %d\n",u,v);
	return 0;
}

Measured memory_bytes: 19344