akhauriyash/Code-Regression huggingface dataset:
def combmod_pre(N, p):
    '''
    sample usage:
        p = 10**9+7
        N = 10**6
        fact, finv = combmod_pre(N, p)
        combmod(n, r, p)
    '''
    fact = [1, 1]
    finv = [1, 1]
    inv = [0, 1]
    for i in range(2, N+1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        finv.append((finv[-1] * inv[-1]) % p)
    return (fact, finv)


def combmod(n, r, fact, finv, p):
    '''
    sample usage:
        combmod(3000, 1000, fact, finv, p)
            p is a same value of combmod_pre's argument
            fact, finv is return value of combmod_pre
    '''
    if r < 0 or n < r:
        return 0
    return fact[n] * finv[r] * finv[n-r] % p


p = 10**9+7
N = 10**6
fact, finv = combmod_pre(N, p)

h, w, a, b = (int(x) for x in input().split())
ans = 0
for j in range(b, w):
    x = combmod(h - a - 1 + j, j, fact, finv, p)
    y = combmod(a + w - 2 - j, w-1 - j, fact, finv, p)
    ans += x * y
print(ans % p)




Measured memory_bytes: 122232
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

#include <atcoder/all>

using namespace atcoder;
//typedef modint998244353 mint;

int main(){
  int N,M;
  cin>>N>>M;
  VI A(M),B(M);
  rep(i,M) cin>>A[i]>>B[i];
  dsu D(N);
  rep(i,M) D.merge(A[i]-1,B[i]-1);
  VVI X=D.groups();
  cout<<X.size()-1<<endl;
}


Measured memory_bytes: 8328
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 10;
    // const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 179;
    // const ld PI = 3.1415926535;
#endif

// #pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")`  

int f(int x) {
    return x*x*x*x*x;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = -1000; i <= 1000; i++) {
        for (int j = -1000; j <= 1000; j++) {
            if (f(i) - f(j) == n) {
                cout << i << " " << j << "\n";
                return 0;
            }
        }
    }
}
/*

*/  


Measured memory_bytes: 3612
import numpy as np
import sys
input = sys.stdin.readline


n, t = map(int, input().split())
dish = [list(map(int, input().split())) for _ in range(n)]
dish.sort()

ans = 0
dp = np.zeros(t, dtype=int)
for time, point in dish:
    ans = max(ans, dp.max()+point)
    np.maximum(dp[time:], dp[:-time]+point, out=dp[time:])
print(ans)

Measured memory_bytes: 12772
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

int main() {
	int n;
	cin >> n;
	ll ans = 0;
	for (int a = 1; a < n; a++) {
		ans += (n - 1) / a;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3592
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int[string] s, t;

    int n = readint;
    for (int i = 0; i < n; i++) {
        string a = readln.chomp;
        s[a]++;
    }

    int m = readint;
    for (int i = 0; i < m; i++) {
        string a = readln.chomp;
        t[a]++;
    }

    int ans = 0;
    foreach (k, v; s) {
        ans = max(ans, max(0, v - t.get(k, 0)));
    }
    writeln(ans);
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int min=10000,N,T;
    scanf("%d %d",&N,&T);
    int c[N],t[N],i,counter=0;

    for(i=0;i<N;i++){
        scanf("%d %d",&c[i],&t[i]);
        if((c[i]<min)&&(t[i]<=T)){
            min = c[i];
        }
        if(T<t[i]){
            counter += 1;
        }
    }
    if(counter==N){
        printf("TLE");
        return 0;
    }

    printf("%d",min);

}

Measured memory_bytes: 128
import math

def calculate():
    if ra + rb < d:
        print 0
    elif abs(ra - rb) <= d <= ra + rb:
        print 1
    elif rb > ra and d < rb - ra:
        print -2
    elif ra > rb and d < ra - rb:
        print 2
        
N = int(raw_input())

for i in range(N):
    xa, ya, ra, xb, yb, rb = map(float, raw_input().split())
    d = math.sqrt((xb-xa)**2 + (yb-ya)**2)
    calculate()

Measured memory_bytes: 4388
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, _begin, _end) for (__typeof(_end) end = _end, begin = _begin,  i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0, _len = (end); i < (_len); i += 1)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define readint ({int t;cin >> t;t;})

const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}


//#define int ll
int N, K, A[101010], memo[101010];
bool first(int k){
    if(k == 0)return 0;
    if(~memo[k])return memo[k];
    int win = 0;
    _for(i,N)if(k >= A[i])win = win || (!first(k - A[i]));
    return memo[k] = win;
}
class KStones {
public:

void solve(std::istream& cin, std::ostream& cout) {
    cin >> N >> K;
    Fill(memo, -1);
    _for(i,N)cin >> A[i];
    cout << (first(K)?"First":"Second") << endl;

}
};


