akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

const int D = 365;
int C[26] = {};
int S[D][26] = {};
vector<int> L(26, 0);
vector<int> T;

ll ret[26] = {};

void input() {
    int dummy; cin >> dummy;
    REP(i, 0, 26) cin >> C[i];
    REP(i, 0, D) REP(j, 0, 26) cin >> S[i][j];
}

ll calc_init() {
    ll ret = 0; int d = T.size(); L.assign(26, 0);
    REP(i, 0, d) {
        ret += S[i][T[i]];
        L[T[i]] = i + 1;
        REP(j, 0, 26) ret -= C[j] * (i + 1 - L[j]);
    }
    return ret;
}

void init() {
    REP(i, 0, D) {
        int max_score = 0, max_idx = 0;
        REP(j, 0, 26) {
            T.push_back(j);
            ll cur = calc_init();
            if (max_score < cur) {
                max_score = cur;
                max_idx = j;
            }
            T.pop_back();
        }
        T.push_back(max_idx);
    }
}

int main() {
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    auto start = std::chrono::system_clock::now();
    const ll limit = 1950*1000;
    
    input();
    init();

    REP(i, 0, D) {
        ret[T[i]] += S[i][T[i]];
        L[T[i]] = i + 1;
        REP(j, 0, 26) {
            ret[j] -= C[j] * (i + 1 - L[j]);
        }
    }

    ll best = 0;
    REP(i, 0, 26) best += ret[i];

    mt19937_64 mt(random_device{}());
    uniform_int_distribution<int> day(0, D - 1);
    uniform_int_distribution<int> con(0, 25);
    while (1) {
        std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
        double elapsed = std::chrono::duration_cast<std::chrono::microseconds>(now-start).count();
        if(elapsed > limit) break;

        int d = day(mt);
        int next = con(mt);
        int prev = T[d];
        T[d] = next;
        L[prev] = 0;
        L[next] = 0;
        ll oldp = ret[prev];
        ll oldn = ret[next];
        ll cur = best - oldp - oldn;
        ret[prev] = 0;
        ret[next] = 0;
        REP(i, 0, D) {
            if (T[i] == prev || T[i] == next) {
                ret[T[i]] += S[i][T[i]];
                L[T[i]] = i + 1;
            }
            ret[prev] -= C[prev] * (i + 1 - L[prev]);
            ret[next] -= C[next] * (i + 1 - L[next]);
        }
        if (best >= cur + ret[prev] + ret[next]) {
            T[d] = prev;
            ret[prev] = oldp;
            ret[next] = oldn;
        } else {
            best = cur + ret[prev] + ret[next];
        }
        // cout << best << endl;
    }
    
    for (auto t : T) cout << t + 1 << endl;
    return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>
int main(void)
{
	int E,Y,S;
	scanf("%d %d",&E,&Y);
	if(E==0){
	if(Y>=1868 && Y<=1911){
	S=Y-1868+1;
	printf("M%d\n",S);
	}
	else if(Y>=1912 && Y<=1925){
	S=Y-1912+1;
	printf("T%d\n",S);
	}
	else if(Y>=1926 && Y<=1988){
	S=Y-1926+1;
	printf("S%d\n",S);
	}
	else if(Y>=1989 && Y<=2016){
	S=Y-1989+1;
	printf("H%d\n",S);
	}
}
	else if(E==1) {
		S=1868+Y-1;
		printf("%d\n",S);
	}
	else if(E==2) {
		S=1912+Y-1;
		printf("%d\n",S);
	}
	else if(E==3) {
		S=1926+Y-1;
		printf("%d\n",S);
	}
	else if(E==4) {
		S=1989+Y-1;
		printf("%d\n",S);
	}
	return 0;
}	
	


Measured memory_bytes: 2752
#include<iostream>
#include<vector>
#include<climits>

int main(){
	long long answer= LLONG_MAX;

	int n, c;
	std::vector<int> dList;
	std::vector<int> cList;
	std::vector<std::vector<int>> cntColor;

	std::cin>> n>> c;
	dList.resize(c*c);
	cList.resize(n*n);
	cntColor.resize(3);
	for(int i=0; i<3; i++)
		cntColor[i].resize(c, 0);

	for(int i=0; i< c*c; i++)
		std::cin>> dList[i];

	for(int i=0; i< n*n; i++){
		int tmp;
		std::cin>> tmp;
		cList[i]= tmp-1;
	}

	for(int i=0; i< n*n; i++){
		int x= (i%n)+1;
		int y= (i/n)+1;
		int mod= (x+y)%3;
		int color= cList[i];

		cntColor[mod][color]++;
	}

	for(int iter0=0; iter0< c; iter0++){
		for(int iter1=0; iter1<c; iter1++){
			for(int iter2=0; iter2<c; iter2++){
				if(iter0==iter1 || iter1==iter2 || iter0==iter2)
					continue;

				long long sum=0;
				for(int iterC=0; iterC< c; iterC++){
					sum+= dList[iterC*c+iter0] *cntColor[0][iterC];
					sum+= dList[iterC*c+iter1] *cntColor[1][iterC];
					sum+= dList[iterC*c+iter2] *cntColor[2][iterC];
				}

				if(answer> sum)
					answer= sum;
			}

		}

	}

	std::cout<<answer<<std::endl;

	return 0;
}

Measured memory_bytes: 1280
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    R = input_number()
    if R < 1200:
        print("ABC")
    elif R < 2800:
        print("ARC")
    else:
        print("AGC")
        

if __name__ == '__main__':
    main()


Measured memory_bytes: 9104
#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  string s;
  cin>>s;
  int c=0;
  for(int i=0;i<s.length()/2;i++) {
    if(s[i]!=s[s.length()-i-1])
      c++;
  }
  cout<<c;
  return 0;
}

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


