akhauriyash/Code-Regression huggingface dataset:
MOD = 10 ** 9 + 7
N, K = gets.split.map(&:to_i)
E = Hash.new { |h, k| h[k] = [] }

(N - 1).times do
  a, b = gets.split.map { |a| a.to_i - 1 }

  E[a] << b
  E[b] << a
end

queue = [[0, -1]]
ans = K

until queue.empty?
  cur, from = queue.shift
  can_use_color_cnt = (from == -1) ? K - 1 : K - 2

  if E[cur].size > K
    ans *= 0
  else
    res = 1

    E[cur].each do |u|
      next if u == from

      res = res * can_use_color_cnt % MOD
      can_use_color_cnt -= 1
    end

    E[cur].each do |u|
      next if u == from

      queue << [u, cur]
    end

    ans = ans * res % MOD
  end
end

puts ans 


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

#define pb push_back
#define PQ priority_queue
#define make_unique(x) sort((x).begin(), (x).end()); (x).erase(unique((x).begin(), (x).end()), (x).end())

typedef long long ll;
typedef long double ld;

//__builtin_popcount(x)

using namespace std;

/*const int mod = 1e9 + 7;

ll add(ll a, ll b) {
    ll res = a + b;
    if (res >= mod) res -= mod;
    return res;
}

ll sub(ll a, ll b) {
    ll res = a - b + mod;
    if (res >= mod) res -= mod;
    return res;
}

ll mul(ll a, ll b) {
    return (((a % mod) * (b % mod)) % mod);
}

int powm(int a, long long n) {
	if (n == 0) {
		return 1;
	}
	else if (n & 1) {
		return mul(a, powm(a, n - 1));
	}
	else {
		return powm(mul(a, a), n / 2);
	}
}*/

/* Z-FUNCTION
ll l = 0, r = 0, n = (int)s.size();
vector<int> z(n, 0);
for (int i = 1; i < n; i++) {
    if (r >= i) {
        z[i] = min(1ll*z[i-l], r-i+1);
    }
    while (z[i] + i < n && s[z[i]] == s[z[i] + i]) z[i]++;
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
}
*/

/*vector<ll> find_dividers(ll x) {
    vector<ll> dividers;

    for (ll i = 1; i <= sqrt(x); i++) {
        if (x % i == 0) {
           dividers.push_back(i);
            if (1ll*i * i != x) {
                dividers.push_back(1ll*x / 1ll*i);
            }
        }
    }

    return dividers;
}*/

/*int nok(int a, int b) {
    return a / __gcd(a, b) * b;
}*/

// ceil(a/b) = (a+b-1)/b

