akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

using ll = long long;

const int MAXN = 6e3;
const int MAXK = 6e3;
int N, K;
int A[MAXN];
ll pref[MAXN];
bool canReach[MAXK];

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> A[i];
  sort(A, A + N);
  pref[0] = 0;
  for (int i = 0; i < N; i++) pref[i+1] = pref[i] + A[i];
  int bestReach = 0;
  canReach[0] = 1;
  
  for (int i = N-1; i >= 0; i--) {
    if (bestReach + pref[i+1] < K) {
      cout << i+1 << '\n';
      exit(0);
    }
    for (int v = K-1-A[i]; v >= 0; v--) {
      if (canReach[v]) {
        canReach[A[i]+v] = true;
        bestReach = max(bestReach, A[i]+v);
      }
    }
  }
  cout << 0 << '\n';
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int odd = 0;
  int n;
  scanf("%d",&n);
  REP(i,n){
    int x;
    scanf("%d",&x);
    if(x%2==1)odd++;
  }
  puts(odd%2==0?"YES":"NO");
  return 0;
}


Measured memory_bytes: 256
#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 ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;

typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 303, MOD = 1e9 + 7;
int n, m, dp[N][N][N];
vector <pii> R[N];

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

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int l, r, x;
		cin >> l >> r >> x;
		R[r].pb({l, x});
	}
	int res = 0;
	dp[0][0][0] = 1;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (j > 0 && i == j) {
				continue;
			}
			for (int k = 0; k <= n; k++) {
				if (k > 0 && (i == k || j == k)) {
					continue;
				}
				int pos = max({i, j, k});
				
				int bad = 0;
				for (auto seg : R[pos]) {
					int l = seg.F, x = seg.S;
					if ((i >= l) + (j >= l) + (k >= l) != x) {
						bad = 1;
						break;
					}
				}
				if (bad) {
					dp[i][j][k] = 0;
					continue;
				}
				if (pos == n) {
					add(res, dp[i][j][k]);
				}	else {
					add(dp[pos + 1][j][k], dp[i][j][k]);
					add(dp[i][pos + 1][k], dp[i][j][k]);
					add(dp[i][j][pos + 1], dp[i][j][k]);
				}
			}
		}
	}
	cout << res;
}


Measured memory_bytes: 108800
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s1,s2;
	int mini=0;
	cin>>s1>>s2;
	for(int i=0;i<s1.length();i++)
	{
		if(s1[i]!=s2[i])
		{
			mini++;	
		}
	}
	cout<<mini;
}

