akhauriyash/Code-Regression huggingface dataset:
while true
    a,op,b = gets.split.map(&:to_s)
 
    case op
    when "?" then
        break
    when "+" then
        puts a.to_i + b.to_i
    when "-" then
        puts a.to_i - b.to_i
    when "*" then
        puts a.to_i * b.to_i
    when "/" then
        puts a.to_i / b.to_i
    else
        break
    end
end

Measured memory_bytes: 8584
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
     
#define pb emplace_back
#define fi first
#define se second
     
using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ ll x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

int n, k;

bool used[2010];

vi G[2010];
pi edge[2010];

void dfs( int x , int p , int d ){
  used[x] = true;
  if( d == k / 2 ){
    return;
  }
  YYS( w , G[x] ){
    if( w != p ){
      dfs( w , x , d+1 );
    }
  }
}

int main(){

  n = in();
  k = in();
  REP( i , n-1 ){
    int a = in() - 1;
    int b = in() - 1;
    G[a].pb( b );
    G[b].pb( a );
    edge[i] = pi( a , b );
  }

  int ans = 0;

  if( k % 2 == 0 ){
    REP( i , n ){
      REP( j , n ){
	used[j] = false;
      }
      dfs( i , -1 , 0 );
      int cnt = 0;
      REP( j , n ){
	if( used[j] ){
	  cnt++;
	}
      }
      chmax( ans , cnt );
    }
  } else {
    REP( i , n-1 ){
      REP( j , n ){
	used[j] = false;
      }
      dfs( edge[i].fi , edge[i].se , 0 );
      dfs( edge[i].se , edge[i].fi , 0 );
      int cnt = 0;
      REP( j , n ){
	if( used[j] ){
	  cnt++;
	}
      }
      chmax( ans , cnt );
    }
  }

  printf( "%d\n" , n - ans );
  
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

const long long mod = 1000000007;

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

  vector<int> h(N);
  int count = 0;
  int maxH = 0;
  for (int i = 0; i < N; i++) {
    cin >> h[i];
    if (h[i] >= maxH) {
      count++;
      maxH = h[i];
    }
  }

  cout << count << endl;

  return 0;
}


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

using namespace std;
using ll = long long;
using pint = pair<int, int>;

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

	string ans = "";
	for (int i = 0; i < K; ++i) {
		ans += "ACL";
	}

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


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
ll negasi=0, a, b, c, d, ans=0;
	
int main(){
	IOS
	cin >> a >> b >> c >> d;
	ll kpk=(c*d)/__gcd(c, d);
	ans=abs(a-b)+1;
	negasi=(b/c-(a-1)/c)+(b/d-(a-1)/d)-(b/kpk-(a-1)/kpk);
	cout << ans-negasi << '\n';
}


Measured memory_bytes: 3632
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define vint vector<int>


