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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

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

void Main() {
    i32 N;
    string S;
    cin >> N >> S;
    i32 sum = 0;
    char current = ' ';
    for (i32 i = 0; i < N; i++) {
        if(current == S[i]) continue;
        sum++;
        current = S[i];
    }
    cout << sum << endl;

}


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

using namespace std;

char a[52],b[52];

int main()
{
    cin>>a;
    cin>>b;
    int la=strlen(a);
	int lb=strlen(b);
    int l=min(la,lb);
	int ll=ll=max(la,lb);
    for(int i=0;i<=l-1;i++)
        cout<<a[i]<<b[i];
    if(la>lb)
        for(int i=l;i<=ll-1;i++)
            cout<<a[i];
    else 
		for(int i=l;i<=ll-1;i++)
            cout<<b[i];
    cout<<endl;
    return 0;
}

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

int main() {
    string str;
    cin >> str;

    for (int bit = 0; bit < (1<<3); bit++) {
        string ans = "";
        ans += str[0];
        int sum = str[0] - '0';
        for (int i = 0; i < 3; i++) {
            if (bit & (1<<i)) {
                sum += str[i + 1] - '0';
                ans += "+";
                ans += str[i + 1];
            } else {
                sum -= str[i + 1] - '0';
                ans += "-";
                ans +=str[i + 1];
            }
        }
        if (sum == 7) {
            ans += "=7";
            cout << ans << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string a;
	string b;
	cin>>a;
	cin>>b;
	int n;
	n=a.size();
	int count=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]==b[i])
		{
			continue;
		}
		else{
			count+=1;
		}
	}
	cout<<count<<endl;

}

Measured memory_bytes: 3924
#include<stdio.h>
#include<ctype.h>
#include<vector>
#include<map>
typedef std::map<int,int>M;
typedef M::iterator I;
typedef std::pair<int,int>P;
std::vector<P>v;
int x[10];
int F(char*&p,int n)
{
	if(isdigit(*p))
		return -*p+'0';
	v.push_back(P(0,0));
	int r=F(++p,v.size());
	v[n].first=r;
	r=F(p+=2,v.size());
	v[n].second=r;
	++p;
	return n;
}
M G(int i)
{
	M m;
	if(i<0)m[x[-i]]=1;
	else
	{
		M a(G(v[i].first)),b(G(v[i].second));
		for(I p=a.begin();p!=a.end();++p)for(I q=b.begin();q!=b.end();++q)
		{
			int a=p->first,b=q->first,c=p->second*q->second;
			m[a&b]+=c;
			m[a|b]+=c;
			m[a^b]+=c;
		}
	}
	return m;
}
int main()
{
	int n,i,j,t;
	char*p,s[512];
	while(fgets(s,512,stdin),*s-'E')
	{
		v.clear();
		scanf("%d",&n);
		for(i=1;i<=n;++i)for(x[i]=j=0;j<4;++j)scanf("%d",&t),x[i]=x[i]*2+t;
		t=F(p=s,0);
		printf("%d\n",t?x[-t]==15:G(0)[15]);
		fgets(s,512,stdin);
	}
	return 0;
}

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

