akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

public class AtCoder_157_B
{
    public static void Main()
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        int[] line0 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int[] line1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int[] line2 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        int[,] bingoVal = new int[3, 3];
        for (int i = 0; i < 3; i++)
        {
            bingoVal[0, i] = line0[i];
        }
        for (int i = 0; i < 3; i++)
        {
            bingoVal[1, i] = line1[i];
        }
        for (int i = 0; i < 3; i++)
        {
            bingoVal[2, i] = line2[i];
        }

        bool[,] bingo = new bool[3, 3];
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                bingo[i, j] = false;
            }
        }

        int n = int.Parse(Console.ReadLine());
        for (int k = 0; k < n; k++)
        {
            int b = int.Parse(Console.ReadLine());
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (bingoVal[i, j] == b)
                    {
                        bingo[i, j] = true;
                    }
                }
            }
        }

        // 横
        var ans = false;
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (bingo[i, j] == false) break;
                if (j == 2) ans = true;
            }
            if (ans == true) break;
        }

        if (ans == false)
        {
            // 縦
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (bingo[j, i] == false) break;
                    if (j == 2) ans = true;
                }
                if (ans == true) break;
            }
        }

        if (ans == false)
        {
            // 斜め
            if (bingo[0, 0] && bingo[1, 1] && bingo[2, 2] ||
                bingo[0, 2] && bingo[1, 1] && bingo[2, 0])
            {
                ans = true;
            }
        }

        if (ans)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}


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

void inp_str(int*);

int main(void) {

int input1[150];
inp_str(input1);

int X,A;

X=input1[0];
A=input1[1];


//printf("N=%d\n",N);
//printf("X=%d\n",X);
//printf("%d\n",temp);




if(X<A){
	printf("0\n");
} else {
	printf("10\n");

}


    return 0;

}


void inp_str(int instr[]){
char *ptr;
int z,i,count;
char str[20000]={'\0'};
char *ln;

fgets(str, 20000, stdin); // 入力："123456\n"
ln = strchr(str, '\n'); /* 改行文字を検索 */
if (ln != NULL) { /* 改行が読み取られていたかどうか */
   *ln = '\0';    /* 改行文字を終端文字に置き換える */
}
else {            /* 入力ストリーム上に文字が残ってる場合 */
   while (1) {    /* 改行文字が読み取られるまで空読みする */
       z = getchar();
      if (z == '\n' || z == EOF) break;
   }
}
	count=0;
    ptr = strtok(str, " ");
    i = atoi(ptr);
    instr[count]=i;
    count=count+1;
    // 2回目以降
    while(ptr != NULL) {
        // strtok関数により変更されたNULLのポインタが先頭
        ptr = strtok(NULL, " ");
        // ptrがNULLの場合エラーが発生するので対処
        if(ptr != NULL) {
		    i = atoi(ptr);
    instr[count]=i;
    		count=count+1;
        }
    }
}



Measured memory_bytes: 128
import fractions

def func(A,B,C,D):
#	print "A,B,C,D::",A,B,C,D

	if A<B:
		print "No"
	elif B>D:
		print "No"
	elif B<=C:
		print "Yes"

	else:
		A%=B
		g=fractions.gcd(B,D)
		if g==B:
			if A>C:
				print "No"
			else:
				print "Yes"
		elif B-g>C:
			print "No"
		else:
			print "Yes"
T=input()

for i in range(T):
	a,b,c,d=map(int, raw_input().split())
	func(a,b,c,d)



Measured memory_bytes: 34920
n = int(input())

if n <= 599:
    print("8")
elif n <=799:
    print("7")
elif n <=999:
    print("6")
elif n <=1199:
    print("5")
elif n <=1399:
    print("4")
elif n <=1599:
    print("3")
elif n <=1799:
    print("2")
elif n <=1999:
    print("1")

Measured memory_bytes: 9180
#include <stdio.h>

