akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define int long long
 
#define pii pair<int, int>
 
#define x1 x1228
#define y1 y1228
 
#define left left228
#define right right228
 
#define pb push_back
#define eb emplace_back
 
#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   
 
#define matr vector<vector<int> > 
 
#define all(x) x.begin(), x.end()
 
 
using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 3e5 + 7, mod = 998244353, MAXN = 1e6 + 7;
const double eps = 1e-9;
const ll inf = 1e18; 
mt19937 rnd(time(0));


void solve() { 
    int a, b; 
    cin >> a >> b;
    int ans = 0;
    if (a <= 3) ans += (4 - a);
    if (b <= 3) ans += (4 - b);
    if (a == 1 && b == 1) ans += 4;
    cout << ans * 100000;    
}                                   
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
}  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int64 long long int
int main(){
	int n;
	ios::sync_with_stdio(false);
	cin >> n;
	int64 sum = 0, z = (int64)2e18, res = 0;
	for(int i=1; i<=n; i++){
		int64 cur, pro;
		cin >> cur >> pro;
		z = min(z, sum - cur);
		sum += pro;
		res = max(res, sum - cur - z);
	}
	cout << res <<endl;
	return 0;
}

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

int n,a,b;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin>>n>>a>>b;
    if(n*a<=b)
        cout<<n*a;
    else
        cout<<b;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main (void){
    int n,i,j,k,ans=0,r,l,h=0;
    char koku[11],ring[21];
    scanf("%s%d",koku,&n);
    for(i=0;i<11;i++){
        r=i;
        if(koku[i]=='\0')break;
    }
    for(i=0;i<n;i++){
        scanf(" %s",ring);
        ring[20]=ring[10];
        l=0;
        for(j=0;j<10;j++){
            ring[j+10]=ring[j];
        }
        for(j=0;j<20;j++){
            if(ring[j]==koku[0]){
                for(k=0;k<20;k++){
                    if(ring[k+j]!=koku[k]||koku[k]=='\0')break;
                    l++;
                }
                if(r==l&&h==0)ans++,h++;
                l=0;
            }
        }
        h=0;
    }
    printf("%d\n",ans);
return 0;
}

Measured memory_bytes: 596
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    int a,b,c;
    cin >>a>>b;
    
    if(a == 0){
        if( b >= 1868 && b <= 1911){
            c = (b - 1867);
            cout << "M"<<c<<endl;
        }else if(b <= 1925){
            c = (b - 1911);
            cout << "T"<<c<<endl;
        }else if(b <= 1988){
            c = (b - 1925);
            cout << "S"<<c<<endl;
        }else{
            c = (b - 1988);
            cout << "H"<<c<<endl;
        }
    }
    
    if(a == 1){
        c = b + 1867;
        cout <<c<<endl;
        
    }else if(a == 2){
        c = b + 1911;
        cout <<c<<endl;
    }else if(a == 3){
        c = b + 1925;
        cout <<c<<endl;
    }else if(a == 4){
        c = b + 1988;
        cout <<c<<endl;
    }
    
    
}


Measured memory_bytes: 3100
// Problem : U - Grouping
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_u
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

int n;
int a[20][20];
int cost[1<<20];
int dp[1<<20];

void solve(){
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++) cin>>a[i][j];
    }
    for(int mask=0;mask<(1<<n);mask++){
        for(int i=0;i<n;i++){
            if(!((mask>>i)&1)) continue; 
            for(int j=i+1;j<n;j++){
                if(!((mask>>j)&1)) continue;
                cost[mask] += a[i][j];
            }
        }
    }
    int ans = 0;
    dp[0] = 0;
    for(int mask=1;mask<(1<<n);mask++){
        dp[mask] = cost[mask];
        for(int submask=mask;submask>=0;submask=(submask-1)&mask){
            dp[mask] = max(dp[mask],dp[submask]+cost[mask^submask]);
            if(submask == 0) break;
        }
        ans = max(ans,dp[mask]);
    }
    cout<<ans;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

