akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int H, W, M;
  cin>>H>>W>>M;
  int h[M], w[M];
  REP(i, M){
    cin>>h[i]>>w[i];
    h[i]--; w[i]--;
  }
  
  vector<int> num_h(H, 0), num_w(W, 0);
  typedef pair<int, int> P;
  map<P, bool> mp;
  REP(i, M){
    num_h[h[i]]++;
    num_w[w[i]]++;
    mp[P(h[i], w[i])] = true;
  }
  int max_num_h = 0, max_num_w = 0;
  REP(i, H) max_num_h = max(max_num_h, num_h[i]);
  REP(j, W) max_num_w = max(max_num_w, num_w[j]);
  vector<int> candh, candw;
  REP(i, H) if(max_num_h == num_h[i]) candh.push_back(i);
  REP(j, W) if(max_num_w == num_w[j]) candw.push_back(j);
  int ans = 0;
  long long n = candh.size(), m = candw.size();
  if(n * m > M){
    ans = max_num_h + max_num_w;
  }else{
    bool flag = false;
    for(int& ch: candh){
      for(int& cw: candw){
        if(mp[P(ch, cw)]) continue;
        flag = true;
      }
    }
    if(flag){
      ans = max_num_h + max_num_w;
    }else{
      ans = max_num_h + max_num_w - 1;
    }
  }
  cout << ans << endl;
  
  return 0;
}

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

int main() {
  static const double pi = 3.141592653589793;
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  double angleA, angleB;
  angleA = 30 * H + 0.5 * M;
  angleB = 6 * M;
  double ap[2], bp[2];
  ap[0] = A * sin(angleA / 180 * pi);
  ap[1] = A * cos(angleA / 180 * pi);
  bp[0] = B * sin(angleB / 180 * pi);
  bp[1] = B * cos(angleB / 180 * pi);
  double ans;
  ans = sqrt(pow(bp[0] - ap[0],2) + pow(bp[1] - ap[1], 2));
  cout << fixed << setprecision(20) << ans << endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    string S, T;
    cin >> S >> T;
    ll N = S.size();
    ll M = T.size();
    vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 0));
    rep(i, N) {
        rep(j, M) {
            if (S[i] == T[j]) {
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
            } else {
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
            }
        }
    }
    string ans = "";
    ll i = N - 1;
    ll j = M - 1;
    while ((i >= 0 && j >= 0)) {
        if (S[i] == T[j]) {
            ans += S[i];
            i--;
            j--;
        } else {
            if (i > 0 && j > 0) {
                if (dp[i + 1][j] > dp[i][j + 1]) {
                    j--;
                } else {
                    i--;
                }
            } else {
                if (i == 0) {
                    j--;
                } else {
                    i--;
                }
            }
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
}

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


Measured memory_bytes: 73632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e15;
typedef pair<int,int> ii;
typedef vector<int> vi;

const int max_item_cnt=100+10;
const int max_value_sum=1e5+10;
ll W[max_item_cnt],V[max_item_cnt];
ll dp[max_value_sum]; 
// dp[i] - min sum of weights with i value
 
int main(){
	ll n,w;
	cin>>n>>w;
	ll max_val=0;
	for(int i=1;i<=n;i++){
		cin>>W[i]>>V[i];
		max_val+=V[i];
	}
	for(int i=1;i<=max_val;i++)dp[i]=inf;	
	for(int i=1;i<=n;i++){
		for(int j=max_val;j>=V[i];j--){
			dp[j]=min(dp[j-V[i]]+W[i],dp[j]);
		}
	}
	ll ans=0;
	//ans - max v such as dp[v]<=w
	for(int v=max_val;v>=0 && !ans;v--){
		if(dp[v]<=w){
			ans=v;
		}
	}
	cout<<ans;
 
	return 0;
}

Measured memory_bytes: 1024
import Control.Monad

data Type = BTC | JPY

main :: IO ()
main = do
    n <- read <$> getLine :: IO Int
    ns <- replicateM n ((\[a, b] -> if b == "JPY" then read a else 380000.0 * read a) . words <$> getLine) :: IO [Double]
    print $ sum ns
    

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

#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
vector<int> dy = {1, 0, -1, 0};
vector<int> dx = {0, 1, 0, -1};
typedef pair<int, int> PII;

int main() {

    string s;
    cin >> s;
    long long ans = 0;
    for(int i = 0; i < static_cast<int>(s.length()); i++){
        ans += (s.at(i) - '0');
    }
    if(ans % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;

}

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

#define io              ios_base::sync_with_stdio(false),cin.tie(NULL);
#define ll              long long
#define vi              vector<int>
#define pii             pair<int, int>
#define vii             vector<pii>
#define mii             map<int, int>

#define pb              push_back
#define ff              first
#define ss              second
#define sz              size()
#define all(a)          a.begin(), a.end()
#define mem(a, b)       memset(a, b, sizeof(a))
#define mod             1000000007
#define inf             1e9
#define c               1.00

int main()
{
    io;
    ll n,k;
    double ans = 0.0;
    cin >> n >> k;
    for(ll i = 1; i <= n; i++)
    {
        ll x = i;
        int steps = 0;
        while(x < k)
        {
            steps++;
            x *= 2;
        }
        ans += pow((1.00/2.00),steps);
    }
    ans /= (n*c);
    printf("%0.12f\n",ans);
}


Measured memory_bytes: 4168
#include <bits/stdc++.h>
#pragma GCC optimize(3,"Ofast","inline")
using namespace std;
int n,dp[2003][2003],a[6003],ans,tg,MX[2003],cur;
int A[100004],B[100004],C[100004],t;
void add(int x,int y,int z){A[t]=x,B[t]=y,C[t++]=z;}
int main(){
	cin>>n;
	for(int i=1;i<=3*n;i++)scanf("%d",&a[i]);
	memset(dp,-1,sizeof(dp));
	memset(MX,-1,sizeof(MX));
	dp[a[1]][a[2]]=dp[a[2]][a[1]]=MX[a[1]]=MX[a[2]]=cur=0;
	for(int i=3;i<3*n;i+=3){
		if(a[i]==a[i+1]&&a[i]==a[i+2]){tg++;continue;}
		t=0;
		if(a[i]>a[i+1])swap(a[i],a[i+1]);
		if(a[i+1]>a[i+2])swap(a[i+1],a[i+2]);
		if(a[i]>a[i+1])swap(a[i],a[i+1]);
		for(int j=1;j<=n;j++){
			if(a[i]==a[i+1])if(dp[j][a[i]]>=0)add(j,a[i+2],dp[j][a[i]]+1);
			if(a[i+1]==a[i+2])if(dp[j][a[i+1]]>=0)add(j,a[i],dp[j][a[i+1]]+1);
		}
		if(dp[a[i]][a[i]]>=0)add(a[i+1],a[i+2],dp[a[i]][a[i]]+1);
		if(dp[a[i+1]][a[i+1]]>=0)add(a[i],a[i+2],dp[a[i+1]][a[i+1]]+1);
		if(dp[a[i+2]][a[i+2]]>=0)add(a[i],a[i+1],dp[a[i+2]][a[i+2]]+1);
		add(a[i],a[i+1],cur),add(a[i+1],a[i+2],cur),add(a[i],a[i+2],cur);
		for(int k=1;k<=n;k++)if(MX[k]>=0)add(a[i],k,MX[k]),add(a[i+1],k,MX[k]),add(a[i+2],k,MX[k]);
		for(int j=0;j<t;j++)if(dp[A[j]][B[j]]<C[j])
			dp[A[j]][B[j]]=dp[B[j]][A[j]]=C[j],MX[A[j]]=max(MX[A[j]],C[j]),MX[B[j]]=max(MX[B[j]],C[j]),cur=max(cur,C[j]);
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++)if(dp[i][j]>=0)ans=max(ans,dp[i][j]);
		if(dp[i][i]>=0)if(i==a[3*n])ans=max(ans,dp[i][i]+1);
	}
	printf("%d",ans+tg);
}


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

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)


