akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int n, m, q;
vi a, b, c, d;
int ans;

void calc(vi A) {
    int tmp = 0;
    rep(i, q) {
        if(A[b[i]] - A[a[i]] == c[i]) tmp += d[i];
    }
    ans = max(ans, tmp);
    return;
}

void dfs(vi A) {
    if(A.size() == n + 1) {
        calc(A);
        return;
    }

    A.push_back(A.back());
    while(A.back() <= m) {
        dfs(A);
        A.back()++;
    }
}

int main()
{
    cin >> n >> m >> q;
    a = b = c = d = vi(q);
    rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];

    vi A;
    dfs(vi(1, 1));

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

Measured memory_bytes: 3644
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var a = o.a();
  var b = o.a();
  var t = o.a();
  return Math.floor(t/a)*b;
}

Measured memory_bytes: 22076
import math

def get_distance(x1, y1, x2, y2):
    d = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
    return d

if __name__ == '__main__':
    x1, y1, x2, y2 = map(float,input().split())
    d = get_distance(x1, y1, x2, y2)
    print(d)


Measured memory_bytes: 5656
#include <bits/stdc++.h>
using namespace std;
//16:05
long N;

int main()
{
    cin >> N ;
    long x = 1;
    for(long i = 2;i<=sqrt(N);i++)
    {
        if(N%i == 0)
        {
            x = i;
        }
    }
    
    long y = N/x;
    
    int count = 1;
    while(y / 10 > 0)
    {
        y /= 10;
        count ++;
    }
    
    cout << count << endl;
 
    return 0;
    
}

Measured memory_bytes: 256
# B
import numpy as np
N, M, V, P = map(int, input().split())
A = np.array(input().split(), dtype=int)

A = np.sort(A)[::-1]

# X(1-origin)が再録される可能性があるか
def f(X):
    # M人が, Pに票を入れず、Xに全振りして可能性がないなら終了
    if (A[P-1] > A[X-1] + M):
        # print("C1")
        return False

    # M人がV2回投票を行う
    V2 = V - (P-1) - 1 - (N-X)
    if V2 < 0: V2 = 0
    # A[P:X]の範囲にM人がV2回投票を行ったとき、Ax = A[X-1] + Mを超えたら終了(同点はOK)
    # 自明に小さいAに票を入れる
    Ax = A[X-1] + M
    RANGE = Ax - A[P-1:X-1]
    # 先にAxから引いておくので、負数になったら終了
    
    # RANGEの各要素はPまで吸収できる→Mとmaxをとって、合計値がM*V以下ならOK
    # print(RANGE)
    RANGE = np.minimum(RANGE, M)
    # print(RANGE)
    # print(np.sum(RANGE), M*V2)
    return np.sum(RANGE) >= M*V2

# 二分探索
lo, up = P, N

while(lo!=up):
    ta = (lo + up + 1) // 2
    # print(lo, up, ta)

    if f(ta):
        lo = ta
    else:
        up = ta - 1

print(lo)


Measured memory_bytes: 23960
--Koch-recursion
type Coord= (Double,Double)

koch_n_vertex::Int -> [Coord]
koch_n_vertex 0 = [(1.0,0.0)]
koch_n_vertex n = let rec = koch_n_vertex (n-1) in
                  let pt1 = map trans1 rec in
                  let pt2 = map trans2 rec in
                  let pt3 = map trans3 rec in
                  let pt4 = map trans4 rec in
                  pt1++pt2++pt3++pt4

trans1::Coord -> Coord
trans1 (x,y) = ((1/3)*x,(1/3)*y)

trans2::Coord -> Coord
trans2 coord = let (x',y')= rotate (pi/3) (trans1 coord) in (x'+(1/3),y')

trans3::Coord -> Coord
trans3 coord = let (x',y')= rotate ((-pi)/3) (trans1 coord) in (x'+(1/2),y'+((sin (pi/3))/3))

trans4::Coord -> Coord
trans4 coord = let (x',y')= trans1 coord in (x'+(2/3),y')

rotate::Double->Coord -> Coord
rotate rad (x,y) = let s = sin rad in let c = cos rad in ((x*c)-(y*s),(x*s)+(y*c))

solver::Int -> [Coord]
solver n = map (\(x,y)-> (100.0*x,100.0*y)) ((0.0,0.0):koch_n_vertex n)

printer::Show a => [(a,a)]-> IO ()
printer [] = return ()
printer ((x,y):xs) = do
  putStr ((show x)++" "++(show y)++"\n")
  printer xs

main::IO()
main = do
  nc<-getLine
  let n= read nc ::Int
  printer (solver n)

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

#ifdef _WIN32
#define scanfll(x) scanf("%I64d", x)
#define printfll(x) printf("%I64d", x)
#else
#define scanfll(x) scanf("%lld", x)
#define printfll(x) printf("%lld", x)
#endif
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vll>; using vld = vector<ld>; 
using vi = vector<int>; using vvi = vector<vi>;
vll conv(vi& v) { vll r(v.size()); rep(i, v.size()) r[i] = v[i]; return r; }
using P = pair<ll, ll>;

