akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define MOD 1000000007
#define CAP 10000000
#define inf 1000000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(v) v.size()
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}
#define dbg(x) cout <<#x<<":"<<x<<endl;
 
#define int ll

vector<int> lazy(400005,inf);
void buildTree(int *tree,int start,int end,int node){
	if(start==end) {
		if(start==0) tree[node] = 0;
		else tree[node]=inf;
	}
	else if(start<end){
		int mid=(start+end)/2,left=2*node+1,right=left+1;
		buildTree(tree,start,mid,left);
		buildTree(tree,mid+1,end,right);
		tree[node]=min(tree[left],tree[right]);
	}
	lazy[node] = inf;
}
void update(int *tree,int start,int end,int l,int r,int dif,int node){
	// cout<<"#"<<start<<" "<<end<<" -- "<<dif<<endl;
	if(lazy[node]!=inf){
		// there are pending updates
		tree[node]=min(lazy[node],tree[node]);
		if(start!=end){
			lazy[2*node+1]=min(lazy[2*node+1],lazy[node]);
			lazy[2*node+2]=min(lazy[2*node+2],lazy[node]);
		}
		lazy[node]=inf;
	}
	if(start> r or end<l)return;
	else if(start>=l and end<=r){
		lazy[node] = min(lazy[node], dif);
		tree[node]=min(tree[node],dif);	// make the update for the current range and keep them pending for the child nodes
		if(start!=end){
			lazy[2*node+1]=min(lazy[2*node+1],lazy[node]);
			lazy[2*node+2]=min(lazy[2*node+2],lazy[node]);
		}
		return;
	}
	int mid=(start+end)/2;
	update(tree,start,mid,l,r,dif,2*node+1);
	update(tree,mid+1,end,l,r,dif,2*node+2);
	tree[node]=min(tree[2*node+1],tree[2*node+2]);
}
int queryMin(int *tree,int start,int end,int l,int r,int node){
	if(lazy[node]!=inf){
		// if there are updates pending, apply them before making the queries
		tree[node]=min(lazy[node],tree[node]);
		if(start!=end){
			lazy[2*node+1]=min(lazy[2*node+1],lazy[node]);
			lazy[2*node+2]=min(lazy[2*node+2],lazy[node]);
		}
		lazy[node]=inf;
	}
	if(start>r or end<l)return inf;
	else if(start>=l and end<=r)return tree[node];
	else{
		int mid=(start+end)/2,left=2*node+1,right=left+1;
		return min(queryMin(tree,start,mid,l,r,left),queryMin(tree,mid+1,end,l,r,right));
	}
}

signed main() {
	fast;

	int n,m;
	cin>>n>>m;

	vector<pair<pii,int>> edge(m);
	for(int i=0;i<m;i++) cin>>edge[i].f.f>>edge[i].f.s>>edge[i].s, edge[i].f.f--, edge[i].f.s--;

	int tree[400005];
	buildTree(tree,0,n-1,0);

	sort(all(edge));

	for(int i=0;i<m;i++){
		int val = queryMin(tree, 0,n-1,edge[i].f.f,edge[i].f.f,0) + edge[i].s;
		// cout<<"$$"<<val<<endl;
		update(tree, 0,n-1,edge[i].f.f,edge[i].f.s,val,0);
	}
	int ans = queryMin(tree,0,n-1,n-1,n-1,0);
	if(ans==inf) cout<<-1;
	else cout<<ans;
}

Measured memory_bytes: 8576
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int N=500010;
int n;
char buf[N];
int o[N];
vector<PII> x[N];
int dp[N];

void pre() {
    if (n<3) return;
    if (buf[0]=='1') o[1]=1;
    if (buf[1]=='1') o[2]=o[1]+1;
    for (int i=2;i<n;i++) {
        if (buf[i]=='1') {
            o[i+1]=o[i]+1;
            if (o[i]==0) {
                for (int j=0;j<o[i-1];j++) {
                    x[i+1].pb(mp(j+1,i-2-j));
                }
            } else {
                int pos=i-o[i];
                if (pos>1&&o[pos-1]>0) x[i+1].pb(mp(o[i+1],pos-2));
            }
        }
    }
}

int main()
{
    scanf("%d",&n);
    scanf("%s",buf);
    pre();
    for (int i=3;i<=n;i++) {
        dp[i]=dp[i-1];
        for (auto& entry:x[i]) {
            dp[i]=max(dp[i],dp[entry.second]+entry.first);
        }
    }
    printf("%d\n",dp[n]);
}

Measured memory_bytes: 37248
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

int main(){
    ll A;
    double B;
    cin >> A >> B;

    ll b2 = (B+0.001)*100;
    // cout << b2 << endl;

    ll ans = A * b2 / 100;

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

    return 0;
}


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

