akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

void solve()
{
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	
	
	if(k<=a)
	{
		cout << k << "\n";
	}
	else if(k<=a+b)
	{
		cout << a << "\n";
	}
	else 
	{
		cout << a-(k-a-b) << "\n";
	}
}

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


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vl a(n+1,0);
    rep(i,n)cin>>a[i+1];
    ll ans=LINF;
    partial_sum(all(a),a.begin());
    rep(i,n-1){
        chmin(ans,abs(a[n]-a[i+1]-a[i+1]));
    }
    puta(ans);
    return 0;
}

Measured memory_bytes: 1792
package main

import "fmt"

func main() {
	var a, b, k int64
	fmt.Scan(&a, &b, &k)

	if k-a >= 0 {
		k = k - a
		a = 0
		if k-b >= 0 {
			b = 0
		} else {
			b = b - k
		}
	} else {
		a = a - k
	}
	fmt.Printf("%v %v\n", a, b)
}


Measured memory_bytes: 512
#include<stdio.h>
int MAX=100;
int INFTY=1000000;
int WHITE=0;
int GRAY=1;
int BLACK=2;
int dijkstra(void);
int n,i,M[100][100];

int main(){
  int k,c,u,v;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(int j=0;j<n;j++){
      M[i][j]=INFTY;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(int j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      M[u][v]=c;
    }
  }
  
  dijkstra();
  
  return 0;
}

int dijkstra(){
  int u,mincost;
  int d[MAX],color[MAX];

  for(i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=WHITE;
  }

  d[0]=0;
  color[0]=GRAY;

  while(1){
    mincost=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(mincost>d[i]&&color[i]!=BLACK){
	u=i;
	mincost=d[i];
	}
    }
    
    if(u==-1) break;
    color[u]=BLACK;
    
    for(int v=0;v<n;v++){
      if(color[v]!=BLACK&&M[u][v]!=INFTY){
	if(d[v]>d[u]+M[u][v]){
	  d[v]=d[u]+M[u][v];
	  color[v]=GRAY;
	}
      }
    }
    
  }
  
  for(i=0;i<n;i++){
    if(d[i]!=INFTY&&d[i]!=-1)
      printf("%d %d\n",i,d[i]);
  }
  return 0;
}


Measured memory_bytes: 2108
N, X = [int(i) for i in input().split(' ')]

def f(n):
    return 4 * pow(2, n) - 3
def g(n):
    return pow(2, n+1) - 1