const int N = 25;
const int NN = N*N;

class Mat : public vector<vector<int> >{
public:
  void init(int h,int w){
    clear();
    rep(i,h)push_back(vector<int>(w));
  }
  void print(){
    rep(i,size()){
      rep(j,at(i).size())printf("%d ",at(i).at(j));puts("");
    }
  }
};

int haki(Mat& mat){
  int used[NN]={0};
  int y = mat.size();
  int x = mat[0].size();

  int rank = 0;
  rep(i,x){
    rep(j,y){
      if(used[j]==0 && mat[j][i]==1){
	used[j] = 1;
	rank++;

	rep(k,y){
	  if(used[k]==0 && mat[k][i]==1){
	    rep(p,x)mat[k][p]^=mat[j][p];
	  }
	}
      }
    }
  }

  return rank;
}


int w,h,d;
int board[N][N];

bool input(){
  cin>>w>>h>>d;
  if(w==0)return false;

  rep(i,h)rep(j,w)cin>>board[i][j];

  return true;
}


Mat A;
Mat B;
int n;
int solve(){
  n=w*h;
  A.init(n, n);
  B.init(n, n+1);

  rep(i,n){
    rep(j,n){
      int x = i%w;
      int y = i/w;
      int s = j%w;
      int t  = j/w;
      if((x==s && y==t) || abs(x-s)+abs(y-t)==d){
	A[i][j] = 1;
	B[i][j] = 1;
      }
    }
  }

  rep(i,n){
    B[i][n]=board[i/w][i%w];
  }

  //  A.print();
  //B.print();

  int va = haki(A);
  int vb = haki(B);

  //printf("%d : %d\n",va,vb);
  if(va==vb)return 1;
  return 0;
}

int main(){
  while(input())cout<<solve()<<endl;
}

Measured memory_bytes: 4256
#include<cstdio>
#include<map>
using namespace std;
map<int,bool> mp;
int n,a;
bool check;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		if(mp[a])
			check=1;
		else
			mp[a]=1;
	}
	puts(check?"NO":"YES");
	return 0;
}

Measured memory_bytes: 9600
import sys
import heapq
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
inf = 10**18
L = [-(-inf)]
R = [inf]
Lsum = 0
Rsum = 0
const = 0