int main(){
  int a,b,k;
  vector<int> map;
  cin >> a >> b >> k;
  for(int i=min(a,b); i>0; --i){
    if(a >=i && b >= i && a%i == 0 && b%i ==0){
      map.push_back(i);
    }
  }
  cout << map[k-1] << endl;
}


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

int main()
{
  string S,T ;
  cin>>S ;
  cin>>T ;
  int ans=0 ;
  for(int i=0;i<3;i++){
    if(S[i]==T[i]) ans++ ;
  }
  cout<<ans ;
    
  return 0 ;
}


Measured memory_bytes: 256
#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>;
using Graph = vector<vector<int>>;

int main() {
    int n,m;
    cin >> n >> m;
    vector<P> p(m);
    rep(i,m) cin >> p[i].first >> p[i].second;
    sort(p.begin(),p.end());
    int ans=m, l=p[0].first, r=p[0].second;
    for(int i=1; i<m; ++i){
        if(r<=p[i].first){
            l=p[i].first;
            r=p[i].second;
        }
        else{
            if(r>p[i].second){
                l=p[i].first;
                r=p[i].second;
                --ans;
            }else{
                l=p[i].first;
                --ans;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
import sys
for line in sys.stdin.readlines():
  c1,c2,c3 = line.split()
  c1,c2,c3 = int(c1),int(c2),int(c3)
  l = [i for i in range(1,11) if i != c1 and i != c2 and i != c3]
  s = c1 + c2
  count = 0
  for i in l:
    if s + i <= 20:
      count += 1
  if count >= 4:
    print('YES')
  else:
    print('NO')

Measured memory_bytes: 7636
import numpy as np


# 約数の列挙
def make_divisors(n):
    divisors = set()
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.add(i)
            divisors.add(n // i)
    return sorted(list(divisors))


N, K, *A = map(int, open(0).read().split())

A = np.array(A, np.int64)
d = make_divisors(A.sum())

for i in d[::-1]:
    r = A % i
    r = r[r.nonzero()]
    l = r.size
    if l == 0:
        print(i)
        exit()
    else:
        n = np.arange(l - 1, 0, -1)
    r.sort()
    np.cumsum(r, out=r)
    if np.any((r[:-1] == i * n - (r[-1] - r[:-1])) & (r[:-1] <= K)):
        print(i)
        exit()


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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

const int mod = 1000000007;

int n, c[200005];
int dp[200005], sum_dp_col[200005];

int main(){
	scanf("%d", &n);
	dp[0] = 1;
	for(int i = 1; i <= n; i++){
		scanf("%d", &c[i]);
		dp[i] = dp[i - 1];
		if(i == 1 || (c[i] != c[i - 1])){
			dp[i] += sum_dp_col[c[i]];
			dp[i] %= mod;
			sum_dp_col[c[i]] = dp[i];
		}
	}
	printf("%d\n", dp[n]);
	return 0;
}

Measured memory_bytes: 2560
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

H,W = LI()

if W == 1 or H == 1:
    print(1)
    exit()
else:
    x = ((W+1)//2)*((H+1)//2)
    y = (W//2)*(H//2)
    print(x+y)

Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>

using namespace std;

typedef long long ll;

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

  ll ans = N*100/108;

  if(N*100%108!=0)
    ans++;

  
  if(ans*108/100==N)
    cout << ans <<endl;
  else
    cout << ":(" << endl;



  return 0;
}


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

using namespace std;

string s;

int main()
{
  	cin>>s;
  	int res=1;
  	for(int i=1;i<s.size();i++)
    {
      	if(s[i]!=s[i-1])
        {
          	res++;
        }
        else
        {
          	if(i!=s.size()-1)
          		res++;
          	i++;
            s[i]='#';
        }
    }
  	cout<<res;
}

Measured memory_bytes: 640
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Net.Http.Headers;
using System.Security.Cryptography;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve(args);
			Console.Out.Flush();
		}

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve(string[] args)
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			int n = int.Parse(Console.ReadLine());
			bool ans = false;
			int c = 0;
			for (int i = 0; i < n; i++) {
				int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
				int d1 = vs[0];
				int d2 = vs[1];
				if (d1 == d2) {
					c++;
					if (c == 3) {
						ans = true;
					}
				} else {
					c = 0;
				}
			}
			if (ans) {
				Console.WriteLine("Yes");
			} else {
				Console.WriteLine("No");
			}
		}
	}
}


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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1000000007LL
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(i=a;i<=b;i++)

#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

ll mypow(ll a, ll b) { if(b == 0) return 1; ll temp=mypow(a,b/2); temp=(temp*temp)%INF; if(b%2 == 1) temp=(a*temp)%INF; return temp; }
int mygcd(int a, int b) { if(b==0) return a; return mygcd(b,a%b); }
int cntBits(ll a) { int ret=0; while(a>0) { ret++; a/=2; } return ret; }

int arr[100010],dp[100010];
int main()
{
	ios::sync_with_stdio(0);
	int tt=1,tcase; 
	//cin >> tt;
	rep(tcase,1,tt)
	{
		int n,k; cin >> n >> k;
		int i;
		rep(i,1,n) cin >> arr[i];
		dp[2]=abs(arr[2]-arr[1]);
		rep(i,3,n)
		{
			dp[i]=INT_MAX;
			for(int j=i-1;j>=max(1,i-k);j--) 
				dp[i]=min(dp[j]+abs(arr[i]-arr[j]), dp[i]);
		}
		cout << dp[n] << "\n";
	}
	return 0;
}


Measured memory_bytes: 1024
class UnionFind:
  def __init__(self, num):
    self.rank = [0]*num
    self.par = [i for i in range(num)] #基準(par = parentのpar)
    self.n   = num
    self.size = [1]*num

  def find(self, x):
    if self.par[x] == x:
      return x
    else:
      self.par[x] = self.find(self.par[x]) #自分じゃなきゃ親を探す
      return self.par[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x == y:
      return
    if self.rank[x] > self.rank[y]: #ランクの高い方に基準を合わせる
      self.par[y] = x
      self.size[x]+=self.size[y]
      self.size[y] = 0
    else:
      self.par[x] = y
      self.size[y] += self.size[x]
      self.size[x] = 0
      if self.rank[x] == self.rank[y]:
        self.rank[y] += 1

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

  def all_find(self):
    for n in range(len(self.par)):
      self.find(n)

n,m=map(int,input().split())
edges=[]
for i in range(m):
  a,b=map(int,input().split())
  edges.append([a-1,b-1])


uf=UnionFind(n)
point=n*(n-1)//2
ans=[]
while edges:
  ans.append(point)
  a,b=edges.pop()
  pa=uf.find(a)
  pb=uf.find(b)
  if not uf.same(pa,pb):
    point-=(uf.size[pa]*uf.size[pb])
  uf.union(a,b)
print(*ans[::-1],sep="\n")


Measured memory_bytes: 26352
#include<iostream>
#include<utility>
#include<queue>
#include<map>
#define h first
#define w second
using namespace std;
typedef pair<int, int> P;

const int MAX_H = 55;
const int MAX_W = 55;

int grid[MAX_H][MAX_W];
bool is_checked[MAX_H][MAX_W];

void solve(int W, int H) {
    map<P, bool> is_exist;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> grid[i][j];
            is_checked[i][j] = false;
            is_exist[P(i, j)] = true;
        }
    }
    queue<P> Q;
    int land_cnt = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (grid[i][j] == 1 && !is_checked[i][j]) {
                Q.push(P(i, j));
                is_checked[i][j] = true;
                while (!Q.empty()) {
                    P now_pos = Q.front();
                    Q.pop();
                    for (int k = -1; k <= 1; k++) {
                        for (int l = -1; l <= 1; l++) {
                            P new_pos = P(now_pos.h + k, now_pos.w + l);
                            if (!is_exist[new_pos]) continue;
                            if (is_checked[new_pos.h][new_pos.w]) continue;
                            if (grid[new_pos.h][new_pos.w] == 0) continue;
                            Q.push(new_pos);
                            is_checked[new_pos.h][new_pos.w] = true;
                        }
                    }
                }
                land_cnt++;
            }
        }
    }
    cout << land_cnt << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int W, H;
    while (true) {
        cin >> W >> H;
        if (W == 0 && H == 0) break;
        solve(W, H);
    }
    return 0;
}


