akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define clr(a, b) memset(a, b, sizeof(a))
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REPD(i, a, b) for(int i=(int)(a)-1; i>=(int)(b); --i)
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const double pi = 3.141592653589793;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double ang = abs(0.5 * (60 *h - 11 *m)); 
    ang = min(ang, 360-ang);
    ang = ang * pi;
    ang /= 180;
    double res = a*a + b*b ;
    res -= 2 * a * b * cos(ang);
    res = sqrt(res);
    cout << setprecision(10) << fixed << res << '\n';
    return 0;
}


Measured memory_bytes: 4208
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  cout << a/100
    +(a - (a/100) * 100)/10
    +a - (a/100) * 100 - 10 * ((a - (a/100) * 100)/10) << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import *

def bfs(s):
    dist = [-1]*N
    dist[s] = 0
    q = deque([s])
    
    while q:
        v = q.popleft()
        
        for nv in G[v]:
            if dist[nv]==-1:
                dist[nv] = dist[v]+1
                q.append(nv)
    
    return dist

N = int(input())
G = [[] for _ in range(N)]

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

dist = bfs(0)
M = -1

for i in range(N):
    if dist[i]>M:
        M = dist[i]
        s = i

d = max(bfs(s))+1
dp = [False]*(d+1)
dp[1] = True

for i in range(3, d+1):
    dp[i] |= not dp[i-1]
    dp[i] |= not dp[i-2]

if dp[d]:
    print('First')
else:
    print('Second')

Measured memory_bytes: 114552
#include<bits/stdc++.h>
using namespace std;
int fnc(vector<int> a[],int i,int dp[])
{
	if(dp[i]!=-1)
	return dp[i];
	else
	{
		int j;
		dp[i]=0;
		for(j=0;j<a[i].size();j++)
		{
			dp[i]=max(dp[i],1+fnc(a,a[i][j],dp));
		}
		return dp[i];
	}
}
int main()
{
 int n,m;
 cin>>n>>m;
 vector<int> a[n+1];
 int i;
 i=m;
 while(i-->0)
 {
 	int x,y;
 	cin>>x>>y;
 	a[x].push_back(y);
 }
 int dp[n+1];
 int ans=0;
 for(i=1;i<=n;i++)
 dp[i]=-1;
 i=1;
 while(i<=n)
 {
 	if(dp[i]==-1)
 	 fnc(a,i,dp);	
	  ans=max(ans,dp[i]);
	  i++;
 }
 cout<<ans<<endl;
 return 0;
}


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

