akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;

int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    vector<int> a(n+1);
    vector<int> b(n+1,0);
    
    int sum = 0;
    
    rep(i,n) cin >> a[i];
    rep(i,n){
        if(a[i] > n) sum++;
        else b[a[i]]++;
    }
    
    int s = n;
    
    for(int i = 1; i <= n; i++){
        if(i<=b[i]){
            sum += b[i] - i;
            s -= b[i];
        } else if(i>b[i] or i > s){
            sum += b[i];
        }
    }
    cout << sum << endl;

}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    string s, t;
    cin >> s >> t;
    map<char, ll> s_map;
    map<char, ll> t_map;
    map<string, ll> _map;
    for(size_t i=0;i<s.size(); i++)
    {
        s_map[s[i]]++;
        //_map[s[i]]++;
    }
    for(size_t i=0;i<t.size(); i++)
    {
        t_map[t[i]]++;
        //_map[t[i]]++;
    }
    string _s = "", _t = "";
    for (auto it = s_map.begin(), e = s_map.end(); it != e; ++it) {
        for(size_t i=0;i<it->second; i++)
        {
            _s += it->first;
        }
    }
    for (auto it = t_map.rbegin(), e = t_map.rend(); it != e; ++it) {
        for(size_t i=0;i<it->second; i++)
        {
            _t += it->first;
        }
    }
    _map[_s]++, _map[_t]++;
    bool ok = false;
    cerr << _s << ":" << _t << endl;
    for(auto i : _map)
    {
        cerr << i.first << endl;
        if(i.first == _s && i.first != _t) ok = true;
        break;
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3604
# 参考にした提出:https://atcoder.jp/contests/abc168/submissions/16604668 #
from collections import deque
n,m = map(int,input().split())
l = [[] for i in range(n+1)]
for i in range(m):
    a,b = map(int,input().split())
    l[a].append(b)
    l[b].append(a)
d = [-1] * (n+1)
d[0],d[1] = 0,0
queue = deque()
queue.append(1)
while queue:
    x = queue.popleft()
    for i in l[x]:
        if d[i] == -1:
            d[i] = x
            queue.append(i)
print('Yes')
for i in d[2:]:
    print(i)

Measured memory_bytes: 34700
h, w = map(int, input().split())
b = []
temp = []
ans = []
for i in range(h):
  b.append(input())

for i in range(h):
  for j in range(w):
    count = 0
    if b[i][j] == "#":
      temp.append("#")
    else:
      # 左右
      if not j - 1 < 0:
        if b[i][j-1] == "#":
          count += 1 

      if not j + 1 >= w:
        if b[i][j+1] == "#":
          count += 1
      # 上
      if not i - 1 < 0:
        if b[i-1][j] == "#":
          count += 1
        
        if not j - 1 < 0:
          if b[i-1][j-1] == "#":
            count += 1

        if not j + 1 >= w:
          if b[i-1][j+1] == "#":
            count += 1
      
      # 下
      if not i + 1 >= h:
        if b[i+1][j] == "#":
          count += 1
        
        if not j - 1 < 0:
          if b[i+1][j-1] == "#":
            count += 1

        if not j + 1 >= w:
          if b[i+1][j+1] == "#":
            count += 1
        
      temp.append(str(count))

for i in range(h):
  print("".join(temp[i*w:i*w+w]))

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int X=scan.nextInt();
	int check=0;
    int Y=X;
    if(X>2){
	for(int i=X;check==0;i++){
      for(int j=2;j<i;j++){
        if(i%j==0){
          break;
        }
        if(j==i-1){
			check=1;
        }
      }
      Y=i;
    }
    }
    System.out.println(Y);
  }
}

Measured memory_bytes: 23636
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

#define sd(n) scanf("%d",&n) == 0
#define sc(n) scanf(" %c",&n) == 0

#define pl(x) printf("%lld", x)

#define rep(i, begin, end) for (decltype(begin) i = begin; i < end; i++)


using namespace std;

char r1[200];
char r2[200];

int main() {
	int n; 
	sd(n);
	rep(i, 0, n) {
		char c;
		sc(c);
		r1[i] = c;
	}
	rep(i, 0, n) {
		char c;
		sc(c);
		r2[i] = c;
	}

	long long sum = (long long)6;
	int index = 2;
	int last = 2;
	if (r1[0] == r2[0]) {
		sum = (long long)3;
		last = 1;
		index = 1;
	}

	rep(i, index, n) {

		if (r1[i] == r2[i]) {
			if (last != 1) {
				last = 1;
				continue;
			}
			sum *= (long long)2;
		}
		else {
			if (last == 2) {
				sum *= (long long)3;
			}
			else {
				sum *= (long long)2;
			}
			last = 2;
			i++;
		}
		sum %= (long long)1000000007;

	}

	pl(sum);
}

