akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>

#define M 1046527
#define L 14

char box[M][L]; 

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1+(key%(M-1)); }

int find(char str[]){
  long long key,i,x;
  
  key=getKey(str);
  for(i=0;;i++){
    x=(h1(key)+i*h2(key))%M;
    if(strcmp(box[x],str)==0) return 1;
    else if(strlen(box[x])==0) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key,i,x;

  key=getKey(str);
  for(i=0;;i++){
    x=(h1(key)+i*h2(key))%M;
    if(strcmp(box[x],str)==0) return 1;
    else if(strlen(box[x])==0){
      strcpy(box[x],str);
      return 0;
    }
  }
  return 0;

}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) box[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



Measured memory_bytes: 16104
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
using namespace std;

int main() {
	int A, B;
	cin >> A >> B;

	cout << (A * 3 + B) / 2 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 1000001
int Pri[MAX],is_comp[MAX]={0};
void ene()
{
	int i,j,p=0;
	for(i=2;i<MAX;i++)
		if(!is_comp[i])
		{
			Pri[p++]=i;
			for(j=i*2;j<MAX;j+=i)
				is_comp[j]=1;
		}
}

int main()
{
	int N,i,r;
	ene();
	for(;scanf("%d",&N),N;)
	{
		for(i=r=0;Pri[i]<=N/2;i++)
			if(!is_comp[N-Pri[i]])r++;
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 6736
<?php
list($n) = ints();
$a = ints();
$b = ints();
$c = ints();
sort($a);
sort($b);
sort($c);
$ans = $i = $j = $k = 0;
while ($j < $n) {
    while ($i < $n && $b[$j] > $a[$i]) ++$i;
    while ($k < $n && $b[$j] >= $c[$k]) ++$k;
    $ans += $i * ($n - $k);
    ++$j;
}
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


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

int main()
{
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int mx = -101;
    int my = 101;
    rep(i, n) {
        int x1;
        cin >> x1;
        mx = max(mx, x1);
    }
    rep(i, m) {
        int y1;
        cin >> y1;
        my = min(my, y1);
    }
    if(mx >= y || my <= x) cout << "War" << endl;
    else if(mx < my) cout << "No War" << endl;
    else cout << "War" << endl;
    return 0;
}

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

int main()
{
  int val, val_1000, val_100, val_10;
  cin >> val;
  val_1000 = val / 1000;
  val      = val % 1000;
  
  val_100  = val / 100;
  val      = val % 100;
  
  val_10   = val / 10;
  val      = val % 10;
  
  if ((val_1000 == val_100 && val_100 == val_10) ||(val_100 == val_10 && val_10 == val))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3616
#include <cstdio>

char score(int x,int y,int z){
  if(x==-1||y==-1) return 'F';
  else if(x+y>=80) return 'A';
  else if(80>x+y&&x+y>=65) return 'B';
  else if(65>x+y&&x+y>=50&&x>=0&&y>=0) return 'C';
  else if(50>x+y&&x+y>=30&&z>=50) return 'C';
  else if(50>x+y&&x+y>=30&&z<50) return 'D';
  else if(30>x+y) return 'F';
}

int main(void){
  int m,f,r;
  char i;

  for(;;){
    scanf("%d %d %d", &m, &f, &r);
    if(m==-1&&f==-1&&r==-1) break;

    i=score(m,f,r);
    printf("%c\n", i);
  }

  return 0;
}


Measured memory_bytes: 1028
isPrime = [True] * 200001
sum = 0
sumPrime = [sum]
def calcPrime():
    global sum
    isPrime[0] = isPrime[1] = False
    for i in range(len(isPrime)):
        if(isPrime[i]):
            sum += i
            sumPrime.append(sum)
            for j in range(2 * i, len(isPrime), i):
                isPrime[j] = False
                
calcPrime()
while(True):
    n = input()
    if(n == 0):
        break
    print(sumPrime[n])

Measured memory_bytes: 15288
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, l int
	fmt.Scanf("%d %d", &n, &l)

	var ss = make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%s", &ss[i])
	}

	sort.Strings(ss)

	for _, s := range ss {
		fmt.Print(s)
	}
}

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

using namespace std;

int main(){
    int a[4];
    int ans;
    string s;
    cin >> s;
    int n=s.size();
    for(int i=0;i<n;i++){
        a[i]=stoi(s.substr(i,1));
    }

    for(int i=0;i<(1<<(n-1));i++){
        int tmp=a[0];
        for(int j=0;j<n-1;j++){
            if(i>>j & 1){
                tmp+=a[j+1];
            }else{
                tmp-=a[j+1];
            }
        }
        if(tmp==7){
            ans=i;
            break;
        }
    }

    cout << a[0];
    for(int i=1;i<n;i++){
        if(ans>>(i-1) & 1){
            cout << '+';
        }else{
            cout << '-';
        }
        cout << a[i];
    }
    cout << "=7";

    return 0;
}


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

bool dp[2000009];

int main()
{
    int n, i, j, a[2009], sum = 0;

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

    sort(a, a+n);

    dp[0] = 1;

//    for(i = 0; i <= sum/2; i++)
//        dp[i][0] = 0;
//    for(i = 0; i <= n; i++)
//        dp[0][i] = 1;

    for(i = 0; i < n; i++)
    {
        for(j = sum/2; j >= a[i]; j--)
        {
            dp[j] |= dp[j - a[i]];
        }
    }

//    for(i = 0; i <= sum/2; i++)
//    {
//        cout << dp[i];
//        cout << endl;
//    }

    for(i = sum/2; i >= 0; i--)
    {
        if(dp[i])
        {
            cout << sum - i;
            return 0;
        }
    }
}


Measured memory_bytes: 5600
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int a, b, c, d;
  rd(a, b, c, d);

  writeln(max(0, min(b, d) - max(a, c)));
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#define REP(i, a, b) for (auto i = (a); i < (b); ++i)
using namespace std;

const int inf = 1e9;
const int N = 601;
bool adj[N][N];
int deg[N];
double E[N][2];

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

	int n, m; cin >> n >> m;

	while(m--) {
		int s, t; cin >> s >> t; --s, --t;
		adj[s][t] = 1;
		++deg[s];
	}

	auto solve = [&](bool b) {
		E[n - 1][b] = 0;
		REP(i, 0, n) E[i][b] = 0;
		for (int i = n - 2; i >= 0; --i) {
			E[i][b] = 0;
			for (int j = i + 1; j < n - 1; ++j)
				if (adj[i][j])
					E[i][b] += E[j][b];
			E[i][b] /= deg[i];
			E[i][b] += 1;
		}
	};

	solve(0);
	double ans = E[0][0];

	REP(i, 0, n - 1) {
		if (deg[i] == 1) continue;

		int mxpos; double mx = -1;

		REP(j, i + 1, n)
			if (adj[i][j])
				if (mx < E[j][0]) {
					mxpos = j;
					mx = E[j][0];
				}

		--deg[i]; adj[i][mxpos] = 0;
		solve(1);
		++deg[i]; adj[i][mxpos] = 1;

		ans = min(ans, E[0][1]);
	}

	cout << fixed << setprecision(10) << ans;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n,m;
int l[200010], r[200010], d[200010], h[100010];
long long dist[100010];
vector<pair<int, int>> g[100010];
vector<int> tmp;
set<int> rel;

int main(){
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		cin >> l[i] >> r[i] >> d[i];
		
		l[i]--; r[i]--;
		h[r[i]]++;
		g[l[i]].push_back(make_pair(r[i], d[i]));
		rel.insert(l[i]);
		rel.insert(r[i]);
	}
	
	queue<int> qu;
	for(auto v : rel){
		if(!h[v]){
			qu.push(v);
			dist[v] = 1;
		}
	}
	
	while(!qu.empty()){
		int p = qu.front(); qu.pop();
		
		tmp.push_back(p);
		for(int i = 0;i < g[p].size();i++){
			h[g[p][i].first]--;
			
			if(!h[g[p][i].first]) qu.push(g[p][i].first);
		}
	}
	
	if(!m){
		cout << "Yes" << endl;
		return 0;
	}
	
	if(tmp.size() < rel.size()){
		cout << "No" << endl;
		return 0;
	}
	
	for(int i = 0;i < tmp.size();i++){
		int p = tmp[i];
		
		for(int j = 0;j < g[p].size();j++){
			pair<int, int> e = g[p][j];
			
			if(!dist[e.first]) dist[e.first] = dist[p] + e.second;
			else if(dist[p] + e.second != dist[e.first]){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 14844
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    int a = s.nextInt();

    if(a == 25){
      System.out.println("Christmas");
    }else if(a == 24){
      System.out.println("Christmas Eve");
    }else if(a == 23){
      System.out.println("Christmas Eve Eve");
    }else if(a == 22){
      System.out.println("Christmas Eve Eve Eve");
    }
  }
}


Measured memory_bytes: 21844
using System;
using System.Linq;
public class Program {
  public static void Main() {
    int[] AB = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    if (AB.Sum() == 15) {
      Console.WriteLine("+");
    } else if (AB[0] * AB[1] == 15) {
      Console.WriteLine("*");
    } else {
      Console.WriteLine("x");
    }
  }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define int long long


template <class X> class Solve{
public:
	string s;
	int p;
	Solve(string s_){
		s = s_;
		s += "~";
		p = 0;
	}
	X one(){
		X r = num();
		while( s[p] == '+' || s[p] == '*' ){
			char c = s[p];
			p++;
			X l = num();
			if( c == '*' ){
				r *= l;
			}else{
				r += l;
			}
		}
		return r;
	}
	X num(){
		X ans = 0;
		while( s[p] >= '0' && s[p] <= '9'){
			ans = ans * 10 + s[p] - '0';
			p++;
		}
		return ans;
	}

	X two(){
		X r = three();
		while( s[p] == '+' ){
			char c = s[p];
			p++;
			X l = three();
			r += l;
		}
		return r;
	}

	X three(){
		X r = num();
		while( s[p] == '*' ){
			char c = s[p];
			p++;
			X l = num();
			r *= l;
		}
		return r;
	}
};

signed main(){
	string s;
	int n;
	cin >> s >> n;
	int b = 0;
	if( fabs(Solve<double>(s).one()-n) < 1e5 ){
		if( Solve<int>(s).one()-n == 0 ){
			b += 1;
		}
	}
	if( fabs(Solve<double>(s).two()-n) < 1e5 ){
		if( Solve<int>(s).two()-n == 0 ){
			b += 2;
		}
	}
	string table = "ILMU";
	cout << table[b] << endl;
	
}

Measured memory_bytes: 1208
n = gets.to_i
w = gets.chomp
words = [w]
(n-1).times do
  n_w = gets.chomp
  if w.chars.last != n_w.chars.first or words.include?(n_w)
    puts "No"
    exit 0
  end
  w = n_w
  words.push(w)
end
puts "Yes"


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

int H, W;
vector<vector<int>> field;

void dfs(int h, int w) {
	field[h][w] = 0;
	/* 8方向に探索 */
	for (int dh = -1; dh <= 1; dh++) {
		for (int dw = -1; dw <= 1; dw++) {
			int nh = h + dh;
			int nw = w + dw;

			if (nh < 0 || H <= nh || nw < 0 || W <= nw) continue;
			if (field[nh][nw] == 0) continue;
			
			dfs(nh, nw);
		}
	}
}

int main() {
	while (cin >> W >> H) {
		if (H == 0 || W == 0) break;
		field.assign(H, vector<int>(W, 0)); // 0で初期化
		for (int h = 0; h < H; h++) {
			for (int w = 0; w < W; w++) {
				cin >> field[h][w];
			}
		}
		 
		/* すべての地点に対して探索を行う */
		int count = 0;
		rep(h, H) {
			rep(w, W) {
				if (field[h][w] == 0) continue;
				dfs(h, w);
				count++;
			}
		}
		cout << count << endl;
	}
}


Measured memory_bytes: 3280
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */
 
    //#pragma comment(linker, ack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(ll i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(ll i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    // #define te    
    typedef long double ld;
    typedef long long ll;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 100100;

    void solve() {
        ll h, w, n;
        cin >> h >> w >> n;
        map<ll, ll> mp , cnt;
        rep(i, n){
            ll x, y;
            cin >> x >> y; --x, --y;
            //cout << "new" << endl;
            repA(i, max(0ll, x-2), min(h-3, x)) 
                repA(j, max(0ll, y-2), min(w-3, y)){
                   // cout << i << " " << j << endl;
                    mp[i*1000000000 + j]++;
                }
        }
        trav(i, mp) cnt[i.snd]++;
        ll pre = (h-2)*(w-2);
        rep(i, 10) pre-=cnt[i];
        cnt[0] = pre;
        rep(i, 10) cout << cnt[i] << endl;
    }
 
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
       // ll ti;   cin >> ti;  while(ti--)
      solve();
      return 0;
    } 

Measured memory_bytes: 56576
const MOD: usize = 1_000_000_007;

fn memo(cur_h: usize, cur_w: usize, cur_goal: usize, dp: &mut Vec<Vec<Vec<Option<usize>>>>, limit_h: usize, limit_w: usize, target_goal: usize) -> usize {
    if cur_h >= limit_h {
        if cur_goal == target_goal {
            return 1;
        }
        return 0;
    }
    if let Some(memo_value) = dp[cur_h][cur_w][cur_goal] {
        return memo_value;
    }
    let mut result: usize = 0;
    //use
    {
        let mut next_w = cur_w + 2;
        let mut next_h = cur_h;
        let mut next_goal = cur_goal;
        if next_w >= limit_w {
            next_w = 0;
            next_h += 1;
        }
        let left = cur_w;
        let right = cur_w + 1;
        if left == cur_goal {
            next_goal = right;
        } else if right == cur_goal {
            next_goal = left;
        }

        result += memo(next_h, next_w, next_goal, dp, limit_h, limit_w, target_goal);
        result %= MOD;
    }
    //no use
    {
        let mut next_w = cur_w + 1;
        let mut next_h = cur_h;
        if next_w >= limit_w {
            next_w = 0;
            next_h += 1;
        }
        result += memo(next_h, next_w, cur_goal, dp, limit_h, limit_w, target_goal);
        result %= MOD;
    }
    dp[cur_h][cur_w][cur_goal] = Some(result);
    return result;
}

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let h: usize = sc.read();
    let w: usize = sc.read::<usize>() - 1;
    let k: usize = sc.read::<usize>() - 1;
    //dp[h][w][goal]
    let mut dp: Vec<Vec<Vec<Option<usize>>>> = vec![vec![vec![None; 10]; 10]; 110];
    let mut res = 1;
    if w != 0 {
        res = memo(0, 0, 0, &mut dp, h, w, k);
    }
    println!("{}", res);
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            for(int i = 1;i < 10;i++)
            {
                for(int j = 1;j < 10;j++)
                {
                    int multiplication = i * j;
                    Console.Write("{0}x{1}={2}\n", i, j,multiplication);
                }
            }
        }
    }
}

Measured memory_bytes: 5588
#include<stdio.h>

int main(){
	int a,b,w;
	int value;

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

	if( a < b ){
		value = b - ( a + w );
	}else{
		value = a - ( b + w );
	}

	if( value > 0 ){
		printf("%d\n",value);
	}else{
		printf("0\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
void makecopy(int *saikoro,int *copy){
  int i;
  for(i=1;i<=6;i++){
    copy[i]=saikoro[i];
  }
}


int main(){
  int *saikoro,*copy,i,ue,syoumen,n,j;
  saikoro=malloc(7*sizeof(int));
  copy=malloc(7*sizeof(int));
  for(i=1;i<=6;i++) scanf("%d",&saikoro[i]);
  makecopy(saikoro,copy);
  scanf("%d",&n);
  char order[8]="SSSSEEEE";
  for(j=0;j<n;j++){
    scanf("%d %d",&ue,&syoumen);
    for(i=0;i<strlen(order);i++){
      if(order[i]=='S'){
        saikoro[2]=copy[1];
        saikoro[6]=copy[2];
        saikoro[5]=copy[6];
        saikoro[1]=copy[5];
        makecopy(saikoro,copy);
      }
      if(order[i]=='N'){
        saikoro[1]=copy[2];
        saikoro[2]=copy[6];
        saikoro[6]=copy[5];
        saikoro[5]=copy[1];
        makecopy(saikoro,copy);
      }
      if(order[i]=='W'){
        saikoro[4]=copy[1];
        saikoro[6]=copy[4];
        saikoro[3]=copy[6];
        saikoro[1]=copy[3];
        makecopy(saikoro,copy);
      }
      if(order[i]=='E'){
        saikoro[1]=copy[4];
        saikoro[4]=copy[6];
        saikoro[6]=copy[3];
        saikoro[3]=copy[1];
        makecopy(saikoro,copy);
      }
      if(saikoro[1]==ue) break;
    }
    while(saikoro[2]!=syoumen){
      saikoro[2]=copy[3];
      saikoro[4]=copy[2];
      saikoro[5]=copy[4];
      saikoro[3]=copy[5];
      makecopy(saikoro,copy);
    }
    printf("%d\n",saikoro[3]);
  }
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
	a.at(i)-=(i+1);
  }
  sort(a.begin(), a.end());
  long long ans=0;
  if(n%2==1){
	int b=a.at(n/2);
	for(int i=0;i<n;i++){
	  ans+=abs(a[i]-b);
	}
  }else{
	int b1=a.at(n/2),b2=a.at((n/2)-1);
	long long ans1=0;
    long long ans2=0;
	for(int i=0;i<n;i++){
	  ans1+=abs(a.at(i)-b1);
	  ans2+=abs(a.at(i)-b2);
	}
    ans=min(ans1,ans2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int h1 = scanner.nextInt();
        final int m1 = scanner.nextInt();
        final int h2 = scanner.nextInt();
        final int m2 = scanner.nextInt();
        final int k = scanner.nextInt();

        System.out.println(Math.max(h2*60 + m2 - (h1*60 + m1) - k, 0));
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }
    }
}


Measured memory_bytes: 32684
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<vector<int>> BA(N,vector<int>(2,0));
    for(int i=0; i<N; i++){
        cin >> BA[i][1] >> BA[i][0];
    }

    sort(BA.begin(),BA.end());
    int time=0;
    for(int i=0; i<N; i++){
        time+=BA[i][1];
        if(time<=BA[i][0]){
            continue;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    int q;
    cin >> q;
    for (int j = 0; j < q; ++j) {
        int b, e;
        cin >> b >> e;
        reverse(a.begin() + b, a.begin() + e);
    }
    for (int i = 0; i < n; ++i) {
        if (i == 0) cout << a[0];
        else cout << " " << a[i];
    }
    cout << endl;
}



Measured memory_bytes: 3108
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
const int INF=1e+9;
const ll INFLL=1e+17;
int N;
int prime[1000000];
vi sieve(int x){
  vi res;
  for(int i=2;i<=x;i++) prime[i]=true;
  for(int i=2;i<=x;i++){
    if(prime[i]){
      res.push_back(i);
      int b=i;
      while(b<=x){
	prime[b]=false;
	b+=i;
      }
    }
  }
  return res;
}
void solve(){
  vi v=sieve(55555);
  int cnt=0,j=0;
  while(cnt<N){
    if(v[j]%10==3){
      std::cout<<v[j]<<" ";
      cnt++;
    }
    j++;
  }
  std::cout<<"\n";
}
int main(){
  cin>>N;
  solve();
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
    int A,B,C,D;
    int sq1,sq2;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    sq1 = A*B;
    sq2 = C*D;
    if(sq1 > sq2){
      printf("%d\n",sq1);
    }else if(sq1 < sq2){
      printf("%d\n",sq2);
    }else{
      printf("%d\n",sq1);
    }
}


Measured memory_bytes: 128
import java.util.*;

public class Main{
    public static void main(String[]args){
        int[][] bingo=new int[3][3];
        
        Scanner sc = new Scanner(System.in);
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                bingo[i][j]=sc.nextInt();
            }
        }
      
        int N=sc.nextInt();
        int count=0;
        int [] number =new int[N];

        for(int i=0;i<N;i++){
            number[i]=sc.nextInt();
        }
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                for(int m=0;m<N;m++){
                    if(number[m]==bingo[i][j])
                    bingo[i][j]=0;
                }
            }
        }
        if(bingo[0][0]+bingo[0][1]+bingo[0][2]==0||bingo[1][0]+bingo[1][1]+bingo[1][2]==0||
           bingo[2][0]+bingo[2][1]+bingo[2][2]==0||bingo[0][0]+bingo[1][0]+bingo[2][0]==0||
           bingo[0][1]+bingo[1][1]+bingo[2][1]==0||bingo[0][2]+bingo[1][2]+bingo[2][2]==0||
           bingo[0][0]+bingo[1][1]+bingo[2][2]==0||bingo[2][0]+bingo[1][1]+bingo[0][2]==0
           )System.out.println("Yes");
           else
           System.out.println("No");
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

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; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};
ll N,M,V,P,border;
bool is_pos(vector<ll> A,int mid){
    if(A[mid]+M<border) return false;
    ll score=A[mid]+M;

    ll sum=M*(V-P);
    //cout<<mid<<", "<<score<<", "<<sum<<endl;
    for(int i=0;i<=N-P;++i){
        if(i==mid) continue;
        sum-=min(M,score-A[i]);
        if(sum<=0) return true;
    }
    return false;
}

int main() {
    cin>>N>>M>>V>>P;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    border=A[N-P];
    if(V<=P){
        cout<<A.end()-lower_bound(A.begin(),A.end(),border-M)<<endl;
        return 0;
    }

    ll mini=-1,maxi=N-P;
    while(maxi-mini>1){
        ll mid=(maxi+mini)/2;
        //cout<<maxi<<" "<<mini<<" "<<mid<<endl;
        if(is_pos(A,mid)){
            maxi=mid;
        }else mini=mid;

    }

    cout<<N-maxi<<endl;

    return 0;
}


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

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

N, M = map(int, raw_input().split())
m = {}
for i in range(2, 100000):
    if M % i == 0:
        m[i] = 0
    while M % i == 0:
        m[i] += 1
        M /= i

if M > 1:
    m[M] = 1

ans = 1
MOD = 10 ** 9 + 7

for p in m:
    S = 1
    for i in range(1, m[p] + 1):
        S *= N + m[p] - i
        S /= i
    ans *= S
    ans %= MOD

print ans

Measured memory_bytes: 6136
import java.util.Arrays;
import java.util.Scanner;
class Main{
	public static void main(String[] args){
	Scanner x=new Scanner(System.in);
        while(x.hasNext()){
            int m=x.nextInt();
            int[] A=new int[m];
            for(int i=0;i<m;i++){
                A[i]=x.nextInt();
            }
			int count=0;
            int n =A.length;
			for(int i=0;i<n-1;i++){
				for(int j=n-1;j>i;j--){
					if(A[j-1]>A[j]){
						int temp = A[j];
						A[j]=A[j-1];
						A[j-1]=temp;
						count++;
					}
				}
			}
			Show(A);
			System.out.println(count);
			break;
		}
	}	
	public static void Show(int[] A){
	    int i;
		for(i=0;i<A.length-1;i++){
			System.out.print(A[i]+" ");
		}
		System.out.println(A[i]);
	}
}	


Measured memory_bytes: 26240
n = gets.to_i
a,b = 2.times.map{Array.new(n)}
ab = Array.new(2*n){[0,0]}
sum_a,sum_b = 0,0

n.times do |i|
  c,d = gets.split.map(&:to_i)
  a[i],b[i] = c,d
  sum_a += c
  sum_b += d
  ab[2*i,2] = [[c,i],[d,i]]
end
ab = ab.sort_by{|i,j|i}

used = Array.new(n,false)
n.times do |i|
  used[ab[i][1]] = true
end

sum_mix = 0
n.times do |i|
  sum_mix += ab[i][0]
end

if used.all?{|b|b == true}
  ans = [sum_a,sum_b].min
  n.times do |i|
    ret = sum_mix-(a[i] < b[i] ? a[i] : b[i])
    ret += ab[n][1] == i ? ab[n+1][0] : ab[n][0]
    ans = ret if ans > ret
  end
else
  ans = [sum_a,sum_b,sum_mix].min
end
p ans

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - キャンディーとN人の子供イージー / Children and Candies (ABC Edit)
            int n = int.Parse(Console.ReadLine());
            int candies = 0;

            for(int i = 1; i <= n; i++)
            {
                candies += i;
            }

            Console.WriteLine(candies);
        }
    }
}

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

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

  vector<int> a(n + 1);
  vector<int> see(n + 1);

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

  int ans = 0;
  int next = 1;
  while (true) {
    ans++;
    if (see[next] == 1) {
      ans = -1;
      break;
    }
    see[next] = 1;
    next = a[next];
    if (next == 2) break;
  }

  cout << ans << endl;
}


