akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#include <map>
/* All our base are belong to AC */
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<int,int>;
const ll M = 1e9+7;
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;};
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}

int main() {
  int n; cin>>n;
  cout<<n+n*n+n*n*n<<endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
	int a,b;
  	cin>>a>>b;
  if(a>8||b>8)cout<<":("<<endl;
  else cout<<"Yay!"<<endl;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
l = sorted(filter(lambda x:x[1] > 1,c.items()),reverse=True)

if len(l) == 0:
  print(0)
else:
  if l[0][1] >= 4:
    print(l[0][0]**2)
  else:
    print(l[0][0]*l[1][0])

Measured memory_bytes: 18600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		int [] A = new int[N];
		String [] str = br.readLine().split(" ");
		for(int i = 0;i < str.length;i++){
			A[i] = Integer.parseInt(str[i]);
		}
		insertionSort(A,N);
	}

	public static void insertionSort(int[] A,int N){
		show(A);
		for(int i=1; i<N;i++){
			int v = A[i];
			int j = i-1;
			while(j>=0 && A[j] > v){
				A[j+1] = A[j];
				j--;
			}
			A[j+1] = v;
			show(A);
		}
	}

	public static void show(int []A){
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < A.length;i++){
			sb.append(A[i]);
			if(i != A.length-1) sb.append(" ");
		}
		System.out.println(sb.toString());
	}

}

Measured memory_bytes: 27028
#include<iostream>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define ck(a,b) (0<=a&&a<b)
using namespace std;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int w,h,c[4],s[30][30],cost[30][30][4];
struct S{
	int y,x,d,c;
	bool operator<(const S &a)const{
		return c>a.c;
	}
};
int main(){
	while(cin>>w>>h,w){
		rep(i,h)rep(j,w){
			rep(k,4)cost[i][j][k]=INF;
			cin>>s[i][j];
		}
		rep(i,4)cin>>c[i]; cost[0][0][0]=0;
		priority_queue<S> Q;
		S cs,ns; cs.y=cs.x=cs.d=cs.c=0; Q.push(cs);
		while(!Q.empty()){
			cs=Q.top(),Q.pop();
			if(cs.y==h-1&&cs.x==w-1){
				cout<<cs.c<<endl; break;
			}
			rep(r,4){
				ns.d=cs.d+r&3,ns.y=cs.y+dy[ns.d],ns.x=cs.x+dx[ns.d],
				ns.c=cs.c+(r==s[cs.y][cs.x]?0:c[r]);
				if(ck(ns.y,h)&&ck(ns.x,w)&&cost[ns.y][ns.x][ns.d]>ns.c)
				cost[ns.y][ns.x][ns.d]=ns.c,Q.push(ns);
			}
		}
		
	}
	return 0;
}

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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int b = 0; b < 60; b++) {
        int bit = ((int)1 << b);
        int cnt = 0;
		for (int i = 0; i < N; i++) {
            if(A[i] & bit){
                cnt++;
            }
		}
        res += ((((bit % MOD) * cnt) % MOD) * (N - cnt)) % MOD;
        res %= MOD;
	}
	cout << res << endl;
}

Measured memory_bytes: 2560
n=int(input())
mod=10**9+7
memo=[{} for i in range(n+1)]
def ok(last4):
  for i in range(4):
    tmp=list(last4)
    if i>=1:
      tmp[i-1],tmp[i]=tmp[i],tmp[i-1]
    if ''.join(tmp).count('AGC')>=1:
      return False
  return True
def dfs(cur,last3):
  if last3 in memo[cur]:
    return memo[cur][last3]
  if cur==n:
    return 1
  ret=0
  for c in 'ACGT':
    if ok(last3+c):
      ret=(ret+dfs(cur+1,last3[1:]+c))%mod
  memo[cur][last3]=ret
  return ret
print(dfs(0,'TTT'))

Measured memory_bytes: 3872
while True:
  n=int(input())
  if n==0:
    break
  count=0
  for i in range(1,n):
    goukei=0
    for j in range(i,n):
      goukei+=j
      #print(goukei)
      if goukei==n:
        count+=1
        break
      if goukei>n:
        break

  print(count)


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

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

  vector<int> L(N);

  for(int i = 0; i < N; i++) cin >> L[i];

  int sum = 0;
  for(int i = 0; i < N; i++){
    sum += L[i];
  }

  sort(L.begin(),L.end());

  if(L[N - 1] < sum - L[N - 1]) cout << "Yes";
  else cout << "No";

  
  return 0;
}

