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

int main(){
  int n,X=0;
  cin >> n;
  vector<int>vec(n);
  for(int i=0; i<n; i++){
    cin >> vec[i];
  }
  for(int i=1; i<n-1; i++){
   if(vec[i-1] < vec[i] && vec[i] < vec[i+1]){
     X++;
   }
    else if(vec[i-1] > vec[i] && vec[i] > vec[i+1]) {
      X++;
  }
  }
  cout << X << endl;
}

Measured memory_bytes: 3580
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<long long int>in(n);
    rep(i,n)cin>>in[i];
    sort(all(in));
    long long int sum=0;
    rep(i,n)sum+=in[i]*(n-i-1);
    cout<<sum<<endl;
  }


}

Measured memory_bytes: 1296
#include <bits/stdc++.h>    
using namespace std;
typedef unsigned long long LL;

    int main() {
            
            LL a;
            double b;
            cin >> a >> b;
            LL c=(b+0.000001)*100;
            LL s=a*c;
            s/=100;
            cout << s << '\n';
            return 0;
        }

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

class Dmondai
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();
        var ans = 0L;
        var minusCount = 0;
        var absMinNum=long.MaxValue;
        for (int i=0;i<N;++i)
        {
            if (A[i] < 0) minusCount++;
            var absNum = Math.Abs(A[i]);
            ans +=absNum;
            if (absNum < absMinNum) absMinNum = absNum;
        }
        if (minusCount % 2 == 1) ans -= (absMinNum * 2);
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 28892
import Data.Functor((<$>))

main :: IO ()
main = do 
        q  <- read.last.words <$> getLine
        xs <- map ((\[n, t] -> (n, read t)).words).lines <$> getContents
        mapM_ (putStrLn.f) $ solve xs [] [] q 0
    where f (n, t) = n ++ (' ' : show t) 

solve :: [(String, Int)] -> [(String, Int)] -> [(String, Int)] -> Int -> Int -> [(String, Int)]
solve []            [] zs _ _   = reverse zs
solve []            ys zs q cnt = solve (reverse ys) [] zs q cnt
solve ((n, t) : xs) ys zs q cnt = let t'   = t - q
                                      cnt' = cnt + q
                                      m    = cnt' + t'
                                  in if t' > 0 then solve xs ((n, t') : ys) zs q cnt'
                                               else solve xs ys  ((n, m) : zs) q m

Measured memory_bytes: 35332
s=input()
if s[0] == 'A' and s[2:-1].count('C') == 1 and s[1].islower() and s[-1].islower() and (s[2:-1] == 'C' or s[2:-1].replace('C','').islower()):
    print('AC')
else:
    print('WA')

Measured memory_bytes: 3060
l = list(map(int, input().split()))

ans = 0

maxl = max(l)

for i in range(3):
	if l[i]==maxl:
		pass
	else:
		while maxl-2 >= l[i]:
			l[i] = l[i] + 2
			ans = ans + 1

minl = min(l)

k = []
for i in range(3):
	k.append(l[i]-minl)

if sum(k)==0:
	pass
elif sum(k)==2:
	ans = ans + 2
elif sum(k)==1:
	ans = ans + 1

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <limits>
#include <map>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    map<string, int> mapping;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        mapping[s]++;
    }
    int m;
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        string s;
        cin >> s;
        mapping[s]--;
    }
    int ans = 0;
    for (auto& v : mapping)
    {
        ans = max(ans, v.second);
    }
    cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  for(int i = 0; i < N; i++){
  string S;
  cin >> S;
   if(S == "Y"){
    cout << "Four" << endl;
    return 0;
   }
  }
 
 cout << "Three" << endl;
 return 0;
}


Measured memory_bytes: 256
lenght = int(input())
items = []
for _ in range(lenght):
  items.append(input())
counts = dict()
for i in items:
  counts[i] = counts.get(i, 0) + 1
a = sorted(counts.items(), key=lambda x: x[0])    
b = sorted(a, key=lambda x: x[1], reverse = True)
for i in b:
  if(i[1] == b[0][1]):
    print(i[0])
  else:
    break

Measured memory_bytes: 48268
s = int(input())

def fun(n):
  if n % 2 == 0:
    return int(n / 2)
  else:
    return 3 * n + 1

a = [s]
for i in range(10000):
  ai = fun(a[i])
  a.append(ai)

b = 0
for i in range(10000):
  if b ==1:
    break
  for j in range(i + 1,9999):
    if a[j] == a[i]:
      b += 1
      print(j + 1)
      break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }

int main() {
  ll n, ww, memo = -1;
  cin >> n >> ww;
  vll w(n), v(n);
  for (ll i = 0; i < n; i++) cin >> w[i] >> v[i];
  long long dp[100001]; dp[0] = 0;
  vector<vll> check(100001, vll(n));
  for (ll i = 1; i <= ww; i++) {
    dp[i] = dp[i - 1];
    for (ll j = 0; j < n; j++) {
      if (i < w[j] || check[i - w[j]][j] == 1) continue;
      if (chmax(dp[i], dp[i - w[j]] + v[j])) memo = j;
    }
    if (memo != -1) {
      check[i] = check[i - w[memo]];
      check[i][memo] = 1;
    }
    else check[i] = check[i-1];
    memo = -1;
  }
  cout << dp[ww] << endl;
}


