akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
  for (ll i = 0; i < v.size(); ++i) \
    cout << v[i] << " ";            \
  cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)
#define get(n) \
  ll n;        \
  cin >> n
#define getvec(v, n)         \
  vector<ll> v(n);           \
  for (ll i = 0; i < n; i++) \
    cin >> v[i];
#define getstr(s) \
  string s;       \
  cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

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

void mainSolve()
{
  int mx = 1e6;
  vl sieve(mx + 1);
  for (int i = 0; i <= mx; i++)
    sieve[i] = i;
  for (int i = 2; (i * i) <= mx; i++)
  {
    if (sieve[i] == i)
    {
      for (int j = (i * i); j <= mx; j += i)
      {
        if (sieve[j] == j)
          sieve[j] = i;
      }
    }
  }
  get(n);
  getvec(v, n);
  ll g = v[0];
  for (int i = 1; i < n; i++)
    g = gcd(g, v[i]);
  if (g != 1)
  {
    p1("not coprime");
    return;
  }
  unordered_map<int, int> m;
  for (int i = 0; i < n; i++)
  {
    int x = v[i];
    unordered_set<ll> s;
    while (x != 1)
    {
      s.insert(sieve[x]);
      x /= sieve[x];
    }
    for (int y : s)
    {
      if (m[y] > 0)
      {
        p1("setwise coprime");
        return;
      }
      ++m[y];
    }
  }
  p1("pairwise coprime");
}

int main()
{
  fio;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  //get(t);
  ll t = 1;
  while (t--)
  {
    mainSolve();
  }
  return 0;
}


Measured memory_bytes: 18764
import numpy as np
from copy import deepcopy

n=int(input())
a=list(map(int,input().split()))
b=a
d=[]
m=0
for i,j in enumerate(a):
    d.append(j-i-1)
    # print(d[i])