Measured memory_bytes: 4008
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    ans = 0
    for i in range(60):
        one = 0
        for a in A:
            if a & (1 << i):
                one += 1
        ans = (ans + one * (N - one) * (1 << i)) % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    int p, q, r;
     cin >> p >> q >> r;
    ppp(min({p+q, q+r, r+p}));

    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
z=[]
x=[]
y=[]
for i in a:
    if i%4==0:
        z.append(i)
    elif i%2==0:
        x.append(i)
    else:
        y.append(i)
yy=len(y)
if len(x)==0:
    if len(z)+1-yy>=0:
        print("Yes")
    else:
        print("No")
    exit()
if len(z)-yy>=0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 63000
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long ll;
typedef long double ld;
#define INF (1LL<<60)
#define MOD1 1000000007
/*swap 交換*/
void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
/*2つのうち大きい数を返す*/
ll max2(ll a,ll b){return a>=b?a:b;}
/*2つのうち小さい数を返す*/
ll min2(ll a,ll b){return a>=b?b:a;}
/*絶対値*/
ll ABS(ll a){return a>=0?a:(-a);}
typedef struct{
    ll aa;
    ll bb;
}frequent;
// 小大
int compare(const void *a, const void *b){
    return *(ll *)a>*(ll *)b?1:*(ll *)a<*(ll *)b?-1:0;}