void solve() {
    int n;
    cin >> n;
    const string acl = "ACL";
    string ans = "";
    for (int i = 0; i < n; i++) ans += acl;
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.setf(ios::fixed);
    //cout.precision(10);

    int t=1;
    //cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3656
H, W, h, w = map(int, raw_input().split())
f = (H / h) * (W / w)
m = H * W - f * h * w
if m == 0:
    print "No"
    quit()
t = (f + m - 1) / m + 1
a = [[t] * W for _ in xrange(H)]
k = t * (h * w - 1) + 1
s = H * W * t
for i in xrange(h - 1, H, h):
    for j in xrange(w - 1, W, w):
        a[i][j] = -k
        s -= k + 1
if s < 0:
    print "No"
else:
    print "Yes"
    for l in a:
        print " ".join(map(str, l))


Measured memory_bytes: 8708
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        int t=s.nextInt();
        int n=s.nextInt();
        s.nextLine();
        String[] arr=new String[t];
        for(int i=0;i<t;i++){
            arr[i]=s.nextLine();
        }
        Arrays.sort(arr);
        StringBuilder str=new StringBuilder();
        for(int i=0;i<arr.length;i++){
            str.append(arr[i]);
        }
        System.out.println(str);

    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
using Int = long long;
const Int MOD = 998244353;
const Int ROOT = 3;
Int modpow(Int x, Int n) {
    Int ans = 1;
    while (n > 0) {
        if (n & 1) ans = ans * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ans;
}
Int modinv(Int x) {
    return modpow(x, MOD - 2);
}
void ntt(vector<Int> &A, bool rev) {
    int N = A.size();
    if (N == 1) return;
    vector<Int> A0(N / 2), A1(N / 2);
    for (int i = 0; 2 * i < N; i++) {
        A0[i] = A[2 * i];
        A1[i] = A[2 * i + 1];
    }
    ntt(A0, rev);
    ntt(A1, rev);
    Int w = modpow(ROOT, !rev ? (MOD - 1) / N : MOD - 1 - (MOD - 1) / N);
    Int wk = 1;
    Int coeff = (rev == 0 ? 1 : modinv(2));
    for (int i = 0; 2 * i < N; i++) {
        A[i] = (A0[i] + wk * A1[i]) % MOD;
        A[i + N / 2] = (A0[i] + MOD - wk * A1[i] % MOD) % MOD;
        A[i] = A[i] * coeff % MOD;
        A[i + N / 2] = A[i + N / 2] * coeff % MOD;
        wk = wk * w % MOD;
    }
}
vector<Int> convolve(const vector<Int> &A, const vector<Int> &B) {
    int sz = 1;
    while (sz < A.size() + B.size() - 1) sz *= 2;
    vector<Int> a(A), b(B);
    a.resize(sz);
    b.resize(sz);
    ntt(a, false);
    ntt(b, false);
    for (int i = 0; i < sz; i++) {
        a[i] = a[i] * b[i] % MOD;
    }
    ntt(a, true);
    a.resize(A.size() + B.size() - 1);
    return a;
}
int main() {
    Int N, M; cin >> N >> M;
    vector<Int> A(N), B(M);
    for (auto &a : A) cin >> a;
    for (auto &b : B) cin >> b;
    auto C = convolve(A, B);
    for (int i = 0; i < C.size(); i++) {
        cout << C[i] << " \n"[i + 1 == C.size()];
    }
    return 0;
}


Measured memory_bytes: 44300
#include<bits/stdc++.h>
using namespace std;
#define ALL(A) A.begin(),A.end()
const long long mod=1000000007;
int main(){
    int r,g,b,n;
    cin>>r>>g>>b>>n;
    int sum=0,ans=0;
    for(int i=0;i*r<=n;i++){
        for(int j=0;i*r+j*g<=n;j++){
            if((n-i*r-j*g)%b==0){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pairSS
#define int long long
#define MOD 1000000007
int gcd(int a,int b){
  if(a==0){
    return b;
  }
  return gcd(b%a,a);
}
int lcm(int a,int b){
  return a*b/gcd(a,b);
}
int keta(int a){
  int count = 0;
  while(a!=0){
    a = a/10;
    count++;
  }
  return count;
}
signed main(){
  int n;
  cin >> n;
  int h[n];
  for(int i=0;i<n;i++){
    cin >> h[n-i-1];
  }
  bool ans = true;
  for(int i=0;i<n;i++){
    if(i==n-1){
      break;
    }
    if(h[i]+2<=h[i+1]){
      ans = false;
    } else if (h[i]+1==h[i+1]){
      h[i+1]=h[i+1]-1;
    }
  }
  if(ans){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 1024
while true
  n, m, h, k = gets.split.map(&:to_i)
  break if n == 0
  amd = Array.new(h){ Array.new(n) }
  score = n.times.map{ gets.to_i }
  m.times do
    a, b = gets.split.map(&:to_i)
    amd[b][a-1] = true
  end
  res = Array.new(n){ |i| i }
  bar = Array.new(n){ Array.new(n) }
  (h-1).downto(0) do |i|
    n.times do |j|
      if amd[i][j]
        res[j], res[j+1] = res[j+1], res[j]
        bar[res[j]][res[j+1]] = bar[res[j+1]][res[j]] = true
      end
    end
  end
  tmp = 0
  flag = Array.new(n)
  k.times do |i|
    tmp += score[res[i]]
    flag[res[i]] = true
  end
  ret = tmp
  n.times do |i|
    n.times do |j|
      if flag[i] && !flag[j] && bar[i][j]
        ret = [ret, tmp - score[i] + score[j]].min
      end
    end
  end
  p ret
end

Measured memory_bytes: 27092
#include<bits/stdc++.h>
#define N 4005
using namespace std;
int n,a,b,tot;
int ans[300005];
int main(){
	scanf("%d%d%d",&n,&a,&b);
	if (a+b>n+1||1ll*a*b<n)
		return puts("-1"),0;
	int r=n;
	for (int i=1;i<=b;i++){
		int j,R=r-1;
		for (j=1;j<a&&R>b-i;j++,R--);
		for (int k=j;k;k--)
			ans[++tot]=r+1-k;
		r-=j;
	}
	for (int i=1;i<=n;i++)
		printf("%d ",ans[i]);
}

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

#define int long long
#define INF ((int)1e18)
#define MAX 210000

int a[MAX];
vector<pair<int,int> > temp;

signed main(){
  int N, sum = 0, tsum = 0;

  cin>>N;

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

  for(int i = N-1; i >= 0; i--){
    int con = 1;
    
    while(temp.size() && temp[temp.size()-1].first > a[i]){
      pair<int,int> temp2 = temp[temp.size()-1]; temp.pop_back();
      tsum -= temp2.first*temp2.second;
      con+= temp2.second;
    }

    tsum += con*a[i];
    temp.push_back(make_pair(a[i],con));

    //cout<<tsum<<" "<<con<<" "<<a[i]<<" "<<i<<endl;
    sum += tsum;
  }

  cout<<sum<<endl;

  
  return 0;
}


Measured memory_bytes: 6896
#include "bits/stdc++.h"
#include "sstream"
#define EPS 1e-9
using namespace std;
const int N=1e3+5,OO=0x3f3f3f3f;
typedef long long ll;
const int mod=1e9+7;
char arr[N][N]; int n,m,dp[N][N];
int solve(int i,int j){
   if(i==n-1&&j==m-1)
       return 1;
   if(i==n||j==m)
       return 0;
    int &ret=dp[i][j];
    if(~ret)
        return ret;
    ret=0;
    if(i+1<n&&arr[i+1][j]=='.')
        ret=(ret%mod+solve(i+1,j)%mod)%mod;
    if(j+1<m&&arr[i][j+1]=='.')
        ret=(ret%mod+solve(i,j+1)%mod)%mod;
    return ret%mod;
}
int main() {
   scanf("%d%d",&n,&m);
  for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
          scanf(" %c",&arr[i][j]);
      memset(dp,-1, sizeof(dp));
    printf("%d",solve(0,0)%mod);
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define INF         1e9
#define fastRead    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;

const int MAX = 1e6 + 6;
int main()
{
    fastRead;
    map<string,int>mp;
    int t;
    cin>>t;
    while(t--) {
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<'\n';
    cout<<"WA x "<<mp["WA"]<<'\n';
    cout<<"TLE x "<<mp["TLE"]<<'\n';
    cout<<"RE x "<<mp["RE"]<<'\n';
    return 0;
    
}

Measured memory_bytes: 3636
N = int(input())
A = list(map(int,input().split()))
def factorize2(n): # 素因数分解　2次元素数リスト([素数,指数])
    i = 2
    m = 1
    table = []
    sign = -1
    while i * i <= n:
        j = 0
        while n % i == 0:
            n //= i
            j += 1
        if j != 0:
            table.append([i,j])
        if i >= 5:
            if sign < 0:
                sign = 1
                i = 6*m + sign
            else:
                m += 1
                sign = -1
                i = 6*m + sign
        elif i == 2:
            i += 1
        elif i == 3:
            i = 5
    if n > 1:
        table.append([n,1])
    return table # list
ans = 10**9
for i in range(N):
    d = factorize2(A[i])
    if d[0][0]==2:
        ans = min(ans,d[0][1])
    else:
        ans = 0
        break
print(ans)

Measured memory_bytes: 39152
import itertools

don = [int(input()) for i in range(5)]

final_time = float('inf')
for v in itertools.permutations(don):
  time = 0
  for j in v:
    while(time % 10 != 0):
      time += 1
    time += j
  final_time = min(final_time, time)
print(final_time)

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

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

  int n = s.size();
  long long ans = 0, cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'A') {
      ++cnt;
      while (i + 2 < n && s[i + 1] == 'B' && s[i + 2] == 'C')
        ans += cnt, i += 2;
    } else {
      cnt = 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#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;
	cout << k / 2 * ((k + 1) / 2) << endl;
}


Measured memory_bytes: 3528
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST
{
    static void Main()
    {
        Sol mySol = new Sol();
        mySol.Solve();
    }
}

class Sol
{

    public Sol()
    {

        long[] a = rla();

        if (a[2] - a[1] <= 0) { Console.WriteLine("delicious"); }
        else if (a[2] - a[1] <= a[0]) { Console.WriteLine("safe"); }
        else { Console.WriteLine("dangerous"); }
    }


    public void Solve()
    {

    }

    static String rs() { return Console.ReadLine(); }
    static int ri() { return int.Parse(Console.ReadLine()); }
    static long rl() { return long.Parse(Console.ReadLine()); }
    static double rd() { return double.Parse(Console.ReadLine()); }
    static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
    static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
    static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
    static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }


}

Measured memory_bytes: 11092
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    s = ns()
    t = ns()

    if s == t[:-1]:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 9664
#include <bits/stdc++.h>
using namespace std;
int calcsum(int a)
{

  if(a < 10)
    return a;
  else{
    int buf=a;
    buf/=10;
    buf*=10;
    return calcsum(buf/10)+a-buf;
  }

}
int main()
{
  int n,a,b;
  int ans=0;
  cin >> n >> a >> b;
  for(int i=1;i<=n;i++){
    int buf=calcsum(i);
    if(a<=buf&&b>=buf){
      ans+=i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: i64,
        M: i64,
    }
    println!("{}",(N-1)*(M-1));
}

Measured memory_bytes: 4352
n,m,c = map(int,input().split())
b = [int(x) for x in input().split()]
ans = 0
for s in range(n):
    a = [int(x) for x in input().split()]
    scr = sum([a[i]*b[i] for i in range(m)]) + c
    if scr > 0:
        ans += 1
print(ans)

Measured memory_bytes: 38256
import java.util.Scanner;
public class Main{
    public static void main (String [] args){
        Scanner sc =new Scanner(System.in);
      
        while(true){
        int H =sc.nextInt();
        int W =sc.nextInt();
        if(H==0 && W==0)break;
        while(H>0){
            for(int a=0;W>a;a++){
                System.out.print("#");
            }
            H--;
            System.out.println();
        }
      
        System.out.println();
    }
        sc.close();
   }
 
}


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

N = int(input().strip())+2
A = list(map(int,input().split()))+[N-1,N]
INF = N
dp = [[-INF for j in range(N)] for i in range(N)]
dpmax = -INF
dpmaxj = [-INF for i in range(N)]
score = 0
a,b,c,d,e = [i-1 for i in sorted(A[:5])]

if a == b == c:
  dp[d][e] = dp[e][d] = dpmaxj[d] = dpmaxj[e] = dpmax = 1
elif b == c == d:
  dp[a][e] = dp[e][a] = dpmaxj[a] = dpmaxj[e] = dpmax = 1
elif c == d == e:
  dp[a][b] = dp[b][a] = dpmaxj[a] = dpmaxj[b] = dpmax = 1
else:
  L = [a,b,c,d,e]
  for i in range(5):
    for j in range(i+1,5):
      p,q = L[i],L[j]
      dp[p][q] = dp[q][p] = dpmaxj[p] = dpmaxj[q] = 0
  dpmax = 0 

def update(i,j):
  dpmaxj[i] = max(dpmaxj[i],dp[i][j])
  dpmaxj[j] = max(dpmaxj[j],dp[i][j])

for i in range(N-3):
  prevdpmax = dpmax
  prevdpmaxj = dpmaxj[:]
  dpd = [dp[k][k] for k in range(N)]
  a,b,c = A[i*3+5:i*3+8]
  a -= 1
  b -= 1
  c -= 1
  prevdpka = [dp[i][a] for i in range(N)]
  prevdpla = [dp[a][i] for i in range(N)] 
  prevdpkb = [dp[i][b] for i in range(N)]
  prevdplb = [dp[b][i] for i in range(N)] 
  if a == b == c:
    score += 1
    continue
  elif a == b:
    for k in range(N):
      dp[k][c] = max(dp[k][c],max(prevdpka[k],prevdpla[k]) + 1)
      dp[c][k] = max(dp[c][k],max(prevdpka[k],prevdpla[k]) + 1)
      dpmax = max(dpmax,dp[k][c],dp[c][k])
      update(k,c)
      update(c,k)
  elif a == c:
    for k in range(N):
      dp[k][b] = max(dp[k][b],max(prevdpka[k],prevdpla[k]) + 1)
      dp[b][k] = max(dp[b][k],max(prevdpka[k],prevdpla[k]) + 1)
      dpmax = max(dpmax,dp[k][b],dp[b][k])
      update(k,b)
      update(b,k)
  elif b == c:
    for k in range(N):
      dp[k][a] = max(dp[k][a],max(prevdpkb[k],prevdplb[k]) + 1)
      dp[a][k] = max(dp[a][k],max(prevdpkb[k],prevdplb[k]) + 1)
      dpmax = max(dpmax,dp[k][a],dp[a][k])
      update(k,a)
      update(a,k)
  dp[b][c] = max(dp[b][c],dpd[a] + 1)
  dp[c][b] = max(dp[c][b],dpd[a] + 1)
  dp[a][c] = max(dp[a][c],dpd[b] + 1)
  dp[c][a] = max(dp[c][a],dpd[b] + 1)
  dp[a][b] = max(dp[a][b],dpd[c] + 1)
  dp[b][a] = max(dp[b][a],dpd[c] + 1)
  dpmax = max(dpmax,dp[b][c],dp[a][c],dp[a][b],dp[c][b],dp[c][a],dp[b][a])
  
  dp[a][b] = max(0,dp[a][b],prevdpmax)
  dp[b][a] = max(0,dp[b][a],prevdpmax)
  dp[b][c] = max(0,dp[b][c],prevdpmax)
  dp[c][b] = max(0,dp[c][b],prevdpmax)
  dp[a][c] = max(0,dp[a][c],prevdpmax)
  dp[c][a] = max(0,dp[c][a],prevdpmax)
  update(a,b)
  update(a,c)
  update(b,a)
  update(b,c)
  update(c,a)
  update(c,b)
  for j in range(N):
    dp[j][a] = max(dp[j][a],prevdpmaxj[j])
    dp[j][b] = max(dp[j][b],prevdpmaxj[j])
    dp[j][c] = max(dp[j][c],prevdpmaxj[j])
    dp[a][j] = max(dp[a][j],prevdpmaxj[j])
    dp[b][j] = max(dp[b][j],prevdpmaxj[j])
    dp[c][j] = max(dp[c][j],prevdpmaxj[j])
    update(j,a)
    update(j,b)
    update(j,c)
    update(a,j)
    update(b,j)
    update(c,j)

print(max(dp[N-2][N-1],dp[N-1][N-2])+score)

Measured memory_bytes: 130812
n, k = list(map(int, input().split()))
count = 0
#when k <= i < j,  i % j >= k
if k == 0:
    print(n ** 2)
    exit()
for i in range(1, n + 1):
    if i <= k:
        continue
    count += max(0, (n % i) - k + 1)
    count += (n // i) * (i - k)
print(count)


Measured memory_bytes: 3060
#include<stdio.h>
#define N 44

int F[N];

int fibonacci(n){
  if(n == 1 || n == 0){
    return F[n] = 1;
  }
  if(F[n]) return F[n];

  return F[n] = fibonacci(n - 2) + fibonacci(n - 1);
}

int main(){
  int n;
  scanf("%d",&n);
  printf("%d\n",fibonacci(n));
  return 0;
  
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<N;i++)
#define For(i,f,t) for(int i=f;i<t;i++)
typedef long long ll;
typedef vector<ll> vll;
int main(){
  int N; cin>>N;
  vll a(N+1); a[0] = 0;
  For(i,1,N+1) cin>>a[i];
  rep(i,N) a[i+1] += a[i];
  sort(a.begin(),a.end());
  ll ans = 0;
  int cnt = 0;
  rep(i,N){
    ans += cnt;
    if(a[i+1] == a[i]) cnt++;
    else if(cnt) cnt = 0;
  }
  ans += cnt;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t;
    }
    return n*rep_jijo(n,x-1);
}

int main(){
    int n;
    cin >> n;
    cout << n*(n+1)/2 <<endl;
    return 0;
}



Measured memory_bytes: 256
a, b, c, d = gets.chomp.split.map(&:to_i)

c_cnt = b/c - (a-1)/c
d_cnt = b/d - (a-1)/d

g = c.lcm(d)
g_cnt = b/g - (a-1)/g

puts (b - a + 1) - (c_cnt + d_cnt - g_cnt)


Measured memory_bytes: 3836
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll a,b;
  cin>>a>>b;
  ll mx=max(a,b);
  ll mn=min(a,b);
  cout<<max(mx+mx-1,mx+mn)<<endl;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)turn idx;
#define deg_to_rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad_to_deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> cntwa(N+1, 0);
  int wa_ans = 0;
  set<int> s;
  int p;
  string S;
  rep(i, 0, M) {
    cin >> p >> S;
    if (S == "AC") {
      // まだACしていない場合
      if (s.find(p) == s.end()) {
        s.insert(p);
        wa_ans += cntwa[p];
      }
    } else if (S == "WA") {
      cntwa[p]++;
    }
  }
  cout << (int)s.size() << " " << wa_ans << endl;
};


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

int H,W;
char t[2005][2005];


int mp[2005][2005];
int h,w;

int haji(int);

int main(){
  scanf("%d %d",&H,&W);
  for(int i=0;i<H;i++){
    scanf("%s",t[i]);
  }
  
  for(int i=1;i<H;i++){
    for(int j=1;j<W;j++){

      int ca=0,cb=0;
      for(int di=0;di<2;di++)
        for(int dj=0;dj<2;dj++)
          if(t[ i-di] [ j - dj ] == '.')ca++;
          else cb++;
      
      int flg=0;
      if(ca==1 && cb==3)flg=1;
      if(ca==3&&cb==1)flg=1;
      mp[i-1][j-1]=flg;
      
    }
  }
  h=H-1;
  w=W-1;
  int ans=haji(0);
  ans=max( ans, max(H,W) );
  cout<<ans<<endl;
  return 0;
}


 
struct dat{int h,i;};
 
int calc(int A[],int f){
  stack <dat> S;
  int res = 0;
  for(int i=0;i<=w;i++){
    int h = A[i];
    if(S.empty() || S.top().h < h) S.push((dat){h,i});
    else if(S.top().h > h){
      int ni = i;
      while(!S.empty() && S.top().h > h){
        dat t = S.top(); S.pop();
        ni = t.i;
        
        if(f==0 && i-t.i>0 && t.h>0){
          int area = (i - t.i + 1) * ( t.h + 1);
          res = max(res,area);
        }
        if(f==1){
          int area = (i - t.i ) * ( t.h );
          res = max(res,area);
        }
      }
      res = max(res,(i-ni)*h);
      S.push((dat){h,ni});
    }
  }
  return res;
}
 
int haji(int f){

   
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)mp[i][j]=!mp[i][j];
   
  for(int j=0;j<w;j++)
    for(int i=1;i<h;i++)if(mp[i][j]) mp[i][j] = mp[i-1][j]+1;
 
 
  //cout<<endl;for(int i=0;i<h;i++){for(int j=0;j<w;j++)cout<<mp[i][j]<<" ";cout<<endl;}
  int ans = 0;
  for(int i=0;i<h;i++)ans = max(ans,calc(mp[i],f));
  
  return ans;
}


Measured memory_bytes: 19968
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    ll N;
    cin >> N;
    int cnt = 1;
    for (int i = 2; (ll)i * i <= N; ++i) {
        if (N % i)
            continue;
        ll tmp = N;
        while (tmp % i == 0)
            tmp /= i;
        if (tmp % i == 1)
            cnt++;
    }

    if (N > 2) {
        N--;
        for (int i = 1; (ll)i * i <= N; ++i) {
            if (N % i)
                continue;
            if (i == N / i || i == 1)
                cnt++;
            else
                cnt += 2;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		int ma = Integer.parseInt(str[1]);
		int mb = Integer.parseInt(str[2]);

		int a[] = new int[n];
		int b[] = new int[n];
		int c[] = new int[n];

		for (int i = 0; i < n; i++) {
			str = br.readLine().split(" ");

			a[i] = Integer.parseInt(str[0]);
			b[i] = Integer.parseInt(str[1]);
			c[i] = Integer.parseInt(str[2]);
		}

		long dp[][][] = new long[51][510][510];

		for (int i = 0; i < 51; i++) {
			for (int j = 0; j < 510; j++) {
				Arrays.fill(dp[i][j], Integer.MAX_VALUE);
			}
		}

		dp[0][0][0] = 0;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 500; j++) {
				for (int k = 0; k < 500; k++) {
					if (dp[i][j][k] >= Integer.MAX_VALUE)
						continue;

					dp[i + 1][j][k] = Math.min(dp[i + 1][j][k], dp[i][j][k]); // i番目の薬を選ばなかった時
					dp[i + 1][j + a[i]][k + b[i]] = Math.min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]); // i番目の薬を選んだ時
				}
			}
		}

		long ans = Integer.MAX_VALUE;
		for (int j = 1; j < 500; j++) {
			for (int k = 1; k < 500; k++) {
				if (j * mb != k * ma)
					continue;

				ans = Math.min(ans, dp[n][j][k]);
			}
		}

		if (ans < Integer.MAX_VALUE)
			System.out.println(ans);
		else
			System.out.println("-1");
	}
}


Measured memory_bytes: 188756
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
typedef priority_queue<int> p_queue;
typedef long long ll;
//prev_permutation(a,a+3);
int read(){
	char c=getchar();
	int sum=0;
	while(c>'9'||c<'0')c=getchar();
	while(c<='9'&&c>='0')sum=sum*10+c-'a',c=getchar();
	return sum;
}
int n;
int a[10],b[10];
int x[10];
int fir,sec;
int cnt;
bool check(){
	for(int i=0;i<n;i++){
		if(a[i]!=x[i])return 0;
	}
	return 1;
}
bool check1(){
	for(int i=0;i<n;i++){
		if(b[i]!=x[i])return 0;
	}
	return 1;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>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++){
		x[i]=i+1;
	}
	do{
//		for(int i=0;i<n;i++)cout<<x[i]<<' ';
//		cout<<'\n';
		cnt++;
        if(check())fir=cnt;
        if(check1())sec=cnt;
    }
	while ( next_permutation(x,x+n) );
//    cout<<fir<<' '<<sec<<'\n';
    cout<<max(fir-sec,sec-fir);
	return 0;
}


Measured memory_bytes: 256
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

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

def main():
    n = int(input())
    Present = [[] for _ in range(n)] # 人による
    for i in range(n):
        a = int(input())
        for j in range(a):
            x,y = readInts()
            Present[i].append([x-1,y]) # 0-indexed
    #print(Present)
    ans = 0
    # こっから、誰が正直者で、正直者ではないかをbit全探索
    for bit in range(1 << n):
        cnt = 0
        for i in range(n):
            if bit & (1 << i): # フラグが立っていたらそいつは正直者
                cnt += 1
                for x,y in Present[i]:
                    if y != (bit >> x & 1):
                        break
                else:
                    continue
                break
        else:
            ans = max(ans,cnt)
    print(ans)
if __name__ == '__main__':
  main()


Measured memory_bytes: 5616
n, k = map(int, input().split())
a = list(map(int, input().split()))

t = 0
while (k >> t) != 0:
    t += 1

cnts = [0] * t
for i in range(n):
    for j in range(t):
        if (a[i] & (1 << j)) != 0:
            cnts[j] += 1

x = 0
for i in reversed(range(t)):
    p = cnts[i] # ビットが立っている数
    if p < n - p and (x | (1 << i)) <= k:
        x = x | (1 << i)

print(sum(x ^ p for p in a))

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string a;
  cin >> a;
  int n = (int) a.length();
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      int ok = 1;
      for (int u = i; u <= j; u++) {
        if (a[u] != 'A' && a[u] != 'T' && a[u] != 'C' && a[u] != 'G') {
          ok = 0;
        }
      }
      if (ok) {
        ans = max(ans, j - i + 1);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            Char[] a = Console.ReadLine().ToCharArray();
            string output = "Good";
            for(int i=0; i<a.Length-1; i++)
            {
                if (a[i].Equals(a[i + 1]))
                {
                    output = "Bad";
                }
            }

            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	map<ll,ll>ch;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		ch[x]++;
		if(ch[x]==2){
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
	// your code goes here
	return 0;
}

Measured memory_bytes: 15940
n,m = map(int,input().split())
f = [False for i in range(n)]
ac = 0
wa = [0 for i in range(n)]
for i in range(m):
  p,s = input().split()
  p = int(p) - 1
  if not f[p]:
    if s == "WA":
      wa[p] += 1
    else:
      f[p] = True
      ac += 1
w = 0
for e,c in zip(f,wa):
  if e:
    w += c
print(ac,w)
  

Measured memory_bytes: 10760
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using ll = long long;

int main() {
    int N, K;
    cin >> N >> K;
    int count = 0;
    int a = 1;
    while (a <= K && count < N) {
        ++count;
        a *= 2;
    }
    while (count < N) {
        ++count;
        a += K;
    }
    cout << a << endl;
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  
  if(s == "RRR")cout << 3 << endl;
  else if(s == "RRS")cout << 2 << endl;
  else if(s == "SRR")cout << 2 << endl;
  else if(s == "SSS")cout << 0 << endl;
  else cout << 1 << endl;
}

Measured memory_bytes: 3620
# 入力
N,Q = map(int,input().split())
S = input()
# 0-indexed
query = [[int(e)-1 for e in input().split()] for _ in range(Q)]

# 開区間で持つ
acc = [0]*(N+1)
# [0,0)は何も含まない 更新は1から
for i in range(1,N):
    # 累積和 とりあえず前の値と同じにする
    # 開区間なのでS[i]を見るときはacc[i+1]を見る
    acc[i+1] = acc[i]
    if S[i-1] == "A" and S[i] == "C":
        # 条件を満たすなら+1
        acc[i+1] += 1

for l,r in query:
    # 開区間だからr+1,lになる
    # 閉区間と比べてl==0の場合分けが不必要
    ans = acc[r+1] - acc[l]
    # ただし、S[l-1]がAかつS[l]がCとなる場合は帳尻合わせに-1する
    if S[l-1] == "A" and S[l] == "C":
        ans -= 1
    print(ans)

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

int main()
{
    ll a;
    ll b, n;
    cin >> a >> b >> n;
    ll ans=floor((double)(a*min(b-1,n))/b)-a*floor((double)min(b-1,n)/b);
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 3660
// #define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  lint n, a, b;
  std::cin >> n >> a >> b;
  a--,b--;
  if ((b-a)%2==0) {
    lint ans = (b-a) /2;
    std::cout << ans << std::endl;
    return 0;
  }
  lint x = (a+b+1)/2;
  lint y = (n-1-a + n-1-b + 1)/2;
  // debug(x,y);
  lint ans = std::min(x,y);
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n, m;
	cin >> n >> m;
	int s[m];
	int c[m];
	zip(i, 0, m)  cin >> s[i] >> c[i];
	int flag = 0;
	map<int, int>mt;
	vector<int>ch(n);
	zip(i, 0, n)
	{
		ch[i] = 0;
	}
	zip(i, 0, m)
	{
		int x = mt[s[i]];
		if (s[i] > n)
		{
			flag = 1;
			break;
		}
		else if (s[i] == 1 && c[i] == 0 && n > 1)
		{
			flag = 1;
			break;
		}
		else if (mt[s[i]] == 0)
		{
			mt[s[i]] = c[i];
			ch[s[i] - 1] = (c[i]);
		}
		else if (x != c[i])
		{
			flag = 1;
			break;
		}

	}
	if (ch[0] == 0 && n > 1)
	{
		ch[0] = 1;
	}
	else if (ch[0] == 0 && n == 1)
	{
		ch[0] = 0;
	}
	if (flag == 1)
	{
		cout << -1 << en;
	}
	else
	{

		zip(i, 0, n)
		{
			cout << ch[i];
		}
		cout << en;
	}

	return 0;
}



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

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        String input = br.readLine();
        String[] input_array = input.split(" ");
        int result = 0;

        if(Integer.parseInt(input_array[0]) == 1){
          result += 300000;
        }else if(Integer.parseInt(input_array[0]) == 2){
          result += 200000;
        }else if(Integer.parseInt(input_array[0]) == 3){
          result += 100000;
        }

        if(Integer.parseInt(input_array[1]) == 1){
          result += 300000;
        }else if(Integer.parseInt(input_array[1]) == 2){
          result += 200000;
        }else if(Integer.parseInt(input_array[1]) == 3){
          result += 100000;
        }

        if(Integer.parseInt(input_array[0]) == 1 && Integer.parseInt(input_array[1]) == 1){
          result += 400000;
        }

        System.out.println(result);
      }
    }
}