Measured memory_bytes: 3912
#include <stdio.h>
typedef long long ll;
int main() {
	ll x, ans;
	scanf("%lld", &x);
	ans = (x / (5 + 6)) * 2;
	int left = x % (5 + 6);
	if (left == 0) {
		ans += 0;
	} else if (1 <= left && left <= 6) {
		ans += 1;
	} else {
		ans += 2;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): return k.join(list(map(str, lst)))
INF = float('inf')
from math import sqrt
from itertools import permutations
def solve():
    n = II()

    town = []
    for i in range(n):
        x, y = MI()
        town.append((x, y))

    def f(t1, t2):
        x1, y1 = t1
        x2, y2 = t2
        return sqrt( (x1 - x2) ** 2 + (y1 - y2) ** 2)

    tot = 0
    cnt = 0
    for t in permutations(town, n):
        cnt += 1
        d = 0
        # print(t)
        for i in range(n-1):
            j = i + 1
            d = f(t[i], t[j])
            # print(d)
            tot += d

    print(tot / cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);    
#define f(i,j,k)  for(int i=j;i<k;i++)
#define fr(i,j,k) for(int i<=k-1;i>=j;i--)
#define ll long long
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;

int main()
{
	fio
	int TC;
	//cin>>TC;
	TC=1;
	while(TC--)
	{
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		bool takahashi=true;
		while(a>0 && c>0)
		{
			if(takahashi)
			{
				c-=b;
				takahashi=false;
			}
			else
			{
				a-=d;
				takahashi=true;
			}

		}
		(a>0)?cout<<"Yes\n":cout<<"No\n";
		
	}
	return 0;
}


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

bool checker(string str1, string str2){
  int num1 = str1.size();
  bool result;
  if(str1.at(num1-1) == str2.at(0)) result = true;
  else result = false;
  return result;
}

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  if(checker(A,B) && checker(B,C)) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	string ans;
	if (a <= 8 && b <= 8) { ans = "Yay!"; }
	else { ans = ":("; }
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define ld double
#define llu unsigned long long
#define rep(i,x,y)  for(int i=int(x);i<int(y);++i)
#define For(i,x,y)  for(int i=int(x);i<=int(y);++i)
#define FOr(i,x,y)  for(int i=int(x);i>=int(y);--i)
#define pi acos(-1) 
#define mk make_pair
#define pa pair<ll,ll>
#define lf else if
#define IL inline
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define sqr(x)      ((x)*(x))
#define Mul(x,y)    ((x)=1LL*(x)*(y)%mod)
#define Add(x,y)    ((x)=((x)+(y))%mod)
#define Max(x,y)    ((x)=((x)<(y)?(y):(x)))
#define E(x)        return writeln(x),0
#define p(x)        printf("~%lld~\n",LL(x))
#define pp(x,y)     printf("~~%lld %lld~~\n",LL(x),LL(y))
#define LL			(long long)
#define ppp(x,y,z)  printf("~~~%lld %lld %lld~~~\n",LL(x),LL(y),LL(z))
#define pppp(a,b,c,d)	printf("~~~%lld %lld %lld %lld\n",LL(a),LL(b),LL(c),LL(d))
#define f_in(x)     freopen(x".in","r",stdin)
#define f_out(x)    freopen(x".out","w",stdout)
#define open(x)     f_in(x),f_out(x)
#define fi first
#define se second
#define GuYue		puts("\nGuYueNa________________________________________________________________________________")
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
    struct _{_(){freopen("cf.in","r",stdin);}}_; 
#endif 
#define NEG 1
    static const int GYN=2333333;
    char SZB[GYN],*S=SZB,*T=SZB;
    inline char gc(){   if (S==T){  T=(S=SZB)+fread(SZB,1,GYN,stdin); if (S==T) return '\n';  }   return *S++;    }
#if NEG
    inline ll read(){    ll x=0,g=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') g=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*g; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
	void Print(long long *a,int s,int t){For(i,s,t)printf("%lld ",a[i]);}
	void Print(int *a,int s,int t){For(i,s,t)printf("%d ",a[i]);}
	void Print(char *a,int s,int t){For(i,s,t)putchar(a[i]);}
	void writeln(ll x){write(x);puts("");}
}using namespace SHENZHEBEI;
const ll N=310;
ll c[N][N],f[N][N],n,k,mod;
int main(){
	n=read(),k=read(),mod=read();
	For(i,0,n+1)For(j,0,i)c[i][j]=j?(c[i-1][j-1]+c[i-1][j])%mod:1ll;
	FOr(i,k,0){
		Add(f[i][1],1);
		For(j,1,n+1)For(k,1,n+1)Add(f[i][j+k],f[i][j]*f[i+1][k]%mod*c[j+k-2][j-1]%mod);
		For(j,0,n)Add(f[i][j],f[i+1][j]);
	}writeln(f[0][n+1]);
}
/*
		x1		x2		x3		x4		x5
f[i][j]	i个点j个字数
f[x][i]	f[x+y][i+1]
*/


Measured memory_bytes: 1664
import java.math.*;
import java.util.*;
import java.lang.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n];
        int ans = 1001001001;
        for(int i = 0 ; i<x.length;i++){
            x[i] = sc.nextInt();
        }
        for(int i = 0; i<=100 ;i++){
            int tmp = 0;
            for(int j = 0;j<n;j++){
                tmp += (x[j]-i)*(x[j]-i);
            }
            ans = Math.min(tmp,ans);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23252
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        S: chars,
    }
    let mut ans: u64 = 0;

    for bit in 0..1 << S.len()-1 {
        let mut acc_str = String::new();
        let mut acc = 0_u64;
        acc_str.push(S[0]);
        for i in 0..S.len() - 1 {
            if bit & 1 << i != 0 {
                acc += acc_str.parse::<u64>().unwrap();
                acc_str = String::new();
            }
            acc_str.push(S[i+1]);
        }
        acc += acc_str.parse::<u64>().unwrap();
        ans += acc;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n;i++)