int main() {
  int K, S;
  int count;

  cin >> K >> S;
  
  for(int x = 0; x < K+1; x++){
    for(int y = x; y < K+1; y++){
      for(int z = y; z < K+1; z++){
        if(x+y+z == S){
          if(x == y && y == z){
            count += 1;
          }
          else if(x == y && y != z){
            count += 3;
          }
          else if(x != y && y == z){
            count += 3;
          }
          else{
            count += 6;  
          }
        }
      } 
    }
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
# ABC138D - Ki
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    def dfs(v, p):
        for u in T[v]:
            if u != p:
                cnt[u] += cnt[v]
                dfs(u, v)

    N, Q = tuple(map(int, input().split()))
    A = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    P = tuple(tuple(map(int, input().split())) for _ in range(Q))
    T = [[] for _ in range(N + 1)]  # T[i] := children of vertex i
    cnt = [0] * (N + 1)
    for a, b in A:  # set tree relations
        T[a] += [b]
        T[b] += [a]
    for p, x in P:  # increment on roots
        cnt[p] += x
    dfs(1, -1)
    print(*cnt[1:])


if __name__ == "__main__":
    main()

Measured memory_bytes: 303312
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>

using namespace std;

void solve(string S);

void solve(string S) {
  string ans;
  int l = stoi(S.substr(0, 2));
  int r = stoi(S.substr(2, 2));
  if (l >= 1 && l <= 12 && r >= 1 && r <= 12) {
    ans = "AMBIGUOUS";
  } else if (l >= 1 && l <= 12 && (r > 12 || r == 0)) {
    ans = "MMYY";
  } else if ((l > 12 || l == 0) && r >= 1 && r <= 12) {
    ans = "YYMM";
  } else {
    ans = "NA";
  }
  cout << ans << endl;
}

int main() {
  string S;
  cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
import numpy as np

# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#S = str(input())
N, K = map(int, input().split())

M = np.base_repr(N, K)
print (len(str(M)))



Measured memory_bytes: 12504
class SWAG():
    def __init__(self,unit,f):
        self.fold_r=[unit]
        self.fold_l=[unit]
        self.data_r=[]
        self.data_l=[]
        self.f=f
    def __refill_right(self):
        temp=[]
        n=len(self.data_l)
        for _ in range(n//2):
            temp.append(self.popleft())
        for _ in range(n//2,n):
            self.append(self.popleft())
        for t in temp[::-1]:
            self.appendleft(t)
    def __refill_left(self):
        temp=[]
        n=len(self.data_r)
        for _ in range(n//2):
            temp.append(self.pop())
        for _ in range(n//2,n):
            self.appendleft(self.pop())
        for t in temp[::-1]:
            self.append(t)
    def append(self,x):
        self.fold_r.append(self.f(self.fold_r[-1],x))
        self.data_r.append(x)
    def appendleft(self,x):
        self.fold_l.append(self.f(self.fold_l[-1],x))
        self.data_l.append(x)
    def pop(self):
        if not self.data_r:
            self.__refill_right()
        self.fold_r.pop()
        return self.data_r.pop()
    def popleft(self):
        if not self.data_l:
            self.__refill_left()
        self.fold_l.pop()
        return self.data_l.pop()
    def fold_all(self):
        return self.f(self.fold_r[-1],self.fold_l[-1])
n,k,*p=map(int,open(0).read().split())
c=[0]
for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),
*c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]
x=not f
s_min=SWAG(10**18,min)
s_max=SWAG(0,max)
*_,=map(s_min.append,p[:k-1])
*_,=map(s_max.append,p[1:k])
for i,(a,b,c)in enumerate(zip(p,p[k:],c)):
    f|=c
    s_min.append(p[i+k-1])
    s_max.append(b)
    if not c and(a!=s_min.fold_all()or b!=s_max.fold_all()):x+=1
    s_min.popleft()
    s_max.popleft()
print(x+f)

Measured memory_bytes: 28900
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

		while(true) {
			c -= b;
			if(c <= 0) {
				System.out.println("Yes");
				break;
			}
			a -= d;
			if(a <= 0) {
				System.out.println("No");
				break;
			}
		}

		sc.close();
	}
}


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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
	int n;
	cin >> n;
	vi a(n);
	REP(i, n) cin >> a[i];
	cout << accumulate(ALL(a), 0LL) - n << "\n";
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		scan.close();
		if(a==1)a=14;
		if(b==1)b=14;
		if(a>b)System.out.println("Alice");
		else if(a<b)System.out.println("Bob");
		else System.out.println("Draw");
	}
}

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

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

template <typename T, typename U>
bool chmin(T &a, const U &b){
  return (a > b ? a = b, true : false);
}

template <typename T, typename U>
bool chmax(T &a, const U &b){
  return (a < b ? a = b, true : false);
}

template <typename T, size_t N, typename U>
void fill_array(T (&a)[N], const U &v){
  std::fill((U*)a, (U*)(a + N), v);
}

template <typename T>
auto make_vector(int n, int m, const T &value){
  return std::vector<std::vector<T>>(n, std::vector<T>(m, value));
}

template <typename T>
std::ostream& operator<<(std::ostream &s, const std::vector<T> &a){
  for(auto it = a.begin(); it != a.end(); ++it){
    if(it != a.begin()) s << " ";
    s << *it;
  }
  return s;
}

template <typename T>
std::istream& operator>>(std::istream &s, std::vector<T> &a){
  for(auto &x : a) s >> x;
  return s;
}

/**
 * @title Union-find
 * @docs unionfind.md
 */
class UnionFind{
  std::vector<int> parent, depth, size;
  int count;

public:
  UnionFind(){}
  UnionFind(int n): parent(n), depth(n,1), size(n,1), count(n){
    std::iota(parent.begin(), parent.end(), 0);
  }
  
  int root_of(int i){
    if(parent[i] == i) return i;
    else return parent[i] = root_of(parent[i]);
  }
  
  bool is_same(int i, int j){return root_of(i) == root_of(j);}

  int merge(int i, int j){
    int ri = root_of(i), rj = root_of(j);
    if(ri == rj) return ri;
    else{
      --count;
      if(depth[ri] < depth[rj]){
        parent[ri] = rj;
        size[rj] += size[ri];
        return rj;
      }else{
        parent[rj] = ri;
        size[ri] += size[rj];
        if(depth[ri] == depth[rj]) ++depth[ri];
        return ri;
      }
    }
  }

  int size_of(int i){return size[root_of(i)];}

  int count_group(){return count;}
};


namespace solver{
  void init(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(12);
    std::cerr << std::fixed << std::setprecision(12);
    std::cin.exceptions(std::ios_base::failbit);
  }
  
  void solve(){
    int N, M; std::cin >> N >> M;
    UnionFind uf(N);
    for(int i = 0; i < M; ++i){
      int A, B; std::cin >> A >> B;
      --A, --B;
      uf.merge(A, B);
    }

    int ans = 0;

    for(int i = 0; i < N; ++i){
      chmax(ans, uf.size_of(i));
    }



    std::cout << ans << "\n";
  }
}

int main(){
  solver::init();
  while(true){
    try{
      solver::solve();
    }catch(const std::istream::failure &e){
      break;
    }
  }
  return 0;
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

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

    int sum = 0;
    rep(i, 0, m) {
        int a;
        cin >> a;
        sum += a;
    }
    if (n < sum) {
        cout << -1 << endl;
    } else {
        cout << n - sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3656
#pragma GCC optimize("Ofast")
#include"bits/stdc++.h"
using namespace std;

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


Measured memory_bytes: 256
import statistics

n=int(input())
a = list(map(int, input().rstrip().split()))


for i in range(len(a)):
    a[i] -= (i+1)
med = statistics.median(a)
b = [a_i-med for a_i in a] 
S=0
for i in b:
    S += abs(i)
    
print(int(S))

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

#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> v;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    const int N = 3;
    string s; cin >> s;

    int ans=700;
    for (int i = 0; i < N; i++)
        if (s[i] == 'o') ans += 100;
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int n;
    static int[,] map;
    static void Main()
    {
        n = int.Parse(Console.ReadLine());
        int[][] a = Enumerable.Repeat(0, 2).Select(_ => Console.ReadLine().Split(' ').Select(int.Parse).ToArray()).ToArray();
        map = new int[2, n];
        int[] dx = { 1, 0 };
        int[] dy = { 0, 1 };

        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < n; j++)
            {
                for(int k = 0; k < 2; k++){
                    int x = j - dy[k];
                    int y = i - dx[k];
                    int dv = 0;
                    if(x >= 0 && y >= 0)
                    {
                        dv = map[y, x];
                    }
                    map[i, j] = Math.Max(a[i][j] + dv, map[i, j]);
                }
            }
        }
        Console.WriteLine(map[1, n - 1]);
    }
    static void Show()
    {
        Console.WriteLine("----");
        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < n; j++)
            {
                Console.Write(map[i, j] + " ");
            }
            Console.Write('\n');
        }
        Console.WriteLine("----");
    }
}

