akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int X,Y,Z;
multiset<string>S;
multiset<string>::iterator it;
string x,y;
int main()
{
	file();
	read(X),read(Y),read(Z);
	For(i,1,X)S.insert("a");
	For(i,1,Y)S.insert("b");
	For(i,1,Z)S.insert("c");
	while(S.size()>1)
	{
		it=S.begin();
		x=*it;S.erase(it);
		it=S.end();--it;
		y=*it;S.erase(it);
		S.insert(x+y);
	}
	cout<<*S.begin()<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool isVowel(char c)
{
    if(c=='a'|| c=='e'||c=='i'||c=='o'||c=='u')
        return true ;
    else
        return false ;
}
int main()
{
    char c ;

    cin>> c ;
    if (isVowel(c))
        cout<< "vowel" ;
    else
        cout << "consonant" ;
    return 0;
}


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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 998244353ll;
const ll MAXN = (ll) 1e5 + 10;
const ll INF = (ll) 2242545357980376863;
const ld EPS = (ld) 1e-8;

ll dp[MAXN][3];
ll a[MAXN][3];

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//memset(dp, 31 , sizeof dp);
	ll n, k;
	cin >> n;
	for(int i = 1; i <= n; i++) for(int j = 0;j<3;j++) cin >> a[i][j];
	//dp[1] = abs(h[0] - h[1]);
	for(int i = 1;i<=n;i++){
		for(int j = 0;j<3;j++){
			for(int k = 0; k<3;k++){
				if(k == j) continue;
				dp[i][k] = max(dp[i-1][j] + a[i][k], dp[i][k]);
			}
		}
	}
	//debug(dp[6][1]);
	cout << *max_element(dp[n], dp[n] + 3);

	return 0;
}