int main(void) {
	int d, n, x, a[100],o = 0;
	cin >> n >> d >> x;d--;
	rep(i, n) {
		cin >> a[i];
		o += d / a[i] + 1;
	}
	cout << o + x << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<functional>
#include<string>
#include<vector>
#include<cstring>
#include<utility>
#include<set>
#include<map>

#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 2e9
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
const double PI = acos(-1);

using namespace std;

int main(void) {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	//	freopen("input.txt", "r", stdin);

	int K; cin >> K;
	for (int i = 1; i <= K; i++) {
		cout << "ACL";
	}

}


Measured memory_bytes: 3644
#include <stdio.h>
int main(){

  int n,a[100],sum,blank,i,j;

  while(1){

    sum=0;
    scanf("%d",&n);
    if(n == 0) break;

    for(i = 0; i < n; i++) scanf("%d",&a[i]);

    for(i = 0; i < n-1; i++){

      for(j = 0; j < n-1; j++){

        if(a[j] > a[j+1]){

        blank=a[j];
        a[j]=a[j+1];
        a[j+1]=blank;

        }

      }

    }

    //   for(i = 0; i < n; i++) printf("%d ",a[i]);                                                                                                                                            

    for(i = 1; i < n-1; i++) sum += a[i];

    printf("%d\n",sum/(n-2));

  }

  return 0;

}

Measured memory_bytes: 600
//suhan lee,saitama university

#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
#include <complex>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define repn(i,n) for(int i=0;i<n;i++)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
#define pb push_back 
#define pf push_front
vector<string> atom;
vector<int> atwei;
int unknown_flag;
int readnum(string input,int& i){
  int out=input[i++]-'0';
  while(isdigit(input[i])){
    out*=10;
    out+=input[i++]-'0';
  }
  return out;
}
int mole(string input,int& i);
int ex2(string input,int& i);
int atomn(string input,int& i);
int kak(string input,int & i){
  i++;
  int out=mole(input,i);
  i++;
  //  cout<<"kak1:"<<out<<endl;
  out*=readnum(input,i);
  //cout<<"kak:"<<out<<endl;
  return out;
}

int mole(string input,int& i){
  int out=0;
  if(input[i]==0||input.size()<=i) return 0;
  if(input[i]=='('){
    out+=kak(input,i);
  }
  else{
    out+=ex2(input,i);
  }
  if(input[i]!=0&&input[i]!=')')
    return out+=mole(input,i);
  else return out;
}
int ex2(string input,int& i){
  int out=atomn(input,i);
  if(isdigit(input[i])){
    out*=readnum(input,i);
  } 
  return out;
  
}
int atomn(string input,int& i){
  string atat;
  if(input[i+1]>='a'&&input[i+1]<='z'){
    atat=input[i];
    atat+=input[i+1];
    i=i+2;
  }
  else {
    atat=input[i];
    i=i+1;
  }
  int j;
  for(j=0;j<int(atom.size());j++){
    if(atom[j]==atat) break;
  }
  if(j==atom.size()) {
    unknown_flag=true;
    //  cout<<atat<<endl;
    return 0;
  }
  //cout<<"i:"<<i<<endl;
  return atwei[j];
}



int main(){
  
  int i,tmpwei;
  string tmpst;
  i=0;
  //  printf("%d %d\n",'a','z');
  while(true){
    cin>>tmpst;
    if(tmpst=="END_OF_FIRST_PART")
      break;
    cin>>tmpwei;
    atom.pb(tmpst);
    atwei.pb(tmpwei);
  }
  while(true){
    unknown_flag=false;
    i=0;
    cin>>tmpst;
    if(tmpst=="0") return 0;
    tmpwei=mole(tmpst,i);
    if(unknown_flag) cout<<"UNKNOWN\n";
    else cout<<tmpwei<<endl;
  }
  return 0;
}

Measured memory_bytes: 1256
# coding: utf-8
# Your code here!

list = input()
ans_list = []
#print(list)

for i in range(len(list)):
    if list[i] == "?":
        ans_list.append("D")
    else:
        ans_list.append(list[i])
#print(ans_list)

for i in range(len(list)):
    print(ans_list[i], end="")

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

// typedef long long ll;
long long n, m = 1e9 + 7;
long long poww(long long a, long long b)
{
	if (b == 0) return 1;
	if (b == 1) return a % m;
	long long x = poww(a, b / 2) % m;
	x = (x * x) % m;
	if (b % 2 == 0) return (x) % m;
	else return (x * a) % m;
}
int gcd(int a, int b) {
	if (b == 0) return a;
	if (b == 1) return 1;
	return gcd(b, a % b);
}
int summ(long long n) {
	int sum = 0;
	for (int i = 0; i < 18; i++)
	{
		sum += n % 10; n /= 10;
		if (n == 0) break;
	}
	return sum;
}
vector<long long> fc;
long long fact(long long n) {
	fc[0] = 1; fc[1] = 1; fc[2] = 2;
	for (long long i = 3; i <= n; i++)
	{
		fc[i] = (i % m * fc[i - 1] % m) % m;
	}
	return fc[n] % m;
}
bool check(unordered_map<int, int>& map) {
	return 0;
}

int main() {
	// ios::sync_with_stdio(false); cin.tie(NULL);
	int t, k, n;
	cin >> n >> k;
	int h[n];
	for (int i = 0; i < n; i++)
	{cin >> h[i];}
	vector<int> a(n, INT_MAX);
	a[0] = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < min(i + k + 1, n); j++)
		{
			a[j] = min(a[i] + abs(h[i] - h[j]), a[j]);
		}
	}
	cout << a[n - 1] << endl;
	return 0;
}

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

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

  map<string,int> m ;

  rep(i,n){
      string s;
      cin >> s;
      m[s]++;
  }

  cout << "AC x " <<  m["AC"] << endl;
  cout << "WA x " << m["WA"] << endl;
  cout << "TLE x " << m["TLE"] << endl;
  cout << "RE x " << m["RE"] << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  int a[26] = {0};
  string s;cin >> s;
  for(int i=0;i<s.size();i++){
    int k=s[i]-'a';
    a[k] = 1;
  }
  for(int i=0;i<26;i++){
    if(a[i]!=1){
      char t = i+'a';
      cout << t << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;

}


Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
using namespace std;
using LL = long long;
LL N, M, S;
LL A[50];
inline LL ceil(LL d, LL n) {return (d+n-1)/n;}
inline bool ok(LL x) {
  if(M < S-x) return false;
  LL s = 0;
  for(auto i=0; i<N; ++i) {
    s += max(0ll, ceil(A[i]+x+1-N, N+1));
    if(x < s)return false;
  }
  return true;
}
int main() {
  scanf("%lld", &N);
  M=N*(N-1);
  for(auto i=0; i<N; ++i) scanf("%lld", A+i), S+=A[i];
  LL l = -1, h = 1e18;
  while(l+1 < h) {
    LL m = (l+h)>>1;
    (ok(m) ? h : l) = m;
  }
  for(auto x=max(0ll,h-M); x<=h; ++x) if(ok(x)) {
    printf("%lld\n",x);
    break;
  }
}

Measured memory_bytes: 128
from enum import Enum
from queue import Queue

import numpy as np

import collections
import bisect
import sys
import math

from scipy.sparse.csgraph import floyd_warshall

BIG_NUM = 200000000000
MOD = 1000000007
EPS = 0.000000001

A,B = map(int,input().split())
if A < 10 and B < 10:
    print(A*B)
else:
    print(-1)

Measured memory_bytes: 13828
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String a = input.readLine( );
		String b = input.readLine( );
		int a1;
		int b1;

		if(a.length() > b.length()){
			System.out.println("GREATER");
		}else if(b.length() > a.length()){
			System.out.println("LESS");
		}else{
			while(a.length()>0 && b.length()>0){
				a1 = Integer.parseInt(a.substring(0, 1));
				b1 = Integer.parseInt(b.substring(0, 1));
				if(a1>b1){
					System.out.println("GREATER");
					break;
				}else if(b1>a1){
					System.out.println("LESS");
					break;
				}
				a = a.substring(1);
				b = b.substring(1);
			}
			if(a.length()==0){
				System.out.println("EQUAL");
			}
		}
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
//1 < n < 10^4
//x, y, z <= 100
//x, y, z 
int main(){
    int n;
    cin >> n;
    vector<int> res(n + 1, 0);
    int tmp;

    for(int x = 1; x <= 100; x++){
        for(int y = 1; y <= 100; y++){
            for(int z = 1; z <= 100; z++){
                tmp = x*x + y*y + z*z + x*y + y*z + z*x;
                //tmp == 1~nの数を求める
                //n = 3
                //f(1), f(2), f(3)
                //ans.at(0), ans.at(1), ans.at(2), ans.at(3)
                if(tmp > n){
                    break;
                }
                res.at(tmp)++;
            }
        }
    }

    //res.size() = 4
    //sort(res.begin(), res.end()); 1 3 2→ 3 2 1
    for(int i = 1; i <= n; i++){ 
        //res(n + 1) → res.at(0) ~ rse.at(n)
        cout << res.at(i) << endl;
    }
}

Measured memory_bytes: 3608
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define RANGE(i, x, n) for(int i = x; i < n; ++i)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

void accelerate()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

const int MAXN = 10010;
vector<int> E[MAXN];
vector<int> c;
vector<int> ans;
int res;
int cnt;
int vis[MAXN];
int decm[MAXN];

void BFS(set<int> &S)
{
    while(!S.empty()) {
        set<int> next;
        for(auto v: S) {
            for(auto u: E[v]) {
                if(!vis[u]) {
                    ++decm[u];
                    next.insert(u);
                }
            }
        }
        S.clear();
        for(auto x: next) {
            if(E[x].size()-decm[x] <= 1) {
                S.insert(x);
            }
        }
        for(auto v: S) {
            ans[v] = c[cnt++];
            vis[v] = 1;
        }
    }
}

void DFS(int v = 0, int fa = -1)
{
    for(auto u: E[v]) {
        if(u != fa) {
            res += min(ans[v], ans[u]);
            DFS(u, v);
        }
    }
}

int main()
{
    accelerate();
    int n;
    cin >> n;
    c.resize(n);
    ans.resize(n);
    REP(i, n-1) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        E[x].push_back(y);
        E[y].push_back(x);
    }
    REP(i, n) {
        cin >> c[i];
    }
    sort(c.begin(), c.end());
    map<int, vector<int>> ds;
    REP(i, n) {
        ds[E[i].size()].push_back(i);
    }
    cnt = 0;
    set<int> S;
    for(auto e: ds) {
        for(auto x: e.second) {
            ans[x] = c[cnt];
            ++cnt;
            S.insert(x);
            vis[x] = 1;
        }
        break;
    }
    BFS(S);
    DFS();
    cout << res << endl;
    REP(i, n) cout << ans[i] << " "; cout << endl;

}


