akhauriyash/Code-Regression huggingface dataset:
import * as fs from "fs";
/**
4 3
###
###
...
###
*/

let [line1, ...lines] = fs.readFileSync("/dev/stdin", "utf8").trim().split('\n');
let [H, W] = line1.split(' ').map(Number);

let table: string[][] = [];
let visited: boolean[][] = [];

for(let i=0; i<H; i++) {
    table.push(Array.from(lines[i]));
    visited.push(new Array(W).fill(false));
}

function dfs(i: number, j: number): number {
    let counter: Map<string, number> = new Map([['.', 0], ['#', 0]]);
    counter.set(table[i][j], 1);
    visited[i][j] = true;
    let stack = [[i, j]];
    while (stack.length != 0) {
        let [x, y] = stack.pop();
        for(let [x1, y1] of [[x-1, y], [x+1, y], [x, y-1], [x, y+1]]) {
            if (0 <= x1 && x1 < H && 0 <= y1 && y1 < W &&
                visited[x1][y1] == false && table[x][y] != table[x1][y1]) {
                visited[x1][y1] = true;
                stack.push([x1, y1]);
                counter.set(table[x1][y1], counter.get(table[x1][y1])+1);
            }
        }
    }
    return counter.get('#')*counter.get('.');
}

let answer = 0;
for(let i=0; i<H; i++) {
    for(let j=0; j<W; j++) {
        if (!visited[i][j]) {
            answer += dfs(i, j);
        }
    }
}

console.log(answer);


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

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

bit_list = [0 for i in range(50)]
for i in range(N):
    a = A[i]
    for j in range(50):
        if a%2==1:
            bit_list[j]+=1
        a=a//2
        if a==0:
            break

bitk=bin(K)[2:]
lenk = len(bitk)
bitk=bitk[::-1]

maxscore=0
for i in range(len(bitk)):
    patA=0
    if bitk[i]=="1":
        first=i
        for j in range(50):
            if j<first:
                patA+=max(N-bit_list[j],bit_list[j])*(2**j)
            elif j==first:
                patA+=bit_list[j]*(2**j)
            elif j<lenk:
                if bitk[j]=="0":
                    patA+=bit_list[j]*(2**j)
                else:
                    patA+=(N-bit_list[j])*(2**j)
            else:
                patA+=bit_list[j]*(2**j)


    maxscore=max(patA,maxscore)

patB=0
for i in range(50):
    patB+=bit_list[i]*(2**i)
patC=0
for i in range(50):
    if i<lenk:
        if bitk[i]=="0":
            patC+=bit_list[i]*(2**i)
        else:
            patC+=(N-bit_list[i])*(2**i)
    else:
        patC+=bit_list[i]*(2**i)

print(max(maxscore,patB,patC))

Measured memory_bytes: 14620
n = int(input())
a = list(map(int, input().split()))

mod = 10**9+7

m = 62
d = [0]*m

ans = 0
for i in range(n):
    ai = a[i]
    for j in range(m):
        # 1
        if ai&(1<<j):
            ans += (1<<j)*(i-d[j])
            d[j] += 1
        # 0
        else:
            ans += (1<<j)*d[j]
    ans %= mod

print(ans)

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

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

using namespace std;

pair<int,int> factor(string s, int i) {
  int num = s[i] - '0';
  while(++i < s.size() && s[i] == '*') {
    num *= s[++i] - '0';
  }
  return make_pair(num, i);
}

int expr(string s) {
  int num, i;
  tie(num, i) = factor(s, 0);
  while(i < s.size()) {
    int p, j;
    tie(p, j) = factor(s, i+1);
    num += p;
    i = j;
  }
  return num;
}

int expr2(string s) {
  int i = 0;
  int num = s[i] - '0';
  while(++i < s.size()) {
    if (s[i] == '*')
      num *= s[++i] - '0';
    else
      num += s[++i] - '0';
  }
  return num;
}