Measured memory_bytes: 3284
#include <bits/stdc++.h>
#define VanLoi "bai1"
#define f first
#define s second
#define fi(a,b,c) for( int a= b; a<= c;++a)
#define fid(a,b,c) for( int a= b; a>= c;--a)
#define pii pair< int, int>
#define ll long long
#define pb push_back
#define getbit(x,i) (x>>i&1)
#define maxn 100005
#define oo 1e18

using namespace std;

int M, D, res = 0;

int main()
{
    ios_base:: sync_with_stdio(0);
    //freopen(VanLoi".inp","r",stdin);
    //freopen(VanLoi".out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> M >> D;
    fi(i, 1, M)
        fi(j, 1, D){
            int d1 = j / 10, d2 = j % 10;
            if (d1 >= 2 && d2 >= 2 && d1 * d2 == i) res++;
        }
    cout << res;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (H, W) = listOfLong()
    var ans = Long.MAX_VALUE
    if (H * W % 3 == 0L) return println(0)
    fun solv(H: Long, W: Long) {
        for (h in 1 until H) {
            val d1 = h * W
            for (n in 0 .. 1) {
                val d2 =
                    if (n == 0) (H - h) * (W / 2) // Ｔ型
                    else (H - h) / 2 * W  // 三型
                val d3 = (H * W) - d1 - d2
                val d = listOf(d1, d2, d3).sorted()
                ans = Math.min(ans, d.last() - d.first())
            }
        }
    }
    solv(H, W); if (W == H) return println(ans)
    solv(W, H); println(ans)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(vararg deltas: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + deltas[index % deltas.size] }
fun listOfLong(offset: Long = 0L) = listOfString().map { it.toLong() + offset}


Measured memory_bytes: 51444
#include <bits/stdc++.h>
using namespace std;
int n ,a[200] ,sum[200] ,sum2[200] ,res = INT_MIN ,i ,b[200];
int main(){ios::sync_with_stdio(0) ,cin.tie(0) ,cout.tie(0);
 cin >> n;
    for(i = 1; i <= n; i++) cin >> a[i] ,sum[i] = sum[i - 1] + a[i];
    for(int i = 1; i <= n; i++) cin >> b[i] ,a[i] += b[i];
     for(int i = n; i >= 1; i--)sum2[i] = sum2[i + 1] + b[i];
    for(i = 1; i <= n;i++) res = max(res , (a[i] + sum[i - 1] + sum2[i + 1]));
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const 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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;
/*
int N;
ll K;
vector<int> A, F;
*/
/*
bool isOK(ll mid){
    ll count = 0;
    rep(i,N){
        count += max(0ll, A[i] - mid/F[i]);
    }
    if (count <= K) return true;
    else return false;
}

ll binary_search(){
    ll ng = -1;
    ll ok = 1e12;

    while(abs(ok-ng)>1){
        ll mid = (ok+ng) / 2;

        if(isOK(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}
*/
int main(){
    int N;
    ll K;
    cin >> N >> K;
    vector<int> A(N), F(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> F[i];

    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());

    ll ng = -1;
    ll ok = 1e12;
    while(abs(ok-ng)>1){
        ll mid = (ok+ng) / 2;
        ll count = 0;
        rep(i,N){
            count += max(0ll, A[i] - mid/F[i]);
        }
        if(K >= count){
            ok = mid;
        }
        else{
            ng = mid;
        }
    }
    cout << ok << endl;
}

Measured memory_bytes: 4792
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include <algorithm>
using namespace std;
 
int main(){
 
  int N;
 
  cin >> N;
  
  vector<long> P(N);
  for(int i=0; i<N; i++)
    cin >> P[i];
 
  int cnt = 0;
  int min = P[0];
  
  for(int i=0; i<N; i++){
    if(P[i] <= min){
      min = P[i];
      cnt += 1;
    }
  }
  cout << cnt;
  return 0;
}


Measured memory_bytes: 1792
const main = input => {
  const hon = [2,4,5,7,9]
  const pon = [0,1,6,8]
  const n = Number(Number(input).toFixed().slice(-1))
  return hon.includes(n) ? "hon" : pon.includes(n) ? "pon" : "bon"
}
console.log(main(require('fs').readFileSync('/dev/stdin', 'utf8')))

Measured memory_bytes: 29628
// uno {{{
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(c) begin(c),end(c)
#define REP(i,n) for ( int i=0; i<(int)(n); i++ )
#define REP1(i,a,b) for ( int i=(int)(a); i<=(int)(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;

void RI() {}

template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}

template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
// }}}

string S;
LL K;
void input() {
    cin >> S >> K;
}

void solve() {
    LL ans1 = 0, ans2 = 0;
    int n = S.length();
    
    if(S == string(n, S[0])) {
        printf("%lld\n", K*n/2);
    } else {
        REP(i, n-1) {
            if(S[i%n] == S[(i+1) % n]) {
                ans1++;
                i++;
            }
        }
        REP(i, 2*n-1) {
            if(S[i%n] == S[(i+1) % n]) {
                ans2++;
                i++;
            }
        }
        printf("%lld\n", ans1 + (ans2 - ans1)*(K-1));
    }
}

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


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

int main() {
    ll n;
    std::cin >> n;
    ll ans =0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                ans += gcd(gcd(i,j),k);
            }
        }
    }
    std::cout << ans << std::endl;
}



