akhauriyash/Code-Regression huggingface dataset:
#ifdef __APPLE__
    # include <iostream>
    # include <cmath>
    # include <algorithm>
    # include <stdio.h>
    # include <cstdint>
    # include <cstring>
    # include <string>
    # include <cstdlib>
    # include <vector>
    # include <bitset>
    # include <map>
    # include <queue>
    # include <ctime>
    # include <stack>
    # include <set>
    # include <list>
    # include <random>
    # include <deque>
    # include <functional>
    # include <iomanip>
    # include <sstream>
    # include <fstream>
    # include <complex>
    # include <numeric>
    # include <immintrin.h>
    # include <cassert>
    # include <array>
    # include <tuple>
    # include <unordered_map>
    # include <unordered_set>
    # include <thread>
#else
    # include <bits/stdc++.h>
#endif

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;

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

const int max_n = -1, inf = 1000111222;

int main() {
//    freopen("barik.in", "r", stdin);
//    freopen("barik.out", "w", stdout);

    int n;
    cin>>n;
    if (n%1000==0){
        cout<<0<<"\n";
    }
    else{
        cout<<1000-n%1000<<"\n";
    }
}


Measured memory_bytes: 3620
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
int main() {
    string S;

    cin >> S;
    if(S == "SUN") {
        cout<<7<<endl;
    } else if(S == "MON") {
        cout<<6<<endl;
    } else if(S == "TUE") {
        cout<<5<<endl;
    } else if(S == "WED") {
        cout<<4<<endl;
    } else if(S == "THU") {
        cout<<3<<endl;
    } else if(S == "FRI") {
        cout<<2<<endl;
    } else if(S == "SAT") {
        cout<<1<<endl;
    }
}

Measured memory_bytes: 256
// ALDS_1_2_B.cpp
// Selection Sort
#include <iostream>
#include <vector>
using namespace std;

void trace(vector<int> &nums, int N)
{
	for (int i = 0; i < N; i++) {
		if (i >= 1) cout << " ";
		cout << nums[i];
	}
	cout << endl;
}

void myswap(int &a, int &b)
{
	int t = a;
	a = b;
	b = t;
}

void selectionSort(vector<int> &nums, int N, int& cnt)
{
	for (int i = 0; i < N; i++) {
		int minPos = i;
		for (int j = i+1; j < N; j++) {
			if (nums[j] < nums[minPos]) minPos = j;
		}
		if (i != minPos) {
			myswap(nums[i], nums[minPos]);
			cnt++;
		}
	}
	
}

int main()
{
	int N;
	cin >> N;
	vector<int> nums(N);
	for (int i =0; i < N; i++) {
		cin >> nums[i];
	}
	int cnt = 0;
	selectionSort(nums, N, cnt);
	trace(nums, N);
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3092
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /////////////////////
    // Write code below /
    /////////////////////
    int A, B;
    cin >> A >> B;
    int numberOfCoins = 0;
    for (int i = 0; i < 2; i++) {
        if (A < B) {
            numberOfCoins += B--;
        } else {
            numberOfCoins += A--;
        }
    }
    cout << numberOfCoins << endl;
    
    return 0;
}


Measured memory_bytes: 256
// 基本テンプレート (縮小版)

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
typedef pair<int, int> pii;
typedef long long ll;
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, A;
int x[51], dp[51][51][2501];

