akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main()
{
    string s;
    int K, S;
    cin >> K >> S;
    //cout << K <<" ks " << S <<endl;


    long count = 0;
    for (int x = 0; x <= K; x++) {
        for (int y = 0; y <= K; y++) {
            int z = S -( x+y );
            if (z >=0 && z <= K){
                count++;
            }
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>

using namespace std;

int main(void) {
    int a, b;
    cin >> a;
    cin >> b;
    int resA = a / 0.08;
    int resB = b / 0.1;
    int res = -1;
    for (int i = min(resA, resB)-1; i <= max(resA, resB)+1; i++) {
        if ( ((int)(i * 0.08) == a) && ((int)(i * 0.1) == b) ) {
            res = i;
            break;
        }
    }
    cout << res;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long ans = sc.nextLong();
		for (int i = 1; i < n; i++) {
		    ans = lcm(ans, sc.nextLong());
		}
        System.out.println(ans);
	}
	
	static long lcm(long a, long b) {
	    long x = gcd(a, b);
	    return a / x * b;
	}
	
	static long gcd(long a, long b) {
	    if (a % b == 0) {
	        return b;
	    } else {
	        return gcd(b, a % b);
	    }
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main(){
  double n;
  cin>>n;
  vector<double> x(n),y(n);
  rep(i,n) cin>>x[i]>>y[i];
  vector<int> t(n);
  rep(i,n) t[i]=i;
  double sum=0;
  int cnt=0;
  do{
    for(int i=1;i<n;i++){
      sum+=sqrt((x[t[i]]-x[t[i-1]])*(x[t[i]]-x[t[i-1]])+(y[t[i]]-y[t[i-1]])*(y[t[i]]-y[t[i-1]]));
    }
    cnt++;
  }while(next_permutation(all(t)));
  printf("%.10f\n",sum/cnt);
}

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

typedef long long ll;
ll n;
ll Now;

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        Now += i;
        if(Now >= n){
            cout<< i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int euclid(int, int);
void swap(int *, int *);

int main(void){
  int K;
  cin >> K;
  long result = 0;
  for (int a = 1; a <= K; a++){
    for (int b = 1; b <= K; b++){
      for (int c = 1; c <= K; c++){
        int ab  = euclid(a,b);
        int abc = euclid(ab,c);
        result = result + abc;
      }
    }
  }
  cout << result << endl;
  return 0;
}
int euclid(int small, int big){
  int amari = 0;
  if (small > big){
    swap(&small, &big);
  }
  while (true){
    if((amari = big % small) == 0)
      return small;
    big = small;
    small = amari;
  }
  return 0;
}

void swap(int *x, int *y){
  int temp;
  temp = *x;
  *x = *y;
  *y = temp;
}

Measured memory_bytes: 3580
#include<stdio.h>
#define N 1000000

typedef long int ll;

ll cnt = 0;

void InsertionSort(int A[], const int n, const int g);
void ShellSort(int [], int);

int main()
{
  int i;
  int n;
  int A[N+1];
  
  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
  }

  ShellSort(A,n);

  printf("%ld\n",cnt);
  
  for(i = 0;i < n;i++){
    printf("%d\n",A[i]);
  }
}

void InsertionSort(int A[], const int n, const int g) // from 1 to g
{
  int i=0,j=0;
  int key;

  for(i = g;i < n;i++){
    key = A[i];
    j = i-g;
    
    while(j >= 0 && A[j] > key){
      A[j+g] = A[j];
      j -= g;
      cnt++;
    }
    A[j+g] = key;
  }
}

void ShellSort(int A[], int n)
{
  int i=0;
  int h = 0;
  int G[101];
  
  cnt = 0;
  
  while(h <= n){
    h = 3*h+1;
    G[i] = h;
    i++;
  }
  int m = i-1;

  printf("%d\n",m);
  for(i = 0;i < m;i++){
    if(i) printf(" ");
    printf("%d",G[m-1-i]);
  }
  printf("\n");
  
  for(i = 0;i < m;i++){
    InsertionSort(A,n,G[m-1-i]);
  }
}



Measured memory_bytes: 5688
def GCD(a: int, b: int) -> int:
    return a if b == 0 else GCD(b, a % b)


def LCM(a: int, b: int) -> int:
    return a * b // GCD(a, b)


MOD = 10**9 + 7
n = int(input())
a = tuple(map(int, input().split()))

MAX_a = max(a)
iinv = [1] * (MAX_a + 1)
for i in range(2, MAX_a + 1):
    iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD

lcm = 1
for i in range(n):
    lcm = LCM(lcm, a[i])

lcm %= MOD

ans = 0
for i in range(n):
    ans += lcm * iinv[a[i]]
    ans %= MOD

print(ans)


Measured memory_bytes: 78684
a,b=map(int,input().split())
def gcd(a, b):
  return a if b == 0 else gcd(b, a%b)

def factorize(n):
  a = []
  while n % 2 == 0:
    a.append(2)
    n /= 2
  f = 3
  while f * f <= n:
    if n % f == 0:
      a.append(f)
      n /= f
    else:
      f += 2
  if n != 1: a.append(n)
  return a

print(len(set(factorize(gcd(a,b))))+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int n;
  cin >> n;
  vi a(n);
  REP(i,n) cin >>a[i];
  sort(ALL(a),greater<int>());
  ll ans=a[0];
  int s=1,c=0;
  REP(i,n-2) {
    ans+=a[s];
    c++;
    if(c==2) {
      s++;
      c=0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4048
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

bool setset(bool s1, bool s2, bool s){
  /*
  if(s1==true  && s2==true ) return s;
  if(s1==false && s2==true ) return !s;
  if(s1==true  && s2==false) return !s;
  if(s1==false && s2==false) return s;
  */
  return (s1^s2)!=s;
}

bool check(vb& set1, vb& s, ll N){
  FOR(i, 2, N){
    set1[i] = setset(set1[i-1], set1[i-2], s[i-1]);
  }
  if(set1[1] == setset(set1[0], set1[N-1], s[0]) && set1[0] == setset(set1[N-1], set1[N-2], s[N-1])){
    string ans;
    REP(i, N){
      if(set1[i]==true) ans += 'S';
      else ans += 'W';
    }
    cout << ans << "\n";
    return true;
  }
  return false;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;
  vb s(N, false);
  REP(i, N){
    char tmp;
    cin >> tmp;
    if(tmp=='o') s[i]=true;
  }

  vb set1(N, false); // true - sheep / false - wolf

  set1[0] = true;
  set1[1] = true;
  bool flag = check(set1, s, N);
  if(flag) return 0;

  set1[0] = true;
  set1[1] = false;
  flag = check(set1, s, N);
  if(flag) return 0;

  set1[0] = false;
  set1[1] = true;
  flag = check(set1, s, N);
  if(flag) return 0;

  set1[0] = false;
  set1[1] = false;
  flag = check(set1, s, N);
  if(flag) return 0;

  cout << "-1\n";

  return 0;
}

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

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

    int negCnt = 0;
    vector<ll> a(n);
    rep (i, n)
    {
        int x;
        cin >> x;
        if (x < 0)
        {
            a[i] = x * -1;
            negCnt++;
        }
        else
            a[i] = x;
    }

    ll ans;
    sort(a.begin(), a.end());
    if (negCnt % 2)
        ans = accumulate(a.begin() + 1, a.end(), 0LL + a[0] * -1);
    else
        ans = accumulate(a.begin(), a.end(), 0LL);

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

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


int main()
{
    long long int n,W;
    cin>>n>>W;
    long long int w[n+1],v[n+1],i;
    long long int sum=0;
    for(i=1; i<=n; i++)
    {
        cin>>w[i]>>v[i];
        sum+=v[i];
    }

    long long int dp[sum+1];
    for(i=1; i<=sum; i++)
        dp[i]=100000000000000;

    dp[0]=0;


    for(long long int item=1; item<=n; ++item)
    {
        for(long long int j=sum; j>=v[item]; j--)
        {
            dp[j]=min(dp[j], dp[j-v[item]]+w[item]);
        }
    }

    int res=0;
    for(i=sum; i>=0; i--)
    {
        if(dp[i]<=W)
        {
            res=i;
            break;
        }
    }
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 4344
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define all(v) v.begin(), v.end()
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;cin>>a>>b;
    ll g=__gcd(a,b);
    int cnt=0;
    for(ll i=2;i*i<=g;i++){
        if(g%i==0){
            cnt++;
            while(g%i==0)g/=i;
        }
    }
    if(g!=1)cnt++;
    cout << cnt+1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <iomanip>
#include <vector>
using namespace std;
typedef long long ll;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define MAX_V 100001
#define MOD 1000000007
typedef vector<vector<int> > Graph;

int main(){
    int n;cin>>n;
    int a,b,count;
    count=0;
    vector<int> v;
    vector<int> p(n);
    vector<int> q(n);
    for(int i=0;i<n;i++) cin>>p[i];
    for(int i=0;i<n;i++) cin>>q[i];
    for(int i=1;i<n+1;i++) v.push_back(i);
    do{
        count++;
        for(int i=0;i<n;i++){
            if(v[i]!=p[i]) break;
            if(i==n-1) a=count;
        }
        for(int i=0;i<n;i++){
            if(v[i]!=q[i]) break;
            if(i==n-1) b=count;
        }
    }while(next_permutation(v.begin(),v.end()));
    cout<<abs(a-b)<<endl;
}


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

using namespace std;

const int N = 3005, M = 2e5 + 5, MOD = 1e9 + 7;
int n, h, w, fac[M], dp[M];
pair<int, int> p[M];

inline int add(int a, int b){
	a += b;
	if(a >= MOD)a -= b;
	return a;
}

inline int sub(int a, int b){
	a -= b;
	if(a < 0)a += MOD;
	return a;
}

inline int mul(int a, int b){
	return (int)((long long)a * b %MOD);
}

inline int inv(int a){
	int res = 1, b = MOD - 2;
	while(b > 0){
		if(b & 1)res = mul(res, a);
		b /= 2;
		a = mul(a, a);
	}
	return res;
}

inline int C(int n, int r){
	return mul(fac[n], inv(mul(fac[r], fac[n - r])));
}

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

	fac[0] = 1;
	for(int i=1;i<M;++i)
		fac[i] = mul(fac[i - 1], i);

	cin>>h>>w>>n; h--; w--;
	for(int i=0;i<n;++i){
		cin>>p[i].first>>p[i].second;
		p[i].first--; p[i].second--;
	}
	sort(p, p + n);

	int ans = C(h + w, h);

	for(int i=0;i<n;++i){
		int r = p[i].first, c = p[i].second;
		dp[i] = C(r + c, r);

		for(int j=0;j<i;++j){
			int r1 = p[j].first, c1 = p[j].second;
			if(r1 > r || c1 > c)continue;

			dp[i] = sub(dp[i], mul(dp[j], C(r - r1 + c - c1, r - r1)));
		}
		ans = sub(ans, mul(dp[i], C(h - r + w - c, h - r)));
	}

	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
	int main(void){
	int n,m,l,i,j,k;
	long long int x[101][101],y[101][101],z[101][101]={0};
		scanf("%d %d %d",&n,&m,&l);

			for(i=0;i<n;i++){
				for(j=0;j<m;j++){
					scanf("%d",&x[i][j]);
				}
			}

			for(i=0;i<m;i++){
				for(j=0;j<l;j++){
					scanf("%d",&y[i][j]);
				}
			}

			for(i=0;i<n;i++){
				for(k=0;k<m;k++){
					for(j=0;j<l;j++){
						z[i][j]+=x[i][k]*y[k][j];
					}
				}
			}
			for(i=0;i<n;i++){
				for(j=0;j<l;j++){
					printf("%lld",z[i][j]);
					if(j!=l-1){
						printf(" ");
					}
				}
				printf("\n");
			}
		return 0;
}

Measured memory_bytes: 848
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Sentou
            var line = ReadLine().ToList();
            int n = line[0];    //スイッチの押された回数
            int t = line[1];    //お湯の出続ける秒数

            long totalTime = CalcTotalTimeOfHotWater(n, t);
            Console.WriteLine(totalTime);
        }

        static long CalcTotalTimeOfHotWater(int n, int t)
        {
            var people = ReadLine().ToList();

            int startTime = 0;
            int endTime = t;
            long sum = 0;

            for(int i = 1; i < n; i++)
            {
                int nextStartTime = people[i];

                if (nextStartTime < endTime)
                {
                    int diff = nextStartTime - startTime;
                    sum += diff;
                }
                else
                {
                    sum += t;
                }

                startTime = nextStartTime;
                endTime = startTime + t;
            }

            return sum + t;
        }

        static IEnumerable<int> ReadLine()
        {
            var line = Console.ReadLine().TrimEnd();
            var array = line.Split(' ');

            foreach (var s in array)
            {
                yield return int.Parse(s);
            }
        }
    }
}

Measured memory_bytes: 28640
n, k = map(int, input().split())
if k%2 == 1:
  ans = (n//k)**3
  print(ans)

else:
  ans = (n//k)**3
  if n%k >= k//2:
    ans += (n//k+1)**3
  else:
    ans += (n//k)**3
  print(ans)

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

const int MAX = 25;

struct node{
    int id = -1;
    int parent = -1;
    int degree = 0;
    int left = -1;
    int right = -1;
    int sibling = -1;
};

node nodes[MAX];

int getDegree(int left, int right) {
    if (left < 0 && right < 0) {
        return 0;
    }
    
    if (left > -1 && right > -1) {
        return 2;
    }
    
    return 1;
}

void preorder(int id) {
    if (id < 0) { return; }
    printf(" %d", id);
    preorder(nodes[id].left);
    preorder(nodes[id].right);
}

void inorder(int id) {
    if (id < 0) { return; }
    inorder(nodes[id].left);
    printf(" %d", id);
    inorder(nodes[id].right);
}

void postorder(int id) {
    if (id < 0) { return; }
    postorder(nodes[id].left);
    postorder(nodes[id].right);
    printf(" %d", id);
}

int main() {
    int N;

    scanf("%d", &N);
    
    for (int i = 0; i < N; i++) {
        int id, left, right;
        scanf("%d", &id);
        scanf("%d", &left);
        scanf("%d", &right);
        nodes[id].id = id;
        nodes[id].left = left;
        nodes[id].right = right;
        nodes[id].degree = getDegree(left, right);
        
        if (left != -1) {
            nodes[left].parent = id;
            nodes[left].id = left;
            nodes[left].sibling = right;   
        }
        
        if (right != -1) {
            nodes[right].parent = id;
            nodes[right].id = right;
            nodes[right].sibling = left;   
        }
    }
    
    int root = 0;
    for (int i = 0; i < N; i++) {
        if (nodes[i].parent == -1) { root = nodes[i].id; break; }
    }
    
    cout << "Preorder" << endl;
    preorder(root);
    cout << endl;
    
    cout << "Inorder" << endl;
    inorder(root);
    cout << endl;
    
    cout << "Postorder" << endl;
    postorder(root);
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
const long double PI = acos(-1.0);

#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SORT(v) sort(ALL(v));
#define RSORT(v) sort(RALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;
 
#define HOGE COUT("HOGE")
 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
 
template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
template<typename T> T gcd(T a,T b){if(b==0){return a;}else{return gcd(b, a%b);}}



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;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  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, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
int main() {
    IN(int, n);
    VIN(int, a, n);
    SORT(a);
    pii m = MP(INF, INF);
    REP(i, n-1){
        if (abs(2*a[i]-a[n-1])<m.first) {
            m.first = abs(2*a[i]-a[n-1]);
            m.second = i;
        }
    }
    cout << a[n-1] << " " << a[m.second] << endl;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
    using namespace std;
 
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define mod 1000000007
    #define qmod 998244353
    #define M 1000001
    #define endl "\n"
    #define all(a) (a).begin(),(a).end()
    #define rep(i,a,b) for(int i=a;i<b;++i)
    #define repr(i,a,b) for(int i=a;i>=b;--i)
    #define F first
    #define S second
    #define pb push_back
    #define mp make_pair
 
    typedef long long ll;
    typedef pair<int,int> pii;
    typedef vector<int> vi;
    typedef vector<string> vs;
    typedef vector<pii> vii;
    typedef vector<vi> vvi; 

    void dfs(vvi adj,bool visited[],int s){
        visited[s]=true;      
        cout<<s<<" ";
        for(auto i:adj[s]){
            if(!visited[i]) dfs(adj,visited,i);
        }
    }

    int main(){
        
   /* #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin); 
    freopen("output.txt","w",stdout);   
    #endif  */
 
        fast;
        int v,e,n;
        cin>>n>>v>>e;
        vvi adj(n+5);
        rep(i,0,n-1){
            adj[i+1].pb(i+2);
            adj[i+2].pb(i+1);
        }
        adj[v].pb(e);
        adj[e].pb(v);
       // for(int i=1;i<n;i++){for(int j=0;j<adj[i].size();j++) cout<<adj[i][j]<<" ";cout<<endl;}
        map<int,int> mp;
        rep(i,1,n+1){
            bool visited[n+5];
            memset(visited,false,sizeof(visited));
            queue<int> q;
            int s=i,dist[n+5]={};
            dist[s]=0;
            q.push(s);
            visited[s]=true;
            while(!q.empty()){
                int u=q.front();
                q.pop();
                for(auto i:adj[u]){
                    if(!visited[i]){
                        q.push(i);
                        visited[i]=true;
                        dist[i]=dist[u]+1;
                    }
                }
            }
            rep(i,1,n+1){
                mp[dist[i]]++;
            } 

        }
        rep(i,1,n) {
            int ans=mp[i];
            if(!ans) cout<<0<<endl;
            else cout<<mp[i]/2<<endl;
        }

        //for(auto i:mp) cout<<i.F<<" "<<i.S<<endl;
        return 0;  
    } 

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; ++i) cin >> a[i];

  if ((n - 1) % (k - 1) == 0) cout << (n - 1) / (k - 1) << endl;
  else cout << ((n - 1) / (k - 1)) + 1 << endl;
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int n,a,MAX;
int cnt[105];

int main()
{
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		cin >> a;
		cnt[a]++;
		MAX = max(MAX,a);
	}
	for (int i = MAX;i >= (MAX + 1) / 2;i--)
	{
		int s = 2;
		if (i == (MAX + 1) / 2 && MAX % 2 == 0)
			s = 1;
		if (cnt[i] < s)
		{
			puts("Impossible");
			return 0;
		}
		cnt[i] -= s;
	}
	for (int i = 1;i <= MAX;i++)
		if (cnt[i] && i <= (MAX + 1) / 2)
		{
			puts("Impossible");
			return 0;
		}
	puts("Possible");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<set>
#include<iomanip>
using namespace std;

int main()
{
	int a,b;
	char s[20];
	cin>>a>>b>>s;
	for(int i=0;i<=a+b;i++)
	{
		if(i==a)
		{
			if(s[i]!='-')
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
		else
		{
			if(s[i]=='-')
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long inputNum = scan.nextLong();
		scan.close();

		if (inputNum == 2) {
			System.out.println(2);
			return;
		}
		if (inputNum == 3) {
			System.out.println(3);
			return;
		}

		for (int i = 0; ; i++) {
			if (isPrimeNumber(inputNum + i)) {
				System.out.println(inputNum + i);
				return;
			}
		}
	}

	private static boolean isPrimeNumber(long value) {
		boolean ret = true;

		for (int i = 2; ; i++) {
			if (value % i == 0) {
				ret = false;
				break;
			}

			if (i >= (value / 2)) {
				break;
			}
		}
		return ret;
	}
}


Measured memory_bytes: 21716
import qualified Control.Monad as Monad
import qualified Data.ByteString.Char8 as BS
import qualified Data.Maybe as Maybe
import qualified Debug.Trace as Trace

dist :: [Int] -> [Int] -> Double
dist a b = sqrt ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))
    where x1 = (fromIntegral (a !! 0))
          y1 = (fromIntegral (a !! 1))
          x2 = (fromIntegral (b !! 0))
          y2 = (fromIntegral (b !! 1))


solve :: Int -> [[Int]] -> Double
solve n a = (foldl1 (+) dists) / (fromIntegral n)
    where dists = [dist x y | x <- a, y <- a]



main = do
    n <- (fst . Maybe.fromJust . BS.readInt) <$> BS.getLine
    a <- Monad.replicateM n (map (fst . Maybe.fromJust . BS.readInt) . BS.words <$> BS.getLine)
    let ans = solve n a
    print ans

Measured memory_bytes: 3928
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    string s; cin >> s;
    int ans = 0;
    REP(i,s.size()) if (s[i] == '+') ans++; else ans--;
    OUT(ans)

    return 0;
}

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

int main(){
  string S; cin>>S;
  ll N=S.size();
  ll countA=0;
  ll countB=0;
  ll countC=0;
  for(ll i=0; i<N; i++){
    if(S[i]=='a') countA++;
    if(S[i]=='b') countB++;
    if(S[i]=='c') countC++;
  }
  if(abs(countA-countB)<=1 && abs(countB-countC)<=1 && abs(countC-countA)<=1) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 512
import java.io.*;
import java.lang.*;
import java.util.*;

public class Main
{
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 5; i++) {
            int curr = sc.nextInt();
            if (curr == 0) {
                System.out.println(i + 1);
                break;
            }
        }
        
    }
}


Measured memory_bytes: 35784
#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 double PI = acos(-1);
const ll MOD = 1000000007;

vector<vector<int>> data(200001, vector<int>(0));
vector<ll> ans(200001, 0);

void sousa(int a, int from = -1){

  rep(i, data[a].size()){
    if(data[a][i] == from) continue;
    ans[data[a][i]] += ans[a];
    sousa(data[a][i], a);
  }
}

int main() {
  int N, Q;
  cin >> N >> Q;
  rep(i, N-1){
    int a, b;
    cin >> a >> b;
    data[a].push_back(b);
    data[b].push_back(a);
  }

  rep(i, Q){
    int p, x;
    cin >> p >> x;
    ans[p] += x;
  }

  sousa(1);


  for(int i = 1; i <= N; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 24320
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	g := make([][]int, n)
	for i := 0; i < n-1; i++ {
		a, b := intScanner()-1, intScanner()-1
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}
	cs := intSliceScanner(n)
	sort.Sort(sort.Reverse(sort.IntSlice(cs)))
	ans := 0
	for i := 1; i < n; i++ {
		ans += cs[i]
	}
	q := []int{0}
	s := make([]int, n)
	for i := 0; len(q) != 0; i++ {
		y := q[0]
		q = q[1:]
		s[y] = cs[i]
		for _, v := range g[y] {
			if s[v] == 0 {
				q = append(q, v)
			}
		}
	}
	fmt.Println(ans)
	fmt.Println(strings.Trim(fmt.Sprint(s), "[]"))
}


Measured memory_bytes: 2688
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[][] a = new long[n][2];
		int number = 0;
		long answer = 0;
		for(int i = 0; i < n; i++) {
			a[i][0] = sc.nextLong();
			a[i][1] = sc.nextLong();
		}		
		Arrays.sort(a,(x,y)->Long.compare(x[0], y[0]));
		for(int i = 0; i < n; i++) {
			if(number + a[i][1] < m) {
				answer += a[i][0] * a[i][1];
				number += a[i][1];
			}
			else{
				answer += a[i][0] * (m - number);
				break;
			}
		}
		System.out.println(answer);
	}

}

Measured memory_bytes: 95248
package main

import "fmt"

func main() {
	h := make([]int, 0)
	w := make([]int, 0)

	for{
		var hnum, wnum int
		fmt.Scan(&hnum)
		fmt.Scan(&wnum)
		if hnum == 0 && wnum == 0{
			break
		}
		h = append(h, hnum)
		w = append(w, wnum)
	}

	for i:=0; i<len(h); i++{
		for l:=0; l<h[i]; l++{
			for k:=0; k<w[i]; k++{
				fmt.Print("#")
			}
			fmt.Println()
		}
		fmt.Print("\n")
	}
}



Measured memory_bytes: 1116
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    std::deque<char> deq{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    std::deque<char> ans;
    for (int i=0;i<s.size();i++) {
        if (find(ans.begin(),ans.end(),s.at(i))==ans.end()) {
            ans.emplace_back(s.at(i));
        }
    }
    sort(ans.begin(),ans.end());
    int flag=0;
    for (int j=0;j<26;j++) {
        if (deq[j]!=ans[j]) {
            cout<<deq[j]<<endl;
            flag=1;
            break;
        }
    }
    if (flag==0) {
        cout<<"None"<<endl;
    }
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include<functional>
#include <tuple>
#include <map>
#include<set>
#include <cmath>
#include <stack>
#include<cstdio>
#include<stdio.h>
using namespace std;

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

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

int main() {
  string a,b,c;
  cin>>a>>b>>c;
  
  char d;
  d = 'A'-'a';
  
  a.at(0) +=d;
  b.at(0) +=d;
  c.at(0) +=d;
  
  cout<<a.at(0)<<b.at(0)<<c.at(0)<<endl;
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > p;
int main(){
	int n, m, a, b;
	scanf("%d%d", &n, &m);
	for(int i = 0 ; i < n ; ++i){
		scanf("%d%d", &a, &b);
		p.push_back(make_pair(a, b));
	}
	sort(p.begin(), p.end());
	
	long long cnt = m, res = 0;
	for(int i = 0 ; i < n ; ++i){
		if(p[i].second < cnt){
			cnt -= p[i].second;
			res += p[i].second * p[i].first;
		}
		else{
			res += cnt * p[i].first;
			cnt = 0;
			break;
		}
	}
	printf("%lld\n", res);
	return 0;
}
 

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

const ll INF = 1e18;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int N, K;
	cin >> N >> K;
	vector<int> h(N);
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	vector<ll> dp(N, INF);
	dp[0] = 0;
	for (int i = 1; i < N; i++) {
		for (int j = 1; j <= min(K, i); j++) {
			dp[i] = min(dp[i], abs(h[i] - h[i - j]) + dp[i - j]);
		}
	}
	cout << dp[N - 1];
	
	return 0;
}


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

int main(){
    int n,v,ans,c1,c2;
    cin >> n;
    map<int, int> V0,V1;
    pair<int, int> v1top = make_pair(-1, 0),v1sec = make_pair(-1, 0), v0top = make_pair(-1, 0), v0sec = make_pair(-1, 0);

    
    for(int i=0;i<n;i++){
        cin >> v;
        if(i%2){
            V1[v]++;
        }else{
            V0[v]++;
        }
    }

    for(auto iter = V0.begin();iter!=V0.end();iter++){
        if(v0top.second < iter->second){
            v0top.first = iter->first;
            v0sec.second = v0top.second;
            v0top.second = iter->second;
        }else if(v0sec.second < iter->second){
            v0sec.second = iter->second;
        }
    }
  
    for(auto iter = V1.begin();iter!=V1.end();iter++){
        if(v1top.second < iter->second){
            v1top.first = iter->first;
            v1sec.second = v1top.second;
            v1top.second = iter->second;
        }else if(v1sec.second < iter->second){
            v1sec.second = iter->second;
        }
    }
  
    if(v0top.first==v1top.first){
            c1 = n-v0top.second-v1sec.second;
            c2 = n-v0sec.second-v1top.second;
            ans = min(c1, c2);
    }else{
        ans = n-v0top.second-v1top.second;
    }
    cout << ans << endl;
}



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

#define mp              make_pair
#define pb              push_back
#define ff              first
#define ss              second
#define inc(A,B)        A=(A+(B))%MOD
#define mul(A,B)        (ll(A)*ll(B)%ll(MOD))
#define sub(a,b)        (((a)-(b)+MOD)%MOD)

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

const int MAX_N = 100005;
const int MOD = 1e9 + 7;

int n, exponent;
int memo[MAX_N];

void update ( int &cant, int nextCant ) {
  if ( cant == -1 )
    cant = nextCant;
  else
    cant = min ( cant, nextCant );
}

void fillFor ( int num ) {
  for ( int i = 0; i <= n-num; ++i )
    if ( memo[i] != -1 )
      update ( memo[i+num], memo[i]+1 );
}

void doForExp ( int exponent, int bas ) {
  do {
    bas *= exponent;
    fillFor ( bas );
  } while ( bas <= n/exponent );
}

int main() {

//  freopen ( "in.txt" , "r" , stdin );
//  freopen ( "out.txt" , "w" , stdout );

  memset ( memo, -1, sizeof memo );
  scanf ( "%d", &n );

  memo[0] = 0;
  doForExp ( 6, 1 );
  doForExp ( 9, 1 );
  fillFor ( 1 );

  printf ( "%d\n", memo[n] );

  return 0;

}

Measured memory_bytes: 640
n, a, b, c = map(int, input().split())
abc = list((a, b, c))
ans = [0] * n
dic = {'A': 0, 'B': 1, 'C': 2}
flag = True
s = [input() for i in range(n)]
for i in range(n):
    if abc[dic[s[i][0]]] == 0 and abc[dic[s[i][1]]] == 0:
        flag = False
        break
    elif sum(abc) == 2 and abc[dic[s[i][0]]] == 1 and abc[dic[s[i][1]]] == 1 and i != n - 1:
        ps = (set(s[i]) & set(s[i + 1])).pop()
        ms = (set(s[i]) - set(ps)).pop()
        abc[dic[ps]] += 1
        abc[dic[ms]] -= 1
        ans[i] = ps
    elif abc[dic[s[i][0]]] <= abc[dic[s[i][1]]]:
        abc[dic[s[i][0]]] += 1
        abc[dic[s[i][1]]] -= 1
        ans[i] = s[i][0]
    else:
        abc[dic[s[i][0]]] -= 1
        abc[dic[s[i][1]]] += 1
        ans[i] = s[i][1]
if flag:
    print('Yes')
    print(*ans, sep='\n')
else:
    print('No')

Measured memory_bytes: 18352
#include "bits/stdc++.h"

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;



int main() {
	speed;
	cout << fixed << setprecision(6);
	/*start*/
	int n;
	cin >> n;
	if (n < 3) {
		c(0);
	}
	else c(n / 3);
	return 0;
}



Measured memory_bytes: 256
t[10];M(int*a){return*a-*1[&a];}main(n,i,j,r,S){for(;~scanf(S="%d\n",&n);){for(i=n;i--;t[i]^=30720)for(t[i]=getchar(j=n)|i<<7;--j;r<2?t[i]+=1<<15-r*4:0)scanf(S,&r);for(qsort(t,n,4,M);n--;puts(&j))j=t[n]&127;}}

Measured memory_bytes: 0
#include <iostream>
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);
#define pii pair<ll  , int>
#define mpi make_pair
#define F first
#define S second
#define pb push_back
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define endl '\n'
#define vii vector<ll>
#define INF 1e18

void solve()
{	
	
}

int main()
{
	fastio;
	int h ,w , a, b;

	cin>>h>>w>>a>>b;

	string s1 ,s2;

	s1 = "";s2 = "";

	for(int i = 0;i<a;i++)
	{
		s1 += '0';
		s2 += '1';
	}

	for(int i = a;i<w;i++)
	{
		s1 += '1';
		s2 +='0';
	}

	for(int i = 0 ; i<b;i++)cout<<s1<<endl;
		for(int i = b ; i <h;i++)cout<<s2<<endl;

	return 0;
}



Measured memory_bytes: 1280
a,b,c,k = map(int,input().split())

ans=0
if k<a:
    print(k);exit()
if k>=a:
    ans+=a
    k-=a
    if k==0:
        print(ans);exit()
if k>=b:
    k-=b
    if k==0:
        print(ans);exit()
print(ans-k)

Measured memory_bytes: 9068
// 2020-08-23 22:46:59
#include <cstring>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
#include <deque>


#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

using T = tuple<int, int, int>;
const int inf = 1e9;
void answer() {
  int h, w;
  cin >> h >> w;
  int Ch, Cw, Dh, Dw;
  cin >> Ch >> Cw >> Dh >> Dw;
  Ch--;
  Cw--;
  Dh--;
  Dw--;
  vector<string> maze(h);
  rep(i, h) {
    string s;
    cin >> s;
    maze[i] = s;
  }
  deque<T> que;
  vector<vector<int> > D(h, vector<int>(w, inf));
  que.emplace_front(0, Ch, Cw);
  while(!que.empty()) {
    auto [cd, cy, cx] = que.front(); que.pop_front();
    if(D[cy][cx] < cd) continue;
    chmin(D[cy][cx], cd);
    REPC(dy, -2, 2) REPC(dx, -2, 2) {
      if(dy == 0 && dx == 0) continue;
      int ny = cy + dy, nx = cx + dx;
      if(ny < 0 || h <= ny || nx < 0 || w <= nx || maze[ny][nx] == '#') continue;
      if(abs(ny - cy) + abs(nx - cx) == 1) {
        int nd = cd;
        if(chmin(D[ny][nx], nd)) {
          que.emplace_front(nd, ny, nx);
        }
      } else {
        int nd = cd + 1;
        if(chmin(D[ny][nx], nd)) {
          que.emplace_back(nd, ny, nx);
        }
      }
    }
  }
  int ans = D[Dh][Dw];
  if(ans == inf) ans = -1;
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 8132
n,k = [int(i) for i in input().split()]
mod = 10**9+7
chk = 0
ans = 0
for i in range(n+1):
  chk += (n + i*n +1 -(i+1)*i)%mod
  chk %= mod
for i in range(k-1):
  ans += (n + i*n +1 -(i+1)*i)%mod
  ans %= mod
print((chk-ans)%mod) 

Measured memory_bytes: 9228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n,m;
  cin >> n >> m;
  vector<vector<int>> graph(n);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--; b--;
    graph.at(a).push_back(b);
    graph.at(b).push_back(a);
  }
  rep(i,n){
    cout << graph.at(i).size() << endl;
  }
}


Measured memory_bytes: 256
def prim(n):
    d = [None] * 100
    p = [None] * 100
    color = [None] * 100
    
    for i in xrange(n):
        d[i] = float('inf')
        p[i] = -1
        color[i] = 0
    
    d[0] = 0
    
    while(True):
        minv = float('inf')
        u = -1
        for i in xrange(n):
            if minv > d[i] and color[i] != 2:
                u = i
                minv = d[i]
        
        if u == -1:
            break
        
        color[u] = 2
        
        for v in xrange(n):
            if color[v] != 2 and data[u][v] != float('inf'):
                if (d[v] > data[u][v]):
                    d[v] = data[u][v]
                    p[v] = u
                    color[v] = 1
    
    sum_val = 0
    for i in xrange(n):
        if p[i] != -1:
            sum_val += data[i][p[i]]
    
    return sum_val
    
n = input()
data = [None] * n
for i in xrange(n):
    data[i] = [None] * n
    line = map(int, raw_input().split())
    for j in xrange(n):
        if line[j] == -1:
            data[i][j] = float('inf')
        else:
            data[i][j] = line[j];
print prim(n)

    

Measured memory_bytes: 6572
#include<iostream>
#include <algorithm>
#include <vector>
using namespace std;
int judge(int t, int x, int y){
  int a = t-x-y;
  if(a>=0 && a%2==0) return 1;
  else return 0;
}
int main(){
  int N, ans=1;
  cin >> N;
  int t[N+1],x[N+1],y[N+1];

  t[0]=0;
  x[0]=0;
  y[0]=0;

  for(int i=0;i<N;i++){
    cin >> t[i+1] >> x[i+1] >> y[i+1];
    ans *= judge(t[i+1]-t[i], x[i+1]-x[i], y[i+1]-y[i]); 
  }
  
  if(ans){
    cout << "Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;
#define MAX 100000
int n,k;
long long T[MAX];

int check(int p){
    int i=0;
    for(int j=0;j<k;j++){
        long long s =0;
        while(s+T[i]<=p){
            s+=T[i];
            i++;
            if(i == n) return n;
        }
    }
    return i;
}
int solve(){
    
    int left = 0;
    int right = 100000*10000;
    while(left<right){
        int mid = (left+right)/2;
        if(check(mid)==n&&check(mid-1)<n){
            return mid;
        }
        else if(check(mid)==n){
            right = mid;
        }
        else {
            left = mid+1;
        }
    }
}
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>T[i];
    }
    int p = solve();
    cout<<p<<endl;
    return 0;
}



Measured memory_bytes: 3888
#include <cstdio>
#include <iostream>
#include <vector>
#include <unordered_set>
#include <chrono>
using namespace std;

struct custom_hash {
    typedef long long ll;
    typedef unsigned long long ull;
    const ull FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    static ull splitmix64(ull x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(ll x) const {
        return splitmix64(x + FIXED_RANDOM);
    }
    size_t operator()(const pair<int,int> &i)const{
        return splitmix64((((ll)i.first)^(((ll)i.second)<<32))+FIXED_RANDOM);
    }
};

struct ufds{
    int p[100005];

    ufds(){
        for (int x=0;x<100005;x++){
            p[x]=x;
        }
    }
    int parent(int i){return (p[i]==i)?i:p[i]=parent(p[i]);}
    void unions(int i,int j){
        i=parent(i),j=parent(j);
        p[i]=j;
    }
}dsu=*new ufds();



inline long long E(int i,int j){
    if (i>j) return (long long)i<<32|j;
    else return (long long)j<<32|i;
}

inline int f(long long i){
    return i>>32;
}

inline int s(long long i){
    return i&4294967295;
}

int n;
unordered_set<int,custom_hash> al[100005];
unordered_set<long long,custom_hash> edges;
vector<long long> del;

inline void INS(long long temp){
    if (edges.count(temp)){
        edges.erase(temp);
        al[f(temp)].erase(s(temp));
        al[s(temp)].erase(f(temp));
        del.push_back(temp);
    }
    else{
        edges.insert(temp);
        al[f(temp)].insert(s(temp));
        al[s(temp)].insert(f(temp));
    }
}

inline void DEL(int i,int j){
    edges.erase(E(i,j));
    al[i].erase(j);
}

int main(){
    scanf("%d",&n);
    
    int a,b;
    for (int x=2;x<2*n;x++){
        scanf("%d%d",&a,&b);
        INS(E(a,b));
    }
    
    long long curr;
    int u,v; //u->v merging
    while (!del.empty()){
        curr=del.back(),del.pop_back();
        
        u=dsu.parent(f(curr)),v=dsu.parent(s(curr));
        if (al[u].size()>al[v].size()) swap(u,v);
        
        for (auto &it:al[u]){
            DEL(it,u);
            INS(E(it,v));
        }
        
        dsu.unions(u,v);
    }
    
    if (edges.empty()) printf("YES\n");
    else printf("NO\n");
}

Measured memory_bytes: 36296