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

main() {
  int N; cin >> N;
  string s; cin >> s;
  s += s[0];

  string SSWWS("SSWWS");
  string ans;
  for (int i = 0; i < 4; i++) {
    string res = SSWWS.substr(i, 2);
    for (int j = 1; j < N; j++) {
      for (int k = 0; k < 4; k++) {
        if (res.substr(j - 1, 2) == SSWWS.substr(k, 2)) res += (s[j] == 'o') ? "SW"[k % 2] : "WS"[k % 2];
      }
    }
    if (res.back() != res.front()) continue;

    bool ok = false;
    for (int k = 0; k < 4; k++) {
      if (res.substr(N - 1, 2) == SSWWS.substr(k, 2)) {
        if (s[0] == 'o' && res[1] == "SW"[k % 2] || s[0] == 'x' && res[1] == "WS"[k % 2]) ok = true;
      }
    }
    if (ok) ans = res.substr(0, N);
  }
  cout << ( (ans.empty()) ? "-1" : ans ) << endl;
}


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

using namespace std;

#define INF 210000000
#define int long long

int gcd(int a, int b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

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

signed main() {
		int a,b,c;
		cin >> a >> b >> c;
		if(a + b >= c && a <= c) cout << "YES" << endl;
		else cout << "NO" << endl;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int cost, money, times;
  scanf("%d %d %d",&cost, &money, &times);
  int a1 = money/cost;
  if (cost>money){
    printf("%d",a1);
  }else if (money>=cost && a1> times){
    printf("%d",times);
  }else{
    printf("%d",a1);
  }
return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int T = 0;
		int H = 0;

		for (int i = 0; i < N; i++) {
			String Taro = sc.next();
			String Hana = sc.next();

			if (Taro.compareTo(Hana) == 0) {
				T++;
				H++;
//.compareToで比べる時、左の値が大きい場合には正の値、右の値の方が大きければ負の値がでる
			} else if (Taro.compareTo(Hana) > 0) {
				T += 3;
			} else {
				H += 3;
			}

		}
		System.out.println(T + " " + H);
	}
}



Measured memory_bytes: 30348
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;



using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;
stack<int> ANSAN[200002];
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
int ANS;

vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p = -1){
    for(int u: to[v]){
        if(u == p) continue;
        ans[u] += ans[v];
        dfs(u, v);
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    rep(i, n - 1){
        int a, b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    rep(i, q){
        int p, x;
        cin >> p >> x;
        --p;
        ans[p] += x;
    }
    dfs(0);
    rep(i, n) cout << ans[i] << " ";
    cout << endl;


}

Measured memory_bytes: 157824
#include<bits/stdc++.h>
using namespace std;
int a[1010],n,sum=0;
int main(){
	ios::sync_with_stdio(false);
    cin>>n;
    n*=2;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n;i+=2){
        sum+=a[i];
    }
    cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')

N, K, C = MI()
S = input()

L = list()
i = 0
while i < N:
    if len(L) >= K:
        break
    elif S[i] == 'o':
        L.append(i)
        i += C + 1
    else:
        i += 1

R = list()
i = N - 1
while i >= 0:
    if len(R) >= K:
        break
    elif S[i] == 'o':
        R.append(i)
        i -= C + 1
    else:
        i -= 1
R.reverse()

for i in range(K):
    if L[i] == R[i]:
        print(L[i] + 1)


Measured memory_bytes: 58056
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());

        Set<Integer> p = new HashSet<>();
        int[] count = new int[1000001];
        boolean[] isDiv = new boolean[1000001];

        for (int i = 0; i < n; i++) {
            int num = Integer.parseInt(sc.next());
            p.add(num);
            if (count[num] < 1) {
                for (int j = num * 2; j < 1000001; j += num) {
                    isDiv[j] = true;
                }
            }
            count[num]++;
        }
        sc.close();

        // 主処理
        int result = 0;
        for (int num : p) {
            if (count[num] == 1 && !isDiv[num]) {
                result++;
            }
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 73520
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, s, n, m) for(ll i = s; i < (ll)(n); i+=m)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e5)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

int main()
{
    ll N;
    cin >> N;
    vector<ll> v(N);
    rep(i, 0, N, 1) { 
        cin >> v[i];
    }
    sort(all(v));
    double ans = v[0];
    rep(i, 1, N, 1) {
        ans = (ans + v[i]) / 2.;
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>


struct Node {
	int id, ref, res;
};
bool operator<(const Node &a, const Node &b) {
	return a.ref != b.ref ? a.ref > b.ref : a.res < b.res;
}

int main() {
	int N, M, L; std::cin >> N >> M >> L;
	std::vector<std::vector<long long>> edg(N, std::vector<long long>(N, 1e18));
	for (int i = 0; i < N; i++) edg[i][i] = 0;
	for (int i = 0; i < M; i++) {
		int a, b, c; std::cin >> a >> b >> c;
		a--; b--;
		edg[a][b] = edg[b][a] = c;
	}

	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				edg[i][j] = std::min(edg[i][j], edg[i][k] + edg[k][j]);
			}
		}
	}

	std::vector<std::vector<int>> cnt(N, std::vector<int>(N, 1e9));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i == j) cnt[i][i] = 0;
			if (edg[i][j] <= L) cnt[i][j] = 1;
		}
	}
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				cnt[i][j] = std::min(cnt[i][j], cnt[i][k] + cnt[k][j]);
			}
		}
	}
	
	int Q; std::cin >> Q;
	while (Q--) {
		int s, t; std::cin >> s >> t;
		std::cout << (cnt[s - 1][t - 1] < 1e9 ? cnt[s - 1][t - 1] - 1 : -1) << std::endl;
	}
	return 0;
}


