akhauriyash/Code-Regression huggingface dataset:
// =================================
//   author: memset0
//   date: 2019.03.20 21:58:38
//   website: https://memset0.cn/
// =================================
#include <bits/stdc++.h>
#define ll long long
#define debug(...) ((void)0)
#ifndef debug
#define debug(...) fprintf(stderr,__VA_ARGS__)
#endif
namespace ringo {
template <class T> inline void read(T &x) {
	x = 0; register char c = getchar(); register bool f = 0;
	while (!isdigit(c)) f ^= c == '-', c = getchar();
	while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
	if (f) x = -x;
}
template <class T> inline void print(T x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) print(x / 10);
	putchar('0' + x % 10);
}
template <class T> inline void print(T x, char c) { print(x), putchar(c); }

const int N = 10;
int n, m, ans = true, a[N][N];

void main() {
	read(n), read(m);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			char c = getchar();
			while (c != '#' && c != '.') c = getchar();
			a[i][j] = c == '#';
		}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (a[i][j]) {
				if (i != n && j != m) {
					if (a[i + 1][j] && a[i][j + 1])
						ans = false;
					if (!a[i + 1][j] && !a[i][j + 1])
						ans = false;
				}
				if (i != 1 || j != 1) {
					if (a[i - 1][j] && a[i][j - 1])
						ans = false;
					if (!a[i - 1][j] && !a[i][j - 1])
						ans = false;
				}
			}
	puts(ans ? "Possible" : "Impossible");
}

} signed main() { return ringo::main(), 0; }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
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; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){
  int A[3][3];
  bool B[3][3];
  rep(i,3)rep(j,3){
    cin >> A[i][j];
    B[i][j]=false;
  }
  int N;
  cin >> N;
  rep(i,N){
    int b;
    cin >> b;
    rep(i,3)rep(j,3){
      if(A[i][j]==b) B[i][j]=true;
    }
  }
  rep(i,3){
    int tmp=0;
    rep(j,3){
      if(B[i][j]) tmp++;
    }
    if(tmp==3){
      Yes
      return 0;
    }
  }
  rep(j,3){
    int tmp=0;
    rep(i,3){
      if(B[i][j]) tmp++;
    }
    if(tmp==3){
      Yes
      return 0;
    }
  }
  if(B[0][0] && B[1][1] && B[2][2]){
    Yes
    return 0;
  }
  if(B[0][2] && B[1][1] && B[2][0]){
    Yes
    return 0;
  }
  No
  return 0;
}


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

int main(void)
{
  char s[200000];
  long long int sum = 0,i;
  
  scanf("%s", s);
  
  int l = strlen(s);
  
  for(i = 0;i < l;i++)
    sum += s[i] - '0';
  
  if(sum%9==0)
    printf("Yes");
  else
    printf("No");         

  return 0;
}


Measured memory_bytes: 1924
#include <iostream>
#include <string>

using namespace std;

string st(int, string);

int main(){ 
    int N;
    string S;
    string ans;
    cin >> N;
    cin >> S;
    ans = st(N,S);
    cout << ans;
    return 0;
}

string st(int N, string S){
    if (N % 2 == 0) {
        int num = N/2;
        for (int i = 0; i < num; i++)
        {
            if (S[i] != S[i+num])
            {
                return "No";
            }
        }
            return "Yes";
    }
    else{
        return "No";
    }
}


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

int N;
string S;

int main(){
    cin >> N >> S;
    int left = 0;
    int right = 0;
    for (int i = 1; i < N; i++){
        if (S[i] == 'E'){
            right += 1;
        }
    }
    int num = right + left;
    for (int i = 0; i < N - 1; i++){
        if (S[i] == 'E'){
            left = left;
        }else{
            left += 1;
        }
        if (S[i + 1] == 'E'){
            right -= 1;
        }else{
            right = right;
        }
        num = min(num, right + left);
    }
    cout << num << endl;
    return 0;
}

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (auto &&item : a)
    {
        cin >> item;
    }

    int sum = 0;
    for (auto &&item : a)
    {
        sum += item;
    }
    for (auto &&item : a)
    {
        if (item < ((double)sum / (double)(4.0*m)))
        {
            n--;
        }
    }

    if (n >= m)
        cout << "Yes";
    else
        cout << "No";
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
a = [0, 0, 0, 0, 0]
for i in range(5):
    a[i] = (int)(input())
k = (int)(input())
isExist = "Yay!"

for d in [d+1 for d in range(4)]:
    for i in range(4):
        if i + d < 5 and (a[i+d] - a[i] > k):
            isExist = ":("

print(isExist)

Measured memory_bytes: 3064
package main

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

var sc = bufio.NewScanner(os.Stdin)

