akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<cmath>
#include<set>

std::set<int> primeFactorization(long long n){
    std::set<int> s;
    int nm = std::sqrt(n);
    for(int i = 2; i <= nm; i++){
        if(n % i == 0){
            s.insert(i);
            do{
                n /= i;
            }while(n % i == 0);
        }
    }
    if(n != 1) s.insert(n);
    return s;
}

int main(void){
    long long a, b;
    std::cin >> a >> b;
    std::set <int> sa, sb;
    sa = primeFactorization(a);
    sb = primeFactorization(b);
    int ans = 0;
    for(auto i = sa.begin(); i != sa.end(); i++){
        if(sb.find(*i) != sb.end()) ans++;
    }
    ans++;
    std::cout << ans << std::endl;
    return 0;
}

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

int main(){

	string s;
	getline(cin, s);
	if(s.empty()){
		getline(cin, s);
	}

	if(s[0] == s[1] and s[1] == s[2]){
		cout<<"No";
	}
	else cout<<"Yes";
	return 0;
}


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

int N, A, B, C, D;
string S;

bool A_first() {
    bool ret = true;

    S[B-1] = '#';
    for (int i = A-1; i < C-1; i++) {
        if (S[i] == '#' && S[i+1] == '#') ret = false;
    }
    S[C-1] = '#';

    S[B-1] = '.';
    for (int i = B-1; i < D-1; i++) {
        if (S[i] == '#' && S[i+1] == '#') ret = false;
    }
    S[C-1] = '.';

    return ret;
}

bool B_first() {
    bool ret = true;

    S[A-1] = '#';
    for (int i = B-1; i < D-1; i++) {
        if (S[i] == '#' && S[i+1] == '#') ret = false;
    }
    S[D-1] = '#';

    S[A-1] = '.';
    for (int i = A-1; i < C-1; i++) {
        if (S[i] == '#' && S[i+1] == '#') ret = false;
    }
    S[D-1] = '.';

    return ret;
}

bool AB_mutual() {
    bool ret = false;

    for (int i = B-1; i < D-2; i++) {
        if (S[i] == '.' && S[i+1] == '.' && S[i+2] == '.') {
            ret = true;
        }
    }

    for (int i = A-1; i < max(C-1, D-1); i++) {
        if (S[i] == '#' && S[i+1] == '#') ret = false;
    }

    return ret;
}

int main() {
    cin >> N >> A >> B >> C >> D >> S;

    bool f1 = A_first();
    bool f2 = B_first();
    bool f3 = AB_mutual();

    if (f1 || f2 || f3) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int h=sc.nextInt();
		int a=sc.nextInt();
		int c=0;
		while(h>0) {
			h-=a;
			c++;
		}
		System.out.println(c);
		sc.close();
	}
}


Measured memory_bytes: 22100
let flip f x y = f y x

let () = Scanf.scanf "%d %d %d" @@ fun a b k ->
  Printf.printf "%d\n" @@
  flip List.nth (k - 1) @@
  List.filter (fun d -> a mod d = 0 && b mod d = 0) @@
  Array.to_list @@ Array.init (min a b) @@ ( - ) @@ min a b


Measured memory_bytes: 384
L = ["", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
S = ""
N = int(input())
while N > 26:
  if N % 26 != 0:
    a = N % 26
    N -= a
    S = L[a] + S
    N //= 26
  else:
    S = L[26] + S
    N //= 26
    N -= 1
S = L[N] + S
print(S.lower())

Measured memory_bytes: 8992
#include<bits/stdc++.h>
using namespace std;
signed main(){
  string a;
  int b,c,d=0;
  cin>>a;
  for(int i=0;i<4;i++){
    b=a[i];
    for(int j=i+1;j<4;j++){
      c=a[j];
      if(b==c){
	d++;
      }
    }
  }
  if(d==2){
    cout<<"Yes"<<"\n";
  }
  else{
    cout<<"No"<<"\n";
  }
  return(0);
}


Measured memory_bytes: 384
k = int(input())

go = 0
keta = len(str(k))

for i  in range(10**1000000):
    if k % 2 ==0:
        print(-1)
        break
    if k % 5==0:
        print(-1)
        break
    else:
        go =(go*10+7) %k
        if go ==0:
            print(i+1)
            break


Measured memory_bytes: 11232
#include<stdio.h>
int main(void){
    int i,j,box,Mt[9];
    for(i=0;i<10;i++){
            scanf("%d",&Mt[i]);
    }
    for(i=0;i<9;i++){
        for(j=i+1;j<10;j++){
            if(Mt[i]<Mt[j]){
                box=Mt[i];
                Mt[i]=Mt[j];
                Mt[j]=box;
            }
        }
    }
    for(i=0;i<3;i++){
        printf("%d\n",Mt[i]);
    }
return 0;
}

Measured memory_bytes: 600
<?php
fscanf(STDIN, "%d", $nLoop);
$AC = 0;
$WA = 0;
$TLE = 0;
$RE = 0;

while(fscanf(STDIN, "%s", $sInput)){
  if($sInput == 'AC'){
    $AC = $AC + 1;
  }
  elseif($sInput == 'WA'){
    $WA = $WA + 1;
  }
  elseif($sInput == 'TLE'){
    $TLE = $TLE + 1;
  }
  elseif($sInput == 'RE'){
    $RE = $RE + 1;
  }
}

echo 'AC x ' .$AC. "\n";
echo 'WA x ' .$WA. "\n";
echo 'TLE x ' .$TLE. "\n";
echo 'RE x ' .$RE. "\n";
?>

Measured memory_bytes: 15976
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

using namespace std;
#define all(c) begin(c), end(c)
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using ll = long long;
using pii = pair<int, int>;
#define VV(T) vector<vector< T > >

int n;
int a[25];
double dp[25][252525];
double inf = 1e9;

double solve() {
    fill((double*)begin(dp), (double*)end(dp), inf);
    dp[0][1] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 1; j < 252525; ++j) {
            for (int k = j; k < 252525; k += j) {
                double nxt = dp[i][j];
                nxt = max(nxt, abs((double)(a[i] - k) / a[i]));
                dp[i + 1][k] = min(dp[i + 1][k], nxt);
            }
        }
    }
    return *min_element(begin(dp[n]), end(dp[n]));
}

