akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a) 
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a) 
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll sum(ll n) { 
	return (1 + n) * n / 2;
}
//1から整数nまでの合計
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double sqrtNum = sqrt(a);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
}; // // //Unionfind木 // // //Unionfind木
//Unionfind木

// ===============================================================

int main() {
	ll n; cin >> n;
	vs sel(n);
	for (int i = 0; i < n; i++) {
		cin >> sel[i];
	}
	for (int i = 0; i < n; i++) {
		sort(sel[i].begin(), sel[i].end());
	}
	sort(sel.begin(), sel.end());
	ll ans = 0;
	vector<unsigned long long> junbi(n, 1);
	ll count = 0;
	ll atosakinokaunto = 1;
	for (int i = 0; i < n - 1; i++) {
		if (sel[i] == sel[i + 1]) {
			junbi[count] += atosakinokaunto;
			atosakinokaunto++;
		}
		else {
			atosakinokaunto = 1;
			count++;
		}
	}
	for (int i = 0; i < n; i++) {
		if (junbi[i] == 1) {
		}
		else ans += junbi[i]-1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 7104
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int max = 0;
		int second = 0;
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			int current = Integer.parseInt(sc.next());
			arr[i] = current;
			if (current > max) {
				second = max;
				max = current;
			} else if (current == max) {
				second = current;
			} else if (current > second) {
				second = current;
			}
		}
		for (int i = 0; i < N; i++) {
			if (max == arr[i]) {
				System.out.println(second);
			} else {
				System.out.println(max);
			}
		}
		sc.close();
	}
}


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

int main()
{
    ll a,b,k;cin >> a >>b>>k;
    if (a<=k)
    {
        k-=a;
        a=0;
        if (b<=k)
        {
            k-=b;
            b=0;
        }
        else
        {
            b-=k;
        }
        
    }
    else
    {
        a-=k;
    }
    cout << a<<" " << b << endl;
    return 0;
    
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main(){
	lli n;
	cin>>n;
	vector<lli> a(n);
	for(lli i=0;i<n;i++){
		cin>>a[i];
	}
	vector<vector<lli> > dp(n,vector<lli>(n));
	for(lli i=0;i<n;i++){
		dp[i][i]=a[i];
	}
	for(lli l=2;l<=n;l++){
		for(lli i=0;i<n-l+1;i++){
			lli j=i+l-1;
			dp[i][j]=max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
		}
	}
	cout<<dp[0][n-1]<<endl;
}

Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<int> a(n, 0);
    for(int i=0;i<n;++i) cin >> a[i];
    sort(a.begin(), a.end());

    int v=0;
    for(int i=0;i<n;++i) {
        if(i&1) v-=a[n-i-1];
        else v+= a[n-i-1];
    }
    cout << v << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
int main() {
  int num;
  int fcnt = 0, scnt = 0;
  for (int i = 0; i < 3; i++){
    scanf("%d", &num);
    if (num == 5) fcnt++;
    else if (num == 7) scnt++;
  }
  if (fcnt == 2 && scnt == 1) puts("YES");
  else puts("NO");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define pdd              pair<double,double>
#define ll               long long
#define mod              1000000007
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<int, int> &a,
               const pair<int, int> &b)
{
    return (a.second < b.second);
}
ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}
int main()
{
    fast;
    ll i,j,n,c=0,d=0,e=0,f=0,g=0,h=0,sum=0,k;
     string a;
     cin>>a;
     if((a[2]==a[3])&&(a[4]==a[5]))
     {
         cout<<"Yes";
     }
     else
        cout<<"No";
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
   
  int a[100],i,n,j,s,count=0;
   
  scanf("%d",&n);
 
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
   
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(a[j]<a[j-1]){
    s = a[j-1];
    a[j-1] = a[j];
    a[j] = s;
    count++;
      }
    }
  }
   
  for(i=0;i<n;i++){
    printf("%d",a[i]);
      if(i==n-1){
    printf("\n");
    break;
      }
      printf(" ");
  }
   
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 604
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] x = new int[N];
		for(int i = 0;i < N;i ++) {
			x[i] = sc.nextInt();
		}
		int center = K / 2, sum = 0;;
		for(int i = 0;i < N;i ++) {
			if(x[i] <= center) {
				sum += x[i] * 2;
			}else {
				sum += (K - x[i]) * 2;
			}
		}
		System.out.println(sum);
	}

}

Measured memory_bytes: 21844
#include<cstdio>                                                                                   
#include<algorithm>                                                                                
using namespace std;                                                                               
                                                                                                   
int N,K,dat[100000];                                                                               
long long r,t;                                                                                     
                                                                                                   