Measured memory_bytes: 1664
a = str(input())
b = list(a)
if b == ["S","S","S"]:
  print(0)
elif b == ["R", "S", "R"]:
  print(1)
elif b ==["R", "S", "S"]:
  print(1)
elif b == ["S","R","S"]:
  print(1)
elif b == ["S","S","R"]:
  print(1)
elif b == ["R","R","S"]:
  print(2)
elif b == ["S","R","R"]:
  print(2)
else:
  print(3)

Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define pb push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr double eps = 1e-14; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int n;

constexpr long long minf = -100000 * 5000;

void solve(){
    vector<int> a(n);
    rep(i,n) cin>>a[i];

    vector<ll> sum(n+10,0);    // sum[i] = a[0] + ... + a[i-1]
    for(int i=0;i<n;i++) sum[i+1] = sum[i] + a[i]; 

    ll ans = minf-10;

    rep(i,n) rep(j,n) if(i<=j){
        // k = a[i] + ... + a[j]
        ll k = sum[j+1] - sum[i];
        ans = max(ans,k);
    }

    cout << ans << endl;
}

int main(){
    while(cin>>n){
        if(n==0) break;
        solve();
    }
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define rep(i,l,n) for(i=l;i<n;i++)


int main(){
	int i,w,n,a,b,c[35],d;
	char k;

	cin>>w;
	cin>>n;
	//cout<<w<<" "<<n<<endl;
	rep(i,1,w+1){
		c[i]=i;
	}
	rep(i,1,n+1){
		cin>>a>>k>>b;
		//cout<<c[a]<<" "<<c[b]<<endl;
		swap(c[a],c[b]);
		//cout<<c[a]<<" "<<c[b]<<endl<<endl;
		
	}
	rep(i,1,w+1){
		cout<<c[i]<<endl;
	}
	

}

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

template<typename T>
vector<T> compress(vector<T> A){
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    return A;
}

int main(){
    int N;
    cin >> N;
    vector<pair<int, int>> A(N);
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        A[i] = {a, i};
    }
    sort(A.begin(), A.end());
    int ans = 0;
    for(int i=0; i<N; i++) if((i-A[i].second)%2) ans++;
    ans /= 2;
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll a,b;
  cin >> a >> b;

  if(b-2*a>=0 && (b-2*a)%2==0 && 4*a-b>=0 && (4*a-b)%2==0)cout << "Yes" << endl;
  else cout << "No" << endl;

}

Measured memory_bytes: 3648
def solve():
    x, k, d = map(int, input().split())
    l = x - k * d
    r = x + k * d
    if l > 0:
        print(l)
        return
    elif r < 0:
        print(-r)
        return
    a1 = r - r // (2 * d) * (2 * d)
    a2 = a1 - (2 * d)
    ans = min(abs(a1), abs(a2))
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 9184
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
int main()
{
    ll n,k,cnt=0,ans,a;
 
    cin >> n >> k;
 
    a = n%k;
    ans = min(a,k-a);
 
    cout << ans << endl;
    return 0;
 
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class B
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine().Trim());
        string S = Console.ReadLine().Trim();

        var count = 0;
        for (int i = 0; i < N - 2; i++)
        {
            if (S.Substring(i, 3) == "ABC") count++;
        }

        Console.WriteLine(count);
    }

}

Measured memory_bytes: 13140
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;

/*----------macros----------*/

//input, output================
#define fastio                          \
std::ios::sync_with_stdio(false);       \
std::cin.tie(nullptr);                  \
std::cout.tie(nullptr)

#define endl '\n'
#define fcout(a)                        \
cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef vector<int>     Vi;
typedef vector<ll>      Vl;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF    = (ll)1e9 + 1;
constexpr ll INFll  = (ll)1e18 + 1;
constexpr ll MOD1   = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define psb push_back
#define epb emplace_back
#define psf push_front
#define mkp make_pair
#define fst first
#define snd second

//others================
#define sz(x)                           \
(int) x.size()

#define all(x)                          \
(x).begin(), (x).end()

#define rall(x)                         \
(x).rbegin(), (x).rend()

#define rep(i, n)                       \
for(int i = 0; (i) < (n); ++(i))

#define reps(i, n)                      \
for(int i = 1; (i) <= (n); ++(i))

#define rrep(i, n)                      \
for(int i = n - 1; (i) >= 0 ; --(i))

#define repbit(bit, n)                  \
for(int bit = 0; (bit) < (1 << (n)); ++(bit))

#define ifbit(bit, i)                   \
if((bit) & (1 << (i)))

#define CtoI(c)                         \
int((c)) - int('0')

#define ItoC(c)                         \
char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b)
{ return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b)
{ return a > b && (a = b, true); }

// Vi  dx = {1, 0, -1, 0},
//     dy = {0, 1, 0, -1};

// Vi  dx2 = { 1,1,0,-1,-1,-1,0,1 },
//     dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
fastio;

    int k; cin >> k;
    int a = 0, b = 0;
    reps(i, k){
        if(i%2 == 0) ++a;
        else ++b;
    }

    cout << a * b << endl;

