akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i+2 < n; i++) {
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
    }
    cout << ans << '\n';
}



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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const string YES = "Yes";
const string NO = "No";
const ll mod = 1e9+7;



int main(){
	cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    string s,t; cin >> s >> t;
    string ans;
    REP(i,n){
        ans += s[i];
        ans += t[i];
    }
    cout << ans;
    return 0;
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    map<int,int> a;
    rep(i,n){
      int x;
      cin>>x;
      a[x]++;
    }
    //sort(begin(a),end(a));
    int ans=0;
    int cnt=0;
    FOR(i,1,100010){
      if(ans<a[i-1]+a[i]+a[i+1]){
        ans=a[i-1]+a[i]+a[i+1];
      }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4992
using System;

namespace ALDS1_4D{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var N = sr.Next<int>();
            var K = sr.Next<int>();
            var W = sr.Next<int>(N);

            Func<int, int> check = p =>{
                var now = 0;
                var cnt = 1;
                foreach(var w in W){
                    if(w > p) return int.MaxValue;
                    if(now + w > p){
                        now = w;
                        cnt++;
                    } else{
                        now += w;
                    }
                }
                return cnt;
            };

            var left = 0;
            var right = int.MaxValue;
            while(left < right){
                var mid = (left + right) / 2;
                if(check(mid) <= K){
                    right = mid;
                }
                if(check(mid) > K){
                    left = mid + 1;
                }
            }

            Console.WriteLine(left);
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = Console.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }
    }
}

Measured memory_bytes: 11048
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

using namespace std;
typedef long long ll;

ll vs[100000+5];

int main(void) {
  int n;
  scanf("%d", &n);
  ll res = 0;
  REP(i, n) {
    scanf("%lld", &vs[i]);
    res += i % 2 == 0 ? vs[i] : -vs[i];
  }
  REP(i, n) {
    printf("%lld%c", res, i == n-1 ? '\n' : ' ');
    res = 2*vs[i] - res;
  }
  return 0;
}


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

int n,s,y,x,i;
int d[12][12],b[12][12],a[12][12];
int dx[] = { 0,0,0,1,-1};
int dy[] = {-1,1,0,0, 0};

void flip(int x, int y)
{
	a[y][x] = 1;
	for(int i=0; i<5; i++)
	{
		b[y+dy[i]][x+dx[i]] = 1-b[y+dy[i]][x+dx[i]];
	}
}

