akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;
char s[105];
int q[405];
int hd,tl;
int main(){
	int i,j;
	n=read();
	scanf("%s",s+1);
	int st=101,ed=100;
	for(i=1;i<=n;i++){
		q[++ed]=(s[i]=='(')?1:-1;
	}
	int hd=st,tl=ed;
	int cnt=0;
	for(i=st;i<=ed;i++){
		cnt+=q[i];
		if(cnt<0){
			q[--hd]=1;cnt++;
		}
	}
	while(cnt>0){
		q[++tl]=-1;cnt--;
	}
	for(int i=hd;i<=tl;i++){
		if(q[i]==1)putchar('(');
		else if(q[i]==-1)putchar(')');
	}
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = input().split()
A = [int(a) for a in A]
S = [1]
a = 1
number = 0
numbers=[-1 for _ in range(N)]
for _ in range(N + 1):
    b = A[a - 1]
    if numbers[b-1] != -1:
      c=numbers[b-1]
      break
    numbers[b-1]=number
    number += 1
    S.append(b)
    a = b
T = S[c+1:number+1]
if K <= number:
  print(S[K ])
else:
  z = K - c-1
  y = z % (number - c)
  print(T[y])



Measured memory_bytes: 32272
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    double s = Math.sqrt((double)N);
    long n = (long)s;
    
    int x = 1;
    int y = 1;
    long afterX = 0;
    long afterY = 0;
    
    for(long i=n; i>0; i--){
      if(N % i == 0){
        afterX = i;
        break;
      }
    }
    
    afterY = N / afterX;
    System.out.println((afterX-x) + (afterY-y));
  }
}


Measured memory_bytes: 23764
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long A = sc.nextLong();
        long B = sc.nextLong();

        long left;
        long right;
        long mid;
        if ((B-A-1)%2 == 1) {
            left = A-1+(B-A)/2;
            right = N-B+(B-A)/2;
            mid = (B-A)/2;
        } else {
            left = A+(B-A-1)/2;
            right = N-B+1+(B-A-1)/2;
            mid = Long.MAX_VALUE;
        }
        /*
        System.out.println("l " + left);
        System.out.println("r " + right);
        System.out.println("m " + mid);
        */

        System.out.println(Math.min(Math.min(left, right), mid));
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define dbg(x) cerr << #x << " = " << x << "\n"
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie()
using namespace std;
using ll = long long;

const int N = int(2e5) + 500;

int n, pf[N], ans;
char c[N];

