akhauriyash/Code-Regression huggingface dataset:
"""クラスカル
重み付きグラフの最小全域木(辺の重みの総和が最小になる全域木)
# 全域木：グラフのすべての頂点を含む部分グラフであって、
# 木である限りできるだけ多くの辺を持つもの
クラスカルのアルゴリズム
UnionFindを使う

O(|E|log(V))
"""

class UnionFind():
    """
    UnionFindTreeのクラス
    
    Attributes:
    n: int: ノード数
    parents: そのノードが属する木の根を格納, 根の場合は-1

    """
    def __init__(self, n):
        """ノード数nで初期化"""
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        """ノード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が属するグループと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):
        """xが属するグループの要素数を返す"""
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """x, yが同じグループに属するかどうかを返す"""
        return self.find(x) == self.find(y)

    def members(self, x):
        """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):
        """{root: [そのグループの要素リスト]}の辞書を返す"""
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        """printデバッグ用. root: [要素リスト]をstrで返す"""
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())




def kruskal(edge_list: list, n_V: int):
    """
    クラスカル法
    edge_list: 各要素が(weight, node1, node2)のリスト
    n_V: ノード数
    sortがボトルネックとなりO(|E|log(|E|))
    """
    edge_list = sorted(edge_list) # 重み昇順に整列
    ret = 0
    uf = UnionFind(n_V) # UnionFind
    n_edges = 0
    for w, s, t in edge_list:
        if n_edges == n_V-1: #全域木になったら終了
            break
        if uf.same(s, t):
            #s, tが同じグループの場合,
            #構築するものが木ではなくなってしまう(閉路ができる)
            #のでcontinue
            continue
        
        uf.union(s, t) # s, tを併合
        ret += w
        n_edges += 1
    
    return ret

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

uf = UnionFind(N)
for _ in range(M):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)

print(uf.group_count() - 1)

Measured memory_bytes: 75880
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007ll
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define db(x) cout << #x << " = " << x << '\n'
#define sep cout << "********************************************\n"
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL)
ll n;
ll ans = 0;
ll solve(ll c)
{
	ll low = 0, high = c, mx = 0;
	while (low <= high)
	{
		ll mid = (low + high ) / 2;
		if ((mid * (mid + 1)) / 2 <= c)
		{
			mx = mid;
			low = mid + 1;
		}
		else
			high = mid - 1;
	}
	return mx;
}
int main(int argc, char const *argv[])
{
	fast;
	cin >> n;
	for (ll i = 2; i * i <= n; ++i)
	{
		if (n % i == 0)
		{
			ll c = 0;
			while (n % i == 0)
			{
				n /= i;
				c ++;
			}
			ans += solve(c);
		}
	}
	if (n > 1)
		ans ++;
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  int n,c=0;
  cin>>n;
  reps(i,1,n){
    if(n-i>i)c++;
    else break;
  }
  cout<<c;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define INF 1000000007
int main()
{
	ll n,w;
	cin>>n>>w;
	vector<ll> wt,v;
	ll sum=0;
	for(ll i=0;i<n;i++)
	{
		ll x,y;
		cin>>x>>y;
		wt.push_back(x);
		v.push_back(y);
	}
	for(auto k:v)
		sum+=k;
	vector<ll> dp(sum+1,INF);
	dp[0]=0;
	for(ll i=0;i<n;i++)
	{
		for(ll j=sum-v[i];j>=0;j--)
		{
			dp[j+v[i]]=min(dp[j+v[i]],dp[j]+wt[i]);
		}
	}
	ll ans=0;
	for(ll i=0;i<=sum;i++)
	{
		if(dp[i]<=w)
			ans=max(ans,(long long) i );
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
var k:Int = Int(readLine()!)!
var c:Int = 1
if k % 2 == 0 || k % 5 == 0 {
  c = -1
} else {
  var m:Int = 7
  while m % k != 0 {
    let m2 = m % k
    m = 10*m2 + 7
    c += 1
  }
}
print(c)

Measured memory_bytes: 7688
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define min(p,q)((p)<(q)?(p):(q))
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

ll a[100010];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	sortup(a,n);
	int ans=1e9;
	for(int i=0;i+k-1<n;i++)ans=min(ans,a[i+k-1]-a[i]);
	printf("%d",ans);
}

Measured memory_bytes: 1788
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;

using ll = long long int;

#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;

bool pal(string const& s) {
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] != s[s.size() - 1 - i]) return false;
	}
	return true;
}

bool res() {
	string s;
	cin >> s;
	if (!cin) return false;

	if (pal(s) && pal(s.substr(0, (s.size() - 1) / 2)) && pal(s.substr((s.size() + 1) / 2, (s.size() - 1) / 2))) cout << "Yes\n";
	else cout << "No\n";
	return true;
}

int main() {
	while (res()) {}
	return 0;
}

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

typedef long long ll ; 
typedef unsigned long long ull ; 
typedef vector<int> vi ; 
typedef vector<vi> vii ;
typedef vector<ll> vl ;
typedef vector<vl> vll ;
typedef set<int> si ; 
typedef map<int,int> mii ; 
typedef map<ll,ll>  mll ; 
typedef map<string,int> msi ;
typedef set<ll> sl ; 
typedef set<char> sc ; 
typedef pair<int,int> pii ;


