akhauriyash/Code-Regression huggingface dataset:
import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.IArray             as IA
import qualified Data.Array.IO                 as AI
import qualified Data.Array.MArray             as MA
import qualified Data.Array.ST                 as STA
import qualified Data.Array.Unboxed            as AU
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Graph                    as G
import           Data.Int
import qualified Data.IntMap                   as IM
import qualified Data.IntSet                   as IS
import           Data.List
import qualified Data.Map.Strict               as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence                 as SQ
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Tree                     as T
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt :: IO Int
readInt = fst . fromJust . BS.readInt <$> BS.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readIntLists :: Int -> IO [[Int]]
readIntLists n = replicateM n readInts

readInteger :: IO Integer
readInteger = fst . fromJust . BS.readInteger <$> BS.getLine

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegerLists :: Int -> IO [[Integer]]
readIntegerLists n = replicateM n readIntegers

readStrings :: IO [String]
readStrings = map BS.unpack . BS.words <$> BS.getLine

readStringLists :: Int -> IO [[String]]
readStringLists n = replicateM n <$> readStrings

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putList :: Show a => [a] -> IO ()
putList [n     ] = print n
putList (n : ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n     ] = putStrLn n
putStrList (n : ns) = do
  putStr n
  putStr " "
  putStrList ns

yesNoUpper b | b         = putStrLn "YES"
             | otherwise = putStrLn "NO"

yesNo b | b         = putStrLn "Yes"
        | otherwise = putStrLn "No"

divCeiling x n | b == 0    = a
               | otherwise = a + 1
  where (a, b) = x `divMod` n

main = do
  s <- getLine
  yesNo $ '7' `elem` s


Measured memory_bytes: 3740
N,K=map(int,input().split())
A = list(map(int, input().split()))

count={}

for i in range(N):
  if A[i] not in count:
    count[A[i]]=1
  else:
    count[A[i]]+=1

if(len(count)<=K):
  print(0)
else:
  x=len(count)-K #減らさなければならない種類
  answer=0
  sorted_count=sorted(count.items(),key=lambda x:x[1])
  for i in range(x):
    answer+=int(sorted_count[i][1])
  
  print(answer)

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

int N, M, X, C[12], A[12][12];

int main()
{
	cin >> N >> M >> X;
	for (int i = 0; i < N; i++){
		cin >> C[i];
		for (int j = 0; j < M; j++) cin >> A[i][j];
	}

	int ans = 0x7fffffff;
	for (int b = 0; b < (1 << N); b++){
		int cost = 0, sum[12] = { 0, };
		for (int i = 0; i < N; i++) if (b & (1 << i)){
			cost += C[i];
			for (int j = 0; j < M; j++) sum[j] += A[i][j];
		}

		bool g = 1;
		for (int j = 0; j < M; j++) if (sum[j] < X) g = 0;
		if (g) ans = min(ans, cost);
	}

	if (ans == 0x7fffffff)
		ans = -1;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    ll ans=0;
    /*for(ll i=0;i<=min(3*a,n);i++){
        ll tmp=(a*i)/b-a*(i/b);
        ans=max(ans,tmp);
    }*/
    if(n>=b-1) ans=max(ans,(a*(b-1))/b-a*((b-1)/b));
    else ans=max(ans,(a*n)/b-a*(n/b));
    cout<<ans<<endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>  // ver2.2.2
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ

int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n,qw;
  cin >> n;
  rep(i,0,n){
    cin >> qw;
    if(qw%2==1) {
      cout<<"first"<<endl;
      return 0;
    }
  }
  cout<<"second"<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		int n;
		Scanner sc = new Scanner(System.in);
		int data[] = new int[4];	
		n = sc.nextInt();
		
		int score[] = new int[n];
		
		for(int i=0; i<n*(n-1)/2; i++){
			for(int j=0; j<4; j++){
				data[j]=sc.nextInt();
			}
			if(data[2]>data[3]){
				score[(data[0]-1)]+=3;
			}
			else if(data[3]>data[2]){
				score[(data[1]-1)]+=3;
			}
			else if(data[2]==data[3]){
				score[(data[0]-1)]+=1;
				score[(data[1]-1)]+=1;
			}
		}
		
		int result;
		for(int i=0; i<n; i++){
			result=1;
			for(int j=0; j<n; j++){
				if(score[i]<score[j]) result++;
			}
			System.out.println(result);
		}

	}

}

Measured memory_bytes: 44012
N = int(input())
ARR = [int(s) for s in input().split(" ")]
def calculate(n,arr):

    left = list([])
    right = list([])
    if n % 2 == 0:
        for index,ar in enumerate(arr):
            if index % 2 == 0:
                right.append(str(ar))
            else:
                left.append(str(ar))
    else:
        for index,ar in enumerate(arr):
            if index % 2 == 0:
                left.append(str(ar))
            else:
                right.append(str(ar))

    left.reverse()
    left.extend(right)

    return left

result = calculate(N,ARR)
print(" ".join(result))

