akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	// 連続した部分文字列がkの長さをもつとすると
	// aa
	// a*a
	// のどちらかしか存在しない。このパターンを使わないということはa**a**q...と繰り返すことになるがこの方法では条件をみたすことはないからである
	// テスト
	// asdfghjklaa : 最後だけ
	// faewasdfala
	// qwertyuioaa
	// aaqwertyuiop:最初
	static String line;

	static int N;
	public static void main(String args[]) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		line = br.readLine();
		String text[] = line.split("");
		N = text.length;
		method(text);
	}

	static void method(String text[]) {

		for (int i = 0; i < text.length - 2; i++) {
			if (text[i].equals(text[i + 2])) {
//				i++;
				System.out.println(i + " " + (i + 2));
				return;
			}
		}

		for (int i = 0; i < text.length - 1; i++) {
			if (text[i].equals(text[i + 1])) {
//				i++;
				System.out.println(i + " " + (i + 1));
				return;
			}
		}

		System.out.println("-1 -1");
	}
}


Measured memory_bytes: 23204
#!/usr/bin/env python

def main():
    s = input() + "#"
    t = input()
    m = len(s)
    n = len(t)

    c_max = 0
    for i in range(m-n):
        cnt = 0
        for j in range(n):
            if s[i+j] == t[j]:
                cnt += 1
        if cnt > c_max:
            c_max = cnt

    print(n - c_max)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >>K;
  
  int X = 1;
  for(int i = 0; i < N; i++){
  	if(X*2 < X+K){
    	X *= 2;
    }else{
    	X += K;
    }
  }
  cout << X << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N,M;
    cin >> N >> M;
    ll ans=N;
    ll i;
    ll a;
    for(i=0;i<M;i++){
        cin >> a;
        ans-=a;
    }
    cout << max((ll)-1,ans)<<endl;
    return 0;
}


Measured memory_bytes: 3164
n = int(input())
a = list(map(int,input().split())) + [0]
i = 0
tmp = 0
ans = 0
while i+1 <= n:
    #print(a[i],tmp,ans)
    if a[i] >= a[i+1]:
        tmp += 1
        if i + 1 == n:
            tmp -= 1
    else:
        ans = max(ans,tmp)
        tmp = 0
    i += 1
ans = max(ans,tmp)
print(ans)


Measured memory_bytes: 15020
fun main(args: Array<String>) {
    val (A,B,C,D) = readLine()!!.split(" ").map{ i -> i.toInt() }
    var result = 0;
    if(B<=C || D<=A) {result = 0}
    else if(A<=C && D<=B) {result = Math.abs(C - D)} 
    else if(C<=A && B<=D) {result = Math.abs(A - B)}
    else if(A>=C && D<=B) {result = Math.abs(A - D)} 
    else if(C>=A && B<=D) {result = Math.abs(C - B)} 
    println(result)
}

Measured memory_bytes: 37816
#include <float.h>
#include <math.h>
#include <stdio.h>

#include <iostream>
#include <vector>
#include <algorithm>

typedef struct {
  float x,y,z,r;
} Cell;

int main(void)
{
  while (1) {
    int n,i;
    Cell v[100];
    int vlen=0;
    float G [100][100];
    for (int i=0;i<100;++i)
      for(int j=0;j<100;++j)
	G[i][j]=FLT_MAX;
     
    scanf("%d",&n);
    if( n==0 )
      break;
   
    for(i=0;i<n;++i){ 
      float x,y,z,r;
      scanf("%f %f %f %f",&x,&y,&z,&r);
      for(int j=0; j<vlen; ++j){
	float dx = x - v[j].x;
	float dy = y - v[j].y;
	float dz = z - v[j].z;
	float d = sqrt(dx*dx + dy*dy + dz*dz) - (v[j].r + r);
	if (d<=0){
	  G[i][j] = 0.0;
	  G[j][i] = 0.0;
	} else {
	  G[i][j] = d;
	  G[j][i] = d;
	}	
      }

      Cell const c = { x, y, z, r };
      v[vlen] = c;
      ++vlen;
    }
    float sum = 0.0;
    float d[100];
    bool visited[100];
    std::fill( d, d+100, FLT_MAX );
    std::fill( visited, visited+100, false );

    //initialize
    int u = 0;
    d[0] = 0;

    for( int i=0; i<n; ++i ) {
      float tmp = FLT_MAX;
      for( int j=0; j<n; ++j ) {
	if ( !visited[j] && d[j] < tmp ) {
	  tmp = d[j];
	  u = j;
	}
      }
      sum += d[u];
      visited[u] = true;

      for(int j=0; j<n; ++j ) {
	if ( !visited[j] && G[u][j] < d[j] ) {
	  d[j] = G[u][j];
	}
      }
    }
    printf( "%.3lf\n", sum );
  }
}

Measured memory_bytes: 0
a=[]
for i in range(3):
  da=list(map(int,input().split()))
  for j in da:
    a.append(j)
