akhauriyash/Code-Regression huggingface dataset:
import sys
import itertools
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
li=[]
for i in range(n):
    li.append(i+1)
a=list(itertools.permutations(li))
tmp=[0,0]

for i in range(len(a)):
    if list(a[i])==p:
        tmp[0]=i
    if list(a[i])==q:
        tmp[1]=i
print(abs(tmp[0]-tmp[1]))

Measured memory_bytes: 46576
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main() 
{   
    int N,A,B,C;
    cin>>N>>A>>B>>C;
    vint l(N);
    REP(i,N) cin>>l[i];

    int ans=1e18;
    REP(_S,pow(4,N)){
        int S=_S;
        int cost=0;
        int a=0,b=0,c=0;
        REP(i,N){
            if(S%4==0){
                if(a>0) cost+=10;
                a+=l[i];
            }
            if(S%4==1){
                if(b>0) cost+=10;
                b+=l[i];
            }
            if(S%4==2){
                if(c>0) cost+=10;
                c+=l[i];
            }
            S/=4;
        }
        if(a>0 and b>0 and c>0){
            cost+=abs(a-A)+abs(b-B)+abs(c-C);
            ans=min(ans,cost);
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
import java.io.*
import java.util.*

val pw = PrintWriter(System.out)
const val YES = "Yes"
const val NO = "No"
fun solve(A: Long, B: Long) {
    if (A % 2L == 1L && B % 2L == 1L) println(YES)
    else println(NO)
        return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }

    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }

    val sc = Scanner(System.`in`)
    val A = sc.next().toLong()
    val B = sc.next().toLong()
    solve(A, B)
}



Measured memory_bytes: 29600
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main{
	Scanner s=new Scanner(System.in);

	void solve(){
		StringBuilder a=new StringBuilder();
		StringBuilder b=new StringBuilder(s.next());
		boolean rev=false;

		for(int q=gInt();q>0;--q) {
			if(gInt()==1) {
				rev^=true;
			}else {
				StringBuilder c=rev^gInt()==1?a:b;
				c.append(s.next().charAt(0));
			}
		}
		a.reverse().append(b);
		System.out.println(rev?a.reverse():a);
	}

	public static void main(String[] A){
		new Main().solve();
	}

	int gInt(){
		return Integer.parseInt(s.next());
	}
	long gLong(){
		return Long.parseLong(s.next());
	}
	double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,this::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,this::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,this::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(this::gInt).limit(n);
	}
	LongStream LONGS(int n){
		return LongStream.generate(this::gLong).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}

class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}


Measured memory_bytes: 90464
#include "bits/stdc++.h"

using namespace std;

using i64 = int_fast64_t;

deque<pair<char, int>> f(string &s)
{
    i64 n = s.size(), cur = 1;
    deque<pair<char, int>> ps;
    for (int i = 0; i < n - 1; i++)
    {
        if (s[i] == s[i + 1])
        {
            cur++;
        }
        else
        {
            ps.push_back(make_pair(s[i], cur));
            cur = 1;
        }
    }
    ps.push_back(make_pair(s.back(), cur));
    return ps;
}

void solve()
{
    string s;
    i64 k;
    cin >> s >> k;
    auto ps = f(s);
    if (ps.size() == 1)
    {
        cout << s.size() * k / 2 << endl;
        return;
    }
    i64 ans = 0, off = 0;
    for (auto &p : ps)
    {
        off += p.second / 2;
    }
    s += s;
    ps = f(s);
    i64 dif = 0;
    for (auto &p : ps)
    {
        dif += p.second / 2;
    }
    dif -= off;
    dif *= k - 1;
    ans = dif + off;
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>

typedef long long ll;
#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;

int main(){
	int N, A;
	cin >> N >> A;

	ll double_time = N * N;
	cout << (double_time - A) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int x;
	cin >> x;
	if (x  == 3 || x == 5 || x == 7)
	{
		cout << "YES";
	}
	else
	{
		cout << "NO";
	}
	cout << endl;
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[])
{
	stack<int> S1;
	stack<pair<int, int> > S2;
	char ch;
	int sum = 0;
	for (int i = 0; cin >> ch; i++) {
		if (ch == '\\') S1.push(i);
		else if (ch == '/' && S1.size() > 0) {
			int j = S1.top();
			S1.pop();
			sum += i - j;
			int a = i - j;
			while (S2.size() > 0 && S2.top().first > j) {
				a += S2.top().second;
				S2.pop();
			}
			S2.push(make_pair(j, a));
		}
	}
	vector<int> ans;
	while (S2.size() > 0) {
		ans.push_back(S2.top().second);
		S2.pop();
	}
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for (int i = 0; i < ans.size(); i++) {
		cout << " ";
		cout << ans[i];
	}
	cout << endl;

	return 0;
}



Measured memory_bytes: 3224
#include<stdio.h>

int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a < b && a < c )
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	
	return 0;
}