int main(){                                                                                        
    while(scanf("%d%d",&N,&K),N||K){                                                               
        for(int i=0;i<N;i++){                                                                      
            scanf("%d",dat+i);                                                                     
        }                                                                                          
        t=0;                                                                                       
        for(int i=0;i<K;i++){                                                                      
            t+=dat[i];                                                                             
        }                                                                                          
        r=t;                                                                                       
        for(int i=K;i<N;i++){                                                                      
            t=t-dat[i-K]+dat[i];                                                                   
            r=max(r,t);                                                                            
        }                                                                                          
        printf("%lld\n",r);                                                                        
    }                                                                                              
}  

Measured memory_bytes: 0
import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()

cnt = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        num = L[i] + L[j]
        third = bisect.bisect_left(L,num)
        if third > j:
            cnt += third - j - 1
print(cnt)

Measured memory_bytes: 9368
#include<bits/stdc++.h>
using namespace std;
const int maxx=1e5+2;
typedef long long ll;
char str[maxx];
int f[maxx];
int dp[maxx];
int ans[maxx];
int main(){
    scanf("%s",str+1);
    int sz=strlen(str+1);
    for(int i=1;i<=sz;i++){
        if(i==1){
            f[i]=1;
        }else{
            if(str[i]==str[i-1]){
                f[i]=f[i-1]+1;
            }else{
                f[i]=1;
            }
        }
    }
    for(int i=sz;i;i--){
        if(i==sz){
            dp[i]=1;
        }else{
            if(str[i]==str[i+1]){
                dp[i]=dp[i+1]+1;
            }else{
                dp[i]=1;
            }
        }
    }
    //for(int i=1;i<=sz;i++) cout<<dp[i]<<" ";
    //puts("");
    for(int i=1;i<=sz;i++){
        if(str[i]=='L'&&str[i-1]=='R'){
            if((dp[i]+f[i-1])%2==0){
                int x=(dp[i]+f[i-1])/2;
                ans[i]=x;
                ans[i-1]=x;
            }else{
                int x=(dp[i]+f[i-1])/2;
                //cout<<i<<" "<<x<<endl;
                if(max(dp[i],f[i-1])&1){

                   if(dp[i]>f[i-1]){
                        ans[i]=x+1;
                        ans[i-1]=x;
                    }else{
                        ans[i]=x;
                        ans[i-1]=x+1;
                    }
                }else{
                    if(dp[i]>f[i-1]){
                        ans[i]=x;
                        ans[i-1]=x+1;
                    }else{
                        ans[i]=x+1;
                        ans[i-1]=x;
                    }
                }

            }
        }
    }
    for(int i=1;i<=sz;i++){
        printf("%d ",ans[i]);
    }
    puts("");
}


Measured memory_bytes: 1664
function Main(input) {
  	var list = input.split("\n")[1].split(" ").map((list)=>Number(list));
  var count = 0;
  for(var i = 0; i < list.length; i++){
    if(list[i] % 2 == 1){
       count++;
       }
  }
  if(count % 2 == 0){
     console.log("YES");
     }else{
     console.log("NO");
     }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 19936
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

struct union_find{
    vector<int> par;
    vector<int> depth;
    vector<int> siz;

    union_find(int n) : par(n) , depth(n,0) , siz(n,1){
        rep(i,n) par[i]=i;
    }

    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }

    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        siz[x] +=siz[y];
        siz[y] =siz[x];
        if(depth[x]<depth[y]) par[x]=par[y];
        else{
            par[y]=par[x];
            if(depth[x]==depth[y]) depth[x] ++;
        }
    }

    bool same(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return siz[find(x)];
    }
};

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,q;
    cin>>n>>q;
    int x,y,z;
    union_find uf(n);
    rep(i,q){
        cin>>x>>y>>z;
        if(!x) uf.unite(z,y);
        else{
            // cout<<"ans=";
            if(uf.same(y,z)) cout<<1<<endl;
            else cout<<0<<endl;
        }
    }
}


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;

const int N = 300003;
const int MOD = 1e9 + 7;

inline int getInt() {
  int x;
  scanf("%d", &x);
  return x;
}