n=int(input())
for i in range (n):
  b=int(input())
  for j in range(len(a)):
    if a[j] == b:
      a[j]=0

for i in range (3):
  if a[i] == a[i+3] and a[i+3]==a[i+6]:
    print('Yes')
    exit()
for i in range(3):
  if a[3*i]==a[3*i+1] and a[3*i]==a[3*i+2]:
    print('Yes')
    exit() 
if a[0]==a[4] and a[0]==a[8]:
  print('Yes')
  exit()

if a[2]==a[4] and a[2]==a[6]:
  print('Yes')
  exit()
print('No')

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

using namespace std;

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

    if(s.length()<=k)cout<< s<<endl;
    else{
        for(int i=0;i<k;i++)cout<<s[i];
        cout<<"..."<<endl;
    }


    return 0;
}

Measured memory_bytes: 3156
#include <stdio.h>
#include <string.h>
int main(){
  int a, b;

  scanf("%d%d", &a, &b);

  if(a > b){
    printf("%d", a + a -1);
  }else if(a == b){
    printf("%d", a + b);
  }else{
    printf("%d", b + b - 1);
  }

  printf("\n");
  
}



Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

// read to vector
// for example M_RTV(as, int, n) expands to the below:
// ```
// vector<int> as(n);
// for(int lcnt = 0; lcnt < n; lcnt++) cin >> as[lcnt];
// ```
#define M_RTV(ident, type, cnt) \
    do {\
        vector<type> ident(cnt);\
        for(int lcnt = 0; lcnt < cnt; lcnt++) cin >> ident[lcnt];\
    } while(false)

// shorthand for range
#define M_RG(ident) ident.begin(), ident.end()

// https://qiita.com/EqualL2/items/b4683db7ab4e90545bb2
int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}

int main() {
    int n, r;
    cin >> n >> r;
    if (n < 10) r += 100*(10-n);
    cout << r << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> pii;
using namespace std;
using ll = long long;
#define PI 3.14159265358979323846264338327950L
const int mod = 1000000007;


struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};




void solve(){
    string s; int k;
    cin >> k >> s;
    int n = s.size();
    mint ans = 0;
    
    combination c(n+k);
    
    for(int i = 0; i <= k; i++){
        mint add = mint(26).pow(i);
        add *= mint(25).pow(k-i);
        add *= c(n+k-i-1,n-1);
        ans += add;
    }
    
    cout << ans;
}



int main(){
    solve();
}




Measured memory_bytes: 35660
N = input()
K = int(input())
m = len(N)
dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(m + 1)]
dp[0][0][0] = 1 #[i][j][k] i桁目まで決める　N未満で確定でj=1 0でない数がk個

for i in range(1, m + 1):
    l = int(N[i - 1])
    for k in range(K + 1): # 0でない数の個数 k を変化させていく
        if k -1 >= 0:
            if l != 0: #i桁目 1～9
                dp[i][0][k] = dp[i - 1][0][k-1]
                dp[i][1][k] = dp[i - 1][1][k] + 9*dp[i - 1][1][k-1] + dp[i - 1][0][k] + (l-1)*dp[i - 1][0][k-1]
            else: #i桁目 0
                dp[i][0][k] = dp[i - 1][0][k]
                dp[i][1][k] = dp[i - 1][1][k] + 9*dp[i - 1][1][k-1]
        else: #すべての数が0ではない場合
            dp[i][0][k] = 0 # i桁目　Nと一致　すべてが0　→　該当なし　0コ
            dp[i][1][k] = 1 # i桁目　N未満　  すべてが0  →　0のみ　  1コ

#print(dp)
print(dp[m][0][K] + dp[m][1][K])

Measured memory_bytes: 9224
import java.util.*;class Main{public static void main(String[]z){Map<Integer,Integer>m=new TreeMap<Integer, Integer>();int t;for(Scanner s=new Scanner(System.in);s.hasNext();)m.put(t=s.nextInt(),m.containsKey(t)?m.get(t)+1:1);for(int i:m.keySet())if(m.get(i)==Collections.max(m.values()))System.out.println(i);}}

Measured memory_bytes: 12000
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
long long int  m,t;
long long int a[200005];
int main()
{
	cin >> t;
	for (int i = 1; i <= t; i++)
	{
		cin >> a[i];
	}
	sort(a + 1, a + 1 + t);
	m = a[t];
	int j = t - 1;
	for (int i = (t - 2) / 2; i > 0; i--)
	{
		m += 2 * a[j--];
	}

	if (t % 2 == 1)
	{
		m += a[j];
	}
		
	cout << m;
}

Measured memory_bytes: 5152
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

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

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        Scanner sc = new Scanner(is);
        int p[]  = new int[5];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextInt();
        }
        int k = sc.nextInt();
        for (int i = 0; i < p.length; i++) {
            for (int j = 0; j < p.length; j++) {
                if (Math.abs(p[j] - p[i]) > k) {
                    os.println(":(");
                    return;
                }
            }
        }
        os.println("Yay!");
    }
}

