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

typedef long long ll;
const int M=100010;

struct node{
	ll v , x;
}a[M];

ll vis[M];

bool cmp (node x,node y){
	return x.v > y.v;
}

int n , k;
ll cnt, tp ,res,ans;
int main(){
	cin >> n >> k ;
	for (int i = 1 ; i <= n ; i ++ ){
		int a1 , b ;
		cin >> a1 >> b ;
		a[ i ].x = a1 ;
		a[ i ].v = b ;
	}
	sort (a + 1 , a + n + 1 , cmp );
	stack<ll> s;
    for (int i = 1 ;i <= n ;i ++){
        if(cnt < k){
                if( vis [ a [ i ].x ] == 0 ){
                    vis [ a [ i ].x ]=1;
                    tp ++;
                }
				else{
                    s.push( a[ i ].v );
                }
                res+=a[i].v;
                cnt++;
                ans=max(ans,res+1ll*tp*tp);
        }
        else{
            if(s.empty()) break;
            if(vis[a[i].x]) continue;
            vis [ a [ i ] . x ]=1;
            tp ++;
            res -= s.top();
            res += a[i].v;
            s.pop();
            ans=max( ans , res + tp * tp );
        }
    }
    printf("%lld\n" , ans);
    return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, h;
  cin >> n >> h;
  vector<pair<int, int>> vp(n);
  rep(i, n){
    int a, b;
    cin >> a >> b;
    vp.at(i) = {a, b};
  }

  auto mitr = vp.begin();
  repit(itr, vp){
    if(itr->first > mitr->first){
      mitr = itr;
    }else if(itr->first == mitr->first){
      if(itr->second < mitr->second){
        mitr = itr;
      }
    }
  }
  int mxa = mitr->first, mxb = mitr->second;
  vp.erase(mitr);
  sort(ALL(vp), [](const auto &l, const auto &r){
    return l.second > r.second;
  });
  ll ans = 0;
  for(auto p : vp){
    if(p.second > mxa){
      h -= p.second;
      ans++;
      if(h <= 0) break;
    }else break;
  }
  if(h > 0){
    h -= mxb;
    ans++;
    if(h >= 0){
      ans += (h+mxa-1)/mxa;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

const int N_MAX = 2002;

int n, x, y;

int cnt[N_MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> x >> y;
    for(int i = 1; i <= n; i++)
        for(int j = i + 1; j <= n; j++)
        {
            int d = n;
            d = min(d, j - i);
            int di, dj;
            di = abs(i - x);
            dj = abs(j - y);
            d = min(d, di + dj + 1);
            cnt[d]++;
        }
    for(int i = 1; i < n; i++)
        cout << cnt[i] << "\n";
    return 0;
}


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();
    if(n%2==0){
      System.out.println(n/2-1);
    }else{
      System.out.println(n/2);
    }
  }
}

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

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

int getnum(const vector<int>&as, int K) {
	int ans = 0;
	for (int l = 0; l <= as.size() - K; ++l) {
		int num = 1;
		for (int i = l; i < l + K; ++i) {
			num *= as[i];
		}
		ans = max(ans, num);
	}
	return ans;
}

int main() {
	while (1) {
		int N, K; cin >> N >> K;
		if (!N)break;
		vector<int>as(N);
		for (int i = 0; i < N; ++i) {
			cin >> as[i];
		}
		int fst = getnum(as, K);
		int ans = 0;
		for (int i = 0; i < N; ++i) {
			for (int j = 1; j < N; ++j) {
				swap(as[i], as[j]);
				int n = getnum(as, K);
				ans = max(ans, n - fst);
				swap(as[i], as[j]);

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

Measured memory_bytes: 3040
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        a[0] = 11;
        int num = a[0];
        System.out.println(a[0] + " ");

        boolean bl;
        for(int i=1; i<n; i++){
            do{
                num += 10;
            }while(primJudge(num) == false);
            a[i] = num;
            System.out.println(a[i] + " ");   
        }
    }

    public static  boolean primJudge (int k){
        boolean bl = true;
        if( k==1 ) bl = false;
        if( k==2 ) bl = true;
        if( k>=3){
            for(int j=3; j*j<=k; j+=2){
                if(k % j == 0){
                    bl = false;
                    break;
                }
            }
        }
        return(bl);
    }
}

Measured memory_bytes: 21844
#include<stdio.h>

int main(){
  int i,j,n,num,prev;
  char segment[]="0000000";
  char nums[][8]={"0111111","0000110","1011011","1001111",
		  "1100110","1101101","1111101","0100111",
		  "1111111","1101111","0000000"};
  do{
    scanf("%d",&n);
    if(n==-1) break;
    for(prev=10,i=0;i<n;i++,prev=num){
      scanf("%d",&num);
      for(j=0;j<7;j++){
	if(nums[prev][j]==nums[num][j]){
	  segment[j]='0';
	}else{
	  segment[j]='1';
	}
      }
      printf("%s\n",segment);
    }
  }while(1);
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    string s;
    cin >> s;
    vector<int64_t> v(s.size());
    for(int i=0; i<s.size(); i++){
        v.at(i) = s.at(i);
    }
    vector<char> res1(s.size()), res2(s.size());
    char a='0', b='1';
    for(int i=0; i<s.size(); i++){
        res1.at(i) = a;
        res2.at(i) = b;
        swap(a, b);
    }
    int64_t r1=0, r2=0;
    for(int i=0; i<s.size(); i++){
        if(res1.at(i)!= s.at(i)) r1++;
        if(res2.at(i)!= s.at(i)) r2++;
    }
    cout << min(r1, r2) << endl;
}


Measured memory_bytes: 1360
#include <vector>
#include <iostream>
#include <algorithm>
#include <climits>

using namespace std;
const long long INF = (1LL << 29);

//dist table
long long graph[201][201];


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

    vector<int> visit_towns(R);
    for(int i = 0 ; i < R; ++i){
        cin >> visit_towns[i];
        visit_towns[i]--;
    }


    //init
    for(int i=0; i<N; ++i){
        for(int j=0; j<N; ++j){
            if(i == j){
                graph[i][j] = 0;
            }else{
                graph[i][j] = INF;
            }
        }
    }


    for(int i=0; i<M; ++i){
        long long A, B, C;
        cin >> A >> B >> C;
        A--; B--;
        graph[A][B] = min(C, graph[A][B]);
        graph[B][A] = min(C, graph[B][A]);
    }

    //warshall_floyd
    for(int k=0; k < N; ++k){  // 経由する頂点
        for(int i=0; i<N; ++i){ // 始点
            for(int j=0; j < N; ++j){  //// 終点
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
            }
        }
    }

    long long ans = INF;
    sort(visit_towns.begin(), visit_towns.end());
    do{
        long long tmp = 0;
        for(int i=0; i<visit_towns.size()-1; ++i){
            tmp += graph[visit_towns[i]][visit_towns[i+1]];
        }
        ans = min(ans, tmp);

    }while(next_permutation(visit_towns.begin(), visit_towns.end() ) );

    cout << ans << endl;
}

Measured memory_bytes: 512
n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(n-2):
    if min(p[i],p[i+1],p[i+2]) != p[i+1]:
        if max(p[i],p[i+1],p[i+2]) != p[i+1]:
            ans += 1
print(ans)

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> P(M);
  vector<int> Y(M);
  vector<int> num(N+1,1);
  vector<pair<int,int>> Yn(M);
  for (int i=0; i<M; i++) {
    cin >> P[i] >> Y[i];
    Yn[i].first = Y[i];
    Yn[i].second = i;
  }
  sort(Yn.begin(),Yn.end());
  int shi;
  for (int i=0; i<M; i++) {
    shi = Yn[i].second;
    Y[shi] = num[P[shi]];
    num[P[shi]]++;
  }
  for (int i=0; i<M; i++) {
    if (P[i] < 10) {
      cout << 0;
    }
    if (P[i] < 100) {
      cout << 0;
    }
    if (P[i] < 1000) {
      cout << 0;
    }
    if (P[i] < 10000) {
      cout << 0;
    }
    if (P[i] < 100000) {
      cout << 0;
    }
    cout << P[i];
    if (Y[i] < 10) {
      cout << 0;
    }
    if (Y[i] < 100) {
      cout << 0;
    }
    if (Y[i] < 1000) {
      cout << 0;
    }
    if (Y[i] < 10000) {
      cout << 0;
    }
    if (Y[i] < 100000) {
      cout << 0;
    }
    cout << Y[i] << endl;
  }
}

Measured memory_bytes: 3456
N = int(input())
A = list(map(int,input().split()))
A.sort()
count = 0

for i in range(N-1,0,-1):
    l = 0
    r = i -1
    while(l< r):
        if (A[l] + A[r] >A[i]):
            count += (r-l)
            r -= 1
        else:
            l += 1
print(count)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
 
using namespace std;
 
int main(){
  int n, a, b;
  string s;
  cin >> n >> a >> b;
  cin >> s;
  
  int brank = 0;
  int arank = 0;
  for(int i = 0; i < n; i++){
      if(s[i] == 'a'){
        if(arank< a + b){
          cout << "Yes" << endl;
          arank++;
        }
        else{
          cout << "No" << endl;
        }
      }
      else if(s[i] == 'b'){
          if(arank < a + b && brank <= b - 1){
             cout << "Yes" << endl;
             arank++;
             brank++;
          }
          else{
            cout << "No" << endl;
          }
      }
      else{
           cout << "No" << endl;
      }
  }
 
}

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

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	
	if(a>=c&&a>=b&&c>=b||a>=c&&a>=b&&b>c) cout<<a*10+b+c<<endl;
	if(b>c&&b>a&&a>=c||b>c&&b>a&&c>a) cout<<b*10+a+c<<endl;
	if(c>a&&c>b&&a>=b||c>a&&c>b&&b>a) cout<<c*10+b+a<<endl;
	
	return 0;
}

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

