akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main(){
  int a[4],b[4];
  while(cin >>a[0]){
    for(int i=1; i<4; i++) cin >>a[i];
    for(int i=0; i<4; i++) cin >>b[i];
    int x = 0,y = 0;
    for(int i=0; i<4; i++){
      if(a[i] == b[i]){
	x++;
	a[i] = b[i] = -1;
      }
    }
    for(int i=0; i<4; i++){
      if(b[i] == -1) continue;
      for(int j=0; j<4; j++){
	if(b[i] == a[j]){
	  a[j] = -1;
	  y++;
	  break;
	}
      }
    }
    cout <<x<<" "<<y<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
struct Bipartite_Matching
{
  vector< vector< int > > graph;
  vector< int > match, alive, used;
  int timestamp;
 
  Bipartite_Matching(int n)
  {
    timestamp = 0;
    graph.resize(n);
    alive.assign(n, 1);
    used.assign(n, 0);
    match.assign(n, -1);
  }
 
  void add_edge(int u, int v)
  {
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
 
  bool dfs(int v)
  {
    used[v] = timestamp;
    for(int i = 0; i < graph[v].size(); i++) {
      int u = graph[v][i], w = match[u];
      if(alive[u] == 0) continue;
      if(w == -1 || (used[w] != timestamp && dfs(w))) {
        match[v] = u;
        match[u] = v;
        return (true);
      }
    }
    return (false);
  }
 
  int bipartite_matching()
  {
    int ret = 0;
    for(int i = 0; i < graph.size(); i++) {
      if(alive[i] == 0) continue;
      if(match[i] == -1) {
        ++timestamp;
        ret += dfs(i);
      }
    }
    return (ret);
  } 
};
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<int,int>;
using PP=pair<int,P>;
using Pl=pair<ll,ll>;
using PPl=pair<ll,Pl>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
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;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    using vp=vector<P>;
    vp a(n),b(n);
    REP(i,n){
        cin>>a[i].fi>>a[i].se;
    }
    REP(i,n){
        cin>>b[i].fi>>b[i].se;
    }
    Bipartite_Matching g(n*2);
    REP(i,n){
        REP(j,n){
            if(a[i].fi<b[j].fi&&a[i].se<b[j].se){
                g.add_edge(i,j+n);
            }
        }
    }
    cout<<g.bipartite_matching()<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e;
long long gcd(int x,int y){
	if(x%y==0) return y;
	else return gcd(y,x%y);
}
long long lcm(long long x,long long y){
	return x*y/gcd(x,y);
}
long long C(long long x){
	long long ret=x/c+x/d-x/e;
	return ret;
}
int main(){
	cin>>a>>b>>c>>d;
	e=lcm(c,d);
	cout<<(b-a+1)-C(b)+C(a-1)<<endl;
	return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

template <typename T>
struct RMQ
{
    int n;
    const T ex = 0; //初期値
    vector<T> dat; //tree本体
    RMQ(vector<T> v){
        int x = 1;
        int i;
        n = v.size();
        while(x < n) x <<= 1;
        n = x; 
        dat.resize(2*n-1, ex);
        for(i = 0;i < v.size();++i){
            dat.at(i + n - 1) = v.at(i);
        }
        for(i = n-2;i >= 0;--i){
            dat.at(i) = calculate(dat.at(2*i+1), dat.at(2*i+2));
        }
    }
    
    T calculate(T a, T b){
        return max(a, b); //最小値
    }
    
    void update(int ind, T x){
        ind += n - 1;
        dat.at(ind) = x;
        while(ind > 0){
            ind = (ind-1)/2;
            dat.at(ind) = calculate(dat.at(2*ind + 1), dat.at(2*ind + 2));
        }
    }
    
    T query(int a, int b){return query_sub(a, b, 0, 0, n);} //[a, b)
    T query_sub(int a, int b, int now, int l, int r){
        if(r <= a || b <= l) return ex;
        else if(a <= l && r <= b) return dat.at(now);
        else{
            T vl = query_sub(a, b, 2*now + 1, l, (l + r)/2);
            T vr = query_sub(a, b, 2*now + 2, (l + r)/2, r);
            return calculate(vl, vr);
        }
    }
};

int main()
{
    ll i,j;
    ll n,k;
    cin >> n >> k;
    ll INF = 3e5 + 1;
    vector<ll> ini(INF, 0);
    RMQ<ll> seg(ini);
    rep(i,n){
        ll a;
        cin >> a;
        ll left = max(a-k, 0ll);
        ll right = min(a + k + 1, INF);
        ll tmp = seg.query(left, right);
        seg.update(a, tmp + 1);
    }
    cout << seg.query(0, INF) << endl;

    return 0;
}

Measured memory_bytes: 16208
import java.util.Scanner;

class Main {
  private static int[] table;
  private static int m = 998244353;
  private static int[][] lrs;

  private static void calc(int x) {
    long sum = table[x - 1];
    if (x == 2) sum = 0;
    for (int i = 0; i < lrs.length; i++) {
      int s = lrs[i][0];
      int e = lrs[i][1];
      if (x - e > 1) {
        sum = (sum + m - table[x - e - 1]) % m;
      }
      if (x - s >= 1) {
        sum = (sum + table[x - s]) % m;
      }
    }
    table[x] = (int)sum;
  }

  public static void main(String[] args) {
    var sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    lrs = new int[k][2];
    for (int i = 0; i < k; i++) {
      lrs[i][0] = sc.nextInt();
      lrs[i][1] = sc.nextInt();
    }
    table = new int[n + 1];
    table[1] = 1;

    for (int i = 2; i <= n; i++) {
      calc(i);
    }
    var answer = table[n];
    System.out.println(answer);
  }
}

Measured memory_bytes: 37020
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<ll,P> PP;
int main() {
	int h, w;
	cin >> h >> w;
	int alf[26] = {};
	rep(i, h) {
		rep(j, w) {
			char m;
			cin >> m;
			alf[m - 'a']++;
		}
	}
	bool out=true;
		int c1 = 0; int c2 = 0;
	rep(i, 26) {
		if (alf[i] % 2) {
			c1++;
		}
		else if (alf[i] % 4 == 2) {
			c2++;
		}
	}
	if (h % 2 && w % 2) {
		
		if (c1 != 1)out = false;
		int d = h / 2; d += w / 2;
		if (c2 > d)out = false;
	}
	else if (h % 2) {
		if (c1)out = false;
		int d = w / 2;
		if (c2 > d)out = false;
	}
	else if (w % 2) {
		if (c1)out = false;
		int d = h / 2;
		if (c2 > d)out = false;
	}
	else {
		if (c1 || c2)out = false;
	}
	if (out)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
//const long long INF = 1LL << 60;
 int INF = 500000;
 int MAX = 1e5+10;
 ll mod = 998244353;

int main(){
  int n,x,d=0,cnt=1;
  cin >> n >> x;
  vector<int> l(n,0);
  rep(i,n) cin >> l[i];
  for(int i=0;i<n;i++){
    d+=l[i];
    if(d <= x)cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>

std::map<int, int> mp;

int nxt(int number) {
  int p = 1;
  while(p <= number) 
    p *= 2;
  return p;
}

int main() {
  int n;
  std::cin >> n;
  for(int i = 1; i <= n; i++) {
    int val;
    std::cin >> val;
    mp[val]++;
  }
  int result = 0;
  while(0 < mp.size()) {
    std::map<int,int>::iterator  it = mp.end();
    it--;
    if(it->second == 0)
      mp.erase(it);
    else {
      int oth = nxt(it->first) - it->first;
      if(oth == it->first) {
        if(1 < it->second) {
          it->second -= 2;
          result++;
        } else
          mp.erase(it);
      } else {
        if(0 < mp[oth]) {
          it->second--;
          mp[oth]--;
          result++;
        } else
          mp.erase(it);
      }
    }
  }
  std::cout << result;
  return 0;
}


Measured memory_bytes: 12912
#include<stdio.h>
#include<string.h>

int main(){
  int h,w;
  char s[101],c[300][300];
  scanf("%d %d",&h,&w);
  for(int i=0;i<h;i++){
    scanf("%s",s);
    printf("%s\n",s);
    printf("%s\n",s);
  }
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main()
{
  int n;
  cin >> n;
  int t[] = {1, 2, 4, 8, 16, 32, 64, 128}, i = 0;
  while (true) {
    if (n < t[i]) break;
    i++;
  }
  cout << t[i - 1] << endl;
  return 0;
}


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

using namespace std;

const int MD = 1e9 + 7;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, m, ans = 0;
    cin >> n >> m;
    if (n >= (m >> 1))
        ans = (m >> 1);
    if (n < (m >> 1))
        ans += n + ((m - (n << 1)) >> 2);
    cout << ans << "\n";
    return 0;
}

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

ll N, K;
const int MAX = 2.0e5 + 100;
ll H[MAX];

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >>  H[i];

    sort(H, H+N, greater<>());

    ll cnt =0;
    for (int i = 0; i < N; i++) {
        if (i >= K) cnt += H[i];
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int h,w,a,b;
    std::cin >> h >> w >> a >> b;
    int v[h][w];
    rep(i,h){
        rep(j,w){
            v[i][j] = ((i < b && j < a) || (i >= b && j >= a)) ? 0 :1;
        }
    }
    rep(i,h){
        rep(j,w){
            std::cout << v[i][j];
        }
        std::cout << std::endl;
    }
}

Measured memory_bytes: 5120
N=int(input())
A=[]
B=[]
for i in range(N):
    a=int(input())
    if a%10:
        A.append(a)
    else:
        B.append(a)
m=sum(A)+sum(B)
A.sort()
for i in range(len(A)):
    if m%10:
        print(m)
        exit()
    else:
        m-=A[i]
print(0)


Measured memory_bytes: 3060
n=int(input())
h=list(map(int,input().split()))
dp=[10**18 for i in range(n)]
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])


Measured memory_bytes: 13924
import numpy as np

N, K = map(int, input().split())
# N, K = 3, 2
di = np.zeros((K), dtype='int64')
Ai = np.ones((N),  dtype='int8')

for i in range(K):
    di[i] = int(input())
    Sunuke = map(int, input().split())
    for s in Sunuke:
        Ai[int(s)-1] = 0
        
print (Ai.sum())

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

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = 1LL<<60;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1]; for (int i = 0; i < n + 1; i++) { a[i] = 1; }for (int i = 2; i < n + 1; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

vector<vector<pair<int,int>>> Edge;
vector<int> node;

bool bellman_ford(int n,int s) {
	node = vector<int>(n,INF);
	node[s] = 0;
	REP (i,n) {
		REP (j,Edge.size()) {
			REP (k,Edge[j].size()) {
				int from = j,to = Edge[j][k].F;
				int cost = Edge[j][k].S;
				if (node[from] != INF && node[to] > node[from] + cost) {
					node[to] = node[from] + cost;
					if (i == n - 1 && to == n - 1) return true;
				}
			}
		}
	}
	return false;
}

int colors[3][30];
int colsum[3];

signed main() {
	int n, c;
	cin >> n >> c;
	int d[c][c];
	REP (i,c) {
		REP (j,c) {
			cin >> d[i][j];
		}
	}
	REP (i,n) {
		REP (j,n) {
			int x;cin >> x;
			colors[(i+j+2) % 3][x-1]++;
			colsum[(i+j+2) % 3]++;
		}
	}
	int ans = INF;
	REP (i,c) {
		REP (j,c) {
			REP (k,c) {
				if (i == j || j == k || k == i) continue;
				int tmp = 0;
				REP (l,c) {
					tmp += colors[0][l] * d[l][i] + colors[1][l] * d[l][j] + colors[2][l] * d[l][k];
				}
				ans = min(ans,tmp);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.Map as M
import Text.Printf

readInts :: IO [Int]
readInts = map read . words <$> getLine

main :: IO ()
main = do
  getLine
  xs <- readInts
  let (m0, m1, s) = solve xs
  printf "%d %d %d\n" m0 m1 s

solve :: [Int] -> (Int, Int, Int)
solve = (,,) <$> minimum <*> maximum <*> sum



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

int main()
{
    int n;
    int stack[10];
    int index=0;
    vector<int> r;
    while (scanf("%d",&n) != EOF)
    {
	if (n!=0)
	{
	    stack[index] = n;
	    index++;
	} else {
	    r.push_back(stack[index-1]);
	    index--;
	}
    }
    for (int i=0; i<r.size(); i++)
    {
	cout << r[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int a[200005];
bool ok[200005];
map<int,int> mp;
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n;i++)
	{
		mp[a[i]]=i+1;
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(i>0&&a[i]==a[i-1])continue;
		//if(i==1)cout<<"Y"<<endl;
		if(!ok[i]){
			if(a[i-1]!=a[i]&&a[i+1]!=a[i])ans++;
			for(int j=a[i+1]-(a[i+1]%a[i]);j<=a[n-1];j+=a[i])
			{//cout<<j<<endl;
				if(mp[j]!=0){
					
					ok[mp[j]-1]=true;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define LOG1(a)			  cerr<< #a << " = " << (a) << "\n"
#define LOG2(a, b)		  cerr<< #a << " = " << (a) << ", " << #b << " = " << (b) << "\n"
#define endl "\n"

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

const ll INF = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int nax = 1000000 + 10;

int n, arr[nax];

void sieve(int n)
{
    arr[1] = 1;
    arr[0] = 1;
    for(int i = 2; i <= n; i++)
    {
        if(arr[i] == 1) continue;
        for(int j = 2 * i; j <= n; j += i) arr[j] = 1;
    }
}
int main()
{
    ios::sync_with_stdio(0);
    n = 1e5 + 10;
    sieve(n);
    vi v;
    for(int i = 1; i <= n; i += 2)
    {
        int n1 = i;
        int n2 = (i + 1) / 2;
        if(arr[n1] == 0 && arr[n2] == 0)
            v.pb(i);
    }
    int q;
    cin >> q;
    while(q--)
    {
        int l, r;
        cin >> l >> r;
        int ans = (upper_bound(v.begin(), v.end(), r) - v.begin());
        int ans1 = (lower_bound(v.begin(), v.end(), l) - v.begin());
        cout << ans - ans1 << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc = new Scanner(System.in);
	int n;
	public void run(){
		int a = sc.nextInt();
		int b = sc.nextInt();
		solve(a, b);
	}
	public void solve(int a, int b){
		int ans = a;
		if(a > b){
			ans = a - 1;
		}
		System.out.println(ans);
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
	static class Pair {
        int first,second;
        public Pair(int a,int b) {
            this.first = a;
            this.second = b;
        }
    }	
}


Measured memory_bytes: 20948
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    int arr[N];
    for (int i = 0 ; i < N ; i++)
        cin >> arr[i];

    sort(arr , arr + N);
    long long ans = arr[N - 1];
    int j = N - 2;
    for (int i = N - 3 ; i >= 0; ){
        ans += arr[j] , --i;
        if (i >= 0)
            ans += arr[j] , --i;
        j--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v
#define NUM(x,v) (POSU(x,v)-POSL(x,v))
const ll INF=1e15+7;
const ll N = 200003;
ll n,a[N],y=0,x=0;
pair<ll,ll> ans[N];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	FOR(i,0,n){
		cin>>a[i];
	}
	ll x;
	x=1;
	FOR(i,0,n){
		ans[i].second=a[i];
		if(i%2==0){
			x++;
			ans[i].first=x;
		}else{
			x*=-1;
			ans[i].first=x;
			x*=-1;
			x++;
		}
	}
	sort(ans,ans+n);
	if(n%2==0)FOR(i,0,n){
		cout<<ans[i].second<<" ";
		
	}else FOR(i,0,n)cout<<ans[n-1-i].second<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 6912
#include <iostream>
#include <stdio.h>
#include <stdint.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <deque>

using namespace::std;

int ri()
{
	int x;
	scanf("%d", &x);

	return x;
}

int64_t ri64()
{
	int64_t x;
	scanf("%lld", &x);

	return x;
}

void wi(int x)
{
	printf("%d\n", x);
}

void wvi(vector<int> &v)
{
	for (int i = 0; i < v.size(); i++)
		printf("%d ", v[i]);
	printf("\n");
}

void dbg(string &str, int x)
{
	cout << str << ": ";
	wi(x);
}

void dbg(string &str, vector<int> &x)
{
	cout << str << ": ";
	wvi(x);
}

int main()
{
        int M = ri();
        int D = ri();

        int ans = 0;
        for (int m = 1; m <= M; m++)
        {
                for (int d = 1; d <= D; d++)
                {
                        int d10 = d / 10;
                        int d1 = d % 10;

                        if (d1 >= 2 && d10 >= 2 && (m == d1 * d10))
                                ans++;
                }
        }		

        wi(ans);

	return 0;
}


Measured memory_bytes: 256
s=input()
t=input()
dicST={}
dicTS={}

for i,j in zip(s,t):
  if (dicTS.get(j,0) != 0 and dicTS[j] != i) or \
    (dicST.get(i,0) != 0 and dicST[i] != j):
    print("No")
    break
  else:
    dicTS[j] = i
    dicST[i] = j
else:
  print("Yes")

Measured memory_bytes: 3632
import math

inp = input()
hw = inp.split(' ')
hi = int(hw[0])
wi = int(hw[1])

gusu_p = math.ceil(wi/2)
kisu_p = math.floor(wi/2)

gusu_num = math.ceil(hi/2)
kisu_num = math.floor(hi/2)

ret = (gusu_p*gusu_num) + (kisu_p * kisu_num)

if hi == 1:
    print('1')
elif	wi == 1:
    print('1')
else:
    print('{}'.format(ret))


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int H=sc.nextInt();
		int W=sc.nextInt();

		int h=sc.nextInt();
		int w=sc.nextInt();

		int[][] matrix=new int[H][W];

		for(int i=0;i<H;i++) for(int j=0;j<W;j++) matrix[i][j]=0;

		for(int i=0;i<h;i++) {
			for(int j=0;j<W;j++) matrix[i][j]=1;
		}

		for(int i=0;i<H;i++) {
			for(int j=0;j<w;j++) matrix[i][j]=1;
		}

		int count=0;

		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				if(matrix[i][j]==0) count++;
			}
		}

		System.out.println(count);

		sc.close();

	}

}


Measured memory_bytes: 22996
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    int M = sc.nextInt();
	    
	    int S[]= new int [M];
	    
	    for (int i = 0; i < M; i ++) {
			int ki = sc.nextInt();
			for (int j = 0; j < ki; j ++) {
				S[i] += 1 << (sc.nextInt() - 1);
				//System.out.println(Integer.toBinaryString(S[i]));
			}
		}
	    
	    
	    int p [] = new int [M];
	    for (int i = 0; i < M; i++) {
	    	p[i]=sc.nextInt();
	    }
	    
	    sc.close();
	    
	    long ans = 0;
	    for (int i = 0; i < Math.pow(2,N); i++) {
	    	boolean ok = true;
			for (int j = 0; j < M; j++) {
				if (Integer.bitCount(S[j] & i) % 2 != p[j]) {
					ok = false;
					break;
				}
			}
			if (ok) 
				ans ++; 
	    	
	    }
	    System.out.println(ans);
	    
	}

}


Measured memory_bytes: 22868
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl

int main() {
	lint N;
	cin >> N;
	rep(i, N) {
		string S;
		cin >> S;
		sort(S);
		int a = stoi(S);
		reverse(S);
		int b = stoi(S);
		cout << b - a << enld;
	}
}


Measured memory_bytes: 3056
#include<stdio.h>
#include<set>
using namespace std;
int n,x;
set<int> s;
int main()
{
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&x);
		if(s.find(x)!=s.end()) s.erase(x);
		else s.insert(x);
	}
	printf("%d\n",s.size());
	return 0;
}

Measured memory_bytes: 4864
X,N = list(map(int,input().split()))
p = list(map(int,input().split()))

p = set(p)

now = 10**29
for i in range(102):
    if not i in p:
        if abs(i-X)<now:
            now = abs(i-X)

if not X-now in p:
    print(X-now)
else:
    print(X+now)

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


def solve(cs):
    num_w = cs.count("W")
    num_r = cs.count("R")
    ref = "R" * num_r + "W" * num_w
    num_mismatches = sum(c != d for c, d in zip(cs, ref))
    res = num_mismatches // 2
    return res


def main():
    n = int(input())
    cs = input()
    res = solve(cs)
    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9664
# -*- coding: utf-8 -*-
import numpy as np

N = int(input())
A = [input() for _ in range(N)]

def count(a):
  if '.' in a:
    c = a.split('.')
    n = int(c[0]+c[1])
    count2 = count5 = 9 - len(c[1])
  else:
    n = int(a)
    count2 = count5 = 9
  while n%2 == 0 and count2<18:
    n //= 2
    count2 += 1
  while n%5 == 0 and count5<18:
    n //= 5
    count5 += 1
  return count2,count5

Z = np.zeros((19,19), dtype=np.int64)
answer = 0
for a in A:
  c2,c5 = count(a)
  answer += Z[18-c2,18-c5]
  Z[:c2+1,:c5+1] += 1

print(answer)

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

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

    string s;
    cin >> s;
    int n = s.size();
    int result = 0;
    for(int i = 0; i < n; i++) {
        if(s[i] != s[n - 1 - i])
            result++;
    }
    cout << result / 2 << "\n";
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N,K;
ll A[200005];
const ll max_n=1<<18;
ll dat1[2*max_n-1],dat2[2*max_n-1];
void add(ll a,ll b,ll x,ll k,ll l,ll r){
    if(a<=l&&r<=b){
        dat1[k]+=x;
    }
    else if(l<b&&a<r){
        dat2[k]+=(min(b,r)-max(a,l))*x;
        add(a,b,x,k*2+1,l,(l+r)/2);
        add(a,b,x,k*2+2,(l+r)/2,r);
    }
}
ll sum(ll a,ll b,ll k,ll l,ll r){
    if(b<=l||r<=a) return 0;
    else if(a<=l&&r<=b) return dat1[k]*(r-l)+dat2[k];
    else{
        ll res=(min(b,r)-max(a,l))*dat1[k];
        res+=sum(a,b,k*2+1,l,(l+r)/2);
        res+=sum(a,b,k*2+2,(l+r)/2,r);
        return res;
    }
}

int main(){

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

cin>>N>>K;
rep(i,N) cin>>A[i];
if(K>100){
	rep(i,N) cout<<N<<" ";
	cout<<endl;
	exit(0);
}
rep(k,K){
	memset(dat1,0,sizeof(dat1));
	memset(dat2,0,sizeof(dat2));
	rep(i,N){
		ll d=A[i];
		ll xleft=max((ll)0,i-d);
		ll xright=min(N-1,i+d);
		add(xleft,xright+1,1,0,0,N);
	}
	rep(i,N) A[i]=min(N,sum(i,i+1,0,0,N));
}
rep(i,N) cout<<A[i]<<" ";
cout<<endl;


}
	

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

typedef long long LL;
typedef pair <int,int> pii;

#define pb push_back
#define fi first
#define sc second
#define mp make_pair

const int MAXN=200005,MOD=1000000007,inv2=(MOD+1)/2;

int pw[MAXN],fac[MAXN],inv[MAXN],sb[MAXN],sw[MAXN];

void preprocess(int n)
{
	fac[0]=1;
	for (int i=1;i<=n;i++)
		fac[i]=(LL)fac[i-1]*i%MOD;
	inv[0]=inv[1]=1;
	for (int i=2;i<=n;i++)
		inv[i]=(LL)(MOD-MOD/i)*inv[MOD%i]%MOD;
	for (int i=2;i<=n;i++)
		inv[i]=(LL)inv[i-1]*inv[i]%MOD;
	pw[0]=1;
	for (int i=1;i<=n;i++)
		pw[i]=(LL)pw[i-1]*inv2%MOD;
}

int C(int n,int m)
{
	if (n<m)
		return 0;
	return (LL)fac[n]*inv[m]%MOD*inv[n-m]%MOD;
}

int main()
{
	#ifdef local
		freopen("read.txt","r",stdin);
	#endif
	int b,w;
	scanf("%d%d",&b,&w);
	preprocess(b+w);
	for (int i=1;i<=b+w;i++)
	{
		sb[i]=(sb[i-1]+(LL)pw[i]*C(i-1,b-1))%MOD;
		sw[i]=(sw[i-1]+(LL)pw[i]*C(i-1,w-1))%MOD;
	}
	for (int i=1;i<=b+w;i++)
	{
		//int p=(LL)pw[i-1]*C(i-1,w)%MOD;
		printf("%lld\n",(sw[i-1]+(1-sw[i-1]-sb[i-1]+MOD*2LL)*inv2)%MOD);
	}
	return 0;
}

Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
int main(){
	ll n; cin>>n;
	ll t;
	double x=0;
	for(int i=0;i<n;i++) cin>>t,x+=1.0/(double)t;
	x=1.0/x;
	cout<<fixed<<setprecision(12)<<x;

}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define SE second
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define mp make_pair
#define LL long long
#define LI long int
#define LLI long long int
#define REP(i,a,b) for(long long i=a;i<b;i++)
#define PER(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl

using namespace std;

int main() {
    string s;
    LL ans=0;
    cin>>s;
    string c =s.substr(0,1);
    for(int i=1;i<s.length();i++){
        if(c==s.substr(i,1));
        else{
            ans++;
            c=s.substr(i,1);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.*;
import java.lang.*;

public class Main {
	public void run() throws Exception {
		FastScanner sc = new FastScanner();
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] arr = new int[n];
		int corr = 0;
		int pen = 0;
		for (int i = 0; i<k; i++) {
			int num = sc.nextInt()-1;
			String s = sc.next();
			if (arr[num] == -1) continue;
			else if (s.equals("WA")) {
				arr[num] +=1;
			}
			else {
				corr++;
				pen+=arr[num];
				arr[num] = -1;
			}
		}
		System.out.println(corr + " " + pen);
	}
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 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 double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}

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

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

using namespace std;

int main(){
    int n, m, f, s, mid;
    cin >> n >> m;
    vector<unsigned char>::iterator itr;
    vector<unsigned char> checker(n, 0);
    for(int i = 0; i < m; i++){
        cin >> f >> s;
        if(f != 1 && s != n) 
            continue;
        if(f == 1){
            itr = checker.begin() + s;
            *itr |= 1;
        }else{
            itr = checker.begin() + f;
            *itr |= 2;
        }
        if(*itr == 3){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
        cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(vector<T> v){
  int n=v.size();
  rep(i,n-1)
    cout << v[i] << " ";
  cout << v[n-1] << "\n";
}
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
int order(int n){
  return (1+sqrt(8*n+1.1))/2;
}

int edge(int k){
  return k*(k-1)/2;
}

int main(){
  int n; cin >>n;
  int k=order(n);
  if(edge(k)!=n){
    print("No"); return 0;
  }
  print("Yes"); print(k);
  vector<vector<int>> vec(k);
  int cnt=1;
  rep(i,k){
    rep(j,i){
      vec[i].push_back(vec[j][i-1]);
    }
    rep(j,k-i-1){
      vec[i].push_back(cnt++);
    }
  }
  rep(i,k){
    print(k-1,vec[i]);
  }
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI 3.14159265358979

lli dp[100000];

bool compareHeight(const pair<lli,lli> &a,const pair<lli,lli> &b){
	if(a.first!=b.first)return a.first < b.first;
	else return a.second > b.second;
}

signed main(){

	lli n,t;
	cin>>n>>t;

	vector<pair<lli,lli>> me(n);

	REP(i,0,n)cin>>me[i].first>>me[i].second;

	sort(me.begin(),me.end(),compareHeight);

	if(DEBUG){
		REP(i,0,n)cout<<me[i].first<<" "<<me[i].second<<endl;
	}

	REP(i,0,100000)dp[i]=0;

	REP(i,0,n){
		for(lli j=t-1;j>=0;j--){
			if(dp[j]){
				if(DEBUG)cout<<"i="<<i<<" j="<<j<<"dp[j]="<<dp[j]<<endl;
				dp[j+me[i].first] = max(dp[j+me[i].first],dp[j] + me[i].second);
			}
		}
		dp[me[i].first] = max(dp[me[i].first],me[i].second);
	}

	lli ans = 0;
	REP(i,0,100000){
		if(DEBUG)if(dp[i])cout<<"i="<<i<<" dp[i]"<<dp[i]<<endl;
		ans = max(ans,dp[i]);
	}
	cout<<ans<<endl;
 
	return 0;
}

Measured memory_bytes: 1024
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;
using ll = long long int;

int main(){
    int n; cin >> n;
    vector<ll> a(n, 0);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=0; i<n-1; i++){
        a[i+1] += a[i];
    }
    unordered_map<ll, ll> um;
    for(int i=0; i<n; i++){
        um[a[i]]++;
    }
    ll ans = 0;
    for(auto& v:um){
        if(v.first == 0){
            ans += v.second;
        }
        if(v.second > 1){
            ans += v.second * (v.second-1) / 2;
        }
    }
    cout << ans << "\n";
    return 0;
}

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

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

  int ans = 0;

  for (int i = N; i > 0; i--) {
    if (i % 2 == 0) continue;
    int cnt = 0;
    for (int j = i; j > 0 ; j--) {
      if (i % j == 0) cnt++;
    }
    if (cnt == 8) ans++;
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str1 = scan.next();
		String str2 = scan.next();
		char[] arr1 = str1.toCharArray();
		char[] arr2 = str2.toCharArray();
		int len1 = arr1.length;
		int len2 = arr2.length;
		int[][] dp = new int[len1 + 1][len2 + 1];
		for(int i = 1 ; i <= len1; i++) {
			for(int j = 1 ; j <= len2 ; j++) {
				if(arr1[i - 1] == arr2[j - 1])
					dp[i][j] = dp[i-1][j-1] + 1;
				else dp[i][j] = Math.max(dp[i][j-1], dp[i-1][j]);
			}
		}
		StringBuilder sb = new StringBuilder();
		int i = len1 , j = len2;
		while(i > 0 && j > 0) {
			if(arr1[i-1] ==arr2[j - 1]) {
				sb.append(arr1[i - 1]);
				i--;
				j--;
			}
			else {
				if(dp[i-1][j] > dp[i][j-1]) {
					i--;
				}
				else {
					j--;
				}
			}
		}
		System.out.println(sb.reverse());
	}
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

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

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    ll lb = 0, ub = 1LL<<31;
    while(ub-lb>1) {
        ll mid = (lb+ub)/2;
        // cout << lb << " " << mid << " " << ub << endl;

        vector<ll> x(n);
        x[0] = mid;
        REP(i, n) {
            if(i == n-1) {
                if(x[i] + mid == a[n-1]*2) {
                    REP(j, n) {
                        cout << x[j] << (j==n-1?'\n':' ');
                    }
                    return 0;
                } else if(x[i] + mid > a[n-1]*2) {
                    ub = mid;
                } else {
                    lb = mid;
                }
            } else {
                x[i+1] = a[i]*2 - x[i];
            }
        }
    }

    vector<ll> x(n);
    x[0] = 0;
    REP(i, n) {
        if(i == n-1) {
            if(x[i] + 0 == a[n-1]*2) {
                REP(j, n) {
                    cout << x[j] << (j==n-1?'\n':' ');
                }
                return 0;
            }
        } else {
            x[i+1] = a[i]*2 - x[i];
        }
    }

    assert(false);

    return 0;
}


Measured memory_bytes: 2928
def explore(curlis,visited):
    global can
    if can==1 or curlis==[]:
        return
    i,j,k = curlis.pop(0)
    visited[i][j]=True
    if i == h-1 and j == w-1:
        print(k)
        visited.append("G")
        can=1
    for x,y in move:
        if check(i,j,x,y):
            visited[i+x][j+y]=True
            curlis.append([i+x,j+y,k+1])
    explore(curlis,visited)
		
		
def check(i,j,x,y):
    if 0<=i+x<h and 0<=j+y<w:
        if not visited[i+x][j+y]:
            if x==1:
                if orimap[2*i+1][j]:
                    return False
            if x==-1:
                if orimap[2*i-1][j]:
                    return False
            if y==1:
                if orimap[2*i][j]:
                    return False
            if y==-1:
                if orimap[2*i][j-1]:
                    return False
            return True
    return False

import sys
sys.setrecursionlimit(10000000)
move = ((0,1),(1,0),(-1,0),(0,-1))
w,h = map(int,input().split())
while w!=0 and h!=0:
    can=0
    orimap = []
    visited = []
    for _ in range((h*2)-1):
        if _ % 2==0:
            orimap.append(list(map(int,input().split()))+[1])
            visited.append([False]*w)
        elif _ % 2==1:
            orimap.append(list(map(int,input().split())))
    orimap.append([1]*w)
    explore([[0,0,1]],visited)
    if not can:
        print(0)
    w,h=map(int,input().split())
	



Measured memory_bytes: 6524
def 解():
    iN,iK = [int(_) for _ in input().split()]
    #aA = [int(_) for _ in input().split()]
    dA = {}
    def addD(d,a):
        if a in d:
            d[a] += 1
        else:
            d[a] = 1
    for a in [int(_) for _ in input().split()]:
        addD(dA,a)
    aList = sorted(list(dA.items()),key=lambda x:x[1])
    print(sum(map(lambda x:x[1],aList[0:len(aList)-iK])))
解()


Measured memory_bytes: 39064
#include<bits/stdc++.h>
using namespace std;
int main (){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int64_t a,b,c,d;
	cin>>a>>b>>c>>d;
	int64_t maxi=b*d;
	maxi=max(maxi,a*c);
	maxi=max(maxi,b*c);
	maxi=max(maxi,a*d);
	cout<<maxi;
}

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

int main() {
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    int a[n];
    a[0]=0;
    for(int i=1;i<n;i++){
        a[i]=a[i-1];
        if(s[i-1]=='A'&&s[i]=='C') a[i]++;
    }
    for(int i=0;i<q;i++){
        int l,r;
        cin >> l >> r;
        cout << a[r-1]-a[l-1] << endl;
    }
}

Measured memory_bytes: 1536
n = int(input())
b = list(map(int, input().split()))
ans = []
tmp = 0
while len(b) != tmp and len(b) > 0:
    tmp = len(b)
    for i in reversed(range(len(b))):
        if b[i] == i+1:
            b.pop(i)
            ans.append(i+1)
            break

if len(b) > 0:
    print(-1)
else:
    for x in reversed(ans):
        print(x)   

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define strall(v) (v).cbegin(),(v).cend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> a(3);
  rep(i,3) cin >> a[i];
  string s;
  cin >> s;
  vector<int> ctoi(256);
  //''はintにキャストされる
  ctoi['r'] = 2;
  ctoi['c'] = 0;
  ctoi['p'] = 1;
  int ans = 0;
  rep(i,k){
    vector<int> x;
    for(int j=i;j<n;j+=k){//勝ち負けが関係あるのはkこ間隔の手のみ
      x.push_back(ctoi[s[j]]);
    }
    vector<int> dp(2);
    int pre = -1;
    for(int nx:x){
      vector<int> p(2);//一個前
      swap(dp,p);
      dp[0] = max(p[0],p[1]);//この時点では勝っても負けてもいい
      if(pre == nx){ //前の手と同じ
        dp[1] = p[0]+a[nx];//今勝ちたい，p[0](前回負け)
      }else{
        dp[1] = max(p[0],p[1]) + a[nx];//前と違う，連続で勝つ
      }
      pre = nx;//前の手を記録
    }
    ans += max(dp[0],dp[1]);//負けたほうがいいのか，勝った方がいいのか
  }
  cout << ans << endl;
}

Measured memory_bytes: 1020
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std; 

int main(){
    int n;
    scanf("%d",&n);
    int a[n];
    for(int i=0; i<n; i++) scanf("%d", a+i);
    vector<int> b;
    for(int i=0; i<n; i++){
        if(i%2==0) b.push_back(a[i]);
        else b.insert(b.begin(), a[i]);
    }
    if(n%2!=0) reverse(begin(b), end(b));
    printf("%d", b[0]);
    for(int i=1; i<n; i++) printf(" %d", b[i]);
    printf("\n");
}

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

#define mod 1000000007
#define ll long long

ll mpow(ll x, ll y)
{
  ll res=1;
  while(y)
  {
    if(y&1)
      res=res*x%mod;
    x=x*x%mod;
    y>>=1;
  }
  return res;
}

vector<ll> tfact(1e7+1);

void fact(ll n)
{
  for(ll i=0;i<=n;i++)
  {
	if(i==0)
      tfact[i]=1;
    else
      tfact[i]=tfact[i-1]*i%mod;
  }
}

ll comb(ll n, ll k)
{
  return tfact[n]*mpow(tfact[k],mod-2)%mod*mpow(tfact[n-k],mod-2)%mod;
}

int main(){
  ll h,w,n;
  cin>>h>>w>>n;
  fact(h+w+10);
  vector<pair<ll,ll>> g(n+1);
  for(ll i=0;i<n;i++)
  {
    ll x,y;
    cin>>y>>x;
    y--,x--;
    g[i]={y,x};
  }
  g[n]={h-1,w-1};
  vector<ll> dp(n+1);
  sort(g.begin(),g.end());
  for(ll i=0;i<=n;i++)
  {
    ll y=g[i].first;
    ll x=g[i].second;
    dp[i]=comb(y+x,y);
    for(ll j=0;j<i;j++)
    {
      ll dx=g[i].first-g[j].first;
      ll dy=g[i].second-g[j].second;
      if(dx>=0&&dy>=0)
        dp[i]=(dp[i]-dp[j]*comb(dx+dy,dy)%mod+mod)%mod;
    }
  }
  cout<<dp[n];
  return 0;
  
}


Measured memory_bytes: 78464
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    char a;
    cin >> a;
    if('a'<=a && a<= 'z') cout << 'a';
    else cout << 'A' << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
string xuan(string a){
	char c=a[a.size()-1];
	for(int i=a.size()-1;i>0;i--)
	a[i]=a[i-1];
	a[0]=c;
	return a;
}
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
	string a,b;
	cin>>a>>b;
	for(int i=0;i<a.size();i++){
		if(a==b){
			cout<<"Yes\n";
			return 0;
		}
		a=xuan(a);
	}
	cout<<"No\n";
    return 0;
}


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

using namespace std;
int main()
{
	int n;
	cin>>n;
	int c[n];
	int a[n];
	c[0]=0;
	for(int i=1;i<n;i++)
	{
		cin>>a[i];
		c[i]=0;
	}
	for(int i=1;i<n;i++)
	{
		c[a[i]-1]++;
	}for(int i=0;i<n;i++)
	{
		cout<<c[i]<<endl;
	}
}


Measured memory_bytes: 5156
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#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(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	for (int t; cin >> t&&t;) {
		int n; cin >> n;
		int tt = 0;
		rep(i, 0, n) {
			int s, f; cin >> s >> f;
			tt += f - s;
		}
		if (tt >= t)cout << "OK" << endl;
		else cout << t - tt << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
def f(s):
    return abs(int(s))

def cul(x,X):
    dic={0:1}
    for i in range(len(x)):
        tmp={}
        for j in dic:
            tmp[j+x[i]]=1
            tmp[j-x[i]]=1
        dic=tmp
    if X in dic: return True
    else: return False

s=input()
X,Y=map(int,input().split())
x,y=[],[]
d,tmp=0,0
for i in range(len(s)):
    if s[i]=="T":
        if tmp!=0:
            if d==0: x.append(tmp)
            else: y.append(tmp)
        d^=1
        tmp=0
        
    else: tmp+=1
if tmp!=0:
    if d==0: x.append(tmp)
    else: y.append(tmp)


if s[0]=="F": X=abs(X-x.pop(0))
Y=abs(Y)


print("Yes" if cul(x,X) and cul(y,Y) else "No")

Measured memory_bytes: 3868
#include <bits/stdc++.h>
#define elif else if
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define INF 0x3f3f3f3f
typedef long long ll;

using namespace std;

typedef unsigned pnt;
const char ori='a',fin='z';
const pnt csize=fin-ori+1;
const int maxn=110000;
struct SAM{

	struct node{
		pnt next[csize],fa;
		int len,cnt,firstpos,lastpos;
	}data[maxn<<1];
	pnt l;
	SAM(){memset(this,0,sizeof(*this));}
	
	void init(const string&s){
		pnt lst=0;
		data[0].fa=-1;
		for(int i=0;i<s.length();++i){
			char c=s[i]-ori;
			
			data[++l].len=data[lst].len+1;
			pnt p=lst;lst=l;data[l].cnt=1;data[l].firstpos=data[l].len-1;
			for(;(~p)&&!data[p].next[c];p=data[p].fa)data[p].next[c]=l;
			if(!~p)data[l].fa=0;
			else{
				pnt q=data[p].next[c];
				if(data[q].len==data[p].len+1)data[l].fa=q;
				else{
					data[++l]=data[q];data[l].cnt=0;
					data[l].len=data[p].len+1;
					data[q].fa=data[l-1].fa=l;
					for(;(~p)&&data[p].next[c]==q;p=data[p].fa)data[p].next[c]=l;
				}
			}
		}
		buildCnt();
	}
	
	pnt find(const string&s){
		pnt now=0;
		for(pnt i=0;i<s.length();++i){
			if(!data[now].next[s[i]-ori])return 0;
			now=data[now].next[s[i]-ori];
		}
		return now;
	}
	
	
    void buildCnt(){
		vector<int>a(l+1),b(l+1);
		for(int i=0;i<=l;i+=1)++a[data[i].len];
		for(int i=1;i<=l;i+=1)a[i]+=a[i-1];
		for(int i=0;i<=l;i+=1)b[--a[data[i].len]]=i;
		
		for(int i=l;i;--i){
			data[data[b[i]].fa].cnt+=data[b[i]].cnt;
			data[b[i]].lastpos=max(data[b[i]].lastpos,data[b[i]].firstpos);
			data[data[b[i]].fa].lastpos=max(data[data[b[i]].fa].lastpos,data[b[i]].lastpos);
		}
        data[0].cnt=0;
    }
    
	ll getAns(){
		ll ans=0;
		for(int i=1;i<=l;i+=1){
			ans=max(ans,min(data[i].lastpos-data[i].firstpos,data[i].len));
		}
		return ans;
	}
	
	void print(){
		cout<<"Next DAG:"<<endl;
		for(int i=0;i<=l;i+=1){
			cout<<i<<":";
			for(char c=0;c<csize;c+=1){
				if(data[i].next[c])cout<<char(ori+c)<<":"<<data[i].next[c]<<' ';
			}
			cout<<endl;
		}
		cout<<"parent tree:"<<endl;
		for(int i=1;i<=l;i+=1){
			cout<<i<<':'<<data[i].fa<<' ';
		}
		cout<<endl;
		cout<<"cnt:"<<endl;
		for(int i=1;i<=l;i+=1){
			cout<<i<<':'<<data[i].cnt<<' ';
		}
	}
	
}dag;


int main (/*int argc, char const* argv[]*/){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int n;cin>>n;
	string s;cin>>s;
	dag.init(s);
	cout<<dag.getAns()<<'\n';
//	dag.print();
//	for(int i=1;i<=n;i+=1){
//		string s;cin>>s;
//		tree.append(s);
//	}
//	int q;cin>>q;
//	for(int i=1;i<=q;i+=1){
//		string s;cin>>s;
//		if(tree.find(s))cout<<"Yes"<<endl;
//		else cout<<"No"<<endl;
//	}
	return 0;
}


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

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> X(H, 0), Y(W, 0);
  set<pair<int, int>> S;
  for (int i = 0; i < M; i++) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    X.at(h)++;
    Y.at(w)++;
    pair<int, int> P = make_pair(h, w);
    S.insert(P);
  }
  int Mx = 0, My = 0;
  for (int i = 0; i < H; i++) Mx = max(Mx, X.at(i));
  for (int i = 0; i < W; i++) My = max(My, Y.at(i));
  vector<int> Kx, Ky;
  for (int i = 0; i < H; i++) {
    if (X.at(i) == Mx) Kx.push_back(i);
  }
  for (int i = 0; i < W; i++) {
    if (Y.at(i) == My) Ky.push_back(i);
  }
  int d = -1;
  for (int i = 0; i < Kx.size(); i++) {
    for (int j = 0; j < Ky.size(); j++) {
      pair<int, int> P = make_pair(Kx.at(i), Ky.at(j));
      if (!(S.count(P))) {
        d = 0;
        break;
      }
    if (d == 0) break;
    }
  }
  cout << Mx + My + d << endl;
}

Measured memory_bytes: 23848