template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &v) {  o << "(" << v.first << ", " << v.second << ")"; return o; }
template<size_t...> struct seq{}; template<size_t N, size_t... Is> struct gen_seq : gen_seq<N-1, N-1, Is...>{}; template<size_t... Is> struct gen_seq<0, Is...> : seq<Is...>{};
template<class Ch, class Tr, class Tuple, size_t... Is>
void print_tuple(basic_ostream<Ch,Tr>& os, Tuple const& t, seq<Is...>){ using s = int[]; (void)s{0, (void(os << (Is == 0? "" : ", ") << get<Is>(t)), 0)...}; }
template<class Ch, class Tr, class... Args> 
auto operator<<(basic_ostream<Ch, Tr>& os, tuple<Args...> const& t) -> basic_ostream<Ch, Tr>& { os << "("; print_tuple(os, t, gen_seq<sizeof...(Args)>()); return os << ")"; }
ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; cout << endl; } return o; }
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]";  return o; }
template <typename T>  ostream &operator<<(ostream &o, const set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U>  ostream &operator<<(ostream &o, const map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U>  ostream &operator<<(ostream &o, const unordered_map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]";  return o; }
void printbits(ll mask, ll n) { rep(i, n) { cout << !!(mask & (1ll << i)); } cout << endl; }
#define ldout fixed << setprecision(40) 

static const double EPS = 1e-14;
static const long long INF = 1e18;
static const long long mo = 1e9+7;

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n; cin >> n;
    vll a(n*2); rep(i, a.size()) cin >> a[i];
    sort(all(a));
    reverse(all(a));
    ll ret = 0;
    rep(i, n) {
        ret += min(a[2*i], a[2*i+1]);
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;

int dec(string s)
{
	int ret=0,d=1;
	for(int i=0; i<s.size(); i++)
	{
		if(isdigit(s[i])) d=s[i]-'0';
		else
		{
			if(s[i]=='m') ret+=d*1000;
			if(s[i]=='c') ret+=d*100;
			if(s[i]=='x') ret+=d*10;
			if(s[i]=='i') ret+=d*1;

			d=1;

		}
	}
	return ret;
}

void enc(int a)
{
	char dig[]={'i','x','c','m'};
	string s;

	for(int i=0; i<4; i++)
	{
		int d=a%10;
		if(d!=0)
		{
			s+=dig[i];
			if(d!=1) s+=(char)(d+'0');
		}

		a/=10;
	}
	
	reverse(s.begin(), s.end());
	cout << s << endl;
}

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

	while(N--)
	{
		string a,b;
		cin >> a >> b;
		enc(dec(a)+dec(b));
	}

}

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

typedef long long ll;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int start = max(a, c), end = min(b, d);
    int ans = end - start;
    if (ans < 0)
        cout << 0 << endl;
    else
        cout << ans << endl;
    return 0;
}

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

struct BIT{
    // 1-origin
    vector<int> v;
    int n;

    BIT(){}

    BIT(int _n):
        v(vector<int>(_n+1, 0)), n(_n) {}

    int sum(int i){
        int s = 0;
        while(i > 0){
            s += v[i];
            i -= lsb(i);
        }
        return s;
    }
    
    int sum(int l, int r){
        return sum(r) - sum(l-1);
    }

    void add(int i, int x){
        while(i <= n){
            v[i] += x;
            i += lsb(i);
        }
    }

private:
    // least significant bit
    int lsb(int i){
        return i & -i;
    }
};

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

    BIT bit[26];
    for(int i = 0; i < 26; i++) bit[i] = BIT(n);

    for(int i = 0; i < n; i++){
        bit[s[i]-'a'].add(i+1, 1);
    }

    while(q--){
        int op;
        cin >> op;
        if(op == 1){
            int i;
            char c;
            cin >> i >> c;
            i--;
            if(s[i] == c)   continue;
            bit[s[i]-'a'].add(i+1, -1);
            s[i] = c;
            bit[s[i]-'a'].add(i+1, 1);
        }else if(op == 2){
            int l, r;
            cin >> l >> r;
            int cnt = 0;
            for(int i = 0; i < 26; i++){
                cnt += (bit[i].sum(r)-bit[i].sum(l-1))>0;
            }
            cout << cnt << endl;
        }
    }
    return 0;
}

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

int main() {
    double a, b, h, m;
    const double PI=3.14159265358979323846;
    cin >> a >> b >> h >> m;
    double res = a*a + b*b - 2*a*b*cos(PI*((h*30+m*0.5)-m*6)/180);
    res = sqrt(res);
    cout << std::setprecision(20) << res << endl;
    return 0;
}

Measured memory_bytes: 4228
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
import java.util.*; 
/**
 * :)
 **/
 
