akhauriyash/Code-Regression huggingface dataset:
module Main where

import qualified Data.Vector.Unboxed.Mutable   as VUM
import qualified Data.Vector.Unboxed           as VU
import           Control.Monad.Primitive
import qualified Data.ByteString.Char8         as BS
import qualified Data.ByteString.Lazy.Char8    as BSL
import qualified Data.ByteString.Builder       as BSB
import           Data.Char                      ( isSpace )
import           Data.List                      ( unfoldr )


main :: IO ()
main = do
  [n, m] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  pairs <- VU.replicateM m $ (\v -> (v VU.! 0 - 1, v VU.! 1 - 1)) . VU.unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  uf <- initUf n
  uf' <- VU.foldM (\uf (a, b) -> uniteUf uf a b) uf pairs
  sizes <- mapM (sizeUf uf') [0..n-1]
  print $ maximum sizes

data UnionFind s = UnionFind
  { parent :: VUM.MVector s Int
  , size :: VUM.MVector s Int
  }

-- Vector internally uses 0-indexed

initUf :: PrimMonad m => Int -> m (UnionFind (PrimState m))
initUf n = UnionFind <$> VU.thaw (VU.enumFromN 0 n) <*> VUM.replicate n 1

rootUf
  :: PrimMonad m
  => UnionFind (PrimState m)
  -> Int
  -> m (UnionFind (PrimState m), Int)
rootUf uf x = do
  px <- VUM.read (parent uf) x
  if px == x
    then return (uf, x)
    else do
      (UnionFind parent' size', rx) <- rootUf uf px
      VUM.write parent' x rx
      return (UnionFind parent' size', rx)

sameUf
  :: PrimMonad m
  => UnionFind (PrimState m)
  -> Int
  -> Int
  -> m (UnionFind (PrimState m), Bool)
sameUf uf x y = do
  (uf' , rx) <- rootUf uf x
  (uf'', ry) <- rootUf uf' y
  return (uf'', rx == ry)

uniteUf
  :: PrimMonad m
  => UnionFind (PrimState m)
  -> Int
  -> Int
  -> m (UnionFind (PrimState m))
uniteUf uf x y = do
  (uf'                           , x') <- rootUf uf x
  (uf''@(UnionFind parent' size'), y') <- rootUf uf' y
  if x' == y'
    then return uf''
    else do
      sizeX <- VUM.read size' x'
      sizeY <- VUM.read size' y'
      if sizeX < sizeY
        then do
          VUM.write parent' x' y'
          VUM.write size' y' (sizeX + sizeY)
          return $ UnionFind parent' size'
        else do
          VUM.write parent' y' x'
          VUM.write size' x' (sizeX + sizeY)
          return $ UnionFind parent' size'

sizeUf :: PrimMonad m => UnionFind (PrimState m) -> Int -> m Int
sizeUf uf x = do
  (UnionFind _ size', x') <- rootUf uf x
  VUM.read size' x'


Measured memory_bytes: 23168
/* kadai5_3
   nabe9393 */

#include <stdio.h>

int main(void){
  int height, width, i, j;
  scanf("%d %d", &height, &width);
  int row[height],column[width];
  char square[height][width];
  for(i=0;i<height;i++){
    for(j=0;j<width;j++){
      scanf(" %c",&square[i][j]);
      row[i]=0;
      column[j]=0;
    }
  }
  for(i=0;i<height;i++){
    for(j=0;j<width;j++){
      if(square[i][j]=='#'){
        row[i]=1;
        column[j]=1;
      }
    }
  }
  for(i=0;i<height;i++){
    if(row[i]==1){
      for(j=0;j<width;j++){
        if(column[j]==1){
          printf("%c",square[i][j]);
        }
      }
    printf("\n");
    }
  }
  return 0;
}

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

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

int main()
{
	// freopen("input.in", "r", stdin);

	int n, m;
	cin >> n >> m;
	int sum = 0;
	for(int i = 1; i <= m; i++)
	{
		int x; cin >> x;
		sum += x;
	}
	if(sum >= n) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 256
while true
    str = gets.chomp
    if str == "-"
        break
    else
        gets.to_i.times do
            shuflle_start_index = gets.to_i
            str = str[shuflle_start_index...str.size] + str[0...shuflle_start_index]
        end
        puts str
    end
end


Measured memory_bytes: 6880
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

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

ll lcm(ll a,ll b){
    if(a==0||b==0){
        return 0;
    }
    return a*b/gcd(a,b);
}

int main(){
    ll k;
    cin >> k;
    ll ans=0;
    rep2(a,k){
        rep2(b,k){
            rep2(c,k){
                ans+=gcd(a,gcd(b,c));
                //cerr<<a<<' '<<b<<' '<<c<<' '<<lcm(a,lcm(b,c))<<endl;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}



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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

ll mod_pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = mod_pow(x * x % MOD, n / 2);
  if (n & 1) res = res * x % MOD;
  return res;
}

ll modsubtraction(ll a, ll b) {
  ll ans = (a - b) % MOD;
  if (ans < 0)
    ans += MOD;
  return ans;
}

ll combination(ll n, ll k) {
  ll sum1 = 1;
  ll sum2 = 1;
  for (int i = 1; i <= k; i++) {
    sum1 = sum1 * (n-k+i) % MOD;
    sum2 = sum2 * i % MOD;
  }
  sum2 = mod_pow(sum2, MOD-2);
  return sum1 * sum2 % MOD;
}

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

  ll n, a, b;
  ll ans, dis1, dis2;
  cin >> n >> a >> b;
  ans = mod_pow(2, n)-1;
  dis1 = combination(n, a);
  dis2 = combination(n, b);
  ans = modsubtraction(ans, dis1);
  ans = modsubtraction(ans, dis2);
  cout << ans << endl;
}


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

using namespace std;

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

  if (N == 1) {
    printf("Hello World\n");
  } else {
    int A, B;
    cin >> A >> B;
    printf("%d\n", A + B);
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

constexpr char BR = '\n';


///////////////////////////////////////////////////

bool f(int N, string S)
{
    if (N % 2 == 1)
        return false;

    for (int i = 0; i < N/2; i++)
    {
        if (S[i] != S[i+N/2])
            return false;
    }
    
    return true;
}

int main()
{
    int N;
    io >> N;
    string S;
    io >> S;
    io << YesNo(f(N, S)) << BR;
}

Measured memory_bytes: 3680
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    string s;
    cin >> s;

    int ans = 0;
    for(int i = 0; i < (int)s.size(); i++){
        if(i % 2 == 0){
            if(s[i] == 'p'){
                ans--;
            }
        }
        else{
            if(s[i] == 'g'){
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){

	int n,k,s,data;
	s = 0;
	
	while(cin >> n >> k, n && k){
	vector<int> sum;	

	rep(i,n){
		cin >> data;
		sum.push_back(data);
	}
	
	data = 0;

	rep(i,k){

		data += sum[i];
		
	}

	int res;
	res = data;
	
	rep(i,n - k){
		data -= sum[i];
		data += sum[i+k];
		res = max(res,data);
	}

	cout << res << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1728
#include <stdio.h>
#include <stdlib.h>
#define max_size (int)(1e5 + 1)

int max(int a, int b){
	return a >= b ? a : b;
}

int main(){
	int N, C, s, t, c, i, j, sum, ans = 0;
	scanf("%d%d", &N, &C);
	int **A = (int **)malloc(sizeof(int *) * C);
	for(i = 0; i < C; i++){
		A[i] = (int *)malloc(sizeof(int) * max_size);
		for(j = 0; j < max_size; j++){
			A[i][j] = 0;
		}
	}
	for(i = 0; i < N; i++){
		scanf("%d%d%d", &s, &t, &c);
		for(j = s; j <= t; j++){
			A[c - 1][j] = 1;
		}
	}
	for(i = 0; i < max_size; i++){
		sum = 0;
		for(j = 0; j < C; j++){
			sum += A[j][i];
		}
		ans = max(ans, sum);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

int main(){
    
    int N;cin>>N;
    bool ok=false;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==N) ok=true;
        }
    }
    
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
    int sum,r,g,b;
  sum=0;
  cin>>r>>g>>b;
  sum=r*100+g*10+b;
  if(sum%4==0){
	cout<<"YES";
  }else{
    cout<<"NO";
  }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
ll add(ll k)
{
    return (k * (k + 1) / 2) % mod;
}

int main()
{
    ll n, k, ans = 0;
    cin >> n >> k;
    vector<ll> v(n);
    rep(i, n) cin >> v[i];

    rep(i,n)
    {
        rep(j,n)
        {
            if (i == j)
                continue;

            if (v[i] > v[j])
            {
                if (i < j)
                {
                    (ans += add(k))%=mod;
                }
                else
                {
                    (ans += add(k - 1))%=mod;
                }
            }
        }
    }
    cout << ans << endl;
}

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

bool solve() {
	int h, w; cin >> h >> w;
	int cnt[26] = {};
	for(int i = 0; i < h; ++i) {
		for(int i = 0; i < w; ++i) {
			char c; cin >> c;
			cnt[c - 'a']++;
		}
	}
	int g1 = 0, g2 = 0, g4 = 0;
	if(h % 2 == 1 and w % 2 == 1) g1 = 1;
	if(h % 2 == 1) {
		g2 += w / 2;
	}
	if(w % 2 == 1) {
		g2 += h / 2;
	}
	g4 = (h / 2) * (w / 2);
	for(int i = 0; i < 26; ++i) {
		if(cnt[i] % 2 == 1) {
			if(g1 == 0) {
				return false;
			}
			cnt[i]--;
			g1--;
		}
	}
	if(g1 != 0) {
		return false;
	}
	for(int i = 0; i < 26; ++i) {
		if(cnt[i] % 4 == 2) {
			if(g2 == 0) {
				return false;
			}
			cnt[i] -= 2;
			g2--;
		}
	}
	for(int i = 0; i < 26; ++i) {
		if(cnt[i] > 0) {
			while(g2 > 0 and cnt[i] > 0) {
				cnt[i] -= 2;
				g2--;
			}
		}
	}
	if(g2 != 0) {
		return false;
	}
	for(int i = 0; i < 26; ++i) {
		if(cnt[i] > 0 and cnt[i] % 4 == 0) {
			if(g4 == 0) {
				return false;
			}
			g4 -= cnt[i] / 4;
			cnt[i] %= 4;
		}
	}
	if(g4 != 0) {
		return false;
	}
	for(int i = 0; i < 26; ++i) {
		if(cnt[i] > 0) {
			return false;
		}
	}
	return true;
}

int main() {
	cout << (solve() ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
H = [int(i) for i in input().split()]

temp = H[-1]

for i in range (2,N+1):
    if(temp < H[(-1)*i]-1):
        print("No")
        exit()
    else:
        if(temp != H[(-1)*i] - 1):
            temp = min(temp,H[(-1)*i])
print("Yes")

Measured memory_bytes: 14252
import java.util.*;
import java.math.*;
import java.io.BufferedInputStream;
public class Main{
    static TreeSet[] count;
    static int[] st;
    public static void main(String[] args){
        Scanner sc = new Scanner (new BufferedInputStream(System.in));
        int n = sc.nextInt();
        String s = sc.next();
        st = new int[n];
        int times = sc.nextInt();
        count = new TreeSet[26];
        for(int i = 0; i < n; ++i) {
            int index = s.charAt(i) - 'a';
            st[i] = index; 
            if(count[index] == null) {
                count[index] = new TreeSet<Integer>();
            }
            count[index].add(i);
        }
        for(int time = 0; time < times; ++time) {
            int type = sc.nextInt();
            int index = sc.nextInt();
            int third;
            if(type == 2) {
                third = sc.nextInt();
                query(index - 1, third);
            } else {
                third = sc.next().charAt(0) - 'a';
                change(index - 1, third);
            }
        }
      }

      private static void query(int start, int end) {
          int res = 0;
          for(int i = 0; i < 26; ++i) {
              if(count[i] == null) continue;
              Integer high = (Integer) count[i].ceiling(start);
              if(high != null && high >= start && high < end) res++;
          }
          System.out.println(res);
      }

      private static void change(int index, int target) {
          int ori = st[index];
        if(ori == target) return;
          count[ori].remove(index);
          st[index] = target;
          if(count[target] == null) count[target] = new TreeSet<Integer>();
          count[target].add(index);
      }
}

Measured memory_bytes: 102700
import math
N = int(input())
x = [0] * N
y = [0] * N
h = [0] * N
#Cx Cy H を求める
for i in range(N):
    x[i], y[i], h[i] = map(int,input().split())
#h>0となるものは必ず存在するので
#そのときに答えの(cx,cy,H)の候補としてprobに(10000個)格納する
#最大でN*100*100=10^6
prob = []
for i in range(N):
    if h[i] > 0:
        for cx in range(101):
            for cy in range(101):
                H = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
                prob.append([cx,cy,H])
        break
#答えの候補probの中からすべての条件を満たすものを探す
#最大でN*10000 = 10^6
for i in range(N):
    minus = []
    for j in range(len(prob)):
        cx = prob[j][0]
        cy = prob[j][1]
        H = prob[j][2]
        if h[i] == max(H-abs(x[i] - cx) -abs(y[i] - cy),0):
            continue
        else:
            minus.append([cx,cy,H])
    if len(minus) == 0:
        continue
    else:
        for k in range(len(minus)):
            prob.remove(minus[k])
print(str(prob[0][0])+' '+str(prob[0][1])+' '+str(prob[0][2]))

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll N; cin >> N;
	ll prd = 1;
	ll dekai = 1e18;
	bool flag = false;
	for (int i = 0; i < N; i++) {
		ll A;
		cin >> A;
		if (A == 0) prd = 0;
		if (prd == 0) continue;
		if (flag) continue;
		if (A > dekai / prd) {
			flag = true;
		}
		if (flag) continue;
		prd *= A;
	}
	if (!prd) {
		cout << 0 << endl;
	} else if (flag || prd > dekai) {
		cout << -1 << endl;
	} else {
		cout << prd << endl;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


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

int main()
{
  uint64_t n, a, b;
  cin >> n >> a >> b;
  uint64_t ans;
  if ((b - a) % 2 == 0) {
    ans = (b - a) / 2;
  } else {
    uint64_t x = a - 1;
    uint64_t y = n - b;
    ans = (b - a + 1) / 2 + min(x, y);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
while True:
    table=input().split()
    
    a=int(table[0])
    op=table[1]
    b=int(table[2])
    
    if op == '?':
        break
    
    if op == '+':
        print("%d"%(a+b))
    elif op == '-':
        print("%d"%(a-b))
    elif op == '*':
        print("%d"%(a*b))
    else:
        print("%d"%(a/b))


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

int main() {
    int a, b, ans;
    cin >> a >> b;
    if(a == b) ans = a + b;
    else ans = 2 * max(a, b) - 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

arr = sorted(make_divisors(N))

if len(arr)%2==0:
  i=arr[len(arr)//2-1]
  j=arr[len(arr)//2]
else:
  i = arr[len(arr)//2]
  j = arr[len(arr)//2]
print(i+j-2)


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


int main() {
  int k;
  cin >> k;
  

  int n = 7;
  
  REP(i,k){
    if(n % k == 0){
      cout << i+1 << endl;
      return 0;
    }
    n %= k;
    n *= 10;
    n += 7;
  }
  cout << -1 << endl;
  
  
}

Measured memory_bytes: 3640
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}
// fold was added in D 2.071.0.
template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
        static if (S.length < 2) {
            return reduce!fun(seed, r);
        } else {
            return reduce!fun(tuple(seed), r);
        }
    }
}

void main() {
    readln.chomp.find!"a=='A'".retro.find!"a=='Z'".array.length.writeln;
}


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

int main() {
	long long N;
	string S;
	cin >> N;
	cin >> S;
	long long i;
	vector<long long> A(30);
	for (i = 0; i < 26; i++) {
		A.at(i) = 0;
	}
	for (i = 0; i < N; i++) {
		switch (S.at(i)) {
		case 'a':
			A[0] += 1;
			break;
		case 'b':
			A[1] += 1;
			break;
		case 'c':
			A[2] += 1;
			break;
		case 'd':
			A[3] += 1;
			break;
		case 'e':
			A[4] += 1;
			break;
		case 'f':
			A[5] += 1;
			break;
		case 'g':
			A[6] += 1;
			break;
		case 'h':
			A[7] += 1;
			break;
		case 'i':
			A[8] += 1;
			break;
		case 'j':
			A[9] += 1;
			break;
		case 'k':
			A[10] += 1;
			break;
		case 'l':
			A[11] += 1;
			break;
		case 'm':
			A[12] += 1;
			break;
		case 'n':
			A[13] += 1;
			break;
		case 'o':
			A[14] += 1;
			break;
		case 'p':
			A[15] += 1;
			break;
		case 'q':
			A[16] += 1;
			break;
		case 'r':
			A[17] += 1;
			break;
		case 's':
			A[18] += 1;
			break;
		case 't':
			A[19] += 1;
			break;
		case 'u':
			A[20] += 1;
			break;
		case 'v':
			A[21] += 1;
			break;
		case 'w':
			A[22] += 1;
			break;
		case 'x':
			A[23] += 1;
			break;
		case 'y':
			A[24] += 1;
			break;
		case 'z':
			A[25] += 1;
			break;
		}
	}
	long long B = 1;
	for (i = 0; i < 26; i++) {
		B = B*(A.at(i) + 1) % 1000000007;
	}
	cout << B - 1;
}

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

int main(void){
  int n;cin >> n;
  if(n >= 1000)cout << "ABD" << endl;
  else cout << "ABC" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
  return os << "{" << p.first << ", " << p.second << "}";
}
template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
  os << "{";
  rep(i, v.size()) { if(i) os << ", "; os << v[i]; }
  return os << "}";
}
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 998244353;

ll binary_pow(ll a, ll N) {
  ll ans = 1;
  ll tmp = a;
  while(N > 0) {
    if(N % 2 == 1) {
      ans *= tmp;
      ans %= mod;
    }
    N /= 2;
    tmp *= tmp;
    tmp %= mod;
  }
  return ans;
}

int main() {
  int N;
  cin >> N;
  vector<int> num(N);
  vector<int> D(N);
  rep(i, N) {
    cin >> D[i];
    num[D[i]]++;
  }
  ll ans;
  rep(i, N) {
    if(i == 0) {
      if(num[i] != 1 || D[0] != 0) { ans = 0; break; }
      else ans = 1;
    } else {
      ans *= binary_pow(num[i-1], num[i]);
      ans %= mod;
    }
  }
  cout << ans << endl;
  return 0;
}



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

int main() {
  int N, K;
  int sum = 0;
  cin >> N >> K;
    
  for (int i = 0; i < N; i++){
    int x;
    cin >> x;
	if (x < (K - x)) {
      sum += x * 2;
    } else {
      sum += (K - x) * 2;
    }
  
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        List<Integer> inputs = new ArrayList<Integer>();

        Scanner sc = new Scanner(System.in);
        for(int i=0; i<10; i++) {
            if(!sc.hasNextInt()) {
                break;
            }
            int input = sc.nextInt();
            inputs.add(Integer.valueOf(input));
        }

        Collections.sort(inputs, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        
        for(int height : inputs.subList(0, Math.min(inputs.size(), 3))) {
            System.out.println(height);
        }
    }
}

Measured memory_bytes: 12000
#include <iostream>

int main(){
    int n,k,s;
    std::cin >> n >> k >> s;
    for (int i = 0; i < n; ++i) {
        if(i < k)std::cout << s << ' ';
        else if (s==1000000000)std::cout << 1 << ' ';
        else std::cout << 1000000000 << ' ';
    }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll lg=31;
const ll N=1e5+5;
const ll INF=3e18;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;

#define f first
#define s second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repp(i, a, b) for(int i = a; i > (b); --i)
#define sz(x) (int)(x).size()
#define pb push_back
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main() {
  FASTIO;
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max({a * c, a * d, b * c, b * d}) << endl;
  return 0;
}

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

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

    vector<ll> w(n);
    vector<ll> v(n);

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

    vector<vector<ll>> dp(n + 1);

    for(ll i= 0; i < n + 1; i++){
        vector<ll> temp(W + 1, 0);
        dp[i] = temp;
    }
    for(ll i= 1; i <= n; i++){
        for(ll j = 1; j <= W; j++){
            if(j < w[i - 1]){
                dp[i][j] = dp[i - 1][j];
            } else {
                dp[i][j] = max(dp[i - 1][j - w[i - 1]] + v[i - 1], dp[i - 1][j]); 
            }
        }
    }

    // for(ll i = 0; i <= n; i++){
    //     for(ll j = 0; j <= W; j++){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    cout << dp[n][W] << endl;
}

Measured memory_bytes: 79984
n = int(input())
a = list(map(int, input().split()))
s =0
count = -1
for i in range(len(a)-1):
    count+=1
    for j in range(len(a)-1):
        j =j+1+count
        if j<(len(a)):
            s += a[i]*a[j]
print(s) 

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)
    {
      x=x->left;
    }
  return x;
}

Node treeMaximum(Node x){
 while(x->right!=NIL)
    {
      x=x->right;
    }
 return x;
}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key)
    {
      return u;
    }
  if(k<u->key)
    {
      return treeSearch(u->left,k);
    }
  else
    {
      return treeSearch(u->right,k);
    }
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)
    {
      return treeMaximum(x->right);
    }
  y=x->parent;
  while(y!=NIL && x==y->right)
    {
      x=y;
      y=y->parent;
      return y;
    }
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL)
    {
      y=z;
    }
  else
    {
      y=treeSuccessor(z);
    }
  if(y->left!=NIL)
    {
      x=y->left;
    }
  if(x!=NIL)
    {
      x->parent=y->parent;
    }
  if(y->parent==NIL)
    {
      root=x;
    }
  else if(y==y->parent->left)
    {
      y->parent->left=x;
    }
  else
    {
      y->parent->right=x;
    }
  if(y!=z)
    {
      z->key=y->key;
    }

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL)
    {
      y=x;
      if(z->key < x->key)
	{
	  x=x->left;
	}
      else
	{
	  x=x->right;
	}
    }
  z->parent=y;
  if(y==NIL)
    {
      root=z;
    }
  else if(z->key < y->key)
	{
	  y->left=z;
	}
      else
	{
	  y->right=z;
	}
    }




void inorder(Node u){
  if(u!=NIL)
    {
      inorder(u->left);
      printf(" %d",u->key);
      inorder(u->right);
    }
     
}
void preorder(Node u){
  if(u!=NIL)
    {
      printf(" %d",u->key);
      preorder(u->left);
      preorder(u->right);
    }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25136
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
using namespace std;

#ifdef WAFDAYO
#define DBG_PRINT(s, t, u) { cerr << s << " \e[2m=\e[m \e[1m" << t << "\e[m" << u; }
#else
#define DBG_PRINT(s, t, u) {}
#endif
#define dbg(x) DBG_PRINT(#x, x, ", ")
#define dbgln(x) DBG_PRINT(#x, x, endl)
#define idbg(x, i) DBG_PRINT(#x "[" << i << "]", x[i], ", ")
#define idbgln(x, i) DBG_PRINT(#x "[" << i << "]", x[i], endl)

typedef long long i64;
const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

int main() {

	int m;
	vector<pair<int,i64>> dc;
	scanf("%d", &m);
	dc.resize(m);
	for(int i = 0; i < m; i++) {
		int d;
		i64 c;
		scanf("%d%lld", &d, &c);
		dc[i] = {d, c};
	}

	i64 d_sum = 0;
	i64 len = 0;
	for(auto& x : dc) {
		d_sum += x.first * x.second;
		len += x.second;
	}

	i64 ans = (len - 1) + (d_sum - 1) / 9;

	printf("%lld\n", ans);

	return 0;
}


// wafdayo~~~


Measured memory_bytes: 3328
<?php
    $N = intval(trim(fgets(STDIN)));
    $S = trim(fgets(STDIN));
    $count=1;
    for($i=0;$i<$N-1;$i++){
        if($S[$i] != $S[$i+1]){
            $count++;
        }
    }
    echo $count;
?>

Measured memory_bytes: 16376
#include <iostream>



using namespace std;

long long arrA[100001];
long long arrB[100001];
int main()
{
	int n;
cin >> n;

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

	long long counter = 0;

	for (int i = n - 1; i >= 0; i--)
	{
		arrA[i] += counter;
		
		if (arrA[i] % arrB[i] == 0)continue;
		if (arrA[i] < arrB[i]) { counter += arrB[i] - arrA[i]; continue; }

		int temp = (arrA[i] - (arrA[i] % arrB[i]) + arrB[i]) - arrA[i];
		counter += temp;
	

	}
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 1920
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;

int main() {
  int64_t N, M, p, acc = 0, wac = 0;
  string s;
  cin >> N >> M;
  map<int, int> wa{};
  vector<bool> ac(N, false);
  for (int i = 0; i < M; i++) {
    cin >> p >> s;
    p--;
    if (s == "AC" && !ac[p]) ac[p] = true;
    if (s == "WA" && !ac[p]) wa[p]++;
  }

  for (int i = 0; i < N; i++) {
    if (ac[i]) {
      acc++;
      wac += wa[i];
    }
  }
  cout << acc << " " << wac << endl;
}


Measured memory_bytes: 7700
#define NDEBUG
#include <bits/stdc++.h>
#define clean(x,y) memset(x,y,sizeof(x))
#define inc(i,s,t) for(int i=s;i<=t;++i)
#define dec(i,s,t) for(int i=s;i>=t;--i)
#define debug(x) std::cerr<<(x)<<" "
typedef long long ll;
const int inf = 0x7f7f7f7f;

inline void gettime() {
	debug("Time: ");
	debug(clock()) << " ms\n";
}
inline int read() {
	static char c;
	static int x;
	while (c = getchar(), !isdigit(c));
	x = c - '0';
	while (c = getchar(), isdigit(c))
		x = (x << 1) + (x << 3) + c - '0';
	return x;
}
inline char achar() {
	static char c;
	while (c = getchar(), !isalpha(c));
	return c;
}

int n,m,last;
int from[100],to[100],dis[100];
void add(int x,int y,int z) {
	++m;
	from[m]=x;
	to[m]=y;
	dis[m]=z;
}

int main() {
#ifndef ONLINE_JUDGE
	std::atexit(gettime);
#endif

	n=read()-1;
	for (int i=0; (1<<(i+1))-1<=n; ++i) {
		add(i+1,i+2,1<<i);
		add(i+1,i+2,0);
		last=i;
	}
	int rem=n-(1<<(last+1))+1;
	++n;
	for (int i=0; rem; rem>>=1,++i)
		if (rem&1)
			add(i+1,last+2,n-=(1<<i));
	printf("%d %d\n", last+2,m);
	for (int i=1; i<=m; ++i)
		printf("%d %d %d\n", from[i],to[i],dis[i]);
}

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

using namespace std;

char s1[1000];
char s2[1000];
char s3[1000];
int main()
{
    cin >> s1;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> s2;
        if (strcmp(s2,"replace")==0)
        {
            int a, b;
            cin >> a >> b >> s3;
            int p_length = b - a + 1;
            for (int i = 0; i < p_length; i++)
                s1[a + i] = s3[i];
        }
        if (strcmp(s2,"reverse")==0)
        {
            int a, b;
            cin >> a >> b;
            while (a < b)
            {
                swap(s1[a++], s1[b--]);
            }
        }
        if (strcmp(s2,"print")==0)
        {
            int a, b;
            scanf("%d%d", &a, &b);
            for (int i = a; i <= b; i++)
            {
                cout << s1[i];
            }
            cout << endl;
        }
    }

    return 0;
}



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

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

int main() {
    long long A,B;
    cin >> A >> B;
    long long gcd_val = gcd(A,B);
    int ans = 1;
    for(long long i = 2; i*i <= gcd_val; i++) {
        int ok = 0;
        while(gcd_val%i == 0) {
            ok = 1;
            gcd_val/=i;
        }
        ans += ok;
    }
    if(gcd_val!=1) ans++;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
N, M, X = map(int, input().split())

A = [i for i in map(int, input().split())]
squares=[i for i in range(N+1)]
V=squares[X]
lowest=[]
highest =[]
for i in range(len(A)):
    if A[i]<V:
        lowest.append(A[i])
    else:
        highest.append(A[i])
if len(lowest)>len(highest):
    cost = len(highest)
else:
    cost = len(lowest)

print(cost)
       

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

using namespace std;

int main() {
	string s1, s2;
	cin>>s1>>s2;
	int n = s1.size();
	int m = s2.size();
	vector<vector<int>> dp(n+1, vector<int>(m+1,0));

	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			if(s1[i-1]==s2[j-1])
				dp[i][j] = max(dp[i-1][j-1]+1, max(dp[i-1][j], dp[i][j-1]));
			else
				dp[i][j] = max(dp[i-1][j-1], max(dp[i-1][j], dp[i][j-1]));
		}
	}

	// for(int i=1; i<=n; i++) {
	// 	for(int j=1; j<=m; j++) {
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }

	int len=1;
	string ans = "";
	int i=n, j=m;
	while(i>0&&j>0) {
		if(s1[i-1]==s2[j-1]) {
			ans = s1[i-1] + ans;
			i--;
			j--;
		} else {
			if(dp[i-1][j] > dp[i][j-1])
				i--;
			else
				j--;
		}
	}
	// for(int sum=2; sum<=n+m; sum++) {
	// 	int i;
	// 	if(sum>m+1) {
	// 		i=sum-m;
	// 	}
	// 	else i=1;
	// 	for(;i<=n&&sum-i>0; i++) {
	// 		int j=sum-i;
	// 		if(dp[i][j]==len) {
	// 			cout<<i<<" "<<j<<" "<<sum<<endl;
	// 			cout<<s1[i-1]<<" "<<s2[j-1]<<" "<<len<<endl;
	// 			ans+=s1[i-1];
	// 			len++;
	// 		}
	// 	}
	// 	cout<<endl;
	// }
	cout<<ans<<endl;
	return 0;
}


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

int bubbleSort(vector<int>& A, int N) {
	bool flag = true;
	int count = 0;
	int i = 0;
	while (flag) {
		flag = false;
		for (int j = N-1; j > i; j--) {
			if (A[j-1] > A[j]) {
				int tmp = A[j-1];
				A[j-1] = A[j];
				A[j] = tmp;
				flag = true;
				count++;
			}
		}
		i++;
	}
	return count;
}

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	int cnt = bubbleSort(A, N);
	for (int i = 0; i < N; i++) {
		if (i == N-1) cout << A[i] << endl;
		else cout << A[i] << ' ';
	}
	cout << cnt << endl;
}



Measured memory_bytes: 3128
#include<iostream>
#include<string>

using namespace std;

int main(){
 int n;cin>>n;
 int r=n%10;
  
 if(r==2 || r==4 || r==5 || r==7|| r==9) cout<<"hon \n";
 
  if(r==0 || r==1 || r==6 || r==8 ) cout<<"pon \n";
  
  if(r==3 ) cout<<"bon \n";
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;

public class ABC0125_A3v9 {
    private static void Main(string[] args) {
        var inputs = new List<string>(){
            Console.ReadLine().Trim(),
            Console.ReadLine().Trim(),
        };
        Prepare(inputs);
    }

    private static void Prepare(List<string> inputs) {
        var length = int.Parse(inputs[0]);
        var numbers = inputs[1].Split()
            .Select(x => int.Parse(x))
            .OrderBy(n => n)
            .ToArray();
        Compute(length, numbers);
    }

    private static void Compute(int length, int[] numbers) {
        var candidateA = GetCandidateAgcdA(numbers);
        var candidateB = GetCandidateAgcdB(numbers);
        OutputAnswer(Math.Max(candidateA, candidateB).ToString());
    }

    private static void OutputAnswer(string text) => Console.WriteLine(text);

    private static int GetCandidateAgcdA(int[] numbers) {
        var standard = numbers[0];
        var tempAGCD = 1;

        for (int divisor = 1; divisor * divisor < standard; divisor++) {
            if (standard % divisor == 0) {
                tempAGCD = GetACD(tempAGCD, numbers, divisor);
                tempAGCD = GetACD(tempAGCD, numbers, standard / divisor);
            }
        }

        return tempAGCD;
    }
    private static int GetACD(int tempGCD, int[] numbers, int divisor) {
        if (tempGCD < divisor && IsACD(numbers, divisor))
            return divisor;
        else
            return tempGCD;
    }
    private static bool IsACD(int[] numbers, int divisor) {
        if (divisor <= 0) {
            return false;
        }

        var count = 0;

        foreach (var number in numbers) {
            if (number % divisor != 0) {
                count++;

                if (count > 1)
                    return false;
            }
        }

        return true;
    }
  
    private static int GetCandidateAgcdB(IEnumerable<int> numbers) {
        var tempGCD = numbers.ElementAt(1);

        for (int index = 2; index < numbers.Count(); index++) {
            tempGCD = GetGcdFrom2Ints(tempGCD, numbers.ElementAt(index));
        }
        return tempGCD;
    }
    private static int GetGcdFrom2Ints(int a, int b) => a > b ? CalcGCD(a, b) : CalcGCD(b, a);
    private static int CalcGCD(int a, int b) => b == 0 ? a : CalcGCD(b, a % b);
}

Measured memory_bytes: 30428
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Diagnostics;

namespace test
{

    class Program
    {
        static void Main(string[] args)
        {
            int a = 0;
            int b = 0;
            int c = 0;

            for (int i = 0; i < 10; i++)
            {
                int h = int.Parse(Console.ReadLine());
                if (h > c)
                {
                    if (h > b)
                    {
                        if (h > a)
                        {
                            int tmp1 = a;
                            int tmp2 = b;
                            a = h;
                            b = tmp1;
                            c = tmp2;
                        }
                        else
                        {
                            int tmp = b;
                            b = h;
                            c = tmp;
                        }
                    }
                    else
                    {
                        c = h;
                    }
                }

            }

            Console.WriteLine(a);
            Console.WriteLine(b);
            Console.WriteLine(c);


        }

    }
        
}

Measured memory_bytes: 5600
N = int(input())
A = list(map(int, input().split()))
B = [None]*N

for n in range(N, 0, -1):
    B[n-1] = A[n-1]
    k=n*2
    while k<=N:
        B[n-1] ^= B[k-1]
        k += n

M = sum(B)
print(M)
if M>0:
    print(' '.join( [str(i+1) for i,b in enumerate(B) if b==1] ))

Measured memory_bytes: 14780
'''
1つの始点から全頂点への最短距離を求めるアルゴリズム
辺の数E,頂点の数Vに対し、O((E+V)log(V))
edge[u]=[(d1, v1), (d2, v2), ...]が頂点uと頂点viに距離diの辺があることを表す隣接リストが入力
無向グラフにて検証済み。有効グラフのたぶんいけるので確認したらここを書き換えて欲しい。
'''

from heapq import heappush, heappop

INF = 10**15
 
def dijkstra(s, edges):
    n = len(edges)
    que = []
    d = [INF] * n
    d[s] = 0
    heappush(que, (0, s))

    while len(que) > 0:
        (c, v) = heappop(que)
        if d[v] < c:
            continue
        for (cc, w) in edges[v]:
            if d[w] > d[v] + cc:
                d[w] = d[v] + cc
                heappush(que, (d[w], w))

    return d

n, m, s, t = map(int, input().split())
s, t = s-1, t-1
yen_edge = [[] for i in range(n)]
snook_edge = [[] for i in range(n)]
for i in range(m):
    ui, vi, ai, bi = map(int, input().split())
    ui, vi = vi-1, ui-1
    yen_edge[ui].append((ai, vi))
    yen_edge[vi].append((ai, ui))
    snook_edge[ui].append((bi, vi))
    snook_edge[vi].append((bi, ui))

distance_yen = dijkstra(s, yen_edge)
distance_snook = dijkstra(t, snook_edge)

ans_lst = [0 for i in range(n)]
temp_min = 10**15
for i in range(n)[::-1]:
    now = distance_yen[i] + distance_snook[i]
    temp_min = min(temp_min, now)
    ans_lst[i] = 10**15 - temp_min

for i in range(n):
    print(ans_lst[i])

Measured memory_bytes: 115140
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

int MOD_BIG = 1000000007;
int MOD_BIG2 = 998244353;
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using std::vector;

#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

//////////////////////////////////////

struct Mod_nCm {
    ll MAX, MOD;
    vector<ll> fac, finv, inv;
    Mod_nCm(ll max, ll mod): MAX(max+1), MOD(mod), fac(MAX), finv(MAX), inv(MAX) {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    ll get_nCm(ll n, ll m) {
        if (n > MAX) return -1;
        if (n < m) return 0;
        if (n < 0 || m < 0) return 0;
        return fac[n] * (finv[m] * finv[n - m] % MOD) % MOD;
    }
};

//////////////////////////////////////

int main() {
    
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    int a = H - A;
    
    Mod_nCm ncm(H+W+1, MOD_BIG);
    
    ll sum = 0;
    
    FOR(b, 0, B) {
        sum += ncm.get_nCm(a+b-1, b) * ncm.get_nCm(W-b+A-2, A-1);
        sum %= MOD_BIG;
    }
    cerr << sum << endl;
    cerr << ncm.get_nCm(H+W-2, H-1) << endl;
    
    int ans = (ncm.get_nCm(H+W-2, H-1) - sum + MOD_BIG) % MOD_BIG;
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <cstring>

const int maxn=100000;

char s[maxn+10];
int len;

int main()
{
  scanf("%s",s+1);
  len=strlen(s+1);
  if((s[len]!='0')||(s[1]!='1'))
    {
      puts("-1");
      return 0;
    }
  for(int i=1; i<=len-i; ++i)
    {
      if(s[i]!=s[len-i])
        {
          puts("-1");
          return 0;
        }
    }
  int past=1;
  for(int i=1; i<len; ++i)
    {
      printf("%d %d\n",past,i+1);
      if(s[i]=='1')
        {
          past=i+1;
        }
    }
  return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>

using namespace std;

int h, w;
vector<vector<bool>> senbei;

vector < vector<bool>> rev(int a) {
	auto tmp = senbei;
	int ct = 0;
	for (int i = 1; i < (1 << h); i = i << 1) {
		ct++;
		if (a & i) {
			for (int j = 0; j < w; j++) {
				tmp[ct - 1][j] = !tmp[ct - 1][j];
			}
		}
	}
	return tmp;
}

int main() {
	while (cin >> h >> w, h * w) {
		senbei.resize(h);
		for (int i = 0; i < h; i++) {
			senbei[i].resize(w);
			for (int j = 0; j < w; j++) {
				int tmp;
				cin >> tmp;
				senbei[i][j] = static_cast<bool>(tmp);
			}
		}
		int ans = 0;
		for (int i = 0; i < (1 << h); i++) {
			auto tmp = rev(i);
			int ct = 0;
			for (int i = 0; i < w; i++) {
				int c = 0;
				for (int j = 0; j < h; j++) {
					if (tmp[j][i])c++;
				}
				c = max(c, h - c);
				ct += c;
			}
			ans = max(ct, ans);
		}
		cout << ans << endl;
		senbei.clear();
	}
	return 0;
}

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

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n"
#define ll long long
#define uint unsigned int
#define ushort unsigned short
#define ulong unsigned long

ll MOD = 10e9 + 7;

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    int ans = max(0, c-(a-b));
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
int main(void){
    int A,B;
    cin>>A>>B;
    int ans=0;
    for(int i=1;i<4;i++){
        if((A*B*i)%2==1) ans=1;
    }
    if(ans==1) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int N = s.nextInt();

			long ret = 0;
			long min = Long.MAX_VALUE;
			boolean plus = true;
			for (int i = 0; i < N; i++) {
				long a = s.nextLong();
				if (a < 0) {
					plus = !plus;
				}

				ret += Math.abs(a);
				min = Math.min(min, Math.abs(a));
			}
			if (!plus) {
				ret = ret - min * 2;
			}
			System.out.println(ret);
		}
	}
}


Measured memory_bytes: 50440
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){
    int a[4];
    for(int i=0;i<4;i++){
        cin>>a[i];
    }
    cout<<min(min(abs(a[0]+a[1]-a[2]-a[3]),abs(a[0]+a[2]-a[1]-a[3])),abs(a[0]+a[3]-a[2]-a[1]))<<endl;
}


Measured memory_bytes: 3112