int main(){
	string s;
	cin >> s;
	if(s[0]=='9' || s[1]=='9') cout << "Yes\n";
	else cout << "No\n";
	
	
	return 0;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <cstring>

/*
sum[r] - sum[l] >= r - l + 1
sum[r] - r - 1 >= sum[l] - l

sum[r][0] - sum[l][0] >= r - l + 1
sum[r][1] - sum[l][0] >= r - l + 1
sum[r][0] - sum[l][1] >= r - l
*/

typedef long long int64;

#ifdef LOCAL
const int MAXN = 100;
#else 
const int MAXN = 100000 + 10;
#endif

int n, m;
int a[MAXN];
int sum[2][MAXN >> 1];
int c[2][MAXN << 1];

inline int lowbit(int x) { return x & -x; } 
inline void add(int c[], int p) {
	for(; p<=m; p+=lowbit(p))
		c[p]++;
}
inline int query(int c[], int p) {
	int res = 0;
	for(; p; p^=lowbit(p))
		res += c[p];
	return res;
}

bool judge(int mid) { // judge if ans >= mid
	int i, j, k;
	int64 ans = 0;
	
	memset(c, 0, sizeof(c));
	
	sum[0][0] = n + 2;
	for(i=1; i<=n; i++) {
		j = i >> 1;
		k = i & 1;
		sum[k][j] = sum[!k][j - !k] + (a[i] < mid);
	}
	
	for(i=0; sum[0][i]; i++) {
		for(j=0; j<=1 and sum[j][i]; j++) {
			ans += query(c[j], sum[j][i] - i - 1);
			ans += query(c[!j], sum[j][i] - i - j);
			if(j == 1)
				ans += sum[1][i] - sum[0][i];
		}
		for(j=0; j<=1 and sum[j][i]; j++)
			add(c[j], sum[j][i] - i);
	}
	
	return ans < (n + 1ll) * n / 4 + 1;
}

int main() {
	int i, l, r, mid;
	
	scanf("%d", &n);
	m = 2 * n + 2;
	for(i=1; i<=n; i++) 
		scanf("%d", &a[i]);
		
	l = 1;
	r = 1000000000;
	while(l ^ r) {
		mid = (l + r + 1) >> 1;
		if(judge(mid))
			l = mid;
		else
			r = mid - 1;
	}
	printf("%d\n", l);
	return 0;
} 


Measured memory_bytes: 2560
N=int(input())
S=input()
R,G,B=0,0,0
ans=0
for i in range(N):
    if S[i]=='R':
        R+=1
    elif S[i]=='G':
        G+=1
    else:
        B+=1
ans+=R*G*B
f,s,t=0,1,2
while t<=N-1:
    i=0
    while i+t<=N-1:
        if S[f+i]!=S[s+i] and S[f+i]!=S[t+i] and S[s+i]!=S[t+i]:
            ans-=1
        i+=1
    s+=1
    t+=2
print(ans)

Measured memory_bytes: 67884
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
int main()
{
	string s;
	cin >> s;
  if(s.size() % 2 == 1)
  {
    cout << "No\n";
    return 0;
  }
	for(int i = 0; i < s.size() - 1; ++i)
	{
		if(s[i] == 'h' && s[i + 1] == 'i')
		{
			++i;
		}
      	else
        {
        	cout << "No\n";
            return 0;
        }
	}
	cout << "Yes\n";
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, b := intScanner(), intScanner()
	if a%3 == 0 || b%3 == 0 || (a+b)%3 == 0 {
		fmt.Println("Possible")
	} else {
		fmt.Println("Impossible")
	}
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const int mod=1e9+7;
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
//LL powmod(LL a,LL b) {LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int R,C,n;
int getPos(int x,int y){
    if(x==0) return y;
    else if (y == C) return C + x;
    else if (x == R) return C + R + (C - y);
    else if (y == 0) return C + R + C + (R - x);
    else return -1;
}
vector<PII>g;
int main(){
//    freopen("B-small-attempt1.in","r",stdin);
//    freopen("output.txt","w",stdout);
    int x,y;
    cin>>R>>C>>n;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        int a=getPos(x,y);
        cin>>x>>y;
        int b=getPos(x,y);
        if(a!=-1&&b!=-1){
            g.pb({a,i});
            g.pb({b,i});
        }
    }
    sort(all(g));
    stack<int>s;
    for(auto i:g){
        if(s.empty() || s.top()!=i.se) s.push(i.se);
        else s.pop();
    }
    puts(s.empty()?"YES":"NO");
	return 0;
}
/*
*/


Measured memory_bytes: 2420
#include <iostream>
using namespace std;
int main(){

	int n,x[1000000];
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> x[i];
	}
	int max = x[1]-x[0];
	int min = x[0];
	for(int k=1;k<n;k++){
		if(max < (x[k] - min))
			max = (x[k] - min);
		if(min > x[k])
			min = x[k];
	}
	cout << max << endl;
}

Measured memory_bytes: 3964
import sys
input = sys.stdin.buffer.readline

class UnionFind:
    __slots__ = ["data"]
    
    def __init__(self, n=0):
        self.data = [-1]*(n+1)
    
    def root(self, x):
        if self.data[x] < 0:
            return x
        self.data[x] = self.root(self.data[x])
        return self.data[x]
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.data[x] < self.data[y]:
                self.data[x] += self.data[y]
                self.data[y] = x
            else:
                self.data[y] += self.data[x]
                self.data[x] = y
    
    def same(self, x, y):
        return self.root(x) == self.root(y)
    
    def size(self, x):
        return -self.data[self.root(x)]
                


def main():
    n, m, k = map(int, input().split())
    friends = [0]*(n+1)
    blocks = [[] for _ in range(n+1)]
    uf = UnionFind(n)
    for _ in range(m):
        a, b = map(int, input().split())
        friends[a] += 1
        friends[b] += 1
        uf.unite(a, b)
    for _ in range(k):
        c, d = map(int, input().split())
        blocks[c].append(d)
        blocks[d].append(c)
    for i in range(1, n+1):
        nf = friends[i]
        nb = sum([uf.same(i, b) for b in blocks[i]])
        ans = uf.size(i) - 1 - nf - nb
        print(ans)


if __name__ == "__main__":
    main()

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

using namespace std;

typedef long long ll;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<ll> a(n+1);
    for(int i = 0; i < n; i++) {
        if (s[i]=='<'){
            a[i+1] = max(a[i+1], a[i]+1);
        }
    }

    for(int i = n-1; i >=0; i--) {
        if (s[i]=='>'){
            a[i] = max(a[i], a[i+1]+1);
        }
    }
    ll sum=0;
    for(int i = 0; i < n+1; i++) {
        sum += a[i];
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 7628
package main

import (
	"fmt"
)

func main() {

	var c string
	fmt.Scan(&c)

	if c == "a" || c == "e" || c == "i" || c == "o" || c == "u" {
		fmt.Println("vowel")
	} else {
		fmt.Println("consonant")
	}
}


Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        int j=0;
        int[] ave=new int[20];
        Scanner sc = new Scanner(System.in);
        while(true){
            int sum=0;
            int max=0; int min=5000;
            int n=sc.nextInt();
            if(n==0) break;
            int[] count = new int[n];
            for(int i=0;i<count.length;i++){
                count[i]=sc.nextInt();
                if(count[i]>max) max=count[i];
                if(count[i]<min) min=count[i];
                sum+=count[i];
            }
            sum-=max; sum-=min;
            ave[j]=sum/(n-2);
            j++;
        }
        for(int i=0;i<j;i++){
            System.out.println(ave[i]);
        }

    }
}