Measured memory_bytes: 1536
// #define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

ll INF = 1LL << 31;
int main()
{
    int n;
    cin >> n;
    vector<P> m(n);
    rep(i, n) cin >> m[i].first >> m[i].second;

    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, INF));
    rep(i, n + 1) dp[i][i] = 0;

    // start by doing a 1 matrix times 1 matrix multiplication
    // AB = A.x * A.y * B.y
    for (int w = 1; w <= n; w++)
    {
        // for each possible left most matrix for each width
        // i.e. until your "right" matrix defined by the width is m[n-1]
        for (int l = 0; l <= n - w; l++)
        {
            // as seen here.
            int r = l + w - 1;

            // for every matrix inbetween:
            for (int k = l; k < r; k++)
            {
                // multiplying (AB)(CDE) gives you an (A.x * B.y) x (C.x=B.y * E.y) mult.
                // Thus, this is a A.x * B.y * E.y + dp[A][B] + dp[C][E].

                // Do this for all possible combinations
                // e.g. A(BCD), (AB)(CD), (ABC)D where ABC-> A(BC) or (AB)C , etc.
                chmin(dp[l][r], m[l].first * m[k].second * m[r].second + dp[l][k] + dp[k + 1][r]);
            }
        }
    }

    cout << dp[0][n - 1] << endl;

    return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL)
    x = x->left;
  
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL)
    x = x->right;
  
  return x;
}