public class Main 
{ 
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
  public static long primeFactors(long n)
{
    long ans=1;
    if(n%2==0)
    ans*=2*1l;
    while (n%2 == 0)
    {
        n = n/2;
    }
    
    for (int i = 3; i*i<=n; i = i+2)
    {
        if(n%i==0)
        ans*=i*1l;
        while (n%i == 0)
        {
            n = n/i;
        }
    }
   
    if (n > 2)
        ans*=n*1l;
        return ans;
}

public static long gcd( long a, long b)
{
    if(b==0)
    return a;
    return gcd(b, a%b);
}
    public static void main(String[] args) 
    { 
        FastReader sc=new FastReader(); 
	 
	    String s=sc.next();
	    String t=sc.next();
	    int n=s.length();
	    boolean check=true;
	    for( int i=0;i<n;i++)
	    {
	        if(s.charAt(i)!=t.charAt(i))
	        {
	            check=false;
	            break;
	        }
	    }
	  if(check)
	  System.out.println("Yes");
	  else
	  System.out.println("No");
	    
	    //System.out.print(sb.toString());
    
	    //System.out.print(sb.toString());
		
	}
	public static void sort( long a[])
	{
	    ArrayList<Long> adj=new ArrayList<>();
	    for( int i=0;i<a.length;i++)
	    {
	        adj.add(a[i]);
	    }
	    Collections.sort(adj);
	    for( int i=0;i<a.length;i++)
	    {
	        a[i]=adj.get(i);
	    }
	}
	public static long find(int ind, long bit[])
    {
        long sum=0;
        while(ind>0)
        {
           long last_bit= (ind) & (-ind);
           sum+=bit[ind];
           ind-=last_bit;
           
        }
        return sum;
    }
    public static void update( long bit[], int ind, int val, int lim )
    {
        while(ind<=lim)
        {
            bit[ind]+=val;
            ind+=(ind)&(-ind);
        }
    }
}


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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int c_u = 0;
  int c_d = 0;
  int c_l = 0;
  int c_r = 0;
  
  if(b < d){
    for(int i=0; i< d-b; i++){
      cout << "U";
      c_u++;
    }
  }
  if(b > d){
    for(int j=0; j< b-d; j++){
      cout << "D";
      c_d++;
    }
  }
  
  if(a < c){
    for(int k=0; k< c-a; k++){
      cout << "R";
      c_r++;
    }
  }
  if(a > c){
    for(int l=0; l< a-c; l++){
      cout << "L";
      c_l++;
    }
  }
  
  if(c_u > 0){
    for(int m=0; m<c_u; m++){
      cout << "D";
    }
  }
  if(c_d > 0){
    for(int n=0; n<c_d; n++){
      cout << "U";
    }
  }
  if(c_r > 0){
    for(int o=0; o<c_r+1; o++){
      cout << "L";
    }
  }
  if(c_l > 0){
    for(int p=0; p<c_l+1; p++){
      cout << "R";
    }
  }
  
  //2周目
  if(c_u > 0){
    for(int q=0; q<c_u+1; q++){
      cout << "U";
    }
  }
  if(c_d > 0){
    for(int r=0; r<c_d+1; r++){
      cout << "D";
    }
  }
  if(c_r > 0){
    for(int s=0; s<c_r+1; s++){
      cout << "R";
    }
  }
  if(c_l > 0){
    for(int t=0; t<c_l+1; t++){
      cout << "L";
    }
  }
  if(c_u > 0){
    cout << "D";
  }
  if(c_d > 0){
    cout << "U";
  }
  if(c_r > 0){
    cout << "R";
  }
  if(c_l > 0){
    cout << "L";
  }
  
  if(c_u > 0){
    for(int u=0; u<c_u+1; u++){
      cout << "D";
    }
  }
  if(c_d > 0){
    for(int v=0; v<c_d+1; v++){
      cout << "U";
    }
  }
  if(c_r > 0){
    for(int w=0; w<c_r+1; w++){
      cout << "L";
    }
  }
  if(c_l > 0){
    for(int x=0; x<c_l+1; x++){
      cout << "R";
    }
  }
  
  if(c_u > 0){
    cout << "U";
  }
  if(c_d > 0){
    cout << "D";
  }
  cout << endl; 
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
//  val l = List.fill(5)(sc.nextInt)
  val d = sc.nextInt

  val ans =
    if (d == 25) "Christmas"
    else if (d == 24) "Christmas Eve"
    else if (d == 23) "Christmas Eve Eve"
    else if (d == 22) "Christmas Eve Eve Eve"

  println(ans)
}

Measured memory_bytes: 25416
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a) (a).begin(),(a).end()
#define ll long long
long long min(long long x,long long y){return (x<y ? x:y);}
long long max(long long x,long long y){return (x>y ? x:y);}
#define ld long double
int stoi(string s) {return atoi(s.c_str());}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
#define LINEY "YES\n"
#define Liney "Yes\n"
#define LINEN "NO\n"
#define Linen "No\n"

int func(string s){
  char c,d;
  int count = 0;
  int s_size = s.size();
  for(int i=1;i<s_size;i++){
    c = s[i-1];
    d = s[i];
    if(c=='A' && d=='B'){count++;}
  }
  return count;
}

// -A B-A B- 

int main(){
  int N; cin>>N;
  string s; char t,e;
  int count = 0;
  int num_a = 0;
  int num_b = 0;
  int num_ab = 0;
  REP(i,N){
    cin >> s;
    count += func(s);
    t = s[0];
    e = s[s.size()-1];
    if(e=='A'){
      if(t=='B'){num_ab++;}
      else{num_a++;}
    }
    else if(t=='B'){num_b++;}
  }
  if(num_a+num_b>0){
    count += min(num_a,num_b)+num_ab;
  }else{
    count += max(num_ab-1,0);
  }
  printf("%d\n",count);
}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))
num = [-1] * n


