akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  int k;
  cin >> s >> k;
  int n = s.length();
  vector<string> d;
  for(int i = 0; i < n; i++){
    for(int j = i; j < min(k+i, n); j++){
      string t = "";
      for(int l = i; l <= j; l++){
        t += s[l];
      }
      d.push_back(t);
    }
  }
  sort(d.begin(), d.end());
  decltype(d)::iterator result = unique(d.begin(), d.end());
  d.erase(result, d.end());
  cout << d[k-1] << endl;
  return 0;
}

Measured memory_bytes: 1660
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	LL n;
	cin>>n;
	cout<<(n*(n-1))/2<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int row, col;
        int[] matrix;

        row = scanner.nextInt();
        col = scanner.nextInt();

        matrix = new int[col];

        int in, sum;
        for(int rowi = 0; rowi < row; rowi++){
            sum = 0;
            for(int coli = 0; coli < col; coli++){
                in = scanner.nextInt();
                matrix[coli] += in;
                sum += in;
                System.out.print(in + " ");
            }
            System.out.println(sum);
        }

        sum = 0;
        for(int i:matrix){
            sum += i;
            System.out.print(i + " ");
        }
        System.out.println(sum);

        scanner.close();
    }
}



Measured memory_bytes: 40160
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using VI = vector<int>;
using VB = vector<bool>;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  // a^tを求める関数 階乗の計算
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

// a^n modを計算している
ll modpow(ll a, ll n, ll m){
  ll res = 1;
  // 二進法展開することで求めている
  // n = 45とすると
  // 45=2^0+2^2+2^3+2^5
  while (n > 0){
    if (n & 1) res = res * a % m;
    a = a * a % m;
    // ビット演算子　みぎに１ビットずらす。　整数では x/2しているのと同じ
    n >>= 1;
  }
  return res;
}

mint choose(int n, int a){
  mint x = 1, y =1;
  // y = a!
  // 階乗の計算
  // xは分子なので (n-i)!
  rep(i, a){
    x *= n -i;
    y *= i + 1;
  }

  return x/y;
}
int main()
{
  int n, a, b;
  cin >> n >> a >> b;
  mint ans = mint(2).pow(n);
  ans -= 1;
  ans  -= choose(n, a);
  ans  -= choose(n, b);
  cout << ans.x << endl;
  return 0;

}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    
    int d = 20;
    int n;
    cin >> n;
    unordered_map<int, unordered_map<int, int>> um;
    long long int res = 0;
    for (int i = 0; i < n; i++ ) {
        string s;
        cin >> s;
        long long int t;
        int n1 = 0, n2 = 0;
        if (s.find('.') == string::npos) {
            t = stoll(s);
            while (t % 2 == 0) {
                t /= 2;
                n1++;
            }
            while (t % 5 == 0) {
                t /= 5;
                n2++;
            }
        } else {
            int index = s.find('.');
            n1 = s.size() - 1 - index;
            n1 = -n1;
            n2 = n1;
            s = string(s.begin(), s.begin() + index) + string(s.begin() + index + 1, s.end());
            t = stoll(s);
            while (t % 2 == 0) {
                t /= 2;
                n1++;
            }
            while (t % 5 == 0) {
                t /= 5;
                n2++;
            }
        }
        um[n1][n2]++;
        // cout << n1 << " " << n2 << endl;
        // cout << res << endl;
    }
    for (auto pp1 : um) {
        for (auto pp2 : pp1.second) {
            int n1 = pp1.first;
            int n2 = pp2.first;
            long long int c = pp2.second;
            if (n1 >= 0 && n2 >= 0) res -= c;
            for (auto p1 : um) {
                for (auto p2 : p1.second) {
                    if (n1 + p1.first >= 0 && n2 + p2.first >= 0) {
                        res += p2.second * c;
                    }
                }
            }
        }
    }
    cout << res / 2 << endl;
}


Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
int t;

int main()
{
    while (true)
    {
        int x,y;
        cin>>x>>y;
        if (x==0 && y==0) break;
        if (x>y)
        {
            t=x;
            x=y;
            y=t;
        }
        cout<<x<<" "<<y<<endl;
    }
    return 0;
}




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

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define int long long
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

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

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}

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

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);
	int n,a,b;
	cin >> n >> a >> b;
	int st = a + b;
	int ans = n/st;
	ans *= a;
	ans += min(a,n%st);
	cout << ans;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int cmp(const void *a, const void *b)
{
  return *(int*)b-*(int*)a;
}

int main()
{
  int n,h;
  
  scanf("%d%d",&n,&h);
  
  int a[n],b[n];
  int count=0;
  int i;
  
  for(i=0;i<n;i++)
  {
    scanf("%d%d",&a[i],&b[i]);
  }
  
  qsort(a,n,sizeof(int),cmp);
  qsort(b,n,sizeof(int),cmp);
 
  i=0;
  while(h>0)
  {
    if(i<n)
    {
     if(a[0]<b[i])
     {
       h-=b[i];
     }
     else
     {
       h-=a[0];
     }
    }
    else
    {
       h-=a[0];
    }
    i++;
    count++;
  }
  
  printf("%d\n",count);
  return 0;
}

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

int n;
int p[1005] = {0};
int x[1005] = {0};
// black whilte list, dp from n to 1
int dp[1005][2] = {0};
vector<int> ls[1005];
void prians(bool answer) {
  if(answer)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}

bool solve();
void make(int x);