#undef int
int main() {
	KStones solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	in.tie(0); ios::sync_with_stdio(0); out<<fixed<<setprecision(20);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3840
/* ex9_1
  kt125*/

#include<stdio.h>
#include<stdlib.h>
#define SIZE 11
typedef struct{
    int size; //格納最大数
    int count; //データ数
    char data[SIZE]; //データの配列
    char *top; //topへのポインタ
} stack;
void initialize_stack(stack *stk); //スタックを初期化する関数
void print_stack(stack *stk); //スタックの中身をprintする関数
void push(stack *stk, char x); //スタックのpush操作をする関数
void pop(stack *stk); //スタックのpop操作wpする関数

stack stk;

int main(void){
    char key[12];
    char *ptr;
    scanf("%s", key); //入力を読み取る
    ptr = key; //keyの先頭アドレスを渡す
    initialize_stack(&stk);
    while(*ptr){ //ヌル文字に至るまで数字ならpush,'B'ならpop
        if( *ptr == '0' || *ptr == '1'){
            push(&stk, *ptr);
        }else{
            pop(&stk);
        }
        ptr++;
    }
    print_stack(&stk);
    return 0;
}

void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]); //データの一番後ろのアドレスを渡す
}

void pop(stack *stk){
    if(stk->count <= 0){ //データが空のときは何もしない
        return;
    }else{
        stk->top++;
        stk->count--;
    }
}

void push(stack *stk, char x){
    if(stk->count >= stk->size){ //エラー出力
        printf("Error:stack overflow. (x=%lf)\n", x);
        exit(1);
    }else{
        //topをずらして、そのアドレスに新たにxを追加
        stk->top--;
        *(stk->top) = x;
        stk->count++;
    }
}

void print_stack(stack *stk){
    char *p;
    p = &(stk->data[SIZE-1]);
    //stkには古いものが後ろに格納されているので後ろからprint
    for(int i=0; i<stk->count; i++){
        printf("%c", *p--);
    }
    printf("\n");
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n - 1); i >= 0; --i)
#define mod 1000000007
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
//#define INF 931931114518101
using namespace std;
typedef pair<ll, ll> P;
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename ARR> void fill_all(ARR &arr, const T &v) {
  for (auto &i : arr) {
    fill_all(i, v);
  }
}
#define yo 100001
//------------------変数-----------------------//
ll n;
pair<double, double> trans[5000];
//-------------------関数----------------------//

int main() {
  ll m;
  cin >> n >> m;
  n = n - m;
  ll cnt = n * 100;
  cnt += m * 1900;
  ll hoge = pow(2, m);
  cout << cnt * hoge << endl;
}


Measured memory_bytes: 512
#include"bits/stdc++.h"
using namespace std;

int main()
{
    int e[12];
    for(int i=0;i<12;i++)
        cin >> e[i];
    sort(e,e+12);
    for(int i=0;i<3;i++)
        for(int j=0;j<3;j++)
            if(e[i*4]!=e[i*4+j+1]){
                cout << "no" << endl;
                return 0;
            }
    cout << "yes" << endl;
    return 0;
}



Measured memory_bytes: 3160
import java.util.Scanner;

public class Main {
		public static void main(String args[]) {
			Scanner in = new Scanner(System.in);
			int inputNum = in.nextInt();
			System.out.println(getNowShakkin(inputNum));
		}

		public static int getNowShakkin(int weekInterval) {
			double result = 100;

			for (int i = 0; i < weekInterval; i++) {
				result = result + result * 0.05;
				result = (Math.ceil((double) result));
			}

			return (int)result * 1000;
		}
	}

Measured memory_bytes: 25968
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>

struct node{
	struct node *left;
	struct node *right;
	struct node *parent;
	int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
	while (x->left!=NIL){
		x = x->left;
	}
	return x;
}

Node treeSearch(Node u, int k){
	if (u == NIL){return NIL;}
	if (u->key == k){ return u; }
	else if (u->key > k){
		return treeSearch(u->left, k);
	}
	else{
		return treeSearch(u->right, k);
	}
}

Node treeSuccessor(Node x){
}

