akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X[] = new int[M];
		for(int i=0;i<M;i++) {
			X[i]=sc.nextInt();
		}
		Arrays.sort(X);
		if(N>=M) {
			System.out.println(0);
			return;
		}
		
		if(N==1) {
			System.out.println(X[M-1]-X[0]);
			return;
		}
		
		//M個の座標をN個の塊に分ける。
		//大きい間隔は避けたいので、M個の座標のうち最大間隔を求める。
		
		PriorityQueue pq = new PriorityQueue(1, new MeanComparator());
		for(int i=0;i<M-1;i++) {
			Mean mean = new Mean();
			mean.setFrom_point(X[i]);//元の位置
			mean.setTo_point(X[i+1]);
			mean.setLength(X[i+1]-X[i]);
			pq.add(mean);
		}
		int ans = 0;
		int fromP[] = new int[N-1];
		int toP[] = new int[N-1];
		for(int i=0;i<N-1;i++) {
			Mean tmp = (Mean)pq.poll();
			fromP[i] = tmp.getFrom_point();
			toP[i] = tmp.getTo_point();
		}
		
		Arrays.sort(fromP);
		Arrays.sort(toP);
		
		ans = fromP[0]-X[0];
		for(int i=1;i<N-1;i++) {
			ans += (fromP[i]-toP[i-1]);
		}
		ans += (X[M-1]-toP[N-2]);
		
		
		System.out.println(ans);
			
		}
		
		
 	}

	class Mean{
		private int from_point;
		private int to_point;
		private int length;
		public int getTo_point() {
			return to_point;
		}
		public void setTo_point(int to_point) {
			this.to_point = to_point;
		}
		public int getFrom_point() {
			return from_point;
		}
		public void setFrom_point(int from_point) {
			this.from_point = from_point;
		}
		public int getLength() {
			return length;
		}
		public void setLength(int length) {
			this.length = length;
		}
		
	}

	
	class MeanComparator implements Comparator{
		@Override
		public int compare(Object o1, Object o2) {
			Mean m1 = (Mean)o1;
			Mean m2 = (Mean)o2;
 			int c1 = m1.getLength();
 			int c2 = m2.getLength();
 					
 			if(c1>c2) {
 				return -1;
 			}else if(c1<c2) {
 				return 1;
 			}else {
 				return 0;
 			}
		}
		
	}



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

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  int books[n][m+1];
  for (int i = 0; i < n; i++){
    cin >> books[i][0];
    for (int j = 1; j <= m; j++){
      cin >> books[i][j];
    }
  }
  int ans =-1;
  for (int bit = 0; bit < (1<<n); ++bit) {
    vector<int> alg(m);
    int price = 0;
    for (int i = 0; i < n; ++i) {
      if (bit & (1<<i)) {
        price += books[i][0];
        for (int j = 0; j < m; j++){
          alg[j] = alg[j] + books[i][j+1];
        } 
      }
    }
    for (int j = 0; j < m; j++){
      if (alg[j] < x) {
        price = -1;
        break;
      }
    }
    if (price != -1) {
      if (ans == -1) {
        ans = price;
      } else {
        ans = min(ans, price);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec(n, 0);
  for (int i = 0; i < m; i++) {
    int j, k;
  	cin >> j >> k;
    vec.at(j-1)++;
    vec.at(k-1)++;
  }
  for (int i = 0; i < n; i++) {
    cout << vec.at(i) << endl;
  }
}

Measured memory_bytes: 256
line = input()
a, b, k = line.split(" ")
a = int(a)
b = int(b)
k = int(k)
 
if k >= a+b:
    print(0,0)
else:
    if a - k < 0:
        print(0, b-(k-a))
    else:
        print(a - k, b)
    


Measured memory_bytes: 2940
#!/usr/bin python3
# -*- coding: utf-8 -*-

INF = 10**6

n, m = map(int, input().split())
dp = [INF] * (2**n)
dp[0] = 0
for i in range(m):
    a, b = map(int, input().split())
    bit = ['0'] * n
    for x in set(map(int, input().split())):
        bit[x-1] = '1'
    bit = int(''.join(bit), 2)
    for j in range(2**n-1, -1, -1):
        dp[j|bit] = min(dp[j|bit], a + dp[j])
if dp[-1] == INF:
    print(-1)
else:
    print(dp[-1])


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

#define mp make_pair
#define pb push_back


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

using namespace std;

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
        cerr << (*i) << " ";
    }
    cerr << "\n";
}
const int INF = 1e9;