Measured memory_bytes: 28956
#include <iostream>
#include <algorithm>
#include <cmath>

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

int main() {
    int s, w;
    cin >> s >> w;
  
    if(s <= w) {
      cout << "unsafe" << endl;
    } else {
      cout << "safe" << endl;
    }
}


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

using namespace std;

const int N = 1e5+10;

int dp[N];

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

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

	dp[0] = 0, dp[1] = abs(v[1]-v[0]);
	for(int i = 2; i < n; i++) {
		dp[i] = min(dp[i-1]+abs(v[i]-v[i-1]), dp[i-2]+abs(v[i]-v[i-2]));
	}

	cout << dp[n-1];
}

Measured memory_bytes: 4052
### constants

MAX_INT = 1 << 30

### subroutines

def connected?(n, nbrs, edges)
  used = n.times.map{false}
  used[0] = true
  q = [0]

  while ! q.empty?
    u = q.shift

    for v in nbrs[u]
      if ! edges[u][v].nil? && ! used[v]
        used[v] = true
        q << v
      end
    end
  end

  for usd in used
    return false if ! usd
  end
  true
end

### main

loop do
  n, m = gets.split.map(&:to_i)
  break if n == 0 && m == 0

  min_cost = 0
  nlinks = 0
  links = []
  edges = n.times.map{[]}
  nbrs = n.times.map{[]}

  m.times do
    i, j, w = gets.split.map(&:to_i)
    if w <= 0
      min_cost += w
    else
      nlinks += 1
      links << [w, i, j]
      edges[i][j] = edges[j][i] = w
      nbrs[i] << j
      nbrs[j] << i
    end
  end
  links.sort!

  #p links
  #p edges
  #p nbrs

  if nlinks < n - 1 || ! connected?(n, nbrs, edges)
    puts min_cost
    next
  end

  min_del = MAX_INT

  for k in (0...nlinks)
    w, i, j = links[k]
    edges[i][j] = edges[j][i] = nil
    ctd = connected?(n, nbrs, edges)
    edges[i][j] = edges[j][i] = w

    if ! ctd
      min_del = w if min_del > w
      break
    end
  end

  links2 = []

  for i in (0...nlinks)
    li = links[i]
    wi = li[0]
    for j in ((i + 1)...nlinks)
      lj = links[j]
      wj = lj[0]
      links2 << [wi + wj, li, lj]
    end
  end

  nlinks2 = links2.length
  links2.sort!
  #p links2

  for k in (0...nlinks2)
    ww, l1, l2 = links2[k]
    w1, i1, j1 = l1
    w2, i2, j2 = l2

    edges[i1][j1] = edges[j1][i1] = nil
    edges[i2][j2] = edges[j2][i2] = nil

    ctd = connected?(n, nbrs, edges)

    edges[i1][j1] = edges[j1][i1] = w1
    edges[i2][j2] = edges[j2][i2] = w2

    if ! ctd
      min_del = ww if min_del > ww
      break
    end
  end

  puts (min_cost + min_del)
end

Measured memory_bytes: 6400
#include <bits/stdc++.h>
#include<atcoder/all>
#define ll long long
#define s std
ll a, n, l, i;
void f(ll x, ll y) {
  if ((i = s::__gcd(x,y) > 1 ? 0 : atcoder::inv_mod(x,y)) > 0)
    a = s::min({a, i * x - 1, (y-i) * x});
}
int main() {
  s::cin >> n; a = n + (n & 1 ^ 1);
  for (ll d = 1; d * d <= n; d++)
    if (n % d == 0)
      f(2 * d, n / d), f(2 * n / d, d);
  s::cout << a << "\n";
}

Measured memory_bytes: 3664
import java.util.Scanner;
import static java.lang.Math.ceil;
class Main{
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
		int a = input.nextInt();
		int b = input.nextInt();
		System.out.println((int)ceil((1.0*a)/(1.0*b)));
	}
}

Measured memory_bytes: 21716
#include<stdio.h>

int main(void){

	long int N, M, i, SUM = 0;
	int A[10001];

	scanf("%d %d", &N, &M);
	
	for(i = 0; i < M; i++)
		scanf("%d", &A[i]);

	for(i = 0; i < M; i++)
		SUM += A[i];

	if(N - SUM >= 0)
		printf("%d", N - SUM);
	else if(N < SUM) 
		printf("%d", -1);

	return 0;
}

Measured memory_bytes: 1764
#include<bits/stdc++.h>
#define MAX 10000001
using namespace std;