void treeDelete(Node z){
	Node y; // node to be deleted
	Node x; // child of y

	if (z->left == NIL && z->right == NIL){//子なし
		if (z->parent->left == z){
			z->parent->left = NIL;
		}
		else{
			z->parent->right = NIL;
		}
		free(z);
	}
	else if (z->left != NIL && z->right != NIL){//子2人
		x = z->right;
		while (x->left != NIL){
			x = x->left;
		}
		z->key = x->key;
		treeDelete(x);
		
	}
	else{//子1人
		if (z->left!=NIL){//左に子がいたら
			if (z->parent->left == z){//zが親の左側にいたら
				z->parent->left = z->left;
				z->left->parent = z->parent;
			}
			else{//zが親の右側にいたら
				z->parent->right = z->left;
				z->left->parent = z->parent;
			}
		}
		else{//右に子がいたら
			if (z->parent->left == z){//zが親の左側にいたら
				z->parent->left = z->right;
				z->right->parent = z->parent;
				free(z);
			}
			else{//zが親の右側にいたら
				z->parent->right = z->right;
				z->right->parent = z->parent;
			}
		}
	}
}

Node sss(int k, Node x){
	if (x == NIL){ return x; }
	if (k < x->key){
		if (x->left != NIL){
			return sss(k, x->left);
		}
		else{
			return x;
		}
	}
	else{
		if (x->right != NIL){
			return sss(k, x->right);
		}
		else{
			return x;
		}
	}
}

void insert(int k){
	Node y = sss(k,root);
	Node z;

	z = malloc(sizeof(struct node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	z->parent = y;

	if (y == NIL){ root=z; }
	else if (y->key < k){
		y->right = z;
	}
	else{
		y->left = z;
	}
}

void inorder(Node u){
	if (u->left != NIL)
		inorder(u->left);
	printf(" %d", u->key);
	if (u->right != NIL)
		inorder(u->right);	
}
void preorder(Node u){
	printf(" %d", u->key);
	if (u->left != NIL)
		preorder(u->left);
	if (u->right != NIL)
		preorder(u->right);
}


int main(){
	int n, i, x;
	char com[20];
	scanf("%d", &n);

	for (i = 0; i < n; i++){
		scanf("%s", com);
		if (com[0] == 'f'){
			scanf("%d", &x);
			Node t = treeSearch(root, x);
			if (t != NIL) printf("yes\n");
			else printf("no\n");
		}
		else if (com[0] == 'i'){
			scanf("%d", &x);
			insert(x);
		}
		else if (com[0] == 'p'){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if (com[0] == 'd'){
			scanf("%d", &x);
			treeDelete(treeSearch(root, x));
		}
	}

	return 0;
}


Measured memory_bytes: 20480
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	string x, y;
	cin >> x >> y;
	if (x > y)
		cout << '>' << endl;
	else if (x == y)
		cout << '=' << endl;
	else
		cout << '<' << endl;
}

Measured memory_bytes: 256
def solve():

    n = int(input())
    a = list(map(int, input().split()))

    b = [a[i] for i in range(n)]

   # print(a)
   # print(b)

    #Even
    sum_e = 0
    ans_e = 0

    for i in range(n):
        sum_e += a[i]
        if i%2 == 0:
            if sum_e <= 0:
                ans_e += abs(sum_e) + 1
                sum_e += abs(sum_e) + 1
        else:
            if sum_e >= 0:
                ans_e += abs(sum_e) + 1
                sum_e -= abs(sum_e) + 1

    #Odd
    sum_o = 0
    ans_o = 0

    for i in range(n):
        sum_o += b[i]
        if i%2 == 1:
            if sum_o <= 0:
                ans_o += abs(sum_o) + 1
                sum_o += abs(sum_o) + 1
        else:
            if sum_o >= 0:
                ans_o += abs(sum_o) + 1
                sum_o -= abs(sum_o) + 1

    if ans_o <= ans_e:
        ans = ans_o
    else:
        ans = ans_e


    print(ans)

if __name__ ==  "__main__":
    solve()


Measured memory_bytes: 20180
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  for(int i=0;i<=s.size();i++){
    for(int j=i;j<=s.size();j++){
      if(s.substr(0,i)+s.substr(j,s.size())=="keyence"){
        cout << "YES";
        return 0;
      }
    }
  }
  cout << "NO";
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll sum(ll N) {
    ll n = N % 4;
    if (n == 1)
        return 1;
    if (n == 3)
        return 0;
    if (n == 2)
        return 3LL + 4LL * (N - 2) / 4;
    return N;
}

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

    ll A, B;
    cin >> A >> B;

    cout << (sum(B) ^ sum(std::max(A - 1, 0LL))) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int N, M;
    cin >> N >> M;
    vector<set<int>> g(N+1);
    REP(i,M) {
        int a, b;
        cin >> a >> b;
        g[a].insert(b);
        g[b].insert(a);
    }

    vector<int> q;
    vector<int> ans(N+1);
    ans[0] = 1; ans[1] = 1;
    for(auto x:g[1]) {
        ans[x] = 1;
        q.push_back(x);

        //g[1].erase(x);
        //g[x].erase(1);
    }

    while(!q.empty()) {
        vector<int> tmp;
        swap(q,tmp);
        for (auto x:tmp) {
            for (auto y:g[x]){
                if (ans[y] == 0) {
                    ans[y] = x;
                    q.push_back(y);
                }
                //g[x].erase(y);
                //g[y].erase(x);
            }
        }
    }

    if(find(ALL(ans),0) == ans.end()) {
        OUT("Yes")
        FOR(i,2,N+1) OUT(ans[i])
    } else OUT("No")

    return 0;
}

Measured memory_bytes: 27652
def func(input):
  if input % 2 == 0:
    return int(0.5 * input)
  else:
    return int(3*input+1)
  

input = list(map(int,input().split()))
start = int(input[0])

list = []

for i in range(1,1000000):
  if i == 1:
    list.append(start)
  else:
    temp = func(list[i-2])
    if temp in list:
      print(i)
      break
    else:
      list.append(temp)



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

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

    set<int> S;
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        S.insert(a);
    }

    if (S.size() == N)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    
    
}

