akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll mod=1e9+7;

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

int main()
{
    ll n;
    cin >> n;
    //vector<ll> a(n),b(n);
    vector<ll> p(200001);
    ll v=1;
    rep(i,200001){
        p[i]=v;
        v*=2;
        v%=mod;
    }
    map<pll,ll> m;
    map<pll,bool> s;
    rep(i,n){
        ll p,q;
        cin >> p >> q;
        if(p==0 && q==0){
            m[make_pair(0,0)]++;
            continue;
        }
        if(p==0 && q!=0){
            m[make_pair(0,1)]++;
            continue;
        }
        if(p!=0 && q==0){
            m[make_pair(1,0)]++;
            continue;
        }
        ll r=gcd(p,q);
        p/=r;
        q/=r;
        //a[i]=p;
        //b[i]=q;
        m[make_pair(p,q)]++;
    }
    ll ans=1;
    for(auto x:m){
        //cout << x.fi.fi << " " << x.fi.se << endl;
        if(x.fi.fi==0 && x.fi.se==0){
            continue;
        }
        if(s.count(make_pair(x.fi.fi,x.fi.se))){
            continue;
        }
        ll sum1=0;
        if(m.count(make_pair(-x.fi.se,x.fi.fi))){
            sum1+=m[make_pair(-x.fi.se,x.fi.fi)];
            s[make_pair(-x.fi.se,x.fi.fi)]=true;
        }
        if(m.count(make_pair(x.fi.se,-x.fi.fi))){
            sum1+=m[make_pair(x.fi.se,-x.fi.fi)];
            s[make_pair(x.fi.se,-x.fi.fi)]=true;
        }
        ll sum2=0;
        if(m.count(make_pair(x.fi.fi,x.fi.se))){
            sum2+=m[make_pair(x.fi.fi,x.fi.se)];
            s[make_pair(x.fi.fi,x.fi.se)]=true;
        }
        if(m.count(make_pair(-x.fi.fi,-x.fi.se))){
            sum2+=m[make_pair(-x.fi.fi,-x.fi.se)];
            s[make_pair(-x.fi.fi,-x.fi.se)]=true;
        }
        
        ans*=(p[sum1]+p[sum2]-1)%mod;
        ans%=mod;
    }
    ans+=m[make_pair(0,0)];
    cout << (ans+mod-1)%mod << endl;
    return 0;
} 


Measured memory_bytes: 29820
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const n = Number(stdin.split('\n')[0])
const [d, x] = stdin
  .split('\n')[1]
  .split(' ')
  .map(Number)
const a = stdin
  .split('\n')
  .map(Number)
  .slice(2)

const ans = () => {
  const count = a
    .map(v => {
      const arr = []
      for (let i = 0; i * v + 1 <= d; i++) {
        arr.push(i * v + 1)
      }
      return arr.length
    })
    .reduce((p, c) => p + c)

  return count + x
}

console.log(ans())


Measured memory_bytes: 7372
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  ll ans = 0;
  std::cin >> N;
  std::vector<int> A(N);
  for(int i=0;i<N;i++) {
    std::cin >> A[i];
    A[i]-=i+1;
  }
  sort(A.begin(), A.end());
  for(int i=0;i<N;i++){
    ans += abs(A[i]-A[N/2]);
  }
  std::cout << ans << '\n';
  return 0;
}


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

#ifdef DEBUG
    #include "debug.h"
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define dump(...)
#endif


// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

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

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

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

#define int long long
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

//*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)




void solve(){
    int X, Y;
    cin >> X >> Y;
    
    bool ans = false;
    
    for(int i=0; i<=X; i++)
        if(i*4+(X-i)*2==Y) ans=true;
    
    if(ans)Yes;
    else No;
}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T x=0,f=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	int main(){
		long long n=read<long long>();
		printf("%lld\n",(n/500)*1000+(n%500)/5*5);
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

Measured memory_bytes: 256
import java.util.Scanner;

  
public class Main {
	
	
  public static void main(String[] args) {
	  int n=Integer.MAX_VALUE;
	  Scanner sc=new Scanner(System.in);
	 
	  for(int i=0;i<n;i++){
	  int a=Integer.parseInt(sc.next());
	 String s=sc.next();
	 int b=Integer.parseInt(sc.next()); 
	 
	 if(s.equals("+")){
		 System.out.println(a+b);
	 }
	 else if(s.equals("-")){
		 System.out.println(a-b); 
	 
	 }
 else if(s.equals("*")){
	 System.out.println(a*b);
 }
	 
 else if(s.equals("/")){
	 System.out.println(a/b);
 
 }
 else if(s.equals("?")){
	break; 
 }
 }
  }
}

Measured memory_bytes: 17352
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n, sum = 0; 
    cin>>n; 
    if (n>2) sum = n-1;
    for (int i=2;i*i<=n;i++){
    	if (n%i==0) { 
    		int k = n/i-1;
    		if (n/k==n%k) sum += k;
    	} 
    } 
    cout << sum << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main()
{
#ifdef TarekHasan
    freopen("input.txt","r",stdin);
#endif // TarekHasan
    string str,pattern;
    cin >> str >> pattern;

    auto haming_distance = [&](string a, string b)
    {
        int counter = 0;
        for(int i=0; i<a.size(); i++)
        {
            if(a[i]!=b[i])
                counter++;
        }
        return counter;
    };


    int min_mismatch = INT_MAX;
    for(int i=0; i<=str.size()-pattern.size(); i++)
    {
        min_mismatch = min(min_mismatch,haming_distance(str.substr(i,pattern.size()),pattern));
    }
    cout << min_mismatch << endl;
    return 0;
}


Measured memory_bytes: 3636
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(n - 2):
    a = list()
    a.append(p[i])
    a.append(p[i + 1])
    a.append(p[i + 2])
    check = p[i + 1]
    a.sort()
    if check == a[1]:
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			
			final int t = sc.nextInt();
			
			if(t == 0){
				break;
			}
			
			final int n = sc.nextInt();
			
			int time = t;
			for(int i = 0; i < n; i++){
				int start = sc.nextInt();
				int end = sc.nextInt();
				
				time -= end - start;
			}
			
			if(time <= 0){
				System.out.println("OK");
			}else{
				System.out.println(time);
			}
						
		}
	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