using namespace std;

int n;

bool check(int y) {
	int x = y;
	int ans = 0;
	while (x > 0) {
		ans ++;
		x /= 10;
	}
	if (ans & 1) return 1;
	else return 0;
}

int main() {
	scanf("%d", &n);
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		int k = i;
		if (check(k)) cnt ++;
	}
	cout << cnt << endl;
	return 0;
} 

Measured memory_bytes: 256
S = list(input())
loop = len(S)//2
if len(S)%2 == 1:
    odd = 1
else:
    odd = 0
A = 0
B = 0
for x in range(loop):
    if S[x*2] == "0":
        A += 1
    if S[1+x*2] == "1":
        A += 1
for x in range(loop):
    if S[x*2] == "1":
        B += 1
    if S[1+x*2] == "0":
        B += 1
if odd == 1:
        if S[-1] == "0":
            A += 1 
        else:
            B += 1
if A < B:
    ans = A
else:
    ans = B
print(ans)

Measured memory_bytes: 4008
w,h,n = map(int, input().split())
a,b,c,d = 0,0,w,h
for _ in range(n):
    x,y,i = map(int, input().split())
    if i == 1:
        a = max(a,x)
    elif i == 2:
        c = min(c,x)
    elif i == 3:
        b = max(b,y)
    elif i == 4:
        d = min(d,y)

