akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

class Main{
    static int[][] dp,  ab;
    static int n, t;
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt(); t=sc.nextInt();
        ab=new int[n][2];
        for(int i=0;i<n;i++){
            int a=sc.nextInt(), b=sc.nextInt();
            ab[i][0]=a; ab[i][1]=b;
        }
        sc.close();
        Arrays.sort(ab, (u, v)->u[0]>v[0]?1:u[0]<v[0]?-1:0);
        dp=new int[n][t+1];
        System.out.println(dp(0, t));
    }
    static int dp(int i, int rest){
        if(rest<=0 || i>=n) return 0;
        if(dp[i][rest]>0) return dp[i][rest];
        return dp[i][rest]=Math.max(dp(i+1, rest), dp(i+1, rest-ab[i][0])+ab[i][1]);
    }
}


Measured memory_bytes: 69972
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,cnt=0;
  int d[101];
  cin>>n;
  for(int i=0;i<n;i++)cin>>d[i];
  sort(d,d+n);
  reverse(d,d+n);
  for(int i=0;i<n;i++){
    if(i!=0){
      if(d[i-1]>d[i])cnt++;
    }
    else cnt++;
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong bignum = 1_000_000_007;
alias Pair = Tuple!(long, "number", long, "times");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    auto n = lread();
    auto p = aryread();
    long count;
    foreach (i; 1 .. n - 1)
    {
        if(p[i - 1] < p[i] && p[i] < p[i + 1])
            count++;
        if(p[i - 1] > p[i] && p[i] > p[i + 1])
            count++;
    }
    count.writeln();
}


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

ll N;
string S;

int main() { 
    cin >> N >> S;
    S.push_back('%');
    ll out = 0;
    for (int i = 0; i < N; i++) {
      if (S[i] == S[i + 1]) {
        continue;
      } else {
        out++;
      }
    }
    cout << out << endl;
    return 0; 
}

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

int main(){
  int w, h, n;
  cin >> w >> h >> n;
  int xt = 0, yt = 0;
  for (int i = 0; i < n; i++) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1)
    xt = max(x, xt);
    if (a == 2)
    w = min(x, w);
    if (a == 3)
    yt = max(y, yt);
    if (a == 4)
    h = min(y, h);
  }
  int ans;
  if (w >= xt && h >= yt)
  ans = (w - xt) * (h - yt);
  else
  ans = 0;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>

using namespace std;

#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

int main(int argc, char *argv[]) {
  int a;
  cin >> a;
  cout << a + a*a + a*a*a << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}

signed main (){
    int n,m;cin>>n>>m;
    if(n>=m){
        cout<<0<<endl;
        return 0;
    }
    vector<int> v(m);
    rep(i,0,m)cin>>v[i];
    vector<int> dis(m-1);
    sort(all(v));
    rep(i,0,m-1)dis[i]=v[i+1]-v[i];
    Sort(dis);
    cout<<accumulate(dis.begin(),dis.begin()+(m-n),0)<<endl;
    
}
/*
2 5
10 12 1 2 14
*/


Measured memory_bytes: 1792
package main

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

type node struct {
	key  int32
	prev *node
	next *node
}

func (n *node) rPrint(buf *bytes.Buffer) {
	buf.WriteString(fmt.Sprint(n.key))
	if n.next != nil {
		buf.WriteString(" ")
		n.next.rPrint(buf)
	}
	return
}

func (n *node) Delete(first, last *node) (*node, *node) {
	if n.prev != nil && n.next != nil {
		//swap
		n.prev.next = n.next
		n.next.prev = n.prev
		return first, last
	}

	if n.next == nil && n.prev == nil {
		return nil, nil
	}

	if n.prev == nil {
		first = n.next
		n.next.prev = nil
	}

	if n.next == nil {
		last = n.prev
		n.prev.next = nil
	}

	return first, last
}