Measured memory_bytes: 9600
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        HashSet<Integer> set = new HashSet<>();
        int[] balls = new int[n+1];
        for(int i = 0; i<n; i++) {
            int a = sc.nextInt();
            balls[a]++;
            set.add(a);
        }
        Arrays.sort(balls);
        int cnt = set.size();
        int ans = 0;
        //System.out.println(cnt);
        for(int i = balls.length-set.size(); i< balls.length-1; i++) {
            //System.out.println(i+" "+balls[i]);
            if(cnt>k) {
                ans += balls[i];
                cnt--;
            }else break;
        }
        System.out.println(ans);

    }
}
class Ball {
    int a,b;
    public Ball(int a, int b) {
        this.a = a;
        this.b = b;
    }
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++)
  {
    cin >> d[i];
  }
  
  int ans = 0;
  for (int i = 0; i < N - 1; i++)
  {
    for (int j = i + 1; j < N; j++)
      ans += d[i] * d[j];
  }
  cout << ans << endl;
}

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

int a[10001];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	int ans = 0;
	for(int i=0;i<k;i++){
		ans+=a[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
    char S[55];
    scanf("%s", S);
    int length;
    int i;

    length = strlen(S);
    for (i = 0; i < length - 8; i++){
        printf("%c", S[i]);
    }
    printf("\n");




    return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int c, a, n;
        cin >> c >> a >> n;
        int ans = 0;
        c -= n;
        a -= n;
        if (c < 0 || a < 0) {
            c += n;
            a += n;
            ans += min(c, a);
            c -= ans;
            a -= ans;
            if (c > 0) {
                ans += c / 3;
            }
        } else {
            ans += n;
            c -= 2 * a;
            if (c < 0) {
                c += 2 * a;
                ans += c / 2;
            } else {
                ans += a;
                ans += c / 3;
            }
        }
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 3228
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main()
{
    string s, t;
    cin >> s >> t;
    auto repl = 10'000;

    for (int t_pos = 0; t_pos + t.length() <= s.length(); ++t_pos) {
        auto cnt = 0;
        for (int i = 0; i < t.length(); ++i) {
            if (t[i] != s[t_pos + i])
                ++cnt;
        }
        repl = min(repl, cnt);
    }
    cout << repl << endl;
    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main()
{
  string a, s, c;
  cin >> a >> s >> c;
  cout << a[0] << s[0] << c[0] << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int k = in.nextInt();

            for (int i = 0; i <= n; i++) {
                for (int j = 0; j <= m; j++) {
                    if (i * j + (i - n) * (j - m) == k) {
                        out.println("Yes");
                        return;
                    }
                }
            }

            out.println("No");
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 23380
#include <bits/stdc++.h>
//F6編譯，右上三角形執行，ctrl+c強制停止執行  F5開啟exe
#define ll long long
#define maxn 200005
#define mod 998244353
using namespace std;

typedef pair<int, int> P;

int n;
int a[maxn];
int cnt[maxn];
set<int> s;

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
        s.insert(a[i]);
        cnt[a[i]]++;
    }
    for (int i = 0; i < n; i++)
    {
        cnt[a[i]]--;
        if (cnt[a[i]] == 0)
            s.erase(a[i]);
        auto iter = s.end();
        iter--;
        printf("%d\n", *iter);
        cnt[a[i]]++;
        s.insert(a[i]);
    }
    return 0;
}


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

using ll = long long;

int N;
vector<vector<int>> graph;

ll calc(vector<int> roots) {
    ll muls[100]; fill(muls, muls+100, 1LL);

    for (int root : roots) {
        int dist[100]; fill(dist, dist+N, -1); dist[root] = 0;
        queue<int> que; que.push(root);
        while (!que.empty()) {
            int v = que.front(); que.pop();
            int n_children = 0;
            for (int w : graph[v]) {
                bool found = false;
                for (int r : roots) if (r == w) found = true;
                if (!found && dist[w] == -1) {
                    ++n_children;
                    dist[w] = dist[v] + 1;
                    que.push(w);
                }
            }
            muls[dist[v]] = max(muls[dist[v]], (ll)n_children);
        }
    }

    ll ans = roots.size();
    for (int j = 0; j < 100; ++j) ans *= muls[j];
    return ans;
}

pair<int, int> farthest_one(int x) {
    int dist[100];
    fill(dist, dist+N, -1);

    queue<int> que;
    dist[x] = 0; que.push(x);

    int ans = x;
    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (int w : graph[v]) {
            if (dist[w] == -1) {
                dist[w] = dist[v] + 1;
                ans = w; que.push(w);
            }
        }
    }
    return make_pair(ans, dist[ans]);
}

int main() {
    cin >> N;
    graph.resize(N);
    for (int j = 0; j < N-1; ++j) {
        int a, b; cin >> a >> b; --a; --b;
        graph[a].emplace_back(b); graph[b].emplace_back(a);
    }

    auto vsp = farthest_one(0), vgp = farthest_one(vsp.first);

    int diag = vgp.second;


    ll ans = 1LL << 60;

    vector<int> roots;
    for (int j = 0; j < N; ++j) {
        auto pr = farthest_one(j);
        if (pr.second <= (diag % 2 == 0 ? diag/2 : diag/2+1)) {
            roots.push_back(j);
        }
    }

    ans = calc(roots);

    if (diag % 2 == 0) {
        assert(roots.size() == 1);
        int centre = roots[0];
        for (int w : graph[centre]) {
            roots.clear();
            roots.push_back(centre); roots.push_back(w);
            ans = min(ans, calc(roots));
        }
    }

    cout << (1 + diag / 2) << " " << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// Add compile option "-std=c++11" for C++11 compile.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

// Macro
#define rep(i, N) for(int i=0; i<(int)N; i++)

// Type
template <typename T> using P = pair<T, T>;
using ll = long long;
using ull = unsigned long long;

// Constants
const ll INF = 1e18;
const ll MOD = 1000000007;

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

  int V[N], C[N];
  rep(i, N) cin >> V[i];
  rep(i, N) cin >> C[i];

  int res = 0;
  rep(i, N) {
    if(V[i] - C[i] >= 0) res += (V[i] - C[i]);
  }

  cout << res << endl;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>

int main(void){
	int n, i;
	double s[1000], m, a;
	while(1){
		m=0; a=0;
		scanf("%d", &n);
		if(n==0){ return(0); }
		for(i=0; i<n; ++i){	scanf("%lf", s+i); m+=s[i];}
		m/=n;
		for(i=0; i<n; ++i){ a+=(s[i]-m)*(s[i]-m); }
		printf("%lf\n", sqrt(a/n));
	}
}


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

public class Main {
  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String line = br.readLine();
    StringTokenizer st = new StringTokenizer(line);
    int a = Integer.parseInt(st.nextToken());
    int b = Integer.parseInt(st.nextToken());
    StringBuilder sb = new StringBuilder();
    if (a % 2 == 0 || b % 2 == 0) {
      sb.append(String.format("%s", "Even"));
    } else {
      sb.append(String.format("%s", "Odd"));
    }
    System.out.println(sb.toString());
  }
}


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

#define M 200010

#define mem(a, b) memset(a, b, sizeof(a))
#define F(literate_val, max, step) for (literate_val = 0; literate_val < max; literate_val += step)

typedef long long LL;
typedef unsigned long long ULL;

//std::unordered_map<LL, LL> _NAME_MAP;
LL Array[M];
inline LL qr()
{
    register char c = getchar();
    if (c == EOF)
        return -1;
    register LL n = 0;
    while (c > '9' || c < '0')
    {
        c = getchar();
    }

    while (c <= '9' && c >= '0')
    {
        n = (n << 3) + (n << 1) + c - 48;
        c = getchar();
    }

    return n;
}
inline char qrc()
{
    register char c = getchar();
    while (c < 'A' && c > 'Z')
        c = getchar();
    return c;
}

int main()
{

    LL n, m;
    n = qr();
    m = qr();
    LL c = qr();
    LL tmp = std::max(n, m);
    if (c % tmp != 0)
    {
        std::cout << c / tmp + 1 << '\n';
    }
    else
        printf("%lld", c / tmp);
    return 0;
}

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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()
#define YES()         printf("YES\n")
#define NO()          printf("NO\n")
#define Yes()         printf("Yes\n")
#define No()          printf("No\n")
#define in(a,x,b)     ((a) <= (x) && (x) < (b))

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;
template<class T = int> using V = vector<T>;

template<class T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T = int> T inline input() { T x; cin >> x; return (x); }
template<class T> void inline print(T& x) { cout << x << '\n'; }
#define debug(x) cerr << #x << ": " << x << endl;

const int dxs[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dys[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

int prime[1001001];
bool is_prime[1001001];

int sieve(int n) {
  int p = 0;
  for (int i = 0; i < n; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < n; i++){
    if (is_prime[i]){
      prime[p++] = i;
      for (int j = 2*i; j < n; j+=i) is_prime[j] = false;
    }
  }
  return p;
}

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

  int K,T;
  cin >> K >> T;
  int A[T];
  REP(i,T) cin >> A[i];

  priority_queue<int> q;
  REP(i,T) q.push(A[i]);

  while (q.size() > 1) {
    int first_max = q.top(); q.pop();
    int second_max = q.top(); q.pop();
    if (first_max > 1) q.push(first_max-1);
    if (second_max > 1) q.push(second_max-1);
  }

  cout << q.top()-1 << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
const double EPS = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int  maxn = 1e5 + 100;
const int  maxm = 300;
int a[maxn];
int main()
{
        int n;
        cin  >>n;
        for(int i=1;i<=n;i++)
        scanf("%d",a+i);
        int anser=0;
        int flag=0;
        int pop;
        int pop1;
        for(int i=1;i<n;i++)
        {
        if(a[i]==i&&a[i+1]==i+1)
        {
        int pop=a[i];
        a[i]=a[i+1];
        a[i+1]=pop;
        anser++;
        }
        }
        for(int i=1;i<=n;i++)
        {
        if(a[i]==i)
        anser++;
        }
        cout<<anser<<endl;
}


Measured memory_bytes: 640
from collections import deque

jumps = [
    [1, -2], [0, -2], [-1, -2], [-2, -1], [-2, 0], [-2, 1], [-1, 2], [0, 2], [1, 2], [2, -1], [2, 0], [2, 1]
]

def bfs(ipy, ipx, ys, xs, n):
    q = deque()
    q.append([ipy, ipx, -1])
    while q:
        py, px, t = q.popleft()
        if t == n-1:
            return True

        for dy, dx in jumps:
            npy = py + dy
            npx = px + dx
            if npy in range(10) and npx in range(10) and abs(npy - ys[t+1]) <= 1 and abs(npx - xs[t+1]) <= 1:
                q.append([npy, npx, t+1])

    return False

if __name__ == '__main__':
    while True:
        try:
            ipx, ipy = map(int, input().split())
            if ipx == 0 and ipy == 0:
                break
            n = int(input())
            l = list(map(int, input().split()))
            xs = l[::2]
            ys = l[1::2]
            
            if bfs(ipy, ipx, ys, xs, n):
                print('OK')
            else:
                print('NA')
        except:
            break

Measured memory_bytes: 7984
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}


 
int main() {
  int N;
  cin >> N;
  vi A(N);
  vp cmd;
  rep(i,N) {
    cin >> A[i];
  }
  sort(rng(A));
  vi pl,mi;
  pl.push_back(A[N-1]);
  mi.push_back(A[0]);
  srep(i,1,N-1) {
    if(A[i] >= 0) {
      pl.push_back(A[i]);
    } else {
      mi.push_back(A[i]);
    }
  }
  int p = mi[0];
  rep(i,sz(pl)-1) {
    cmd.push_back(P(p,pl[i]));
    p -= pl[i];
  }
  int q = pl[sz(pl)-1];
  cmd.push_back(P(q,p));
  q -= p;
  srep(i,1,sz(mi)) {
    cmd.push_back(P(q,mi[i]));
    q -= mi[i];
  }
  cout << q << endl;
  rep(i,sz(cmd)) {
    cout << cmd[i].first << " " << cmd[i].second << endl;
  }

  return 0;
}

Measured memory_bytes: 3828
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const int INF = INT_MAX / 2;
map<vector<vector<int> >, int> memo;
vector<vector<int> > goal(4, vector<int>(8, 0));

int solve(vector<vector<int> >& card)
{
    if(card == goal)
        return 0;
    if(memo.find(card) != memo.end())
        return memo[card];

    int ret = INF;

    for(int i=0; i<4; ++i){
        for(int j=1; j<8; ++j){
            if(card[i][j] != 0)
                continue;
            for(int k=0; k<4; ++k){
                for(int l=1; l<8; ++l){
                    if(card[i][j-1] + 1 == card[k][l]){
                        swap(card[i][j], card[k][l]);
                        ret = min(ret, solve(card) + 1);
                        swap(card[i][j], card[k][l]);
                    }
                }
            }
        }
    }

    return memo[card] = ret;
}

int main()
{
    for(int i=0; i<4; ++i){
        for(int j=0; j<7; ++j){
            goal[i][j] = 11 + i*10 + j;
        }
    }

    int d;
    cin >> d;

    while(--d >= 0){
        vector<vector<int> > card(4, vector<int>(8));
        for(int i=0; i<4; ++i){
            for(int j=1; j<8; ++j){
                cin >> card[i][j];
                if(card[i][j] % 10 == 1)
                    card[i][j] = 0;
            }
        }
        for(int i=0; i<4; ++i)
            card[i][0] = 11 + 10 * i;

        memo.clear();
        int ret = solve(card);
        if(ret == INF)
            cout << -1 << endl;
        else
            cout << ret << endl;
    }

    return 0;
}

Measured memory_bytes: 16000
#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[i];
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int Alice=0,Bob=0;
  for(int i=0;i<N;i++){
    if(i%2==0)Alice+=a[i];
    else Bob+=a[i];
  }
  cout<<Alice-Bob<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int p[1<<15];
void dfs(int d,int j,int s){
  if(d==4){p[s]++;return;}
  for(int i=j;i*i+s<=(1<<15);i++){
    dfs(d+1,i,s+i*i);
  }
}

int main(){
  int n;
  dfs(0,0,0);
  while(cin>>n&&n)cout<<p[n]<<endl;
  return 0;
}

Measured memory_bytes: 1288
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int n;
    R(n);
    set<string>AA;
    REP(i,n){
        string s;
        R(s);
        AA.insert(s);
    }
    W(SZ(AA));
    return 0;
}


Measured memory_bytes: 19312
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

/*
0のアスキー　"48"
*/

//マクロ
#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--)
#define ALL(x) x.begin(),x.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))


int main(){
    ll D,T,S;
    cin >> D >> T >> S;

    double d = ceil(D / (double)S);

    //cout << d << endl;

    if(d <= T)
        cout << "Yes" << endl;
    else
        cout << "No" <<endl;

    return 0;
}





    


Measured memory_bytes: 3616
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

long long calc(long long x,long long y,long long int& count){

	int tmp_count = 0,tmp;

	while(y != 0){
		tmp = y;
		y = x%y;
		x = tmp;
		tmp_count++;
	}

	count = tmp_count;
	return x;
}

int main(){

	long long a,b,count,number;

	while(true){
		scanf("%lld %lld",&a,&b);
		if(a == 0 && b == 0)break;

		if(a > b){
			number = calc(a,b,count);
		}else{
			number = calc(b,a,count);
		}

		printf("%lld %lld\n",number,count);

	}

    return 0;
}

Measured memory_bytes: 2564
dp = []
mod = 10 ** 9 + 7

def check(pre_3, pre_2, pre_1, now_num):
    if pre_2 == 0 and pre_1 == 2 and now_num == 1:
        return 1
    if pre_2 == 2 and pre_1 == 0 and now_num == 1:
        return 1
    if pre_2 == 0 and pre_1 == 1 and now_num == 2:
        return 1
    if pre_3 == 0 and pre_2 == 2 and now_num == 1:
        return 1
    if pre_3 == 0 and pre_1 == 2 and now_num == 1:
        return 1
    return 0

def print_ans(num):
    global dp, mod
    count = 0
    for pre_3 in range(4):
        for pre_2 in range(4):
            for pre_1 in range(4):
                count += dp[num][pre_3][pre_2][pre_1]
    print(count % mod)

# 0:'A', 1:'C', 2:'G', 3:'T'
def start_process(num):
    global dp, mod
    dp = [[[[0, 0, 0, 0] for k in range(4)] for j in range(4)] for i in range(num + 1)]
    dp[0][3][3][3] = 1
    for char_num in range(num):
        for pre_3 in range(4):
            for pre_2 in range(4):
                for pre_1 in range(4):
                    for now_num in range(4):
                        if check(pre_3, pre_2, pre_1, now_num):
                            continue
                        dp[char_num + 1][pre_2][pre_1][now_num] += dp[char_num][pre_3][pre_2][pre_1]
                        dp[char_num + 1][pre_2][pre_1][now_num] %= mod
    print_ans(num)

def main():
    num = int(input())
    start_process(num)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
import java.io.*;
import java.util.*;
/*

BubbleSort(A)
1 for i = 0 to A.length-1
2     for j = A.length-1 downto i+1
3         if A[j] < A[j-1]
4             swap A[j] and A[j-1]

入力例 1
5
5 3 2 4 1


*/

public class Main{ 

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		BubbleSort sort = new BubbleSort(scan.nextInt());
		sort.loadSequence(scan);
		scan.close();
		sort.sort();
		System.out.println(sort);
		System.out.println(sort.swapTimes);
	}

}
class BubbleSort extends Sorting{
	public BubbleSort(int n){
		super(n);
	}
	@Override
	public void sort(){
		for(int i=0; i<seq.length-1;i++)
			for(int j=seq.length-1; i<j ;j--)
				if(seq[j]<seq[j-1])
					swap(j,j-1);
	}	
}
abstract class Sorting{
	int swapTimes;
	int[] seq;
	public Sorting(int n){
		swapTimes=0;
		seq = new int[n];
	}
	public void loadSequence(Scanner scan){
		for(int i=0; i<seq.length; i++)
			seq[i] = scan.nextInt();
	}
	@Override
	public String toString(){
		String tmp = "";
		for(int i=0; i<seq.length; i++)
			tmp = tmp + " " + seq[i];
		return tmp.trim();
	}
	void swap(int i, int j){
		swapTimes++;
		int tmp = seq[i];
		seq[i] = seq[j];
		seq[j] = tmp;
	}
	abstract public void sort();
}