Measured memory_bytes: 33812
from heapq import heappop,heappush
def dijkstra(s,n,edge):
  """
  始点sから各頂点への最短距離を返す

  Parameters
  ----------
  s : int
      視点とする頂点（0-indexed）
  n : int
      グラフの要素数
  eage:list
      グラグ

  Returns
  -------
  dist ：list
  始点sから各頂点への最短距離
  """
  dist=[float("inf")]*n
  dist[s]=0
  used=[-1]*n
  hq=[[dist[s],s]]
  while hq:
    d,cur=heappop(hq)
    if dist[cur]<d:continue # 距離が最小でない場合は飛ばす
    for nx,nxd in edge[cur]:
      if dist[cur]+nxd<dist[nx]:
        dist[nx]=dist[cur]+nxd
        used[nx]=cur
        heappush(hq,[dist[cur]+nxd,nx])
  return dist

n=int(input())
edge=[[] for _ in range(n)]
for _ in range(n-1):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  edge[a].append((b,c))
  edge[b].append((a,c))


q,k=map(int,input().split())
xy=[list(map(int,input().split()))for _ in range(q)]
d=dijkstra(k-1,n,edge)
for x,y in xy:
  print(d[x-1]+d[y-1])


Measured memory_bytes: 74256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000005


int main(){
	
	int N,K,Q;
	cin>>N>>K>>Q;
	
	vector<pair<int,int>> P;
	
	vector<int> A(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
		P.emplace_back(A[i],i);
	}
	
	sort(P.begin(),P.end());
	int ans = Inf;
	for(int i=0;i<=N;i++){
		priority_queue<int,vector<int>,greater<int>> QQ;
		int now = 0;
		while(true){
			if(now>=N)break;
			priority_queue<int,vector<int>,greater<int>> q;
			while(now!=N&&A[now]!=Inf){
				q.push(A[now]);
				now++;
			}
			while(q.size()>=K){
				QQ.push(q.top());
				q.pop();
			}
			now++;
		}
		if(QQ.size()<Q)break;
		int Y = QQ.top();
		for(int j=0;j<Q-1;j++)QQ.pop();
		int X = QQ.top();
		ans = min(ans,X-Y);
		if(i!=N){
			A[P[i].second]=Inf;
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
	
}


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

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  int x,y,z;
  cin >> x >> y >> z;
  x -= y + 2*z;
  int ans = 1;
  while(true){
    if(x  - y >= 0){
      x -= y;
    }else break;

    if(x - z >= 0){ans ++; x -= z;}
    else break;

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


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

int main(){
  int N;
  cin >> N;
  long count=0;
  for(int i=0;i<N;i++){
    if((i+1)%15!=0 && (i+1)%5!=0 && (i+1)%3!=0){
      count+=i+1;
    }
  }
  cout << count << endl;
}


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

int main(){
    int h,w,n;
    cin>>h>>w>>n;
    vector<pair<int,int>> p;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        p.push_back(make_pair(a,i+1));
    }
    sort(p.begin(),p.end());
    reverse(p.begin(),p.end());
    int k=0,l=0;
    int c[h][w];
    for(int i=0;i<h;i++){
        if(i%2==0){
            for(int j=0;j<w;j++){
                if(l+1>p[k].first){
                    l=0;
                    k++;
                    c[i][j]=p[k].second;
                    l++;
                }
                else{
                    c[i][j]=p[k].second;
                    l++;
                }
            }
        }
        else{
            for(int j=w-1;j>=0;j--){
                if(l+1>p[k].first){
                    l=0;
                    k++;
                    c[i][j]=p[k].second;
                    l++;
                }
                else{
                    c[i][j]=p[k].second;
                    l++;
                }
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<c[i][j]<<" ";
        }
        cout<<endl;
    }
}

Measured memory_bytes: 512
H, W = map(int, input().split())
S = [[j for j in input()] for i in range(H)]
X = [[0 for j in range(W)] for i in range(H)]
Y = [[0 for j in range(W)] for i in range(H)]

for i in range(H):
    start = -1
    cnt = 0
    for j in range(W + 1):
        if j == W or S[i][j] == '#':
            for k in range(start + 1, j):
                X[i][k] = cnt
            cnt = 0
            start = j
        else:
            cnt += 1

for j in range(W):
    start = -1
    cnt = 0
    for i in range(H + 1):
        if i == H or S[i][j] == '#':
            for k in range(start + 1, i):
                Y[k][j] = cnt
            cnt = 0
            start = i
        else:
            cnt += 1

m = 0
for i in range(H):
    for j in range(W):
        m = max(m, X[i][j] + Y[i][j])

print(m - 1)


Measured memory_bytes: 252808
#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#endif
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

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


struct Mo {

    int width;
    vector< int > left, right, order;
    vector< bool > v;

    Mo(int N, int Q) : width((int) sqrt(N)), order(Q), v(N) {
        iota(begin(order), end(order), 0);
    }

    void add(int l, int r) { /* [l, r) */
        left.emplace_back(l);
        right.emplace_back(r);
    }

    template< typename ADD, typename DEL, typename REM >
    void run(const ADD &add, const DEL &del, const REM &rem) {
        assert(left.size() == order.size());
        sort(begin(order), end(order), [&](int a, int b) {
            int ablock = left[a] / width, bblock = left[b] / width;
            if(ablock != bblock) return ablock < bblock;
            if(ablock & 1) return right[a] < right[b];
            return right[a] > right[b];
        });
        int nl = 0, nr = 0;
        auto push = [&](int idx) {
            v[idx].flip();
            if(v[idx]) add(idx);
            else del(idx);
        };
        for(auto idx : order) {
            while(nl > left[idx]) push(--nl);
            while(nr < right[idx]) push(nr++);
            while(nl < left[idx]) push(nl++);
            while(nr > right[idx]) push(--nr);
            rem(idx);
        }
    }
};

int main() {
    int N, Q;
    cin >> N >> Q;
    vector< int > A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector< int > f(1000001);
    Mo mo(N, Q);
    for(int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        mo.add(--l, r);
    }
    int ret = 0;
    auto add = [&](int idx) { if(f[A[idx]]++ == 0) ret++; };
    auto del = [&](int idx) { if(f[A[idx]]-- == 1) --ret; };
    vector< int > ans(Q);
    auto rem = [&](int idx) { ans[idx] = ret; };
    mo.run(add, del, rem);
    for(int i = 0; i < Q; i++) {
        cout << ans[i] << "\n";
    }
}


Measured memory_bytes: 17676
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

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

		StringTokenizer st;
		StringBuilder sb = new StringBuilder();
		int[] stock = new int[100];
		int[] needs = new int[100];

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

			int n = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			int k = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
			if ((n | k) == 0) {
				break;
			}

			st = new StringTokenizer(br.readLine());
			for (int i = 0; i < k; i++) {
				stock[i] = Integer.parseInt(st.nextToken());
				needs[i] ^= needs[i];
			}
			for (int i = 0; i < n; i++) {
				st = new StringTokenizer(br.readLine());
				for (int j = 0; j < k; j++) {
					needs[j] += Integer.parseInt(st.nextToken());
				}
			}
			for (int i = 0; i < k; i++) {
				if (stock[i] < needs[i]) {
					sb.append("No\n");
					continue next;
				}
			}
			sb.append("Yes\n");
		}
		System.out.print(sb.toString());
	}
}

