akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    INT(h,w);
    vector2d(char,maze,h,w);
    vector2d(int,dp,h,w);
    in(maze);
    rep(y,h){
        rep(x,w){
            if(y==0){
                if(x==0)dp[y][x]=(maze[y][x]=='#');
                else dp[y][x]=dp[y][x-1]+(maze[y][x]!=maze[y][x-1]&&maze[y][x]=='#');
            }else{
                if(x==0)dp[y][x]=dp[y-1][x]+(maze[y][x]!=maze[y-1][x]&&maze[y][x]=='#');
                else{
                    dp[y][x]=min(dp[y-1][x]+(maze[y][x]!=maze[y-1][x]&&maze[y][x]=='#'),
                    dp[y][x-1]+(maze[y][x]!=maze[y][x-1]&&maze[y][x]=='#'));
                }
            }
        }
    }
    out(dp[h-1][w-1]);
}

Measured memory_bytes: 3792
inputs = Array.new
while line = $stdin.gets
  inputs << line.chomp
end
N, K = inputs[0].split(" ").map(&:to_i)
h = inputs[1..-1].map(&:to_i)

sorted = h.sort

i = 0
ans = 1000000000000000000000000000000000
while i <= N - K
  tmp = sorted[i+K-1] - sorted[i]
  ans = tmp if ans > tmp
  i += 1
end

puts ans


Measured memory_bytes: 10360
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
#define S    1048576
using namespace std;
char I[S+1],*Is=I,*It=I;
inline char gc(){return Is==It?((It=(Is=I)+fread(I,1,S,stdin))==I?EOF:*Is++):*Is++;}
//char gc(){return getchar();}
int gi(){
    char c=gc();
    int x=0;
    while(c<48)c=gc();
    while(c>47)x=x*10+c-48,c=gc();
    return x;
}
int n,tot,b[200005],c[200005],nx[200005],he[100005],s[100005];
ll ans;
void add(int x,int y,int z){
    ++tot;
    b[tot]=y,c[tot]=z;
    nx[tot]=he[x],he[x]=tot;
}
void dfs(int x,int y){
    s[x]=1;
    int ss=0;
    for(int i=he[x];i;i=nx[i]){
        int z=b[i];
        if(y==z) continue;
        dfs(z,x);
        s[x]+=s[z];
        ans+=c[i]*2ll*min(s[z],n-s[z]);
        if(s[z]*2==n)ans-=c[i];
        if(s[z]>ss)ss=s[z];
    }
    if(n-s[x]>ss)ss=n-s[x];
    if(ss*2<n){
        int o=orz;
        for(int i=he[x];i;i=nx[i])if(c[i]<o)o=c[i];
        ans-=o;
    }
}
int main(){
    n=gi();
    for(int i=1;i<n;++i){
        int x,y,z;
        x=gi();y=gi();z=gi();
        add(x,y,z);
        add(y,x,z);
    }
    dfs(1,0);
    printf("%lld\n",ans);
    //system("pause");
    return 0;
}


Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll MAX = 510000;
ll fac[MAX],inv[MAX],finv[MAX];

void combination(){
	fac[0] = fac[1] = 1;
	inv[1] = 1;
	finv[0] = finv[1] = 1;
	for(int 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 comb(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;
}

int main(){
  combination();
  ll N,K;
  cin>>N>>K;
  for(int i = 1;i<=K;i++){
    cout << comb(N-K+1,i)*comb(K-1,i-1)%MOD << endl;
  }
  return 0;
}

Measured memory_bytes: 12160
import sys

def I(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))

def main():
    N = I()
    a = LI()
    t = [0, 0, 0]
    for ai in a:
        t[ai-1] += 1
    A, B, C = t
    E = B+C

    dp = [[0 if (i+j==0) else N/(i+j) for j in range(E+1)] for i in range(N+1)]

    for k in range(C+1):
        for i in range(N+1):
            dp[i][E] = 0 if (i+E+k==0) else N/(i+E+k)
        for j in range(E+1):
            for i in range(N+1):
                z = i+j+k
                if (not z):
                    continue
                d = dp[i][j]
                if (i<N):
                    dp[i+1][j] += (i+1)*d/(z+1)
                if (i>0) and (j<E):
                    dp[i-1][j+1] += (j+1)*d/z
                if (j>0) and (k<C):
                    dp[i][j-1] = (k+1)*d/z + N/z

    print(dp[A][B])

if __name__ == "__main__":
    main()


Measured memory_bytes: 43376
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

s=ss()
t=ss()
def lcs(str1, str2):
    '''文字列str1, str2の最長共通部分列(Lowest Common Subsequence, LCS)を求める
    計算量O(len(str1)*len(str2))  
    '''
    dp = [[0]*(len(str2) + 1) for _ in range(len(str1) + 1)]
    for i in range(len(str1)):
        for j in range(len(str2)):
            if str1[i] == str2[j]:
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
            else:
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])
 
    '''復元を実行
    最長の長さを求めるなら return dp[len(str1)][len(str2)] をするとよい
    '''
    res = ''
    i, j = len(str1), len(str2)
    while i > 0 and j > 0:
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            res = str1[i-1] + res
            i -= 1
            j -= 1
    return res