int main()
{
	cin >> n;
	while(n--)
	{
		for(y=1; y<=10; y++)
		for(x=1; x<=10; x++)
		{
			cin >> d[y][x];
		}
		for(i=0; i<1024; i++)
		{
			memset(a,0,sizeof(a));
			memcpy(b,d,sizeof(d));

			for(y=1,x=1; x<=10; x++)
			{
				if((i>>(x-1))&1) flip(x,y);
			}

			for(y=2; y<=10; y++)
			for(x=1; x<=10; x++)
			{
				if(b[y-1][x]) flip(x,y);
			}

			for(y=10,x=1,s=0; x<=10; x++)
			{
				s+=b[y][x];
			}

			if(s==0) break;
		}

		for(y=1; y<=10; y++)
		{
			for(x=1; x<=10; x++)
			{
				cout << a[y][x] << (x==10?"":" ");
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long x = sc.nextLong();
		Bargar b = new Bargar(n);
		System.out.println(b.getAmount(x));
    }
    
    static class Bargar {
        int size;
        long count;
        long paties;
        
        Bargar inside;
        
        public Bargar (int size) {
            this.size = size;
            if (size == 0) {
                count = 1;
                paties = 1;
            } else {
                inside = new Bargar(size - 1);
                count = inside.count * 2 + 3;
                paties = inside.paties * 2 + 1;
            }
        }
        
        public long getAmount(long total) {
            if (size == 0) {
                return 1;
            }
            long ans = 0;
            total--;
            if (total <= 0) {
                return ans;
            }
            if (total <= inside.count) {
                return inside.getAmount(total);
            }
            ans += inside.paties;
            total -= inside.count;
            if (total <= 0) {
                return ans;
            }
            total--;
            ans++;
            if (total <= 0) {
                return ans;
            }
            return ans + inside.getAmount(total);
        }
    }
}



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

using namespace std;

int n,k;

void solve(){
    int i,j;
    string str;
    cin >> n >> k;
    vector<int> p(n);
    for(i = 0;i < n;i++) cin >> p[i];
    set<int> s;
    for(i = 0;i < k;i++) s.insert(p[i]);
    long long ans = 1;
    for(;i < n;i++){
        ans++;
        if(*s.begin() == p[i-k] && *s.rbegin() < p[i]){
            ans--;
        }
        s.erase(p[i-k]);
        s.insert(p[i]);
    }
    vector<int> b(n,0);
    for(i = 0;i < n-1;i++){
        if(p[i] > p[i+1]) b[i] = 1;
    }
    for(i = 0,j = 0;i < n-1;i++){
        if(b[i] == 1){
            j = i+k-1;
        }
        else if(i < j){
            b[i] = 1;
        }
    }
    j = 0;
    int f = 0;
    for(i = k-2;i < n-1;i++){
        if(b[i] == 0 && f == 0){
            j++;
            f = 1;
        }
        if(b[i] == 1) f = 0;
    }
    if(j > 1) ans -= j-1;
    cout << ans << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
 vector<int> vi[maxii];
 vector<int>:: iterator child;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


int arr[maxii];
int arr2[maxii];
bool check[maxii];

bool dfs(int node,int c)
{
    check[node]=true;
    arr2[node]=c;
    for(int child=0;child<vi[node].size();child++)
    {
        if(check[vi[node][child]]==false)
        {
            if(dfs(vi[node][child],c^1)==false)
            {
                return false;
            }
        }
        else if(arr2[node]==arr2[vi[node][child]])
        {
            return false;
        }
        //else if()
    }
    return true;
}

int main()
{
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    if(n<=k)
    {
        cout<<n*x;
    }
    else
    {
        int res=k*x;
        int res1=n-k;
        res1=res1*y;
        cout<<res+res1;
    }
}






Measured memory_bytes: 5956
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
#define PI  acos(-1)
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
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); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  long double a,b;cin>>a>>b;
  int ans=a*b;
  print(ans);

}


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

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

	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0) {
			ans += (s[i] == 'p' ? -1 : 0);
		}
		else {
			ans += (s[i] == 'g' ? 1 : 0);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy
setrecursionlimit(10**6)

#@pysnooper.snoop()
n=int(stdin.readline().rstrip())
a=[int(stdin.readline().rstrip()) for _ in range(n)]
ans=0
mi=a[0]
ma=-(10**10)
for i in range(1,n):
    ma=max(ma,a[i]-mi)
    mi=min(mi,a[i])
print(ma)


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

#define int long long

using namespace std;

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

//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    int n, cnt = 0;
    string s;
    cin >> n >> s;
    int l = 0, r = n-1, x, c = 0;

    while(l < r) {
        if(s[l] == 'R')
            l++;
        else if(s[r] == 'W')
            r--;
        else {
            s[l] = 'R', s[r] = 'W', l++, r--, cnt++;
        }
    }

    cout << cnt;

    return 0;
}


Measured memory_bytes: 3700
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  ll a, b, n;
  cin >> a >> b >> n;
  if(b <= n){
    ll tmp = (a * (b-1)) / b;
    cout << tmp << endl;
  }else{
    ll tmp = (a * n) / b;
    cout << tmp << endl;
  }
  return 0;
}


Measured memory_bytes: 3176
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>
#include <atcoder/all>


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

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


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


















ll op(ll a, ll b){
    return a + b;
}

ll e(){
    return 0;
}

ll mapping(ll a, ll b){
    return a + b;
}

ll composition(ll a, ll b){
    return a + b;
}

ll id(){
    return 0;
}

int main(){
    ll n, Q;
    cin >> n >> Q;
    vector<ll> a(n);
    lazy_segtree<ll, op, e, ll, mapping, composition, id> tree(a);
    REP(i, n){
        cin >> a[i];
        tree.set(i, a[i]);
    }
    REP(i, Q){
        ll q;
        cin >> q;
        if(q == 0){
            ll p, x;
            cin >> p >> x;
            tree.set(p, tree.get(p) + x);
        }
        else{
            ll l, r;
            cin >> l >> r;
            cout << tree.prod(l, r) << endl;
        }
    }
}