Measured memory_bytes: 13524
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<20)
#define LLINF (1LL<<60)
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    if(n%2==0){
        int left=1,width=n+1,count=0;
        bool ishalf=false;//widthがnの半分以下の時true
        while(count!=m){
            width-=2;
            if(!ishalf&&width*2<=n){
                width--;
                ishalf=true;
            }
            cout<<left<<' '<<left+width<<endl;
            left++;
            count++;
        }
    }
    else{
        for(int i=1;i<=m;i++){
            cout<<i<<' '<<n-i<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3632
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を素因数分解する。
# 3. 2.の結果に含まれる素因数の種類の数＋１が答え

def main():
  a, b = sorted(list(map(int, input().split())), reverse = True)
  while b != 0: a, b = b, a % b
  print(num_facto(a) + 1)  
  
def num_facto(n):
  ans = 0
  max_n = int(n ** 0.5) + 1
  is_prime = [True for x in range(max_n + 1)]
  is_prime[0], is_prime[1] = False, False
  for cursor in two_and_odds(max_n):
    if is_prime[cursor]:
      if n % cursor == 0:
        ans += 1
        while n % cursor == 0: n = n // cursor
      for i in range(cursor, max_n, cursor): is_prime[i] = False
  if n != 1: ans += 1
  return ans

def two_and_odds(max_n):
  if max_n >= 2: yield 2
  for i in range(3, max_n, 2): yield i
    
if __name__ == "__main__":
  main()


Measured memory_bytes: 113904
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    n = gcd(n, 360);
    cout << 360 / n << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
int main(){
    int A,B,C,X;
    int count,total,a,b,c;
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    scanf("%d",&X);
    count =0;
    for(a=0;a<A+1;a++){
        for(b=0;b<B+1;b++){
            for(c=0;c<C+1;c++){
                total =500*a+100*b+50*c;
                if(total == X){
                      count++;
                  }
            }
        }
    }
    
    printf("%d",count);
    return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
int32_t main(){
    
    string s;
    cin >> s;
    if(s == "AAA" || s == "BBB")
        cout << "No\n";
    else
        cout << "Yes\n";
    return 0;
}



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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<pii> p(n);
    REP(i,n){
        cin >> p[i].first;
        p[i].second = i;
    }
    sort(p.rbegin(),p.rend());
    multiset<int32> st;
    st.insert(-1);
    st.insert(-1);
    st.insert(n);
    st.insert(n);
    st.insert(p[0].second);
    int64 ans = 0;
    FOR(i,1,n){
        auto iter = st.lower_bound(p[i].second);
        int32 l1 = *(--(--iter));
        int32 l2 = *(++iter);
        int32 r1 = *(++iter);
        int32 r2 = *(++iter);
        // cout << p[i].first << " " << l1 << " " << l2 << " " << r1 << " " << r2 << endl;
        ans += p[i].first * ((l2-l1) * (r1-p[i].second) + (p[i].second-l2) * (r2-r1));
        st.insert(p[i].second);
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
    char c=getchar();bool f=0;x=0;
    while(!isdigit(c)) f|=c=='-',c=getchar();
    while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    if(f) x=-x;return x;
}
template<class t> inline void write(t x){
    if(x<0) putchar('-'),write(-x);
    else{if(x>9) write(x/10);putchar('0'+x%10);}
}
template<class t> inline void writeln(t x){
	write(x),putchar('\n');
	return;
}
/*int check(int j){
	if(a[j]>=a[j+1] && a[j]<=a[j+2]){
		return a[j];
	}
	if(a[j]>=a[j+2] && a[j]<=a[j+1]){
		return a[j];
	}
	if(a[j+1]>=a[j] && a[j+1]<=a[j+2]){
		return a[j+1];
	}
	if(a[j+1]>=a[j+2] && a[j+1]<=a[j]){
		return a[j+1];
	}
	if(a[j+2]>=a[j+1] && a[j+2]<=a[j]){
		return a[j+2];
	}
	if(a[j+2]>=a[j] && a[j+2]<=a[j+1]){
		return a[j+2];
	}
}*/
int l,r,mid,a[200010],n;
bool f[200010];
bool check(int num){
	for(int i=1;i<=2*n-1;i++){
		if(a[i]>num){
			f[i]=1;
		}else{
			f[i]=0;
		}
	}
	for(int i=1;i<=n-1;i++){
		if(f[n+i]==f[n+i-1] && f[n+i]!=0){
			return 0;
		}
		if(f[n+i]==f[n+i-1] && f[n+i]==0){
			return 1;
		}
		if(f[n-i]==f[n-i+1] && f[n-i]!=0){
			return 0;
		}
		if(f[n-i]==f[n-i+1] && f[n-i]==0){
			return 1;
		}
	}
	return f[n]^(n&1);
}
int main(){
  //  freopen("pyramid.in","r",stdin);
//	freopen("pyramid.out","w",stdout);
	read(n);
	for(int i=1;i<=2*n-1;i++){
		read(a[i]);
	}
	r=2*n-1;
	while(l<r){
		mid=(l+r)/2;
		if(check(mid)==0){
			l=mid+1;
		}else{
			r=mid;
		}
	}
	write(l);
	/*
	for(int i=1;i<=2*n-1;i++){
		if(a[i]==1 || a[i]==0){
			pd=0;
		}else{
			pd=1;
			break;
		}
	}
	if(pd==0){
		if(a[n-1]==a[n] || a[n]==a[n+1]){
			cout<<a[n];
			return 0;
		}
		else{
			for(int i=1;i<=2*n-3;i++){
				f[i]=check(i);
			}
			int num0=0,num1=0;
			for(int i=1;i<=2*n-3;i++){
				if(f[i]==1){
					num1++;
				}else{
					num0++;
				}
			}
			if(num1>num0){
				cout<<"1";
				return 0;
			}else{
				cout<<"0";
				return 0;
			}
		}
	}else{
		int s=n;
		int mid;
		for(int i=1;i<=2*s-1;i++){
			if(s==1){
				break;
			}
			for(int j=1;j<=2*s-3;j++){
				f[i]=check(j);
			}
			s-=2;
			for(int j=1;j<=2*s-1;j++){
				a[i]=f[i];
			}
		}
		write(f[1]);
	}*/
    return 0;
}

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

int main()
{
    long long N, M;
    cin >> N >> M;

    long long A, B;
    vector<pair<long long, long long>> work(N);
    for (long long i = 0; i < N; i++)
    {
        cin >> A >> B;
        work[i] = make_pair(A, B);
    }

    sort(work.begin(), work.end());
    priority_queue<long long> q;
    long long work_idx = 0;
    long long ans = 0;
    for (long long day = M; day >= 0; day--)
    {
        while (work_idx < N && (work[work_idx].first + day) <= M)
        {
            q.push(work[work_idx].second);
            work_idx++;
        }
        if (!q.empty())
        {
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2936
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector< vector <int> >a(n,vector<int>(3));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>a[i][j];
		}
	}
	vector< vector <int> >dp(n,vector<int>(3,0));
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	for(int i=1;i<n;i++)
	{
		for(int j = 0;j<3;j++)
		{
			int val = max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
			dp[i][j] = val + a[i][j];
		}
	}
	int ans = max(dp[n-1][0],dp[n-1][1]);
	ans = max(ans,dp[n-1][2]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 14024
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    int n;
    scanf("%d", &n);

    int a[100000];

    int minc = 1;

    long long cnt = 0;

    for (int i=0;i<n;i++) {
        scanf("%d", a+i);
        int x = (a[i]-1) / minc;
        if (x>0) {
            a[i] = 1;
        }

        cnt += x;

        minc = max(minc, a[i]+1);
    }

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

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,M;
  cin >> N >> M;
  vector<pair<int, int> > fir;
  vector<pair<int, int> > sec;
  int a,b;
  rep(i,M){
    cin >> a >> b;
    a--;b--;
    if(a==0) fir.pb(mp(a,b));
    else if(b==N-1) sec.pb(mp(a,b));
  }
  set<int> s;
  rep(i,fir.size()){
    s.insert(fir[i].second);
  }
  rep(i,sec.size()){
    if(s.count(sec[i].first)){
      cout <<"POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  
	     
  return 0;
    

}


Measured memory_bytes: 6592
package main

import "fmt"

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	bcnt := 0
	a := make([][]int, h)
	s := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Scan(&s[i])
		a[i] = make([]int, w)
		for j := 0; j < w; j++ {
			if s[i][j] == '#' {
				bcnt++
			}
			a[i][j] = -1
		}
	}
	a[0][0] = 1

	q := make([][2]int, 0)
	q = append(q, [2]int{0, 0})
	for len(q) > 0 {
		p := q[0]
		q = q[1:]
		x, y := p[0], p[1]
		dx := []int{0, 0, -1, 1}
		dy := []int{-1, 1, 0, 0}
		for d := 0; d < len(dx); d++ {
			nx, ny := x+dx[d], y+dy[d]
			if 0 <= nx && nx < w && 0 <= ny && ny < h {
				if s[ny][nx] == '.' && a[ny][nx] == -1 {
					a[ny][nx] = a[y][x] + 1
					q = append(q, [2]int{nx, ny})
				}
			}
		}
	}

	if a[h-1][w-1] == -1 {
		fmt.Println(-1)
		return
	}

	fmt.Println(h*w - (a[h-1][w-1] + bcnt))
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	string S;
	cin >> S;
	S[5] = ' ';
	S[13] = ' ';
	cout << S << endl;
}



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

using namespace std;
typedef long long ll;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int x, y, z; cin >> x >> y >> z;
  	cout << z << ' ' << x << ' ' << y << endl;
  	return 0;
}


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

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    vector<vector<char>> square(w, vector<char>(h));
    for(int i = 0; i < w; i++){
        for(int j = 0; j < h; j++){
            square.at(i).at(j) = '.';
        }
    }
    vector<int> x(n);
    vector<int> y(n);
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> x.at(i) >> y.at(i) >> a.at(i);
    }
    for(int k= 0; k < n; k++){
    if(a.at(k) == 1){
        for(int i = 0; i < x.at(k); i++){
            for(int j = 0; j < h; j++){
                square.at(i).at(j) = '*';
            }
        }
    } else if(a.at(k) == 2){
        for(int i = x.at(k); i < w; i++){
            for(int j = 0; j < h; j++){
                square.at(i).at(j) = '*';
            }
        }
    } else if(a.at(k) == 3){
        for(int i = 0; i < w; i++){
            for(int j = 0; j < y.at(k); j++){
                square.at(i).at(j) = '*';
            }
        }
    } else {
        for(int i = 0; i < w; i++){
            for(int j = y.at(k); j < h; j++){
                square.at(i).at(j) = '*';
            }
        }
    }
    }
    int count = 0;
    for(int i = 0; i < w; i++){
        for(int j = 0; j < h; j++){
            if(square.at(i).at(j) == '.'){
                count++;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int lcm(int x, int y)
{
    return (x / __gcd(x, y) * y);
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        if(i > 0)
        {
            ans = lcm(x, ans);
        }
        else ans = x;
    }
    cout << ans << endl;
    return 0;
}




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

int main() {
  string s;
  cin >> s;
  bool finish=false;

  for (int i=0; i<s.size()-1; i++) {
    if (s[i] == s[i+1]) {
      cout << i+1 << " " << i+2 << endl;
      finish = true;
      break;
    }
    if (s[i] == s[i+2]) {
      cout << i+1 << " " << i+3 << endl;
      finish = true;
      break;
    }
  }

  if (!finish) {
    cout << -1 << " " << -1 << endl;
  }

  return 0;
}


Measured memory_bytes: 512
function Main(input) {
  input = input.split(" ");
  const A = Number.parseInt(input[0]);  //1
  const B = Number.parseInt(input[1]);  //0
  const C = Number.parseInt(input[2]);  //-1
  const K = Number.parseInt(input[3]);

  if (A >= K) {
    console.log(K);
  } else if (A + B >= K) {
    console.log(A);
  } else {
    console.log(A - (K - A - B));
  }

}

// デバッグ用
function debug() {
  var input = document.getElementById("input").value;
  Main(input);
}

//* この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int freq[26];

int main(){
  string str;  
  while(cin >> str){
    for(char c: str){
      if(isalpha(c)) freq[tolower(c)-'a']++;
    }
  }

  for(int i=0; i<26; i++){
    cout << (char)(i+'a') << " : " << freq[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a==1)
	{
		if(b==2)
			cout<<"3\n";
		else if(b==3)
			cout<<"2\n";
	}
	else if(a==2)
	{
		if(b==1)
			cout<<"3\n";
		else if(b==3)
			cout<<"1\n";
	}
	else if(a==3)
	{
		if(b==1)
			cout<<"2\n";
		else if(b==2)
			cout<<"1\n";	
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>

using namespace std;

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

int main() {
  while (true) {
    int an, bn, r;
    scanf("%d %d %d", &an, &bn, &r);
    if (an == 0) break;
    int a[an];
    rep (i, an) {
      int x, y;
      scanf("%d %d", &x, &y);
      a[i] = (x + 50) * 10112 + y + 50;
    }
    vector<bool> b(10112 * 10112, false);
    rep (i, bn) {
      int x, y;
      scanf("%d %d", &x, &y);
      b[(x + 50) * 10112 + y + 50] = true;
    }
    int res = 0;
    int d[10000];
    int t = 0;
    for (int i = -4 * r; i <= 4 * r; ++i) for (int j = -4 * r; j <= 4 * r; ++j) if (4 * r * r <= i * i + j * j && i * i + j * j <= 16 * r * r) d[t++] = i * 10112 + j;
    rep (i, an) rep (j, t) if (b[a[i] + d[j]]) ++res;
    printf("%d\n", res);
  }
}

Measured memory_bytes: 13924
import sys
N = int(input())
abc = [list(map(int, input().split()))for _ in range(N)]
dp = [[0] * 3 for _ in range(N)]

if N == 1:
    print(max(abc[0]))
    sys.exit()

dp[0][0] = abc[0][0]
dp[0][1] = abc[0][1]
dp[0][2] = abc[0][2]

for i in range(1, N):
    dp1 = dp[i - 1][1] + abc[i][0]
    dp2 = dp[i - 1][2] + abc[i][0]
    dp[i][0] = max(dp1, dp2)
    dp1 = dp[i - 1][0] + abc[i][1]
    dp2 = dp[i - 1][2] + abc[i][1]
    dp[i][1] = max(dp1, dp2)
    dp1 = dp[i - 1][0] + abc[i][2]
    dp2 = dp[i - 1][1] + abc[i][2]
    dp[i][2] = max(dp1, dp2)

print(max(dp[-1]))

Measured memory_bytes: 47364
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath> // abs など
#include <numeric> // accumulate など
#include <stdexcept>
#include <cassert> // assert
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

// #define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
  cerr << H << " ";
  debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

// constexpr inline ll MOD = 1'000'000'007;

int main()
{
  // 入出力
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int a,b;
  cin >> a >> b;
  cout << a * b << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int N;
int A[100000];

int main(){
    cin>>N;
    rep(i,N) cin>>A[i];

    int plus=0, minus=0;
    rep(i,N){
        if(A[i]>=0) plus++;
        else minus++;
    }
    if(plus==0 || minus==0){
        if(plus==0){
            plus++;
            minus--;
        }else{
            plus--;
            minus++;
        }
    }
    
    sort(A,A+N);

    vector<P> x;
    int ans=A[minus-1];
    minus--;
    while(plus>1){
        x.push_back(P(ans,A[minus+plus]));
        ans-=A[minus+plus];
        plus--;
    }
    x.push_back(P(A[minus+plus],ans));
    ans=A[minus+plus]-ans;
    while(minus>0){
        x.push_back(P(ans,A[minus-1]));
        ans-=A[minus-1];
        minus--;
    }

    cout<<ans<<endl;
    repr(e,x){
        cout<<e.first<<' '<<e.second<<endl;
    }
}

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

int main() {
  int n;
  cin>>n;
  ll vec[n];
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  ll ans=0,i=0,z=0;
  while(i<n){
    if(vec[i]==0){
      ans+=z/2;
      z=0;
      i++;
    }
    else{
      z+=vec[i];
      i++;
    }
  }
  cout<<ans+z/2<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void)
{
	int x, h, m, s;
	scanf("%d", &x);
	h=x/3600;
	m=(x%3600)/60;
	s=(x%3600)%60;
	printf("%d:%d:%d\n", h, m, s);
	return 0;
}


Measured memory_bytes: 2720
X, Y, Z, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split())) 


A = sorted(A, key = lambda x:-x)
B = sorted(B, key = lambda x:-x)
C = sorted(C, key = lambda x:-x)

AB = [0] * (X * Y)

ABC = []

for i in range(X):
    for j in range(Y):
        if (i + 1) * (j + 1) > K:
            break
        for k in range(Z):
            if (i + 1) * (j + 1) * (k + 1) > K:
                break
            ABC.append(A[i] + B[j] + C[k])

ABC = sorted(ABC, key = lambda x:-x)
for i in range(0, K):
    print(ABC[i])

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

using namespace std;
using ll = long long;
const long double pi = acos(-1);

int main()
{
    int n, m; cin >> n >> m;
    vector<vector<int>> hen(n);
    for(int i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--, b--;
        hen[a].push_back(b);
        hen[b].push_back(a);
    }
    cout << "Yes" << endl;

    vector<int> ans(n);
    vector<bool> seen(n);
    queue<int> que;
    seen[0] = true;
    que.push(0);

    while(que.size()) {
        int cur = que.front();
        que.pop();
        for(auto i : hen[cur]) {
            if(seen[i])continue;
            ans[i] = cur;
            seen[i] = true;
            que.push(i);
        }
    }
    for(int i = 1; i < n; i++)cout << ans[i] + 1 << endl;
}

Measured memory_bytes: 10036
#!/usr/bin/env python3
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

(n,), *q = [[*map(int,o.split())] for o in open(0)]
MAX = 10 ** 5 + 1
UF = UnionFind(2 * MAX)
for x, y in q:
    UF.union(x, y + MAX)
cnt_x = [0] * (2 * MAX)
cnt_y = cnt_x[:]
for i in range(MAX):
    cnt_x[UF.find(i)] += 1
    cnt_y[UF.find(i + MAX)] += 1
print(sum(X * Y for X, Y in zip(cnt_x, cnt_y)) - n)

Measured memory_bytes: 95892
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  int n;
  cin >> n;
  vector<int> b(n), ans;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int j = 0; j < n; j++) {
    for (int i = b.size() - 1; i >= 0; i--) {
      if (b[i] == i + 1) {
        ans.push_back(b[i]);
        b.erase(b.begin() + i);
        break;
      }
    }
  }
  reverse(ans.begin(), ans.end());
  if (ans.size() != n) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < n; i++) {
      cout << ans[i] << endl;
    }
  }
  return 0;
}

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

#define vec(v) vector<int>(v)
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define mapci(mp) map<char*,int>(mp)
#define mapcc(mp) map<char*,char*>(mp)
typedef long long ll;
using namespace std;

int main(){
	string a="NWSE";
	string s;
	cin>>s;
	int n=s.length(),b[4]={0};
	for(int i=0;i<n;i++){
		for(int j=0;j<4;j++){
			if(s[i]==a[j]){
				b[j]++;
			}
		}
	}
	for(int i=0;i<4;i++){
		if(b[i]!=0){
			if(i>=2){
				if(b[i-2]==0){
					cout <<"No"<<endl;
				    return 0;
				}
			}
		    else{
		    	if(b[i+2]==0){
		    		cout <<"No"<<endl;
				    return 0;
		    	}
		    }
		}
	}
	cout << "Yes"<<endl;
	return 0;
}

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

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()
B = LIST()

def solve(N):
    dp = [0] * (N+1)
    for i in range(N+1):
        dp[i] = i
    for i in range(N+1):
        for j in range(3):
            a, b = A[j], B[j]
            if i+a <= N:
                dp[i+a] = max(dp[i+a], dp[i] + b)
    return dp[N]

N2 = solve(N)
A, B = B, A
ans = solve(N2)
print(ans)


Measured memory_bytes: 230808
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

signed main(){
	ll n,sum = 0,ans = LINF,memo = 0;
	cin >> n;
	ll a[n] = {};
	
	rep(i,0,n){
		cin >> a[i];
		sum += a[i];
	}
	
	rep(i,0,n){
		memo += a[i];
		ans = min(abs(sum - memo*2),ans);
	}
	
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>

using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b;
	if (a==2 or b==2){
		cout << "No\n";
	}else{
		cout << "Yes\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
using namespace std;

typedef long long ll;

#define MOD 1000000007
#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    char a, b, c;
    cin >> a >> b >> c;

    int cnt5 = 0, cnt7 = 0;
    if (a == '5') cnt5++;
    else if(a == '7') cnt7++;

    if (b == '5') cnt5++;
    else if (b == '7') cnt7++;

    if (c == '5') cnt5++;
    else if (c == '7') cnt7++;

    if(cnt5 == 2 && cnt7 == 1){
        p("YES");
    }else{
        p("NO");
    }
}

Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=50;
struct Z { ll cost; int val; int lim; };
bool operator<(const Z &a,const Z &b) { return a.cost*b.val<b.cost*a.val; }

int n,cap,lim;
int w[MAXN],par[MAXN];

ll wsum[MAXN]; int sz[MAXN];


Z z[MAXN];
vector<pair<ll,int> > singles;

vector<int> cost;

void run() {
	scanf("%d%d%d",&n,&cap,&lim); REP(i,n) { scanf("%d",&w[i]); if(i==0) par[i]=-1; else scanf("%d",&par[i]),--par[i]; }

	REP(i,n) wsum[i]=w[i],sz[i]=1; for(int i=n-1;i>=0;--i) if(par[i]!=-1) wsum[par[i]]+=wsum[i],sz[par[i]]+=sz[i];

	REP(i,n) z[i].cost=wsum[i],z[i].val=sz[i],z[i].lim=min(par[i]==-1?INT_MAX:lim,wsum[i]==0?INT_MAX:(int)(cap/wsum[i]));
	sort(z,z+n);
	singles.clear();
	REP(i,n) { int cur=min(z[i].lim,n); REP(j,cur) singles.PB(MP(z[i].cost,z[i].val)); z[i].lim-=cur; }
	//printf("z:"); REP(i,n) printf(" [%lld->%d (%d)]",z[i].cost,z[i].val,z[i].lim); puts("");
	//printf("singles:"); REPSZ(i,singles) printf(" %lld->%d",singles[i].first,singles[i].second); puts("");


	int totvalsum=0; REPSZ(i,singles) totvalsum+=singles[i].second;
	cost=vector<int>(totvalsum+1,INT_MAX); cost[0]=0; int mxvalsum=0;
	REPSZ(i,singles) {
		for(int j=mxvalsum;j>=0;--j) if(cost[j]!=INT_MAX) {
			int nj=j+singles[i].second,ncost=(int)min((ll)INT_MAX,cost[j]+singles[i].first);
			if(ncost<cost[nj]) cost[nj]=ncost,mxvalsum=max(mxvalsum,nj);
		}
	}
	//printf("cost:" ); REPE(i,mxvalsum) if(cost[i]!=INT_MAX) printf(" %d=%d",i,cost[i]); puts("");
	ll ret=0;
	REPE(i,mxvalsum) if(cost[i]<=cap) {
		int rem=cap-cost[i]; ll cur=i;
		REP(j,n) {
			int now=z[j].lim; if(z[j].cost!=0) now=min(now,(int)(rem/z[j].cost));
			cur+=(ll)now*z[j].val;
			rem-=now*z[j].cost;
		}
		ret=max(ret,cur);
	}
	printf("%lld\n",ret);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
int q[1000001][3];
bool vis[1001][1001];
char c[1001][1001];
int main(){
	int h,w,n;
	cin>>h>>w>>n;
	int x,y;
	int ex,ey;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>c[i][j];
			if(c[i][j]=='S'){
				y=i;
				x=j;
			}
			if(c[i][j]=='1'){
				ey=i;
				ex=j;
			}
			if(c[i][j]=='X'){
				vis[i][j]=false;
			}
			else{
				vis[i][j]=true;
			}
		}
	}
	int ans=0;
	for(int r=0;r<n;r++){
	char skey=r+'0';
	char dkey=r+'1';
	if(r>0){
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(c[i][j]==skey){
					y=i;
					x=j;
				}
				if(c[i][j]==dkey){
					ey=i;
					ex=j;
				}
				if(c[i][j]=='X'){
					vis[i][j]=false;
				}
				else{
					vis[i][j]=true;
				}
			}
		}
	}
	int head=0,tail=1;
	q[0][0]=x;
	q[0][1]=y;
	q[0][2]=0;
	vis[y][x]=false;
	int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
	int cnt=0;
	while(true){
		int x=q[head][0];
		int y=q[head][1];
		int len=q[head][2];
		if(x==ex&&y==ey){
			cnt=len;
			break;
		}
		for(int i=0;i<4;i++){
			if(x+dx[i]>=0&&x+dx[i]<w&&y+dy[i]>=0&&y+dy[i]<h){
				if(vis[y+dy[i]][x+dx[i]]==true){
					q[tail][0]=x+dx[i];
					q[tail][1]=y+dy[i];
					q[tail][2]=len+1;
					tail++;
					vis[y+dy[i]][x+dx[i]]=false;
				}
			}
		}
		head++;
	}
	ans+=cnt;
	}
	cout<<ans<<endl;
	return 0;
}

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