signed main() {
    cin >> N >> A;
    rep(i,0,N) cin >> x[i];

    dp[0][0][0] = 1;
    rep(i,0,N) repq(j,0,i) rep(k,0,2501) {
        dp[i+1][j][k] += dp[i][j][k];
        if(k+x[i] > 2500) continue;
        dp[i+1][j+1][k+x[i]] += dp[i][j][k];
    }
    int ans = 0;
    repq(i,1,N) ans += dp[N][i][A*i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 49152
/**
*    created: 23.05.2020 01:27:20
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

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

    string s;
    cin >> s;
    int cnt0 = 0;
    int cnt1 = 0;
    rep(i,s.size()) {
        if (s[i] == '0') cnt0++;
        else cnt1++;
    }
    cout << 2 * min(cnt1, cnt0) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  string S;
  cin >> S;
  ll ans = 0;
  for (ll i = 0; i < 4; ++i) {
    if (S[i] == '+') {
      ans += 1;
    }
    else {
      ans -= 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long
#define ll getchar();getchar();return 0;
using namespace std;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n%i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	int ans;
	for (int i = (min(x, y)); i >= 1; i--) {
		if (x%i == 0 && y%i == 0) {
			ans = i;
			break;
		}
	}
	return ans;
}
int yakusuunowa(int n) {
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (n%i == 0)ans += i;
	}
	return ans;
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int ketanowa(int n) {
	int cnt = 0, sum = 0;
	for (int i = 10; i <= n * 10; i *= 10) {
		if (i == 10)cnt += n % i;
		else sum += (n%i - n % (i / 10)) / (i / 10);
	}
	return cnt + sum;
}
signed main() {
	int a, b;
	cin >> a >> b;
	if (a == b)puts("Draw");
	else if (a == 1)puts("Alice");
	else if (b == 1)puts("Bob");
	else if (a < b)puts("Bob");
	else puts("Alice");
	ll
}

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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;
int main(){

Vec vec(9);
for(int i=0;i<9;i++){
    cin>>vec[i];
}
int n,x;
cin>>n;
for(int i=0;i<n;i++){
    cin>>x;
    for(int j=0;j<9;j++){
        if(vec[j]==x){
            vec[j]=0;
        }
    } 
}
bool xz=false;
if(vec[0]==0&&vec[4]==0&&vec[8]==0){
   xz=true;
}
if(vec[2]==0&&vec[4]==0&&vec[6]==0){
   xz=true;
}
for(int i=0;i<7;i+=3){
    if(vec[i]==0&&vec[i+1]==0&&vec[i+2]==0){
   xz=true;
    }
}
for(int i=0;i<3;i++){
    if(vec[i]==0&&vec[i+3]==0&&vec[i+6]==0){
   xz=true;
    }
}
if(xz){
    cout<<"Yes"<<endl;
}
else
cout<<"No"<<endl;


}


Measured memory_bytes: 3564
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
 	int N;
 	cin >> N;
 	int T[N], A[N];
 	for(int i=0;i<N;i++){
 		cin >> T[i] >> A[i];
 	}
 	ll ansT = T[0];
 	ll ansA = A[0];

 	for(int i=1;i<N;i++){
 		ll tmp = max((ansT+T[i]-1)/T[i], (ansA+A[i]-1)/A[i]);
 		ansT = tmp*T[i];
 		ansA = tmp*A[i];
 	}
 	cout << ansT + ansA <<endl;

  	return 0;
}

Measured memory_bytes: 256
/**
*	  Name: Ajay
*	  Institute: IIITH 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define ll long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vii vector<ppi>
#define vll vector<ll>
#define mp make_pair
#define fi first
#define se second
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void input()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

int main()
{      
  fastio();
  int n,m,i,j,t;
  cin>>n>>m;
  double a[n],total=0;
  for(i=0;i<n;i++) cin>>a[i],total+=a[i];
  sort(a,a+n);
  total=(total/(4.0*m));
  //cout<<total<<endl;
  if(a[n-m]>=total){
  	cout<<"Yes";
  }
  else{
  	cout<<"No";
  }
  return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long A, long long B, long long H, long long M){
    double tmp = 12 * 60;
    double a_r = ((H * 60 + M) / tmp) * 360.0;
    double b_r = M / 60.0 * 360.0;


    if(a_r < 90) {
        a_r = 90.0 - a_r;
    } else if (90 <= a_r && a_r < 180) {
        a_r = 360 - (a_r - 90);
    } else if (180 <= a_r && a_r < 270) {
        a_r = 180 + (270 - a_r);
    } else {
        a_r = 450 - a_r;
    }

    if(b_r < 90) {
        b_r = 90.0 - b_r;
    } else if (90 <= b_r && b_r < 180) {
        b_r = 360 - (b_r - 90);
    } else if (180 <= b_r && b_r < 270) {
        b_r = 180 + (270 - b_r);
    } else {
        b_r = 450 - b_r;
    }


    double ax = cos(a_r * M_PI / 180) * A;
    double ay = sin(a_r * M_PI / 180) * A;
    double bx = cos(b_r * M_PI / 180) * B;
    double by = sin(b_r * M_PI / 180) * B;

    printf("%.12f\n", sqrt((bx-ax)*(bx-ax) + (by-ay)*(by-ay)));
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long H;
    scanf("%lld",&H);
    long long M;
    scanf("%lld",&M);
    solve(A, B, H, M);
    return 0;
}


Measured memory_bytes: 4148
n = int(input())
a = [int(i) for i in input().split()]

a1 = a[::2]
a2 = a[1::2]

from collections import defaultdict

d1 = defaultdict(int)
d1[0] = 0
for ai in a1:
	d1[ai] += 1  

d2 = defaultdict(int)
d2[0] = 0
for ai in a2:
	d2[ai] += 1  

an1 = list(d1.items())
an1.sort(key = lambda x: -x[1])

an2 = list(d2.items())
an2.sort(key = lambda x: -x[1])

if an1[0][0] == an2[0][0]:
	print(n - max(an1[0][1] + an2[1][1], an1[1][1] + an2[0][1]))
else:
	print(n - an1[0][1] - an2[0][1])


Measured memory_bytes: 66028
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define MOD 1000000007
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int n, ans, aux, sol, num;

int main(){
    ios::sync_with_stdio(0);
    cin >> n;
    sol = 0;
    num = 1;
    forr(i,1,n+1){
        aux = i;
        ans = 0;
        while(aux%2==0){
            ans++;
            aux/=2;
        }
        if(ans > sol){
            num = i;
            sol = ans;
        }
    }
    cout << num << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = in.nextInt();
		}
		int num = 0;
		boolean hasNum = false;
		for (int i = 0; i < a.length; i++) {
			if (num + 1 == a[i]) {
				num++;
				hasNum = true;
			}
		}
		if (hasNum) {
			System.out.println(N - num);
		} else {
			System.out.println(-1);
		}
		in.close();
	}
}

Measured memory_bytes: 86248
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int N,K,S; cin >> N >> K >> S;
    if (S < 1e+9){
        rep(i,K) cout << S << " ";
        rep(i,N-K) cout << S+1 << " ";
    }
    else {
        rep(i,K) cout << S << " ";
        rep(i,N-K) cout << 1 << " ";
    }
  

}


Measured memory_bytes: 1280
S = input()

cnt = 0
ml = 0

for i in range (len(S)):
  cnt = 0
  for j in range(i+1, len(S)+1):
    cnt = S[i:j].count("A") + S[i:j].count("T") + S[i:j].count("G") + S[i:j].count("C") 
    
    if cnt == len(S[i:j]) and cnt > ml:
      ml = cnt
  
print(ml)
  
  

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

LL n;

int main()
{
	scanf("%lld", &n);
	LL ans = 1;
	for(int i = 1; i <= 1e5; i++) {
		if((LL)i * (LL)i > n) break;
		else ans = (LL)i * (LL)i;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define ll long long

using namespace std;

int main() {
  ll A, B, K;
  cin >> A >> B >> K;
  if (A >= K) {
    A = A - K;
    cout << A << " " << B << endl;
  } else {
    B = B - (K - A);
    if (B <= 0) {
      B = 0;
    }
    cout << 0 << " " << B << endl;
  }
}

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

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

typedef long long int64;

int main() {
  string s;
  cin >> s;
  sort(s.begin(), s.end());

  if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

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

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;

int main(){
  char str[50];
  int h, w, res[50][50];
  scanf("%d%d", &h, &w);
  rep(i, h){
    scanf("%s", str);
    rep(j, w) res[i][j] = str[j] - '0';
  }
  for(int i = 1; i < w; ++i) res[0][i] += res[0][i-1];
  for(int i = 1; i < h; ++i) res[i][0] += res[i-1][0];
  for(int i = 1; i < h; ++i) for(int j = 1; j < w; ++j)
      res[i][j] += min(res[i-1][j], res[i][j-1]);
  /*  rep(i, h){
   rep(j, w) printf("%d", res[i][j]);
    puts("");
    }*/
  printf("%d\n", res[h-1][w-1]);
  return 0;
}

Measured memory_bytes: 1200
# N A,B,Cの文字数
# 制約：A,B,Cは英小文字
# いずれかの文字列を1文字抽出して別の文字列を変換する

# リスト化
N = int(input())
A = list(input())
B = list(input())
C = list(input())

count = 0
for i in range(N):
    if A[i] == B[i] and A[i] == C[i]:
        continue
    elif A[i] == C[i]:
        count += 1
    elif B[i] == C[i]:
        count += 1
    elif A[i] == B[i]:
        count += 1
    else:
        count += 2
print(count)

Measured memory_bytes: 3064
N, K = map(int, input().split())
answer = 0
MOD = 10**9+7
for i in range(K, N+2):
  lower = i*(i-1)//2
  upper = (N*(N+1)-(N-i)*(N-i+1))//2
  answer += (upper-lower+1)%MOD
print(answer%MOD)

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

namespace ABC136C
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = CIN.Long();
            long[] H = CIN.LongArray();

            int down = 0;
            long before = H[0];
            for (int i = 1; i < N; i++)
            {
                if (before - H[i] > 1)
                {
                    Console.WriteLine("No");
                    return;
                }

                if (before - H[i] == 1)
                {
                    down++;

                    if (down > 1)
                    {
                        Console.WriteLine("No");
                        return;
                    }

                    before = H[i];
                    continue;
                }

                if (before - H[i] == 0)
                {
                    before = H[i];
                    continue;
                }

                down = 0;
                before = H[i];
            }
            Console.WriteLine("Yes");
        }
    }

    internal static class CIN
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

