akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int t=0;
  int p=0;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='g'){
      if(p>0){
	t++;
	p--;
      }
      else p++;
    }
    else{
      if(p>0){
	p--;
      }
      else{
	t--;
	p++;
      }
    }
  }
  cout<<t<<endl;
  return(0);
}
  


Measured memory_bytes: 512
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main{

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

	class Position{
		int x, y;
		Position(int _x, int _y){
			this.x = _x;
			this.y = _y;
		}
		
		public boolean equals(Object a){
			return a instanceof Position && ((Position)a).x == this.x && ((Position)a).y == this.y;
		}
		
		public int hashCode(){
			return java.util.Arrays.hashCode(new int[]{this.x, this.y});
		}
	}

	class State{
		int x, y, dist;
		State(int _x, int _y, int _d){
			this.x = _x;
			this.y = _y;
			this.dist = _d;
		}
	}

	void run(){
		Scanner in = new Scanner(System.in);
		for(;;){
			int t = in.nextInt(), n = in.nextInt();
			if(n==0 && t==0) return ;
			Set<Position> blocks = new HashSet<Position>();
			for(int i=0; i<n; i++){
				blocks.add(new Position(in.nextInt(), in.nextInt()));
			}
			Position start = new Position(in.nextInt(), in.nextInt());
			System.out.println(solve(blocks, t, start));
		}
	}

	int solve(Set<Position> blocks, int t, Position start){
		Set<Position> visited = new HashSet<Position>();
		visited.add(start);
		Queue<State> que = new LinkedList<State>();
		que.add(new State(start.x, start.y, 0));
		while(!que.isEmpty()){
			State tp = que.poll();
			Position cur = new Position(tp.x, tp.y);
			int dist = tp.dist;
			if(dist >= t){
				continue;
			}
			for(int k=0; k<6; k++){
				Position next = new Position(cur.x + dx[k], cur.y + dy[k]);
				if(!visited.contains(next) && !blocks.contains(next)){
					visited.add(next);
					que.add(new State(next.x, next.y, dist + 1));
				}
			}
		}
		return  visited.size();
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 14000
#include <stdio.h>
int main(void){
	char s[1000];
	int i = 0;
	scanf("%s",s);
	while (s[i] != '\0'){
		switch (s[i]){
		case '2':
			printf("k");
			break;
		case '3':
			printf("s");
			break;
		case '4':
			printf("t");
			break;
		case '5':
			printf("n");
			break;
		case '6':
			printf("h");
			break;
		case '7':
			printf("m");
			break;
		case '8':
			printf("y");
			break;
		case '9':
			printf("r");
			break;
		case '0':
			if (s[i + 1] != 'U') printf("w");
			break;
		}
		switch(s[i + 1]){
		case 'L':
			printf("i");
			break;
		case 'U':
			if (s[i] != '0') printf("u");
			break;
		case 'R':
			printf("e");
			break;
		case 'D':
			printf("o");
			break;
		default:
			printf("a");
			break;
		}
		if (s[i] == '0' && s[i + 1] == 'U') printf("nn");
		i+=2;
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;
 
#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
 
 
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  string str;cin >> str;
  str+='0';
  vector<ll>s;
  ll x,y ; cin >> x >> y;
 
  vector<ll> xx, yy;
 
  ll i = 0;
  ll co=0;
  while(str[i]!='0'){
    if(str[i]!='T')co++;
    else {s.pb(co); co=0;}
    i++;
  }
  if(str[i-1]!='T')s.pb(co);
  rep(i,s.size()){
    if(i%2==0) xx.pb(s[i]);
    else yy.pb(s[i]);
  }

  x -= xx[0];
  xx.erase(xx.begin()+0);
  //rep(i,xx.size()) cout << xx[i] << endl;
  xx.pb(abs(x)); yy.pb(abs(y));
  
  sort(rall(xx));
  sort(rall(yy));
 
  ll ans = 0;
  rep(i,xx.size()){
    if(ans >= 0) ans -= xx[i];
    else ans+=xx[i];
  }
  if(ans !=0) {cout << "No" << endl; return 0;}
  
  rep(i,yy.size()){
    if(ans >=0) ans -= yy[i];
    else ans +=yy[i];
  }
 
  if(ans!=0){cout << "No" << endl; return 0;}
  cout << "Yes" << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	int C = sc.nextInt();
    	int D = sc.nextInt();
    	int total = 0;

    	if(A<=B){
    		total += A;
    	}else{
    		total+=B;
    	}
    	if(C<=D){
    		total +=C;
    	}else{
    		total +=D;
    	}



    	System.out.println(total);

}

}

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

using namespace std;

int main(){

  int i,N,m,M;
  string S,T,U;
  
  //cin>>S>>T;
  cin>>N;
  //cin>>U;
  m=N;
  //  cout<<S<<endl;
  
  for(i=0;i<3;i++){
    M=m%10;
    //cout<<m<<endl;
    if(7==M){
      cout<<"Yes"<<endl;
      return 0;
    }
    m=m/10;
  }
  cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    int cnt[26];
    int answer=0;
    for(int i=0;i<26;i++){
        cnt[i]=0;
    }
    for (int i=0;i<n;i++){
        string s;
        cin>>s;
        cnt[s[0]-'A']++;
   }
    while(1){
        sort(begin(cnt),end(cnt),greater<int>());
        if(cnt[k-1]==0) break;
        for(int i=0;i<k;i++){
            cnt[i]--;
        }
        answer++;
    }
    cout<<answer<<endl;
    return 0;
}

Measured memory_bytes: 256
/*
    OUTLAW!!
           ---SIDHU MOOSEWALA
                                */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli M=1000000007;   
lli INF=1e17;
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,q,z,y,k,m;
const double pi1=3.14159265358979323846;
//unordered_map<pair<ll,lli>,lli> mp;
lli me(lli a,lli b,lli M)
{
    if(b==0)
    return 1;
    else if(b%2==0)
    return me((a*a)%M,b/2,M);
    else
    return (a%M*me((a*a)%M,(b-1)/2,M)%M)%M;
}
lli mI(lli a,lli m)
{
    return me(a,m-2,m);
}
//lli tot=0;
vector<lli> pf(string s) {
    int n = (int)s.length();
    vector<lli> pi(n);
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
    return pi;
}
//map<ll,lli> dp;
//set<lli> s[100005];
//lli dp[3005][3005];
//ost s[500005];
bool cmp(ll a,ll b)
{
    if(a.second==b.second)
    return a.first<b.first;
    return a.second<b.second;
}
//string sdp[3005][3005];
lli vis[3000004];
lli mk[3000004];
lli keep[3000004];
int main()
{
    ios_base::sync_with_stdio(0);
    cin>>n;
    ll x[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>x[i].first>>x[i].second;
    }
    sort(x+1,x+n+1,cmp);
    lli s=0;
    for(int i=1;i<=n;i++)
    {
        s+=x[i].first;
        if(s>x[i].second)
        return cout<<"No",0;
    }
    cout<<"Yes";
    //for(int i=1;i<=n;i++)
}

Measured memory_bytes: 3456
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int h, w; cin >> h >> w;
	int ans = INF;
	int a = 0, b = 0, c = 0;
	rep(i, 2) {
		rep(j, w - 1) {
			a = (j + 1)*h;
			b = (h / 2)*(w - j - 1);
			c = ((h + 1) / 2)*(w - j - 1);
			chmin(ans, max({ a,b,c }) - min({ a,b,c }));
		}
		swap(h, w);
	}
	chmin(ans, min((w + 2) / 3 * h - (w / 3)*h, (h + 2) / 3 * w - (h / 3)*w));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

int H,W,N;
int sr,sc;
string S,T;
int cnt[2][4][200001];

int main(){
    cin>>H>>W>>N>>sr>>sc>>S>>T;
    map<char,int> m;
    m['L']=0;
    m['R']=1;
    m['U']=2;
    m['D']=3;

    repn(i,N){
        cnt[0][m[S[i-1]]][i]++;
        cnt[1][m[T[i-1]]][i]++;
    }
    rep(i,2){
        rep(j,4){
            repn(k,N){
                cnt[i][j][k]+=cnt[i][j][k-1];
            }
        }
    }

    int x=sc, y=sr;
    rep(i,N){
        if(S[i]=='L') x--;
        if(S[i]=='U') y--;
        if(x<1 || y<1){
            cout<<"NO"<<endl;
            return 0;
        }
        if(T[i]=='R') x=min(x+1,W);
        if(T[i]=='D') y=min(y+1,H);
    }
    x=sc, y=sr;
    rep(i,N){
        if(S[i]=='R') x++;
        if(S[i]=='D') y++;
        if(x>W || y>H){
            cout<<"NO"<<endl;
            return 0;
        }
        if(T[i]=='L') x=max(x-1,1);
        if(T[i]=='U') y=max(y-1,1);
    }

    cout<<"YES"<<endl;
}

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

int main()
{
    long a,b,c,k;
    cin>>a>>b>>c>>k;
    if (k<=a) cout<<k<<endl;
    else if (k>a && k<=a+b) cout<<a<<endl;
    else cout<<(a-(k-a-b))<<endl;
}

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

int main() {
    for(int T; cin >> T, T; ) {
        int N; cin >> N;
        while(N--) {
            int a, b; cin >> a >> b;
            T -= b - a;
        }
        if(T <= 0) cout << "OK" << endl;
        else cout << T << endl;
    }
}

Measured memory_bytes: 1160
#include <algorithm> 
#include <iostream> 
using namespace std; 
 
int main(){
long long int N,A,B,yan;
cin>>N>>A>>B;
if(A>B){
cout<<0<<endl;
return 0;
}
if(N==1){
if(A==B){
cout<<1<<endl;
return 0;
}else{
cout<<0<<endl;
return 0;
}
}
yan=(N-2)*B-(N-2)*A+1;
cout<<yan<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
int main(){
    ll a;
    long double b;
    ll c;
    ll d;
    ll tmp;
    cin>>a>>b;
    tmp=b*1000;
    //cout<<tmp<<endl;
    c=tmp/1000;
    //cout<<"c : "<<c<<endl;
    d=tmp-c*1000;
    //cout<<"d : "<<d<<endl;
    
    ll x=a*c;
    ll y=a*d/1000;
    //cout<<x<<endl;
    //cout<<y<<endl;
    cout<<x+y<<endl;


    return 0;
}


Measured memory_bytes: 3728
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
//#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int A[300][300];
	bool owari = 0;
	rep(i, N) rep(j, N) A[i][j] = getint();
	rep(i, N) A[i][i] = 1e9;

	ll kotae = 0;
	rep(i, N) {
		rep(j, i) {
			auto a = A[i] + j;
			auto b = A[i];
			auto c = A[j];
			bool B = 1;
			rep(k, N) {
				if (*a == b[k] + c[k]) B = 0;
				else if (*a > b[k] + c[k]) owari = true;
			}
			if (B) kotae += *a;
		}
		if (owari) {
			printf("-1");
			return 0;
		}
	}

	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 640
a, b, k = map(int, input().split())
ans = set([])
num_a, num_b = a, b
for _ in range(k):
    if num_a <= b:
        ans.add(num_a)
        num_a += 1
    if a <= num_b:
        ans.add(num_b)
        num_b -= 1
ans = list(ans)
ans.sort()
print("\n".join(list(map(str, ans))))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
int main() {
  ios::sync_with_stdio(false);
  vector<int>a={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin>>k;
  cout<<a[k-1];
  return 0;
}

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

int main(void){
   int H,W;
   cin>>H>>W;
   vector<vector<char>> s(H,vector<char>(W));
   for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
         cin>>s[i][j];
      }
   }
   bool ans=true;
   for(int i=1;i<H-1;i++){
      for(int j=1;j<W-1;j++){
         if(s[i][j]=='#'){
            if(s[i-1][j]!='#'&&s[i+1][j]!='#'&&s[i][j-1]!='#'&&s[i][j+1]!='#'){
               ans=false;
               break;
            }
         }
      }
   }
   if(ans) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
//sort(a, a + N, greater<ll>())   // descend
//sort(a, a+N)                    //  ascend

/* 
void comb(vector<vector <ll> > &v) {
	ll mod=1000000007;
	rep (i,0,v.size()) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	rep (k,1,v.size()) {
		rep (j,1,k) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%mod;
		}
	}
}
/*main内でnCn~nC0 生成 **
vector<vector<ll> > v(n + 1, vector<ll>(n + 1, 0));
comb(v);
*/

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

	ll odd=0;
	ll even=0;
	rep(i,0,n){
		if(a[i]%2) even++;
		else odd++;;
	}
	if(even%2==1)cout<<"NO";
	else cout<<"YES";
}

Measured memory_bytes: 1532
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll n, p[21] = {}, counter = 0;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> p[i];
	for (int i = 1; i <= n - 2; i++) {
		if ((p[i] < p[i + 1] && p[i + 1] < p[i + 2]) || (p[i] > p[i + 1] && p[i + 1] > p[i + 2]))counter++;
	}
	cout << counter << endl;
	return 0;
}

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

int main() {
    long long N, Q, res = 0;
    cin >> N;
    vector<long long> A(N);
    map<long long, long long> data;
    for (long long i = 0; i < N; i++) {
        cin >> A.at(i);
        if (data.count(A.at(i))) {
            data[A.at(i)] = data.at(A.at(i)) + 1;
        }
        else {
            data[A.at(i)] = 1;
        }
        res += A.at(i);
    }
    cin >> Q;
    vector<long long> Bs(Q), Cs(Q);
    for (long long i = 0; i < Q; i++) {
        cin >> Bs.at(i) >> Cs.at(i);
    }
    for (long long i = 0; i < Q; i++) {
        long long B = Bs.at(i), C = Cs.at(i);
        if (data.count(B)) {
            res += (C - B) * data.at(B);
            if (data.count(C)) {
                data[C] = data.at(C) + data.at(B);
            }
            else {
                data[C] = data.at(B);
            }
            data[B] = 0;
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 10452
// C - Same Integers
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define all(x) (x).begin(),(x).end()

int main(){
	int A,B,C; cin>>A>>B>>C;
	vi S{A,B,C};
	int ans = 0;
	while(S[0]!=S[1] || S[1]!=S[2]){
		sort(all(S));
		if(S[1] == S[2]){//same big 2
			if(S[1]-S[0] >= 2) S[0] += 2;
			else{ S[1] += 1; S[2] += 1; }
		}
		else{//not same || same small 2
			if(S[2]-S[1] >= 2) S[0] += 2;
			else{ S[1] += 1; S[0] += 1; }
		}
		ans++;
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}
int mod = 1000000000 + 7;
int dp[101][4][4][4];
int main()
{
        //input->compute->output//

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

        cout << T / A * B << endl;

        return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

    vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1));
    irep(i, s.size()) irep(j, t.size())
    {
        if (i == 0 || j == 0) {
            dp[i][j] = 0;
        } else {
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
            }
        }
    }

    int i = s.size(), j = t.size();
    string result;
    while (i != 0 && j != 0) {
        if (dp[i][j] == dp[i - 1][j]) {
            i--;
        } else if (dp[i][j] == dp[i][j - 1]) {
            j--;
        } else {
            result.push_back(s[i - 1]);
            i--;
            j--;
        }
    }
    reverse(result.begin(), result.end());
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード

//ループ
#define rep(i, n) for(int i = 0; i < n; i++) //普通のループ
#define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ

//型名省略
typedef long long ll;
//値
static const ll MX = 100005;
static const ll MX_ll = 1e18;

using namespace std;

//#include "./lib/generic/search.h"

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

    ll t=0;
    rep(i,m) t+=b[i]; //m冊全部読んだことにする

    int j = m;
    int ans=0;
    rep(i, n+1){ //aからi冊選ぶことを示す。最初はiが0冊のときから計算
         while(j>0 && t>k){ //合計時間がkを超えていたら1冊ずつ諦めていく。break条件はtがkを超えているか、諦められる本がない状況
             --j;
             t -= b[j];
        }
        if(t > k) break; //諦められるBの本がないかつAの本だけでkを超えているならbreak
        ans = max(ans, i+j); //iはaの冊数、jはbの冊数
        if(i==n) break; //Aの本がn冊目までいったときにbreak
        t += a[i]; //次のループからは1冊読んでいる状況
    }
    cout << ans << endl;
    return 0;
}

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

using Int = long long int;
using UInt = unsigned long long int;


int main(void) {
    Int n;
    cin >> n;
    Int rt, ra;
    cin >> rt >> ra;

    Int t, a;
    for (Int i = 1; i < n; ++i) {
        cin >> t >> a;
        Int times;
        if (rt <= t && ra <= a) { 
            times = 1;
        } else if (rt <= t && ra > a) {
            times = ra / a;
            if (ra % a != 0) {
                ++times;
            }
        } else if (rt > t && ra <= a) {
            times = rt / t;
            if (rt % t != 0) {
                ++times;
            }
        } else {
            Int times_a = ra / a;
            Int times_t = rt / t;
            if (ra % a != 0) {
                ++times_a;
            }
            if (rt % t != 0) {
                ++times_t;
            }
            times = max(times_a, times_t);
        }
        rt = t * times;
        ra = a * times;
    }
    cout << rt + ra << endl;
    return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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



void func(long long N){
    
    N%=10;
    if(N==3)cout<<"bon"<<endl;
    else if(N==0 || N==1||N==6||N==8)cout<<"pon"<<endl;
    else cout<<"hon"<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    func(N);
    return 0;
}


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

int H[2], M[2], K;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  cin >> H[0] >> M[0] >> H[1] >> M[1] >> K;
  int a = H[0] * 60 + M[0];
  int b = H[1] * 60 + M[1];
  
  cout << (b - a - K) << "\n";
}

Measured memory_bytes: 3612
/*-----------------------------------------------,
|  __                                       __   |
| |  |--.-----.---.-.----.----.-----.-----.|  |_ |
| |  _  |  -__|  _  |  __|  __|  -__|  _  ||   _||
| |_____|_____|___._|____|____|_____|   __||____||
|                                   |__|         |
`-----------------------------------------------*/
#include<algorithm>
#include<array>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
typedef long long ll; typedef long double ld ;using namespace std;
#define INF 1000000000000
#define MOD 10000007
#define ALL(name) (name).begin(),(name).end()
#define REP(counter, limit) for (long long counter = 0; counter < limit; counter++)
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
struct setupios{setupios(){ios::sync_with_stdio(0);cin.tie(nullptr); /*cout<<fixed<<setprecision(20);*/};}setupios;
int main() {

  int n;
  string s;
  cin>>n>>s;
  int ans=0;
  for(int i=1;i<s.size();i++){
    //cout<<s.substr(0,i)<<" "<<s.substr(i,s.size()-i)<<endl;
    char asci='a';
    int num=0;
    for(int w=0;w<26;w++){
      if(s.substr(0,i).find(asci)!=string::npos and s.substr(i,s.size()-i).find(asci)!=string::npos){
        num++;
      }
      asci++;
    }
    ans=max(ans,num);
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
ll a,ans=0;
bool flag;
ll fact(ll m){
    map<ll,ll> X;
    while(m){
        flag=false;
        For(i,2,sqrt(m)+2){
            if(m%i==0){
                flag=true;
                m/=i;
                X[i]++;
                break;
            }
        }
        if(flag) continue;
        X[m]++;
        break;
    }
    return X[2];
}
void Main(){    
    cin>>a;
    For(i,0,a) {
        ll t;cin>>t;
        ans+=fact(t);
    }
    cout<<ans<<endl;
}
int main(){
    Main();
    return 0;
}


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

int main() {
  int n,m;
  cin >>n>>m;
  vector<int> a(m);
  
  for(int i=0;i<m;i++){
    cin >> a.at(i);
  }
  
  int ans = 0;
  for(int j=0;j<m;j++){
    ans +=a.at(j);
  }
  int g = n-ans;
  if(ans<=n){
    cout<<g<<endl;
  }else{
    cout<<-1<<endl;
  }

}

Measured memory_bytes: 3672
N = int(input())
Vs = list(map(int, input().split()))
value = 0
prop = 1

for i in range(N-2):
    MAX = max(Vs)
    prop = 0.5**(i+1)

    value += MAX * prop
    
    Vs.remove(MAX)

value += (Vs[0] + Vs[1]) * (prop/2)

print(value)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, k;
    cin >> n >> k;

    vl a(n);
    vl rui(n+1);
    rep(i, n) {
        cin >> a[i];
        rui[i+1] = rui[i] + a[i];
    }

    vl v;
    rep(L, n) {
        exrep(R, L, n-1) {
            v.pb(rui[R+1] - rui[L]);
        }
    }

    ll m = v.size();
    vl used(m);  // used[i] : v[i]を使用しないなら1
    ll ans = 0;
    for(ll d = 50; d >= 0; d--) {
        ll mask = 1LL<<d;
        ll cnt = 0;
        rep(i, m) {
            if(used[i]) {
                continue;
            }
            if(v[i] & mask) {
                cnt++;
            }
        }
        if(cnt >= k) {
            rep(i, m) {
                if(v[i] & mask) {
                    ;
                }
                else {
                    used[i] = 1;
                }
            }
            ans += mask;
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 8176
#include <bits/stdc++.h>
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define irep(i,a,n) for(int i = a;i < (int)(n);i++)
using namespace std;
typedef long long ll;
 
int main(){
    string S;
    cin >> S;
 
    int S1 = stoi(S.substr(0,2));
    int S2 = stoi(S.substr(2,2));
 
    if((S1 == 0 || S1 > 12) && S2 <= 12 && S2 > 0){
        cout << "YYMM" << endl;
    }else if((S2 == 0 || S2 > 12) && S1 <= 12 && S1 > 0){
        cout << "MMYY" << endl;
    }else if(S1 <= 12 && S1 > 0 && S2 <= 12 && S2 > 0){
        cout << "AMBIGUOUS" << endl;
    }else{
        cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int x, n;
    cin >> x >> n;
    set<int> s;
    rep(i, n) {
        int a;
        cin >> a;
        s.emplace(a);
    }
    rep(i, x+10) {
        {
            int y = x - i;
            if(s.count(y));
            else {
                cout << y << '\n';
                return 0;
            }
        }
        {
            int y = x + i;
            if(s.count(y));
            else {
                cout << y << '\n';
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3632
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    D = il()
    ret = 0
    for i in itertools.combinations(D, 2):
        ret += i[0] * i[1]
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
N=int(input())
H=[10**9]+list(map(int,input().split()))
dp=[0]*(N+1)
for i in range(N-1):
    dp[i+2]=min(dp[i]+abs(H[i]-H[i+2]),dp[i+1]+abs(H[i+1]-H[i+2]))
print(dp[-1])

Measured memory_bytes: 13976
#![allow(unused_imports)]
    #![allow(dead_code)]
    use std::io::prelude::*;
    use std::cmp::{max, min};
    use std::collections::BinaryHeap;

    const MOD: i64 = 1e9 as i64 + 7; 

    fn main(){
        let n: usize = read();
        let m: usize = read();
        let mut q = BinaryHeap::new();
        for _ in 0..n{
            let a: usize = read::<usize>();
            q.push(a);
        }
        for _ in 0..m{
            let x = q.pop().unwrap();
            q.push(x / 2);
        }
        let mut ans = 0;
        for i in q.iter(){
            ans += *i;
        }
        println!("{}", ans);
    }

    fn read<T>() -> T
    where
        T: std::str::FromStr,
    {
        let stdin = std::io::stdin();
        let token: String = stdin
            .lock()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        token.parse().ok().unwrap()
    }


Measured memory_bytes: 4352
#include <bits/stdc++.h>
int g[500][500];
using namespace std;

int main(){
  int N,M,Q;
  cin>>N>>M>>Q;
  int l,r;
  for(int i=0;i<500;i++)for(int j=0;j<500;j++)g[i][j]=0;
  for(int i=0;i<M;i++){
    cin>>l>>r;
    l--;r--;
    g[l][r]++;
  }
  for(int i=499;i>=0;i--)for(int j=1;j<500;j++)g[i][j]+=g[i][j-1];
  for(int j=0;j<500;j++)for(int i=498;i>=0;i--)g[i][j]+=g[i+1][j];
  std::vector<int> p(Q),q(Q);
  for(int i=0;i<Q;i++){
    cin>>p[i]>>q[i];
    p[i]--;q[i]--;
  }
  for(int i=0;i<Q;i++){
    cout<<g[p[i]][q[i]]<<endl;
  }
}


Measured memory_bytes: 2688
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var N int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &N)
	fmt.Println(rec(N))
}

func rec(n int) string {
	var str string

	if n == 0 {
		return "0"
	}
	if n == 1 {
		return "1"
	}

	if n%2 == 0 {
		// even
		str = rec(n/(-2)) + "0"
	} else {
		// odd
		str = rec((n-1)/(-2)) + "1"
	}

	return str
}


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

#define endl '\n'

#define int long long

typedef long long ll;
typedef long double ld;

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

const int INF = 1000000000;
const int MOD = 1000000007; // 998244353
#define MAX 10000003
#define F first
#define S second

int prime[MAX]; 
unordered_map<int, int> max_map; 

int power(int a, int n) 
{ 
   if (n == 0) 
      return 1; 
   int p = power(a, n / 2) % MOD; 
   p = (p * p) % MOD; 
   if (n & 1) 
      p = (p * a) % MOD; 
   return p; 
} 

void sieve() 
{ 
   prime[0] = prime[1] = 1; 
   for (int i = 2; i < MAX; i++) { 
      if (prime[i] == 0) { 
         for (int j = i * 2; j < MAX; j += i) { 
            if (prime[j] == 0) { 
               prime[j] = i; 
            } 
         } 
         prime[i] = i; 
      } 
   } 
}  

ll lcmModuloM(int ar[], int n) 
{ 
   for (int i = 0; i < n; i++) { 
      int num = ar[i]; 
      unordered_map<int, int> temp; 
      while (num > 1) { 
         int factor = prime[num]; 
         temp[factor]++; 
         num /= factor; 
      }

      for (auto it : temp) { 
         max_map[it.first] = max(max_map[it.first], it.second); 
      } 
   } 
   ll ans = 1;
   for (auto it : max_map) { 
      ans = (ans * power(it.F, it.S)) % MOD; 
   } 
   return ans; 
} 

int modpow(int a, int b) {
   int res = 1;
   while (b) {
      if (b & 1)
         res = ((res % MOD) * (a % MOD)) % MOD, res %= MOD;
      a = (a % MOD * a % MOD) % MOD, a %= MOD;
      b >>= 1;
   }
   return res;
}

signed main() {  
   ios::sync_with_stdio(false);
   cin.tie(nullptr);
   int n;
   cin >> n;
   int a[n];
   for (int i = 0; i < n; i++)
      cin >> a[i];
   sieve();
   int lcm = lcmModuloM(a, n);
   int res = 0;
   for (int i = 0; i < n; i++) {
      int cur = (lcm % MOD * modpow(a[i], MOD - 2) % MOD) % MOD;
      res = (res % MOD + cur % MOD) % MOD;
      res %= MOD;
   }
   cout << res % MOD << endl;
   return 0;
}

Measured memory_bytes: 78848
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include <random>
#define ll long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;

struct Edge{
    ll t,w;
    Edge(){}
    Edge(ll t,ll w) : t(t),w(w){};
};

vector<Edge> G[MAX];
ll n,d[MAX];

void bfs(ll s){
    rep(i,n) d[i]=LLINF;
    queue<ll> que;
    que.push(s);
    d[s]=0;
    ll u;
    while(!que.empty()){
        u=que.front();
        que.pop();
        rep(i,G[u].size()){
            Edge e=G[u][i];
            if(d[e.t]==LLINF){
                d[e.t]=d[u]+e.w;
                que.push(e.t);
            }
        }
    }
}

ll Diameter(){
    bfs(0);
    ll maxv=0,target=0;
    rep(i,n){
        if(d[i]==LLINF) continue;
        if(maxv<d[i]){
            maxv=d[i];
            target=i;
        }
    }
    bfs(target);
    maxv=0;
    rep(i,n){
        if(d[i]==LLINF) continue;
        maxv=max(maxv,d[i]);
    }
    return maxv;
}




int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll diameter;
    cin>>n;
    rep(i,n-1){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        G[a].push_back(Edge(b,1));
        G[b].push_back(Edge(a,1));
    }
    diameter=Diameter();
    if(diameter%3==1){
        cout<<"Second"<<endl;
    }
    else{
        cout<<"First"<<endl;
    }
    return 0;
}


Measured memory_bytes: 26988
#include <stdio.h>

int main(void) {
int a, b;
int d, r;
double f;

scanf("%d %d", &a, &b);

d = a / b;
r = a % b;
f = (double)a / b;

printf("%d %d %.6f\n", d, r, f);

return 0;
}


Measured memory_bytes: 2048
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    n = NI()
    A = LI()
    S = sorted(A)

    bit = [0] * (n+1)

    def bit_add(i,x):
        while i <= n:
            bit[i] += x
            i += i & (-i)

    def bit_sum(i):
        ret = 0
        while i > 0:
            ret += bit[i]
            i -= i & (-i)
        return ret

    ans = 0
    for i,x in enumerate(A):
        z = bisect.bisect_left(S,x) + 1
        bit_add(z,1)
        ans += z - bit_sum(z)
    print (ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 29048
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
  int n;
  vector<int> a(100);

  cin>>n;
  for(int i=0;i<n;i++)
  {
    cin>>a.at(i);
  }

  sort(a.rbegin(),a.rend());

  int alice=0,bob=0;
  for(int i=0;i<n;i++)
  {
    if(i%2==0) alice+=a.at(i);
    else bob+=a.at(i);
  }

  cout<<alice-bob<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    sort(ALL(A));
    vector<int> ex(1000001);
    int ans = N;
    REP(i, N) {
        if((i != 0 && A[i] == A[i-1]) || (i != N-1 && A[i] == A[i+1])) {
            ans--;
        } else if(ex[A[i]]) {
            ans--;
        }
        if(!ex[A[i]]) {
            for(int j=A[i]; j<1000001; j+=A[i]) {
                ex[j] = true;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 7952
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
#include<cassert>
using namespace std;
#include<atcoder/all>
using namespace atcoder;


#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

using mint = modint998244353;

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

/////////////////////////////////////
template<typename T>
struct BIT {
	ll n;
	vector<T> bt;
	ll sz;

	BIT(ll n0) {
		n = n0;
		sz = 1;
		while (sz < n) { sz *= 2; }
		bt.assign(sz + 1, 0);
	}

	ll sum(ll i) {
		T ret = 0;
		for (ll x = i; x > 0; x -= x & (-x)) {
			ret += bt[x];
		}
		return ret;
	}

	void add(ll i, ll w) {
		for (ll x = i; x <= sz; x += x & (-x)) {
			bt[x] += w;
		}
		return;
	}
};



template <typename T>
ll tento(ll N, vector<T> A) {
	vector<pair<T, ll>> p(N + 1);

	repn(i, N) p[i] = { A[i],i };
	sort(++p.begin(), p.end());

	BIT<T> bit(N);
	ll ret = 0;

	repn(i, N) {
		ll t = p[i].second;
		ret += bit.sum(t);
		bit.add(t, 1);
	}

	//ret = N * (N - 1) / 2 - ret;
	return ret;
}


mint op(mint a, mint b) { return a + b; }
mint e() { return 0; }

int main() {
	ll N, M;
	cin >> N >> M;

	dsu g(N);

	rep(i, M) {
		ll a, b;
		cin >> a >> b;
		g.merge(a - 1, b - 1);
	}

	ll ans = g.groups().size() - 1;
	cout << ans << endl;

}


Measured memory_bytes: 9104
/**
*    author:  yuya1234
*    created: 09.07.2020 13:30:56
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define ALL(v) (s).begin(), (s).end()
#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

  ll n,a,b;
  cin>>n>>a>>b;

  ll ans;
  ans=(a+b*(n-1))-(a*(n-1)+b);

  if(ans<0)cout<<0<<endl;
  else if(ans==0)cout<<1<<endl;
  else cout<<ans+1<<endl;

  return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;


public class Main{
	
	public static void main(String[] args){

		int total = 0;
		int ntotal = 0;
		int dataset = 0;
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextLine()) {
			Scanner scstr = new Scanner(sc.nextLine());
			scstr.useDelimiter(",");
			
			int each = scstr.nextInt();
			int n = scstr.nextInt();
			if(each == 0 && n == 0) break;
			dataset++;
			total += subTotal(each, n);
			ntotal += n;
			scstr.close();
		}
		sc.close();
		System.out.println(total);
		System.out.println(average(ntotal, dataset));
	}
	
	static int subTotal(int each, int n) {
		return each * n;
	}
	
	static int average(int sum, int n) {
		float d = (float)sum / (float)n;
		return Math.round(d);
	}
}

Measured memory_bytes: 17376
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);		
	int N;  cin >> N;
	vector<P>  vec(N);
	for(int i = 0 ; i < N ; i++){
			int X, L;  cin >> X >> L;
			vec[i].first = X + L, vec[i].second = X - L;
	}

	SORT(vec);
	int ans = 0, t = -INF;
	for(int i = 0 ; i < N ; i++){
			if(t <= vec[i].second){
					ans++;
					t = vec[i].first;
			}
	}

	cout << ans << endl;
		
	return 0;
}


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

using namespace std;
#define intMax 2147483647
#define rep(i, a, b) for (long long i = a; i < b; i++)
#define repp(i, a, b) for (long long i = a; i >= b; i--)
#define be(a) (a.begin(), a.end())
#define rbe(p) (p.rbegin(), p.rend())
#define pb push_back

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    vector<int> A = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin >> n;
    cout << A[n-1];
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace CompetitiveProgramming
{


  class Solve
  {
    const int INF = (int)(1e9) + 10;
    
    private void Main()
    {
      int N = Scanner.NextInt();
      var a = Scanner.GetLine_Int();

      int ans = 0;
      for (int i = 0; i < N; i++)
      {
        if (a[a[i] - 1] == i + 1) 
        {
          ans++;
        }
      }
      Console.WriteLine(ans / 2);

    }
    public Solve()
    {
      Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
      Main();
      Console.Out.Flush();
    }
  }

  class Program
  {
    static void Main(string[] args)
    {
      new Solve();
    }
  }

  class Scanner
  {
    public static string GetLine() { return Console.ReadLine().Trim(); }
    public static int[] GetLine_Int() { return Console.ReadLine().Trim().Split().Select(int.Parse).ToArray(); }
    public static long[] GetLine_Long() { return Console.ReadLine().Trim().Split().Select(long.Parse).ToArray(); }
    public static ulong[] GetLine_ULong() { return Console.ReadLine().Trim().Split().Select(ulong.Parse).ToArray(); }
    public static string GetContents() { return Console.In.ReadToEnd(); }
    public static int NextInt() { return int.Parse(Console.ReadLine().Trim()); }
    public static long NextLong() { return long.Parse(Console.ReadLine().Trim()); }
    public static ulong NextULong() { return ulong.Parse(Console.ReadLine().Trim()); }
  }
}

Measured memory_bytes: 10968