Measured memory_bytes: 21844
from collections import Counter, defaultdict, deque
import itertools 
import bisect
from sys import stdin, stdout
from itertools import repeat
import sys


# sys.stdin = open('input')
# sys.stdout = open('/mnt/d/Gg/output', 'w')
# n, k = map(int, raw_input().split())
# da = map(int, raw_input().split())
# db = map(int, raw_input().split())




def main():
    n, a, b, c = map(int, raw_input().split())
    da = [a, b, c]
    ans = []
    query = []
    for i in range(n):
        query.append(raw_input().strip())
    
    def get(idx, x, y):
        if da[x]+da[y]==0:
            return
        if da[x]==1 and da[y]==1 and idx < n-1:
            if query[idx][0] not in query[idx+1]:
                ans.append(query[idx][1])
                da[x] -= 1
                da[y] += 1
            else:
                ans.append(query[idx][0])
                da[y] -= 1
                da[x] += 1
            return
        if da[x]>da[y]:
            ans.append(query[idx][1])
            da[y] += 1
            da[x] -= 1 
        else:
            ans.append(query[idx][0])
            da[y] -= 1
            da[x] += 1 

    for i in range(n):
        if query[i] == 'AB':
            get(i, 0, 1)
        elif query[i] == 'AC':
            get(i, 0, 2)
        else:
            get(i, 1, 2)
    if len(ans) < n:
        print "No"
    else:
        print "Yes"
        print '\n'.join(ans)

    
# import time
# pre = time.time()
main()