Measured memory_bytes: 256
function main(input) {
    var nums = input.split('\n')[1].split(' ').map((n) => parseInt(n, 10))

    var count = 0;
    while(nums.every((n) => (n%2) === 0)) {
        count++;
        nums = nums.map((n) => n/2);
    }
    console.log(count);

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using namespace std;


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

long long INF = 1LL << 40;
long long dp[100010];
int h[1000010];
int K,N;
int main(){
    cin >> N >> K;
    for(int i = 0; i < N; i++)cin >> h[i];

    for(int i = 0 ; i < 100010; i++)dp[i] = INF;

    dp[0] = 0;

    for(int i = 0 ; i < N; i++){
        for(int j = 1; j <= K; j++){
            chmin(dp[i+j],dp[i] + abs(h[i] - h[i + j]));
        }
    }

    cout << dp[N-1] << endl;

}

Measured memory_bytes: 3328
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if v<=w:
  print('NO')
else:
  if a<b and (a+v*t)>=(b+w*t):
    print('YES')
  elif a>b and (a-v*t)<=(b-w*t):
    print('YES')
  else:
    print('NO')

Measured memory_bytes: 9192
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String S = sc.next();

        System.out.println(solve(S) ? "yes" : "no");

        sc.close();
    }

    static boolean solve(String S) {
        return S.chars().distinct().count() == S.length();
    }
}

Measured memory_bytes: 27092
# -*- coding: utf-8 -*-
from sys import stdin

s_in = lambda: stdin.readline()[:-1]  # s = s_in()


def replace_digits(x):
    if x == '1':
        return '9'
    else:
        return '1'

n = s_in()
ans = ''
for x in list(n):
    ans += replace_digits(x)
print(ans)


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> ivv;


int main()
{
	int n;
	
	while(cin >> n,n)
	{
		int ans = 0;
		vector<string> v;
		REP(i,n)
		{
			string tmp;
			cin >> tmp;
			v.PB(tmp);
		}
		
		REP(i,n/2)
		{
			string s1,s2;
			if(v[2*i][0] != v[2*i + 1][0])ans++;
		}
		
		cout << ans << endl;
		
	}
			
	
	return 0;
}

Measured memory_bytes: 3088
#include<stdio.h>
long long a[100010];
int main()
{
	for(int i=1;i<=100001;i++)
	a[i]=i*i;
	int n;
	scanf("%d",&n);
	int k=0;
	for(int i=1;i<100001;i++)
	{
		if(a[i]>n)
		{
			k=i;
			break;
		}
	}
	printf("%d\n",a[k-1]);
	return 0;
}

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

int main(void){
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int count = 0;
  for(int i = 0;i <= a;i++){
    for(int j = 0;j <= b;j++){
      for(int k = 0;k <= c;k++){
        if(500*i+100*j+50*k == x){
          count++;
        }
      }
    }
  }
  cout << count << endl;
}


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

public class Main{
	
	static int[][] map;
	
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		Main app = new Main();
		
		while(true){
			map = new int[12][];
			for(int i = 0; i < 12; i++)
				map[i] = app.toIntegerArrays(reader.readLine().toCharArray());
			
			int count = 0;
			for(int i = 0; i < 12; i++){
				for(int j = 0; j < 12; j++){
					if(map[i][j] == 1){
						app.check(i, j);
						count++;
					}
				}
			}
			System.out.println(count);
			
			if(reader.readLine() == null) break;
		}
		isr.close();
		reader.close();
	}
	
	public void check(int x, int y){
		if(x > 11 || y > 11 || x < 0 || y < 0 || map[x][y] == 0) return;
		map[x][y] = 0;
		check(x + 1, y);
		check(x - 1, y);
		check(x, y + 1);
		check(x, y - 1);
	}
	public int[] toIntegerArrays(char[] array){
		int[] result = new int[12];
		int i = 0;
		for(int var : array) result[i++] = (int)var - (int)'0';
		return result;
	}
	
}

Measured memory_bytes: 24144
def dot(a,b):
    return a[0]*b[0] + a[1]*b[1]

x1, y1, x2, y2 = map(int, input().split()) 
a = [x2-x1, y2-y1]
q = int(input())
for i in range(q):
    x,y = map(int, input().split()) 
    b = [x-x1, y-y1]
    co = dot(a,b) / dot(a,a)
    print(a[0]*co+x1, a[1]*co+y1)

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


int main()
{
	string s;
	cin >> s;
	int n = s.length();
	int ans=0;
	s+='1';
	for(int i=0;i<n;i++)
	{
		if(s[i]==s[i+1]){
			i+=2;
			ans++;
			if(i<n)
			ans++;
		}
		else
		{
			ans++;
		}
	}
	cout<<ans;
	


} 


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

#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)

int main() {
    int n;
    cin >> n;
    set<int> s;
    rep(i, n) {
        int x;
        cin >> x;
        s.insert(x);
    }
    cout << s.size() << endl;
}


Measured memory_bytes: 256
#include <iostream>

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

//conversion
//------------------------------------------
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();
}

//math
//-------------------------------------------
template <class T>
inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const long long INFL = __LONG_LONG_MAX__ / 10;
const int INFI = __INT_MAX__ / 10;

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
// #define dump(x) cerr << #x << " = " << (x) << endl;
// #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
//                       << " " << __FILE__ << endl;