int n, m;
int ed[20][20];
int gg[1 << 16];
int dp[1 << 15][15];
int sm;

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            ed[i][j] = -INF;
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        ed[a][b] = ed[b][a] = c;
        sm += c;
    }
    for (int i = 1; i < (1 << n); ++i) {
        gg[i] = 0;
        for (int j = 0; j < n; ++j) {
            if ((i >> j) & 1)
                for (int k = j + 1; k < n; ++k)
                    if ((i >> k) & 1)
                        if (ed[j][k] > 0)
                            gg[i] += ed[j][k];
        }
    }
    for (int i = 0; i < (1 << n); ++i)
        for (int j = 0; j < n; ++j)
            dp[i][j] = -INF;
    for (int i = 1; i < (1 << n); ++i) {
        if (i % 2 == 0)
            continue;
        dp[i][0] = gg[i];
    }
    for (int i = 1; i < (1 << n); ++i) {
        for (int j = 0; j < n; ++j) {
            if (dp[i][j] < 0)
                continue;
            int msk = (1 << n) - 1 - i;
            for (int k = msk; k; k = (k - 1) & msk) {
                for (int l = 0; l < n; ++l) {
                    if (((k >> l) & 1) && ed[j][l] > 0)
                        dp[k | i][l] = max(dp[k | i][l], dp[i][j] + ed[j][l] + gg[k]);
                }
            }
        }
    }
    cout << sm - dp[(1 << n) - 1][n - 1] << "\n";
    return 0;
}




Measured memory_bytes: 2304
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int a, b;
    cin >> a >> b;
    cout << 6 - a - b << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define sz(a) int((a).size())
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define lp(i, a, b) for(ll i = a; i < b; i++)
#define lpr(i, a, b) for(ll i = a; i >= b; i--)
#define all(c) c.begin(), c.end()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
void yes(){
    cout << "YES" << endl;
}
void no(){
    cout << "NO" << endl;
}
void nl(){
    cout << endl;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int a, b;
    cin >> a >> b;
    int y = a*b;
    cout << y << endl;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 20;
int n, m;
vector<int> e[N];
int q[N], f, r;
int vis[N];
int check(int u) {
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i];
    if (!vis[v]) return v;
  }
  return -1;
}
int main() {
  while (cin >> n >> m) {
    bool flag = true;
    for (int i = 1; i <= n; i++) e[i].clear(), vis[i] = 0;
    int u, v;
    f = 1e5, r = 1e5 + 1;
    while (m--) {
      scanf("%d%d", &u, &v);
      e[u].push_back(v);
      e[v].push_back(u);
      if (flag) {
        flag = false;
        vis[u] = vis[v] = 1;
        q[f] = u;
        q[r] = v;
      }
    }

    while (true) {
      int u = check(q[f]);
      if (u == -1)
        break;
      else {
        q[--f] = u;
        vis[u] = 1;
      }
    }
    while (true) {
      int u = check(q[r]);
      if (u == -1)
        break;
      else {
        q[++r] = u;
        vis[u] = 1;
      }
    }
    cout << r - f + 1 << endl;
    while (f <= r) printf("%d ", q[f++]);
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 9472
#include<bits/stdc++.h>
using namespace std;
int main(void){
		#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
 	string s,t;
  	cin>>s>>t;
  	if(t.length()<=s.length()||t.length()>s.length()+1)
      cout<<"No";
  else{
    string ans=(s==t.substr(0,s.length()))?"Yes":"No";
    cout<<ans;
	}
}


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

int main(){
int n;cin>>n;
  int h1,h2,c,ans;
  cin>>h1;
  ans=c=0;
  for(int i=0;i<n-1;i++){
  	cin>>h2;
    if(h1<h2){
      c=0;
    }else{c++;}
    ans=max(c,ans);
  	h1=h2;
  }
  cout <<ans<<endl;
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N, M; cin >> N >> M;
    vector<vector<int>> adList(N);
    map<pair<int, int>, LLONG> edge2WeightMap;
    for (int i = 0; i < M; ++i)
    {
        int l, r, d; cin >> l >> r >> d; --l; --r;
        adList[l].push_back(r);
        adList[r].push_back(l);
        edge2WeightMap.insert({ { l, r }, -d });
        edge2WeightMap.insert({ { r, l }, d });
    }
    // DFSで全ての頂点に適当な座標値を与える:O(N+M)
    vector<LLONG> xs(N);
    vector<bool> notVisited(N, true);
    for (int s = 0; s < N; ++s)
    {
        if (notVisited[s])
        {
            notVisited[s] = false;
            xs[s] = 0;  // 座標値のスタート値は任意
            deque<int> Q{ s };
            while (!Q.empty())
            {
                int v = Q.front(); Q.pop_front();
                for (const int n : adList[v])
                {
                    if (notVisited[n])
                    {
                        notVisited[n] = false;
                        xs[n] = xs[v] + edge2WeightMap[{v, n}];
                        Q.push_back(n);
                    }
                }
            }
        }
    }
    // 改めて全ての辺に対し矛盾がないかチェック:O(M)
    bool isOK = true;
    for (const auto &kvp : edge2WeightMap)
    {
        int v = kvp.first.first, u = kvp.first.second;
        int w = kvp.second;
        if (xs[u] - xs[v] != w)
        {
            isOK = false;
            break;
        }
    }
    cout << (isOK ? "Yes" : "No") << endl;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  vi h(n); rep(i, n) std::cin >> h[i];
  vi dp(n, inf);
  dp[0] = 0;
  rep(i, n) {
    if (i+1 < n) chmin(dp[i+1], dp[i]+abs(h[i]-h[i+1]));
    if (i+2 < n) chmin(dp[i+2], dp[i]+abs(h[i]-h[i+2]));
  }
  std::cout << dp[n-1] << "\n";
}


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

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a;

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

		a.push_back(aa);
	}

	sort(a.begin(), a.end());

	long long candidate0 = 0;
	int next = -1;

	for (int i = n - 1; i >= 1; i--) {
		if (a[i] == a[i - 1]) {
			candidate0 = a[i];
			next = i - 2;
			break;
		}
	}

	long long candidate1 = 0;

	for (int i = next; i >= 1; i--) {
		if (a[i] == a[i - 1]) {
			candidate1 = a[i];
			break;
		}
	}

	cout << candidate0 * candidate1 << endl;




	return 0;
}



