akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

const int N_MAX = 10000;

int main(void) {
  std::ios_base::sync_with_stdio(false);

  int n = 0;

  std::cin >> n;

  std::vector<int> *v = new std::vector<int>(N_MAX + 1, -1);

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

    std::cin >> a;

    if (v->at(a) < 0) {
      v->at(a) = 0;
    }
    
    v->at(a) += 1;
  }

  bool printFirst = true;

  for (int i = 0; i <= N_MAX; i++) {
    if (v->at(i) < 0) {
      continue;
    }

    if (!printFirst) {
      std::cout << " ";
    }
    
    for (int j = 0; j < v->at(i); j++) {
      if (j != 0) {
	std::cout << " ";
      }
      
      std::cout << i;
    }

    printFirst = false;
  }

  std::cout << std::endl;
  
  return 0;
}

Measured memory_bytes: 1240
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        long sum = 0;
        
        int end = in.nextInt();
        for(int i = 0; i < end; i++) {
            int num = in.nextInt();
            min = min > num ? num : min;
            max = max < num ? num : max;
            sum += num;
        }
  
        System.out.printf("%d %d %d%n", min, max, sum);
    }
}



Measured memory_bytes: 42736
#include<iostream>
#include<unordered_set>
using namespace std;
int main(){
    int n; 
    cin>>n;
    unordered_set<int>ump;
    int index=1;
    while(ump.find(n)==ump.end()){
        ump.insert(n);
        if(n%2==0){
            n/=2;
        }
        else{
            n=3*n+1;
        }
        index++;
    }
    cout<<index;
}