int main(void){
    ll n,i;
    scanf("%lld",&n);
    ll h[n],dp[n];
    for(i=0;i<n;i++){
        scanf("%lld",&h[i]);
    }
    dp[0]=0;
    dp[1]=ABS(h[1]-h[0]);
    for(i=2;i<n;i++){
        dp[i]=min2( dp[i-1]+ABS(h[i]-h[i-1]), dp[i-2]+ABS(h[i]-h[i-2]) );
    }
    // for(i=0;i<n;i++){
    //     printf("%lld ",dp[i]);
    // }
    printf("%lld\n",dp[n-1]);
    return 0;
}


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

X, Y = [int(x) for x in input().strip().split()]

ans = 0
if X == 1:
    ans = 30 * 10 ** 4
elif X == 2:
    ans = 20 * 10 ** 4
elif X == 3:
    ans = 10 * 10 ** 4

if Y == 1:
    ans += 30 * 10 ** 4
elif Y == 2:
    ans += 20 * 10 ** 4
elif Y == 3:
    ans += 10 * 10 ** 4

if X == 1 and Y == 1:
    ans += 40 * 10 ** 4

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
    static final int INF = Integer.MAX_VALUE;
    static final int WHITE = 0;
    static final int GRAY  = 1;
    static final int BLACK = 2;
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] g = new int[n][n];
        
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int in = sc.nextInt();
                g[i][j] = in == -1 ? INF : in;
            }
        }
        
        System.out.println(prim(g, n));
    }
    
    // g[u][v]にuからvへの辺の重みが記録されている。
    static int prim(int[][] g, int n) {
        int u;
        int minV;
        int[] d = new int[n];     // 「T (T: MSTに属する頂点の集合) に属する頂点」と「V-T (V: グラフの全頂点) に属する頂点」をつなぐ辺の中で、重みが最小の辺の重み
        int[] p = new int[n];     // MSTにおける、頂点vの親
        int[] color = new int[n]; // vの訪問状態
        
        for (int i = 0; i < n; i++) {
            d[i] = INF;
            p[i] = -1;
            color[i] = WHITE;
        }
        
        d[0] = 0;
        
        while(true) {
            minV = INF;
            u = -1;
            for (int i = 0; i < n; i++) {
                if (minV > d[i] && color[i] != BLACK) {
                    u = i;
                    minV = d[i];
                }
            }
            if (u == -1) break;
            color[u] = BLACK;
            for (int v = 0; v < n; v++) {
                if (color[v] != BLACK && g[u][v] != INF) {
                    if (d[v] > g[u][v]) {
                        d[v] = g[u][v];
                        p[v] = u;
                        color[v] = GRAY;
                    }
                }
            }
        }
        int sum = 0;
        for (int i = 0; i < n; i++) {
            if (p[i] != -1) sum += g[i][p[i]];
        }
        return sum;
    }
}