uint64_t popcnt(uint64_t n)
{
    uint64_t c = 0;
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555);
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333);
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f0f0f0f0f);
    c = (c & 0x00ff00ff00ff00ff) + ((c >> 8) & 0x00ff00ff00ff00ff);
    c = (c & 0x0000ffff0000ffff) + ((c >> 16) & 0x0000ffff0000ffff);
    c = (c & 0x00000000ffffffff) + ((c >> 32) & 0x00000000ffffffff);
    return (c);
}

int N;
// const int LimitN = 100;

int main()
{
    ios::sync_with_stdio(false);

    int A, B;
    cin >> A >> B;

    cout << max(0, (A - 2 * B)) << endl;
}

Measured memory_bytes: 888
#include <stdio.h>

int main(void) {
    int n;
    scanf("%d", &n);

    char s[n];
    scanf("%s", s);

    int w[n];
    int e[n];
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            w[i] = s[i] == 'W' ? 1 : 0;
            e[(n - 1) - i] = s[(n - 1) - i] == 'E' ? 1 : 0;
            continue;
        }

        if (s[i] == 'W') {
            w[i] = w[i - 1] + 1;
        } else {
            w[i] = w[i - 1];
        }

        if (s[(n - 1) - i] == 'E') {
            e[(n - 1) - i] = e[(n - 1) - i + 1] + 1;
        } else {
            e[(n - 1) - i] = e[(n - 1) - i + 1];
        }
    }

    int min;
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            min = w[i] + e[i] - 1;
            continue;
        }
        int total = w[i] + e[i] - 1;
        // printf("%d: w:%d e:%d\n", i, w[i], e[i]);
        if (min > total) {
            // printf("total: %d\n", total);
            min = total;
        }
    }

    printf("%d\n", min);

    return 0;
}


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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	bool end = true;

	while (end) {
		c -= b;
		if (c <= 0) {
			cout << "Yes" << endl;
			break;
		}
		a -= d;
		if (a <= 0) {
			cout << "No" << endl;
			break;
		}

	}

}