int main(int argc, char *argv[]){
     int a, b, f1, f2=0, i;
     
     while(scanf("%d %d",&a,&b), a+b!=0){
	  /* üsðoÍ */
	  if(f2) puts(""); else f2=1;

	  f1=0; /* NAÅÈ¢tO */
	  
	  for(i=a; i<=b; i++)
	       if(i%4==0 && (i%100!=0 || i%400==0))
		    printf("%d\n",i), f1=1;
	  
	  if(!f1) puts("NA");
     }

     return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a;
  vector<long long> grx,gry,grz;
  long long x1[50],y1[50],z1[50],x2[50],y2[50],z2[50];
  int used[100][100][100] = {};
  cin >> n >> a;
  for(int i=0;i<n;i++){
    cin >> x1[i] >> y1[i] >> z1[i] >> x2[i] >> y2[i] >> z2[i];
    grx.push_back(x1[i]);
    grx.push_back(x2[i]);
    gry.push_back(y1[i]);
    gry.push_back(y2[i]);
    grz.push_back(z1[i]);
    grz.push_back(z2[i]);
  }
  sort(grx.begin(),grx.end());
  grx.erase(unique(grx.begin(),grx.end()),grx.end());
  sort(gry.begin(),gry.end());
  gry.erase(unique(gry.begin(),gry.end()),gry.end());
  sort(grz.begin(),grz.end());
  grz.erase(unique(grz.begin(),grz.end()),grz.end());

  long long sum = 0;

  for(int i=0;i<grx.size()-1;i++)
    for(int j=0;j<gry.size()-1;j++) 
      for(int k=0;k<grz.size()-1;k++){
	
	for(int l=0;l<n;l++){
	  if(grx[i] >= x1[l] && grx[i+1] <= x2[l] && gry[j] >= y1[l] && gry[j+1] <= y2[l] && grz[k] >= z1[l] && grz[k+1] <= z2[l]){
	    used[i][j][k]++;
	    if(used[i][j][k] == a) sum += (grx[i+1]-grx[i]) * (gry[j+1]-gry[j]) * (grz[k+1]-grz[k]); 
	  }
	}
	
      }

  cout << sum << endl;
  return (0);
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  ll X; cin >> X;
  REP(A, -1000, 1000) REP(B, -1000, 1000) {
    if ((ll)A*A*A*A*A - (ll)B*B*B*B*B == X) {
      return !printf("%d %d\n", A, B);
    }
  }
  assert(1);
}


Measured memory_bytes: 3720
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m=sc.nextInt();
        int[] positions=new int[sc.nextInt()];
        if(m>positions.length)m=positions.length;
        for(int i=0;i<positions.length;i++){
            positions[i]=sc.nextInt();
        }
        Arrays.sort(positions);
        int[] b=new int[positions.length-1];
        for(int i=0;i<b.length;i++){
            b[i]=positions[i+1]-positions[i];
        }
        Arrays.sort(b);
        int tmp=positions[positions.length-1]-positions[0];
        for(int i=0;i<m-1;i++){
            tmp-=b[b.length-1-i];
        }
        System.out.println(tmp);
                
        
        
        
        

}

}

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

const int STACKMAX = 50;
typedef int elementtype;

typedef struct {
	elementtype elem[STACKMAX];
	int position;
} stack;

void initstack(stack *s) {
	s->position = 0;
}

void push (stack *s, elementtype x) {
	if (s->position >= STACKMAX) {
		cout << "stack overflow" << endl;
		exit(0);
	} else {
		s->elem[s->position] = x;
		s->position++;
	}
}

elementtype pop (stack *s) {
	elementtype element;

	if (s->position < 0) {
		cout << "stack underflow" << endl;
		exit(0);
	} else {
		s->position--;
		return s->elem[s->position];
	}

}

void print (stack *s) {
	for (int i = 0; i < s->position; i++) cout << s->elem[i];
	cout << "\n";
}

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

	int n, r, p, c, i = 1;
	stack *cards1 = (stack *)malloc(sizeof(stack)), *cards2 = (stack *)malloc(sizeof(stack));

	while (cin >> n >> r, n | r) {
		int a[n];
		i = 1;
		for (int k = n - 1; k >= 0; k--) a[k] = i++;
		for (int i = 0; i < r; i++) {
			cin >> p >> c;

			initstack(cards1);
			initstack(cards2);

			for (int j = 0; j < p + c - 1; j++) {
				if(j < p - 1) {
					push(cards1, a[j]);
				} else {
					push(cards2, a[j]);
				}
			}

		//	print(cards1);
		//	print(cards2);

			for (int l = p + c - 2; l >= 0; l--) {
				if (cards1->position != 0) {
					a[l] = pop(cards1);
				} else {
					a[l] = pop(cards2);
				}
			}
		}

		cout << a[0] << "\n";
	}

	free(cards1);
	free(cards2);

	return 0;
}

Measured memory_bytes: 1196
#include<cstdio>
#include<cstring>
int main(void){
  int a[10010];
  int ans, n;
  memset(a, -1, sizeof(a));
  a[0] = a[1] = 0;
  for(int i = 2;i * i <= 10000; i++){
    if(a[i] == -1){
      a[i] = 1;
      for(int j = 2;i * j <= 10000; j++)
	a[i * j] = 0;
    }
  }

  while(scanf("%d", &n) != EOF){
    ans = 0;
    int i, j;
    for(i = 1, j = n;i < j; i++, j--){
      if(a[i] && a[j]) ans++;
    }
    ans = ans * 2;
    if(i == j && a[i] && a[j]) ans++;
    printf("%d\n", ans);
  }
}


