akhauriyash/Code-Regression huggingface dataset:
//解説AC A<<C<<B<<D が考えれてなかった

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    A--, B--, C--, D--;
    string S;
    cin >> S;

    for (int i = 1; i < N; ++i) {
        if (S.at(i - 1) == '#' && S.at(i) == '#' && ((A <= i && i <= C) || B <= i && i <= D)) {
            cout << "No" << endl;
            exit(0);
        }
    }
    if (C > D) {
        for (int i = B; i <= D; ++i) {
            if (S.at(i - 1) == '.' && S.at(i) == '.' && S.at(i + 1) == '.') {
                cout << "Yes" << endl;
                exit(0);
            }
        }
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 592
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

class option {
public:
  i64 a, b, c;
  option() :
    option(0, 0, 0) {
  }
  option(const i64 a, const i64 b, const i64 c) :
    a(a), b(b), c(c) {
  }
};

namespace std {
  std::istream& operator>>(std::istream& is, option& self) {
    return is >> self.a >> self.b >> self.c;
  }
}

int main() {
  i64 N;
  std::cin >> N;
  std::vector<option> options;
  tools::read(options, N);

  std::reverse(options.begin(), options.end());
  std::vector<option> dp;
  dp.reserve(N);
  dp.emplace_back(
    std::max(options.front().b, options.front().c),
    std::max(options.front().c, options.front().a),
    std::max(options.front().a, options.front().b)
  );
  for (i64 i = 1; i < N; ++i) {
    dp.emplace_back(
      std::max(options[i].b + dp.back().b, options[i].c + dp.back().c),
      std::max(options[i].c + dp.back().c, options[i].a + dp.back().a),
      std::max(options[i].a + dp.back().a, options[i].b + dp.back().b)
    );
  }
  std::cout << std::max({dp.back().a, dp.back().b, dp.back().c}) << std::endl;
  return 0;
}

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

int main() {int n,s=0;vector<int> a,b,c;int r=n+1;
    cin>>n;
   for(int i=0;i<n;i++)
   {int A;cin>>A;a.push_back(A);}
            for(int i=0;i<n;i++)
   {int A;cin>>A;b.push_back(A);}
            for(int i=0;i<n-1;i++)
   {int A;cin>>A;c.push_back(A);}
   for(int i=0;i<n;i++){
   s+=b[a[i]-1];if(r+1==a[i]){s+=c[r-1];}r=a[i];}
cout<<s<<endl;}

Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
L = []
for i in range(N):
    L.append(int(input()))
    
import itertools
m = 4
bit_list = list(itertools.product([i for i in range(m)], repeat=N))
ans = 10 ** 18
for bit in bit_list:
    retA = 0
    retB = 0
    retC = 0
    checkA = False
    checkB = False
    checkC = False
    cost = 0
    for i,j in enumerate(bit):
        if j == 1:
            retA += L[i]
            if checkA:
                cost += 10
            checkA = True
        if j == 2:
            retB += L[i]
            if checkB:
                cost += 10
            checkB = True
        if j == 3:
            retC += L[i]
            if checkC:
                cost += 10
            checkC = True
    if min(retA,retB,retC) != 0:
        ans = min(ans, abs(A-retA)+abs(B-retB)+abs(C-retC)+cost)
print(ans) 

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

int main(){
    char i,j;
    int a[3] = {1,0,0};
    int tmp;
    while(scanf("%c,%c",&i,&j) != EOF){
        if((i == 'A' && j == 'B') || (i == 'B' && j == 'A')){
            tmp=a[0];
            a[0]=a[1];
            a[1]=tmp;
        }
        else if((i == 'B' && j == 'C') || (i == 'C' && j == 'B')){
            tmp=a[1];
            a[1]=a[2];
            a[2]=tmp;
        }
        else if((i == 'A' && j == 'C') || (i == 'C' && j == 'A')){
            tmp=a[0];
            a[0]=a[2];
            a[2]=tmp;
        }
    }
    for(int i=0;i<3;i++){
        if(a[i] == 1){
            if(i == 0) cout << "A" << endl;
            else if(i == 1) cout << "B" << endl;
            else if(i == 2) cout << "C" << endl;
        }
    }
}

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

int main() {
	int n, c, k;
    cin >> n >> c >> k;
    vector<int> time(n);
    for (int i = 0; i < n; i++){
        cin >> time.at(i);
    }

    sort(time.begin(), time.end());

    int bus = 0;
    int num = 0;
    while (num < n){
              bus++;
        int limit = time.at(num) + k;
        int passenger = 1;
        num++;
        if (num == n){
            break;
        }
        while(limit >= time.at(num) && passenger < c){
            passenger++;
            num++;
            if (num == n){
            break;
            }
        }

    }

    cout << bus << endl;
}

Measured memory_bytes: 640
arr = list(map(int,list(input().split())))

X=arr[0]
Y=arr[1]


if Y%2==1:
	print('No')
	exit()

Y2=Y/2
if Y2<X :
	print('No')
	exit()
if X*2<Y2 :
	print('No')
	exit()

print('Yes')




Measured memory_bytes: 9172
import java.util.*;

class Main {
	
	public static int[] solve (int[] p, int[] w, int lim) {
		
		int maxP = 0, sum = 0;
		int[][] dp = new int[w.length + 1][lim + 1];
		
		for (int[] d : dp)
			Arrays.fill(d, -1);
		
		dp[0][0] = 0;
		for (int i = 0; i < w.length; i++) {
			for (int j = 0; j < lim + 1; j++) {
				if (dp[i][j] == -1) continue;
				dp[i + 1][j] = Math.max(dp[i][j],dp[i + 1][j]);
				if (j + w[i] < lim + 1) {
					dp[i + 1][j + w[i]] = Math.max(dp[i + 1][j + w[i]], dp[i][j] + p[i]);
				}
			}
		}
		
		for (int j = 0; j < lim + 1; j++) {
			if (maxP < dp[w.length][j]) {
				maxP = dp[w.length][j];
				sum = j;
			}
		}
		return new int[]{maxP,sum};
	}
	
	public static void main(String[] args) {
		
		int cnt = 1;
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			
			int w = Integer.parseInt(sc.nextLine());
			if (w == 0) break;
			int n = Integer.parseInt(sc.nextLine());
			int[] price = new int[n];
			int[] weight = new int[n];
			for (int i = 0; i < n; i++) {
				String[] str = sc.nextLine().split(",");
				price[i] = Integer.parseInt(str[0]);
				weight[i] = Integer.parseInt(str[1]);
			}
			int[] ans = solve(price,weight,w);
			System.out.println("Case " + cnt++ + ":");
			System.out.println(ans[0] + "\n" + ans[1]);
			
		}
		
	}
	
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int a,b,ans;
	cin>>a>>b;
	if(b<a)ans=2*a-1;
	if(a<b)ans=2*b-1;
	if(a==b)ans=2*a;
	cout<<ans<<endl;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n;
li a[333][333];
li table[333][333];

int main() {
    cin >> n;
    rin{
        rep(j, n) {
            cin >> a[i][j];
        }
    }

    li res = 0;
    rin{
        repp(j, i + 1, n) {
            li tmp = INF;
            rep(k, n) {
                if (k == j || k == i)continue;
                tmp = min(tmp, a[i][k] + a[k][j]);
            }
            //p4(i, j, tmp, a[i][j]);
            if (tmp > a[i][j]) {
                res += a[i][j];
            } else if (tmp < a[i][j]) {
                puts("-1");
                return 0;
            }
        }
    }
    cout << res << endl;



    return 0;
}

Measured memory_bytes: 4388
n,m = map(int,input().split())
A = [0]*n
for i in range(m):
    a,b = map(int,input().split())
    a-=1
    b-=1
    if a==0: A[b]+=1
    elif b==n-1: A[a]+=1
ok = False
for i in range(1,n-1):
    if A[i]>=2:
        ok = True
        break
if ok: print("POSSIBLE")
else: print("IMPOSSIBLE")

Measured memory_bytes: 4596
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define endl '\n';
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    // int n,k;
    // cin>>k>>n;
    // vi v(n);
    // rep(i,n)cin>>v[i];
    // vi sum;
    // rep(i,n-1)sum.pb(v[i+1]-v[i]);
    // sum.pb(v[0]+(k-v[n-1]));
    // Sort(sum);
    // fin(k-sum[sum.size()-1]);

    int x;cin>>x;
    ll ans=0;
    ans+=x/500*1000;
    x%=500;
    ans+=x/5*5;
    fin(ans);
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from collections import Counter
from heapq import heappop,heappush,heapify

H,W = map(int,input().split())
A = ''.join(input().rstrip() for _ in range(H))

q = list(-x for x in Counter(A).values())
heapify(q)

pop = lambda: -heappop(q)
push = lambda x: heappush(q,-x)

tasks = [4] * (H//2) * (W//2)
tasks += [2] * ((H%2) * (W//2) + (W%2) * (H//2))
tasks += [1] * ((H%2) * (W%2))

bl = True
for k in tasks:
    n = pop()
    if n < k:
        bl = False
        break
    push(n-k)

answer = 'Yes' if bl else 'No'
print(answer)

tasks

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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 dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;





int main(int argc, const char * argv[]) {
    
   

    cin.tie(0);
    ios::sync_with_stdio(false);
   
    
    int r,g; cin >> r >> g;
    cout << 2*g - r << endl;
    
    
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long MOD = 1000000007;

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

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

	int x, y;
	cin >> x >> y;

	int ans = 0;
	switch (x) {
	case 1:
		ans += 300000;
		break;
	case 2:
		ans += 200000;
		break;
	case 3:
		ans += 100000;
		break;
	default:
		//do-nothing.
		break;
	}

	switch (y) {
	case 1:
		ans += 300000;
		break;
	case 2:
		ans += 200000;
		break;
	case 3:
		ans += 100000;
		break;
	default:
		//do-nothing.
		break;
	}

	if (x == 1 && y == 1) {
		ans += 400000;
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
 
using namespace std;
 
 
int main(){
    int coin[6]={1,5,10,50,100,500},in,ans;
     
 
 while(1){
    ans=0;
    scanf("%d",&in);
     
    if(in==0)
      break;
 
    in=1000-in;
     
    for(int i=5;i>=0;i--){
        ans+=in/coin[i];
        in%=coin[i];
    }
     
    printf("%d\n",ans);
     
  }
    return 0;
}

Measured memory_bytes: 3164
#include <stdio.h>

int a[512][512];
int b[512][512];
int n;

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) {
			scanf("%d", &a[i][j]);
			b[i][j] = a[i][j];
		}

	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (b[i][j] > b[i][k] + b[k][j]) {
					printf("-1\n"); return 0;
				}
			}
		}
	}

	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (b[i][j] == b[i][k] + b[k][j] && b[i][k] > 0 && b[k][j] > 0) {
					b[i][j] = -1;
				}
			}
		}
	}

	long long total = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (b[i][j] > 0) {
				total += b[i][j];
			}
		}
	}
	printf("%lld\n", total / 2);
	return 0;
}

Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            //// 文字列の入力
            //string s = Console.ReadLine();

            //// 整数の入力
            //long n = long.Parse(Console.ReadLine());

            //// 文字列配列の入力
            //string[] inputStrArray = Console.ReadLine().Split(' ');

            //// 整数配列の入力
            //var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            string s = Console.ReadLine();

            string result = "";

            if (s == "A") {
                result = "T";
            } else if (s == "T") {
                result = "A";
            } else if (s == "G") {
                result = "C";
			} else {
                result = "G";
			}

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 25604
N, K = map(int, input().split())
X = list(map(int, input().split()))

