akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
 
int main(void)
{
    int a[10000], n, i;
    int max, min;
    long sum;
     
    scanf("%d", &n);
    scanf("%d", &a[0]);
    sum = a[0];
    max = a[0];
    min = a[0];
    for(i = 1; i < n ; i++)
    {
        scanf("%d", &a[i]);
        sum +=  a[i];
        if(a[i] > max)
        {
            max = a[i];
        }
        if(a[i] < min)
        {
            min = a[i];
        }
    }
     
    printf("%d %d %ld\n", min, max, sum);
     
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,m,d;
  string s,t;
  int ans=0;
  cin>>n>>m>>d;
  for(int i=n;i<=m;i++){
    if(i%d==0) ans++;
  } 

  cout<<ans<<endl;

  return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	string s;
	cin >> s;
	rep(i, s.size() - 2) {
		vector<char>c;
		rep(j, 3)c.push_back(s[i + j]);
		sort(c.begin(), c.end());
		c.erase(unique(c.begin(), c.end()), c.end());
		if (c.size() <= 2) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	if (s.size() == 2 && s[0] == s[1]){
	cout << 1 << " " << 2 << endl;
	return 0;
}
	cout << -1 << " " << -1 << endl;
	return 0;
}

Measured memory_bytes: 512
package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextInt64() int64 {
	i, err := strconv.ParseInt(io.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}


func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

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

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

func absi(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func b2i(b bool) int {
	if b {
		return 1
	}
	return 0
}

type Int64s []int64
func (f Int64s) Len() int {
	return len(f)
}
func (f Int64s) Less(i, j int) bool {
	return f[i] < f[j]
}

func (f Int64s) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}


func solve(io *Io) {
	a := make([]int, 3)
	for i := range(a) {
		a[i] = io.NextInt()
	}
	sort.Ints(a)

	io.PrintLn(a[2] - a[0])
}

func main() {
	io := NewIo()
	defer io.Flush()

	solve(io)
}


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

int a, b, c, d;
int main() {
	cin >> a >> b >> c >> d;
	cout << (abs(c-a)<=d || abs(b-a)<=d && abs(c-b)<=d ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 3616
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    a,b,c,k=map(int, input().split())
    l=[]
    if k<=a:
        print(k)
    elif a<k<=a+b:
        print(a)
    else:
        print(a-(k-(a+b)))
resolve()

Measured memory_bytes: 9060
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

t = sum(B)

# しゃくとり法
res = 0
j = m
for i in range(n + 1):
    while j > 0 and t > k:
        j -= 1
        t -= B[j]
    if t > k:
        break
    res = max(res, i + j)
    if i == n: break
    t += A[i]

print(res)

Measured memory_bytes: 118304
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
d = []
h = []
for i in range(n):
    k = readi()
    d.append(k)
    heapq.heappush(h,-k)
t1 = -heapq.heappop(h)
t2 = -1
if h:
    t2 = -heapq.heappop(h)
if n == 1:
    print(d[0])
else:
    for i in range(n):
        if d[i] == t1:
            print(t2)
        else:
            print(t1)

Measured memory_bytes: 22884
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[][][] h = new int[4][3][10];
    for(int i = 0; i < 4; i++){
      for(int j = 0; j < 3; j++){
        for(int k = 0; k < 10; k++){
          h[i][j][k] = 0;
        }
      }
    }

    int x = Integer.parseInt(sc.next());
    for(int i = 0; i < x; i++){
      int b = Integer.parseInt(sc.next());
      int f = Integer.parseInt(sc.next());
      int r = Integer.parseInt(sc.next());
      int v = Integer.parseInt(sc.next());
      h[b - 1][f - 1][r - 1] += v;
    }

    for(int i = 0; i < 4; i++){
      for(int j = 0; j < 3; j++){
        for(int k = 0; k < 10; k++){
          System.out.printf(" %d", h[i][j][k]);
        }
        System.out.printf("\n");
      }
      if(i != 3)System.out.printf("####################\n");
    }
  }
}


Measured memory_bytes: 30168
#include<bits/stdc++.h>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = 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 (b<a) { a=b; return 1; } return 0; }

int main(){
  int a; cin >> a;
  cout << a+a*a+a*a*a;
  return 0;
}


Measured memory_bytes: 3624
'use strict'

const main = (INPUT) => {
  const input = INPUT.split('\n')[1].split(' ').map(n => Number(n))
  const sum = input.reduce((a, x) => a + x, 0)
  const ave = Math.round(sum / input.length)
  let ans = 0

  for (let i = 0; i < input.length; i++) {
    ans += Math.pow((input[i] - ave), 2)
  }
  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
use std::io;
use std::str::FromStr;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
                assert!(_it.next().is_none());
        }
    };
}

