akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
  数値型から文字列に変換　to_string(number);これは簡単
  文字列から数値型に変換　stoi(number)
  文字列からllに変換　stoll(number)*/

//ここから書き始める
int main(){
	vector<int> a(4,0);
	rep(i,6){
		int s;
		cin >> s;
		s--;
		a[s] ++;
	}
	SORT(a);
//	for(auto x:a){
//		cout<<x<<" " ;
//	}
	if(a[3]>=3) cout<<"NO"<<endl;
	else cout <<"YES"<<endl;
		
}


Measured memory_bytes: 256
#include<iostream>
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<algorithm>
#include<math.h>
#include"boost/algorithm/string.hpp"

using namespace std;

struct test_t{
	unsigned long long target;
	unsigned long long state;
	long long diff;
	int change;

	friend bool operator<(const test_t& l, const test_t& r)
	{
		return l.diff < r.diff;
	}
};

int main(){
		

	/*Q3*/
	/*Q2*/

	int n;
	vector<string> str;
	str.resize(3);
	cin >> n;
	cin >> str[0];
	cin >> str[1];
	cin >> str[2];

	int count = 0;

	for (int i = 0; i < n; ++i){
		//3つとも同じ
		if (str[0][i] == str[1][i] && str[0][i] == str[2][i]){
			count += 0;
		}
		else if (str[0][i] == str[1][i] || str[0][i] == str[2][i] || str[1][i] == str[2][i]){
			count += 1;
		}
		else{
			count += 2;
		}

	}

	cout << count;
	return 0;

	/*Q1*/
	//typedef
	/*
	int ret = 0;
	int in[4] = {0};
	int total, a, b, max, min;
	
	cin >> total >> a >> b;

	max = a > b ? b : a;

	if (a + b > total){
		min = a + b - total;
	}
	else{
		min = 0;
	}

	cout << max << " " << min;

	return 0;
	*/
	/*Q2*/

	/*Q3*/

		/*Q4*/

		//return 0;
}


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

using namespace std;

#define fi first
#define se second
#define pb push_back

const int N = 705;
int n, m, cntCC[2][N], nCC, ans;
vector<int> gr[N];
bool edge[N][N], vis[N], sta[N], dp[N][N][N];

void dfs(int u) {
    vis[u] = 1;
    cntCC[ sta[u] ][nCC] ++;
    for (int v : gr[u]) {
        if(vis[v]) {
            if(sta[v] == sta[u]) { cout << -1; exit(0); }
        }
        else {
            sta[v] = (sta[u] ^ 1);
            dfs(v);
        }
    }
}

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m; ans = m;
    for (int i = 0; i < m; ++i) {
        int u, v; cin >> u >> v;
        edge[u][v] = edge[v][u] = 1;
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            if(i != j && !edge[i][j]) gr[i].pb(j), gr[j].pb(i);
        }
    }

    for (int i = 1; i <= n; ++i) if(!vis[i]) nCC ++, dfs(i);

    dp[0][0][0] = 1;
    for (int i = 0; i < nCC; ++i) {
        for (int j = 0; j <= n; ++j) {
            for (int k = 0; k <= n; ++k) {
                if(!dp[i][j][k]) continue;
                dp[i + 1][j + cntCC[0][i + 1] ][k + cntCC[1][i + 1] ] |= dp[i][j][k];
                dp[i + 1][j + cntCC[1][i + 1] ][k + cntCC[0][i + 1] ] |= dp[i][j][k];
            }
        }
    }

    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            if(!dp[nCC][i][j]) continue ;
            ans = min(ans, i * (i - 1) / 2 + j * (j - 1) / 2);
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 332544
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    
    a=[int(input()) for i in range(n)]
    b=sum(a[0:k])
    c=[b]
    for j in range(k,n):
        b=b+a[j]-a[j-k]
        c.append(b)
    print(max(c))