Measured memory_bytes: 892
import collections
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(M)]

ans = [0]*N
G = [set() for i in range(N)]
for a, b in AB:
    a -= 1
    b -= 1
    G[a].add(b)
    G[b].add(a)

q = collections.deque([0])

r = set()
r.add(0)
while(q):
    x = q.popleft()
    for y in G[x]:
        if y in r:
            continue
        else:
            ans[y] = x+1
            r.add(y)
            q.append(y)

if len(r) < N:
    print('No')
else:
    print("Yes")
    print(*ans[1:], sep='\n')


Measured memory_bytes: 97924
n=int(input())
s=[int(input()) for i in range(n)]

s.sort()
S=sum(s)

if S%10!=0:
    print(S)
else:
    for num in s:
        if num%10!=0:
            S-=num
            if S%10!=0:
                print(S)
                exit()

    print(0)  

Measured memory_bytes: 3060
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN   
#define linf LLONG_MAX
#define lninf LLONG_MIN   
const ll mod=1e9+7;
const int N=1e5+4;
 
ll fac[N],infac[N];
 
ll me(ll a,ll b)
{
    ll res=1;
 
    while(b)
    {
        if(b&1)
        res=(res*a)%mod;
 
        b>>=1;
 
        a=(a*a)%mod;
    }
 
    return res;
}
 
ll mi(ll a)
{
    return me(a,mod-2);
}
 
void factorial()
{
   fac[0]=1;
 
   for(ll i=1;i<N;i++)
   fac[i]=(i*fac[i-1])%mod;
 
   infac[N-1]=mi(fac[N-1]);
 
   for(ll i=N-1;i>=1;i--)
   infac[i-1]=(i*infac[i])%mod;
}
 
ll ncr(ll n,ll r)
{
    if(n<r)
    return 0;
 
    ll val=fac[n];
 
    val=(val*infac[r])%mod;
 
    val=(val*infac[n-r])%mod;
 
    return val;
}
 
int main()
{
	factorial();

	int sum; scn(sum);

	ll ans = 0;

	for(int len = 1;3*len <= sum;len++)
	{
		int nsum = sum - 3*len;

		ll here = ncr(nsum+len-1,len-1);

		ans = (ans + here)%mod;
	}

	lpri(ans);
}

Measured memory_bytes: 5380
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;
#define ll long long
#define ld long double


int main() {
	
	int n;
	cin >> n;
	vector<int> a(4, 0);
	string cur;
	for (int i = 0; i < n; i++) {
		cin >> cur;
		if (cur == "AC")a[0]++;
		if (cur == "WA")a[1]++;
		if (cur == "TLE")a[2]++;
		if (cur == "RE")a[3]++;
	}
	cout << "AC x " << a[0] << endl;
	cout << "WA x " << a[1] << endl;
	cout << "TLE x " << a[2] << endl;
	cout << "RE x " << a[3] << endl;
	return 0;
}

Measured memory_bytes: 3252
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), cout, ", ") << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, ostream &os = cout, string sep = " ")
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), os, ", ") << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, L);
    FOUT(pow(L / 3.0, 3));
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(x) cout<<x<<endl

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF = 1e18;
const int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

//function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();
LL ave(LL, LL);

int main() {
	string s; cin >> s;
	s[3] = '8';
	cout << s;
}

LL gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}
bool isEven(LL a) {
	return !((bool)(a % 2));
}
void coutY() {
	cout << "Yes" << endl;
	return;
}
void coutN() {
	cout << "No" << endl;
	return;
}
LL ave(LL a, LL b) {
	return (a + b) / 2;
}

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