Measured memory_bytes: 29404
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
signed main()
{
	fastio();   
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	int t=1;
	//cin>>t;
	while(t--)
	{
		ll H1,M1,H2,M2,K;
		cin>>H1>>M1>>H2>>M2>>K;
		if(M1>M2)
		{
			ll ans=H2-H1-1;
			ans*=60;
			ans+=(60-(M1-M2));
			cout<<ans-K<<endl;
		}
		else
		{
			ll ans=H2-H1;
			ans*=60;
			ans+=(M2-M1);
			cout<<ans-K<<endl;
		}
	}
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
class UnionFind {
private:
	unsigned size_; std::vector<unsigned> par, rank;
public:
	UnionFind() : size_(0), par(std::vector<unsigned>()), rank(std::vector<unsigned>()) {};
	UnionFind(unsigned size__) : size_(size__) {
		par.resize(size_); rank.resize(size_);
		for (unsigned i = 0; i < size_; i++) par[i] = i, rank[i] = 0;
	}
	unsigned size() { return size_; }
	unsigned root(unsigned x) { return par[x] == x ? x : par[x] = root(par[x]); }
	bool same(unsigned x, unsigned y) { return root(x) == root(y); }
	void unite(unsigned x, unsigned y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++;
		else par[y] = x;
	}
	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};
int n, m; tuple<int, int, int>x[1000000];
int main() {
	while (true) {
		cin >> n >> m; if (n == 0 && m == 0)break;
		for (int i = 0; i < m; i++) {
			int s, t, u; cin >> s >> t >> u; x[i] = make_tuple(u, s, t);
		}
		UnionFind UF(n + 1); int T = 1; if (n % 2 == 1)T = 2;
		sort(x, x + m); int cnt = 0, cnt2 = 0;
		for (int i = 0; i < m; i++) {
			if (UF.same(get<1>(x[i]), get<2>(x[i])) == false) {
				UF.unite(get<1>(x[i]), get<2>(x[i]));
				if (T == 1 && cnt2 == (n - 1) / 2) { cnt += get<0>(x[i]); }
				if (T == 2 && (cnt2 == (n - 1) / 2 || cnt2 == (n - 2) / 2)) { cnt += get<0>(x[i]); }
				cnt2++;
			}
		}
		cout << cnt / T << endl;
	}
	return 0;
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    string s;
    cin >> s;
    while(true){
	if(s == "0") break;
	int a,b;
	a = 0;
	b = 0;
	for(int i=1;i<s.size();i++){
	    if(s[i] == 'A'){
		a++;
	    }else if(s[i] == 'B'){
		b++;
	    }
	}
	cin >> s;
	if(a >= 10 && b >= 10){
	    if(a > b){
		a++;
	    }else{
		b++;
	    }
	}else{
	    if(a > b) a = 11;
	    else b = 11;
	}
	printf("%d %d\n",a,b);
    }
    return 0;
}

Measured memory_bytes: 1184
# -*- coding: utf-8 -*-

n, x = map(int, input().split())

l = list(map(int, input().split()))
a = []
for i in range(n+1):
    if i == 0:
        a.append(0)
        continue
    a.append(a[i-1]+l[i-1])

ans = 0
for i in a:
    if i <= x:
        ans += 1
print(ans)



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

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

	int	n;
	int	k;
	int	q;
	cin >> n >> k >> q;
	vector<int>	A(n);

	rep(i, q)
	{
		int	a;

		cin >> a;
		A.at(a - 1)++;
	}
	int	pass;

	pass = q - k;
	rep(i, n)
	{
		if (A.at(i) > pass)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
	static final long MOD = 1000000007;
	
	static class Pair {
		int a, b;

		public Pair(int a, int b) {
			this.a = a;
			this.b = b;
		}
		
	}
	
	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();
		
		HashMap<Integer, ArrayList<Pair>> map = new HashMap<>();
		
		for(int i=0; i<N; i++) {
			for(int j=2; j*j<=A[i]; j++) {
				if(A[i]%j==0) {
					int cnt = 0;
					while(A[i]%j==0) {
						cnt++;
						A[i]/=j;
					}
					ArrayList<Pair> list = map.get(j);
					if(list==null)
						list = new ArrayList<>();
					list.add(new Pair(i,cnt));
					map.put(j, list);
				}
			}
			if(A[i]>1) {
				ArrayList<Pair> list = map.get(A[i]);
				if(list==null)
					list = new ArrayList<>();
				list.add(new Pair(i, 1));
				map.put(A[i], list);
			}
		}
		
		long total = 1;
		long[] div = new long[N];
		Arrays.fill(div, 1);
		
		Iterator<Integer> it = map.keySet().iterator();
		while(it.hasNext()) {
			int i = it.next();
			ArrayList<Pair> list = map.get(i);
			int max = 0;
			for(Pair p : list) {
				max = Math.max(max, p.b);
			}
			
			for(Pair p : list)
				for(int j=0; j<p.b; j++)
					div[p.a] = divide(div[p.a], i);
			for(int j=0; j<max; j++)
				total = multi(total, i);
		}
		
		for(int i=0; i<N; i++)
			div[i] = multi(div[i], total);
		
		long ans = 0;
		for(int i=0; i<N; i++)
			ans = (ans + div[i]) % MOD;
		
		System.out.println(ans);
		sc.close();
	}
	
	static long multi(long a, long b) {
		return (a*b)%MOD;
	}
	
	static long divide(long a, long b) {
		return (a*rev(b)) %MOD;
	}

	static long rev(long a) {
		return pow(a, MOD-2);
	}
	
	static long pow(long a, long b) {
		long ans = 1;
		while(b>0) {
			if((b&1)!=0)
				ans = (ans * a)%MOD;
			a = (a * a)%MOD;
			b>>=1;
		}
		
		return ans;
	}

}



