akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    a = list(map(int,input().split()))
    
    le = max(a).bit_length()
    bin = [0 for _ in range(le)]
    l,r = 0,0
    ans = 0
    while r < N:
        num = a[r]
        for i in range(le):
            bin[i] += num%2
            num //= 2
        if 2 not in bin:
            ans += r-l+1
            r += 1
        else:
            while (l < r and 2 in bin):
                num = a[l]
                for i in range(le):
                    bin[i] -= num%2
                    num //= 2
                l += 1
            ans += r-l+1
            r += 1

    print(ans)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 20408
N=int(input())
S=""
if N==0:
    print(0)
    exit()
while(True):
    if N==1:
        S="1"+S
        break
    if N%2==1:
        S="1"+S
    else:
        S="0"+S
    N-=N%2
    N=N//(-2)
print(S)


Measured memory_bytes: 38384
d, n = map(int, input().split())
def culc(x):
    if x % 100 != 0:
        return 0
    else:
        cnt = 0
        while x % 100 == 0:
            x //= 100
            cnt +=1
        return cnt            

count = 0

for i in range(1, 1010001):
    if culc(i) == d:
        count += 1
    if count == n:
        print(i)
        break

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
int main(){
  ll n; cin >> n;
  queue<ll> q;
  q.push(3);
  q.push(5);
  q.push(7);
  ll ans=0;
  while(true){
    ll c=q.front(); q.pop();
    if(c>n) break;
    string s= to_string(c);
    if(s.find("3")!=string::npos&&s.find("5")!=string::npos&&s.find("7")!=string::npos){
      ans++;
    }
    q.push(10*c+3);
    q.push(10*c+5);
    q.push(10*c+7);
  }
  std::cout << ans;
  return 0;
}


Measured memory_bytes: 768
#include<stdio.h>
#include<iostream>

using namespace std;

int main(void)
{
 int a,b,c,d;
  cin>>a>>b>>c>>d;
  int l,r;
  l=a+b;
  r=c+d;
  if(l<r)
  {
cout<<"Right"<<endl;
  }
 else if(r<l)
 {
cout<<"Left"<<endl;
 }
  else
  {
    cout<<"Balanced"<<endl;
  }
  
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i=0; i<n; i++){
    cin >> vec.at(i);
  }
  
  int count=0;
  for(int i=0; i<n; i++){
    if((i+1) != vec.at(i)){
      count++;
    }
  }
  
  if(count <= 2){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int x;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;


    for(int i=1;i<=10000;i++)
    {
        x=a*i;
        if(x%b==c)
        {
            cout<<"YES"<<endl;
            return 0;
        }
    }

    cout<<"NO"<<endl;
    return 0;


}


Measured memory_bytes: 256
N,M = map(int,input().split())
A = set([int(input()) for i in range(M)])
MOD = 10**9+7



dp = [0]*(N+1)
dp[0] = 1
for i in range(N):
    if i+1 not in A:
        dp[i+1] += dp[i]
        dp[i+1] %= MOD
    if i+2 <= N and i+2 not in A:
        dp[i+2] += dp[i]
        dp[i+2] %= MOD
print(dp[-1]%MOD)


Measured memory_bytes: 56664
/*
Author : Gaurav Singh
*/
#include<bits/stdc++.h>
using namespace std;
#define N 200005
#define MOD 1000000007
#define ll long long
#define ld long double
#define ull unsigned long long
#define li long int
#define str string
#define vll vector<ll>
#define pb push_back
#define frn(i,n) for(ll (i) = 0; (i) <(n) ; (i)=(i+1))
#define fr(i,n) for(ll (i) = 1; (i) <=(n) ; (i)=(i+1))
#define frev(i,n) for(ll (i) = n-1; (i) >=(0) ; (i)--)
#define fr1(j,a,b,c) for(ll (j) = a; (j) <c ; (i)=(i+b))
#define w(t) while(t--)
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
void solve(){
    ll n,k,a,i,x;
    cin>>n>>k;
    frn(i,n){
        cin>>a;
    }
    x=(n-1)%(k-1);
    x==0?cout<<(n-1)/(k-1):cout<<(n-1)/(k-1)+1;
}
int main()
{   
   fast;
   int t=1;
    w(t){
        solve();
    }
   return 0;
}   

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


int main(){

    int A, B;
    cin >> A >> B;

    if(A >= 13){
        cout << B << endl;
    } else if(6 <= A && A <= 12){
        cout << B/2 << endl;
    } else if(0 <= A && A <= 5){
        cout << 0 << endl;
    }
    
    return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n, k;
  cin >> n >> k;

  vector<ll> a(n);
  REP(i, n)
    cin >> a[i];

  sort(a.begin(), a.end());
  vector<ll> b = a;
  decltype(b)::iterator result = unique(b.begin(), b.end());
  b.erase(result, b.end());

  vector<pll> unique_cou(b.size());
  ll cou = 0;
  REP(i, b.size()){
    unique_cou[i].SE = b[i];
    for(int j = cou; a[cou] == b[i]; cou++)
      unique_cou[i].FI++;
  }


  sort(unique_cou.begin(), unique_cou.end());
  ll sum = 0;
  REP(i, unique_cou.size()-k){
//    cout << unique_cou[i].FI << endl;
    sum += unique_cou[i].FI;
  }
  cout << sum << endl;
  
}


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

#define pb push_back
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

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

int main()
{
	fastio;

	int n, x;
	cin >> n;

	int res = 0;
	for (int i = 1; i <= n; ++i)
	{
		cin >> x;
		res += (i % 2 && x%2);
	}
	cout << res << '\n';

	return 0;
}


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