Measured memory_bytes: 40032
package main

import "fmt"

func main() {
	var n, t int
	fmt.Scan(&n)
	tot, p := 1, 1
	for i := 0; i < n; i++ {
		fmt.Scan(&t)
		if t%2 == 0 {
			p *= 2
		}
		tot *= 3
	}
	fmt.Println(tot - p)
}


Measured memory_bytes: 512
program unification
  implicit none
  character(100000) :: s
  integer :: n, i, m = 0
  read(*,*) s
  n = len_trim(s)
  do i = 1, n
    m = m+ichar(s(i:i))-48
  end do
  write(*,'(i0)') 2*min(m,n-m)
end program unification

Measured memory_bytes: 700
// organize and work - Abhinav IIITA
#include <bits/stdc++.h>
using namespace std;
#define int long long 
void q1(){
	int a,b;
	cin>>a>>b;
	if(a<10 && b<10)
	cout<<a*b;
	else
	cout<<"-1";
}
void q2(){
	int n;cin>>n;
	int fg=0;
	for(int i=1;i<=9;++i)
	if(n%i==0){
		int ano=n/i;
		if(ano<=9 && ano>=1)
		fg=1;
	}
	fg==1 ? cout<<"Yes\n" : cout<<"No\n";
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	t=1;
	while(t--)
	q2();
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var items = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
            var N = items[0];
            var K = items[1];
            var H = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();

            var attacks = new List<long>();
            foreach (var h in H.OrderByDescending(elem => elem))
            {
                if (K > 0)
                {
                    // 体力が高いモンスターには必殺技を使う
                    K--;
                }
                else
                {
                    // それ以外は攻撃
                    attacks.Add(h);
                }
            }

            var answer = attacks.Sum();
            Console.WriteLine(answer);
        }
    }
}


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