signed main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    double a,b,x;
    cin >> a >> b >> x;
    double t;

    if(x < a * a * b / 2){
        t = x / a / b / b * 2;
    }else{
        x = a * a * b - x;
        double s = x / a / a * 2;
        t = a / s;
    }

    double ans = atan(1/t);
    ans *= 180;
    ans /= 3.14159265358979;
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
int fg(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
signed main(){
 int k;
 int a,b;
 cin>>k>>a>>b;
 for(int i=a;i<=b;i++){
   if(i%k==0){
    cout<<"OK";
     break;
   }
   else if(i==b){
    cout<<"NG";
   }
  else{
    continue;
  }
 }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    ll N, M;
    cin >> N >> M;

    ll MOD = 1000000007;

    vector<ll> A(N+2, 1); // 1 --> safe, 0 --> break
    for (int i = 0; i < M; i++) {
        int k;
        cin >> k;
        A[k] = 0;
    }

    vector<ll> stair(N+2, 0);
    stair[N] = 1;
    stair[N-1] = 1;

    for (int i = N-2; i >= 0; i--) {
        ll tmp = 0;
        if (A[i+1] == 1) {
            tmp += stair[i+1];
        }
        if (A[i+2] == 1) {
            tmp += stair[i+2];
        }
        stair[i] = tmp % MOD;
    }

    cout << stair[0] << endl;
    // for (int i = 0; i < N; i++) {
    //     cout << stair[i] << endl;
    // }






    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int X, Y, Z;
	cin >>X >>Y >>Z;
	cout <<Z <<' ' <<X <<' ' <<Y <<endl;
	return 0;
}



Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

int n, t;
int cc, tt;
int ans = INF<int>();

int main() {
	cin >> n >> t;
	REP(i, n) {
		cin >> cc >> tt;
		if (tt <= t)ans = min(ans, cc);
	}
	if (ans == INF<int>()) {
		cout << "TLE" << endl;
	}
	else {
		cout << ans << endl;
	}
}

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

int main(){
  int i,j,k=0;
  
  char N[256];
  
  scanf("%s",N);
  
  for(i=0;i<strlen(N);i++){
    k += (N[i] - '0');
  }
  
  j = atoi(N);
  
  if(j%k == 0)
    puts("Yes");
  
  else
    puts("No");
  
  return 0;
}
  
  


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<(max({a,b,c})*3-a-b-c)/2+(max({a,b,c})*3-a-b-c)%2*2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int n,a[101],i,j,k;
int main(void){
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]%2==0){
            k++;
            if((a[i]%5==0)||(a[i]%3==0)){
                j++;
            }
        }
    }
    if(j==k){
        printf("APPROVED\n");
        return 0;
    }else{
        printf("DENIED\n");
        return 0;
    }
}

Measured memory_bytes: 128
# coding: utf-8


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted(A, reverse=True)

    ans = A[0]
    rest = N-2
    i = 1
    while rest > 0:
        if i == len(A):
            break

        if rest >= 2:
            ans += 2 * A[i]
            rest -= 2
        else:
            ans += A[i]
            rest -= 1
        i += 1

    return ans


print(main())


Measured memory_bytes: 31680
a,b,c = map(int, input().split()) 

if(a>=b):
    min = b
else:
    min = a


list = []

for i in range(1,min+1):
    if(a%i == 0 and b%i ==0):
        list.append(i)
list.reverse()

print(list[c-1])

Measured memory_bytes: 3060
N = int(input())
S_s = [input() for _ in range(N)]
S_data1 = []
S_data2 = []
for S in S_s:
    life = 0
    A=0
    for c in S:
        if c == '(':
            life += 1
        else:
            if life > 0:
                life -= 1
            else:
                A += 1
    if(A<life):
        S_data1.append(tuple([A,life]))
    else:
        S_data2.append(tuple([A,life]))
S_data1.sort()
S_data2 = sorted(S_data2, key=lambda x:-x[1])
S_data1.extend(S_data2)
S_data = tuple(S_data1)
life = 0
answer = True
for S_datum in S_data:
    life -= S_datum[0]
    if life < 0:
        answer = False
        break
    life += S_datum[1]
else:
    if life != 0:
        answer = False