int main(){
  int N , K , d , a ;
  cin >> N >> K ;
  vector<bool> ans2(N,true) ;
  for(int i =0;i<K;i++){
    cin >> d;
    for(int j =0;j<d;j++){
      cin >> a;
      a--;
      ans2[a] = false;
    }
  }
  int ans1 =0;
  for(int i =0;i<N;i++){
    if(ans2[i]==true) ans1++;
  }
  
  cout << ans1 << endl;

}
  

Measured memory_bytes: 3552
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

int N, M;
int x[100010];

signed main()
{
	cin >> N >> M;
	rep(i, M) cin >> x[i];

	sort(x, x + M);
	vector<int> d(M - 1);
	int S = 0;
	rep(i, M - 1) d[i] = x[i + 1] - x[i], S += d[i];
	sort(all(d), greater<int>());

	int ans = 0;
	rep(i, min(M - 1, N - 1)) ans += d[i];
	cout << S - ans << endl;
}




Measured memory_bytes: 1792
from bisect import bisect_left,bisect_right

def check_prime(x):
  p= int(x**0.5)
  for i in range(2,p+1):
    if x%i==0:
      return False
  else:
    return True
  
prime=[2]
like=[]
for i in range(3,100001,2):
  if check_prime(i):
    prime.append(i)
    if (i+1)//2 in prime:
      like.append(i)
      
#print(like)

Q=int(input())
l=[0]*Q
r=[0]*Q
for i in range(Q):
  l[i],r[i]= map(int,input().split())
  s=bisect_left(like,l[i])
  t=bisect_right(like,r[i])  
  print(t-s)

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

 ll  GetDigit(ll num)
{
    return log10(num) + 1;
}

int main(){
    ll n,c=0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < s.size();i++)
    {
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
        {
            c++;
        }
    }
    cout << c;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from math import sin, cos, radians

def rotate_point(point, angle, center_point=(0, 0)):
    """Rotates a point around center_point(origin by default)
    Angle is in degrees.
    Rotation is counter-clockwise
    """
    angle_rad = radians(angle % 360)
    # Shift the point so that center_point becomes the origin
    new_point = (point[0] - center_point[0], point[1] - center_point[1])
    new_point = (new_point[0] * cos(angle_rad) - new_point[1] * sin(angle_rad),
                 new_point[0] * sin(angle_rad) + new_point[1] * cos(angle_rad))
    # Reverse the shifting we have done
    new_point = (round(new_point[0] + center_point[0]), round(new_point[1] + center_point[1]))
    return new_point

def main():
    X1,Y1,X2,Y2  = map(int, input().split())
    Cord1 = (X1,Y1)
    Cord2 = (X2,Y2)
    Cord3 = rotate_point(Cord1,-90, Cord2)
    Cord4 = rotate_point(Cord2,90, Cord1)
    print("{} {} {} {}".format(Cord3[0],Cord3[1],Cord4[0],Cord4[1]))
                

    

if __name__ == '__main__':
    main()

Measured memory_bytes: 39408
#include <bits/stdc++.h>
const int mod=1e9+7;
using LL=long long;
using namespace std;
namespace ndifix{
template<class T>void rsort(T &v){std::sort(v.rbegin(),v.rend());}
}//end of namespace ndifix