using namespace std;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

ll solve(ll N, ll M) {
    const int mod = 1e9 + 7;
    if (N == 1) {
        return (M + 1) % mod;
    }
    N--, M++;
    ll k1 = ((M % N) % mod) * ((M / N) % mod + 1) % mod;
    ll c1 = ((M / N) % mod + 1) % mod;
    ll k2 = (M % mod + mod - k1) % mod;
    ll c2 = (c1 + mod - 1) % mod;
    return (k1 * c1 % mod + k2 * c2 % mod) % mod;
}

void solve() {
    ll N, M;
    cin >> N >> M;
    cout << solve(N, M) << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 3236
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    let d: i32 = read();
    let one_tree = 2 * d + 1;
    let quotient = n / one_tree;
    let reminder = n % one_tree;
    let ans = if reminder == 0{
        quotient
    } else {
        quotient + 1
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


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

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

Measured memory_bytes: 256
def modpow(a, n, m)
  return 1 if n == 0

  tmp = modpow(a, n / 2, m)
  n % 2 == 0 ? tmp * tmp % m : tmp * tmp * a % m
end

M = 1_000_000_007

n, k = gets.chomp.split(' ').map(&:to_i)

g = (0..k).map { 0 }

answer = k.downto(1).map { |m|
  g[m] = (k / m).downto(2).inject(modpow(k / m, n, M)) { |r, i| (r - g[i * m]) % M } 
  g[m] * m % M
}.sum % M

puts answer


Measured memory_bytes: 16200
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int n;
	cin >> n;
	int i = 1;
	while(1){
		if(i < n) i *= 2;
		else if(i == n) break;
		else{
			i /= 2;
			break;
		}
	}
	cout << i ;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int a,b,c,x;
  cin>>a>>b>>c>>x;
  int ans=0;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(500*i+100*j+50*k==x){ans++;}
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if(a - b * 2 < 0){
        printf("0");
    }else{
        printf("%d", a - b * 2);
    }
    
    return 0;
    
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
struct UnionFind{
  vector<int>d;//データ
  UnionFind(int n=0):d(n,-1){}//初期値は全部根(-1)とする
  int find(int x){
    if(d[x]<0)return x;
    return d[x]=find(d[x]);
  }
  bool unite(int x,int y){//2つ頂点をくっつける
    x=find(x);
    y=find(y);
    if(x==y)return false;//一致していればOK
    if(d[x]>d[y])swap(x,y);//サイズが大きいものをxとする（根は負なので大小関係に注意）
    d[x]+=d[y];//サイズの合算
    d[y]=x;//根をxとする
    return false;
  }
  bool same(int x,int y){//同じ集合に属しているかを判定する
    return find(x)==find(y);
  }
  int size(int x){//サイズを求める（根はマイナスなので、マイナスをとる）
    return -d[find(x)];
  }
};
int deg[200200];
vector<int>to[200200];
int main() {
  int n,m;
  cin>>n>>m;
  UnionFind uf(n);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    deg[a]++;
    deg[b]++;
    uf.unite(a,b);
  }
 int saidai=0;
  rep(i,n){
    saidai=max(saidai,uf.size(i));
  }
  cout<<saidai<<endl;
  return 0;
}

Measured memory_bytes: 9592
#include<iostream>
#include<cstring>
using namespace std;
char a[4],b[4];
int main(){
	cin>>a;
	cin>>b;
	if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

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

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))