int main(){
    int a,b,c;cin >> a >> b >> c;
    bool ok=true;
    if(a==b&&a==c) ok=false;
    else if(a!=b&&b!=c&&c!=a) ok=false;
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int a, b, c, k;
   
	scanf("%d %d %d %d", &a, &b, &c, &k);
	if (k < a) {
		printf("%d\n", k);
	} else if (k < a + b) {
		printf("%d\n", a);
	} else {
		printf("%d\n", a - k + a + b);
   }
	return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int min=1000000;
  for(int i=0;i<s.size()-2;i++){
    string tmp = "aaa";
    tmp[0] = s[i];
    tmp[1] = s[i+1];
    tmp[2] = s[i+2];
    if (min>abs(stoi(tmp)-753)) min=abs(stoi(tmp)-753);
  }
  cout << min;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#pragma warning (disable: 4996)

long long N, X[1 << 18], Y[1 << 18], S[1 << 18], A[1 << 18][2], V1, V2;
long long FinalAns = 0;

int main() {
	scanf("%lld", &N);
	for (int i = 1; i <= 2 * N; i++) {
		scanf("%lld%lld", &X[i], &Y[i]);
		FinalAns += abs(X[i] - max(1LL, min(N, X[i])));
		FinalAns += abs(Y[i] - max(1LL, min(2LL, Y[i])));
		X[i] = max(1LL, min(N, X[i]));
		Y[i] = max(1LL, min(2LL, Y[i]));
		S[X[i]]++; A[X[i]][Y[i]]++;
	}
	for (int i = 1; i <= N; i++) S[i] += S[i - 1];
	for (int i = 2; i <= N; i++) FinalAns += abs(2LL * (i - 1LL) - S[i - 1]);

	long long D1 = 0, D2 = 0;
	for (int i = 1; i <= N; i++) {
		D1 += (A[i][1] - 1LL);
		D2 += (A[i][2] - 1LL);
		if (D1 > 0LL && 0LL > D2) {
			long long K = min(D1, -D2);
			D1 -= K; D2 += K;
			FinalAns += K;
		}
		if (D1 < 0LL && 0LL < D2) {
			long long K = min(-D1, D2);
			D1 += K; D2 -= K;
			FinalAns += K;
		}
	}
	cout << FinalAns << endl;
	return 0;
}


Measured memory_bytes: 8716
import sys
range = xrange
input = raw_input

n,k = [int(x) for x in input().split()]
V = [int(x) for x in input().split()]

bestsumma = -10**18

for pick in range(min(k+1,n+1)):
    for leftpick in range(pick+1):
        rightpick = pick - leftpick
       
        picks = V[:leftpick]
        if rightpick:
            picks += V[-rightpick:]
        picks.sort(reverse=True)
        
        cumsum = [0]
        for p in picks:
            cumsum.append(cumsum[-1] + p)

        for put_back in range(0, k - pick+1):
            left = pick - put_back
            #score = sum(picks[:left])
            if len(cumsum)>left>=0:
                score = cumsum[left]

                if score > bestsumma:
                    bestsumma = score

print bestsumma


Measured memory_bytes: 32620
#include <bits/stdc++.h>
#define ll long long
#define sz(a) int((a).size())
#define fr(i,n) for(int i=0;i<n;i++) 
#define rf(i,n) for(int i=1;i<=n;i++) 
#define pb push_back 
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define MAX INT_MAX 
using namespace std;
#define M 1000000007
int main()
{
    int t,n;
    cin>>t>>n;
    if(t==n)
    cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


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

int main(){
    long long a,b,k;
    cin>>a>>b>>k;
    if(a>=k) a-=k;
    else{
        k-=a;
        a=0;
        if(b>=k) b-=k;
        else{
            b=0;
        }
    }
    cout<<a<<' '<<b<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 2333
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
int n, m, dp[maxn][4][2];
char c[maxn];
il int dfs(int u, int use, int li) {
	if(use > m) return 0;
	if(u > n) return use == m;
	if(dp[u][use][li] != -1) return dp[u][use][li];
	int p = li == 1 ? c[u] - '0' : 9, ans = 0;
	rep(i, 0, p) ans += dfs(u + 1, use + (i != 0), li && i == p);
	return dp[u][use][li] = ans;
} 
signed main() {
	scanf("%s", c + 1), n = strlen(c + 1), m = read(), mem(dp, -1);
	cout << dfs(1, 0, 1);
	return 0;
}


Measured memory_bytes: 384
import java.lang.IllegalArgumentException
import java.util.*

fun main(args: Array<String>) {


    var sc = Scanner(System.`in`)

    val n = sc.nextInt()
    val m = sc.nextInt()

    var cs = (0 until m).map { sc.nextInt() }

    // dp[i] i番目のコインを使って、n円払う最小の枚数
    var dp = IntArray(n+1)
    dp[0] = 0
    dp[1] = 1
    for(i in 2..n){
        dp[i] = cs.filter { it <= i }.map { dp[i-it] + 1 }.min() ?: throw IllegalArgumentException()
    }

    println(dp[n])



}




Measured memory_bytes: 62532
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define mod 1000000007

int main(){
  long long dp[16]={0},ndp[16]={0},l,i,j,k;
  char *s=malloc(sizeof(char)*131072);
  dp[0]=1;
  scanf("%s",s);
  l=strlen(s);
  for(i=0;i<l;i++){
    for(j=0;j<13;j++){
      for(k=0;k<=9;k++){
        if(s[i]=='?' || s[i]==('0'+k)){
          ndp[(j*10+k)%13]+=dp[j];
          ndp[(j*10+k)%13]%=mod;
        }
      }
    }
    for(j=0;j<13;j++){
      dp[j]=ndp[j];
      ndp[j]=0;
    }
  }
  printf("%lld\n",dp[5]);
  return 0;
}


Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<exception>
#include<stdexcept>
#include<streambuf>
#include<iterator>
#include<string.h>
#include<stdlib.h>
#include<typeinfo>
#include<valarray>
#include<iostream>
#include<sstream>
#include<istream>
#include<stdio.h>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<ctype.h>
#include<cassert>
#include<cstdlib>
#include<utility>
#include<cstring>
#include<numeric>
#include<ostream>
#include<cwctype>
#include<fstream>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cctype>
#include<string>
#include<vector>
#include<limits>
#include<locale>
#include<memory>
#include<cerrno>
#include<time.h>
#include<iosfwd>
#include<cfloat>
#include<cstdio>
#include<cwchar>
#include<cmath>
#include<ctime>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<ios>
#include<map>
#include<set>
#include<new>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define MP make_pair
using namespace std;
typedef long long ll;
const int INF=1e9+7;
int n;
ll a[105];
int main()
{
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>n;
	a[1]=2;
	a[2]=1;
	for (int i=3;i<=90;i++)
	a[i]=a[i-1]+a[i-2];
	cout<<a[n+1];
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(a); sll(b); sll(c);
	if(a == b && b == c && a > 0)	puts("Yes");
	else	puts("No");
}


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

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";


#define     SPEED     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	ll          long long int
#define 	pb          push_back
#define 	pii         pair<int,int>
#define 	vi          vector<int>
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	hell        1000000007
#define 	rep(i,n)    for(i=0;i<n;i++)
#define 	repe(i,a,b) for(i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search
#define 	mp          make_pair

ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2);
	if(b%2==0)
		return((c%hell)*(c%hell))%hell;
	return ((((c%hell)*(c%hell))%hell)*(a%hell))%hell;
}

/********************************************************/



int main()
{
	SPEED;
	ll n,k,t,c=0,i,j,m,cs=0;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>n;
		// n=s.length();
		ll a[n];
		rep(i,n)
		{
			cin>>a[i];
			c+=a[i];
			cs=max(a[i],cs);
		}
		if((2*cs<c))
			cout<<"Yes";
		else
			cout<<"No";
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
# include <climits>
#define ll long long int
#define rep(i,rept) for (ll i = 0; i < rept; i++)
using namespace std;
/*int ketawa(ll num) {
	int dig, sum = 0;
	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}
	return sum;
}
*/
int main()
{
	int n,m;
	cin >> n >> m;
	if (n + m == 15) {
		cout << "+";
	}
	else if(n*m == 15) {
		cout << "*";
	}
	else {
		cout << "x";
	}
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;
using ll = long long;
using vi = vector <int>;
inline int read() {
    int x = 0, f = 1, c = getchar();
    for (;!isdigit(c);c = getchar()) if (c == '-') f = 0;
    for (; isdigit(c);c = getchar()) x = x * 10 + c - 48;
    return f ? x : -x;
}
inline void write(int x) {
    if (x < 0) putchar('-'), x = -x;
    int stk[25], tp = 0;
    if (!x) stk[tp ++] = 0;
    for (; x; x /= 10) stk[tp ++] = x % 10;
    for (; tp; putchar(48 + stk[-- tp]));
}
char s[200005];
int main() {
    scanf("%s", s); int n = strlen(s);
    ll ans = 0;
    vi v;
    for (int i = 0; i < n; ++ i) {
        bool ok = 1;
        if (s[i] == 'A') v.pb(0);
        else if (s[i] == 'B' && s[i + 1] == 'C') v.pb(1), ++ i;
        else ok = 0;
        if (!ok || i == n - 1) {
            int cnt = 0;
            for (int j = v.size() - 1; ~j; -- j) {
                if (!v[j]) ans += cnt;
                else cnt ++;
            }
            v.clear();
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1528
#include <iostream>
#include <list>
#include <iterator>
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <set>
#include <stdio.h>
#include <cmath>
 
#define loop(i,n)   for(i=0;i<n;i++)
#define ll          long long
#define MAX         10000001
#define pi          acos(-1)

ll i,j,k,cnt,sum;
 
using namespace std;

bitset<MAX> prime;

void seive(){
	prime[0] = 1;
	prime[1] = 1;
	prime[2] = 0;

	for(i=4;i<MAX;i+=2){
		prime[i] = 1;
	}

	for(i=3;i*i<=MAX;i+=2){
		if(!prime[i]){
			for(j=i+i;j<MAX;j+=i){
				prime[j] = 1;
			}
		}
	}
}


//Code Starts Here//
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll day,n,cnt=0;
	cin>>day>>n;
	int arr[n];

	for(i=0;i<n;i++){
		cin>>arr[i];
		cnt += arr[i];
	}

	if(cnt>day){
		cout<<-1<<endl;
	}
	else{
		cout<<day - cnt<<endl;
	}


	return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>

int main(void){
   int x[5];
   scanf("%d %d %d %d %d",&x[0],&x[1],&x[2],&x[3],&x[4]);
   for(int i=0;i<5;i++){
      if(x[i]==0){
         printf("%d",i+1);
      }
   }
   return 0;
}


Measured memory_bytes: 1688
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a < b && b < c) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3092
#include <stdio.h>
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <map>
#include <vector>

using namespace std;

int main() {
    int X;
    int A;
    int B;

    int R;

    scanf("%d",&X);
    scanf("%d",&A);
    scanf("%d",&B);

    R = (X - A) - ((X - A)/B)*B;
    printf("%d\n",R);
    return 0;
}

Measured memory_bytes: 256
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)


int Len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}


int Sint(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int GCD(int a,int b)
{
  int r, tmp;
   /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}


int Factorial(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}


long long int Svec(vector<long long int> v){
  long long int n=0;
  for(long long int i=0;i<v.size();i++) n+=v[i];
  return n;
}


/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  int n,m;
  bool flag=false;
  cin>>n>>m;
  vector<pair<int,int>> v;
  set<int> st1,st2,st3;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    if(a==1 && b==n){
      cout<<"POSSIBLE"<<endl;
      return 0;
    }
    v.emplace_back(a,b);
  }
  rep(i,m){
    if(v[i].first==1){
      st1.insert(v[i].second);
    }
  }
  rep(i,m){
    if(v[i].second==n){
      st2.insert(v[i].first);
    }
  }
  set_intersection(st1.begin(),st1.end(),st2.begin(),st2.end(),inserter(st3,st3.end()));
  
  if(st3.size()>=1) flag=true;
  
  
  
  if(flag){
    cout<<"POSSIBLE"<<endl;
  }else{
    cout<<"IMPOSSIBLE"<<endl;
  }
}

Measured memory_bytes: 11248
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;
 
int32_t main(){
	IOS;
	int h,a;
	cin>>h>>a;
	int ans=0;
	if(h%a==0) ans=-1;
	ans+=(h/a)+1;
	cout<<ans<<endl; 
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for(int i = 0; i<N; i++) A[i] = sc.nextInt();
        for(int i = N-1; i>=0; i--) {
            System.out.printf("%d", A[i]);
            if(i!= 0) System.out.printf(" ");
        }
        System.out.printf("\n");
        sc.close();
    }
}


Measured memory_bytes: 26488
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
	int n = 0;
	cin >> n;
	while(n--){
		map<char, vector<int> > table;
		table['R'] = vector<int>(10, 0);
		table['G'] = vector<int>(10, 0);
		table['B'] = vector<int>(10, 0);
		vector<int> number(9, 0);
		char clist[] = {'R', 'G', 'B'};
		for(int i = 0; i < 9; i++){
			cin >> number[i];
		}
		for(int i = 0; i < 9; i++){
			char color = ' ';
			cin >> color;
			table[color][number[i]]++;
		}

		bool win = true;
		for(int i = 0; i < 3; i++){
			for(int j = 1; j <= 9; j++){
				if(table[clist[i]][j] >= 3) table[clist[i]][j] -= 3; 
			}
			for(int j = 1; j <= 7; j++){
				while(table[clist[i]][j] > 0){
					table[clist[i]][j]--;
					table[clist[i]][j+1]--;
					table[clist[i]][j+2]--;
				}
			}
			for(int j = 1; j <= 9; j++){
				if(table[clist[i]][j] != 0) win = false;
			}
		}

		cout << (win ? 1 : 0) << endl;
	}
	return 0;
}

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