int main(){
  int n;cin>>n;
  vector<int> a(n);for(int i=0;i<n;i++)cin>>a[i];
  vector<int> b=a;
  ndifix::rsort(b);
  for(int i=0;i<n;i++){
    if(a[i]!=b[0])cout<<b[0]<<endl;
    if(a[i]==b[0])cout<<b[1]<<endl;
  }
  return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<map>
 
using namespace std;
 
int main() {
    const int SIZE = 2001;
    bool dp[SIZE] = { false };
     
    int n;
    int m;
    int ary[20];
    vector<int> vec;
 
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> ary[i];
    }
 
    vec.push_back(0);
    dp[0] = true;
    for (int i = 0; i < n; i++) {
        int s = vec.size();
        for (int j = 0; j < s; j++) {
            if (dp[vec[j] + ary[i]] == false) {
                dp[vec[j] + ary[i]] = true;
                vec.push_back(vec[j] + ary[i]);
            }
        }
    }
     
    cin >> m;
    for (int i = 0; i < m; i++) {
        int v;
        cin >> v;
        if (dp[v]) {
            cout << "yes" << endl;
        }
        else {
            cout << "no" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3160
n = int(input())
T = list(map(int, input().split()))
t = [0]
for i in range(n):
	t.append(t[-1] + T[i])
v = list(map(int, input().split()))

ans = 0
prev_spped = 0

for x in range(1, 2 * t[-1] + 1):
	time = x / 2
	speeds = [time, t[-1] - time]
	for i in range(n):
		if time <= t[i]:
			speeds.append(v[i] + t[i] - time)
		elif t[i] < time <= t[i + 1]:
			speeds.append(v[i])
		else:
			speeds.append(v[i] + time - t[i + 1])
	speed = min(speeds)
	ans += (speed + prev_spped) * 0.25
	prev_spped = speed

print(ans)

Measured memory_bytes: 45532
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli A, B, m;
    cin >> A >> B >> m;
    vi a(A), b(B);
    lli ma = INF, mb = INF;
    rep(i,A){
        cin >> a[i];
        ma = min(ma, a[i]);
    }
    rep(i,B){
        cin >> b[i];
        mb = min(mb, b[i]);
    }
    lli ans=ma+mb;
    rep(i,m){
        lli x, y, c;
        cin >> x >> y >> c;
        x--;
        y--;
        ans = min(ans, a[x] + b[y] - c);
    }
    out(ans);
}

Measured memory_bytes: 4840
function Picker(input) {
  var lines = input.split('\n');
  var fields = lines.reduce(function(all, line) { return all.concat(line.split(' ')); }, []);
  var p = 0;

  return {
    int: function() {
      return parseInt(fields[p++], 10);
    },
    float: function() {
      return parseFloat(fields[p++]);
    },
    str: function() {
      return fields[p++];
    }
  };
}

function Main(input) {
  var pick = Picker(input);
  var s = pick.str();

  var c1 =0;
  var c2 = 0;
  for (var i = 0; i < s.length; ++i) {
    if (s[i] == i % 2) {
      c1++;
    } else {
      c2++;
    }
  }

  console.log(c1 < c2 ? c1 : c2);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9420
#include <cstdio>
#include <cstring>
using namespace std;
static_assert(sizeof(long) >= 8, "long too short");
char s[100001];
int main() {
    scanf("%s", s);
    int n = strlen(s);
    int ans = (n + 1) / 2;
    while (ans < n && s[ans] == s[ans - 1] && s[n - ans - 1] == s[n - ans])
        ans++;
    printf("%d\n", ans);
}


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

#define reint register int
#define coint const int

using namespace std;

struct Vector {
    double x, y;

    inline Vector operator+(const Vector &v) const {
        return (Vector){ x + v.x, y + v.y };
    }

    inline double dot(const Vector &v) const { return x * v.x + y * v.y; }
    inline double cross(const Vector &v) const { return x * v.y - y * v.x; }
    inline double length(void) const { return sqrt(x * x + y * y); }

    inline Vector operator*(const double a) const {
        return (Vector){ x * a, y * a };
    }
};

struct Point {
    double x, y;

    inline Vector operator-(const Point &p) const {
        return (Vector){ x - p.x, y - p.y };
    }

    inline Point operator+(const Vector &v) const {
        return (Point){ x + v.x, y + v.y };
    }
};

int main(void) {
    Point p1, p2;
    scanf("%lf%lf%lf%lf", &p1.x, &p1.y, &p2.x, &p2.y);
    const Vector vecP1P2 = p2 - p1;
    const double lenP1P2 = vecP1P2.length();
    int q;
    scanf("%d", &q);
    for (reint i = 1; i <= q; ++i) {
        Point p;
        scanf("%lf%lf", &p.x, &p.y);
        const Vector vecP1P = p - p1;
        const double lenP1X = vecP1P.dot(vecP1P2) / lenP1P2;
        const Vector vecP1X = vecP1P2 * (lenP1X / lenP1P2);
        const Point x = p1 + vecP1X;
        printf("%.12f %.12f\n", x.x, x.y);
    }

    return 0;
}



Measured memory_bytes: 3220
#include<stdio.h>
#include<string.h>
int main()
{
    char w[100], main[200], cpy[100];
    int wl,mainlen,i,j,c=0,y=0;

    scanf("%s",&main)   ; mainlen=strlen(main) *2;
    scanf("%s",&w)    ; wl=strlen(w);

    strcpy(cpy,main);
    strcat(main,cpy);

    for(i=0;  i< mainlen-wl ; i++)
    {
        for(j=0; j<wl;j++)
        {
            if(main[i+j] == w[j]) c++;
        }
        if(c==wl) y=1;
        else c=0;
    }

    if(y==1) printf("Yes\n");
    else printf("No\n");

    return 0;


}




Measured memory_bytes: 2684
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
 
int main(){
    ll k;
    string s;
    cin>>k>>s;
    ll n=s.length();
    if(n<=k){
        cout<<s<<endl;
    }
    else{
        ll i;
        for(i=0;i<k;i++){
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
    return 0;
}

Measured memory_bytes: 3580
from collections import deque
N = int(input())
H = list(map(int, input().split()))
high = [H[i] - H[i + 1] for i in range(N - 1)]
ans = deque()
cnt = 0

for j in range(len(high)):
    if high[j] >= 0:
        cnt += 1
    else:
        ans.append(cnt)
        cnt = 0

ans.append(cnt)
print(max(ans))

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

import sys

sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

# ベルマンフォード(頂点数, 辺集合(0-indexed), 始点)
def bellman_ford(N: int, edges: list, src: int) -> list:
    # 頂点[ある始点からの最短距離]
    # (経路自体を知りたい時はここに前の頂点も持たせる)
    res = [INF] * N
    res[src] = 0
    # 各辺によるコストの置き換えを頂点数N-1回繰り返す
    for i in range(N-1):
        for src, dest, cost in edges:
            if res[dest] > res[src] + cost:
                res[dest] = res[src] + cost
    # 負の閉路(いくらでもコストを減らせてしまう場所)がないかチェックする
    for src, dest, cost in edges:
        if res[dest] > res[src] + cost:
            # あったら空リストを返却
            return []
    # 問題なければ頂点リストを返却
    return res

N,M,r=MAP()
edges=[None]*M
for i in range(M):
    s,t,d=MAP()
    edges[i]=(s, t, d)

ans=bellman_ford(N, edges, r)

if not len(ans):
    print('NEGATIVE CYCLE')
    exit()

for i in range(N):
    if ans[i]==INF:
        ans[i]='INF'
for i in range(N):
    print(ans[i])



Measured memory_bytes: 6152
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		long[] A = new long[N];
		for(int i=0; i<N; i++)
			A[i] = sc.nextInt();
		
		long[] l = new long[N+1];
		long[] r = new long[N+1];
		for(int i=0; i<N; i++) {
			l[i+1] = l[i] + A[i];
			r[i+1] = r[i] + A[N-1-i];
		}
		
		long ans = Long.MAX_VALUE;
		
		for(int i=2; i<=N-2; i++) {
			long[] suml = findSplit(l, i);
			long[] sumr = findSplit(r, N-i);
			long min = Math.min( Math.min(suml[0], suml[1]),Math.min(sumr[0], sumr[1]));
			long max = Math.max( Math.max(suml[0], suml[1]),Math.max(sumr[0], sumr[1]));
			ans = Math.min(ans, max-min);
		}
		
		System.out.println(ans);
	}
	
	static long[] findSplit(long[] a, int i) {
		int idx = Arrays.binarySearch(a, a[i]/2);
		long[] ans = new long[2];
		if(idx>=0) {
		} else {
			idx = -idx-2;
			if(idx < i-1 && a[i]-a[idx+1] > a[idx]) {
				idx++;
			}
		}
		
		ans[0] = a[idx];
		ans[1] = a[i]-ans[0];
		return ans;
	}
}


Measured memory_bytes: 95112
n, m = map(int, input().split())
lst = []
for _ in range(m):
    a, b = map(int, input().split())
    lst.append((a, b))
sor = sorted(lst, key=lambda x:x[1])
spl = -1
cnt = 0
for a, b in sor:
    if a<=spl:
        continue
    else:
        spl = b-1
        cnt += 1
print(cnt)

Measured memory_bytes: 18960
#include<stdio.h>
 
long max(long a,long b){
	if(a>b){
    	return a;
    }else{
    	return b;
    }
}
 
long min(long a,long b){
	if(a<b){
    	return a;
    }else{
    	return b;
    }
}
 
int f(long a,long b){
  long c=max(a,b);
  int keta=1;
  for(int i=0;i<10;i++){
  	if(c/10>0){
    	keta++;
      	c/=10;
    }
  }
  return keta;
}
 
 
 
int main(void){
  
  long N;
  int minnum=11;
  scanf("%ld",&N);
  
  for(long a=1;a*a<=N;a++){
  	if(N%a == 0){
      long b=N/a;
      int res=f(a,b);
      minnum=min(minnum,res);
    }
  }
  
  printf("%ld",minnum);
  
 
return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

void dfs(map<int, int>::iterator it, vector<int> &times, map<int, int> &d, int &ret) {
    if (it == d.end()) {
        int mindiff = 25;
        int nt = times.size();
        for (int i = 0; i < nt; ++i) {
            for (int j = 0; j < nt; ++j) {
                if (i == j)
                    continue;
                int timemin = min(times[i], times[j]);
                int timemax = max(times[i], times[j]);
                chmin(mindiff, timemax - timemin);
                chmin(mindiff, 24 - timemax + timemin);
            }
        }
        chmax(ret, mindiff);
        return;
    }
    if (it->second == 1) {
        auto ntimes = times;
        ntimes.push_back(it->first);
        dfs(next(it), ntimes, d, ret);
        ntimes = times;
        ntimes.push_back(24 - it->first);
        dfs(next(it), ntimes, d, ret);
    }
    if (it->second == 2) {
        auto ntimes = times;
        ntimes.push_back(it->first);
        ntimes.push_back(24 - it->first);
        dfs(next(it), ntimes, d, ret);
    }
}

int main() {
    int n;
    cin >> n;
    map<int, int> d;
    bool zero = false;
    for (int i = 0; i < n; ++i) {
        int dd;
        cin >> dd;
        d[dd]++;
        if (d[dd] == 3)
            zero = true;
    }
    if (zero) {
        cout << 0 << "\n";
        return 0;
    }
    int ret = 0;
    vector<int> times = {0};
    dfs(d.begin(), times, d, ret);
    cout << ret << "\n";

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
a = []
res = 0
for _ in range(N):
  s, t = input().split()
  t = int(t)
  a.append((s, t))
  res += t
s = input()[: -1]
for i in range(N):
  res -= a[i][1]
  if a[i][0] == s:
    break
print(res)

Measured memory_bytes: 38256
//written by libra9z
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <valarray>
#include <utility>
#include <numeric>
#include <memory>
#include <functional>
#include <stdexcept>
#include <typeinfo>
#include <limits>
#include <complex>
#include <locale>
using namespace std;
#define Debug(x) cerr << #x << " = " << x << endl
#define Debug22(x,y) cerr<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<endl;
#define Debug2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define Debug3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<")\n";
#define Debug_arr(v,n) for(int i=0;i<n;++i) cerr<<#v<<"["<<i<<"]"<<" = "<<v[i]<<endl;
#define SET(p,v) fill((__typeof(**p)*)p,(__typeof(**p)*)p+sizeof(p),v);
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define prl cerr << "called: " << __LINE__ << endl
#define all(s) s.begin(),s.end()
int n,m,a[200005];
map <int,int> mp;
int main()
{
	cin>>n;
	for (int i=0;i<n;++i) cin>>a[i],mp[a[i]]++;
	cin>>m;
	for (int j=0;j<m;++j) 
	{
		int x;
		cin>>x;
		if (mp[x])
		{
			mp[x]--;
		}
		else
		{
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
 

int main(){
    string s;cin >> s;
    for (int i = 0; i < s.length()-1; i++) {
        if(s[i]==s[i+1]){
            puts("Bad");
            return 0;
        }
    }
    puts("Good");
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    allXor = a[0]^a[1]
    for i in range(2,N):
        allXor ^= a[i]
    s = ""
    for i in range(len(a)):
        isLast = (len(a) -1 ==i)
        c = str(allXor^a[i])
        if not isLast:
            s += c + " "
        else:
            s+=c
    print(s)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 37592
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    ll N,M,V,P;
    cin>>N>>M>>V>>P;
    vector<ll> A(N);
    REP(i,N) cin>>A[i];
    sort(rAll(A));
    int ans=0;
    ll sum=0;
    ll s=min(V-1,P-1);
    REP(i,N){
        if(i<P){
            ans++;
            continue;
        }
        if(s==V-1){
            if(A[i]+M>=A[P-1]) ans++;
            continue;
        }
        ll t=min(V-s-1,N-i-1);
        if(s+1+t==V){
            if(A[i]+M>=A[P-1]) ans++;
            sum+=A[P-1]-A[i];
            continue;
        }
        ll num=V-s-1-t;
        if(num*M<=sum){
            if(A[i]+M>=A[P-1]) ans++;
            sum+=A[P-1]-A[i];
            continue;
        }
        ll vote=num*M-sum;
        if(A[i]+M>=A[P-1]+(vote-1)/(i-(P-1))+1) ans++;
        sum+=A[P-1]-A[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
	"sort"
	"strconv"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	mp1, mp2, arr := make(map[int][]int), make(map[string]string), make([]string, m)
	for i := 0; i < m; i++ {
		var p, y int
		fmt.Scan(&p, &y)
		a, ok := mp1[p]
		if ok {
			mp1[p] = append(a, y)
		} else {
			mp1[p] = []int{y}
		}
		key := strconv.Itoa(p) + "-" + strconv.Itoa(y)
		arr[i] = key
	}
	for k := range mp1 {
		sort.Sort(sort.IntSlice(mp1[k]))
	}
	for k, v := range mp1 {
		for i, j := range v {
			vv := fmt.Sprintf("%06d%06d", k, i + 1)
			key := strconv.Itoa(k) + "-" + strconv.Itoa(j)
			mp2[key] = vv
		}
	}
	for _, i := range arr {
		fmt.Println(mp2[i])
	}
}

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

string s;
int i;
map<string,int> chem;

int inner_morecule();
int number();
int atom();

int morecule(){
	int ret=0;
	while(s[i]!='$' && s[i]!=')'){
		int val=inner_morecule();
		if(val==-1) return -1;
		ret+=val;
	}
	return ret;
	
}

int inner_morecule(){
	int ret=0;
	if(s[i]=='('){
		i++;
		ret=morecule();
		i++;
	}else{
		ret=atom();
		if(ret==-1) return -1;
	}
	return ret*number();
}

int number(){
	int ret=0;
	while(isdigit(s[i])){
		ret=ret*10+s[i++]-'0';
	}
	return ret?ret:1;
}

int atom(){
	string ret=s.substr(i,1);
	i++;
	if(islower(s[i])){
		ret+=s[i];
		i++;
	}
	if(chem.find(ret)==chem.end()){
		return -1;
	}
	return chem[ret];
}

string solve(){
	int val=morecule();
	if(val==-1) return "UNKNOWN";
	return to_string(val);
}

int main(){
	{	string tmp;
		while(cin>>tmp,tmp!="END_OF_FIRST_PART"){
			int n; cin>>n;
			chem[tmp]=n;
		}
	}
	while(cin>>s,s!="0"){
		i=0;
		s+="$";
		cout<<solve()<<endl;
	}
	return 0;
}



Measured memory_bytes: 3136
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

struct edge {
    int next;
    int id;
};

int main() {
    int n; cin >> n;
    vector<vector<edge>> ab(n);
    for (int i = 0; i < n-1; i++)
    {
        int a, b; cin >> a >> b;
        a--; b--;
        ab[a].push_back((edge){b, i});
        ab[b].push_back((edge){a, i});
    }
    vector<int> ans(n);
    auto rec = [&](auto &&rec, int now, int before, int bcolor) -> void {
        int color = 1;
        for (auto n : ab[now]) {
            int next = n.next;
            int eid = n.id;

            if (next == before) continue;
            if (color == bcolor) color++;
            ans[eid] = color;
            // cout << eid << ' ' << now << ' ' << next << ' ' << color << endl;
            rec(rec, next, now, color);
            color++;
        }
    };
    
    rec(rec, 0, 0, 0);
    int mx=0;
    for (int i = 0; i < n-1; i++)
    {
        mx = max(ans[i], mx);
    }
    cout << mx << endl;
    for (int i = 0; i < n-1; i++)
    {
        cout << ans[i] << endl;
    }
    

    return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1LL<<60;
const int INF = 1LL<<17;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

ll bit[500500];
ll n;
#define N 500010

ll sum(ll i){
    ll res=0;
    while(0<i){
        res += bit[i];
        i -= i&-i;
    }
    return res;
}
void add(ll i, ll x){
    while(i<=n){
        bit[i] += x;
        i += i&-i;
    }
}


ll rsum(ll l, ll r){
    return sum(r)-sum(l-1);
}
vector<vector<ll>> qr(N), qri(N);
vector<ll>  c(N), res(N);
int main(){
    ll q;   cin >> n >> q;


    rep(i, n) cin >> c[i+1];
    vector<ll> a(N);
    rep(i, q){
        ll a, b;    cin >> a >> b;
        qr[b].push_back(a);
        qri[b].push_back(i);
    }

    FOR(i, 1, n+1){
        if(a[c[i]]>0) add(a[c[i]], -1);
        add(i, 1);
        a[c[i]] = i;
        rep(j, qr[i].size()){
            res[qri[i][j]] = rsum(qr[i][j], i);
        }
    }
    rep(i, q) cout << res[i] << endl;
}


Measured memory_bytes: 62728
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    char c;
    cin >> c;
    cout << (char)(c + 1) << endl;
    return 0;
}


Measured memory_bytes: 3536
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = 10000000000


def main():
    # ------ 入力 ------#
    n = int(input())    # 数字

    # 定数行入力
    x = n
    dList = [list(map(int, input().split())) for _ in range(x)]     # スペース区切り連続数字(行列)

    # ------ 処理 ------#
    flg = 1
    for i in range(n-2):
        if dList[i][0] == dList[i][1]:
            if dList[i+1][0] == dList[i+1][1]:
                if dList[i+2][0] == dList[i+2][1]:
                    flg = 0

    # ------ 出力 ------#
    if flg == 0:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()


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


int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int c=0;
    for(int i=0;i<s1.length();i++)
    {
        if(s1[i]!=s2[i])
            c++;
    }
    cout<<c;
}

Measured memory_bytes: 3852
#include<cstdio>
#include<algorithm>
int a[100000], b[100000];
int main() {
	int n, h, i;
	scanf("%d%d", &n, &h);
	for (i = 0; i < n; i++) {
		scanf("%d%d", &a[i], &b[i]);
	}
	std::sort(a, a + n, [](const int& a, const int& b) {return a > b; });
	std::sort(b, b + n, [](const int& a, const int& b) {return a > b; });
	i = 0;
	while (h>0&&i<n&&a[0] < b[i]) {
		h-= b[i];
		i++;
	}
	if (h>0) {
		i += h / a[0];
		if (h % a[0] != 0) {
			i++;
		}
	}
	printf("%d", i);
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define revstr(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b)
{
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s)
{
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
// ll nck(ll N,ll K,ll mod)
// {
// 	if(N<K)
// 	{
// 		return 0;
// 	}
// 	return (((facs[N]*facsinv[N-K])%mod)*facsinv[K])%mod;
// }
ll power(ll x,ll y,ll p)
{
	ll res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		{
			res=(res*x)%p;
		}
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x,ll mod)
{
	if(x>=mod)
	{
		x%=mod;
	}
}
// void checktime()
// {
// 	struct timespec ts;
// 	printf("Running Program\n");
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double st=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	// Call Funcn Here
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double en=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	printf("Program ended\nTime = %Lf\n",en-st);
// }
ll A[200005],F[200005];
ll check(ll N,ll K,ll m)
{
	ll sum=0,maxi=-1;
	forl(i,N)
	{
		sum+=(A[i]-min(A[i],m/F[i]));
		maxi=max(maxi,min(A[i],m/F[i])*F[i]);
	}
	if(sum<=K)
	{
		return maxi;
	}
	else
	{
		return -1;
	}
}
int main(void)
{
	fastio
	ll N,K;
	cin>>N>>K;
	forl(i,N)
	{
		cin>>A[i];
	}
	forl(i,N)
	{
		cin>>F[i];
	}
	sort(A,A+N);
	sort(F,F+N,greater <ll> ());
	ll l=0,r=1e18;
	ll ans=-1;
	forl(i,N)
	{
		ans=max(A[i]*F[i],ans);
	}
	while(l<=r)
	{
		ll m=l+(r-l)/2;
		ll tmp;
		if((tmp=check(N,K,m))==-1)
		{
			l=m+1;
		}
		else
		{
			ans=min(ans,tmp);
			r=m-1;
		}
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3328
n, m = map(int, input().split())

ac = [False] * n
wa = [0] * n
res_ac = 0
res_wa = 0
for _ in range(m):
    p, s = input().split()
    p = int(p)

    if s == "AC":
        if not ac[p-1]:
            ac[p-1] = True
            res_ac += 1
            res_wa += wa[p-1]
    else:
        wa[p-1] += 1

print(res_ac, res_wa)

Measured memory_bytes: 51176
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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

    int n; cin >> n;
    string s; cin >> s;
    int cnt = 0;

    rep(i,10) rep(j,10) rep(k,10){
        bool first=true,second=false,third=false,good=false;
        rep(index, n){
            int x = s[index]-'0';
            if(first && x==i){
                first = false;
                second = true;
            } else if (second && x==j){
                second = false;
                third = true;
            } else if (third && x==k){
                good = true;
            }
        }

        if(good) cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String input = br.readLine();
		String[] tmpArray = input.split(" ");
		int n = Integer.parseInt(tmpArray[0]);
		int hp = Integer.parseInt(tmpArray[1]);
		
//		int[] attack = new int[n];
//		int[] throwAtk = new int[n];
		Attack attack[] = new Attack[2*n];
		
//		int throwSum = 0;
//		int maxAtk = 0;
		for(int i = 0; i < n; i++){
			tmpArray = br.readLine().split(" ");
			int a = Integer.parseInt(tmpArray[0]);
			int b = Integer.parseInt(tmpArray[1]);
			attack[2*i] = new Attack(a, true);
			attack[2*i + 1] = new Attack(b, false);
//			throwSum += throwAtk[i];
//			maxAtk = Math.max(maxAtk, attack[i]);
		}
		
		int result = 0;
		Arrays.sort(attack);
		
		for(int i = 2*n - 1; i >= 0 ; i--){
			if(attack[i].unlimited){
//				System.out.println("attack");
				if(hp % attack[i].damage != 0){
					result++;
				}
				result += hp/attack[i].damage;
				break;
			}
			else {
//				System.out.println("throw");
				hp -= attack[i].damage;
				result++;
				if(hp <= 0){
					break;
				}
			}
		}
		
		System.out.println(result);
	}

}

class Attack implements Comparable<Attack>{
	int damage;
	boolean unlimited;
	public Attack(int damage, boolean unlimited){
		this.damage = damage;
		this.unlimited = unlimited;
	}
	public int compareTo(Attack atk) {
		// TODO Auto-generated method stub
		return this.damage - atk.damage;
	}
	
	
}

Measured memory_bytes: 52236
#include <stdio.h>
#include<vector>
#include<math.h>
#include<string>

typedef long long ll;
typedef unsigned short int unsi;
typedef unsigned int uni;
typedef unsigned long int unli;

using namespace std;

unsi gojoho(unsi A, unsi B) {
	unsi R = 1;
	if (A > B) {
		while (R!=0) {
			R = A % B;
			A = B;
			B = R;
		}
		return A;
	} else {
		while (R != 0) {
			R = B % A;
			B = A;
			A = R;
		}
		return B;
	}
}

uni gojoho(uni A, uni B) {
	uni R = 1;
	if (A > B) {
		while (R != 0) {
			R = A % B;
			A = B;
			B = R;
		}
		return A;
	} else {
		while (R != 0) {
			R = B % A;
			B = A;
			A = R;
		}
		return B;
	}
}

unli gojoho(unli A, unli B) {
	unli R = 1;
	if (A > B) {
		while (R != 0) {
			R = A % B;
			A = B;
			B = R;
		}
		return A;
	} else {
		while (R != 0) {
			R = B % A;
			B = A;
			A = R;
		}
		return B;
	}
}

int gojoho(int A, int B) {
	int R = 1;
	if (A > B) {
		while (R != 0) {
			R = A % B;
			A = B;
			B = R;
		}
		return A;
	} else {
		while (R != 0) {
			R = B % A;
			B = A;
			A = R;
		}
		return B;
	}
}



int main(){
	int A, B;
	scanf("%d%d", &A, &B);
	
	if (A <= 5) {
		printf("%d", 0);
	}else if (A <= 12) {
		printf("%d", B / 2);
	}
	else {
		printf("%d", B);
	}

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

/*** Loops ***/
#define ip(n) ll n; cin>>n;
#define ip2(n,k) ll n; cin>>n; ll k; cin>>k;
#define ff1(i,a,b) for(ll i = a; i < b; i++)
#define ff2(i,a,b) for(ll i = b-1; i >= a; i--)

/*** STLs ***/
#define vvll vector<vll>
#define pb push_back
#define mem(name, value) memset(name, value, sizeof(name))
#define MN3(n1,n2,n3) min(n1,min(n2,n3))
#define MN4(n1,n2,n3,n4) min(n1,min(n2,min(n3,n4)))
#define MX3(n1,n2,n3) max(n1,max(n2,n3))
#define MX4(n1,n2,n3,n4) max(n1,max(n2,max(n3,n4)))
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))

/***input loops***/
#define ipve(vc,n) vll vc(n); ff1(i,0,n){cin>>vc[i];}
#define ipvc(vc,n) vll vc; ff1(i,0,n){ip(x);vc.pb(x);}



/*** Typedef ***/
typedef long long ll;
//typedef long long lli;
typedef long long int lli;
typedef unsigned long long ull;
typedef    long double   ld;

// DEBUG
#ifdef LOCAL // compile with -DLOCAL
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

using namespace std;
int main(){

	ios::sync_with_stdio(false);
    cin.tie(0);//this reduced the time by 2ms
    
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif
    ll sum=0;
    ip(n);
    ip(k);
    ll v[n];
  //  ipvc(v,n); srt(v);
    ff1(i,0,n){
        cin>>v[i];
    }
    sort(v,v+n);
    ff1(i,0,k){sum+=v[i];}
    cout<<sum;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
using ll = long long;

int main(){
    int n,m;
    cin >> n >> m;
    dsu d(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        d.merge(a,b);
    }
    int cnt = d.groups().size();
    int ans = cnt -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8852
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  unsigned long long  N;
  unsigned long long result=0;

  cin >> N;

  for(int i=1; i <= N ;i++){
  
    if((i % 3 ==0)||(i % 5 ==0)){
    }else{
      result += i;
    }
  }

  cout << result << endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>  // std::greater<T>()

using namespace std;

// macro
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define DESCEND greater<int>()  // sort 降順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから

// func declaration
template <class T> void printVec(vector<T>);
template <class T> void calcVec(vector<T>&, int, char);
bool checkMultiple(vector<int>&, int);

/*MEMO
辞書順
abc < abcd, atcoder < atlas
*/

int main() {
    int N;
    cin >> N;
    vector<int> vec;

    REP(i, N) {
        int num;
        cin >> num;
        if (num%2 != 0) {
            break;
        } else {
            vec.push_back(num);
        }
    }

    if (vec.size() == N) {
        int count = 0, num = 2;

        while (checkMultiple(vec, num)) {
            calcVec(vec, num, '/');
            count++;
        }
        cout << count << endl;
    } else{
        cout << 0 << endl;
    }

    
    return 0;
}

// function
template <class T> void printVec(vector<T> vec) {
    // 1要素ずつ、空白・改行なしで出力
    REP(i, vec.size()) {
        cout << vec.at(i);
    }
    cout << endl;
}

template <class T> void calcVec(vector<T> &vec, int num, char ch) {
    // vec全体への演算
    if (ch == '+') {
        REP(i, vec.size()) {
            vec.at(i) += num;
        }
    } else if (ch == '-') {
        REP(i, vec.size()) {
            vec.at(i) -= num;
        }
    } else if (ch == '*') {
        REP(i, vec.size()) {
            vec.at(i) *= num;
        }
    } else if (ch == '/'){
        REP(i, vec.size()) {
            vec.at(i) /= num;
        }
    } else if (ch == '%') {
        REP(i, vec.size()) {
            vec.at(i) %= num;
        }
    }
}

bool checkMultiple(vector<int> &vec, int num) {
    // vecの中身が、numの倍数かどうかのチェック
    int count = 0;
    REP(i, vec.size()) {
        if (vec.at(i)%num != 0) count++;
    }
    return (count == 0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
const ll mo=1000000007;
const ll INF=1<<30;
ll ans=0;
ll h,w,n;

bool in(ll x,ll y){
    return (x>=0&&y>=0&&x<w&&y<h);
}
int main()
{ 

cin >> h>>w>>n; 
ll r,c;
cin >> r>>c; 
string s,t;
cin >> s>>t; 

ll now=c;
rep(i,n){
    if(s[i]=='R')now++;
    if(now>w){
        cout << "NO" << endl;
        return 0;
    }
    if(t[i]=='L'&&now>1)now--;
}
now=c;
rep(i,n){
    if(s[i]=='L')now--;
    if(now<1){
        cout << "NO" << endl;
        return 0;
    }
    if(t[i]=='R'&&now<w)now++;
}
now=r;
rep(i,n){
    if(s[i]=='U')now--;
    if(now<1){
        cout << "NO" << endl;
        return 0;
    }
    if(t[i]=='D'&&now<h)now++;
}
now=r;
rep(i,n){
    if(s[i]=='D')now++;
    if(now>h){
        cout << "NO" << endl;
        return 0;
    }
    if(t[i]=='U'&&now>1)now--;
}

cout << "YES" << endl;
return 0;
} 

Measured memory_bytes: 904
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int N=200010;
const ll P=924844033;
int n;
vector<int>g[N];
int siz[N];
int rev[N<<2],lim,lev;
ll pwr(int ll x,ll y){
	if(!y)return 1;
	if(y&1)return pwr(x,y-1)*x%P;
	ll z=pwr(x,y/2);
	return z*z%P;
}
inline void ntt(ll *a,int t){
	for(int i=0;i<lim;i++)
		if(i<rev[i])
			swap(a[i],a[rev[i]]);
	for(int mid=1;mid<lim;mid<<=1){
		int rgt=mid<<1;
		ll wn=pwr(5,(P-1)/rgt);
		if(t==-1)wn=pwr(wn,P-2);
		for(int loc=0;loc<lim;loc+=rgt){
			ll w=1;
			for(int k=0;k<mid;k++){
				ll x=a[loc+k],y=w*a[loc+mid+k]%P;
				a[loc+k]=(x+y)%P;
				a[loc+mid+k]=(x-y+P)%P;
				w=w*wn%P;
			}
		}
	}
	if(t==-1){
		ll invlim=pwr(lim,P-2);
		for(int i=0;i<lim;i++)
			a[i]=a[i]*invlim%P;
	}
}
ll a[N<<2],b[N<<2];
ll fac[N],inv[N];
void dfs(int x,int f){
	siz[x]=1;
	int i,k;
	for(i=g[x].size()-1;~i;i--){
		k=g[x][i];
		if(k==f)continue;
		dfs(k,x);
		a[siz[k]]++;
		siz[x]+=siz[k];
	}
	a[n-siz[x]]++;
}
inline void init(){
	fac[0]=1;
	int i;
	for(i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%P;
	inv[n]=pwr(fac[n],P-2);
	for(i=n;i;i--)
		inv[i-1]=inv[i]*i%P;
}
int main(){
	int i;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].pb(y);
		g[y].pb(x);
	}
	dfs(1,0);
	for(i=1;i<n;i++)
		a[i]=P-a[i];
	a[n]=n;
	init();
	for(i=1;i<=n;i++)
		a[i]=a[i]*fac[i]%P;
	for(i=1;i<=n;i++)
		b[i]=inv[n-i];
	//(i)+(n-(i-k))=(n+k)
	lim=1;
	while(lim<=n*2){
		lim<<=1;
		lev++;
	}
	for(i=0;i<lim;i++)
		rev[i]=(rev[i>>1]>>1)|((i&1)<<(lev-1));
	ntt(a,1);
	ntt(b,1);
	for(i=0;i<lim;i++)
		a[i]=a[i]*b[i]%P;
	ntt(a,-1);
	for(i=1;i<=n;i++)
		printf("%lld\n",a[i+n]*inv[i]%P);
	return 0;
}

Measured memory_bytes: 45952
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

s = input()
t = input()

t = t[:-1]
if s==t:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 68348
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,x;
int res[300001];
bool used[300001];

int main(void){
	scanf("%d%d",&n,&x);
	if(n==2){
		printf("%s\n",x==2?"Yes":"No");
		if(x==2){
			printf("1 2 3\n");
		}
	}else{
		if(x==1 || x==2*n-1)printf("No\n");
		else{
			printf("Yes\n");
			res[n]=x;
			res[n-1]=x+1;
			res[n+1]=x-1;
			res[n-2]=1;
			if(x==2){
				res[n+2]=2*n-1;
				res[n+1]=x-1;
				res[n-1]=x+1;
				res[n-2]=0;
			}
			used[x]=true;
			used[x-1]=true;
			used[x+1]=true;
			if(x==2)used[2*n-1]=true;
			else used[1]=true;
			int now=1;
			for(int i=1;i<=2*n-1;i++){
				if(res[i]!=0)printf("%d\n",res[i]);
				else{
					while(used[now])now++;
					printf("%d\n",now);
					now++;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 1536