func initNode(key int32) *node {
	return &node{
		key: key,
	}
}

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	var first, last *node
	stdin.Scan()

	for stdin.Scan() {
		cmd := stdin.Text()
		switch cmd {
		case "deleteFirst":
			first, last = first.Delete(first, last)
		case "deleteLast":
			first, last = last.Delete(first, last)
		default:
			xcmd := strings.Split(cmd, " ")
			k, _ := strconv.Atoi(xcmd[1])
			k32 := int32(k)
			switch xcmd[0] {
			case "delete":
				for a := first; a != nil; a = a.next {
					if a.key == k32 {
						first, last = a.Delete(first, last)
						break
					}
				}
			case "insert":
				n := initNode(k32)
				n.next = first
				if first != nil {
					first.prev = n
				}

				first = n
				if last == nil {
					last = n
				}
			}
		}
	}
	var buf bytes.Buffer
	first.rPrint(&buf)
	fmt.Println(buf.String())
}



Measured memory_bytes: 94948
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const ll INF = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int main() {
	int N, M;
	cin >> N >> M;
	const int NMAX = 1000;
	const int MMAX = 2000;
	int a[MMAX], b[MMAX];
	ll c[MMAX];
	for (int i = 0; i < M; ++i) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--, b[i]--;
		c[i] = -c[i];
	}
	ll dist[NMAX];
	for (int i = 0; i < N; ++i) {
		dist[i] = INF;
	}
	dist[0] = 0;
	for (int loop = 0; loop < N - 1; ++loop) {
		for (int i = 0; i < M; ++i) {
			if (dist[a[i]] == INF)continue;
			if (dist[b[i]] > dist[a[i]] + c[i]) {
				dist[b[i]] = dist[a[i]] + c[i];
			}
		}
	}
	ll ans = dist[N - 1];
	bool negative[NMAX];
	for (int i = 0; i < N; ++i) {
		negative[i] = false;
	}
	for (int loop = 0; loop < N; ++loop) {
		for (int i = 0; i < M; ++i) {
			if (dist[a[i]] == INF)continue;//関係にない負閉路は無視
			if (dist[b[i]] > dist[a[i]] + c[i]) {
				dist[b[i]] = dist[a[i]] + c[i];
				negative[b[i]] = true;
			}
			if (negative[a[i]] == true) {
				negative[b[i]] = true;
			}
		}
	}
	if (negative[N - 1]) {
		cout << "inf" << endl;
	}
	else {
		cout << -ans << endl;
	}
	return 0;
}

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

static const int N = 100;

int main() {
  int M[N][N];
  int n, u, k, v;

  cin >> n;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) M[i][j] = 0;
  }

  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for (int j = 0; j < k; j++) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if ( j ) cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }

  return 0;

}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ld pi = 3.14159265358;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c;
    cin >> a >> b >> c;
    if(b - a == c - b)cout << "YES" << "\n";
    else cout << "NO" << endl;
}

Measured memory_bytes: 3648
#include<iostream>

using namespace std;
typedef long long ll;

int main(void){
  ll a,b,c;
  cin >> a >> b >> c;
  ll ret;
  if ( a + b + 1 >= c){
    ret = b + c;
  }
  else ret = b + (a+b+1);
  cout << ret << endl;
  return 0;
}
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<P> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i + 1;
    }
    sort(all(a));
    for (int i = 0; i < n; i++) {
        cout << a[i].second;
        if (i < n - 1) {
            cout << " ";
        }
    }
    cout << endl;
}

