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

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

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

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

  LL N;
  cin >> N;
  vector<LL> A(N);

  LL x = 0;
  REP(i, N)
  {
    cin >> A[i];
    if(i%2==0){
      x += A[i];
    }else{
      x -= A[i];
    }
  }

  x /= 2;

  vector<LL> Y(N);

  Y[0] = x;

  FOR(i,1,N){
    Y[i] = A[i-1] - Y[i - 1];
  }
  
  REP(i,N){
    if(i!=0){
      cout << " ";
    }
    cout << Y[i] * 2;
  }
  cout << endl;
}

//  3 8 7 5 5

// 1 2 6 1 4


// x a[0]-x a[1]-(a[0]-x)


//  2 2 4
 
// x a[0]-x a[1]-a[0]+x a[2]-a[1]+a[0]-x
// 2x=a[2]-a[1]+a[0]


Measured memory_bytes: 2944
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>
#include <unordered_map>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll intpow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = intpow(N, P/2);
        return t*t;
    }
    return N * intpow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
int main(){
    string s;cin>>s;
    int n=s.size();
    bool flag=0;//R
    int cnt1=0;
    int cnt2=0;
    int num[100002];
    rep(i,n-1){
        int mid;
        
        if(s[i]=='R'&&s[i+1]=='R'){
            cnt1++;
            num[i]=0;
            }
        if(s[i]=='R'&&s[i+1]=='L')mid=i;
        if(s[i]=='L'&&s[i+1]=='L'){
            cnt2++;
            num[i+1]=0;
            }
        if((s[i]=='L'&&s[i+1]=='R')||i==n-2){
            num[mid]=cnt1/2+(cnt2+1)/2+1;
            num[mid+1]=cnt2/2+(cnt1+1)/2+1;
            cnt1=0;
            cnt2=0;
            }
        }

        rep(i,n)cout << num[i]<<endl;
}

Measured memory_bytes: 1024
x=int(input())
 
if x<100:
	print("0")
	exit()
 
while 1:
	tm=(str(x)[-2:])
	if int(tm) > 5:
		x-=105
	else:
		print("1")
		exit()
 
	if x<100:
		print("0")
		exit()

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for(int i = a; i <= n; i++)
#define sum(start, end) accumulate(start, end, 0)

template<class T, class U>
bool check(T first, U second) {
    return (first == second);
}

template<class T>
T digitSum(T num) {
    T dig;
    T sum = 0;
    while (num) {
        dig = num % 10;
        sum += dig;
        num /= 10;
    }
    return sum;
}

typedef long long ll;


void solve() {
    ll n;
    cin >> n;

    cout << (n % digitSum(n) == 0 ? "Yes" : "No") << endl;
}

int main() {	
    std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
    solve();
}