int main(){
    int N,K;
    cin >> N >>K;
    int h[N];
    REP(i,N){
        cin >> h[i];
    }
    vector<int> dp(N+102, INF);
    dp[0]=0;
    REP(i,N){
        REP2(j,1,K+1){
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i]-h[i+j]));
        }
    }


    cout << dp[N-1]<< endl;


}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define printjudge(cond) {if(cond) printf("Yes\n"); else printf("No\n");}
#define printans(ans) {printf("%d\n", (ans));}
typedef int* intarray;
typedef char* chararray;

int main(){
    int H, W;
    scanf("%d %d ", &H, &W);
    chararray* a;
    a = new chararray[H];
    for(int i=0; i<H; i++) a[i] = new char[W+1];
    for(int i=0; i<H; i++){
        scanf("%s", a[i]);
    }
    intarray row = new int[H];
    intarray column = new int[W];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(a[i][j]=='#') {row[i] = 1; break;}
            if(j==W-1) row[i] = 0;
        }
    }
    for(int j=0; j<W; j++){
        for(int i=0; i<H; i++){
            if(a[i][j]=='#') {column[j] = 1; break;}
            if(j==W-1) column[j] = 0;
        }
    }
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(row[i]*column[j]) printf("%c", a[i][j]);
        }
        printf("\n");
    }
    return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;
