akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.StringTokenizer;

public class Main {
  private static PrintWriter out;

  public static void main(String[] args) {
    Main main = new Main();
    Runtime.getRuntime().addShutdownHook(new Thread(() -> out.close()));
    try {
      main.run(args);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void run(String[] arguments) throws Exception {
    MyScanner sc = new MyScanner();
    out = new PrintWriter(new BufferedOutputStream(System.out));

    int N = sc.nextInt();
    long total = 0;
    for (int i = 1; i <= N; i++) {
      if (i%3!=0 && i%5!=0){
        total+=i;
      }
    }
    out.println(total);
    out.close();
  }

  /*          
   * Form: http://codeforces.com/blog/entry/7018
   */
  private class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    MyScanner() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

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

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

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

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


Measured memory_bytes: 33964
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

//Union-Find tree
struct UnionFind
{
	vector<int> par;
	vector<int> rank;

	UnionFind(int n) : par(n),rank(n)
	{
		for (int i = 0; i < n; i++)
		{
			par[i] = i;
			rank[i] = 0;
		}
	}
	int root(int x)
	{
		if (par[x] == x)
		{
			return x;
		}
		else
		{
			return par[x] = root(par[x]);
		}
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if (rx == ry)return;
		if (rank[rx] < rank[ry])
		{
			par[rx] = ry;
		}
		else
		{
			par[ry] = rx;
			if (rank[rx] == rank[ry])rank[rx]++;
		}
	}
	bool same(int x, int y)
	{
		return root(x) == root(y);
	}
};

void solve()
{
	int n, m; cin >> n >> m;
	vector<int> a(m), b(m);
	rep(i, m) cin >> a[i] >> b[i];
	int ans = 0;
	rep(i ,m)
	{
		UnionFind uf(n);
		rep(j, m)if(i != j)
		{
			uf.unite(a[j]-1,b[j]-1);
		}
		rep(j ,n)
		{
			bool ok = true;
			rep(k, n)if(!uf.same(0, k)) ok = false;
			if(!ok)
			{
				ans++;
				break;
			}
		}
	}	
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

using pos_t = std::pair<int, int>;

constexpr int N { 8 };

std::vector<std::string> solve(int k, const std::vector<pos_t> & p) {
    std::vector<std::string> board(N, "........");

    std::vector<int> perm(N);
    for (int i = 0; i < N; ++i) {
        perm[i] = i;
    }

    do {
        const bool ok = [&] {
            for (int i = 0; i < k; ++i) {
                const auto x { p[i].first };
                const auto y { p[i].second };
                if (perm[y] != x) {
                    return false;
                }
            }
            return true;
        }();
        if (ok) {
            bool can_put { true };
            for (int i = 0; i < N - 1; ++i) {
                for (int j = 1; i + j < N; ++j) {
                    if (perm[i] + j == perm[i + j]) {
                        can_put = false;
                    }
                    if (perm[i] - j == perm[i + j]) {
                        can_put = false;
                    }
                }
            }
            if (can_put) {
                for (int i = 0; i < N; ++i) {
                    board[perm[i]][i] = 'Q';
                }
                return board;
            }
        }
    } while(std::next_permutation(perm.begin(),perm.end()));

    // ここに到達することはないが、警告が出るためからの vector を返す
    return std::vector<std::string>{};
}

int main() {
    int k;
    std::cin >> k;

    std::vector<pos_t> p;
    for (int i = 0; i < k; ++i) {
        int x, y;
        std::cin >> x >> y;
        p.push_back(std::make_pair(x, y));
    }
    
    const auto board = solve(k, p);
    
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            std::cout << board[i][j];
        }
        std::cout << std::endl;
    }

    return 0;
}




Measured memory_bytes: 3220
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
int main(){
  int x,n; cin>>x>>n;
  vector<int>q(102); //0で初期化される
  rep(i,n){
    int p; cin>>p;
    q[p] = 1;
  }
  int mini = 100000;
  int ans = 0;
  for (int i=0; i<102; i++){
    if (q[i]==1) continue;
    else{
      if (abs(x-i)<mini){
        mini = min(abs(x-i), mini);
        ans = i;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
int main(void)
{
  int c[30]={0};
  char x[200]={0};
  int count=0;
  scanf("%d %d %d", c+0,c+1,c+2);
  for(int *color=c; *color!=0; ++color){
    if(x[*color]++==0){
      ++count;
    }
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const int length_of_string = 1005;

char* reverse(char *rev_str, int start, int end){
    char *rev_str_copied;
    rev_str_copied = (char*)malloc(length_of_string * sizeof(char));
    memset(rev_str_copied, '\0', length_of_string);
    
    /*step 1: copy string of lenght of statr to rev_str_copied*/
    strncpy(rev_str_copied, rev_str, start); 
    
    /*step 2: reverse the string form start to end*/
    int i,j;
    for(i=end,j=start; i>=start,j<=end; i--,j++){
        *(rev_str_copied+j) = *(rev_str+i);
    }

    /*step 3: copy the other character to rev_str_copied*/
    rev_str += (end + 1);/*go to index end+1*/
    strcat(rev_str_copied, rev_str);
   
    /*step 4: copy rev_str_copied to rev_str*/
    rev_str -= (end+1);//important!! can't delete
    strcpy(rev_str, rev_str_copied);
    
    free(rev_str_copied);
    return rev_str;
}

void print(char* str, int start, int end){
    int i;
    for(i=start; i<=end; i++){
        printf("%c", *(str+i));
    }
    printf("\n");
}

char *replace_string(char *str, int start, int end, char *replace_str){
    int i;
    for(i=start; i<= end; i++){
        *(str+i) = *replace_str;
        replace_str++;
    }
    return str;
}

int main(){
    char *str;
    str = (char*)malloc(length_of_string * sizeof(char));
   
    fgets(str, length_of_string*sizeof(char), stdin);
    *(str+strlen(str)-1) = '\0';
    int instr_num;
    scanf("%d", &instr_num);
    getchar();//important!!
    int i;
    for(i=0; i<instr_num; i++){
        char instr[2000];
        fgets(instr, sizeof(instr), stdin);
        instr[strlen(instr)-1] = '\0';
        if(instr[2] == 'p'){
            char in_replace_string[length_of_string];
            int start_index, end_index;
            sscanf(instr, "replace %d %d %s", &start_index, &end_index, in_replace_string);
            replace_string(str, start_index, end_index, in_replace_string);        
        }
        else if(instr[2] == 'v'){
            int start_index, end_index;
            sscanf(instr, "reverse %d %d", &start_index, &end_index);
            reverse(str, start_index, end_index);
        }
        else if(instr[2] == 'i'){
            int start_index, end_index;
            sscanf(instr, "print %d %d", &start_index, &end_index);
            print(str, start_index, end_index);
        }
    }
    free(str);
}



Measured memory_bytes: 2112
import java.util.*

fun main(args: Array<String>) {

    val sc = Scanner(System.`in`)
    val N = sc.nextInt()

    var set = mutableSetOf<Long>()
    for (n in 0 until N) {
        val A = sc.nextLong()
        set.add(A)
    }
    var premin = set.min()!!
    while (true) {
        val newset = mutableSetOf<Long>()
        for (s in set) newset.add(s%premin)
        set = newset
        set.remove(0L)
        set.add(premin)
        if (set.size == 0) break
        val min = set.min()!!
        if (min == premin) break
        premin = min
    }

    println(premin)
}


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

int main(){
  int n;
  cin>>n;
  int ans=0;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    while(x%2==0){
      x/=2;
      ans++;
    }
  }
  cout<<ans<<endl;
}


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

int crescente(const void *a, const void *b){
    if (*(int*)a == *(int*)b)
        return 0;
    else
        if (*(int*)a > *(int*)b)
            return 1;
        else
            return -1;
}

int main(){
    int qtdNUM, diferenca = 0;
    scanf("%d", &qtdNUM);
    int vetNUM[qtdNUM];
    for (int i = 0; i < qtdNUM; i++){
        scanf("%d", &vetNUM[i]);
    }
    qsort(vetNUM, qtdNUM, sizeof(int), crescente);
    diferenca = vetNUM[qtdNUM - 1] - vetNUM[0];
    printf("%d\n", diferenca);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt(), m = sc.nextInt(), x = sc.nextInt(), y = sc.nextInt();
		int max = x, min = y;
		for (int i = 0; i < n; i++) {
			max = Math.max(max, sc.nextInt());
		}
		for (int i = 0; i < m; i++) {
			min = Math.min(min, sc.nextInt());
		}
		System.out.println(max >= min ? "War" : "No War");
	}
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=200005,K=1000000007;
const LL INF=0x7FFFFFFFFFFFFFFF;
map <LL,int> M;
vector <LL> V[maxn];
int n,m,p,zeros,frees,ans,fra[maxn];
LL a[maxn],b[maxn],ori[maxn];
int sgn(LL A) { return A>0?1:-1; }
LL gcd(LL A,LL B) { return B?gcd(B,A%B):A; }
int Pow(int A,int B)
{
	int res=1;
	while (B)
	{
		if (B&1) res=(LL)res*A%K;
		A=(LL)A*A%K;
		B>>=1;
	}
	return res;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i],&b[i]);
		if (!a[i] && !b[i]) { zeros++; continue; }
		if (!a[i]) b[i]=1; else
		if (!b[i]) a[i]=1; else
		{
			int sign=sgn(a[i])*sgn(b[i]);
			LL g=gcd(abs(a[i]),abs(b[i]));
			a[i]=abs(a[i])/g;
			b[i]=abs(b[i])/g;
			a[i]*=sign;
		}
		if (!M[a[i]]) M[a[i]]=++m,ori[m]=a[i];
		V[M[a[i]]].push_back(b[i]);
		//printf("%lld %lld\n",a[i],b[i]);
	}
	for (int i=1;i<=m;i++)
	{
		sort(V[i].begin(),V[i].end());
		V[i].push_back(INF);
	}
	/*
	for (int i=1;i<=m;i++)
	{
		printf(">>>>>%d : ",ori[i]);
		for (int j=0,J=V[i].size()-2;j<=J;j++) printf("%d ",V[i][j]);
		puts("");
	}
	*/
	for (int i=1;i<=m;i++)
		for (int j=0,J=V[i].size()-2;j<=J;j++)
		{
			int cnt=1;
			while (V[i][j]==V[i][j+1]) j++,cnt++;
			LL need=-sgn(ori[i])*V[i][j];
			if (!M[need])
			{
				frees+=cnt;
				continue;
			}
			int u=M[need],
				L=lower_bound(V[u].begin(),V[u].end(),abs(ori[i]))-V[u].begin(),
				R=upper_bound(V[u].begin(),V[u].end(),abs(ori[i]))-V[u].begin()-1,
				sum=R-L+1;
			if (!sum) frees+=cnt; else
			if (u<i)
			{
				fra[++p]=(Pow(2,cnt)+Pow(2,sum)-1)%K;
				if (fra[p]<0) fra[p]+=K;
			}
		}
	ans=Pow(2,frees);
	for (int i=1;i<=p;i++) ans=(LL)ans*fra[i]%K;
	ans=((ans+zeros-1)%K+K)%K;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 44288
#!/usr/bin/env python3

# 125 => 125, 1+25, 12+5, 1+2+5
# i文字目までの数字を使った時の和が sum_v

ans = 0

def dfs(S, i, cur, sum_v):
    global ans
    # print(cur,)
    if i == len(S)-1:
        ans += sum_v
        return 
    dfs(S, i+1, int(S[i+1]), sum_v+int(S[i+1]),)
    dfs(S, i+1, cur*10+int(S[i+1]), sum_v+cur*9+int(S[i+1]))

S = input()
dfs(S, -1, 0, 0)
print(ans//2)


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

#define for0(i, n) for (ll i = 0; i < (ll)(n); ++i) // 0 based indexing
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (ll i = (ll)(l); i <= (ll)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (ll i = (ll)(n); i >= 1; --i) // reverse 1 based

#define ff first
#define ss second
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,k,x,y;
	cin >> n >> k;
	vector <ll> v(n,0);
	for0(i,k){
		cin >> x;
		for0(j,x){
			cin >> y;
			v[y-1]++;
		}
	}
	ll ct= 0;
	for0(i,n){
		if(v[i] == 0){
			ct++;
		}
	}
	cout << ct << endl;
	return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>

int main()
{
    int K, X, i;
    scanf("%d %d", &K, &X);
    for (i = -K + 1; i <= K - 1; i++)
    {
        if (X + i < -1000000 || X + i > 1000000)
        {
            continue;
        }
        printf("%d", X + i);
        if (i != K - 1)
        {
            printf(" ");
        }
    }
    return 0;
}

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

int cal_sum_digits(int n){
  int sum = 0;
  while(n > 0){
    sum += ( n % 10);
    n /= 10;
  }
  return sum;
}

int main(){
  int N,ans = INT_MAX;
  cin >> N;
  for(int i = 1; i < N;i++){
    int a = i,b= N - i;
    ans = min(ans,cal_sum_digits(a) + cal_sum_digits(b));
  }
  cout << ans << endl;
}
    
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  int a[m];
  rep(i, m) cin >> a[i];
  sort(a, a + m);
  vector<int> b;
  if (n >= m) {
    cout << 0 << endl;
  } else {
    rep(i, m - 1) b.push_back(a[i + 1] - a[i]);
    sort(b.rbegin(), b.rend());
    int l = a[m - 1] - a[0];
    rep(i, n - 1) l -= b[i];
    cout << l << endl;
  }
  return 0;
}

Measured memory_bytes: 1276
from heapq import heappop,heappush
from collections import defaultdict
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab_sort = sorted(ab,key=lambda x:x[0])
h_queue = []
j = 0
ans = 0
for i in range(1,m+1):
    while (j < n) and (ab_sort[j][0] <= i):
        heappush(h_queue,-ab_sort[j][1])
        j += 1
    if len(h_queue) :
        ans -= heappop(h_queue)
print(ans)


Measured memory_bytes: 33596
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

/*

ナップサック問題

xs[i][w]: i個目より前までで、重さw以下とした場合の価値の最大値

xs[0][w] = 0
xs[i][w] = (w - ws[i] >= 0)?
		xs[i - 1][w - ws[i]] + vs[i] : xs[i - 1][w]

*/

void main(){
	long n = read.to!long;
	long npw = read.to!long;
	
	long[] ws, vs;
	foreach(i; 0 .. n){
		ws ~= read.to!long;
		vs ~= read.to!long;
	}
	
	long[][] xs = [[]];
	foreach(w; 0 .. npw + 1) xs[0] ~= 0;
	
	foreach(i; 0 .. n){
		long[] q = [];
		foreach(w; 0 .. npw + 1){
			q ~= max(
					((w - ws[i] >= 0) ? xs[$ - 1][w - ws[i]] + vs[i] : 0),
					xs[$ - 1][w]
				);
			debug writeln("q:", q, " w:", w, " i:", i);
		}
		xs ~= q;
	}
	
	xs[n][npw].writeln;
}


Measured memory_bytes: 113404
s = input()
n = len(s)
ans = [0] * n

cnt = 0
for i in range(n):
    if s[i] == "R": cnt += 1
    else:
        ans[i] += cnt//2
        ans[i-1] += (cnt+1)//2
        cnt = 0

s = s[::-1]
ans.reverse()

for i in range(n):
    if s[i] == "L": cnt += 1
    else:
        ans[i] += cnt//2
        ans[i-1] += (cnt+1)//2
        cnt = 0

ans.reverse()
for i in range(n):
    print(ans[i])

Measured memory_bytes: 49496
import java.util.Scanner;

class Main {

    public static void main(String[] args){
	Scanner stdin = new Scanner(System.in);
	int[] nums = new int[6];
	final int a = 0;
	final int b = 1;
	final int c = 2;
	final int d = 3;
	final int e = 4;
	final int f = 5;
	
	
	while(stdin.hasNextInt()){
	    for(int i = 0; i < 6; i++){
		nums[i] = stdin.nextInt();
	    }

	    double y = (double)(nums[d] * nums[c] - nums[a] * nums[f]) /
		(nums[d] * nums[b] - nums[a] * nums[e]);
	    double x = (nums[c] - nums[b] * y) / nums[a];
	    System.out.printf("%.3f %.3f\n", x, y);
	}
    }
}

Measured memory_bytes: 12000
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>

using namespace std;
typedef long long int ll;

int n,h,w,a[1010],b[1010],r=0;

int main(){
    scanf("%d %d %d",&n,&h,&w);
    for(int i=0;i<n;i++){
        scanf("%d %d",&a[i],&b[i]);
        r+=(a[i]>=h and b[i]>=w);
    }
    printf("%d\n",r);
}

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

double mDistance(double xyDif[], int n, int p)
{
    double ans = 0;
    for (int i = 0; i < n; i++)
        ans += pow(xyDif[i], p);
    if (p == 2)
        ans = sqrt(ans);
    else if (p == 3)
        ans = cbrt(ans);
    return ans;
}

int main()
{
    int n, i;
    scanf("%d", &n);
    int x[n], y[n];
    double xyDif[n], ans[4] = {};
    for (i = 0; i < n; i++)
        scanf("%d", &x[i]);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &y[i]);
        xyDif[i] = fabs(x[i] - y[i]);
    }

    for (i = 0; i < 3; i++)
        ans[i] = mDistance(xyDif, n, i + 1);
    for (i = 0; i < n; i++)
        ans[3] = max(ans[3], xyDif[i]);

    for (i = 0; i < 4; i++)
        printf("%lf\n", ans[i]);
}



Measured memory_bytes: 3452
import sys
readline = sys.stdin.readline

N = int(readline())

fact = [True] * 55556
fact[0] = False
fact[1] = False
ans = []
for i in range(len(fact)):
  if fact[i]:
    for j in range(i * 2, len(fact), i):
      fact[j] = False
    if i % 5 == 1:
      ans.append(i)
      if len(ans) == N:
        break
      
print(*ans)
      


Measured memory_bytes: 9048
#include <iostream>
#include <string>
#include <list>
#include <cstring>

int main(void) {
  int K;

  std::string str;

  std::string s_;
  std::cin >> s_;
  const char* s = s_.c_str();

  std::cin >> str;
  K = std::stoi(str);

  size_t lsize = 0;
  size_t len = s_.length();

  typedef struct s_set {
    int pos;
    int len;

    s_set(int i, int j) : pos(i), len(j) {
    }
  } set;

  std::list<std::string> wlist;
  //std::list<set> wlist;

  wlist.push_back(s_.substr(0, 1));
  //wlist.push_back(set(0, 1));
  for (int a = 'a'; a <= 'z' && lsize < K; ++a) {        /* a to z   */
    for (int b = 'a'; b <= 'z' && lsize < K; ++b) {      /* a to z   */
      for (int i = 0; i < len; ++i) {                    /* 0 to len */
        if (s[i] == a && (i+1 >= len || s[i+1] == b)) {
          for (int j = 1; j <= len - i && j <= K; ++j) {           /* length 1 to len - i */
            for (auto itr = wlist.begin(); itr != wlist.end(); ++itr) {
              int cmp = s_.compare(i, j, *itr);
              //int cmp = s_.compare(i, j, s_, itr->pos, itr->len);
              if (cmp == 0) {
                break;
              }
              if (cmp < 0) {
                wlist.insert(itr, s_.substr(i, j));
                //wlist.insert(itr, set(i, j));
                lsize++;
                break;
              }
              if (cmp > 0 && itr->c_str() == wlist.rbegin()->c_str()) {
              //if (cmp > 0 && (itr->pos == wlist.rbegin()->pos && itr->len == wlist.rbegin()->len)) {
                wlist.push_back(s_.substr(i, j));
                //wlist.push_back(set(i, j));
                lsize++;
                break;
              }
            }
          }
        }
      }
    }
  }

  size_t idx = 0;
  for (auto &str : wlist) {
    idx++;
    if (idx == K) {
      std::cout << str << std::endl;
      //std::cout << str.pos << "," << str.len << std::endl;
      //std::cout << s_.substr(str.pos, str.len) << std::endl;
    }
  }

  return 0;
}

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

using ld = long double;
using ll = int64_t;
using Str = std::string;
template <class T> using Vec = std::vector<T>;
template <class K, class V> using UM = std::unordered_map<K, V>;

namespace io {

    template <class ...As> auto &read(As &...as)
    { return (std::cin >> ... >> as); }

} // namespace io

#define PB push_back

#define A(xs) xs.begin(), xs.end()
#define R(...) __VA_ARGS__; io::read(__VA_ARGS__)
#define FOR(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int main() {
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    Str R(s);
    cout << s.substr(0, 3);
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
	int n, m, ans = 0;
	cin >> n >> m;

	int coin[m], dp[n + 1];
	memset(dp, 1000000, sizeof(dp));
	for (int i = 0; i < m; i++) {
		cin >> coin[i];
		dp[coin[i]] = 1;
	}
	sort(coin, coin + m);
	for (int i = 1; i < n; i++)
		for (int j = 0; j < m; j++)
			if (i + coin[j] <= n) dp[i + coin[j]] = min(dp[i + coin[j]],dp[i] + 1);

	cout << dp[n] << endl;

	return 0;
}

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  char turn = 'a';
  int ai=0,bi=0,ci=0;
  
  while(1){
    
    if(ai>=A.size() && turn=='a'){
      cout << "A" << endl;
      return 0;
    }
    if(bi>=B.size() && turn=='b'){
      cout << "B" << endl;
      return 0;
    }
    if(ci>=C.size() && turn=='c'){
      cout << "C" << endl;
      return 0;
    }
      
    if(turn == 'a'){
      turn = A[ai];
      ai++;
    }
    else if(turn == 'b'){
      turn = B[bi];
      bi++;
    }
    else if(turn == 'c'){
      turn = C[ci];
      ci++;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define _USE_MATH_DEFINES
#include<math.h>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<map>
#include<unordered_map>
#include<set>
#include <algorithm>
#include <utility>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

typedef unsigned long long ull;
typedef long long ll;

#define Prime1 1000000007
#define Prime2 9999973

int i, j, k, l, m, n;
int H, W, N, M, Q;
int a, b, c, d;

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

	if (a > c)
	{
		std::swap(a, c);
		std::swap(b, d);
	}
	if (b < c)
	{
		cout << "0\n";
	}
	else
	{
		cout << std::min(b,d) - c << '\n';
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
int main(){
	int n;
	cin>>n;
	char c;
	scanf("%c",&c);
	lp(i,n){
		int count=1,memo1=0;
		lp(i,2){
			while(1){
				scanf("%c",&c);
				if('2'<=c &&c<='9'){
					count=c-'0';
				}
				else if('a'<=c&&c<='z'){
					if(c=='m') memo1+=count*1000;
					if(c=='c') memo1+=count*100;
					if(c=='x') memo1+=count*10;
					if(c=='i') memo1+=count*1;
					count=1;
				}
				else break;
			}
		}
		if(memo1>=1000){
			if(memo1<2000) cout<<"m";
			else cout<<memo1/1000<<"m";
		}
		memo1%=1000;
		if(memo1>=100){
			if(memo1<200) cout<<"c";
			else cout<<memo1/100<<"c";
		}
		memo1%=100;
		if(memo1>=10){
			if(memo1<20) cout<<"x";
			else cout<<memo1/10<<"x";
		}
		memo1%=10;
		if(memo1>=1){
			if(memo1<2) cout<<"i";
			else cout<<memo1/1<<"i";
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) b.rbegin(),v.rend()
typedef long long ll;
//isPrime
//modpow modinv
int main() {
  int n;
  cin >> n;
  map<int,int> mp;

  rep(i,n){
    int key;
    cin >> key;
    if(mp.count(key)){
      cout << "NO" << endl;
      return 0;
    }else{
      mp[key]=1;
    }
  }
  cout << "YES" << endl;

}




Measured memory_bytes: 9600
const main = (txt: any): void => {
  const input = txt.split('\n')
  let [W, H, N] = input[0].split(' ').map((i: string) => { return Number(i) })
  let Ma1 = 0
  let Ma2 = W
  let Ma3 = 0
  let Ma4 = H
  for (let i = 1; i <= N; i++) {
    let x: number
    let y: number
    let a: number
    [x, y, a] = input[i].split(' ').map((i: string) => { return Number(i) })
    if (a === 1 && x > Ma1) {
      Ma1 = x
    }
    if (a === 2 && x < Ma2) {
      Ma2 = x
    }
    if (a === 3 && y > Ma3) {
      Ma3 = y
    }
    if (a === 4 && y < Ma4) {
      Ma4 = y
    }
  }
  const Wn = Ma2 - Ma1
  const Hn = Ma4 - Ma3
  const sum = (Ma2 - Ma1) * (Ma4 - Ma3)
  if (sum >= 0 && Wn > 0 && Hn > 0) {
    console.log(sum)
  }
  else {
    console.log('0')
  }
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include<iostream>
using namespace std;
int max(long long int *p,int N){
  int top=1;
  for(int i=2;i<=N;i++){
    if(p[top]<p[i]) top = i;
  }
  return top;
}
int main(){
  int N,R,L,d,t,x,old=1,oldt=0;
  cin >> N >> R >> L;
  long long int pt[N+1],ptime[N+1];
  for(int i=0;i<=N;i++) pt[i]=ptime[i]=0;
  for(int i=0;i<R;i++){
    cin >> d >> t >> x;
    ptime[old] += t-oldt;
    oldt = t;
    pt[d] += x;
    if(x>=0){
      if(pt[old]<pt[d]) old = d;
      if(pt[old]==pt[d]&&old>d) old = d; 
    }else{
      if(old==d) old = max(pt,N);
    }
  }
  ptime[old] += L- oldt;
  int ans=1;
  for(int i=2;i<=N;i++){
    if(ptime[ans]<ptime[i]) ans = i;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  ll a,b,k;
  cin >> a >> b >> k;
  if (k > a){
    k -= a; a = 0;
  }
  else{
    a -= k; k = 0;
  }
  if (k > b){
    k -= b; b = 0;
  }
  else{
    b -= k; k = 0;
  }
  cout << a << " " << b << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	boolean[] prime;
	int[][] map;
	int[][][] dp;
	HashMap<Integer, P> p2ind;
	int MAX = 1050, M = 1000000;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		pre();
		
		for(;;) {
			int n = sc.nextInt(), s = sc.nextInt();
			if((n|s) == 0) break;
			
			for(int[][] a: dp) for(int[] b: a) fill(b, -1);
			
			P p = p2ind.get(s);
			dp[p.y][p.x][0] = prime[s]? 0: 1; dp[p.y][p.x][1] = prime[s]? 0:s;
			
			int ansn = 0, ansp = 0;
			for(int y=1;y<MAX;y++) for(int x=1;x<MAX-1;x++) {
				if(map[y][x] > n) continue;
				for(int dx=-1;dx<=1;dx++) if(map[y-1][x+dx] <= n && dp[y-1][x+dx][0] >= 0) {
					if(!prime[map[y][x]]) {
						dp[y][x][0] = max(dp[y][x][0], dp[y-1][x+dx][0] + 1);
						dp[y][x][1] = map[y][x];
					} else {
						if(dp[y][x][0] < dp[y-1][x+dx][0]) {
							dp[y][x][0] = dp[y-1][x+dx][0];
							dp[y][x][1] = dp[y-1][x+dx][1];
						} else if(dp[y][x][0] == dp[y-1][x+dx][0] && dp[y][x][1] < dp[y-1][x+dx][1]) {
							dp[y][x][0] = dp[y-1][x+dx][0];
							dp[y][x][1] = dp[y-1][x+dx][1];
						}
					}
				}
				if(ansn < dp[y][x][0]) {
					ansn = dp[y][x][0];
					ansp = dp[y][x][1];
				} else if(ansn == dp[y][x][0]) {
					ansp = max(ansp, dp[y][x][1]);
				}
//				debug(x, y, map[y][x], dp[y][x][0], dp[y][x][1]);
			}
			
			System.out.println(ansn + " " + ansp);
		}

	}
	
	int[] dx = {1,0,-1,0}, dy = {0,-1,0,1};
	void pre() {
		p2ind = new HashMap<Integer, P>();
		map = new int[MAX][MAX]; dp = new int[MAX][MAX][2];
		for(int[] a: map) fill(a, INF);
		
		prime = new boolean[M+1];
		prime[0] = prime[1] = true;
		for(int i=2;i<=M;i++) if(!prime[i]) 
			for(int j=i*2;j<=M;j+=i) prime[j] = true;
		
		int ind = 1, len=0, x = MAX/2, y = MAX/2, d=0;
		while(true) {
			len++;
			for(int c=0;c<2;c++) {
				for(int i=0;i<len;i++) {
					map[y][x] = ind; p2ind.put(ind, new P(x, y));
					ind++; x += dx[d]; y += dy[d];
				}
				d = (d+1)&3;
			}
			if(ind > M) break;
		}
		
/*		for(int sy=MAX/2-10;sy<=MAX/2+10;sy++) for(int sx=MAX/2-10;sx<=MAX/2+10;sx++) {
			System.out.printf("%4d%s", map[sy][sx], sx==MAX/2+10? "\n": "");
		}*/
	}
	
	class P {
		int x, y;
		P(int x, int y) {
			this.x = x; this.y = y;
		}
		
		public int hashCode() {
			return x * 100000 + y;
		}
		
		public boolean compareTo(Object o) {
			if(o instanceof P) {
				P p = (P)o;
				return x == p.x && y == p.y;
			}
			return false;
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 161532
// Problem : A - Lucky 7
// Contest : AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define vb vector<bool>
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define pb push_back
#define fi first
#define se second
#define m_p make_pair
#define vpii vector<pii>
#define vs vector<string>
//Proof: 
//Complexity:
void print(vi v){
	ll n = v.size();
	for(ll i = 0;i<n;i++){
		cout<<v[i]<<" ";
	}
        cout<<endl;
}
ll power(ll a, ll b){
    ll res = 1;
    while(b!=0){
        if(b&1){
            res *= a; 
        }
        a = (a * a);
        b = (b / 2);
    }
    return res;
}
int main(){
    SPEED;
    string s;
    cin>>s;
    if(s[0]=='7' || s[1]=='7' || s[2]=='7')cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long llong;
int main(){
    int a, b;
    cin >> a >> b;

    if (a == 1){
        if (b == 2) cout << 3 << endl;
        else cout << 2 << endl;
    }

    if (a == 2){
        if (b == 1) cout << 3 << endl;
        else cout << 1 << endl;
    }

    if (a == 3){
        if (b == 1) cout << 2 << endl;
        else cout << 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n, m;
    cin >> n >> m;
    ll sum = 0;
    for(int i = 0; i < m; i ++) {
        ll a;
        cin >> a;
        sum += a;
    }
    if(sum > n) {
        cout << -1;
    } else {
        cout << n - sum << endl;
    }
    return 0;
}




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

#define pb push_back
const int maxn = 100;

int n, d, x;
vector<double> mem[maxn];

bool distance(int a, int b)
{
	double res = 0;
	for(int j = 0; j < d; j++)
	{
		res += (mem[a][j]-mem[b][j])*(mem[a][j]-mem[b][j]);
	}
	double ans = sqrt(res);
	//cout << res << endl;
	if((int)ans != ans) return false;
	else return true;
}

int solve()
{
	int cnt = 0; 
	for(int i = 0; i < n; i++)
		for(int j = i+1; j < n; j++)
		{
			if(distance(i, j)) cnt++;
		}
	return cnt;
}

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

	for(int i = 0; i < n; i++)
		for(int j = 0; j < d; j++)
		{
			cin >> x;
			mem[i].pb(x);
		}

	printf("%d\n", solve());
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        int K = s.nextInt();
        int Q = s.nextInt();

        int points[] = new int[N];
        for (int i = 0; i < N; i++) {
            points[i] = 0;
        }

        for (int i = 0; i < Q; i++) {
            int w = s.nextInt();
            points[w-1]++;
        }

        for (int i = 0; i < N; i++) {
            if (K - (Q - points[i]) > 0) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }

}


Measured memory_bytes: 61060
fun main(args: Array<String>) {
    abc154a()
}

fun abc154a() {
    val (s, t) = readLine()!!.split(' ')
    var (a, b) = readLine()!!.split(' ').map { it.toInt() }
    val u = readLine()!!

    if (u == s) a-- else b--

    val answer = "$a $b"

    return println(answer)
}


Measured memory_bytes: 38308
from fractions import gcd
a, b, c, d = map(int, input().split())

def lcm(x, y):
    return x*y//gcd(x,y)

def notDiv(a, c, d):
    return a - a//c - a//d + a//lcm(c, d)

print( notDiv(b, c, d)-notDiv(a-1, c, d) )


Measured memory_bytes: 64364
n, m, x = gets.split.map(&:to_i)
arr = []
n.times do
  arr << gets.split.map(&:to_i)
end

max = 10 ** 9
min_cost = max
(2 ** n).times do |i|
  s = ("0" * n + i.to_s(2))[(-n)..-1]
  cost = 0
  skill = Array.new(m, 0)
  s.each_char.with_index do |c, j|
    next if c == "0"
    
    c, *sk_arr = arr[j]
    cost += c
    sk_arr.each_with_index {|sk, k| skill[k] += sk}
  end
  
  next if !skill.find {|sk| sk < x}.nil?
  
  min_cost = cost if min_cost > cost
end
puts min_cost == max ? -1 : min_cost

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

int main() {
    string s;
    cin >> s;
    int n = s.length();
    int a=0, b=0;
    for(int i=0; i<n; i++){
        if(s[i]=='1'){
            a++;
        }else{
            b++;
        }
    }
    if(a==0 || b==0){
        cout << 0 << endl;
        return 0;
    }else{
        cout << 2 * min(a, b) << endl;
        return 0;
    }
}

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

int main(){
    int N;
    string a;
    vector<string> s;
    
    cin >> N;

    for(int i = 0; i < N; i++){
        cin >> a;
        s.push_back(a);
    } 

    sort(s.begin(), s.end() );
    s.erase(unique(s.begin(), s.end()), s.end());

    
    cout << s.size() << endl;
    return 0;
}

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

const int N = 1e5 + 5;
int sex[N];

int query(int m){
    cout << m << endl;
    string s;
    cin >> s;
    if(s[0] == 'M') return 1;
    if(s[0] == 'F') return 2;
    return 0;
}

int main(){
    fcin;

    int n;
    cin >> n;

    int q = query(0);
    if(!q) return 0;

    sex[0] = sex[n] = q;

    auto odd = [&](int l, int r){
        return (r - l + 1) & 1;
    };

    int l = 0, r = n;
    while(l <= r){
        int mid = (l + r)/2;
        int q = query(mid);

        if(!q) return 0;

        sex[mid] = q;

        if(odd(l, mid) and sex[l] != sex[mid]){
            r = mid;
        } else if(!odd(l, mid) and sex[l] == sex[mid]){
            r = mid;
        } else if(!odd(mid, r) and sex[r] == sex[mid]){
            l = mid;
        } else if(odd(mid, r) and sex[r] != sex[mid]){
            l = mid;
        }
    }
    return 0;
}



Measured memory_bytes: 980
#include <stdio.h>

int MOD = 1000000007;
long long fact[1000005], finv[1000005], inv[1000005];

void f1(void) {
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 1000005; i++){
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long f2(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fact[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void) {
    f1();
    int X, Y, N;
    scanf("%d%d", &X, &Y);
    if ((X+Y)%3!=0 || X>2*Y || Y>2*X) {
        printf("%d", 0);
        return 0;
    }
    else N=(X+Y)/3;
    X=X-N; Y=Y-N;
    printf("%lld", f2(X+Y, X));
    return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

int main(){
  ll x,y;
  cin >> x >>y;
  for(int i=0; i<=x; i++){
    ll ans=i*2+(x-i)*4;
    if(ans==y){
      cout << "Yes" << endl;
      return 0;
      
    }
    
    
  }
  cout << "No" << endl;
  
}
  
  
  


Measured memory_bytes: 3628
#DP　動的計画法

N = int(input())

INF = 10 ** 9
dp = [INF] * (N+1) #初期化配列

dp[0] = 0
for n in range(1, N+1):
    power = 1
    while power <= N:
        dp[n] = min(dp[n], dp[n-power]+1)
        power *= 6
    power = 1
    while power <= N:
        dp[n] = min(dp[n], dp[n-power]+1)
        power *= 9

#print (dp)
print (dp[N])

Measured memory_bytes: 3828
def main():
    n = int(input())
    a = list(map(int, input().split()))
    abs_a = list(map(abs, a))

    cnt = 0
    for i in a:
        if i < 0:
            cnt += 1
        elif i == 0:
            print(sum(abs_a))
            exit()

    if cnt % 2 == 0:
        print(sum(abs_a))
    else:
        print(sum(abs_a) - 2 * min(abs_a))

main()

Measured memory_bytes: 90780
A, B, C, X, Y = map(int, input().split())
# ナップザック問題、にするまでもない。
for i in range(max(X,Y)+1):
    cost = i * 2*C + max(X-i, 0)*A + max(Y-i, 0) *B
    if i ==0:
        res = cost
    else:
        res = min(res, cost)
print(res)

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

int main () {
  int A, B;
  cin >> A >> B;
  vector<vector<int> > list(B, vector<int>(2));
  for(int i = 0; i<B; i++) cin >> list[i][0] >> list[i][1];

  for(int i = 1; i<=A; i++) {
      int cnt = 0;
      for(int j = 0; j<B; j++) {
          if(list[j][0] == i) cnt++;
          if(list[j][1] == i) cnt++;
       }
       cout << cnt << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int d;
    cin >> d;
    vector<int> c(26);
    int s[d][26];
    const int n = 26;
    for(int i = 0; i < n; i++) cin >> c[i];
    for(int i = 0; i < d; i++){
        for(int j = 0; j < n; j++){
            cin >> s[i][j];
        }
    }
    map<int,int> last;
    vector<int> corr;
    for(int now = 0; now < d; now++){
        int ct;
        int mx = -mod;
        for(int i = 0; i < n; i++){
            int can = 0;
            can += s[now][i];
            for(int j = 0; j < n; j++){
                if(i == j) continue;
                can -= c[j]*(now+1-last[j]);
            }
            if(mx < can){
                mx = can;
                ct = i;
            }
        }
        last[ct] = now+1;
        corr.push_back(ct);
    }
    auto stimulate = [&](vector<int>& now,int old,int nxt){
        long long fans = 0;
        map<int,int> flast;
        for(int i = 0; i < d; i++){
            fans += s[i][now[i]];
            flast[now[i]] = i+1;
            for(int j = 0; j < 26; j++){
                fans -= c[j]*(i+1-flast[j]);
            }
        }
        long long sans = 0;
        map<int,int> slast;
        int tmp = now[old];
        now[old] = nxt;
        for(int i = 0; i < d; i++){
            sans += s[i][now[i]];
            slast[now[i]] = i+1;
            for(int j = 0; j < 26; j++){
                sans -= c[j]*(i+1-slast[j]);
            }
        }
        now[old] = tmp;
        if(sans > fans) return true;
        else return false;
    };
    for(int i = 0; i < d; i++){
        for(int j = 0; j < n; j++){
            if(stimulate(corr,i,j)){
                corr[i] = j;
            }
        }
    }
    for(int i = 0; i < d; i++) cout << corr[i]+1 << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<iomanip>
#include<complex>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef queue<int> QI;
typedef list<int> LI;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EMP empty()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 1000000000
#define PI  acos(-1.0)
////////////////////////////////////////////////
#define Nmax 105
#define Wmax 10005
#define Dia 1
#define Top 0

struct item{int v,w;};
int N,W,c[Nmax][Wmax],g[Nmax][Wmax];
item it[Nmax];

void compute(int &maxv,VI &sele)
{
	for(int w=0;w<=W;w++)
	{
		c[0][w]=0;
		g[0][w]=Dia;
	}
	for(int i=1;i<=N;i++)c[i][0]=0;
	
	FOR(i,1,N+1)
	{
		FOR(w,1,W+1)
		{
			c[i][w]=c[i-1][w];
			g[i][w]=Top;
			if(it[i].w>w)continue;
			if(it[i].v+c[i-1][w-it[i].w]>c[i-1][w])
			{
				c[i][w]=it[i].v+c[i-1][w-it[i].w];
				g[i][w]=Dia;
			}
		}
	}
	
	maxv=c[N][W];
	sele.clear();
	for(int i=N,w=W;i>=1;i--)
	{
		if(g[i][w]==Dia)
		{
			sele.PB(i);
			w-=it[i].w;
		}
	}
	
	reverse(sele.begin(),sele.end());
}

int main()
{
	int maxv;
	VI sele;
	cin>>N>>W;
	FOR(i,1,N+1)cin>>it[i].v>>it[i].w;
	compute(maxv,sele);
	cout<<maxv<<endl;
	return 0;
}

Measured memory_bytes: 11044
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
  ll n, k;
  cin>>n>>k;
  ll res = k; n--;
  while(n--) res *= k-1;
  cout<<res<<endl;
	return 0;
}


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


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
 
typedef long long LL;
using namespace std;
 
int n, m;
char s[105][105];
int l[105], r[105];
 
int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
 
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++){
		scanf("%s", s[i] + 1);
	}
	for (int i = 1; i <= n; i++){
		int t = 0;
		for (int j = 1; j <= m; j++){
			if(s[i][j] == '.'){
				t++;
			}
		}
		if(t == m) l[i] = 1;
	}
	for (int i = 1; i <= m; i++){
		int t = 0;
		for (int j = 1; j <= n; j++){
			if(s[j][i] == '.'){
				t++;
			}
		}
		if(t == n) r[i] = 1;
	}
	for (int i = 1; i <= n; i++){
		int flag = 0;
		for (int j = 1; j <= m; j++){
			if(l[i] || r[j]) continue;
			flag = 1;
			printf("%c", s[i][j]);
		}
		if(flag) printf("\n");
	}
 
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  if (n & 1)
    cout << 0 << '\n';
  else {
    n /= 2;
    long long cnt = 0;
    long long pw5 = 5;
    while (n >= pw5) cnt += n / pw5, pw5 *= 5;
    cout << cnt << '\n';
  }
  return 0;
}


Measured memory_bytes: 3656
import java.lang.*;
import java.io.*;
import java.util.*;

class Main{
	public static void main(String args[]) throws FileNotFoundException{
		FScanner fs=new FScanner();
		//Scanner sc=new Scanner(System.in);
		
		int[] num=fs.readIntL();
		int n=num[0];
		int k=num[1];
		
		int[] s=new int[k];
		int idx=0;
		
		while(n>=1){
			s[idx]+=1;
			if(idx>=k-1){
				idx=0;
			}else{
				idx++;
			}
			n-=1;
		}
		int min=100;
		int max=1;
		for(int i=0; i<s.length; i++){
			if(min>s[i]){
				min=s[i];
			}
			if(max<s[i]){
				max=s[i];
			}
		}
		
		System.out.println(max-min);
		
	}
	
	

	static void disp(int[] data){
		for(int i=0; i<data.length; i++){
				System.out.printf("%d ",data[i]);
		}
			System.out.println();
	}
	
	static class FScanner{
		Scanner sc;
		FScanner() throws FileNotFoundException{
			sc=new Scanner(System.in);
		}
		boolean hasNextLine(){
			boolean has=true;
			if(!sc.hasNextLine()){
				has=false;
			}
			return has;
		}
		int readInt(){
			int i=Integer.parseInt(sc.nextLine());
			return i;
		}
		int[] readIntL(){
			String[] buf=sc.nextLine().split(" ");
			int[] num=new int[buf.length];
			for(int i=0; i<buf.length; i++){
				num[i]=Integer.parseInt(buf[i]);
			}
			return num;
		}
		String[] readStringL(){
			String[] s=sc.nextLine().split("");
			return s;
		}
	}
}


Measured memory_bytes: 23764
from collections import deque

h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
count = 0
for i in s:
    for j in range(w):
        if i[j] == "#":
            count += 1

def bfs():
    
    d = [[float("inf")] * w for i in range(h)]
    
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((0, 0))
    d[0][0] = 0

    while que:

        p = que.popleft()

        if p[0] == h - 1 and p[1] == w - 1:
            break

        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and d[nx][ny] == float("inf"):
                
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1

    return d[h - 1][w - 1]

ans = bfs()
if ans == float("inf"):
    print(-1)
else:
    print((h*w) - (ans+1) - count)

Measured memory_bytes: 40560