Measured memory_bytes: 11700
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR (int x) {
	if (x ==1)
		return false;
	if (x == 2)
		return true;
	if (x%2==0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}

using namespace std;
#pragma endregion

signed main() {
	int w=0, l=0;
	string S;
	cin >> S;
	rep(i, S.size()) {
		if (S[i] == 'o')
			w++;
		else
			l++;
	}
	if (15 - (w + l) >= 8 - w)
		cout << "YES";
	else
		cout << "NO";
}

Measured memory_bytes: 256
#include <climits>
#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

const int MAX_N = 200000;

ll l;
int n;
vector<int> trees(MAX_N+2);

int main() {
    cin >> l >> n;
    for(int i=1;i<=n;++i) cin >> trees[i];
    trees[n+1] = l;

    ll a[n+1];
    a[0] = 0;
    for(int i=1;i<=n;++i) a[i] = a[i-1] + trees[i];

    ll ans = 0LL, tmpans;
    for(int i=1;i<=n;++i) {
        tmpans = (n-i) * l + 2 * (a[i+(n-i)/2] - a[i-1]) - trees[i+(n-i+1)/2] - 2 * (a[n] - a[i+(n-i+1)/2]);
        ans = max(ans, tmpans);
        tmpans = i * l + 2 * a[(i-1)/2] + trees[(i+1)/2] - 2 * (a[i] - a[i-(i+1)/2]);
        ans = max(ans, tmpans);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
long long a[105],b[105];
int main()
{
	long long n,sum=1e9;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		b[i]=b[i-1]+a[i];
	}
	for(int i=1;i<=n;i++)
		sum=min(sum,abs(b[i]-(b[n]-b[i])));
	cout<<sum;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n,i,ans,max,min;
    scanf("%d",&n);
    int a[n];
    scanf("%d",&a[0]);
    max = a[0];
    min = a[0];
    for(i=1;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]>max)max = a[i];
        if(a[i]<min)min = a[i];
    }
    printf("%d",max-min);
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

	// data representation
	// int of vertices
	static int v;
	// the graph
	static int[][] graph;
	// int[] that's gonna represent the mst
	static int[] mst;
	// boolean of vertices that have been visited
	static boolean[] visited;
	
	
	public static void prim() {
		
		
		//pick a vertex
		mst[0] = 0;
		
		for(int i = 0; i < v; i++) {
			int u = minVertex();
			//set that this vertex has been visited
			visited[u] = true;
			
			// go through all the edges that is connected to and find the least cost
			// check that there is a connection ( no -1) and that it has not been visited yet
			// also check that the path is less costly than the one exisiting in MST now
			for(int j = 0; j < v; j++) {
				if(graph[u][j] != -1 && !visited[j] && graph[u][j] < mst[j] ){
					mst[j] = graph[u][j];
				}
			}
		}
		
		//now sum it all up and print it out
		int sum = 0;
		for(int i = 0; i < v; i++) {
			sum += mst[i];
		}
		System.out.println(sum);
		
	}
	
	public static int minVertex() {
		int min = 0;
		// the biggest a number can be is 2000
		int limit = 2001;
		
		for(int i = 0; i < v; i++) {
			if(visited[i] == false && mst[i] < limit) {
				limit = mst[i];
				min = i;
			}
		}
		
		return min;
	}
	
	public static void main(String[] args) {
		
		//Set up Scanner
		Scanner in = new Scanner(System.in);
		
		//First int is the number of vertices
		v = in.nextInt();
		
		//To represent graph given
		graph = new int[v][v];
		
		//fill in the graph with adjanceny matrix given
		for (int i = 0; i < v; i++) {
			for(int j = 0; j < v; j++) {
				graph[i][j] = in.nextInt();
			}
		}
		//close the scanner
		in.close();
		
		// initialize all vertices to say they have not been visited
		// initialize mst to infinity
		mst = new int[v];
		visited = new boolean[v];
		
		for(int i = 0; i < v; i++) {
			mst[i] = 9999999;
			visited[i] = false;
		}
				
		//call the algorithim here
		prim();
		

	}	
}



Measured memory_bytes: 40932
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

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

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int a, b;
    cin >> a >> b;
    if (a % 3 == 0 | b % 3 == 0 | (a + b) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 256
loop do
  n = gets.to_i
  break if n == 0

  num = 0
  lim = ((n+n%2)/2)
  1.upto(lim-1) do |base|
    (base..lim).inject(0) do |sum, i|
      sum += i
      if ( sum >= n )
        num += 1 if sum == n
        break
      end
      next sum
    end
  end

  puts num
end

Measured memory_bytes: 6100
import java.util.*;
public class Main {
	public static void main(String[] args){
       Scanner sc = new Scanner(System.in);   
       //値の取得
      int N = sc.nextInt();
      int K = sc.nextInt();
      int ans = K;
       for(int i=1;i<N;i++){
        ans*=(K-1);
       }
      System.out.println(ans);
    }
}

Measured memory_bytes: 35464
N = int(input())
S = [input() for _ in range(N)]
first = 0
second = 0
ans = "YES"
for s in S:
    if s == "A":
        first += 1
    elif s == "Un":
        second += 1
    if first < second:
        ans = "NO"
        break
if first != second:
    ans = "NO"
print(ans)


Measured memory_bytes: 5604
import java.util.*;

import static java.lang.System.*;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = ni();
        long[] A = nlarr(N);
        Arrays.sort(A);

        long BSum = 0;
        for (int i = 0; i < N; i++) {
            BSum += A[i];
        }

        for (int i = 0; i < N - 1; i +=2 ) {
            if (A[i] <= 0 && A[i + 1] <= 0) {
                BSum += 2 * Math.abs(A[i] + A[i + 1]);
            } else if (A[i] <= 0 && A[i + 1] >= 0) {
                if (Math.abs(A[i]) > A[i + 1]) {
                    BSum += 2 * Math.abs(A[i]) - 2 * A[i + 1];
                }
            }
        }

        out.println(BSum);
    }

    static int ni() {
        return sc.nextInt();
    }

    static long nl() {
        return sc.nextLong();
    }

    static String ns() {
        return sc.next();
    }

    static int[] niarr(int N) {
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        return a;
    }

    static long[] nlarr(int N) {
        long[] a = new long[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextLong();
        }
        return a;
    }
}

