akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
using namespace std;
typedef int long long l;

int main()
{
	l n;
	cin >> n;
	l sum=0,mi=1000000000,nega=0;
	for(l i=1 ; i<=n ; i++)
	{
		l a;
		cin >> a;
		sum+=abs(a);
		l b=abs(a);
		mi=min(b,mi);
		if(a<0) nega+=1;
	}
	cout << sum-(nega%2)*mi*2;
	return 0;
}

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

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class BColorfulHats {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        vector<int> a(N);
        map<int, int> cnt;
        REP(i, N) {
            cin >> a[i];
            cnt[a[i]]++;
        }
        sort(a.begin(), a.end());

        if (a.back() > N - 1) {
            cout << "No" << endl;
            return;
        }

        if (a.front() + 1 < a.back()) {
            cout << "No" << endl;
            return;
        }
        if (a.front() == a.back()) {
            cout << (N >= 2 * a.front() || a.front() + 1 == N ? "Yes" : "No") << endl;
            return;
        }

        int anum = cnt[a.front()];
        int bnum = cnt[a.back()];
        if (anum > a.front()) {
            cout << "No" << endl;
            return;
        }
        if (bnum >= (a.back() - anum) * 2) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    BColorfulHats solver;
    solver.solve(in, out);
    return 0;
}


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

using namespace std;

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

	string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for (int i=0; i<S.size(); i++) {
		for (int j=0; j<26; j++) {
			if (S.at(i) == alphabet.at(j)) {
				S.at(i) = alphabet.at(j+N);
				break;
			}
		}
	}
	cout << S << endl;
}


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