print(max(0,c-a) * max(0,d-b))
# print(a,b,c,d)


Measured memory_bytes: 3060
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long K = sc.nextLong();
        long ans = K;
        if(N == 1){
            ans = K;
            System.out.println(ans);
            return;
        }
        for(int i = 1; i < N; i++){
            ans *= K - 1;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35636
h,w,k=gets.split.map(&:to_i)
c=[]
s=[]
h.times do
  c << gets.chomp.chars
  s << []
end
a=0
[0,1].repeated_permutation(h) do |bi|
  [0,1].repeated_permutation(w) do |bj|
    h.times do |i|
      s[i]=c[i].dup
    end
    h.times do |i|
      if bi[i]==1
        s[i]=["."]*w
      end
    end
    w.times do |j|
      if bj[j]==1
        h.times do |i|
          s[i][j]="."
        end
      end
    end
    cnt=0
    h.times do |i|
      cnt+=s[i].count("#")
    end
    if cnt==k
      a+=1
    end
  end
end
puts a


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    vector<ll> v(K);
    REP(i, K) {
        cin >> v[i];
    }

    REP(b, pow(2LL, K)) {
        ll x = 0;
        REP(j, K) {
            if ((b >> j) & 1)
                x |= (1LL << v[j]);
        }
        cout << x << ":";
        REP(j, K) {
            if ((b >> j) & 1)
                cout << " " << v[j];
        }
        cout << endl;
    }
    return 0;
}


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