int main(){
  int n, num = 0;
  cin >> n;
  vector<int> a(n);
  rep(i, n, 0) cin >> a[i];
  
  rep(i, n, 0){
    if(a[i] != i+1) num++;
  }
  
  if(num > 2) cout << "NO" << endl;
  else cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int A[100100];

int main() {
    long long H, N;
    cin >> H >> N;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        H -= A[i];
    }
    if (H > 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>

using namespace std;

int main() {
	int N, K;
	int r, s, p;
	string t;
	cin >> N >> K;
	cin >> r >> s >> p;
	cin >> t;
	string player = "";
	map<char, pair<char, int>> mp;
	mp['r'] = make_pair('p', p);
	mp['s'] = make_pair('r', r);
	mp['p'] = make_pair('s', s);
	int score = 0;
	for (int i = 1; i <= N; ++i) {
		if (i <= K) {
			player += mp[t[i - 1]].first;
			score += mp[t[i - 1]].second;
		}
		else if(N - K < i){
			if (player[i - K - 1] != mp[t[i - 1]].first) {
				score += mp[t[i - 1]].second;
			}
		}
		else {
			if (player[i - K - 1] != mp[t[i - 1]].first) {
				score += mp[t[i - 1]].second;
				player += mp[t[i - 1]].first;
			}
			else {
				score += mp[mp[t[i + K - 1]].second].second * 0;
				player += mp[mp[t[i + K - 1]].second].first;
			}
		}
	}
	cout << score << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    string A;
    cin >> A;
    if (isupper(A[0])) {
        cout << "A" << endl;
    } else {
        cout << "a" << endl;
    }
    return 0;
}



Measured memory_bytes: 3624
fun main (args:Array<String>){
    val (a , b , c , k) = readLine()!!.split(" ").map(String::toLong)
    var maxVal = 0L
    if(a < k) {
        maxVal += a * 1
//        print(maxVal)
        if(b > k - a || b == k - a) {
            maxVal += (k - a) * 0
            print(maxVal)
            return
        }
        // OK
        if(b < k - a){
//            print((k - a - b) * -1)
            maxVal += (k - a - b) * -1
            print(maxVal)
            return
        }
    }
    // OK
    if(a == k){
        maxVal += a * 1
        print(maxVal)
        return
    }
    if(a > k){
        maxVal +=  (a - (a - k)) * 1
        print(maxVal)
        return
     }
}

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

#define ll long long int
#define ld long double
#define u128 __int128 
#define ff first
#define ss second
#define pb push_back
#define PI 3.141592653589793

#define MOD 1000000007
#define N 10100
#define M 1000010

int main() 
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(10);

	double a, b;
	cin >> a >> b;
	cout << fixed << a /b;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int h, w;
	cin >> h >> w;
	char a[110][110];
	for(int i = 0; i <= h + 1; i++){
		for(int j = 0; j <= w + 1; j++){
			a[i][j] = '#';
		}
	}
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++){
			cin >> a[i][j];
		}
	}

	for(int i = 0; i <= h + 1; i++){
		for(int j = 0; j <= w + 1; j++){
			cout << a[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;

	string S[200];
	rep(i, N) cin >> S[i];

	int D[200][200] = {};
	rep(i, N) rep(j, N) {
		if (i == j) D[i][j] = 0;
		else if (S[i][j] == '1') D[i][j] = 1;
		else D[i][j] = 1e9;
	}

	rep(k, N) rep(i, N) rep(j, N) {
		D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
	}

	int guuki[200];
	guuki[0] = 0;
	rep1(i, N - 1) {
		guuki[i] = (D[0][i] + guuki[0]) % 2;
	}

	int OK = 1;
	int saidai = 0;
	rep(i, N) {
		for (int j = i + 1; j < N; j++) {
			saidai = max(saidai, D[i][j]);
			if ((guuki[i] + guuki[j] + D[i][j]) % 2) {
				OK = 0;
			}
		}
	}

	if (OK) co(saidai + 1);
	else co(-1);



	Would you please return 0;
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, m;
  cin >> n >> m;

  vll ans(n, 0);

  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    ans[a]++;
    ans[b]++;
  }

  rep(i, n) { cout << ans[i] << endl; }

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
char M[100][101];
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int H,W;
void dfs(int x,int y) {
	char ch=M[y][x];
	M[y][x]=' ';
	for(int i=0;i<4;i++) {
		int nx=x+dx[i],ny=y+dy[i];
		if(0>nx||nx>=W||0>ny||ny>=H)continue;
		if(M[ny][nx]!=ch)continue;
		dfs(nx,ny);
	}
}
int main() {
	while(scanf("%d %d",&H,&W),H) {
		for(int h=0;h<H;h++) {
			scanf("%s",M[h]);
		}
		int sum=0;
		for(int h=0;h<H;h++) {
			for(int w=0;w<W;w++) {
				if(M[h][w]!=' ') {
					sum++;
					dfs(w,h);
				}
			}
		}
		printf("%d\n",sum);
	}
}

Measured memory_bytes: 1504
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
#define N_MAX 200002
typedef pair<ll, ll> P;

const ll MOD = 1000000007;

ll pow[N_MAX];

void init(){
    pow[0] = 1;
    for(int i=1;i<N_MAX;i++){
        pow[i] = pow[i-1]*2;
        pow[i] %= MOD;
    }
}

ll inv_(ll n){
    if(n == 1) return 1;
    else return MOD-inv_(MOD%n)*(MOD/n)%MOD;
}

P add(P a, P b){
    P ans;
    ans.first = (a.first*b.second+a.second*b.first)%MOD;
    ans.second = (a.second*b.second)%MOD;
    return ans;
}

P sub(P a, P b){
    P ans;
    ans.first = ((a.first*b.second-a.second*b.first)%MOD+MOD)%MOD;
    ans.second = (a.second*b.second)%MOD;
    return ans;
}

P mul(P a, P b){
    P ans;
    ans.first = (a.first*b.first)%MOD;
    ans.second = (a.second*b.second)%MOD;
    return ans;
}

vector<int> cnt[200000], G[200000];
bool used[200000];
int N;

int dfs(int v){
    used[v] = true;
    int sum = 1;
    for(int i = 0; i < G[v].size(); i++){
        if(!used[G[v][i]]){
            int tmp = dfs(G[v][i]);
            sum += tmp;
            cnt[v].push_back(tmp);
        }
    }
    cnt[v].push_back(N-sum);
    return sum;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    init();
    for(int i = 0; i < N-1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0);
    P ans = P(0, 1);
    for(int i = 0; i < N; i++){
        P tmp = P(1, 2);
        P all = P(1, 1);
        if(G[i].size() == 1) continue;
        for(int j = 0; j < cnt[i].size(); j++){
            if(cnt[i][j] == 0) continue;
            all = mul(all, P(1, pow[cnt[i][j]]));
        }
        P one = P(0, 1);
        for(int j = 0; j < cnt[i].size(); j++){
            if(cnt[i][j] == 0) continue;
            P tmp_ = mul(all, P(pow[cnt[i][j]], 1));
            tmp_ = mul(tmp_, P(pow[cnt[i][j]]-1, pow[cnt[i][j]]));
            // cout << tmp_.first << ' ' << tmp_.second << endl;
            one = add(one, tmp_);
        }
        tmp = mul(tmp, sub(P(1, 1),add(all, one)));
        // cout << all.first << ' ' << all.second << endl;
        // cout << one.first << ' ' << one.second << endl;
        ans = add(ans, tmp);
        // cout << ans.first << ' ' << ans.second << endl;
    }
    ll s = ans.first;
    ll t = ans.second;
    // cout << s << ' ' << t << endl;
    cout << (s*inv_(t))%MOD << endl;
}

Measured memory_bytes: 37248
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] og = new int[n];
		int[] srt = new int[n];
		for( int i = 0; i < n; i++ ) {
			og[i] = in.nextInt();
			srt[i] = og[i];
		}
		
		Arrays.sort(srt);
		int med = (int) n/2;
		HashMap<Integer, Integer> hm = new HashMap<>();
		
		for( int i = 0; i < n; i++ ) {
			if( i == med ) med--;
			hm.putIfAbsent(srt[i], srt[med]);
		}
		
		for( int i = 0; i < n; i++ ) {
			System.out.println(hm.get(og[i]));
		}
	}
}