typedef priority_queue<int, vector<int>, greater<int>> min_heap;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const double PI = 4*atan(1);
const ll INF = 1e18;
const int MX = 100001;

ll a, b, c, d;

const int maxn = 5e3 + 5;
ll dp[maxn][maxn];

const ll mod = 998244353;

ll add(ll a, ll b) {
    return (((a + b) % mod) + mod) % mod;
}

ll prod(ll a,  ll b) {
    return (((a * b) % mod) + mod) % mod;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> a >> b >> c >> d;
    dp[a][b] = 1;
    for (ll i = a; i <= c; i++) {
        for (ll j = b; j <= d; j++) {
            if (i == a and j == b) {
                continue;
            }
            ll res = 0;
            if (i > a) {
                res = add(res, j * dp[i - 1][j]); // exactly one elt
            }
            if (j > b) {
                res = add(res, i * dp[i][j - 1]);
            }
            if (i > a and j > b) {
                ll ch = prod(prod(i - 1, j - 1), dp[i - 1][j - 1]);
                res = add(res, -ch);
            }
            dp[i][j] = res;
            // cout << "i:  " << i << ", j: " << j << ", dp: " << dp[i][j] << "\n";
        }
    }
    // cout << dp[1][2] << "\n";
    cout << dp[c][d] << "\n";

}


Measured memory_bytes: 85880
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
const int INF = 100000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007ll;
std::vector<ll> enum_div(ll n)//nの約数を列挙
{
	std::vector<ll> ret;
	for(ll i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}
int main(){
	ll n;
	std::cin >> n;
	vector<ll> a;
	a=enum_div(n);
	a.pb(n);
	sort(all(a));
//	rep(i,a.size())std::cout << a[i] << std::endl;
	
	if(a.size()%2==1)std::cout << (a[a.size()/2]-1)*2 << std::endl;
	else std::cout << (a[a.size()/2]-1)+(a[a.size()/2-1]-1) << std::endl;
}

Measured memory_bytes: 384
package main

import (
	"fmt"
	"strings"
)

func main() {

	var s1 string
	var s2 string
	var s3 string

	fmt.Scan(&s1)
	fmt.Scan(&s2)
	fmt.Scan(&s3)
	res := strings.ToUpper(s1[0:1]) + strings.ToUpper(s2[0:1]) + strings.ToUpper(s3[0:1])
	fmt.Println(res)

}


Measured memory_bytes: 640