akhauriyash/Code-Regression huggingface dataset:
/**
 *
 * AtCoder Beginner Contest 106 - Problema C: To Infinity (https://beta.atcoder.jp/contests/abc106/tasks/abc106_c)
 *
 * Find the garden area excluding the roads.
 *
 * Math solution: the rectangle area is AB. One road has area A, the other one has area B. The
 * roads intersection has area 1.
 */
#include <iostream>

using namespace std;
using ll = long long;

void solve(const string& S, ll K)
{
    for (const auto& c : S)
    {
        if (c != '1')
        {
            cout << c << endl;
            return;
        }

        --K;

        if (not K)
            break;
    }

    cout << 1 << endl;
}

int main()
{
    ios::sync_with_stdio(false);

    string S;
    ll K;
    cin >> S >> K;

    solve(S, K);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <utility>

using namespace std;

template<class T>
vector<T> dijkstra(vector<vector<int>> E, vector<vector<T>> W, int s, T inf)
{
    int n = (int)E.size();

    vector<T> D(n, inf);
    typedef pair<T,int> P;
    priority_queue<P,vector<P>,greater<P>> Q;

    D[s] = T();
    Q.push(make_pair(D[s], s));

    while (!Q.empty())
    {
        T d = Q.top().first;
        int p = Q.top().second;
        Q.pop();
        if (d > D[p])
            continue;
        for (int i=0; i<(int)E[p].size(); i++)
        {
            int t = E[p][i];
            if (d+W[p][i] < D[t])
                D[t] = d+W[p][i],
                Q.push(make_pair(D[t], t));
        }
    }
    return D;
}

int main()
{
    long long inf = 1000000000000000LL;

    int n, m, s, t;
    cin>>n>>m>>s>>t;
    s--, t--;
    vector<int> u(m), v(m);
    vector<long long> a(m), b(m);
    for (int i=0; i<m; i++)
    {
        cin>>u[i]>>v[i]>>a[i]>>b[i];
        u[i]--, v[i]--;
    }

    vector<vector<int>> E(n);
    vector<vector<long long>> W(n);
    for (int i=0; i<m; i++)
    {
        E[u[i]].push_back(v[i]);
        W[u[i]].push_back(a[i]);
        E[v[i]].push_back(u[i]);
        W[v[i]].push_back(a[i]);
    }
    vector<long long> A = dijkstra(E, W, s, inf);

    E = vector<vector<int>>(n);
    W = vector<vector<long long>>(n);
    for (int i=0; i<m; i++)
    {
        E[u[i]].push_back(v[i]);
        W[u[i]].push_back(b[i]);
        E[v[i]].push_back(u[i]);
        W[v[i]].push_back(b[i]);
    }
    vector<long long> B = dijkstra(E, W, t, inf);

    vector<long long> ans(n);
    for (int i=0; i<n; i++)
        ans[i] = inf - A[i] - B[i];
    for (int i=n-2; i>=0; i--)
        ans[i] = max(ans[i], ans[i+1]);

    for (long long t: ans)
        cout<<t<<endl;
}


Measured memory_bytes: 30776
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

V<string> amap(800);
V<V<bool>> visited(800, V<bool>(800, false));

int main() {
  ll h, w, k; cin >> h >> w >> k;
  REP(i, h) cin >> amap.at(i);
  ll sx, sy;
  REP(i, h) REP(j, w) {
    if (amap.at(i).at(j) == 'S') {sx=j; sy=i; break;}
  }
  visited.at(sy).at(sx) = true;
  queue<tuple<ll, ll, ll>> que; que.push(make_tuple(sx, sy, k));

  ll ans = 10000;
  while (!que.empty()) {
    tuple<ll, ll, ll> q = que.front(); que.pop();
    if (get<2>(q) < 0) continue;
    else{
      ll x=get<0>(q), y=get<1>(q), rk=get<2>(q);
      ans = min(ans, min(min(x, w-x-1), min(y, h-y-1)));
      if (x-1>=0 && amap.at(y).at(x-1) == '.' && !visited.at(y).at(x-1)) {
        visited.at(y).at(x-1) = true;
        que.push(make_tuple(x-1, y, rk-1));
      }
      if (x+1<w && amap.at(y).at(x+1) == '.' && !visited.at(y).at(x+1)) {
        visited.at(y).at(x+1) = true;
        que.push(make_tuple(x+1, y, rk-1));
      }
      if (y-1>=0 && amap.at(y-1).at(x) == '.' && !visited.at(y-1).at(x)) {
        visited.at(y-1).at(x) = true;
        que.push(make_tuple(x, y-1, rk-1));
      }
      if (y+1<h && amap.at(y+1).at(x) == '.' && !visited.at(y+1).at(x)) {
        visited.at(y+1).at(x) = true;
        que.push(make_tuple(x, y+1, rk-1));
      }
    }
  }
  cout << ans / k + (ans % k ? 1 : 0) + 1 << endl;
  return 0;
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;
ll calc_cnt(string s){
    int n=s.size();
    string t=s;
    ll cnt=0;
    rep(i,n){
        if(t[i+1]==t[i]){
            t[i+1]='A';
            cnt++;
        }
    }
    return cnt;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin>>s;
ll k;
cin>>k;
vector<ll> diff(3);
rep(i,3){
    string _s=s;
    rep(j,i){
        _s+=s;
    }
    diff[i]=calc_cnt(_s);
}
rreps(i,1,3){
diff[i]-=diff[i-1];
}

ll ans=diff[0];
rep(i,k-1){
    ans+=diff[i%2+1];
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 3660
_n = gets.chomp.to_i
ary = gets.chomp.split.map(&:to_i)

l_max = 0
r_max = 2

diffs = []
ary_size = ary.size
cumulative_sums = []
ary_size.times do |i|
  cumulative_sums.push(cumulative_sums[-1].to_i + ary[i])
end

(1..(ary_size - 3)).each do |i|
  l_max = (l_max...i).find do |j|
    cumulative_sums[j] >= (cumulative_sums[i] - cumulative_sums[j])
  end || (i - 1)
  r_max = ([r_max, i + 1].max...(ary_size - 2)).find do |k|
    cumulative_sums[k] - cumulative_sums[i] >= cumulative_sums[-1] - cumulative_sums[k]
  end || (ary_size - 2)

  if !l_max.zero? && (cumulative_sums[i] - cumulative_sums[l_max]) < cumulative_sums[l_max - 1]
    l_max -= 1
  end
  if r_max != (i + 1) && (cumulative_sums[-1] - cumulative_sums[r_max]) < (cumulative_sums[r_max - 1] - cumulative_sums[i])
    r_max -= 1
  end

  sec1 = cumulative_sums[l_max]
  sec2 = cumulative_sums[i] - cumulative_sums[l_max]
  sec3 = cumulative_sums[r_max] - cumulative_sums[i]
  sec4 = cumulative_sums[-1] - cumulative_sums[r_max]
  tmp_ary = [sec1, sec2, sec3, sec4]
  diffs.push(tmp_ary.max - tmp_ary.min)
end

puts diffs.min

Measured memory_bytes: 37496
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>
#include <cassert>

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define fill(x,y) memset(x,y,sizeof(x))
#define prev PREV
                         
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }

int n;
int m;
int x[200000];

int main () {
	scanf ("%d", &n);
	for (int i = 0; i < n; i++) scanf ("%d", &x[i]);
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		if (x[i] > i || (i > 0 && x[i - 1] + 1 < x[i])) {
			printf ("-1\n");
			re 0;
		}
		if (i + 1 == n || x[i] + 1 > x[i + 1]) ans += x[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
int N; 
cin >> N;
long long int A[314159], B[314159];  
for(int i = 0; i < N; i++){
cin >> A[i]; 
B[i+1] = B[i] + A[i]; 
}
long long int ans = abs(B[N] - 2 * B[1]); 
for(int i = 1; i < N; i++){
long long int K = abs(B[N] - 2 * B[i]);  
ans = min(ans, K); 
}
cout << ans << endl; 
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <map>
#include <deque>
#include <queue>
#include <set>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	cout<<(b-a)*(b-a+1)/2-b;
	return 0;
}


Measured memory_bytes: 256
/*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog oi.ender-zzm.pro
*/
#include <bits/stdc++.h>
using namespace std;

inline int Isdigit(char c) {
	if (c < '0' || c > '9') return 0;
	return 1;
}
inline int readint(){
    register int x = 0, flag = 1;
    register char ch;
    while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (Isdigit(ch)) x = x * 10 + (ch & 15), ch = getchar();
	return x * flag;
}

inline long long readlong() {
	register long long x = 0, flag = 1;
	register char ch;
	while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (Isdigit(ch)) x = x * 10 + (ch & 15), ch = getchar();
	return x * flag;
}
template <class T>
inline void write(T x){
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define debug(x) cout << #x << " = " << x << endl;
#define For(i, x, y) for (int i = (x); i <= (y); i++) 
#define Rep(i, x, y) for (int i = (x); i >= (y); i--) 
#define ri readint
#define rl readlong

#define int long long
signed main() {
	int a, b, c, d;
	a = ri(), b = ri(), c = ri(), d = ri();
	int ans = a * c;
	ans = max(ans, a * c);
	ans = max(ans, a * d);
	ans = max(ans, b * c);
	ans = max(ans, b * d);
	if (a <= 0 && b >= 0) ans = max(ans, 0ll);
	if (c <= 0 && d >= 0) ans = max(ans, 0ll);
	cout << ans << endl;
}


Measured memory_bytes: 3628
#include<iostream>

using namespace std;

int main() {

	int H,W;
	int i,n,m;

	while (1) {

                cin>>H>>W;

		if (H == 0 && W == 0) break;

		for (n = 0; n < H; n++) {

			for (m = 0; m < W; m++) {
				cout << "#";
			}

			cout << endl;

		}

		cout << endl;

	}
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

template <class T>
class Lazy_Segment_Tree{
	private:
	int n;
	vector<T> date,lazy;
	void Set_Lazy(int k,T x){
		date[k]+=x;
		lazy[k]+=x;
	}
	void Push(int k){
		Set_Lazy(k*2+1,lazy[k]);
		Set_Lazy(k*2+2,lazy[k]);
		lazy[k]=0;
	}
	void Fix(int k){
		date[k]=min(date[k*2+1],date[k*2+2]);
	}
	void Add_func(int a,int b,int k,int l,int r,T x){
		if(r<=a||b<=l) return;
		if(a<=l&&r<=b){
			Set_Lazy(k,x);
			return;
		}
		Push(k);
		int m=(l+r)/2;
		Add_func(a,b,k*2+1,l,m,x);
		Add_func(a,b,k*2+2,m,r,x);
		Fix(k);
	}
	void Update_func(int I,int k,int l,int r,T x){
		if(r<=I||I<l) return;
		if(l==I&&r-l==1){
			date[k]=x;
			lazy[k]=x;
			return;
		}
		Push(k);
		int m=(l+r)/2;
		Update_func(I,k*2+1,l,m,x);
		Update_func(I,k*2+2,m,r,x);
		Fix(k);
	}
	T Query_func(int a,int b,int k,int l,int r){
		if(r<=a||b<=l) return inf;
		if(a<=l&&r<=b) return date[k];
		Push(k);
		int m=(l+r)/2;
		T vl=Query_func(a,b,k*2+1,l,m);
		T vr=Query_func(a,b,k*2+2,m,r);
		return min(vl,vr);
	}
	public:
	Lazy_Segment_Tree(int n_){
		n=1;
		while(n<n_) n*=2;
		date=lazy=vector<T>(2*n-1);
	}
	void Add(int a,int b,T x){
		Add_func(a,b,0,0,n,x);
	}
	void Update(int k,T x){
		Update_func(k,0,0,n,x);
	}
	T Query(int a,int b){
		return Query_func(a,b,0,0,n);
	}
};

ll n,m;
vl L,R,a;
vp b;

int main(){
	cin>>n>>m;
	L=R=a=vl(m);
	b=vp(m);
	ll res=0,I=0;
	for(int i=0;i<m;i++){
		cin>>L[i]>>R[i]>>a[i];
		b[i]={R[i],i};
		res+=a[i];
	}
	sort(b.begin(),b.end());
	Lazy_Segment_Tree<ll> st(n+2);
	for(int i=0;i<=n;i++){
		while(I<m&&b[I].first==i){
			int id=b[I].second;
			st.Add(0,L[id],a[id]);
			I++;
		}
		ll tmp=st.Query(0,i+1);
		st.Update(i+1,tmp);
		if(i==n) res-=tmp;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 14720
class SegmentTree:
    def __init__(self, lst, op, e):
        self.n = len(lst)
        self.N = 1 << ((self.n - 1).bit_length())
        self.op = op # operation
        self.e = e # identity element
        self.v = self._build(lst)
        
    def _build(self, lst):
        # construction of a tree
        # total 2 * self.N - 1 elements
        tree = [self.e] * (self.N - 1) + lst + [self.e] * (self.N - self.n)
        for i in range(self.N - 2, -1, -1):
            tree[i] = self.op(tree[2*i + 1], tree[2*i + 2])
        return tree
    
    def __getitem__(self, i):
        return self.v[i + self.N - 1]
    
    # update a_i to be x 
    def update(self, i, x):
        i += self.N - 1
        self.v[i] = x
        while i > 0:
            i -= 1; i >>= 1
            self.v[i] = self.op(self.v[2*i + 1], self.v[2*i + 2])
    
    # returns answer for the query interval [l, r)
    def query(self, l, r):
        left = l + self.N - 1
        right = r + self.N - 1
        L = self.e; R = self.e
        while left < right:
            if left & 1 == 0: # self.v[left] is the right child
                L = self.op(L, self.v[left])
                left += 1
            if right & 1 == 0: # self.v[right-1] is the left child
                right -= 1
                R = self.op(self.v[right], R)
            left -= 1; left >>= 1
            right >>= 1
        return self.op(L, R)

def coord_compress(A):
    B = {a: i for i, a in enumerate(sorted(set(A)))}
    return [B[a] for a in A]
    
def LIS(A):
    A = coord_compress(A)
    dp = SegmentTree([0] * len(A), max, 0)
    for a in A:
        dp.update(a, max(dp[a], dp.query(0, a) + 1))
    return max(dp)

N = int(input())
A = [int(input()) for _ in range(N)]
print(LIS(A))


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

class Main{
	static int[][] dp;
	static long ans = 0;
	static int H;
	static int W;
	static char[][] map;
	static int sub = 0;
	static boolean[][] used;
	static int[][] okblack;
	static ArrayList<Integer> bList;
	static int count;



	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		H = sc.nextInt();
		W = sc.nextInt();
		map = new char[H][W];
		for(int i = 0;i < H;i++){
			String ss = sc.next();
			for(int j = 0;j < W;j++){
				map[i][j] = ss.charAt(j);
			}
		}
		//		for(int i = 0;i < H;i++){
		//			for(int j = 0;j < W;j++){
		//				System.out.print(map[i][j])				;
		//				}
		//			System.out.println();
		//		}
		bList = new ArrayList<Integer>();

		int[][] black = new int[H][W];
		for(int i = 0;i < H;i++){
			for(int j = 0;j < W;j++){
				if(map[i][j] == '#'){
					bList.add(i);
					bList.add(j);
				}
			}
		}	
		used = new boolean[H][W];

		for(int i = 0;i < bList.size();i=i+2){
			//			System.out.println("next");
			count = 1;
			sub = 0;
			if(map[bList.get(i)][bList.get(i+1)] == '#'){
				used[bList.get(i)][bList.get(i+1)] = true;
				dfs(bList.get(i),bList.get(i+1),1);
				ans += (long)sub*count;
			}

		}


		System.out.println(ans);





	}
	static void dfs(int y,int x,int color){
		//						System.out.println("y " + y + " x "+x  );



		if(map[y][x] == '.' && color == 0){
		//										System.out.println("ok");
			sub++;
		}
		int[] dx = {-1,1,0,0};
		int[] dy = {0,0,1,-1};
		for(int i = 0;i < 4;i++){
			if(x + dx[i] >= 0 && x + dx[i] < W && y + dy[i] >= 0 && y + dy[i] < H){
				if(color == 1){
					if(map[y+dy[i]][x+dx[i]] == '.' && !used[y+dy[i]][x+dx[i]]){
						used[y+dy[i]][x+dx[i]] = true;
						dfs(y+dy[i], x+dx[i], 0);
						//						used[y+dy[i]][x+dx[i]] = false;;

					}
				}else{
					if(map[y+dy[i]][x+dx[i]] == '#'&& !used[y+dy[i]][x+dx[i]]){
						map[y+dy[i]][x+dx[i]] = '¥';
						count++;
						used[y+dy[i]][x+dx[i]] = true;
						dfs(y+dy[i], x+dx[i], 1);

						//						used[y+dy[i]][x+dx[i]] = false;;

					}
				}
			}
		}

	}



}







class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}



Measured memory_bytes: 71808
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <bitset>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)

using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

    ll i,j,h;
    ll Q,M,K,P,A,B,N;

    long double x;

    string S;

    ll ans=0;
    ll count=0;
    ll flag=0;
    ll temp=0;

    cin >>S;
    
if(S=="ABC"){

    cout<< "ARC" <<endl;
}else{
    cout<< "ABC" <<endl;
}

    return 0;
}

Measured memory_bytes: 3612
S = list(input())

s = S[2:-1]
s_sub = []
cnt = 0
for i in s:
  if (i == 'C'):
    cnt += 1

for i in S[1:]:
  if (i != 'C'):
    s_sub.append(i)
if (S[0] == 'A' and cnt == 1 and "".join(s_sub).islower()):
  print('AC')
else:
  print('WA')


Measured memory_bytes: 3060
#include <iostream>

using namespace std;
typedef long long int ll;
ll N1097 = 1000000007LL;

int main(){
    ll N;
    cin >> N;
    ll S1[100];
    for(ll i=0;i<100;i++){
        S1[i]=0;
    }
    ll a;
    for(ll kkk=0;kkk<N;kkk++){
        cin >> a;
        ll b=1;
        ll i=0;
        while(b<=a){
            if(a&b){
                S1[i] += 1;
            }
            i += 1;
            b <<= 1;
        }
    }
    ll ans=0;
    ll b=1;
    for(ll i=0;i<100;i++){
        ll s1 = S1[i];
        ll s0 = N - s1;
        ans += (((s1*s0)%N1097) * (b%N1097)) % N1097;
        ans %= N1097;
        b <<= 1;
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
const int INF32 = 100100100;
const ll INF64 = 9223372036854775807;
using namespace std;

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

    int N, K;
    cin >> N >> K;
    vector<int> X(N);
    REP(i, N) cin >> X[i];

    ll ans = INF64;

    REP(start, N) {
        int end = start + K - 1;
        if (end >= N)
            continue;

        ll l = abs(X[end]) + abs(X[end] - X[start]);
        ll r = abs(X[start]) + abs(X[end] - X[start]);
        ans  = min(ans, min(l, r));
    }

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

Measured memory_bytes: 640
from math import factorial
from functools import reduce
def combinations(x, y):
    a = reduce(lambda x, y: x*y , [x - i for i in range(y)])
    b = factorial(y)
    return a//b
N, A, B = map(int,input().split())
v = sorted([int(vi) for vi in input().split()],reverse=True)
ans1 = sum(v[:A])/A

if v[0] != v[A-1]:
    X = sum([v[A-1] == v[i] for i in range(N)])
    Y = sum([v[A-1] == v[i] for i in range(A)])
    ans2 = combinations(X, Y)
else:
    X = sum([v[0] == v[i] for i in range(N)])
    ans2 = sum([combinations(X,i) for i in range(A, B+1)])

print(ans1)
print(ans2)


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

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

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> maze(h);
    for (int i = 0; i < h; ++i) {
        cin >> maze[i];
    }

    int res = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (maze[i][j] == '#') continue;
            vector<vector<int>> d(h, vector<int>(w, INF));

            queue<pii> que;
            que.push(pii(i, j));
            d[i][j] = 0;
            while(!que.empty()){
                pii p = que.front();
                que.pop();
                for (int k = 0; k < 4; ++k) {
                    int nx = p.first + dx[k];
                    int ny = p.second + dy[k];
                    if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
                    if (maze[nx][ny] == '#') continue;
                    if (d[nx][ny] != INF) continue;

                    d[nx][ny] = d[p.first][p.second] + 1;
                    que.push(pii(nx, ny));
                }
            }

            for (int s = 0; s < h; ++s) {
                for (int t = 0; t < w; ++t) {
                    if (d[s][t] != INF) {
                        chmax(res, d[s][t]);
                    }
                }
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mod 1000000007
#define vll vector<ll>
#define inf 1e12
#define pll pair<ll,ll>
#define ff first 
#define ss second 
#define PI acos(-1)
#define prm 998244353
#define endl '\n'
using namespace std;
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//cout << fixed << setprecision(0)
/*
ll power(ll x,ll y)
{
	ll res=1;
	while(y>0)
	{
		if(y%2==1)res=(res*x)%mod;
		y=y/2;
		x=(x*x)%mod;
	}
	return res;
}
ll inv(ll a) 
{
return power(a,mod-2);
}
 
ll fact[2000007];
ll inr[2000007];
void pre()
{
	fact[0]=1;
	for(ll i=1;i<=2000005;i++)fact[i]=(fact[i-1]*i)%mod;
	inr[0]=1;
	for(ll i=1;i<=2000005;i++)inr[i]=inv(fact[i]);
}
 
ll ncr(ll n,ll r)
{
	ll a=(fact[n]*inr[r])%mod;
	ll b=(a*inr[n-r])%mod;
	return b;
}
 
ll spf[10000050];
void sieve()
{
	for(ll i=2;i*i<=10000030;i++)
	{
		if(spf[i]==0)
		{
			for(ll j=i+i;j<=10000030;j+=i)
			{
				if(spf[j]==0)
				{
					spf[j]=i;
				}
			}
		}
	}
}
*/

int main()
{
    fastio; 
    //sieve();
    //pre();
    ll T=1;
    //cin>>T;  
    while(T--)
    {
    	ll n;
    	cin>>n;
    	ll a[n];
    	for(ll i=0;i<n;i++)cin>>a[i];//,m[a[i]]++;
    	ll ans=0;
    
    	for(ll i=0;i<n;i++)
    	{
    		for(ll j=i+1;j<n;j++)
    		{
    			//if(i==j)continue;
    			for(ll k=j+1;k<n;k++)
    			{
    				//if(k==i||k==j)continue;
    				set<ll>s;
    				s.insert(a[i]);
    				s.insert(a[j]);
    				s.insert(a[k]);
    				if(s.size()<3)continue;
    				ll b[3];
    				b[0]=a[i];
    				b[1]=a[j];
    				b[2]=a[k];
    				sort(b,b+3);
    				
    				if(b[2]<b[0]+b[1])ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A + B == C + D) {
    cout << "Balanced" << endl;
  } else if (A + B < C + D) {
    cout << "Right" << endl;
  } else {
    cout << "Left" << endl;
  }
}

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

void Main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  map<long long, long long> L, R;
  for (int i = 0; i < N; i++) {
    L[(i + 1) + A[i]]++;
    R[(i + 1) - A[i]]++;
  }
  long long ans = 0;
  for (auto l: L) {
    ans += l.second * R[l.first];
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 38672
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
    int n,a[201],ans = 0;
        scanf("%d",&n);
    for(int i=1;i<=2*n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+1+2*n);
    for(int i=1;i<=2*n;i+=2)
        ans+=a[i];
    printf("%d\n",ans);
    return 0;
 } 

Measured memory_bytes: 128
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<ll>;

ll MOD = 1000000007;



int main()
{
	int N;
	int K;
	cin >> N >> K;

	string S;
	cin >> S;

	int ans = 0;

	for (int i = 1; i < S.length(); ++i)
	{
		if (S[i] == S[i - 1])
		{
			ans += 1;
		}
	}

	cout << min(N - 1, ans + K * 2) << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
long long int dp[100000][3];
long long int sum0(long long int n,vector< vector<int> > &arr);
long long int sum1(long long int n,vector< vector<int> > &arr);
long long int sum2(long long int n,vector< vector<int> > &arr);
int main()
{
    memset(dp,-1,sizeof(dp));
    long long int n,r1,r2,r3;
    cin>>n;
    vector<int> a(3);
    vector< vector<int> >arr(n,a);
    for(long long int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        cin>>arr[i][j];
    }
    if(n==1)cout<<max(arr[0][0],max(arr[0][1],arr[0][2]));
    else
    {
    dp[0][0]=arr[0][0];dp[0][1]=arr[0][1];dp[0][2]=arr[0][2];
    dp[1][0]=arr[1][0]+max(arr[0][1],arr[0][2]);dp[1][1]=arr[1][1]+max(arr[0][0],arr[0][2]);dp[1][2]=arr[1][2]+max(arr[0][1],arr[0][0]);
    r1=arr[n-1][0]+max(sum1(n-2,arr),sum2(n-2,arr));
    r2=arr[n-1][1]+max(sum0(n-2,arr),sum2(n-2,arr));
    r3=arr[n-1][2]+max(sum0(n-2,arr),sum1(n-2,arr));
    cout<<max(max(r1,r2),r3);
    }
    
}
long long int sum1(long long int n,vector< vector<int> > &arr)
{
    if(dp[n][1]!=-1)return dp[n][1];
    dp[n][1]=arr[n][1]+max(sum0(n-1,arr),sum2(n-1,arr));
    return dp[n][1];
}
long long int sum2(long long int n,vector< vector<int> > &arr)
{
    if(dp[n][2]!=-1)return dp[n][2];
    dp[n][2]=arr[n][2]+max(sum0(n-1,arr),sum1(n-1,arr));
    return dp[n][2];
}
long long int sum0(long long int n,vector< vector<int> > &arr)
{
    if(dp[n][0]!=-1)return dp[n][0];
    dp[n][0]=arr[n][0]+max(sum1(n-1,arr),sum2(n-1,arr));
    return dp[n][0];
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin >> n;
	string s; cin >> s;
	vector<vector<int> > g(n);
	for(int i = 0; i < n - 1; i ++){
		int u, v; cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int ans = 1<<30;
	for(int i = 0; i < n; i++){
		vector<int> low(n), high(n), cnt(n);
		function<void (int, int)> dfs = [&](int cur, int par){
			cnt[cur] = s[cur] == '1';
			high[cur] = 0;
			int max_low = -1;
			int max_high = 0;
			for(int nxt : g[cur]){
				if(nxt == par) continue;
				dfs(nxt, cur);
				cnt[cur] += cnt[nxt];
				high[nxt] += cnt[nxt];
				low[nxt] += cnt[nxt];
				high[cur] += high[nxt];
				if(max_low < low[nxt]){
					max_low = low[nxt];
					max_high = high[nxt];
				}
			}
			if(max_low > high[cur] - max_high){
				low[cur] = max_low - high[cur] + max_high;
			} else {
				low[cur] = high[cur] % 2;
			}
		};
		dfs(i, -1);
		if(low[i] == 0){
			ans = min(ans, high[i] / 2);
		}
	}
	if(ans == (1<<30)) ans = -1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	int c,d;
	c=a+b;
	d=b-a;
	if(b%a==0)
	printf("%d",c);
	else
	printf("%d",d);
	return 0; 
 } 

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;


int MOD=1000000007;


int main(){
    int N,co=0;
    cin >> N;
    int p[N];
    for(int i=0; i<N; i++){
    cin >> p[i];
    if(p[i] != i+1) co+=1;
    }
    
    if(co<=2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

using namespace std;

int main() {
  string S, T;
  bool ans = true;
  
  cin >> S >> T;
  
  map<char, char> mapsS;
  map<char, char> mapsT;
  
  for (int i = 0; i < S.length(); i++) {
    if (mapsS.find(S[i]) == mapsS.end()) {
      mapsS[S[i]] = T[i];
    }
    
    if (mapsT.find(T[i]) == mapsT.end()) {
      mapsT[T[i]] = S[i];
    }
    
    if (mapsS[S[i]] != T[i] || mapsT[T[i]] != S[i]) {
      ans = false;
      break;
    }
  }
  
  cout << (ans ? "Yes" : "No") << endl;
  
  return 0;
}

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

int main(){
    int N ,M;
    cin >> N >> M;
    int a;
    int count = 0;
    vector<int> A(N);
    int sum = 0;
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
        sum += A.at(i);
    }
    for(int i = 0; i < N; i++){
        if(A.at(i) >= (double)sum/(double)(4*M) ){
            count++;
        }
    }
    if(count >= M ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char const* argv[])
{
	int n,m;
	cin >> n >> m;
	VL a(n), b(n);
	priority_queue<LL> pqb; // bを降順ソート
	priority_queue<pair<LL,LL>, vector<PLL>, greater<PLL>> pqab;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		pqab.push({a[i],b[i]});
	}
	LL ans = 0;
	for (int i = 1; i <= m; i++) {
		while (!pqab.empty() and pqab.top().first == i) {
			pqb.push(pqab.top().second);
			pqab.pop();
		}
		if (!pqb.empty()) {
			ans += pqb.top();
			pqb.pop();
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
//#define che
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define MK make_pair
#define PB push_back
#define fi first
#define se second

typedef long long LL;
typedef pair<int, int> PII;
const int N=303;
const LL MOD= 998244353;
typedef bitset<N> bs;

bs a[N];
LL pw[N];
int n,m;



int main(){
	#ifdef che
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
	#endif
	scanf("%d%d", &n, &m);
	pw[0]=1;
	for (int i=1; i<N; ++i) pw[i]=(pw[i-1]<<1)%MOD;
	for (int i=0,x; i<n; ++i)
		for (int j=0; j<m; ++j){
			scanf("%d", &x);
			if ( x) a[i].flip(j);
		}
	
	for (int i=0,j=0; i<n && j<m; ++j){
		bool flag=false;
		for (int k=i; k<n; ++k)
			if ( a[k].test(j)){
				swap(a[i],a[k]);
				flag= true;break;
			}
		if ( flag){
			for (int k=i+1; k<n; ++k)
				if ( a[k].test(j)) a[k]^=a[i];
			++i;
		}
	}
	int fr=0;// free row
	for (int i=0; i<n; ++i) if ( a[i].count()==0) ++fr;
	LL ans= (pw[n]-pw[fr]+MOD)%MOD;
	ans=ans*pw[m-1]%MOD;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
N, L = list(map(int, input().split()))
As = list(map(int, input().split()))

sumL = sum(As)

l,r = 0, N-1
ans = []
cnt = 0

center = -1
for i in range(N-1):
    if As[i]+As[i+1]>=L:
        center = i+1
        break
if center < 0:
    print('Impossible')
else:
    print('Possible')
    for i in range(center-1):
        print(i+1)
    for i in range(N-1, center, -1):
        print(i)
    print(center)
# while sumL>=L and cnt < N-1:
#     # print(l,r,As[l],As[r])
#     if As[l] < As[r]:
#         # print('l<')
#         l += 1
#         sumL -= As[l]
#         ans.append(l)
#         cnt += 1
#     else:
#         # print('r<')
#         r -= 1
#         sumL -= As[r+1]
#         ans.append(r+1)
#         cnt += 1
#     # print('suml',sumL)
# if cnt==N-1:
#     print('Possible')
#     for _a in ans:
#         print(_a)
# else:
#     print('Impossible')


Measured memory_bytes: 14304
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int n,i,j,k,cnt[1005];
char s[200005];
long long ans;

int main()
{
	scanf("%s",s+1);n=strlen(s+1);
	ans=(long long)n*(n+1)/2+1;
	for(i=1;i<=n;++i)ans-=++cnt[s[i]];
	printf("%lld\n",ans);
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include <stdio.h>
using namespace std;
typedef long long ll;

int main() {
	double w, h, x, y,ans1,ans2,ans,flag=0;
	cin >> w >> h >> x >> y;
	if (x + x == w && y + y == h) {
		cout << w*h/2 << " 1" <<  endl;
	}
	else {
		cout << w * h / 2 << " 0" << endl;
	}
}


Measured memory_bytes: 256
program main
  implicit none
  integer :: n, i, j, sum = -1, csum = 0
  integer, allocatable :: x(:)

  read *, n
  allocate (x(n))
  read *, x

  do i = 1, 100
    csum = 0
    do j = 1, n
      csum = csum + (x(j) - i) ** 2
    end do
    if (csum < sum .or. i == 1) sum = csum
  end do
  print '(i0)', sum
end program

Measured memory_bytes: 640
h, w = map(int, input().split())

S = [[x for x in str(input())] for _ in range(h)]

for i in range(h):
    S[i].insert(0, '/')
    S[i].append('/')

S.insert(0, ['/']*(w+2))
S.append(['/']*(w+2))

count = 0

for j in range(1, h+1):
    for k in range(1, w+1):
        if S[j][k] == '#':
            count += 1
            if S[j-1][k].count('#') + S[j+1][k].count('#') + S[j][k-1].count('#') + S[j][k+1].count('#') >= 1:
                count -= 1

if count == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    points = list(map(string_to_int, inputs))
    points = [p for p in points if p[2] != 0]
    if len(points) == 1:
        return "{} {} {}".format(points[0][0], points[0][1], points[0][2])
    for top_x in range(101):
        for top_y in range(101):
            is_correct = True
            p = points[0]
            prev_h = max(p[2] + abs(p[0] - top_x) + abs(p[1] - top_y), 0)
            for [px, py, ph] in points:
                top_h = max(ph + abs(px - top_x) + abs(py - top_y), 0)
                if top_h != prev_h:
                    is_correct = False
                    break
            if is_correct:
                return "{} {} {}".format(top_x, top_y, prev_h)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)


Measured memory_bytes: 3316
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	int n;
	cin >> n;
	if (n % 2 == 0) {
		cout << n << endl;
	}
	else {
		cout << n * 2 << endl;
	}
}


Measured memory_bytes: 256
a,b = map(int, input().split())
s = list(input())
flg = True
for i in range(a+b+1):
    if(i!=a and s[i]=='-'):
        flg = False
        break
    elif(i==a and s[i]!='-'):
        flg = False
        break

if(flg):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
// https://atcoder.jp/contests/dp/tasks/dp_h

#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>

using namespace std;

int main (int argc, char* argv[]) {
	long long n;
	cin >> n;

	vector<double> dp(n + 1);
	dp[0] = 1.0;
	for (long long i = 0; i < n; i++) {
		double p;
		cin >> p;
		for (long long j = n; j >= 1; j--) {
			dp[j] += dp[j - 1] * p;
			dp[j - 1] *= 1.0 - p;
		}
	}
	double prob = 0.0;
	for (long long i = (n + 1) / 2; i < n + 1; i++) {
		prob += dp[i];
	}
	cout << setprecision(10) << prob << endl;
}


Measured memory_bytes: 256
while 1:
    s = input()
    if s=='#':
        break
    g, y, m, d=s.split()
    y=int(y)
    m=int(m)
    if y > 31:
        print('? ' + str(y-30) + ' ' + str(m) + ' ' + d)
    elif y == 31:
        if m > 4:
            print('? 1 ' + str(m) + ' ' + d)
        else:
            print('HEISEI 31 ' + str(m) + ' ' + d)
    else:
        print(s)


Measured memory_bytes: 5600
n,k=map(int,input().split())
if k>(n-1)*(n-2)//2:
  print(-1)
else:
  count=0
  now=2
  ans=[]
  for i in range(2,n+1):
    ans.append([1,i])
  now1=2
  while count<(n-1)*(n-2)//2-k:
    count+=1
    now1+=1
    if now1==n+1:
      now+=1
      now1=now+1
    ans.append([now,now1])
  print(len(ans))
  for i in ans:
    print(i[0],i[1])

Measured memory_bytes: 4120
rec = rho = 0
while True:
    try:
        a, b, c = map(int, input().split(','))
    except:
        break
    if a ** 2 + b ** 2 == c ** 2:
        rec += 1
    if a == b:
        rho += 1
print(rec, rho, sep='\n')

Measured memory_bytes: 7640
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=q
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)

n, m = map(int, input().split())
s=[]
c=[]
for i in range(m):
	_s, _c = map(int, input().split())
	s.append(_s-1)
	c.append(_c)

if m==0:
	if n==1:
		print(0)
		exit()

ans = -1
for i in range(1000):
	*t, = map(int, list(str(i)))

	if len(t) != n:
		continue

	ok = True
	for j in range(m):
		if t[s[j]]!=c[j]:
			ok = False
			break
 
	if ok:
		print(i)
		quit()

print(-1)

Measured memory_bytes: 3944
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define ff fflush(stdout)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	int n;
	cin>>n;
	cout<<(n-2)*180<<endl;
	return 0;
}


Measured memory_bytes: 896
#include<stdio.h>

int main(){
    int a, b;
    char op;
    scanf("%d %c %d", &a, &op, &b);
    while(op != '?'){
        switch(op){
            case '+':
                printf("%d\n", a+b);
                break;
            case '-':
                printf("%d\n", a-b);
                break;
            case '/':
                printf("%d\n", a/b);
                break;
            case '*':
                printf("%d\n", a*b);
                break;
        }
        scanf("%d %c %d", &a, &op, &b);  
    }
    return(0);
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> L(2 * N);
    rep(i, 2 * N) cin >> L[i];
    sort(L.begin(), L.end());
    int ans = 0;
    rep(i, N) ans += L[2 * i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int r, c;
	int buf, sum;
	vector<int> tmp;
	vector< vector<int> > mat;

	cin >> r >> c;

	for(int i = 0;i < r;i++) {
		sum = 0;

		for(int j = 0;j < c;j++) {
			cin >> buf;

			tmp.push_back(buf);
			sum += buf;
		}

		tmp.push_back(sum);
		mat.push_back(tmp);

		tmp.clear();
	}

	for(int i = 0;i < c + 1;i++) {
		sum = 0;

		for(int j = 0;j < r;j++) {
			sum += mat[j][i];
		}

		tmp.push_back(sum);
	}

	mat.push_back(tmp);

	for(int i = 0;i < r + 1;i++) {
		for(int j = 0;j < c + 1;j++) {
			cout << mat[i][j];

			if(j < c)
				cout << " ";
		}

		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3160
n, m = map(int, input().split())
l = [[] for _ in range(n)]
o = []
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    l[a] += [b]
if l[0] == [] and n >= 2:
    l[0] += [1]
elif n == 1 and l[0] == []:
    l[0] += [0]
if l[0] == [0] and n >= 2:
    print(-1)
    exit()
for j in range(n):
    if len(set(l[j])) > 1:
        print(-1)
        exit()
    if l[j] == []:
        l[j] += [0]
for k in l:
    o.append(str(k[0]))
ans = ''.join(o)
print(ans)

Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                String[] str = Console.ReadLine().Split(' ');
                int a = int.Parse(str[0]);
                int b = int.Parse(str[2]);
                String op = str[1];

                if (op == "+")
                {
                    Console.WriteLine(a + b);
                }
                else if (op == "-")
                {
                    Console.WriteLine(a - b);
                }
                else if (op == "*")
                {
                    Console.WriteLine(a * b);
                }
                else if (op == "/")
                {
                    Console.WriteLine(a / b);
                }
                else if (op == "?")
                {
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 5616
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    ans = 0

    for a in range(1, N):
        for b in range(1, N):
            x = a * b
            if x >= N:
                break
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9164
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[1000000];
int main()
{

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

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

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

        if(a[i]<=min1)
        {

            counttt++;
        }
        if(a[i]<min1)
        {
            min1=a[i];
        }
    }
    cout<<counttt<<'\n';







}


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

#define int long long
#define pb push_back
#define vec vector
#define endl '\n'
#define ss second
#define ff first

#define watch(x) cout<<#x<<" is "<<x<<endl;

#define MAX 200100
#define MOD 1000000007
#define INF 2100000000

using namespace std;

string s;
map < char, int > m;

int32_t main ()
{
    ios_base::sync_with_stdio ( 0 );
    cin.tie ( 0 ); cout.tie ( 0 );
    
	cin >> s;
	int n = s.size();

	for ( int i = 0; i < n; ++ i )
		m[s[i]] ++;

	int ans = 1+n*(n-1)/2;

	for ( auto i: m )
		ans -= i.ss*(i.ss-1)/2;

	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 720