Node treeSearch(Node x, int k){
  if(x == NIL || k == x->key)
    return x;
  if(k < x->key)
    return treeSearch(x->left,k);
  else
    return treeSearch(x->right,k);

}

Node treeSuccessor(Node x){
  Node y;
  
  if(x->right != NIL)
    return treeMinimum(x->right);

  y = x->parent;
  
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }

  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL)
    y = z;
  else
    y = treeSuccessor(z);

  if(y->left != NIL)
    x = y->right;
  else
    x = y->right;

  if(x != NIL)
    x->parent = y->parent;

  if(y->parent == NIL)
    root = x;
  else if(y == y->parent->left)
    y->parent->left = x;
  else
    y->parent->right = x;

  if(y != z)
    z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x!=NIL){
    y = x;
    if(z->key < x->key)
      x=x->left;
    else
      x=x->right;
  }
  
  z->parent = y;
  
  if(y==NIL)
    root=z;
  else
    if(z->key < y->key)
      y->left=z;
    else
      y->right=z; 
}

void inorder(Node x){
  if(x != NIL){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  }
}
  
void preorder(Node x){
  if(x != NIL){
    printf(" %d",x->key);
    preorder(x->left);
    preorder(x->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("\nyes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25156
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin>>H>>W;
  vector<string>S(H);
  for(int i=0; i<H; i++){
    cin>>S[i];}
  
  int count=0;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(S[i][j]=='.'){
        count=0;  //ここでcountを再度宣言。
        for(int k=max(0,i-1); k<min(H,i+2); k++){  //  この数値範囲での処理なら、
          for(int l=max(0,j-1); l<min(W,j+2); l++){ // 8方向全てに'#'があるか検索できる。
            if(S[k][l]=='#'){  // '#'があるとき、count++して、
              count++;}
          }
        S[i][j]=count+'0';}  // その数を元のS[i][j]に代入する。
      }    // countを数字表記したい場合は'0'を、アルファベット表記したい場合は'a'を足すと、
    }      // int型のcountの値をを数字、アルファベットに準じた文字表記にしてくれる。
  }  //計算処理はここで終了。'.'のみ処理するだけで、'#'に手は付けない。
  for(int i=0; i<H; i++){
    cout<<S[i]<<endl;}  // 処理結果を出力する。
}


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

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int a, b,c;
  cin>>a>>b>>c;

  if(a+b+c == 17) cout<<"YES"<<endl;
  else cout<<"NO"<<endl; 


  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)

using namespace std;
typedef long long ll;
/*
int main(){
for(int i=1;i<=100000;++i){
  cout<<i<<" "<<100000<<endl;
}
}

*/


int main(){
    ll N,K;
    cin>>N>>K;
    ll array[100001];
    
    for(int i=0;i!=100001;++i){
        array[i]=0;
    }
    
    for(int i=1;i!=N+1;++i){
        ll a,b;
        cin>>a>>b;
        array[a]+=b;
    }
    
    ll sum_array[100001];
    sum_array[0]=0;
    
    for(int i=1;i<=100000;++i){
        sum_array[i]=array[i]+sum_array[i-1];
    }
  
    int i;
 
    for(i=1;i<=100000;++i){
        if(sum_array[i-1]<K&&K<=sum_array[i]){
            break;
        }
    }
    
    
    cout<<i<<endl;
        
    
}



Measured memory_bytes: 5168
#include <iostream>
#include <stack>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <numeric>
#include <vector>
using namespace std;
#define endl "\n"
typedef long long Int;
Int N,A,B,C,l[8];

Int dfs(Int cur,Int a,Int b,Int c){
    if(cur==N){
        if(min({a,b,c})>0)return abs(a-A)+abs(b-B)+abs(c-C)-30;
        return 1000000000;
    }
    return min({dfs(cur+1,a,b,c),dfs(cur+1,a+l[cur],b,c)+10,dfs(cur+1,a,b+l[cur],c)+10,dfs(cur+1,a,b,c+l[cur])+10});
}
int main() {
    cin>>N>>A>>B>>C;
    for(int i=0;i<N;i++){
        cin>>l[i];
    }
    cout<<dfs(0,0,0,0)<<endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::{stdin, Read};


fn main() {
    let mut buffer = String::new();
    let mut stdin = stdin();

    stdin.read_to_string(&mut buffer).unwrap();
    let rows: Vec<&str> = buffer.split('\n').collect();
    let row1: Vec<&str> = rows[0].split(' ').collect();
    let a:u64 = row1[0].parse().unwrap();
    let b:u64 = row1[1].parse().unwrap();

    println!("{}", a * b);
}

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

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1000000007;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL A;
	cin >> A;
	string bs;
	cin >> bs;
	LL bup = stoi(bs.substr(0, 1));
	LL bdown = stoi(bs.substr(2, 2));
	LL B = bup * 100 + bdown;
	cout << (A * B) / 100 << "\n";
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int x[100]={0};
  int y[100]={0};
  for(int i = 0; i<n;i++){
      cin >> x[i];
  }
  for(int i = 0; i<n;i++){
      cin >> y[i];
  }
  
  double ans1 = 0;
  double ans2 = 0;
  double ans3 = 0;
  double ans4 = 0;
  
  for(int i = 0; i< n;i++){
      ans1+= abs(x[i] - y[i]);
      ans2 += pow(abs(x[i] - y[i]), 2);
      ans3 += pow(abs(x[i] - y[i]), 3);
      if(ans4<abs(x[i] - y[i]))ans4 = abs(x[i] - y[i]);
  }
  ans2 = pow(ans2, 0.5);
  ans3 = pow(ans3, 0.333333333333333333333333);
  cout << fixed << setprecision(6)<< ans1 << endl;
    cout << fixed << setprecision(6)<< ans2<< endl;
      cout << fixed << setprecision(6)<< ans3 << endl;
        cout << fixed << setprecision(6)<< ans4 << endl;
}


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