for i in range(m):
    s, c = list(map(int, input().split()))
    if n > 1 and s == 1 and c == 0:
        print(-1)
        exit()
    elif num[s-1] != -1 and num[s-1] != c:
        print(-1)
        exit()
    else:
        num[s-1] = c

for i in range(n):
    if i == 0 and num[i] == -1:
        if n == 1:
            num[i] = 0
        else:
            num[i] = 1

    elif num[i] == -1:
        num[i] = 0

print(int(''.join(list(map(str, num)))))


Measured memory_bytes: 3064
import java.io.BufferedReader

fun main() = Thread(null, ::test, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun test() = SimpleIO_test().exec {
    val (n, m, k) = readLine().split(' ').map { it.toInt() }
    val aList = readLine().split(' ').map { it.toLong() }
    val bList = readLine().split(' ').map { it.toLong() }

    var takeB = m
    var timeSumA = 0L
    var timeSumB = bList.sum()
    var answer = 0

    for (takeA in 0..n) {
        while (timeSumA + timeSumB > k && takeB > 0) {
            timeSumB -= bList[takeB - 1]
            takeB--
        }

        if (timeSumA + takeB > k) break

        answer = Math.max(answer, takeA + takeB)

        if (takeA in aList.indices) timeSumA += aList[takeA]
    }

    println(answer)
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType")
private class SimpleIO_test {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private val sb: StringBuilder = StringBuilder()
    fun readLine() = br.readLine()!!
    fun println() = sb.appendln()
    fun print(any: Any) = sb.append(any)
    fun println(any: Any) = sb.appendln(any)
    fun <T> print(any: Iterable<T>, separator: String) = sb.append(any.joinToString(separator))
    fun <T> println(any: Iterable<T>, separator: String) = sb.appendln(any.joinToString(separator))
    fun exec(action: SimpleIO_test.() -> Unit) = run { action() }.run { kotlin.io.println(sb) }
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 78932
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
int a[int(1e5+10)]; 
ll dp[100010][2];
int main() {
	int n;
	cin >> n;
	rep(i,n) cin >> a[i];
	dp[0][0] = 0;
	dp[0][1] = -(1LL<<60);
	rep(i,n) {
		dp[i+1][0]=max(dp[i][0]+a[i],dp[i][1]-a[i]);
		dp[i+1][1]=max(dp[i][0]-a[i],dp[i][1]+a[i]);
	}
	cout << dp[n][0] << endl;
	return 0;
}

Measured memory_bytes: 5552
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#include<ctype.h>
int main(){
int i, j, n, cnt;
while(~scanf("%d", &n)){
        cnt=0;
    for(int i=1;i<=9;i++){
        for(j=1;j<=9;j++){
            if((i*j)==n){
               cnt++;
            }

        }
    }
if(cnt>0)
     printf("Yes");
else
    printf("No");
}

return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
using namespace std;

set<char> st={'a','e','i','o','u'};

// ll mod=1e9 +7;
ll mod=  998244353;

const int M=200006;
int f[M],inv[M];
int expo(int base,int exponent,int mod){
    int ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2,mod);
    for(int i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
int C(int n,int r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

ll n,i;
ll dp[503][503];

vector<ll>a(503);
ll caldp(ll l,ll r)
{
    if(l+1==r)
    {
         dp[l][r]=a[l];
    }
    if(dp[l][r]!=0)
    return dp[l][r];
    
    dp[l][r]=-1;
    for(ll mid=l+1;mid<r;mid++)
    {
        ll lpart=caldp(l,mid);
        ll rpart=caldp(mid,r);
        if(lpart>0 && lpart==rpart)
         dp[l][r]=lpart+1;
    }
    return dp[l][r];
}

ll cal(ll tmp)
{
    ll ans=0;
     if(tmp%2==0)
            {
                ll terms=tmp/2;
                ans+=(tmp*(terms)) - ((terms*(terms-1))); 
            }
    else
            {
                ll terms=tmp/2 +1;
                ans+=(tmp*terms) - (terms*(terms-1));
            }
        return ans;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //compute();
    
    ll tests=1;
   // cin>>tests;
    while(tests--)
    {
        ll h,w,i;
        cin>>h>>w;
      if(h==1 || w==1) {cout<<1;return 0;}
        ll ans=0;
        ll t1,t2;
        if(w%2==0)
        {t1=w/2;t2=t1;}
        else{t1=w/2 +1;t2=w-t1;}
        if(h%2==0)
        {ans+=(h/2)*(t1+t2);}
        else
        {
            ans+=(h/2 +1)*t1;
            ans+=(h/2)*t2;
        }
        cout<<ans;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <queue>
#include <iostream>
#include <cmath>

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
typedef long long ll;
using namespace std;



// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    // Failed to predict input format
    char a;
    cin >> a;
    if (isupper(a)) { 
        cout << 'A' << endl;
    } else { 
        cout << 'a' << endl;
    }
    return 0;
}


Measured memory_bytes: 3548
// 2012/11/07 Tazoe

#include <iostream>
using namespace std;

int main()
{
	bool is_prime[1000000];

	is_prime[0] = is_prime[1] = false;
	for(int i=2; i<1000000; i++){
		is_prime[i] = true;
	}

	for(int i=2; i*i<1000000; i++){
		if(is_prime[i]){
			for(int j=i+i; j<1000000; j+=i){
				is_prime[j] = false;
			}
		}
	}

	int n_prime[1000000];

	int cnt = 0;
	for(int i=0; i<1000000; i++){
		if(is_prime[i]){
			cnt++;
		}

		n_prime[i] = cnt;
	}

	while(true){
		int n;
		cin >> n;

		if(cin.eof())
			break;

		cout << n_prime[n] << endl;
	}

	return 0;
}

Measured memory_bytes: 6040
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


string solve(string str) {
  int it = 0;
  deque<char> res;
  res.push_back(str[0]);
  for (int i = 1; i < str.size(); i += 3) {
    bool isFront = true;
    if (str[i] != '-') isFront = false;
    if (isFront) {
      ++it;
      if (it >= res.size()) {
	res.push_back(str[i+2]);
      }
    }
    else {
      --it;
      if (it < 0) {
	++it;
	res.push_front(str[i+2]);
      }
    }
    //for (int i = 0; i < res.size(); ++i) cout << res[i];
    //cout << ", " << it << endl;
  }
  string sres = "";
  for (int i = 0; i < res.size(); ++i) {
    sres += res[i];
  }
  return sres;
}

int n;
int main() {
  while (cin >> n) {
    string str;
    for (int i = 0; i < n; ++i) {
      cin >> str;
      cout << solve(str) << endl;
    }
  }
}


Measured memory_bytes: 1216
#!/usr/bin/env python3
#ABC76 C

from copy import deepcopy
s = list(input())
t = list(input())

ns = len(s)
nt = len(t)
f1 = 0
for i in range(ns):
    if s[i] in t:
        ind = t.index(s[i])
        for j in range(i-ind,i-ind+nt):
            if j < ns:
                if s[j] == t[j-i+ind] or s[j] == '?':
                    continue
                else:
                    break
            else:
                break
        else:
            f1 = 1
            x = deepcopy(s)
            x[i-ind:i-ind+nt] = t
            break
f2 = 0
for i in range(ns)[::-1]:
    if s[i] == '?':
        for j in range(i,i+nt):
            if j < ns:
                if s[j] == t[j-i] or s[j] == '?':
                    continue
                else:
                    break
            else:
                break
        else:
            f2 = 1
            y = deepcopy(s)
            y[i:i+nt] = t
            break
if f1 & f2:
    for i in range(ns):
        if x[i] == '?':
            x[i] = 'a'
        if y[i] == '?':
            y[i] = 'a'
    x = ''.join(x)
    y = ''.join(y)
    ans = [x,y]
    ans.sort()
    print(ans[0])

elif f1 and not f2:
    for i in range(ns):
        if x[i] == '?':
            x[i] = 'a'
    x = ''.join(x)
    print(x)
elif not f1 and f2:
    for i in range(ns):
        if y[i] == '?':
            y[i] = 'a'
    y = ''.join(y)
    print(y)
else:
    print('UNRESTORABLE')


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


def main():
    N, M = map(int, input().split())
    A = []
    B = []
    for _ in range(N):
        A.append(input().strip())
    for _ in range(M):
        B.append(input().strip())

    for ay in range(0, N-M+1):
        for ax in range(0, N-M+1):
            m = 0
            for by in range(M):
                for bx in range(M):
                    if A[ay + by][ax + bx] == B[by][bx]:
                        m += 1
                        if m == M*M:
                            print("Yes")
                            return
    print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 40176
/*
 * coder: @SumitRaut
 */
#include <bits/stdc++.h>

using namespace std;

inline void solve() {
	int n;
	cin>>n;
	vector<int> d1(n),d2(n);
	cin>>d1[0]>>d2[0]>>d1[1]>>d2[1];
	for(int i=2;i<n;++i) {
		cin>>d1[i]>>d2[i];
		if(d1[i]==d2[i]&&d1[i-1]==d2[i-1]&&d1[i-2]==d2[i-2]) {
			cout<<"Yes\n";
			return;
		}
	}
	cout<<"No\n";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
        solve();
    return 0;
}


Measured memory_bytes: 3656
//omajinai
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//omajinai

int main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i ++){
        cin >> a.at(i);
    }

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

    int count=1,ans=0;

    for(int i = 1;i < n;i ++){
        if(a.at(i) == a.at(i-1)){
            count ++;
            if(count > a.at(i)){
                ans ++;
            }
        }else{
            if(count < a.at(i-1)){
                ans += count;
            }
            count = 1;
        }
    }

    if(count < a.at(n-1)){
        ans += count;
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
x = gets.chomp.to_i
count = 0
ans = 0
(0..(x/500)+1).each do |i|
    (0..(x/100)+1).each do |j|
        (0..(x/50)+1).each do |k|
            ans = 500 * i + 100 * j + 50 * k
            if ans.to_s == x.to_s && i <= a && j <= b && k <= c
                count += 1
            end
        end
    end
end
puts count

Measured memory_bytes: 14228
N,M=list(map(int,input().split()))
L=[0]*M
R=[0]*M
for i in range(M):
  L[i],R[i]=map(int,input().split())
a=max(L)
b=min(R)
if b>=a:
  print(b-a+1)
else:
  print(0)

Measured memory_bytes: 10868
import re
ptn = re.compile(r"(A|C|T|G)*")

S = input()
T = set()
xx=ptn.match("FAFA")
for i in range(len(S)):
  for j in range(len(S)):
    x = ptn.match(S[i:i+j+1])
    if(x.group(0)):
      T.add(len(x.group(0)))
try:
  print(max(T))
except:
  print(0)

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

int main() {
    int N;
    long long K;
    cin >> N >> K;
    vector<int> A(N + 1);
    for (int i = 1; i <= N; ++i) {
        cin >> A[i];
    }

    vector<bool> reached(N + 1, false);
    vector<int> first_reached(N + 1, -1);
    vector<int> route;

    // t = 0
    reached[1] = true;
    first_reached[1] = 0;
    route.push_back(1);

    int first_time;
    int second_time;

    for (int t = 1; t <= N; ++t) {
        int next_city = A[route.back()];
        if (reached[next_city]) {
            first_time = first_reached[next_city];
            second_time = t;
            break;
        }

        if (t == K) {
            cout << next_city << endl;
            return 0;
        }

        reached[next_city] = true;
        first_reached[next_city] = t;
        route.push_back(next_city);
    }

    long long reminder = (K - first_time) % (second_time - first_time);

    cout << route[first_time + reminder] << endl;
}

Measured memory_bytes: 5812
n = int(input())
R = [int(input()) for i in range(n)]

minv = R[0]
maxv = R[1] - R[0]

for j in range(1,n):
    if( maxv < R[j] - minv):
        maxv = R[j] - minv
    if( R[j] < minv ):
        minv = R[j]
print(maxv)


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

ll N, K;
vector<ll> pos, neg;
ll z = 0;

ll count_neg(ll x){
	//正×負で絶対値がx以上になるものを探す
	ll res = 0;
	for(auto val: pos){
		ll ng = -1;
		ll ok = neg.size();
		while(ok-ng>1){
			ll md = (ok+ng)/2;
			if(val*neg[md]>=x) ok = md;
			else ng = md;
		}
		res += (ll)neg.size() - ok;
	}
	return res;
}

ll count_pos(ll x){
	ll res = 0;

	// 負×負で絶対値がx以下になるものを探す
	REP(i, neg.size()){
		ll val = neg[i];
		ll ok = -1;
		ll ng = i;
		while(ng-ok>1){
			ll md = (ok+ng)/2;
			if(val*neg[md]<=x) ok = md;
			else ng = md;
		}
		res += ng;
	}

	// 正×正で絶対値がx以下になるものを探す
	REP(i, pos.size()){
		ll val = pos[i];
		ll ok = -1;
		ll ng = i;
		while(ng-ok>1){
			ll md = (ok+ng)/2;
			if(val*pos[md]<=x) ok = md;
			else ng = md;
		}
		res += ng;
	}

	return res;
}

ll count(ll x){
	ll res = 0;
	ll zeros = N*(N-1)/2 - (N-z)*(N-z-1)/2;

	if(x<0){
		res += count_neg(-x);
	}else if(x==0){
		res += count_neg(0);
		res += zeros;
	}else{
		res += count_neg(0);
		res += zeros;
		res += count_pos(x);
	}

	return res;
}

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

    
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    REP(i, N){
    	if(A[i]>0) pos.push_back(A[i]);
    	else if(A[i]==0) z++;
    	else neg.push_back(-A[i]);
    }
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());

    //cout << pos << endl;
    //cout << neg << endl;

    const ll INF = (ll)1e18 + 5;

    ll ng = -INF;
    ll ok = INF;
    while(ok-ng>1){
    	ll md = (ok+ng)/2;
    	if(count(md)>=K) ok = md;
    	else ng = md;
    }

    cout << ok << endl;
    return 0;
}

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

int cmp(int *x, int *y)
{
	return (*x - *y);
}

int main(void)
{
	int con[10001];
	int n;
	int i;

	while (scanf("%d", &n), n){
		long long sum = 0;
		long long buf = 0;
		
		for (i = 0; i < n; i++) scanf("%d", con + i);
		qsort(con, n, 4, cmp);
		for (i = 0; i < n; i++){
			sum += buf;
			buf += con[i];
		}

		printf("%lld\n", sum);
	}

	return (0);
}

Measured memory_bytes: 716
#include<bits/stdc++.h>
using namespace std;
int d1[10]={0,0,-1,-1,-1,1,1,1};
int d2[10]={1,-1,0,1,-1,0,1,-1};
char mp[59][59];
int n,m,a[59][59],ans[59][59];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%s",mp[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			a[i][j]=mp[i][j]=='#'?1:0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			for(int k=0;k<8;k++){
				int x=i+d1[k],y=j+d2[k];
				if(a[x][y])ans[i][j]++;
			}		
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)
			if(mp[i][j]!='#')printf("%d",ans[i][j]);
			else printf("#");
		printf("\n");		
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int b[100001];

int main()
{
    int i,j,n,max=0,c;
    scanf("%d",&n);
    int a[n];
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        if(a[i] != 0)
        {
            ++b[a[i]-1];
            ++b[a[i]];
            ++b[a[i]+1];
        }
        else
        {
            ++b[a[i]];
            ++b[a[i]+1];
        }
        if( b[a[i]] > max )
        {
            max=b[a[i]];
        }
        if( b[a[i]+1] > max )
        {
            max=b[a[i]+1];
        }
        if( b[a[i]-1] > max && a[i] != 0 )
        {
            max=b[a[i]-1];
        }
    }
    printf("%d",max);
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    map<string, ll> mp;
    rep(i, n) {
        string s;
        cin >> s;
        sort(all(s));
        mp[s]++;
    }
    ll ans = 0;
    for (auto&& p : mp) {
        ans += p.se * (p.se - 1) / 2;
    } 
    cout << ans << endl;
}

Measured memory_bytes: 11264
import itertools

n = int(input())


def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


n_table = prime_decomposition(n)
if not n_table:
    n_table.append(1)
f = 9999
#print(n_table)

for i in range(len(n_table) + 1):
#    print("\n" + str(i))
    i_a = itertools.combinations(n_table, i)

    while True:
        try:
            a = 1
            for j in next(i_a):
#                print("i_a=" + str(j))
                a *= j
            b = int(n / a)
#            print("b=" + str(b))
            _f = (len(str(max(a, b))))
        except StopIteration:
            break

        if _f < f:
            f = _f

print(f)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
using namespace std;
string s;
inline char correspond(char const x){return ((!(x-'b'))?('d'):(((!(x-'d'))?('b'):(((!(x-'p'))?('q'):('p'))))));}
signed main()
{
	getline(cin,s);string s1;
	for(register int i(0);i^s.length();i++){s1+=(correspond(s[i]));}reverse(s1.begin(),s1.end());
	puts(((s==s1)?("Yes"):("No")));
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
typedef vector<int> vi;
const int MAX=1e5+2;
const int MOD=1e9+7;

int main(){
	string s;
	cin>>s;
	int K;
	cin>>K;
	int c[MAX];
	int l=s.size();
	rep(i,l){
		char x=s[i];
		int a=x-'a';
		c[i]=a;
	}
	rep(i,l-1){
		if(c[i]==0)continue;
		else if(26-c[i]<=K){
			s[i]='a';
			K-=(26-c[i]);
		}
	}
	K+=c[l-1];
	K=K%26;
	char x='a'+K;
	s[l-1]=x;
	cout<<s<<endl;
}

Measured memory_bytes: 896
import sys

readline = sys.stdin.buffer.readline
import math

sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    S = readline().decode('utf-8')

    total = S.count('R') * S.count('G') * S.count('B')

    for stride in range(1, math.ceil(N / 2) + 1):
        for start in range(N):
            if start + stride * 2 >= N:
                break
            else:
                if S[start] != S[start + stride] and S[start + stride] != S[start + stride * 2] and S[start + stride * 2] != S[start]:
                    total -= 1

    print(total)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9264
n,m=map(int,input().split(' '))
a=[]
for i in range(n):
  tmp=list(map(int,input().split(' ')))
  tmp.append(sum(tmp))
  a.append(tmp)
al=[]
for i in range(m+1):
  tmp=0
  for j in range(n):
    tmp+=a[j][i]
  al.append(tmp)
a.append(al)

for i in a:
  s=''
  for j in range(len(i)):
    if j==len(i)-1:
      s+=str(i[j])
    else:
      s+=str(i[j])+' '
  print(s)


Measured memory_bytes: 5696
#include<stdio.h>
static const int N=501;
static const int INFTY=(1<<21);

int main(){
  int M[N][N];
  int n,u,k,v;
  int i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++)M[i][j];
  }

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

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j)printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  return 0;
}



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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> dist(10, vector<int>(10));
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> dist[i][j];
        }
    }
    vector<vector<int>> num(H, vector<int>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> num[i][j];
        }
    }

    // Warshall-Floyd
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (num[i][j] != -1) {
                ans += dist[num[i][j]][1];
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
#define mod 1000000007

// debug fn.
template<typename T>
void deb(initializer_list<T> l)
{
    for (auto &e : l)
        cout << e << ' ';
    cout << endl;
}

void solve(){
    int n;
    cin>>n;
    vector<ll> dp(n+1, 0);
    for(int i = 1; i <= n; i++){
        ll j = i;
        while (j <= n){
            dp[j] += j;
            j += i;
        }
        // dp[i] *= i;
    }
    ll ans = 0;
//    for(int j = 1; j <= n; j++){
//        cout<<dp[j]<<" ";
//    }
//    cout<<endl;
    for(int j = 1; j <= n; j++){
        ans += dp[j];
    }
    cout<<ans;
}

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

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

    return 0;
}