if N == 1:
    print(abs(X[0]))
    exit()


flg = False

for x in X:
    if x < 0:
        flg = True

if flg is False:
    print(X[K - 1])
    exit()

flag2 = False

for x in X:
    if x > 0:
        flag2 = True

if flag2 is False:
    X.reverse()
    print(abs(X[K - 1]))
    exit()


def sol(lft, rgt):
    if X[lft] < 0 and X[rgt] < 0:
        return float('inf')
    elif X[lft] <= 0:
        return min(2 * abs(X[lft]) + X[rgt], abs(X[lft]) + 2 * X[rgt])
    else:
        return float('inf')


lft, rgt = 0, 0
ans = float('inf')
while True:

    if rgt == N - 1:
        break

    if rgt - lft + 1 < K:
        rgt += 1
        if rgt - lft + 1 == K:
            ans = min(ans, sol(lft, rgt))
            lft += 1
print(ans)


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 500 + 7;
int n, m, a[N][N], b[N][N], c[N][N];

void print(int x) {
  if (x) {
    cout << "#";
  } else {
    cout << ".";
  }
}

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

  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    for (int j = 1; j <= m; j++) {
      a[i][j] = (s[j - 1] == '#');
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i % 2 == 0) {
      b[i][1] = 1;
      for (int j = 2; j <= m; j++) {
        c[i][j] = 1;
      }
    } else {
      for (int j = 1; j < m; j++) {
        b[i][j] = 1;
      }
      c[i][m] = 1;
    }
    for (int j = 1; j <= m; j++) {
      b[i][j] |= a[i][j];
      c[i][j] |= a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      print(b[i][j]);
    }
    cout << "\n";
  }
  cout << "\n";
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      print(c[i][j]);
    }
    cout << "\n";
  }
}


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

