akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;  //これで"std::cout"が"cout"と書ける

//MACRO
typedef long long ll;                  //64bit以上を表現可能な型
#define INF 100000000                  //ほぼ無限
#define itn int                        //タイポ対策
#define all(x) (x).begin(), (x).end()  //sort(all(x))などとする
#define SZ(x) ((int)(x).size())        //size()簡略化
//repetition
#define FOR(i, p, b) for (int i = (p); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define repR(i, n) for (int i = n; i >= 0; i--)
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \<< " " << __FILE__ << endl;
template <class T>
bool chMAX(T &a, const T &b) {  //aよりbが大きければaに代入
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chMIN(T &a, const T &b) {  //aよりbが小さければaに代入
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

//
//
//

int main() {
    int h, w;
    cin >> h >> w;
    string board[50];

    FOR(i, 0, h) {
        cin >> board[i];
    }

    const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
    const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
    //８方向の探索用    右、下、左、上、右下、左下、左上、右上となっている

    FOR(i, 0, h) {
        FOR(j, 0, w) {
            if (board[i][j] == '#') {
                continue;  //自身が爆弾ならスルー
            }
            int num = 0;
            FOR(d, 0, 8) {
                const int ni = i + dy[d];
                const int nj = j + dx[d];
                if (ni < 0 or h <= ni) continue;
                if (nj < 0 or w <= nj) continue;
                if (board[ni][nj] == '#') {
                    num++;
                }
            }
            board[i][j] = char(num + '0');
        }
    }
    FOR(i, 0, h) {
        cout << board[i] << endl;
    }

}

Measured memory_bytes: 256
//
// Created by yamunaku on 2019/09/07.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    string s,t;
    cin >> s >> t;
    int ans=0;
    rep(i,3) if(s[i]==t[i]) ans++;
    cout << ans << endl;
    return 0;
}


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

int main()
{
  long long a, b, x;
  cin >> a >> b >> x;
  if(a != 0)
  {
    cout << b / x - (a - 1) / x << endl;
  }
  else
  {
    cout << b / x + 1 << endl;
  }
}


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

// imos法
// 区間のダメージをimos法を使って累積で求める。
// 範囲が広いので、モンスター位置で範囲を管理。
// 範囲に入っているかの判定は lower_bound で行う。

ll total[200020];

int main() {
  ll N,D,A;
  cin >> N >> D >> A;
  vector< pair<ll,ll> > mon(N);
  REP(i,N) {
    cin >> mon[i].first >> mon[i].second;
    mon[i].second = (mon[i].second+A-1) / A;
  }
  sort( mon.begin(), mon.end() );
  ll ans = 0;
  REP(i,N) {
    mon[i].second -= total[i];
    if ( mon[i].second > 0 ) {
      // 現在の累積ダメージが体力より低ければ、爆弾を置く
      total[i] += mon[i].second;
      ans += mon[i].second;
      // 爆弾範囲外になる最初のモンスター位置で、累積ダメージを引く
      auto it = lower_bound( mon.begin(), mon.end(), make_pair(mon[i].first+2*D+1, -1LL<<60));
      ll x = distance(mon.begin(), it);
      total[x] -= mon[i].second;
    }
    total[i+1] += total[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <string>

uint64_t getDigit(uint64_t val)
{
	return std::to_string(val).length();
}

uint64_t F(uint64_t A, uint64_t B)
{
	uint64_t a = getDigit(A);
	uint64_t b = getDigit(B);
	return a > b ? a : b;
}

int main()
{
	uint64_t N;
	uint64_t answer;

	std::cin >> N;

	answer = UINT64_MAX;
	uint64_t limit = std::sqrt(N) + 1;
	for (uint64_t i = 1; i < limit; i++)
	{
		if (N % i == 0)
		{
			uint64_t A = i;
			uint64_t B = N / A;
			uint64_t f = F(A, B);

			if (f < answer)
			{
				answer = f;
			}
		}
	}

	std::cout << answer;

	return 0;
}


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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    cout << (A <= B / K * K ? "OK" : "NG") << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
   cin >> N;
  vector<int> vec(N);
for (int i = 0; i < N; i++) {
  cin >> vec.at(i);
} 
  int max;
  max =0;
  int count;
  count = 0;
  for(int j=0;j<N-1;j++){
   if(j + max >= N){break;}
   count =0;
  for(int i = j;i<N-1;i++){
  if(vec.at(i)>=vec.at(i+1)){
  count +=1;
  if(max < count){ max = count; }    
  }else{ break; } 
  }
  }
  
  
  cout << max << endl;
  
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
typedef long long ll;

ll F[45];
ll fibonacci(ll n) {
  if(n < 2)
    return F[n] = 1;
  if(F[n])
    return F[n];
  return F[n] = fibonacci(n-1) + fibonacci(n-2);
}
int main() {
  ll n;
  cin >> n;
  cout << fibonacci(n) << endl;
}

Measured memory_bytes: 1156
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string.h>
#include <bitset>
#include <array>

using namespace std;

const int maxn=1e5+5, mod=1e9+7, Log=30;
typedef long long ll;

inline int sum(int a, int b){
	if(a+b>=mod){
		return a+b-mod;
	}
	if(a+b<0){
		return a+b+mod;
	}
	return a+b;
}

inline int mul(int a, int b){
	return (ll)a*b%mod;
}

int pot(int a, int b){
	int sol=1;
	for(int i=0; i<Log; i++){
		if((1<<i)&b){
			sol=mul(sol, a);
		}
		a=mul(a, a);
	}
	return sol;
}

inline int dijel(int a, int b){
	return mul(a, pot(b, mod-2));
}


int a[maxn];
int fact[maxn];

void precompute(){
	fact[0]=1;
	for(int i=1; i<maxn; i++){
		fact[i]=mul(fact[i-1], i);
	}
}

inline int povrh(int a, int b){
	return dijel(fact[a], mul(fact[b], fact[a-b]));
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, k;
	precompute();
	cin >> n >> k;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	sort(a, a+n);
	int sol=0;
	for(int i=0; i<n; i++){
		if(i+1>=k){
//			cout << "in1" << endl;
//			cout << mul(a[i], povrh(i, k-1)) << endl;
			sol=sum(sol, mul(a[i], povrh(i, k-1)));
		}
		if(i<=n-k){
//			cout << "in2" << endl;
//			cout << mul(a[i], povrh(n-i-1, k-1)) << endl;
			sol=sum(sol, -mul(a[i], povrh(n-i-1, k-1)));
		}
//		cout << sol << '\n';
	}
	cout << sol << '\n';
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pi acos(-1.0)
#define rf freopen("in.txt", "r", stdin);
#define ld long double
#define all(v) v.begin(),v.end()
#define push_back push_back
#define ff first
#define ss second
#define ln length()
#define rep(i,a, n) for(int i=a;i<=n;i++)
#define repp(i,a,b) for(int i=a;i<b;i++)
#define s(n) scanf("%d",&n);
#define sl(n) scanf("%lld",&n);
#define sld(n) scanf("%lf", &n);

using namespace std;

int main() { //rf
    ll a, b;
    sl(a); sl(b);
    if (a%3 == 0 || b%3 == 0 || (a+b)%3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}


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

int main()
{
    int n1, n2, n3, mayor, suma;
    cin>>n1 >> n2>> n3;

    if ( n1 >= n2 && n1 >= n3 ){
        mayor=n1;
    }
    else{
        if ( n2 > n3 ){
            mayor=n2;
        }
        else{
            mayor=n3;
        }
    }
    
    suma=n1+n2+n3-mayor;
    cout<<suma;

}

Measured memory_bytes: 3516
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int l=0;
    int r = s.size();
    for (int i = 0;i<s.size();i++){
        char c = s[i];
        if (c!='A'){
            l++;
        }
        else{
            break;
        }
    }
    for (int i=s.size()-1;i>=0;i--){
        char c = s[i];
        if (c!='Z'){
            r--;
        }
        else{
            break;
        }
    }
    cout<<r-l;

    
}


Measured memory_bytes: 3736
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from heapq import heapify, heappop, heappush

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

N, K = MAP()

ans = 0
for b in range(1, N + 1):
    p = N // b
    r = N % b
    ans += p * max(0, b - K)
    ans += max(0, r - K + 1)
    if K == 0:
        ans -= 1
print(ans)



Measured memory_bytes: 5168
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

priority_queue<string, vector<string>, greater<string>> pq;

void func(const string s, int n) {
    const int s_len = s.size();
    if (s_len == n) {
        pq.emplace(s);
        return;
    }

    char max_alp = 'a' - 1;
    for (auto &&i : s) {
        max_alp = max(i, max_alp);
    }

    for (char i = 'a'; i <= min((char)(max_alp + 1), 'z'); i++) {
        func(s + i, n);
    }
}

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

    int n;
    cin >> n;

    func("", n);

    while (pq.size()) {
        cout << pq.top() << endl;
        pq.pop();
    }
}


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

void swp(int x,int y){
int tt,yy;
tt=x;yy=y;
x=yy;y=tt;

}
int main()
{

int N,k,f,tmp,r;
int num[101]={};
cin>>N;
f=1;tmp=0;r=0;
for(int i=0;i<N;i++)
{cin>>k;num[i]=k;}

while(f==1)
{
f=0;
for(int j=N-1;j>=1;j--)
{
if(num[j]<num[j-1]){r++;
tmp=num[j];num[j]=num[j-1];num[j-1]=tmp;f=1;}
;
}
}
for(int i=0;i<N-1;i++)
{cout<<num[i]<<" ";}
cout<<num[N-1]<<endl;
cout<<r<<endl;
return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	int N;
	cin >> N;
	cout << (N+999)/1000*1000-N << endl;

	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long modl(long long a,long long b,long long c){
	long long res,t;
	res=1%c;
	t=a%c;
	while(b){
		if(b&1){
			res=res*t%c;
		}
		t=t*t%c;
		b>>=1;
	}
	return res;
}
int main(){
	int n,num,k=0,flag=1;
	long long ans=1;
	int a[100010];
	scanf("%d",&n);
	memset(a,0,sizeof(a));
	for(int i=1;i<=n;i++){
		scanf("%d",&num);
		a[num]++;
	}
	if(a[0]>=2)flag=0;
	else {
		for(int i=1;i<n;i++){
			if(a[i]>=3) {
				flag=0;
			}
			else if(a[i]==2){
				k++;
			}
		}
	}

	if(flag==0)printf("0\n");
	else printf("%lld\n",modl(2,k,1000000000+7));
}

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

using namespace std;

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

  for (int i=A; i<=B; i++) {
      if (i % K == 0) {
          cout << "OK" << endl;
          return 0;
      }
  }
  cout << "NG" << endl;

}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
long n;

string strN;
void solve(){
  int S = 0;
  long N;
  for(int i = 0; i < strN.size(); i++){
    S += strN[i] - '0';
  }
  N = atoi(strN.c_str());
  if(N%S == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return;
}
int main(){
  cin >>  strN;
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
 
int main(){

    int N;
    cin >> N;
    string S[N];
    int AC,WA,TLE,RE;
    AC = 0;
    WA = 0;
    TLE = 0;
    RE = 0;
    for(int i = 0; i< N; i++){
        cin >> S[i];
        if(S[i] == "AC"){
            AC++;
        }else if(S[i] == "WA"){
            WA++;
        }else if(S[i] == "TLE"){
            TLE++;
        }else{
            RE++;
        }
    }

    cout << "AC" << " " << "x" << " " << AC << endl;
    cout << "WA" << " " << "x" << " " << WA << endl;
    cout << "TLE" << " " << "x" << " " << TLE << endl;
    cout << "RE" << " " << "x" << " " << RE << endl;
}


Measured memory_bytes: 6716
table = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8],
         [0, 4, 8], [2, 4, 6]]
check = ->(field, type) {
  table.each do |pat|
    return true if pat.map {|i| field[i] == type}.all?
  end
  false
}
game = ->(field, left) {
  if check.(field, "o")
      "o"
  elsif check.(field, "x")
      "x"
  else
    nxt = (left.size % 2).zero? ? "x" : "o"
    left.each do |pos|
      table[pos] = nxt
      a = game.(table, left.reject {|i| i == pos})
      return a if a
      table[pos] = "s"
    end
    false
  end
}
         
$<.readlines.map(&:chomp).map(&:chars).each do |field|
  left = field.map {|i| i == "s" ? i : nil}.compact
  result = game.(field, left)
  puts result ? result : "d"
end



Measured memory_bytes: 6884
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define F first
#define S second
#define nl cout<<"\n"
//cout<<fixed<<setprecision(11);
const ll MOD=1e9+7;
const ll ARR_MAX = 1e5+1;
const ll VAL_MAX = 1e5+1;
const ll INF=1e14;

void solve(){
    int n;cin>>n;
    int p[n],q[n];
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    for(int j=0;j<n;j++){
        cin>>q[j];
    }
    int perm[n]={};
    for(int i=0;i<n;i++){
        perm[i]=i+1;
    }
    int a=0,b=0;
    while(next_permutation(perm,perm+n)){
        bool f=0;
        for(int i=0;i<n;i++){
            if(perm[i]>p[i]){
                f=1;
                break;
            }
            else if(perm[i]<p[i]){
                f=0;
                break;
            }
        }
        if(f){
            a++;
        }
        f=0;
        for(int i=0;i<n;i++){
            if(perm[i]>q[i]){
                f=1;
                break;
            }
            else if(perm[i]<q[i]){
                f=0;
                break;
            }
        }
        if(f){
            b++;
        }
    }
    cout<<abs(a-b),nl;
}

int main(){
    fastio();
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
let to_list str =
  let n = String.length str in
  let rec doit i acc =
    if i = n then acc
    else doit (i + 1) (str.[i] :: acc)
  in
  doit 0 []

let to_int c = int_of_char c - int_of_char '0'

let plus l1 l2 =
  let rec doit i acc = function
    | ([], [], 1) -> (i + 1, 1 :: acc)
    | ([], [], _) -> (i, acc)
    | ([], hd :: tl, carry) ->
        let x = to_int hd + carry in
        if x <= 9 then doit (i + 1) (x :: acc) ([], tl, 0)
        else doit (i + 1) (x mod 10 :: acc) ([], tl, 1)
    | (hd :: tl, [], carry) ->
        let x = to_int hd + carry in
        if x <= 9 then doit (i + 1) (x :: acc) (tl, [], 0)
        else doit (i + 1) (x mod 10 :: acc) (tl, [], 1)
    | (a :: b, c :: d, carry) ->
        let x = to_int a + to_int c + carry in
        if x <= 9 then doit (i + 1) (x :: acc) (b, d, 0)
        else doit (i + 1) (x mod 10 :: acc) (b, d, 1)
  in
  doit 0 [] (to_list l1, to_list l2, 0)

let () =
  let n = read_int () in
  let rec doit i =
    if i < n then begin
      let l1 = read_line () in
      let l2 = read_line () in
      let n1 = String.length l1 in
      let n2 = String.length l2 in
      if n1 > 80 || n2 > 80 then print_endline "overflow"
      else if n1 < 10 && n2 < 10 then Printf.printf "%d\n" (int_of_string l1 + int_of_string l2)
      else begin
        let z, ans = plus l1 l2 in
        if z > 80 then print_endline "overflow"
        else (List.iter (fun e -> print_int e) ans; print_newline ())
      end;
      doit (i + 1)
    end
  in
  doit 0

Measured memory_bytes: 2152
// https://beta.atcoder.jp/contests/abc070

#include <bits/stdc++.h>
using namespace std;

template <typename T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr>
T gcd(T x, T y) {
    if (x < y) swap(x, y);
    while (0 < y) {
        auto r = x % y;
        x = y, y = r;
    }

    return x;
}

int main() {
    int n;
    cin >> n;
    uint64_t ans;
    for (int i = 0; i < n; ++i) {
        uint64_t t;
        cin >> t;

        if (i == 0) ans = t;
        else ans *= t / gcd(ans, t);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(){
    int x;
    int num;
    vector<int> v;

    while(cin >> x){
        num = x;
        if(num == 0){
            break;
        }
        v.push_back(x);
    }

    for(int i = 0; i < v.size(); i++){
        cout << "Case" << " " << (i+1) << ": " << v[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	ll n,t,a;
	ll T=0,A=0;
	cin >> n;
	REP(i,n){
		cin >> t >> a;
		
		if(t >= T && a >= A){
			T = t;
			A = a;
		}else{
			ll tt=t*max(T/t, A/a);
			ll aa=a*max(T/t, A/a);
			while(tt < T || aa < A){
				tt += t;
				aa += a;
			}
			
			T = tt;
			A = aa;
		}
	}
	
	cout << T+A << endl;
	
	return 0;
}

Measured memory_bytes: 3584
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    else:
        par[x] += par[y]
        par[y] = x
        return True
def same(x,y):
    return find(x) == find(y)
def size(x):
    return -par[find(x)]
n = int(input())
par = [-1]*n
p = []
edge = []
for i in range(n):
    x,y = map(int,input().split())
    p.append([x,y,i])
p.sort(key=lambda x:x[0])
for i in range(n-1):
    x_0,_,j=p[i]
    x_1,_,k=p[i+1]
    edge.append([x_1-x_0,j,k])
p.sort(key=lambda x:x[1])
for i in range(n-1):
    _,y_0,j=p[i]
    _,y_1,k=p[i+1]
    edge.append([y_1-y_0,j,k])
edge.sort()
ans = 0
for i in range(len(edge)):
    cost,u,v = edge[i]
    if not same(u,v):
        unite(u,v)
        ans+=cost
print(ans)

Measured memory_bytes: 126604
using System;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(ReadLine());
        if(N % 2 == 0)
        {
            WriteLine(N / 2 - 1);
        }
        else
        {
            WriteLine(N / 2);
        }
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include<vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using ll = long long;

using namespace std;



int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    int ans = 0;
    rep(i,n) cin >> a[i];
    rep(i,n) {
        cin >> b[i];
        ans += b[i];
    }
    rrep(i,n-1) cin >> c[i];
    rep(i,n-1) {
        if(a[i+1]-a[i]==1) ans += c[a[i]];
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
 int a, b, c;
 string ans;
 cin >> a >> b >>c;
 if(a < c){
  if(b>c){
   ans="Yes";
  }else{
  ans="No";
  }
 }else{
 if(b<c){
   ans="Yes";
  }else{
  ans="No";
  }
}
 cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9+1;
ll n;
ll rain[100005];
ll ans[100005];
int main(){
    cin >> n;
    ll sum = 0;
    rep(i,n){
        cin >> rain[i];
        sum += rain[i];
        if (i%2){
            if (i == 1) ans[i/2] = rain[i];
            else ans[i/2] += ans[i/2-1]+rain[i];
        }
    }
    rep(i,n/2+1){
        ans[n/2+i] = ans[n/2+i-1]+rain[2*i];
    }
    rep(i,n){
        ll a = 0;
        if ((i+1)%2){
            if (i == 0) a = 2*ans[n/2-1];
            else a = 2*(ans[i/2+n/2-1]-ans[i/2-1]);
        }
        else{
            if (i == 1) a = 2*(ans[n-1]-ans[n/2]);
            else a = 2*(ans[n-1]-ans[n/2+i/2]+ans[i/2-1]);
        }
        cout << sum-a << ' ';
    }
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, c=0;
  cin >> n;
  string s;
  map <string, int> m;
  forll(i, 0, n){
	cin >> s;
	m[s]++;
  }
  for (auto i=m.begin(); i!=m.end(); ++i)
	c++;
  cout << c << endl;
}


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

int main(){
    ll a,b,c,k;cin>>a>>b>>c>>k;
    if(k<=a){cout<<k<<endl;}
    else{
        if(k<=a+b){
            cout<<a<<endl;
        }else{
            cout<<a-(k-a-b)<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

const int MAX_N = 100050;
int N, M;
int a[MAX_N], b[MAX_N];

int cnt[MAX_N] = {};

int main(int argc, char **argv) {
    std::cin >> N >> M;

    for (int i = 1; i <= M; i++) {
        std::cin >> a[i] >> b[i];
    }

    for (int i = 1; i <= M; i++) {
        cnt[a[i]]++;
        cnt[b[i]]++;
    }

    for (int i = 1; i <= N; i++) {
        if (cnt[i] % 2 != 0) {
            std::cout << "NO" << std::endl;
            return 0;
        }
    }

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

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	int N; cin >> N;
	int A[200];
	rep(i, 0, N) {
		cin >> A[i];
	}
	int count = 0;

	bool even = true;

	rep(i, 0, N) {
		if (A[i] % 2 != 0) {
			even = false;
		}
	}
	if (!even) {
		cout << 0 << endl;
		return 0;
	}

	while (true) {
		count++;
		rep(i, 0, N) {
			A[i] /= 2;
		}

		rep(i, 0, N) {
			if (A[i] % 2 != 0) {
				even = false;
				break;
			}
		}

		if (!even) {
			break;
		}
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for (int i=1; i <= n; i++){
        int ex = 1;
        while (true){
            int A = i*(ex-1) + k;
            int B = i*ex - 1;
            A = max((int) 1, A);
            B = min(n, B);
            if (A > n) break;
            if (A <= B) ans += B-A+1;
            ex++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
O = list(input())
E = list(input())

l = len(O)
L = len(E)
s = ''

if l == L:
    for i in range(l):
        s = s + O[i] + E[i]
    print(s)
else:
    for i in range(L):
        s = s + O[i] + E[i]
    s += O[-1]
    print(s)


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

int n;
ll x[200010],y[200010];

void solve(){
    cin >> n;
    rep(i,n) cin >> x[i] >> y[i];
    ll ma1=-INF,ma2=-INF,ma3=-INF,ma4=-INF;int it1,it2,it3,it4;
    rep(i,n){
        if(chmax(ma1,x[i]+y[i])) it1=i;
        if(chmax(ma2,x[i]-y[i])) it2=i;
        if(chmax(ma3,-x[i]+y[i])) it3=i;
        if(chmax(ma4,-x[i]-y[i])) it4=i;
    }
    ll ans=0;
    rep(i,n){
        chmax(ans,abs(x[i]-x[it1])+abs(y[i]-y[it1]));
        chmax(ans,abs(x[i]-x[it2])+abs(y[i]-y[it2]));
        chmax(ans,abs(x[i]-x[it3])+abs(y[i]-y[it3]));
        chmax(ans,abs(x[i]-x[it4])+abs(y[i]-y[it4]));
    }
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 6780
s = gets.chomp

a = s[0..1].to_i
b = s[2..3].to_i

case [a.between?(1,12), b.between?(1,12)]
when [true,true]
  puts "AMBIGUOUS"
when [true,false]
  puts "MMYY"
when [false,true]
  puts "YYMM"
when [false,false]
  puts "NA"
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    int ans = (n - 1 + k - 2) / (k - 1);
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
typedef long long ll;
int max_cal(int a,int b)
{
  if(a>=b) return a;
  else return b;
}
void main(void)
{
  ll x,a,b,tmpi,tmpj,flag=0;
  scanf("%lld",&x);
  for(int i=-120;i<=120;i++){
    tmpi=i*i;
    tmpi=tmpi*tmpi*i;
    for(int j=-120;j<=i;j++){
      tmpj=j*j;
      tmpj=tmpj*tmpj*j;
      if((tmpi-tmpj)==x){
        flag=1;
        a=i;
        b=j;
        break;
      }
    }
    if(flag==1) break;
  }
  printf("%lld %lld",a,b);


}

Measured memory_bytes: 1696
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 文字列の入力
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long k = sc.nextLong();

		long sum = 0;
		if (a >= k) {
			sum = k;
		} else if (a < k && a + b >= k) {
			sum = a;
		} else {
			sum = a - (k - (a + b));
		}

		// 出力
		System.out.println(sum);
		sc.close();
	}
}


Measured memory_bytes: 35604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
char s[17];
ll val[17][17];
ll dp[17];
ll cnt[17];
int main()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	scanf("%s", s);
	int n = strlen(s);
	for (int i = n; i >= 1; i--)
	{
		s[i] = s[i - 1];
	}
	for (int i = 1; i <= n; i++)
	{
		ll x = 0;
		for (int j = i; j <= n; j++)
		{
			x = (10 * x + s[j] - '0');
			val[i][j] = x;
		}
	}
	dp[0] = 0;
	cnt[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = i; j >= 1; j--)
		{
			dp[i] += dp[j - 1] + cnt[j - 1] * val[j][i];
			cnt[i] += cnt[j - 1];
		}
	}
	printf("%lld\n", dp[n]);
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <utility>
#include <string>

#define loop(n) for(ll i=0;i<n;i++)

using namespace std;

typedef long long int ll;

constexpr int maxn = 40,maxc = 10;

int n,m[2],a[maxn+1][3],d[maxn+1][maxn*maxc+11][maxn*maxc+11];

int main() {
    scanf("%d %d %d",&n,&m[0],&m[1]);
    for(int i = 1;i <= n;i++) scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);
    for(int i = 0;i <= n;i++) for(int j = 0;j <= maxn*maxc+10;j++) for(int k = 0;k <= maxn*maxc+10;k++) d[i][j][k] = INT32_MAX/2;
    d[0][0][0] = 0;
    for(int i = 1;i <= n;i++) for(int j = 0;j <= maxn*maxc;j++) for(int k = 0;k <= maxn*maxc;k++) {
        int s = j + a[i][0],t = k + a[i][1];
        d[i][s][t] = min(d[i][s][t],d[i-1][j][k]+a[i][2]);
        d[i][j][k] = min(d[i][j][k],d[i-1][j][k]);
    }
    int ret = INT32_MAX/2;
    for(int i = 1;max(m[0],m[1])*i <= maxn*maxc;i++) ret = min(ret,d[n][m[0]*i][m[1]*i]);
    printf("%d",ret == INT32_MAX/2 ? -1 : ret);
}

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;
// int ans[100001][100001];

int main(){

  int n;cin>>n;
  int a[n+10],b[n+10];
  vector<vector<int> >v(100003);
  int k=0;
  rep(i,0,n-1){
    cin>>a[i]>>b[i];
    v[a[i]].push_back(b[i]);
    v[b[i]].push_back(a[i]);
    if(k<v[a[i]].size())k=v[a[i]].size();
    if(k<v[b[i]].size())k=v[b[i]].size();
  }
  // rep(i,1,n)sort(v[i].begin(),v[i].end());

  out(k);

  vector<vector<int> >alr(100003);
  map<P,int>mp;
  rep(i,1,n){
    int cn=1;
    rep(j,0,v[i].size()){
      if(alr[i].size()!=0&&alr[i][0]==cn){cn++;alr[i].erase(alr[i].begin());}
      if(i>v[i][j])continue;
      alr[v[i][j]].push_back(cn);

      mp[P(i,v[i][j])]=cn;
      cn++;
    }
  }
  rep(i,0,n-1){
    out(mp[P(a[i],b[i])]);
  }


  return 0;
}


Measured memory_bytes: 18560
#include<bits/stdc++.h>
#define fi(i,a,b) for(ll i = a; i < b; i++)
#define fd(i,a,b) for(ll i = a; i >= b; i--)
#define cfi(container,it) for(auto it = container.begin(); it != container.end(); it++)
#define cfd(container,it) for(auto it = container.rbegin(); it != container.rend(); it++)
#define vi vector<int>
#define vll vector<ll>
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back

using namespace std;
using ll = long long;
const int MOD = (int) 1e9 + 7;

const int nax = 2e5 + 5;
ll n, k, knt = -1, rep = 0;
vi ans, dup, a(nax);
bool vis[nax] = {false};
map<ll, ll> mp;

void compute(ll start) {
	ans.pb(start);
	ll next = a[start];
	while(next != start) {
		ans.pb(next);
		next = a[next];
	}
}

void dfs(ll cur) {

	vis[cur] = true;
	mp[cur] = (++knt);

	if(!vis[a[cur]])
		dfs(a[cur]);
	else {
		rep = mp[a[cur]];
		compute(a[cur]);
	}

}

ll dfs2(ll cur) {
	ll mov = 0;
	while(mov != k) {
		cur = a[cur];
		mov++;
	}

	return cur;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin>>n>>k;

	fi(i, 1, n + 1) {
		cin>>a[i];
	}

	dfs(1);

	if(k > rep) {
		k -= rep;
	} else {
		cout<<dfs2(1)<<'\n';
		return 0;
	}
	ll sz = ans.size();
	k %= sz;
	if(k < 0)
		k += sz;
	cout<<ans[k]<<'\n';

	return 0;
}

Measured memory_bytes: 16800
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[100000],dp[100][100];

int main(){
  cin >> s;
  rep(i,0,s.sz){
    if(s[i] == ',')printf(" ");
    else cout << s[i];
  }
  puts("");
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int maxn=51;
const int xx[4]={1,-1,0,0};
const int yy[4]={0,0,1,-1};
int endx,endy;
int n,m;
int num[maxn][maxn];
int q[maxn][maxn][1001];
bool visit[maxn][maxn];
char s[maxn][maxn];
int now;

bool ins(int x,int y)
{
	return x>=0&&x<n&&y>=0&&y<m;
}

bool dfs(int x,int y,int dep)
{
	visit[x][y]=1;
	if (x==endx&&y==endy)
	{
		 q[x][y][ num[x][y]++]=dep;
		 now=dep;
		 return 1;
	}
	for(int i=0;i<4;i++)
	{
		int nowx=x+xx[i];
		int nowy=y+yy[i];
		if (ins(nowx,nowy)&&!visit[nowx][nowy]&&s[nowx][nowy]=='.')
		{
			if (dfs(nowx,nowy,dep+1))
			{
				q[x][y][ num[x][y]++]=dep;
				return 1;
			}
		}
	}
	return 0;
}

int a[maxn][maxn],b[maxn][maxn],c[maxn][maxn];

int main()
{
	int k;
	while(scanf("%d %d %d",&n,&m,&k)==3)
	{
		for(int i=0;i<n;i++) scanf("%s",s[i]);
		for(int i=0;i<n;i++)
		 for(int j=0;j<m;j++) scanf("%d",&a[i][j]);
		for(int i=0;i<n;i++)
		 for(int j=0;j<m;j++) scanf("%d",&b[i][j]);
		for(int i=0;i<n;i++)
		 for(int j=0;j<m;j++) scanf("%d",&c[i][j]);
		memset(num,0,sizeof(num));
		int xx,yy;
		scanf("%d %d",&xx,&yy);
		bool first=1;

		now=0;
		k--;
		while(k--)
		{
			scanf("%d %d",&endx,&endy);
			memset(visit,0,sizeof(visit));
			dfs(xx,yy,now);
			if (!first) num[xx][yy]--;
			first=0;
			xx=endx;yy=endy;
		}
		int ans=0;
		for(int i=0;i<n;i++)
		 for(int j=0;j<m;j++)
		  if (num[i][j])
		  {
		  	ans+=b[i][j]+c[i][j];
		  	for(int k=0;k<num[i][j]-1;k++)
		  	{
		  		int t=min(b[i][j]+c[i][j],
						 (q[i][j][k+1]-q[i][j][k])*a[i][j]);
		  		ans+=t;
		  	}
		  }
		printf("%d\n",ans);
	}
	return 0;
}

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

int main() {
  ll n; cin >> n;
  ll sum=0; vector<ll> a(n); map<ll,ll>mp;
  rep(i,n){
    cin >> a[i];
    sum+=a[i];
    mp[a[i]]++;
  }
  ll q; cin >> q;
  vector<ll> ans(q);
  rep(i,q){
    ll b,c; cin >> b >> c;
    sum-=b*mp[b];
    sum+=c*mp[b];

    mp[c]+=mp[b];
    mp[b]=0;

    ans[i]=sum;
  }

  rep(i,q)cout << ans[i] << endl;

}


Measured memory_bytes: 10560
require 'prime'

n = gets.to_i

primes = Hash.new(0)
(2..n).each { |i|
  i.prime_division.each { |p, n|
    primes[p] = primes[p] + n
  }
}

p primes.values.inject(1) { |mem, var| mem * (var + 1) } % (10 ** 9 + 7)

Measured memory_bytes: 2300
import sys

def print_arr(arr):
	for i in range(len(arr)):
		sys.stdout.write(str(arr[i]))
		if i != len(arr) - 1:
			sys.stdout.write(' ')
	print()

def insertion_sort(arr, n, g):
	cnt = 0
	for i in range(g, n):
		v = arr[i]
		j = i - g
		while j >= 0 and arr[j] > v:
			arr[j + g] = arr[j]
			j = j - g
			cnt += 1
		arr[j + g] = v
	return cnt

def shell_sort(arr, g):
	cnt = 0
	for i in range(len(g)):
		cnt += insertion_sort(arr, len(arr), g[i])
	return cnt

def get_gap(gap):
	lst = []
	v = 1
	cnt = 1
	while v <= gap:
		lst.append(v)
		v += 3**cnt
		cnt += 1
	if len(lst) == 0: lst.append(1)
	return list(reversed(lst))

n = int(input())
arr = [0] * n
for i in range(n):
	arr[i] = int(input())

g = get_gap(n)
m = len(g)
cnt = shell_sort(arr, g)

print(m)
print_arr(g)
print(cnt)
for i in range(n):
	print(arr[i])



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

#define endl "\n"
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first 
#define ss second 
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vii vector<pii>
#define vvi vector<vi>
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

//const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

//#define int int64_t
//int a[N+2];
vi N;
int solve(int pos,int flag,int f1,int f2,int f3){
  if(pos==N.size()){
    if(f1==1 && f2==1 && f3==1)
      return 1;
    else return 0;
  }
  vi v;
  v.pb(3);
  v.pb(5);
  v.pb(7);
  int ans=0;
  for(auto curr:v){
    if(flag==0 && curr<=N[pos]){
      if(curr==3)
        ans+=solve(pos+1,flag|(curr<N[pos]),f1|1,f2,f3);
      if(curr==5)
        ans+=solve(pos+1,flag|(curr<N[pos]),f1,f2|1,f3);
      if(curr==7)
        ans+=solve(pos+1,flag|(curr<N[pos]),f1,f2,f3|1);
    }else if(flag==1){
      if(curr==3)
        ans+=solve(pos+1,flag,f1|1,f2,f3);
      if(curr==5)
        ans+=solve(pos+1,flag,f1,f2|1,f3);
      if(curr==7)
        ans+=solve(pos+1,flag,f1,f2,f3|1);
    }
  }
  return ans;

}
int32_t  main(){
  IOS;
  int n;cin>>n;//process it to string 
  while(n>0){
    N.pb(n%10);
    n/=10;
  }
  reverse(all(N));
  int ans=solve(0,0,0,0,0);
  for(int i=1;i<N.size();++i)ans+=solve(i,1,0,0,0);
  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int h1, m1;
  cin >> h1 >> m1;
  int h2, m2;
  cin >> h2 >> m2;
  int k;
  cin >> k;
  int t = h2 * 60 + m2 - (h1 * 60 + m1);
  cout << t - k << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define vi vector<int>
#define Vi vector<vector<int>>
#define ll long long
#define P pair<int,int>
#define vp  vector<P>
#define vl vector<long>
#define mod 1000000009
using namespace std;
int main(){
	int n,m;
	ll k;
	cin>>n>>m>>k;
	vl A(n+1,0),B(m+1,0);
	for(int i=1;i<=n;i++){
		cin>>A[i];
		A[i]+=A[i-1];
	}
	for(int i=1;i<=m;i++){
		cin>>B[i];
		B[i]+=B[i-1];
	}
	int ans=0,i=0,j=m;
	while(i<=n && k>=A[i]){
		while(j>=0 && B[j]>k-A[i])
			j--;
		ans=max(ans,i+j);
		i++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6412
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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;
}
void dfs(ll v,ll par,set<ll> &st,vl &ans, vvl &g){
    for(auto nv:g[v]){
        if(par==nv)continue;
        if(ans[nv]==-1){
            ans[nv]=v;
            st.ins(v);dfs(nv,v,st,ans,g);st.erase(v);
        }
        else{
            if(st.count(ans[nv]))ans[nv]=v;
        }
    }
}
int main(){
    ll n,m;cin >>n >>m;
    vvl g(n);
    vl ans(n,-1);
    set<ll> st;rep(i,n)st.ins(i);
    rep(i,n-1+m){
        ll a,b;cin >> a >> b;a--;b--;
        g[a].pb(b);
        st.erase(b);
    }
    ll s=*st.begin();st.clear();
    dfs(s,-1,st,ans,g);
    for(auto p:ans)cout << p+1 <<endl;
} 

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

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

    vector<int> a(s.size()+1, 0);
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '<') a[i+1] = a[i] + 1;
    }
    for (int i = s.size()-1; i >= 0; i--) {
        if (s[i] == '>') a[i] = max (a[i], a[i+1]+1);
    }
    long long ans = 0;
    for (int i = 0; i <= s.size(); i++) ans += a[i];
    cout << ans << endl;
}


Measured memory_bytes: 5772
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int a,b,c,f=0,i;
    cin>>a>>b>>c;
    a%=b;
    for (i=0;i<b;i++)
    {
        if ((a*i)%b==c)
        {
            f=1;
            break;
        }
    }
    if (f)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <cstring>
#include <cmath>
#include <string>
#include <numeric>*/

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //桁DP→桁を前から見に行く。
  
  //input
  string S;
  cin >> S;//添え字は0~N-1
  int N = S.length();
  
  //main
  vector<vector<long>> memo(N+10, vector<long>(13, 0)); //Sを右からi(0~N)桁見た。  
  memo[0][0] = 1;
  
  int mod = 1e9+7;
  int m = 13;
  
  //Sを後から見て行くとpowがオーバーフローする。
  for(int i=1; i<N+1; i++){//左からi桁目
    if(S[i-1]=='?'){//i桁目が"?"の時
      for(int k=0; k<10; k++){
        //int km = (k*(long)pow(10,i-1)) % m;
        //kに代入するとループが正常に回らない。
        for(int j=0; j<13; j++){
          int j_next = (j*10+k)%m;
          memo[i][j_next] += memo[i-1][j];
        }
      }
      fN(j,13) memo[i][j] %= mod;
      
    }else{//i桁目が数字の時
      int k = S[i-1] - '0';
      //int km = (k*(int)pow(10,i-1)) % m;
      for(int j=0; j<13; j++){
        int j_next = (j*10+k)%m;
        memo[i][j_next] += memo[i-1][j];
      }  
    fN(j,13) memo[i][j] %= mod;
    }
  }
  
  // output
  cout << (memo[N][5])%mod << endl;
  
  //debug
  /*
  fN(i,N+1){
    fN(j,13){
      cout<<memo[i][j]<<" ";
    }
    cout << endl;
  }
  */
  
  return 0;
}

Measured memory_bytes: 13696
#include <stdio.h>
 
int main(void) {
    int count,max;
    int maxseisuu;
    int minseisuu;
    int i,j;
    char seisuu[10],temp;
    scanf("%d",&max);
    for(count=0;count<max;count++) {
        scanf("%s",seisuu);
        for(i=7;i>0;i--) {
            for(j=0;j<i;j++) {
                if(seisuu[j]>seisuu[j+1]) {
                    temp=seisuu[j];
                    seisuu[j]=seisuu[j+1];
                    seisuu[j+1]=temp;
                }
            }
        }
        maxseisuu=0;minseisuu=0;
        for(i=0;i<8;i++) {
            minseisuu=minseisuu*10+seisuu[i]-'0';
            maxseisuu=maxseisuu*10+seisuu[7-i]-'0';
        }
        printf("%d\n",maxseisuu-minseisuu);
    }
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

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;}

const ll MOD = 1000000007;
const int INF = 1<<29;

int main(){
  int a, b; cin >> a >> b;

  int res = 0;
  if (a > b) swap(a, b);
  for(int i = 0; i < b; ++i){
    res += a * pow(10, i);
  }
  cout << res << endl;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int n;
int a[300000];
vector<int>E[300000];
int dp[300000];
int ans[300000];

void dfs(int v,int p){
	int id=lower_bound(dp,dp+300000,a[v])-dp;
	int memo=dp[id];
	dp[id]=a[v];
	ans[v]=lower_bound(dp,dp+300000,INF)-dp;
	for(int u:E[v]){
		if(u==p)continue;
		dfs(u,v);
	}
	dp[id]=memo;
}
int main(){
	cin>>n;
	rep(i,n)scanf("%d",&a[i]);
	rep(i,n-1){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	memset(dp,0x3f,sizeof(dp));
	dfs(0,-1);
	rep(i,n){
		printf("%d\n",ans[i]);
	}
}

Measured memory_bytes: 34116