Measured memory_bytes: 3532
class Union_Find():
    def __init__(self,N):
        """0,1,...,n-1を要素として初期化する.

        n:要素数
        """
        self.n=N
        self.parents=[-1]*N
        self.rank=[0]*N

    def find(self, x):
        """要素xの属している族を調べる.

        x:要素
        """
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """要素x,yを同一視する.

        x,y:要素
        """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x]>self.rank[y]:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
        else:
            self.parents[y] += self.parents[x]
            self.parents[x] = y

            if self.rank[x]==self.rank[y]:
                self.rank[y]+=1

    def size(self, x):
        """要素xの属している要素の数.

        x:要素
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """要素x,yは同一視されているか?

        x,y:要素
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """要素xが属している族の要素.
        ※族の要素の個数が欲しいときはsizeを使うこと!!

        x:要素
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """族の名前のリスト
        """
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """族の個数
        """
        return len(self.roots())

    def all_group_members(self):
        """全ての族の出力
        """
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

#=
N,M=map(int,input().split())
U=Union_Find(N)

for _ in range(M):
    A,B=map(int,input().split())
    U.union(A-1,B-1)

print(U.group_count()-1)


Measured memory_bytes: 75596
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
ll hell=pow(10,9)+7;
bool comp(ll a,ll b){
	return abs(a)>abs(b);
}
void solve(){
	ll n,k,res=1,f=0;
	cin>>n>>k;
	vector<ll> v(n);
	for(ll i=0;i<n;i++){
		cin>>v[i];
		if(v[i]>0)
		f=1;
	}
	if(k==n){
		for(ll i=0;i<n;i++)
		res=(res*v[i])%hell;
		if(res<0)
		res+=hell;
		cout<<res;
		exit(0);
	}
	sort(v.begin(),v.end(),comp);
	if(!f&&k%2==1){
		reverse(v.begin(),v.end());
		for(ll i=0;i<k;i++)
		res=(res*v[i])%hell;
		if(res<0)
		res+=hell;
		cout<<res;
		exit(0);
	}
	ll cnt=0;
	for(ll i=0;i<k;i++){
		if(v[i]<0)
		cnt++;
		if(v[i]==0){
			cout<<0;
			exit(0);
		}
	}
	if(cnt%2){
		ll a=hell,b=hell,c=0,d=0;
		for(ll i=0;i<k;i++)
		if(v[i]>0)
		a=min(a,v[i]);
		else
		b=min(b,-v[i]);
		for(ll i=k;i<n;i++)
		if(v[i]>0)
		d=max(d,v[i]);
		else
		c=max(c,-v[i]);
		if(a*d>=b*c||a==hell){
			for(ll i=0;i<k;i++)
			if(v[i]<0&&abs(v[i])==b){
				swap(v[i],d);
				break;
			}
		}
		else{
			c*=(-1);
			for(ll i=0;i<k;i++)
			if(v[i]>0&&v[i]==a){
				swap(v[i],c);
				break;
			}
		}
	}
	for(ll i=0;i<k;i++)
	res=(res*v[i])%hell;
	if(res<0)
	res+=hell;
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++)
	solve();
}


Measured memory_bytes: 4960
#include <bits/stdc++.h>
#define int long long
#define INT_MAX INT64_MAX
#define INT_MIN INT64_MIN
#define PI 3.14159265358979323846
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define MOD 1000000007
/* DEFINE cout */
#define pln cout << "===============================\n"
#define on cout<<"\n"
#define os cout<<" "
#define o2(a,b) cout<<a<<" "<<b
#define o(a) cout << a
#define bitcount __builtin_popcount
/* DEFINE cout */
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int x,int y){
    int res = 1;
    int p = MOD;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
signed main(){
    string s, t;
    cin >> s >> t;
    int n = s.length();
    int ans= 0;
    for(int i=0; n>i; i++){
        if(s[i] != t[i]){
            ans++;
        }
    }
    cout << ans << endl;
}






Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define PI 3.14159265358979323846
using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 == 0) {
            continue;
        }
        if (i % 5 == 0) {
            continue;
        }
        ans += i;
    }
    cout << ans << endl;

}

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

int main() {
  char c;
  cin >> c;
  
  if (c == 'a'|| c == 'i'|| c == 'u'|| c == 'e'|| c == 'o'){
    cout << "vowel" <<endl;
  }

  else{
    cout << "consonant" <<endl;
  }
}



Measured memory_bytes: 3608
N = int(input())
A = [int(x) - 1 for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

result = 0
was = -5
for a in A:
    result += B[a]
    if was == a-1:
        result += C[a-1]
    was = a

print(result)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;

ll s(vector<ll>& a, ll x)
{
    ll s = 0;
    for (int i = 0; i < a.size(); ++i)
        s += abs(a[i] - x);
    return s;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        a[i] -= i + 1;
    }
    sort(a.begin(), a.end());
    if (n % 2 == 0)
        cout << min(s(a, a[n / 2 - 1]), s(a, a[n / 2]));
    else
        cout << s(a, a[n / 2]);
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 10005
 
#define PI   3.14159265358979323846264338327950
 
#define F first
#define S second
 
#define ll 	 long long int
 
#define mod  1000000007



int main()
{
	FAST;
	ll n;
	cin >> n;
	ll a[n + 3]; ll m = 0;
	ll f = INT_MAX;
	ll b[n + 6];
	for(ll i = 1; i <= n; i ++){
		cin >> a[i];
		a[i] -= (i+1);
	}
	sort(a + 1, a  + n + 1);
	for(ll i = 1; i<= n; i++){
		m += abs(a[i] - a[n/2 + 1] );
	}
	cout << m;
	return 0;
}

Measured memory_bytes: 5180
N,A,B=map(int, input().split())
count = 0
for i in range(1,N+1):
  sum_ = 0
  for k in range(len(str(i))):
    sum_ = sum_ + int(str(i)[k])
  if sum_ >= A and sum_ <= B:
    count = count + i
print(count)


Measured memory_bytes: 2940
sa = io.read()
sb = io.read()
sc = io.read()
local ta, tb, tc = 1, 1, 1
cur = "a"
while true do
  if cur == "a" then
    if #sa < ta then
      print("A") os.exit()
    end
    cur = sa:sub(ta, ta)
    ta = ta + 1
  elseif cur == "b" then
    if #sb < tb then
      print("B") os.exit()
    end
    cur = sb:sub(tb, tb)
    tb = tb + 1
  else
    if #sc < tc then
      print("C") os.exit()
    end
    cur = sc:sub(tc, tc)
    tc = tc + 1
  end
end


Measured memory_bytes: 888
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int n,temp, sum=0;
    cin>>n;
    temp=n;

    while(temp>0)
    {
        sum+= temp%10;
        temp= temp/10;
    }

    if(n%sum==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}



Measured memory_bytes: 3572
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 100000

int main(void) {
    int num = get_int();
    static int arr[NUM_MAX];
    fget_array(arr, num);
    static int map[NUM_MAX+1];
    int i;
    for(i = 0; i < num; i++) {
        map[arr[i]]++;
    }

    int cnt = 0;
    for(i = 0; i <= NUM_MAX; i++) {
        if(map[i] >= 2) cnt += map[i]-1;
    }
#ifdef DEBUG
    printf("%d\n", cnt);
#endif
    if(cnt == 0) {
        printf("%d\n", num);
    } else {
        int ans = num - ((cnt-1)/2 + 1)*2;
        printf("%d\n", ans);
    }

    return 0;
}

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

typedef long long ll;
using vi = vector<int>;

#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define MOD 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  ll a,b,n;
  cin >> n >> a >> b;
  if (a % 2 == b % 2) {
    cout << (b - a) / 2 << endl;
  } else {
    cout << min(a-1, n-b) + 1 + (b-a-1) / 2 << endl;
  }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
##################################
# University of Wisconsin-Madison
# Author: Yaqi Zhang
##################################

# standard library
import sys
from functools import lru_cache

sys.setrecursionlimit(10**9)

Input = lambda: sys.stdin.readline().rstrip()
IntRead = lambda: int(Input())
LineRead = lambda: list(map(int, Input().split()))


INF = 10**18

def main():
    S, W = LineRead()
    print("unsafe" if W >= S else 'safe')

if __name__ == "__main__":
    main()



Measured memory_bytes: 9560
# AOJ 0031 Weight
# Python3 2018.6.14 bal4u

w = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512];

while True:
	try:
		a = int(input())
	except EOFError:
		break
		
	ans = []
	i = 0
	while a > 0:
		if a & 1:
			ans.append(w[i])
		a >>= 1
		i += 1
	print(*ans)


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

int main(){
  int N,flag = 0;
  string s;
  cin >> N;cin.ignore();
  getline(cin,s);
  for(int i = 0; i < (N-1)*2;i++){
    if(s[i*2] == 'Y'){
      flag = 1;
      break;

    }

  }
  if (flag == 1){
    cout << "Four" <<endl;
  }else{
    cout << "Three" <<endl;
  }
}


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

int main() {
	string s;
	cin >> s;
	if (s[5] == '1')
		cout << "TBD";
	else if (s[6] - '0' >= 5)
		cout << "TBD";
	else
		cout << "Heisei";
	cout << endl;
	return 0;
}


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

int main() {
  int N, M, k = 0, v = 0;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++) cin >> s.at(i);
  cin >> M;
  vector<string> t(M);
  for (int i = 0; i < M; i++) cin >> t.at(i);
  
  for (string a : s) {
    for (string b : s) if (a == b) k++;   
    for (string b : t) if (a == b) k--;   
    if (v < k) v = k;
    k = 0;
  }
    
  cout << v << endl;
  return 0;
}


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

int main() {
  long long int a, b, k;

  cin >> a >> b >> k;

  if(a > k) {
    cout << a - k << " " << b << endl;
  } else if (a + b - k > 0){
    cout << 0 << " " << a + b - k << endl;
  } else {
    cout << 0 << " " << 0 << endl;
  }
}

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

#define Mset(s, n)      memset(s, n, sizeof(s))
#define Rp0(i, m)       for(int i = 0; i < m; ++i)
#define Rpd(i, m, l)    for(int i = l; i >= m; --i)
#define Rp1(i ,m)       for(int i = 1; i <= m; i++)
#define All(a)          (a).begin(), (a).end()
#define Lwb             lower_bound
#define Upb             upper_bound
#define Sz(a)           int((a).size())
#define u_map           unordered_map
#define fi              first
#define se              second
#define pb              push_back
#define pf              push_front
#define is              insert
#define ooi             INT_MAX
#define ool             LLONG_MAX
#define ll              long long
#define ull             unsigned ll
#define ld              long double
#define pii             pair<int, int>
#define vi              vector<int>
#define vpii            vector<pii>

const ll MOD = (ll) 1e9 + 7;
const ld PI = acos((ld) -1);
inline int Get_bit(int x, int k){return (x >> (k - 1)) & 1;}
inline ll Gcd(ll a, ll b) {ll r; while(b){ r = a % b; a = b; b = r;} return a;}
inline ll Lcm(ll a, ll b) {return a / Gcd(a, b) * b;}
inline ll Pow(ll n, ll k) {ll r = 1; for(; k; k >>= 1, n = n * n % MOD){if(k & 1) r = r * n % MOD;} return r;}
const int base = 311;


const int N = 1e6 + 10;

/*
    @ Copyright belong to Shadow4207
*/

ll n, m, k, ans;

void Solve(){
    int a, b;
    cin >> n >> a >> b;
    if(n * a < b) cout << n * a; else cout << b;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
    Solve();
    return 0;
}











Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
long long a[100005],b[100005];
int main()
{
	long long ans=0;
	scanf("%d",&n);for(int i=1;i<=n;++i) scanf("%lld",&a[i]);
	sort(a+1,a+1+n);
	if(n%2) {
		int c1=0,c2=n/2+1;
		long long saigou=0;
		b[1]=a[n/2+1];b[n]=a[n/2];
		for(int i=2;i<n;++i) if(!(i%2)) b[i]=a[++c2];else b[i]=a[++c1];
		for(int i=1;i<n;++i) ans+=abs(b[i+1]-b[i]);saigou=max(saigou,ans);
		b[n]=a[n/2+2];c1=0;c2=n/2+2;
		for(int i=2;i<n;++i) if(!(i%2)) b[i]=a[++c1];else b[i]=a[++c2];
		ans=0;
		for(int i=1;i<n;++i) ans+=abs(b[i+1]-b[i]);saigou=max(saigou,ans);
		printf("%lld\n",saigou);
	}
	else {
		int c1=0,c2=n/2+1;
		b[1]=a[n/2];b[n]=a[n/2+1];
		for(int i=2;i<n;++i) if(!(i%2)) b[i]=a[++c2];else b[i]=a[++c1];
		for(int i=1;i<n;++i) ans+=abs(b[i+1]-b[i]);
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
 
using namespace std;
 
#define x first
#define y second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
 
const ll MOD = 1e9+7;
const ll INF = 1e9+5;
 
int a, b, c, d, e, n, m, k;
string s, t, r;
char c1, c2, c3;
 
int A[200005];
int B[200005];
int C[200005];
 
int main() {
	int n, m;
  	cin >>n>>m;
  int uk = 0;
  	for (int i=0 ; i<n ; i++) {
      cin >>A[i];
      uk+=A[i];
    }
  sort(A, A+n);
  reverse(A, A+n);
  if (A[m-1]*4*m < uk) cout <<"No"<<endl;
  else cout <<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstdint>

using namespace std;

using elem_t = pair<int_least32_t, int_least32_t>;

int main()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
	
	int_least32_t n;
	int_least64_t k;
	cin >> n >> k;

	vector<elem_t> v( n );
	for(auto& x : v) {
		cin >> x.first >> x.second;
	}

	sort(v.begin(), v.end(), [](elem_t x, elem_t y){ return x.first < y.first; } );

	int_least32_t result;
	int_least64_t count = 0;
	for(auto i = 0; count < k; ++i) {
		result = v[i].first;
		count += v[i].second;
	}

	cout << result << endl;
}


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

int main(){

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

    int flag1 = 1;
    int flag2 = 1;
    
    string s;
    cin >> s;
    for(int i=0; i<s.length()-2; i++){
        if(s[i] != s[i+1]){
            flag1 = 0;
        }
    }

    for(int i=1; i<s.length()-1; i++){
        if(s[i] != s[i+1]){
            flag2 = 0;
        }
    }

    if(flag1 || flag2){
        cout << "Yes" << '\n';
    }else{
        cout << "No" << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
import itertools

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, K = ZZ()
    S = input()
    gr = itertools.groupby(S)
    ll = []
    for c, d in gr: ll.append([c, len(list(d))])

    output = N - len(ll)
    i = 1
    for _ in range(K):
        if i == len(ll)-1: output += 1
        elif i < len(ll): output += 2
        else: break
        i += 2

    print(output)

    return

if __name__ == '__main__':
    main()


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

def solve():
    a, b, c = list(map(int, input().split()))
    penki_set = set()
    penki_set.add(a)
    penki_set.add(b)
    penki_set.add(c)
    print(len(penki_set))

if __name__ == "__main__":
    solve()


Measured memory_bytes: 2940
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/

	coding: utf-8
	lang: C++ (GCC 9.2.1)
*/

#include <bits/stdc++.h>
using namespace std;

// utility of stdin,stdout
#define _CRT_SECURE_NO_WARNINGS
#define OUT cout << 
#define BR << endl
#define RET return 0
#define TLong long long
#define TBMod int(1e9+7)

int main(int argc, char const *argv[])
{
	// DON'T CHANGE
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	// here
	TLong n, q;
	TLong b, c;
	TLong psum = 0;
	map<TLong, TLong> ncnt;

	cin >> n;
	vector<TLong> a(n + 2);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		psum += a[i];
		if(ncnt.count(a[i])){
			ncnt[a[i]] += 1;
		}
		else	ncnt[a[i]] = 1;
	}
	cin >> q;
	while(q--){
		cin >> b >> c;
		if(ncnt.count(b)){
			psum += (c - b) * ncnt[b];

			if(ncnt.count(c))	ncnt[c] += ncnt[b];
			else ncnt[c] = ncnt[b];
			ncnt[b] = 0;
		}
		OUT(psum) BR;
	}
	RET;
}


Measured memory_bytes: 9256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    N, M, *a = map(int, read().split())
    A = {i for i in a}
    P = (10**9)+7

    dp = [0]*(N+1)
    dp[0] = 1

    if not (1 in A):
        dp[1] = 1
        
    for i in range(2, N+1):
        if i not in A:
            dp[i] = (dp[i-1] + dp[i-2])%P
    print(dp[N])
if __name__ == '__main__':
    main()


Measured memory_bytes: 14164
#include <iostream>

using namespace std;

int main(){
  int K;
  cin >> K;
  
  int S;
  cin >> S;
  
  int count=0;
  
  for(int i=0;i<=K;i++){
    for(int j=0;j<=K;j++){
      int k  = S - i -j;
      if(0 <= k && k <=K){
        count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <sstream>
#include <deque>
#define ll long long
using namespace std;
const int maxn=100000;
const ll mod=1000000007;
int n,m;

ll factorial(int n){
	ll ans=1;
	for(int i=1;i<n+1;i++){
		ans*=i;
		ans=ans%mod;
	}
	
	ans=ans%mod;
	return ans;
	
	
	
}

int main(){
	cin>>n>>m;
	if(n==m){
		
		ll ans_n=factorial(n);
		ll ans_m=factorial(m);
		
		ll out=((ans_n*ans_m))%mod;
		out=(2*out)%mod;
		cout<<out;
		return 0;
		
		
	}
	if(abs(n-m)==1){
		ll ans_n=factorial(n);
		ll ans_m=factorial(m);
		
		ll out=((ans_n*ans_m))%mod;
		cout<<out;
		return 0;
	}
	cout<<"0";
	return 0;
}

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

public class Main {
    static long min=Long.MAX_VALUE;
    static int n,m,x;
    static int price[];
    static int increment[][];

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
         n = s.nextInt();m=s.nextInt();x=s.nextInt();
        price = new int[n];
        increment = new int[n][m];
        for(int i=0;i<n;i++){
            price[i]=s.nextInt();
            for(int j=0;j<m;j++)increment[i][j]=s.nextInt();
        }
        arr = new ArrayList<>();
        solve(0,0L);
        if(min==Long.MAX_VALUE)System.out.println(-1);
        else System.out.println(min);
    }

    static ArrayList<Integer> arr ;

    public static void solve(int i,long sum){
        if(i==n){
            long algo[] = new long[m];
            for(int j=0;j<arr.size();j++){
                int u = arr.get(j);
                for(int o=0;o<m;o++)algo[o]+=increment[u][o];
            }
            boolean flag = true;
            for(int j=0;j<m;j++){
                if(algo[j]<x){
                    flag=false;
                    break;
                }
            }
            if(flag)min=Math.min(min,sum);

        }
        else{
            arr.add(i);
            solve(i+1,sum+price[i]);
            arr.remove(arr.size()-1);
            solve(i+1,sum);
        }
    }
}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 29600
n, q = gets.chomp.split.map(&:to_i)
s = gets.chomp

position = []
0.upto(s.length - 2){|x|position << x if s[x, 2] == "AC"}

table_r = []
position.each{|pos| table_r[pos + 1] = 1}

cum = 0
0.upto(s.length - 1){|pos|
    if table_r[pos].nil?
        table_r[pos] = cum
    else
        table_r[pos] += cum
    end
    cum = table_r[pos]
}

table_l = []
0.upto(s.length - 2){|pos| table_l[pos] = table_r[pos + 1] - 1}

table = []
position.each{|pos|
    table[pos] = 0.5
    table[pos + 1] = 0.5
}
#p table
cum = 0.0
0.upto(s.length - 1){|pos|
    if table[pos].nil?
        table[pos] = cum
    else
        table[pos] += cum
    end
    cum = table[pos]
}
#p table

q.times{
    l, r = gets.chomp.split.map(&:to_i)
#    puts table_r[r - 1] - table_l[l - 1]
    puts table_r[r-1] -  table_r[l-1]
}


Measured memory_bytes: 5500
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;


signed main(){
	//cout << fixed << setprecision(10);
	int h,w; cin >> h >> w;
	vector<string> vec(h);
	rep(i,0,h){
		cin >> vec[i];
	}
	ll ans = 0;
	vvl g(h + 1,vl(w + 1));
	rep(i,0,h){
		ll cnt = 0;
		ll ind = 0;
		rep(j,0,w){
			if(vec[i][j] == '.'){
				cnt++;
			}
			else{
				g[i][ind] += cnt;
				g[i][j] -= cnt;
				ind = j + 1;
				cnt = 0;
			}
		}
		g[i][ind] += cnt;
		rep(j,1,w){
			g[i][j] += g[i][j - 1];
		}
	}
	vvl f(h + 1,vl(w + 1));
	rep(j,0,w){
		ll cnt = 0;
		ll ind = 0;
		rep(i,0,h){
			if(vec[i][j] == '.'){
				cnt++;
			}
			else{
				f[ind][j] += cnt;
				f[i][j] -= cnt;
				ind = i + 1;
				cnt = 0;
			}
		}
		f[ind][j] += cnt;
		rep(i,1,h){
			f[i][j] += f[i - 1][j];
		}
	}
	rep(i,0,h){
		rep(j,0,w){
			chmax(ans , g[i][j] + f[i][j]);
		}
	}
	cout << ans - 1<< endl;
}

Measured memory_bytes: 73460
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.Reader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.ArrayDeque;
import java.util.List;
import java.util.Queue;
import java.util.StringTokenizer;

/**
 * The Java template file for AtCoder online judge.
 */
public class Main {

  private static FastScanner scanner;
  private static PrintWriter printer;

  public static void solve() {
    int n = scanner.nextInt();
    int k = scanner.nextInt();
    int[] stones = new int[n];
    for (int i = 0; i < n; i++) {
      stones[i] = scanner.nextInt();
    }
    // dp[i] - True if the next player to move wins with the remaining i
    // stones
    boolean[] dp = new boolean[k + 1];
    dp[0] = false;
    for (int i = 1; i <= k; i++) {
      for (int stone : stones) {
        if (i >= stone && !dp[i - stone]) {
          dp[i] = true;
          break;
        }
      }
    }
    String result = dp[k] ? "First" : "Second";
    printer.println(result);
  }

  public static void main(String[] args) {
    scanner = new FastScanner();
    printer = new PrintWriter(System.out);
    solve();
    printer.flush();
  }

  private static class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    public FastScanner(Reader in) {
      br = new BufferedReader(in);
    }

    public FastScanner() {
      this(new InputStreamReader(System.in));
    }

    public String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

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

    public long nextLong() {
      return Long.parseLong(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }

    public int[] readIntArray(int size) {
      int[] ret = new int[size];
      for (int i = 0; i < size; i++) {
        ret[i] = nextInt();
      }
      return ret;
    }
  }
}


Measured memory_bytes: 23252
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <numeric>

using namespace std;

using ll=long long;

ll N;
vector<ll> X, L;
vector<pair<ll,ll> > P;

const ll INF = 1e15;

int main()
{
    cin >> N;
    P.resize(N);
    for(int i = 0;i < N;i++)
    {
        ll X, L;
        cin >> X >> L;
        P[i].first = X + L;
        P[i].second = X - L;
    }
    sort(P.begin(), P.end());
    ll cur = -INF;
    ll ans = 0;
    for(int i = 0;i < N;i++)
    {
        ll l = P[i].second;
        ll r = P[i].first;

        if(cur <= l)
        {
            ans++;
            cur = r;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2424
// ABC 151-D
// 2020.1.12 bal4u

#include <stdio.h>
#include <string.h>

int H, W;
char map[25][25];
int ans;
char vis[25][25];

#define MAX 1000000
typedef struct { char r, c; int s; } Q;
Q q[MAX+5]; int top, end;
int mv[4][2] = {{-1,0},{0,-1},{1,0},{0,1}};

int bfs(int r0, int c0) {
	int i, r, c, s, rr, cc, ma;
	
	ma = 0;
	memset(vis, 0, sizeof(vis));
	top = 0, end = 1;
	q[0].r = r0, q[0].c = c0, q[0].s = 0;
	while (top != end) {
		r = q[top].r, c = q[top].c, s = q[top].s;
		if (++top == MAX) top = 0;
		if (s > ma) ma = s;
		if (vis[r][c]) continue;
		vis[r][c] = 1;
		for (i = 0; i < 4; ++i) {
			rr = r + mv[i][0], cc = c + mv[i][1];
			if (map[rr][cc] == '#' || rr < 0 || rr >= H || c < 0 || c >= W)
				continue;
			q[end].r = rr, q[end].c = cc, q[end].s = s+1;
			if (++end == MAX) end = 0;
		}
	}
//	printf("r0=%d, c0=%d, ma=%d\n", r0, c0, ma);
	return ma;
}

int main()
{
	int r, c;
	
	scanf("%d%d", &H, &W);
	for (r = 0; r < H; ++r) scanf("%s", map[r]);
	for (r = 0; r < H; ++r) for (c = 0; c < W; ++c) {
		if (map[r][c] == '.') {
			int x = bfs(r, c);
			if (x > ans) ans = x;
		}
	}
	printf("%d\n", ans-1);
	return 0;
}


Measured memory_bytes: 128
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

sort_S = list(sorted(S[:]))
sort_T = list(sorted(T[:]))
i, j = 0, 0
ans = 0
while i < n and j < q:
    if sort_S[i] == sort_T[j]: 
        ans += 1
        i += 1
        j += 1
    elif sort_S[i] > sort_T[j]:
        j += 1
    elif sort_S[i] < sort_T[j]:
        i += 1
print(ans)


Measured memory_bytes: 6552
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
class Z { static void Main() => new K(); }
struct P : IComparable<P>
{
	public readonly int H, Power;
	public P(int h, int p) {H = h; Power = p; }
	public int CompareTo(P p) => End.CompareTo(p.End);
	public int End => H + Power;
	// public override string ToString() => $"({H}, {Power})";
}
class K
{
	public const long INF = 2011686018427387913L;
	public K()
	{
		Console.WriteLine(Solve());
	}
	int Solve()
	{
		var N = int.Parse(Console.ReadLine());
		var ps = new List<P>();
		for (int i = 0; i < N; i++)
		{
			var I = Console.ReadLine().Split().Select(int.Parse).ToArray();
			ps.Add(new P(I[0], I[1]));
		}
		ps.Sort();
		// Console.WriteLine(string.Join(", ", ps));
		// dp[i][j] = [0, i) の人から j 人積むときの高さの最小値
		// j について単調増加
		var dp = new List<long>[N + 1];
		dp[0] = new List<long>{ 0 };
		for (var i = 0; i < N; i++)
		{
			// dp[i + 1] = new long[i + 2];
			dp[i + 1] = dp[i].ToList();
			for (var j = 1; j < dp[i].Count; j++) if (dp[i][j - 1] <= ps[i].H) dp[i + 1][j] = Min(dp[i][j], dp[i][j - 1] + ps[i].Power); else break;
			var z = dp[i][dp[i].Count - 1];
			if (z <= ps[i].H) dp[i + 1].Add(z + ps[i].Power);
			dp[i] = null;
			// Console.WriteLine(string.Join(", ", dp[i + 1]));
		}
		//var m = 0;
		//for (var j = 1; j <= N; j++) if (dp[N][j] < INF) m = j;
		return dp[N].Count - 1;
	}
}


Measured memory_bytes: 38488
// in the name of Allah

#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define MP make_pair
#define pii pair<int, int>
#define p push_back

using namespace std;

const ll mx=2e5+5;

ll n, s[mx], sum;
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i];
		sum+=s[i];
	}
	sort(s, s+n);
	sum-=s[n-1]/2;
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
s = [list(input()) for _ in range(2)]
mod = 10**9+7
ans = 1
i = 0
pre = -1
while i < N:
  if s[0][i] == s[1][i]: # 縦
    if pre == -1:
      ans *= 3
    elif pre == 0:
      ans *= 1
    elif pre == 1:
      ans *= 2

    ans %= mod
    pre = 1
    i += 1
  elif s[0][i] == s[0][i+1]: # 横
    if pre == -1:
      ans *= 6
    elif pre == 0:
      ans *= 3
    elif pre == 1:
      ans *= 2
    
    ans %= mod
    pre = 0
    i += 2
print(ans)

Measured memory_bytes: 61452
#include <iostream>
using namespace std;
int main(void){
    int r,g,b,T;
    cin>>r>>g>>b;
    T=r*100+g*10+b;
    if(T%4==0){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    
    return 0;
}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

int main()
{
	int l=ty(),r=ty();
	if(l<=0 && r>=0)puts("Zero");
	else if(l>0)puts("Positive");
	else puts((r-l+1)&1?"Negative":"Positive");

	return 0;
}


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

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

    vector<int> kind(M);
    for (int i = 0; i < M; ++i) cin >> kind[i];
    sort(kind.begin(), kind.end());

    vector<int> dp(N+1, N); dp[0] = 0;
    for (int i = 0; i < M; ++i)
        for (int j = kind[i]; j <= N; ++j)
            dp[j] = min(dp[j], dp[j - kind[i]] + 1);

    cout << dp[N] << endl;

    return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
int A[4];
void Calc(){
	for(int i=0;i<6;i++){
		int x = rei()-1;
		A[x]++;
	}
	sort(A,A+4);
	if(A[0] == 1 && A[1] == 1 && A[2] == 2 && A[3] == 2){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

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

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

    vector<int> score(N),not_ten;

    int total_s = 0;

    for(int i=0; i<N; i++) {
        cin >> score[i];
        total_s += score[i];
        if(score[i] % 10 != 0) not_ten.push_back(score[i]);
    }

    if(total_s % 10 == 0 && not_ten.size() > 0){
        sort(not_ten.begin(), not_ten.end());
        total_s -= not_ten[0];
    }

    if (total_s % 10 == 0) total_s = 0;

    cout << total_s << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>

using namespace std;

void eratosthenes(vector<int> &n){	
	n[0] = n[1] = 1;
	for (int i = 2;i <= 120000; i++){
		if (n[i] == 0){
			for (int j = 2; j <= (120000/i); j++){
				n[i * j] = 1;
			}

		}
	}
	return;
}

bool isPrime(int n){
	if (n < 2) return false;
	if (n == 2) return true;
	for (int i = 2; i <= sqrt(n) + 1; i++){
		if (n % i == 0) return false;
	}
	return true;
}
		
int main(){
	vector<int> era(120000);
	eratosthenes(era);
	vector<int> Primelist(120001);
	int index = 1;
	for (int i = 1; i <= era.size(); i++){
		if (era[i] == 0){
			Primelist[index] = i;
			index++;
		}
	}
	while(1){
		int n,p; cin >> n >> p;
		if (n + p == -2) break;
		index = 1;
		while(n >= Primelist[index]){
			index++;
		}
		
		vector<int> list(120000);
		for (int i = 1; i <= p; i++){
			for (int j = i; j <= p; j++){
				list[(i-1) * p + j] = Primelist[index + i - 1] + Primelist[index + j - 1];
			}
		}
		sort(list.begin(),list.end());
		index = 0;
		while(list[index] == 0){
			index++;
		}
		cout << list[index + p - 1] << endl;
		
	}

return 0;
}

Measured memory_bytes: 4092
n = int(input())
a_list = list(map(int, input().split()))
a_list = list(enumerate(a_list))
a_list = sorted(a_list, key=lambda x: x[1])
result = ''
sum = 0
for a in a_list:
    sum = a[0] + 1
    result += str(sum) + ' '

print(result)

Measured memory_bytes: 19412
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

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

	long long r, d, x;
	scanf("%lld%lld%lld", &r, &d, &x);
	for (int i = 0; i < 10; i++) {
		x = r*x - d;
		printf("%lld\n", x);
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(s,e) for(int x = s; x <= e; x++)
#define BR printf("\n")
#define INF 2000000000

typedef long long ll;
ll sum = 0;

void rec(ll E, ll e){
    if (E < e) swap(E,e);
    
    ll syo = E/e;
    ll yo  = E%e;
    if (yo) {
        sum += 2*syo*e;
        rec(e,yo);
    }else{
        sum += (2*syo-1)*e;
    }
}

int main(){
    ll N,X;
    cin >> N >> X;
    sum = N;
    
    rec(X,N-X);
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int pot[55][55];

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	string sa[55];
	cin>>n>>m;
	mcf_graph<int,int> gr(n*m+10);
	int g_start=n*m+5,g_end=n*m+6;
	for(i=0;i<n;i++){
		cin>>sa[i];
	}
	a=0;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			if(sa[i][j]=='#')continue;
			if(i!=n-1 && sa[i+1][j]!='#'){
				pot[i+1][j]=min(pot[i][j]-1,pot[i+1][j]);
			}
			if(j!=m-1 && sa[i][j+1]!='#'){
				pot[i][j+1]=min(pot[i][j]-1,pot[i][j+1]);
			}
			a=min(a,pot[i][j]);
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			if(sa[i][j]=='#')continue;
			if(i!=n-1 && sa[i+1][j]!='#')gr.add_edge(i*m+j,(i+1)*m+j,200,pot[i][j]-pot[i+1][j]-1);
			if(j!=m-1 && sa[i][j+1]!='#')gr.add_edge(i*m+j,i*m+j+1,200,pot[i][j]-pot[i][j+1]-1);
			if(sa[i][j]=='o')gr.add_edge(g_start,i*m+j,1,-pot[i][j]);
			gr.add_edge(i*m+j,g_end,1,pot[i][j]-a);
		}
	}
	P pa=gr.flow(g_start,g_end);
	b=a*pa.first+pa.second;
	cout<<-b<<endl;
}

Measured memory_bytes: 4200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define repin(a,n) vector<ll> a(n);rep(i,n){cin>>a[i];}
#define repins(a,n) vector<string> a(n);rep(i,n){cin>>a[i];}
#define repind(a,n) vector<double> a(n);rep(i,n){cin>>a[i];}
#define in(a) ll a;cin>>a;
#define ins(a) string a;cin>>a;
#define ind(a) double a;cin>>a;
template<class T>
inline void out(T a){cout<<a<<endl; }
inline void out(double a){ printf("%.10f\n", a);} 
#define all(x) (x).begin(),(x).end()
#define rep2(i,a,b) for(ll i=(a);i<(b);++i)
using vell = vector<ll>;
using ves = vector<string>;
using ved = vector<double>;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main()
{
	in(n);
	in(k);
	out((int)(floor(log(n) / log(k))+1));
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main()
{
  ll N,sum;cin>>N;
  sum=0;
  VL A(N);

  REP(i,N)
  {
    cin>>A[i];
    sum=sum+A[i];
  }
  ll left,ans,right,tmp;
  left=0;
  right=0;
  tmp=0;
  ans=2020202020;
  REP(i,N)
  {
    left=left+A[i];
    right=sum-left;
    tmp=llabs(left-right);
    ans=min(ans,tmp);
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mondai0029
{
	class Program
	{
		static void Main(string[] args)
		{
			var	word	= Console.ReadLine().Split();

			int	max_cnt		= 0;
			var	max_cnt_str	= "";
			for( int i = 0; i < word.Length; i++ ) {
				int	cnt	= 0;
				for( int j = 0; j < word.Length; j++ ) {
					if( word[ i ] == word[ j ] ) {
						cnt++;
					}
				}
				if( cnt > max_cnt ) {
					max_cnt		= cnt;
					max_cnt_str	= word[ i ];
				}
			}

			int	max_len		= 0;
			var	max_len_str	= "";
			for( int i = 0; i < word.Length; i++ ) {
				if( word[ i ].Length > max_len ) {
					max_len		= word[ i ].Length;
					max_len_str	= word[ i ];
				}
			}

			Console.WriteLine( max_cnt_str + " " + max_len_str );
		}
	}
}

Measured memory_bytes: 5224
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,ans;
int main(){
	scanf("%lld",&n);
	printf("%lld",(n-2)*180);
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int n,m;cin>>n>>m;
    vc<pi> ab;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        ab.emplace_back(a,b);
    }

    sort(all(ab));
    
    ab.emplace_back(m+1,0);
    priority_queue<int> pq;
    ll ans=0;

    int idx=0;
    repa(i,1,m+1){
        while(ab[idx].first<=i){
            pq.push(ab[idx].second);
            idx++;
        }
        if(!pq.empty()){
            ans+=pq.top();
            pq.pop();
        }
    }

    cout<<ans<<"\n";

    return 0;

}

Measured memory_bytes: 1908
n, k = map(int, input().split())
d_array = [int(x) for x in input().split()]

for i in range(n, 100000):
    flag = True
    price = str(i)
    for d in d_array:
        str_d = str(d)
        if str_d in price:
            flag = False
    else:
        if flag:
            print(i)
            exit()

            

Measured memory_bytes: 40684
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

const int correct = abs('a' - 'A');

int ans = 0;
vector<string> vec(9);
vector<vector<string> > piece(3,vector<string>(3));
vector<vector<int> > offset(3,vector<int>(3,0));
vector<int> used(9,0);

bool valid(char a,char b){
  return abs(a - b) == correct; 
}

void rec(int x, int y) {
  if(x == 3) return rec(0, y + 1);
  if(y == 3) {
    ans++;
    return ;
  }

  for(int i = 0;i < 9;i++){
    if(used[i])continue;
    for(int d = 0;d < 4;d++){
      if(x-1 >= 0){
	if(!valid(vec[i][(3+d)%4], piece[y][x-1][(1+offset[y][x-1])%4])){
	  continue;
	}
      }
      if(y-1 >= 0){
	if(!valid(vec[i][d], piece[y-1][x][(2+offset[y-1][x])%4])){
	  continue;
	}
      }
      piece[y][x] = vec[i];
      offset[y][x] = d;
      used[i] = 1;
      rec(x+1,y);
      used[i] = 0;
    }
  }
}

int main(){
  int n;
  cin >> n;
  while(n--){
    for(auto &e : vec) {
      cin >> e;
    }
    ans = 0;
    rec(0,0);
    cout << ans << endl;
  }
    
    
  
  return 0;
}

Measured memory_bytes: 1220