return 0;
}

Measured memory_bytes: 3552
#ABC127D-IntegerCards.py

from sys import stdin

input = stdin.readline

N, M = list(map(int, input().split()))
A = [[1,a] for a in list(map(int, input().split()))]
BC = [list(map(int, input().split())) for _ in range(M)]

List = A + BC

List.sort(key=lambda x:x[1])
sumList = []

for b, c in reversed(List):
    for i in range(b):
        if len(sumList) < N:
            sumList.append(c)
        else:
            break
    else:
        continue
    break

print(sum(sumList))


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

using namespace std;

int main(){

	int max=0;
	int l=0;
	string s, str;
	cin>> s;

	for(int i=0;i<s.size();i++){
		str=s.substr(i, 1);
		if(str=="A" || str=="C" || str=="T" || str=="G"){
			l++;
		}else{
			if(max<l) max=l;
			l=0;
		}
	}

	if(max<l) max=l;

	cout<< max << endl;


}

Measured memory_bytes: 256
m, d = map(int, input().split())

if m in (1,3,5,7,8,10,12) and d == 31:
  print(1)
elif m in (4,6,9,11) and d == 30:
  print(1)
elif m == 2 and d == 28:
  print(1)
else:
  print(0)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define ld          long double
#define endl        "\n"

const int mod = 1e9+7;

inline int add(int a, int b) { int res = a + b; if(res >= mod) res -= mod;  return res; }
inline int sub(int a, int b) { int res = a - b; if(res < 0) res += mod; return res;}
inline int mul(int a, int b) { return (a * b)%mod; }

const int N = 55;
int n, m;
int dep[N];
int fa[N];
int path[22];
vector<int> g[N];

void rec(int u) {
    for(int v : g[u]) if(v != fa[u]) {
        fa[v] = u;
        dep[v] = dep[u] + 1;
        rec(v);
    }
}

void solve() {
    cin >> n;
    for(int i=1; i<n; i++) {
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    rec(1);
    cin >> m;
    for(int i=0; i<m; i++) {
        int u, v; cin >> u >> v;
        if(dep[u] < dep[v]) swap(u, v);
        while(dep[u] > dep[v]) {
            path[i] |= (1LL << (u - 1));
            u = fa[u];
        }   // Now, both u & v at same level, so find LCA
        while(u != v) {
            path[i] |= (1LL << (u - 1)) | (1LL << (v - 1));
            u = fa[u], v = fa[v];
        }
    }
    int ans = 0;
    for(int i=0; i < (1LL << m); i++) {
        int cnt = 0, white = 0;
        int msk = 0;
        for(int j=0; j<m; j++) if(i & (1LL << j)) cnt++, msk |= path[j];
        for(int j=0; j<n; j++) if(msk & (1LL << j)) white++;
        ans += (cnt%2 ? -1 : 1) * (1LL << (n - white - 1));
    }
    cout << ans << endl;
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);

    int T = 1;
    //cin >> T;

    while(T--) {
        solve();
    }
    return 0;
}

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

int main()
{
	int N, x = 0;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		x ^= a[i];
		a[i] = a[i] ^ (a[i] - 1);
	}
	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());
	int res = 0;
	for (int i = 30; i >= 0; i--) {
		if (x & (1 << i)) {
			int v = lower_bound(a.begin(), a.end(), (1 << (i + 1)) - 1) - a.begin();
			if (v != (int)a.size() && a[v] == (1 << (i + 1)) - 1) {
				x ^= a[v];
				res++;
			}
		}
	}
	cout << (x ? -1 : res) << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
typedef long long ll;
typedef unsigned int uint;
using namespace std;
const int MAX_N = 8;
bool G[MAX_N][MAX_N];

int dfs(int v, int n, bool visited[MAX_N]) {
    bool all_visited = true;
    for (int i = 0; i < n; i++) {
        if (visited[i] == false) {
            all_visited = false;
        }
    }

    if (all_visited) {
        return 1;
    }

    int ret = 0;
    for (int i = 0; i < n; i++) {
        if (G[v][i] == false) continue;
        if (visited[i]) continue;
        visited[i] = true;
        ret += dfs(i, n, visited);
        visited[i] = false;
    }

    return ret;
}

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

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a][b] = G[b][a] = true;
    }

    bool visited[MAX_N];
    fill(visited, visited+MAX_N, false);
    visited[0] = true;
    cout << dfs(0, n, visited);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String[] data = sc.nextLine().split(" ");
        int n = Integer.parseInt(data[0]);
        int m = Integer.parseInt(data[1]);
        int l = Integer.parseInt(data[2]);

        int[][] listA = new int[n][m];
        int[][] listB = new int[l][m];
        for(int i = 0; i < n; i++){
            String[] strTmp = sc.nextLine().split(" ");
            for(int j = 0; j < m;j++){
                listA[i][j]=Integer.parseInt(strTmp[j]);
            }
        }
        
        for(int i = 0; i < m; i++){
            String[] strTmp = sc.nextLine().split(" ");
            for(int j = 0; j < l;j++){
                listB[j][i]=Integer.parseInt(strTmp[j]);
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < n; i++){
            for(int j = 0; j < l;j++){
                long tmp = 0;
                for(int k = 0; k < m;k++){
                    tmp+=listA[i][k]*listB[j][k];
                }
                if(j==l-1) sb.append(tmp);
                else sb.append(tmp+" ");
            }
            sb.append("\n");
        }       
        System.out.print(sb);
    }
}