int main() {
    fast_io;

    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> c[i];

    for (int i = 0; i < n; ++i)
        pf[i] = (i - 1 < 0 ? 0 : pf[i - 1]) + (c[i] == 'R');

    ans = min(n - pf[n - 1], pf[n - 1]);
    for (int i = 0; i < n; ++i) {
        int len = i + 1;
        int white_left = len - pf[i];
        int red_right = pf[n - 1] - pf[i];
        int cur = 0;

        int o = min(white_left, red_right);
        white_left -= o;
        red_right -= o;
        cur += o;

        cur += white_left + red_right;

        ans = min(ans, cur);
    }

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


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

int main(){
    int n, k, m;
    while(cin >>n >>k >>m){
        if(n == 0 && k == 0 && m == 0) break;
        vector<int> vec(n);
        for(int i = 1; i <= n; i++) vec[i - 1] = i;
        vector<int>::iterator it = vec.begin() + m - 1;
        vec.erase(it);
        while(vec.size() != 1){
            it += (k - 1);
            while(it >= vec.end()) it = vec.begin() + (it - vec.end());
            vec.erase(it);
            if(it >= vec.end()) it = vec.begin();
        }
        cout <<vec[0] <<endl;
    }
    return 0;
}

Measured memory_bytes: 1252
///
/**
 * @Samaritan
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#define pb emplace_back
#define fi first
#define se second
#define PII pair<int, int>
#define PLL pair<LL, LL>

LL quick_pow (LL a, LL b, LL mod) {
    LL ans = 1, base = a;
    while (b) {
        if (b & 1) (ans *= base) %= mod;
        b >>= 1;
        (base *= base) %= mod;
    }
    return ans;
}

const int mod = 1e9 + 7;
const int N = 2e2 + 5;

struct node {
    int pos, v;
    bool operator < (const node& k) const {
        return v > k.v;
    }
};

char pic[N][N];

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    memset(pic, 0, sizeof pic);
    int n = 100;
    int cnt = b - 1;
    int max_col = 2;
    for (int i = 1; i <= n; ++i) {
        if (!cnt) break;
        for (int j = 1; j <= n; ++j) {
            if (i & 1 && j & 1) {
                pic[i][j] = '#';
                cnt--;
                if (!cnt) {
                        max_col = i + 1;
                    break;
                }
            }
        }
        if (!cnt) break;
    }
    for (int i = 1; i <= max_col; ++i) {
        for (int j = 1; j <= n; ++j) {
            if (!pic[i][j]) pic[i][j] = '.';
        }
    }
    cnt = a - 1;
    for (int i = max_col + 2; i <= n; ++i) {
        if (!cnt) break;
        for (int j = 1; j <= n; ++j) {
            if (i & 1 && j & 1) {
                pic[i][j] = '.';
                cnt--;
                if (!cnt) {
                    break;
                }
            }
        }
        if (!cnt) break;
    }
    for (int i = max_col + 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            if (!pic[i][j]) pic[i][j] = '#';
        }
    }
    printf("100 100\n");
    for (int i = 1; i <= n; ++i) printf("%s\n", pic[i] + 1);
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      k: usize,
      mut s: chars,
    }
    s[k-1] = ((s[k-1] as u8 - 'A' as u8) + 'a' as u8) as char;
    let s = s.into_iter().collect::<String>();
    println!("{}", s);
}


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


int main()
{
    int N,R;
    int ans;

    cin >> N >> R;

    if(N>=10){
        cout << R <<endl;
    }else{
        cout << R + 100*(10-N) << endl;
    }


 
    return 0;

}

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

int main() {
  int n, l, r, s = 0;
  cin >> n;
  REP(i, n) {
    cin >> l >> r;
    s += r - l + 1;
  }
  cout << s << endl;
  return 0;
}

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

#define int long long
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);

int32_t main(){
	fast;
	int n;
	cin >> n;
	
	int a[n];
	for(auto &x : a)    cin >> x;
	
	int ans= INT_MAX;
	for(int j=-100 ; j<=100 ;j++)
	{
		int temp = 0;
		for(auto x : a) temp += pow(x-j,2);
		ans = min(ans,temp);
	}
	cout << ans;
}







Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
 
class Atest {
    static void Main(string[] args) {
        int[] abc = Console.ReadLine().Trim().Split(' ').Select(a => int.Parse(a)).ToArray();
        if (abc[0] == abc[1] && abc[0] == abc[2]) {
            System.Console.WriteLine("No");
        } else if (abc[0] != abc[1] && abc[0] != abc[2] && abc[1] != abc[2]) {
            System.Console.WriteLine("No");
        } else {
            System.Console.WriteLine("Yes");
        }
    }
}

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

#define each(i, c) for (auto& i : c)

typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9+7;

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

  string s;
  cin >> s;

  ll ans = 0;
  for (ll i = 0; i < n-2;) {
    if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') {
      ++ans;
      i += 3;
    } else {
      ++i;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
#define N 1000
#define WHITE 0
#define BLACK 1
#define NILL -1

int d[N];
int w[N][N];/*w[i][j]にiからjへ移動する*/
int color[N];/*Sに含まれるかを確認*/
int v;

int main(void){

  int n,i,j,mincost,u,k;
  int s=0;/*スタート地点*/

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      w[i][j] = INT_MAX;
    }
  }

  for(i=0;i<n;i++){
    d[i] = INT_MAX;
    color[i] = 0;
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      scanf("%d",&w[u][v]);
    }
  }

  d[s] = 0;

  while(1){
    mincost = INT_MAX;
      for(i=0;i<n;i++){
	if(d[i] < mincost && color[i] == WHITE){
	  mincost = d[i];
	  u = i;
	}
      }

    if(mincost == INT_MAX) break;

    color[u] = BLACK;

    for(v=0;v<=n;v++){
      if(w[u][v] == INT_MAX) continue;
      if(d[v] > d[u] + w[u][v]){
	d[v] = d[u] + w[u][v];
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }
  return 0;
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct point
{
    ll x, y;
};
point a[200009];
ll n;
double d;
ll ans;
void inp()
{
    cin >> n >> d;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].x >> a[i].y;
    }
}
double distan(point a)
{
    double k = ((a.x*a.x) + (a.y*a.y))*1.0;
    return (sqrt(k));
}
void process()
{
    ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (distan(a[i]) <= d) ans++;
    }
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("test.inp","r", stdin);
    inp();
    process();
    return 0;
}


Measured memory_bytes: 6684
x = int(input())
if x < 600:
  ans = 8
elif x < 800:
  ans = 7
elif x < 1000:
  ans = 6
elif x < 1200:
  ans = 5
elif x <1400:
  ans = 4
elif x < 1600:
  ans = 3
elif x < 1800:
  ans = 2
else:
  ans = 1
print(ans)

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

	int N, ans = 100000100;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++)cin >> A[i];

	sort(A.begin(), A.end());
	for (int i = 0; i < A.size() - 1; i++) {
		if (A[i + 1] % A[i] == 0) {
			A.erase(A.begin() + i + 1);
			i--;
		}
		else A[i + 1] %= A[i];
	}
	sort(A.begin(), A.end());
	int s = 1;
	while (s != A.size()) {
		if (A[s - 1] == A[s])A.erase(A.begin()+s);
		else s++;
	}
	while (A.size() > 1) {
		sort(A.begin(), A.end());
		if (A[A.size() - 1] % A[A.size() - 2] == 0)A.pop_back();
		else A[A.size() - 1] %= A[A.size() - 2];
	}

	cout << A[0] << endl;

	return 0;
}


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