Measured memory_bytes: 256
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-02-13 13:49:16
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#include<assert.h>
const int N=400010;
int n,a[N],s[N],v[N],t;
int check(int c)
{
	s[t=1]=a[1]; v[1]=1;
	fr(i,2,n) if(a[i]>a[i-1])
	{
		if(v[t]==1) s[t]=a[i];
		else{ t++; s[t]=a[i]; v[t]=1; }
	}
	else
	{
		while(s[t-1]>=a[i]) t--;
		s[t]=a[i];
		if(v[t]==c)
		{
			if(t==1) return 0;
			if(s[t-1]-1==s[t-2])
			{
				v[t-1]++; v[t]=1;
				if(v[t-1]==v[t-2])
				{
					s[t-2]=s[t-1]; v[t-1]=v[t]; s[t-1]=s[t]; t--;
				}
			}
			else
			{
				t++;
				s[t-1]=s[t-2]; s[t-2]--; s[t]=a[i];
				v[t-1]=v[t-2]+1; v[t]=1;
			}
		}
		else
		{
			if(s[t]-1==s[t-1])
			{
				v[t]++;
				if(v[t]==v[t-1]){ s[t-1]=s[t]; t--; }
			}
			else
			{
				s[t]--; t++; s[t]=s[t-1]+1; v[t]=v[t-1]+1;
			}
		}
		assert(t<=1||v[t]!=v[t-1]); assert(t<=2||v[t-1]!=v[t-2]);
	}
	return 1;
}
int main()
{
	n=read();
	fr(i,1,n) a[i]=read();
	int l=1,r=n;
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

int main() {
	int d;
	ll g;
	cin >> d >> g;
	vector<long long> p(d), c(d);
	for (int i = 0; i < d; ++i) cin >> p[i] >> c[i];
	ll res = 1 << 30;
	for (int bit = 0; bit < (1 << d); ++bit) {
		ll sum = 0, num = 0;//numは問題数,sumは得点
		for (int i = 0; i < d; ++i) {
			if (bit & (1 << i)) {
				sum += c[i] + p[i] * 100 * (i + 1);
				num += p[i];
			}
		}
		if (sum >= g) res = min(res, num);
		else {
			for (int i = d - 1; i >= 0; --i) {
				if (bit & (1 << i)) continue;
				for (int j = 0; j < p[i]; ++j) {
					if (sum >= g) break;
					sum += 100 * (i + 1);
					++num;
				}
			}
			res = min(res, num);
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

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

    set<string> setS;
    rep(i,1,K+1){
        rep(j,0,s.size()-i+1){
            setS.insert(s.substr(j,i));
            if(setS.size()>K) setS.erase(*(prev(setS.end())));
        }
    }

    string ans=*(next(setS.begin(),K-1));
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define Fordown(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}

const int N = 1e5 + 1e3;
int last  = -1;
int ans = 0;
int main () {
	int n = read();
	For (i, 1, n) {
		int val = read();
		if (val == i) {
			++ans;
			if (last == i - 1) --ans;
			else last = i;
		}
	}
	printf ("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

  if ( b-a <= 0 ) {
    cout << "delicious" << endl;
  } else if ( b-a <= x ) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }
  
  return 0;
}



Measured memory_bytes: 384
import math

words = lambda t : list(map(t, input().split()))
n = int(input())

x = n / 1.08
#print(x)
if math.floor(math.floor(x) * 1.08) == n:
    #print(1)
    print(math.floor(x))
elif math.floor(math.ceil(x) * 1.08) == n:
    #print(2)
    print(math.ceil(x))
else:
    print(":(")


Measured memory_bytes: 3060
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
// r#"2017/12/01"# => "2018/12/01",
r#"579 123 456"# => "0",
// r#"24"# => "No",
//
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        x: i64,
        a: i64,
        b: i64,
    }

    (x - a - (x - a) / b * b).to_string()
}

Measured memory_bytes: 4352
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;


void calc() {

	Int H, W; std::cin >> H >> W;
	std::array<std::array<Int, 10>, 10> dist;
	std::vector<std::vector<Int>> A(H, std::vector<Int>(W));
	rep(i, 10)rep(j, 10) {
		std::cin >> dist[i][j];
	}
	rep(i, H)rep(j, W) {
		std::cin >> A[i][j];
	}
	rep(k, 10)rep(i, 10)rep(j, 10) {
		dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
	}
	Int ans = 0;
	rep(i, H)rep(j, W) {
		if (A[i][j] == -1)continue;
		ans += dist[A[i][j]][1];
	}

	std::cout << ans;

}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int x;
  std::cin >> x;
  for(int i = -118; i <= 119; i++){
    for(int j = 119; j >= -118; j--){
      ll a = pow(i,5), b = pow(j,5);
      if(a - b == (ll)x){
        std::cout << i << ' ' << j << '\n';
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 4100
//21
#include<iostream>
#include<algorithm>

using namespace std;

int g[20][20];
int w,h;

int dfs(int sy,int sx,int d){
  if(d>10){
    return 100;
  }else{
    int m=100;
    for(int i=0;i<4;i++){
      int y=sy,x=sx;
      int di[]={0,1,0,-1,0};
      for(int j=0;;j++){
	int ny=y+di[i];
	int nx=x+di[i+1];
	if(0<=ny&&ny<h&&0<=nx&&nx<w){
	  if(g[ny][nx]==3){
	    m=d;
	    break;
	  }else if(g[ny][nx]==1){
	    if(j==0)break;
	    g[ny][nx]=0;
	    m=min(m,dfs(y,x,d+1));
	    g[ny][nx]=1;
	    break;
	  }
	  y=ny;
	  x=nx;
	}else{
	  break;
	}
      }
    }
    return m;
  }
}

int main(){
  while(cin>>w>>h,w|h){
    int sy,sx;
    for(int y=0;y<h;y++){
      for(int x=0;x<w;x++){
	cin>>g[y][x];
	if(g[y][x]==2){
	  sy=y;
	  sx=x;
	}
      }
    }
    int r=dfs(sy,sx,1);
    cout<<((r>10)?-1:r)<<endl;
  }
  return 0;
}
    

Measured memory_bytes: 1160
from math import gcd

mod = 1000000007

n = int(input())
counter = {}
zeros = 0
for i in range(n):
    a, b = map(int, input().split())
    if (a == 0 and b == 0):
        zeros += 1
        continue
    g = gcd(a, b)
    a //= g
    b //= g
    if (b < 0):
        a = -a
        b = -b
    if (b == 0 and a < 0):
        a = -a
    counter[(a, b)] = counter.get((a, b), 0)+1

counted = set()
ans = 1
for s, s_count in counter.items():
    if s not in counted:
        if s[0] > 0 and s[1] >= 0:
            t = (-s[1], s[0])
        else:
            t = (s[1], -s[0])
        t_count = counter.get(t, 0)
        now = pow(2, s_count, mod)-1
        now += pow(2, t_count, mod)-1
        now += 1
        ans *= now
        ans %= mod
        counted.add(s)
        counted.add(t)
print((ans - 1 + zeros) % mod)


Measured memory_bytes: 90912
def main():
  N,K=map(int,input().split())
  A=list(map(int,input().split()))
  n=[0]*N
  #行ったことある町リスト
  d=[1]
  for _ in range(K):
    T=A[d[-1]-1]
    if n[T-1]==1:
      break
    else:
      n[T-1]=1
    d.append(T)
  F=d.index(T)
  LOOP_TOWN=d[F:]
  q=(K-F)%len(LOOP_TOWN)
  print(LOOP_TOWN[q])

if __name__ == "__main__":
    main()


Measured memory_bytes: 32208
from sys import exit, stdin

input = stdin.readline
import copy

# from collections import deque,Counter
# import numpy as np


def pow_mod(a, n, d):
    tmp = 1
    for _ in range(n):
        tmp = (tmp * a) % d
    return tmp


(N,) = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = (pow_mod(10, N, mod) + pow_mod(8, N, mod) - 2 * pow_mod(9, N, mod)) % mod

print(ans)


Measured memory_bytes: 9260
# input
n = gets.chomp.to_i
graph = Array.new(n+1){[]}
color = Array.new(n+1, -1)

(n-1).times do
  u, v, w = gets.chomp.split.map(&:to_i)
  graph[u].push([v, w])
  graph[v].push([u, w])
end  

# main
que = [1]
color[1] = 0
while not que.empty? do
  nver = que.shift
  ncol = color[nver]
  
  graph[nver].each do |v|
    if color[v[0]] == -1 then
      que.push(v[0])
    end
    if v[1].odd? then
      color[v[0]] = 1 - ncol
    else
      color[v[0]] = ncol
    end
  end
end
  
# output
(1..n).each do |i|
  puts color[i]
end
  

Measured memory_bytes: 27516
x, k, d = map(int, input().split())

x, cnt = abs(x), abs(x) // d
if k % 2 == cnt % 2:
    ans = abs(x - d * min(k,cnt))
elif k % 2 != cnt % 2:
    ans = abs(x - d * min(k,(cnt + 1)))
print(ans)


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

int main()
{
	int n;
	
	cin >> n;

	for (int i = 0; i < n; i++){
		queue<int> ball;
		int num;
		for (int j = 0; j < 10; j++){
			cin >> num;
			ball.push(num);
		}

		int b = 0, c = 0;
		for (int j = 0; j < 10; j++){
			int p_ball = ball.front();
			if (b < p_ball){
				b = p_ball;
				ball.pop();
			}
			else if (c < p_ball){
				c = p_ball;
				ball.pop();
			}
			else {
				cout << "NO" << endl;
				break;
			}
		}

		if (ball.empty()){
			cout << "YES" << endl;
		}
	}

	return (0);
}

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

int main(){

    string S;
    cin >> S;

    int ans = 0;
    for(int i = 0; i < S.size(); i++){
        int count = 0;
        for(int j = i; j < S.size(); j++){
            if(S[j] == 'A' || S[j] == 'C' || S[j] == 'G' || S[j] == 'T') count++;
            else break;
        }
        ans = max(ans, count);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
L=int(input())
a=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[L-1])


Measured memory_bytes: 3064
N = int(input())
s = input()
ans = 0
for i in range(1000):
  code = str(i).zfill(3)
  f = 0
  for j in range(len(s)):
    if (s[j] == code[f]):
      f += 1
    if (f == 3):
      break
  if (f == 3):
    ans += 1
print(ans)


Measured memory_bytes: 41180
a,b,c,x,y = map(int,input().split())
pizza = [(x,a),(y,b)]
pizza.sort()
sp,sq = pizza[0][1],pizza[0][0]
lp,lq = pizza[1][1],pizza[1][0]


print(min(a*x+b*y,c*2*lq,c*2*sq+lp*(lq-sq)))

Measured memory_bytes: 3064
N, WI = map(int, input().split())
V = [0] * N
W = [0] * N
for i in range(N):
    v, w = map(int, input().split())
    V[i] = v
    W[i] = w

dp = [[0] * 10100 for _ in range(N+1)]

for i in range(1,1+N):
    for j in range(10100):
        if j-W[i-1] >= 0:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-W[i-1]]+V[i-1])
        else:
            dp[i][j] = dp[i-1][j]
    
print(dp[N][WI])



Measured memory_bytes: 40480
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
    cin>>a>>b>>c;
  if(a<b&&b<c){
    cout<<a<<" "<<b<<" "<<c<<endl;
  }
  else if(a<c&&c<b){
    cout<<a<<" "<<c<<" "<<b<<endl;
  }
  else if(b<a&&a<c){
    cout<<b<<" "<<a<<" "<<c<<endl;
  }
  else if(b<c&&c<a){
    cout<<b<<" "<<c<<" "<<a<<endl;
  }
  else if(c<a&&a<b){
    cout<<c<<" "<<a<<" "<<b<<endl;
  }
  else if(c<b&&b<a){
    cout<<c<<" "<<b<<" "<<a<<endl;
  }
  else if(a==b&&b<c){
    cout<<a<<" "<<b<<" "<<c<<endl;
  }
  else if(a==c&&c<b){
    cout<<a<<" "<<c<<" "<<b<<endl;
  }
  else if(b==a&&a<c){
    cout<<b<<" "<<a<<" "<<c<<endl;
  }
  else if(b==c&&c<a){
    cout<<b<<" "<<c<<" "<<a<<endl;
  }
  else if(c==a&&a<b){
    cout<<c<<" "<<a<<" "<<b<<endl;
  }
  else if(c==b&&b<a){
    cout<<c<<" "<<b<<" "<<a<<endl;
  }
  else if(a==b&&b==c){
    cout<<a<<" "<<b<<" "<<c<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//

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

        if (A == 2 || B == 2)
        {
                cout << "No" << endl;
                return 0;
        }

        int Q[7] = {1, 3, 5, 7, 8, 10, 12};
        int R[4] = {4, 6, 9, 11};

        for (int i = 0; i < 7; i++)
        {
                for (int j = i + 1; j < 7; j++)
                {
                        if (A == Q[i] && B == Q[j])
                        {
                                cout << "Yes" << endl;
                                return 0;
                        }
                }
        }
        for (int i = 0; i < 4; i++)
        {
                for (int j = i + 1; j < 4; j++)
                {
                        if (A == R[i] && B == R[j])
                        {
                                cout << "Yes" << endl;
                                return 0;
                        }
                }
        }

        cout << "No" << endl;

        return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
#define N 4050
#define mod 924844033
typedef long long ll;
int n,K,vis[N][2],ed[N];
int f[N][N>>1][2],g[N];
ll fac[N],ans;
int main() {
	scanf("%d%d",&n,&K);
	int i,j,x,y,cnt=0;
	for(i=1;i<=n;i++) {
		for(j=0;j<2;j++) if(!vis[i][j]) {
			for(x=i,y=j;x<=n;x+=K,y=!y) {
				vis[x][y]=1; cnt++;
			}
			ed[cnt]=1;
		}
	}
	f[1][0][0]=1;
	for(i=1;i<=cnt;i++) {
		for(j=0;j<=n;j++) {
			f[i+1][j][0]=(f[i][j][1]+f[i][j][0])%mod;
			if(!ed[i]) {
				f[i+1][j+1][1]=f[i][j][0];
			}
		}
	}
	for(i=0;i<=n;i++) g[i]=(f[cnt][i][0]+f[cnt][i][1])%mod;
	for(fac[0]=i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
	for(i=0;i<=n;i++) {
		if(i&1) ans=(ans-g[i]*fac[n-i])%mod;
		else ans=(ans+g[i]*fac[n-i])%mod;
	}
	printf("%lld\n",(ans+mod)%mod);
}


Measured memory_bytes: 63616
#include <bits/stdc++.h>
#define FOR(i, n) for(ll i = 0; i < n; i++)
#define FORR(i, n) for(ll i = n; i >= 0; i--)
#define FORS(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) accumulate(v.begin(),v.end(),0)
#define OUT(n) (cout << n << endl)
#define IN1(a) (cin >> a)
#define IN2(a,b) (cin >> a >> b)
#define IN3(a,b,c) (cin >> a >> b >> c)
#define IN4(a,b,c,d) (cin >> a >> b >> c >> d)
using namespace std;
typedef long long ll;

int main(){
  int a,b,k;
  IN1(k);
  IN2(a,b);
  if (a%k == 0){
    OUT("OK");
    exit(0);}
  else
  {
    if (((a/k)+1)*k <= b){
      OUT("OK");
    }
    else
    {
      OUT("NG");
    }
    
  }
  
  }

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
int main(){
    ll X;
    cin >> X;
    ll a = 100, y = 0;
    while(a < X){
        a += a * 0.01;
        //cout << a << endl;
        y++;
    }
    cout << y << endl;
    return 0;
}

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

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

const int INF = 1001001001;

int main() {
    ll A,B,C,K;
    cin>> A>>B>>C>>K;
    if(A>=K)cout <<K;
    else if(B>=(K-A))cout <<A;
    else cout <<A-(K-A-B);

    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
int main(){
  int A,B,C,D;
  str N;
  cin>>A>>B>>C>>D;
  if(A+B==C+D)cout<<"Balanced"<<endl;
  else if(A+B<C+D)cout<<"Right"<<endl;
  else cout<<"Left"<<endl;
}


Measured memory_bytes: 256
n = int(input())
d = [int(i) for i in input().split()]
a = 0
b = 0
d.sort()
for x in range(n):
    if(x%2==0):
        a+=d[n-1-x]
    else:
        b+=d[n-1-x]
print(str(a-b))

Measured memory_bytes: 3060
n = int(input())
a = list(map(int,input().split()))
c = sorted(a)
mid1 = c[n//2-1]
mid2 = c[n//2]
if mid1 == mid2:
  for i in range(n):
    print(mid1)
  exit()
for i in range(n):
  if a[i] <= mid1:
    print(mid2)
  else:
    print(mid1)



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

typedef long long ll;

const ll N = 1e5 + 10, inf = 1e18;
ll h[N], dp[N];

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> h[i];
    for (int i = n - 2; i >= 0; i--) {
        dp[i] = inf;
        for (int j = 1; j <= k && i + j < n; j++)
            dp[i] = min(dp[i], dp[i + j] + abs(h[i] - h[i + j]));
    }
    cout << dp[0] << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

ll n, a[110], dp[110][21];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    rep(i, 0, n) cin >> a[i];
    dp[0][a[0]] = 1;
    rep(i, 0, n-2) {
        erep(j, 0, 20) {
            if (0 <= j + a[i+1] && j + a[i+1] <= 20) 
                dp[i+1][j+a[i+1]] += dp[i][j];
            if (0 <= j - a[i+1] && j - a[i+1] <= 20) 
                dp[i+1][j-a[i+1]] += dp[i][j];
        }
    }
    cout << dp[n-2][a[n-1]] << endl;
    return 0;
}


Measured memory_bytes: 3188
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

a,b,c=get_i
if a==b and b==c
  puts "No"
elsif a==b or b==c or c==a
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
#include <iostream>
// #include <algorithm>
#include <queue>

using namespace std;

const int INF = 99999999;
typedef pair<int, int> Pair;

char cheese[1000][1000];
int d[1000][1000], count = 0, N;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

void bfs(int row, int col, int sx, int sy, int cur){
    for(int i = 0; i < row; i++) {
        for(int j = 0; j < col; j++) 
            d[i][j] = INF;
    }
    d[sx][sy] = 0; //been visited

    queue<Pair> que;
    que.push(Pair(sx, sy));
    Pair p = que.front();

    while((cheese[p.first][p.second]-'0') != cur) {
        que.pop();
        for(int i = 0; i < 4; i++) {
            int x = p.first + dx[i], y = p.second + dy[i];
            if(x >= 0 && x < row && y >= 0 && y < col && cheese[x][y] != 'X' && d[x][y] == INF) {// can move this way
                d[x][y] = d[p.first][p.second]+1;
                que.push(Pair(x, y));
            }
        }
        p = que.front();
    }

    //cheese[p.first][p.second] != cur
    count += d[p.first][p.second];
    if(cur == N)
        return;
    bfs(row, col, p.first, p.second, cur+1);
}

int main() {
    int row, col, sx, sy;
    cin >> row >> col >> N;
    for(int i = 0; i < row; i++) {
        for(int j = 0; j < col; j++) {
            cin >> cheese[i][j];
            if(cheese[i][j] == 'S') {
                sx = i;
                sy = j;
            }
        }
    }
    bfs(row, col, sx, sy, 1);
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 7960
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 1e5+10;
int n,m,x[N],y[N],z[N],a[N],b[N],c[N],d[N],cnt,cnt1,cnt2;

int fa[N],s1[N],s2[N],deg[N];
vector<int>v[N];
vector<pa>v2[N];
inline int Find(int x){
	return fa[x]==x?fa[x]:fa[x]=Find(fa[x]);
}

inline void GG(){
	puts("-1");exit(0);
}

int main(){
	n=read(),m=read();
	For(i,1,n) fa[i]=i;
	For(i,1,m){
		x[i]=read(),y[i]=read(),z[i]=read();
		deg[x[i]]++,deg[y[i]]++;
		int rtx=Find(x[i]),rty=Find(y[i]);
		cnt+=x[i]!=y[i];
		if (rtx!=rty) fa[rtx]=rty;
	}
	For(i,1,n) s1[Find(i)]++,v[Find(i)].pb(i);
	For(i,1,m) s2[Find(x[i])]++,v2[Find(x[i])].ep(x[i]==y[i],z[i]);
	For(i,1,n) if (Find(i)==i){
		bool flag=1;
		for (auto i:v[i]) flag&=deg[i]==2;
		if (s1[i]==1&&s2[i]==1){
			++cnt1;
			if (v2[i][0].se>2) a[++*a]=v2[i][0].se-2;
		} else if (s1[i]==s2[i]&&flag){
			++cnt2;
			for (auto j:v2[i]) if (j.se>1) b[++*b]=j.se-1;
		} else {
			for (auto j:v2[i]) if (j.se>1)
				if (j.fi==0) c[++*c]=j.se-1;
					else d[++*d]=j.se-1;
		}
	}
	if (!(*c)&&!(*d)){
		if (cnt2) GG();
			else return printf("%d\n",cnt),0;
	}
	int ans=1e9;
	sort(a+1,a+1+*a),reverse(a+1,a+1+*a);
	sort(b+1,b+1+*b),reverse(b+1,b+1+*b);
	sort(c+1,c+1+*c),reverse(c+1,c+1+*c);
	sort(d+1,d+1+*d),reverse(d+1,d+1+*d);
	ll s=0;
	For(i,1,*c) s+=c[i];
	if (s>=cnt2) return printf("%d\n",cnt+cnt2),0;
	int ret=0,r=0;
	if (*c){
		For(i,1,*b) s+=b[i];
		if (s>=cnt2) return printf("%d\n",cnt+cnt2),0;
		while (r<*a&&s<cnt2) ret+=2,s+=a[++r];
		if (s>=cnt2) ans=min(ans,cnt+cnt2+ret);
	} else {
		while (r<*a&&s<cnt2) ret+=2,s+=a[++r];
		if (s>=cnt2) ans=min(ans,cnt+cnt2+ret);
		For(i,1,*b) s+=b[i];
	}
	For(i,1,*d){
		s+=d[i];
		while (s-a[r]>=cnt2&&r) s-=a[r],--r,ret-=2;
		if (s>=cnt2) ans=min(ans,cnt+cnt2+ret+i);
	}
	printf("%d\n",ans==1e9?-1:ans);
}

Measured memory_bytes: 15432
import bisect
from itertools import accumulate

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

C = list(accumulate(A))
D = list(accumulate(B))

x = bisect.bisect_right(C, K)
cnt = K - C[x -1]
y = bisect.bisect_right(D, cnt)
ans = x + y

for i in range(x)[::-1]:
    cnt += A[i]
    y = bisect.bisect_right(D,cnt)
    ans = max(ans, i + y)

print(ans)

Measured memory_bytes: 126488
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int r; cin >> r;
    double a = 3.0*r*r;
    ct(a);
}



Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 10000000;

int main()
{
    int R[MAX], n;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> R[i];
    }

    int maxv = -2147483648;
    int minv = R[0];


    for (int i = 1; i < n; i++)
    {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }

        // for (int i = 1; i < n; i++)
        // {
        //     maxv = max(maxv, R[i] - minv);
        //     minv = min(minv, R[i]);
        // }

        cout << maxv << endl;

    return 0;
}


Measured memory_bytes: 3880
N = int(input())
A = list(map(int, input().split()))
ans = 0

d = {}

for i, a in enumerate(A):
    tmp = i + 1 - a
    if tmp in d.keys():
        d[tmp] += 1
    else:
        d[tmp] = 1

# print(d)

for i, a in enumerate(A):
    tmp = a + i + 1
    tmptmp = i + 1 - a
    if tmp in d.keys():
        ans += d[tmp]
    if tmptmp in d.keys():
        d[tmptmp] = max(0, d[tmptmp] - 1)

print(ans)


Measured memory_bytes: 111112
#include <iostream>
#include <vector>
#include <algorithm>


int main(void){

	int n;
	std::cin >> n;

	std::vector<int> a(n);
	for(int i = 0; i < n; i++){
		std::cin >> a[i];
	}

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

	
	int cnt = 0;
	int preNum = a[0];
	int numCnt = 1;
	for(int i = 1; i < n; i++){
		if(preNum == a[i]){
			numCnt++;
		}
		else{

			if(numCnt < preNum){
				cnt += numCnt;
			}
			else if(numCnt > preNum){
				cnt += (numCnt - preNum);
			}

			preNum = a[i];
			numCnt = 1;
		}
	}

	if(numCnt < preNum){
		cnt += numCnt;
	}
	else if(numCnt > preNum){
		cnt += (numCnt - preNum);
	}

	std::cout << cnt << std::endl;

	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main() {
  int x;
  int kyu;

  scanf("%d", &x);

  if (x<600) kyu=8;
  else if (x<800) kyu=7;
  else if (x<1000) kyu=6;
  else if (x<1200) kyu=5;
  else if (x<1400) kyu=4;
  else if (x<1600) kyu=3;
  else if (x<1800) kyu=2;
  else kyu=1;

  printf("%d", kyu);
  return 0;
}

Measured memory_bytes: 2156
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b, q = list(map(int, readline().split()))
    s = [0] * (a + 2)
    t = [0] * (b + 2)
    d = [0] * (a + b + 2)

    for i in range(1, a + 1):
        dist = int(input())
        s[i] = dist
        d[i] = (dist, 0)

    s[0] = -INF
    s[a + 1] = INF

    for i in range(1, b + 1):
        dist = int(input())
        t[i] = dist
        d[a + i] = (dist, 1)

    t[0] = -INF
    t[b + 1] = INF

    d[0] = (-INF, 0)
    d[-1] = (INF, 0)

    d.sort()
    d2 = [k[0] for k in d]
    import bisect

    for _ in range(q):
        x = int(input())
        d_idx = bisect.bisect_left(d2, x)
        left = d[d_idx - 1]
        right = d[d_idx]
        res_left = x - left[0]
        res_right = right[0] - x

        if left[1] == 0:
            t_idx = bisect.bisect_left(t, left[0])
            tl = t[t_idx - 1]
            tr = t[t_idx]
            res_left += min(abs(left[0] - tl), abs(tr - left[0]))
        else:
            s_idx = bisect.bisect_left(s, left[0])
            sl = s[s_idx - 1]
            sr = s[s_idx]
            res_left += min(abs(left[0] - sl), abs(sr - left[0]))

        if right[1] == 0:
            t_idx = bisect.bisect_left(t, right[0])
            tl = t[t_idx - 1]
            tr = t[t_idx]
            res_right += min(abs(right[0] - tl), abs(tr - right[0]))
        else:
            s_idx = bisect.bisect_left(s, right[0])
            sl = s[s_idx - 1]
            sr = s[s_idx]
            res_right += min(abs(right[0] - sl), abs(sr - right[0]))
        print(min(res_left, res_right))


if __name__ == '__main__':
    main()


Measured memory_bytes: 115860
use std::io;

fn main() {
    const NMAX: usize = 100usize;
    let mut N = String::new();
    io::stdin().read_line(&mut N);
    let N = N.trim().parse::<u64>().unwrap();
    let mut s = [0; NMAX];

    for i in 0..N {
        let mut input = String::new();
        io::stdin().read_line(&mut input);
        s[i as usize] = input.trim().parse::<i64>().unwrap();
    }

    let mut minsub = 101i64;
    let mut sum = 0i64;

    for i in 0..N {
        let a = s[i as usize];
        sum += a;
        if a % 10 != 0 && a < minsub {
            minsub = a;
        }
    }

    let mut max: i64;
    if sum % 10 != 0 {
        max = sum;
    }
    else {
        if minsub != 101i64 {
            max = sum - minsub;
        }
        else {
            max = 0i64;
        }
    }

    println!("{}", max);
}

Measured memory_bytes: 4352
/*
* @Author: Kabid
* @Date:   2020-04-26 18:01:07
* @Last Modified by:   Kabid
* @Last Modified time: 2020-05-10 18:25:37
*/
#include<bits/stdc++.h>

#define ll long long
#define  in(x) scanf("%d",&x);
#define out(x) printf("%d",x);
#define  ins(x)  scanf("%s",x);
#define outs(x) printf("%s",x);
#define lin puts("");
#define _ putchar(' ');
using namespace std;

int t;       //test cases
ll  n=0, m; //variables
ll a,b,c,k;
int main() {
	cin>>a>>b>>c>>k;
	if(k<=a){
		cout<<k*1<<endl;
	}
	else if(k<=a+b){
		cout<<a*1<<endl;
	}
	else{
		cout<<a-(k-a-b)<<endl;
	}
	
	

	return 0;
	}
	



Measured memory_bytes: 3636
from collections import Counter


N = int(input())
A = list(map(int, input().split()))
c = sorted(Counter(A).items())

MOD = 10**9 + 7

if N%2 == 0:
    for i in range(len(c)):
        if c[i][0] != 2*i+1 or c[i][1] != 2:
            print(0)
            exit()
    print(pow(2, len(c), MOD))
else:
    if c[0][0] != 0 or c[0][1] != 1:
        print(0)
        exit()
    for i in range(1, len(c)):
        if c[i][0] != 2*i or c[i][1] != 2:
            print(0)
            exit()
    print(pow(2, len(c)-1, MOD))


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

using namespace std;

#define MODULE 1000000007
#define MP make_pair

template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

typedef pair<int, int> P;
typedef long long LL;
const int INF = INT_MAX / 2;    //int_max->2*e+9
const int MAXN = 100001;

/*struct edge {
    edge(int to, int cost) : to(to), cost(cost) {}
    int to, cost;
};
vector<edge> graph[MAXN];*/


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

//-----Template---------
int n,a,b;
string s;
int kokunaiT=0;
int kaigaiT=0;
bool hoge[100001];
int main(){
    ios::sync_with_stdio(false); //cout<< fixed << setprecision(10);

    cin>>n>>a>>b;
    cin>>s;
    for (int i = 0; i < s.length(); ++i) {
        if(s[i]=='a'){
            if((kokunaiT+kaigaiT)<(a+b)) {
                kokunaiT++;
                hoge[i]=true;
            }
        }else if(s[i]=='b'){
            if((kokunaiT+kaigaiT)<(a+b) &&(kaigaiT<b)){
                kaigaiT++;
                hoge[i]= true;
            }
        }
    }
    for (int i = 0; i < s.length(); ++i) {
        cout<<(hoge[i]?"Yes":"No")<<endl;
    }
}

Measured memory_bytes: 976
import java.util.*;
 
class Main{
	public static void main(String args[]) throws Exception{
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a > b){
			System.out.println(a - 1);
		}else{
			System.out.println(a);
		}
	}
}

Measured memory_bytes: 20820
#include <iostream>
#include <bitset>
#include <cmath>

using namespace std;

int N;
int ans = 0;

void check(int num) {
		bitset<3> used;
		int l = log(num) + 1;

		int rest;
		int t = num;
		for (int i = 0; i < l; i++) {
				rest = t % 10;
				if (rest == 3) used[0] = true;
				if (rest == 5) used[1] = true;
				if (rest == 7) used[2] = true;
				t /= 10;
		}

		if (used.all() && num<=N) ans++;
}

void dfs(int num) {
		check(num);
		if (num <= 100000000) {
				dfs(10*num+3);
				dfs(10*num+5);
				dfs(10*num+7);
		}
}

int main() {
		cin >> N;
		dfs(0);
		cout << ans << endl;
		return 0;
}


Measured memory_bytes: 384
N, M, P = map(int, input().split())
ABC = []
for _ in range(M):
    a, b, c = map(int, input().split())
    ABC.append((a, b, c))
import sys
INT_MAX = sys.maxsize # 9223372036854775807        
    
def bellman_ford(edges,num_v,source):

    dist=[INT_MAX] * num_v
    dist[source]=0

    #辺の緩和
    has_negative = False
    for i in range(num_v):
        for edge in edges:
            if edge[0] != INT_MAX and dist[edge[1]] > dist[edge[0]] + edge[2]:
                if dist[edge[0]] != INT_MAX:
                    dist[edge[1]] = dist[edge[0]] + edge[2]
                if i==num_v-1:
                    has_negative = True
    
    if has_negative == False:
        return dist
    
    negative = [False] * num_v
    for _ in range(N):
        for edge in edges:
            if dist[edge[0]] == INT_MAX:
                continue
            if dist[edge[1]] > dist[edge[0]] + edge[2]:
                dist[edge[1]] = dist[edge[0]] + edge[2]
                negative[edge[1]] = True
            # ある頂点が負閉路の一部なら、それに隣接する頂点も負閉路の一部
            if negative[edge[0]]:
                negative[edge[1]] = True
    for i, is_negative in enumerate(negative):
        if is_negative:
            dist[i] = -1 * INT_MAX
    return dist

edges = ABC[:]
edges = [(a, b, -c+P) for a, b, c in edges]

shortest_path = bellman_ford(edges, N+1, 1)
ans = -1 * shortest_path[N]
#print(shortest_path)
if ans == -INT_MAX or ans == INT_MAX:
    print(-1)
elif ans < 0:
    print(0)
else:
    print(ans)


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

using namespace std;
typedef long long ll;
typedef double dd;
#define all(v) v.begin(),v.end()
#define endl "\n"
#define clr(n, r) memset(n,r,sizeof(n));

void fast() {

    cin.tie(0);
    cin.sync_with_stdio(0);
}


int main() {
    fast();
    int a,b,c;
    cin>>a>>b>>c;
    int fi=(a==5)+(b==5)+(c==5);


    int si=(a==7)+(b==7)+(c==7);
    if(fi==2&&si==1)cout<<"YES";
    else cout<<"NO";

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    
    while(true){
    int n,m;
    cin >> n ;
    if(cin.eof()) break;
    cin >> m;

    vector<int> a(1000);
    vector<int> b(1000);
    vector<int> c(1000);
    vector<bool> u(1000);
    vector<int> ans(1000);
    fill(u.begin(),u.end(),true);
    for(int i=0;i<n;i++){
	cin >> a[i];
    };
    for(int i=0;i<m;i++){
	cin >> b[i];
    }
    for(int i=0;i<n;i++){
	for(int j=0;j<m;j++){
	    if(u[j] && a[i] <= b[j]){
		u[j] = false;
		ans[i]++;
	    }
	}
    }
    int res = -1,ansnum = 0;;
    for(int i=0;i<n;i++){
	if(res < ans[i]){
	    res = ans[i];
	    ansnum = i + 1;
	}
    }

    cout << ansnum << endl;
    }

    return 0;
}

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

using namespace std;
 
int main()
{
    int N;
    long long K;
    cin >> N >> K;
    vector<int> A(N);
    vector<int> A_was(N,-1);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    int At = 1;
    for (long long i = 0; i < K; i++)
    {
        if (A_was.at(At-1) != -1)
        {
            long long po = i - A_was.at(At-1);
            long long new_i = i+((K-i)/po)*po;
            if (new_i < K-1)
            {
                i = new_i; 
            }else{
                new_i = i+((K-i)/po-1)*po;
                if (new_i > i)
                {
                    i = new_i;
                }
            }
        }else
        {
            A_was.at(At-1) = i;
        }
        At = A.at(At-1);
    }
    cout << At;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  long long c;
  cin >> n >> c;
  vector<long long> pos(n);
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> pos[i] >> v[i];
  }

  vector<long long> sum(n + 1), revsum(n + 1);
  for (int i = 0; i < n; i++) {
    sum[i + 1] = sum[i] + v[i];
    revsum[i + 1] = revsum[i] + v[n - 1 - i];
  }

  vector<long long> a1(n + 1), a2(n + 1), b1(n + 1), b2(n + 1);
  for (int i = 0; i < n; i++) {
    a1[i + 1] = max(a1[i], sum[i + 1] - pos[i]);
    a2[i + 1] = max(a2[i], sum[i + 1] - 2 * pos[i]);
    b1[i + 1] = max(b1[i], revsum[i + 1] - (c - pos[n - 1 - i]));
    b2[i + 1] = max(b2[i], revsum[i + 1] - 2 * (c - pos[n - 1 - i]));
  }

  long long ans = max(a1[n], b1[n]);
  for (int i = 0; i <= n; i++) {
    ans = max(ans, a1[i] + b2[n - i]);
    ans = max(ans, a2[i] + b1[n - i]);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 9068
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    vector<vector<int>> c(3, vector<int>(3));
    for(int i = 0; i < 3; ++i){
        for(int j = 0; j < 3; ++j){
            cin >> c[i][j];
        }
    }
    
    for(int x = -100; x <= 200; ++x){
        vector<int> a(3), b(3);
        a[0] = x;
        for(int i = 0; i < 3; ++i){
            b[i] = c[0][i] - a[0];
        }
        for(int i = 1; i < 3; ++i){
            a[i] = c[i][0] - b[0];
        }
        bool ok = true;
        for(int i = 0; i < 3; ++i){
            for(int j = 0; j < 3; ++j){
                if(a[i] + b[j] != c[i][j]){
                    ok = false;
                    break;
                }
            }
            if(!ok) break;
        }
        if(ok){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}

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

using namespace std;

int main(){
	while(true){
		int d, n, m;
		scanf("%d", &d);
		if(d == 0){ break; }
		scanf("%d%d", &n, &m);
		vector<int> shops;
		shops.push_back(0);
		while(--n){
			int tmp;
			scanf("%d", &tmp);
			shops.push_back(tmp);
		}
		sort(shops.begin(), shops.end());
		int answer = 0;
		while(m--){
			int tmp, dist = 0;
			scanf("%d", &tmp);
			vector<int>::iterator bound = lower_bound(shops.begin(), shops.end(), tmp);
			if(bound == shops.begin()){
				vector<int>::iterator last = shops.end(); --last;
				dist = min(tmp - (*bound), d - (*last) + tmp);
			}else if(bound == shops.end()){
				vector<int>::iterator last = shops.end(); --last;
				dist = min(tmp - (*last), (*(shops.begin())) + d - tmp);
			}else{
				vector<int>::iterator prev = bound; --bound;
				dist = min(tmp - (*bound), (*prev) - tmp);
			}
			answer += dist;
		}
		printf("%d\n", answer);
	}
	return 0;
}

Measured memory_bytes: 1336
n = int(input())

ans = float('inf')
for a in range(1, n):
    b = n - a
    dsum = 0
    for i in range(len(str(a))):
        x = int(str(a)[i])
        dsum += x
    for i in range(len(str(b))):
        x = int(str(b)[i])
        dsum += x
    ans = min(ans, dsum)

print(ans)

Measured memory_bytes: 41708
// AOJ 2261: [[iwi]]
// 2017.10.11 bal4u@uu

#include <stdio.h>
#include <string.h>

char s[17], *p, *q;
int c[17][17];

int check(int i, int j)
{
	int k;
	char a[2][6] = {{ '(', ')', '{', '}', '[', ']' },
					{ ')', '(', '}', '{', ']', '[' }};
	for (k = 0; k < 6; k++)
		if (*(p-i) == a[0][k] && *(q+j) == a[1][k]) return 1;
	return 0;
}

int LCS(int m, int n)
{
	int i, j;

	for (i = 1; i <= m; i++) for (j = 1; j <= n; j++) {
	    if (check(i-1, j-1)) c[i][j] = c[i-1][j-1] + 1;
		else {
			if (c[i-1][j] >= c[i][j-1]) c[i][j] = c[i-1][j];
			else c[i][j] = c[i][j-1];
		}
	}
	return c[m][n];
}

int main()
{
	int n, ans;

	scanf("%s", s); n = strlen(s);
	p = s; while (*p != 'w') p++;
	q = p; q+=2, p-=2;
	ans = LCS(p-s+1, n-(p-s)-4);
	printf("%d\n", 2*ans+3);
	return 0;
}

Measured memory_bytes: 1828
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define maxin(v) *max_element(v.begin(), v.end())
#define minin(v) *min_element(v.begin(), v.end())
#define sumall(vect) accumulate(vect.begin(), vect.end(), 0)
#define count(x, vect) count(vect.begin(), vect.end(), x)
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 100000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "------------------------------------\n"
//#define min(a, b, c) min(a, min(b, c))
//#define max(a, b, c) max(a, max(b, c))
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp;
string str;
set<ll> s;
vll v;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	string s,t;
	cin>>s>>t;
	string ans;
	for(int i=0;i<2*s.length();i++)
	{
	    if(i%2==0)
	    ans.pb(s[i/2]);
	    else
	    ans.pb((t[i/2]));
	}
	cout<<ans;
	
	
} 

Measured memory_bytes: 256
N,M = map(int,input().split())
P = [list(map(int,input().split())) for i in range(M)]
for i in range(M):
    P[i].append(i)
P.sort(key=lambda x: x[1])
B = [1]*N

for i in range(M):
    P[i] += "0"*(6 - len(str(P[i][0]))) + str(P[i][0]) + "0"*(6 - len(str(B[P[i][0]-1]))) + str(B[P[i][0]-1]),
    B[P[i][0]-1] += 1
    
P.sort(key=lambda x: x[2])
for i in range(M):
    print(P[i][3])

Measured memory_bytes: 38836