t = 0
o = 0
for s in S:
    if s == 'a':
        if t < A + B:
            print('Yes')
            t += 1
        else:
            print('No')

    if s == 'b':
        if t < A + B and o < B:
            print('Yes')
            t += 1
            o += 1
        else:
            print('No')

    if s == 'c':
        print('No')


Measured memory_bytes: 4040
//#pragma GCC optimize ("-O3","unroll-loops")
#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>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;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 REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
//#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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

const int MOD = 1e9 + 7;
const ll INF = 1e17;
const int INT_INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

vector<int>key[10010];
int A[10010];
ll dp[1 << 12];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M; cin >> N >> M;
	REP(i, M) {
		cin >> A[i];
		int b; cin >> b;
		REP(j, b) {
			int x; cin >> x;
			x--;
			key[i].pb(x);
		}
	}
	REP(i, 1 << 12)dp[i] = INT_MAX;
	dp[0] = 0;
	REP(bit, 1 << N) {
		REP(i, M) {
			int newbit = bit;
			REP(j, key[i].size()) {
				newbit |= (1 << key[i][j]);
			}
			//pe(bit)print(newbit);
			chmin(dp[newbit], dp[bit] + A[i]);
		}
	}
	if (dp[(1 << N) - 1] == INT_MAX) {
		print(-1);
	}
	else print(dp[(1 << N) - 1]);
}


Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<math.h>
#include<stack>
#include<map>
#include<limits.h>
#include<vector>
#include<string.h>
#include<string>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int N = 2e5+5;
const int Mod = 1e9+7;
#define pi acos(-1)
#define INF 1e9+5
#define INM INT_MIN
#define pb(a)  push_back(a)
#define mk(a,b) make_pair(a,b)
#define dbg(x) cout << "now this num is " << x << endl;
#define met0(axx) memset(axx,0,sizeof(axx));
#define metf(axx) memset(axx,-1,sizeof(axx));
#define sd(ax) scanf("%d",&ax)
#define sld(ax) scanf("%lld",&ax)
#define sldd(ax,bx) scanf("%lld %lld",&ax,&bx)
#define sdd(ax,bx) scanf("%d %d",&ax,&bx)
#define sddd(ax,bx,cx) scanf("%d %d %d",&ax,&bx,&cx)
#define sfd(ax) scanf("%lf",&ax)
#define sfdd(ax,bx) scanf("%lf %lf",&ax,&bx)
#define pr(a) printf("%d\n",a)
#define plr(a) printf("%lld\n",a)
/*
贪心？pu..看zzl学长的贪心,emm..很微妙.也能过
但是可以直接dfs暴搜..
*/
int n,f = 0;
string s[N];
char ans[N];
void dfs(int x,int y,int z,int i)
{
	if(f) return ;
	if(i == n+1)
	{
		if(x >= 0 && y >= 0 && z >= 0)
		{
			f = 1;
			printf("Yes\n");
			for(int i=1;i<=n;++i) cout << ans[i] << "\n";
		}
		return ;
	}
	if(s[i] == "AB")
	{
		if(y > 0) ans[i] = 'A',dfs(x+1,y-1,z,i+1);
		if(x > 0) ans[i] = 'B',dfs(x-1,y+1,z,i+1);
	}
	if(s[i] == "BC")
	{
		if(z > 0) ans[i] = 'B',dfs(x,y+1,z-1,i+1);
		if(y > 0) ans[i] = 'C',dfs(x,y-1,z+1,i+1);
	}
	if(s[i] == "AC")
	{
		if(z > 0) ans[i] = 'A',dfs(x+1,y,z-1,i+1);
		if(x > 0) ans[i] = 'C',dfs(x-1,y,z+1,i+1);
	}
}
int main()
{
	sd(n);
	int a,b,c;sddd(a,b,c);
	for(int i=1;i<=n;++i) cin >> s[i];
	dfs(a,b,c,1);
	if(!f) printf("No\n");
//	system("pause");
	return 0;
}


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