int main(){
    int A=7;
    int K,ans;
    cin >> K;
    if(K%2==0 || K%5==0){
        cout << -1 << endl;
        return 0;
    }
    long long amari=0;
    for(int i=1; ;i++){
        amari+=A%K;
        if(amari%K==0){
            ans=i;
            break;
        }else{
            A*=10;
            A%=K;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	int k, h, n, a[200001], ans = 0;cin >> n >> k;
	rep(i, 200001) a[i] = 0;
	rep(i, n) {
		cin >> h;a[h]++;
	}
	vector<int> v;
	rep(i, 200001) {
		if (a[i] > 0) v.push_back(a[i]);
	}
	sort(v.begin(), v.end());
	if (v.size() <= k) {
		cout << 0 << endl;
		return 0;
	}
	rep(i, v.size() - k) ans += v[i];
	cout << ans << endl;
}

Measured memory_bytes: 2168
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

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

  vector<int> arr;

  if(a > b) swap(a, b);

  for(int i = 1; i <= a; i++){
    if(a % i == 0 && b % i == 0){
      arr.push_back(i);
    }
  }

  cout << arr[arr.size()-k] << endl;

  return 0;

}


Measured memory_bytes: 256
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // 入力
        MyScanner sc = new MyScanner(System.in);
        double N = sc.nextInt();

        // 初期化
        double ans;

        // 主処理
        // 奇数を数える
        int odd_cnt = 0;
        for (int i = 1; i <= N; i++) {
            odd_cnt = i % 2 == 1 ? odd_cnt+1 : odd_cnt;
        }
        // 奇数である確率を計算
        ans = odd_cnt / N;

        // 出力
        System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader br;
        // 標準入力から入力値を取得
        MyScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }
        // 標準入力を文字列で取得
        public String nextString() throws IOException {
            return br.readLine();
        }
        // 標準入力を文字列の配列で取得
        public String[] nextStringArray() throws IOException {
            return nextString().split(" ");
        }
        // 標準入力を数値で取得
        public int nextInt() throws IOException {
            return Integer.parseInt(nextString());
        }
        // 標準入力を数値の配列で取得
        public int[] nextIntArray() throws IOException {
            String[] strArr = nextStringArray();
            int[] intArr = new int[strArr.length];
            for(int i = 0; i < strArr.length; i++) {
                intArr[i] = Integer.parseInt(strArr[i]);
            }
            return intArr;
        }
        // 標準入力を数値で取得
        public long nextLong() throws IOException {
            return Long.parseLong(nextString());
        }
        // 標準入力を数値の配列で取得
        public long[] nextLongArray() throws IOException {
            String[] strArr = nextStringArray();
            long[] intArr = new long[strArr.length];
            for(int i = 0; i < strArr.length; i++) {
                intArr[i] = Long.parseLong(strArr[i]);
            }
            return intArr;
        }
    }

}


Measured memory_bytes: 22484
#include <iostream>

using namespace std;
long long a[1000005] = {};
long long calc(long long *, long long, long long, long long, long long);
long long get_sign(long long);

int main()
{
	long long n, ans, ans2;
	long long tmp, sign = 0, cnt;
	cin >> n;
	for (long long i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	//最初を正
	sign = 1;
	if (a[0] > 0)
	{
		tmp = a[0];
		cnt = 0;
	}
	else
	{
		tmp = 1;
		cnt = (-1 * a[0]) + 1;
	}
	ans = calc(a, n, sign, tmp, cnt);
	//最初を負
	sign = 0;
	if (a[0] < 0)
	{
		tmp = a[0];
		cnt = 0;
	}
	else
	{
		tmp = -1;
		cnt = a[0] + 1;
	}
	ans2 = calc(a, n, sign, tmp, cnt);
	if (ans2 < ans) ans = ans2;
	cout << ans << endl;
	return 0;
}

long long calc(long long *a, long long n, long long sign, long long tmp, long long cnt)
{
	for (long long i = 0; i < n - 1; i++)
	{
		tmp = tmp + a[i + 1];
		if (sign == 1)
		{
			if (tmp >= 0)
			{
				cnt += tmp + 1;
				tmp = -1;
			}
		}
		else
		{
			if (tmp <= 0)
			{
				cnt += (-1 * tmp) + 1;
				tmp = 1;
			}
		}
		sign = get_sign(tmp);
	}
	return cnt;
}

long long get_sign(long long tmp)
{
	if (tmp < 0) return 0;
	else return 1;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int flag = 0;
        for (char c = 'a'; c <= 'z'; c++) {
            for (int i = 0; i < s.length(); i++) {
                if (c == s.charAt(i)) {
                    flag = 1;
                    break;
                }
            }
            if (flag == 0) {
                System.out.println(c);
                System.exit(0);
            }
            flag = 0;
        }
        System.out.println("None");
    }
}


Measured memory_bytes: 24000
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] arr = sc.nextLine().split(" ");
		int n = Integer.parseInt(arr[0]);
		int k = Integer.parseInt(arr[1]);
		int[] seq = new int[n];
		arr = sc.nextLine().split(" ");
		for(int i=0; i<seq.length; i++)
			seq[i] = Integer.parseInt(arr[i]);
		sc.close();

		int count = 1 + (int)Math.ceil((double)(n-k)/(k-1));
		System.out.println(count);
	}
}


Measured memory_bytes: 47040
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  const std::string expected = "CODEFESTIVAL2016";
  std::string S;
  std::cin >> S;

  i64 answer = 0;
  for (i64 i = 0; i < 16; ++i) {
    if (S[i] != expected[i]) ++answer;
  }

  std::cout << answer << std::endl;
  return 0;
}

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