func r() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n, c, k := r(), r(), r()
	t := make([]int, n)
	for i := 0; i < n; i++ {
		t[i] = r()
	}
	sort.Ints(t)

	bus := 1
	limit := t[0] + k
	ans := 1
	for i := 1; i < n; i++ {
		bus++
		if bus > c || t[i] > limit {
			ans++
			bus = 1
			limit = t[i] + k
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1408
#include <stdio.h>

int main(){
  int K,A,B;
  scanf("%d %d %d",&K,&A,&B);
  
  int L=K;
  int sw=0;
  while(L<=B){
    
    if(A<=L){
      sw=1;
    }
   
  L=L+K;  
  }
  
  if(sw==1){
    printf("OK\n");
  }else{
    printf("NG\n");
  }
  return 0;
}

Measured memory_bytes: 1664
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int N = str.length();
        int ans = 0;
        
        for(int i=0; i<N/2; i++){
            if(str.charAt(i) != str.charAt(N-i-1)){
                ans++;
            }
            //System.out.println(i);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35612
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#define maxn 2020
using namespace std;
typedef long long LL;
char c[maxn];
LL f[maxn][maxn];
LL k;
int n;
int dp[maxn][maxn];
char ans[maxn*2];
int main()
{
    scanf("%s%lld",c+1,&k);
    n=strlen(c+1);
    for(int i=1;i<=n;++i)
    {
        dp[i][i]=0;
        f[i][i]=1;
    }
    for(int l=2;l<=n;++l)
        for(int i=1;i+l-1<=n;++i)
        {
            int j=i+l-1;
            if(c[i]==c[j])
            {
                dp[i][j]=dp[i+1][j-1];
                if(i+1>j-1) f[i][j]=1;
                else f[i][j]=f[i+1][j-1];
            }
            else
            {
                if(dp[i+1][j]+1<dp[i][j-1]+1)
                {
                    dp[i][j]=dp[i+1][j]+1;
                    f[i][j]=f[i+1][j];
                }
                else if(dp[i+1][j]+1==dp[i][j-1]+1)
                {
                    dp[i][j]=dp[i+1][j]+1;
                    f[i][j]=f[i+1][j]+f[i][j-1];
                    if(f[i][j]>k) f[i][j]=k;
                }
                else
                {
                    dp[i][j]=dp[i][j-1]+1;
                    f[i][j]=f[i][j-1];
                }
            }
        }
    if(f[1][n]<k) printf("NONE\n");
    else
    {
        LL m=k;
        int l=1,r=dp[1][n]+n,L=1,R=n;
        while(L<R)
        {
            if(c[L]==c[R])
            {
                ans[l]=c[L];
                ans[r]=c[R];
                l++;
                r--;
                L++;
                R--;
            }
            else
            {
                if(dp[L+1][R]+1<dp[L][R-1]+1)
                {
                    ans[r--]=c[L];
                    ans[l++]=c[L];
                    L++;
                }
                else if(dp[L+1][R]+1==dp[L][R-1]+1)
                {
                    if(c[L]<c[R])
                    {
                        if(f[L+1][R]>=m)
                        {
                            ans[r--]=c[L];
                            ans[l++]=c[L];
                            L++;
                        }
                        else
                        {
                            m-=f[L+1][R];
                            ans[r--]=c[R];
                            ans[l++]=c[R];
                            R--;
                        }
                    }
                    else
                    {
                        if(f[L][R-1]>=m)
                        {
                            ans[r--]=c[R];
                            ans[l++]=c[R];
                            R--;
                        }
                        else
                        {
                            m-=f[L][R-1];
                            ans[r--]=c[L];
                            ans[l++]=c[L];
                            L++;
                        }
                    }
                }
                else
                {
                    ans[r--]=c[R];
                    ans[l++]=c[R];
                    R--;
                }
            }
        }
        if(L==R) ans[l]=c[L];
    printf("%s\n",ans+1);
    }
    return 0;
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

vi merge(const vi& a,const vi& us,const vi& vs)
{
	vi res;
	int i=0,j=0;
	while(i<us.size()&&j<vs.size())
		res.push_back(a[us[i]]>=a[vs[j]]?us[i++]:vs[j++]);
	res.insert(end(res),i+all(us));
	res.insert(end(res),j+all(vs));
	return res;
}

vi dfs(const vvi& g,const vi& a,int u,vi& vis)
{
	vis[u]=1;
	vi res;
	for(int v:g[u]) if(!vis[v])
		res=merge(a,res,dfs(g,a,v,vis));
	res.insert(begin(res),u);
	return res;
}

int main()
{
	for(int n;cin>>n&&n;){
		vi a(n);
		rep(i,n) cin>>a[i];
		sort(all(a));
		vvi g(n);
		rep(i,n) repi(j,i+1,n) if(__gcd(a[i],a[j])!=1){
			g[i].push_back(j);
			g[j].push_back(i);
		}
		vi vis(n),res;
		rep(i,n) if(!vis[i])
			res=merge(a,res,dfs(g,a,i,vis));
		rep(i,n) cout<<a[res[i]]<<" \n"[i==n-1];
	}
}


Measured memory_bytes: 17920
#include <bits/stdc++.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int a,b;
int y[200000],z[200000];
int mutu(){
	int l=0,r=1000000000005;
	while(r-l>1){
		int x=(l+r-1)/2,sum=0;
		f(i,a){
			sum+=max((int)(0),y[a-i-1]-x/z[i]);
		}
		if(sum>b)l=x+1;
		else r=x+1;
	}
	return l;
}
signed main(){
	cin>>a>>b;
	f(i,a)cin>>y[i];
	f(i,a)cin>>z[i];
	sort(y,y+a);
	sort(z,z+a);
	cout<<mutu()<<endl;
}


Measured memory_bytes: 3328
#include<iostream>
#include<cmath>
#include<climits>
using namespace std;

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

int solve(){
  int ans=INT_MAX;
  for(int i=1;i<=n+1000;i++){
    int dx,dy;
    int tmp;
    dy=abs(a/i-b/i);
    dx=abs(a%i-b%i);
    tmp=dy+dx;
    dy=abs(c/i-d/i);
    dx=abs(c%i-d%i);
    tmp+=dy+dx;
    ans=min(tmp,ans);
  }
  return ans;
}


int main(){
  cin>>n>>a>>b>>c>>d;
  a--;b--;c--;d--;
  cout<<solve()<<endl;
}

Measured memory_bytes: 1164
def solve(s)
    if s[0] =~ /[0-9]/
        return (s.to_i / 2) + 1
    else
        level = 0
        i = 0
        while s[i] == "["
            level += 1
            i += 1
        end
        st = "]" * level
        sub = Array.new
        while true
            t = s.index(st)
            break if t == nil
            sub.push(solve(s[1...(t + level - 1)]))
            s = s[(t + level)...s.length]
        end
        sub.sort!
        ret = 0
        0.upto(sub.size / 2) do |i|
            ret += sub[i]
        end
        return ret
    end
end
n = gets.to_i
n.times do
    s = gets.chomp
    p solve(s[1...(s.length - 1)])
end

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

int main()
{
    int m, k;
    cin >> m >> k;
    if(k >= (1 << m)){
        cout << -1 << endl;
        return 0;
    }
    if(m == 0){
        if(k == 0){
            cout << "0 0" << endl;
        }
        else{
            cout << -1 << endl;
        }
        return 0;
    }
    if(m == 1){
        if(k == 0){
            cout << "1 1 0 0" << endl;
        }
        else{
            cout << -1 << endl;
        }
        return 0;
    }
    for(int i = 0; i < (1 << m); i++){
        if(i == k) continue;
        cout << i << " ";
    }
    cout << k << " ";
    for(int i = (1 << m) - 1; i >= 0; i--){
        if(i == k) continue;
        cout << i << " ";
    }
    cout << k << endl;
}


Measured memory_bytes: 3636
import java.util.*
import kotlin.math.*

fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d:String = " ") = str().split(d)
fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
fun list() = list {toInt()}

fun <T> T.print() = println(this)

const val mod = 998244353L

fun main() {
	abc000X()
}

fun abc000X() {
	val n = int()
	val a = LongArray(n+1) {0L}

	var r=0L

	for(i in 1..n) {
		for(j in i..n step i)
			++a[j]
		r+=a[i]*i
	}
	println(r)
}


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

using namespace std;

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

int main(){
    int n, k;
    cin >> n >> k;
    int h[100005];
    int ans = 0;
    for(int i = 0; i < n; i++){
        cin >> h[i];
        if(h[i] >= k)ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        n:i64,
    }
    let ans = n * (2 * (n-1) + (n-1) * -1)/2;
    println!("{}",ans);
}


fn is_prime(x:i64) -> bool {
    if x == 2 {return true;}
    if x < 2 || x % 2 == 0 {return false;}
    let mut j = 3;
    while j <= (x as f64).sqrt() as i64 {
        if x % j == 0 {
            return false;
        }
        j += 2;
    }
    true
}


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

// 次の長さ 32 の数列の K  番目の項を出力してください。
// 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51

static int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main()
{
	int k;
	cin >> k;
	cout << a[k-1] << endl;
}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.List
import Data.Array

strToInt s = (read :: String -> Int)
           
           
main = do

  n <- readLn :: IO Int
  xn <- map read . words <$> getLine
  
  let an = sub $ reverse $ sort xn
  
  if (length an) > 1 then print ( (an !! 0) * (an !! 1) )
                     else print 0


sub :: [Int] -> [Int]
sub [] = []
sub (x:[]) = []
sub (x:xn) = if (x == (head xn))
             then [x] ++ sub (tail xn)
             else sub xn

Measured memory_bytes: 48508
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MAX = 310;
const long long INF = 1LL<<50;

long long G[MAX][MAX];
using pll = pair<long long, long long>;

int main() {
    int N, M; long long L;
    cin >> N >> M >> L;
    
    for (int i = 0; i < MAX; ++i) {
        for (int j = 0; j < MAX; ++j) G[i][j] = INF;
        G[i][i] = 0;
    }
    for (int i = 0; i < M; ++i) {
        int a, b; long long c;
        cin >> a >> b >> c; --a, --b;
        G[a][b] = G[b][a] = c;
    }

    vector<vector<pll> > dist(N, vector<pll>(N, {INF, INF}));
    for (int s = 0; s < N; ++s) {
        dist[s][s] = {0, 0};
        priority_queue<pair<pll, int>,
                       vector<pair<pll, int> >,
                       greater<pair<pll, int> > > que;
        que.push(make_pair(pll(0, 0), s));
        while (!que.empty()) {
            auto p = que.top();
            que.pop();
            
            long long v = p.second;
            long long kaisuu = p.first.first;
            long long used = p.first.second;
            
            if (p.first > dist[s][v]) continue;
            for (int nv = 0; nv < N; ++nv) {
                if (nv == v) continue;
                if (G[v][nv] > L) continue;
                long long nused = used + G[v][nv];
                pll np = {0, 0};
                if (nused > L) np = {kaisuu + 1, G[v][nv]};
                else np = {kaisuu, nused};

                if (chmin(dist[s][nv], np)) que.push(make_pair(np, nv));
            }
        }
    }

    int Q; cin >> Q;
    while (Q--) {
        int a, b; cin >> a >> b; --a, --b;
        
        long long res = dist[a][b].first;
        if (res >= INF) cout << -1 << endl;
        else cout << res << endl;
    }
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

struct max_flow{
    struct edge{int to,cap,rev;};
    vector<vector<edge>> graph;
    vector<bool> done;
    max_flow(int size):graph(size),done(size){}
    void add_edge(int from,int to,int cap){
        graph[from].push_back(edge{to,cap,(int)graph[to].size()});
        graph[to].push_back(edge{from,0,(int)graph[from].size()-1});
    }
    int dfs(int v,int t,int f){
        if(v==t) return f;
        done[v]=true;
        for(auto &e:graph[v]){
            if(done[e.to] or e.cap<=0) continue;
            int d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                graph[e.to][e.rev].cap+=d;
                return d;
            }
        }
        return 0;
    }
    int calc_max_flow(int s,int t){
        int flow=0;
        while(true){
            fill(done.begin(),done.end(),false);
            int f=dfs(s,t,inf);
            if(f==0) return flow;
            flow+=f;
        }
    }
};

void solve(){
    int v,e;
    cin >> v >> e;
    max_flow mf(v);
    rep(i,0,e){
        int s,t,c;
        cin >> s >> t >> c;
        mf.add_edge(s,t,c);
    }
    cout << mf.calc_max_flow(0,v-1) << endl;
}
int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n,t,l,b;
int board[111];
double mem[111][111][2];

double dfs(int x,int rest,bool lose){
	if(x==n)return 1.0;
	if(rest==0)return 0.0;
	if(!lose&&board[x]==1)return dfs(x,rest-1,true);
	if(board[x]==2)return dfs(0,rest,false);
	if(mem[x][rest][lose]!=-1)return mem[x][rest][lose];
	double res=0;
	repl(i,1,6+1){
		int nx=x+i;
		if(nx<=n)res+=(1.0/6.0)*dfs(nx,rest-1,false);
		else res+=(1.0/6.0)*dfs(n-(nx-n),rest-1,false);
	}
	return mem[x][rest][lose]=res;
}

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>n>>t>>l>>b;
		if(n==0)break;
		memset(board,0,sizeof(board));
		rep(i,l){
			int ll;
			cin>>ll;
			board[ll]=1;
		}
		rep(i,b){
			int bb;
			cin>>bb;
			board[bb]=2;
		}
		rep(i,111)rep(j,111)rep(k,2)mem[i][j][k]=-1;
		printf("%.10f\n", dfs(0,t,false));
	}
	return 0;
}

Measured memory_bytes: 3376
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        int N, M;
        cin >> N >> M;
        if (N == 0 && M == 0) return 0;
        vector<int> a(N);
        rep(i, N) cin >> a[i];
        a.push_back(0);
        N++;
        vector<int> aa(N*N);
        rep(i, N) rep(j, N) aa[i*N + j] = a[i] + a[j];
        sort(aa.begin(), aa.end());

        int ans = 0;
        rep(i, N*N) {
            int tmp = aa[i];
            int aim = M - tmp;
            if(aim < 0) continue;
            tmp += *(upper_bound(aa.begin(), aa.end(), aim) - 1);
            if(tmp <= M ) ans = max(ans, tmp);
        }
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 7316
#include <bits/stdc++.h>
using namespace std;
void main_sub(void);
int main(int argc, char* argv[]) {
    main_sub();
    return 0;
}
// int を int64_t にする
// g++ に -DUSE_STRICT_INT をつけるか、
// 下のコメントアウトを外すと無効化
// #define USE_STRICT_INT
using i64 = int64_t;
#ifndef USE_STRICT_INT
#define int i64
#endif
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF = (1 << 30);
constexpr i64 INFL = (1LL << 62);
constexpr i64 MOD = 1000000007;

void main_sub(void) {
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    vector<int> q(n);
    rep(i, n) cin >> q[i];
    vector<int> v(n);
    rep(i, n) v[i] = i + 1;
    int a = -1;
    int b = -1;
    int cnt = 0;
    while (next_permutation(all(v))) {
        bool p_flag = true;
        bool q_flag = true;
        rep(i, n) {
            if (v[i] != p[i]) p_flag = false;
            if (v[i] != q[i]) q_flag = false;
        }
        if (p_flag) a = cnt;
        if (q_flag) b = cnt;
        cnt++;
    };
    cout << abs(a - b) << endl;
    return;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	ll n;
	rl(n);
	n=n*n;
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e2 + 10;
LL p[N];
LL tot[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	p[0] = 1;
	for (int i = 1; i < N; i++) p[i] = p[i - 1] * 2 + 1;
	tot[0] = 1;
	for (int i = 1; i < N; i++) tot[i] = tot[i - 1] * 2 + 3;
	int n;
	LL x;
	cin >> n >> x;
	LL ans = 0;
	while (n >= 0)
	{
		if (n == 0)
		{
			ans++;
			break;
		}
		LL l = 1, r = tot[n];
		LL mid = (r + 1) / 2;
		if (x >= mid) ans += p[n - 1] + 1;
		if (x == r) ans += p[n - 1];
		if (x == l || x == mid || x == r) break;
		if (x > mid) x -= mid;
		else x--;
		n--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define double long double

const int N= 1e6+10;

int n,t,k;
string str;

int32_t main()
{
	IOS;
	
	string str;
	cin>>k;
	cin>>str;
	if(str.length()<= k)
	    cout<<str<<endl;
    else
	    cout<<str.substr(0,k)+"..."<<endl;   
	return 0;
	
	
}

Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#include<map>
#include <limits>
# include <iomanip>
#define INF 1000000009;
using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}
int kaizyo(int a) {
	long long ans = 1;
	for (int i = a; i > 0; i--) {
		ans *= i;
		ans = ans % 1000000007;
		//cout << ans << endl;
	}
	ans = ans % 1000000007;
	return ans;
}
int main() {
	int a = 0, b = 0;
	cin >> a >> b;
	if (abs(a - b) % 2 != 0) {
		cout << "IMPOSSIBLE" << endl;
		return 0;
	}
	cout << abs(a - b) / 2 + min(a, b) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
 
using namespace std;
 
int N;
int a[100001];
int rems;
 
int main() {
    scanf("%d", &N);
    int x;
    for(int i = 0; i<N; i++) {
        scanf("%d", &x);
        if(x > N) {
            rems++; continue;
        }
        a[x]++;
    }
    for(int i = 1; i<=N; i++) {
        if(a[i] < i) {
            rems += a[i];
        } else {
            rems += a[i] - i;
        }
    }
    printf("%d\n", rems);
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#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; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

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

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    string A,B;
    cin >> A >> B;
    print(B << A);
    return 0;
}

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

int main(){
    int K, X, Y;
    cin >> K >> X >> Y;
    if(abs(X) + abs(Y) == K){
        cout << "1\n" << X << " " << Y << endl;
        return 0;
    }

    int xsign = 1, ysign = 1;
    bool sw = false;
    if(X < 0){
        X *= -1;
        xsign = -1;
    }
    if(Y < 0){
        Y *= -1;
        ysign = -1;
    }
    if(X < Y){
        swap(X, Y);
        sw = true;
    }

    int D = X+Y;
    int A = max(2, (D+K-1)/K);
    int L = A * K;
    if((L-D)%2){
        A++;
        L += K;
        if((L-D)%2){
            cout << -1 << endl;
            return 0;
        }
    }
    int R = (L-D)/2;

    vector<pair<int, int>> ans;
    
    if(A == 3){
            int b = min(R, (R+X-Y)/2);
            int a = R-b;
            for(int i=1; i<=A; i++){
            int l = i*K;
            if(l <= a){
                ans.emplace_back(-l, 0);
            }else if(l <= a+Y+b){
                l -= a;
                ans.emplace_back(-a, l);
            }else if(l <= a+Y+b+a+X){
                l -= a+Y+b;
                ans.emplace_back(l-a, b+Y);
            }else{
                l -= a+Y+b+a+X;
                ans.emplace_back(X, Y + (b-l));
            }
        }
    }else{
        for(int i=1; i<=A; i++){
            int l = i*K;
            if(l <= Y+R){
                ans.emplace_back(0, l);
            }else if(l <= Y+R+X){
                l -= Y+R;
                ans.emplace_back(l, Y+R);
            }else{
                l -= Y+R+X;
                ans.emplace_back(X, Y + (R - l));
            }
        }
    }

    if(sw) for(int i=0; i<A; i++) swap(ans[i].first, ans[i].second);
    cout << A << endl;
    for(auto& p : ans){
        printf("%d %d\n", p.first*xsign, p.second*ysign);
    }
    
    return 0;
}


Measured memory_bytes: 3952
#include <bits/stdc++.h>
#define int long long
using namespace std;


signed main() {
  int N;
  cin >> N;
  
  vector<pair<int, int>> A;
  int num;
  int zyun;
  for( int i = 0; i < N; i++ ){
    cin >> num;
    zyun = i;
    A.push_back(make_pair(num, zyun));
  }
  sort(A.begin(), A.end());
  for( int i = 0; i < N; i++ ){
    tie( num, zyun ) = A.at(i);
    cout << zyun+1 << " ";
  }
    
}


Measured memory_bytes: 2544
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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;}
int const INF = 1001001001;


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

int N,K;
cin >> N >> K;
int ans = 0;
rep(i,N) {
    int x;
    cin >> x;
    ans += 2 * min(x,K-x);
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

#include <vector>

struct UnionFind
{
    vector<int> data;

    UnionFind(int sz)
    {
        data.assign(sz, -1);
    }

    bool unite(int x, int y)
    {
        x = root(x), y = root(y);
        if (x == y)
            return false;
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int root(int k)
    {
        if (data[k] < 0)
            return k;
        data[k] = root(data[k]);
        return data[k];
    }

    int size(int k)
    {
        return (-data[root(k)]);
    }

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

struct BipartiteGraph : UnionFind
{
    vector<int> color;

    BipartiteGraph(int N) : color(2 * N, -1), UnionFind(2 * N) {}

    /*
    color u, v by same color ->  unite(u, v) && unite(u + N, v + N)
    color u, v by different color -> unite(u + N, v) && unite(u, v + N)
    */

    bool BG_unite(int u, int v, bool same)
    {
        int N = ((int)color.size()) / 2;
        if (same == true)
        {
            unite(u, v);
            unite(u + N, v + N);
        }
        else
        {
            unite(u + N, v);
            unite(u, v + N);
        }
    }

    // 0, 1, ..., v - 1 -> left; v, v + 1, ..., 2 * v - 1 -> right;
    bool BG_coloring()
    {
        int N = ((int)color.size()) / 2;
        for (int i = 0; i < N; i++)
        {
            int s = root(i), t = root(i + N);
            if (s == t)
                return false;
            if (color[s] < 0)
                color[s] = 0, color[t] = 1;
        }
        return true;
    }

    //return k's color
    bool operator[](int v)
    {
        return (bool)(color[root(v)]);
    }
};

int main()
{
    int N, M;
    cin >> N >> M;
    BipartiteGraph bg(N);

    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        bg.BG_unite(a, b, 0);
    }

    if (bg.BG_coloring() == false)
    {
        cout << ((ll)N * (ll)(N - 1LL)) / 2 - (ll)M << endl;
    }
    else
    {
        map<bool, int> mp;
        for (int i = 0; i < N; i++)
        {
            mp[bg[i]]++;
        }
        cout << (ll)mp[false] * (ll)mp[true] - (ll)M << endl;
    }
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

static const int MAX = 200000;

int main () {

  int n, R[MAX];

  cin >> n;

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

  int max = -1000000000;
  int min = R[0];

  for (int i = 1; i < n; i++) {

    if (max < R[i] - min) {
      max = R[i] - min;
    }

    if (min > R[i]) {
      min = R[i];
    }

  }

  cout << max << endl;

}

Measured memory_bytes: 3848
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using ll = long long;
//西暦⇒時代の歴
struct Data
{
    string s;
    ll E, W;
};
int main()
{
    ll N, Q;
    while (cin >> N >> Q, N || Q)
    {
        vector<Data> v;
        for (int i = 0; i < N; ++i)
        {

            Data e;
            cin >> e.s >> e.E >> e.W;
            v.push_back(e);
        }

        for (int i = 0; i < Q; ++i)
        {
            ll t;
            cin >> t;
            bool ok = false;
            for (int j = 0; j < N; ++j)
            {
                if (t <= v[j].W && t > v[j].W - v[j].E)
                {
                    cout << v[j].s << " " << t - (v[j].W - v[j].E) << endl;
                    ok = true;
                }
            }
            if (!ok)
                cout << "Unknown" << endl;
        }
    }
}


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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M;
  cin >> N >> M;

  vector<int> m(M);
  vector<int> c(100001, 0);  
  vector<int> A(100001, 0);
  vector<int> all;  
  for ( int i = 0; i < M; i++ ) {
    cin >> m[i];
    m[i]--;    
    c[m[i]]++;    
  }

  int add = 0;
  {
    int cnt = 0;
    bool f = false;    
    for ( int i = 0; i < N; i++ ) {
      if ( !f ) {
	if ( c[i] ) {
	  f = true;	  
	} else {
	  add++;
	}
      } else {
	if ( c[i] ) {
	  A[cnt]++;
	  all.push_back(cnt);	  
	  cnt = 0;	  
	} else {
	  cnt++;	  
	}
      }
    }

    if ( cnt ) all.push_back(cnt);    
  }

  int sum = 0;  
  for ( int i : all ) sum += i;
  sort(all.begin(), all.end());
  vector<int> B(N, 0);
  int idx = 0;  
  for ( int i = 0; i < N; i++ ) {
    B[i] = sum + add;    
    while ( idx < all.size() && all[idx]-i <= 0 ) idx++;    
    sum -= (all.size()-idx);    
  }

  reverse(B.begin(), B.end());

  // for ( int i : B ) cout << i << endl;
   
  int Q;
  cin >> Q;
  vector<int> l(Q);  
  for ( int i = 0; i < Q; i++ ) {
    cin >> l[i];    
    int it = upper_bound(B.begin(), B.end(), l[i]) - B.begin();
    if ( N-it+1 <= 0 || N-it+1 > N ) cout << -1 << endl;    
    else cout << N-it+1 << endl;          
  }    
  
  return 0;
}



Measured memory_bytes: 7724
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
const lli mod = 998244353;
int main()
{
	lli a; cin >> a;
	pair<lli, lli> arr[a + 50];
	for(int i=0; i<a; i++)
		cin >> arr[i].first >> arr[i].second;
	sort(arr, arr + a);
	stack<pair<lli, lli> > S;
	pair<lli, lli> tmp(a, 2e9);
	S.push(tmp);
	lli dp[a + 50];
	dp[a] = 1;
	for(int i=a - 1; i >= 0; i--)
	{
		while(S.top().second < arr[i].first + arr[i].second)
			S.pop();
		lli tmp = S.top().first;
		S.push(make_pair(i, arr[i].first));
		dp[i] = (dp[i + 1] + dp[tmp]) % mod;
	}
	cout << dp[0] << '\n';
	return 0;
}

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

int main()
{
    ll m = 1000000007;
    int n, k;
    cin >> n >> k;
    vector<ll> po;
    vector<ll> ne;
    for (int i = 0; i < n; i++)
    {
        ll t;
        cin >> t;
        if (t > 0)
            po.push_back(t);
        else
            ne.push_back(abs(t));
    }
    sort(po.begin(), po.end());
    sort(ne.begin(), ne.end());
    ll ans = 1;
    bool pos = 1;
    if (k % 2 == 1)
    {
        if (!(po.size() >= 1))
            pos = 0;
    }
    for (int i = 0; i < k;)
    {
        if (pos)
        {
            if (k - i >= 2)
            {
                if (po.size() >= 2 && ne.size() >= 2)
                {
                    if (po[po.size() - 1] * po[po.size() - 2] > ne[ne.size() - 1] * ne[ne.size() - 2])
                    {
                        ans = ans * po[po.size() - 1] % m;
                        ans = ans * po[po.size() - 2] % m;
                        po.pop_back();
                        po.pop_back();
                    }
                    else
                    {
                        ans = ans * ne[ne.size() - 1] % m;
                        ans = ans * ne[ne.size() - 2] % m;
                        ne.pop_back();
                        ne.pop_back();
                    }
                    i += 2;
                }
                else if (po.size() >= 2)
                {
                    ans = ans * po[po.size() - 1] % m;
                    ans = ans * po[po.size() - 2] % m;
                    po.pop_back();
                    po.pop_back();
                    i += 2;
                }
                else if (ne.size() >= 2)
                {
                    ans = ans * ne[ne.size() - 1] % m;
                    ans = ans * ne[ne.size() - 2] % m;
                    ne.pop_back();
                    ne.pop_back();
                    i += 2;
                }
                else
                {
                    ans = ans * po[po.size() - 1] % m;
                    po.pop_back();
                    i++;
                }
            }
            else if (po.size() >= 1)
            {
                ans = ans * po[po.size() - 1] % m;
                po.pop_back();
                i++;
            }
            else
            {
                ans = ans * -ne[ne.size() - 1] % m;
                ne.pop_back();
                i++;
            }
        }
        else
        {
            for (; i < k; i++)
            {
                ans = ans * ne[i] % m;
            }
        }
    }
    if (pos)
    {
        if (ans >= 0)
            cout << ans << endl;
        else
            cout << (m + ans) % m << endl;
    }
    else
        cout << (m - ans) % m << endl;
}

Measured memory_bytes: 5476
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN2(d,n);
  if(n!=100) OUT((int)pow(100,d)*n);
  else OUT((int)pow(100,d)*(n+1));
}

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

int main()
{
	int a, b, i, ret_scanf;
	int iFind;
	
	iFind = 0;
    // フォーマットに従って標準入力から入力
    ret_scanf = scanf("%d %d ", &a, &b);
    
    for (i = 0; i < 1000000000; i++) {
    	if (abs(a - i ) == abs(b - i) ) {
    		iFind = 1;
    		break;
    	}
    }
    if (iFind == 1) {
    	printf("%d", i);
    } else {
    	printf("IMPOSSIBLE");
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
#define N 1000100
#define k 100000000 
#define F (rt<<1)
#define s int
#define G (rt<<1|1)
#define o first
#define u second
#define I push_back
#define K return
#define X void
struct J{s a,b,H;}p[N];typedef pair<s,s> pa;bool operator < (J x,J y){if (x.a==y.a) K x.b>y.b;K x.a>y.a;}
priority_queue<J> q;s n,i,a[N],A,t[N];pa m[N<<3];vector
 e[N],ans;X E(pa &x,pa y) {x.o=min(x.o,y.o)
,x.u=min(x.u,y.u);}X c(s rt,s l,s r){m[rt].o=k;m[rt].u=k;if (l==r){if (l&1) m[rt].o=a[l];else 
m[rt].u=a[l];K ;}s D=(l+r)/2;c(F,l,D);c(G,D+1,r);E(m[rt],m[F]),E(m[rt],m[G]);}pa b(s rt,s l,s r,s x,s y)
{if (x<=l&&r<=y) K m[rt];s D=(l+r)/2;pa C=make_pair(k,k);if(x<=D) E(C,b(F,l,D,x,y));if (y>=D+1) E(C,b(G,D+1,r,x,y));
K C;}s d(s l,s r){s f,w,h,z;if (l&1){f=b(1,1,n,l,r).o,h=t[f];w=b(1,1,n,h+1,r).u,z=t[w];}else
{f=b(1,1,n,l,r).u,h=t[f];w=b(1,1,n,h+1,r).o,z=t[w];}p[++A].a=f,p[A].b=w,p[A].H=A;s B=A;if (h!=l)e[B].I(d(l,h-1))
;if(h+1!=z)e[B].I(d(h+1,z-1));if (z!=r)  e[B].I(d(z+1,r));K B;}s main(){scanf("%d",&n);for (i=1;i<=n;i++)scanf("%d",&a[i])
,t[a[i]]=i;c(1,1,n);d(1,n);q.push(p[1]);while (!q.empty()){s x=q.top().H;q.pop();printf("%d %d ",p[x].a,p[x].b);
for (i=0;i<(s)e[x].size();i++)q.push(p[e[x][i]]);}
}

Measured memory_bytes: 54912
n = int(input())
l = [x for x in map(int, input().split())]
l = sorted(l)

cnt = 0
for i in range(n - 2):
    a = l[i]
    k = i + 2
    for j in range(i + 1, n - 1):
        b = l[j]
        while(l[k] < a + b):
            k += 1
            if k == n:
                break
            else:
                pass

        k -= 1
        cnt += k - j
print(cnt)


Measured memory_bytes: 3188