Measured memory_bytes: 109896
list1=[]
for i in range(5):
    a=int(input())
    list1.append(a)
    
#print(list1)

if list1[0]<0:
    ans=(0-list1[0])*list1[2]+list1[3]+list1[1]*list1[4]
else:
    ans=(list1[1]-list1[0])*list1[4]
print(ans)
    


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define ll long long
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define pi pair<int,int>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;

ll n,x;

ll lay(ll n)
{
    if (n==0) return 1;
    else return lay(n-1)*2+3;
}

ll pat(ll n)
{
    if (n==0) return 1;
    else return pat(n-1)*2+1;
}

ll eat(ll n, ll x)
{
    if (x==1)
    {
        if (n) return 0;
        else return 1;
    }
    else if (x<=lay(n-1)+1) return eat(n-1,x-1);
    else if (x==lay(n-1)+2) return pat(n-1)+1;
    else if (x<=2+lay(n-1)*2) return pat(n-1)+1+eat(n-1,x-lay(n-1)-2);
    else return pat(n);
}

int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> x;
    cout << eat(n,x);
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    x, y = map(int, readline().split())
    if x * y >= 0:
        if x < y:
            print(y - x)
        else:
            print(x - y + 2 if x * y > 0 else x - y + 1)
    else:
        print(abs(abs(x) - abs(y)) + 1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#define MAX 2001
typedef long long ll;
ll N, A[MAX];
ll hash[MAX];
ll DP[MAX][MAX];

ll max(ll x, ll y)
{
if (x > y)
return x;
else
return y;
}

void swap(ll * a, ll * b)
{
ll buf = *a;
*a = *b;
*b = buf;
}

void solve(ll x, ll y)
{
//枝刈り N + 1以上は詰められない
if (x + y >= N + 1)
return;
//枝刈り 下のDPができてなければやる意味ない
if (DP[x][y - 1] < 0 || DP[x - 1][y] < 0)
return;
DP[x][y] =
max(DP[x][y - 1] + A[x + y] * (hash[x + y] - y),
DP[x - 1][y] + A[x + y] * (N + 1 - x - hash[x + y]));
//とりま累乗で生成
solve(x, y + 1);
solve(x + 1, y);
}

ll main()
{
scanf("%lld", &N);
for (ll i = 1; i <= N; i++) {
scanf("%lld", A + i);
hash[i] = i;
}
for (ll i = 1; i <= N; i++) {
for (ll j = 1; j < i; j++) {
if (A[j] < A[i]) {
swap(A + i, A + j);
swap(hash + i, hash + j);
}
}
}
memset(DP, -1, sizeof(DP));
DP[0][0] = 0;
for (ll i = 1; i <= N; i++) {
DP[0][i] = DP[0][i - 1] + A[i] * (hash[i] - i);
DP[i][0] = DP[i - 1][0] + A[i] * (N + 1 - i - hash[i]);
}
solve(1, 1);
ll ans = 0;
for (ll i = 0; i <= N; i++)
ans = max(ans, DP[i][N - i]);
printf("%lld", ans);
}


Measured memory_bytes: 33112
#include <iostream>
#include <vector>
#define T 1000
#define M 1000000007
using namespace std;
typedef long long ll;
 
ll func(int);
 
int N,s,t;
string n[T];
vector<int> edge[T];
 
int main(){
  cin>>N;
  for(int i=0;i<N;i++) cin>>n[i];
  for(int i=0;i<N-1;i++) cin>>s>>t,edge[s-1].push_back(t-1);
  cout<<func(0)%M<<endl;
  return 0;
}

ll func(int x){
  ll res=0,res2=1;
  if(!edge[x].size()){
    if(n[x]=="E") return 1;
    if(n[x]=="E?") return 2;
    return 0;
  }
  if(n[x][0]=='E'){
    for(int i=0;i<edge[x].size();i++) res2*=func(edge[x][i]);
    if(n[x]=="E?") res2++;
    return res2%M;
  }
  if(n[x][0]=='A'){
    for(int i=0;i<edge[x].size();i++) res+=func(edge[x][i]);
    if(n[x]=="A?") res++;
    return res%M;
  }
  if(n[x][0]=='R'){
    for(int i=0;i<edge[x].size();i++) res2*=(1+func(edge[x][i]));
    if(n[x]=="R") res2--;
    return res2%M;
  }
}

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

typedef long long ll;
typedef unsigned long long ull;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int P,R,T;
int init[303];
int need[303][303];
int p[200001],r[200001];

bool f(int t){
  vector<int> crtr(R);
  vector<vector<int> > crtp(P,vector<int>(R));
  vector<int> crtnz(P,0);
  vector<bool> used(P,false);

  rep(i,R)crtr[i]=init[i];
  rep(i,P)rep(j,R)crtp[i][j]=need[i][j];
  rep(i,P)rep(j,R)if(crtp[i][j]==0)crtnz[i]++;
  rep(i,t){
    crtr[r[i]]--;
    crtp[p[i]][r[i]]--;
    if(crtr[r[i]]<0)return false;
    if(crtp[p[i]][r[i]]==0)crtnz[p[i]]++;
    if(crtnz[p[i]]==R){
      used[p[i]]=true;
      rep(j,R)crtr[j]+=need[p[i]][j];
    }
  }

  bool update=true;
  while(update){
    update=false;
    rep(i,P){
      if(used[i])continue;
      bool ok=true;
      rep(j,R)if(crtp[i][j]>crtr[j])ok=false;
      if(!ok)continue;
      rep(j,R)crtr[j]+=need[i][j]-crtp[i][j];
      used[i]=true;
      update=true;
      break;
    }
  }
  bool ok=true;
  rep(i,P)if(!used[i])ok=false;
  return ok;
}

int main(){
  scanf("%d%d%d",&P,&R,&T);
  rep(i,R)scanf("%d",init+i);
  rep(i,P)rep(j,R)scanf("%d",&need[i][j]);
  rep(i,T){
    scanf("%d%d",p+i,r+i);
    p[i]--;r[i]--;
  }

  int lb=0,ub=T+1;
  while(ub-lb>1){
    int mid=(lb+ub)/2;
    if(f(mid))lb=mid;
    else ub=mid;
  }
  if(ub==T+1)cout<<-1<<endl;
  else cout<<ub<<endl;
  return 0;
}



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

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

    vector<int> w(n);

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

    int mini = sum;
    int sumi = 0;
    for(int i = 0; i < n; i++){
        sumi += w[i];
        mini = min(mini, abs(sumi - (sum - sumi)));
    }

    cout << mini << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}