#define DEBUG(x) cerr << #x << " = " << x << endl

enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };

template<typename T>
struct Dice {
  T var[6]; int id[6];
  Dice() {
    id[0] = TOP, id[1] = FRONT, id[2] = LEFT;
    id[3] = RIGHT, id[4] = BACK, id[5] = BOTTOM;
  }
  T& operator[] (FACE f) { return var[id[f]]; }
  const T& operator[] (FACE f) const { return var[id[f]]; }
  bool operator ==(const Dice<T>& b) const {
    const Dice<T>& a = *this;
    if(a[TOP] != b[TOP]) return false;
    if(a[BOTTOM] != b[BOTTOM]) return false;
    if(a[FRONT] != b[FRONT]) return false;
    if(a[BACK] != b[BACK]) return false;
    if(a[LEFT] != b[LEFT]) return false;
    if(a[RIGHT] != b[RIGHT]) return false;
    return true;
  }
  // a -> b, b -> c, c -> d, d -> a
  void roll(FACE a, FACE b, FACE c, FACE d) {
    int value = id[d];
    id[d] = id[c], id[c] = id[b], id[b] = id[a], id[a] = value;
  }
  // FRONT???RIGHT????§??????????
  void roll_r() { roll(FRONT, RIGHT, BACK, LEFT); }
  // FRONT???TOP????§??????????
  void roll_u() { roll(FRONT, TOP, BACK, BOTTOM); }
  // TOP, RIGHT, BOTTOM, LEFT???????¨???????????§??????????
  void roll_c() { roll(TOP, RIGHT, BOTTOM, LEFT); }
  // roll_r??¨roll_u????????????????????????????????????roll_c???4?????????
  bool eq(const Dice& d) {
    for(int k = 0; k < 6; k++) {
      for(int i = 0; i < 4; i++) {
        if(*this == d) return true;
        roll_c();
      }
      if(k % 2 == 0) roll_r();
      else roll_u();
    }
    return false;
  }
};

int main() {
  int N; cin >> N;
  vector<Dice<int>> dd(N);
  for(int i = 0; i < N; ++i) {
    cin >> dd[i][TOP];
    cin >> dd[i][FRONT];
    cin >> dd[i][RIGHT];
    cin >> dd[i][LEFT];
    cin >> dd[i][BACK];
    cin >> dd[i][BOTTOM];
  }
  bool same = false;
  for(int i = 0; i < N; ++i) {
    for(int j = i + 1; j < N; ++j) {
      if(dd[i].eq(dd[j])) same = true;
    }
  }
  cout << (same ? "No" : "Yes") << endl;
}

Measured memory_bytes: 1196
import java.util.*;

public class Main{
	public static void main(String args[]){

		// 値取得
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		if(n == 0){
			System.out.println(n);
		}else{
			System.out.println(n*n*n);
		}
	}
}

Measured memory_bytes: 21844
/*

https://www.cnblogs.com/SovietPower/p/9757375.html
*/
#include <cstdio>
#include <algorithm>
#define mod 998244353
const int N=1e6;

int fac[N+3],ifac[N+3];

inline int FP(int x,int k)
{
	int t=1;
	for(; k; k>>=1,x=1ll*x*x%mod)
		if(k&1) t=1ll*t*x%mod;
	return t;
}
#define C(n,m) (1ll*fac[n+m]*ifac[n]%mod*ifac[m]%mod)//C(n+m,n)

int main()
{
	int n,m; scanf("%d%d",&n,&m);
	if(n<m) std::swap(n,m);

	int lim=n+m; fac[0]=fac[1]=1;
	for(int i=1; i<=lim; ++i) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[lim]=FP(fac[lim],mod-2);
	for(int i=lim; i; --i) ifac[i-1]=1ll*ifac[i]*i%mod;

	long long ans=0;
	for(int i=1; i<=m; ++i) ans+=1ll*C(i,i)*C(n-i,m-i)%mod;
	ans=ans%mod*FP(C(n,m),mod-2)%mod*FP(2,mod-2)%mod;
	printf("%lld\n",(ans+n)%mod);

	return 0;
}

Measured memory_bytes: 7936
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int num  = sc.nextInt();
        for(int i = 1; i < n; i++) {
            num ^= sc.nextInt();
        }
        if(num == 0) System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 47664
#include<stdio.h>
#include<stdlib.h>


int cmp(const int *a,const int *b){

return *a > *b ? -1 : *a < *b ? 1 : 0 ;
}
//qsort(pa,n,sizeof(int),(int(*)(const void* ,const void*))cmp);

