akhauriyash/Code-Regression huggingface dataset:
//Be Name Khoda, Besmellah Rahmane Rahim, In The Name Of God;
//#include<bits/stdc++.h>
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include <stdio.h>
#include <string.h>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>

using namespace std;

const long long N = 2e3 + 5;
const long long mod = 1e9 + 7;
long long dp[N][N];
long long fact[N * N];
long long n, k;
//dp[i][j] = the number of ways when i zero has come and j colorful ball has come


void pre()
{
	fact[0] = 1;
	for (long long i = 1; i < N * N; i++)
	{
		fact[i] = fact[i - 1] * i;
		fact[i] = fact[i] % mod;
	}
}

long long power(long long a, long long b)
{
	if (!b)
	{
		return 1;
	}
	long long ans = power(a, b / 2);
	ans = ans * ans;
	ans = ans % mod;
	if (b % 2)
	{
		ans = ans * a;
		ans = ans % mod;
	}
	return ans % mod;
}

long long choose(long long a, long long b)
{
	if (a > b)
	{
		return 0;
	}
	long long ans = fact[b];
	ans = ans * power(fact[a], mod - 2);
	ans = ans % mod;
	ans = ans * power(fact[b - a], mod - 2);
	ans = ans % mod;
	return ans;
}


int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	pre();
	cin >> n >> k;
	dp[0][0] = 1;
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= n; j++)
		{
			// the i + j * (k - 1) + 1th ball 
			if (j > i)
			{
				continue;
			}
			if (i == j) // this ball only can be zero
			{
				dp[i + 1][j] += dp[i][j];
				dp[i + 1][j] %= mod;
				continue;
			}
			else
			{
				//this ball is zero
				dp[i + 1][j] += dp[i][j];
				dp[i + 1][j] %= mod;
				// this ball is colorful
				dp[i][j + 1] += dp[i][j] * choose(k - 2, n * k - i - j * (k - 1) - 1);
				dp[i][j + 1] %= mod;
			}
		}
	}
	if (k > 1)
	{
		cout << (dp[n][n] * fact[n]) % mod << endl;
	}
	else
	{
		cout << 1 << endl;
	}

}




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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

void printVec(vector<int>& vec) {
    for (auto& e : vec) {
        cout << e << " ";
    }
    cout << endl;
}

int func(std::string S) {
    // cout << fixed << setprecision(8);

    return 0;
}