Measured memory_bytes: 20556
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define INF 1e9
#define MOD 1000000007
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main(void){
    while(1){
        int n,x;cin>>n>>x;
        if(n+x==0)return 0;
        ll ans=0;
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                //if(i==j)continue;
                for(int k=j+1;k<=n;k++){
                    //if(i==k||j==k)continue;
                    if(i+j+k==x)ans++;
                }
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

int main()
{
  int k,f,s,sum=0;
  cin>>k;
  for(int a=1;a<=k;a++){
      for(int b=1;b<=k;b++)
      {
          for(int c=1;c<=k;c++)
          {
                 f=gcd(a,b);
                 s=gcd(f,c);
                 sum=sum+s;
          }
      }
  } 
  cout<<sum;
}
  

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b;
    cin >> a >> b;
    if(b % a == 0)
        cout << a + b;
    else
        cout << b - a;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int H,W;
int A[200];
int dp[200][200];
main()
{
	cin>>H>>W;
	for(int i=0;i<W;i++)for(int j=0;j<W;j++)dp[i][j]=-1e9;
	dp[0][1]=0;
	for(int _=0;_<H;_++)
	{
		for(int i=0;i<W;i++)cin>>A[i];
		for(int i=0;i<W;i++)for(int j=i+1;j<W;j++)
		{
			dp[i][j]+=A[i];
			if(i+1<j)dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
		}
		for(int i=0;i<W;i++)for(int j=i+1;j<W;j++)
		{
			dp[i][j]+=A[j];
			if(j+1<W)dp[i][j+1]=max(dp[i][j+1],dp[i][j]);
		}
	}
	int ans=0;
	for(int i=0;i+1<W;i++)ans=max(ans,dp[i][W-1]);
	cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <numeric>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

int main(void){
  int n;
  cin >> n;
  int m = 0;
  int s = 0;
  rep(i, n) {
    int tmp;
    cin >> tmp;
    if (m < tmp) m = tmp;
    s += tmp;
  }
  if (s > 2 * m) cout << "Yes";
  else cout << "No";
  return 0;
}


Measured memory_bytes: 888
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 15
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

int main(void) {
  int n, m, x;
  scanf("%d %d %d", &n, &m, &x);
  int c[MAX], a[MAX][MAX];
  rep(i, 0, n) {
    scanf("%d", &c[i]);
    rep(j, 0, m) scanf("%d", &a[i][j]);
  }

  int ans = INF;
  for (int i = 0; i < (1 << n); i++) {
    int money = 0;
    int sum_a[MAX] = {0};
    for (int j = 0; j < n; j++) {
      int buy = (i >> j) & 1;
      money += c[j] * buy;
      for (int k = 0; k < m; k++) sum_a[k] += a[j][k] * buy;
    }
    int ok = 1;
    for (int k = 0; k < m; k++) {
      if (sum_a[k] >= x) continue;
      ok = 0;
      break;
    }
    if (ok) ans = min(money, ans);
  }
  printf("%d\n", ans == INF ? -1 : ans);
  return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
    
    #define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
    #define ll long long int
    #define ull unsigned long long int
    #define ld long double
    #define sb __builtin_popcount
    #define vi vector<int>
    #define vl vector<ll>
    #define vc vector<char>
    #define ii pair<int, int>
    #define pq priority_queue<ii, vector<ii>, greater<ii>>
    #define vii vector<ii>
    #define viii vector<tuple<ll, ll, ll>>
    #define sz(a) int((a).size())
    #define f(a, b) for (int i = a; i < b; i++)
    #define fr(a, b) for (int i = a - 1; i >= b; i--)
    #define tr(x, m) for (auto x : m)
    #define in(a, b) (b.find(a) != string::npos)
    #define minin(a) *min_element(all(a))
    #define maxin(a) *max_element(all(a))
    #define bs(l, h, k) equal_range(l, h, k);
    #define X first
    #define Y second
    #define fill(a, x) memset(a, x, sizeof(a))
    #define pb push_back
    #define pf push_front
    #define mp make_pair
    #define all(v) v.begin(), v.end()
    #define rall(v) reverse(v.begin(), v.end())
    #define unq(v) v.erase(unique(all(v)), v.end())
    #define el "\n"
    #define mx3(a, b, c) max(max(a, b), c)
    #define S(v) accumulate(all(v), (ll)0)
    #define IP(v1, v2) inner_product(all(v1), v2.begin(), (ll)0)
    
    const long double PI = atan(1.0) * 4.0;
    const ll MOD = 1e9 + 7;
    const ll INF = 1e18;
    const ld EPS = 0.0000001;
    #define N 100005   
        
        int main() {
            fio;
            ll m,n;
            cin>>m>>n;
            ll ans= m*(m-1) + n*(n-1);
            ans/=2;
            cout<<ans<<el; 
            return 0;
        }


Measured memory_bytes: 256
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N = int(input())
S = input()
ans = S[1:N].count('E')
tmp = ans
for i in range(N-1):
    if S[i] == 'W':
        tmp += 1
    if S[i + 1] == 'E':
        tmp -= 1
    ans = min(tmp, ans)
print(str(ans))


Measured memory_bytes: 3780
while True :
    n = int(input())
    if n == 0 :
        break
    
    card = list(input())
    
    maisu = [0] * (n + 1)
    x = 0
    
    for i in range(100) :
        if card[i] == 'M' :
            maisu[x] += 1
        elif card[i] == 'S' :
            maisu[n] += maisu[x] + 1
            maisu[x] = 0
        elif card[i] == 'L' :
            maisu[x] += maisu[n] + 1
            maisu[n] = 0
            
        x += 1
        if x == n :
            x = 0
    ba = maisu.pop()
    maisu.sort()
    
    for i in range(n) :
        print(maisu[i], end=" ")
    print(ba)


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

const int maxn=1000005;
const int mod=998244353;
int n,m,ans;
int fac[maxn],ifac[maxn],pw4[maxn];

int binom(int a,int b){
	if(a<0||b<0||a<b)return 0;
	return 1LL*fac[a]*ifac[b]%mod*ifac[a-b]%mod;
}

void solve(int n,int m){
	for(int i=0;i<=min(n,m);i++){
		int coef;
		if(n-1==m)coef=i==n-1?1:0;
		else if(n-1>m){
			coef=(binom(n-1-(i+1)+m-i,m-i)+mod-binom(n-1-i+m-(i+1),m-(i+1)))%mod;
			ans=(ans+1LL*coef*binom(2*i,i)%mod*(n-1+m-i-i))%mod;
		}
		else coef=(binom(n-1-i+m-(i+1),m-(i+1))+mod-binom(n-1-(i+1)+m-i,m-i))%mod;
		ans=(ans+1LL*coef*(1LL*binom(2*i,i)*(2*i+1)%mod+pw4[i])%mod*(mod+1)/2)%mod;
	}
}

int main(){
	scanf("%d%d",&n,&m);
	fac[0]=ifac[0]=fac[1]=ifac[1]=1;
	for(int i=2;i<=n+m;i++){
		fac[i]=1LL*fac[i-1]*i%mod;
		ifac[i]=1LL*ifac[mod%i]*(mod-mod/i)%mod;
	}
	pw4[0]=1;
	for(int i=1;i<=n+m;i++){
		ifac[i]=1LL*ifac[i-1]*ifac[i]%mod;
		pw4[i]=4LL*pw4[i-1]%mod;
	}
	solve(n,m);
	solve(m,n);
	for(int i=0;i<=min(n,m);i++)ans=(ans+1LL*binom(2*i-1,i-1)*binom(n-i+m-i,n-i))%mod;
	ans=1LL*ans*ifac[n+m]%mod*fac[n]%mod*fac[m]%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 15536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] nums = br.readLine().split(" ");
		int a = Integer.parseInt(nums[0]);
		int b = Integer.parseInt(nums[1]);

		System.out.println(Math.max(a + b, Math.max(a - b, a * b)));

	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int main() {
    int N;
    cin >> N;
    map<string, int> mp;
    int M = 0;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        mp[s]++;
        M = max(M, mp[s]);
    }
    set<string> st;
    for (auto ite = mp.begin(); ite != mp.end(); ++ite) {
        if (ite->second == M) st.insert(ite->first);
    }
    for (auto ite = st.begin(); ite != st.end(); ++ite) {
        cout << *ite << endl;
    }
    return 0;
}

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

using namespace std;

int main()
{int N ; cin >> N;
 vector<int> A(N+2,0);//A[0],A[N+1]を発着地点とする
 for(int i = 1; i <= N;i++)
 {cin >> A[i];}
 
 int total = 0;
 
 for(int i = 0; i <= N; i++)
 {total += abs(A[i+1] - A[i]);}
 
 for(int j = 1; j <= N; j++)
 {int c = abs(A[j+1] - A[j]) + abs(A[j] - A[j-1]) - abs(A[j+1] - A[j-1]);
  cout << total - c << endl;}
 
 return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

struct edge {
    int to;
    int weight;
};

vector<edge> G[200010];
bool visit[100010];
int d[100010];

int dfs(int v, int dist) {

    if(visit[v]) {
        if(d[v] != dist) {
            return 1;
        }
        else {
            return 0;
        }
    }

    visit[v] = true;
    d[v] = dist;
    rep(i, G[v].size()) {
        if(dfs(G[v][i].to, d[v] + G[v][i].weight)) {
            return 1;
        }
    }

    return 0;
}

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

    rep(i, m) {
        int L, R, D;
        cin >> L >> R >> D;
        L--;  R--;
        G[L].push_back({R,D});
        G[R].push_back({L,-D});
    }

    rep(i, n) {
        if(!visit[i] && dfs(i, 0)) {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 14464
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N, sum=0;
	  cin >> N;
      
      vector<int> V(N);
	  for (int i = 0; i < N; i++) {
 	  cin >> V[i];
	  }
      
      vector<int> C(N);
	  for (int i = 0; i < N; i++) {
 	  cin >> C[i];
	  }
      
      for(int i = 0; i < N; i++){
      	if(V[i]-C[i] > 0){
          sum += V[i] - C[i];
        }
      }  
      
      cout << sum <<endl;

    }

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <cmath>
#include <map>
#include <climits>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<m;i++)
int main()
{
    int N, Z, W; cin >> N >> Z >> W;
    int A[2001]; FOR(i, 1, N+1) cin >> A[i];
    int dp[2][2000]; // player to draw, number of cards taken
    for (int i = N-1; i >= 0; i--) {
        int p0 = i == 0 ? Z : A[i];
        int p1 = i == 0 ? W : A[i];
        int t;
        t = INT_MIN;
        for (int j = i + 1; j <= N-1; j++) t = max(t, dp[1][j]);
        dp[0][i] = max(t, abs(p1 - A[N]));
        t = INT_MAX;
        for (int j = i + 1; j <= N-1; j++) t = min(t, dp[0][j]);
        dp[1][i] = min(t, abs(p0 - A[N]));
    }
    cout << dp[0][0] << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N, X = [int(n) for n in input().split()]
l = [int(n) for n in input().split()]

D = [0]
for i in range(N):
    D.append(D[-1] + l[i])

#print(D)

count = 0
for n in D:
    if n <= X:
        count += 1
    else:
        break

print(count)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
 
 
 
 
int main() {
    int n;
    cin>>n;
    cout<<n*n*n<<endl;
}




Measured memory_bytes: 256
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long[] a = new long[n + 1];
		for(int i = 1 ; i <= n ; i++) {
			a[i] = sc.nextLong();
		}
		String s = "";
		StringBuilder sb = new StringBuilder(s);
		for(int i = k + 1 ; i <= n ; i++) {
			if(a[i - k] >= a[i]) {
				sb.append("No\n");
			}
			else
				sb.append("Yes\n");
		}

		sc.close();
		System.out.println(sb.toString());

	}
}



Measured memory_bytes: 61100
import static java.util.Arrays.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	void solve() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int si = sc.nextInt();
		int gi = sc.nextInt();
		if ((n|m|si|gi) == 0) return;
		V[] vs = new V[n];
		for (int i = 0; i < n; i++) vs[i] = new V();
		V s = vs[si];
		V g = vs[gi];

		for (int i = 0; i < m; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			String label = sc.next();
			vs[y].add(vs[x], label); // rev
		}

		g.memo = "";
		boolean cycle = false;
		for (int itr = 0; itr < 6 * n; itr++) {
			boolean update = false;
			for (V v : vs) if (!v.memo.equals("{")) {
				for (E e : v.es) {
					String nl = e.label + v.memo;
					if (e.to.memo.compareTo(nl) > 0) {
						if (nl.length() > 6 * n+1) nl = new String(nl.substring(0, 6 * n+1));
						e.to.memo = nl;
						update = true;
						if (e.to == s && itr > 5 * n) cycle = true;
					}
				}
			}
			if (!update) break;
		}

		if (cycle || s.memo.equals("{") || s.memo.length() > 6 * n) {
			out.println("NO");
		} else {
			out.println(s.memo);
		}

	}

	class V {
		List<E> es = new ArrayList<E>();
		String memo = "{";
		void add(V to, String label) {
			this.es.add(new E(to, label));
		}
	}
	class E {
		V to;
		String label;
		E(V to, String label) {
			this.to = to;
			this.label = label;
		}
	}


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

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

Measured memory_bytes: 95640
n,m=map(int,input().split())
submit=[]
ans_table={}
ans1=0
ans2=0
cnt1=0
cnt2=0
if m==0:
    print("0 0")
else:
    for i in range(m):
        submit.append(list(input().split()))
    submit.sort(key=lambda x:x[0])

    tmp=submit[0][0]
    for i in submit:
        if i[0]!=tmp:
           tmp = i[0]
           cnt2 = 0
        if i[1]=="WA":
            cnt2+=1
        else:
            if i[0] in ans_table:
                continue
            else:
                ans_table[i[0]]="AC"
                ans2+=cnt2
                ans1+=1
    print(ans1,ans2)

Measured memory_bytes: 81112
main = do
    fs <- getLine
    ss <- getContents
    let ns = map (\x -> read x :: Int) $ words ss
    putStrLn $ show $ length $ filter isPrime ns

isPrime :: Int -> Bool
isPrime n = isNoDivisor n [2..nm]
  where
    nm = floor $ (fromIntegral n) ** (1/2)
    isNoDivisor x ys = and $ map (\y -> x `mod` y /= 0) ys



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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<ll> vecll;
typedef vector<string> vecs;
template<class T,class U> using Hash=unordered_map<T,U>;

#define REP(i, a, n) for(ll i = a; i < (ll)n; i++)
#define RREP(i, a, n) for(ll i = n-1; i >= (ll)a; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define MD 1000000007

template<class T> T read(){T a;cin >> a;return a;}
template<class T> void read(T& a){cin >> a;}
template<class T, class ...Args> void read(T& a, Args&... args){cin >> a; read(args...);} 
template<class T> void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}}
template<char c = ' ',class T> void write(T a){cout << setprecision(12) << a << endl;}
template<char c = ' ',class T,class ...Args> void write(T a, Args... args){cout << setprecision(12) << a << c; write<c>(args...);}
template<class T> void warr(vector<T> a, const char* c = " "){cout << a[0];for(int i = 1; i < (int)a.size(); i++)cout << c << a[i];cout << endl;;}
template<class T> void warr(T a, int n, const char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;}
void split(string s, string delim, veci& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(atoi(s.substr(pos).data()));break;}else {result.push_back(atoi(s.substr(pos, p - pos).data()));}pos = p + delim.size();}}
void split(string s, string delim, vecs& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(s.substr(pos));break;}else {result.push_back(s.substr(pos, p - pos));}pos = p + delim.size();}}
ll gcd(ll a, ll b){while(true){ll k = a % b;if(k == 0)return b;a = b;b = k;}}
ll comb(ll n, ll m){ll p=1;m=min(m,n-m);for(ll i=1;i<=m;i++){p*=n-i+1;p/=i;}return p;}

