akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()


int D;
int c[26];
int s[365][26];

int ans[365];


void greedy() {
	int last[26] = {};
	rep(i, 26)last[i] = -1;

	rep(i, D) {
		int ma = -INF;
		int con = -1;

		int pena[26];
		rep(j, 26) {
			pena[j] = c[j] * (i - last[j]);
		}

		rep(j,26) {
			//int score = s[i][j] + pena[j];
			int score = s[i][j] + 5 * pena[j];
			if (ma < score) {
				ma = score;
				con = j;
			}
		}
		assert(con != -1);

		last[con] = i;
		ans[i] = con;
	}
}


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


#if defined(_MSC_VER)
	D = 365;
	mt19937 mt;
	rep(i, 26)c[i] = mt() % 100;
	rep(i, 365)rep(j, 26) s[i][j] = mt() % 20000;
#else
	cin >> D;
	rep(i, 26)cin >> c[i];
	rep(i, 365)rep(j, 26)cin >> s[i][j];
#endif // #if defined(_MSC_VER)


	greedy();


	int last[26] = {};
	rep(i, 26)last[i] = -1;
	int score = 0;
	rep(i, D) {
		cout << ans[i] + 1 << endl;

		score += s[i][ans[i]];
		last[ans[i]] = i;
		rep(j, 26) {
			score -= c[j] * (i - last[j]);
		}
	}
	cerr << score << endl;


	return 0;
}


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

int main(){
    long double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed << setprecision(8) << sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2)) << endl;
    return 0;
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n, k; cin >> n >> k;
    double ans = 0;
    rep(i, n) {
        int score = i+1;
        double tmp = 1.0/n;
        while (score < k) {
            score *= 2;
            tmp *= 1.0/2;
        }
        ans += tmp;
    }
    printf("%.10f\n", ans);
}

Measured memory_bytes: 256
program main;
var
	n, sum : integer;
    i, j, k : integer;
    
function gcd(x, y : integer) : integer;
begin
	while true do
    begin
   		x := x mod y;
        if x = 0 then break;
        y := y mod x;
        if y = 0 then break;
    end;
    gcd := x + y;
end;
    
begin
	sum := 0;
	readln(n);
    for i := 1 to n do
    	for j := 1 to n do
        	for k := 1 to n do
            	sum := sum + gcd(gcd(i, j), k);
    writeln(sum);
end.

Measured memory_bytes: 1376
i, j = map(int, input().split())
list_a = []
list_b = []

for n in range(i):
    list_a.append(list(map(int, input().split())))
for n in range(j):
    list_b.append(int(input()))