int main() {

	int x;
	int y;
	cin >> x >> y;
	int sum = 0;

	if (x == 1) {
		sum += 300000;
	}
	else if (x == 2) {
		sum += 200000;
	}
	else if (x == 3) {
		sum += 100000;
	}
	if (y == 1) {
		sum += 300000;
	}
	else if (y == 2) {
		sum += 200000;
	}
	else if (y == 3) {
		sum += 100000;
	}
	if (x == 1 && y == 1) {
		sum += 400000;
	}
	cout << sum;

	return 0;

}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var in string
	fmt.Scan(&in)
	fmt.Println(op(in))
}

func op(in string) string {
	nums := [4]int{int(in[0] - '0'), int(in[1] - '0'), int(in[2] - '0'), int(in[3] - '0')}
	for i := 0; i < (1 << 3); i++ {
		ans := nums[0]
		ops := []string{}
		for j := uint8(0); j < 3; j++ {
			if i&(1<<j) != 0 {
				ans += nums[j+1]
				ops = append(ops, "+")
			} else {
				ans -= nums[j+1]
				ops = append(ops, "-")
			}
		}
		if ans == 7 {
			return fmt.Sprintf("%d%s%d%s%d%s%d=7", nums[0], ops[0], nums[1], ops[1], nums[2], ops[2], nums[3])
		}
	}
	return ""
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        int ans = 1;
        a[0] = sc.nextInt();
        int min = a[0];
        for(int i=1; i<N; i++){
            a[i] = sc.nextInt();
            if(a[i]<=min){
                //System.out.println(i+":"+min+">"+a[i]);
                min = a[i];
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 60424
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 100000000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define endl "\n"
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   bool flag=false;
   int x[n],y[n];
   rep(i,0,n)
   {
       cin>>x[i]>>y[i];
   }
   for(int i=2;i<n;i++)
   {
       if(x[i]==y[i] && x[i-1]==y[i-1] && x[i-2]==y[i-2])flag=true;
   }
   if(flag)
    cout<<"Yes"<<endl;
   else
    cout<<"No"<<endl;
}


Measured memory_bytes: 3652
def main():
  import sys
  input=sys.stdin.buffer.readline
  n=int(input())
  d=[0]*n+[1<<c-97for c in input()[:n]]
  for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i]
  r=[]
  for _ in range(int(input())):
    q,a,b=input().split()
    i,s=int(a)+n-1,0
    if q<b'2':
      d[i]=1<<b[0]-97
      while i:
        i//=2
        d[i]=d[i+i]|d[i-~i]
      continue
    j=int(b)+n
    while i<j:
      if i&1:
        s|=d[i]
        i+=1
      if j&1:
        j-=1
        s|=d[j]
      i//=2
      j//=2
    r+=bin(s).count('1'),
  print(' '.join(map(str,r)))
main()

Measured memory_bytes: 43816
#!/usr/bin/env python
#pyrival orz
import os
import sys
from io import BytesIO, IOBase

"""
    for _ in range(int(input())):
    n,m=map(int,input().split())
    n=int(input())
    a = [int(x) for x in input().split()]
"""

def main():

    def gcd(x, y):
        """greatest common divisor of x and y"""
        while y:
            x, y = y, x % y
        return x

    N = 1000000+2
    cnt = [0]*N

    n = int(input())
    a = [int(x) for x in input().split()]

    for x in a:
        cnt[x]+=1

    for i in range(2,N):
        c=0
        for j in range(i,N,i):
            c+=cnt[j]
        if c>=2:
            break
    else:
        print("pairwise coprime")
        exit(0)

    g=a[0]
    for x in a:
        g=gcd(g,x)
        if g==1:
            print("setwise coprime")
            exit(0)

    print("not coprime")
# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 189976
#include<bits/stdc++.h>
using namespace std;
const int maxn=5005;
const int maxm=205;
int a[maxn],change[maxn][maxm];
int q[maxm][maxn],top[maxm];
int n,m;
long long lazy[maxn<<2];
long long _max[maxn<<2];
void init()
{
    memset(lazy,0,sizeof(lazy));
    memset(_max,0,sizeof(_max));
    memset(top,0,sizeof(top));
}
void read()
{
    scanf("%d%d",&n,&m);
    a[1]=0;
    for(int i=2;i<=n;i++)
        scanf("%d",a+i);
    for(int j=1;j<=m;j++)
        change[0][j]=1e9+7;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
            scanf("%d",&change[i][j]);
    }
}
void Push_down(int id)
{
    lazy[id<<1]+=lazy[id];
    lazy[id<<1|1]+=lazy[id];
    _max[id<<1]+=lazy[id];
    _max[id<<1|1]+=lazy[id];
    lazy[id]=0;
}
void Push_up(int id)
{
    _max[id]=max(_max[id<<1],_max[id<<1|1]);
}
void updata(int id,int l,int r,int tl,int tr,int w)
{
    if(l==tl&&r==tr){
        lazy[id]+=w;
        _max[id]+=w;
        return;
    }
    if(lazy[id]){
        Push_down(id);
    }
    int mid=(l+r)>>1;
    if(tr<=mid) updata(id<<1,l,mid,tl,tr,w);
    else if(tl>mid) updata(id<<1|1,mid+1,r,tl,tr,w);
    else{
        updata(id<<1,l,mid,tl,mid,w);
        updata(id<<1|1,mid+1,r,mid+1,tr,w);
    }
    Push_up(id);
}
long long Q(int id,int l,int r,int tl,int tr)
{
    if(l==tl&&r==tr){
        return _max[id];
    }
    int mid=(l+r)>>1;
    if(lazy[id]) Push_down(id);
    if(tr<=mid) return Q(id<<1,l,mid,tl,tr);
    else if(tl>mid) return Q(id<<1|1,mid+1,r,tl,tr);
    else return max(Q(id<<1,l,mid,tl,mid),Q(id<<1|1,mid+1,r,mid+1,tr));
}
void solve()
{
    for(int j=1;j<=m;j++)
        q[j][top[j]++]=0;
    long long ans=0;
    for(int i=1;i<=n;i++)
    {
        updata(1,1,n,1,i,-a[i]);
        for(int j=1;j<=m;j++)
        {
            while(top[j]&&change[q[j][top[j]-1]][j]<=change[i][j])
            {
                updata(1,1,n,q[j][top[j]-2]+1,q[j][top[j]-1],-change[q[j][top[j]-1]][j]);
                top[j]--;
            }
            updata(1,1,n,q[j][top[j]-1]+1,i,change[i][j]);
            q[j][top[j]++]=i;
        }
        updata(1,1,n,i,i,a[i]);
        ans=max(ans,Q(1,1,n,1,n));
    }
    printf("%lld\n",ans);
}
int main()
{
    init();
    read();
    solve();
    return 0;
}


