akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
ship = [[] for i in range(N+1)]

for i in range(M):
    a, b = map(int, input().split())
    ship[a].append(b)
    ship[b].append(a)

flag = 0
for i in ship[1]:
    if N in ship[i]:
        flag = 1
if flag == 1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 75212
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define pob pop_back
#define mp make_pair
#define ff first
#define ss second
#define pi 3.14159265
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <ll, ll> pll;
const ll M=1e9+7;
ll inf=1e18;
int main()
{
    int s=1+2+4+3+5;
    int s1=0,x;
    for(int i=0;i<5;i++){
        cin>>x;
        s1+=x;
    }
    cout<<s-s1;
}


Measured memory_bytes: 3548
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
using namespace std;
#define int long long
#define inf 1145141919810
typedef pair<int, int> P;
vector<P>G[114514];
int d[114514];
bool used[114514];

signed main() {
	int k;
	cin >> k;

	for (int i = 0; i<k; i++) {
		G[i].push_back(P((i + 1) % k, 1));
		G[i].push_back(P((i * 10) % k, 0));
	}

	deque<P>Q;
	fill(d, d + k, inf);
	fill(used, used + k, inf);
	d[1] = 0;
	Q.push_back(P(0, 1));

	while (Q.size()) {
		P p = Q.front();
		Q.pop_front();
		int v = p.second;
		if (d[v]<p.first)continue;
		for (int i = 0; i<G[v].size(); i++) {
			P e = G[v][i];
			if (d[e.first]>d[v] + e.second) {
				d[e.first] = d[v] + e.second;
				if (e.second)Q.push_back(P(d[e.first], e.first));
				else Q.push_front(P(d[e.first], e.first));
			}
		}
	}
	cout << d[0]+1 << endl;
}

Measured memory_bytes: 9344
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<iomanip>
#include<unordered_map>

using namespace std;
typedef long long ll;

ll dx[] = {1, 0};
ll dy[] = {0, 1};

int main()
{
    ll N;
    vector<ll> a(5);
    cin >> N >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    sort(a.begin(), a.end());
    cout << (ll)ceil((double)N/a[0])+4LL <<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String cards;
    int count, shuffle;
    
    while (in.hasNext()) {
      cards = in.next();
      if (cards.equals("-")) break;
      count = in.nextInt();
      
      for (int i = 0; i < count; i++) {
        shuffle = in.nextInt();
        cards = shuffle(cards, shuffle);
      }
      System.out.println(cards);
    }
  }
  public static String shuffle(String cards, int shuffle) {
    StringBuilder output = new StringBuilder();
    String first = cards.substring(0, shuffle);
    String last = cards.substring(shuffle, cards.length());
    cards = output.append(last).append(first).toString();
    return cards;
  }
}

Measured memory_bytes: 18480
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if 500 * i + 100 * j + 50 * k == x:
                count += 1

print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C,X;
    int result=0;
    cin >> A >> B >> C >> X;
    for(int i=0;i<=A;i++){
        for(int j=0;j<=B;j++){
            for(int k=0;k<=C;k++){
                if( i*500 + j*100 + k*50==X ){
                    result++;
                }
            }
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 256
s=0
taro = int(input())
if taro<40:
    taro=40
s+=taro    
ziro = int(input())
if ziro<40:
    ziro=40
s+=ziro    
saburo = int(input())
if saburo<40:
    saburo=40
s+=saburo
siro = int(input())
if siro<40:
    siro=40
s+=siro
hanako = int(input())
if hanako<40:
    hanako=40
s+=hanako
print(s//5)


Measured memory_bytes: 5592
#! /usr/bin/python
# -*- coding: utf-8 -*-

N = int(raw_input())
while N!=0:
    M = []
    for i in range(N):
        M.append(map(int, raw_input().split()))
        M[i].pop(0)
    K = map(int, raw_input().split())
    K.pop(0)
    ans = []
    for i in range(len(M)):
        j = 0
        while j < len(K):
            if not K[j] in M[i]:
                break
            j += 1
        if j == len(K):
            ans.append(i)
    if len(ans) == 1:
        print ans[0]+1
    else:
        print -1

    N = int(raw_input())

Measured memory_bytes: 4312
# Contest: AtCoder Beginner Contest 145 (https://atcoder.jp/contests/abc145)
# Problem: C: Average Length (https://atcoder.jp/contests/abc145/tasks/abc145_c)

def rint():
    return int(input())


def rints():
    return list(map(int, input().split()))


n = rint()
p = [rints() for _ in range(n)]
from itertools import permutations
from math import sqrt
per = list(permutations(range(n)))
s = 0
for pe in per:
    for i in range(1, n):
        x1, y1 = p[pe[i - 1]]
        x2, y2 = p[pe[i]]
        s += sqrt((x1 - x2)**2 + (y1 - y2)**2)
print(s / len(per))


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

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

typedef long long LL;
typedef long double LD;

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


Measured memory_bytes: 256
package main

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

func main() {
	n := readInt()
	if n%2 != 0 {
		fmt.Println(0)
		return
	}

	c := 0
	for x := 10; n/x > 0; x *= 5 {
		c += n / x
	}
	fmt.Println(c)
}

var stdin *bufio.Scanner

func read() string {
	if stdin == nil {
		stdin = bufio.NewScanner(os.Stdin)
		stdin.Split(bufio.ScanWords)
		stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	}
	stdin.Scan()
	return stdin.Text()
}

func readInt() int {
	n, _ := strconv.Atoi(read())
	return n
}

func readFloat64() float64 {
	n, _ := strconv.ParseFloat(read(), 64)
	return n
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 500009
#define MOD 1000000007
#define INF 1000000000

int main(){
  int N;
  ll K;
  cin>>N>>K;
  vector<vector<int>> a(N,vector<int>(N));
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cin>>a.at(i).at(j);
    }
  }

  vector<vector<vector<ll>>> dp(N,vector<vector<ll>>(N,vector<ll>(64,0)));
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(a.at(i).at(j)==1){
        dp[i][j][1]++;
      }
    }
  }

  for(int d=2;d<64;d++){
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        for(int k=0;k<N;k++){
          dp[i][j][d]+=dp[i][k][d-1]*dp[k][j][d-1]%MOD;
          dp[i][j][d]%=MOD;
        }
      }
    }
  }

  //cout<<dp.at(0).at(3).at(5)<<endl;

  vector<vector<ll>> count(64,vector<ll>(N,0));
  for(int i=0;i<N;i++){
    count.at(0).at(i)=1;
  }
  for(int d=1;d<64;d++){
    if(K%2==1){
      for(int j=0;j<N;j++){
        for(int i=0;i<N;i++){
          count.at(d).at(j)+=count.at(d-1).at(i)*dp.at(i).at(j).at(d)%MOD;
          count.at(d).at(j)%=MOD;
        }
      }
    }else{
      for(int j=0;j<N;j++){
        count.at(d).at(j)=count.at(d-1).at(j);
      }
    }
    K>>=1;
  }

  ll ans=0;
  for(int i=0;i<N;i++){
    ans+=count.at(63).at(i);
  }
  ans%=MOD;
  cout<<ans<<endl;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define MOD2 998244353
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;