for n in range(i):
    result = 0
    for m in range(j):
        result += list_a[n][m] * list_b[m]
    print(result)



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

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    int ans = n;
    sort(s.begin(),s.end());
    for(int i=0; i<n-1; ++i){
        for(int j=i+1; j<n; ++j){
            int x = i;
            if(s[x]==s[j]){
                --ans;
                i=j-1;
            }else{
                i=j-1;
                break;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <climits>
#include <utility>
#include <map>
#include <set>
#include <complex>
#include <numeric>

#include <time.h>
#include <float.h>

#define loop(i, start, end) for(i = (start); i <= (end); i++)
#define loopIterators(it, vec) for(it = (vec).begin(); it != (vec).end(); it++)
#define loopIteratorsRev(it, vec) for(it = (vec).rbegin(); it != (vec).rend(); it++)
#define loopRev(i, start, end) for(i = (start); i >= (end); i--)
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCases(t) cin >> t; while(t--)
#define PN(n) cout << (n)
#define PN1(n) cout << (n) << " "
#define PN2(a, b) cout << (a) << " " << (b) << " "
#define PNN1(n) cout << (n) << endl
#define PNN2(a, b) cout << (a) << " " << (b) << endl
#define PNN3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define PrintArray(ar, n) for(i = 0; i < n; i++) cout << ar[i] << " "; cout << endl
#define PrintObject(ar, it) loopIterators(it, ar) cout << *it << " "; cout << endl
#define PrintMap(map, it) loopIterators(it, map) PNN2(it->first, it->second)
#define sz(a) sizeof(a)
#define IN1(n) cin >> n
#define IN2(a, b) cin >> a >> b
#define IN3(a, b, c) cin >> a >> b >> c
#define ALL(s) s.begin(), s.end()
#define SWAP(a, b, c) c = a; a = b; b = c
#define STRSP(s) scanf("%[^\n]%*c", s)
#define ENTER PNN1("")
#define MOD7 1000000007
#define MOD9 10000009
#define llPair std::pair<lli, lli>
#define iiPair std::pair<int, int>
#define ONLINE_JUDGE

typedef long long int lli;
typedef long int li;
typedef unsigned long long int ulli;
typedef long double ld;

using namespace std;

int main(void){
	FLASH

	#ifndef ONLINE_JUDGE
		freopen("input-stream.txt", "r", stdin);
		freopen("output-stream.txt", "w", stdout);
	#endif

	std::string s;
	IN1(s);

	PNN1(s.at(2) == s.at(3) && s.at(4) == s.at(5)? "Yes": "No");

	// int n;
	// IN1(n);
	//
	// lli ans = 1LL * n / 500 * 1000;
	// n %= 500;
	// ans += 1LL * n / 5 * 5;
	// PNN1(ans);


	#ifndef ONLINE_JUDGE
		fclose(stdin);
		fclose(stdout);
	#endif

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int judge(int);
int main(){
  int number, i, n[10000], count = 0;

  scanf("%d",&number);
  for(i = 0; i < number; i++){
    scanf("%d",&n[i]);
    count += judge(n[i]);
  }

  printf("%d\n",count);

  return 0;
}

int judge(int n){
  int i;
  if(n < 2) return 0;
  else if(n == 2) return 1;
  else if(n%2 == 0) return 0;
  else{
    for(i = 3; i*i <= n; i +=2 ){
      if(n%i == 0) return 0;
    }
  }
  return 1;
}


Measured memory_bytes: 2036
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
  long N,a,m;
  vector<long> A;
  cin >> N;
  for(int i=0;i<5;i++){
  	cin >> a;
  	A.push_back(a);
  }
  m = *min_element(A.begin(), A.end());

  long M = (N + m - 1)/m;

  cout << M+4 <<endl;

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int a[7]={1,3,5,7,8,10,12};
int b[4]={4,6,9,11};
int c[1]={2};
int main(){
    int x,y,f,t;
    while(scanf("%d %d",&x,&y)==2){
        f=0;t=0;
        for(int i=0;i<7;i++){
            if(x==a[i])
                f=1;
        }
        for(int i=0;i<4;i++){
            if(x==b[i])
                t=1;
        }
        if(f==1){
            for(int i=0;i<7;i++){
                if(y==a[i])
                    f=2;
            }
        }
        if(t==1){
            for(int i=0;i<4;i++){
                if(y==b[i])
                    t=2;
            }
        }
        if(f==2||t==2)
            printf("Yes\n");
        else
            printf("No\n");
    }
return 0;
}


Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	r := intScanner()
	if r < 1200 {
		fmt.Println("ABC")
	} else if r < 2800 {
		fmt.Println("ARC")
	} else {
		fmt.Println("AGC")
	}
}


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

const int N = 1e6 + 5;
const int mod = 1e9 + 7;

int dp[N], pref[N];

inline void modadd(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}

int main() {
  int n;
  scanf("%d", &n);
  pref[1] = dp[1] = n;
  dp[2] = 1LL * n * n % mod;
  pref[2] = pref[1];
  modadd(pref[2], dp[2]);
  for (int i = 3; i <= n; i ++) {
    dp[i] = dp[i - 1];
    if (i > 2) modadd(dp[i], 1LL * (n - 1) * (n - 1) % mod);
    if (i >= 3) modadd(dp[i], pref[i - 3]);
    modadd(dp[i], n - i + 2);
    pref[i] = pref[i - 1];
    modadd(pref[i], dp[i]);
  }
  printf("%d\n", dp[n]);
  return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i;
	cin>>n;
	string s[n];
	int max=0;
	int c=1;
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
	}
	sort(s,s+n);
	for(i=0;i<n-1;i++)
	{
		if(s[i]==s[i+1])
		c++;
		else
		{
			if(max<c)
			max=c;
			c=1;
		}
	}
	if(max<c)
	max=c;
	if(max==1)
	{
		for(i=0;i<n;i++)
		cout<<s[i]<<endl;
	}
	c=1;
	for(i=0;i<n-1;i++)
	{
	if(s[i]==s[i+1])
	  {
	c++;
	if(c==max)
	cout<<s[i]<<endl;	
      }
    else
    c=1;
	}
	
}

Measured memory_bytes: 14208
from collections import defaultdict

n = int(input())
vs = list(map(int, input().split()))

def count(vs):
    d1 = defaultdict(int)
    d2 = defaultdict(int)
    for i, v in enumerate(vs):
        if i % 2 == 0:
            d1[v] += 1
        else:
            d2[v] += 1
    return d1, d2

d1, d2 = count(vs)
d1 = sorted([(v, k) for k, v in d1.items()], reverse=True)
d2 = sorted([(v, k) for k, v in d2.items()], reverse=True)
n1, v1 = d1[0]
n2, v2 = d2[0]
if v1 == v2:
    n1_2 = 0 if len(d1) == 1 else d1[1][0]
    n2_2 = 0 if len(d2) == 1 else d2[1][0]
    total = max(n1 + n2_2, n2 + n1_2)
else:
    total = n1 + n2

print(n - total)

Measured memory_bytes: 18072
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    
    int a1,a2,a3;
  scanf("%d%d%d",&a1,&a2,&a3);
  int a[3]={a1,a2,a3};
  sort(a,a+3);
    int ans=a[2]-a[1]+a[1]-a[0];
  
  printf("%d",ans);
    
}

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

int main() {
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    vector<int> l(n), r(n);
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'o'){
            l[cnt] = i;
            cnt++;
            i += c;
        }
        if(cnt == k) break;
    }
    for(int i = n - 1; i >= 0; i--){
        if(s[i] == 'o'){
            r[cnt-1] = i;
            cnt--;
            i -= c;
        }
        if(cnt == 0) break;
    }
    for(int i = 0; i < k; i++){
        if(l[i] == r[i]){
            cout << l[i] + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3332
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
using Graph = vector<vector<ll> >;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;



// auto mod ll
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const ll mod = 1000000007;
//const ll 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;}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//入力
ll n,k;
vector<mint>a;

int main(){
    cin >> n >> k;
    a.resize(n);
    rep(i,n)cin>>a[i].x;
    vector<mint>t(n,0);
    rep(i,n){
        for(ll j=i+1;j<n;j++){
            if(a[i].x>a[j].x)t[i]+=1;
        }
    }
    vector<mint>s(n,0);
    rep(i,n){
        rep(j,n){
            if(a[i].x>a[j].x)s[i]+=1;
        }
    }
    mint ans = 0;
    rep(i,n){
        ans += t[i]*k+s[i]*k*(k-1)/2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3664
/*
created by Sanyam Singhal
/*/

#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long int
#define mod 1000000007
#define w(t) int t;	cin>>t while(t--)
#define triplet pair<int,pair<int,int>>
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define fastIO ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);
#define loop(i, k, n) for(ll i=k; i<n; i+=1)
#define loop2(i, k, n) for(ll i=k; i>=n; i--)

const ll inf = 1e18;

void take_fileIO(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
  return;
}

int main(){

  fastIO;
  // take_fileIO();
  
  int n,m;
  cin>>n>>m;

  vector<vector<char>>matrix(n+1, vector<char>(m+1));
  for(int i=1; i<=n; i++){
    for(int j=1; j<=m; j++){
      cin>>matrix[i][j];
    }
  }
  
  vector<vector<ll>>dp(n+1, vector<ll>(m+1));
  dp[1][1]=1;

  for(int i=2; i<=n; i++){
    if(matrix[i][1]=='.' && dp[i-1][1]==1)
      dp[i][1]=1;
    else
      dp[i][1]=0;
  }
  for(int j=2; j<=m; j++){
    if(matrix[1][j]=='.' && dp[1][j-1]==1)
      dp[1][j]=1;
    else
      dp[1][j]=0;
  }

  for(int i=2; i<=n; i++){
    for(int j=2; j<=m; j++){
      if(matrix[i][j]=='#')
        dp[i][j]=0;
      else
        dp[i][j] = (dp[i-1][j]%mod + dp[i][j-1]%mod)%mod;
    }
  }

  // for(int i=1; i<=n; i++){
  //   for(int j=1; j<=m; j++){
  //     cout<<dp[i][j]<<" ";
  //   }
  //   cout<<endl;
  // }

  cout<<dp[n][m]<<endl;

  return 0;
}

Measured memory_bytes: 9216
n, k = list(map(int, input().split()))
ab = []
for i in range(n):
    x, y = map(int, input().split())
    ab.append((x, y))

ab_sorted = sorted(ab, key=lambda x: x[0])

total = 0
for i in range(n):
    if total + ab_sorted[i][1] >= k:
        print(ab_sorted[i][0])
        exit()
    else:
        total += ab_sorted[i][1]


Measured memory_bytes: 18960
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<ii,int> iii;



char pet[803][803];
bool visited[803][803];
int mox[] = {0, 0, -1, 1}, moy[] = {-1, 1, 0, 0};

int main()
{
//        freopen("input.in", "r", stdin);
    int n, m, k;
    cin >> n >> m >> k;
    
    for(int i = 0; i <= n+1; i++)
        for(int j = 0; j <= m+1; j++)
            pet[i][j] = '#';
    
    ii s;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            cin >> pet[i][j];
            if(pet[i][j] == 'S')
                s = {i,j};
        }
    }
    
    queue<iii> q;
    q.push({s, k});
    visited[s.fi][s.se] = 1;
    while(q.size())
    {
        iii curr = q.front(); q.pop();
        int rem = curr.se;
        int x = curr.fi.fi;
        int y = curr.fi.se;
        if(rem == 0) continue;
        for(int i = 0; i < 4; i++)
        {
            int _x = x+mox[i];
            int _y = y+moy[i];
            if(visited[_x][_y] || pet[_x][_y] == '#')
                continue;
            
            visited[_x][_y] = 1;
            q.push({{_x, _y}, rem-1});
        }
    }
    
    int mn = 1e9;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(visited[i][j])
            {
                int jar = min({i-1,j-1,n-i,m-j});
                jar = (jar+k-1)/k;
                mn = min(jar+1, mn);
            }
        }
    }
    cout << mn << "\n";
    