Measured memory_bytes: 89804
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main(){

  int n, k;
  cin >> n >> k;
  int ans = 1;
  for (int i = 0; i < n; i++){
    ans = min(ans * 2, ans + k);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)


int main(){
    int n, k, q; cin >> n >> k >> q;
    vector<int> v(n);
    rep(i,n) v[i] = k;
    vector<int> p(q);
    rep(i, q) cin >> p[i];
    rep(i, q){
        v[p[i]-1]++;
    }
    rep(i,n){
        v[i] -= q;
    }
    for(int x : v){
        if(x <= 0){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }

}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define rep(i,n) for (int i = 0; i < n; ++i) 
#define REP(i,k,n) for (int i = k; i <= n; ++i) 
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl
#define sz(a) int((a).size())
#define endl '\n' // remove for interactive

const int N = 1e5 + 5;
int dp[N][3];

int main()
{
    ios_base::sync_with_stdio(0); //cant use scanf, printf
    cin.tie(0);cout.tie(0); // no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); // no scientific output
    int n; cin>>n;
    vi a,b,c;
    rep(i, n)
    {
        int x, y, z; cin>>x>>y>>z;
        a.pb(x);b.pb(y);c.pb(z);
    }
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    REP(i, 1, n-1)
    {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
    }
    cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}



/*before sub
loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
*/

Measured memory_bytes: 2924
use std::io::Read;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let c: usize = itr.next().unwrap().parse().unwrap();

    let mut cumsum: Vec<Vec<i64>> = vec![vec![0; 100010]; c + 1];
    for _ in 0..n {
        let s: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let t: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let c: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        cumsum[c][s] += 1;
        cumsum[c][t + 1] -= 1;
    }
    for i in 0..c {
        for j in 0..100005 {
            cumsum[i][j + 1] += cumsum[i][j];
        }
    }

    let mut ans: i64 = 0;
    for i in 0..100005 {
        let mut cnt: i64 = 0;
        for j in 0..c {
            if cumsum[j][i] > 0 {
                cnt += 1;
            }
        }
        ans = std::cmp::max(ans, cnt);
    }
    println!("{}", ans);
}


Measured memory_bytes: 37116
import math
from functools import reduce

K = int(input())

ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        ab = math.gcd(a, b)
        for c in range(1, K + 1):
            abc = math.gcd(ab, c)
            ans += abc

print(ans)

Measured memory_bytes: 9584
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define REP(n) FOR(i,n)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define ntuples(type1,type2,type3,v,n) vector<tuple<type1,type2,type3>> v(n);for(size_t i=0;i<(n);i++){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

int main() {
  int n;
  string s,t;
  cin>>n>>s>>t;
  for (int i = 0; i < n; i++) {
    cout<<s[i]<<t[i];
  }
}

Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const A = arg[1].split(" ").map(n=>parseInt(n));
    
    let limit = [];
    
    for(let i in A) {
        let cnt = 0;
        
        while(A[i] % 2 === 0 || A[i] === 0) {
            A[i] /= 2;
            cnt++;
        }
        
        limit.push(cnt);
        cnt = 0;
    }
    
    console.log(limit.reduce((m,n)=>m+n));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 22344
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>
#include <map>


using namespace std;

int main(int argc, const char * argv[]) {
  int n;
  cin >> n;
  vector<long long> a(n),b(n),c(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n; i++){
    cin >> b[i];
  }
  for(int i = 0; i < n; i++){
    cin >> c[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  long long ans = 0;
  for(int i = 0; i < n; i++){
    auto it1 = lower_bound(a.begin(), a.end(), b[i]);
    auto it2 = upper_bound(c.begin(), c.end(), b[i]);
    long long a_index = it1 - a.begin();
    long long c_index = it2 - c.begin();
    ans += a_index * (n-c_index);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
x,y=map(int,input().split())

def ju(i,j):
    if i%j==0:
        d=j
    else:
        a=i
        b=j
        c=a%b
        while c>0:
            a=b
            b=c
            c=a%b
            if c==0:
                d=b
                break
    return d

if x>=y:
    print(ju(x,y))
else:
    print(ju(y,x))


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
template <class T1, class T2>void print(T1 a[], T2 n) { for (T2 i = 0; i < n; i++) { cout << a[i] << " ";} cout << endl;}
template <class T1, class T2>void print(vector<T1> a, T2 n) { for (T2 i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl;}
ll modexpo(ll a, ll b, ll m) {if (b == 0) {return 1;} else if (a == 1) {return 1;} if (b % 2 == 0) {ll t = modexpo(a, b / 2, m); t = (t * t) % m; return t;} else {ll t = modexpo(a, b / 2, m); t = (t * t) % m; t = (t * a) % m; return t;}}




int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int k, a, b;
	cin >> k >> a >> b;

	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK\n";
			return 0;
		}
	}
	cout << "NG\n";
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define INF 1000000000000000
#define fi first
#define se second
#define all(v) v.begin(),v.end()
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
int kaijo(int n){
	int ans=1;
	for(int i=2;i<=n;i++){
		ans*=i;
		ans%=MOD;
	}
	return ans;
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int comb(int a,int b){
	return kaijo(a)*modpow(kaijo(a-b),MOD-2)%MOD*modpow(kaijo(b),MOD-2)%MOD;
}
int n,k,r[2222][2222],ans;
signed main(){
	cin>>n>>k;
	rep(i,n){
		int a,b;
		char c;
		cin>>a>>b>>c;
		if(c=='B')a+=k;
		a%=(2*k),b%=(2*k);
		a++,b++;
		r[a][b]++;
	}
	rep(i,2*k){
		rep(j,2*k){
			r[i+1][j+1]+=r[i][j+1]+r[i+1][j]-r[i][j];
		}
	}
	int a,b,c,d,e;
	int kk=2*k;
	rep(i,k+1){
		rep(j,k+1){
			a=r[i][j];
			b=r[i+k][j+k]-r[i+k][j]-r[i][j+k]+r[i][j];
			c=r[kk][j]-r[i+k][j];
			d=r[i][kk]-r[i][j+k];
			e=r[kk][kk]-r[kk][j+k]-r[i+k][kk]+r[i+k][j+k];
			int s=a+b+c+d+e;
			ans=max({ans,s,n-s});
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 35072
a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())

if a>b:
  v = -v
  w = -w
  if b - v*t >= a - w*t:
    print('YES')
  else:
    print('NO')
else:
  if b - v*t <= a - w*t:
    print('YES')
  else:
    print('NO')

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

bool ask(int a, int b) {
	cout << "? " <<  a << " " << b << endl;
	char ans;
	cin >> ans;
	return ans == 'Y';
}


int main(void) {
	int a, b;
	cin >> a >> b;
	const int n = a + b;


	if (a <= b) {
		puts("Impossible");
		return 0;
	}

	int need = b + 1;
	vector<int> path;

	rep(i, n) {
		if (path.empty()) {
			path.push_back(i);
			if (path.size() >= need) break;
		} else {
			bool ret = ask(i, path.back());
			if (ret) {
				path.push_back(i);
			} else {
				path.pop_back();
				need--;
			}
			if (path.size() >= need) break;
		}
	}

	int honest = path[0];
	string ans = string(n, '1');

	rep(i, n) {
		if (i == honest) continue;
		if (ask(honest, i) == 0) ans[i] = '0';
	}

	cout << "! " << ans << endl;


	return 0;
}

Measured memory_bytes: 848
#include"stdio.h"
#define nmax 1000000
int ans[nmax];
bool is_prime[nmax + 1];

void sieve(int n) {
	int p = 0;
	for (int i = 0; i <= n; i++)is_prime[i] = true;
	is_prime[0] = is_prime[1] = 0;
	ans[0] = ans[1] = 0;
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) {
			p++;
			for (int j = 2 * i; j <= n; j += i)is_prime[j] = false;
		}
		ans[i] = p;
	}
}
int main()
{
	sieve(nmax);
	int n,m=0;
	for (; scanf("%d", &n) == 1;) {
		printf("%d\n", ans[n]);
	}
	return 0;
}


Measured memory_bytes: 7568
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int k;
	cin >> k;
	vector<int> v(k, 0);
	int r = 0;
	for (int i = 1;; i++) {
		r = r * 10 + 7;
		r %= k;
		if (r == 0) {
			cout << i << endl;
			return 0;
		}
		if (v[r] == 1) {
			cout << -1 << endl;
			return 0;
		}
		v[r] = 1;
	}
}


Measured memory_bytes: 7212
#![allow(unused_imports)]

use text_io::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    let mut a:String = read!();
    let vv:Vec<char> = a.chars().collect_vec();
    let mut v:Vec<isize> = Vec::new();
    for i in 0..vv.len() {
        if vv[i]=='0' {v.push(0) }
        if vv[i]=='1' {v.push(1) }
        if vv[i]=='2' {v.push(2) }
        if vv[i]=='3' {v.push(3) }
        if vv[i]=='4' {v.push(4) }
        if vv[i]=='5' {v.push(5) }
        if vv[i]=='6' {v.push(6) }
        if vv[i]=='7' {v.push(7) }
        if vv[i]=='8' {v.push(8) }
        if vv[i]=='9' {v.push(9) }
    }
    if v[0]+v[1]+v[2]+v[3]==7 {println!("{}+{}+{}+{}=7",v[0],v[1],v[2],v[3]) }
    else if v[0]+v[1]+v[2]-v[3]==7 {println!("{}+{}+{}-{}=7",v[0],v[1],v[2],v[3]) }
    else if v[0]+v[1]-v[2]+v[3]==7 {println!("{}+{}-{}+{}=7",v[0],v[1],v[2],v[3]) }
    else if v[0]+v[1]-v[2]-v[3]==7 {println!("{}+{}-{}-{}=7",v[0],v[1],v[2],v[3]) }
    else if v[0]-v[1]+v[2]+v[3]==7 {println!("{}-{}+{}+{}=7",v[0],v[1],v[2],v[3]) }
    else if v[0]-v[1]+v[2]-v[3]==7 {println!("{}-{}+{}-{}=7",v[0],v[1],v[2],v[3]) }
    else if v[0]-v[1]-v[2]+v[3]==7 {println!("{}-{}-{}+{}=7",v[0],v[1],v[2],v[3]) }
    else if v[0]-v[1]-v[2]-v[3]==7 {println!("{}-{}-{}-{}=7",v[0],v[1],v[2],v[3]) }
}

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

int main() {
  int L;
  cin >> L;
  double M=1;
  for(int i=0; i<3; i++){
    M *= L;
  }
  M /= 27;
  printf("%.16f", M);
  //cout << M << endl;
  
}


// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));
 
  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
   // }
  //}


Measured memory_bytes: 256
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;

int a[maxn];
vector<int>e[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n,m;
  cin>>n>>m;
  for(int i=1;i<=n;i++)cin>>a[i];
  for(int i=1;i<=m;i++){
    int x,y;
    cin>>x>>y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  int ret = 0;
  for(int i=1;i<=n;i++){
    int mx = 0;
    for(int j=0;j<e[i].size();j++){
      int v = e[i][j];
      mx = max(mx, a[v]);
    }
    if(mx<a[i])ret++;
  }
  cout<<ret<<endl;
  return 0;
}

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

signed main() {
  int H, W; cin >> H >> W;
  char a[100][100], b[102][102];
  for(int i = 0; i < H; i++) {
    cin >> a[i];
  }

  // '#'で予め埋めておく
  for(int i = 0; i < H+2; i++) {
    for(int j = 0; j < W+2; j++) {
      b[i][j] = '#';
    }
  }
  // a の要素を b へコピーする
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      b[i+1][j+1] = a[i][j];
    }
  }

  for(int i = 0; i < H+2; i++) {
    for(int j = 0; j < W+2; j++) {
      cout << b[i][j];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import * as fs from "fs";
 
let input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
var n = parseInt(input[0]);
var k = parseInt(input[1]);
var x = parseInt(input[2]);
var y = parseInt(input[3]);
var result = 0;
if (n <= k) {
    result = x * n;
} else { 
    result = x * k + y * (n - k)
};

console.log(result);




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

ans = 0
for i in range(n):
    for j in range(i,n):
        for k in range(j,n):
            if i != j and (j != k and k != i):
                if l[i] != l[j] and (l[j] != l[k] and l[k] != l[i]):  
                    abc = []
                    abc.append(l[i])
                    abc.append(l[j])
                    abc.append(l[k])
                    abc.sort()
                    if abc[0] + abc[1] > abc[2]:
                        ans += 1
print(ans)

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

typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

vector<pair<ll ,int> > factorize(ll n) {
  vector<pair<ll ,int> > res;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i) continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n, 1);
  return res;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll g = __gcd(a, b);
  auto f = factorize(g);
  int ans = f.size() + 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
using namespace std;
int f(int a, int b) {
	if (b < 10)return a * 10 + b;
	if (b < 100)return a * 100 + b;
	if (b < 1000)return a * 1000 + b;
	if (b < 10000)return a * 10000 + b;
	if (b < 100000)return a * 100000 + b;
}
signed main() {
	int n, a[12345]; vector<int>v;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	for (int i = 0; i < min((int)4, n); i++) {
		for (int j = 0; j < min((int)4, n); j++) {
			if (i != j)v.push_back(f(a[i], a[j]));
		}
	}
	sort(v.begin(), v.end());
	cout << v[2] << endl;
}


Measured memory_bytes: 3172
N = int(input())
t = []
x = []
y = []
for i in range(N):
    ti, xi, yi = map(int, input().split())
    t.append(ti)
    x.append(xi)
    y.append(yi)

t.append(0)
x.append(0)
y.append(0)

for i in range(N):
    if t[i] >= x[i] + y[i]:
        if t[i] % 2 == (x[i] + y[i]) % 2:
            t[i + 1] -= t[i]
            x[i + 1] -= x[i]
            y[i + 1] -= y[i]
        else:
            print('No')
            quit()
            #break
    else:
        print('No')
        quit()
        #break
print('Yes')

Measured memory_bytes: 11764
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,c,k;
	cin>>a>>b>>c>>k;
	if(a>=k) cout<<k;
	else{
		if(b>=k-a) cout<<a;
		else
			cout<<a-(k-a-b);
	}
	return 0;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define REPS(i,n) for(int i=1;i<=(n);i++)
#define RREPS(i,n) for(int i=(n);i>0;i--)
#define mp make_pair
#define pb(a) push_back(a)
#define VSORT(v) sort(v.begin(), v.end());
typedef long long ll;
int A[100002];
int main(){
    int N;
    cin >> N;
    int sum = 0;
    A[0] = 0;
    A[N+1] = 0;
    REPS(i,N){
        cin >> A[i];
        sum += abs(A[i] - A[i-1]);
    }
    sum += abs(A[N+1] - A[N]);
    REPS(i,N){
        int ans = sum;
        ans += abs(A[i+1]-A[i-1]);
        ans -= abs(A[i] - A[i-1]);
        ans -= abs(A[i+1] - A[i]);
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

long double memo[3111][3111];

int main ()
{
    int n;
    cin >> n;
    double p;
    memo[0][0] = 1;
    for (int i = 0 ; i < n ; i++)
    {
        cin >> p;
        for (int j = 0 ; j < n ; j++)
        {
            memo[i + 1][j] += memo[i][j] * (1 - p);
            memo[i + 1][j + 1] += memo[i][j] * p;
        }
    }
    long double s = 0;
    for (int i = (n + 1) / 2 ; i <= n ; i++)
    {
        s += memo[n][i];
    }
    cout << fixed << setprecision(10) << s;
}


Measured memory_bytes: 147712
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;

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

    int k; cin >> k;
    int i = 1;
    int cur = 7;
    while(i <= k){
        if(cur % k == 0) break;
        cur = cur * 10 + 7;
        cur %= k;
        i++;
    }
    if(i <= k)cout << i << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 3644
#include <stdlib.h>
#include <vector>

class lowest_common_ancestor {
	std::vector<std::vector<size_t>> g, parent;
	std::vector<size_t> depth;
	
	const size_t logN = 20;

	private:
	void dfs(size_t v, int par = -1, size_t d = 0) {
		parent[0][v] = par;
		depth[v] = d;
		
		for(auto e:g[v]) {
			if(e == par) continue;
			
			dfs(e, v, d + 1);
		}
	}
	void build() {
		dfs(0);
		
		for(int k = 0; k < logN - 1; k++) {
			for(int i = 0; i < g.size(); i++) {
				if(parent[k][i] == -1) parent[k + 1][i] = -1;
				else parent[k + 1][i] = parent[k][parent[k][i]];
			}
		}
	}

	public:
	lowest_common_ancestor() {}
	lowest_common_ancestor(int n) : g(n), depth(n) {
		parent.assign(logN, std::vector<size_t>(n, -1));
	}
	void add_edge(const size_t & u, const size_t & v) {
		g[u].push_back(v);
		g[v].push_back(u);
	}
	const size_t query(size_t u, size_t v) {
		static bool built = false;
		if(!built) {
			build();
			built = true;
		}

		if(depth[u] > depth[v]) std::swap(u, v);
		for(int k = 0; k < logN; k++) {
			if(((depth[v] - depth[u]) >> k) & 1) v = parent[k][v];
		}
		if(u == v) return u;

		for(int k = logN - 1; k >= 0; k--) {
			if(parent[k][u] == parent[k][v]) continue;

			u = parent[k][u];
			v = parent[k][v];			
		}		
		return parent[0][u];
	}
};

#include <stdio.h>

int main() {
	int n; scanf("%d", &n);
	lowest_common_ancestor lca(n);
	for(int i = 0; i < n; i++) {
		int k; scanf("%d", &k);

		while(k--) {
			int p; scanf("%d", &p);

			lca.add_edge(i, p);
		}
	}

	int q; scanf("%d", &q);
	while(q--) {
		int x, y; scanf("%d%d", &x, &y);

		printf("%d\n", lca.query(x, y));
	}
}



Measured memory_bytes: 27848
#include <bits/stdc++.h>
using namespace std;
int n;
int x[10], y[10];
double dis(int i, int j) {
    double dx=x[i]-x[j];
    double dy=y[i]-y[j];
    return pow(dx*dx+dy*dy,0.5);
}
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) cin>>x[i]>>y[i];
    double ans=0.0;
    for(int i=1;i<=n;i++)
	{ 
        for(int j=i+1;j<=n;j++) ans+=dis(i,j)*2/n;
    }
    cout<<fixed<<setprecision(10)<<ans<<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;
using ll = long long;

int main() {
    int N, M, C;
    cin >> N >> M >> C;
    vector<int> B(M);
    rep(i, M) cin >> B[i];
    int ans = 0;
    rep(i, N) {
        int tmp = C;
        rep(j, M) {
            int A;
            cin >> A;
            tmp += A * B[j];
        }
        if (tmp > 0) ans += 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int number_n, number_m, current_point, i, j, count_left = 0, count_right = 0;
  scanf("%d %d %d", &number_n, &number_m, &current_point);
  int cost_point[number_m];
  for(i = 0; i < number_m; i++) {
    scanf("%d", &cost_point[i]);
  }
  for(i = 1; i < number_n; i++) {
    for(j = 0; j < number_m; j++) {
      if(i == cost_point[j]) {
        if(i < current_point) {
          count_left++;
        } else {
          count_right++;
        }
      }
    }
  }
  printf("%d\n", (count_left < count_right)? count_left : count_right);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
const Int MOD=1e9+7;
Int calc(Int n,Int m){
  vector<Int> dp(n+1,1);
  for(Int i=0;i<m;i++){
    vector<Int> nx(n+1,0);
    for(Int j=0;j<=n;j++){
      if(j!=0){
	nx[j-1]+=dp[j];
	nx[j-0]+=dp[j];
	nx[j-1]%=MOD;
	nx[j-0]%=MOD;
      }
      if(j!=n){
	nx[j+1]+=dp[j];
	nx[j+0]+=dp[j];
	nx[j+1]%=MOD;
	nx[j+0]%=MOD;
      }
    }
    swap(dp,nx);
  }
  Int res=0;
  for(Int j=0;j<=n;j++)
    res=(res+dp[j])%MOD;
  return res;
}
signed main(){
  Int n,m;
  cin>>n>>m;
  Int ans=calc(n,m);
  ans+=MOD-calc(n-1,m);
  ans%=MOD;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

ll dp[105][2][4];
ll go(int i, int j, int k, v32 &dig)
{
	if (i >= sz(dig))
	{
		if (k == 0)
			return 1;
		return 0;
	}
	if (k < 0)
		return 0;
	if (dp[i][j][k] != -1)
		return dp[i][j][k];
	ll ans = 0;
	if (j)
	{
		ans += go(i + 1, 1, k - (dig[i] ? 1 : 0), dig);
		for (int num = 0; num < dig[i]; num++)
			ans += go(i + 1, 0, k - (num ? 1 : 0), dig);
	}
	else
	{
		for (int num = 0; num < 10; num++)
			ans += go(i + 1, 0, k - (num ? 1 : 0), dig);
	}
	return dp[i][j][k] = ans;
}
void solve()
{
	string s;
	int k;
	cin >> s >> k;
	v32 dig;
	for (auto c : s)
		dig.push_back(c - '0');
	memset(dp, -1, sizeof(dp));
	cout << go(0, 1, k, dig) << ln;
	return;
}

int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	clock_t start, stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
 <url:>
 問題文============================================================
 
 =================================================================
 
 解説=============================================================
 
 ================================================================
 */
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    while(cin >> N){
        if(N == 0) break;
        vector<ll> k(N);
        bool f = false;
        for(auto& in:k){
            cin >> in;
            if(in >= 2){
                f = true;
            }
        }
        if(!f){
            cout << "NA" << endl;
            continue;
        }
        ll ans = 0;
        for(int i = 0; i < N;i++){
            if(k[i] == 0) continue;
            ans++;
        }
        cout << ans+1 << endl;
    }
    return 0;
}



Measured memory_bytes: 3200
import sys
import io


def run(input: io.TextIOBase, output: io.TextIOBase):
    d = set()
    for i in input.readline().strip():
        if i in d:
            d.remove(i)
        else:
            d.add(i)
    if len(d) == 0:
        r = "Yes"
    else:
        r = "No"
    output.write(r + '\n')


if __name__ == '__main__':
    run(sys.stdin, sys.stdout)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool ip(string s){
	int n=s.size(),l=0,r=n-1;
	while(l<=r) if(s[l++]!=s[r--]) return false;
	return true;
}
int main(){
	string s; cin>>s;
	int n=s.size(),l=0,r=n-1;
	if(ip(s) and ip(s.substr(0,(n-1)/2)) and ip(s.substr((n+1)/2))) cout<<"Yes";
	else cout<<"No";
}


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

namespace CSharpSample01
{


    class Program
    {
        
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long[] data = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

            int ans = 0;
            for(int i = 0; i < N; i++)
            {
                while(data[i] % 2 == 0)
                {
                    ans++;
                    data[i] /= 2;
                }
               
            }

            Console.WriteLine(ans);

        }
    }
}

Measured memory_bytes: 14304
#include <iostream>

int main()
{
  int a,b;
  std::cin >> a >> b;
  if(a<b) std::cout << "a < b" << std::endl;
  else if(a>b) std::cout << "a > b" << std::endl;
  else if(a==b) std::cout << "a == b" << std::endl;
  return 0;
}



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

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

  int Ai = 0;
  vector<int> A(N + 1);

  rep(i, N - 1) {
    cin >> Ai;
    A[Ai]++;
  }

  rep(i, N) cout << A[i + 1] << endl;

  return 0;
}

Measured memory_bytes: 3948
#include <stdio.h>
#include <string.h>

int main(void)
{
    int n, p;
    int kouho[50];
    int wan;
    int step;
    
    while (1){
        memset(kouho, 0, sizeof(kouho));
        
        scanf("%d%d", &n, &p);
        if (n == 0 && p == 0){
            break;
        }
        
        wan = p;
        step = 0;
        while (1){
            if (wan > 0){
                kouho[step]++;
                wan--;
                if (kouho[step] == p){
                    break;
                }
            }
            else {
                wan += kouho[step];
                kouho[step] = 0;
            }
            step = (step + 1) % n;
        }
        printf("%d\n", step);
    }
    return (0);
}



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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int res = 0;
    rep(i,n){
        bool s = true;
        rep(j,i){
            if(h[j] > h[i]) s = false;
        }
        if(s) res++;
    }
    cout << res << endl;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

typedef pair<int,int> P;

int main2() {
  int N = nextInt();
  int M = nextInt();
  vector<P> v;
  REP(i, N) {
    int A = nextInt();
    int B = nextInt();
    v.push_back({A, B});
  }
  sort(ALL(v), [](const P&a, const P&b){
    return a.first < b.first;
  });

  int ans = 0;
  priority_queue<int> pq;
  int i = 0;
  for (int d = 1; d <= M; d++) {
    while (i < N && v[i].first <= d) {
      pq.push(v[i].second);
      i++;
    }
    if (!pq.empty()) {
      ans += pq.top(); pq.pop();
    }
  }

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

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int main()
{
	int q;
	cin >> q;
	while(q--){
		string a, b;
		cin >> a >> b;
		int dp[1010][1010];
		dp[0][0] = 0;
		rep(i,a.size()){
			rep(j,b.size()){
				if(a[i] == b[j]){
					dp[i+1][j+1] = dp[i][j] + 1;
				} else {
					dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
				}
			}
		}
		cout << dp[a.size()][b.size()] << endl;
	}
}



Measured memory_bytes: 7172
import itertools
n = int(input())
x = [input() for i in range(n)] 
num,march,answer = [0,0,0,0,0],["M","A","R","C","H"],0
for j in x:
 if j[0] in march: num[march.index(j[0])] += 1
while 0 in num: num.remove(0)
for k in list(itertools.combinations(num,3)): 
 answer += k[0]*k[1]*k[2]
print(answer) 

Measured memory_bytes: 9772
// AtCoder ABC126: D - Even Relation
// 2019.9.8 bal4u

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

#if 1
int getchar_unlocked(void);
int putchar_unlocked(int c);
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

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

#define MAX 100005
int N;
char col[MAX];
int hi[MAX], *to[MAX], *w[MAX];

void dfs(int now, int par, int c) {
	int i, j;
	col[now] = c;
	for (i = 0; i < hi[now]; i++) if ((j = to[now][i]) != par) {
		if (w[now][i] & 1) dfs(j, now, !c);
		else               dfs(j, now, c);
	}
}

int main()
{
	int i, k, u, v;
	int *memo, sz;
	
	N = in();
	memo = malloc(N*3*sizeof(int));
	sz = 0; for (i = 1; i < N; i++) {
		memo[sz++] = u = in()-1, memo[sz++] = v = in()-1, memo[sz++] = in();
		hi[u]++, hi[v]++;
	}
	for (i = 0; i < N; i++) if (hi[i]) {
		to[i] = malloc(hi[i]*sizeof(int));
		w[i] = malloc(hi[i]*sizeof(int));
	}
	memset(hi, 0, sizeof(hi));
	i = 0; while (i < sz) {
		u = memo[i++], v = memo[i++];
		k = hi[u]++, to[u][k] = v, w[u][k] = memo[i];
		k = hi[v]++, to[v][k] = u, w[v][k] = memo[i++];
	}
	dfs(0, -1, 0);
	for (i = 0; i < N; i++) pc(col[i]+'0'), pc('\n');
	return 0;
}


Measured memory_bytes: 12288