int main(){
	int N; cin>>N;
	vector<int> B(N+1,INT_MAX);
	for(int i=1; i<N; ++i) cin>>B[i];
	long long ans = 0;
	for(int i=0; i<N; ++i) ans += min(B[i], B[i+1]);
	cout<< ans <<endl;
}

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

int main(void)
{
	int x,a,b;
	scanf("%d%d%d",&x,&a,&b);
		
	if((x>=1&&x<=1000)&&(a>=1&&a<=1000)&&(b>=1&&b<=1000))
	{
		if((abs(x-a))<(abs(x-b))){
				printf("A");
			}else{
				printf("B");
			}
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;

const ll siz = 4e3 + 10;
const ll SIZ = 1e6 + 10;
const ll mod = 1e9 + 7;
const ll maxx = 2e9;
const ll MAXX = 1e18;
const ll base = 31;

int n;
string s;
int cntR[siz], cntG[siz], cntB[siz];
int ans;

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    freopen ("IN_3.INP", "r", stdin);
//    freopen ("OUT_3.OUT", "w", stdout);
    cin >> n >> s;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R') cntR[i] = cntR[i - 1] + 1;
        else cntR[i] = cntR[i - 1];
        if (s[i] == 'G') cntG[i] = cntG[i - 1] + 1;
        else cntG[i] = cntG[i - 1];
        if (s[i] == 'B') cntB[i] = cntB[i - 1] + 1;
        else cntB[i] = cntB[i - 1];
    }
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
        {
            if (s[i] == s[j]) continue;
            if (s[i] == 'R')
            {
                if (s[j] == 'G')
                {
                    ans += cntB[n - 1] - cntB[j - 1];
                    int k = j * 2 - i;
                    if (k < n && s[k] == 'B') ans--;
                }
                else
                {
                    ans += cntG[n - 1] - cntG[j - 1];
                    int k = j * 2 - i;
                    if (k < n && s[k] == 'G') ans--;
                }
            }
            if (s[i] == 'G')
            {
                if (s[j] == 'R')
                {
                    ans += cntB[n - 1] - cntB[j - 1];
                    int k = j * 2 - i;
                    if (k < n && s[k] == 'B') ans--;
                }
                else
                {
                    ans += cntR[n - 1] - cntR[j - 1];
                    int k = j * 2 - i;
                    if (k < n && s[k] == 'R') ans--;
                }
            }
            if (s[i] == 'B')
            {
                if (s[j] == 'R')
                {
                    ans += cntG[n - 1] - cntG[j - 1];
                    int k = j * 2 - i;
                    if (k < n && s[k] == 'G') ans--;
                }
                else
                {
                    ans += cntR[n - 1] - cntR[j - 1];
                    int k = j * 2 - i;
                    if (k < n && s[k] == 'R') ans--;
                }
            }
        }
    cout << ans;
    return 0;
}

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