Measured memory_bytes: 36712
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define P 1000000007
#define inf 1e18
int main()
{
    ll i, n;
    //ll i,n;
    cin >> n;
    cout << (n * (n - 1)) / 2 << "\n";

    return (0);
}

Measured memory_bytes: 3624
#include <cstdio>
#include <algorithm>
#include <vector>
static const int MAXN = 1003;
static const int MAXX = 5004;
static const int INF = 0x3fffffff;

int n;
int x[MAXN];
std::vector<int> e[MAXN];

int f[MAXN][MAXX];
int g[MAXN];

void dfs(int u)
{
    f[u][0] = 0;
    for (int i = 1; i < MAXX; ++i) f[u][i] = INF;

    for (int v : e[u]) {
        dfs(v);
        static int ff[MAXX];
        for (int i = 0; i < MAXX; ++i) ff[i] = INF;
        for (int i = MAXX - x[v]; i >= 0; --i)
            ff[i + x[v]] = std::min(ff[i + x[v]], f[u][i] + g[v]);
        for (int i = MAXX - g[v]; i >= 0; --i)
            ff[i + g[v]] = std::min(ff[i + g[v]], f[u][i] + x[v]);
        std::copy(ff, ff + MAXX, f[u]);
    }

    g[u] = INF;
    for (int i = 0; i <= x[u]; ++i) g[u] = std::min(g[u], f[u][i]);
}

int main()
{
    scanf("%d", &n);

    for (int i = 1, p; i < n; ++i) {
        scanf("%d", &p); --p;
        e[p].push_back(i);
    }
    for (int i = 0; i < n; ++i) scanf("%d", &x[i]);

    dfs(0);
    puts(g[0] == INF ? "IMPOSSIBLE" : "POSSIBLE");

    return 0;
}


Measured memory_bytes: 19968
use proconio::input;
use rand::prelude::*;
use std::collections::BTreeSet;

fn eval_lasts(days: i64, cs: &Vec<i64>, schedule: &Vec<BTreeSet<i64>>) -> i64 {
    let mut score = 0;

    for i in 0..cs.len() {
        let mut last = -1;

        for d in schedule[i].iter() {
            let x = d - last;
            let n = (x * (x - 1)) / 2;
            score -= cs[i] * n;
            last = *d;
        }
        let x = days - last;
        let n = (x * (x - 1)) / 2;
        score -= cs[i] * n;
    }

    score
}

fn eval(
    days: u64,
    cs: &Vec<i64>,
    sats: &Vec<Vec<i64>>,
    ts: &Vec<u64>,
) -> (i64, Vec<BTreeSet<i64>>) {
    let mut score = 0;

    let mut schedule = vec![BTreeSet::<i64>::new(); 26];

    for day in 0usize..(days as usize) {
        let contest = ts[day as usize] as usize;
        score += sats[day][contest] as i64;
        schedule[contest].insert(day as i64);
    }

    (score, schedule)
}

fn main() {
    input! { days: u64 };
    let mut cs = vec![0; 26];

    for i in 0..26 {
        input! {
            x: i64
        };

        cs[i] = x;
    }

    let mut sats = vec![vec![0; 26]; days as usize];
    for d in 0..days {
        for i in 0..26 {
            input! {
                s: i64
            };

            sats[d as usize][i as usize] = s;
        }
    }

    let mut ts = vec![0u64; days as usize];
    for i in 0..ts.len() {
        ts[i] = (i as u64) % 26;
    }

    let (mut base_score, mut schedule) = eval(days, &cs, &sats, &ts);

    let mut cur_score = base_score + eval_lasts(days as i64, &cs, &schedule);

    for _ in 0..300000 {
        // Swap `day_a` and `day_b`
        let day_a = rand::random::<usize>() % (days - 1) as usize;
        let day_b = day_a + 1;

        let prev_contest_a = ts[day_a as usize] as usize;
        let prev_contest_b = ts[day_b as usize] as usize;

        let mut next_score = base_score;
        next_score -= sats[day_a][prev_contest_a];
        next_score -= sats[day_b][prev_contest_b];
        schedule[prev_contest_a].remove(&(day_a as i64));
        schedule[prev_contest_b].remove(&(day_b as i64));

        next_score += sats[day_a][prev_contest_b];
        next_score += sats[day_b][prev_contest_a];
        schedule[prev_contest_a].insert(day_b as i64);
        schedule[prev_contest_b].insert(day_a as i64);

        let s2 = eval_lasts(days as i64, &cs, &schedule);

        if next_score + s2 > cur_score {
            base_score = next_score;
            cur_score = next_score + s2;
            ts[day_a as usize] = prev_contest_b as u64;
            ts[day_b as usize] = prev_contest_a as u64;
        } else {
            schedule[prev_contest_a].remove(&(day_b as i64));
            schedule[prev_contest_b].remove(&(day_a as i64));

            schedule[prev_contest_a].insert(day_a as i64);
            schedule[prev_contest_b].insert(day_a as i64);
        }
    }

    for t in ts {
        println!("{}", t + 1);
    }
}