int main(void)
{
    ll n,a;
    ll ma=-1000000,mi=1000000,su=0;
    read(n);
    rep(i,n){
        read(a);
        ma=max(ma,a);
        mi=min(mi,a);
        su+=a;
    }
    write(mi,ma,su);
    return 0;
}

Measured memory_bytes: 3096
#include "bits/stdc++.h"
using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP(a, b) make_pair(a, b)
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n, m;
vector<pi>s;
int dp[1024];

int main(){
  while(scanf("%d", &n) && n){
    s.clear();
    int h, r;
    rep(i, n){
      scanf("%d%d", &h, &r);
      s.push_back(MP(h, r));
    }
    scanf("%d", &m);
    rep(i, m){
      scanf("%d%d", &h, &r);
      s.push_back(MP(h, r));
    }

    sort(s.begin(), s.end());
    memset(dp, 0, sizeof(dp));

    int res = 0;
    rep(i, s.size()){
      dp[i] = 1;
      rep(j, i) if(s[j].F < s[i].F && s[j].S < s[i].S){
    dp[i] = max(dp[i], dp[j] + 1);
      }
      res = max(res, dp[i]);
    }
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 3112
N=int(input())
S=list(input())
if N%2!=0:
    print("No")
else:
    s_1=S[:int(N/2)]
    s_2=S[int(N/2):N]
    if s_1==s_2:
        print("Yes")
    else:
        print("No")
  
  

Measured memory_bytes: 9044
def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)

def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max,mod=DIV):
    fac,finv,inv = [0]*max, [0]*max, [0]*max
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod -inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
    class CONV:
        def __init__(self):
            pass
        def ncr(self,n,k):
            if(n<k):
                return 0
            if(n<0 or k<0 ):
                return 0
            return fac[n]*(finv[k]*finv[n-k]%mod)%mod
    return CONV()