int main() {
  int L;
  cin >> L;
  int count = 0, top;//count:1の数 top:最上位の1の位置
  int arr[21]={0};
  for(int i = 0; i <= 20; i++){
    if((L >> i) & 1 == 1){//i桁目が1
      arr[count] = i;
      count++;
      top = i;
    }
  }

  if(count == 1){
    cout << top + 1 << " " << top * 2 << endl;
    for(int i = 0; i < top; i++){
      cout << top - i << " " << top - i + 1 << " " << pow(2, i) << endl;
      cout << top - i << " " << top - i + 1 << " " << 0 << endl;
    }
  }else{
    cout << top + 1 << " " << top * 2 + count - 1 << endl;
    for(int i = 0; i < top; i++){
      cout << top - i << " " << top - i + 1 << " " << pow(2, i) << endl;
      cout << top - i << " " << top - i + 1 << " " << 0 << endl;
    }
    for(int i = 0; i < count - 1; i++){
      int temp = L;
      temp = temp >> arr[i] + 1;
      temp = temp << arr[i] + 1;
      cout << 1 << " " << top + 2 - arr[i] - 1 << " " << temp << endl;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>

void call(int n) {

	for (int i{ 1 }; i <= n; ++i) {

		if (i % 3 == 0)//|| i%10==3 )
			std::cout << " " << i;
		else {
			int x = i;
			while (x % 10 != 3) {
				x /= 10;
				if (x == 0)
					break;
			}
			if (x % 10 == 3)
				std::cout << " " << i;
		}
	}

	std::cout << "\n";
}

int main() {
	int x;
	std::cin >> x;
	call(x);
	return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(15) << << endl;
#include <cassert>
//#include "atcoder/all"

using namespace std;
//using namespace atcoder;

#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define P pair<int,int>

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};

int main(){
    int n; cin >> n;
    vector<ll> z(n),w(n);
    rep(i,n){
        int x,y; cin >> x >> y;
        z[i] = x + y;
        w[i] = x - y;
    }
    sort(z.begin(),z.end());
    sort(w.begin(),w.end());
    cout << max(z[n-1]-z[0], w[n-1]-w[0]) << endl;
}



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

int main() {
    int n, l;
    cin >> n >> l;
    
    string s[n+10];
    for (int i=0; i<n; i++) {
        cin >> s[i];
    }
    
    sort(s, s+n);
    string new_string = "";
    for (int i=0; i<n; i++) {
        new_string += s[i];
    }
    
    cout << new_string << endl;

    return 0;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void)
{
  int x,a,b; cin>>x>>a>>b;
  
  int A=a-x;
  int B=b-x;
  if(A<0){A=-A;}
  if(B<0){B=-B;}
  
  if(A<B){puts("A");}
  else{puts("B");}
  
  return 0;
}

Measured memory_bytes: 256
# https://betrue12.hateblo.jp/entry/2020/03/28/142051

def main():
    N, K = map(int, input().split())
    *A, = map(int, input().split())

    def divisor_generator(n):
        div = 1

        stock = []
        while div * div <= n:
            if n % div == 0:
                yield n // div
                stock.append(div)
            div += 1

        for div in reversed(stock):
            yield div

    tot = sum(A)
    for div in divisor_generator(tot):
        k = tot // div - sum(a // div for a in A)
        R = sorted(a % div for a in A)
        Rc = [div - r for r in R]

        cond = (sr := sum(r for r in R[:N - k])) == sum(r for r in Rc[N - k:]) and sr <= K
        if cond:
            print(div)
            return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9352
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
int main(){
    long long n,k;
    cin >> n >> k;
    int ans = 0;
    while(n>0){
        n/=k;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b;
    char op;
    while(1){
        cin >> a >> op >> b;
        if(op=='+'){
            cout << a+b<<endl;
        }else if(op=='-'){
            cout << a-b<<endl;
        }else if(op=='*'){
            cout << a*b<<endl;
        }else if(op=='/'){
            cout << a/b<<endl;
        }if(op=='?'){
            break;
        }
        
    }
    
    
    
    
}


Measured memory_bytes: 3108
k, n = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
max = k - a[len(a) - 1] + a[0]
for i in range(len(a) - 1):
    t = a[i + 1] - a[i]
    if(t > max): max = t

print(k - max)

Measured memory_bytes: 26420
#include <stdio.h>

int main(void)
{
  char N[4];
  
  scanf("%s", N);
  
  if(N[0]=='7' || N[1]=='7' || N[2]=='7'){
    printf("Yes");
  }
  else{
  	printf("No");
  }
  
  return 0;
}



Measured memory_bytes: 1736
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
b = sorted(a, key=lambda x: x[1])
judge = 0
flag = "Yes"
for j in range(n):
  judge += b[j][0]
  if(judge >  b[j][1]):
    print("No")
    flag = "No"
    break
    
if(flag == "Yes"):
  print("Yes")
  

Measured memory_bytes: 55196
import Control.Applicative
import qualified Data.Map as Map
import qualified Data.IntMap as IMap

solve :: [Int] -> Int
solve = f5 . f4 . f3 . f2

f5 :: [Int] -> Int
f5 = sum . map comb
    where comb n = div (n*(n-1)) 2

f4 :: IMap.IntMap Int -> [Int]
f4 = map snd . IMap.toList

f3 :: [Int] -> IMap.IntMap Int
f3 = foldl app IMap.empty 
app mp v | IMap.member v mp = IMap.update (\x->Just (x+1)) v mp
         | otherwise = IMap.insert v 1 mp
    

f2 :: [Int] -> [Int]
f2 = foldl f1 [0]

f1 :: [Int] -> Int -> [Int]
f1 [] a = [a]
f1 all@(x:xs) a = (a+x):all

main = do
    getLine
    list <- map read . words <$> getLine :: IO [Int]
    print $ solve list

Measured memory_bytes: 162172
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

#define int long long 
signed main(){
    int n,m;
    cin >> n >> m;
    vector<int>a(n);
    rep(i,n) cin >> a[i];
    set<pair<int,pair<int,int> > > st;
    set<pair<int,pair<int,int> >,greater< pair<int,pair<int,int> > >  > st2;
    rep(i,n){
        st.insert(MP(max(i,a[i]),MP(i,a[i])));
        st2.insert(MP(min(i,a[i]),MP(i,a[i])));
    }
    ll ans = 0;
    rep(i,m){
        auto x = *st.begin();
        auto y = *st2.begin();
        //cerr << x.second.first << " " << x.second.second << " " << y.second.first << " " << y.second.second << endl; 
        if(y.second.first > x.second.first&& y.second.second > x.second.second &&x.second!=y.second){
            st.erase(x);
            st.erase(MP(max(y.second.first,y.second.second),y.second));
            st.erase(MP(min(x.second.first,x.second.second),x.second));
            st2.erase(y);
            pair<int,pair<int,int> > a,b,c,d;
            a = MP(max(x.second.first,y.second.second),MP(x.second.first,y.second.second));
            b = MP(max(y.second.first,x.second.second),MP(y.second.first,x.second.second));
            c = MP(min(x.second.first,y.second.second),MP(x.second.first,y.second.second));
            d = MP(min(y.second.first,x.second.second),MP(y.second.first,x.second.second));
            st.insert(a);
            st.insert(b);
            st2.insert(c);
            st2.insert(d);
        }
    }
    for(auto x:st){
        //cerr << x.second.second << " ";
        ans += abs(x.second.first-x.second.second);
    }
    //cerr << endl;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 17564
import math

n=int(input())
start=int(math.sqrt(n)//1)
#print(start)
List=[]
for i in range(1,start+1):
  if (n%i==0):
    List.append(i)
    List.append(int(n//i))
num=len(List)
#print(List)
print(List[num-2]+List[num-1]-2)

Measured memory_bytes: 3268
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        k: usize
    }
    let mut ans: f64 = 0.0;
    for i in 1..n + 1 {
        let mut l = 0;
        while i << l < k {
            l += 1;
        }
        ans += 2.0f64.powi(- l as i32);
    }
    ans /= n as f64;
    println!("{}", ans);
}


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

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

  vector<int> number_of_people_fasing_East(N, 0);
  vector<int> number_of_people_fasing_West(N, 0);

  for (int person = 0; person < N; person++) {
    if (person > 0) number_of_people_fasing_West[person] = number_of_people_fasing_West[person-1];
    if (S[person] == 'E') number_of_people_fasing_West[person]++; 
  }

  for (int person = N-1; person >= 0; person--) {
    if (person < N-1) number_of_people_fasing_East[person] = number_of_people_fasing_East[person+1];
    if (S[person] == 'W') number_of_people_fasing_East[person]++; 
  }

  int ans = N-1;
  for (int person = 0; person < N; person++) {
    int number_of_people_already_fasing = 1;
    if (person > 0) number_of_people_already_fasing += number_of_people_fasing_West[person-1];
    if (person < N-1) number_of_people_already_fasing += number_of_people_fasing_East[person+1];
    
    ans = min(ans, N - number_of_people_already_fasing);
  }

  cout << ans << endl;
}

Measured memory_bytes: 3076
n = int(input())
s = input()
ans = 0
for i in range(1, n):
    num = 0
    for c in range(ord('a'), ord('z')+1):
        if (chr(c) in s[:i] and chr(c) in s[i:]):
            num += 1
    ans = max(ans, num)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;
#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif


namespace Solver{
using namespace std;

struct Problem{
    int n;
    LL sa,sb,cnt,sum;
    vector<LL> a,b;
    Problem(LL n):n(n),a(n),b(n){};

    void solve(){
        for(int i=0; i<n; ++i){
            cin >> a[i];
        }
        for(int i=0; i<n; ++i){
            cin >> b[i];
        }
        sa = accumulate(a.begin(),a.end(),0ll);
        sb = accumulate(b.begin(),b.end(),0ll);
        cnt = sb-sa;
        sum=0;
        for(int i=0; i<n; ++i){
            sum+=max((b[i]-a[i]+1)/2,0ll);
        }
        if(sum>cnt)cout << "No"<<"\n";
        else cout << "Yes" <<"\n";
    }
};
}

int main(){
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    long long n=0;
    std::cin >> n;
    Solver::Problem p(n);
    p.solve();
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n, w;
    scanf("%i%i", &n, &w);
    vector<pair<int,int>> arr(n+1);
    for (int x = 1; x <= n; x++)
        scanf("%i%i", &arr[x].first, &arr[x].second);
    vector<vector<long long>> dp(105, vector<long long>(100005, LONG_MAX));
    dp[0][0] = 0;
    long long ans = 0;
    for (int x = 1; x <= n; x++)
    {
        for (int y = 0; y < 100005; y++)
        {
            if (y >= arr[x].second && dp[x-1][y-arr[x].second] < LONG_MAX)
                dp[x][y] = min(dp[x-1][y-arr[x].second]+arr[x].first, dp[x-1][y]);
            else
                dp[x][y] = dp[x-1][y];
            if (dp[x][y] <= w)
                ans = max(ans, (long long)y);
        }
    }
    printf("%lli\n", ans);
}

Measured memory_bytes: 83328
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) xmax = x; return true;
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) xmin = x; return true;
    return false;
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

struct Wit {
    int p;
    int b;
};

void solve() {
    int N; cin >> N;
    vector<vector<Wit>> vec(N);

    FOR(i, 0, N) {
        int a; cin >> a;
        vec[i].resize(a);
        FOR(j, 0, a) {
            cin >> vec[i][j].p >> vec[i][j].b;
            --vec[i][j].p;
        }
    }

    auto judge = [&N, &vec](int bit) -> bool {
        for (int i = 0; i < N; ++i) {
            if (!(bit & (1 << i))) continue;
            for (auto& xy : vec[i]) {
                if (xy.b == 1 && !(bit & (1 << xy.p))) return false;
                if (xy.b == 0 && (bit & (1 << xy.p))) return false;
            }
        }
        return true;
    };

    int ret = 0;
    FOR(bit, 0, 1<<N) {
        if (judge(bit)) chmax(ret, __builtin_popcount(bit));
    }
    cout << ret << endl;    
}

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

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 65536*2
#define REP(i,n) for(long long i = 0;i < n;++i)
long long gekoa[200000] = {};
long long gyaku(long long n) {
	if (gekoa[n]) return gekoa[n];
	long long ans = 1;
	long long now = n;
	long long hoge = n;
	long long geko = MAX_MOD - 2;
	while (geko != 0) {
		if (geko % 2 == 1) {
			ans *= now;
			ans %= MAX_MOD;
		}
		now *= now;
		now %= MAX_MOD;
		geko /= 2;
	}
	return gekoa[hoge] = ans;
}
int main() {
	long long n, p;
	cin >> n >> p;
	if (n == 1) {
		cout << p << endl;
		return 0;
	}
	long long geko = 1;
	for (int i = 2; i <= sqrt(p); ++i) {
		long long cnt = 0;
		while (p % i == 0) {
			cnt++;
			p /= i;
		}
		for (int q = 0; q < cnt / n; ++q) {
			geko *= i;
		}
	}
	cout << geko << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

const int MaxN = 1e5 + 5; 
typedef long long LL;
int a[106];

int main(){
	LL n, k;
	cin>>n>>k;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		cin>>a[i];
	}
	sort(a+1, a+1+n);
	for(int i = 1; i <= n;i++){
		if(a[i] <= k){
			ans++;
			k -= a[i];
		}
	}
	if(k > 0 && ans == n) ans--;
	if(ans == -1) cout<<"0"<<endl;
	else cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <numeric>
#include <tuple>
#include <cstdio>

using namespace std;

typedef long long ll;


#define rep(i,b) for(ll i=0;i<(b);++i)
#define rep1(i,b) for(ll i=1;i<=(b);++i)
#define vec vector
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

int N;
int s[110];

int dp[10010][110];

int rec(int ans, int prob) {
   if (prob > N) {
      return ((ans % 10 == 0) ? 0 : ans);
   } else {
      if (dp[ans][prob] < 0) {
         dp[ans][prob] = max(rec(ans, prob + 1), rec(ans+s[prob], prob+1));
      }
      return dp[ans][prob];
   }
}

int main() {
   cin >> N;
   rep1(i, N) {
      cin >> s[i];
   }
   rep(i, 10010) {
      rep(j, N+1) {
         dp[i][j] = -1;
      }
   }
      //dp[i][N+1] = ((i % 10 == 0) ? 0 : i);
   /*
   rep(i, 10010) {
      for (int j=N;j>=0;j--) {
         if (i+s[j] <= 10000) {
            dp[i][j] = max(dp[i][j+1], dp[i+s[j]][j+1]);
         } else {
            dp[i][j] = dp[i][j+1];
         }
      }
   }
   */
   cout << rec(0, 0) << endl;
   //cout << dp[0][0] << endl;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

ll check[110000];

int main() {
  ll n, x, m;
  cin >> n >> x >> m;
  if(x==0) {
    cout << 0 << endl;
    return 0;
  }
  vll v;
  ll cnt = 0LL;
  ll a = x;
  rep(i,m*2) {
    v.push_back(a);
    cnt += a;
    check[a] = true;
    a *= a;
    a %= m;
    if(check[a]) break;
    if(a==0) {
      cout << cnt << endl;
      return 0;
    }
  }
  if(a==x) {
    ll s = v.size();
    ll ans = 0LL;
    ll c = n - n%s;
    ll b = c/s;
    ans += cnt*b;
    rep(i,n%s) ans += v[i];
    cout << ans << endl;
  }
  else {
    ll ans = 0LL;
    bool swi = true;
    vll vv;
    ll vs = v.size();
    rep(i,vs) {
      if(v[i]==a) swi = false;
      if(swi) {
        ans += v[i];
        n--;
      }
      else vv.push_back(v[i]);
    }
    ll s = vv.size();
    ll sum = 0LL;
    rep(i,s) sum += vv[i];
    ll b = n/s;
    ans += sum*b;
    rep(i,n%s) ans += vv[i];
    cout << ans << endl;
  }
  return 0;
}


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

int N;
int x[10], y[10];

double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}

void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> x[i] >> y[i];
    double sum = 0.0;
    vector<int> v(N);
    for(int i = 0; i < N; i++) v[i] = i + 1;
    do {
        for(int i = 0; i < N - 1; i++) sum += dist(v[i], v[i+1]);
    } while(next_permutation(v.begin(), v.end()));
    int Factorial = 1;
    for(int i = 2; i <= N; i++) Factorial *= i;
    cout << fixed << setprecision(10) << sum / Factorial << endl;
    return;
}

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

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

int main(void){
  int A,B;
  cin >> A >> B;
  if(A == 1 && B == 1){
    cout << "Draw" << endl;
  }
  else if(A == 1){
    cout << "Alice" << endl;
  }
  else if(B == 1){
    cout << "Bob" << endl;
  }
  else if(A == B){
    cout << "Draw" << endl;
  }
  else if(A > B){
    cout << "Alice" << endl;
  }
  else{
    cout << "Bob" << endl;
  }
}

Measured memory_bytes: 256
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
unsigned XorShift(void){static unsigned x = 123456789;static unsigned y = 362436069;static unsigned z = 521288629;static unsigned w = 88675123;unsigned t;t = x ^ (x << 11);x = y; y = z; z = w;return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

string a;

main(){
	cin>>a;
	char t=a.front();
	rep(i,3){
		if(t==a[i+1]){
			dump("Bad");
			return 0;
		}
		t=a[i+1];
	}
	dump("Good");
}

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define int long long

const LL mod = 1e9 + 7;


template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);
    string s;
    cin  >> s;
    int ans = 0;
    for (int i = 0;i < s.size()/2;i++) {
        ans += s[i] != s[s.size() - 1 - i];
    }
    cout << ans;
    return 0;
}


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

int main() {
  int max=0, min=INT_MAX;
  int n; cin >> n;
  for(int i=0; i<n; ++i) {
    int a; cin >> a;
    if(a<min) min = a;
    if(a>max) max = a;
  }
  cout << max-min << endl;
}


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

ll dp[110][100010];
ll w[100000];
ll v[100000];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N, W;
	cin >> N >> W;
	for(int i = 0; i < N; i++){
		cin >> w[i] >> v[i];
	}

	for(int i = 0; i < N; i++){
		for(int j = 0; j <= W; j++){
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			if(j + w[i] <= W){
				dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
			}
		}
	}

	ll ans = 0;
	for(int i = 0; i <= W; i++){
		ans = max(ans, dp[N][i]);
	}
	cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef double db;

#define dbg(x) cout<<#x<<" is "<<x<<endl

const int maxn = 1e6;

int a[maxn];
int n;
int k;

int ck(int m) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        cnt += (a[i] + m - 1) / m - 1;
    }
//    dbg(m);
//    dbg(cnt);
    return k >= cnt;
}

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%d", a + i);
    }
    int bg = 1, ed = 1e9 + 7;
    while (bg < ed) {
        int mid = (bg + ed) / 2;
        if (ck(mid)) {
            ed = mid;
        } else {
            bg = mid + 1;
        }
    }
    printf("%d\n", bg);
    return 0;
}

