akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> d(3);
    for(int i=0;i<3;i++){
        cin>>d[i];
    }
    vector<pair<int,int>> com;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        int a,b;
        if(s=="AB"){
            a=0,b=1;
        }
        if(s=="AC"){
            a=0,b=2;
        }
        if(s=="BC"){
            a=1,b=2;
        }
        com.emplace_back(a,b);
    }
    com.emplace_back(0,1);
    
    string ans;

    auto add=[&](int s,int t){
        d[s]++;
        d[t]--;
        ans+='A'+s;
    };

    for(int i=0;i<n;i++){
        int s=com[i].first;
        int t=com[i].second;
        if(!d[s]&&!d[t]){
            cout<<"No"<<endl;
            return 0;
        }

        if(!d[s]){
            add(s,t);                        
        }
        else if(!d[t]){
            add(t,s);
        }
        else{
            int ns=com[i+1].first;
            int nt=com[i+1].second;
            if(s==ns||s==nt){
                add(s,t);
            }
            else{
                add(t,s);
            }
        }                
    }

    cout<<"Yes"<<endl;
    for(int i=0;i<n;i++){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 4316
using System;

namespace A {
    class Program {
        static void Main(string[] args) {
            var input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);

            if (a <= 8 && b <= 8) Console.WriteLine("Yay!");
            else Console.WriteLine(":(");
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
using namespace std;
typedef long long ll;
ll mod=1e9+7;


int main(){
  ll n;
  string s;
  cin >> n >> s;
  int check=0;
  int x[2*n];
  for(int i=0;i<2*n;i++){
    if(s[i]=='B'&&check%2==0||s[i]=='W'&&check%2==1){
      check++; x[i]=0;
    }
    else{
      check--; x[i]=1;
    }
    cerr << check << endl;
  }
  if(check){
    cout << 0 << endl;
    return 0;
  }
  ll ans=1;
  for(ll i=1;i<=n;i++){
    ans*=i; ans%=mod;
  }
  ll cnt=0;
  for(ll i=2*n-1;i>=0;i--){
    if(x[i]) cnt++;
    else{
      ans*=cnt; ans%=mod; cnt--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1412
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const lli mod=1e9+7;
const lli pINF=LLONG_MAX;
const lli nINF=-LLONG_MAX;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;}b/=2;a*=a;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define printli(n) printf("%lld\n",n)
#define all(v) v.begin(),v.end()
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}
int a[100005];

int main() {
	int n;
	si(n);
	
	for(int i=1;i<=n;i++) si(a[i]);
	int ans=0;
	
	for(int i=1;i<=n;i++){
	    if(a[i]==i){
	        if(i!=n) {swap(a[i],a[i+1]);ans++;}
	        else {swap(a[i],a[i-1]);ans++;}
	    }
	}
	
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

typedef long double ldou;

inline ll sq(int a) { return a * 1LL * a; }

const int MAXN = 1005;

ldou dist[MAXN];
int x[MAXN], y[MAXN];
ldou r[MAXN];

inline ldou eudist(int x1, int y1, int x2, int y2) {
    return sqrt((ldou)sq(x1 - x2) + sq(y1 - y2));
}

int main() {
    //freopen("", "rt", stdin);
    //freopen("", "wt", stdout);
    int xs, ys, xt, yt, n;
    cin >> xs >> ys >> xt >> yt;
    cin >> n;
    priority_queue<pair<ldou, int>, vector<pair<ldou, int> >, greater<pair<ldou, int> > > pq;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> r[i];
        dist[i] = max((ldou)0.0, eudist(xs, ys, x[i], y[i]) - r[i]);
        pq.push(mp(dist[i], i));
    }
    while (!pq.empty()) {
        ldou w = pq.top().fi;
        int u = pq.top().se;
        pq.pop();

        if (w > dist[u]) continue;

        for (int i = 0; i < n; i++) {
            if (i == u) continue;
            ldou cost = w + max((ldou)0.0, eudist(x[u], y[u], x[i], y[i]) - r[u] - r[i]);
            if (cost < dist[i]) {
                dist[i] = cost;
                pq.push(mp(cost, i));
            }
        }
    }
    ldou ans = eudist(xs, ys, xt, yt);
    for (int i = 0; i < n; i++)
        ans = min(ans, dist[i] + max((ldou)0.0, eudist(x[i], y[i], xt, yt) - r[i]));
    cout << setprecision(10) << fixed << ans << endl;
    return 0;
}






Measured memory_bytes: 8684
import Control.Applicative

main :: IO ()
main = solve <$> f >>= mapM_ putStrLn
  where
    f = words <$> getLine

solve :: [String] -> [String]
solve [sw, sh, c] = [l1] ++ l2s ++ [l3] ++ l2s ++ [l1]
  where
    w = read sw :: Int
    h = read sh :: Int
    l1 = "+" ++ replicate (w - 2) '-' ++ "+"
    l2 = "|" ++ replicate (w - 2) '.' ++ "|"
    l2s = replicate ((h - 3) `div` 2) l2
    l3 = "|" ++ replicate ((w - 3) `div` 2) '.' ++ c ++ replicate ((w - 3) `div` 2) '.' ++ "|"



Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<P> a(n);
    vector<int> b;
    rep(i, n)cin >> a[i].first;
    rep(i, n)cin >> a[i].second;
    ll num1 = 0, num2 = 0, ans = 0;
    rep(i, n){
        if(a[i].first > a[i].second)b.push_back(a[i].first-a[i].second);
        else if(a[i].second > a[i].first){
            num1 += a[i].second-a[i].first;
            ans++;
        }
    }
    sort(rall(b));
    rep(i, b.size()){
        if(num1 > num2){
            ans++;
            num2 += b.at(i);
        }
    }
    if(num1 <= num2)cout << ans << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<map>
using namespace std;
map<string, int> table;
int main()
{
    string word, frequent="", longest="";
    int  N = 0;
    while (cin >> word)
    {
        if (table.find(word) == table.end())
            table[word] = 0;
        table[word]++;
        if (N < table[word])
        {
            N = table[word];
            frequent = word;
        }
        if (word.size()>longest.size())
            longest = word;
    }
    cout << frequent << " " << longest << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    string s,t; cin >> s >> t;
    int ans = 1e9;
    for(int i = 0; i <= s.size() - t.size(); i++){
        int cnt = 0;
        for(int j = 0; j < t.size(); j++){
            if(s[i + j] != t[j]){
                cnt += 1;
            }
        }
        ans = min(ans,cnt);

    }
    cout << ans <<'\n';






}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;

int main(){
    ll k=0;
    for(ll i=0;i<10000000000;i++){k++;
    ;}
    ll S;
    cin >> S;
    ll W;
    cin >> W;
    if(S<=W)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 200005;

int n;
int a[N];
LL ans;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]), a[i] -= i;
  sort(a + 1, a + 1 + n);
  int md = a[(1 + n) / 2];
  for (int i = 1; i <= n; ++i)
    ans += abs(md - a[i]);
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 896
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

int main()
{
  int n;
  cin >> n;
  cout << (n + 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i;
	char str[1001];

	scanf("%s", str);

	for (i = 0; str[i] != '\0'; ++i) {
		if ('A' <= str[i] && str[i] <= 'C') {
			str[i] = 'X' + (str[i] - 'A');
		}
		else {
			str[i] -= 3;
		}
	}

	printf("%s\n", str);

	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>                                           
 
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb; 
typedef long long ll;  
typedef double db;                         
 
 
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, N = 3e5 + 48, mod = 1e9 + 7;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;
 

int n, m, v, u, dp[N], dp1[N];
vi g[N], pref[N], suff[N];


void dfs (int v, int p = 0) {
	dp[v] = 1;
	for (auto to : g[v])
		if (to != p) {
			dfs(to, v);
			dp[v] = dp[v] * 1ll * (dp[to] + 1) % m;
			pref[v].pb(dp[v]); 
		}                                                              

	reverse(all(g[v]));
	dp[v] = 1;
	for (auto to : g[v])
		if (to != p) {
			dp[v] = dp[v] * 1ll * (dp[to] + 1) % m;
			suff[v].pb(dp[v]); 
		}

	reverse(all(suff[v]));
	reverse(all(g[v]));
}


void dfs1 (int v, int p = 0, int id = -1) {
	dp1[v] = 1;
    if (p) { 
		dp1[v] = dp1[p] * 1ll * (id ? pref[p][id - 1] : 1) % m * (id == sz(suff[p]) - 1 ? 1 : suff[p][id + 1]) % m;
		(++dp1[v]) %= m;		    		
    }	

    int cur = 0;
	for (auto to : g[v])
		if (to != p)	
			dfs1(to, v, cur++);
}


main () {
	cin >> n >> m;
	forn (i, 2, n) {
		cin >> v >> u;
		g[v].pb(u);
		g[u].pb(v);
	}

	dfs(1);
	dfs1(1);
	forn (v, 1, n)
		cout << dp[v] * 1ll * dp1[v] % m << endl;
}          
 

Measured memory_bytes: 39168
#include<bits/stdc++.h>
#define forn(i, n) for(int i=0;i<(int)(n);i++)
#define for1(i, n) for(int i=1;i<=(int)(n);i++)
#define fore(i, l, r) for(int i=(int)(l);i<=(int)(r);i++)
#define ford(i, n) for(int i=(int)(n)-1;i>=0;i--)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl "\n"
#define MAX 1000000007
using namespace std;
typedef int64_t ll;
typedef vector<int> vi;
typedef vector<int64_t> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	int n;
	cin >> n;
	vi v(n);
	forn(i,n) cin >> v[i];
	int curr=1;
	int brk=0;
	forn(i,n){
		if(v[i]==curr){
			curr++;
		}
		else
			brk++;
	}
	if(brk==n)
		cout << "-1";
	else
		cout << brk;
	return 0;
}



Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int S, W;

int main() {

	cin >> S >> W;


	if (S <= W)
		cout << "unsafe" << endl;
	else
		cout << "safe" << endl;

	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
long long jc(int a)
{
	long long anss;
	anss = a;
	anss *= (a-1);
	return anss/2;
}
bool pd(string a,string b)
{
	bool bw=true;
	int aoc[26]={0},boc[26]={0};
	for(int i=0;i<a.size();i++)
	{
		aoc[a[i]-'a']++;
	}
	for(int j=0;j<b.size();j++)
	{
		boc[b[j]-'a']++;
	}
	for(int k=0;k<26;k++)
	{
		if(aoc[k]!=boc[k])
		{
			bw=false;
		}
	}
	return bw;
} 	
int main()
{
    string s[100010];
    int n;
    long long ans=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
    	cin>>s[i];
    	sort(s[i].begin(),s[i].end());
	}
	sort(s,s+n);
	string d="";
	int y=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]==d)
		{
			y++;
			if(i==(n-1))
			{
				ans+=jc(y);
			}
		}
		else
		{
			ans+=jc(y);
			y=1;
			d=s[i];
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 7296
def m():
    s = input()
    q = int(input())
    inv = 0
    pre = []
    sub = []

    for i in range(q):
        raw = input().split()
        if len(raw) == 1:
            inv = inv ^ 1
        else:
            f = int(raw[1])-1
            c = raw[2]
            if inv==f:
                pre.append(c)
            else:
                sub.append(c)
    
    if inv==0:
        print(''.join(pre[::-1])+s+''.join(sub))
    else:
        print(''.join(sub[::-1])+s[::-1]+''.join(pre))

m()

Measured memory_bytes: 71640
#include <bits/stdc++.h>
#define prev someone_else_0
#define last someone_else_1
#define next someone_else_2

using namespace std;

const long double eps = 1e-9;

const int MaxN = 2e5 + 15;

long long k, n;

long long a[3];

int main()
{
//    freopen("input.txt", "r", stdin);
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    cin >> k;
    if(k > 1e9 * 1ll * 1e6)
    {
        n = 50;
        long long step1 = k - (k / 50) * 51;
        long long step2 = k - (k - (k / 50) * 49) * 51;
        cout << n << '\n';
        for(int i = 1; i <= 50; ++i)
        {
            long long step = k - (k / 50) * 51;
            if(k % 50 >= i && k % 50 > 0)
                step -= 51;
            cout << 49 - step << ' ';
        }
    }else
    {
        n = 2;
        long long step1 = (k - (k / 2) * 3);
        long long step2 = (k - (k - k / 2) * 3);
        cout << 2 << '\n' << 1 - step2 << ' ' << 1 - step1 << '\n';
    }
}
/**
4 4
2 5
3 3
1 4
2 2
0 3
1 1
*/


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int main() {
    int n; cin >> n;
    vector<int> c(n-1), s(n-1), f(n-1);
    rep(i, n-1) cin >> c[i] >> s[i] >> f[i];

    rep(i, n-1) {
        int now = 0;
        FOR(j,i,n-1) {
            if(now < s[j]) {
                now = s[j];
                now += c[j];
            } else {
                int t = (now - s[j])%f[j];
                if(t == 0) {
                    now += c[j];
                } else {
                    now += f[j] - t;
                    now += c[j];
                }
            }
        }
        cout << now << endl;
    }

    cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	long long x=0,maxi=0;
	for(long long i=0; i<n; i++) {
		if(s[i]=='I') {
			x++;
			if(x>maxi)
				maxi=x;
		} else
			x--;
	}
	cout<<maxi;
}


Measured memory_bytes: 256
H,W = map(int,input().split())

if H % 2==0 and W % 2 ==0 :
    ans = (H*W)/2
elif H % 2==0 and W % 2 ==1 :
    ans = (H*W)/2
elif H % 2==1 and W % 2 ==0 :
    ans = (H*W)/2
elif H % 2==1 and W % 2 ==1 :
    ans = (H*W)/2 + 1

if H==1 or W==1:
    ans= 1
print(int(ans))


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1000 + 5;
const int MAX_N = 1e5 + 5;

int MOD = 1e9 + 7;
long modpow(long m, long p) {
    if (p == 0) return 1;
    if (p % 2)
        return m * modpow(m, p - 1) % MOD;
    else {
        long res = modpow(m, p / 2);
        return res * res % MOD;
    }
}

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    ll ans = 0;
    for (ll i = 0; i < 60; i++) {
        ll cnt_zero = 0;
        ll cnt_one = 0;
        for (auto e : a) {
            if ((e >> i) & 1 == 1) {
                cnt_one += 1;
            } else {
                cnt_zero += 1;
            }
        }
        ll temp = (cnt_one * cnt_zero) % M;
        temp = temp * ((ll)pow(2, i) % M);
        ans += temp;
        ans %= M;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include<stdio.h>
int main(void){
  long long n,m,sum=0;
  scanf("%lld",&n);
  for(m=1;m*m<=n;m++){
    if(n%m==0 && (n/m)-1>m)sum=sum+(n/m)-1;
  }
  printf("%lld",sum);
  return 0;
}


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

#define Q 1000000007
#define N 100000
#define W 0
#define WB 1

int n;
vector<int> adj[N];
int visited[N];
long long dp[N][2]; // node, W/WorB


void dfs(int now){
  int isLeaf = 1;
//  cout << "dfs " << now << endl;
  visited[now] = 1;
  dp[now][W] = 1;
  dp[now][WB] = 1;
  for (auto it = adj[now].begin(); it != adj[now].end(); it++){
    if (visited[*it]) continue;
    isLeaf = 0;
    dfs(*it);
    dp[now][WB] *= dp[*it][W];
    dp[now][WB] %= Q;
    dp[now][W] *= dp[*it][WB];
    dp[now][W] %= Q;
  }
  (dp[now][WB] += dp[now][W]) %= Q;
  if (isLeaf){
    dp[now][W] = 1; dp[now][WB] = 2;
  }
//  cout << "dp[" << now << "] = " << dp[now][W] << ", " << dp[now][WB] << endl;
}

int main(void){
  cin >> n;
  for (int i=0; i<n; i++){
    visited[i] = 0;
    adj[i] = vector<int>();
  }
  for (int i=0; i<n-1; i++){
    int a, b;
    cin >> a >> b;
    adj[a-1].push_back(b-1);
    adj[b-1].push_back(a-1);
  }
  dfs(0);
  cout << dp[0][WB] << endl;  
  return 0;
}


Measured memory_bytes: 11904
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
to = [0 for _ in range(n + 1)]

for i in range(1, n + 1):
    to[i] = a[i - 1]
ans = 0
for i in range(1, n + 1):
    if to[to[i]] == i:
        ans += 1
print(ans // 2)


Measured memory_bytes: 14008
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  vector<int> vec(n);
  int total = 0;
  rep(i, n) {
    cin >> vec[i];
    total += vec[i];
  }
  sort(vec.begin(), vec.end());
  ll ans = INF;
  rep(i,vec[n-1]+1) {
    ll tmp = 0;
    rep(j, n) {
      tmp += pow((vec[j] - i), 2);
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <map>

int main(){
    int a, b;
    std::cin >> a >> b;

    std::cout << ((b % a == 0)? (a + b):(b - a)) << std::endl;
    
    return 0;
}

Measured memory_bytes: 3600
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    R,G,B,n=map(int,input().split())
    ans=0
    for r in range(n//R+1):
        for g in range((n-r*R)//G+1):
            if (n-r*R-g*G)%B==0:
                ans+=1
    print(ans)


if __name__=='__main__':
    main()

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

const int INF = 1e9;

int main() {
  int n, a;
  cin>>n>>a;
  int x[n];
  for (int i=0; i<n; i++) cin>>x[i];

  long long dp[n+1][2501];
  for (int i=0; i<n+1; i++) {
    for (int j=0; j<2501; j++) {
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  for (int i=0; i<n; i++) {
    for (int j=i; j>=0; j--) {
      for (int k=0; k<2501; k++) {
        if (dp[j][k] > 0) {
          dp[j+1][k+x[i]] += dp[j][k];
        }
      }
    }
  }
  long long cnt = 0;
  for (int i=1; i<=n; i++) {
    for (int j=1; j<2501; j++) {
      if (i * a == j) {
        cnt += dp[i][j];
      }
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
#define MOD 1000000007

//制約 k,n<10^7  and  p is primenumber  and p>n
const ll MAX=1001001;
vl fac(MAX), finv(MAX), inv(MAX);
// テーブルを作る前処理 O(n)
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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 COM(ll n, ll k){
    if (n<k or n<0 or k<0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    // solution comes here
    ll X, Y, n, m;
    cin >> X >> Y;

    n=( -X + 2*Y)/3;
    m=( -Y + 2*X)/3;
    if((X+Y)%3 or (-X+2*Y)%3 or (2*X-Y)%3 or n<0 or m<0){
        cout << 0 << nl;
        return 0;
    }

    COMinit();
    cout << COM(n+m, min(m,n)) << nl;
}

Measured memory_bytes: 23680
s = input()
t = input()

ds = dict()
dt = dict()
tr = dict()
tr2 = dict()
res = True
for i in range(len(s)):
    ds[s[i]] = True
    dt[s[i]] = True
    if s[i] not in tr:
        tr[s[i]] = t[i]
    else:
        if tr[s[i]] != t[i]:
            res = False

    if t[i] not in tr2:
        tr2[t[i]] = s[i]
    else:
        if tr2[t[i]] != s[i]:
            res = False

#if (len(ds) == 26 or len(dt) == 26) and ds != dt:
#    res = False

print("Yes" if res else "No")


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

int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

int main(void)
{
	int N;
	int score[101];
	int a=0;
	int b=0;
	int i;
	int t;
	
	for(i=0;i<N;i++){
		score[i]=0;
	}
	
	t=scanf("%d", &N);
	for(i=0;i<N;i++){
		t=scanf("%d", &score[i]);
	}
	
	qsort(score, N, sizeof(int), compare_int);
	for(i=0;i<N;i++){
		if(i%2==0){
			a=a+score[i];
		}else{
			b=b+score[i];
		}
	}
	
	printf("%d",a-b);
	
	return 0;
}

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



int main(){
    for(int l=0;l>-1;l++){
        if(l !=0){ cout << endl;}
        int n,m; cin>>n>>m;
        if(n==0&&m==0) break;
        vector<int> a(n);
        for(int i=0;i<n;i++){
            cin >> a[i];
        }//入力終わり
        int ans=0;
        sort(a.begin(),a.end(),greater<>());
        for(int i=0;i<n-1;i++){
            for(int j=i+1;j<n;j++){
                if(a[i]+a[j]<=m){
                    
                        ans=max(ans,a[i]+a[j]);
                        break;
                    
                }
            }
        }
        if(ans==0) cout << "NONE" ;
        else cout << ans ;

        
    
    }
}





Measured memory_bytes: 3124
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int lst[410];

int main() {
	for (int i = 1; i <=400; i++) {
		lst[i] = i * i;
	}
	int a, b,temp;
	cin >> a >> b;
	int cnt=0;
	temp = b;
	while (temp > 0) {
		cnt++;
		temp /= 10;
	}
	int ans = a * pow(10, cnt) + b;
	for (int i = 1; i <= 400;i++) {
		if (ans == lst[i]) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 4000
#include <iostream>
#include <set>
#include <numeric>
#include <map>
#include <vector>
using namespace std;

bool used[200000];
vector <int> edges[200000];

void dfs(int cur){
    used[cur] = true;
    for(int i = 0; i < edges[cur].size(); i++){
        int next = edges[cur][i];
        if(used[next]){
            continue;
        }
        dfs(next);
    }
}

int main(void){
   int N;
   int M;
   cin >> N >> M;
   
   for(int i = 0; i < N; i++){
       int K;
       cin >> K;
       for(int j = 0; j < K; j++){
           int L;
           cin >> L;
           edges[i].push_back(N + L - 1);
           edges[N + L - 1].push_back(i);
       }
   }
   
   dfs(0);
   for(int i = 0; i < N; i++){
       if(!used[i]){
           cout << "NO" << endl;
           return 0;
       }
   }
   cout << "YES" << endl;
   return 0;
}


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

int main() {
  int n,i,ans=0;
  cin>>n;
  
  for(i=0;n>=4*i;i++)
    if((n-4*i)%7==0)
      ans++;
  
  for(i=0;n>=7*i;i++)
    if((n-7*i)%4==0)
      ans++;
  
  if(ans==0)
    cout<<"No";
  else cout<<"Yes";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;


int main(){
    string S, S_; cin >> S; S_ = S;
    set<char> ST;
    for(auto ch : S) ST.insert(ch);
    
    for(int i = 0; i < 26; i++){
        char add = i+97;
        if(ST.find(add) == ST.end()){
            S_+=add;
            cout << S_ << endl;
            return 0;
        }
    }
 //cout << 1 << endl;
    for(int i = S.size()-1; i >=0; i--){
        char ch = S[i];
        //cout << S_ << endl;
        for(int j = (int)S[i]; j <= 122; j++){
            if(ST.find((char)j) == ST.end() && S[i] < j){
                S_[i] = j;
                cout << S_ << endl;
                return 0;
            }
        }
        S_.erase(i);
        ST.erase(ch);

    } 
    cout << -1 << endl;
}

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

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

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

void modcomb(vec &c, ll n, ll k, ll m)
{
    vec inv(k+1, 0);
    inv[1] = 1;
    c[0] = 1; c[1] = n;
    REP(i,2,k+1) {
        inv[i] = m - inv[m%i] * (m / i) % m;
        c[i] = (((c[i-1] * (n - i + 1)) % m) * inv[i]) % m;
    }
}

int main()
{
    ll N, M, K;
    cin >> N >> M >> K;

    vec C(K-2+1, 0);
    modcomb(C, N*M-2, K-2, MOD);
    ll a = ((M*M*N*(N*N-1) + M*N*N*(M*M-1)) / 6) % MOD;
    a = a * C[K-2] % MOD;
    PR(a);

    return 0;
}

/*



*/

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

int main() {
	int n,ans=0;
	char str[100001]={};
	scanf("%d", &n);
	scanf("%s", str);
	ans=strlen(str);
	for (int i = 0; i < n; i++) {
		int j=i+1;
		if(str[i]==str[j]){
			while(str[i]==str[j]){
				j++;
				ans--;
			}
			i=j-1;
		}
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a,b,c;
	scanf("%d %d %d", &a,&b,&c);
	
	if(a == b && a != c){
		printf("Yes\n");
	}
	else if(b == c && b != a){
		printf("Yes\n");
	}
	else if(c == a && c != b){
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 3116
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

M = 1e+18.to_i

def main(argv)
  n = InputLine.to_i
  a = InputLine.to_ia

  if a.include?(0) then
    puts 0.to_s
    return
  end

  p = 1
  n.times do |i|
    p = p * a[i]

    if p > M then
      p = -1
      break
    end
  end

  puts p.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 23456
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll q;cin>>q;
  for(ll i=0;i<q;i++){
    ll a,b;cin>>a>>b;
    if(a>b)swap(a,b);
    ll ans=a-1;
    ll l=pow(a*b,0.5);
    if(l*(l+1)<a*b)l++;
    //if(i==5){cout<<l<<" "<<r;return 0;}
    if(l>=b){
      ll u=(a*b)/(a+1);
      if((a*b)%(a+1)==0)u--;
      ans+=u;
    }
    else{
      ans+=l-1;
      ll u=(a*b)/l;
      if((a*b)%l==0)u--;
      ans+=max(u-a,(ll)0);
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mod 1000000007
using namespace std;

long long n,m,x[100010],y[100010],sum1,sum2;

int main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=1; i<=n; i++)
	{
		scanf("%lld",&x[i]);
	}
	for(int i=1; i<=m; i++)
	{
		scanf("%lld",&y[i]);
	}
	for(int i=1; i<=n; i++)
	{
		sum1+=(i-1)*x[i]-(n-i)*x[i];
	}
	sum1%=mod;
	for(int i=1; i<=m; i++)
	{
		sum2+=(i-1)*y[i]-(m-i)*y[i];
	}
	sum2%=mod;
	printf("%lld\n",sum1*sum2%mod);
}

Measured memory_bytes: 1792
#include<stdio.h>

int n,A[2000];

int solve(int i, int m){
  int result;
  if(m == 0)return 1;
  if(i >= n)return 0;
  result = solve(i + 1,m) || solve(i + 1,m - A[i]);
  return result;
}

int main(){
  int q,M,i;

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d",&M);
if(solve(0,M))printf("yes\n");
    else printf("no\n");
  }
  return 0;
}



Measured memory_bytes: 2100
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args){
        int H, N; {int[] a = in.ii(); H = a[0]; N = a[1];}
        int[] A = new int[N];
        int[] B = new int[N];
        int[] dp = new int[H+1];
        Arrays.fill(dp, 100000000);
        dp[0] = 0;
        
        int max = 0;
        for(int i = 0; i < N; i++){
            int[] a = in.ii();
            A[i] = a[0];
            B[i] = a[1];
            if(max < a[0]){
                max = a[0];
            }
        }        

        for(int i = 0; i <= H; i++){
            int min = dp[i];
            for(int j = 0; j < N; j++){
                int k = i-A[j];
                if(0 <= k){
                    int m = dp[k] + B[j];
                    if(m < min){
                        min = m; 
                    }
                }
            }
            dp[i] = min;
        }
        
        int min = dp[H];
        for(int i = H+1, M = H+max; i < M; i++){
            for(int j = 0; j < N; j++){
                int k = i-A[j];
                if(0 <= k && k < H){
                    int m = dp[k] + B[j];
                    if(m < min){
                        min = m;
                    }
                }
            }
        }
        
        out.println(min);
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 25020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //10^19 < 9223372036854775807
typedef unsigned long long ull; //10^20 < 18446744073709551615

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

#define MOD 1000000007

int main(void)
{
    ll N,K;
    cin >> N >> K;

    vector<int> A(110,0);
    REP (i, K) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int a;
            cin >> a;
            A[a-1]++;
        }
    }

    int ans = 0;
    REP (i,N) {
        if (A[i] > 0 ) {
            ans++;
        }
    }

    cout << N-ans << endl;

    return 0;
}


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

unsigned long long dp[51][51][2510], a[51];

int main()
{
    int n, x; cin>>n>>x;
    for(int i=0; i<n; ++i) cin>>a[i];

    dp[0][0][0]=1;
    for(int i=1; i<=n; ++i) {
        for(int j=0; j<=i; ++j) {
            for(int k=0; k<=2500; ++k) {
                dp[i][j][k]=dp[i-1][j][k];
                if (j>0 and k>=a[i-1])
                    dp[i][j][k]+=dp[i-1][j-1][k-a[i-1]];
            }
        }
    }

    auto res=0ULL;
    for(int j=1; j<=n; ++j)
        if (x*j<2510) res+=dp[n][j][x*j];
    cout<<res<<endl;
}


Measured memory_bytes: 26496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n,k;
    cin>>n>>k;
    ll ans=1;
    rep(0,i,n)ans=min(ans+k,2*ans);
    cout<<ans;
}


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

#define INF 2147483637

int main(){
	int n;
	int d[100005] = {INF};
	int h[100005] = {0};
	std::cin >> n;
	for(int i = 1; i <= n; i++){
		std::cin >> h[i];
	}
	
	
	d[2] = abs(h[1] - h[2]);
	d[1] = 0;
	for(int i = 3; i <= n; i++){
		d[i] = std::min(d[i - 1] + std::abs(h[i] - h[i - 1]), d[i - 2] + std::abs(h[i] - h[i - 2]));	
	}
	
	std::cout << d[n] << '\n';
	
	return 0;
}

Measured memory_bytes: 4368
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
int main(){
    int64_t a,b,c,k;
    cin>>a>>b>>c>>k;
    int64_t ans=0;
    if(a>=k){
        ans = k;
    }
    else if(a+b>=k){
        ans = a;
    }
    else{//a+b+c>=k
        ans = a;
        k -= a+b;
        ans -= k;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <stdio.h>

int main()
{
        int N;
        int a[100];
        int b[100];
        int c[100];
        int out = 0;

        scanf("%d", &N);

        for (int i = 0; i < N; i++)     scanf("%d", &a[i]);
        for (int i = 0; i < N; i++)     scanf("%d", &b[i]);
        for (int i = 0; i < N-1; i++)   scanf("%d", &c[i]);

        for (int i = 0; i < N; i++) {
                out += b[a[i]-1];
                if (a[i]-1 == a[i-1]) {
                        out += c[a[i-1]-1];
                }
        }

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

        return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
using namespace std;
int main(void){
   int a,b,c;
   cin>>a>>b>>c;
   if(a==b)cout<<c<<endl;
   else if(a==c)cout<<b<<endl;
   else cout<<a<<endl;
    
}


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

class Main {
	public static void main(String args[]) throws IOException {
		@SuppressWarnings("resource")
		Scanner cin = new Scanner(System.in);
		ArrayList<String> inLines = new ArrayList<String>();
		for (; cin.hasNext();) {
			inLines.add(cin.nextLine());
		}
		Solver solver = new Solver();
		solver.solve(inLines);
	}
}

class Solver {

	public void solve(ArrayList<String> inLines) {
		long x = Long.parseLong(inLines.get(0));
		long ans = (x / 11) * 2;
		if (x % 11 != 0) {
			if (x % 11 <= 6)
				ans += 1;
			else
				ans += 2;
		}
		System.out.println(ans);
	}
}


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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  
  if (a.at(a.size()-1) == b.at(0) && b.at(b.size()-1) == c.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

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

int main(void){
  int N;
  cin >> N;
  
  int ans = 100;
  for(int i = 0; i < N; i++){
    int x;
    cin >> x;
    
    for(int j = 0 ;; j++){
      if((x % 2) == 0){
        x /= 2;
      }else{
        if(ans > j){
          ans = j;
        }
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef vector<vector<P>> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<ll> vec;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n;
    cin>>n;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    int g=0;
    rep(i,n){
        g+=a[i];
    }
    
    sort(rall(a));
    cout<<a[n-1]<<" ";
    cout<<a[0]<<" ";
    cout<<g<<endl;

}


Measured memory_bytes: 3300
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    int a,n,d,x;
    cin >> n >> d >> x;
    for(int i = 0;i < n;i++)
    {
        cin >> a;
        for(int j = 1;j <= d;j += a)
        {
            x++;
        }
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*
import kotlin.*

import java.io.InputStream
import java.lang.NumberFormatException
import java.lang.StringBuilder


fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = FastScanner()
        val s = sc.next()

        // sに2種
        // abab...のみ
        // Second

        // 2種以上
        // 各文字1つずつ |s|%2==1? First:Second
        //
        // 各文字1つずつ残して消す
        //
        //
        //

        println(if((s[0] == s[s.length-1]) xor (s.length %2==0)) "Second" else "First")
    }
}


class FastScanner {
    companion object {
        val input: InputStream = System.`in`
        val buffer = ByteArray(1024) { 0 }
        fun isPrintableChar(c: Int): Boolean = c in 33..126
    }

    var ptr = 0
    var buflen = 0
    private fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = input.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }

    private fun readByte(): Int = if (hasNextByte()) buffer[ptr++].toInt() else -1

    private fun skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr].toInt())) ptr++
    }

    fun hasNext(): Boolean {
        skipUnprintable()
        return hasNextByte()
    }

    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b)
            b = readByte()
        }
        return sb.toString()
    }

    fun nextInt(): Int {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0
        var b = readByte()
        // '-' = 45
        val minus = b == 45
        if (minus) {
            b = readByte()
        }

        // '0' = 48 '9' = 57
        if (b !in 48..57) {
            throw NumberFormatException()
        }

        while (true) {
            if (b in 48..57) {
                n *= 10
                n += b - 48
            } else if (b == -1 || !isPrintableChar(b)) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var b = readByte()
        // '-' = 45
        val minus = b == 45
        if (minus) {
            b = readByte()
        }

        // '0' = 48 '9' = 57
        if (b !in 48..57) {
            throw NumberFormatException()
        }

        while (true) {
            if (b in 48..57) {
                n *= 10
                n += b - 48
            } else if (b == -1 || !isPrintableChar(b)) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextDouble(): Double = next().toDouble()
}


Measured memory_bytes: 31392
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep0(i, n) for (int i = 0; i <= (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX
int main(){
    ll n,m;
    cin>>n>>m;
    ll p[m];
    string s[m];
    rep(i,m){
        cin>>p[i]>>s[i];
    }
    ll ac[n+1]={};
    ll wa[n+1]={};
    rep(i,m){
        if(s[i]=="AC") ac[p[i]]=1;
        else{
            if(ac[p[i]]!=1){
                wa[p[i]]+=1;
            }
        }
    }
    ll ans=0;
    ll anw=0;
    rep0(i,n){
        ans+=ac[i];
        if(ac[i]==1) anw+=wa[i];
    }
    cout<<ans<<" "<<anw<<endl;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int n; cin>>n;
    vector <int> a(n); 
    map <int,int> ma;
    rep(i,n) {cin>>a[i]; ma[a[i]]++;}
    sort(a.begin(),a.end());
    int ans = 0;
    rrep(i,n){
        int now = a[i];
        if(ma[now] == 0) continue;
        int goal = 1LL;
        while(now>=goal) goal*= 2LL;
        int need = goal - a[i];
        if(a[i] == need){
            if(ma[need]>=2) ma[need]-=2, ans += 1;
        }else if(ma[goal-a[i]]) ma[goal-a[i]]--, ma[now]--, ans += 1; 
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 26752
#include<bits/stdc++.h>
 
using namespace std;
 
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);
int sub(int,int);
template<typename A> ostream& operator<<(ostream&,vector<A>&);
 
const int N=5000002;

void solve(){
	int n;
	cin>>n;
	ll ans=(1ll*(n-1)*(n))/2;
	cout<<ans;
			
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}


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

using namespace std;

typedef long long ll;

int a[1000000];

int main()
{
    int n, k;
    while(cin >> n >> k && n && k) {
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }
        
        ll pre = 0;
        for(int i = 0; i < k; i++) {
            pre += a[i];
        }
        
        ll ret = pre;
        for(int i = 0; i < n - k; i++) {
            pre = pre - a[i] + a[k + i];
            ret = max(ret, pre);
        }
        
        cout << ret << endl;
    }
}

Measured memory_bytes: 1544
import java.util.Scanner;

//Sum of Consecutive Integers
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			int res = 0;
			for(int i=1;i+1<=n;i++){
				int s = 2*i+1, k = i+2;
				while(s<n){
					s+=k; k++;
				}
				if(s==n)res++;
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000