Measured memory_bytes: 18340
#include<stdio.h>
#include<stdlib.h>
#define df 0
#define MOD 1000000007
int d_count=10000;

typedef long int li;
li inv(li a);
li waru(li a,li b);
li kake(li a,li b);

int main(){
  int a[100000];
  int num[100000];
  int n,k,i,j;
  scanf("%d%d",&n,&k);
  i=1;
  while(1){
    a[i]=n/i;
    if(a[i]<i){
      j=i-1; 
      break;
    }
    if(a[i]==i){
      num[i]=1;
      j=i-1;i++;
      break;
    }
    num[i]=1;
    i++;
  }

  while(j>0){
    a[i]=j;
    num[i]=a[j]-a[j+1];
    i++;j--;
  }
  int len=i;

  if(df){
    printf("  n:");
    for(i=1;i<len;i++)
      printf(" %2d",i);
    printf("\n  a:");
    for(i=1;i<len;i++)
      printf(" %2d",a[i]);
    printf("\nnum:");
    for(i=1;i<len;i++)
      printf(" %2d",num[i]);
    printf("\n");
  }

  li ans[len],prev[len];
  for(i=1;i<len;i++){
    ans[i]=kake(a[i],num[i]);
  }
  if(df){
    printf("ans[%d]:\n   ",j);
    for(i=1;i<len;i++){
      printf(" %2d",ans[i]);
    }
    printf("\n");
  }
  for(j=2;j<=k;j++){
    for(i=1;i<len;i++)
      prev[i]=ans[i];
    li sum=0;
    for(i=1;i<len;i++){
      sum=(sum+prev[i])%MOD;
      ans[len-i]=sum*num[len-i]%MOD;
    }
    if(df){
      printf("ans[%d]:\n   ",j);
      for(i=1;i<len;i++){
	printf(" %2d",ans[i]);
      }
      printf("\n");
    }
  }
  printf("%d",ans[1]);
  
  return 0;
}