#ifdef KIRYA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h << "\n";
}

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;

    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;

    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].push_back(v);
    }
    int from, to;
    cin >> from >> to;
    --from, --to;
    vector<vector<int>> visited(n, vector<int>(3, 0));
    queue<pair<int, int>> q;
    q.push({from, 0});
    visited[from][0] = 1;
    while (!q.empty()) {
        auto p = q.front();
        q.pop();
        int v = p.first, d = p.second + 1;
        int x = d % 3;
        for (int ngb : g[v]) {
            if (visited[ngb][x]) {
                continue;
            }
            if (ngb == to && x == 0) {
                cout << d / 3 << endl;
                return;
            }
            visited[ngb][x] = 1;
            q.push({ngb,d});
        }
    }
    cout << "-1\n";
}

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

    int q = 1;

    for (int i = 0; i < q; ++i) {
        solve();
    }
}

Measured memory_bytes: 11264
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 51


int main(){
  int n,ma,mb;
  int a,b,c;
  int dp[501][501];
  
  scanf("%d%d%d",&n,&ma,&mb);

  for(int i=0;i<=n*10;i++){
    for(int j=0;j<=n*10;j++){
      dp[i][j] = INF;
    }
  }


  dp[0][0] = 0;
  
  for(int i=0;i<n;i++){
    scanf("%d%d%d",&a,&b,&c);
    
    for(int j=n*10;j>=0;j--){
      for(int k=n*10;k>=0;k--){
        dp[j+a][k+b] = min(dp[j+a][k+b],dp[j][k] + c);
      }
    }
  }

  int ans = INF;
  
  for(int i=1;ma*i <= n*10 && mb*i <= n*10;i++){
    ans = min(ans, dp[ma*i][mb*i]);
  }

  if(ans == INF) ans = -1;
  
  printf("%d\n",ans);
  
  return 0;
}