int main() {
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if (m2 == m1 + 1 || (m1 == 12 && m2 == 1)) {
        if ((d1 == 31 && d2 == 1 &&
             (m1 == 1 || m1 == 3 || m1 == 5 || m1 == 7 || m1 == 8 || m1 == 10 ||
              m1 == 12)) ||
            (d1 == 30 && d2 == 1 &&
             (m1 == 4 || m1 == 6 || m1 == 9 || m1 == 11)) ||
            (d1 == 28 && d2 == 1 && m1 == 2)) {
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
    } else {
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 

using namespace std;
using namespace __gnu_pbds; 
#define     mod            (int)1e9+7
#define     MOD             998244353
#define     ll              long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     t()             int test;cin>>test;while(test--)
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif


 
int main()
 
{  
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

    IOS;

    int n;
    cin>>n;
    std::vector<ll int> v(n);
    for(auto &i: v )cin>>i;
    map<ll int, ll int> m;
    
    ll sum =0;

    for(auto i: v)
      {
        sum+=i;
        m[i]++;
      }

    int q;
    cin>>q;
    while(q--)
    {
      ll int minus, add;

      cin>>minus>>add;

      sum = sum - m[minus]*minus + m[minus]*add;

      m[add] += m[minus];

      m.erase(minus);

      cout<<sum<<endl;
    }  


    
    
    
  
   
}

Measured memory_bytes: 7956
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

struct UF {
	vector<int>par;//親
	vector<int>Rank;//木の深さ

            UF(int n){init(n);}

	//初期化
	void init(int n) {
		par.resize(n); Rank.resize(n);
		for (int i = 0; i < n; i++) {
			par[i]= i;
			Rank[i] = 0;
		}
	}

	//木の根を求める
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	//xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;//すでに同じ集合に属している

		if (Rank[x] < Rank[y]) {//高さが小さい方を下に
			par[x] = y;
		}
		else {
			par[y] = x;
			if (Rank[x] == Rank[y])Rank[x]++;//同じだとrankが変わらないままになるので増やす（それ以外は大きい方のrankが採用される）
		}
	}

	//xとyが同じ集合に属するかを判定
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

int main() {
	ll n,m;
    cin>>n>>m;
    vector<ll>x(m),y(m),z(m);
    rep(i,m){
        cin>>x[i]>>y[i]>>z[i];
        x[i]--;y[i]--;
        }
    struct UF tree(n+1);
    rep(i,m){
        tree.unite(x[i],y[i]);
    }
    map<int,ll>s;
    for(int i=0;i<n;++i){
        s[tree.find(i)]++;
    }
    cout<<s.size()<<endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int n; cin >> n;
	vector<ll> a(n);
	int ans = 0;
	rep(i, n) {
		cin >> a[i];
		while(a[i] % 2 == 0) {
			a[i] /= 2;
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define MAX 1e9
using namespace std;
int eiei(int a, int b){
    if(a>b) swap(a,b);
    while(b%a!=0 && a!=1){
        b%=a;
        swap(a,b);
    }
    return a;
}
int main(){
    int n;
    int x[100005];
    cin>>n>>x[0];
    for(int i=1;i<n+1;i++) cin>>x[i];
    sort(x,x+n+1);
    int y[100005];
    for(int i=0;i<n;i++){
        y[i]=x[i+1]-x[i];
    }
    if(n==1){
        cout<<y[0]<<endl;
        return 0;
    }
    int a=y[0],b=y[1];
    int ans=eiei(b,a);
    for(int i=2;i<n;i++){
        ans=eiei(ans,y[i]);
    }
    cout<<ans<<endl;
    return 0;
}




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

template<typename T>
vector<pair<T, T>> FACTORIZATION(T x) {
    vector<pair<T, T>> ans;
    for (T i = 2; i * i <= x; i++) {
        if (x % i == 0) {
            T count = 0;
            while (x % i == 0) {
                count++;
                x /= i;
            }
            ans.push_back(make_pair(count,i));
        }
    }
    if (x != 1) ans.push_back(make_pair(1, x));
    return ans;
}

int main(void) {
    int64_t N;
    int64_t remains = 0;
    int loopcnt = 0;
    int ans = 0;
    cin >> N;

    // z = p^e zは2以上(eが正の整数）

    // 素因数分解して最も大きい指数の基数を取ってくる
    // ソートしやすいように後ろが基数
    vector<pair<int64_t,int64_t>> lst = FACTORIZATION(N);
    sort(lst.begin(), lst.end());
//    unordered_set<int64_t> st;

    for(int i=0;i<lst.size();i++) {
        remains += lst[i].first;
    }
    
    // 最初は１個ずつ使っていって、
    for(int i=0;i<lst.size();i++) {
//        st.insert(lst[i].second);
        N /= lst[i].second;
        lst[i].first--;
        remains--;
    }
    ans = lst.size();

    //setにあったら２個以上連続を割る
    if(remains) {
        for(int i=lst.size()-1;i>=0;i--) {
            loopcnt = 2;
            while(lst[i].first >= loopcnt) {
                lst[i].first -= loopcnt;
                N /= pow(lst[i].second,loopcnt);
//                st.insert(make_pair(lst[i].second, loopcnt));
                ans++;
                loopcnt++;
            }
        }
    }

    // ここまでで大分小さくなっているはずなのであとは総当り
    // 組み合わせは考慮不要なのでここまででOKのはず
///    vector<pair<int64_t,int64_t>> lst2 = FACTORIZATION(N);
    cout << ans << endl;
    
    return 0;
}


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

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

#define mod 1000000007
typedef long long ll;

int main() {
    ll ans=0,k;
    cin>>k;
    rept(i,1,k+1){
        rept(j,1,k+1){
            rept(h,1,k+1){
                ans+=gcd(i,gcd(j,h));
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3576
import java.util.*;
import java.math.*;
import java.util.Scanner;
import java.util.Arrays;

public class Main {
	/*static void sort(int[] A,int l,int r) {
		if(l=r) {
			
		}
		sort(A,0,(l+r)/2);
		sort(A,1+ (l+r)/2,r);
		
	}*/

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);
		
		//X+Y+Z=S   0<=X,Y,Z<=K

		int sx=sc.nextInt();
		int sy=sc.nextInt();
		int tx=sc.nextInt();
		int ty=sc.nextInt();
		
		for(int i=0;i<(ty-sy);i++) {
			System.out.print('U');
		}
		for(int i=0;i<(tx-sx);i++) {
			System.out.print('R');
		}	
		for(int i=0;i<(ty-sy);i++) {
			System.out.print('D');
		}
		for(int i=0;i<(tx-sx);i++) {
			System.out.print('L');
		}
		
		System.out.print('L');
		
		
		for(int i=0;i<(ty-sy)+1;i++) {
			System.out.print('U');
		}
		for(int i=0;i<(tx-sx)+1;i++) {
			System.out.print('R');
		}
		
		System.out.print('D');
		System.out.print('R');
		
		for(int i=0;i<(ty-sy)+1;i++) {
			System.out.print('D');
		}
		for(int i=0;i<(tx-sx)+1;i++) {
			System.out.print('L');
		}
		System.out.print('U');

	}

}

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

#define endl '\n'
#define int long long

const int N = 1e5+9;
int cache[N][3], h[N][3], n;

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n;
	for(int i = 1; i <= n; i ++) {
		for(int j = 0; j < 3; j ++) {
			cin >> h[i][j];
		}
	}
	for(int i = 1; i <= n; i ++) {
		for(int j = 0; j < 3; j ++) {
			cache[i][j] = h[i][j] + max(cache[i-1][(j+1)%3], cache[i-1][(j+2)%3]);
		}
	}
	cout << *max_element(cache[n], cache[n]+3) << endl;

	return 0;
}

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

int main(){
  int n;
  int a,b,A,B;

  while(cin >> n,n){
    A = 0; B = 0;
    for(int i=0;i<n;i++){
      cin >> a >> b;
      if(a==b){
	A += a; B += b;
      }else if(a < b){
	B += b+a;
      }else{
	A += a+b;
      }
    }
    cout << A << " " << B << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	int c[26];
	for (int i = 0; i < 26; i++) c[i] = 50;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		int d[26];
		for (int j = 0; j < 26; j++) d[j] = 0;
		for (int j = 0; j < s.size(); j++) {
			d[s[j] - 'a']++;
		}
		for (int j = 0; j < 26; j++) {
			c[j] = min(c[j], d[j]);
		}
	}
	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < c[i]; j++) {
			cout << (char) ('a' + i);
		}
	}
	return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  int d;
  vector<int> B(N);
  for (int i = 0; i < K; i++) {
    cin >> d;
    for (int j = 0; j < d; j++) {
      vector<int> A(d);
      cin >> A.at(j);
      B.at(A.at(j)-1)++;
    }
  }
  
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (B.at(i) == 0) {
      count++;
    }
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

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

int main()
{
  int a, b;
  cin >> a >> b;

  int ans = 0;
  ans = max(ans, 2 * a - 1);
  ans = max(ans, 2 * b - 1);
  ans = max(ans, a + b);

  cout << ans << endl;
}


Measured memory_bytes: 256
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <cctype>
using namespace std;

int main() {
	int W;
	int R;
	while(1){
		R=0;
		cin>>W;
		if(W==-1) break;
		if(W<=10)R=1150;
		else if(W>10&&W<=20)R=1150+(W-10)*125;
		else if(W>20&&W<=30)R=1150+1250+(W-20)*140;
		else if(W>30)R=1150+1250+1400+(W-30)*160;

		cout<<4280-R<<endl;
	}


	return 0;
}

Measured memory_bytes: 3080
$input = $stdin.read.split("\n")
N,M,X = $input.shift.split(" ").map(&:to_i)
$input = $input.map{|line| line.split(" ").map(&:to_i)}


def ok?(ai)
  return false if ai.count == 0
  ai.map{|a| a[1..]}.transpose.all?{|line| line.sum >= X}
end

all = (0...N).to_a
ans = Float::INFINITY
(1..N).each do |r|
  mss = (all.combination(r).to_a)
  mss.each do |ms|
    ai = ms.map{|m| $input[m] }
    cost = ai.map{|a| a.first }.sum
    if ok?(ai)
      ans = [ans,cost].min
    end
  end
end

if ans.infinite?
  puts "-1"
else
  puts ans
end


Measured memory_bytes: 14636
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int n, id, s;
	double h, w, t, tmp;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		
		cin >> s >> h >> w;
		t = (w / (h*h))* 10000 - 22.0;
		
		if(t < 0){
			t = -t;
		}

		for(int i = 1; i < n; i++){
			cin >> id >> h >> w;
			
			tmp = (w / (h*h))*10000 - 22.0;
			if(tmp < 0){
				tmp = -tmp;
			}
			
			if(t > tmp){
				t = tmp;
				s = id;
			}
		}
		
		cout << s << endl;
	}
	
	return 0;
}

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


#define ll long long 


int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n;
    cin>>n;
    
    double p[n+1];
    
    for(ll i = 1; i <= n; i++) cin>>p[i];
    
    
    double dp[n+1][n+1];
    dp[0][0] = 1;
    
    for(int i = 1; i<= n; i++) {
        for(int j = 0; j <= i; j++) {
            if(j == 0) {
                dp[i][j] = dp[i-1][j] * (1 - p[i]);
                continue;
            }
            
            
            if(i == j) {
                dp[i][j] = dp[i-1][j-1] * p[i];
                continue;
            }
            
            
            dp[i][j] = (dp[i-1][j] * (1-p[i]) )+ (dp[i-1][j-1] * p[i] );
            
        }
    }
    
    
    double ans = 0;
    
    for(int j = n/2 + 1; j<= n; j++) ans+= dp[n][j];
    
    cout<<fixed<<setprecision(10)<<ans<<endl;
    
    
	return 0;
}


Measured memory_bytes: 70528
#include<stdio.h>
int main(){
    int x,y,i,a;
    for(i = 0 ; 1 ; i++ ){
        scanf("%d %d",&x,&y);
        if(x==0&&y==0)break;

        if(x>y){
            a=x;
            x=y;
            y=a;
        }
    printf("%d %d\n",x,y);
    }
    return 0;
}

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

using namespace std;

int main(){

  int n,k; cin>>k>>n;

  int a[n];

  for (int i=0; i<n; i++) cin>>a[i];

  int maxr=-1;

  for (int i=0; i<n; i++){

    int d;

    if (i+1==n) d=a[0]+k -a[i];

    else d=a[i+1] - a[i];

    maxr=max(maxr, d);

  }

  cout<<(k-maxr)<<endl;

  return 0;

}



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using Int = int64_t;
using P = pair<Int, Int>;
const Int INF = 1<<30;
const Int MOD = (Int)1e9 + 7;
const Int MAX_N = (Int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
#define debug2(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl;
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int x; cin >> x;
    cout << !x << endl;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;

int main()
{
    string s;
    cin >> s;
    reverse(s.begin(),s.end());

    int flag = 1;
    for(int i = 0; i < s.size(); ){
        string s5 = s.substr(i,5),s6 = s.substr(i,6),s7 = s.substr(i,7);
        if(s5 == "esare") i += 5;        
        else if(s5 == "maerd") i += 5;
        else if(s6 == "resare") i += 6;              
        else if(s7 == "remaerd") i += 7;
        else{flag = 0; break;}
    }

    cout << (flag ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
 
#define vl vector<ll>
#define vi vector<int>
 
#define ff first
#define ss second
 
#define pb push_back
#define MOD 1000000007
//const int nax = 1e6+5;
#define inf 4e18
 
#define display(v) for(int i =0;i<v.size();++i)cout << v[i] << " "
#define all(v) v.begin(),v.end()
ll sqr(ll x){return x*x;}
inline ll add(ll a, ll b){ ll c = a + b; if(c >= MOD) c -= MOD; return c; }
inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
const int nax = 1000*1000 + 10;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL); 
    int n,i; cin>>n;
    for( i =0;i<12;++i){
        if(1000*i >= n)break;
    }
    cout << 1000*i - n ;
    

   
    return 0;
}
    

// Химаншу


Measured memory_bytes: 3652
n=int(input())
satisfis=[0]*n
for i in range(n):
    line=list(map(int,input().split()))
    satisfis[i]=line

max_list=[[0 for i in range(3)] for j in range(n+1)]

for i in range(0,n):
    for j in range(3):
        max_list[i+1][j]=max(max_list[i][(j+1)%3]
        ,max_list[i][(j+2)%3])+satisfis[i][j]

print(max(max_list[-1]))



Measured memory_bytes: 47336
/* _________________________________________________________________________________________________
  |                                                                                                 |
  |                             Author      : Aditya Ahuja                                          |
  |                             Date        : Sun,  4th Aug 2019                                    |
  |_________________________________________________________________________________________________|
*/
 
#include<bits/stdc++.h>
using namespace std;

// #define int long long

#define pb          push_back
#define F           first
#define S           second
#define endl        "\n"
#define rep(i,a,b)  for(int i = a; i < (int)b; i++)
#define req(i,a,b)  for(int i = (int)b - 1; i >= a; i--)
#define all(a)      (a).begin(),(a).end()
#define ret(x)      {cout << x << endl; return;}
#define sz(x)       (int)x.size()
#define type(x)     typeid(x).name()

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

int gcd(int a, int b) {return b?gcd(b,a%b):a;}

#ifdef LOCAL
	#define wa(x)       cerr << (#x) << " --- " << (x) << endl
	#define pvi(v)      {for(auto it:v) cerr << it << " "; cerr << endl;}
	#define line1	    cerr << "---------------------------" << endl;
#else
	#define wa //
	#define line1 //
	#define pvi //
	#define printf //
#endif

void solve();
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout << fixed << setprecision(10);

	int t=1; 
	// cin>>t;
	while(t--) solve();
	return 0;
}

//___________________________________________________________________________________________________


int mod = 1e9+7;
int o(int a){
	return a%mod;
}



void solve() {

	int n,m;
	cin >> n >> m;

	vii g(n,vi(m,1));

	rep(i,0,n){
		rep(j,0,m){
			char t;
			cin >> t;
			if(t == '#') g[i][j] = 0;
		}
	}

	vii dp(n, vi(m,0));

	dp[0][0] = g[0][0];

	rep(i,0,n){
		rep(j,0,m){
			
			if(i+j == 0) continue;
			if(g[i][j] == 0) continue;

			if(i != 0) dp[i][j] = o(dp[i][j] + dp[i-1][j]);
			if(j != 0) dp[i][j] = o(dp[i][j] + dp[i][j-1]);
		}
	}

	for(auto r:dp) pvi(r);

	cout << dp[n-1][m-1] << endl;
}


Measured memory_bytes: 8192
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	int n;
	string s;
	while(cin >> n)
	{
		cin >> s;
		vector<int> r(n+1), g(n+1), b(n+1);
		for(int i=n-1; i>=0; i--)
		{
			r[i] += r[i+1];
			g[i] += g[i+1];
			b[i] += b[i+1];
			if(s[i] == 'R')
				r[i]++;
			else if(s[i] == 'G')
				g[i]++;
			else
				b[i]++;
		}
		long long cnt = 0;
		for(int i=0; i<n-2; i++)
		{
			for(int j=i+1; j<n-1; j++)
			{
				if(s[i] != s[j])
				{
					if((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R'))
					{
						cnt += b[j+1];
						if(2*j-i < n && s[2*j-i] == 'B')
							cnt--;
					}
					else if((s[i] == 'B' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'B'))
					{
						cnt += r[j+1];
						if(2*j-i < n && s[2*j-i] == 'R')
							cnt--;
					}
					else
					{
						cnt += g[j+1];
						if(2*j-i < n && s[2*j-i] == 'G')
							cnt--;
					}
				}
			}
		}

		cout << cnt << '\n';
	}
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
 
int main() {
  int n, m, a, b, ans = 0;
  //string s;
  cin >> n >> m;
  //vector<int> v(n), c(n);
  //if(1) {}
  //((a == b)? "Yes" : "No")
  //for(int i = 0; i < n; i++){}
  cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    string s;cin >> s;
    int k;cin >> k;
    int n = s.size();
    set<string> st;
    for(int i=1;i<=min(10, n);i++){
        for(int j=0;j<n-i+1;j++){
            st.insert(s.substr(j, i));
        }
    }
    vector<string> v;
    for(auto ss : st){
        v.push_back(ss);
    }
    sort(v.begin(), v.end());
    cout << v[k-1] << endl;
    return 0;
}


Measured memory_bytes: 4608
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    h, n = LI()
    a_s = LI()
    if sum(a_s) < h:
        print("No")
    else:
        print("Yes")

if __name__ == '__main__':
    main()

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


int main() {
    int n;

    cin >> n;
    string s;
    for (int i = 0; i < n; i++) {
        string tmp;
        cin >> tmp;

        if (tmp == "A") s += '(';
        else s += ')';
    }

    int a = 0;
    for (auto ch:s) {
        if (ch == '(') {
            a++;
        }
        else {
            a--;
            if (a < 0) {
                cout << "NO" << endl;
                return 0;
            }
        }
    }

    if (a > 0) {
        cout << "NO" << endl;
    }
    else {
        cout << "YES" << endl;
    }


    return 0;
}



Measured memory_bytes: 3180
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N, M; cin >> N >> M;
    vector<vector<long long> > sum(8, vector<long long>(N));
    for (int i = 0; i < N; i++) {
        vector<long long> a(3);
        for (int j = 0; j < 3; j++) cin >> a[j];

        for (int bit = 0; bit < 8; bit++) {
            for (int j = 0; j < 3; j++) {
                if (bit & 1<<j) sum[bit][i] += a[j];
                else sum[bit][i] -= a[j];
            }
        }
    }

    long long ans = -1LL<<60;
    for (int i = 0; i < 8; i++) {
        sort(sum[i].rbegin(), sum[i].rend());
        long long tmp = 0;
        for (int j = 0; j < M; j++) {
            tmp += sum[i][j];
        }
        ans = max(ans, tmp);
    }

    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
#define iof freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define BiEdge(v,a,b) (v)[(a)].pb((b)),(v)[(b)].pb((a))
#define ll long long
#define ld long double
#define pb push_back
#define Pb pop_back
#define F first
#define S second
#define X real()
#define Y imag()
#define pi acos(-1)
#define eps 1e-7
#define bpc __builtin_popcount
#define all(f) (f).begin(),(f).end()
#define allr(f) (f).rbegin(),(f).rend()
#define cross(a,b) (conj(a)*(b)).real()
#define dot(a,b) (conj(a)*(b)).imag()
typedef complex <ld> point ;
typedef vector <point> polygon ;
typedef tuple <ll,ll,ll> line ;
const int mod = 1e9+7 , A = 1e6+1 ;

int main()
{
	ios
	ll n , k ;
	cin >> n >> k ;
	ll dp[n] , a[n] ;
	for (int i = 0 ; i < n ; cin >> a[i++]) ;
	dp[0] = 0 , dp[1] = abs(a[1] - a[0]) ;
	for (int i = 2 ; i < n ; i++)
	{
		ll x ;
		dp[i] = 1e18 ;
		i - k < 0 ? x = 0 : x = i - k ;
		for (int j = i - 1 ; j >= x ; j--)
			dp[i] = min(dp[i] , dp[j] + abs(a[i] - a[j])) ;
	}
	cout << dp[n-1] ;
	return 0 ;
}


Measured memory_bytes: 1792
n,k,*a=map(int,open(0).read().split())
a.sort()
p=a.pop
s=b=~k%2or p()
i=0
while k>1:
 x=a[i]*a[i+1]
 if x*b>a[-1]*a[-2]*b:s*=x;i+=2
 else:s*=p()*p()
 s%=10**9+7;k-=2
print(s)

Measured memory_bytes: 112196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;
ll M=1000000000000000000;
ll a[100010];
int main(void){
    ll n,ans=1;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==0){
            cout<<0<<endl;
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        if(ans>M/a[i]){
            cout<<-1<<endl;
            return 0;
        }
        else ans*=a[i];
    }
    cout<<ans<<endl;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    
    int ans = 0;
    for (int i = 0; i < (int)s.size(); i++)
        if (s[i] != t[i])
            ans++;
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3916
n, t = list(map(int, input().split()))
a = list(map(int, input().split()))

remain_max = [a[-1]]*n
for i in range(1, n):
    remain_max[-(i+1)] = max(a[-i], remain_max[-i])

diffs = [0]*n
for i in range(n):
    diffs[i] = remain_max[i] - a[i]

max_diff = 0
ans = 0
for i in range(n):
    if diffs[i] > max_diff:
        max_diff = diffs[i]
        ans = 1
    elif diffs[i] == max_diff:
        ans += 1

print(ans)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
/*ていればok
*/


int main() {
 ll N,M;
 cin >> N >> M;
 string S,T;
 cin >> S >> T;

 ll g = gcd(N,M);
 bool flag = true;
 for(int i = 0;i<=g-1;i++){
     if(S[i*N/g] != T[i*M/g]){
         flag = false;
         break;
     }
 }
 if(flag) cout << N*M/g << endl;
 else cout << -1 << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main()
{
    vector<int> vw(10), vk(10);
    int a;
    for(int i = 0; i < 10; i++) 
        cin >> vw[i];

    for(int i = 0; i < 10; i++) 
        cin >> vk[i];

    sort(vw.begin(), vw.end(), greater<int>());
    sort(vk.begin(), vk.end(), greater<int>());

    int sw, sk;
    sw = sk = 0;
    for(int i = 0; i < 3; i++) {
        sw += vw[i];
        sk += vk[i];
    }
    cout << sw << " " << sk << endl;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	static int N=(int) 1e5;
	static int n,k;
	static long a[]=new long[N+5];
	static long ans=(long) 2e15;
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		k=sc.nextInt();
		for(int i=1;i<=n;i++) {
			a[i]=sc.nextInt();
		}
		
		int l=0,r=0;
		for(int i=1;i+k-1<=n;i++) {
			l=i;
			r=i+k-1;
			ans=Math.min(ans,a[r]-a[l]+Math.min(Math.abs(a[l]),Math.abs(a[r])));
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 58144
H, W = map(int, input().split())
S = []
for i in range(H):
    r = input()
    S.append(list(r))

def is_kabe(v1, v2):
    if S[v1][v2] == '#':
        return True
    else:
        return False

def bfs(v1, v2):
    m = []
    for i in range(H):
        m.append([None]*W)

    m[v1][v2] = 0
    q = [[v1, v2]]
    while q:
        mass = q.pop(0)
        # print('mass', mass)
        # print('--', m)
        a = mass[0]
        b = mass[1]
        next_cost = m[a][b] + 1
        if a - 1 >= 0:
            up = m[a-1][b]
            if not is_kabe(a-1, b) and up is None:
                m[a-1][b] = next_cost
                q.append([a-1, b])
        if a + 1 < H:
            down = m[a+1][b]
            if not is_kabe(a+1, b) and down is None:
                m[a+1][b] = next_cost
                q.append([a+1, b])
        if b - 1 >= 0:
            left = m[a][b-1]
            if not is_kabe(a, b-1) and left is None:
                m[a][b-1] = next_cost
                q.append([a, b-1])
        if b + 1 < W:
            right = m[a][b+1]
            if not is_kabe(a, b+1) and right is None:
                m[a][b+1] = next_cost
                q.append([a, b+1])

    # print('---')
    # for i in range(H):
    #     for j in range(W):
    #         if m[i][j] is None:
    #             print('-', end=' ')
    #         else:
    #             print(m[i][j], end=' ')
    #     print()

    mx = 0
    for i in range(H):
        for j in range(W):
            cost = m[i][j]
            if cost is not None:
                mx = max(mx, cost)
    return mx


r = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        x = bfs(i, j)
        r = max(r, x)
print(r)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, cnt, ans;
int a[N];
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for(int i = 1; i <= n + 1; ++i)
	{
		if(a[i] == i) ++cnt;
		else if(cnt)
		{
			ans += (cnt + 1) >> 1;
			cnt = 0;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>

int N;
long long A[100010];
long long B[100010];

void solve()
{
	int i;
	long long res = 0;
	long long add = 0;
	for(i=N-1; i>=0; i--){
		A[i] += add;
		if(A[i] % B[i] == 0)
			continue;
		long long n1= A[i] / B[i];
		long long tmp = (n1+1) * B[i] - A[i];
		res += tmp;
		add += tmp;
	}
	printf("%lld\n", res);
}

int main()
{
	int i;
	scanf("%d", &N);
	for(i=0; i<N; i++){
		scanf("%lld %lld", &A[i], &B[i]);
	}
	solve();
	return 0;
}

Measured memory_bytes: 1664
n = int(input())
parent = [-1]*n
depth = [0]*n
height = [0]*n
G = [[-1, -1] for _ in range(n)]
for i in range(n):
    id, *g  = map(int, input().split())
    G[id] = g
    for child in g:
        if child != -1:
            parent[child] = id

def dfs(r, d):
    if r == -1:
        return -1
    depth[r] = d
    height[r] = max(dfs(G[r][0], d + 1), dfs(G[r][1], d + 1)) + 1
    return height[r]

for i in range(n):
    if parent[i] == -1:
        dfs(i, 0)
        break

for i in range(n):
    T = ''
    if parent[i] == -1:
        T = 'root'
    elif G[i][0] == G[i][1] == -1:
        T = 'leaf'
    else:
        T = 'internal node'
    sibling = -1
    if parent[i] != -1:
        for child in G[parent[i]]:
            if child != i:
                sibling = child
    degree = (G[i][0] != -1) + (G[i][1] != -1)
    print(f'node {i}: parent = {parent[i]}, sibling = {sibling}, degree = {degree}, depth = {depth[i]}, height = {height[i]}, {T}')



Measured memory_bytes: 5632
import math

a,b,h,m=map(int,input().split())
# y/60 = x/360
x=abs(h*5+(5*(m/60))-m)*6
x=min(x,360-x)
# c^2=a^2+b^2-2ab cosC
print(math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(x))))


Measured memory_bytes: 62380
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)*}
    };
}

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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

//
// # Examples
//
// # integers
// input! { n: usize, m: usize, ... }
//
// # array
// input! { n: usize, v: [i32; n], }
//
// # matrix
// input! { n: usize, m: usize, mat: [[]] }
//
// # string
// input! { s: chars }

// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: usize,
//     w: usize,
//     board: [chars; h],
// }


fn main() {
    input!{
        h: usize,
        w: usize,
        mat: [[i32; w]; h],
    }
    let mut mat = mat;
    let mut ans = Vec::new();
    for y in 0..h {
        for x in 0..w {
            if mat[y][x] % 2 == 1 {
                if x < w-1 {
                    mat[y][x] -= 1;
                    mat[y][x+1] += 1;
                    ans.push((y,x,y,x+1));
                } else if y < h-1 {
                    mat[y][x] -= 1;
                    mat[y+1][x] += 1;
                    ans.push((y,x,y+1,x));
                }
            }
        }
    }
    println!("{}", ans.len());
    for (y, x, yy, xx) in ans {
      println!("{} {} {} {}", y+1, x+1, yy+1, xx+1);
    }
}


Measured memory_bytes: 12788
import java.util.Scanner;

public class Main
{

	// 絶対値を求める関数
	static int abs(int a)
	{
		if (a < 0) {
			a = -a;
		}
		return a;
	}

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);

		int a[] = new int[1000];

		int n = sc.nextInt();
		
		while (n > 0) {
			int best = 1000000;
			
			for (int i = 0;i < n;i++) {
				a[i] = sc.nextInt();
			}

			for (int i = 0;i < n;++i) {
				for (int j = i + 1;j < n;++j) {
					if (abs(a[i] - a[j]) < best) {
						best = abs(a[i] - a[j]);
					}
				}
			}
			
			System.out.println(best);

			n = sc.nextInt();
		}
	}
}



Measured memory_bytes: 46572
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int T = 1; 
    // cin >> T; 
    while (T--) {
        int n;
        cin >> n;

        int ans = 1000 * (n / 500);
        n %= 500;
        ans += 5 * (n / 5);
        cout << ans << '\n';
        
    }
    
    return 0;
}



Measured memory_bytes: 3516
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  long long a, b, x;

  std::cin >> a >> b >> x;

  long long l = (a + x - 1) / x * x, u = b / x * x;

  if (l <= u) {
    std::cout << u / x - l / x + 1 << std::endl;
  }
  else {
    std::cout << 0 << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
c=-1
d=0
f=0
g=0
N, M = map(int, input().split())
list = []
for i in range(M):
    a,b=input().split()
    list.append((int(a), int(b)))

for i in range(M):
	
	if list[i][0]>N or (list[i][0]+list[i][1]==1 and N!=1):
		print(c)
		f=1
		break
	for j in range(i+1,M):
		if list[i][0]==list[j][0]:
			g=1
			if list[i][1]!=list[j][1]:
				print(c)
				f=1
				break
	if f==1:
		break
	if g==0:
		d+=list[i][1]*(10**(N-list[i][0]))
	g=0
if f==0:
	if (d-10**(N-1)<0 and N!=1) or (d==0 and N!=1):
		print(d+10**(N-1))
	else:
		print(d)

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
void trace(int n, int arr[]){for(int i = 0; i < n; i++){cout << arr[i] << " ";} cout << endl << endl;}
const int N = 21, mod = 1e9 + 7;
ll n, dp[N + 2][(1 << 21) + 3], arr[N + 2][N + 2];
ll solve(int idx, int msk){
    if(idx >= n)
        return 1;
    if(dp[idx][msk] != -1)
        return dp[idx][msk];
    ll ans = 0;
    for(int i = 0; i < n; i++)
        if(arr[idx][i] && !((msk >> i) & 1))
            ans = (ans + (solve(idx + 1, (msk | (1 << i))) % mod)) % mod;
    dp[idx][msk] = ans;
    return ans;
}
int main()
{
    Hello
    cin >> n;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> arr[i][j];
    memset(dp, -1, sizeof dp);
    cout << solve(0, 0);
    return 0;
}

Measured memory_bytes: 380460
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
/**************************************************************************/
const int N = 1e5+2;
signed main()
{
    fast;
    int n;
    cin>>n;
    int a[n+1];
    int neg = 0;
    int sum = 0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum+=abs(a[i]);
        if(a[i]<0)
            neg++;
        a[i] = abs(a[i]);
    }
    sort(a+1,a+1+n);
    if(neg&1)
        cout<<sum-2*a[1];
    else cout<<sum;
    return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int n = 32 - Integer.numberOfLeadingZeros(l);
		int sum = 0;
//		System.err.println(n + " " + Integer.numberOfLeadingZeros(l - 1));
		ArrayList<Edge> edges = new ArrayList<>();
		for(int i=0;i<n-1;i++) {
			edges.add(new Edge(n-1-i,n-i,0));
			edges.add(new Edge(n-1-i,n-i,1<<i));
		}
		sum += 1 << (n - 1);
//		System.err.println(l);
		for(int i=0;i<=n-2;i++) {
			if ((l >> i & 1) == 1) {
				edges.add(new Edge(1,n-i,sum));
				sum += 1 << i;
			}
		}
		System.out.println(n + " " + edges.size());
		for(Edge e: edges) {
			System.out.println(e.u + " " + e.v + " " + e.c);
		}
	}

	static class Edge {
		int u,v,c;

		public Edge(int u, int v, int c) {
			super();
			this.u = u;
			this.v = v;
			this.c = c;
		}
		
	}
}