Measured memory_bytes: 3580
/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define   pb              push_back
#define   REP(i,n)        for(int i=1;i<=n;i++)
#define   FOR(i,a,b)      for(int i=a;i<=b;i++)
#define   all(v)          v.begin(),v.end()
#define   F               first
#define   S               second
#define   vl              vector<LL>
#define   itr             ::iterator it
#define   lb              lower_bound
#define   ub              upper_bound
#define   LL              long long
#define   ULL             unsigned long long
#define   ret             return 
#define   sz(x)           (LL)x.size()
LL n,i,j,ans = 0,x,y,dp[1000000],w[1000000],b[1000000],M = (LL)1E9+7;
vector <LL> v[100000+10],leaf ;
void dfs(LL node,LL par)
{  if(v[node].size()==1 and v[node][0]==par) 
   {  dp[node] = 2 ; 
      b[node] = w[node] = 1; 
      ret ;  
   }  
   w[node] = 1,b[node] = 1 ;     
   for(auto i:v[node])
   {  if(i==par) continue ; 
      dfs(i,node) ;
      w[node] = (w[node] * (w[i] + b[i]+M)%M)%M ; 
      b[node] = (b[node] * w[i])%M ; 
   }
   dp[node] = (w[node] + b[node] + M)%M ; 
} 
int main()
{   // Read the constraints,highlights,Time Limit,Test Cases
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n ; 
    REP(i,n-1) cin>>x>>y,v[x].pb(y),v[y].pb(x) ; 
    dp[1] = 2,w[1] = 1,b[1] = 1 ; 
    dfs(1,0) ;
    cout<<(dp[1]+M)%M<<endl;   
}
//Check for 0,1 and other corner cases.

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

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

    int ans = 0;
    while (n > 0) {
        n = n / k;
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
K, S = gets.chomp.split.map{|v| v.to_i}
x = y = z = (0..K).to_a

c = 0
(0..K).to_a.each do |xv|
  xs = S - xv
  break if xs < 0
  next if 0 < xs - K - K

  (0..K).to_a.each do |yv|
    break if xs - yv < 0
    ys = xs - yv
    next if 0 < ys - K

    c += 1
  end
end

puts c



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

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

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

int main()
{
    string s;
    cin >> s;
    int q;
    cin >> q;
    int x, f;

    string bef, aft;
    char c;
    int ok = 1;

    for (int i = 0; i < q; i++) {
        cin >> x;
        if (x == 1) ok = 1 - ok;
        if (x == 2) {
            cin >> f >> c;
            if (ok) {
                if (f == 1) bef = c + bef;
                if (f == 2) aft = aft + c;
            } else {
                if (f == 1) aft = aft + c;
                if (f == 2) bef = c + bef;
            }
        }
    }
    string tmp = bef + s + aft; 
    if (ok) cout << tmp << endl;
    else {
        reverse(tmp.begin(), tmp.end());
        cout << tmp << endl;
    }
    return 0;
}



Measured memory_bytes: 1512
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #ここにコード
    #input
    from collections import Counter
    import itertools
    N = int(input())

    dp = [[0, 0] for _ in range(N)]
    for i in range(N):
        S = str(input())
        T = []
        for s in S:
            if s == "(":
                T.append(1)
            else:
                T.append(-1)
        x = list(itertools.accumulate(T))[-1]
        y = min(itertools.accumulate(T))
        dp[i] = [x, y]


    #output
    dp1 = [[x, y] for x, y in dp if x >= 0]
    dp2 = [[x, y] for x, y in dp if x < 0]
    dp1 = sorted(dp1, key = lambda x:x[1], reverse = True)
    dp2 = sorted(dp2, key = lambda x:x[0]-x[1], reverse = True)
    dp = dp1 + dp2

    checker = 0
    for p in dp:
        if checker + p[1] < 0:
            print("No")
            exit()
        checker += p[0]

    if checker == 0:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int n;
    cin >> n;

    // 処理
    int sum  = 0;
    int temp = n;
    while (temp > 0) {
        sum += temp % 10;
        temp /= 10;
    }
    // 出力

    cout << (n % sum == 0 ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,k;
int main() {
    set<int> s;
    cin>>n>>k;
    for(int i=1;i<=k;i++) {
        int d;
        cin>>d;
        for(int j=1;j<=d;j++) {
            int x;
            cin>>x;
            s.insert(x);
        }
    }
    cout<<n-s.size()<<endl;
    return 0;    
}

Measured memory_bytes: 3624
#include <stdio.h>

using namespace std;

int main(void)
{
    int A, B, C, D;
    scanf("%d %d %d %d", &A, &B, &C, &D);

    int ans = 0;
    if (A < B) ans += A;
    else ans += B;

    if (C < D) ans += C;
    else ans += D;

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import math
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#############
# Main Code #
#############

N,A,B = map(int,input().split())


amari = N % (A+B)
sho = math.floor(N/(A+B))

if amari<A:
  last = amari
else:
  last = A



print(int(sho*A+last))


Measured memory_bytes: 38384
# coding: utf-8

# https://atcoder.jp/contests/abc102/tasks/arc100_a
# 13:03-13:20


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

    B = sorted([A[i]-i for i in range(N)])
    
    b = B[N//2]

    return sum([abs(B[i]-b) for i in range(N)])


print(main())


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<pair<int,string>> V(M);
  for (int i = 0; i < M; i++) 
    cin >> V.at(i).first >> V.at(i).second;
  
  vector<int> W(N,0);
  
  int ac = 0; 
  int wa = 0; 
  for (int j = 0; j < M; j++) {
    if (V.at(j).second == "AC")
      W.at(V.at(j).first - 1)++;
    if (W.at(V.at(j).first - 1) == 0 && V.at(j).second == "WA")
      wa++;
  }
  
  for (int l = 0; l < N; l++) {
    if (W.at(l) > 0)
      ac++;
  }
  
  for (int k = 0; k < M; k++) {
    if (W.at(V.at(k).first - 1) == 0 && V.at(k).second == "WA")
      wa--;
  }
  
  cout << ac << " " << wa << endl;
  
  
}


Measured memory_bytes: 7384
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <numeric>
#include <cassert>
#ifdef DEBUG
#include "./Lib/debug.hpp"
#else
#define dump(...)
template<class T>inline auto d_val(T a, T b) { return a; }
#endif

/* (=＾o＾=) */
#define int ll

/* macro */
#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define REPI2(it,b,e) for(auto it = (b); it != (e); ++it)
#define REPI(it,c) REPI2(it, (c).begin(), (c).end())
#define RREPI(it,c) REPI2(it, (c).rbegin(), (c).rend())
#define REPI_ERACE2(it, b, e) for(auto it = (b); it != (e);)
#define REPI_ERACE(it, c) REPI_ERACE2(it, (c).begin(), (c).end())
#define ALL(x) (x).begin(),(x).end()
#define cauto const auto&
/* macro func */
#define SORT(x) do{sort(ALL(x));}while(false)
#define RSORT(x) do{sort((x).rbegin(),(x).rend());}while(false)
#define UNIQUE(v) do{v.erase( unique(v.begin(), v.end()), v.end() );}while(false)
#define MAX(x,y) do{x = std::max(x,y);}while(false)
#define MIN(x,y) do{x = std::min(x,y);}while(false)
#define BR do{cout<<"\n";}while(false)

/* type define */
using ll = long long;
using PAIR = std::pair<ll, ll>;
using VS = std::vector<std::string>;
using VL = std::vector<long long>;
using VVL = std::vector<VL>;
using VVVL = std::vector<VVL>;
using VD = std::vector<double>;
template<class T>
using V = std::vector<T>;

/* using std */
using std::cout;
constexpr char endl = '\n';
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::unordered_multiset;
using std::multiset;
using std::bitset;
using std::priority_queue;

/* constant value */
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;

/* Initial processing  */
struct Preprocessing { Preprocessing() { std::cin.tie(0); std::ios::sync_with_stdio(0); }; }_Preprocessing;

/* Remove the source of the bug */
signed pow(signed, signed) { assert(false); return -1; }

/* define hash */
namespace std { template <>	class hash<std::pair<ll, ll>> { public:	size_t operator()(const std::pair<ll, ll>& x) const { return hash<ll>()(1000000000 * x.first + x.second); } }; }

/* input */
template<class T> std::istream& operator >> (std::istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }

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

signed main() {
	ll n;
	cin >> n;
	ll ans = 0;
	REP(i, n) {
		ans += i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n k
d1 ... dk

n 10000
k 10
 */
int n,k,d[10];

bool hate(int a){
  while(a>0){
    REP(i,k){
      if(d[i]==a%10) return true;
    }
    a/=10;
  }
  return false;
}

int main(){
  cin>>n>>k;
  REP(i,k){
    cin>>d[i];
  }

  FOR_IN(i,n,99999){
    if(!hate(i)){
      cout<<i<<endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: i64,
        k: i64
    }

    let mut result = 0;
    for i in k..=n+1 {
        result += count(n, i);
        result %= 1_000_000_007;
    }

    println!("{:?}", result);
}

fn count(n: i64, k: i64) -> i64 {
    (n - k + 1) * k  + 1 % 1_000_000_007
}


Measured memory_bytes: 2088
#include <iostream>
using namespace std;
int n,cnt;
string s;
int main(){
	cin >>n;
	for(int i=0;i<n;i++){
		cin >>s;
		if(s=="A"){
			cnt++;
		}else if(s=="Un"){
			cnt--;
			if(cnt<0)break;
		}
	}
	if(cnt==0){
		cout <<"YES" <<endl;
	}else{
		cout <<"NO" <<endl;
	}
}

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

using namespace std;

#define ll long long

int main() {
    ll n;
    cin >> n;
    map<string, ll> mp;
    string s;
    while (n--) {
        cin >> s;
        mp[s]++;
    }
    vector<pair<string, ll>> v;
    for (auto it = mp.begin(); it != mp.end(); it++) {
        v.push_back(*it);
    }
    sort(v.rbegin(), v.rend(), [](const pair<string, ll> &a, const pair<string, ll> &b) {
        if (a.second == b.second)
            return a.first > b.first;
        return a.second < b.second;
    });
    auto highest = v.begin();
    auto cur = v.begin();
    while (cur->second == highest->second) {
        cout << cur->first << "\n";
        cur++;
    }
}

Measured memory_bytes: 29552
/* Author darklight13 -_- 
   IIT Patna 
*/
#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define int long long int
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii>   vii;
// typedef tree<int, null_type, less<int>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//     data_set;
#define rep(i,l,r)   for(int i=(l);i<(r);i++)
#define deb(x)     cout << (#x) << " is " << (x) << endl
#define dbg(x)     cout << x << ' '
#define here cout << " Hey! ";
#define  pb push_back
#define  F  first
#define  S  second
#define all(v) (v).begin(),(v).end()
#define sz(a) (int)((a).size())
#define sq(x) ((x)*(x))
const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int N = 2e5+5;
const int INF = 1000111000111000111LL;
const ld PI = 3.1415926535898;

int32_t main()
{
	SYNC
	int h,w; cin >> h >> w;
	if(h==1 || w == 1)	return cout << 1,0;
	cout << (h*w + 1)/2;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iterator>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  copy_n(istream_iterator<int>(cin), M, A.begin());
  int result = N - accumulate(A.begin(), A.end(), 0);
  cout << max(result, -1) << endl;
  return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
   int x,y;
   cin>>x>>y;
   if((x==y||x==1) && (y%4==0||y%2==0))
   cout<<"Yes";
   else if(y>4*x || y&1||y<x*2)
   cout<<"No";
   else
   cout<<"Yes";

}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;

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

  double ans = 0;

  rep( i, N ) {
    double A;
    std::cin >> A;

    ans += 1.0/A;
  }

  printf( "%.12f\n", 1.0/ans );

  return 0;
}

Measured memory_bytes: 3772
n, m = map(int, input().split())
h = list(map(int, input().split()))

ans = [1 for i in range(len(h))]
for j in range(m):
    a, b = map(int, input().split())
    if h[a-1] <= h[b-1]:
        ans[a-1] = 0
    if h[b-1] <= h[a-1]:
        ans[b-1] = 0

print(sum(ans))

Measured memory_bytes: 20028
import math

def using_sqrt(number):
    #numberが素数であればTrue,違うならFalse
    for divisor in range(2,math.floor(math.sqrt(number))+1):
        if number % divisor == 0:
            return False
    return True

N = int(input())

count = 0
for i in range(N):
    q = int(input())
    if using_sqrt(q):
        count += 1
print(count)


Measured memory_bytes: 5680
#include<bits/stdc++.h>
using namespace std;
typedef struct{
  int x,y;
}P;

int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
int d[100][100];
char mp[100][100];
#define INF 100000
int main(){
  int h,w,cnt=0;
  cin>>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>mp[i][j];
      if(mp[i][j]=='.')cnt++;
      d[i][j]=INF;
    }
  }
  queue<P>que;
  que.push((P){0,0});
  d[0][0]=0;

  while(!que.empty()){
    P p=que.front();
    que.pop();
    int x=p.x;
    int y=p.y;
    if(x==w-1&&y==h-1)break;
    for(int i=0;i<4;i++){
      int nx=x+dx[i];
      int ny=y+dy[i];
      if(0<=nx&&nx<w&&0<=ny&&ny<h&&mp[ny][nx]!='#'&&d[ny][nx]==INF){
        d[ny][nx]=d[y][x]+1;
        que.push((P){nx,ny});
      }
    }
  }
  if(d[h-1][w-1]==INF)cout<<-1<<endl;
  else cout<<cnt-1-d[h-1][w-1]<<endl;
  return(0);
}

Measured memory_bytes: 256
from math import gcd
class SegmentTree:
    def __init__(self,n,ele=0):

        self.ide_ele = ele

        self.num =2**(n-1).bit_length()
        self.seg=[self.ide_ele]*2*self.num


    #####segfunc######
    def segfunc(self,x,y):
        return gcd(x,y)

    def init(self,init_val):
        #set_val
        for i in range(n):
            self.seg[i+self.num-1]=init_val[i]    
        #built
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self,k,x):
        k += self.num-1
        self.seg[k] = x
        while k:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self,p,q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res
n=int(input())
a=list(map(int,input().split()))
st=SegmentTree(n)
st.init(a)
ans=-1
for i in range(n):
    ans=max(ans,gcd(st.query(0,i),st.query(i+1,n)))
print(ans)

Measured memory_bytes: 21132
package main

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

func solve() {
	n, w := getInt(), getInt()
	ws := make([]int, n)
	vs := make([]int, n)
	for i := 0; i < n; i++ {
		ws[i] = getInt()
		vs[i] = getInt()
	}

	dp := make([][]int, n+1)
	for i := range dp {
		dp[i] = make([]int, w+1)
	}

	for i := 1; i <= n; i++ {
		for j := range dp[i] {
			if j-ws[i-1] >= 0 {
				dp[i][j] = max(dp[i-1][j], dp[i-1][j-ws[i-1]]+vs[i-1])
			} else {
				dp[i][j] = dp[i-1][j]
			}
		}
	}

	fmt.Fprintln(wr, dp[n][w])
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 81792
import java.util.Scanner;

//20180508
//07

public class Main {
    public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);

		while (scanner.hasNextLine()) {
			int h = scanner.nextInt();
			int w = scanner.nextInt();

			if(h == 0 && w == 0) {
				break;
			}

			for (int y = 1; y <= h; y++) {
				for (int x = 1;x <= w;x++) {
					if(x == 1 || y == 1 || x == w || y == h) {
						System.out.print("#");
					} else {
						System.out.print(".");
					}
				}
				System.out.println();
			}
			System.out.println();
		}

    	scanner.close();
    }
}


Measured memory_bytes: 32488
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

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

    if ((N - 1) * (N - 2) / 2 < K) {
        cout << -1 << endl;
        return 0;
    }

    bool used[110][110];
    REP(i,110)REP(j,110) used[i][j] = false;

    for (int i = 2; i <= N; i++) {
        used[1][i] = true;
        used[i][1] = true;
    }

    int cur = (N - 1) * (N - 2) / 2;
    for (int i = 2; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) {
            if (cur > K) {
                cur--;
                used[i][j] = true;
                used[j][i] = true;
            }
        }
    }

    vector<pair<int,int>> ans;
    for (int i = 1; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) {
            if (used[i][j]) {
                ans.emplace_back(i, j);
            }
        }
    }

    cout << ans.size() << endl;
    for (auto x: ans) {
        cout << x.first << " " << x.second << endl;
    }

    return 0;
}