Measured memory_bytes: 384
rect = 0
dia = 0
while True:
  try:
    a,b,c = map(int,input().split(","))
  except EOFError:
    print(rect)
    print(dia)
    break
  if (a**2+b**2 == c**2):
    rect += 1
  elif (a == b):
    dia += 1


Measured memory_bytes: 5600
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
 
using namespace std;
 
typedef long long ll;

const int N = 2e5 + 7;

vector <pair <int, int>> g[N];

ll val[N];
bool used[N];

vector <int> cmp;

bool ok = true;

void dfs(int u) {
  cmp.push_back(u);
  used[u] = true;
  for (auto pr : g[u]) {
    int v = pr.first, w = pr.second;
    if (!used[v]) {
      val[v] = w - val[u];
      dfs(v);
    } else if (val[v] != w - val[u]) {
      ok = false;
    }
  }
} 
 
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n, m;
  cin >> n >> m;
  int k;
  cin >> k;
  for (int i = 0; i < k; ++i) {
    int r, c, x;
    cin >> r >> c >> x;
    --r, --c;
    g[r].push_back({n + c, x});
    g[n + c].push_back({r, x});
  }
  for (int i = 0; i < n + m; ++i) {
    if (!used[i]) {
      cmp.clear();
      dfs(i);
      ll ml = 1e18, mr = 1e18;
      for (int v : cmp) {
        if (v < n) {
          ml = min(ml, val[v]);
        } else {
          mr = min(mr, val[v]);
        }
      }
      ok &= (ml + mr >= 0);
    }
  }
  cout << (ok ? "Yes" : "No") << '\n';
}



Measured memory_bytes: 15096
n,t = map(int, input().split())
y = 10**5
c = [list(map(int,input().split())) for i in range(n)]
for i in range(n):
    if c[i][1]<=t:
        y=min(y,c[i][0])
if y != 10**5:
    print(y)
else:
    print("TLE")

Measured memory_bytes: 9128
from collections import Counter

n = int(input())
counter_a = Counter(map(int, input().split()))
maxCnt = 0
for key, value in counter_a.items():
    cnt = counter_a[key-1] + counter_a[key] + counter_a[key+1]
    maxCnt = max(maxCnt, cnt)
print(maxCnt)

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



i64 n, m, a[101010], b[101010];
i64 ans[101010];
//union-find
struct UnionFind {
	vector<int> par, depth, sz;
	UnionFind(int n) : par(n+1), depth(n+1), sz(n+1){
		for(int i = 0; i <= n; i++){
			par[i] = i;
			depth[i] = 0;
			sz[i] = 1;
		}
	}
	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;
		sz[x] += sz[y];
		sz[y] = sz[x];
		if(depth[x] < depth[y]){
			par[x] = y;
		}
		else{
			par[y] = x;
			if(depth[x] == depth[y]) depth[x]++;
		}
	}
	bool same(int x, int y){
		return find(x) == find(y);
	}
	int size(int x){
		return sz[find(x)];
	}
};
////
void solve(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}
	UnionFind uf(n);
	ans[m] = n*(n-1)/2;
	for(int i = m-1; i > 0; i--){
		if(uf.same(a[i],b[i])){
			ans[i] = ans[i+1];
			continue;
		}
		ans[i] = ans[i+1]-(uf.size(a[i])*uf.size(b[i]));
		uf.unite(a[i],b[i]);
	}
	for(int i = 1; i <= m; i++){
		cout << ans[i] << endl;
	}
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 4864
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> p(N);
    rep(i,N) {
        cin >> p[i];
        --p[i];
    }

    vector<int> seen(N);
    int c = 0;
    while (!seen[c]) {
        seen[c] = 1;
        c = p[c];
    }
    set<int> circle;
    while (!circle.count(c)) {
        circle.emplace(c);
        c = p[c];
    }
    if (~(int)circle.size()&1) {
        cout << "POSSIBLE" << ln;
        return 0;
    }
    vector<vector<int>> G(N);
    rep(i,N) {
        if (circle.count(i)) continue;
        G[p[i]].emplace_back(i);
    }
    auto dfs=[&](auto&& self, int v)->int {
        for (auto nv : G[v]) {
            if (self(self,nv)==0) return 1;
        }
        return 0;
    };
    int cnt = 0;
    for (auto c : circle) {
        cnt += dfs(dfs,c);
    }

    cout << ((cnt==0 or cnt==(int)circle.size()) ? "IMPOSSIBLE" : "POSSIBLE") << ln;
}


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

int left(int i){ return i*2; }

int right(int i){ return i*2 + 1; }

int parent(int i){ return i/2; }