int main() {
    string s;cin>>s;
    ll n=s.size();
    vector<int> dp(1<<26,INF);
    dp[0]=0;
    int now=0;
    rep(i,n){
        now^=1<<(s[i]-'a');
        int res=dp[now];
        rep(j,26)chmin(res,dp[now^(1<<j)]);
        chmin(dp[now],res+1);
        if(i==n-1)out(res+1);
    }
}


Measured memory_bytes: 265796
#include <stdio.h>
#include <string.h>

int main(void) {
	int n;
	int square[16][16];
	int table[16][16];

	scanf("%d", &n);
	while(n) {
		int i, j;
		int m = 1;
		i = j = n / 2;
		i++;
		memset(square, 0, sizeof(table));

		while(m <= n * n) {
			if(i >= n)
				i = 0;
			if(j >= n)
				j = 0;
			else if(j < 0)
				j = n - 1;

			while(square[i][j]) {
				i++; j--;
				if(i >= n)
					i = 0;
				if(j >= n)
					j = 0;
				else if(j < 0)
					j = n - 1;
			}

			square[i][j] = m;
			i++; j++; m++;
		}

		for(i = 0; i < n; i++) {
			for(j = 0; j < n; j++) {
				printf("% 4d", square[i][j]);
			}
			putchar('\n');
		}
		scanf("%d", &n);
	}

	return 0;
}

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