Measured memory_bytes: 61244
import collections
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

##* graph
##pre graph
m,lst,nxt,to=0,[],[],[]

def init_graph(node_count, edge_count):
    global lst,nxt,to
    lst = [-1 for _ in range(node_count)]
    nxt = [0  for _ in range(edge_count)]
    to  = [0  for _ in range(edge_count)]

# bidirection
def add_edge(u, v):
    global m
    nxt[m], lst[u], to[m], m = lst[u], m, v, m + 1
    nxt[m], lst[v], to[m], m = lst[v], m, u, m + 1

# bidirection weight
def add_edge(u, v, w):
    global m
    nxt[m], lst[u], to[m], m = lst[u], m, (v, w), m + 1
    nxt[m], lst[v], to[m], m = lst[v], m, (u, w), m + 1

def traverse(u):
    m = lst[u]
    while m != -1:
        yield m
        m = nxt[m]


n = getint()
init_graph(n, 2 * n)

for _ in range(n - 1):
    u, v, w = getints()
    add_edge(u - 1, v - 1, w)

def get_distance(u, dist):
    dist[u] = 0
    stk = [(u, 0)]
    while stk:
        v, d = stk[-1]
        stk.pop()
        for m in traverse(v):
            vv, w = to[m]
            if dist[vv] >= 0:
                continue
            dist[vv] = d + w
            stk.append((vv, d + w))


dist = [-1]*n
get_distance(0, dist)

# print(dist)


for i in range(n):
    print(dist[i] % 2)

Measured memory_bytes: 41628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_9_c2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int point0 = 0;
            int point1 = 0;
            string[] word = new string[2];

            for (int i = 0; i < n; i++)
            {
                word = Console.ReadLine().Split(' ');
                if (word[0].CompareTo(word[1]) > 0)
                {
                    point0 += 3;
                }
                else if (word[0].CompareTo(word[1]) < 0)
                {
                    point1 += 3;
                }
                else
                {
                    point0 += 1;
                    point1 += 1;
                }
            }
                Console.WriteLine("{0} {1}", point0, point1);
        }
    }
}



Measured memory_bytes: 20772
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int n, t, tt[200000];
    cin >> n >> t;
    for(int i=0; i<n; i++) cin >> tt[i];

    int x = 0;
    for(int i=0; i<n-1; i++){
        if(tt[i] + t >= tt[i+1]){
            x += tt[i+1] - tt[i];
        }
        else x += t;
    }
    x += t;

    cout << x << endl;

    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) {
                break;
            } else {
                for (int i = 1; i <= H; ++i) {
                    for (int j = 1; j <= W; ++j) {
                        if (((i % 2 == 1) && (j % 2 == 1)) || ((i % 2 == 0) && (j % 2 == 0))) {
                            System.out.print("#");
                        } else {
                            System.out.print(".");
                        }
                    }
                    System.out.print("\n");
                }
                System.out.print("\n");
            }
        }
    }
}


Measured memory_bytes: 37716
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int N=2005;
int n;
int a[N][N];
bool fl[N][N],fr[N][N];
vector<int>pos[N];
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
		for(int j=1;j<=i-1;j++)
			scanf("%1d",&a[i][j]),a[j][i]=a[i][j]^1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(a[i][j]) pos[i].push_back(j);
	for(int i=1;i<=n;i++)
		fl[i][i]=fr[i][i]=true;
	for(int len=2;len<=n;len++)
		for(int i=1;i+len-1<=n;i++)
		{
			int j=i+len-1;
			int l=lower_bound(pos[i].begin(),pos[i].end(),i+1)-pos[i].begin(),r=upper_bound(pos[i].begin(),pos[i].end(),j)-pos[i].begin()-1;
			for(int p=l;p<=r;p++)
			{
				int k=pos[i][p];
				fl[i][j]|=fr[i+1][k]&fl[k][j];
				if(fl[i][j]) break;
			}
			l=lower_bound(pos[j].begin(),pos[j].end(),i)-pos[j].begin(),r=upper_bound(pos[j].begin(),pos[j].end(),j-1)-pos[j].begin()-1;
			for(int p=l;p<=r;p++)
			{
				int k=pos[j][p];
				fr[i][j]|=fr[i][k]&fl[k][j-1];
				if(fr[i][j]) break;
			}
		}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(fr[1][i]&&fl[i][n]) ans++;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 38404
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  cout << max(0, 60 * (h2 - h1) + m2 - m1 - k) << endl;
  return 0;
}