print(lcs(s,t))

Measured memory_bytes: 135864
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

#n = int(input)
#h,w = [int(i) for i in readline().split()]
#n,k,s = [int(i) for i in read().split()]

n = int(input())
a = [int(i)-1 for i in readline().split()]
b = [int(i)-1 for i in readline().split()]

N = 1<<n
ans = INF = 10**9
for mask in range(N):
    bucket = [[] for _ in range(50)]
    for i in range(n):
        bucket[a[i] if mask&(1<<i) else b[i]].append(i)
    
    cnt = 0
    res = []
    #print(bucket)
    #if mask == 3: print(bucket[:5])
    for bi in bucket:
        if not bi: continue
        l = len(bi)
        o = [i for i in bi if ((mask>>i)^i)&1==0]
        e = [i for i in bi if ((mask>>i)^i)&1==1]
        odd = len(o)
        even = len(e)
        #if mask == 3: print(cnt,bi,o,e)
        if l%2 == 0:
            if odd != even: break
        else:
            if cnt%2==0:
                if even != odd+1: break
            else:
                if odd != even+1: break
        
        #偶奇を突破したら
        for i in range(l):
            res.append(e[i//2] if (i+cnt)%2==0 else o[i//2])
        cnt += l
        
        
    else: #うまくいったら
        num = 0
        for i in range(n):
            for j in range(i+1,n):
                if res[i] > res[j]: num += 1
        #print(mask,num,res)
        ans = min(ans,num)                

if ans == INF: print(-1)
else: print(ans)




Measured memory_bytes: 71132
// Problem : C - A x B + C
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

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

#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define pb push_back
#define fi first
#define se second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()

const ll inf=0x3f3f3f3f3f3f3f3f;
const ll N = 1e6;
vi findDivisors() 
{ 
  
    // Array to store the count 
    // of divisors 
    ll n = N;
    vi div(n + 1, 0); 
  
    // For every number from 1 to n 
    for (ll i = 1; i <= n; i++) { 
  
        // Increase divisors count for 
        // every number divisible by i 
        for (ll j = 1; j * i <= n; j++) 
            div[i * j]++; 
    } 
  
    // Print the divisors 
    return div;
} 
  
// Driver cod
int main() {
    SPEED;
    vi v = findDivisors();
    ll n;
    cin>>n;
    ll ans = 0;
    for(ll c = 1; c < n; c++) {
    	ans += v[c];
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 11036
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        double[] a = new double[n];
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextDouble();
        }

        double tmp = 0;
        for (int i = 0 ; i < n ; i++) {
            tmp += 1 / a[i];
        }

        System.out.println(1 / tmp);
    }

}


Measured memory_bytes: 23380
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{

  int n;
  char s[105];
memset(s,0,sizeof(s));
cin >> s;
int m=strlen(s);
cout << s[0] << m-2 << s[m-1] << endl;

	return 0;
}


Measured memory_bytes: 256
#[test]
fn test_solve() {
    assert_eq!(solve("3 2\n4 1 5\n"), "3\n");
    assert_eq!(solve("13 17\n29 7 5 7 9 51 7 13 8 55 42 9 81\n"), "6\n");
    assert_eq!(solve("10 400000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n"), "25\n");
}
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();
    let m: usize = sc.read();
    let a: Vec<usize> = (0..n).map(|_| sc.read()).collect();

    let mut sum = vec![0; n + 1];
    for i in 0..n {
        sum[i + 1] = a[i] + sum[i];
    }

    use std::collections::HashMap;
    let mut map: HashMap<usize, usize> = HashMap::new();
    for i in 0..n + 1 {
        let m = sum[i] % m;
        if let Some(v) = map.insert(m, 1) {
            map.insert(m, v + 1);
        }
    }

    let ans: usize = map.iter().map(|(_, n)| n * (n - 1) / 2).sum();

    format!("{}\n", ans)
}
fn main() {
    let mut buf = String::new();
    use std::io::{Read, Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}


Measured memory_bytes: 14588
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;	//w, h

int n, w, d;
int id, pos;
vector<P> rects;

void cut(int old_id, int new_id, int type, int pos) {
	if (type == 0) {	//x???
		rects[new_id].first  = rects[old_id].first - pos;
		rects[new_id].second = rects[old_id].second;
		rects[old_id].first  = pos;
	}
	else {	//y???
		rects[new_id].first  = rects[old_id].first;
		rects[new_id].second = rects[old_id].second - pos;
		rects[old_id].second = pos;
	}
	
	//????????????????????±????????????????????????????????????
	for (int i = old_id; i < new_id - 1; i++) {
		swap(rects[i], rects[i + 1]);
	}
}

signed main() {
	rects.resize(200);
	
	while (cin >> n >> w >> d) {
		if (!n && !w && !d) break;
		rects[0] = P(w, d);
		
		for (int i = 0; i < n; i++) {
			cin >> id >> pos; id--;
			
			//cut
			int qw = rects[id].first;
			int qh = rects[id].second;
			
			pos %= (2 * (qw + qh));	//0???????????¨???
			
			if (pos < qw)
				cut(id, i + 1, 0, min(pos, qw - pos));
			else if (pos < qw + qh)
				cut(id, i + 1, 1, min(qw + qh - pos, qh - (qw + qh - pos)));
			else if (pos < 2 * qw + qh)
				cut(id, i + 1, 0, min(2 * qw + qh - pos, qw - (2 * qw + qh - pos)));
			else
				cut(id, i + 1, 1, min(2 * (qw + qh) - pos, qh - (2 * (qw + qh) - pos)));
		}
		
		vector<int> areas;
		for (int i = 0; i < n + 1; i++) areas.push_back(rects[i].first * rects[i].second);
		sort(areas.begin(), areas.end());
		for (int i = 0; i < n + 1; i++) {
			cout << areas[i];
			if (i < n) cout << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3124
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    cout << (n*3+m)/2 << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int n;
int a[100000];


long long calc(const vector<int> &sm, const vector<int> &la) {
	long long ret = 0;
	int m = la.front();
	if (sm.size() > la.size()) {
		rep(i, sm.size()) {
			if (i + 2 >= sm.size())ret += m - sm[i];
			else ret += (m - sm[i]) * 2;
		}
		rep(i, la.size()) {
			if (i < 0)ret += la[i] - m;
			else ret += (la[i] - m) * 2;
		}
	}
	else if( sm.size() < la.size()){
		rep(i, sm.size()) {
			if (i + 0 >= sm.size())ret += m - sm[i];
			else ret += (m - sm[i]) * 2;
		}
		rep(i, la.size()) {
			if (i < 2)ret += la[i] - m;
			else ret += (la[i] - m) * 2;
		}
	}
	else {
		rep(i,sm.size()) {
			if (i + 1 >= sm.size())ret += m - sm[i];
			else ret += (m - sm[i]) * 2;
		}
		rep(i, la.size()) {
			if (i < 1)ret += la[i] - m;
			else ret += (la[i] - m) * 2;
		}
	}
	return ret;
}


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


	cin >> n;
	rep(i, n)cin >> a[i];
	sort(a, a + n);

	

	long long ans = calc(vector<int>(a, a + n / 2), vector<int>(a + n / 2, a + n));

	if (n % 2 == 1) {
		ans = max(ans, calc(vector<int>(a, a + n / 2 + 1), vector<int>(a + n / 2 + 1, a + n)));
	}
	


	
	cout << ans << endl;



	return 0;
}

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

vector<int> cost[90001];
int main() {
  int h, w, d;
  cin>>h>>w>>d;
  pair<int, int> p[h*w+1];
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      int a;
      cin>>a;
      p[a] = make_pair(i, j);
    }
  }
  for (int i=1; i<=d; i++) {
    cost[i].push_back(0);
    for (int j=i+d; j<=w*h; j+=d) {
      if (j - d >= 1) {
        cost[i].push_back(cost[i].back()
          + abs(p[j].first - p[j-d].first)
          + abs(p[j].second - p[j-d].second));
      }
    }
  }
  int q;
  cin>>q;
  for (int _=0; _<q; _++) {
    int l, r;
    cin>>l>>r;
    int mod = l % d;
    if (mod == 0) {
      mod = d;
      --l;
      --r;
    }
    cout<<cost[mod][r/d] - cost[mod][l/d]<<endl;
  }
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
using namespace std;
using pi = pair<int, int>;
using lint = long long;
const int MAXN = 100005;

int n;
vector<int> gph[MAXN];
int ret[MAXN], par[MAXN], chk[MAXN];

pi dfs(int x, int p){
	pi ret(0, x);
	for(auto &i : gph[x]){
		if(i == p) continue;
		par[i] = x;
		auto k = dfs(i, x);
		k.first++;
		ret = max(ret, k);
	}
	return ret;
}

int main(){
	scanf("%d",&n);
	for(int i=1; i<n; i++){
		int s, e; scanf("%d %d",&s,&e);
		gph[s].push_back(e);
		gph[e].push_back(s);
	}
	int st = dfs(1, -1).second;
	int ed = dfs(st, -1).second;
	for(int j=ed; ; j=par[j]){
		chk[j] = j;
		if(j == st) break;
	}
	for(int i=1; i<=n; i++){
		if(!chk[i]){
			bool ok = 0;
			for(auto &j : gph[i]){
				if(chk[j]) ok = true;
			}
			if(!ok){
				puts("-1");
				return 0;
			}
		}
	}
	vector<int> v;
	for(int j=ed; ; j=par[j]){
		int cnt = 1;
		for(auto &k : gph[j]){
			if(!chk[k]) cnt++;
		}
		v.push_back(cnt);
		if(j == st) break;
	}
	v = min(v, vector<int>(v.rbegin(), v.rend()));
	int sum = 0;
	int p = 0;
	for(auto &i : v){
		for(int j=sum+2; j<=sum+i; j++){
			ret[++p] = j;
		}
		ret[++p] = sum + 1;
		sum += i;
	}
	for(int j=1; j<=n; j++) printf("%d ", ret[j]);
}


Measured memory_bytes: 15728
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rr(x,y) read(x);read(y)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
#define pb(x) push_back(x)
#define sss(str) scanf("%s",str+1)
#define ssf(x) scanf("%lf",&x)
#define aLL(x) x.begin(),x.end()
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef double dd;
typedef pair<int,int> pt;
const int N=2e5+5;
const int M=2e3+50;
const int INF=0x7fffffff;
const int mod=1e9+7;
const int sz=18;
const double eps=1e-10;
const double pi=acos(-1);
//***********************
int n,m;
char str[N];
int f[N];
int sum[N];
map<int,int> mm;
//***********************
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int qpow(int a,int p,int mo)
{
    int res=1;
    while(p){
        if(p&1) res=res*a%mo;
        a=a*a%mo;
        p>>=1;
    }
    return res;
}
int main()
{
    rr(n,m);
    sss(str);
    FOR(i,1,n) f[i]=str[i]-'0';
    if(m==2||m==5){
        LL ans=0;
        FOR(i,1,n){
            if(f[i]%m==0){
                ans+=1ll*i;
            }
        }
        cout<<ans<<endl;
        return 0;
    }
    for(int i=n;i>=1;i--){
        sum[i]=(sum[i+1]+f[i]*qpow(10,n-i,m))%m;
        //cout<<sum[i]<<endl;
        mm[sum[i]]++;
    }
    LL ans=0;
    for(int i=n+1;i>=2;i--){
        if(mm.count(sum[i])) ans+=mm[sum[i]];
        mm[sum[i-1]]--;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <deque>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;


int main(){
  long long N,a,ab,af,sb,sf;
  deque<int> A,S;
  multimap<int,string> list;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> a;
    A.push_back(a);
  }
  sort(A.begin(),A.end());
  S.push_back(A.back());
  A.pop_back();
  long long ans=0;
  while(!A.empty()){
    list.clear();
    ab=A.back();
    af=A.front();
    sb=S.back();
    sf=S.front();
    list.emplace(abs(ab-sb),"back_back");
    list.emplace(abs(ab-sf),"back_front");
    list.emplace(abs(af-sb),"front_back");
    list.emplace(abs(af-sf),"front_front");
    auto itr = list.rbegin();
    ans += itr->first;
    if(itr->second=="back_back"){
      A.pop_back();
      S.push_back(ab);
    }else if(itr->second=="back_front"){
      A.pop_back();
      S.push_front(ab);
    }else if(itr->second=="front_back"){
      A.pop_front();
      S.push_back(af);
    }else if(itr->second=="front_front"){
      A.pop_front();
      S.push_front(af);
    }else{
      cout << "ouch" <<endl;
    }
  }
  cout << ans << endl;
}
  

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

int main(){
    ll h, w;
    cin >> h >> w;
    if (h%3 == 0 || w%3 == 0){
        cout << 0 << endl;
        return 0;
    }
    int d[3] = {-1, 0, 1};

    ll ans = h * w;
    rep(y, 3){
        rep(x, 3){
            ll p = h / 3 + d[y];
            ll q = w / 2 + d[x];
            ll u = h / 2 + d[y];
            ll v = w / 3 + d[x];
            ll smx1 = max({p * w, (h-p)*q, (h-p)*(w-q)});
            ll smn1 = min({p * w, (h-p)*q, (h-p)*(w-q)});
            ll smx2 = max({v * h, (w-v)*u, (w-v)*(h-u)});
            ll smn2 = min({v * h, (w-v)*u, (w-v)*(h-u)});
            ans = min({ans, smx1 - smn1, smx2 - smn2});
        }
    }

    rep(a, 3){
        rep(b, 3){
            ll p = h / 3 + d[a];
            ll q = h / 3 * 2 + d[b];
            ll u = w / 3 + d[a];
            ll v = w / 3 * 2 + d[b];
            ll smx1 = max({p * w, (q-p) * w, (h-q) * w});
            ll smn1 = min({p * w, (q-p) * w, (h-q) * w});
            ll smx2 = max({u * h, (v-u) * h, (w-v) * h});
            ll smn2 = min({u * h, (v-u) * h, (w-v) * h});
            ans = min({ans, smx1 - smn1, smx2 - smn2});
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
using namespace std;
 
const long long INF = 1e7;
const long long N = 1e5+ 7;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;
 
long double a, n, b, c = 1, d , cnt , m , ans;
string s , s1 , s2;
set<char>st;
ll used[N];
vector<int>v;
int main()
{
   /// freopen("symposium.in" ,"r" ,stdin);
///freopen("symposium.out" , "w" ,  stdout);
    ios_base::sync_with_stdio(0);
cin >> s >> s1;
cin >> n >> m;
cin >> s2;
if( s2 == s )
    n --;
else
    m --;
cout << n << " " << m;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define MAX_M 10
#define MAX_N 10

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

int M,N,c;
int tile[MAX_M][MAX_N],opt[MAX_M][MAX_N],flip[MAX_M][MAX_N];

int get(int x,int y)
{
	int c=tile[x][y];
	for(int d=0;d<5;d++)
	{
		int x2=x+dx[d],y2=y+dy[d];
		if(0<=x2 && x2<M && 0<=y2 && y2<N)
			c+=flip[x2][y2];
	}
	return c%2;
}

int calc()
{
	for(int i=1;i<M;i++)
		for(int j=0;j<N;j++)
			if(get(i-1,j) !=0)
				flip[i][j]=1;
	for(int j=0;j<N;j++)
		if(get(M-1,j)!=0)
			return -1;
	int res=0;
	for(int i=0;i<M;i++)
		for(int j=0;j<N;j++)
			res+=flip[i][j];
	return res;
}

void solve()
{
	memset(opt,0,sizeof(opt));
	int res=-1;
	for(int i=0;i<1<<N;i++)
	{
		memset(flip,0,sizeof(flip));
		
		for(int j=0;j<N;j++)
			flip[0][N-j-1]=i>>j&1;
		int num=calc();
		if(num>=0)
		{
			res=num;
			memcpy(opt,flip,sizeof(flip));
		}
	}
	for(int i=0;i<M;i++)
		for(int j=0;j<N;j++)
			printf("%d%c",opt[i][j],j+1==N?'\n':' ');
}

int main()
{
	N=10;
	M=10;
	int x;
	scanf("%d",&x);
	for(c=0;c<x;c++)
	{
		for(int i=0;i<M;i++)
			for(int j=0;j<N;j++)
			{
				int t;
				scanf("%d",&t);
				tile[i][j]=t;
			}
		solve();
	}
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int m = max(a,max(b,c));
    cout << m * 10 + (a + b + c - m) << endl;
}


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

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

    if(a + b == c + d)
    {
        cout << "Balanced" << "\n";
    } else
    {
        cout << (a + b > c + d ? "Left" : "Right") << "\n";
    }

    return 0;
}


Measured memory_bytes: 3628
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
int main()
{
  int K;
  string S;
  cin >> S;
  cin >> K;
  vector<string> s;
  REP(i,S.length())REP(j,6) s.push_back(S.substr(i,j));
  sort(s.begin(),s.end());
  s.erase(unique(s.begin(),s.end()),s.end());

  cout << s[K] << endl;
  return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
char s[N];
int l[N],r[N],cnt;
int L[N],R[N];
set<char>jh;
string ans;
bool vis[30];
int main()
{
    scanf("%s",s+1);int jl=0;
    int len=strlen(s+1);
    for(int i=len;i>=1;i--){
        if(jh.size()==0)jl=i;
        jh.insert(s[i]);
        if(jh.size()==26){
            r[++cnt]=jl;
            l[cnt]=i;jh.clear();
        }
    }
    int n=cnt;
    for(int i=1,j=cnt;j>=1;j--,i++){
        L[i]=l[j];R[i]=r[j];
    }
    if(cnt==0){
        for(int i=1;i<=len;i++){
            vis[s[i]-'a']=1;
        }int p;
        for(int i=0;i<26;i++)if(vis[i]==0){p=i;break;}
        ans+=char(p+'a');cout<<ans<<endl;
        return 0;
    }
    int p=1;
    memset(vis,0,sizeof(vis));
    for(int j=1;j<L[1];j++)vis[s[j]-'a']=1;
    int pos=0;
    for(int j=0;j<26;j++)if(!vis[j]){pos=j;break;}
    ans+=char(pos+'a');
    while(p<=len&&s[p]!=pos+'a')p++;
    for(int i=1;i<=n;i++){
        memset(vis,0,sizeof(vis));
        p++;
        for(int j=p;j<=R[i];j++){
            vis[s[j]-'a']=1;
        }
        for(int j=0;j<26;j++)if(!vis[j]){pos=j;break;}
        ans+=char(pos+'a');
        while(p<=len&&s[p]!=pos+'a')p++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <stdio.h>
int main()
{
	while(1){
	int shina=0,nedan=0,coin=0;
	scanf("%d",&shina);
	if(shina==0){
		break;
	}
	nedan=1000-shina;
	while(nedan!=0){
	if(nedan>=500){
		nedan=nedan-500;
		coin++;
		}
	else if(nedan>=100){
		nedan=nedan-100;
		coin++;
		}
	else if(nedan>=50){
		nedan=nedan-50;
		coin++;
		}
	else if(nedan>=10){
		nedan=nedan-10;
		coin++;
		}
	else if(nedan>=5){
		nedan=nedan-5;
		coin++;
		}
	else if(nedan>=1){
		nedan=nedan-1;
		coin++;
		}
	}
	printf("%d\n",coin);
}
	return 0;
}


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

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

  bool h = false;

  for (int i = 0; i <= 25; i++) {
    for (int j = 0; j <= 14; j++) {
      if (((i*4)+(j*7)) == N) {
        h = true;
        break;
      }
    }
  }

  cout << (h ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int A,B,C,X;
    cin >> A >> B >> C >> X;
    int cnt = 0;
    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)cnt++;
            }
        }
    }
    cout << cnt << endl;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define hello777 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#include <string>
#define pie 3.14159265358979323846
constexpr int MOD = 1e9+7;
const int MAX= 1e5+5;
using namespace std;


ll gcd(int a, int b)
{ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
// 
//ll lcm(int a, int b)  
// {  
//    return a/gcd(a, b) *b;  
// }
//  
//int prime(int n)
//{
//	rep(i,2,n+1)
//	{
//		if(n%i==0)return i;
//	}
//	
//vector<unordered_set<int> > prime_factors(MAX,unordered_set<int>());
//int primes[MAX];
//int prefix[MAX][6];
//void sieve(){
//    //primes i stores the largest prime factor of a number....
//    for(int i=2;i<MAX;++i){
//        if(primes[i]!=0){
//            continue;
//        }
//        primes[i] = i;
//        for(int j=2*i;j<MAX;j+=i){
//            primes[j] = i;
//        }
//    }
//    
//    for(int i=2;i<MAX;++i){
//        int current = i;
//        
//        while(current!=1){
//            prime_factors[i].insert(primes[current]);
//            current = current/primes[current];
//        }
//    }
//    
//    for(int i=1;i<MAX;++i){
//        for(int k=1;k<=5;++k){
//            prefix[i][k] = prefix[i-1][k] + (prime_factors[i].size()==k);
//        }
//    }
//    
//}
void solve() 
{
	string s;
	cin>>s;
	ll ans=0;
	for(auto x:s)ans+=(x-'0');
	if(ans%9==0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

int main()
{
	hello777;
	int q=1;
	
//    cin>>q;
    while(q--)
    {   
      solve();
    }
}


Measured memory_bytes: 3732
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
    public static void main(String[] args) throws IOException
	{
        int n;
		int a; 
		int min;
		int max;
		int i;
        long sum=0;
         
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(br.readLine());
         
        min = Integer.MAX_VALUE;
        max = Integer.MIN_VALUE;
         
        String[] strAry = br.readLine().split(" ");
         
        for (i=0;i<n;i++) {
            a = Integer.parseInt(strAry[i]);
            if (a<min) min = a;
            if (a>max) max = a;
            sum += a;
        }
         
        System.out.println(min + " " + max + " " + sum);
    }
}

Measured memory_bytes: 28464
// AGC 39 A 途中
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007

int main(){
    string s; cin >> s;
    int k; cin >> k;
    ll c = 1, head = -1, tail = 0;
    ll ans = 0;
    ll len = s.length();
    for(int i = 1; i < len; i++){
        if(s[i-1] == s[i]){
            c++;
        }else{
            ans += c/2;
            if(head == -1) head = c;
            c = 1;
        }
    }
    ans += c/2;
    tail = c;
    ans *= k;
    if(head == -1){
        cout << len*k/2 << endl; return 0;
    }else if(s[0] == s[len-1]){
        ans -= (head/2 + tail/2 - (head+tail)/2)*(k-1);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

void solve(int t,int n){
	int sx,sy;
	vvi vv(200,vi(200,INF));
	rep(i,n){
		cin>>sx>>sy;
		sx+=100;sy+=100;
		vv[sx][sy]=-1;
	}
	cin>>sx>>sy;
	sx+=100,sy+=100;
	queue<pii> q;
	q.push(pii(sx,sy));
	vv[sx][sy]=0;
	int ans=1;
	while(!q.empty()){
		tie(sx,sy)=q.front();q.pop();
		if(vv[sx][sy]>=t)continue;
		rep(i,6){
			if(vv[sx+dx[i]][sy+dy[i]]<=vv[sx][sy]+1)continue;
			ans++;
			vv[sx+dx[i]][sy+dy[i]]=vv[sx][sy]+1;
			q.push(pii(sx+dx[i],sy+dy[i]));
		}
	}
	cout<<ans<<endl;

}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int t,n;
	while(cin>>t>>n,t|n)solve(t,n);
}


Measured memory_bytes: 3280
# 25
import itertools

n = int(input())
a = tuple(list(map(int,input().split())))
b = tuple(list(map(int,input().split())))
list = [num for num in range(1, n + 1)]

count = 1
aidx = bidx = 0
for i in itertools.permutations(list, n):
    if i == a: aidx = count
    if i == b: bidx = count
    if aidx != 0 and bidx != 0: break
    count += 1

print(abs(aidx - bidx))

Measured memory_bytes: 9048
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    REP(i,100) REP(j,100){
        if(4*i+7*j==N){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
 
}


Measured memory_bytes: 256
(* O(n√n) *)
open Hashtbl
let n = read_int ()
let h = create n
let factorize n =
  let g k v = if mem h k then replace h k @@ find h k + v else add h k v in
  let rec f c d m =
    if d > m || d * d > n then
      if c > 0 then g d c else if m > 1 then g m 1 else ()
    else
      if m mod d = 0 then f (c + 1) d @@ m / d
      else (if c > 0 then g d c; f 0 @@ d + 1) m in
  f 0 2 n
let divisor_count h = fold (fun _ c acc -> acc * (c + 1) mod 1_000_000_007) h 1
let rec f n = if n = 0 then divisor_count h else (factorize n; f @@ n - 1)
let _ = f n |> Printf.printf "%d\n"

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	
	bool flag = false;
	while(n && !flag) {
		if(n % 10 == 7) flag = true;
		n /= 10; 
	}
	
	if(flag) cout << "Yes" << endl; else cout << "No" << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const unsigned int M = 1000000007;
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b;
    while(cin>>a>>b){
        cout<<((a+b)%24)<<endl;
    }
}


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

using namespace std;

int main() {
  int i, j, k;
  char c1, c2;
  string S;
  int isYYMM = 0;
  int isMMYY = 0;
  
  cin >> S;
  
  c1 = S[0];
  i = c1 - '0';
  c2 = S[1];
  j = c2 - '0';
  k = i*10 + j;
  if (1 <= k && k <= 12) isMMYY = 1;
  
  c1 = S[2];
  i = c1 - '0';
  c2 = S[3];
  j = c2 - '0';
  k = i*10 + j;
  if (1 <= k && k <= 12) isYYMM = 1;
  
  if (isYYMM && isMMYY) cout << "AMBIGUOUS" << endl;
  else if (isYYMM) cout << "YYMM" << endl;
  else if (isMMYY) cout << "MMYY" << endl;
  else cout << "NA" << endl;

  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  int a,b,t;
  cin>>a>>b>>t;
  int x=t/a;
  cout<<x*b<<endl;
}


Measured memory_bytes: 256
from math import sqrt


N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

cnt = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        s = 0
        for d in range(D):
            s += (X[i][d] - X[j][d]) ** 2
        s = sqrt(s)
        if s.is_integer():
            cnt += 1
print(cnt // 2)



Measured memory_bytes: 3188
#!/usr/bin/env python3
import sys


def solve(N: int, X: "List[int]"):
    X.sort()
    m = 10000000
    for p in range(X[0], X[-1] + 1):
        s = 0
        for x in X:
            s += (x - p) ** 2
        if s < m:
            m = s

    print(m)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#ARC067-C
N=int(input())
CNT=[0 for i in range(N+1)]
for i in range(2,N+1):
    k=2
    while k<=i:
        if i%k==0:
            CNT[k]+=1
            i//=k
        else:
            k+=1
ans=1
for cnt in CNT:
    ans*=cnt+1
print(ans%(10**9+7))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define INF 1000000000001
#define DIM 100001
#define mod 1000000007
#define PI 3.1415926535897932384626433
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define T true
#define F false
#define fi first
#define endl "\n"
#define se second
#define DIM 100001
#define pb push_back
#define amen exit(0);
#define qwe return 0;
#define mod 1000000007
#define INF 1000000000001
#define gg cout<<"OPS"<<endl;
#define PI 3.1415926535897932384626433
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define time cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
typedef char ch;
typedef bool boll;
typedef string st;
typedef long long ll;
typedef long double ld;
typedef set < string > sst;
typedef set < long long > sll;
typedef unsigned long long ull;
typedef queue < long long > que;
typedef deque < long long > deq;
typedef vector < long long > vec;
typedef map < long long, long long > mll;
typedef pair < long long, long long > pll;
typedef pair < long long, unsigned long long > pul;
typedef vector < pair < long long, long long > > vpl;
typedef tree <ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> myset;
ll n,z,x,s;
int main()
{
     fast;
     ll a,b,c,d;
     cin>>a>>b>>c>>d;
     cout<<max({a*c,b*d,b*c,d*a})<<endl;
     //time;
}



Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <deque>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<m;i++)
template <typename Container> void P(const Container &c) {
    for (const auto& x : c) cout << x << ' '; cout << '\n';
}
const int MOD = 1000000007;
int main()
{
    int N; cin >> N;
    vector<int> A(N); REP(i, N) cin >> A[i];
    deque<int> d;
    bool reverse = false;
    REP(i, N) {
        if (!reverse) {
            d.push_back(A[i]);
        } else {
            d.push_front(A[i]);
        }
        reverse = !reverse;
    }
    if (!reverse) for (int i=0; i<d.size(); i++) cout << d[i] << ' ';
    else          for (int i=d.size()-1; i>=0; i--) cout << d[i] << ' ';
    cout << endl;
    return 0;
}


Measured memory_bytes: 3840
from collections import defaultdict
n = int(input())
L = list(map(int,input().split()))
li = [L[0]]
for i in range(1,n):
    li.append(L[i] + li[i-1])

dic = defaultdict(int)
for i in range(n):
    dic[li[i]] +=1

li2 = []
for k,v in dic.items():
    li2.append((k,v))

cnt = 0
for i in range(len(li2)):
    if li2[i][0] == 0:
        cnt += li2[i][1]
    cnt += li2[i][1]*(li2[i][1]-1)//2
print(cnt)

Measured memory_bytes: 48220
#include <bits/stdc++.h>
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t,k;
  cin >> t >> k;
  if (k == 1){
    cout << t - 1 << '\n';
    return 0;
  }
  vector<int> a(k);
  for (int i = 0; i < k; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  cout << max(0, a[k-1] * 2 - t - 1) << '\n';

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
ll sum;
vector<vector<int>> G;
vector<int> C;
vector<int> ans;
int id;
void dfs(int tmp, int par) {
  ans[tmp] = C[id];
  id++;
  if(par != -1) sum += ans[tmp];
  for(int ne: G[tmp]) {
    if(ne != par) {
      dfs(ne, tmp);
    }
  }
}
int main() {
  int N;
  cin >> N;
  G = vector<vector<int>>(N);
  rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  C = vector<int>(N);
  rep(i, N) cin >> C[i];
  sort(all(C), greater<int>());
  int root;
  rep(i, N) if(G[i].size() == 1) root = i;
  sum = 0;
  id = 0;
  ans = vector<int>(N);
  dfs(root, -1);
  cout << sum << endl;
  rep(i, N) cout << ans[i] << ' ';
  cout << endl;
  return 0;
}


Measured memory_bytes: 1408
n, x, y = map(int, input().split())
l_list = [0] * 10000000
for i in range(1, n+1):
    for j in range(i+1, n+1):
        start = i
        end = j
        l = end - start
        l = min(l, abs(start - x) + abs(end - y) + 1)
        l_list[l] += 1
for i in range(1, n):
    print(l_list[i])

Measured memory_bytes: 81652
#include<cstdio>
int n,a,b;
bool pd(int t){
	int sum=0;
	while(t){
		sum+=t%10;
		t/=10;
	}
	if(sum>=a and sum<=b)
		return true;
	return false;
}
int main(){
	int ans=0;
	scanf("%d %d %d",&n,&a,&b);
	for(int i=1;i<=n;i++){
		if(pd(i))
			ans+=i;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
import math
 
Q = int(input())
 
# 素数表
n = 100000
P = [False] * n
P[2] = True
for i in range(3, n, 2):
    k = True
    for j in range(3, int(math.sqrt(i)) + 1, 2):
        if i % j == 0:
            k = False
            break
    if k:
        P[i] = True
 
# Nと(N+1)÷2が素数か否か
a = [0] * n
for i in range(1, n, 2):
    j = (i + 1) // 2
    if P[i] and P[j]:
        a[i] = 1
# 累積和
for i in range(n - 1):
    a[i + 1] += a[i]
 
for _ in range(Q):
    l, r = map(int, input().split())
    print(a[r] - a[l - 1])

Measured memory_bytes: 7156
#n=int(input())
n,k,q=map(int,input().split())
#t=int(input())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
windic={i:0 for i in range(1,n+1)}
for i in range(q):
    a=int(input())
    windic[a]=windic[a]+1

for i in range(1,n+1):
    if k-q+windic[i]>=1:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 19456
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str1 = scan.next();
		String str2 = scan.next();
		int cnt = 0;

		for(int i = -1+str1.length();i>=0;i--) {
			if(str1.charAt(i) != str2.charAt(i)) {
				cnt += 1;
			}
		}
		System.out.println(cnt);

		scan.close();
	}
}

Measured memory_bytes: 31796
if __name__=="__main__":
    n = int(input())
    myList = []
    while n>0:
        myList.append(n % 10)
        n = n/10
    if myList[0]==2 or myList[0]==4 or myList[0]==5 or myList[0]==7 or myList[0]== 9:
        print("hon")
    elif myList[0]==0 or myList[0]==1 or myList[0]==6 or myList[0]==8:
        print("pon")
    elif myList[0]==3:
        print("bon")


Measured memory_bytes: 9196
#include<iostream>
#include <string>
#include<vector>

using namespace std;

int main(){

	string a,b,c;
	cin >> a >> b >> c;
	int A, B ,C;
	A = toupper(a[0]);
	B = toupper(b[0]);
	C = toupper(c[0]);
	cout << char(A) << char(B) << char(C) <<endl;

	return 0;

}

Measured memory_bytes: 256