Measured memory_bytes: 4492
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
using namespace std;
const ll MAX = 1e5 + 5;

int main(void)
{
	string s;
	cin >> s;
	ll n = s.length();
	vector <ll> v, ans[MAX];
	if(s[0] != '1' || s[n - 1] != '0')
	{
		cout << "-1" << endl;
		return 0;
	}
	for(int i = 0; i < n - 1; i++)
	{
		if(n - i - 2 >= 0 && s[i] != s[n - i - 2])
		{
			cout << "-1" << endl;
			return 0;
		}
	}
	ll k = 0;
	for(int i = 0; i < n - 1; i++)
	{
		if(s[i] == '1')
		{
			for(int j = 0; j < v.size(); j++)
			{
				ans[k].pb(i + 1);
				ans[k].pb(v[j]);
				k++;
			}
			v.clear();
			v.pb(i + 1);
		}
		else
			v.pb(i + 1);
	}
	for(int i = 0; i < v.size(); i++)
	{
		ans[k].pb(n);
		ans[k].pb(v[i]);
		k++;
	}

	for(int i = 0; i < k; i++)
		cout << ans[i][0] << " " << ans[i][1] << endl;


 	



	return 0;
}

Measured memory_bytes: 7796
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
 
using namespace std;
 
int main(int argc, char* argv[]) {
 
	int a,b,h;
 
	cin >> a >> b >> h;
 
	cout << (a+b)*h/2 << endl;
 
	return 0;
 
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int i, N, p, dif;

  scanf("%d", &N);
  dif = 0;
  for (i = 1; i <= N; i++) {
    scanf("%d", &p);
    if (p != i) dif++;
  }

  if (dif == 0 || dif == 2) printf("YES\n");
  else printf("NO\n");
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, n, m, a, b;
  scanf("%lld%lld", &n, &m);
  bool s[n];
  for(i = 0; i < n; ++i) s[i] = false;
  for(i = 0; i < m; ++i) {
    scanf("%lld%lld", &a, &b);
    s[--a] = !s[a], s[--b] = !s[b];
  }
  for(i = 0; i < n; ++i) if(s[i]) {
     printf("NO");
     return 0;
  }
  printf("YES");
  return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Control.Monad.ST
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
toTuple (x : y : _) = (x, y)

main = do
    [h, n] <- getIntList
    abs <- map toTuple <$> replicateM n getIntList
    let ans = runST $ do
            dp <- VUM.replicate 10001 (10 ^ 9)
            VUM.write dp 0 0
            forM_ abs $ \(a, b) -> do
                forM_ [0..10000] $ \i -> do
                     when (i - a >= 0) $ do
                         s <- VUM.read dp i
                         t <- VUM.read dp (i - a)
                         VUM.write dp i $ min s (t + b)
            VU.freeze dp
    print . flip (VU.!) h $ VU.scanr min (10 ^ 9) ans

Measured memory_bytes: 1916
#include<bits/stdc++.h>
#define MAX_V 1500
#define INF 1<<29
using namespace std;
struct edge{int to,cap,rev;};
vector<edge>G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});
}
void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<int>q;
  level[s]=0;
  q.push(s);
  while(!q.empty()){
    int v=q.front();q.pop();
    for(int i=0;i<G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[e.to]<0){
        level[e.to]=level[v]+1;
        q.push(e.to);
      }
    }
  }
}
int dfs(int v,int t,int f){
  if(v==t)return f;
  for(int &i=iter[v];i<G[v].size();i++){
    edge &e=G[v][i];
    if(e.cap>0&&level[v]<level[e.to]){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}
int max_flow(int s,int t){
  int flow=0;
  while(1){
    bfs(s);
    if(level[t]<0)return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f=dfs(s,t,INF))>0){
      flow+=f;
    }
  }
}
int main(){
  int a,b;
  while(cin>>a>>b,a+b){
    for(int i=0;i<MAX_V;i++)G[i].clear();
    int aa[a],bb[b];
    for(int i=0;i<a;i++)scanf("%d",&aa[i]);
    for(int i=0;i<b;i++)scanf("%d",&bb[i]);
    for(int i=101;i<601;i++)add_edge(0,i,1);
    for(int i=701;i<1201;i++)add_edge(i,1499,1);
    for(int i=0;i<a;i++)
     for(int j=0;j<b;j++)
      if((__gcd(aa[i],bb[j]))!=1)add_edge(i+101,j+701,1);
    cout<<max_flow(0,1499)<<endl;
  }
}