Measured memory_bytes: 3648
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, A = readline().decode('utf8').split()
S = int(N + A)


print('Yes' if S == int(S ** .5) * int(S ** .5) else 'No')


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 1001001001;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


mint comb(int n, int r){
	if ( r * 2 > n ) r = n - r;
	mint dividend = 1;
	mint divisor  = 1;
	for (int i = 1; i <= r; ++i ) {
	dividend *= (n-i+1);
	divisor  *= i;
	}
	return dividend / divisor;
}

int main(){
	int x, y; cin >> x >> y;
	if((x+y)%3 || x<(x+y)/3 || y<(x+y)/3){
		cout << 0 << endl;
		return 0;
	}
	int n = (x+y) /3;
	int r = x - n;
	cout << comb(n,r) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

void solve() {
    int N; cin >> N;
    ll A[200200], B[200200];
    ll sum = 0;
    bool flag = true;
    ll mini = INF;
    rep(i, N) {
        cin >> A[i] >> B[i];
        if(A[i] > B[i]) mini = min(mini, B[i]);
        if(A[i] != B[i]) flag = false;
        sum += A[i];
    }
    if(flag) {
        cout << 0 << endl;
    } else {
        cout << sum - mini << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

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

int main(){

    double r = 0;
    double pi = 3.141592653589;		//円周率の設定 


    cin >> r ;


    cout << fixed;			//出力時の小数点以下の有効数字を6桁に設定
    cout << setprecision(6);		//さらに大きな数を指定しても可

    cout << r * r * pi << " ";		//面積の出力
    cout << r * 2 * pi << endl;		//円周の出力


    return 0;
}


Measured memory_bytes: 3228
// 16/06/2020 // 7:15 PM // 

#include <bits/stdc++.h>

using namespace std;

#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define pb push_back
#define int long long

const int MAXN  = 20;
const int INF   = 0x3f3f3f3f3f3f3f3f;
const int MAXNN = 65536 + 5; // 2^16 + 5 

int n, max_mask; 
int a[MAXN][MAXN], pts[MAXNN];
vector<int> memo;

void pre_calc(){
	for(int mask=1; mask<=max_mask; mask++){   // O(2^n * n^2)
		for(int i=0; i<=n; i++){
			if(((1<<i)&mask) == 0) continue;
			
			for(int j=i+1; j<=n; j++)
				if(((1<<j)&mask)!=0)
					pts[mask] += a[i][j];
		}
	}
}

int solve(int mask_total){ 
	if(memo[mask_total]!=-INF) return memo[mask_total];

	if(mask_total==max_mask ) return 0;

	int& ans = memo[mask_total];
	ans = -INF;
	
	vector<int> disp;
	for(int k=0; k<n; k++){
		if(((1<<k)&mask_total)==0) disp.pb(k);
	}
	int max_temp = (1<<((int)disp.size()))-1; 
	for(int tmask=1; tmask<=max_temp; tmask++){
		int gp_mask = 0;
		for(int k=0; k<(int)disp.size(); k++){
			if(((1<<k)&tmask)!=0) gp_mask += (1<<disp[k]);
		}
		
		ans = max(ans, pts[gp_mask] + solve(mask_total|gp_mask));
	}

	return ans;
}

int32_t	main(){
	fast_io;
	
	cin >> n; 
	
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
			cin >> a[i][j];
	
	max_mask = (1<<n)-1;
	
	memo.resize(max_mask+1, -INF);
		
	pre_calc();
	
	cout << solve(0) << endl;
	
	return 0;
}

Measured memory_bytes: 4240
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MD = 1000000007;

/* sample input

*/

int main()
{
	int n;
	string s1, s2;
	ll answer = 0;
	cin >> n;
	cin >> s1;
	cin >> s2;

	//繋がり方4パターン
	int flug = 0; //前の状態,縦なら0,横なら1

	int size = s1.length();

	int current;
	if (s1[0] == s1[1]) {
		answer = 6;
		current = 2;
		flug = 1;
	}
	else {
		answer = 3;
		current = 1;
		flug = 0;
	}


	for (int i = current; i < size; ) {
		if (i < size - 1) {//size-1なら縦しか無理
			if (s1[i] == s1[i + 1]) {
				if (flug == 0) {
					//縦横
					answer = answer * 2 % MD;
					flug = 1;
					i += 2;
				}
				else {
					//横横
					answer = answer * 3 % MD;
					flug = 1;
					i += 2;
				}
			}
			else {
				if (flug == 0) {
					//縦縦
					answer = answer * 2 % MD;
					flug = 0;
					i += 1;
				}
				else {
					//横縦
					answer = answer * 1 % MD;
					flug = 0;
					i += 1;
				}
			}
		}
		else {
			//i==size-1なら縦しか無理
			if (flug == 0) {
				//縦縦
				answer = answer * 2 % MD;
				flug = 0;
				i += 1;
			}
			else {
				//横縦
				answer = answer * 1 % MD;
				flug = 0;
				i += 1;
			}
		}
	}

	cout << answer;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set> 
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>
using namespace std;
#define assem99 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define ld long double
#define ii pair<int, int>
#define vii vector<ii>
#define f(i,a,b) for(int i=a; i<b; i++)
#define F first
#define S second
#define sz(a) (int)(a).size()
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
int x[] = { 0, -1, 0, 1, -1, 1, -1, 1 };
int y[] = { -1, 0, 1, 0, 1, -1, -1, 1 };
const int MOD = 998244353, N = 2e5 + 5;
const double pi = acos(-1);

int dp[3005][3005];

int main()
{
	assem99;

	string s, t; cin >> s >> t;
	f(i, 0, sz(s))
	{
		f(j, 0, sz(t))
		{
			if (s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
			else dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
		}
	}
	int cur = dp[sz(s)][sz(t)];
	string ans = "";
	int i = sz(s), j = sz(t);
	while (i > 0 && j > 0)
	{
		if (dp[i][j] != dp[i - 1][j] && dp[i][j] != dp[i][j - 1])
		{
			ans += s[i - 1];
			i--, j--;
		}
		else if (dp[i][j] == dp[i - 1][j]) i--;
		else j--;
	}
	for (int i = sz(ans) - 1; i >= 0; i--) cout << ans[i];

	return 0;
}


Measured memory_bytes: 35456
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

const int MOD = 924844033;
const int MAX = 5100;

long long fac[MAX];
void FACInit(){
    fac[0] = fac[1] = 1;
    for(int i = 2; i < MAX; i++) fac[i] = fac[i-1] * i % MOD;
}

int dp[4100][2100][2]; // dp[サイズ i までのパスについて][j 個のマッチングを得ていて][最後の辺が「選ばれているかどうか]

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

int main() {
    FACInit();
    int N, K;
    cin >> N >> K;
    
    vector<int> pathsize(K*2, 0); // 各パスのサイズ
    for (int k = 0; k < K*2; ++k) {
        for (int i = k; i < N; i += K*2) {
            if (i - K >= 0) ++pathsize[k];
            if (i + K < N) ++pathsize[k];
        }
    }
    for (int i = 0; i < pathsize.size(); ++i) {
        if (pathsize[i] == 0)
            pathsize.erase(pathsize.begin() + i--);
    }
    
    // DP: サイズ i のマッチングの個数を求める
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    int kireme = pathsize[0];
    int kireme_ind = 0;
    for (int i = 0; i <= N*2; ++i) {
        for (int j = 0; j <= min(N, i); ++j) {
            add(dp[i+1][j][0], dp[i][j][0]);
            add(dp[i+1][j+1][1], dp[i][j][0]);
            add(dp[i+1][j][0], dp[i][j][1]);
            if (i == kireme) add(dp[i+1][j+1][1], dp[i][j][1]);
        }
        if (i == kireme) {
            ++kireme_ind;
            if (kireme_ind == (int)pathsize.size()) break;
            kireme += pathsize[kireme_ind];
        }
    }

    // 包除原理する
    long long res = 0;
    for (int num = 0; num <= N; ++num) {
        long long matching_size = (dp[kireme][num][0] + dp[kireme][num][1]) % MOD;
        if (num % 2 == 0) (res += fac[N - num] * matching_size % MOD) %= MOD;
        else (res += MOD - fac[N - num] * matching_size % MOD) %= MOD;
    }
    
    cout << res << endl;
}

Measured memory_bytes: 67584
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] ve = scanner.nextLine().split(" ", 2);
        int v = Integer.parseInt(ve[0]);
        int e = Integer.parseInt(ve[1]);

        Map<Integer, List<Integer>> vEdges = new HashMap<>();

        for (int i = 0; i < e; i++) {
            String[] st = scanner.nextLine().split(" ", 2);
            int s = Integer.parseInt(st[0]);
            int t = Integer.parseInt(st[1]);

            List<Integer> edges = vEdges.get(s);
            if (edges == null) {
                edges = new ArrayList<>();
                vEdges.put(s, edges);
            }
            edges.add(t);
        }

        Set<Integer> visited = new HashSet<>();
        List<Integer> sorted = new ArrayList<>();
        for (int i = 0; i < v; i++) {
            visit(visited, sorted, vEdges, i, 0);
        }

        for (Integer vertex : sorted) {
            System.out.println(vertex);
        }
    }

    private static void visit(Set<Integer> visited, List<Integer> sorted, Map<Integer, List<Integer>> vEdges, int vertex, int depth) {
        if (visited.contains(vertex)) return;
        visited.add(vertex);

        if (vEdges.containsKey(vertex)) {
            for (Integer edge : vEdges.get(vertex)) {
                visit(visited, sorted, vEdges, edge, depth + 1);
            }
        }
        sorted.add(0, vertex);
    }
}



Measured memory_bytes: 106820
#include <iostream>
#include<cmath>
#include <iomanip>

using namespace std;

int main()
{
	int N, A, B;
	cin >> N >> A >> B;

	int t = N * A;

	if (t <= B) {
		cout << t << endl;
	}
	else {
		cout << B << endl;
	}

}






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


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }


    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);


        var n = Read();
        double total = 0;
        for(int i = 0; i < n; i++)
        {
            string[] str = Console.ReadLine().Split(' ');
            var x = double.Parse(str[0]);
            var u = str[1];
            if (u == "JPY")
            {
                total += x;
            }
            else
            {
                total += x * 380000;
            }

        }
        Console.WriteLine(total);


        Console.Out.Flush();
    }
}

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

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    ll c1=0;
    for(int i=0;i<n;i++)
    {
        if(i==n-1)
        {
            c1+= a[i]/2;
        }
        else
        {
            c1+=a[i];
        }
    }
    cout<<c1;
    return 0;
}