int main() {
  int n = getInt();
  int w = getInt();
  vi W(n), V(n);
  for (int i = 0; i < n; i++) {
    W[i] = getInt();
    V[i] = getInt();
  }
  vector<vector<ll>> dp(2, vector<ll>(w + 1, 0));
  for (int i = W[0]; i <= w; i++) {
    dp[0][i] = V[0];
  }
  for (int i = 1; i < n; i++) {
    int x = i&1;
    for (int j = 0; j <= w; j++) {
      if (j - W[i] >= 0) {
        dp[x][j] = max(dp[1 - x][j], dp[1 - x][j - W[i]] + V[i]);
      } else {
        dp[x][j] = dp[1 - x][j];
      }
    }
  }
  ll ans = 0;
  for (ll x : dp[1 - (n&1)]) {
    ans = max(ans, x);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int n;
int a[4];
int main(){
	cin >> n;
	REP(i,4) {
		a[i] = n % 10;
		n /= 10;
	}
	if(a[0] == a[1] && a[1] == a[2]) {
		cout << "Yes" << endl;
	}else if(a[2] == a[3] && a[1] == a[2]) {
		cout << "Yes" << endl;
	}else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b){
	return (b > 0)? gcd(b, a % b) : a ;
}
long long int lcm(long long int a, long long int b){
	return a / gcd(a, b) * b; 
}
int main(){
	int N; long long M; cin >> N >> M; 
	long long A[100010] = {}; 
	long long L = 1; 
	int mn = 100; int mx = -1; 
	for(int i = 0; i < N; i++){
		cin >> A[i]; int cnt = 0; 
		while(!(A[i] & 1)){
			A[i] >>= 1; cnt ++;  
		}
		mn = min(cnt, mn); mx = max(cnt, mx); 
	}
	if(mn != mx){
		cout << 0 << endl; return 0; 
	}
	for(int i = 0; i < N; i++){
		L = lcm(L, A[i]); 
		if(L > M){
			cout << 0 << endl; return 0; 
		}
	}
	long long num = (M >> (mn-1)) / L; 
	cout << (num + 1) / 2 << endl; 
}

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

int main()
{
    long long k,a,b;
    cin >> k >> a >> b;
    // a->b;
    if ( (a-1)+1+1>k||b<=a ) {
        cout << k+1 << '\n';
    } else {
        long long x=a;
        long long kk=k;
        kk-=(a-1); // get b biscuit
        x+=(long long)(b-a)*(kk/2);
        if ( kk%2 ) {
            x++;
        }
        cout << max(k+1,x) << '\n';
    }

    return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
typedef long double ld;
#define maxn 1001

int N, A[maxn];

int32_t main()
{
	cin>>N;
	
	ld sm = 0;
	FOR(i,1,N){
		cin>>A[i];
		sm += (ld)1 / (ld)A[i];
	}
	
	
	cout<<setprecision(8)<<ld(1) / sm;
}


Measured memory_bytes: 3824
let () =
  Scanf.scanf "%s" @@ fun a ->
  let a = Array.init (String.length a) (fun i -> i, a.[i]) in
  let ct = Array.make 26 0 in
  Array.fold_left (fun c (i, x) ->
    let x = int_of_char x - 97 in
    let c' = c + (i - ct.(x)) in
    ct.(x) <- ct.(x) + 1;
    c') 1 a
  |> Printf.printf "%d\n"

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

#define INF (1<<30)

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

	int w[n+2], e[n+2];	for(int i=1;i<=n;i++)w[i]=e[i]=0;
	w[0]=w[n+1]=e[0]=e[n+1]=INF;

	char ch;
	for(int i=1;i<=n;i++){
		cin>>ch;
		if(ch=='E') e[i]++;
		else w[i]++;
	}
	for(int i=2;i<=n;i++){
		w[i]+=w[i-1];
	}
	for(int i=n;i>=2;i--){
		e[i-1]+=e[i];
	}

	int ans=INF;

	for(int i=1;i<=n;i++){
		int check=0;
		if(i-1)check+=w[i-1];
		if(i+1<=n)check+=e[i+1];

		ans=min(ans,check);
	}

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


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

const int maxN=310;
const int Mod=998244353;

int n,m;
bitset<maxN> B[maxN];
int C[maxN][maxN],Sm[maxN],pw[maxN];

int main(){
    pw[0]=1;for (int i=1;i<maxN;i++) pw[i]=2ll*pw[i-1]%Mod;
    scanf("%d%d",&n,&m);
    int cnt=0,one=0;
    for (int i=1;i<=n;i++){
        bitset<maxN> I;I.reset();
        for (int j=1;j<=m;j++){
            int x;scanf("%d",&x);I[j]=x;
        }
        bool flag=0;
        for (int j=1;j<=m;j++)
            if (I[j]){
                if (B[j]==0){
                    B[j]=I;flag=1;break;
                }
                else I^=B[j];
            }
        if (flag==0) ++cnt;
    }

    printf("%lld\n",1ll*(pw[n]-pw[cnt]+Mod)%Mod*pw[m-1]%Mod);return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
s = 0
m = 10**9
n = 0
for x in A:
    if x < 0:
        n += 1
        x = -x
    s += x
    m = min(m, x)
if n%2 == 1:
    s -= 2*m
print(s)

Measured memory_bytes: 14332
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[100]={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] << endl;
}


Measured memory_bytes: 3604
program main
  implicit none
  character(10**6)S,S_compr
  integer:: N,N_compr,i,cnt(3)=0,c_max,c_min,d,last,memo
  logical skip
  read*,S
  S_compr=""
  N = 1;N_compr = 1
  do i=1,len_trim(S)
    if(i==1)then
      S_compr(N_compr:N_compr) = S(i:i)
      N_compr=N_compr+1
    else if(s_compr(N_compr-1:N_compr-1) /= s(i:i))then 
      S_compr(N_compr:N_compr) = S(i:i)
      N_compr=N_compr+1
    endif
  end do
  do i=1,N_compr-1
    cnt(ichar(s_compr(i:i))-64)=cnt(ichar(s_compr(i:i))-64)+1
  end do
	c_max = merge(2,1,cnt(2) > cnt(1))
	if(cnt(3) >= cnt(c_max)) c_max = 3
    c_min = merge(2,1,cnt(2) < cnt(1))
	if(cnt(3) <= cnt(c_min)) c_min = 3
	if(cnt(1) > cnt(2)) call swap(cnt(1),cnt(2))
	if(cnt(1) > cnt(3)) call swap(cnt(1),cnt(3))
	if(cnt(2) > cnt(3)) call swap(cnt(2),cnt(3))
   
	if(cnt(1) == cnt(3))then
	  print"(A)", s_compr
      stop
	endif
 
	d = cnt(3)-cnt(2)
	do i = 1,N_compr-1
    if(ichar(s_compr(i:i))-64 == c_max .and. d > 0)then
      if(i==1)then
        d=d-1
        cnt(3)=cnt(3)-1
        s_compr(i:i) = 'Z'
	  else if(i==N_compr-1 .or. s_compr(i-1:i-1) /= s_compr(i+1:i+1))then
        d=d-1
        cnt(3)=cnt(3)-1
        s_compr(i:i) = 'Z'
      endif
    endif
  end do
  do i = 2, N_compr-1
    if(ichar(s_compr(i:i))-64 == c_max .and. d > 0)then
	  if(ichar(s_compr(i-1:i-1))-64 == c_min)then
        d=d-1
        cnt(1)=cnt(1)-1
        cnt(3)=cnt(3)-1 
        s_compr(i:i) = "Z"
        s_compr(i-1:i-1) = 'Z'
      endif
    endif
  end do
  N = 1;N_compr = 1
  do i=1,len_trim(S_compr)
	if(s_compr(i:i) <= 'C')then
      s_compr(N_compr:N_compr) = s_compr(i:i)
      N_compr=N_compr+1
    endif
  end do
    S_compr=S_compr(1:N_compr-1)
	d = cnt(2)-cnt(1)
	last = -1

  skip=.false.
	do i= 1,N_compr-1
      if(skip)then
        skip=.false.
        cycle
      endif
	  if(d == 0)exit
      if(ichar(s_compr(i:i))-64 == c_max .or. ichar(s_compr(i+1:i+1))-64 == c_max)then
	    if(ichar(s_compr(i:i))-64 /= c_min .and. ichar(s_compr(i+1:i+1))-64 /= c_min)then
	      if(last == -1)then
            s_compr(i:i)=char(ichar(s_compr(i:i))+4) 
            s_compr(i+1:i+1)=char(ichar(s_compr(i:i))+4) 
            d=d-1  
          else if( i == N_compr-2 .or. s_compr(last:last) /= s_compr(i+2:i+2))then
            s_compr(i:i)="D" 
            s_compr(i+1:i+1)="D"
            d=d-1
          endif
        endif
      endif
	  if(ichar(s_compr(i:i)) <= ichar('C'))then
        last = i
      else
        skip=.true.
      endif
	end do
  N_compr=1
  do i=1,len_trim(s_compr)
	if(ichar(s_compr(i:i)) <= ichar('C'))then
      s_compr(N_compr:N_compr) = s_compr(i:i)
      N_compr=N_compr+1
    endif
  end do
  print"(A)", trim(s_compr(1:N_compr-1))
contains
subroutine swap(a,b)
  implicit none
  integer a,b
  a=xor(a,b)
  b=xor(a,b)
  a=xor(a,b)
end subroutine
end

Measured memory_bytes: 6024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
			String srt=sc.nextLine();
			String srt2="AAA";
			String srt3="BBB";
			if(srt.equals(srt2)||srt.equals(srt3)){
				System.out.println("No");
			}
			else{
				System.out.println("Yes");
			}
		}
	}


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


int main(){
	int n, k;
  	cin>>n>>k;
  	int d[k];
  	vector<int> a[k];
  	int ck[n]={0};
  	for(int i=0;i<k;i++){
    	cin>>d[i];
      	for(int j=0;j<d[i];j++){
        	int t;
          	cin>>t;
          	a[i].push_back(t);
          	if(ck[t-1]==0) ck[t-1]=1;
        }
    }
  	
  	int num=0;
  	for(int i=0;i<n;i++){
    	if(ck[i]==0) num++;
    }
  	
  	cout<<num<<endl;
}

Measured memory_bytes: 3588
// +build ignore
package main

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

func solve(sc *scanner, wr *bufio.Writer) int {
	N := sc.i()
	K := sc.i()
	P := make([]int, N)
	for i := 0; i < N; i++ {
		P[i] = sc.i()
	}

	sort.Ints(P)

	ans := 0
	for i := 0; i < K; i++ {
		ans += P[i]
	}

	fmt.Println(ans)

	return 0
}

func main() {
	sc := newScanner(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	ret := solve(sc, wr)
	wr.Flush()
	os.Exit(ret)
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}


Measured memory_bytes: 1784
n = int(input())
pn = [int(i) for i in input().split()]
flag = False
ans = 0
for i in range(n):
  if pn[i] == i+1:
    if flag:
      flag = False
    else:
      ans += 1
      flag = True      
  else:
    flag = False
print(ans)

Measured memory_bytes: 13880
import java.io.*;
import java.util.*;

public class Main {


    private  static void solver(InputReader sc, PrintWriter out) throws Exception {

        int n =  sc.nextInt();
        String s = sc.next();
        Stack<Character> stack = new Stack<>();
        for ( int i=0;i<n;i++){
           if(stack.isEmpty()){
               stack.push(s.charAt(i));
           }
           else if(stack.peek()!=s.charAt(i)){
               stack.push(s.charAt(i));
           }
        }
        out.println(stack.size());
    }
    private  static long gcd(long a, long b){
        if(b==0)
            return a;
        else
            return gcd(b,a%b);
    }

    public static void main(String[] args) throws Exception{
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in,out);
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong(){
            return Long.parseLong(next());
        }

        public long[] readLongArr(int n){
            long arr[] = new long[n];
            for(int i=0; i<n; i++){
                arr[i] = nextLong();
            }
            return arr;
        }
        public int[] readIntArr(int n){
            int arr[] = new int[n];
            for(int i=0; i<n; i++){
                arr[i] = nextInt();
            }
            return arr;
        }
    }
}
class Pair implements Comparable<Pair>{
    int x;
    String s;
    Pair(int x, String s){
        this.x = x;
        this.s = s;
    }
    public int compareTo(Pair p){
        return this.x-p.x;
    }
}

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

int main(){
 int n,q; cin>>n>>q;
  vector<queue<int>>vec(n);
  for(int i=0 ;i<q;i++){
  int k,t,x; cin>>k;
    if(k==0){
    cin>>t>>x;
      vec.at(t).push(x);
    }
    else{
    cin>>t;
      if(!vec.at(t).empty()){
      if(k==1) cout<<vec.at(t).front() <<endl;
        else vec.at(t).pop();
      }
    } 
  }
}


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

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

  int N; cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<vector<ll>> B(N, vector<ll>(2, 0));

  B[0][0] = A[0], B[0][1] = -A[0];
  for (int i = 0; i < N - 1; i++) {
    B[i + 1][0] = max(B[i][0] + A[i + 1], B[i][1] - A[i + 1]);
    B[i + 1][1] = max(B[i][0] - A[i + 1], B[i][1] + A[i + 1]);
  }
  ll ans = max(B[N - 2][0] + A[N - 1], B[N - 2][1] - A[N - 1]);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<list>
#include<vector>
#include<cmath>

#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;


int main(){

    int n, k;
    cin >> n >> k;
    int d[k];
    rep(i,0,k)cin >> d[i];

    bool flg = true;
    for(int i=n;i<100000;i++){
        int tmp = i;
        flg = true;
        while(tmp!=0){
            for(int j=0;j<k;j++){
                if(tmp%10==d[j])flg = false;
            }
            tmp /=10;
        }
        if(flg){
            cout << i << endl;
            return 0;
        }
    }
}


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define INFTY 999999

int main(void){
    char a,b,c,d;
    scanf("%c %c %c %c", &a, &b, &c, &d);

    if(a=='1'||b=='1'||c=='1'||d=='1'){
        if(a=='9'||b=='9'||c=='9'||d=='9'){
            if(a=='7'||b=='7'||c=='7'||d=='7'){
                if(a=='4'||b=='4'||c=='4'||d=='4'){
                    printf("YES\n");
                }
                else{
                    printf("NO\n");
                }
            }
            else{
                printf("NO\n");
            }
        }
        else{
            printf("NO\n");
        }
    }
    else{
        printf("NO\n");
    }
    
    return 0;
    
}


Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main();

void Compare_Func_Display(const int &arg_a, int &arg_b);


int main()
{
	const int MIN_LIMIT = -40;
	const int MAX_LIMIT = 40;
	const int ON_TEMPERATURE = 30;

	std::string buf;
	std::cin >> buf;

	int room_temperature = stoi(buf.c_str());

	if ((MIN_LIMIT > room_temperature) || (MAX_LIMIT < room_temperature))
	{
		return 0;
	}
	Compare_Func_Display(ON_TEMPERATURE, room_temperature);
	return 0;
}

void Compare_Func_Display(const int &arg_a, int &arg_b)
{
	if (arg_a <= arg_b)
	{
		std::cout << "Yes" << std::endl;
		return;
	}
	std::cout << "No" << std::endl;
	return;
}


Measured memory_bytes: 3632
a = list(map(int,input().split()))
if a[0]<a[1]:
  if a[0]<a[2] and a[2]<a[1]:
    print("Yes")
  else:
    print("No")
else:
  if a[1]<a[2] and a[2]<a[0]:
    print("Yes")
  else:
    print("No")


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;

std::vector<bool> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}

int main(){
    ll x;
    cin >> x;
    sieve(100003);
    FOR(i,x,100004){
        if(IsPrime[i]){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    string S, T;
    cin >> S >> T;
    int N = S.size();
    int M = T.size();
    int ans = min(N, M);
    for(int i = 0; i <= N - M; i++) {
        int c = 0;
        for(int j = 0; j < M; j++) {
            if (S[i + j] == T[j]) c++;
        }
        ans = min(ans, M - c);
    }
    cout << ans << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

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

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	int xa = abs(x - a);
	int xb = abs(x - b);
	int s = min(xa, xb);
	if (s == xa)cout << "A";
	else cout << "B";
}

Measured memory_bytes: 256
#include <cstdio>
 
const int N = 100500;
 
char buf[N];
 
int main() {
    int n, a, b;
    scanf("%d %d %d", &n, &a, &b);
    scanf("%s", buf);
    int ab = a + b, ca = 0, cb = 0;
    for (int i = 0; i < n; i++) {
        if (buf[i] == 'a') {
            if (ca + cb < ab) {
                ca++;
                puts("Yes");
            } else {
                puts("No");
            }
        } else if (buf[i] == 'b') {
            if (ca + cb < ab && cb < b) {
                cb++;
                puts("Yes");
            } else {
                puts("No");
            }
        } else{
        	puts("No");
        }
    }
}

Measured memory_bytes: 640
/**
 * @author yuichirw
 */
import java.util.*;
import static java.lang.Math.*;

public class Main {
	static int 		n;
	static char[][] field;
	static Scanner 	sc = new Scanner(System.in);

	
	static boolean read() {
		n = sc.nextInt(); sc.nextLine();
		if(n == 0) return false;
		field = new char[n][n];
		for(int i = 0; i < n; i++) {
			field[i] = sc.nextLine().toCharArray();
		}
		return true;
	}
	
	static int solve() {
		int[][] dp = new int[n][n];
		//init
		for(int i = 0; i < n; i++) {
			dp[i][0] = (field[i][0] == '*') ? 0:1;
			dp[0][i] = (field[0][i] == '*') ? 0:1;
		}

		int ans = 0;
		//dp
		for(int i = 1; i < n; i++) {
			for(int j = 1; j < n; j++) {
				if(field[i][j] == '*') {
					dp[i][j] = 0;
				} else {
					dp[i][j] = min(dp[i-1][j], min(dp[i][j-1], dp[i-1][j-1])) + 1;
					ans = max(dp[i][j], ans);
				}
				
			}
		}
		return ans;
	}
	
	public static void main(String[] args) {
		while(read()) {
			System.out.println(solve());
		}
	}
}

Measured memory_bytes: 17000
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define out return 0
#define pii pair<ll,ll>
#define ll long long int
using namespace std;
ll mn=1e18,mx=-1e18;
const ll mv=1000005;
ll n,a[205],ans;
int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cin>>n;
	for(int i=0;i<2*n;i++){
		cin>>a[i];
	}
	sort(a,a+2*n);
	for(int i=0;i<2*n;i+=2){
		ans+=a[i];
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int d; cin >> d;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i,d) rep(j,26) {
        cin >> s[i][j];
    }
    vector<int> t(d);
    rep(i,d) { cin >> t[i]; t[i] --; }
    int now = 0;
    vector<int> last(26);
    vector<int> ans(d);
    rep(i,d) {
        int typ = t[i];
        now += s[i][typ];
        last[typ] = i+1;
        rep(j, 26) {
            now -= c[j] * (i + 1 - last[j]);
        }
        ans[i] = now;
    }
    rep(i,d) cout << ans[i] << "\n";
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int ar[n];
    int total_votes=0;
    for(int i=0;i<n;i++){
        cin>>ar[i];
        total_votes=total_votes + ar[i];
    }
    int cnbeselected=0;
    for(int i=0;i<n;i++){
        if(ar[i]>=static_cast<double>(total_votes)/(4*m)){
            cnbeselected++;
        }
    }
    if(cnbeselected>=m) cout<<"Yes";
    else cout<<"No";

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5; 
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}

ll raise(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}




void solve()
{
    ll x; cin >> x;
    for (ll i=-200; i<=200; i++) {
        for (ll j=-200; j<=200; j++) {
            if (raise(i,5) - raise(j,5) == x ) {
                sout(i); nout(j); return;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3628
n = int(input())
p = list(map(int, input().strip().split()))


down_i = []
down_count = 0
for i in range(n-1):
    if p[i] > p[i+1]:
        down_i.append([i,p[i],p[i+1]])
        down_count += 1


if down_count == 0:
    print('YES')
else:
    if down_count == 1:
        p[down_i[0][0]] = p[down_i[0][0]+1]
        p[down_i[0][0]+1] = down_i[0][1]

        c = 0
        for i in range(n-1):
            if p[i] > p[i+1]:
                c += 1

        if c <= 0:
            print('YES')
        else:
            print('NO')

    elif down_count == 2:
        p[down_i[0][0]] = down_i[1][2]
        p[down_i[1][0]+1] = down_i[0][1]

        #print(p)

        c = 0
        for i in range(n-1):
            if p[i] > p[i+1]:
                c += 1

        if c <= 0:
            print('YES')
        else:
            print('NO')
    else:
        print('NO')


Measured memory_bytes: 3064
"ABC083 C - Multiple Gift"
"https://atcoder.jp/contests/abc083/tasks/arc088_a"

include Math

# 入力
X, Y = gets.split.map(&:to_i)

# puts (Math.log(Y.to_f/X.to_f, 2) + 1.to_f).floor

exp = X
ans = 0
while exp <= Y
  exp *= 2
  ans += 1
end
puts ans

Measured memory_bytes: 1788
/* ****GT_18**** */

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define INF			1000000000000000
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;
using namespace __gnu_pbds;

#define N  200005

ll h,w,n;
vector<pii> a;
ll fac[N];
ll inv[N];
ll dp[N];


void precalc(){
	fac[0]=fac[1]=1;
	rep(i,2,N)fac[i]=(fac[i-1]*i)%hell;
	inv[1] = 1;
	for(ll i = 2; i < N; ++i)
    inv[i] = hell - (hell/i) * inv[hell%i] % hell;
}


ll expo(ll base, ll exponent, ll mod) {								//return base^exponent modulo modulus
    ll ans = 1;
    while(exponent !=0 ) {
        if((exponent&1) == 1) {
            ans = ans*base ;
            ans = ans%mod;
        }
        base = base*base;
        base %= mod;
        exponent>>= 1;
    }
    return ans%mod;
}

inline ll calc(ll x, ll y){
	ll inv1 = expo(fac[x],hell-2,hell);
	ll inv2 = expo(fac[y],hell-2,hell);
	return ((fac[x+y]*inv1)%hell*inv2)%hell;
}


ll solve(){

	rep(i,0,n){
		dp[i]=calc(a[i].F-1,a[i].S-1);
	}

	rep(i,0,n-1){
		rep(j,i+1,n){
			if(a[j].F < a[i].F or a[j].S<a[i].S)continue;
			dp[j]=(dp[j]-(dp[i]*calc(a[j].F-a[i].F,a[j].S-a[i].S))%hell + hell)%hell;
		}
	}

	ll ans=calc(h-1,w-1);
	rep(i,0,n){
		ans = (ans - (dp[i]*calc(h-a[i].F,w-a[i].S))%hell + hell)%hell;
	}
	return ans;

}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	precalc();
	while(TESTS--)
	{
		cin>>h>>w>>n;
		rep(i,0,n){
			ll x,y;
			cin>>x>>y;
			a.pb({x,y});
		}
		sort(all(a));
		cout<<solve()<<endl;

	}
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    ll ans=0;
    ll a=0,b=0;

    for(int i = 0; i < s.size()-1; i++) {
        if(s[i]=='<') a++;
        if(s[i]=='>') b++;
        if(s[i]=='>' && s[i+1]=='<'){
            ll x=max(a,b),y=min(a,b);
            x *= max(a,b)+1;
            y *= min(a,b)-1;
            x /= 2;
            y /= 2;
            ans += x+y;
            
            a=0,b=0;
        }
    }
    if(s[s.size()-1]=='<') a++;
    if(s[s.size()-1]=='>') b++;

    ll x=max(a,b),y=min(a,b);
    x *= max(a,b)+1;
    y *= min(a,b)-1;
    x /= 2;
    y /= 2;
    ans += x+y;

    cout << ans << endl;

    return 0;
}

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

using ll = long long;

//constant
const double MOD = 1e-9 + 7;  
const double EPS = 1e-10;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPI(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

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

// view vector
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

// ***************************************

int main(void){
    
    
    int N, K;
    cin >> N >> K;
    int R, S, P;
    cin >> R >> S >> P;
    string str;
    cin >> str;

    map<char, int> score;
    score['r'] = P;
    score['s'] = R;
    score['p'] = S;

    vector<bool> lst(N, true);

    ll ans = 0;
    REP(i, N){
        
        if (i < K){
            ans += score[str[i]];
            continue;
        }

        if (str[i - K] == str[i] && lst[i - K] == true){
            lst[i] = false;
        } else{
            ans += score[str[i]];
        }
    }

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

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

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;
}

int main(){
  int n, m, s=0, a=0;
  cin >> n >> m;
  for(int i=0; i<m; i++){
    cin >> a;
    s+=a;
  }
  if(s>n) cout << -1 << endl;
  else cout << n-s << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define INF 1000000000000
using ll = long long;


int main(){
  string s;
  cin >> s;
  int flag = 0;
  int l = (s.size()-1)/2;
  rep(i,l){
    if(s.at(i)!=s.at(l-1-i))flag = 1;
  }
  rep(i,l){
    if(s.at(i+l+1)!=s.at(s.size()-1-i))flag = 1;
  }
  rep(i,s.size()){
    if(s.at(i)!=s.at(s.size()-1-i))flag = 1;
  }
  if(flag)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    static int[] list;
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		String x = sc.next();
		
		// 計算
		//int result = 0;
		int cnt = 0;
		for(int i = 0; i < n; i++){
		    if(x.charAt(i) == '1') cnt++;
		}
		int mplus = 0;
		int tmp = 1;
		for(int i = 0; i < n; i++){
		    if(x.charAt(n-i-1) == '1'){
		        mplus += tmp%(cnt+1);
		        mplus %= cnt+1;
		    }
		    tmp *= 2;
		    tmp %= (cnt+1);
		}
		int mminus = 0;
		tmp = 1;
		for(int i = 0; i < n; i++){
		    if(cnt == 1) break;
		    if(x.charAt(n-i-1) == '1'){
		        mminus += tmp%(cnt-1);
		        mminus %= cnt-1;
		    }
		    tmp *= 2;
		    tmp %= (cnt-1);
		}
		int[] plus = new int[n+1];
		int[] minus = new int[n+1];
		tmp = 1;
		for(int i = 0; i < n; i++){
		    plus[n-i-1] = tmp%(cnt+1);
		    tmp *= 2;
		    tmp %= (cnt+1);
		}
		tmp = 1;
		for(int i = 0; i < n; i++){
		    if(cnt == 1) break;
		    minus[n-i-1] = tmp%(cnt-1);
		    tmp *= 2;
		    tmp %= (cnt-1);
		}

		list = new int[n+1];
		Arrays.fill(list, -1);
		list[0] = 0;
		list[1] = 1;
		for(int i = 0; i <= n; i++){
		    f(i);
		}
		
		for(int i = 0; i < n; i++){
		    int result = 0;
		    boolean flg = false;
		    if(x.charAt(i) == '1') flg = true;
		    
		    if(flg){
		        if(cnt != 1) result = list[(mminus-minus[i]+(cnt-1))%(cnt-1)] + 1;
		    }else{
		        result = list[(mplus+plus[i])%(cnt+1)] + 1;
		    }
		    System.out.println(result);
		}
		

		// 出力
		//System.out.println(result);
	}
	
	public static int f(int n) {
	    if(list[n] != -1) return list[n];
	    int m = Integer.bitCount(n);
	    list[n] = f(n%m)+1;
	    return list[n];
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
	
}



Measured memory_bytes: 58648