Measured memory_bytes: 2080
#include<stdio.h>

int main(){
  int n,i;
  int F[45];

  scanf("%d",&n);

  F[0]=F[1]=1;

  for(i=2;i<=n;i++){
    F[i]=F[i-2]+F[i-1];
  }

  printf("%d\n",F[n]);

  return 0;
}

Measured memory_bytes: 596
/* --- author: dxm --- */
#include<bits/stdc++.h>
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
#define DEBUG

const int maxn=100005;
int x,k,q;
int a[maxn],b[maxn],c[maxn],r[maxn];

int main(){
#ifndef DEBUG
	freopen("my.in","r",stdin);
	freopen("my.out","w",stdout);
#endif
	scanf("%d%d",&x,&k);
	REP(i,k)scanf("%d",&r[i]);
	b[0]=x;
	REP(i,k){
		a[i]=a[i-1];b[i]=b[i-1];
		if(i&1){
			a[i]=max(a[i],min(r[i]-r[i-1]-c[i-1],b[i]));
			c[i]=max(a[i-1]+c[i-1]-r[i]+r[i-1],0)-a[i];
		}
		else{
			b[i]=min(b[i],max(x-(r[i]-r[i-1])-c[i-1],a[i]));
			c[i]=min(b[i-1]+c[i-1]+r[i]-r[i-1],x)-b[i];
		}
//		cout<<a[i]<<" "<<b[i]<<" "<<c[i]<<endl;
	} 
	scanf("%d",&q);
	while(q--){
		int t,ini;
		scanf("%d%d",&t,&ini);
		int pos=upper_bound(r+1,r+1+k,t)-r-1,ans=c[pos];
		if(ini<=a[pos])ans+=a[pos];
		else if(ini>=b[pos])ans+=b[pos];
		else ans+=ini;
		if(pos&1)ans=min(x,ans+(t-r[pos]));
		else ans=max(0,ans-(t-r[pos]));
		printf("%d\n",ans);
	}
	return 0;
}

/*
Input:
-----------------
Output:
*/

Measured memory_bytes: 2816
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 9223372036854775807;
constexpr auto mod = 1000000007;