Measured memory_bytes: 1024
import java.util.concurrent.LinkedBlockingQueue

fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main() {
    data class Edge(val from: Long, val to: Long, val distance: Long)

    val n = readLine()?.toInt() ?: return
    val edges = hashMapOf<Long, MutableList<Edge>>()
    repeat(n - 1) {
        val (a, b, c) = longList()
        edges.getOrPut(a) { mutableListOf() }.add(Edge(a, b, c))
        edges.getOrPut(b) { mutableListOf() }.add(Edge(b, a, c))
    }
    val (q, k) = intList()
    val arrived = Array(n + 1) { false }
    val distances = Array(n + 1) { 0L }
    val queue = LinkedBlockingQueue<Pair<Long, Long>>()
    queue.add(Pair(k.toLong(), 0L))
    arrived[k] = true
    while (queue.isNotEmpty()) {
        val (v, d) = queue.poll()
        edges[v]?.forEach {
            val to = it.to.toInt()
            if (!arrived[to]) {
                arrived[to] = true
                val distance = d + it.distance
                distances[to] = distance
                queue.add(Pair(it.to, distance))
            }
        }
    }
    buildString {
        repeat(q) {
            val (x, y) = intList()
            appendln(distances[x] + distances[y])
        }
    }.let {
        println(it.trimIndent())
    }
}


Measured memory_bytes: 99928
//#include "pch.h"
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <math.h>
#define OO INT_MAX
#define mp(x,y) make_pair(x,y)
#define x first
#define y second
#define ll unsigned long long int
#define pp pair<int,int>
#define heap priority_queue<pp, vector<pp>, greater<pp>>
using namespace std;

int ans;
string  s;
string s1;
void check(string str, int i) {
	if (i == s.size()) {
		if (str == "ABC")
			ans++;
		return;
	}
	s1 = str;
	check(s1,i+1);
	s1 = str + s[i];
	check(s1, i + 1);
}

int main()
{
	//freopen("test.txt", "r", stdin);
	string s, t;
	int n;
	cin >> n;
	cin >> s >> t;
	string newS;
	for (int i = 0; i < n; i++) {
		newS.push_back(s[i]);
		newS.push_back(t[i]);
	}
	cout << newS;
}




Measured memory_bytes: 256