Measured memory_bytes: 23124
S = list(input())
N = len(S)

def dp(s, i, used, limit):
  if i == N - 1:
    if used == limit:
      return eval(''.join(s))
    else:
      return 0
  if used > limit:
    return 0
  splus = s[:]
  splus[i] += '+'
  ret = dp(splus[:], i + 1, used + 1, limit) + dp(s[:], i + 1, used, limit)
  return ret

ret = 0
for p in range(N):
  ret += dp(S[:], 0, 0, p)

print(ret)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>
#include <cstdio>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;
using P = pair<int,int>;
using TP = tuple<int,int,int>;

int main() {
    int h,w,ch,cw,dh,dw;
    scanf("%d %d %d %d %d %d",&h, &w,&ch,&cw,&dh,&dw);

    char s[h+1][w+1];
    for (int i=0; i<h; i++) {
        scanf("%s",s[i]);
    }

    vector num(h, vector(w,-1));

    const vector dx = {-1,0,+1,0};
    const vector dy = {0,+1,0,-1};

    deque<TP> q;
    q.emplace_back(0, ch-1,cw-1);
    while(!q.empty()) {
        auto [c,y,x] = q.front(); q.pop_front();
        if (x<0 || w<=x) continue;
        if (y<0 || h<=y) continue;
        if (s[y][x] == '#') continue;
        if (num[y][x]>=0 && num[y][x]<=c) continue;
        num[y][x] = c;


        for (short i=0; i<4; i++) {
            const int xi = x + dx[i];
            const int yi = y + dy[i];
            q.emplace_front(c,yi,xi);
        }

        for (short i=-2; i <=2; i++) {
            for (short j=-2; j<=2; j++) {
                const int xi = x + j;
                const int yi = y + i;
                q.emplace_back(c+1,yi, xi);
            }
        }
    }


    cout << num[dh-1][dw-1] << endl;
}

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