Measured memory_bytes: 1068
s=input()
x=[i%2 for i in range(len(s))]
y=[~i%2 for i in range(len(s))]
#print(x,y)
c=0
e=0
for i in range(len(s)):
    #print(s[i],x[i],y[i])
    if int(s[i])!=x[i]:
        c+=1
    if int(s[i])!=y[i]:
        e+=1
print(min(c,e))

Measured memory_bytes: 4852
#include <bits/stdc++.h>
#define ll long long int
#define INF 1e13
using namespace std;
void BFS2(ll source, vector<vector<ll> > &adjList, ll V, vector<ll> &parent)
{
    queue<ll> BFSqueue;
    vector<bool> visited(V,false);
    BFSqueue.push(source);
    visited[source] = true;
    while(!BFSqueue.empty())
    {
        ll node = BFSqueue.front();
        BFSqueue.pop();
        for(auto &neighbour: adjList[node])
        {
            parent[neighbour] = node;
            if(neighbour == source)
            {
                return;
            }
            if(!visited[neighbour])
            {
                BFSqueue.push(neighbour);
                visited[neighbour] = true;
            }
        }
    }
    return;
}
pair<ll,ll> BFS(ll source, vector<vector<ll> > &adjList, ll V)
{
    ll len = 0;
    queue<ll> BFSqueue;
    vector<ll> mindistance(V,0);
    vector<bool> visited(V,false);
    // vector<ll> parent(V,-1);
    BFSqueue.push(source);
    visited[source] = true;
    while(!BFSqueue.empty())
    {
        ll node = BFSqueue.front();
        BFSqueue.pop();
        for(auto &neighbour: adjList[node])
        {
            len++;
            if(neighbour == source)
            {
                return {mindistance[node] + 1,source};
            }
            else if(!visited[neighbour])
            {
                BFSqueue.push(neighbour);
                visited[neighbour] = true;
                mindistance[neighbour] = mindistance[node] + 1;
                // parent[neighbour] = node;
            }
            else if(visited[neighbour])
                return {INF,-1};
        }
    }
    return {INF,-1};
}
int main()
{
    ll tt = 1;
    // cin >> tt;
    while(tt--)
    {
        ll V, E;
        cin >> V >> E;
        vector<vector<ll> >adjList(V);
        for(ll i = 0; i < E; i++)
        {
            ll u, v;
            cin >> u >> v;
            u--;
            v--;
            adjList[u].push_back(v);
        }
        vector<bool> vismain(V,false);
        vector<pair<ll,ll> > cyclelen(V);
        for(ll i = 0; i < V; i++)
        {
            pair<ll,ll> p = BFS(i,adjList,V);
            cyclelen[i].first = p.first;
            cyclelen[i].second = p.second;
        }
        sort(cyclelen.begin(),cyclelen.end());
        if(cyclelen[0].first == INF)
        {
            cout << -1 << '\n';
            continue;
        }
        // else
        vector<ll> parent(V,0);
        ll mindissrc = cyclelen[0].second;
        BFS2(mindissrc,adjList,V,parent);
        vector<ll> ans;
        ll node = mindissrc;
        while(parent[node] != mindissrc)
        {
            ans.push_back(node);
            node = parent[node];
        }
        ans.push_back(node);
        ll anssize = ans.size();
        cout << anssize << '\n';
        for(ll i = anssize-1; i >= 0; i--)
            cout << ans[i]+1 << " ";
        cout << '\n';
    } return 0;
}


Measured memory_bytes: 384
// 問題の URL を書いておく
// https://atcoder.jp/contests/abc156/tasks/abc156_c

#include <algorithm>
#include <bitset>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#include <cmath>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

int main(int, const char**)
{
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i, n)
    {
        cin >> x[i];
    }

    int cost = numeric_limits<int>::max();
    rep(i, 100)
    {
        int c = 0;
        rep(j, n)
        {
            c += pow((1 + i) - x[j], 2);
        }
        cost = min(cost, c);
    }
    cout << cost << endl;

    return 0;
}


Measured memory_bytes: 3596
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
constexpr int mod = 1e9 + 7;