Measured memory_bytes: 81360
n,y = map(int,input().split())
ans = [-1,-1,-1]

for i in range(n+1):
    for j in range(n+1):
            if 10000*i+5000*j+1000*(n-i-j)==y and n-i-j>=0:
                ans = [i,j,n-i-j]

print(*ans)

Measured memory_bytes: 40812
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
s1=t1*a1+t2*a2
s2=t1*b1+t2*b2
if s1>s2:
	s2,s1=s1,s2
if s1==s2:
	print("infinity")
	exit()
import math
cnt=math.ceil(s1/(s2-s1))
aa=t1*a1
bb=t1*b1
aaa=t1*a1+t2*a2
bbb=t1*b1+t2*b2
if (aa>bb and aaa>bbb) or (aa<bb and aaa<bbb):
	print(0)
	exit()
q=abs(aa-bb)
ans=q//(s2-s1)*2+1
if q%(s2-s1)==0:
	ans-=1
print(ans)


Measured memory_bytes: 3192
#include <stdio.h>

int S[1000000],n;

int binarySearch(int key)
{
  int left = 0;
  int right = n;
  int mid;
         while(left < right)
           {
             mid = (left + right) / 2;
               if (S[mid] == key)return 1;
               if (key > S[mid]) left = mid +1;
               else if (key < S[mid])right = mid;
           }
  return 0;
}