Measured memory_bytes: 36788
#include <bits/stdc++.h>
#include<chrono>
using namespace std;
#define ff first
#define pb push_back
#define ss second
#define ll long long
#define MAX 5000
#define mpi map<int, int>
#define mpll map<ll, ll>
#define pll pair<ll, ll>
#define plld pair<ll, double>
#define SKILLER ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define vi std::vector<int>
#define vll std::vector<ll>
#define vs std::vector<string>
#define vvi std::vector<std::vector<int>>
#define vvll std::vector<std::vector<ll>>
#define all(v) v.begin(), v.end()
#define loop(i, a, b) for(int i = a; i < b; i++)
const int Maxn = 1e5+1, Mod = 1e9 + 7;
int main(){
    SKILLER;
    
         ll n; cin >> n;
         std::vector<ll> v(n+1, 0);
         for(int i = 1; i < n; i++){
         	ll x; cin >> x;
         	v[x]++;
         }
         for (int i = 1; i <= n; ++i)
         {
         	cout << v[i] <<"\n";
         }
    return 0;
}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, T;
  int c, t;
  int ans = INT_MAX;
  cin >> N >> T;
  for(int i = 0; i < N; i++){
    cin >> c >> t;
    if(T >= t){
      if(ans > c){
        ans = c;
      }
    }
  }
  if(ans == INT_MAX){
    cout << "TLE" << endl;
  }else{
    cout << ans << endl;
  }
}