Measured memory_bytes: 41080
#include<iostream>


using namespace std;
int hantei(int N);
int main(){
    int kosuu,m,N;
    cin >> N;
    if(hantei(N)==0){
        cout << "No";
        return 0;
    }
    kosuu=hantei(N);
    cout << "Yes\n";
    cout << kosuu+1 << "\n";
    for(int i=1;i<=kosuu+1;i++){
        cout << kosuu;
        for(int j=(i-1)*(i-2)/2+1;j<=i*(i-1)/2;j++){
            cout << " ";
            cout << j;
        }
        if(i==kosuu+1)break;
        cout << " ";
        cout << i*(i+1)/2;
        m=i*(i+1)/2;
        for(int j=i;j<=kosuu-1;j++){
            cout <<" ";
            cout << m+j;
            m+=j;
        }
        cout << "\n";
    }
    return 0;
}

int hantei(int N){
    for(int i=1;;i++){
        if(i*(i+1)==2*N){
            return i;
        } else if(i*(i+1)>2*N){
            return 0;
        }
    }
    return -1;
}


Measured memory_bytes: 1408
#include<stdio.h>

int main(){
  int n,i,max=1,l[11],lt=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&l[i]);
    lt+=l[i];
    if(max<l[i]) max=l[i];
  }
  if(max<lt-max) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 128
A,B,C,D = map(int,input().split())
if A > D or B < C:
  print(0)
elif A <= C and D <= B:
  print(D-C)
elif C <= A and B <= D:
  print(B-A)
elif A <= C and C <= B:
  print(B-C)
else:
  print(D-A)
  
  

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

int main() {
    int N,K; cin >> N >> K;
    int ans = 0;
    for(int i=0;i<N;i++){
        int c=0;cin >> c;
        ans += 2*min(c,K-c);
    }
    cout << ans << endl;

    return 0;
}

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