template <typename T, typename U>
vector<U> make_vector(T&& n, U&& val) {
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
decltype(auto) make_vector(T&& n, Args&&... args) {
  return vector<decltype(make_vector(forward<Args>(args)...))>(forward<T>(n), make_vector(forward<Args>(args)...));
}

const int INF = 1001001001;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void solve() {
  int n;
  cin >> n;
  map<string, int> cnt;
  rep(i, n) {
    string s;
    cin >> s;
    cnt[s] += 1;
  }
  cout << "AC x " << cnt["AC"] << endl;
  cout << "WA x " << cnt["WA"] << endl;
  cout << "TLE x " << cnt["TLE"] << endl;
  cout << "RE x " << cnt["RE"] << endl;
}


Measured memory_bytes: 3564
#include<iostream>
#include<deque>
#include<algorithm>
#include<math.h>
#include<string>
using namespace std;
int main() {
	int r;
	cin >> r;
	if (r < 1200)
		cout << "ABC" << endl;
	else if (r < 2800)
		cout << "ARC" << endl;
	else cout << "AGC" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

ll N, L;
vector<ll> x(100005, big);
ll nexthotel[20][100005];

void prepare() {
  ll index;
  for(ll i=0;i<N;++i) {
    index = upper_bound(x.begin(), x.end(), x[i]+L) - x.begin() - 1;
    nexthotel[0][i] = index;
  }
  for(ll i=1;i<20;++i) {
    for(ll j=0;j<N;++j) {
      nexthotel[i][j] = nexthotel[i-1][nexthotel[i-1][j]];
    }
  }
}

int main() {
  cin>>N;
  for(ll i=0;i<N;++i) cin>>x[i];
  cin>>L;
  prepare();
  /**
  for(ll i=0;i<20;++i) {
    for(ll j=0;j<N;++j) {
      cout<<nexthotel[i][j]<<" ";
    }
    cout<<endl;
  }
  **/
  ll Q;
  cin>>Q;
  ll A, B;
  vector<ll> ans(Q, 0);
  ll tmp;
  ll two;
  for(ll i=0;i<Q;++i) {
    cin>>A>>B;
    A--;
    B--;
    if(A>B) swap(A, B);
    while(A<B) {
      tmp = 0;
      two = 1;
      while(nexthotel[tmp+1][A]<B) {
        two *= 2;
        tmp++;
      }
      A = nexthotel[tmp][A];
      ans[i] += two;
    }
  }
  for(ll i=0;i<Q;++i) cout<<ans[i]<<endl;
}



Measured memory_bytes: 20428
#include <stdio.h>
#include <float.h>

int main(){
    double in, high=0.0, low=DBL_MAX;

    while(scanf("%lf", &in) != EOF){
        if(high < in){
            high = in;
        }
        if(low > in){
            low = in;
        }
    }

    printf("%.1f\n", high - low);

    return 0;
}

Measured memory_bytes: 652
using System;

namespace ABC125
{
    class Program
    {
        static int Main(string[] args)
        {
            Program.ProblemC();
            return 0;
        }

        static int ProblemC()
        {
            int n = int.Parse(System.Console.ReadLine());
            string[] Val = System.Console.ReadLine().Split(' ');

            int[] maxarray = new int[n];
            int[] right = new int[n+1];
            int[] left = new int[n+1];
            right[n-1] = 0;
            left[0] = 0;



            for(int j = 0; j < n; j++)
            {
                left[j + 1] = GCD(left[j], int.Parse(Val[j]));
                right[n - j - 1] = GCD(right[n-j], int.Parse(Val[n-j-1]));
            }

            for(int k = 0; k < n; k++)
            {
                maxarray[k] = GCD(left[k], right[k + 1]);
            }

            int m;
            m = 1;

            for(int i = 0; i<n; i++)
            {
                if (maxarray[i] > m) m = maxarray[i];
            }
            System.Console.WriteLine(m);

            return 0;
        }

        static int GCD(int x, int y)
        {
            if (x == 0)
            {
                return y;
            }
            if (y == 0)
            {
                return x;
            }
            if (x % y == 0 || y % x == 0)
            {
                return Math.Min(x, y);
            }
            else
            {
                int z = Math.Min(x % y, y % x);
                return GCD(z, Math.Min(x, y));
            }
        }
    }
}


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

Measured memory_bytes: 256
#include<cstdio>

int main(void) {
    int n,k;
    scanf("%d%d",&n,&k);
    double res = 0.0;
    for(int i=1; i<=n; i++) {
        for(int j=0; j<20; j++) {
            if(i * (1<<j) >= k) {
                res += 1.0 / (1<<j);
                break;
            }
        }
    }
    res /= n;
    printf("%.16f\n", res);
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 150;
int N, K, M;
int add(int a, int b) {return (a + b)%M;}
int mul(int a, int b) {return 1LL*a*b%M;}
int f[MAXN + 5][MAXN + 5];
void solve1() {
	K /= 2, f[0][0] = 1;
	for(int i=1;i<=N;i++) {
		for(int j=0;j<=K;j++)
			f[i][0] = add(f[i][0], f[i-1][j]);
		for(int j=0;j<K;j++)
			f[i][j+1] = add(f[i][j+1], f[i-1][j]);
	}
	int ans1 = 0, ans2 = 0;
	for(int i=0;i<=K;i++)
		ans1 = add(ans1, f[N/2][i]);
	for(int i=0;i<=K;i++)
		ans2 = add(ans2, f[(N+1)/2][i]);
	printf("%d\n", mul(ans1, ans2));
}
int g[2*MAXN + 5][MAXN + 5][MAXN + 5];
void solve2() {
	int p; g[0][0][0] = 1;
	for(int i=2;i-K<=N;i+=2) {
		for(int j=0;j<=N;j++)
			for(int k=0;k<=K+1;k++)
				g[i][0][0] = add(g[i][0][0], g[i-2][j][k]);
		if( i <= N ) {
			for(int j=0;j<=N;j++)
				for(int k=0;k<=K+1;k++)
					g[i][j+1][0] = add(g[i][j+1][0], g[i-2][j][k]);
		}
		if( i - K >= 1 ) {
			for(int j=0;j<=N;j++) {
				for(int k=1;k<=K;k++)
					g[i][0][k+1] = add(g[i][0][k+1], g[i-2][j][k]);
				g[i][0][0] = add(g[i][0][0], g[i-2][j][0]);
			}
		}
		if( i <= N && i - K >= 1 ) {
			for(int j=0;j<=N;j++)
				for(int k=0;max(k,j+1)<=K;k++)
					g[i][j+1][max(k+1,j+2)] = add(g[i][j+1][max(k+1,j+2)], g[i-2][j][k]);
		}
		p = i;
	}
	int ans = 0;
	for(int j=0;j<=N;j++)
		for(int k=0;k<=K+1;k++)
			ans = add(ans, g[p][j][k]);
	printf("%d\n", ans);
}
int main() {
	scanf("%d%d%d", &N, &K, &M);
	if( K % 2 == 0 ) solve1();
	else solve2();
}

Measured memory_bytes: 9180
s = input()
t = input()
s_len = len(s)
t_len = len(t)

max_c = 0
if t in s:
    print(0)
    exit()
for i in range(s_len - t_len + 1):
    count = 0
    for j in range(t_len):
        if s[i+j] == t[j]:
            count+=1
    if count > max_c:
        max_c = count
print(t_len-max_c)

Measured memory_bytes: 9024
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>

using namespace std;

/**
   ceil(0, 2) == 0
   ceil(1, 2) == 1
   ceil(2, 2) == 1
   ceil(3, 2) == 2
   ceil(4, 2) == 2
*/
template<class T>
T ceil(T dividend, T divisor)
{
    return (dividend + (divisor - 1)) / divisor;
}

int main()
{
    std::string S;
    std::cin >> S;

    const size_t L = S.size();

    // ナイーブ実装
    #if 0
    for (size_t s = 0; s < L - 1; ++s) {
        for (size_t e = s + 2; e <= L; ++e) {
            // [s, e)
            const size_t sublen = e - s;
            const size_t over_half = sublen / 2 + 1;
            std::vector<int> chars(26);
            for (size_t i = s; i < e; ++i) {
                char c = S[i];
                c -= 'a';
                chars[c]++;
                if (chars[c] >= over_half) {
                    std::cout << s+1 << " " << e << std::endl;
                    return 0;
                }
            }
        }
    }

    std::cout << "-1 -1" << std::endl;
    #endif

    /*
      特定の文字Ｘから始まる部分文字列に着目する。
      これが過半数をとる、ということは、
      全体にわたって「薄まる」ような文字列の
      配列があってはならない。

      つまり、Xから始まる文字列について、
      XX : 問題ない。過半数超えている
      XY : 今後のリカバリに期待。XYXと続けば過半数。
          ここで XYZ とくると、もう過半数に
          戻ってくることはない。

      反対に、 XX あるいは XYXという文字列があれば、
      それ自体がアンバランスな文字列になっている。
     */

    for (size_t i = 0; i < L - 2; ++i) {
        if (S[i] == S[i+1]) {
            std::cout << i+1 << " " << i+1+1 << std::endl;
            return 0;
        }
        if (S[i] == S[i+2]) {
            std::cout << i+1 << " " << i+2+1 << std::endl;
            return 0;
        }
    }
    // 最後
    if (S[L-2] == S[L-1]) {
        std::cout << L-2+1 << " " << L-1+1 << std::endl;
        return 0;
    }

    std::cout << "-1 -1" << std::endl;
    return 0;
}


Measured memory_bytes: 512
def calc_tax(price,tax)
  (price * (100 + tax) / 100.0).floor
end

loop do
  x,y,s = gets.split.map(&:to_i)
  break if x == 0 and y == 0 and s == 0
  result = 0
  (1..s-1).each do |i|
    (1..s-1).each do |j|
      result = [result, calc_tax(i,y) + calc_tax(j,y)].max if calc_tax(i,x) + calc_tax(j,x) == s
    end
  end
  puts result
end

Measured memory_bytes: 6120
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.IArray           as IA
import qualified Data.Array.IO               as AI
import qualified Data.Array.MArray           as MA
import qualified Data.Array.ST               as STA
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import qualified Data.Graph                  as G
import           Data.Int
import qualified Data.IntMap                 as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence               as SQ
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Tree                   as T
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putLn :: Show a => a -> IO ()
putLn = print

putList :: Show a => [a] -> IO ()
putList [n] = put n
putList (n:ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n] = putStr n
putStrList (n:ns) = do
  putStr n
  putStr " "
  putStrList ns

main = do
  [a, b] <- readInt
  put $ maximum [a - b, a + b, a * b]


Measured memory_bytes: 380
n = int(input())
s = input()

a, b = [], []
for i in range(n):
    if s[i] == 'W':
        a.append(1)
        b.append(0)
    else:
        a.append(0)
        b.append(1)        
        
import itertools
accum_a = [0] + list(itertools.accumulate(a))
accum_b = list(itertools.accumulate(b))

ans = float('inf')
for i in range(n):
    ans = min(ans, accum_a[i] + abs((accum_b[-1] - accum_b[i])))
print(ans)

Measured memory_bytes: 33108
/*---------------Go Code GO---------------*/

#include<bits/stdc++.h>
using namespace std;

#define     PI              acos(-1.0)
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define     precision(a)    fixed<<setprecision(a)
#define     endl            '\n'
#define     Flush           cout<<flush
#define     LLMX            0x3fffffffffffffff
#define     PW2(a)          (long long)1<<a


int main()
{
    long long i,j,k,l,m,n,o,p,q,tst,csin=0;
    cin>>n>>m;
    if(n==m)
        cout<<"Yes\n";
    else cout<<"No\n";





    return 0;
}




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

using namespace std;

int main(){
	int n, m, x, y, ans = 0;
	cin >> n >> m >> x >> y;
	vector<int> a(n), b(m);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < m; i++){
		cin >> b[i];
	}
	int l, r;
	l = *max_element(a.begin(), a.end());
	r = *min_element(b.begin(), b.end());
	bool f = false;
	for(int i = x + 1; i <= y; i++){
		if(l < i && i <= r){
			f = true;
			break;
		}
	}
	if(f){
		cout << "No War" << endl;
	} else{
		cout << "War" << endl;
	}
	return 0;
}

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

int main() {
  int N, Y;
  cin >> N >> Y;
  
  int x, y, z;
  x = -1;
  y = -1;
  z = -1;
  
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N - i; j++) {
      if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y) {
        x = i;
        y = j;
        z = N - i - j;
        break;
      }
    }
  }
  
  cout << x << " " << y << " " << z << endl;
}




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