def main():
    N,K = isRaw()
    ans = 1
    while N !=0:
        N = N//K
        if N==0:
            return ans
        ans+=1
    return ans
    


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  string n;
  cin >> n;
  if (n[0] == n[2]) Yes();
  else No();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(RALL(x)
#define SUM(x) accumulate(ALL(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

int main () {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];

  vector<pii> p(n);
  rep(i,n) p[i] = make_pair(a[i],i+1);

  SORT(p);

  rep(i,n) printf("%d%s",p[i].se,i!=n-1?" ":"\n");
}

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

int main(){
  long long int N ,ans = 0 ;
  string S ;
  cin >> S;
  N = S.size();
  for(int i = 0; i < N / 2; i++){
    if(S[i] != S[N-1 - i]) ans++;
  }
  cout << ans << endl;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

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

  int a, b;
  cin >> a >> b;
  cout << 6 - a - b << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    string s;
    cin >> s;
    if (s == "Sunny")
        cout << "Cloudy"
             << "\n";
    else if (s == "Cloudy")
        cout << "Rainy"
             << "\n";
    else
        cout << "Sunny"
             << "\n";
    return 0;
}

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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

//library----------------------------------------------


int main(){
    CIN(N);
    SCIN(s);
    s.erase(unique(all(s)),s.end());
    int ans=s.size();
    
    printf("%d\n",ans);

    return 0;
}

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