e=deepcopy(d)
e.sort()
c=e[n//2]
ans=0
for i,j in enumerate(d):
    # print(d[i])
    ans+=abs(d[i]-c)
print(ans)


Measured memory_bytes: 34188
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import java.util.Map.Entry;

public class Main {
	
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		
		Scanner in = new Scanner(System.in);
		
		String O = in.next();
		String E = in.next();
		for(int i = 0; i < O.length() + E.length(); i++){
			if(i % 2 == 0) System.out.print(O.charAt(i / 2));
			else System.out.print(E.charAt((i - 1) / 2));
		}
		System.out.println();
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int h,w;
	cin>>h>>w;
	vector<string> g(h);
	rep(i,h){
		cin>>g[i];
	}
	int ans=0;
	vector<vector<int>> suml(h,vector<int>(w,0));
	vector<vector<int>> sumr(h,vector<int>(w,0)); 
	vector<vector<int>> sumu(h,vector<int>(w,0)); 
	vector<vector<int>> sumd(h,vector<int>(w,0));
	rep(i,h){
		rep(j,w){
			if(g[i][j]=='#') continue;
			if(j==0) continue;
			if(g[i][j-1]=='#') continue;
			suml[i][j]=suml[i][j-1]+1;
		}
		for(int j=w-1;j>=0;j--){
			if(g[i][j]=='#') continue;
			if(j==w-1) continue;
			if(g[i][j+1]=='#') continue;
			sumr[i][j]=sumr[i][j+1]+1;
		}
	}
	rep(j,w){
		rep(i,h){
			if(g[i][j]=='#') continue;
			if(i==0) continue;
			if(g[i-1][j]=='#') continue;
			sumu[i][j]=sumu[i-1][j]+1;
		}
		for(int i=h-1;i>=0;i--){
			if(g[i][j]=='#') continue;
			if(i==h-1) continue;
			if(g[i+1][j]=='#') continue;
			sumd[i][j]=sumd[i+1][j]+1;
		}
	}
	rep(i,h)rep(j,w){
		if(g[i][j]=='#') continue;
		chmax(ans,sumr[i][j]+suml[i][j]+sumu[i][j]+sumd[i][j]+1);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 67328
#include<bits/stdc++.h>
using namespace std;
long long a[100005];
long long b[100005];
int main(){
	int n;
	cin>>n;
	long long tot=0;
	for(int i=0;i<n+1;i++){
		cin>>a[i];
		tot+=a[i];
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	for(int i=0;i<n;i++){
		if(b[i]>a[i]){
			b[i]-=a[i];
			a[i]=0;
			if(b[i]>a[i+1]){
				a[i+1]=0;
				b[i]=0;
			}else{
				a[i+1]-=b[i];
				b[i]=0;
			}
		}else{
			a[i]-=b[i];
			b[i]=0;
		}
	}
	long long sum=0;
	for(int i=0;i<n+1;i++){
//		cout<<a[i]<<" ";
		sum+=a[i]; 
	}
//	cout<<endl;
	cout<<tot-sum;
	return 0;
}

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

#define ABS(a) ((a)>=0?(a):-(a))

const int mod=998244353;

typedef long long int int64;

int modPow(int r,int64 n){
  int t=1;
  int s=r;
  while(n>0){
    if(n%2) t=(int64)t*s%mod;
    s=(int64)s*s%mod;
    n>>=1;
  }
  return t;
}

typedef struct masu{
  int a,b,c;
} node;

int cmp(const void *a,const void *b){
  node *p=(node *)a;
  node *q=(node *)b;
  if(p->a!=q->a) return p->a-q->a;
  return p->b-q->b;
}

int popcnt(int n){
  int res=0;
  while(n){
    res+=n&1;
    n>>=1;
  }
  return res;
}

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  node *d=(node *)calloc(m,sizeof(node));
  node *e=(node *)calloc(m,sizeof(node));
  int dlen=0;
  int elen=0;
  while(m--){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(ABS(a-b)<=2){
      d[dlen++]=(node){a,b,c};
    } else {
      if(b<a){
	int s=a;
	a=b;
	b=s;
      }
      e[elen++]=(node){a,b,c};
    }
  }
  qsort(d,dlen,sizeof(node),cmp);
  qsort(e,elen,sizeof(node),cmp);
  int way=1;
  int64 cnt=(int64)(n-3)*(n-2)/2;;
  int i,j,k;
  i=0;
  while(i<elen){
    cnt--;
    i++;
    if(i<elen && cmp(e+i,e+i-1)==0){
      if(e[i].c!=e[i-1].c){
	way=0;
      }
      i++;
    }
  }
  way=(int64)way*modPow(2,cnt)%mod;
  int now[16];
  for(i=0;i<(1<<4);i++){
    int ok=popcnt(i)%2==0?1:0;
    for(j=0;j<dlen && d[j].a<=2;j++){
      if(d[j].b>2) continue;
      int shift=2*(d[j].a-1)+d[j].b-1;
      if(((i>>shift)&1)!=d[j].c) ok=0;
    }
    now[i]=ok;
  }
  k=0;
  for(i=3;i<=n;i++){
    while(k<dlen && d[k].a<=i-3) k++;
    int next[16];
    for(j=0;j<16;j++) next[j]=0;
    for(j=0;j<(1<<5);j++){
      int ok=1;
      int l;
      for(l=k;l<dlen && d[l].a<=i;l++){
	if(d[l].b>i) continue;
	if(d[l].a<i && d[l].b<i) continue;
	int shift=d[l].b-(i-2)+i-d[l].a;
	if(((j>>shift)&1)!=d[l].c) ok=0;
      }
      if(!ok) continue;
      int m=popcnt(j);
      for(l=0;l<(1<<4);l++){
	if((popcnt(l)+m)%2==0 && popcnt((l&8)+((j>>1)&7))%2==0){
	  int index=((l>>3)&1)+2*((j>>3)&1)+4*((j>>1)&1)+8*((j>>2)&1);
	  next[index]=(next[index]+now[l])%mod;
	}
      }
    }
    for(j=0;j<16;j++) now[j]=next[j];
  }
  int sum=0;
  for(i=0;i<(1<<4);i++) sum=(sum+now[i])%mod;
  int ans=(int64)sum*way%mod;
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 1916
import sys
x,n=map(int,input().split())
p=list(map(int,input().split()))
c=0
if n==0:
  print(x)
  sys.exit()
for i in range(x,-200,-1):
  
  if not i in p:
    print(i)
    sys.exit()
  if not (x+c) in p:
    print(x+c)
    sys.exit()
  c+=1


Measured memory_bytes: 9192
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <string>

using namespace std;
#define M 110

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

  sort(a, a+N);

  i = 0;
  while (i < N && x >= a[i]){
    x -= a[i];
    i++;
  }
  int cnt = i;
  if (x > 0 && cnt == N)
    cnt --;
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	if s == "A" {
		fmt.Println("T")
	} else if s == "T" {
		fmt.Println("A")
	} else if s == "C" {
		fmt.Println("G")
	} else if s == "G" {
		fmt.Println("C")
	}
}


Measured memory_bytes: 512
import java.util.Scanner;	//Scannerクラス：Java標準入力を取得する

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			String str = sc.nextLine();
			char []csen = str.toCharArray();
			for(int i = 0;i < str.length();i++) {
				if( Character.isUpperCase( csen[i] ) ) {
					csen[i] = Character.toLowerCase(csen[i]);
					System.out.print(csen[i] );
				}
				else if( Character.isLowerCase( csen[i] ) ) {
					csen[i] = Character.toUpperCase(csen[i]);
					System.out.print(csen[i] );
				}
				else {
					System.out.print(csen[i]);
				}
			}
			System.out.println();
		}
	}
}