int main() {
	//37c
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin>>n;
	typedef long long ll;
	vector<ll> a(n), b(n);
	for (ll &p:a) cin>>p;
	for (ll &p:b) cin>>p;
	typedef pair<ll, int> pii;
	priority_queue<pii> Q;
    for (ll i = 0; i < n; i ++) {
		if (b[i] < a[i]) {
			cout<<-1;
			return 0;
		}
		else if (b[i] > a[i]) Q.emplace(b[i], i);
    }
    long long ans = 0;
    while (!Q.empty()) {
        int i = Q.top().second; Q.pop();

		ll to = max(b[(i+1)%n], b[(i+n-1)%n]);

		ll sum = b[(i+1)%n] + b[(i+n-1)%n];

		if (b[i] < sum) {
			cout<<-1;
			return 0;
		}

        if (a[i] >= to) {
			if ((b[i] - a[i]) % sum) {
				cout<<-1;
				return 0;
			}
			ans += (b[i] - a[i]) / sum;
			b[i] = a[i];
        }

        else {
			ll step = (b[i] - to) / sum + 1;
			b[i] -= step * sum;
			if (b[i] < a[i]) {
				cout<<-1;
				return 0;
			}
			ans += step;
			if (b[i] > a[i]) Q.emplace(b[i], i);
        }
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 10528
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <iomanip>
#include <set>
#include <sstream>
#include <cmath>
#include <deque>
#include <list>
#include <bitset>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long int64;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define FST first
#define SND second

signed main(){
    lint N; cin >> N;
    vector<lint> res(N, 0);
    vector<lint> C(N), S(N), F(N);
    REP(i, N-1){
        cin >> C[i] >> S[i] >> F[i];
    }
    F[N-1]=1;
    REP(i, N-1){
        lint t = S[i] + C[i];
        FOR(j, i+1, N-1) {
            if(t<S[j]) t = S[j];
            if(t%F[j]!=0) t += F[j] - (t%F[j]);
            t += C[j];
        }
        res[i] = t;
    }
    REP(i, N){
        cout << res[i] << "\n";
    }
    cout << flush;
    return 0;
}


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

using namespace std;

vector<int> memo;

class Dice{
    int s[6];   //?????????????????¢
public:
    Dice(int *);
    void throw_dice(char);
    int get_up() const {return s[0];}
    int get_s(int n) const {return s[n];}
    int get_hash() const;
};

Dice::Dice(int *dice_s){
    for (int i=0;i<6;i++) s[i]=dice_s[i];
}

void Dice::throw_dice(char d){
    int temp,temp2;
    switch(d){
        case 'S':
            temp=temp2=s[2-1];
            s[2-1]=s[1-1];
            temp2=s[6-1];
            s[6-1]=temp;
            temp=temp2;
            temp2=s[5-1];
            s[5-1]=temp;
            temp=temp2;
            s[1-1]=temp;
            break;
        case 'E':
            temp=temp2=s[3-1];
            s[3-1]=s[1-1];
            temp2=s[6-1];
            s[6-1]=temp;
            temp=temp2;
            temp2=s[4-1];
            s[4-1]=temp;
            temp=temp2;
            s[1-1]=temp;
            break;
        case 'N':
            temp=temp2=s[5-1];
            s[5-1]=s[1-1];
            temp2=s[6-1];
            s[6-1]=temp;
            temp=temp2;
            temp2=s[2-1];
            s[2-1]=temp;
            temp=temp2;
            s[1-1]=temp;
            break;
        case 'W':
            temp=temp2=s[4-1];
            s[4-1]=s[1-1];
            temp2=s[6-1];
            s[6-1]=temp;
            temp=temp2;
            temp2=s[3-1];
            s[3-1]=temp;
            temp=temp2;
            s[1-1]=temp;
            break;
        default:
            cout<<"Error!";
            break;
    }
}

int Dice::get_hash() const{
    return s[0]+10*s[1]+100*s[2]+1000*s[3]+10000*s[4]+100000*s[5];
}

bool operator == (const Dice &d1,const Dice &d2){
    for (int i=0;i<6;i++){
        if (d1.get_s(i)!=d2.get_s(i)){
            return false;
        }
    }
    return true;
}

int comp_dice(const Dice &d1,Dice d2);

int main(){
    int s[6];
    int i;
    for (i=0;i<6;i++){
        cin>>s[i];
    }
    Dice d1(s);
    for (i=0;i<6;i++){
        cin>>s[i];
    }
    Dice d2(s);
    //dice2???????????????dice1????????´?????????
    if (comp_dice(d1,d2)){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

int comp_dice(const Dice &d1,Dice d2){
    int hash=d2.get_hash();
    for (vector<int>::iterator i=memo.begin();i!=memo.end();i++){
        if (hash==*i){
            //?????§????§£?????????????????????
            return 0;
        }
    }
    memo.push_back(hash);
    if (d1==d2){
        return 1;
    }
    Dice tempd1(d2);
    Dice tempd2(d2);
    Dice tempd3(d2);
    Dice tempd4(d2);
    tempd1.throw_dice('S');
    tempd2.throw_dice('E');
    tempd3.throw_dice('N');
    tempd4.throw_dice('W');
    return comp_dice(d1,tempd1)+comp_dice(d1,tempd2)+comp_dice(d1,tempd3)+comp_dice(d1,tempd4);
}

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

typedef long long int ll;
ll INF = (1ll << 31) - 1;

struct SegmentTree {
 private:
  int n;  // 最下段のノード数
  vector<int> node;

 public:
  SegmentTree(vector<int> v) {
    int sz = v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1, INF);

    // 最下段に突っ込む
    for (int i = 0; i < sz; i++) node[(n - 1) + i] = v[i];

    // 最下段以外を更新していく
    for (int i = n - 2; i >= 0; i--) {
      node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
    }
  }

  // i番目の要素をvalに変更する
  void update(int i, int val) {
    // まず最下段(2n-1)を変更する
    i += n - 1;
    node[i] = val;

    // 上に行きながら更新していく
    while (i > 0) {
      i = (i - 1) / 2;  // 親へ
      node[i] = min(node[2 * i + 1], node[2 * i + 2]);
    }
  }

  // [a,b) 中の最小値を返す。[l,r)は対称区間の左端と右端。
  int getmin(int a, int b, int now = 0, int l = 0, int r = -1) {
    // 初期化
    if (r < 0) r = n;

    // 俺は関係ないとき -> 答えの邪魔にならない値を返す
    if (r <= a || b <= l) return INF;

    // 要求区間の中にノードがすっぽり入ってる → 計算候補として返す
    if (a <= l && r <= b) return node[now];

    // ノードの一部分だけ要求区間に入ってる → 子を再帰的に探索する
    int vl = getmin(a, b, 2 * now + 1, l, (l + r) / 2);  // 子(左)
    int vr = getmin(a, b, 2 * now + 2, (l + r) / 2, r);  // 子(右)
    return min(vl, vr);
  }
};

// ============================================================

int main() {
  int n, q;
  cin >> n >> q;

  vector<int> v(n, INF);
  SegmentTree seg(v);

  int c, x, y;
  for (int i = 0; i < q; i++) {
    cin >> c >> x >> y;
    if (c == 0) {
      seg.update(x, y);
    } else {
      cout << seg.getmin(x, y + 1) << endl;  // 半開区間なので
    }
  }
}



Measured memory_bytes: 4752
import java.util.Arrays;
import java.util.Scanner;

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

		int[] weightList = new int[N];
		for (int i = 0 ; i < N; i++) {
			weightList[i] = sc.nextInt();
		}
		int nokori = X;
		for (int weight : weightList) {
			nokori = nokori - weight;
		}
		Arrays.sort(weightList);

		int dounuts = N + (nokori / weightList[0]);
		System.out.println(dounuts);


	}
}


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

typedef long long ll;

int n, k;
vector<int> v;
vector<vector<bool>> l(1, vector<bool>(1,true)), r(1, vector<bool>(1,true));

void build(vector<vector<bool>>& stk, int x) {
    vector<bool> a = stk.back();
    a.resize(min(int(a.size())+x+1, k+1), false);

    for (int i = int(a.size())-1; i >= x; i--)
        if (a[i-x])
            a[i] = true;

    stk.push_back(a);
}

vector<int> va, vb;
int get(vector<bool>& a, vector<bool>& b) {
    va.clear(); vb.clear();
    for (int i = 0; i < a.size(); i++)
        if (a[i]) va.push_back(i);
    for (int i = 0; i < b.size(); i++)
        if (b[i]) vb.push_back(i);

    int ret = 0;
    for (int i=0, j=int(vb.size())-1; i < va.size(); i++) {
        while (va[i] + vb[j] >= k && j >= 0) j--;
        if (j < 0) break;
        ret = max(ret, va[i] + vb[j]);
    }

    return ret;
}

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

    v.resize(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];

    for (int i = n-1; i >= 0; i--)
        build(r, v[i]);

    int ans = n;
    for (int i = 0; i < n; i++) {
        r.pop_back();
        if (get(l.back(), r.back()) + v[i] >= k) ans--;
        build(l, v[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 4060
#include <bits/stdc++.h>
#define int long long

using namespace std;

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie();
    cout.tie();

    int n, k, x, res = 0;
    cin >> n >> k;
    vector<int>kek;
    while(n--) {
        cin >> x;
        kek.push_back(x);
    }
    sort(kek.begin(), kek.end());
    for(int i = 0; i < k; i++) {
        res+=kek[i];
    }
    cout << res << "\n";


    return 0;
}


Measured memory_bytes: 3596
from collections import deque
n, m = map(int, input().split())
r = [[0] for i in range(n+1)]
num = {0:0, 1:1}
e = deque([]) 
for i in range(m):
	a, b = map(int, input().split())
	r[a].append(b)
	r[b].append(a)
e.append(1)
while len(e) > 0:
	x = e.popleft()
	for y in r[x]:
		if y not in num:
			num[y] = x
			e.append(y)
print("Yes")
for i in range(2, n+1):
	print(num[i])

Measured memory_bytes: 42820
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	for (int i=int(s.size());i>=1;i--){
		for (int j=0;j+i-1<s.size();j++){
			bool o=1;
			for (int k=j;k<=j+i-1;k++)
				o&=(s[k]=='A' || s[k]=='T' || s[k]=='C' || s[k]=='G');
			if (o) return !printf("%d",i);
		}
	}
	puts("0");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define STR_MAX 4000
#define BUF_SIZE (STR_MAX+10)

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

enum {
    ENUM_RED = 0,
    ENUM_GREEN,
    ENUM_BLUE,
    ENUM_ALL
};

char table[256] = {
    ['R'] = ENUM_RED,
    ['G'] = ENUM_GREEN,
    ['B'] = ENUM_BLUE,
};

#define TYPE_ALL ((1<<ENUM_ALL)-1)

int main(void) {
    int len = get_int(); // length
    char str[BUF_SIZE];
    get_str(str, BUF_SIZE);
    int i, j;
    char type[BUF_SIZE] = {0};
    for(i = 0; i < len; i++) {
        type[i] = table[str[i]];
    }
    uint64_t sum[3] = {0};
    // cumulative
    for(i = 0; i < ENUM_ALL; i++) {
        for(j = 0; j < len; j++) {
            sum[i] += (type[j] == i);
        }
    }

    uint64_t cnt = sum[0] * sum[1] * sum[2];

    uint64_t exclude = 0;
    int dist;
    for(dist = 1; dist < len; dist++) {
        for(i = 0; i < len; i++) {
            if(i + dist*2 >= len) break;
            int tp = (1<<type[i]) | (1<<type[i+dist]) | (1<<type[i+dist*2]);
            if(tp == TYPE_ALL) exclude++;
        }
    }
#ifdef DEBUG
    printf("%llu - %llu\n", cnt, exclude);
#endif
    printf("%llu\n", cnt - exclude);

    return 0;
}

Measured memory_bytes: 1740
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */
 
/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */
 
/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
struct edge{
	int to,cost;
};
int n;
vector<vector<edge>> g(100100);
vi color(100100);
bool bo[100100];
void dfs(int v) {
	for(auto e:g[v]) {
		if(bo[e.to])continue;
      	//cout << e.to+1 << " " << e.cost << endl;
		if(e.cost&1) {
          	
			color[e.to]=(color[v]+1)%2;
			
		}
      	else {
          color[e.to]=color[v];
        }
      	bo[e.to]=true;
        dfs(e.to);
	}
}
signed main() {
	cin >> n;
  	fill(bo,bo+100100,false);
	rep(i,n-1) {
		int a,b,c;cin >> a >> b >> c;
		a--;b--;
		g[a].pb({b,c});
		g[b].pb({a,c});
	}
	color[0]=0;
	bo[0]=true;
	dfs(0);
	rep(i, n) cout << color[i] << endl;
	return 0;
}




Measured memory_bytes: 13180
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007
#define intt int64_t

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    int c=min(a, b), cou=0;
    for(int i=c; i!=0; i--) {
        if(a%i==0&&b%i==0) cou++;
        if(cou==k) {cout << i << endl; return 0;}
    }
}

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

int main(){
  char b;
  cin >> b;
  if(b == 'A'){
    cout << 'T' << endl;
  }
  else if(b == 'T'){
    cout << 'A' << endl;
  }
  else if(b == 'C'){
    cout << 'G' << endl;
  }
  else{
    cout << 'C' << endl;
  }
}

Measured memory_bytes: 768
package main

import (
	"fmt"
)

func getMax(nums []int) int {
	max := -10000
	for _, n := range nums {
		if max < n {
			max = n
		}
	}
	return max
}

func getMin(nums []int) int {
	min := 10000
	for _, n := range nums {
		if min > n {
			min = n
		}
	}
	return min
}

func main() {
	var N, M, X, Y int
	fmt.Scan(&N, &M, &X, &Y)

	Xs := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&Xs[i])
	}
	Xs = append(Xs, X)

	Ys := make([]int, M)
	for i := 0; i < M; i++ {
		fmt.Scan(&Ys[i])
	}
	Ys = append(Ys, Y)

	maxX := getMax(Xs)
	minY := getMin(Ys)

	if maxX < minY {
		fmt.Println("No War")
	} else {
		fmt.Println("War")
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define  pb push_back
#define f first
#define s second

///shortcuts
///ctr+alr+T
ll my_max(ll a, ll b)
{
    return a>b? a: b;
}

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

    int n , w; cin>>n>>w;
    vector< pair<ll,ll> > v;
    v.pb({0,0});
    for (int i = 0; i < n; ++i) {
        ll ww;
        ll  vv;
        cin>>ww>>vv;
        v.pb({ww,vv});
    }

    ll dp[n+1][w+1];
    //sort(v.begin(),v.end());
   /* for(auto itr : v)
        cout<<itr.f<<" ";
    cout<<endl;
    for(auto itr : v)
        cout<<itr.s<<" ";
    cout<<endl;*/

    ll mx  = 0;
   // cout<<"haha"<<endl;
    for (int item = 0; item <= n ; item++) {
        for (int weight = 0; weight <= w; weight++)
        {
            if (item == 0 || weight == 0) {
                dp[item][weight] = 0;
            }
            else if (v[item].f <= weight) {
               // cout<<"haha"<<endl;
             //   cout<<v[item].f <<" "<<v[item].s<<endl;
                dp[item][weight] = my_max(v[item].s + dp[item - 1][weight - v[item].f],dp[item - 1][weight]);
               // cout<<"haha"<<endl;
            }
            else {
                dp[item][weight] = dp[item - 1][weight];
            }
           // cout<<dp[item][weight]<<" ";
            mx = my_max(mx  ,dp[item][weight]);
        }
       // cout<<endl;
    }
   cout<<mx<<endl;






}

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

int main(){
	int n;
	cin>>n;
	char s[n]={};
	cin>>s;
	int k=strlen(s);
	char d=s[0];
	int ans=1;
	for(int i=0; i<k; i++){
		if(d!=s[i]){
			ans++;
			d=s[i];
		}
	}
	cout<<ans<<endl;
}

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

void solve(){
  string s; cin >> s;
  int ans;
  if(s == "SUN") ans = 7;
  else if(s == "MON") ans = 6;
  else if(s == "TUE") ans = 5;
  else if(s == "WED") ans = 4;
  else if(s == "THU") ans = 3;
  else if(s == "FRI") ans = 2;
  else ans = 1;
  cout << ans << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
from collections import deque
N,M = list(map(int, input().split()))

# node 3bai
# 0 N-1, N 2N-1, 2N 3N-1.
G = {}
for i in range(3*N):
  G[i] = []

for i in range(M):
  u,v = list(map(int, input().split()))
  u,v = u-1, v-1 # 0-indexed
  G[u].append(v+N)
  G[u+N].append(v+2*N)
  G[u+2*N].append(v)
  
S,T = list(map(int, input().split()))
S,T = S-1, T-1 # 0-indexed

q = deque()
visited = [False for i in range(3*N)]
willsearch = [False for i in range(3*N)]
dists = [-1 for i in range(3*N)]
q.append(S)
dists[S] = 0

while len(q) > 0:
  now = q.popleft()
  visited[now] = True
  for nextp in G[now]:
    if visited[nextp] or willsearch[nextp]:
      continue
    willsearch[nextp] = True
    q.append(nextp)
    dists[nextp] = dists[now] + 1
    
if dists[T] > 0:
  print(dists[T] // 3)
else:
  print(-1)

Measured memory_bytes: 85848
x = list(str(input()))
y = list(str(input()))
z = list(str(input()))

def play(player):
    if player == 'a':
        if x == []:
            print('A')
            return 0
        next = x.pop(0)
    elif player == 'b':
        if y == []:
            print('B')
            return 0
        next = y.pop(0)
    elif player == 'c':
        if  z == []:
            print('C')
            return 0
        next = z.pop(0)
    play(next)

play('a')


Measured memory_bytes: 3188
while True:
    a, op, b = input().split()
    a =int(a)
    b =int(b)
    if op == "?":
        break
    elif op=="+" :
        print(a + b)
    elif op=="-" :
        print(a-b)
    elif op=="*":
        print(a*b)
    else:
        print(a//b)


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

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int> > adj(n);
    while (m--) {
        int u, v; cin >> u >> v;
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    long long a = 0, b = 0, c = 0;
    int col[n];
    bool visited[n];
    fill(visited, visited+n, false);
    function <bool(int, int)> dfs = [&](int i, int c) {
        col[i] = c;
        visited[i] = true;
        bool ret = true;
        for (int j : adj[i]) {
            if (!visited[j]) { if (!dfs(j, -c)) ret = false; }
            else if (col[j] == c) ret = false;
        }
        return ret;
    };
    for (int i = 0; i < n; i++) {
        if (adj[i].empty()) a++;
        else if (visited[i]) continue;
        else if (dfs(i, 1)) b++;
        else c++;
    }
    cout << 2 * a * n - a * a + b * b + (b + c) * (b + c) << endl;
}


Measured memory_bytes: 11008
/**
 *   Author: Praveen Ojha
 *   Created: 26 March 2019
 *   Time: 04:41:04
**/
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define mod 1000000007
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long double ld;
typedef pair<int,int> pii;
int cnt[4];
const int MAXN=305;
double dp[MAXN][MAXN][MAXN]; //dp[i][j][k] refers expected value of state with i->1s, j->2s and k->3s
int n,a[MAXN];
//dp[i][j][k]=1+dp[i][j][k]*(n-(a+b+c))/n+dp[i-1][j][k]*(i/n)+dp[i+1][j-1][k]*(j/n)+dp[i][j+1][k-1]*(k/n)
int32_t main(){__
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i],cnt[a[i]]++;
	//n+=10;
	for(int k=0;k<=n;k++){
		for(int j=0;j<=n;j++){
			for(int i=0;i<=n;i++){
				if(i==0 && j==0 && k==0)
					continue;
				if(i+j+k>n)
					continue;
				double temp=(double)n/(i+j+k);
				double p1=(double)i/(i+j+k);
				double p2=(double)j/(i+j+k);
				double p3=(double)k/(i+j+k);

				if(i)
					dp[i][j][k]+=(dp[i-1][j][k]*p1);
				if(j)
					dp[i][j][k]+=(dp[i+1][j-1][k]*p2);
				if(k)
					dp[i][j][k]+=(dp[i][j+1][k-1]*p3);
				dp[i][j][k]+=temp;
			}
		}
	}
	cout<<setprecision(15)<<dp[cnt[1]][cnt[2]][cnt[3]]<<"\n";
return 0;
}

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

struct card
{
    char suit;
    int value;
    int initOrder;
};

int main(){

    int n;
    cin >> n;
    vector<card> a(n);
    vector<card> b(n);
    string initstr;
    for(int i=0; i<n; i++) {
        cin >> initstr;
        a[i].suit = initstr[0];
        b[i].suit = initstr[0];
        a[i].value = initstr[1] - '0';
        b[i].value = initstr[1] - '0';
        a[i].initOrder = i;
        b[i].initOrder = i;
    }

    bool flag = 1;
    card tmp;
    while(flag){
        flag = 0;
        for(int j=n-1; j>0; j--){
            if(a[j].value < a[j-1].value){
                tmp = a[j];
                a[j] = a[j-1];
                a[j-1] = tmp;
                flag = 1;
            }
        }
    }

    for(int k=0; k<n; k++) {
        if(k != n-1){
            cout << a[k].suit << a[k].value << " ";
        }else{
            cout << a[k].suit << a[k].value << endl;
        }
    }

    string str = "Stable";
    for(int k=0; k<n-1; k++) {
        if((a[k].value == a[k+1].value) and (a[k].initOrder > a[k+1].initOrder)){
            str = "Not stable";
        }
    }
    cout << str << endl;

    int minj = 0;
    for(int i=0; i<n; i++){
        minj = i;
        for(int j=i; j<n; j++){
            if(b[j].value < b[minj].value){
                minj = j;
            }
        }
        if(minj != i){
            tmp = b[i];
            b[i] = b[minj];
            b[minj] = tmp;
        }
    }

    for(int k=0; k<n; k++) {
        if(k != n-1){
            cout << b[k].suit << b[k].value << " ";
        }else{
            cout << b[k].suit << b[k].value << endl;
        }
    }

    str = "Stable";
    for(int k=0; k<n-1; k++) {
        if((b[k].value == b[k+1].value) and (b[k].initOrder > b[k+1].initOrder)){
            str = "Not stable";
        }
    }
    cout << str << endl;

    return 0;
}



Measured memory_bytes: 3184
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    while (1) {
        int m,f,r;
        scanf("%d %d %d",&m,&f,&r);
        
        if(m == -1 && f == -1 && r == -1){
            break;
        }
        
        if(m == -1 || f == -1){
            printf("F\n");
        }
        else if(m + f >= 80){
            printf("A\n");
        }
        else if(m + f >= 65){
            printf("B\n");
        }
        else if (m + f >= 50){
            printf("C\n");
        }
        else if (m + f >=30){
            if (r >= 50) {
                printf("C\n");
            }
            else{
                printf("D\n");
            }
        }
        else{
            printf("F\n");
        }
        
    }
    
    return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define rep(i, a, b) for(int i = a; i < b; ++i)

int debug = 0;

main() {
    int n, q, t, x;
    cin >> n >> q;
    set <array <int, 2>> hor, ver;
    hor.insert({{1, n}});
    ver.insert({{1, n}});
    int ans = (n - 2) * (n - 2);
    int mnx = n, mny = n;
    rep(i, 0, q) {
        cin >> t >> x;
        if (t == 1) {
            auto cur = *(--ver.lower_bound({{x, 0}}));
            ans -= (cur[1] - 2);
            if (x < mnx) {
                mnx = x;
                ver.insert({{x, cur[1]}});
            }
            if (cur[0] == 1) {
                auto fst = *hor.begin();
                hor.erase(fst);
                hor.insert({{fst[0], x}});
            }
            if (debug) {
                cerr << " cur: " << cur[0] << ' ' << cur[1] << endl;
            }
        } else {
            auto cur = *(--hor.lower_bound({{x, 0}}));
            ans -= (cur[1] - 2);
            if (x < mny) {
                mny = x;
                hor.insert({{x, cur[1]}});
            }
            if (cur[0] == 1) {
                auto fst = *ver.begin();
                ver.erase(fst);
                ver.insert({{fst[0], x}});
            }
            if (debug) {
                cerr << " cur: " << cur[0] << ' ' << cur[1] << endl;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 16052
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val x = sc.nextLong()
    println(problem165b(x))
}

fun problem165b(x: Long): Long {
    var x2 = 100L
    var count = 0L
    while (true) {
        x2 = (x2 * 1.01).toLong()
        count++
        if (x2 >= x) return count
    }
}

Measured memory_bytes: 36372