Measured memory_bytes: 23124
#include<stdio.h>
#include<iostream>
#include <utility>
#include<stack>
#include<cstdio>
using namespace std;

int field[51][51];
int w,h;

void land(int x,int y){
	stack<pair<int,int> > field2;
	int dx[]={1,1,1,-1,-1,-1,0,0},dy[]={1,0,-1,1,0,-1,1,-1};
	int xx,yy,flag,stka=1;

	field2.push(pair<int,int>(x,y));
	field[x][y]=0;

	while(1){
		flag=0;
		for(int i=0;i<9;i++){
			if(field2.top().first+dx[i]>=0&&field2.top().first+dx[i]<=w&&field2.top().second+dy[i]>=0&&field2.top().second+dy[i]<=h){
				if(field[field2.top().first+dx[i]][field2.top().second+dy[i]]==1){
					xx=field2.top().first+dx[i],yy=field2.top().second+dy[i];
					field[field2.top().first+dx[i]][field2.top().second+dy[i]]=0;
					field2.push(pair<int,int>(xx,yy));
					stka+=1;
					flag=1;
					break;
				}
			}
		}
		if(flag==0){
			field2.pop();
			stka--;
			if(stka==0){
				break;
			}
		}
	}
	return;
}

int main(void){

	int kazu=0;

	while(1){

	scanf("%d %d",&w,&h);

	if(w==0&&h==0) break;

	kazu=0;

	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			scanf("%d",&field[j][i]);
		}
	}

	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){

			if(field[j][i]==1){
				land(j,i);
				kazu++;
			}

		}
	}

	printf("%d\n",kazu);
	}

	return 0;
}