"""
[], []
[x], []
[x], [y]
[x, z], [y]
...
"""

xmed = None

for _ in range(N):
    f, *arg = map(int, input().split())
    if f == 1:
        a, b = arg
        const += b
        if xmed is None:
            xmed = a
            while -L[0] > xmed or xmed > R[0]:
                while xmed < -L[0]:
                    Lsum += xmed
                    xmed = -heapq.heappushpop(L, -xmed)
                    Lsum -= xmed
                while xmed > R[0]:
                    Rsum += xmed
                    xmed = heapq.heappushpop(R, xmed)
                    Rsum -= xmed
        else:
            if a < xmed:
                a, xmed = xmed, a
            heapq.heappush(L, -xmed)
            heapq.heappush(R, a)
            Lsum += xmed
            Rsum += a
            xmed = None
            while -L[0] > R[0]:
                lx = -heapq.heappop(L)
                rx = heapq.heappop(R)
                heapq.heappush(L, -rx)
                heapq.heappush(R, lx)
                Lsum += rx - lx
                Rsum += lx - rx
    else:
        if xmed is None:
            xres = -L[0]
        else:
            xres = xmed
        F = const
        F += Rsum - xres * (len(R) - 1)
        F += xres * (len(L) - 1) - Lsum
        print(xres, F)