typedef struct _data{
	int value;
	struct _data *next;
} data;

void push(data **p, int val)
{
	data *d = (data*)malloc(sizeof(data));
	d->value = val;
	d->next = *p;
	*p = d;
}

int pop(data **p)
{
	int val = (*p)->value;
	data *w = *p;
	*p = (*p)->next;
	free(w);
	return val;
}

void terminate(data *p)
{
	data *w;
	while (p != NULL)
	{
		w = p;
		p = p->next;
		free(w);
	}
}

int main()
{
	data *head = NULL;
	char w[8];
	int a, b;
	
	while (scanf("%7s",w) != EOF)
	{
		switch (w[0])
		{
			case '+':
				a = pop(&head);
				b = pop(&head);
				push(&head,a + b);
				break;
			case '-':
				a = pop(&head);
				b = pop(&head);
				push(&head,b - a);
				break;
			case '*':
				a = pop(&head);
				b = pop(&head);
				push(&head,a * b);
				break;
			default:
				push(&head,atoi(w));
				break;
		}
	}

	printf("%d\n",pop(&head));

	terminate(head);

	return 0;
}

Measured memory_bytes: 1852
#include <iostream>
#include <vector>
#define INF (int)1e9

int bellman_ford(int m, int p, int q, std::vector<std::vector<std::pair<int, int> > > v) {
    std::vector<int> rvec(m, INF);
    bool flag;
    rvec[p] = 0;
    int value;
    int target;

    do{
        flag = false;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < v[i].size(); j++) {
                value = v[i][j].first;
                target = v[i][j].second;
                if (rvec[target] > rvec[i] + value) {
                    rvec[target] = rvec[i] + value;
                    flag = true;
                }
            }
        }
    } while(flag);

    return rvec[q];
}