Measured memory_bytes: 1664
#include <iostream>
#include <iterator>
#include <cstdio>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <chrono>
#include <functional>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") {
		if (judge_exp) {
			cout << ok << endl;
		} else {
			cout << ng << endl;
		}
	}

	int ncr(int left, int right) {
		right = min(left - right, right);
		int ans = 1;
		for (int i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000256;
	const int tenfive = 100100;
}

using namespace atcoder;

int main(void) {
	int a;
	cin >> a;
	if (a % 2 == 0) {
		cout << a << endl;
	}
	else {
		cout << a*2 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    int ans = 0;
    vector<int> A(n), B(n);
    REP(i, n) cin >> A[i];
    REP(i, n) cin >> B[i];
    REP(i, n){
        ans += A[i] - B[i] > 0 ? A[i] - B[i] : 0;
    } 
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;
const ll INF = 10000;

ll ans;
ll N;
vector<vector<pair<ll, ll> > > XY;

bool judge(vector<bool>& X){
    REP(i,N){
        if(!X[i]) continue;
        for(auto&& p : XY[i]){
            if(X[p.first] != p.second)
                return false;
        }
    }
    return true;
}

void dfs(int v, vector<bool>& X){
    if(v == N){
        bool valid = judge(X);
        if(valid){
            ll tmp = 0;
            for(auto&& x : X){
                if(x) tmp++;
            }
            chmax(ans, tmp);
        }
        return;
    }
    
    X.push_back(true);
    dfs(v+1, X);
    X.pop_back();

    X.push_back(false);
    dfs(v+1, X);
    X.pop_back();
}

int main(){
    cin >> N;
    XY.resize(N);
    REP(i,N){
        ll a;
        cin >> a;
        REP(k,a){
            ll x, y;
            cin >> x >> y;
            x--;
            XY[i].emplace_back(x, y);
        }
    }

    ans = 0;
    vector<bool> X;
    dfs(0, X);
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import itertools

def solve(N, F, P):
    max_prof = -1 * float('inf')
    for seq in itertools.product([True,False], repeat = 10):
        if not any(seq):
            continue

        prof = 0
        for f,p in zip(F,P):
            prof += p[sum(itertools.compress(f, seq))]
        max_prof = max(prof,max_prof)
    print(max_prof)


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N = int(input())
    F = []
    P = []
    for i in range(N):
        F.append(list(map(int,input().split())))
    for i in range(N):
        P.append(list(map(int,input().split())))

    solve(N, F, P)



if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	// Code for B - Snuke's Coloring 2 (ABC Edit)
	var W, H, N int
	fmt.Scanf("%d %d %d", &W, &H, &N)

	x := make([]int, N)
	y := make([]int, N)
	a := make([]int, N)

	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d %d", &x[i], &y[i], &a[i])
	}

	var X1, Y1, X2, Y2 int
	X1 = 0
	Y1 = 0
	X2 = W
	Y2 = H
	for i := 0; i < N; i++ {
		if a[i] == 1 {
			if X1 <= x[i] {
				X1 = x[i]
			}
		} else if a[i] == 2 {
			if X2 >= x[i] {
				X2 = x[i]
			}
		} else if a[i] == 3 {
			if Y1 <= y[i] {
				Y1 = y[i]
			}
		} else {
			if Y2 >= y[i] {
				Y2 = y[i]
			}
		}
	}

	if X2-X1 < 0 || Y2-Y1 < 0 {
		fmt.Println("0")
	} else {
		fmt.Println((X2 - X1) * (Y2 - Y1))
	}
}


Measured memory_bytes: 1836
import java.util.HashSet;
import java.util.Set;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.io.*;
import java.util.*;
import java.util.Arrays;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner();
        try (final FastWriter writer = new FastWriter()) {
            final int N = scanner.nextInt(), K = scanner.nextInt();
            final long[] p = new long[N];
            for (int i = 0; i < N; i++) p[i] = scanner.nextLong();
            final long[] a = new long[N + 1];
            for (int i = 0; i < N; i++) a[i + 1] = a[i] + p[i];
            long max = 0;
            for (int i = 0; i + K <= N; i++) {
                max = Math.max(max, a[i + K] - a[i]);
            }
            writer.println((double)(max + K) / 2);
        }
    }
}

class FastWriter extends PrintWriter {
    public FastWriter() {
        super(new BufferedOutputStream(System.out));
    }

    public static void main(final String[] args) {
        try (final FastWriter w = new FastWriter()) {
            w.println(32);
        }
    }
}

class FastScanner {
    private final BufferedReader br;
    private StringTokenizer st;