def ss2(k, n):
    if n == 0:
        return 1
    nn = f(n)
    cc = (nn//2) + 1
    if k == 1:
        return 0
    if k >= nn:
        return g(n) 
    elif k == cc:
        return g(n-1) + 1  
    elif k > cc:
        return g(n-1) + 1 + ss2(k-cc, n-1)
    elif k < cc:
        return ss2(k-1, n-1)

print(ss2(X, N))




Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define int long long int
using namespace std;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      //freopen("q.gir","r",stdin);
      int n;
      cin>>n;
      string s;
      cin>>s;
      string a=s.substr(0,n/2);
      string b=s.substr(n/2,n/2);
      if(a==b&&n%2==0){
            cout<<"Yes";
      }
      else cout<<"No";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>

using namespace std;

int main()
{
    int N;
    cin >> N;
    priority_queue<string> q;
    for (int i = 0; i < N; i++)
    {
        string s;
        cin >> s;
        q.push(s);
    }
    int ans = 0;
    while (!q.empty())
    {
        string top = q.top();
        ans++;

        while (!q.empty() && q.top() == top)
        {
            q.pop();
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 11660
import sys,fractions
input=sys.stdin.readline
N=int(input())
num = list(map(int,input().split()))
g = fractions.gcd
left=[0]*(N+1)
right=[0]*(N+1)
for i in range(N):
  j = N-i-1#初期値=4
  left[i+1] = g(left[i],num[i])
  right[j] = g(right[j+1],num[j])
ans=0
for k in range(N):
  ans = max(ans,g(left[k],right[k+1]))
print(ans)

Measured memory_bytes: 16100
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int t; cin >> t; cin.ignore(); while(t--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}

int main(){
    fast();
 
/* you get what you work for not what you wish for */
    
    inp(n);
    inpv(a, n);
    ll sum = 0;
    for(auto i:a){
        sum+=i;
    }
    ll ans = 1e18;
    ll right = sum;
    ll left = 0;
    for(auto i:a){
        left += i;
        right = sum-left;
        ans = min(ans, abs(left-right));
    }
    cout << ans << endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define N 900000
#define MOD 924844033
#define int long long
int M[3] = {998244353, 924844033, 1004535809};
int G[3] = {3, 5, 3};
int n;
vector <int> bi[N];
int sum[N], cnt[N], A[N], B[N];
int fac[N], inv[N];
void dfs(int t, int f)
{
    sum[t] = 1;
    for (int i = 0; i < bi[t].size(); ++ i)
        if (bi[t][i] != f)
        {
            dfs(bi[t][i], t);
            sum[t] += sum[bi[t][i]];
        }
    if (f)
    {
        cnt[sum[t]] --;
        cnt[n - sum[t]] --;
    }
}
int powi(int a, int b, int c)
{
    int d = 1;
    for (; b; b /= 2, a = 1ll * a * a % c)
        if (b & 1) d = 1ll * d * a % c;
    return d;
}
void NTT(int A[], int n, int M, int G, int fl)
{
    for (int i = 1; i < n; ++ i)
    {
        int d = 0;
        for (int j = 1, k = n >> 1; j < n; j <<= 1, k >>= 1) if (i & j) d |= k;
        if (i < d) swap(A[i], A[d]);
    }
    for (int i = 2; i <= n; i <<= 1)
    {
        int w0 = powi(G, (M - 1) / i, M);
        if (fl < 0) w0 = powi(w0, M - 2, M);
        for (int j = 0; j < n; j += i)
        {
            int w = 1;
            for (int k = j; k < j + (i >> 1); ++ k)
            {
                int u = A[k], v = 1ll * A[k + (i >> 1)] * w % M;
                A[k] = (u + v) % M, A[k + (i >> 1)] = (u - v + M) % M;
                w = 1ll * w * w0 % M;
            }
        }
    }
    if (fl < 0) for (int i = 0; i < n; ++ i) A[i] = (1ll * A[i] * powi(n, M - 2, M)) % M;
}

__int128 CRT(int a[], int m[], int n)
{
    __int128 M = 1;
    __int128 ans = 0;
    for (int i = 0; i < n; ++ i) M *= m[i];
    for (int i = 0; i < n; ++ i)
    {
        __int128 Mi = M / m[i];
        ans = (ans + Mi * powi(Mi % m[i], m[i] - 2, m[i]) * a[i]) % M;
    }
    if (ans < 0) ans += M;
    return ans;
}


void solve(int M, int G)
{
    int nn = 1; while (nn <= n) nn *= 2; nn *= 2;
    for (int i = 0; i < nn; ++ i) A[i] = B[i] = 0;
    for (int i = 0; i <= n; ++ i) A[n - i] = 1ll * fac[i] * cnt[i] % M;
    for (int i = 0; i <= n; ++ i) B[i] = inv[i];
    NTT(A, nn, M, G, 1);
    NTT(B, nn, M, G, 1);
    for (int i = 0; i < nn; ++ i) A[i] = 1ll * A[i] * B[i] % M;
    NTT(A, nn, M, G, -1);
}
int T[N][3];
signed main()
{
    scanf("%lld", &n);
    for (int i = 1; i < n; ++ i)
    {
        int a, b;
        scanf("%lld%lld", &a, &b);
        bi[a].push_back(b);
        bi[b].push_back(a);
    }
    cnt[n] = n;
    dfs(1, 0);
    fac[0] = 1;
    for (int i = 1; i <= n; ++ i) fac[i] = (1ll * fac[i - 1] * i) % MOD;
    inv[n] = powi(fac[n], MOD - 2, MOD);
    for (int i = n - 1; ~i; -- i) inv[i] = (1ll * inv[i + 1] * (i + 1)) % MOD;

        solve(M[1], G[1]);

    for (int i = n - 1; ~i; -- i)
        printf("%lld\n", (int)(1ll * A[i] * inv[n - i] % MOD));

}


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

const int di[] = { 0, 1,-1, 0};
const int dj[] = { 1, 0, 0,-1};
int main() {
	// input
	int h,w;
	cin >> h >> w;
	int si,sj;
	cin >> si >> sj;
	int ti,tj;
	cin >> ti >> tj;
	si--;sj--;ti--;tj--;
	vector<string> s(h);
	rep(i,h) cin >> s[i];
	// input done
	const int INF = 1e9;
	vector<vector<int>> dist(h, vector<int>(w, INF));
	queue<P> q,qB;
	dist[si][sj] = 0;
	q.emplace(si,sj);
	qB.emplace(si,sj);
	do {
		while(!q.empty()) {
			int i=q.front().first;
			int j=q.front().second;
			qB.emplace(i,j);
			int d = dist[i][j];
			q.pop();
			// printf("x: %d, y: %d\n",x,y);
			// move by A
			rep(v,4) {
				int ni = i+di[v], nj = j+dj[v];
				if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
				if (s[ni][nj]=='#') continue;
				if (dist[ni][nj] <= d) continue;
				dist[ni][nj] = d;
				// printf("nx: %d, ny: %d,cost: %d\n",nx,ny,d[ny][nx]);
				q.emplace(ni,nj);
				qB.emplace(ni,nj);
			}
		}
		while(!qB.empty()) {
			int i=qB.front().first;
			int j=qB.front().second;
			int d = dist[i][j];
			qB.pop();
			// move by B
			for(int ei=-2;ei<=2;ei++) {
				for (int ej=-2;ej<=2;ej++) {
					int ni = i+ei, nj = j+ej;
					if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
					if (s[ni][nj]=='#') continue;
					if (dist[ni][nj] <= d+1) continue;
					// printf("B nx: %d, ny: %d,cost: %d, s:%c\n",nx,ny,d[ny][nx],s[ny][nx]);
					dist[ni][nj] = d+1;
					q.emplace(ni,nj);
				}
			}
		}
	} while (!q.empty() || !qB.empty());
	int ans = dist[ti][tj];
	if (ans == INF) ans = -1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9536
#include <stdio.h>

int main(){
  int A,B,min;
  scanf("%d",&A);
  scanf("%d",&B);
  if(B==1)
    min = 0;
  else if(A>=B)
    min = 1;
  else{
    min = (B-1)/(A-1);
    if((B-1)%(A-1)!=0)
      min++;
  }
  printf("%d\n",min);
  return 0;
}
    


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<deque>
using namespace std;
long long int memo[45];
long long int fib(int n)
{
	if (n < 0)return 0;
	if (memo[n] != -1500)return memo[n];
	if (n == 0 || n == 1)return 1;
	long long int ans = 0;
	ans += fib(n - 1) + fib(n - 2);

	return memo[n]=ans;
	
}

int main()
{
	int n; cin >> n; for (int i = 0; i < 45; i++)memo[i] = -1500;
	cout << fib(n) << endl;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

int main()
{
    int H, W, N;
    scanf("%d %d %d", &W, &H, &N);
    bool mp[H+1][W+1]; // 1 - indexed
    REP(i, 1, H+1) REP(j, 1, W+1) mp[i][j] = true;

    /*
    REP(j, 1, H+1) { REP(k, 1, W+1) printf("%d ", mp[j][k] ? 1 : 0); printf("\n"); }
    printf("\n");
    */
    REP(i, 0, N) {
        int x, y, a;
        scanf("%d %d %d", &x, &y, &a);
        if(a == 1) REP(j, 1, H+1) REP(k, 1, x+1) mp[j][k] = false;
        else if(a == 2) REP(j, 1, H+1) REP(k, x+1, W+1) mp[j][k] = false;
        else if(a == 3) REP(j, 1, y+1) REP(k, 1, W+1) mp[j][k] = false;
        else            REP(j, y+1, H+1) REP(k, 1, W+1) mp[j][k] = false;
        /*
        REP(j, 1, H+1) { REP(k, 1, W+1) printf("%d ", mp[j][k] ? 1 : 0); printf("\n"); }
        printf("\n");
        */
    }

    int res = 0;
    REP(i, 1, H+1) REP(j, 1, W+1) if(mp[i][j]) res++;
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		String dogName = "";
		while(n>26){
	 		dogName += numberToAlphabet((n-1)%26);
			n=(n-1)/26;
		}
		dogName += numberToAlphabet(n-1);
		StringBuffer ans = new StringBuffer(dogName);
		System.out.println(ans.reverse().toString());
    }
  	
  	public static String numberToAlphabet(long num){
		switch ((int)num){
  	case 0:
    	return("a");
  case 1:
    return("b");
  case 2:
    return("c");
  case 3:
    return("d");
  case 4:
    return("e");
  case 5:
    return("f");
  case 6:
    return("g");
  case 7:
    return("h");
  case 8:
    return("i");
  case 9:
    return("j");
  case 10:
    return("k");
  case 11:
    return("l");
  case 12:
    return("m");
  case 13:
    return("n");
  case 14:
    return("o");
  case 15:
    return("p");
  case 16:
    return("q");
  case 17:
    return("r");
  case 18:
    return("s");
  case 19:
    return("t");
  case 20:
    return("u");
  case 21:
    return("v");
  case 22:
    return("w");
  case 23:
    return("x");
  case 24:
    return("y");
  case 25:
    return("z");
}
      return("");
    }
  
}

Measured memory_bytes: 39788
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main(){
    init();
    string s;cin>>s;
    ll N=s.size();
    for (int left = 0; left < N; left++)
    {
        for (int right = 0; right < N; right++)
        {
            string t;
            for(int i=0;i<N;i++){
                if(!(left<=i&&i<=right))t.push_back(s[i]);
            }
            if(t=="keyence"){
                cout<<"YES"<<endl;
                return 0;
            }
        }
        
    }
    cout<<"NO"<<endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long long int a = 0;
	long long int b = 0;
	while (1)
	{
		cin >> a;
		cin >> b;
		if (a == 0 && b == 0)
		{
			break;
		}
		long long int c = a*a*(a*a + 4 * b*b) * 10000000000;
		long long int d = sqrt(c);
		cout << a * a + d / 100000 << '.' << d % 100000 << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 2980
from collections import Counter
N = int(input())
V = list(map(int,input().split()))

even = list(Counter(V[0::2]).most_common())
even.append((100001,0))
odd = list(Counter(V[1::2]).most_common())
odd.append((100001,0))
if even[0][0] == odd[0][0]:
    o = []
    o.append(even[0][1]+odd[1][1])
    o.append(even[1][1]+odd[0][1])
    print(N-max(o))
else:
    print(N-even[0][1]-odd[0][1])


Measured memory_bytes: 20700
from collections import defaultdict, deque

(n, m) = map(int, raw_input().split())

d = defaultdict(list)

for i in xrange(m):
    (a, b) = map(int, raw_input().split())
    d[a].append(b)
    d[b].append(a)

pre = [0 for i in xrange(n + 1)]
cnt = 0

q = deque([1])
while q:
    cur = q.popleft()
    for nxt in d[cur]:
        if pre[nxt] == 0:
            cnt += 1
            pre[nxt] = cur
            q.append(nxt)


if cnt < n - 1:
    print 'No'
else:
    print 'Yes'
    for i in xrange(2, n + 1):
        print pre[i]


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

int main(void){
    int n;
    cin >> n;
    if(n >= 2000)cout << 1 << endl;
    else {
        int b = 0;
        for(int i = 0;i < 20;i++){
            for(int j = 0;j < 20;j++){
                for(int k = 0;k < 20;k++){
                    for(int l = 0;l < 20;l++){
                        for(int p = 0;p < 20;p++){
                            for(int q = 0;q < 20;q++){
                                int total = i*100+j*101+k*102+l*103+p*104+q*105;
                                if(total == n)b = 1;
                            }
                        }
                    }
                }
            }
        }
        cout << b << endl;
    }
}

Measured memory_bytes: 384
s=list(input())
l=len(s)
for i  in range(0,l):
  if i%2==0:
    if s[i]=="L":
      print("No")
      exit()
  elif i%2==1:
    if s[i]=="R":
      print("No")
      exit()
  else:
    pass
print("Yes")

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	int n;
	cin >> n;
	cout << 180 * (n - 2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include <cmath>
#include<queue>
#include<cstdio>
//#include <bits/stdc++.h>
using namespace std;

int main(){
    long int N,M,ans;
    cin>>N>>M;
    ans=N;
    long int A[M];
    for (long int i=0;i<M;i++){
        cin>>A[i];
        ans-=A[i];
    }
    if (ans<0) cout<<-1<<endl;
    else cout<<ans<<endl;
    
    return 0;
}

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n,k;
    cin >> n >> k;
    if (k>(n-1)*(n-2)/2)
    {
        cout << -1 << endl;
        return 0;
    }
    
    vector<P> vc;
    for (int i = 2; i < n+1; i++)
    {
        vc.push_back(P{1,i});
    }
    int add = (n-1)*(n-2)/2-k;
    for (int i = 2; i < n+1; i++)
    {
        for (int j = i+1; j < n+1; j++)
        {
            if (add==0)
            {
                break;
            }
            vc.push_back(P{i, j});
            add--;
        }
        if (add == 0)
        {
            break;
        }
    }
    

    cout << sz(vc) << endl;
    rep(i,sz(vc))
    {
        cout << vc[i].first << " " << vc[i].second << endl;
    }
}

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

class UnionFindTree
{
    vector<int> parent;
    vector<int> depth;
    vector<int> cnt;

public:
    UnionFindTree(int n) : parent(n), depth(n), cnt(n)
    {
        for (int i = 0; i < n; i++)
        {
            parent[i] = i;
            depth[i] = 0;
            cnt[i] = 1;
        }
    }

    //木の根を求める
    int find(int x)
    {
        if (parent[x] == x)
        {
            return x;
        }
        else
        {
            return parent[x] = find(parent[x]);
        }
    }

    //xとyの属する集合を併合
    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (depth[x] < depth[y])
        {
            parent[x] = y;
            cnt[y] += cnt[x];
        }
        else
        {
            parent[y] = x;
            cnt[x] += cnt[y];
            if (depth[x] == depth[y])
                depth[x]++;
        }
    }

    bool same(int x, int y)
    {
        return find(x) == find(y);
    }

    int size(int x)
    {
        return cnt[find(x)];
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    UnionFindTree utree(n + 10);
    for (int i = 0; i < m; i++)
    {
        int x, y, z;
        cin >> x >> y >> z;
        utree.unite(x, y);
    }
    map<int, int> fl;
    int ans = n;
    for (int i = 1; i <= n; i++)
    {
        if (!fl[utree.find(i)])
        {
            fl[utree.find(i)] = 1;
            ans -= utree.size(i)-1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6144
/*   Abhijith  */
#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define	endl '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vector<lld> v(405,0),s(405,0);
vector<vector<lld> > dp(405,vector<lld>(405,1e18));
int main()
{
     ios;
     lld n;
     cin>>n;
     rep(i,1,n)
     {
         cin>>v[i];
         dp[i][i]=v[i];
         s[i]=s[i-1]+v[i];
     }
     rep(l,2,n)
     {
         rep(i,1,n-l+1)
         {
             lld j=i+l-1;
             lld temp=0;
             rep(k,i,j-1)
             {
                 temp=(dp[i][k]+dp[k+1][j]-s[i-1]+s[j]);
                 if(k==i)
                    temp-=v[i];
                 if(k==j-1)
                    temp-=v[j];
                 dp[i][j]=min(dp[i][j],temp);
             }
             //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
         }
     }
     cout<<dp[1][n]<<endl;
    return 0;
}


Measured memory_bytes: 1536
#include<iostream>

using namespace std;

int main(void)

{
    int x;
    cin>>x;
    if(x >= 400 && x <= 599)cout<<"8\n";
    else if(x >= 600 && x <= 799)cout<<"7\n";
    else if(x >= 800 && x <= 999)cout<<"6\n";
    else if(x >= 1000 && x <= 1199)cout<<"5\n";
    else if(x >= 1200 && x <= 1399)cout<<"4\n";
    else if(x >= 1400 && x <= 1599)cout<<"3\n";
    else if(x >= 1600 && x <= 1799)cout<<"2\n";
    else cout<<"1\n";
    return 0;
}


Measured memory_bytes: 3132
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1000005;
int a[N];
int main()
{
	//freopen("input.txt","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	long long cnt=0;
	cin >>n;
	for(int i=1;i<=n;i++)cin >>a[i];
	int j=1,s=0;
	for(int i=1;i<=n;i++)
	{
		for(;(j<=n)&&((s&a[j])==0);j++)
			s^=a[j];
		cnt+=(long long)j-i;
		s^=a[i];
		//cout <<j<<endl;
	}
	cout <<cnt;
	return 0;
}

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

int main()
{
ll n ;
cin >> n ;
ans=(double)((n+1)/2)/n;

cout<<fixed<<setprecision(12)<<ans<<endl;

return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstdio>

using namespace std;

typedef long double ld;

const int TYRE = 10001;
const int NODE = 101;
const int INF = (1<<25);

struct State{
  int x, pos;
  ld t;
  bool operator < (const State& s) const {
    return t > s.t;
  }
};

vector<int> V;

ld T[TYRE][NODE];
int n;
ld b,r,v,e,f;


void solve(){
  fill(T[0],T[0]+TYRE*NODE,(ld)INF);

  priority_queue<State> Q;
  Q.push((State){0,0,0});

  while(!Q.empty()){

    State now = Q.top(); Q.pop();
    if(now.pos == n) continue;

    if(T[now.x][now.pos] < now.t) continue;

    //change tyre
    
    State nex = now;
    nex.x = 0;
    nex.t += b;
    int diff = V[now.pos+1]-V[now.pos];
    
    for(int i = 0; i < diff; i++){
      if(nex.x >= r) nex.t += 1.0/(v-e*(nex.x-r));
      else nex.t += 1.0/(v-f*(r-nex.x));
      nex.x++;
    }
    nex.pos++;
    
    if(T[nex.x][nex.pos] > nex.t) {
      T[nex.x][nex.pos] = nex.t;
      Q.push(nex);
    }

    //not change tyre
    nex = now;

    for(int i = 0; i < diff; i++){
      if(nex.x >= r) nex.t += 1.0/(v-e*(nex.x-r));
      else nex.t += 1.0/(v-f*(r-nex.x));
      nex.x++;
    }

    nex.pos++;
    
    if(T[nex.x][nex.pos] > nex.t) {
      T[nex.x][nex.pos] = nex.t;
      Q.push(nex);
    }
  }
  ld ans = (ld)INF;
  
  for(int i = 0; i < TYRE; i++) ans = min(ans,T[i][n]);

  printf("%.4Lf\n",ans);
}


void input(){
  V.resize(n+1); V[0] = 0;
  for(int i = 1; i <= n; i++) cin >> V[i];
  cin >> b >> r >> v >> e >> f;
}

int main(){
  
  while(cin >> n && n){
    input();
    solve();
  }
  return 0;
}

Measured memory_bytes: 17056
n = int(input())
tbl=[[0 for j in range(10)] for i in range(10)]
for i in range(1,n+1):
    s= str(i)
    h=int(s[0])
    b=int(s[-1])
    tbl[h][b]+=1
ans = 0
for i in range(10):
    for j in range(10):
        ans+=tbl[i][j]*tbl[j][i]
print(ans)

Measured memory_bytes: 3064
#include "stdio.h"
int main(int argc, char const *argv[]) {
  int N;
  long long int H,W;
  scanf("%d%lld%lld",&N,&H,&W);
  long long int A[N],B[N];
  for (size_t i = 0; i < N; i++) {
    scanf("%lld%lld",&A[i],&B[i]);
  }
  int ans=0;
  for (size_t i = 0; i < N; i++) {
    if (H<=A[i]&&W<=B[i]) {
      ans++;
    }
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;int a[105];int d[105][100005];
#define M 1000000007
#define r(i,a,b) for(int i=a;i<=b;i++)
int main(){ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n,k;cin>>n>>k;r(i,0,n-1){cin>>a[i];}r(i,0,a[0])d[0][i]=i+1;r(i,a[0]+1,k)d[0][i]=d[0][a[0]];r(i,1,n-1){d[i][0]=1;r(j,1,k){d[i][j]=d[i][j-1];d[i][j]+=(d[i-1][j]-(j-a[i]-1>=0?d[i-1][j-a[i]-1]:0))%M;d[i][j]%=M;}}cout<<(d[n-1][k]-d[n-1][k-1]+M)%M<<"\n";return 0;}

Measured memory_bytes: 41216
from heapq import heappush,heappop
n,m = map(int,input().split())
l = [list(map(int,input().split())) for _ in [0]*n]
l.sort(key=lambda x:x[0])
ans = 0
tmpl = []
i = 0
for d in range(1,m+1):
  while i<=n-1 and l[i][0] <= d:
    #tmpl.append(l[i][1])
    heappush(tmpl,-l[i][1])
    i += 1
  if len(tmpl) > 0:
    #maxindex = tmpl.index(max(tmpl))
    #ans += tmpl[maxindex]
    #del tmpl[maxindex]
    ans -= heappop(tmpl)
print(ans)


Measured memory_bytes: 32664
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

const MOD: usize = 1_000_000_007;


#[fastout]
fn solve() {
    input!{
        n: usize, k: usize,
        d_vec: [usize; k]
    }

    let d_set = d_vec.into_iter().collect::<HashSet<usize>>();

    for ans in n..=100000 {
        let ans_set = ans.to_string().chars().map(|x| x as usize - 48).collect::<HashSet<usize>>();
        if ans_set.intersection(&d_set).into_iter().count() == 0 {
            println!("{}", ans);
            break;
        }
    }

}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 2188
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>

typedef int Type;
struct List
{
	Type data;
	struct List *prev;
	struct List *next;
};
typedef struct List List;

List* list_create_element(void)
{
	List *list = malloc(sizeof(List));
	return list;
}

void list_delete_element(List* list)
{
	free(list);
}

List* list_init(void)
{
	List *list = list_create_element();
	list->prev = list;
	list->next = list;
	return list;
}

void list_insert(List *prev, Type data)
{
	List *next = prev->next;
	List *curr = list_create_element();
	curr->data = data;
	curr->prev = prev;
	curr->next = next;
	prev->next = curr;
	next->prev = curr;
}

void list_remove(List *curr)
{
	List *prev = curr->prev;
	List *next = curr->next;
	list_delete_element(curr);
	prev->next = next;
	next->prev = prev;
}

List* list_search(List *list, Type data)
{
	for(List *curr = list->next; curr != list; curr = curr->next)
	{
		if(data == curr->data)
		{
			return curr;
		}
	}
	return NULL;
}

void list_free(List *list)
{
	while(list != list->next)
	{
		list_remove(list->next);
	}
	list_delete_element(list);
}

void list_dump(List *list)
{
	int flag = 0;
	for(List *curr = list->next; curr != list; curr = curr->next)
	{
		if(flag) { printf(" "); }
		flag = 1;
		printf("%d", curr->data);
	}
	printf("\n");
}

int main()
{
	int n, x;
	char command[16];
	List *list;
	List *temp;

	list = list_init();
	scanf("%d", &n);
	for(int i = 0; i < n; ++i)
	{
		scanf("%s", command);

		if(strcmp(command, "insert") == 0)
		{
			scanf("%d", &x);
			list_insert(list, x);
		}
		if(strcmp(command, "delete") == 0)
		{
			scanf("%d", &x);
			temp = list_search(list, x);
			if(temp)
			{
				list_remove(temp);
			}
		}
		if(strcmp(command, "deleteFirst") == 0)
		{
			list_remove(list->next);
		}
		if(strcmp(command, "deleteLast") == 0)
		{
			list_remove(list->prev);
		}
	}	
	list_dump(list);
	list_free(list);

	return 0;
}



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

int main()
{
  int n,m,c,x=0,s=0;
  int a[20][20],b[20];
  cin >> n >> m >> c;
  for(int i=0;i<m;i++){
    cin >>b[i];
  }
  for(int i=0;i<n;i++){
	for(int j=0;j<m;j++)
      cin >> a[i][j];
  }
  for(int i=0;i<n;i++){
    x = 0;
	for(int j=0;j<m;j++){
		x +=a[i][j]*b[j];
    }
    if(x+c>0)
      s++;
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main(){
  int a, b; cin >> a >> b;
  if(a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0){
    cout << "Possible" << endl;
  }
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
int main(void){
  int64_t N,K;
  cin >> N >> K;
  
  int64_t NK = N - (K * (N / K));
  int64_t KN = K - N;
  int64_t diff = min(abs(NK),abs(KN));
  
  while(diff > abs(diff-K) || diff > abs(K-diff)){
    diff = min(abs(diff-K),abs(K-diff));
  }
  
  cout << diff << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define vll vector<long long> 
#define pll pair<ll,ll>
#define f(i,a,b) for(long long i=a;i<b;i++)
#define F first
#define S second
#define pb(i) push_back(i)
#define mp(x,y) make_pair(x,y)
#define all(v)  (v).begin(),(v).end()
#define sz 1001
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main(){
	FIO;
	ll n,w;cin>>n>>w;
	vll wt(n),val(n);
	f(i,0,n) cin>>wt[i]>>val[i];
	ll dp[n+1][w+1];
	f(i,0,n+1){
		f(j,0,w+1){
			if(i==0 or j==0) dp[i][j]=0;
			else if(wt[i-1]<=j){
				ll a = val[i-1]+dp[i-1][j-wt[i-1]]; //taking it
				ll b = dp[i-1][j];//not taking it
				dp[i][j] = max(a,b);
			}
			else dp[i][j] = dp[i-1][j];
		}
	}
	cout<<dp[n][w]<<"\n";
}

Measured memory_bytes: 82388
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
typedef priority_queue<p> pq;
typedef priority_queue<p, vector<p>, greater<p>> gpq;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s;
    ll k;
    cin >> s >> k;

    ll ans = 0;
    if (s.size() == 1)
    {
        cout << k / 2 << endl;
        return 0;
    }

    bool l_is_r_flag = false, all_same_flag = true;
    if(s[0] == s[s.size() - 1])
        l_is_r_flag = true;

    ll same_cnt = 1, ans1 = 0;
    char prev_c = s[0];
    FOR(i, 1, s.size())
    {
        if(s[i] == prev_c)
        {
            same_cnt++;
            //cout << "  yes " << i << " " << s[i] << "  " << same_cnt << endl;
        }else
        {
            //cout << "  no " << i << " " << s[i] << "  " <<  same_cnt << endl;
            ans1 += same_cnt / 2;
            same_cnt = 1;
            all_same_flag = false;
        }
        prev_c = s[i];
    }
    ans1 += same_cnt / 2;
    //cout << "                 " << ans1 << endl;

    if(k == 1)
    {
        cout << ans1 << endl;
        return 0;
    }

    // 両端が異なる文字
    if(l_is_r_flag == false)
    {
        cout << ans1 * k << endl;
        return 0;
    }

    // すべて同じ文字
    if(all_same_flag == true)
    {
        cout << s.size() * k / 2 << endl;
        return 0;
    }

    string ss = s + s;
    same_cnt = 1;
    ll ans2 = 0;
    prev_c = s[0];
    FOR(i, 1, ss.size())
    {
        if (ss[i] == prev_c)
        {
            same_cnt++;
        }
        else
        {
            ans2 += same_cnt / 2;
            same_cnt = 1;
            all_same_flag = false;
        }
        prev_c = ss[i];
    }
    ans2 += same_cnt / 2;

    //cout << "  last " << ans1 << " " << ans2 << endl;
    cout << ans1 + (ans2 - ans1) * (k - 1) << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> num(110);
  for(int i=0;i<N;i++) {
    cin >> num.at(i);
  }
  sort(num.begin(),num.end());
  reverse(num.begin(),num.end());

  int sum=0,max=1000;
  for(int j=0;j<N;j++) {
    if(num.at(j)<max) {
      sum++;
      max=num.at(j);
      //cout << max << endl;
    }
    else continue;
  }
  cout << sum << endl;
}
    


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

using namespace std;

int N, M;

int main() {
	int curPos, cnt;
	string allType, target, str;

	allType = "I";
	for (int i = 1; i <= 1000000; ++i) {
		allType += "OI";
	}

	while (cin >> N, N) {
		cin >> M >> str;
		target = allType.substr(0, 1 + 2 * N);
		cnt = 0;
		curPos = str.find(target);
		while (curPos != string::npos) {
			++cnt;
			curPos = str.find(target, curPos + 1);
		}
		cout << cnt << endl;
	}
	
	return 0;
}


Measured memory_bytes: 6816
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
    public static Node[] nodes;
    public static void main (String[] args) throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int n = Integer.parseInt(br.readLine());
	nodes = new Node[n];
	for (int i = 0; i < n; i++) {
	    nodes[i] = new Node(i);
	}
	
	String[] input;
	int id, k, childId;
	int[] a;
	for (int i = 0; i < n; i++) {
	    input = br.readLine().split(" ");
	    id = Integer.parseInt(input[0]);
	    k = Integer.parseInt(input[1]);
	    nodes[id].k = k;
	    if (k == 0) {
		nodes[id].type = 1;
	    } else {
		a = new int[k];
		for (int j = 0; j < k; j++) {
		    childId = Integer.parseInt(input[2+j]);
		    a[j] = childId;
		    nodes[childId].parent = id;
		}
		nodes[id].c = a;
	    }
	}

	for (int i = 0; i < n; i++) {
	    nodes[i].depth = setDepth(i);
	}
	
	StringBuilder sb = new StringBuilder();

	for (int i = 0; i < n; i++) {
	    sb.append("node " + i);
	    sb.append(": parent = " + nodes[i].parent);
	    sb.append(", depth = " + nodes[i].depth);
	    sb.append(", ");
	    if (nodes[i].type == -1) {
		sb.append("root, ");
	    } else if (nodes[i].type == 0) {
		sb.append("internal node, ");
	    } else if (nodes[i].type == 1) {
		sb.append("leaf, ");
	    }
	    sb.append("[");
	    if (nodes[i].k != 0) {
		sb.append(nodes[i].c[0]);
	    }
	    for (int j = 1; j < nodes[i].k; j++) {
		sb.append(", " + nodes[i].c[j]);
	    }
	    sb.append("]\n");
	}
	System.out.print(sb);

    }
    public static int setDepth (int id) {
	if (nodes[id].depth >= 0) return nodes[id].depth;
	if (nodes[id].parent == -1) {
	    nodes[id].type = -1;
	    return nodes[id].depth = 0;
	}
	return nodes[id].depth = setDepth(nodes[id].parent)+1;
    }
    
}

class Node {
    int id;
    int parent;
    int depth;
    int type; //-1: root, 0: internal node, 1: leaf
    int k;
    int[] c;
    Node (int id) {
	this.id = id;
	this.parent = -1;
	this.depth = -1;
	this.type = 0;
    }
}



Measured memory_bytes: 102060
n, l = map(int, raw_input().split())
A = map(int, raw_input().split())

for i in xrange(n-1):
    if A[i]+A[i+1] >= l:
        print "Possible"
        print "\n".join(map(str, range(1, i+1) + range(n-1, i+1, -1) + [i+1]))
        break
else:
    print "Impossible"


Measured memory_bytes: 15608
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iA = 0;
            iA += int.Parse(sS[0]);
            iA += int.Parse(sS[1]);
            iA += int.Parse(sS[2]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "win";
            if (iA  > 21) { sOut = "bust"; }

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define N 10009
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
int a[10000];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    while(m--)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        a[x]++;
        a[y]++;
    }
    for(int i=1;i<=n;i++)
        printf("%d\n",a[i]);
    return 0;
}










Measured memory_bytes: 256
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

def nuri(table, m, x, y):
    if table[x-1][y] and m[x-1][y] == 0:
        m[x-1][y] = m[x][y]
        nuri(table, m, x-1, y)
    if table[x+1][y] and m[x+1][y] == 0:
        m[x+1][y] = m[x][y]
        nuri(table, m, x+1, y)
    if table[x][y-1] and m[x][y-1] == 0:
        m[x][y-1] = m[x][y]
        nuri(table, m, x, y-1)
    if table[x][y+1] and m[x][y+1] == 0:
        m[x][y+1] = m[x][y]
        nuri(table, m, x, y+1)
    return

N = list(get_input())
for l in range(0,len(N),13):
    table = [[False for i in range(14)] for j in range(14)]
    for i in range(12):
        for j in range(12):
            if int(N[l+i][j]) == 1:
                table[i+1][j+1] = True

    m = [[0 for i in range(14)] for j in range(14)]

    cnt = 0
    for i in range(1,13):
        for j in range(1,13):
            if table[i][j] and m[i][j] == 0:
                cnt += 1
                m[i][j] = cnt
                nuri(table, m, i, j)

    print(cnt)



Measured memory_bytes: 5624
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var M = A[0];
        var sum = 0L;
        for (int i = 1; i < N; i++)
        {
            if (A[i] < M)
            {
                sum += M - A[i];
            }
            else
            {
                M = A[i];
            }
        }
        Console.WriteLine(sum);
    }
}


Measured memory_bytes: 47560
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();
		sc.close();
		int k = X / (Z + Y);
		if(X - k * (Z + Y) >= Z) {
			System.out.println(k);
		}else {
			System.out.println(k - 1);
		}
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    string s;ll k;
    cin >> k >>s;
    ll x=s.size();
    if(x<=k)cout << s <<endl;
    else {
        rep(i,k)cout << s[i];
        cout <<"..." <<endl;
    }
}

Measured memory_bytes: 3628
import math
#from functools import reduce

#def gcd(*numbers):
#    return reduce(math.gcd, numbers)

def main():
    K = int(input())
    ans = 0
    #全てが同じ数字
    for i in range(1,K+1,1):
        for j in range(1,K+1,1):
            for k in range(1,K+1,1):
                ans += math.gcd(i,math.gcd(j,k))

    return ans

print(main())


Measured memory_bytes: 9172
#include <bits/stdc++.h>
typedef long long  ll;
#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define form for(int j=0;j<n;j++) 
#define fora(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define kek cout<<endl; 
#define all(v) ((v).begin()), ((v).end()) 
#define pob pop_back() 
#define halt {cout<<"No"; return 0;}
const ll MOD = 1e9 + 7;
const int N = 200005;
const int INF = 1e8;
const ll MOD1=998244353;
using namespace std;

int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
 press_F_to_pay_respect;
 // cout << fixed << setprecision(12) << ans;
string s;
cin>>s;
string k=s.substr(0,3);
string l=s.substr(1,3);
sort(all(k));
sort(all(l));
if((k[0]==k[2]) || (l[0]==l[2])) cout<<"Yes";
else cout<<"No";
return 0;
 

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char str[100];
inline int max(const int &a,const int &b){return a>b?a:b;}
inline int min(const int &a,const int &b){return a<b?a:b;}
inline void read(int &n)
{
	n=0;char c=getchar();bool b=0;
	while(c<'0'||c>'9'){if(c=='-')b=1;c=getchar();}
	while(c>='0'&&c<='9') n=(n<<3)+(n<<1)+c-48,c=getchar();
	if(b) n=-n;
}
struct node
{
	int num,plus;
}t[400005];
int n,l,r,ans;
inline void pushdown(int l,int r,int now)
{
	if(!t[now].plus)return;
	int mid=(l+r)>>1;
	t[now<<1].num=mid-l+1;
	t[now<<1|1].num=r-mid;
	t[now<<1].plus=t[now<<1|1].plus=1;
	t[now].plus=0;
}
void add(int L,int R,int l,int r,int now)
{
	if(L<=l&&r<=R){t[now].num=r-l+1;t[now].plus=1;return;}
	int mid=(l+r)>>1;
	pushdown(l,r,now);
	if(L<=mid) add(L,R,l,mid,now<<1);
	if(R>mid) add(L,R,mid+1,r,now<<1|1);
	t[now].num=t[now<<1].num+t[now<<1|1].num;
}
int main()
{
	read(n);
	for(int i=1;i<=n;i++)
	  read(l),read(r),add(l,r,1,100000,1);
	printf("%d",t[1].num);
}

Measured memory_bytes: 2304
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    A.sort()

    ok = True
    if len(A) % 2 == 0:
        for i in range(N // 2):
            if not A[2 * i] == A[2 * i + 1] == 2 * i + 1:
                ok = False
                break
    else:
        if A[0] != 0:
            ok = False
        else:
            for i in range(N // 2):
                if not A[2 * i + 1] == A[2 * i + 2] == 2 * i + 2:
                    ok = False
                    break

    if ok:
        ans = pow(2, N // 2, MOD)
    else:
        ans = 0

    print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 20636
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
int a[3][105];
int n;
ll X ,s;
int main(){
	scanf("%d",&n);
	for(int i = 1;i <= 2;i++){
		for(int j = 1;j <= n;j++){
					scanf("%d",&a[i][j]);
			}
		}
		X = 0;
		for(int i = 1;i <= n;i++)
		{
		s = 0;
			for(int j = 1;j <= i;j++)
			{
				s = s + a[1][j];
			}
			for(int k = i;k <= n;k++)
			{
				s = s + a[2][k];
			}
			if(s > X)
			{
				X = s;
			}
		}
		printf("%lld\n",X);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <deque>
#include <queue>
#include <cstring>
#include <set>
#include <list>
#include <map>
#include <random>
#include <unordered_map>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<bool> vb;
typedef std::vector<string> vs;
typedef std::vector<double> vd;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<int> > vvi;
typedef vector<vvi> vvvi;
typedef vector<vll> vvll;
typedef std::vector<std::pair<int, int> > vpi;
typedef vector<vpi> vvpi;
typedef std::pair<int, int> pi;
typedef std::pair<ll, ll> pll;
typedef std::vector<pll> vpll;

const long long mod = 1000000007;

#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define forn(i, a, b) for(int i = a; i < b; i++)

#define pb push_back
#define mp make_pair

ll d[51][51][2501];

int main()
{

    int n, m;
    cin>>n>>m;
    vi a(n);
    forn(i,0,n) cin>>a[i];
    d[0][0][0] = 1;
    forn(i,0,n) {
        forn(k,0,i+1) {
            forn(sum,0,2500) {
                d[i+1][k+1][sum+a[i]] += d[i][k][sum];
                d[i+1][k][sum] += d[i][k][sum];
            
            }
        }
    }
    ll ans = 0;
    forn(i,1,n+1) ans += d[n][i][i*m];
    cout<<ans;
    
    
    
    
}



Measured memory_bytes: 26368
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n+1];
		for(int i=1;i<=n;i++) {
			a[i] = in.nextInt();
		}
		boolean[] ans = new boolean[n+1];
		for(int i=n;i>=1;i--) {
			int count = 0;
			int tmp = i*2;
			while(tmp<=n) {
				if(ans[tmp]) count++;
				tmp += i;
			}
			if(count%2!=a[i]) ans[i] = true;
		}
		StringBuilder res = new StringBuilder();
		int count = 0;
		for(int i=1;i<=n;i++) {
			if(ans[i]) {
				res.append(i);
				res.append(" ");
				count++;
			}
		}
		System.out.println(count);
		System.out.println(res.toString());
		
		in.close();

	}

}


Measured memory_bytes: 82508