int main() {
  cin >> n;
  for(int i = 1; i < n; ++i) {
    cin >> p[i];
    --p[i];
  }
  for(int i = 0; i < n; ++i) cin >> x[i];
  prians(solve());
  // for(int i = 0; i < n; ++i)
  // cout << dp[i][0] << " " << dp[i][1] << endl;
  return 0;
}

bool solve() {
  for(int i = n - 1; i >= 0; --i) {
    if(i == 0 && (dp[i][0] <= x[i] || dp[i][1] <= x[i]))
      return 1;
    make(i);
    // both over
    if(dp[i][0] > x[i] && dp[i][1] > x[i]) break;
    // both less
    else if(dp[i][0] <= x[i] && dp[i][1] <= x[i]) {
      if(dp[i][0] > dp[i][1]) swap(dp[i][0], dp[i][1]);
      dp[i][1] = x[i];
      dp[p[i]][0] += dp[i][0];
      dp[p[i]][1] += dp[i][1];
      ls[p[i]].push_back(dp[i][1] - dp[i][0]);
    }
    // either less
    else {
      if(dp[i][0] > dp[i][1]) swap(dp[i][0], dp[i][1]);
      dp[i][0] = x[i];
      dp[p[i]][0] += dp[i][0];
      dp[p[i]][1] += dp[i][1];
      ls[p[i]].push_back(dp[i][1] - dp[i][0]);
    }
  }
  return 0;
}

void make(int now) {
  sort(ls[now].begin(), ls[now].end(), greater<int>());
  if(dp[now][0] > dp[now][1]) swap(dp[now][0], dp[now][1]);
  if(dp[now][0] >= x[now]) return;
  for(int i = 0; i < ls[now].size(); ++i) {
    if(dp[now][0] + ls[now][i] <= x[now]) {
      dp[now][0] += ls[now][i];
      dp[now][1] -= ls[now][i];
    }
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)



int main(){
	int n, l;
	cin >> n >> l;
	int ans=0;
	int index;
	if(l>=0) index = 0;
	else if(l <= -1*n) index = n-1;
	else index = n;
	
	REP(i,n){
		if(l + i == 0 || index == i) continue;
		ans += l+i;
	}
	
	cout << ans << endl;
	
	
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
//#include<iostream>
using namespace std;
 
const int N = 200005;
 
int a[N];
int c[N];
 
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	cin>>n;
	int ans = 0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		c[i] = -1000000;
	}
	
	for(int i=1;i<=n;i++){
		c[a[i]] = max(c[a[i]],c[a[i]-1]+1);
		ans = max(ans,c[a[i]]);
	}
	
	if(ans == 0){
		cout<<-1;
		return 0;
	}
	cout<<n-ans;
	
	return 0;
}


Measured memory_bytes: 5224
package main

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

func main() {
	scan_init()
	n := scanInt()
	a := make([]int,n)
	memo := map[int][]int{}
	for i:= 0; i<n; i++ {
		a[i] = scanInt()
		if _,ok := memo[a[i]]; !ok {
			memo[a[i]] = []int{}
		}
		memo[a[i]] = append(memo[a[i]],i)
	}
	q := scanInt()
	b := make([]int,q)
	c := make([]int,q)
	for i:= 0; i<q; i++ {
		// 添字の指定なので -1
		b[i] = scanInt()
		c[i] = scanInt()
	}
	// fmt.Println(b,c,a)
	sum := 0
	for i:= 0; i<n;i++ {
		sum += a[i]
	}
	for i:= 0; i<q; i++ {
		takeB := b[i]
		takeC := c[i]
		henka := takeC - takeB
		sum += henka*len(memo[takeB])
		memo[takeC] = append(memo[takeC],memo[takeB]...)
		memo[takeB] = []int{}
		// fmt.Println(a)
		fmt.Println(sum)
	}
}
var sc = bufio.NewScanner(os.Stdin)
func scan_init () {
	sc.Split(bufio.ScanWords)
}
func scanInt () int{
sc.Scan()
	i,_ := strconv.Atoi(sc.Text())
	return i
}
//func scan () string{
//  sc.Scan()
//	return sc.Text()
//}


Measured memory_bytes: 102688
N = int(input())
dp = [1] * (N+1)#約数個数テーブル
def primes(n):#nまでの素数を列挙
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2,int(n**(0.5)+1)):
        if not is_prime[i]:
            continue
        for j in range(i*2,n+1,i):
            is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
li_p = primes(N)
for i in li_p:
    cnt = 1
    I = i
    while i <= N:
        tmp = cnt
        cnt += 1
        for j in range(i, N+1, i):
            dp[j] //= tmp
            dp[j] *= cnt
        i *= I
ans = 0
for i in range(1, N+1):
    ans += i*dp[i]
print(ans)

Measured memory_bytes: 271232
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;

#define int long long

#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define rrep(i, n) for (int i=(int)n-1;i>=0;--i)
#define rrep1(i, n) for (int i=n;i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)r;++i)
#define rrange(i, l, r) for (int i=(int)r-1;i>=(int)l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;
using ld=long double;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}

const int mod = TEN(9)+7;

string convert(int a)
{
	string ret = "";

	while (a) {
		ret.push_back(a % 10);
		a /= 10;
	}

	reverse(all(ret));

	return ret;
}

int S(int a)
{
	int ret = 0;

	while (a) ret += a % 10, a /= 10;

	return ret;
}

double f(int a)
{
	return (double)a / S(a);
}

void output(int a)
{
	printf("%lld: S(%lld) = %lld, f(%lld) = %f\n", a, a, S(a), a, f(a));
}