#define For(i, j, k) for (int i = j; i <= k; i++)

using namespace std;

const int N = 55;

int A[N], B[N], n;
bool G[N][N], flag[N][N];

int main() {

	scanf("%d", &n);
	For(i, 1, n) scanf("%d", &A[i]);
	For(i, 1, n) scanf("%d", &B[i]), flag[i][A[i]] = true;

	For(i, 0, 50) {
		G[i][i] = true;
		For(j, 1, i) For(k, 0, 50) G[i][k] |= G[i % j][k];
	}

	For(i, 1, n) if (!G[A[i]][B[i]]) {
		puts("-1");
		return 0;
	}

	long long ans = 0;
	while (true) {
		bool ok = true;
		For(i, 1, n) if (!flag[i][B[i]]) { ok = false; break; }
		if (ok) break;

		int mx = 0;
		For(i, 1, n) if (!flag[i][B[i]]) {
			int mn = 50;
			For(now, 1, 50) if (flag[i][now] && G[now][B[i]]) {
				For(j, 1, now) if (G[now % j][B[i]]) {
					mn = min(mn, j);
					break;
				}
			}
			mx = max(mx, mn);
		}

		ans |= 1ll << mx;
		For(i, 1, n) For(j, 1, 50) flag[i][j % mx] |= flag[i][j];
	}

	printf("%lld\n", ans);

	return 0;
}

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