//    for(int i = 1; i <= n; i++)
//    {
//        for(int j = 1; j <= m; j++)
//            cout << visited[i][j];
//        cout << "\n";
//    }
    
}


Measured memory_bytes: 1536
k,t=map(int,input().split())
a=list(map(int,input().split()))
p=max(a)
q=sum(a)
import math
if p<=math.ceil(q/2):
	print(0)
else:
	if k%2==0:
		t=-1
	else:
		t=0
	print(2*(p-math.ceil(q/2))+t)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	cin>>n;
	ll p[n+1],mini[n+1];
	for(ll i=1;i<=n;i++)
	cin>>p[i];
	mini[1]=p[1];
	for(ll i=2;i<=n;i++)
	mini[i]=min(mini[i-1],p[i]);
	ll cnt=0;
	for(ll i=1;i<=n;i++)
	if(mini[i]==p[i])
	cnt++;
	cout<<cnt;
	
}

Measured memory_bytes: 6760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
  int N = 0 ;
  cin >> N ;
  string S ,T ;
  cin >> S >> T ;
  int j = 0 ;
  rep(i,N){
    int k = i ; 
      while( S.at(k) == T.at(j) ){
        j++;
        if( k == N-1 ){
          cout << 2*N - j << endl;
          return 0 ;
        }
        k++;
      }
    j = 0 ;
  }
  cout << 2*N - j << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