template <int mod>
struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if ((x += p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &p) {
        if ((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }

    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

using modint = ModInt<mod>;

int main() {
    int n;
    cin >> n;
    vector<modint> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    reverse(a.begin(), a.end());
    modint product, sum = 0, ans = 0;
    for (int i = 1; i < n; i++) {
        sum += a[i - 1];
        product = a[i];
        ans += sum * product;
    }
    cout << ans << endl;
    return 0;
}


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

#define llint long long

void openFile() {
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef Tr___
    freopen("test.inp", "r", stdin);
    freopen("test.out", "w", stdout);
    #endif
}

const int maxN = 50 + 5;
const int maxM = 1e6 + 5;
const llint INF = 1e9 + 7;
const int dx[] = {0, 0, -1, -1, -1, 1, 1, 1};
const int dy[] = {-1, 1, 0, -1, 1, -1, 0, 1};

int N, M;
char c[maxN][maxN];

void enter() {
    cin >> N >> M;
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= M; ++j) {
            cin >> c[i][j];
        } 
    }
}

inline bool avail(int x, int y) {
    return (x > 0 and y > 0 and x <= N and y <= M);
}

void solve() {
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= M; ++j) {
            if (c[i][j] == '#') {
                putchar('#');
            }
            else {
                int cnt = 0;
                for (int k = 0; k < 8; ++k) {
                    int x = i + dx[k];
                    int y = j + dy[k];
                    if (!avail(x, y)) continue;
                    if (c[x][y] == '#') ++cnt;
                }
                putchar(cnt + 48);
            }
        }
        putchar('\n');
    }
}

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

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

var t string
var alphabet string = "abcdefghijklmnopqrstuvwxyz"

func main() {

	fmt.Scan(&t)
	m := make(map[string]int, len(t))

	for i := 0; i < len(string(alphabet)); i++ {
		m[string(alphabet[i])]++
	}

	for i := 0; i < len(t); i++ {
		delete(m, string(t[i]))
	}

	for i := 0; i < len(alphabet); i++ {
		if m[string(alphabet[i])] != 0 {
			fmt.Println(string(alphabet[i]))
			return
		}
	}
	fmt.Println("None")
}

/*  ----------------------------------------  */

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy []XY

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	if a[i].x == a[j].x {
		return a[i].y > a[j].y
	}
	return a[i].x > a[j].x
}


Measured memory_bytes: 3456
#include<iostream>

using namespace std;

int main(){
	
	int Md[12] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30}; 
	int month;
	int day;
		
	while( cin >> month >> day ) {
	
	if( month == 0 && day == 0)
	break;
	
	if( month == 1 && day == 1) {
		
	cout << "Thursday\n";
	continue;
	
	}
	if( month == 1 && day == 2) {
		
	cout << "Friday\n";
	continue;
	
	}
	if( month == 1 && day == 3) {
		
	cout << "Saturday\n";
	continue;
	
	}
	if( month == 1 && day == 4) {
		
	cout << "Sunday\n";
	continue;
	
	}
	for(int i=0;i<month;i++)
	day += Md[i];
	
	switch( (day - 4) % 7) {
		
		case 1:
		cout << "Monday\n";
		break;
		
		case 2:
		cout << "Tuesday\n";
		break;
		
		case 3:
		cout << "Wednesday\n";
		break;
		
		case 4:
		cout << "Thursday\n";
		break;
		
		case 5:
		cout << "Friday\n";
		break;
		
		case 6:
		cout << "Saturday\n";
		break;
		
		default:
		cout << "Sunday\n";
		break;
		
	}
	
	//cout << day; 
}
    return 0;
}


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
using std::swap;

// priceをキーに降順でソート
//sort(fruits.begin(), fruits.end(),
//     [](const fruit& x, const fruit& y) { return x.price > y.price;});

/*
int main() {
    int N, A, B;
    std:cin >> N >> A >> B;
    std::cout << min(N*A, B) << std::endl;
    return 0;
}
 */

/*
int main(){
    int N, D;
    std::cin >> N >> D;
    int X[N][D];
    float dist;
    int ans=0;
    for(int i=0; i<N; i++){
        for(int j=0; j<D; j++){
            std:cin >> X[i][j];
        }
    }
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N && i!=j; j++){
            int sum = 0;
            for(int k=0; k<D; k++){
                sum += pow(X[i][k]-X[j][k],2.0);
            }
            dist = sqrt(sum);
            if(dist==(int)dist){
                ans++;
            }
        }
    }
    std::cout << ans << std::endl;
    return 0;
}
*/