Measured memory_bytes: 83072
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
int a, b, c;
int main(void) {
    cin >> a >> b >> c;
    (a + b + c - max({ a,b,c }) == max({ a,b,c }) ? cout << "Yes" << endl : cout << "No" << endl);
    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
int main(void){
	int n,i,cnt=0;
	char s[50];
	scanf("%d%s",&n,s);
	for(i=0;s[i+2]!='\0';i++){
		if(s[i]=='A'){
			cnt+=s[i+1]=='B'&&s[i+2]=='C';
		}
	}
	printf("%d",cnt);
	return 0;
}


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

int main() {
	int A, B, C, X, Y;
	std::cin >> A >> B >> C >> X >> Y;

	int N_A = 0, N_B = 0, N_AB = 0, ans;
	if(A + B <= 2 * C) {
		ans = X * A + Y * B;
	} else {
		N_AB = std::min(X, Y);
		N_A = X - N_AB;
		N_B = Y - N_AB;

		ans = std::min(2 * std::max(X, Y) * C, N_A * A + N_B * B + 2 * N_AB * C);
	}

	std::cout << ans << std::endl;
 }


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    int a;
    string s;
    cin >> a >> s;
    cout << (a >= 3200 ? s : "red") << endl;
    return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  var n = sc.nextInt()
  var b = Array.fill(n)(sc.nextInt())
  var ar = Range(1,n+1)
  for(i <- 0 until n){
    b(i) = (b(i)-ar(i)).abs
  }
  b = b.sorted
  if (n == 2){println("YES");sys.exit()}
  println(if(b(n-3) == 0) "YES" else "NO")
}


Measured memory_bytes: 55468
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int a = sc.nextInt();
   int b = sc.nextInt();
   
   String ans = "";
   if(a>b) 
   {
     for(int i=0;i<a;i++)
     {
       ans += b + "";
     }
   }
   else
   {
     for(int i=0;i<b;i++)
     {
       ans += a + "";
     }
   }
   System.out.println(ans);
 }
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}