int main(void)
{
  int i,q,key;
  int cnt = 0;
  scanf("%d",&n);
  for(i = 0;i < n;i++)
    {
      scanf("%d",&S[i]);
    }
  scanf("%d",&q);
  for(i = 0;i < q;i++)
    {
      scanf("%d",&key);
      if (binarySearch(key))cnt++;
    }
  printf("%d\n",cnt);
return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long powMonster = sc.nextLong();
		
		// 攻撃loop
		long attacks = attackMonsters(powMonster);
		
		log(attacks);
		sc.close();
	}
	
	static long attackMonsters(long powMonster) {
		long attacks = 0;
		if(powMonster == 1) {
			attacks=1;
		}
		else {
			long pow1;
			pow1 = (powMonster)/2;
			attacks = attackMonsters(pow1) * 2 + 1;
		}
		return attacks;
	}
	
	static void log(String s) {
		System.out.println(s);
	}

	static void log(int i) {
		System.out.println(i);
	}

	static void log(long i) {
		System.out.println(i);
	}

	static void log(double d) {
		System.out.printf("%.12f\n",d);
	}
	
}


Measured memory_bytes: 21844
kisu=['R', 'U', 'D']
gusu=['L', 'U', 'D']

s=input()
swit=0
for i in range(len(s)):
    if i%2==0:
        if not(s[i] in kisu):
            swit=1
    else:
        if not(s[i] in gusu):
            swit=1