Measured memory_bytes: 256
import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools

mod = int(1e9+7)
INF = 1<<29

def main():
    n = int(input())
    x = list(map(int,input().split()))
    ans = [INF] * 105
    for i in range(105):
        p = 0
        for j in range(n):
            p += (x[j]-(i+1))**2
        ans[i] = min(ans[i],p)
    print(min(ans))
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 39152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    int n;cin>>n;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    //check
    bool flag=false;
    rep(i,n)if(v[i]==1)flag=true;
    if(flag==false){
        cout<<"-1"<<endl;
        return 0;
    }
    //sort
    //sort(v.begin(),v.end());
    ll cnt=0;
    int idx=1;
    rep(i,n){
        if(v[i]==idx){
            idx++;
        }
        else{
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 1024
fn calc_msd(x: usize) -> usize {
    let mut msd = x;
    while msd >= 10 {
        msd /= 10;
    }
    msd
}

fn calc_comb(n: usize) -> Vec<Vec<u64>> {
    let mut comb = vec![vec![0u64; 10]; 10];
    for x in 1..(n+1) {
        let msd = calc_msd(x);
        let lsd = x%10;
        comb[msd][lsd] += 1;
    }
    comb
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();

    let comb = calc_comb(n);

    let mut ans = 0u64;
    for i in 1..10 {
        for j in 1..10 {
            ans += comb[i][j] * comb[j][i];
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
S = input()
ans = 0
for b in range(2**(len(S)-1)):
    opes = []
    for k in range(len(S)-1):
        if b&(1<<k):
            opes.append('+')
        else:
            opes.append('')
    formula = ''.join([a+o for a,o in zip(S,opes)]) + S[-1]
    ans += eval(formula)

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define ll long long
const long long INF = 1LL << 60;

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

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

ll gcd(ll m, ll n){
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd



int main() {
	int x[4];
	int y[4];
	cin >> x[0] >> y[0] >> x[1] >> y[1];
	x[2] = y[0] - y[1] + x[1];
	y[2] = x[1] - x[0] + y[1];
	x[3] = y[1] - y[2] + x[2];
	y[3] = x[2] - x[1] + y[2];
	cout << x[2] << ' ' << y[2] << ' ' << x[3] << ' ' << y[3];

	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;

#define MOD 1000000007
#define INF INT_MAX
#define ll long long

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

	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0) {
			printf("%c", s[i]);
		}
	}
	printf("\n");

	return (0);
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
using namespace std;
typedef unsigned long long ull;
typedef pair<ll, ll>P;
const ll mod = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool fl = true;;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
struct edge { ll to, cost; };

int main() {
	ll n, a[100010], ans = 0;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	for (int i = 1;i < n - 1;i++) {
		if (a[i - 1] % 2 == 1 && a[i] != 0) {
			ans++;
			a[i-1]--;
			a[i]--;
		}
		if (a[i + 1] % 2 == 1 && a[i] != 0) {
			ans++;
			a[i + 1]--;
			a[i]--;
		}
	}
	for (int i = 0;i < n;i++) {
		ans += a[i] / 2;
	}
	cout << ans << endl;
	}

Measured memory_bytes: 1024
// Aizu 1141: Dirichlet's Theorem on Arithmetic Progre...
// 2017.9.13 bal4u@uu

#include <stdio.h>

#define MAX  1000000
#define SQRT 1000     // sqrt(MAX)
char prime[MAX + 5], *p, *q, *pmax = prime + MAX;

void mkprime()
{
	int k;
	prime[1] = 1; for (p = prime + 4; p <= pmax; p += 2) *p = 1;
	for (k = 3, p = prime + 3; k <= SQRT; k += 2, p += 2)
		if (!*p) for (q = p + k; q <= pmax; q += k) *q = 1;
}

int main()
{
	int a, d, n;

	mkprime();
	while (scanf("%d%d%d", &a, &d, &n) && a) { a -= d;
		while (n > 0) {
			a += d;
			if (!prime[a]) n--;
		}
		printf("%d\n", a);
	}
	return 0;
}

Measured memory_bytes: 2696
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int inf = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    int n;
    string s;
    cin >> n >> s;
    int c = 1;
    for (int i = 0; i  <n; i++) {
        if (i == 0) continue;
        if (s[i] != s[i-1]) c++;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 #define ll long long
 #define int long long
 #define MOD  1000000007
 #define MAX 500005
 #include<iomanip>
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define x first
 #define y second
using namespace std;

 int32_t main()
{
    Need_for_speed(activated);
//    satisfy
//    {
//
//    }
    ll a,b;cin>>a>>b;
    if(a>b)
    {
        fore(i,0,a)
        cout<<b;
    }
    else
    fore(i,0,b)
    {cout<<a;}

    return 0;
}
















Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    ll x[n],y[n],z[n];
    ll nx[n],ny[n],nz[n];
    rep(i,n){
        cin >> x[i] >> y[i] >> z[i];
    }
    ll ans = 0;
    rep(i,(1<<3)){
        if (i&1) rep(i,n) nx[i] = -x[i];
        else rep(i,n) nx[i] = x[i];
        if (i&2) rep(i,n) ny[i] = -y[i];
        else rep(i,n) ny[i] = y[i];
        if (i&4) rep(i,n) nz[i] = -z[i];
        else rep(i,n) nz[i] = z[i];
        vector<P> a;
        rep(i,n){
            a.push_back(P(nx[i]+ny[i]+nz[i],i));
        }
        RSORT(a);
        ll b = 0,d = 0,p = 0,index;
        rep(i,m){
            index = a[i].second;
            b += x[index];
            d += y[index];
            p += z[index];
        }
        chmax(ans,abs(b)+abs(d)+abs(p));
    }
    PRINT(ans);
}


Measured memory_bytes: 384
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
 
ll rui(ll abc,ll bed){
	//aのb乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
} 
ll i,j,k,ii,jj;
ll n,m,sum,num;
ll ans;
ll a,b,c,d,e,h,w;
 
ll x[500005],v[500005];
ll rv[500005],lv[500005];
ll rx[500005],lx[500005];
ll rmax[500005],lmax[500005];

int main(){
    cin>>n>>c;
	for(i=0;i<n;i++){
		cin>>x[i]>>v[i];
	}
	ll vsum=0;
	for(i=0;i<n;i++){
		rv[i] = vsum + v[i];
		rx[i] = x[i];
		vsum = rv[i];
		//pe(rv[i]);p(rx[i]);
	}
	vsum=0;
	for(i=0;i<n;i++){
		lv[i] = vsum + v[n-1-i];
		lx[i] = c - x[n-1-i];
		vsum = lv[i];
		//pe(lv[i]);p(lx[i]);
	}
	ans = 0;
	for(i=0;i<n;i++){
		ans = max(ans,rv[i]-rx[i]);
	}
	for(i=0;i<n;i++){
		ans = max(ans,lv[i]-lx[i]);
	}
	for(i=0;i<n;i++){
		if(i==0) rmax[i] = rv[i]-rx[i];
		if(i>=1) rmax[i] = max(rmax[i-1],rv[i]-rx[i]);
	}
	for(i=0;i<n;i++){
		if(i==0) lmax[i] = lv[i]-lx[i];
		if(i>=1) lmax[i] = max(lmax[i-1],lv[i]-lx[i]);
	}
	for(i=0;i<n;i++){
		ans = max(ans,rv[i] - 2*rx[i] + lmax[n-2-i]);
		ans = max(ans,lv[i] - 2*lx[i] + rmax[n-2-i]);
	}
	//p(rv[0]-2*rx[0]+lmax[n-1]);
	p(ans);

	
	return 0;
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

int main(void)
{
    const int N_MAX = 100;
    int N;
    int A[2][N_MAX];
    cin >> N;
    REP(i, 2) REP(j, N) cin >> A[i][j];
    int dp[2][N_MAX];
    dp[1][N - 1] = A[1][N - 1];
    dp[0][N - 1] = A[0][N - 1] + A[1][N - 1];
    //printf("dp[%d][%d] = %d\n", 1, N - 1, dp[1][N - 1]);
    //printf("dp[%d][%d] = %d\n", 0, N - 1, dp[0][N - 1]);
    RREP(j, N - 1) {
        dp[1][j] = A[1][j] + dp[1][j + 1];
        dp[0][j] = A[0][j] + max(dp[1][j], dp[0][j + 1]);
        //printf("dp[%d][%d] = %d\n", 1, j, dp[1][j]);
        //printf("dp[%d][%d] = %d\n", 0, j, dp[0][j]);
    }
    cout << dp[0][0] << endl;
    return 0;
}


Measured memory_bytes: 256
w,h,n=map(int,input().split())

x1,x2,y1,y2=0,w,0,h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
      x1=max(x1,x)
  elif a==2:
      x2=min(x2,x)
  elif a==3:
      y1=max(y1,y)
  else:
      y2=min(y2,y)
        
s=(x2-x1)*(y2-y1)
if x2-x1<0 or y2-y1<0:
  print(0)
else:
  print(s)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    string a,b,c;
    cin>>a>>b>>c;
    if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]){
        cout<<"YES";
    }else{
        cout<<"NO";
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	char b;
	scanf("%c",&b);
	switch(b) {
		case 'A':
			printf("T\n");
			break;
		case 'T':
			printf("A\n");
			break;
		case 'C':
			printf("G\n");
			break;
		case 'G':
			printf("C\n");
			break;
		

	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;
int main(void){

	int s1,s2,s3,s4,a;
	int t1,t2,t3,t4,b;

	cin >>s1;
	cin >>s2;
	cin >>s3;
	cin >>s4;
	a=s1+s2+s3+s4;
	cin >>t1;
	cin >>t2;
	cin >>t3;
	cin >>t4;
    b=t1+t2+t3+t4;
    if(a>b)cout << a << endl;
    else cout << b << endl;


	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<stdexcept>
using namespace std;
typedef long long ll;
int main() {
	string s;
	cin >> s;
	int sum = 0;
	int ans = 1e5;
	for (int i = 0; i < s.size() - 2; i++) {
		sum = ((s[i]-'0') * 100 + (s[i + 1]-'0') * 10 + (s[i+2]-'0'));
		ans = min(ans, abs(753 - sum));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
k = int(input())

count = 0
for _ in range(1, 100):
    if (a < b):
        break
    count+=1
    b *= 2
for _ in range(1, 100):
    if (b < c):
        break
    count+=1
    c *= 2

if (count <= k):
    print('Yes')
else:
    print('No')

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

int main()
{
  int n, m;
  cin >> n >> m;
  
  vector<int> p(n);
  rep(i, n) {cin >> p[i]; p[i]--;}
  
  vector<vector<int>> graph(n, vector<int>(0));
  rep(i, m)
  {
    int x, y;
    cin >> x >> y;
    x--; y--;
    graph[x].emplace_back(y);
    graph[y].emplace_back(x);
  }
  rep(i, n)
  {
    sort(graph[i].begin(), graph[i].end());
    graph[i].erase(unique(graph[i].begin(), graph[i].end()), graph[i].end());
    //for(int x : graph[i]) cout << x << " "; cout << endl;
  }
  
  vector<bool> visited(n, false);
  stack<int> stc;
  int res = 0;
  rep(i, n)
  {
    if(visited[i]) continue;
    stc.push(i);
    
    vector<int> key(0);
    set<int> val;
    
    while(stc.size())
    {
      int x = stc.top();
      stc.pop();
      visited[x] = true;
      key.emplace_back(x);
      val.insert(p[x]);
      
      for(int y : graph[x])
      {
        if(!visited[y])
          stc.push(y);
      }
    }
    sort(key.begin(), key.end());
    key.erase(unique(key.begin(), key.end()), key.end());
    
    for(int x : key)
    {
      if(val.find(x) != val.end()) res++;
    }
  }
  
  cout << res << endl;
  
  return 0;
}
  
  
  

Measured memory_bytes: 11128