int main() {
  string S,T;
  cin >> S >> T;

  vector<int> schar(30);
  vector<int> tchar(30);

  for(char c='a';c<='z';c++) {
    for(int i=0;i<S.size();i++) {
      if(S[i]==c) schar[c-'a']++;
      if(T[i]==c) tchar[c-'a']++;
    }
  }
  bool jg=true;
  int num=0;
  for(int i=0;i<30;i++) {
    //cout << schar[i] << " ";
    num=0;
    for(int j=0;j<schar.size();j++){
      //cout << schar[j] << " ";
      if(schar[i]==tchar[j]){
        tchar[j]=0;
        num++;
        break;
      }else if(num==0 && j==schar.size()-1){
        jg=false;
      }
    }
   }
  if(jg) cout << "Yes" << endl;
  else cout << "No" << endl;
}
        




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


int main()
{

    string S;
    cin >> S;

    int diff = 1e+9;
    for( int i = 0; i <= S.size()-3; ++i )
    {
        int num = 100*(S[i]-'0') + 10*(S[i+1]-'0') + (S[i+2]-'0');
        diff = min( diff, abs(num - 753) );
    }

    cout << diff << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, s = 0; cin >> n;
    int a[n];
    for(int i = 0 ; i < n; i++)
    {
       cin >> a[i];
    }
    for(int i  = 0 ; i<n; i++)
    {
        for(int j = i+ 1; j<n ;j++)
        {
            s += (a[i]*a[j]);
        }
    }
    cout << s << '\n';
}



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