if answer:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 267032
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = Integer.parseInt(sc.next());
    int s = Integer.parseInt(sc.next());
    int count = 0;
    for(int i = 0; i <= k; i++) {
      for(int j = 0; j <= k; j++) {
        if(s - i - j >= 0 && s - i - j <= k) count++;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
 
 
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-8;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

// ここから編集
template<typename T = int> struct BIT{
  vector<T> node;

  int N;
  BIT(int n){
    N = n;
    node.resize(N+1);
  }

  void add(int i, T x){
    i++;
    while(i <= N){
      node[i] += x;
      i += (i & -i);
    }
  }

  T sum(int i){
    T res = 0;
    while(i > 0){
      res += node[i];
      i -= (i & -i);
    }
    return res;
  }

  

};

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

    int N; cin >> N;
    vector<ll> a(N);
    ll xr = 0;
    REP(i,N)cin >> a[i], xr^=a[i];

    REP(i,N){
      if(i) cout << " ";
      cout << (xr^a[i]);
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4740
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * Convenient Location
 */
public class Main {

	static final int MAX_LOC = 10;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			//init
			long[][] g = new long[MAX_LOC][MAX_LOC];
			int N = 0;

			for (int i = 0; i < g.length; i++) {
				for (int j = 0; j < g[i].length; j++) {
					if (i != j) g[i][j] = Integer.MAX_VALUE;
				}
			}
			for (int i = 0; i < n; i++) {
				words = br.readLine().split(" ");
				int x, y, d;
				x = parseInt(words[0]);
				y = parseInt(words[1]);
				d = parseInt(words[2]);
				N = Math.max(N, Math.max(x, y));
				g[y][x] = g[x][y] = d;
			}

			//solve
			for (int k = 0; k <= N; k++) {
				for (int i = 0; i <= N; i++) {
					for (int j = 0; j <= N; j++) {
						g[i][j] = Math.min(g[i][j], g[i][k] + g[k][j]);
					}
				}
			}

			int pos = Integer.MAX_VALUE;
			int min = Integer.MAX_VALUE;
			for (int i = 0; i <= N; i++) {
				int tmp = 0;
				for (int j = 0; j <= N; j++) {
					tmp += g[i][j];
				}
				if (tmp < min) {
					pos = i;
					min = tmp;
				}
			}

			System.out.println(pos + " " + min);

		}//end while
	}// end main
}

Measured memory_bytes: 24044
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846

int n, m, a, b, B, w, x[100005], c[16], ans, p3[20];
int dp[15000000], y[15000000], z[15000000];
bool f[15000000]={1};
vector<int> r;
int main(){
    p3[0]=1; fox1(l, 18) p3[l]=p3[l-1]*3;
    scanf("%i", &n); ans=n;
    fox(l, n-1){
        scanf("%i%i%i", &a, &b, &w);
        x[a]^=w;
        x[b]^=w;
    }
    fox(l, n){
        c[x[l]]++;
        //cout << x[l] << ' ';
    }
    ans-=c[0];
    fox1(l, 15){
        ans-=c[l]/2;
        c[l]%=2;
        if (c[l]) r.pb(l);
    }
    if (r.size()){
        fox(l, p3[m]) dp[l]=-(1<<30);
        dp[0]=0;
        m=r.size();
        fox(l, p3[m]){
            if (dp[l]<0) continue;
            fox(l2, m){
                if (l/p3[l2]%3==0){
                    dp[l+p3[l2]]=max(dp[l+p3[l2]], dp[l]);
                    y[l+p3[l2]]=y[l]^r[l2];
                    z[l+p3[l2]]=z[l]+p3[l2];
                }
            }
            if (y[l]==0 && !f[l]){
                //cout << "*";
                dp[l+z[l]]=max(dp[l+z[l]], dp[l]+1);
                y[l+z[l]]=0;
                z[l+z[l]]=0;
                f[l+z[l]]=1;
            }
            //cout << l << ' ' << dp[l] << endl;
        }
        ans-=dp[p3[m]-1];
    }
    cout << ans;
    return 0;
}


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

k = []
s = []
for i in range(M):
    ks = list(map(int, input().split()))
    k.append(ks[0])
    s.append(ks[1:])

p = list(map(int, input().split()))

switch = [0]*N

res = 0
for i in range(1<<N):
    div = i
    for j in range(N):
        switch[j] = div % 2
        div //= 2

    on = True
    for l in range(M):
        s_state = 0
        for s_check in s[l]:
            s_state ^= switch[s_check-1]
        if s_state != p[l]:
            on = False
    
    if on:
        res += 1

print(res)

Measured memory_bytes: 73916
package main

import "fmt"

func main() {
	var a, b, c, d, e, k int
	fmt.Scan(&a, &b, &c, &d, &e, &k)
	if (e - a) <= k {
		fmt.Println("Yay!")
	} else {
		fmt.Println(":(")
	}
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  rep (i, 2) {
    if (a > b) {
      ans += a;
      a--;
    }
    else {
      ans += b;
      b--;
    }
  }
  cout << ans << endl;
}


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

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//-----------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vector<vector<ll>> a(N, vector<ll>(3));
    rep(i, N) cin >> a[i][0] >> a[i][1] >> a[i][2];
    vector<vector<ll>> dp(N + 1, vector<ll>(3));
    rep(i, N) {
        rep(j, 3) dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + a[i][j];
    }
    cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;
    return 0;
}

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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}
ll mod = 1000000000+7;
ll n,m;
vector<ll> x,y;
ll x_l[100000];
ll y_l[100000];
/*
1番目のものにはn個入る
2番目のものにはn-1+n-1個入る
k番目のものには
a[k-1]-1+k-1個入る
*/
ll sum = 0;