int main(void){
  int i,n;
  int *Heap;


  // input and alloc
  scanf("%d",&n);
  Heap = (int *)malloc(sizeof(int) * n+1);
  for(i=1; i<=n; i++) scanf("%d ",&Heap[i]);

  // output
  for(i=1; i<=n; i++) {
    printf("node %d: key = %d, ", i, Heap[i]);
    if(i != 1) printf("parent key = %d, ", Heap[parent(i)]);
    if(left(i) <= n) printf("left key = %d, ", Heap[left(i)]);
    if(right(i) <= n) printf("right key = %d, ", Heap[right(i)]);
    printf("\n");
  }

  free(Heap);

  return 0;
}

Measured memory_bytes: 604
N, K = map(int, input().split())

h = [0] * N
for i in range(N):
    h[i] = int(input())

h.sort()

value = h[N-1]
for i in range(N-K+1):
    value = min(value, h[i+K-1] - h[i])

print(value)

Measured memory_bytes: 7472
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <bitset>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

// union find
class union_find {
public:
    int n;
    vector<int> parent, rnk, num;
    
    union_find(int n) : n(n), parent(n), rnk(n, 0), num(n, 1) {rep(i, n) parent[i] = i; }
    
    int root(int x){ return (parent[x] == x) ? x : root(parent[x]); }
    
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if (x == y) {
            return;
        }
        if (rnk[x] < rnk[y]) {
            parent[x] = y;
            num[y] += num[x];
        }
        else{
            parent[y] = x;
            num[x] += num[y];
            if (rnk[x] == rnk[y]) {
                rnk[x]++;
            }
        }
        n--;
    }
    
    bool same(int x, int y) {return root(x) == root(y);}
    
    int count(int x){ return num[root(x)]; }
};
const int MAX_N = 150020;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int N, R;
    cin >> N >> R;
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
        A[i]--;
    }
    union_find uf(N);
    rep(i, N) uf.unite(A[i], A[A[i]]);
    vector<int> used(N, 0);
    vector<int> B;
    rep(i, N) {
        int root = uf.root(i);
        if (used[root]) {
            continue;
        }
        used[root] = true;
        B.pb(uf.count(root));
    }
    bitset<MAX_N> C(1);
    rep(i, B.size()){
        C |= (C << B[i]);
    }
    
    if(C.test(min(R, N - R)) == 1) {
        output("Yes");
    }
    else {
        output("No");
    }
    
    
    
    
    return 0;
}