using namespace std;

int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  for (int i = 1; i < b; i++) {
    if ((i * a - c) % b == 0) {
      puts("YES");
      return 0;
    }
  }
  puts("NO");
}


Measured memory_bytes: 256
import numpy as np
N,T = map(int,input().split())
AB = []
for _ in range(N):
    AB.append(list(map(int,input().split())))
AB.sort(key=lambda x:(x[0],-x[-1]))
dp = np.array([0]*T)
ans = 0
for a,b in AB:
    ans = max(ans,dp[-1]+b)
    dp[a:] = np.maximum(dp[:-a]+b,dp[a:])
print(max(ans,dp[-1]))

Measured memory_bytes: 12996
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF (int)1e9
#define INFL (ll)1e11
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int L;
	cin >> L;
	vector<int> pow2;
	int tmp = 1;
	while (tmp <= L) {
		pow2.push_back(tmp);
		tmp *= 2;
	}
	int N = pow2.size();
	int M = 2 * (N - 1);
	int i = N - 2;
	vector<pair<int, int>> sd;
	while (L > pow2[N - 1]) {
		if (L - pow2[i] >= pow2[N - 1]) {
			L -= pow2[i];
			sd.push_back(P(i + 1, L));
			M++;
		}
		i--;
	}
	cout << N << " " << M << "\n";
	for (int i = 1;i < N;i++) {
		cout << i << " " << i + 1 << " " << 0 << "\n";
		cout << i << " " << i + 1 << " " << pow2[i - 1] << "\n";
	}
	REP(i, sd.size()) {
		cout << sd[i].first << " " << N << " " << sd[i].second << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
    int flag1=0,flag2=0;
    char a[10],b[10],c[10];
    scanf("%s %s %s",a,b,c);

    if(a[strlen(a)-1]==b[0]){
        flag1++;
    }
    if(b[strlen(b)-1]==c[0]){
        flag2++;
    }

    if(flag1==1&&flag2==1){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }

    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt(), m = sc.nextInt(), c = sc.nextInt();
		int[] b = new int[m];
		for (int i = 0; i < m; i++) {
			b[i] = sc.nextInt();
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < m; j++) {
				sum += sc.nextInt() * b[j];

			}
			if (sum + c > 0) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 25812
#C問題
N=int(input())
A=[]
B=[]
C=[]
for i in range(0,N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(a+b)
C.sort()
C.reverse()
point=-sum(B)
#print(point)
i=0
while i<N:
    point=point+C[i]
    i=i+2
print(point)

Measured memory_bytes: 15400
x,y,X,Y,v,d;C(w){w=abs(y-Y);d=(X<x-(v=(w+y%2)/2)?x-v-X:X>x+(v=(w+1-y%2)/2)?X-x-v:0)+w;}m,n,D[101][101],s,b;main(c){for(;scanf("%d%d%d",&m,&n,&s),m;printf("%d\n",b)){for(memset(D,1,40804);s--;)for(scanf("%d%d",&X,&Y),y=n;y;y--)for(x=m;x;x--)C(),d<D[x][y]?D[x][y]=d:0;for(b=!scanf("%d",&s);s--;b=c>b?c:b)for(c=!scanf("%d%d",&X,&Y),y=n;y;y--)for(x=m;x;c+=d<D[x--][y])C();}exit(0);}

Measured memory_bytes: 0
// D - Coloring Edges on Tree
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define eb emplace_back
using II = pair<int,int>;

int main(){
	int N; cin>>N;
	vvi tree(N);
	vector<II> edge;
	rp(i, 0, N-1){
		int a,b; cin>>a>>b; a--,b--;
		tree[a].eb(b); tree[b].eb(a);
		edge.eb(a,b);
	}

	int K = 0;
	vi p_color(N), visited(N);
	queue<int> q;
	q.push(0);
	visited[0] = true;
	while(!q.empty()){
		int p = q.front(); q.pop();
		K = max(K, (int)tree[p].size());
		int color = 1;
		for(auto c:tree[p]){
			if(visited[c]) continue;
			if(color==p_color[p]) color++;
			p_color[c] = color++;
			q.push(c);
			visited[c] = true;
		}
	}

	cout<< K <<endl;
	for(auto e:edge) cout<< p_color[e.second] <<endl;
}

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

import Control.Monad
import Control.Monad.Trans.State.Strict
import Data.Char (isSpace)
import Data.Maybe (fromJust)
import qualified Data.ByteString.Lazy.Char8 as B
import Data.List
import Data.Bits
--
type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT (B.readInt . B.dropWhile isSpace)

parseInt2 :: Parser (Int,Int)
parseInt2 = liftM2 (,) parseInt parseInt

parse :: Parser [(Int,Int)]
parse = do
    (n,m)<-parseInt2
    replicateM m parseInt2

main=do
    as <- fromJust.evalStateT parse <$> B.getContents
    print.length.merge.sort $ as

merge ((a1,b1):(a2,b2):as)
    | ma < mb = merge ((ma,mb):as)
    | otherwise = (a1,b1):merge ((a2,b2):as)
    where
        ma = max a1 a2
        mb = min b1 b2
merge ab = ab

Measured memory_bytes: 28028
#include <stdio.h>
int main(void)
{
int n,m,temp;
scanf("%d%d",&n,&m);
int a[n+1][m+1];
for(int i=0;i<n;i++)
{
temp=0;
for(int j=0;j<m;j++)
{
scanf("%d",&a[i][j]);
temp+=a[i][j];
}
a[i][m]=temp;
}
for(int j=0;j<=m;j++)
{
temp=0;
for(int i=0;i<n;i++)
{
temp+=a[i][j];
}
a[n][j]=temp;
}
for(int i=0;i<=n;i++)
{
printf("%d",a[i][0]);
for(int j=1;j<=m;j++)
{
printf(" %d",a[i][j]);
}
printf("\n");
}

}




Measured memory_bytes: 2104
# https://atcoder.jp/contests/abc127/tasks/abc127_d


import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

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

    heap = []
    for a in A:
        heappush(heap, (-a, 1))

    for _ in range(M):
        b, c = map(int, input().split())
        heappush(heap, (-c, b))

    cards = []
    while len(cards) < N:
        val, num = heappop(heap)
        cards.append(-val)
        if num > 1:
            heappush(heap, (val, num - 1))

    print(sum(cards))

if __name__ == '__main__':
    main()


Measured memory_bytes: 92056
// solution for ABC170F
// author : lynmisakura

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

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

using ll = long long;
using P = pair<int,int>;

int h,w,k;

int s[2],t[2];
vector<string> g;

int dx[] = {1,0,-1,0},dy[] = {0,-1,0,1};

const int INF = 1e9;

void input(){
    cin >> h >> w >> k;
    cin >> s[0] >> s[1] >> t[0] >> t[1];
    s[0]--,s[1]--,t[0]--,t[1]--;
    
    REP(i,h){
        string s;cin >> s;
        g.push_back(s);
    }
}


P dist[4000010];

int id(int x,int y,int d){
    return 4 * (x * w + y) + d;
}

int x_,y_,d_;
void get_posi(int id){
    d_ = id % 4;
    id /= 4;
    y_ = id % w;
    x_ = id / w;
}

bool inner(int x,int y){
    return x >= 0 && x < h && y >= 0 && y < w;
}

void print(){
    REP(i,h){
        REP(j,w){
            int res = INF;
            REP(k,4) res = min(res , dist[id(i,j,k)].first + (dist[id(i,j,k)].second > 0));
            cout << setw(5) << (res == INF ? "INF" : to_string(res));
        }
        cout << '\n';
    }
}

bool cmp(int now,int next_){
    
    P tmp = dist[now];
    
    int p = tmp.first;
    int q = tmp.second;
    
    if(next_ % 4 == d_){
        q++;
        if(q == k){
            q = 0;
            p++;
        }
        
    }else{
        if(q == 0){q++; if(q == k){p++;q = 0;}}
        else p++,q = 1;
    }
    
    if(dist[next_].first > p || ( dist[next_].first == p && dist[next_].second > q)) { 
        dist[next_] = (P){p,q}; return true;
    }
    else return false;
}

int main(void){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    input();
    
    REP(i,h * w * 4) dist[i].first = 1000000000;
    
    REP(i,4) dist[id(s[0],s[1],i)] = make_pair(0,0);
    
    //print();
    // BFS
    queue<int> q;
    REP(i,4){
        q.push(id(s[0],s[1],i));
    }
    
    while(q.size()){
        int now = q.front();q.pop();
        
        get_posi(now);
        
        REP(d,4){
            int nx = x_ + dx[d];
            int ny = y_ + dy[d];
            
            if(inner(nx,ny)){
                
                if(g[nx][ny] == '@') continue;
                
                int nid = id(nx,ny,d);
                if(cmp(now,nid)){
                    q.push(nid);
                }
            }
        }
        
    }
    
    int ans = INF;
    REP(i,4){
       //cout << dist[id(t[0],t[1],i)].first << '\n';
        ans = min(ans , dist[id(t[0],t[1],i)].first + (int)(dist[id(t[0],t[1],i)].second > 0));
    }
    
    //print();
    
    
    if(ans == INF){
        cout << -1 << '\n';
    }else cout << ans << '\n';
    
}


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

using namespace std;

using ll = long long;

bool is_prime(int n) {
    if (n % 2 == 0) return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

vector<int> divisor(int n) {
    vector<int> res;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.emplace_back(i);
            if (i != n / i) res.emplace_back(n / i);
        }
    }
    return res;
}

map<int, int> prime_factor(int n) {
    map<int, int> res;
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

vector<int> sieve(int n) {
    vector<int> res;
    vector<bool> is_prime(n + 1, true);
    is_prime[0] = false;
    is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (!is_prime[i]) continue;
        res.emplace_back(i);
        for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];

    vector<int> v(n + 1, 0);
    for (int i = n; i >= 1; i--) {
        int sum = 0;
        for (int j = i * 2; j <= n; j += i) {
            sum += v[j];
        }
        sum %= 2;
        v[i] = (a[i] + 2 - sum) % 2;
    }

    vector<int> ans;
    for (int i = 1; i <= n; i++) {
        if (v[i]) ans.push_back(i);
    }

    cout << ans.size() << "\n";
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << " \n"[i + 1 == ans.size()];
    }
    return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;

int main(){
  int N,M,C;
  cin >>N>>M>>C;
  
  vector<int> B(M);
  rep(i,0,M) cin >> B[i];
  
  int A;
  int sum = C;
  int ans = 0;
  rep(j,0,N){
    rep(i,0,M){
      cin >>A;
      sum += A*B[i];
    }
    if(sum>0) ans++;
    sum = C;
  }
  
  cout <<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>

using namespace std;

void solve();

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

void solve(){

	string a,b,c;
	
	cin >> a >> b >> c;

	if(a.back() == b.front() && b.back() == c.front()){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  string S; cin >> S;
  int N = S.size(); int tmp, ans; ans = N;
  rep(i, N){
    if(S[i]!=S[i+1]){
      tmp = max(i+1, N-1-i);
      ans = min(ans, tmp);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	long long n, i, j, k, ans, x;
	cin >> n;
	vector<long long> a(n + 1), s(n + 1);
	s[0] = 0;
	for (i = 1; i <= n; i++) {
		cin >> a[i];
		s[i] = s[i - 1] + a[i];
	}
	ans = 1LL << 60;
	for (i = 1; i < n; i++) {
		if (s[i] * 2 == s[n]) ans = 0;
		else if (s[i] * 2 < s[n]) {
			if (s[i] >= n - i) ans = min(ans, (s[n] - s[i]) - s[i]);
		}
		else {
			if (i <= s[n] - s[i]) ans = min(ans, s[i] - (s[n] - s[i]));
		}

	}
	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 3328
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use proconio::input;
use proconio::marker::*;
use std::cmp::{min, max};
use std::collections::{HashSet, HashMap, BinaryHeap, VecDeque};

static MOD: i64 = 1e9 as i64 + 7;

fn main() {
    input! {
        s: String,
    }
    let ans = if s.chars().collect::<Vec<char>>()[s.len() - 1] != 's'{ format!("{}{}", s, "s") }else{ format!("{}{}", s, "es") };
    println!("{}", ans);
}


Measured memory_bytes: 2148
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void) {
	int a, b, ans[20005], i = 0, j;
	char op[5];
	while (1) {
		cin >> a >> op >> b;
		if (op[0] == '+') {
			ans[i] = a + b;
		}
		if (op[0] == '-') {
			ans[i] = a - b;
		}
		if (op[0] == '*') {
			ans[i] = a * b;
		}
		if (op[0] == '/') {
			ans[i] = a / b;
		}
		if (op[0] == '?') {
			break;
		}
		i++;
	}
	for (j = 0; j < i; j++) {
		cout << ans[j] << endl;
	}
	return 0;
}


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

using namespace std;

const int N = 600+7;
const int M = N*N/2;

int n, m;
vector<int> e[N];
double res;
double dp[N];

inline void calc(int del)
{
    dp[n] = 0;
    for (int i = n-1; i; --i) {
        double sum = 0.0, mx = 0.0;
        int num = e[i].size();
        for (int j : e[i]) {
            sum += dp[j];
            mx = max(mx, dp[j]);
        }
        if (i == del && num >= 2) {
            --num;
            sum -= mx;
        }
        dp[i] = sum/num+1;
    }
    res = min(res, dp[1]);
}

int main()
{
    scanf("%d %d", &n, &m);
    for (int i = 1, s, t; i <= m; ++i) {
        scanf("%d %d", &s, &t);
        e[s].push_back(t);
    }
    res = 1e12;
    for (int i = 0; i <= n; ++i) calc(i);
    printf("%.10lf\n", res);
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
using namespace std;
  
int main()
{
	int m, n;
	cin >> n >> m;
	n += 1;
	m += 1;
	int *a = new int[n * m];
	for (int i = 0; i < n-1; i++)
		for (int j = 0; j < m-1; j++)
			cin >> a[i * m + j];
	for (int i = 0; i < n; i++) {
		a[i * m + m -1] = 0;
		for (int j = 0; j < m-1; j++)
			a[i * m + m -1] += a[i * m + j];
	}
	for (int i = 0; i < m; i++) {
		a[(n - 1) * m + i] = 0;
		for (int j = 0; j < n-1; j++)
			a[(n - 1) * m + i] += a[m * j + i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << a[i * m + j];
			if(j < m -1)
				cout << ' ';
		}
		cout << endl;
	}
    delete [] a;
    return 0;
}

Measured memory_bytes: 3100