signed main()
{
	int N, x; cin >> N >> x;
	vi a(N);
	rep(i,N) cin>>a[i];
	int ans = 0;
	ans += max(a[0] - x, 0ll);
	chmin(a[0], x);

	range(i, 1, N) {
		if (a[i] + a[i - 1] > x) {
			// 0 <= x - a[i - 1]
			int nxt_ai = x - a[i - 1];
			ans += max(a[i] - nxt_ai, 0ll);
			a[i] = nxt_ai;
			if (a[i] + a[i - 1] > x) return 1;
		}
	}

	cout << ans << endl;
}




Measured memory_bytes: 1024
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  var a = Array.fill(6)(sc.nextInt())
  var b = Array.fill(4)(0)
  for (i <- 0 until 6){
    b(a(i)-1) += 1
  }
  println(if(b.max >= 3) "NO" else "YES")
}


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n; cin >> n;

    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    int ans = INF;

    int cur = 1;

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

        if (a[cur] == 2) {
            ans = i;
            break;
        }

        cur = a[cur];
    }

    if (ans == INF) {
        puts("-1");
    } else {
        cout << ans << endl;
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=1000000000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> divisor(ll x){vector<ll> div;
	for(ll i=1;i*i<=x;i++){if(x%i==0){div.pb(i);if(i*i!=x)div.pb(x/i);}}
	sort(div.bg,div.ed);return div;}


int main(){
	ll N; cin>>N;
	vector<ll>A(2*N);
	rep(i,2*N) cin>>A[i];
	sort(A.bg,A.ed);
	ll ans=0;
	for(int i=0;i<2*N;i+=2){
		ans+=A[i];
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

vll md;

void divisor(ll m){
    for(ll i=1;i*i<=m;i++){
        if(m%i==0){
            md.push_back(i);
            if(i!=m/i)md.push_back(m/i);
        }
    }
    return;
}

int main(){
    ll n,m;cin>>n>>m;
    divisor(m);
    sort(all(md));
    ll ans;
    for(auto tmp:md){
        if(tmp*n<=m)ans=tmp;
        else break;
    }
    cout<<ans<<endl;
}

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

int main(){
  int n;
  cin >> n;
  int s = 1000000000;
  int sum = 0;
  int m = n;
  for(int i=0; i<9; i++){
    sum += m/s;
    m -= (m/s)*s;
    s /= 10;
  }
  sum += m;
  if(n%sum){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,l;
  cin>>n>>l;
  long long r=l+n-1;
  long long eat;
  if(l>=0){
eat=l;
  }
else if(r<=0){
eat=r;
}
else{
eat=0;
}
 long long d=(l+r)*n;
cout<<d/2-eat<<endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

const int maxn = 500010;
int n, K, p[maxn], a[maxn], d[maxn], mn[maxn << 2];
vector<int> G[maxn];
priority_queue<int> q;

#define mid (l + r >> 1)
#define ls (k << 1)
#define rs (k << 1 | 1)
void modify(int k, int l, int r, int p, int v) {
    if (l == r) { mn[k] = v; return; }
    if (mid >= p) modify(ls, l, mid, p, v);
    else modify(rs, mid + 1, r, p, v);
    mn[k] = min(mn[ls], mn[rs]);
}

int qmin(int k, int l, int r, int ql, int qr) {
    if (l >= ql && r <= qr) return mn[k];
    int ans = INT_MAX;
    if (mid >= ql) ans = qmin(ls, l, mid, ql, qr);
    if (mid < qr) ans = min(ans, qmin(rs, mid + 1, r, ql, qr));
    return ans;
}

int main() {
    scanf("%d %d", &n, &K);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &p[i]), a[p[i]] = i;
    }
    memset(mn, 0x3f, sizeof(mn));
    for (int i = n; i; i--) {
        int j = qmin(1, 1, n, a[i] - K + 1, a[i]);
        if (j <= n) G[a[j]].push_back(a[i]), d[a[i]]++;
        j = qmin(1, 1, n, a[i], a[i] + K - 1);
        if (j <= n) G[a[j]].push_back(a[i]), d[a[i]]++;
        modify(1, 1, n, a[i], i);
    }
    for (int i = 1; i <= n; i++) {
        if (!d[i]) q.push(i);
    }
    for (int i = n; i; i--) {
        int v = a[i] = q.top(); q.pop();
        for (int u : G[v]) if (!--d[u]) q.push(u);
    }
    for (int i = 1; i <= n; i++) {
        p[a[i]] = i;
    }
    for (int i = 1; i <= n; i++) {
        printf("%d\n", p[i]);
    }
    return 0;
}

Measured memory_bytes: 45184
n = int(input())
a = list(map(int, input().split()))

dict = {}
for i in range(n):
    if a[i] in dict:
        dict[a[i]] = dict[a[i]] + 1
    else:
        dict[a[i]] = 1

total_cnt = 0
for k, v in dict.items():
    a_cnt = 0
    if k > v:
        a_cnt += v
    else:
        a_cnt += (v - k)
    total_cnt += a_cnt
print(total_cnt)

Measured memory_bytes: 21880
#include<bits/stdc++.h>
#define rint register int 
#define ll long long 
#define mk make_pair
#define pa pair<int,int>
using namespace std;
int N,M,A[1010010],cnt;
int main(){
	cin>>N>>M;
	for(rint i=1;i<=M;++i) cin>>A[i],cnt+=(A[i]&1);
	if(cnt>2) {
		cout<<"Impossible\n";
		return 0;
	}
	if(N==1) cout<<1<<"\n"<<"1\n1\n",exit(0);
	if(M==1) {
		cout<<N<<"\n2\n"<<N-1<<" "<<1<<endl;
		return 0;
	}
	if(cnt==1) {
		for(rint i=1;i<=M;++i) if(A[i]&1) swap(A[1],A[i]);
		for(rint i=1;i<=M;++i) cout<<A[i]<<" ";
		cout<<endl;
		cout<<M<<endl;
		A[1]++,A[M]--;
//		cout<<A[1]+1<<" ";
		for(rint i=1;i<=M;++i) cout<<A[i]<<" ";
//		cout<<endl; 
		return 0;
	}
	int fl=1;
	for(rint i=1;i<=M;++i) if(A[i]&1) if(fl) swap(A[1],A[i]),fl=0;else swap(A[M],A[i]);
	for(rint i=1;i<=M;++i) cout<<A[i]<<" ";
		cout<<endl;
		A[1]++,A[M]--;
		if(A[M]==0) M--;
		cout<<M<<endl;
	
//		cout<<A[1]+1<<" ";
		for(rint i=1;i<=M;++i) cout<<A[i]<<" ";
//		cout<<endl; 
		return 0;
	return 0;
}

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

int main() {
    long long int a, b, k;
    cin >> a >> b >> k;
    if(a < k) { 
        b -= k-a;
        a = 0;
        if(b < 0) b = 0;
    } else {
        a -= k;
    }
    cout << a << " " << b << '\n';
}


Measured memory_bytes: 256
S = input()
ans = [0]*len(S)
#Rについて
Rlen = 0
for n,s in enumerate(S):#S[0]=R,S[N]=L
    if s=="R":
        Rlen += 1
    if s=="R" and S[n+1] == "L":
        ans[n] += (Rlen+1)//2
        ans[n+1] += Rlen//2
        Rlen = 0
Llen = 0
for n in range(len(S)-1,-1,-1):#S[0]=R,S[N]=L
    s = S[n]
    if s=="L":
        Llen += 1
    if s=="L" and S[n-1]=="R":
        ans[n] += (Llen+1)//2
        ans[n-1] += Llen//2
        Llen = 0
    
print(*ans)

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
 
    vector<int> a(n);
    for(int i= 0; i < n; i++) {
        cin >> a[i];
    }
 
    vector<int> pre_gcd(n + 1), suf_gcd(n + 1);
 
    for(int i = 1; i <= n; i++) {
        pre_gcd[i] = __gcd(pre_gcd[i - 1], a[i - 1]);
    }
 
//    for(auto it : pre_gcd) {
//        cout << it << " ";
//    }
//    cout << endl;
 
    for(int i = n; i >= 1; i--) {
        suf_gcd[i - 1] = __gcd(suf_gcd[i], a[i - 1]);
    }
 
//    for(auto it : suf_gcd) {
//        cout << it << " ";
//    }
//    cout << endl;
 
    int ans = 0;
    for(int i = 0; i + 1 < pre_gcd.size(); i++) {
        ans = max( ans, __gcd(pre_gcd[i], suf_gcd[i + 1]) );
    }
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main() {

    int n;cin>>n;
    vector<vector<int>> dp(n, vector<int>(3,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>dp[i][j];
        }
    }
    for(int i=1;i<n;i++){
        dp[i][0]+=max(dp[i-1][1], dp[i-1][2]);
        dp[i][1]+=max(dp[i-1][0], dp[i-1][2]);
        dp[i][2]+=max(dp[i-1][0], dp[i-1][1]);
    }
int ans=0;
for(int j=0;j<3;j++) ans=max(ans, dp[n-1][j]);
cout<<ans;
    return 0;
}


Measured memory_bytes: 8804
#include<stdio.h>

int main(){
	int b,c;
	scanf("%d %d",&b,&c);
	long long ans = 0;
	ans = c;
	for(int i = 1; i < b; i++){
		ans = ans * (c-1);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,k;
    cin >> n >> k;
    k *= n;
    vector<int> a(n);
    map<int,vector<int>> idx;
    rep(i,n){
        cin >> a[i];
        idx[a[i]].emplace_back(i);
    }
    vector<ll> w(n);
    for(auto kv: idx){
        int s = kv.second.size();
        kv.second.emplace_back(kv.second[0] + n);
        for(int i=0; i<s; i++){
            w[kv.second[i]] = kv.second[i+1] - kv.second[i] + 1;
        }
    }
    int L = 60;
    vector<vector<ll>> nx;
    nx.emplace_back(w);
    for(int _=0; _<L; _++){
        vector<ll> x = nx.back();
        vector<ll> y(n);
        for(int i=0; i<n; i++){
            y[i] = min(k+1,x[i]+x[(i+x[i])%n]);
        }
        nx.emplace_back(y);
    }
    ll cur = 0;
    for(int i=L-1; i>=0; i--){
        if(cur + nx[i][cur%n] <= k){
            cur += nx[i][cur%n];
        }
    }
    if(cur == k) return 0;
    vector<int> ans;
    set<int> has;
    for(int i=cur%n; i<n; i++){
        if(has.count(a[i])){
            while(1){
                int v = ans.back();
                ans.pop_back();
                has.erase(v);
                if(v == a[i]) break;
            }
        }else{
            ans.emplace_back(a[i]);
            has.insert(a[i]);
        }
    }
    rep(i,ans.size()){
        cout << ans[i] << " \n"[i+1==ans.size()];
    }
    return 0;
}

Measured memory_bytes: 131272
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int g[102][102];

int main(void){
  int n,w,h,s,t;

  while(cin >> n,n){
    fill(g[0],g[102],0);
    cin >> w >> h;

    for(int i=0;i<n;i++){
      int x,y;
      cin >> x >> y;
      g[y-1][x-1]=1;
    }
    cin >> s >> t;
    int ans = 0;
    for(int i=0;i<h-t+1;i++){
      for(int j=0;j<w-s+1;j++){
	int cnt = 0;
	for(int k=0;k<t;k++){
	  for(int l=0;l<s;l++){
	    cnt += g[i+k][j+l];
	  }
	}
	ans = max(ans, cnt);
      }
    }

    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3052
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {
    int a,b,c=0;
    cin>>a>>b;
    for(int i=0;i<a;i++){
        for(int j=1;j<13;j++){
            if(i==j){
                c++;
            }
        }
    }
    for(int i=1;i<=b;i++){
        if(i==a)c++;
    }
    cout<<c<<endl;
    return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n,cnt=0,ans=0,a[10000000],b[10000000],c,cmp,data,m,h,w,x,y,xcmp,ycmp,sum=0;
bool graph[50][50];
bool visited[50];
string s;

vector<int> z;
void dfs(int v){
    visited[v]=true;
    rrep(v2,0,n){
        if(graph[v][v2]==false){
            continue;
        }
        if(visited[v2]==true){
            continue;
        }
        dfs(v2);
    }
}

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

       cin >> n >> m;
       rep(i,m){
           cin >> a[i] >> b[i];
           a[i]--;
           b[i]--;
           graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
       }
       rep(i,m){
           graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;
           rep(j,n){
               visited[j]=false;
           }
           dfs(0);
           bool bridge=false;
           rep(j,n){
               if(visited[j]==false){
                   bridge=true;
               }
           }
           if(bridge){
               ans+=1;
           }
           graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
       }
       Cout(ans);
return 0;
}


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

class dice {
private :
    map<string, int> face_num;
public :
    dice() {}
    dice(map<string, int> &face_num) {
        this->face_num = face_num;
    }

    void roll(const char &direction) {
        if (direction == 'E') {
            swap(face_num["top"], face_num["left"]);
            swap(face_num["right"], face_num["left"]);
            swap(face_num["bottom"], face_num["left"]);
        }
        else if (direction == 'N') {
            swap(face_num["front"], face_num["bottom"]);
            swap(face_num["top"], face_num["bottom"]);
            swap(face_num["back"], face_num["bottom"]);
        }
        else if (direction == 'S') {
            swap(face_num["top"], face_num["back"]);
            swap(face_num["front"], face_num["back"]);
            swap(face_num["bottom"], face_num["back"]);
        }
        else if (direction == 'W') {
            swap(face_num["top"], face_num["right"]);
            swap(face_num["left"], face_num["right"]);
            swap(face_num["bottom"], face_num["right"]);
        }
        else
            cout << "plz input direction" << '\n';
    }

    void rotate() {
        int front_num = face_num["front"];
        face_num["front"] = face_num["left"];
        face_num["left"] = face_num["back"];
        face_num["back"] = face_num["right"];
        face_num["right"] = front_num;
    }

    dice new_rolled_dice(const char &direction) {
        dice d = *this;
        d.roll(direction);
        return d;
    }
    dice new_fliped_dice() {
        dice d = *this;
        d.roll('W');
        d.roll('W');
        return d;
    }
    
    int position_num(const string &position) {
        return face_num[position];
    }

    bool equals(dice &d) {
        return face_num == d.face_num;
    }

    void show() {
        cout << face_num["top"] << face_num["front"] << face_num["right"] << face_num["left"] << face_num["back"] << face_num["bottom"] << '\n';
    }
};

int main()
{
    map<string, int> num1, num2;
    cin >> num1["top"] >> num1["front"] >> num1["right"] >> num1["left"] >> num1["back"] >> num1["bottom"];
    dice d1 = dice(num1);
    cin >> num2["top"] >> num2["front"] >> num2["right"] >> num2["left"] >> num2["back"] >> num2["bottom"];
    dice d2 = dice(num2);


    vector<dice> dices(6);
    string dir = "ENSW";
    for(int i = 0; i < dices.size(); i++) {
        if (i == 0)
            dices[0] = d1;
        else if (i == 5)
            dices[5] = d1.new_fliped_dice();
        else
            dices[i] = d1.new_rolled_dice(dir[i - 1]);
    }
    for(int i = 0; i < dices.size(); i++) {
        for(int j = 0; j < 4; j++) {
            if (dices[i].equals(d2)) {
                cout << "Yes" << '\n';
                return 0;
            }
            dices[i].rotate();
        }
    }
    cout << "No" << '\n';
    return 0;
}


Measured memory_bytes: 3244
import java.io.*;
class Main{
	public static void main(String[] args) throws IOException {
		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		 String buf = br.readLine();
		 int x = Integer.parseInt(buf);
		 x = x * x * x;
		 System.out.println(x);
	}
}

Measured memory_bytes: 24392
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int N){
    vector<int>S;
    rep(i,N)if(bit & (1<<i))S.push_back(i);
    return S;
}

int main(){
    string s;cin>>s;
    int n = s.size();
    vector<int> v(n,0);
    int cnt1 = 0,cnt2 = 0;
    rep(i,n-1){
        if(s[i] == 'R' && s[i+1] == 'L' && i%2==1){
            v[i] += cnt1+1;
            v[i+1] += cnt2+1;
            cnt1 = 0;cnt2 = 0;
            i++;
            continue;
        }
        if(s[i] == 'R' && s[i+1] == 'L' && i%2==0){
            v[i] += cnt2+1;
            v[i+1] += cnt1+1;
            cnt1 = 0;cnt2 = 0;
            i++;
            continue;
        }
        if(s[i] == 'R' && i%2 == 1)cnt1++;
        if(s[i] == 'R' && i%2 == 0)cnt2++;
    }
    reverse(ALL(s));
    reverse(ALL(v));
    cnt1 = 0;cnt2 = 0;
    rep(i,n-1){
        if(s[i] == 'L' && s[i+1] == 'R' && i%2==1){
            v[i] += cnt1;
            v[i+1] += cnt2;
            cnt1 = 0;cnt2 = 0;
            i++;
            continue;
        }
        if(s[i] == 'L' && s[i+1] == 'R' && i%2==0){
            v[i] += cnt2;
            v[i+1] += cnt1;
            cnt1 = 0;cnt2 = 0;
            i++;
            continue;
        }
        if(s[i] == 'L' && i%2 == 1)cnt1++;
        if(s[i] == 'L' && i%2 == 0)cnt2++;
    }
    reverse(ALL(v));
    rep(i,n)cout<<v[i]<<" ";
}



Measured memory_bytes: 1024
package main
import(
  "fmt"
)
func main(){
  var a, b, r, x, temp int64
  fmt.Scan(&a, &b)
  x=a*b
  if a<b{
    temp=a
    a=b
    b=temp
  }
  r=a%b
  l:
  for{
    if r==0{
      break l
    }
    a=b
    b=r
    r=a%b
    }
  fmt.Println(x/b)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
// #include <boost/lexical_cast.hpp>
using namespace std;


#define ll long long int
#define vll vector<ll>tm#define vllv vector<vector<ll>> 
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
 

void solve()
{
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	if(a[0]==0)
	{
		cout<<0;
		return;
	}
	ll ans=1;
	
	ll tm = 1e18;
	
	for(ll i=0;i<n;i++)
	{
		if((tm/ans) >= a[i]) 
		{
			ans*=a[i];
		}
		else
		{
			cout<<-1;
			return;
		}
	}
	cout<< ans << endl;
}
	

int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4428
#include <bits/stdc++.h>
		using namespace std;
		typedef long long ll;
		#define PI 3.14159265358979
		#define EPS 1e-8
		#define mod  998244353
		#define fi first
		#define se second
		#define mp make_pair
		#define pb push_back
		#define endl "\n"
			 
		const ll INF=1e15;	
		const int N=2e5+50;
		 

		 
		long long binpow(long long a, long long b, long long m) {
			a %= m;
			long long res = 1;
			while (b > 0) {
				if (b & 1)
					res = res * a % m;
				a = a * a % m;
				b >>= 1;
			}
			return res;
		}
		
		ll modinverse(ll a,ll m)
		{
			return binpow(a,m-2,m);
		}
		
		
		int main()
		{
			ios_base::sync_with_stdio(false);
			cin.tie(NULL);cout.tie(0);
			
			ll n;
			cin>>n;
			stack<ll> st[1005];
			for(ll i=1;i<=n;i++)
			{
				vector<ll> v;
				for(ll j=1;j<n;j++)
				{
					ll val;cin>>val;
					v.pb(val);
				}
				
				reverse(v.begin(),v.end());
				
				for(ll j=0;j+1<n;j++)
				{
					st[i].push(v[j]);
				}
			}
			
			ll cnt=0;
			ll c1=0;
			while(c1<((n*(n-1))/2))
			{
				ll c=0;
				cnt++;
				vector<ll> vis(1005,0);
				for(ll i=1;i<=n;i++)
				{
					if(!st[i].empty() && !vis[i])
					{
						ll j=st[i].top();
						if(!st[j].empty() && st[j].top()==i && !vis[j])
						{
							//cout<<i<<" "<<j<<endl;
							st[i].pop();
							st[j].pop();
							c=1;
							c1++;
							vis[i]=vis[j]=1;
						}
					}
				} 
				if(!c)
				{
					cout<<-1;
					exit(0);
				}
			}
			cout<<cnt;
		}
			
			
		


Measured memory_bytes: 12352
from collections import deque
s = input()
a_L = deque([val for val in s])

div_L = [""]
moji = ""

counter = 0

while a_L:
    tmp = a_L.popleft()
    moji += tmp
    if moji !=  div_L[counter]:
        div_L.append(moji)
        moji = ""
        counter += 1

print(len(div_L)-1)


Measured memory_bytes: 74744
S = input()
n = len(S)
mod = 998244353
# dp[i][j] = i番目まで見てj個青玉をとっているときの場合の数
# 求めるもの : sum(dp[2*n])
dp = [[0] * (2 * n + 1) for i in range(2 * n + 1)]
dp[0][0] = 1
now = 0
for i, s in enumerate(S):
    now += int(s)
    for j in range(i+1):
        dp[i + 1][j] += ((2 * (i + 1) - now - (i - j)) > 0) * dp[i][j]
        dp[i + 1][j + 1] += ((now - j) > 0) * dp[i][j]
        dp[i + 1][j] %= mod
        dp[i + 1][j + 1] %= mod
ans = 0
for i in range(n, 2 * n):
    for j in range(i+1):
        dp[i + 1][j] += ((2 * n - now - (i - j)) > 0) * dp[i][j]
        dp[i + 1][j + 1] += ((now - j) > 0) * dp[i][j]
        dp[i + 1][j] %= mod
        dp[i + 1][j + 1] %= mod
print(sum(dp[2*n])%mod)

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

long long gcd(long long A,long long B)
{
    if(B == 0) return A;
    return gcd(B,A%B);
}
int main()
{
    long long A,B;
    cin >> A >> B;
    long long x = gcd(A,B);
    int ret = 1;
    long long n = x;
    for(long long i=2;i*i<=n;i++){
        if(x % i != 0) continue;
        while(x % i == 0){
            x /= i;
        }
        ret++;
    }
    if( x != 1) ret++;
    cout << ret << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
const int N = 1e5+5;
const int INF = (1<<30)-1;

int hd[N],iter[N],dis[N];
struct E{int v,w,nxt;}e[N<<3];
queue<int>Q;
bool v[N];
int p[N],q[N],c[N],d[N];
int n,nc,nd,tot=1,S,T;

inline void add(int u,int v,int w,int w2){
	e[++tot]={v,w,hd[u]};hd[u]=tot;
	e[++tot]={u,w2,hd[v]};hd[v]=tot;
}
inline bool bfs(){
	memcpy(iter,hd,sizeof(hd));
	memset(dis,-1,sizeof(dis));
	Q.push(S);dis[S]=0;
	while(!Q.empty()){
		int x=Q.front();Q.pop();
		for(int i=hd[x],y;i;i=e[i].nxt)
			if(e[i].w&&dis[y=e[i].v]==-1){
				dis[y]=dis[x]+1, Q.push(y);
			}
	}
	return ~dis[T];
}
int dfs(int x=S,int f=INF){
	if(x==T||!f)return f;
	int sf=0,y;
	for(int &i=iter[x];i;i=e[i].nxt)
		if(e[i].w&&dis[y=e[i].v]==dis[x]+1){
			int w=dfs(y,min(f,e[i].w));
			e[i].w-=w, e[i^1].w+=w;
			f-=w, sf+=w;
			if(!f)break;
		}
	return sf;
}

void prep(int p[],int c[],int &m){
	m = 0;
	rep(i,1,n) if(!c[i]){
		++m;
		for(int x=i;!c[x];x=p[x]) c[x] = m;
	}
}

int main() {
	scanf("%d",&n);
	rep(i,1,n)scanf("%d",p+i),++p[i];
	rep(i,1,n)scanf("%d",q+i),++q[i];
	prep(p,c,nc);
	prep(q,d,nd);
	S = 0, T = nc+nd+1;
	int ans = n;
	rep(i,1,n){
		bool f1 = (p[i]==i), f2 = (q[i]==i);
		if(f1&&f2) --ans;
		else if(f1) add(nc+d[i],T,1,0);
		else if(f2) add(S,c[i],1,0);
		else add(nc+d[i],c[i],1,p[i]==q[i]);
	}
	int flow = 0;
	while(bfs()) flow += dfs();
	printf("%d\n",ans-flow);
	return 0;
}

Measured memory_bytes: 7296
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b,c;
    cin >> a >> b >> c;
    if((a + b + c ) == 17)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

  string s;
  cin >> s;
  int n=s.length();
  for(int i=0; i<n; i++){
    if(i%2==0 && s[i]=='L'){
      cout << "No" << endl;
      return 0;
    }
    if(i%2!=0 && s[i]=='R'){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int s[100000];
    int t[100000];
    int i,j,k,l,n,key;
	int mid;
	int x = 0;
    scanf("%d",&n);
    for (i = 0; i < n; i++)
        scanf("%d",&s[i]);
    scanf("%d",&l);
    for (i = 0; i < l; i++)
        scanf("%d",&t[i]);
    
    for (i = 0; i < l; i++) {
		key = t[i];
		int right = n;
		int left = 0;
	    while (left < right) {
		    mid = (left + right) / 2;
		    if (s[mid] == key){
			    x++;
			    left = left+10000;
			}
		    else if (key < s[mid])
		        right = mid;
		    else
		        left = mid +1;
        }
    }
    printf("%d\n", x);
    
    return 0;
}


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

namespace ABC081
{
    class ProblemB
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            int res = 0;
            while (true)
            {
                bool hasOddNum = false;
                for (int i = 0; i < N; i++)
                    if (A[i] % 2 != 0)
                        hasOddNum = true;

                if (hasOddNum) break;

                for (int i = 0; i < N; i++)
                    A[i] /= 2;

                res++;
            }

            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 28512
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2253




#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>




#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;




using namespace std;




#define MAX 121
#define CONT 60




int T,N;




void dfs(int x, int y, int turn, vector< vector<int> > &field)
{
	int dx[6] = {0, 1, 1, 0, -1, -1};
	int dy[6] = {1, 1, 0, -1, -1, 0};




	if(x < 0 || x >= MAX || y < 0 || y >= MAX){ return; } //範囲外




	if(turn > T){ return; } //ターン数オーバー




	if(field[x][y] <= turn && field[x][y]){ return; } //到達修正
	if(field[x][y] == -1){ return; } //障害物




	field[x][y] = turn;
	
	rep(i,6){
		dfs(x+dx[i], y+dy[i], turn+1, field);
	}
}




int main()
{
	while(cin >> T >> N )
	{
		if(T == 0 && N == 0){ break; }




		vector< vector<int> > field(MAX,vector<int>(MAX,0));
	
		int X,Y;
		rep(nth,N)
		{
			cin >> X >> Y;
			field[X+CONT][Y+CONT] = -1;
		}




		int sx,sy;
		cin >> sx >> sy;
	
		int ans = 0;
		dfs(sx+CONT,sy+CONT,0,field);
		field[sx+CONT][sy+CONT] = 1;
		
		rep(y,MAX){
			rep(x,MAX){
				if(field[x][y] > 0){ ans++; }
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

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

int main(){
  string s;
  cin >> s;
  int n=s.size();
  vector<int> a(3,0);
  rep(i,n){
    if(s[i]=='a') a[0]++;
    if(s[i]=='b') a[1]++;
    if(s[i]=='c') a[2]++;
  }

  sort(a.rbegin(),a.rend());
  vector<int> b(3,n/3);
  if(n%3>=1) b[0]++;
  if(n%3>=2) b[1]++;

  if(a!=b){
    cout << "NO" << ln; return 0;
  }
  cout << "YES" << ln;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n,m,a,b;
	cin >>n>>m;
	bool mp[n]={};
	bool mp2[n]={};
	for(int i=0;i<m;++i){
		cin >>a>>b;
		if(a==1){mp[b-1]=1;}
		if(b==n){mp2[a-1]=1;}
	}
	for(int i=0;i<n;++i){
		if(mp[i]==1&&mp2[i]==1){
			cout<<"POSSIBLE"<<endl;goto end1;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
	end1:
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

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

        if (s2.length() < t.length()) {
            System.out.println("UNRESTORABLE");
            return;
        }

        for (int i = s2.length() - t.length(); i >= 0; i--) {
            if (canPlace(s2.substring(i, i + t.length()), t)) {
                for (int j = 0; j < s2.length(); j++) {
                    if (j >= i && j < i + t.length()) {
                        System.out.print(t.charAt(j - i));
                    } else if (s2.charAt(j) == '?') {
                        System.out.print('a');
                    } else {
                        System.out.print(s2.charAt(j));
                    }
                }
                return;
            }
        }

        System.out.println("UNRESTORABLE");
    }
    
    static boolean canPlace(String s, String t) {
        if (s.length() < t.length()) {
            return false;
        }

        for (int i = 0; i < t.length(); i++) {
            if (s.charAt(i) == '?') {
                continue;
            }

            if (s.charAt(i) != t.charAt(i)) {
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 35732
#include <math.h>
#include <bits/stdc++.h>
#include <deque>
#include <string>
#include <vector>
#include <algorithm>
#define ll long long int
#define l long double
#define pi 3.14159265358979323846
#define mod 1000000007
#define vali 1000000000000000000
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin >> n>>k;
    ll a[n],sum=0;
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<k;i++)
    sum+=a[i];
    cout<<sum<<endl;
}
    

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

int main(){

	int a, b, c;
	int i;
	cin >> a >> b >> c;
	if(a>b){
		i = a;
		a = b;
		b = i;
	}
	if(b>c){
		i = b;
		b = c;
		c = i;
	}
	if(a>b){
		i = a;
		a = b;
		b = i;
	}
	cout << a << " " << b << " " << c << endl;

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n;
  cin >> n;
  
  vector<long> vec(n);
  for(long i = 0; i < n; i++){
    cin >> vec[i];
  }
  
  long count = 0;
  for(long i = 1; i <= n; i++){
    if(vec[vec[i - 1] - 1] == i) count++;
  }
  cout << count/2 << endl;
}

Measured memory_bytes: 1024
import math

a,b,h,m=map(int,input().split())

pi=math.pi

r1=2.0*pi/12.0*h+pi/6.0/60.0*m

r2=2.0*pi/60.0*m

g=a*a+b*b-2.0*a*b*math.cos(r1-r2)

print(math.sqrt(g))


Measured memory_bytes: 9560
#![allow(dead_code)]
#![allow(unused_imports)]
use ascii::{AsciiChar, AsciiStr, AsciiString};
use indexmap::IndexMap;
use itertools::*;
use libm::*;
use num::*;
use ordered_float::OrderedFloat;
use permutohedron::LexicalPermutation;
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::mem::swap;

fn main() {
    input! {
        n: isize,
        a: [i64; n],
        q: isize,
        bc: [(i64, i64); q],
    };

    let mut ans: i64 = a.iter().sum();

    let mut map = BTreeMap::new();
    for x in a {
        *map.entry(x).or_insert(0) += 1;
    }

    for (b, c) in bc {
        let n = *map.entry(b).or_insert(0);
        *map.entry(c).or_insert(0) += n;
        if let Some(x) = map.get_mut(&b) {
            *x = 0;
        }
        ans += (c - b) * n;
        println!("{}", ans);
    }
}


Measured memory_bytes: 7948
#include<stdio.h>
int main(void)
{
	int w,h,c,a,b,x;
	scanf("%d %d %d",&w,&h,&c);
	a=w;	b=h;
	if(a<b){
		x=a;
		a=b;
		b=x;
	}
	x=a%b;
	while(x!=0){
		a=b;
		b=x;
		x=a%b;
	}
	w=w/b;
	h=h/b;
	x=w*h;
	c=c*x;
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 2728
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;

i64 extgcd(i64 a, i64 b, i64& x, i64& y) {
    i64 g = a;
    x = 1, y = 0;
    if (b) {
        g = extgcd(b, a % b, y, x);
        y -= a / b * x;
    }
    return g;
}

int main() {
    i64 a, b, x, y;
    cin >> a >> b;
    extgcd(a, b, x, y);
    cout << x << " " << y << endl;
}


Measured memory_bytes: 3100