Measured memory_bytes: 10592
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n,m;cin>>n>>m;
    vector<char>match(8);
    rep(i,m){
        char a;cin>>a;
        if(a=='1')match[2]='1';
        if(a=='2')match[5]=max(match[5],'2');
        if(a=='3')match[5]=max(match[5],'3');
        if(a=='4')match[4]='4';
        if(a=='5')match[5]=max(match[5],'5');
        if(a=='6')match[6]=max(match[6],'6');
        if(a=='7')match[3]='7';
        if(a=='8')match[7]='8';
        if(a=='9')match[6]=max(match[6],'9');
    }
    vector<string>dp(10010);
    REP(i,1,n+1){
        rep(j,8){
            if(match[j]){
                if(i-j>=0){
                    if(dp[i-j].size()>0||i-j==0){
                    string a="";
                    a+=match[j];
                    a+=dp[i-j];
                    if(a.size()>dp[i].size())dp[i]=a;
                    if(a.size()==dp[i].size()&&dp[i]<a)dp[i]=a;
                    }
                }
            }
        }
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 32384
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <complex>
#include <cmath>
#define rep(i,a) for(int i=0;i<(a);++i)

using Pt = std::complex<double>;

double x[3], y[3];
double a[3], ma, r;

double sqr( double x )
{ return x*x; }

bool C( double x )
{ return (1-x/r)*ma >= 2*x; }

double cross( const Pt &c1, const Pt &c2 )
{ return std::imag( c1*std::conj(c2) ); }

int main()
{
  rep( i, 3 )
    std::cin >> x[i] >> y[i];

  rep( i, 3 )
  {
    a[i] = sqrt(sqr(x[(i+1)%3]-x[i])+sqr(y[(i+1)%3]-y[i]));
    ma = std::max( ma, a[i] );
  }

  r = fabs(cross( Pt( x[1]-x[0], y[1]-y[0] ), Pt( x[2]-x[0], y[2]-y[0] ) ))/(a[0]+a[1]+a[2]);

  double lb = 0, ub = 1e6;

  rep( i, 1000000 )
  {
    double mid = (lb+ub)/2;

    if( C(mid) )
      lb = mid;
    else
      ub = mid;
  }

  std::cout << std::fixed << std::setprecision(12) << lb << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
// long long -> lint
using lint = long long;
// fast cin and cout from hitonanode-san's code
// w/o 71 ms -> w/ 18 ms (tested on ABC148-D with C++14(GCC 5.4.1))
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

int main(){
    // input
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    for( int i=0; i<N; i++ ){
        B[i] = 0;
        if( i > 0){
            cin >> A[i];
        }else{
            A[i] = 0;
        }
    }

    //
    for( int i=1; i<N; i++ ){
        B[A[i]-1] += 1;
    }

    // out
    for( int i=0; i<N; i++ ){
        cout << B[i] << endl;
    }
} 

Measured memory_bytes: 4744
#include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main(){
    int person, winNum, percent;
    int vote[1005], sumMoney;
    while(cin >> person >> winNum >> percent, person || winNum || percent){
        percent = 100 - percent;
        sumMoney = 0;
        range(i, 1, person + 1){
            cin >> vote[i];
            sumMoney+= vote[i] * 100;
        }
        if(vote[winNum] != 0)
            cout << (sumMoney * percent / 100) / vote[winNum] << endl;
        else
            cout << 0 << endl;
    }
}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

using namespace std;

const int INF = numeric_limits<int>::max() / 2;

int main(){
    int a,b,t;
    cin >> a >> b >> t;
    cout << b * (t / a) << endl;
}

Measured memory_bytes: 256
n = int(input())
dp = [[0]*3 for _ in range(n+1)]
for i in range(n):
  a,b,c = map(int, input().split())
  dp[i+1][0] = a + max(dp[i][1], dp[i][2])
  dp[i+1][1] = b + max(dp[i][0], dp[i][2])
  dp[i+1][2] = c + max(dp[i][1], dp[i][0])
print(max(dp[n]))

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

#define REP(i, x) for (int i = 0, i##_len = (int)(x); i < i##_len; i++)
#define REP1(i, x) for (int i = 1, i##_len = (int)(x); i <= i##_len; i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 9;
using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using l_l = pair<ll, ll>;
using d_d = pair<double, double>;
using vint = vector<int>;
using vll = vector<ll>;
using vbool = vector<bool>;

int main() {
    string s;
    cin >> s;
    REP(i, s.size() - 1) {
        if (s[i] == s[i + 1]) {
            cout << i + 1 << " " << i + 2;
            return 0;
        }
    }
    REP(i, s.size() - 2) {
        if (s[i] == s[i + 2]) {
            cout << i + 1 << " " << i + 3;
            return 0;
        }
    }
    cout << "-1 -1";
}

Measured memory_bytes: 512
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn put(map: &Vec<Vec<bool>>, r: usize, c: usize) -> Vec<Vec<bool>> {
    let mut cln = map.clone();

    for i in 0..8 {
        cln[i][c] = true;
    }
    for j in 0..8 {
        cln[r][j] = true;
        if j <= r + c && r + c < j + 8 {
            cln[r + c - j][j] = true;
        }
        if c <= r + j && r + j < c + 8 {
            cln[r + j - c][j] = true;
        }
    }
    cln
}

fn solve(map: &Vec<Vec<bool>>, v: &mut Vec<Vec<usize>>, cnt: u32) -> bool {
    if cnt == 8 {
        return true;
    }
    for i in 0..8 {
        for j in 0..8 {
            if !map[i][j] {
                let cln = put(&map, i, j);
                let result = solve(&cln, v, cnt + 1);
                if result {
                    v.push(vec![i, j]);
                    return true;
                }
            }
        }
    }
    false
}

fn main() {
    let k: u32 = read();
    let mut v: Vec<Vec<usize>> = read_vec2(k);
    let mut map: Vec<Vec<bool>> = vec![vec![false; 8]; 8];
    for rc in &v {
        map = put(&map, rc[0], rc[1]);
    }
    solve(&map, &mut v, k);

    let mut ans: Vec<Vec<char>> = vec![vec!['.'; 8]; 8];
    for p in v {
        ans[p[0]][p[1]] = 'Q';
    }
    for a in ans {
        for b in a {
            print!("{}", b);
        }
        println!("");
    }
}



Measured memory_bytes: 5056
import java.io.*;
import java.util.*;

/*
 * To execute Java, please define "static void main" on a class
 * named Solution.
 *
 * If you need more classes, simply define them inline.
 */

public class Main {
  public int solve(int n, int a, int b) {
    return Math.min(n*a, b);  
  }
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    System.out.println(new Main().solve(n,a,b));
  }
}


Measured memory_bytes: 21072
#include <stdio.h>