#define F first
#define S second
#define pb push_back
#define mp make_pair

ll gcd(ll a, ll b){
	if (a == 0) return b;
	return gcd(b%a, a);
}

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

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

	ll n,i,j,mx = 1e9;

	string s;

	cin >> n >> s;

	ll a[n][2];
	ll r = 0 ,w = 0;

	for(i=0;i<n;i++)
	{
		if(s[i] == 'R')
		{
			r++;
		}
		else
		{
			w++;
		}
		a[i][0] = r;
		a[i][1] = w;
	}

	mx = min(r,w);
	for(i=0;i<n;i++)
	{
		ll re = a[i][0];
		ll wi = a[i][1];

		ll remr = r - re;
		ll remw = w- wi;

		ll tot = max(remr,wi);

		if(tot < mx)
			mx = tot;
	}

	cout << mx << endl;


}

Measured memory_bytes: 6900
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

const int MAX = 5100000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ll N; cin >> N;
  for(ll h = 1; h < 3501LL; h++) {
    for(ll w = 1; w < 3501LL; w++) {
      //cout << "ok" << endl;
      ll child = N*h*w;
      ll mother = 4*w*h-N*(h+w);
      //cout << child << " " << mother << endl;
      if(mother == 0) continue;
      if(child%mother == 0 && mother > 0){
        ll n = child/mother;
        printf("%lld %lld %lld\n", h, n, w);
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main() {
  int h,w,k;
  cin >> h >> w;
  cout << ((h%2 & w%2)?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;

import static java.lang.Character.toUpperCase;

public class Main {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String str = br.readLine();
            StringTokenizer s = new StringTokenizer(str, " ");
            for(int i = 0; i < 3; i++) {
                char c = toUpperCase(s.nextToken().charAt(0));
                System.out.print(c);
            }
        } catch (IOException e) {
            System.out.println("error");
        }
    }
}

Measured memory_bytes: 21204
#include<functional>
#include<algorithm>
#include<iterator>
#include<cstring>
#include<cstdio>
#include<vector>
using namespace std;
struct R{int v,z,c;}e[1111111];
int K[222222],cur[222222],ce=1;
void ins(int a,int b,int c)
{
	e[++ce]=(R){b,K[a],c};
	K[a]=ce;
}
void AE(int a,int b)
{
	ins(a,b,1);
	ins(b,a,0);
}
int s,t,d[222222];
bool BFS()
{
	static int q[222222],du,my;
	memset(d,0,sizeof(d));
	memcpy(cur,K,sizeof(cur));
	for(d[q[du=my=1]=s]=1;du<=my;)
	{
		int u=q[du++];
		for(int i=K[u];i;i=e[i].z)if(e[i].c&&!d[e[i].v])
		{
			d[e[i].v]=d[u]+1;
			q[++my]=e[i].v;
		}
	}
	return d[t];
}
int DFS(int u,int r)
{
	if(u==t)return r;
	int tmp=r;
	for(int&i=cur[u];i;i=e[i].z)if(e[i].c&&d[e[i].v]==d[u]+1)
	{
		int qwq=DFS(e[i].v,min(r,e[i].c));
		if(qwq)
		{
			r-=qwq;
			e[i].c-=qwq;
			e[i^1].c+=qwq;
			if(!r)return tmp;
		}
	}
	return tmp-r;
}
int Dinic()
{
	int r=0;
	for(;BFS();)r+=DFS(s,2333333);
	return r;
}
bool viz[222222];
int n,p[111111],u[111111],v[111111];
void dfs(int u,int pa,int gp)
{
	viz[u]=1;
	if(u<=n&&pa)
	{
		::u[pa-n]=gp;
		::v[pa-n]=u;
	}
	for(int i=K[u];i;i=e[i].z)if(!viz[e[i].v]&&e[i].c)
		dfs(e[i].v,u,pa);
}
int main()
{
	scanf("%d",&n);
	s=2*n;
	t=2*n+1;
	for(int i=2;i<=n;++i)AE(s,i);
	for(int i=1;i<n;++i)
	{
		int c;
		for(scanf("%d",&c);c--;)
		{
			int v;
			scanf("%d",&v);
			AE(v,i+n);
		}
		AE(i+n,t);
	}
	viz[s]=viz[t]=1;
	if(Dinic()!=n-1)return puts("-1"),0;
	dfs(1,0,0);
	for(int i=1;i<n;++i)if(!u[i])return puts("-1"),0;
	for(int i=1;i<n;++i)printf("%d %d\n",u[i],v[i]);
	return 0;
}

Measured memory_bytes: 20608
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<utility>
using namespace std;
#define MS(m,z) memset(m,z,sizeof(m))
typedef unsigned U; typedef pair<int,int > P; typedef long long ll;
void inp();
int main(){
#ifdef XS
	//freopen(".in","r",stdin);
#endif
	//int n;scanf("%d",&n);for(int i=1;i<=n;i++)
	inp();
	return 0;
}
void inp(){
	int n;
	scanf("%d",&n);
	int a,b,c;
	a=n/100;
	b=(n%100)/10;
	c=(n%10);
	char ans[][10]={
		"No","Yes"
	};
	puts(ans[a==c]);
}
//A.cc by xsthunder at Sat Aug 12 20:01:08 2017


Measured memory_bytes: 128
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]
last = gets.chomp[-1].to_i
drf = ["hon","pon","bon"]
drf.each do |arr_name|
  eval(
    "if(#{arr_name}.include?(last))
       puts '#{arr_name}'
       exit
     end")
end


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

int main()
{
	int n,m,a,i;
	while(cin >> n, n)
	{
		for(a=i=0,m=5; i<13; i++,m*=5)
		{
			a+=n/m;
		}
		cout << a << endl;
	}
}

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

int main()
{
	int N, M;
	cin >> N >> M;
	int a[50][2];
	for (int i = 0; i < M; i++) {
		cin >> a[i][0] >> a[i][1];
	}
	int b[50] = { 0 };
	for (int i = 0; i < M; i++) {
		b[a[i][0] - 1]++;
		b[a[i][1] - 1]++;
	}
	for (int i = 0; i < N; i++) {
		cout << b[i] << endl;
	}
}

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

#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()

using namespace std;

using pii = pair<int, int>;

int main() {
    auto cmp = [](pii p1, pii p2) {
        return p1.first > p2.first || p1.first == p2.first && p1.second < p2.second;
    };
    while (true) {
        int n, m;
        cin >> n >> m;
        if (n == 0) {
            break;
        }
        vector<int> count(m);
        REP(i, n) {
            REP(j, m) {
                int x;
                cin >> x;
                count[j] += x;
            }
        }
        vector<pii> v(m);
        REP(i, m) v[i] = pii(count[i], i);
        sort(all(v), cmp);
        REP(i, m) {
            char c = (i == m - 1 ? '\n' : ' ');
            cout << v[i].second + 1 << c;
        }
    }
    cout << flush;
    return 0;
}


Measured memory_bytes: 3036
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,T,sum=0;cin>>n>>T;
  int t[n];
  for(int i=0;i<n;i++) cin>>t[i];
  for(int i=0;i<n-1;i++){
    if(t[i+1]-t[i]<=T){
      sum+=t[i+1]-t[i];
    }
    else sum+=T;
  }
  sum+=T;
  cout<<sum<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define MAX 10001
#define NIL -1

int S[MAX];

void makeSet(int x) {
    S[x] = x;
}

int findSet(int x) {
    if (S[x]==NIL) return NIL;
    else {
        while(S[x]!=x) {
            x = S[x];
        }
        return x;
    }
}

void unite(int x, int y) {
    x = findSet(x);
    y = findSet(y);

    if (x==NIL || y==NIL) return;

    S[y] = x;
}

int main() {
    int n, q;
    int x, y, com;

    scanf("%d %d", &n, &q);

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

    for (int i=0; i<q; i++) {
        scanf("%d %d %d", &com, &x, &y);

        if (com==0) unite(x, y);
        else {
            if (findSet(x)==findSet(y)) printf("1\n");
            else printf("0\n");
        }
    }

    return 0;
}


Measured memory_bytes: 2724
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int mod=1000000007;
inline int rd(){
	char c=getchar();int x=0;
	for(;c<'0'||c>'9';c=getchar());
	for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0';
	return x;
}
int n,ans=1;
int a[200010],fa[200010],dep[200010],size[200010];
bool vis[200010]={false};
vector<int>vec[200010],v,vv;
int power(int x,int k){
	int res=1,s=x;
	for(;k;k>>=1){
		if(k&1)
			res=(ll)res*s%mod;
		s=(ll)s*s%mod;
	}
	return res;
}
int solve(int root){
	v.clear();v.push_back(root);
	vis[root]=true;
	for(int i=0;i<v.size();i++){
		int x=v[i];
		size[x]=1;fa[x]=0;a[x]=0;
		for(int j=0;j<vec[x].size();j++){
			int y=vec[x][j];
			if(!vis[y]){
				v.push_back(y);
				vis[y]=true;
			}
		}
	}
	int total=0;
	for(int i=0;i<v.size();i++)
		for(int j=0;j<vec[v[i]].size();j++)
			a[vec[v[i]][j]]++,total++;
	if(total/2!=v.size())
		return 0;
	vv.clear();
	for(int i=0;i<v.size();i++)
		if(a[v[i]]==1)
			vv.push_back(v[i]);
	for(int i=0;i<vv.size();i++){
		int x=vv[i];
		for(int j=0;j<vec[x].size();j++){
			int y=vec[x][j];
			if(--a[y]){
				fa[x]=y;
				if(a[y]==1)
					vv.push_back(y);
				else
					root=y;
			}
		}
	}
	for(int x=root;;){
		for(int i=0;i<vec[x].size();i++){
			int y=vec[x][i];
			if(a[y]>1&&fa[y]!=x){
				fa[x]=y;x=y;
				break;
			}
		}
		if(x==root)
			break;
	}
	int res=1;
	for(int i=0;i<vv.size();i++){
		int x=vv[i];
		res=(ll)res*size[x]%mod;
		if(x<fa[fa[x]])
			size[fa[x]]+=size[x];
	}
	for(int x=root;;){
		if(x>fa[fa[x]]){
			root=fa[x];
			break;
		}
		x=fa[x];
		if(x==root)
			return 0;
	}
	for(int x=root;;){
		res=(ll)res*size[x]%mod;
		if(x<fa[fa[x]])
			size[fa[x]]+=size[x];
		x=fa[x];
		if(x==root)
			break;
	}
	return power(res,mod-2);
}
int main(){
	n=rd();
	for(int i=1;i<=n*2;i++)
		vec[i].clear();
	for(int i=1;i<=n*2;i++){
		int x=rd(),y=rd();
		vec[x].push_back(n+y);
		vec[n+y].push_back(x);
	}
	for(int i=1;i<=n*2;i++)
		ans=(ll)ans*i%mod;
	for(int i=1;i<=n*2;i++)
		if(!vis[i]){
			int res=solve(i);
			for(int j=0;j<v.size();j++){
				vis[v[j]]=false;
				reverse(vec[v[j]].begin(),vec[v[j]].end());
			}
			res+=solve(i);
			if(res>=mod)
				res-=mod;
			ans=(ll)ans*res%mod;
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 16504
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    // - - - - o o
    // - - - x - o
    // - - o - - o
    // - x - - - o
    // o - - - - o  (1,1) (3,3)
    // o o o o
    // o o x o
    // o o o o
    // o x o o
    // o o o o
    for(int i = B+1; i <= D; i++) {
        cout << 'U';
    }
    for(int i = A+1; i <= C; i++) {
        cout << 'R';
    }
    for(int i = D-1; i >= B; i--) {
        cout << 'D';
    }
    for(int i = C-1; i >= A; i--) {
        cout << 'L';
    }
    cout << 'L';
    for(int i = B+1; i <= D+1; i++) {
        cout << 'U';
    }
    for(int i = A; i <= C; i++) {
        cout << 'R';
    }
    cout << 'D';
    cout << 'R';
    for(int i = D-1; i >= B-1; i--) {
        cout << 'D';
    }
    for(int i = C; i >= A; i--) {
        cout << 'L';
    }
    cout << 'U';
    cout << endl;
    //UURRDDLLLUUURRDRDDDLLU
}


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

const int N = 2e5 + 10;
const int M = 2005;
const int mod = 1e9 + 7;

int a[N], b[N];
int dp[M << 1][M << 1], p[N], inv[N];

int mod_pow(int x, int n){
	int ret = 1;
	while (n){
		if (n & 1) ret = 1LL * ret * x % mod;
		x = 1LL * x * x % mod;
		n >>= 1;
	}
	return ret;
}

int C(int x, int y){
	if (x < y) return 0;
	return 1LL * p[x] * inv[y] % mod * inv[x - y] % mod;
}

int main(){
	p[0] = 1; inv[0] = 1;
	for (int i = 1; i < N; i++) p[i] = 1LL * p[i - 1] * i % mod;
	for (int i = 1; i < N; i++) inv[i] = mod_pow(p[i], mod - 2);
	int n, k, ans;
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) scanf("%d %d",&a[i],&b[i]);
	for (int i = 1; i <= n; i++) dp[M - a[i]][M - b[i]]++;
	for (int i = 2; i <= M * 4 - 2; i++){
		for (int j = 1; j < i; j++){
			k = i - j;
			if (max(j, k) > M * 2 - 1) continue;
			if (j > 1){
				dp[j][k] += dp[j - 1][k];
				dp[j][k] %= mod;
			}
			if (k > 1){
				dp[j][k] += dp[j][k - 1];
				dp[j][k] %= mod;
			}
		}
	}
	ans = 0;
	for (int i = 1; i <= n; i++){
		ans += dp[M + a[i]][M + b[i]];
		ans %= mod;
	}
	for (int i = 1; i <= n; i++) ans = (ans - C((a[i] + b[i]) * 2, a[i] * 2) + mod) % mod;
	ans = 1LL * ans * mod_pow(2, mod - 2) % mod;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 66176
#include<bits/stdc++.h>
#define fi first
#define se second
#define bug cout<<"--------------"<<endl
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=1e9;
const ll llf=1e18;
const int mod=1e9+7;
const int maxn=1e5+10;
char s[55];
int k;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>s+1;
	k=strlen(s+1);
	int ans=0;
	for(int i=1;i<=k;i++){
		if(s[i]=='o') ans++;
	}
	if(ans+15-k>=8) puts("YES");
	else puts("NO");
	return 0;
}


Measured memory_bytes: 256
n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

al = list(map(lambda x: x - 1, al))

s = 0
a_prev = -100
for a in al:
    s += bl[a]
    if a_prev != (n - 1) and a - a_prev == 1:
        s += cl[a_prev]
    a_prev = a


print(s)


Measured memory_bytes: 3064
import sys
import os
import math

N=int(input())
count = 0

for i in range(1, N+1):
    if i % 2 == 0:
        continue
    else:
        yakusu = 0
        for j in range(1, i+1):
            if i % j == 0:
                yakusu += 1

    if yakusu == 8:
        count += 1

print(count)

Measured memory_bytes: 9096
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp {
	char name[100];
	int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}

P dequeue(){
	P x = Q[head];
	head = (head + 1) % LEN;
	return x;
}

int min(int a,int b){
	return a<b ? a:b;
}

int main(){
	int elaps = 0, c;
	int i, q;
	P u;
	
	
	scanf("%d %d",&n,&q);
	for(i=1;i<=n;i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	head = 1; tail = n + 1;
	
	while(head != tail){
		u = dequeue();
		c = min(q, u.t);
		u.t -= c;
		elaps += c;
		if(u.t > 0) enqueue(u);
		else{
			printf("%s %d\n",u.name,elaps);
		}
	}
	return 0;
}





Measured memory_bytes: 11944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e18+7;
const ll MOD=1e9+7;
const ll N = 1000;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	vector<ll> a(100001);
	FOR(i,0,n){
		ll k;
		cin>>k;
		a[k]++;
	}
	ll num2=0;
	ll ans=0;
	FOR(i,1,100001){
		if(a[i]%2==1)ans++;
		else if(a[i]>0){
			num2++;
		}
	}
	if(num2%2==0)ans+=num2;
	else ans+=num2-1;
	pri(ans);
}

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

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#define pb push_back
#define ss second
#define ff first
#define N 1000006
#define inf 1000000009
#define ll long long
#define mid(a,b) (a+b)/2
#define pii pair<int,int>

using namespace std;

const int mod = 1e9+7;
int a[N],lc[N],x,cnt,n,pr;
ll ans,jog,l;
int b[N];
vector <int> v;

ll pw(ll a,ll b){
	if(b == 0) return 1;
	ll x = pw(a,b / 2);
	if(b % 2) return (((x * x) % mod)*a)%mod;
	return (x * x) % mod;
}

int main()
{
	for(int i = 2;i <= 1e6;i++) b[i] = i;
	for(int i = 4;i <= 1e6;i += 2) b[i] = 2;
	for(int i = 3;i*i <= 1e6;i += 2)
		if(b[i] == i) for(int j = i * i;j <= 1e6;j += i) if(b[j] == j) b[j] = i;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",&a[i]);
		x = a[i],cnt = 0,pr = 0;
		while(x > 1){
			if(b[x] != pr){
				lc[pr] = max(lc[pr],cnt);
				cnt = 0;
			}
			pr = b[x];
			x /= b[x];
			cnt++;
		}
		lc[pr] = max(lc[pr],cnt);
	}
	l = 1;
	for(int i = 2;i <= 1e6;i++)
		if(lc[i]) l = (l * pw(i,lc[i])) % mod;
	for(int i = 1;i <= n;i++){
		ans = (ans + (l * pw(a[i],mod - 2)) % mod) % mod;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 8448
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoders {
	class Program {
		static void Main(string[] args) {

			var inputArray = retreiveIntArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}

			var N = inputArray[0];

			var maisu = N / 2;
			var amari = N % 2;
			if (amari != 0) {
				maisu = maisu + 1;
			}


			//答えの出力
			var ans = maisu;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray =  Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static int[] retreiveIntArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var intArray = inputArray.Select(s => int.Parse(s));
			return intArray.ToArray();
		}
	}
}


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

int main() {
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  s.erase(unique(s.begin(), s.end()), s.end());
  char a = 'a';
  bool ok = true;
  for (int i = 0;i<26;i++) {
    if (s.find(a) > s.size()) {
      cout << a-- << endl;
      ok = false;
      break;
    }
    else a++;
  }
  if (ok) cout << "None" << endl;
}
  

  


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>

using namespace std;

int f(int N)
{
  int sum = 0;
  while (N > 0) {
    sum += N % 10;
    N /= 10;
  }
  return sum;
}

int main()
{
  int N;
  cin >> N;
  cout << (N % f(N) == 0 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int A = sc.nextInt(); // 1
    int B = sc.nextInt(); // 0
    int C = sc.nextInt(); // -1
    int K = sc.nextInt(); // total

    int sum = 0;

    if(A<K){
      K = K -A;
      sum +=A;
    }else{
      System.out.println(K);
      return;  
    }
    if(B<=K){
      K = K - B;
    }else{
      System.out.println(K);
      return;  
    }
    System.out.println(sum-K);  
    return;
  }
}





Measured memory_bytes: 35760
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();

            Map<Integer, Integer> map = new HashMap<>();
            for (int x = 1; x <= 1000; x++) {
                for (int y = 1; y <= 1000; y++) {
                    for (int z = 1; z <= 1000; z++) {
                        int key = x * x + y * y + z * z + x * y + y * z + z * x;
                        if (key > N) break;
                        map.merge(key, 1, Integer::sum);
                    }
                }
            }
            for (int i = 1; i <= N; i++) {
                out.println(map.getOrDefault(i, 0));
            }
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



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

using namespace std;
int n, k;
long long a[100005], ans = (long long)2e9;
int main()
{

    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i + k - 1 <= n; i++)
    {
        int l = i, r = i + k - 1;
        ans = min(ans, a[r] - a[l] + min(abs(a[l]), abs(a[r])));
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

//----------------------------------------------------------------

int main()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll cnt = 0;
    for (int i = 0; i < s.size() - 1; i++)
    {
        if (s.at(i) != s.at(i + 1))
        {
            cnt++;
        }
    }
    cout << cnt + 1 << endl;
}


Measured memory_bytes: 512
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val S = readInputLine().toCharArray()

    val nums = BooleanArray(1000)
    
    nums[(S[0] - '0').toInt() * 100 + (S[1] - '0').toInt() * 10 + (S[2] - '0').toInt()] = true

    for (i in 3 until S.size) {
        val num = (S[i] - '0').toInt()
        val added = mutableSetOf<Int>()
        for (j in 0..999) {
            if (nums[j]) {
                val digit1 = j / 100
                val digit2 = (j - digit1 * 100) / 10
                val digit3 = j % 10
                added.add(digit1 * 100 + digit2 * 10 + num)
                added.add(digit1 * 100 + digit3 * 10 + num)
                added.add(digit2 * 100 + digit3 * 10 + num)
            }
        }
        for (a in added) {
            nums[a] = true
        }
    }
    
    var ans = 0
    
    for (i in 0..999) {
        if (nums[i]) {
            ans++
        }
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 119092
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORr(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORr(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int mod = 1000000007;
int dp[100005][13];

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

  int n = s.size();

  dp[0][0] = 1;
  int digit = 1;
  REP(i, n){
    if(s[n-1-i] == '?'){
      REP(j, 10){
        REP(k, 13){
          dp[i+1][(digit*j+k)%13] = (dp[i+1][(digit*j+k)%13] + dp[i][k])%mod;
        }
      }
    }else{
      int j = s[n-1-i] - '0';
      REP(k, 13){
        dp[i+1][(digit*j+k)%13] = (dp[i+1][(digit*j+k)%13] + dp[i][k])%mod;
      }
    }
    digit = (digit*10)%13;
  }
  cout << dp[n][5] << endl;
}

Measured memory_bytes: 5504
#include<iostream>
using namespace std;
int dp[5005][5005];
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int maxi=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(i==0&&s[i]==s[j])dp[i][j]=1;
			else if(s[i]==s[j]&&j-i>dp[i-1][j-1]){
				dp[i][j]=dp[i-1][j-1]+1;
			}
			maxi=max(maxi,dp[i][j]);
		}
	}
	cout<<maxi;
}

Measured memory_bytes: 96768