int main() {
  int n,d;
  cin >> n >> d;
  
  if (n%(2*d+1) == 0){ 
  cout << n/(2*d+1) << endl;
  }
  else {
    cout << n/(2*d+1) +1 << endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define data_type long long
#define endl "\n"
vector<data_type>nod;
void nod_all(data_type n)
{
    nod.resize(n+7);
    for(data_type i=1; i<=n; i++)
        {
            for(data_type j=i; j<=n; j+=i)
                nod[j]+=1;
        }

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    data_type n;
    cin>>n;
    nod_all(n);
    for(data_type i=2; i<=n; i++)
        nod[i]=(nod[i]*i)+nod[i-1];
    cout<<nod[n]<<endl;


    return 0;
}


Measured memory_bytes: 81316
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s1,s2;
  cin >> s1 >> s2;
  if(s1[0]==s2[2] && s1[1]==s2[1] && s1[2]==s2[0]){
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
if H%3==0 or W%3==0:
    print(0)

else:
    for m in range(2):
        H,W=W,H
        if H%2==0:
            A1=(H//2)* W
        else:
            A1=(H//2 +1)* W
        A2=(H//2)* W
        A3=0
        if m == 0:
            value=max(A1,A2,A3)-min(A1,A2,A3)
        else:
            value=min(max(A1,A2,A3)-min(A1,A2,A3),value)
        for i in range(W):
            A3+=H
            if H%2==0:
                A1-=H//2
            else:
                A1-=H//2 + 1
            A2-=H//2
            value=min(max(A1,A2,A3)-min(A1,A2,A3),value)
    value=min(value,H,W)



    print(value)


Measured memory_bytes: 40304
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    if (s=="SUN"){
        cout<<"7"<<endl;
    }
    else if (s=="MON"){
        cout<<"6"<<endl;
    }
    else if (s=="TUE"){
        cout<<"5"<<endl;
    }
    else if (s=="WED"){
        cout<<"4"<<endl;
    }
    else if (s=="THU"){
        cout<<"3"<<endl;
    }
    else if (s=="FRI"){
        cout<<"2"<<endl;
    }
    else if (s=="SAT"){
        cout<<"1"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3596
dhw = [(1,0),(0,-1),(0,1),(-1,0),
( 2,-2),( 2,-1),( 2, 0),( 2, 1),( 2, 2),
( 1,-2),( 1,-1),        ( 1, 1),( 1, 2),
( 0,-2),                        ( 0, 2),
(-1,-2),(-1,-1),        (-1, 1),(-1, 2),
(-2,-2),(-2,-1),(-2, 0),(-2, 1),(-2, 2)]

H, W = map(int, input().split())
sh, sw = map(lambda x:int(x)-1, input().split())
eh, ew = map(lambda x:int(x)-1, input().split())
S = [input() for _ in range(H)]

dst = [[-1]*W for _ in range(H)]
dst[sh][sw] = 0

from collections import deque
dq = deque([[sh, sw]])
while dq:
    h, w = dq.popleft()

    for i in range(4):
        nh = h + dhw[i][0]; nw = w + dhw[i][1]
        if nh < 0 or H <= nh : continue
        if nw < 0 or W <= nw : continue
        if S[nh][nw] == '#': continue
        if dst[nh][nw] == -1 or dst[h][w] < dst[nh][nw]:
            dst[nh][nw] = dst[h][w]
            dq.appendleft([nh, nw])

    for i in range(4, 24):
        nh = h + dhw[i][0]; nw = w + dhw[i][1]
        if nh < 0 or H <= nh : continue
        if nw < 0 or W <= nw : continue
        if S[nh][nw] == '#': continue
        if dst[nh][nw] >= 0: continue
        if dst[nh][nw] == -1 or dst[h][w] + 1 < dst[nh][nw]:
            dst[nh][nw] = dst[h][w] + 1
            dq.append([nh, nw])

print(dst[eh][ew])


Measured memory_bytes: 92024
use whiteread::parse_line;

fn main() {
    let n: usize = parse_line().unwrap();
    let mut a: Vec<usize> = parse_line().unwrap();
    let mut b: Vec<usize> = parse_line().unwrap();
    let mut cnt = 0;

    for i in 0..n {
        if b[i] < a[i] {
            cnt += b[i];
            b[i] = 0;
        } else {
            cnt += a[i];
            b[i] -= a[i];
        }
        if b[i] < a[i + 1] {
            cnt += b[i];
            a[i + 1] -= b[i];
        } else {
            cnt += a[i + 1];
            a[i + 1] = 0;
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4580
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <string.h>
#include <vector>

using namespace std;

typedef vector <vector<int>> Graph;
const int MAX_N = 10000;

int root;
bool visited[MAX_N];
bool finished[MAX_N];

void dfs(int u, int parent, const Graph &G, stack<int> &path) {
  visited[u] = true;
  path.push(u);

  for (int v : G[u]) {
    if (v == parent) continue;
    if (finished[v]) continue;

    if (visited[v] && !finished[v]) {
      root = v;
      return;
    }

    dfs(v, u, G, path);

    if (root != -1) return;
  }

  path.pop();
  finished[u] = true;
}

vector<int> cycle_detection(int start, const Graph &G) {
  root = -1;
  memset(visited, false, sizeof(visited));
  memset(finished, false, sizeof(finished));
  stack<int> path;

  dfs(start, -1, G, path);

  vector<int> res;

  while (!path.empty()) {
    res.push_back(path.top());
    path.pop();
  }

  return res;
}

int main() {
  int N, M;
  cin >> N >> M;
  Graph G(N + 1);

  int a, b;
  for (int i = 0; i < M; ++i) {
    cin >> a >> b;

    G[a].push_back(b);
  }

  int minV = INT_MAX;
  vector<int> ans;

  for (int i = 1; i <= N && ans.empty(); ++i) {
    vector<int> path = cycle_detection(i, G);

    if (path.empty()) continue;

    for (int root : path) {
      queue<int> que;
      que.push(root);
      memset(visited, false, sizeof(visited));
      int parents[N + 1];
      memset(parents, -1, sizeof(parents));

      while (!que.empty()) {
        int u = que.front();
        que.pop();

        visited[u] = true;

        for (int v : G[u]) {
          if (v == root) {
            int cur = u;
            vector<int> res;

            while (cur != -1) {
              res.push_back(cur);
              cur = parents[cur];
            }

            if (minV > res.size()) {
              minV = res.size();
              ans = res;
            }

            break;
          }

          if (visited[v]) continue;

          parents[v] = u;
          que.push(v);
        }
      }
    }
  }

  if (ans.empty()) {
    cout << -1 << endl;
  } else {
    cout << ans.size() << endl;
    for (int v : ans) {
      cout << v << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3768
n = int(input())
t = list(map(int, input().split()))
m = int(input())
p_x = []
for _ in range(m):
  p, x = map(int, input().split())
  p_x.append([p, x])
for i in p_x:
  p = i[0]
  x = i[1] 
  ans = sum(t) - t[p-1] + x
  print(ans)

Measured memory_bytes: 9096
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,t[100000],x[100000],y[100000];
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> t[i] >> x[i] >> y[i];
    if(t[i]%2!=(x[i]+y[i])%2||t[i]<x[i]+y[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include <cstdlib>
#include<bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    int n, m;
    cin >> n >> m;
    out(n*m);
}


Measured memory_bytes: 3636
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[3];
    for(int i = 0; i < n; i++){
      int tmp = sc.nextInt();
      if(tmp % 4 == 0){
        a[2]++;
      }else if(tmp % 2 == 0){
        a[1]++;
      }else{
        a[0]++;
      }
    }
    if(a[0] <= a[2] || (a[0] == a[2]+1 && a[1] == 0)){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


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

//vector…可変長、データの大きさに合わせてサイズを変える
//list…双方向リスト、要素を挿入、削除の多いとき
//forward_list
//array…固定長配列
//set…集合
//multiset
//bitset…2進数、固定長ビット列
//map…連想配列、キーと値を関連付ける
//multimap
//deque
//stack…FILO
//queue…FIFO
//priority_queue
//pair…二つの値を一組
//tuple…複数の値を一組

template<typename T>
void remove(std::vector<T>& vector, unsigned int index) {
    vector.erase(vector.begin() + index);
}

template<class T>
T ma(std::vector<T> &v) {
    T maxi = 0;
    for(auto &i:v) maxi = max(maxi, i);
    return maxi;
}

#define rep(i, n, m) for (int i = n; i <= m; i++)
#define Rep(i, n, m) for (int i = m; i >= 1; i--)

typedef long long ll;
typedef unsigned long long ull;

ull ans = 0;

int main() {
    int a, b, t;
    cin >> a >> b >> t;
    ans = t/a * b;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){
 
            int one = Integer.parseInt(sc.next());
            int zero = Integer.parseInt(sc.next());
            int minus = Integer.parseInt(sc.next());
            int k = Integer.parseInt(sc.next());

            int ans = 0;

            for(int i = 0; i < k; i++){
                if(one != 0){
                    one--;
                    ans++;
                }else if(zero != 0){
                    zero--;
                }else if(minus != 0){
                    minus--;
                    ans--;
                }
            }

            System.out.println(ans);
            
        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

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

int main() {
    int N,K;
    cin >> N >> K;
    vector<int64_t> H(N);
    for(int i;i<N;i++) cin >> H.at(i);

    sort(H.begin(),H.end());
    int64_t cnt = 0;

    for(int i=0;i<N-K;i++){
        cnt += H.at(i);
    }

    cout << cnt << endl;

    return 0;
}


/*
戦略：ＨＰ高い敵に必殺技ー＞ソート
その他を通常攻撃にすれば、通常攻撃回数は最小になるはず


*/

Measured memory_bytes: 1792
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;

class Program
{
	//Main
	static void Main(string[] args)
	{
		//読み込む
		long N = long.Parse(Console.ReadLine());

		//Nの約数のうち、Kで割った商をKで割った余りが1のものをカウント
		/*
		即ち、N = pKとしたとき、
		p = qK + rと表せるが、（0<=q）
		この余りrが1となれば良い
		（∵p = qK + 1となれば、Kを引き続けることで答えが1となる）
		*/
		long divCounterN = 0;
		//(N-1)の約数をカウント
		long divCounterN2 = 0;

		//約数を数え上げ
		long root = (long)Math.Sqrt(N);
		long root2 = (long)Math.Sqrt(N-1);

		//Nの約数について調査
		for(long i=1; i<=root; i++){
				if(N % i == 0){
						//約数iがKとなる場合についてカウント
						if(i != 1){
								long K = i;
								long div = N;
								while(div % K == 0){
										div /= K;
								}
								if(div % K == 1){
										divCounterN ++;
								}
						}

						//約数N/iについても同様に検証
						long K2 = N/i;
						long div2 = N;
						while(div2 % K2 == 0){
								div2 /= K2;
						}
						if(div2 % K2 == 1){
								divCounterN ++;
						}

						//平方根の場合は二重に加算していることに注意
						if(i*i == N){
								divCounterN --;
						}
				}
		}

		//N-1の約数を調査
		for(long i=1; i<=root2; i++){
				if((N-1) % i == 0){
						divCounterN2 ++;
				}
		}

		if((N-1)!= 1){
				divCounterN2 *= 2;
				if(root2*root2 == (N-1)){
						divCounterN2 --;
				}
		}

		/*debug
		Console.WriteLine(divCounterN);
		Console.WriteLine(divCounterN2);
		*/

		//両者を加算
		long answer = divCounterN + divCounterN2;

		//(N-1)の約数1の分を減算（Nを1で割っても余らない）
		//（1は、NとN-1の唯一の公約数）
		answer --;

		Console.WriteLine(answer);

	}
}



Measured memory_bytes: 13140
#include <stdio.h>
int main (){
int n,b,i,j;
int card [4][13] = {0};
char a;
scanf("%d\n",&n);

for (i = 0;i<n;i++){
scanf("%c %d\n",&a,&b);
if (a == 'S'){
 card[0][b-1] = b;
}else if(a == 'H'){
    card[1][b-1] = b;
    
}else if (a == 'C'){
    card[2][b-1] = b;
}else{
    card[3][b-1] = b;
}
}

for (i = 0;i<4;i++){
    for (j = 0;j<13;j++){
        if (card[i][j] == 0){
            if (i == 0){
             printf("S %d\n",j+1);   
            }else if (i == 1){
                printf("H %d\n",j+1);
            }else if (i == 2){
                printf("C %d\n",j+1);
            }else{
                printf("D %d\n",j+1);
            }
        }
    }
}


return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#include <unordered_set>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

const int MOD = 1e9 + 7;
const int MAX = 1e6;

ll fact[MAX + 1];
ll invfact[MAX + 1];

ll modpow(ll a, ll b) {
	if (b == 0) return 1;
	if (b & 1) return modpow(a, b - 1) * a % MOD;
	else {
		ll tmp = modpow(a, b / 2);
		return tmp * tmp % MOD;
	}
}

ll nCk(int a, int b) {
	//n! / (k!(n-k)!)
	return fact[a] * invfact[b] % MOD * invfact[a - b] % MOD;
}

ll nPk(int a, int b) {
	return fact[a] * invfact[a- b] % MOD;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N, M; cin >> N >> M;

	fact[0] = 1;
	for (int i = 1; i <= MAX; i++) fact[i] = fact[i - 1] * i % MOD;
	invfact[MAX] = modpow(fact[MAX], MOD - 2);
	for (int i = MAX; i >= 1; i--) invfact[i - 1] = invfact[i] * i % MOD;

	ll ans = 0;
	for (int i = 0; i <= N; i++) {
		if (i % 2 == 0) {
			ans = (ans + nCk(N, i) * nPk(M, i) % MOD * nPk(M - i, N - i) % MOD * nPk(M - i, N - i) % MOD) % MOD;
		}
		else {
			ans = (ans - nCk(N, i) * nPk(M, i) % MOD * nPk(M - i, N - i) % MOD * nPk(M - i, N - i) % MOD + MOD) % MOD;
		}
	}

	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 19288
#include<stdio.h>
int main(void){
  int X,Happy,i;
  scanf("%d",&X);
  for(Happy=0;X>=500;X=X-500)
    Happy=Happy+1000;
  for(i=0;X>=5;X=X-5)
    Happy=Happy+5;
  printf("%d",Happy);
return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	N := nextInt()
	A := make([]int, N)
	numbers := map[int][]int{}
	M := 1

	for i := 0; i < N; i++ {
		a := nextInt()
		A[i] = a
		numbers[a] = append(numbers[a], i)
		M = max(a, M)
	}

	c := 0

	for i, l := range numbers {
		if len(l) > 1 {
			continue
		}
		divs := divisors(i)
		// debug(i, divs)
		exists := false
		for j := 0; j < len(divs); j++ {
			_, ok := numbers[divs[j]]
			if ok && divs[j] != i {
				exists = true
				break
			}
		}
		if !exists {
			c++
		}
	}

	fmt.Println(c)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func divisors(n int) []int {
	divs := make([]int, 0)

	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			divs = append(divs, i)

			if i != n/i {
				divs = append(divs, n/i)
			}
		}
	}

	return divs
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}

func debug(args ...interface{}) {
	fmt.Fprintln(os.Stderr, args)
}


Measured memory_bytes: 41160
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main() {
  int n;
  cin>>n;
  vector<string> ids(n);
  REP(i,n)cin>>ids[i];
  bool opened = false;
  int m;
  cin>>m;
  REP(i,m){
    string s;
    cin>>s;
    auto itr = find(begin(ids),end(ids),s);
    if (itr == end(ids)) {
      cout << "Unknown " << s << endl;
    } else {
      if (opened) {
        cout << "Closed by " << s << endl;
      } else {
        cout << "Opened by " << s << endl;
      }
      opened = !opened;
    }
  }
  return 0;
}

Measured memory_bytes: 1216
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main(){
    int n;
    cin >> n;    
    vector<int> a(n);
    for(int i=0; i<n; ++i) cin >> a[i];

    vector<int> left(n+1), right(n+1);
    for(int i=0; i<n; ++i) left[i+1] = GCD(left[i], a[i]);
    for(int i=n-1; i>=0; --i) right[i] = GCD(right[i+1], a[i]);

    int ans = 0;
    for(int i=0; i<n; i++){
        int l = left[i];
        int r = right[i+1];

        if(GCD(l, r) > ans) ans = GCD(l, r);

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1536
const main = (input) => {
  input = input.trim();
  input = input.split(' ');
  const n = parseInt(input[0], 10);
  
  if(n%2===0){
    console.log(n);
  }else{
    console.log(2*n);
  }
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
import java.util.Scanner;

public class Main {
    static int N;
    static int THRESHOLD = 111;

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        scanner.close();

        for(int i = 0; i < 9; i++) {
            if(N > THRESHOLD * i && N <= THRESHOLD * (i + 1)) {
                System.out.println(THRESHOLD * (i + 1));
                break;
            }
        }
    }
}


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

using namespace std;

using ll = long long;

ll f[10000002];

int main() {

  ll n; cin >> n;
  for (int i = 1; i < 10000002; ++i) {
      for (int j = i; j < 10000002; j+=i) {
        ++f[j];
      }
   }

  ll ans = 0;
  for(ll i = 1; i <= n; ++i){
    ans += (i * f[i]);
  }
  cout << ans;
  return 0;
}


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

int dig_sum(int a) {
    int sm = 0;
    while(a > 0) {
        sm += a%10;
        a /= 10;
    }
    return sm;
}

bool harshad(int a) {
    return a%dig_sum(a) == 0;
}

int main()
{
    int N;
    cin >> N;
    if(harshad(N)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner in=new Scanner(System.in);
        int a=in.nextInt(),b=in.nextInt();
        if(a+b>16 || a>8 || b>8){
            System.out.println(":(");
        }else{
            System.out.println("Yay!");
        }

    }

}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 310;
 
int n, m;
vector <int> v[N];
int front[N];
 
bool can(int x) {
  for (int i = 0; i < n; ++i) {
    front[i] = 0;
  }
  set <int> del;
  while (1) {
    map <int, vector <int> > mp;
    for (int i = 0; i < n; ++i) {
      if (front[i] < v[i].size()) {
	int c = v[i][front[i]];
	mp[c].push_back(i);
      } else {
	return 0;
      }
    }
    vector <int> fail;
    for (auto &kv : mp) {
      if (kv.second.size() > x) {
	del.insert(kv.first);
	for (int i : kv.second) {
	  fail.push_back(i);
	}
      }
    }
    if (fail.empty()) return 1;
    for (auto i : fail) {
      for (++front[i]; front[i] < v[i].size(); ++front[i]) {
	if (del.count(v[i][front[i]]) == 0) break;
      }
    }
  }
  return 1;
}
 
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0, x; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &x);
      v[i].push_back(x);
    }
  }
  int l = 0, r = n;
  while (l + 1 < r) {
    int md = (l + r) / 2;
    if (can(md)) {
      r = md;
    } else {
      l = md;
    }
  }
  printf("%d\n", r);
  return 0;
}


Measured memory_bytes: 896
A=input()
B=input()
C=input()
lA,lB,lC=[],[],[]
A1,B1,C1=0,0,0
for i in A:
     lA.append(i)
for i in B:
     lB.append(i)
for i in C:
     lC.append(i)
def fu(i):
     global A1,B1,C1
     if i=='a':
          if len(lA)-1==A1:
               return print("A")
          else:
               A1+=1
               fu(lA[A1])
     if i=='b':
          if len(lB)==B1:
               return print("B")
          else:
               B1+=1
               fu(lB[B1-1])
     if i=='c':
          if len(lC)==C1:
               return print("C")
          else:
               C1+=1
               fu(lC[C1-1])
fu(lA[0])

Measured memory_bytes: 3188
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kishan Sairam Adapa
 */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ll long long int
#define MOD ((int)(1e9) + 7)

using namespace std;

class CAttackSurvival {
public:
    void solve(istream& cin, ostream& cout) {
        ll n, k , q;
        cin >> n >> k  >> q;
        vector<int> cor(n+1, 0);
        for(int i=0; i<q; i++) {
            int tp;
            cin >> tp;
            cor[tp]++;
        }
        for(int i=1; i<=n; i++) {
            cor[i] = cor[i] - q + k;
            cout << ((cor[i] > 0) ? "Yes\n": "No\n");
        }
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    CAttackSurvival solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1024
while True:
    w, h = map(int, input().split())
    if w == 0: break
    goal = (w,h)
    vart = []
    hori = []
    for i in range(2*h-1):
        if i % 2 == 0:
            vart.append(list(map(int, input().split())))
        else:
            hori.append(list(map(int, input().split())))
    node = [[0 for i in range(h)] for i in range(w)]
    queue = [(0,0)]
    while queue:
        p = queue.pop(0)
        x, y = p[0], p[1]
        node[x][y] += 1
        if y-1 >= 0 and hori[y-1][x] == 0 and node[x][y-1] == 0:
            node[x][y-1] = node[x][y]
            queue.append((x,y-1))
        if y+1 < h and hori[y][x] == 0 and node[x][y+1] == 0:
            node[x][y+1] = node[x][y]
            queue.append((x,y+1))
        if x-1 >= 0 and vart[y][x-1] == 0 and node[x-1][y] == 0:
            node[x-1][y] = node[x][y]
            queue.append((x-1,y))
        if x+1 < w and vart[y][x] == 0 and node[x+1][y] == 0:
            node[x+1][y] = node[x][y]
            queue.append((x+1,y))
    print(node[goal[0]-1][goal[1]-1])

Measured memory_bytes: 7712
import java.math.BigInteger;
import java.util.*;

public class Main {

    public static void main(String[] args) {
	// write your code here
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();

    if(N % K  == 0)
        System.out.println(0);
    else
        System.out.println(1);
    }










    public static Integer min(List<Integer> ar){
        int min = 10000;
        int index = 0;
        for(int i = 0; i< ar.size();i++){
            if(min > ar.get(i)){
                min = ar.get(i);
                index = i;
            }
        }
        return min;
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <string.h>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#define INF 100000000
 
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;
const ll M = 998244353;
 
int main(void) {
    ll n, k, d, tmp;
    cin >> n >> k;
    ll sunuke[n];
    fill(sunuke, sunuke+n, 0);
    for(ll i=0;i<k;i++) {
      cin >> d;
      for(ll j=0;j<d;j++) {
        cin >> tmp;
        sunuke[tmp-1]++;
      }
    }
    tmp = 0;
    for(ll i=0;i<n;i++) {
        if(sunuke[i]==0) tmp++;
    }
    cout << tmp << endl;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iostream>
#define pb push_back
#define mkp make_pair
using namespace std;

int n;
const int maxn = 100005;
typedef long long ll;


int main()
{

    cin >> n;
    ll ans = 0;
    int now = 1;
    for (int i = 1; i <= n; i ++)
    {
        ll t;
        cin >> t;
        ans += (t-1)/now;
        if (i == 1 || t == now)
        {
            now ++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#define ABC122_A
#ifdef ABC122_A
// ABC122-A 

#pragma comment (linker, "/STACK:256000000")
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(const size_t n, const size_t m, const T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; }return 0; }
constexpr ll pow2(const int n) { return 1ll << n; }
constexpr int INF = 1 << 28; constexpr ll LINF = 1ll << 60;
constexpr int MAX = 1e5 + 5; constexpr int MOD = 1e9 + 7; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }; constexpr int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;
// 1. 問題よくよめえええええええええええええええええええええええええ
// 2. intオーバーフロー << * + あたり
// 3. 落ち着け

int N, M, H, W;
int ans;
string s;

int main() {
    char c;
    cin >> c;

    if (c == 'A') write("T");
    else if (c == 'T') write("A");
    else if (c == 'G') write("C");
    else write("G");
}

#endif

Measured memory_bytes: 256
function main()
  n=parse(Int,readline())
  bucket=[0 for i=1:10^5]
  sum=0
  for i=parse.(Int,split(readline())); sum+=i; bucket[i]+=1;end
  q=parse(Int,readline())
  for i=1:q
    b,c=parse.(Int,split(readline()))
    sum+=bucket[b]*(c-b)
    bucket[c]+=bucket[b]
    bucket[b]=0
    println(sum);end
end
main()

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


def solve(S: str, T: str):
    length = len(T)
    s_list =[]
    counter = length
    ans = 0

    for i in range(len(S)-length+1):
        s = S[i:i+length]
        for i in range(length):
            #print(s[i], T[i])
            if s[i] != T[i]:
                ans+=1

        counter = min(ans, counter)

        ans = 0

    return print(counter)


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9132
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define debug freopen("input", "r", stdin);freopen("output", "w", stdout)
#define endl '\n'
#define all(var) var.begin(), var.end()
int const MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
    map < char , bool > mp;
    string s; cin >> s;
    for(auto i: s)
        mp[i] = true;
    if(mp.size() == 2) cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int MAXN=1e5+10;
int num1[MAXN],num2[MAXN];
int T,n;
int head[MAXN],net[2*MAXN],u[2*MAXN],v[2*MAXN],tot;
int read()
{
	int f=0,w=1; char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { f=(f<<3)+(f<<1)+ch-'0'; ch=getchar(); }
	return f*w;
}
void add(int l,int r)
{
	u[++tot]=l; v[tot]=r; net[tot]=head[l]; head[l]=tot;
}
int vt[MAXN];
void dfs(int now,int step,int flag)
{
	vt[now]=1; 
	if(flag==1) num1[now]=step;
	if(flag==2) num2[now]=step;
	for(int i=head[now];i;i=net[i])
		if(vt[v[i]]==0)
			dfs(v[i],step+1,flag);
}
int main()
{
	//freopen("T3.in","r",stdin);
	//freopen("T3.out","w",stdout);
	T=1;
	while(T--)
	{
		n=read(); tot=0;
		memset(head,0,sizeof(head));
		memset(net,0,sizeof(net));
		memset(u,0,sizeof(u));
		memset(v,0,sizeof(v));
		memset(num1,0,sizeof(num1));
		memset(num2,0,sizeof(num2));
		for(int i=1;i<n;i++)
		{
			int l=read(),r=read();
			add(l,r);
			add(r,l);
		}
		memset(vt,0,sizeof(vt));
		dfs(1,0,1);
		memset(vt,0,sizeof(vt));
		dfs(n,0,2);
		int p1=0,p2=0;
		for(int i=1;i<=n;i++)
		{
			if(num1[i]<num2[i])
				p1++;
			if(num2[i]<num1[i])
				p2++;
			if(num1[i]==num2[i])
				p1++;
		}
		if(p1>p2) printf("Fennec\n");
		else printf("Snuke\n");
	}
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}

class BIT
{
public:
    vector<int> bit;
    int M;

    BIT(int M):
        bit(vector<int>(M+1, 0)), M(M) {}

    int sum(int i) {
        if (!i) return 0;
        return bit[i] + sum(i-(i&-i));
    }

    void add(int i, int x) {
        if (i > M) return;
        bit[i] += x;
        add(i+(i&-i), x);
    }
};

signed main(){

    string S; cin >> S;
    int N = S.size();
    BIT b(N + 1);
    int ans = 0;
    REP(i, N){
        if(S[i] == 'B') b.add(i + 1, 1);
        else ans += b.sum(i + 1);
    }
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 2180
use proconio::input;

fn main() {
    input! {
        x: u32,
    }

    let ans = match x {
        400..=599 => 8,
        600..=799 => 7,
        800..=999 => 6,
        1000..=1199 => 5,
        1200..=1399 => 4,
        1400..=1599 => 3,
        1600..=1799 => 2,
        1800..=1999 => 1,
        _ => unreachable!(),
    };

    println!("{}", ans);
}


Measured memory_bytes: 2148
#include<bits/stdc++.h>
// #define long long long long long long
#define loop(i,start,end) for(long long i = start; i< end; i++)
using namespace std;
vector <vector<long long>> dp;
vector <long long> val;
vector <long long> weight;
long long N, W;
long long best(long long n, long long weight_aval, long long prev_valsum){
    if(n+1==N){
        if(weight[n]<=weight_aval){
            return val[n];
        }
        else{
            return 0;
        }
    }
    else{
        long long opt1,opt2;
        if(dp[n][weight_aval]!=-1){
            return dp[n][weight_aval];
        }
        else{
            if(weight[n]<=weight_aval){
                opt1 = val[n]+best(n+1,weight_aval-weight[n], prev_valsum+val[n]);
                opt2 = best(n+1,weight_aval,prev_valsum);
                dp[n][weight_aval] = max(opt1,opt2);
                return max(opt1,opt2);
            }
            else{
                opt2 = best(n+1,weight_aval,prev_valsum);
                dp[n][weight_aval] = opt2;
                return opt2;
            }
        }
    }
}
int main(){
    long long n,w,el;
    cin>>n>>w;
    N = n;
    W = w;
    for(long long i = 0; i< n; i++){
        cin>>el;
        weight.push_back(el);
        cin>>el;
        val.push_back(el);
    }
    if(n==1){
        if(weight[0]<=w){
            cout<<val[0];
        }
        else{
            cout<<0;
        }
    }
    else{
        dp.resize(n+1);
        for (long long i = 0; i < n+1; ++i)
            dp[i].resize(w+1,-1);
        cout<<best(0,w,0);
    }
}

Measured memory_bytes: 79488
#include <utility> // pair make_pair
using std::swap; // c++11
using std::pair;
using std::make_pair;
#include <tuple> // tuple(c++11) make_tuple(c++11)
using std::tuple; // get<address>(variable)
using std::make_tuple;
#include <string> // string stoi(c++11) stoll(c++11) to_string(c++11)
using std::string;
using std::stoi;
using std::stoll;
using std::to_string;
#include <queue> // queue priority_queue
using std::queue;
using std::priority_queue;
#include <stack> // stack
using std::stack;
#include <vector> // vector
using std::vector;
#include <map> // map
using std::map;
#include <set> // set
using std::set; // insert erase find count
#include <algorithm> // min max
using std::sort;
using std::lower_bound; // iterator,  >=
using std::upper_bound; // iterator,  >
using std::min;
using std::max;
using std::min_element; // iterator
using std::max_element; // iterator
#include <complex> // complex
using std::complex; // real imag
#include <iostream> // cin cout
using std::cin;
using std::cout;
using std::endl;
#include <iomanip> // setprecision fixed(manipulator)
using std::setprecision;
using std::fixed;
#include <cmath>
#include <cstdio>

#define lli long long int
#define INF (int)1e09
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define EFOR(i, m, n) for (int i = m; i <= n; i++)
#define RFOR(i, m, n) for (int i = m; i > n; i--)
#define REFOR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort((v).begin(), (v).end()) // sort vector
typedef pair<int, int> PI;
typedef tuple<int, int, int> TI;
template <typename T> using Vec = vector<T>; // c++11

int main(void) {
    int h;
    int w;
    cin >> h >> w;
    Vec<Vec<int> > exchange(10, Vec<int>(10));
    FOR (i, 0, 10) {
        FOR (j, 0, 10) {
            cin >> exchange[i][j];
        }
    }

    FOR (k, 0, 10) {
        FOR (i, 0, 10) {
            FOR (j, 0, 10) {
                exchange[i][j] = min(exchange[i][j], exchange[i][k] + exchange[k][j]);
            }
        }
    }

    int count[10] = {};

    FOR (i, 0, h) {
        FOR (j, 0, w) {
            int temp;
            cin >> temp;
            if (temp != -1) {
                count[temp]++;
            }
        }
    }

    int ans = 0;
    FOR (i, 0, 10) {
        ans += exchange[i][1] * count[i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  int t, r = 0, m = 10;

  REP(i, 5)
  {
    cin >> t;
    r += ceil((double)t / 10) * 10;
    if (t % 10 != 0)
      m = min(m, t % 10);
  }

  cout << r - 10 + m << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	std::string s; cin >> s;
	
	if(s[1] == s[2] and (s[0] == s[1] or s[2] == s[3])) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
using namespace std;
int main(){
    string s;
    cin>>s;
    vector<int> a(3,0);
    rep(i,0,(int)s.length())a[s[i]-'a']++;
    int ok=0;
    if(abs(a[0]-a[1])<2&&abs(a[0]-a[2])<2&&abs(a[1]-a[2])<2)ok=1;
	if(ok)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int mxn=3e5+9;
#define ll long long
long long n,k,m, l, ans=-1, a[mxn];
map<long long, long long>mp;

bool checkOdd()
{
    for(auto z : mp){
        if(z.first%2==1) return false;
        else if(z.first==0) {if(z.second!=1) return false;}
        else if(z.second!=2) return false;
    }
    return true;
}
bool checkEven()
{
    for(auto z : mp){
        if(z.first%2==0) return false;
        else if(z.second!=2) return false;
    }
    return true;
}
ll bigmod(ll a, ll b){if(b==0) return 1%mod;ll x = bigmod(a,b/2);
    x = (x*x)%mod;if(b%2==1) x = (x*a)%mod;return x;}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
        mp[ a[i] ]++;
    }
    if(n%2==1 and checkOdd()) cout<<bigmod(2,n/2)<<endl;
    else if(n%2==0 and checkEven()) cout<<bigmod(2,n/2)<<endl;
    else cout<<0<<endl;
    return 0;
}



Measured memory_bytes: 4992
/*
    author: kartik8800
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(ll i = a; i < b; i++)
#define mod 1000000007
#define inf 1e9 + 1
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

struct item
{
    int wt;
    int val;
};
 
int solve(vector<item> ar, int n, int W)
{
    int maxVal = n * 1000;
    ll dp[n+1][maxVal + 1];

    for(int val = 0; val <= maxVal; val++)
        dp[1][val] = inf;
    dp[1][0] = 0;
    dp[1][ar[1].val] = ar[1].wt;

    for(int i = 2; i <= n; i++)
    {
        for(int v = 0; v <= maxVal; v++)
        {
            dp[i][v] = dp[i-1][v];
            if(ar[i].val > v)
                continue;
            dp[i][v] = min(dp[i][v], ar[i].wt + dp[i-1][v-ar[i].val]);
        }
    }

    int ans = 0;
    for(int x = 0; x <= maxVal; x++)
    {
        if(dp[n][x] <= W)
            ans = x;
    }

    return ans;
}
 
int main() {
    int n, w;
    cin >> n >> w;
    vector<item> ar(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin >> ar[i].wt >> ar[i].val; 
    }
    cout << solve(ar, n, w);
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
const ll mod=1e9+7;
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll res=pow(x,y/2);
  res*=res;
  res%=mod;
  if(y%2==1) res*=x;
  return res%mod;
}
ll gyaku(ll x){
  return pow(x,mod-2);
}
vector<ll> frac;
void frac_set(ll n){
  frac.push_back(1);
  for(ll i=1;i<=n;i++) frac.push_back(frac[i-1]*i%mod);
}
ll nCr(ll n,ll r){
  ll res=frac[n];
  res*=gyaku(frac[r]);
  res%=mod;
  res*=gyaku(frac[n-r]);
  return res%mod;
}
signed main(){
  ll n,m,ans=1;
  bool f=false;
  cin>>n>>m;
  ll mm=m;
  frac_set(500005);
  for(ll i=2;i*i<=mm;i++){
    ll cnt=0;
    while(m%i==0) {
      m/=i;
      cnt++;
      f=true;
    }
    if(cnt==0) continue;
    ans*=nCr(n+cnt-1,cnt);
    ans%=mod;
  }
  if(m!=1) ans*=n;
  cout<<ans%mod<<endl;
}


Measured memory_bytes: 6512
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    s = S()
    ans = 0
    
    for i in range(1,n):
        left = s[:i]
        right = s[i:]
        leftset = set(left)
        rightset = set(right)
        share = len(leftset & rightset)
        ans = max(ans, share)

    print(ans)
main()

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

int main()
{
    int n,k,x,y;
    while(~scanf("%d%d%d%d",&n,&k,&x,&y))
    {
        if(n>k)
            printf("%d\n",(n-k)*y+k*x);
            else
                printf("%d\n",n*x);
    }

    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        String s = std.next();
        int center = n / 2;
        String left = s.substring(0, center);
        String right = s.substring(center);
        if (left.equals(right)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////

ll keta(ll n) {
	if (n < 10) { return n; }
	return keta(n / 10) + n % 10;
}

int main() {

	ll n;
	cin >> n;

	ll ans=INF;

	repn(a, n - 1) {
		ans = min(keta(a) + keta(n - a), ans);
	}
	
	cout << ans;
	system("PAUSE");

}





Measured memory_bytes: 504
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	ll N, X;
	cin >> N >> X;

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

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

	ll sum = 0;

	for (int i = 0; i < N; i++) {
		sum += A[i];

		if (sum > X) {
			cout << i;
			return 0;
		}

		if (i == N - 1) {

			if (sum == X) {
				cout << N;
			}
			else {
				cout << N - 1;
			}
		}

	}





}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    long A, B;
    cin >> A >> B;
    for (long c = 1, d = A - 1, i = 0;; c += d, ++i) {
        if (B <= c) {
            cout << i << endl;
            return 0;
        }
    }
}


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

using namespace std;

int dp[123456], a[123456];
const int inf = 0x7f7f7f7f;
int main(){
//    freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    for(int i = 0; i < n; ++i)dp[i] = inf;
    dp[0] = 0;
    for(int i = 0; i < n ; ++i){
        for(int j: {i+1, i+2}){
            if(j < n)
            dp[j] = min(dp[j], dp[i]+abs(a[i]-a[j]));
        }
    }
//    for(int i = 0; i < n; ++i)cout << dp[i] << " ";
//    cout << endl;
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl



int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<ll> cost_even(n,0);
    vector<ll> cost_odd(n,0);
    for(int i = 0; i < n; i++){
        if(a[i]==0){
            cost_even[i] = 2;
            cost_odd[i] = 1;
        }else if(a[i]%2==0){
            cost_odd[i] = 1;
        }else{
            cost_even[i] = 1;
        }
    }

    vector<vector<ll>> dp(5, vector<ll>(n,0));
    dp[0][0] = a[0];
    dp[1][0] = cost_even[0];
    dp[2][0] = cost_odd[0];
    dp[3][0] = cost_even[0];
    dp[4][0] = a[0];
    for(int i = 1; i < n; i++){
        ll m = dp[0][i-1];
        dp[0][i] = m + a[i];
        dp[1][i] = min(m,dp[1][i-1])+cost_even[i];
        m = min(m, dp[1][i-1]);
        dp[2][i] = min(m,dp[2][i-1])+cost_odd[i];
        m = min(m, dp[2][i-1]);
        dp[3][i] = min(m,dp[3][i-1])+cost_even[i];
        m = min(m, dp[3][i-1]);
        dp[4][i] = min(m,dp[4][i-1])+a[i];
    }
    ll ans = 1LL << 60;
    for(int i = 0; i < 5; i++){
        ans = min(ans, dp[i][n-1]);
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 14336