Measured memory_bytes: 17044
from collections import deque
def main():
    s = list(input())

    leftsub = s[0:len(s)//2]
    rightsub = s[len(s)//2+2:-1]

    if isPalindrome(s) and isPalindrome(leftsub) and isPalindrome(rightsub):
        print("Yes")
        return
    print("No")

def isPalindrome(s):
    s_rev = s[::-1]

    for i in range(len(s)//2):
        if s[i]!=s_rev[i]:
            return False

    return True
    


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int cnt = 0;
        int ans = 0;
        
        for(int k=1; k<=n; k+=2){
            for(int i=1; i<=k; i+=2){
                if(k%i == 0){
                    cnt++;
                }
            }
            if(cnt == 8){
                ans++;
            }
            cnt = 0;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23636
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <stdio.h>
using namespace std;
ostringstream oss ;

int main(){
    int n,k;
    int r,s,p;
    string t ;
    cin >> n >> k >> r >> s >> p >> t;
    vector<int> a(t.size(),0);
    int64_t sum = 0;
    for (size_t i = 0; i < k; i++)
    {
        if (t.at(i) == 'r')
        {
            a.at(i) = 1;
            sum += p;
        }
        if (t.at(i) == 's')
        {
            a.at(i) = 1;
            sum += r;
        }
        if (t.at(i) == 'p')
        {
            a.at(i) = 1;
            sum += s;
        }


        
    }
    for (size_t i = k; i < n; i++)
    {
        if (t.at(i) == 'r')
        {
            if (t.at(i-k) == 'r')
            {
                if (a.at(i-k) == 1)
                {
                    a.at(i) = 0 ;
                }else
                {
                    a.at(i) = 1;
                    sum += p;
                }
                
                
            }else
            {
                a.at(i) = 1;
                sum += p;
            }
            
            
        }
        if (t.at(i) == 's')
        {
            if (t.at(i-k) == 's')
            {
                if (a.at(i-k) == 1)
                {
                    a.at(i) = 0 ;
                }else
                {
                    a.at(i) = 1;
                    sum += r;
                }
                
                
            }else
            {
                a.at(i) = 1;
                sum += r;
            }
            
            
        }
        if (t.at(i) == 'p')
        {
            if (t.at(i-k) == 'p')
            {
                if (a.at(i-k) == 1)
                {
                    a.at(i) = 0 ;
                }else
                {
                    a.at(i) = 1;
                    sum += s;
                }
                
                
            }else
            {
                a.at(i) = 1;
                sum += s;
            }
            
            
        }
    }
    
    cout << sum << endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <math.h>
typedef long long ll;
using namespace std;

int main(int argc, char* argv[])
{
    double a,b,x;
    
    cin >> a >> b >> x;
    if(x/a > a*b/2){
        printf("%.10f",atan2(2*(b-x/a/a),a) *180 / acos(-1));
    }else{
        printf("%.10f",atan2(b,2*x/a/b) *180 / acos(-1));
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){

	int N,K,X,Y;
	cin>>N>>K>>X>>Y;
	
	int sum = 0;
	REP(i,N){
		if(i >= K){
			sum+=Y;
		}else{
			sum += X;
		}
	}
	cout<<sum<<endl;
	return 0;
}


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

class Cube{
public:
  int f[6];
  Cube(){}
  void roll_z(){ roll(1, 2, 4, 3);}
  void roll_y(){ roll(0, 2, 5, 3);}
  void roll_x(){ roll(0, 1, 5, 4);}
  void roll(int i, int j, int k, int l){
    int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
  }
  void move(char ch){
    if ( ch == 'E') for ( int i = 0; i < 3; i++ ) roll_y();
    if ( ch == 'W') roll_y();
    if ( ch == 'N') roll_x();
    if ( ch == 'S') for ( int i = 0; i < 3; i++ ) roll_x();
  }
};

int main(){
  Cube c;
  string com;
  
  for ( int i = 0; i < 6; i++ ) cin >> c.f[i];
  cin >> com;
  
  for ( int i = 0; i < com.size(); i++ ) c.move(com[i]);
  
  cout << c.f[0] << endl;
  
  return 0;
}


Measured memory_bytes: 3212
N=int(input())
A=[]
A=list(map(int,input().split()))
B={}
for i in range(N):
    if(str(A[i]) in B):
        B[str(A[i])]+=1
    elif(str(A[i]) not in B):
        B[str(A[i])]=1

ans=0

for key,value in B.items():
    key=int(key)
    if(key<value):
        ans+=(value-key)
    elif(key==value):
        pass
    elif(key>value):
        ans+=value
        
print(ans)

Measured memory_bytes: 23116
L=int(input())
A=[int(input()) for _ in range(L)]

INF=2*L

dp=[[INF for _ in range(5)] for _ in range(L+1)]

for j in range(5):
    dp[0][j]=0

for i in range(1,L+1):
    a=A[i-1]

    if A[i-1]==0:
        o=2
    else:
        o=A[i-1]%2

    e=(A[i-1]+1)%2


    dp[i][0]=dp[i-1][0]+a
    dp[i][1]=min(dp[i-1][0]+o,dp[i-1][1]+o)
    dp[i][2]=min(dp[i-1][0]+e,dp[i-1][1]+e,dp[i-1][2]+e)
    dp[i][3]=min(dp[i-1][0]+o,dp[i-1][1]+o,dp[i-1][2]+o,dp[i-1][3]+o)
    dp[i][4]=min(dp[i-1][0]+a,dp[i-1][1]+a,dp[i-1][2]+a,dp[i-1][3]+a,dp[i-1][4]+a)

print(min(dp[L]))

Measured memory_bytes: 74052
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/* Coding space */
ll ans = 0;

void sep(string str){
  rep(i,str.size()){
    ans += stoll(str.substr(0,i+1))*pow(2,str.substr(i+1).size()-1,LLINF);
    sep(str.substr(i+1));
  }
  return;
}

int main(){
  string s; cin >> s;
  sep(s);
  cout << ans << endl;
}

Measured memory_bytes: 256
N,M = map(int, input().split())
E = []
for _ in range(M):
  a,b = map(int, input().split())
  E.append((a-1,b-1))

## https://note.nkmk.me/python-union-find/
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
###
uf = UnionFind(N)

ans = [0] * (M+1)
ans[M] = N*(N-1) // 2
  
for i in range(M-1,-1,-1):
  a,b = E[i]
  if uf.same(a,b):
    ans[i] = ans[i+1]
  else:
    # union
    _t, _u = uf.size(a), uf.size(b)
    uf.union(a,b)
    #_v = uf.size(a)
    ans[i] = ans[i+1] - _t*_u
  
for i in range(1,M+1):
  print(ans[i])

Measured memory_bytes: 88052
#include <bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
typedef long long ll;

int main()
{
  int N;cin>>N;
  string S;cin>>S;
  string T;
  int count=1;
  for (int i=1;i<N;i++)
  {
    if (S[i]!=S[i-1])
    {
      count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPLL(i, n) for(ll i = 0;i < (n);++i)

#define endl "\n"
#define pb push_back
#define MOD 1000000007LL
#define PI 3.1415926

typedef long long ll;

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T> inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	ll a, b; cin >> a >> b;
	if(a%3==0 or b%3==0){
		cout << 0 << endl;
	} else {
		double ave = (double)(a*b) / 3.0;
		double MIN = 100000.0; ll w, ans, s1, s2, s3;
		for (ll i = 1; i <= a; i++) {
			if(abs((double)(i*b) - ave) < MIN){
				MIN = abs((double)(i*b) - ave);
				w = i; s1 = i*b;
			}
		}
		s2 = (a-w)*(b/2); s3 = (a-w)*(b - b/2);
		ans = max({s1,s2,s3}) - min({s1,s2,s3});

		MIN = 100000.0;
		for (ll i = 1; i <= b; i++) {
			if(abs((double)(i*a) - ave) < MIN){
				MIN = abs((double)(i*a) - ave);
				w = i; s1 = i*a;
			}
		}
		s2 = (b-w)*(a/2); s3 = (b-w)*(a - a/2);
		ans = min(ans, max({s1,s2,s3}) - min({s1,s2,s3}));

		cout << min({ans, a, b}) << endl;
	}

	return 0;
}

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

int main() {
int N ;
    cin >> N ;
  bool ans= false ;
  for (int i=0; i<= N/4; i++){
  if ((N-4*i)%7==0)
	ans= true;
  }
   if(ans==true) cout << "Yes"<< endl; 
    else cout << "No" << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[4];
int main()
{
    bool ok=0;
    for(int i=0;i<4;i++) cin>>s[i];
    for(int i=1;i<4;i++){
        if(s[i]==s[i-1]){
            printf("Bad\n");
            ok=1;
            break;
        }
    }
    if(ok==0) printf("Good\n");
    return 0;
}



Measured memory_bytes: 256
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<lli>
#define mii             map<lli,lli>
#define pqb             priority_queue<lli>
#define pqs             priority_queue<lli,vi,greater<lli> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            lli x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
lli n;
unordered_map < lli, unordered_map <lli, lli> > dp;
lli help(lli idx, lli k, vi& v) {
	if (k == 0) return 0;
	if (idx >= n) return -inf;
	int len = n - idx + 1;
	if (k  * 2 > len) return -inf;
	if (dp.count(idx) && dp[idx].count(k)) return dp[idx][k];
	lli ret ;
	ret = max(help(idx + 1, k, v), v[idx] + help(idx + 2, k - 1, v));

	return dp[idx][k] = ret;
}
void solve() {

	cin >> n;
	vi v(n);
	for (lli i = 0; i < n; i++) cin >> v[i];
	dp.clear();
	cout << help(0, n / 2, v) << endl;
}
int main()
{
	zanj0();
	solve();
	return 0;
}

Measured memory_bytes: 44224
#include<iostream>
using namespace std;
#define MAX 100000

int parent(int i) { return i/2; }
int left(int i) { return 2*i; }
int right(int i) { return 2*i+1; }

int main(){
    int H,i,A[MAX+1];
    
    cin >> H;
    for(i=1;i<=H;i++) cin >> A[i];
    
    for(i=1;i<=H;i++){
        cout << "node " << i << ": key = " << A[i] << ", ";
        if(parent(i)>=1) cout << "parent key = " << A[parent(i)] << ", ";
        if(left(i)<=H) cout << "left key = " << A[left(i)] << ", ";
        if(right(i)<=H) cout << "right key = " << A[right(i)] << ", ";
        cout << endl;
    }
    return 0;
}



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

#define SEP " \r\n"
// https://abc096.contest.atcoder.jp/tasks/abc096_a

//--------------------------------------------------------------
int main(){

	char instr[1000];
	char *sa[2];
	int month, day, i;

	fgets(instr, sizeof(instr), stdin);
	sa[0] = strtok(instr, SEP);
	sa[1] = strtok(NULL, SEP);
	month = atoi(sa[0]);
	day = atoi(sa[1]);

	if(month > day) month--;

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

	return(0);
}


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

int main(){
    int count = 0;
    int digit_num;
    int a[200],b[200];
    int sum;
    while(cin >> a[count] >> b[count]){
        if(a[count] >=0 && a[count] <= 1000000)
            if(b[count] >= 0 && b[count] <= 1000000){
                sum = a[count] + b[count];
                digit_num = 1;
                while((sum/10) != 0){
                    digit_num ++;
                    sum = sum / 10;
                }
                cout << digit_num<<endl;
                count++;
                if(count >200) break;
            }
    }
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    int i;
    long long int n,k,q,a;
    long long int result[100000] = {};
    
    cin >> n >> k >> q;
    
    for(i=0;i<n;i++){
        result[i] = k-q;
    }
    for(i=0;i<q;i++){
        cin >> a;
        a = a-1;
        result[a]++;
    }
    
    
    for(i=0;i<n;i++){
        if(result[i] > 0) cout << "Yes" << endl;
        else cout << "No"<< endl;
    }//
    
    
    
}

Measured memory_bytes: 1408
#include <stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r) {
  int x, i, j, t;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j] <= x) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

int main(void) {
  int i, q;

  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%d",&A[i]);
  q = partition(0,n-1);

  for(i=0; i<n; i++) {
    if(i) printf(" ");
    if(i==q) printf("[");
    printf("%d",A[i]);
    if(i==q) printf("]");
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 2120
#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>;

int main(){
   int a,b,c,d;
   cin >> a >> b >> c >> d;
   bool flag = true;

   while((a>0) && (b>0)){
      c -= b;
      if(c<=0){
         flag = true;
         break;
      }
      a -= d;
      if(a<=0){
         flag = false;
         break;
      }
   }
   if(flag) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;  
}

Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 20){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}


/*
const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}
*/

ll N, K;
bool dp[100010];
void solve(){
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  rep(i, K+1)rep(j, N)if(i-A[j] >= 0 && dp[i-A[j]] == 0){
    dp[i] = 1;
  }
  if(dp[K]){
    cout << "First" << endl;
  }else{
    cout << "Second" << endl;
  }
}

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


Measured memory_bytes: 384
N=gets.to_i
as=gets.split.map(&:to_i)
hash=Hash.new{0}
as.each do |e|
    hash[e]+=1
end
cnt=0
for i in 0..as.max
    j=hash[i-1]+hash[i]+hash[i+1]
    cnt=cnt<j ? j : cnt
end
puts cnt

Measured memory_bytes: 12164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

const int mod = 1e9 + 7;
const int inf = 1e9;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;

struct edge {int from,to,cost;};

int main()
{
    int v,e,r;
    cin >> v >> e >> r;

    edge es[e];

    for(int i = 0; i < e; i++){
        int s,t,c;
        cin >> s >> t >> c;
        es[i].from = s;
        es[i].to = t;
        es[i].cost = c;
    }

    int d[v];
    for(int i = 0; i < v; i++){
        d[i] = inf;
    }
    d[r] = 0;
    
    for(int i = 0; i < v; i++){
        bool update = false;
        for(int j = 0; j < e; j++){
            edge e = es[j];
            if(d[e.from] != inf && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }

        if(!update) break;

        if(i == v-1 && update){
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }

    for(int i = 0; i < v; i++){
        if(d[i] == inf){
            cout << "INF" << endl;
        }else{
            cout << d[i] << endl;
        }
    }
}


Measured memory_bytes: 3116
import java.util.*;

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

    int a = 0; 
    for(int i=0; i<100; i++){
    for(int j=0; j<100; j++){
    if(X==i+j){
        if(Y==2*i+4*j){
        a++;
        }
    }
    }
}
    if(a>0){
	System.out.println("Yes");  
    }else{        
	System.out.println("No");
	}
    }
    
}


Measured memory_bytes: 35776
main = do
  [s] <- map read . words <$> getLine
  let xs = func s
  print $ length xs + 4
  
func :: Int -> [Int]
func 1 = []
func 2 = []
func 4 = []
func x 
  | even x = (x `div` 2) : func (x `div` 2)
  | otherwise = (x * 3 + 1) : func (x * 3 + 1)



Measured memory_bytes: 508
A = int(input())
B = int(input())
C = int(input())
X = int(input())
x = X//50
ans=0
for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if 10*a+2*b+c==x:
        ans+=1
print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;


public class Main {

	//残り数問が結果合わない
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		String strN = sc.next();
		String strA = sc.next();
		String strB = sc.next();
		// 1 <= N <= 10^18
		long N = Long.parseLong(strN);

		//A >= 0
		long A = Long.parseLong(strA);

		//B >= 0
		long B = Long.parseLong(strB);

		boolean flg = false;

		if(A == 0) {
			System.out.println(0);
			return;
		}

		long roop = N / (A+B);
		long amari = N % (A+B);
		if(amari > A) {
			amari = A;
		}

		System.out.println(roop * A + amari);

	}

}


Measured memory_bytes: 22740
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    cin >> n;
    int64_t res = 1, INF = 1000000007;
    for(int i=1; i<n+1; i++){
        res *= i;
        res %= INF;
    }
    cout << res << endl;
}


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

using namespace std;

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

const ll INF=1e18;
const ll mod=1e9+7;

int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    vector<ll> dp1(n+1),dp2(n+1);
    rep(i,n){
        if(s[i]=='W') dp1[i+1]=dp1[i]+1;
        else dp1[i+1]=dp1[i];
    }
    rep(i,n){
        if(s[n-1-i]=='W') dp2[n-1-i]=dp2[n-i]+1;
        else dp2[n-1-i]=dp2[n-i];
    }
    ll ans=INF;
    for(ll i=0;i<=n;i++){
        ll cnt=0;
        ll sw=min(dp1[i],n-i-dp2[i]);
        ll d=dp1[i]-sw;
        if(d) cnt+=d;
        cnt+=n-i-dp2[i]-sw+sw;
        ans=min(ans,cnt);
        //cout << cnt << endl;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6804
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;


int main(){
 string s;cin>>s;
 int K;cin>>K;
 
 char ans = '1';
 for(int i=0;i<K and i<s.size();i++){

     if(s[i] != '1'){ans = s[i];break;}

 }
 
 cout<<ans<<endl;

    return 0;
}

 


Measured memory_bytes: 256
#include <bits/stdc++.h>
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)

#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()

using namespace std;

ll mod = 1e9+7;
inline ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

inline ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

inline ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

inline ll nCr(ll n, ll r) {
    if ( r * 2 > n ) r = n - r;
    ll dividend = 1;
    ll divisor  = 1;
    for ( ll i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return (dividend / divisor);
}

// 因数分解
inline vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}

inline bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

//階乗
inline ll factorialMethod(ll k){
    ll sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

inline ll vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) { // 発見できたとき
        return 1;
    }
    else { // 発見できなかったとき
        return 0;
    }
}

int main(){
    string s;
    cin >> s;
    
    ll ans = 0;
    rep(i, s.size() / 2){
        if(s[i] != s[s.size() - 1 - i]){
            ans ++;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/*
Written By mafailure
*/
//In the name of God
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long 
//#define int long long 
// int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1};
// int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2};
const long long mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef vector< pair< int, int > > vii;
typedef map<int, int> mii;
typedef pair<int, ii> pip;
typedef pair<ii, int> ppi;
#define arrinp(arr,init,final,size,type) type* arr=new type[size];for(int i=init;i<final;i++)cin>>arr[i];
#define cr2d(arr,n,m,t) t**arr=new t*[n];for(int i=0;i<n;i++)arr[i]=new t[m];
#define w(t) int t;cin>>t; while(t--)
#define takeInp(n) int n;cin>>n;
#define fr(i,init,final) for(int i=init;i<final;i++)
#define frr(i,init,final) for(int i=init;i>=final;i--)
#define Fr(i,final) for(int i=0;i<final;i++)
#define Frr(i,first) for(int i=first;i>=0;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define debug(x) cerr<<">value ("<<#x<<") : "<<x<<endl;
#define setb __builtin_popcount
#define lsone(n) (n&(-n))
#define rlsone(n) (n&(n-1))
#define clr(a,b) memset(a,b,sizeof(a))
const int inf= INT_MAX;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>  ordered_set; 
vi init(string s)
{
	istringstream sin(s);
	int n;
	vi arr;
	while(sin>>n)arr.push_back(n);
	return arr;
}
int power(int x, int y,int mod)
{ 
	if(y==0)return 1;
	int u=power(x,y/2,mod);
	u=(u*u)%mod;
	if(y%2)u=(x*u)%mod;
	return u;
    
}
int gcd(int a,int b)
{
	if(a<b)return gcd(b,a);
	return (b==0?a:(a%b?gcd(b,a%b):b));
}
int gcd_e(int a,int b,int &x,int &y)
{
	
	if(b==0){x=1; y=0; return a;}
	int x1,y1;
	int p=gcd_e(b,a%b,x1,y1);
	x=y1;
	y=x1-(a/b)*y1;
	return p;
}
signed main()
{
	IOS
	int k;
	cin>>k;
	if(k%2==0||k%5==0){cout<<-1<<endl; return 0;}
	int num=0;
	int ans=0;
	fr(i,0,k)
	{
		num=num*10+7;
		num%=k;
		ans++;
		if(num%k==0){cout<<ans; return 0;}	
	}
	cout<<-1<<endl;
	
			
	
}



Measured memory_bytes: 3644
#include "bits/stdc++.h"

using namespace std;


signed main(void) {

  int a, b; cin >> a >> b;

  if (a >= 13)
    cout << b;
  else if (a >= 6)
    cout << b / 2;
  else
    cout << 0;
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits//stdc++.h>
using namespace std;
#define int long long
#define rep(i,n,k) for(int i=n;i<k;i++)
#define P make_pair
#define F first
#define S second
#define M LLONG_MAX
signed main(void){
    int n,m,ans,w,p,q;
    ans=0;
    string s;
    cin>>n>>p>>q;
    ans+=n/(p+q);
    ans=ans*p;

    ans+=min((n%(p+q)),p);
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
/*cout <<"Debug"
cout <<x-30<<' '<<y-30<<endl;*/
typedef pair<pair<int ,int>, int> P;
vector<pair<pair<int ,int>, int> > v_ans;
vector<long int>v;
vector<int>v_hana;
/*taro tenn,hanako_ten,sum*/

bool cmp(P h, P r){
  return h.second < r.second;
}
int main(){
  long int N,K,ans = 0,ind = 0;
  cin >>N>>K;

  for(int i = 0;i<N;i++){
    long int x;
    cin >>x;
    v.push_back(x);
  }
  ans = 1;
  ind = K;
  while(ind < N){
    ans++;
    ind += (K-1);
  }
  cout <<ans<<endl;
  return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
const int N=205;
int n,id,D[N],flag,vis[N],fa[N*2];
char a[N][N];
vector<int>g;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
    int x=0,fl=1;char ch=gc();
    for (;ch<48||ch>57;ch=gc())if(ch=='-')fl=-1;
    for (;48<=ch&&ch<=57;ch=gc())x=(x<<3)+(x<<1)+(ch^48);
    return x*fl;
}
int find(int x) {
	if(fa[x]==x)return x;
	fa[x]=find(fa[x]);
	return fa[x];
}
void bfs(int u,int dep) {
	D[u]=dep;
	queue<int>q;
	q.push(u);
	while(!q.empty()) {
		int u=q.front();
		q.pop();
		for(int i=1; i<=n; i++)
			if(a[u][i]=='1'&&!D[i]) {
				D[i]=D[u]+1;
				q.push(i);
			}
	}
}
void dfs(int u) {
	vis[u]=id;
	for(int i=1; i<=n; i++)
		if(a[u][i]=='1'&&(!vis[i]))dfs(i);
}
signed main() {
	n=read();
	for(int i=1; i<=n; i++)
		scanf("%s",a[i]+1);
	if(n==2) {
		cout<<2;
		return 0;
	}
	for(int i=1; i<=n; i++)fa[i]=i,fa[i+n]=i+n;
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			if(a[i][j]=='1') {
				if(find(i)==find(j)||find(i+n)==find(j+n)) {
					puts("-1");
					return 0;
				}
				fa[find(i)]=find(j+n);
				fa[find(j)]=find(i+n);
			}
	int ans=-1;
	for(int i=1; i<=n; i++) {
		g.clear();
		memset(D,0,sizeof(D));
		memset(vis,0,sizeof(vis));
		bfs(i,1);
		id=0;
		for(int j=1; j<=n; j++)
			if(a[i][j]=='1'&&!vis[j]) {
				id++;
				dfs(j);
				int ma=0;
				for(int k=1; k<=n; k++)
					if(vis[k]==id)ma=max(ma,D[k]);
				g.push_back(ma);
			}
		if(g.size()==0)continue;
		sort(g.begin(),g.end());
		if(g.size()==1)ans=max(ans,g[0]);
		else ans=max(ans,g[0]+g[1]-1);
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <utility>

int main(void) {
  int i, j, k, n, m, l, s, t, e;
  scanf("%d%d", &n, &m);
  std::vector< std::pair<int, int> >  v[n];
  std::vector< std::pair<int, int> >::iterator it;
  while( 1 ) {
    scanf("%d%d%d", &s, &t, &e);
    if(!e) break;
    s--, t--;
    std::pair<int, int> p = std::make_pair(t, e);
    v[s].push_back(p);
  }
  scanf("%d", &l);
  for(i = 0; i < l; ++i) {
    int b[m];
    for(j = 0; j < m; ++j) scanf("%d", &b[j]);
    for(j = 0; j < n; ++j) {
      int c = 0;
      for(it = v[j].begin(); it != v[j].end(); ++it) c += b[(*it).first] * (*it).second;
      if(j != n - 1) printf("%d ", c);
      else printf("%d\n", c);
    }
  }
  return 0;
}


Measured memory_bytes: 3760
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline


def DFS(num,parent,point):
    D[num]=point+Q[num]
    for i in M[num]:
        if i!=parent:
            DFS(i,num,D[num])


n,q=map(int,input().split())

M=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    M[a-1] +=[b-1]
    M[b-1] +=[a-1]

Q=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    Q[p-1] +=x

D=[0]*n
DFS(0,-1,0)
print(*D)


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

int main(){
	int a,b,c;
  	cin>>a>>b>>c;
  	vector<int> v;
  	for(int i=1;i<=max(a,b);i++){
    	if(a%i==0&&b%i==0) v.push_back(i);
    }
  	cout<<v[v.size()-c];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
// IO
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
#define pd(a) printf("%d ", a)
#define pld(a) printf("%d\n", a)
#define pda(a, n) fo(i, n) pd(a[i])
#define pl printf("\n")
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b) 
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
// math
const ll mod = 1e9+7;
template<typename T> T gcf(T a, T b) {return (b == 0) ? a : gcf(b, a%b);} 
template<typename T> T lcm(T a, T b) {return (a*b)/gcf(a, b);}
template<typename T> T sumTo(T x) {return x * (x+1) / 2;}
template<typename T> T sumSquaresTo(T x) {return x * (x+1) * (2*x+1) / 6;}
template<typename T> T ceilDiv(T n, T d) {return (n+d-1)/d;}

const int MAXN = 1e5+50;
ll num[MAXN];

void solve() {
    fo(i, MAXN) num[i] = (ll) 0;
    int n; cin >> n;
    ll sum = 0;
    fo(i, n) {
        int ai;
        cin >> ai;
        num[ai]++;
        sum += ai;
    }   
    int q; cin >> q;
    while (q--) {
        int bi, ci; cin>>bi>>ci;
        ll change = num[bi];
        num[ci] += change;
        num[bi] = 0;
        sum += change * (ci-bi);
        cout << sum << '\n';
    }
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4412
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
using namespace std;
typedef long long LL;
const int N=3e5;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
#define x first
#define y second
int x[N],mx[N],f[N];
pair<int,int>p[N];
inline bool cmp(const pair<int,int> &a,const pair<int,int> &b) { return a.y==b.y?a.x<b.x:a.y<b.y; }
int main()
{
	int n=gi(),i,l,r,t,mid,len;
	for (i=1;i<=n;i++) p[i].x=gi(),p[i].y=x[i]=gi();
	sort(x+1,x+1+n);len=unique(x+1,x+1+n)-x-1;
	for (i=1;i<=n;p[i++].y=l) for (l=1,r=len;l!=r;p[i].y<=x[mid=(l+r)>>1]?r=mid:l=mid+1);
	sort(p+1,p+1+n);
	for (i=1;i<=n;i++) mx[i]=max(mx[i-1],p[i].y);
	for (i=n,t=1<<30;i;i--) p[i]=make_pair(t=min(t,p[i].y),mx[i]);
	sort(p+1,p+1+n,cmp);
	const int mod=1e9+7;
	f[0]=1;
	for (i=1;i<=n;i++) {
		for (t=p[i-1].y+1;t<=p[i].y;t++)
			(f[t]+=f[t-1])%=mod;
		t=f[p[i].y];
		if (p[i].x!=1) (t-=f[p[i].x-2])%=mod;
		(f[p[i].y]+=t)%=mod;
	}
	printf("%d\n",((f[len]-f[len-1]+mod)%mod+mod)%mod);
	return 0;
}


Measured memory_bytes: 4864
#include <cstring>
#include <cstdio>

char a[60], s[16][10] = {"KIHBR", "AKIHBR", "KIHABR",
"KIHBAR", "KIHBRA", "AKIHABAR", "AKIHBAR","AKIHBRA",
"KIHABAR", "KIHABRA", "KIHBARA","AKIHABAR",
"AKIHABRA", "AKIHBARA","KIHABARA", "AKIHABARA"};

inline bool check(char *a, char *s) {
	if (strlen(a) != strlen(s)) return 0;
	for (int i = 0; i < strlen(a); i++) {
		if (a[i] != s[i]) return 0;
	}
	return 1;
}

int main() {
    scanf("%s", &a);
	for (int i = 0; i < 16; i++) {
		if (check(a, s[i])) {
			return puts("YES"), 0;
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 128