akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#define ll long long
using namespace std;

const int INF = (1<<31)-1, MAX_N = 1<<17;

int N;
ll dat[2*MAX_N -1];

void init( int n_ )
{
    N = 1;
    while( N < n_ )
        N <<= 1;
 
    for(int i=0; i < 2*N-1; i++)
        dat[i] = INF;
 
    return;
}
 

void update(int k, int a){
    k += N - 1;
    dat[k] = a;
    while(k > 0){
        k = ( k - 1 ) / 2;
        dat[k] = min(dat[ k * 2 + 1 ], dat[ k * 2 + 2 ]);
    }
    return;
}

ll query(int a, int b, int k, int l, int r){
    if( r <= a || b <= l ){
        return INF;
    }
    if( a <= l && r <= b ){
        return dat[k];
    }else{
        ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
}

int main(void){
    int n, q;
    cin >> n >> q;

    init(n);
    
    for(int i=0; i<q; i++){
        ll com, x, y;
        cin >> com >> x >> y;
        
        if(com == 0){
            update(x, y);
        }else{
            cout << query(x, y+1, 0, 0, N) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5124
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String s = scanner.nextLine();
        char[] sArr = s.toCharArray();
        Arrays.sort(sArr);
        s = new String(sArr);

        String t = scanner.nextLine();
        char[] tArr = t.toCharArray();
        Arrays.sort(tArr);
        t = new StringBuilder(new String(tArr)).reverse().toString();

        if (s.compareTo(t) < 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23764
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0;
    cin>>n;
    int a[n+1];
    int pre[n+1];
    pre[0]=0;
    for(int i=1;i<=n;++i)
    {
        cin>>a[i];
        pre[i]=pre[i-1]+a[i];
    }
    int ans=INT_MAX;
    for(int i=1;i<=n;++i)
    {
        int diff=abs(pre[n]-2*pre[i]);
        ans=min(ans,diff);
    }
    cout<<ans<<endl;
}

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

int main(){
  double N;
  cin >> N;
  vector<int> v(N);
  for(int i=0; i<N; i++) cin >> v.at(i);
  sort(v.begin(), v.end());
  double ans=v.at(0);
  for(int i=0; i<N-1; i++){
    ans = (ans + v.at(i+1))/2;
  }
  std::cout << std::setprecision(15)<< ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF INT_MIN 
#define INF INT_MAX 
#define MP make_pair
#define int ll int

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef map<int,int>MII;
typedef vector<int> VI;
const int MAX = 1e4 + 5;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/
//int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1 
//int root(int x){return x==f[x]?x:f[x]=root(f[x]);}


signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{
    int n,d,a;
    cin>>n>>d>>a;
    vector<PII>ar(n);
    for(int i=0;i<n;i++)
    {
        cin>>ar[i].FI>>ar[i].SE;
    }
    sort(all(ar));
    int ans=0;int pointer=NINF;int amount=0;vector<PII>re;int sum=0;
    for(int i=0;i<n;i++)
    {  int x1=0;
        for(auto it:re)
        {
            if(it.FI<ar[i].FI){x1++;sum-=it.SE;}
            else
            {
                break;
            }
        }
        
        for(int i=0;i<x1;i++)re.erase(re.begin());
        ar[i].SE-=sum*a;
        //cout<<ar[i].SE<<" ";
        if(ar[i].SE>0)
        {
            int x=(ar[i].SE-1)/a+1;
            sum+=x;
            ans+=x;
            re.pb({ar[i].FI+2*d,x});
        }
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
}


return 0;
}





Measured memory_bytes: 5620
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int ans=0;
  while(a>0&&b>0){
    c-=b;
    if(c<=0){
      ans=1;
      break;
    }
    a-=d;
  }
  if(ans==1)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3624
//
//  main.cpp
//  C
//
//  Created by Charles on 2017/12/23.
//  Copyright © 2017年 Charles. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
ll a,b;
int main(int argc, const char * argv[]) {
    while(~scanf("%lld%lld",&a,&b)){
        int ans=0;
        ll tmp=a;
        while(tmp<=b){
            tmp<<=1;
            ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

N = int(input())
A = list(map(int, input().split()))

def log2(i):
	cnt = 0
	while i % 2 == 0:
		i = i // 2
		cnt += 1
	return cnt


minimum = 1000

for i in A:
    minimum = min(minimum, log2(i))
	
print(minimum)



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin >> n >> m;
    vector<tuple<long long int,long long int,int> > v1,v2; //v1は県,年,入力順
    for(int i = 0;i < m;i++)
    {
        int p;
        long long int y;
        cin >> p >> y;
        v1.push_back(make_tuple(y,p,i));
    }
    sort(v1.begin(),v1.end());
    int number[100000] = {};
    for(int i = 0;i < m;i++)
    {
        v2.push_back(make_tuple(get<2>(v1[i]),get<1>(v1[i]),number[get<1>(v1[i]) - 1] + 1));
        number[get<1>(v1[i]) - 1]++;
    }
    sort(v2.begin(),v2.end());
    for(int i = 0;i < m;i++)
    {
        cout << setw(6) << setfill('0') << get<1>(v2[i]);
        cout << setw(6) << setfill('0') << get<2>(v2[i]) << "\n";
    }

    return 0;
}

Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int N,M; cin >> N >> M;
    vector<vector<int>> v(N,vector<int>(2));
    int ac = 0; int pena = 0;
    for(int i=0;i<M;i++){
        int p; string S; cin >> p >> S;
        if(v[p-1][1] == 0){
            if(S=="WA") v[p-1][0]++;
            else v[p-1][1] = 1;
        }
    }

    for(int i=0;i<N;i++){
        if(v[i][1] == 1){
            ac++; pena+=v[i][0];
        }
    }
    cout << ac << ' ' << pena << endl;
}




Measured memory_bytes: 5760
#from heapdict import heapdict
import sys
import heapq
input=sys.stdin.readline

def dijkstra(G,start,n):#グラフ,初期頂点,頂点数
    INF=2<<28
    dist=[INF]*n;dist[start]=0
    used=[False]*n;used[start]=True
    q=[]

    for v in G[start]:
        heapq.heappush(q,v)
    
    while len(q)>0:
        now1,now2=heapq.heappop(q)
        #print(now1,now2)
        if used[now2]:
            continue
        v=now2
        dist[v]=now1
        used[v]=True

        for e1,e2 in G[v]:
            if not used[e2]:
                heapq.heappush(q,(e1+dist[v],e2))

    return dist

def main():
    N=int(input().rstrip())
    g=[[] for _ in range(N)]
    for _ in range(N):
        u,k,*c=map(int,input().split())
        for j in range(0,k*2,2):
            g[u].append((c[j+1],c[j]))

    ans=dijkstra(g,0,N)
    for i,x in enumerate(ans):
        print(i,x)

if __name__=="__main__":
    main()


Measured memory_bytes: 92724
n,k,s = map(int,input().split())
ans = []
if k == 0:
    a = 10**9
    if s == 10**9:
        a -= 1
    for i in range(n):
        ans.append(a)
elif n == k:
    for i in range(n):
        ans.append(s)
else:
    a = s
    b = 10**9
    if s == 10**9:
        b -= 1
    for i in range(k):
        ans.append(a)
    for i in range(n-k):
        ans.append(b)
print(*ans)

Measured memory_bytes: 6680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n, d;
    cin >> n >> d;
    ll ans = (n+2*d)/(2*d+1);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long int i,j,k,l,n,t,save=1;
	cin>>n>>k;
	long long int a[k+1],b[n];
	map<long long int,long long int>m;
	for(i=0;i<n;i++)
	{
	cin>>b[i];
	m[b[i]]=1;
    }
	a[0]=0;
	for(i=1;i<k+1;i++)
	{
		save=1;
	if(m[i]==1)
	a[i]=1;
	else
	{
		for(j=0;b[j]<=i&&j<n;j++)
		{
			if(a[i-b[j]]==0)
			{
				save=0;
			}
		}
		a[i]=save^1;
		}	
	}
	if(a[k]==1)
	cout<<"First";
	else
	cout<<"Second";
	return 0;
}

Measured memory_bytes: 7296
#include <algorithm>
#include <iostream>
using namespace std;
 
int main(){
  int a[3];
  for(int i = 0; i < 3; ++i)
    cin >> a[i];
  sort(a,a+3);
  if((a[0] == a[1]) ^ (a[2] == a[1])) puts("Yes");
  else puts("No");
}

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

// Shortening code
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;

// Macros
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = a; i >= b; i--)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    // Your code
    int n, W;
    cin >> n >> W;

    vi w(n), v(n);
    REP(i, 0, n)
    {
        cin >> w[i] >> v[i];
    }

    vector<ll> dp(W + 1, 0);
    REP(i, 0, n){
        RREP(x, W - w[i], 0){
            dp[w[i] + x] = max(dp[w[i] + x], dp[x] + v[i]);
        }
    }
    cout << dp[W];

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

#define REP(i,n,m) for(i=n;i<m;i++)
#define rep(i,n) REP(i,0,n)

int h,w;
int ans;
int flg[10],t[10][10000];

int count(void){
  int i,j;
  int tmp, res = 0;

  rep(j,w){
    //1の数を数える
    tmp = 0;
    rep(i,h) if(flg[i] && !t[i][j] || !flg[i] && t[i][j]) tmp++;

    if(tmp < h - tmp) //j列目を裏返した方がいい
      res += h - tmp;
    else //j列目を裏返さない方がいい
      res += tmp;
  }

  return res;
}

void solve(int idx){
  int res;

  if(idx == h){
    res = count();
    if(ans < res) ans = res;
    return;
  }

  //idx行目を裏返さない
  flg[idx] = 0;
  solve(idx+1);

  //idx行目を裏返す
  flg[idx] = 1;
  solve(idx+1);
}

int main(void){
  int i,j;

  while(scanf("%d%d",&h,&w) && (h||w)){
    rep(i,h) rep(j,w) scanf("%d",&t[i][j]);
    ans = 0;
    solve(0);
    printf("%d\n",ans);
  }

  return 0;
}

Measured memory_bytes: 1416
#include<iostream>
#include<utility>

long GCD(long, long);
long LCM(long, long);

int main()
{
    long a,b;
    while(std::cin >> a >> b)
    {
        if(a < b)
        {
            std::swap(a,b);
        }
        
        std::cout << GCD(a,b) << " ";
        std::cout << LCM(a,b) << std::endl;
    }
    return 0;
}

long GCD(long a, long b)
{
    if(a == 0 || b == 0) return 0;
    long r = a % b;
    if(r == 0) return b;
    return GCD(b,r);
}

long LCM(long a, long b)
{
    if(a == 0 || b == 0) return 0;
    return (a * b / GCD(a,b));
}

Measured memory_bytes: 1160
n,m = map(int,input().split())
ps = []
for i in range(m):
    ppss = [i for i in input().split()]
    ps.append(ppss)
ac = [0 for i in range(n)]
wa = [0 for i in range(n)]
for i in range(m):
    if ps[i][1] == 'AC':
        ac[int(ps[i][0])-1] = 1
    else:
        if ac[int(ps[i][0])-1] != 1:
            wa[int(ps[i][0])-1] += 1
for i in range(n):
    if ac[i] != 1:
        wa[i] = 0
print(sum(ac),sum(wa))

Measured memory_bytes: 27568
a, b = map(int, input().split())

ans = [["#" if i < 50 else "." for _ in range(100)] for i in range(100)]

for i in range(a - 1):
  rows =  (i // 50) * 2
  clms = (i % 50) * 2
  ans[rows * 2][clms] = "."

for i in range(b - 1):
  rows = (i // 50) * 2
  clms = (i % 50) * 2
  ans[99 - rows][clms] = "#"
  
print(100, 100)
for a in ans:
  print("".join(a))

Measured memory_bytes: 9292
import math
a=int(input())
for i in range(a):
    x1,y1,x2,y2,x3,y3=[float(j) for j in input().split()]
    A=x1**2+y1**2-x2**2-y2**2
    B=x2**2+y2**2-x3**2-y3**2
    x12=x1-x2
    x23=x2-x3
    y12=y1-y2
    y23=y2-y3
    x=(y23*A-y12*B)/(2*(x12*y23-x23*y12))
    if (y12==0):
        y=(B-2*x23*x)/(2*y23)
    else:
        y=(A-2*x12*x)/(2*y12)
    r=math.sqrt((x1-x)**2+(y1-y)**2)
    print('{:.3f} {:.3f} {:.3f}'.format(x,y,r))

Measured memory_bytes: 7772
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class Program {
    static Scanner cin = new Scanner();
    static void Main(string[] args) {
        int N = cin.Int();
        var A = cin.ArrayInt(N);
        int odd = 0;
        for (int i = 0; i < N; i++) {
            if (A[i] % 2 != 0) odd++;
        }

        Console.WriteLine(odd % 2 != 0 ? "NO" : "YES");
        Console.ReadLine();
    }
}

Measured memory_bytes: 24288
function Main(input){
	var tmp = input.split(" ");
	var num1 = Math.max(tmp[0], tmp[2]);
	var num2 = Math.min(tmp[1], tmp[3]);

	if(num2 < num1){
		console.log(0);
	}else{
		console.log(num2 - num1);
	}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
flg = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
A = [[0] * 3 for _ in range(3)]
for _ in range(N):
	b = int(input())
	for i in range(3):
		for j in range(3):
			if flg[i][j] == b:
				A[i][j] = 1

cond = 0

for i in range(3):
	if A[i].count(1) == 3:
		cond = 1
for j in range(3):
	if sum([A[k][j] for k in range(3)]) == 3:
		cond = 1


if sum([A[k][k] for k in range(3)]) == 3:
	cond = 1

if A[0][2]+A[1][1]+A[2][0] == 3:
	cond = 1

if cond == 1:
	print('Yes')
else:
	print('No')



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

// typedef long long ll;

// #define int ll
// #define all(v) v.begin(), v.end()
// #define reps(__i, a, b) for (int __i = a; i < b; i++)
// #define rep(__i, n) reps(__i, 0, n)

// const ll INF = (1ll << 60);
// const ll MOD = (ll)1e9 + 7;

double dp[3010][3010]; // i回投げた時j回表が出る確率

int main()
{
    int n;
    double p[3010];
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> p[i];

    dp[0][0] = 1;
    for (int i = 1; i <= n; i++)
    {
        dp[i][0] = dp[i - 1][0] * (1 - p[i]);
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
        }
    }
    double ret = 0;
    for (int i = (n + 1) / 2; i <= n; i++)
        ret += dp[n][i];

    printf("%.10f\n", ret);
}

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

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

  string ans="";
  int cnt=0;
  for (int i=0; i<s.size(); i++) {
    if (s[i] == 'B') {
      if (!ans.empty()) ans.erase(--cnt);
    } else {
      ans.push_back(s[i]); cnt++;
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int oo = 0x3f3f3f3f;
const int maxn = 2000 + 5;
const int mod = 1e9 + 7;
 
template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

int A, B;
LL C[maxn][maxn], D[maxn][maxn];

void init() {
    for(int i = 0; i < maxn; ++i) {
        C[i][0] = C[i][i] = 1;
        for(int j = 1; j < i; ++j) 
            C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod;
    }

    for(int i = 0; i < maxn; ++i) {
        D[i][0] = C[i][0];
        for(int j = 1; j < maxn; ++j)
            D[i][j] = (D[i][j-1] + C[i][j]) % mod;
    }
}

int main() {
#ifdef Wearry
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    init();
    cin >> A >> B;

    LL ans = 0;
    for(int i = 0; i <= A; ++i) {
        LL res = 0;
        for(int j = 1; j <= A - i; ++j) {
            res = (res + C[B - 1][j] * D[j - 1][A - i - j]) % mod;
        }
        ans = (ans + (i + 1) * res) % mod;
    }
    ans = (ans + A + 1) % mod;
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 63104
d=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for _ in range(d)]
score=0
prev=0
se=set()
for i in range(d):
    lis=[]
    if i//26>prev:
        se=set()
        prev=i//26
    for j in range(26):
        lis.append((s[i][j]-c[j],j))
    lis.sort(reverse=True)
    for j in range(26):
        if lis[j][1] not in se:
            se.add(lis[j][1])
            print(lis[j][1]+1)
            break

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


int main()
{
	//freopen("input16.txt","r",stdin);freopen("output16.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int i,t=0;
	string a;
	cin>>a;
	for (i=1;i<a.size();i++){
		if (a[i]!=a[i-1]){
			t++;
		}
	}
	cout<<t;
	return 0;
}

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

int main(){
    double R,G,NR,NG;
    cin>>R>>G;
    NG=G;
    while(R<0||G>4500){
        cin>>R>>G;
    }
    if(R>=G){
        while(1){
            NR=(R+NG)/2.0;
            if(NR<G){
                cout<<NG+1<<"\n";
                break;
            }
            NG--;
        }
    }
    else{
        while(1){
            NR=(R+NG)/2.0;
            if(NR>=G){
                cout<<NG<<"\n";
                break;
            }
            NG++;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int x=s.nextInt();
		int y=s.nextInt();
		int z=s.nextInt();
		int d=s.nextInt();
		long[] a=new long[x];
		long[] b=new long[y];
		long[] c=new long[z];
		Arrays.setAll(a,i->s.nextLong());
		Arrays.setAll(b,i->s.nextLong());
		Arrays.setAll(c,i->s.nextLong());
		Arrays.sort(a);
		Arrays.sort(b);
		Arrays.sort(c);

		PriorityQueue<Long> r=new PriorityQueue<>();
		r.add(-1L);

		for(int i=x-1;i>=0;--i){
			if(r.peek()>a[i]+b[y-1]+c[z-1])
				break;
			for(int j=y-1;j>=0;--j){
				if(r.peek()>a[i]+b[j]+c[z-1])
					break;
				for(int k=z-1;k>=0;--k){
					if(r.peek()>a[i]+b[j]+c[k])
						break;

					r.add(a[i]+b[j]+c[k]);
					if(r.size()>d)
						r.poll();
				}
			}
		}
		r.stream().sorted(Comparator.reverseOrder()).forEach(System.out::println);
	}
}

Measured memory_bytes: 91004
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
#include<cmath>
#include<string>
#include<iomanip>
#include <numeric>
#include <limits>
using namespace std;
 
int main()
{
long long x,y,z,p=0; cin>>x>>y>>z;
x-=(2*z);
while(x>=y)
{
    p++; x-=(y+z);
}
cout<<p;
return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;


int main(){
  int N;
  cin >> N;
  int P[N];
  for (int i = 0; i < N; i++){
    cin >> P[i];
  }
  int cnt = 1;
  int m = P[0];
  for (int i = 1; i < N; i++){
    if (min(P[i],m) == P[i]){
      cnt++;
      m = min(P[i],m);
    }
  }
  cout << cnt << endl;
}
    

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
    long N;
    cin >> N;
    
    long ans = N;
    //long ans1,ans2;
    for (long i=1; (float)i<sqrt((float)N)+1; i++) {
        long A=i;
        if (N%A==0) {
            long B=N/A;
            long kari_ans=0;
            if (A>B) {
                //ans1=A;
                //ans2=B;
                while (A!=0) {
                    kari_ans++;
                    A=A/10;
                }
            }
            else{
                //ans1=A;
                //ans2=B;
                while (B!=0) {
                    kari_ans++;
                    B=B/10;
                }
            }
            
            if (ans>kari_ans) {
                ans=kari_ans;
            }
        }
    }
    
    //cout << ans1 << endl << ans2 << endl;
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  ll N;
  cin >> N;
  vector<ll> A;
  rep(i, N) {
    ll a;
    cin >> a;
    A.push_back(a);
  }

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

  vector<pair<ll, ll>> P;
  for (ll i = 1; i < N - 1; i++) {
    pair<ll, ll> p;
    if (A[i] >= 0) {
      p = make_pair(A[0], A[i]);
      A[0] -= A[i];
    } else {
      p = make_pair(A[N - 1], A[i]);
      A[N - 1] -= A[i];
    }
    P.push_back(p);
  }

  pair<ll, ll> p = make_pair(A[N - 1], A[0]);
  P.push_back(p);
  ll result = A[N - 1] - A[0];

  cout << result << endl;
  for (pair<ll, ll> p : P) {
    cout << p.first << " " << p.second << endl;
  }

  return 0;
}


Measured memory_bytes: 4336
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int main(){
        vector<int> val,n;
        char cn;
        int a,b,sum=0;
        float avr=0;
        while(cin>>a>>cn>>b){
                val.push_back(a);
                n.push_back(b);
        }
        for(int i=0;i<n.size();i++){
                sum+=(n[i]*val[i]);
                avr+=n[i];
        }
        avr /= n.size();
        avr += 0.5;
        
        printf("%d\n%.0f\n",sum,avr);
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int k;
string s;

signed main() {
	cin >> k >> s;
	if ((int)s.size() <= k)cout << s << endl;
	else cout << s.substr(0, k) << "..." << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<long long> vl;
typedef vector<bool> vb;
#define int long long
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Maxn 4000007
const int INF = 1e9 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
void foo(){
    int n, k;
    cin>>n>>k;
    cout<<min(n%k, k-n%k);
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)foo();
}

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

void solve(long long &N, long long &K)
{
    long long n0;
    long long n1;
    long long a_n0, a_n1;
    n0 = N / K + 1;
    n1 = n0 + 1;
    a_n0 = N - K * (n0 - 1);
    a_n1 = abs(N - K * (n1 - 1));

    cout << ((a_n0 <= a_n1) ? a_n0 : a_n1) << endl;
}

// 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)
int main()
{
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 3696
#include<cstdio>
#include<cmath>
#include<algorithm>
#define MAXN 100006
using namespace std;
int n,x[MAXN],d[MAXN][30],L,Q,l,r,m;
int find(int p)
{
	int l=0,r=n;
	while(l<r)
	{
		int mid=(l+r+1)/2;
		if(x[mid]<=p) l=mid;
		else r=mid-1;
	}
	return l;
}
int cont(int l,int r)
{
	int re=0;
	while(l!=r)
	{
		int cnt=0;
		while(d[l][cnt]<r)
			cnt++;
		if(cnt!=0) cnt--;
		re+=1<<cnt;
		l=min(d[l][cnt],r);
	}
	return re;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&x[i]);
	scanf("%d",&L);
	scanf("%d",&Q);
	for(int i=1;i<=n;i++)
		d[i][0]=find(x[i]+L);//lower_bound(x+1,x+1+n,x[i]+L)-x;
	/*for(int i=1;i<=n;i++)
		printf("%d ",d[i][0]);*/
	for(int j=1;(1<<j)<=n*4;j++)
		for(int i=1;i<=n;i++)
			d[i][j]=d[d[i][j-1]][j-1];
	for(int i=1;i<=Q;i++)
	{
		scanf("%d%d",&l,&r);
		if(l>r) swap(l,r);
		printf("%d\n",cont(l,r));
	}
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+5,mo=1e9+7;
typedef long long LL;
char s[N];
void Inverse(int p,int a[],int n){//ÏßÐÔÇó<=nµÄÊý%pÒâÒåÏÂµÄÄæÔª 
	a[1]=1;
	for(int i=2;i<=n;i++){
		a[i]=1ll*(p-p/i)*a[p%i]%p;
	}
}
int inv[N],fac[N],pow25[N],pow26[N];
void init(int n){
	pow25[0]=pow26[0]=fac[0]=inv[0]=1;Inverse(mo,inv,n);
	for(int i=1;i<=n;i++)inv[i]=1ll*inv[i-1]*inv[i]%mo,fac[i]=1ll*i*fac[i-1]%mo,pow25[i]=25ll*pow25[i-1]%mo,pow26[i]=26ll*pow26[i-1]%mo;
}
int C(int n,int m){return 1ll*fac[n]*inv[m]%mo*inv[n-m]%mo;}
int main(){
	int k,l;scanf("%d%s",&k,s),l=strlen(s);
	LL ans=0;
	init(k+l);
	for(int i=0;i<=k;i++){
		(ans+=1ll*pow26[k-i]*pow25[i]%mo*C(l+i-1,i)%mo)%=mo;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 35952
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
 
      String S =sc.next();
      char[] a = S.toCharArray();
      
        if(a[0]==a[1]&& a[1]!=a[2]&& a[2]==a[3]){
          System.out.print("Yes");
        }
        else if(a[0]==a[2]&& a[2]!=a[3]&& a[3]==a[1]){
        System.out.print("Yes");
        }
        else if(a[0]==a[3]&& a[3]!=a[1]&& a[1]==a[2]){
         System.out.print("Yes");
        }else{
        System.out.print("No");
        }
    }
}

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

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RREP(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define ALL(r) (r).begin(), (r).end()

void Main() {
    // todo
    int n, a, b, x = 0, y = 0; string s;
    cin >> n >> a >> b >> s;
    rep(i, n) {
        if(s[i] == 'a' && x < a+b) {
            cout << "Yes" << endl;
            x++;
        } else if(s[i] == 'b' && x < a+b && y < b) {
            cout << "Yes" << endl;
            x++; y++;
        } else {
            cout << "No" << endl;
        }
    }
}

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


Measured memory_bytes: 848
#include <iostream>
#include <string>
 
int bomb_num(std::string S[], int y, int x, int H, int W)
{
  int result = 0;
  
  for(int i = y - 1; i <= y + 1; i++)
  {
    if(i < 0 || i >= H)
    {
      continue;
    }
    
    for(int k = x - 1; k <= x + 1; k++)
    {
      if(k < 0 || k >= W)
      {
        continue;
      }
      
      if(S[i][k] == '#')
      {
        result++;
      }      
    }
  } 
      
      
  return result;
}

int main()
{
  int H, W;
  std::string S[50];
  std::cin >> H >> W;
  
  for(int i = 0; i < H; i++)
  {
    std::cin >> S[i];
  }
  
  for(int i = 0; i < H; i++)
  {
    for(int k = 0; k < W; k++)
    {
      if(S[i][k] == '.')
      {
        std::cout << bomb_num(S, i, k, H, W);
      }
      else
      {
        std::cout << S[i][k];
      }
    }
    std::cout << "\n";
  }

  return 0;
}

Measured memory_bytes: 3168
import java.io.*;
import java.util.*;

class Main{
  static int n;
  public static void main(String args[])throws Exception{
    Scanner sc = new Scanner(System.in);
    int sum=0;
    n = sc.nextInt();
    int k = sc.nextInt();
    int list [] = new int[n];
    int max = 0;
    ArrayList<Integer> brock = new ArrayList<>();
    for(int i =0; i<n; i++){
      brock.add(sc.nextInt());
      sum+=brock.get(i);
      max = Math.max(max,brock.get(i));
    }
    int left = max;
    int right = sum;
    while (left < right) {
      int mid = (left + right) / 2;
      int count = 0;
      sum = 0;
      for (int i = 0; i < n; i++) {
        if (sum + brock.get(i) > mid) {
          sum = brock.get(i);
          count++;
        } else {
          sum += brock.get(i);
        }
        if (count == k) {
          break;
        }
      }
      if (count == k) {
        left = mid + 1;
      } else {
        right = mid;
      }
    }
    System.out.println(left);
  }
}
//   Collections.sort(brock, Collections.reverseOrder());
//   for(int i = 0; i<n; i++){
//     list[getmin(list)] += brock.get(i);
//   }
//   System.out.println(maxlist(list));
// }
//
// static int getmin(int list[]){
//   int min = 99999;
//   int min_n=0;
//   for(int i = 0; i<n; i++){
//     if(list[i]<min){
//       min = list[i];
//       min_n = i;
//     }
//   }
//   return min_n;
// }
//
// static int maxlist(int list[]){
//   int max = 0;
//   for(int i = 0; i<n; i++){
//     if(list[i]>max){
//       max = list[i];
//     }
//   }
//   return max;
// }


Measured memory_bytes: 72608
#include<bits/stdc++.h>
using namespace std;
int main()
{
     int h,s;
     long long sum=0;
    cin>>h>>s;
    long long arr[h];
    for(int i=0;i<h;i++)
    {
      cin>>arr[i];
    }
    sort(arr,arr+h);
    for( int i=0;i<max(0,h-s);i++)
    {
        sum+=arr[i];
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 1792
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long
#define MOD 1000000007
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
/*
    init : O(n)
    query : O(1)
    constraint : 1 < k <= n < (about 10^7), mod is a prime, k,n < mod

    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;

    p = (p / a) * a + (p % a)
    ( mod p * a^-1 for both ) <=> 0 = (p / a) + (p % a) * a^-1
    <=> - (p/a) = (p % a) * a^-1
    <=> a^-1 = - (p/a)^-1 * (p/a)
    <=> a^-1 = MOD - (p/a)^-1 * (p/a) % MOD

*/
const int MAX_K = 300000;
bool fact_initialized = false;
long long fact[MAX_K], fact_inv[MAX_K], inv[MAX_K];

// This will be automatically called during combination_mod
void combination_init(int mod)
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;

    for(int i = 2; i < MAX_K; ++i)
    {
        fact[i] = fact[i-1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i-1] * inv[i] % mod;
    }
}

// Used:
//   ABC151-E
long long combination_mod(int n, int k, int mod)
{
    if (n < k || n < 0 || k < 0) return 0;
    if(!fact_initialized)
    {
        combination_init(mod);
        fact_initialized = true;
    } 
    return fact[n] * (fact_inv[k] * fact_inv[n-k] % mod) % mod;
}
int main(){
    std::ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    ll ret = 0;
    for(ll i=k;i<=n+1;++i)
    {
        ll start = (0 + (i-1)) * i / 2;
        ll end = (n + (n - i + 1)) * i / 2;
        ret += end - start + 1;
        ret %= MOD;
    }
    cout << ret << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int a[3][3];
int d[3][3];

int main () {
  rep(i,3)rep(j,3) cin >> a[i][j];
  int n;
  cin >> n;
  rep(ni,n) {
    int x;
    cin >> x;
    rep(i,3)rep(j,3) if (a[i][j] == x) d[i][j] = 1;
  }
  bool ans = false;
  rep(i,3) {
    int cnt = 0;
    rep(j,3) cnt += d[i][j];
    if (cnt == 3) ans = true;
  }
  rep(i,3) {
    int cnt = 0;
    rep(j,3) cnt += d[j][i];
    if (cnt == 3) ans = true;
  }
  {
    int cnt = 0;
    rep(j,3) cnt += d[j][j];
    if (cnt == 3) ans = true;
  }
  {
    int cnt = 0;
    rep(j,3) cnt += d[j][2-j];
    if (cnt == 3) ans = true;
  }
  puts(ans?"Yes":"No");
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = read().rstrip().decode()


def test(S):
    N = len(S)
    words = []
    words.append(S)
    words.append(S[: (N - 1) // 2])
    words.append(S[(N + 1) // 2:])
    return all(T == T[::-1] for T in words)


print('Yes' if test(S) else 'No')


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

int main()
{
	int F[100];
	F[0]=1;
	F[1]=1;
	for(int i=2;i<45;++i){
		F[i]=F[i-2]+F[i-1];
	}

	int n;
	cin>>n;
	cout<<F[n]<<endl;
	return 0;
}

Measured memory_bytes: 3072
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
int a[105];
int main()
{
    int n,k;
    cin>>n>>k;
    for (int i=1;i<=n;i++)
        cin>>a[i];
    int suma=0;
    for (int i=1;i<=n;i++)
    {
        if (a[i]<k-a[i])
              suma+=2*a[i];
         else
            suma+=2*(k-a[i]);
    }
         cout << suma << endl;

    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc108a()
}

fun abc108a() {
    val k = readLine()!!.toInt()

    val evens = (1..k).count { it % 2 == 0 }
    val odds = (1..k).count { it % 2 != 0 }

    println(evens * odds)
}


Measured memory_bytes: 33436
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  $ans = 0;
  for ($i=0; $i<$n; $i++) {
    list($l, $r) = explode(" ", trim(fgets(STDIN)));
    $ans += ($r - $l + 1);
  }

  echo $ans;

Measured memory_bytes: 16204
#include<bits/stdc++.h>
using namespace std;
#define fast {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
typedef long long int ll;
typedef string S;
#define M 1e18
#define AS 250005
#define in(x)  cin>>x
#define o(x)  cout<<x
#define sp cout<<' '
#define nw cout<<endl
#define rt return
#define fr(i,a,n) for(ll i=a;i<=n;i++)
#define frm(i,a,n) for(ll i=n;i>=a;i--)
#define P pair<ll,ll>
#define vc vector<ll>
#define pb push_back
#define MP map<ll,ll>
bool sortin(const pair<ll,ll> &e,const pair<ll,ll> &f){return (e.first<f.first);}
bool POT(ll x){return x && (!(x&(x-1)));}
ll i,j,k,l,m,n,p,q,r,a,b,c,x,y,z,ts,mn=1e18,mod=1e9+7;
ll ar[AS],br[AS],xr[AS];
int main()
{
    fast;
    in(n>>x);
    n-=__gcd(n,x);
    o(n*3);
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P  = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    if (isupper(s))
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "a" << endl;
    }

    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


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


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int N, H[20],i,j,Ans = 1;
	
	cin >> N;
	for (i = N; i>0 ; i--)
		cin >> H[i];

	for (i = 1; i < N; i++) {
		Ans += 1;
		for (j = i + 1; j <= N; j++) {
			if (H[i] < H[j]) {
				Ans -= 1;
				break;
			}
		}
	}

	cout << Ans;
	return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;

const ll linf = 1LL << 62;
const int inf = 999999;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll atcoder = int(1e9 + 7);

#define Endl endl
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define all(x) x.begin(),x.end()
#define atcoder(int)1e9+7
#define rep(i,n) for(int i = 0;i<n;i++)
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)


ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

int  main() {
	
	int n,a;
	cin >> n;
	int cnt = 0;
	rep(i, n) {
		cin >> a;
		if (a % 2 != 0)cnt++;
	}
	if (cnt % 2 != 0 ? pr("NO") : pr("YES"));


	return 0;

}

Measured memory_bytes: 256
w = input()

dict = {}
flag = 0

for i in range(97, 97+26):
    dict[chr(i)] = 0

for c in w:
    dict[c] += 1

for v in dict.values():
    if v % 2 == 1:
        flag = 1

if flag == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    string s, t;
    cin >> s >> t;
    
    auto is_match = [](const string s, const string t) {
        assert (s.length() == t.length());
        bool ret = true;
        repeat(i, s.length()) {
            if (s[i] == '?' || s[i] == t[i]) continue;
            ret = false;
        }
        return ret;
    };
    
    for (int i = s.length() - t.length(); i >= 0; --i) {
        string subs = s.substr(i, t.length());
        if (is_match(subs, t)) {
            repeat(j, i) {
                if (s[j] == '?') cout << 'a';
                else cout << s[j];
            }
            cout << t;
            repeat_from(j, i + t.length(), s.length()) {
                if (s[j] == '?') cout << 'a';
                else cout << s[j];
            }
            cout << endl;
            return 0;
        }
    }
    cout << "UNRESTORABLE" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 999999999
using namespace std;
int dist[100005],x,y,d,i,viz[100005],ok,n,m;
vector <pair<int,int>> G[100005];

void dfs(int node){
    viz[node] = 1;
    for(auto v: G[node]){
        int vecin = v.first;
        int d = v.second;
        if(vecin<node)
            d = -d;
        int new_dist = dist[node] + d;
        if(dist[vecin] != INF && dist[vecin] != new_dist)
            ok = 1;
        dist[vecin] = new_dist;
        if(viz[vecin] == 0)
            dfs(vecin);
    }
}

int main()
{
    cin>>n>>m;
    for(i=1;i<=100005;i++)
        dist[i]=INF;
    for(i=1;i<=m;i++)
    {
        cin>>x>>y>>d;
        if(x>y){
            swap(x,y);
            d = -d;
        }
        G[x].push_back(make_pair(y,d));
        G[y].push_back(make_pair(x,d));
    }

    for(i=1;i<=n;i++){
        if(viz[i]==0){
            dist[i] = 0;
            dfs(i);
        }
        if(ok==1){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";

    return 0;
}


Measured memory_bytes: 12416
#include<iostream>
#include<algorithm>
#include<cmath>
bool cmp(int a, int b){
	return a > b;
}
using namespace std;
int main(){
	int n;
	long long mid = 0;
	long long a[100010];
	cin >> n;
	for(int i = 0; i < n; i ++)cin >> a[i];
	sort(a, a + n, cmp);
	for(int i = 1; i < n; i ++){
		if(abs(a[0] - 2 * a[i]) <= abs(a[0] - 2 * mid))mid = a[i];
		else break;
	}
	cout << a[0] << ' ' << mid; 
}

Measured memory_bytes: 1024
from sys import stdin

input = stdin.readline

n, m = map(int, input().split())
h = list(map(int, input().split()))
eg = [[] for _ in range(n)]

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

ans = 0
for i in range(n):
    high = True
    for to in eg[i]:
        if h[i] <= h[to]:
            high = False
    if high:
        ans += 1
print(ans)


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

short max(short x,short y){if(x<y)return y; return x;}

int main(){
	static short imos[5005][5005]={0};
	int n,m,a,b,x;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d%d",&a,&b,&x);
		imos[a][b]=max(imos[a][b],x+1);
	}
	int ans=0;
	for(int i=1;i<=n;i++)for(int j=1;j<=i;j++){
		imos[i][j]=max(imos[i][j],max(imos[i-1][j]-1,imos[i-1][j-1]-1));
		if(imos[i][j]>0)ans++;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 48904
#-------------
N = int(input())
#-------------

if N%2 == 0:
  k = N//2
else:
  k = (N+1)//2

cmb = []
for i in range(1,k+1):
  cmb.append([i , N-i])
  
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)

ans = []
for i in range(k-1):
  X = digitSum(cmb[i][0])
  Y = digitSum(cmb[i][1])
  ans.append(X+Y)


if ans == []:
  print("2")
else:
  print(min(ans))

Measured memory_bytes: 16656
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		System.out.println(solve());
	}
	
	public static int solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
		}
		int sum = 0;
		Queue<Integer> q = new PriorityQueue<>();
		for (int i = 0; i < arr.length; i++) {
			q.add(arr[i]);
			if (arr[i] <= q.peek()) {
				sum++;
			}
		}
		return sum;
	}
}

Measured memory_bytes: 65228