/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;  
int main() 
{
	FAST
	ll n;
	cin>>n;
	n--;
  	cout<<((n*(n+1))/2);
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = [list(map(int, input().split())) for i in range(2*k)]
ans = [0]*n
for i in range(k):
    for j in range(a[i*2][0]):
        s = a[i*2+1][j]
        ans[s-1] += 1
ans = [str(i) for i in ans]
print(ans.count('0'))

Measured memory_bytes: 68412
n = int(input())
p = list(map(int, input().split()))
m = []
cnt = 0
for i in range(n - 1):
    m.append(p[i + 1] - p[i])
for i in range(n - 2):
    if 0 < m[i] * m[i + 1]:
        cnt += 1
print(cnt)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  char op;
  cin >> a >> op >> b;
  if(op == '+') {
    cout << a + b << endl;
  } else {
    cout << a - b << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define pi pair<int,int>
#define ff first
#define ss second
#include "string"


const int N = 1000003;
const int M = 1000003;

int mod( int m ,int mod = M) {
   m %= mod;
   return (m + mod) % mod;
}

int power(int x,int y) {
   int res = 1;
   x = mod(x);
   while (y > 0) {
      if (y & 1)
         res =mod(res * x);
      y = y / 2;
      x = mod(x * x);
   }
   return mod(res);
}

int f[N],invf[N];
void fact() {
   f[0] = f[1] = 1;
   for(int i=2;i<N;i++)
      f[i] = mod(f[i-1] * i);

   invf[N-1] = power(f[N-1],M-2);
   for(int i=N-1;i>0;i--)
      invf[i-1] = mod(invf[i] * i);

}

int nCr(int n,int r) {
   if(r>n)
      return 0;
   int ans = f[n];
   ans = mod(ans*invf[n-r]);
   ans = mod(ans*invf[r]);
   return ans;
}

int nPr(int n,int r) {
   if(r>n)
      return 0;
   int ans = f[n];
   ans = mod(ans*invf[n-r]);
   return ans;
}



int32_t main(){
	boost;
	fact();
	int t;
	cin >> t;
	while(t--) {
		int x, d, n;
		cin >> x >> d >> n;
		if(x == 0) {
			cout << 0 << endl;
			continue;
		}
		else if(d == 0) {
			cout << power(x, n) << endl;
			continue;
		}
		int l = mod(x * power(d,M-2));
		int r = l + n - 1;
		int tt = (r / M) * M;

		if(tt >= l && tt <= r)
			cout << 0 << endl;
		else {
			int ans = mod(f[r] * invf[l - 1]);
			ans = mod(ans * power(d, n));
			cout << ans << endl;
		}
	}
}



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

int main(){
    int a, b;
    cin >> a >>  b ;
    int num = a + b;
    int ans = 0;
    if (num % 2 != 0) {
        ans = (num + 1) / 2;
    } else ans = num / 2;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
#define ld long double
#define ll long long
using namespace std;

int N, Q, H, S, D;
ll vq, vh, vs, vd, vmin;

int main() {
    scanf("%d%d%d%d%d", &Q, &H, &S, &D, &N);
    vq = Q * 8LL, vh = H * 4LL, vs = S * 2LL, vd = D;
    vmin = min( min(vq, vh), min(vs, vd) );

    ll Ans = 0;
    if(vmin == vq) Ans = (ll)N * 4 * Q;
    else if(vmin == vh) Ans = (ll)N * 2 * H;
    else if(vmin == vs) Ans = (ll)N * S;
    else {
    	Ans = (ll)(N / 2) * D;
        if(N & 1) Ans += min( min(4 * Q, 2 * H), S );
    }
    printf("%lld", Ans);
}

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

void print(const vector<int> v)
{
	rep(i, v.size())
	{
		if (i) cout << " ";
		cout << v[i];
	}
	cout << endl;
}

int main(void)
{
	int n;
	cin >> n;
	vector<int> v;
	repd(i, 1, n+1)
	{
		v.push_back(i);
	}
	
    do {
        print(v);
    } while (std::next_permutation(v.begin(), v.end()));
}


Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <random>
#include <cassert>
#include <numeric>
#define ll long long int
#define LL unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;



int main() {
    ll n, k; cin >> n >> k;
    ll ans = 1ll;
    ans *= k;
    rep(i,n-1){
        ans *= (k-1);
    }
    cout << ans << endl;
}


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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	string s;
	cin >> s;
	vector<int> alp(26);
	rep (i, 4) alp[s[i] - 'A']++;
	rep (i, 26) {
	  if (alp[i] == 0) continue;
	  if (alp[i] != 2) {
		cout << "No" << endl;
		return 0;
	  }
	}
	cout << "Yes" << endl;
	
    return 0;
}



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

int main()
{
    long long N, x;
    cin >> N >> x;

    long long A[N];
    long long ans = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        if (i == 0)
        {
            if (A[0] > x)
            {
                ans = A[0] - x;
                A[0] = x;
            }
        }
        else
        {
            if (A[i - 1] + A[i] > x)
            {
                ans += A[i - 1] + A[i] - x;
                A[i] -= A[i - 1] + A[i] - x;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
// long double EPS=1E-8;
////////////////////////////////////////

bool comp(l_l a,l_l b){
    if(a.first<b.first)return true;
    else if(a.first==b.first&&a.second>b.second)return true;
    else return false;
}

bool comp2(l_l a,l_l b){
    if(a.second>b.second)return true;
    else return false;
}


int main() {
    ll n,k;cin>>n>>k;
    vector<l_l> a(n);rep(i,0,n-1)cin>>a[i].first>>a[i].second;
    sort(a.begin(),a.end(),comp);
    vector<l_l>b,c;
    rep(i,0,n-1){
        if(i==0){
            b.pb(a[i]);
        }else if(a[i-1].first==a[i].first){
            c.pb(a[i]);
        }else{
            b.pb(a[i]);
        }
    }
    sort(b.begin(),b.end(),comp2);sort(c.begin(),c.end(),comp2);
    ll bs=b.size(),cs=c.size();
   // rep(i,0,bs-1)cout<<b[i].first<<" "<<b[i].second<<endl;cout<<endl;
   // rep(i,0,cs-1)cout<<c[i].first<<" "<<c[i].second<<endl;cout<<endl;
    ll x[bs],y[cs];
    if(b.size()){
        x[0]=b[0].second;
        rep(i,1,bs-1)x[i]=x[i-1]+b[i].second;
    }
    if(c.size()){
        y[0]=c[0].second;
        rep(i,1,cs-1)y[i]=y[i-1]+c[i].second;
    }
    ll ans=0;
  //  rep(i,0,bs-1)cout<<x[i]<<" ";cout<<endl;
  //  rep(i,0,cs-1)cout<<y[i]<<" ";cout<<endl;
    for(ll i=1;i<=bs&&i<=k;i++){
        if(i+cs<k)continue;
        ll sum=i*i;
        if(k-i-1<0)sum+=x[i-1];
        else sum+=x[i-1]+y[k-i-1];
    //cout<<i<<" "<<sum<<endl;
        Max(&ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4336
(* O(n) *)
let n = Scanf.scanf " %d" @@ (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let _ = print_endline @@ if Array.fold_left (fun acc a -> (acc + a) mod 2) 0 a_s = 0 then "YES" else "NO"

Measured memory_bytes: 5376
a = list(input())
b = list(input())
c = list(input())

t = a.pop(0)
while True:
  if t == "a":
    if a == []:
      print("A")
      exit()
    else: t = a.pop(0)
  elif t == "b":
    if b == []:
      print("B")
      exit()
    else: t = b.pop(0)
  elif t == "c":
    if c == []:
      print("C")
      exit()
    else: t = c.pop(0)

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

/*

dp[1]=0
dp[i]= \max_{j=1}^{i-1} min(dp[j]+(hi-hj)^2+c)
dp[i]= dp[j] + h[i]^2 -2h[i]h[j] + h[j]^2 + c
dp[i] + h[i]^2 - c = dp[j] + h[j]^2 - 2h[i]h[j]

A = dp[i] + h[i]^2 - c
B = dp[j] + h[j]^2
C = 2h[i]

A = B - Ch[j]
B = Ch[j] + A

we want min A

let y = B, x = h[j]

y = Cx + A

*/

typedef long long LL;
const int M=2e5+5;

LL h[M];

LL dp[M];

int n;
LL c;

int qu[M],l,r;

inline LL getdp(int j,int i)
{
	return dp[j]+(h[i]-h[j])*(h[i]-h[j])+c;
}

inline LL y(int i)
{
	return dp[i]+h[i]*h[i];
}
inline bool check(int i,int j,int k)
{
	LL xi=h[i],yi=y(i);
	LL xj=h[j],yj=y(j);
	LL xk=h[k],yk=y(k);
	// (xi-xj)/(yi-yj) >= (xi-xk)/(yi-yk)
	return (xi-xj)*(yi-yk) >= (xi-xk)*(yi-yj);
}

int main()
{
	scanf("%d%lld",&n,&c);
	for(int i=1;i<=n;i++)
		scanf("%lld",&h[i]);
	l=r=0;
	qu[r++]=1;
	for(int i=2;i<=n;i++)
	{
		while(r-l>1&&getdp(qu[l],i)>=getdp(qu[l+1],i))
			l++;
		dp[i]=getdp(qu[l],i);
		while(r-l>1&&check(i,qu[r-1],qu[r-2]))
			r--;
		qu[r++]=i;
	}
	printf("%lld\n",dp[n]);
	return 0;
}

Measured memory_bytes: 4096
#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>;

const int N = 100005;
vector<vector<int>> to(N);
vector<int> used(N,0);

void dfs(int v,int p){
  if(used[v]==1) return;
  used[v]=1;
  for(int u : to[v]){
    if(u==p) continue;
    dfs(u,v);
  }
  return;
};

int main() {
  int n,M;
  cin >> n >> M;
  rep(i,M){
    int x,y,z;
     cin >> x >> y >> z;
     x--;y--;
     to[x].push_back(y);
     to[y].push_back(x);
  }
  int cnt=0;
  for(int i=0;i<n;i++){
    if(used[i]==1) continue;
    dfs(i,-1);cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
#ifdef __DEBUG__
    void debug_out() { cerr << endl; } 
    template <typename Head, typename... Tail>
    void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);}
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 
#endif

using ll = long long int;


inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<ll> A;
inline void input(){
    fast_io();
    cin >> N;
    A = fetch_vec<ll>(N+1);
}

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

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


bool isok(ll p){
    if(A[0]%p) return false;
    if(p<=N){
        vector<ll> AP(p,0);
        for (int i = 0; i <= N; i++) AP[i%(p-1)] += A[i];
        for (int i = 0; i < p; i++) if(AP[i]%p) return false;
    }
    else{
        for (int i = 0; i <= N; i++) if(A[i]%p) return false;
    }
    return true;
}

inline void chmax(ll &a, ll b){if(a<b) a=b;}

int solve(){
    reverse(A.begin(),A.end());
    ll f1 = accumulate(A.begin(),A.end(),0LL);
    if(f1==0) f1 = abs(A[0]);
    // if(f1==0) {
    //     for (int i = 0; i <= N; i++)
    //     {
    //         if(i%2) f1 += A[i];
    //         else f1 -= A[i];
    //     }
    //     f1 = abs(f1);
    // }
    set<ll> ans;
    if(f1!=0){
        auto pf = prime_factor(abs(f1));
        for(auto [p,c]:pf){
            if(isok(p)) ans.insert(p);
        }
    }
    else{
        auto pt = prime_table(N);        
        for (int i = 2; i <= N; i++)
        {
            if(!pt[i]) continue;
            if(isok(i)) ans.insert(i);
        }

        f1 = abs(A[N]);
        auto pf = prime_factor(abs(f1));
        for(auto [p,c]:pf){
            if(isok(p)) ans.insert(p);
        }
    }

    for(auto a:ans) cout << a << endl;
    if(ans.empty()) cout << endl;
    return 0;
}   

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


Measured memory_bytes: 3784
use std::cmp::{max, min};
use std::collections::{HashMap, HashSet, VecDeque};
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let a = read::<i32>();
    let b = read::<i32>();
    println!("{}", vec![a + b, a - b, a * b].iter().max().unwrap())
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
		for (int i=0;i<N;i++) {
			A[i] = sc.nextInt();
			if (map.containsKey(-A[i]+i)) {
				map.put(-A[i]+i, map.get(-A[i]+i)+1);
			} else {
				map.put(-A[i]+i, 1);
			}
		}

		long ans = 0L;
		for (int i=0;i<N;i++) {
			if (map.get(-A[i]+i)>1) {
				map.put(-A[i]+i, map.get(-A[i]+i)-1);
			} else {
				map.remove(-A[i]+i);
			}

			if (map.containsKey(A[i]+i)) ans += map.get(A[i]+i);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 70408
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
// now

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0) : d(n,-1){}
    int Find (int x){//根の番号を探す
        if(d[x] < 0) return x;
        return d[x] = Find(d[x]);
    }
    bool unite (int x, int y){
        x = Find(x); y = Find(y);
        if(x == y ) return false;
        if(d[x] < d[y]){
            swap(x,y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    } 

    bool same(int x, int y){
        return Find(x) == Find(y);
    }
    int size(int x) {
        return (-d[Find(x)]);
    }
};


ll nCr (ll n, ll r){
    ll ans = 1;
    for(ll i = n ; i > n-r ; i --){
        ans *= i;
    }
    for(ll i = 1 ; i<= r; i ++){
        ans /= i;
    }
    return ans ;
}

int nPr (int n,int r){
    int ans = 1;
    for(int i = n ; i > n-r ; i --){
        ans *= i;
    }
    return ans ;
}
 ll modd = 1e9+ 7;
ll wa (ll n,ll mi, ll ma){
    ll ans  = n * (mi+ma) /2;
    return ans;
}
ll kw(ll k,ll n){
    
    ll ans  =0;
    ll mi,ma;
    mi= wa(k,0,k-1);
    
    ma = wa(k,n-k+1,n);
    
    return (ma-mi +1)%modd;
}

int main(){
    int a[1000001];
    int k;
    cin >> k;

    a[1] = 7%k;

    for(int i = 2;i<= k;i++){
        a[i] = (a[i-1] * 10 + 7)%k;
    }

    for(int i = 1;i<=k;i++){
        if(a[i] == 0){
            cout << i <<endl;
            return 0;
        }
    }
    cout << -1 << endl;
}





Measured memory_bytes: 7468
a, b, c, x, y = list(map(int, input().split()))

if x < y:
    if 2 * c < b:
        print(2 * y * c)
    elif b  <= 2 * c <= (a + b):
        print((y - x) * b + 2 * x * c)
    else:
        print(x * a + y * b)
else:
    if 2 * c < a:
        print(2 * x * c)
    elif a <= 2 * c <= (a + b):
        print((x - y) * a + 2 * y * c)
    else:
        print(x * a + y * b)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;


int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int N; cin >> N;
  vector<vector<ll>> A(N, vector<ll>(N));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) cin >> A.at(i).at(j);
  }

  vector<ll> full(1<<N);
  vector<ll> val(1<<N);

  for (int k = 0; k < N; k++) {
    for (int x = 0; x < (1<<k); x++) {
      ll s = full.at(x);
      for (int m = 0; m < k; m++) if ((1<<m) & x) s += A.at(k).at(m);
      full.at((1<<k)|x) = s;
    }
  }
  for (int x = 0; x < 1<<N; x++) {
    ll s = full.at(x);
    int y = x;
    while ((y = x & (y-1)) != 0) {
      int z = x ^ y;
      s = max(s, val.at(y) + val.at(z));
    }
    val.at(x) = s;
  }

  cout << val.at((1<<N) - 1) << endl;
  return 0;
}



Measured memory_bytes: 1280
l=[]
for i in range(3):
  l1=list(map(int,input().split()))
  l.append(l1)
flag=0
y0=l[0][0]-0
y1=l[1][0]-0
y2=l[2][0]-0
x1=l[0][1]-y0
x2=l[0][2]-y0
if l[1][1]==y1+x1 and l[1][2]==y1+x2 and l[2][1]==y2+x1 and l[2][2]==y2+x2:
    flag=1
else:
    pass
if flag==1:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;

bool check(int arg){
    int count=0;
    for(int i=2;i*i<=arg;i++){
        if(arg%i==0){
            if(i%7==1 || i%7 == 6){
                count++;
            }
            if((arg/i)%7 == 1 || (arg/i)%7 == 6){
                count++;
            }
        }
        if(count>1) return false;
    }
    return true;
}

int main(){
    int n;
    while(cin >> n && n != 1){
        vector<int> v;
        for(int i=1;i*i<=n;i++){
            if(n%i==0){
                if(i%7 == 1 || i%7 == 6){
                    if(check(i) && i != 1 && i*i != n){
                        v.push_back(i);
                    }
                }
                if((n/i)%7 == 1 || (n/i)%7==6){
                    if(check(n/i)){
                        v.push_back(n/i);
                    }
                }
            }
        }
        sort(v.begin(), v.end());

        printf("%d:", n);
        for(int i=0;i<v.size();i++){
            printf(" %d", v[i]);
        }
        printf("\n");
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define input(array) repi(array##_itr, array) { cin >> *(array##_itr); }
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
ll mod                = 1e9 +7;
int fix(ll value) { return ((value % 13LL)+13LL)%13; }
int main(){
	string s;

	int ans=0;
	cin >>s;
	Vi trans(s.size() + 2);
	trans[s.size()-1] = 1;
	for (int i = s.size() -2; i >= 0; i--) {
		trans[i] = trans[i + 1] * 10;
		trans[i] %= 13;
	}
	VV dp(s.size(), V(13, 0LL));
	for (int i = 0; i < 10; i++) {
		if (s.back() - '0' == i or s.back() == '?') {
			dp[s.size()-1][i] = 1LL;
		}
	}
	for (int i = s.size()-1; i >0; i--) {
	//	clog << trans[i-1] << endl;
		rep(j, 13) { dp[i][j] %= mod; }

		//
		if (s[i - 1] == '?') {
			for (int val = 0; val < 10; val++) {
			
			    for (int j = 0; j < 13; j++) {
			dp[i - 1][fix(j + trans[i - 1] * val)] +=dp[i][j];
		//	dp[i - 1][fix(j + trans[i - 1] * val)] %= mod;
				}
			}
			continue;
		}
		for (int j = 0; j < 13; j++) {
			dp[i - 1][fix(j + trans[i - 1] * (s[i - 1] - '0'))] += dp[i][j];
	//		dp[i - 1][fix(j + trans[i - 1] * (s[i - 1] - '0'))] %= mod;
		}

		//
	}
	/*
	rep(i, s.size()) {
		rep(j, 13) { clog << dp[i][j] << " "; }
		clog << endl;
	}
	*/
	cout << dp[0][5]%mod << endl;
}

Measured memory_bytes: 16988
//2019/3/15
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int X = sc.nextInt();

		int sum = 0;

		int min = sc.nextInt();

		int a = 0;

		sum += min;

		int ans = N;

		for(int i=1;i<N;i++) {

			a = sc.nextInt();

			sum += a;

			if(a<min) min = a;
		}

		X -= sum;

		while(true) {

			if(X<min) break;

			X -= min;

			ans++;
		}

		System.out.println(ans);
	}

}


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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 1000000007

#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"
#define ff first
#define ss second

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define take(arr,n) REP(i,0,n)cin>>arr[i];
#define print(arr, n) REP(i,0,n)cout<<arr[i]<<" ";
#define printv(v) REP(i,0,v.size())cout<<v[i]<<" ";

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

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

void merge(ll *arr, ll st, ll mid, ll ed, ll maxele){
  ll i=st,j=mid+1,k=st;
  while(i<=mid && j<=ed){
    if(arr[i]%maxele <= arr[j]%maxele){
      arr[k]=arr[k]+(arr[i]%maxele)*maxele;
      k++;
      i++;
    }
    else{
      arr[k]=arr[k]+(arr[j]%maxele)*maxele;
      k++;
      j++;
    }
  }
  while(i<=mid){
    arr[k]=arr[k]+(arr[i]%maxele)*maxele;
    k++;
    i++;
  }
  while(j<=ed){
    arr[k]=arr[k]+(arr[j]%maxele)*maxele;
    k++;
    j++;
  }
  REP(i,st,ed+1)arr[i]=arr[i]/maxele;
}

void mergeSortRec(ll *arr, ll st, ll ed, ll maxele){
  if(st>=ed)return;
  ll mid=(st+ed)/2;
  mergeSortRec(arr,st,mid,maxele);
  mergeSortRec(arr,mid+1,ed,maxele);
  merge(arr,st,mid,ed,maxele);
}

void mergeSort(ll *arr, ll n){
  ll maxele=*max_element(arr,arr+n)+1;
  mergeSortRec(arr,0,n-1,maxele);
}

ll fact(ll n){
  if(n<=1)return 1;
  return ((n%M)*(fact(n-1)%M))%M;
}

int main() {
    fast
    ll t;
    //cin>>t;
    t=1;
    while(t--){
      ll n;
      cin>>n;
      ull arr[n];
      take(arr,n);
      ull dp[n];
      dp[0]=arr[0];
      REP(i,1,n){
        dp[i]=dp[i-1]+arr[i];
      }
      ull sum=0;
      RREP(i,n-1,0){
        sum=(sum%M+(((dp[i]-arr[i])%M)*arr[i]%M)%M)%M;
      }
      cout<<sum;
    }
    return 0;
}


Measured memory_bytes: 6776
import math

def maxHeapify(s):
	#print(s)
	l = s * 2
	r = l + 1

	if l <= main[0] and main[l] > main[s]:
			#print("Left: " +str(main[l]) + ":" + str(l))
			largest = l
	else:
		largest = s
	if r <= main[0] and main[r] > main[largest]:
		#print("Right: "+ str(main[r]) + ":" + str(r))
		largest = r

	if largest != s:
		#print("move node:" + str(largest) + " " + str(main[largest]))

		swa = main[s]
		main[s] = main[largest]
		main[largest] = swa
		maxHeapify(largest)


n = input()

main = list(map(int, input().split()))
main.insert(0,int(n))

#print(main)

del n

for i in range(math.floor(main[0]/2),0,-1):
	#print(i)
	maxHeapify(int(i))

for i in range(1,main[0]+1):
	print(" " + str(main[i]),end="")

print()


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

int arr[102],freq[102];

int main() {
    int x ,n,element;
    cin>>x>>n;


    for(int i=0;i<n;i++){
        cin>>element;
        freq[element]++;
    }


    int j=0;

    for(int i=0;i<=101;i++){
        if(freq[i]==0){
            arr[j]=i;
            j++;
        }
    }


    sort(arr,arr+102);


    int low = *lower_bound(arr,arr+102,x);

    int mini = low-x;
    int ans = low;

    for(int i=0;i<=x;i++){
        if(freq[i]==0){
            if(x-i<=mini){
                ans=i;
            }
        }
    }

    cout<<ans<<endl;


    return 0;
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  vector<ll> sum(n+1, 0);
  for (ll i = 1; i <= n; ++i) {
    for (ll j = 1; i*j <= n; ++j) {
      sum[i*j]++;
    }
  }

  ll ans = 0;
  for (ll i = 1; i <= n; ++i) {
    ans += i*sum[i];
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 81316
A, B, C = sorted(map(int,input().split()))

if A == B and A == C:
    print(0)
    exit()
cnt = 0
cnt += (C - A) // 2
A = ((C - A) // 2) * 2 + A
cnt += (C - B) // 2
B = ((C - B) // 2) * 2 + B

if A == B and A == C:
    print(cnt)
elif A == B and A != C:
    print(cnt+1)
else:
    print(cnt+2)

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

int main(){
  ll n,ans=0;cin>>n;
  if(!(n%2)){
    ans+=n/10;
    n/=10;
    while(n>4){
      ans+=n/5;
      n/=5;
    }
  }
  
  cout<<ans;
}

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

int main()
{
    int n,ct=0;
    cin>>n;

    int v[n];
    int c[n];
    for(int i=0;i<n;i++){cin>>v[i];}
    for(int i=0;i<n;i++){cin>>c[i];}

    for(int i=0;i<n;i++)
    {ct+=max(0,v[i]-c[i]);}
    cout<<ct<<endl;
}


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

using namespace std;
typedef long long ll;

const ll mod = 1e9 + 7;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    ll a = 1, b = 1, c = 1;
    for (int i = 1; i <= n; i++) {
        a *= 10; b *= 8; c *= 9;
        a %= mod; b %= mod; c %= mod;
    }
    cout << ((a + b - 2 * c) % mod + mod) % mod << endl;
    return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n, m; cin >> n >> m;
    vector<ll> num(n+1, 0);
    rep(i, m) {
        ll a, b; cin >> a >> b;
        num[a]++;
        num[b]++;
    }
    bool ok = true;
    rep(i, n+1) {
        if((num[i]%2) != 0) {
            ok = false;
            break;
        }
    }
    if(ok) cout << "YES";
    else cout << "NO";
    cout << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 4052
import java.util.Arrays;
import java.util.Scanner;
import java.util.jar.JarEntry;

public class Main {

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int H = scanner.nextInt();
        final int W = scanner.nextInt();
        final int[][] a = new int[H][W];
        final int[][][] dp = new int[H][W][2];
        for (int i = 0; i < H; i++) {
            final String s = scanner.next();
            for (int j = 0; j < s.length(); j++) {
                a[i][j] = s.charAt(j);
            }
        }
        int ans = 0;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                int sum = 0;
                if (a[i][j] == '#') {
                    continue;
                }
                // horizontal
                if (dp[i][j][0] != 0) {
                    sum += dp[i][j][0];
                } else {
                    int hori = 0;
                    for (int k = j; k < W; k++) {
                        if (a[i][k] == '#') {
                            break;
                        }
                        hori++;
                    }
                    for (int k = j; k < W; k++) {
                        if (a[i][k] == '#') {
                            break;
                        }
                        dp[i][k][0] = hori;
                    }
                    sum += hori;
                }

                // vertial
                if (dp[i][j][1] != 0) {
                    sum += dp[i][j][1];
                } else {
                    int ver = 0;
                    for (int k = i; k < H; k++) {
                        if (a[k][j] == '#') {
                            break;
                        }
                        ver++;
                    }
                    for (int k = i; k < H; k++) {
                        if (a[k][j] == '#') {
                            break;
                        }
                        dp[k][j][1] = ver;
                    }
                    sum += ver;
                }
                ans = Math.max(ans, sum);
            }

        }

        System.out.println(ans - 1);
        
    }
}


Measured memory_bytes: 210480
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <deque>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int p[11],k[11],s[11][11];
int get_bit(int x,int i){return (x>>i)&1;}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++) {
        scanf("%d",&k[i]);
        for (int j = 0; j <k[i];j++)
            scanf("%d",&s[i][j]);
    }
    for(int i=0;i<m;i++)cin>>p[i];
    int sum=0;
    for(int i=0;i<(1<<n);i++)
    {
        int f=0;
        for(int r=0;r<m;r++) {
            int ans=0;
            for(int l=0;l<k[r];l++)
                if (i&(1<<(s[r][l]-1)))
                    ans++;
            if(ans%2==p[r])
            {
                f++;
            }
        }
        if(f==m)
            sum++;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
#define en "\n"
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(v) v.begin(), v.end()
 
using namespace std;
const ll maxn=3e3+100,inf=1e18,LOG=23,mod=1e9 + 7;

#define bt(i) (1 << (i))
#define int ll

int n, m, dp[maxn][maxn], p[maxn][maxn];
string s, t;
char a[maxn], b[maxn];

main()
{
	cin >> s >> t;
	FOR(0, i, s.size())
	{
		a[i + 1] = s[i];
	}
	FOR(0, i, t.size())
	{
		b[i + 1] = t[i];
	}
	n = s.size();
	m = t.size();
	forn(1, i, n)
	{
		forn(1, j, m)
		{
			if(dp[i - 1][j] < dp[i][j - 1])
			{
				dp[i][j] = dp[i][j - 1];
				p[i][j] = 2;
			}
			else
			{
				dp[i][j] = dp[i - 1][j];
				p[i][j] = 1;
			}
			if(a[i] == b[j])
			{
				dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
				if(dp[i][j] == dp[i - 1][j - 1] + 1)
				{
					p[i][j] = 3;
				}
			}
		}
	}
	string ans;
	int cur1 = n;
	int cur2 = m;
	while(cur1 && cur2)
	{
		if(p[cur1][cur2] == 1)
		{
			cur1--;
		}
		else
		if(p[cur1][cur2] == 2)
		{
			cur2--;
		}
		else
		{
			ans += a[cur1];
			cur1--;
			cur2--;
		}
	}
	reverse(all(ans));
	cout << ans;
}

Measured memory_bytes: 149760
#include <iostream>
#include<map>
using namespace std;
typedef long long ll;
ll n,s[26],d[365][26],t[365],ans,u[26],q,a,b,c,MAX=-10000000,L,A[365],M,MM,ok;
int main(void){
    cin>>n;
    for(int i=0;i<26;i++){
        cin>>s[i];
    }
    for(int i=0;i<n;i++){
        M=0;
        for(int j=0;j<26;j++){
            cin>>d[i][j];
            if(M<d[i][j]){MM=j;M=d[i][j];}
        }
        t[i]=MM+1;
    }
    
    
    //for(int i=0;i<n;i++){
    //        t[i]=rand()%26+1;
    ///    }
        
        
    q=200000;
    while(q--){
        a=rand()%n;
        b=rand()%26;
        ans=0;
        for(int i=0;i<26;i++)u[i]=0;
        
        c=t[a];
        t[a]=b+1;
        
        for(int i=0;i<n;i++){
            ans+=d[i][t[i]-1];
            u[t[i]-1]=i+1;
            for(int j=0;j<26;j++){
                ans-=s[j]*(i+1-u[j]);
            }
        }
        if(ok==0){MAX=ans;ok=1;}
        if(MAX<ans){
            MAX=ans;
        }
        else t[a]=c;
    }
    
    for(int i=0;i<n;i++){
        cout<<t[i]<<endl;
    }
    //cout<<MAX<<endl;
}


Measured memory_bytes: 3740
r,c=map(int,input().split())
M=[]
N=[]
S=0
e=0

for i in range(r):
    L=list(input().split())
    for j in range(c):
        S+=int(L[j])
    L.append(S)
    M.append(L)
    S=0
    
for k in range(r):
    d=M[k]
    
    for l in range(c+1):
        if l<c:
            print(d[l],end=' ')
        else:
            print(d[l])
            
for m in range(c+1):
    for n in range(r):
        a=M[n]
        e+=int(a[m])
    if m<c:
        print(e,end=' ')
        e=0
    else:
        print(e)
        e=0
        


Measured memory_bytes: 6684
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main(){

  int x, a, b;
  cin >> x >> a >> b;

  int s = a - b;

  if (s >= 0){
    cout << "delicious" << endl;
  }
  else if ((s < 0) && (x >= abs(s))){
    cout << "safe" << endl;
  }
  else {
    cout << "dangerous" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
//確か、r以下とそれ以外の境界部分のインデックスをうごうごやっていた……気がする。
//書いた当時のことを覚えていないので、誰か解読してください。

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
	int n, m, p, q, r, x, y;
	vector<int>::iterator itx, ity, it;

	while( cin >> n >> m >> p >> q >> r ){
		vector<int> v1, v2;
		v1.push_back(0);
		v1.push_back(r);
		
		for(int i = 0; i < m; ++i){
			cin >> x >> y;
			itx = upper_bound(v1.begin(), v1.end(), x);
			ity = upper_bound(v1.begin(), v1.end(), y);
			
			if( (ity - v1.begin()) % 2 == 0 ){	v2.push_back(0);	}
			v2.push_back(0);

			for(it = ity; it != v1.end(); ++it){
				v2.push_back(*it - y);
			}

			if( (v1.end() - itx) % 2 != 0 ){	v2.push_back(n - y);	}
			for(it = itx; it != ity; ++it){
				v2.push_back(*it - x + n - y);
			}
			
			it = v1.begin();
			if( (ity - v1.begin()) % 2 != 0 ){	++it;	}

			if( v1.size() > 2 && !it[1] ){
				 it += 2;	//重複排除
			}

			if( *it + n - x == v2.back() ){	//重複排除
				++it;
				v2.pop_back();
			}
			for( ; it != itx; ++it){
				v2.push_back(*it + n - x);
			}

			v1.swap(v2);
			v2.clear();
		}

		v1.insert( upper_bound(v1.begin(), v1.end(), p - 1), 2, p - 1);
		v1.insert( lower_bound(v1.begin(), v1.end(), q), q);
		v1.push_back(n);

		it = upper_bound(v1.begin(), v1.end(), p - 1);
		if( (it - v1.begin()) % 2 != 0) --it;

		int ans = 0;
		for( ; *it < q; ++it){
			int prev = *it;
			++it;
			ans += *it - prev;
		}
		
		cout << ans << '\n';
	}
}

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

const int MAX = 101000;

int main() {
    int X,ans=0;
    cin >> X;
    for(int i=1;i<=X;++i) {
        if((i*(i+1)/2) >= X){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b, c, n;
string s, t;


int main()
{
	cin >> n;
	vector<int> A(n),b(n);
	
	rep(i, n)
	{
		cin >> A.at(i);
		b.at(i) = A.at(i);
	}
	sort(all(A));
	reverse(all(A));

	rep(i, n)
	{
		if (b.at(i) != A.at(0))
			cout << A.at(0) << endl;
		else
			cout << A.at(1) << endl;
	}


}


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

using namespace std;
typedef unsigned long long ll;

int main() {
    ll k;
    cin >> k;
    int cnt = 0;
    ll a = 0;
    for (ll i = 1; i <= 1e6; i++) {
        cnt++;
        a *= 10;
        a += 7;
        a %= k;
        if (a == 0) {
            cout << cnt << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


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

using ld = long double;
const ld eps = 1e-8, pi = acos(-1.0);

bool eq(ld a, ld b) {
	return abs(a - b) < eps;
}

using Point = complex<ld>;

class Line {
public:
	Point a, b;
};

ld dot(Point a, Point b) {
	return real(conj(a) * b);
}

ld cross(Point a, Point b) {
	return imag(conj(a) * b);
}

int ccw(Point a, Point b, Point c) {
	b -= a, c -= a;
	if (cross(b, c) > eps) return 1;
	if (cross(b, c) < -eps) return -1;
	if (dot(b, c) < 0) return 2;
	if (norm(b) < norm(c)) return -2;
	return 0;
}

bool isis_ll(Line l, Line m) {
	return abs(cross(l.b - l.a, m.b - m.a)) > eps;
}

bool isis_ls(Line l, Line s) {
	return (cross(l.b - l.a, s.a - s.b) * cross(l.b - l.a, s.b - s.a) < eps);
}

bool isis_lp(Line l, Point p) {
	return abs(cross(l.b - p, l.a - p)) < eps;
}

bool isis_sp(Line s, Point p) {
	return abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps;
}

Point proj(Line l, Point p) {
	ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
	return l.a + t * (l.a - l.b);
}

int main()
{
	int q;
	ld p1x, p1y, p2x, p2y, x, y;
	cout << fixed << setprecision(9);
	cin >> p1x >> p1y >> p2x >> p2y;
	Line l = { (Point) { p1x, p1y }, (Point) { p2x, p2y } };
	cin >> q;
	while (q--) {
		cin >> x >> y;
		Point res = proj(l, (Point) { x, y });
		cout << res.real() << ' ' << res.imag() << endl;
	}
	return 0;
}

Measured memory_bytes: 3328
N = int(input())
A = list(map(int, input().split()))

M = 1000
K = 0

# 0: nothing, 1:buy, 2:sell
flgs = [0] * N
for i in range(N-1):
    if i == 0:
        if A[i] < A[i+1]:
            flgs[i] = 1
        continue
    if A[i] < A[i+1]:
        flgs[i] = 1
    else:
        flgs[i] = 2
flgs[N-1] = 2

for i in range(N):
    flg = flgs[i]
    if flg == 1:
        K += M // A[i]
        M = M % A[i]
    elif flg == 2:
        M += A[i] * K
        K = 0

print(M)


Measured memory_bytes: 9220
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int N, M; cin >> N >> M;
  
  vector<int> ball(N,1);
  set<int> d;
  d.insert(0);

  int x, y;
  rep(i,M){
    cin >> x >> y;
    x--,y--;
    ball[x]--;
    ball[y]++;
    if (d.count(x)) d.insert(y);
    if (ball[x]==0) d.erase(x);
  }

  cout << d.size() << endl;


  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 8296
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9+7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
def check(x,m):
    if m % x:
        return m % x == 1
    return check(x,m//x)

def count(n):
    cnt = 1
    f = defaultdict(int)
    for i in range(2,int(math.sqrt(n))+1):
        if n % i == 0 and f[i] == 0:
            cnt += 1
            f[i] = 1
            if f[n//i] == 0:
                cnt += 1
                f[n//i] = 1
    return cnt

def count2(n):
    cnt = 1
    f = defaultdict(int)
    for i in range(2, int(math.sqrt(n))+1):
        if n % i == 0:
            if check(i,n) and f[i] == 0:
                cnt += 1
                f[i] = 1
            if check(n//i,n) and f[n//i] == 0:
                cnt += 1
                f[n//i] = 1
    return cnt

if n == 2:
    print(1)
    quit()
ans = count(n-1)
ans += count2(n)
print(ans)


Measured memory_bytes: 39408
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) \
    do           \
    {            \
    } while (0)
#define dump(x) \
    do          \
    {           \
    } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;

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

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void solve()
{
    LL k;
    cin >> k;
    LL dd = k / (51 * 50);
    LL baseadd = dd * 51;
    LL rem = k % (51 * 50);
    VLL a(50);
    iota(all(a), baseadd);
    REP(i, 0, rem)
    {
        LL minv = *min_element(all(a));
        for (auto &v : a)
        {
            if (v != minv)
                --v;
            else
                v += 50;
        }
    }
    cout << 50 << endl;
    REP(i, 0, 50)
    {
        if (i)
            cout << " ";
        cout << a[i];
    }
    cout << endl;
}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 256