int main() {
  int N;
  cin >> N;
  set<string> s;
  for (int i = 0; i < N; i++) {
    string x;
    cin >> x;
    s.insert(x);
  }
  cout << s.size() << endl;
}

Measured memory_bytes: 19228
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    
	    Queue <Long> OVER = new LinkedList<Long>(); 
	    PriorityQueue <Long> A = new PriorityQueue<Long>(); 
	    
        for(int i = 0; i < N; i++) {
        	Long temp = sc.nextLong();
        	if (temp<=Math.pow(10, 5))
        		A.add(temp);
        	else
        		OVER.add(temp);
        }
        sc.close();
        
        if (A.isEmpty())
        	System.out.println(OVER.size());
	    
        else {
      
        long count = 0;
        int ans = 0;
        
        while (A.isEmpty()!=true){
        	count = 1;
        	long temp = A.poll();
        	
        	while (A.isEmpty()!=true && A.peek()==temp){
        		A.poll();
        		count++;
        	}
        	
        	if (temp>count)
        		ans += count; 
        	
        	else if (temp<count)
        		ans += (count-temp);
        	
        }
        System.out.println(OVER.size()+ans);
        
        }

	}

}


Measured memory_bytes: 62316
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()

cnt = Counter(S)

flg = max(cnt["a"],cnt["b"],cnt["c"]) - min(cnt["a"],cnt["b"],cnt["c"])