int main(){
  scanf("%lld %lld",&n,&m);
  REP(i,n){
    ll a;
    scanf("%lld",&a);
    x.push_back(a);
  }
  REP(i,m){
    ll a;
    scanf("%lld",&a);
    y.push_back(a);
  }
  REP(k,n){
    sum += x[k]*(k-(n-k-1));
    sum %= mod;
  }
  ll ysum = 0;
  REP(k,m){
    ysum += y[k]*(k-(m-k-1));
    ysum %= mod;
  }
  printf("%lld\n",(sum*ysum) % mod);
}


Measured memory_bytes: 2548
#縦H A

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = (10**5)*2
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
H,W,A,B=map(int,input().split())
ans=0
for i in range(H-A):
  ans+=cmb(B+i-1,B-1,mod) * cmb(H-i+W-B-2,W-B-1,mod)
print(ans%mod)
# 1 1 1
# $ 1 2

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    map<string, int> ulaz;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        ulaz[s] += 1;
    }
    int maxValue = 0;
    for (map<string, int>::iterator it = ulaz.begin(); it != ulaz.end(); it++)
    {
        if (maxValue < it -> second)
        {
            maxValue = it -> second;
        }
    }

    for (map<string, int>::iterator it = ulaz.begin(); it != ulaz.end(); it++)
    {
        if (it -> second == maxValue)
        {
            cout << it -> first << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 25216
import java.io.*;
import java.util.Scanner;

public class Main {
  
  public static void main(String[] args){
    
    try {
      //ローカル変数定義
      int internal_rating;      //内部レーティング
      int display_rating;       //表示レーティング
      int participation_times;  //参加回数
      
      //標準入力受け取り
      Scanner scan = new Scanner(System.in);
      String  N    = scan.next();
      String  R    = scan.next();
      
      participation_times = Integer.parseInt(N);
      display_rating      = Integer.parseInt(R);
      
      //内部レーティング算出
      if (participation_times >= 10) {
        internal_rating = display_rating;
      } else {
        internal_rating = display_rating + 100*(10-participation_times);
      }
      
      System.out.println(internal_rating);
      
    } catch (Exception e) {
      
      System.out.println("error");

    }
  }
}


Measured memory_bytes: 21972
s = input()
t = input()
c = [[] for _ in range(26)]
total = 0
for i in range(len(s)):
    c[ord(s[i])-ord('a')].append(i)
idex = 0
run = -1
while(idex<len(t)):
    need = ord(t[idex])-ord('a')
    if len(c[need])==0:
        print(-1)
        exit()
    else:
        l = 0
        r = len(c[need])-1
        while(l<r):
            next = (l+r)//2
            if (c[need][next]> run):
                r=next
            else:
                l=next+1
        if c[need][r]>run:
            total+= c[need][r]-run
            run = c[need][r]

        else:
            total+=len(s)-1-run
            total+=c[need][0]+1
            run=c[need][0]
    idex+=1
print(total)

Measured memory_bytes: 7540
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int N, M, K;
int a[200005], b[200005];
ll tota[200005], totb[200005]; 

int main() {
    cin >> N >> M >> K;
    rep(i,N) cin >> a[i];
    rep(i,M) cin >> b[i];
    rep(i,N) {
        tota[i+1] = tota[i] + a[i];
    }
    rep(i,M) {
        totb[i+1] = totb[i] + b[i];
    }
    int res = 0;
    int nj = M;
    rep(ni, N+1) {
        while(nj >= 0 && totb[nj]  + tota[ni] > K) nj--;
        if(0 <= nj) chmax(res, ni + nj);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 8300
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

// ---- ----

int main() {
	LL n, x, d;
	cin >> n >> x >> d;
	
	if(d == 0) { cout << (x == 0 ? 1 : n + 1) << endl; return 0; }
	
	if(d <  0) { x *= -1; d *= -1; }
	
	auto sumID = [](LL l, LL r) { return (r - l) * (l + r - 1) / 2; };
	
	map<LL, multiset<pair<LL, int>>> mp;
	incII(c, 0, n) {
		LL m = mo(c * x, d);
		LL l = c * x + d * (sumID(0, 0 + c) + 0);
		LL r = c * x + d * (sumID(n - c, n) + 1);
		mp[m].emplace(l, 0);
		mp[m].emplace(r, 1);
	}
	
	LL ans = 0;
	RF(ms, mp) {
		stack<LL> st;
		RF(p, ms.SE) {
			if(p.SE == 0) { st.push(p.FI); }
			if(p.SE == 1) {
				LL l = st.top(); st.pop();
				if(st.empty()) { ans += fl(p.FI - l, d); }
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 44032
import bisect
from collections import deque
import math
n, d, A = map(int, input().split())
xh = []
for _ in range(n):
    x, h = map(int, input().split())
    xh.append([x, h])
xh.sort(key=lambda x: x[0])

monster_x = []
monster_hp = []
for i in range(n):
    monster_x.append(xh[i][0])
    monster_hp.append(xh[i][1])

dist = 2 * d
ans = 0
damage = 0
cum_damage = [0] * (n + 1)
for i in range(n):
    cum_damage[i + 1] += cum_damage[i]
    damage = cum_damage[i + 1] * A
    if damage < monster_hp[i]:
        min_attack_num = math.ceil((monster_hp[i] - damage) / A) 
        index = bisect.bisect_right(monster_x, monster_x[i] + dist)
        cum_damage[i + 1] += min_attack_num
        if index < n:
            t = min(index + 1, n)
            cum_damage[t] -= min_attack_num
        ans += min_attack_num

print(ans)


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;
//#define DEBUG(x) ;

vector<long long> toDivisor(ll num)
{
	vector<long long> d;
	for (ll i = 1; i*i <= num; ++i)
	{
		if (i*i == num)
		{
			d.push_back(i);
		}
		else if (num % i == 0)
		{
			d.push_back(i);
			d.push_back(num/i);
		}
	}
	return d;
}

vector<pair<long long , long long>> toDivisorP(ll num)
{
	vector<pair<long long, long long>> d;
	for (ll i = 1; i * i <= num; ++i)
	{
		if (i*i == num) d.push_back(pair<ll, ll>(i, i));
		else if (num % i == 0)
		{
			d.push_back(pair<ll, ll>(i, num/i));
		}
	}
	return d;
}


int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll N; cin >> N;

	vector<ll> divi1 = toDivisor(N-1);
	vector<ll> divi2 = toDivisor(N);

	ll res{divi1.size()-1};
	for (auto k : divi2)
	{
		if (k == 1) continue;
		ll nc = N;
		while (nc % k == 0)
		{
			nc /= k;
		}
		if (nc % k == 1) ++res;
	}
	std::cout << res << std::endl;
	
	return 0;
}


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

using namespace std;

#define Rep(i,a,b)  for (int i=(a);i<(b);i++)
#define rep(i,n)    for (int i=0;i<(n);i++)
#define all(x)      (x).begin(), (x).end()

#define ll long long

int main()
{
	int n;
	string s;
	cin >> n;
	cin >> s;
	int w = count(all(s), '.');
	int b = w;
	rep (i, n) {
		if (s[i] == '#')
			w++;
		else
			w--;
		if (b > w)
			b = w;
	}
	cout << b << endl;
}



Measured memory_bytes: 640
from collections import Counter
N = int(input())
S = [i for i in input()]
count = 0
s = Counter(S)
for i in range(N):
    for j in range(i,N):
        if (i+j)%2==0 and S[(i+j)//2]!=S[i] and S[i]!=S[j] and S[(i+j)//2]!=S[j]:
            count += 1

print((s['R'] * s['B'] * s['G'])-count)

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





int main() {
  int g;
cin>>g;
  vector<string>op(g);
  for(int i=0;i<g;i++)
  {
  string y;
    cin>>y;
    op.at(i)=y;
    }

sort(op.begin(), op.end());
int a=1;
  int b=1;
  for(int i=0;i<g-1;i++)
  {
  
  if(op.at(i)==op.at(i+1))  b=b+1;
    else b=1;
     a=max(a,b) ;
  }
  int c=1;  
 if(a!=1)
 {
  for(int i=0;i<g-1;i++)
  {
  
  
  if(op.at(i)==op.at(i+1))  c=c+1;
    else c=1;
  
  if(a==c) cout<<op.at(i)<<endl;
  }
}
  else if(a==1)
  {
  for(int i=0;i<g;i++)
  {
  cout<<op.at(i)<<endl;
  }
  }
}






Measured memory_bytes: 15232
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define N 300020
#define MOD 1000000007
using namespace std;

char a[N];
int f[N][3][3];

inline int Mod(int x)
{
    return x + ((x >> 31) & MOD);
}

inline void Modadd(int &x, int y)
{
    x = Mod(x + y - MOD);

    return;
}

int main(void)
{
    int n;
    int i, j, k;

    scanf("%s", a);
    n = (int)strlen(a);

    f[0][0][0] = 1;
    for(i = 0; i < n; i ++)
        for(j = 0; j < 3; j ++)
            for(k = 0; k < 3; k ++)
                if(f[i][j][k])
                {
                    if(a[i] != '1')
                    {
                        if(j == 2)
                            Modadd(f[i + 1][1][k], f[i][j][k]);
                        else
                            Modadd(f[i + 1][j + 1][k], f[i][j][k]);
                    }
                    if(a[i] != '0')
                    {
                        if(j)
                            Modadd(f[i + 1][j - 1][k], f[i][j][k]);
                        else
                            Modadd(f[i + 1][0][min(k + 1, 2)], f[i][j][k]);
                    }
                }
    k = 0;
    Modadd(k, f[n][0][0]);
    Modadd(k, f[n][0][1]);
    Modadd(k, f[n][0][2]);
    Modadd(k, f[n][1][1]);
    Modadd(k, f[n][1][2]);
    Modadd(k, f[n][2][2]);
    printf("%d\n", k);

    return 0;
}


Measured memory_bytes: 11136
import numpy as np

MOD = 10**9+7

N,M = map(int,input().split())

An = np.zeros(N+1,dtype=int)
An[0] = 1

for _ in range(M):
    m = int(input())
    An[m] = -1

# 1段目だけは特別に
if An[1] == -1:
    An[1] = 0
else:
    An[1] = 1

for i in range(2,N+1):
    if An[i] == -1:
        An[i] = 0
        continue

    An[i] = (An[i-1] + An[i-2]) % MOD

print(An[N])

Measured memory_bytes: 13236
#include<stdio.h>

int main(void){
        int x,y;
        while(1){
                scanf("%d %d",&x,&y);
                if(x == 0 && y == 0)
                        break;
                else if(x>y)
                        printf("%d %d\n",y,x);
                else
                        printf("%d %d\n",x,y);
        }
        return 0;
}

Measured memory_bytes: 600
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if i == 0 or i == H - 1:
                print('#', end='')
            elif j == 0 or j == W -1:
                print('#', end='')
            else:
                print('.', end='')
        print()
    print()


Measured memory_bytes: 7000
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int k, n;
	cin >> k >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int m = k + a[0] - a[n - 1];
	for (int j = 1; j < n; j++) {
		m = max(m, a[j] - a[j - 1]);
	}
	cout << (k - m) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{
 	int a,b,c;
 	cin>>a>>b>>c;
 	if(a==5&&b==5&&c==7)
	 {
		cout<<"YES"<<endl;
     }
    else if
	(a==5&&c==5&&b==7)
	{
	cout<<"YES"<<endl;
    }
	else if
	(a==7&&b==5&&c==5)
    { 
	cout<<"YES"<<endl;
	}
	else 
	cout<<"NO"<<endl; 
 	return 0;
}

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

int main() {
	int R;
	cin >> R;
	if (R < 1200)cout << "ABC";
	if (R >= 1200 && R < 2800)cout << "ARC";
	if (R >= 2800)cout << "AGC";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	int x = scan.nextInt();
    	int h,m,s;
    	h = x / (60*60);
    	m = (x-h*60*60)/60;
    	s = x-h*60*60-m*60;
        System.out.println(h+":"+m+":"+s);
    }
}

Measured memory_bytes: 26100
from collections import *

N = int(input())
D = list(map(int, input().split()))
cnt = Counter(D)
l = []
T = [0]

for k, v in cnt.items():
    if v>=3:
        print(0)
        exit()
    
    if v==1:
        l.append(k)
    else:
        T.append(k)
        T.append(24-k)

ans = 0

for i in range(1<<len(l)):
    t = T[:]
    
    for j in range(len(l)):
        if (i>>j)&1:
            t.append(l[j])
        else:
            t.append(24-l[j])
    
    t.sort()
    d = t[0]+24-t[-1]
    ans_cand = min(d, 24-d)
    
    for i in range(len(t)-1):
        d = t[i+1]-t[i]
        ans_cand = min(ans_cand, min(d, 24-d))
    
    ans = max(ans, ans_cand)

print(ans)

Measured memory_bytes: 40560
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int a[n];
int ma=0;
for(int i=0;i<n;i++)
    cin>>a[i];
int dp[n];
dp[n-1]=0;
for(int i=n-2;i>=0;i--){
    if(a[i]>=a[i+1])
    {
        dp[i]=dp[i+1]+1;
        ma=max(ma,dp[i]);

    }
    else dp[i]=0;
}
cout<<ma<<endl;
}













Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int count;
  count =0;
  rep(i,n){
    if((s[i]=='A') && (s[i+1]=='B') && (s[i+2]=='C')){
      count +=1;
    }
  }
  cout << count << endl;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i<N; i++) cin >> A.at(i);
    int al = 0, bo = 0;
    sort(A.begin(), A.end(), [](int a, int b){return a > b;});
    for(int i = 0; i < N; i++){
        if(i % 2 == 0) al += A.at(i);
        else bo += A.at(i);
    }
    cout << al - bo << endl;
}

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

class UnionFind {
private:
  int sz;
  vector<int> par, size_;
public:
  UnionFind() {}
  UnionFind(int n) : sz(n), par(sz), size_(sz, 1) {
    iota(par.begin(), par.end(), 0);
  }
  int root(int x) {
    if (par.at(x) == x) return x;
    else return par.at(x) = root(par.at(x));
  }
  void unit(int x,int y) {
    x = root(x), y = root(y);
    if (x == y) return;
    if (size_.at(x) < size_.at(y)) swap(x, y);
    par.at(y) = x;
    size_.at(x) += size_.at(y);
  }
  int size(int x) {
    x = root(x);
    return size_.at(x);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> P(N);
  for (int i = 0; i < N; i++) {
    cin >> P.at(i);
    P.at(i)--;
  }
  UnionFind UF(N);
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    UF.unit(x, y);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (P.at(i) == i) {
      ans++;
      continue;
    }
    if (UF.root(i) == UF.root(P.at(i))) ans++;
  }
  cout << ans << "\n";
}

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

using namespace std;

using int64 = long long;
const int mod = (int) (1e9 + 7);

const int64 infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

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

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

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

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
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);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

template< typename T >
size_t longest_increasing_subsequence(const vector< T > &a, bool strict) {
  vector< int > lis;
  for(auto &p : a) {
    typename vector< T >::iterator it;
    if(strict) it = lower_bound(begin(lis), end(lis), p);
    else it = upper_bound(begin(lis), end(lis), p);
    if(end(lis) == it) lis.emplace_back(p);
    else *it = p;
  }
  return lis.size();
}


int main() {
  int N;
  cin >> N;
  vector< int > A(N);
  cin >> A;
  reverse(begin(A), end(A));
  cout << longest_increasing_subsequence(A, false) << endl;
}

Measured memory_bytes: 1276
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
//#define int long long
//----------------------------------------------------
int n, k;
int a[100];
signed main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	reverse(a, a + n);
	int ans = 0;
	for (int i = 0; i < k; i++) {
		ans += a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma once
using namespace std;
int main() {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if(s.at(0) == s.at(1) and s.at(1) != s.at(2) and s.at(2) == s.at(3)) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//const int MAX=;



int main(){
	int A,B,C;
	cin>>A>>B>>C;
	if(A==B && B==C)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
/*
 * c.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_M = 500;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

pii rvs[MAX_M];

/* subroutines */

/* main */

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

  for (int i = 0; i < m; i++) cin >> rvs[i].first >> rvs[i].second;
  sort(rvs, rvs + m);

  int sum = 0, pci = -1, pdi = -1;
  for (int i = 0; i < m; i++) {
    int &ci = rvs[i].first, &di = rvs[i].second;
    if (pdi >= ci) {
      if (pdi < di) pdi = di;
    }
    else {
      sum += pdi - pci;
      pci = ci, pdi = di;
    }
  }
  sum += pdi - pci;

  printf("%d\n", n + 1 + sum * 2);
  return 0;
}

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

int main(){
    int a;
    cin >> a;
    double aux = (double) a/2;
    double aux2 = (double) a;
    cout << setprecision(7) << fixed;
    if(a%2 == 0){
        cout << aux/a << endl;
    } else{
        int aux3 = ((aux2/2)+1);
        cout << ((double) aux3 )/a << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main (String [] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		
		while (b > 0) {
			int temp = a;
			a = b;
			b = temp % b;
		}
		
		System.out.println(a);
	}
}


Measured memory_bytes: 26180
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string.h>
using namespace std;
typedef long long int llint;
int main() {
	char a[15], b[15], c[15];
	cin >> a >> b >> c;
	if (a[strlen(a) - 1] == b[0] && b[strlen(b) - 1] == c[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// Created by Kshitij Anand NSIT
#include <bits/stdc++.h>
//#include <ext/numeric>
//using namespace __gnu_cxx;


using namespace std;


#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define db(x)  cout<<#x<<" : "<<x<<endl


const int N = 1000000007;

void solve(){

    int n,a,b,c, ans=0, count=0, sum=0;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }  

    int pref[n] = {};
    pref[n - 1] = arr[n - 1]%N;

    for(int i=n - 2; i>=0; i--) {

        pref[i] = (arr[i]%N + pref[i + 1]%N)%N;
        pref[i]%=N;
    }

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

        ans += ((pref[i]%N - arr[i]%N + N)*arr[i]%N)%N;
        ans%=N;
    }

    cout<<ans<<endl;

}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
  //  int t; cin>>t; while(t--)
    {     
      solve();
    }

  return 0;
}


Measured memory_bytes: 6780