int main() {
    while (cin >> n) {
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }
        printf("%.10lf\n", solve());
    }
}

Measured memory_bytes: 52500
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		proconScan proScan = new proconScan(" ");
		proScan.scan();
		Long nInteger = proScan.nextLong();
		Long mInteger = proScan.nextLong();
		Long buf = mInteger - nInteger - nInteger;
		if (buf < 0) {
			buf = Math.floorDiv(mInteger, 2);
		} else {
			buf = nInteger + Math.floorDiv(buf, 4);
		}
		System.out.println(buf);
		proScan.proconEnd();
	}

}

class proconScan {
	private BufferedReader br;
	private String inLine;
	private String[] inString;
	private Integer idx;
	private String splitChar;

	public proconScan() {
		br = new BufferedReader(new InputStreamReader(System.in));
		idx = 0;
		splitChar = " ";
	}

	public proconScan(String split) {
		br = new BufferedReader(new InputStreamReader(System.in));
		idx = 0;
		splitChar = split;
	}

	public void proconEnd() throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		br.close();
	}

	public String scan() throws IOException {
		idx = 0;
		inLine = br.readLine();
		inString = inLine.split(splitChar, 0);
		return inLine;
	}

	public Integer scanInteger1() throws IOException {
		scan();
		return Integer.parseInt(inString[0]);
	}

	public String backLine() {
		return inLine;
	}

	public String nextString() {
		return inString[idx++];
	}

	public String[] getString() {
		return inString;
	}

	public Long nextLong() {
		Long num;
		try {
			num = Long.parseLong(inString[idx++]);
		} catch (NumberFormatException e) {
			num = null;// TODO: handle exception
		}
		return num;
	}

	public Integer nextInteger() {
		Integer num;
		try {
			num = Integer.parseInt(inString[idx++]);
		} catch (NumberFormatException e) {
			num = null;// TODO: handle exception
		}
		return num;
	}

	public Integer[] getInteger() {
		Integer[] num = new Integer[this.getLen()];

		for (int i = 0; i < this.getLen(); i++) {
			num[i] = Integer.parseInt(inString[i]);
		}

		return num;
	}

	public Float nextFloat() {
		Float num;
		try {
			num = Float.parseFloat(inString[idx++]);
		} catch (NumberFormatException e) {
			num = null;// TODO: handle exception
		}
		return num;
	}

	public Float[] getFloat() {
		Float[] num = new Float[this.getLen()];

		for (int i = 0; i < this.getLen(); i++) {
			num[i] = Float.parseFloat(inString[i]);
		}

		return num;
	}

	public Integer getLen() {
		return inString.length;
	}

	public int[] getInt() {
		int[] num = new int[this.getLen()];

		for (int i = 0; i < this.getLen(); i++) {
			num[i] = Integer.parseInt(inString[i]);
		}

		return num;
	}

}

Measured memory_bytes: 23380
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    if ((a % 2 == 0 && b % 2 == 0 && c % 2 == 0) || (a % 2 == 1 && b % 2 == 1 && c % 2 == 1))
    {
        //
    }
    else if ((a % 2 == 1 && b % 2 == 1 && c % 2 == 0) || (a % 2 == 0 && b % 2 == 1 && c % 2 == 1) || (a % 2 == 1 && b % 2 == 0 && c % 2 == 1))
    {
        if (a % 2 == 1)
        {
            a++;
        }
        if (b % 2 == 1)
        {
            b++;
        }
        if (c % 2 == 1)
        {
            c++;
        }
        ans++;
    }
    else
    {
         if (a % 2 == 0)
        {
            a++;
        }
        if (b % 2 == 0)
        {
            b++;
        }
        if (c % 2 == 0)
        {
            c++;
        }
        ans++;
    }
    int maxi = max(max(a, b), c);
    int mini = min(min(a, b), c);
    int midd = a + b + c - maxi - mini;
    ans += (maxi - midd) / 2 + (maxi - mini) / 2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = []
'''
t = s
for i in range(n):
    s.append(str(input()))
ans = n
for i in range(n-1):
    for j in range(i+1, n):
        if s[j] == s[i]:
            ans -= 1
            del t[j]
print(ans)
print(len(t))
'''
for i in range(n):
    s.append(str(input()))
sa = set(s)
print(len(sa))

Measured memory_bytes: 35620
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	UL S[2001][2001] = {};
	UL J1[2001][2001] = {};
	UL J2[2001][2001] = {};

	void Query() {
		UL y1, y2, x1, x2; cin >> y1 >> x1 >> y2>> x2;
		y1--; x1--;
		UL mass = S[x2][y2] + S[x1][y1] - S[x1][y2] - S[x2][y1];
		UL J1s = J1[x2][y2] + J1[x1 + 1][y1] - J1[x1 + 1][y2] - J1[x2][y1];
		UL J2s = J2[x2][y2] + J2[x1][y1 + 1] - J2[x1][y2] - J2[x2][y1 + 1];
		cout << (mass - J1s - J2s) << endl;
	}

	void Solve() {
		UL H, W; cin >> H >> W;
		UL Q; cin >> Q;
		rep(y, H) rep(x, W) {
			char c; cin >> c;
			S[x + 1][y + 1] = (c - '0');
		}
		rep(y, H) rep(x, W) if (S[x][y + 1] && S[x + 1][y + 1]) J1[x + 1][y + 1] = 1;
		rep(y, H) rep(x, W) if (S[x + 1][y] && S[x + 1][y + 1]) J2[x + 1][y + 1] = 1;
		rep(y, H) rep(x, W) S[x + 1][y + 1] += S[x][y + 1];
		rep(y, H) rep(x, W) S[x + 1][y + 1] += S[x + 1][y];
		rep(y, H) rep(x, W) J1[x + 1][y + 1] += J1[x][y + 1];
		rep(y, H) rep(x, W) J1[x + 1][y + 1] += J1[x + 1][y];
		rep(y, H) rep(x, W) J2[x + 1][y + 1] += J2[x][y + 1];
		rep(y, H) rep(x, W) J2[x + 1][y + 1] += J2[x + 1][y];
		rep(i, Q) Query();
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 48768
#include <stdio.h>

int main(){
    int n, i, j, v;
    scanf("%d",&n);
    int *a = new int [n];
    for(i=0;i<n;i++)scanf("%d",a+i);
    for(i=0;i<n;i++){
        v = a[i];
        j = i-1;
        while(j>=0&&v<a[j]){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        for(j=0;j<n;j++){
            if(j>0)printf(" ");
            printf("%d",a[j]);
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2716
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    string s; cin>>s;
    string t = "ABC";
    int ans = 0;
    rep(i,n-2) {
        string a;
        a.push_back(s[i]);
        a.push_back(s[i+1]);
        a.push_back(s[i+2]);
        if (a == t) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;

std::string S;

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

  std::cout << (S[2]==S[3] && S[4]==S[5] ? "Yes" : "No") << std::endl;

  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    data class Point(val x: Long, val y: Long)
    data class CheckPoint(val number: Int, val x: Long, val y: Long)

    val (n, m) = readLine()?.split(" ")?.map(String::toInt) ?: return

    val students = mutableListOf<Point>()

    repeat(n) {
        val (a, b) = readLine()?.split(" ")?.map(String::toLong) ?: return
        students.add(Point(a, b))
    }
    val checkPoints = mutableListOf<CheckPoint>()
    repeat(m) {
        val (c, d) = readLine()?.split(" ")?.map(String::toLong) ?: return
        checkPoints.add(CheckPoint(it + 1, c, d))
    }

    buildString {
        students.forEach { student ->
            val min = checkPoints.minBy { checkPoint ->
                Math.abs(student.x - checkPoint.x) + Math.abs(student.y - checkPoint.y)
            }!!
            appendln(min.number)
        }
    }.let {
        println(it)
    }
}


Measured memory_bytes: 37936
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int N,A[101];
int main() {
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i];
	}

	int total=0;
	sort(A,A+N,greater<int>());
	for(int i=0;i<N;i+=2){
		total+=A[i]-A[i+1];
	}

	cout<<total<<endl;

 	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define ll long long
using namespace std;

int main() {
    ll N;
    cin >> N;
	ll sum=0;
	for(ll i=1;i<N+1;i++){
		if(i%3==0 || i%5==0) continue;
		sum += i;
	}
    cout<< sum <<endl;

    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 100005;

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

    for( int i = 0; i < 7; ++i ) {
        int a, b;
        cin >> a >> b;
        cout << abs( a - b ) << endl;

    }

    return 0;
}



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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

int n,W,wmin;
VVi wa(4);

int dfs(int depth,int weight,int value){        //cout<<depth<<" "<<weight<<" "<<value<<endl;
    if(depth==4){
        if(weight>W) return 0;
        else return value;
    }
    int ret=0;
    REP(i,0,wa[depth].size()){
        chmax(ret,dfs(depth+1,weight+(wmin+depth)*i,value+wa[depth][i]));
    }
    return ret;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    cin>>n>>W;
    Vi w(n),v(n);
    vin(w,v);
    wmin=*min_element(ALL(w));
    REP(i,0,n){
        wa[w[i]-wmin].pb(v[i]);
    }
    REP(i,0,4){
        sort(ALL(wa[i]),greater<int>());
        wa[i].insert(wa[i].begin(),0);
    }
    REP(i,0,4){
        REP(j,1,wa[i].size()){
            wa[i][j]+=wa[i][j-1];
        }
//        vout(wa[i]);
    }

    cout<<dfs(0,0,0)<<endl;
    return 0;
}


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

int x, k, q;
vector<int> r, t, a, dif, sum, res;
vector<vector<int>> memo;

void solve();

int main() {
  cin >> x >> k;
  r.resize(k + 1);
  for (int i = 1; i <= k; ++i) cin >> r[i];
  r.push_back(2 * (int)1e9 + 2);
  k = r.size();
  cin >> q;
  t.resize(q);
  a.resize(q);
  res.resize(q);
  for (int i = 0; i < q; ++i) cin >> t[i] >> a[i];
  solve();
  for (auto p : res) cout << p << endl;
  return 0;
}

void solve() {
  for (int i = 1; i < k; ++i) dif.push_back(r[i] - r[i - 1]);
  sum.resize(k);
  memo.resize(k, vector<int>(2));
  memo[0][0] = 0;
  memo[0][1] = x;
  for (int i = 0; i < k - 1; ++i) {
    if (i & 1)
      sum[i + 1] = sum[i] + dif[i];
    else
      sum[i + 1] = sum[i] - dif[i];
    for (int p = 0; p < 2; ++p) {
      if (i & 1)
        memo[i + 1][p] = min(memo[i][p] + dif[i], x);
      else
        memo[i + 1][p] = max(memo[i][p] - dif[i], 0);
    }
  }
  for (int i = 0, id = 0, d = 0, u = x; i < q; ++i) {
    int nt = t[i], na = a[i];
    while (id + 1 < k && r[id + 1] < nt) {
      if (id & 1) {
        if (dif[id] >= x) u = 0;
        u = min(u, x - sum[id + 1]);
      } else {
        if (dif[id] >= x) d = x;
        d = max(d, -sum[id + 1]);
      }
      ++id;
    }
    if (na <= d)
      na = memo[id][0];
    else if (na >= u)
      na = memo[id][1];
    else
      na += sum[id];
    if (id & 1)
      na = min(na + (nt - r[id]), x);
    else
      na = max(na - (nt - r[id]), 0);
    res[i] = na;
  }
}

Measured memory_bytes: 11192
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];

int main() {
    FAST;
    ll t, i, j, k, p, q,l,r, x, y, u, n, m;
    cin>>n>>m;
    vc v(n+1,0),w(n+1,0);
    Ff(i,1,n+1)
    cin>>w[i]>>v[i];

    ll dp[n+1][m+1];
    Ff(i,0,m+1)
    dp[0][i]=0;

    Ff(i,1,n+1)
    {
        Ff(j,0,m+1)
        {
            if(j<w[i])
            dp[i][j]=dp[i-1][j];
            else
            dp[i][j]=max(dp[i-1][j],v[i]+dp[i-1][j-w[i]]);
        }
    }

    cout<<dp[n][m];
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(ll n, ll m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

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

#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
const int MOD=1e9+7;
int powmod(int a,int l, int md){a%=md; int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
int invmod(int a, int md){return powmod(a,md-2,md);}
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
typedef vector<int> vi; typedef pair<int, int> ii; typedef vector< ii > vii;
#define pb push_back
int __set(int b, int i) {return b|(1LL<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return (((a%md)*(b%md))%md+md)%md;}
int addmod(int a, int b, int md) {return ((a%md+b%md)%md+md)%md;}
int submod(int a, int b, int md) {return (((a%md-b%md)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);



signed main(void) {
	IOS;
	int k,n; cin>>k>>n;
	vi a(n);
	for(int i = 0; i < n; i++) {
		cin>>a[i];
	}
	int ans=k;
	for(int i = 0; i < n; i++) {
		if(i==n-1) {
			ans=min(ans,k-(a[0]+k-a[i]));
			// cout<<ans<<endl;
		} else {
			ans=min(ans,k-(a[i+1]-a[i]));
			// cout<<ans<<endl;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long LL;
const int INF = 1e9 + 10;
int a[1111111];
int n, T;
vector<int> vec1, vec2;

inline int solve(int l, int r, int delta) {
//cout << l << " " << r << endl;
	int s1 = 0, s2 = 0;
	int mina = INF, maxa = -INF;
	for (int i = l; i <= r; ++i) {
		if (a[i] - mina == delta) {
			++s1;
		}
		mina = min(mina, a[i]);
	}
	for (int i = r; i >= l; --i) {
		if (maxa - a[i] == delta) {
			++s2;
		}
		maxa = max(maxa, a[i]);
	}
	return min(s1, s2);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> n >> T;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	
	int mina = INF, maxa = -INF;
	int delta = 0;
	for (int i = 1; i <= n; ++i) {
		delta = max(delta, a[i] - mina);
		mina = min(mina, a[i]);
	}
	mina = INF;
	int ans = 0, last = 0;
	vec1.clear();
	vec1.push_back(0);
	vec2.clear();
	vec2.push_back(0);
	a[0] = -2; a[n + 1] = -1;
	for (int i = 1; i <= n; ++i) {
		if (a[i] - mina == delta) {
			if (a[i] != a[vec1[vec1.size() - 1]]) {
				vec1.push_back(i);
				vec2.push_back(i);
			} else {
				vec2[vec2.size() - 1] = i;
			}
		}
		mina = min(mina, a[i]);
	}
	vec1.push_back(n + 1);
	vec2.push_back(n + 1);
	for (int i = 1; i + 1 < vec1.size(); ++i) {
		ans += solve(vec2[i - 1] + 1, vec1[i + 1] - 1, delta);
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 1908
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		BigDecimal[] bd = new BigDecimal[n];
		String[] s = new String[n];
		BigDecimal rate = new BigDecimal("380000");
		for (int i = 0; i < n; i++) {
			bd[i] = new BigDecimal(sc.next());
			s[i] = sc.next();
			if ("BTC".equals(s[i])) {
				bd[i] = bd[i].multiply(rate);
			}
		}
		sc.close();

		BigDecimal sum = BigDecimal.ZERO;
		for (int i = 0; i < n; i++) {
			sum = sum.add(bd[i]);
		}
		System.out.println(sum.toString());
	}
}


Measured memory_bytes: 21844
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
using namespace std;
signed main()
{
	fastio;
	double l;
	cin>>l;
	l=l/(double)3;
	cout<<fixed<<setprecision(8)<<l*l*l<<endl;
}












Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
  int n;
  cin>>n;
  vector<vector<int>> a(n,vector<int>(2));
  for(int i=0;i<n;++i) {
    cin>>a[i][0]>>a[i][1];
  }
  int count=0;
  for(int i=0;i<n;++i) {
    if(a[i][0]==a[i][1])
      count++;
    else
      count=0;
    if(count==3) {
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}
    

Measured memory_bytes: 3572
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

S = sys.stdin.buffer.readline().decode().rstrip()
print( 'x' * len(S))


Measured memory_bytes: 25324
fun ac103(args: Array<String>) {
    val numList = args[1].split(" ").map { it.toInt() }
    val evenNumToCount = mutableMapOf(0 to 0)
    val oddNumToCount = mutableMapOf(0 to 0)
    numList.forEachIndexed { index, num ->
        if (index % 2 == 0) {
            if (!evenNumToCount.containsKey(num)) {
                evenNumToCount[num] = 0
            }
            evenNumToCount[num] = evenNumToCount[num]!! + 1
        } else {
            if (!oddNumToCount.containsKey(num)) {
                oddNumToCount[num] = 0
            }
            oddNumToCount[num] = oddNumToCount[num]!! + 1
        }
    }

    val evenSorted = evenNumToCount.entries.sortedByDescending { it.value }
    val oddSorted = oddNumToCount.entries.sortedByDescending { it.value }
    if (evenSorted[0].key != oddSorted[0].key) {
        println(numList.size - evenSorted[0].value - oddSorted[0].value)
    } else {
        println(Math.min(numList.size - evenSorted[0].value - oddSorted[1].value,
                numList.size - evenSorted[1].value - oddSorted[0].value))

    }
}

fun main(args: Array<String>) {
    ac103(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

Measured memory_bytes: 60252
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
      
n = int(input())
print(num2alpha(n).lower())

Measured memory_bytes: 9180
#include<stdio.h>
#define Max 500000
#define term 2000000000

int Left[(Max/2)+2], Right[(Max/2)+2];
int c=0;


void merge(int e[], int n, int left, int mid, int right){
  int i,j,k;

  int x = (mid-left);
  int y = (right-mid);

  for ( i=0; i<x; i++ )
   Left[i] = e[left+i];
  for ( i=0; i<y; i++ )
   Right[i] = e[mid+i];

  Left[x]= Right[y] = term;
  i = j = 0;
  for ( k=left; k<right; k++){
    c++;
    if ( Left[i]<=Right[j] ){
      e[k] = Left[i++];
    } else {
      e[k] = Right[j++];
    }
  }
}

void mergeSort(int e[], int n, int left, int right ){
  int mid;
  if ( left+1<right ){
    mid=(left + right)/2;
    mergeSort(e, n, left, mid);
    mergeSort(e, n, mid, right);
    merge(e, n, left, mid, right);
  }
}

int main(){
  int e[Max], n, i;
  scanf("%d", &n);
  for ( i=0; i<n; i++) {
    scanf("%d", &e[i]);
    if (e[i]>=term ){
      return 1;
    }
  }
  mergeSort(e,n,0,n);

  for ( i=0; i<n; i++) {
    if ( i !=0 ) 
    printf(" ");

    printf("%d", e[i]);
    }
  printf("\n");

  printf("%d\n", c);


  return 0;
}




Measured memory_bytes: 5688
#[allow(unused_imports)] use proconio::{input, marker::{Bytes, Chars, Usize1, Isize1}};
#[allow(unused_imports)] use std::cmp::{min, max};
#[allow(unused_imports)] use superslice::Ext as _;

#[proconio::fastout]
fn main() {
	input! {
		x: usize,
	}

	let mut ans = 1;
	for i in 2usize..=31 {
		let mut j = 2;
		loop {
			let n = i.pow(j);
			if n > x {
				break;
			}
			ans = max(ans, n);
			j += 1;
		}
	}

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


Measured memory_bytes: 2164
function gcd(a, b) {
  if (a % b === 0) {
    return b;
  }

  return gcd(b, a % b);
}

function main(input) {
  const K = parseInt(input);

  let res = 0;

  for (let c = 1; c <= K; ++c) {
    for (let b = 1; b <= K; ++b) {
      for (let a = 1; a <= K; ++a) {
        res += gcd(gcd(a, b), c);
      }
    }
  }
  console.log(res);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 31568
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main() {
  int H,W,ans=0; cin>>H>>W;
  vector<vector<char>> S(H,vector<char>(W));
  queue<pair<int,int>> Q;
  vector<vector<bool>> dist(H,vector<bool>(W,false)); 
  rep(i,H){
    rep(j,W){
      cin>>S.at(i).at(j);
      if(S.at(i).at(j)=='#'){
        Q.push(make_pair(i,j));
        dist[i][j]=true;
      }
    }
  }
  Q.push(make_pair(-1,-1));
  while(!Q.empty()){
    pair<int, int> start = Q.front();
    int x=start.first,y=start.second;
    Q.pop();
    if(x==-1&&y==-1){
      if(Q.empty())continue;
      ans++;
      Q.push(make_pair(-1,-1));
      continue;  
    }
    rep(j,4){
      int nx=x+dx[j],ny=y+dy[j];
      if(nx<0 || nx>= H || ny<0 || ny>=W) continue;
      if(dist[nx][ny]==false){
      Q.push(make_pair(nx,ny));
      dist[nx][ny]=true;
      }
    }
  }
  cout<<ans;
}


Measured memory_bytes: 12360
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int ans = 0;
	int mi = 10;
	for (int i = 0; i < 5; ++i) {
		int d;
		cin >> d;
		ans += (d + 9) / 10 * 10;
		if(d % 10 > 0)
			mi = min(mi, d % 10);
	}
	cout << ans - 10 + mi << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProgrammingContest
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            string [] res = str.Split(' ');
            int i, j;
            Int32.TryParse(res[0], out i);
            Int32.TryParse(res[1], out j);

            Console.Write((i - 1) * (j - 1));
        }
    }
}


Measured memory_bytes: 11220
import math
N = int(input())
xy = []
for _ in range(N):
    xy.append(list(map(int, input().split())))
dist = []
for i in range(N-1):
    for j in range(i+1, N):
        dist.append(math.sqrt((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2))
print(sum([one*math.factorial(N-1)*2 for one in dist])/math.factorial(N))

Measured memory_bytes: 38356
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int c1,c2,c3;
	while(cin>>c1>>c2>>c3)
	{
		bool c[10]; fill(c,c+10,0);
		c[c1-1]=c[c2-1]=c[c3-1]=true;
		int cnt=0;
		for(int i = 0; c1+c2+i+1 < 21 ; ++i)
		{
			if(c[i]) continue;
			cnt++;
		}
		if(3<cnt) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

  return 0;
}

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

using namespace std;

    int n, w; // the number of temperatures to analyse
    int weight[101], value[101];
    long long dp[101][100010];
    long long ans=0;

int main() {
    


    cin >> n >>w; cin.ignore();
    for (int i = 0; i < n; i++) {
        cin >> weight[i]>> value[i]; cin.ignore();
    }

    //init
    for (int i = 0; i < w; ++i)
    {
      dp[0][i] = 0; 
    }

    for (int i = 0; i < n; ++i)
    {//till dp[n] 
    	for( int j = 0; j<=w; ++j)
    	{
	    	if (j >= weight[i])
	    	{
	    		dp[i+1][j] = max(dp[i][j], dp[i][j-weight[i]]+value[i]); 
	    	} 
	    	else
	    	{
	    		dp[i+1][j] = dp[i][j];
	    	}
	    	//cout<<"i="<<i<<" j="<<j<<" "<< dp[i+1][j]<< endl;
		}
    }

    for (int i = 0; i <= w; ++i)
    {
    	if (ans<dp[n][i])
    	{
    		ans = dp[n][i];
    	}
    	//cout<<dp[n][i]<<endl; 
    }

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

Measured memory_bytes: 79104
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <iomanip>
#include <math.h>
#include <fstream>

using namespace std;

long long mod = 1000000007;

void dfs(int p, int prev, vector<int> &a, vector<int> &dp, int dpl, vector<vector<int>> &v, vector<int> &res)
{
    int l = -1, r = dpl, mid;
    while (r - l > 1)
    {
        mid = (l + r) / 2;
        if (dp[mid] >= a[p])
        {
            r = mid;
        }
        else
        {
            l = mid;
        }
    }
    int temp = dp[r];
    dp[r] = a[p];
    if (temp == -1)
    {
        dpl++;
    }
    res[p] = dpl;
    for (int i = 0; i < v[p].size(); i++)
    {
        if (v[p][i] == prev)
        {
            continue;
        }
        dfs(v[p][i], p, a, dp, dpl, v, res);
    }
    dp[r] = temp;
}

int main()
{
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    // ifstream cin("in.txt");
    // ofstream cout("out.txt");
    
    
    // int t;
    // cin >> t;
    // for (int qwe = 0; qwe < t; qwe++)
    // {
    //     cout << "Case #" << qwe + 1 << ": ";
    // }


    int n, k;
    cin >> n >> k;
    vector<bool> b(n + 1, true);
    int res = n;
    for (int i = 0; i < k; i++)
    {
        int x;
        cin >> x;
        int y;
        for (int j = 0; j < x; j++)
        {
            cin >> y;
            if (b[y])
            {
                res--;
            }
            b[y] = false;
        }
    }
    cout << res << '\n';


    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


//k!
ll facctorialMethod(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum = sum%MOD*i%MOD;
    }
    return sum%MOD;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int N,W;cin>>N>>W;
    vector<int> w(N), v(N);
    rep(i,N)cin>>w[i]>>v[i];
    ll dp[110][100010];
    rep(i,W+1)dp[0][i] = 0;
    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= W; j++){
            dp[i][j] = dp[i-1][j];
            if(j < w[i-1])continue;
            dp[i][j] = max(dp[i][j],dp[i-1][j-w[i-1]]+v[i-1]);
        }
    }
    cout << dp[N][W] << endl;

}




Measured memory_bytes: 81024
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 2e5 + 5, mod = 1e9 + 7;

ll dp[N][3][3], arr[N], n;

ll solve(int ind, int jmp, int odd)
{
    if(ind >= n) return -1e17 * (jmp == 2 or odd == 1);
    ll &ret = dp[ind][jmp][odd];
    if(~ret) return ret;
    ret = solve(ind + 2, jmp, !odd) + arr[ind];
    if(jmp) ret = max(ret, solve(ind + 1, jmp - 1, odd));
    return ret;
}

int main()
{
    memset(dp, -1, sizeof dp);
    scanf("%lld", &n);
    if(n == 1) return puts("0");
    for(int i = 0 ; i < n ; i++) scanf("%lld", arr + i);
    printf("%lld\n", solve(0, 1 + (n&1), (n/2)&1));
    return 0;
}


Measured memory_bytes: 25736
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    int h, w;
    cin >> h >> w;
    char s[h][w];
    int black = 0;
    rep(i,h){
        rep(j,w) {
            char tmp;
            cin >> tmp;
            s[i][j] = tmp;
            if (tmp == '#')
                black++;
        }
    }

    int d[h][w];
    rep(i,h) {
        rep(j,w) {
            d[i][j] = INF;
        }
    }
    queue<PII> q;
    q.emplace(0, 0);
    d[0][0] = 0;

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

    while(!q.empty()) {
        PII now = q.front();
        q.pop();
        rep(i,4) {
            int nx = now.first + dx[i], ny = now.second + dy[i];

            if (nx < 0 || nx >= h || ny < 0 || ny >= w
                || s[nx][ny] == '#' || d[nx][ny] != INF)
                continue;
            d[nx][ny] = d[now.first][now.second] + 1;
            q.emplace(nx, ny);
        }
    }

    if (d[h-1][w-1] == INF) {
        cout << -1 << endl;
        return 0;
    }

    cout << h*w - black - d[h-1][w-1] -1<< endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int i,j,k;
  int ans=0;
  vector<int> v;
  for(i=0;i<n*2;i++){
    cin >> k;
    v.push_back(k);
  }
  sort(v.begin(),v.end());
  for(i=0;i<n;i++) ans+=v[i*2];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <tuple>
#include <cmath>
using namespace std;
typedef long long ll;
//typedef pair<ll, ll> P;

#define rep(i, m) for(ll i=0;i<(m);i++)
#define rep1(i, m) for(ll i=1;i<=(m);i++)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

struct BIND {int s, t, v; };

template<typename T> struct UnionFind {
   vector<T> data;
   UnionFind(T size):data(size){
      for(T i=0;i<size;i++) {
         data[i] = i;
      }
   }
   bool unite(T x, T y) {
      x = root(x); y = root(y);
      if (x != y) {
         data[y] = x;
      }
      return x != y;
   }
   bool same(T x, T y) {
      return root(x) == root(y);
   }
   bool sameall() {
      return all_of(data.begin(), data.end(), [this](T x) {return same(0, x);});
      bool istrue = true;
      for (T i=0;i<data.size();i++) {
         istrue &= same(0, i);
      }
      return istrue;
   }

   T root(T x) {
      return (data[x] == x) ? x: data[x] = root(data[x]);
   }
};

int main() {
   int N, M;
   cin >> N >> M;
   vector<int> a(M), b(M);
   rep(i, M) {
      cin >> a[i] >> b[i];
      a[i]--;
      b[i]--;
   }

   int cnt = 0;
   rep(i, M) {
      UnionFind<int> uf(N);
      rep(j, M) {
         if (i == j) continue;
         uf.unite(a[j], b[j]);
      }
      cnt += !uf.sameall();
   }
   cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)

ll binpowmod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return binpowmod(n, p-2, p);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,f,t,k,w,j;
    cin >> n >> w;
    ll v[n+1],p[n+1];
    ll sum=0,sum1=0;
    repp(i,1,n+1) 
    {
        cin >> p[i] >> v[i];
        sum+=v[i];
        sum1+=p[i];
    }
    ll dp[sum+1];
    memset(dp,1e9+5,sizeof(dp));
    dp[0]=0;
    
    if(sum1<=w) 
    {
        cout << sum ;
        return 0;
    }
    for(i=1;i<n+1;++i)
    {
        for(j=sum-v[i];j>=0;j--)
        {
            dp[j+v[i]]=std::min(dp[j]+p[i],dp[j+v[i]]);
            //cout << j+v[i] << " " << dp[j+v[i]] << endl;
        }
        
    }
    ll ans=1e9+5;
    
    dp[sum]=sum1;
    for(j=sum;j>=0;j--)
    {
        if(dp[j]<=w) 
        {
            ans=j;
            break;
        }
        else continue;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.util.stream.*;

public class Main {
	Scanner sc;
	String s, t;
	
	public Main() {
		sc = new Scanner(System.in);
	}
	
	@SuppressWarnings("unchecked")
	private void calc() {
		s = sc.next();
		t = sc.next();
		
		List[] m = new List[26];
		for (int i = 0; i < 26; i++) m[i] = new ArrayList();
		
		for (int i = 0; i < s.length(); i++)
			m[s.charAt(i)-'a'].add(i);
		
		int[][] map = new int[26][];
		for (int i = 0; i < 26; i++) {
			map[i] = new int[m[i].size()];
			for (int j = 0; j < map[i].length; j++)
				map[i][j] = (Integer)m[i].get(j);
		}
		
		int count = 0;
		int pos = 0;
		for (int i = 0; i < t.length(); i++) {
			int c = t.charAt(i)-'a';
			if (map[c].length == 0) {
				pos = -1;
				break;
			}
			if (pos >= s.length()) {
				pos = 0;
				count++;
			}
			
			while (true) {
				int index = Arrays.binarySearch(map[c], pos);
				if (index >= 0) {
					pos++;
				} else if (index < -map[c].length) {
					pos = 0;
					count++;
					continue;
				} else {
					pos = map[c][-index-1]+1;
				}
				break;
			}
		}
		if (pos == -1) System.out.println(-1);
		else System.out.println((long)count*s.length()+pos);
		System.out.flush();
	}

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

}


Measured memory_bytes: 28968
#include <stdio.h>

int main(void) {
	int n,i;
	
	
	while(1) {
		scanf("%d", &n);
		if(n==0) break;
		
		int c2=0, c5=0;
		
		for(i=n; i>0; i--) {
			int k=i;
			while(k%2==0) {
				k = k/2;
				c2++;
			}
			while(k%5==0) {
				k=k/5;
				c5++;
			}
		}
		
		printf("%d\n", (c2>c5)?c5:c2);


	}
	
	return 0;
}

Measured memory_bytes: 600
import sys

for i in sys.stdin:
    n = int(i)
    cnt = 0
    for a in range(10):
        for b in range(10):
            for c in range(10):
                for d in range(10):
                    if a+b+c+d == n:
                        cnt += 1
                        break
    print(cnt)

Measured memory_bytes: 7516
#include<iostream>
#include<set>
using namespace std;
int main() {
	int N;
	cin >> N;
	char S;
	set<char>fuck;
	for (int i = 0; i < N; ++i) {
		cin >> S;
		fuck.insert(S);
	}
	if (fuck.size() == 3)
		cout << "Three";
	else
		cout << "Four";
	return 0;
}


Measured memory_bytes: 256