Measured memory_bytes: 3620
N=int(input())
CARD={}
for i in range(N):
  s = str(input())
  if s not in CARD:
    CARD[s] = 1
  else:
    CARD[s]+=1
M=int(input())
for i in range(M):
  t = str(input())
  if t in CARD:
    CARD[t]-=1
print(max(max(CARD.values()),0))

Measured memory_bytes: 9036
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int a = scn.nextInt();
      	int b = scn.nextInt();
      	int c = scn.nextInt();
      	String ans = "No";
      	if((a==b&&a!=c) || (a==c&&a!=b) || (b==c&&b!=a)) ans = "Yes";
      	System.out.println(ans);
	}
}

Measured memory_bytes: 35576
s = input()
lens = len(s)


def helper(s):
    n = len(s)
    for i in range(n // 2):
        if s[i] != s[n - 1 - i]:
            return False
    return True


if helper(s) and helper(s[:(lens - 1) // 2]) and helper(s[(lens + 1) // 2:]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
// Problem : B - Bishop
// Contest : AtCoder - Panasonic Programming Contest 2020
// URL : https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a) for (int i=0; i<(a); i++)
#define rep1(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rep(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define imax INT_MAX
#define imin INT_MIN
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	 
	ios_base::sync_with_stdio(0); cin.tie(0); 
	ll h,w;
	cin>>h>>w;
	ll ans=(h==1||w==1)?1:((h*w)+1)/2;
	cout<<ans<<nl;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3604
a, b = (int(i) for i in input().split())
while a != 0 or b != 0:
    count = 0
    for i in range(1, a-1):
        for j in range(i+1 , a):
            for k in range(i+2, a+1):
                if i + j + k == b and i < j < k:
                    count += 1
    print("{0}".format(count))
    a, b = (int(i) for i in input().split())

Measured memory_bytes: 7680
n = int(input())

m = '357'
ml = [1,1,1]

count = 0
flag = True
while flag:
    '''
    print(m)
    print(count)
    print(ml)
    '''
    if int(m) <= n:
        if 0 in ml:
            pass
        else:
            count += 1
    else:
        flag = False
    tmpm = m[::-1]
    for i,x in enumerate(tmpm):
        if x == '3':
            m = '3'*i + '5' + tmpm[i+1:]
            m = m[::-1]
            ml[0] -= 1
            ml[0] += i
            ml[1] += 1
            ml[2] -= i
            break
        elif x == '5':
            m = '3'*i + '7' + tmpm[i+1:]
            m = m[::-1]
            ml[0] += i
            ml[1] -= 1
            ml[2] -= i
            ml[2] += 1
            break
        else:
            pass
    if ml[0] == 0 and ml[1] == 0:
        tmpl = len(m)
        m = '3' * (tmpl+1)
        ml = [tmpl+1, 0, 0]


print(count)


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

#include <string>
using namespace std;
#define rep(i, n)                    \
  for (int i = 0; i < (int)(n); i++) \
    ;

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  string n;
  cin >> n;
  long sum = 0;
  for (int i = 0; i < n.size(); i++) {
    sum += stol(to_string(n.at(i))) - 48;
  }
  if (sum % 9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3780
#nCr % mod
def comb_mod(n, r, mod):
  x = 1
  y = 1
  for i in range(r):
    x = (x * (n - i)) % mod
    y = (y * (i + 1)) % mod
    
  ans = x * pow_k(y, mod-2, mod)
  
  return ans % mod
  
# x^n % mod
def pow_k(x, n, mod):
  if n == 0:
    return 1

  K = 1
  while n > 1:
    if n % 2 != 0:
      K = (x * K) % mod
        
    x = (x * x) % mod

    n //= 2

  return (x * K) % mod
  
def main():
  MOD = 10 ** 9 + 7
  n,k = map(int,input().split())
  
  for i in range(1,k+1):
    ans = comb_mod(n-k+1, i, MOD) * comb_mod(k-1, i-1, MOD)
    ans %= MOD
    print(ans)
    
main()

Measured memory_bytes: 43504
#include <stdio.h>
#define MAX 101

int G[MAX][MAX];

int main(){
  int i,j,u,k,v,num;

  scanf("%d",&num);
  for(i=1; i<=num; i++){
    for(j=1; j<=num; j++){
      G[i][j] = 0;
    }
  }
  for(i=1; i<=num; i++){
    scanf("%d%d",&u,&k);
    for(j=1; j<=k; j++){
      scanf("%d",&v);
      G[u][v] = 1;
    }
  }

  for(i=1; i<=num; i++){
    for(j=1; j<=num; j++){
      printf("%d",G[i][j]);
      if(j!=num) printf(" ");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
int main(){
int A,B,C,K,x;
cin >> A >> B >> C >> K;
if(A<K){
	if(B<K-A){x=A+(-1)*(K-(A+B));
		
	}
	if(B>=K-A){x=A;
	}

}



if(A>=K){x=K;}

cout << x << endl;
return 0;
}

Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));
        String line = bi.readLine();
        String[] str1 = line.split(" ");
        int N = Integer.parseInt(str1[0]);
        int K = Integer.parseInt(str1[1]);

        String[] str2 = bi.readLine().split(" ");

        HashMap<Integer, Double> exp = new HashMap<>();
        double p = 0;
        double result = 0;
        for (int i = 0; i < N; i++){
            int pp = Integer.parseInt(str2[i]);
            if (exp.containsKey(pp) == false) {
                exp.put(pp, (double)(1 + pp) /2);
            }
            p += exp.get(pp);
            if (i >= K) {
                p -= exp.get(Integer.parseInt(str2[i - K]));
            }
            if (result < p) {
                result = p;
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 51412
#include <stdio.h>
int main(void){
    
    int a,b;
    
    scanf("%d",&a);
    scanf("%d",&b);
    
    if(a<b)printf("a < b\n");
    if(a>b)printf("a > b\n");
    if(a==b)printf("a == b\n");
    
    return 0;
}



Measured memory_bytes: 2052
n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n-1):
  u, v, w = map(int, input().split())
  adj[u-1].append((w, v-1))
  adj[v-1].append((w, u-1))
paint = [None] * n
paint[0] = 0
stack = [0]
while stack:
  u = stack.pop()
  for w, v in adj[u]:
    if paint[v] is None:
      stack.append(v)
      paint[v] = (paint[u] + w) % 2
for p in paint:
  print(p)

Measured memory_bytes: 38828
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

#define fs first
#define sc second

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


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

// std::vector Initialization
template<typename T>
void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U>
void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

// std::vector Debug
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    bool a = 1;
    for (auto e : v ) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "]";
    return os;
}

// std::pair Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << " " << p.second << ")";
    return os;
}

// std::set Debug
template<typename T>
ostream& operator<<(ostream& os, const set<T>& st) {
    os << "{";
    bool a = 1;
    for (auto e : st) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "}";
    return os;
}

// std::multiset Debug
template<typename T>
ostream& operator<<(ostream& os, const multiset<T>& st) {
    os << "{";
    bool a = 1;
    for (auto e : st) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "}";
    return os;
}

// std::map Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
    os << "{";
    bool a = 1;
    for (auto e : mp) {
        os << (a ? "" : " ");
        os << e.first << ":" << e.second;
        a = 0;
    }
    os << "}";
    return os;
}

// std::tuple Debug
template<int N, class Tuple>
void out(ostream& os, const Tuple& t){}
template<int N, class Tuple, class H, class ...Ts>
void out(ostream& os, const Tuple& t) {
    if (N) os << " ";
    os << get<N>(t);
    out<N+1,Tuple,Ts...>(os, t);
}
template<class ...Ts>
ostream& operator<<(ostream& os, const tuple<Ts...>& t) {
    os << "(";
    out<0,tuple<Ts...>,Ts...>(os, t);
    os << ")";
    return os;
}

// Debug
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl


struct edge { int to, cost; };
ostream& operator<<(ostream& os, const edge& e) {
    os << "(" << e.to << ", " << e.cost << ")";
    return os;
}

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 1e9+7;

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

    bool ans = true;
    for (int i = 1; i < n; ++i) {
        if (h[i-1] < h[i]) {
            --h[i];
        } else if (h[i-1] > h[i]) {
            ans = false;
            break;
        }
    }

    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

// index が条件を満たすかどうか
bool isOK(vector<ll> v, ll index, ll key) {
    if (v[index] > key)
        return true;
    else
        return false;
}

// 汎用的な二分探索のテンプレ
ll binary_search(vector<ll> v, ll key) {
    //「index = 0」が条件を満たすこともあるので、初期値は -1
    ll ng = -1LL;

    // 「index = a.size()-1」が条件を満たさないこともあるので、
    // 初期値は a.size()
    ll ok = (ll)v.size();

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;

        if (isOK(v, mid, key))
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> L(N);
    rep(i, N) cin >> L[i];

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

    // repv(L) cout << *it << " ";
    // cout << endl;

    ll cnt = 0;

    for (ll i = N - 1; i >= 2; i--) {
        for (ll j = i - 1; j >= 1; j--) {
            ll rest = L[i] - L[j];
            // if (rest > L[j - 1]) continue;
            auto itr = upper_bound(L.begin(), L.end(), rest);
            ll ng = distance(L.begin(), itr);

            if (ng < j) cnt += (j - ng);

            // // ll idx = binary_search(L, rest);

            // cout << "i: " << L[i] << ", j: " << L[j] << ", rest: " << rest
            //      << ", j_idx: " << j << ", ng: " << ng << endl;
            // cnt += (j - idx);
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>
int main()
{
	long long max,sum,a,b,c;
	while(scanf("%lld%lld%lld",&a,&b,&c)!=EOF)
	{
		max=a>b?a:b;
		max=max>c?max:c;
		sum=(max-a)+(max-b)+(max-c);
		if(sum%2==0)
		printf("%lld\n",sum/2);
		else
		{
			printf("%lld\n",sum/2+2);
		}
	}
	return 0;
 } 

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){

   int x, y;

   cin >> x >> y;

   for(int i = 0; i <= x; i++){
      if(2*i + 4*(x-i) == y){
         cout << "Yes" << endl;
         return 0;
      }
   }

   cout << "No" << endl;

   return 0;
}

Measured memory_bytes: 3592
from math import factorial
MOD = 10 ** 9 + 7
n, m = map(int, input().split())
if abs(n - m) >= 2:
    print(0)
elif abs(n - m) == 1:
    print((factorial(n) * factorial(m)) % MOD)
else:
    print((factorial(n) * factorial(m) * 2) % MOD)


Measured memory_bytes: 5188
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  int a,b;
  cin>>a>>b;
  cout<<a*b<<endl;
  return 0;
}


Measured memory_bytes: 3620
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N, M := getInt(), getInt()
	n := make([]int, N+1)
	for i := 0; i < M; i++ {
		a, b := getInt()-1, getInt()-1
		if a > b {
			a, b = b, a
		}
		n[a]++
		n[b]--
		// out(n)
	}
	// out(n)
	for i := 1; i <= N; i++ {
		n[i] += n[i-1]
	}
	// out(n)
	ans := "YES"
	for i := 0; i < N; i++ {
		if n[i]%2 == 1 {
			ans = "NO"
		}
	}
	out(ans)
}


Measured memory_bytes: 2560
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define MAX_N (1<<18)
struct SegTree {
  int seg[MAX_N*2-1] = {}, lazy[MAX_N*2-1] = {};
  SegTree() {
    rep(i, MAX_N*2-1) lazy[i] = 1;
  }
  void setLazy(int k, int v) {
    seg[k] = (1LL*seg[k]*v)%MOD;
    lazy[k] = (1LL*lazy[k]*v)%MOD;
  }
  void push(int k) {
    if (lazy[k] == 1) return;
    setLazy(k*2+1, lazy[k]);
    setLazy(k*2+2, lazy[k]);
    lazy[k] = 1;
  }
  void add(int k, int v) {
    k += MAX_N-1;
    seg[k] = (seg[k]+v)%MOD;
    while (k > 0) {
      k = (k-1)/2;
      seg[k] = (seg[k*2+1]+seg[k*2+2])%MOD;
    }
  }
  int sum(int a, int b, int k=0, int l=0, int r=MAX_N) {
    if (b <= l || r <= a) return 0;
    if (a <= l && r <= b) return seg[k];
    return (sum(a, b, k*2+1, l, (l+r)/2) + sum(a, b, k*2+2, (l+r)/2, r)) % MOD;
  }
  void mul(int a, int b, int x, int k=0, int l=0, int r=MAX_N) {
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) return setLazy(k, x);
    mul(a, b, x, k*2+1, l, (l+r)/2);
    mul(a, b, x, k*2+2, (l+r)/2, r);
    seg[k] = (seg[k*2+1]+seg[k*2+2])%MOD;
  }
} seg;

int N;
int V[200000];
int L[200000], R[200000];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  vector<P> ps;
  vector<int> vs;
  rep(i, N) {
    int x, y;
    cin >> x >> y;
    vs.pb(y);
    ps.pb(P(x, y));
  }
  sort(all(vs));
  sort(all(ps));
  rep(i, N) V[i] = index(vs, ps[i]._2);
  int cur = -1;
  rep(i, N) {
    cur = max(cur, V[i]);
    R[i] = cur;
  }
  cur = vs.size();
  for (int i=N-1; i>=0; i--) {
    cur = min(cur, V[i]);
    L[i] = cur;
  }
  vector<P> segs;
  rep(i, N) segs.pb(P(L[i], R[i]));
  sort(all(segs));
  seg.add(0, 1);
  rep(i, N) {
    int l = segs[i]._1, r = segs[i]._2;
    seg.add(r+1, seg.sum(l, r+2));
    seg.mul(r+2, MAX_N, 2);
  }
  cout << seg.sum(N, N+1) << "\n";
  return 0;
}


Measured memory_bytes: 12264
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int N = 0;
  cin >> N;
  int ans = 0;
  for(int i = 0; i < N; i++){
    ans += i+1;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char x[3];
	char y[3];
	
	gets(x);
	gets(y);
	if(x[1] == y[1]){
		if(x[0] == y[2] && x[2] == y[0]) printf("YES");
		else printf("NO");
	}else{
		printf("NO");
	}
	return(0);
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
	const int p[6] = {
		77, 51, 
		4, -1, 0, -3
	};
	int n[6];
	while(1){
		for(int i=0;i<6;++i)
			scanf("%d",&n[i]);
		if( n[5] == 0 ) break;
		n[5] -= n[0] * 6 + n[1] * 4 + n[2] + n[3] + n[4];
		int sum = 100;
		for(int i=0;i<6;++i)
			sum += n[i] * p[i];
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
  int H,W,N;
  cin>>H>>W>>N;
  N--;
  if(H>W){
  cout<<N/H+1<<endl;
  }else{
  cout<<N/W+1<<endl;
  }
}

Measured memory_bytes: 256
from typing import  Any, Sequence

def binarySearch(A: Sequence, Key: int) -> int:
    global cnt
    left = 0
    right = len(A)
    while True:
        mid = (left + right) // 2
        if A[mid] == Key:
            cnt += 1
            return cnt
        elif A[mid] < Key:
            left = mid + 1
        else:
            right = mid - 1
        if left > right:
            break
    return  0

n = int(input())
S = list(map(int, input().split()))
S = list(set(S))
S = sorted(S)

q = int(input())
T = list(map(int, input().split()))

cnt = 0

for i in T:

    binarySearch(S, i)

print(cnt)




Measured memory_bytes: 18580
package main

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

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}
func main() {
	sc.Split(bufio.ScanWords)
	N, _ := strconv.Atoi(read())
	K, _ := strconv.Atoi(read())

	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i], _ = strconv.Atoi(read())
	}

	sort.Sort(sort.IntSlice(a))

	var sum int
	for _, x := range a[len(a)-K:] {
		sum += x
	}
	fmt.Println(sum)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define mx 105