int main(void){
  int S;
  cin >> S;
  if(S / 100 > 12 && S % 100 > 12) cout << "NA";
  else if(S / 100 > 12 && S % 100 == 0) cout << "NA";
  else if(S / 100 == 0 && S % 100 > 12) cout << "NA";
  else if(S / 100 == 0 && S % 100 == 0) cout << "NA";
  else if(S / 100 > 12 || S / 100 == 0) cout << "YYMM";
  else if(S % 100 > 12 || S % 100 == 0) cout << "MMYY";
  else cout << "AMBIGUOUS";
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

#define INF LLONG_MAX / 5
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define enld endl

signed main() {
	int N, W;
	cin >> N >> W;
	vector<int>w(N);
	vector<int>v(N);
	rep(i, N) {
		cin >> w[i] >> v[i];
	}
	vector<vector<int>>dp(N + 1, vector<int>(W + 1));
	rep(i, N + 1) {
		rep(j, W + 1) {
			if (i == 0) {
				dp[i][j] == 0;
			}
			else {
				if (j - w[i-1] < 0) {
					dp[i][j] = dp[i - 1][j];
				}
				else {
					dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i-1]] + v[i-1]);
				}
			}
		}
	}
	cout << dp[N][W] << endl;
}

/*
int N, W;
	cin >> N >> W;
	vector<int>w(N), v(N);
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
	}
	vector<vector<int>> dp(N + 1, vector<int>(W + 1));
	for (int i = 0; i < N; i++) {
		for (int ws = 0; ws <= W; ws++) {
			if (ws >= w[i]) {
				dp[i + 1][ws] = max(dp[i][ws], dp[i][ws - w[i]] + v[i]);
			}
			else {
				dp[i + 1][ws] = dp[i][ws];
			}
		}
	}
	cout << dp[N][W] << endl;
	*/

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