Measured memory_bytes: 2776
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, T = LI()
    ans = inf
    for i in range(N):
        c, t = LI()
        if t <= T:
            ans = min(ans, c)
    if ans == inf:
        print("TLE")
        return
    print(ans)

main()



Measured memory_bytes: 83616
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vp = vector<pii>;
using vs = vector<string>;
using qi = queue<int>;
using qp = queue<pii>;
using pqi = priority_queue<int>;
using pqim = priority_queue<pii, vector<pii>, greater<pii> >;
using ppp = pair<int, pair<int, int>>;
#define all(vec) vec.begin(), vec.end()
#define rall(vec) vec.rbegin(), vec.rend()
#define pb push_back
const ll mod = 998244353;
const ll inf = 1e18;

int n;
	int a, b, c, d, e;

void input() {
	cin >> a >> b >> c >> d >> e;


}

void solve() {
	if (!a) cout << 1;
	else if (!b) cout << 2;
	else if (!c) cout << 3;
	else if (!d) cout << 4;
	else cout << 5;

	return;
}

int main() {
	cin.tie(NULL); ios_base::sync_with_stdio(false);

	input();
	solve();
}

Measured memory_bytes: 3636
# keyence2019B - KEYENCE String
def main():
    S = input()
    n = len(S)
    K = "keyence"
    for i in range(n):
        for j in range(i, n):
            s = S[:i] + S[j:]
            if s == K:
                print("YES")
                return
    else:
        print("NO")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;

ll to_log(ll h) {
  ll n = 0;
  while ( h/2 > 0) {
    h /= 2;
    n ++;
  }
  return n;
}

ll f(ll n) {
  if (n == 1) {
    return 3;
  }
  return f(n-1) * 2 + 1;
}

int main() {
  ll h;
  cin >> h;

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

  ll log_h = to_log(h);
  ll ans = f(log_h);

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   /// BISMILLAHIR RAHMANIR RAHIM
   int h1,h2,m1,m2,p;
   cin>>h1>>m1>>h2>>m2>>p;

    int ans=(60*(h2-h1)+m2-m1-p);
    cout<<ans<<endl;



    /// ALHAMDULILLAH
}


Measured memory_bytes: 3628
H, W = map(int, input().split())
a = [list(input()) for i in range(H)]

a1 = []
for h in range(H):
  if not all(s=="." for s in a[h]):
    a1.append(a[h])

a2 = [[] for i in range(len(a1))]
for w in range(W):
  tmp_a = [row[w] for row in a1]
  if not all(s=="." for s in tmp_a):
    for i in range(len(tmp_a)):
      a2[i].append(tmp_a[i])

for row in a2:
  print("".join(row))

Measured memory_bytes: 3188
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

maxa = max(a)

a.remove(maxa)

half = maxa / 2
minabs_from_half = 10**18

ans = -1
for ai in a:
    if abs(half - ai) < minabs_from_half:
        ans = ai
        minabs_from_half = abs(half - ai)

print(maxa, ans)

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

#define mp(x, y) make_pair((x), (y))

typedef long long ll;

int x, y;

int main()
{
	scanf("%d%d", &x, &y);

	if(x%y==0) printf("-1\n");
	else printf("%d\n", x);

	return 0;
}

Measured memory_bytes: 256
awk '{
  ok = 1
  for (i=1; i<=length($1); ++i) {
    c = substr($1, i, 1)
    if (i % 2 == 1 && c == "L") ok = 0;
    if (i % 2 == 0 && c == "R") ok = 0;
  }
  if (ok) print "Yes"
  else print "No"
}'


Measured memory_bytes: 552
use std::io;
use std::cmp;

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split(' ')
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

fn main() {

    let (n, mut x) = {
        let i = read::<usize>();
        (i[0], i[1])
    };

    let mut min = 10000000;
    for _ in 0..n {
        let m = read_one::<usize>();
        x -= m;
        min = cmp::min(m, min);
    }
    println!("{}", n + x / min);
}

Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace ABC138
{
    class Program
    {
        static void Main()
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            var input = Console.ReadLine().Split(' ').Select(int.Parse);
            var N = input.First();
            var Q = input.Skip(1).First();
            var llNodes = new LLNode[N];
            for (int i = 0; i < N; i++)
                llNodes[i] = new LLNode(i);

            for (int i = 0; i < N - 1; i++)
            {
                input = Console.ReadLine().Split(' ').Select(int.Parse);
                llNodes[input.First() - 1].AddEdge(llNodes[input.Skip(1).First() - 1]);
            }

            for (int i = 0; i < Q; i++)
            {
                input = Console.ReadLine().Split(' ').Select(int.Parse);
                llNodes[input.First() - 1].val += input.Skip(1).First();
            }

            var ans = new int[N];
            var que = new Queue<Search>();
            que.Enqueue(new Search(llNodes[0], 0));
            while (que.Count > 0)
            {
                var q = que.Dequeue();
                ans[q.ln.number] = q.sum + q.ln.val;
                foreach (var node in q.ln.next)
                    que.Enqueue(new Search(node, q.sum + q.ln.val));
            }

            Console.WriteLine(string.Join(" ", ans));
            Console.Out.Flush();
        }

        public class Search
        {
            public LLNode ln;
            public int sum;

            public Search(LLNode n, int s)
            {
                ln = n;
                sum = s;
            }
        }

        public class LLNode
        {
            public List<LLNode> next;
            public int val;
            public int number;

            public LLNode(int num)
            {
                val = 0;
                next = new List<LLNode>();
                number = num;
            }

            public void AddEdge(LLNode nex)
            {
                next.Add(nex);
            }
        }
    }
}