int main() {
    int n; cin >> n;
    if(n == 2) {
        int a, b; cin >> a >> b;
        int m = __gcd(a, b);
        for(int i = 1; i <= m; i++) {
            if(a % i == 0 && b % i == 0) {
                cout << i << endl;
            }
        }
    }
    else {
        int a, b, c; cin >> a >> b >> c;
        int m = __gcd(__gcd(a, b), c);
        for(int i = 1; i <= m; i++) {
            if(a % i == 0 && b % i == 0 && c % i == 0) {
                cout << i << endl;
            }
        }
    }
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(void) 
{
  int i, n, amount = 100000;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    amount *= 1.05;

    if (amount % 1000 != 0) 
      amount = amount - amount % 1000 + 1000;
  }

  printf("%d\n", amount);

  return 0;
}

Measured memory_bytes: 592
#include <iostream>
using namespace std;
#define MAX 1000000
struct Node {
	int parent, left, right, key,root;
};
Node *T;
void maxHeap(int i) {
	int largest;
	int l = 2*i+1;
	int r = 2*i+2;
	if (l<T[i].root && T[l].key>T[i].key) {
		largest = l;
	}
	else {
		largest = i;
	}
	if (r<T[i].root && T[r].key>T[largest].key) {
		largest = r;
	}
	if (largest != i) {
		Node tmp = T[i];
		T[i] = T[largest];
		T[largest] = tmp;
		maxHeap(largest);
	}
}
int main() {
	int n,id, max = 0;;
	cin >> n;
	T=new Node[2*n];
	for (int i = 0; i < n; i++) {
		cin >> id;
		T[i].key = id;
		T[i].root=n;
	}
	for (int i = 0; i < n; i++) {
		T[i].left = T[2 * i + 1].key;
		T[i].right = T[2 * i + 2].key;
		T[2 * i + 1].parent = T[i].key;
		T[2 * i + 2].parent = T[i].key;
	}
	for(int i=n/2;i>=0;i--){
	    maxHeap(i);
	}
	for (int i = 0; i < n; i++) {
		cout << " " << T[i].key;
	}
	cout << endl;
	
}


Measured memory_bytes: 22628
//{Headers
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<string>
#include<algorithm>
#include<list>
#include<queue>
#include<deque>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<bitset>

using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
#define mp(x,y) make_pair(x,y)
typedef long long ll;
//}

const int MAXN=1e6;
int N,nPrime[MAXN];

bool isPrime[MAXN];
void EratosthenesSeive(){
    memset(isPrime,true,sizeof isPrime);
    isPrime[0]=isPrime[1]=false;
    for(int i=2;i<MAXN;i++) if(isPrime[i]){
        for(int j=i<<1;j<MAXN;j+=i)
            isPrime[j]=false;
    }
}

void init(){
    EratosthenesSeive();
    nPrime[0]=0;
    for(int i=1;i<MAXN;i++) nPrime[i]=nPrime[i-1]+(isPrime[i]?1:0);
}