int main(void) {
    int n;
    int m;

    int a;
    int b;
    int cost;
    int time;

    int k;

    int p;
    int q;
    int r;

    int res;

    while (true) {
        std::cin >> n >> m;
        if (n == 0 && m == 0) {
            break; 
        }

        std::vector<std::vector<std::pair<int, int> > > vcost(m);
        std::vector<std::vector<std::pair<int, int> > > vtime(m);

        for (int i = 0; i < n; i++) {
            std::cin >> a >> b >> cost >> time;
            --a;
            --b;
            vcost[a].push_back(std::make_pair(cost, b));
            vcost[b].push_back(std::make_pair(cost, a));
            vtime[a].push_back(std::make_pair(time, b));
            vtime[b].push_back(std::make_pair(time, a));
        }

        std::cin >> k;

        for (int i = 0; i < k; i++) {
            std::cin >> p >> q >> r;
            --p;
            --q;

            // ????????????????????????
            if (r == 0) {
                res = bellman_ford(m, p, q, vcost);
            } else {
                res = bellman_ford(m, p, q, vtime);
            }
            std::cout << res << std::endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3088
n=int(input())
#a,b=map(int,input().split())
vl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

vl.sort()
#ans=(vl[0]+vl[1])/2.0
ans=vl[0]
for i in range(1,n):
    ans=(ans+vl[i])/2

print('{:.9f}'.format(ans))

Measured memory_bytes: 2940
#include<stdio.h>

int main(void){
        int n, a[4];
        scanf("%d", &n);
        for(int i=0; i<4; i++){
                a[3-i] = n%10;
                n /= 10;
        }

        for(int i=0; i<8; i++){
                int r = a[0];
                for(int j=0; j<3; j++){
                        if((i>>j)&1) r += a[j+1];
                        else r -= a[j+1];
                }
                if(r==7){
                        printf("%d", a[0]);
                        for(int j=0; j<3; j++){
                                if((i>>j)&1) printf("+");
                                else printf("-");
                                printf("%d", a[j+1]);
                        }
                        puts("=7");
                        return 0;
                }
        }
        return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	long a=sc.nextLong(),v=sc.nextLong(),b=sc.nextLong(),w=sc.nextLong(),t=sc.nextLong();
    
    long g=0;
    
      if(a<b){
        if(a+(long)Math.abs(v)*t<b+(long)Math.abs(w)*t){
          System.out.println("NO");
        }else{
          System.out.println("YES");
        }
      }else{
        if(a-(long)Math.abs(v)*t<=b-(long)Math.abs(w)*t){
          System.out.println("YES");
        }else{
          System.out.println("NO");
        }
      }
      
      
    
    
    
  }
}


Measured memory_bytes: 35784
#include <iostream>
#include <string>
using namespace std;
 
int main (void) {
  string a, b;
  cin >> a >> b;
  int c = stoi(a + b);
  for(int i = 0; i <= 1000; i++) {
    if (i * i == c) {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll mod = 1e9+7;
 
ll fpow(ll a, ll b){
 
	if(b == 0)
		return 1ll;
	if(b == 1)
		return a;
	
	ll val = fpow(a,b/2)%mod;
 
	ll res = (val*val)%mod;
	if(b%2 == 1)
		return (res*a)%mod;
	return res;
}
bool comp(pair<ll,ll> p1, pair<ll,ll> p2){
	return p1.first + p1.second < p2.first + p2.second;
}
 
int main(){
 
	ll n;
	cin >> n;
	if(n == 1){
		cout << 0 << "\n";
	}
	else{
		ll ans = 100*mod + fpow(10,n) + fpow(8,n);
		ans -= 2*fpow(9,n);
		cout << ans%mod << "\n";
		
	}
 
	
	
}

Measured memory_bytes: 3608