fn main() {

    from_line!(n: i32);

    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let mut it = buf.split_whitespace().map(|n| usize::from_str(n).unwrap());

    let mut v: Vec<i64> = buf.split_whitespace()
        .map(|n| i64::from_str(n).unwrap())
        .collect();

    loop {
        if v.len() != 1 {
            print!("{:?} ", v.pop().unwrap());
        }
        else {
            println!("{:?}", v.pop().unwrap());
            break;
        }
    }
}



Measured memory_bytes: 5040
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    public static void solve(Scanner sc) {
        int W = sc.nextInt();
        int H = sc.nextInt();
        int N = sc.nextInt();
        int[] points = {0, W, 0, H};
        for (int i = 0; i < N; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            int a = sc.nextInt();

            int point = points[a - 1];
            switch (a) {
            case 1:
                point = Math.max(point, x);
                break;
            case 2:
                point = Math.min(point, x);
                break;
            case 3:
                point = Math.max(point, y);
                break;
            case 4:
                point = Math.min(point, y);
            }
            points[a - 1] = point;
        }

        int width = points[1] - points[0];
        int hight = points[3] - points[2];
        if (width <= 0 || hight <= 0) {
            System.out.println(0);
            return;
        }
        System.out.println(width * hight);
    }
}

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

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(9)<<fixed;
	
	int n;
	cin>>n;
	int t;
	int s=0;
	map<int,int> m;
	for(int i=0;i<n;i++)
	{
		cin>>t;
		s+=t;
		m[t]++;
	}
	int q;
	cin>>q;
	int b,c;
	for(int i=0;i<q;i++)
	{
		cin>>b>>c;
		s+=m[b]*(c-b);
		m[c]+=m[b];
		m[b]=0;
		cout<<s<<endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;


int N, M;
vector<int> S[20];
int P[20];

int main(){

    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int s;
            cin >> s; s--;
            S[i].push_back(s);
        }
    }
    for(int i = 0; i < M; i++) cin >> P[i];
    int res = 0;
    for(int mask = 0; mask < (1 << N); mask++){
        int ans = 0;
        for(int j = 0; j < M; j++){
            int cnt = 0;
            for(int s : S[j]){
                if((mask >> s) & 1){
                    cnt++;
                }
            }
            if(cnt % 2 == P[j]){
                ans++;
            }
        }
        if(ans == M){
            res++;
        }
    }
    cout << res << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <stdio.h>
#include <string.h>

#define rep(i, n) for (int i = 0; i < n; ++i)
typedef unsigned long long ll;

using namespace std;

int main()
{
    ll n;
    cin >> n;
    vector<ll> A,ball;
    A.assign(n, 0);
    ball.assign(n, 0);
    vector<ll> combi;
    combi.assign(n, 0);
    rep(i, n)
    {
        cin >> A[i];
        ball[A[i]-1] += 1;
    }
    ll cnt = 0;
    rep(i, n)
    {
        if(ball[i] > 1 ){
            if (ball[i]%2 == 0){
                combi[i] = ball[i] / 2;
                combi[i] *= ball[i] - 1;
                cnt += combi[i];
            }else{
                combi[i] = (ball[i]-1) / 2;
                combi[i] *= ball[i] ;
                cnt += combi[i];
            }
        }
    }
    ll out_result,out_result2,out_result3;
    rep(i, n)
    {
        if (ball[A[i]-1] > 1){
            if (ball[A[i]-1]%2 == 0){
                out_result = (ball[A[i]-1] - 2) / 2;
                out_result *= ball[A[i]-1] - 1;
            }else{
                out_result = (ball[A[i]-1] - 1) / 2;
                out_result *= ball[A[i]-1] - 2;
            }
            out_result2 = cnt - combi[A[i]-1];
            out_result3 = out_result + out_result2;
//            out_result = cnt - combi[A[i]] + out_result;
            cout << out_result3 << endl;
        }
        else
        {
            cout << cnt << endl;
        }
    }
    return 0;
}

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

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

  s.pop_back();
  while (1) {
    int n = s.size();
    if (n % 2 == 0) {
      string t = s.substr(0, n / 2), u = s.substr(n / 2);
      if (t == u) {
        cout << s.size() << endl;
        return 0;
      }
    }
    s.pop_back();
  }
}


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++)
const ll INF = 1e10;