ans = "YES"
if flg>1:
    ans = "NO" 
    
print(ans)


Measured memory_bytes: 3444
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long 
    ll dp[101][100010];
    int main(){
        ll n,w;
        cin>>n>>w;
        ll tot=0;
       ll val[n+2],wg[n+2];
       
        for(int i=0;i<n;i++)
        {
            cin>>wg[i]>>val[i];
            tot+=val[i];
        }
        
            for(int i=0;i<=tot;i++)
            dp[0][i]=INT_MAX;
        
        for(int i=0;i<=n;i++)
        dp[i][0]=0;
        
        for(int i=1;i<=n;i++){
            
            for(int j=1;j<=tot;j++)
            {
                if(val[i-1]<=j)
                dp[i][j]=min(dp[i-1][j],dp[i-1][j-val[i-1]]+wg[i-1]);
                else
                dp[i][j]=dp[i-1][j];
            }
            
        }
        /*for(int i=0;i<=n;i++)
        {
            for(int j=0;j<=tot;j++)
            {
                cout<<dp[i][j]<<" ";
            }
            cout<<endl;
        }
       */
            for(int i=tot;i>=0;i--)
            {
                if(dp[n][i]<=w)
               {
                   cout<<i<<endl;
                   break;
               }
            }
        
    }

Measured memory_bytes: 79104
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int bfs(PII begin, PII end, vector<string> grid, bool arv[]){
  int H = grid.size();
  int W = grid[0].size();
  queue<PII> q1,q2;
  q1.push(begin);
  int ans = 1;
  while(1){
    if(q1.empty()){
      q1 = q2;
      while(!q2.empty()) q2.pop();
      ans++;
    }else{
      PII point = q1.front();
      q1.pop();
      REP(i,4){
        int x = point.first + dx[i];
        int y = point.second + dy[i];
        if(PII(x,y)==end){
          return ans;
        }
        if(0<=x&&x<W&&0<=y&&y<H&&grid[y][x]!='X'&&arv[y*W+x]==false){
          q2.push(PII(x,y));
          arv[y*W+x] = true;
        }
      }
    }
  }
}
    


int main(void){
  int H,W,N;
  cin>>H>>W>>N;
  vector<string> grid(H);
  PII start;
  vector<PII> cheese(N+1);
  REP(i,H) cin>>grid[i];
  REP(y,H)REP(x,W){
    if(grid[y][x]=='S') cheese[0] = PII(x,y);
    if('0'<=grid[y][x]&&grid[y][x]<='9') cheese[ grid[y][x] - '0'] = PII(x,y);
  }
  int ans = 0;
  bool arv[1000000];
  REP(i,N){
    memset(arv,0,sizeof(arv));
    ans += bfs(cheese[i],cheese[i+1],grid,arv);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3904
from math import sqrt
n = int(raw_input())
coords = [map(int, raw_input().split()) for i in range(n)]
dist = 0
for i in range(n):
    for j in range(i+1, n):
        if i != j:
            dist += sqrt((coords[i][0]-coords[j][0])**2 + (coords[i][1] - coords[j][1])**2)

def factorial(n):
    res = n
    for i in range(1, n):
        res *= i
    return res
            
print dist * 2 / n

Measured memory_bytes: 2692
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;

public class Main{
	public static void main(String[] args){
      
      	String[] input1;
      	String[] input2;
        
      	try (Scanner sc = new Scanner(System.in)) {
          input1 = sc.nextLine().split(" "); // nextLine:enterまで取得
          input2 = sc.nextLine().split(" ");
        }
      	
      	int n = Integer.parseInt(input1[0]);
        int x = Integer.parseInt(input1[1]);
      
      	List<Integer> list = new ArrayList<>();
      	for (String str : input2) {
         	list.add(Integer.parseInt(str));
        }
		
      	int d = 0;
      	int cnt = 1;
        for (int i = 0; i < list.size(); i++){
        	int e = d + list.get(i);
          
          	if (e <= x) {
              cnt ++;
            }  
          	d = e;
        }
      System.out.println(cnt);
	}
}


Measured memory_bytes: 22868
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.replace(/\n$/,"")).split("\n");
var n=Arr.shift();
for(var i=0;i<n;i++){
   var str=Arr[i];
   var strA=str.replace(/\>\'(\=+)\#(\=+)\~/,function(s,s1,s2){
      if(s1==s2)s=s.replace(/\=+/g,"=");
      return s;
   });
   var strB=str.replace(/\>\^(Q=)+~~/,function(s){
      return ">^Q=~~";
   });
   if(strA==">'=#=~"){console.log("A");continue;}
   if(strB==">^Q=~~"){console.log("B");continue;}
   console.log("NA");
}