A_dict = dict()
for i in range(N):
    if A_dict.get(A[i]) is None:
        A_dict[A[i]] = 1
    else:
        A_dict[A[i]] += 1
A_dict_len = len(A_dict.keys())
ans = 0
A_dict_sorted = sorted(A_dict.items(), key=lambda a: a[1])
#print(A_dict_sorted)
for i in range(max(0, A_dict_len - K)):
    ans += A_dict_sorted[i][1]
print(ans)


Measured memory_bytes: 42696
h, w = map(int, input().split())
mat = []
for i in range(h):
  mat.append(list(map(int, input().split())))
sousa = []
for y in range(h):
  if y % 2 == 0:
    x = -1
    for x in range(w-1):
      if mat[y][x] % 2 == 1:
        mat[y][x] -= 1
        mat[y][x+1] += 1
        sousa.append((y+1, x+1, y+1, x+1+1))
    x += 1
    if mat[y][x] % 2 == 1 and y < h-1:
        mat[y][x] -= 1
        mat[y+1][x] += 1
        sousa.append((y+1, x+1, y+1+1, x+1))
  if y % 2 == 1:
    x = w
    for x in range(w-1, 0, -1):
      if mat[y][x] % 2 == 1:
        mat[y][x] -= 1
        mat[y][x-1] += 1
        sousa.append((y+1, x+1, y+1, x+1-1))
    x -= 1
    if mat[y][x] % 2 == 1 and y < h-1:
        mat[y][x] -= 1
        mat[y+1][x] += 1
        sousa.append((y+1, x+1, y+1+1, x+1))

print(len(sousa))
for y,x,y1,x1 in sousa:
  print(y,x,y1,x1)


Measured memory_bytes: 26656
import numpy as np
import math

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

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

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

# 1 <= N <= 10^5
# 2 <= M <= 10^9
# 1 <= A <= 10^9

S = []
total = 0
S.append(0)
for i in range(N):
    total = (total + A[i]) % M
    S.append(total)

oS = sorted(S)

count = 0

# print(oS)

cur_val = 0
number = 0
for i in range(0, N+1):
    if oS[i] == cur_val:
        number += 1
    if oS[i] > cur_val or i == N:
        if number >= 2:
            count += int(number * (number - 1) / 2)
        # print(cur_val, number)
        number = 1
        cur_val = oS[i]

print(count)


Measured memory_bytes: 23100
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
class Seg_Tree{
    private:
    int e=1000000007;
    int n;
    vector<int> node;
    public:
    int process(int left,int right){
        if(left==e)return right;
        if(right==e)return left;
        return max(left,right);
    }
    Seg_Tree(vector<int> v){
        int num=1;
        int size=v.size();
        while(num<size){
            num*=2;
        }
        n=num;
        node.resize(2*num-1,e);
        for(int i=0;i<size;i++)node[i+num-1]=v[i];
        for(int i=n-2;i>=0;i--)node[i]=process(node[i*2+1],node[i*2+2]);
    }
    void update(int x,int val){
        x+=(n-1);
        node[x]=val;
        while(x>0){
            x=(x-1)/2;
            node[x]=process(node[x*2+1],node[x*2+2]);
        }
    }
    int out(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        if(a>=r||b<=l)return e;
        if(a<=l&&b>=r)return node[k];
        int vl=out(a,b,k*2+1,l,(l+r)/2);
        int vr=out(a,b,k*2+2,(l+r)/2,r);
        return process(vl,vr);
    }
};
signed main(){
  int n;cin>>n;
  Seg_Tree tree(vector<int>(n+1,0));
  vector<int> h(n);
  vector<int> a(n);
  rep(i,n)cin>>h[i];
  rep(i,n)cin>>a[i];
  rep(i,n){
      tree.update(h[i],tree.out(0,h[i]+1)+a[i]);
  }
  cout<<tree.out(0,n+1)<<endl;
  return 0;
}