int main(){
	int a, b, c, n, lengh[3], ans[1000];
	priority_queue< int > Q;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b>>c;
		Q.push(a);
		Q.push(b);
		Q.push(c);
		for(int j=0;j<3;j++){
			lengh[j]=Q.top();
			Q.pop();
		}
		int res=lengh[1]*lengh[1]+lengh[2]*lengh[2];
		int res2=lengh[0]*lengh[0];
		if(res==res2){
			ans[i]=1;
		}else{
			ans[i]=0;
		}
	}
	for(int i=0;i<n;i++){
		if(ans[i]==1){
			cout<<"YES"<<endl;
		}else if(ans[i]==0){
			cout<<"NO"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3120
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;

int H,W;
char a[1000][1000];

LL ans = 0;

//座標(h,w)へ行く経路の場合の数をdp[h][w]とおく
//ただし(h,w)が壁ならdp[h][w]=-1
vector<vector<LL>> dp;

void solve(){
	dp = vector<vector<LL>>(H,vector<LL>(W,0));
	dp[0][0] = 1;
	for(int h=0;h<H;h++){
		for(int w=0;w<W;w++){
			if(h<H-1){
				if(a[h+1][w]=='#') dp[h+1][w] = 0;
				else{
					dp[h+1][w] += dp[h][w];
					dp[h+1][w] %= mod;
				}
			}
			if(w<W-1){
				if(a[h][w+1]=='#') dp[h][w+1] = 0;
				else{
					dp[h][w+1] += dp[h][w];
					dp[h][w+1] %= mod;
				}
			}
		}
	}
	ans = dp[H-1][W-1];
}
 
int main(){
	cin >> H >> W;
	for(int h=0;h<H;h++){
		for(int w=0;w<W;w++) cin >> a[h][w];
	}
 
	solve();

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

Measured memory_bytes: 9088
import java.io.*;
import java.math.*;
import java.util.*;





public class Main {

    static MyScanner in = new MyScanner();
    static   PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    int N;
    static int max = 200001;
    static int [] dr = {1,-1,0,0};
    static int [] dc={0,0,-1,1};
    static boolean [][] grid;
    static int [] bishopr = {-1,1,-1,1};
    static int [] bishopc = {1,1,-1,-1};
    static long H,W,cnt;
    public static void main(String args[]) throws IOException {
           int L = in.nextInt();
           int R = in.nextInt();
           int d = in.nextInt();
           int cnt =0;
           for(int i=L;i<=R;i++){
                if(i%d==0)
                    cnt++;
           }
           out.println(cnt);


        out.flush();
        }
       static boolean isValid (int r, int c){
           if(r>=0&&r<H&&c>=0&&c<W){
               return true;
           }
           return false;
       }
        private static void dfs(int r, int c) {
            for(int i=0;i<4;i++){
                int nr = bishopr[i] +r;
                int nc = bishopc[i]+c;
                if(isValid(nr, nc)&&!grid[nr][nc]){
                    cnt++;
                    grid[nr][nc] = true;
                    dfs(nr, nc);
                }
            }
        }

        static boolean isEven(long a) {
            return (a&1)==0;
        }
       static  void swap (int a, int b){

        int temmp = b;
        b=a;
        a = temmp;
        }
    

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
   
        public MyScanner() {
           br = new BufferedReader(new InputStreamReader(System.in));
        }
   
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
   
        int nextInt() {
            return Integer.parseInt(next());
        }
   
        long nextLong() {
            return Long.parseLong(next());
        }
   
        double nextDouble() {
            return Double.parseDouble(next());
        }
   
        String nextLine(){
            String str = "";
        try {
           str = br.readLine();
        } catch (IOException e) {
           e.printStackTrace();
        }
        return str;
        }
  
     }
}

Measured memory_bytes: 32968
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    if (to_string(i).length() % 2 == 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Cin(T, x) T x; cin >> x
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cout(x) cout << (x) << "\n"
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, vs, n, m) vector<vector<T>> vs(n, vector<T>(m))

using namespace std;
using ll = long long;

int main(void){
    Cin(int, n);
    
    int ans = n;
    For(i, n/9+1){
        int n9 = i, m = n-9*n9, c = 0;
        while(n9){
            while(n9 % 9){
                c ++;
                n9 --;
            }
            n9 /= 9;
        }
        int p6 = 279936;
        while(m > 0){
            while(p6 <= m) m -= p6, c ++;
            p6 /= 6;
        }
        ans = min(ans, c);
    }
    Cout(ans);
}


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

using namespace std;

#define ll				long long
#define pb				push_back
#define w(x)			int x; cin>>x; while(x--)
#define mp      		make_pair
#define mod     		1000000007
#define inf     		1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define endl	  		"\n"
#define sp 				" "
#define ca(x) 			"Case "<<x<<": "


int main()
{
	int ac = 0, wa = 0, tle = 0, re = 0;
	w(t)
	{
		string s;
		cin >> s;
		if (s == "AC") ac++;
		else if (s == "WA") wa++;
		else if (s == "TLE") tle++;
		else if (s == "RE") re++;
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;

	return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
using ll = long long;
vector<ll> a;
int main(){
    ll n,m,b,c,x;
    map<ll,ll> mp;
    vector<ll> a;
    cin >> n >> m;
    for(ll i=0;i<n;i++){
        cin >> x;
        mp[x]++;
        a.push_back(x);
    }
    for(ll i=0;i<m;i++){
        cin >> b >> c;
        mp[c]+=b;
        a.push_back(c);
    }
    sort(a.begin(),a.end());
    ll sum=n,ans=0;
    for(ll i=a.size()-1;sum>0;i--){
        if(mp[a[i]]>=0){
            ans+=a[i]*min(sum,mp[a[i]]);
            sum-=mp[a[i]];
            mp[a[i]]=0;
        }
    }
    cout << ans;
}

Measured memory_bytes: 14320
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    int N, K;
    cin >> N >> K;
    int p[N];
    double e[N], s[N + 1];
    s[0] = 0.0;
    for (int i = 0; i < N; i++) {
        cin >> p[i];
        e[i] = (double)(1 + p[i]) / 2.0;
        s[i + 1] = s[i] + e[i];
    }
    double ans = 0.0;
    for (int i = 1; i + K - 1 < N + 1; i++) {
        ans = max(ans, s[i + K - 1] - s[i - 1]);
    }
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
typedef long long ll;
#define len(_x) (sizeof((_x)) / sizeof(_x)[0])
#define tr(container, it) \
	for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c,x) ((c).find(x) != (c).end())   //O(log n) 
#define contains(c,x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define fastIO  ios_base::sync_with_stdio(false); cin.tie(0); 
#define Ichar(_x) char _x;scanf("%c",&_x);
#define Iint(_x) int _x;scanf("%d",&_x); 
#define Ill(_x)  ll _x;scanf("%lld",&_x);
#define inc(a,b,x)(x)>a && (x)<b	
#define incE(a,b,x)(x)>=a && (x)<=b	
#define fileIO 	freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
map<ll,int> arr;
int main(int argc, char* argv[])
{
	Iint(n)
		ll t;
	for (int i = 0; i < n; ++i)
{
		scanf("%lld", &t);
		arr[t]++;
}
	ll mi = 0;
	for(auto i=arr.begin();i!=arr.end();++i)
	{
		mi += i->second < i->first ? i->second : i->second - i->first;

	}
	
	std::cout << mi	;
}


Measured memory_bytes: 6272
local List = {}
function List.new ()
    return {first = 0, last = -1}
end

function List.pushleft (list, value)
    local first = list.first - 1
    list.first = first
    list[first] = value
end

function List.pushright (list, value)
    local last = list.last + 1
    list.last = last
    list[last] = value
end

function List.popleft (list)
    local first = list.first
    local value = list[first]
    list[first] = nil
    list.first = first + 1
    return value
end

function List.popright (list)
    local last = list.last
    local value = list[last]
    list[last] = nil
    list.last = last - 1
    return value
end

function List.empty (list)
    return list.first > list.last
end

----------

local n=io.read("n")
local graph={}
for i=1,n do
    graph[i]={}
end
for i=1,n-1 do
    local u,v,w=io.read("n","n","n")
    w=w%2
    graph[u][v]=w
    graph[v][u]=w
end

local stack=List.new()
List.pushright(stack,{1,0})
local checked={true}
local color={1}

while not List.empty(stack) do
    local pop=List.popright(stack)
    local u=pop[1]
    local w=pop[2]
    for v,_ in pairs(graph[u]) do
        local nw=w+graph[u][v]
        if not checked[v] then
            if nw%2==0 then
                color[v]=1
            else
                color[v]=0
            end
            checked[v]=true
            List.pushright(stack,{v,nw})
        end
    end
end

for i=1,n do
    print(color[i])
end

Measured memory_bytes: 32560
m,n,x,y = gets.split(/ +/).map(&:to_i)
xx = gets.split(/ +/).map(&:to_i)
yy = gets.split(/ +/).map(&:to_i)
xx<<x
yy<< y

if xx.max < yy.min
  puts "No War"
else
  puts "War"
end


Measured memory_bytes: 1788
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

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

int main(){
	int n,x,i;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x;
		if(x%2==0 and x%3 and x%5){
			cout<<"DENIED";
			return 0;
		}
	}
	cout<<"APPROVED";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n, a, b;
    cin>>n>>a>>b;

    string ans;
    if((b - a) % 2 == 0){
        ans = "Alice";
    }else{
        ans = "Borys";
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int[] l = new int[n];
    for (int i = 0; i < n; i++) {
      l[i] = scanner.nextInt();
    }
    scanner.close();
    int max = 0;
    for (int i = 0; i < n; i++) {
      if (max < l[i]) {
        max = l[i];
      }
    }
    if (n == 1) {
      System.out.println(max);
      return;
    }
    int count = 0;
    for (int i = max; i > 0; i--) {
      for (int j = 0; j < n - 1; j++) {
        if (l[j] == i) {
          if (l[j + 1] == i) {
            l[j]--;
          } else {
            l[j]--;
            count++;
          }
        }
      }
      if (l[n - 1] == i) {
        l[n - 1]--;
        count++;
      }
    }
    System.out.println(count);

  }

}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define ll long long
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;

int main() {
  INIT;
  
  int a, b,c,d;
  cin >> a >> b >> c >> d;

  if(a*b > c*d){
    cout << a*b << endl;
  }else{
    cout << c*d << endl;
  }
  return 0;
}

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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define REP(i, n) for(ll i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define pb push_back

const long long MOD = 1000000007;
const long long INF = 1LL<<60;


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

    ll x;
    cin >> x;

    for(ll a = 0; a < 10000; a++){
        for(ll b = 0; b < 10000; b++){
            ll aa = a*a*a*a*a;
            ll bb = b*b*b*b*b;
            if(aa+bb == x){
                cout << a << " " << -b << endl;
                return 0;
            }
            if(aa-bb == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3652
import time
import random


class Problem:

    def __init__(self, D, s, c):
        self.last_days = [0] * 26
        self.D = D
        self.s = s
        self.c = c

    def scoring(self, day, ind):
        day_score = self.s[day - 1][ind]
        self.last_days[ind] = day
        minus_score = 0
        for i in range(26):
            minus_score += self.c[i] * (day - self.last_days[i])
        day_score -= minus_score
        return day_score

    def _strategy(self, day):
        ind = random.randint(0, 25)
        score = self.scoring(day, ind)
        return score, ind

    def solve(self):
        answer = []
        sum_score = 0
        for i in range(self.D):
            score, ind = self._strategy(i)
            answer.append(ind)
            sum_score += score
        return sum_score, answer

    def init(self):
        self.last_days = [0] * 26


def main():
    time_start = time.time()
    DO_TIME = 2
    D = int(input())
    c = list(map(int, input().split()))
    s = []

    for _ in range(D):
        s.append(list(map(int, input().split())))

    max_score = 0
    max_answer = [1] * D
    problem = Problem(D, s, c)
    ite = 0
    while time.time() - time_start < DO_TIME * 0.9:
        ite += 1
        score, answer = problem.solve()

        if score > max_score:
            max_score = score
            max_answer = answer

    for i in range(D):
        max_answer[i] += 1
        print(max_answer[i])
    # print(ite)
    # print(max_answer)
    # print(max_score)


main()

# tmp = [1, 17, 13, 14, 13]
# sum_s = 0
# problem.init()
# for i in range(5):
#     score = problem.scoring(i + 1, tmp[i] -1 )
#     sum_s += score
#     print(last_days)
#     print(score)
#
# print(sum_s)


Measured memory_bytes: 87788
#include <bits/stdc++.h>
typedef long long ll; 
 
using namespace std;
using P = pair<ll, int>;

const int SIZE = 200005;
vector<int> par;
vector<int> r;

void init (int n) {
	par.resize(n);
	r.resize(n);
	for (int i = 0; i < n; i++) {
		par[i] = i;
		r[i] = 0;
	}
}

int find(int x) {
    if (par[x] == x) {
		return x;
    } else {
		return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (r[x] < r[y]) {
		par[x] = y;
    } else {
		par[y] = x;
		if (r[x] == r[y]) r[x]++;
    }
}

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

struct edge {int u, v; ll cost;};
bool comp(const edge&  e1, const edge& e2) {
	return e1.cost < e2.cost;
}

edge es[SIZE];
int V, E;
ll kruscal() {
	sort(es, es + E, comp);
	init(V);
	ll res = 0;
	for (int i = 0; i < E; i++) {
		edge e = es[i];
		if (!same(e.u, e.v)) {
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}


int main() {
	int N;
	cin >> N;
	vector<P> x(N);
	vector<P> y(N);
	for (int i = 0; i < N; i++) {
		ll a, b;
		cin >> a >> b;
		x[i] = P(a, i);
		y[i] = P(b, i);
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());

	E = 0;
	V = N;
	for (int i = 0; i < N - 1; i++) {
		ll a = x[i].first;
		ll b = x[i + 1].first;
		int n = x[i].second;
		int m = x[i + 1].second;

		es[E++] = (edge){n, m, b - a};
	}
	for (int i = 0; i < N - 1; i++) {
		ll a = y[i].first;
		ll b = y[i + 1].first;
		int n = y[i].second;
		int m = y[i + 1].second;

		es[E++] = (edge){n, m, b - a};
	}

	ll res = kruscal();
	cout << res << endl;

	return 0;
}


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

using namespace std;

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

    map<char,int> check;
    for(int i=0;i<n;i++){
        char s;
        cin >> s;
        check[s]++;
    }
    if(check.size()==3) cout << "Three" << endl;
    else cout << "Four" << endl;
}

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

int main(){
  
  int n;
  int m;
  int a[111];
  int b[111][111];
  int c[111]={0};

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

  for(int i=0;i<m;i++){
    for(int j=0;j<n;j++){
      scanf("%d",&b[i][j]);
      if(a[i]==b[i][j]){
	c[j]++;
      }
      else{
	c[a[i]-1]++;
      }
    }
  }

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

  return 0;
}

Measured memory_bytes: 1236
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,M=map(int,input().split())
    d=defaultdict(int)
    x=2
    while M>1:
        if M%x==0:
            d[x]+=1
            M//=x
        else:
            x+=1
    def COMinit(n,MOD):
        fac,finv,inv=[0]*max(2,n+1),[0]*max(2,n+1),[0]*max(2,n+1)
        fac[0]=fac[1]=1
        finv[0]=finv[1]=1
        inv[1]=1
        for i in range(2,(n+1)):
            fac[i]=fac[i-1]*i%MOD
            inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
            finv[i]=finv[i-1]*inv[i]%MOD
        return fac,finv,inv
    
    fac,finv,inv=COMinit(10**6,MOD)
    
    def COM(n, k, MOD=MOD):
        if n<k or n<0 or k<0:
            return 0
        return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
    
    ans=1
    for v in d.values():
        ans*=COM(N-1+v,v,MOD)
        ans%=MOD
    print(ans)

if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;

const ll INF = 1e18L + 5;

vector<ll> pre; // preprocessing
// pre[mask] - score of group 'mask'
vector<ll> dp;

void rec(int i, const vector<int>& not_taken, ll score_so_far, int mask, int group) {
    if (i == (int) not_taken.size()) {
        dp[mask] = max(dp[mask], score_so_far + pre[group]);
        return;
    }
    rec(i + 1, not_taken, score_so_far, mask, group);
    rec(i + 1, not_taken, score_so_far, mask ^ (1 << not_taken[i]),
        group ^ (1 << not_taken[i]));
}

signed main() {
    int n;
    scanf("%d", &n);
    vector<vector<ll>> in(n, vector<ll>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            scanf("%lld", &in[i][j]);
        }
    }
    pre.resize(1 << n);
    // O(2^n * n^2)
    for (int mask = 0; mask < (1 << n); mask++) {
        for(int i = 0; i < n; i++) {
            if (mask & (1 << i)) {
                for (int j = i + 1; j < n; j++) {
                    if (mask & (1 << j)) {
                        pre[mask] += in[i][j];
                    }
                }
            }
        }
    }
    // dp[mask] - best total score if we grouped rabbits from 'mask' already
    dp.resize(1 << n, -INF);
    dp[0] = 0;
    // O(2^n * n + 3^n)
    for (int mask = 0; mask < (1 << n); mask++) {
        vector<int> not_taken;
        for (int i = 0; i < n; i++) {
            if (!(mask & (1 << i))) {
                not_taken.push_back(i);
            }
        }
        rec(0, not_taken, dp[mask], mask, 0);
    }
    printf("%lld\n", dp[(1 << n) - 1]);
    return false;
}

Measured memory_bytes: 1280
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    string keys[n];
    for (int i = 0; i < n; ++i) {
        cin >> keys[i];
    }
    int m;
    cin >> m;
    bool isOpen = false;
    for (int i = 0; i < m; ++i) {
        string key;
        cin >> key;
        string result = "Unknown ";
        for (int j = 0; j < n; ++j) {
            if (keys[j] == key) {
                result = isOpen ? "Closed by " : "Opened by ";
                isOpen = !isOpen;
            }
        }
        cout << result << key << endl;
    }
}

Measured memory_bytes: 1224
#include<cstdio>
#include<algorithm>
using namespace std;
inline char tc(void){
	static char fl[10000],*A=fl,*B=fl;
	return A==B&&(B=(A=fl)+fread(fl,1,10000,stdin),A==B)?EOF:*A++;
}
inline int read(void){
	int a=0;char c;
	while((c=tc())<'0'||c>'9');
	while(c>='0'&&c<='9')a=a*10+c-'0',c=tc();
	return a;
}
int x,y,a,b,c,ans;
int main(void){
	register int i;
	a=read(),b=read(),c=read(),x=read(),y=read();
	if(c*2<=a+b){
		ans=min(x,y)*c*2;
		int t=min(x,y);
		x-=t,y-=t;
		if(x&&a>=c*2){
			ans+=c*2*x;
		}else if(x)ans+=a*x;
		if(y&&b>=c*2){
			ans+=c*2*y;
		}else if(y)ans+=b*y;
	}else{
		ans=a*x+b*y;
	}
	printf("%d",ans);
	return 0;
}
 

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

namespace AtCoder
{
    class program
    {
        static void Main(string[] args)
        {
            int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = n[0];
            int M = n[1];

            Console.WriteLine((int)Math.Pow(2, M) * (100 * (N - M) + 1900 * M));                               
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 13268
s = input()
mod = 2019
array = [0]*(len(s)+1)

for i in range(len(s)):
    array[i+1] = (array[i] + pow(10,i,mod)*int(s[len(s)-(i+1)])) % mod
    

    
array.sort()

cnt = 0
w = 1

for i in range(0, len(array)-1):
    if array[i] == array[i+1]:
        w += 1
    else:
        if w >= 2:
            cnt += w*(w-1)/2
            w = 1
            
if w != 1:
    cnt += w*(w-1)/2
    
print(int(cnt))

Measured memory_bytes: 17192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n; ll K;
    cin >> n >> K;
    VL a(n); cin >> a;


    VI k(40, 0);
    for (int j = 0; K; j++) {
        k[j] = K % 2;
        K /= 2;
    }
    reverse(all(k));

    VI bit(40, 0);
    FOR(i, 0, n) {
        for (int j = 0; a[i]; j++) {
            bit[j] += a[i] % 2;
            a[i] /= 2;
        }
    }
    reverse(all(bit));

    vector<VL> dp(41, VL(2, -1));
    dp[0][0] = 0;
    FOR(i, 0, 40)FOR(small, 0, 2) {
        if (dp[i][small] == -1)continue;
        eFOR(x, 0, (small ? 1 : k[i])) {
            ll num = (1LL << (40 - i - 1)) * (ll)(x ? n - bit[i] : bit[i]);
            chmax(dp[i + 1][small || x < k[i]], dp[i][small] + num);
        }
    }
    cout << max(dp[40][0], dp[40][1]) << "\n";
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int maxn=4e5+5;
const int inf=0x3f3f3f3f;
inline int read(){
	char c=getchar();int t=0,f=1;
	while((!isdigit(c))&&(c!=EOF)){if(c=='-')f=-1;c=getchar();}
	while((isdigit(c))&&(c!=EOF)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,s,t;
struct edge{
	int v,p,w;
}e[maxn<<1];
int h[maxn],cnt=1;
inline void add(int a,int b,int c){
	e[++cnt].p=h[a];
	e[cnt].v=b;
	e[cnt].w=c;
	h[a]=cnt;
}
int dis[maxn];
bool bfs(){
	queue<int> q;
	while(!q.empty())q.pop();
	q.push(s);
	memset(dis,0,sizeof(dis));
	dis[s]=1;
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=h[u];i;i=e[i].p){
			int v=e[i].v;
			if(e[i].w&&!dis[v]){
				dis[v]=dis[u]+1;
				q.push(v);
			}
		}
	}
	return dis[t];
}
int ht[maxn];
int dfs(int u,int rest){
	if((u==t)||rest==0)return rest;
	int tot=0;
	for(int &i=ht[u];i;i=e[i].p){
		int v=e[i].v;
		if(e[i].w&&dis[v]==dis[u]+1){
			int di=dfs(v,min(rest,e[i].w));
			e[i].w-=di;e[i^1].w+=di;
			rest-=di;tot+=di;
			if(rest==0)break;
		}
	}
	return tot;
}
int dinic(){
	int ans=0;
	while(bfs()){
		int di=0;
		for(int i=s;i<=t;i++)ht[i]=h[i];
		while(di=dfs(s,inf))ans+=di;
	}
	return ans;
}
int cho[maxn];
vector<int> g[maxn];
typedef pair<int,int> pii;
pii res[maxn];
bool get(){
	for(int u=1;u<n;u++){
		for(int i=h[u];i;i=e[i].p){
			int v=e[i].v;
			if(v!=s&&(e[i].w==0)){cho[v-n]=u;}
		}
	}
	queue<int> q;
	while(!q.empty())q.pop();
	q.push(n);int sum=0;
	while(!q.empty()){
		int u=q.front();q.pop();sum++;
		for(int i=0;i<g[u].size();i++){
			int v=g[u][i];
			if(cho[v])res[v]=pii(u,cho[v]),q.push(cho[v]),cho[v]=0;
		}
	}
	return sum==n;
}
signed main(){
	n=read();s=0,t=n+n;
	for(int i=1;i<n;i++){
		int k=read();
		for(int j=1;j<=k;j++){
			int x=read();
			add(x,i+n,1);
			add(i+n,x,0);
			g[x].push_back(i);
		}
		add(s,i,1);
		add(i,s,0);
		add(i+n,t,1);
		add(t,i+n,0);
	}
	if(dinic()<n-1){puts("-1");return 0;}
	if(!get()){puts("-1");return 0;}
	for(int i=1;i<n;i++)
	printf("%d %d\n",res[i].first,res[i].second);
	return 0;
}


Measured memory_bytes: 33044
using System;

namespace ABC026A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);


            if (a==b && a==c)
                Console.WriteLine('1');
            else if (a==b && a!=c || a==c && a!=b || b==c && b!=a)
                Console.WriteLine('2');
            else
                Console.WriteLine("3");

            Console.ReadKey();
        }
    }
}

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

int m = 0, cnt = 0, G[100];

void shellSort(int a[], int n) {
	int i, j;
	cnt = 0;
	G[0] = 1;
	while (1) {
		G[m + 1] = 3 * G[m] + 1;
		if (G[m + 1] >= n)break;
		else m++;
	}
	m++;
	for (i = m - 1; i >= 0; i--) {
		int k, j, tmp;
		for (k = G[i]; k < n; k++) {
			tmp = a[k];
			j = k - G[i];
			while (j >= 0 && a[j] > tmp) {
				a[j + G[i]] = a[j];
				j -= G[i];
				cnt++;
			}
			a[j + G[i]] = tmp;
		}
	}
}


int main() {
	int i, j, n, a[1000000];
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	shellSort(a, n);
	printf("%d\n", m);
	for (i = m - 1; i >= 0; i--) {
		printf("%d", G[i]);
		if (i != 0)printf(" ");
		else printf("\n");
	}

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

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

	return 0;
}

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

typedef long long LL;
const int N = 310;
const int Mod = 1e9 + 7;
int n, m, f[N][N][N];

inline int dec(int x) {return x < 0 ? x + Mod : x;}
inline int inc(int x) {return x >= Mod ? x - Mod : x;}

int main() {
	cin >> n >> m;
	f[0][1][1] = 1;
	for (int i = 0; i < m; ++i)
		for (int j = 1; j <= i + 1 && j <= n; ++j)
			for (int k = 0; k <= j; ++k) if (f[i][j][k]) {
				f[i + 1][j + 1][k] = inc(f[i + 1][j + 1][k] + 1LL * f[i][j][k] * (n - j) % Mod);
				f[i + 1][j][k] = inc(f[i + 1][j][k] + 1LL * f[i][j][k] * (j - k) % Mod);
				f[i + 1][j][j] = inc(f[i + 1][j][j] + 1LL * f[i][j][k] * k % Mod);
			}
	cout << f[m][n][n];
	return 0;
}

Measured memory_bytes: 112896
#include<stdio.h>
#include<algorithm>
#include<functional>
int power(int x, int n)
{
	int power = 1;
	for (int i = 0; i < n; i++) {
		power *= x;
	}
	return power;
}
using namespace std;
int main()
{
	int a, b, tmp, L = 0, num;
	scanf("%d%d", &a, &b);
	tmp = b;
	while (tmp > 0) {
		L++;
		tmp /= 10;
	}
	num = a * power(10, L) + b;
	int i = 1;
	while (power(i, 2) <= num) {
		if (num == power(i, 2)) {
			printf("Yes");
			return 0;
		}
		i++;
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define deb(x) cout<<#x<<" "<<x<<endl;
#define print(arr,n) for(int i=0;i<n;++i) { cout<<arr[i]<<" "; } cout<<endl;
#define ub(x,el) upper_bound(x.begin(),x.end(),el) - x.begin()
#define lb(x,el) lower_bound(x.begin(),x.end(),el) - x.begin();
#define bs(x,el) binary_search(x.begin(),x.end(),el)
#define MOD 1000000007
#define finish return 0
using namespace std;
using namespace __gnu_pbds; 
typedef long long int ll;
typedef tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template<typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) { }}; template<typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, T val = T()) : vector<T>(n, val) { } };
inline ll mod(ll x) { return (x%MOD + MOD)%MOD; }
ll gcd(ll a, ll b, ll &x, ll &y){if(a == 0){x = 0, y = 1; return b;} ll x1, y1;  ll d = gcd(b%a, a, x1, y1); x = y1 - (b/a) * x1; y = x1; return d;}
ll power(ll x,ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;   } return res; } 
ll power(ll x,ll y) { ll res = 1; while (y > 0) { if (y & 1) res = (res*x); y = y>>1; x = (x*x);   } return res; } 
ll mod(ll num, ll den){ return mod(mod(num) * power(den,MOD-2,MOD)); }
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll x;
	cin>>x;
	vector<ll> arr;
	map<ll,ll> mp;
	for(ll i=0;;++i)
	{
		ll well = power(i,5);
		
		if(well > (1e+18)) break;
		arr.push_back(well);
		mp[well] = i;
		mp[-1*well] = -i;
		
	}
	ll n = arr.size();
	for(ll i=1;i<n;++i) arr.push_back(-1*arr[i]);
	sort(arr.begin(),arr.end());
	for(ll i=0;i<arr.size();++i)
	{
		if(bs(arr,arr[i]+x))
		{
	//		cout<<arr[i]<<" "<<arr[i]+x<<endl;
			cout<<mp[arr[i]+x]<<" "<<mp[arr[i]]<<endl;
			break;

		}
	}
}

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

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

	vector<int> HP(N, 0);

	vector<int> A(Q);
	for (int i = 0; i < Q; i++) {
		cin >> A[i];
		A[i]--;
		HP[A[i]]++;
	}

	for (int i = 0; i < N; i++) {
		if ((K - Q + HP[i]) > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}


Measured memory_bytes: 1408
def make_somites(i, a)
    new_somites = a.dup
    if new_somites[i] != "r" && new_somites[i+1] != "r"
      new_somites[i] = "r"
      new_somites[i+1] = "r"
    elsif new_somites[i] != "b" && new_somites[i+1] != "b"
      new_somites[i] = "b"
      new_somites[i+1] = "b"
    else new_somites[i] != "g" && new_somites[i+1] != "g"
      new_somites[i] = "g"
      new_somites[i+1] = "g"
    end
    return new_somites
end

loop do
  insect = gets.chomp
  break if insect == "0"

  queue = []
  time = {count: 0}
  queue << [insect, time[:count]]
  len_insect = insect.length
  found = false

  # 過去に作られたwormであるかの判定、何度も出る場合は全てが同じ色になることはないのでNAを出力する
  reached = {a: true}

  loop do
    next_queue = []
    until queue.empty?
      target_somites = queue.shift
      if target_somites[0].split("").uniq.length == 1
        next_queue = []
        found = true
        break
      end

      (0..len_insect-2).each do |i|
        if target_somites[0][i] != target_somites[0][i+1]
          a = target_somites[0].dup
          new_somites = make_somites(i, a)
          next if reached[new_somites]
          reached[new_somites] = true
          next_queue << [new_somites, target_somites[1]+1]
        end
      end
    end
    
    if next_queue.empty?
      puts found ? target_somites[1] : "NA"
      break
    end
    queue = next_queue
  end
end



Measured memory_bytes: 7860