Measured memory_bytes: 1236
#include<iostream>
using namespace std;
int main()
{
    char a=getchar(),b,c;
    int ans=-3;
    putchar(a);
    while(a!=EOF)
    {
        ans++;
        c=b;
        b=a;
        a=getchar();
    }
    cout<<ans;
    putchar(c);
    puts("");
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace _102_2
{
    class Program
    {
        static void Main(string[] args)
        {
			int N = int.Parse(Console.ReadLine());
			string[] aST = Console.ReadLine().Split();
			int[] a = new int[N];
			for (int i = 0; i < N; i += 1)
			{
				a[i] = int.Parse(aST[i]);
			}
			Array.Sort(a);
			Console.WriteLine(a[N - 1] - a[0]);

        }
    }
}


Measured memory_bytes: 11220
# include <stdio.h>
# include <string.h>
# include <iostream>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int M = 300 + 10;
int n, K, mod;
int C[M][M], f[M][M], s[M][M];

int main() {
//  freopen("seq.in", "r", stdin);
//  freopen("seq.out", "w", stdout);
  cin >> n >> K >> mod;
  C[0][0] = 1;
  for (int i = 1; i <= n; ++ i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++ j) {
      C[i][j] = C[i-1][j-1] + C[i-1][j]; 
      if (C[i][j] >= mod) C[i][j] -= mod;
    }
  }
  for (int i = 0; i <= K; ++ i) f[1][i] = 1;
  for (int i = K; ~i; -- i) {
    s[1][i] = s[1][i + 1] + f[1][i];
    if(s[1][i] >= mod) s[1][i] -= mod;
  }
  for (int i = 2; i <= n+1; ++ i) {
    for (int j = 0; j <= K; ++ j)
      for (int k = 1; k < i; ++ k) {
        f[i][j] += 1ll * f[i-k][j] * s[k][j+1] % mod * C[i-2][k-1] % mod;
        if(f[i][j] >= mod) f[i][j] -= mod;
      }
    for (int j = K; ~j; -- j) {
      s[i][j] = s[i][j+1] + f[i][j];
      if(s[i][j] >= mod) s[i][j] -= mod;
    }
  } 
  cout << f[n+1][0] << endl;
  return 0;
}




Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 1e9+7;
ll fac[900100];
ll inv[900100];
ll facinv[900100];
void C_init(){
    fac[0] = 1;
    for(int i = 1;i < 900100;i++)fac[i] = (fac[i-1] * i)%mod;
    inv[1] = 1;
    for(int i = 2;i < 900100;i++)inv[i] = ((-(mod/i)*inv[mod%i])%mod+mod)%mod;
    facinv[0] = 1;
    for(int i = 1;i < 900100;i++)facinv[i] = (facinv[i-1] * inv[i])%mod;
    return;
}
ll nCr(ll n, ll r){
    return max((ll)0,((fac[n] * facinv[n-r])%mod * facinv[r])%mod);
}
int main() {
  ll x, y, cnt_x = 0, cnt_y = 0;
  cin >> x >> y;
  while (x*y >= 2) {
    if (x < y) {
      x--;
      y-=2;
      cnt_y++;
    }
    else {
      x-=2;
      y--;
      cnt_x++;
    }
  }
  
  ll ans = 0;
  if (x == 0 && y == 0) {
    C_init();
    ans = nCr(cnt_x + cnt_y, cnt_x);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 21376
#include <bits/stdc++.h>
#define repi(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)
#define rep(i, n) repi(i, 0, n)
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
struct Vec{
    double x, y;
};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
     return false;
}
template<class T>
T min(T a, T b)
{
    if (a < b) return a;
    return b;
}
template<class T>
T max(T a, T b)
{
    if (a > b) return a;
    return b;
}
using namespace std;
int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    int N,ans = 0;
    ll D;
    cin >> N >> D;
    ll dis;
    rep(i, N){
        ll x, y;
        cin >> x >> y;
        dis = x*x + y*y;
        if (dis <= D*D) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3668