li inv(li a){
  li x0,y0,x1,y1,z0,z1,q,x2,y2,z2;
  x0=0;y0=1;z0=MOD;
  x1=1;y1=0;z1=a;
  if(df)printf("\n");
  if(df)printf("%10ld %10ld %10ld\n",x0,y0,z0);
  if(df)printf("%10ld %10ld %10ld\n",x1,y1,z1);
  while(z1!=1){
    d_count-=df; if(d_count<0){printf("err:inv\n");break;}
    q=z0/z1;
    x2=x0-x1*q;
    y2=y0-y1*q;
    z2=z0-z1*q;
    x0=x1;y0=y1;z0=z1;
    x1=x2;y1=y2;z1=z2;
  if(df)printf("%10ld %10ld %10ld\n",x1,y1,z1);
  }
  return (MOD+x1)%MOD;
}
li waru(li a,li b){
  if(df)printf("calc:%ld/%ld",a,b);
  if(a%b==0){
    if(df) printf("->%ld\n",a/b);
    return a/b;
  }
  else{
    li c=inv(b);
    c=kake(a,c);
    if(df) printf("->%ld\n",c);
    return(c);
  }
}

li kake(li a,li b){
  //  if(df)printf("%ld*%ld\n",a%MOD,b%MOD);
  a%=MOD;
  b%=MOD;
  return(a*b%MOD);
}

/// confirm df==0 ///


Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve(){
	int n,k;
	cin>>n>>k;
	int res = 0;
	while(n){
		res++;
		n = n/k;
	}
	cout<<res<<endl;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256