void solve(){printf("%d\n",nPrime[N]);}

int main(void){
//    freopen("in.txt","r",stdin);
    init();
    while(~scanf("%d",&N))
        solve();
    return 0;
}

/*
Sample Input
10
3
11
Output for the Sample Input
4
2
5
*/



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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int dp[101][4][2];
// dp[i][j][k]
// i個までの桁を見ている時
// j個の非ゼロを使い
// k:0なら今の所Nと一致
// k:1ならすでにN以下が確定している

int main(){
  string s;cin>>s;
  int k;cin>>k;
  int n=s.size();
  dp[0][0][0]=1;

  rep(i, n)rep(j, 4)rep(kk, 2){
    int c = s[i]-'0';
    rep(d, 10){
      int ni=i+1, nj=j, nk=kk;
      if(d!=0)nj++; // 非0が増えたのでインクリメント
      if(nj>3)continue; //配列に収まりきらないので無視

      if(kk==0){
        if(d>c)continue; // 着目中の数値がnの桁よりも大きければN超過確定なので無視
        if(d<c) nk=1; // 桁同士の比較がこれまでNと同じで、着目中の桁で初めて下回ったのでN以下確定。
      }

      dp[ni][nj][nk] += dp[i][j][kk];
    }
  }

//  cout<<dp[n][k][1]<<' '<<dp[n][k][0]<<endl;
  cout<<dp[n][k][1]+dp[n][k][0]<<endl;

  return 0;
}

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

fn next_token<R: Read>(reader: &mut R) -> Vec<u8> {
    let mut buf: [u8; 1] = [0];
    let mut read_chars = false;
    let mut ret: Vec<u8> = vec![];

    loop {
        if reader.read(&mut buf).unwrap() == 0 {
            break;
        } else {
            if buf[0] == '\r' as u8 || buf[0] == '\n' as u8 || buf[0] == ' ' as u8 {
                if read_chars {
                    break;
                }
            } else {
                read_chars = true;
                ret.push(buf[0]);
            }
        }
    };
    ret
}
fn next_i64<R: Read>(reader: &mut R) -> i64 {
    let token = next_token(reader);
    let mut ret: i64 = 0;
    let mut sgn = false;

    for c in token {
        if '0' as u8 <= c && c <= '9' as u8 {
            ret = ret * 10 + (c - ('0' as u8)) as i64;
        } else if '-' as u8 == c {
            sgn = true;
        }
    };
    ret * if sgn { -1 } else { 1 }
}
fn next_i32<R: Read>(reader: &mut R) -> i32 {
    next_i64(reader) as i32
}

fn main() {
    let buf = &mut BufReader::new(io::stdin());

    let n = next_i32(buf);
    let mut a = vec![];
    for _ in 0..n {
        a.push(next_i64(buf));
    }

    let mut ret1 = 0 as i64;
    let mut sum = 0 as i64;
    for i in 0..n {
        sum += a[i as usize];
        if i % 2 == 0 {
            // target: +
            let diff = cmp::max(0, 1 - sum);
            sum += diff;
            ret1 += diff;
        } else {
            // target: -
            let diff = cmp::max(0, sum + 1);
            sum -= diff;
            ret1 += diff;
        }
    //    println!("{} {}", ret1, sum);
    }
    let mut ret2 = 0 as i64;
    let mut sum = 0 as i64;
    for i in 0..n {
        sum += a[i as usize];
        if i % 2 == 1 {
            // target: +
            let diff = cmp::max(0, 1 - sum);
            sum += diff;
            ret2 += diff;
        } else {
            // target: -
            let diff = cmp::max(0, sum + 1);
            sum -= diff;
            ret2 += diff;
        }
    }

    println!("{}", cmp::min(ret1, ret2));
}


Measured memory_bytes: 4352
#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>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void makegraph(int x,vector<vec> &v){rep(i,x-1){int a=in(),b=in();v[a].pb(b);v[b].pb(a);}}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 255050

ll n,m,k;

vec G[N];
int who[N];
ll a[N],b[N];
vec V[N];
int visited[N];
int ans[N];
int mem[N];
main(){
    n=in();m=in();
    rep(i,m+n-1){
        int x=in(),y=in();
        G[x].pb(y);
        V[y].pb(x);
    }
    int top=1;
    while(V[top].size())top=V[top][0];
    vec now,temp;
    now.pb(top);
    visited[top]=1;
    rep2(i,1,n)mem[i]=V[i].size();
    while(now.size()){
        for(auto e:now){
            for(auto c:G[e]){
                mem[c]--;
                if(mem[c]==0){
                    ans[c]=e;
                    temp.pb(c);
                }
            }
        }
        now=temp;
        vec aaa;
        temp=aaa;
    }
    rep2(i,1,n)cout<<ans[i]<<endl;
}

Measured memory_bytes: 23680