int main() {
  string s;
  cin>>s;
  int ans;
  cin>>ans;
  int bob = expr2(s);
  int calc = expr(s);
  if (ans == bob) {
    if (ans == calc) {
      cout << 'U' << endl;
    } else {
      cout << 'L' << endl;
    }
  } else {
    if (ans == calc) {
      cout << 'M' << endl;
    } else {
      cout << 'I' << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1204
#include<stdio.h>
int main(){
    int k,s;
    scanf("%d %d",&k,&s);
    int sum=0;
    for(int x=0;x<=k;x++){
        for(int y=0;y<=k;y++){
        
            if(0<=(s-x-y)&&(s-x-y)<=k) sum++; 
        }
    }
    printf("%d",sum);
    printf("\n");
    return 0;
}

Measured memory_bytes: 1696
function Main(raw) {
  const input = raw.split(/ |\n/);
  const A = parseInt(input[0], 10);
  const B = parseInt(input[1], 10);
  const ans= (B%A==0)?A+B:B-A;
  //出力
  console.log("%d", ans);
}

//DO NOT EDIT
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
signed main(){
    ll n;cin>>n;
    vector<ll>a(n+1);
    REP(i,1,n+1){
        ll k=1;
        while(k*i<=n){
            a[k*i]++;
            k++;
        }
    }
    ll ans=0;
    REP(i,1,n+1){
        ans+=i*a[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 81400
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define E endl
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(9)

int fact(int n) 
{ 
	return (n <= 1) ? 1 : n * fact(n - 1); 
} 

int findSmallerInRight(char* str, int low, int high) 
{ 
	int countRight = 0, i; 

	for (i = low + 1; i <= high; ++i) 
		if (str[i] < str[low]) 
			++countRight; 

	return countRight; 
} 


int main() 
{ 
	ll n;
	cin>>n;
    char a[n+1];
    char b[n+1];
    for(ll i=0;i<n;i++)
    cin>>a[i];
    for(ll i=0;i<n;i++)
    cin>>b[i];
    
    string c="",d="";
    char f;
    for(ll i=0;i<n;i++)
    {
      // f=a[i]-48;
       c=c+a[i];
       d=d+b[i];
    }
    
    int mul = fact(n); 
	int rank = 1; 
	int countRight; 

	int i; 
	for (i = 0; i <n; ++i) { 
		mul /= n - i; 
		countRight = findSmallerInRight(a, i, n - 1); 

		rank += countRight * mul; 
	} 
	int mul1 = fact(n); 
	int rank2 = 1; 
	 countRight=0; 


	for (i = 0; i <n; ++i) { 
		mul1 /= n - i; 
		countRight = findSmallerInRight(b, i, n - 1); 

		rank2 += countRight * mul1; 
	}
	cout<<abs(rank2-rank);
	return 0; 
} 



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

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;

 main()

{
    fast
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int sum=0;
    if(a<=k)
    {
        sum+=a;
        k=k-a;
    }
    else
    {
        sum+=k;
        cout<<sum<<endl;
        return 0;
    }
    if(b<=k)
    {
        k=k-b;
    }
    else
    {
        cout<<sum<<endl;
        return 0;
    }
    sum-=min(c,k);
    cout<<sum<<endl;
    return 0;

}





































Measured memory_bytes: 3632
package main

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

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	grid := make([]string, h+2)
	wall := createWall(w)
	grid[0] = wall
	grid[h+1] = wall
	sc := bufio.NewScanner(os.Stdin)
	for i := 1; i <= h; i++ {
		sc.Scan()
		grid[i] = "." + sc.Text() + "."
	}
	for i := 1; i <= h; i++ {
		buf := bytes.NewBuffer([]byte{})
		for j := 1; j <= w; j++ {
			if grid[i][j] == '#' {
				buf.Write([]byte{'#'})
				continue
			}
			n := bombNum(grid, i, j)
			buf.WriteString(fmt.Sprintf("%d", n))
		}
		fmt.Println(buf.String())
	}
}

func bombNum(grid []string, i, j int) (num int) {
	type pos struct{ y, x int }
	for _, p := range []pos{
		{i - 1, j - 1}, {i - 1, j}, {i - 1, j + 1},
		{i, j - 1}, {i, j + 1},
		{i + 1, j - 1}, {i + 1, j}, {i + 1, j + 1},
	} {
		if grid[p.y][p.x] == '#' {
			num++
		}
	}
	return
}

func createWall(w int) string {
	buf := bytes.NewBuffer([]byte{})
	for i := 0; i < w+2; i++ {
		buf.Write([]byte{'.'})
	}
	return buf.String()
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ABC_109
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int h = int.Parse(input[0]);
            int w = int.Parse(input[1]);
            var coins = new int[h, w];
            long allCoins = 0;
            for (int i = 0; i < h; i++)
            {
                input = Console.ReadLine().Split(' ');
                for (int j = 0; j < w; j++)
                {
                    coins[i, j] = int.Parse(input[j]);
                    allCoins += coins[i, j];
                }
            }
            var handleList = new List<string>();
            bool isOdd = allCoins % 2 == 1;
            for (int i = 0; i < h; i++)//左から右へ
            {
                for (int j = 0; j < w; j++)//上から下へ
                {
                    if (coins[i, j] % 2 == 0) continue;

                    if (isOdd)
                    {
                        isOdd = false;
                        continue;
                    }

                    //move
                    if (i < h - 1 && coins[i + 1, j] % 2 == 1)
                    {
                        handleList.Add(string.Format("{0} {1} {2} {3}",
                            i+1, j+1, i + 2, j+1));
                        coins[i, j]--;
                        coins[i + 1, j]++;
                    }
                    else if (j < w - 1 && coins[i, j + 1] % 2 == 1)
                    {
                        handleList.Add(string.Format("{0} {1} {2} {3}",
                            i + 1, j + 1, i + 1, j + 2));
                        coins[i, j]--;
                        coins[i, j + 1]++;
                    }
                    else
                    {
                        if (i < h - 1)
                        {
                            handleList.Add(string.Format("{0} {1} {2} {3}",
                                i + 1, j + 1, i + 2, j + 1));
                            coins[i, j]--;
                            coins[i + 1, j]++;
                        }
                        else
                        {
                            handleList.Add(string.Format("{0} {1} {2} {3}",
                                i + 1, j + 1, i + 1, j + 2));
                            coins[i, j]--;
                            coins[i, j + 1]++;
                        }
                    }
                }
            }
            Console.WriteLine(handleList.Count);
            for(int i = 0; i < handleList.Count; i++)
            {
                Console.WriteLine(handleList[i]);
            }
        }
    }
}


Measured memory_bytes: 28580
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

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

bool prime_number(int n){
   if(n < 2){
      return false;
   }
   else if(n == 2){
      return true;
   }
   if(n % 2 == 0){
      return false;
   }
   for(int i=3;i<=n/i;i+=2){
      if(n % i == 0) return false;
      return true;
   }
}

int main(){
   stack<int> a;
   int n;
   while(cin >> n){
      if(n!=0) a.push(n);
      else{
         cout << a.top() << endl;
         a.pop();
      }
      
   }
   return 0;
}

Measured memory_bytes: 1200
/**
 *   created: 21 July 2019  12:00:05
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	optimizeIO();
	int tt=1;
	// cin>>tt;
	while(tt--){
		int a,b;
		cin>>a>>b;
		int  c = a+b;
		if(c%2){
			cout<<"IMPOSSIBLE";
		}
		else{
			cout<<c/2;
		}
	}
	return 0;
}


Measured memory_bytes: 256
double n,p[333][333][333],r;
c[4];
f(i,j,k,I){I=i+j+k;r=p[i][j][k]?:(p[i][j][k]=(i*(i?f(i-1,j,k),r:0)+j*(j?f(i+1,j-1,k),r:0)+k*(k?f(i,j+1,k-1),r:0)+n)/I);}
main(a)
{
	for(***p=1;~scanf("%d",&a);)!n?n=a:c[a]++;
	printf("%.9f",r-1,f(c[1],c[2],c[3]));
}

Measured memory_bytes: 260224
import heapq
N, M = map(int, input().split())
arubaito = [list(map(int, input().split())) for _ in range(N)]
arubaito.sort()
arubaito2 = [[] for _ in range(M+1)]
for i in range(N):
    if arubaito[i][0] <= M:
        arubaito2[arubaito[i][0]].append(arubaito[i][1])
for i in range(M):
    arubaito2[i].sort(reverse=True)
target = []
ans = 0
heapq.heapify(target)
for i in range(1,M+1):
    for k in arubaito2[i]:
        heapq.heappush(target,k*(-1))
    if len(target) > 0:
        ans += heapq.heappop(target)*(-1)
print(ans)

Measured memory_bytes: 39324
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << ( a + b == c || a + c == b || b + c == a ? "Yes" : "No" ) << endl;
	return 0;
}

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

const int INF = (1<<21);

class State{
public:
	int n,cost,w;
	State(int n=0,int c=0,int w=0):n(n),cost(c),w(w){}
	bool operator < (const State &s) const {
		return cost > s.cost;
	}
};

int main(){
	int n,m;
	while(cin >> n >> m && n && m){
		int G[100][100],d[100][3],f[100][3];
		fill(G[0],G[100],INF);
		fill(d[0],d[100],INF);
		fill(f[0],f[100],false);
		for(int i=0;i<m;i++){
			int a,b,c;
			cin >> a >> b >> c;
			a--;
			b--;
			G[a][b] = G[b][a] = c;
		}

		priority_queue<State> Q;
		State u,v;
		d[0][0] = 0;
		Q.push(u);
		while(!Q.empty()){
			u = Q.top();
			Q.pop();
			f[u.n][u.w] = true;
			for(int i=0;i<n;i++){
				if(u.w == 0 && !f[i][1] && d[u.n][0] < d[i][1] && G[u.n][i] != INF){
					v = u;
					v.n = i;
					v.cost = d[i][1] = d[u.n][0];
					v.w = 1;
					Q.push(v);
				}
				if(u.w == 1){
					if(!f[i][2] && d[u.n][1] < d[i][2] && G[u.n][i] != INF){
						v = u;
						v.n = i;
						v.cost = d[i][2] = d[u.n][1];
						v.w = 2;
						Q.push(v);
					}
				} else if(!f[i][u.w] && d[u.n][u.w] + G[u.n][i] < d[i][u.w]){
					v = u;
					v.n = i;
					v.cost = d[i][u.w] = d[u.n][u.w] + G[u.n][i];
					Q.push(v);
				}
			}
		}

		//for(int i=0;i<3;i++) cout << d[n-1][i] << " ";
		cout << min(d[n-1][0],d[n-1][2]) << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
int n, k, a[20], inf;
bool b[20];
int f(int i, int cnt) {
	if (i == n) {
		if (cnt != k)return inf;
		int m = 0, r = 0;
		for (int i = 0; i < n; i++) {
			if (b[i]) {
				if (m >= a[i]) {
					r += m++ + 1 - a[i];
				}
			}
			m = max(m, a[i]);
		}
		return r;
	}
	int r = f(i + 1, cnt);
	b[i] = 1;
	int r1;
	if (cnt == k - 1)r1 = f(n, cnt + 1);
	else r1 = f(i + 1, cnt + 1);
	b[i] = 0;
	return min(r, r1);
}
signed main() {
	cin >> n >> k;
	inf = 1000000000 * n + 10;
	for (int i = 0; i < n; i++)cin >> a[i];
	cout << f(0, 0) << endl;\
}

Measured memory_bytes: 256
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	void run(){

		for(;;){

			

			int n = sc.nextInt();

			if(n == 0)break;

			char[] map = new char[256];

			for(int i = 0; i < 256; i++){

				map[i] = (char) i;

			}

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

				map[sc.next().charAt(0)] = sc.next().charAt(0);

			}

			int m  = sc.nextInt();

			for(long i = 0; i < m; i++){

				// ret += map[sc.next().charAt(0)] © TLE 

				System.out.print(map[sc.next().charAt(0)]);

			}

			

			System.out.println();

			

		}

		

	}

	public static void main(String[] args){

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 12000
#include <iostream>
#include <map>
#include <utility>
#include <set>
#include <algorithm>
using namespace std;
struct Elem {
    int X;
    int Y;
    int idx;
    Elem(int _X, int _Y, int _idx) : X(_X), Y(_Y), idx(_idx) {}
    Elem() {}
};
int main() {
    int N;
    cin >> N;

    multimap<int, Elem> scores[2];
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        scores[0].insert(make_pair((x + y), Elem(x, y, i)));
        scores[1].insert(make_pair((y + x), Elem(x, y, i)));
    }
   
    int64_t sum[2] = {0, 0};
    set<int> deleted;

    while (scores[0].size() > 0) {
        for (int i = 0; i < 2; i++) {
           while(scores[i].size() > 0) { 
                auto ite = scores[i].end();
                ite--;
                if (deleted.find(ite -> second.idx) != deleted.end()) {
                    scores[i].erase(ite);
                    continue;
                } else {
                    deleted.insert(ite->second.idx);
                    if (i == 0) sum[0] += ite->second.X;
                    else sum[1] += ite->second.Y;
                    break;
                }
            };
          }
    }
    
    cout << sum[0] - sum[1] << endl;
    return 0;
}



Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  vector<ll> sums(n);
  ll ansp = 0;
  ll ansm = 0;
  //p
  vector<ll> ap;
  ap = a;
  vector<ll> sumsp(n);
  sumsp[0]=ap[0];
  if(sumsp[0]<=0){
    ansp += 1 - sumsp[0];
    ap[0]=1;
    sumsp[0]=1;
  }
  for(int i=1;i<n;i++){
    sumsp[i] = sumsp[i-1]+ap[i];
    if(sumsp[i-1]>0 && sumsp[i]>=0){
      ansp += ap[i] + (sumsp[i-1]+1);
      ap[i] = -(sumsp[i-1]+1);
      sumsp[i] = -1;
    }
    else if(sumsp[i-1]<0 && sumsp[i]<=0){
      ansp += (-ap[i])+(-sumsp[i-1]+1);
      ap[i] = (-sumsp[i-1]+1);
      sumsp[i] = 1;
    }
  }
  //m
  vector<ll> am;
  am = a;
  vector<ll> sumsm(n);
  sumsm[0]=am[0];
  if(sumsm[0]>=0){
    ansm += 1 + sumsm[0];
    am[0]=-1;
    sumsm[0]=-1;
  }
  for(int i=1;i<n;i++){
    sumsm[i] = sumsm[i-1]+am[i];
    if(sumsm[i-1]>0 && sumsm[i]>=0){
      ansm += am[i] + (sumsm[i-1]+1);
      am[i] = -(sumsm[i-1]+1);
      sumsm[i] = -1;
    }
    else if(sumsm[i-1]<0 && sumsm[i]<=0){
      ansm += (-am[i])+(-sumsm[i-1]+1);
      am[i] = (-sumsm[i-1]+1);
      sumsm[i] = 1;
    }
  }
  cout << min(ansp,ansm) << endl;
  return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int ans=1,n,k;
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		if(ans>k)ans+=k;
		else ans*=2;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O2")
#pragma GCC optimization ("unroll-loops")
using namespace std;

int n, m;
vector < pair < int, int > > g[100013][3];
map < pair < int, int >, int > dist;
map < pair < int, int >, bool > used;

void bfs (pair < int, int > root) {
	queue < pair < int, int > > q;
	used[root] = 1;
	dist[root] = 0;
	q.push(root);
	while (!q.empty()) {
		pair < int, int > u = q.front();
		q.pop();
		for (auto v: g[u.first][u.second]) {
			if (!used[v]) {
				used[v] = 1;
				dist[v] = dist[u] + 1;
				q.push(v);
			}
		}
	}
}

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int u, v;
		cin >> u >> v;
		for (int j = 0; j < 3; ++j)
			g[u][j].push_back(make_pair(v, (j + 1) % 3));
	}
	int s, t;
	cin >> s >> t;
	bfs(make_pair(s, 0));
	if (used[make_pair(t, 0)])
		cout << dist[make_pair(t, 0)] / 3 << '\n';
	else
		cout << "-1\n";
}


Measured memory_bytes: 54272
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int o = 0; sc.nextInt();
		String tok = sc.next();
		StringBuilder ob = new StringBuilder();
		StringBuilder cb = new StringBuilder();
		for (char ch : tok.toCharArray()) {
			if (ch==')' && o==0) ob.append("(");
			else if (ch==')' && o>0) o--;
			if (ch=='(') o++;
		}
		while (o-->0) cb.append(")");
		System.out.println(ob+tok+cb);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 39404
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    ll k,a,b;
    cin >> k >> a >> b;
    ll now = 1;
    int tmp = k;
    now += min(a-1,k);
    k -= min(a-1,k);
    if(k > 0){
        if(k%2 == 0 && a < b){
            now += (b-a)*k/2;
        }
        else if(k%2 == 1 && a<b){
            k--;
            now += (b-a)*k/2;
            now++;
        }
        else{
            now += k;
        }
        if(now < tmp+1) now = tmp+1;
    }
    
    cout << now << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <iomanip>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 1000000007
#define inf 1000000007
#define ll long long
#define ull unsigned long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 100010
#define _DEBUG
template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}
inline int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}

int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}
int pow(int a,int b,int c){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%c;
        a=1LL*a*a%c;b>>=1;
    }
    return ans;
}

int dp[N][3],a[N][3];
int main(){
    //srand(time(NULL)+clock());
    int ca=0,T,k,i,j,m=0,K,n;
    double start=clock();
    scanf("%d",&n);
    rep(i,0,n)scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
    rep(i,1,n+1){
        rep(j,0,3){
            rep(k,0,3)if(k!=j){
                Max(dp[i][j],dp[i-1][k]+a[i-1][j]);
            }
        }
    }
    int ans=max(dp[n][0],max(dp[n][1],dp[n][2]));
    printf("%d\n",ans);
    cerr<<(1.*clock()-start)/CLOCKS_PER_SEC<<"\n";
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll D, N;
    cin >> D >> N;
    ll p = pow(100LL, D);
    ll ans = p * N;
    if (N == 100)
        ans += p;
    cout << ans << endl;
    return 0;
}

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


def solve(A: int, B: int):
    for i, a, b in map(lambda x: (x, int(x*0.08), int(x*0.1)), range(A*100)):
        if a == A and b == B:
            return i
    return -1


# Generated by 1.1.6 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():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    print(solve(A, B))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  int N, K, X, Y, sum = 0;

  unused = scanf("%d", &N);
  unused = scanf("%d", &K);
  unused = scanf("%d", &X);
  unused = scanf("%d", &Y);

  if(N > K){
    sum += K*X;
    sum += (N-K)*Y;
  }else{
    sum += N*X;
  }

  printf("%d", sum);
  return 0;
}

Measured memory_bytes: 128
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m,k = na()

import collections
import itertools
import operator

class UnionFind:
  def __init__(self, elems=None):
    class KeyDict(dict):
      def __missing__(self, key):
        self[key] = key
        return key

    self.parent = KeyDict()
    self.rank = collections.defaultdict(int)
    self.size_ = collections.defaultdict(lambda: 1)

    if elems is not None:
      for elem in elems:
        _, _, _ = self.parent[elem], self.rank[elem], self.size_[elem]

  def find(self, x):
    if self.parent[x] == x:
      return x
    else:
      self.parent[x] = self.find(self.parent[x])
      return self.parent[x]

  def unite(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x == y:
      return
    if self.rank[x] < self.rank[y]:
      self.parent[x] = y
      self.size_[y] += self.size_[x]
    else:
      self.parent[y] = x
      self.size_[x] += self.size_[y]
    if self.rank[x] == self.rank[y]:
      self.rank[x] += 1

  def are_same(self, x, y):
    return self.find(x) == self.find(y)

  def grouper(self):
    roots = [(x, self.find(x_par)) for x, x_par in self.parent.items()]
    root = operator.itemgetter(1)
    for _, group in itertools.groupby(sorted(roots, key=root), root):
      yield [x for x, _ in group]

  def size(self,x):
    return self.size_[self.find(x)]

g = UnionFind()
fr = [0]*n

for i in range(m):
	a,b = na()
	g.unite(a,b)
	fr[a-1] -= 1
	fr[b-1] -= 1
for j in range(k):
	c,d = na()
	if g.are_same(c,d):
		fr[c-1] -= 1
		fr[d-1] -= 1

for p in range(n):
	fr[p] += (g.size(p+1)-1)

print(' '.join(str(s) for s in fr))

Measured memory_bytes: 39088
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define df 0
int dc=100000;
#define MAX 100010
#define MAX_heap 200000
typedef long int li;

typedef struct{
  int i;
  li item;
}cell;

typedef struct _heap{
  cell cells[MAX_heap+1]; // 1-origin
  int length;
}heap;

typedef unsigned char boolean;

int adj(int i,int n){
  if(i==-1)i+=n;
  if(i==n)i-=n;
  return i;
}
void init_heap_univ(heap* H);
boolean compare_cell(cell x, cell y);
void put_heap_univ(heap* H,cell x);
cell pull_heap_univ(heap* H);
int flag_heap_univ(heap* H, int itr,cell temp);


int main(){
  if(df)printf("*** debug mode ***\n");
  int n;
  scanf("%d",&n);
  int a[n],i;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  cell b[i];
  heap que;
  init_heap_univ(&que);
  for(i=0;i<n;i++){
    li x;
    scanf("%ld",&x);
    b[i].i=i;
    b[i].item=x;
    put_heap_univ(&que,b[i]);
  }
  long int ans=0;
  while(que.length){
    cell c=pull_heap_univ(&que);
    if(df)printf("i:%d,item:%ld ... %ld rem\n",c.i,c.item,c.item-a[c.i]);
    if(c.item==a[c.i])continue;
    int i=adj(c.i-1,n),j=adj(c.i+1,n);
    li p=b[i].item+b[j].item;
    if(df)printf("find %d,%d (%ld,%ld)  ",i,j,b[i].item,b[j].item);
    li num=(c.item-a[c.i])/p;
    if(df)printf("-> delete %ld times\n",num);
    if(num<=0){
      ans=-1;
      break;
    }
    ans+=num;
    c.item-=num*p;
    b[c.i].item=c.item;
    put_heap_univ(&que,c);
  }
  
  

  printf("%ld",ans);
  return 0;
}

void init_heap_univ(heap* H){
  H->length=0;
}

boolean compare_cell(cell x, cell y){
  if(x.item>y.item)return 1;
  return 0;
}

void put_heap_univ(heap* H,cell x){
  H->length++;
  int i=H->length;
  while(i>1 && compare_cell(x,H->cells[i/2])){
    H->cells[i]=H->cells[i/2];
    i/=2;
  }
  H->cells[i]=x;
  //  for(i=0; i<=heap[0];i++)
  //    printf("%lu ",heap[i]);
  //  printf("\n",heap[i]);

}

cell pull_heap_univ(heap* H){
  cell x=H->cells[1],temp=H->cells[H->length];
  int itr=1,itr2,flag;
  H->length--;
  flag=flag_heap_univ(H,itr,temp);
  while(flag){
    itr2=2*itr+flag-1;
    H->cells[itr]=H->cells[itr2];
    itr=itr2;
    flag=flag_heap_univ(H,itr,temp);
  }
  H->cells[itr]=temp;
  return x;
}

int flag_heap_univ(heap* H, int itr,cell temp){
  int flag;
  if(H->length<itr*2) flag=0;
  else if(H->length==itr*2)
    flag=(compare_cell(temp,H->cells[itr*2])?0:1);
  else if(compare_cell(H->cells[itr*2],H->cells[itr*2+1]))
    flag=(compare_cell(temp,H->cells[itr*2])?0:1);
  else flag=(compare_cell(temp,H->cells[itr*2+1])?0:2);

  //  printf("%d ",flag);
  return flag;
}



/// confirm df==0 ///


Measured memory_bytes: 7296
#include <iostream>
#define llint long long

using namespace std;

llint p, q;
bool prime[100005];

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

int main(void)
{
	cin >> p >> q;
	llint g = gcd(p, q);
	
	p /= g, q /= g;
	
	for(int i = 2; i < 1005; i++){
		if(prime[i]) continue;
		for(int j = 2*i; j < 100005; j+=i) prime[j] = true;
	}
	
	llint ans = 1;
	for(int i = 2; i < 100005; i++){
		if(prime[i]) continue;
		bool flag = false;
		while(q % i == 0){
			q /= i;
			flag = true;
		}
		if(flag) ans *= i;
	}
	if(q > 1) ans *= q;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3196
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();

        String s = String.valueOf(n);
        if (n % 10 == 0) {
            System.out.println("10");
        } else {
            int ans = 0;
            for (int i = 0; i < s.length(); i++) {
                ans += Integer.parseInt(String.valueOf(s.charAt(i)));
            }
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 23764
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#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>
#if __cplusplus >= 201103L
#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>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, ans;
    cin >> a >> b;
    if (a % b == 0) {
      ans = 0;
    } else {
      ans = 1;
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,a;
  cin >> n;
  for(int i=0;i<n;i++){
    long long b=0,c=0;
    bool f=true;
    for(int j=0;j<10;j++){
      cin >> a;
      if(b<a){
        b=a;
      }else if(c<a){
        c=a;
      }else{
        f=false;
      }
    }
    cout << (f?"YES":"NO") << endl;
  }
  return 0;
}



Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

int main() {
    int a, b;
    scanf("%2d%2d", &a, &b);
    bool f = 1 <= a && a <= 12, g = 1 <= b && b <= 12;
    string ans = "NA";
    if (f && g) ans = "AMBIGUOUS";
    if (f && !g) ans = "MMYY";
    if (!f && g) ans = "YYMM";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define brep(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define SZ(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
#define MAX 100005
int n,m;
int curi,curj;
int flip  =0;
int flag = 0;
void nexti(){
	if((curj == m-1 || curj == 0) && flag == 1){
		curi++;
		flip ^= 1;
		flag = 0;
		return;
	}
	flag = 1;
	if(flip == 0) curj++;
	else curj--;
}
int main(){
	int cols;
	int a[MAX];
	int ans[105][105];
	cin >> n >> m;
	cin >> cols;
	curi = 0;
	curj = 0;
	rep(i,0,cols) cin >> a[i];
	
 
	for(int i = 0;i < cols;i++){
 
		for(int j = 0;j < a[i];j++){
 
			ans[curi][curj] = i+1;
			if(m != 1) nexti();
			else curi++;
		}
	}
	for(int i = 0;i < n;i++){
 
		for(int j = 0;j < m;j++){
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
H, N = map(int, input().split())

skill_list = []
for i in range(N):
  skill_list.append(list(map(int, input().split())))

max_B = 0
for i in range(N):
  if skill_list[i][0] > max_B: max_B = skill_list[i][0]

dp = [float('inf') for i in range(H + max_B)]

dp[0] = 0
for i in range(H):
  for j in range(N):
    if dp[i + skill_list[j][0]] > dp[i] + skill_list[j][1]:
      dp[i + skill_list[j][0]] = dp[i] + skill_list[j][1]

print(min(dp[H : H + max_B]))

Measured memory_bytes: 42988
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(long long i=0;i<n;i++)
#define REPP(i,m,n) for(long long i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    vector<int> V(3);
    REP(i,3) cin >> V[i];
    int cnt = 0;
    while(V[0] != V[1] || V[1] != V[2]){
        sort ALL(V);
        if(V[2] - V[0] >= 2){
            cnt++;
            V[0] += 2;
        }
        else if(V[2] - V[0] == 1){
            cnt++;
            V[2] -= 1;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<string>
#include<string.h>
#include<cmath>
#include<set>
#include<vector>
#include<queue>
#include<map>
#include<time.h>
using namespace std;
using ll = long long;
const int INF = 2e9 + 10;
using pii = pair<int, int>;
using vi = vector<int>;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define mp make_pair 
#define pb push_back
#define clr(x, v) memset(x, v, sizeof (x))
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const int N = 1e6 + 10;
int h, w;
int a[505][505];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    while (cin >> h >> w) {
        vector<vector<int>> res;
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                cin >> a[i][j];
            }
        }
        int y = 1, x = 1;
        int pre = 0;
        int dx = 1;
        while (true) {
            int ny = y, nx = x;
            if (dx == 1 && nx == w || dx == -1 && nx == 1) {
                ny++;
                dx = -dx;
            }
            else {
                nx += dx;
            }
            if (ny > h) break;
            a[y][x] += pre;
            if (a[y][x] & 1) {
                res.emplace_back(vector<int>{y, x, ny, nx}); 
                pre = 1;
            } else {
                pre = 0;
            }
            y = ny, x = nx;
        }
        cout << (int) res.size() << endl;
        for (auto v : res) {
            cout << v[0] << " " << v[1] << " " << v[2] << " " << v[3] << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 10032
#include <iostream>
#include <stdlib.h>
#include <string>

using namespace std;

void solve()
{
	int ans = 0;
	string str;
	while(cin >> str)
	{
		string num_str;
		for(int i = 0; i < str.size(); ++i)
		{
			if('0' <= str[i] && str[i] <= '9')
			{
				num_str += str[i];
			}
			else
			{
				ans += atoi(num_str.c_str());
				num_str = "";
			}
		}
		if(num_str != "")
		{
			ans += atoi(num_str.c_str());
		}
	}
	cout << ans << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

//何が、何回で残るか
pll calc(ll x, ll n) {
	if (n == 0)return pll(0, 0);
	if (n == 1)return pll(x,0);
	pll res = calc(x, n / 2);
	ll ans = 2 * res.second;
	deque<ll> deq;
	deq.push_back(res.first);
	if (n & 1)deq.push_back(x);
	deq.push_back(res.first);
	while (deq.size() >= 2) {
		ll next = deq.front();
		deq.pop_front();
		next += deq.front();
		deq.pop_front();
		ans++;
		if (next <= 9)deq.push_front(next);
		else {
			deq.push_front(next % 10);
			deq.push_front(next/10);
		}
	}
	return pll(deq.front(),ans);
}

pll calc(pll a, pll b) {
	deque<ll> deq;
	ll ans = 0;
	a = calc(a.first,a.second);
	deq.push_back(a.first);
	ans += a.second;
	b = calc(b.first, b.second);
	deq.push_back(b.first);
	ans += b.second;
	while (deq.size() > 1) {
		ll next = deq.front();
		deq.pop_front();
		next += deq.front();
		deq.pop_front();
		ans++;
		if (next <= 9)deq.push_front(next);
		else {
			deq.push_front(next % 10);
			deq.push_front(next / 10);
		}
	}
	return pll(deq.front(), ans);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	ll M;
	cin >> M;
	deque<pll> deq;
	for (ll m = 0; m < M; m++) {
		ll d, c;
		cin >> d >> c;
		deq.push_back(pll(d, c));
	}
	ll ans = 0;
	while (deq.size() > 1) {
		pll res = calc(deq.front(), deq[1]);
		deq.pop_front();
		deq.pop_front();
		ans += res.second;
		deq.push_front(pll(res.first, 1));
	}
	if (deq.front().second > 1) {
		pll res = calc(deq.front().first, deq.front().second);
		ans += res.second;
	}
	cout << ans << "\n";
	return 0;
}


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

using namespace std;

int calc(int A, const vector<int> &a) {
  return abs(A - accumulate(a.begin(), a.end(), 0)) + (a.size() - 1) * 10;
}

int main() {
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<int> L(N);
  for (int i = 0; i < N; i++) cin >> L[i];

  int answer = numeric_limits<int>::max();
  for (int i = 0; i < pow(4, N); i++) {
    vector<int> a, b, c;
    for (int j = 0; j < N; j++) {
      int k = (i >> (2 * j)) & 3;
      if (k == 0) {
        a.push_back(L[j]);
      } else if (k == 1) {
        b.push_back(L[j]);
      } else if (k == 2) {
        c.push_back(L[j]);
      }
    }

    if (a.empty() || b.empty() || c.empty()) {
      continue;
    }

    int mp = calc(A, a) + calc(B, b) + calc(C, c);
    answer = min(answer, mp);
  }
  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N, K, S;
    cin >> N >> K >> S;
    int A[N]{};
    int v = 1000000000;
    for (int i = 0; i < K; i++) {
        A[i] = S;
    }
    if (S == v) {
        for (int i = K; i < N; i++) {
            A[i] = 1;
        }
    } else {
        for (int i = K; i < N; i++) {
            A[i] = v;
        }
    }
    for (int i = 0; i < N; i++) {
        if (i == N - 1) {
            cout << A[i] << "\n";
        } else {
            cout << A[i] << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

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


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

const int inf = 1e9;
struct edge { int to, cost; edge(int to, int cost) : to(to), cost(cost) {} };

template<class T> bool bellman_ford(int s, const VV<edge>& g, V<T>& d) {
  d.assign(g.size(), inf);
  d[s] = 0;
  for (int i = 0; i < g.size(); i++) {
    bool upd = false;
    for (int v = 0; v < g.size(); v++) {
      for (auto&& e : g[v]) {
        if (d[v] != inf and d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          upd = true;
        }
      }
    }
    if (!upd) return false;
  }
  return true;
}

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  VV<edge> g(n);
  for (int i = 0; i < m; i++) {
    int a, b; cin >> a >> b;
    g[a].emplace_back(b, -1);
  }
  V<> d;
  for (int i = 0; i < n; i++) if (bellman_ford<int>(i, g, d)) return cout << 1 << '\n', 0;
  cout << 0 << '\n';
}


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

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

    for (ll i = 1; i <= 3500; ++i) {
        for (ll j = i; j <= 3500; ++j) {
            if ((4 * i * j - N * (i + j)) == 0)
                continue;
            if ((N * i * j) % (4 * i * j - N * (i + j)) != 0)
                continue;

            ll k = (N * i * j) / (4 * i * j - N * (i + j));
            if (k >= 0) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3604