Measured memory_bytes: 384
i, j = [int(x) for x in raw_input().split()]
l = []
for x in xrange(i):
	l.append(list(raw_input()))
o = []
for x in xrange(i):
	for y in xrange(j):
		if l[x][y] == '#':
			o.append('#')
			continue
		#is '.'
		temp = 0
		for d_x in xrange(-1, 2):
			for d_y in xrange(-1, 2):
				if x + d_x < 0 or x + d_x >= i or y + d_y < 0 or y + d_y >= j:
					continue
				try:
					if l[x + d_x][y + d_y] == '#':
						temp += 1
				except:
					continue
		s = 0
		o.append(str(temp))
	o.append('\n')
print ''.join(o[:-1])

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

using namespace std;

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

#define F first
#define S second
#define tm alksdfj

const int MAXN = 400 + 4;
const int MAXE = 1e5 + 10;

int n, m, d[MAXN][MAXN], tm[MAXN];
int from[MAXE], to[MAXE];
vector<int> adj[MAXN];
bool ok[MAXN];
bool flag;

void dfs(int v){
	for (int e:adj[v]){
		int u = from[e]^to[e]^v;
		if (tm[u] == -1){
			if (e < tm[v])
				tm[u] = e, dfs(u);
		}
		else
			if (e < max(tm[u], tm[v]) && e != tm[u] && e != tm[v]) flag = 1;
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		cin >> from[i] >> to[i], from[i]--, to[i]--;
		adj[from[i]].push_back(i);
		adj[to[i]].push_back(i);
	}

	memset(d, -1, sizeof(d));
	for (int v = 0; v < n; v++){
		memset(tm, -1, sizeof(tm));
		tm[v] = m;
		flag = 0;
		dfs(v);
		ok[v] = !flag;
		for (int u = 0; u < n; u++)
			d[v][u] = tm[u];
	}

	int ans = 0;
	for (int v = 0; v < n; v++)
		if (ok[v])
			for (int u = v+1; u < n; u++)
				if (ok[u])
					if (d[v][u] == -1 && d[u][v] == -1){
						bool fail = 0;
						for (int w = 0; !fail && w < n; w++)
							if (w^v && w^u)
								if (d[v][w] > -1 && d[u][w] > -1 && d[v][w] != d[u][w]) fail = 1;

						if (!fail)
							ans++;
					}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> P;
typedef pair<lint, lint> PL;

int cnt[3];

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n, a, b; cin >> n >> a >> b;
    for(int i=0;i<n;i++){
        int p; cin >> p;
        if(p<=a) cnt[0]++;
        else if(p<=b) cnt[1]++;
        else cnt[2]++;
    }

    cout << min(cnt[0], min(cnt[1], cnt[2])) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define vl vector
#define pb push_back
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,m;
    cin>>n;
    ll sum=0;
    ll arr[n];
    for(i=0;i<n;i++) cin>>arr[i];
    for(i=0;i<n;i++) for(j=0;j<n;j++)
    {
        if(i!=j)
            sum+=arr[i]*arr[j];
    }
    cout<<sum/2;
}