Measured memory_bytes: 9436
#include<cstdio>
#include<cstring>

int main(){
    char str[1001];
    while(1){
        scanf("%s",str);
        if(str[0]=='0') break;
        int sum=0;
        for(int i=0;i<strlen(str);i++){
            sum += (str[i] - '0');
        }
        printf("%d\n",sum);
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#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()
#define MOD 1000000007
#define INF (1LL<<25)     //33554432
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void)
{
  int a, b;
  while(cin >> a >> b) {
    int tmp = a + b;
    cout << to_string(tmp).size() << endl;
  }
  return 0;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
string s, t;
int main() {
    cin >> s >> t;
    int slen = s.length();
    int tlen = t.length();
    string answer = s;
    bool result = false;

    if(slen < tlen) {
        cout << "UNRESTORABLE" << endl;
    }else {
        for(int i = slen-1; i >= tlen-1; --i) {
            bool ansflg = true;
            for(int j = 0; j < tlen; ++j) {
                if(s.at(i-j) != '?') {
                    if(s.at(i-j) != t.at(tlen-1-j)) {
                        ansflg = false;
                        break;
                    }
                }
            }
            if(ansflg) {
                int first = i-tlen+1;
                for(int k = 0; k < tlen; ++k) {
                    answer.at(first+k) = t.at(k);
                }
                result = true;
                break;
            }
        }

        if(!result) {
            cout << "UNRESTORABLE" << endl;
        }else {
            for(int i = 0; i < slen; ++i) {
                if(answer.at(i) == '?') {
                    answer.at(i) = 'a';
                }
            }
            cout << answer << endl;
        }
    }
}

Measured memory_bytes: 256
import math

K = int(input())
G = [[0] *(K+1) for i in range(K+1)]

for a in range(1,K+1):
  t = 0
  for b in range(1,K+1):
    w = math.gcd(a,b)
    G[a][b] = w
    t += w
  G[a][0] = t
#
t = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    w = G[a][b]
    t += G[w][0]
#
print(t)


Measured memory_bytes: 9268
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		double ax,ay,bx,by,cx,cy,px,py,sitaAB = 0,sitaBC = 0,sitaCA = 0;

		while(scanner.hasNext()){
			ax = scanner.nextDouble();
			ay = scanner.nextDouble();
			bx = scanner.nextDouble();
			by = scanner.nextDouble();
			cx = scanner.nextDouble();
			cy = scanner.nextDouble();
			px = scanner.nextDouble();
			py = scanner.nextDouble();

			sitaAB = Math.acos(prod(ax-px, ay-py, bx-px, by-py) / (range(ax, ay, px, py) * range(bx, by, px, py)));
			sitaBC = Math.acos(prod(bx-px, by-py, cx-px, cy-py) / (range(bx, by, px, py) * range(cx, cy, px, py)));
			sitaCA = Math.acos(prod(cx-px, cy-py, ax-px, ay-py) / (range(cx, cy, px, py) * range(ax, ay, px, py)));
			if(equal((sitaAB + sitaBC + sitaCA), Math.PI*2)){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}

	public static double prod(double x1, double y1, double x2, double y2){
		return ((x1*x2) + (y1*y2));
	}
	public static double range(double x1, double y1, double x2, double y2){
		return Math.sqrt(Math.pow(x2-x1, 2) + Math.pow(y2-y1, 2));
	}
	public static boolean equal(double a, double b){
		if((a-b) < 0.0000000001 && (a-b) > -0.0000000001){
			return true;
		}else{
			return false;
		}
	}
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, C;
ll D[35][35], c[505][505];
ll ans[3][35], res = 1e18;

int main(){
  cin >> N >> C;
  for (int i = 1; i <= C; i++){
    for (int j = 1; j <= C; j++){
      cin >> D[i][j];
    }
  }
  for (int i = 1; i <= N; i++){
    for (int j = 1; j <= N; j++){
      cin >> c[i][j];
      for (int k = 1; k <= C; k++){
        ans[(i+j)%3][k] += D[c[i][j]][k];
      }
    }
  }

  for (int i = 1; i <= C; i++){
    for (int j = 1; j <= C; j++){
      for (int k = 1; k <= C; k++){
        if (i == j || j == k || k == i) continue;
        res = min(res, ans[0][i] + ans[1][j] + ans[2][k]);
      }
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 5560
#include<iostream>
using namespace std;
int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
    int b,c;
    cin>>b>>c;
    if(a[b-1]==a[c-1]) cout<<"Yes";//判断
    else cout<<"No";
    return 0;//比赛时不可少
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = n / (a + b) * a;
	n %= a + b;
	if (n >= a) ans += a;
	else ans += n;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3560
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int A;
	while(~scanf("%d",&A) && A <= 9999)
	{
		int flag = 0;
		int a = A/1000;
		int b= A/100 % 10;
		int c = A/10 % 10 % 10;
		int d = A%10 %10 %10;
		if( a + b + c + d == 7 )	flag = 1; 
		if( a + b + c - d == 7 )	flag = 2; 
		if( a + b - c + d == 7 )	flag = 3; 
		if( a + b - c - d == 7 )	flag = 4; 
		if( a - b + c + d == 7 )	flag = 5; 
		if( a - b + c - d == 7 )	flag = 6; 
		if( a - b - c + d == 7 )	flag = 7; 
		if( a - b - c - d == 7 )	flag = 8; 
		if( flag == 1 )		printf("%d+%d+%d+%d=7\n",a,b,c,d);
		if( flag == 2 )		printf("%d+%d+%d-%d=7\n",a,b,c,d);
		if( flag == 3 )		printf("%d+%d-%d+%d=7\n",a,b,c,d);
		if( flag == 4 )		printf("%d+%d-%d-%d=7\n",a,b,c,d);
		if( flag == 5 )		printf("%d-%d+%d+%d=7\n",a,b,c,d);
		if( flag == 6 )		printf("%d-%d+%d-%d=7\n",a,b,c,d);
		if( flag == 7 )		printf("%d-%d-%d+%d=7\n",a,b,c,d);
		if( flag == 8 )		printf("%d-%d-%d-%d=7\n",a,b,c,d);
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll ans = 0;
  ll n;cin>>n;
  vi L(n);
  for(auto &a:L)cin>>a;
  sort(ALL(L));
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
	if(L[i]!=L[j] && L[j] != L[k] && L[k] < L[i] + L[j]){
	  ans++;
	}
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 1000000007
using namespace std;
int main()
{
 	speed_up
 	ll n,flag=1;cin>>n;
 	ll h[n];rep(i,0,n) cin>>h[i];
 	
 	rep(i,1,n)
 	{
	   	if(h[i]-1>=h[i-1])
	   	h[i]-=1;
				
	}
	
	for(ll i=1;i<n;i++)
	{
		if(h[i]<h[i-1])
		{
			cout<<"No";
			return 0;
		}
		}	
	 
	cout<<"Yes";
	
	
	
	
 return 0;
}

Measured memory_bytes: 1024