if swit==1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 38384
#include <stdio.h>
#define M 50
int X[M];long long Z[M+1][M*M+1];
int main(){
	int N,A,S=0;
	long long R=0;
	scanf("%d%d",&N,&A);
	for(int i=0;i<N;i++)scanf("%d",X+i);
	Z[0][0]=1;
	for(int i=0;i<N;i++){
		S+=X[i];
		for(int k=i;k>=0;k--)for(int j=S;j>=X[i];j--)Z[k+1][j]+=Z[k][j-X[i]];
	}
	for(int i=1;i<=N;i++)R+=Z[i][i*A];
	printf("%lld\n",R);
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue> 
 
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, K;

	cin >> N >> K;

	vector<long long> H(N);

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

	sort(H.begin(), H.end(), greater<long long>());

	long long count = 0;

	for(int i = K; i < N; i++) {
		count += H[i];
	}

	cout << count << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>

int main()
{
    int n, x, count = 0;
    int i, j;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d", &x);
        if (x == 2) count++;
        else if (x % 2){
            for (j = 3; j < sqrt((double)x); j += 2){
                if (x % j == 0) break;
            }
            if (j > sqrt((double)x)) count++;
        }
    }
    printf("%d\n", count);
    
    return 0;
}

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

using namespace std;

int main(){
 int n,a,b; 
  cin >> n;
  
  int res=0;
  int rank=0;
  for(int i=0;i<n;i++){
  cin >> a >> b;
    if(a>rank){
   rank=a;
   res=a+b;
    }
    }
  cout << res << endl;
   
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  if (n == 0) {
    cout << 1 << endl;
  } else if (n == 1) {
    cout << 2 << endl;
  } else if (n == 2) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 3156
fun main(args: Array<String>) {
    val except = readLine()!!.toCharArray()
    val actual = readLine()!!.toCharArray()
    var res = 0

    for (i in 0..2) {
        if (except[i] == actual[i]) {
            res += 1
        }
    }

    print(res)
}

Measured memory_bytes: 31780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846264338327950;
inline int newline() { putchar('\n'); return 0; }

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

    ll sum = 0;

    for (auto c: s) {
        int i = c - 48;
        sum += i;
    }

    if (sum % 9 == 0) { print("Yes"); }
    else { print("No"); }

    return 0;
}

Measured memory_bytes: 3748