int main() {

	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	if (x < y) {
		swap(a, b);
		swap(x, y);
	}

	c *= 2;
	if (c < a + b) {
		int ans = 0;
		ans += c * y;
		x -= y;
		if (c < a)ans += c * x;
		else ans += a * x;
		cout << ans << endl;
	}
	else cout << a * x + b * y << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(i, vec.size()) cout << vec[i] << " "; print("");
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;

void Main(){

	ll X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;
	vl p(A);
	vl q(B);
	vl r(C);
	rep(i, A) cin >> p[i];
	rep(i, B) cin >> q[i];
	rep(i, C) cin >> r[i];
	
	SORT(p); SORT(q); SORT(r);
	REV(r);
	ll ans = 0;
	ll ind1 = A - X;
	ll ind2 = B - Y;
	rep2(i, ind1, A) ans += p[i];
	rep2(i, ind2, B) ans += q[i];
	ll ind3 = 0;
	ll ma, mb;
	rep(i, C){
		
		if(ind1 == A && ind2 == B) break;
		if(ind1 == A) ma = INF;
		else ma = p[ind1];
		if(ind2 == B) mb = INF;
		else mb = q[ind2];
		
		if(ma >= mb){
			if(mb < r[ind3]){
				ans -= mb;
				ans += r[ind3];
				ind2++;
				ind3++;
			}
		}
		else{
			if(ma < r[ind3]){
				ans -= ma;
				ans += r[ind3];
				ind1++;
				ind3++;
			}
		}
	}
	
	print(ans);
	
}

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





Measured memory_bytes: 5572
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[26];
int main() {
	// your code goes here
	string s;
	cin>>s;
	ll flag=0;
	char ch;
	for(ll i=0;i<s.length();i++)
	a[s[i]-'a']++;
	for(ll i=0;i<26;i++)
	{
		if(a[i]==0)
		{
			flag=1;
			ch = i+'a';
			break;
		}
	}
	if(flag==0)
	cout<<"None"<<endl;
	else
	{
		cout<<ch<<endl;
	}
	return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC() ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);


int main()
{
    int i = 0, j = 0, cs = 0, in;
    int a, b, c, d; cin>>a>>b>>c>>d;
    while(a > 0 && c > 0){
        c -= b;
        a -= d;
    }
    if(c <= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3644
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0

for p in range(A+1):
    for q in range(B+1):
        for r in range(C+1):
            if (X - 500*p - 100*q - 50*r) == 0:
                ans += 1
                
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
    char s[1000];
    gets(s);
    int l=strlen(s);
    int i;
    for(i=0;i<l;i++)
    {
     if(s[l-1]=='s')
     {
        printf("%s",s);
        printf("es");
        break;
     }
     else
     {
     printf("%s",s);
     printf("s");
     break;
     }
    }
    
    return 0;
}

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

int main() {
  int N;
  int a[100];
  
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> a[i];
  
  int mini = 1000000000;
  int maxm = 0;
  
  for (int i = 0; i < N; ++i){
    mini = min(mini, a[i]);
    maxm = max(maxm, a[i]);
  }
  
  cout << maxm - mini << endl;
}

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

main(){
  int a,b,k,i,count=0,ans;
  cin >> a >> b >> k;
  
  for(i=100;0<i;i--){
    if(a%i==0 && b%i==0){
      count++;
      if(count==k){cout << i <<endl; break;}
    }
  }
  
}

Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,c=INTM()
    if (a*100+b*10+c)%4 == 0:
        print('YES')
    else:
        print('NO')
if __name__ == '__main__':
    do()

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>

using namespace std;

int main() {
  long long n, y;
  cin >> n >> y;

  for (long long i = 0; i <= n; i++) {
    for (long long j = 0; i + j <= n; j++) {
      long long k = n - i - j;
      if (i * 10000 + j * 5000 + k * 1000 == y) {
        cout << i << ' ' << j << ' ' << k << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const double pi=acos(-1.0);
const int maxn=3010;
int n,L; ll m;
double t[maxn];
double a,b,x,y,tmp;
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(L);
	m=(ll)n*(n-1)*(n-2)/6;
	for (int i=1;i<=n;i++) read(t[i]);
	for (int i=1;i<=n;i++)
	for (int j=i+1,k;j<=n;j++) {
		tmp=(t[i]+t[j])/2;
		tmp=2*pi*tmp/L;
		k=j-i-1;
		x=cos(tmp);
		y=sin(tmp);
		a+=x*(n-2-k);
		b+=y*(n-2-k);
		tmp+=pi;
		x=cos(tmp);
		y=sin(tmp);
		a+=x*k;
		b+=y*k;
	}
	printf("%.10lf %.10lf\n",a/m,b/m);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

ans = 0
j = 0
B = list(map(abs,A))

for a in A:
    if a <= 0:
        j += 1
ans = sum(B)
if j%2 == 1:
    k = min(B)
    ans -= 2*k
print(ans)

Measured memory_bytes: 14284
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int sum=INT_MAX;
int c=0;
// int dfs(vector<vector<pair<int,int>>> v,int s,int d,bool vis[]){
//      if(s==d){
//        sum=min(sum,c);
//      }
//     c=0;
//     for(auto x: v[s]){
//             if(!vis[x.first]){
//                 c+=x.second;
//                 c+=dfs(v,x.first,d,vis);
//             }
//     }
//     return c;
// }

int main(){
    int n,m,l;
    cin>>n>>m>>l;
    vector<vector<pair<int,int>>> v(n+1);
    ll dp[n+1][n+1];
    for(int i=1;i<=n;i++){
         for(int j=1;j<=n;j++){
           if(i==j)  dp[i][i]=0;
           else dp[i][j]=INT_MAX;
         }
    }
    for(int i=0;i<m;i++){
        int x,y,w;
        cin>>x>>y>>w;
        dp[x][y]=dp[y][x]=w;
    }
    for(int k=1;k<=n;k++){
         for(int i=1;i<=n;i++){
             for(int j=1;j<=n;j++){
                 dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
             }
         }
    }
   ll dp2[n+1][n+1];
    for(int i=1;i<=n;i++){
         for(int j=1;j<=n;j++){
           if(dp[i][j]<=l) dp2[i][j]=1;
           else dp2[i][j]=INT_MAX;
         }
    }
    for(int k=1;k<=n;k++){
         for(int i=1;i<=n;i++){
             for(int j=1;j<=n;j++){
                 dp2[i][j]=min(dp2[i][j],dp2[i][k]+dp2[k][j]);
             }
         }
    }
     int t;
     cin>>t;
     while(t--){
         int x,y;
         cin>>x>>y;
         int ans=0;
        // cout<<dp2[x][y]<<" ";
         //if(dp[x][y]>l) 
         if(dp2[x][y]==INT_MAX) ans=-1;
         else ans=dp2[x][y]-1;
          cout<<ans<<endl;
         //sum=0;
     }
}

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

using namespace std;
typedef long long ll;
ll s[4]={25, 10, 5, 1};

int main(){
    ll n; cin>>n;
    int ans = 0;
    for(int i=0;i<4;i++){
        ans += n/s[i];
        n %= s[i];
        if(n==0) break;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3120
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Modulo
    {
        private const int M = 1000000007;
        private readonly int[] m_facs;
        public int Mul(int a, int b)
        {
            return (int)(Math.BigMul(a, b) % M);
        }
        public Modulo(int n)
        {
            m_facs = new int[n + 1];
            m_facs[0] = 1;
            for (int i = 1; i <= n; ++i)
            {
                m_facs[i] = Mul(m_facs[i - 1], i);
            }
        }
        public int Fac(int n)
        {
            return m_facs[n];
        }
        public int Pow(int a, int m)
        {
            switch (m)
            {
            case 0:
                return 1;
            case 1:
                return a;
            default:
                int p1 = Pow(a, m / 2);
                int p2 = Mul(p1, p1);
                return ((m % 2) == 0) ? p2 : Mul(p2, a);
            }
        }
        public int Div(int a, int b)
        {
            return Mul(a, Pow(b, M - 2));
        }
        public int Ncr(int n, int r)
        {
            if (n < r) { return 0; }
            if (n == r) { return 1; }
            int res = Fac(n);
            res = Div(res, Fac(r));
            res = Div(res, Fac(n - r));
            return res;
        }
    }
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Solve(int N, int M)
        {
            var exponents = new List<int>();
            for (int i = 2; i * i <= 1000000000 && M > 1; ++i)
            {
                int j = 0;
                while (M % i == 0)
                {
                    M /= i;
                    ++j;
                }
                if (j > 0) { exponents.Add(j); }
            }
            if (M > 1) { exponents.Add(1); }
            var mod = new Modulo(131072);
            long ans = 1;
            foreach (int e in exponents)
            {
                ans *= mod.Ncr(e + N - 1, e);
                ans %= 1000000007;
            }
            return ans;
        }
        static void Main(string[] args)
        {
            int[] V = ReadInts();
            Console.WriteLine(Solve(V[0], V[1]));
        }
    }
}


Measured memory_bytes: 13536
n, m = map(int, input().split())
ab = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append((a, b))
# a の少ない順
ab.sort(key=lambda a: a[0])
ans = 0
for i in ab:
    for a in range(i[1]):
        m -= 1
        if m < 0:
            break
        ans += i[0]
    
    if m < 0:
        break

print(ans)



Measured memory_bytes: 18164
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
const ll inf = 1e18 + 1;
const ll limit = 1e9;

int main() {
    int n; cin >> n;
    vector<int> b(n+1);
    for (int i = 0; i < n - 1; i++) {
        int a; cin >> a;
        b[a]++;
    }
    for (int i = 1; i <= n; i++) cout << b[i] << "\n";
}

Measured memory_bytes: 3996
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) throws IOException {
		ContestScanner scan = new ContestScanner();

		int N = scan.nextInt();

		int[] Nums = new int[N];

		for(int i=0; i < N; i++)
		{
			Nums[i] = scan.nextInt();
		}

		(new Solve(N, Nums)).solve();
	}

}
class Solve {
	private final int N;
	private final int[] Nums;

	public Solve(final int N, final int[] Nums)
	{
		this.N = N;
		this.Nums = Nums;
	}

	public void solve()
	{
		int count = 0;

		for(int i=0; i < N; i++)
		{
			if(isPrime(Nums[i])) count++;
		}

		System.out.println(count);
	}

	public boolean isPrime(final int num)
	{
		if(num <= 2) return true;

		if(num <= 1 || num % 2 == 0) return false;

		int limit = (int)Math.ceil(Math.sqrt(num));
		int v = 3;

		do {
			if(v < num && num % v == 0) return false;

			v += 2;
		} while(v <= limit);

		return true;
	}
}
class ContestScanner {
	BufferedReader reader;
	String[] line;
	int index;
	public ContestScanner() {
		reader = new BufferedReader(new InputStreamReader(System.in));
	}

	public ContestScanner(String filename) throws FileNotFoundException {
		reader = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
	}

	public String nextToken() throws IOException {
		if(line == null || index >= line.length)
		{
			line = reader.readLine().trim().split(" ");
			index = 0;
		}

		return line[index++];
	}

	public String next() throws IOException {
		return nextToken();
	}

	public String readLine() throws IOException {
		line = null;
		index = 0;

		return reader.readLine();
	}

	public int nextInt() throws IOException, NumberFormatException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException, NumberFormatException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException, NumberFormatException {
		return Double.parseDouble(nextToken());
	}

	public int[] nextIntArray(int N) throws IOException, NumberFormatException {
		int[] result = new int[N];

		for(int i=0; i < N; i++) result[i] = nextInt();

		return result;
	}

	public long[] nextLongArray(int N) throws IOException, NumberFormatException {
		long[] result = new long[N];

		for(int i=0; i < N; i++) result[i] = nextLong();

		return result;
	}

	public double[] nexDoubleArray(int N) throws IOException, NumberFormatException {
		double[] result = new double[N];

		for(int i=0; i < N; i++) result[i] = nextDouble();

		return result;
	}
}

Measured memory_bytes: 30792
N, K = map(int, input().split())
W = [int(input()) for i in range(N)]


def can_be_loaded(P):
    """
    最大積載量がPのとき、何個の荷物が積めるかを返す
    """
    j = 0
    for i in range(K):
        s = 0
        while s + W[j] <= P:
            s += W[j]
            j += 1
            if j == N:
                return N
    return j


left = 0
right = 10**5 * 10**4  # k=1, n=10**5, w=10**4の場合
while right - left > 1:
    mid = (left + right) / 2
    v = can_be_loaded(mid)  # P = midとして何個積めるかチェック
    if v >= N:  # ここに=を入れているので最後がreturn rightでOK
        right = mid
    else:
        left = mid
print(int(right))




Measured memory_bytes: 9584
def solve():
    N = int(input())
    S = input()

    def rolling_hash(s, mod, base = 37):
        l = len(s)
        h = [0]*(l + 1)
        v = 0
        for i in range(l):
            h[i+1] = v = (v * base + ord(s[i])) % mod
        pw = [1]*(l + 1)
        v = 1
        for i in range(l):
            pw[i+1] = v = v * base % mod
        return h, pw

    def chk(S, mod, D = [0]*N):
        h, pw = rolling_hash(S, mod)
        left = 0; right = N//2+1
        while left+1 < right:
            l = mid = (left + right) >> 1
            p = pw[l]
            for i in range(min(l, N-2*l+1)):
                D[i] = (h[l+i] - h[i]*p) % mod
            s = set()
            ok = 0
            for i in range(l, N-l+1):
                s.add(D[i-l])
                D[i] = v = (h[l+i] - h[i]*p) % mod
                if v in s:
                    ok = 1
                    break
            if ok:
                left = mid
            else:
                right = mid
        return left

    print(chk(S, 10**9 + 9))
solve()


Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod 1000000007
#pragma GCC optimize ("-O2")
#define mod2 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define endl "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<pair<lli,int>, null_type,less<pair<lli,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define p_q priority_queue 
#define min_p_q priority_queue <int,vt <int>,greater <int>>
using namespace std;
using namespace __gnu_pbds; 
template <typename T> 
void DEBUG_ARR(vt<T> a){
	f(i,0,a.size())cout<<a[i]<<" ";
	cout<<"\n";
}

int main() { 
    fastio;
    int n;
    cin>>n;
    int a[n+1];
    f(i,1,n+1)cin>>a[i];
    int pos=1;
    int ans=0;
    f(i,1,n+1){
        if(a[i]!=pos){
            ans++;
        }
        else pos++;
    }
    if(ans>n-1){
        cout<<-1;
    }
    else cout<<ans;
    return 0; 	
}

Measured memory_bytes: 1024
N,M = map(int,input().split())
A = [0 for _ in range(N+1)]
B = [0 for _ in range(N+1)]
for _ in range(M):
    p,S = input().split()
    p = int(p)
    if S=="AC":
        if A[p]==0:
            A[p]=1
    else:
        if A[p]==0:
            B[p] += 1
for i in range(N+1):
    if A[i]==0:
        B[i]=0
print(sum(A),sum(B))

Measured memory_bytes: 85716
#include <bits/stdc++.h>
using namespace std;
const int MAX=100;
int N,K,ans,a;
vector<int> l;
int main() {
	ans=0;
	cin >> N >> K;
	for(int i=0;i<N;++i){
		cin>>a;
		l.push_back(a);
	}
	sort(l.begin(), l.end()); 
	for(int i=N-1;N-K-1<i;--i){
		ans+=l[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib> //func147bでインクルード
#include <vector>  //func146b
using namespace std;
 
size_t length(const string& str) {
    return str.length();
}
 
void func141b()
{
    string s, tmp;
    vector<char> v = { 'L','R' };
    tmp = "Yes";
    cin >> s;
    for (int i = 0; i < length(s); ++i) {
        if (s[i] == v[i % 2]) tmp = "No";
    }
    cout << tmp << endl;
}
 
int main(){
  func141b();
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    int copy;
    int a[n];
    int j=0;
    int i=n-1;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    while(i>=j){
        copy=a[i];
        a[i]=a[j];
        a[j]=copy;
        j=j+1;
        i=i-1;
    }

    for(int i=0; i<n; i++){
        cout << a[i] <<" \n"[i==n-1];
    }
    return 0;
}


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

int main(){
  string s;
  cin>>s;
  bool f=false;
  rep(i,3) if(s[i]=='7') f=true;
  if(f) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

using namespace std ;

char c ;

int main ()
{
    c=getchar();
    if ( c=='A' ) puts("T");
    else if ( c=='T' ) puts("A");
    else if ( c=='C' ) puts("G");
    else puts("C");
    return 0 ;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <stack>

#define REP(i,n) for(int (i) = 0;(i) < (n) ; ++(i))
#define REPA(a,i,n) for(int (i) = (a) ; (i) < (n) ; ++(i))
#if defined(_MSC_VER)||__cplusplus > 199711L
#define AUTO(r,v) auto r = (v)
#else
#define AUTO(r,v) typeof(v) r = (v)
#endif
#define ALL(c) (c).begin() , (c).end()
#define EACH(it,c) for(AUTO(it,(c).begin());it != (c).end();++it)
#define LL long long 
#define INF  99999999;
#define QUICK_CIN ios::sync_with_stdio(false); cin.tie(0);
using namespace std;

int balls[10];

bool is_b[10];

bool check(){
	int b(-1), c(-1);

	REP(i, 10){
		if (is_b[i]){
			if (b > balls[i])
				return false;
			b = balls[i];
		}
		else{
			if (c > balls[i])
				return false;
			c = balls[i];
		}
	}
	return true;
}

bool DFS(int i){
	if (i == 10)
		return check();

	bool ret(false);

	ret |= DFS(i + 1);

	is_b[i] = true;

	ret |= DFS(i + 1);

	is_b[i] = false;

	return ret;
}

int main(){
	QUICK_CIN;

	int n;
	cin >> n;

	REP(i, n){
		REP(j, 10){
			cin >> balls[j];
		}
		cout << (DFS(0) ? "YES" : "NO") << endl;
		fill(is_b, is_b + 10, false);
	}

	return 0;
}

Measured memory_bytes: 1180
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string a, b; cin >> a >> b;
	if (a.size() == b.size())cout << (a == b ? "EQUAL" : (a < b ? "LESS" : "GREATER")) << endl;
	else cout << (a.size() < b.size() ? "LESS" : "GREATER") << endl;


	return 0;
}

Measured memory_bytes: 256
n = int(input())
A = [int(input()) for _ in range(n)]
visited = [False for _ in range(n)]
button = 0
ans = 0
while True:
    if visited[button]:
        print(-1)
        exit()
    if button == 1:
        break
    visited[button] = True
    button = A[button] - 1
    ans += 1
print(ans)


Measured memory_bytes: 7852
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N; cin >> N;
    vector<ll> A(N); for(auto& in:A) cin >> in;
    string S; cin >> S;

    vector<ll> B;
    for(int i = N-1; i>= 0; i--){
        ll V = A[i];
        for(auto b:B) V = min(V,V^b);
        if(V){
            if(S[i] == '1'){
                return 1;
            }
            B.emplace_back(V);
        }
    }
    return 0;
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    //solve<ll>(0);
    int T; cin >> T;
    while(T--) cout << fixed << setprecision(12) << solve<ll>() << endl;
    return 0;
}

Measured memory_bytes: 3580
# 最小公倍数(mathは3.5以降) fractions
from functools import reduce
import fractions #(2020-0405  fractions→math)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y) # 「//」はフロートにせずにintにする
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N,M = (int(x) for x in input().split())
A = list(map(int, input().split()))
lcm         =lcm_list(A)
han_lcm     =lcm//2
han_lcm_num =M//han_lcm
han_lcm_num =(han_lcm_num +1)//2 #偶数を除く

#半公倍数がA自身の中にある時は✖
if han_lcm in A:
    han_lcm_num =0
#半公倍数がaiで割り切れるときは✖
for a in A:
    if han_lcm % a ==0:
        han_lcm_num =0
print(han_lcm_num)

Measured memory_bytes: 16292
using System;

public class Hello
{
	public static void Main()
	{
		string[] line = Console.ReadLine().Trim().Split(' ');
		var a = int.Parse(line[0]);
		var b = int.Parse(line[1]);
		int ans;
		if (a >= 13) ans = b;
		else if (a <= 5) ans = 0;
		else ans = b / 2;
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;
long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}
ll modinv(ll a){ ll b=mod,u=1,v=0,t; while(b){ t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } return (u+mod)%mod; }
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
ll modncr(ll n,ll r){ ll i,plus=1; rep(i,r){ plus=(plus*(n-i))%mod; plus=moddevide(plus,i+1); } return plus; }
ll euclidean_gcd(ll a, ll b) { if(a<b) return euclidean_gcd(b, a); ll r; while ((r=a%b)){a=b;b=r;} return b; }
ll countdigits(ll n){ ll ans=0; while(n){n/=10;ans++;} return ans; }
ll sumdigits(ll n){ ll ans=0; while(n){ans+=n%10;n/=10;} return ans; }
void printmap(vector<ll>& a,ll H,ll W){ ll i,j; For(i,0,H+2){ For(j,0,W+2){cout<<a[i*(W+2)+j];} cout<<endl; } } void inputmap(vector<ll>& a,ll H,ll W){ ll i,j; string ss; For(i,1,H+1){ cin>>ss; For(j,1,W+1){ if(ss[j-1]=='#'){ a[i*(W+2)+j]=1; }else{ a[i*(W+2)+j]=0; } } } }
int main(){
  ll i,j,N,K,a;
  string ss;
  cin>>N>>K>>a;
  if(N+a==K+K){
  cout<<"YES"<<endl;
  }else{
  cout<<"NO"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





vector<vector<ll>> g1, g2;
vector<bool> visited;
vector<ll> ver_num;
ll cur;

void dfs(ll v){
    for(auto &child : g1[v]){
        if(!visited[child]){
            visited[child] = true;
            dfs(child);
        }
    }
    ver_num[v] = cur++;
}

int main() {
    ll n, m;
    cin >> n >> m;
    g1.resize(n);
    g2.resize(n);
    vector<ll> cnt(n);
    REP(i, n - 1 + m){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g1[a].push_back(b);
        g2[b].push_back(a);
        cnt[b]++;
    }
    
    ll root = -1;
    REP(i, n){
        if(cnt[i] == 0){
            root = i;
            break;
        }
    }
    visited.resize(n);
    ver_num.resize(n);
    visited[root] = true;
    dfs(root);
    
    REP(i, n){
        if(i == root){
            cout << 0 << endl;
            continue;
        }
        
        ll ans = -2, k = INF;
        for(auto &v : g2[i]){
            if(ver_num[i] < ver_num[v] && k > ver_num[v]){
                k = ver_num[v];
                ans = v;
            }
        }
        cout << ans + 1 << endl;
    }
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

    ll L, R;
    cin >> L >> R;
    if(R - L >= 2019) {
        printf("0\n");
        return 0;
    }

    L %= 2019;
    R %= 2019;
    if(R < L) {
        printf("0\n");
        return 0;
    }

    ll ans = LLINF;
    for(ll i = L; i < R; ++i) {
        for(ll j = i + 1; j <= R; ++j) {
            ll cand = (i * j) % 2019;
            ans = min(ans, cand);
        }
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#include <bits/extc++.h>
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>,
  rb_tree_tag, tree_order_statistics_node_update>;

// cur.order_of_key(2)
// the number of elements in the set less than 2
// *cur.find_by_order(1)
// the 1-st smallest number in the set(0-based)

typedef long long ll;

const int MAX_N = 1e5 + 5;

int bs [MAX_N];

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

  ordered_set<pair<int, int>> as;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    as.insert(make_pair(a, i));
  }

  for (int i = 0; i < n; i++) {
    cin >> bs[i];
  }

  ordered_set<pair<int, int>> cs;
  for (int i = 0; i < n; i++) {
    int c;
    cin >> c;
    cs.insert(make_pair(c, i));
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (ll) as.order_of_key(make_pair(bs[i], -1))
      * (n - (ll) cs.order_of_key(make_pair(bs[i] + 1, -1)));
  }
  cout << ans << endl;
}


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

int main() {
  string S;
  cin >> S;
  
  int ans = 0;
  for (int i = 0; i < S.size(); ++i) {
    for (int j = i; j < S.size(); ++j) {
      bool judge = true;
      for (int k = i; k < j + 1; ++k) {
        if (S[k] != 'A' && S[k] != 'C' && S[k] != 'G' && S[k] != 'T') judge = false;
      }
      if (judge) ans = max(ans, j - i + 1);
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<map>
#include<set>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<string>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define il inline
#define rg register
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define rep(i,st,ed) for(rg int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(rg int i=(ed);i>=(st);--i)
#define rep0(i,n) for(rg int i=0;i<(n);++i)
#define per0(i,n) for(rg int i=(n)-1;i>=0;--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
template<typename T> il T qmin(const T &x,const T &y){return x<y?x:y;}
template<typename T> il T qmax(const T &x,const T &y){return x>y?x:y;}
template<typename T> il void getmin(T &x,const T &y){if(y<x) x=y;}
template<typename T> il void getmax(T &x,const T &y){if(y>x) x=y;}
il void fileio(const string &s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e18+7;
const int N=105,M=N<<1;

int v[M],nxt[M];
int head[N],n;

il void addedge(int p,int x,int y){
	v[p]=y,nxt[p]=head[x],head[x]=p;
}

il int mxdep(const int &u,const int &p){
	int ans=0;
	for(int e=head[u];e;e=nxt[e]){
		if(v[e]==p) continue;
		getmax(ans,mxdep(v[e],u));
	}
	return ans+1;
}

int tot[N];

il void dfs(const int &u,const int &p,const int &d){
	int cur=0;
	for(int e=head[u];e;e=nxt[e]){
		if(v[e]==p) continue;
		dfs(v[e],u,d+1);
		++cur;
	}
	getmax(tot[d],cur);
}

il ll calc(int x,int y,int d){
	memset(tot+1,0,sizeof(int)*d);
	dfs(x,y,1);
	dfs(y,x,1);
	ll res=1;
	rep(i,1,d-1){
		assert(tot[i]);
		res=res*tot[i];
	}
	return res<<(x==y?0:1);
}

int main(){
//	fileio("test");
	scanf("%d",&n);
	rep(i,1,n-1){
		int x,y;
		scanf("%d%d",&x,&y);
		addedge(lch(i),x,y);
		addedge(rch(i),y,x);
	}
	pil ans=mp(inf,0);
	rep(i,1,n){
		int dep=mxdep(i,0);
		if(dep>ans.X) continue;
		getmin(ans,mp(dep,calc(i,i,dep)));
	}
	rep(i,1,n-1){
		int x=v[rch(i)],y=v[lch(i)];
		int dep=qmax(mxdep(x,y),mxdep(y,x));
		if(dep>ans.X) continue;
		getmin(ans,mp(dep,calc(x,y,dep)));
	}
	printf("%d %lld\n",ans.X,ans.Y);
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = nextInt()
    fun listOfIntToPair(p: List<Int>): Pair<Int, Int> = Pair(p[0], p[1])
    val AB = Array<Pair<Int, Int>>(N, { listOfIntToPair(listOfInt()) }).sortedBy { it.second }
    var ans = true
    var t = 0
    repeat(N) {
        t += AB[it].first
        if (t > AB[it].second) ans = false
    }
    println("${if (ans) "Yes" else "No"}")
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


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

int main(){
	int N;
	int A[200001];
	cin >> N;
	for(int i = 1; i <= N; i++){
		A[i] = 0;
	}
	for(int i = 2; i <= N; i++){
		int tmp;
		cin >> tmp;
		A[tmp]++;
	}
	for(int i =1; i <= N; i++){
		cout << A[i] << endl;
	}
}

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

int main()
{
    string s; cin>>s;
    int res=-(s[0]=='p');
    int g=1, p=0;
    for(int i=1; i<s.size(); ++i) {
        int c=s[i]%2; // g=1, p=0
        if (c) {
            if (p+1<=g) { ++p; ++res; }
            else ++g;
        }
        else {
            if (p+1<=g) ++p;
            else { ++g; --res; }
        }
    }
    cout<<res<<endl;
}


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

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

bool compare(const ii &x , const ii &y){
    return x.second < y.second;
}

void solve() {
    int n ;
    cin>>n;
    vii data(n);
    for (int i = 0; i < n; ++i) {
        int x , l;
        cin>>x>>l;
        data[i].first = x - l ;
        data[i].second = x+ l;
    }
    sort(data.begin() , data.end() , compare);
    int ans = 1;
    int last = data[0].second;
    for(int i = 1 ; i<n ; i++){
        if( last <= data[i].first ){
            ans++;
            last = data[i].second;
        }
    }
    cout<<ans<<endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
a = list(map(int,input().split()))
b = []
flag = 0
for i in range(n):
  if a[i]<= 0:
    flag += 1
  b.append(abs(a[i]))
if flag % 2== 0:
  print(sum(b))
else:
  print(sum(b)-sorted(b)[0]*2)

Measured memory_bytes: 65184
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int c = sc.nextInt();
		int[] b = new int[m];
		for (int i = 0; i < m; i++) {
			b[i] = sc.nextInt();
		}
		int[][] a = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			int sum = c;
			for (int j = 0; j < m; j++) {
				sum += a[i][j] * b[j];
			}
			if (sum > 0) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <cmath>
#include <numeric>
#include <cstdlib>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

int main(){

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

    int k;
    cin >> k;

    string str;
    cin >> str;

    if(str.size() <= k){
        cout << str;
    }else{
        string sub = str.substr(0,k);
        cout << sub << "...";
    }






    return 0;
}

Measured memory_bytes: 3644