Measured memory_bytes: 10800
a=input("")
if(a=="SUN"):
  print(7)
elif(a=="MON"):
  print(6)
elif(a=="TUE"):
  print(5)
elif(a=="WED"):
  print(4)
elif(a=="THU"):
  print(3)
elif(a=="FRI"):
  print(2)
else:
  print(1)

Measured memory_bytes: 9056
#学習用
def root(x):
    # xが根であれば
    if x == p[x]:
        # xを返す
        return x
    # xが根でなければp[x]の根をp[x]に設定する
    p[x] = y = root(p[x])
    # p[x]の根を返却する
    return y
def unite(x, y):
    # xとyの根を取得する
    px = root(x); py = root(y)
    # xとyの根が同じならば
    if px == py:
        # 根が同じならば、0を返す
        return 0
    # yの根がxの根より大きければ、
    if px < py:
        # yの根の位置のp[]を、xの根にする
        p[py] = px
        # xの根の位置のサイズszを、yの根の位置のサイズだけ加算する
        sz[px] += sz[py]
    else:
    # yの根がxの根より小さければ
        # xの根の位置のp[]を、yの根を指すようにする
        p[px] = py
        sz[py] += sz[px]
    # 根が異なっていた＝結合した場合は、1を返却する
    return 1

N , M = map(int, input().split())
*p , = range(N)
sz = [1] * N
E = []
for i in range(M):
    a , b = map(int, input().split())
    E.append((a-1, b-1))