int main(){
	int N;
	cin >> N;
	vector<int> an(N);
	for(int i=0;i<N;i++){
		cin >> an.at(i);
	}
	sort(an.begin(),an.end());
	
	int fir=an.at(0);
	int end=an.at(N-1);
	int cost,ans;
	cost=0;
	ans=1000000000;
	
	for(int i=fir;i<=end;i++){
		cost=0;
		for(int j=0;j<N;j++){
			cost+=(an.at(j)-i)*(an.at(j)-i);
		}
		if(cost<ans){
			ans=cost;
		}
	}
	
	cout<<ans<<endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main() {
    double L;
    cin >> L;

    double d = L / 3;
    double ans = d * d * d;

    printf("%.10f", ans);

    return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = ~(1<<31);
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int l[500010],r[500010];

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

	for(int i = 0; i < s.size(); i++){
		if(s[i] == '<') l[i+1] += l[i]+1;
	}
	for(int i = s.size()-1; i >= 0; i--){
		if(s[i] == '>') r[i] += r[i+1]+1;
	}

	ll ans = 0;
	for(int i = 0; i <= s.size(); i++){
		ans += max(l[i],r[i]);
	}

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


Measured memory_bytes: 4740
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}

void main()
{
  int n; readV(n);
  writeln(n%calc(n) == 0 ? "Yes" : "No");
}

auto calc(int n)
{
  int r = 0;
  for (; n > 0; n /= 10) r += n%10;
  return r;
}


Measured memory_bytes: 256
class Dice():
	def __init__(self):
		self.number = [_ for _ in range(6)]
		self.work = [_ for _ in range(6)]

	def setNumber(self,n0,n1,n2,n3,n4,n5):
		self.number[0] = n0
		self.number[1] = n1
		self.number[2] = n2
		self.number[3] = n3
		self.number[4] = n4
		self.number[5] = n5

	def roll(self,loc):
		for _ in range(6):
			self.work[_] = self.number[_]
		if loc == "E":
			self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
		elif loc == "N":
			self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
		elif loc == "S":
			self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
		elif loc == "W":
			self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
	def get_top(self):
		return self.number[0]
	def get_right(self,n1,n2):
		if(n1 == self.number[0]):
			if(n2 == self.number[1]): print(self.number[2])
			elif(n2 == self.number[2]): print(self.number[4])
			elif(n2 == self.number[3]): print(self.number[1])
			elif(n2 == self.number[4]): print(self.number[3])
		elif(n1 == self.number[1]):
                        if(n2 == self.number[0]): print(self.number[3])
                        elif(n2 == self.number[2]): print(self.number[0])
                        elif(n2 == self.number[3]): print(self.number[5])
                        elif(n2 == self.number[5]): print(self.number[2])
		elif(n1 == self.number[2]):
                        if(n2 == self.number[0]): print(self.number[1])
                        elif(n2 == self.number[1]): print(self.number[5])
                        elif(n2 == self.number[4]): print(self.number[0])
                        elif(n2 == self.number[5]): print(self.number[4])
		elif(n1 == self.number[3]):
                        if(n2 == self.number[0]): print(self.number[4])
                        elif(n2 == self.number[1]): print(self.number[0])
                        elif(n2 == self.number[4]): print(self.number[5])
                        elif(n2 == self.number[5]): print(self.number[1])
		elif(n1 == self.number[4]):
                        if(n2 == self.number[0]): print(self.number[2])
                        elif(n2 == self.number[2]): print(self.number[5])
                        elif(n2 == self.number[3]): print(self.number[0])
                        elif(n2 == self.number[5]): print(self.number[3])
		elif(n1 == self.number[5]):
                        if(n2 == self.number[1]): print(self.number[3])
                        elif(n2 == self.number[2]): print(self.number[1])
                        elif(n2 == self.number[3]): print(self.number[4])
                        elif(n2 == self.number[4]): print(self.number[2])

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

mydice = Dice()

mydice.setNumber(data[0],data[1],data[2],data[3],data[4],data[5])
for _ in range(q):
	flat = list(map(int,input().split()))
	mydice.get_right(flat[0],flat[1])



Measured memory_bytes: 5752
#include <iostream>

using namespace std;

int main()
{
    int n,k;

    cin >> n;
    cin >> k;

    int result = 1;

    for (int a = 0; a < n; ++a) {
        if(k <= result){
            result += k;
        }else{
            result += result;
        }
    }

    cout << result << endl;

    return 0;
}


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

#define debug(x) cerr << #x << ": " << x << endl;

#define iosbase ios_base::sync_with_stdio(false)
#define tie cin.tie();cout.tie();

#define endl '\n'

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

priority_queue<int> fila;

int n, m, k, q, x;
int main(){
  iosbase;
  tie;

  cin >> n >> x;

  for(int i = 0; i < n; i++){
    cin >> q;
    fila.push(q);
  }

  int topo = 0;
  while(x>0){
    topo = fila.top();
    fila.pop();

    // debug(topo);
    topo/=2;
    fila.push(topo);
    x--;
  }

  long long sum = 0;
  while(!fila.empty()){
    sum+= (1LL) * ((long long) fila.top());
    fila.pop();
  }

  cout << sum << endl;


}


Measured memory_bytes: 892
K, S = map(int, input().split())
l = [i for i in range(K+1)]
cnt = 0
for i in l:
    if i > S:
        break
    elif i == S:
        cnt += 1
        break
    elif i < S:
        tmp1 = S-i
        if K-tmp1 >= 0:
            cnt += tmp1 + 1
        else:
            tmp2 = 2*K + 1 - tmp1
            if tmp2 > 0:
                cnt += tmp2
                
print(cnt)

Measured memory_bytes: 3064
s = gets.chomp
K = gets.to_i
# char_var = Hash.new
# s.each_char do |c|
#   char_var[c] = 0 if char_var.has_key? c
#   char_var[c] += 1
# end

str_len = 1
sub_str = Hash.new
[K, s.size].min.times do |str_len|
  (s.size - str_len).times do |i|
    ss = s[i..(i+str_len)]
    sub_str[ss] = true unless sub_str.has_key? ss
  end
  # if sub_str.size >= K
  #   break
  # end
end
#pp (sub_str.keys.sort)
puts (sub_str.keys.sort)[K-1]


Measured memory_bytes: 3960
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var N = Input.NextInt();
            var x = Input.NextLong();
            var list = Input.LongList();
            long count = 0;

            if (list[0] + list[1] > x) {
                count += list[0] + list[1] - x;
                list[1] = Math.Max(0, x - list[0]);
                list[0] = x - list[1];
            }

            if (list[N - 1] + list[N - 2] > x) {
                count += list[N - 1] + list[N - 2] - x;
                list[N - 2] = Math.Max(0, x - list[N - 1]);
                list[N - 1] = x - list[N - 2];
            }

            for (int i = 1; i < N - 3; i++) {
                if (list[i] + list[i + 1] > x) {
                    count += list[i + 1] + list[i] - x;
                    list[i + 1] = x - list[i];
                }
            }

            Console.WriteLine(count);
        }
    }

    class Input {
        static IEnumerator<string> enumerator;

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            if (enumerator == null || !enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
                enumerator.MoveNext();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            if (enumerator == null || !enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
                enumerator.MoveNext();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 28764
while True:
    n = int(input())
    if n == 0:
        break
    a = 0
    b = 0
    for i in range(n):
        input_card = input().split()
        if int(input_card[0]) > int(input_card[1]):
            a += int(input_card[0]) + int(input_card[1])
        elif int(input_card[0]) < int(input_card[1]):
            b += int(input_card[0]) + int(input_card[1])
        else:
            a += int(input_card[0])
            b += int(input_card[1])
    print(f"{a} {b}")


Measured memory_bytes: 5628
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 9999999999;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define f first
#define s second
#define pi 3.141592653589793238
using namespace std;
const ll sz = 200000;
vector<pll> adj[sz];
bool vis[sz];
ll dis[sz];
ll col[sz];

void dfs(ll cur,ll sum)
{
	vis[cur] = true;
	for(auto v:adj[cur])
	{
		if(vis[v.f]) continue;
		if((sum+v.s)%2==1) col[v.f] = 1;
		dfs(v.f,sum+v.s); 
	}
}

int main()
{
	std::ios::sync_with_stdio(false);
		
	ll n;
	cin >> n;

	for(int i = 2;i<=n;i++)
	{
		ll x,y,d;
		cin >> x >> y >> d;
		adj[x].pb(mp(y,d));
		adj[y].pb(mp(x,d));
	}

	dfs(1,0);
	for(int i = 1;i<=n;i++) cout << col[i]  << endl;


	return 0;
}



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

int main(){
	#ifdef LOCAL_DEFINE
		freopen("../a.in","r",stdin);
		freopen("../a.out", "w",stdout);
	#endif

	int A,B,K;
	cin >> A >> B >> K;
	int ct = 1;
	vector<int> v;
	while(ct<=A&&ct<=B){
		if(A%ct==0&&B%ct==0){
			v.push_back(ct);
		}
		ct++;
	}
	sort(v.begin(), v.end());
	cout << v[v.size()-K] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    int H,W;
    scanf("%d %d",&H,&W);
    for (int i=1;i<=300;i++){
        if(H==0 && W==0){
            break;
        }
        else{
            for(int j=1;j<=H;j++){
                for(int k=1;k<=W;k++){
                    if((j+k)%2==0){
                        printf("#");
                    }
                    else{
                        printf(".");
                    }
                }
                printf("\n");
            }
            printf("\n");
            scanf("%d %d",&H,&W);
        }
    }
    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl; 

    return 0;
}


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

int a, b, k;
bool who = true;

int main() {
    cin >> a >> b >> k;
    for (int i = 1; i <= k; ++i) {
        who = !who;
        if (who == false) {
            b += a / 2;
            a /= 2;
        } else {
            a += b / 2;
            b /= 2;
        }
    }
    cout << a << " " << b << endl;
    return 0;
}

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

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

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

using namespace std;

#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int> 
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define eps 1e-9

ll A[1000001];

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

	ll n, i, j, k, x, y, z;
	ll ans = 0;
	cin >> n;
	for (i = 1; i <= n; ++i) cin >> A[i];
	for (i = 1; i <= n; ++i) {
		if ((A[i] > i-1) || (A[i] > A[i-1]+1)) {
			cout << -1 << endl;
			return 0;
		}
		if (A[i] == A[i-1]+1) ans += 1;
		else ans += A[i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1920
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True

    for i in range(n):
      for j in range(n):
        if(x+i==p[j]):
          check=False
      if(check):
        l_list.append(x+i)
      check=True
    if(l_list == [] and s_list == []):
      ans = x-1
    elif(l_list == []):
      ans = max(s_list)
    elif(s_list == []):
      ans = min(l_list)
    else:
      if(abs(x-min(l_list)) > abs(x-max(s_list))):
        ans = max(s_list)
      elif(abs(x-min(l_list))==abs(x-max(s_list))):
        ans=max(s_list)
      else:
        ans=min(l_list)  

print(ans)

Measured memory_bytes: 9256
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val n = readLine.trim.toInt
  for (_ ← 0 until n){
    val a = readLine.trim.split(' ').map(_.toInt)
    val b = readLine.trim.split(' ').map(_.toInt)
    println(
      (a.permutations.map{c ⇒
      c.zip(b).map{
        case (a, b) if a > b ⇒ a + b
        case (a, b) ⇒ -a - b
      }.sum.let{it ⇒ if (it > 0) 1 else 0: Int}
    }.sum.toDouble / (2 to 9).fold(1){case (a, b) ⇒ a * b}
    ).let{it ⇒
        s"${it.toString.take(7)} ${(1-it).toString.take(7)}"
      }
    )
  }

  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
/*

 */


Measured memory_bytes: 577244
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void){
    int W, H, x, y;
    cin >> W >> H >> x >> y;
    int multi = (2*x==W && 2*y==H) ? 1 : 0;
    cout << (double)W*H/2 << " " << multi << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF INT_MAX 
int main(){
    int a,b,c,d,e;
    cin >> a >> b >> c >> d >> e;
    int k;
    int flag=0;
    cin >> k;
    if(e-a<=k){
        flag++;
    }
    if(flag==0){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;  
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(void)
{	
int H=0;int R=0;
scanf("%d %d",&H,&R);
if(H+R==0){printf("0\n");}
else if(H+R<0){printf("-1\n");}
else{printf("1\n");}
return 0;
}


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

int main() {
  int N, A, B;
  cin >> N;
  A = (N % 1000) % 111;
  B = ((N - N % 10) / 10) % 111;
    
  if (A == 0 || B == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rush() int T;scanf("%d",&T);int kase=1;while(T--)
#define all(x) (x).begin(),(x).End()
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define pb(x) push_back(x)
using namespace std;
using std::bitset;
typedef long long ll;
const ll maxn=1e6+5;
const ll mod=998244353;
const ll INF=0x3f3f3f3f3f3f3f3f;
const long double PI=acos(-1.0);
const long double eps=1e-5;
inline ll read(){ll ans=0,flag=1;char c;c=getchar();while(c<'0' || c>'9'){if(c=='-')flag=-1;c=getchar();}while(c>='0' && c<='9'){ans=ans*10+(ll)(c-'0');c=getchar();}return ans*flag;}
ll quickpow(ll x,ll y,ll mod){ll ans=1;while(y){if(y&1)ans=ans*x%mod;x=x*x%mod;y>>=1;}return ans;}

int main()
{
    string a;
    cin>>a;
    int len=a.length();
    int cnt=0;
    for(int i=0,j=len-1;i<len;i++,j--)
    {
        if(a[i]!=a[j])
            cnt++;
    }
    cout<<cnt/2<<endl;
}


Measured memory_bytes: 256
s=input()
t=input()

max_itti=0

for i in range(len(s)-len(t)+1):
    
    ittisuu=0
    
    for j in range(len(t)):
        
        if t[j] == s[i+j]:
            ittisuu += 1
            
            
    max_itti=max(max_itti,ittisuu)  
print(len(t) - max_itti)
      
      

Measured memory_bytes: 67576
toInt :: (String -> Int)
toInt x = read x ::Int

getInts = do
    x <- getLine
    let y = (map$toInt)$words x
    return y

a :: Int -> Int
a x = 2 * x

ret :: [Int] -> Int -> Int -> Int
ret hs c h
    | head hs > h = (head hs) - 1
    | otherwise = ret (tail hs) (c + 1) h

main = do
    ns <- getInts
    let h = head ns
    let r = ret (iterate a 1) 0 h
    putStrLn $ show r


Measured memory_bytes: 508
N, K = map(int, input().split())

a_list = list(map(int, input().split()))
a_set = set(a_list)
if len(a_set) <= K:
    print(0)
else:
    a_map = {}
    for a in a_list:
        if a in a_map:
            a_map[a] += 1
        else:
            a_map[a] = 1
    margin = len(a_set) - K
    a_map = sorted(a_map.items(), key=lambda x:x[1])
    count = 0
    for i in range(margin):
        count += a_map[i][1]
    print(count)

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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int a,b;
	cin>>a>>b;
	if ((a*b)%2==0){
		cout<<"Even";
	}
	else {
		cout<<"Odd";
	}
	return 0;
}

Measured memory_bytes: 256
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
pp=gsmi

prevmin=2*10**5+1
n.times do |i|
  cnt+=1 if prevmin>=pp[i]
  prevmin=pp[i] if prevmin>pp[i]
end

puts cnt

Measured memory_bytes: 16532
#include <iostream>
using namespace std;
int main(void){
    int N,L,eat,ans = 0;
    cin >> N >> L;
    if (L < 0){
        if(L+N-1 >= 0){
            eat = 0;
        }else {
            eat = L+N-1;
        }
    }else {
        eat = L;
    }
    for(int i = L;i < L+N;i++){
        if(i == eat) continue;
        ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif

bool is_palindrome(int n) {
    string s = to_string(n);
    string t = s;
    reverse(t.begin(), t.end());
    return s == t;
}

int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A, B; cin >> A >> B;
    
    int ans = 0;
    FOR(i,A,B+1) {
        if (is_palindrome(i)) ans++;
    }
  
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/*
ID:wmj20041
TASK:
LANG:C++
*/
#include<functional>
#include<algorithm>
#include<exception>
#include<stdexcept>
#include<streambuf>
#include<iterator>
#include<string.h>
#include<stdlib.h>
#include<typeinfo>
#include<valarray>
#include<iostream>
#include<sstream>
#include<istream>
#include<stdio.h>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<ctype.h>
#include<cassert>
#include<cstdlib>
#include<utility>
#include<cstring>
#include<numeric>
#include<ostream>
#include<cwctype>
#include<fstream>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cctype>
#include<string>
#include<vector>
#include<limits>
#include<locale>
#include<memory>
#include<cerrno>
#include<time.h>
#include<iosfwd>
#include<cfloat>
#include<cstdio>
#include<cwchar>
#include<cmath>
#include<ctime>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<ios>
#include<map>
#include<set>
#include<new>
#define LL long long
#define pb push_back
#define pob pop_back
#define mp make_pair
#define FILL(a,v) memset((void*)a,v,sizeof(a))
#define FILL0(a) FILL(a,0)
#define FILL1(a) FILL(a,-1)
#define FILLBIG(a) FILL(a,0x7f)
#define ALL(a) (a).begin(),(a).end()
#define Inf ((int)0x7f7f7f7f)
#define Mod 1000000007
#define foreach(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define FOR(i,x) for(int i=0;i<x;i++)
#define RFOR(i,x) for(int i=x-1;i>=0;i--)
#define FFOR(i,a,b) for(int i=a;i<b;i++)
#define FRFOR(i,a,b) for(int i=a-1;i>=b;i--)
#define SZ(a) ((int)(a).size())
#define FI first
#define SE second
#define OVER(a) return puts(a),0
#define fastio ios::sync_with_stdio(0)
#define filei(f) freopen(f,"r",stdin)
#define fileo(f) freopen(f,"w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define MASK(a) (1<<(a))
#define MASKX(x,a) ((x)<<(a))
#define BIT(a,b) ((a>>b)&1)
#define cddx(a) priority_queue<a >
#define cxdd(a) priority_queue<a,vector<a >,greater<a > >
#define deval(a) {cerr<<#a<<" = "<<a<<endl;}
#define dearr(be,en) {cerr<<#be;cerr<<" = {";for(auto i=be;i!=en;i++)cerr<<' '<<*i;cerr<<" }\n";}
#define reg register
using namespace std;
typedef pair<int,int> pii;
typedef unsigned long long UINT;
typedef unsigned int uint;
typedef long long INT;
typedef long double ldouble;
typedef pair<INT,INT> PII;
typedef stringstream sst;
typedef istringstream iss;
typedef vector<int> vint;
typedef vector<INT> VINT;
typedef vector<pii> vpii;
typedef vector<PII> VPII;
typedef priority_queue<int> pqi;
typedef priority_queue<INT> PQI;
typedef priority_queue<pii> pqp;
typedef priority_queue<PII> PQP;
typedef priority_queue<int,vint,greater<int> > xqi;
typedef priority_queue<INT,VINT,greater<INT> > XQI;
typedef priority_queue<pii,vpii,greater<pii> > xqp;
typedef priority_queue<PII,VPII,greater<PII> > XQP;
const int INF=1e9+7;
using namespace std;
string s;
int main()
{
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>s;
	int k=0;
	for (int i=0;i<3;i++)
	if (s[i]=='1') k++;
	cout<<k;
	return 0;
}


Measured memory_bytes: 256
def main():
  import sys
  n,k=map(int,input().split())
  a=tuple(map(int,sys.stdin.readline().split()))
  
  count=lambda arr,now:sum(element<now for element in arr)
  
  ans=0
  prime=10**9+7
  k=k%prime
  for i in range(n):
    left=count(a[:i],a[i])
    right=count(a[i+1:],a[i])
    res=(k-1)*k//2*(right+left)+right*k
    ans+=res%prime
    
  print(ans%prime)

if __name__=="__main__":
  main()

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

long long K;

long long by(long long num) {
    for (int i = 0; i < K; ++i) {
        num = num * 2;
    }
    return num;
}

int main(void) {
    long long A, B, C;
    cin >> A >> B >> C;
    cin >> K;

    long long maxnum;
    long long sum = 0;
    if (A >= B) {
        if (A >= C) {
            maxnum = by(A);
            sum = maxnum + B + C;
        } else if (C >= A) {
            maxnum = by(C);
            sum = maxnum + A + B;
        }
    } else {
        if (B >= C) {
            maxnum = by(B);
            sum = maxnum + A + C;
        } else {
            maxnum = by(C);
            sum = maxnum + A + B;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int x, y, r, tmp;


  scanf("%d %d", &x, &y);

  if(x < y){
    tmp = x;
    x = y;
    y = tmp;
  }
  //printf("x = %d, y = %d\n", x, y);

  r = x % y;

  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }

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


  return 0;
}

Measured memory_bytes: 592
#include <iostream>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	n %= 10;	
	if(n == 3) cout<<"bon";
	else if(n == 0 || n == 1 || n== 6 || n== 8) cout<<"pon";
	else cout<<"hon";
}

Measured memory_bytes: 3128
import math
def popcount(x):
    s=0
    y=int(math.log2(x))+2
    for i in range(y):
        if(x>>i)&1:
            s+=1
    return x%s
n=int(input())
x=input()[::-1]
#1がなんこ出るのか
c=x.count("1")
#c+1とc-1だけ考えれば良い
#c=1の時場合分け
#m[i][j]:2^iまで考えたときのmod(c+j-1)
if c!=1:
    m=[[1%(c-1),1%(c+1)]]
    for i in range(n-1):
        m.append([(2*m[-1][0])%(c-1),(2*m[-1][1])%(c+1)])
    l=[0,0]
    for i in range(n):
        if x[i]=="1":
            l[0]+=m[i][0]
            l[1]+=m[i][1]
            l[0]%=(c-1)
            l[1]%=(c+1)
else:
    m=[[1%(c+1),1%(c+1)]]
    for i in range(n-1):
        m.append([(2*m[-1][0])%(c+1),(2*m[-1][1])%(c+1)])
    l=[0,0]
    for i in range(n):
        if x[i]=="1":
            l[0]+=m[i][0]
            l[1]+=m[i][1]
            l[0]%=(c+1)
            l[1]%=(c+1)
#一個だけ変えたいので全体を求める

#最初以外はpopcount使って間に合う
ans=[0]*n
for i in range(n):
    if x[i]=="1":
        if c-1==0:
            ans[i]=0
            continue
        p=(l[0]+(c-1)-m[i][0])%(c-1)
        ans[i]+=1
        while p!=0:
            p=popcount(p)
            ans[i]+=1
    else:
        p=(l[1]+m[i][1])%(c+1)
        ans[i]+=1
        while p!=0:
            p=popcount(p)
            ans[i]+=1
ans=ans[::-1]
for i in range(n):
    print(ans[i])






Measured memory_bytes: 98428