akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
using namespace std ; 
#define ll long long int 
#define pb push_back
#define ff first 
#define dobara(i,a,b) for(int (i) = (a); (i) < (b); (i)++)
#define ss second 
#define S(x) scanf("%d",&x) 
#define SL(x) scanf("%lld",&x)
#define M 1000000007
#define sz(x) (int)x.size()
#define all(a) (a).begin(),(a).end()

int arr[55] , pos[55] , n ; 

int main(){
	cin>>n ; 

	for(int i=1;i<=n;i++){
		cin>>arr[i] ; 
		pos[arr[i]] = i ;
	}
	int cnt = 0 ; 

	for(int i=1;i<=n;i++){
		if(pos[arr[i]] != arr[i]){
			cnt++ ; 
		}
	} 

	if(cnt == 0 || cnt == 2){
		cout<<"YES\n" ; 
	}
	else{
		cout<<"NO\n" ; 
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef pair<int,int> P;
typedef long long ll;
int h,w;
int a[600][600];

struct axis{
    int x1;
    int y1;
    int x2;
    int y2;
};

int main(void){
    cin>>h>>w;
    vector<axis>p;
    int i,j,num=0;
    for(i=1;i<=h;i++){
        for(j=1;j<=w;j++){
            cin>>a[i][j];
        }
    }
    i=1,j=1;
    while(num!=h*w){
        if(i%2==1){
            for(j=1;j<=w;j++){
                if(num==h*w-1){
                    num++;
                    break;
                }

                if(a[i][j]%2==1){
                    if(j==w){
                        p.push_back({i,j,i+1,j});
                        a[i][j]--;
                        a[i+1][j]++;
                    }
                    else{
                        p.push_back({i,j,i,j+1});
                        a[i][j]--;
                        a[i][j+1]++;
                    }
                    num++;
                }
                else num++;
            }
            i++;
        }
        else{
            for(j=w;j>=1;j--){
                if(num==h*w-1){
                    num++;
                    break;
                }
                if(a[i][j]%2==1){
                    if(j==1){
                        p.push_back({i,j,i+1,j});
                        a[i][j]--;
                        a[i+1][j]++;
                    }
                    else{
                        p.push_back({i,j,i,j-1});
                        a[i][j]--;
                        a[i][j-1]++;
                    }
                    num++;
                }
                else num++;
            }
            i++;
        }
    }
    cout<<p.size()<<endl;
    for(auto itr=p.begin();itr!=p.end();++itr){
        cout<<itr->x1<<" "<<itr->y1<<" "
            <<itr->x2<<" "<<itr->y2<<endl;
    }
    return 0;
}

Measured memory_bytes: 5360
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
vector<int> g[111111];
map<pair<int, int>, int> m;
void dfs(int now, int from, int used) {
    int col = 1;
    each(i, g[now]) {
        if(i != from) {
            if(col == used) {
                col++;
            }
            m[{now, i}] = col;
            dfs(i, now, col);
            col++;
        }
    }
}
signed main() {
    INCANT;
    int n, a, b;
    vector<pair<int, int>> gg;
    cin>>n;
    rep(i, n - 1) {
        cin>>a>>b;
        a--, b--;
        g[a].push_back(b);
        gg.push_back({a, b});
    }
    dfs(0, -1, -1);
    set<int> an;
    each(p, gg) {
        an.insert(m[p]);
    }
    cout<<an.size()<<endl;
    each(p, gg) {
        cout<<m[p]<<endl;
    }
}


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

int main(){
  ll N,K,x,t;
  cin >> N >> K;
  vector<ll> A(N),F(N);
  rep(i,N) cin >> A.at(i);
  rep(i,N) cin >> F.at(i);
  sort(A.begin(),A.end());
  sort(F.begin(),F.end());
  x=(ll)pow(2,39);
  t=38;
  while(t>=0){
    ll k=0;
    rep(i,N){
      if(A.at(i)>x/F.at(N-i-1)){
        k+=A.at(i)-x/F.at(N-i-1);
      }
    }
    if(k<=K){
      x-=(ll)pow(2,t);
      t--;
    }else{
      x+=(ll)pow(2,t);
      t--;
    }
  }
  ll k=0;
  rep(i,N){
    if(A.at(i)>x/F.at(N-i-1)){  
      k+=A.at(i)-x/F.at(N-i-1);
    }
  }
  if(k>K){
    x++;
  }
  k=0;
  rep(i,N){
    k+=A.at(i);
  }
  if(k<=K){
    x=0;
  }
  cout << x << endl;
}


Measured memory_bytes: 3328
from heapq import heappush, heappop

def input(f):
    n, = map(int, f.readline().split())
    s = [None for _ in range(n-1)]
    t = [None for _ in range(n-1)]
    w = [None for _ in range(n-1)]
    for i in range(n-1):
        s[i], t[i], w[i] = map(int, f.readline().split())
    return n, s, t, w

def solve(n, s, t, w):
    graph = [[] for _ in range(n)]
    def add_edge(src, dst, w):
        graph[src].append((dst, w))
        graph[dst].append((src, w))
    for i in range(n-1):
        add_edge(s[i], t[i], w[i])
    
    queue = []
    
    def find(root):
        INF = 100000 * 1000 + 1;
        best = [INF for _ in range(n)]
        best[root] = 0
        
        def find_next(cur):
            for nxt_v, nxt_w in graph[cur]:
                dist = best[cur] + nxt_w
                if dist < best[nxt_v]:
                    best[nxt_v] = dist
                    yield dist, nxt_v
        
        def dequeue():
            _, cur_v = heappop(queue)
            for nxt in find_next(cur_v):
                heappush(queue, nxt)
        
        while queue:
            dequeue()

        res = (0, root)
        for i in range(n):
            if best[i] > res[0]:
                res = (best[i], i)
        return res, best
    
    def run(root):
        heappush(queue, (0, root))
        return find(root)
    
    ret0, best0 = run(0)
    ret1, best1 = run(ret0[1])
    ret2, best2 = run(ret1[1])
    
    for i in range(n):
        yield max(best1[i], best2[i])

with open('/dev/stdin') as f:
    for d in solve(*input(f)):
        print(d)


Measured memory_bytes: 10120
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {
    int n;
    long int l[1000];
    int i, j, k;
    int ans=0;
    scanf("%d", &n);
    for (i=0;i<n;i++) scanf("%ld", &l[i]);
    for (i=0;i<n;i++) {
        for (j=i+1;j<n;j++) {
            for (k=j+1;k<n;k++) {
                if (i!=j&&j!=k&&i!=k) {
                    if (l[i]!=l[j]&&l[j]!=l[k]&&l[i]!=l[k]) {
                        long int a, b, c;
                        a=l[i];
                        b=l[j];
                        c=l[k];
                        if (a+b>c&&b+c>a&&c+a>b) {
                            ans++;
                            //printf("%d %d %d\n", i+1,j+1,k+1);
                        }
                    }
                }
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1740
#include <iostream>
#include <cmath>

using namespace std;

#define MAX_N 100000

int n, k, a[MAX_N];
int ans;

void solve()
{
    ans = ceil((float)(n-1)/(k-1));
}

int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) {
        int temp;
        scanf("%d", &temp);
        a[i] = temp;
    }

    solve();

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <set>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
#include <iostream>
#include <ctime>
#include <unistd.h>

using namespace std;

#define TRACE(x) cerr << #x <<  " = " << x << endl
#define _ << " " <<
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)

#define X first
#define Y second

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

int cnt[3];

string rek(vector <pair<string, int> > V) {
  //  TRACE(V.size());
  
  if (V.size() == 1) {
    string ret = "";
    REP(i, V[0].Y)
      ret += V[0].X;

    return ret;
  }  
  
  multiset <string> S;
  REP(i, V[0].Y)
    S.insert(V[0].X);

  for (int i=(int) V.size()-1; i; i--) {
    REP(j, V[i].Y) {
      auto it = S.begin();
      string tmp = *it;
      S.erase(it);
      tmp += V[i].X;
      S.insert(tmp);
    }
  }

  //  TRACE(S.size());

  vector <pair<string, int> > T;
  for (multiset <string> :: iterator it = S.begin(); it != S.end(); ) {
    int kol = 0;
    multiset <string> :: iterator it2 = it;
    for (; it2 != S.end() && *it2 == *it; it2++, kol++);
    T.push_back({*it, kol});
    it = it2;
  }

  return rek(T);
}

int main()
{
  int n=0;
  REP(i, 3) {
    scanf("%d", &cnt[i]);
    n += cnt[i];
  }

  vector <pair<string, int> > V;
  REP(i, 3) {
    if (cnt[i]) {
      string tmp = "";
      tmp.push_back((char) ('a' + i));
      V.push_back({tmp, cnt[i]});
    }
  }

  cout << rek(V) << endl;
    
  return 0;
}


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

#define ll long long
#define ull unsigned long long

#define	max	(ll)(1e9 + 7)

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

struct UnionFind
{
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<int> childN;
	ll r = 0;

	UnionFind(int N) : par(N), childN(N)
	{
		//最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++)
			par[i] = i, childN[i] = 1;
	}

	int root(int x)
	{
		// データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y)
	{
		// xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		r -= childN[rx] * (childN[rx] - 1) / 2;
		r -= childN[ry] * (childN[ry] - 1) / 2;
		childN[ry] += childN[rx];
		childN[rx] = 0;
		r += childN[ry] * (childN[ry] - 1) / 2;
	}

	bool same(int x, int y)
	{
		// 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//	for priority queue
//	priority_queue<ipair, vector<ipair>, greater<ipair>>
using ipair = pair<int, pair<int, int>>;
bool operator>(const ipair a, const ipair b) { return a.first > b.first; };
bool operator<(const ipair a, const ipair b) { return a.first < b.first; };

using xpair = pair<int, int>;
bool operator>(const xpair &a, const xpair &b) { return a.second > b.second || (a.second == b.second && a.first > b.first); };
bool operator<(const xpair &a, const xpair &b) { return a.second < b.second || (a.second == b.second && a.first > b.first); };
bool operator==(const xpair &a, const xpair &b) { return a.first == b.first; };

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

	ull r = n * (n + 1) / 2;

	for (int i = 2; i <= n; i++)
	{
		ull p = n / i;
		ull q;
		if (p % 2 == 0)
		{
			q = p / 2;
			q *= (p + 1);
		}
		else
		{
			q = (p + 1) / 2;
			q *= p;
		}
		r += q * i;
	}

	printf("%lld", r);
	return 0;
}


Measured memory_bytes: 3252
def ascan; gets.split.map(&:to_i); end


while (n,m = ascan) != [0,0]
    xx = n.times.map{gets.to_i}
    yy = m.times.map{gets.to_i}
    
    ans = nil
    
    xsum = xx.reduce(:+)
    ysum = yy.reduce(:+)
    
    n.times do |i|
        m.times do |j|
            x = xx[i]
            y = yy[j]
            ans = [x,y]if xsum-2*x == ysum-2*y && (!ans || ans[0]+ans[1] > x+y)
        end
    end
    puts ans ? ans*" " : "-1"
end


Measured memory_bytes: 6884
import itertools
import sys
import numpy as np
INF = float("inf")
N, M, X = list(map(int, sys.stdin.buffer.readline().split()))
A = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]
 
A = np.array(A, dtype=int)
mat = A[:, 1:]
C = A[:, 0]
 
ans = INF
for choices in itertools.product((True, False), repeat=N):
    choices = np.array(list(choices), dtype=bool)
    if np.all(mat[choices, :].sum(axis=0) >= X):
        ans = min(ans, C[choices].sum())
if ans == INF:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 27212
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

char in[200050];
ll cnt[26];
int main() {
	scanf("%s", in);

	int i, j;
	for (i = 0; in[i] != 0; i++) cnt[in[i] - 'a']++;

	int N = strlen(in);

	ll ans = 0;
	for (i = 0; i < 26; i++) ans += cnt[i] * (N - cnt[i]);
	ans /= 2;
	printf("%lld\n", ans + 1);
	return 0;
}

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

//イコールがあるのでビット全探索ではない
//再帰で書くのでここに書いておく
int N,M,Q;
int a[55],b[55],c[55],d[55],A[10];
int ans=0;

void check(){
  int sum=0;
  for (int i=0;i<Q;i++)
  {
    if (A[b[i]]-A[a[i]]==c[i]){
       sum += d[i];
    }
  }
  ans = max(sum,ans); 
}
  

//深さ優先探索
void dfs(int depth)
{
  if (depth==0){
    for (int i=1;i<=M;i++){
       A[0]=i;
       dfs(1);
    }
  }
  else if(depth==N){
    check();
  }
  else{
    for (int i=A[depth-1];i<=M;i++){
      A[depth] = i;
      dfs(depth+1);
    }
  }
}

int main()
{
  cin>>N>>M>>Q;
  for (int i=0;i<Q;i++)
  {
    cin>>a[i]>>b[i]>>c[i]>>d[i];
    a[i]--;b[i]--;
  }
  dfs(0);
  cout<<ans<<endl;
}

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

typedef long long LL;
//A 难吃解毒
//B 好吃解毒
//C 好吃有毒
int main()
{
    LL A,B,C;
    cin >> A >> B >> C;
    LL res = 0;
    if(A+B >= C)
        res = B + C;
    else
        res = B + A + B + 1;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(string, a, b);

	if (a.size() > b.size()) {
		OUT("GREATER")BR;
		return 0;
	} else if (a.size() < b.size()) {
		OUT("LESS")BR;
		return 0;
	} else {
		if (a == b) {
			OUT("EQUAL")BR;
		} else if (a > b) {
			OUT("GREATER")BR;
		} else {
			OUT("LESS")BR;
		}
	}
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
double arr[50009],brr[50009];
double k;
double g;
double permute(string s, int l, int r)
{
    if (l == r)
    {
        for(int i=1; i<s.size(); i++)
        {
            int j=s[i]-'0';
            int x=s[i-1]-'0';
            k=k+sqrt(((arr[j]-arr[x])*(arr[j]-arr[x]))+((brr[j]-brr[x])*(brr[j]-brr[x])));
        }
        g=g+1.0;
    }
    else
    {
        for (int i = l; i <= r; i++)
        {
            swap(s[l], s[i]);
            permute(s, l+1, r);
            swap(s[l], s[i]);
        }
    }
    return k;
}
int main()
{
    int a;
    double z,y;
    cout<<fixed<<setprecision(12);
    string str = "";
    cin>>a;
    for(int i=1; i<=a; i++)
    {
        cin>>arr[i]>>brr[i];
        str+=(i+'0');
    }
    int n = str.size();
    z=permute(str, 0, n-1);
    cout<<(z/g)<<endl;
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[allow(unused_macros)]
macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

fn main() {
    input! {
        x: usize,
    }

    let mut base = 100;
    let mut years = 0;

    while base < x {
        base += base / 100;
        years += 1;
    }

    echo!(years);
}


Measured memory_bytes: 2156
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define all(V) (V).begin(), (V).end() 
using namespace std;
typedef long long ll;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;

// template <typename T>
// using ost = tree<T, null_type, less <T>, 
// rb_tree_tag, tree_order_statistics_node_update>;

// template <typename T>
// int lessThan(ost <T> &ds, T v) {
//     return ds.order_of_key(v);
// }

// template <typename T>
// T getKth(ost <T> &ds, int k) {
//     if(k >= ds.size() || k < 0) {
//         cerr << "Out of bounds of ost\n";
//         assert(false);
//     }
//     return *ds.find_by_order(k);
// }
int main() {fio;
	int n;
	cin >> n;
	vector <int> p(n), a(n);
	for(int i = 0; i < n; i++) {
		int u;
		cin >> u;
		a[i] = u;
		p[i] = i;
	}
	sort(all(p), [&](int i, int j){
		return a[i] < a[j];
	});
	int ans = 0;
	for(int i = 0; i < n; i++) {
		if((p[i] - i + 2 * n) % 2) {
			ans++;
		}
	}
	assert(ans % 2 == 0);
	cout << ans / 2;
	return 0;
}

Measured memory_bytes: 3972
/**
 * @author: shashankchdhry
 * @made:   2020-04-06 10:56:00 
**/
#include <bits/stdc++.h>

using namespace std;

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

    string o, e;
    cin >> o >> e;

    int m = o.length(), n = e.length();

    string ans;
    for (int i = 0; i < n; i++)
    {
        ans += o[i];
        ans += e[i];
    }

    if (abs(m-n) == 1)
        ans += o[m-1];
    
    cout << ans << "\n";

    return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

void solve() {
  int n, d; scanf("%d%d", &n, &d);
  int ans = 0;
  for (long long x, y, i = 0; i < n; ++i) {
    scanf("%lld%lld", &x, &y);
    if (sqrt(x*x+y*y) <= d) ++ans;
  }
  printf("%d", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 3788
import sys

def main():
    input = sys.stdin.readline
    A, B = map(int, input().split())

    if A % 3 == 0 or B % 3 == 0 or (A + B) % 3 == 0:
        return 'Possible'
    else:
        return 'Impossible'


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String Base = sc.nextLine();
		switch(Base) {
			case "A":
				System.out.println("T");
				break;
			case "T":
				System.out.println("A");
				break;
			case "C":
				System.out.println("G");
				break;
			default:
				System.out.println("C");
		}
	}
}


Measured memory_bytes: 23252
H, W = gets.split.map(&:to_i)
N = gets.to_i
as = gets.split.map(&:to_i)

ind = 0
result = Array.new(H){Array.new(W)}
as.length.times do |i|
    as[i].times do |j|
        result[ind / W][ind % W] = i + 1
        ind += 1
    end
end

(0..((H-1)/2)).each do |i|
    result[2*i].reverse!
end

H.times do |i|
    puts result[i].join(' ')
end

Measured memory_bytes: 2428
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
12
---+/
/+---test
5
---+/
/+---test
1000000000000000000
---+/

void main(string[] args) {
  const N = readln.chomp.to!long;

  if (N%2 == 1) {
    0.writeln;
    return;
  }

  size_t ans;
  for (long i = 10; i <= N; i*=5) {
    ans += N/i;
  }
  ans.writeln;
}


Measured memory_bytes: 256
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define c1 __builtin_popcount
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//HELPERS

vector<int> powers2(32,0);void initialize(){ for(int i=1;i<powers2.size();i++) powers2[i] = powers2[i-1]*2;}
int32_t main()
{
IOS
string s;
cin>>s;
int q;
cin>>q;
string front,back;
int cnt=0;
while(q--) {
    int t;
    cin>>t;
    if(t == 1) cnt++;
    else {  
        int a;
        cin>>a;
        string ch;
        cin>>ch;
        if(a==1 && cnt&1) back+=ch;
        else if(a == 1 && cnt%2==0) front+=ch;
        else if(a==2 && cnt&1) front+=ch;
        else if(a==2 && cnt%2==0) back+=ch;  
    }
}
reverse(all(front));
s = front+s+back;
if(cnt&1) {
    reverse(all(s));
    cout<<s;
}
else cout<<s;
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 1200
// 0072
#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

struct road{
	int dis;
	int v1;
	int v2;
};


int findSet(int x, vector<int> &p){
	if(x != p[x])
		p[x] = findSet(p[x], p);
	return p[x];
}

bool isSameSet(int x, int y, vector<int> &p){
	return findSet(x, p) == findSet(y, p);
}

void link(int x, int y, vector<int> &p, vector<int> &rank){
	if(rank[x] > rank[y]){
		p[y] = x;
	}else{
		p[x] = y;
		if(rank[x] == rank[y])
			rank[y]++;
	}
}

void unite(int x, int y, vector<int> &p, vector<int> &rank){
	link(findSet(x, p), findSet(y, p), p, rank);
}

void Sort(vector<road> &ver){
	road r;
	for(int i=0;i<ver.size();i++){
		for(int j=1;j<ver.size()-i;j++){
			if(ver[j-1].dis > ver[j].dis){
				r = ver[j-1];
				ver[j-1] = ver[j];
				ver[j] = r;
			}
		}
	}
}

int lantern(vector<road> ver){
	vector<int> rank, p;
	for(int i=0;i<ver.size();i++){
		p.push_back(i);
		rank.push_back(0);
	}

	int lan = 0;
	for(int i=0;i<ver.size();i++){
		if(!isSameSet(ver[i].v1, ver[i].v2, p)){
			lan += ver[i].dis/100-1;
			unite(ver[i].v1, ver[i].v2, p, rank);
		}
	}

	return lan;
}

int main(){
	while(1){
		int n, m, a, b, d;
		vector<road> ver;
		road v;

		cin>>n;
		if(n == 0)
			break;

		cin>>m;
		for(int i=0;i<m;i++){
			scanf("%d,%d,%d", &a, &b, &d);
			v.v1 = a;
			v.v2 = b;
			v.dis = d;
			ver.push_back(v);
		}

		Sort(ver);
		
		cout<<lantern(ver)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1396
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    ll ans = 0;
    map<ll, ll> A;
    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        A[a]++;
        ans += a;
    }

    int Q;
    cin >> Q;
    while(Q--) {
        ll b, c;
        cin >> b >> c;
        ll Ab = A[b];
        ll Ac = A[c];

        A[c] += Ab;
        A[b] = 0;

        ans -= Ab * b;
        ans += Ab * c;

        cout << ans << endl;
    }
}

Measured memory_bytes: 9420
def read_tokens():
    return input().strip().split(' ')

def read_ints():
    return [int(token) for token in read_tokens()]

def solve(b, n):
    ret = []
    while len(b) > 0:
        # print(b)
        c = None
        for i in reversed(range(len(b))):
            if b[i] > i + 1:
                return [-1]
            if b[i] == i + 1:
                c = b[:i] + b[i+1:]
                ret.append(b[i])
                break
        if c is None:
            return [-1]
        b = c
    return list(reversed(ret))

x, y = read_ints()

def f(x):
    if x <= 3:
        return [300000, 200000, 100000][x-1]
    return 0

s = f(x) + f(y)
if x == 1 and y == 1:
    s += 400000

print(s)

Measured memory_bytes: 3316
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()

ans = 0


numB = [0] * N

j = 0

for i, b in enumerate(B):
    while j < N and b >= C[j]:
        j += 1
    numB[i] = N-j

for i in range(N-2, -1, -1):
    numB[i] += numB[i+1]

j = 0

for i, a in enumerate(A):
    while j < N and a >= B[j]:
        j += 1
    if j < N:
        ans += numB[j]


print(ans)


Measured memory_bytes: 105444
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000007)
	sc.Split(bufio.ScanWords)
	k := intScanner()
	a := intScanner()
	b := intScanner()
	f := false
	for i := 1; ; i++ {
		if k*i >= a && k*i <= b {
			f = true
		} else if k*i > b {
			break
		}
	}
	if f {
		fmt.Println("OK")
	} else {
		fmt.Println("NG")
	}
}


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

ans = [0]*(n+1)

for x in range(1,100):
	for y in range(1,100):
		for z in range(1,100):
			if pow(x,2) + pow(y,2) + pow(z,2) + x*y + y*z + z*x <= n:
				ans[pow(x,2) + pow(y,2) + pow(z,2) + x*y + y*z + z*x] += 1			
for i in range(1,n+1):
	print(ans[i])

Measured memory_bytes: 9424
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  for(int i=0;i<n;++i){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int tmp=vec.at(0),count=1;
  for(int i=0;i<n;++i){
    if(tmp<vec.at(i)){
      count++;
      tmp=vec.at(i);
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll int,ll int>
#define PI 2*acos(0)
//#define mx 100005
#define INF LONG_LONG_MAX
using namespace std;
const ll int p=1000000007;
//vector<ll > prime;
//bool mark[mx];
ll int mod(ll int a,ll int b)
{
    ll int m=a%b;
    if(m<0) m=(b<0)?(m-b):(m+b);
    return m;
}
ll maxpow(ll n)
{
    return (n & (~(n-1)));
}
bool isPrime(ll n)
{
    if(n<2) return false;
    if(n==2) return true;
    if(n%2==0) return false;
    for(ll i=3;i*i<=n;i+=2){
        if(n%i==0) return false;
    }
    return true;
}
/*void init()
{
    mark[1]=1;
    int i,j,limit=sqrt(mx*1.0)+2;
    prime.push_back(2);
    for(i=4;i<mx;i+=2) mark[i]=1;
    mark[2]=0;
    for(i=3;i<mx;i+=2){
        if(!mark[i]){
            prime.push_back(i);
            if(i<=limit){
                for(j=i*i;j<mx;j+=2*i){
                    mark[j]=1;
                }
            }
        }
    }
}*/
/*
ll maxdiv(ll n)
{
    ll i,ans=1;
    for(i=0;i<prime.size();i++){
        if(n%prime[i]==0){
            ans=n/prime[i];break;
            //return ans;
        }
    }
    return ans;
}*/
ll lcm(ll a,ll b)
{
    ll ans=a*b;
    return (ans/__gcd(a,b));
}
// ax+by and a>b
ll gcd(ll a,ll b,ll &x,ll &y)
{
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll d=gcd(b,mod(a,b),x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return d;
}
ll abso(ll a)
{
    if(a>=0) return a;
    return -a;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin>>s;
    int i;
    if(s[s.size()-1]=='s') s+="es";
    else s+="s";
    cout<<s;
    return 0;
}
//1028C


Measured memory_bytes: 3648
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}
var mod = 1e9+7;
function mul(){for(var a=arguments,r=a[0],i=a.length;--i;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i])%mod;return r;}
var fac=[],finv=[],invs=[],pow2=[];
function fset(n){
  fac.length=n+1,fac[0]=fac[1]=1;
  for(var i=2;i<=n;)fac[i]=mul(fac[i-1],i++);
  finv.length=n+1,finv[0]=finv[1]=1,finv[n]=inv(fac[n]);
  for(i=n;2<i;)finv[i-1]=mul(finv[i],i--);
  //invs.length=n+1,invs[0]=invs[1]=1;
  //for(i=2;i<=n;)invs[i]=mul(fac[i-1],finv[i++]);
  //pow2.length=n+1,pow2[0]=1;
  //for(i=1;i<=n;i++)pow2[i]=pow2[i-1]*2%mod;
}
function inv(b){for(var a=mod,u=0,v=1,t;b;v=t)t=a/b|0,a-=t*b,u-=t*v,t=a,a=b,b=t,t=u,u=v;u%=mod;return u<0?u+mod:u;}
function pow(a,n){for(var r=1;n;a=mul(a,a),n>>=1)if(n&1)r=mul(a,r);return r;}
function ncr(n,r){return mul(fac[n],finv[r],finv[n-r]);}
function npr(n,r){return mul(fac[n],finv[n-r]);}
function mput(n){return (n%mod+mod)%mod;}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var k = next();
  var a = nexts(n);
  var m = [], z = 0, p = [];
  for(var i = 0; i < n; i++){
    if(a[i] < 0)m.push(-a[i]);
    else if(a[i] > 0)p.push(a[i]);
    else z++;
  }
  var pl = p.length, ml = m.length;
  if(k > pl+ml)return 0;
  var ans = 1;
  if(n === k){
    for(var i = 0; i < n; i++)ans = mul(ans,Math.abs(a[i]));
    return ml%2 ? mput(-ans) : ans;
  }
  p.sort((a,b)=>b-a);
  m.sort((a,b)=>b-a);
  if(ml === n && k%2){
    for(var i = 0; i < k; i++){
      ans = mul(ans,m[ml-i-1]);
    }
    return mput(-ans);
  }
  p.push(0), pl++;
  var pi = 0, mi = 0;
  if(k&1)k--, ans = p[0], pi = 1;
  for(var i = 0; i < k; i+=2){
    if(pi+2 > pl){
      ans = mul(ans, m[mi++]);
      ans = mul(ans, m[mi++]);
    }else if(mi+2 > ml){
      ans = mul(ans, p[pi++]);
      ans = mul(ans, p[pi++]);
    }else if(BigInt(p[pi])*BigInt(p[pi+1]) > BigInt(m[mi])*BigInt(m[mi+1])){
      ans = mul(ans, p[pi++]);
      ans = mul(ans, p[pi++]);
    }else{
      ans = mul(ans, m[mi++]);
      ans = mul(ans, m[mi++]);
    }
  }
  return ans;
}

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

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


Measured memory_bytes: 3280
n = int(input())
ans = 0
cnt = 0
ch = [[0,0]]*1000
for i in range(n):
    a,b = map(int,input().split())
    ch.append([a,b])
    if a == b:
        cnt += 1
    else:
        ans = max(ans,cnt)
        cnt = 0
for i in range(len(ch)):
    if ch[i][0] != ch[i][1]:
        break
else:
    print("Yes")
    exit()
if ans >= 3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 63716
N, X = map(int, input().split())
L = list(map(int, input().split()))
D = 0
for i in range(2, N + 2):
    if D + L[i - 2] > X:
        print(i - 1)
        break
    D = D + L[i - 2]
else:
    print(i)


Measured memory_bytes: 9116
while True:
    h, w = map(int, input().split())
    
    if h == 0 and w == 0:
        break
    
    e = ''.join(['#.' for _ in range(w)])[:w]
    o = ''.join(['.#' for _ in range(w)])[:w]
    
    for i in range(h):
        if i % 2 == 0:
            print(e)
        else:
            print(o)
    print()


Measured memory_bytes: 5624
#include<iostream>
#include<algorithm>
#include<utility>
#include<cstring>
using namespace std;
int main(){
	int n=0;
	int i=0;
	int j=0;
	int x=0;
	int g=0;
	int s[10005];
	bool a=false;
	memset(s,0,sizeof(s));
	cin>>n;
	while(n!=0){
		for(i=0;i<n;i++){
			cin>>x;
			if(x>=2){
				a=true;
			}
			if(x!=0){
				g++;
			}
		}
		if(a==false){
			s[j]=1;
		}else{
			s[j]=g+1;
		}
		a=false;
		g=0;
		cin>>n;
		j++;
	}
	i=0;
	while(s[i]!=0){
		if(s[i]==1){
			cout<<"NA"<<endl;
		}else{
			cout<<s[i]<<endl;
		}
		i++;
	}
}

Measured memory_bytes: 1208
import sys
import bisect
input = sys.stdin.readline

N,Q=map(int,input().split())
STOP=[list(map(int,input().split())) for i in range(N)]
D=[int(input()) for i in range(Q)]

#Segment tree(1-indexed,再帰を使わないもの)

seg_el=1<<((Q+1).bit_length())#Segment treeの台の要素数
SEG=[10**15]*(2*seg_el)#1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化

def updates(l,r,x):
    L=l+seg_el
    R=r+seg_el

    while L<R:
        if L & 1:
            SEG[L]=min(SEG[L],x)
            L+=1

        if R & 1:
            R-=1
            SEG[R]=min(SEG[R],x)
        L>>=1
        R>>=1

def getvalue(n,seg_el):
    i=n+seg_el
    ANS=SEG[i]
    #子ノードへ
    
    while i!=0:
        i>>=1
        ANS=min(ANS,SEG[i],SEG[i])
        
    return ANS

for x,y,z in STOP:
    le=bisect.bisect_left(D,x-z)
    ri=bisect.bisect_left(D,y-z)

    updates(le,ri,z)

for d in range(Q):
    ANS=getvalue(d,seg_el)
    if ANS==10**15:
        print(-1)
    else:
        print(ANS)
    


Measured memory_bytes: 110812
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll binpow(ll x,ll y){
    ll res=1;
    while(y>0){
        if(y&1)
            res*=x;
        y>>=1;
        x*=x;
    }
    return res;
}
double dist(ll x1,ll y1,ll x2,ll y2){
    return sqrt(binpow(abs(x2-x1),2)+binpow(abs(y2-y1),2));
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,i,x,y;
    cin>>n;
    double num=n,ans=0,sol=0,count=0;
    vector<ll> arr;
    vector<pair<ll,ll> >v;
    for(i=1;i<=n;i++){
        arr.push_back(i-1);
        cin>>x>>y;
        v.push_back(make_pair(x,y));
    }
    do{
        ans=0.0;
        count+=1;
        for(i=0;i<n-1;i++)
            ans+=dist(v[arr[i]].first,v[arr[i]].second,v[arr[i+1]].first,v[arr[i+1]].second);
        sol+=ans;
    }while(next_permutation(arr.begin(),arr.end()));
    cout<<fixed<<setprecision(6)<<(sol/count)<<endl;
    return 0;
}


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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,x;
vector<int> C;
vector<vector<int>> A;

const long long INF = 1LL << 60;

long long score(const vector<long long> &K) {
    long long res = 0; 
    ll skill[m];
  rep(j,m)skill[j]=0;
    for (int i = 0; i < n; ++i) {

      if(K[i]==0)continue;
    
      
      res+=C[i];
      rep(j,m){

        skill[j]+=A[i][j];
        
      }
      
    }
  	rep(i,m)if(skill[i]<x)res=INF;
    return res;
}

long long dfs(vector<long long> &K) {
    // 数列の長さが N に達したら打ち切り
    if (K.size() == n) {
        // 処理
        return score(K);
    }

  ll res=INF;
    for (int v = 0; v < 2; ++v) {
        K.push_back(v);
        res=min(res, dfs(K));
        K.pop_back();
    }
  return res;
}


int main(){


  cin>>n>>m>>x;
	
  C.resize(n);
  A.resize(n);
  rep(i,n)A[i].resize(m);
  int check[m];
  rep(j,m)check[j]=0;
  
  rep(i,n){

    cin>>C[i];
    rep(j,m){
      cin>>A[i][j];
    	
      check[j]+=A[i][j];
    }
    
  }
  rep(j,m){

    if(check[j]<x){cout<<-1<<endl;return 0;}
    
  }
  
  vector<ll> K;
  cout<<dfs(K)<<endl;
  
  
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
int main(){
  int i,j,n,f=0;
  int a[3010];

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

  for(j=0;j<n;j++){
    f=f+(a[j]-1);
  }
  printf("%d\n", f);
  return 0;
}

Measured memory_bytes: 128
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	h := readInt()
	w := readInt()
	a := make([][]byte, h)
	f := make([][]int, h)
	for i := range a {
		a[i] = []byte(readString())
		f[i] = make([]int, w)
		for j := range f[i] {
			if a[i][j] == '.' {
				f[i][j] = 1000000007
			}
		}
	}
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if 0 < i {
				f[i][j] = min(f[i][j], f[i-1][j]+1)
			}
			if 0 < j {
				f[i][j] = min(f[i][j], f[i][j-1]+1)
			}
		}
	}
	for i := h - 1; 0 <= i; i-- {
		for j := w - 1; 0 <= j; j-- {
			if i < h-1 {
				f[i][j] = min(f[i][j], f[i+1][j]+1)
			}
			if j < w-1 {
				f[i][j] = min(f[i][j], f[i][j+1]+1)
			}
		}
	}
	ans := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if a[i][j] == '.' {
				ans = max(ans, f[i][j])
			}
		}
	}
	println(ans)
}

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

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

// -----------------------------------------------------------------------------


Measured memory_bytes: 10368
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<long long> C(N - 1), S(N - 1), F(N - 1);

    for (int i = 0; i < N - 1; ++i)
    {
        cin >> C.at(i) >> S.at(i) >> F.at(i);
    }

    long long time, num;
    for (int i = 0; i < N - 1; ++i)
    {
        time = 0;
        time += S[i];
        for (int j = i; j < N - 2; ++j)
        {
            time += C[j];
            if (time < S[j + 1])
            {
                time = S[j + 1];
            }
            else
            {
                num = (time - 1) / F[j + 1] + 1;
                // 発車まで待つ
                time += num * F[j + 1] - time;
            }
        }
        time += C[N - 2];
        cout << time << endl;
    }
    cout << 0 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 101
#define INF 150000

int main(){
  int i, j, min, x, y, z, n;
  int M[N][N];
  int color[N], d[N];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    color[i] = 0;
    d[i] = INF;
    for(j = 0; j < n; j++){
      M[i][j] = -1;
    }
  }

  for(i = 0; i < n; i++){
    scanf("%d %d", &x, &y);
    for(j = 0; j < y; j++){
      scanf("%d", &z);
      scanf("%d", &M[x][z]);
    }
  }

  d[0] = 0;

  while(1){
    min = INF;
    for(i = 0; i < n; i++){
      if(color[i] != 1 && d[i] < min){
        min = d[i];
        x = i;
      }
    }

    if(min == INF)
      break;

    for(i = 0; i < n; i++){
      if(M[x][i] != -1 && color[i] != 1 && d[x] + M[x][i] < d[i])
        d[i] = d[x] + M[x][i];
    }

    color[x] = 1;

  }

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

  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 16

int n;
int a[N][N];
ll s[1 << N];

ll memo[1 << N];
bool used[1 << N];
ll dfs(int state) {
  int t = (-1 & state);
  if(used[state]) {
    return memo[state];
  }
  used[state] = true;
  ll r = -INFLL;
  while(t > 0) {
    r = max(r, dfs(state ^ t) + s[t]);
    t = (t - 1) & state;
  }
  return memo[state] = r;
}

int main() {
  cin >> n;
  rep(i, n) rep(j, n) cin >> a[i][j];
  rep(state, 1<<n) {
    used[state] = false;
    s[state] = 0;
    rep(i, n) {
      if((state & (1 << i)) == 0) continue;
      rep(j, n) {
        if(i >= j || (state & (1 << j)) == 0) continue;
        s[state] += a[i][j];
      }
    }
  }
  used[0] = true;
  memo[0] = 0;
  cout << dfs((1 << n) - 1) << endl;
  return 0;
}

Measured memory_bytes: 1280
def div2_count(n):
  if n % 2 != 0: return 0
  else: return 1 + div2_count(n / 2)

N = int(input())
ans = 1
count = 0

for i in range(N, 1, -1):
  tmp = div2_count(i) 
  if tmp > count: 
    ans = i
    count = tmp
    
print(ans)


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

typedef long long ll;
typedef pair<int, int> pii;
const int N = 2e5 + 100;

int n, m, dp[N], nxt[N];
string s;
set<pii> st;

int main() {
	cin >> n >> m >> s;
	dp[n] = 0;
	st.insert(pii(dp[n], n));
	for (int i = n - 1; ~i; i--) {
		st.erase(pii(dp[i + m + 1], i + m + 1));
		if (st.empty() || s[i] == '1')
			dp[i] = -N;
		else {
			dp[i] = st.begin()->first + 1;
			nxt[i] = st.begin()->second;
			st.insert(pii(dp[i], i));
		}
	}
	if (dp[0] == -N) {
		cout << -1;
		return 0;
	}
	int now = 0;
	while (now < n) {
		cout << nxt[now] - now << ' ';
		now = nxt[now];
	}
}


Measured memory_bytes: 3712
import math

def main():
    a, b, H, M = map(int, input().split())

    # 時針は、１分間で0.5度（１時間で30度）
    # 分針の１分は、6度

    # 余弦定理を使用
    M_angle = 6 * M
    H_angle = 0.5 * (H * 60 + M)
    angle = abs(M_angle - H_angle)
    
    print(math.sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * math.cos(math.radians(angle))))

if __name__ == "__main__":
    main()

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()

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


int main()
{
    int n;
    cin >> n;
    int p[10], q[10];
    rep(i, n){
        cin >> p[i];
    }

    rep(i, n){
        cin >> q[i];
    }
    vector<int> v(n);
    rep(i, n) v[i] = i + 1;

    int cnt = 0;
    int x, y;
    do
    {
        cnt++;
        bool ok = true;
        rep(i, n){
            if(v[i] != p[i]){
                ok = false;
            }
        }
        if(ok) x = cnt;
        ok = true;
        rep(i, n){
            if(v[i] != q[i]){
                ok = false;
            }
        }
        if(ok) y = cnt;
    } while (next_permutation(all(v)));
    
    cout << abs(x - y) << "\n";


    return 0;
}


Measured memory_bytes: 256
n = int(input())
L = list(map(int, input().split()))
count = {}
for a in L:
    if a not in count:
        count[a] = 1
    else:
        count[a] += 1
leng = sorted(set(count), reverse=True)
flag = 0
for i in leng:
    if count[i] >= 4:
        if flag == 0:
            print(i * i)
            break
        else:
            print(l * i)
            break
    elif count[i] >= 2:
        if flag == 0:
            l = i
            flag = 1
        else:
            print(l * i)
            break
else:
    print(0)


Measured memory_bytes: 19080