    public FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (final IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (final IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}



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

#define ll long long
#define f first
#define s second
#define inf 1e15
#define mod 1000000007

#define N 300005

string s;
ll n,m,x,y,d,k;
ll a[N];

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
	int t=1;
//	cin>>t;
	while(t--){
	    
	    
	    cin>>n;
	    ll prefix[n];
	    for(int i=0;i<n;i++){
	        cin>>a[i];
	    }
	    prefix[n-1]=a[n-1];
	    
	    for(int i=n-2;i>=0;i--){
	        prefix[i]=(prefix[i+1]+a[i])%mod;
	    }
	    
	    
	    ll ans=0;
	    
	    for(int i=0;i<n;i++){
	        
	        ans=(ans+(a[i]*((prefix[i]-a[i]+mod)%mod)%mod))%mod;
	    }
	    
	    
	    cout<<ans<<"\n";
	    
	    
	}
	return 0;
}


Measured memory_bytes: 6776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

int main() {
    int n; cin >> n;
    int buttons[n];
    int ans = 1;
    for(int i = 0;i < n;i++){
        cin >> buttons[i];
    }
    
    int button = buttons[0]-1;
    if(buttons[0] == 2){
        cout << ans << endl;
        return 0;
    }
    for(int i = 1;i < n;i++){
        if(buttons[button] == 2){
            ans++;
            break;
        }else{
            button = buttons[button]-1;
            ans++;
            if(i == n-1){
                ans = -1;
            }
        }
    }
    cout << ans << endl;
    
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(150) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define Lower(v,X) lower_bound(v.begin(),v.end(),X)-v.begin();
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> S;UE(S);Out(S.size());
}


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

int gcd(int a, int b) {
    while (b > 0) {
        int tmp = b;
        b = a % b;
        a = tmp;
    }
    return a;
}

int main() {
    int x, y;
    std::cin >> x;
    std::cin >> y;
    if (x > y) {
        std::cout << gcd(x, y) << std::endl;
    } else if (x < y) {
        std::cout << gcd(y, x) << std::endl;
    } else if (x == y) {
        std::cout << gcd(x, y) << std::endl; 
    }
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1000000007;

void add(long long &a, long long b) {a+=b;if(a>=MOD)a-=MOD;}

int H, W, K;
long long solve() {
    --K;
    vector<vector<long long> > dp(H+1, vector<long long>(W, 0));
    dp[0][0] = 1;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            //cout << i << ", " << j << ": " << dp[i][j] << endl;
            for (int bit = 0; bit < 1<<(W-1); ++bit) {
                bool ok = true;
                for (int k = 0; k < W-2; ++k) {
                    if ((bit & (1<<k)) && (bit & (1<<(k+1)))) ok = false;
                }
                if (!ok) continue;
                int nj = j;
                if (bit & (1<<j)) nj = j+1;
                else if (j > 0 && (bit & (1<<(j-1)))) nj = j-1;
                add(dp[i+1][nj], dp[i][j]);
            }   
        }
    }
    return dp[H][K];
}

int main() {
    while (cin >> H >> W >> K) cout << solve() << endl;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: i64,
    x: i64,
    d: i64,
  }
  if d == 0 {
    if x == 0 {
      puts!("1\n");
    } else {
      puts!("{}\n", n + 1)
    }
    return;
  }
  use std::collections::BTreeMap;
  let mut range = BTreeMap::new();
  for i in 0 .. n + 1 {
    let left = i * (i - 1) / 2;
    let right = i * (2 * n - i - 1) / 2;
    range.entry((i * x) % d).or_insert(vec![]).push((i * x + left * d, i * x + right * d));
  }
  let mut ans = 0i64;
  for v in range.values() {
    let mut rs = vec![];
    for &(l, r) in v {
      if l < r {
        rs.push((l, false));
        rs.push((r, true));
      } else {
        rs.push((l, true));
        rs.push((r, false));
      }
    }
    rs.sort();
    let mut open = 0;
    let mut last = 0;
    for &(p, r) in &rs {
      if r {
        open -= 1;
        if open == 0 {
          ans += (p - last).abs() / d.abs() + 1;
        }
      } else {
        if open == 0 {
          last = p;
        }
        open += 1;
      }
    }
  }

  puts!("{}\n", ans);
}


Measured memory_bytes: 37116
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};