int main(void){
  int k,x;
  scanf("%d%d",&k,&x);
  if(500*k>=x){
    printf("Yes");
    return 0;
  }
  else{
    printf("No");
  }




  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

const int MAX_INT = 1000100;
// const int MAX_INT = 100;

int main() {
	int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> isp(MAX_INT+1, 0);
    for(const auto& num: a) {
        if (isp[num]>1) continue;
        for(int i=1; num*i<=MAX_INT; i++) {
            isp[num*i]++;
        }
        // debug(isp);
    }
    int ans = 0;
    for(const auto& num: a) {
        if (isp[num]==1) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8008
from math import sqrt

N, D = map(int, input().split())

X = []
for i in range(N):
    x_line = list(map(int, input().split()))
    X.append(x_line)

count = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d])**2
        droot = sqrt(float(dist))
        if droot.is_integer():
            count += 1

print(count)

Measured memory_bytes: 3064
ans_list = []
while True:
    n = int(input())
    if n==0:
        break
    A = list(map(int,input().split()))
    ave = sum(A) // len(A)
    cnt = 0
    for a in A:
        if a <= ave:
            cnt += 1
    ans_list.append(cnt)

for ans in ans_list:
    print(ans)


Measured memory_bytes: 6604
N = gets.to_i

points = []
N.times do
  t, x, y = gets.split.map(&:to_i)
  points << [t, x, y]
end

possible = true
t = 0
x = 0
y = 0
points.each do |point|
  # puts "x: #{x} y: #{y} nx: #{point[1]} ny: #{point[2]}"
  distance = (x - point[1]).abs + (y - point[2]).abs
  move = point[0] - t

  # p "dis: #{distance} move: #{move}"

  if move < distance
    possible = false
    break
  end

  if (move - distance) % 2 != 0
    possible = false
    break
  end

  t = point[0]
  x = point[1]
  y = point[2]
end

if possible
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 9468
#include<bits/stdc++.h>
using namespace std;
int mod = 1e9+7;
int dp[1005][1005];
int main(){
    int t,h,w;
    char st[1003][1003];
        cin>>h>>w;
        for(int i = 0;i<h;i++){
            scanf("%s",st[i]);
        }
        dp[0][0] = 1;
        for(int i = 0;i<h;i++){
            for(int j = 0 ;j<w;j++){
                int c1 = j+1;
                int r1 = i +1;
                if(st[i][j] == '.'){
                     if(st[i][c1] != '#'){
                        dp[i][c1] += dp[i][j];
                        if(dp[i][c1]>= mod)
                            dp[i][c1] -= mod;
                    }

                     if(st[r1][j] != '#'){
                        dp[r1][j] += dp[i][j];
                        if(dp[r1][j]>= mod)
                            dp[r1][j] -= mod;
                     }
                }
            }
        }
            cout<<dp[h-1][w-1]<<endl;
        }





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

int main() {
  int N,sum=0,lim=0;
  cin >> N;
  vector<int> H(N);
  
  for (auto&& x:H) {
    cin >> x;
  }
  lim = H.at(0);
  for (int i=0;i<N;i++) {
    if  (H.at(i) >= lim) {
      lim = H.at(i);
      sum++;
    } else {
      continue;
    }
  }
  cout << sum << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 61;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);

    int a;
    string s;
    cin >> a >> s;
    if (a < 3200) s = "red";

    cout << s << endl;
     
    return 0;
}

Measured memory_bytes: 256
from sys import stdin, stdout  
  
def main(): 
	n, k = [int(x) for x in stdin.readline().split()] 
	arr = [int(x) for x in stdin.readline().split()] 
	notValid = set()
	for x in range(k): 
		a, b = [int(x) for x in stdin.readline().split()] 
		if arr[a-1] > arr[b-1]:
			notValid.add(b)
		elif arr[a-1] == arr[b-1]:
			notValid.add(b)
			notValid.add(a)
		else:
			notValid.add(a)
	#print(notValid,"hass")

	stdout.write(str(n - len(notValid))+'\n')
if __name__ == "__main__": 
	main()

Measured memory_bytes: 20336
#include<stdio.h>