Measured memory_bytes: 7528
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
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; }
typedef long long ll;
#define pint pair<int,int>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k; cin >> n >> k;
    if(n*500>=k) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)

void candidate(vector<string> &rec, ll N, string s){
    if(stoll(s)<= N)
        rec.push_back(s);
    else
        return;
    string tmp = s;
    tmp.push_back('3');
    candidate(rec, N, tmp);
    tmp = s; tmp.push_back('5');
    candidate(rec, N, tmp);
    tmp = s; tmp.push_back('7');
    candidate(rec, N, tmp);
    
}

bool checkGood(string s){
    bool has3=false, has5=false, has7=false;
    rep(i, s.length()){
        if(s[i]=='3')
            has3 = true;
        if(s[i]=='5')
            has5 = true;
        if(s[i]=='7')
            has7 = true;
    }
    if(has3 && has5 && has7)
        return true;
    else
    {
        return false;
    }
    
}

void solve(long long N){
    vector<string> rec;
    rec.push_back("3");
    rec.push_back("5");
    rec.push_back("7");
    candidate(rec, N, "3");
    candidate(rec, N, "5");
    candidate(rec, N, "7");
    ll cnt = 0;
    rep(i, rec.size()){
        if(checkGood(rec[i]))
            cnt++;
    }
    cout << cnt << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 2172
def main():
    N = int(input())

    X_L = tuple(tuple(int(j) for j in input().split()) for i in range(N))
    ranges = tuple((x - l, x + l) for x, l in X_L)
    sorted_X_L = sorted(X_L, key=lambda x: x[0])

    # sorted_ranges = sorted(ranges, key=lambda x: x[0])

    x_max = - 1e9
    x_min = 2e9

    allowed = []

    for i in range(N):
        i_min = sorted_X_L[i][0] - sorted_X_L[i][1]  # min
        i_max = sorted_X_L[i][0] + sorted_X_L[i][1]  # max

        if i_min >= x_max:
            allowed.append(sorted_X_L[i])
            x_max = max(x_max, i_max)
            x_min = min(x_min, i_min)
        elif i_max <= x_max:
            allowed[-1] = sorted_X_L[i]
            x_max = i_max

    print(len(allowed))


if __name__ == '__main__':
    main()


Measured memory_bytes: 34096
s = input()
for i in range(1000):
    s = s[:-2]
    tnp = 0
    for j in range(len(s)//2):
        if (s[j]!=s[len(s)//2+j]):
            tnp += 1
    if (tnp==0):
        print(len(s))
        break

Measured memory_bytes: 9052
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 1000000007;

#define M 1000000007


std::vector<ll> fac(100001); //n!(mod M)
std::vector<ll> ifac(100001); //k!^{M-2} (mod M)

//x^n(mod M)d
ll
mpow(ll x, ll n)
{
    ll ans = 1;
    while (n > 0){
        if (n & 1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

void
cominit()
{
    fac[0] = 1;
    ifac[0] = 1;
    for (ll i = 0; i < 100001; i++){
        fac[i+1] = fac[i] * (i+1) % M; // n! mod M
        ifac[i+1] = ifac[i] * mpow(i+1, M-2) % M; // k!^{M-2} mod M
    }
}


ll
comb(ll a, ll b)  // aCb mod M
{
    if (a == 0 && b == 0) return 1;
    if (a < b || a < 0) return 0;
    ll tmp = ifac[a-b] * ifac[b] % M;
    return tmp * fac[a] % M;
}

int main() {
    cominit();
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    ll res = 0;
    for (ll i = 1; i <= n; ++i) {
        if (n - i >= k - 1) {
            //cerr << "- " << a[i-1] << "*" << comb(n-i, k-1) << "=" << (a[i-1] * comb(n-i, k-1)) << endl;
            res -= (a[i-1] * comb(n-i, k-1)) % M;
            res %= M;
        }
    }
    for (ll i = n; i >= 1; --i) {
        if (i - 1 >= k - 1) {
            //cerr << "+ " << a[i-1] << "*" << comb(i-1, k-1) << "=" << (a[i-1] * comb(i-1, k-1)) << endl;
            res += (a[i-1] * comb(i-1, k-1)) % M;
            res %= M;
        }
    }
    res = (res+M)%M;
    cout << res << endl;
}


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

namespace ConsoleApp15
{
    class Class327
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var ab = new int[N][];
            for(int i = 0; i < N; i++)
            {
                ab[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            }
            Array.Sort(ab, (x, y) => -x[1].CompareTo(y[1]));

            int count = 0;
            var frags = Enumerable.Repeat(true, N).ToArray();
            var cd = new int[N][];
            for (int i = 0; i < N; i++)
                cd[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(cd, (x, y) => x[0].CompareTo(y[0]));
            for(int i = 0; i < N; i++)
            {
                
                for(int j = 0; j < N; j++)
                {
                    if (frags[j] && cd[i][0] >= ab[j][0] && cd[i][1] >= ab[j][1])
                    {
                        count++;
                        frags[j] = false;
                        break;
                    }
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13524
import sys
input = sys.stdin.readline

mod = 998244353
n, q = map(int, input().split())


class LazySegTree:
    def __init__(self, N):
        self.INF = 2**31-1
        self.N = N
        self.LV = (self.N - 1).bit_length()
        self.N0 = 2 ** self.LV
        self.data = [0] * (2 * self.N0)
        self.lazy = [0] * (2 * self.N0)
        self.size = [0] * (2 * self.N0)
        val = 1
        for i in range(self.N):
            self.size[self.N0 + self.N - 2 - i] = val
            val = val * 10 % mod
        for i in range(self.N0 - 2, -1, -1):
            self.size[i] = (self.size[2 * i + 1] + self.size[2 * i + 2]) % mod

    def gindex(self, l, r):
        L = (l + self.N0) >> 1; R = (r + self.N0) >> 1
        lc = 0 if l & 1 else (L & -L).bit_length()
        rc = 0 if r & 1 else (R & -R).bit_length()
        for i in range(self.LV):
            if rc <= i:
                yield R
            if L < R and lc <= i:
                yield L
            L >>= 1; R >>= 1

    # 遅延伝搬処理
    def propagates(self, *ids):
        for i in reversed(ids):
            v = self.lazy[i-1]
            if not v:
                continue
            self.lazy[2*i-1] = v; self.lazy[2*i] = v
            self.data[2*i-1] = v * self.size[2*i-1] % mod
            self.data[2*i] = v * self.size[2*i] % mod
            self.lazy[i-1] = 0

    # 区間[l, r)にxを加算
    def update(self, l, r, x):
        *ids, = self.gindex(l, r)
        self.propagates(*ids)

        L = self.N0 + l; R = self.N0 + r
        while L < R:
            if R & 1:
                R -= 1
                self.lazy[R-1] = x; self.data[R-1] = x * self.size[R-1] % mod
            if L & 1:
                self.lazy[L-1] = x; self.data[L-1] = x * self.size[L-1] % mod
                L += 1
            L >>= 1; R >>= 1
        for i in ids:
            self.data[i-1] = (self.data[2*i-1] + self.data[2*i]) % mod

    # 区間[l, r)内の最小値を求める
    def query(self, l, r):
        self.propagates(*self.gindex(l, r))
        L = self.N0 + l; R = self.N0 + r

        s = 0
        while L < R:
            if R & 1:
                R -= 1
                s = (s + self.data[R-1]) % mod
            if L & 1:
                s = (s + self.data[L-1]) % mod
                L += 1
            L >>= 1; R >>= 1
        return s


lst = LazySegTree(n)
lst.update(0, n, 1)

for _ in range(q):
    l, r, d = map(int, input().split())
    l -= 1
    lst.update(l, r, d)
    print(lst.query(0, n))


Measured memory_bytes: 123792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
  pair<int, int> tmp;
  vector< pair<int, int> > team;
  while(scanf("%d,%d", &tmp.second, &tmp.first)){
    if(tmp.first == 0 && tmp.second == 0) break; 
    team.push_back(tmp);
  }
  sort(team.rbegin(), team.rend());
  
  int cnt = 1;
  map<int, int> ans;
  
  ans.insert(make_pair(team[0].second, cnt));
  
  for(int i = 1 ; i < team.size() ; i++){
    if(team[i-1].first > team[i].first) ++cnt;
    ans.insert(make_pair(team[i].second, cnt));
  }
  
  int n;
  while(cin >> n){
    cout << ans[n] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    vll a(n);
    ll neg = 0;
    REP(i, n){
        cin >> a[i];
        if(a[i] < 0) neg++;
    }
    if(neg == 0) neg = 1;
    if(neg == n) neg = n - 1;
    VSORT(a);
    vll x(n - 1), y(n - 1);
    REP(i, n - neg - 1){
        x[i] = a[0], y[i] = a[neg + i];
        a[0] -= a[neg + i];
    }
    REP(i, neg){
        x[i + n - neg - 1] = a[n - 1], y[i + n - neg - 1] = a[i];
        a[n - 1] -= a[i];
    }
    cout << a[n - 1] << endl;
    REP(i, n - 1) cout << x[i] << " " << y[i] << endl;
    return 0;
}

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

int main()
{
    int n, x;
    int oneThird;
    int i, j, k, left, left_half;
    int cnt;
    while((cin >> n >> x) && n+x)
    {
        cnt = 0;
        oneThird = x/3;
        for (i = 1; i <= oneThird && i < n; i++)
        {
            left = x - i;
            left_half = left/2;            
            for (j = i+1; j <= left_half && j < n; j++)
            {
                k = left -j;
                if (k <= n && k > j)
                    cnt++;
            }
        }
        cout << cnt << endl;        
    }
    return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int k,t;
	cin >> k >> t;
	vector<int> a(t);
	rep(i,t)cin>>a[i];
	sort(ALL(a),greater<int>());
	if(a[0]<=k/2)
	{
		cout<<0<<endl;
		return 0;
	}
	a[0]-=k-a[0]+1;
	cout<<a[0]<<endl;
	return 0;
}

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

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

vector<string> v;
vector<string> list_ans;
ll dir_j[8] = {0,1,1,1,0,-1,-1,-1};
ll dir_i[8] = {1,1,0,-1,-1,-1,0,1};

void push(ll i, ll j){
  ll h = v.size();
  ll w = v[0].size();
  FOR(p,0,8){
    ll tmp_i = i;
    ll tmp_j = j;
    string s;
    s.push_back(v[tmp_i][tmp_j]);
    tmp_i += dir_i[p];
    tmp_j += dir_j[p];
    tmp_i += h;
    tmp_j += w;
    tmp_i %= h;
    tmp_j %= w;
    while(!(tmp_i == i && tmp_j == j)){
//      cout<<"t_i = "<<tmp_i<<" t_j = "<<tmp_j<<endl;
      s.push_back(v[tmp_i][tmp_j]);
      tmp_i += dir_i[p];
      tmp_j += dir_j[p];
      tmp_i += h;
      tmp_j += w;
      tmp_i %= h;
      tmp_j %= w;
    }
    list_ans.push_back(s);
  }
}

string ch_res(string a, string b){
  if(a.size()<b.size()){
    return b;
  }
  return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w;
    cin>>h>>w;
    while(h!=0){
      v = vector<string>(0,"");
      list_ans = vector<string>(0,"");
      FOR(i,0,h){
        string s;
        cin>>s;
        v.push_back(s);
      }

      FOR(i,0,h){
        FOR(j,0,w){
//          cout<<"i = "<<i<<" j = "<<j<<endl;
          push(i,j);
        }
      }

      sortAl(list_ans);
      string res;
      FOR(i,1,list_ans.size()){
        string a = list_ans[i-1];
        string b = list_ans[i];
        string tmp_a;
        string tmp_b;
        FOR(j,0,a.size()){
          tmp_a.push_back(a[j]);
          tmp_b.push_back(b[j]);
          if(tmp_a == tmp_b) res = ch_res(res, tmp_a);
        }
      }

      if(res.size() == 1) cout<<0<<endl;
      else cout<<res<<endl;

      cin>>h>>w;
    }
}



Measured memory_bytes: 3296
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    string s;
    cin >> n >> s >> k;
    for(int i=0;i<n;i++)
    {
        if(s[i]!=s[k-1]) cout << '*';
        else cout << s[i];
    }
}


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

using namespace std;

int moc(int a, int n)
{
  	int res = 1;
  
 	for(int i = 0; i < n; ++i)
      res *= a;
  
    return res;
}

int main()
{
	int a;
  	cin >> a;
  	cout << a + moc(a, 2) + moc(a, 3) << '\n';
}

Measured memory_bytes: 3564
#include <cstdio>
#include <queue>
#include <iostream>
#include <algorithm>
#define INT long long
#define oo 987654321
using namespace std;

INT n, a, b;

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    INT sum = (a+(n-1)*b) - (b+(n-1)*a)+1;
    cout<<(sum>=0?sum:0)<<endl;
    return 0;
}



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

bool is_integer( double x ){
  return floor(x)==x;
}

double Distance(int *p_1,int *p_2,int D){
    
    double sum = 0;
    
    for(int i=0;i<D;i++){
        int r,l;
        l = *(p_1 + i);
        r = *(p_2 + i);
        sum += pow((r-l),2);
    }
    
    return sqrt(sum);
}

int main(void){
    
    int N,D,ans = 0;
    cin >> N >> D;

    int data[N][D];

    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            cin >> data[i][j];
        }
    }
    
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(is_integer(Distance(&data[i][0],&data[j][0],D))) ans++;
        }
    }
    
    cout << ans << endl;
}

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

struct edge {
  int from, to, cost;
};


int INF;
vector<vector<edge>> es;
vector<int> dist;

bool bellmanFord (int n, int s) {
  dist[s] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < es[j].size(); k++) {
        edge e_ = es[j][k];
        if (dist[e_.from] != INF && dist[e_.to] > dist[e_.from] + e_.cost) {
          dist[e_.to] = dist[e_.from] + e_.cost;
          // n回目にも更新があるなら、負の閉路が存在する
          if (i == n - 1) {
            return true;
          }
        }
      }
    }
  }
  return false;
}

int main() {
  
  int n;
  cin >> n;

  INF = 2000000;
  es.resize(n);
  dist = vector<int>(n, INF);

  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      edge e;
      e.from = u;
      cin >> e.to >> e.cost;
      es[i].push_back(e);
    }
  }

  bool flg = bellmanFord(n, 0);
  
  for (int i = 0; i < n; i++) {
    cout << i << " " <<  dist[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

std::vector<ll> primes(ll n) {
  std::vector<ll> p; p.reserve(1.26 * (double)n / std::log(n)); p.push_back(2);
  std::vector<bool> isd(n);
  for (ll i = 3; i < n; i += 2) if (!isd[i])
   { p.push_back(i); for (ll j = i * i; j < n; j += i) isd[j] = true; }
  return p;
}

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;

  auto P = primes(55555);

  for(auto&& p : P) {
    if ( p % 5 == 1 ) {
      N--;
      std::cout << p << " ";
    }
    if ( N == 0 ) break;
  }
  std::cout << std::endl;

  return 0;
}


Measured memory_bytes: 512
/*
 *  ॐॐॐॐ
 *  मनुष्य के साहस से बड़ा कोई लक्ष्य नहीं, हारा वही जो लड़ा नहीं ।। 
 *          ---- स्वामी विवेकानंद जी
 */
/*
 * Author: @SumitRaut
 */


#include <bits/stdc++.h>
#define debug1(x) cerr<<#x<<' '<<x<<'\n'
#define debug2(x,y) cerr<<#x<<' '<<x<<' '<<#y<<' '<<y<<'\n'
#define debug3(x,y,z) cerr<<#x<<' '<<x<<' '<<#y<<' '<<y<<' '<<#z<<' '<<z<<'\n'
#define sbc __builtin_popcount
#define pb push_back
#define em emplace
#define emb emplace_back
#define ll long long
int mod = 1e9+7;

template<typename T> void smax(T& a, T b) { if(a<b) a=b; }
template<typename T> void smin(T& a, T b) { if(a<b) a=b; }
template<typename T> T pw(T a,T b) { T p=1,one=1; while(b) { if(b&one) p=p*a; a=a*a; b >>=1; } return p; }
template<typename T> T gcd(T x,T y) { /* if(y==0) return x; return gcd (y,x%y); */ T t; while(y!=0) { t=y; y=x%y; x=t; } return x; }
template<typename T> T pwm(T a,T b) { T p=1,one=1,mod=1e9+7; while(b) { if(b&one) p=p*a%mod; a=a*a%mod; b >>=1; } return p; }

using namespace std;
class Timer { chrono::high_resolution_clock::time_point start_t, end_t; public: Timer() { start_t=chrono::high_resolution_clock::now(); } ~Timer() { end_t = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>(end_t-start_t); cerr<<"\nRunTime: "<<duration.count()<<"ms"<<'\n'; } };
ll n,k;
inline void solve() {
    // Timer timer;
	cin>>n>>k;
	n%=k;
	cout<<min(k-n,n)<<'\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // int t; cin>>t; while(t--)
        solve();
    return 0;
}



Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST
import           Data.Ord
import qualified Data.Vector.Unboxed           as UV

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

main = do
  digits <- UV.fromList . map digitToInt <$> getLine
  k      <- readInt
  let d      = UV.length digits
      cumsum = UV.tail
        $ UV.scanl' (\acc val -> if val /= 0 then acc + 1 else acc) 0 digits
      matched = if (UV.length . UV.filter (/= 0) $ digits) == k then 1 else 0
      lowerDigit =
        sum . map (\val -> combi (val - 1) (k - 1) * (9 ^ k)) $ [1 .. (d - 1)]
      zeroDigit =
        sum
          . map
              (\i ->
                combi (d - i - 1) (k - cumsum UV.! (i - 1))
                  * 9
                  ^ (k - cumsum UV.! (i - 1))
              )
          . filter
              (\i -> (digits UV.! i /= 0) && (k - cumsum UV.! (i - 1) >= 0))
          $ [1 .. (d - 1)]
      equalDigit =
        sum
          . map
              (\i ->
                (digits UV.! i - 1)
                  * combi (d - i - 1) (k - cumsum UV.! i)
                  * 9
                  ^ (k - cumsum UV.! i)
              )
          . filter (\i -> (digits UV.! i > 1) && (k - cumsum UV.! i >= 0))
          $ [0 .. (d - 1)]
  print $ matched + lowerDigit + zeroDigit + equalDigit

combi n k
  | n < 0 || k < 0   = 0
  | n < k            = 0
  | n == 0 || k == 0 = 1
  | otherwise = foldl' (*) 1 [(n - k + 1) .. n] `div` foldl' (*) 1 [1 .. k]


Measured memory_bytes: 508
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const ll INF = 1LL << 60;

//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    if (a[0]+a[1]==a[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3580
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
const int N=2e5+50;
const int INF=0x3f3f3f3f;
typedef long long ll;
long long powMod(ll a,ll n)
{
    ll ans=1;
    for(;n>0;n>>= 1)
    {
        if(n&1)
            ans=ans*a;
        a=a*a;
    }
    return ans;
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    ll sum=0;
    sum=m;
    sum*=pow(m-1,n-1);
    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val (s, w) = readIntegerList()
    if (w >= s) {
        println("unsafe")
    } else {
        println("safe")
    }
}


fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 36492
package main

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

func main() {
	a, b, c := ReadInt(), ReadInt(), ReadInt()
	if a >= c || b >= c || a+b == c {
		fmt.Println("No")
		return
	}
	if 4*a*b < (c-a-b)*(c-a-b) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1844