using namespace std;

int main(){
	int n, a[mx], mni;
	double av, sm = 0, mn = 10000;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		sm += a[i];
	}
	av = sm/n;
	for(int i = 0; i < n; i++){
		if(mn > abs(a[i]-av)){
			mn = abs(a[i]-av);
			mni = i;
		}
	}
	printf("%d\n", mni);
}


Measured memory_bytes: 256
N = int(input())
ListP = []
for i in range (N):
  ListP.append(input())
M = int(input())
ListN = []
for i in range (M):
  ListN.append(input())
res = 0
mid = 0
for i in range(N):
  mid += ListP.count(ListP[i])
  mid += -ListN.count(ListP[i])
  res = max(res,mid)
  mid = 0
print(res)

Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define st string
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define each(i, n) for(auto&& i: n)

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if(A + B + C > 21) {
    cout << "bust" << endl;
  }
  else {
    cout << "win" << endl;
  }
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
	while(cin >> n, n) {
		vector<pair<int, int> > v(n);
		for(int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
		cin >> m; v.resize(n + m);
		for(int i = 0; i < m; i++) cin >> v[n + i].first >> v[n + i].second;
		n += m;
		sort(v.begin(), v.end());
		vector<int> dp(n + 1);
		for(int i = 1; i <= n; i++) {
			dp[i] = 1;
			for(int j = 1; v[j - 1].first < v[i - 1].first; j++) {
				if(v[j - 1].second < v[i - 1].second) {
					dp[i] = max(dp[i], dp[j] + 1);
				}
			}
		}
		cout << *max_element(dp.begin(), dp.end()) << endl;
	}
}

Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <iomanip>