Measured memory_bytes: 7168
void main() {
  problem();
}

void problem() {
  const N = scan!long;
  const M = scan!long;
  const An = scan!long(cast(int)M);

  long solve() {
    const slack = N - An.sum;

    return slack >= 0 ? slack : -1;
  }

  solve().writeln;
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------


Measured memory_bytes: 3032
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int N;
string s[10000];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    rep(i,0,N) cin>>s[i];
    int ans=0;
    int a=0, b=0, c=0;
    rep(i,0,N){
        rep(j,0,s[i].length()-1){
            if(s[i][j]=='A'&&s[i][j+1]=='B') ans++;
        }
        if(s[i][0]=='B'&&s[i][s[i].length()-1]=='A') c++;
        else if(s[i][s[i].length()-1]=='A') a++;
        else if(s[i][0]=='B') b++;
    }
    if(a&&b){
        ans+=c+1+min(a,b)-1;
    }
    else if(a){
        ans+=c;
    }
    else if(b){
        ans+=c;
    }
    else{
        ans+=max(c-1,0);
    }
    cout <<ans<<"\n";
}

Measured memory_bytes: 768
from collections import deque
queue = deque(input())
q = int(input())
li = [list(input().split()) for _ in range(q)]

flag = 1
for i in range(q):
    if int(li[i][0]) == 1:
        flag *= -1
        continue

    if int(li[i][1]) == 1:
        if flag == 1:
            queue.appendleft(li[i][2])
        else:
            queue.append(li[i][2])
    else:
        if flag == 1:
            queue.append(li[i][2])
        else:
            queue.appendleft(li[i][2])

if flag == 1:
    print("".join(queue))
else:
    ans = list(queue)
    print("".join(ans[::-1]))

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