#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
const int INF = 1 << 29 ; 
#define MOD (ll)(1e9+7)
#define eps 1e-6
#define pb push_back 
#define mp make_pair 
#define DEBUG(x)		cout << '>' << #x << ':' << x << endl;
#define F first 
#define S second 

int main() 
{
	ios::sync_with_stdio(0) ;
	int n ;
	cin >> n;
	int W;
	cin >> W;
	int w[n] , v[n];
	REP(i,n) cin >> w[i] >> v[i];
	long long dp[W+5];
	REP(i,W+5) dp[i] = 0;
	for(int i = 0; i < n; ++i) {
		for(int j = W-w[i]; j >= 0; --j) {
			if(j + w[i] > W) break;
			dp[j+w[i]] = max(dp[j+w[i]] , dp[j] + v[i]);
		}
	}
	long long ans = 0;
	for(int i = 0; i <= W; ++i) {
		//cout << dp[i] << " " ;
		ans = max(ans , dp[i]);
	}
	cout << ans << endl;
	return 0 ; 
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace PaizaTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var oneLine = Console.ReadLine().Split(' ').Select(int.Parse);

            var set = new HashSet<int>();
            for (int i = 0; i < oneLine.Count(); i++)
            {
                set.Add(oneLine.ElementAt(i));
            }
 
            Console.WriteLine(set.Count == 2 ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13408
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

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

    int n;
    cin>>n;
    vector<int> num;
    for(int i=0;i<n;i++){
        int s;
        cin>>s;
        num.push_back(s);
    }
    sort(all(num));
    ll sum=0;
    for(int i=0;i<n;i++){
        sum+=num[i];
    }
    cout<<num[0]<<" "<<num[SZ(num)-1]<<" "<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3332
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

const (
	// 初期バッファサイズ
	initialBufSize = 10000
	// バッファサイズの最大値。Scannerは必要に応じこのサイズまでバッファを大きくして各行をスキャンする。
	// この値がinitialBufSize以下の場合、Scannerはバッファの拡張を一切行わず与えられた初期バッファのみを使う。
	maxBufSize = 100000000
)

func main() {
	var wtr = bufio.NewWriter(os.Stdout)
	var scanner = bufio.NewScanner(os.Stdin)
	buf := make([]byte, initialBufSize)
	scanner.Buffer(buf, maxBufSize)
	scanner.Split(bufio.ScanLines)
	var K, N int
	if scanner.Scan() {
		str := scanner.Text()
		cols := strings.Split(str, " ")
		K, _ = strconv.Atoi(cols[0])
		N, _ = strconv.Atoi(cols[1])
	}

	_ = K
	A := make([]int, N)
	if scanner.Scan() {
		str := scanner.Text()
		cols := strings.Split(str, " ")
		for i := 0; i < N; i++ {
			A[i], _ = strconv.Atoi(cols[i])
		}
	}
	var tmp, max int
	max = 0
	for i := 0; i < N; i++ {
		if i == 0 {
			tmp = A[0] + (K - A[N-1])
		} else {
			tmp = A[i] - A[i-1]
		}
		//fmt.Println(tmp)
		if tmp > max {
			max = tmp
		}
	}

	fmt.Fprintln(wtr, K-max)
	_ = wtr.Flush()
}


Measured memory_bytes: 11904
#include<cstdio>
#include<cctype>
#include<unordered_map>
#include<vector>
#include<queue>
using namespace std;
const int N=1e5,M=2e5,P=N+2*M,inf=0x3f3f3f3f;
typedef pair<int,int> pii;
int n,m,tot;
vector<pii>e[P+1];
int dis[P+1];
int read()
{
	int ret=0;
	char c=getchar();
	while(!isdigit(c)) {
		c=getchar();
	}
	while(isdigit(c)) {
		ret=ret*10+c-'0';
		c=getchar();
	}
	return ret;
}
int get_number(int p,int c)
{
	static unordered_map<long long,int>mp;
	long long has=(long long)p<<32|c;
	if(!mp[has]) {
		mp[has]=++tot;
	}
	return mp[has];
}
void dijkstra()
{
	static bool vis[P+1];
	static priority_queue<pii,vector<pii>,greater<pii>>que;
	fill(dis+1,dis+tot+1,inf);
	que.push(pii{dis[1]=0,1});
	while(!que.empty()) {
		int u=que.top().second;
		que.pop();
		if(vis[u]) {
			continue;
		}
		vis[u]=true;
		for(pii e:e[u]) {
			int v=e.first;
			if(dis[u]+e.second<dis[v]) {
				que.push(pii{dis[v]=dis[u]+e.second,v});
			}
		}
	}
	return;
}
int main()
{
	n=read(),m=read();
	tot=n;
	for(int i=1,u,v,c;i<=m;++i) {
		u=read(),v=read(),c=read();
		int uc=get_number(u,c),vc=get_number(v,c);
		e[u].push_back(pii{uc,1}),e[uc].push_back(pii{u,1});
		e[v].push_back(pii{vc,1}),e[vc].push_back(pii{v,1});
		e[uc].push_back(pii{vc,0}),e[vc].push_back(pii{uc,0});
	}
	dijkstra();
	printf("%d\n",dis[n]==inf?-1:dis[n]/2);
	return 0;
}


Measured memory_bytes: 53200
// C++ program to find 3 elements such that max(abs(A[i]-B[j]), abs(B[j]- 
// C[k]), abs(C[k]-A[i])) is minimized. 
  
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define pb push_back  
#define MOD 998244353 
// Driver program 


int main() 
{
  int n;
  cin>>n;
  set <string> s;
  for(int i=1;i<=n;i++){
    string t;
    cin>>t;
    s.insert(t);
  }
  cout<<s.size()<<'\n';
} 

Measured memory_bytes: 19220
#include <stdio.h>

int main(){
   int n,i,x[100],ans,sum,ans2;
 
   scanf("%d",&n);
   for (sum=i=0;i<n;i++) {
      scanf("%d",&x[i]);
      sum+=x[i];
   }
   sum/=n;
   for (ans=i=0;i<n;i++) ans+=(sum-x[i])*(sum-x[i]);
   if (sum>=0) sum++;
   else        sum--;
   for (ans2=i=0;i<n;i++) ans2+=(sum-x[i])*(sum-x[i]);
   if (ans2<ans) ans=ans2;
   printf("%d\n",ans);
   return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=50;
ll N,X,height[MAX_N+5],p_num[MAX_N+5];

ll solve(ll n,ll x){
  ll res;
  if(x==1&&n==0)res=1;
  else if(n==0)res=0;
  else if(x==1)res=0;
  else if(2<=x&&x<=1+height[n-1])res=solve(n-1,x-1);
  else if(x==2+height[n-1])res=p_num[n-1]+1;
  else if(3+height[n-1]<=x&&x<=2+2*height[n-1]) res=solve(n-1,x-(2+height[n-1]))+p_num[n-1]+1;
  else if(x==height[n]) res=p_num[n];
  return res;
}

int main(){
  cin>>N>>X;
  height[0]=1;
  p_num[0]=1;
  for(ll i=0;i<=N;i++){
    height[i+1]=2*height[i]+3;
    p_num[i+1]=2*p_num[i]+1;
  }

  ll ans=solve(N,X);
  cout<<ans<<endl;
  return 0;
}


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

int a,b,pi[233333],pp[233333][2],pf[233333],pl[233333];

int sou(int k,int f,int d)
{
	int i=pi[k],dd; pf[k]=f; pl[k]=1;
	if(k==a) dd=d; else dd=0;
	while(i!=0)
	{
		if(pp[i][0]!=f)
		{
			dd=max(dd,sou(pp[i][0],k,d+1));
			pl[k]=max(pl[k],pl[pp[i][0]]+1);
		}
		i=pp[i][1];
	}
	return dd;
}

int main()
{
	int n; scanf("%d%d%d",&n,&a,&b);
	for(int i=1,j=0; i<n; i++)
	{
		int x,y; scanf("%d%d",&x,&y);
		pp[++j][0]=y; pp[j][1]=pi[x]; pi[x]=j;
		pp[++j][0]=x; pp[j][1]=pi[y]; pi[y]=j;
	}
	int d=sou(b,0,1),t=d%2;
	d=d/2-1;
	for(int i=1; i<=d; i++) a=pf[a];
	printf("%d",pl[a]-1+d+t);
	return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
int main(){
    double n;
    cin >>n;
    if(int(n)%2 == 0){
        cout<< 0.5;
    }
    else{
        double k = ((n+1)/n)*0.5;
        cout << k; 
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 100005
ll counter[mx] = {0};
int main()
{	
	ios_base::sync_with_stdio(0);
	ll n,value,copy,k;
	cin>>n>>k;
	for(int i=1; i<=n; i++){
		cin>>value>>copy;
		counter[value]+=copy;
	}
	ll sum = 0;
	for(int i=0; i<mx; i++){
		sum+=counter[i];
		if(sum>=k){
			cout<<i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a) for(i=0;i<a;i++)
using namespace std;
static const int W = 0;
static const int B = 1;

void dijkstra(int n, vector<vector<int> > &M) {
    int i,u,min;
    vector<int> d(n);
    vector<int> p(n);
    vector<int> color(n);

    rep(i,n){
        d[i] = INT_MAX;
        p[i] = -1;
        color[i] = W;
    }
    d[0] = 0;
    while(true){
        min = INT_MAX;
        rep(i,n){
            if(min > d[i] && color[i] != B) {
                u = i;
                min = d[i];
            }
        }
        if(min == INT_MAX) break;
        color[u] = B;
        rep(i,n){
            if(color[i] != B && M[u][i] + d[u] < d[i]) {
                p[i] = u;
                d[i] = M[u][i] + d[u];
            }
        }
    }
    rep(i,n){
        cout << i << " " << d[i] << endl;
    }
}

int main(void) {
    int i,j,n,u,k,v;
    vector<vector<int> > M;
    cin >> n;
    M.resize(n);

    rep(i,n){
        M[i].resize(n);
    }
    rep(i,n){
        rep(j,n){
            M[i][j] = (1<<21);
        }
    }

    rep(i,n){
        cin >> u >> k;
        rep(j,k){
            cin >> v;
            cin >> M[u][v];
        }
    }
    dijkstra(n,M);
    return 0;
}

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

int main(){
  int t;
  scanf("%d\n",&t);
  char data[t][4];
  int c0 = 0,c1 = 0,c2 = 0,c3 = 0;//AC,WA,TLE,RE
  for(int i = 0;i < t;i++){
    scanf("%s",data[t]);
    if(strcmp(data[t],"AC") == 0){
      ++c0;
    }else if(strcmp(data[t],"WA") == 0){
      ++c1;
    }else if(strcmp(data[t],"TLE") == 0){
      ++c2;
    }else if(strcmp(data[t],"RE") == 0){
      ++c3;
    }
  }
  printf("AC x %d\n",c0);
  printf("WA x %d\n",c1);
  printf("TLE x %d\n",c2);
  printf("RE x %d\n",c3);
  return 0;
}


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

using namespace std;

int main(){
    string s;
    bool isf = 1;
    while(cin >> s) {
        if(isf) {
           isf = 0; 
        } else {
           cout << " ";
        }
        for(int i = 0; i < s.length(); i++)
        {
            if(isalpha(s[i])) {
                if(islower(s[i])) {
                    cout << (char)toupper(s[i]);
                } else if(isupper(s[i])) {
                    cout << (char)tolower(s[i]);
                } else {
                    cout << s[i];
                }
            } else {
                cout << s[i];
            }
        }
    }
    cout << endl;
    
}


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

typedef struct {
 int key;
 struct node *left, *right, *parent;
}node;

node *root, *NIL;


void insert(int k) {
 node* y = NIL, * x = root, * z;
 z = (node*)malloc(sizeof(node));
 z->key = k; z->left = NIL; z->right = NIL;

 while (x != NIL) {
  y = x;
  if (k < x->key) {
   x = x->left;
  }
  else {
   x = x->right;
  }
 }
 z->parent = y;

 if (y == NIL) root = z;
 else {
  if (k < y->key) {
   y->left = z;
  }
  else {
   y->right = z;
  }
 }
}

void search(int key) {
  node* copy = root;

 while (copy!= NIL) {
  if (copy->key == key)
{   printf("yes");
   return;
  }
  
    if (key < copy->key) copy = copy->left;
  else copy= copy->right;
  
 }
   printf("no");
 

}

void inOrder(node* input_node) {
 if (input_node == NIL)return;
 inOrder(input_node->left);
 printf(" %d", input_node->key); //from note put space before number
 inOrder(input_node->right);
}
void preOrder(node* input_node) {
 if (input_node == NIL)return;
 printf(" %d", input_node->key);
 preOrder(input_node->left);
 preOrder(input_node->right);
}

int main() {
 int i;
 int n;
 int A[500000];
 scanf("%d", &n);
 char function[258];
 char str1[]="insert";
  char str2[]="print";
  char str3[]="find";
 

 for (i = 0; i<n; i++)
  {
      scanf("%s", function);
    if (strcmp(function, str1) == 0)
     {
        scanf("%d", &A[i]);
        insert(A[i]);
  }
  if (strcmp(str3, function) == 0)
   {
       scanf("%d", &A[i]);
       search(A[i]);
       printf("\n");
  }
  if (strcmp(str2, function) == 0) 
  {
      inOrder(root);
      printf("\n");
      preOrder(root);
      printf("\n");
  }
 }

 return 0;
}



Measured memory_bytes: 22416
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  int mn = min(A, B);
  int mx = max(A, B);
  cout << ((mn < C && C < mx) ? "Yes" : "No") << endl;
  return 0;
}

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

int main(){
    int h,a;
    cin>>h>>a;
    int ans=h/a;
    if(h%a!=0)ans++;
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(10000000); // n! mod M
vector<ll> ifac(10000000); // k^{M-2} mod M

ll mpow(ll x, ll n){ // x^n(modM)
    ll ans = 1;
    while (n!=0) {
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n= n>>1;
    }
    return ans;
}

ll comb(ll a, ll b) { // aCb mod M
    if (a==0 && b==0) return 1;
    if (a<b || a<0) return 0;
    ll tmp = ifac[a-b] * ifac[b] % M;
    return tmp * fac[a] % M;
}

int fact(int n) {
    int ans = 1;
    for(int i=1;i<=n;i++) ans*=i;
    return ans;
}

int main() {

    fac[0] = 1;
    ifac[0] = 1;
    for (ll i=0;i<10000000;i++) {
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i] * mpow(i+1, M-2) % M; // k^{M-2} mod M
    }

    ll X, Y;
    cin >> X >> Y;
    if((X+Y)%3!=0 || (2*X-Y)%3!=0 || (X-2*Y)%3 != 0 || (2*X-Y)<0 || (2*Y-X) < 0){
        cout << 0 << endl;
        return 0;
    }
    ll n, m;
    n = (2*X-Y)/3;
    m = (2*Y-X)/3;
    cout << comb(n+m, n) << endl;
    return 0;
}

Measured memory_bytes: 156544
#include"bits/stdc++.h"
using namespace std;
typedef long long LL;
LL n,m;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    while(cin >> n >> m){
        LL ans=0;
        if(n*2>=m){
            cout << m/2 << endl;
        }
        else{
            cout << n+(m-2*n)/4 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <string.h>
#include<math.h>
#include<iostream>
using namespace std;

int main()
{
    int K;
    double x, y;
    int a = 0;
    int ans = -1;
    int count = 1;


    cin >> K;

    if (K % 2 == 0 || K % 5 == 0)
        cout << ans << endl;
    else {
        while (1) {
            a = 10 * a + 7;
            if (a % K == 0)
                break;

            a %= K;
            count++;
        }

        cout << count << endl;
    }

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#ifdef DEBUG
#define display(x) cerr << #x << " = " << x << endl;
#define displaya(a, st, n)\
	{cerr << #a << " = {";\
	for(int qwq = (st); qwq <= (n); ++qwq) {\
		if(qwq == (st)) cerr << a[qwq];\
		else cerr << ", " << a[qwq];\
	} cerr << "}" << endl;}
#define displayv(v) displaya(v, 0, (int)(v).size() - 1)
#endif
template<typename T> bool chmin(T &a, const T &b) { return a > b ? a = b, true : false; }
template<typename T> bool chmax(T &a, const T &b) { return a < b ? a = b, true : false; }

vector<LL> d;
void factor(LL n) {
	d.push_back(1);
	auto add = [&](LL p, int k) {
		int sz = d.size();
		for(int i = 0; i < sz; ++i) {
			d.push_back(d[i] * p);
			for(int j = 1; j < k; ++j)
				d.push_back(d.back() * p);
		}
	};
	for(LL i = 2; i * i <= n; ++i) if(n % i == 0) {
		int cnt = 0;
		while(n % i == 0) n /= i, cnt++;
		add(i, cnt);
	}
	if(n > 1) add(n, 1);
}

int main() {
	ios::sync_with_stdio(false);
	LL n; cin >> n;
	factor(n);
	LL cnt = 0;
	for(LL x : d) if(x > 1) {
//		cout << "test " << x << endl;
		LL cand = x - 1;
		if(n / cand == n % cand) cnt += cand;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	X, A := sc.NextInt(), sc.NextInt()
	if X < A {
		fmt.Println(0)
	} else {
		fmt.Println(10)
	}
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int p,q,r;
  cin>>p>>q>>r;
  cout << min(p+q,min(q+r,r+p)) << endl;
  return 0;
}


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

using namespace std;

using ll = long long;
const int N = 1e5 + 5;

string s;

int main()
{
    std::ios::sync_with_stdio(false);

    while ( cin >> s )
    {
        int tmp = 0;
        int ans = 1000;
        int num = (s[0]-'0')*100 + (s[1]-'0')*10 + s[2]-'0';

        ans = min(ans, abs(num-753));

        for (int i = 3; i < s.size(); i++)
        {
            num -= (s[i-3]-'0')*100;
            num *= 10;
            num += s[i]-'0';
            ans = min(ans, abs(num-753));
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;

int ans=0;
int n;

void dfs(ll a=0,int b=0){

    if(a<=n){
        if(b==7)ans++;
    }
    else return;

    for(int last=3;last<=7;last+=2){
        a=a*10+last;
        if(last==3)dfs(a,b|1);
        if(last==5)dfs(a,b|2);
        if(last==7)dfs(a,b|4);
        a/=10;
    }
}

int main(){
    cin>>n;
    dfs(0,0);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	ll N, L, T;
	cin >> N >> L >> T;

	vll X(N), W(N);
	for (ll i = 0; i < N; i++) {
		cin >> X[i] >> W[i];
	}

	// i番目の蟻とすれ違う回数
	vll count(N);
	count[0] = 0;
	ll sum = 0;

	for (ll i = 1; i < N; i++) {

		if (W[0] == 1) {

			if (W[0] != W[i]) {
				ll dis = X[i] - X[0];
				if (dis < 0) {
					dis += L;
				}

				count[i] = (2 * T - dis + L - 1) / L;

			}
		}
		else {

			if (W[0] != W[i]) {
				ll dis = X[0] - X[i];
				if (dis < 0) {
					dis += L;
				}

				count[i] = (2 * T - dis) / L + ll(dis <= 2 * T);

			}

		}
	}

	if (W[0] == 1) {
		for (ll i = 0; i < N; i++) {
			sum += count[i];
			sum %= N;
		}
	}
	else {

		for (ll i = 0; i < N; i++) {
			sum -= count[i];
			sum %= N;
		}
	}

	sum %= N; // ゼッケンの番号
	if (sum < 0) {
		sum += N;
	}

	ll x;// ゼッケンがsumの蟻の座標
	if (W[0] == 1) {
		x = (X[0] + T) % L;
	}
	else {
		x = (X[0] - T) % L;
		if (x < 0) {
			x += L;
		}
	}


	// すべての蟻の座標
	vll new_X(N);
	for (ll i = 0; i < N; i++) {
		if (W[i] == 1) {
			new_X[i] = (X[i] + T) % L;
		}
		else {
			new_X[i] = (X[i] - T) % L;
			if (new_X[i] < 0) {
				new_X[i] += L;
			}
		}
	}

	sort(new_X.begin(), new_X.end());

	// 
	auto Iter1 = lower_bound(new_X.begin(), new_X.end(), x);
	ll sum_idx = Iter1 - new_X.begin();

	vll ans(N);
	for (ll i = 0; i < N; i++) {
		ans[(i + sum) % N] = new_X[(sum_idx + i) % N];
	}

	for (ll i = 0; i < N; i++) {
		cout << ans[i] << endl;
	}


}


Measured memory_bytes: 5120
#include <stdio.h>

int main(){
    int n, l;
    int i, j, sum=0, sumn=0, sa, ans, samin=500;

    scanf("%d %d", &n, &l);

    for(i=0; i<n; i++){
        sum += l + i;
    }

    for(i=0; i<n; i++){
        sumn = 0;
        
        for(j=0; j<n; j++){
            if(i != j)
                sumn += l + j;
        }

        sa = sum - sumn;
        if(sa < 0)
            sa *= -1;

        if(samin > sa){
            samin = sa;
            ans = sumn;
        }
    }

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

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
vi dp;
vector<vi> G;

bool dfs2(int v, int c){
    if(dp[v] >= 0){
        return (dp[v] != c);
    }
    dp[v] = c;

    bool ret = true;
    for(auto& nv : G[v]){
        ret &= dfs2(nv, c);
    }
    dp[v] = inf;
    return ret;
}

int dfs(int v){
    int& ret = dp[v];
    if(ret >= 0) return ret;

    ret = 0;
    for(auto& nv : G[v]){
        chmax(ret, 1 + dfs(nv));
    }

    return ret;
}

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

    int m; cin >> m;
    vector<vi> A(m, vi(m-1));
    rep(i, m) rep(j, m-1) cin >> A[i][j], A[i][j]--;

    using Pa = tuple<int, int>;
    map<Pa, int> dic;
    int n = 0;
    rep(i, m){
        rep(j, i+1, m){
            dic[Pa(i, j)] = n;
            dic[Pa(j, i)] = n++;
        }
    }
    assert(n == m * (m - 1) / 2);

    G = vector<vi>(n);
    vi n_in(n);
    rep(i, m){
        rep(j, 1, m-1){
            int u = dic[Pa(i, A[i][j-1])];
            int v = dic[Pa(i, A[i][j])];
            G[u].emplace_back(v);
            n_in[v]++;
        }
    }

    dp = vi(n, -1);
    bool ok = true;
    rep(v, n){
        if(n_in[v] == 0){
            ok &= dfs2(v, v);
        }
    }
    for(auto& e : dp){
        ok &= (e >= 0);
    }
    if(not ok){
        cout << -1 << endl;
        return 0;
    }

    dp = vi(n, -1);
    int res = 0;
    rep(v, n){
        if(n_in[v] == 0){
            int cur = dfs(v) + 1;
            chmax(res, cur);
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 99968
#include <iostream>
#include <cstdio>                                               //scanf,printf
#include <algorithm>                                            //max,min
#include <string>                                               //string
#include <cstring>                                              //strlen,strcat
#include <cctype>                                               //isalpha,tolower
#include <cmath>                                                //sqrt,sin
#include <stack>                                                //top,push
#include <queue>                                                //fornt,push
#include <vector>                                               //push_back,sort
#include <set>                                                  //insert,begin
#include <map>                                                  //insert,find
#include <list>                                                 //push_front,begin
using namespace std;


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

int main(){
    int n;
    cin>>n;
    int candy[3][101],pick[3][101]={0};
    for(int i=0; i<2; i++){
        for(int j=1; j<=n; j++){
            cin>>candy[i+1][j];
        }
    }
    pick[1][1]=candy[1][1];
    pick[2][1]=candy[1][1]+candy[2][1];
    for(int i=1; i<=2; i++){
        if(i==1){
            for(int j=2; j<=n; j++){
                pick[i][j]=pick[i][j-1]+candy[i][j];
            }
        }else if(i==2){
            for(int j=2; j<=n; j++){
                int a;
                a=max(pick[i][j-1],pick[i-1][j]);
                pick[i][j]=a+candy[i][j];
            }
        }
    }
    cout<<pick[2][n]<<endl;
}

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

int main(){
  int N, K, a1, a2, a = 1;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    a1 = a * 2;
    a2 = a + K;
    if(a1 < a2){
      a = a1;
    }
    else{
      a = a2;
    }
  }
  cout << a << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int t;
    cin>>t;
    int cnt=0;
    while(t--){
    	int n;
    	cin>>n;
    	while(n%2==0){
    		n/=2;
    		++cnt;
    	}
    }
    cout<<cnt;
   	return 0;
}

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

namespace AC {
#define ll long long
#define PLL pair<ll, ll>
#define PDD pair<double, double>
#define PDPLL pair<double, PLL>
#define PLPLL pair<ll, PLL>
#define pb push_back
#define fi first
#define se second
#define ls rt << 1
#define rs rt << 1 | 1

    const ll N = 1e5 + 66;

    ll BUGS = 1;

    inline ll read(){
        ll x = 0;    bool flag = 1;   char ch = getchar();
        while(ch < '0' || ch > '9') { if(ch == '-') flag = 0; ch = getchar(); }
        while(ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); }
        if(flag) return x;  return (~(x - 1));
    }

    inline void read(ll arr[], ll s, ll e) { for(ll i = s; i <= e; ++i) arr[i] = read(); }

    inline void write(ll x){
        if(x < 0) { x = ~(x - 1); putchar('-'); }
        if(x > 9) write(x / 10); putchar(x % 10 + '0');
    }

    inline void print(ll x) { write(x); puts(""); }

    inline void print(ll arr[], ll s, ll e) {
        for(ll i = s; i <= e - 1; ++i) write(arr[i]), putchar(' ');
        write(arr[e]); puts("");
    }

    inline ll max3(ll a, ll b, ll c) { return max(a, max(b, c)); }

    inline ll min3(ll a, ll b, ll c) { return min(a, min(b, c)); }

    inline void debugNum(ll num, string ss) { cout << "BUGS" << BUGS++ << " : " << ss << " : " << num << endl; }

    inline void debugArr(ll arr[], ll s, ll e, string ss) {
        cout << "BUGS" << BUGS++ << " : " << ss << " : " << endl;
        for(ll i = s; i <= e; ++i) cout << "i : " << i << " val : " << arr[i] << endl;
    }

    inline void IO() {
        //ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
        //cout << setiosflags(ios::fixed) << setprecision(1); //保留小数点后1位
        //cout << setprecision(1); //保留1位有效数字
//        freopen("in.txt", "r", stdin);
//        freopen("out.txt", "w", stdout);
    }
}using namespace AC;

ll n;

int main() {
    IO();
    while(cin >> n) {
        map<string, ll> MM;
        for(ll i = 1; i <= n; ++i) {
            string ss;
            cin >> ss;
            MM[ss]++;
        }

        printf("AC x %lld\n", MM["AC"]);
        printf("WA x %lld\n", MM["WA"]);
        printf("TLE x %lld\n", MM["TLE"]);
        printf("RE x %lld\n", MM["RE"]);
    }
    return 0;
}



Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int N,M;
  cin>>N>>M;
  
  int Nan=N*(N-1)/2;
  int Man=M*(M-1)/2;
  int ans=Nan+Man;
  cout<<ans<<endl;
}

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

int main(){
#ifdef _DEBUG
	freopen("in" , "r", stdin );
	freopen("out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int a, b, c; cin >> a >> b >> c;
	if(a + b == c || a + c == b || b + c == a) cout << "Yes\n";
	else cout << "No\n";
}


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

bool allLettersSame(string s){
  for(int i=0; i<s.size(); i++){
    if(s[i] != s[0]) return false;
  }
  return true;
}

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

  long long k;
  cin >> k;

  if(allLettersSame(s)){
    cout << k * s.size() / 2;
    return 0;
  }

  long long ans = 0;
  int kiri = 0, kanan = 0;

  vector<int> counter;
  while(kiri < s.size()){
    while(kanan + 1 < s.size() && s[kiri] == s[kanan+1])
      kanan++;
    ans += (kanan - kiri + 1)/2;
    counter.push_back(kanan-kiri+1);
    kiri = kanan+1;
    kanan = kiri;
  }
  ans *= k;

  if(s[0] == s[s.size()-1] && counter[0]%2 == 1 && counter.back()%2==1){
    ans += k-1;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> ca(n);
  
  for(int i=0;i<n;i++){
    cin >> a[i];
    ca[i]=a[i];
  }
  sort(a.begin(),a.end(),greater<int>());
  for(int i=0;i<n;i++){
    if(ca[i]==a[0])cout << a[1]<<endl;
    else cout<<a[0]<<endl;
  }
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"
typedef long long ll;


int main(){
    int N, a, Q, l, r, ans;
    string S, i, c;
    cin >> N >> S >> Q;
    vector<set<int>> st(26);
    REP(i,N){
        st[S[i]-97].insert(i+1);
    }
    REP(_,Q){
        cin >> a >> i >> c;
        if (a == 1){
            int k = stoi(i);
            REP(j,26){st[j].erase(k);}
            st[c[0]-97].insert(k);
        }else{
            ans = 0; l = stoi(i); r = stoi(c);
            REP(j,26){
                ans += (st[j].lower_bound(l)!=st[j].lower_bound(r+1));
            }
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 26244
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, x;
  int a[105];
  cin>>n >> x;
  for (int i=0; i < n; i++) cin>>a[i];
  sort(a,a+n);
  int cnt = 0;
  while (x >= a[cnt] && cnt < n-1){
    x -= a[cnt++];
  }
  if (cnt==n-1 && x == a[cnt]) cnt++;
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();
		int max = A + B;
		if(A - B > max){
			max = A - B;
			if(A * B > max){
				max = A * B;
			}
		}else if(A * B > max){
			max = A * B;
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 22608
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
std::vector<ll> G[10010];
ll c[10010];
ll deg[10010];
ll ans[10010];

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

  rep( i, N-1 ) {
    ll a, b;
    std::cin >> a >> b;
    --a; --b;

    G[a].emplace_back( b );
    G[b].emplace_back( a );

    ++deg[a];
    ++deg[b];
  }

  rep( i, N )
    std::cin >> c[i];

  std::sort( c, c+N );

  std::priority_queue<P, std::vector<P>, std::greater<P>> pque;

  rep( i, N )
    pque.emplace( deg[i], i );

  ll score = 0;
  ll ptr = 0;

  while( !pque.empty() ) {
    P p = pque.top(); pque.pop();

    if( p.first > deg[p.second] || ans[p.second] )
      continue;

    if( ptr >= N )
      break;

    ll v = p.second;

    ans[v] = c[ptr];
    score += deg[v]*c[ptr];

    ++ptr;

    for( auto u : G[v] )
    {
      --deg[u];

      pque.emplace( deg[u], u );
    }
  }

  std::cout << score << std::endl;

  rep( i, N )
    std::cout << ans[i] << (i==N-1?'\n':' ');

  return 0;
}

Measured memory_bytes: 1796
import itertools as it

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

ar = [[0]*4]*q

for i in range(q):
    ar[i] = [int(s) for s in input().split()]

A = list(it.combinations_with_replacement(list(range(1,m+1)),n))
mx = 0

for cnd in A:
    mx_tmp=0
    for i in range(q):
        if(cnd[ar[i][1]-1] - cnd[ar[i][0]-1] == ar[i][2]):
            mx_tmp += ar[i][3]
    mx = max(mx,mx_tmp)

print(mx)

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

int main() {
  int N;
  cin >> N;
  
  for ( int i = 0 ; i < N ; i++ ) {
    string S;
    cin >> S;
    
    if ( S == "Y" ){
      cout << "Four" << endl;
      break;
    }
    else if ( i == N - 1 ) {
      cout << "Three" << endl;
    }
  }
}


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

int main()
{
    int64_t n,sum=0;
    cin>>n;
    vector<int64_t>x(n);
    REP(i,n){cin>>x[i];sum+=x[i];}
    sort(x.begin(),x.end());
    cout<<x[0]<<" "<<x[x.size()-1]<<" "<<sum<<endl;
}



Measured memory_bytes: 3192
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    int N,p[20],M=0,sum=0;cin>>N;
    for(int i=0;i<N;++i){
        cin>>p[i];
        sum+=p[i];
        M=max(M,p[i]);
    }
    sum-=M;
    M/=2;
    sum+=M;
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input()) for _ in range(n)]
  
    s=sum(a[0:k])
    ss=[s]
 
    for i in range(k,n):
            
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))


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

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

  int k = 15 - s.length();
  int w, l = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'o') {
      w++;
    }
    if (s[i] == 'x') {
      l++;
    }
  }

  if (k >= 8 - w) {
    cout << "YES" << "\n";
  } else {
    cout << "NO" << "\n";
  }
}


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

int n, k;
int ans = 0;
int psum[200005];
int tree[800005];
ii tmp[200005];

void upd(int id, int l, int r, int i)
{
    if (i < l || i > r)
        return;
    if (l == r)
    {
        if (l == i)
            tree[id]++;
        return;
    }

    int mid = (l + r) / 2;
    upd(id*2, l, mid, i);
    upd(id*2 + 1, mid+1, r, i);
    tree[id] = tree[id*2] + tree[id*2 + 1];
}

int get(int id, int l, int r, int u, int v)
{
    if (v < l || r < u)
        return 0;

    if (u <= l && r <= v)
        return tree[id];

    int mid = (l + r) / 2;
    return get(id*2, l, mid, u, v) + get(id*2 + 1, mid+1, r, u, v);
}

void compress()
{
    int last = 1e18, cnt = 0;
    sort(tmp, tmp + n + 1);
    for (int i = 0; i <= n; i++)
    {
        if (last != tmp[i].fi)
        {
            cnt++;
            last = tmp[i].fi;
        }
        psum[tmp[i].se] = cnt;
    }
}

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

//    freopen("depart.inp", "r", stdin);
//    freopen("depart.out", "w", stdout);

    cin >> n >> k;
    int sum = 0;

    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        psum[i] = psum[i-1] + x - k;
        tmp[i].fi = psum[i];
        tmp[i].se = i;
    }
    compress();

    for (int i = 0; i <= n; i++)
    {
        ans += get(1, 0, n, 0, psum[i]);
        upd(1, 0, n, psum[i]);
    }
    cout << ans;
}


Measured memory_bytes: 12384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; ++i) cin >> d[i];

    sort(d.begin(), d.end());
    int idx = (n - 1)/ 2;
    int left = d[idx];
    int right = d[idx + 1];
    int ans = right - left;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.20f\n", ans); あれ
// const double PI = 3.141592653589793238462643383;


int main() {
  int l,r,d; cin>>l>>r>>d;
  int cnt = 0;
  for(int i=l; i<=r; i++) {
    if (i%d==0) cnt++;
  }
  cout << cnt << endl;

}


Measured memory_bytes: 3136