int main() {

	long long  n; cin >> n;
	vector<long long > cnt(60, 0);
	for (long long  i = 1; i <= n; i++) {
		long long  a; cin >> a;
		for (long long  j = 0; j <= 59; j++) cnt[j] += ((a & (1ll << j)) != 0);
	}

	long long  ans = 0;
	for (long long  j = 0; j <= 59; j++) {
		ans = ((ans % MOD) + (((cnt[j] % MOD * (n - cnt[j]) % MOD) % MOD) * ((1ll << j) % MOD)) % MOD) % MOD;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void)
{
  int h,w,i,j;
  
  while(1){
    scanf("%d %d",&h,&w);
    if (h==0 && w ==0)
      break;
    else{
      for(i=0;i<=h-1;i++){
	for (j=0;j<=w-1;j++){
	  printf("#");}
	printf("\n");
      }
      printf("\n");
    }
  }
  return 0;
}

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

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int N,C1;
ll D[31][100001]={};
ll S,T,C;
int main() {
	cin>>N>>C1;

	for(int i=0;i<N;i++){
		cin>>S>>T>>C;
		for(int j=S-1;j<T;j++){
			D[C][j]=1;
		}
	}

	int total=0;
	for(int i=0;i<100001;i++){
		int K=0;
		for(int j=1;j<31;j++){
			if(D[j][i]==1)K+=1;
		}
		total=max(total,K);
	}

	cout<<total<<endl;

	return 0;
}


Measured memory_bytes: 23808
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define all(v) v.begin(), v.end() // sort(all(array))
#define INF 1000000000
#define mod 1000000007
#define EPS 0.001
using namespace std;
using ll = long long;
using vi = vector<int>; //vi array(要素数, 初期値)
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>; //vvi table(行数, vi(列数, 初期値))
using vvc = vector<vc>;
using vvs = vector<vs>;
using vvb = vector<vb>;

//解法1 long double型の利用
int main() {
    long double a, b; cin >> a >> b;
    /*long longへのキャストで1.00-->0.9999...となるかもしれない
    ==> +0.001(EPS)をする*/
    cout << (ll)(a * b + EPS) << endl;
}

/*解法2 文字列の利用
int main() {
    ll a; cin >> a;
    string b; cin >> b;
    ll b100 = (b[0] - '0') * 100 + (b[2] - '0') * 10 + (b[3] - '0');
    cout << a * b100 / 100 << endl;
}
*/



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

int main() {
	string str;
	int q;
	cin >> str >> q;
	for(int i = 0; i < q; i++) {
		string order;
		cin >> order;
		if(order == "print") {
			int a, b;
			cin >> a >> b;
			for(int i = a; i <= b; i++) {
				cout << str[i];
			}
			cout << "\n";
		}
		if(order == "reverse") {
			int a, b;
			cin >> a >> b;
			string tmp = str.substr(a, b-a+1);
			reverse(tmp.begin(), tmp.end());
			for(int i = a; i <= b; i++) {
				str[i] = tmp[i - a];
			}
		}
		if(order == "replace") {
			int a, b;
			string replace;
			cin >> a >> b >> replace;
			for(int i = a; i <= b; i++) {
				str[i] = replace[i - a];
			}
		}
	}
}


Measured memory_bytes: 3232
#include <stdio.h>

int main() {
  int h, w;
  scanf("%d%d\n", &h, &w);
  int g[h][w], m[h][w], cnt = 0;
  for (int i=0; i<h; i++) for (int j=0; j<w; j++) m[i][j] = 0;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      scanf("%d", g[i]+j);
      if ((g[i][j]+m[i][j])%2) {
        if (j!=w-1) {
          m[i][j+1]++;
          cnt++;
        }
        else if (i!=h-1) {
          m[i+1][j]++;
          cnt++;
        }
      }
    }
  }
  printf("%d\n", cnt);
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (g[i][j]%2 == 0) continue;
      if (j != w-1) {
        g[i][j+1]++;
        printf("%d %d %d %d\n", i+1, j+1, i+1, j+2);
      } else if (i != h-1){
        g[i+1][j]++;
        printf("%d %d %d %d\n", i+1, j+1, i+2, j+1);
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
const ll MOD = 1000000007;
using namespace std;

const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
int main(void)
{
    int h, w;
    cin >> h >> w;
    vector<string> v(h);
    rep(i, 0, h) cin >> v[i];
    int ans = 0;
    rep(i, 0, h)
    {
        rep(j, 0, w)
        {
            if (v[i][j] == '#')
                continue;
            queue<pair<int, int>> p;
            vector<vector<int>> dist(h, vector<int>(w, -1));
            p.push({i, j});
            dist[i][j] = 0;
            while (!p.empty())
            {
                pair<int, int> tmp = p.front();
                p.pop();
                rep(k, 0, 4)
                {
                    int ny = tmp.first + dy[k];
                    int nx = tmp.second + dx[k];
                    if (ny < 0 || ny >= h || nx < 0 || nx >= w)
                        continue;
                    if (v[ny][nx] == '.')
                    {
                        if (ny < 0 || nx < 0 || ny >= h || nx >= w)
                            continue;
                        if (dist[ny][nx] > dist[tmp.first][tmp.second] + 1 || dist[ny][nx] == -1)
                            dist[ny][nx] = dist[tmp.first][tmp.second] + 1, ans = max(ans, dist[ny][nx]), p.push({ny, nx});
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <cmath>
//#include <iomanip>
//#include <map>
//#include <unordered_map>
//#include <cstring>

using namespace std;
using ll = long long;
// using pint = pair<int, int>;
using Graph = vector<vector<int>>;
// ll INF = 1LL << 60;

vector<ll> counter;
Graph G;

void dfs(int v, int pv) {
	if (pv != -1) counter[v] += counter[pv];
	for (int nv : G[v]) {
		if (nv == pv) continue;
		dfs(nv, v);
	}
}

int main() {
	int N, Q;
	cin >> N >> Q;
	G.resize(N);
	counter.resize(N);
	counter.assign(N, 0);
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> p(Q), x(Q);
	for (int i = 0; i < Q; i++) {
		int p, x;
		cin >> p >> x;
		p--;
		counter[p] += x;
	}

	dfs(0, -1);

	for (int i = 0; i < N; i++) cout << counter[i] << " ";

	return 0;
}

Measured memory_bytes: 26688
fn func(input_str: &str) {
    let mut iter = input_str.split_whitespace();
    let h: usize = iter.next().unwrap().parse().unwrap();
    let w: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();
    if w == 1 {
        println!("{}", 1);
        return;
    }
    fn rec(a_s: Vec<usize>, pat_0: &mut Vec<usize>, pat_1: &mut Vec<usize>, w: usize) {
        if a_s.len() == w - 1 {
            for i in 1..(w - 1) {
                if a_s[i - 1] + a_s[i] == 0 {
                    pat_0[i] += 1;
                }
            }
            if a_s[0] == 0 {
                pat_0[0] += 1
            }
            if a_s[w - 2] == 0 {
                pat_0[w - 1] += 1
            }
            for i in 0..(w - 1) {
                if a_s[i] == 1 {
                    pat_1[i] += 1;
                }
            }
        } else {
            if let Some(&last) = a_s.last() {
                if last == 0 {
                    let mut n_a_s = a_s.clone();
                    n_a_s.push(1);
                    rec(n_a_s, pat_0, pat_1, w);
                }
            }
            let mut n_a_s = a_s.clone();
            n_a_s.push(0);
            rec(n_a_s, pat_0, pat_1, w);
        }
    }
    let mut pat_0 = vec![0; w];
    let mut pat_1 = vec![0; w - 1];
    rec(vec![0], &mut pat_0, &mut pat_1, w);
    rec(vec![1], &mut pat_0, &mut pat_1, w);
    let mut cnt_s = vec![vec![0; w]; h + 1];
    cnt_s[0][0] = 1;
    for i in 1..(h + 1) {
        for j in 0..w {
            cnt_s[i][j] += cnt_s[i - 1][j] * pat_0[j];
            cnt_s[i][j] %= 1000000007;
            if j < w - 1 {
                cnt_s[i][j] += cnt_s[i - 1][j + 1] * pat_1[j];
                cnt_s[i][j] %= 1000000007;
            }
            if j > 0 {
                cnt_s[i][j] += cnt_s[i - 1][j - 1] * pat_1[j - 1];
                cnt_s[i][j] %= 1000000007;
            }
        }
    }
    println!("{}", cnt_s[h][k-1]);
}

use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    func(&buf[..]);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

const int INF=1e18;

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

    int N,K; cin>>N>>K;
    vector<int> h(N);
    for(int i=0;i<N;i++) cin>>h[i];

    vector<int> dp(N,INF);
    dp[0]=0;
    for(int i=0;i<N;i++){
        for(int j=1;j<=K;j++) if(i+j<=N-1){
            chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
    }
    cout<<dp[N-1]<<endl;
    return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if(a==b){
        cout << "Draw" << endl;
        return 0;
    }
    if(a<b){
        if(a!=1){
            cout << "Bob" << endl;
            return 0;
        }else{
            cout << "Alice" << endl;
            return 0;
        }
    }
    if(b<a){
        if(b!=1){
            cout << "Alice" << endl;
            return 0;
        }else{
            cout << "Bob" << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
/*************************************************************************
    > File Name: GRL_2_B.cpp
    > Author: Roundgod
    > Mail: wcysai@foxmail.com 
    > Created Time: 2018-10-30 14:09:00
 ************************************************************************/

#include<bits/stdc++.h>
#pragma GCC optimize(3)
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,m,root;
namespace ZL
{
	const int N=100010,M=100010,inf=1e9; 
	struct edge
    {
	    int u,v,w,use,id;
	}b[M],a[2000100];
	int n,m,ans,pre[N],id[N],vis[N],root,In[N],h[N],len,way[M];
	void init(int _n,int _root)
    {
		n=_n; m=0; b[0].w=inf; root=_root;
	}
	void add(int u,int v,int w)
    {
		b[++m]=(edge){u,v,w,0,m};
		a[m]=b[m];
	}
	int work()
    {
		len=m;
	    for (;;)
        {
	        for (int i=1;i<=n;i++){pre[i]=0; In[i]=inf; id[i]=0; vis[i]=0; h[i]=0;}
	        for (int i=1;i<=m;i++)
	            if (b[i].u!=b[i].v&&b[i].w<In[b[i].v])
                {
	                pre[b[i].v]=b[i].u; In[b[i].v]=b[i].w; h[b[i].v]=b[i].id;
	            }
	        for (int i=1;i<=n;i++) if (pre[i]==0&&i!=root) return 0;
	        int cnt=0; In[root]=0;
	        for (int i=1;i<=n;i++)
            {
	            if (i!=root) a[h[i]].use++; 
	            int now=i; ans+=In[i];
	            while (vis[now]==0&&now!=root)
                {
	                vis[now]=i; now=pre[now];
	            }
	            if (now!=root&&vis[now]==i)
                {
	                cnt++; int kk=now;
	                while (1)
                    {
	                    id[now]=cnt; now=pre[now];
	                    if (now==kk) break;
	                }
	            }
	        }
	        if (cnt==0) return 1;
	        for (int i=1;i<=n;i++) if (id[i]==0) id[i]=++cnt;
	        for (int i=1;i<=m;i++)
            {
	            int k1=In[b[i].v]; int k2=b[i].v;
	            b[i].u=id[b[i].u]; b[i].v=id[b[i].v];       
	            if (b[i].u!=b[i].v)
                {
	                b[i].w-=k1; a[++len].u=b[i].id; a[len].v=h[k2];
	                b[i].id=len;
	            }
	        }
	        n=cnt;
	        root=id[root];
	    }
	    return 1;
	}
	void getway()
    {
		for (int i=1;i<=m;i++) way[i]=0;
		for (int i=len;i>m;i--)
        {
			a[a[i].u].use+=a[i].use; a[a[i].v].use-=a[i].use;
		}
		for (int i=1;i<=m;i++) way[i]=a[i].use;
	}
}
int main()
{
    scanf("%d%d%d",&n,&m,&root);root++;ZL::init(n,root);
    for(int i=0;i<m;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        u++;v++;ZL::add(u,v,w);
    }
    ZL::work(); printf("%d\n",ZL::ans);
    return 0;
}



Measured memory_bytes: 3664
#include<stdio.h>
int n;
int x[99];
int y[99];
int main()
{
	int cnt=0;
	while(1)
	{
		cnt++;
		int i, j;
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++)
			scanf("%d %d",&x[i],&y[i]);
		x[n] = x[0];
		y[n] = y[0];
		int s = 0;
		for(i=0;i<n;i++)
		{
			s += -x[i]*y[i+1] + x[i+1]*y[i];
		}
		printf("%d %d.%d\n",cnt,s/2,(s%2)*5);
	}
}

Measured memory_bytes: 1028
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	
	M := ScanInt(scanner)
	N := ScanInt(scanner)
	
	var ans int
	if M == 1 && N == 1 {
	    ans = 1
	} else if M == 1 {
	    ans = N - 2
	} else if N == 1 {
	    ans = M - 2
	} else {
	    ans = (M - 2) * (N - 2)
	}
	fmt.Println(ans)
}

func ScanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func ScanFloat64(scanner *bufio.Scanner) float64 {
	scanner.Scan()
	f, e := strconv.ParseFloat(scanner.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func ScanText(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func Max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Abs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}
 

Measured memory_bytes: 640
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]
class UnionFind:
    def __init__(self,N):
        self.Parent=[-1]*N
    def unite(self,m,n):
        rm=self.root(m)
        rn=self.root(n)
        if rm==rn:
            return False
        else:
            if self.size(rm)<self.size(rn):
                rm,rn=rn,rm
            self.Parent[rm]+=self.Parent[rn]
            self.Parent[rn]=rm
            return True
    def root(self,n):
        if self.Parent[n]<0:
            return n
        else:
            self.Parent[n]=self.root(self.Parent[n])
            return self.Parent[n]
    def size(self,n):
        return -self.Parent[self.root(n)]
u=UnionFind(N)
for a,b in AB:
    u.unite(a-1,b-1)
print(max([u.size(i) for i in range(N)]))

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

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

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

  int ans = a[0];
  rep(i,n-1) {
    ans = gcd(ans, a[i+1]);
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
  int a,b,c,co,i;
  cin >> a >> b >> c;
  co=0;
  if(a*c<=b){
    co=c;
  }else{
    for(i=1;i*a<=b;++i){
      co=co+1;
    }
  }
  cout << co <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int s = n%10;
  if(s == 0 || s == 1 || s == 6 || s == 8) cout << "pon" << endl;
  else if(s == 3) cout << "bon" << endl;
  else cout << "hon" << endl;
}

Measured memory_bytes: 3584
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=505;
int n,m;
int a[MAXN][MAXN],b[MAXN][MAXN];
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		a[1][i]=1;
		b[n][i]=1;
	}
	for(int i=2;i<n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(j&1)
				a[i][j]=1;
			else
				b[i][j]=1;
		}
	}
	for(int i=1;i<=n;i++)
	{
		scanf("\n");
		for(int j=1;j<=m;j++)
		{
			char c;
			scanf("%c",&c);
			if(c=='#')
				a[i][j]=b[i][j]=1;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			if(a[i][j])
				printf("#");
			else
				printf(".");
		printf("\n");
	}
	printf("\n");
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			if(b[i][j])
				printf("#");
			else
				printf(".");
		printf("\n");
	}
}

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

using namespace std;
typedef long long ll;

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

    int ans_tmp = 0;
    int ans = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            ans_tmp++;
        } else {
            ans_tmp = 0;
        }
        ans = max(ans, ans_tmp);
    }
    cout << ans << endl;
}

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

int ans;

void solve(char map[][22], int x, int y){
    ans++;
    map[x][y] = '#';
    if(map[x+1][y] == '.')
        solve(map, x+1, y);
    if(map[x][y+1] == '.')
        solve(map, x, y+1);
    if(map[x-1][y] == '.')
        solve(map, x-1, y);
    if(map[x][y-1] == '.')
        solve(map, x, y-1);
}

int main(){
    int width, height;
    while(cin >> width >> height, width||height){
        char map[22][22], str[22];
        rep(i,22)
            rep(j,22)
                map[i][j] = '#';
        int x, y;
        ans = 0;
        range(i, 1, height + 1){
            cin >> str;
            range(j, 1, width + 1){
                map[i][j] = str[j-1];
                if(map[i][j] == '@'){
                    x = i; y = j;
                }
            }
        }
        solve(map, x, y);
        cout << ans << endl;
    }
}

Measured memory_bytes: 1192
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
}; 

int main(){
    Stream io;
    
    int N, X;
    io.read(N, X);
    vector<int> x(N);
    for(int i = 0; i < N; i++){
        io.read(x[i]);
    }
    int ans = abs(X - x[0]);
    for(int i = 1; i < N; i++){
        ans = __gcd(ans, abs(X - x[i]));
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 640