int main(){

  int N, ini, count;
  cin >> N;
  long A[N];
  for(int i=0; i<N; i++){
    cin >> A[i];
  }

  while(true){
    sort(A, A+N);
    count=0;
    for(int i=0; i<N; i++){
      if(A[i]==0){
        count++;
      }else{
        ini = i;
        break;
      }
    }

    if(count==N-1){
      cout << A[N-1] << endl;
      return 0;
    }

    for(int i=ini+1; i<N; i++){
      if(A[i]/A[ini] > 0){
        A[i] = A[i]%A[ini];
      }else{
        A[i] = 0;
      }
    }
  }


  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int sum[1005];
int main() {
    int n, m;
    while(true) {
        cin >> n >> m;
        if(n == 0) break;
        for(int i = 1; i <= n; i++) sum[i] = 0;
        for(int i = 1; i <= m; i++) {
            for(int j = 1; j <= n; j++) {
                int now;
                cin >> now;
                sum[j] += now;
            }
        }
        int maxi = 0;
        for(int i = 1; i <= n; i++) {
            maxi = max(maxi, sum[i]);
        }
        cout << maxi << endl;
    }
}


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

int main() {
  int N;
  int x = 0;
  cin >> N;
  
  for(int i=0;i<N;i++){
    int l,r;
    cin >> l >> r; 
    x += r-l+1;
  }
  
  cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

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

void Main() {
  Cin(int, n);
  Cin(string, s);
  Cin(int, k);

  char sk = s[k - 1];
  for (auto& e : s)
    if (e != sk) e = '*';

  cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
#define LL long long
#define INF 0x3f3f3f3f

const int MAXN = 1e2 + 5;
const LL MOD = 1e9 + 7;

int h, w;
char mp[MAXN][MAXN];
int ne[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
bool vis[MAXN][MAXN];
struct node
{
    int x, y;
    int step;
};

int bfs()
{
    node p;
    p.x = 1;
    p.y = 1;
    p.step = 0;
    queue<node > q;
    vis[1][1] = 1;
    q.push(p);
    while(!q.empty())
    {
        node p = q.front();
        q.pop();
        // cout << p.x << " " << p.y << endl;
        if(p.x == h && p.y == w)
            return p.step;
        for(int i = 0; i < 4; i++)
        {
            int nx = p.x+ne[i][0];
            int ny = p.y+ne[i][1];
            if(vis[nx][ny])
                continue;
            if(nx < 1 || nx > h || ny < 1 || ny > w)
                continue;
            if(mp[nx][ny] == '#')
                continue;
            vis[nx][ny] = 1;
            node zz;
            zz.x = nx;
            zz.y = ny;
            zz.step = p.step+1;
            q.push(zz);
        }
    }
    return -1;
}

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
#endif

    cin >> h >> w;
    getchar();
    int sum = 0;
    for(int i = 1; i <= h; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            scanf("%c", &mp[i][j]);
            if(mp[i][j] == '.')
                sum++;
        }
        getchar();
    }
    int dz = bfs();
    // cout << dz << endl;
    if(dz == -1)
        cout << dz << endl;
    else
        cout << sum - dz - 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll di[10][10];
    ll N;
    cin>>N;
    ll mul=1;
    MEMSET(di, 0);
    rep(i, N){
        if(mul*10<=i+1) mul*=10;
        int top=(i+1)/mul;
        int low=(i+1)%10;
        di[top][low]++;
    }
    ll count=0;
    for(int i=1; i<10; i++)
        for(int j=1; j<10; j++){
            count+=di[i][j]*di[j][i];
        }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    int n;
    string s;
    cin >> n >> s;
    rep(i, s.size()){
        int tmp = s[i] - 'A';
        cout << (char) ((tmp+n)%26 + 'A');
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi=3.14159265358979;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,k,dp[1010][1010];
    cin>>n>>k;
    if(n<k){
        cout<<0<<endl;
        return 0;
    }
    n-=k;
    dp[0][0]=1;
    rep2(i,1,k+1){
        rep(j,n+1){
            if(j-i>=0){
                dp[i][j]=(dp[i-1][j]+dp[i][j-i])%MOD;
            }
            else{
                dp[i][j]=dp[i-1][j]%MOD;
            }
        }
    }
    cout<<dp[k][n]<<endl;
    return 0;
}


Measured memory_bytes: 7428
#include <iostream>
#include <deque>
#include <vector>

using namespace std;

template <class T>
std::vector<int> slideMin(const std::vector<T>& v, int k) {
  /* vの連続するk区間の最小値のindexのリストを返す */
  std::vector<int> ret;
  std::deque<int> dq;
  int n = v.size();
  for (int i = 0; i < n; ++i) {
    while (dq.size() && v[dq.back()] >= v[i]) dq.pop_back();
    dq.push_back(i);
    if (i - k + 1 >= 0) {
      ret.push_back(dq.front());
      if (dq.front() <= i-k+1) dq.pop_front();
    }
  }
  return ret;
}

#ifndef call_from_test
#include <cassert>
int main() {
  int n, l; cin >> n >> l;
  vector<int> la(n);
  for (int &a: la) cin >> a;

  vector<int> ret = slideMin(la, l);
  for (int i = 0; i < ret.size(); ++i) {
    if (i > 0) cout << " ";
    cout << la[ret[i]];
  }
  cout << endl;
}
#endif



Measured memory_bytes: 10980
// 2014/07/29 Tazoe

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

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

	int q;
	cin >> q;

	for(int i=0; i<q; i++){
		string s;
		cin >> s;

		if(s=="print"){
			int a, b;
			cin >> a >> b;

			for(int j=a; j<=b; j++){
				cout << str[j];
			}
			cout << endl;
		}
		else if(s=="reverse"){
			int a, b;
			cin >> a >> b;

			for(int j=a, k=b; j<k; j++, k--){
				swap(str[j], str[k]);
			}
		}
		else if(s=="replace"){
			int a, b;
			cin >> a >> b;
			string p;
			cin >> p;

			for(int j=a, k=0; j<=b; j++, k++){
				str[j] = p[k];
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1212
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	vector<string>in(n);
	vi c(n);
	rep(i,n)cin>>in[i]>>c[i];
	int co=0;
	int coo=0;
	rep(i,n){
		if(m==0){
			cout<<"! Game Over"<<endl;
			return 0;
		}
		int t=0;
		while(1){
			if(t==in[i].size())break;
			cout<<"? ";
			rep(j,in[i].size())cout<<(j<t?'_':(char)in[i][j]);
			cout<<endl;
			char d,dd;
			cin>>d;
			co++;
			d=toupper(d);
			dd=toupper(in[i][t]);
			if(dd==d){
				t++;
				coo++;
			}else{
				c[i]--;
				if(c[i]<0){
					m--;
					break;
				}
			}
		}
	}
	if(m==0){
		cout<<"! Game Over"<<endl;
		return 0;
	}
	double q=coo*100.0/co;
	q=(int)(q*10);
	q/=10;
	printf("! Game Clear %0.1f\n",q);
}

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

long long n, k;
vector<long long> a, res;

void solve();

int main() {
  cin >> n >> k;
  a.resize(n);
  for (auto &p : a) cin >> p;
  solve();
  for (int i = 0; i < n; ++i) cout << res[i] << " \n"[i == n - 1];
  return 0;
}

void solve() {
  while (k) {
    res.assign(n + 1, 0);
    for (int i = 0; i < n; ++i) {
      ++res[max(0LL, i - a[i])];
      --res[min(n, i + a[i] + 1)];
    }
    for (int i = 1; i < n; ++i) res[i] += res[i - 1];
    a = res;
    if (!(--k)) return;
    bool ch = 1;
    for (int i = 0; i < n; ++i)
      if (res[i] != n) ch = 0;
    if (ch) break;
  }
}

Measured memory_bytes: 7944
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

ll d[210][210];

int main(){
	ll n;
	cin>>n;
	clr(d,-1);
	rep(i,0,n){
		rep(j,i+1,n){
			if(d[i][j]!=-1)continue;
			rep(k,j+1,n){
				string s1;
				rep(l,0,n){
					if(l==i||l==j||l==k)s1+="1";
					else s1+="0";
				}
				cout << "?" << " " << s1 << endl;
				ll ans1;
				cin>>ans1;
				if(ans1 == 0){
					d[i][j] = 0;
					d[i][k] = 0;
					d[j][k] = 0;
				}
				else if(ans1 == 4){
					string s2;
					rep(l,0,n){
						if(l==i||l==j)s2+="1";
						else s2+="0";
					}
					cout << "?" << " " << s2 << endl;
					ll ans2;
					cin>>ans2;
					if(ans2 == 0){
						d[i][j] = 0;
						d[i][k] = 1;
						d[j][k] = 1;
						continue;
					}
					string s3;
					rep(l,0,n){
						if(l==j||l==k)s3+="1";
						else s3+="0";
					}
					cout << "?" << " " << s3 << endl;
					ll ans3;
					cin>>ans3;
					if(ans3 == 0){
						d[i][j] = 1;
						d[i][k] = 1;
						d[j][k] = 0;
						continue;
					}
					d[i][j] = 1;
					d[i][k] = 0;
					d[j][k] = 1;
					continue;
				}
				else{
					string s2;
					rep(l,0,n){
						if(l==i||l==j)s2+="1";
						else s2+="0";
					}
					cout << "?" << " " << s2 << endl;
					ll ans2;
					cin>>ans2;
					if(ans2 == 1){
						d[i][j] = 1;
						d[i][k] = 0;
						d[j][k] = 0;
						continue;
					}
					string s3;
					rep(l,0,n){
						if(l==j||l==k)s3+="1";
						else s3+="0";
					}
					cout << "?" << " " << s3 << endl;
					ll ans3;
					cin>>ans3;
					if(ans3 == 1){
						d[i][j] = 0;
						d[i][k] = 0;
						d[j][k] = 1;
						continue;
					}
					d[i][j] = 0;
					d[i][k] = 1;
					d[j][k] = 0;
					continue;
				}
			}
		}
	}
	cout << "! ";
	vector<pair<ll,ll> > v;
	rep(i,0,200){
		rep(j,i+1,200){
			if(d[i][j] == 1){
				v.pb(mp(i,j));
			}
		}
	}
	rep(i,0,v.sz){
		cout << "(" << v[i].fi << "," << v[i].se << ")";
		if(i!=v.sz-1)cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1236
#python3 
g=[[-1 for _ in range(15)] for _ in range(15)]
n=int(input())
for i in range(n):
  a=int(input())
  for _ in range(a):
    x,y=map(int, input().split())
    g[i][x-1]=y

ans=0
for i in range(1<<n):
  hy = [0 for _ in range(n)]
  for j in range(n):
    if (i>>j)&1:
      hy[j]=1

  ok = True 
  for j in range(n):
    if hy[j]==1:
      for k in range(n):
        if g[j][k] == -1: continue; 
        if g[j][k] != hy[k]: ok = False; 
  if ok:
    ans=max(ans, hy.count(1))

print(ans)

Measured memory_bytes: 3064
def make_candidate(N, seed, l):
    seed3 = seed+"3"
    seed5 = seed+"5"
    seed7 = seed+"7"

    if int(seed3) <= N:
        l.append(seed3)
        l = make_candidate(N, seed3, l)
    
    if int(seed5) <= N:
        l.append(seed5)
        l = make_candidate(N, seed5, l)
    
    if int(seed7) <= N:
        l.append(seed7)
        l = make_candidate(N, seed7, l)
    
    return l


N = int(input())

l = make_candidate(N, "0", [])

num = 0
for n in l:
    s = str(n)
    exist = s.count('3') * s.count('5') * s.count('7')

    if exist>0:
        num = num + 1

print(num)


Measured memory_bytes: 5224