int main(){
    long long int L, R;
    std::cin >> L >> R;
    int min=2018;
    int tmp;
    if(R-L > 2018){
        std::cout << 0 << std::endl;
        return 0;
    }
    L %= 2019;
    R %= 2019;
    if(L>R){
        std::cout << 0 << std::endl;
    }
    else{
        for(int i=0; i<R-L; i++){
            for(int j=i+1; j<R-L+1; j++){
                tmp=((L+i)*(L+j))%2019;
                if(tmp<min){
                    min = tmp;
                }
            }
        }
        std::cout << min << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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(){
    ll n,k=0; cin>>n;
    vector<vector<ll>> edge(n+1);
    vector<ll> color(n+1,-1),depth(n+1,0),A(n-1),B(n-1);
    rep(i,n-1){
        ll a,b; cin>>a>>b;
        edge[a].push_back(b); edge[b].push_back(a);
        A[i]=a; B[i]=b;
    }
    queue<ll> que;
    que.push(1);
    color[1]=0;
    depth[1]=1;
    while(!que.empty()){
        ll q=que.front();
        que.pop();
        ll i=1;
        for(ll x:edge[q]){
            //edge[q].erase(remove(edge[q].begin(),edge[q].end(),x),edge[q].end());
            edge[x].erase(remove(edge[x].begin(),edge[x].end(),q),edge[x].end());
            if(color[q]==i)i++;
            color[x]=i; chmax(k,i); i++;
            depth[x]=depth[q]+1;
            que.push(x);
        }
    }
    cout<<k<<endl;
    rep(i,n-1){
        if(depth[A[i]]>depth[B[i]]) cout<<color[A[i]]<<endl;
        else cout<<color[B[i]]<<endl;
    }
    return 0;
}

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

#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ll long long
#define pb push_back
#define zoom                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pl pair<ll, ll>
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#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
#define trace(v)                                   \
    for (auto it = v.begin(); it != v.end(); it++) \
        cerr << *it << " ";                        \
    cerr << endl;
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;

void solve()
{
    int n;
    cin>>n;

    vi v(n);
    map<ll,ll> m;
    ll sum=0;
    forn(i,n){
        cin>>v[i];
        m[v[i]]++;
        sum+=v[i];
    }

    int q;
    cin>>q;

    forn(i,q){
        ll prev,curr;
        cin>>prev>>curr;
        if(m.count(prev)==0){
            cout<<sum<<endl;
        }else{
            ll temp=m[prev];
            sum-=(temp)*prev;
            sum+=(temp)*curr;
            m.erase(prev);
            m[curr]+=temp;

            cout<<sum<<endl;
        }
    }


}

int main()
{
    zoom;
    ll t=1;
    //cin >> t;

    while (t--)
    {
        solve();
    }
}

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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
inline int sq(int n){
  return n * n;
}

int dp[20001][256];
int main(){
  int N, M;
  while(cin>>N>>M && N){
    vector<int> code(M);
    REP(i,M)cin>>code[i];
    vector<int> X(N);
    REP(i,N)cin>>X[i];
    REP(i,20001)fill(dp[i], dp[i] + 256, INF);
    dp[0][128] = 0;
    REP(i,N)REP(j,256)if(dp[i][j]!=INF){
      int t = dp[i][j];
      REP(k, M){
        int Y = j + code[k];
        if(Y > 255) Y = 255;
        if(Y < 0) Y = 0;
        dp[i+1][Y] = min(dp[i+1][Y], t + sq(X[i] - Y));
      }
    }
    int ans = INF;
    REP(j, 256) ans = min(ans, dp[N][j]);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 20000
#include <iostream>
#include <vector>
#include <string>

using namespace std;

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    
    int r_cnt = 0;
    for(int i = 0; i < n; ++i){
        if(s[i] == 'R') ++r_cnt;
    }

    int ng_r = 0;
    int ng_w = 0;
    for(int i = 0; i < n; ++i){
        if(i < r_cnt && s[i] == 'W') ++ng_w;
        if(i >= r_cnt && s[i] == 'R') ++ng_r;
    }

    cout << min(ng_w, ng_r) + abs(ng_w - ng_r) << endl;
}

Measured memory_bytes: 3796
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
double ans,dp[51][3000];
int X,Y,Z;

int dice[4],t[51],u[51],N;
void init();
double dfs(int,int);

int main(){
  while(cin>>X>>Y>>Z&&X){
    init();
    for(int i=0;i<X;i++)cin>>dice[i];
    for(int i=0;i<Z;i++){
      cin>>N;
      cin>>t[N]>>u[N];
    }
    cout<<(int)dfs(0,0)<<endl;
  }
  return 0;
}

void init(){
  for(int i=0;i<51;i++){
    for(int j=0;j<3000;j++)dp[i][j]=-1.0;
    t[i]=u[i]=0;
  }
}

double dfs(int pos,int cnt){
  if(pos>=Y)return (double)cnt;
  if(dp[pos][cnt]!=-1.0)return dp[pos][cnt];
  double res=0;
  for(int i=0;i<X;i++){
    int npos=pos+dice[i];
    if(t[npos]==1)res+= dfs(npos+u[npos],cnt);
    else if(t[npos]==2)res+= dfs(npos,cnt+u[npos]);
    else res+= dfs(npos, max(0,cnt-u[npos]));
  }
  return dp[pos][cnt]=res/(double)X;
}

Measured memory_bytes: 2356
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashSet;
fn main() {
    input! {
        x: i32,
        n: i32,
        p: [i32; n],
    }
    let p: HashSet<_> = p.into_iter().collect();
    for i in 0..102 {
        for j in &[x - i, x + i] {
            if !p.contains(j) {
                println!("{}", j);
                return;
            }
        }
    }
}

Measured memory_bytes: 2188
#include <stdio.h>
int main(void) {
	// your code goes here
	int a,b;
	char c;
	while(1){
		scanf("%d %c %d",&a,&c,&b);
		if(c=='?'){
			break;
		}if(c=='+'){
			printf("%d\n",a+b);
		}if(c=='-'){
			printf("%d\n",a-b);
		}if(c=='*'){
			printf("%d\n",a*b);
		}if(c=='/'){
			printf("%d\n",a/b);
		}
	}
	return 0;

}


Measured memory_bytes: 2120
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll H, N;
    cin >> H >> N;
    VLL A(N), B(N);
    ll dai=0;
    rep(i,N){
        cin >> A[i] >> B[i];
        dai=max(dai,A[i]);
    }
    VLL memo(100000, INF);
    memo[0]=0;
    rep(i,N){
        rep(j,H){
            if(memo[j]!=INF){
                ll n=j+A[i];
                chmin(memo[n],memo[j]+B[i]);
            }
        }
    }
    ll ans=INF;
    rept(i,H,H+dai+1){
        ans=min(ans,memo[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3968
a,b,k=map(int,input().split())
x=[]
y=[]
for i in range(1,a+1):
    if a%i==0:
        x.append(i)
for i in range(1,b+1):
    if b%i==0:
        if i in x:
            y.append(i)
print(y[-k])


Measured memory_bytes: 2940
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define lli long long int
#define llu unsigned long long int
#define fr(va, beg, end) for (lli va = beg; va < end; va++)
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
#define sz(x) (lli)(x.size())
const lli MOD = 1e9 + 7;
// cout << fixed << setprecision(0) << pi <<endl;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// for multiset
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

void solve() {
    lli n, a;
    string st;
    cin >> st;
    for (lli i = 0; i < st.length(); i++) {
        if (st[i] == '?') {
            st[i] = 'D';
        }
    }
    cout << st << endl;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // lli t; cin >> t; while(t--)
    solve();
    rt;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
using namespace std;
using LL = long long;
const int INF = 1e9;

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

    int X;
    X = (int)(N / 1.08);
    if ((int)(X*1.08) == N) {
        cout << X << endl;
    } else if ((int)((X+1)*1.08) == N) {
        cout << X+1 << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}



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

int main(){
  int n;
  cin>>n;
  vector<pair<int,int>>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i].second>>a[i].first;
  }
  sort(a.begin(),a.end());
  long long wa=0;
  bool check=false;
  for(int i=0;i<n;i++){
    wa+=a[i].second;
    if(wa<=a[i].first){
      check=true;
    }else{
      check=false;
      break;
    }
  }
  if(check)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 4756
#include <stdio.h>
int main(void){
    int i,k,W,H;
    for(;;){
        scanf("%d %d",&H,&W);
        if(H==0 && W==0)break;
        for(i=0;i<H;i++){
            for(k=0;k<W;k++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

struct edge{
  int to;
  int cost;
  int time;
};

struct state{
  ll time;
  int to;
  int cost;
  bool operator < (const state &s) const{
    return time>s.time;
  }
};

bool comp(const state& s1,const state& s2){
  return s1.time<s2.time;
}

int main(){
  int n,m,s;
  cin>>n>>m>>s;
  s=min(s,50*n);
  vector<edge> path[n];
  rep(i,0,m){
    int u,v,a,b;
    cin>>u>>v>>a>>b;
    path[u-1].push_back(edge{v-1,a,b});
    path[v-1].push_back(edge{u-1,a,b});
  }
  int c[n],d[n];
  rep(i,0,n) cin>>c[i]>>d[i];
  priority_queue<state> q;
  q.push(state{0,0,s});
  ll dp[n][50*n+1];
  rep(i,0,n){
    rep(j,0,50*n+1){
      dp[i][j]=1e15;
    }
  }
  dp[0][s]=0;
  while(q.size()){
    state f=q.top();
    q.pop();
    if(dp[f.to][f.cost]<f.time) continue;
    if(dp[f.to][min(f.cost+c[f.to],50*n)]>f.time+d[f.to]){
      dp[f.to][min(f.cost+c[f.to],50*n)]=f.time+d[f.to];
      q.push(state{f.time+d[f.to],f.to,min(f.cost+c[f.to],50*n)});
    }
    for(edge e:path[f.to]){
      if(f.cost<e.cost) continue;
      if(dp[e.to][f.cost-e.cost]>f.time+e.time){
        dp[e.to][f.cost-e.cost]=f.time+e.time;
        q.push(state{dp[e.to][f.cost-e.cost],e.to,f.cost-e.cost});
      }
    }
  }
  rep(i,1,n){
    ll ans=1e15;
    rep(j,0,50*n+1) {
      ans=min(ans,dp[i][j]);
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 6152
#include "bits/stdc++.h"
using namespace std;

using int64 = long long;

#define int long long

signed main() {
	int n;
	while (true) {
		cin >> n;
		if (n == 0) break;
		vector<int> h(n + 1);
		for (int i = 0; i < n + 1; ++i) cin >> h[i];
		for (int i = 0; i < n + 1; ++i) {
			vector<int> t;
			for (int j = 0; j < n + 1; ++j) {
				if (i == j) continue;
				t.emplace_back(h[j]);
			}
			int d = t[1] - t[0];
			bool f = true;
			for (int j = 0; j + 1 < n; ++j) {
				if (t[j + 1] - t[j] != d) {
					f = false;
					break;
				}
			}
			if (f) {
				cout << h[i] << endl;
				break;
			}
		}
	}
}


Measured memory_bytes: 3168
package main

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

func main() {
	var n, m, l int
	fmt.Scan(&n, &m, &l)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	// Warshall–Floyd Algorithm
	const inf = int(1e9 + 10)
	dist := make([][]int, n)
	for i := range dist {
		dist[i] = make([]int, n)
		for j := range dist[i] {
			dist[i][j] = inf
		}
		dist[i][i] = 0
	}

	for i := 0; i < m; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		b, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		c, _ := strconv.Atoi(sc.Text())
		a--
		b--
		dist[a][b], dist[b][a] = c, c
	}
	for k := 0; k < n; k++ {
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
			}
		}
	}

	dist2 := make([][]int, n)
	for i := 0; i < n; i++ {
		dist2[i] = make([]int, n)
		for j := 0; j < n; j++ {
			dist2[i][j] = inf
			if dist[i][j] <= l {
				dist2[i][j] = 1
			}
		}
	}
	for k := 0; k < n; k++ {
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				dist2[i][j] = min(dist2[i][j], dist2[i][k]+dist2[k][j])
			}
		}
	}

	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())
	qs := make([][]int, q)
	for i := range qs {
		sc.Scan()
		s, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		t, _ := strconv.Atoi(sc.Text())
		s--
		t--
		qs[i] = []int{s, t}
	}

	for _, v := range qs {
		s, t := v[0], v[1]
		ans := dist2[s][t]
		if ans == inf {
			fmt.Println(-1)
		} else {
			fmt.Println(ans - 1)
		}
	}
}

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

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 7920
#include <iostream>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll a, b;
    cin >> a >> b;
    if(a <= 9 && b <= 9){
        cout << a * b << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 888
/* 
 * Author: aps
 * Time: 2019-07-20 15:46:02
**/
#include<bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const ll inf = 1e18;
const ll mod = 1e9+7;
 
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x;}
inline ll sub(ll x, ll y) { x -= y; if (x < 0) x += mod; return x;}
inline ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod;}
inline ll power(ll a, ll b) {
    ll x = 1;
    while (b) {
        if (b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline ll inv(ll a) { return power(a, mod - 2);}
 
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    int a[n],tot_xor=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        tot_xor ^= a[i];
    }
    int ok = 1;
    for(int i=0;i<n;i++){
        if(a[i] == (tot_xor ^ a[i]));
        else ok = 0;
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 640
n, c, k = map(int, input().split())
t = sorted([int(input()) for _i in range(n)])+[float('inf')]

b = 0
time = t[0]
count = 0
for i in range(n+1):
    if t[i] > time+k or count == c:
        b += 1
        time = t[i]
        count = 0
    count += 1
print(b)

Measured memory_bytes: 8276
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1e9;
const double PI = acos(-1.0);

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int r, c;
	int matrix[101][101] = {};
	cin >> r >> c;
	REP(i, r) {
		REP(j, c) {
			cin >> matrix[i][j];
		}
	}
	
	REP(i, r + 1) {
		REP(j, c + 1) {
			cout << matrix[i][j];
			if(j != c) {
				cout << " ";
				if(i != r) matrix[i][c] += matrix[i][j];
			} else {
				cout << "\n";
			}
			matrix[r][j] += matrix[i][j];
		}
	}
	
	return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}

    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

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

    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(M), Y(M), Z(M);
    rep(i, M) cin >> X[i] >> Y[i] >> Z[i], --X[i], --Y[i];

    UnionFind uf(N);
    rep(i, M) uf.merge(X[i], Y[i]);

    set<int> s;
    rep(i, N) s.insert(uf.root(i));
    cout << s.size() << endl;
}

Measured memory_bytes: 6400
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
ak = 0
ak_2 = 0

for i in range(N):
  ak += A[i]
  ak_2 += A[i] ** 2
s = int(((ak ** 2) - ak_2) // 2)
print(s % mod)

Measured memory_bytes: 31540
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>
#include <map>
#include <limits>

using namespace std;

int main(int argc, const char * argv[]) {
  long long n, k;
  cin >> n >> k;

  int mIndex = 1;
  int a;
  for(int i = 1; i <= n; i++){
    cin >> a;
    if(a == 1){
      mIndex = i;
    }
  }
  if(n == 1){
    cout << 0 << endl;
  }
  if(n <= k){
    cout << 1 << endl;
    return 0;
  }
//  cout << mIndex << "," << n-mIndex-1 << endl;
//  cout << ceil(mIndex/(k-1.0)) << "," << ceil((n-mIndex-1)/(k-1.0)) << endl;
  //cout << mIndex-1 << "," << n-mIndex << endl;
  //cout << ceil((mIndex-1)/(k-1.0)) + ceil(max((n-mIndex),(n%mIndex))/(k-1.0)) << endl;
  cout << ceil((n-1)/(k-1.0)) << endl;
  return 0;
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long n; cin >> n;
    if (n == 0) cout << 0 << endl;
    else if (n & 1) cout << 0 << endl;
    else {
        long long x = 0;
        for (long long d = 10; d <= n; d *= 5) {
            x += n / d;
        }
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
void main() {
    auto N = ri;
    auto A = readAs!(int[]);

    (3 ^^ N - 2 ^^ A.count!(v => v % 2 == 0)).writeln;
}

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

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

long rl() {
	return readAs!long;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n)     for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n)    for (int i = 1; i <= (int)(n); ++i)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rrep(i, n)    for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n)   for (int i = (int)(n); i >= 1; --i)
#define allrep(V, v)  for (auto &&V : v)
#define all(x)        (x).begin(), (x).end()
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = 1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  int n;
  cin >> n;
  vector<int> d(n);
  rep (i, n) cin >> d[i];
  sort(all(d));
  int r = n / 2, l = r - 1;
  cout << d[r] - d[l] << endl;
  return 0;
}

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

int main(){
    int n,q,a[20],m[200],box[21][2001] = {1};
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    cin >> q;
    for(int i = 0; i < q; i++) cin >> m[i];

    for(int i = 0; i < n; i++){
        for(int j = 0; j <= 2000; j++){
            if(box[i][j] && j + a[i] <= 2000){
                box[i + 1][j + a[i]] = 1;
            }
            if(box[i][j]) box[i + 1][j] = 1;
        }
    }

    for(int i = 0; i < q; i++){
        if(box[n][m[i]])
            cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

Measured memory_bytes: 3252
#include<cstdio>
#include<algorithm>
int n,k;
long long ans=1000000000,f[100005];
long long solve(int l,int r)
{
	if (f[l]>=0&&f[r]>=0) return f[r];
	else if (f[l]<=0&&f[r]<=0) return -f[l];
	else return f[r]-f[l]+std::min(f[r],-f[l]);
}
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%lld",&f[i]);
	for (int l=1;l<=n;l++)
	{
		int r=l+k-1;
		if (r>n) break;
		ans=std::min(ans,solve(l,r));
	}
	printf("%lld\n",ans);
	return 0;
}

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


int main() {
    int s, w;
    cin >> s >> w;
    if(s>w){
        cout << "safe" << endl;
    }else{
        cout << "unsafe" << endl;
    }
}

Measured memory_bytes: 3624