int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int n,sum = 1;
  string s; cin>> n >> s;
  rep(i,n-1){
    if(s[i]!=s[i+1]) sum++;
  }
  cout<<sum<<endl;
  
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

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




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main() {
  FAST
  ll n,k;
  cin>>n>>k;
  ll ans=(n/k)*k;
  ans=n-ans;
  ans=min(ans,k-ans);
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3620
n, k = map(int, input().split())
W = [int(input()) for i in range(n)]

left = max(W)-1; right = sum(W)
while left+1 < right:
    mid = (left + right) // 2
    cnt = 1; cur = 0
    for w in W:
        if mid < cur + w:
            cur = w
            cnt += 1
        else:
            cur += w
    if cnt <= k:
        right = mid
    else:
        left = mid
print(right)



Measured memory_bytes: 9564
N, M = [int(x) for x in input().split()]

A = []
B = []

for _ in range(N):
	A.append(input())

for _ in range(M):
	B.append(input())

judge = False
	
for i in range(N - M + 1):
	for j in range(N - M + 1):
		for k in range(M):
			if B[k] != A[i + k][j: j + M]:
				break
			if k == M - 1:
				judge = True

if judge:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
	double weight;
	while(cin >> weight){
		if(weight <= 48)
			cout << "light fly" << endl;
		if(weight > 48 && weight <= 51)
			cout << "fly" << endl;
		if(weight > 51 && weight <= 54)
			cout << "bantam" << endl;
		if(weight > 54 && weight <= 57)
			cout << "feather" << endl;
		if(weight > 57 && weight <= 60)
			cout << "light" << endl;
		if(weight > 60 && weight <= 64)
			cout << "light welter" << endl;
		if(weight > 64 && weight <= 69)
			cout << "welter" << endl;
		if(weight > 69 && weight <= 75)
			cout << "light middle" << endl;
		if(weight > 75 && weight <= 81)
			cout << "middle" << endl;
		if(weight > 81 && weight <= 91)
			cout << "light heavy" << endl;
		if(weight > 91)
			cout << "heavy" << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(auto &t:a)cin>>t;return i;}
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T> void prArr(T a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

ll mod_pow(ll x,ll n){
  ll res=1;
  while(n){
    if(n%2) res=res*x%mod;
    x=x*x%mod;
    n/=2;
  }
  return res;
}

ll divi(ll a,ll b){
  return a * mod_pow(b,mod-2) % mod;
}

ll factorial(int i){
  static vector<ll> k(1e6);
  if(!k[0]){k[0]=1;for(int i=1;i<(int)k.size();i++)k[i]=i*k[i-1]%mod;}
  return k[i];
}

ll nCr(ll n,ll r){
  ll a = mod_pow( factorial(r) * factorial(n-r) % mod ,mod-2);
  return factorial(n) * a % mod;
}

signed main(){
  int h,w,A,B;
  cin>>h>>w>>A>>B;

  int ans = nCr(h+w-2,w-1);
  for(int i=0;i<A;i++){
    int a = nCr(h-1-i+B-1,B-1);
    int b = nCr(i+(w-B-1),i);
    ans = (ans - a*b%mod + mod) % mod;
  }

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


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	int x, y;
	cin >> x >> y;
	cout << (((y <= x * 4) && ((y & 1) == 0) && (x * 2 <= y))  ? "Yes" : "No");
}

int main()
{
	fastio;
	solve();

	return 0;
}

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

int main(void){
    int a,b;
    cin>>a>>b;
    if(a<=9){
        if(b<=9){
            cout<<a*b<<endl;
        }else{
            cout<<"-1"<<endl;
        }
    }else{
        cout<<"-1"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, s, l, r;
int x[100020];
long long p[100020];
long long z;
int main() {
	scanf("%d%d", &n, &s);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &x[i], &p[i]);
	}
	for (int l = 0, r = n - 1; l <= r;) {
		if (x[l] >= s) {
			z += x[r] - s;
			break;
		}
		if (x[r] <= s) {
			z += s - x[l];
			break;
		}
		z += x[r] - x[l];
		if (p[l] >= p[r]) {
			while (l < r && p[l] >= p[r]) {
				p[l] += p[r--];
			}
		} else {
			while (l < r && p[l] < p[r]) {
				p[r] += p[l++];
			}
		}
	}
	printf("%lld\n", z);
	return 0;
}

Measured memory_bytes: 1408
module IntSet = Set.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let ass = Array.init n @@ fun _ ->
    Scanf.scanf "%d " @@ fun k ->
      let as_ = Array.init k @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
      IntSet.of_list @@ Array.to_list as_ in
  Printf.printf "%d\n" @@ IntSet.cardinal @@ Array.fold_left IntSet.inter ass.(0) ass


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define maxn 100005
#define ll long long
#define scan(x) scanf("%d",&x)
#define scann(n,m) scanf("%d %d",&n,&m)
#define INF 0x3f3f3f3f

using namespace std;

int main()
{
   string s;
   cin>>s;
   int n;
   cin>>n;
   for(int i=0;i<s.length();i+=n)
   {
       cout<<s[i];
   }
   cout<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool f() {
	int H, W;
	cin >> H >> W;
	map<char, int> cnt;
	for (int i = 0; i < H; ++ i) {
		string s;
		cin >> s;
		for (char c : s) ++cnt[c];
	}
	if (H % 2 && W % 2) {
		for (auto& p : cnt) if (p.second % 2 == 1) {
			-- p.second;
			break;
		}
	}
	int a2 = 0;
	if (W % 2) a2 += H/2;
	if (H % 2) a2 += W/2;
	for (auto& p : cnt) {
		if (p.second % 2 == 1) return false;
		if (p.second % 4 == 2) {
			if (a2 == 0) return false;
			p.second -= 2;
			-- a2;
		}
	}
	if (a2 % 2 != 0) return false;
	return true;
}
int main() {
	cout << (f() ? "Yes" : "No") << endl;
}


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

N = int(input())
V = list(map(int, input().rstrip().split(' ')))
C = list(map(int, input().rstrip().split(' ')))

sum_value = 0
for i in range(N):
    if V[i] - C[i] > 0:
        sum_value += V[i] - C[i]
        
print(sum_value)


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

#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end());
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
bool black[550][550];
signed main() {
    cin >> N;
    int cntBlack = 0;
    rep(i, N) {
        string a;
        cin >> a;
        rep(j, N) { cntBlack += black[i][j] = a[j] == '#'; }
    }
    if (cntBlack == 0) {
        cout << -1 << endl;
        return 0;
    }
    int cntCol = 0;
    rep(i, N) {
        rep(j, N) {
            if (!black[j][i]) {
                cntCol++;
                break;
            }
        }
    }
    int ans = 114514;
    rep(i, N) {
        int cur = 0;
        rep(j, N) { if (!black[i][j]) { cur++; }}
        cur++;
        rep(j, N) {
            if (black[j][i]) {
                cur--;
                break;
            }
        }
        chmin(ans, cur);
    }
    ans += cntCol;
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#ifdef LOCAL
template <class T> ostream &operator<<(ostream &str, const vector<T> &vec) {
  str << '[';
  for (auto it = vec.begin(); it != vec.end(); it++) {
    if (it != vec.begin())
      str << ", ";
    str << *it;
  }
  str << ']';
  return str;
}
#define var(x) "[" << #x << ": " << x << "] "
#define dbg cerr << "  line " << __LINE__ << ": "
#else
#define var(x) 0
struct dbg_cls {
  template <class T> dbg_cls &operator<<(const T &oth) { return *this; }
} dbg;
#endif
using ll = long long;
using ld = long double;
int main(int argc, char **argv) {
  ios::sync_with_stdio(false), cin.tie(0);
  auto solve = [&]() {
    ll ans = 1;
    ld l = 0;
    int n;
    cin >> n;
    vector<ll> d(n);
    for (int k = 0; k < n; k++) {
      ll r;
      cin >> r;
      d[k] = r;
    }
    for (auto r : d) {
      if (!r) {
        cout << "0\n";
        return;
      }
    }
    for (auto r : d) {
      ld cl = logl(r) / logl(10);
      l += cl;
      if (l > 18.0L) {
        cout << "-1\n";
        return;
      }
      ans *= r;
      if (ans > (ll)1'000'000'000'000'000'000ll) {
        cout << "-1\n";
        return;
      }
    }
    cout << ans << '\n';
  };
  int t;
  t = 1;
  while (t--)
    solve();
  return 0;
}


Measured memory_bytes: 3996
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long ll;
const int MAXN = 2010;
const int MOD = 1e9+7;
int _w;

int C[MAXN][MAXN], sum[MAXN][MAXN], f[MAXN][MAXN];
void prelude() {
	for( int i = 0; i < MAXN; ++i ) {
		f[i][0] = sum[i][0] = C[i][0] = 1;
		for( int j = 1; j <= i; ++j )
			C[i][j] = (C[i-1][j] + C[i-1][j-1]) % MOD;
		for( int j = 1; j < MAXN; ++j )
			sum[i][j] = (sum[i][j-1] + C[i][j]) % MOD;
		for( int j = 1; j < MAXN; ++j )
			f[i][j] = (f[i][j-1] + sum[i][j]) % MOD;
	}
}

int solvet( int t, int b ) {
	int ans = 1; // i == 0
	for( int i = 1; i <= min(t-1, b); ++i ) {
		int tmp = f[i-1][t-i-1];
		//for( int s = 1; s <= t-i; ++s )
		//	tmp = (tmp + sum[i-1][min(s-1, i-1)]);
		tmp = int((ll)tmp * C[b][i] % MOD);
		ans = (ans + tmp) % MOD;
	}
	return ans;
}

int main() {
	prelude();
	int a, b;
	_w = scanf( "%d%d", &a, &b );
	if( !a || !b ) return puts("1"), 0;
	int ans = 0;
	for( int t = 1; t <= a+1; ++t )
		ans = (ans + solvet(t, b-1)) % MOD;
	printf( "%d\n", ans );
	return 0;
}


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

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define sz(c) int(c.size())
#define clr(v, d)   memset(v, d, sizeof(v))
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF             1e9
#define NINF             -1e9

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;


int main() {

	string p,a;

	cin>>p>>a;

	ll cnt=0;
	loop(i,sz(p))if(p[i]==a[i])cnt++;
	cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <sstream>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define clr(a) memset(a, 0, sizeof(a))
#define set(a) memset(a, -1, sizeof(a))
#define pb push_back
#define sz(a) ((ll)a.size())
#define all(a) a.begin(), a.end()
#define mp make_pair
#define rep(i, a, y) for (ll i = a; i <= y; i++)
#define rep2(i, b) for (ll i = 0; i < b; i++)
#define repl(i, a, b) for (ll i = a; i <= b; i++)
#define ppi pair<int, int>
#define scl(x) scanf("%d", &x)
#define pcl(x) printf("%d", x)
#define FastRead                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0)
/*
 
     ██╗██╗   ██╗██╗  ██╗ █████╗ ███╗   ██╗
     ██║██║   ██║██║  ██║██╔══██╗████╗  ██║
     ██║██║   ██║███████║███████║██╔██╗ ██║
██   ██║██║   ██║██╔══██║██╔══██║██║╚██╗██║
╚█████╔╝╚██████╔╝██║  ██║██║  ██║██║ ╚████║
 ╚════╝  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝
 
*/
int main()
{
    ll s,w;
    cin>>s>>w;
    if(w>=s) cout<<"unsafe\n";
    else cout<<"safe\n";
    return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	static int ans;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long k = sc.nextLong();
		long d = sc.nextLong();
		long result;
		if(Math.abs(x) / k >= d) {
			result = Math.abs(x) - (k*d);
		}
		else {
			long c = Math.abs(x) / d;
			long t = k -c;
			if(t % 2 == 0) {
				result = Math.abs(x) - c * d;
			}
			else {
				result = Math.abs(Math.abs(x) - (c+1) * d);
			}
		}
		System.out.println(result);
	}
}

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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N,ans=0;
    cin >> N; 
    for (int i = 0; i<N; ++i) {
        int val;
        cin >> val;
        if (i%2==0 && val%2==1) ++ans;
    }
    cout << ans;    
}

Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>
#include <string.h>
int main() {
    std::string strS;
    std::cin >> strS;
    bool isOK = false;
    if(strS[2] == strS[3] && strS[4] == strS[5]){
        isOK = true;
    }

    if(isOK == true){
        std::cout << "Yes" << std::endl;
    }
    else{std::cout << "No" << std::endl;}

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstdio>
#include<queue>
#include<functional>
#include <tuple>
#include<iomanip>
#include<stack>
#include<cmath>
#define ll long long
#define N 1000000007
using namespace std;
int main() {
	int n; cin >> n;
	string s; cin >> s;
	char data[26];
	for (int i = 0; i < 26; ++i) data[i] = 'A' + i;
	for (int i = 0; i < s.length(); ++i) {
		int x=s[i]-'A';
		x += n;
		s[i] = data[x % 26];
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

string s;
int v[4] = { 0 };

int main()
{
	cin >> s;

	if (s.size() == 1) {
		cout << "No" << endl;
		return 0;
	}

	for (int i = 0; i < s.size(); ++i)
	{
		if (s[i] == 'N') v[0] += 1;
		else if (s[i] == 'W') v[1] += 1;
		else if (s[i] == 'S') v[2] += 1;
		else if (s[i] == 'E') v[3] += 1;
	}

	//cout << v[0] << " " << v[1] << " " << v[2] << " " << v[3] << endl;
	if ((v[1] - v[3] == 0 && v[0] - v[2] == 0)
		|| ((v[1] == 0 && v[3] == 0 && (v[0] != 0 && v[2] != 0)) 
			|| (v[0] == 0 && v[2] == 0 && (v[1] != 0 && v[3] != 0))))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

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

int par[100000];

void init(int n){
  for(int i=0; i<n; i++) par[i] = i;
}
 
int root(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = root(par[x]);
  }
}
 
bool same(int x, int y){
  return root(x) == root(y);
}
	
void unite(int x, int y){
  x = root(x);
  y = root(y);
  if(x == y) return;
  
  par[x] = y;
}

int main()
{
  int n,q;
  cin >> n >> q;
  int p, a, b;
  init(n);
  for(int i=0; i<q; i++){
    cin >> p >> a >> b;
    if(p == 0) unite(a,b);
    else cout << (same(a, b) ? "1" : "0") << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3152
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, a[105];
int c[9];
int MAX,MIN;

int main() {
  INCANT;
  cin >> N;
  int a;
  rep(i, N) {
    cin >> a;
    a/=400;
    if (a>=9) a=8;
    c[a]++;
  }
  int r=0;
  rep(i, 8) if (c[i]) r++;
  MAX=r+c[8];
  MIN=r+((c[8]>0 && r==0)?1:0);
  cout << MIN << ' ' << MAX << "\n";
  return 0;
}

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

// header area

void dfs(int keta, string tmp, vector<string> &ans_v, int N){
    if(keta == N){
        // 重複がないことを確認する。setに入れた際のサイズを比較。
        set<char> set_v;
        rep(i, N) set_v.insert(tmp[i]);
        if(set_v.size() == tmp.size()){
            // cout << "set_tmp: " << tmp << endl;
            ans_v.push_back(tmp);
        }
        return;
    }else{
        int ar[N];
        iota(ar, ar+N, 1);
        for(int c_i: ar){
            char c = '0'+c_i;
            if(tmp.find(c) == string::npos){
                dfs(keta+1, tmp+c, ans_v, N);
            }
        }
    }
}

int main(){
    int N; cin >> N;
    string p;
    string q;
    rep(i, N){
        char t; cin >> t;
        p+=t;
    }
    rep(i, N){
        char t; cin >> t;
        q+=t;
    }

    // 全探索の場合でも、8^8=16777216程度の探索回数
    vector<string> ans_v;
    dfs(0, "", ans_v, N);

    int a_v=0;
    int b_v=0;
    int i=0;
    for(string x: ans_v){
        string str_a(p);
        string str_b(q);
        // cout << x << " : " << str_a << endl;
        if(x==str_a) a_v = i;
        if(x==str_b) b_v = i;

        i++;
    }


    cout << abs(a_v -b_v) << endl;


    return 0;
}

Measured memory_bytes: 2424
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int sum[100010];
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) {
		int q, w;
		scanf("%d %d", &q, &w);
		sum[q]++;
		sum[w+1]--;
		int pre = q;
		for (int y = 2; y <= sqrt(w); y++) {
			int st = q / y;
			if (q%y)
				st++;
			int en = w / y;
			sum[st]++;
			sum[min(en + 1, pre)]--;
			pre = st;
		}
		int x = sqrt(w);
		for (int y = 1; y <= min(x,pre-1); y++) {
			int st = q / y;
			if (q%y)
				st++;
			st *= y;
			if (q <= st && st <= w) {
				sum[y]++;
				sum[y + 1]--;
			}
		}
	}
	int dap = 0;
	for (int i = 1; i <= m; i++) {
		dap += sum[i];
		printf("%d\n",dap);
	}
}

Measured memory_bytes: 1280
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int c = 1;
    int cnt = 0;
    
    for(int i=0; i<N; i++){
      cnt += c;
      c +=1;
    }
    System.out.println(cnt);
  }
}

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

int main() {
  int N, A, B;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.rbegin(),vec.rend());
  
  A = 0; B = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) A += vec.at(i);
    else B += vec.at(i);
  }
  
  cout << A - B << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
//Ford-Fulkerson O(FE)
#include<algorithm>
#include<utility>
#include<vector>
#include<limits>
template<typename T>
struct MF{
	struct edge{
		int to,rev;
		T cap;
	};
	vector<vector<edge> >G;
	vector<int>used;
	MF(int n_=0):G(n_),used(n_,0){}
	void add_edge(int from,int to,T cap)
	{
		G[from].push_back({
			to,(int)G[to].size(),cap
		});
		G[to].push_back({
			from,(int)G[from].size()-1,0
		});
	}
	T dfs(int u,int t,T f,int dfstime)
	{
		if(u==t)return f;
		used[u]=dfstime;
		for(edge&e:G[u])
		{
			if(used[e.to]<dfstime&&e.cap>0)
			{
				T d=dfs(e.to,t,min(f,e.cap),dfstime);
				if(d>0)
				{
					e.cap-=d;
					G[e.to][e.rev].cap+=d;
					return d;
				}
			}
		}
		return 0;
	}
	T max_flow(int s,int t)
	{
		T ret=0;
		for(int dfstime=1;;dfstime++)
		{
			T f=dfs(s,t,numeric_limits<T>::max(),dfstime);
			if(f>0)ret+=f;
			else break;
		}
		return ret;
	}
};
main()
{
	int N,E;
	cin>>N>>E;
	MF<int>mf(N);
	for(int i=0;i<E;i++)
	{
		int u,v,c;cin>>u>>v>>c;
		mf.add_edge(u,v,c);
	}
	cout<<mf.max_flow(0,N-1)<<endl;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    string S;
    cin >> S;
    ll ans, N;
    ans = N = S.size();
    repe(i, 1, N + 1){
        if (S[i - 1] != S[i]) chmin(ans, max(i, N - i));
    }

    cout << ans << endl;
}

Measured memory_bytes: 3796
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;
#define LL long long
const int maxn = 1e5 + 10;
int a[maxn], b[maxn], book[maxn];
int n;
struct node
{
	int val, IS;
	int num;
}q[maxn * 2];
bool cmp(node a, node b)
{
	return a.val < b.val;
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++)
		scanf("%d %d", &a[i], &b[i]);
	for(int i = 1; i <= n; i ++)
	{
		q[i].val = a[i]; q[i + n].val = b[i];
		q[i].IS = 1; q[i + n].IS = 0;
		q[i].num = i; q[i + n].num = i;
	}
	sort(a + 1, a + n + 1);
	sort(b + 1, b + n + 1);
	sort(q + 1, q + n * 2 + 1, cmp);
	int flag = 1;
	LL ans1 = 1e18, ans2 = 1e18, ans3 = 0;
	
	for(int i = 1; i <= n; i ++)
	{
		if(a[i] > b[i])
		{
			flag = 0;
			break;
		}
	}
	if(flag)
	{
		ans1 = 0;
		for(int i = 1; i <= n; i ++)
			ans1 += a[i];
	}
	//cout << "! " << ans1 << endl;
	flag = 1;
	for(int i = 1; i <= n; i ++)
	{
		if(b[i] > a[i])
		{
			flag = 0;
			break;
		}
	}
	if(flag)
	{
		ans2 = 0;
		for(int i = 1; i <= n; i ++)
			ans2 += b[i];
	}
	//cout << "! " << ans2 << endl;
	for(int i = 1; i <= n; i ++)
	{
		book[q[i].num] ++;
	}
	flag = 0;
	for(int i = 1; i <= n; i ++)
	{
		if(book[i] > 1)
		{
			flag = 1;
			break;
		}
	}
	if(flag)
	{
		for(int i = 1; i <= n; i ++)
			ans3 += q[i].val;
	}
	else
	{
		ans3 = 1e18;
		LL sum = 0;
		for(int i = 1; i <= n; i ++)
			sum += q[i].val;
		//LL temp = ans3;
		for(int i = 1; i <= n; i ++)
		{
			LL t_ans = sum;
			t_ans -= q[i].val;
			if(q[n + 1].num == q[i].num)
				t_ans += q[n + 2].val;
			else
				t_ans += q[n + 1].val;
			ans3 = min (ans3, t_ans);
		}
	}
	//cout << ans1 << " " << ans2 << " " << ans3 << endl;
	ans1 = min (ans1, ans2);
	ans1 = min (ans1, ans3);
	cout << ans1 << endl;
	return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

int main() {
	cin >> N >> Q;
	cin >> S;
	vector<int> a(S.size(), 0);
	int ans = 0;
	for (int i = 1; i < S.size(); i++) {
		if (S[i] == 'C' && S[i - 1] == 'A') {
			a[i] = a[i - 1] + 1;
		}
		else {
			a[i] = a[i - 1];
		}
	}
	for (int i = 0; i < Q; i++) {
		int l, r;
		cin >> l >> r;
		cout << a[r - 1] - a[l - 1] << endl;
	}
}


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

using namespace std;
int main(){
	int a, d, n, i, j;
	while(1){
		int count = 0;
		long long int b = 0, c = 0;
		int k = 0;
		cin >> a >> d >> n;
		if(a == 0 && d == 0 && n == 0) break;
		while(k != n){
			bool yakusu = false;
			if(count == 0){
				b = a;
				if(b == 1){
					count++;
					continue;
				}
				else if(b >= 2){
					for(j = 2;j*j < b+1;j++){
						if(b % j == 0){
							yakusu = true;
							break;
						}
					}
				}
				count++;
				if(!yakusu){
					c = b;
					k++;
					//cout << c <<  " " << "k = " << k << endl;
				}
			}
			else if(count != 0){
				b = a + d*count;
				//cout  << "b = " << b << " d = " << d << " count = " << count << " d*count = " << d*count << endl;
				for(j = 2;j*j < b+1;j++){ 
					if(b % j == 0){
						yakusu = true;
						break;
					}
				}
				count++;
				if(!yakusu){
					c = b;
					k++;
					//cout << c  << " " << "k = " << k << endl;
				}
			}
		}
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    cin>>s;
    int len=s.size();
    for(int i=0;i<=len;i++)
    {
        if(s[i]=='C')
        {
            for(int j=i;j<=len;j++)
            {
                if(s[j]=='F') 
                {
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))


for i in range(n-1):
  if h[n-1-i]<h[n-i-2]-1:
    print('No')
    exit()
  elif h[n-1-i]==h[n-i-2]-1:
    h[n-i-2]=h[n-i-2]-1

print('Yes')


       
    


Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,c,cnt=0,s=0;
    cin>>n>>m>>c;
    int a[100],b[100];
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
    }
    while(n--)
    {
        s=0;
    for(int i=0;i<m;i++)
    {
        cin>>b[i];
        s+=b[i]*a[i];
    }
    if(s+c>0)
    {
        cnt++;
    }

}
cout<<cnt<<endl;
return 0;
}


Measured memory_bytes: 256
N = gets.to_i
P = gets.split.map!(&:to_i)
Q = gets.split.map!(&:to_i)


a = (1..N).to_a.permutation(N).find_index(P)
b = (1..N).to_a.permutation(N).find_index(Q)

puts (a-b).abs


Measured memory_bytes: 2172
#include<bits/stdc++.h>
#define ll long long
#define inf 2147483647 
using namespace std;
struct edge{//储存边的信息 
    int v;
    ll cost;
};
struct node{//堆内的结构体 pos:节点编号，num：距离 
    int pos;
    ll num;
    friend bool operator < (node a,node b)//堆 运算符重载（按照num最小堆） 
    {
        return a.num>b.num;
    }
};
int n,m,s;
vector<edge> mp[100010];//邻接表+vector存图 
ll dis[100010];//距离各点的距离 
bool book[100010];//标记是否处理过 
priority_queue<node> q;//最小堆优化 
void Dijkstra()//算法框架 
{
    for(int i=0;i<n;i++)//将节点依次存入堆 
    {
        node t;
        t.pos=i;t.num=dis[i];
        q.push(t);
    }
    book[s]=true;//起点已经取过了 
    while(!q.empty())//精华部分 
    {
        node t=q.top();
        if(book[t.pos])//懒惰删除 
        {
            q.pop();
            continue;
        }
        book[t.pos]=true;
        for(int j=0;j<mp[t.pos].size();j++)//实现按边的松弛 
        {
            edge tmp=mp[t.pos][j];
            if(dis[tmp.v]>dis[t.pos]+tmp.cost)
            {
                dis[tmp.v]=dis[t.pos]+tmp.cost;
                q.push((node){tmp.v,dis[tmp.v]});//将更新的值存入堆 
            }
             
        }
        q.pop();
    }
}
void init()//初始化 不解释 
{
    for(int i=0;i<n;i++)
    dis[i]=(i==s?0:inf);
}
int main()//主函数 
{
    cin>>n>>m>>s;
    init();
    memset(book,false,sizeof(book));
    for(int i=0;i<m;i++)//邻接表将节点存入 
    {
        int x;
        edge y;
        scanf("%d%d%lld",&x,&y.v,&y.cost);
        if(x==s) dis[y.v]=min(dis[y.v],y.cost);
        mp[x].push_back(y);
    }
    Dijkstra();//跑一边算法 
    for(int i=0;i<n;i++)
        if(dis[i]!=inf) printf("%lld\n",dis[i]);//输出结果 
        else printf("INF\n");
    return 0;
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cctype>
using namespace std;
int main()
{
	char ch;
	int cnt[26] = {};
	while (cin >> ch)
	{
		ch = tolower(ch);
		if (isalpha(ch))
		{
			cnt[ch - 'a']++;
		}
	}

	for (int i = 0; i < 26; i++)
	{
		printf("%c : %d\n" , i+('a') , cnt[i]);
	}
	return 0;
}


Measured memory_bytes: 3216
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

char n[10];
bool maked = false;

void solve(int x, int sum, char s[]){
  if(x == 4 && sum == 7 && maked == false){
    cout << n[0];
    REP(i,3){
      cout << s[i] << n[i + 1];
    }
    cout << "=7\n";
    maked = true;
    return;
  }

  if(maked == true){
    return;
  }

  if(x == 4){
    return;
  }

  REP(i,2){
    int t = n[x] - '0';
    if(i == 0){
      s[x - 1] = '+';
      solve(x + 1, sum + t, s);  
    }else{
      s[x - 1] = '-';
      solve(x + 1, sum - t, s);
    }
  }
}

int main(){

  cin >> n;

  int t = n[0] - '0';
  char s[10];
  solve(1, t, s);

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,a[22];
int cnt[2001];

void es(int x=0,int sum=0){
  if(x==n){
    if(sum<2001)cnt[sum]++;
    return;
  }
  es(x+1,sum+a[x]);
  es(x+1,sum);
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  es();
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int x;
    cin>>x;
    cout<<(cnt[x]?"yes":"no")<<endl;
  }
  return 0;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define vv(type)		vector<vector<type>>
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define db(x) 			cout<<x<<" "
#define db1(x) 			cout<<x<<'\n'
#define db2(x,y) 		cout<<x<<" "<<y<<'\n'
#define db3(x,y,z) 		cout<<x<<" "<<y<<" "<<z<<'\n'
#define rep(i,n) 		for(int i=0;i<(n);++i)
#define repA(i,a,n) 	for(int i=a;i<=(n);++i)
#define repD(i,a,n) 	for(int i=a;i>=(n);--i)
#define so(a) 			sort(a.begin(),a.end())
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
// to find all local maximaa and minima in O(n)
//	 for (int i=1;i<=n;i++)
//        {
//            if (i==1 || i==n || (p[i-1]<p[i])!=(p[i]<p[i+1]))
//           ans.push_back(p[i]);
//        }
int dx[] = { -1, 1, -1, 0, 0, -1, 1, 1 };
int dy[] = { -1, -1, 1, -1, 1, 0, 0, 1 };
int gcd(int a, int b)
{
	if (!b)
		return a;
	return gcd(b, a % b);
}
int modular_expo(int x, int y, int m)
{
	int ans = 1;
	while (y)
	{
		if (y & 1)
			ans = (ans % m * x % m) % m;
		x = (x % m * x % m) % m;
		y /= 2;
	}
	return ans % m ;
}
int power(int x, int y)
{
	int ans = 1;
	while (y)
	{
		if (y & 1)
			ans = (ans * x);
		x *= x;
		y /= 2;
	}
	return ans;
}
vector<int>tree[100001];
int dp[100001][2];
int solve(int u, bool constraint, int pr)
{
	if (dp[u][constraint] != -1)
		return dp[u][constraint];
	int ans = 0;
	int w = 1;
	for (int child : tree[u])
	{
		if (child != pr)
		{
			w = (w * solve(child, 0, u)) % mod;
		}
	}
	ans += w;
	if (!constraint)
	{
		w = 1;
		for (int child : tree[u])
			if (child != pr)
				w = (w * solve(child, 1, u)) % mod;
		ans = (ans + w) % mod;
	}
	return dp[u][constraint] = ans;
}

void solve()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	memset(dp, -1, sizeof(dp));
	rep(i, n - 1)
	{
		int u, v;
		cin >> u >> v;
		tree[u].pb(v);
		tree[v].pb(u);
	}
	db1(solve(1, 0, -1));
}
int32_t main()
{
	solve();
	return 0;
}


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

#define MAX(X,Y) ((X)>(Y)?(X):(Y))

int main(void){
  int t,acc,x;

  acc = x = 0;
  for (int i=0; i<5; i++){
    cin >> t;
    x = MAX(x, (10-t%10)%10);
    acc += (t+9)/10*10;
  }
  cout << (acc-x) << endl;
  return 0;
}
  

Measured memory_bytes: 256
local n = io.read("*n")
local t = 0
local x = 0
local y = 0
for i = 1, n do
  local t0, x0, y0 = io.read("*n", "*n", "*n")
  local dt = t0 - t
  local dx = x0 - x
  local dy = y0 - y
  if dx + dy > dt or (dt - dx - dy) % 2 > 0 then
    print("No")
    return 
  end
  t = t0
  x = x0
  y = y0
end
return print("Yes")


Measured memory_bytes: 256
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <sstream>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define sort_key(struct_name,key_name) [](const struct_name &x, const struct_name &y){return x.key_name < y.key_name;}
#define pb(x) push_back(x)
typedef long long ll;
const long long MOD = 1e9 + 7;
using namespace std;

//main
int main(){
    int N, K; cin >> N >> K;
    string S; cin >> S;
    int zero = 0;
    if(S[0]=='R' && S[1]=='R') zero += 1;
    if(S[N-1]=='L' && S[N-2]=='L') zero += 1;
    for(int i=1; i<N-1; i++){
        if(S[i]=='L' && S[i-1]=='L') zero += 1;
        if(S[i]=='R' && S[i+1]=='R') zero += 1;
    }
    int ans = min(N-1,zero+K*2);
    cout << ans << endl;
}



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

using namespace std;
using ll = long long;

int main(void){

   int n;
   cin >> n;

   vector<int> a(n);
   for (int i = 0; i < n;i++)
      cin >> a.at(i);

   //すべての可能性
   ll cnt = pow(3, n);

   int d_cnt = 1;
   for (int i = 0; i < n; i++){
      if(a.at(i)%2==0)
         d_cnt *= 2;
   }
   cout << cnt-d_cnt << endl;

   return 0;
   }


Measured memory_bytes: 384
import sys

# import os
# path = os.getcwd()
# path = os.path.join(path,"input.txt")
# sys.stdin = open(path)

input = sys.stdin.readline
import numpy as np
N = int(input())
abc = np.zeros((N,3))
for i in range(N):
    abc[i] = list(map(int,input().split()))

dp = np.zeros((N,3))
for i in range(N):
    if i == 0:
        dp[i] = abc[i]
        continue
    dp_a,dp_b,dp_c = dp[i-1]
    dp[i] = abc[i] + [max(dp_b,dp_c),max(dp_a,dp_c),max(dp_a,dp_b)]
print(int(max(dp[N-1])))


Measured memory_bytes: 18512
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  long long int N, A, B;
  cin >> N >> A >> B;
  if (A + B == 0 || A == 0)
  {
    cout << 0 << endl;
  }
  else if (A > N % (A + B) )
  {
    cout << N / (A + B) * A + N % (A + B) << endl;
  }
  else if (A <= N % (A + B) )
  {
    cout << N / (A + B) * A + A << endl;
  }
  return 0;
}


Measured memory_bytes: 256