Measured memory_bytes: 26976
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	//iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
void solve() {
	while (true) {
		int n, m;
		cin >> n >> m;
		if (n == 0) return;
		map<pair<int, int>, int> next;
		REP(i, m) {
			int a, b;
			cin >> a >> b;
			next[mp(a, b)] = 1;
		}
		int a, b;
		cin >> a >> b;
		queue<pair<int, int>> gogo;
		gogo.push(mp(a, b));
		map<pair<int, int>, int> visited;
		visited[mp(a, b)] = 1;
		int ans = 0;
		while (gogo.empty() == false) {
			pair<int, int> now = gogo.front();
			gogo.pop();
			ans++;
			int dx[6] = { 0,-1,-1,0,1,1 };
			int dy[6] = { 1,0,-1,-1,0,1 };
			REP(q, 6) {
				int x = now.first + dx[q];
				int y = now.second + dy[q];
				if (next[mp(x, y)] == 1) continue;
				if (visited[mp(x, y)] != 0) {
					continue;
				}
				visited[mp(x, y)] = visited[now] + 1;
				if (visited[mp(x, y)] != n + 1) {
					gogo.push(mp(x, y));
				}
				else ans++;
			}
		}
		cout << ans << endl;
	}
}
#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3540
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
    string s;cin>>s;
    long long n=(int)s.length();
    vector<long long> num(30,0);
    for(int i=0;i<n;i++){
        int buf=s[i]-'a';
        num[buf]++;
    }
    long long sum=(n*(n-1)/2)+1;
    for(int i=0;i<30;i++){
        sum=sum-(num[i]*(num[i]-1))/2;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N; cin >> N;
  vector<int> H(N); REP(i, N) cin >> H[i];

  int ans = 0;
  for (int i = 0, cur = 0; i < N-1; ++i) {
    if (H[i] >= H[i+1]) {
      cur++;
    } else {
      cur = 0;
    }
    ans = max(ans, cur);
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include<cmath>
#include<iomanip>
#include <algorithm>
#include<string.h>
#include<queue>
#include<deque>
#include<set>

using namespace std;
//cout<<setprecision(9)<<fixed<<a;
typedef long long ll;


int main()

{
   ll n,sum=0,m;
   cin>>n;
   for(int i=1; i<=n; i++)
   {
       m=n/i;
       sum+=i*(m*(m+1))/2;
   }
   cout<<sum;


}











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

int main() {
   int n;
   cin >> n;
   int k = n%10;
   string ans = "";
   if (k == 3) ans = "bon";
   else if(k==0 || k==1 || k==6|| k==8) ans="pon";
   else ans="hon";

   cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int>V(N);
    vector<int>C(N); 
    for(int i = 0; i < N; i++) cin >> V[i];
    for(int i = 0; i < N; i++) cin >> C[i];
    int ans = 0;
    for(int i = 0; i < N; i++) {
        if(V[i] > C[i]) ans+=V[i]-C[i];
    }
    cout << ans << endl;
}

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

int main(){
    char S[10],T[10],U[10];
    int A,B;
   
    scanf("%s%s",S,T);

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

    scanf("%s",U);

    if(strcmp(S,U)==0) A-=1;
    else if(strcmp(T,U)==0) B-=1;

    printf("%d %d",A,B);


    return 0;
}

Measured memory_bytes: 128
#include <iostream>
      #include <string>
      #include <vector>
      #include <algorithm>
      #include <utility>
      using namespace std;
      typedef long long ll;
      #define rep(i, n) for (int i=0;i < (int)(n);i++)



      int main(){
         ll x;
         cin >> x;
         ll ans;
         ans=(x/11)*2;
         if (x%11 == 0);
         else if (x%11 <= 6 ) ans++;
         else ans+=2;
         cout << ans << endl;
         
         return 0;
         
      }



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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> Pair;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

ll N, W;
VL v, w;
vector<VL> dp;

int main() {
    cin >> N >> W;
    ll vsum = 0;
    REP(i, N) {
        v.emplace_back(IN());
        vsum += v[i];
        w.emplace_back(IN());
    }
    dp.assign(N + 1, VL(vsum + 1, LINF));
    dp[0][0] = 0;
    REP(i, N) REP(j, vsum + 1) {
        if(j < v[i])
            dp[i + 1][j] = dp[i][j];
        else
            dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
    }
    ll ans = 0;
    REP(i, vsum + 1) if(dp[N][i] <= W) ans = i;
    cout << ans << "\n";
}



Measured memory_bytes: 10804
def resolve():
    n, m, q = map(int, input().split())
    rosen = [[0] * n for _ in range(n)]
    for i in range(m):
        l, r = map(int, input().split())
        l -= 1
        r -= 1
        rosen[l][r] += 1
    cum = [[0] * (n+1) for _ in range((n+1))]

    for i in range(n):
        if i == 0:
            cum[0][0] = rosen[0][0]
            for j in range(1, n):
                cum[0][j] = cum[0][j-1] + rosen[0][j]
        else:
            cum[i][0] = cum[i-1][0] + rosen[i][0]
            for j in range(1,n):
                cum[i][j] = cum[i-1][j] + cum[i][j-1] - cum[i-1][j-1] + rosen[i][j]
    for i in range(q):
        p, q = map(int, input().split())
        p -= 1
        q -= 1
        if p == 0:
            print(cum[q][q])
        else:
            print(cum[q][q]-cum[p-1][q]-cum[q][p-1]+cum[p-1][p-1])
resolve()

Measured memory_bytes: 20728
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-01-15 00:33:40
**/

#include <cstdio>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#define getchar_unlocked getchar
#else
#define debug(_) 1728
#endif

class UnionFind {
 public:
  UnionFind(int n) : n_(n) { Initialize(); }

  inline int GetRoot(int x) {
    if (parent_[x] == -1)
      return x;
    else
      return parent_[x] = GetRoot(parent_[x]);
  }

  bool IsSame(int x, int y) { return GetRoot(x) == GetRoot(y); }

  void Unite(int x, int y) {
    x = GetRoot(x);
    y = GetRoot(y);
    if (x == y) return;
    if (rank_[x] < rank_[y]) std::swap(x, y);
    if (rank_[x] == rank_[y]) ++rank_[x];
    parent_[y] = x;
    return;
  }

 private:
  const int n_;
  std::vector<int> parent_;
  std::vector<int> rank_;

  void Initialize() {
    parent_.assign(n_, -1);
    rank_.assign(n_, 0);
  }
};

template<class T> inline void fastin(T &num) {
  bool negative = false;
  T c;
  num = 0;
  c = getchar_unlocked();
  if (c == '-') {
    negative = true;
    c = getchar_unlocked();
  }
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
  if (negative) num *= -1;
}

int main() {
  //ios_base::sync_with_stdio(false);
  //cin.tie(nullptr);

  int n, k, l; fastin(n); fastin(k); fastin(l);

  UnionFind uf1(n), uf2(n);

  for (int i = 0; i < k; ++i) {
    int p, q; fastin(p); fastin(q);
    --p; --q;
    uf1.Unite(p, q);
  }

  for (int i = 0; i < l; ++i) {
    int r, s; fastin(r); fastin(s);
    --r; --s;
    uf2.Unite(r, s);
  }

  map<pair<int, int>, int> mp;
  for (int i = 0; i < n; ++i) {
    ++mp[{uf1.GetRoot(i), uf2.GetRoot(i)}];
  }

  for (int i = 0; i < n; ++i) {
    printf("%d ", mp[{uf1.GetRoot(i), uf2.GetRoot(i)}]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 15104
#include<stdio.h>
int main() {
  int n,T,c[1000],t[1000],i,min;
  scanf("%d%d",&n,&T);
  for(i=0;i<n;i++){
    scanf("%d%d",&c[i],&t[i]);
  }
  for(i=0;i<n;i++){
    if(t[i]>T) c[i]=1001;
  }
  min=c[0];
  for(i=1;i<n;i++){
    if(min>c[i]){
      min=c[i];
    }
  }
  if(1001>min) printf("%d",min);
  else puts("TLE");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n;
  cin >> n;
  vector<pii> task(n);
  rep(i, n) {
    cin >> task[i].second >> task[i].first;
  }

  sort(all(task));

  ll now = 0;
  rep(i, n) {
    now += task[i].second;
    if (task[i].first < now) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    int N, K;
    string S;
    cin >> N >> K >> S;

    int score = 0;
    rep(i, N - 1) {
        if (S[i] == S[i + 1]) score++;
    }
    int ans = min(score + 2 * K, N - 1);
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

// #define DEBUG

const ll mod = 1e9 + 7;
ll mypow(ll x, ll y, ll m = mod)
{
    ll ans = 1;
    ll q = x;
    while (y > 0)
    {
        if (y % 2 == 1)
        {
            ans *= q;
            ans %= m;
        }
        q = q * q;
        q %= m;
        y = y / 2;
    }
    return ans % m;
}

ll permulation(ll x, ll y, ll m = mod)
{
    ll ans = 0;
    if (x >= y)
    {

        ans = 1;
        for (ll i = x - y + 1; i <= x; i++)
        {
            ans = (ans * i) % m;
        }
    }
    return ans;
}

ll combination(ll x, ll y, ll m = mod)
{
    ll ans = 0;
    if (y == 0 || y == x)
        ans = 1;
    else
    {
        ans = 1;
        for (ll i = x - y + 1; i <= x; i++)
        {
            ans = (ans * i) % m;
        }
        for (ll i = 1; i <= y; i++)
        {
            ans = (ans * mypow(i, m - 2, m)) % m;
        }
    }
    return ans;
}

ll fractual(ll x, ll m = mod)
{
    if (x == 0)
        return 0;
    else
        return permulation(x, x, m);
}

ll multi_choose(ll x, ll y, ll m = mod)
{
    return combination(x + y - 1, y - 1, m);
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    ll n, k;
    cin >> n >> k;
    cout << combination(k, n) << endl;
    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 3104
import numpy as np

# H, W = 4, 4
# ARR = [
#     ["#", "#", ".", "#"],
#     [".", ".", ".", "."],
#     ["#", "#", ".", "#"],
#     [".", "#", ".", "#"],
# ]



H, W = map(int, input().split())
ARR = []

for i in range(H):
    ARR.append(list(input()))


def calculate(h, w, arr):
    arr = np.array(arr)
    arr = np.where(arr == ".", 0, 1)
    s = np.sum(arr, axis=1)

    p = s > 0
    m = arr[p]


    t = np.sum(m, axis=0)

    o = t > 0

    res = m[:, o]

    res = np.where(res==1,"#",".")

    for re in res:
        print("".join(re))



calculate(H, W, ARR)


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

using namespace std;
typedef long long ll;
int n,a[200000];
ll b[200000];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++) b[i]=b[i-1]+a[i];
	for(int i=n;i>=1;i--)
	{
		if(a[i]>b[i-1]*2)
		{
			printf("%d\n",n-i+1);
			return 0;
		}
	}
	printf("%d\n",n);
	return 0 ;
}

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

using namespace std;

typedef long long ll;
#define SWAP(x,y,z) {if ( y > z ) swap(y,z); if ( x > y ) swap(x,y); if (y > z) swap(y,z);}


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

    int n,ans = 0,x = 0;
    string s;

    cin >> n;
    cin >> s;

    for ( int i = 0; i < n; i++ )
    {
        if ( s[i] == 'I' ) x++;
        else x--;
        ans = max(ans,x);
    }
    cout << ans;
    return 0;
    // 274751WM
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		if (N == 1) {
			System.out.println(0);
			return;
		}

		// 10^n - 8^n - 2(9^n - 8^n)
		System.out.println(sub(sub(pow(10, N), pow(8, N)), mul(2, sub(pow(9, N), pow(8, N)))));
	}

	static final int MOD = 1000000007;

	int mod(long val) {
		return Math.floorMod(val, MOD);
	}

	int add(long a, long b) {
		return mod(a + b);
	}

	int sub(long a, long b) {
		return add(a, -b);
	}

	int mul(long a, long b) {
		return mod(a * b);
	}

	int pow(long a, long n) {
		int res = 1;
		for (; n > 0; n /= 2) {
			if (n % 2 == 1) res = mul(res, a);
			a = mul(a, a);
		}
		return res;
	}

	long[] factorial;
	long[] facInverse;
	long[] inverse;

	void initNCR() {
		int MOD = 1000000007;
		int MAX = 1000000 + 7;
		factorial = new long[MAX];
		facInverse = new long[MAX];
		inverse = new long[MAX];
		factorial[0] = factorial[1] = 1;
		facInverse[0] = facInverse[1] = 1;
		inverse[1] = 1;
		for (int i = 2; i < MAX; i++) {
			factorial[i] = factorial[i - 1] * i % MOD;
			long inv = inverse[i] = MOD - inverse[MOD % i] * (MOD / i) % MOD;
			facInverse[i] = facInverse[i - 1] * inv % MOD;
		}
	}

	int ncr(int n, int r) {
		if (n < r) return 0;
		if (n < 0 || r < 0) return 0;
		return (int) (factorial[n] * (facInverse[r] * facInverse[n - r] % 1000000007) % 1000000007);
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		new Solver().solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

Measured memory_bytes: 32684
//   HVARDHANSINGH   //
 
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
 
#define ll      long long
#define F       first
#define S       second
#define endl    "\n"

const ll M =    200006;
const int mod = 1000000007;

void solve()
{
	int a;
	string s;	cin>>a>>s;
	
	if(a<3200)	cout<<"red";
	else		cout<<s;
	
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    int T = 1;
    // cin>>T;
    while(T--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

// Light version
using Data = int;
const int len = 1 << 19;

struct BIT {
  vector<Data> data;
  BIT() : data(len, 0) {}
  void update(int i, Data value) {
    for (; i < len; i |= i+1) data[i] += value;
  }
  Data query(int i) {
    Data s = 0;
    for (; i >= 0; i = (i&i+1)-1) s += data[i];
    return s;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,q;
  cin>>n>>q;
  vecint last(n+1, -1);
  vector<tuple<int,int>> vp;
  REP(i,n) {
    int c;
    cin>>c;
    if (last[c] >= 0) {
      vp.emplace_back(last[c], i);
    }
    last[c] = i;
  }
  sort(ALL(vp));
  reverse(ALL(vp));
  vector<tuple<int,int,int>> vq;
  REP(i,q) {
    int l,r;
    cin>>l>>r;
    --l;--r;
    vq.emplace_back(l,r,i);
  }
  sort(ALL(vq));
  reverse(ALL(vq));
  auto itr = begin(vp);
  BIT bit;
  vecint res(q);
  for(auto&&[x,y,i]:vq) {
    while (itr != end(vp)) {
      auto&&[xp,yp] = *itr;
      if (xp < x) break;
      bit.update(yp, 1);
      ++itr;
    }
    res[i] = (y-x+1) - bit.query(y);
  }
  REP(i,q) {
    cout<<res[i]<<"\n";
  }
  return 0;
}


Measured memory_bytes: 18864
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] A = new int[50];
        int[] B = new int[50];
        int[] C = new int[50];
        int i = 0;
        
        while(true){
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
            C[i] = sc.nextInt();
            if(A[i] == -1 && B[i] == -1 && C[i] == -1) break;
            i++;
        }
        for(int j = 0; j < i; j++){
            if(A[j] == -1 || B[j] == -1) System.out.println("F");
            else if(A[j] + B[j] >= 80) System.out.println("A");
            else if(A[j] + B[j] < 80 && A[j] + B[j] >=65) System.out.println("B");
            else if((A[j] + B[j] < 65 && A[j] + B[j] >=50) || (A[j] + B[j] < 50 && A[j] + B[j] >=30 && C[j] >=50)) System.out.println("C");
            else if(A[j] + B[j] < 50 && A[j] + B[j] >=30 && C[j] < 50) System.out.println("D");
            else if(A[j] + B[j] < 30) System.out.println("F");
        }
    }
}


Measured memory_bytes: 26340
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
    int to;
    ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
}

int N, M, A[10];
int B[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

string x(string A, string B) {
    if (A.length() > B.length())return A;
    else if (A.length() < B.length())return B;
    return max(A, B);
}

map<ll, string> m;

string solve(ll n = N) {
    if (m.find(n) != m.end())return m[n];
    if (n == 0) return m[n] = "";
    string s = "";
    bool flag = 0;
    for (int i = 0; i < M; i++) {
        if (n - B[A[i]] >= 0 && solve(n - B[A[i]]) != "-") {
            s = x(s, to_string(A[i]) + solve(n - B[A[i]]));
            flag = 1;
        }
    }
    if (flag) {
        return m[n] = s;
    }
    return "-";
}

int main() {
    COME_LET_THE_GAMES_BEGIN();
    cin >> N >> M;
    rep(i, M) {
        cin >> A[i];
    }
    cout << solve() << endl;
}

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

struct Match {
    int n;
    vector<vector<int>> G;
    vector<bool> used;
    vector<int> match;

    Match(int n_) : n(n_) { G.resize(n); }
    void add_edge(int u, int v) {
        G[u].push_back(v);
        G[v].push_back(u);
    }
    bool dfs(int v) {
        used[v] = true;
        for(auto nv : G[v]) {
            int vv = match[nv];
            if(vv < 0 || (!used[vv] && dfs(vv))) {
                match[v] = nv;
                match[nv] = v;
                return true;
            }
        }
        return false;
    }
    int solve() {
        int res = 0;
        match.assign(n,-1);
        for (int i = 0; i < n; i++) {
            if(match[i] >= 0) continue;
            used.assign(n,false);
            if(dfs(i)) res++;
        }
        return res;
    }
};

int main(){
    int n; cin >> n;
    int a[n], b[n], c[n], d[n];
    rep(i,n) cin >> a[i] >> b[i];
    rep(i,n) cin >> c[i] >> d[i];
    Match data(2*n);
    rep(i,n) rep(j,n) if(a[i] < c[j] && b[i] < d[j]) data.add_edge(i,j+n);
    cout << data.solve() << endl;
}

Measured memory_bytes: 3612
#include <stdio.h>
int main(void)
{
int n, x, l[101], i, p=0, keep;
  scanf("%d", &n);
  scanf("%d", &x);
  for(i=1; i<=n; i++)
  scanf("%d", &l[i]);
  for(i=1; i<=n; i++)
  {
    p=p+l[i];
    if(x<p){
      keep=i;
      break;
    }
  }
  printf("%d", keep);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", ";
        a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}

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

    for (;;) {
        int N, M; cin >> N >> M;
        if (N == 0) break;

        vll mi(N), ma(N);
        REP(i, M) {
            int s, k; cin >> s >> k;
            REP(j, k) {
                int c; cin >> c; --c;
                ma[c] += s;
                if (k == 1) mi[c] += s;
            }
        }

        ll ans = 0;
        int maxI = max_element(ALL(ma)) - ma.begin();
        int minI = min_element(ALL(mi)) - mi.begin();
        if (maxI != minI) {
            ans = *max_element(ALL(ma)) - *min_element(ALL(mi)) + 1;
        } else {
            REP(i, N) {
                if (maxI != i) chmax(ans, ma[maxI] - mi[i] + 1);
                if (minI != i) chmax(ans, ma[i] - mi[minI] + 1);
            }
        }
        cout << ans << endl;
    }

    return 0;
}



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

using namespace std;

int main() {
    string S, a;
    int w;

    cin>>S;
    cin>>w;
    for(int i = 0; i < S.length(); i++) {
        if(i % w == 0) printf("%c", S[i]);
    }

    printf("\n");

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

w,h,n = map(int, input().split())

area = [[0 for i in range(w)] for j in range(h)]

for i in range(n):
    a,b,c = map(int, input().split())
    if(c == 1):
        for j in range(h):
            for k in range(a):
                area[j][k] = 1
    if (c == 2):
        for j in range(h):
            for k in range(a,w):
                area[j][k] = 1
    if(c == 3):
        for j in range(b):
            for k in range(w):
                area[j][k] = 1
    if (c == 4):
        for j in range(b,h):
            for k in range(w):
                area[j][k] = 1

counter = 0

for i in range(h):
    for j in range(w):
        if(area[i][j] == 0):
            counter += 1

print(counter)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 1000000;
const ll INF = (1LL << 31) - 1;
const double pi=acos(-1);



int main(){
  double n,ans=0;
  cin >> n;
  vector<double>x(n);
  vector<double>y(n);
  rep(i,n) cin >> x[i] >> y[i];
  rep(i,n-1){
    for(int j=i+1;j<n;j++){
      double d=pow(x[i]-x[j],2)+pow(y[i]-y[j],2);
      ans+=sqrt(d);
    }
  }
  cout << fixed << setprecision(10) << ans*2/n << endl;
    
}


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

using namespace std;

typedef long long int ll;
typedef long double ld;

int main()
{
	int n;
	cin >> n;
	ll arr[n];
	for(int i = 0; i < n; i++) cin >> arr[i];
	ll x = 0;
	ll pre[n];
	for(int i = 0; i < n; i++)
	{
		if(i == 0) pre[i] = arr[i];
		else pre[i] = (pre[i - 1] ^ arr[i]);
	}
	ll arr1[n];
//	cout << "0 ";
	arr1[0] = 0;
	ll pre1[n];
	pre1[0] = 0;
	ll xorr = 0, sum = arr[0];
	for(int i = 0; i < n; i++)
	{
		cout << (pre[n - 1] ^ arr[i]) << " ";
//		pre1[i] = (pre[n - 1] ^ arr[i]);
		arr1[i] = (pre[n - 1] ^ arr[i]);
		xorr = (xorr ^ arr1[i]);
	}
//	cout << sum << "\n";
//	cout << "\n";
//	for(int i = 0; i <n; i++) cout << (xorr ^ arr1[i]) << " ";
}

Measured memory_bytes: 8268
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
                
    divisors.sort()
    return divisors
 
 
a, b, c = map(int, input().split())
 
c_set = list(set(make_divisors(a))&set(make_divisors(b)))
 
c_set.sort()
print(c_set[-c])

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

/*

median 0 ~ N-1

odd: (N - 1)/2
even: N/2-1, N/2
*/

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

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

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    if (N % 2 == 0) { // even
        // the double of median
        int maxMed = B[N / 2 - 1] + B[N / 2];
        int minMed = A[N / 2 - 1] + A[N / 2];
        cout << maxMed - minMed + 1;
    } else { // odd
        int maxMed = B[(N - 1) / 2];
        int minMed = A[(N - 1) / 2];
        cout << maxMed - minMed + 1;
    }
}


Measured memory_bytes: 4828
// input macro 
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){
    input!{
        s: chars,
    }
    let mut v = Vec::new();
    let mut cnt = 0;
    for i in (0..s.len()){
        if v.is_empty(){
            v.push(s[i]);
        }else if v.last() != Some(&s[i]){
            cnt += 1;
            v.pop();
        }else{
            v.push(s[i]);
        }
    }
    println!("{}", cnt * 2);
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;

#define M (2<<15)

vector<int> sq;
void init() {
    for (int i = 0; i * i <= M; i++) {
        sq.push_back(i * i);
    }
}

bool is_sq(int n) {
    return binary_search(sq.begin(), sq.end(), n);
}

int solve(int n) {
    int c = 0;
    int r;
    for (int i = 0; i < sq.size(); i++) {
        r = n - sq[i];
        if (r < sq[i]) {
            break;
        }
        for (int j = i; j < sq.size(); j++) {
            r = n - sq[i] - sq[j];
            if (r < sq[j]) {
                break;
            }
            for (int k = j; k < sq.size(); k++) {
                r = n - sq[i] - sq[j] - sq[k];
                if (r < sq[k]) {
                    break;
                }
                //cout << "\t" << r << endl;
                if (is_sq(r)) {
                    c++;
                }
            }
        }
    }
end:
    return c;
}

int main() {
    init();
    int n;
    while (cin >> n, n) {
        cout << solve(n) << endl;
    }
    return 0;
}

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

using ll = long long;

//constant
const ll MOD = 1e+9 + 7;
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

// DP
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 (b < a) { a = b; return 1; } return 0; }

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


int main(void) {

	string S, T;
	cin >> S >> T;

	vector<vector<int>> dp(3001, vector<int>(3001));

	REP(i, S.size()) {
		REP(j, T.size()) {
			if (S[i] == T[j]) chmax<int>(dp[i + 1][j + 1], dp[i][j] + 1);
			chmax<int>(dp[i + 1][j + 1], dp[i][j + 1]);
			chmax<int>(dp[i + 1][j + 1], dp[i + 1][j]);
		}
	}

	int i = S.size();
	int j = T.size();
	string ans{};
	while (i > 0 && j > 0) {
		if (dp[i][j] == dp[i - 1][j]) { i--; }
		else if (dp[i][j] == dp[i][j - 1]) { j--; }
		else {
			ans = S[i-1] + ans;
			i--; j--;
		}

	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 35584
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    cin >> n >> m;
    vector<string> A(n), Arev(n);
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        A[i] = s;
        reverse(s.begin(),s.end());
        Arev[i] = s;
    }
    sort(A.begin(),A.end());
    sort(Arev.begin(),Arev.end());
    A.emplace_back("{");
    Arev.emplace_back("{");
    for (int _ = 0; _ < m; ++_) {
        string s;
        cin >> s;
        int ans = 0;
        if(s.back() == '*'){
            s.pop_back();
            int cur = -1;
            for (int i = 0; i < s.size(); ++i) {
                if(s[i] == '?') cur = i;
            }
            if(~cur){
                for (char i = 'a'; i <= 'z'; ++i) {
                    s[cur] = i;
                    ans -= lower_bound(A.begin(),A.end(), s) - A.begin();
                    s.push_back('}');
                    ans += lower_bound(A.begin(),A.end(), s) - A.begin();
                    s.pop_back();
                }
            }else {
                ans -= lower_bound(A.begin(),A.end(), s) - A.begin();
                s.push_back('}');
                ans += lower_bound(A.begin(),A.end(), s) - A.begin();
                s.pop_back();
            }
        }else if(s.front() == '*') {
            reverse(s.begin(),s.end());
            s.pop_back();
            int cur = -1;
            for (int i = 0; i < s.size(); ++i) {
                if(s[i] == '?') cur = i;
            }
            if(~cur){
                for (char i = 'a'; i <= 'z'; ++i) {
                    s[cur] = i;
                    ans -= lower_bound(Arev.begin(),Arev.end(), s) - Arev.begin();
                    s.push_back('}');
                    ans += lower_bound(Arev.begin(),Arev.end(), s) - Arev.begin();
                    s.pop_back();
                }
            }else {
                ans -= lower_bound(Arev.begin(),Arev.end(), s) - Arev.begin();
                s.push_back('}');
                ans += lower_bound(Arev.begin(),Arev.end(), s) - Arev.begin();
                s.pop_back();
            }
        }else {
            int cur = -1;
            for (int i = 0; i < s.size(); ++i) {
                if(s[i] == '?') cur = i;
            }
            if(~cur){
                for (char i = 'a'; i <= 'z'; ++i) {
                    s[cur] = i;
                    ans += *(lower_bound(A.begin(),A.end(), s)) == s;
                }
            }else {
                ans += *(lower_bound(A.begin(),A.end(), s)) == s;
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll H, W;
	cin >> H >> W;
	ll ans = 1e10;
	for (ll i = 1; i < H; i++) {
		ll vmin = min({W * i, (H - i) / 2 * W, (H - i - (H - i) / 2) * W});
		ll vmax = max({W * i, (H - i) / 2 * W, (H - i - (H - i) / 2) * W});
		if (H - i > 1) ans = min(ans, vmax - vmin);
		vmin = min({W * i, (H - i) * (W / 2), (H - i) * (W - W / 2)});
		vmax = max({W * i, (H - i) * (W / 2), (H - i) * (W - W / 2)});
		ans = min(ans, vmax - vmin);
	}
	for (ll i = 1; i < W; i++) {
		ll vmin = min({H * i, (W - i) / 2 * H, (W - i - (W - i) / 2) * H});
		ll vmax = max({H * i, (W - i) / 2 * H, (W - i - (W - i) / 2) * H});
		if (W - i > 1) ans = min(ans, vmax - vmin);
		vmin = min({H * i, (W - i) * (H / 2), (W - i) * (H - H / 2)});
		vmax = max({H * i, (W - i) * (H / 2), (W - i) * (H - H / 2)});
		ans = min(ans, vmax - vmin);
	}	
	cout << ans << endl;
	return 0;
}

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

signed main(void)
{
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++)
	{
		int a;
		cin >> a;
		n -= a;
	}
	if (n < 0)
		n = -1;
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 3636
n, k = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n):
    p[i] = (1 + p[i]) / 2
sum = 0
for i in range(k):
    sum += p[i]
ans = sum
for i in range(k, n):
    sum -= p[i - k]
    sum += p[i]
    ans = max(ans, sum)
print('{:.10f}'.format(ans))


Measured memory_bytes: 25060