ans = [None] * M
E.reverse()
res = 0
ans[-1] = "%d\n" % (N*(N-1)//2)

for i , (a,b) in enumerate(E[:-1]):
    sa = sz[root(a)]; sb = sz[root(b)]
    if unite(a , b):
        sc = sz[root(a)]
        res += sc*(sc-1)//2 - sa*(sa-1)//2 - sb*(sb-1)//2
    ans[-2-i] = "%d\n" % (N*(N-1)//2 -res)
open(1, 'w').writelines(ans)    

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

int main(void){
    int a,b[3];
    cin >> a;
    b[0] = a / 100;
    b[1] = (a - (b[0] * 100)) / 10;
    b[2] = a - (b[0]*100) - (b[1]*10);
    for(int i = 0;i < 3;i++){
        if(b[i] == 1) cout << 9;
        else cout << 1;
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
  int a,b,c,d;
  cin >> a;
  cin >>b;
  cin >>c;
  cin >>d;
  
  if(a>b)a=b;
  if(c>d)c=d;
  
  cout << a+c <<endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n, max_profit = (1 - 1000000000), min;
	cin >> n;
	cin >> min;
	for(int i = 1; i < n; i++){
		int x;
		cin >> x;
		if(max_profit < x - min) max_profit = x - min;
		if(min > x) min = x;
	}
	cout << max_profit << endl;

	return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <iomanip>
#include <string>
using std::cin;
using std::cout;
using std::endl;

int main()
{
    std::string S;
    int midLength, result = 0;

    cin >> S;
    midLength = (int)S.length() / 2;
    for (int i = 0; i < midLength; i++)
    {
        if (S[i] != S[S.length() - i - 1])
            result++;
    }
    cout << result << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000LL;
constexpr auto MOD = 1000000007;

int main() {

	int n, a, b, c;
	cin >> n >> a >> b >> c;
	string select = "";
	rep(i, n) {
		string s;
		cin >> s;
		if (s == "AB")select.push_back('0');
		if (s == "AC")select.push_back('1');
		if (s == "BC")select.push_back('2');
	}

	string ans = "";
	rep(i, n) {
		int s = select[i] - '0';
		if (s == 0) {
			bool a_plus = 0;
			if (a < b)a_plus=true;
			if (a == b && i < n - 1)if (select[i + 1] == '1')a_plus = true;
			if (a_plus) {
				a++;
				b--;
				ans.push_back('A');
			}
			else {
				a--;
				b++;
				ans.push_back('B');
			}
		}
		if (s == 1) {
			bool a_plus = 0;
			if (a < c)a_plus = true;
			if (a == c && i < n - 1)if (select[i + 1] == '0')a_plus = true;
			if (a_plus) {
				a++;
				c--;
				ans.push_back('A');
			}
			else {
				a--;
				c++;
				ans.push_back('C');
			}	
		}
		if (s == 2) {
			bool b_plus = 0;
			if (b < c)b_plus = true;
			if (b == c && i < n - 1)if (select[i + 1] == '0')b_plus = true;
			if (b_plus) {
				b++;
				c--;
				ans.push_back('B');
			}
			else {
				b--;
				c++;
				ans.push_back('C');
			}
		}
		if (a < 0 || b < 0 || c < 0) {
			cout << "No" << endl;
			return 0;
		}
	}

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

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

using namespace std;

typedef long long ll;

const ll mod = 998244353;
map<string, ll> ans;

ll Solve(string s) {
  if (s == "") return 1;
  if (ans.count(s)) return ans[s];
  ans[s] = Solve(s.substr(1));
  if (s[0] == '1') {
    ans[s] = ans[s] * 2 % mod;
  }

  for (int t = 1; t < s.size(); ++t) {
    for (int k = 2; k * t <= s.size(); ++k) {
      string ss(t, '1');
      for (int i = 0; i < t * k; ++i) {
        if (s[i] == '0') ss[i % t] = '0';
      }
      ans[s] += Solve(ss) * Solve(s.substr(t * k));
      ans[s] %= mod;
    }
  }

  return ans[s];
}

int main()
{
  string s;
  cin >> s;
  cout << Solve(s) << endl;
  return 0;
}


Measured memory_bytes: 5632
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

#define MAX_N 1000000007
#define INF 100000000000000

int main(){
  long long n,ans;
  cin >> n;
  ans = 2*n;
  for(long long i=1000000;i>=1;i--){
    if(n%i == 0){
      ans = min(ans,i+n/i-2);
    }
  }
  cout << ans <<endl;

  return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
	while(true){
		int n, m;
		cin >> n >> m;
		if(n == 0 && m == 0){ break; }
		vector<int> h(n), w(m);
		for(int i = 0; i < n; ++i){ cin >> h[i]; }
		for(int j = 0; j < m; ++j){ cin >> w[j]; }
		map<int, int> mp;
		for(int i = 0; i < n; ++i){
			int sum = 0;
			for(int j = i; j < n; ++j){
				sum += h[j];
				++mp[sum];
			}
		}
		ll answer = 0;
		for(int i = 0; i < m; ++i){
			int sum = 0;
			for(int j = i; j < m; ++j){
				sum += w[j];
				answer += mp[sum];
			}
		}
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 19040
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//??°?????????
		while(true){
			//??????????¨?????????° m
			int m = sc.nextInt();
			//??????????¨?????????° f
			int f = sc.nextInt();
			//???????¨?????????° r
			int r = sc.nextInt();
			//????¨??????????????±?????????´??? m f r ???-1????????????
			if(m == -1 && f == -1 && r == -1){
				break;
			}
			//????¨????
			int sum = m + f;
			//??????????????¶???
			//??????????¨? m ??¨??????????¨? f ???????????????????¬????????????´????????????F
			if(m == -1 || f == -1){
				System.out.println("F");
			//??????????¨? m ??¨??????????¨? f ???????¨????80?????\???????????°?????????A
			}else if(sum >= 80){
				System.out.println("A");
			//??????????¨? m ??¨??????????¨? f ???????¨????65?????\???80?????????????????°?????????B
			}else if( 80 > sum  && sum >= 65){
				System.out.println("B");
			//??????????¨? m ??¨??????????¨? f ???????¨????50?????\???65?????????????????°?????????C
			}else if(sum >= 50 && 65 > sum){
				System.out.println("C");
			//??????????¨? m ??¨??????????¨? f ???????¨????30?????\???50?????????????????°?????????D
			}else if(sum>= 30 && 50 > sum){

				//???????¨? r ????????????50?????\???????????°?????????C
				if(r >= 50){
					System.out.println("C");
				//???????¨? r ????????????50?????????????????°?????????D
				}else{
					System.out.println("D");
				}
			//??????????¨? m ??¨??????????¨? f ???????¨????30?????????????????°?????????F
			}else if(sum < 30){
				System.out.println("F");
			}
		}
	}
}

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

int main(){
  int N;
  string A, B, C;
  cin >> N >> A >> B >> C;
  vector<int> match(N);
  for(int i=0; i<N; i++){
    if(A.at(i)!=B.at(i)) match.at(i)++;
    if(B.at(i)!=C.at(i)) match.at(i)++;
    if(C.at(i)!=A.at(i)) match.at(i)++;
    if(match.at(i)>=2) match.at(i)--;
  }
  int ans=0;
  for(int i=0; i<N; i++) ans+=match.at(i);
  cout << ans << endl;
}

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

int main() {
	long long x,y,c;
	cin>>x>>y;
	c=abs(abs(x)-abs(y));
	if(x*y<0){
	    c++;
	}else if(x>y){
	    c+=2;
	    if(x*y==0)c--;
	}
	cout<<c<<endl;
	return 0;
}

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

using namespace std;

int a[200'009];

int main() {
  int n;
  scanf("%d", &n);
  int mx[3] = {0, 0, 0};
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    a[i] = -a[i];
    mx[2] = a[i];
    sort(mx, mx + 3);
  }
  for (int i = 0; i < n; ++i) {
    printf("%d\n", a[i] != mx[0] ? -mx[0] : -mx[1]);
  }
}


Measured memory_bytes: 2304