using namespace std;

int N, K;

int main()
{

	cin >> N;
	cin >> K;

	double ans = 0.0;

	ans += max(0, N + 1 - K);

	int k = 1;
	while ((K - 1) / k >= 1) {
		int n = max(0,min(N,(K - 1) / k) - (K - 1) / k / 2);

		k *= 2;
		ans += (1.0 / k) * n;
	}

	ans /= N;
	cout << fixed << setprecision(11) << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = nextInt(scanner);
        int m = nextInt(scanner);
        int x = nextInt(scanner);
        int[] c = new int[n];
        int[][] a = new int[n][m];
        for (int i = 0; i < n; i++) {
            c[i] = nextInt(scanner);
            for (int j = 0; j < m; j++) {
                a[i][j] = nextInt(scanner);
            }
        }

        int finalPrice = -1;
        for (int i = 0; i < Math.pow(2, n); i++) {
            int[] points = new int[m];
            int price = 0;
            for (int j = 0; j < n; j++) {
                if ((1&i>>j) == 1) {
                    for (int k = 0; k < m; k++) {
                        points[k] += a[j][k];
                    }
                    price += c[j];
                }
            }
            boolean isPass = true;
            for (int point: points) {
                if (point < x) {
                    isPass = false;
                    break;
                }
            }
            if (isPass) {
                if (finalPrice > price || finalPrice == -1) {
                    finalPrice = price;
                }
            }
        }
        System.out.println(finalPrice);
    }

    public static int nextInt(Scanner scanner) {
        return Integer.parseInt(scanner.next());
    }
}


Measured memory_bytes: 37144
#include <iostream>
using namespace std;
 
int main(void){
  int a[1000];
  int n,b,e,k,q;
   
  cin >> n;
  for (int i=0; i<n; i++) cin >> a[i];
  cin >> q;
  for (int i=0; i<q; i++){
    int cnt = 0;
    cin >> b >> e >> k;
    for (int j=b; j<e; j++){
      if (a[j] == k) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}
   


Measured memory_bytes: 3120
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, parser) => {
        $next
    };

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        n: usize,
    }

    let mut x = vec![0usize; n + 1];
    x[0] = 2;
    x[1] = 1;
    for i in 2..n + 1 {
        x[i] = x[i - 2] + x[i - 1];
    }
    println!("{}", x[n]);
}


Measured memory_bytes: 4352