int main() {
  long long int N, x, ans = 0, left, right, sum;
  scanf("%lld%lld", &N, &x);
  long long int a[N];
  for (int i = 0; i < N; i++)
    scanf("%lld", &a[i]);
  left = a[0];
  for (int i = 1; i < N; i++) {
    right = a[i];
    sum = left + right;
    if (sum > x) {
      if (left > x) {
        right = 0;
        left = x;
      } else {
        right -= sum - x;
      }
      ans += sum - x;
    }
    left = right;
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 896
import java.util.Scanner;

public class Main {
	static Scanner src = new Scanner(System.in);
	public static void main(String[] args) {
		String str1 = src.next();
		String str2 = src.next();
		if(str2.substring(0, str2.length() - 1).equals(str1)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 35680
N, M = map(int, input().split())
ab = []
for _ in range(M):
    a, b = map(int, input().split())
    ab.append((a,b))

# bの昇順でsort
ab.sort(key=lambda inv: inv[1])   


count = 0
while(0 < len(ab)):
    count += 1
    cutb = ab[0][1]
    # cutbで除外できる闘争を除外する
    remove_index = 0
    for i in range(len(ab)):
        a, b = ab[i]
        if a <= cutb - 1 and cutb <= b:
            remove_index = i
        else:
            break

    ab = ab[remove_index+1:]

print(count)


Measured memory_bytes: 18208
#include <bits/stdc++.h>
#include <set>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 998244353;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou(bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<int> hukasa;
  vector<int> kazu;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    kazu = vector<int>(n,1);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
      kazu.at(rx) += kazu.at(ry);
    }
    else{
      par.at(rx) = ry;
      kazu.at(ry) += kazu.at(rx);
    }
  }
  void newkazu(){
    int n = kazu.size();
    for(int i=0;i<n;i++){
      kazu.at(i) = kazu.at(root(i));
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
int main(){
  long long n;
  cin >> n;
  vector<long long> yakusu;
  for(long long i=2;i*i<=n;i++){
    if(n % i == 0){
      yakusu.push_back(i);
      if(i*i != n)yakusu.push_back(n/i);
    }
  }
  vector<long long> yakusu2;
  for(long long i=2;i*i<=n-1;i++){
    if((n-1) % i == 0){
      yakusu2.push_back(i);
      if(i*i != n-1)yakusu.push_back((n-1)/i);
    }
  }
  if(n>2)yakusu2.push_back(n-1);
  yakusu.push_back(n);
  long long ans = yakusu2.size();
  for(long long i:yakusu){
    long long tmp = n;
    while(tmp % i == 0)tmp /= i;
    if(tmp % i == 1)ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3672
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
using namespace std;

const double pi=4*atan(1.0);

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

	int Num=b-a+1;

	if(a>0){
		cout<<"Positive"<<endl;
	}
	else if(a==0){
		cout<<"Zero"<<endl;
	}
	else{
		if(b>=0){
			cout<<"Zero"<<endl;
		}
		else{
			if(Num%2){
				cout<<"Negative"<<endl;
			}
			else{
				cout<<"Positive"<<endl;
			}
		}
	}

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

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

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

int main() {
	ll N;string  s; cin >> N >> s;

	ll mx = -1;
	for(int c = 0; c <= N-2;c++){
		map<char, int> p1, p2;

		for (int i = 0; i <= c; i++) p1[s[i]] = 1;
		for (int i = N - 1; i > c; i--)p2[s[i]] = 1;

		ll cnt = 0;
		for (int i = 0; i < N; i++) {
			if (p1[s[i]] == 1 && p2[s[i]] == 1) {
				p1[s[i]] = 0;
				p2[s[i]] = 0;
				cnt++;
			}
		}

		mx = max(mx, cnt);
	}

	cout << mx << endl;
}

Measured memory_bytes: 256
#include<cstdio>
using ll = long long;
using ull = unsigned long long;
const static int MAX_N = 100000;

unsigned par[MAX_N], rank[MAX_N], group_size[MAX_N];

void Init_union_find(unsigned n){
	for (unsigned i = 0; i < n; ++i){
		par[i] = i;
		rank[i] = 0;
		group_size[i] = 1;
	}
}

unsigned Find(unsigned x){
	if(par[x] == x) return x;
	else return par[x] = Find(par[x]);
}

void Unite(unsigned x, unsigned y){
	x = Find(x);
	y = Find(y);
	if(x == y) return;
	if(rank[x] < rank[y]){
		par[x] = y;
		group_size[y] += group_size[x];
	}else{
		par[y] = x;
		group_size[x] += group_size[y];
		if(rank[x] == rank[y]) rank[x]++;
	}
}

bool Same(unsigned x, unsigned y){
	return Find(x) == Find(y);
}

int main(){
    ull N, M;
    scanf("%llu %llu", &N, &M);
    unsigned A[M], B[M];
    for(unsigned i = 0; i < M; ++i){
        scanf("%u %u", A + i, B + i);
        A[i]--;B[i]--;
    }
    ull inconvenience[M];
    inconvenience[M-1] = N*(N - 1) >> 1;
    Init_union_find(N);
    for (int i = M - 2; i >= 0; i--){
        inconvenience[i] = inconvenience[i+1];
        if(!Same(A[i+1], B[i+1])){
            inconvenience[i] -= group_size[Find(A[i+1])]*group_size[Find(B[i+1])];
            Unite(A[i+1], B[i+1]);
        }
    }
    for (size_t i = 0; i < M; i++){
        printf("%llu\n", inconvenience[i]);
    }
	return 0;
}

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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;

int main(){
  string S,ans;
  ans = "Yes";
  cin>>S;
  if(S.at(0)==S.at(1)&&S.at(0)==S.at(2))ans = "No";

  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;



public class Main{


	public static void main(String[] args){

		Scanner scan=new Scanner(System.in);

		while(true){
		int n=scan.nextInt();
		int x=scan.nextInt();

		if(n==0&&x==0)break;

		System.out.println(return_num(n,x));

		}

		scan.close();
	}

	public static int return_num(int n, int x){
		int num=0;

		for(int i=1;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				for(int k=j+1;k<n+1;k++){
					if(i+j+k==x)num++;
				}
			}
		}


	return num;
			}


}

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


int main() {
  int N;
  long long result;
  scanf ("%d", &N);
  
  result = N;
  result = result * (result-1) / 2;
  
  
  printf("%lld", result);
  return 0;
}




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

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

    long long ans = 0;
    for(int i=0;i<N-K;i++){
        ans += H.at(i);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		int retu[26] ={0};
		for (int i = 0; i < n; i++) {
			cin >> retu[i];
		}
		int oha = 32;
		bool hantei = true;
		int j = 0;
		while (oha > 0) {
			if (hantei) {
				oha -= (oha-1)%5;
				hantei = false;
			} else {
				oha -= retu[j];
				j++;
				if (j >= n) {
					j = 0;
				}
				hantei = true;
				if (oha < 0) {
					oha = 0;
				}
			}
			cout << oha << endl;
		}
	}
	return 0;
}

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

int main(){
 char c,c2,c3;
 int n;
 int cnt[26]={0};

 while (cin>>c){
  c2=tolower(c);
  n=c2-'a';
  cnt[n]++;
 }
 for(int i=0;i<26;i++){
  c3='a'+i;
  cout << c3 << " : " << cnt[i] << endl;
 }

 return 0;
}

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

int main()
{
  int j,v,n;
  cin>>n;
  int num[n];
  for(int i=0;i<n;i++)
  {
    cin >> num[i];
  }

  for(int i = 0;i <n-1;i++)
  {
    cout<<num[i]<<" ";
  }
  cout << num[n-1] << endl;

  for (int i = 1; i < n; i++) {
      v = num[i];
      j = i - 1;
      while(j >= 0 && num[j] > v)
      {
      num[j+1] = num[j];
      j--;
      }
  num[j+1] = v;

  for(int i = 0;i < n-1;i++)
  {
    cout<<num[i]<<" ";
  }
  cout << num[n-1] << endl;
  }

}

Measured memory_bytes: 1164
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
#include<list>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n,ll mod = MOD){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%mod;
        }
        x = (x*x)%mod;
        n >>= 1;
    }
    return ret;
}

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

ll twoPow(ll shiftNum){
    return (1LL << (shiftNum - 1));
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll n;
    cin >> n;

    vector<double> v(n);

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

    priority_queue<double,vector<double>,greater<double>> pq;

    for(int i = 0; i < n; i++){
        pq.push(v[i]);
    }

    while(pq.size() > 1){
        double a,b;
        a = pq.top();pq.pop();
        b = pq.top();pq.pop();
        pq.push((a+b)/2);
    }

    cout << pq.top() << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        string S = Console.ReadLine();
        char[] charS = S.ToCharArray();
        bool ans = false;
        for(int i = 1; i < 4; i++)
        {
            if(charS[0] == charS[i])
            {
                if(i == 3)
                {
                    if (charS[1] == charS[2] && charS[0] != charS[1])
                    {
                        ans = true;
                        break;
                    }
                }
                else if(i == 2)
                {
                    if(charS[1] == charS[3] && charS[0] != charS[1])
                    {
                        ans = true;
                        break;
                    }
                }
                else if(i == 1)
                {
                    if(charS[2] == charS[3] && charS[0] != charS[2])
                    {
                        ans = true;
                        break;
                    }
                }
            }
        }
        if (ans)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD = 1000000007;
ll cnt =0,ans=0;
const int MAX = 510000;

int main (){
     ll n;     cin >> n;
     ll x[n] , y[n],xl[n],yl[n];
     ll maxx=-INF,minx=INF,maxy=-INF,miny=INF;
     for(int i=0;i<n;i++){
          cin >> x[i] >> y[i];
          xl[i] = x[i] + y[i] ;
          yl[i] = x[i] - y[i] ;

     }

     for(int i=0;i<n;i++){
          maxx = max(maxx,xl[i]);
          minx = min(minx,xl[i]);
          maxy = max(maxy,yl[i]);
          miny = min(miny,yl[i]);
     }
     
     ans = max(maxx-minx,maxy-miny);
     cout << ans << endl;



}

Measured memory_bytes: 9840
#include<bits/stdc++.h>
using namespace std;
map<int,int> m;
vector<int> v;
int main()
{
    int n,ans;
    cin>>n;
    for(int i=1;i<=n;++i){
        int x;
        cin>>x;
        if(m[x]==0) v.push_back(x);
        ++m[x];
    }
    for(int i=0;i<v.size();++i) if(m[v[i]]>=v[i]) ans+=m[v[i]]-v[i]; else ans+=m[v[i]];
    cout<<ans;
    return 0;
}

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

#define min(a, b) (((a) < (b)) ? (a) : (b))

#define INIT_CAP 10

typedef struct {
	int *to, cap, size;
} AdjList;

typedef struct {
	char name[11];
	int cost;
} Rec;

int n;
AdjList adj[5000];
Rec ing[5000];

void init(int n) {
	int i;
	for (i = 0; i < n; i++) {
		adj[i].to = malloc(sizeof(int) * INIT_CAP);
		adj[i].cap = INIT_CAP;
		adj[i].size = 0;
	}
}

void add(int from, int to) {
	if (adj[from].size == adj[from].cap) {
		adj[from].cap <<= 1;
		adj[from].to = realloc(adj[from].to, sizeof(int) * adj[from].cap);
	}
	adj[from].to[adj[from].size++] = to;
}

int searchIdx(char str[]) {
	int i;

	for (i = 0; i < n; i++)
		if (!strcmp(str, ing[i].name))
			break;

	return i;
}

int min, visited[5000];

void dfs(int i) {
	int j;

	visited[i] = 1;
	min = min(min, ing[i].cost);

	for (j = 0; j < adj[i].size; j++) {
		int to = adj[i].to[j];
		if (!visited[to])
			dfs(to);
	}
}

int searchMinCost(int i) {
	min = 100000;
	memset(visited, 0, sizeof visited);

	dfs(i);

	return ing[i].cost = min;
}

int main(void) {
	int i;
	int m;
	int ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%s %d", ing[i].name, &ing[i].cost);

	scanf("%d", &m);
	init(n);
	while (m--) {
		char s[11], t[11];
		int idx_s, idx_t;

		scanf("%s %s", s, t);
		idx_s = searchIdx(s);
		idx_t = searchIdx(t);

		add(idx_s, idx_t);
		add(idx_t, idx_s);
	}

	ans = 0;
	for (i = 0; i < n; i++)
		ans += searchMinCost(i);

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

	return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;



int main(){
	ll n, m;
	cin >> n >> m;
	ll ans;
	if (2 * n >= m) {
		ans = m / 2;
	}
	else {
		ans = n;
		m = m - 2 * n;
		ans += m / 4;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 105
#define INF (1e8)
int K,N,M;
int T;
 
bool g[MAX][MAX];
int G[MAX][MAX];
int C[MAX];
int tmp[MAX][MAX];
 
bool visited[MAX];
bool used[MAX];
 
void copyA(){
  for(int i=0;i<MAX;i++)
    for(int j=0;j<MAX;j++)
      tmp[i][j]=G[i][j];
}
void copyB(){
  for(int i=0;i<MAX;i++)
    for(int j=0;j<MAX;j++)
      G[i][j]=tmp[i][j];
}
 
 
 
int dfs(int pos,int ti,int f){
  if(pos==ti)return f;
  visited[pos]=true;
  for(int tt=-1;tt<T;tt++){
    int to=tt;
    if(to==-1)to=T;
     
    if(visited[to])continue;
    if(G[pos][to]==0)continue;
     
    int k=dfs(to,ti, min(f,G[pos][to]) );
    if(k>0){
      G[pos][to]-=k;
      G[to][pos]+=k;
      return k;
    }
  }
  return 0;
}
 
int maxFlow(int si,int ti){
  if(si==ti)return INF;
  int res=0;
  while(1){
    memset(visited,false,sizeof(visited));
    int f=dfs(si,ti,INF);
    if(f==0)break;
    res+=f;
 
  }
  return res;
}
int calcC(int id){
  if(C[id]!=-1)return C[id];
  copyA();
  if(used[id]){
    C[id]=maxFlow(T,id);
  }else{
    C[id]=maxFlow(id,0);
  }
  copyB();
  return C[id];
}
 
int main(){
  memset(C,-1,sizeof(C));
   
  bool isOverfuro=false;
  cin>>K>>N>>M;
  T=N+K+1;
  for(int i=0;i<M;i++){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==0&&1<=b&&b<=K){
      isOverfuro=true;
    }
    if(b==0&&1<=a&&a<=K){
      isOverfuro=true;
    }
    G[a][b]+=c;
    G[b][a]+=c;
    g[a][b]=true;
    g[b][a]=true;
  }
   
  for(int i=1;i<=K;i++){
    G[T][i]=INF;
  }
 
  if(isOverfuro){
    cout<<"overfuro"<<endl;
    return 0;
  }
 
  int F=maxFlow(T,0);
  assert(F>0);
   
  memset(visited,false,sizeof(visited));
  dfs(T,0,INF);
   
  for(int i=0;i<=T;i++){
    used[i]=visited[i];
  }
 
  C[0]=INF;
   
  int ans=0;
  for(int i=0;i<T;i++){
    for(int j=0;j<T;j++){
      if(i==j)continue;
      if(G[i][j]==0&&g[i][j]==true && used[i]==true && used[j]==false ){
        calcC(i);
        calcC(j);
        ans=max(ans, min(C[i],C[j]) );
      }
    }
  }
  cout<<F+ans<<endl;
  return 0;
}

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

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int road[n];

  rep(i, n) {
    road[i] = 0;
  }

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    ++road[a - 1];
    ++road[b - 1];
  }

  rep(i, n) {
    cout << road[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }

    static Scanner cin;

    void calc()
    {
        var N = cin.nextInt();
        var dp = new int[100010];
        for(int i = 1;i <= 100000; i++)
        {
            dp[i] = int.MaxValue;
            int power = 1;
            while(power <= i)
            {
                dp[i] = Math.Min(dp[i], dp[i - power] + 1);
                power *= 6;
            }

            power = 1;
            while (power <= i)
            {
                dp[i] = Math.Min(dp[i], dp[i - power] + 1);
                power *= 9;
            }
        }
        Console.WriteLine(dp[N]);
    }


    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  uint64_t g = gcd(m,n);
  if(m%g==0) return (m/g)*n;
  if(n%g==0) return (n/g)*m;
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

/* 
  //エラトステネスのふるい
  int maxNum = 100000;
  char isNotPrime[maxNum+1] = {};
  isNotPrime[0]=isNotPrime[1]=1;
  for(int i=2;i<maxNum;i++){
    if(isNotPrime[i]==1) continue;
    int num = i+i;
    while(num<=maxNum){
      isNotPrime[num]=1;
      num += i;
    }
  }
*/
// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

signed main() {
  string s;
  cin >> s;

  bool failed = false;
  while(s.length()>=5 && false == failed){
    string last5Str = s.substr(s.length()-5);
    if(last5Str=="dream"
       ||last5Str=="erase"){
      s = s.substr(0,s.length()-5);
      continue;
    }
    if(s.length()>=6
       &&s.substr(s.length()-6)=="eraser"){
        s = s.substr(0,s.length()-6);
      continue;
    }
    if(s.length()>=7
       &&s.substr(s.length()-7)=="dreamer"){
        s = s.substr(0,s.length()-7);
      continue;
    }
    failed = true;
  }
  // dream,dreamer
  // erase,eraser
  
  if(failed || s.length()>0) cout << "NO" << endl;
  else cout << "YES" << endl;

  return 0;
}



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


int main() {

    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    rep(i, h) cin >> a[i];
    vector<bool> row(h, false);
    vector<bool> col(h, false);
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (a[i][j] == '#') {
                row[i] = true;
                col[j] = true;
            }
        }
    }
    for (int i = 0; i < h; ++i) {
        if (row[i]) {
            for (int j = 0; j < w; ++j){
                if (col[j]) {
                    cout << a[i][j];
                }
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 764