int main(){
  int a, b, k;
  vector<int> vec;
  cin >> a >> b >> k;
  rep(i,101) if(a%i==0 && b%i==0) vec.push_back(i);
  reverse(vec.begin(),vec.end());
  cout << vec.at(k-1) << endl;
}
    

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define dump(x)  cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i:a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int x, y;

int mon(int a, int b) {
	int re;
	if (a >= 5 && b >= 2)re = (x / 5 * 4)*a + (y / 5 * 4)*b;
	else re = x * a + y * b;
	return re;
}


int main() {
	int n; cin >> n;
	rep(i, n) {
		int b, p; cin >> x >> y >> b >> p;

		int ans = INT_MAX;
		rep(i, 6)rep(j, 3) {
			int m = mon(b + i, p + j);
			//cout << "(" << b + i << "," << p + j << ") = " << m << endl;
			ans = min(ans, m);
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3100
# include <bits/stdc++.h>
# define int long long
# define endl "\n"
using namespace std;

void solve() {

	int n;
	cin >> n;

	int sum = 0;
	unordered_map <int, int> freq;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		freq[x]++;
		sum += x;
	}
	int q;
	cin >> q;
	while (q--) {
		int b, c;
		cin >> b >> c;

		sum -= b * freq[b];
		sum += c * freq[b];
		freq[c] += freq[b];
		freq[b] = 0;

		cout << sum << endl;
	}
}

signed main() {

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

# ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
# endif

	solve();

	return 0;
}

Measured memory_bytes: 6968
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 200005;
int nums[MAXN];
int main() {
    ios::sync_with_stdio(0);
    int K, N;
    cin >> K >> N;
    int maxx = 0;
    for (int i = 1; i <= N; ++i) {
        cin >> nums[i];
    }
    for (int i = 1; i <= N - 1; ++i) {
        maxx = max(maxx, nums[i + 1] - nums[i]);
    }
    maxx = max(maxx, nums[1] + K - nums[N]);
    cout << K - maxx << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define x first
#define y second
#define iter iterator
#define riter reversed_iterator
#define y1 Lorem_ipsum_
#define tm dolor_sit_amet_
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int mxN = 10;
const int P = 998244353;
char a[mxN+3][mxN+3];
int row[mxN+3],col[mxN+3];
llong f[mxN+3][mxN+3][2],g[mxN+3][mxN+3][2],h[mxN+3][mxN+3];
llong comb[mxN+3][mxN+3],combi[mxN+3][mxN+3];
int n,m;

void updsum(llong &x,llong y) {x+=y-P,x+=(x>>31)&P;}

llong quickpow(llong x,llong y)
{
	if(y==0ll) {return 1ll;}
	llong ret = quickpow(x,y>>1); ret = ret*ret%P; if(y&1ll) ret = ret*x%P;
	return ret;
}
llong mulinv(llong x) {return quickpow(x,P-2);}
void initcomb(int n)
{
	comb[0][0] = 1ll;
	for(int i=1; i<=n; i++) {comb[i][0] = comb[i][i] = 1ll; for(int j=1; j<i; j++) {updsum(comb[i][j]=comb[i-1][j-1],comb[i-1][j]);}}
	for(int i=0; i<=n; i++) for(int j=0; j<=i; j++) {combi[i][j] = mulinv(comb[i][j]);}
}

int main()
{
	initcomb(mxN);
	n = read(),m = read();
	for(int i=0; i<n; i++) {scanf("%s",a[i]); for(int j=0; j<m; j++) a[i][j] = (a[i][j]=='#'?1:0),row[i]|=(a[i][j]<<j),col[j]|=(a[i][j]<<i);}
	llong ans = (1<<m);
	for(int i=0; i<m; i++) {g[0][i][1] = 1ll<<i;}
	for(int i=0; i<n; i++)
	{
		for(int j=0; j<m; j++)
		{
			for(int k=1; k<=i; k++)
			{
				llong tmp = (g[i-k][j][0]+g[i-k][j][1]*2ll)*comb[i][k]%P;
				updsum(f[i][j][0],tmp);
				tmp = g[i-k][j][1]*((1ll<<k)-2ll)%P*comb[i][k]%P;
				updsum(f[i][j][1],tmp);
			}
			for(int k=1; k<=j; k++)
			{
				llong tmp = (f[i][j-k][0]+f[i][j-k][1]*2ll)*comb[j][k]%P;
				updsum(g[i][j][0],tmp);
				tmp = f[i][j-k][1]*((1ll<<k)-2ll)%P*comb[j][k]%P;
				updsum(g[i][j][1],tmp);
			}
			h[i][j] = (f[i][j][0]+f[i][j][1]+g[i][j][0]+g[i][j][1])%P;
			llong coe = comb[n][i]*comb[m][j]%P;
			updsum(ans,f[i][j][1]*coe%P*((1ll<<m-j)-2ll)%P);
			updsum(ans,g[i][j][1]*coe%P*((1ll<<n-i)-2ll)%P);
		}
	}
	for(int i=1; i<(1<<n); i++)
	{
		for(int j=1; j<(1<<m); j++)
		{
			bool ok = true; int cnt1 = 0,cnt2 = 0;
			for(int k=0; k<n; k++) if(i&(1<<k))
			{
				cnt1++;
				if((row[k]&j)==j||(row[k]&j)==0) {ok = false; break;}
			}
			for(int k=0; k<m; k++) if(j&(1<<k))
			{
				cnt2++;
				if((col[k]&i)==i||(col[k]&i)==0) {ok = false; break;}
			}
			if(!ok) continue;
			updsum(ans,h[n-cnt1][m-cnt2]);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256