Measured memory_bytes: 3636
s=input()

a=[]
b=[]

for i in range(len(s)):
  if i%2==0:
    a.append(0)
    b.append(1)
  else:
    a.append(1)
    b.append(0)
ans1=0
ans2=0
for i in range(len(s)):
  if a[i]==int(s[i]):
    ans1+=1

for i in range(len(s)):
  if b[i]==int(s[i]):
    ans2+=1    
    

print(min(ans1,ans2))

Measured memory_bytes: 4852
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
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;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	string S; cin >> S;
	int N = S.size();
    
	int ans = 100;
	rep(k,26) {
		vector<bool> A(N+1,false);
		rep(i,N) if (S[i] == char('a'+k)) A[i] = true;
		int cnt = 100;
        rep(l,N) {
			bool check = true;
			rep(i,N-l) if (!A[i]) check = false;
			if (check) {
				cnt = l;
				break;
			}
			rep(i,N) if (A[i+1]) A[i] = true;
		}
		chmin(ans,cnt);
	}

	cout << ans << endl;
}


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

typedef long long ll;
#define rep(i, n) for(ll i=0; i<n; i++)
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define sz(v) ll(v.size)

int main(){
    string s;
    cin >> s;
    ll counter_1 = 0;
    rep(i, s.size()) {
        if (i % 2 == 0 && s[i] == '0') {
            counter_1++;
        }
        if (i % 2 == 1 && s[i] == '1') {
            counter_1++;
        }
    }
    ll counter_2 = 0;
    rep(i, s.size()) {
        if (i % 2 == 0 && s[i] == '1') {
            counter_2++;
        }
        if (i % 2 == 1 && s[i] == '0') {
            counter_2++;
        }
    }
    cout << min(counter_1, counter_2) << endl;
    return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	int a[7][2];
	a[0][0] = 1;
	a[0][1] = 4;
	a[1][0] =6;
	a[1][1] = 2;
	a[2][0] = 5;
	a[2][1] = 3;
	a[3][0] = 4;
	a[3][1] = 1;
	a[4][0] = 1;
	a[4][1] = 6;
	a[5][0] = 3;
	a[5][1] = 4;
	a[6][0] = 6;
	a[6][1] = 6;

	while (1) {

		string st; cin >> st;
		if (st == "#")break;
		else {
			int now = 0;
			for (auto c : st) {
				int aa = c - '0';
				now = a[now][aa];
			}
			if (now == 3) {
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3204
package main

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

func main() {
	sc := newInputScanner(true, 1024)
	N, M := sc.nextInt(), sc.nextInt()
	sol := &solution{
		dp: make([]int, N),
		N:  N,
		M:  M,
	}
	fmt.Println(sol.solve())
}

type solution struct {
	debuggable
	dp []int
	N  int
	M  int
}

func (sol *solution) solve() int {
	sol.dp[0] = 1
	var k int
	for i := 1; i < sol.N; i++ {
		k = min(i, sol.N-i+1)
		for j := k; j < sol.N; j++ {
			sol.debug(func() {
				fmt.Printf("adding %d(%d) to %d(%d)\n", j-k, sol.dp[j-k], j, sol.dp[j])
			})
			sol.dp[j] += sol.dp[j-k]
			if sol.dp[j] >= sol.M {
				sol.dp[j] %= sol.M
			}
		}
		sol.debug(func() {
			fmt.Println(i, k, sol.dp)
		})
	}
	var answer int
	for i := 0; i < sol.N; i++ {
		answer += (sol.N - i) * sol.dp[i]
		if answer >= sol.M {
			answer %= sol.M
		}
	}
	return answer
}

func min(i, j int) int {
	if i < j {
		return i
	} else {
		return j
	}
}

type inputScanner struct {
	*bufio.Scanner
}

func newInputScanner(enabledScanWords bool, sizeInKB int) *inputScanner {
	scanner := bufio.NewScanner(os.Stdin)
	if enabledScanWords {
		scanner.Split(bufio.ScanWords)
	}
	capacity := sizeInKB * 1024
	buf := make([]byte, capacity)
	scanner.Buffer(buf, capacity)
	return &inputScanner{
		Scanner: scanner,
	}
}

func (inputSc *inputScanner) nextInt() int {
	i, e := strconv.Atoi(inputSc.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (inputSc *inputScanner) nextUInt64() uint64 {
	i, e := strconv.ParseUint(inputSc.nextStr(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func (inputSc *inputScanner) nextStr() string {
	inputSc.Scan()
	return inputSc.Text()
}

type debuggable struct {
}

const (
	DEBUG_ON = false
)

func (d *debuggable) debug(f func()) {
	if DEBUG_ON {
		f()
	}
}


Measured memory_bytes: 640
<?php
fscanf(STDIN, "%d %d", $N, $Y);

for ($k10 = 0; $k10 * 10000 <= $Y; $k10++) {
    for ($k5 = 0; $k10 * 10000 + $k5 * 5000 <= $Y; $k5++) {
        $k1 = ($Y - $k10 * 10000 - $k5 * 5000) / 1000;
        // printf("k10:%d k5:%d k1:%d\n", $k10, $k5, $k1);
        if ($k10 + $k5 + $k1 == $N) {
            echo "{$k10} {$k5} {$k1}" . PHP_EOL;
            exit;
        }
    }
}
echo "-1 -1 -1" . PHP_EOL;


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

int main()
{
	int N, count=1, i = 0;
	cin >> N;
	int d[100];
	while (i < N)
		cin >> d[i++];
	sort (d, d+N);
	i = 0;
	while (i < N - 1)
	{
		if (d[i] < d[i+1])
			count++;
		i++;
	}
	cout << count << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	ll N, x; cin>>N>>x;
	vector<ll> a(N);
	rep(i,N)cin>>a[i];
	ll ans = 0;
	ll l = 0, r = N-1;
	while(r-l > 0){
		if(a[l]+a[l+1] > x){
			ll need = a[l] + a[l+1] - x;
			ll new_next = max(a[l+1]-need, 0LL);
			ans += need;
			a[l+1] = new_next;
		}
		if(r-l == 1)break;
		if(a[r]+a[r-1] > x){
			ll need = a[r]+a[r-1] - x;
			ll new_next = max(a[r-1]-need, 0LL);
			ans += need;
			a[r-1] = new_next;
		}
		++l; --r;
	}
	cout<<ans<<endl;
}

// int main(){
// 	ll N, x; cin>>N>>x;
// 	vector<ll> A(N);
// 	rep(i,N)cin>>A[i];
// 	ll ans = 0;
// 	rep(i,N){
// 		if(i%2 == 1 && i+1 <N){
// 			if(A[i-1]+A[i] > x){
// 				ll mew = max(0LL, x-A[i-1]);
// 				if(mew <= A[i]){
// 					ans += A[i]-mew;
// 					A[i] = mew;
// 				}
// 			}
// 			if(A[i]+A[i+1] > x){
// 				ll mew = max(0LL, x-A[i+1]);
// 				if(mew <= A[i]){
// 					ans += A[i]-mew;
// 					A[i] = mew;
// 				}
// 			}
// 		}
// 	}
// 	rep(i,N-1){
// 		if(A[i]+A[i+1] > x){
// 			ans += A[i] + A[i+1] - x;
// 			if(i%2 == 1){
// 				A[i+1] -= A[i] + A[i+1] - x;
// 			}
// 		}
// 	}
// 	cout<<ans<<endl;
// 	return 0;
// }

Measured memory_bytes: 1024
// https://atcoder.jp/contests/dp/tasks/dp_f
#include <bits/stdc++.h>
using namespace std;

string longer(string const& a, string const& b) {
  if (a.length() < b.length())
    return b;
  return a;
}

int main() {
  string a, b;
  cin >> a >> b;
  string t(longer(a,b)),s(a == t ? b:a);
  string lcs[2][t.length() + 1];

  for (int i = 1; i <= s.length() + 1; ++i)
    for (int j = 1; j <= t.length(); ++j) {
      lcs[i % 2][j] = longer(lcs[i % 2][j - 1], lcs[(i + 1) % 2][j]);
      if (s[i - 1] == t[j - 1])
        lcs[i % 2][j] = lcs[(i + 1) % 2][j - 1] + s[i - 1];
    }
      
  cout << lcs[1][t.length()] << endl;
}


Measured memory_bytes: 16768