Measured memory_bytes: 384
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
string s;
ll a,t;
string f(){
	string w="";
	while(t<s.size()){
		if(a<w.size())return w;
		if(isalpha(s[t])){
			w+=s[t];
			t++;
		}else if(s[t]==')'){
			return w;
		}else{
			int co=0;
			while(isdigit(s[t])){
				co*=10;
				co+=s[t]-'0';
				t++;
			}
			string tmp;
			if(isalpha(s[t])){
				tmp=s[t];
			}else{
				t++;
				tmp=f();
			}
//			cout<<co<<" "<<tmp.size()<<endl;
//			cout<<w<<endl;
			while(co--){
				w+=tmp;
				if(a<w.size())return w;
			}
			t++;
		}
	}
	return w;
}
int main(){
	while(cin>>s>>a,s!="0"){
		t=0;
		string out=f();
		if(a<out.size())cout<<out[a]<<endl;
		else cout<<"0"<<endl;
	}
}








Measured memory_bytes: 8584
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;

const int maxm = 1e6+5;
int dp[maxm][2];

void run_case() {
    string str;
    cin >> str;
    dp[str.size()-1][1] = str[str.size()-1]-'0';
    dp[str.size()-1][0] = 10 - str[str.size()-1] +'0';
    for(int i = str.size()-2; i >= 0; --i) {
        int num = str[i]-'0';
        dp[i][1] = min(dp[i+1][0]+1, dp[i+1][1]) + num;
        dp[i][0] = 10 - num + min(dp[i+1][0]-1, dp[i+1][1]);
    }
    cout << min(dp[0][0]+1, dp[0][1]);
    
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    //cout.setf(ios_base::showpoint);cout.precision(8);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
const int maxn=200010;
int n,a[maxn];
vector<int> v;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		v.push_back(a[i]);
	}
	sort(v.begin(),v.end());
	int tmp=v[v.size()-1];
	for(int i=0;i<n;i++)
	{
		if(a[i]!=tmp)
			cout<<tmp<<endl;
		else
			cout<<v[v.size()-2]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <complex>

using namespace std;

int main() {
	int n;
  long long num;
  int ans = 0;
	
	cin >> n; 

  for (int i = 1; i <= n; i++) {
    cin >> num;
    if (num % 2 == 0) {
      while (num % 2 == 0) {
        num /= 2;
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#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 unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

const int N = 1000010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

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

struct Info {
    int node, cost;
    Info(){}
    Info(int _node, int _cost){
        node = _node; cost = _cost;
    }
    bool operator < (const Info &other) const {
        return cost > other.cost;
    }
};

priority_queue < Info > pq;

int dp[N];

int main(){
    int n; fastScan(n);
    for(int i = 0; i < N; i++){
        dp[i] = INF;
    }
    for(int i = 1; i < 10; i++){
        if(dp[i % n] > i){
            dp[i % n] = i;
            pq.push(Info(i % n, i));
        }
    }
    while(!pq.empty()){
        int node = pq.top().node;
        int cost = pq.top().cost;
        pq.pop();
        for(int i = 0; i <= 10; i++){
            int next = (node * 10 + i) % n;
            int ncost = cost + i;
            if(dp[next] > ncost){
                dp[next] = ncost;
                pq.push(Info(next, ncost));
            }
        }
    }
    printf("%d\n", dp[0]);
}


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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    ll a, b;
    cin >> a >> b;
    vector<ll> v = {a + b, a - b, a * b};
    cout << *std::max_element(ALL(v)) << endl;
    return 0;
}


Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int A, B;  cin >> A >> B;

    int ans = B;
    if (6 <= A && A <= 12) ans /= 2;
    else if (A <= 5) ans = 0;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

	N, K, Q := scanInt(), scanInt(), scanInt()
	score := make([]int, N)
	for i := 0; i < Q; i++ {
		A := scanInt()
		score[A-1]++
	}

	for _, s := range score {
		if K-Q+s > 0 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


Measured memory_bytes: 3968
def main():
    from itertools import accumulate
    n, *ab = map(int, open(0).read().split())
    c = list(zip(*[iter(ab)] * 2))
    c.sort(key=lambda x: (x[1], x[0]))
    d, f = zip(*c)
    for i, j in zip(accumulate(d), f):
        if i > j:
            print('No')
            break
    else:
        print('Yes')


if __name__ == '__main__':
    main()


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

int A[404];
long long dp[404][404], S[404][404];

long long solve(int left, int right)
{
    if(left == right)
        return 0;
    
    if(dp[left][right] != -1)
        return dp[left][right];
    
    long long ans = (long long) 1e18;
    
    for(int i = left+1; i <= right; i++)
        ans = min(ans, solve(left, i-1) + solve(i, right) + S[left][i-1] + S[i][right]);
    
    return dp[left][right] = ans;
}

int main() {

    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    
    int N;
    cin >> N;
    
    for(int i=1; i<=N; i++)
        cin >> A[i];
    
    for(int i=1; i<=N; i++)
        for(int j=i; j<=N; j++)
            S[i][j] = S[i][j-1] + A[j];
    
    memset(dp, -1, sizeof(dp));
    
    cout << solve(1, N) << "\n";
    return 0;
}

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

int main(){
  
 int k,i=0;
string a;
  cin>>k;
  cin>>a;
  if(k>=a.length()){
    cout<<a;
  }
  else{
  	for(int j=0;j<k;j++){
      cout<<a[j];
    }
    cout<<"...";
  
  }
    
  return 0;
}


Measured memory_bytes: 3592
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int L = sc.nextInt();
		int R = sc.nextInt();
		int d = sc.nextInt();
		
		int c = 0;
		for (int i = L; i <= R; ++i) {
			if (i % d == 0) c++;
		}
		
		System.out.println(c);
	}
}


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

using namespace std;
typedef __int128 var;

const int N = 112;
const int MOD = 998244353;

int _ad(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }

int _mu(int a, int b) { return (1ll * a * b) % MOD; }

char s[N];
int n, pw2[N];
map<var, bool> mark;
map<var, int> dp;

int solve(var K);
var getS(var S, int l, int r);

int main() {
  scanf("%s", s);
  n = strlen(s);
  pw2[0] = 1;
  for (int i = 1; i <= n; ++i) 
    pw2[i] = _ad(pw2[i - 1], pw2[i - 1]);
  var S = 0;
  for (int i = n - 1; i >= 0; --i)
    (S <<= 1) |= (s[i] - '0');
  S |= (var) n << n;
  printf("%d\n", solve(S));
  return 0;
}

int solve(var K) {
  if (mark[K]) return dp[K];
  mark[K] = true;
  int res = 0, k = K >> n;
  if (!k) {
    dp[K] = 1;
    return 1;
  }
  var S = getS(K, 0, n - 1);
  for (int i = 0; i < k; ++i)
    if ((S >> i) & 1) ++res;
  res = pw2[res];
  int cnt = 0;
  for (int i = 0; i < k; ++i) {
    for (int j = i; j < k; ++j) {
      int len = (j - i + 1);
      if (j + len > k - 1) break;
      var v = getS(S, i, j);
      for (int t = i + len; t + len - 1 < k; t += len) {
        var fS = getS(S, t, t + len - 1),
            bS = getS(S, t + len, k - 1);
        v &= fS;
        res = _ad(res, _mu(pw2[cnt], _mu(
                solve(v | (var) len << n),
                solve(bS | (var) (k - (t + len)) << n)
              )));
      }
    }
    if ((S >> i) & 1) cnt++;
  }
  dp[K] = res;
  return res;
}

var getS(var S, int l, int r) {
  return S >> l & (((var) 1 << (r - l + 1)) - 1);
}


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

void pour(int pos, int l, int r, double& a, vector<double> const& x, vector<double> const& h, vector<double>& ans) {
    if(r - l > 1) {
        int mid = l + 1;
        for(int i = l + 1; i < r; ++i) {
            if(h[mid] < h[i]) {
                mid = i;
            }
        }
        if(pos < mid) {
            pour(pos, l, mid, a, x, h, ans);
            pour(pos, mid, r, a, x, h, ans);
        } else {
            pour(pos, mid, r, a, x, h, ans);
            pour(pos, l, mid, a, x, h, ans);
        }
    }

    double side_h = min(h[l], h[r]);
    double add = max(0.0, (side_h - ans[l]) * (x[r] - x[l]));
    add = min(add, a);
    a -= add;
    for(int i = l; i < r; ++i) {
        ans[i] += add / (x[r] - x[l]);
    }
}

int main() {
    int D; cin >> D;
    while(D--) {
        int N; cin >> N;
        vector<double> x(N + 2), h(N + 2);
        for(int i = 1; i <= N; ++i) {
            cin >> x[i] >> h[i];
        }
        x[N + 1] = 100;
        h[0] = h[N + 1] = 50;
        int M; cin >> M;
        vector<double> in(N + 1);
        for(int i = 0; i < M; ++i) {
            int F, A; cin >> F >> A;
            int j = upper_bound(begin(x), end(x), F) - begin(x) - 1;
            in[j] += A / 30.0;
        }

        int L; cin >> L;
        while(L--) {
            int P, T; cin >> P >> T;
            vector<double> ans(N + 1);
            for(int i = 0; i < N + 1; ++i) {
                double a = in[i] * T;
                pour(i, 0, N + 1, a, x, h, ans);
            }
            int j = upper_bound(begin(x), end(x), P) - begin(x) - 1;
            cout << fixed << setprecision(6) << ans[j] << endl;
        }
    }
}



Measured memory_bytes: 3176
#include<stdio.h>
int main ()
{


    int a,b,c,x,y,z;
    scanf("%d%d%d",&a,&b,&c);

    x= a+b;
    y = a+c;
    z= b+c;

    if (x<=y && x<= z)
    {
        printf("%d",x);
    }

     else if (y<=x && y<= z)
    {
        printf("%d",y);
    }
  else  if (z<=y && z<= x)
    {
        printf("%d",z);
    }

}


Measured memory_bytes: 128
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


# def bubble_sort(a):
#     count = 0
#     for i in range(len(a)):
#         for j in range(len(a) - 1, i, -1):
#             if a[j] < a[j - 1]:
#                 a[j - 1], a[j] = a[j], a[j - 1]
#                 count = count + 1
#     return count


def main():
    n = int(input())
    a = list(map(int, input().split()))

    sorted_a = sorted(a)
    map_a = {}
    for i in range(n):
        map_a[sorted_a[i]] = i
    flat_a = list(map(lambda x: map_a[x], a))
    # print(map_a)
    # print(flat_a)

    bit = BIT(n)
    count = 0
    for i in range(n):
        bit.add(flat_a[i] + 1, 1)
        count = count + i + 1 - bit.sum(flat_a[i] + 1)
    print(count)


if __name__ == '__main__':
    main()

# 3 5 2 1 4
# 2 4 1 0 3
#     1|
#     1   1|
#   1|1   1
# 1|1 1   1
# 1 1 1 1|1



Measured memory_bytes: 41852
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int M = 100005, N = 50004;

int n, m, tt;
pair<int, int> a[M];
char ans[M];

bitset<N> s[N];

void solv1()
{
    for (int i = 1; i <= n; ++i)
        s[i][i] = 1;
    for (int i = m - 1; i >= 0; --i)
    {
        int x = a[i].first;
        int y = a[i].second;
        s[x] |= s[y];
        s[y] |= s[x];
    }
    bitset<N> t;
    for (int i = 1; i <= n; ++i)
        t[i] = 1;
    for (int i = 1; i <= n; ++i)
        t &= s[i];
    int u = -1;
    for (int i = 1; i <= n; ++i)
    {
        if (t[i] == 1)
        {
            u = i;
            break;
        }
    }
    if (u == -1)
    {
        printf("-1\n");
        return;
    }
    for (int i = 1; i <= n; ++i)
        t[i] = 0;
    t[u] = 1;
    for (int i = m - 1; i >= 0; --i)
    {
        int x = a[i].first;
        int y = a[i].second;
        if (t[x] == 1 && t[y] == 0)
        {
            ans[i] = '^';
            t[y] = 1;
        }
        else if (t[x] == 0 && t[y] == 1)
        {
            ans[i] = 'v';
            t[x] = 1;
        }
        else
            ans[i] = '^';
    }
    printf("%s\n", ans);
}

int u[M];
int q[M];

void solv2()
{
	for (int i = 1; i <= n; ++i)
	{
		u[i] = i;
		q[i] = 1;
	}
	for (int i = m - 1; i >= 0; --i)
	{
		if (u[a[i].first] == u[a[i].second])
		{
			ans[i] = '^';
			continue;
		}
		if (q[u[a[i].first]] == n - 1)
		{
			if (q[u[a[i].second]] == n - 1)
			{
				printf("-1\n");
				return;
			}
			ans[i] = 'v';
			--q[u[a[i].first]];
			++q[u[a[i].second]];
			u[a[i].first] = u[a[i].second];
		}
		else
		{
			ans[i] = '^';
			--q[u[a[i].second]];
			++q[u[a[i].first]];
			u[a[i].second] = u[a[i].first];
		}
	}
	printf("%s\n", ans);
}

int main()
{
	scanf("%d%d%d", &n, &m, &tt);
	for (int i = 0; i < m; ++i)
	{
		scanf("%d%d", &a[i].first, &a[i].second);
	}
	if (tt == 1)
        solv1();
	else
        solv2();
	return 0;
}


Measured memory_bytes: 306688
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	sum := 0
	min := 999
	for i := 0; i < n; i++ {
		var s int
		fmt.Scan(&s)
		sum += s
		if s%10 != 0 && s < min {
			min = s
		}
	}

	if min == 999 {
		min = 0
	}

	ans := sum
	if ans%10 == 0 {
		ans -= min
	}

	if ans%10 == 0 {
		ans = 0
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<stdio.h>
int main(void){
int x, y, W, H, r;
    scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
    if(x-r >= 0&&y-r >= 0&&x+r <= W&&y+r <= H)
        printf("Yes\n");
    else    printf("No\n");
return 0;
}

Measured memory_bytes: 1816
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( iter = $ iter : ident , $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut $ iter = s . split_whitespace ( ) ; input_inner ! { $ iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , mut $ var : usize $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , $ var : usize $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , { chars : $ base : expr } ) => { read_value ! ( $ iter , String ) . chars ( ) . map ( | c | ( c as u8 - $ base as u8 ) as usize ) . collect ::< Vec < usize >> ( ) } ; ( $ iter : expr , { char : $ base : expr } ) => { read_value ! ( $ iter , { chars : $ base } ) [ 0 ] } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , char ) => { read_value ! ( $ iter , chars ) [ 0 ] } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
use std::cmp::min;
fn main() {
    input! { n, m, x: [usize; n] };
    let xmax = *x.iter().max().unwrap();
    let mut rem = vec![0; m];
    let mut cnt = vec![0; xmax + 1];
    let mut sm = vec![0; m];
    for &xi in x.iter() {
        rem[xi % m] += 1;
        cnt[xi] += 1;
    }
    for i in 1..xmax + 1 {
        sm[i % m] += cnt[i] / 2;
    }
    let mut ans = 0;
    for i in 0..m / 2 + 1 {
        let j = (m - i) % m;
        if i == j {
            ans += rem[i] / 2;
        } else if rem[i] < rem[j] {
            ans += rem[i] + min(sm[j] * 2, rem[j] - rem[i]) / 2;
        } else {
            ans += rem[j] + min(sm[i] * 2, rem[i] - rem[j]) / 2;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    string S,W;
    cin >>S>>W;
    int ans=0;
    REP(i,3){
        if(S[i]==W[i]){
            ans++;
        }
    }
    cout <<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
  string s;
  int k;
  vector<string> V;

  cin >> s;
  cin >> k;

  for ( int a = 1; a <= k; ++a ) {
    for ( int i = 0; i+a <= s.size(); ++i ) {
      string tmp = "";
      for ( int j = i; j < i+a; ++j ) tmp += s[j];
      V.push_back(tmp);
    }
  }

  sort(V.begin(), V.end());
  unique(V.begin(), V.end());

  cout << V[k-1] << endl;

}


Measured memory_bytes: 1160
from collections import Counter


S = input()
T = input()
ans = -1
countS = Counter(S)
countT = Counter(T)
for i in range(len(S)):
    s = countS[S[i]]
    t = countT[T[i]]
    if s != t:
        ans = 1
        break
    else:
        ans = 0
print('YNeos'[ans::2])

Measured memory_bytes: 4144
import sys
input = sys.stdin.readline

def main():
	N,Q = map(int,input().split())
	A = list(map(int,input().split()))
	X = [list(map(int,input().split())) for _ in range(Q)]
	A.sort()
	X.sort(key=lambda x:-x[1])
	ans = sum(A)
	left = 0
	right = 0
	for i in range(Q):
		if right > N:
			break
		else:
			right = left + X[i][0]
			for j in range(left,min(right,N)):
				if A[j] < X[i][1]:
					ans = ans-A[j]+X[i][1]
		left = right
	print(ans)

if __name__ == "__main__":
	main()

Measured memory_bytes: 36088