int main(){
    int height,width;
    for(;;){
        scanf("%d%d",&height,&width);
        if(width == 0 && height == 0)break;

        for(int j = 1; j <= height; j++){
            for(int i = 1; i <= width; i++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2052
#include <stdio.h>
#include <stdlib.h>
#define min(X, Y) ((X) < (Y) ? (X) : (Y))

typedef long long ll;

int cmp(const void *, const void *);

int main()
{
    ll n, k;
    ll arr[100005];
    ll ans = 1ll << 60ll;

    scanf("%lld %lld", &n, &k);
    for (ll i = 0; i  < n; i++) {
        scanf("%lld", &arr[i]);
    }

    qsort(arr, n, sizeof(ll), cmp);

    for (ll i = 0; i < n - k + 1; i++) {
        ans = min(ans, arr[i + k - 1] - arr[i]);
    }

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

    return 0;
}

int cmp(const void *a, const void *b)
{
    return *(long long*)a - *(long long*)b;
}


Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

const int MaxN = 123456;

vector <int> g[MaxN];
int used[MaxN], q[MaxN];

int main (void)
{
  int i, n, u, v;
  while (scanf ("%d", &n) != EOF)
  {
    for (i = 0; i < n; i++)
      g[i].clear();

    for (i = 0; i < n - 1; i++)
    {
      scanf ("%d %d", &v, &u);
      u--, v--;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    memset (used, 0, sizeof used);
    used[0] = 1;
    used[n-1] = 2;
    q[0] = 0;
    q[1] = n - 1;
    int ans[] = {0, 1, 1};
    int cur = 0, end = 2;
    while (cur < end)
    {
      v = q[cur++];
      for (size_t i = 0; i < g[v].size(); i++)
      {
        if (used[g[v][i]] == 0)
        {
          used[g[v][i]] = used[v];
          ans[used[v]]++;
          q[end++] = g[v][i];
        }
      }
    }
//    for (i = 0; i < n; i++)
//      printf ("%d %d\n", i+1, used[i]);
    printf (ans[1] > ans[2] ? "Fennec\n" : "Snuke\n");
  }
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  long long sum = 0;
  
  for(int i=0; i<n; i++) sum += a[i];
  
  vector<int> memo(100000);
  
  for(int i=0; i<n; i++) memo[a[i]-1]++;
  
  int q;
  cin >> q; 
  
  vector<int> bc(2*q);
  for(int i=0; i<2*q; i++) cin >> bc[i];
  
  for(int i=1; i<=q; i++){
    sum += (bc[2*(i-1)+1]-bc[2*(i-1)]) * memo[bc[2*(i-1)]-1];
    cout << sum << endl;
    memo[bc[2*(i-1)+1]-1] += memo[bc[2*(i-1)]-1];
    memo[bc[2*(i-1)]-1] = 0;
  }
 
	return 0;
}


Measured memory_bytes: 4736
package main

import "fmt"

var INF = 100100100100

func main() {
	var n, m, x int
	fmt.Scan(&n, &m, &x)
	c := make([]int, n)
	a := make(map[int][]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&c[i])
		a[i] = make([]int, m)
		for j, _ := range a[i] {
			fmt.Scan(&a[i][j])
		}
	}

	ans := INF
	for i := 0; i < 1<<uint(n); i++ {
		price := 0
		exp := make([]int, m)
		for j := 0; j < n; j++ {
			if i>>uint(j)&1 == 1 {
				price += c[j]
				for k := 0; k < m; k++ {
					exp[k] += a[j][k]
				}
			}
		}
		ok := true
		for j := 0; j < m; j++ {
			if exp[j] < x {
				ok = false
			}
		}
		if ok {
			ans = min(ans, price)
		}

	}
	if ans == INF {
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

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

int main(){
  	int N;
  	cin >> N;
  	int a[N];
  	for(int i = 0; i < N ; i++)cin >> a[i];
  	sort(a,a+N);
  	cout<<a[N-1]-a[0]<<endl;
  	
}

Measured memory_bytes: 256
package main

import "fmt"

type i64 int64

const MOD i64 = 1000000007

var fact, invf [202020]i64

func modPow(b, n, mod i64) i64 {
	if n == 1 {
		return b
	}
	ret := modPow(b*b%mod, n/2, mod)
	if n&1 == 1 {
		ret = ret * b % mod
	}
	return ret
}

func inverce(n i64) i64 {
	return modPow(n, MOD-2, MOD)
}

func comb(n, k i64) i64 {
	if k < 0 || n < k {
		return 0
	}
	return fact[n] * invf[k] % MOD * invf[n-k] % MOD
}

func main() {
	var h, w, a, b, ans i64
	fmt.Scan(&h, &w, &a, &b)

	fact[0] = 1
	invf[0] = 1

	for i := i64(1); i < 202020; i++ {
		fact[i] = (fact[i-1] * i) % MOD
		invf[i] = inverce(fact[i])
	}

	for i := i64(1); i <= h-a; i++ {
		ans += comb(b-1+i-1, b-1) * comb(w-b-1+h-i, h-i) % MOD
		ans %= MOD
	}

	fmt.Println(ans)
}


Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <functional>
#include <cmath>
#include <memory>
#ifndef ONLINE_JUDGE
# include <complex>
# include <random>
# include <array>
# include <unordered_map>
# include <unordered_set>
# define mkt make_tuple
#endif
#ifdef _LOCAL
# include "local/local.hpp"
#else
# define assert(...) ((void)0)
# define ifdebug if (false)
# define echo(...) ((void)0)
#endif
using namespace std;
typedef long long ll; typedef unsigned long long ull;
#define repi(_I, _B, _E) for(int _I = (_B); (_I) < (_E); ++ (_I))
#define rep(_I, _N) for(int _I = 0; (_I) < (_N); ++ (_I))
#define all(_X) (_X).begin(), (_X).end()

ll const MOD = 1000000007;

/**
2分累乗法(Exponentiation by squaring)
(T, f, unit): 半群
@result: x^n
@order: O(log |n|)
//*/
template<typename T, typename Fun>
T exp_by_squaring(T const& x, int n, Fun&& f, T const& unit)
{
	assert(n >= 0);
	if (n == 1) return x;
	T z = unit;
	T w = x;
	while (n != 0) {
		if ((n & 1) != 0) {
			z = f(z, w); n ^= 1;
		}
		else {
			w = f(w, w); n >>= 1;
		}
	}
	return std::move(z);
}

template<typename Int>
Int exp_by_squaring(Int x, int n)
{
	return exp_by_squaring(x, n, [](Int l, Int r) { return l * r; }, Int(1));
}

template<long long Mod> struct FiniteField
{
	using Int = long long;

	static Int unit() { return 1; }
	static Int inject(Int x) { return (x % Mod + Mod) % Mod; }
	static Int add(Int x, Int y) { return inject(inject(x) + inject(y)); }
	static Int sub(Int x, Int y) { return inject(inject(x) - inject(y)); }
	static Int mul(Int x, Int y) { return inject(inject(x) * inject(y)); }
	static Int div(Int x, Int y) { return mul(x, inv(y)); }
	static Int inv(Int x) { return pow(x, Mod - 2); }

	static Int pow(Int x, int n) { return exp_by_squaring(x, n, mul, unit()); }

	template<size_t Max>
	static Int fact(int n)
	{
		static array<Int, Max> t ={ 1, 1 };
		for (int i = 2; i <= n; ++i) {
			if (t[i] == 0) { t[i] = inject(i * t[i - 1]); }
		}
		return t[n];
	}

	//(n!)^-1
	template<size_t Max>
	static Int fact_inv(int n)
	{
		static array<Int, Max> t ={ 1, 1 };
		if (t[n] == 0) {
			t[n] = inv(fact<Max>(n));
			for (int i = n - 1; i >= 2; --i) {
				t[i] = inject(t[i + 1] * (i + 1));
			}
		}
		return t[n];
	}
	template<size_t Max>
	static Int combi(int n, int r)
	{
		if (n < r) { return 0; }
		if (r == 0) { return 1; }
		return (fact<Max>(n) * fact_inv<Max>(n - r) % Mod) * fact_inv<Max>(r) % Mod;
	}
};

bool verify(int n, vector<int> const& ds)
{
	if (n % 2 == 0)
	{
		rep(i, n)
		{
			if (ds[i] != (i / 2) * 2 + 1) return false;
		}
	}
	else
	{
		rep(i, n)
		{
			if (ds[i] != ((i + 1) / 2) * 2) return false;
		}
	}
	return true;
}

ll calc(int n, vector<int> const& ds)
{
	if (!verify(n, ds))
	{
		return 0LL;
	}

	return FiniteField<MOD>::pow(2, n / 2);
}

int main()
{
	int n;
	cin >> n;
	auto ds = vector<int>(n);
	rep(i, n)
	{
		cin >> ds[i];
	}
	sort(all(ds));
	cout << calc(n, ds) << endl;
	return 0;
}


Measured memory_bytes: 640
using System;

class Program {
    static void Main( string[] args )
    {
        string[] s = Console.ReadLine().Split();

        int a = int.Parse( s[ 0 ] );
        int b = int.Parse( s[ 1 ] );
        int c = int.Parse( s[ 2 ] );

        int count = 0;

        for ( int i = a; i <= b; ++i ) {
            if ( 0 == c % i ) {
                count += 1;
            }
        }

        Console.WriteLine( count );
    }
}

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

//他の解答見て解答

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

    ll ans = 0;
    if(a + 2 >= b or k < a){
        ans = k + 1;
    }else{
        k -= a - 1;
        ans = a + (b - a) * (k / 2) + k % 2;
    }
    put(ans);
}

Measured memory_bytes: 3600
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 1000005
#define PP pair<pair<ll,ll>,pair<pair<ll,ll>,ll>>
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1e9;
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {

	fast
	// cases
	{
		ll a, b;
		cin >> a >> b;
		cout << a*b << END;
	}


// #ifndef ONLINE_JUDGE
// 	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>

using namespace std;

struct Elem {
    int key;
    Elem *prev = NULL;
    Elem *next = NULL;
};

Elem *head = NULL;
Elem *tail = NULL;

void insert(int x) {
    Elem *elem = new Elem();
    elem->key = x;
    elem->next = head;
    if (head == NULL)
        tail = elem;
    else
        head->prev = elem;
    head = elem;
}

void deleteFirst() {
    head = head->next;
    if (head != NULL)
        head->prev = NULL;
    else
        tail = NULL;
}

void deleteLast() {
    tail = tail->prev;
    if (tail != NULL)
        tail->next = NULL;
    else
        head = NULL;
}

void _delete(int x) {
    Elem *temp = head;
    while (temp != NULL) {
        if (temp->key == x) {
            if (temp == head) {
                deleteFirst();
            }
            else if (temp == tail) {
                deleteLast();
            }
            else {
                temp->prev->next = temp->next;
                temp->next->prev = temp->prev;
            }
            break;
        }
        temp = temp->next;
    }
}

int main() {
    int n, x;
    string s;
    cin >> n;
    while (n--) {
        cin >> s;
        if (s == "insert") {
            cin >> x;
            insert(x);
        }
        if (s == "delete") {
            cin >> x;
            _delete(x);
        }
        if (s == "deleteFirst") {
            deleteFirst();
        }
        if (s == "deleteLast") {
            deleteLast();
        }
    }

    while (head != NULL) {
        cout << head->key;
        if (head != tail)
            cout << " ";
        head = head->next;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 37516
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <climits>
using namespace std;

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

  if(a < 10 && b < 10){
    cout << a*b << endl;
  }else{
    cout << "-1" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();

        // f(0, A-1) xor f(0, B)と同じ
        long tmp1 = func(A-1);
        long tmp2 = func(B);

        out.println(tmp1^tmp2);
    }

    public static long func(long x) {

        // 偶数nと偶数n+1の排他的論理和は1
        // (0 xor 1) xor (2 xor 3) ... xor ... (2n xor 2n+1) xor 2n+2
        //  = 1 xor 1 xor ... xor ... 1 xor n+2

        int oneNum = (int) ((x + 1) / 2);

        if(oneNum % 2 == 0){
            if(x % 2 == 0) {
                return x;
            } else {
                return 0;
            }
        } else {
            if(x % 2 == 0) {
                return 1^x;
            } else {
                return 1;
            }
        }
    }

}


Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

typedef __int128_t ull;
const ull h = 92709568269121;
const ull B = 912121313;
int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  //x -> y
  //(x-y)回の操作
  //見る範囲 0 ~ (x-y)にyの先頭があり、残りが末尾で一致している
  vector<string> v(n);
  re(i,n) std::cin >> v[i];
  sort(all(v), [](string a, string b){return a.size() < b.size();});
  ll ans = 0;
  // hash -> num

  map<ull, ll> mp;
  for(int i=0;i<n;i++){
    ull ret = 0;
    ll m = v[i].size();
    vector<ll> ok(m+1, 0);
    for(int j=0;j<m;j++){
      ll now = j+1;
      ll num = v[i][j] - 'a';
      ok[now] = ok[now-1]|(1<<num);
    }
    //iより左にjが存在するか
    for(int j=m;j>=0;j--){
      if(j==m){
        //26種類
        for(int k=0;k<26;k++){
          if((ok[j]>>k)&1){
            ull ad = 'a' + k;
            //付け加えたもの
            ull tmp = ((ret*B)%h + ad)%h;
            auto itr = mp.find(tmp);
            if(itr!=mp.end()) ans += (*itr).second;
          }
        }
        continue;
      }
      
      ull num = v[i][j];
      ret = ((ret * B)%h + num)%h;

      for(int k=0;k<26;k++){
        if((ok[j]>>k)&1){
          //付け加えたもの
          ull ad = 'a' + k;
          ull tmp = ((ret*B)%h + ad)%h;
          auto itr = mp.find(tmp);
          if(itr!=mp.end()) ans += (*itr).second;
        }
      }
    }
    auto itr = mp.find(ret);
    if(itr==mp.end()) mp.emplace(ret, 1);
    else (*itr).second++;
  }

  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 23036
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fir first
#define sec second
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

ll a, b, c, d;

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

ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}

ll antidiv(ll a){
	return a - (a / c + a / d - (a / lcm(c,d)));
}

int main(){
	cin >> a >> b >> c >> d;
	cout << antidiv(b) - antidiv(a-1) << endl;
	return 0;
}


Measured memory_bytes: 256
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));
 
$n = (int)$input[0];
$m = (int)$input[1];
 
$input = explode(' ', trim(fgets(STDIN)));
$as = [];
foreach ($input as $v) {
	$as[] = (int)$v;
}
sort($as);

$cmds = [];
for ($i=0; $i < $m; $i++) { 
	$input = explode(' ', trim(fgets(STDIN)));
	$b = (int)$input[0];
	$c = (int)$input[1];
	if (isset($cmds[$c])) {
		$cmds[$c] += $b;
	}else{
		$cmds[$c] = $b;
	}
}
krsort($cmds);

$sum = 0;
$n_idx = 0;
$end_flg = false;
foreach ($cmds as $c => $b) {
	$limit = min($n, $n_idx + $b);
	for ($j=$n_idx; $j < $limit; $j++) { 
		++$n_idx;
		$sum += max($as[$j], $c);
		if ($as[$j] >= $c) {
			$end_flg = true;
			break;
		}
	}
	if ($end_flg) {
		break;
	}
}
for ($i=$n_idx; $i < $n; $i++) { 
	$sum += $as[$i];
}
echo $sum;

Measured memory_bytes: 19184
// AtCoder ABC136: C - Build Stairs
// 2019.8.26 bal4u

#include <stdio.h>

//// 高速入力
#define gc() getchar_unlocked()

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int main()
{
	int h, ph, N;
	
	ph = 0;
	N = in(); while (N--) {
		h = in();
		if (ph < h) h--;
		if (ph > h) { puts("No"); return 0; }
		ph = h;
	}
	puts("Yes");
	return 0;
}

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

signed main() {
    string s, ans;
    cin >> s;

    ans = "Yes\n";
    for ( int i = 0; i < s.size(); i++ ) {
        if ( i % 2 == 0 && s[i] == 'L' ) {
            ans = "No\n";
        } 
        else if ( i % 2 == 1 && s[i] == 'R' ) {
            ans = "No\n";
        }
    }    
    
    cout << ans;
    return (0);
}

Measured memory_bytes: 3596
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=2e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
int dp[120][120];
int a[120];	
int k;
int dfs(int pos,int sta,int lead,int limit){
	if(pos == -1) return sta == k;
	if(!lead&&!limit&&dp[pos][sta]!=-1) return dp[pos][sta];
	int up = limit?a[pos]:9;
	int tmp = 0;
	for(int i = 0;i <= up;++i){
		if(lead&&i == 0) tmp += dfs(pos - 1,sta,lead,limit&&i == a[pos]);
		else tmp += dfs(pos-1,sta + (i == 0?0:1),0,limit&&i == a[pos]);
	}
	if(!limit&&!lead) dp[pos][sta] = tmp;
	return tmp;
}
int main(){
	string s;
	cin >> s>>k;
	int l = s.size();
	int pos = 0;
	memset(dp,-1,sizeof dp);
	for(int i = l-1;i >= 0;-- i){
		a[pos++] = s[i] - '0';
	}
	cout <<	dfs(pos-1,0,1,1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())

char itoc(int i){
  string s = "zabcdefghijklmnopqrstuvwxy";
  return s.at(i);
}

int main()
{
    int n;
    cin >> n;
    
    if(n%1000==0) cout << 0 << endl;
    else cout << (1000-n%1000) << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
//---------------------------------------------------
//library zone!!!!!
typedef long long ll;
typedef long double ld;
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld mod_pow(ld x, ll n, ll p) {
	ld res = 1;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='9') s[i]='1';
		else s[i]='9';
	}
	cout<<s<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int[][] red = new int[N][2];
    int[][] blue = new int[N][2];

    for (int i = 0; i < N; i++){
      red[i][0] = scanner.nextInt();
      red[i][1] = scanner.nextInt();
    }
    for (int i = 0; i < N; i++){
      blue[i][0] = scanner.nextInt();
      blue[i][1] = scanner.nextInt();
    }
    int count = 0;
    boolean[] visited = new boolean[N];

    Arrays.sort(blue, Comparator.comparingInt(o1 -> o1[0]));
    Arrays.sort(red, Comparator.comparingInt(o1 -> -o1[1]));

    for (int i = 0; i < N; i++){
      for (int j = 0; j < N; j++){
        if (!visited[j] && blue[i][0] > red[j][0] && blue[i][1] > red[j][1]){
          count++;
          visited[j] = true;
          break;
        }
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 28756
#include <stdio.h>

int main( void )
{
	int H, W, H_Cou, W_Cou;
	
	while(1)
	{
		scanf( "%d %d", &H, &W );
		
		if( H == 0 && W == 0 )
		{
			break;
		}
		else
		{
			for( H_Cou = 0; H_Cou < H; H_Cou++ )
			{
				if( H_Cou == 0 || H_Cou == H - 1 )
				{
					for( W_Cou = 0; W_Cou < W; W_Cou++ )
					{
						printf( "#" );
					}
				}
				else
				{
					for( W_Cou = 0; W_Cou < W; W_Cou++ )
					{
						if( W_Cou == 0 || W_Cou == W - 1 )
						{
							printf( "#" );
						}
						else
						{
							printf( "." );
						}
					}
				}
				printf( "\n" );
			}
			printf( "\n" );
		}
	}
	return 0;
}

Measured memory_bytes: 572
/* Author: topcoderme123
   Date: 5th july 
*/

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define np next_permutation
using namespace std;
using vi=vector<int>;
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define vii vector<vi>
#define vb vector<bool>
#define pr pair<int,int>
#define vl vector<ll>
#define vs vector<string>
#define us unordered_map<int,int>
#define Mpq priority_queue<int>
#define mpq priority_queue<int,vi,greater<int>> 
#define eb emplace_back
#define prl pair<ll,ll>
#define vp vector<pr>
#define inf 1000000000000000008
#define ld long double
const int N=(int)1e6+11;

int h,w,k,ans;

char g[10][10];

void solve(){
   cin>>h>>w>>k;
   lp(i,h) lp(j,w) cin>>g[i][j];

   for(int i=0;i<(1<<h);i++){
     us rows;
     if(i>0) for(int k=0;k<=log2(i);k++) if(i&(1<<k)) rows[k]++;

     for(int j=0;j<(1<<w);j++){
        us cols;
        if(j>0) for(int k=0;k<=log2(j);k++) if(j&(1<<k)) cols[k]++;

        int cnt=0;
        for(int p=0;p<h;p++){
          for(int q=0;q<w;q++){
             if(g[p][q]=='#' and rows.find(p)==rows.end() and cols.find(q)==cols.end())
                cnt++;
          }
        }
        if(cnt==k) ans++;
     }
   }
   cout<<ans<<"\n";
}

int main(){
   ios_base::sync_with_stdio(0);
   cin.tie(nullptr);

   //assert(freopen("input.txt", "r", stdin));
   //assert(freopen("output.txt", "w", stdout));   

   solve();
   return 0;   	
}



Measured memory_bytes: 3708