typedef struct{
    int to;
    int cost;
}VE;

int N, M;
vector<VE> L[100100];
ll C[100100];

bool dfs(int v, int n){
    C[v] = n;
    for(int i = 0; i < L[v].size(); i++){
        VE ve = L[v][i];
        int next = ve.to;
        int cost = ve.cost;
        if(C[next] != INF){
            if(C[next] != C[v]+cost) {
                return false;
            }
        }
        else{
            bool valid = dfs(next, n+cost);
            if(!valid) return false;
        }
    }
    return true;
}

int main(){
    cin >> N >> M;
    REP(i,M){
        ll l, r, d;
        cin >> l >> r >> d;
        l--, r--;
        L[l].push_back((VE){r, d});
        L[r].push_back((VE){l, -d});
    }

    fill(C, C+N, INF);
    REP(i,N){
        if(C[i] != INF) continue;
        bool valid = dfs(i, 0);
        if(!valid){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;

}


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

int main() {
  int N,M;cin>>N>>M;
  vector<vector<int>> a(M);
  for(int i=0;i<M;i++){
      int k;cin>>k;
      for(int j=0;j<k;j++){
          int b;cin>>b;
          b--;
          a[i].push_back(b);
          
      }
  }

  vector<int> p(M);
  for(int i=0;i<M;i++){
      cin>>p[i];
  }
    int res=0;
  for(int i=0;i<(1<<N);i++){
      bool ans=true;
      
      for(int j=0;j<M;j++){
         int c=0; 
          for(int naka : a[j]){
              if(i&(1<<naka)){
                  c++;
              }
          }
     if(p[j]!=c%2)ans=false;
      }

     
      if(ans)res++;
     
    


  }

  cout<<res<<endl;

  /*int ans = 0;
	for (int i = 0; i < (1 << N); ++i) {
		bool ok = true;
		for (int j = 0; j < M; ++j) {
			int c = 0;
			for (int id : a[j]) {
				if ((i >> id) & 1) {
					++c;
				}
			}
			c %= 2;
			if (c != p[j]) {
				ok = false;
			}
		}
		if (ok) {
			++ans;
		}
	}

	cout << ans << endl;*/


}



Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std ;
typedef long long ll ;
# define rep (i , n ) for ( int i =0; i < n ; i++)
# define _sort(arg) sort(begin(arg), end(arg))

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

	int A, B, C;
	
	cin >> A >> B >> C;

	int c_5 = 0;
	int c_7 = 0;
	if (A == 5)
	{
		c_5++;
	}
	else if (A == 7)
	{
		c_7++;
	}

	if (B == 5)
	{
		c_5++;
	}
	else if (B == 7)
	{
		c_7++;
	}
	if (C == 5)
	{
		c_5++;
	}
	else if (C == 7)
	{
		c_7++;
	}

	if ((c_5 == 2) && (c_7 == 1))
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << 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 = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int ans = 1;
	for (int i = 2; i <= n; i++)
	{
		int cur = i;
		while (cur * i <= n)
		{
			cur *= i;
			ans = max(ans, cur);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//In The Name Of God
#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
#define mp make_pair
#define L(x) (2*(x))
#define R(x) ((2*(x))+1)
#define pii pair<int, int>
#define pb push_back
using namespace std;
const int N = 4e2 + 5, Mod = 1e9 + 7, P = 727, Lg = 22, TOF = 1900, Inf = 3e18 + 5;

int Dp[N][N], A[N], Ps[N];
int32_t main(){
      ios_base::sync_with_stdio(0); cin.tie(0);
      int n; cin >> n;
      for(int i = 1; i <= n; i++){
            cin >> A[i];
            Ps[i] = Ps[i - 1] + A[i];
      }
      for(int i = 2; i <= n; i++){
            for(int j = 1; j <= n - i + 1; j++){
                  int l = j, r = j + i - 1;
                  Dp[l][r] = Inf;
                  for(int k = l; k <= r - 1; k++)
                        Dp[l][r] = min(Dp[l][r], Dp[l][k] + Dp[k + 1][r] + (Ps[k] - Ps[l - 1]) + (Ps[r] - Ps[k]));
            }
      }
      cout << Dp[1][n];
      return 0;
}



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

const int maxn=4e5+10;

int n,x,y,fa[maxn],dep[maxn],Ans;

struct Tree{
	int tote,FIR[maxn],TO[maxn],NEXT[maxn];

	void addedge(int u,int v)
	{
		TO[++tote]=v;
		NEXT[tote]=FIR[u];
		FIR[u]=tote;
	}

	void dfs(int u)
	{
		for (int p=FIR[u];p;p=NEXT[p])
		{
			int v=TO[p];
			if (fa[u]==v) continue;
			fa[v]=u;
			dep[v]=dep[u]+1;
			dfs(v);
		}
	}

	void solve(int u,int f,int dis)
	{
		Ans=max(Ans,dep[u]);
		for (int p=FIR[u];p;p=NEXT[p])
		{
			int v=TO[p];
			if (v==f) continue;
			bool flag=fa[v]==u||fa[u]==v||fa[fa[v]]==u||fa[fa[u]]==v||fa[u]==fa[v];
			if (!flag) {Ans=1e8; return;}
			if (dis+1>=dep[v]) continue;
			solve(v,u,dis+1);
		}
	}
}red,blue;

int main()
{
#ifdef h10
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	int i,u,v;
	scanf("%d%d%d",&n,&x,&y);
	for (i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		red.addedge(u,v);
		red.addedge(v,u);
	}
	for (i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		blue.addedge(u,v);
		blue.addedge(v,u);
	}
	blue.dfs(y);
	red.solve(x,0,0);
	if (Ans>=1e7) puts("-1");
	else printf("%d\n",Ans*2);
}


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

#define add(i,j) (sqrt(cakes[i]*cakes[j]) * 2 - cakes[i] + cakes[j])

vector< string > split( const string& str, string del){
  char *p,  *str_buff = new char[str.size() + 1], first = 0;
  vector< string > ret;
  strcpy( str_buff, str.c_str());
  while(p = strtok((first++ ? NULL : str_buff), del.c_str())){
    ret.push_back(p);
  }
  //  delete str_buff;
  return ret;
}
int main(){
  string strb;
  while(getline(cin, strb)){
    vector< string > strs = split( strb, " ");
    int box = atoi(strs[0].c_str());
    vector< int > cakes(strs.size() - 1);
    for(int i = 0; i < strs.size() - 1; i++){
      cakes[i] = atoi(strs[i + 1].c_str());
    }

    const int INF = 1 << 30;
    double dp[12][1 << 12];
    fill_n( *dp, 12 * (1 << 12), INF);

    for(int i = 0; i < cakes.size(); i++){
      dp[i][1 << i] = cakes[i] * 2;
    }

    for(int j = 0; j < 1 << cakes.size(); j++){
      for(int i = 0; i < cakes.size(); i++){
        if(dp[i][j] == INF) continue;
        for(int k = 0; k < cakes.size(); k++){
          if(j >> k & 1) continue;
          dp[k][j|(1 << k)] = min( dp[k][j|(1 << k)], dp[i][j] + add(i,k));
        }
      }
    }
    bool judge = false;
    for(int i = 0; i < cakes.size(); i++){
      judge |= dp[i][(1 << cakes.size()) - 1] <= box;
    }
    if(judge) cout << "OK" << endl;
    else cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 1584
import java.util.*;

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

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

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  for(ll &x:a) cin >> x;
  for(int i=1; i<n; ++i) 
  a[i]+=a[i-1];
  ll ans = a[n-1];
  for(int i=0; i<n-1; ++i) 
    ans = min(ans, abs(a[n-1] - 2*a[i]));
  cout << ans;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>  // ver1.9.4
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a[a.size()-1]<<endl;
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

signed main() {
  cout << fixed << setprecision(15);
  int n,p;
  cin >> n >> p;
  int o=0,e=0,qw;
  int ans1,ans0;
  rep(i,0,n){
    cin >> qw;
    if(qw%2==0) e++;
    else o++;
  }
  qw = pow(2,n);
  if(o==0){
    if(p==0) cout << qw << endl;
    if(p==1) cout << 0 << endl;
    return 0;
  }
  cout << qw/2 << endl;
  
  
  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
if 2*k > n+1:
	print(-1)
else:
	for i in range(n//2):
		print((2*k+n-2)//2 - i, k+n+1+2*i, k+2*n+i)
	for i in range(n-n//2):
		print(k+n-1-i, k+n+2*i, k+2*n+n//2+i)

Measured memory_bytes: 5172
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
   ll n;cin>>n;
   if((n-n%10)%1110 == 0 || (n%1000)%111 == 0) cout << "Yes" << ednl;
   else cout << "No" << ednl;
}


Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2019/07/21
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
	int A = 0, B = 0, ans = 0;
	scanf("%d %d", &A, &B);
	ans = 6 - (A + B);
	printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define maxn 200000
#define mod 998244353
#define FLASH cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define FILEIO freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin); //freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);
using namespace std;

int power(int a, int b, int m)
{
    int ans = 1;
    a %= m;
    while(b){
        if(b & 1) ans = (ans * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return ans;
}

int n, m, k, fac[maxn + 1] = {1};

int C(int a , int b){
    if(b < 0 or b > a) return 0;
    int ans = fac[a];
    ans *= power((fac[b]*fac[a - b])%mod, mod - 2, mod);
    ans %= mod;
    return ans; 
}

signed main()
{
    
    FLASH

    for(int i = 1; i <= maxn; i++) fac[i]  = (fac[i - 1]*i)%mod;
    cin>>n>>m>>k;

    int ans = 0;
    for(int i = 0; i <= k; i++){
        int temp = C(n - 1, i);
        temp *= power(m - 1, n - 1 - i, mod);
        temp %= mod;
        ans += temp;
        ans %= mod;
    }
    ans *= m;
    ans %= mod;
    cout<<ans<<'\n';
}

Measured memory_bytes: 5228
from collections import deque

s = deque(list(map(str, input().rstrip())))
q = int(input())

state = 1
for _ in range(q):
    li = list(map(str, input().split()))
    if li[0] == "1":
        state *= -1
    elif (li[1] == "1" and state == 1) or (li[1] == "2" and state == -1):
        s.appendleft(li[2])
    else:
        s.append(li[2])

if state == -1:
    s.reverse()

print("".join(s))

Measured memory_bytes: 8676
#include <stdio.h>

int main()
{
  int n;
  scanf("%d", &n);
  if(n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 7 || n % 10 == 9){
    printf("hon\n");
  }else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8){
    printf("pon\n");
  }else{
    printf("bon\n");
  }
  
  return 0;
}

Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
const int N = 2000 + 5;
ll r[N][N] = {}, l[N][N] = {};
ll u[N][N] = {}, d[N][N] = {};
char arr[N][N];
int main(){
    Hello
    ll h, w, ans = 0;
    cin >> h >> w;
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            cin >> arr[i][j];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(arr[i][j] == '#') l[i][j] = 0;
            else {
                if(j == 0) l[i][j] = 1;
                else l[i][j] = l[i][j - 1] + 1;
            }
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = w - 1; j >= 0; j--){
            if(arr[i][j] == '#') r[i][j] = 0;
            else{
                if(j == w - 1) r[i][j] = 1;
                else r[i][j] = r[i][j + 1] + 1;
            }
        }
    }
    for(int j = 0; j < w; j++){
        for(int i = 0; i < h; i++){
            if(arr[i][j] == '#') u[i][j] = 0;
            else{
                if(i == 0) u[i][j] = 1;
                else u[i][j] = u[i - 1][j] + 1;
            }
        }
    }
    for(int j = 0; j < w; j++){
        for(int i = h - 1; i >= 0; i--){
            if(arr[i][j] == '#') d[i][j] = 0;
            else{
                if(i == h - 1) d[i][j] = 1;
                else d[i][j] = d[i + 1][j] + 1;
            }
        }
    }
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            if(arr[i][j] == '.')
            ans = max(ans, r[i][j] + l[i][j] + u[i][j] + d[i][j] - 3);
    cout << ans;
    return 0;
}


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

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

int main(){
    int n, D;
    cin >> n >> D;
    vector<pii> v;
    vector<int> x(n), y(n), b(n);
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> b[i];
        v.push_back({b[i],i});
    }
    sort(v.begin(), v.end());
    vector<bool> ng(n, 0);
    priority_queue<pii> l, r, u, d;
    ll ans = 0;
    for(int j = 0; j < n; j++){
        int i = v[j].second;
        int to = v[j].first;
        l.push({-x[i], i}); d.push({-y[i], i});
        r.push({x[i], i});  u.push({y[i], i});
        bool update = true;
        while(update){
            update = false;
            while(!l.empty()&&(ng[l.top().second]||abs(b[l.top().second]-to)>D)){
                ng[l.top().second] = true;  l.pop();    update = true;
            }
            while(!d.empty()&&(ng[d.top().second]||abs(b[d.top().second]-to)>D)){
                ng[d.top().second] = true;  d.pop();    update = true;
            }
            while(!r.empty()&&(ng[r.top().second]||abs(b[r.top().second]-to)>D)){
                ng[r.top().second] = true;  r.pop();    update = true;
            }
            while(!u.empty()&&(ng[u.top().second]||abs(b[u.top().second]-to)>D)){
                ng[u.top().second] = true;  u.pop();    update = true;
            }
        }
        // printf("%d %d %d %d\n", r.top().first, l.top().first, u.top().first, d.top().first);
        ans = max(ans, (ll)(r.top().first+l.top().first)*(u.top().first+d.top().first));
    }
    cout << ans << endl;
    return 0;
}


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

long A[100010],
	 B[100010],
	 C[100010];
	 
int main(){
	long N,Q,i,j,tmp;
	long long sum=0;
	char ans[200];
	scanf("%ld",&N);

	for(i=0;i<N;i++){
		scanf("%ld",&tmp);
		A[tmp]++;
		sum+=tmp;
	}
	scanf("%ld",&Q);
	for(i=0;i<Q;i++){
		scanf("%ld%ld",B+i,C+i);
	}	
	
	
	for(i=0;i<Q;i++){
		long num=A[B[i]];
		if(A[B[i]]>0){
			sum-=A[B[i]]*B[i];
			sum+=A[B[i]]*C[i];
			A[C[i]]+=A[B[i]];			
			A[B[i]]=0;
			
		}
		printf("%lld\n",sum);
	}


	return 0;
}


//702 =  1 1 +0

Measured memory_bytes: 4076
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using PLL = pair<ll, ll>;
template <typename T> using V = vector<T>;

const ll inf = 1e12;
struct Solver {
    ll N;
    map<ll, ll> lefts;
    set<ll> left_minus;
    V<set<ll>> file_lefts;
    map<ll, ll> file_id;
    V<ll> rev_file_id;

    Solver() {
        cin >> N;
        lefts[0] = -1;
        lefts[inf] = -1;
        left_minus.insert(0);
        left_minus.insert(-inf);
        file_lefts.resize(N);
    }

    ll set_file_id(ll name) {
        auto ite = file_id.find(name);
        if(ite != file_id.end()) return ite->second;
        ll ret = file_id.size();
        file_id[name] = ret;
        file_lefts.push_back(set<ll>());
        rev_file_id.push_back(name);
        return ret;
    }

    void write() {
        ll file_name, file_size;
        cin >> file_name >> file_size;
        ll id = set_file_id(file_name);
        ll left_now = 0;
        while(file_size) {
            auto itel = lefts.lower_bound(left_now);
            if(itel->second != -1) {
                left_now = itel->first + 1;
                continue;
            }
            auto iter = lefts.upper_bound(itel->first);
            ll range = iter->first - itel->first;
            itel->second = id;
            file_lefts[id].insert(itel->first);
            if(file_size < range) {
                ll key = itel->first + file_size;
                lefts[key] = -1;
                left_minus.insert(-key);
                file_size = 0;
            } else {
                file_size -= range;
            }
            left_now = iter->first;
        }
    }

    void del() {
        ll file_name;
        cin >> file_name;
        ll id = set_file_id(file_name);
        for(auto &&left : file_lefts[id]) {
            auto ite = lefts.lower_bound(left);
            ite->second = -1;
        }
        file_lefts[id].clear();
    }

    ll read() {
        ll sector;
        cin >> sector;
        auto ite_m = left_minus.lower_bound(-sector);
        auto ite = lefts.lower_bound(-*ite_m);
        if(ite->second == -1) return -1;
        return rev_file_id[ite->second];
    }

    bool solve() {
        if(!N) return false;

        while(N--) {
            char c;
            cin >> c;
            switch(c) {
                case 'W':
                    write();
                    break;
                case 'D':
                    del();
                    break;
                case 'R':
                    cout << read() << endl;
                    break;
                default:
                    assert(false);
            }
        }

        return true;
    }
};

int main() {
    while(Solver().solve()) cout << endl;;
    return 0;
}



Measured memory_bytes: 4528
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A):
    s = 1
    MAX = 10**18
    for a in sorted(A):
        s *= a
        if s > MAX:
            return -1
    return s


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 21780
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("YES\n")
#define ptn printf("NO\n")
//==========================Code here==========================
LL k, x;
int main() {
	cin >> k >> x;
	for (LL i = x - k + 1; i <= x + k - 1; ++i) cout << i << " ";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=100+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
#endif
}
ll A,B,C,D;
void input()
{
	A=read<ll>(),B=read<ll>(),C=read<ll>(),D=read<ll>();
}
void work()
{
	if(D<B)puts("No");
	else if(A<B)puts("No");
	else
	{
		ll tmp=__gcd(B,D);
		ll num=(A-C-1)/tmp-(A-B)/tmp;
		if(num>0)puts("No");
		else puts("Yes");
	}
}
int main()
{
	//file();
	int T=read<int>();
	while(T--)
	{
		input();
		work();
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
using namespace std;
#define ll long long int

bool solve(string s){
  if(s > "2019/04/30")return true;
  else return false;

}

void output(bool ok){
  if(ok)cout<<"TBD"<<endl;
  else cout<<"Heisei"<<endl;  
}

int main(){ 
  string s;
  cin >> s;
  bool ok = solve(s);
  output(ok);
  return 0;
}


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')

typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    ll n;
    cin >> n;
    if (n == 0 || n == 1 || n % 2)
        cout << 0 << "\n";
    else
    {
        ll p = 5;
        ll ans = 0;
        while (true)
        {
            if (n / p == 0)
                break;
            ans += n / p / 2;
            p *= 5;
        }
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
typedef long long ll; 
const ll mod = 1e9+7;
#define fo(i, n) for (int i = 0; i < n; i++)
#define sc(n) scanf("%d", &n) 
using namespace std;

float n;

void solve() {
    cin >> n;
    printf("%.18f", pow(n/3, 3));
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 384
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
      n: usize,
      t: usize,
      ts: [usize; n],
    }
    let mut sum = 0;
    for i in 1..n {
        sum += min(ts[i] - ts[i-1], t)
    }
    println!("{}", sum + t);
}


Measured memory_bytes: 6396
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<utility>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
int main()
{
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x;cin>>x;
		while(x%2==0)x/=2,ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque

K = int(input())

Q = deque((1,))
inf = float('inf')
L = [inf]*K
L[1] = 1

while Q[0] != 0:
  n = Q.popleft()
  a = (n+1)%K
  if L[a] > L[n]+1:
    L[a] = L[n]+1
    Q.append(a)
  b = (n*10)%K
  if L[b] > L[n]:
    L[b] = L[n]
    Q.appendleft(b)

print(L[0])

Measured memory_bytes: 6004
#include<bits/stdc++.h>
#include<string>
#include<cctype>
#include<cmath>
#include<queue>
#include<stack> 
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

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

Measured memory_bytes: 256
def SPFA(G:list, source=0):
	from collections import deque
	V = len(G)
	d = [float("inf")]*V
	inQ = [False]*V
	cnt = [0]*V
	d[source] = 0
	cnt[source] = 1
	Q = deque([source])
	_sum = 0
	_len = 1
	while Q:
		f = Q.popleft()
		inQ[f] = False
		_sum -= d[f]
		_len -= 1
		for t,c in G[f]:
			dist = d[f] + c
			if dist < d[t]:
				d[t] = dist
				if not inQ[t]:
					inQ[t] = True
					cnt[t] += 1
					if dist*_len < _sum:
						Q.appendleft(t)
					else:
						Q.append(t)
					_sum += dist
					_len += 1
				if cnt[t] > V:
					#negative cycle
					return None
	return d
	
def main():
	V,E,r,*L=map(int,open(0).read().split())
	G=[[]for _ in range(V)]
	for s,t,d in zip(*[iter(L)]*3):
		G[s].append((t,d))
	ret = SPFA(G,r)
	if ret==None:
		print("NEGATIVE CYCLE")
	else:
		for x in ret:
			print("INF" if x==float("inf") else x)
			
if __name__=="__main__":main()


Measured memory_bytes: 6556
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int id[100];
long double p[100];
long double w[100];
bool flag[100];
int cmb[101][101];

long double kitai(long double prob){
  if(prob == 1.0) return 1.0;
  return 1.0 / prob;
}

int main(){
  int n;

  REP(i, 101){
    cmb[i][0] = cmb[i][i] = 1;
    for(int j = 1; j < i; j++)
      cmb[i][j] = (cmb[i-1][j-1] + cmb[i-1][j]) % 100000007;
  }

  while(scanf("%d", &n), n){
    int cnt = 1;
    int sum = 0;
    long double ans = 0.0;

    REP(i,n) cin >> p[i] >> id[i] >> w[i];
    REP(i,n) flag[i] = false;
    REP(i,n) if(!flag[i]){
      int ii = i;
      int c  = 0;

      long double maxp = 0.0;
      int pcnt    = 0;

      while(!flag[ii]){
        long double tmp = 0.0;
        for(int now = ii; ; now = id[now]){
          if(id[now] == ii){
            tmp += kitai(p[now]);
            break;
          }else{
            tmp += kitai(w[now]);
          }
        }
#define ABS(x) ((x) < 0 ? -(x) : (x))
        if(maxp == 0.0 || maxp - 1e-11 > tmp){
          maxp = tmp;
          pcnt = 1;
        }else if(ABS(maxp - tmp) < 1e-11){
          pcnt++;
        }

        flag[ii] = true;
        ii = id[ii];
        c++;
      }
      cnt = (cnt * (long long)cmb[sum + c][c]) % 100000007;
      cnt = (cnt * (long long)pcnt) % 100000007;
      sum = sum + c;
      ans += maxp;
    }
    printf("%.11f %d\n", (double)ans, cnt);
  }
  return 0;
}

Measured memory_bytes: 1060
#include<stdio.h>
#include<stdlib.h>
void fun(char *,int );
void fun(char *s,int n)
{
    int cnt1=0,cnt2=0,i;
    for(i=0;i<n;i++)
    {
        if(s[i]=='(')
        {
            cnt1++;
        }
        if(s[i]==')')
        {
            cnt1--;
            if(cnt1<0)
            {
                cnt2++;
                cnt1=0;
            }
        }
    }
    for(i=0;i<cnt2;i++)
    {
        printf("(");
    }
    printf("%s",s);
    for(i=0;i<cnt1;i++)
    {
        printf(")");
    }
    printf("\n");
}
int main()
{
    char a[101];
    int n;
    scanf("%d%s",&n,a);
    fun(a,n);
    return 0;
}

Measured memory_bytes: 128
from collections import Counter

N, M = map(int, input().split())
A = list(map(int, input().split()))

accA = [0] * (N + 1)
for i, a in enumerate(A, start=1):
    accA[i] = (accA[i - 1] + a) % M

cntS = Counter()
ans = 0
for s in accA:
    ans += cntS[s]
    cntS[s] += 1

print(ans)


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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

#define x1 iuasdhiausdhisa
#define x2 ashiueHIUHEAUIHSEI
#define y1 jiNSDNEJSENJIAEbniAHENUIAe
#define y2 jasndkjOSADJKsdSDOSdoSDJAIOsdjoi

using namespace std;

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

const int MAX = 2e5 + 5;
constexpr double PI = acos(-1.0);
int n;
ll x1, y1, x2, y2;

int main() {
	scanf("%lld %lld %lld %lld", &x1, &y1, &x2, &y2);
	scanf("%d", &n);
	if(x1 > x2) {
		swap(x1, x2);
		swap(y1, y2);
	}

	vector< pair<ll, ll> > v;
	fori(i, 1, n + 1) {
		ll x, y;
		scanf("%lld %lld", &x, &y);
		if(min(x1, x2) <= x && x <= max(x1, x2) && min(y1, y2) <= y && y <= max(y1, y2)) {
			if(y1 > y2) {
				y = max(y1, y2) - y + 1;
			}
			v.emplace_back(x, y);
		}
	}

	if(y1 > y2) {
		swap(y1, y2);
	}

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

	vector<ll> lis(n, (ll) 1e18);
	int len = 0;
	fori(i, 0, v.size()) {
		int pos = upper_bound(lis.begin(), lis.end(), v[i].second) - lis.begin();
		lis[pos] = v[i].second;
		len = max(len, pos + 1);
	}

	ll dx = x2 - x1;
	ll dy = y2 - y1;
	
	ll d = dx + dy;
	ll p = len - (min(dx, dy) + 1 == len);
	ll s = min(dx, dy) + 1 == len;

	double ans = 100 * d - (20 - 5 * PI) * p + (10 * PI - 20) * s;
	printf("%.15lf\n", ans);

	return 0;
}



Measured memory_bytes: 6256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<random>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<stdlib.h>
#include<unordered_map>
#include<time.h>
#define int long long
#define rep(i,a,n) for (int (i)=(a);(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef long double ld;
int n, a;
list<int>l;
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (n % 2 == 1) {
			if (i % 2 == 0)
				l.push_front(a);
			else
				l.push_back(a);
		}
		else {
			if (i % 2 == 0)
				l.push_back(a);
			else
				l.push_front(a);
		}
	}
	list<int>::iterator it = l.begin();
	while (it != l.end()) {
		if (it == l.begin()) cout << (*it);
		else cout << " " << (*it);
		it++;
	}
	cout << endl;
}

Measured memory_bytes: 8448