template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for(auto v : V) os << v << " ";
    return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}

int main(){
    FAST;
    int n, m;
    cin >> n >> m;
    V<int> a(n);
    int sum = 0;
    loop(i, 0, n) {
        cin >> a[i];
        sum += a[i];
    }
    sort(all(a), greater<int>());
    if(a[m-1] < (double)sum/(4*m)) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atc_0028
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();

            int a = int.Parse(str);

            string s = Console.ReadLine();

            if (3200 <= a)
            {
                Console.WriteLine(s);
            }
            else
            {
                Console.WriteLine("red");
            }
        }
    }
}


Measured memory_bytes: 27336
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName

template <typename T>ostream &operator<<(ostream &out,const vector<T> &v) {rep(i,(int)v.size()-1)cout<<v[i]<<" ";cout<<v[(int)v.size()-1];return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const map<T1, T2> &p) {out << "(" << p.first << ", " << p.second << ")";return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const pair<T1, T2> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template<class T>void debag(const T &obj){cout<<obj<<endl;}

bool solve(){
  ll n;cin>>n;
  vector<bool>ans(n,false);
  ll k;cin>>k;
  rep(i,k){
    ll d;cin>>d;
    rep(i,d){
      ll a;cin>>a;
      ans[--a]=true;
    }
  }
  ll num=0;
  rep(i,n)if(!ans[i])num++;
  cout<<num<<endl;
  return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(30);
  solve();
}


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

int main()
{
    int n, x = 0, x1, con = 0, con1 = 0;
    cin >> n;
    cin >> x;
    for(int i = 0; i < n-1; i++)
    {
        cin >> x1;
        if(x >= x1) con++;
        else{
            if(con > con1) con1 = con;
            con = 0;
        }
        x = x1;

    }
    if(con > con1) con1 = con;
    cout << con1;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int x1,y1,x2,y2,x,y;
	cin>>x1>>y1>>x2>>y2;
	x=x2-x1,y=y2-y1;
	cout<<x2-y<<" ";
	cout<<y2+x<<" ";
	cout<<x2-y-x<<" ";
	cout<<y2+x-y;
	return 0;
}

Measured memory_bytes: 256
import java.io.*
import java.util.*

fun solve(S: String){
    println(700 + 100 * S.count{ it == 'o' })
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val S = sc.next()
    solve(S)
}



Measured memory_bytes: 31516
/*

    author : s@if

*/

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

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			99999999
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)


bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)1e5+9;

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    ll i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    cin>>l>>r;

    ll ans = 2018;

    for(i=l,j=0; i<r && j<10000; i++,j++)
    {
        for(k=i+1,p=0; k<=r && p<10000; k++,p++)
        {
            m = (i*k)%2019;

            ans = min(ans,m);
        }
    }

    for(i=r,j=0; i>=l && j<10000; i--,j++)
    {
        for(k=i-1, p=0; k>=l && p<10000; k--,p++)
        {
            m = (i*k)%2019;

            ans = min(ans,m);
        }
    }

    cout<<ans<<endl;

   // main();

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


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

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_V(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_M(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}

int main() {
    int n, m;
    cin >> n >> m;
    V<ll> a(n);
    V<pair<ll, ll>> bc(m);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >> bc[i].first >> bc[i].second;
    }

    sort(a.begin(), a.end());
    sort(bc.begin(), bc.end(), [](pair<ll, ll> x, pair<ll, ll> y) {
        return x.second > y.second;
    });

    bool ok = false;
    int p = 0;
    for (int i = 0; i < m; ++i) {
        if(ok)break;
        ll rest = bc[i].first, num = bc[i].second;
        int cnt = 0;
        while(p<n && cnt < rest){
            if(a[p]>num){
                ok=true;
                break;
            }
            a[p++]=num;
            cnt++;
        }
    }
    cout<<accumulate(a.begin(), a.end(), 0LL)<<endl;

    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>

using namespace std;

int N,C;
vector<vector<int> > V;
int dx[] = {-1,0,-1,1,0,1};
int dy[] = {-1,-1,0,0,1,1}; 

void print(const vector<vector<int> >& v){
  for(int i = 0; i < (int)v.size(); i++){
    for(int j = 0; j < (int)v[i].size(); j++) cout << v[i][j] << " ";
    cout << endl;
  }
}

void input(){
  V.resize(N,vector<int>());
  for(int i = 0; i < N; i++){
    V[i].resize(i+1);
    for(int j = 0; j < (int)V[i].size(); j++) cin >> V[i][j];
  }
}

void dfs(int x, int y, int col, vector< vector<int> >& v){

  if(v[y][x] <= 0) return;
   v[y][x] = -1;
  for(int i = 0; i < 6; i++){
    int nx = x+dx[i];
    int ny = y+dy[i];
    if(0>ny || ny>=(int)v.size()) continue;
    if(0>nx || nx>=(int)v[ny].size()) continue;
    if(v[ny][nx] == col) dfs(nx,ny,col,v);
  }
}

int count(vector< vector<int> > v, int col){

  for(int i = 0; i < (int)v.size(); i++)
    for(int j = 0; j < (int)v[i].size(); j++){
      if(v[i][j] != 0) continue;
      for(int k = 0; k < 6; k++){
	int nx = j+dx[k];
	int ny = i+dy[k];
	if(0>ny || ny>=(int)v.size()) continue;
	if(0>nx || nx>=(int)v[ny].size()) continue;
	if(v[ny][nx] <= 0) continue;
	dfs(nx,ny,v[ny][nx],v);
      }
    }

  int res = 0;
  for(int i = 0; i < (int)v.size(); i++)
    for(int j = 0; j < (int)v[i].size(); j++){
      if(v[i][j] <= 0) continue;
      res += (v[i][j]==col?-1:1);
    }
  return res;
}

void solve(){
  int ans = -(1<<25);
  for(int i = 0; i < (int)V.size(); i++)
    for(int j = 0; j < (int)V[i].size(); j++){
      if(V[i][j] != 0) continue;
	V[i][j] = C;
	ans = max(ans,count(V,C));
	V[i][j] = 0;	
    }
  cout << ans << endl;
}

int main(){
  while(cin >> N >> C && (N|C)){
    input();
    solve();
  }
}

Measured memory_bytes: 1224
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define MSG(x) std::cout << #x << " : " << x << "\n";
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N, M;
vector<int> L;
vector<int> R;

struct Point
{
    Point(int _b, int _e)
        : b(_b)
        , e(_e)
    {
    }
    int b; // begin
    int e; // end

    int length() const
    {
        return e - b;
    }

    bool operator <(const Point& other) const
    {
        return this->length() < other.length();
    }
    bool operator >(const Point& other) const
    {
        return this->length() > other.length();
    }
};
vector<Point> P;

int main()
{
    cin >> N >> M;
    L.resize(M);
    R.resize(M);
    rep (i, M)
    {
        cin >> L[i];
        cin >> R[i];
        P.push_back(Point(L[i], R[i]));
    }

    std::sort(ALL(P), std::greater<Point>());
    Point now = P[0];
    // cout << now.b << ", " << now.e << endl;
    for (int i = 0; i < P.size() - 1; ++i)
    {
        if (now.e < P[i+1].b)
        {
            // cout << "A" << endl;
            cout << 0 << endl;
            return 0;
        }
        if (now.b > P[i+1].e)
        {
            // cout << "B" << endl;
            cout << 0 << endl;
            return 0;
        }

        if (now.b < P[i+1].b)
        {
            // cout << "C" << endl;
            now.b = P[i+1].b;
        }

        if (now.e > P[i+1].e)
        {
            // cout << "D" << endl;
            now.e = P[i+1].e;
        }

        if (now.b > now.e)
        {
            // cout << "E" << endl;
            cout << 0 << endl;
            return 0;
        }
        // cout << now.b << ", " << now.e << endl;
    }

    cout << now.length() + 1 << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N, C; scanf("%d %d", &N, &C);
  vector<int> S(N + 5), T(N + 5), CH(N + 5);
  vector<vector<int>> table(C + 5, vector<int>(1e5 * 2 + 5, 0));
  for (int i = 1; i <= N; ++i) {
    scanf("%d %d %d", &S[i], &T[i], &CH[i]);
    S[i] *= 2;
    T[i] *= 2;
    ++table[CH[i]][S[i] - 1];
    --table[CH[i]][T[i]];
  }

  vector<int> in_use(1e5 * 2 + 5, 0);
  for (int ch = 1; ch <= C; ++ch) {
    for (int i = 1; i <= 1e5 * 2; ++i) {
      table[ch][i] += table[ch][i - 1];
    }
    for (int i = 1; i <= 1e5 * 2; ++i) {
      if (table[ch][i] > 0) { ++in_use[i]; }
    }
  }
  int ans = *max_element(in_use.begin(), in_use.end());
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 29696
N, M = map(int, input().split())
lis = []
for _ in range(N):
  a, b = map(int, input().split())
  lis.append((a, b))
def eval(data):
  return data[0]
lis.sort(key=eval)
total = 0
num = 0
mark = 0
for i in range(N):
  num = num + lis[i][1]
  total = total + lis[i][0]*lis[i][1]
  if num > M:
    mark = i
    total = total - lis[i][0]*lis[i][1]
    num = num - lis[i][1]
    break
total = total + (M - num)*lis[mark][0]
print(total)  

Measured memory_bytes: 18168
def main():
    n = int(input())

    A = [0] * (10 ** 6)
    for x in range(1, 10 ** 2 + 1):
        for y in range(1, 10 ** 2 + 1):
            for z in range(1, 10 ** 2 + 1):
                i = x ** 2 + y ** 2 + z ** 2 + x*y + y*z + z*x
                A[i] += 1

    for i in range(1, n + 1):
        print(A[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 76304
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
#define Uniq(v) v.erase(unique(All(v)),v.end())
typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
typedef pair<string, int> Psi;
typedef vector<int> Vi;
const int INF = (1<<30);
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

int main()
{
  int N;
  ll A[100001];

  cin >> N;
  Rep(i, N) cin >> A[i];

  ll sum = 0;
  ll tmp = 0;
  Rep(i, N) {
    if( A[i] != 0 ) {
      tmp += A[i];
    } else {
      sum += tmp / 2;
      tmp = 0;
    }
  }
  sum += tmp / 2;

  cout << sum << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const int max_n = 1e6;
ll a[max_n];
vector<ll> v;
map<ll,ll> ma;
ll n;

int main(){
  cin >> n;
  map<ll,ll> ma;
  for(ll nn=2 ; nn<=n ; nn++){
    ll k = nn;
    for(ll i=2 ; i*i<=k ; i++){
      while(k % i == 0){
        ++ma[i];
        k /= i;
      }
    }
    if(k!=1) ma[k]++;
  }
  ll ans = 1;
  for(auto ite=begin(ma) ; ite!=end(ma); ite++){
    ans *= (ite->second+1) % mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


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

typedef vector<int> VI;

int main(){
    int N,Q;
    cin>>N>>Q;
  
    string S;
    VI s2(N+1,0);
    cin>>S;
  
    for (int i=0;i<N;++i)
        s2[i+1]=s2[i]+(S.substr(i,2)=="AC"?1:0);  // 前缀和 

    for (int i=0;i<Q;++i){
        int l,r;
        cin>>l>>r;
        cout<<(s2[r-1]-s2[l-1])<< endl;
    }
}

Measured memory_bytes: 1408
import           System.IO
import           Control.Monad
import           Control.Applicative


data Res = Res {
  oldmax :: Int,
  oldmin :: Int
} deriving Show

f :: Res -> Int -> Res
f acc a = Res (max (oldmax acc) (a - oldmin acc)) (min (oldmin acc) a)

main = do
  n    <- readLn :: IO Int
  list <- replicateM n (readLn :: IO Int)
  putStrLn $ show $ oldmax $ foldl f
                                   Res {oldmax = minBound, oldmin = maxBound}
                                   list



Measured memory_bytes: 125864
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var x = NextInt();
            var a = NextInt();
            var b = NextInt();

            Console.WriteLine(Math.Abs(x - a) < Math.Abs(x - b) ? "A" : "B");
        }
    }

    class MyMath {
        static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 13268
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
	double v;
	double h, t, y;
	int N;
	
	while((scanf("%lf", &v)) != EOF){
		t = v / 9.8;
		y = 4.9 * pow(t, 2);
		
		N = y / 5 + 1;
		if((double)5 * N - 5 < y) N++;
		
		printf("%d\n", N);
	}
	
	return 0;
}

Measured memory_bytes: 1056
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 998244353;

#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int A;
	int B;
	cin >> A >> B;
	if (A < 6) cout << 0 << endl;
	else if (A <= 12) cout << B / 2 << endl;
	else cout << B << endl;
}

Measured memory_bytes: 256
H, W = map(int, input().split())

a = []
for i in range(H):
    a.append(list(map(int, input().split())))

move = []    
for i in range(H):
    for j in range(W):
        if a[i][j] % 2 == 1:
            if j < W-1:
                move.append([i, j, i, j+1])
                a[i][j+1] += 1
            elif i < H-1:
                move.append([i, j, i+1, j])
                a[i+1][j] += 1

print(len(move))
for x, y, x2, y2 in move:
    print(x+1, y+1, x2+1, y2+1)

Measured memory_bytes: 26364
#include <stdio.h>
int main(void){
	char s[100000];
	scanf("%s",s);
	int i,alpha[26];
	for(i=0;s[i]!='\0';i++){alpha[s[i]-'a']++;}
	i=0;
	while(i<26){
		if(alpha[i]==0){printf("%c",i+'a');return 0;}
		i++;
	}
	printf("None");
}

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

int main() {
  int A, B, i, x;
  cin >> A >> B;
  i = A;
  x = 0;
  
  while (i <= B) {
    int a, b, c, d, e;
    a = i / 10000;
    b = (i - a * 10000) / 1000;
    c = (i - a * 10000 - b * 1000) / 100;
    d = (i - a * 10000 - b * 1000 - c * 100) / 10;
    e = i - a * 10000 - b * 1000 - c * 100 - d * 10;
    
    if (a == e && b == d) {
      x++;
    }
    i++;
  }
  
  cout << x << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];

  ll sum = 0;
  rep(i,n) sum += a[i];

  vector<ll> ps;
  for(ll i = 2; i*i<=sum; ++i){
    if(sum%i==0){
      ps.emplace_back(i);
      if(i*i!=sum) ps.emplace_back(sum/i);
    }
  }
  ps.push_back(sum);
  ll ans = 1;
  for(ll p:ps){
    bool ok = [&]{
      vector<ll> m;
      rep(i,n) if(a[i]%p!=0) m.emplace_back(a[i]%p);
      if(m.empty()) return true;
      sort(m.begin(),m.end());

      vector<ll> l(m.size()+1), r(m.size()+1);
      rep(i,m.size()){
        l[i+1] = l[i] + m[i];
        r[i+1] = r[i] + (p-m[m.size()-1-i]);
      }
      rep(i,m.size()+1){
        ll li = l[i], ri = r[m.size()-i];
        if( li>k || ri>k ) continue;
        if(abs(li-ri)%p==0) return true;
      }
      return false;
    }();
    if(ok) ans = max(ans,p);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
b=10
d=[]
ans=[]
k=-10000
for i in range(5):
  a=int(input())
  d.append(a)
  if b>a%10 and a%10!=0:
    b=a%10
    k=i
  if a%10==0:
    ans.append(a)
  else:
    ans.append((a//10+1)*10)
if k!=-10000:
  ans[k]=d[k]
print(sum(ans))


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  ll N; cin >> N;
  vector<ll> A(N); REP(i, N) cin >> A[i];
  ll Q; cin >> Q;
  vector<ll> B(Q), C(Q); REP(i, Q) cin >> B[i] >> C[i];
  map<ll, ll> m;
  ll ans = accumulate(all(A), 0LL);
  REP(i, N) {
    m[A[i]]++;
  }
  for(int i = 0; i < Q; ++i) {
    ll tmp = m[B[i]];
    ll res = C[i] * tmp - B[i] * tmp;
    ll a = ans + res;
    ans += res;
    cout << a << endl;
    m[C[i]] += m[B[i]];
    m[B[i]] = 0;
  }
}

Measured memory_bytes: 11400
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int a;
	cin >> a;
	if (a < 1000) cout << "ABC" << endl;
	else cout << "ABD" << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline

def main():
    N, Q = map(int, input().split())
    # edges = [None]*N
    edges = [[] for _ in range(N)]
    # edges[0] = 0
    # edges[0].append = 0
    for _ in range(N-1):
        a, b = map(int, input().split())
        edges[b-1].append(a-1)
        edges[a-1].append(b-1)

    counts = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        counts[p-1] += x

    parent_nodes = deque()
    parent_nodes.append(0)
    visited_nodes = set()
    while parent_nodes:
        parent = parent_nodes.popleft()
        if parent in visited_nodes:
            continue
        visited_nodes.add(parent)
        for child in edges[parent]:
            if child in visited_nodes:
                continue
            counts[child] += counts[parent]
            parent_nodes.append(child)

    print(' '.join(list(map(str, counts))))

if __name__ == "__main__":
    main()

Measured memory_bytes: 73708
use proconio::*;
use std::collections::BinaryHeap;

fn main() {
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
    };

    let mut score = 0;
    let mut lasts = [-1; 26];
    let mut t = vec![26; d];
    let depth = 7;
    for i in 0..d {
        let mut max_score = -10000000;
        for j in 0..26 {
            let tmp = search(i, j, &c, &s, &mut lasts, depth, d, 0);
            if tmp > max_score {
                max_score = tmp;
                t[i] = j;
            }
        }
        score += max_score;
        lasts[t[i]] = i as i64;
    }

    for &a in &t {
        println!("{}", a + 1);
    }
}

fn calc_score(i: usize, j: usize, c: &Vec<i64>, s: &Vec<Vec<i64>>, lasts: &mut [i64; 26]) -> i64 {
    let mut res = s[i][j];
    let tmp = lasts[j];
    lasts[j] = i as i64;

    for j in 0..26 {
        let i = i as i64;
        let last = lasts[j];
        res -= c[j] * (i - last);
    }

    lasts[j] = tmp;
    res
}

fn search(
    i: usize,
    t: usize,
    c: &Vec<i64>,
    s: &Vec<Vec<i64>>,
    lasts: &mut [i64; 26],
    depth: usize,
    d: usize,
    cscore: i64,
) -> i64 {
    if depth == 0 || i == d - 1 {
        return calc_score(i, t, &c, &s, lasts) + cscore;
    }

    let mut max_score = -1000000;
    let tmp_last = lasts[t];
    lasts[t] = i as i64;
    let tmp_score = calc_score(i, t, &c, &s, lasts);
    let mut cands = BinaryHeap::new();
    for j in 0..26 {
        let tmp_score = calc_score(i + 1, j, &c, &s, lasts);
        cands.push((tmp_score, j));
    }
    for &(_, j) in cands.iter().take(2) {
        let tmp = search(i + 1, j, &c, &s, lasts, depth - 1, d, cscore + tmp_score);

        if tmp > max_score {
            max_score = tmp;
        }
    }

    lasts[t] = tmp_last;
    max_score + cscore
}


Measured memory_bytes: 2284
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
signed main(){
    ll n;cin>>n;
    map<ll,vector<pll> >x,y;
    map<ll,vector<pll> >xpy;
    map<ll,vector<pll> >ymx;
    rep(i,n){
        ll a,b;cin>>a>>b;
        char c;cin>>c;
        ll d=0;
        if(c=='R')d=0;
        if(c=='U')d=1;
        if(c=='L')d=2;
        if(c=='D')d=3;

        x[a].pb(mp(b,d));
        y[b].pb(mp(a,d));
        xpy[a+b].pb(mp(a,d));
        ymx[b-a+200000].pb(mp(a,d));
    }
    ll ans=inf*inf;
    for(auto s:x){
        ll u=-1,d=-1;
        ll i=s.first;
        sort(all(x[i]));
        for(auto e:x[i]){
            if(e.second==1)d=e.first;
            if(e.second==3)u=e.first;
            if(u>=0&&d>=0&&u-d>=0){
                ans=min(ans,(u-d)*5);
            }
        }
    }
    for(auto s:y){
        ll l=-1,r=-1;
        ll i=s.first;
        sort(all(y[i]));
        for(auto e:y[i]){
            if(e.second==0)l=e.first;
            if(e.second==2)r=e.first;
            if(l>=0&&r>=0&&r-l>=0){
                ans=min(ans,(r-l)*5);
            }
        }
    }
    for(auto s:xpy){
        ll l=-1,r=-1,u=-1,d=-1;
        ll i=s.first;
        sort(all(xpy[i]));
        for(auto e:xpy[i]){
            if(e.second==0)l=e.first;
            if(e.second==2)r=e.first;
            if(e.second==1)d=e.first;
            if(e.second==3)u=e.first;
            if(l>=0&&d>=0&&d>=l)ans=min(ans,(d-l)*10);
            if(r>=0&&u>=0&&r>=u)ans=min(ans,(r-u)*10);
        }
    }
    for(auto s:ymx){
        ll l=-1,r=-1,u=-1,d=-1;
        ll i=s.first;
        sort(all(ymx[i]));
        for(auto e:ymx[i]){
            if(e.second==0)l=e.first;
            if(e.second==2)r=e.first;
            if(e.second==1)d=e.first;
            if(e.second==3)u=e.first;
            if(l>=0&&u>=0&&u>=l)ans=min(ans,(u-l)*10);
            if(r>=0&&d>=0&&r>=d)ans=min(ans,(r-d)*10);
        }
    }
    if(ans==inf*inf){
        cout<<"SAFE"<<endl;
    }else{
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 74340
/* Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/
#include <bits/stdc++.h>
using namespace std;
#define fore(i, a, b) for (int i = a, to = b; i < to; i++)
#define foref(i, a, b) for (int i = b - 1, to = a; i >= to; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
typedef pair<Long, Long> Pair;
void solve() {
  Long a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int t = 1;
  //cin >> t;
  while (t--) solve();

  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
void init_ios() {ios_base::sync_with_stdio(false); cin.tie(nullptr);}

int N;

int main() {
    cin >> N;
    vector<int> A(N);
    for (auto& a : A) cin >> a;

    vector<pair<int, int>> b;
    for (int i = 0; i < N; ++i) b.emplace_back(A[i], i);

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

    vector<int> c(N);
    for (int i = 0; i < N; ++i) {
        c[b[i].second] = i;
    }

    for (int i = 0; i < N; ++i) {
        int x = c[i] < N / 2 ? b[N/2].first : b[N/2-1].first;
        cout << x << endl;
    }

    return 0;
}


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

int main(){
    long long n , m;
    cin >> n >> m;
    long long nn = max(n, m);
    m = min(n, m);
    n = nn;
    long long k = n % m;
    while (k != 0){
        n = m;
        m = k;
        k = n % m;
    }
    cout << m << endl;
}


Measured memory_bytes: 3088
import bisect  # 配列二分法
from collections import defaultdict

N = int(input())
S = [*input()]
Q = int(input())
d = defaultdict(list)

# 各アルファベットの出現場所を記録
for i, c in enumerate(S):
    d[c] += [i]

# この時点でどのアルファベットについてもソート済み
# print(d)

for _ in range(Q):
    q, y, z = input().split()

    if q == '1':
        i = int(y) - 1  # 文字の変更位置

        if S[i] == z: continue  # 同じ文字の場合は処理終了

        # 削除 O(N)
        b = bisect.bisect(d[S[i]], i)  # 2分法で i の出現位置を(log N)で探す
        d[S[i]].pop(b - 1)  # 削除

        # 追加 O(N) かかる？
        S[i] = z
        bisect.insort(d[z], i) 

    else:
        left = int(y) - 1
        right = int(z) - 1

        count = 0
        for v in d.values():
            count += 1 if bisect.bisect(v, right) - bisect.bisect_left(v, left) > 0 else 0

        print(count)

Measured memory_bytes: 35220
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#define maxn 100009
using namespace std;
int n, a[maxn];
long long A, B;
bool check(long long x){
	long long cnt = 0;
	for(int i = 1; i <= n; i++){
		if(x >= a[i])
			continue;
		if(x * B >= a[i])
			continue;
		if(x * A < a[i])
			return 0;
		cnt += (a[i] - x * B + A - B - 1) / (A - B);
	}
	return cnt <= x;
}
int main(){
	cin >> n >> A >> B;
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	long long l = 0, r = 1e16;
	while(l < r){
		long long m = (l + r) >> 1;
		if(check(m))
			 r = m;
		else
			l = m + 1;
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

int main(){
    string s;
    cin >> s;
    int n=s.size();
    int K;
    cin >> K;
    int dp[105][105][2];//i桁目まで決定,j個の非ゼロを使用,k=0一致するかも、k=1大丈夫
    dp[0][0][0]=1;
    rep(i,n)rep(j,n)rep(k,2){
        int nd=s[i]-'0';//i桁目のnの数
        rep(d,10){
            int ni=i+1,nj=j,nk=k;
            if(d!=0){
                nj++;
            }
            if(nj>K)continue;
            if(k==0){
                if(d>nd)continue;
                if(d<nd)nk=1;
            }
            dp[ni][nj][nk]+=dp[i][j][k];
        }
    }
    int ans=dp[n][K][0]+dp[n][K][1];
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define watch(x) cerr << (#x) << " is " << (x) << endl;
using namespace std;
const int MAXN = 100001;
const int INF = 1234567890;
const double PI = acos(-1);
using ll = long long;

double dist(double x1, double y1, double x2, double y2){
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	double a, b, h, m; cin >> a >> b >> h >> m;
	double min_angle = 2 * PI * ((m) / 60);
	double hr_angle = 2 * PI * ((h * 60 + m) / 720);



	double x1 = b * cos(min_angle);
	double y1 = b * sin(min_angle);
	double x2 = a * cos(hr_angle);
	double y2 = a * sin(hr_angle);
	cout << fixed << setprecision(12) << dist(x1, y1, x2, y2);
	return 0;
}


Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h, w, k;
  cin>>h>>w>>k;
  vector<string> cake(h);
  vector<int> e(w, 0);
  vector<vector<int> > board(h, e);
  for(int i = 0; i < h; ++i)cin>>cake[i];
  int cnt = 1;
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w;){
      if(cake[i][j] == '#'){
	board[i][j]=cnt;j++;
	while(cake[i][j] != '#' && j < w){
	  board[i][j]=cnt;
	  j++;
	}
	cnt++;
      }
      else j++;
    }
  }
  cnt = k;
  for(int i = h - 1; i >= 0; i--){
    for(int j = w - 1; j >= 0; ){
      if(cake[i][j] == '#'){
	cnt = board[i][j];
	j--;
	if(j >= 0){
	  while(board[i][j]== 0 && j >= 0){
	    board[i][j] = cnt;
	    j--;
	  }
	}
      }
      else j--;
    }
  }
  /*
  cnt = k;
  for(int j = 0; j < w; ++j){
    for(int i = 0; i < h; ){
      if(cake[i][j] == '#'){
	cnt = board[i][j];i++;
	while(i < h && board[i][j] == 0){
	  board[i][j] = cnt;
	  i++;
	}
      }
      else i++;
    }
  }
  cnt = k;
  for(int j = 0; j < w; ++j){
    for(int i = h - 1; i >= 0; ){
      if(cake[i][j] == '#'){
	cnt = board[i][j];i--;
	while(i >= 0 && board[i][j] == 0){
	  board[i][j] = cnt;
	  i--;
	}
      }
      else{ i--;}
    }
  }
  */
  cnt = k;
  for(int j = 0; j < w; ++j){
    for(int i = 0; i < h; ){
      if(i + 1 < h && board[i + 1][j] == 0){
	cnt = board[i][j];i++;
	while(i < h && board[i][j] == 0){
	  board[i][j] = cnt;
	  i++;
	}
      }
      else i++;
    }
  }
  cnt = k;
  for(int j = 0; j < w; ++j){
    for(int i = h - 1; i >= 0; ){
      if(i - 1 >= 0 && board[i - 1][j] == 0){
	cnt = board[i][j];i--;
	while(i >= 0 && board[i][j] == 0){
	  board[i][j] = cnt;
	  i--;
	}
      }
      else{ i--;}
    }
  }

  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; j++){
      cout<<board[i][j]<<" ";
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 1280
def kouyaku(a,b):
    aa = max(a,b)
    bb = min(a,b)
    if bb == 0:
        return aa
    else:
        return kouyaku(bb,aa%bb)

N = int(input())
A = [int(i) for i in input().split()]
ans = A[0]
A.sort()
for i in range(N):
    ans = kouyaku(ans, A[i])
print(ans)

Measured memory_bytes: 14252
def resolve():
    list_S = list(input())
    S = [int(s) for s in list_S]
#    print()
#    print(S)
    s1 = S[::2]
    s2 = S[1::2]
#    print(s1)
#    print(s2)
    
#    print(sum(s1))
#    print(sum(s2))
    sums1 = sum(s1)
    sums2 = sum(s2)
    if sums1>sums2:
        print(len(s1)-sums1+sums2)
    else:
        print(len(s2)-sums2+sums1)

resolve()


Measured memory_bytes: 5420
import sys
input=sys.stdin.readline

N, M = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PRICE = 0
NBOTTLE = 1

AB.sort() # price昇順でソート
bought = 0
paid = 0
for i in range(N):
    if bought >= M: break
    buy = min(M - bought, AB[i][NBOTTLE])
    bought += buy
    paid += buy * AB[i][PRICE]

print(paid)


Measured memory_bytes: 21536
object Main extends App {
  import scala.io.StdIn._

  val target = readLine.trim
  println(
    find(target).let{case (a, b) ⇒ s"$a $b"}
  )
  def find(target: String): (Int, Int) = {
    target.indices.tail.find(i ⇒ target(i) == target(i - 1)).map(i ⇒ (i, i + 1)).getOrElse(target.indices.drop(2).find(i ⇒ target(i) == target(i - 2)).map(i ⇒ (i - 1, i + 1)).getOrElse(-1, -1))
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
    @inline
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}

Measured memory_bytes: 32004
# -*- coding: UTF-8 -*-

tap_pattern = input()
taps_odd = ["R", "U", "D"]
taps_even = ["L", "U", "D"]
easy = True

for i in range(1,len(tap_pattern)+1):
  if i%2 == 0:
    if tap_pattern[i-1] not in taps_even:
      easy = False
  elif i%2 != 0:
    if tap_pattern[i-1] not in taps_odd:
      easy = False

if easy == True:
  result = "Yes"
else:
  result = "No"
  
print(result)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define mp make_pair
#define int long long
#define rc(s) return cout<<s,0
#define gog pair<int,string>
//#define cin fin
//#define cout fout
using namespace std;

//ifstream fin("joc7.in");
//ofstream fout("joc7.out");

const int nmax=1e3+5;
const int mod=1e9+7;
const int mod1=998244353;

int x,a;

int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie();cout.tie();
	cin >> x >> a;
	if(x<a) rc(0);
	else rc(10);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <tuple>

typedef long long ll;

using namespace std;
int main() {
    vector<ll> v(5);
    cin >> v[0] >> v[1] >> v[2] >> v[3] >> v[4];
    ll ret = 0;
    ll resid = 10;
    for(auto vi : v){
        ret += ((vi-1)/10)*10 + 10;
        resid = min( (vi-1)%10 +1, resid );
    }
    cout << ret + resid - 10 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int H = s.nextInt();
		int R = s.nextInt();
		int a = H + R;
		int ans = 1;
		
		if(a<0){
			ans = -1;
		}else if(a == 0){
			ans = 0;
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 26324
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n;
  	cin >> n;
  	long long num = n , dig = 0;
  	while(num != 0){
     	num /= 10;
        dig++;
    }
    long long ans = 9;
  	if(dig == 1){
		cout << n << endl;
      	return 0;
    }
  	
  	else{
		for(int i = 3 ; i < dig ; i += 2){
			ans += (pow(10 , i) - pow(10 , i - 1));
        }
    	if(dig % 2)
    		ans += (n - pow(10,dig - 1) + 1);
    	cout << ans << endl;
      	return 0;
    }
  	
}

Measured memory_bytes: 512