Measured memory_bytes: 60776
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define tp tuple<int,int,int>
#define mtp make_tuple
using namespace std;

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int x;
    cin>>x;
    int cur=100;
    int cnt=0;
    while(cur<x)
    {
        cnt++;
        cur=cur+(cur/100);
    }
    cout<<cnt;
}


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

int main() {
	int N;
	cin >> N;
	
	vector< int > a(N);
	for (int i=0; i<N; ++i) cin >> a[i];
	
	int L = 0, R = N-1, sum = 0;
	
	map< int, int > cnt;
	
	vector< int > ans;
	
	while (L < N) {
		if (a[L] != a[R]) {
			if (cnt[a[R]] == 0) ++sum;
			if (cnt[a[L]] == 0) ++sum;
			
			if (cnt[a[R]] == -1) --sum;
			if (cnt[a[L]] == 1) --sum;
			
			++cnt[a[R]];
			--cnt[a[L]];
		}
		
		if (sum == 0) ans.push_back(L+1);
		
		++L;
		--R;
	}
	
	int m = ans.size();
	for (int i=0; i<m; ++i) cout << ans[i] << (i<m-1? " " : "\n");
}


Measured memory_bytes: 5536
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
for i in A:
    if i == A[0]:
        mem = i
    ans += B[i - 1]
    if i - 1 == mem:
        ans += C[mem - 1]
    mem = i
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main(){
  int x,n;
  cin>>x>>n;
  vector<int> p(n);
  rep(i,n) cin>>p[i];
  sort(all(p));
  vector<int> q(300);
  for(int i=-100;i<200;i++) q[i+100]=i+1;
  
  rep(i,n){
    q.erase(remove(q.begin(), q.end(), p[i]), q.end());
  }
  rep(i,300){
    q[i]-=x;
  }
  
  int min=abs(q[0]);
  int ans=0;
  rep(i,300){
    if(abs(q[i])<min) {
      min=abs(q[i]);
      ans=q[i];
    }
  }
  ans+=x;
  
  dunk(ans);
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;
int main() {
    unsigned long long int n,k,a,b;
    cin>>n>>k;
    a=n%k;
    b=k-a;
    if(b<0)
        b=-b;
    if(a<b)
        cout<<a;
    else
        cout<<b;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int X, t;

int main() {
  cin >> X >> t;
  cout << max(X - t, 0);
}


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

using LL = long long;
using LD = long double;
 
LL mod = 1e9+7;

static LL g[101][100002];

int main()
{
	for (LL i = 0; i < 100; ++i) {
		for (LL j = 0; j < 100002; ++j) {
			g[i][j] = 0;
		}
	}
	LL n, k;
	cin >> n >> k;

	vector<LL> a(n);

	for (auto &e : a) {
		cin >> e;
	}

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

	g[0][0] = 1;

	for (LL i = 0; i <= n-1; ++i) {
		for (LL j = 0; j <= k; ++j) {
			g[i+1][j] += g[i][j];
			g[i+1][min(j+a[i]+1, k+1)] -= g[i][j];
			
		}
		LL acc = 0;
		for (LL j = 0; j <= k; ++j) {
			acc += g[i+1][j];
			acc %= mod;
			g[i+1][j] = (acc+mod)%mod;
		}
	}

	// for (LL i = 0; i <= n; ++i) {
	// 	for (LL j = 0; j <= k; ++j) {
	// 		cout << g[i][j] << " ";
	// 	}
	// 	cout << "\n";
	// }

	cout << g[n][k] << "\n";



}

Measured memory_bytes: 79104
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int arr[] = new int[n];

        for(int i=0; i<n; i++)
            arr[i] = sc.nextInt();

        for(int i=0; i<arr.length; i++){
            int j = i;

            while(j > 0 && arr[j-1] > arr[j]){
                int temp = arr[j-1];
                arr[j-1] = arr[j];
                arr[j] = temp;
                j--;
            }
            // System.out.println(Arrays.toString(arr));
            for (int k = 0; k < arr.length; k++) {
                if(k != 0){System.out.print(" ");}
                System.out.print(arr[k]);
                
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 34168
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>

#define MODULE 
#define RAND(min,max) (rand()%(max-min+1)+min)
#define LOGI(log) printf("\n%d\n",log);
#define LOGS(log) printf("\n%s\n",log);
#define DEBUG() {printf("\nDEBUG %d\n",num_debug);num_debug++;}
char num_debug = 0;

int compare_int(const void* a, const void* b);

int main(void) {
	srand((unsigned)time(NULL));

	int N, K;
	int p[1000];
	scanf("%d%d", &N, &K);
	for (int i = 0; i < N; i++) {
		scanf("%d", &p[i]);
	}

	qsort(p, N, sizeof(int), compare_int);

	unsigned int sum=0;
	for (int i = 0; i < K; i++) {
		sum += p[i];
	}

	printf("%d", sum);

	return 0;
}

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

Measured memory_bytes: 1720
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a)
	fmt.Scan(&b)
	if a > 9 || b > 9 {
		fmt.Println("-1")
		return
	}
	if a < 1 || b < 1 {
		fmt.Println("-1")
		return
	}
	fmt.Println(a * b)
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.length()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>())
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////
	int a,b,c;
	cin >> a >> b >> c;
	if(a==b) cout << c << endl;
	if(c==b) cout << a << endl;
	if(a==c) cout << b << endl;

//////////////////////////////////////////////
}


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

int main() {
  int N;
  string S;
  cin >> N  >>S;
  vector <int> vec(N + 1);
  
  vec.at(0) = 0;
  for (int i = 0 ; i < N ; i++ ){
    if (S.at(i) == 'I' ){
      vec.at(i + 1) = vec.at(i) + 1;
    }
    else {
      vec.at(i + 1 ) = vec.at(i) - 1;
    }
  }
  
//  for ( int i = 0 ; i < N ; i++ ) {
//    cout << vec.at(i) << " " ;
//  }
  
  int answer = 0;
  for ( int i = 0 ; i < N + 1 ; i++ ){
    answer = max(answer, vec.at(i) );
  }
  
  cout << answer;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,ans=0;
    cin>>n>>m;
    int k[m],s[m][n],p[m];
    rep(i,m){
        cin>>k[i];
        rep(j,k[i]) cin>>s[i][j];
    }
    rep(i,m) cin>>p[i];
    rep(i,pow(2,n)){
        int b=0;
        rep(j,m){
            int a=0;
            rep(l,k[j]) if(i&(1<<(s[j][l]-1))) a++;
            if(a%2==p[j]) b++;
        }
        if(b==m) ans++;
    }
    cout<<ans;
}

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

int main() {
	long long int x, y;
	cin >> x >> y;
	if (x < y && x * y > 0) cout << y - x << endl;
	if (x > y && x * y > 0) cout << x - y + 2 << endl;
	if (x * y < 0) cout << abs(x + y) + 1 << endl;
	if (x == 0 && y > 0) cout << y << endl;
	if (x == 0 && y < 0) cout << 1 - y << endl;
	if (y == 0 && x < 0) cout << -x << endl;
	if (y == 0 && x > 0) cout << 1 + x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct flow{
	int n,s,t;
	struct edge{
		int from,to,cap;
		edge(int f,int t,int c):from(f),to(t),cap(c){}
	};
	vector<edge>e;
	vector<vector<int> >v;
	flow(int n,int s,int t):n(n),s(s),t(t),v(n){}
	
	
	void addedge(int s,int t,int c){
		v[s].emplace_back(e.size());
		e.emplace_back(s,t,c);
		v[t].emplace_back(e.size());
		e.emplace_back(t,s,0);
	}
	vector<int>dist,par;
	int minedge;
	int bfs(){
		for(int i=0;i<n;i++){
			par[i]=-1;
			dist[i]=INT_MAX;
		}
		
		dist[s]=0;
		queue<int>q;
		q.emplace(s);
		while(!q.empty()){
			int u=q.front();
			q.pop();
			for(int i=0;i<v[u].size();i++){
				if(e[v[u][i]].cap<=0){
					continue;
				}
				if(dist[e[v[u][i]].to]==INT_MAX){
					dist[e[v[u][i]].to]=dist[u]+1;
					par[e[v[u][i]].to]=v[u][i];
					q.emplace(e[v[u][i]].to);
				}
			}
		}
		return dist[t];
	}
	int aug(){
		minedge=INT_MAX;
		for(int i=t;par[i]!=-1;i=e[par[i]].from){
			minedge=min(e[par[i]].cap,minedge);
		}
		for(int i=t;par[i]!=-1;i=e[par[i]].from){
			e[par[i]].cap-=minedge;
			e[par[i]^1].cap+=minedge;
		}
		return minedge;
	}
	int maxflow(){
		int flowrate=0;
		for(int i=0;i<n;i++){
			par.emplace_back(-1);
			dist.emplace_back(INT_MAX);
		}
		while(bfs()!=INT_MAX){
			
			flowrate+=aug();
		}
		return flowrate;
	}
};
int main(){
	int n,m;
	cin>>n>>m;
	flow f(n,0,n-1);
	while(m--){
		int s,t,c;
		cin>>s>>t>>c;
		f.addedge(s,t,c);
	}
	
	cout<<f.maxflow()<<"\n";
}


Measured memory_bytes: 3184
#include <stdio.h>
void maxHeapify(int);
int h,A[500000];
void maxHeapify(int i){
	int l,r,largest,tmp;
	l=i*2;
	r=i*2+1;
	
	if(l<=h && A[l]>A[i]) largest=l;
	else largest=i;
	
	if(r<=h && A[r]>A[largest]) largest=r;
	if(largest!=i){
		tmp=A[i];
		A[i]=A[largest];
		A[largest]=tmp;
		maxHeapify(largest);
	}
}

int main(){
	int i;
	
	scanf("%d",&h);
	for(i=1;i<=h;i++) scanf("%d",&A[i]);
	
	for(i=h/2;i>=1;i--) maxHeapify(i);
	
	for(i=1;i<=h;i++) printf(" %d",A[i]);
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 3660
//============================================================================
// Name        : AOJ.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;
typedef long long ll;
int main(){

	int a,b;

	cin>>a>>b;

	if(a<=b){
		cout<<a<<endl;
	}else{
		cout<<a-1<<endl;
	}


	return 0;
}


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


int main()
{
    int N;
    cin >> N;
    vector<int> s(N);
    for( int i = 0; i < N; ++i ) cin >> s[i];


    long long ans = 0;
    for( int C = 1; C < N; ++C ){  // C = A-B
        long long score = 0;
        vector<bool> isVisited(N, false);
        for( int k = 0;; ++k ){  // k*C + A = N-1
            int A = (N-1) - k*C;
            int B = A-C;
            if (A <= 0) break;  // A = (N-1) - k*C > 0 の条件
            if (B <= 0) break;  // B = A-C = (N-1)-(k-1)*C > 0 の条件

            if( isVisited[k*C] ) break;
            isVisited[k*C] = true;
            score += s[k*C];
            
            if( isVisited[A] ) break;
            isVisited[A] = true;
            score += s[A];

            ans = max(ans, score);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define pii             pair<int , int >
#define in(a)           scanf("%d", &a)
#define in2(a, b)       scanf("%d%d", &a, &b)
#define in3(a, b, c)    scanf("%d%d%d", &a, &b, &c)
#define piil            pair<ll , ll >
#define inl(a)          scanf("%lld", &a)
#define inl2(a, b)      scanf("%lld%lld", &a, &b)
#define inl3(a, b, c)   scanf("%lld%lld%lld", &a, &b, &c)
#define ins(s)          scanf("%s",s)
#define prst(s)         printf("%s\n",s)
#define pn              printf("\n")
#define pr(a)           printf("%d\n", a)
#define prl(a)          printf("%lld\n", a)
#define prs(a)          printf("%d ", a)
#define pr2(a, b)       printf("%d %d\n", a, b)
#define pr3(a, b, c)    printf("%d %d %d\n", a, b, c)
#define prsl(a)         printf("%lld ", a)
#define prl2(a, b)      printf("%lld %lld\n", a, b)
#define prl3(a, b, c)   printf("%lld %lld %lld\n", a, b, c)
#define pcs(a)          printf("Case %d: ", a)
#define pf              printf
#define sc              scanf
#define m_p             make_pair
#define vi              vector<int >
#define vil             vector<ll >
#define pb              push_back
#define mem(a, b)       memset((a), (b), sizeof(a))
#define lg2(n)         (31-__builtin_clz(n))
#define N 2000010
#define inf 9999999
#define ll long long
#define ull unsigned long long
#define MIN INT_MIN
#define MAX INT_MAX
#define __  std::ios_base::sync_with_stdio (false); cin.tie(0); cout.tie(0);
#define Check(n, pos) (n & (1<<pos))
#define Set(n, pos) (n | (1<<pos))
ll gcd(ll a, ll b){if(b==0) {return a;}return gcd(b, a % b);}
using namespace std;
ll BigMod(ll B,ll P,ll M){     ll R=1; while(P>0)      {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;}
ll histogram(ll arr[],ll n) {  stack<int>s;  int area=0,i=0;  while(i<n) { if(s.empty() || arr[s.top()]<=arr[i]) s.push(i++); else { int tp=s.top(); s.pop(); int xx=arr[tp]*(s.empty() ? i : i - s.top() - 1);area=max(area,xx);}}while(!s.empty()){ int tp=s.top(); s.pop(); int xx=arr[tp]*(s.empty() ? i : i - s.top() - 1); area=max(area,xx); } return area;}
//___________________________________________________________________________________________________________________
ll dp[N],arr[N];
char str[N];
int main()
{
   ll n,m,k,a,b;
   ll sum=0;
   string s;
  cin>>n;
  if(n%2==0) cout<<n<<endl;
  else cout<<(n*2)<<endl;
   
    return 0;
}




Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>

typedef struct
{
  double x,y;
}Point;

void koch(int n,Point a,Point b)
{
  if(n==0)return;
  Point s,t,u;
  double th = M_PI *60.0/180.0;
  s.x = (2.0*a.x+1.0*b.x)/3.0;
  s.y= (2.0*a.y+1.0*b.y)/3.0;
  t.x=(1.0*a.x+2.0*b.x)/3.0;
  t.y=(1.0*a.y+2.0*b.y)/3.0;
  u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);
}

int main()
{
  Point a,b;
  int n;

  scanf("%d",&n);

  a.x=0;
  a.y=0;
  b.x=100;
  b.y=0;
  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);
  
  return 0;
}



Measured memory_bytes: 2052
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
	

int main(){
	FIO
	
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)cin >> a[i];
	cout << a[0];
	for(int i = 1; i < n; i++)cout << ' ' << a[i];
	cout << '\n';
	for(int i = 1; i < n; i++){
		int key = a[i];
		int j = i - 1;
		while(j >= 0 && a[j] >= key){
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = key;
		cout << a[0];
		for(int i = 1; i < n; i++)cout << ' ' << a[i];
		cout << '\n';
	}
	
	return 0;
}



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

int main() {
	ll n,y;
	cin >> n >> y;
	rep(i,n+1) {
		rep(j,n+1-i) {
			ll k = n-i-j;
			//cout << i << j << k << endl;
			if (10000*i + 5000*j + 1000*k == y) {
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}
	printf("%d %d %d", -1, -1, -1);

	return 0;
}


Measured memory_bytes: 256